@dsqlbase/core 0.2.1 → 0.3.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/CHANGELOG.md +27 -0
- package/dist/definition/base.d.ts +3 -30
- package/dist/definition/base.d.ts.map +1 -1
- package/dist/definition/base.js +3 -14
- package/dist/definition/base.js.map +1 -1
- package/dist/definition/column.d.ts +22 -14
- package/dist/definition/column.d.ts.map +1 -1
- package/dist/definition/column.js +11 -37
- package/dist/definition/column.js.map +1 -1
- package/dist/definition/constraint.d.ts +9 -9
- package/dist/definition/constraint.d.ts.map +1 -1
- package/dist/definition/constraint.js.map +1 -1
- package/dist/definition/domain.d.ts +2 -1
- package/dist/definition/domain.d.ts.map +1 -1
- package/dist/definition/domain.js +2 -1
- package/dist/definition/domain.js.map +1 -1
- package/dist/definition/index.d.ts +5 -6
- package/dist/definition/index.d.ts.map +1 -1
- package/dist/definition/index.js +3 -4
- package/dist/definition/index.js.map +1 -1
- package/dist/definition/indexes.d.ts +9 -20
- package/dist/definition/indexes.d.ts.map +1 -1
- package/dist/definition/indexes.js +3 -6
- package/dist/definition/indexes.js.map +1 -1
- package/dist/definition/namespace.d.ts +2 -2
- package/dist/definition/namespace.d.ts.map +1 -1
- package/dist/definition/namespace.js.map +1 -1
- package/dist/definition/policy.d.ts +35 -0
- package/dist/definition/policy.d.ts.map +1 -0
- package/dist/definition/policy.js +42 -0
- package/dist/definition/policy.js.map +1 -0
- package/dist/definition/relations.d.ts +28 -33
- package/dist/definition/relations.d.ts.map +1 -1
- package/dist/definition/relations.js +1 -4
- package/dist/definition/relations.js.map +1 -1
- package/dist/definition/table.d.ts +39 -32
- package/dist/definition/table.d.ts.map +1 -1
- package/dist/definition/table.js +57 -67
- package/dist/definition/table.js.map +1 -1
- package/dist/definition/union.d.ts +18 -61
- package/dist/definition/union.d.ts.map +1 -1
- package/dist/definition/union.js +8 -69
- package/dist/definition/union.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/resolvers/codec.d.ts +16 -0
- package/dist/resolvers/codec.d.ts.map +1 -0
- package/dist/resolvers/codec.js +9 -0
- package/dist/resolvers/codec.js.map +1 -0
- package/dist/resolvers/hooks.d.ts +39 -0
- package/dist/resolvers/hooks.d.ts.map +1 -0
- package/dist/resolvers/hooks.js +2 -0
- package/dist/resolvers/hooks.js.map +1 -0
- package/dist/resolvers/index.d.ts +5 -0
- package/dist/resolvers/index.d.ts.map +1 -0
- package/dist/resolvers/index.js +2 -0
- package/dist/resolvers/index.js.map +1 -0
- package/dist/resolvers/policy.d.ts +31 -0
- package/dist/resolvers/policy.d.ts.map +1 -0
- package/dist/resolvers/policy.js +2 -0
- package/dist/resolvers/policy.js.map +1 -0
- package/dist/resolvers/validator.d.ts +14 -0
- package/dist/resolvers/validator.d.ts.map +1 -0
- package/dist/resolvers/validator.js +2 -0
- package/dist/resolvers/validator.js.map +1 -0
- package/dist/runtime/base.d.ts +7 -4
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/build.d.ts +22 -0
- package/dist/runtime/build.d.ts.map +1 -0
- package/dist/runtime/build.js +184 -0
- package/dist/runtime/build.js.map +1 -0
- package/dist/runtime/column.d.ts +40 -23
- package/dist/runtime/column.d.ts.map +1 -1
- package/dist/runtime/column.js +120 -28
- package/dist/runtime/column.js.map +1 -1
- package/dist/runtime/context.d.ts +17 -26
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +4 -6
- package/dist/runtime/context.js.map +1 -1
- package/dist/runtime/errors.d.ts +31 -9
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/errors.js +54 -11
- package/dist/runtime/errors.js.map +1 -1
- package/dist/runtime/executor.d.ts.map +1 -1
- package/dist/runtime/executor.js +10 -1
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/index.d.ts +10 -6
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -3
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/operation.d.ts +62 -83
- package/dist/runtime/operation.d.ts.map +1 -1
- package/dist/runtime/operation.js +194 -260
- package/dist/runtime/operation.js.map +1 -1
- package/dist/runtime/policy.d.ts +35 -0
- package/dist/runtime/policy.d.ts.map +1 -0
- package/dist/runtime/policy.js +72 -0
- package/dist/runtime/policy.js.map +1 -0
- package/dist/runtime/reference.d.ts +87 -0
- package/dist/runtime/reference.d.ts.map +1 -0
- package/dist/runtime/reference.js +68 -0
- package/dist/runtime/reference.js.map +1 -0
- package/dist/runtime/registry.d.ts +26 -95
- package/dist/runtime/registry.d.ts.map +1 -1
- package/dist/runtime/registry.js +29 -408
- package/dist/runtime/registry.js.map +1 -1
- package/dist/runtime/relation.d.ts +45 -0
- package/dist/runtime/relation.d.ts.map +1 -0
- package/dist/runtime/relation.js +2 -0
- package/dist/runtime/relation.js.map +1 -0
- package/dist/runtime/table.d.ts +31 -35
- package/dist/runtime/table.d.ts.map +1 -1
- package/dist/runtime/table.js +78 -47
- package/dist/runtime/table.js.map +1 -1
- package/dist/runtime/union.d.ts +11 -4
- package/dist/runtime/union.d.ts.map +1 -1
- package/dist/runtime/union.js +18 -7
- package/dist/runtime/union.js.map +1 -1
- package/dist/sql/index.d.ts +2 -2
- package/dist/sql/index.d.ts.map +1 -1
- package/dist/sql/index.js +1 -1
- package/dist/sql/index.js.map +1 -1
- package/dist/sql/nodes.d.ts +22 -0
- package/dist/sql/nodes.d.ts.map +1 -1
- package/dist/sql/nodes.js +21 -0
- package/dist/sql/nodes.js.map +1 -1
- package/dist/sql/tag.d.ts +3 -15
- package/dist/sql/tag.d.ts.map +1 -1
- package/dist/sql/tag.js +5 -71
- package/dist/sql/tag.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/types.d.ts +2 -14
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js.map +1 -1
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/references.d.ts +23 -0
- package/dist/validation/references.d.ts.map +1 -0
- package/dist/validation/references.js +240 -0
- package/dist/validation/references.js.map +1 -0
- package/dist/validation/validate.d.ts +40 -0
- package/dist/validation/validate.d.ts.map +1 -0
- package/dist/validation/validate.js +354 -0
- package/dist/validation/validate.js.map +1 -0
- package/package.json +13 -4
- package/dist/definition/embedded.d.ts +0 -131
- package/dist/definition/embedded.d.ts.map +0 -1
- package/dist/definition/embedded.js +0 -133
- package/dist/definition/embedded.js.map +0 -1
- package/dist/definition/tenant.d.ts +0 -50
- package/dist/definition/tenant.d.ts.map +0 -1
- package/dist/definition/tenant.js +0 -73
- package/dist/definition/tenant.js.map +0 -1
- package/dist/runtime/group.d.ts +0 -54
- package/dist/runtime/group.d.ts.map +0 -1
- package/dist/runtime/group.js +0 -96
- package/dist/runtime/group.js.map +0 -1
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { ColumnDefinition, RESERVED_FIELD_NAMES, Relation, RelationsDefinition, TableDefinition, UnionDefinition, } from "../definition/index.js";
|
|
2
|
+
import { validateReferences } from "./references.js";
|
|
3
|
+
/**
|
|
4
|
+
* Checks a schema definition, throwing on the first problem. Pure: it reads definitions only,
|
|
5
|
+
* builds nothing, and keeps nothing — a schema it accepts can be built without further checks.
|
|
6
|
+
*
|
|
7
|
+
* - every union is keyed by an alias no table uses, and lists each member under the alias the
|
|
8
|
+
* schema exports it as;
|
|
9
|
+
* - every relation's pairs line up, carry the same column hooks, its discriminator is where one
|
|
10
|
+
* belongs, and its field name is free on the table that gets it — including each member of a
|
|
11
|
+
* union it is declared on;
|
|
12
|
+
* - no column's references form a ring, and a column with hooks references one target, reached
|
|
13
|
+
* in every union member through a unique key.
|
|
14
|
+
*/
|
|
15
|
+
export function validateSchema(schema) {
|
|
16
|
+
const index = indexSchema(schema);
|
|
17
|
+
validateUnions(schema, index);
|
|
18
|
+
for (const relation of index.relations) {
|
|
19
|
+
validateRelation(relation, index);
|
|
20
|
+
}
|
|
21
|
+
validateReferences(index.relations, referenceIndex(index), (entry) => {
|
|
22
|
+
const union = entry.relation.target;
|
|
23
|
+
const alias = [...index.unions].find(([, candidate]) => candidate === union)?.[0] ?? "";
|
|
24
|
+
return memberToColumns(entry.field, alias, union, entry.relation.to);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function referenceIndex(index) {
|
|
28
|
+
const owners = new Map();
|
|
29
|
+
for (const table of index.tables.values()) {
|
|
30
|
+
for (const column of Object.values(table.columns)) {
|
|
31
|
+
owners.set(column, table);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
aliases: new Map([...index.tables].map(([alias, table]) => [table, alias])),
|
|
36
|
+
unions: new Map([...index.unions].map(([alias, union]) => [union, alias])),
|
|
37
|
+
owners,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Every relation in the schema as the table that has it sees it, in declaration order. A
|
|
42
|
+
* relation declared on a union appears once per member, with `from` resolved to that member's
|
|
43
|
+
* columns. Throws on a name a table receives twice.
|
|
44
|
+
*/
|
|
45
|
+
export function collectRelations(schema) {
|
|
46
|
+
const relations = [];
|
|
47
|
+
const names = new Map();
|
|
48
|
+
const add = (entry) => {
|
|
49
|
+
const byName = names.get(entry.source) ?? new Map();
|
|
50
|
+
const existing = byName.get(entry.field);
|
|
51
|
+
if (existing) {
|
|
52
|
+
const fromUnion = entry.union ?? existing.union;
|
|
53
|
+
throw new Error(fromUnion && entry.union !== existing.union
|
|
54
|
+
? `Relation "${entry.field}" on ${fromUnion.name} has the same name as relation ` +
|
|
55
|
+
`"${entry.field}" on its member "${(entry.union ? entry.member : existing.member)}".`
|
|
56
|
+
: `Duplicate relation name: ${entry.field}`);
|
|
57
|
+
}
|
|
58
|
+
byName.set(entry.field, entry);
|
|
59
|
+
names.set(entry.source, byName);
|
|
60
|
+
relations.push(entry);
|
|
61
|
+
};
|
|
62
|
+
for (const node of Object.values(schema)) {
|
|
63
|
+
if (!(node instanceof RelationsDefinition)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const declared = node.relations;
|
|
67
|
+
if (node.table instanceof UnionDefinition) {
|
|
68
|
+
const union = node.table;
|
|
69
|
+
for (const [field, relation] of Object.entries(declared)) {
|
|
70
|
+
validateUnionSource(union, field, relation);
|
|
71
|
+
for (const [member, source] of Object.entries(union.members)) {
|
|
72
|
+
add({
|
|
73
|
+
field,
|
|
74
|
+
source,
|
|
75
|
+
union,
|
|
76
|
+
member,
|
|
77
|
+
relation: {
|
|
78
|
+
...relation,
|
|
79
|
+
from: relation.from.map((column) => Object.values(source.columns).find((c) => c.name === column.name)),
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const [field, relation] of Object.entries(declared)) {
|
|
87
|
+
add({ field, relation, source: node.table });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return relations;
|
|
91
|
+
}
|
|
92
|
+
function indexSchema(schema) {
|
|
93
|
+
const tables = new Map();
|
|
94
|
+
const unions = new Map();
|
|
95
|
+
for (const [alias, node] of Object.entries(schema)) {
|
|
96
|
+
if (node instanceof TableDefinition) {
|
|
97
|
+
tables.set(alias, node);
|
|
98
|
+
}
|
|
99
|
+
else if (node instanceof UnionDefinition) {
|
|
100
|
+
unions.set(alias, node);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { tables, unions, relations: collectRelations(schema) };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A union and a table are both read through the client by name — a table by alias or database
|
|
107
|
+
* name — so a union's alias can only mean one of them; and a member is keyed by the alias it is exported under, which is what makes a
|
|
108
|
+
* member key mean the same thing as `$$meta.key` and a node key.
|
|
109
|
+
*/
|
|
110
|
+
function validateUnions(schema, index) {
|
|
111
|
+
for (const [alias, union] of index.unions) {
|
|
112
|
+
// The client addresses a table by alias or by database name.
|
|
113
|
+
if (index.tables.has(alias) || [...index.tables.values()].some((t) => t.name === alias)) {
|
|
114
|
+
throw new Error(`Union "${alias}" has the same name as a table in the schema. A union and a table ` +
|
|
115
|
+
`are both read through the client by that name, so it can only mean one of them.`);
|
|
116
|
+
}
|
|
117
|
+
for (const [key, member] of Object.entries(union.members)) {
|
|
118
|
+
if (schema[key] !== member) {
|
|
119
|
+
throw new Error(`Union "${alias}" lists table "${member.name}" under "${key}", but the schema does ` +
|
|
120
|
+
`not export that table as "${key}". Union members are keyed by their schema alias.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
validateUnionColumns(union);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function validateUnionColumns(union) {
|
|
127
|
+
for (const [field, column] of Object.entries(union.columns)) {
|
|
128
|
+
if (!column) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
for (const [alias, member] of Object.entries(union.members)) {
|
|
132
|
+
const candidate = member.columns[field];
|
|
133
|
+
const label = `${union.name} declares "${field}", but member "${alias}"`;
|
|
134
|
+
if (!candidate) {
|
|
135
|
+
throw new Error(`${label} has no such field.`);
|
|
136
|
+
}
|
|
137
|
+
if (candidate.name !== column.name) {
|
|
138
|
+
throw new Error(`${label} stores it in column "${candidate.name}", not "${column.name}". A shared ` +
|
|
139
|
+
`field has one column name on every member.`);
|
|
140
|
+
}
|
|
141
|
+
if (candidate["_dataType"] !== column["_dataType"] ||
|
|
142
|
+
Object.getPrototypeOf(candidate) !== Object.getPrototypeOf(column)) {
|
|
143
|
+
throw new Error(`${label} declares it as a different kind of column (${candidate["_dataType"]}). ` +
|
|
144
|
+
`A shared field has one type on every member.`);
|
|
145
|
+
}
|
|
146
|
+
if (column["_notNull"] && !candidate["_notNull"]) {
|
|
147
|
+
throw new Error(`${label} allows NULL in it, and the union declares it NOT NULL.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** A relation declared on a union: its `from` names the union's fields, and it targets a table. */
|
|
153
|
+
function validateUnionSource(union, field, relation) {
|
|
154
|
+
const label = `Relation "${field}" on ${union.name}`;
|
|
155
|
+
if (!(relation.target instanceof TableDefinition)) {
|
|
156
|
+
throw new Error(`${label} targets a union. A relation whose source is a union must target a table.`);
|
|
157
|
+
}
|
|
158
|
+
if (relation.discriminator) {
|
|
159
|
+
throw new Error(`${label} declares a discriminator, but only a belongs-to a union needs one.`);
|
|
160
|
+
}
|
|
161
|
+
for (const column of relation.from) {
|
|
162
|
+
if (!(column instanceof ColumnDefinition) ||
|
|
163
|
+
!Object.values(union.columns).some((c) => c === column)) {
|
|
164
|
+
throw new Error(`${label}: a "from" column must be a field the union declares (\`union.columns.<field>\`).`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The field alias a column is declared under on `table`, or `undefined` when the column does
|
|
170
|
+
* not belong to it. Identity, not name: a column from a different table that happens to share a
|
|
171
|
+
* name is not a match, which is the copy-paste mistake this catches.
|
|
172
|
+
*/
|
|
173
|
+
export function findColumnAlias(table, column) {
|
|
174
|
+
return Object.entries(table.columns).find(([, candidate]) => candidate === column)?.[0];
|
|
175
|
+
}
|
|
176
|
+
function isTableInSchema(index, table) {
|
|
177
|
+
return [...index.tables.values()].includes(table);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Checks that a relation's column pairs line up: equal, non-zero length; each column declared
|
|
181
|
+
* on the side it is listed under, and not deprecated; both columns of a pair of the same type.
|
|
182
|
+
* The query builder correlates over every pair, so a malformed relation would otherwise surface
|
|
183
|
+
* as a confusing SQL error at query time, or not at all.
|
|
184
|
+
*/
|
|
185
|
+
function validateRelation(entry, index) {
|
|
186
|
+
const { field, relation, source, union } = entry;
|
|
187
|
+
const sourceName = source.name;
|
|
188
|
+
const label = union
|
|
189
|
+
? `Relation "${field}" on ${union.name} (member table "${sourceName}")`
|
|
190
|
+
: `Relation "${field}" on table "${sourceName}"`;
|
|
191
|
+
if (!isTableInSchema(index, source)) {
|
|
192
|
+
throw new Error(`Table not found for relations: ${sourceName}`);
|
|
193
|
+
}
|
|
194
|
+
// Columns and relations share one namespace: the client addresses both as fields of the same
|
|
195
|
+
// model (`select`, `join`, and the keys of a result row), so a name can only mean one of them.
|
|
196
|
+
const column = source.columns[field];
|
|
197
|
+
if (column && !column["_deprecated"]) {
|
|
198
|
+
throw new Error(`Relation "${field}" on table "${sourceName}" collides with a column of the same ` +
|
|
199
|
+
`name. Columns and relations share one field namespace on a table.`);
|
|
200
|
+
}
|
|
201
|
+
// That one namespace also excludes the names the runtime writes onto result rows.
|
|
202
|
+
if (RESERVED_FIELD_NAMES.includes(field)) {
|
|
203
|
+
throw new Error(`Table "${sourceName}" declares a relation named "${field}", which is reserved. ` +
|
|
204
|
+
`The runtime writes ${RESERVED_FIELD_NAMES.join(" and ")} onto every result row.`);
|
|
205
|
+
}
|
|
206
|
+
const { from } = relation;
|
|
207
|
+
if (from.length === 0) {
|
|
208
|
+
throw new Error(`${label} must declare at least one column pair in "from" and "to".`);
|
|
209
|
+
}
|
|
210
|
+
if (relation.target instanceof UnionDefinition) {
|
|
211
|
+
validateUnionTarget(label, relation, source, index);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const to = relation.to;
|
|
215
|
+
if (to.length === 0) {
|
|
216
|
+
throw new Error(`${label} must declare at least one column pair in "from" and "to".`);
|
|
217
|
+
}
|
|
218
|
+
if (from.length !== to.length) {
|
|
219
|
+
throw new Error(`${label} pairs ${from.length} "from" column(s) with ${to.length} "to" column(s); ` +
|
|
220
|
+
`the two sides must have the same length.`);
|
|
221
|
+
}
|
|
222
|
+
if (relation.discriminator) {
|
|
223
|
+
throw new Error(`${label} declares a discriminator, but its target is a single table. Only a ` +
|
|
224
|
+
`belongs-to a union needs one.`);
|
|
225
|
+
}
|
|
226
|
+
const target = relation.target;
|
|
227
|
+
if (!isTableInSchema(index, target)) {
|
|
228
|
+
throw new Error(`${label} targets table "${target.name}", which is not in the schema.`);
|
|
229
|
+
}
|
|
230
|
+
for (const [position, fromColumn] of from.entries()) {
|
|
231
|
+
validatePair(label, source, fromColumn, target, to[position], `target table "${target.name}"`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/** One pair: each column declared, and live, on its side; both of one type, with one set of hooks. */
|
|
235
|
+
function validatePair(label, source, fromColumn, target, toColumn, targetLabel) {
|
|
236
|
+
const fromAlias = findColumnAlias(source, fromColumn);
|
|
237
|
+
const toAlias = findColumnAlias(target, toColumn);
|
|
238
|
+
if (!fromAlias) {
|
|
239
|
+
throw new Error(`${label}: "from" column "${fromColumn.name}" is not declared on table "${source.name}".`);
|
|
240
|
+
}
|
|
241
|
+
if (!toAlias) {
|
|
242
|
+
throw new Error(`${label}: "to" column "${toColumn.name}" is not declared on ${targetLabel}.`);
|
|
243
|
+
}
|
|
244
|
+
for (const [table, alias, column] of [
|
|
245
|
+
[source, fromAlias, fromColumn],
|
|
246
|
+
[target, toAlias, toColumn],
|
|
247
|
+
]) {
|
|
248
|
+
if (column["_deprecated"]) {
|
|
249
|
+
throw new Error(`${label}: "${table.name}"."${alias}" is deprecated, so the client cannot read it.`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const fromType = fromColumn["_dataType"];
|
|
253
|
+
const toType = toColumn["_dataType"];
|
|
254
|
+
if (fromType !== toType) {
|
|
255
|
+
throw new Error(`${label}: "${source.name}"."${fromAlias}" is "${fromType}" but ` +
|
|
256
|
+
`"${target.name}"."${toAlias}" is "${toType}"; ` +
|
|
257
|
+
`both columns of a pair must have the same type.`);
|
|
258
|
+
}
|
|
259
|
+
// A value crosses the relation as it is read and written: through the same hooks on both sides.
|
|
260
|
+
if (fromColumn["_hooks"] !== toColumn["_hooks"]) {
|
|
261
|
+
throw new Error(`${label} pairs "${source.name}"."${fromAlias}" and "${target.name}"."${toAlias}", but ` +
|
|
262
|
+
`they carry different column hooks — a guid() and a plain column, say. Both sides of ` +
|
|
263
|
+
`a pair must read and write their values the same way.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The union half of {@link validateRelation}: the union must be in the schema, `to` must name a
|
|
268
|
+
* column on every member — through a shared field or a per-member list — paired with `from` by
|
|
269
|
+
* type, and only a belongs-to may carry a discriminator.
|
|
270
|
+
*/
|
|
271
|
+
function validateUnionTarget(label, relation, source, index) {
|
|
272
|
+
const target = relation.target;
|
|
273
|
+
const alias = [...index.unions].find(([, candidate]) => candidate === target)?.[0];
|
|
274
|
+
if (!alias) {
|
|
275
|
+
throw new Error(`${label} targets ${target.name}, which is not in the schema.`);
|
|
276
|
+
}
|
|
277
|
+
const { from } = relation;
|
|
278
|
+
for (const [member, to] of Object.entries(memberToColumns(label, alias, target, relation.to))) {
|
|
279
|
+
if (to.length !== from.length) {
|
|
280
|
+
throw new Error(`${label} pairs ${from.length} "from" column(s) with ${to.length} "to" column(s) on ` +
|
|
281
|
+
`member "${member}"; the two sides must have the same length.`);
|
|
282
|
+
}
|
|
283
|
+
const memberTable = target.members[member];
|
|
284
|
+
for (const [position, toColumn] of to.entries()) {
|
|
285
|
+
validatePair(label, source, from[position], memberTable, toColumn, `member "${member}" of union "${alias}"`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
validateDiscriminator(label, relation, source, alias);
|
|
289
|
+
}
|
|
290
|
+
/** `to` as one column-definition list per member, whichever form it was written in. */
|
|
291
|
+
export function memberToColumns(label, alias, union, to) {
|
|
292
|
+
const members = Object.entries(union.members);
|
|
293
|
+
if (Array.isArray(to)) {
|
|
294
|
+
if (to.length === 0) {
|
|
295
|
+
throw new Error(`${label} must declare at least one column pair in "from" and "to".`);
|
|
296
|
+
}
|
|
297
|
+
return Object.fromEntries(members.map(([member, table]) => [
|
|
298
|
+
member,
|
|
299
|
+
to.map((column) => {
|
|
300
|
+
if (!(column instanceof ColumnDefinition) ||
|
|
301
|
+
!Object.values(union.columns).some((c) => c === column)) {
|
|
302
|
+
throw new Error(`${label}: a "to" column given as a list must be a shared field of union ` +
|
|
303
|
+
`"${alias}" (\`${alias}.columns.<field>\`). To name a different column per ` +
|
|
304
|
+
`member, pass one list per member instead.`);
|
|
305
|
+
}
|
|
306
|
+
return Object.values(table.columns).find((c) => c.name === column.name);
|
|
307
|
+
}),
|
|
308
|
+
]));
|
|
309
|
+
}
|
|
310
|
+
const lists = to;
|
|
311
|
+
const given = Object.keys(lists);
|
|
312
|
+
const missing = members.filter(([member]) => !given.includes(member));
|
|
313
|
+
const unknown = given.filter((member) => !members.some(([m]) => m === member));
|
|
314
|
+
if (missing.length > 0 || unknown.length > 0) {
|
|
315
|
+
throw new Error(`${label} must name one "to" column list per member of union "${alias}" ` +
|
|
316
|
+
`(${members.map(([member]) => member).join(", ")})` +
|
|
317
|
+
(missing.length > 0 ? `; missing: ${missing.map(([member]) => member).join(", ")}` : "") +
|
|
318
|
+
(unknown.length > 0 ? `; not members: ${unknown.join(", ")}` : "") +
|
|
319
|
+
`.`);
|
|
320
|
+
}
|
|
321
|
+
return lists;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* A belongs-to a union may store which member it points at in a column of its own — the
|
|
325
|
+
* discriminator, holding a member alias. Without one, the member is the first holding the key,
|
|
326
|
+
* computed when the query runs. Has-many and has-one to a union need none, since the key lives
|
|
327
|
+
* on each member, so one there is a mistake.
|
|
328
|
+
*/
|
|
329
|
+
function validateDiscriminator(label, relation, source, union) {
|
|
330
|
+
const { discriminator } = relation;
|
|
331
|
+
if (relation.type !== Relation.BELONGS_TO) {
|
|
332
|
+
if (discriminator) {
|
|
333
|
+
throw new Error(`${label} declares a discriminator, but only a belongs-to a union needs one: the ` +
|
|
334
|
+
`members of "${union}" hold the key.`);
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (!discriminator) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const alias = findColumnAlias(source, discriminator);
|
|
342
|
+
if (!alias) {
|
|
343
|
+
throw new Error(`${label}: discriminator "${discriminator.name}" is not declared on table "${source.name}".`);
|
|
344
|
+
}
|
|
345
|
+
const dataType = discriminator["_dataType"];
|
|
346
|
+
const textLike = discriminator["_domain"] !== undefined ||
|
|
347
|
+
dataType === "text" ||
|
|
348
|
+
/^(varchar|char)\(\d+\)$/.test(dataType);
|
|
349
|
+
if (!textLike) {
|
|
350
|
+
throw new Error(`${label}: discriminator "${source.name}"."${alias}" is "${dataType}"; it holds a ` +
|
|
351
|
+
`member alias, so it must be text, varchar, char, or a text domain.`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validation/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,gBAAgB,EAEhB,oBAAoB,EACpB,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAElC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE9B,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACvC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,E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AKG;AACH,SAAS,qBAAqB,CAC5B,KAAa,EACb,QAA0B,EAC1B,MAA0B,EAC1B,KAAa;IAEb,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IAEnC,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC1C,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,0EAA0E;gBAChF,eAAe,KAAK,iBAAiB,CACxC,CAAC;QACJ,CAAC;QAED,OAAO;IACT,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAErD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,oBAAoB,aAAa,CAAC,IAAI,+BAA+B,MAAM,CAAC,IAAI,IAAI,CAC7F,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAW,CAAC;IACtD,MAAM,QAAQ,GACZ,aAAa,CAAC,SAAS,CAAC,KAAK,SAAS;QACtC,QAAQ,KAAK,MAAM;QACnB,yBAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,oBAAoB,MAAM,CAAC,IAAI,MAAM,KAAK,SAAS,QAAQ,gBAAgB;YACjF,oEAAoE,CACvE,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import {\n AnyColumnDefinition,\n AnyFieldRelation,\n AnyTableDefinition,\n AnyTableRelations,\n AnyUnionDefinition,\n ColumnDefinition,\n DefinitionSchema,\n RESERVED_FIELD_NAMES,\n Relation,\n RelationsDefinition,\n TableDefinition,\n UnionDefinition,\n} from \"../definition/index.js\";\nimport { validateReferences } from \"./references.js\";\n\n/**\n * Checks a schema definition, throwing on the first problem. Pure: it reads definitions only,\n * builds nothing, and keeps nothing — a schema it accepts can be built without further checks.\n *\n * - every union is keyed by an alias no table uses, and lists each member under the alias the\n * schema exports it as;\n * - every relation's pairs line up, carry the same column hooks, its discriminator is where one\n * belongs, and its field name is free on the table that gets it — including each member of a\n * union it is declared on;\n * - no column's references form a ring, and a column with hooks references one target, reached\n * in every union member through a unique key.\n */\nexport function validateSchema(schema: DefinitionSchema): void {\n const index = indexSchema(schema);\n\n validateUnions(schema, index);\n\n for (const relation of index.relations) {\n validateRelation(relation, index);\n }\n\n validateReferences(index.relations, referenceIndex(index), (entry) => {\n const union = entry.relation.target as AnyUnionDefinition;\n const alias = [...index.unions].find(([, candidate]) => candidate === union)?.[0] ?? \"\";\n\n return memberToColumns(entry.field, alias, union, entry.relation.to);\n });\n}\n\nfunction referenceIndex(index: SchemaIndex) {\n const owners = new Map<AnyColumnDefinition, AnyTableDefinition>();\n\n for (const table of index.tables.values()) {\n for (const column of Object.values<AnyColumnDefinition>(table.columns)) {\n owners.set(column, table);\n }\n }\n\n return {\n aliases: new Map([...index.tables].map(([alias, table]) => [table, alias])),\n unions: new Map([...index.unions].map(([alias, union]) => [union, alias])),\n owners,\n };\n}\n\n/** A relation as some table receives it: declared on that table, or on a union it is in. */\nexport type SourcedRelation = {\n readonly field: string;\n readonly relation: AnyFieldRelation;\n /** The table that has the relation. */\n readonly source: AnyTableDefinition;\n /** The union it was declared on, for a relation whose source is a union. */\n readonly union?: AnyUnionDefinition;\n /** That union's member alias for `source`. */\n readonly member?: string;\n};\n\ntype SchemaIndex = {\n readonly tables: ReadonlyMap<string, AnyTableDefinition>; // alias → definition\n readonly unions: ReadonlyMap<string, AnyUnionDefinition>; // alias → definition\n readonly relations: readonly SourcedRelation[];\n};\n\n/**\n * Every relation in the schema as the table that has it sees it, in declaration order. A\n * relation declared on a union appears once per member, with `from` resolved to that member's\n * columns. Throws on a name a table receives twice.\n */\nexport function collectRelations(schema: DefinitionSchema): SourcedRelation[] {\n const relations: SourcedRelation[] = [];\n const names = new Map<AnyTableDefinition, Map<string, SourcedRelation>>();\n\n const add = (entry: SourcedRelation) => {\n const byName = names.get(entry.source) ?? new Map<string, SourcedRelation>();\n const existing = byName.get(entry.field);\n\n if (existing) {\n const fromUnion = entry.union ?? existing.union;\n\n throw new Error(\n fromUnion && entry.union !== existing.union\n ? `Relation \"${entry.field}\" on ${fromUnion.name} has the same name as relation ` +\n `\"${entry.field}\" on its member \"${(entry.union ? entry.member : existing.member) as string}\".`\n : `Duplicate relation name: ${entry.field}`\n );\n }\n\n byName.set(entry.field, entry);\n names.set(entry.source, byName);\n relations.push(entry);\n };\n\n for (const node of Object.values(schema)) {\n if (!(node instanceof RelationsDefinition)) {\n continue;\n }\n\n const declared = node.relations as AnyTableRelations;\n\n if (node.table instanceof UnionDefinition) {\n const union = node.table;\n\n for (const [field, relation] of Object.entries(declared)) {\n validateUnionSource(union, field, relation);\n\n for (const [member, source] of Object.entries<AnyTableDefinition>(union.members)) {\n add({\n field,\n source,\n union,\n member,\n relation: {\n ...relation,\n from: relation.from.map((column) =>\n Object.values(source.columns).find((c) => c.name === column.name)\n ) as AnyColumnDefinition[],\n } as AnyFieldRelation,\n });\n }\n }\n\n continue;\n }\n\n for (const [field, relation] of Object.entries(declared)) {\n add({ field, relation, source: node.table as AnyTableDefinition });\n }\n }\n\n return relations;\n}\n\nfunction indexSchema(schema: DefinitionSchema): SchemaIndex {\n const tables = new Map<string, AnyTableDefinition>();\n const unions = new Map<string, AnyUnionDefinition>();\n\n for (const [alias, node] of Object.entries(schema)) {\n if (node instanceof TableDefinition) {\n tables.set(alias, node);\n } else if (node instanceof UnionDefinition) {\n unions.set(alias, node);\n }\n }\n\n return { tables, unions, relations: collectRelations(schema) };\n}\n\n/**\n * A union and a table are both read through the client by name — a table by alias or database\n * name — so a union's alias can only mean one of them; and a member is keyed by the alias it is exported under, which is what makes a\n * member key mean the same thing as `$$meta.key` and a node key.\n */\nfunction validateUnions(schema: DefinitionSchema, index: SchemaIndex): void {\n for (const [alias, union] of index.unions) {\n // The client addresses a table by alias or by database name.\n if (index.tables.has(alias) || [...index.tables.values()].some((t) => t.name === alias)) {\n throw new Error(\n `Union \"${alias}\" has the same name as a table in the schema. A union and a table ` +\n `are both read through the client by that name, so it can only mean one of them.`\n );\n }\n\n for (const [key, member] of Object.entries<AnyTableDefinition>(union.members)) {\n if (schema[key] !== member) {\n throw new Error(\n `Union \"${alias}\" lists table \"${member.name}\" under \"${key}\", but the schema does ` +\n `not export that table as \"${key}\". Union members are keyed by their schema alias.`\n );\n }\n }\n\n validateUnionColumns(union);\n }\n}\n\nfunction validateUnionColumns(union: AnyUnionDefinition): void {\n for (const [field, column] of Object.entries<AnyColumnDefinition>(union.columns)) {\n if (!column) {\n continue;\n }\n\n for (const [alias, member] of Object.entries(union.members)) {\n const candidate = (member.columns as Record<string, AnyColumnDefinition>)[field];\n\n const label = `${union.name} declares \"${field}\", but member \"${alias}\"`;\n\n if (!candidate) {\n throw new Error(`${label} has no such field.`);\n }\n\n if (candidate.name !== column.name) {\n throw new Error(\n `${label} stores it in column \"${candidate.name}\", not \"${column.name}\". A shared ` +\n `field has one column name on every member.`\n );\n }\n\n if (\n candidate[\"_dataType\"] !== column[\"_dataType\"] ||\n Object.getPrototypeOf(candidate) !== Object.getPrototypeOf(column)\n ) {\n throw new Error(\n `${label} declares it as a different kind of column (${candidate[\"_dataType\"]}). ` +\n `A shared field has one type on every member.`\n );\n }\n\n if (column[\"_notNull\"] && !candidate[\"_notNull\"]) {\n throw new Error(`${label} allows NULL in it, and the union declares it NOT NULL.`);\n }\n }\n }\n}\n\n/** A relation declared on a union: its `from` names the union's fields, and it targets a table. */\nfunction validateUnionSource(\n union: AnyUnionDefinition,\n field: string,\n relation: AnyFieldRelation\n): void {\n const label = `Relation \"${field}\" on ${union.name}`;\n\n if (!(relation.target instanceof TableDefinition)) {\n throw new Error(\n `${label} targets a union. A relation whose source is a union must target a table.`\n );\n }\n\n if (relation.discriminator) {\n throw new Error(`${label} declares a discriminator, but only a belongs-to a union needs one.`);\n }\n\n for (const column of relation.from as unknown[]) {\n if (\n !(column instanceof ColumnDefinition) ||\n !Object.values(union.columns).some((c) => c === column)\n ) {\n throw new Error(\n `${label}: a \"from\" column must be a field the union declares (\\`union.columns.<field>\\`).`\n );\n }\n }\n}\n\n/**\n * The field alias a column is declared under on `table`, or `undefined` when the column does\n * not belong to it. Identity, not name: a column from a different table that happens to share a\n * name is not a match, which is the copy-paste mistake this catches.\n */\nexport function findColumnAlias(\n table: AnyTableDefinition,\n column: AnyColumnDefinition\n): string | undefined {\n return Object.entries(table.columns).find(([, candidate]) => candidate === column)?.[0];\n}\n\nfunction isTableInSchema(index: SchemaIndex, table: AnyTableDefinition): boolean {\n return [...index.tables.values()].includes(table);\n}\n\n/**\n * Checks that a relation's column pairs line up: equal, non-zero length; each column declared\n * on the side it is listed under, and not deprecated; both columns of a pair of the same type.\n * The query builder correlates over every pair, so a malformed relation would otherwise surface\n * as a confusing SQL error at query time, or not at all.\n */\nfunction validateRelation(entry: SourcedRelation, index: SchemaIndex): void {\n const { field, relation, source, union } = entry;\n const sourceName = source.name;\n const label = union\n ? `Relation \"${field}\" on ${union.name} (member table \"${sourceName}\")`\n : `Relation \"${field}\" on table \"${sourceName}\"`;\n\n if (!isTableInSchema(index, source)) {\n throw new Error(`Table not found for relations: ${sourceName}`);\n }\n\n // Columns and relations share one namespace: the client addresses both as fields of the same\n // model (`select`, `join`, and the keys of a result row), so a name can only mean one of them.\n const column = source.columns[field];\n\n if (column && !column[\"_deprecated\"]) {\n throw new Error(\n `Relation \"${field}\" on table \"${sourceName}\" collides with a column of the same ` +\n `name. Columns and relations share one field namespace on a table.`\n );\n }\n\n // That one namespace also excludes the names the runtime writes onto result rows.\n if (RESERVED_FIELD_NAMES.includes(field)) {\n throw new Error(\n `Table \"${sourceName}\" declares a relation named \"${field}\", which is reserved. ` +\n `The runtime writes ${RESERVED_FIELD_NAMES.join(\" and \")} onto every result row.`\n );\n }\n\n const { from } = relation;\n\n if (from.length === 0) {\n throw new Error(`${label} must declare at least one column pair in \"from\" and \"to\".`);\n }\n\n if (relation.target instanceof UnionDefinition) {\n validateUnionTarget(label, relation, source, index);\n return;\n }\n\n const to = relation.to as AnyColumnDefinition[];\n\n if (to.length === 0) {\n throw new Error(`${label} must declare at least one column pair in \"from\" and \"to\".`);\n }\n\n if (from.length !== to.length) {\n throw new Error(\n `${label} pairs ${from.length} \"from\" column(s) with ${to.length} \"to\" column(s); ` +\n `the two sides must have the same length.`\n );\n }\n\n if (relation.discriminator) {\n throw new Error(\n `${label} declares a discriminator, but its target is a single table. Only a ` +\n `belongs-to a union needs one.`\n );\n }\n\n const target = relation.target;\n\n if (!isTableInSchema(index, target)) {\n throw new Error(`${label} targets table \"${target.name}\", which is not in the schema.`);\n }\n\n for (const [position, fromColumn] of from.entries()) {\n validatePair(label, source, fromColumn, target, to[position], `target table \"${target.name}\"`);\n }\n}\n\n/** One pair: each column declared, and live, on its side; both of one type, with one set of hooks. */\nfunction validatePair(\n label: string,\n source: AnyTableDefinition,\n fromColumn: AnyColumnDefinition,\n target: AnyTableDefinition,\n toColumn: AnyColumnDefinition,\n targetLabel: string\n): void {\n const fromAlias = findColumnAlias(source, fromColumn);\n const toAlias = findColumnAlias(target, toColumn);\n\n if (!fromAlias) {\n throw new Error(\n `${label}: \"from\" column \"${fromColumn.name}\" is not declared on table \"${source.name}\".`\n );\n }\n\n if (!toAlias) {\n throw new Error(`${label}: \"to\" column \"${toColumn.name}\" is not declared on ${targetLabel}.`);\n }\n\n for (const [table, alias, column] of [\n [source, fromAlias, fromColumn],\n [target, toAlias, toColumn],\n ] as const) {\n if (column[\"_deprecated\"]) {\n throw new Error(\n `${label}: \"${table.name}\".\"${alias}\" is deprecated, so the client cannot read it.`\n );\n }\n }\n\n const fromType = fromColumn[\"_dataType\"];\n const toType = toColumn[\"_dataType\"];\n\n if (fromType !== toType) {\n throw new Error(\n `${label}: \"${source.name}\".\"${fromAlias}\" is \"${fromType}\" but ` +\n `\"${target.name}\".\"${toAlias}\" is \"${toType}\"; ` +\n `both columns of a pair must have the same type.`\n );\n }\n\n // A value crosses the relation as it is read and written: through the same hooks on both sides.\n if (fromColumn[\"_hooks\"] !== toColumn[\"_hooks\"]) {\n throw new Error(\n `${label} pairs \"${source.name}\".\"${fromAlias}\" and \"${target.name}\".\"${toAlias}\", but ` +\n `they carry different column hooks — a guid() and a plain column, say. Both sides of ` +\n `a pair must read and write their values the same way.`\n );\n }\n}\n\n/**\n * The union half of {@link validateRelation}: the union must be in the schema, `to` must name a\n * column on every member — through a shared field or a per-member list — paired with `from` by\n * type, and only a belongs-to may carry a discriminator.\n */\nfunction validateUnionTarget(\n label: string,\n relation: AnyFieldRelation,\n source: AnyTableDefinition,\n index: SchemaIndex\n): void {\n const target = relation.target as AnyUnionDefinition;\n const alias = [...index.unions].find(([, candidate]) => candidate === target)?.[0];\n\n if (!alias) {\n throw new Error(`${label} targets ${target.name}, which is not in the schema.`);\n }\n\n const { from } = relation;\n\n for (const [member, to] of Object.entries(memberToColumns(label, alias, target, relation.to))) {\n if (to.length !== from.length) {\n throw new Error(\n `${label} pairs ${from.length} \"from\" column(s) with ${to.length} \"to\" column(s) on ` +\n `member \"${member}\"; the two sides must have the same length.`\n );\n }\n\n const memberTable = target.members[member] as AnyTableDefinition;\n\n for (const [position, toColumn] of to.entries()) {\n validatePair(\n label,\n source,\n from[position],\n memberTable,\n toColumn,\n `member \"${member}\" of union \"${alias}\"`\n );\n }\n }\n\n validateDiscriminator(label, relation, source, alias);\n}\n\n/** `to` as one column-definition list per member, whichever form it was written in. */\nexport function memberToColumns(\n label: string,\n alias: string,\n union: AnyUnionDefinition,\n to: AnyFieldRelation[\"to\"]\n): Record<string, AnyColumnDefinition[]> {\n const members = Object.entries(union.members);\n\n if (Array.isArray(to)) {\n if (to.length === 0) {\n throw new Error(`${label} must declare at least one column pair in \"from\" and \"to\".`);\n }\n\n return Object.fromEntries(\n members.map(([member, table]: [string, AnyTableDefinition]) => [\n member,\n to.map((column: AnyColumnDefinition) => {\n if (\n !(column instanceof ColumnDefinition) ||\n !Object.values(union.columns).some((c) => c === column)\n ) {\n throw new Error(\n `${label}: a \"to\" column given as a list must be a shared field of union ` +\n `\"${alias}\" (\\`${alias}.columns.<field>\\`). To name a different column per ` +\n `member, pass one list per member instead.`\n );\n }\n\n return Object.values(table.columns).find(\n (c: AnyColumnDefinition) => c.name === column.name\n );\n }),\n ])\n );\n }\n\n const lists = to as Record<string, AnyColumnDefinition[]>;\n const given = Object.keys(lists);\n\n const missing = members.filter(([member]) => !given.includes(member));\n const unknown = given.filter((member) => !members.some(([m]) => m === member));\n\n if (missing.length > 0 || unknown.length > 0) {\n throw new Error(\n `${label} must name one \"to\" column list per member of union \"${alias}\" ` +\n `(${members.map(([member]) => member).join(\", \")})` +\n (missing.length > 0 ? `; missing: ${missing.map(([member]) => member).join(\", \")}` : \"\") +\n (unknown.length > 0 ? `; not members: ${unknown.join(\", \")}` : \"\") +\n `.`\n );\n }\n\n return lists;\n}\n\n/**\n * A belongs-to a union may store which member it points at in a column of its own — the\n * discriminator, holding a member alias. Without one, the member is the first holding the key,\n * computed when the query runs. Has-many and has-one to a union need none, since the key lives\n * on each member, so one there is a mistake.\n */\nfunction validateDiscriminator(\n label: string,\n relation: AnyFieldRelation,\n source: AnyTableDefinition,\n union: string\n): void {\n const { discriminator } = relation;\n\n if (relation.type !== Relation.BELONGS_TO) {\n if (discriminator) {\n throw new Error(\n `${label} declares a discriminator, but only a belongs-to a union needs one: the ` +\n `members of \"${union}\" hold the key.`\n );\n }\n\n return;\n }\n\n if (!discriminator) {\n return;\n }\n\n const alias = findColumnAlias(source, discriminator);\n\n if (!alias) {\n throw new Error(\n `${label}: discriminator \"${discriminator.name}\" is not declared on table \"${source.name}\".`\n );\n }\n\n const dataType = discriminator[\"_dataType\"] as string;\n const textLike =\n discriminator[\"_domain\"] !== undefined ||\n dataType === \"text\" ||\n /^(varchar|char)\\(\\d+\\)$/.test(dataType);\n\n if (!textLike) {\n throw new Error(\n `${label}: discriminator \"${source.name}\".\"${alias}\" is \"${dataType}\"; it holds a ` +\n `member alias, so it must be text, varchar, char, or a text domain.`\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsqlbase/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Core primitives and utilities for dsqlbase",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -62,6 +62,14 @@
|
|
|
62
62
|
"types": "./dist/sql/*.d.ts",
|
|
63
63
|
"default": "./dist/sql/*.js"
|
|
64
64
|
},
|
|
65
|
+
"./resolvers": {
|
|
66
|
+
"types": "./dist/resolvers/index.d.ts",
|
|
67
|
+
"default": "./dist/resolvers/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./validation": {
|
|
70
|
+
"types": "./dist/validation/index.d.ts",
|
|
71
|
+
"default": "./dist/validation/index.js"
|
|
72
|
+
},
|
|
65
73
|
"./utils": {
|
|
66
74
|
"types": "./dist/utils/index.d.ts",
|
|
67
75
|
"default": "./dist/utils/index.js"
|
|
@@ -72,10 +80,11 @@
|
|
|
72
80
|
}
|
|
73
81
|
},
|
|
74
82
|
"scripts": {
|
|
75
|
-
"prebuild": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})
|
|
76
|
-
"build": "tsc",
|
|
77
|
-
"dev": "tsc --watch",
|
|
83
|
+
"prebuild": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\"",
|
|
84
|
+
"build": "tsc -p tsconfig.build.json",
|
|
85
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
78
86
|
"test": "vitest run",
|
|
87
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
79
88
|
"lint": "eslint src --ext .ts",
|
|
80
89
|
"prepack": "node -e \"require('fs').copyFileSync('../../LICENSE','LICENSE')\""
|
|
81
90
|
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { HasDefault } from "../utils/index.js";
|
|
2
|
-
import { DefinitionNode, NodeRef } from "./base.js";
|
|
3
|
-
import { AnyColumnDefinition } from "./column.js";
|
|
4
|
-
export type AnyColumnGroupDefinition = ColumnGroupDefinition<string, any, any>;
|
|
5
|
-
/**
|
|
6
|
-
* Matches a column group by its `kind` rather than by class: comparing a column against the
|
|
7
|
-
* class structurally is costly enough, across a schema's tables, to exhaust the checker.
|
|
8
|
-
*/
|
|
9
|
-
export type GroupOf<TColumns extends TableColumnDefinitions> = {
|
|
10
|
-
readonly kind: "COLUMN_GROUP";
|
|
11
|
-
readonly columns: Readonly<TColumns>;
|
|
12
|
-
};
|
|
13
|
-
/** What a table's `columns` — and an embedded object's — hold: a column, or a group of them. */
|
|
14
|
-
export type AnyTableColumnDefinition = AnyColumnDefinition | AnyColumnGroupDefinition;
|
|
15
|
-
export type TableColumnDefinitions = Record<string, AnyTableColumnDefinition>;
|
|
16
|
-
/**
|
|
17
|
-
* Column refs for a table's — or a group's — columns, as the `check`, `unique`, `primaryKey`
|
|
18
|
-
* and `index` callbacks receive them: a column is a ref, a group the refs of its own columns,
|
|
19
|
-
* so a member reads `c.netValue.amount`.
|
|
20
|
-
*/
|
|
21
|
-
export type ColumnRefs<TColumns extends TableColumnDefinitions> = {
|
|
22
|
-
readonly [K in keyof TColumns]: TColumns[K] extends GroupOf<infer TGroupColumns> ? ColumnRefs<TGroupColumns> : NodeRef<TColumns[K]>;
|
|
23
|
-
};
|
|
24
|
-
/** Any one column ref in {@link ColumnRefs}, however deep. */
|
|
25
|
-
export type ColumnRefOf<TColumns extends TableColumnDefinitions> = {
|
|
26
|
-
[K in keyof TColumns]: TColumns[K] extends GroupOf<infer TGroupColumns> ? ColumnRefOf<TGroupColumns> : NodeRef<TColumns[K]>;
|
|
27
|
-
}[keyof TColumns];
|
|
28
|
-
type MemberDefaultOf<TMember> = TMember extends GroupOf<infer TColumns> ? GroupDefaultOf<TColumns> : TMember extends {
|
|
29
|
-
__type: {
|
|
30
|
-
inputType: infer TInput;
|
|
31
|
-
};
|
|
32
|
-
} ? TInput : never;
|
|
33
|
-
/** What `.default()` on a group takes: a value for any of its members, nested groups included. */
|
|
34
|
-
export type GroupDefaultOf<TColumns extends TableColumnDefinitions> = {
|
|
35
|
-
[K in keyof TColumns]?: MemberDefaultOf<TColumns[K]>;
|
|
36
|
-
};
|
|
37
|
-
export type ColumnGroupConfig<TColumns extends TableColumnDefinitions, THasDefault extends boolean> = {
|
|
38
|
-
columns: TColumns;
|
|
39
|
-
hasDefault: THasDefault;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A reusable set of columns — a value object such as `Money` or `Address` — that a table embeds
|
|
43
|
-
* as real columns through {@link EmbeddedObjectDefinition.column}.
|
|
44
|
-
*
|
|
45
|
-
* The object itself is never placed in a table and produces no DDL. Its members are templates:
|
|
46
|
-
* each `.column()` copies them under a prefixed name, so one object placed twice, on one table
|
|
47
|
-
* or several, never shares a definition.
|
|
48
|
-
*/
|
|
49
|
-
export declare class EmbeddedObjectDefinition<TColumns extends TableColumnDefinitions> extends DefinitionNode<"embedded", {
|
|
50
|
-
columns: TColumns;
|
|
51
|
-
}> {
|
|
52
|
-
readonly kind: "EMBEDDED_OBJECT";
|
|
53
|
-
readonly columns: Readonly<TColumns>;
|
|
54
|
-
constructor(columns: TColumns);
|
|
55
|
-
/**
|
|
56
|
-
* Embeds this object in a table as the group `name`: one real column per member, named
|
|
57
|
-
* `<name>_<member>` — `money.column("net_value")` gives `net_value_amount` and
|
|
58
|
-
* `net_value_currency`. A nested group chains the prefix: `billing_geo_lat`.
|
|
59
|
-
*/
|
|
60
|
-
column<TName extends string>(name: TName): ColumnGroupDefinition<TName, TColumns, false>;
|
|
61
|
-
}
|
|
62
|
-
export type AnyEmbeddedObjectDefinition = EmbeddedObjectDefinition<any>;
|
|
63
|
-
/**
|
|
64
|
-
* An embedded object placed in a table: its own copies of the object's members, named with the
|
|
65
|
-
* group's prefix. A table's `columns` may hold one wherever it holds a column.
|
|
66
|
-
*
|
|
67
|
-
* A group has no nullability of its own. Each member keeps its own `.notNull()` as its column's
|
|
68
|
-
* `NOT NULL`; a group whose members are all nullable can be absent, which it is when all of
|
|
69
|
-
* them are `NULL`.
|
|
70
|
-
*/
|
|
71
|
-
export declare class ColumnGroupDefinition<TName extends string, TColumns extends TableColumnDefinitions, THasDefault extends boolean = false> extends DefinitionNode<TName, ColumnGroupConfig<TColumns, THasDefault>> {
|
|
72
|
-
readonly kind: "COLUMN_GROUP";
|
|
73
|
-
readonly object: EmbeddedObjectDefinition<TColumns>;
|
|
74
|
-
readonly columns: Readonly<TColumns>;
|
|
75
|
-
protected _default?: GroupDefaultOf<TColumns>;
|
|
76
|
-
constructor(name: TName, object: EmbeddedObjectDefinition<TColumns>);
|
|
77
|
-
/**
|
|
78
|
-
* Defaults for the group's members — `address.column("billing").default({ city: "-" })` is
|
|
79
|
-
* `.default("-")` on `billing_city`. Members not named keep their own default, if any.
|
|
80
|
-
*/
|
|
81
|
-
default(value: GroupDefaultOf<TColumns>): HasDefault<ColumnGroupDefinition<TName, TColumns, true>>;
|
|
82
|
-
toJSON(): {
|
|
83
|
-
kind: "COLUMN_GROUP";
|
|
84
|
-
name: TName;
|
|
85
|
-
columns: {
|
|
86
|
-
readonly kind: "COLUMN";
|
|
87
|
-
readonly name: string;
|
|
88
|
-
readonly dataType: string;
|
|
89
|
-
readonly notNull: boolean;
|
|
90
|
-
readonly primaryKey: boolean;
|
|
91
|
-
readonly unique: boolean;
|
|
92
|
-
readonly defaultValue: string | null;
|
|
93
|
-
readonly check: {
|
|
94
|
-
readonly kind: "CHECK_CONSTRAINT";
|
|
95
|
-
readonly name: string;
|
|
96
|
-
readonly expression: string;
|
|
97
|
-
readonly validated: boolean;
|
|
98
|
-
} | null;
|
|
99
|
-
readonly domain: string | null;
|
|
100
|
-
readonly generated: {
|
|
101
|
-
type: "ALWAYS";
|
|
102
|
-
expression: string;
|
|
103
|
-
mode: "STORED";
|
|
104
|
-
} | null;
|
|
105
|
-
readonly identity: {
|
|
106
|
-
type: import("./column.js").ColumnGeneratedType;
|
|
107
|
-
sequenceName: string | undefined;
|
|
108
|
-
options: {
|
|
109
|
-
dataType: string | undefined;
|
|
110
|
-
cache: number | undefined;
|
|
111
|
-
cycle: boolean | undefined;
|
|
112
|
-
increment: number | undefined;
|
|
113
|
-
minValue: number | undefined;
|
|
114
|
-
maxValue: number | undefined;
|
|
115
|
-
startValue: number | undefined;
|
|
116
|
-
ownedBy: string | undefined;
|
|
117
|
-
} | null;
|
|
118
|
-
} | null;
|
|
119
|
-
readonly deprecated: boolean;
|
|
120
|
-
readonly renamedFrom: string | null;
|
|
121
|
-
}[];
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Every real column under `columns`, groups walked depth first, each with its field path —
|
|
126
|
-
* `["netValue", "amount"]`. What reaches the database: DDL, the duplicate-name check, tenant
|
|
127
|
-
* claims.
|
|
128
|
-
*/
|
|
129
|
-
export declare function columnEntries(columns: Readonly<TableColumnDefinitions>, path?: string[]): [path: string[], column: AnyColumnDefinition][];
|
|
130
|
-
export {};
|
|
131
|
-
//# sourceMappingURL=embedded.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../src/definition/embedded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAQ,OAAO,EAAwB,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAoB,MAAM,aAAa,CAAC;AAGpE,MAAM,MAAM,wBAAwB,GAAG,qBAAqB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE/E;;;GAGG;A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