durable-db 0.1.6 → 0.1.8

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.
@@ -0,0 +1,6 @@
1
+ import { type } from "arktype";
2
+
3
+ //#region src/arktypeConfig.d.ts
4
+ declare const type$1: typeof type;
5
+ //#endregion
6
+ export { type$1 as t };
@@ -7434,7 +7434,7 @@ $arkTypeRegistry.typeAttachments = {
7434
7434
  Array: keywords.Array.root,
7435
7435
  Date: keywords.Date
7436
7436
  };
7437
- const type = Object.assign(ark.type, $arkTypeRegistry.typeAttachments);
7437
+ const type$1 = Object.assign(ark.type, $arkTypeRegistry.typeAttachments);
7438
7438
  const match = ark.match;
7439
7439
  const fn = ark.fn;
7440
7440
  const generic = ark.generic;
@@ -7442,5 +7442,9 @@ const schema = ark.schema;
7442
7442
  const define = ark.define;
7443
7443
  const declare = ark.declare;
7444
7444
 
7445
+ //#endregion
7446
+ //#region src/arktypeConfig.ts
7447
+ const type = scope({}, { jitless: true }).type;
7448
+
7445
7449
  //#endregion
7446
7450
  export { type as t };
package/dist/cli/bin.js CHANGED
@@ -3,9 +3,9 @@ import "../debug-DmBrUmwe.js";
3
3
  import "../state-B4v8ICj8.js";
4
4
  import "../snapshot-DMW6j2Ix.js";
5
5
  import "../generator-DyrLOnPS.js";
6
- import "../parser-DCZuDQSQ.js";
7
- import "../push-DbdlGawo.js";
8
- import { n as registerDbCommands } from "../cli-EPI9dH9A.js";
6
+ import "../parser-CzKUWwk1.js";
7
+ import "../push-CAgrAjKM.js";
8
+ import { n as registerDbCommands } from "../cli-CjxrMYk5.js";
9
9
  import { Command } from "commander";
10
10
 
11
11
  //#region src/cli/bin.ts
@@ -1,6 +1,6 @@
1
1
  import { t as Snapshot } from "../snapshot-DOerumb7.js";
2
- import { l as DatabaseInfo } from "../defineDatabase-B8KJ1xYJ.js";
3
- import "../index-C5C4vaBs.js";
2
+ import { l as DatabaseInfo } from "../defineDatabase-Bjws1Jkd.js";
3
+ import "../index-CXsj1VQb.js";
4
4
  import { Command } from "commander";
5
5
 
6
6
  //#region src/cli/command.d.ts
package/dist/cli/index.js CHANGED
@@ -2,8 +2,8 @@ import "../debug-DmBrUmwe.js";
2
2
  import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-B4v8ICj8.js";
3
3
  import "../snapshot-DMW6j2Ix.js";
4
4
  import "../generator-DyrLOnPS.js";
5
- import "../parser-DCZuDQSQ.js";
6
- import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-DbdlGawo.js";
7
- import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-EPI9dH9A.js";
5
+ import "../parser-CzKUWwk1.js";
6
+ import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-CAgrAjKM.js";
7
+ import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-CjxrMYk5.js";
8
8
 
9
9
  export { createDbCommand, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, push, pushOne, registerDbCommands, reportCliError, reset, resetAndPush, saveDevState, status, validate };
@@ -2,8 +2,8 @@ import { i as init_debug, t as debugCli } from "./debug-DmBrUmwe.js";
2
2
  import { _ as saveDevState, a as generateEpoch, c as getDevPaths, d as init_state, f as loadDevMigrations, m as loadDevState, t as clearDatabaseDevState } from "./state-B4v8ICj8.js";
3
3
  import { a as hashSnapshot } from "./snapshot-DMW6j2Ix.js";
4
4
  import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-DyrLOnPS.js";
