durable-db 0.2.0 → 0.2.2
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/dist/{arktypeConfig-zgI5p6zF.d.ts → arktypeConfig-AXvobTPL.d.ts} +0 -1
- package/dist/{arktypeConfig-CTCJm4vA.js → arktypeConfig-DxP0OcV_.js} +1014 -1033
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +2 -10
- package/dist/cli/index.d.ts +27 -29
- package/dist/cli/index.js +4 -9
- package/dist/{cli-DnsOTcrH.js → cli-BUSZTS2D.js} +196 -19
- package/dist/context/index.d.ts +50 -2
- package/dist/context/index.js +119 -5
- package/dist/db/index.d.ts +4 -4
- package/dist/db/index.js +10 -12
- package/dist/{debug-DmBrUmwe.js → debug-Cz8KzMft.js} +23 -27
- package/dist/{defineDatabase-BD3k1L7d.js → defineDatabase-CHmzpzFf.js} +2 -4
- package/dist/{defineDatabase-DtkM6k1S.d.ts → defineDatabase-IUthY3Ex.d.ts} +5 -5
- package/dist/{discovery-DfimBbS_.d.ts → discovery-gHeLq8jk.d.ts} +1 -1
- package/dist/{index-BHLOQ7uV.d.ts → index-BdrcuAU7.d.ts} +4 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -8
- package/dist/{kysely-BH7QZBZw.js → kysely-Be6KwFZC.js} +45 -31
- package/dist/migrations/generator.d.ts +14 -17
- package/dist/migrations/generator.js +202 -5
- package/dist/migrations/snapshot.d.ts +1 -1
- package/dist/migrations/snapshot.js +91 -3
- package/dist/{parser-BdV7Zqcv.js → parser-DR57GOjv.js} +21 -19
- package/dist/registry.d.ts +10 -11
- package/dist/registry.js +3 -5
- package/dist/schema.d.ts +5 -2
- package/dist/schema.js +6 -3
- package/dist/snapshot-CaG5xnE2.d.ts +48 -0
- package/dist/{state-DtZ70cBR.js → state-OVuoHRC9.js} +3 -5
- package/dist/testing/index.d.ts +4 -5
- package/dist/testing/index.js +6 -10
- package/dist/transport/protocol.d.ts +7 -8
- package/dist/transport/protocol.js +34 -3
- package/dist/transport/websocket.d.ts +4 -5
- package/dist/transport/websocket.js +103 -3
- package/dist/vite/durableDb.d.ts +6 -7
- package/dist/vite/durableDb.js +23 -28
- package/package.json +12 -12
- package/dist/context-kIVZbhye.js +0 -121
- package/dist/generator-KHBZaOI1.js +0 -202
- package/dist/index-zzQS_psa.d.ts +0 -51
- package/dist/protocol-DEubbBbR.js +0 -35
- package/dist/push-BhrMZaQx.js +0 -190
- package/dist/push-cUJBpv5y.js +0 -8
- package/dist/schema-C2yy5KCT.d.ts +0 -6
- package/dist/schema-IFq7ovQq.js +0 -8
- package/dist/snapshot-DMW6j2Ix.js +0 -93
- package/dist/snapshot-DsSRYFe-.d.ts +0 -125
- package/dist/state-vav3VCId.js +0 -5
- package/dist/websocket-eao2rnHL.js +0 -104
package/dist/db/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as type } from "../arktypeConfig-
|
|
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-
|
|
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-
|
|
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 };
|
|
1
|
+
import { t as type } from "../arktypeConfig-AXvobTPL.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-IUthY3Ex.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-BdrcuAU7.js";
|
|
4
|
+
export { type Action, type ActionConfig, type ActionContext, type ActionInfo, type ArgsSchema, CamelCasePlugin, type CompiledQuery, type CreateKyselyOptions, type DatabaseConfig, type DatabaseDefinition, type DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, type DrizzleToKysely, type InferArgs, type Kysely, type KyselyPlugin, type Migration, type MigrationAttemptInfo, MigrationSchemaConflictError, type Migrations, type ParsedDatabaseFile, type QueryResult, SchemaPlugin, type SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
package/dist/db/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { i as init_debug, n as debugMigrations } from "../debug-
|
|
2
|
-
import { t as type } from "../arktypeConfig-
|
|
3
|
-
import { n as defineDatabase } from "../defineDatabase-
|
|
4
|
-
import { a as createDrizzlePlugins, i as SchemaPlugin, n as DateSerializePlugin, o as dateSerializers, r as DrizzleDefaultsPlugin, t as createKyselyFromSql } from "../kysely-
|
|
1
|
+
import { i as init_debug, n as debugMigrations } from "../debug-Cz8KzMft.js";
|
|
2
|
+
import { t as type } from "../arktypeConfig-DxP0OcV_.js";
|
|
3
|
+
import { n as defineDatabase } from "../defineDatabase-CHmzpzFf.js";
|
|
4
|
+
import { a as createDrizzlePlugins, i as SchemaPlugin, n as DateSerializePlugin, o as dateSerializers, r as DrizzleDefaultsPlugin, t as createKyselyFromSql } from "../kysely-Be6KwFZC.js";
|
|
5
5
|
import { DurableObject } from "cloudflare:workers";
|
|
6
6
|
import { CamelCasePlugin } from "kysely";
|
|
7
7
|
import { studio } from "@outerbase/browsable-durable-object";
|
|
8
|
-
|
|
9
8
|
//#region src/db/SqliteDurableObject.ts
|
|
10
9
|
init_debug();
|
|
11
10
|
/**
|
|
@@ -149,8 +148,8 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
149
148
|
* Execute raw SQL statement
|
|
150
149
|
* Used by migrations for direct SQL execution
|
|
151
150
|
*/
|
|
152
|
-
execSql(sql
|
|
153
|
-
this.sql.exec(sql
|
|
151
|
+
execSql(sql) {
|
|
152
|
+
this.sql.exec(sql);
|
|
154
153
|
}
|
|
155
154
|
/**
|
|
156
155
|
* Run pending migrations with PITR safety.
|
|
@@ -235,9 +234,9 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
235
234
|
}
|
|
236
235
|
if (restoreScheduled) {
|
|
237
236
|
const attempts = this.getMigrationAttempts();
|
|
238
|
-
const remaining = Math.max(0,
|
|
237
|
+
const remaining = Math.max(0, 4 - attempts.attemptCount);
|
|
239
238
|
const pendingNames = Array.from(new Set(pending.map((p) => p.name))).join(", ");
|
|
240
|
-
console.error(`[database] Migration failed (attempt ${attempts.attemptCount}
|
|
239
|
+
console.error(`[database] Migration failed (attempt ${attempts.attemptCount}/4, ${remaining} PITR-protected retries remaining). Restoring to pre-migration bookmark. Pending: ${pendingNames || "(none)"}.`, error);
|
|
241
240
|
this.ctx.abort("Restoring to pre-migration bookmark");
|
|
242
241
|
}
|
|
243
242
|
}
|
|
@@ -377,7 +376,7 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
377
376
|
async getMigrationStatus() {
|
|
378
377
|
const attempts = this.getMigrationAttempts();
|
|
379
378
|
const pitrAvailable = await this.checkPitrAvailable();
|
|
380
|
-
const pitrAttemptsRemaining = pitrAvailable ? Math.max(0,
|
|
379
|
+
const pitrAttemptsRemaining = pitrAvailable ? Math.max(0, 4 - attempts.attemptCount) : 0;
|
|
381
380
|
const appliedSet = /* @__PURE__ */ new Set();
|
|
382
381
|
try {
|
|
383
382
|
const rows = this.sql.exec("SELECT DISTINCT name FROM __migrations").toArray();
|
|
@@ -434,6 +433,5 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
434
433
|
ws.close(1011, "Unexpected error");
|
|
435
434
|
}
|
|
436
435
|
};
|
|
437
|
-
|
|
438
436
|
//#endregion
|
|
439
|
-
export { CamelCasePlugin, DateSerializePlugin, DrizzleDefaultsPlugin, MigrationSchemaConflictError, SchemaPlugin, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
437
|
+
export { CamelCasePlugin, DateSerializePlugin, DrizzleDefaultsPlugin, MigrationSchemaConflictError, SchemaPlugin, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region rolldown:runtime
|
|
1
|
+
import "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esmMin = (fn, res) => () =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (symbols) {
|
|
18
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
var __esmMin = (fn, res, err) => () => {
|
|
8
|
+
if (err) throw err[0];
|
|
9
|
+
try {
|
|
10
|
+
return fn && (res = fn(fn = 0)), res;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw err = [e], e;
|
|
19
13
|
}
|
|
14
|
+
};
|
|
15
|
+
var __exportAll = (all, no_symbols) => {
|
|
16
|
+
let target = {};
|
|
17
|
+
for (var name in all) __defProp(target, name, {
|
|
18
|
+
get: all[name],
|
|
19
|
+
enumerable: true
|
|
20
|
+
});
|
|
21
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
20
22
|
return target;
|
|
21
23
|
};
|
|
22
24
|
var __copyProps = (to, from, except, desc) => {
|
|
23
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
26
|
+
key = keys[i];
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
28
|
+
get: ((k) => from[k]).bind(null, key),
|
|
29
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
+
});
|
|
33
31
|
}
|
|
34
32
|
return to;
|
|
35
33
|
};
|
|
36
34
|
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
-
|
|
38
35
|
//#endregion
|
|
39
36
|
//#region src/utils/debug.ts
|
|
40
37
|
function readDebugEnv() {
|
|
@@ -93,6 +90,5 @@ var init_debug = __esmMin((() => {
|
|
|
93
90
|
debugCli = createDebug("database:cli");
|
|
94
91
|
debugMigrations = createDebug("database:migrations");
|
|
95
92
|
}));
|
|
96
|
-
|
|
97
93
|
//#endregion
|
|
98
|
-
export { __esmMin as a, init_debug as i, debugMigrations as n,
|
|
94
|
+
export { __esmMin as a, init_debug as i, debugMigrations as n, __exportAll as o, debugVite as r, __toCommonJS as s, debugCli as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as type } from "./arktypeConfig-
|
|
2
|
-
|
|
1
|
+
import { t as type } from "./arktypeConfig-DxP0OcV_.js";
|
|
3
2
|
//#region src/db/defineDatabase.ts
|
|
4
3
|
/**
|
|
5
4
|
* Non-enumerable property the source `action()` stashes on the function it
|
|
@@ -67,6 +66,5 @@ function defineDatabase(_config) {
|
|
|
67
66
|
destroyDatabase
|
|
68
67
|
};
|
|
69
68
|
}
|
|
70
|
-
|
|
71
69
|
//#endregion
|
|
72
|
-
export { defineDatabase as n, ACTION_TEST_META as t };
|
|
70
|
+
export { defineDatabase as n, ACTION_TEST_META as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import "./arktypeConfig-AXvobTPL.js";
|
|
2
|
+
import { type } from "arktype";
|
|
1
3
|
import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
2
4
|
import { Kysely } from "kysely";
|
|
3
5
|
import { Kyselify } from "drizzle-orm/kysely";
|
|
4
|
-
|
|
5
6
|
//#region src/db/types.d.ts
|
|
6
|
-
|
|
7
7
|
/**
|
|
8
8
|
* Base type for ArkType schema definitions.
|
|
9
9
|
* This represents any valid arktype definition object.
|
|
@@ -29,14 +29,14 @@ interface DatabaseConfig<TSchema extends Record<string, SQLiteTableWithColumns<a
|
|
|
29
29
|
/**
|
|
30
30
|
* Convert a Drizzle schema to Kysely database types using drizzle-kysely
|
|
31
31
|
*/
|
|
32
|
-
type DrizzleToKysely<TSchema extends Record<string, SQLiteTableWithColumns<any>>> = { [K in keyof TSchema]: TSchema[K] extends SQLiteTableWithColumns<any> ? Kyselify<TSchema[K]> : never };
|
|
32
|
+
type DrizzleToKysely<TSchema extends Record<string, SQLiteTableWithColumns<any>>> = { [K in keyof TSchema]: TSchema[K] extends SQLiteTableWithColumns<any> ? Kyselify<TSchema[K]> : never; };
|
|
33
33
|
/**
|
|
34
34
|
* ArkType helpers – mirror Ark's own API:
|
|
35
35
|
* - arkType.validate<Def> → definition shape with DSL validation/autocomplete
|
|
36
36
|
* - arkType.infer<Def> → inferred output type
|
|
37
37
|
*/
|
|
38
|
-
type ArkDef<Def> =
|
|
39
|
-
type InferArgs<Def> =
|
|
38
|
+
type ArkDef<Def> = type.validate<Def>;
|
|
39
|
+
type InferArgs<Def> = type.infer<Def>;
|
|
40
40
|
/**
|
|
41
41
|
* Context passed to action handlers
|
|
42
42
|
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import "./arktypeConfig-AXvobTPL.js";
|
|
2
|
+
import "./defineDatabase-IUthY3Ex.js";
|
|
1
3
|
import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
2
|
-
import { DurableObject } from "cloudflare:workers";
|
|
3
4
|
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
|
-
import {
|
|
5
|
+
import { DurableObject } from "cloudflare:workers";
|
|
5
6
|
import { studio } from "@outerbase/browsable-durable-object";
|
|
6
|
-
|
|
7
|
+
import { Table } from "drizzle-orm";
|
|
7
8
|
//#region src/db/kysely.d.ts
|
|
8
9
|
/**
|
|
9
10
|
* SQL executor function type
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as type } from "./arktypeConfig-
|
|
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-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { t as type } from "./arktypeConfig-AXvobTPL.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-IUthY3Ex.js";
|
|
3
|
+
import { getTenantId, hasTenantId, setTenantIdResolver } from "./context/index.js";
|
|
4
|
+
import { AnySQLiteColumn, blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex } from "./schema.js";
|
|
5
5
|
import { Kysely } from "kysely";
|
|
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,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-kIVZbhye.js";
|
|
7
|
-
|
|
8
|
-
export { blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
|
1
|
+
import { t as type } from "./arktypeConfig-DxP0OcV_.js";
|
|
2
|
+
import { n as defineDatabase } from "./defineDatabase-CHmzpzFf.js";
|
|
3
|
+
import { blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex } from "./schema.js";
|
|
4
|
+
import { getTenantId, hasTenantId, setTenantIdResolver } from "./context/index.js";
|
|
5
|
+
export { blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
|
@@ -2,7 +2,6 @@ import { SQLiteSyncDialect, getTableConfig } from "drizzle-orm/sqlite-core";
|
|
|
2
2
|
import { toCamelCase, toSnakeCase } from "drizzle-orm/casing";
|
|
3
3
|
import { CamelCasePlugin, ColumnNode, ColumnUpdateNode, InsertQueryNode, Kysely, PrimitiveValueListNode, SqliteDialect, TableNode, ValueListNode, ValueNode, ValuesNode, sql } from "kysely";
|
|
4
4
|
import { Table, getTableColumns, getTableName, is, isSQLWrapper } from "drizzle-orm";
|
|
5
|
-
|
|
6
5
|
//#region src/db/plugins.ts
|
|
7
6
|
/**
|
|
8
7
|
* Schema-aware CamelCasePlugin that uses Drizzle schema for column name mapping.
|
|
@@ -116,7 +115,8 @@ var DrizzleDefaultsPlugin = class {
|
|
|
116
115
|
else throw new Error("Unsupported row node type in insert query");
|
|
117
116
|
const processedValues = originalValues.map((val, idx) => {
|
|
118
117
|
if (val.kind === "DefaultInsertValueNode") {
|
|
119
|
-
const
|
|
118
|
+
const colName = providedColumns[idx].column.name;
|
|
119
|
+
const colDef = tableDefaults[colName];
|
|
120
120
|
if (colDef?.defaultFn) return createValueNode(colDef.defaultFn());
|
|
121
121
|
}
|
|
122
122
|
return val;
|
|
@@ -163,17 +163,36 @@ var DrizzleDefaultsPlugin = class {
|
|
|
163
163
|
* SQLite stores dates as TEXT in ISO format (without timezone)
|
|
164
164
|
*/
|
|
165
165
|
const dateSerializers = {
|
|
166
|
+
/**
|
|
167
|
+
* Serialize a Date to SQLite format
|
|
168
|
+
* Converts to ISO string, removes timezone info
|
|
169
|
+
*/
|
|
166
170
|
serialize(value) {
|
|
167
171
|
return value.toISOString().replace("T", " ").slice(0, 19);
|
|
168
172
|
},
|
|
173
|
+
/**
|
|
174
|
+
* Deserialize a SQLite date string to Date
|
|
175
|
+
* Parses assuming UTC timezone
|
|
176
|
+
*/
|
|
169
177
|
deserialize(value) {
|
|
170
178
|
const normalized = value.replace(" ", "T");
|
|
171
179
|
if (/(?:Z|[+-]\d{2}:?\d{2})$/.test(normalized)) return new Date(normalized);
|
|
172
180
|
return /* @__PURE__ */ new Date(normalized + "Z");
|
|
173
181
|
},
|
|
182
|
+
/**
|
|
183
|
+
* Check if a string looks like an ISO date
|
|
184
|
+
*/
|
|
174
185
|
isDateString(value) {
|
|
175
186
|
return /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}/.test(value);
|
|
176
187
|
},
|
|
188
|
+
/**
|
|
189
|
+
* Check if a string matches exactly the format produced by serialize()
|
|
190
|
+
* (and SQLite's CURRENT_TIMESTAMP): `YYYY-MM-DD HH:MM:SS`.
|
|
191
|
+
*
|
|
192
|
+
* The read path only deserializes strings in this exact format. Anything
|
|
193
|
+
* else — full ISO strings with a 'T' separator, timezone, or milliseconds —
|
|
194
|
+
* was stored by the user as a plain string and must round-trip verbatim.
|
|
195
|
+
*/
|
|
177
196
|
isSerializedDateString(value) {
|
|
178
197
|
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(value);
|
|
179
198
|
}
|
|
@@ -314,10 +333,7 @@ var BooleanDeserializePlugin = class {
|
|
|
314
333
|
*/
|
|
315
334
|
function assertValidSchema(schema) {
|
|
316
335
|
if (schema === null || typeof schema !== "object" || Array.isArray(schema)) throw new Error(`[db] Invalid schema: expected a record of Drizzle tables (e.g. { users, posts }), got ${Array.isArray(schema) ? "array" : schema === null ? "null" : typeof schema}.`);
|
|
317
|
-
for (const [key, value] of Object.entries(schema)) if (!is(value, Table)) {
|
|
318
|
-
const got = value === null ? "null" : value === void 0 ? "undefined" : typeof value;
|
|
319
|
-
throw new Error(`[db] Invalid schema: '${key}' is not a Drizzle table (got ${got}). Make sure every value is defined with table() from 'durable-db/schema'.`);
|
|
320
|
-
}
|
|
336
|
+
for (const [key, value] of Object.entries(schema)) if (!is(value, Table)) throw new Error(`[db] Invalid schema: '${key}' is not a Drizzle table (got ${value === null ? "null" : value === void 0 ? "undefined" : typeof value}). Make sure every value is defined with table() from 'durable-db/schema'.`);
|
|
321
337
|
}
|
|
322
338
|
/**
|
|
323
339
|
* Create all recommended plugins for use with Drizzle schemas.
|
|
@@ -339,7 +355,6 @@ function createDrizzlePlugins(schema, camelCase = true) {
|
|
|
339
355
|
plugins.push(new BooleanDeserializePlugin(schema));
|
|
340
356
|
return plugins;
|
|
341
357
|
}
|
|
342
|
-
|
|
343
358
|
//#endregion
|
|
344
359
|
//#region src/db/kysely.ts
|
|
345
360
|
const MAX_BOUND_PARAMETERS = 100;
|
|
@@ -382,16 +397,16 @@ function escapeLiteral(value) {
|
|
|
382
397
|
*
|
|
383
398
|
* Exported for tests.
|
|
384
399
|
*/
|
|
385
|
-
function inlineParameters(sql
|
|
400
|
+
function inlineParameters(sql, parameters) {
|
|
386
401
|
let out = "";
|
|
387
402
|
let p = 0;
|
|
388
|
-
for (let i = 0; i < sql
|
|
389
|
-
const ch = sql
|
|
403
|
+
for (let i = 0; i < sql.length; i++) {
|
|
404
|
+
const ch = sql[i];
|
|
390
405
|
if (ch === "'" || ch === "\"") {
|
|
391
406
|
let j = i + 1;
|
|
392
|
-
while (j < sql
|
|
393
|
-
if (sql
|
|
394
|
-
if (sql
|
|
407
|
+
while (j < sql.length) {
|
|
408
|
+
if (sql[j] === ch) {
|
|
409
|
+
if (sql[j + 1] === ch) {
|
|
395
410
|
j += 2;
|
|
396
411
|
continue;
|
|
397
412
|
}
|
|
@@ -399,21 +414,21 @@ function inlineParameters(sql$1, parameters) {
|
|
|
399
414
|
}
|
|
400
415
|
j++;
|
|
401
416
|
}
|
|
402
|
-
out += sql
|
|
417
|
+
out += sql.slice(i, j + 1);
|
|
403
418
|
i = j;
|
|
404
419
|
continue;
|
|
405
420
|
}
|
|
406
|
-
if (ch === "-" && sql
|
|
407
|
-
let j = sql
|
|
408
|
-
if (j === -1) j = sql
|
|
409
|
-
out += sql
|
|
421
|
+
if (ch === "-" && sql[i + 1] === "-") {
|
|
422
|
+
let j = sql.indexOf("\n", i);
|
|
423
|
+
if (j === -1) j = sql.length;
|
|
424
|
+
out += sql.slice(i, j);
|
|
410
425
|
i = j - 1;
|
|
411
426
|
continue;
|
|
412
427
|
}
|
|
413
|
-
if (ch === "/" && sql
|
|
414
|
-
let j = sql
|
|
415
|
-
j = j === -1 ? sql
|
|
416
|
-
out += sql
|
|
428
|
+
if (ch === "/" && sql[i + 1] === "*") {
|
|
429
|
+
let j = sql.indexOf("*/", i + 2);
|
|
430
|
+
j = j === -1 ? sql.length : j + 2;
|
|
431
|
+
out += sql.slice(i, j);
|
|
417
432
|
i = j - 1;
|
|
418
433
|
continue;
|
|
419
434
|
}
|
|
@@ -432,8 +447,8 @@ function inlineParameters(sql$1, parameters) {
|
|
|
432
447
|
*/
|
|
433
448
|
var CloudflareSqliteDriver = class {
|
|
434
449
|
sql;
|
|
435
|
-
constructor(sql
|
|
436
|
-
this.sql = sql
|
|
450
|
+
constructor(sql) {
|
|
451
|
+
this.sql = sql;
|
|
437
452
|
}
|
|
438
453
|
async init() {}
|
|
439
454
|
async acquireConnection() {
|
|
@@ -455,13 +470,13 @@ var CloudflareSqliteDriver = class {
|
|
|
455
470
|
/**
|
|
456
471
|
* Helper to create a CompiledQuery object
|
|
457
472
|
*/
|
|
458
|
-
function createCompiledQuery(sql
|
|
473
|
+
function createCompiledQuery(sql, parameters = []) {
|
|
459
474
|
return {
|
|
460
|
-
sql
|
|
475
|
+
sql,
|
|
461
476
|
parameters,
|
|
462
477
|
query: {
|
|
463
478
|
kind: "RawNode",
|
|
464
|
-
sqlFragments: [sql
|
|
479
|
+
sqlFragments: [sql],
|
|
465
480
|
parameters: []
|
|
466
481
|
}
|
|
467
482
|
};
|
|
@@ -471,8 +486,8 @@ function createCompiledQuery(sql$1, parameters = []) {
|
|
|
471
486
|
*/
|
|
472
487
|
var CloudflareSqliteConnection = class {
|
|
473
488
|
sql;
|
|
474
|
-
constructor(sql
|
|
475
|
-
this.sql = sql
|
|
489
|
+
constructor(sql) {
|
|
490
|
+
this.sql = sql;
|
|
476
491
|
}
|
|
477
492
|
async executeQuery(compiledQuery) {
|
|
478
493
|
let queryStr = compiledQuery.sql;
|
|
@@ -532,6 +547,5 @@ function createKyselyFromSql(sqlStorage, options = {}) {
|
|
|
532
547
|
plugins: allPlugins
|
|
533
548
|
});
|
|
534
549
|
}
|
|
535
|
-
|
|
536
550
|
//#endregion
|
|
537
|
-
export { createDrizzlePlugins as a, SchemaPlugin as i, DateSerializePlugin as n, dateSerializers as o, DrizzleDefaultsPlugin as r, createKyselyFromSql as t };
|
|
551
|
+
export { createDrizzlePlugins as a, SchemaPlugin as i, DateSerializePlugin as n, dateSerializers as o, DrizzleDefaultsPlugin as r, createKyselyFromSql as t };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { t as Snapshot } from "../snapshot-
|
|
2
|
-
|
|
1
|
+
import { t as Snapshot } from "../snapshot-CaG5xnE2.js";
|
|
3
2
|
//#region src/migrations/generator.d.ts
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Result of migration generation
|
|
7
5
|
*/
|
|
8
|
-
interface MigrationResult {
|
|
6
|
+
export interface MigrationResult {
|
|
9
7
|
/** Whether changes were detected */
|
|
10
8
|
hasChanges: boolean;
|
|
11
9
|
/** Generated SQL statements */
|
|
@@ -20,7 +18,7 @@ interface MigrationResult {
|
|
|
20
18
|
/**
|
|
21
19
|
* Options for migration generation
|
|
22
20
|
*/
|
|
23
|
-
interface GenerateMigrationOptions {
|
|
21
|
+
export interface GenerateMigrationOptions {
|
|
24
22
|
/** Directory to store migrations and snapshots */
|
|
25
23
|
migrationsDir: string;
|
|
26
24
|
/** Drizzle schema objects */
|
|
@@ -33,15 +31,15 @@ interface GenerateMigrationOptions {
|
|
|
33
31
|
/**
|
|
34
32
|
* Load the previous snapshot from the migrations directory
|
|
35
33
|
*/
|
|
36
|
-
declare function loadSnapshot(migrationsDir: string): Snapshot;
|
|
34
|
+
export declare function loadSnapshot(migrationsDir: string): Snapshot;
|
|
37
35
|
/**
|
|
38
36
|
* Save a snapshot to the migrations directory
|
|
39
37
|
*/
|
|
40
|
-
declare function saveSnapshot(migrationsDir: string, snapshot: Snapshot): void;
|
|
38
|
+
export declare function saveSnapshot(migrationsDir: string, snapshot: Snapshot): void;
|
|
41
39
|
/**
|
|
42
40
|
* Generate a timestamp-based migration name
|
|
43
41
|
*/
|
|
44
|
-
declare function generateMigrationName(suffix?: string): string;
|
|
42
|
+
export declare function generateMigrationName(suffix?: string): string;
|
|
45
43
|
/**
|
|
46
44
|
* Generate a migration from schema changes
|
|
47
45
|
*
|
|
@@ -62,18 +60,18 @@ declare function generateMigrationName(suffix?: string): string;
|
|
|
62
60
|
* }
|
|
63
61
|
* ```
|
|
64
62
|
*/
|
|
65
|
-
declare function generateMigration(options: GenerateMigrationOptions): Promise<MigrationResult>;
|
|
63
|
+
export declare function generateMigration(options: GenerateMigrationOptions): Promise<MigrationResult>;
|
|
66
64
|
/**
|
|
67
65
|
* Parse SQL content into chunks (split by breakpoints) and statements
|
|
68
66
|
*
|
|
69
67
|
* @param content - Raw SQL file content
|
|
70
68
|
* @returns Array of chunks, where each chunk is an array of SQL statements
|
|
71
69
|
*/
|
|
72
|
-
declare function parseSqlMigration(content: string): string[][];
|
|
70
|
+
export declare function parseSqlMigration(content: string): string[][];
|
|
73
71
|
/**
|
|
74
72
|
* Migration data structure for embedding in generated code
|
|
75
73
|
*/
|
|
76
|
-
interface MigrationData {
|
|
74
|
+
export interface MigrationData {
|
|
77
75
|
name: string;
|
|
78
76
|
chunks: string[][];
|
|
79
77
|
}
|
|
@@ -81,21 +79,20 @@ interface MigrationData {
|
|
|
81
79
|
* Load all migration SQL files from a directory
|
|
82
80
|
* Returns migrations sorted by name (timestamp order) with breakpoint parsing
|
|
83
81
|
*/
|
|
84
|
-
declare function loadMigrationFiles(migrationsDir: string): Map<string, string[][]>;
|
|
82
|
+
export declare function loadMigrationFiles(migrationsDir: string): Map<string, string[][]>;
|
|
85
83
|
/**
|
|
86
84
|
* Load a schema module using dynamic import
|
|
87
85
|
* Works with both ESM and CJS modules
|
|
88
86
|
*/
|
|
89
|
-
declare function loadSchemaModule(schemaPath: string, tableNames: string[]): Promise<Record<string, unknown>>;
|
|
87
|
+
export declare function loadSchemaModule(schemaPath: string, tableNames: string[]): Promise<Record<string, unknown>>;
|
|
90
88
|
/**
|
|
91
89
|
* Build schema module with esbuild and return the exports
|
|
92
90
|
* This is useful when the schema is TypeScript and needs transpilation
|
|
93
91
|
*/
|
|
94
|
-
declare function buildAndLoadSchema(schemaPath: string, tableNames: string[]): Promise<Record<string, unknown>>;
|
|
92
|
+
export declare function buildAndLoadSchema(schemaPath: string, tableNames: string[]): Promise<Record<string, unknown>>;
|
|
95
93
|
/**
|
|
96
94
|
* Generate SQL to create all tables from scratch
|
|
97
95
|
* Useful for initial setup or testing
|
|
98
96
|
*/
|
|
99
|
-
declare function generateCreateTableSQL(schema: Record<string, unknown>): Promise<string[]>;
|
|
100
|
-
//#endregion
|
|
101
|
-
export { GenerateMigrationOptions, MigrationData, MigrationResult, buildAndLoadSchema, generateCreateTableSQL, generateMigration, generateMigrationName, loadMigrationFiles, loadSchemaModule, loadSnapshot, parseSqlMigration, saveSnapshot };
|
|
97
|
+
export declare function generateCreateTableSQL(schema: Record<string, unknown>): Promise<string[]>;
|
|
98
|
+
//#endregion
|