qubu 0.3.4 → 0.4.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/dist/codegen.d.mts +1 -1
- package/dist/codegen.mjs +1 -1
- package/dist/column-D-8OqGuV.mjs +328 -0
- package/dist/{table-llv9tsZ8.mjs → column-LV7oGQde.mjs} +9 -97
- package/dist/{complete-types-BdFqUfbb.d.mts → complete-types-BavBtv8J.d.mts} +1 -1
- package/dist/core.d.mts +1 -1
- package/dist/core.mjs +3 -3
- package/dist/ddl.d.mts +1 -1
- package/dist/ddl.mjs +3 -3
- package/dist/diff.d.mts +1 -1
- package/dist/drizzle-mysql.d.mts +2 -2
- package/dist/drizzle-mysql.mjs +2 -2
- package/dist/drizzle-postgres.d.mts +2 -2
- package/dist/drizzle-postgres.mjs +2 -2
- package/dist/drizzle-sqlite.d.mts +36 -3
- package/dist/drizzle-sqlite.mjs +30 -4
- package/dist/drizzle.d.mts +1 -1
- package/dist/{index-Dug5HnLB.d.mts → index-D3ZOwPT-.d.mts} +2 -2
- package/dist/{index-Ds7-mhJi.d.mts → index-DH0qV6aS.d.mts} +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +64 -34
- package/dist/introspection.d.mts +2 -2
- package/dist/introspection.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/{mysql-DqkqXB6A.mjs → mysql-CKEKGnj4.mjs} +3 -3
- package/dist/mysql.d.mts +1 -1
- package/dist/{on-conflict-BxnxubMb.mjs → on-conflict-4MOBl51J.mjs} +4 -3
- package/dist/{postgres-DEBBeh52.mjs → postgres-BK2APkKP.mjs} +3 -2
- package/dist/postgres.d.mts +1 -1
- package/dist/postgres.mjs +3 -3
- package/dist/{registry-BufIskVN.mjs → registry-CXV8u7Pt.mjs} +3 -108
- package/dist/{relational-DCZrrNia.mjs → relational-DuQ9IHSb.mjs} +4 -4
- package/dist/{runtime-BTr-MTlo.mjs → runtime-Cn_Xgzta.mjs} +1 -1
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +6 -4
- package/dist/{serialize-PF1cfH2P.mjs → serialize-CFtYYAdk.mjs} +2 -2
- package/dist/{snapshot-CWPgzxNx.mjs → snapshot-DJpfmxhQ.mjs} +1 -1
- package/dist/snapshot.d.mts +3 -3
- package/dist/snapshot.mjs +4 -4
- package/dist/{source-DUoJVXmL.mjs → source-DGO3DRgg.mjs} +3 -3
- package/dist/{sqlite-BU6DBxef.mjs → sqlite-CrsK0Fza.mjs} +3 -3
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +1 -1
- package/dist/table-D6rcs8SB.mjs +96 -0
- package/dist/{types-BX0mckiU.d.mts → types-CSNJTYaM.d.mts} +1 -1
- package/dist/{types-H4vyCw8_.d.mts → types-DZsueVoI.d.mts} +1 -1
- package/dist/{types-4Q076HKo.d.mts → types-Deo_q43Y.d.mts} +1442 -916
- package/dist/{types-Cec0xzo4.mjs → types-g-vVvj1B.mjs} +4 -3
- package/dist/{value-BvilP0oz.mjs → value-b6OFZXVS.mjs} +1 -1
- package/dist/vite/ambient.d.ts +13 -61
- package/docs/dialects-and-execution.md +84 -34
- package/docs/guides/drizzle.md +27 -0
- package/docs/reference/supported-surface.md +7 -7
- package/package.json +1 -1
- package/dist/column-CXMxx8Hq.mjs +0 -118
- package/dist/naming-QVCOnSj2.mjs +0 -20
package/dist/codegen.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { St as IntrospectionDiagnostic, dt as IntrospectionResult, i as CatalogClassificationConfidence, p as CatalogDialect, z as CatalogPortableStorageType } from "./types-
|
|
1
|
+
import { St as IntrospectionDiagnostic, dt as IntrospectionResult, i as CatalogClassificationConfidence, p as CatalogDialect, z as CatalogPortableStorageType } from "./types-CSNJTYaM.mjs";
|
|
2
2
|
//#region src/codegen/types.d.ts
|
|
3
3
|
/** TypeScript value types that the controlled source printer can emit. */
|
|
4
4
|
type CodegenApplicationType = 'unknown' | 'string' | 'number' | 'boolean' | 'bigint' | 'Date' | 'Uint8Array';
|
package/dist/codegen.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as decodeSchemaSnapshot } from "./canonical-BbnqavJm.mjs";
|
|
2
|
-
import { t as mapCatalogToSnapshot } from "./snapshot-
|
|
2
|
+
import { t as mapCatalogToSnapshot } from "./snapshot-DJpfmxhQ.mjs";
|
|
3
3
|
//#region src/codegen/source.ts
|
|
4
4
|
const header = `/* Generated by Qubu. Do not edit this machine-owned file. */
|
|
5
5
|
import * as _qubu from 'qubu'
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { a as assertDialectCapability } from "./json-CUZlv4HT.mjs";
|
|
2
|
+
//#region src/result.ts
|
|
3
|
+
const resultValueMetadata = Symbol("qubu.result-value-metadata");
|
|
4
|
+
function resultValue(type, decoder) {
|
|
5
|
+
return type === void 0 && decoder === void 0 ? void 0 : Object.freeze({
|
|
6
|
+
...type === void 0 ? {} : { type },
|
|
7
|
+
...decoder === void 0 ? {} : { decoder }
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function resultValueOf(value) {
|
|
11
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
12
|
+
return value[resultValueMetadata];
|
|
13
|
+
}
|
|
14
|
+
function attachResultValue(value, metadata) {
|
|
15
|
+
if (metadata === void 0) return value;
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
...value,
|
|
18
|
+
[resultValueMetadata]: metadata
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function createResultShape(fields) {
|
|
22
|
+
return Object.freeze({ fields: Object.freeze(fields.map((field) => Object.freeze({ ...field }))) });
|
|
23
|
+
}
|
|
24
|
+
function resultShapeValue(shape, name) {
|
|
25
|
+
const field = shape.fields.find((candidate) => candidate.name === name);
|
|
26
|
+
return field === void 0 ? void 0 : resultValue(field.type, field.decoder);
|
|
27
|
+
}
|
|
28
|
+
/** Decode SQLite/MySQL-style boolean values while accepting native booleans. */
|
|
29
|
+
const booleanResultDecoder = (value) => {
|
|
30
|
+
if (typeof value === "boolean") return value;
|
|
31
|
+
if (value === 0 || value === 0n) return false;
|
|
32
|
+
if (value === 1 || value === 1n) return true;
|
|
33
|
+
throw new TypeError("Expected a boolean or numeric 0/1 result");
|
|
34
|
+
};
|
|
35
|
+
/** Decode a SQL DATE string as a JavaScript Date at UTC midnight. */
|
|
36
|
+
const dateResultDecoder = (value) => {
|
|
37
|
+
if (value instanceof Date && !Number.isNaN(value.getTime())) return value;
|
|
38
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/u.test(value)) throw new TypeError("Expected a valid Date or YYYY-MM-DD result");
|
|
39
|
+
const decoded = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
|
|
40
|
+
if (Number.isNaN(decoded.getTime()) || decoded.toISOString().slice(0, 10) !== value) throw new TypeError("Expected a valid calendar date result");
|
|
41
|
+
return decoded;
|
|
42
|
+
};
|
|
43
|
+
/** Decode a SQL/ISO timestamp string while accepting driver-created Dates. */
|
|
44
|
+
const timestampResultDecoder = (value) => {
|
|
45
|
+
if (value instanceof Date && !Number.isNaN(value.getTime())) return value;
|
|
46
|
+
if (typeof value !== "string") throw new TypeError("Expected a valid Date or timestamp string result");
|
|
47
|
+
const normalized = value.includes("T") ? value : value.replace(" ", "T");
|
|
48
|
+
const decoded = new Date(/(?:Z|[+-]\d{2}:?\d{2})$/u.test(normalized) ? normalized : `${normalized}Z`);
|
|
49
|
+
if (Number.isNaN(decoded.getTime())) throw new TypeError("Expected a valid timestamp result");
|
|
50
|
+
return decoded;
|
|
51
|
+
};
|
|
52
|
+
/** Decode a serialized JSON result. Use only when the adapter returns JSON text. */
|
|
53
|
+
const jsonTextResultDecoder = (value) => {
|
|
54
|
+
if (typeof value !== "string") return value;
|
|
55
|
+
return JSON.parse(value);
|
|
56
|
+
};
|
|
57
|
+
/** Error raised when a projected driver value cannot be decoded. */
|
|
58
|
+
var ResultDecodingError = class extends TypeError {
|
|
59
|
+
name = "ResultDecodingError";
|
|
60
|
+
field;
|
|
61
|
+
rowIndex;
|
|
62
|
+
resultType;
|
|
63
|
+
constructor(field, rowIndex, resultType) {
|
|
64
|
+
super(`Could not decode result field "${field}" in row ${rowIndex}${resultType === void 0 ? "" : ` as ${resultType}`}`);
|
|
65
|
+
this.field = field;
|
|
66
|
+
this.rowIndex = rowIndex;
|
|
67
|
+
this.resultType = resultType;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function decodeResultRow(row, shape, decoders, dialect, rowIndex) {
|
|
71
|
+
let decoded;
|
|
72
|
+
for (const field of shape.fields) {
|
|
73
|
+
const decoder = field.decoder ?? (field.type ? decoders?.[field.type] : void 0);
|
|
74
|
+
if (decoder === void 0 || row[field.name] === null) continue;
|
|
75
|
+
try {
|
|
76
|
+
decoded ??= { ...row };
|
|
77
|
+
decoded[field.name] = decoder(row[field.name], {
|
|
78
|
+
dialect,
|
|
79
|
+
field: field.name,
|
|
80
|
+
rowIndex
|
|
81
|
+
});
|
|
82
|
+
} catch {
|
|
83
|
+
throw new ResultDecodingError(field.name, rowIndex, field.type);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return decoded ?? row;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/core/fragment.ts
|
|
90
|
+
function fragment(render) {
|
|
91
|
+
return Object.freeze({ render });
|
|
92
|
+
}
|
|
93
|
+
function sequence(parts, separator = " ") {
|
|
94
|
+
return fragment((context) => {
|
|
95
|
+
let first = true;
|
|
96
|
+
for (const part of parts) {
|
|
97
|
+
if (!first) context.append(separator);
|
|
98
|
+
context.render(part);
|
|
99
|
+
first = false;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function parenthesize(part) {
|
|
104
|
+
return fragment((context) => {
|
|
105
|
+
context.append("(");
|
|
106
|
+
context.render(part);
|
|
107
|
+
context.append(")");
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function isFragment(value) {
|
|
111
|
+
return typeof value === "object" && value !== null && "render" in value && typeof value.render === "function";
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/expressions/types.ts
|
|
115
|
+
/** Runtime/type-level proof that an expression is safe to use in schema SQL. */
|
|
116
|
+
const schemaExpressionBrand = Symbol("qubu.schema-expression");
|
|
117
|
+
/** Add a concrete dialect requirement without dropping expression metadata. */
|
|
118
|
+
function withDialectCapability(expression, capability) {
|
|
119
|
+
const wrapped = makeExpression(expression.expressionKind, (context) => {
|
|
120
|
+
assertDialectCapability(context.dialect, capability);
|
|
121
|
+
context.render(expression);
|
|
122
|
+
}, expression.expressionCategory, resultValueOf(expression));
|
|
123
|
+
return isSchemaExpression(expression) ? markSchemaExpression(wrapped) : wrapped;
|
|
124
|
+
}
|
|
125
|
+
function makeExpression(expressionKind, render, expressionCategory, result) {
|
|
126
|
+
return attachResultValue(Object.freeze({
|
|
127
|
+
expressionKind,
|
|
128
|
+
...expressionCategory ? { expressionCategory } : {},
|
|
129
|
+
...fragment(render)
|
|
130
|
+
}), result);
|
|
131
|
+
}
|
|
132
|
+
/** Mark a query-only expression category without changing its SQL renderer. */
|
|
133
|
+
function markExpressionCategory(expression, category) {
|
|
134
|
+
return Object.freeze({
|
|
135
|
+
...expression,
|
|
136
|
+
expressionCategory: category
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Mark a built-in or explicitly audited renderer as schema-deterministic.
|
|
141
|
+
* Prefer {@link defineSchemaExpression} for application extensions because it
|
|
142
|
+
* supplies a restricted schema rendering context.
|
|
143
|
+
*/
|
|
144
|
+
function makeSchemaExpression(expressionKind, render, result) {
|
|
145
|
+
const expression = makeExpression(expressionKind, render, void 0, result);
|
|
146
|
+
return Object.freeze({
|
|
147
|
+
...expression,
|
|
148
|
+
[schemaExpressionBrand]: true
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/** Add the schema-determinism brand to an explicitly audited expression. */
|
|
152
|
+
function markSchemaExpression(expression) {
|
|
153
|
+
if (isSchemaExpression(expression)) return expression;
|
|
154
|
+
return Object.freeze({
|
|
155
|
+
...expression,
|
|
156
|
+
[schemaExpressionBrand]: true
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Test the runtime brand used by schema rendering and validation. */
|
|
160
|
+
function isSchemaExpression(value) {
|
|
161
|
+
return typeof value === "object" && value !== null && schemaExpressionBrand in value && value[schemaExpressionBrand] === true;
|
|
162
|
+
}
|
|
163
|
+
function isExpression(value) {
|
|
164
|
+
return typeof value === "object" && value !== null && "expressionKind" in value && "render" in value && typeof value.render === "function";
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/core/naming.ts
|
|
168
|
+
/** Convert an application-facing field name to a SQL-facing identifier. */
|
|
169
|
+
function snakeCaseIdentifier(name) {
|
|
170
|
+
return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
|
|
171
|
+
}
|
|
172
|
+
function resolveSqlNames(fields) {
|
|
173
|
+
const sqlNames = {};
|
|
174
|
+
const fieldsBySqlName = /* @__PURE__ */ new Map();
|
|
175
|
+
for (const field of fields) {
|
|
176
|
+
const sqlName = field.sqlName ?? snakeCaseIdentifier(field.fieldName);
|
|
177
|
+
if (sqlName.length === 0) throw new Error(`SQL name for field "${field.fieldName}" cannot be empty`);
|
|
178
|
+
const existingField = fieldsBySqlName.get(sqlName);
|
|
179
|
+
if (existingField) throw new Error(`Fields "${existingField}" and "${field.fieldName}" both resolve to SQL name "${sqlName}"`);
|
|
180
|
+
fieldsBySqlName.set(sqlName, field.fieldName);
|
|
181
|
+
sqlNames[field.fieldName] = sqlName;
|
|
182
|
+
}
|
|
183
|
+
return Object.freeze(sqlNames);
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/schema/metadata.ts
|
|
187
|
+
/** Error raised when relational metadata cannot be represented safely. */
|
|
188
|
+
var SchemaMetadataValidationError = class extends TypeError {
|
|
189
|
+
name = "SchemaMetadataValidationError";
|
|
190
|
+
diagnostics;
|
|
191
|
+
issues;
|
|
192
|
+
constructor(diagnostics) {
|
|
193
|
+
const frozenDiagnostics = Object.freeze(diagnostics.map((diagnostic) => Object.freeze({
|
|
194
|
+
...diagnostic,
|
|
195
|
+
path: Object.freeze([...diagnostic.path]),
|
|
196
|
+
relatedPaths: diagnostic.relatedPaths ? Object.freeze(diagnostic.relatedPaths.map((path) => Object.freeze([...path]))) : void 0
|
|
197
|
+
})));
|
|
198
|
+
super(frozenDiagnostics.map((diagnostic) => diagnostic.message).join("\n"));
|
|
199
|
+
this.diagnostics = frozenDiagnostics;
|
|
200
|
+
this.issues = frozenDiagnostics;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/** Generate the version-one physical name for a relational object ID. */
|
|
204
|
+
function generatedSchemaObjectName(id) {
|
|
205
|
+
return snakeCaseIdentifier(id);
|
|
206
|
+
}
|
|
207
|
+
/** Deep-freeze plain metadata values without introducing executable nodes. */
|
|
208
|
+
function freezeSchemaMetadata(value) {
|
|
209
|
+
if (Array.isArray(value)) return Object.freeze(value.map((item) => freezeSchemaMetadata(item)));
|
|
210
|
+
if (typeof value !== "object" || value === null) return value;
|
|
211
|
+
const frozen = Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, freezeSchemaMetadata(nested)]));
|
|
212
|
+
return Object.freeze(frozen);
|
|
213
|
+
}
|
|
214
|
+
/** Check the portable identifier subset used for generated metadata names. */
|
|
215
|
+
function isValidSchemaObjectName(name) {
|
|
216
|
+
return name.length > 0 && name === name.trim() && !/[.\\/\u0000-\u001f\u007f"']/u.test(name);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Attach a record key and resolved physical name without changing the
|
|
220
|
+
* enumerable shape of legacy constraint/index values. The properties are
|
|
221
|
+
* still ordinary read-only runtime metadata and are available to snapshot
|
|
222
|
+
* traversals.
|
|
223
|
+
*/
|
|
224
|
+
function materializeSchemaObjectIdentity(value, id, physicalName) {
|
|
225
|
+
const materialized = { ...value };
|
|
226
|
+
Object.defineProperties(materialized, {
|
|
227
|
+
id: {
|
|
228
|
+
configurable: false,
|
|
229
|
+
enumerable: false,
|
|
230
|
+
value: id,
|
|
231
|
+
writable: false
|
|
232
|
+
},
|
|
233
|
+
physicalName: {
|
|
234
|
+
configurable: false,
|
|
235
|
+
enumerable: false,
|
|
236
|
+
value: physicalName ?? generatedSchemaObjectName(id),
|
|
237
|
+
writable: false
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return Object.freeze(materialized);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolve and validate names for one metadata record. The caller decides
|
|
244
|
+
* whether constraint and index names share a database namespace.
|
|
245
|
+
*/
|
|
246
|
+
function materializeSchemaObjectRecord(record, kind) {
|
|
247
|
+
const diagnostics = [];
|
|
248
|
+
const names = /* @__PURE__ */ new Map();
|
|
249
|
+
const result = {};
|
|
250
|
+
for (const [id, value] of Object.entries(record)) {
|
|
251
|
+
const physicalName = value.physicalName ?? generatedSchemaObjectName(id);
|
|
252
|
+
const path = [kind === "constraint" ? "constraints" : "indexes", id];
|
|
253
|
+
if (!isValidSchemaObjectName(physicalName)) diagnostics.push({
|
|
254
|
+
code: "invalid-physical-name",
|
|
255
|
+
message: `The ${kind} "${id}" has invalid physical name "${physicalName}"`,
|
|
256
|
+
path: [...path, "physicalName"]
|
|
257
|
+
});
|
|
258
|
+
const previousId = names.get(physicalName);
|
|
259
|
+
if (previousId !== void 0) diagnostics.push({
|
|
260
|
+
code: "duplicate-physical-name",
|
|
261
|
+
message: `The ${kind}s "${previousId}" and "${id}" both use physical name "${physicalName}"`,
|
|
262
|
+
path: [...path, "physicalName"],
|
|
263
|
+
relatedPaths: [[
|
|
264
|
+
kind === "constraint" ? "constraints" : "indexes",
|
|
265
|
+
previousId,
|
|
266
|
+
"physicalName"
|
|
267
|
+
]]
|
|
268
|
+
});
|
|
269
|
+
else names.set(physicalName, id);
|
|
270
|
+
result[id] = materializeSchemaObjectIdentity(value, id, physicalName);
|
|
271
|
+
}
|
|
272
|
+
if (diagnostics.length > 0) throw new SchemaMetadataValidationError(diagnostics);
|
|
273
|
+
return Object.freeze(result);
|
|
274
|
+
}
|
|
275
|
+
/** Return a diagnostic when a dialect extension is used by another adapter. */
|
|
276
|
+
function dialectMismatchDiagnostic(extension, dialect, path) {
|
|
277
|
+
if (extension.dialect === dialect) return void 0;
|
|
278
|
+
return {
|
|
279
|
+
code: "dialect-mismatch",
|
|
280
|
+
message: `Dialect extension belongs to "${extension.dialect}" but the active schema dialect is "${dialect}"`,
|
|
281
|
+
path,
|
|
282
|
+
dialect
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/** Throw a structured error for one or more dialect capability findings. */
|
|
286
|
+
function assertSchemaDialectSupport(diagnostics) {
|
|
287
|
+
if (diagnostics.length > 0) throw new SchemaMetadataValidationError(diagnostics);
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/core/primitives/identifier.ts
|
|
291
|
+
function identifier(name) {
|
|
292
|
+
return fragment((context) => context.append(context.dialect.quoteIdentifier(name)));
|
|
293
|
+
}
|
|
294
|
+
function qualifiedIdentifier(...parts) {
|
|
295
|
+
return fragment((context) => {
|
|
296
|
+
parts.forEach((part, index) => {
|
|
297
|
+
if (index > 0) context.append(".");
|
|
298
|
+
context.append(context.dialect.quoteIdentifier(part));
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/expressions/column.ts
|
|
304
|
+
function createColumnReference(columnName, sourceReference, fieldName, result) {
|
|
305
|
+
const expression = makeSchemaExpression("column", (context) => {
|
|
306
|
+
if (context.renderColumnReference) {
|
|
307
|
+
context.renderColumnReference(columnName);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
context.render(sourceReference);
|
|
311
|
+
context.append(".");
|
|
312
|
+
context.render(identifier(columnName));
|
|
313
|
+
}, result);
|
|
314
|
+
return Object.freeze({
|
|
315
|
+
...expression,
|
|
316
|
+
fieldName,
|
|
317
|
+
columnName
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function isColumnReference(value) {
|
|
321
|
+
return typeof value === "object" && value !== null && "expressionKind" in value && value.expressionKind === "column";
|
|
322
|
+
}
|
|
323
|
+
/** Turn an expression into a fragment that renders it without changing it. */
|
|
324
|
+
function expressionFragment(expression) {
|
|
325
|
+
return fragment((context) => context.render(expression));
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
export { dateResultDecoder as A, fragment as C, ResultDecodingError as D, sequence as E, resultValueOf as F, timestampResultDecoder as I, jsonTextResultDecoder as M, resultShapeValue as N, booleanResultDecoder as O, resultValue as P, withDialectCapability as S, parenthesize as T, isSchemaExpression as _, qualifiedIdentifier as a, markExpressionCategory as b, dialectMismatchDiagnostic as c, isValidSchemaObjectName as d, materializeSchemaObjectIdentity as f, isExpression as g, snakeCaseIdentifier as h, identifier as i, decodeResultRow as j, createResultShape as k, freezeSchemaMetadata as l, resolveSqlNames as m, expressionFragment as n, SchemaMetadataValidationError as o, materializeSchemaObjectRecord as p, isColumnReference as r, assertSchemaDialectSupport as s, createColumnReference as t, generatedSchemaObjectName as u, makeExpression as v, isFragment as w, markSchemaExpression as x, makeSchemaExpression as y };
|
|
@@ -1,55 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as resolveSqlNames } from "./naming-QVCOnSj2.mjs";
|
|
3
|
-
import { r as exposeColumns, t as createSource } from "./source-DUoJVXmL.mjs";
|
|
4
|
-
import { M as materializeSchemaObjectRecord, O as freezeSchemaMetadata } from "./registry-BufIskVN.mjs";
|
|
5
|
-
//#region src/schema/alias.ts
|
|
6
|
-
function alias(sourceOrQuery, name) {
|
|
7
|
-
const input = sourceOrQuery;
|
|
8
|
-
const reference = identifier(name);
|
|
9
|
-
const isQuery = "queryKind" in input;
|
|
10
|
-
const source = createSource(isQuery ? "query-alias" : "table-alias", (context) => {
|
|
11
|
-
if (isQuery) context.renderRelation(parenthesize(input));
|
|
12
|
-
else context.render(input);
|
|
13
|
-
context.append(" AS ");
|
|
14
|
-
context.render(reference);
|
|
15
|
-
}, reference);
|
|
16
|
-
const fieldNames = isQuery ? Object.keys(input.row) : Object.keys(input.columns);
|
|
17
|
-
const querySqlNames = isQuery ? resolveSqlNames(fieldNames.map((fieldName) => ({ fieldName }))) : void 0;
|
|
18
|
-
const columns = Object.fromEntries(fieldNames.map((fieldName) => {
|
|
19
|
-
const columnName = isQuery ? querySqlNames[fieldName] : input.columns[fieldName].columnName;
|
|
20
|
-
return [fieldName, createColumnReference(columnName, reference, fieldName)];
|
|
21
|
-
}));
|
|
22
|
-
Object.assign(source, {
|
|
23
|
-
alias: name,
|
|
24
|
-
base: isQuery ? void 0 : input,
|
|
25
|
-
query: isQuery ? input : void 0,
|
|
26
|
-
constraints: isQuery ? {} : input.constraints,
|
|
27
|
-
indexes: isQuery ? {} : "indexes" in input ? input.indexes : {},
|
|
28
|
-
columns
|
|
29
|
-
});
|
|
30
|
-
exposeColumns(source, columns);
|
|
31
|
-
return source;
|
|
32
|
-
}
|
|
33
|
-
/** Render a query as a LATERAL source whose outer requirements stay visible. */
|
|
34
|
-
function lateral(query, name) {
|
|
35
|
-
const reference = identifier(name);
|
|
36
|
-
const source = createSource("lateral", (context) => {
|
|
37
|
-
context.append("LATERAL ");
|
|
38
|
-
context.renderRelation(parenthesize(query));
|
|
39
|
-
context.append(" AS ");
|
|
40
|
-
context.render(reference);
|
|
41
|
-
}, reference);
|
|
42
|
-
const sqlNames = resolveSqlNames(Object.keys(query.row).map((fieldName) => ({ fieldName })));
|
|
43
|
-
const columns = Object.fromEntries(Object.keys(query.row).map((fieldName) => [fieldName, createColumnReference(sqlNames[fieldName], reference, fieldName)]));
|
|
44
|
-
Object.assign(source, {
|
|
45
|
-
alias: name,
|
|
46
|
-
query,
|
|
47
|
-
columns
|
|
48
|
-
});
|
|
49
|
-
exposeColumns(source, columns);
|
|
50
|
-
return source;
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
1
|
+
import { P as resultValue, _ as isSchemaExpression, l as freezeSchemaMetadata } from "./column-D-8OqGuV.mjs";
|
|
53
2
|
//#region src/schema/column-behavior.ts
|
|
54
3
|
/** A column behavior error with a stable code and optional property path. */
|
|
55
4
|
var ColumnBehaviorError = class extends TypeError {
|
|
@@ -286,6 +235,7 @@ function column(options) {
|
|
|
286
235
|
...resolveColumnBehavior(options ?? {}),
|
|
287
236
|
sqlName: options?.sqlName,
|
|
288
237
|
storage: options?.storage ? Object.freeze({ ...options.storage }) : void 0,
|
|
238
|
+
...options?.decode === void 0 ? {} : { resultDecoder: options.decode },
|
|
289
239
|
$type: narrowColumnType,
|
|
290
240
|
castTarget: options?.castType ? Object.freeze({
|
|
291
241
|
kind: "named-cast",
|
|
@@ -293,6 +243,12 @@ function column(options) {
|
|
|
293
243
|
}) : void 0
|
|
294
244
|
});
|
|
295
245
|
}
|
|
246
|
+
/** Resolve the runtime result metadata carried by a column definition. */
|
|
247
|
+
function columnResultValue(definition) {
|
|
248
|
+
const storage = definition.storage;
|
|
249
|
+
const type = storage?.kind === "portable" && (storage.type === "boolean" || storage.type === "date" || storage.type === "timestamp" || storage.type === "json") ? storage.type : void 0;
|
|
250
|
+
return resultValue(type, definition.resultDecoder);
|
|
251
|
+
}
|
|
296
252
|
function nativeColumn(storageOrDialect, typeOrOptions, maybeOptions) {
|
|
297
253
|
const storage = typeof storageOrDialect === "string" ? nativeStorage(storageOrDialect, typeOrOptions) : storageOrDialect;
|
|
298
254
|
return column({
|
|
@@ -337,48 +293,4 @@ function binary(options) {
|
|
|
337
293
|
return withPortableStorage(withPortableCast(column(options), "binary"), "binary");
|
|
338
294
|
}
|
|
339
295
|
//#endregion
|
|
340
|
-
|
|
341
|
-
function table(name, definitions, metadata) {
|
|
342
|
-
const source = createSource("table", (context) => context.render(identifier(name)), identifier(name));
|
|
343
|
-
const sqlNames = resolveSqlNames(Object.entries(definitions).map(([fieldName, definition]) => ({
|
|
344
|
-
fieldName,
|
|
345
|
-
sqlName: definition.sqlName
|
|
346
|
-
})));
|
|
347
|
-
const columns = Object.fromEntries(Object.keys(definitions).map((fieldName) => {
|
|
348
|
-
const sqlName = sqlNames[fieldName];
|
|
349
|
-
return [fieldName, createColumnReference(sqlName, source.reference, fieldName)];
|
|
350
|
-
}));
|
|
351
|
-
Object.assign(source, {
|
|
352
|
-
tableName: name,
|
|
353
|
-
definitions,
|
|
354
|
-
sqlNames,
|
|
355
|
-
columns,
|
|
356
|
-
constraints: {},
|
|
357
|
-
indexes: {}
|
|
358
|
-
});
|
|
359
|
-
exposeColumns(source, columns);
|
|
360
|
-
const resolvedMetadata = metadata ? metadata(source) : {
|
|
361
|
-
constraints: {},
|
|
362
|
-
indexes: {}
|
|
363
|
-
};
|
|
364
|
-
const constraints = materializeSchemaObjectRecord(resolvedMetadata.constraints, "constraint");
|
|
365
|
-
const indexes = Object.fromEntries(Object.entries(resolvedMetadata.indexes).map(([indexName, tableIndex]) => {
|
|
366
|
-
const candidateKey = tableIndex.unique && tableIndex.predicate === void 0 && tableIndex.terms.every((term) => {
|
|
367
|
-
const expression = "orderKind" in term ? term.expression : term;
|
|
368
|
-
return expression.expressionKind === "column" && definitions[expression.fieldName]?.nullable === false;
|
|
369
|
-
});
|
|
370
|
-
return [indexName, Object.freeze({
|
|
371
|
-
...tableIndex,
|
|
372
|
-
candidateKey
|
|
373
|
-
})];
|
|
374
|
-
}));
|
|
375
|
-
const namedIndexes = materializeSchemaObjectRecord(indexes, "index");
|
|
376
|
-
Object.assign(source, {
|
|
377
|
-
...resolvedMetadata,
|
|
378
|
-
constraints,
|
|
379
|
-
indexes: namedIndexes
|
|
380
|
-
});
|
|
381
|
-
return source;
|
|
382
|
-
}
|
|
383
|
-
//#endregion
|
|
384
|
-
export { resolveColumnBehavior as C, identityColumn as S, lateral as T, ColumnBehaviorError as _, column as a, externalGeneratedColumn as b, json as c, nullable as d, numeric as f, uuid as g, timestamp as h, boolean as i, nativeColumn as l, text as m, bigint as n, date as o, portableStorage as p, binary as r, integer as s, table as t, nativeStorage as u, canonicalLiteral as v, alias as w, generatedColumn as x, externalDefault as y };
|
|
296
|
+
export { resolveColumnBehavior as C, identityColumn as S, ColumnBehaviorError as _, columnResultValue as a, externalGeneratedColumn as b, json as c, nullable as d, numeric as f, uuid as g, timestamp as h, column as i, nativeColumn as l, text as m, binary as n, date as o, portableStorage as p, boolean as r, integer as s, bigint as t, nativeStorage as u, canonicalLiteral as v, generatedColumn as x, externalDefault as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SnapshotStorage, D as SnapshotLiteral, O as SnapshotNamingPolicy, T as SnapshotJsonValue, b as SnapshotGeneratedColumn, d as SnapshotDefault, f as SnapshotDiagnostic, g as SnapshotExpression, h as SnapshotDialectExtension, i as SchemaSnapshotInput, m as SnapshotDialect } from "./types-
|
|
1
|
+
import { A as SnapshotStorage, D as SnapshotLiteral, O as SnapshotNamingPolicy, T as SnapshotJsonValue, b as SnapshotGeneratedColumn, d as SnapshotDefault, f as SnapshotDiagnostic, g as SnapshotExpression, h as SnapshotDialectExtension, i as SchemaSnapshotInput, m as SnapshotDialect } from "./types-Deo_q43Y.mjs";
|
|
2
2
|
//#region src/snapshot/complete-types.d.ts
|
|
3
3
|
/** The stable envelope tag shared by Snapshot v1 and the complete model. */
|
|
4
4
|
declare const completeSchemaSnapshotFormat: "qubu-schema";
|
package/dist/core.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as PaginationKind, $l as
|
|
1
|
+
import { $ as PaginationKind, $l as InheritedMetadata, Au as SqlBoolean, B as CastTarget, Bl as CapabilityMetadataOf, Bu as SqlSemanticType, Cl as markExpressionCategory, Cu as fragment, Du as AnySqlType, Eu as sequence, Fu as SqlInteger, G as DialectJson, Ga as typedValue, Gl as Fragment, Gu as SqlUnknown, H as DialectCapability, Hl as CardinalityOf, Hu as SqlTextLike, Il as AggregateDependenciesOf, Iu as SqlJson, J as DialectRowLocking, Jl as GroupingKeysOf, K as DialectOptions, Kl as FragmentMeta, Ku as SqlUuid, Ll as AggregateMeta, Lu as SqlNumericLike, Mo as RenderOptions, Mu as SqlDecimal, No as RenderedQuery, Nu as SqlEqualityComparable, Ou as SqlBigInt, Po as render, Pu as SqlEqualityCompatible, Q as NamedCastTarget, Ql as HasWindow, Ri as ClausePlacement, Rl as AnyFragment, Ru as SqlOrderCompatible, Sl as makeExpression, Su as WindowMeta, Tu as parenthesize, U as DialectCastTypes, Ul as DependenciesOf, Uu as SqlTimestamp, V as Dialect, Vl as CardinalityMeta, Vu as SqlText, W as DialectExplain, Wl as ExpressionMeta, Wu as SqlTypeSatisfies, X as ExplainRenderOptions, Xl as HasAggregate, Y as ExplainFormat, Ya as typedCast, Yl as GroupingMeta, Z as JsonScalarKind, Zl as HasSubquery, _u as RequiresSourceMeta, at as SchemaLiteralRenderer, au as OutputOf, bu as SubqueryMeta, ct as resolveCastTarget, cu as ProvidesSourceMeta, du as RenderFunction, et as PaginationPart, eu as InheritedMetadataOf, fl as Expression, fu as RequiresCapabilityMeta, gu as RequiresOuterSourceMeta, hu as RequiresOuterOf, it as RowLockWaitPolicy, iu as NullableSourcesOf, jo as RenderCapabilityValidation, ju as SqlDate, ku as SqlBinary, ll as expressionFragment, lu as QueryCardinality, mu as RequiresOuterMetadataOf, nt as PortableCastType, nu as NullabilityOf, ot as assertDialectCapability, ou as ProvidesOuterOf, pu as RequiresOf, q as DialectPagination, ql as GroupingDependenciesOf, rt as RowLockMode, ru as NullableSourceMeta, sa as typedCall, st as createDialect, su as ProvidesOuterSourceMeta, tt as PortableCastTarget, tu as MetadataOf, uu as RenderContext, vu as ResultMeta, wl as withDialectCapability, wu as isFragment, xl as isExpression, xu as VisibleDependenciesOf, yu as SqlTypeOf, zi as SelectClause, zl as CapabilitiesOf, zu as SqlOrderable } from "./types-Deo_q43Y.mjs";
|
|
2
2
|
//#region src/core/primitives/compose.d.ts
|
|
3
3
|
declare function commaSeparated<const TParts extends readonly AnyFragment[]>(parts: TParts): Fragment<InheritedMetadata<TParts[number]>>;
|
|
4
4
|
declare function keyword<TPart extends AnyFragment | undefined>(value: string, part?: TPart): Fragment<TPart extends AnyFragment ? InheritedMetadata<TPart> : never>;
|
package/dist/core.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as assertDialectCapability, o as createDialect, s as resolveCastTarget } from "./json-CUZlv4HT.mjs";
|
|
2
|
-
import { a as routineName, c as render, i as typedCall, s as typedCast, t as createClause } from "./types-
|
|
3
|
-
import {
|
|
4
|
-
import { a as parameter, r as typedValue } from "./value-
|
|
2
|
+
import { a as routineName, c as render, i as typedCall, s as typedCast, t as createClause } from "./types-g-vVvj1B.mjs";
|
|
3
|
+
import { C as fragment, E as sequence, S as withDialectCapability, T as parenthesize, a as qualifiedIdentifier, b as markExpressionCategory, g as isExpression, i as identifier, n as expressionFragment, v as makeExpression, w as isFragment } from "./column-D-8OqGuV.mjs";
|
|
4
|
+
import { a as parameter, r as typedValue } from "./value-b6OFZXVS.mjs";
|
|
5
5
|
//#region src/core/primitives/compose.ts
|
|
6
6
|
function commaSeparated(parts) {
|
|
7
7
|
return sequence(parts, ", ");
|
package/dist/ddl.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ir as SchemaDialect } from "./types-Deo_q43Y.mjs";
|
|
2
2
|
import { MigrationLockRequirement, MigrationOperation, MigrationPlan, MigrationTransactionRequirement } from "./migration.mjs";
|
|
3
3
|
//#region src/ddl/types.d.ts
|
|
4
4
|
/** Stable diagnostic categories produced before a migration is rendered. */
|
package/dist/ddl.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as sqliteSchemaDialect } from "./sqlite-
|
|
2
|
-
import { n as postgresSchemaDialect } from "./postgres-
|
|
3
|
-
import { n as mysqlSchemaDialect } from "./mysql-
|
|
1
|
+
import { n as sqliteSchemaDialect } from "./sqlite-CrsK0Fza.mjs";
|
|
2
|
+
import { n as postgresSchemaDialect } from "./postgres-BK2APkKP.mjs";
|
|
3
|
+
import { n as mysqlSchemaDialect } from "./mysql-CKEKGnj4.mjs";
|
|
4
4
|
import { assertMigrationPlan } from "./migration.mjs";
|
|
5
5
|
//#region src/ddl/emitter.ts
|
|
6
6
|
const objectKinds = /* @__PURE__ */ new Set([
|
package/dist/diff.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as SnapshotDiffPropertyChange, D as SnapshotRenameTarget, E as SnapshotRenameSuggestion, S as SnapshotDiffPath, T as SnapshotRenameHintResult, _ as SnapshotDiffObjectKind, a as diffSnapshots, b as SnapshotDiffOperationType, c as validateRenameHints, d as SnapshotDiffDecodeResult, f as SnapshotDiffDiagnostic, g as SnapshotDiffObject, h as SnapshotDiffInput, i as decodeSnapshotRenameHints, l as validateSnapshotRenameHints, m as SnapshotDiffEvidence, n as decodeRenameHints, o as encodeRenameHints, p as SnapshotDiffDiagnosticCode, r as decodeSnapshotForDiff, s as encodeSnapshotRenameHints, t as compareSnapshots, u as SnapshotDiff, v as SnapshotDiffObjectReference, w as SnapshotRenameHint, x as SnapshotDiffOptions, y as SnapshotDiffOperation } from "./index-
|
|
1
|
+
import { C as SnapshotDiffPropertyChange, D as SnapshotRenameTarget, E as SnapshotRenameSuggestion, S as SnapshotDiffPath, T as SnapshotRenameHintResult, _ as SnapshotDiffObjectKind, a as diffSnapshots, b as SnapshotDiffOperationType, c as validateRenameHints, d as SnapshotDiffDecodeResult, f as SnapshotDiffDiagnostic, g as SnapshotDiffObject, h as SnapshotDiffInput, i as decodeSnapshotRenameHints, l as validateSnapshotRenameHints, m as SnapshotDiffEvidence, n as decodeRenameHints, o as encodeRenameHints, p as SnapshotDiffDiagnosticCode, r as decodeSnapshotForDiff, s as encodeSnapshotRenameHints, t as compareSnapshots, u as SnapshotDiff, v as SnapshotDiffObjectReference, w as SnapshotRenameHint, x as SnapshotDiffOptions, y as SnapshotDiffOperation } from "./index-D3ZOwPT-.mjs";
|
|
2
2
|
export { SnapshotDiff, SnapshotDiffDecodeResult, SnapshotDiffDiagnostic, SnapshotDiffDiagnosticCode, SnapshotDiffEvidence, SnapshotDiffInput, SnapshotDiffObject, SnapshotDiffObjectKind, SnapshotDiffObjectReference, SnapshotDiffOperation, SnapshotDiffOperationType, SnapshotDiffOptions, SnapshotDiffPath, SnapshotDiffPropertyChange, SnapshotRenameHint, SnapshotRenameHintResult, SnapshotRenameSuggestion, SnapshotRenameTarget, compareSnapshots, decodeRenameHints, decodeSnapshotForDiff, decodeSnapshotRenameHints, diffSnapshots, encodeRenameHints, encodeSnapshotRenameHints, validateRenameHints, validateSnapshotRenameHints };
|
package/dist/drizzle-mysql.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-
|
|
1
|
+
import { Lt as AnyTable, ei as Schema, oi as SchemaTableRecord } from "./types-Deo_q43Y.mjs";
|
|
2
|
+
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-DZsueVoI.mjs";
|
|
3
3
|
import { MySqlColumn, MySqlTableWithColumns } from "drizzle-orm/mysql-core";
|
|
4
4
|
//#region src/drizzle/mysql.d.ts
|
|
5
5
|
type MysqlDrizzleColumn<TTableName extends string, TDefinition> = MySqlColumn<DrizzleColumnConfig<TTableName, TDefinition>>;
|
package/dist/drizzle-mysql.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createMysqlSchemaSnapshot } from "./mysql-
|
|
2
|
-
import { i as stringExtension, n as extensionData, t as convertDrizzleSchema } from "./runtime-
|
|
1
|
+
import { t as createMysqlSchemaSnapshot } from "./mysql-CKEKGnj4.mjs";
|
|
2
|
+
import { i as stringExtension, n as extensionData, t as convertDrizzleSchema } from "./runtime-Cn_Xgzta.mjs";
|
|
3
3
|
import { bigint, boolean, char, check, customType, date, datetime, decimal, foreignKey, index, int, json, mysqlSchema, mysqlTable, primaryKey, text, unique, uniqueIndex } from "drizzle-orm/mysql-core";
|
|
4
4
|
//#region src/drizzle/mysql.ts
|
|
5
5
|
const mysqlAdapter = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-
|
|
1
|
+
import { Lt as AnyTable, ei as Schema, oi as SchemaTableRecord } from "./types-Deo_q43Y.mjs";
|
|
2
|
+
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-DZsueVoI.mjs";
|
|
3
3
|
import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core";
|
|
4
4
|
//#region src/drizzle/postgres.d.ts
|
|
5
5
|
type PostgresDrizzleColumn<TTableName extends string, TDefinition> = PgColumn<'custom', DrizzleColumnConfig<TTableName, TDefinition>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createPostgresSchemaSnapshot } from "./postgres-
|
|
2
|
-
import { i as stringExtension, n as extensionData, r as recordExtension, t as convertDrizzleSchema } from "./runtime-
|
|
1
|
+
import { t as createPostgresSchemaSnapshot } from "./postgres-BK2APkKP.mjs";
|
|
2
|
+
import { i as stringExtension, n as extensionData, r as recordExtension, t as convertDrizzleSchema } from "./runtime-Cn_Xgzta.mjs";
|
|
3
3
|
import { bigint, boolean, check, customType, date, foreignKey, index, integer, jsonb, numeric, pgSchema, pgTable, primaryKey, text, timestamp, unique, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
4
4
|
//#region src/drizzle/postgres.ts
|
|
5
5
|
const postgresAdapter = {
|
|
@@ -1,9 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-
|
|
1
|
+
import { Lt as AnyTable, Uu as SqlTimestamp, ei as Schema, kc as ExternalDefaultDescriptor, oi as SchemaTableRecord, qs as NativeColumnStorage, ws as ColumnDefinition } from "./types-Deo_q43Y.mjs";
|
|
2
|
+
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-DZsueVoI.mjs";
|
|
3
3
|
import { SQLiteColumn, SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
4
4
|
//#region src/drizzle/sqlite.d.ts
|
|
5
5
|
type SqliteDrizzleColumn<TTableName extends string, TDefinition> = SQLiteColumn<DrizzleColumnConfig<TTableName, TDefinition>>;
|
|
6
6
|
type SqliteDrizzleColumns<TTable extends AnyTable> = { [TKey in keyof TTable['definitions']]: SqliteDrizzleColumn<TTable['tableName'], TTable['definitions'][TKey]>; };
|
|
7
|
+
/** Integer encoding used by Drizzle's SQLite timestamp column builder. */
|
|
8
|
+
type SqliteTimestampMode = 'timestamp' | 'timestamp_ms';
|
|
9
|
+
/** Runtime options for a Drizzle-compatible SQLite integer timestamp. */
|
|
10
|
+
interface SqliteTimestampOptions {
|
|
11
|
+
/** Store Unix seconds by default, or milliseconds with `timestamp_ms`. */
|
|
12
|
+
readonly mode?: SqliteTimestampMode;
|
|
13
|
+
readonly nullable?: boolean;
|
|
14
|
+
readonly sqlName?: string;
|
|
15
|
+
/** Supply an application value when a Drizzle insert omits this column. */
|
|
16
|
+
readonly defaultFn?: () => Date;
|
|
17
|
+
}
|
|
18
|
+
type SqliteTimestampNullable<TOptions extends SqliteTimestampOptions> = TOptions extends {
|
|
19
|
+
readonly nullable: true;
|
|
20
|
+
} ? true : false;
|
|
21
|
+
type SqliteTimestampHasDefault<TOptions extends SqliteTimestampOptions> = TOptions extends {
|
|
22
|
+
readonly defaultFn: () => Date;
|
|
23
|
+
} ? true : false;
|
|
24
|
+
/** Qubu definition produced by {@link sqliteTimestamp}. */
|
|
25
|
+
type SqliteTimestampColumn<TOptions extends SqliteTimestampOptions = {}> = ColumnDefinition<{
|
|
26
|
+
readonly output: Date;
|
|
27
|
+
readonly nullable: SqliteTimestampNullable<TOptions>;
|
|
28
|
+
readonly hasDefault: SqliteTimestampHasDefault<TOptions>;
|
|
29
|
+
readonly sqlType: SqlTimestamp;
|
|
30
|
+
readonly storage: NativeColumnStorage<'sqlite', 'INTEGER'>;
|
|
31
|
+
readonly default: SqliteTimestampHasDefault<TOptions> extends true ? ExternalDefaultDescriptor : undefined;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Declare a SQLite `INTEGER` timestamp that retains Drizzle's Date codec.
|
|
35
|
+
*
|
|
36
|
+
* @remarks `defaultFn` is runtime-only. Snapshots and emitted DDL retain the
|
|
37
|
+
* native `INTEGER` storage but do not serialize the callback.
|
|
38
|
+
*/
|
|
39
|
+
declare function sqliteTimestamp<const TOptions extends SqliteTimestampOptions = {}>(options?: TOptions): SqliteTimestampColumn<TOptions>;
|
|
7
40
|
/** The Drizzle SQLite table produced for one Qubu table. */
|
|
8
41
|
type SqliteDrizzleTable<TTable extends AnyTable> = SQLiteTableWithColumns<{
|
|
9
42
|
name: TTable['tableName'];
|
|
@@ -21,4 +54,4 @@ type SqliteDrizzleSchema<TSchema extends Schema<any>> = { readonly [TKey in keyo
|
|
|
21
54
|
*/
|
|
22
55
|
declare function toSqliteDrizzleSchema<const TTables extends SchemaTableRecord>(schema: Schema<TTables> & DrizzleSchemaValidation<TTables, 'sqlite'>): SqliteDrizzleSchema<Schema<TTables>>;
|
|
23
56
|
//#endregion
|
|
24
|
-
export { SqliteDrizzleSchema, SqliteDrizzleTable, toSqliteDrizzleSchema };
|
|
57
|
+
export { SqliteDrizzleSchema, SqliteDrizzleTable, SqliteTimestampColumn, SqliteTimestampMode, SqliteTimestampOptions, sqliteTimestamp, toSqliteDrizzleSchema };
|