qubu 0.0.0 → 0.3.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.
Files changed (109) hide show
  1. package/dist/canonical-BbnqavJm.mjs +972 -0
  2. package/dist/codegen.d.mts +107 -0
  3. package/dist/codegen.mjs +1199 -0
  4. package/dist/column-CXMxx8Hq.mjs +118 -0
  5. package/dist/complete-D5Djh-zo.mjs +1788 -0
  6. package/dist/complete-types-BdFqUfbb.d.mts +371 -0
  7. package/dist/core.d.mts +33 -0
  8. package/dist/core.mjs +36 -0
  9. package/dist/ddl.d.mts +118 -0
  10. package/dist/ddl.mjs +1120 -0
  11. package/dist/dialect-b2-Z6uBF.mjs +13 -0
  12. package/dist/diff.d.mts +2 -0
  13. package/dist/diff.mjs +883 -0
  14. package/dist/drizzle-mysql.d.mts +24 -0
  15. package/dist/drizzle-mysql.mjs +72 -0
  16. package/dist/drizzle-postgres.d.mts +24 -0
  17. package/dist/drizzle-postgres.mjs +73 -0
  18. package/dist/drizzle-sqlite.d.mts +24 -0
  19. package/dist/drizzle-sqlite.mjs +82 -0
  20. package/dist/drizzle.d.mts +13 -0
  21. package/dist/drizzle.mjs +2 -0
  22. package/dist/errors-BGCoLe_r.mjs +14 -0
  23. package/dist/errors-Dxv73YJu.mjs +26 -0
  24. package/dist/explain-CkIK13L_.mjs +98 -0
  25. package/dist/index-Ds7-mhJi.d.mts +146 -0
  26. package/dist/index-Dug5HnLB.d.mts +204 -0
  27. package/dist/index.d.mts +2 -0
  28. package/dist/index.mjs +1276 -0
  29. package/dist/introspection.d.mts +117 -0
  30. package/dist/introspection.mjs +4341 -0
  31. package/dist/json-CUZlv4HT.mjs +169 -0
  32. package/dist/migration.d.mts +215 -0
  33. package/dist/migration.mjs +1161 -0
  34. package/dist/mysql-DqkqXB6A.mjs +355 -0
  35. package/dist/mysql.d.mts +5 -0
  36. package/dist/mysql.mjs +50 -0
  37. package/dist/naming-QVCOnSj2.mjs +20 -0
  38. package/dist/omit-OxV58AwX.mjs +5 -0
  39. package/dist/on-conflict-BxnxubMb.mjs +143 -0
  40. package/dist/postgres-DEBBeh52.mjs +235 -0
  41. package/dist/postgres.d.mts +123 -0
  42. package/dist/postgres.mjs +52 -0
  43. package/dist/registry-BufIskVN.mjs +569 -0
  44. package/dist/relational-DCZrrNia.mjs +77 -0
  45. package/dist/runtime-BTr-MTlo.mjs +193 -0
  46. package/dist/schema.d.mts +2 -0
  47. package/dist/schema.mjs +5 -0
  48. package/dist/serialize-PF1cfH2P.mjs +556 -0
  49. package/dist/snapshot-CWPgzxNx.mjs +392 -0
  50. package/dist/snapshot.d.mts +4 -0
  51. package/dist/snapshot.mjs +8 -0
  52. package/dist/source-DUoJVXmL.mjs +68 -0
  53. package/dist/sqlite-BU6DBxef.mjs +320 -0
  54. package/dist/sqlite.d.mts +5 -0
  55. package/dist/sqlite.mjs +48 -0
  56. package/dist/standard-BTVYKh_F.mjs +12 -0
  57. package/dist/table-llv9tsZ8.mjs +384 -0
  58. package/dist/types-4Q076HKo.d.mts +3636 -0
  59. package/dist/types-BX0mckiU.d.mts +644 -0
  60. package/dist/types-CO1KaRNc.d.mts +46 -0
  61. package/dist/types-Cec0xzo4.mjs +116 -0
  62. package/dist/value-BvilP0oz.mjs +29 -0
  63. package/dist/vite/ambient.d.ts +449 -0
  64. package/dist/vite.d.mts +35 -0
  65. package/dist/vite.mjs +498 -0
  66. package/docs/config.json +21 -0
  67. package/docs/dialects-and-execution.md +427 -0
  68. package/docs/getting-started.md +96 -0
  69. package/docs/guides/compose-queries.md +225 -0
  70. package/docs/guides/drizzle.md +129 -0
  71. package/docs/guides/extensions/dialects.md +40 -0
  72. package/docs/guides/extensions/overview.md +36 -0
  73. package/docs/guides/extensions/sources-and-clauses.md +82 -0
  74. package/docs/guides/extensions/typed-expressions.md +94 -0
  75. package/docs/guides/extensions/unsafe-syntax.md +27 -0
  76. package/docs/guides/json.md +65 -0
  77. package/docs/guides/mutations.md +138 -0
  78. package/docs/guides/select/conditions.md +110 -0
  79. package/docs/guides/select/grouping-and-windows.md +82 -0
  80. package/docs/guides/select/ordering-and-pagination.md +78 -0
  81. package/docs/guides/select/overview.md +139 -0
  82. package/docs/guides/sql-templates.md +157 -0
  83. package/docs/guides/vite-plugin.md +92 -0
  84. package/docs/index.md +111 -0
  85. package/docs/query-model/fragments.md +109 -0
  86. package/docs/query-model/result-shapes.md +125 -0
  87. package/docs/query-model/source-scope.md +182 -0
  88. package/docs/reference/introspection-support.md +196 -0
  89. package/docs/reference/mysql-snapshot.md +55 -0
  90. package/docs/reference/postgres-snapshot.md +61 -0
  91. package/docs/reference/sqlite-snapshot.md +53 -0
  92. package/docs/reference/supported-surface.md +104 -0
  93. package/docs/schema/catalog-model.md +58 -0
  94. package/docs/schema/code-generation.md +139 -0
  95. package/docs/schema/columns-and-writes.md +130 -0
  96. package/docs/schema/constraints-and-indexes.md +180 -0
  97. package/docs/schema/ddl-emission.md +75 -0
  98. package/docs/schema/diff.md +75 -0
  99. package/docs/schema/introspection.md +214 -0
  100. package/docs/schema/migration-plans.md +76 -0
  101. package/docs/schema/snapshots.md +93 -0
  102. package/docs/schema/storage-and-schema-sql.md +104 -0
  103. package/docs/schema/tables-and-names.md +106 -0
  104. package/docs/sql-semantic-types.md +141 -0
  105. package/docs/troubleshooting.md +151 -0
  106. package/package.json +132 -10
  107. package/skills/qubu/SKILL.md +42 -0
  108. package/skills/qubu/agents/openai.yaml +6 -0
  109. package/readme.md +0 -1
