@firtoz/drizzle-sqlite-wasm 0.2.9 → 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,13 @@
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
+
3
11
  ## 0.2.9
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/drizzle-sqlite-wasm",
3
- "version": "0.2.9",
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,11 +69,12 @@
69
69
  "access": "public"
70
70
  },
71
71
  "dependencies": {
72
- "@firtoz/drizzle-utils": "^0.3.3",
72
+ "@firtoz/db-helpers": "^1.0.0",
73
+ "@firtoz/drizzle-utils": "^1.0.0",
73
74
  "@firtoz/maybe-error": "^1.5.2",
74
75
  "@firtoz/worker-helper": "^1.3.4",
75
76
  "@sqlite.org/sqlite-wasm": "^3.51.2-build6",
76
- "@tanstack/db": "^0.5.25",
77
+ "@tanstack/db": "^0.5.26",
77
78
  "drizzle-orm": "^0.45.1",
78
79
  "drizzle-valibot": "^0.4.2",
79
80
  "react": "^19.2.4",
@@ -82,6 +83,6 @@
82
83
  },
83
84
  "devDependencies": {
84
85
  "@standard-schema/spec": "^1.1.0",
85
- "@types/react": "^19.2.13"
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
- if (expression.type === "ref") {
196
- // PropRef - reference to a column
197
- const propRef = expression as IR.PropRef;
198
- const columnName = propRef.path[propRef.path.length - 1];
199
- const column = table[columnName as keyof typeof table];
200
-
201
- if (!column || !(column instanceof SQLiteColumn)) {
202
- console.error("[SQLite Collection] Column lookup failed:", {
203
- columnName,
204
- column,
205
- tableKeys: Object.keys(table),
206
- hasColumn: columnName in table,
207
- });
208
- throw new Error(`Column ${String(columnName)} not found in table`);
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
- switch (func.name) {
229
- case "eq":
230
- return eq(args[0], args[1]);
231
- case "ne":
232
- return ne(args[0], args[1]);
233
- case "gt":
234
- return gt(args[0], args[1]);
235
- case "gte":
236
- return gte(args[0], args[1]);
237
- case "lt":
238
- return lt(args[0], args[1]);
239
- case "lte":
240
- return lte(args[0], args[1]);
241
- case "and": {
242
- const result = and(...args);
243
- if (!result) {
244
- throw new Error("Invalid 'and' expression - no arguments provided");
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
- return result;
247
- }
248
- case "or": {
249
- const result = or(...args);
250
- if (!result) {
251
- throw new Error("Invalid 'or' expression - no arguments provided");
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
- return result;
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
- type: mutation.type,
209
- id: mutation.key,
210
- data:
211
- mutation.type === "delete"
212
- ? undefined
213
- : mutation.type === "update"
214
- ? mutation.changes
215
- : mutation.modified,
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(