qubu 0.3.5 → 0.4.1
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/{canonical-BbnqavJm.mjs → canonical-BXUguqfo.mjs} +23 -23
- package/dist/codegen.d.mts +25 -33
- package/dist/codegen.mjs +38 -45
- package/dist/column-hqKr7-1I.mjs +620 -0
- package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
- package/dist/{complete-types-B2PO6wQD.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +4 -4
- package/dist/ddl.d.mts +12 -12
- package/dist/ddl.mjs +13 -14
- package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
- package/dist/diff.d.mts +1 -1
- package/dist/diff.mjs +6 -7
- package/dist/{index-7qc6OcIC.d.mts → index-1DpA3mUh.d.mts} +20 -20
- package/dist/{index-CqWnouTK.d.mts → index-CPvfEheG.d.mts} +13 -15
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +148 -120
- package/dist/introspection.d.mts +8 -8
- package/dist/introspection.mjs +29 -30
- package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
- package/dist/migration.d.mts +20 -21
- package/dist/migration.mjs +5 -6
- package/dist/{mysql-DqkqXB6A.mjs → mysql-B_cYzzX2.mjs} +237 -7
- package/dist/mysql.d.mts +1 -1
- package/dist/mysql.mjs +3 -3
- package/dist/{on-conflict-BxnxubMb.mjs → on-conflict-hfPW0KmQ.mjs} +4 -4
- package/dist/postgres.d.mts +5 -5
- package/dist/postgres.mjs +6 -6
- package/dist/{registry-BufIskVN.mjs → registry-BRMLYwDp.mjs} +27 -135
- package/dist/{relational-DCZrrNia.mjs → relational-BZ3WDPzC.mjs} +4 -4
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +6 -6
- package/dist/{snapshot-CWPgzxNx.mjs → snapshot-C-W65HEd.mjs} +5 -5
- package/dist/snapshot.d.mts +3 -3
- package/dist/snapshot.mjs +5 -7
- package/dist/{source-DUoJVXmL.mjs → source-BcS2AsIg.mjs} +7 -9
- package/dist/{serialize-PF1cfH2P.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
- package/dist/sqlite.d.mts +2 -2
- package/dist/sqlite.mjs +2 -2
- package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
- package/dist/{table-CCUJ60rB.mjs → table-Bp5irMSj.mjs} +5 -7
- package/dist/{types-D8M1yZF4.d.mts → types-BK1COGZe.d.mts} +2661 -2150
- package/dist/{types-Cec0xzo4.mjs → types-JM3FcAnX.mjs} +8 -8
- package/dist/{types-LBt5rclR.d.mts → types-JSZHpUEj.d.mts} +83 -84
- package/dist/{value-BvilP0oz.mjs → value-Bi71Agyf.mjs} +1 -1
- package/dist/vite/ambient.d.ts +311 -390
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/docs/dialects-and-execution.md +121 -81
- package/docs/getting-started.md +4 -4
- package/docs/guides/better-auth.md +57 -0
- package/docs/guides/compose-queries.md +24 -67
- package/docs/guides/drizzle.md +23 -23
- package/docs/guides/extensions/dialects.md +4 -4
- package/docs/guides/extensions/sources-and-clauses.md +15 -15
- package/docs/guides/extensions/typed-expressions.md +13 -17
- package/docs/guides/extensions/unsafe-syntax.md +3 -3
- package/docs/guides/json.md +7 -7
- package/docs/guides/mutations.md +14 -21
- package/docs/guides/select/conditions.md +6 -8
- package/docs/guides/select/grouping-and-windows.md +4 -15
- package/docs/guides/select/ordering-and-pagination.md +6 -19
- package/docs/guides/select/overview.md +12 -26
- package/docs/guides/sql-templates.md +20 -24
- package/docs/guides/vite-plugin.md +9 -13
- package/docs/index.md +5 -7
- package/docs/query-model/fragments.md +4 -15
- package/docs/query-model/result-shapes.md +11 -14
- package/docs/query-model/source-scope.md +31 -49
- package/docs/reference/mysql-snapshot.md +2 -5
- package/docs/reference/postgres-snapshot.md +3 -3
- package/docs/reference/sqlite-snapshot.md +2 -5
- package/docs/reference/supported-surface.md +33 -33
- package/docs/schema/catalog-model.md +2 -5
- package/docs/schema/code-generation.md +18 -18
- package/docs/schema/columns-and-writes.md +17 -25
- package/docs/schema/constraints-and-indexes.md +36 -52
- package/docs/schema/ddl-emission.md +6 -6
- package/docs/schema/diff.md +5 -5
- package/docs/schema/introspection.md +7 -7
- package/docs/schema/migration-plans.md +9 -9
- package/docs/schema/snapshots.md +3 -3
- package/docs/schema/storage-and-schema-sql.md +11 -11
- package/docs/schema/tables-and-names.md +11 -14
- package/docs/sql-semantic-types.md +10 -10
- package/docs/troubleshooting.md +10 -10
- package/package.json +21 -33
- package/skills/qubu/agents/openai.yaml +3 -3
- package/dist/column-CXMxx8Hq.mjs +0 -118
- package/dist/column-CYMbKbOy.mjs +0 -290
- package/dist/drizzle-mysql.d.mts +0 -24
- package/dist/drizzle-mysql.mjs +0 -72
- package/dist/drizzle-postgres.d.mts +0 -24
- package/dist/drizzle-postgres.mjs +0 -73
- package/dist/drizzle-sqlite.d.mts +0 -50
- package/dist/drizzle-sqlite.mjs +0 -108
- package/dist/drizzle.d.mts +0 -13
- package/dist/drizzle.mjs +0 -2
- package/dist/errors-BGCoLe_r.mjs +0 -14
- package/dist/naming-QVCOnSj2.mjs +0 -20
- package/dist/postgres-DEBBeh52.mjs +0 -235
- package/dist/runtime-Cn_Xgzta.mjs +0 -193
- package/dist/sqlite-BU6DBxef.mjs +0 -320
- package/dist/types-Ctlxz1ip.d.mts +0 -45
package/docs/troubleshooting.md
CHANGED
|
@@ -12,9 +12,9 @@ Check that the query includes the original source or use the columns exposed by
|
|
|
12
12
|
the alias, CTE, or derived table you actually placed in the query:
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
import { alias, from, select } from
|
|
15
|
+
import { alias, from, select } from "qubu"
|
|
16
16
|
|
|
17
|
-
const author = alias(users,
|
|
17
|
+
const author = alias(users, "author")
|
|
18
18
|
|
|
19
19
|
select({ name: author.name }, from(author))
|
|
20
20
|
```
|
|
@@ -27,9 +27,9 @@ identity after aliasing.
|
|
|
27
27
|
This is the default mutation safety check. Add a source-aware predicate:
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import { deleteFrom, eq, update, where } from
|
|
30
|
+
import { deleteFrom, eq, update, where } from "qubu"
|
|
31
31
|
|
|
32
|
-
update(users, { name:
|
|
32
|
+
update(users, { name: "Ada" }, where(eq(users.id, 7)))
|
|
33
33
|
deleteFrom(users, where(eq(users.id, 8)))
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -43,7 +43,7 @@ A scalar subquery must return one selected field. Reduce the projection before
|
|
|
43
43
|
calling `scalar()`:
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
import { from, scalar, select } from
|
|
46
|
+
import { from, scalar, select } from "qubu"
|
|
47
47
|
|
|
48
48
|
const idQuery = select({ id: users.id }, from(users))
|
|
49
49
|
const idExpression = scalar(idQuery)
|
|
@@ -58,8 +58,8 @@ Render with the dialect that the adapter expects and inspect both fields of the
|
|
|
58
58
|
result:
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import { render } from
|
|
62
|
-
import { postgresDialect } from
|
|
61
|
+
import { render } from "qubu"
|
|
62
|
+
import { postgresDialect } from "qubu/postgres"
|
|
63
63
|
|
|
64
64
|
const statement = render(query, postgresDialect())
|
|
65
65
|
console.log(statement.text)
|
|
@@ -78,7 +78,7 @@ path, and hint before changing the query. The hint names the repair boundary;
|
|
|
78
78
|
the path points to the clause or field that needs attention.
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
|
-
import { QueryValidationError, fetchFirst } from
|
|
81
|
+
import { QueryValidationError, fetchFirst } from "qubu"
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
84
|
fetchFirst(-1)
|
|
@@ -140,10 +140,10 @@ placement. Rendering traverses that normalized statement, so inspect the final
|
|
|
140
140
|
`text` and `parameters` together rather than assuming source argument order:
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
|
-
import { eq, fetchFirst, from, render, select, where } from
|
|
143
|
+
import { eq, fetchFirst, from, render, select, where } from "qubu"
|
|
144
144
|
|
|
145
145
|
const statement = render(
|
|
146
|
-
select({ id: users.id }, from(users), where(eq(users.id, 7)), fetchFirst(10))
|
|
146
|
+
select({ id: users.id }, from(users), where(eq(users.id, 7)), fetchFirst(10)),
|
|
147
147
|
)
|
|
148
148
|
```
|
|
149
149
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qubu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/aleclarson/qubu"
|
|
7
7
|
},
|
|
8
|
-
"type": "module",
|
|
9
8
|
"files": [
|
|
10
9
|
"dist",
|
|
11
10
|
"docs",
|
|
12
11
|
"skills"
|
|
13
12
|
],
|
|
13
|
+
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/index.d.mts",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"types": "./dist/diff.d.mts",
|
|
33
33
|
"import": "./dist/diff.mjs"
|
|
34
34
|
},
|
|
35
|
-
"./drizzle": {
|
|
36
|
-
"types": "./dist/drizzle.d.mts",
|
|
37
|
-
"import": "./dist/drizzle.mjs"
|
|
38
|
-
},
|
|
39
35
|
"./introspection": {
|
|
40
36
|
"types": "./dist/introspection.d.mts",
|
|
41
37
|
"import": "./dist/introspection.mjs"
|
|
@@ -69,34 +65,29 @@
|
|
|
69
65
|
"import": "./dist/vite.mjs"
|
|
70
66
|
},
|
|
71
67
|
"./package.json": "./package.json",
|
|
72
|
-
"./drizzle/mysql": {
|
|
73
|
-
"types": "./dist/drizzle-mysql.d.mts",
|
|
74
|
-
"import": "./dist/drizzle-mysql.mjs"
|
|
75
|
-
},
|
|
76
|
-
"./drizzle/postgres": {
|
|
77
|
-
"types": "./dist/drizzle-postgres.d.mts",
|
|
78
|
-
"import": "./dist/drizzle-postgres.mjs"
|
|
79
|
-
},
|
|
80
|
-
"./drizzle/sqlite": {
|
|
81
|
-
"types": "./dist/drizzle-sqlite.d.mts",
|
|
82
|
-
"import": "./dist/drizzle-sqlite.mjs"
|
|
83
|
-
},
|
|
84
68
|
"./globals": {
|
|
85
69
|
"types": "./dist/vite/ambient.d.ts"
|
|
86
70
|
}
|
|
87
71
|
},
|
|
88
|
-
"
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@standard-schema/spec": "^1.0.0"
|
|
74
|
+
},
|
|
89
75
|
"devDependencies": {
|
|
90
76
|
"@alloc/prettier-config": "^1.0.0",
|
|
77
|
+
"@electric-sql/pglite": "^0.5.8",
|
|
78
|
+
"@libsql/client": "^0.17.4",
|
|
91
79
|
"@pg-nano/pg-tmp": "^2.0.3",
|
|
80
|
+
"@stylistic/eslint-plugin": "^6.0.0-beta.6",
|
|
92
81
|
"@types/bun": "^1.3.0",
|
|
93
82
|
"@types/node": "^24.6.2",
|
|
94
83
|
"@types/pg": "^8.23.1",
|
|
95
|
-
"drizzle-orm": "1.0.0-rc.4",
|
|
96
84
|
"lildocs": "^0.1.27",
|
|
97
85
|
"mysql2": "^3.23.4",
|
|
86
|
+
"oxfmt": "^0.58.0",
|
|
87
|
+
"oxlint": "1.73.0",
|
|
98
88
|
"pg": "^8.23.0",
|
|
99
89
|
"picospawn": "^0.3.10",
|
|
90
|
+
"postgres": "^3.4.9",
|
|
100
91
|
"prettier": "^3.6.2",
|
|
101
92
|
"qubu": "link:",
|
|
102
93
|
"radashi": "^12.6.2",
|
|
@@ -106,30 +97,27 @@
|
|
|
106
97
|
"typescript": "^5.9.3",
|
|
107
98
|
"vitest": "^3.2.4"
|
|
108
99
|
},
|
|
109
|
-
"
|
|
110
|
-
"@standard-schema/spec": "^1.0.0"
|
|
111
|
-
},
|
|
112
|
-
"peerDependencies": {
|
|
113
|
-
"drizzle-orm": "^1.0.0-rc.4"
|
|
114
|
-
},
|
|
115
|
-
"peerDependenciesMeta": {
|
|
116
|
-
"drizzle-orm": {
|
|
117
|
-
"optional": true
|
|
118
|
-
}
|
|
119
|
-
},
|
|
100
|
+
"prettier": "@alloc/prettier-config",
|
|
120
101
|
"scripts": {
|
|
121
102
|
"build": "tsdown",
|
|
103
|
+
"build:workspace-packages": "pnpm --recursive --filter './adapters/*' build",
|
|
122
104
|
"check:package": "node ./scripts/test-package.mjs --check-built",
|
|
105
|
+
"check:workspace-versions": "node ./scripts/set-release-version.mjs --check",
|
|
123
106
|
"playground": "bun run ./playground/playground.ts",
|
|
124
107
|
"test": "vitest",
|
|
125
|
-
"test:e2e": "vitest --run test/e2e
|
|
108
|
+
"test:e2e": "vitest --run test/e2e",
|
|
126
109
|
"test:type-performance": "node ./scripts/test-type-performance.mjs",
|
|
127
110
|
"diff-check": "vitest --run test/diff.test.ts test/migration.test.ts",
|
|
128
111
|
"test:bun": "node ./scripts/test-package.mjs --runtime=bun",
|
|
129
112
|
"test:package": "node ./scripts/test-package.mjs",
|
|
113
|
+
"test:workspace-children": "pnpm --recursive --filter './adapters/*' build && node ./scripts/test-workspace-packages.mjs",
|
|
114
|
+
"test:workspace-packages": "pnpm run test:package && pnpm run test:workspace-children",
|
|
130
115
|
"test:package:node": "node ./scripts/test-package.mjs --runtime=node",
|
|
131
116
|
"typecheck": "vitest --typecheck --run",
|
|
117
|
+
"typecheck:workspace-packages": "pnpm --recursive --filter './adapters/*' typecheck",
|
|
132
118
|
"typecheck:playground": "tsc --project ./playground/tsconfig.json",
|
|
133
|
-
"
|
|
119
|
+
"format": "oxlint --fix && oxfmt",
|
|
120
|
+
"release:version": "node ./scripts/set-release-version.mjs",
|
|
121
|
+
"release:publish": "node ./scripts/publish-workspace.mjs"
|
|
134
122
|
}
|
|
135
123
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
interface:
|
|
2
|
-
display_name:
|
|
3
|
-
short_description:
|
|
4
|
-
default_prompt:
|
|
2
|
+
display_name: "Qubu"
|
|
3
|
+
short_description: "Route Qubu work to package docs"
|
|
4
|
+
default_prompt: "Use $qubu to find the smallest canonical Qubu guide for this task."
|
|
5
5
|
policy:
|
|
6
6
|
allow_implicit_invocation: true
|
package/dist/column-CXMxx8Hq.mjs
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { a as assertDialectCapability } from "./json-CUZlv4HT.mjs";
|
|
2
|
-
//#region src/core/fragment.ts
|
|
3
|
-
function fragment(render) {
|
|
4
|
-
return Object.freeze({ render });
|
|
5
|
-
}
|
|
6
|
-
function sequence(parts, separator = " ") {
|
|
7
|
-
return fragment((context) => {
|
|
8
|
-
let first = true;
|
|
9
|
-
for (const part of parts) {
|
|
10
|
-
if (!first) context.append(separator);
|
|
11
|
-
context.render(part);
|
|
12
|
-
first = false;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function parenthesize(part) {
|
|
17
|
-
return fragment((context) => {
|
|
18
|
-
context.append("(");
|
|
19
|
-
context.render(part);
|
|
20
|
-
context.append(")");
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function isFragment(value) {
|
|
24
|
-
return typeof value === "object" && value !== null && "render" in value && typeof value.render === "function";
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/expressions/types.ts
|
|
28
|
-
/** Runtime/type-level proof that an expression is safe to use in schema SQL. */
|
|
29
|
-
const schemaExpressionBrand = Symbol("qubu.schema-expression");
|
|
30
|
-
/** Add a concrete dialect requirement without dropping expression metadata. */
|
|
31
|
-
function withDialectCapability(expression, capability) {
|
|
32
|
-
const wrapped = makeExpression(expression.expressionKind, (context) => {
|
|
33
|
-
assertDialectCapability(context.dialect, capability);
|
|
34
|
-
context.render(expression);
|
|
35
|
-
});
|
|
36
|
-
return isSchemaExpression(expression) ? markSchemaExpression(wrapped) : wrapped;
|
|
37
|
-
}
|
|
38
|
-
function makeExpression(expressionKind, render, expressionCategory) {
|
|
39
|
-
return Object.freeze({
|
|
40
|
-
expressionKind,
|
|
41
|
-
...expressionCategory ? { expressionCategory } : {},
|
|
42
|
-
...fragment(render)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/** Mark a query-only expression category without changing its SQL renderer. */
|
|
46
|
-
function markExpressionCategory(expression, category) {
|
|
47
|
-
return Object.freeze({
|
|
48
|
-
...expression,
|
|
49
|
-
expressionCategory: category
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Mark a built-in or explicitly audited renderer as schema-deterministic.
|
|
54
|
-
* Prefer {@link defineSchemaExpression} for application extensions because it
|
|
55
|
-
* supplies a restricted schema rendering context.
|
|
56
|
-
*/
|
|
57
|
-
function makeSchemaExpression(expressionKind, render) {
|
|
58
|
-
const expression = makeExpression(expressionKind, render);
|
|
59
|
-
return Object.freeze({
|
|
60
|
-
...expression,
|
|
61
|
-
[schemaExpressionBrand]: true
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/** Add the schema-determinism brand to an explicitly audited expression. */
|
|
65
|
-
function markSchemaExpression(expression) {
|
|
66
|
-
if (isSchemaExpression(expression)) return expression;
|
|
67
|
-
return Object.freeze({
|
|
68
|
-
...expression,
|
|
69
|
-
[schemaExpressionBrand]: true
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/** Test the runtime brand used by schema rendering and validation. */
|
|
73
|
-
function isSchemaExpression(value) {
|
|
74
|
-
return typeof value === "object" && value !== null && schemaExpressionBrand in value && value[schemaExpressionBrand] === true;
|
|
75
|
-
}
|
|
76
|
-
function isExpression(value) {
|
|
77
|
-
return typeof value === "object" && value !== null && "expressionKind" in value && "render" in value && typeof value.render === "function";
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/core/primitives/identifier.ts
|
|
81
|
-
function identifier(name) {
|
|
82
|
-
return fragment((context) => context.append(context.dialect.quoteIdentifier(name)));
|
|
83
|
-
}
|
|
84
|
-
function qualifiedIdentifier(...parts) {
|
|
85
|
-
return fragment((context) => {
|
|
86
|
-
parts.forEach((part, index) => {
|
|
87
|
-
if (index > 0) context.append(".");
|
|
88
|
-
context.append(context.dialect.quoteIdentifier(part));
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/expressions/column.ts
|
|
94
|
-
function createColumnReference(columnName, sourceReference, fieldName) {
|
|
95
|
-
const expression = makeSchemaExpression("column", (context) => {
|
|
96
|
-
if (context.renderColumnReference) {
|
|
97
|
-
context.renderColumnReference(columnName);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
context.render(sourceReference);
|
|
101
|
-
context.append(".");
|
|
102
|
-
context.render(identifier(columnName));
|
|
103
|
-
});
|
|
104
|
-
return Object.freeze({
|
|
105
|
-
...expression,
|
|
106
|
-
fieldName,
|
|
107
|
-
columnName
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function isColumnReference(value) {
|
|
111
|
-
return typeof value === "object" && value !== null && "expressionKind" in value && value.expressionKind === "column";
|
|
112
|
-
}
|
|
113
|
-
/** Turn an expression into a fragment that renders it without changing it. */
|
|
114
|
-
function expressionFragment(expression) {
|
|
115
|
-
return fragment((context) => context.render(expression));
|
|
116
|
-
}
|
|
117
|
-
//#endregion
|
|
118
|
-
export { qualifiedIdentifier as a, makeExpression as c, markSchemaExpression as d, withDialectCapability as f, sequence as g, parenthesize as h, identifier as i, makeSchemaExpression as l, isFragment as m, expressionFragment as n, isExpression as o, fragment as p, isColumnReference as r, isSchemaExpression as s, createColumnReference as t, markExpressionCategory as u };
|
package/dist/column-CYMbKbOy.mjs
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { s as isSchemaExpression } from "./column-CXMxx8Hq.mjs";
|
|
2
|
-
import { O as freezeSchemaMetadata } from "./registry-BufIskVN.mjs";
|
|
3
|
-
//#region src/schema/column-behavior.ts
|
|
4
|
-
/** A column behavior error with a stable code and optional property path. */
|
|
5
|
-
var ColumnBehaviorError = class extends TypeError {
|
|
6
|
-
code;
|
|
7
|
-
path;
|
|
8
|
-
constructor(code, message, path) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = "ColumnBehaviorError";
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.path = path;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/** Build a canonical literal node from a supported JavaScript scalar. */
|
|
16
|
-
function canonicalLiteral(value) {
|
|
17
|
-
if (value === null) return Object.freeze({ kind: "null" });
|
|
18
|
-
if (typeof value === "boolean") return Object.freeze({
|
|
19
|
-
kind: "boolean",
|
|
20
|
-
value
|
|
21
|
-
});
|
|
22
|
-
if (typeof value === "string") return Object.freeze({
|
|
23
|
-
kind: "string",
|
|
24
|
-
value
|
|
25
|
-
});
|
|
26
|
-
if (typeof value === "bigint") return Object.freeze({
|
|
27
|
-
kind: "bigint",
|
|
28
|
-
value: String(value)
|
|
29
|
-
});
|
|
30
|
-
if (!Number.isFinite(value)) throw new ColumnBehaviorError("invalid-default", "Default literal numbers must be finite", "default.value");
|
|
31
|
-
return Object.freeze({
|
|
32
|
-
kind: "number",
|
|
33
|
-
value: Object.is(value, -0) ? "0" : String(value)
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function literalDefault(value) {
|
|
37
|
-
return Object.freeze({
|
|
38
|
-
kind: "literal",
|
|
39
|
-
value: canonicalLiteral(value)
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/** Normalize a public default input into its canonical snapshot descriptor. */
|
|
43
|
-
function normalizeDefault(value) {
|
|
44
|
-
if (isSchemaExpression(value)) return Object.freeze({
|
|
45
|
-
kind: "expression",
|
|
46
|
-
expression: value
|
|
47
|
-
});
|
|
48
|
-
if (isExternalDefaultDescriptor(value)) return externalDefault();
|
|
49
|
-
return literalDefault(value);
|
|
50
|
-
}
|
|
51
|
-
/** Mark a legacy or externally managed database default explicitly. */
|
|
52
|
-
function externalDefault() {
|
|
53
|
-
return Object.freeze({ kind: "external" });
|
|
54
|
-
}
|
|
55
|
-
/** Create an immutable generated-column descriptor. */
|
|
56
|
-
function generatedColumn(expression, mode) {
|
|
57
|
-
assertSchemaExpression(expression, "generatedColumn.expression", "invalid-generated-column");
|
|
58
|
-
const resolvedMode = typeof mode === "string" ? mode : mode?.mode ?? "stored";
|
|
59
|
-
if (resolvedMode !== "stored" && resolvedMode !== "virtual") throw new ColumnBehaviorError("invalid-generated-column", `Generated-column mode must be "stored" or "virtual", received "${String(resolvedMode)}"`, "generatedColumn.mode");
|
|
60
|
-
return Object.freeze({
|
|
61
|
-
kind: "expression",
|
|
62
|
-
expression,
|
|
63
|
-
mode: resolvedMode
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/** Mark a legacy or externally managed generated column explicitly. */
|
|
67
|
-
function externalGeneratedColumn() {
|
|
68
|
-
return Object.freeze({ kind: "external" });
|
|
69
|
-
}
|
|
70
|
-
/** Describe a database identity column without inventing a generated SQL expression. */
|
|
71
|
-
function identityColumn(generation, options) {
|
|
72
|
-
const resolvedGeneration = generation ?? "by-default";
|
|
73
|
-
if (resolvedGeneration !== "always" && resolvedGeneration !== "by-default") throw new ColumnBehaviorError("invalid-identity", `Identity generation must be "always" or "by-default", received "${String(resolvedGeneration)}"`, "identity.generation");
|
|
74
|
-
return Object.freeze({
|
|
75
|
-
kind: "identity",
|
|
76
|
-
generation: resolvedGeneration,
|
|
77
|
-
...options?.dialect === void 0 ? {} : { dialect: freezeSchemaMetadata(options.dialect) }
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/** Normalize complete and legacy column behavior into immutable metadata. */
|
|
81
|
-
function resolveColumnBehavior(options) {
|
|
82
|
-
const hasDefaultFlag = options.hasDefault === true;
|
|
83
|
-
const generatedFlag = options.generated === true;
|
|
84
|
-
const defaultDescriptor = options.default === void 0 ? void 0 : normalizeDefault(options.default);
|
|
85
|
-
const generatedDescriptor = options.generatedColumn;
|
|
86
|
-
const identityDescriptor = options.identity;
|
|
87
|
-
const onUpdateExpression = options.onUpdate;
|
|
88
|
-
if (onUpdateExpression !== void 0 && !isSchemaExpression(onUpdateExpression)) throw new ColumnBehaviorError("invalid-on-update", "Column onUpdate metadata must carry the deterministic schema-expression brand", "onUpdate");
|
|
89
|
-
if (defaultDescriptor !== void 0) {
|
|
90
|
-
assertDefaultDescriptor(defaultDescriptor);
|
|
91
|
-
if (options.hasDefault === false) throw new ColumnBehaviorError("default-flag-conflict", "A complete default descriptor cannot be combined with hasDefault: false", "hasDefault");
|
|
92
|
-
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");
|
|
93
|
-
if (generatedFlag) throw new ColumnBehaviorError("default-generated-conflict", "A complete default descriptor cannot be combined with generated: true", "default");
|
|
94
|
-
}
|
|
95
|
-
if (generatedDescriptor !== void 0) {
|
|
96
|
-
assertGeneratedColumnDescriptor(generatedDescriptor);
|
|
97
|
-
if (options.generated === false) throw new ColumnBehaviorError("generated-flag-conflict", "A complete generated-column descriptor cannot be combined with generated: false", "generated");
|
|
98
|
-
if (identityDescriptor !== void 0) throw new ColumnBehaviorError("identity-generated-conflict", "A column cannot declare both generated-column and identity metadata", "generatedColumn");
|
|
99
|
-
if (hasDefaultFlag) throw new ColumnBehaviorError("default-generated-conflict", "A complete generated-column descriptor cannot be combined with hasDefault: true", "generatedColumn");
|
|
100
|
-
}
|
|
101
|
-
if (identityDescriptor !== void 0) {
|
|
102
|
-
assertIdentityDescriptor(identityDescriptor);
|
|
103
|
-
if (options.generated === false) throw new ColumnBehaviorError("generated-flag-conflict", "Identity metadata cannot be combined with generated: false", "generated");
|
|
104
|
-
if (hasDefaultFlag) throw new ColumnBehaviorError("identity-generated-conflict", "Identity metadata cannot be combined with hasDefault: true", "identity");
|
|
105
|
-
}
|
|
106
|
-
const normalizedDefault = defaultDescriptor === void 0 ? void 0 : freezeDefaultDescriptor(defaultDescriptor);
|
|
107
|
-
const normalizedGenerated = generatedDescriptor === void 0 ? void 0 : freezeGeneratedColumnDescriptor(generatedDescriptor);
|
|
108
|
-
const normalizedIdentity = identityDescriptor === void 0 ? void 0 : freezeIdentityDescriptor(identityDescriptor);
|
|
109
|
-
return Object.freeze({
|
|
110
|
-
hasDefault: hasDefaultFlag || normalizedDefault !== void 0,
|
|
111
|
-
generated: generatedFlag || normalizedGenerated !== void 0 || normalizedIdentity !== void 0,
|
|
112
|
-
default: normalizedDefault ?? (hasDefaultFlag ? externalDefault() : void 0),
|
|
113
|
-
generatedColumn: normalizedGenerated ?? (generatedFlag && normalizedIdentity === void 0 ? externalGeneratedColumn() : void 0),
|
|
114
|
-
identity: normalizedIdentity,
|
|
115
|
-
onUpdate: onUpdateExpression
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function freezeDefaultDescriptor(value) {
|
|
119
|
-
if (value.kind === "external") return externalDefault();
|
|
120
|
-
if (value.kind === "expression") return Object.freeze({
|
|
121
|
-
kind: "expression",
|
|
122
|
-
expression: value.expression
|
|
123
|
-
});
|
|
124
|
-
return Object.freeze({
|
|
125
|
-
kind: "literal",
|
|
126
|
-
value: Object.freeze({ ...value.value })
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function isExternalDefaultDescriptor(value) {
|
|
130
|
-
return typeof value === "object" && value !== null && value.kind === "external";
|
|
131
|
-
}
|
|
132
|
-
function freezeGeneratedColumnDescriptor(value) {
|
|
133
|
-
if (value.kind === "external") return externalGeneratedColumn();
|
|
134
|
-
return Object.freeze({
|
|
135
|
-
kind: "expression",
|
|
136
|
-
expression: value.expression,
|
|
137
|
-
mode: value.mode
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
function freezeIdentityDescriptor(value) {
|
|
141
|
-
return Object.freeze({
|
|
142
|
-
kind: "identity",
|
|
143
|
-
generation: value.generation,
|
|
144
|
-
...value.dialect === void 0 ? {} : { dialect: freezeSchemaMetadata(value.dialect) }
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function assertSchemaExpression(expression, path, code = "invalid-default") {
|
|
148
|
-
if (!isSchemaExpression(expression)) throw new ColumnBehaviorError(code, "Schema behavior expressions must carry the deterministic schema-expression brand", path);
|
|
149
|
-
}
|
|
150
|
-
function assertDefaultDescriptor(value) {
|
|
151
|
-
if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-default", "Column default metadata must be an object", "default");
|
|
152
|
-
if (value.kind === "external") return;
|
|
153
|
-
if (value.kind === "expression") {
|
|
154
|
-
assertSchemaExpression(value.expression, "default.expression");
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (value.kind === "literal") {
|
|
158
|
-
assertCanonicalLiteral(value.value);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
throw new ColumnBehaviorError("invalid-default", "Unknown column default descriptor kind", "default.kind");
|
|
162
|
-
}
|
|
163
|
-
function assertGeneratedColumnDescriptor(value) {
|
|
164
|
-
if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-generated-column", "Generated-column metadata must be an object", "generatedColumn");
|
|
165
|
-
if (value.kind === "external") return;
|
|
166
|
-
if (value.kind === "expression") {
|
|
167
|
-
assertSchemaExpression(value.expression, "generatedColumn.expression", "invalid-generated-column");
|
|
168
|
-
if (value.mode !== "stored" && value.mode !== "virtual") throw new ColumnBehaviorError("invalid-generated-column", "Generated-column mode must be \"stored\" or \"virtual\"", "generatedColumn.mode");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
throw new ColumnBehaviorError("invalid-generated-column", "Unknown generated-column descriptor kind", "generatedColumn.kind");
|
|
172
|
-
}
|
|
173
|
-
function assertIdentityDescriptor(value) {
|
|
174
|
-
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");
|
|
175
|
-
if (value.dialect !== void 0) {
|
|
176
|
-
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");
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function assertCanonicalLiteral(value) {
|
|
180
|
-
if (!value || typeof value !== "object") throw new ColumnBehaviorError("invalid-default", "Literal defaults must contain a canonical literal node", "default.value");
|
|
181
|
-
switch (value.kind) {
|
|
182
|
-
case "null": return;
|
|
183
|
-
case "boolean":
|
|
184
|
-
if (typeof value.value === "boolean") return;
|
|
185
|
-
break;
|
|
186
|
-
case "string":
|
|
187
|
-
if (typeof value.value === "string") return;
|
|
188
|
-
break;
|
|
189
|
-
case "number":
|
|
190
|
-
if (typeof value.value === "string" && value.value.length > 0) return;
|
|
191
|
-
break;
|
|
192
|
-
case "bigint": if (/^-?(0|[1-9][0-9]*)$/.test(value.value)) return;
|
|
193
|
-
}
|
|
194
|
-
throw new ColumnBehaviorError("invalid-default", "Literal defaults must contain a valid canonical literal node", "default.value");
|
|
195
|
-
}
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/schema/column.ts
|
|
198
|
-
/** Create an immutable portable physical storage descriptor. */
|
|
199
|
-
function portableStorage(type) {
|
|
200
|
-
return Object.freeze({
|
|
201
|
-
kind: "portable",
|
|
202
|
-
type
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
function nativeStorage(dialectOrOptions, type) {
|
|
206
|
-
const dialect = typeof dialectOrOptions === "string" ? dialectOrOptions : dialectOrOptions.dialect;
|
|
207
|
-
const declaration = typeof dialectOrOptions === "string" ? type : "type" in dialectOrOptions ? dialectOrOptions.type : dialectOrOptions.declaration;
|
|
208
|
-
return Object.freeze({
|
|
209
|
-
kind: "native",
|
|
210
|
-
dialect,
|
|
211
|
-
type: declaration
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function narrowColumnType() {
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
function withPortableCast(definition, type) {
|
|
218
|
-
return Object.freeze({
|
|
219
|
-
...definition,
|
|
220
|
-
castTarget: Object.freeze({
|
|
221
|
-
kind: "portable-cast",
|
|
222
|
-
type
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
function withPortableStorage(definition, type) {
|
|
227
|
-
return Object.freeze({
|
|
228
|
-
...definition,
|
|
229
|
-
storage: portableStorage(type)
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
function column(options) {
|
|
233
|
-
return Object.freeze({
|
|
234
|
-
definitionKind: "column",
|
|
235
|
-
nullable: options?.nullable === true,
|
|
236
|
-
...resolveColumnBehavior(options ?? {}),
|
|
237
|
-
sqlName: options?.sqlName,
|
|
238
|
-
storage: options?.storage ? Object.freeze({ ...options.storage }) : void 0,
|
|
239
|
-
$type: narrowColumnType,
|
|
240
|
-
castTarget: options?.castType ? Object.freeze({
|
|
241
|
-
kind: "named-cast",
|
|
242
|
-
typeName: options.castType
|
|
243
|
-
}) : void 0
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
function nativeColumn(storageOrDialect, typeOrOptions, maybeOptions) {
|
|
247
|
-
const storage = typeof storageOrDialect === "string" ? nativeStorage(storageOrDialect, typeOrOptions) : storageOrDialect;
|
|
248
|
-
return column({
|
|
249
|
-
...(typeof storageOrDialect === "string" ? maybeOptions : typeOrOptions) ?? {},
|
|
250
|
-
storage
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
function nullable(definition) {
|
|
254
|
-
return Object.freeze({
|
|
255
|
-
...definition,
|
|
256
|
-
nullable: true
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
function integer(options) {
|
|
260
|
-
return withPortableStorage(withPortableCast(column(options), "integer"), "integer");
|
|
261
|
-
}
|
|
262
|
-
function numeric(options) {
|
|
263
|
-
return withPortableStorage(withPortableCast(column(options), "decimal"), "numeric");
|
|
264
|
-
}
|
|
265
|
-
function text(options) {
|
|
266
|
-
return withPortableStorage(withPortableCast(column(options), "text"), "text");
|
|
267
|
-
}
|
|
268
|
-
function boolean(options) {
|
|
269
|
-
return withPortableStorage(withPortableCast(column(options), "boolean"), "boolean");
|
|
270
|
-
}
|
|
271
|
-
function date(options) {
|
|
272
|
-
return withPortableStorage(withPortableCast(column(options), "date"), "date");
|
|
273
|
-
}
|
|
274
|
-
function timestamp(options) {
|
|
275
|
-
return withPortableStorage(withPortableCast(column(options), "timestamp"), "timestamp");
|
|
276
|
-
}
|
|
277
|
-
function uuid(options) {
|
|
278
|
-
return withPortableStorage(withPortableCast(column(options), "uuid"), "uuid");
|
|
279
|
-
}
|
|
280
|
-
function json(options) {
|
|
281
|
-
return withPortableStorage(withPortableCast(column(options), "json"), "json");
|
|
282
|
-
}
|
|
283
|
-
function bigint(options) {
|
|
284
|
-
return withPortableStorage(withPortableCast(column(options), "bigint"), "bigint");
|
|
285
|
-
}
|
|
286
|
-
function binary(options) {
|
|
287
|
-
return withPortableStorage(withPortableCast(column(options), "binary"), "binary");
|
|
288
|
-
}
|
|
289
|
-
//#endregion
|
|
290
|
-
export { resolveColumnBehavior as S, canonicalLiteral as _, date as a, generatedColumn as b, nativeColumn as c, numeric as d, portableStorage as f, ColumnBehaviorError as g, uuid as h, column as i, nativeStorage as l, timestamp as m, binary as n, integer as o, text as p, boolean as r, json as s, bigint as t, nullable as u, externalDefault as v, identityColumn as x, externalGeneratedColumn as y };
|
package/dist/drizzle-mysql.d.mts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Pt as AnyTable, Xr as Schema, ni as SchemaTableRecord } from "./types-D8M1yZF4.mjs";
|
|
2
|
-
import { r as DrizzleSchemaValidation, t as DrizzleColumnConfig } from "./types-Ctlxz1ip.mjs";
|
|
3
|
-
import { MySqlColumn, MySqlTableWithColumns } from "drizzle-orm/mysql-core";
|
|
4
|
-
//#region src/drizzle/mysql.d.ts
|
|
5
|
-
type MysqlDrizzleColumn<TTableName extends string, TDefinition> = MySqlColumn<DrizzleColumnConfig<TTableName, TDefinition>>;
|
|
6
|
-
type MysqlDrizzleColumns<TTable extends AnyTable> = { [TKey in keyof TTable['definitions']]: MysqlDrizzleColumn<TTable['tableName'], TTable['definitions'][TKey]>; };
|
|
7
|
-
/** The Drizzle MySQL table produced for one Qubu table. */
|
|
8
|
-
type MysqlDrizzleTable<TTable extends AnyTable> = MySqlTableWithColumns<{
|
|
9
|
-
name: TTable['tableName'];
|
|
10
|
-
schema: string | undefined;
|
|
11
|
-
columns: MysqlDrizzleColumns<TTable>;
|
|
12
|
-
dialect: 'mysql';
|
|
13
|
-
}>;
|
|
14
|
-
/** A MySQL Drizzle table record retaining Qubu's logical table keys. */
|
|
15
|
-
type MysqlDrizzleSchema<TSchema extends Schema<any>> = { readonly [TKey in keyof TSchema['tables']]: MysqlDrizzleTable<TSchema['tables'][TKey]>; };
|
|
16
|
-
/**
|
|
17
|
-
* Convert a live Qubu schema registry into MySQL Drizzle table objects.
|
|
18
|
-
*
|
|
19
|
-
* @throws A snapshot validation error for invalid MySQL metadata, or a
|
|
20
|
-
* DrizzleSchemaConversionError when Drizzle cannot represent required metadata.
|
|
21
|
-
*/
|
|
22
|
-
declare function toMysqlDrizzleSchema<const TTables extends SchemaTableRecord>(schema: Schema<TTables> & DrizzleSchemaValidation<TTables, 'mysql'>): MysqlDrizzleSchema<Schema<TTables>>;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { MysqlDrizzleSchema, MysqlDrizzleTable, toMysqlDrizzleSchema };
|