durable-db 0.0.3 → 0.0.4

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.
Files changed (41) hide show
  1. package/dist/cli/bin.js +6 -6
  2. package/dist/cli/index.d.ts +3 -3
  3. package/dist/cli/index.js +6 -6
  4. package/dist/{cli-Cr9686BF.js → cli-AzoPlqMA.js} +6 -6
  5. package/dist/context/index.d.ts +1 -1
  6. package/dist/context/index.js +2 -2
  7. package/dist/{context-BuIiIQ6K.js → context-BcWMofTp.js} +1 -1
  8. package/dist/db/index.d.ts +2 -2
  9. package/dist/db/index.js +2 -2
  10. package/dist/{defineDatabase-jBv90-Pk.d.ts → defineDatabase-B8do9yYZ.d.ts} +1 -1
  11. package/dist/{defineDatabase-CONf4xFC.js → defineDatabase-C91B-LMQ.js} +1 -1
  12. package/dist/{generator-BUPP9scJ.js → generator-B4yBWHRz.js} +24 -2
  13. package/dist/{index-CU9edk9Q.d.ts → index-nm3-NwUh.d.ts} +1 -1
  14. package/dist/index.d.ts +4 -4
  15. package/dist/index.js +5 -5
  16. package/dist/migrations/generator.d.ts +1 -1
  17. package/dist/migrations/generator.js +2 -2
  18. package/dist/migrations/snapshot.d.ts +1 -1
  19. package/dist/migrations/snapshot.js +1 -1
  20. package/dist/out-CuoxKfaH.js +7446 -0
  21. package/dist/{push-BgQ5cnfH.js → push-BymAOkB9.js} +4 -4
  22. package/dist/push-CT2aX_AM.js +8 -0
  23. package/dist/registry.d.ts +3 -1
  24. package/dist/registry.js +3 -3
  25. package/dist/schema.d.ts +1 -1
  26. package/dist/schema.js +1 -1
  27. package/dist/{state-BCcvNN-M.js → state-BUCIODvB.js} +1 -1
  28. package/dist/transport/protocol.js +1 -1
  29. package/dist/transport/websocket.js +1 -1
  30. package/dist/vite/durableDb.js +7 -7
  31. package/dist/{websocket-Dx1fqwnF.js → websocket-Cwc7933g.js} +1 -1
  32. package/package.json +1 -1
  33. package/dist/push-BkkaslPd.js +0 -8
  34. /package/dist/{index-CqVMaMYY.d.ts → index-DN2vKPw_.d.ts} +0 -0
  35. /package/dist/{parser-CbX54Flt.js → parser-qOiKNcYc.js} +0 -0
  36. /package/dist/{protocol-g_plhPOY.js → protocol-v7B4_9xU.js} +0 -0
  37. /package/dist/{schema-CpzTOfZ6.d.ts → schema-CjGvnsaZ.d.ts} +0 -0
  38. /package/dist/{schema-BOtrGnzM.js → schema-ou5L5I9Y.js} +0 -0
  39. /package/dist/{snapshot-D170nL7i.js → snapshot-CgEvcMZb.js} +0 -0
  40. /package/dist/{snapshot-C162qYoA.d.ts → snapshot-oD3wAJF2.d.ts} +0 -0
  41. /package/dist/{state-FOEjpgJ6.js → state-DDHYOyvD.js} +0 -0
package/dist/cli/bin.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import "../debug-BZJbKybf.js";
3
- import "../state-FOEjpgJ6.js";
4
- import "../snapshot-D170nL7i.js";
5
- import "../generator-BUPP9scJ.js";
6
- import "../parser-CbX54Flt.js";
7
- import "../push-BgQ5cnfH.js";
8
- import { n as registerDbCommands } from "../cli-Cr9686BF.js";
3
+ import "../state-DDHYOyvD.js";
4
+ import "../snapshot-CgEvcMZb.js";
5
+ import "../generator-B4yBWHRz.js";
6
+ import "../parser-qOiKNcYc.js";
7
+ import "../push-BymAOkB9.js";
8
+ import { n as registerDbCommands } from "../cli-AzoPlqMA.js";
9
9
  import { Command } from "commander";
10
10
 
11
11
  //#region src/cli/bin.ts
@@ -1,6 +1,6 @@
1
- import { t as Snapshot } from "../snapshot-C162qYoA.js";
2
- import { l as DatabaseInfo } from "../defineDatabase-jBv90-Pk.js";
3
- import "../index-CU9edk9Q.js";
1
+ import { t as Snapshot } from "../snapshot-oD3wAJF2.js";
2
+ import { l as DatabaseInfo } from "../defineDatabase-B8do9yYZ.js";
3
+ import "../index-nm3-NwUh.js";
4
4
  import { Command } from "commander";
5
5
 
6
6
  //#region src/cli/command.d.ts
