@gobing-ai/ts-db 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/bun-sqlite.js +3 -3
- package/dist/embedded-migrations.d.ts +2 -0
- package/dist/embedded-migrations.d.ts.map +1 -1
- package/dist/embedded-migrations.js +1 -0
- package/dist/entity-dao.d.ts +17 -17
- package/dist/entity-dao.d.ts.map +1 -1
- package/dist/entity-dao.js +23 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +2 -2
- package/package.json +3 -3
- package/src/adapters/bun-sqlite.ts +3 -3
- package/src/embedded-migrations.ts +2 -0
- package/src/entity-dao.ts +19 -19
- package/src/index.ts +0 -11
- package/src/migrate.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAbsolutePath, resolvePath } from '@gobing-ai/ts-runtime';
|
|
2
2
|
import { Database } from '@gobing-ai/ts-runtime/bun-sqlite';
|
|
3
3
|
import { drizzle } from 'drizzle-orm/bun-sqlite';
|
|
4
4
|
import * as schema from '../schema/runtime.js';
|
|
@@ -33,8 +33,8 @@ export class BunSqliteAdapter {
|
|
|
33
33
|
let dbPath = options?.databaseUrl ?? DEFAULT_DB_PATH;
|
|
34
34
|
const pragmas = { ...DEFAULT_PRAGMAS, ...options?.pragmas };
|
|
35
35
|
// Resolve relative paths
|
|
36
|
-
if (dbPath !== ':memory:' && !
|
|
37
|
-
dbPath =
|
|
36
|
+
if (dbPath !== ':memory:' && !isAbsolutePath(dbPath)) {
|
|
37
|
+
dbPath = resolvePath(dbPath);
|
|
38
38
|
}
|
|
39
39
|
this.sqlite = new Database(dbPath, { create: true });
|
|
40
40
|
this.sqlite.run(pragmas.journalMode);
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
* DO NOT EDIT MANUALLY. Regenerate with: bun run scripts/embed-migrations.ts
|
|
8
8
|
*/
|
|
9
|
+
/** A single embedded migration with its identifying tag, SQL, and content hash. */
|
|
9
10
|
export interface EmbeddedMigration {
|
|
10
11
|
tag: string;
|
|
11
12
|
sql: string;
|
|
12
13
|
hash: string;
|
|
13
14
|
}
|
|
15
|
+
/** Auto-generated array of all embedded migrations, ordered by tag. */
|
|
14
16
|
export declare const embeddedMigrations: EmbeddedMigration[];
|
|
15
17
|
//# sourceMappingURL=embedded-migrations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedded-migrations.d.ts","sourceRoot":"","sources":["../src/embedded-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,iBAAiB;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,EA0BjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"embedded-migrations.d.ts","sourceRoot":"","sources":["../src/embedded-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,mFAAmF;AACnF,MAAM,WAAW,iBAAiB;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,EA0BjD,CAAC"}
|
package/dist/entity-dao.d.ts
CHANGED
|
@@ -39,6 +39,23 @@ export interface CursorListSpec {
|
|
|
39
39
|
direction?: 'asc' | 'desc';
|
|
40
40
|
includeDeleted?: boolean;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A structural validator (e.g. a zod schema). Kept structural so EntityDao never
|
|
44
|
+
* imports zod/drizzle-zod — consumers wire `defineTable().insertSchema` here when
|
|
45
|
+
* they want boundary validation.
|
|
46
|
+
*/
|
|
47
|
+
export interface DaoValidator {
|
|
48
|
+
parse(input: unknown): unknown;
|
|
49
|
+
}
|
|
50
|
+
/** Optional EntityDao configuration. */
|
|
51
|
+
export interface EntityDaoOptions {
|
|
52
|
+
/** Schema used to validate input before `create`/`createMany`/`upsert`. */
|
|
53
|
+
insertSchema?: DaoValidator;
|
|
54
|
+
/** Schema used to validate input before `update`. Falls back to `insertSchema` when absent. */
|
|
55
|
+
updateSchema?: DaoValidator;
|
|
56
|
+
/** Which write operations validate. Default: all (`create`, `createMany`, `upsert`, `update`) when a schema is present. */
|
|
57
|
+
validateOn?: ('create' | 'createMany' | 'upsert' | 'update')[];
|
|
58
|
+
}
|
|
42
59
|
/**
|
|
43
60
|
* Generic CRUD base class for entity DAOs — the STRUCTURED tier of the facade.
|
|
44
61
|
*
|
|
@@ -62,23 +79,6 @@ export interface CursorListSpec {
|
|
|
62
79
|
* }
|
|
63
80
|
* ```
|
|
64
81
|
*/
|
|
65
|
-
/**
|
|
66
|
-
* A structural validator (e.g. a zod schema). Kept structural so EntityDao never
|
|
67
|
-
* imports zod/drizzle-zod — consumers wire `defineTable().insertSchema` here when
|
|
68
|
-
* they want boundary validation.
|
|
69
|
-
*/
|
|
70
|
-
export interface DaoValidator {
|
|
71
|
-
parse(input: unknown): unknown;
|
|
72
|
-
}
|
|
73
|
-
/** Optional EntityDao configuration. */
|
|
74
|
-
export interface EntityDaoOptions {
|
|
75
|
-
/** Schema used to validate input before `create`/`createMany`/`upsert`. */
|
|
76
|
-
insertSchema?: DaoValidator;
|
|
77
|
-
/** Schema used to validate input before `update`. Falls back to `insertSchema` when absent. */
|
|
78
|
-
updateSchema?: DaoValidator;
|
|
79
|
-
/** Which write operations validate. Default: all (`create`, `createMany`, `upsert`, `update`) when a schema is present. */
|
|
80
|
-
validateOn?: ('create' | 'createMany' | 'upsert' | 'update')[];
|
|
81
|
-
}
|
|
82
82
|
export declare class EntityDao<TTable extends EntityTable, TPK extends SQLiteColumn> extends BaseDao {
|
|
83
83
|
readonly table: TTable;
|
|
84
84
|
/** Primary key columns. A single-element array for single-PK tables, multiple for composite. */
|
package/dist/entity-dao.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-dao.d.ts","sourceRoot":"","sources":["../src/entity-dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAYhF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACpC,SAAS,EAAE,YAAY,CAAC;IACxB,SAAS,EAAE,YAAY,CAAC;CAC3B,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG;IAC3C,MAAM,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC,0EAA0E;AAC1E,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAE5D,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,4CAA4C;AAC5C,MAAM,WAAW,cAAc;IAC3B,wEAAwE;IACxE,MAA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AAM,CAAC;IAUvE,qEAAqE;IACrE,OAAO,CAAC,UAAU;CAQrB"}
|
package/dist/entity-dao.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import { and, count as countFn, eq } from 'drizzle-orm';
|
|
2
2
|
import { BaseDao } from './base-dao.js';
|
|
3
3
|
import { compilePredicate } from './query-spec.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generic CRUD base class for entity DAOs — the STRUCTURED tier of the facade.
|
|
6
|
+
*
|
|
7
|
+
* Extends {@link BaseDao} (raw tier) with typed create/read/update/delete over a
|
|
8
|
+
* single table, using RETURNING, drizzle-free predicate filters, soft-delete
|
|
9
|
+
* auto-filtering, batch insert, upsert, and cursor pagination. drizzle is hidden
|
|
10
|
+
* entirely — consumers use ts-db vocabulary. (G1/G3)
|
|
11
|
+
*
|
|
12
|
+
* @typeParam TTable - The table type (must extend EntityTable).
|
|
13
|
+
* @typeParam TPK - The primary key column type.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* class UsersDao extends EntityDao<typeof users, typeof users.id> {
|
|
18
|
+
* constructor(adapter: DbAdapter) {
|
|
19
|
+
* super(adapter, users, [users.id], 'users');
|
|
20
|
+
* }
|
|
21
|
+
* findByEmail(email: string) {
|
|
22
|
+
* return this.findBy(users.email, email);
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
4
27
|
export class EntityDao extends BaseDao {
|
|
5
28
|
table;
|
|
6
29
|
/** Primary key columns. A single-element array for single-PK tables, multiple for composite. */
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,5 @@ export { type InboxMessage, InboxMessageDao } from './inbox-message-dao';
|
|
|
7
7
|
export { applyMigrations, type MigrationLogger, type MigrationOptions } from './migrate';
|
|
8
8
|
export { type ColRef, type ComparisonOp, compileOrderBy, compilePredicate, type ListSpec, type OrderTerm, type Predicate, } from './query-spec';
|
|
9
9
|
export { QueueJobDao, type QueueJobRecord, type QueueStats } from './queue-job-dao';
|
|
10
|
-
export { appendOnlyColumns, buildAppendOnlyColumns, buildStandardColumns, buildStandardColumnsWithSoftDelete, nowTimestamp, standardColumns, standardColumnsWithSoftDelete, } from './schema/common';
|
|
11
|
-
export { inboxMessages } from './schema/inbox-messages';
|
|
12
|
-
export { queueJobs } from './schema/queue-jobs';
|
|
13
10
|
export type { SpanContext } from './span-context';
|
|
14
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,kBAAkB,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EACH,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,cAAc,EACd,gBAAgB,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpF,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,KAAK,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,kBAAkB,GAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EACH,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,cAAc,EACd,gBAAgB,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpF,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,3 @@ export { InboxMessageDao } from './inbox-message-dao.js';
|
|
|
7
7
|
export { applyMigrations } from './migrate.js';
|
|
8
8
|
export { compileOrderBy, compilePredicate, } from './query-spec.js';
|
|
9
9
|
export { QueueJobDao } from './queue-job-dao.js';
|
|
10
|
-
export { appendOnlyColumns, buildAppendOnlyColumns, buildStandardColumns, buildStandardColumnsWithSoftDelete, nowTimestamp, standardColumns, standardColumnsWithSoftDelete, } from './schema/common.js';
|
|
11
|
-
export { inboxMessages } from './schema/inbox-messages.js';
|
|
12
|
-
export { queueJobs } from './schema/queue-jobs.js';
|
package/dist/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,yDAAyD;IACzD,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AA8ED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDnG"}
|
package/dist/migrate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getProcessCwd, resolvePath } from '@gobing-ai/ts-runtime';
|
|
2
2
|
import { embeddedMigrations } from './embedded-migrations.js';
|
|
3
3
|
/**
|
|
4
4
|
* Ensure the migration tracking table exists with proper SQLite types.
|
|
@@ -88,7 +88,7 @@ export async function applyMigrations(adapter, options) {
|
|
|
88
88
|
}
|
|
89
89
|
const table = validateMigrationTableName(options?.migrationsTable ?? '__drizzle_migrations');
|
|
90
90
|
await ensureJournalTable(adapter, table);
|
|
91
|
-
const folder = options?.migrationsFolder ??
|
|
91
|
+
const folder = options?.migrationsFolder ?? resolvePath(getProcessCwd(), 'drizzle');
|
|
92
92
|
// File-based migrations: attempt only if the drizzle/ folder is present.
|
|
93
93
|
// With an injected fs we get a definitive answer (await the Promise — a bare
|
|
94
94
|
// `fs.exists(...)` is always truthy and silently disables the check); without
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gobing-ai/ts-db",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "@gobing-ai/ts-db — a drizzle-free database facade: typed DAOs over Bun SQLite / Cloudflare D1, a small predicate query spec, single-source-of-truth tables, and migrations. Drizzle stays an internal detail.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-db-v<version> && git push --tags' && exit 1"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@gobing-ai/ts-runtime": "^0.3.
|
|
70
|
-
"@gobing-ai/ts-utils": "^0.3.
|
|
69
|
+
"@gobing-ai/ts-runtime": "^0.3.2",
|
|
70
|
+
"@gobing-ai/ts-utils": "^0.3.2"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"drizzle-orm": ">=0.38.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAbsolutePath, resolvePath } from '@gobing-ai/ts-runtime';
|
|
2
2
|
import { Database } from '@gobing-ai/ts-runtime/bun-sqlite';
|
|
3
3
|
import { type BunSQLiteDatabase, drizzle } from 'drizzle-orm/bun-sqlite';
|
|
4
4
|
import type { DbAdapter, InternalDb } from '../adapter';
|
|
@@ -61,8 +61,8 @@ export class BunSqliteAdapter implements DbAdapter {
|
|
|
61
61
|
const pragmas = { ...DEFAULT_PRAGMAS, ...options?.pragmas };
|
|
62
62
|
|
|
63
63
|
// Resolve relative paths
|
|
64
|
-
if (dbPath !== ':memory:' && !
|
|
65
|
-
dbPath =
|
|
64
|
+
if (dbPath !== ':memory:' && !isAbsolutePath(dbPath)) {
|
|
65
|
+
dbPath = resolvePath(dbPath);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
this.sqlite = new Database(dbPath, { create: true });
|
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
* DO NOT EDIT MANUALLY. Regenerate with: bun run scripts/embed-migrations.ts
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
/** A single embedded migration with its identifying tag, SQL, and content hash. */
|
|
10
11
|
export interface EmbeddedMigration {
|
|
11
12
|
tag: string;
|
|
12
13
|
sql: string;
|
|
13
14
|
hash: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
/** Auto-generated array of all embedded migrations, ordered by tag. */
|
|
16
18
|
export const embeddedMigrations: EmbeddedMigration[] = [
|
|
17
19
|
{
|
|
18
20
|
tag: '0000_init',
|
package/src/entity-dao.ts
CHANGED
|
@@ -57,6 +57,25 @@ export interface CursorListSpec {
|
|
|
57
57
|
includeDeleted?: boolean;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* A structural validator (e.g. a zod schema). Kept structural so EntityDao never
|
|
62
|
+
* imports zod/drizzle-zod — consumers wire `defineTable().insertSchema` here when
|
|
63
|
+
* they want boundary validation.
|
|
64
|
+
*/
|
|
65
|
+
export interface DaoValidator {
|
|
66
|
+
parse(input: unknown): unknown;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Optional EntityDao configuration. */
|
|
70
|
+
export interface EntityDaoOptions {
|
|
71
|
+
/** Schema used to validate input before `create`/`createMany`/`upsert`. */
|
|
72
|
+
insertSchema?: DaoValidator;
|
|
73
|
+
/** Schema used to validate input before `update`. Falls back to `insertSchema` when absent. */
|
|
74
|
+
updateSchema?: DaoValidator;
|
|
75
|
+
/** Which write operations validate. Default: all (`create`, `createMany`, `upsert`, `update`) when a schema is present. */
|
|
76
|
+
validateOn?: ('create' | 'createMany' | 'upsert' | 'update')[];
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
/**
|
|
61
80
|
* Generic CRUD base class for entity DAOs — the STRUCTURED tier of the facade.
|
|
62
81
|
*
|
|
@@ -80,25 +99,6 @@ export interface CursorListSpec {
|
|
|
80
99
|
* }
|
|
81
100
|
* ```
|
|
82
101
|
*/
|
|
83
|
-
/**
|
|
84
|
-
* A structural validator (e.g. a zod schema). Kept structural so EntityDao never
|
|
85
|
-
* imports zod/drizzle-zod — consumers wire `defineTable().insertSchema` here when
|
|
86
|
-
* they want boundary validation.
|
|
87
|
-
*/
|
|
88
|
-
export interface DaoValidator {
|
|
89
|
-
parse(input: unknown): unknown;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Optional EntityDao configuration. */
|
|
93
|
-
export interface EntityDaoOptions {
|
|
94
|
-
/** Schema used to validate input before `create`/`createMany`/`upsert`. */
|
|
95
|
-
insertSchema?: DaoValidator;
|
|
96
|
-
/** Schema used to validate input before `update`. Falls back to `insertSchema` when absent. */
|
|
97
|
-
updateSchema?: DaoValidator;
|
|
98
|
-
/** Which write operations validate. Default: all (`create`, `createMany`, `upsert`, `update`) when a schema is present. */
|
|
99
|
-
validateOn?: ('create' | 'createMany' | 'upsert' | 'update')[];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
102
|
export class EntityDao<TTable extends EntityTable, TPK extends SQLiteColumn> extends BaseDao {
|
|
103
103
|
readonly table: TTable;
|
|
104
104
|
/** Primary key columns. A single-element array for single-PK tables, multiple for composite. */
|
package/src/index.ts
CHANGED
|
@@ -26,15 +26,4 @@ export {
|
|
|
26
26
|
type Predicate,
|
|
27
27
|
} from './query-spec';
|
|
28
28
|
export { QueueJobDao, type QueueJobRecord, type QueueStats } from './queue-job-dao';
|
|
29
|
-
export {
|
|
30
|
-
appendOnlyColumns,
|
|
31
|
-
buildAppendOnlyColumns,
|
|
32
|
-
buildStandardColumns,
|
|
33
|
-
buildStandardColumnsWithSoftDelete,
|
|
34
|
-
nowTimestamp,
|
|
35
|
-
standardColumns,
|
|
36
|
-
standardColumnsWithSoftDelete,
|
|
37
|
-
} from './schema/common';
|
|
38
|
-
export { inboxMessages } from './schema/inbox-messages';
|
|
39
|
-
export { queueJobs } from './schema/queue-jobs';
|
|
40
29
|
export type { SpanContext } from './span-context';
|
package/src/migrate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
1
|
import type { FileSystem } from '@gobing-ai/ts-runtime';
|
|
2
|
+
import { getProcessCwd, resolvePath } from '@gobing-ai/ts-runtime';
|
|
3
3
|
|
|
4
4
|
import type { DbAdapter } from './adapter';
|
|
5
5
|
import { embeddedMigrations } from './embedded-migrations';
|
|
@@ -135,7 +135,7 @@ export async function applyMigrations(adapter: DbAdapter, options?: MigrationOpt
|
|
|
135
135
|
|
|
136
136
|
await ensureJournalTable(adapter, table);
|
|
137
137
|
|
|
138
|
-
const folder = options?.migrationsFolder ??
|
|
138
|
+
const folder = options?.migrationsFolder ?? resolvePath(getProcessCwd(), 'drizzle');
|
|
139
139
|
|
|
140
140
|
// File-based migrations: attempt only if the drizzle/ folder is present.
|
|
141
141
|
// With an injected fs we get a definitive answer (await the Promise — a bare
|