@firtoz/drizzle-utils 1.2.1 → 1.3.0
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/CHANGELOG.md +14 -0
- package/README.md +8 -1
- package/dist/chunk-7RBDVFVG.js +408 -0
- package/dist/chunk-7RBDVFVG.js.map +1 -0
- package/dist/chunk-J7DNZ25N.js +3 -0
- package/dist/chunk-J7DNZ25N.js.map +1 -0
- package/dist/chunk-JM254VLB.js +92 -0
- package/dist/chunk-JM254VLB.js.map +1 -0
- package/dist/chunk-LIICLRMB.js +45 -0
- package/dist/chunk-LIICLRMB.js.map +1 -0
- package/dist/chunk-TOYHUPFU.js +91 -0
- package/dist/chunk-TOYHUPFU.js.map +1 -0
- package/dist/collection-utils.d.ts +106 -0
- package/dist/collection-utils.js +3 -0
- package/dist/collection-utils.js.map +1 -0
- package/dist/drizzle-sqlite-table-collection.d.ts +19 -0
- package/dist/drizzle-sqlite-table-collection.js +3 -0
- package/dist/drizzle-sqlite-table-collection.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/sqlite-table-sync/convert-ir.d.ts +10 -0
- package/dist/sqlite-table-sync/convert-ir.js +3 -0
- package/dist/sqlite-table-sync/convert-ir.js.map +1 -0
- package/dist/sqlite-table-sync/index.d.ts +11 -0
- package/dist/sqlite-table-sync/index.js +5 -0
- package/dist/sqlite-table-sync/index.js.map +1 -0
- package/dist/sqlite-table-sync/sqlite-table-sync-backend.d.ts +28 -0
- package/dist/sqlite-table-sync/sqlite-table-sync-backend.js +4 -0
- package/dist/sqlite-table-sync/sqlite-table-sync-backend.js.map +1 -0
- package/dist/sqlite-table-sync/types.d.ts +59 -0
- package/dist/sqlite-table-sync/types.js +3 -0
- package/dist/sqlite-table-sync/types.js.map +1 -0
- package/dist/syncableTable.d.ts +49 -0
- package/dist/syncableTable.js +3 -0
- package/dist/syncableTable.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +23 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"convert-ir.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { SQLInterceptor, SQLOperation } from './types.js';
|
|
2
|
+
export { convertBasicExpressionToDrizzle, convertOrderByToDrizzle } from './convert-ir.js';
|
|
3
|
+
export { SqliteDriverMode, SqliteTableSyncBackendConfig, createSqliteTableSyncBackend } from './sqlite-table-sync-backend.js';
|
|
4
|
+
import '@tanstack/db';
|
|
5
|
+
import 'drizzle-orm';
|
|
6
|
+
import '../collection-utils.js';
|
|
7
|
+
import 'drizzle-valibot';
|
|
8
|
+
import '@firtoz/db-helpers';
|
|
9
|
+
import 'valibot';
|
|
10
|
+
import '../syncableTable.js';
|
|
11
|
+
import 'drizzle-orm/sqlite-core';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import '../chunk-J7DNZ25N.js';
|
|
2
|
+
export { createSqliteTableSyncBackend } from '../chunk-7RBDVFVG.js';
|
|
3
|
+
export { convertBasicExpressionToDrizzle, convertOrderByToDrizzle } from '../chunk-JM254VLB.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SyncBackend } from '../collection-utils.js';
|
|
2
|
+
import { TableWithRequiredFields } from '../syncableTable.js';
|
|
3
|
+
import { SQLInterceptor } from './types.js';
|
|
4
|
+
import 'drizzle-orm';
|
|
5
|
+
import 'drizzle-valibot';
|
|
6
|
+
import '@firtoz/db-helpers';
|
|
7
|
+
import 'valibot';
|
|
8
|
+
import '@tanstack/db';
|
|
9
|
+
import 'drizzle-orm/sqlite-core';
|
|
10
|
+
|
|
11
|
+
type SqliteDriverMode = "async" | "sync";
|
|
12
|
+
interface SqliteTableSyncBackendConfig<TTable extends TableWithRequiredFields> {
|
|
13
|
+
/** drizzle-orm SQLite database (async WASM/libsql or sync Durable Object) */
|
|
14
|
+
drizzle: any;
|
|
15
|
+
table: TTable;
|
|
16
|
+
tableName: string;
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
checkpoint?: () => Promise<void>;
|
|
19
|
+
interceptor?: SQLInterceptor;
|
|
20
|
+
/**
|
|
21
|
+
* `async`: libsql/WASM — use `await db.transaction(async (tx) => …)`.
|
|
22
|
+
* `sync`: Cloudflare DO SQLite — `transactionSync` requires a **synchronous** callback; use `.all()` / `.run()` on builders inside `tx`.
|
|
23
|
+
*/
|
|
24
|
+
driverMode: SqliteDriverMode;
|
|
25
|
+
}
|
|
26
|
+
declare function createSqliteTableSyncBackend<TTable extends TableWithRequiredFields>(config: SqliteTableSyncBackendConfig<TTable>): SyncBackend<TTable>;
|
|
27
|
+
|
|
28
|
+
export { type SqliteDriverMode, type SqliteTableSyncBackendConfig, createSqliteTableSyncBackend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sqlite-table-sync-backend.js"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation tracking for SQLite-backed TanStack sync backends.
|
|
3
|
+
* Uses discriminated unions so TypeScript can narrow on `type`.
|
|
4
|
+
*/
|
|
5
|
+
type SQLOperation = {
|
|
6
|
+
type: "select-all";
|
|
7
|
+
tableName: string;
|
|
8
|
+
itemsReturned: unknown[];
|
|
9
|
+
itemCount: number;
|
|
10
|
+
context: string;
|
|
11
|
+
sql?: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
} | {
|
|
14
|
+
type: "select-where";
|
|
15
|
+
tableName: string;
|
|
16
|
+
whereClause: string;
|
|
17
|
+
itemsReturned: unknown[];
|
|
18
|
+
itemCount: number;
|
|
19
|
+
context: string;
|
|
20
|
+
sql?: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: "write";
|
|
24
|
+
tableName: string;
|
|
25
|
+
itemsWritten: unknown[];
|
|
26
|
+
writeCount: number;
|
|
27
|
+
context: string;
|
|
28
|
+
timestamp: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: "insert";
|
|
31
|
+
tableName: string;
|
|
32
|
+
item: unknown;
|
|
33
|
+
sql?: string;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: "update";
|
|
37
|
+
tableName: string;
|
|
38
|
+
updates: unknown;
|
|
39
|
+
sql?: string;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
} | {
|
|
42
|
+
type: "delete";
|
|
43
|
+
tableName: string;
|
|
44
|
+
sql?: string;
|
|
45
|
+
timestamp: number;
|
|
46
|
+
} | {
|
|
47
|
+
type: "raw-query";
|
|
48
|
+
sql: string;
|
|
49
|
+
params?: unknown[];
|
|
50
|
+
method: string;
|
|
51
|
+
rowCount: number;
|
|
52
|
+
context: string;
|
|
53
|
+
timestamp: number;
|
|
54
|
+
};
|
|
55
|
+
interface SQLInterceptor {
|
|
56
|
+
onOperation?: (operation: SQLOperation) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type { SQLInterceptor, SQLOperation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as drizzle_orm from 'drizzle-orm';
|
|
2
|
+
import { BuildColumns } from 'drizzle-orm';
|
|
3
|
+
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
4
|
+
import { SQLiteTableWithColumns, TableConfig, SQLiteColumnBuilderBase, SQLiteTableExtraConfigValue } from 'drizzle-orm/sqlite-core';
|
|
5
|
+
import { TableId } from './collection-utils.js';
|
|
6
|
+
import 'drizzle-valibot';
|
|
7
|
+
import '@firtoz/db-helpers';
|
|
8
|
+
import 'valibot';
|
|
9
|
+
import '@tanstack/db';
|
|
10
|
+
|
|
11
|
+
declare const createTableIdColumn: <TTableName extends string>() => drizzle_orm.HasRuntimeDefault<drizzle_orm.HasDefault<drizzle_orm.$Type<drizzle_orm.IsPrimaryKey<drizzle_orm.NotNull<drizzle_orm_sqlite_core.SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>, TableId<TTableName>>>>;
|
|
12
|
+
declare const createdAtColumn: drizzle_orm.NotNull<drizzle_orm.HasRuntimeDefault<drizzle_orm.HasDefault<drizzle_orm_sqlite_core.SQLiteTimestampBuilderInitial<"createdAt">>>>;
|
|
13
|
+
declare const updatedAtColumn: drizzle_orm.NotNull<drizzle_orm.HasRuntimeDefault<drizzle_orm.HasDefault<drizzle_orm_sqlite_core.SQLiteTimestampBuilderInitial<"updatedAt">>>>;
|
|
14
|
+
declare const deletedAtColumn: drizzle_orm_sqlite_core.SQLiteTimestampBuilderInitial<"deletedAt">;
|
|
15
|
+
declare const syncableTable: <TTableName extends string, TColumns extends Record<string, SQLiteColumnBuilderBase> & {
|
|
16
|
+
id?: never;
|
|
17
|
+
createdAt?: never;
|
|
18
|
+
updatedAt?: never;
|
|
19
|
+
deletedAt?: never;
|
|
20
|
+
}>(tableName: TTableName, columns: TColumns, extraConfig?: (self: BuildColumns<TTableName, Omit<TColumns, "id" | "createdAt" | "updatedAt" | "deletedAt"> & {
|
|
21
|
+
id: ReturnType<typeof createTableIdColumn<TTableName>>;
|
|
22
|
+
createdAt: typeof createdAtColumn;
|
|
23
|
+
updatedAt: typeof updatedAtColumn;
|
|
24
|
+
deletedAt: typeof deletedAtColumn;
|
|
25
|
+
}, "sqlite">) => SQLiteTableExtraConfigValue[]) => SQLiteTableWithColumns<{
|
|
26
|
+
name: TTableName;
|
|
27
|
+
schema: undefined;
|
|
28
|
+
columns: Omit<TColumns, "id" | "createdAt" | "updatedAt" | "deletedAt"> & {
|
|
29
|
+
id: ReturnType<typeof createTableIdColumn<TTableName>>;
|
|
30
|
+
createdAt: typeof createdAtColumn;
|
|
31
|
+
updatedAt: typeof updatedAtColumn;
|
|
32
|
+
deletedAt: typeof deletedAtColumn;
|
|
33
|
+
} extends infer T extends Record<string, drizzle_orm.ColumnBuilderBase<drizzle_orm.ColumnBuilderBaseConfig<drizzle_orm.ColumnDataType, string>, object>> ? { [Key in keyof T]: drizzle_orm.BuildColumn<TTableName_1, {
|
|
34
|
+
_: Omit<T[Key]["_"], "name"> & {
|
|
35
|
+
name: T[Key]["_"]["name"] extends "" ? drizzle_orm.Assume<Key, string> : T[Key]["_"]["name"];
|
|
36
|
+
};
|
|
37
|
+
}, TDialect>; } : never;
|
|
38
|
+
dialect: "sqlite";
|
|
39
|
+
}>;
|
|
40
|
+
type TableWithRequiredFields = SQLiteTableWithColumns<Pick<TableConfig, "name" | "schema" | "dialect"> & {
|
|
41
|
+
columns: BuildColumns<string, {
|
|
42
|
+
id: ReturnType<typeof createTableIdColumn<string>>;
|
|
43
|
+
createdAt: typeof createdAtColumn;
|
|
44
|
+
updatedAt: typeof updatedAtColumn;
|
|
45
|
+
deletedAt: typeof deletedAtColumn;
|
|
46
|
+
}, "sqlite">;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export { type TableWithRequiredFields, createdAtColumn, deletedAtColumn, syncableTable, updatedAtColumn };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"syncableTable.js"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
interface JournalEntry {
|
|
2
|
+
idx: number;
|
|
3
|
+
version: string;
|
|
4
|
+
when: number;
|
|
5
|
+
tag: string;
|
|
6
|
+
breakpoints: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface Journal {
|
|
9
|
+
version: string;
|
|
10
|
+
dialect: string;
|
|
11
|
+
entries: JournalEntry[];
|
|
12
|
+
}
|
|
13
|
+
type SqliteColumnType = "text" | "integer" | "real" | "blob" | "numeric";
|
|
14
|
+
interface ColumnDefinition {
|
|
15
|
+
name: string;
|
|
16
|
+
type: SqliteColumnType | string;
|
|
17
|
+
primaryKey: boolean;
|
|
18
|
+
notNull: boolean;
|
|
19
|
+
autoincrement: boolean;
|
|
20
|
+
default?: string | number | boolean | null;
|
|
21
|
+
}
|
|
22
|
+
interface IndexDefinition {
|
|
23
|
+
name: string;
|
|
24
|
+
columns: string[];
|
|
25
|
+
isUnique: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface ForeignKeyDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
tableFrom: string;
|
|
30
|
+
tableTo: string;
|
|
31
|
+
columnsFrom: string[];
|
|
32
|
+
columnsTo: string[];
|
|
33
|
+
onDelete?: "cascade" | "set null" | "set default" | "restrict" | "no action";
|
|
34
|
+
onUpdate?: "cascade" | "set null" | "set default" | "restrict" | "no action";
|
|
35
|
+
}
|
|
36
|
+
interface CompositePrimaryKeyDefinition {
|
|
37
|
+
name: string;
|
|
38
|
+
columns: string[];
|
|
39
|
+
}
|
|
40
|
+
interface UniqueConstraintDefinition {
|
|
41
|
+
name: string;
|
|
42
|
+
columns: string[];
|
|
43
|
+
}
|
|
44
|
+
interface CheckConstraintDefinition {
|
|
45
|
+
name: string;
|
|
46
|
+
value: string;
|
|
47
|
+
}
|
|
48
|
+
interface TableDefinition {
|
|
49
|
+
name: string;
|
|
50
|
+
columns: Record<string, ColumnDefinition>;
|
|
51
|
+
indexes: Record<string, IndexDefinition>;
|
|
52
|
+
foreignKeys: Record<string, ForeignKeyDefinition>;
|
|
53
|
+
compositePrimaryKeys: Record<string, CompositePrimaryKeyDefinition>;
|
|
54
|
+
uniqueConstraints: Record<string, UniqueConstraintDefinition>;
|
|
55
|
+
checkConstraints: Record<string, CheckConstraintDefinition>;
|
|
56
|
+
}
|
|
57
|
+
interface ViewDefinition {
|
|
58
|
+
name: string;
|
|
59
|
+
query: string;
|
|
60
|
+
columns: Record<string, {
|
|
61
|
+
name: string;
|
|
62
|
+
type: string;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
interface EnumDefinition {
|
|
66
|
+
name: string;
|
|
67
|
+
values: string[];
|
|
68
|
+
}
|
|
69
|
+
interface SnapshotMeta {
|
|
70
|
+
schemas: Record<string, unknown>;
|
|
71
|
+
tables: Record<string, unknown>;
|
|
72
|
+
columns: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
interface SnapshotInternal {
|
|
75
|
+
indexes: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface Snapshot {
|
|
78
|
+
version: string;
|
|
79
|
+
dialect: string;
|
|
80
|
+
id: string;
|
|
81
|
+
prevId: string;
|
|
82
|
+
tables: Record<string, TableDefinition>;
|
|
83
|
+
views: Record<string, ViewDefinition>;
|
|
84
|
+
enums: Record<string, EnumDefinition>;
|
|
85
|
+
_meta: SnapshotMeta;
|
|
86
|
+
internal: SnapshotInternal;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type { CheckConstraintDefinition, ColumnDefinition, CompositePrimaryKeyDefinition, EnumDefinition, ForeignKeyDefinition, IndexDefinition, Journal, JournalEntry, Snapshot, SnapshotInternal, SnapshotMeta, SqliteColumnType, TableDefinition, UniqueConstraintDefinition, ViewDefinition };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/drizzle-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared utilities and types for Drizzle-based packages",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
7
|
-
"types": "./
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./
|
|
12
|
-
"import": "./
|
|
13
|
-
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./sqlite-table-sync": {
|
|
15
|
+
"types": "./dist/sqlite-table-sync/index.d.ts",
|
|
16
|
+
"import": "./dist/sqlite-table-sync/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./sqlite-table-sync/*": {
|
|
19
|
+
"types": "./dist/sqlite-table-sync/*.d.ts",
|
|
20
|
+
"import": "./dist/sqlite-table-sync/*.js"
|
|
14
21
|
},
|
|
15
22
|
"./*": {
|
|
16
|
-
"types": "./
|
|
17
|
-
"import": "./
|
|
18
|
-
"require": "./src/*.ts"
|
|
23
|
+
"types": "./dist/*.d.ts",
|
|
24
|
+
"import": "./dist/*.js"
|
|
19
25
|
}
|
|
20
26
|
},
|
|
21
27
|
"files": [
|
|
28
|
+
"dist/**/*.js",
|
|
29
|
+
"dist/**/*.js.map",
|
|
30
|
+
"dist/**/*.d.ts",
|
|
22
31
|
"src/**/*.ts",
|
|
23
32
|
"!src/**/*.test.ts",
|
|
24
33
|
"README.md",
|
|
25
34
|
"CHANGELOG.md"
|
|
26
35
|
],
|
|
27
36
|
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"prepack": "bun run build",
|
|
28
39
|
"typecheck": "tsgo --noEmit -p ./tsconfig.json",
|
|
29
40
|
"lint": "biome check --write src",
|
|
30
41
|
"lint:ci": "biome ci src",
|
|
@@ -65,7 +76,7 @@
|
|
|
65
76
|
"valibot": "^1.3.1"
|
|
66
77
|
},
|
|
67
78
|
"dependencies": {
|
|
68
|
-
"@firtoz/db-helpers": "^2.
|
|
69
|
-
"@firtoz/maybe-error": "^1.
|
|
79
|
+
"@firtoz/db-helpers": "^2.2.0",
|
|
80
|
+
"@firtoz/maybe-error": "^1.6.0"
|
|
70
81
|
}
|
|
71
82
|
}
|