uql-orm 0.104.1 → 0.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -10
- 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 +9 -9
- package/dist/cockroachdb/cockroachDialect.d.ts +2 -2
- package/dist/dialect/abstractDialect.d.ts +3 -3
- package/dist/dialect/abstractSqlDialect.d.ts +39 -37
- package/dist/dialect/abstractSqlDialect.js +35 -32
- package/dist/dialect/aliases.d.ts +2 -0
- package/dist/dialect/aliases.js +2 -0
- package/dist/dialect/jsonSql.js +2 -2
- package/dist/dialect/mergeSqlDialect.d.ts +2 -2
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -7
- package/dist/dialect/mysqlLikeSqlDialect.js +1 -1
- package/dist/dialect/operators.js +2 -4
- package/dist/dialect/queryJoins.d.ts +4 -2
- package/dist/dialect/vectorSqlDialect.d.ts +1 -1
- package/dist/dialect/vectorSqlDialect.js +1 -1
- package/dist/entity/column.d.ts +3 -0
- package/dist/entity/column.js +3 -0
- package/dist/entity/columnOptionsBuilder.d.ts +54 -0
- package/dist/entity/columnOptionsBuilder.js +108 -0
- package/dist/entity/decorator/bag.d.ts +5 -5
- package/dist/entity/decorator/entity.d.ts +3 -20
- package/dist/entity/decorator/entity.js +3 -37
- package/dist/entity/decorator/members.d.ts +46 -76
- package/dist/entity/decorator/members.js +18 -7
- package/dist/entity/index.d.ts +2 -1
- package/dist/entity/index.js +2 -1
- package/dist/entity/metadata/definition.d.ts +15 -26
- package/dist/entity/metadata/definition.js +344 -148
- package/dist/entity/metadata/schemaFixture/animal.d.ts +54 -0
- package/dist/entity/metadata/schemaFixture/animal.js +7 -0
- package/dist/entity/metadata/schemaFixture/author.d.ts +140 -0
- package/dist/entity/metadata/schemaFixture/author.js +25 -0
- package/dist/entity/metadata/schemaFixture/book.d.ts +192 -0
- package/dist/entity/metadata/schemaFixture/book.js +23 -0
- package/dist/http/contract.d.ts +2 -2
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/query.js +12 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/mariadb/mariaDialect.d.ts +2 -2
- package/dist/mariadb/mariaDialect.js +1 -1
- package/dist/mariadb/mariadbQuerier.js +1 -3
- package/dist/migrate/builder/columnBuilder.d.ts +20 -68
- package/dist/migrate/builder/columnBuilder.js +104 -110
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -3
- package/dist/migrate/builder/migrationBuilder.js +7 -6
- package/dist/migrate/builder/tableBuilder.d.ts +3 -55
- package/dist/migrate/builder/tableBuilder.js +88 -204
- package/dist/migrate/builder/types.d.ts +52 -151
- package/dist/migrate/builder/types.js +0 -6
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +24 -24
- package/dist/migrate/codegen/entityTypes.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +3 -1
- package/dist/migrate/codegen/fieldOptionsSource.js +35 -34
- package/dist/migrate/codegen/indexEntrySource.d.ts +16 -0
- package/dist/migrate/codegen/{indexDecoratorSource.js → indexEntrySource.js} +54 -27
- package/dist/migrate/ddl/defaultSql.js +7 -6
- package/dist/migrate/ddl/indexCapabilities.d.ts +8 -7
- package/dist/migrate/ddl/indexCapabilities.js +26 -13
- package/dist/migrate/ddl/indexDdl.d.ts +13 -13
- package/dist/migrate/ddl/indexDdl.js +33 -30
- package/dist/migrate/ddl/mysqlIndexDdl.d.ts +6 -11
- package/dist/migrate/ddl/mysqlIndexDdl.js +17 -28
- package/dist/migrate/ddl/pgIndexDdl.d.ts +2 -2
- package/dist/migrate/ddl/sqliteIndexDdl.d.ts +2 -2
- package/dist/migrate/drift/driftDetector.js +2 -2
- package/dist/migrate/generator/definitionToNode.d.ts +8 -2
- package/dist/migrate/generator/definitionToNode.js +4 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
- package/dist/migrate/introspection/jsonIndexEntry.d.ts +6 -0
- package/dist/migrate/introspection/jsonIndexEntry.js +120 -0
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +25 -21
- package/dist/migrate/introspection/postgresIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/postgresIntrospector.js +3 -4
- package/dist/migrate/introspection/sqliteIntrospector.js +24 -9
- package/dist/migrate/introspection/tableSchemaAST.js +5 -1
- package/dist/migrate/migrator.d.ts +2 -2
- package/dist/migrate/schemaChange.d.ts +3 -3
- package/dist/migrate/schemaChange.js +3 -2
- package/dist/migrate/schemaGenerator.d.ts +5 -5
- package/dist/migrate/schemaGenerator.js +1 -1
- package/dist/migrate/storage/databaseStorage.js +4 -4
- package/dist/mongodb/mongoDialect.d.ts +41 -44
- package/dist/mongodb/mongoDialect.js +118 -32
- package/dist/mongodb/mongoIntrospector.d.ts +3 -1
- package/dist/mongodb/mongoIntrospector.js +11 -5
- package/dist/mongodb/mongoSchemaGenerator.d.ts +4 -4
- package/dist/mongodb/mongoSchemaGenerator.js +35 -27
- package/dist/mongodb/mongodbQuerier.d.ts +1 -11
- package/dist/mongodb/mongodbQuerier.js +9 -43
- package/dist/mssql/mssqlDialect.d.ts +4 -4
- package/dist/postgres/postgresDialect.d.ts +2 -2
- package/dist/querier/abstractQuerier.d.ts +0 -1
- package/dist/querier/abstractQuerier.js +1 -20
- package/dist/querier/abstractSqlQuerier.d.ts +1 -1
- package/dist/querier/keyset.js +3 -3
- package/dist/schema/declaredColumn.d.ts +11 -0
- package/dist/schema/declaredColumn.js +21 -0
- package/dist/schema/indexColumns.d.ts +0 -3
- package/dist/schema/indexColumns.js +11 -7
- package/dist/schema/indexDifferences.d.ts +10 -5
- package/dist/schema/indexDifferences.js +42 -28
- package/dist/schema/schemaASTBuilder.d.ts +4 -4
- package/dist/schema/schemaASTBuilder.js +28 -36
- package/dist/schema/schemaASTDiffer.js +8 -4
- package/dist/schema/sqlExpression.d.ts +21 -17
- package/dist/schema/sqlExpression.js +11 -23
- package/dist/type/column.d.ts +328 -0
- package/dist/type/column.js +2 -0
- package/dist/type/config.d.ts +3 -3
- package/dist/type/dialect.d.ts +15 -14
- package/dist/type/dialect.js +1 -0
- package/dist/type/entity.d.ts +292 -281
- package/dist/type/entity.js +6 -1
- package/dist/type/index.d.ts +2 -0
- package/dist/type/index.js +2 -0
- package/dist/type/migration.d.ts +11 -11
- package/dist/type/querier.d.ts +2 -2
- package/dist/type/query.d.ts +44 -40
- package/dist/type/query.js +2 -3
- package/dist/type/queryAggregate.d.ts +22 -12
- package/dist/type/querySql.d.ts +22 -6
- package/dist/type/querySql.js +27 -9
- package/dist/type/schemaEntity.d.ts +194 -0
- package/dist/type/schemaEntity.js +1 -0
- package/dist/type/utility.d.ts +4 -7
- package/dist/type/vector.d.ts +1 -1
- package/dist/util/ddlExpression.util.d.ts +12 -13
- package/dist/util/ddlExpression.util.js +12 -21
- package/dist/util/dialect.util.d.ts +11 -5
- package/dist/util/dialect.util.js +31 -37
- package/dist/util/field.util.d.ts +10 -9
- package/dist/util/field.util.js +14 -10
- package/dist/util/fieldOption.util.d.ts +11 -95
- package/dist/util/fieldOption.util.js +49 -16
- package/dist/util/hook.util.d.ts +3 -15
- package/dist/util/hook.util.js +3 -16
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/indexEntry.util.d.ts +45 -0
- package/dist/util/indexEntry.util.js +138 -0
- package/dist/util/relationQuery.util.d.ts +0 -1
- package/dist/util/relationQuery.util.js +0 -5
- package/dist/util/sql.d.ts +13 -10
- package/dist/util/sql.js +34 -16
- package/dist/util/sql.util.d.ts +4 -5
- package/dist/util/sql.util.js +7 -16
- package/dist/util/string.util.d.ts +2 -0
- package/dist/util/string.util.js +4 -0
- package/dist/util/triggerWrite.d.ts +5 -5
- package/dist/util/uqlError.d.ts +1 -1
- package/dist/util/uqlError.js +1 -1
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +76 -25
- package/dist/migrate/codegen/indexDecoratorSource.d.ts +0 -16
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import type { ForeignKeyAction } from '../schema/types.js';
|
|
2
|
+
import type { TYPE_BOUNDS, VALUE_DECIDERS } from '../util/fieldOption.util.js';
|
|
3
|
+
import type { BlobColumnType, BooleanColumnType, ColumnType, DateColumnType, DdlDefault, JsonColumnType, NumericColumnType, StringColumnType, VectorColumnType, FieldOptions, HasCompositeKey, IdValue, JsonShape, OnFieldCallback, ShapeValue, StampEvent } from './entity.js';
|
|
4
|
+
import type { QuerySql } from './querySql.js';
|
|
5
|
+
import type { ReferencedKey } from './schemaEntity.js';
|
|
6
|
+
import type { Type, Json, AbstractType } from './utility.js';
|
|
7
|
+
import type { VectorDistance } from './vector.js';
|
|
8
|
+
/** Where a column builder holds its options, so every string key of a builder is a method. */
|
|
9
|
+
export declare const COLUMN_OPTIONS: unique symbol;
|
|
10
|
+
/** What a builder has written and the value a row holds, carried for the type level alone: nothing sets it. */
|
|
11
|
+
export declare const COLUMN_TYPE: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* A column as `f` declares it: the options the registry reads, and for the type level the options written so
|
|
14
|
+
* far, `O`, and the value a row holds, `V`, never `null`, which `nullable()` adds where the row is read.
|
|
15
|
+
*/
|
|
16
|
+
export type Column<O = unknown, V = unknown> = {
|
|
17
|
+
readonly [COLUMN_OPTIONS]: FieldOptions;
|
|
18
|
+
readonly [COLUMN_TYPE]?: {
|
|
19
|
+
readonly options: O;
|
|
20
|
+
readonly value: V;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** The options a builder has written. */
|
|
24
|
+
export type ColumnOptionsOf<C> = C extends Column<infer O> ? O : never;
|
|
25
|
+
/** The value a column holds, `null` aside. */
|
|
26
|
+
export type ColumnValueOf<C> = C extends Column<unknown, infer V> ? V : never;
|
|
27
|
+
/** What a builder writes that lets an insert leave the column out: something fills it. */
|
|
28
|
+
export type FilledOptions = {
|
|
29
|
+
readonly defaultValue: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
readonly onInsert: unknown;
|
|
32
|
+
} | {
|
|
33
|
+
readonly autoIncrement: true;
|
|
34
|
+
};
|
|
35
|
+
/** The `null` a column's row holds: none unless `nullable()` said so. */
|
|
36
|
+
export type NullOf<O> = O extends {
|
|
37
|
+
readonly nullable: true;
|
|
38
|
+
} ? null : never;
|
|
39
|
+
/** A builder that has written none of `K`; the index signature keeps it from being a weak type every builder fails. */
|
|
40
|
+
type Lacking<K extends keyof FieldOptions> = Column<{
|
|
41
|
+
readonly [P in K]?: undefined;
|
|
42
|
+
} & {
|
|
43
|
+
readonly [key: string]: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
/** The options that decide what a column holds: a column the database writes takes none. */
|
|
46
|
+
type ValueDecider = (typeof VALUE_DECIDERS)[number];
|
|
47
|
+
/** What bounds a type: a column type written out as SQL carries its own. */
|
|
48
|
+
type TypeBound = (typeof TYPE_BOUNDS)[number];
|
|
49
|
+
/** A builder whose SQL type is not written out as `sql`, which is what leaves a bound a bound on the column. */
|
|
50
|
+
type TypeNotSql = Column<{
|
|
51
|
+
readonly columnType?: ColumnType;
|
|
52
|
+
} & {
|
|
53
|
+
readonly [key: string]: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
/** The builder of each column family, which is what keeps an option off a column it means nothing on. */
|
|
56
|
+
interface Builders<O, V> {
|
|
57
|
+
readonly numeric: NumericColumn<O, V>;
|
|
58
|
+
readonly string: StringColumn<O, V>;
|
|
59
|
+
readonly date: DateColumn<O, V>;
|
|
60
|
+
readonly boolean: ColumnBuilder<O, V, 'boolean'>;
|
|
61
|
+
readonly json: ColumnBuilder<O, V, 'json'>;
|
|
62
|
+
readonly blob: ColumnBuilder<O, V, 'blob'>;
|
|
63
|
+
readonly vector: VectorColumn<O, V>;
|
|
64
|
+
/** A column whose family is known only at run time: a foreign key's is its target key's, a runtime schema's its data's. */
|
|
65
|
+
readonly any: ColumnBuilder<O, V, 'any'>;
|
|
66
|
+
}
|
|
67
|
+
type Family = keyof Builders<unknown, unknown>;
|
|
68
|
+
/** The same builder, having written `X` too. */
|
|
69
|
+
type With<O, V, X, F extends Family> = Builders<O & X, V>[F];
|
|
70
|
+
/** What every column takes. */
|
|
71
|
+
export interface ColumnBuilder<in out O, in out V, F extends Family> extends Column<O, V> {
|
|
72
|
+
/** Lets the column hold `null`, which a read then answers with: a column is `NOT NULL` otherwise. */
|
|
73
|
+
nullable(this: Lacking<'isId'>): With<O, V, {
|
|
74
|
+
readonly nullable: true;
|
|
75
|
+
}, F>;
|
|
76
|
+
/** Makes it the primary key, or a column of a composite one. */
|
|
77
|
+
id(this: Lacking<'nullable'>): With<O, V, {
|
|
78
|
+
readonly isId: true;
|
|
79
|
+
}, F>;
|
|
80
|
+
/** The column's DDL default: a value, or SQL the database evaluates per row (`currentTimestamp`, `sql`). */
|
|
81
|
+
default(value: DdlDefault<V> | QuerySql): With<O, V, {
|
|
82
|
+
readonly defaultValue: unknown;
|
|
83
|
+
}, F>;
|
|
84
|
+
/** The value uql writes on insert, where the row has none: a value, SQL or a function returning either. */
|
|
85
|
+
onInsert(value: OnFieldCallback<V>): With<O, V, {
|
|
86
|
+
readonly onInsert: unknown;
|
|
87
|
+
}, F>;
|
|
88
|
+
/** The value uql writes on each update. */
|
|
89
|
+
onUpdate(this: Lacking<'updatable'>, value: OnFieldCallback<V>): With<O, V, {
|
|
90
|
+
readonly onUpdate: unknown;
|
|
91
|
+
}, F>;
|
|
92
|
+
/** Leaves the column out of every update. */
|
|
93
|
+
updatable(this: Lacking<'onUpdate'>, updatable: false): With<O, V, {
|
|
94
|
+
readonly updatable: false;
|
|
95
|
+
}, F>;
|
|
96
|
+
/** Makes a delete stamp the column instead, and reads skip stamped rows: `new Date()` unless given a value. */
|
|
97
|
+
softDelete(value?: OnFieldCallback<V>): With<O, V, {
|
|
98
|
+
readonly softDelete: unknown;
|
|
99
|
+
}, F>;
|
|
100
|
+
unique(): With<O, V, {
|
|
101
|
+
readonly unique: true;
|
|
102
|
+
}, F>;
|
|
103
|
+
/** An index over the column, named or not; `false` keeps a foreign key column unindexed. */
|
|
104
|
+
index(name?: string | false): With<O, V, {
|
|
105
|
+
readonly index: unknown;
|
|
106
|
+
}, F>;
|
|
107
|
+
/** The column's name, where it is not the field's. */
|
|
108
|
+
name(column: string): With<O, V, {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
}, F>;
|
|
111
|
+
comment(text: string): With<O, V, {
|
|
112
|
+
readonly comment: string;
|
|
113
|
+
}, F>;
|
|
114
|
+
/** Leaves the column out of a read naming no fields. */
|
|
115
|
+
eager(eager: false): With<O, V, {
|
|
116
|
+
readonly eager: false;
|
|
117
|
+
}, F>;
|
|
118
|
+
/** The SQL type where it differs from the one the builder implies; an engine's own, `sql`citext``, verbatim. */
|
|
119
|
+
columnType(type: ColumnType): With<O, V, {
|
|
120
|
+
readonly columnType: ColumnType;
|
|
121
|
+
}, F>;
|
|
122
|
+
columnType(this: Lacking<TypeBound>, type: QuerySql): With<O, V, {
|
|
123
|
+
readonly columnType: QuerySql;
|
|
124
|
+
}, F>;
|
|
125
|
+
/** A foreign key to `entity`'s key, which the column has to hold the kind of: `f.number().references(() => User)`. */
|
|
126
|
+
references<C extends Type<object>>(entity: () => C & HoldsKey<C, V>): With<O, V, {
|
|
127
|
+
readonly references: () => C;
|
|
128
|
+
}, F>;
|
|
129
|
+
/** The foreign key's delete action. */
|
|
130
|
+
onDelete(this: Column<{
|
|
131
|
+
readonly references: unknown;
|
|
132
|
+
}>, action: ForeignKeyAction): With<O, V, {
|
|
133
|
+
readonly onDelete: ForeignKeyAction;
|
|
134
|
+
}, F>;
|
|
135
|
+
/** Narrows the value a row holds, a branded id or a literal union: `f.uuid().narrow<UserId>()`. */
|
|
136
|
+
narrow<T extends V>(): Builders<O, T>[F];
|
|
137
|
+
/**
|
|
138
|
+
* A column the database computes from `expression`, read in each query naming it; `stored()` keeps it. A relation
|
|
139
|
+
* aggregate is no column's SQL: it is read on each query, so `@Computed` or `aggregates` declares one.
|
|
140
|
+
*/
|
|
141
|
+
as(this: Lacking<ValueDecider | 'isId'>, expression: QuerySql & {
|
|
142
|
+
readonly spec?: never;
|
|
143
|
+
}): ComputedColumn<O & {
|
|
144
|
+
readonly computed: QuerySql;
|
|
145
|
+
}, V>;
|
|
146
|
+
}
|
|
147
|
+
export interface NumericColumn<in out O, in out V> extends ColumnBuilder<O, V, 'numeric'> {
|
|
148
|
+
/** Digits in all: a `DECIMAL`, read as a number where the builder is `f.number()`, rounding where it must. */
|
|
149
|
+
precision(this: TypeNotSql, digits: number): NumericColumn<O & {
|
|
150
|
+
readonly precision: number;
|
|
151
|
+
}, V>;
|
|
152
|
+
scale(this: TypeNotSql, digits: number): NumericColumn<O & {
|
|
153
|
+
readonly scale: number;
|
|
154
|
+
}, V>;
|
|
155
|
+
/** Has the database generate the value, which a numeric sole key does unless `autoIncrement(false)` says otherwise. */
|
|
156
|
+
autoIncrement(): NumericColumn<O & {
|
|
157
|
+
readonly autoIncrement: true;
|
|
158
|
+
}, V>;
|
|
159
|
+
autoIncrement(generated: false): NumericColumn<O & {
|
|
160
|
+
readonly autoIncrement: false;
|
|
161
|
+
}, V>;
|
|
162
|
+
}
|
|
163
|
+
export interface StringColumn<in out O, in out V> extends ColumnBuilder<O, V, 'string'> {
|
|
164
|
+
length(this: TypeNotSql, length: number): StringColumn<O & {
|
|
165
|
+
readonly length: number;
|
|
166
|
+
}, V>;
|
|
167
|
+
}
|
|
168
|
+
export interface DateColumn<in out O, in out V> extends ColumnBuilder<O, V, 'date'> {
|
|
169
|
+
/** Fractional-second digits. */
|
|
170
|
+
precision(this: TypeNotSql, digits: number): DateColumn<O & {
|
|
171
|
+
readonly precision: number;
|
|
172
|
+
}, V>;
|
|
173
|
+
}
|
|
174
|
+
export interface VectorColumn<in out O, in out V> extends ColumnBuilder<O, V, 'vector'> {
|
|
175
|
+
dimensions(this: TypeNotSql, dimensions: number): VectorColumn<O & {
|
|
176
|
+
readonly dimensions: number;
|
|
177
|
+
}, V>;
|
|
178
|
+
/** The metric a search on it uses unless it names its own `$distance`; by default its vector index's, else cosine. */
|
|
179
|
+
distance(distance: VectorDistance): VectorColumn<O & {
|
|
180
|
+
readonly distance: VectorDistance;
|
|
181
|
+
}, V>;
|
|
182
|
+
}
|
|
183
|
+
/** A column the database computes, which nothing writes. */
|
|
184
|
+
export interface ComputedColumn<in out O, in out V> extends Column<O, V> {
|
|
185
|
+
/**
|
|
186
|
+
* Keeps it: a generated column, or with events a stamp a trigger writes on each, whoever writes the row,
|
|
187
|
+
* which keeps a `currentTimestamp` current where `onUpdate` sees only uql's writes.
|
|
188
|
+
*/
|
|
189
|
+
stored(events?: readonly StampEvent[]): ComputedColumn<O & {
|
|
190
|
+
readonly stored: unknown;
|
|
191
|
+
}, V>;
|
|
192
|
+
}
|
|
193
|
+
/** The version column, an optimistic lock: an update matches the version it read and writes the next. */
|
|
194
|
+
export interface VersionColumn<in out O, in out V> extends Column<O, V> {
|
|
195
|
+
name(column: string): VersionColumn<O & {
|
|
196
|
+
readonly name: string;
|
|
197
|
+
}, V>;
|
|
198
|
+
comment(text: string): VersionColumn<O & {
|
|
199
|
+
readonly comment: string;
|
|
200
|
+
}, V>;
|
|
201
|
+
}
|
|
202
|
+
/** A key's kind as a join compares it: a number and a bigint both integers, so a BIGINT column holds either key. */
|
|
203
|
+
type ValueKind<T> = T extends number | bigint ? number | bigint : T;
|
|
204
|
+
/** Refuses a target whose key is another kind of value than the column holds, which no join matches. */
|
|
205
|
+
type HoldsKey<C, V> = [ValueKind<NonNullable<ReferencedKey<C>>>] extends [ValueKind<V>] ? unknown : {
|
|
206
|
+
readonly __columnMustHoldReferencedKey: ReferencedKey<C>;
|
|
207
|
+
};
|
|
208
|
+
/** The column types holding an exact decimal, read as its text: a JS number would round it. */
|
|
209
|
+
type DecimalType = 'decimal' | 'numeric';
|
|
210
|
+
/** What a JSON column holds: its shape's payload, or any document. */
|
|
211
|
+
type JsonValue<S> = [S] extends [never] ? Json : ShapeValue<S> extends infer P extends object | string | number | boolean ? Json<P> : Json;
|
|
212
|
+
/** The key a column referencing `C` holds, or a named complaint for a composite one, which no one column holds. */
|
|
213
|
+
type ReferenceValue<C> = C extends AbstractType<infer E> ? HasCompositeKey<E> extends true ? {
|
|
214
|
+
readonly __compositeKeyNeedsAColumnPerKey: true;
|
|
215
|
+
} : NonNullable<IdValue<E>> : never;
|
|
216
|
+
/** The builders, one per value a column holds; `column` takes any SQL type, its family deciding what it offers. */
|
|
217
|
+
export type ColumnFactory = {
|
|
218
|
+
string(): StringColumn<{
|
|
219
|
+
readonly type: StringConstructor;
|
|
220
|
+
}, string>;
|
|
221
|
+
text(): StringColumn<{
|
|
222
|
+
readonly type: 'text';
|
|
223
|
+
}, string>;
|
|
224
|
+
uuid(): StringColumn<{
|
|
225
|
+
readonly type: 'uuid';
|
|
226
|
+
}, string>;
|
|
227
|
+
number(): NumericColumn<{
|
|
228
|
+
readonly type: NumberConstructor;
|
|
229
|
+
}, number>;
|
|
230
|
+
bigint(): NumericColumn<{
|
|
231
|
+
readonly type: BigIntConstructor;
|
|
232
|
+
}, bigint>;
|
|
233
|
+
/** An exact decimal, read as its text: a JS number would round it. `f.number().precision()` opts in to that. */
|
|
234
|
+
decimal(): NumericColumn<{
|
|
235
|
+
readonly type: 'decimal';
|
|
236
|
+
}, string>;
|
|
237
|
+
decimal(precision: number): NumericColumn<{
|
|
238
|
+
readonly type: 'decimal';
|
|
239
|
+
readonly precision: number;
|
|
240
|
+
}, string>;
|
|
241
|
+
decimal(precision: number, scale: number): NumericColumn<{
|
|
242
|
+
readonly type: 'decimal';
|
|
243
|
+
readonly precision: number;
|
|
244
|
+
readonly scale: number;
|
|
245
|
+
}, string>;
|
|
246
|
+
boolean(): ColumnBuilder<{
|
|
247
|
+
readonly type: BooleanConstructor;
|
|
248
|
+
}, boolean, 'boolean'>;
|
|
249
|
+
date(): DateColumn<{
|
|
250
|
+
readonly type: DateConstructor;
|
|
251
|
+
}, Date>;
|
|
252
|
+
json(): ColumnBuilder<{
|
|
253
|
+
readonly type: 'json';
|
|
254
|
+
}, Json, 'json'>;
|
|
255
|
+
json<const S extends JsonShape>(shape: S): ColumnBuilder<{
|
|
256
|
+
readonly type: 'json';
|
|
257
|
+
readonly shape: S;
|
|
258
|
+
}, JsonValue<S>, 'json'>;
|
|
259
|
+
jsonb(): ColumnBuilder<{
|
|
260
|
+
readonly type: 'jsonb';
|
|
261
|
+
}, Json, 'json'>;
|
|
262
|
+
jsonb<const S extends JsonShape>(shape: S): ColumnBuilder<{
|
|
263
|
+
readonly type: 'jsonb';
|
|
264
|
+
readonly shape: S;
|
|
265
|
+
}, JsonValue<S>, 'json'>;
|
|
266
|
+
vector(dimensions: number): VectorColumn<{
|
|
267
|
+
readonly type: 'vector';
|
|
268
|
+
readonly dimensions: number;
|
|
269
|
+
}, readonly number[]>;
|
|
270
|
+
/** The values the column accepts, a `CHECK (col IN (...))` on every SQL engine, and the row's literal union. */
|
|
271
|
+
enum<const M extends readonly string[]>(members: M): StringColumn<{
|
|
272
|
+
readonly type: StringConstructor;
|
|
273
|
+
readonly enum: M;
|
|
274
|
+
}, M[number]>;
|
|
275
|
+
enum<const M extends readonly number[]>(members: M): NumericColumn<{
|
|
276
|
+
readonly type: NumberConstructor;
|
|
277
|
+
readonly enum: M;
|
|
278
|
+
}, M[number]>;
|
|
279
|
+
/**
|
|
280
|
+
* The optimistic lock: `NOT NULL DEFAULT 0`, and the class's `[versionKey]` brand makes each update carry it. A
|
|
281
|
+
* `BigInt` one counts past 2^53.
|
|
282
|
+
*/
|
|
283
|
+
version(): VersionColumn<{
|
|
284
|
+
readonly type: NumberConstructor;
|
|
285
|
+
readonly version: true;
|
|
286
|
+
}, number>;
|
|
287
|
+
version(type: BigIntConstructor): VersionColumn<{
|
|
288
|
+
readonly type: BigIntConstructor;
|
|
289
|
+
readonly version: true;
|
|
290
|
+
}, bigint>;
|
|
291
|
+
/** A column of SQL type `type`, offering what its family takes. */
|
|
292
|
+
column(type: DecimalType): NumericColumn<{
|
|
293
|
+
readonly type: DecimalType;
|
|
294
|
+
}, string>;
|
|
295
|
+
column(type: Exclude<NumericColumnType, DecimalType>): NumericColumn<{
|
|
296
|
+
readonly type: NumericColumnType;
|
|
297
|
+
}, number | bigint>;
|
|
298
|
+
column(type: StringColumnType): StringColumn<{
|
|
299
|
+
readonly type: StringColumnType;
|
|
300
|
+
}, string>;
|
|
301
|
+
column(type: 'time'): DateColumn<{
|
|
302
|
+
readonly type: 'time';
|
|
303
|
+
}, string>;
|
|
304
|
+
column(type: Exclude<DateColumnType, 'time'>): DateColumn<{
|
|
305
|
+
readonly type: DateColumnType;
|
|
306
|
+
}, Date>;
|
|
307
|
+
column(type: VectorColumnType): VectorColumn<{
|
|
308
|
+
readonly type: VectorColumnType;
|
|
309
|
+
}, readonly number[]>;
|
|
310
|
+
column(type: BooleanColumnType): ColumnBuilder<{
|
|
311
|
+
readonly type: BooleanColumnType;
|
|
312
|
+
}, boolean, 'boolean'>;
|
|
313
|
+
column(type: JsonColumnType): ColumnBuilder<{
|
|
314
|
+
readonly type: JsonColumnType;
|
|
315
|
+
}, Json, 'json'>;
|
|
316
|
+
column(type: BlobColumnType): ColumnBuilder<{
|
|
317
|
+
readonly type: BlobColumnType;
|
|
318
|
+
}, Uint8Array, 'blob'>;
|
|
319
|
+
/** A column whose type is data, as a schema built at run time declares one. */
|
|
320
|
+
column(type: ColumnType): ColumnBuilder<{
|
|
321
|
+
readonly type: ColumnType;
|
|
322
|
+
}, unknown, 'any'>;
|
|
323
|
+
/** A foreign key to `entity`'s key, its column typed as that key is. */
|
|
324
|
+
references<C extends Type<object>>(entity: () => C): ColumnBuilder<{
|
|
325
|
+
readonly references: () => C;
|
|
326
|
+
}, ReferenceValue<C>, 'any'>;
|
|
327
|
+
};
|
|
328
|
+
export {};
|
package/dist/type/config.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ForeignKeyAction } from '../schema/types.js';
|
|
|
2
2
|
import type { MigratorDialect } from './migratorDialect.js';
|
|
3
3
|
import type { Querier } from './querier.js';
|
|
4
4
|
import type { QuerierPool } from './querierPool.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { AbstractType } from './utility.js';
|
|
6
6
|
/**
|
|
7
7
|
* Configuration options for the UQL ORM and Migrator.
|
|
8
8
|
*/
|
|
@@ -15,9 +15,9 @@ export interface Config {
|
|
|
15
15
|
pool: QuerierPool<Querier, MigratorDialect>;
|
|
16
16
|
/**
|
|
17
17
|
* List of entity classes to be managed by the ORM.
|
|
18
|
-
* If omitted,
|
|
18
|
+
* If omitted, every registered entity (`@Entity()` or `defineEntity`) is discovered via `getEntities()`.
|
|
19
19
|
*/
|
|
20
|
-
entities?:
|
|
20
|
+
entities?: AbstractType<object>[];
|
|
21
21
|
/**
|
|
22
22
|
* The directory where migration files are stored.
|
|
23
23
|
* @default './migrations'
|
package/dist/type/dialect.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Query, QueryConflictPaths, QueryPage, QueryRenderOptions, QuerySea
|
|
|
4
4
|
import type { QueryAggregate, QueryAggregateOp } from './queryAggregate.js';
|
|
5
5
|
import type { QuerySqlRenderOptions } from './querySql.js';
|
|
6
6
|
import type { QueryWhere } from './queryWhere.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { AbstractType } from './utility.js';
|
|
8
8
|
import type { QueryVectorQuery } from './vector.js';
|
|
9
9
|
/** The values the database computes that uql exports by name: `currentTimestamp`, `uuid`, ... */
|
|
10
10
|
export declare const SQL_VALUE_NAMES: readonly ['currentTimestamp', 'currentDate', 'currentTime', 'uuid', 'uuidv7'];
|
|
@@ -121,7 +121,7 @@ export interface DialectFeatures {
|
|
|
121
121
|
* (`boundedText`, the Postgres family), or always bounded, 255 by default (`varchar`).
|
|
122
122
|
*/
|
|
123
123
|
readonly stringSizing: 'text' | 'boundedText' | 'varchar';
|
|
124
|
-
/** Whether the engine has unsigned integers, so
|
|
124
|
+
/** Whether the engine has unsigned integers, so an unsigned column type reaches the database. */
|
|
125
125
|
readonly supportsUnsigned: boolean;
|
|
126
126
|
/**
|
|
127
127
|
* Whether the engine has `DECLARE`/`FETCH FORWARD`/`CLOSE` cursors, which a querier with no stream of
|
|
@@ -276,22 +276,22 @@ export type DdlRenderOptions = Pick<QueryComparisonOptions, 'escapedPrefix' | 'o
|
|
|
276
276
|
*/
|
|
277
277
|
export type TriggerWrite = {
|
|
278
278
|
readonly kind: 'insert';
|
|
279
|
-
readonly entity:
|
|
279
|
+
readonly entity: AbstractType<object>;
|
|
280
280
|
readonly row: Readonly<Record<string, unknown>>;
|
|
281
281
|
} | {
|
|
282
282
|
readonly kind: 'upsert';
|
|
283
|
-
readonly entity:
|
|
283
|
+
readonly entity: AbstractType<object>;
|
|
284
284
|
readonly conflictPaths: Readonly<Record<string, unknown>>;
|
|
285
285
|
readonly row: Readonly<Record<string, unknown>>;
|
|
286
286
|
readonly update?: Readonly<Record<string, unknown>>;
|
|
287
287
|
} | {
|
|
288
288
|
readonly kind: 'update';
|
|
289
|
-
readonly entity:
|
|
289
|
+
readonly entity: AbstractType<object>;
|
|
290
290
|
readonly set: Readonly<Record<string, unknown>>;
|
|
291
291
|
readonly where: EntityPredicate<object>;
|
|
292
292
|
} | {
|
|
293
293
|
readonly kind: 'delete';
|
|
294
|
-
readonly entity:
|
|
294
|
+
readonly entity: AbstractType<object>;
|
|
295
295
|
readonly where: EntityPredicate<object>;
|
|
296
296
|
} | {
|
|
297
297
|
readonly kind: 'refuse';
|
|
@@ -327,19 +327,19 @@ export interface SqlQueryDialect {
|
|
|
327
327
|
*/
|
|
328
328
|
readonly sqlValues: SqlValues;
|
|
329
329
|
/** A read; with `totalAlias`, every row also carries the unpaged match count under that alias. */
|
|
330
|
-
find<E>(ctx: QueryContext, entity:
|
|
330
|
+
find<E>(ctx: QueryContext, entity: AbstractType<E>, q: Query<E>, opts?: QueryRenderOptions, totalAlias?: string): void;
|
|
331
331
|
/** A count of the records matching the filter, or of those a page of it takes. */
|
|
332
|
-
count<E>(ctx: QueryContext, entity:
|
|
332
|
+
count<E>(ctx: QueryContext, entity: AbstractType<E>, q: QueryPage<E>, opts?: QueryRenderOptions): void;
|
|
333
333
|
/** An insert of one record or many. */
|
|
334
|
-
insert<E>(ctx: QueryContext, entity:
|
|
334
|
+
insert<E>(ctx: QueryContext, entity: AbstractType<E>, payload: E | E[], opts?: QueryRenderOptions): void;
|
|
335
335
|
/** An update of the records the query matches. */
|
|
336
|
-
update<E>(ctx: QueryContext, entity:
|
|
336
|
+
update<E>(ctx: QueryContext, entity: AbstractType<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?: QueryRenderOptions): void;
|
|
337
337
|
/** An upsert of one record or many by their conflict paths, a conflicting row taking `update` where given. */
|
|
338
|
-
upsert<E>(ctx: QueryContext, entity:
|
|
338
|
+
upsert<E>(ctx: QueryContext, entity: AbstractType<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[], update?: UpdatePayload<E>): void;
|
|
339
339
|
/** A write in a trigger's body; `rows` are what a set-based engine's body reads, narrowed to the ones it fires for. */
|
|
340
340
|
triggerWrite(ctx: QueryContext, write: TriggerWrite, rows?: TriggerRows): void;
|
|
341
341
|
/** A delete of the records the query matches, a soft delete where the entity has one. */
|
|
342
|
-
delete<E>(ctx: QueryContext, entity:
|
|
342
|
+
delete<E>(ctx: QueryContext, entity: AbstractType<E>, q: QuerySearch<E>, opts?: QueryRenderOptions): void;
|
|
343
343
|
/**
|
|
344
344
|
* escape an identifier.
|
|
345
345
|
* @param val the value to be escaped
|
|
@@ -373,7 +373,7 @@ export interface SqlQueryDialect {
|
|
|
373
373
|
/**
|
|
374
374
|
* Build an aggregate query.
|
|
375
375
|
*/
|
|
376
|
-
aggregate<E>(ctx: QueryContext, entity:
|
|
376
|
+
aggregate<E>(ctx: QueryContext, entity: AbstractType<E>, q: QueryAggregate<E>, opts?: QueryRenderOptions): void;
|
|
377
377
|
/**
|
|
378
378
|
* Get the placeholder for a parameter at the given index (1-based).
|
|
379
379
|
* Default: '?' for MySQL/MariaDB/SQLite, '$n' for PostgreSQL.
|
|
@@ -383,7 +383,7 @@ export interface SqlQueryDialect {
|
|
|
383
383
|
* A relation aggregate as a correlated subquery, correlated to the row under `prefix`: what a field
|
|
384
384
|
* declaring `computed: (user) => user.resources.count()` renders as, wherever a clause names it.
|
|
385
385
|
*/
|
|
386
|
-
appendRelationAggregate<E>(ctx: QueryContext, entity:
|
|
386
|
+
appendRelationAggregate<E>(ctx: QueryContext, entity: AbstractType<E>, aggregate: RelationAggregateSpec, prefix: string): void;
|
|
387
387
|
}
|
|
388
388
|
/**
|
|
389
389
|
* The aggregates a relation reads, spelled as the query language spells them, so a `computed` field, an
|
|
@@ -443,6 +443,7 @@ export declare const INDEX_FEATURE_LABELS: {
|
|
|
443
443
|
readonly include: 'covering indexes (INCLUDE)';
|
|
444
444
|
readonly jsonPath: 'indexes over a path inside a JSON column';
|
|
445
445
|
readonly jsonArray: 'multi-valued indexes over a JSON array';
|
|
446
|
+
readonly fulltextPath: 'fulltext indexes over a path inside a JSON column, which a search of whole columns never reads';
|
|
446
447
|
};
|
|
447
448
|
/** Derived from the labels, so a feature cannot be added without the words an error reports it in. */
|
|
448
449
|
export type IndexFeature = keyof typeof INDEX_FEATURE_LABELS;
|
package/dist/type/dialect.js
CHANGED
|
@@ -14,4 +14,5 @@ export const INDEX_FEATURE_LABELS = {
|
|
|
14
14
|
include: 'covering indexes (INCLUDE)',
|
|
15
15
|
jsonPath: 'indexes over a path inside a JSON column',
|
|
16
16
|
jsonArray: 'multi-valued indexes over a JSON array',
|
|
17
|
+
fulltextPath: 'fulltext indexes over a path inside a JSON column, which a search of whole columns never reads',
|
|
17
18
|
};
|