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
|
@@ -2,7 +2,7 @@ import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
|
2
2
|
import type { SchemaAST } from '../schema/schemaAST.js';
|
|
3
3
|
import { type DiffOptions } from '../schema/schemaASTDiffer.js';
|
|
4
4
|
import { type ForeignKeyAction, type TableNode } from '../schema/types.js';
|
|
5
|
-
import type { CreateSchemaOptions, DialectFeatures, DropSchemaOptions, ForeignKeySchema, Rename, SchemaDiff, SchemaGenerator,
|
|
5
|
+
import type { CreateSchemaOptions, DialectFeatures, DropSchemaOptions, ForeignKeySchema, Rename, SchemaDiff, SchemaGenerator, AbstractType } from '../type/index.js';
|
|
6
6
|
import type { AnyMigrationOperation, TableDefinition } from './builder/types.js';
|
|
7
7
|
import { type IndexDdl, type TableDdl } from './ddl/index.js';
|
|
8
8
|
/** The SQL schema generator, one for every SQL engine, its spellings taken from the dialect and its DDL classes. */
|
|
@@ -26,12 +26,12 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
26
26
|
* The entity side as an AST, carrying this generator's default referential action. Named by the dialect's
|
|
27
27
|
* resolvers rather than a naming strategy, which would also rename an explicit `@Entity({ name })`.
|
|
28
28
|
*/
|
|
29
|
-
buildAST(entities: readonly
|
|
29
|
+
buildAST(entities: readonly AbstractType<object>[]): SchemaAST;
|
|
30
30
|
/**
|
|
31
31
|
* Every `CREATE TABLE` for `entities`, then their foreign keys, since a relation graph is routinely
|
|
32
32
|
* cyclic. SQLite keeps them inline: it cannot add one later, and resolves a forward reference lazily.
|
|
33
33
|
*/
|
|
34
|
-
generateCreateSchema(entities: readonly
|
|
34
|
+
generateCreateSchema(entities: readonly AbstractType<object>[], options?: CreateSchemaOptions): string[];
|
|
35
35
|
/**
|
|
36
36
|
* One statement per distinct schema the tables being created live in, in first-seen order. Only
|
|
37
37
|
* the tables actually being created, so a narrowed `only` does not declare namespaces it is not
|
|
@@ -42,7 +42,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
42
42
|
* The inverse of {@link generateCreateSchema}: a table's drop takes its triggers along, so only what they
|
|
43
43
|
* leave behind follows it.
|
|
44
44
|
*/
|
|
45
|
-
generateDropSchema(entities: readonly
|
|
45
|
+
generateDropSchema(entities: readonly AbstractType<object>[], options?: DropSchemaOptions): string[];
|
|
46
46
|
/**
|
|
47
47
|
* The tables of `entities` in dependency order, optionally narrowed to `only`. The AST always spans
|
|
48
48
|
* every entity even when narrowed, so a relation pointing at a table outside the subset still
|
|
@@ -78,7 +78,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
78
78
|
* How the entity differs from the table the database reported, compared by {@link diffTable}, the one
|
|
79
79
|
* drift detection runs, with types normalized as the engine stores them.
|
|
80
80
|
*/
|
|
81
|
-
diffSchema(entity:
|
|
81
|
+
diffSchema(entity: AbstractType<object>, currentTable: TableNode | undefined, desiredAst?: SchemaAST, renamedColumns?: readonly Rename[]): SchemaDiff | undefined;
|
|
82
82
|
/**
|
|
83
83
|
* Both ends of rebuilding `actual` as `desired`. The new table is the entity's, keeping what it cannot
|
|
84
84
|
* know of: the indexes, checks and triggers uql did not make, and foreign keys to tables no entity names.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Document, type Filter, type Sort } from 'mongodb';
|
|
2
2
|
import { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
3
|
-
import type { DialectFeatures, EntityData, EntityMeta, Query, QueryAggregate, QueryOptions, QueryPager, QuerySelectValue, QuerySortMap, QueryWhere,
|
|
3
|
+
import type { DialectFeatures, EntityData, EntityMeta, Query, QueryAggregate, QueryOptions, QueryPager, QuerySelectValue, QuerySortMap, QueryWhere, AbstractType } from '../type/index.js';
|
|
4
4
|
import { type CallbackKey } from '../util/index.js';
|
|
5
5
|
/** How a read runs: its pipeline, or the ordering of the `find` cursor where one expresses it. */
|
|
6
6
|
export type MongoRead = {
|
|
@@ -25,20 +25,20 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
25
25
|
* the document does not use.
|
|
26
26
|
*/
|
|
27
27
|
columnOf<E>(meta: EntityMeta<E>, key: string): string;
|
|
28
|
-
where<E extends Document>(entity:
|
|
28
|
+
where<E extends Document>(entity: AbstractType<E>, where?: QueryWhere<E>, opts?: QueryOptions): Filter<E>;
|
|
29
29
|
/**
|
|
30
30
|
* The stages every pipeline starts with: the `$lookup` each relation condition needs, into a temporary
|
|
31
31
|
* field so `$or` keeps its meaning, the `$match` reading them, and the temporaries taken back out. Each
|
|
32
32
|
* relation aggregate the `$where` or `fields` reads is left on the document, once, under its column.
|
|
33
33
|
* `lookup` keeps the temporaries used, so a later lookup neither repeats nor reuses one.
|
|
34
34
|
*/
|
|
35
|
-
matchStages<E extends Document>(entity:
|
|
35
|
+
matchStages<E extends Document>(entity: AbstractType<E>, where?: QueryWhere<E>, opts?: QueryOptions, fields?: readonly string[], lookup?: Lookup): MongoAggregationPipelineEntry<Document>[];
|
|
36
36
|
/**
|
|
37
37
|
* Renders a `$where` tree without applying entity filters (used for same-scope group-operator
|
|
38
38
|
* recursion). A relation, or a relation aggregate, needs `$lookup` stages, so it is only accepted
|
|
39
39
|
* when `lookup` is given - a plain `find`/`updateMany` filter has nowhere to put them.
|
|
40
40
|
*/
|
|
41
|
-
protected renderFilter<E extends Document>(entity:
|
|
41
|
+
protected renderFilter<E extends Document>(entity: AbstractType<E>, where?: QueryWhere<E>, lookup?: Lookup): Filter<E>;
|
|
42
42
|
/**
|
|
43
43
|
* Renders `$and`/`$or`/`$not`/`$nor` into `filter`, both negations as MongoDB's `$nor` (a `$not`'s clauses
|
|
44
44
|
* wrapped in one `$and`), dropping empty clauses, since MongoDB refuses an empty operator.
|
|
@@ -84,7 +84,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
84
84
|
private allHolding;
|
|
85
85
|
/** An object's keys as {@link held} reads each, a nested object's by its dotted path rather than whole. */
|
|
86
86
|
private containment;
|
|
87
|
-
select<E extends Document>(entity:
|
|
87
|
+
select<E extends Document>(entity: AbstractType<E>, select?: QuerySelectValue<E>): Record<string, 0 | 1>;
|
|
88
88
|
/**
|
|
89
89
|
* The `$sort` stage. A relation key reads the document a `$lookup` unwound onto the parent, so - as
|
|
90
90
|
* on the SQL dialects - it is only addressable when the statement joins that relation. Here that
|
|
@@ -108,7 +108,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
108
108
|
* correlated `$lookup` reading it per parent, and the `$set` that lifts it onto the document as the
|
|
109
109
|
* field the `$sort` then orders by. A parent with no related row reads a zero tally and no distance.
|
|
110
110
|
*/
|
|
111
|
-
sortAggregateStages<E extends Document>(entity:
|
|
111
|
+
sortAggregateStages<E extends Document>(entity: AbstractType<E>, sort: QuerySortMap<E> | undefined): Lookup & {
|
|
112
112
|
readonly fields: string[];
|
|
113
113
|
};
|
|
114
114
|
/** The relation aggregates a read projects or sorts by; its `$where` puts its own on the document. */
|
|
@@ -146,7 +146,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
146
146
|
*/
|
|
147
147
|
private toManyLookup;
|
|
148
148
|
/** Whether a `$sort` reads a relation, which is what forces the lookups to run before it. */
|
|
149
|
-
sortsRelations<E extends Document>(entity:
|
|
149
|
+
sortsRelations<E extends Document>(entity: AbstractType<E>, sort: QuerySortMap<E> | undefined): boolean;
|
|
150
150
|
/**
|
|
151
151
|
* Aggregate results are keyed by `$group`/`$select` alias rather than by column, so an aggregate
|
|
152
152
|
* `$sort` addresses those aliases as-is - the same reason the SQL dialects sort by alias there.
|
|
@@ -161,7 +161,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
161
161
|
* How a read runs, its ordering and aggregates read once for both the routing and the run: the one place
|
|
162
162
|
* deciding how a read is scored and ranked, a root vector search through Atlas.
|
|
163
163
|
*/
|
|
164
|
-
readPlan<E extends Document>(entity:
|
|
164
|
+
readPlan<E extends Document>(entity: AbstractType<E>, q: Query<E>, opts?: QueryOptions): MongoRead;
|
|
165
165
|
/**
|
|
166
166
|
* Whether a read needs stages a `find` cursor cannot express: a lookup to populate, count, filter or
|
|
167
167
|
* order by a relation, one to build a relation aggregate, and the grouping `$distinct` is.
|
|
@@ -173,7 +173,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
173
173
|
*/
|
|
174
174
|
private vectorSearchPipeline;
|
|
175
175
|
/** A read as a pipeline, whether or not a `find` cursor would express it. */
|
|
176
|
-
aggregationPipeline<E extends Document>(entity:
|
|
176
|
+
aggregationPipeline<E extends Document>(entity: AbstractType<E>, q: Query<E>, opts?: QueryOptions): MongoAggregationPipelineEntry<Document>[];
|
|
177
177
|
/** The pipeline of a read no `$vectorSearch` enters, given its ordering, aggregates and vector score. */
|
|
178
178
|
private scanPipeline;
|
|
179
179
|
/** A vector search's exact distance, by its metric, as a score to rank by: its `$project`, else a temporary field. */
|
|
@@ -196,7 +196,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
196
196
|
* The projection a narrowing query asks for, widened by what the pipeline produced (each populated
|
|
197
197
|
* relation and the tallies); last, once the lookups have read the join keys.
|
|
198
198
|
*/
|
|
199
|
-
pipelineProjection<E extends Document>(entity:
|
|
199
|
+
pipelineProjection<E extends Document>(entity: AbstractType<E>, q: Query<E>): Record<string, 0 | 1> | undefined;
|
|
200
200
|
/**
|
|
201
201
|
* The `$lookup`/`$unwind` pair for each relation joined below `parent`, its own relations nested
|
|
202
202
|
* inside its pipeline and resolved before the projection that reads them.
|
|
@@ -219,7 +219,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
219
219
|
normalizeId<E extends Document>(meta: EntityMeta<E>, doc: Document): E;
|
|
220
220
|
normalizeId<E extends Document>(meta: EntityMeta<E>, doc: Document | undefined): E | undefined;
|
|
221
221
|
/** An aggregate's rows with each 64-bit integer decoded as a document's is: a `bigint` only where the column reads a `BigInt` field. */
|
|
222
|
-
normalizeAggregateRows<E extends Document, R extends Document>(entity:
|
|
222
|
+
normalizeAggregateRows<E extends Document, R extends Document>(entity: AbstractType<E>, q: QueryAggregate<E>, rows: R[]): R[];
|
|
223
223
|
/**
|
|
224
224
|
* A key as MongoDB stores it: a 24-hex string as an `ObjectId`, so a write matches the filter looking for
|
|
225
225
|
* it, and anything else as given. Only 24-hex, not any 12-byte string. Arrays convert element-wise.
|
|
@@ -243,7 +243,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
243
243
|
/**
|
|
244
244
|
* Build MongoDB aggregation pipeline stages from a QueryAggregate.
|
|
245
245
|
*/
|
|
246
|
-
buildAggregateStages<E extends Document>(entity:
|
|
246
|
+
buildAggregateStages<E extends Document>(entity: AbstractType<E>, q: QueryAggregate<E>, opts?: QueryOptions): MongoAggregationPipelineEntry<Document>[];
|
|
247
247
|
/**
|
|
248
248
|
* Resolve parsed group entries into the `_id` keys and accumulators of a `$group` stage, and the
|
|
249
249
|
* `columns` its `$project` reads each result from: a group key out of `_id`, a DISTINCT set by its
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyMigrationOperation } from '../migrate/builder/types.js';
|
|
2
2
|
import type { TableNode } from '../schema/types.js';
|
|
3
|
-
import { type CreateSchemaOptions, type IndexSchema, type NamingStrategy, type SchemaDiff, type SchemaGenerator, type
|
|
3
|
+
import { type CreateSchemaOptions, type IndexSchema, type NamingStrategy, type SchemaDiff, type SchemaGenerator, type AbstractType } from '../type/index.js';
|
|
4
4
|
import { MongoDialect } from './mongoDialect.js';
|
|
5
5
|
export declare class MongoSchemaGenerator extends MongoDialect implements SchemaGenerator {
|
|
6
6
|
/** Takes no default foreign key action, since a document store has no foreign keys. */
|
|
@@ -9,8 +9,8 @@ export declare class MongoSchemaGenerator extends MongoDialect implements Schema
|
|
|
9
9
|
* A document store has no cross-collection constraint, so unlike the SQL generator there is nothing to
|
|
10
10
|
* defer and no order to respect: this is each collection and nothing more.
|
|
11
11
|
*/
|
|
12
|
-
generateCreateSchema(entities: readonly
|
|
13
|
-
generateDropSchema(entities: readonly
|
|
12
|
+
generateCreateSchema(entities: readonly AbstractType<object>[], options?: CreateSchemaOptions): string[];
|
|
13
|
+
generateDropSchema(entities: readonly AbstractType<object>[]): string[];
|
|
14
14
|
/** A collection, and one `createIndex` command for each of its indexes, as SQL's `[CREATE TABLE, ...CREATE INDEX]`. */
|
|
15
15
|
private createCollection;
|
|
16
16
|
/**
|
|
@@ -41,5 +41,5 @@ export declare class MongoSchemaGenerator extends MongoDialect implements Schema
|
|
|
41
41
|
private generateCreateSearchIndex;
|
|
42
42
|
/** A collection and its indexes, which is all a document store has: a column, a constraint or SQL throws. */
|
|
43
43
|
generateOperation(operation: AnyMigrationOperation): string[];
|
|
44
|
-
diffSchema(entity:
|
|
44
|
+
diffSchema(entity: AbstractType<object>, currentTable: TableNode | undefined): SchemaDiff | undefined;
|
|
45
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RelationRows, type SelectTerm } from '../dialect/abstractSqlDialect.js';
|
|
2
2
|
import { type JsonAccessMode, type JsonContainer, type JsonKeyWrite, type JsonSlot } from '../dialect/jsonSql.js';
|
|
3
3
|
import { MergeSqlDialect } from '../dialect/mergeSqlDialect.js';
|
|
4
|
-
import type { EntityMeta, SavepointCommand, FieldOptions, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, SqlDialectFeatures, SqlValues, TriggerRows,
|
|
4
|
+
import type { EntityMeta, SavepointCommand, FieldOptions, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, SqlDialectFeatures, SqlValues, TriggerRows, AbstractType, UpdatePayload, VectorDistance, VectorMetric, TransactionOptions } from '../type/index.js';
|
|
5
5
|
/** Microsoft SQL Server 2017 and up. Identifiers are `"`-quoted, the ANSI spelling `tedious` enables. */
|
|
6
6
|
export declare class MsSqlDialect extends MergeSqlDialect {
|
|
7
7
|
#private;
|
|
@@ -48,7 +48,7 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
48
48
|
pager(ctx: QueryContext, opts: QueryPager & {
|
|
49
49
|
$distinct?: boolean;
|
|
50
50
|
}, sorted?: boolean): void;
|
|
51
|
-
insert<E>(ctx: QueryContext, entity:
|
|
51
|
+
insert<E>(ctx: QueryContext, entity: AbstractType<E>, payload: E | E[], opts?: QueryOptions): void;
|
|
52
52
|
/** The table to toggle, or nothing when no record writes a key the engine would have generated. */
|
|
53
53
|
private identityInsertTarget;
|
|
54
54
|
/** An exact decimal, converted before it crosses the wire, where `tedious` would round it. */
|
|
@@ -76,7 +76,7 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
76
76
|
* carrying a trigger, and through a table it works whether one is there or not.
|
|
77
77
|
*/
|
|
78
78
|
returningId<E>(meta: EntityMeta<E>): string;
|
|
79
|
-
upsert<E>(ctx: QueryContext, entity:
|
|
79
|
+
upsert<E>(ctx: QueryContext, entity: AbstractType<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[], update?: UpdatePayload<E>): void;
|
|
80
80
|
/**
|
|
81
81
|
* A statement writing rows, `write`, wrapped in what SQL Server needs around one. The table variable its
|
|
82
82
|
* `OUTPUT` fills, typed as the id column is, and the read handing that back, uncounted so the batch
|
|
@@ -113,7 +113,7 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
113
113
|
/** There is no `CREATE SCHEMA IF NOT EXISTS`, and `CREATE SCHEMA` has to be alone in its batch. */
|
|
114
114
|
createSchemaSql(schema: string): string;
|
|
115
115
|
/** The estimate the engine already keeps per partition, live without a stats refresh. */
|
|
116
|
-
estimatedCount<E>(ctx: QueryContext, entity:
|
|
116
|
+
estimatedCount<E>(ctx: QueryContext, entity: AbstractType<E>): void;
|
|
117
117
|
/** Null-safe on every version, `EXCEPT` comparing NULLs as equal: `IS DISTINCT FROM` needs 2022. */
|
|
118
118
|
neExpr(field: string, ph: string): string;
|
|
119
119
|
protected numericCast(expr: string): string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PGliteOptions } from '@electric-sql/pglite';
|
|
2
2
|
import { AbstractSharedHandleQuerierPool } from '../querier/abstractSharedHandleQuerierPool.js';
|
|
3
|
-
import type { ExtraOptions } from '../type/index.js';
|
|
3
|
+
import type { Except, ExtraOptions } from '../type/index.js';
|
|
4
4
|
import { PgliteDialect } from './pgliteDialect.js';
|
|
5
5
|
import { type PgliteDatabase, PgliteQuerier } from './pgliteQuerier.js';
|
|
6
6
|
/** PGlite's own options but `dataDir`, the pool's first argument; `extensions: { vector }` enables pgvector. Type-only. */
|
|
7
|
-
export type PglitePoolOptions =
|
|
7
|
+
export type PglitePoolOptions = Except<PGliteOptions, 'dataDir'>;
|
|
8
8
|
/**
|
|
9
9
|
* A pool for PGlite, Postgres in WASM in this process, on one connection. A second `BEGIN` silently joins
|
|
10
10
|
* the open transaction, so a unit of work needing its own needs its own pool. Transactions are plain
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PgLikeSqlDialect } from '../dialect/pgLikeSqlDialect.js';
|
|
2
|
-
import type { QueryContext, SqlDialectFeatures, SqlDialectName, SqlValues,
|
|
2
|
+
import type { QueryContext, SqlDialectFeatures, SqlDialectName, SqlValues, AbstractType } from '../type/index.js';
|
|
3
3
|
/** What Postgres has: pgvector, the only engine with `halfvec` and `sparsevec`. */
|
|
4
4
|
export declare const POSTGRES_FEATURES: SqlDialectFeatures;
|
|
5
5
|
/** PostgreSQL, under every driver: `pg`, Neon, PGlite, `bun:sql`. Adds pgvector. */
|
|
@@ -15,5 +15,5 @@ export declare class PostgresDialect extends PgLikeSqlDialect {
|
|
|
15
15
|
* carries `reltuples = -1`, Postgres' "no statistic" (not `NULL`, and not `0`) since PG 14 - handed
|
|
16
16
|
* back raw it would read as a negative row count.
|
|
17
17
|
*/
|
|
18
|
-
estimatedCount<E>(ctx: QueryContext, entity:
|
|
18
|
+
estimatedCount<E>(ctx: QueryContext, entity: AbstractType<E>): void;
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import type { EntityData, ExtraOptions, Query, QueryAggregate, QueryConflictPaths, QueryPage, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, SavepointCommand, SqlQuerier, SqlStatement,
|
|
2
|
+
import type { EntityData, ExtraOptions, Query, QueryAggregate, QueryConflictPaths, QueryPage, QueryOptions, QuerySearch, QueryUpdateResult, RawRow, SavepointCommand, SqlQuerier, SqlStatement, Type, TransactionOptions, UpdatePayload } from '../type/index.js';
|
|
3
3
|
import type { SqlExecution } from '../util/sql.util.js';
|
|
4
4
|
import { AbstractQuerier, type UpsertedId, type WritesReturning } from './abstractQuerier.js';
|
|
5
5
|
/** A statement as it is sent: its SQL and the values it binds. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityMeta, EntityWhereMeta, FieldOptions,
|
|
1
|
+
import type { EntityMeta, EntityWhereMeta, FieldOptions, AbstractType } from '../type/index.js';
|
|
2
2
|
import { SchemaAST } from './schemaAST.js';
|
|
3
3
|
import { type ForeignKeyAction, type TriggerSchema } from './types.js';
|
|
4
4
|
/**
|
|
@@ -17,9 +17,9 @@ export interface BuildSchemaASTOptions {
|
|
|
17
17
|
* The text of SQL an entity declares - a check, a stored computed column, an index expression or
|
|
18
18
|
* predicate - which only a dialect can render. `SqlSchemaGenerator.buildAST` supplies it.
|
|
19
19
|
*/
|
|
20
|
-
compileDdl?: (sql: EntityWhereMeta<object>, entity:
|
|
20
|
+
compileDdl?: (sql: EntityWhereMeta<object>, entity: AbstractType<object>) => string;
|
|
21
21
|
/** A partial index's predicate as the engine writes it, `compileDdl` where none is given. */
|
|
22
|
-
compileIndexPredicate?: (where: EntityWhereMeta<object>, entity:
|
|
22
|
+
compileIndexPredicate?: (where: EntityWhereMeta<object>, entity: AbstractType<object>, indexName: string) => string;
|
|
23
23
|
/** Whether a weighted fulltext index declares one of its own for each heavier column, as MySQL scores through one. */
|
|
24
24
|
textScoreIndexes?: boolean;
|
|
25
25
|
/** Whether a column a vector index covers is `NOT NULL` whatever the entity declares, as MariaDB demands. */
|
|
@@ -33,4 +33,4 @@ export interface BuildSchemaASTOptions {
|
|
|
33
33
|
* Three passes, because each needs the one before it to have finished for *every* entity: a relation
|
|
34
34
|
* resolves against a table another entity declares, and an index against the columns of its own.
|
|
35
35
|
*/
|
|
36
|
-
export declare function buildSchemaAST(entities: readonly
|
|
36
|
+
export declare function buildSchemaAST(entities: readonly AbstractType<object>[], options?: BuildSchemaASTOptions): SchemaAST;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractSharedHandleQuerierPool } from '../querier/abstractSharedHandleQuerierPool.js';
|
|
2
|
+
import type { Except, Merge } from '../type/index.js';
|
|
2
3
|
import type { SqliteDialect } from './sqliteDialect.js';
|
|
3
4
|
import { type SqliteDatabase, type SqlitePreparedStatement, SqliteQuerier } from './sqliteQuerier.js';
|
|
4
5
|
/** What every local SQLite pool accepts on top of its driver's own options. */
|
|
@@ -27,9 +28,9 @@ export type LocalSqliteDatabase = {
|
|
|
27
28
|
* A `node:sqlite` or `bun:sqlite` handle as a {@link LocalSqliteDatabase}. Neither says whether a statement
|
|
28
29
|
* reads, so `reads` does: taken by `run()`, a RETURNING statement's rows would be lost, and its ids with them.
|
|
29
30
|
*/
|
|
30
|
-
export declare function adaptSqlite<S extends
|
|
31
|
+
export declare function adaptSqlite<S extends Except<SqlitePreparedStatement, 'reader'>>(db: Merge<LocalSqliteDatabase, {
|
|
31
32
|
prepare(sql: string): S;
|
|
32
|
-
}
|
|
33
|
+
}>, reads: (stmt: S) => boolean): LocalSqliteDatabase;
|
|
33
34
|
/**
|
|
34
35
|
* `db` extended past SQLite's own: each loadable extension installed, which `node:sqlite` refuses unless
|
|
35
36
|
* opened to allow them, and `REGEXP` defined as libSQL builds it in, which SQLite leaves to the application.
|
package/dist/type/column.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ForeignKeyAction } from '../schema/types.js';
|
|
2
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,
|
|
3
|
+
import type { BlobColumnType, BooleanColumnType, ColumnType, DateColumnType, DdlDefault, JsonColumnType, NumericColumnType, StringColumnType, VectorColumnType, FieldOptions, HasCompositeKey, IdValue, JoinKind, OnFieldCallback, StampEvent } from './entity.js';
|
|
4
4
|
import type { QuerySql } from './querySql.js';
|
|
5
5
|
import type { ReferencedKey } from './schemaEntity.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { StandardSchemaV1 } from './standardSchema.js';
|
|
7
|
+
import type { Type, Json, AbstractType } from './utility.js';
|
|
7
8
|
import type { VectorDistance } from './vector.js';
|
|
8
9
|
/** Where a column builder holds its options, so every string key of a builder is a method. */
|
|
9
10
|
export declare const COLUMN_OPTIONS: unique symbol;
|
|
@@ -199,18 +200,30 @@ export interface VersionColumn<in out O, in out V> extends Column<O, V> {
|
|
|
199
200
|
readonly comment: string;
|
|
200
201
|
}, V>;
|
|
201
202
|
}
|
|
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
203
|
/** Refuses a target whose key is another kind of value than the column holds, which no join matches. */
|
|
205
|
-
type HoldsKey<C, V> = [
|
|
204
|
+
type HoldsKey<C, V> = [JoinKind<NonNullable<ReferencedKey<C>>>] extends [JoinKind<V>] ? unknown : {
|
|
206
205
|
readonly __columnMustHoldReferencedKey: ReferencedKey<C>;
|
|
207
206
|
};
|
|
208
207
|
/** The column types holding an exact decimal, read as its text: a JS number would round it. */
|
|
209
208
|
type DecimalType = 'decimal' | 'numeric';
|
|
210
|
-
/**
|
|
211
|
-
type
|
|
209
|
+
/** A JSON column of `T`, typed by the payload its schema validates to, or any document with none. */
|
|
210
|
+
type JsonColumn<T extends 'json' | 'jsonb'> = {
|
|
211
|
+
(): ColumnBuilder<{
|
|
212
|
+
readonly type: T;
|
|
213
|
+
}, Json, 'json'>;
|
|
214
|
+
<S extends StandardSchemaV1>(schema: S): ColumnBuilder<{
|
|
215
|
+
readonly type: T;
|
|
216
|
+
readonly schema: S;
|
|
217
|
+
}, JsonOutput<PayloadOf<S['~standard']['types']>>, 'json'>;
|
|
218
|
+
};
|
|
219
|
+
/** A schema's output as a JSON column holds it: a document, or the primitive a payload may be. */
|
|
220
|
+
type JsonOutput<O> = O extends object | string | number | boolean | null ? Json<O> : Json;
|
|
221
|
+
/** The output a schema's `types` states, `unknown` where it states none: `never` would type the column as nothing. */
|
|
222
|
+
type PayloadOf<T> = NonNullable<T> extends infer N ? [N] extends [never] ? unknown : N extends {
|
|
223
|
+
readonly output: infer O;
|
|
224
|
+
} ? O : unknown : never;
|
|
212
225
|
/** 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
|
|
226
|
+
type ReferenceValue<C> = C extends AbstractType<infer E> ? HasCompositeKey<E> extends true ? {
|
|
214
227
|
readonly __compositeKeyNeedsAColumnPerKey: true;
|
|
215
228
|
} : NonNullable<IdValue<E>> : never;
|
|
216
229
|
/** The builders, one per value a column holds; `column` takes any SQL type, its family deciding what it offers. */
|
|
@@ -249,20 +262,8 @@ export type ColumnFactory = {
|
|
|
249
262
|
date(): DateColumn<{
|
|
250
263
|
readonly type: DateConstructor;
|
|
251
264
|
}, Date>;
|
|
252
|
-
json
|
|
253
|
-
|
|
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'>;
|
|
265
|
+
json: JsonColumn<'json'>;
|
|
266
|
+
jsonb: JsonColumn<'jsonb'>;
|
|
266
267
|
vector(dimensions: number): VectorColumn<{
|
|
267
268
|
readonly type: 'vector';
|
|
268
269
|
readonly dimensions: number;
|
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
|
*/
|
|
@@ -17,7 +17,7 @@ export interface Config {
|
|
|
17
17
|
* List of entity classes to be managed by the ORM.
|
|
18
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'];
|
|
@@ -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
|
package/dist/type/entity.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type { Querier } from './querier.js';
|
|
|
4
4
|
import type { FilterOptions, RelationQuery } from './query.js';
|
|
5
5
|
import type { ColumnRef, JsonPathRef, QuerySql, SqlFor, RelationAggregate } from './querySql.js';
|
|
6
6
|
import type { QueryWhere } from './queryWhere.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { StandardSchemaV1 } from './standardSchema.js';
|
|
8
|
+
import type { AtLeastOne, Except, ExactlyOne, IsEqual, Merge, IsJson, JsonBrand, IsMany, Json, JsonScalar, Scalar, Type, AbstractType, Unpacked, Writable } from './utility.js';
|
|
8
9
|
import type { VectorDistance, VectorIndexOptions, VectorIndexType } from './vector.js';
|
|
9
10
|
/** Brands the property an entity is identified by, where it is not `id`, `_id` or `uuid`. */
|
|
10
11
|
export declare const idKey: unique symbol;
|
|
@@ -16,11 +17,9 @@ export declare const idKey: unique symbol;
|
|
|
16
17
|
export declare const versionKey: unique symbol;
|
|
17
18
|
/** Brands the fields an insert may leave out, which a default fills, `[filledKey]?: 'units' | 'createdAt'`; each stays present on every read. */
|
|
18
19
|
export declare const filledKey: unique symbol;
|
|
19
|
-
type EntityBrand = typeof idKey | typeof versionKey | typeof filledKey;
|
|
20
|
+
export type EntityBrand = typeof idKey | typeof versionKey | typeof filledKey;
|
|
20
21
|
/** The names an entity's brand `B` lists, `never` where it declares none. */
|
|
21
|
-
type BrandNames<E, B extends EntityBrand> =
|
|
22
|
-
readonly [K in B]?: infer N;
|
|
23
|
-
} ? N : never;
|
|
22
|
+
export type BrandNames<E, B extends EntityBrand> = B extends keyof E ? NonNullable<E[B]> : never;
|
|
24
23
|
/**
|
|
25
24
|
* A brand naming a key that is no field, which each reader would drop silently: refused where an entity
|
|
26
25
|
* registers, `@Entity()`, by a member the class lacks that names the typo. A class with no
|
|
@@ -258,24 +257,6 @@ type TimeColumnType = 'time';
|
|
|
258
257
|
/** A numeric column holding an exact decimal, read as its text: a JS number would round it. */
|
|
259
258
|
type DecimalColumnType = 'decimal' | 'numeric';
|
|
260
259
|
export type JsonColumnType = ColumnTypeOf<'json'>;
|
|
261
|
-
/**
|
|
262
|
-
* A JSON column's payload described as data, in a field's vocabulary: a value's type (`String`), an object of
|
|
263
|
-
* shapes, a key ending in `?` for an optional member, and `[shape]` for an array of it.
|
|
264
|
-
* @example `{ theme: String, 'nickname?': String, tags: [String], billing: { plan: String } }`
|
|
265
|
-
*/
|
|
266
|
-
export type JsonShape = JsonLeaf | readonly [JsonShape] | {
|
|
267
|
-
readonly [key: string]: JsonShape;
|
|
268
|
-
};
|
|
269
|
-
/** The values a JSON document holds at a leaf. */
|
|
270
|
-
type JsonLeaf = StringConstructor | NumberConstructor | BooleanConstructor;
|
|
271
|
-
/** The payload a {@link JsonShape} describes. */
|
|
272
|
-
export type ShapeValue<S> = S extends readonly [infer E] ? ShapeValue<E>[] : S extends JsonLeaf ? TsTypeOf<S> : [Extract<keyof S, `${string}?`>] extends [never] ? {
|
|
273
|
-
-readonly [K in keyof S]: ShapeValue<S[K]>;
|
|
274
|
-
} : {
|
|
275
|
-
-readonly [K in keyof S as K extends `${string}?` ? never : K]: ShapeValue<S[K]>;
|
|
276
|
-
} & {
|
|
277
|
-
-readonly [K in keyof S as K extends `${infer N}?` ? N : never]?: ShapeValue<S[K]>;
|
|
278
|
-
};
|
|
279
260
|
export type BlobColumnType = ColumnTypeOf<'blob'>;
|
|
280
261
|
export type BooleanColumnType = ColumnTypeOf<'boolean'>;
|
|
281
262
|
export type VectorColumnType = ColumnTypeOf<'vector'>;
|
|
@@ -309,8 +290,8 @@ export type FieldOptions<V = unknown> = {
|
|
|
309
290
|
readonly onDelete?: ForeignKeyAction;
|
|
310
291
|
/** The values the column accepts, `f.enum(['draft', 'paid'])`: a `CHECK (col IN (...))` on every SQL engine. */
|
|
311
292
|
readonly enum?: EnumValues;
|
|
312
|
-
/** A JSON column's payload
|
|
313
|
-
readonly
|
|
293
|
+
/** A JSON column's payload as a Standard Schema, `f.json(schema)`, typed by its output and never read at run time. */
|
|
294
|
+
readonly schema?: StandardSchemaV1;
|
|
314
295
|
/**
|
|
315
296
|
* An expression the database computes, never written: spliced into each read, or with `stored` a generated
|
|
316
297
|
* column, `.as(sql`${user.first} || ' ' || ${user.last}`)`. A relation aggregate, `user.resources.count()`,
|
|
@@ -414,11 +395,11 @@ type RelationActions = {
|
|
|
414
395
|
readonly onUpdate?: ForeignKeyAction;
|
|
415
396
|
};
|
|
416
397
|
/** The one column of `O` that can be a foreign key to `E`: a field holding `E`'s key, which has to be a single one. */
|
|
417
|
-
type ForeignKey<O, E> = HasCompositeKey<E> extends true ? never :
|
|
398
|
+
type ForeignKey<O, E> = HasCompositeKey<E> extends true ? never : KeyHolding<O, IdValue<E>>;
|
|
418
399
|
/** One pair of join columns, each a field read off its entity's key map, the local one holding the foreign's value. */
|
|
419
400
|
export type RelationReference<O, E> = {
|
|
420
401
|
readonly [F in keyof E]-?: {
|
|
421
|
-
readonly local:
|
|
402
|
+
readonly local: KeyHolding<O, E[F]>;
|
|
422
403
|
readonly foreign: F;
|
|
423
404
|
};
|
|
424
405
|
}[FieldKey<E>];
|
|
@@ -426,22 +407,24 @@ export type RelationReference<O, E> = {
|
|
|
426
407
|
export type FieldKeyOf<E, T> = {
|
|
427
408
|
readonly [K in FieldKey<E>]-?: [NonNullable<E[K]>] extends [T] ? K : never;
|
|
428
409
|
}[FieldKey<E>];
|
|
429
|
-
/**
|
|
430
|
-
type
|
|
431
|
-
|
|
410
|
+
/** A value's kind as a join compares it: a number and a bigint are one kind, which BIGINT widens. */
|
|
411
|
+
export type JoinKind<T> = T extends number | bigint ? number : T;
|
|
412
|
+
/** The fields of `O` that can hold a key of `V`'s kind, compared as a join compares it at run time. */
|
|
413
|
+
export type KeyHolding<O, V> = [V] extends [never] ? never : {
|
|
414
|
+
readonly [K in keyof O]-?: [JoinKind<NonNullable<V>>] extends [JoinKind<NonNullable<O[K]>>] ? K : never;
|
|
432
415
|
}[FieldKey<O>];
|
|
433
416
|
/** A relation once `getMeta` resolved it: `references` settled into pairs and `mappedBy` a name. */
|
|
434
|
-
export type RelationMeta =
|
|
417
|
+
export type RelationMeta = Merge<RelationRegistration, {
|
|
435
418
|
references: RelationReferences;
|
|
436
|
-
}
|
|
419
|
+
}>;
|
|
437
420
|
/**
|
|
438
421
|
* A relation as the registry takes it: `mappedBy` and `references` read down to names, `references` a
|
|
439
422
|
* single column until `getMeta` pairs it with the target's key.
|
|
440
423
|
*/
|
|
441
|
-
export type RelationRegistration =
|
|
424
|
+
export type RelationRegistration = Merge<RelationOptions<object>, {
|
|
442
425
|
mappedBy?: string;
|
|
443
426
|
references?: RelationReferences | string;
|
|
444
|
-
}
|
|
427
|
+
}>;
|
|
445
428
|
/**
|
|
446
429
|
* What a relation's join callbacks answer, `E` its target and `O` the entity declaring it: one foreign key, pairs of
|
|
447
430
|
* columns, or the target's member mapping it. Each form states its own: a decorated class checks each member's
|
|
@@ -740,7 +723,7 @@ export type EntityIndexMeta<E = object> = {
|
|
|
740
723
|
include?: readonly string[];
|
|
741
724
|
} & VectorIndexOptions & IndexTypeOptions;
|
|
742
725
|
export type EntityMeta<E> = {
|
|
743
|
-
readonly entity:
|
|
726
|
+
readonly entity: AbstractType<E>;
|
|
744
727
|
/** The table, which is the class's own name where the entity named none - see {@link derivedName}. */
|
|
745
728
|
name?: string;
|
|
746
729
|
/** Whether {@link name} came from the class rather than from the author, so a naming strategy applies. */
|
|
@@ -870,11 +853,11 @@ export type TriggerOptions<E = unknown> = {
|
|
|
870
853
|
* A trigger as entity metadata keeps it: the column callback resolved to keys, and a body widened to
|
|
871
854
|
* take both rows, which the renderer passes whatever the event, each body reading only its own.
|
|
872
855
|
*/
|
|
873
|
-
export type EntityTriggerMeta<E = object> =
|
|
856
|
+
export type EntityTriggerMeta<E = object> = Merge<TriggerOptions<E>, {
|
|
874
857
|
readonly of?: readonly string[];
|
|
875
858
|
readonly where?: TriggerPredicate<E, TriggerUpdateEvent> | TriggerMetaBody<E>;
|
|
876
859
|
readonly run: TriggerMetaBody<E> | Readonly<Partial<Record<SqlDialectName, TriggerMetaBody<E>>>>;
|
|
877
|
-
}
|
|
860
|
+
}>;
|
|
878
861
|
/**
|
|
879
862
|
* A body as the renderer calls it, with both rows whatever the event. Bivariant,
|
|
880
863
|
* so a body typing the row its event lacks as `never` is still held here.
|
|
@@ -939,14 +922,14 @@ export type IndexOptions = Except<EntityIndexMeta, 'entries' | 'where'> & {
|
|
|
939
922
|
readonly where?: QuerySql;
|
|
940
923
|
};
|
|
941
924
|
/** {@link IndexOptions} on an entity, `include` and `where` read off the section's refs as its columns are. */
|
|
942
|
-
export type EntityIndexOptions<E> =
|
|
925
|
+
export type EntityIndexOptions<E> = Merge<IndexOptions, {
|
|
943
926
|
readonly include?: readonly ColumnRef<FieldKey<E>>[];
|
|
944
927
|
/**
|
|
945
928
|
* Partial-index predicate, written as the predicate the query passes: a planner matches the two by
|
|
946
929
|
* shape, so a hand-written `sql` that means the same thing leaves the index unused.
|
|
947
930
|
*/
|
|
948
931
|
readonly where?: EntityPredicate<E> | QuerySql;
|
|
949
|
-
}
|
|
932
|
+
}>;
|
|
950
933
|
/** An index as registration reads it: its columns, read off the refs, and its options. */
|
|
951
934
|
export type EntityIndexInput<E> = EntityIndexOptions<E> & {
|
|
952
935
|
readonly columns: readonly EntityIndexColumnInput[];
|
package/dist/type/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './querySql.js';
|
|
|
14
14
|
export * from './schemaEntity.js';
|
|
15
15
|
export * from './queryWhere.js';
|
|
16
16
|
export * from './universalQuerier.js';
|
|
17
|
+
export * from './standardSchema.js';
|
|
17
18
|
export * from './utility.js';
|
|
18
19
|
export * from './vector.js';
|
|
19
20
|
export * from './wire.js';
|