@firtoz/drizzle-sqlite-wasm 0.2.8 → 0.2.10
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
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @firtoz/drizzle-sqlite-wasm
|
|
2
2
|
|
|
3
|
+
## 0.2.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`3c7ce1d`](https://github.com/firtoz/fullstack-toolkit/commit/3c7ce1dbca5c5396386db9927ae7f5e19a562cf6), [`3c7ce1d`](https://github.com/firtoz/fullstack-toolkit/commit/3c7ce1dbca5c5396386db9927ae7f5e19a562cf6)]:
|
|
8
|
+
- @firtoz/db-helpers@1.0.0
|
|
9
|
+
- @firtoz/drizzle-utils@1.0.0
|
|
10
|
+
|
|
11
|
+
## 0.2.9
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`ec365af`](https://github.com/firtoz/fullstack-toolkit/commit/ec365af8c17bcd7efc2b0cf9b3bed5225b853e72)]:
|
|
16
|
+
- @firtoz/drizzle-utils@0.3.3
|
|
17
|
+
- @firtoz/worker-helper@1.3.4
|
|
18
|
+
|
|
3
19
|
## 0.2.8
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/drizzle-sqlite-wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Drizzle SQLite WASM bindings",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -69,19 +69,20 @@
|
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@firtoz/
|
|
72
|
+
"@firtoz/db-helpers": "^1.0.0",
|
|
73
|
+
"@firtoz/drizzle-utils": "^1.0.0",
|
|
73
74
|
"@firtoz/maybe-error": "^1.5.2",
|
|
74
|
-
"@firtoz/worker-helper": "^1.3.
|
|
75
|
-
"@sqlite.org/sqlite-wasm": "^3.51.2-
|
|
76
|
-
"@tanstack/db": "^0.5.
|
|
75
|
+
"@firtoz/worker-helper": "^1.3.4",
|
|
76
|
+
"@sqlite.org/sqlite-wasm": "^3.51.2-build6",
|
|
77
|
+
"@tanstack/db": "^0.5.26",
|
|
77
78
|
"drizzle-orm": "^0.45.1",
|
|
78
79
|
"drizzle-valibot": "^0.4.2",
|
|
79
|
-
"react": "^19.2.
|
|
80
|
+
"react": "^19.2.4",
|
|
80
81
|
"valibot": "^1.2.0",
|
|
81
82
|
"zod": "^4.3.6"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
85
|
"@standard-schema/spec": "^1.1.0",
|
|
85
|
-
"@types/react": "^19.2.
|
|
86
|
+
"@types/react": "^19.2.14"
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -30,12 +30,12 @@ import {
|
|
|
30
30
|
type SQLiteInsertValue,
|
|
31
31
|
SQLiteColumn,
|
|
32
32
|
} from "drizzle-orm/sqlite-core";
|
|
33
|
+
import type { CollectionUtils } from "@firtoz/db-helpers";
|
|
33
34
|
import type {
|
|
34
35
|
SelectSchema,
|
|
35
36
|
TableWithRequiredFields,
|
|
36
37
|
BaseSyncConfig,
|
|
37
38
|
SyncBackend,
|
|
38
|
-
CollectionUtils,
|
|
39
39
|
} from "@firtoz/drizzle-utils";
|
|
40
40
|
import {
|
|
41
41
|
createSyncFunction,
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
createGetKeyFunction,
|
|
44
44
|
createCollectionConfig,
|
|
45
45
|
} from "@firtoz/drizzle-utils";
|
|
46
|
+
import { exhaustiveGuard } from "@firtoz/maybe-error";
|
|
46
47
|
import type * as v from "valibot";
|
|
47
48
|
|
|
48
49
|
export type AnyDrizzleDatabase = BaseSQLiteDatabase<
|
|
@@ -192,87 +193,81 @@ function convertBasicExpressionToDrizzle<TTable extends Table>(
|
|
|
192
193
|
expression: IR.BasicExpression,
|
|
193
194
|
table: TTable,
|
|
194
195
|
): SQL {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// Drizzle columns can be used directly in expressions
|
|
212
|
-
return column as unknown as SQL;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (expression.type === "val") {
|
|
216
|
-
// Value - literal value
|
|
217
|
-
const value = expression as IR.Value;
|
|
218
|
-
return sql`${value.value}`;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (expression.type === "func") {
|
|
222
|
-
// Func - function call like eq, gt, lt, etc.
|
|
223
|
-
const func = expression as IR.Func;
|
|
224
|
-
const args = func.args.map((arg) =>
|
|
225
|
-
convertBasicExpressionToDrizzle(arg, table),
|
|
226
|
-
);
|
|
196
|
+
switch (expression.type) {
|
|
197
|
+
case "ref": {
|
|
198
|
+
const propRef = expression;
|
|
199
|
+
const columnName = propRef.path[propRef.path.length - 1];
|
|
200
|
+
const column = table[columnName as keyof typeof table];
|
|
201
|
+
|
|
202
|
+
if (!column || !(column instanceof SQLiteColumn)) {
|
|
203
|
+
console.error("[SQLite Collection] Column lookup failed:", {
|
|
204
|
+
columnName,
|
|
205
|
+
column,
|
|
206
|
+
tableKeys: Object.keys(table),
|
|
207
|
+
hasColumn: columnName in table,
|
|
208
|
+
});
|
|
209
|
+
throw new Error(`Column ${String(columnName)} not found in table`);
|
|
210
|
+
}
|
|
227
211
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
212
|
+
return column as unknown as SQL;
|
|
213
|
+
}
|
|
214
|
+
case "val": {
|
|
215
|
+
const value = expression;
|
|
216
|
+
return sql`${value.value}`;
|
|
217
|
+
}
|
|
218
|
+
case "func": {
|
|
219
|
+
const func = expression;
|
|
220
|
+
const args = func.args.map((arg) =>
|
|
221
|
+
convertBasicExpressionToDrizzle(arg, table),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
switch (func.name) {
|
|
225
|
+
case "eq":
|
|
226
|
+
return eq(args[0], args[1]);
|
|
227
|
+
case "ne":
|
|
228
|
+
return ne(args[0], args[1]);
|
|
229
|
+
case "gt":
|
|
230
|
+
return gt(args[0], args[1]);
|
|
231
|
+
case "gte":
|
|
232
|
+
return gte(args[0], args[1]);
|
|
233
|
+
case "lt":
|
|
234
|
+
return lt(args[0], args[1]);
|
|
235
|
+
case "lte":
|
|
236
|
+
return lte(args[0], args[1]);
|
|
237
|
+
case "and": {
|
|
238
|
+
const result = and(...args);
|
|
239
|
+
if (!result) {
|
|
240
|
+
throw new Error("Invalid 'and' expression - no arguments provided");
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
245
243
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
244
|
+
case "or": {
|
|
245
|
+
const result = or(...args);
|
|
246
|
+
if (!result) {
|
|
247
|
+
throw new Error("Invalid 'or' expression - no arguments provided");
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
252
250
|
}
|
|
253
|
-
|
|
251
|
+
case "not":
|
|
252
|
+
return not(args[0]);
|
|
253
|
+
case "isNull":
|
|
254
|
+
return isNull(args[0]);
|
|
255
|
+
case "isNotNull":
|
|
256
|
+
return isNotNull(args[0]);
|
|
257
|
+
case "like":
|
|
258
|
+
return like(args[0], args[1]);
|
|
259
|
+
case "in":
|
|
260
|
+
return inArray(args[0], args[1]);
|
|
261
|
+
case "isUndefined":
|
|
262
|
+
// isUndefined is same as isNull in SQLite
|
|
263
|
+
return isNull(args[0]);
|
|
264
|
+
default:
|
|
265
|
+
throw new Error(`Unsupported function: ${func.name}`);
|
|
254
266
|
}
|
|
255
|
-
case "not":
|
|
256
|
-
return not(args[0]);
|
|
257
|
-
case "isNull":
|
|
258
|
-
return isNull(args[0]);
|
|
259
|
-
case "isNotNull":
|
|
260
|
-
return isNotNull(args[0]);
|
|
261
|
-
case "like":
|
|
262
|
-
return like(args[0], args[1]);
|
|
263
|
-
case "in":
|
|
264
|
-
return inArray(args[0], args[1]);
|
|
265
|
-
case "isUndefined":
|
|
266
|
-
// isUndefined is same as isNull in SQLite
|
|
267
|
-
return isNull(args[0]);
|
|
268
|
-
default:
|
|
269
|
-
throw new Error(`Unsupported function: ${func.name}`);
|
|
270
267
|
}
|
|
268
|
+
default:
|
|
269
|
+
exhaustiveGuard(expression);
|
|
271
270
|
}
|
|
272
|
-
|
|
273
|
-
throw new Error(
|
|
274
|
-
`Unsupported expression type: ${(expression as { type: string }).type}`,
|
|
275
|
-
);
|
|
276
271
|
}
|
|
277
272
|
|
|
278
273
|
/**
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
InferSchemaOutput,
|
|
10
10
|
InferSchemaInput,
|
|
11
11
|
} from "@tanstack/db";
|
|
12
|
+
import { exhaustiveGuard } from "@firtoz/maybe-error";
|
|
12
13
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
13
14
|
|
|
14
15
|
interface WebSocketMessage<T> {
|
|
@@ -155,6 +156,8 @@ export function webSocketCollectionOptions<TSchema extends StandardSchemaV1>(
|
|
|
155
156
|
commit();
|
|
156
157
|
}
|
|
157
158
|
break;
|
|
159
|
+
default:
|
|
160
|
+
exhaustiveGuard(message.type);
|
|
158
161
|
}
|
|
159
162
|
};
|
|
160
163
|
|
|
@@ -204,16 +207,30 @@ export function webSocketCollectionOptions<TSchema extends StandardSchemaV1>(
|
|
|
204
207
|
const transactionId = crypto.randomUUID();
|
|
205
208
|
|
|
206
209
|
// Convert all mutations in the transaction to the wire format
|
|
207
|
-
const mutations = params.transaction.mutations.map((mutation) =>
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
const mutations = params.transaction.mutations.map((mutation) => {
|
|
211
|
+
switch (mutation.type) {
|
|
212
|
+
case "insert":
|
|
213
|
+
return {
|
|
214
|
+
type: mutation.type,
|
|
215
|
+
id: mutation.key,
|
|
216
|
+
data: mutation.modified,
|
|
217
|
+
};
|
|
218
|
+
case "update":
|
|
219
|
+
return {
|
|
220
|
+
type: mutation.type,
|
|
221
|
+
id: mutation.key,
|
|
222
|
+
data: mutation.changes,
|
|
223
|
+
};
|
|
224
|
+
case "delete":
|
|
225
|
+
return {
|
|
226
|
+
type: mutation.type,
|
|
227
|
+
id: mutation.key,
|
|
228
|
+
data: undefined,
|
|
229
|
+
};
|
|
230
|
+
default:
|
|
231
|
+
return exhaustiveGuard(mutation);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
217
234
|
|
|
218
235
|
// Send the entire transaction at once
|
|
219
236
|
ws.send(
|