qubu 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +112 -0
  2. package/dist/{complete-DP7pliuY.mjs → canonical-B5_ouh-c.mjs} +466 -241
  3. package/dist/codegen.d.mts +2 -2
  4. package/dist/codegen.mjs +180 -90
  5. package/dist/column-Cyc2CMnG.mjs +116 -0
  6. package/dist/column-DDRvD7SF.mjs +721 -0
  7. package/dist/{constraints-YGyNPQ_z.mjs → constraints-CAmi18Uk.mjs} +8 -3
  8. package/dist/core.d.mts +3 -3
  9. package/dist/core.mjs +4 -5
  10. package/dist/diagnostics-I9vVtXkc.mjs +40 -0
  11. package/dist/diff.d.mts +9 -9
  12. package/dist/diff.mjs +152 -102
  13. package/dist/{explain-CkIK13L_.mjs → explain-BIqEmZha.mjs} +1 -1
  14. package/dist/expressions-_6JF_J77.mjs +130 -0
  15. package/dist/index-CaxrMD1A.d.mts +1 -0
  16. package/dist/index.d.mts +2 -2
  17. package/dist/index.mjs +414 -77
  18. package/dist/introspection/mysql.d.mts +26 -0
  19. package/dist/introspection/mysql.mjs +1278 -0
  20. package/dist/introspection/postgres.d.mts +43 -0
  21. package/dist/introspection/postgres.mjs +1889 -0
  22. package/dist/introspection/sqlite.d.mts +15 -0
  23. package/dist/introspection/sqlite.mjs +1172 -0
  24. package/dist/introspection.d.mts +26 -87
  25. package/dist/introspection.mjs +3 -4351
  26. package/dist/mysql.d.mts +3 -3
  27. package/dist/mysql.mjs +8 -7
  28. package/dist/{errors-Dxv73YJu.mjs → omit-VEr9Ydux.mjs} +5 -1
  29. package/dist/{on-conflict-DZQ85f1t.mjs → on-conflict-B2rFyHGF.mjs} +78 -8
  30. package/dist/on-duplicate-key-update-Czsw1Yq-.mjs +95 -0
  31. package/dist/postgres-hFhd0I9n.mjs +68 -0
  32. package/dist/postgres.d.mts +3 -3
  33. package/dist/postgres.mjs +3 -52
  34. package/dist/registry-BXE_4M9P.mjs +127 -0
  35. package/dist/{relational-CxnLCqZQ.mjs → relational-CoPBETjI.mjs} +3 -3
  36. package/dist/schema.d.mts +2 -2
  37. package/dist/schema.mjs +8 -7
  38. package/dist/{serialize-BN07IK0v.mjs → serialize-CyobNEx-.mjs} +174 -30
  39. package/dist/serialize-Du2UPZMt.d.mts +92 -0
  40. package/dist/snapshot/mysql.d.mts +5 -5
  41. package/dist/snapshot/mysql.mjs +32 -32
  42. package/dist/snapshot/postgres.d.mts +5 -5
  43. package/dist/snapshot/postgres.mjs +25 -25
  44. package/dist/snapshot/sqlite.d.mts +5 -5
  45. package/dist/snapshot/sqlite.mjs +30 -30
  46. package/dist/snapshot-mIb-Zzb5.mjs +1489 -0
  47. package/dist/snapshot.d.mts +4 -5
  48. package/dist/snapshot.mjs +3 -4
  49. package/dist/{source-SqrKWjFJ.mjs → source-DYSUqzvb.mjs} +2 -2
  50. package/dist/sqlite.d.mts +2 -2
  51. package/dist/sqlite.mjs +10 -10
  52. package/dist/{table-BwflqeAj.mjs → table-B8zEq0az.mjs} +4 -4
  53. package/dist/{types-BIJsj2fJ.mjs → types-CYHpSPwj.mjs} +10 -7
  54. package/dist/{types-CTCqtFlS.d.mts → types-CiMvKi5V.d.mts} +14 -4
  55. package/dist/{types-C0VkiwpR.d.mts → types-Dqr4o2I1.d.mts} +640 -189
  56. package/dist/value-CpaUFtjw.mjs +45 -0
  57. package/dist/vite/ambient.d.ts +2 -0
  58. package/dist/vite.d.mts +1 -1
  59. package/dist/vite.mjs +2 -0
  60. package/docs/dialects-and-execution.md +61 -11
  61. package/docs/getting-started.md +1 -1
  62. package/docs/guides/compose-queries.md +22 -0
  63. package/docs/guides/drizzle.md +11 -11
  64. package/docs/guides/extensions/typed-expressions.md +5 -3
  65. package/docs/guides/json.md +95 -2
  66. package/docs/guides/mutations.md +125 -0
  67. package/docs/guides/valtio-sync.md +113 -0
  68. package/docs/index.md +1 -1
  69. package/docs/migrations/adapters.md +58 -21
  70. package/docs/migrations/index.md +50 -12
  71. package/docs/migrations/operations.md +20 -6
  72. package/docs/migrations/recovery.md +7 -1
  73. package/docs/query-model/fragments.md +21 -1
  74. package/docs/reference/introspection-support.md +16 -18
  75. package/docs/reference/supported-surface.md +23 -11
  76. package/docs/schema/catalog-model.md +20 -7
  77. package/docs/schema/code-generation.md +4 -3
  78. package/docs/schema/diff.md +2 -2
  79. package/docs/schema/introspection.md +24 -16
  80. package/docs/schema/snapshots.md +18 -8
  81. package/docs/schema/storage-and-schema-sql.md +7 -2
  82. package/docs/sql-semantic-types.md +8 -0
  83. package/package.json +14 -1
  84. package/dist/canonical-DMvR9yBe.mjs +0 -972
  85. package/dist/column-Da37jYSD.mjs +0 -309
  86. package/dist/column-r1Y4ivwt.mjs +0 -327
  87. package/dist/complete-types-CY0KbzNw.d.mts +0 -371
  88. package/dist/index-B2rZf3-2.d.mts +0 -32
  89. package/dist/json-Db7XRD91.mjs +0 -169
  90. package/dist/omit-OxV58AwX.mjs +0 -5
  91. package/dist/registry-BRcUuazJ.mjs +0 -256
  92. package/dist/serialize-CEIIlWhC.d.mts +0 -66
  93. package/dist/snapshot-Xam8-q0j.mjs +0 -392
  94. package/dist/standard-DfcZEVOj.mjs +0 -12
  95. package/dist/value-D14I_XgL.mjs +0 -29