package/dist/cli/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import "../debug-BZJbKybf.js";
2
- import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-FOEjpgJ6.js";
3
- import "../snapshot-D170nL7i.js";
4
- import "../generator-BUPP9scJ.js";
5
- import "../parser-CbX54Flt.js";
6
- import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-BgQ5cnfH.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-Cr9686BF.js";
2
+ import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-DDHYOyvD.js";
3
+ import "../snapshot-CgEvcMZb.js";
4
+ import "../generator-B4yBWHRz.js";
5
+ import "../parser-qOiKNcYc.js";
6
+ import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-BymAOkB9.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-AzoPlqMA.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 };
@@ -1,9 +1,9 @@
1
1
  import { i as init_debug, t as debugCli } from "./debug-BZJbKybf.js";
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-FOEjpgJ6.js";
3
- import { a as hashSnapshot } from "./snapshot-D170nL7i.js";
4
- import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-BUPP9scJ.js";
5
- import { a as resolveImportPath } from "./parser-CbX54Flt.js";
6
- import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-BgQ5cnfH.js";
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-DDHYOyvD.js";
3
+ import { a as hashSnapshot } from "./snapshot-CgEvcMZb.js";
4
+ import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-B4yBWHRz.js";
5
+ import { a as resolveImportPath } from "./parser-qOiKNcYc.js";
6
+ import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-BymAOkB9.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-BkkaslPd.js");
325
+ const { push: push$1 } = await import("./push-CT2aX_AM.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-CqVMaMYY.js";
1
+ import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-DN2vKPw_.js";
2
2
  export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
@@ -1,5 +1,5 @@
1
1
  import "../debug-BZJbKybf.js";
2
- import "../state-FOEjpgJ6.js";
3
- import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-BuIiIQ6K.js";
2
+ import "../state-DDHYOyvD.js";
3
+ import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-BcWMofTp.js";
4
4
 
5
5
  export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
@@ -1,5 +1,5 @@
1
1
  import { s as __toCommonJS } from "./debug-BZJbKybf.js";
2
- import { d as init_state, v as state_exports } from "./state-FOEjpgJ6.js";
2
+ import { d as init_state, v as state_exports } from "./state-DDHYOyvD.js";
3
3
 
4
4
  //#region src/context/index.ts
5
5
  /**
@@ -1,3 +1,3 @@
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-jBv90-Pk.js";
2
- import { _ as Migrations, a as QueryResult, b as createKyselyFromSql, c as DateSerializePlugin, d as createDrizzlePlugins, f as dateSerializers, g as MigrationSchemaConflictError, h as MigrationAttemptInfo, i as KyselyPlugin, l as DrizzleDefaultsPlugin, m as Migration, n as CompiledQuery, o as studio, p as CreateKyselyOptions, r as Kysely, s as type, t as CamelCasePlugin, u as SchemaPlugin, v as SqlExecutor, y as SqliteDurableObject } from "../index-CU9edk9Q.js";
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-B8do9yYZ.js";
2
+ import { _ as Migrations, a as QueryResult, b as createKyselyFromSql, c as DateSerializePlugin, d as createDrizzlePlugins, f as dateSerializers, g as MigrationSchemaConflictError, h as MigrationAttemptInfo, i as KyselyPlugin, l as DrizzleDefaultsPlugin, m as Migration, n as CompiledQuery, o as studio, p as CreateKyselyOptions, r as Kysely, s as type, t as CamelCasePlugin, u as SchemaPlugin, v as SqlExecutor, y as SqliteDurableObject } from "../index-nm3-NwUh.js";
3
3
  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,6 +1,6 @@
1
1
  import { i as init_debug, n as debugMigrations } from "../debug-BZJbKybf.js";
2
- import { t as defineDatabase } from "../defineDatabase-CONf4xFC.js";
3
- import { type } from "arktype";
2
+ import { t as type } from "../out-CuoxKfaH.js";
3
+ import { t as defineDatabase } from "../defineDatabase-C91B-LMQ.js";
4
4
  import { SQLiteSyncDialect, getTableConfig } from "drizzle-orm/sqlite-core";
5
5
  import { toCamelCase, toSnakeCase } from "drizzle-orm/casing";
6
6
  import { DurableObject } from "cloudflare:workers";
@@ -1,7 +1,7 @@
1
- import { type } from "arktype";
2
1
  import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
3
2
  import { Kysely } from "kysely";
4
3
  import { Kyselify } from "drizzle-orm/kysely";
4
+ import { type } from "arktype";
5
5
 
6
6
  //#region src/db/types.d.ts
7
7
 
@@ -1,4 +1,4 @@
1
- import { type } from "arktype";
1
+ import { t as type } from "./out-CuoxKfaH.js";
2
2
 
3
3
  //#region src/db/defineDatabase.ts
4
4
  /**
@@ -1,7 +1,8 @@
1
1
  import { i as init_debug, n as debugMigrations } from "./debug-BZJbKybf.js";
2
- import { i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "./snapshot-D170nL7i.js";
2
+ import { i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "./snapshot-CgEvcMZb.js";
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
+ import * as os from "node:os";
5
6
  import { pathToFileURL } from "node:url";
6
7
 
7
8
  //#region src/migrations/generator.ts
@@ -139,6 +140,26 @@ async function loadSchemaModule(schemaPath, tableNames) {
139
140
  }
140
141
  }
141
142
  /**
143
+ * Where to drop the transient transpiled-schema `.mjs`. We want a
144
+ * directory that (a) is on the app's node_modules resolution chain
145
+ * so the bundle's bare imports resolve, and (b) is NOT inside the
146
+ * watched `src/` tree (so dev-server watchers don't react to it).
147
+ * The app's `node_modules/.cache/durable-db/` satisfies both; if no
148
+ * node_modules is found walking up from the schema, fall back to the
149
+ * OS temp dir (the schema bundle's externals are usually resolvable
150
+ * relative to cwd in that case too).
151
+ */
152
+ function resolveTempDir(schemaPath) {
153
+ let dir = path.dirname(path.resolve(schemaPath));
154
+ while (true) {
155
+ if (fs.existsSync(path.join(dir, "node_modules"))) return path.join(dir, "node_modules", ".cache", "durable-db");
156
+ const parent = path.dirname(dir);
157
+ if (parent === dir) break;
158
+ dir = parent;
159
+ }
160
+ return path.join(os.tmpdir(), "durable-db");
161
+ }
162
+ /**
142
163
  * Build schema module with esbuild and return the exports
143
164
  * This is useful when the schema is TypeScript and needs transpilation
144
165
  */
@@ -153,7 +174,8 @@ async function buildAndLoadSchema(schemaPath, tableNames) {
153
174
  target: "node18"
154
175
  });
