durable-db 0.13.1 → 0.13.3
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/cli/bin.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/{cli--9cKeEka.js → cli-B_bNgIGE.js} +1 -1
- package/dist/db/index.d.ts +2 -2
- package/dist/{defineDatabase-DlgYfwhP.d.ts → defineDatabase-BmjnvgJ8.d.ts} +44 -8
- package/dist/{index-B5W4m0Dq.d.ts → index-Di-UGgpS.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/migrations/generator.js +2 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +20 -2
- package/dist/vite/durableDb.d.ts +1 -1
- package/package.json +1 -1
package/dist/cli/bin.js
CHANGED
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as DatabaseSource } from "../discovery-gHeLq8jk.js";
|
|
2
2
|
import { C as parseRenameSpec, g as SchemaRenameRequiredError, h as SchemaAmbiguity, m as RenameAnswer, n as Snapshot, t as MigrationResolution, u as MigrationRisk } from "../snapshot-D3_SNABU.js";
|
|
3
|
-
import { l as DatabaseInfo } from "../defineDatabase-
|
|
4
|
-
import "../index-
|
|
3
|
+
import { l as DatabaseInfo } from "../defineDatabase-BmjnvgJ8.js";
|
|
4
|
+
import "../index-Di-UGgpS.js";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import "vite";
|
|
7
7
|
import "@babel/types";
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as getDatabaseEpochs, d as getInstanceKey, f as init_state, g as runningDevServer, l as getDevEpoch, m as loadDevState, o as generateEpoch, p as loadDevMigrations, s as getDatabaseEpoch, u as getDevPaths, v as saveDevState } from "../state-UT6GH0JD.js";
|
|
2
2
|
import { _ as parseRenameSpec, u as SchemaRenameRequiredError } from "../snapshot-CY4FLqAo.js";
|
|
3
3
|
import { n as declaresSchema } from "../parser-mUnAtllk.js";
|
|
4
|
-
import { C as diffSchema, D as reportCliError, E as loadSchemaTables, O as selectDatabases, S as diffDatabases, T as loadSchema, _ as sift, a as reset, b as pushOne, c as status, d as generate, f as generateOne, g as replayWithRows, h as readAccepted, i as DevServerRunningError, l as MigrationFailsOnRowsError, m as accept, n as registerDbCommands, o as resetAndPush, p as ACCEPTED_FILE, r as validate, s as formatStatus, t as createDbCommand, u as UnsafeMigrationError, v as writeAccepted, w as discoverDatabases, x as UnknownDatabaseError, y as push } from "../cli
|
|
4
|
+
import { C as diffSchema, D as reportCliError, E as loadSchemaTables, O as selectDatabases, S as diffDatabases, T as loadSchema, _ as sift, a as reset, b as pushOne, c as status, d as generate, f as generateOne, g as replayWithRows, h as readAccepted, i as DevServerRunningError, l as MigrationFailsOnRowsError, m as accept, n as registerDbCommands, o as resetAndPush, p as ACCEPTED_FILE, r as validate, s as formatStatus, t as createDbCommand, u as UnsafeMigrationError, v as writeAccepted, w as discoverDatabases, x as UnknownDatabaseError, y as push } from "../cli-B_bNgIGE.js";
|
|
5
5
|
init_state();
|
|
6
6
|
export { ACCEPTED_FILE, DevServerRunningError, MigrationFailsOnRowsError, SchemaRenameRequiredError, UnknownDatabaseError, UnsafeMigrationError, accept, createDbCommand, declaresSchema, diffDatabases, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDatabaseEpoch, getDatabaseEpochs, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, loadSchemaTables, parseRenameSpec, push, pushOne, readAccepted, registerDbCommands, replayWithRows, reportCliError, reset, resetAndPush, runningDevServer, saveDevState, selectDatabases, sift, status, validate, writeAccepted };
|
|
@@ -486,7 +486,7 @@ function compare(migration, statements, before, after) {
|
|
|
486
486
|
/** What to do about a failure, by what SQLite said. */
|
|
487
487
|
function remedy(error) {
|
|
488
488
|
if (/NOT NULL constraint failed/i.test(error)) return "a row holds NULL there — give those rows a value in this migration, before the statement: UPDATE … SET … WHERE … IS NULL";
|
|
489
|
-
if (/FOREIGN KEY constraint failed|foreign key mismatch|references a row that is not there/i.test(error)) return "a row references a row that is not there — remove or repair those rows in this migration, before the statement: DELETE FROM … WHERE … NOT IN (SELECT …)";
|
|
489
|
+
if (/FOREIGN KEY constraint failed|foreign key mismatch|references a row that is not there/i.test(error)) return "a row references a row that is not there — remove or repair those rows in this migration, before the statement: add the rows they reference (INSERT INTO … SELECT DISTINCT … WHERE … NOT IN (SELECT …)), or remove the ones that reference nothing (DELETE FROM … WHERE … NOT IN (SELECT …))";
|
|
490
490
|
if (/UNIQUE constraint failed/i.test(error)) return "two rows hold the same value there — make them distinct, or remove one, in this migration before the statement";
|
|
491
491
|
if (/CHECK constraint failed/i.test(error)) return "a row does not meet the check — repair those rows in this migration, before the statement";
|
|
492
492
|
return "it passes on an empty database and fails on one with rows";
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as type } from "../index-bUUlOWfP.js";
|
|
2
|
-
import { C as RelationType, E as relationsOf, S as RelationMap, T as relationOf, _ as RelatedSpec, a as ActionInfo, b as AnySchema, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, g as RelatedOptions, h as RelatedExpression, i as ActionContext, l as DatabaseInfo, m as Related, n as Action, o as ArgsSchema, p as AnyRelated, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely, v as RelatedWhere, w as Relations, x as Relation, y as createRelated } from "../defineDatabase-
|
|
2
|
+
import { C as RelationType, E as relationsOf, S as RelationMap, T as relationOf, _ as RelatedSpec, a as ActionInfo, b as AnySchema, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, g as RelatedOptions, h as RelatedExpression, i as ActionContext, l as DatabaseInfo, m as Related, n as Action, o as ArgsSchema, p as AnyRelated, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely, v as RelatedWhere, w as Relations, x as Relation, y as createRelated } from "../defineDatabase-BmjnvgJ8.js";
|
|
3
3
|
import { a as OutboxSinkContext, c as queueOutboxSink, i as OutboxSink, l as tenantOfInstanceKey, n as OutboxEnvelope, o as OutboxSinkModule, r as OutboxMessage, s as outboxSink, t as Outbox } from "../outbox-D3Q9n7Rt.js";
|
|
4
|
-
import { C as SqliteDurableObject, E as createKyselyFromSql, S as Migrations, T as SqlExecutor, _ as RemovedDatabaseError, a as QueryResult, b as MigrationAttemptInfo, c as DrizzleDefaultsPlugin, d as createDrizzlePlugins, f as createJsonPlugins, g as RemovedDatabaseDurableObject, h as DeleteClassMigration, i as KyselyPlugin, l as JsonPluginOptions, m as parseJsonValue, n as CompiledQuery, o as studio, p as dateSerializers, r as Kysely, s as DateSerializePlugin, t as CamelCasePlugin, u as SchemaPlugin, v as removedDatabaseMessage, w as CreateKyselyOptions, x as MigrationSchemaConflictError, y as Migration } from "../index-
|
|
4
|
+
import { C as SqliteDurableObject, E as createKyselyFromSql, S as Migrations, T as SqlExecutor, _ as RemovedDatabaseError, a as QueryResult, b as MigrationAttemptInfo, c as DrizzleDefaultsPlugin, d as createDrizzlePlugins, f as createJsonPlugins, g as RemovedDatabaseDurableObject, h as DeleteClassMigration, i as KyselyPlugin, l as JsonPluginOptions, m as parseJsonValue, n as CompiledQuery, o as studio, p as dateSerializers, r as Kysely, s as DateSerializePlugin, t as CamelCasePlugin, u as SchemaPlugin, v as removedDatabaseMessage, w as CreateKyselyOptions, x as MigrationSchemaConflictError, y as Migration } from "../index-Di-UGgpS.js";
|
|
5
5
|
export { type Action, type ActionConfig, type ActionContext, type ActionInfo, type AnyRelated, type AnySchema, type ArgsSchema, CamelCasePlugin, type CompiledQuery, type CreateKyselyOptions, type DatabaseConfig, type DatabaseDefinition, type DatabaseInfo, DateSerializePlugin, type DeleteClassMigration, DrizzleDefaultsPlugin, type DrizzleToKysely, type InferArgs, type JsonPluginOptions, type Kysely, type KyselyPlugin, type Migration, type MigrationAttemptInfo, MigrationSchemaConflictError, type Migrations, type Outbox, type OutboxEnvelope, type OutboxMessage, type OutboxSink, type OutboxSinkContext, type OutboxSinkModule, type ParsedDatabaseFile, type QueryResult, type Related, RelatedExpression, type RelatedOptions, type RelatedSpec, type RelatedWhere, type Relation, type RelationMap, type RelationType, type Relations, RemovedDatabaseDurableObject, RemovedDatabaseError, SchemaPlugin, type SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createJsonPlugins, createKyselyFromSql, createRelated, dateSerializers, defineDatabase, outboxSink, parseJsonValue, queueOutboxSink, relationOf, relationsOf, removedDatabaseMessage, studio, tenantOfInstanceKey, type };
|
|
@@ -2,8 +2,7 @@ import "./index-bUUlOWfP.js";
|
|
|
2
2
|
import { t as Outbox } from "./outbox-D3Q9n7Rt.js";
|
|
3
3
|
import { type } from "arktype";
|
|
4
4
|
import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
5
|
-
import { AliasNode, AliasedExpression, Expression, ExpressionBuilder, Kysely, KyselyPlugin, OperationNode, Selectable, SqlBool } from "kysely";
|
|
6
|
-
import { Kyselify } from "drizzle-orm/kysely";
|
|
5
|
+
import { AliasNode, AliasedExpression, ColumnType, Expression, ExpressionBuilder, Kysely, KyselyPlugin, OperationNode, Selectable, SqlBool } from "kysely";
|
|
7
6
|
//#region src/db/relations.d.ts
|
|
8
7
|
type AnySchema = Record<string, SQLiteTableWithColumns<any>>;
|
|
9
8
|
type RefOf<Col> = Col extends {
|
|
@@ -16,7 +15,7 @@ type TableNameOf<Col> = Col extends {
|
|
|
16
15
|
tableName: infer N;
|
|
17
16
|
};
|
|
18
17
|
} ? N : never;
|
|
19
|
-
type ColumnsOf<T> = T extends {
|
|
18
|
+
type ColumnsOf$1<T> = T extends {
|
|
20
19
|
_: {
|
|
21
20
|
columns: infer C;
|
|
22
21
|
};
|
|
@@ -29,16 +28,16 @@ type NameOf<T> = T extends {
|
|
|
29
28
|
type KeyOf<S, Name> = { [K in keyof S & string]: NameOf<S[K]> extends Name ? K : never; }[keyof S & string];
|
|
30
29
|
type TargetOf$1<S, Col> = [RefOf<Col>] extends [never] ? never : string extends TableNameOf<RefOf<Col>> ? never : KeyOf<S, TableNameOf<RefOf<Col>>>;
|
|
31
30
|
/** Every foreign key of a schema the types know: the table and column that hold it, the table it points at. */
|
|
32
|
-
type Edge<S> = { [TK in keyof S & string]: { [CK in keyof ColumnsOf<S[TK]> & string]: [TargetOf$1<S, ColumnsOf<S[TK]>[CK]>] extends [never] ? never : {
|
|
31
|
+
type Edge<S> = { [TK in keyof S & string]: { [CK in keyof ColumnsOf$1<S[TK]> & string]: [TargetOf$1<S, ColumnsOf$1<S[TK]>[CK]>] extends [never] ? never : {
|
|
33
32
|
table: TK;
|
|
34
33
|
column: CK;
|
|
35
|
-
target: TargetOf$1<S, ColumnsOf<S[TK]>[CK]>;
|
|
36
|
-
nullable: ColumnsOf<S[TK]>[CK] extends {
|
|
34
|
+
target: TargetOf$1<S, ColumnsOf$1<S[TK]>[CK]>;
|
|
35
|
+
nullable: ColumnsOf$1<S[TK]>[CK] extends {
|
|
37
36
|
_: {
|
|
38
37
|
notNull: true;
|
|
39
38
|
};
|
|
40
39
|
} ? false : true;
|
|
41
|
-
}; }[keyof ColumnsOf<S[TK]> & string]; }[keyof S & string];
|
|
40
|
+
}; }[keyof ColumnsOf$1<S[TK]> & string]; }[keyof S & string];
|
|
42
41
|
type AnyEdge = {
|
|
43
42
|
table: string;
|
|
44
43
|
column: string;
|
|
@@ -239,7 +238,44 @@ interface DatabaseConfig<TSchema extends Record<string, SQLiteTableWithColumns<a
|
|
|
239
238
|
/**
|
|
240
239
|
* Convert a Drizzle schema to Kysely database types using drizzle-kysely
|
|
241
240
|
*/
|
|
242
|
-
type DrizzleToKysely<TSchema extends Record<string, SQLiteTableWithColumns<any>>> = { [K in keyof TSchema]:
|
|
241
|
+
type DrizzleToKysely<TSchema extends Record<string, SQLiteTableWithColumns<any>>> = { [K in keyof TSchema]: KyselyTable<TSchema[K]>; };
|
|
242
|
+
type ColumnsOf<T> = T extends {
|
|
243
|
+
_: {
|
|
244
|
+
columns: infer C;
|
|
245
|
+
};
|
|
246
|
+
} ? C : never;
|
|
247
|
+
type KyselyTable<T> = { [C in keyof ColumnsOf<T> & string as DbNameOf<C, ColumnsOf<T>[C]>]: KyselyColumn<ColumnsOf<T>[C]>; };
|
|
248
|
+
type DbNameOf<Key, Col> = Col extends {
|
|
249
|
+
_: {
|
|
250
|
+
name: infer N extends string;
|
|
251
|
+
};
|
|
252
|
+
} ? N : Key;
|
|
253
|
+
/** A column's value as a row holds it: null where it may be. */
|
|
254
|
+
type ColumnValue<Col> = Col extends {
|
|
255
|
+
_: {
|
|
256
|
+
notNull: true;
|
|
257
|
+
data: infer D;
|
|
258
|
+
};
|
|
259
|
+
} ? D : Col extends {
|
|
260
|
+
_: {
|
|
261
|
+
data: infer D;
|
|
262
|
+
};
|
|
263
|
+
} ? D | null : never;
|
|
264
|
+
type KyselyColumn<Col> = Col extends {
|
|
265
|
+
_: {
|
|
266
|
+
notNull: true;
|
|
267
|
+
hasDefault: false;
|
|
268
|
+
};
|
|
269
|
+
} ? ColumnValue<Col> : Col extends {
|
|
270
|
+
_: {
|
|
271
|
+
generated: undefined;
|
|
272
|
+
identity: undefined;
|
|
273
|
+
};
|
|
274
|
+
} ? Col extends {
|
|
275
|
+
_: {
|
|
276
|
+
notNull: true;
|
|
277
|
+
};
|
|
278
|
+
} ? ColumnType<ColumnValue<Col>, ColumnValue<Col> | undefined, ColumnValue<Col> | undefined> : ColumnValue<Col> : ColumnType<ColumnValue<Col>, never, never>;
|
|
243
279
|
/**
|
|
244
280
|
* ArkType helpers – mirror Ark's own API:
|
|
245
281
|
* - arkType.validate<Def> → definition shape with DSL validation/autocomplete
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./defineDatabase-
|
|
1
|
+
import "./defineDatabase-BmjnvgJ8.js";
|
|
2
2
|
import { i as OutboxSink, t as Outbox } from "./outbox-D3Q9n7Rt.js";
|
|
3
3
|
import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
4
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";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as Type, l as type } from "./index-bUUlOWfP.js";
|
|
2
|
-
import { C as RelationType, E as relationsOf, S as RelationMap, T as relationOf, _ as RelatedSpec, b as AnySchema, c as DatabaseDefinition, d as InferArgs, g as RelatedOptions, h as RelatedExpression, i as ActionContext, m as Related, n as Action, p as AnyRelated, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely, v as RelatedWhere, w as Relations, x as Relation, y as createRelated } from "./defineDatabase-
|
|
2
|
+
import { C as RelationType, E as relationsOf, S as RelationMap, T as relationOf, _ as RelatedSpec, b as AnySchema, c as DatabaseDefinition, d as InferArgs, g as RelatedOptions, h as RelatedExpression, i as ActionContext, m as Related, n as Action, p as AnyRelated, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely, v as RelatedWhere, w as Relations, x as Relation, y as createRelated } from "./defineDatabase-BmjnvgJ8.js";
|
|
3
3
|
import { a as OutboxSinkContext, i as OutboxSink, n as OutboxEnvelope, o as OutboxSinkModule, r as OutboxMessage, t as Outbox } from "./outbox-D3Q9n7Rt.js";
|
|
4
4
|
import { getTenantId, hasTenantId, setTenantIdResolver } from "./context/index.js";
|
|
5
5
|
import { AnySQLiteColumn, blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex } from "./schema.js";
|
|
@@ -172,7 +172,8 @@ async function buildAndLoadSchema(schemaPath, tableNames) {
|
|
|
172
172
|
format: "esm",
|
|
173
173
|
platform: "node",
|
|
174
174
|
packages: "external",
|
|
175
|
-
target: "node18"
|
|
175
|
+
target: "node18",
|
|
176
|
+
logLevel: "silent"
|
|
176
177
|
});
|
|
177
178
|
if (result.outputFiles?.length !== 1) throw new Error(`Unexpected esbuild output for ${schemaPath}`);
|
|
178
179
|
const tempDir = resolveTempDir(schemaPath);
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
|
3
3
|
import { Kysely } from "kysely";
|
|
4
4
|
import { DatabaseSync } from "node:sqlite";
|
|
5
5
|
//#region src/testing/index.d.ts
|
|
6
|
+
/** `node:sqlite`, loaded without Node 22's experimental notice: for a test that opens a database of its own. */
|
|
7
|
+
export declare const loadSqlite: () => typeof import('node:sqlite');
|
|
6
8
|
type Schema = Record<string, SQLiteTableWithColumns<any>>;
|
|
7
9
|
export interface CreateTestDatabaseOptions {
|
|
8
10
|
/**
|
package/dist/testing/index.js
CHANGED
|
@@ -6,7 +6,25 @@ import { c as tenantOfInstanceKey, i as createActionOutbox, t as createKyselyFro
|
|
|
6
6
|
import { i as generateSnapshotFromSchema, n as createEmptySnapshot, r as generateMigrationStatements } from "../snapshot-CY4FLqAo.js";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
//#region src/testing/index.ts
|
|
9
|
-
|
|
9
|
+
let sqlite;
|
|
10
|
+
/** `node:sqlite`, loaded without Node 22's experimental notice: for a test that opens a database of its own. */
|
|
11
|
+
const loadSqlite = () => {
|
|
12
|
+
if (sqlite) return sqlite;
|
|
13
|
+
const emit = process.emitWarning;
|
|
14
|
+
process.emitWarning = function(warning, ...rest) {
|
|
15
|
+
const option = rest[0];
|
|
16
|
+
const type = typeof option === "string" ? option : option?.type ?? (warning instanceof Error ? warning.name : void 0);
|
|
17
|
+
const text = warning instanceof Error ? warning.message : String(warning);
|
|
18
|
+
if (type === "ExperimentalWarning" && text.startsWith("SQLite ")) return;
|
|
19
|
+
return emit.call(process, warning, ...rest);
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
sqlite = createRequire(import.meta.url)("node:sqlite");
|
|
23
|
+
} finally {
|
|
24
|
+
process.emitWarning = emit;
|
|
25
|
+
}
|
|
26
|
+
return sqlite;
|
|
27
|
+
};
|
|
10
28
|
/**
|
|
11
29
|
* A `SqlStorage`-shaped shim over a synchronous `node:sqlite` connection — the
|
|
12
30
|
* minimal surface `createKyselyFromSql` drives (`exec(sql, …params).toArray()`).
|
|
@@ -113,4 +131,4 @@ async function createTestDatabase(options) {
|
|
|
113
131
|
};
|
|
114
132
|
}
|
|
115
133
|
//#endregion
|
|
116
|
-
export { createTestDatabase };
|
|
134
|
+
export { createTestDatabase, loadSqlite };
|
package/dist/vite/durableDb.d.ts
CHANGED