From 6fb46b24114aafe9833716242ebc3fe6ee4215dc Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 16 Jul 2024 15:29:30 +0200 Subject: [PATCH] refactor: :recycle: switch from deno workspace to `jsr` for `@cohabit/resources-manager` --- deno.json | 5 +---- routes/api/magiclink/index.ts | 4 ++-- routes/api/webauthn/login/[step].ts | 9 ++++----- routes/api/webauthn/register/[step].ts | 11 +++++------ routes/membres/[id]/index.tsx | 2 +- routes/profil/index.tsx | 2 +- src/db/mod.ts | 12 ++++++------ src/members/mod.ts | 3 ++- 8 files changed, 22 insertions(+), 26 deletions(-) diff --git a/deno.json b/deno.json index 1ba15b1..62d9ab6 100644 --- a/deno.json +++ b/deno.json @@ -36,7 +36,7 @@ ":src/": "./src/", ":types": "./types.ts", "@cohabit/mailer": "jsr:@cohabit/mailer@^0.3.3", - "@cohabit/ressources_manager/": "./packages/@cohabit__ressources_manager@0.1.3/", + "@cohabit/resources-manager": "jsr:@cohabit/resources-manager@^0.2.1", "@deno/gfm": "https://deno.land/x/gfm@0.6.0/mod.ts", "@jotsr/delayed": "jsr:@jotsr/delayed@^2.1.1", "@jotsr/smart-css-bundler": "jsr:@jotsr/smart-css-bundler@^0.3.0", @@ -59,9 +59,6 @@ "jsx": "react-jsx", "jsxImportSource": "preact" }, - "workspace": [ - "packages/@cohabit__ressources_manager@0.1.3" - ], "unstable": [ "kv" ] diff --git a/routes/api/magiclink/index.ts b/routes/api/magiclink/index.ts index 2ca60c0..b205cde 100644 --- a/routes/api/magiclink/index.ts +++ b/routes/api/magiclink/index.ts @@ -7,7 +7,7 @@ import { SessionHandlers, SessionStore } from ':src/session/mod.ts' import { respondApi } from ':src/utils.ts' import { Contact, type Mail, send } from '@cohabit/mailer' import { magicLinkTemplate } from '@cohabit/mailer/templates' -import { User } from '@cohabit/ressources_manager/src/models/mod.ts' +import { User } from '@cohabit/resources-manager/models' import { sleep } from '@jotsr/delayed' type MagicLinkInfos = { @@ -17,7 +17,7 @@ type MagicLinkInfos = { } export async function getUserByMail(email: string): Promise { - const [user] = await db.ressource.user + const [user] = await db.resource.user .list((user) => user.mail === email) .take(1) .toArray() diff --git a/routes/api/webauthn/login/[step].ts b/routes/api/webauthn/login/[step].ts index 60daf5c..7a8d760 100644 --- a/routes/api/webauthn/login/[step].ts +++ b/routes/api/webauthn/login/[step].ts @@ -2,8 +2,7 @@ import { db } from ':src/db/mod.ts' import type { SessionHandlers } from ':src/session/mod.ts' import { respondApi } from ':src/utils.ts' import { getRelyingParty } from ':src/webauthn/mod.ts' -import { Credential, Ref, User } from '@cohabit/ressources_manager/mod.ts' -import { Passkey } from '@cohabit/ressources_manager/src/models/src/credential.ts' +import { Credential, Passkey, Ref, User } from '@cohabit/resources-manager/models' import { generateAuthenticationOptions, verifyAuthenticationResponse, @@ -32,7 +31,7 @@ export const handler: SessionHandlers = { const { email } = await req.json() as WebAuthnLoginStartPayload // Get user credentials - const [user] = await db.ressource.user.list((user) => user.mail === email) + const [user] = await db.resource.user.list((user) => user.mail === email) .take(1).toArray() // Resolve refs to credentials const resolver = Ref.dbResolver(db) @@ -121,7 +120,7 @@ export const handler: SessionHandlers = { const newPasskey = { ...passkey, counter: newCounter } // Update credential store - const [credential] = await db.ressource.credential.list( + const [credential] = await db.resource.credential.list( (credential) => { if (credential.category !== 'passkey') { return false @@ -131,7 +130,7 @@ export const handler: SessionHandlers = { ).toArray() // Save credential to db - await db.ressource.credential.set([ + await db.resource.credential.set([ credential.update({ store: newPasskey }), ]) diff --git a/routes/api/webauthn/register/[step].ts b/routes/api/webauthn/register/[step].ts index b8ff3ee..ed6b6c4 100644 --- a/routes/api/webauthn/register/[step].ts +++ b/routes/api/webauthn/register/[step].ts @@ -12,8 +12,7 @@ import type { //TODO improve workspace imports import { db } from ':src/db/mod.ts' import { getRelyingParty } from ':src/webauthn/mod.ts' -import { Credential, Ref, User } from '@cohabit/ressources_manager/mod.ts' -import { Passkey } from '@cohabit/ressources_manager/src/models/src/credential.ts' +import { Credential, Passkey, Ref, User } from '@cohabit/resources-manager/models' import { encodeBase64 } from '@std/encoding' type Params = { step: 'start' | 'finish' } @@ -42,7 +41,7 @@ export const handler: SessionHandlers = { // Get user credentials // Ensure latest user datas - const dbUser = await db.ressource.user.get(user) + const dbUser = await db.resource.user.get(user) // Resolve refs to credentials const resolver = Ref.dbResolver(db) const credentials = await Promise.all(dbUser.credentials.map(resolver)) @@ -117,16 +116,16 @@ export const handler: SessionHandlers = { // create and save new Credentials const credential = Credential.load({ name, category: 'passkey', store }) - await db.ressource.credential.set([credential]) + await db.resource.credential.set([credential]) // Update user credentials // Ensure latest user datas - const dbUser = await db.ressource.user.get(user) + const dbUser = await db.resource.user.get(user) // Append new credentials const credentials = [...dbUser.credentials, credential.toRef()] const updatedUser = user.update({ credentials }) // Save user to db - await db.ressource.user.set([updatedUser]) + await db.resource.user.set([updatedUser]) // Update session ctx.state.session.set('user', updatedUser) diff --git a/routes/membres/[id]/index.tsx b/routes/membres/[id]/index.tsx index 8a1fbd9..b9996a0 100644 --- a/routes/membres/[id]/index.tsx +++ b/routes/membres/[id]/index.tsx @@ -6,7 +6,7 @@ import { fetchCarnet, userToMemberCardProps } from ':src/members/mod.ts' export default async function Member(_: Request, { params, url }: PageProps) { const uuid = params.id as ReturnType - const user = await db.ressource.user.get({ uuid }).catch(() => undefined) + const user = await db.resource.user.get({ uuid }).catch(() => undefined) if (!user) { return

Membre inconnu, peut ĂȘtre serez vous le prochain

diff --git a/routes/profil/index.tsx b/routes/profil/index.tsx index dff9996..747f4aa 100644 --- a/routes/profil/index.tsx +++ b/routes/profil/index.tsx @@ -1,7 +1,7 @@ import LoginForm from ':islands/LoginForm.tsx' import PassKeyRegister from ':islands/PassKeyRegister.tsx' import type { SessionPageProps } from ':src/session/mod.ts' -import type { User } from '@cohabit/ressources_manager/mod.ts' +import type { User } from '@cohabit/resources-manager/models' import { Button } from 'univoq' export default function Profil({ state }: SessionPageProps) { diff --git a/src/db/mod.ts b/src/db/mod.ts index af354e4..f40a303 100644 --- a/src/db/mod.ts +++ b/src/db/mod.ts @@ -1,10 +1,10 @@ -import { Db, Group } from '@cohabit/ressources_manager/mod.ts' +import { Db } from '@cohabit/resources-manager/db' +import { Group, User } from '@cohabit/resources-manager/models' +import type { MailAddress } from '@cohabit/resources-manager/types' // Import Datas import { exists } from '$std/fs/exists.ts' import { ensureDir } from '$std/fs/mod.ts' -import { User } from '@cohabit/ressources_manager/src/models/mod.ts' -import { MailAddress } from '@cohabit/ressources_manager/types.ts' import groups from ":src/db/mock/groups.json" with { type: 'json' } import users from ":src/db/mock/users.json" with { type: 'json' } @@ -21,13 +21,13 @@ if (!dbExist) { // Load groups to DB for (const { name } of groups) { const group = Group.load({ name }) - db.ressource.group.set([group]) + db.resource.group.set([group]) } // Load users to DB for (const { lastname, firstname, mail, groups: groupNames } of users) { // Get groups of user - const groups = await db.ressource.group.listRef((group) => + const groups = await db.resource.group.listRef((group) => groupNames.includes(group.name) ) @@ -38,6 +38,6 @@ if (!dbExist) { groups, }) - db.ressource.user.set([user]) + db.resource.user.set([user]) } } diff --git a/src/members/mod.ts b/src/members/mod.ts index 1ffceef..a587507 100644 --- a/src/members/mod.ts +++ b/src/members/mod.ts @@ -1,6 +1,7 @@ import { MemberCardProps } from ':components/MemberCard.tsx' import { db } from ':src/db/mod.ts' -import { Db, Ref, User } from '@cohabit/ressources_manager/mod.ts' +import { Db } from '@cohabit/resources-manager/db' +import { Ref, User } from '@cohabit/resources-manager/models' export async function fetchCarnet(login: string): Promise { try {