155
176
  if (result.outputFiles?.length !== 1) throw new Error(`Unexpected esbuild output for ${schemaPath}`);
156
- const tempDir = path.dirname(schemaPath);
177
+ const tempDir = resolveTempDir(schemaPath);
178
+ fs.mkdirSync(tempDir, { recursive: true });
157
179
  const tempFile = path.join(tempDir, `_schema_temp_${Date.now()}.mjs`);
158
180
  try {
159
181
  fs.writeFileSync(tempFile, result.outputFiles[0].text);
@@ -1,9 +1,9 @@
1
- import { type as type$1 } from "arktype";
2
1
  import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
3
2
  import { DurableObject } from "cloudflare:workers";
4
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";
5
4
  import { Table } from "drizzle-orm";
6
5
  import { studio } from "@outerbase/browsable-durable-object";
6
+ import { type as type$1 } from "arktype";
7
7
 
8
8
  //#region src/db/SqliteDurableObject.d.ts
9
9
  /**
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-jBv90-Pk.js";
2
- import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-CqVMaMYY.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-CpzTOfZ6.js";
4
- import { type } from "arktype";
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-B8do9yYZ.js";
2
+ import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-DN2vKPw_.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-CjGvnsaZ.js";
5
4
  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,8 +1,8 @@
1
1
  import "./debug-BZJbKybf.js";
2
- import { t as defineDatabase } from "./defineDatabase-CONf4xFC.js";
3
- 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-BOtrGnzM.js";
4
- import "./state-FOEjpgJ6.js";
5
- import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-BuIiIQ6K.js";
6
- import { type } from "arktype";
2
+ import { t as type } from "./out-CuoxKfaH.js";
3
+ import { t as defineDatabase } from "./defineDatabase-C91B-LMQ.js";
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-ou5L5I9Y.js";
5
+ import "./state-DDHYOyvD.js";
6
+ import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-BcWMofTp.js";
7
7
 
8
8
  export { blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
@@ -1,4 +1,4 @@
1
- import { t as Snapshot } from "../snapshot-C162qYoA.js";
1
+ import { t as Snapshot } from "../snapshot-oD3wAJF2.js";
2
2
 
3
3
  //#region src/migrations/generator.d.ts
4
4
 
@@ -1,5 +1,5 @@
1
1
  import "../debug-BZJbKybf.js";
2
- import "../snapshot-D170nL7i.js";
3
- import { a as loadMigrationFiles, c as parseSqlMigration, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, o as loadSchemaModule, r as generateMigration, s as loadSnapshot, t as buildAndLoadSchema } from "../generator-BUPP9scJ.js";
2
+ import "../snapshot-CgEvcMZb.js";
3
+ import { a as loadMigrationFiles, c as parseSqlMigration, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, o as loadSchemaModule, r as generateMigration, s as loadSnapshot, t as buildAndLoadSchema } from "../generator-B4yBWHRz.js";
4
4
 
5
5
  export { buildAndLoadSchema, generateCreateTableSQL, generateMigration, generateMigrationName, loadMigrationFiles, loadSchemaModule, loadSnapshot, parseSqlMigration, saveSnapshot };
@@ -1,2 +1,2 @@
1
- import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-C162qYoA.js";
1
+ import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-oD3wAJF2.js";
2
2
  export { Snapshot, createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema, generateSnapshotId, hashSnapshot, snapshotsEqual };
@@ -1,3 +1,3 @@
1
- import { a as hashSnapshot, i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-D170nL7i.js";
1
+ import { a as hashSnapshot, i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-CgEvcMZb.js";
2
2
 
3
3
  export { createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema, generateSnapshotId, hashSnapshot, snapshotsEqual };