@@ -0,0 +1,384 @@
1
+ import { h as parenthesize, i as identifier, s as isSchemaExpression, t as createColumnReference } from "./column-CXMxx8Hq.mjs";
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
53
+ //#region src/schema/column-behavior.ts
54
+ /** A column behavior error with a stable code and optional property path. */
55
+ var ColumnBehaviorError = class extends TypeError {
56
+ code;
57
+ path;
58
+ constructor(code, message, path) {
59
+ super(message);
60
+ this.name = "ColumnBehaviorError";
61
+ this.code = code;
62
+ this.path = path;
63
+ }
64
+ };
65
+ /** Build a canonical literal node from a supported JavaScript scalar. */
66
+ function canonicalLiteral(value) {
67
+ if (value === null) return Object.freeze({ kind: "null" });
68
+ if (typeof value === "boolean") return Object.freeze({
69
+ kind: "boolean",
70
+ value
71
+ });
72
+ if (typeof value === "string") return Object.freeze({
73
+ kind: "string",
74
+ value
75
+ });
76
+ if (typeof value === "bigint") return Object.freeze({
77
+ kind: "bigint",
78
+ value: String(value)
79
+ });
80
+ if (!Number.isFinite(value)) throw new ColumnBehaviorError("invalid-default", "Default literal numbers must be finite", "default.value");
81
+ return Object.freeze({
82
+ kind: "number",
83
+ value: Object.is(value, -0) ? "0" : String(value)
84
+ });
85
+ }
86
+ function literalDefault(value) {
87
+ return Object.freeze({
88
+ kind: "literal",
89
+ value: canonicalLiteral(value)
90
+ });
91
+ }
92
+ /** Normalize a public default input into its canonical snapshot descriptor. */
93
+ function normalizeDefault(value) {
94
+ if (isSchemaExpression(value)) return Object.freeze({
95
+ kind: "expression",
96
+ expression: value
97
+ });
98
+ if (isExternalDefaultDescriptor(value)) return externalDefault();
99
+ return literalDefault(value);
100
+ }
101
+ /** Mark a legacy or externally managed database default explicitly. */
102
+ function externalDefault() {
103
+ return Object.freeze({ kind: "external" });
104
+ }
105
+ /** Create an immutable generated-column descriptor. */
106
+ function generatedColumn(expression, mode) {
107
+ assertSchemaExpression(expression, "generatedColumn.expression", "invalid-generated-column");
108
+ const resolvedMode = typeof mode === "string" ? mode : mode?.mode ?? "stored";
109
+ if (resolvedMode !== "stored" && resolvedMode !== "virtual") throw new ColumnBehaviorError("invalid-generated-column", `Generated-column mode must be "stored" or "virtual", received "${String(resolvedMode)}"`, "generatedColumn.mode");
110
+ return Object.freeze({
111
+ kind: "expression",
112
+ expression,
113
+ mode: resolvedMode
114
+ });
115
+ }
116
+ /** Mark a legacy or externally managed generated column explicitly. */
117
+ function externalGeneratedColumn() {
118
+ return Object.freeze({ kind: "external" });
119
+ }
120
+ /** Describe a database identity column without inventing a generated SQL expression. */
121
+ function identityColumn(generation, options) {
122
+ const resolvedGeneration = generation ?? "by-default";
123
+ if (resolvedGeneration !== "always" && resolvedGeneration !== "by-default") throw new ColumnBehaviorError("invalid-identity", `Identity generation must be "always" or "by-default", received "${String(resolvedGeneration)}"`, "identity.generation");
124
+ return Object.freeze({
125
+ kind: "identity",
126
+ generation: resolvedGeneration,
127
+ ...options?.dialect === void 0 ? {} : { dialect: freezeSchemaMetadata(options.dialect) }
128
+ });
129
+ }
130
+ /** Normalize complete and legacy column behavior into immutable metadata. */
131
+ function resolveColumnBehavior(options) {
132
+ const hasDefaultFlag = options.hasDefault === true;
133
+ const generatedFlag = options.generated === true;
134
+ const defaultDescriptor = options.default === void 0 ? void 0 : normalizeDefault(options.default);
135
+ const generatedDescriptor = options.generatedColumn;
136
+ const identityDescriptor = options.identity;
137
+ const onUpdateExpression = options.onUpdate;
138
+ if (onUpdateExpression !== void 0 && !isSchemaExpression(onUpdateExpression)) throw new ColumnBehaviorError("invalid-on-update", "Column onUpdate metadata must carry the deterministic schema-expression brand", "onUpdate");
139
+ if (defaultDescriptor !== void 0) {
140
+ assertDefaultDescriptor(defaultDescriptor);
141
+ if (options.hasDefault === false) throw new ColumnBehaviorError("default-flag-conflict", "A complete default descriptor cannot be combined with hasDefault: false", "hasDefault");
142
+ if (generatedDescriptor !== void 0 || identityDescriptor !== void 0) throw new ColumnBehaviorError("default-generated-conflict", "A column cannot declare a complete default together with generated-column or identity metadata", "default");
143
+ if (generatedFlag) throw new ColumnBehaviorError("default-generated-conflict", "A complete default descriptor cannot be combined with generated: true", "default");
144
+ }
145
+ if (generatedDescriptor !== void 0) {
146
+ assertGeneratedColumnDescriptor(generatedDescriptor);
147
+ if (options.generated === false) throw new ColumnBehaviorError("generated-flag-conflict", "A complete generated-column descriptor cannot be combined with generated: false", "generated");
148
+ if (identityDescriptor !== void 0) throw new ColumnBehaviorError("identity-generated-conflict", "A column cannot declare both generated-column and identity metadata", "generatedColumn");
149
+ if (hasDefaultFlag) throw new ColumnBehaviorError("default-generated-conflict", "A complete generated-column descriptor cannot be combined with hasDefault: true", "generatedColumn");
150
+ }
151
+ if (identityDescriptor !== void 0) {
152
+ assertIdentityDescriptor(identityDescriptor);
153
+ if (options.generated === false) throw new ColumnBehaviorError("generated-flag-conflict", "Identity metadata cannot be combined with generated: false", "generated");
154
+ if (hasDefaultFlag) throw new ColumnBehaviorError("identity-generated-conflict", "Identity metadata cannot be combined with hasDefault: true", "identity");
155
+ }
156
+ const normalizedDefault = defaultDescriptor === void 0 ? void 0 : freezeDefaultDescriptor(defaultDescriptor);
157
+ const normalizedGenerated = generatedDescriptor === void 0 ? void 0 : freezeGeneratedColumnDescriptor(generatedDescriptor);
158
+ const normalizedIdentity = identityDescriptor === void 0 ? void 0 : freezeIdentityDescriptor(identityDescriptor);
159
+ return Object.freeze({
160
+ hasDefault: hasDefaultFlag || normalizedDefault !== void 0,
161
+ generated: generatedFlag || normalizedGenerated !== void 0 || normalizedIdentity !== void 0,
162
+ default: normalizedDefault ?? (hasDefaultFlag ? externalDefault() : void 0),
163
+ generatedColumn: normalizedGenerated ?? (generatedFlag && normalizedIdentity === void 0 ? externalGeneratedColumn() : void 0),
164
+ identity: normalizedIdentity,
165
+ onUpdate: onUpdateExpression
166
+ });
167
+ }
168
+ function freezeDefaultDescriptor(value) {
169
+ if (value.kind === "external") return externalDefault();
170
+ if (value.kind === "expression") return Object.freeze({
171
+ kind: "expression",
172
+ expression: value.expression
173
+ });
174
+ return Object.freeze({
175
+ kind: "literal",
176
+ value: Object.freeze({ ...value.value })
177
+ });
178
+ }
179
+ function isExternalDefaultDescriptor(value) {
180
+ return typeof value === "object" && value !== null && value.kind === "external";
181
+ }
182
+ function freezeGeneratedColumnDescriptor(value) {
183
+ if (value.kind === "external") return externalGeneratedColumn();
184
+ return Object.freeze({
185
+ kind: "expression",
186
+ expression: value.expression,
187
+ mode: value.mode
188
+ });
189
+ }
190
+ function freezeIdentityDescriptor(value) {
191
+ return Object.freeze({
192
+ kind: "identity",
193
+ generation: value.generation,
194
+ ...value.dialect === void 0 ? {} : { dialect: freezeSchemaMetadata(value.dialect) }
195
+ });
196
+ }
197
+ function assertSchemaExpression(expression, path, code = "invalid-default") {
198
+ if (!isSchemaExpression(expression)) throw new ColumnBehaviorError(code, "Schema behavior expressions must carry the deterministic schema-expression brand", path);
199
+ }
200
+ function assertDefaultDescriptor(value) {
201
+ if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-default", "Column default metadata must be an object", "default");
202
+ if (value.kind === "external") return;
203
+ if (value.kind === "expression") {
204
+ assertSchemaExpression(value.expression, "default.expression");
205
+ return;
206
+ }
207
+ if (value.kind === "literal") {
208
+ assertCanonicalLiteral(value.value);
209
+ return;
210
+ }
211
+ throw new ColumnBehaviorError("invalid-default", "Unknown column default descriptor kind", "default.kind");
212
+ }
213
+ function assertGeneratedColumnDescriptor(value) {
214
+ if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-generated-column", "Generated-column metadata must be an object", "generatedColumn");
215
+ if (value.kind === "external") return;
216
+ if (value.kind === "expression") {
217
+ assertSchemaExpression(value.expression, "generatedColumn.expression", "invalid-generated-column");
218
+ if (value.mode !== "stored" && value.mode !== "virtual") throw new ColumnBehaviorError("invalid-generated-column", "Generated-column mode must be \"stored\" or \"virtual\"", "generatedColumn.mode");
219
+ return;
220
+ }
221
+ throw new ColumnBehaviorError("invalid-generated-column", "Unknown generated-column descriptor kind", "generatedColumn.kind");
222
+ }
223
+ function assertIdentityDescriptor(value) {
224
+ if (!value || typeof value !== "object" || value.kind !== "identity" || value.generation !== "always" && value.generation !== "by-default") throw new ColumnBehaviorError("invalid-identity", "Identity metadata must use generation \"always\" or \"by-default\"", "identity.generation");
225
+ if (value.dialect !== void 0) {
226
+ if (typeof value.dialect !== "object" || value.dialect === null || typeof value.dialect.dialect !== "string" || value.dialect.dialect.length === 0) throw new ColumnBehaviorError("invalid-identity", "Identity dialect metadata must contain a non-empty dialect tag", "identity.dialect");
227
+ }
228
+ }
229
+ function assertCanonicalLiteral(value) {
230
+ if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-default", "Literal defaults must contain a canonical literal node", "default.value");
231
+ switch (value.kind) {
232
+ case "null": return;
233
+ case "boolean":
234
+ if (typeof value.value === "boolean") return;
235
+ break;
236
+ case "string":
237
+ if (typeof value.value === "string") return;
238
+ break;
239
+ case "number":
240
+ if (typeof value.value === "string" && value.value.length > 0) return;
241
+ break;
242
+ case "bigint": if (/^-?(0|[1-9][0-9]*)$/.test(value.value)) return;
243
+ }
244
+ throw new ColumnBehaviorError("invalid-default", "Literal defaults must contain a valid canonical literal node", "default.value");
245
+ }
246
+ //#endregion
247
+ //#region src/schema/column.ts
248
+ /** Create an immutable portable physical storage descriptor. */
249
+ function portableStorage(type) {
250
+ return Object.freeze({
251
+ kind: "portable",
252
+ type
253
+ });
254
+ }
255
+ function nativeStorage(dialectOrOptions, type) {
256
+ const dialect = typeof dialectOrOptions === "string" ? dialectOrOptions : dialectOrOptions.dialect;
257
+ const declaration = typeof dialectOrOptions === "string" ? type : "type" in dialectOrOptions ? dialectOrOptions.type : dialectOrOptions.declaration;
258
+ return Object.freeze({
259
+ kind: "native",
260
+ dialect,
261
+ type: declaration
262
+ });
263
+ }
264
+ function narrowColumnType() {
265
+ return this;
266
+ }
267
+ function withPortableCast(definition, type) {
268
+ return Object.freeze({
269
+ ...definition,
270
+ castTarget: Object.freeze({
271
+ kind: "portable-cast",
272
+ type
273
+ })
274
+ });
275
+ }
276
+ function withPortableStorage(definition, type) {
277
+ return Object.freeze({
278
+ ...definition,
279
+ storage: portableStorage(type)
280
+ });
281
+ }
282
+ function column(options) {
283
+ return Object.freeze({
284
+ definitionKind: "column",
285
+ nullable: options?.nullable === true,
286
+ ...resolveColumnBehavior(options ?? {}),
287
+ sqlName: options?.sqlName,
288
+ storage: options?.storage ? Object.freeze({ ...options.storage }) : void 0,
289
+ $type: narrowColumnType,
290
+ castTarget: options?.castType ? Object.freeze({
291
+ kind: "named-cast",
292
+ typeName: options.castType
293
+ }) : void 0
294
+ });
295
+ }
296
+ function nativeColumn(storageOrDialect, typeOrOptions, maybeOptions) {
297
+ const storage = typeof storageOrDialect === "string" ? nativeStorage(storageOrDialect, typeOrOptions) : storageOrDialect;
298
+ return column({
299
+ ...(typeof storageOrDialect === "string" ? maybeOptions : typeOrOptions) ?? {},
300
+ storage
301
+ });
302
+ }
303
+ function nullable(definition) {
304
+ return Object.freeze({
305
+ ...definition,
306
+ nullable: true
307
+ });
308
+ }
309
+ function integer(options) {
310
+ return withPortableStorage(withPortableCast(column(options), "integer"), "integer");
311
+ }
312
+ function numeric(options) {
313
+ return withPortableStorage(withPortableCast(column(options), "decimal"), "numeric");
314
+ }
315
+ function text(options) {
316
+ return withPortableStorage(withPortableCast(column(options), "text"), "text");
317
+ }
318
+ function boolean(options) {
319
+ return withPortableStorage(withPortableCast(column(options), "boolean"), "boolean");
320
+ }
321
+ function date(options) {
322
+ return withPortableStorage(withPortableCast(column(options), "date"), "date");
323
+ }
324
+ function timestamp(options) {
325
+ return withPortableStorage(withPortableCast(column(options), "timestamp"), "timestamp");
326
+ }
327
+ function uuid(options) {
328
+ return withPortableStorage(withPortableCast(column(options), "uuid"), "uuid");
329
+ }
330
+ function json(options) {
331
+ return withPortableStorage(withPortableCast(column(options), "json"), "json");
332
+ }
333
+ function bigint(options) {
334
+ return withPortableStorage(withPortableCast(column(options), "bigint"), "bigint");
335
+ }
336
+ function binary(options) {
337
+ return withPortableStorage(withPortableCast(column(options), "binary"), "binary");
338
+ }
339
+ //#endregion
340
+ //#region src/schema/table.ts
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 };