uql-orm 0.112.0 → 0.113.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/README.md +1 -1
- package/dist/browser/http/httpTransport.d.ts +29 -0
- package/dist/browser/http/httpTransport.js +59 -0
- package/dist/browser/http/index.d.ts +1 -2
- package/dist/browser/http/index.js +1 -2
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/querier/clientQuerier.d.ts +7 -0
- package/dist/browser/querier/clientQuerier.js +43 -0
- package/dist/browser/querier/index.d.ts +2 -1
- package/dist/browser/querier/index.js +2 -1
- package/dist/browser/querier/queryOptions.d.ts +23 -0
- package/dist/browser/querier/queryOptions.js +35 -0
- package/dist/browser/type/clientQuerier.d.ts +10 -11
- package/dist/browser/type/index.d.ts +1 -1
- package/dist/browser/type/index.js +1 -1
- package/dist/browser/type/transport.d.ts +13 -0
- package/dist/dialect/abstractDialect.d.ts +2 -2
- package/dist/dialect/abstractSqlDialect.js +3 -3
- package/dist/dialect/jsonSql.js +2 -3
- package/dist/dialect/operators.js +4 -5
- package/dist/express/index.d.ts +1 -1
- package/dist/express/index.js +1 -1
- package/dist/express/router.d.ts +8 -0
- package/dist/express/router.js +50 -0
- package/dist/http/api.d.ts +36 -0
- package/dist/http/api.js +136 -0
- package/dist/http/apiCall.d.ts +59 -0
- package/dist/http/apiCall.js +52 -0
- package/dist/http/errors.d.ts +20 -0
- package/dist/http/errors.js +27 -0
- package/dist/http/exposure.d.ts +54 -0
- package/dist/http/exposure.js +171 -0
- package/dist/http/handler.d.ts +23 -88
- package/dist/http/handler.js +42 -155
- package/dist/http/index.d.ts +8 -4
- package/dist/http/index.js +6 -3
- package/dist/http/route.d.ts +34 -0
- package/dist/http/route.js +82 -0
- package/dist/http/wireCall.d.ts +115 -0
- package/dist/http/wireCall.js +126 -0
- package/dist/http/wireQuery.d.ts +8 -0
- package/dist/http/wireQuery.js +51 -0
- package/dist/http/wireRow.d.ts +20 -0
- package/dist/http/wireRow.js +170 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -1
- package/dist/migrate/introspection/mysqlIntrospector.js +12 -2
- package/dist/mongodb/mongoDialect.d.ts +6 -6
- package/dist/mongodb/mongoDialect.js +6 -6
- package/dist/mongodb/mongodbQuerier.d.ts +8 -8
- package/dist/mssql/mssqlDialect.js +2 -2
- package/dist/nestjs/uqlContextInterceptor.d.ts +3 -3
- package/dist/nestjs/uqlContextInterceptor.js +7 -7
- package/dist/nestjs/uqlModule.d.ts +5 -11
- package/dist/nestjs/uqlModule.js +10 -15
- package/dist/querier/abstractQuerier.d.ts +8 -8
- package/dist/querier/abstractQuerier.js +15 -8
- package/dist/querier/abstractSqlQuerier.d.ts +8 -8
- package/dist/querier/keyset.d.ts +15 -0
- package/dist/querier/keyset.js +16 -11
- package/dist/sqlite/localSqliteQuerierPool.d.ts +1 -1
- package/dist/type/column.d.ts +4 -1
- package/dist/type/querier.d.ts +2 -2
- package/dist/type/query.d.ts +18 -4
- package/dist/type/universalQuerier.d.ts +16 -16
- package/dist/type/wire.d.ts +1 -31
- package/dist/util/dialect.util.d.ts +9 -16
- package/dist/util/dialect.util.js +20 -26
- package/dist/util/field.util.d.ts +4 -1
- package/dist/util/field.util.js +5 -2
- package/dist/util/object.util.d.ts +5 -2
- package/dist/util/object.util.js +12 -15
- package/dist/util/query.util.js +3 -10
- package/dist/util/uqlError.d.ts +27 -1
- package/dist/util/uqlError.js +43 -0
- package/package.json +5 -10
- package/skills/uql-orm/SKILL.md +4 -1
- package/dist/browser/http/bus.d.ts +0 -3
- package/dist/browser/http/bus.js +0 -12
- package/dist/browser/http/http.d.ts +0 -20
- package/dist/browser/http/http.js +0 -67
- package/dist/browser/querier/httpQuerier.d.ts +0 -46
- package/dist/browser/querier/httpQuerier.js +0 -64
- package/dist/browser/type/request.d.ts +0 -27
- package/dist/browser/uql-browser.min.js +0 -4
- package/dist/browser/uql-browser.min.js.map +0 -19
- package/dist/express/querierMiddleware.d.ts +0 -11
- package/dist/express/querierMiddleware.js +0 -39
- package/dist/http/contract.d.ts +0 -98
- package/dist/http/contract.js +0 -83
- package/dist/http/fetchHandler.d.ts +0 -13
- package/dist/http/fetchHandler.js +0 -63
- package/dist/http/query.d.ts +0 -28
- package/dist/http/query.js +0 -119
- /package/dist/browser/type/{request.js → transport.js} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
2
|
-
import type { BooleanLike, CursorPage, Captured, EntityData, EntityId, EntityWrite, EntityMeta, ExtraOptions, FieldKey, Querier, Query, QueryAggregate, QueryAggregateResult, QueryConflictKeys, QueryUpsert, QueryFilter, QueryFindResult, QueryKeyset, QueryOne, QueryOptions, QueryPage, QuerySearch, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, WriteResults, WriteOptions, PrimaryKey, WrittenId, RawRow, ReportedWrite } from '../type/index.js';
|
|
2
|
+
import type { BooleanLike, CursorPage, Captured, EntityData, EntityId, EntityWrite, EntityMeta, ExtraOptions, FieldKey, Querier, Query, QueryAggregate, QueryAggregateResult, QueryConflictKeys, QueryUpsert, QueryFilter, QueryFindResult, QueryKeyset, QueryOne, QueryOptions, StatementOptions, QueryPage, QuerySearch, SavepointCommand, TransactionOptions, Type, UpdatePayload, UpdateWrite, WriteResults, WriteOptions, PrimaryKey, WrittenId, RawRow, ReportedWrite } from '../type/index.js';
|
|
3
3
|
import { LoggerWrapper } from '../util/index.js';
|
|
4
4
|
import { type TransactionScope } from './transaction.js';
|
|
5
5
|
/** What an upsert reports of a row: the value a driver answers for a lone key, or the key the read back names. */
|
|
6
6
|
export type UpsertedId<E> = PrimaryKey | WrittenId<E>;
|
|
7
7
|
/** Each write as one statement reporting the rows it wrote with the fields `keys` names. */
|
|
8
8
|
export type ReportingWrites = {
|
|
9
|
-
update<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts:
|
|
10
|
-
delete<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts:
|
|
9
|
+
update<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts: StatementOptions, keys: readonly FieldKey<E>[]): Promise<E[]>;
|
|
10
|
+
delete<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts: StatementOptions, keys: readonly FieldKey<E>[]): Promise<E[]>;
|
|
11
11
|
/** Inserts `rows`, reporting each in their order and placing its key on it, as `internalInsertMany` does. */
|
|
12
12
|
insert<E extends object>(entity: Type<E>, rows: EntityData<E>[], keys: readonly FieldKey<E>[]): Promise<E[]>;
|
|
13
13
|
/** The rows of `payload` the upsert writes, in its order, `undefined` for one it kept. */
|
|
@@ -56,7 +56,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
56
56
|
* The rows matching `q`, each populated relation and `$count` read with them in the same statement
|
|
57
57
|
* or pipeline. [The design](../../../../architecture/relations-in-one-statement.md).
|
|
58
58
|
*/
|
|
59
|
-
protected abstract internalFindMany<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
59
|
+
protected abstract internalFindMany<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): Promise<E[]>;
|
|
60
60
|
/**
|
|
61
61
|
* Stream records with the relations and counts `findMany` reads, the entity passed first or as `$entity`.
|
|
62
62
|
* `afterLoad` runs on each row as it arrives, and the querier runs nothing else until the loop ends.
|
|
@@ -73,7 +73,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
73
73
|
* which a loop awaiting it never finishes, so `serialize` refuses one meanwhile, and `release` closes the stream.
|
|
74
74
|
*/
|
|
75
75
|
private holdWhileReading;
|
|
76
|
-
protected abstract internalFindManyStream<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
76
|
+
protected abstract internalFindManyStream<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): AsyncIterable<E>;
|
|
77
77
|
/** Find many records and count every match, the entity passed first or as the query's `$entity`. */
|
|
78
78
|
findManyAndCount<E extends object, const Q extends Query<E> & {
|
|
79
79
|
$entity: Type<E>;
|
|
@@ -85,7 +85,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
85
85
|
* The page and how many rows the filter matched beyond it. Two statements here, which is what a
|
|
86
86
|
* backend with no way to answer both at once is left with; SQL overrides it to answer from one.
|
|
87
87
|
*/
|
|
88
|
-
protected internalFindManyAndCount<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
88
|
+
protected internalFindManyAndCount<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): Promise<[E[], number]>;
|
|
89
89
|
/** Read a page of records from a cursor, the entity passed first or as the query's `$entity`. */
|
|
90
90
|
findManyPage<E extends object, const Q extends QueryKeyset<E> & {
|
|
91
91
|
$entity: Type<E>;
|
|
@@ -213,7 +213,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
213
213
|
/** How the engine writes rows of `meta` and reports them in one statement, or `undefined` where `write` reads them. */
|
|
214
214
|
protected reportingWrites<E>(_meta: EntityMeta<E>, _write: ReportedWrite): ReportingWrites | undefined;
|
|
215
215
|
/** Runs one UPDATE over `q`, which names its rows by id wherever {@link updateMany} settled them. */
|
|
216
|
-
protected abstract internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?:
|
|
216
|
+
protected abstract internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?: StatementOptions): Promise<number>;
|
|
217
217
|
restoreOneById<E extends object>(entity: Type<E>, id: EntityId<E>): Promise<number>;
|
|
218
218
|
restoreMany<E extends object>(q: QuerySearch<E> & {
|
|
219
219
|
$entity: Type<E>;
|
|
@@ -268,7 +268,7 @@ export declare abstract class AbstractQuerier implements Querier {
|
|
|
268
268
|
/** Deletes the rows `q` matches, or the ones `read` holds, reading them first where a hook, cascade or page needs them. */
|
|
269
269
|
private deleteRows;
|
|
270
270
|
/** Runs one DELETE (or soft-delete stamp) over `q`, which names its rows by id wherever {@link deleteMany} settled them. */
|
|
271
|
-
protected abstract internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?:
|
|
271
|
+
protected abstract internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: StatementOptions): Promise<number>;
|
|
272
272
|
saveOne<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, payload: EntityWrite<E>, opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['inserted']>;
|
|
273
273
|
saveMany<E extends object, const S extends FieldKey<E> = never, const V extends BooleanLike = true, const W extends boolean = false>(entity: Type<E>, payload: readonly EntityWrite<E>[], opts?: WriteOptions<E, S, V, W>): Promise<WriteResults<E, S, V, W>['inserted'][]>;
|
|
274
274
|
/**
|
|
@@ -81,7 +81,7 @@ function writtenIds(meta, rows) {
|
|
|
81
81
|
*/
|
|
82
82
|
function upsertsByReading(meta, q, rows) {
|
|
83
83
|
return (meta.version !== undefined ||
|
|
84
|
-
securityConditions(meta).length > 0 ||
|
|
84
|
+
securityConditions(meta, ['read', 'insert', 'update']).length > 0 ||
|
|
85
85
|
writesRelations(meta, q.$update ? [...rows, q.$update] : rows));
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
@@ -171,6 +171,11 @@ async function runCallbacks(callbacks) {
|
|
|
171
171
|
await callback();
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* What an upsert or a restore reads and updates rows with: soft-deleted ones too, since a key holds across both, held
|
|
176
|
+
* to the `security` filters an update is.
|
|
177
|
+
*/
|
|
178
|
+
const UPDATING_DELETED = { ...withDeleted(), access: 'update' };
|
|
174
179
|
const STREAM_HOLDS_QUERIER = 'a stream is reading on this querier: run the statement after its loop, or on another querier';
|
|
175
180
|
/** Base class for all database queriers. */
|
|
176
181
|
export class AbstractQuerier {
|
|
@@ -439,10 +444,11 @@ export class AbstractQuerier {
|
|
|
439
444
|
async updateWhere(entity, q, payload, opts) {
|
|
440
445
|
assertNamesRows(entity, 'updateMany', q, opts);
|
|
441
446
|
const meta = getMeta(entity);
|
|
442
|
-
const { returning, ...
|
|
447
|
+
const { returning, ...given } = opts ?? {};
|
|
448
|
+
const rest = { ...given, access: 'update' };
|
|
443
449
|
const keys = returnedKeys(meta, returning);
|
|
444
450
|
if (!keys) {
|
|
445
|
-
return this.updateMatching(entity, q, payload,
|
|
451
|
+
return this.updateMatching(entity, q, payload, rest);
|
|
446
452
|
}
|
|
447
453
|
const reportingWrites = this.reportingWrites(meta, 'update');
|
|
448
454
|
const reporting = (row) => reportingWrites && this.updatesByFilter(entity, q, row) ? reportingWrites : undefined;
|
|
@@ -600,7 +606,7 @@ export class AbstractQuerier {
|
|
|
600
606
|
const $where = whereWith(meta.softDelete, { $ne: null }, q.$where);
|
|
601
607
|
// No version: a restore only undoes the stamp a delete left, which takes none either, and two of
|
|
602
608
|
// them racing agree on the result anyway. A lock is for content, and a restore writes none.
|
|
603
|
-
return this.hooked(entity, 'Update', [{ [meta.softDelete]: null }], ([row]) => this.updateRows(entity, { ...q, $where }, row,
|
|
609
|
+
return this.hooked(entity, 'Update', [{ [meta.softDelete]: null }], ([row]) => this.updateRows(entity, { ...q, $where }, row, UPDATING_DELETED, undefined));
|
|
604
610
|
}
|
|
605
611
|
async upsertOne(...args) {
|
|
606
612
|
const [entity, q, payload, opts] = payloadArgs(args);
|
|
@@ -677,7 +683,7 @@ export class AbstractQuerier {
|
|
|
677
683
|
const assigned = foundRowAssigned(meta, q, row);
|
|
678
684
|
if (assigned) {
|
|
679
685
|
const $where = q.$where ? whereAnd(whereIds(meta, id), [q.$where]) : whereIds(meta, id);
|
|
680
|
-
await this.updateRows(entity, { $where }, assigned,
|
|
686
|
+
await this.updateRows(entity, { $where }, assigned, UPDATING_DELETED, meta.version).catch((error) => {
|
|
681
687
|
// Still at its version, so its `$where` excluded it: kept, as an unversioned row is.
|
|
682
688
|
if (q.$where && error instanceof UqlOptimisticLockError && error.actual === error.expected) {
|
|
683
689
|
return 0;
|
|
@@ -707,10 +713,11 @@ export class AbstractQuerier {
|
|
|
707
713
|
async deleteWhere(entity, q, opts) {
|
|
708
714
|
assertNamesRows(entity, 'deleteMany', q, opts);
|
|
709
715
|
const meta = getMeta(entity);
|
|
710
|
-
const { returning, ...
|
|
716
|
+
const { returning, ...given } = opts ?? {};
|
|
717
|
+
const rest = { ...given, access: 'delete' };
|
|
711
718
|
const keys = returnedKeys(meta, returning);
|
|
712
719
|
if (!keys) {
|
|
713
|
-
return this.deleteRows(entity, q,
|
|
720
|
+
return this.deleteRows(entity, q, rest);
|
|
714
721
|
}
|
|
715
722
|
const read = [...keys, ...meta.ids];
|
|
716
723
|
// A soft delete stamps the rows, which a `RETURNING` would report stamped rather than as they were.
|
|
@@ -1126,7 +1133,7 @@ export class AbstractQuerier {
|
|
|
1126
1133
|
const distinct = [...new Map(named.map((row) => [rowKey(row, keys), row])).values()];
|
|
1127
1134
|
const byConflict = new Map();
|
|
1128
1135
|
for (const q of this.keyedReads(keys, distinct, [...new Set([...select, ...keys])])) {
|
|
1129
|
-
for (const row of await this.readForWrite(entity, q,
|
|
1136
|
+
for (const row of await this.readForWrite(entity, q, UPDATING_DELETED)) {
|
|
1130
1137
|
const key = rowKey(row, keys);
|
|
1131
1138
|
byConflict.set(key, byConflict.has(key) ? undefined : row);
|
|
1132
1139
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
2
|
-
import type { EntityData, EntityMeta, ExtraOptions, Query, QueryAggregate, QueryUpsert, QueryPage,
|
|
2
|
+
import type { EntityData, EntityMeta, ExtraOptions, Query, QueryAggregate, QueryUpsert, QueryPage, StatementOptions, QuerySearch, QueryUpdateResult, RawRow, SavepointCommand, SqlQuerier, SqlStatement, Type, TransactionOptions, UpdatePayload, ReportedWrite } from '../type/index.js';
|
|
3
3
|
import type { SqlExecution } from '../util/sql.util.js';
|
|
4
4
|
import { AbstractQuerier, type UpsertedId, type ReportingWrites } from './abstractQuerier.js';
|
|
5
5
|
/** A statement as it is sent: its SQL and the values it binds. */
|
|
@@ -60,7 +60,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
60
60
|
private vectorTuning;
|
|
61
61
|
/** Whether `tuning` applies only inside a transaction, as a `SET LOCAL` does: a read opens one, or joins the open one. */
|
|
62
62
|
private tunedInTransaction;
|
|
63
|
-
protected internalFindMany<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
63
|
+
protected internalFindMany<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): Promise<E[]>;
|
|
64
64
|
/** Every row `q` matches past its page, deduplicated where it reads `$distinct`. */
|
|
65
65
|
private countUnpaged;
|
|
66
66
|
/**
|
|
@@ -68,7 +68,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
68
68
|
* an empty page. A window counts before `DISTINCT`, and the Postgres family refuses one beside a `$lock`,
|
|
69
69
|
* so those count apart.
|
|
70
70
|
*/
|
|
71
|
-
protected internalFindManyAndCount<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
71
|
+
protected internalFindManyAndCount<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): Promise<[E[], number]>;
|
|
72
72
|
/**
|
|
73
73
|
* The rows a read of `entity` matches, each as its statement reads it, the vector search's tuning leading it, in a
|
|
74
74
|
* transaction of its own where the tuning needs one and none is open.
|
|
@@ -86,7 +86,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
86
86
|
* and connects on its own, its values going as the context holds them, each normalized as it was bound. Tuning
|
|
87
87
|
* that needs a transaction is refused outside one, which would otherwise stay open for the whole loop.
|
|
88
88
|
*/
|
|
89
|
-
protected internalFindManyStream<E extends object>(entity: Type<E>, q: Query<E>, opts?:
|
|
89
|
+
protected internalFindManyStream<E extends object>(entity: Type<E>, q: Query<E>, opts?: StatementOptions): AsyncGenerator<Awaited<E>, void, unknown>;
|
|
90
90
|
/**
|
|
91
91
|
* A read's rows one at a time: paged through a server-side cursor where the engine has one, read whole
|
|
92
92
|
* where it has none. A driver that streams on its own overrides this; a Node `Readable` it hands back
|
|
@@ -99,9 +99,9 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
99
99
|
* as 0; no row is 0 too, since a catalog that does not know the table answers with none.
|
|
100
100
|
*/
|
|
101
101
|
private runCount;
|
|
102
|
-
protected internalCount<E extends object>(entity: Type<E>, q: QueryPage<E>, opts?:
|
|
102
|
+
protected internalCount<E extends object>(entity: Type<E>, q: QueryPage<E>, opts?: StatementOptions): Promise<number>;
|
|
103
103
|
estimatedCount<E extends object>(entity: Type<E>): Promise<number>;
|
|
104
|
-
protected internalAggregate<E extends object>(entity: Type<E>, q: QueryAggregate<E>, opts?:
|
|
104
|
+
protected internalAggregate<E extends object>(entity: Type<E>, q: QueryAggregate<E>, opts?: StatementOptions): Promise<RawRow[]>;
|
|
105
105
|
internalInsertMany<E extends object>(entity: Type<E>, rows: EntityData<E>[]): Promise<void>;
|
|
106
106
|
/**
|
|
107
107
|
* Settles the key of each row leaving it out, unless the database generates it. With no default nothing fills it, so
|
|
@@ -119,7 +119,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
119
119
|
private insertChunks;
|
|
120
120
|
/** Inserts `rows`, reporting each, in their order, with the fields `keys` names, off its own `RETURNING`, and placing its key on it. */
|
|
121
121
|
private insertedRows;
|
|
122
|
-
internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?:
|
|
122
|
+
internalUpdateMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, payload: UpdatePayload<E>, opts?: StatementOptions): Promise<number>;
|
|
123
123
|
/** The writes reading their rows off their own statement, where {@link AbstractSqlDialect.reportsWrite} says so. */
|
|
124
124
|
protected reportingWrites<E>(meta: EntityMeta<E>, write: ReportedWrite): ReportingWrites | undefined;
|
|
125
125
|
/**
|
|
@@ -143,7 +143,7 @@ export declare abstract class AbstractSqlQuerier extends AbstractQuerier impleme
|
|
|
143
143
|
* statement's header names its row's id, which spares the read back.
|
|
144
144
|
*/
|
|
145
145
|
private upsertGroups;
|
|
146
|
-
protected internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?:
|
|
146
|
+
protected internalDeleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E>, opts?: StatementOptions): Promise<number>;
|
|
147
147
|
protected openTransaction(opts?: TransactionOptions): Promise<void>;
|
|
148
148
|
/**
|
|
149
149
|
* A `COMMIT` that fails can leave the transaction open (SQLite answers `SQLITE_BUSY` and keeps it), so the
|
package/dist/querier/keyset.d.ts
CHANGED
|
@@ -17,3 +17,18 @@ export type KeysetRead<E> = {
|
|
|
17
17
|
* another page follows. `nullsSortLowest` says where the engine sorts nulls, for keys with no placement.
|
|
18
18
|
*/
|
|
19
19
|
export declare function keysetRead<E extends object>(meta: EntityMeta<E>, q: QueryKeyset<E>, nullsSortLowest: boolean): KeysetRead<E>;
|
|
20
|
+
/** The clauses {@link assertPageable} reads, which any query has: a client's names none it must. */
|
|
21
|
+
type PageClauses = {
|
|
22
|
+
readonly $limit?: number;
|
|
23
|
+
readonly $after?: string;
|
|
24
|
+
readonly $before?: string;
|
|
25
|
+
readonly $distinct?: unknown;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Refuses a page query with `$skip`, both cursors, `$distinct`, or a `$limit` that is not a positive integer, each
|
|
29
|
+
* refusal naming the clause at fault: what a page needs, for the API to check a client's query by.
|
|
30
|
+
*/
|
|
31
|
+
export declare function assertPageable<E, Q extends PageClauses>(meta: EntityMeta<E>, q: Q): asserts q is Q & {
|
|
32
|
+
readonly $limit: number;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
package/dist/querier/keyset.js
CHANGED
|
@@ -54,28 +54,31 @@ export function keysetRead(meta, q, nullsSortLowest) {
|
|
|
54
54
|
};
|
|
55
55
|
return { query, page };
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Refuses a page query with `$skip`, both cursors, `$distinct`, or a `$limit` that is not a positive integer, each
|
|
59
|
+
* refusal naming the clause at fault: what a page needs, for the API to check a client's query by.
|
|
60
|
+
*/
|
|
61
|
+
export function assertPageable(meta, q) {
|
|
62
|
+
const refuse = (why, clause) => new UqlUsageError(`a page of '${entityName(meta)}' ${why}`, { path: [clause] });
|
|
60
63
|
// The type forbids `$skip`, but untyped input from `/http` can still carry one.
|
|
61
64
|
if ('$skip' in q && q.$skip !== undefined) {
|
|
62
|
-
throw refuse('takes no $skip: an offset reintroduces the drift a cursor removes');
|
|
65
|
+
throw refuse('takes no $skip: an offset reintroduces the drift a cursor removes', '$skip');
|
|
63
66
|
}
|
|
64
67
|
if (q.$after !== undefined && q.$before !== undefined) {
|
|
65
|
-
throw refuse('reads past one cursor, $after or $before, not both');
|
|
68
|
+
throw refuse('reads past one cursor, $after or $before, not both', '$before');
|
|
66
69
|
}
|
|
67
70
|
if (q.$distinct) {
|
|
68
|
-
throw refuse('takes no $distinct: its rows are a grouping, which the cursor compares no column of');
|
|
71
|
+
throw refuse('takes no $distinct: its rows are a grouping, which the cursor compares no column of', '$distinct');
|
|
69
72
|
}
|
|
70
|
-
if (!Number.isInteger(q.$limit) || q.$limit < 1) {
|
|
71
|
-
throw refuse(`holds a positive whole number of rows, and $limit is ${q.$limit}
|
|
73
|
+
if (q.$limit === undefined || !Number.isInteger(q.$limit) || q.$limit < 1) {
|
|
74
|
+
throw refuse(`holds a positive whole number of rows, and $limit is ${q.$limit}`, '$limit');
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
/** Resolves each key of the page's `$sort`, refusing one without a stored value a cursor can compare. */
|
|
75
78
|
function pageOrder(meta, q, nullsSortLowest) {
|
|
76
79
|
const sort = q.$sort ?? {};
|
|
77
80
|
return getKeys(sort).map((key) => {
|
|
78
|
-
const refuse = (why) => new UqlUsageError(`cannot page '${entityName(meta)}' by '${key}': ${why}
|
|
81
|
+
const refuse = (why) => new UqlUsageError(`cannot page '${entityName(meta)}' by '${key}': ${why}`, { path: ['$sort', key] });
|
|
79
82
|
if (key === '$text') {
|
|
80
83
|
throw refuse('a relevance is scored per row, not stored on it');
|
|
81
84
|
}
|
|
@@ -130,7 +133,7 @@ function totalPrefix(meta, order) {
|
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
throw new UqlUsageError(`a page of '${entityName(meta)}' sorts by ${order.map(({ key }) => key).join(', ') || 'nothing'}, which two rows ` +
|
|
133
|
-
`can share: add ${meta.ids.length ? `'${meta.ids.join("', '")}' or ` : ''}a unique, non-null field to the end of $sort
|
|
136
|
+
`can share: add ${meta.ids.length ? `'${meta.ids.join("', '")}' or ` : ''}a unique, non-null field to the end of $sort`, { path: ['$sort'] });
|
|
134
137
|
}
|
|
135
138
|
/** The key in the opposite direction, nulls included, which `$before` reads so its extra row comes first. */
|
|
136
139
|
function inverted(key) {
|
|
@@ -188,7 +191,9 @@ function anyOf(alternatives) {
|
|
|
188
191
|
*/
|
|
189
192
|
function projectedKeys(meta, q) {
|
|
190
193
|
if (isSelectList(q.$select)) {
|
|
191
|
-
throw new UqlUsageError(`a page of '${entityName(meta)}' selects fields, which its cursor is read off
|
|
194
|
+
throw new UqlUsageError(`a page of '${entityName(meta)}' selects fields, which its cursor is read off`, {
|
|
195
|
+
path: ['$select'],
|
|
196
|
+
});
|
|
192
197
|
}
|
|
193
198
|
return normalizeScalarFieldSelection(meta, q.$select);
|
|
194
199
|
}
|
|
@@ -18,7 +18,7 @@ export type LocalSqlitePoolOptions = {
|
|
|
18
18
|
export type LocalSqliteDatabase = {
|
|
19
19
|
prepare(sql: string): SqlitePreparedStatement;
|
|
20
20
|
loadExtension(path: string): void;
|
|
21
|
-
/** Defines a SQL function, which `bun:sqlite` has
|
|
21
|
+
/** Defines a SQL function, which `bun:sqlite` has from Bun 1.4.4. */
|
|
22
22
|
function?(name: string, options: {
|
|
23
23
|
deterministic: boolean;
|
|
24
24
|
}, fn: (...args: SqlValue[]) => SqlValue): unknown;
|
package/dist/type/column.d.ts
CHANGED
|
@@ -111,7 +111,10 @@ export interface ColumnBuilder<in out O, in out V, F extends Family> extends Col
|
|
|
111
111
|
comment(text: string): With<O, V, {
|
|
112
112
|
readonly comment: string;
|
|
113
113
|
}, F>;
|
|
114
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Leaves the column out of a read naming no fields. A read naming it still gets it, so it keeps no secret from a
|
|
116
|
+
* client: an API's `serve(Entity, { members: { field: false } })` does.
|
|
117
|
+
*/
|
|
115
118
|
eager(eager: false): With<O, V, {
|
|
116
119
|
readonly eager: false;
|
|
117
120
|
}, F>;
|
package/dist/type/querier.d.ts
CHANGED
|
@@ -46,11 +46,11 @@ export type EngineName = (typeof ENGINE_NAMES)[DialectName] | 'Cloudflare D1' |
|
|
|
46
46
|
* **first** on purpose: when no signature matches, TypeScript reports the error of the *last* one, so a
|
|
47
47
|
* typo'd query key is reported as itself rather than as a missing `$entity`.
|
|
48
48
|
*/
|
|
49
|
-
type DualRead<K extends keyof ReadQueries<object, never>, R extends keyof ReadResults<
|
|
49
|
+
type DualRead<K extends keyof ReadQueries<object, never>, R extends keyof ReadResults<unknown>> = (<E extends object, const Q extends ReadQueries<E, QuerySql>[K] & {
|
|
50
50
|
$entity: Type<E>;
|
|
51
51
|
}>(q: Captured<ReadQueries<E, QuerySql>[K] & {
|
|
52
52
|
$entity: Type<E>;
|
|
53
|
-
}, Q>, opts?: QueryOptions) => ReadResults<
|
|
53
|
+
}, Q>, opts?: QueryOptions) => ReadResults<QueryFindResult<E, Q>>[R]) & EntityRead<K, R, 'server', QueryOptions>;
|
|
54
54
|
/** Each method below taking a query takes the entity first or as the query's `$entity`, as {@link DualRead} does. */
|
|
55
55
|
export interface Querier extends UniversalQuerier {
|
|
56
56
|
findOne: DualRead<'one', 'one'>;
|
package/dist/type/query.d.ts
CHANGED
|
@@ -24,11 +24,15 @@ export type QueryOptions = {
|
|
|
24
24
|
unfiltered?: boolean;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* What a statement
|
|
28
|
-
*
|
|
29
|
-
* and none of this is a caller's to set: an alias is the dialect's to choose and to spell.
|
|
27
|
+
* What a statement runs with, on top of the options its caller passed. Kept apart from {@link QueryOptions}
|
|
28
|
+
* because that one is public, the third argument of every querier method, and none of this is a caller's to set.
|
|
30
29
|
*/
|
|
31
|
-
export type
|
|
30
|
+
export type StatementOptions = QueryOptions & {
|
|
31
|
+
/** What the statement does, which picks the `security` filters scoping it: a read by default. A write's reads take its own. */
|
|
32
|
+
readonly access?: EntityAccess;
|
|
33
|
+
};
|
|
34
|
+
/** What a statement is rendered with: an alias is the dialect's to choose and to spell. */
|
|
35
|
+
export type QueryRenderOptions = StatementOptions & {
|
|
32
36
|
/** The alias columns are read off, escaped by the dialect unless {@link escapedPrefix} spells it. */
|
|
33
37
|
prefix?: string;
|
|
34
38
|
/**
|
|
@@ -106,6 +110,10 @@ export type FilterWhere<E> = QueryWhere<E> | ((context: UqlContext | undefined)
|
|
|
106
110
|
* `throw` fails closed (the default for `security` filters).
|
|
107
111
|
*/
|
|
108
112
|
export type FilterOnMissing = 'skip' | 'throw';
|
|
113
|
+
/** What a field takes: reading it (select, filter, sort, distinct, aggregate) and writing it. */
|
|
114
|
+
export type FieldAccess = 'read' | 'insert' | 'update';
|
|
115
|
+
/** What a statement does to an entity's rows: a field's access, and deleting rows, which no field has a part in. */
|
|
116
|
+
export type EntityAccess = FieldAccess | 'delete';
|
|
109
117
|
/**
|
|
110
118
|
* Authoring shape for `@Entity({ filters })` and `defineEntity`'s `.filters()`.
|
|
111
119
|
*/
|
|
@@ -117,6 +125,7 @@ export type FilterOptions<E = unknown> = {
|
|
|
117
125
|
readonly security?: false;
|
|
118
126
|
/** What to do when {@link FilterOptions.where} returns `undefined`. Defaults to `skip`. */
|
|
119
127
|
readonly onMissing?: FilterOnMissing;
|
|
128
|
+
readonly ops?: never;
|
|
120
129
|
} | {
|
|
121
130
|
/**
|
|
122
131
|
* Row-level-security filter: always applied (ignores `QueryOptions.filters` bypass) and
|
|
@@ -124,6 +133,11 @@ export type FilterOptions<E = unknown> = {
|
|
|
124
133
|
*/
|
|
125
134
|
readonly security: true;
|
|
126
135
|
readonly onMissing?: 'throw';
|
|
136
|
+
/**
|
|
137
|
+
* The statements it holds, every one by default: `['insert', 'update', 'delete']` lets anyone read a row
|
|
138
|
+
* and only its author write it. An update or a delete reads the rows it changes, so read ones hold it too.
|
|
139
|
+
*/
|
|
140
|
+
readonly ops?: readonly EntityAccess[];
|
|
127
141
|
});
|
|
128
142
|
/**
|
|
129
143
|
* direction for the sort, and where nulls land in it.
|
|
@@ -2,33 +2,33 @@ import type { EntityId, EntityWrite, FieldKey, UpdateWrite } from './entity.js';
|
|
|
2
2
|
import type { Captured, CursorPage, Query, QueryUpsert, QueryFilter, QueryFindResult, QueryKeyset, QueryOne, QueryOptions, QueryPage, QuerySearch, WriteResults, WriteOptions } from './query.js';
|
|
3
3
|
import type { QueryAggregate, QueryAggregateResult } from './queryAggregate.js';
|
|
4
4
|
import type { BooleanLike, Type } from './utility.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { QuerierSql, QuerierTransport } from './wire.js';
|
|
6
6
|
/** The query each read takes, keyed by the kind of read. */
|
|
7
7
|
export type ReadQueries<E, Sql> = {
|
|
8
8
|
readonly one: QueryOne<E, Sql>;
|
|
9
9
|
readonly many: Query<E, Sql>;
|
|
10
10
|
readonly page: QueryKeyset<E, Sql>;
|
|
11
11
|
};
|
|
12
|
-
/** The result type of each read
|
|
13
|
-
export type ReadResults<
|
|
14
|
-
readonly one:
|
|
15
|
-
readonly many:
|
|
16
|
-
readonly counted:
|
|
17
|
-
readonly page:
|
|
12
|
+
/** The result type of each read, keyed by the kind of read: alike on the server and the client. */
|
|
13
|
+
export type ReadResults<T> = {
|
|
14
|
+
readonly one: Promise<T | undefined>;
|
|
15
|
+
readonly many: Promise<T[]>;
|
|
16
|
+
readonly counted: Promise<[T[], number]>;
|
|
17
|
+
readonly page: Promise<CursorPage<T>>;
|
|
18
18
|
readonly stream: AsyncIterable<T>;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* A read that takes the entity first, then the query, and returns rows narrowed to what the query projected. `K` picks
|
|
22
|
-
* the query type, `R` the result type
|
|
22
|
+
* the query type, `R` the result type, `W` the transport, whose SQL its queries may carry, and `O` the options.
|
|
23
23
|
*/
|
|
24
|
-
export type EntityRead<K extends keyof ReadQueries<object, never>, R extends keyof ReadResults<
|
|
24
|
+
export type EntityRead<K extends keyof ReadQueries<object, never>, R extends keyof ReadResults<unknown>, W extends QuerierTransport, O> = <E extends object, const Q extends ReadQueries<E, QuerierSql<W>>[K]>(entity: Type<E>, q: Captured<ReadQueries<E, QuerierSql<W>>[K], Q>, opts?: O) => ReadResults<QueryFindResult<E, Q>>[R];
|
|
25
25
|
/**
|
|
26
26
|
* The operations the server and the browser client declare alike, per transport `W`, options `O`,
|
|
27
27
|
* and delete options `DO`, which on the client also carry the {@link QueryOptions} it cannot pass otherwise.
|
|
28
28
|
*/
|
|
29
29
|
export interface SharedQuerier<W extends QuerierTransport, O, DO = O> {
|
|
30
30
|
/** Find the record with the given primary key. */
|
|
31
|
-
findOneById<E extends object, const Q extends QueryOne<E, QuerierSql<W>> = {}>(entity: Type<E>, id: EntityId<E>, q?: Captured<QueryOne<E, QuerierSql<W>>, Q>, opts?: O):
|
|
31
|
+
findOneById<E extends object, const Q extends QueryOne<E, QuerierSql<W>> = {}>(entity: Type<E>, id: EntityId<E>, q?: Captured<QueryOne<E, QuerierSql<W>>, Q>, opts?: O): Promise<QueryFindResult<E, Q> | undefined>;
|
|
32
32
|
/**
|
|
33
33
|
* obtains the first record matching the given search parameters.
|
|
34
34
|
* @param entity the target entity
|
|
@@ -52,27 +52,27 @@ export interface SharedQuerier<W extends QuerierTransport, O, DO = O> {
|
|
|
52
52
|
*/
|
|
53
53
|
findManyPage: EntityRead<'page', 'page', W, O>;
|
|
54
54
|
/** Count the records matching the filter, or those a page of them takes. */
|
|
55
|
-
count<E extends object>(entity: Type<E>, q?: QueryPage<E, QuerierSql<W>>, opts?: O):
|
|
55
|
+
count<E extends object>(entity: Type<E>, q?: QueryPage<E, QuerierSql<W>>, opts?: O): Promise<number>;
|
|
56
56
|
/** Whether any record matches: a count capped at one row, so the engine stops at the first match. */
|
|
57
|
-
exists<E extends object>(entity: Type<E>, q?: QueryFilter<E, QuerierSql<W>>, opts?: O):
|
|
57
|
+
exists<E extends object>(entity: Type<E>, q?: QueryFilter<E, QuerierSql<W>>, opts?: O): Promise<boolean>;
|
|
58
58
|
/** Update the record with the given primary key; resolves to the number of affected rows. */
|
|
59
|
-
updateOneById<E extends object>(entity: Type<E>, id: EntityId<E>, payload: UpdateWrite<E, QuerierSql<W>>, opts?: O):
|
|
59
|
+
updateOneById<E extends object>(entity: Type<E>, id: EntityId<E>, payload: UpdateWrite<E, QuerierSql<W>>, opts?: O): Promise<number>;
|
|
60
60
|
/** Update the records matching the query; resolves to the number of affected rows. */
|
|
61
|
-
updateMany<E extends object>(entity: Type<E>, q: QuerySearch<E, QuerierSql<W>>, payload: UpdateWrite<E, QuerierSql<W>>, opts?: O):
|
|
61
|
+
updateMany<E extends object>(entity: Type<E>, q: QuerySearch<E, QuerierSql<W>>, payload: UpdateWrite<E, QuerierSql<W>>, opts?: O): Promise<number>;
|
|
62
62
|
/**
|
|
63
63
|
* delete or SoftDelete a record.
|
|
64
64
|
* @param entity the entity to persist on
|
|
65
65
|
* @param id the primary key of the record
|
|
66
66
|
* @return the number of affected records
|
|
67
67
|
*/
|
|
68
|
-
deleteOneById<E extends object>(entity: Type<E>, id: EntityId<E>, opts?: DO):
|
|
68
|
+
deleteOneById<E extends object>(entity: Type<E>, id: EntityId<E>, opts?: DO): Promise<number>;
|
|
69
69
|
/**
|
|
70
70
|
* delete or SoftDelete records.
|
|
71
71
|
* @param entity the entity to persist on
|
|
72
72
|
* @param q the criteria to look for the records
|
|
73
73
|
* @return the number of affected records
|
|
74
74
|
*/
|
|
75
|
-
deleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E, QuerierSql<W>>, opts?: DO):
|
|
75
|
+
deleteMany<E extends object>(entity: Type<E>, q: QuerySearch<E, QuerierSql<W>>, opts?: DO): Promise<number>;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* A `querier` allows to interact with the datasource to perform persistence operations on any entity.
|
package/dist/type/wire.d.ts
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import type { QuerySql } from './querySql.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export type RequestSuccessResponse<E> = {
|
|
6
|
-
data: E;
|
|
7
|
-
count?: number;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* A {@link RequestSuccessResponse} whose `count` is always present - what `findManyAndCount` sends.
|
|
11
|
-
*/
|
|
12
|
-
export type RequestCountedSuccessResponse<E> = RequestSuccessResponse<E> & {
|
|
13
|
-
count: number;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Which side of the wire a querier sits on. A server querier hands the result back directly, a
|
|
17
|
-
* client one hands back the envelope its transport wrapped it in.
|
|
3
|
+
* Which side of the wire a querier sits on, which says what SQL its queries may carry: both answer alike.
|
|
18
4
|
*/
|
|
19
5
|
export type QuerierTransport = 'server' | 'client';
|
|
20
6
|
/**
|
|
@@ -25,19 +11,3 @@ export type QuerierSql<W extends QuerierTransport> = {
|
|
|
25
11
|
server: QuerySql;
|
|
26
12
|
client: never;
|
|
27
13
|
}[W];
|
|
28
|
-
/**
|
|
29
|
-
* A querier method's result on a transport: `Promise<User[]>` on the server, the response envelope on
|
|
30
|
-
* the client. A map indexed by the transport, which resolves away in hovers.
|
|
31
|
-
*/
|
|
32
|
-
export type QuerierResult<W extends QuerierTransport, T> = {
|
|
33
|
-
server: Promise<T>;
|
|
34
|
-
client: Promise<RequestSuccessResponse<T>>;
|
|
35
|
-
}[W];
|
|
36
|
-
/**
|
|
37
|
-
* `findManyAndCount`'s result: the one shape the transports disagree on past the envelope, a tuple
|
|
38
|
-
* on the server against a counted envelope on the client.
|
|
39
|
-
*/
|
|
40
|
-
export type QuerierCountedResult<W extends QuerierTransport, T> = {
|
|
41
|
-
server: Promise<[T[], number]>;
|
|
42
|
-
client: Promise<RequestCountedSuccessResponse<T[]>>;
|
|
43
|
-
}[W];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IndexType } from '../schema/types.js';
|
|
2
|
-
import { type AggregateCall, type CascadeType, type EntityData, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type FieldUpdateOp, type JsonArrayUpdateOp, type JsonUpdateOp, type OnFieldCallback, type QueryAggMap, type QueryConflictKeys, type QueryUpsert, type QueryGroupMap, type QueryOptions, QuerySql, 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';
|
|
2
|
+
import { type AggregateCall, type CascadeType, type EntityAccess, type EntityData, type EntityIndexMeta, type EntityMeta, type FieldKey, type FieldOptions, type FieldUpdateOp, type JsonArrayUpdateOp, type JsonUpdateOp, type OnFieldCallback, type QueryAggMap, type QueryConflictKeys, type QueryUpsert, type QueryGroupMap, type QueryOptions, QuerySql, type QuerySearch, type QuerySelect, type QuerySelectValue, type QuerySortDirection, type QuerySizeComparisonOps, type QuerySortMap, type QueryTextSearchOptions, type QueryVectorQuery, type QueryVectorSearch, type QueryWhere, type RelationKey, type StatementOptions, 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>[];
|
|
@@ -135,12 +135,12 @@ export declare function fieldUpdateOf(key: string, value: FieldUpdateOp): [keyof
|
|
|
135
135
|
* `$where` with the entity's active filters merged in, against the ambient {@link UqlContext}. A convenience
|
|
136
136
|
* filter yields to a `$where` on its key; a `security` one is always ANDed, from {@link securityConditions}.
|
|
137
137
|
*/
|
|
138
|
-
export declare function applyFilters<E>(meta: EntityMeta<E>, whereMap: QueryWhere<E>, opts?:
|
|
138
|
+
export declare function applyFilters<E>(meta: EntityMeta<E>, whereMap: QueryWhere<E>, opts?: StatementOptions): QueryWhere<E>;
|
|
139
139
|
/**
|
|
140
|
-
*
|
|
141
|
-
* `{}`, a trusted context's "no restriction", is left out. Reads AND these in; writes are held to them.
|
|
140
|
+
* The condition of each `security` filter holding any of `accesses`, by name, resolved against the ambient context.
|
|
141
|
+
* One resolving to `{}`, a trusted context's "no restriction", is left out. Reads AND these in; writes are held to them.
|
|
142
142
|
*/
|
|
143
|
-
export declare function securityConditions<E>(meta: EntityMeta<E
|
|
143
|
+
export declare function securityConditions<E>(meta: EntityMeta<E>, accesses: readonly EntityAccess[]): [name: string, condition: QueryWhere<E>][];
|
|
144
144
|
/**
|
|
145
145
|
* Holds written rows to the `security` filters, as {@link applyFilters} holds reads: an inserted row gets
|
|
146
146
|
* each field a condition names and it leaves out, and a row naming one must carry the condition's value.
|
|
@@ -178,20 +178,13 @@ export declare function parseSortByCount(val: unknown): unknown;
|
|
|
178
178
|
* entries consumable by any dialect. Grouped columns come first, then computed columns.
|
|
179
179
|
*/
|
|
180
180
|
export declare function parseGroupMap<E>(group?: QueryGroupMap<E>, select?: QueryAggMap<E>): ParsedGroupEntry<E>[];
|
|
181
|
-
/**
|
|
182
|
-
* Whether `value` is a map of comparison operators rather than a value to compare against. Only a
|
|
183
|
-
* plain object qualifies: `Date`, `QuerySql`, `Uint8Array` and arrays are all `typeof 'object'`, and
|
|
184
|
-
* reading their keys as operators drops the condition (a `Date` has none) or throws on an array's
|
|
185
|
-
* indices. Shared by the SQL and MongoDB builders, whose `$where` and `$having` all face this.
|
|
186
|
-
*/
|
|
187
|
-
export declare function isOperatorMap(value: unknown): value is Record<string, unknown>;
|
|
188
181
|
/** A JSON object, matched by what it holds: a plain object with no operator key. */
|
|
189
182
|
export declare function isJsonObject(value: unknown): value is Record<string, unknown>;
|
|
190
183
|
/**
|
|
191
|
-
* A page operand, checked before it reaches an engine. These arrive from page arithmetic and from
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
184
|
+
* A page operand, checked before it reaches an engine. These arrive from page arithmetic and from a
|
|
185
|
+
* client's call, where JSON carries a fraction or a negative alike, and each engine's own complaint
|
|
186
|
+
* names neither the clause nor the value - or, for `$limit: 0`, quietly means something else.
|
|
187
|
+
* Shared so every backend rejects the same input.
|
|
195
188
|
*/
|
|
196
189
|
export declare function assertNonNegativeInteger(value: number, clause: string): number;
|
|
197
190
|
/**
|