From 752b3783912fe09d4b72755e8ec4fb83f380f6f3 Mon Sep 17 00:00:00 2001 From: omarsamb Date: Tue, 23 Dec 2025 11:36:29 +0000 Subject: [PATCH] fix: update version to 0.1.6 and modify initEntries to return methods of EntryInternal --- db/deno.json | 2 +- db/entries.ts | 35 ++++++++++++++++++++++------------- db/mod.ts | 6 +++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/db/deno.json b/db/deno.json index 32a74fd..d6b0702 100644 --- a/db/deno.json +++ b/db/deno.json @@ -4,7 +4,7 @@ "@std/assert": "jsr:@std/assert@^1.0.16" }, "name": "@01edu/db", - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "exports": { ".": "./mod.ts", diff --git a/db/entries.ts b/db/entries.ts index a343a3b..1859647 100644 --- a/db/entries.ts +++ b/db/entries.ts @@ -152,17 +152,26 @@ export const initEntries = < | RelationTable[] | Record>, const ET extends { [K: string]: EntryTypeDef> }, ->(entryIds: ID, relations: R, entryTypes: ET): { - type: ID - insertListeners: Set>> - view: { [K in (keyof ET & string)]: `entry_${Lowercase}` } - archive: (id: number) => void - insert: { - [K in (keyof ET & string)]: ( - params: InsertParams, ET[K]>, - ) => number - } -} => { +>(entryIds: ID, relations: R, entryTypes: ET): + & Omit< + TableAPI< + 'entryInternal', + & RelToTableProperties + & typeof commonEntryProperties + >, + 'insert' + > + & { + type: ID + insertListeners: Set>> + view: { [K in (keyof ET & string)]: `entry_${Lowercase}` } + archive: (id: number) => void + insert: { + [K in (keyof ET & string)]: ( + params: InsertParams, ET[K]>, + ) => number + } + } => { type Relations = RelToTableProperties type EntryTrigger = EntryTriggerGeneric type EntryListener = EntryListenerGeneric @@ -222,7 +231,7 @@ export const initEntries = < const fieldTables: Record = {} const entryNames = Object.keys(entryTypes) as EntryName[] - const insert = Object.fromEntries( + const insertEntry = Object.fromEntries( entryNames.map((k) => { const type = entryIds[k] const trigger = (entryTypes[k] as { trigger?: EntryTrigger }).trigger @@ -368,7 +377,7 @@ export const initEntries = < ...EntryInternal, type: entryIds, view, - insert, + insert: insertEntry, archive, insertListeners, } diff --git a/db/mod.ts b/db/mod.ts index 70ffc19..bf98762 100644 --- a/db/mod.ts +++ b/db/mod.ts @@ -205,7 +205,7 @@ export type TableAPI = { * } * ``` */ - require: (id: number) => Row> + require: (id: number | undefined) => Row> /** * Asserts that a row with the given ID exists, throwing an error if not. * @param id - The ID to check. @@ -366,8 +366,8 @@ export const createTable = ( const get = (id: number): Row | undefined => getByIdStmt.get(id) - const require = (id: number) => { - const match = getByIdStmt.get(id) + const require = (id: number | undefined) => { + const match = id && getByIdStmt.get(id) if (!match) throw new respond.NotFoundError(notFound) return match as Row }