uql-orm 0.105.0 → 0.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/querier/httpQuerier.d.ts +3 -3
- package/dist/browser/type/clientQuerier.d.ts +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +6 -6
- package/dist/cockroachdb/cockroachDialect.d.ts +2 -2
- package/dist/dialect/abstractDialect.d.ts +3 -3
- package/dist/dialect/abstractSqlDialect.d.ts +35 -35
- package/dist/dialect/mergeSqlDialect.d.ts +2 -2
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +6 -6
- package/dist/dialect/queryJoins.d.ts +2 -2
- package/dist/entity/columnOptionsBuilder.d.ts +3 -3
- package/dist/entity/columnOptionsBuilder.js +3 -5
- package/dist/entity/decorator/bag.d.ts +2 -2
- package/dist/entity/decorator/entity.d.ts +2 -2
- package/dist/entity/decorator/members.d.ts +1 -1
- package/dist/entity/metadata/definition.d.ts +12 -7
- package/dist/entity/metadata/definition.js +84 -87
- package/dist/entity/metadata/schemaFixture/animal.d.ts +17 -5
- package/dist/entity/metadata/schemaFixture/author.d.ts +12 -12
- package/dist/entity/metadata/schemaFixture/author.js +3 -3
- package/dist/entity/metadata/schemaFixture/book.d.ts +20 -20
- package/dist/entity/metadata/schemaFixture/book.js +2 -1
- package/dist/http/contract.d.ts +2 -2
- package/dist/http/handler.d.ts +2 -2
- package/dist/mariadb/mariaDialect.d.ts +2 -2
- package/dist/migrate/cli.js +13 -13
- package/dist/migrate/codegen/entityTypes.d.ts +2 -2
- package/dist/migrate/migrator.d.ts +2 -2
- package/dist/migrate/schemaGenerator.d.ts +5 -5
- package/dist/mongodb/mongoDialect.d.ts +12 -12
- package/dist/mongodb/mongoSchemaGenerator.d.ts +4 -4
- package/dist/mssql/mssqlDialect.d.ts +4 -4
- package/dist/pglite/pgliteQuerierPool.d.ts +2 -2
- package/dist/postgres/postgresDialect.d.ts +2 -2
- package/dist/querier/abstractSqlQuerier.d.ts +1 -1
- package/dist/schema/schemaASTBuilder.d.ts +4 -4
- package/dist/sqlite/localSqliteQuerierPool.d.ts +3 -2
- package/dist/type/column.d.ts +23 -22
- package/dist/type/config.d.ts +2 -2
- package/dist/type/dialect.d.ts +13 -13
- package/dist/type/entity.d.ts +22 -39
- package/dist/type/index.d.ts +1 -0
- package/dist/type/index.js +1 -0
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +2 -2
- package/dist/type/query.d.ts +1 -1
- package/dist/type/querySql.d.ts +2 -2
- package/dist/type/schemaEntity.d.ts +59 -58
- package/dist/type/standardSchema.d.ts +28 -0
- package/dist/type/standardSchema.js +1 -0
- package/dist/type/utility.d.ts +25 -33
- package/dist/util/fieldOption.util.js +1 -1
- package/dist/util/hook.util.d.ts +2 -2
- package/dist/util/sql.d.ts +4 -6
- package/dist/util/sql.js +0 -4
- package/dist/util/triggerWrite.d.ts +5 -5
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +26 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { COLUMN_OPTIONS, REF_KEY, RelationAggregate, SECTION_ENTRY, SOFT_DELETE_FILTER, } from '../../type/index.js';
|
|
2
2
|
import { aggregateField, defaultReadKeys, fieldKeys, isInlinedExpression } from '../../util/field.util.js';
|
|
3
|
-
import { fieldOptionConflict, findVectorIndex, valueTypesOf, hasKeys, holdsForeignKey, isCascadable, isToManyRelation, indexRefs, memberRefs,
|
|
3
|
+
import { fieldOptionConflict, findVectorIndex, valueTypesOf, hasKeys, holdsForeignKey, isCascadable, isToManyRelation, indexRefs, memberRefs, fulltextWeights, normalizeIndexColumn, definedEntries, isRecord, whereWith, } from '../../util/index.js';
|
|
4
4
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
5
5
|
import { ownRegistrations } from '../decorator/bag.js';
|
|
6
6
|
/**
|
|
@@ -36,7 +36,11 @@ function addField(meta, key, opts) {
|
|
|
36
36
|
// Flagged when the author gave `references` but no `type`, so schema generation knows to resolve the
|
|
37
37
|
// column from the referenced primary key (picking up its `columnType`, length and chained keys)
|
|
38
38
|
// instead of treating whatever ends up in `type` as deliberate.
|
|
39
|
-
|
|
39
|
+
fieldStore(meta)[key] = { name: key, ...opts, ...(!opts.type && { typeFromReference: true }) };
|
|
40
|
+
}
|
|
41
|
+
/** `meta`'s fields as a store a key is written into: a generic entity's fields are read-only by type. */
|
|
42
|
+
function fieldStore(meta) {
|
|
43
|
+
return meta.fields;
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* `opts` as the registry takes them: `mappedBy` and `references` read off their key maps down to the
|
|
@@ -163,27 +167,21 @@ export function defineEntity(schema) {
|
|
|
163
167
|
}[schema.name];
|
|
164
168
|
metas.set(entity, { ...emptyMeta(entity), stage: 'declared' });
|
|
165
169
|
declaredSchemas.set(entity, { schema, sections: {} });
|
|
166
|
-
for (const section of
|
|
170
|
+
for (const section of SECTIONS) {
|
|
167
171
|
Object.defineProperty(entity, section, {
|
|
168
|
-
value(
|
|
172
|
+
value(declared, derived) {
|
|
169
173
|
declareSection(this, section, declared);
|
|
174
|
+
if (section === 'relations' && derived) {
|
|
175
|
+
declareSection(this, 'derived', derived);
|
|
176
|
+
}
|
|
170
177
|
return this;
|
|
171
178
|
},
|
|
172
179
|
});
|
|
173
180
|
}
|
|
174
181
|
return entity;
|
|
175
182
|
}
|
|
176
|
-
/** The sections a schema declares as methods. `
|
|
177
|
-
const SECTIONS =
|
|
178
|
-
computed: true,
|
|
179
|
-
indexes: true,
|
|
180
|
-
checks: true,
|
|
181
|
-
triggers: true,
|
|
182
|
-
filters: true,
|
|
183
|
-
hooks: true,
|
|
184
|
-
references: true,
|
|
185
|
-
relations: true,
|
|
186
|
-
};
|
|
183
|
+
/** The sections a schema declares as methods. `derived` is no method: `relations` takes it as its second argument. */
|
|
184
|
+
const SECTIONS = ['computed', 'indexes', 'checks', 'triggers', 'filters', 'hooks', 'relations'];
|
|
187
185
|
/** Records one section of a pending schema, refusing a second of it and one declared after the entity was read. */
|
|
188
186
|
function declareSection(entity, section, declared) {
|
|
189
187
|
const pending = pendingSchema(entity);
|
|
@@ -193,8 +191,7 @@ function declareSection(entity, section, declared) {
|
|
|
193
191
|
if (section in pending.sections) {
|
|
194
192
|
throw new UqlUsageError(`'${entity.name}' declares its ${section} twice: declare them in one call`);
|
|
195
193
|
}
|
|
196
|
-
|
|
197
|
-
Object.assign(pending.sections, { [section]: first }, section === 'relations' && aggregates && { aggregates });
|
|
194
|
+
Object.assign(pending.sections, { [section]: declared });
|
|
198
195
|
}
|
|
199
196
|
/** What `entity` declared as a schema, while it is not registered yet. */
|
|
200
197
|
function pendingSchema(entity) {
|
|
@@ -207,11 +204,12 @@ function settleSchema(entity) {
|
|
|
207
204
|
return;
|
|
208
205
|
}
|
|
209
206
|
const { schema, sections } = pending;
|
|
210
|
-
const fields =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
207
|
+
const fields = fieldsOf(schema.name, schema.fields);
|
|
208
|
+
const refs = memberRefs();
|
|
209
|
+
for (const added of [
|
|
210
|
+
fieldsOf(schema.name, sections.computed?.(refs) ?? {}),
|
|
211
|
+
fieldsOf(schema.name, readDerived(sections.derived, refs)),
|
|
212
|
+
]) {
|
|
215
213
|
const taken = Object.keys(added).find((key) => key in fields);
|
|
216
214
|
if (taken) {
|
|
217
215
|
throw new UqlUsageError(`'${schema.name}.${taken}' is declared twice: name each member once`);
|
|
@@ -231,24 +229,6 @@ function settleSchema(entity) {
|
|
|
231
229
|
hooks: Object.fromEntries(definedEntries(sections.hooks ?? {}).map(([event, runs]) => [event, runs.map((run) => ({ run }))])),
|
|
232
230
|
});
|
|
233
231
|
}
|
|
234
|
-
/** Each foreign key `.references()` names, written onto its column as `@Field`'s `references()` would. */
|
|
235
|
-
function referencedFields(name, fields, references) {
|
|
236
|
-
return Object.fromEntries(Object.entries(references ?? {}).map(([key, target]) => {
|
|
237
|
-
const column = fields[key]?.[COLUMN_OPTIONS];
|
|
238
|
-
if (!column) {
|
|
239
|
-
throw new UqlUsageError(`'.references()' names '${name}.${key}', which is no column of its 'fields'`);
|
|
240
|
-
}
|
|
241
|
-
const { entity, ...action } = typeof target === 'function' ? { entity: target } : target;
|
|
242
|
-
return [key, { ...column, ...action, references: () => entityOf(entity(), key) }];
|
|
243
|
-
}));
|
|
244
|
-
}
|
|
245
|
-
/** The entity a getter returned, refused where it returned anything else. */
|
|
246
|
-
function entityOf(target, key) {
|
|
247
|
-
if (!metas.has(target)) {
|
|
248
|
-
throw new UqlUsageError(`'.references()' points '${key}' at something that is not an entity`);
|
|
249
|
-
}
|
|
250
|
-
return target;
|
|
251
|
-
}
|
|
252
232
|
/** An index as a section's `index(columns, options)` writes it, a bare string its name. */
|
|
253
233
|
function indexEntry(columns, options) {
|
|
254
234
|
const stated = typeof options === 'string' ? { name: options } : options;
|
|
@@ -260,25 +240,26 @@ function checkEntry(where, name) {
|
|
|
260
240
|
function triggerEntry(trigger) {
|
|
261
241
|
return { ...trigger, [SECTION_ENTRY]: 'trigger' };
|
|
262
242
|
}
|
|
263
|
-
/** The options
|
|
264
|
-
function
|
|
265
|
-
return Object.fromEntries(Object.entries(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return columnOptions(computed?.(memberRefs()) ?? {});
|
|
270
|
-
}
|
|
271
|
-
/** A schema's aggregates as the computed fields they read as, through the refs a decorated `@Computed` reads. */
|
|
272
|
-
function aggregateFields(name, aggregates) {
|
|
273
|
-
return Object.fromEntries(Object.entries(aggregates?.(relationRefs()) ?? {}).map(([key, read]) => {
|
|
274
|
-
const aggregate = typeof read === 'function' ? read() : undefined;
|
|
243
|
+
/** The fields a section's values define: a column's options, or an aggregate, which reads as a computed column. */
|
|
244
|
+
function fieldsOf(name, values) {
|
|
245
|
+
return Object.fromEntries(Object.entries(values).map(([key, field]) => {
|
|
246
|
+
if (field instanceof RelationAggregate) {
|
|
247
|
+
return [key, aggregateField(field)];
|
|
248
|
+
}
|
|
275
249
|
// The types refuse anything else; an untyped caller still reaches here.
|
|
276
|
-
if (!(
|
|
277
|
-
throw new UqlUsageError(`'${name}.${key}'
|
|
250
|
+
if (!isColumn(field)) {
|
|
251
|
+
throw new UqlUsageError(`'${name}.${key}' is neither a column nor an aggregate: declare it as one`);
|
|
278
252
|
}
|
|
279
|
-
return [key,
|
|
253
|
+
return [key, field[COLUMN_OPTIONS]];
|
|
280
254
|
}));
|
|
281
255
|
}
|
|
256
|
+
function isColumn(field) {
|
|
257
|
+
return isRecord(field) && COLUMN_OPTIONS in field;
|
|
258
|
+
}
|
|
259
|
+
/** A relation's derived fields, each a thunk read lazily; a value that is no thunk is passed on to be refused. */
|
|
260
|
+
function readDerived(derived, refs) {
|
|
261
|
+
return Object.fromEntries(Object.entries(derived?.(refs) ?? {}).map(([key, read]) => [key, typeof read === 'function' ? read() : read]));
|
|
262
|
+
}
|
|
282
263
|
const RELATION_BUILDER = {
|
|
283
264
|
oneToOne: (target, options) => ({ target, cardinality: '11', options }),
|
|
284
265
|
manyToOne: (target, options) => ({ target, cardinality: 'm1', options }),
|
|
@@ -299,7 +280,7 @@ function settleRelations(meta) {
|
|
|
299
280
|
const declared = declaredSchemas.get(meta.entity)?.sections.relations;
|
|
300
281
|
for (const [key, read] of Object.entries(declared?.(RELATION_BUILDER) ?? {})) {
|
|
301
282
|
const { target, cardinality, options } = read();
|
|
302
|
-
addRelation(meta, key, relationRegistration({ ...options, cardinality, entity: () => target }));
|
|
283
|
+
addRelation(meta, key, relationRegistration({ ...options, cardinality, entity: () => tableOf(target) }));
|
|
303
284
|
}
|
|
304
285
|
// A copy per entity: resolving a relation writes the columns it joins on into it, and those are the resolving
|
|
305
286
|
// entity's, so one shared object would leave every later entity without them.
|
|
@@ -461,7 +442,21 @@ export function getEntities() {
|
|
|
461
442
|
for (const entity of metas.keys()) {
|
|
462
443
|
settleSchema(entity);
|
|
463
444
|
}
|
|
464
|
-
return [...metas.values()]
|
|
445
|
+
return [...metas.values()]
|
|
446
|
+
.filter((meta) => meta.ids.length)
|
|
447
|
+
.map((meta) => meta.entity)
|
|
448
|
+
.filter(isTable);
|
|
449
|
+
}
|
|
450
|
+
/** The class a schema relation targets, refused where it is abstract: a relation needs a table to join. */
|
|
451
|
+
function tableOf(target) {
|
|
452
|
+
if (!isTable(target)) {
|
|
453
|
+
throw new UqlUsageError(`'${target.name}' is abstract: a relation needs a table to join`);
|
|
454
|
+
}
|
|
455
|
+
return target;
|
|
456
|
+
}
|
|
457
|
+
/** Whether `entity` is a table: not marked abstract, so a query or write can take it. */
|
|
458
|
+
function isTable(entity) {
|
|
459
|
+
return !metas.get(entity)?.abstract;
|
|
465
460
|
}
|
|
466
461
|
/** The metadata `entity` has, a pending schema registered first, without settling anything further. */
|
|
467
462
|
function knownMeta(entity) {
|
|
@@ -635,34 +630,33 @@ function fillInverseSide(at, meta, relOpts, mappedBy) {
|
|
|
635
630
|
return relOpts.references;
|
|
636
631
|
}
|
|
637
632
|
/**
|
|
638
|
-
* Refuses a join on a column either entity does not store,
|
|
639
|
-
*
|
|
633
|
+
* Refuses a join on a column either entity does not store, a one-column join whose foreign key, on whichever
|
|
634
|
+
* side holds it, points at another entity, and a join whose column holds another kind of value than its key.
|
|
640
635
|
*/
|
|
641
636
|
function assertJoins(at, meta, relOpts, pairs) {
|
|
642
637
|
const target = registeredMeta(relOpts.entity());
|
|
643
638
|
// Only the owning side of a to-one holds its foreign key; an inverse side and a to-many join on the target's.
|
|
644
639
|
const holdsLocally = holdsForeignKey(relOpts);
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
{ meta
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const column = `'${side.meta.entity.name}.${key}'`;
|
|
652
|
-
const field = side.meta.fields[key];
|
|
653
|
-
if (!field || isInlinedExpression(field)) {
|
|
654
|
-
throw new UqlUsageError(`${at} joins ${column}, which is not a column: declare it with '@Field'.`);
|
|
655
|
-
}
|
|
656
|
-
const referenced = side.holds && pairs.length === 1 ? field.references?.() : undefined;
|
|
657
|
-
if (referenced && !isA(side.joins, referenced)) {
|
|
658
|
-
throw new UqlUsageError(`${at} joins ${column}, a foreign key to '${referenced.name}', not to '${side.joins.name}'.`);
|
|
659
|
-
}
|
|
640
|
+
const single = pairs.length === 1;
|
|
641
|
+
for (const { local, foreign } of pairs) {
|
|
642
|
+
assertJoinColumn(at, { meta, key: local, joins: target.entity, holds: holdsLocally && single });
|
|
643
|
+
assertJoinColumn(at, { meta: target, key: foreign, joins: meta.entity, holds: !holdsLocally && single });
|
|
644
|
+
if (holdsLocally) {
|
|
645
|
+
assertKindsJoin(at, fieldOf(meta, local), valueFieldOf(fieldOf(target, foreign)), target.entity.name);
|
|
660
646
|
}
|
|
661
647
|
}
|
|
662
648
|
}
|
|
663
|
-
/**
|
|
664
|
-
function
|
|
665
|
-
|
|
649
|
+
/** Refuses a join column that is no column, or a foreign key to another entity than the one it joins. */
|
|
650
|
+
function assertJoinColumn(at, side) {
|
|
651
|
+
const column = `'${side.meta.entity.name}.${side.key}'`;
|
|
652
|
+
const field = side.meta.fields[side.key];
|
|
653
|
+
if (!field || isInlinedExpression(field)) {
|
|
654
|
+
throw new UqlUsageError(`${at} joins ${column}, which is not a column: declare it with '@Field'.`);
|
|
655
|
+
}
|
|
656
|
+
const referenced = side.holds ? field.references?.() : undefined;
|
|
657
|
+
if (referenced && !isA(side.joins, referenced)) {
|
|
658
|
+
throw new UqlUsageError(`${at} joins ${column}, a foreign key to '${referenced.name}', not to '${side.joins.name}'.`);
|
|
659
|
+
}
|
|
666
660
|
}
|
|
667
661
|
/** Whether `entity` is `base` or extends it, as an entity inheriting a relation does. */
|
|
668
662
|
function isA(entity, base) {
|
|
@@ -685,9 +679,12 @@ export function foreignKeysOf(meta) {
|
|
|
685
679
|
if (!field.references)
|
|
686
680
|
return [];
|
|
687
681
|
const target = knownMeta(field.references());
|
|
688
|
-
|
|
682
|
+
// A joined column's kinds were checked when its relation settled.
|
|
689
683
|
if (joined.has(key) || !target.ids.length)
|
|
690
684
|
return [];
|
|
685
|
+
if (!field.typeFromReference && target.ids.length === 1) {
|
|
686
|
+
assertKindsJoin(`'${meta.entity.name}.${key}'`, field, valueFieldOf(fieldOf(target, target.ids[0])), target.entity.name);
|
|
687
|
+
}
|
|
691
688
|
if (target.ids.length > 1) {
|
|
692
689
|
throw new UqlUsageError(`'${meta.entity.name}.${key}' cannot reference '${target.entity.name}', whose primary key is composite ` +
|
|
693
690
|
`(${target.ids.join(', ')}): a column points at one. Declare a column per key and pair each with it ` +
|
|
@@ -697,24 +694,24 @@ export function foreignKeysOf(meta) {
|
|
|
697
694
|
});
|
|
698
695
|
return [...owning, ...columns];
|
|
699
696
|
}
|
|
700
|
-
/** The kinds a column of `type` holds as a join compares them, as `
|
|
697
|
+
/** The kinds a column of `type` holds as a join compares them, as `JoinKind` does: a bigint is a number, which BIGINT widens. */
|
|
701
698
|
function joinedKinds(type) {
|
|
702
699
|
const types = valueTypesOf(type);
|
|
703
700
|
return types && [...new Set(types.map((kind) => (kind === 'bigint' ? 'number' : kind)))];
|
|
704
701
|
}
|
|
705
|
-
/** Refuses a
|
|
706
|
-
function
|
|
707
|
-
|
|
702
|
+
/** Refuses a join whose column holds another kind of value than the key it joins to, which no join matches. */
|
|
703
|
+
function assertKindsJoin(at, held, key, target) {
|
|
704
|
+
const heldKinds = joinedKinds(held.type);
|
|
705
|
+
if (!heldKinds)
|
|
708
706
|
return;
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
throw new UqlUsageError(`${at} holds a ${held.join(' or ')}, but the key of '${target.entity.name}' it references is a ${needed.join(' or ')}`);
|
|
707
|
+
const neededKinds = joinedKinds(key.type);
|
|
708
|
+
if (neededKinds && !neededKinds.every((kind) => heldKinds.includes(kind))) {
|
|
709
|
+
throw new UqlUsageError(`${at} holds a ${heldKinds.join(' or ')}, but the key of '${target}' it references is a ${neededKinds.join(' or ')}`);
|
|
713
710
|
}
|
|
714
711
|
}
|
|
715
712
|
/** Each key of `side`, paired with the one column of `junction` referencing it: a rename of either follows. */
|
|
716
713
|
function junctionReferences(at, junction, side) {
|
|
717
|
-
const pairs = foreignKeysOf(junction).flatMap(({ entity, references }) => entity()
|
|
714
|
+
const pairs = foreignKeysOf(junction).flatMap(({ entity, references }) => Object.is(entity(), side.entity) ? references : []);
|
|
718
715
|
return side.ids.map((key) => {
|
|
719
716
|
const [pair, ...others] = pairs.filter(({ foreign }) => foreign === key);
|
|
720
717
|
const referenced = `'${side.entity.name}.${key}'`;
|
|
@@ -10,11 +10,11 @@ export declare const Animal: import("../../../index.js").SchemaEntity<object & {
|
|
|
10
10
|
readonly name: import("../../../index.js").StringColumn<{
|
|
11
11
|
readonly type: StringConstructor;
|
|
12
12
|
}, string>;
|
|
13
|
-
}>, number, {
|
|
13
|
+
}, object>, number, {
|
|
14
14
|
id: number;
|
|
15
15
|
name: string;
|
|
16
16
|
} & {}, object>;
|
|
17
|
-
export declare const Dog: import("../../../index.js").SchemaEntity<object & {
|
|
17
|
+
export declare const Dog: import("../../../index.js").SchemaEntity<import("../../../index.js").Except<object & {
|
|
18
18
|
id: number;
|
|
19
19
|
name: string;
|
|
20
20
|
} & {} & import("../../../index.js").Brands<{
|
|
@@ -26,7 +26,7 @@ export declare const Dog: import("../../../index.js").SchemaEntity<object & {
|
|
|
26
26
|
readonly name: import("../../../index.js").StringColumn<{
|
|
27
27
|
readonly type: StringConstructor;
|
|
28
28
|
}, string>;
|
|
29
|
-
}> & {} & {
|
|
29
|
+
}, object>, typeof import("../../../index.js").idKey | typeof import("../../../index.js").versionKey | typeof import("../../../index.js").filledKey> & {} & {
|
|
30
30
|
tricks?: number | null | undefined;
|
|
31
31
|
} & import("../../../index.js").Brands<{
|
|
32
32
|
readonly tricks: import("../../../index.js").NumericColumn<{
|
|
@@ -34,7 +34,19 @@ export declare const Dog: import("../../../index.js").SchemaEntity<object & {
|
|
|
34
34
|
} & {
|
|
35
35
|
readonly nullable: true;
|
|
36
36
|
}, number>;
|
|
37
|
-
}
|
|
37
|
+
}, object & {
|
|
38
|
+
id: number;
|
|
39
|
+
name: string;
|
|
40
|
+
} & {} & import("../../../index.js").Brands<{
|
|
41
|
+
readonly id: import("../../../index.js").NumericColumn<{
|
|
42
|
+
readonly type: NumberConstructor;
|
|
43
|
+
} & {
|
|
44
|
+
readonly isId: true;
|
|
45
|
+
}, number>;
|
|
46
|
+
readonly name: import("../../../index.js").StringColumn<{
|
|
47
|
+
readonly type: StringConstructor;
|
|
48
|
+
}, string>;
|
|
49
|
+
}, object>>, number, {
|
|
38
50
|
id: number;
|
|
39
51
|
name: string;
|
|
40
52
|
} & {} & {} & {
|
|
@@ -51,4 +63,4 @@ export declare const Dog: import("../../../index.js").SchemaEntity<object & {
|
|
|
51
63
|
readonly name: import("../../../index.js").StringColumn<{
|
|
52
64
|
readonly type: StringConstructor;
|
|
53
65
|
}, string>;
|
|
54
|
-
}>>;
|
|
66
|
+
}, object>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const Author: import("../../../index.js").
|
|
1
|
+
export declare const Author: import("../../../index.js").RelatedEntity<object & {
|
|
2
2
|
id: number;
|
|
3
3
|
name: string;
|
|
4
4
|
createdAt: Date;
|
|
@@ -23,7 +23,7 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
23
23
|
} & {
|
|
24
24
|
readonly defaultValue: unknown;
|
|
25
25
|
}, Date>;
|
|
26
|
-
}> & import("../../../index.js").RelationRow<{
|
|
26
|
+
}, object> & import("../../../index.js").RelationRow<{
|
|
27
27
|
readonly books: () => import("../../../index.js").SchemaRelation<object & {
|
|
28
28
|
id: number;
|
|
29
29
|
title: string;
|
|
@@ -56,9 +56,9 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
56
56
|
readonly authorId: import("../../../index.js").NumericColumn<{
|
|
57
57
|
readonly type: NumberConstructor;
|
|
58
58
|
}, number>;
|
|
59
|
-
}> & {
|
|
60
|
-
readonly shout
|
|
61
|
-
} & import("../../../index.js").RelationRow<{
|
|
59
|
+
}, object> & {
|
|
60
|
+
readonly shout: string | null;
|
|
61
|
+
} & {} & import("../../../index.js").RelationRow<{
|
|
62
62
|
readonly author: () => import("../../../index.js").SchemaRelation<object & {
|
|
63
63
|
id: number;
|
|
64
64
|
name: string;
|
|
@@ -84,7 +84,7 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
84
84
|
} & {
|
|
85
85
|
readonly defaultValue: unknown;
|
|
86
86
|
}, Date>;
|
|
87
|
-
}> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").
|
|
87
|
+
}, object> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").DerivedRow<{
|
|
88
88
|
readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
|
|
89
89
|
readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
|
|
90
90
|
}>, "m1", object & {
|
|
@@ -112,11 +112,11 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
112
112
|
} & {
|
|
113
113
|
readonly defaultValue: unknown;
|
|
114
114
|
}, Date>;
|
|
115
|
-
}> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").
|
|
115
|
+
}, object> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").DerivedRow<{
|
|
116
116
|
readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
|
|
117
117
|
readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
|
|
118
118
|
}>>;
|
|
119
|
-
}> & import("../../../index.js").
|
|
119
|
+
}> & import("../../../index.js").DerivedRow<{}>, "1m", {
|
|
120
120
|
id: number;
|
|
121
121
|
title: string;
|
|
122
122
|
stock: number;
|
|
@@ -124,9 +124,9 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
124
124
|
version: number;
|
|
125
125
|
authorId: number;
|
|
126
126
|
} & {} & {
|
|
127
|
-
readonly shout
|
|
128
|
-
}>;
|
|
129
|
-
}> & import("../../../index.js").
|
|
127
|
+
readonly shout: string | null;
|
|
128
|
+
} & {}>;
|
|
129
|
+
}> & import("../../../index.js").DerivedRow<{
|
|
130
130
|
readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
|
|
131
131
|
readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
|
|
132
132
|
}>, number, {
|
|
@@ -135,6 +135,6 @@ export declare const Author: import("../../../index.js").SchemaClass<object & {
|
|
|
135
135
|
createdAt: Date;
|
|
136
136
|
} & {
|
|
137
137
|
bio?: string | null | undefined;
|
|
138
|
-
}>;
|
|
138
|
+
}, false>;
|
|
139
139
|
export type Author = InstanceType<typeof Author>;
|
|
140
140
|
export declare const label: (author: Author) => string;
|
|
@@ -18,8 +18,8 @@ export const Author = defineEntity({
|
|
|
18
18
|
},
|
|
19
19
|
],
|
|
20
20
|
})
|
|
21
|
-
.relations((rel) => ({ books: () => rel.oneToMany(Book, { mappedBy: (book) => book.author }) }), (
|
|
22
|
-
bookCount: () =>
|
|
23
|
-
topStock: () =>
|
|
21
|
+
.relations((rel) => ({ books: () => rel.oneToMany(Book, { mappedBy: (book) => book.author }) }), (author) => ({
|
|
22
|
+
bookCount: () => author.books.count(),
|
|
23
|
+
topStock: () => author.books.max((book) => book.stock),
|
|
24
24
|
}));
|
|
25
25
|
export const label = (author) => `${author.name} (${author.books?.length ?? 0})`;
|
|
@@ -30,9 +30,9 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
30
30
|
readonly authorId: import("../../../index.js").NumericColumn<{
|
|
31
31
|
readonly type: NumberConstructor;
|
|
32
32
|
}, number>;
|
|
33
|
-
}> & {
|
|
34
|
-
readonly shout
|
|
35
|
-
} & import("../../../index.js").RelationRow<{
|
|
33
|
+
}, object> & {
|
|
34
|
+
readonly shout: string | null;
|
|
35
|
+
} & {} & import("../../../index.js").RelationRow<{
|
|
36
36
|
readonly author: () => import("../../../index.js").SchemaRelation<object & {
|
|
37
37
|
id: number;
|
|
38
38
|
name: string;
|
|
@@ -58,7 +58,7 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
58
58
|
} & {
|
|
59
59
|
readonly defaultValue: unknown;
|
|
60
60
|
}, Date>;
|
|
61
|
-
}> & import("../../../index.js").RelationRow<{
|
|
61
|
+
}, object> & import("../../../index.js").RelationRow<{
|
|
62
62
|
readonly books: () => import("../../../index.js").SchemaRelation<object & {
|
|
63
63
|
id: number;
|
|
64
64
|
title: string;
|
|
@@ -91,9 +91,9 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
91
91
|
readonly authorId: import("../../../index.js").NumericColumn<{
|
|
92
92
|
readonly type: NumberConstructor;
|
|
93
93
|
}, number>;
|
|
94
|
-
}> & {
|
|
95
|
-
readonly shout
|
|
96
|
-
} & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").
|
|
94
|
+
}, object> & {
|
|
95
|
+
readonly shout: string | null;
|
|
96
|
+
} & {} & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").DerivedRow<{}>, "1m", {
|
|
97
97
|
id: number;
|
|
98
98
|
title: string;
|
|
99
99
|
stock: number;
|
|
@@ -101,9 +101,9 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
101
101
|
version: number;
|
|
102
102
|
authorId: number;
|
|
103
103
|
} & {} & {
|
|
104
|
-
readonly shout
|
|
105
|
-
}>;
|
|
106
|
-
}> & import("../../../index.js").
|
|
104
|
+
readonly shout: string | null;
|
|
105
|
+
} & {}>;
|
|
106
|
+
}> & import("../../../index.js").DerivedRow<{
|
|
107
107
|
readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
|
|
108
108
|
readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
|
|
109
109
|
}>, "m1", object & {
|
|
@@ -131,7 +131,7 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
131
131
|
} & {
|
|
132
132
|
readonly defaultValue: unknown;
|
|
133
133
|
}, Date>;
|
|
134
|
-
}> & import("../../../index.js").RelationRow<{
|
|
134
|
+
}, object> & import("../../../index.js").RelationRow<{
|
|
135
135
|
readonly books: () => import("../../../index.js").SchemaRelation<object & {
|
|
136
136
|
id: number;
|
|
137
137
|
title: string;
|
|
@@ -164,9 +164,9 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
164
164
|
readonly authorId: import("../../../index.js").NumericColumn<{
|
|
165
165
|
readonly type: NumberConstructor;
|
|
166
166
|
}, number>;
|
|
167
|
-
}> & {
|
|
168
|
-
readonly shout
|
|
169
|
-
} & import("../../../index.js").RelationRow<any> & import("../../../index.js").
|
|
167
|
+
}, object> & {
|
|
168
|
+
readonly shout: string | null;
|
|
169
|
+
} & {} & import("../../../index.js").RelationRow<any> & import("../../../index.js").DerivedRow<{}>, "1m", {
|
|
170
170
|
id: number;
|
|
171
171
|
title: string;
|
|
172
172
|
stock: number;
|
|
@@ -174,13 +174,13 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
174
174
|
version: number;
|
|
175
175
|
authorId: number;
|
|
176
176
|
} & {} & {
|
|
177
|
-
readonly shout
|
|
178
|
-
}>;
|
|
179
|
-
}> & import("../../../index.js").
|
|
177
|
+
readonly shout: string | null;
|
|
178
|
+
} & {}>;
|
|
179
|
+
}> & import("../../../index.js").DerivedRow<{
|
|
180
180
|
readonly bookCount: () => import("../../../index.js").RelationAggregate<number>;
|
|
181
181
|
readonly topStock: () => import("../../../index.js").RelationAggregate<number | null>;
|
|
182
182
|
}>>;
|
|
183
|
-
}> & import("../../../index.js").
|
|
183
|
+
}> & import("../../../index.js").DerivedRow<{}>, number, {
|
|
184
184
|
id: number;
|
|
185
185
|
title: string;
|
|
186
186
|
stock: number;
|
|
@@ -188,5 +188,5 @@ export declare const Book: import("../../../index.js").SchemaClass<object & {
|
|
|
188
188
|
version: number;
|
|
189
189
|
authorId: number;
|
|
190
190
|
} & {} & {
|
|
191
|
-
readonly shout
|
|
192
|
-
}>;
|
|
191
|
+
readonly shout: string | null;
|
|
192
|
+
} & {}, false>;
|
|
@@ -19,4 +19,5 @@ export const Book = defineEntity({
|
|
|
19
19
|
.nullable()
|
|
20
20
|
.as(sql `upper(${book.title})`),
|
|
21
21
|
}))
|
|
22
|
-
.relations((rel) => ({ author: () => rel.manyToOne(Author, { references: (book) => book.authorId }) }))
|
|
22
|
+
.relations((rel) => ({ author: () => rel.manyToOne(Author, { references: (book) => book.authorId }) }))
|
|
23
|
+
.filters({ byEv: { where: { author: { name: 'Ev' } }, default: false } });
|
package/dist/http/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractType } from '../type/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Single source of truth for the CRUD-over-HTTP surface, shared by server adapters and the browser client.
|
|
4
4
|
* Keys are constrained to {@link UniversalQuerier} method names, so renaming a querier method
|
|
@@ -69,7 +69,7 @@ export type HttpMethod = CrudRoute['method'] | 'QUERY';
|
|
|
69
69
|
/**
|
|
70
70
|
* URL segment for an entity, e.g. `entityPath(UserProfile) === 'user-profile'`.
|
|
71
71
|
*/
|
|
72
|
-
export declare function entityPath<E>(entity:
|
|
72
|
+
export declare function entityPath<E>(entity: AbstractType<E>): string;
|
|
73
73
|
export type RouteMatch = {
|
|
74
74
|
readonly op: CrudOperation;
|
|
75
75
|
/**
|
package/dist/http/handler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityMeta, QuerierPool, Query, RequestSuccessResponse,
|
|
1
|
+
import type { Type, EntityMeta, QuerierPool, Query, RequestSuccessResponse, AbstractType, UqlContext } from '../type/index.js';
|
|
2
2
|
import { type CrudOperation, type HttpMethod } from './contract.js';
|
|
3
3
|
import { type WireCursors, type WireFlags } from './query.js';
|
|
4
4
|
/**
|
|
@@ -50,7 +50,7 @@ export type RequestHandlerOptions<Ctx = unknown> = {
|
|
|
50
50
|
*/
|
|
51
51
|
include: readonly Type<object>[];
|
|
52
52
|
/** The URL segment an entity is addressed by, its kebab-cased class name by default; the browser client takes the same option. */
|
|
53
|
-
entityPath?: (entity:
|
|
53
|
+
entityPath?: (entity: AbstractType<unknown>) => string;
|
|
54
54
|
/**
|
|
55
55
|
* Allow augment any kind of request before it runs. Hooks may be async
|
|
56
56
|
* and abort the request by throwing (a numeric `status` on the error is honored).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RelationRows, type SelectTerm } from '../dialect/abstractSqlDialect.js';
|
|
2
2
|
import { type JsonAccessMode, type JsonSlot } from '../dialect/jsonSql.js';
|
|
3
3
|
import { MysqlLikeSqlDialect } from '../dialect/mysqlLikeSqlDialect.js';
|
|
4
|
-
import type { FieldOptions, Query, QueryContext, SqlDialectFeatures, SqlValues,
|
|
4
|
+
import type { FieldOptions, Query, QueryContext, SqlDialectFeatures, SqlValues, AbstractType, VectorDistance, VectorMetric } from '../type/index.js';
|
|
5
5
|
export declare class MariaDialect extends MysqlLikeSqlDialect {
|
|
6
6
|
readonly dialectName = "mariadb";
|
|
7
7
|
readonly insertIdSource = "returning";
|
|
@@ -41,7 +41,7 @@ export declare class MariaDialect extends MysqlLikeSqlDialect {
|
|
|
41
41
|
* neither a transaction nor a restore, and cannot leak to the next query on this pooled connection,
|
|
42
42
|
* which is why the tuning is not `vectorTuningStatements`, Postgres's `SET LOCAL` shape.
|
|
43
43
|
*/
|
|
44
|
-
protected statementSettings<E>(entity:
|
|
44
|
+
protected statementSettings<E>(entity: AbstractType<E>, q: Query<E>): string[];
|
|
45
45
|
/** `SET STATEMENT ... FOR`, which scopes a variable to the statement it prefixes. */
|
|
46
46
|
protected applySettings(sql: string, settings: readonly string[]): string;
|
|
47
47
|
/**
|
package/dist/migrate/cli.js
CHANGED
|
@@ -230,9 +230,9 @@ function printDriftGroup(title, drifts, icon, showSuggestion) {
|
|
|
230
230
|
}
|
|
231
231
|
function printHelp() {
|
|
232
232
|
console.log(`
|
|
233
|
-
uql-
|
|
233
|
+
uql-migrate - Database migration tool for uql ORM
|
|
234
234
|
|
|
235
|
-
Usage: uql-
|
|
235
|
+
Usage: uql-migrate <command> [options]
|
|
236
236
|
|
|
237
237
|
Commands:
|
|
238
238
|
up Run all pending migrations
|
|
@@ -282,16 +282,16 @@ Configuration:
|
|
|
282
282
|
};
|
|
283
283
|
|
|
284
284
|
Examples:
|
|
285
|
-
uql-
|
|
286
|
-
uql-
|
|
287
|
-
uql-
|
|
288
|
-
uql-
|
|
289
|
-
uql-
|
|
290
|
-
uql-
|
|
291
|
-
uql-
|
|
292
|
-
uql-
|
|
293
|
-
uql-
|
|
294
|
-
uql-
|
|
295
|
-
uql-
|
|
285
|
+
uql-migrate up
|
|
286
|
+
uql-migrate up --step 1
|
|
287
|
+
uql-migrate down
|
|
288
|
+
uql-migrate down --step 3
|
|
289
|
+
uql-migrate status
|
|
290
|
+
uql-migrate generate add_users_table
|
|
291
|
+
uql-migrate generate:entities initial_schema
|
|
292
|
+
uql-migrate generate:from-db --output ./src/entities
|
|
293
|
+
uql-migrate sync --dry-run
|
|
294
|
+
uql-migrate sync --pull
|
|
295
|
+
uql-migrate drift:check
|
|
296
296
|
`);
|
|
297
297
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractType } from '../../type/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* A `.d.ts` for the entities as registered, so a shape that only exists at runtime reaches the
|
|
4
4
|
* compiler too. Interfaces, not the entity classes `generate:from-db` writes: those are the source of
|
|
5
5
|
* a schema, these describe one already defined elsewhere.
|
|
6
6
|
*/
|
|
7
|
-
export declare function entityTypesSource(entities: readonly
|
|
7
|
+
export declare function entityTypesSource(entities: readonly AbstractType<object>[]): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MigrationDefinition, MigrationResult, MigratorDialect, MigratorOptions, Querier, QuerierPool, SchemaDiff, SchemaGenerator, SchemaIntrospector, SqlQuerier, SyncOptions,
|
|
1
|
+
import type { MigrationDefinition, MigrationResult, MigratorDialect, MigratorOptions, Querier, QuerierPool, SchemaDiff, SchemaGenerator, SchemaIntrospector, SqlQuerier, SyncOptions, AbstractType } from '../type/index.js';
|
|
2
2
|
import { LoggerWrapper } from '../util/index.js';
|
|
3
3
|
import type { MigrationBuilder } from './builder/types.js';
|
|
4
4
|
/**
|
|
@@ -9,7 +9,7 @@ export declare class Migrator {
|
|
|
9
9
|
readonly migrationsPath: string;
|
|
10
10
|
readonly logger: LoggerWrapper;
|
|
11
11
|
private readonly _entities?;
|
|
12
|
-
get entities():
|
|
12
|
+
get entities(): AbstractType<object>[];
|
|
13
13
|
/** The generator given, or this dialect's once {@link getSchemaGenerator} has loaded it. */
|
|
14
14
|
schemaGenerator?: SchemaGenerator;
|
|
15
15
|
schemaIntrospector: SchemaIntrospector;
|