uql-orm 0.91.1 → 0.93.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/http/bus.js +3 -4
- package/dist/browser/http/http.d.ts +1 -2
- package/dist/browser/http/http.js +8 -7
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -1
- package/dist/browser/querier/httpQuerier.d.ts +18 -20
- package/dist/browser/querier/httpQuerier.js +20 -56
- package/dist/browser/type/index.d.ts +0 -1
- package/dist/browser/type/index.js +0 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +11 -12
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
- package/dist/cockroachdb/cockroachDialect.js +6 -2
- package/dist/dialect/abstractDialect.d.ts +1 -1
- package/dist/dialect/abstractDialect.js +4 -1
- package/dist/dialect/abstractSqlDialect.d.ts +68 -37
- package/dist/dialect/abstractSqlDialect.js +185 -107
- package/dist/dialect/aliases.d.ts +4 -1
- package/dist/dialect/aliases.js +5 -2
- package/dist/dialect/hydrateColumn.js +3 -10
- package/dist/dialect/jsonSql.d.ts +4 -1
- package/dist/dialect/jsonSql.js +4 -1
- package/dist/dialect/mergeSqlDialect.d.ts +14 -4
- package/dist/dialect/mergeSqlDialect.js +32 -15
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +16 -24
- package/dist/dialect/mysqlLikeSqlDialect.js +38 -52
- package/dist/dialect/pgLikeSqlDialect.d.ts +8 -8
- package/dist/dialect/pgLikeSqlDialect.js +19 -22
- package/dist/http/contract.d.ts +4 -0
- package/dist/http/contract.js +1 -0
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/handler.js +17 -19
- package/dist/http/query.d.ts +5 -3
- package/dist/http/query.js +42 -42
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/maria/mariaDialect.d.ts +4 -3
- package/dist/maria/mariaDialect.js +4 -6
- package/dist/migrate/builder/columnBuilder.d.ts +5 -15
- package/dist/migrate/builder/columnBuilder.js +50 -86
- package/dist/migrate/builder/index.d.ts +0 -1
- package/dist/migrate/builder/index.js +0 -1
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
- package/dist/migrate/builder/migrationBuilder.js +41 -81
- package/dist/migrate/builder/tableBuilder.d.ts +0 -7
- package/dist/migrate/builder/tableBuilder.js +19 -30
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
- package/dist/migrate/codegen/entityTypes.js +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.js +22 -14
- package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
- package/dist/migrate/ddl/defaultSql.d.ts +31 -0
- package/dist/migrate/ddl/defaultSql.js +109 -0
- package/dist/migrate/ddl/index.d.ts +2 -4
- package/dist/migrate/ddl/index.js +14 -5
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
- package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
- package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
- package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
- package/dist/migrate/ddl/pgTableDdl.js +17 -0
- package/dist/migrate/ddl/tableDdl.d.ts +15 -10
- package/dist/migrate/ddl/tableDdl.js +31 -32
- package/dist/migrate/drift/driftDetector.js +46 -59
- package/dist/migrate/generator/definitionToNode.d.ts +11 -7
- package/dist/migrate/generator/definitionToNode.js +27 -34
- package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
- package/dist/migrate/generator/indexNodeToSchema.js +5 -4
- package/dist/migrate/index.js +1 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -0
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
- package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +27 -11
- package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
- package/dist/migrate/introspection/postgresIntrospector.js +3 -3
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
- package/dist/migrate/migrationTarget.js +3 -3
- package/dist/migrate/schemaGenerator.d.ts +8 -12
- package/dist/migrate/schemaGenerator.js +36 -62
- package/dist/migrate/storage/databaseStorage.js +2 -2
- package/dist/migrate/triggerSql.d.ts +1 -1
- package/dist/migrate/triggerSql.js +17 -8
- package/dist/mongo/mongoDialect.d.ts +4 -3
- package/dist/mongo/mongoDialect.js +52 -38
- package/dist/mongo/mongoIntrospector.js +1 -1
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
- package/dist/mongo/mongoSchemaGenerator.js +18 -21
- package/dist/mongo/mongodbQuerier.d.ts +15 -8
- package/dist/mongo/mongodbQuerier.js +48 -33
- package/dist/mssql/mssqlDialect.d.ts +9 -5
- package/dist/mssql/mssqlDialect.js +23 -8
- package/dist/postgres/postgresDialect.d.ts +5 -2
- package/dist/postgres/postgresDialect.js +6 -6
- package/dist/querier/abstractQuerier.d.ts +20 -15
- package/dist/querier/abstractQuerier.js +93 -41
- package/dist/querier/abstractQuerierPool.d.ts +26 -24
- package/dist/querier/abstractQuerierPool.js +26 -64
- package/dist/querier/abstractSqlQuerier.d.ts +5 -6
- package/dist/querier/abstractSqlQuerier.js +15 -33
- package/dist/querier/cursor.d.ts +10 -0
- package/dist/querier/cursor.js +81 -0
- package/dist/querier/keyset.d.ts +19 -0
- package/dist/querier/keyset.js +198 -0
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +13 -12
- package/dist/schema/indexDifferences.d.ts +14 -7
- package/dist/schema/indexDifferences.js +7 -5
- package/dist/schema/schemaAST.d.ts +0 -1
- package/dist/schema/schemaAST.js +0 -2
- package/dist/schema/schemaASTBuilder.js +14 -20
- package/dist/schema/schemaASTDiffer.d.ts +7 -9
- package/dist/schema/schemaASTDiffer.js +54 -107
- package/dist/schema/sqlExpression.d.ts +28 -0
- package/dist/schema/sqlExpression.js +42 -0
- package/dist/schema/types.d.ts +48 -105
- package/dist/sqlite/sqliteDialect.d.ts +10 -13
- package/dist/sqlite/sqliteDialect.js +19 -30
- package/dist/type/dialect.d.ts +46 -11
- package/dist/type/dialect.js +2 -0
- package/dist/type/entity.d.ts +18 -3
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +19 -26
- package/dist/type/query.d.ts +116 -25
- package/dist/type/query.js +21 -28
- package/dist/type/universalQuerier.d.ts +33 -7
- package/dist/type/utility.d.ts +10 -0
- package/dist/util/bytes.d.ts +7 -0
- package/dist/util/bytes.js +22 -0
- package/dist/util/date.d.ts +5 -0
- package/dist/util/date.js +5 -0
- package/dist/util/dialect.util.d.ts +1 -25
- package/dist/util/dialect.util.js +4 -50
- package/dist/util/field.util.d.ts +9 -0
- package/dist/util/field.util.js +15 -0
- package/dist/util/fieldOption.util.js +2 -2
- package/dist/util/index.d.ts +2 -1
- package/dist/util/index.js +2 -1
- package/dist/util/object.util.d.ts +0 -2
- package/dist/util/object.util.js +0 -7
- package/dist/util/query.util.d.ts +40 -0
- package/dist/util/query.util.js +76 -0
- package/dist/util/raw.d.ts +16 -1
- package/dist/util/raw.js +31 -0
- package/dist/util/relationQuery.util.js +18 -16
- package/dist/util/rowKey.util.js +2 -3
- package/dist/util/sql.util.d.ts +8 -2
- package/dist/util/sql.util.js +16 -17
- package/dist/util/sqlLiteral.js +2 -12
- package/dist/util/string.util.d.ts +5 -0
- package/dist/util/string.util.js +12 -0
- package/dist/util/triggerWrite.d.ts +11 -1
- package/dist/util/triggerWrite.js +14 -0
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +22 -10
- package/dist/browser/options.d.ts +0 -4
- package/dist/browser/options.js +0 -13
- package/dist/browser/type/clientQuerierPool.d.ts +0 -4
- package/dist/browser/type/clientQuerierPool.js +0 -1
- package/dist/migrate/builder/expressions.d.ts +0 -69
- package/dist/migrate/builder/expressions.js +0 -145
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import type { EntityId, EntityWrite, FieldKey, RelationKey, UpdateWrite, WrittenId } from './entity.js';
|
|
2
|
-
import type { QueryConflictPaths, QueryFilter, QueryFindResult, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, QueryUpsertOneResult, QueryUpsertManyResult } from './query.js';
|
|
2
|
+
import type { CursorPage, QueryConflictPaths, QueryFilter, QueryFindResult, QueryKeysetProjected, QueryOneProjected, QueryOptions, QueryPage, QueryProjected, QuerySearch, QueryUpsertOneResult, UpsertOptions, QueryUpsertManyResult } from './query.js';
|
|
3
3
|
import type { QueryAggMap, QueryAggregate, QueryAggregateResult, QueryGroupMap } from './queryAggregate.js';
|
|
4
4
|
import type { Type } from './utility.js';
|
|
5
5
|
import type { QuerierCountedResult, QuerierRaw, QuerierResult, QuerierTransport } from './wire.js';
|
|
6
|
+
/** The query type each projected read takes, keyed by the kind of read. */
|
|
7
|
+
export type ProjectedQuery<E, S extends FieldKey<E>, V, X extends FieldKey<E>, P extends RelationKey<E>, C extends RelationKey<E>, Raw> = {
|
|
8
|
+
readonly one: QueryOneProjected<E, S, V, X, P, C, Raw>;
|
|
9
|
+
readonly many: QueryProjected<E, S, V, X, P, C, Raw>;
|
|
10
|
+
readonly page: QueryKeysetProjected<E, S, V, X, P, C, Raw>;
|
|
11
|
+
};
|
|
12
|
+
/** The result type of each projected read on transport `W`, keyed by the kind of read. */
|
|
13
|
+
export type ProjectedResult<W extends QuerierTransport, T> = {
|
|
14
|
+
readonly one: QuerierResult<W, T | undefined>;
|
|
15
|
+
readonly many: QuerierResult<W, T[]>;
|
|
16
|
+
readonly counted: QuerierCountedResult<W, T>;
|
|
17
|
+
readonly page: QuerierResult<W, CursorPage<T>>;
|
|
18
|
+
readonly stream: AsyncIterable<T>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A read that takes an entity and a query, and returns rows narrowed to what the query projected. `Q` picks
|
|
22
|
+
* the query type, `R` the result type on transport `W`, and `O` the options. Declaring it once saves every
|
|
23
|
+
* such read from repeating the six type parameters.
|
|
24
|
+
*/
|
|
25
|
+
export type ProjectedRead<Q extends keyof ProjectedQuery<object, never, never, never, never, never, never>, R extends keyof ProjectedResult<QuerierTransport, unknown>, W extends QuerierTransport, O> = <E extends object, const S extends FieldKey<E> = never, const V = true, const X extends FieldKey<E> = never, const P extends RelationKey<E> = never, const C extends RelationKey<E> = never>(entity: Type<E>, q: ProjectedQuery<E, S, V, X, P, C, QuerierRaw<W>>[Q], opts?: O) => ProjectedResult<W, QueryFindResult<E, S, V, X, P, C>>[R];
|
|
6
26
|
/**
|
|
7
27
|
* The operations the server and the browser client declare alike, per transport `W`, options `O`,
|
|
8
28
|
* and delete options `DO`, which on the client also carry the {@link QueryOptions} it cannot pass otherwise.
|
|
@@ -16,16 +36,22 @@ export interface SharedQuerier<W extends QuerierTransport, O, DO = O> {
|
|
|
16
36
|
* @param q the criteria options
|
|
17
37
|
* @return the record
|
|
18
38
|
*/
|
|
19
|
-
findOne
|
|
39
|
+
findOne: ProjectedRead<'one', 'one', W, O>;
|
|
20
40
|
/**
|
|
21
41
|
* obtains the records matching the given search parameters.
|
|
22
42
|
* @param entity the target entity
|
|
23
43
|
* @param q the criteria options
|
|
24
44
|
* @return the records
|
|
25
45
|
*/
|
|
26
|
-
findMany
|
|
46
|
+
findMany: ProjectedRead<'many', 'many', W, O>;
|
|
27
47
|
/** Find the records matching the query, and count every match past its page. */
|
|
28
|
-
findManyAndCount
|
|
48
|
+
findManyAndCount: ProjectedRead<'many', 'counted', W, O>;
|
|
49
|
+
/**
|
|
50
|
+
* Read a page of the records matching the query, from a cursor instead of an offset, so every page costs
|
|
51
|
+
* the same as the first and rows written in between shift no page. The sort must be total: it must end in
|
|
52
|
+
* the key or a unique, non-null field. Counts nothing.
|
|
53
|
+
*/
|
|
54
|
+
findManyPage: ProjectedRead<'page', 'page', W, O>;
|
|
29
55
|
/** Count the records matching the filter, or those a page of them takes. */
|
|
30
56
|
count<E extends object>(entity: Type<E>, q?: QueryPage<E, QuerierRaw<W>>, opts?: O): QuerierResult<W, number>;
|
|
31
57
|
/** Whether any record matches: a count capped at one row, so the engine stops at the first match. */
|
|
@@ -57,7 +83,7 @@ export interface UniversalQuerier extends SharedQuerier<'server', QueryOptions>
|
|
|
57
83
|
* Stream the records matching the query one at a time, each with the relations and counts `findMany`
|
|
58
84
|
* reads, for bulk reads. Fires no lifecycle hooks.
|
|
59
85
|
*/
|
|
60
|
-
findManyStream
|
|
86
|
+
findManyStream: ProjectedRead<'many', 'stream', 'server', QueryOptions>;
|
|
61
87
|
/** Insert a record and resolve to its id. See {@link UniversalQuerier.insertMany}. */
|
|
62
88
|
insertOne<E extends object>(entity: Type<E>, payload: EntityWrite<E>): Promise<WrittenId<E> | undefined>;
|
|
63
89
|
/**
|
|
@@ -67,9 +93,9 @@ export interface UniversalQuerier extends SharedQuerier<'server', QueryOptions>
|
|
|
67
93
|
*/
|
|
68
94
|
insertMany<E extends object>(entity: Type<E>, payload: readonly EntityWrite<E>[]): Promise<(WrittenId<E> | undefined)[]>;
|
|
69
95
|
/** Insert or update a record by its conflict paths; resolves to its id and whether it was created. */
|
|
70
|
-
upsertOne<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: EntityWrite<E>): Promise<QueryUpsertOneResult<E>>;
|
|
96
|
+
upsertOne<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: EntityWrite<E>, opts?: UpsertOptions<E>): Promise<QueryUpsertOneResult<E>>;
|
|
71
97
|
/** Insert or update records by their conflict paths; resolves to their ids in payload order. */
|
|
72
|
-
upsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: readonly EntityWrite<E>[]): Promise<QueryUpsertManyResult<E>>;
|
|
98
|
+
upsertMany<E extends object>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: readonly EntityWrite<E>[], opts?: UpsertOptions<E>): Promise<QueryUpsertManyResult<E>>;
|
|
73
99
|
/**
|
|
74
100
|
* insert or update a record.
|
|
75
101
|
* @param entity the entity to persist on
|
package/dist/type/utility.d.ts
CHANGED
|
@@ -47,6 +47,16 @@ export type Writable<T> = {
|
|
|
47
47
|
/**
|
|
48
48
|
* `Omit` whose key has to exist, which distributes over a union rather than flattening it, and removes
|
|
49
49
|
* a key from a type with an index signature.
|
|
50
|
+
*
|
|
51
|
+
* `Omit<T, K>` is `Pick<T, Exclude<keyof T, K>>`; its `K extends keyof any` admits any string, so a typo
|
|
52
|
+
* (`Omit<Post, 'titl'>`) compiles and silently drops nothing. `Except` requires `K extends keyof T`, so a
|
|
53
|
+
* misspelled key is a compile error the instant it is written.
|
|
54
|
+
*
|
|
55
|
+
* Beyond the key check, the two differ structurally. `Omit` computes `keyof (A | B)` (the common keys),
|
|
56
|
+
* then `Pick`s from that flat set, so `Omit<A | B, 'x'>` loses every key unique to one arm. `Except` is a
|
|
57
|
+
* homomorphic mapped type over `T`, which TypeScript distributes over unions: `Except<A | B, 'x'>` is
|
|
58
|
+
* `Except<A, 'x'> | Except<B, 'x'>`, each arm keeping its own keys. It also preserves index signatures
|
|
59
|
+
* and property modifiers that `Pick` over a computed key set drops.
|
|
50
60
|
*/
|
|
51
61
|
export type Except<T, K extends keyof T> = {
|
|
52
62
|
[P in keyof T as P extends K ? never : P]: T[P];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes bytes as lowercase hex, two digits per byte. Uses `Buffer` when it exists (~130x faster on 4 KB),
|
|
3
|
+
* and a lookup table on the browser and edge runtimes, which lack it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
6
|
+
/** Decodes the hex text {@link bytesToHex} writes back into bytes. */
|
|
7
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, '0'));
|
|
2
|
+
/**
|
|
3
|
+
* Encodes bytes as lowercase hex, two digits per byte. Uses `Buffer` when it exists (~130x faster on 4 KB),
|
|
4
|
+
* and a lookup table on the browser and edge runtimes, which lack it.
|
|
5
|
+
*/
|
|
6
|
+
export function bytesToHex(bytes) {
|
|
7
|
+
if (typeof Buffer !== 'undefined') {
|
|
8
|
+
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('hex');
|
|
9
|
+
}
|
|
10
|
+
let hex = '';
|
|
11
|
+
for (let i = 0; i < bytes.length; i++)
|
|
12
|
+
hex += HEX_BYTES[bytes[i]];
|
|
13
|
+
return hex;
|
|
14
|
+
}
|
|
15
|
+
/** Decodes the hex text {@link bytesToHex} writes back into bytes. */
|
|
16
|
+
export function hexToBytes(hex) {
|
|
17
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
18
|
+
for (let at = 0; at < bytes.length; at++) {
|
|
19
|
+
bytes[at] = Number.parseInt(hex.slice(at * 2, at * 2 + 2), 16);
|
|
20
|
+
}
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
package/dist/util/date.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fractional-second digits of a timestamp column uql declares when its field states no precision. It
|
|
3
|
+
* matches the milliseconds of a JS `Date` on every engine, so a value the database writes reads back exactly.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DATE_PRECISION = 3;
|
|
1
6
|
/**
|
|
2
7
|
* `YYYY-MM-DD HH:mm:ss.SSS` in UTC, then `zone`: how a date is written, whichever machine writes it. Not
|
|
3
8
|
* `toISOString` as it is, whose `T` and `Z` MySQL rejects outright ("Invalid default value").
|
package/dist/util/date.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fractional-second digits of a timestamp column uql declares when its field states no precision. It
|
|
3
|
+
* matches the milliseconds of a JS `Date` on every engine, so a value the database writes reads back exactly.
|
|
4
|
+
*/
|
|
5
|
+
export const DATE_PRECISION = 3;
|
|
1
6
|
/**
|
|
2
7
|
* `YYYY-MM-DD HH:mm:ss.SSS` in UTC, then `zone`: how a date is written, whichever machine writes it. Not
|
|
3
8
|
* `toISOString` as it is, whose `T` and `Z` MySQL rejects outright ("Invalid default value").
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IndexType } from '../schema/types.js';
|
|
2
|
-
import { type AggregateCall, type CascadeType, type EntityData, type
|
|
2
|
+
import { type AggregateCall, type CascadeType, type EntityData, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type FieldUpdateOp, type JsonUpdateOp, type OnFieldCallback, type QueryAggMap, type QueryExclude, type QueryGroupMap, type QueryOptions, QueryRaw, type QuerySearch, type QuerySelect, type QuerySelectValue, type QuerySortDirection, type QuerySizeComparisonOps, type QuerySortMap, type QueryTextSearchOptions, type QueryVectorQuery, type QueryVectorSearch, type QueryWhere, type RelationKey, type UpdatePayload, type VectorDistance } from '../type/index.js';
|
|
3
3
|
export type CallbackKey = keyof Pick<FieldOptions, 'onInsert' | 'onUpdate'>;
|
|
4
4
|
/** The keys of `payload` a write persists as columns. */
|
|
5
5
|
export declare function filterFieldKeys<E>(meta: EntityMeta<E>, payload: EntityData<E> | UpdatePayload<E>, callbackKey: CallbackKey): FieldKey<E>[];
|
|
@@ -41,20 +41,6 @@ export declare function isCascadable(action: CascadeType, configuration?: boolea
|
|
|
41
41
|
* neither clause on a write at all.
|
|
42
42
|
*/
|
|
43
43
|
export declare function isPagedQuery<E>(q: QuerySearch<E>): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Each of `keys` switched on, as a `$select` or conflict paths name them. This and the `where*` builders
|
|
46
|
-
* below hold the casts a statement built in generic code needs: a key read at run time is no key of
|
|
47
|
-
* these maps to the compiler, whose values it works out per entity.
|
|
48
|
-
*/
|
|
49
|
-
export declare function keySet<E>(keys: readonly FieldKey<E>[]): QueryConflictPaths<E>;
|
|
50
|
-
/** `where`, or no `$where`, with `key` held to `value` as well: spread, so the two `AND`. */
|
|
51
|
-
export declare function whereWith<E>(key: FieldKey<E>, value: unknown, where?: QueryWhere<E>): QueryWhere<E>;
|
|
52
|
-
/** The `$where` holding each of `keys` to what `valueOf` reads for it. */
|
|
53
|
-
export declare function whereEach<E>(keys: readonly FieldKey<E>[], valueOf: (key: FieldKey<E>) => unknown): QueryWhere<E>;
|
|
54
|
-
/** The `$where` any one of `clauses` satisfies. */
|
|
55
|
-
export declare function whereAnyOf<E>(clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
56
|
-
/** `q` selecting nothing but the id: what a write hands its backend's own read builder to settle the rows it will name. */
|
|
57
|
-
export declare function idOnlyQuery<E>(meta: EntityMeta<E>, q: QuerySearch<E>): Query<E>;
|
|
58
44
|
/** Whether `select` is the list form `raw()` fills, narrowing both ways, which `Array.isArray` does not for a `readonly` array. */
|
|
59
45
|
export declare function isSelectList<E>(select: QuerySelectValue<E> | undefined): select is readonly QueryRaw[];
|
|
60
46
|
export declare function normalizeScalarFieldSelection<E>(meta: EntityMeta<E>, select?: QuerySelect<E>, exclude?: QueryExclude<E>): FieldKey<E>[];
|
|
@@ -97,16 +83,6 @@ export declare function isFieldUpdateOp(value: unknown): value is FieldUpdateOp;
|
|
|
97
83
|
* reading one: their order would change the result, and an untyped payload is how both arrive.
|
|
98
84
|
*/
|
|
99
85
|
export declare function fieldUpdateOf(key: string, value: FieldUpdateOp): [keyof FieldUpdateOp, number | bigint];
|
|
100
|
-
/**
|
|
101
|
-
* The `$where` naming rows by key: a bare value names the one key column (refused on a composite), a
|
|
102
|
-
* composite's key map is a `$where` already, and a list is an `IN` of bare values or an OR of maps.
|
|
103
|
-
*/
|
|
104
|
-
export declare function whereIds<E>(meta: EntityMeta<E>, ids: EntityId<E> | EntityId<E>[]): QueryWhere<E>;
|
|
105
|
-
/**
|
|
106
|
-
* Refuses a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of
|
|
107
|
-
* them, and a scalar read as a map has no keys: the statement would address every row.
|
|
108
|
-
*/
|
|
109
|
-
export declare function assertWhere<E>(meta: EntityMeta<E>, where: unknown): void;
|
|
110
86
|
/** Returns a `QueryOptions.filters` value with the built-in soft-delete filter disabled (used by hard delete). */
|
|
111
87
|
export declare function withoutSoftDeleteFilter(filters: QueryOptions['filters']): QueryOptions['filters'];
|
|
112
88
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getContext } from '../context/context.js';
|
|
2
|
-
import { soleIdOf } from '../entity/metadata/definition.js';
|
|
3
2
|
import { QueryRaw, resolveAggregateOp, SOFT_DELETE_FILTER, } from '../type/index.js';
|
|
4
3
|
import { DEFAULT_VECTOR_DISTANCE, VECTOR_INDEX_TYPES } from '../type/vector.js';
|
|
5
4
|
import { defaultReadKeys, fieldKeys, isDatabaseWritten } from './field.util.js';
|
|
6
|
-
import { entityName, getKeys, hasKeys, isOperatorObject,
|
|
5
|
+
import { entityName, getKeys, hasKeys, isOperatorObject, isRecord, someKey } from './object.util.js';
|
|
6
|
+
import { whereAnd } from './query.util.js';
|
|
7
7
|
import { UqlSecurityError, UqlUsageError } from './uqlError.js';
|
|
8
8
|
/** The keys of `payload` a write persists as columns. */
|
|
9
9
|
export function filterFieldKeys(meta, payload, callbackKey) {
|
|
@@ -114,30 +114,6 @@ export function isCascadable(action, configuration) {
|
|
|
114
114
|
export function isPagedQuery(q) {
|
|
115
115
|
return q.$sort !== undefined || q.$limit !== undefined || q.$skip !== undefined;
|
|
116
116
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Each of `keys` switched on, as a `$select` or conflict paths name them. This and the `where*` builders
|
|
119
|
-
* below hold the casts a statement built in generic code needs: a key read at run time is no key of
|
|
120
|
-
* these maps to the compiler, whose values it works out per entity.
|
|
121
|
-
*/
|
|
122
|
-
export function keySet(keys) {
|
|
123
|
-
return Object.fromEntries(keys.map((key) => [key, true]));
|
|
124
|
-
}
|
|
125
|
-
/** `where`, or no `$where`, with `key` held to `value` as well: spread, so the two `AND`. */
|
|
126
|
-
export function whereWith(key, value, where) {
|
|
127
|
-
return { ...where, [key]: value };
|
|
128
|
-
}
|
|
129
|
-
/** The `$where` holding each of `keys` to what `valueOf` reads for it. */
|
|
130
|
-
export function whereEach(keys, valueOf) {
|
|
131
|
-
return Object.fromEntries(keys.map((key) => [key, valueOf(key)]));
|
|
132
|
-
}
|
|
133
|
-
/** The `$where` any one of `clauses` satisfies. */
|
|
134
|
-
export function whereAnyOf(clauses) {
|
|
135
|
-
return { $or: clauses };
|
|
136
|
-
}
|
|
137
|
-
/** `q` selecting nothing but the id: what a write hands its backend's own read builder to settle the rows it will name. */
|
|
138
|
-
export function idOnlyQuery(meta, q) {
|
|
139
|
-
return { ...q, $select: keySet(meta.ids) };
|
|
140
|
-
}
|
|
141
117
|
/** Whether `select` is the list form `raw()` fills, narrowing both ways, which `Array.isArray` does not for a `readonly` array. */
|
|
142
118
|
export function isSelectList(select) {
|
|
143
119
|
return Array.isArray(select);
|
|
@@ -270,25 +246,6 @@ export function fieldUpdateOf(key, value) {
|
|
|
270
246
|
}
|
|
271
247
|
return value.$inc === undefined ? ['$mul', value.$mul] : ['$inc', value.$inc];
|
|
272
248
|
}
|
|
273
|
-
/**
|
|
274
|
-
* The `$where` naming rows by key: a bare value names the one key column (refused on a composite), a
|
|
275
|
-
* composite's key map is a `$where` already, and a list is an `IN` of bare values or an OR of maps.
|
|
276
|
-
*/
|
|
277
|
-
export function whereIds(meta, ids) {
|
|
278
|
-
if (Array.isArray(ids) ? ids.every(isScalarId) : isScalarId(ids)) {
|
|
279
|
-
return whereWith(soleIdOf(meta, 'addressing by a bare id value'), ids);
|
|
280
|
-
}
|
|
281
|
-
return (Array.isArray(ids) ? { $or: ids } : ids);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Refuses a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of
|
|
285
|
-
* them, and a scalar read as a map has no keys: the statement would address every row.
|
|
286
|
-
*/
|
|
287
|
-
export function assertWhere(meta, where) {
|
|
288
|
-
if (!isWhereMap(where)) {
|
|
289
|
-
throw new UqlUsageError(`$where on '${entityName(meta)}' must be a map of conditions, such as { id: 1 }`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
249
|
/** Returns a `QueryOptions.filters` value with the built-in soft-delete filter disabled (used by hard delete). */
|
|
293
250
|
export function withoutSoftDeleteFilter(filters) {
|
|
294
251
|
return filters === false ? false : { ...filters, [SOFT_DELETE_FILTER]: false };
|
|
@@ -314,12 +271,9 @@ export function applyFilters(meta, whereMap, opts) {
|
|
|
314
271
|
}
|
|
315
272
|
}
|
|
316
273
|
}
|
|
274
|
+
const merged = result;
|
|
317
275
|
const security = securityConditions(meta).map(([, condition]) => condition);
|
|
318
|
-
|
|
319
|
-
const existing = result['$and'];
|
|
320
|
-
result['$and'] = existing ? [...existing, ...security] : security;
|
|
321
|
-
}
|
|
322
|
-
return result;
|
|
276
|
+
return security.length ? whereAnd(merged, security) : merged;
|
|
323
277
|
}
|
|
324
278
|
/**
|
|
325
279
|
* Each `security` filter's condition, by name, resolved against the ambient context. One resolving to
|
|
@@ -39,6 +39,15 @@ export declare function isSoleIdField<E>(meta: EntityMeta<E>, field: FieldOption
|
|
|
39
39
|
* states its width. The one answer the create statement and the diff both read.
|
|
40
40
|
*/
|
|
41
41
|
export declare function isAutoIncrement(field: FieldOptions, isPrimaryKey: boolean): boolean;
|
|
42
|
+
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
43
|
+
export declare function fieldFamily(field: FieldOptions): ColumnFamily | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the column is NOT NULL: the field declares `nullable: false` or is a key. A key counts whatever its
|
|
46
|
+
* property says: `id?: number` is optional because the database assigns it, not because it can be null.
|
|
47
|
+
*/
|
|
48
|
+
export declare function declaresNotNull(field: FieldOptions): boolean;
|
|
49
|
+
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
|
50
|
+
export declare function isFieldKey<E>(meta: EntityMeta<E>, key: string): key is FieldKey<E>;
|
|
42
51
|
/** The fields `meta` declares whose options `pick` accepts, in declaration order, each as the entity's own key. */
|
|
43
52
|
export declare function fieldKeys<E>(meta: EntityMeta<E>, pick: (field: FieldMeta) => unknown): FieldKey<E>[];
|
|
44
53
|
/**
|
package/dist/util/field.util.js
CHANGED
|
@@ -83,6 +83,21 @@ export function isAutoIncrement(field, isPrimaryKey) {
|
|
|
83
83
|
return field.autoIncrement;
|
|
84
84
|
return isPrimaryKey && columnFamily(field.type) === 'numeric' && !field.onInsert && !field.references;
|
|
85
85
|
}
|
|
86
|
+
/** The column family of a field, from its `columnType` if set, else from its `type`. */
|
|
87
|
+
export function fieldFamily(field) {
|
|
88
|
+
return columnFamily(field.columnType ?? field.type);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether the column is NOT NULL: the field declares `nullable: false` or is a key. A key counts whatever its
|
|
92
|
+
* property says: `id?: number` is optional because the database assigns it, not because it can be null.
|
|
93
|
+
*/
|
|
94
|
+
export function declaresNotNull(field) {
|
|
95
|
+
return field.isId === true || field.nullable === false;
|
|
96
|
+
}
|
|
97
|
+
/** Whether `key` is a field of `meta`, as opposed to a relation, a JSON path or an unknown key. */
|
|
98
|
+
export function isFieldKey(meta, key) {
|
|
99
|
+
return meta.fields[key] !== undefined;
|
|
100
|
+
}
|
|
86
101
|
/** The fields `meta` declares whose options `pick` accepts, in declaration order, each as the entity's own key. */
|
|
87
102
|
export function fieldKeys(meta, pick) {
|
|
88
103
|
const fields = meta.fields;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryRaw } from '../type/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { fieldFamily, isInlinedExpression } from './field.util.js';
|
|
3
3
|
import { getKeys } from './object.util.js';
|
|
4
4
|
import { constantSql } from './raw.js';
|
|
5
5
|
/**
|
|
@@ -112,7 +112,7 @@ export function fieldOptionConflict(opts) {
|
|
|
112
112
|
if (opts.columnType instanceof QueryRaw && constantSql(opts.columnType) === undefined) {
|
|
113
113
|
return "cannot use 'columnType': a `raw` one names a constant type, so it can bind no value and read no column";
|
|
114
114
|
}
|
|
115
|
-
const family =
|
|
115
|
+
const family = fieldFamily(opts);
|
|
116
116
|
// Walked in table order, not in the order the field happened to be written, so a field with two
|
|
117
117
|
// conflicts always reports the same one. An option no rule knows is a typo, which `@Field`'s own check
|
|
118
118
|
// reports where it can still be spelled right.
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './dialect.util.js';
|
|
2
|
+
export * from './query.util.js';
|
|
2
3
|
export * from './field.util.js';
|
|
3
4
|
export * from './fieldOption.util.js';
|
|
4
5
|
export * from './filters.util.js';
|
|
@@ -7,7 +8,7 @@ export * from './ddlExpression.util.js';
|
|
|
7
8
|
export * from './logger.js';
|
|
8
9
|
export * from './object.util.js';
|
|
9
10
|
export * from './raw.js';
|
|
10
|
-
export { deleteFrom, insertInto, updateTable } from './triggerWrite.js';
|
|
11
|
+
export { deleteFrom, insertInto, refuse, updateTable, upsertInto } from './triggerWrite.js';
|
|
11
12
|
export * from './rowKey.util.js';
|
|
12
13
|
export * from './relationQuery.util.js';
|
|
13
14
|
export * from './sql.util.js';
|
package/dist/util/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './dialect.util.js';
|
|
2
|
+
export * from './query.util.js';
|
|
2
3
|
export * from './field.util.js';
|
|
3
4
|
export * from './fieldOption.util.js';
|
|
4
5
|
export * from './filters.util.js';
|
|
@@ -7,7 +8,7 @@ export * from './ddlExpression.util.js';
|
|
|
7
8
|
export * from './logger.js';
|
|
8
9
|
export * from './object.util.js';
|
|
9
10
|
export * from './raw.js';
|
|
10
|
-
export { deleteFrom, insertInto, updateTable } from './triggerWrite.js';
|
|
11
|
+
export { deleteFrom, insertInto, refuse, updateTable, upsertInto } from './triggerWrite.js';
|
|
11
12
|
export * from './rowKey.util.js';
|
|
12
13
|
export * from './relationQuery.util.js';
|
|
13
14
|
export * from './sql.util.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { EntityMeta } from '../type/index.js';
|
|
2
|
-
export declare function throwPendingTransaction(): never;
|
|
3
|
-
export declare function throwNoPendingTransaction(): never;
|
|
4
2
|
export declare function clone<T>(value: T): T;
|
|
5
3
|
/** Whether `obj` has at least one enumerable key. Narrows away `undefined`/`null` for callers. */
|
|
6
4
|
export declare function hasKeys<T>(obj: T): obj is NonNullable<T>;
|
package/dist/util/object.util.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { UqlUsageError } from './uqlError.js';
|
|
2
|
-
export function throwPendingTransaction() {
|
|
3
|
-
throw new UqlUsageError('pending transaction');
|
|
4
|
-
}
|
|
5
|
-
export function throwNoPendingTransaction() {
|
|
6
|
-
throw new UqlUsageError('not a pending transaction');
|
|
7
|
-
}
|
|
8
1
|
export function clone(value) {
|
|
9
2
|
if (typeof value !== 'object' || value === null) {
|
|
10
3
|
return value;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { EntityId, EntityMeta, FieldKey, Query, QueryConflictPaths, QuerySearch, QuerySortDirection, QuerySortMap, QueryWhere, QueryWhereArray } from '../type/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maps each of `keys` to `true`, the shape of a `$select` or conflict paths. This and the builders below hold
|
|
4
|
+
* the casts generic code needs to build a statement: the compiler types these maps per entity, so it does not
|
|
5
|
+
* accept a key read at run time as one of their keys.
|
|
6
|
+
*/
|
|
7
|
+
export declare function keySet<E>(keys: readonly FieldKey<E>[]): QueryConflictPaths<E>;
|
|
8
|
+
/** `where` (or an empty `$where`) with `key` also set to `value`. Keys in one map combine with `AND`. */
|
|
9
|
+
export declare function whereWith<E>(key: FieldKey<E>, value: unknown, where?: QueryWhere<E>): QueryWhere<E>;
|
|
10
|
+
export declare function whereEach<E>(keys: readonly FieldKey<E>[], valueOf: (key: FieldKey<E>) => unknown): QueryWhere<E>;
|
|
11
|
+
export declare function whereAnyOf<E>(clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
12
|
+
/** A `$sort` from `[key, direction]` pairs, sorting by the keys in the order given. */
|
|
13
|
+
export declare function sortOf<E>(entries: readonly (readonly [FieldKey<E>, QuerySortDirection])[]): QuerySortMap<E>;
|
|
14
|
+
/**
|
|
15
|
+
* Appends `clauses` to the `$and` of `where`. Merging them into its keys instead could lose one to a key of
|
|
16
|
+
* the same name, such as a second `$or`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function whereAnd<E>(where: QueryWhere<E> | undefined, clauses: QueryWhereArray<E>): QueryWhere<E>;
|
|
19
|
+
/** `q` selecting only the id. A write passes it to its backend's read builder to find the rows it will act on. */
|
|
20
|
+
export declare function idOnlyQuery<E>(meta: EntityMeta<E>, q: QuerySearch<E>): Query<E>;
|
|
21
|
+
/**
|
|
22
|
+
* A `$where` selecting rows by key. A bare value matches the single key column (refused on a composite key),
|
|
23
|
+
* a composite key's map is already a `$where`, and a list becomes an `IN` of bare values or an `$or` of maps.
|
|
24
|
+
*/
|
|
25
|
+
export declare function whereIds<E>(meta: EntityMeta<E>, ids: EntityId<E> | EntityId<E>[]): QueryWhere<E>;
|
|
26
|
+
/**
|
|
27
|
+
* Throws on a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of ids,
|
|
28
|
+
* and a scalar read as a map has no keys, so the statement would match every row.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertWhere<E>(meta: EntityMeta<E>, where: unknown): void;
|
|
31
|
+
/** A parsed `$sort` direction: whether it is descending, and where it puts nulls if it says. */
|
|
32
|
+
export type SortDirection = {
|
|
33
|
+
readonly desc: boolean;
|
|
34
|
+
readonly nulls?: 'first' | 'last';
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Parses a `$sort` direction. Every backend and the page cursor share this one parser, so a sort order and
|
|
38
|
+
* the cursor condition that pages through it cannot disagree.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseSortDirection(value: unknown): SortDirection;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { soleIdOf } from '../entity/metadata/definition.js';
|
|
2
|
+
import { entityName, isScalarId, isWhereMap } from './object.util.js';
|
|
3
|
+
import { UqlUsageError } from './uqlError.js';
|
|
4
|
+
/**
|
|
5
|
+
* Maps each of `keys` to `true`, the shape of a `$select` or conflict paths. This and the builders below hold
|
|
6
|
+
* the casts generic code needs to build a statement: the compiler types these maps per entity, so it does not
|
|
7
|
+
* accept a key read at run time as one of their keys.
|
|
8
|
+
*/
|
|
9
|
+
export function keySet(keys) {
|
|
10
|
+
return Object.fromEntries(keys.map((key) => [key, true]));
|
|
11
|
+
}
|
|
12
|
+
/** `where` (or an empty `$where`) with `key` also set to `value`. Keys in one map combine with `AND`. */
|
|
13
|
+
export function whereWith(key, value, where) {
|
|
14
|
+
return { ...where, [key]: value };
|
|
15
|
+
}
|
|
16
|
+
export function whereEach(keys, valueOf) {
|
|
17
|
+
return Object.fromEntries(keys.map((key) => [key, valueOf(key)]));
|
|
18
|
+
}
|
|
19
|
+
export function whereAnyOf(clauses) {
|
|
20
|
+
return { $or: clauses };
|
|
21
|
+
}
|
|
22
|
+
/** A `$sort` from `[key, direction]` pairs, sorting by the keys in the order given. */
|
|
23
|
+
export function sortOf(entries) {
|
|
24
|
+
return Object.fromEntries(entries);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Appends `clauses` to the `$and` of `where`. Merging them into its keys instead could lose one to a key of
|
|
28
|
+
* the same name, such as a second `$or`.
|
|
29
|
+
*/
|
|
30
|
+
export function whereAnd(where, clauses) {
|
|
31
|
+
return { ...where, $and: [...(where?.$and ?? []), ...clauses] };
|
|
32
|
+
}
|
|
33
|
+
/** `q` selecting only the id. A write passes it to its backend's read builder to find the rows it will act on. */
|
|
34
|
+
export function idOnlyQuery(meta, q) {
|
|
35
|
+
return { ...q, $select: keySet(meta.ids) };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A `$where` selecting rows by key. A bare value matches the single key column (refused on a composite key),
|
|
39
|
+
* a composite key's map is already a `$where`, and a list becomes an `IN` of bare values or an `$or` of maps.
|
|
40
|
+
*/
|
|
41
|
+
export function whereIds(meta, ids) {
|
|
42
|
+
if (Array.isArray(ids) ? ids.every(isScalarId) : isScalarId(ids)) {
|
|
43
|
+
return whereWith(soleIdOf(meta, 'addressing by a bare id value'), ids);
|
|
44
|
+
}
|
|
45
|
+
return (Array.isArray(ids) ? { $or: ids } : ids);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Throws on a `$where` that is not a map. Untyped JS and parsed JSON can still pass an id or a list of ids,
|
|
49
|
+
* and a scalar read as a map has no keys, so the statement would match every row.
|
|
50
|
+
*/
|
|
51
|
+
export function assertWhere(meta, where) {
|
|
52
|
+
if (!isWhereMap(where)) {
|
|
53
|
+
throw new UqlUsageError(`$where on '${entityName(meta)}' must be a map of conditions, such as { id: 1 }`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const SORT_DIRECTIONS = new Map([
|
|
57
|
+
[1, { desc: false }],
|
|
58
|
+
['asc', { desc: false }],
|
|
59
|
+
[-1, { desc: true }],
|
|
60
|
+
['desc', { desc: true }],
|
|
61
|
+
['ascNullsFirst', { desc: false, nulls: 'first' }],
|
|
62
|
+
['ascNullsLast', { desc: false, nulls: 'last' }],
|
|
63
|
+
['descNullsFirst', { desc: true, nulls: 'first' }],
|
|
64
|
+
['descNullsLast', { desc: true, nulls: 'last' }],
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Parses a `$sort` direction. Every backend and the page cursor share this one parser, so a sort order and
|
|
68
|
+
* the cursor condition that pages through it cannot disagree.
|
|
69
|
+
*/
|
|
70
|
+
export function parseSortDirection(value) {
|
|
71
|
+
const direction = SORT_DIRECTIONS.get(value);
|
|
72
|
+
if (!direction) {
|
|
73
|
+
throw new UqlUsageError(`unknown sort direction: ${String(value)}`);
|
|
74
|
+
}
|
|
75
|
+
return direction;
|
|
76
|
+
}
|
package/dist/util/raw.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EntitySql, type EntityWhere, type EntityWhereMeta, QueryRaw, type QueryRawFn, type ComputedRefs, type RefMap, type TriggerRowName, type Type } from '../type/index.js';
|
|
1
|
+
import { type EntitySql, type EntityWhere, type EntityWhereMeta, QueryRaw, type QueryRawFn, type ComputedRefs, type RefMap, type SqlValueName, type TriggerRowName, type Type } from '../type/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Raw SQL, where an interpolated value binds, a `refs` field renders its column, and a `raw` renders
|
|
4
4
|
* in place: `raw`GREATEST(0, ${user.credits} - ${amount})``. A callback writes whatever it writes, so
|
|
@@ -11,6 +11,21 @@ export declare function raw(value: QueryRawFn): QueryRaw;
|
|
|
11
11
|
* nowhere to bind a value; `undefined` where it interpolates and so needs one.
|
|
12
12
|
*/
|
|
13
13
|
export declare function constantSql(value: QueryRaw): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The database's clock in UTC to the millisecond, the form uql reads a timestamp back in exactly. Use it for
|
|
16
|
+
* a `defaultValue`, a stamp, an `onUpdate` or a `$where`, in entities and migrations alike.
|
|
17
|
+
*/
|
|
18
|
+
export declare const currentTimestamp: QueryRaw;
|
|
19
|
+
/** Today on the database's clock; on SQLite, the text a bound `Date` at midnight is. */
|
|
20
|
+
export declare const currentDate: QueryRaw;
|
|
21
|
+
/** The time of day on the database's clock. */
|
|
22
|
+
export declare const currentTime: QueryRaw;
|
|
23
|
+
/** A UUID the database generates: a version 4, or a version 1 on MySQL and MariaDB. SQLite has none. */
|
|
24
|
+
export declare const uuid: QueryRaw;
|
|
25
|
+
/** A time-ordered version 7 UUID, which indexes better as a key. Postgres 18+ and MariaDB 11.7+ only. */
|
|
26
|
+
export declare const uuidv7: QueryRaw;
|
|
27
|
+
/** Each value above by its name, the name a migration or `generate:from-db` writes it under. */
|
|
28
|
+
export declare const SQL_VALUES: Readonly<Record<SqlValueName, QueryRaw>>;
|
|
14
29
|
/**
|
|
15
30
|
* The fields of `entity` as {@link ColumnRef}s, each rendering inside `raw` as its column: named the way
|
|
16
31
|
* the dialect names it, so the naming strategy and `@Field({ name })` apply, and qualified by the alias
|
package/dist/util/raw.js
CHANGED
|
@@ -30,6 +30,37 @@ export function raw(value, ...rest) {
|
|
|
30
30
|
export function constantSql(value) {
|
|
31
31
|
return value[RAW_TEXT];
|
|
32
32
|
}
|
|
33
|
+
/** A value the database computes, in each engine's SQL; one an engine has no function for throws. */
|
|
34
|
+
function sqlValue(name) {
|
|
35
|
+
return raw(({ dialect }) => {
|
|
36
|
+
const sql = dialect.sqlValues[name];
|
|
37
|
+
if (sql === undefined) {
|
|
38
|
+
throw new UqlUsageError(`${dialect.dialectName} has no ${name}; write it as raw SQL this engine accepts`);
|
|
39
|
+
}
|
|
40
|
+
return sql;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The database's clock in UTC to the millisecond, the form uql reads a timestamp back in exactly. Use it for
|
|
45
|
+
* a `defaultValue`, a stamp, an `onUpdate` or a `$where`, in entities and migrations alike.
|
|
46
|
+
*/
|
|
47
|
+
export const currentTimestamp = sqlValue('currentTimestamp');
|
|
48
|
+
/** Today on the database's clock; on SQLite, the text a bound `Date` at midnight is. */
|
|
49
|
+
export const currentDate = sqlValue('currentDate');
|
|
50
|
+
/** The time of day on the database's clock. */
|
|
51
|
+
export const currentTime = sqlValue('currentTime');
|
|
52
|
+
/** A UUID the database generates: a version 4, or a version 1 on MySQL and MariaDB. SQLite has none. */
|
|
53
|
+
export const uuid = sqlValue('uuid');
|
|
54
|
+
/** A time-ordered version 7 UUID, which indexes better as a key. Postgres 18+ and MariaDB 11.7+ only. */
|
|
55
|
+
export const uuidv7 = sqlValue('uuidv7');
|
|
56
|
+
/** Each value above by its name, the name a migration or `generate:from-db` writes it under. */
|
|
57
|
+
export const SQL_VALUES = {
|
|
58
|
+
currentTimestamp,
|
|
59
|
+
currentDate,
|
|
60
|
+
currentTime,
|
|
61
|
+
uuid,
|
|
62
|
+
uuidv7,
|
|
63
|
+
};
|
|
33
64
|
/**
|
|
34
65
|
* The fields of `entity` as {@link ColumnRef}s, each rendering inside `raw` as its column: named the way
|
|
35
66
|
* the dialect names it, so the naming strategy and `@Field({ name })` apply, and qualified by the alias
|