durable-db 0.8.0 → 0.9.0
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/README.md +124 -0
- package/dist/cli/index.d.ts +2 -2
- package/dist/db/index.d.ts +3 -3
- package/dist/db/index.js +215 -8
- package/dist/defineDatabase-BvFOZVkv.d.ts +377 -0
- package/dist/defineDatabase-CaqKQagA.js +767 -0
- package/dist/describeAction-CEKfxTQ4.js +24 -0
- package/dist/{index-rlnVnzJJ.d.ts → index-DoxI1p4-.d.ts} +1 -1
- package/dist/index.d.ts +19 -3
- package/dist/index.js +3 -2
- package/dist/kysely-D8JQ4v8n.js +278 -0
- package/dist/registry.d.ts +15 -0
- package/dist/registry.js +30 -2
- package/dist/schema.d.ts +15 -2
- package/dist/testing/index.js +2 -2
- package/dist/vite/durableDb.d.ts +1 -1
- package/dist/vite/durableDb.js +35 -1
- package/package.json +1 -1
- package/virtual.d.ts +12 -0
- package/dist/defineDatabase-595bNB6M.js +0 -110
- package/dist/defineDatabase-By401iHp.d.ts +0 -200
- package/dist/kysely-DvAoap5h.js +0 -631
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
import { r as type } from "./type-CUgZsZp3.js";
|
|
2
|
+
import { t as actionArgsType } from "./actionArgs-DP2tQrlf.js";
|
|
3
|
+
import { Table, getTableColumns, getTableName, is, isSQLWrapper } from "drizzle-orm";
|
|
4
|
+
import { SQLiteSyncDialect, getTableConfig } from "drizzle-orm/sqlite-core";
|
|
5
|
+
import { AliasNode, CamelCasePlugin, ColumnNode, ColumnUpdateNode, IdentifierNode, InsertQueryNode, PrimitiveValueListNode, TableNode, ValueListNode, ValueNode, ValuesNode, sql } from "kysely";
|
|
6
|
+
import { toCamelCase, toSnakeCase } from "drizzle-orm/casing";
|
|
7
|
+
//#region src/db/relations.ts
|
|
8
|
+
const registries = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
function forwardName(column) {
|
|
10
|
+
if (column.length > 2 && column.endsWith("Id")) return column.slice(0, -2);
|
|
11
|
+
if (column.length > 3 && column.endsWith("_id")) return column.slice(0, -3);
|
|
12
|
+
return column;
|
|
13
|
+
}
|
|
14
|
+
const capitalize = (value) => value.charAt(0).toUpperCase() + value.slice(1);
|
|
15
|
+
function propertyOf(table, column) {
|
|
16
|
+
for (const [property, candidate] of Object.entries(getTableColumns(table))) if (candidate === column) return property;
|
|
17
|
+
}
|
|
18
|
+
function build(schema) {
|
|
19
|
+
const keys = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const [key, table] of Object.entries(schema)) keys.set(table, key);
|
|
21
|
+
const found = [];
|
|
22
|
+
for (const [key, table] of Object.entries(schema)) for (const foreignKey of getTableConfig(table).foreignKeys) {
|
|
23
|
+
const { columns, foreignTable, foreignColumns } = foreignKey.reference();
|
|
24
|
+
if (columns.length !== 1 || foreignColumns.length !== 1) continue;
|
|
25
|
+
const target = keys.get(foreignTable);
|
|
26
|
+
const column = propertyOf(table, columns[0]);
|
|
27
|
+
const foreign = target === void 0 ? void 0 : propertyOf(foreignTable, foreignColumns[0]);
|
|
28
|
+
if (target === void 0 || column === void 0 || foreign === void 0) continue;
|
|
29
|
+
found.push({
|
|
30
|
+
table: key,
|
|
31
|
+
column,
|
|
32
|
+
target,
|
|
33
|
+
foreign,
|
|
34
|
+
nullable: !columns[0].notNull
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const registry = {
|
|
38
|
+
relations: {},
|
|
39
|
+
conflicts: /* @__PURE__ */ new Map()
|
|
40
|
+
};
|
|
41
|
+
for (const key of Object.keys(schema)) registry.relations[key] = {};
|
|
42
|
+
const claims = /* @__PURE__ */ new Map();
|
|
43
|
+
const add = (relation, from) => {
|
|
44
|
+
const claim = `${relation.table}.${relation.name}`;
|
|
45
|
+
const earlier = claims.get(claim);
|
|
46
|
+
if (earlier === void 0) {
|
|
47
|
+
claims.set(claim, from);
|
|
48
|
+
registry.relations[relation.table][relation.name] = relation;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
delete registry.relations[relation.table][relation.name];
|
|
52
|
+
let ofTable = registry.conflicts.get(relation.table);
|
|
53
|
+
if (!ofTable) registry.conflicts.set(relation.table, ofTable = /* @__PURE__ */ new Map());
|
|
54
|
+
const claimed = ofTable.get(relation.name) ?? [earlier];
|
|
55
|
+
claimed.push(from);
|
|
56
|
+
ofTable.set(relation.name, claimed);
|
|
57
|
+
};
|
|
58
|
+
for (const edge of found) {
|
|
59
|
+
const from = `${edge.table}.${edge.column} → ${edge.target}.${edge.foreign}`;
|
|
60
|
+
const forward = forwardName(edge.column);
|
|
61
|
+
add({
|
|
62
|
+
kind: "one",
|
|
63
|
+
name: forward,
|
|
64
|
+
table: edge.table,
|
|
65
|
+
target: edge.target,
|
|
66
|
+
local: edge.column,
|
|
67
|
+
foreign: edge.foreign,
|
|
68
|
+
nullable: edge.nullable
|
|
69
|
+
}, from);
|
|
70
|
+
add({
|
|
71
|
+
kind: "many",
|
|
72
|
+
name: found.filter((other) => other.table === edge.table && other.target === edge.target).length > 1 ? `${edge.table}As${capitalize(forward)}` : edge.table,
|
|
73
|
+
table: edge.target,
|
|
74
|
+
target: edge.table,
|
|
75
|
+
local: edge.foreign,
|
|
76
|
+
foreign: edge.column,
|
|
77
|
+
nullable: false
|
|
78
|
+
}, from);
|
|
79
|
+
}
|
|
80
|
+
return registry;
|
|
81
|
+
}
|
|
82
|
+
function registryOf(schema) {
|
|
83
|
+
let registry = registries.get(schema);
|
|
84
|
+
if (!registry) registries.set(schema, registry = build(schema));
|
|
85
|
+
return registry;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The relations a schema's foreign keys declare, per table. Read the first
|
|
89
|
+
* time it is asked for (a foreign key's target is a callback, so every table
|
|
90
|
+
* of the schema exists by then) and kept.
|
|
91
|
+
*/
|
|
92
|
+
function relationsOf(schema) {
|
|
93
|
+
return registryOf(schema).relations;
|
|
94
|
+
}
|
|
95
|
+
/** One relation of a table, or an error that says what there is. */
|
|
96
|
+
function relationOf(schema, table, name) {
|
|
97
|
+
const registry = registryOf(schema);
|
|
98
|
+
const ofTable = registry.relations[table];
|
|
99
|
+
if (!ofTable) throw new Error(`[durable-db] "${table}" is not a table of this database's schema (its tables: ${Object.keys(schema).join(", ") || "none"}).`);
|
|
100
|
+
const relation = ofTable[name];
|
|
101
|
+
if (relation) return relation;
|
|
102
|
+
const claimed = registry.conflicts.get(table)?.get(name);
|
|
103
|
+
if (claimed) throw new Error(`[durable-db] "${table}" has ${claimed.length} relations that would be named "${name}" (${claimed.join("; ")}): rename a column so each gets a name of its own.`);
|
|
104
|
+
const names = Object.keys(ofTable);
|
|
105
|
+
throw new Error(`[durable-db] "${table}" has no relation "${name}". ` + (names.length > 0 ? `Its relations: ${names.join(", ")}.` : "No foreign key leads to or from it: a relation is a column with .references(() => other.column)."));
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/db/plugins.ts
|
|
109
|
+
/**
|
|
110
|
+
* Schema-aware CamelCasePlugin that uses Drizzle schema for column name mapping.
|
|
111
|
+
*
|
|
112
|
+
* Extends CamelCasePlugin to handle non-standard column names that don't follow
|
|
113
|
+
* simple camelCase ↔ snake_case conversion. For example, a JS property `userId`
|
|
114
|
+
* mapped to SQL column `user_identifier` would be handled correctly.
|
|
115
|
+
*
|
|
116
|
+
* Falls back to standard CamelCasePlugin behavior for columns not in the schema.
|
|
117
|
+
*/
|
|
118
|
+
var SchemaPlugin = class extends CamelCasePlugin {
|
|
119
|
+
jsToSql;
|
|
120
|
+
sqlToJs;
|
|
121
|
+
constructor(schema) {
|
|
122
|
+
super();
|
|
123
|
+
this.jsToSql = /* @__PURE__ */ new Map();
|
|
124
|
+
this.sqlToJs = /* @__PURE__ */ new Map();
|
|
125
|
+
for (const [schemaKey, table] of Object.entries(schema)) {
|
|
126
|
+
const tableConfig = getTableConfig(table);
|
|
127
|
+
const sqlTableName = tableConfig.name;
|
|
128
|
+
if (schemaKey !== sqlTableName) {
|
|
129
|
+
this.jsToSql.set(schemaKey, sqlTableName);
|
|
130
|
+
this.sqlToJs.set(sqlTableName, schemaKey);
|
|
131
|
+
}
|
|
132
|
+
const sqlColumnNames = new Set(tableConfig.columns.map((c) => c.name));
|
|
133
|
+
for (const [propertyName, value] of Object.entries(table)) if (value && typeof value === "object" && "name" in value && typeof value.name === "string" && sqlColumnNames.has(value.name) && propertyName !== value.name) {
|
|
134
|
+
this.jsToSql.set(propertyName, value.name);
|
|
135
|
+
this.sqlToJs.set(value.name, propertyName);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
snakeCase(str) {
|
|
140
|
+
return this.jsToSql.get(str) ?? super.snakeCase(str);
|
|
141
|
+
}
|
|
142
|
+
camelCase(str) {
|
|
143
|
+
return this.sqlToJs.get(str) ?? super.camelCase(str);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function getKyselyTableName(node) {
|
|
147
|
+
if (node && TableNode.is(node)) return node.table.identifier.name;
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function getKyselyColumnName(node) {
|
|
151
|
+
if (!node) return null;
|
|
152
|
+
if (ColumnNode.is(node)) return node.column.name;
|
|
153
|
+
if (ColumnUpdateNode.is(node) && node.column) return getKyselyColumnName(node.column);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function convertDrizzleSql(drizzleSql) {
|
|
157
|
+
return drizzleSql.sql.split("?").reduce((acc, part, index) => {
|
|
158
|
+
const param = index < drizzleSql.params.length ? drizzleSql.params[index] : "";
|
|
159
|
+
return acc + part + param;
|
|
160
|
+
}, "");
|
|
161
|
+
}
|
|
162
|
+
function createValueNode(val) {
|
|
163
|
+
if (isSQLWrapper(val)) {
|
|
164
|
+
const drizzleSql = new SQLiteSyncDialect().sqlToQuery(val);
|
|
165
|
+
return sql.raw(convertDrizzleSql(drizzleSql)).toOperationNode();
|
|
166
|
+
}
|
|
167
|
+
return ValueNode.create(val);
|
|
168
|
+
}
|
|
169
|
+
function extractDefaults(schemas) {
|
|
170
|
+
const defaults = /* @__PURE__ */ new Map();
|
|
171
|
+
for (const schema of Object.values(schemas)) {
|
|
172
|
+
const tableName = toCamelCase(getTableName(schema));
|
|
173
|
+
const columns = getTableColumns(schema);
|
|
174
|
+
const tableDefaults = {};
|
|
175
|
+
for (const column of Object.values(columns)) {
|
|
176
|
+
const { defaultFn, onUpdateFn, name } = column;
|
|
177
|
+
if (defaultFn || onUpdateFn) tableDefaults[name] = {
|
|
178
|
+
defaultFn,
|
|
179
|
+
onUpdateFn
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (Object.keys(tableDefaults).length > 0) defaults.set(tableName, tableDefaults);
|
|
183
|
+
}
|
|
184
|
+
return defaults;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Plugin that handles Drizzle's defaultFn and onUpdateFn during Kysely queries.
|
|
188
|
+
*
|
|
189
|
+
* On INSERT: auto-populates columns that have a defaultFn but weren't provided,
|
|
190
|
+
* and resolves DefaultInsertValueNode markers to actual values.
|
|
191
|
+
*
|
|
192
|
+
* On UPDATE: auto-adds column updates for columns with onUpdateFn that weren't
|
|
193
|
+
* already included in the SET clause.
|
|
194
|
+
*/
|
|
195
|
+
var DrizzleDefaultsPlugin = class {
|
|
196
|
+
defaults;
|
|
197
|
+
constructor(drizzleSchemas) {
|
|
198
|
+
this.defaults = extractDefaults(drizzleSchemas);
|
|
199
|
+
}
|
|
200
|
+
transformInsertQuery(node) {
|
|
201
|
+
const tableName = getKyselyTableName(node.into);
|
|
202
|
+
if (!tableName) return node;
|
|
203
|
+
const tableDefaults = this.defaults.get(tableName);
|
|
204
|
+
if (!tableDefaults) return node;
|
|
205
|
+
if (!node.values || !ValuesNode.is(node.values)) return node;
|
|
206
|
+
const providedColumns = node.columns ?? [];
|
|
207
|
+
const providedColumnNames = providedColumns.map((col) => col.column.name);
|
|
208
|
+
const missingDefaults = Object.entries(tableDefaults).filter(([colName, { defaultFn }]) => defaultFn && !providedColumnNames.includes(colName)).map(([colName, { defaultFn }]) => ({
|
|
209
|
+
name: colName,
|
|
210
|
+
defaultFn
|
|
211
|
+
}));
|
|
212
|
+
const newColumns = [...providedColumns, ...missingDefaults.map(({ name }) => ColumnNode.create(name))];
|
|
213
|
+
const newRows = node.values.values.map((rowNode) => {
|
|
214
|
+
if (missingDefaults.length === 0 && PrimitiveValueListNode.is(rowNode)) return rowNode;
|
|
215
|
+
let originalValues;
|
|
216
|
+
if (PrimitiveValueListNode.is(rowNode)) originalValues = rowNode.values.map((val) => ValueNode.create(val));
|
|
217
|
+
else if (ValueListNode.is(rowNode)) originalValues = [...rowNode.values];
|
|
218
|
+
else throw new Error("Unsupported row node type in insert query");
|
|
219
|
+
const processedValues = originalValues.map((val, idx) => {
|
|
220
|
+
if (val.kind === "DefaultInsertValueNode") {
|
|
221
|
+
const colName = providedColumns[idx].column.name;
|
|
222
|
+
const colDef = tableDefaults[colName];
|
|
223
|
+
if (colDef?.defaultFn) return createValueNode(colDef.defaultFn());
|
|
224
|
+
}
|
|
225
|
+
return val;
|
|
226
|
+
});
|
|
227
|
+
const missingValues = missingDefaults.map(({ defaultFn }) => createValueNode(defaultFn()));
|
|
228
|
+
return ValueListNode.create([...processedValues, ...missingValues]);
|
|
229
|
+
});
|
|
230
|
+
return InsertQueryNode.cloneWith(node, {
|
|
231
|
+
columns: newColumns,
|
|
232
|
+
values: ValuesNode.create(newRows)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
transformUpdateQuery(node) {
|
|
236
|
+
const tableName = getKyselyTableName(node.table);
|
|
237
|
+
if (!tableName) return node;
|
|
238
|
+
const tableDefaults = this.defaults.get(tableName);
|
|
239
|
+
if (!tableDefaults) return node;
|
|
240
|
+
const existingUpdates = new Set(node.updates?.map(getKyselyColumnName) || []);
|
|
241
|
+
const newUpdates = node.updates ? [...node.updates] : [];
|
|
242
|
+
for (const [colName, { onUpdateFn }] of Object.entries(tableDefaults)) {
|
|
243
|
+
if (!onUpdateFn || existingUpdates.has(colName)) continue;
|
|
244
|
+
newUpdates.push(ColumnUpdateNode.create(ColumnNode.create(colName), createValueNode(onUpdateFn())));
|
|
245
|
+
}
|
|
246
|
+
if (newUpdates.length === (node.updates?.length || 0)) return node;
|
|
247
|
+
return {
|
|
248
|
+
...node,
|
|
249
|
+
updates: newUpdates
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
transformQuery(args) {
|
|
253
|
+
const { node } = args;
|
|
254
|
+
switch (node.kind) {
|
|
255
|
+
case "InsertQueryNode": return this.transformInsertQuery(node);
|
|
256
|
+
case "UpdateQueryNode": return this.transformUpdateQuery(node);
|
|
257
|
+
default: return node;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async transformResult(args) {
|
|
261
|
+
return args.result;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Date serialization helpers for SQLite
|
|
266
|
+
* SQLite stores dates as TEXT in ISO format (without timezone)
|
|
267
|
+
*/
|
|
268
|
+
const dateSerializers = {
|
|
269
|
+
/**
|
|
270
|
+
* Serialize a Date to SQLite format
|
|
271
|
+
* Converts to ISO string, removes timezone info
|
|
272
|
+
*/
|
|
273
|
+
serialize(value) {
|
|
274
|
+
return value.toISOString().replace("T", " ").slice(0, 19);
|
|
275
|
+
},
|
|
276
|
+
/**
|
|
277
|
+
* Deserialize a SQLite date string to Date
|
|
278
|
+
* Parses assuming UTC timezone
|
|
279
|
+
*/
|
|
280
|
+
deserialize(value) {
|
|
281
|
+
const normalized = value.replace(" ", "T");
|
|
282
|
+
if (/(?:Z|[+-]\d{2}:?\d{2})$/.test(normalized)) return new Date(normalized);
|
|
283
|
+
return /* @__PURE__ */ new Date(normalized + "Z");
|
|
284
|
+
},
|
|
285
|
+
/**
|
|
286
|
+
* Check if a string looks like an ISO date
|
|
287
|
+
*/
|
|
288
|
+
isDateString(value) {
|
|
289
|
+
return /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}/.test(value);
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* Check if a string matches exactly the format produced by serialize()
|
|
293
|
+
* (and SQLite's CURRENT_TIMESTAMP): `YYYY-MM-DD HH:MM:SS`.
|
|
294
|
+
*
|
|
295
|
+
* The read path only deserializes strings in this exact format. Anything
|
|
296
|
+
* else — full ISO strings with a 'T' separator, timezone, or milliseconds —
|
|
297
|
+
* was stored by the user as a plain string and must round-trip verbatim.
|
|
298
|
+
*/
|
|
299
|
+
isSerializedDateString(value) {
|
|
300
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(value);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Collect the names of columns that Drizzle declares as date-typed
|
|
305
|
+
* (e.g. `integer({ mode: 'timestamp' })`). Includes both the SQL column
|
|
306
|
+
* name and the JS property name, since result rows may be seen in either
|
|
307
|
+
* form depending on where this plugin sits relative to CamelCasePlugin.
|
|
308
|
+
*/
|
|
309
|
+
function collectDateColumnNames(schema) {
|
|
310
|
+
const dateColumns = /* @__PURE__ */ new Set();
|
|
311
|
+
for (const table of Object.values(schema)) {
|
|
312
|
+
const columns = getTableColumns(table);
|
|
313
|
+
for (const [propertyName, column] of Object.entries(columns)) if (column.dataType === "date") {
|
|
314
|
+
dateColumns.add(column.name);
|
|
315
|
+
dateColumns.add(propertyName);
|
|
316
|
+
dateColumns.add(toSnakeCase(propertyName));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return dateColumns;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Plugin that serializes/deserializes Date objects for SQLite
|
|
323
|
+
*
|
|
324
|
+
* On query: Converts Date objects to ISO strings
|
|
325
|
+
* On result: Converts stored date strings back to Date objects — but only
|
|
326
|
+
* for values in the exact format the write path produces, and (when a schema
|
|
327
|
+
* is provided) only for columns Drizzle declares as date-typed. Plain text
|
|
328
|
+
* columns holding date-looking strings round-trip verbatim.
|
|
329
|
+
*/
|
|
330
|
+
var DateSerializePlugin = class {
|
|
331
|
+
/**
|
|
332
|
+
* Names of date-typed columns (SQL and JS forms) when constructed with a
|
|
333
|
+
* schema; null means "no schema available", which falls back to matching
|
|
334
|
+
* on value format alone.
|
|
335
|
+
*/
|
|
336
|
+
dateColumns;
|
|
337
|
+
constructor(schema) {
|
|
338
|
+
this.dateColumns = schema ? collectDateColumnNames(schema) : null;
|
|
339
|
+
}
|
|
340
|
+
transformQuery(args) {
|
|
341
|
+
return this.transformNode(args.node);
|
|
342
|
+
}
|
|
343
|
+
transformNode(node) {
|
|
344
|
+
if (node === null || node === void 0) return node;
|
|
345
|
+
if (node instanceof Date) return dateSerializers.serialize(node);
|
|
346
|
+
if (Array.isArray(node)) return node.map((item) => this.transformNode(item));
|
|
347
|
+
if (typeof node === "object") {
|
|
348
|
+
const result = {};
|
|
349
|
+
for (const [key, value] of Object.entries(node)) result[key] = this.transformNode(value);
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
return node;
|
|
353
|
+
}
|
|
354
|
+
async transformResult(args) {
|
|
355
|
+
return {
|
|
356
|
+
...args.result,
|
|
357
|
+
rows: args.result.rows.map((row) => this.transformRow(row))
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
transformRow(row) {
|
|
361
|
+
const result = {};
|
|
362
|
+
for (const [key, value] of Object.entries(row)) if (typeof value === "string" && this.shouldDeserialize(key, value)) result[key] = dateSerializers.deserialize(value);
|
|
363
|
+
else result[key] = value;
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
shouldDeserialize(key, value) {
|
|
367
|
+
if (this.dateColumns && !this.dateColumns.has(key)) return false;
|
|
368
|
+
return dateSerializers.isSerializedDateString(value);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Collect the names of columns Drizzle declares as boolean-typed
|
|
373
|
+
* (`integer({ mode: 'boolean' })`). Mirrors collectDateColumnNames: covers
|
|
374
|
+
* the SQL column name, the JS property name, and the snake_cased property
|
|
375
|
+
* name, so it works on either side of the CamelCasePlugin.
|
|
376
|
+
*/
|
|
377
|
+
function collectBooleanColumnNames(schema) {
|
|
378
|
+
const booleanColumns = /* @__PURE__ */ new Set();
|
|
379
|
+
for (const table of Object.values(schema)) {
|
|
380
|
+
const columns = getTableColumns(table);
|
|
381
|
+
for (const [propertyName, column] of Object.entries(columns)) if (column.dataType === "boolean") {
|
|
382
|
+
booleanColumns.add(column.name);
|
|
383
|
+
booleanColumns.add(propertyName);
|
|
384
|
+
booleanColumns.add(toSnakeCase(propertyName));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return booleanColumns;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Plugin that deserializes boolean-mode columns on read.
|
|
391
|
+
*
|
|
392
|
+
* SQLite stores booleans as INTEGER 1/0 (the write side is normalized in the
|
|
393
|
+
* driver — see normalizeParameter in kysely.ts), so schema-declared boolean
|
|
394
|
+
* columns come back as numbers and must be mapped to real booleans. Legacy
|
|
395
|
+
* rows written before the driver normalization existed carry TEXT
|
|
396
|
+
* 'true'/'false' — those are mapped too, so old data keeps reading correctly.
|
|
397
|
+
* Anything unrecognized round-trips verbatim rather than being guessed at.
|
|
398
|
+
*/
|
|
399
|
+
var BooleanDeserializePlugin = class {
|
|
400
|
+
booleanColumns;
|
|
401
|
+
constructor(schema) {
|
|
402
|
+
this.booleanColumns = collectBooleanColumnNames(schema);
|
|
403
|
+
}
|
|
404
|
+
transformQuery(args) {
|
|
405
|
+
return args.node;
|
|
406
|
+
}
|
|
407
|
+
async transformResult(args) {
|
|
408
|
+
if (this.booleanColumns.size === 0) return args.result;
|
|
409
|
+
return {
|
|
410
|
+
...args.result,
|
|
411
|
+
rows: args.result.rows.map((row) => this.transformRow(row))
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
transformRow(row) {
|
|
415
|
+
const result = {};
|
|
416
|
+
for (const [key, value] of Object.entries(row)) result[key] = this.booleanColumns.has(key) ? this.toBoolean(value) : value;
|
|
417
|
+
return result;
|
|
418
|
+
}
|
|
419
|
+
toBoolean(value) {
|
|
420
|
+
if (value === null || value === void 0 || typeof value === "boolean") return value;
|
|
421
|
+
if (typeof value === "number") return value !== 0;
|
|
422
|
+
if (typeof value === "bigint") return value !== 0n;
|
|
423
|
+
if (value === "true" || value === "1") return true;
|
|
424
|
+
if (value === "false" || value === "0") return false;
|
|
425
|
+
return value;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* Validate that a schema object is shaped like a record of Drizzle tables.
|
|
430
|
+
*
|
|
431
|
+
* Throws a descriptive error pointing at the offending key when the schema
|
|
432
|
+
* is not a plain object or when any value isn't a Drizzle `Table`. This
|
|
433
|
+
* catches the common foot-guns (passing a Drizzle relations helper, a plain
|
|
434
|
+
* column builder, or `undefined` because of a missing import) before Kysely
|
|
435
|
+
* plugins crash with an unhelpful stack deep inside their constructors.
|
|
436
|
+
*/
|
|
437
|
+
function assertValidSchema(schema) {
|
|
438
|
+
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}.`);
|
|
439
|
+
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'.`);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create all recommended plugins for use with Drizzle schemas.
|
|
443
|
+
*
|
|
444
|
+
* Includes:
|
|
445
|
+
* - DrizzleDefaultsPlugin: auto-populates defaultFn/onUpdateFn values
|
|
446
|
+
* - SchemaPlugin (extends CamelCasePlugin): schema-aware camelCase ↔ snake_case
|
|
447
|
+
* - DateSerializePlugin: Date ↔ SQLite text serialization
|
|
448
|
+
* - BooleanDeserializePlugin: boolean-mode columns read back as booleans
|
|
449
|
+
*
|
|
450
|
+
* When camelCase is false, SchemaPlugin is omitted.
|
|
451
|
+
*/
|
|
452
|
+
function createDrizzlePlugins(schema, camelCase = true) {
|
|
453
|
+
assertValidSchema(schema);
|
|
454
|
+
const plugins = [];
|
|
455
|
+
plugins.push(new DrizzleDefaultsPlugin(schema));
|
|
456
|
+
if (camelCase) plugins.push(new SchemaPlugin(schema));
|
|
457
|
+
plugins.push(new DateSerializePlugin(schema));
|
|
458
|
+
plugins.push(new BooleanDeserializePlugin(schema));
|
|
459
|
+
return plugins;
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/db/related.ts
|
|
463
|
+
const RELATED = Symbol.for("durable-db.related");
|
|
464
|
+
const specs = /* @__PURE__ */ new WeakMap();
|
|
465
|
+
function metaOf(spec) {
|
|
466
|
+
return {
|
|
467
|
+
target: spec.relation.target,
|
|
468
|
+
with: new Map(spec.with.map((nested) => [nested.relation.name, metaOf(nested)]))
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function render(spec, outer, depth) {
|
|
472
|
+
const { relation } = spec;
|
|
473
|
+
const row = `_r${depth}`;
|
|
474
|
+
const pairs = spec.columns.map((column) => sql`${sql.lit(column)}, ${sql.ref(`${row}.${column}`)}`);
|
|
475
|
+
for (const nested of spec.with) pairs.push(sql`${sql.lit(nested.relation.name)}, json(${render(nested, row, depth + 1)})`);
|
|
476
|
+
const object = sql`json_object(${sql.join(pairs)})`;
|
|
477
|
+
const target = sql.table(relation.target);
|
|
478
|
+
const matches = (alias) => sql`${sql.ref(`${alias}.${relation.foreign}`)} = ${sql.ref(`${outer}.${relation.local}`)}`;
|
|
479
|
+
if (relation.kind === "one") return sql`(select ${object} from ${target} as ${sql.ref(row)} where ${matches(row)} limit 1)`;
|
|
480
|
+
if (spec.orderBy.length === 0 && spec.limit === void 0) return sql`(select json_group_array(${object}) from ${target} as ${sql.ref(row)} where ${matches(row)})`;
|
|
481
|
+
const inner = `_s${depth}`;
|
|
482
|
+
const order = spec.orderBy.length === 0 ? sql`` : sql` order by ${sql.join(spec.orderBy.map(([column, direction]) => sql`${sql.ref(`${inner}.${column}`)} ${sql.raw(direction)}`))}`;
|
|
483
|
+
const limit = spec.limit === void 0 ? sql`` : sql` limit ${sql.lit(spec.limit)}`;
|
|
484
|
+
return sql`(select json_group_array(${object}) from (select * from ${target} as ${sql.ref(inner)} where ${matches(inner)}${order}${limit}) as ${sql.ref(row)})`;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* A relation as a selection: what `related()` returns. `table` is the table
|
|
488
|
+
* it is a relation of (so `with` takes only the related table's own), `alias`
|
|
489
|
+
* the relation's name — the key it is answered under.
|
|
490
|
+
*/
|
|
491
|
+
var RelatedExpression = class {
|
|
492
|
+
table;
|
|
493
|
+
alias;
|
|
494
|
+
constructor(spec) {
|
|
495
|
+
this.table = spec.relation.table;
|
|
496
|
+
this.alias = spec.relation.name;
|
|
497
|
+
specs.set(this, spec);
|
|
498
|
+
}
|
|
499
|
+
get expression() {
|
|
500
|
+
return render(specs.get(this), this.table, 1);
|
|
501
|
+
}
|
|
502
|
+
toOperationNode() {
|
|
503
|
+
const spec = specs.get(this);
|
|
504
|
+
const marked = {
|
|
505
|
+
...AliasNode.create(render(spec, this.table, 1).toOperationNode(), IdentifierNode.create(this.alias)),
|
|
506
|
+
[RELATED]: metaOf(spec)
|
|
507
|
+
};
|
|
508
|
+
return Object.freeze(marked);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
function specOf(schema, table, name, arg) {
|
|
512
|
+
const relation = relationOf(schema, table, name);
|
|
513
|
+
const where = `[durable-db] related('${table}', '${name}')`;
|
|
514
|
+
const options = Array.isArray(arg) ? { columns: arg } : arg;
|
|
515
|
+
if (typeof options !== "object" || options === null) throw new TypeError(`${where} takes the columns to read: ['id', …], or { columns, with, orderBy, limit }.`);
|
|
516
|
+
const known = getTableColumns(schema[relation.target]);
|
|
517
|
+
const column = (key, what) => {
|
|
518
|
+
if (typeof key !== "string" || !Object.hasOwn(known, key)) throw new TypeError(`${where}: ${what} "${String(key)}" is not a column of "${relation.target}". Its columns: ${Object.keys(known).join(", ")}.`);
|
|
519
|
+
return key;
|
|
520
|
+
};
|
|
521
|
+
if (options.columns !== void 0 && !Array.isArray(options.columns)) throw new TypeError(`${where}: columns is a list of column names.`);
|
|
522
|
+
const columns = [...new Set((options.columns ?? []).map((key) => column(key, "the column")))];
|
|
523
|
+
for (const key of columns) if (known[key].getSQLType() === "blob") throw new TypeError(`${where}: "${key}" is a blob, and a relation is read as JSON, which holds none — read it in a query of its own.`);
|
|
524
|
+
const nested = options.with ?? [];
|
|
525
|
+
if (!Array.isArray(nested)) throw new TypeError(`${where}: with is a list of relations: [related('${relation.target}', …)].`);
|
|
526
|
+
const names = new Set(columns);
|
|
527
|
+
const inner = [];
|
|
528
|
+
for (const item of nested) {
|
|
529
|
+
const spec = item instanceof RelatedExpression ? specs.get(item) : void 0;
|
|
530
|
+
if (!spec) throw new TypeError(`${where}: with is a list of relations: [related('${relation.target}', …)].`);
|
|
531
|
+
if (spec.schema !== schema || spec.relation.table !== relation.target) {
|
|
532
|
+
const other = spec.schema === schema ? "" : " of another database";
|
|
533
|
+
throw new TypeError(`${where}: with takes relations of "${relation.target}", and "${spec.relation.name}" is one of "${spec.relation.table}"${other}.`);
|
|
534
|
+
}
|
|
535
|
+
if (names.has(spec.relation.name)) throw new TypeError(`${where}: "${spec.relation.name}" is there twice — as a column and a relation, or the relation twice.`);
|
|
536
|
+
names.add(spec.relation.name);
|
|
537
|
+
inner.push(spec);
|
|
538
|
+
}
|
|
539
|
+
if (names.size === 0) throw new TypeError(`${where} reads nothing: name the columns to read.`);
|
|
540
|
+
const orderBy = [];
|
|
541
|
+
for (const [key, direction] of Object.entries(options.orderBy ?? {})) {
|
|
542
|
+
if (direction === void 0) continue;
|
|
543
|
+
if (direction !== "asc" && direction !== "desc") throw new TypeError(`${where}: orderBy.${key} is 'asc' or 'desc'.`);
|
|
544
|
+
orderBy.push([column(key, "orderBy"), direction]);
|
|
545
|
+
}
|
|
546
|
+
const { limit } = options;
|
|
547
|
+
if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) throw new TypeError(`${where}: limit is a whole number, 0 or more.`);
|
|
548
|
+
if (relation.kind === "one" && (orderBy.length > 0 || limit !== void 0)) throw new TypeError(`${where} leads to one row: orderBy and limit are for a relation that leads to many.`);
|
|
549
|
+
return {
|
|
550
|
+
schema,
|
|
551
|
+
relation,
|
|
552
|
+
columns,
|
|
553
|
+
with: inner,
|
|
554
|
+
orderBy,
|
|
555
|
+
limit
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
/** `related` for a schema: what `defineDatabase()` hands out. */
|
|
559
|
+
function createRelated(schema) {
|
|
560
|
+
const related = (table, relation, arg) => new RelatedExpression(specOf(schema, table, relation, arg));
|
|
561
|
+
return related;
|
|
562
|
+
}
|
|
563
|
+
function isMarked(node) {
|
|
564
|
+
return typeof node === "object" && node !== null && node[RELATED] !== void 0;
|
|
565
|
+
}
|
|
566
|
+
/** The relations among what a query selects (or returns): each by the key its rows carry it under. */
|
|
567
|
+
function relationsIn(node) {
|
|
568
|
+
const root = node;
|
|
569
|
+
let found;
|
|
570
|
+
for (const item of [...root.selections ?? [], ...root.returning?.selections ?? []]) {
|
|
571
|
+
const selected = item.selection;
|
|
572
|
+
if (!isMarked(selected)) continue;
|
|
573
|
+
found ??= /* @__PURE__ */ new Map();
|
|
574
|
+
found.set(selected.alias.name, selected[RELATED]);
|
|
575
|
+
}
|
|
576
|
+
return found;
|
|
577
|
+
}
|
|
578
|
+
function toBoolean(value) {
|
|
579
|
+
if (typeof value === "number") return value !== 0;
|
|
580
|
+
if (value === "true" || value === "1") return true;
|
|
581
|
+
if (value === "false" || value === "0") return false;
|
|
582
|
+
return value;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* The two plugins behind `related()`. `capture` goes first — it reads the
|
|
586
|
+
* query as the builder made it, marks and all — and `results` last, when the
|
|
587
|
+
* row's keys are the schema's again.
|
|
588
|
+
*/
|
|
589
|
+
function createRelatedPlugins(schema) {
|
|
590
|
+
const selected = /* @__PURE__ */ new WeakMap();
|
|
591
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
592
|
+
const kindsOf = (table) => {
|
|
593
|
+
let kind = kinds.get(table);
|
|
594
|
+
if (!kind) {
|
|
595
|
+
kind = {
|
|
596
|
+
dates: /* @__PURE__ */ new Set(),
|
|
597
|
+
booleans: /* @__PURE__ */ new Set()
|
|
598
|
+
};
|
|
599
|
+
const target = schema[table];
|
|
600
|
+
const columns = target ? getTableColumns(target) : {};
|
|
601
|
+
for (const [key, column] of Object.entries(columns)) if (column.dataType === "date") kind.dates.add(key);
|
|
602
|
+
else if (column.dataType === "boolean") kind.booleans.add(key);
|
|
603
|
+
kinds.set(table, kind);
|
|
604
|
+
}
|
|
605
|
+
return kind;
|
|
606
|
+
};
|
|
607
|
+
const revive = (value, meta) => {
|
|
608
|
+
if (Array.isArray(value)) return value.map((item) => revive(item, meta));
|
|
609
|
+
if (typeof value !== "object" || value === null) return value;
|
|
610
|
+
const { dates, booleans } = kindsOf(meta.target);
|
|
611
|
+
const row = value;
|
|
612
|
+
for (const [key, item] of Object.entries(row)) {
|
|
613
|
+
const nested = meta.with.get(key);
|
|
614
|
+
if (nested) row[key] = revive(item, nested);
|
|
615
|
+
else if (dates.has(key)) {
|
|
616
|
+
if (typeof item === "string" && dateSerializers.isSerializedDateString(item)) row[key] = dateSerializers.deserialize(item);
|
|
617
|
+
} else if (booleans.has(key)) row[key] = toBoolean(item);
|
|
618
|
+
}
|
|
619
|
+
return row;
|
|
620
|
+
};
|
|
621
|
+
return {
|
|
622
|
+
capture: {
|
|
623
|
+
transformQuery({ node, queryId }) {
|
|
624
|
+
const found = relationsIn(node);
|
|
625
|
+
if (found) selected.set(queryId, found);
|
|
626
|
+
return node;
|
|
627
|
+
},
|
|
628
|
+
async transformResult({ result }) {
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
results: {
|
|
633
|
+
transformQuery({ node }) {
|
|
634
|
+
return node;
|
|
635
|
+
},
|
|
636
|
+
async transformResult({ result, queryId }) {
|
|
637
|
+
const relations = selected.get(queryId);
|
|
638
|
+
if (!relations) return result;
|
|
639
|
+
const rows = result.rows.map((row) => {
|
|
640
|
+
const out = { ...row };
|
|
641
|
+
for (const [key, meta] of relations) {
|
|
642
|
+
const raw = out[key];
|
|
643
|
+
if (typeof raw === "string") out[key] = revive(JSON.parse(raw), meta);
|
|
644
|
+
}
|
|
645
|
+
return out;
|
|
646
|
+
});
|
|
647
|
+
return {
|
|
648
|
+
...result,
|
|
649
|
+
rows
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region src/db/defineDatabase.ts
|
|
657
|
+
/**
|
|
658
|
+
* Non-enumerable property the source `action()` stashes on the function it
|
|
659
|
+
* returns, carrying the original `{ args, handler }` config plus the compiled
|
|
660
|
+
* arktype validator. The production Vite transform replaces `action()`
|
|
661
|
+
* call-sites entirely, so this only ever exists in the UNTRANSFORMED world —
|
|
662
|
+
* i.e. tests. The `durable-db/testing` harness reads it to run a handler
|
|
663
|
+
* against a real in-memory database. See src/testing/index.ts.
|
|
664
|
+
*/
|
|
665
|
+
const ACTION_TEST_META = Symbol.for("durable-db.actionTestMeta");
|
|
666
|
+
/**
|
|
667
|
+
* Where the live test databases are listed, newest last. On `globalThis`, not
|
|
668
|
+
* module state: a test run can load `durable-db` (the app's actions) and
|
|
669
|
+
* `durable-db/testing` as separate module copies.
|
|
670
|
+
*/
|
|
671
|
+
const LIVE_TEST_DATABASES = Symbol.for("durable-db.liveTestDatabases");
|
|
672
|
+
/** The live test databases (created on first use). */
|
|
673
|
+
function liveTestDatabases() {
|
|
674
|
+
const store = globalThis;
|
|
675
|
+
return store[LIVE_TEST_DATABASES] ??= [];
|
|
676
|
+
}
|
|
677
|
+
/** The newest live test database holding every table of `schema`, if any. */
|
|
678
|
+
function testDatabaseFor(schema) {
|
|
679
|
+
const tables = Object.values(schema);
|
|
680
|
+
if (tables.length === 0) return void 0;
|
|
681
|
+
const live = globalThis[LIVE_TEST_DATABASES];
|
|
682
|
+
if (!live) return void 0;
|
|
683
|
+
for (let i = live.length - 1; i >= 0; i--) if (tables.every((table) => live[i].tables.has(table))) return live[i];
|
|
684
|
+
}
|
|
685
|
+
/** `createTestDatabase({ schema: { a, b } })` for this database, for messages. */
|
|
686
|
+
function testDatabaseHint(schema) {
|
|
687
|
+
const names = Object.keys(schema);
|
|
688
|
+
return `createTestDatabase({ schema: { ${names.length > 0 ? names.join(", ") : "…"} } })`;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Define a database with its schema and migrations.
|
|
692
|
+
*
|
|
693
|
+
* This function is transformed at build time by the durable-db Vite plugin.
|
|
694
|
+
* At runtime, the actions returned will be RPC stubs that call into the
|
|
695
|
+
* generated Durable Object.
|
|
696
|
+
*
|
|
697
|
+
* Outside the build — code under test calling an action directly — an action
|
|
698
|
+
* runs against the test database `createTestDatabase()` created for its
|
|
699
|
+
* database's tables (the newest one, when there are several); without one it
|
|
700
|
+
* throws.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* import { defineDatabase } from 'durable-db';
|
|
705
|
+
* import { users, posts } from './schema';
|
|
706
|
+
*
|
|
707
|
+
* export const { action } = defineDatabase({
|
|
708
|
+
* schema: { users, posts },
|
|
709
|
+
* });
|
|
710
|
+
*
|
|
711
|
+
* export const createUser = action({
|
|
712
|
+
* args: { name: 'string', email: 'string.email' },
|
|
713
|
+
* handler: async (db, args) => {
|
|
714
|
+
* return db.insertInto('users').values({
|
|
715
|
+
* id: crypto.randomUUID(),
|
|
716
|
+
* name: args.name,
|
|
717
|
+
* email: args.email
|
|
718
|
+
* }).returningAll().executeTakeFirst();
|
|
719
|
+
* },
|
|
720
|
+
* });
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
function defineDatabase(config) {
|
|
724
|
+
const schema = config?.schema ?? {};
|
|
725
|
+
const action = (actionConfig) => {
|
|
726
|
+
const validator = actionArgsType(actionConfig.args);
|
|
727
|
+
const argsDefinition = actionConfig.args;
|
|
728
|
+
const argKeys = argsDefinition !== null && typeof argsDefinition === "object" ? Object.keys(argsDefinition) : null;
|
|
729
|
+
const argsHint = argKeys ? ` (args: ${argKeys.length > 0 ? `{ ${argKeys.join(", ")} }` : "{}"})` : "";
|
|
730
|
+
const actionFn = async (args) => {
|
|
731
|
+
const testDatabase = testDatabaseFor(schema);
|
|
732
|
+
if (testDatabase) return await testDatabase.run(actionFn, args);
|
|
733
|
+
const result = validator(args);
|
|
734
|
+
if (result instanceof type.errors) throw new Error(`Invalid args for action${argsHint}: ${result.summary}`);
|
|
735
|
+
throw new Error(`Action${argsHint} called without transformation: action() call sites are transformed by the build; in tests, create the database with ${testDatabaseHint(schema)} and call the action, or use db.run(action, args).`);
|
|
736
|
+
};
|
|
737
|
+
Object.defineProperty(actionFn, ACTION_TEST_META, {
|
|
738
|
+
value: {
|
|
739
|
+
args: actionConfig.args,
|
|
740
|
+
handler: actionConfig.handler,
|
|
741
|
+
validator,
|
|
742
|
+
schema
|
|
743
|
+
},
|
|
744
|
+
enumerable: false,
|
|
745
|
+
configurable: true
|
|
746
|
+
});
|
|
747
|
+
return actionFn;
|
|
748
|
+
};
|
|
749
|
+
const destroyDatabase = async () => {
|
|
750
|
+
const testDatabase = testDatabaseFor(schema);
|
|
751
|
+
if (testDatabase) {
|
|
752
|
+
testDatabase.clear();
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
throw new Error(`destroyDatabase() called without transformation: it is transformed by the build; in tests, create the database with ${testDatabaseHint(schema)} first.`);
|
|
756
|
+
};
|
|
757
|
+
return {
|
|
758
|
+
action,
|
|
759
|
+
destroyDatabase,
|
|
760
|
+
related: createRelated(schema),
|
|
761
|
+
get relations() {
|
|
762
|
+
return relationsOf(schema);
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
//#endregion
|
|
767
|
+
export { createRelatedPlugins as a, SchemaPlugin as c, relationOf as d, relationsOf as f, RelatedExpression as i, createDrizzlePlugins as l, defineDatabase as n, DateSerializePlugin as o, liveTestDatabases as r, DrizzleDefaultsPlugin as s, ACTION_TEST_META as t, dateSerializers as u };
|