5
- import { a as resolveImportPath, o as loadViteAliases } from "./parser-DCZuDQSQ.js";
6
- import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-DbdlGawo.js";
5
+ import { o as resolveImportPath, s as loadViteAliases } from "./parser-CzKUWwk1.js";
6
+ import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-CAgrAjKM.js";
7
7
  import * as fs from "node:fs";
8
8
  import * as path from "node:path";
9
9
  import { Command } from "commander";
@@ -322,7 +322,7 @@ async function reset(ctx = {}, options = {}) {
322
322
  * Convenience function that combines reset + push
323
323
  */
324
324
  async function resetAndPush(ctx = {}, options = {}) {
325
- const { push: push$1 } = await import("./push-BqFhNoP2.js");
325
+ const { push: push$1 } = await import("./push-D0zsn0Ge.js");
326
326
  return {
327
327
  reset: await reset(ctx, options),
328
328
  push: await push$1(ctx)
@@ -1,2 +1,2 @@
1
- import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-DaDdJ_cg.js";
1
+ import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-D9LHeBx2.js";
2
2
  export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
@@ -1,3 +1,4 @@
1
- import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-B8KJ1xYJ.js";
2
- import { _ as SqliteDurableObject, a as QueryResult, b as createKyselyFromSql, c as DateSerializePlugin, d as createDrizzlePlugins, f as dateSerializers, g as Migrations, h as MigrationSchemaConflictError, i as KyselyPlugin, l as DrizzleDefaultsPlugin, m as MigrationAttemptInfo, n as CompiledQuery, o as studio, p as Migration, r as Kysely, s as type, t as CamelCasePlugin, u as SchemaPlugin, v as CreateKyselyOptions, y as SqlExecutor } from "../index-C5C4vaBs.js";
1
+ import { t as type } from "../arktypeConfig--4OgOv4U.js";
2
+ import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-Bjws1Jkd.js";
3
+ import { _ as CreateKyselyOptions, a as QueryResult, c as DrizzleDefaultsPlugin, d as dateSerializers, f as Migration, g as SqliteDurableObject, h as Migrations, i as KyselyPlugin, l as SchemaPlugin, m as MigrationSchemaConflictError, n as CompiledQuery, o as studio, p as MigrationAttemptInfo, r as Kysely, s as DateSerializePlugin, t as CamelCasePlugin, u as createDrizzlePlugins, v as SqlExecutor, y as createKyselyFromSql } from "../index-CXsj1VQb.js";
3
4
  export { Action, ActionConfig, ActionContext, ActionInfo, ArgsSchema, CamelCasePlugin, CompiledQuery, CreateKyselyOptions, DatabaseConfig, DatabaseDefinition, DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, DrizzleToKysely, InferArgs, Kysely, KyselyPlugin, Migration, MigrationAttemptInfo, MigrationSchemaConflictError, Migrations, ParsedDatabaseFile, QueryResult, SchemaPlugin, SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
package/dist/db/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i as init_debug, n as debugMigrations } from "../debug-DmBrUmwe.js";
2
- import { t as type } from "../out-on886o85.js";
3
- import { n as defineDatabase } from "../defineDatabase-DXA53pG3.js";
4
- import { a as createDrizzlePlugins, i as SchemaPlugin, n as DateSerializePlugin, o as dateSerializers, r as DrizzleDefaultsPlugin, t as createKyselyFromSql } from "../kysely-yPsCWEvR.js";
2
+ import { t as type } from "../arktypeConfig-CTCJm4vA.js";
3
+ import { n as defineDatabase } from "../defineDatabase-BD3k1L7d.js";
4
+ import { a as createDrizzlePlugins, i as SchemaPlugin, n as DateSerializePlugin, o as dateSerializers, r as DrizzleDefaultsPlugin, t as createKyselyFromSql } from "../kysely-BH7QZBZw.js";
5
5
  import { DurableObject } from "cloudflare:workers";
6
6
  import { CamelCasePlugin } from "kysely";
7
7
  import { studio } from "@outerbase/browsable-durable-object";
@@ -1,4 +1,4 @@
1
- import { t as type } from "./out-on886o85.js";
1
+ import { t as type } from "./arktypeConfig-CTCJm4vA.js";
2
2
 
3
3
  //#region src/db/defineDatabase.ts
4
4
  /**
@@ -1,6 +1,5 @@
1
1
  import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
2
2
  import { Kysely } from "kysely";
3
- import { type } from "arktype";
4
3
  import { Kyselify } from "drizzle-orm/kysely";
5
4
 
6
5
  //#region src/db/types.d.ts
@@ -36,8 +35,8 @@ type DrizzleToKysely<TSchema extends Record<string, SQLiteTableWithColumns<any>>
36
35
  * - arkType.validate<Def> → definition shape with DSL validation/autocomplete
37
36
  * - arkType.infer<Def> → inferred output type
38
37
  */
39
- type ArkDef<Def> = type.validate<Def>;
40
- type InferArgs<Def> = type.infer<Def>;
38
+ type ArkDef<Def> = arkType.validate<Def>;
39
+ type InferArgs<Def> = arkType.infer<Def>;
41
40
  /**
42
41
  * Context passed to action handlers
43
42
  */
@@ -3,7 +3,6 @@ import { DurableObject } from "cloudflare:workers";
3
3
  import { CamelCasePlugin, CamelCasePlugin as CamelCasePlugin$1, CompiledQuery, Kysely, Kysely as Kysely$1, KyselyPlugin, KyselyPlugin as KyselyPlugin$1, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, QueryResult as QueryResult$1, RootOperationNode, UnknownRow } from "kysely";
4
4
  import { Table } from "drizzle-orm";
5
5
  import { studio } from "@outerbase/browsable-durable-object";
6
- import { type as type$1 } from "arktype";
7
6
 
8
7
  //#region src/db/kysely.d.ts
9
8
  /**
@@ -343,9 +342,10 @@ declare class DateSerializePlugin implements KyselyPlugin {
343
342
  * - DrizzleDefaultsPlugin: auto-populates defaultFn/onUpdateFn values
344
343
  * - SchemaPlugin (extends CamelCasePlugin): schema-aware camelCase ↔ snake_case
345
344
  * - DateSerializePlugin: Date ↔ SQLite text serialization
345
+ * - BooleanDeserializePlugin: boolean-mode columns read back as booleans
346
346
  *
347
347
  * When camelCase is false, SchemaPlugin is omitted.
348
348
  */
349
349
  declare function createDrizzlePlugins(schema: Record<string, SQLiteTableWithColumns<any>>, camelCase?: boolean): KyselyPlugin[];
350
350
  //#endregion
351
- export { SqliteDurableObject as _, QueryResult$1 as a, createKyselyFromSql as b, DateSerializePlugin as c, createDrizzlePlugins as d, dateSerializers as f, Migrations as g, MigrationSchemaConflictError as h, KyselyPlugin$1 as i, DrizzleDefaultsPlugin as l, MigrationAttemptInfo as m, CompiledQuery as n, studio as o, Migration as p, Kysely$1 as r, type$1 as s, CamelCasePlugin$1 as t, SchemaPlugin as u, CreateKyselyOptions as v, SqlExecutor as y };
351
+ export { CreateKyselyOptions as _, QueryResult$1 as a, DrizzleDefaultsPlugin as c, dateSerializers as d, Migration as f, SqliteDurableObject as g, Migrations as h, KyselyPlugin$1 as i, SchemaPlugin as l, MigrationSchemaConflictError as m, CompiledQuery as n, studio as o, MigrationAttemptInfo as p, Kysely$1 as r, DateSerializePlugin as s, CamelCasePlugin$1 as t, createDrizzlePlugins as u, SqlExecutor as v, createKyselyFromSql as y };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-B8KJ1xYJ.js";
2
- import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-DaDdJ_cg.js";
3
- import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-suxWBY7-.js";
1
+ import { t as type } from "./arktypeConfig--4OgOv4U.js";
2
+ import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-Bjws1Jkd.js";
3
+ import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-D9LHeBx2.js";
4
+ import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-BCjqTRvV.js";
4
5
  import { Kysely } from "kysely";
5
- import { type } from "arktype";
6
6
  export { type Action, type ActionConfig, type ActionContext, type AnySQLiteColumn, type DatabaseConfig, type DatabaseDefinition, type DrizzleToKysely, type InferArgs, type Kysely, blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./debug-DmBrUmwe.js";
2
- import { t as type } from "./out-on886o85.js";
3
- import { n as defineDatabase } from "./defineDatabase-DXA53pG3.js";
2
+ import { t as type } from "./arktypeConfig-CTCJm4vA.js";
3
+ import { n as defineDatabase } from "./defineDatabase-BD3k1L7d.js";
4
4
  import { a as numeric, c as table, i as integer, l as text, n as foreignKey, o as primaryKey, r as index, s as real, t as blob, u as uniqueIndex } from "./schema-IFq7ovQq.js";
5
5
  import "./state-B4v8ICj8.js";
6
6
  import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-Cwe1IsnH.js";
@@ -247,6 +247,63 @@ var DateSerializePlugin = class {
247
247
  }
248
248
  };
249
249
  /**
250
+ * Collect the names of columns Drizzle declares as boolean-typed
251
+ * (`integer({ mode: 'boolean' })`). Mirrors collectDateColumnNames: covers
252
+ * the SQL column name, the JS property name, and the snake_cased property
253
+ * name, so it works on either side of the CamelCasePlugin.
254
+ */
255
+ function collectBooleanColumnNames(schema) {
256
+ const booleanColumns = /* @__PURE__ */ new Set();
257
+ for (const table of Object.values(schema)) {
258
+ const columns = getTableColumns(table);
259
+ for (const [propertyName, column] of Object.entries(columns)) if (column.dataType === "boolean") {
260
+ booleanColumns.add(column.name);
261
+ booleanColumns.add(propertyName);
262
+ booleanColumns.add(toSnakeCase(propertyName));
263
+ }
264
+ }
265
+ return booleanColumns;
266
+ }
267
+ /**
268
+ * Plugin that deserializes boolean-mode columns on read.
269
+ *
270
+ * SQLite stores booleans as INTEGER 1/0 (the write side is normalized in the
271
+ * driver — see normalizeParameter in kysely.ts), so schema-declared boolean
272
+ * columns come back as numbers and must be mapped to real booleans. Legacy
273
+ * rows written before the driver normalization existed carry TEXT
274
+ * 'true'/'false' — those are mapped too, so old data keeps reading correctly.
275
+ * Anything unrecognized round-trips verbatim rather than being guessed at.
276
+ */
277
+ var BooleanDeserializePlugin = class {
278
+ booleanColumns;
279
+ constructor(schema) {
280
+ this.booleanColumns = collectBooleanColumnNames(schema);
281
+ }
282
+ transformQuery(args) {
283
+ return args.node;
284
+ }
285
+ async transformResult(args) {
286
+ if (this.booleanColumns.size === 0) return args.result;
287
+ return {
288
+ ...args.result,
289
+ rows: args.result.rows.map((row) => this.transformRow(row))
290
+ };
291
+ }
292
+ transformRow(row) {
293
+ const result = {};
294
+ for (const [key, value] of Object.entries(row)) result[key] = this.booleanColumns.has(key) ? this.toBoolean(value) : value;
295
+ return result;
296
+ }
297
+ toBoolean(value) {
298
+ if (value === null || value === void 0 || typeof value === "boolean") return value;
299
+ if (typeof value === "number") return value !== 0;
300
+ if (typeof value === "bigint") return value !== 0n;
301
+ if (value === "true" || value === "1") return true;
302
+ if (value === "false" || value === "0") return false;
303
+ return value;
304
+ }
305
+ };
306
+ /**
250
307
  * Validate that a schema object is shaped like a record of Drizzle tables.
251
308
  *
252
309
  * Throws a descriptive error pointing at the offending key when the schema
@@ -269,6 +326,7 @@ function assertValidSchema(schema) {
269
326
  * - DrizzleDefaultsPlugin: auto-populates defaultFn/onUpdateFn values
270
327
  * - SchemaPlugin (extends CamelCasePlugin): schema-aware camelCase ↔ snake_case
271
328
  * - DateSerializePlugin: Date ↔ SQLite text serialization
329
+ * - BooleanDeserializePlugin: boolean-mode columns read back as booleans
272
330
  *
273
331
  * When camelCase is false, SchemaPlugin is omitted.
274
332
  */
@@ -278,11 +336,97 @@ function createDrizzlePlugins(schema, camelCase = true) {
278
336
  plugins.push(new DrizzleDefaultsPlugin(schema));
279
337
  if (camelCase) plugins.push(new SchemaPlugin(schema));
280
338
  plugins.push(new DateSerializePlugin(schema));
339
+ plugins.push(new BooleanDeserializePlugin(schema));
281
340
  return plugins;
282
341
  }
283
342
 
284
343
  //#endregion
285
344
  //#region src/db/kysely.ts
345
+ const MAX_BOUND_PARAMETERS = 100;
346
+ /**
347
+ * workerd has no boolean binding type and silently stringifies JS booleans
348
+ * (storing TEXT 'true' in an INTEGER column); node:sqlite rejects them
349
+ * outright. Normalize to SQLite's 1/0 convention before the value reaches
350
+ * either. `undefined` → NULL for the same reason.
351
+ */
352
+ function normalizeParameter(value) {
353
+ if (typeof value === "boolean") return value ? 1 : 0;
354
+ if (value === void 0) return null;
355
+ return value;
356
+ }
357
+ function escapeLiteral(value) {
358
+ if (value === null || value === void 0) return "NULL";
359
+ if (typeof value === "boolean") return value ? "1" : "0";
360
+ if (typeof value === "number") {
361
+ if (!Number.isFinite(value)) throw new Error(`[db] Cannot inline non-finite number parameter (${value})`);
362
+ return String(value);
363
+ }
364
+ if (typeof value === "bigint") return value.toString();
365
+ if (typeof value === "string") {
366
+ if (value.includes("\0")) throw new Error("[db] Cannot inline a string parameter containing a NUL byte");
367
+ return `'${value.replaceAll("'", "''")}'`;
368
+ }
369
+ if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
370
+ const bytes = value instanceof ArrayBuffer ? new Uint8Array(value) : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
371
+ let hex = "";
372
+ for (const b of bytes) hex += b.toString(16).padStart(2, "0");
373
+ return `X'${hex}'`;
374
+ }
375
+ throw new Error(`[db] Cannot inline SQL parameter of type ${typeof value}`);
376
+ }
377
+ /**
378
+ * Replace each `?` placeholder in `sql` with the escaped literal of its
379
+ * parameter. A real scanner, not a regex: '…' string literals ('' escapes),
380
+ * "…" quoted identifiers, `--` line comments and C-style block comments are
381
+ * skipped, so a `?` inside any of them is never touched.
382
+ *
383
+ * Exported for tests.
384
+ */
385
+ function inlineParameters(sql$1, parameters) {
386
+ let out = "";
387
+ let p = 0;
388
+ for (let i = 0; i < sql$1.length; i++) {
389
+ const ch = sql$1[i];
390
+ if (ch === "'" || ch === "\"") {
391
+ let j = i + 1;
392
+ while (j < sql$1.length) {
393
+ if (sql$1[j] === ch) {
394
+ if (sql$1[j + 1] === ch) {
395
+ j += 2;
396
+ continue;
397
+ }
398
+ break;
399
+ }
400
+ j++;
401
+ }
402
+ out += sql$1.slice(i, j + 1);
403
+ i = j;
404
+ continue;
405
+ }
406
+ if (ch === "-" && sql$1[i + 1] === "-") {
407
+ let j = sql$1.indexOf("\n", i);
408
+ if (j === -1) j = sql$1.length;
409
+ out += sql$1.slice(i, j);
410
+ i = j - 1;
411
+ continue;
412
+ }
413
+ if (ch === "/" && sql$1[i + 1] === "*") {
414
+ let j = sql$1.indexOf("*/", i + 2);
415
+ j = j === -1 ? sql$1.length : j + 2;
416
+ out += sql$1.slice(i, j);
417
+ i = j - 1;
418
+ continue;
419
+ }
420
+ if (ch === "?") {
421
+ if (p >= parameters.length) throw new Error("[db] Query has more `?` placeholders than parameters while inlining");
422
+ out += escapeLiteral(parameters[p++]);
423
+ continue;
424
+ }
425
+ out += ch;
426
+ }
427
+ if (p !== parameters.length) throw new Error(`[db] Inlined ${p} parameter(s) but the query provided ${parameters.length} — placeholder/parameter mismatch`);
428
+ return out;
429
+ }
286
430
  /**
287
431
  * A Kysely driver that uses Cloudflare DO SQLite storage
288
432
  */
@@ -331,7 +475,12 @@ var CloudflareSqliteConnection = class {
331
475
  this.sql = sql$1;
332
476
  }
333
477
  async executeQuery(compiledQuery) {
334
- const { sql: queryStr, parameters } = compiledQuery;
478
+ let queryStr = compiledQuery.sql;
479
+ let parameters = compiledQuery.parameters.map(normalizeParameter);
480
+ if (parameters.length > MAX_BOUND_PARAMETERS) {
481
+ queryStr = inlineParameters(queryStr, parameters);
482
+ parameters = [];
483
+ }
335
484
  const isSelect = /^\s*(SELECT|RETURNING)/i.test(queryStr) || /\s+RETURNING\s+/i.test(queryStr);
336
485
  try {
337
486
  if (isSelect) return {
@@ -159,6 +159,45 @@ function discoverDatabaseFiles(options) {
159
159
  return results;
160
160
  }
161
161
  /**
162
+ * Recursively find action-defining files under the databases directory.
163
+ *
164
+ * The generated Durable Object module side-effect-imports these so every
165
+ * `action()` runs its `registerAction(...)` at DO startup — populating the
166
+ * action registry in the DO's isolate. Without this the registry is only
167
+ * populated by whatever the request path imported, which works in dev (one
168
+ * shared isolate) and via in-app navigation, but a Durable Object is a separate
169
+ * persistent isolate in production: a freshly deep-linked route whose action the
170
+ * DO never loaded throws `Unknown action "X" (was it imported?)`.
171
+ *
172
+ * Returns absolute paths of `.ts`/`.tsx` files that call `action(` (the factory
173
+ * invocation), excluding tests, declarations, and `_`-prefixed helpers. Helper
174
+ * modules without their own actions are pulled in transitively by the action
175
+ * files that import them, so they don't need to be listed here.
176
+ */
177
+ function discoverActionFiles(options) {
178
+ const { projectRoot, databasesDir } = options;
179
+ const absoluteDir = path.join(projectRoot, databasesDir);
180
+ if (!fs.existsSync(absoluteDir)) return [];
181
+ const results = [];
182
+ const walk = (dir) => {
183
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
184
+ if (entry.name.startsWith("_") || entry.name === "node_modules") continue;
185
+ const full = path.join(dir, entry.name);
186
+ if (entry.isDirectory()) {
187
+ walk(full);
188
+ continue;
189
+ }
190
+ if (!/\.tsx?$/.test(entry.name)) continue;
191
+ if (/\.d\.ts$/.test(entry.name) || /\.(test|spec)\.tsx?$/.test(entry.name)) continue;
192
+ try {
193
+ if (/\baction\s*\(/.test(fs.readFileSync(full, "utf-8"))) results.push(full);
194
+ } catch {}
195
+ }
196
+ };
197
+ walk(absoluteDir);
198
+ return results;
199
+ }
200
+ /**
162
201
  * Resolve an import path to an absolute path.
163
202
  *
164
203
  * Relative imports (starting with `.`) are the fast path — resolved directly
@@ -390,4 +429,4 @@ function toScreamingSnakeCase(str) {
390
429
  }
391
430
 
392
431
  //#endregion
393
- export { resolveImportPath as a, readFile as i, parseDatabaseFile as n, loadViteAliases as o, discoverDatabaseFiles as r, BABEL_PARSER_PLUGINS as t };
432
+ export { readFile as a, discoverDatabaseFiles as i, parseDatabaseFile as n, resolveImportPath as o, discoverActionFiles as r, loadViteAliases as s, BABEL_PARSER_PLUGINS as t };
@@ -2,7 +2,7 @@ import { i as init_debug, t as debugCli } from "./debug-DmBrUmwe.js";
2
2
  import { d as init_state, f as loadDevMigrations, h as saveDevMigration, n as clearDevMigrations } from "./state-B4v8ICj8.js";
3
3
  import { n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema } from "./snapshot-DMW6j2Ix.js";
4
4
  import { s as loadSnapshot, t as buildAndLoadSchema } from "./generator-DyrLOnPS.js";
5
- import { a as resolveImportPath, i as readFile, n as parseDatabaseFile, o as loadViteAliases, r as discoverDatabaseFiles } from "./parser-DCZuDQSQ.js";
5
+ import { a as readFile, i as discoverDatabaseFiles, n as parseDatabaseFile, o as resolveImportPath, s as loadViteAliases } from "./parser-CzKUWwk1.js";
6
6
  import * as path from "node:path";
7
7
  import * as crypto from "node:crypto";
8
8
 
@@ -2,7 +2,7 @@ import "./debug-DmBrUmwe.js";
2
2
  import "./state-B4v8ICj8.js";
3
3
  import "./snapshot-DMW6j2Ix.js";
4
4
  import "./generator-DyrLOnPS.js";
5
- import "./parser-DCZuDQSQ.js";
6
- import { n as pushOne, t as push } from "./push-DbdlGawo.js";
5
+ import "./parser-CzKUWwk1.js";
6
+ import { n as pushOne, t as push } from "./push-CAgrAjKM.js";
7
7
 
8
8
  export { push };
@@ -1,4 +1,4 @@
1
- import { type } from "arktype";
1
+ import { t as type } from "./arktypeConfig--4OgOv4U.js";
2
2
 
3
3
  //#region src/registry.d.ts
4
4
  interface ActionDefinition {
package/dist/registry.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as type } from "./out-on886o85.js";
1
+ import { t as type } from "./arktypeConfig-CTCJm4vA.js";
2
2
  import { n as WebSocketTransport } from "./websocket-eao2rnHL.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
 
package/dist/schema.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-suxWBY7-.js";
1
+ import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-BCjqTRvV.js";
2
2
  export { AnySQLiteColumn, blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
@@ -1,9 +1,9 @@
1
1
  import "../debug-DmBrUmwe.js";
2
- import { t as type } from "../out-on886o85.js";
3
- import { t as ACTION_TEST_META } from "../defineDatabase-DXA53pG3.js";
2
+ import { t as type } from "../arktypeConfig-CTCJm4vA.js";
3
+ import { t as ACTION_TEST_META } from "../defineDatabase-BD3k1L7d.js";
4
4
  import "../state-B4v8ICj8.js";
5
5
  import { a as setTenantIdResolver } from "../context-Cwe1IsnH.js";
6
- import { t as createKyselyFromSql } from "../kysely-yPsCWEvR.js";
6
+ import { t as createKyselyFromSql } from "../kysely-BH7QZBZw.js";
7
7
  import { n as generateMigrationStatements, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-DMW6j2Ix.js";
8
8
  import { createRequire } from "node:module";
9
9
 
@@ -2,7 +2,7 @@ import { i as init_debug, r as debugVite } from "../debug-DmBrUmwe.js";
2
2
  import { _ as saveDevState, c as getDevPaths, d as init_state, m as loadDevState } from "../state-B4v8ICj8.js";
3
3
  import "../snapshot-DMW6j2Ix.js";
4
4
  import { a as loadMigrationFiles } from "../generator-DyrLOnPS.js";
5
- import { i as readFile, n as parseDatabaseFile, r as discoverDatabaseFiles, t as BABEL_PARSER_PLUGINS } from "../parser-DCZuDQSQ.js";
5
+ import { a as readFile, i as discoverDatabaseFiles, n as parseDatabaseFile, r as discoverActionFiles, t as BABEL_PARSER_PLUGINS } from "../parser-CzKUWwk1.js";
6
6
  import * as fs from "node:fs";
7
7
  import * as path from "node:path";
8
8
  import { parse } from "@babel/parser";
@@ -340,12 +340,16 @@ function generateWithMap(ast, sourceFileName) {
340
340
  comments: true
341
341
  });
342
342
  }
343
- function generateDurableObjectsModule(databases, registryImport, isDev = false) {
343
+ function generateDurableObjectsModule(databases, registryImport, isDev = false, actionFiles = []) {
344
344
  const bindingNamesExpr = buildBindingNamesObject(databases);
345
345
  const dbTransportsExpr = buildDbTransportsObject(databases);
346
346
  const anyBrowsable = databases.some((db) => db.browsable === true || db.browsable === "development" && isDev);
347
347
  const anyWebSocket = databases.some((db) => db.transport === "websocket");
348
- const imports = [createNamedImport(["SqliteDurableObject", "type"], "durable-db/db"), createNamedImport(["getAction", "runWithDoContext"], registryImport)];
348
+ const imports = [
349
+ createNamedImport(["SqliteDurableObject", "type"], "durable-db/db"),
350
+ createNamedImport(["getAction", "runWithDoContext"], registryImport),
351
+ ...actionFiles.map((file) => t.importDeclaration([], t.stringLiteral(file)))
352
+ ];
349
353
  if (anyBrowsable) imports.push(createNamedImport(["Browsable"], "@outerbase/browsable-durable-object"));
350
354
  if (anyWebSocket) imports.push(createNamedImport(["decodeRequest", "encodeResponse"], "durable-db/transport/protocol"));
351
355
  const statements = [...imports];
@@ -993,7 +997,11 @@ function durableDb(options = {}) {
993
997
  if (id !== VIRTUAL_DO_MODULE_ID) return null;
994
998
  await state.initialize();
995
999
  const isDev = state.config.command === "serve";
996
- return { code: generateDurableObjectsModule(Array.from(state.databases.values()), state.options.registryImport, isDev) };
1000
+ const actionFiles = discoverActionFiles({
1001
+ projectRoot: state.projectRoot,
1002
+ databasesDir: state.options.databasesDir
1003
+ });
1004
+ return { code: generateDurableObjectsModule(Array.from(state.databases.values()), state.options.registryImport, isDev, actionFiles) };
997
1005
  },
998
1006
  async transform(code, id) {
999
1007
  if (/[\\/]drizzle-orm[\\/]/.test(id)) return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-db",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"