@@ -1,256 +0,0 @@
1
- import { t as standardDialect } from "./standard-DfcZEVOj.mjs";
2
- import { _ as isSchemaExpression, h as snakeCaseIdentifier, r as isColumnReference, x as markSchemaExpression, y as makeSchemaExpression } from "./column-r1Y4ivwt.mjs";
3
- import { n as isValueExpression } from "./value-D14I_XgL.mjs";
4
- //#region src/schema/expressions.ts
5
- /** Error raised before a schema expression can become persisted SQL. */
6
- var SchemaExpressionError = class extends TypeError {
7
- code;
8
- mode;
9
- constructor(code, message, mode) {
10
- super(message);
11
- this.name = "SchemaExpressionError";
12
- this.code = code;
13
- this.mode = mode;
14
- }
15
- };
16
- /**
17
- * Normalize only line endings. Whitespace, quoting, and every other byte of a raw schema expression
18
- * remain under the extension author's control.
19
- */
20
- function normalizeSchemaSql(sql) {
21
- return sql.replace(/\r\n?/g, "\n");
22
- }
23
- function schemaExpression(expression) {
24
- return markSchemaExpression(expression);
25
- }
26
- /**
27
- * Define an extension with the restricted schema context. This is the typed alternative to
28
- * {@link unsafeSchemaSql} for deterministic custom syntax.
29
- */
30
- function defineSchemaExpression(kind, render) {
31
- return makeSchemaExpression(kind, (context) => render(context));
32
- }
33
- function unsafeSchemaSql(dialectOrOptions, sql) {
34
- const dialect = typeof dialectOrOptions === "string" ? dialectOrOptions : dialectOrOptions.dialect;
35
- const source = typeof dialectOrOptions === "string" ? sql : dialectOrOptions.sql;
36
- if (!dialect) throw new TypeError("unsafeSchemaSql() requires a dialect tag");
37
- if (source === void 0) throw new TypeError("unsafeSchemaSql() requires SQL text");
38
- const normalized = normalizeSchemaSql(source);
39
- const expression = makeSchemaExpression("unsafe", (context) => context.append(normalized));
40
- return Object.freeze({
41
- ...expression,
42
- schemaSqlDialect: dialect,
43
- schemaSql: normalized
44
- });
45
- }
46
- /** Identify a dialect-tagged raw schema expression. */
47
- function isUnsafeSchemaSql(value) {
48
- return isSchemaExpression(value) && value.expressionKind === "unsafe" && typeof value.schemaSqlDialect === "string" && typeof value.schemaSql === "string";
49
- }
50
- function renderSchemaExpression(expression, optionsOrMode, dialectOption) {
51
- const options = typeof optionsOrMode === "string" ? {
52
- mode: optionsOrMode,
53
- dialect: dialectOption
54
- } : optionsOrMode;
55
- const dialect = options.dialect ?? standardDialect();
56
- if (!isSchemaExpression(expression)) throw new SchemaExpressionError("not-deterministic", "Only branded deterministic expressions can be rendered as schema SQL", options.mode);
57
- assertSupportedExpression(expression, options.mode);
58
- let text = "";
59
- const context = {
60
- dialect,
61
- projectionMode: "result",
62
- schemaMode: options.mode,
63
- append(value) {
64
- text += value;
65
- },
66
- parameter() {
67
- throw new SchemaExpressionError("parameter", "Schema expressions cannot render query parameters", options.mode);
68
- },
69
- literal(value) {
70
- text += renderSchemaLiteral(dialect, value, options.mode);
71
- },
72
- renderColumnReference(columnName) {
73
- if (options.mode === "default") throw new SchemaExpressionError("column-not-allowed", "Default expressions cannot reference table columns", options.mode);
74
- text += dialect.quoteIdentifier(columnName);
75
- },
76
- render(part) {
77
- renderSchemaPart(context, part, options.mode);
78
- },
79
- renderRelation() {
80
- throw new SchemaExpressionError("unsupported-expression", "Schema expressions cannot contain subqueries", options.mode);
81
- }
82
- };
83
- renderSchemaPart(context, expression, options.mode);
84
- return Object.freeze({
85
- text,
86
- parameters: Object.freeze([])
87
- });
88
- }
89
- /** Convenience form for callers that only need the SQL text. */
90
- function renderSchemaSql(expression, options) {
91
- return renderSchemaExpression(expression, options).text;
92
- }
93
- function renderSchemaPart(context, part, mode) {
94
- if (isValueExpression(part)) {
95
- context.literal(part.value);
96
- return;
97
- }
98
- if (isColumnReference(part)) {
99
- context.renderColumnReference(part.columnName);
100
- return;
101
- }
102
- if (isUnsafeSchemaSql(part)) {
103
- if (part.schemaSqlDialect !== context.dialect.name) throw new SchemaExpressionError("dialect-mismatch", `Schema SQL is tagged for "${part.schemaSqlDialect}" but rendered for "${context.dialect.name}"`, mode);
104
- context.append(part.schemaSql);
105
- return;
106
- }
107
- if (!isSchemaExpression(part)) throw new SchemaExpressionError("not-deterministic", "Schema expressions may only compose branded expressions, columns, and literals", mode);
108
- assertSupportedExpression(part, mode);
109
- part.render(context);
110
- }
111
- function assertSupportedExpression(expression, mode) {
112
- if (expression.expressionKind === "subquery" || expression.expressionCategory) throw new SchemaExpressionError("unsupported-expression", "Aggregates, windows, and subqueries are not valid schema expressions", mode);
113
- }
114
- function renderSchemaLiteral(dialect, value, mode) {
115
- if (dialect.renderSchemaLiteral) {
116
- const rendered = dialect.renderSchemaLiteral(value);
117
- if (typeof rendered !== "string" || rendered.includes("?")) throw new SchemaExpressionError("invalid-literal", "A schema literal renderer must return parameter-free SQL text", mode);
118
- return rendered;
119
- }
120
- if (value === null) return "NULL";
121
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
122
- if (typeof value === "string") return `'${value.replaceAll("'", "''")}'`;
123
- if (typeof value === "bigint") return String(value);
124
- if (typeof value === "number") {
125
- if (!Number.isFinite(value)) throw new SchemaExpressionError("unsupported-value", "Schema literals require finite numbers", mode);
126
- return Object.is(value, -0) ? "0" : String(value);
127
- }
128
- throw new SchemaExpressionError("unsupported-value", `Unsupported schema literal type: ${value === void 0 ? "undefined" : typeof value}`, mode);
129
- }
130
- //#endregion
131
- //#region src/schema/registry.ts
132
- /** The first naming-policy version used by schema metadata. */
133
- const schemaNamingPolicyVersion = 1;
134
- /**
135
- * The built-in naming policy for schema-generated physical names.
136
- *
137
- * Explicit names supplied to `table()` remain unchanged. The policy is used by tooling when it
138
- * needs a physical name for a logical table ID.
139
- */
140
- const defaultSchemaNamingPolicy = Object.freeze({
141
- version: 1,
142
- tableName: snakeCaseIdentifier
143
- });
144
- /** Error thrown when a root schema fails registry or naming validation. */
145
- var SchemaValidationError = class extends Error {
146
- name = "SchemaValidationError";
147
- diagnostics;
148
- /** Alias matching validation libraries that call findings "issues". */
149
- issues;
150
- constructor(diagnostics) {
151
- const frozenDiagnostics = Object.freeze(diagnostics.map((diagnostic) => Object.freeze({
152
- ...diagnostic,
153
- path: Object.freeze([...diagnostic.path]),
154
- relatedPaths: diagnostic.relatedPaths ? Object.freeze(diagnostic.relatedPaths.map((path) => Object.freeze([...path]))) : void 0
155
- })));
156
- super(frozenDiagnostics.map((diagnostic) => diagnostic.message).join("\n"));
157
- this.diagnostics = frozenDiagnostics;
158
- this.issues = frozenDiagnostics;
159
- }
160
- };
161
- function entriesOf(input) {
162
- if (Array.isArray(input)) return input;
163
- return Object.entries(input);
164
- }
165
- function validLogicalId(id) {
166
- return id.length > 0 && id === id.trim() && !/[.\\/\u0000-\u001f\u007f]/u.test(id);
167
- }
168
- function validNamespace(namespace) {
169
- return namespace.length > 0 && namespace === namespace.trim() && !/[.\\/\u0000-\u001f\u007f"']/u.test(namespace);
170
- }
171
- function validateEntries(entries, namespace, namingPolicy) {
172
- const diagnostics = [];
173
- const ids = /* @__PURE__ */ new Map();
174
- const physicalNames = /* @__PURE__ */ new Map();
175
- const generatedNames = /* @__PURE__ */ new Map();
176
- for (const [index, [id, table]] of entries.entries()) {
177
- const path = ["tables", id];
178
- const previousId = ids.get(id);
179
- if (previousId !== void 0) diagnostics.push({
180
- code: "duplicate-table-id",
181
- message: `Table ID "${id}" is declared more than once`,
182
- path,
183
- relatedPaths: [["tables", entries[previousId][0]]]
184
- });
185
- else ids.set(id, index);
186
- if (!validLogicalId(id)) diagnostics.push({
187
- code: "invalid-table-id",
188
- message: `Table ID "${id}" must be a non-empty logical identifier`,
189
- path
190
- });
191
- const physicalName = table.tableName || namingPolicy.tableName(id);
192
- const previousPhysicalName = physicalNames.get(physicalName);
193
- if (previousPhysicalName !== void 0) diagnostics.push({
194
- code: "duplicate-physical-name",
195
- message: `Tables "${entries[previousPhysicalName][0]}" and "${id}" both use physical name "${physicalName}"`,
196
- path: [...path, "physicalName"],
197
- relatedPaths: [[
198
- "tables",
199
- entries[previousPhysicalName][0],
200
- "physicalName"
201
- ]]
202
- });
203
- else physicalNames.set(physicalName, index);
204
- const generatedName = namingPolicy.tableName(id);
205
- const previousGeneratedName = generatedNames.get(generatedName);
206
- if (previousGeneratedName !== void 0) diagnostics.push({
207
- code: "generated-name-collision",
208
- message: `Logical table IDs "${entries[previousGeneratedName][0]}" and "${id}" generate the same physical name "${generatedName}"`,
209
- path: [...path, "generatedName"],
210
- relatedPaths: [[
211
- "tables",
212
- entries[previousGeneratedName][0],
213
- "generatedName"
214
- ]]
215
- });
216
- else generatedNames.set(generatedName, index);
217
- }
218
- if (namespace !== void 0 && !validNamespace(namespace)) diagnostics.push({
219
- code: "invalid-namespace",
220
- message: `Schema namespace "${namespace}" must be a non-empty identifier without qualification or control characters`,
221
- path: ["namespace"]
222
- });
223
- return Object.freeze(diagnostics);
224
- }
225
- function freezeTableNames(entries, namingPolicy) {
226
- return Object.freeze(Object.fromEntries(entries.map(([id, table]) => [id, table.tableName || namingPolicy.tableName(id)])));
227
- }
228
- function createSchema(entries, tables, options = {}) {
229
- const namingPolicy = options.namingPolicy ?? defaultSchemaNamingPolicy;
230
- const diagnostics = validateEntries(entries, options.namespace, namingPolicy);
231
- if (diagnostics.length > 0) throw new SchemaValidationError(diagnostics);
232
- const tableNames = freezeTableNames(entries, namingPolicy);
233
- const registry = Object.freeze(Object.fromEntries(entries.map(([id, table]) => [id, Object.freeze({
234
- id,
235
- table,
236
- physicalName: tableNames[id]
237
- })])));
238
- return Object.freeze({
239
- schemaKind: "schema",
240
- tables: Object.freeze({ ...tables }),
241
- registry,
242
- tableNames,
243
- namespace: options.namespace,
244
- namingPolicy: Object.freeze({ ...namingPolicy })
245
- });
246
- }
247
- function schema(tables, options) {
248
- const entries = entriesOf(tables);
249
- return createSchema(entries, Object.fromEntries(entries), options);
250
- }
251
- /** Generate a v1 physical name for a logical table ID. */
252
- function generatedTableName(logicalId, namingPolicy = defaultSchemaNamingPolicy) {
253
- return namingPolicy.tableName(logicalId);
254
- }
255
- //#endregion
256
- export { schemaNamingPolicyVersion as a, isUnsafeSchemaSql as c, renderSchemaSql as d, schemaExpression as f, schema as i, normalizeSchemaSql as l, defaultSchemaNamingPolicy as n, SchemaExpressionError as o, unsafeSchemaSql as p, generatedTableName as r, defineSchemaExpression as s, SchemaValidationError as t, renderSchemaExpression as u };
@@ -1,66 +0,0 @@
1
- import { T as SnapshotJsonValue, Tr as SchemaDialect, Ur as Schema, f as SnapshotDiagnostic, i as SchemaSnapshotInput, l as SnapshotCreateResult, n as SchemaSnapshot, r as SchemaSnapshotAdapter, u as SnapshotDecodeResult } from "./types-C0VkiwpR.mjs";
2
- //#region src/snapshot/canonical.d.ts
3
- /** Error raised when a value cannot cross the canonical JSON boundary. */
4
- declare class SnapshotCanonicalError extends TypeError {
5
- readonly path: readonly (string | number)[];
6
- constructor(message: string, path?: readonly (string | number)[]);
7
- }
8
- /** Convert a JavaScript value to the explicit JSON-safe snapshot domain. */
9
- declare function toSnapshotJsonValue(value: unknown, path?: readonly (string | number)[], seen?: WeakSet<object>): SnapshotJsonValue;
10
- /** Render a JSON-safe value with deterministic scalar and object handling. */
11
- declare function canonicalJson(value: SnapshotJsonValue): string;
12
- /** Canonical JSON for a schema snapshot after fixed-order reconstruction. */
13
- declare function encodeCanonicalSnapshot(snapshot: SchemaSnapshot): string;
14
- /**
15
- * Compute a small deterministic content fingerprint for cache keys and diagnostics. It is
16
- * deliberately not an entity identity, signature, or migration lineage.
17
- */
18
- declare function schemaSnapshotFingerprint(snapshot: SchemaSnapshotInput | string): string;
19
- //#endregion
20
- //#region src/snapshot/decode.d.ts
21
- /** Error raised by throwing snapshot APIs after collecting diagnostics. */
22
- declare class SnapshotValidationError extends TypeError {
23
- readonly name: string;
24
- readonly diagnostics: readonly SnapshotDiagnostic[];
25
- readonly issues: readonly SnapshotDiagnostic[];
26
- constructor(diagnostics: readonly SnapshotDiagnostic[]);
27
- }
28
- /** Decode and strictly validate a JSON string or parsed snapshot value. */
29
- declare function decodeSchemaSnapshot(input: string | unknown): SnapshotDecodeResult;
30
- /** Validate a snapshot and throw one structured error if it is malformed. */
31
- declare function assertSchemaSnapshot(input: SchemaSnapshotInput | string): SchemaSnapshot;
32
- /** Return a fixed-order, deeply immutable copy of a valid snapshot. */
33
- declare function canonicalizeSchemaSnapshot(input: SchemaSnapshotInput): SchemaSnapshot;
34
- //#endregion
35
- //#region src/snapshot/serialize.d.ts
36
- /** Error raised when a live Qubu schema cannot be represented as a snapshot. */
37
- declare class SnapshotSerializationError extends SnapshotValidationError {
38
- readonly name = "SnapshotSerializationError";
39
- }
40
- /** Options for the neutral traversal and a future dialect adapter. */
41
- interface SchemaSnapshotOptions {
42
- readonly adapter?: SchemaSnapshotAdapter;
43
- readonly dialect?: SchemaDialect;
44
- /** Explicit hook overrides retained for custom tooling integrations. */
45
- readonly expressionEncoder?: SchemaDialect["schema"]["encodeExpression"];
46
- readonly storageEncoder?: SchemaDialect["schema"]["encodeStorage"];
47
- readonly extensionEncoder?: SchemaDialect["schema"]["encodeDialectExtension"];
48
- readonly namingPolicy?: {
49
- readonly name: string;
50
- readonly version?: number;
51
- };
52
- }
53
- /** Create a neutral or adapter-owned immutable snapshot from a live schema. */
54
- declare function createSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: SchemaSnapshotOptions): SchemaSnapshot;
55
- /** Non-throwing form of {@link createSchemaSnapshot}. */
56
- declare function tryCreateSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: SchemaSnapshotOptions): SnapshotCreateResult;
57
- /** Encode a valid snapshot using fixed property order and canonical JSON. */
58
- declare function encodeSchemaSnapshot(snapshot: SchemaSnapshot): string;
59
- /** Alias used by tooling packages that call the operation serialization. */
60
- declare const serializeSchema: typeof createSchemaSnapshot;
61
- /** Alias for the canonical snapshot encoder. */
62
- declare const encodeSnapshot: typeof encodeSchemaSnapshot;
63
- /** Alias for the canonical snapshot fingerprint helper. */
64
- declare const fingerprintSchemaSnapshot: typeof schemaSnapshotFingerprint;
65
- //#endregion
66
- export { toSnapshotJsonValue as _, encodeSnapshot as a, tryCreateSchemaSnapshot as c, canonicalizeSchemaSnapshot as d, decodeSchemaSnapshot as f, schemaSnapshotFingerprint as g, encodeCanonicalSnapshot as h, encodeSchemaSnapshot as i, SnapshotValidationError as l, canonicalJson as m, SnapshotSerializationError as n, fingerprintSchemaSnapshot as o, SnapshotCanonicalError as p, createSchemaSnapshot as r, serializeSchema as s, SchemaSnapshotOptions as t, assertSchemaSnapshot as u };