@atscript/db 0.1.147 → 0.1.149
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/{agg-CV7y8nC6.d.cts → agg-42CSpGDR.d.cts} +2 -2
- package/dist/{agg-D5DHsAby.d.mts → agg-Wo-smrYV.d.mts} +3 -3
- package/dist/agg.cjs +1 -1
- package/dist/agg.d.cts +2 -2
- package/dist/agg.d.mts +2 -2
- package/dist/agg.mjs +1 -1
- package/dist/{aggregate-fns-CtsRbZn9.cjs → aggregate-fns-C-UJRobm.cjs} +46 -7
- package/dist/{aggregate-fns-C0BymEqa.mjs → aggregate-fns-CyaZyb9I.mjs} +35 -8
- package/dist/aggregate-rules-D_bsCpUI.cjs +26 -0
- package/dist/aggregate-rules-jdPrxqWa.mjs +15 -0
- package/dist/{buckets-DYopfd2Y.d.mts → buckets-CNdTOnei.d.mts} +312 -18
- package/dist/{buckets-CjdPipCC.d.cts → buckets-DJiYlMXc.d.cts} +312 -18
- package/dist/{column-diff-Dt7EDJsA.cjs → column-diff-CUU4GvYg.cjs} +681 -87
- package/dist/{column-diff-CO06iQvI.mjs → column-diff-Cp6ZoyRE.mjs} +678 -96
- package/dist/{db-error-D5uilS_A.mjs → db-error-Az85UhTX.mjs} +32 -1
- package/dist/{db-error-DTkkeu5b.cjs → db-error-DRQH4sLY.cjs} +55 -0
- package/dist/{fk-diff-BtOmL4OW.d.mts → fk-diff-BQ4krij8.d.cts} +1 -1
- package/dist/{fk-diff-DLqwVkKG.d.cts → fk-diff-DsaIijVX.d.mts} +1 -1
- package/dist/index.cjs +70 -5
- package/dist/index.d.cts +58 -13
- package/dist/index.d.mts +58 -13
- package/dist/index.mjs +64 -6
- package/dist/{nested-writer-SqtYJHF0.cjs → nested-writer-BUQvk6QT.cjs} +68 -2
- package/dist/{nested-writer-D35UsDBT.mjs → nested-writer-CUBoq1ZO.mjs} +57 -3
- package/dist/numeric-operand-B1jKH7x5.mjs +21 -0
- package/dist/numeric-operand-DKfiRLYp.cjs +26 -0
- package/dist/ops.cjs +1 -1
- package/dist/ops.mjs +1 -1
- package/dist/plugin.cjs +36 -9
- package/dist/plugin.mjs +36 -9
- package/dist/rel.cjs +2 -2
- package/dist/rel.d.cts +2 -2
- package/dist/rel.d.mts +2 -2
- package/dist/rel.mjs +2 -2
- package/dist/{relation-helpers-C2bLtE-t.d.mts → relation-helpers-Ba0v49sn.d.mts} +1 -1
- package/dist/{relation-helpers-DH3LvwLV.d.cts → relation-helpers-kX7jjgME.d.cts} +1 -1
- package/dist/{relation-loader-C0qE8xgR.mjs → relation-loader-ByY1Byrl.mjs} +1 -1
- package/dist/{relation-loader-BFhVuJ-B.cjs → relation-loader-D8OrdH-r.cjs} +1 -1
- package/dist/shared.cjs +3 -0
- package/dist/shared.d.cts +12 -1
- package/dist/shared.d.mts +12 -1
- package/dist/shared.mjs +2 -1
- package/dist/sync.cjs +2 -2
- package/dist/sync.d.cts +2 -2
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +2 -2
- package/dist/{validator-Clu2q_7z.mjs → validator-BTiIOTKP.mjs} +9 -3
- package/dist/{validator-CVS-onRg.cjs → validator-UcuJxHNT.cjs} +8 -2
- package/dist/{validator-CMnTI6r7.d.cts → validator-tBNvM1qc.d.cts} +23 -2
- package/dist/{validator-CMnTI6r7.d.mts → validator-tBNvM1qc.d.mts} +23 -2
- package/dist/validator.cjs +2 -2
- package/dist/validator.d.cts +1 -1
- package/dist/validator.d.mts +1 -1
- package/dist/validator.mjs +2 -2
- package/package.json +8 -8
|
@@ -10,6 +10,25 @@ var DbError = class extends Error {
|
|
|
10
10
|
this.stack = void 0;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
/** Whether `error` is a `DbError` with code `CONFLICT` (unique / primary-key violation). */
|
|
14
|
+
function isConflict(error) {
|
|
15
|
+
return error instanceof DbError && error.code === "CONFLICT";
|
|
16
|
+
}
|
|
17
|
+
/** @internal The error every handle of a closed `DbSpace` throws. */
|
|
18
|
+
function spaceClosedError() {
|
|
19
|
+
return new DbError("SPACE_CLOSED", [{
|
|
20
|
+
path: "",
|
|
21
|
+
message: "The DbSpace is closed; table and view handles can no longer be used"
|
|
22
|
+
}]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Collapses the failures of a multi-step shutdown into one `AggregateError`
|
|
26
|
+
* (message lists every failure).
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function aggregateFailure(label, errors) {
|
|
30
|
+
return new AggregateError(errors, `${label}: ${errors.map((e) => e instanceof Error ? e.message : String(e)).join("; ")}`);
|
|
31
|
+
}
|
|
13
32
|
/**
|
|
14
33
|
* Thrown when a write payload nests deeper than the table's
|
|
15
34
|
* declared `@db.depth.limit N`. Surfaced as HTTP 400 in moost-db.
|
|
@@ -83,5 +102,17 @@ function bucketTimeZoneUnavailable(message) {
|
|
|
83
102
|
message
|
|
84
103
|
}]);
|
|
85
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The adapter's `supportsAggregateExpressions()` is false (or its SQL dialect
|
|
107
|
+
* cannot cast to a double) and the query uses arithmetic in an aggregate
|
|
108
|
+
* `$select` (`AGG_EXPR_NOT_SUPPORTED`, `path` `$select`; moost-db: 400).
|
|
109
|
+
* @since 0.1.148
|
|
110
|
+
*/
|
|
111
|
+
function aggregateExpressionsNotSupported() {
|
|
112
|
+
return new DbError("AGG_EXPR_NOT_SUPPORTED", [{
|
|
113
|
+
path: "$select",
|
|
114
|
+
message: "Aggregate expressions are not supported by this adapter"
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
86
117
|
//#endregion
|
|
87
|
-
export {
|
|
118
|
+
export { aggregateExpressionsNotSupported as a, isConflict as c, DepthLimitExceededError as i, spaceClosedError as l, CasMismatchError as n, aggregateFailure as o, DbError as r, bucketTimeZoneUnavailable as s, CasExhaustedError as t };
|
|
@@ -10,6 +10,25 @@ var DbError = class extends Error {
|
|
|
10
10
|
this.stack = void 0;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
/** Whether `error` is a `DbError` with code `CONFLICT` (unique / primary-key violation). */
|
|
14
|
+
function isConflict(error) {
|
|
15
|
+
return error instanceof DbError && error.code === "CONFLICT";
|
|
16
|
+
}
|
|
17
|
+
/** @internal The error every handle of a closed `DbSpace` throws. */
|
|
18
|
+
function spaceClosedError() {
|
|
19
|
+
return new DbError("SPACE_CLOSED", [{
|
|
20
|
+
path: "",
|
|
21
|
+
message: "The DbSpace is closed; table and view handles can no longer be used"
|
|
22
|
+
}]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Collapses the failures of a multi-step shutdown into one `AggregateError`
|
|
26
|
+
* (message lists every failure).
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function aggregateFailure(label, errors) {
|
|
30
|
+
return new AggregateError(errors, `${label}: ${errors.map((e) => e instanceof Error ? e.message : String(e)).join("; ")}`);
|
|
31
|
+
}
|
|
13
32
|
/**
|
|
14
33
|
* Thrown when a write payload nests deeper than the table's
|
|
15
34
|
* declared `@db.depth.limit N`. Surfaced as HTTP 400 in moost-db.
|
|
@@ -83,6 +102,18 @@ function bucketTimeZoneUnavailable(message) {
|
|
|
83
102
|
message
|
|
84
103
|
}]);
|
|
85
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The adapter's `supportsAggregateExpressions()` is false (or its SQL dialect
|
|
107
|
+
* cannot cast to a double) and the query uses arithmetic in an aggregate
|
|
108
|
+
* `$select` (`AGG_EXPR_NOT_SUPPORTED`, `path` `$select`; moost-db: 400).
|
|
109
|
+
* @since 0.1.148
|
|
110
|
+
*/
|
|
111
|
+
function aggregateExpressionsNotSupported() {
|
|
112
|
+
return new DbError("AGG_EXPR_NOT_SUPPORTED", [{
|
|
113
|
+
path: "$select",
|
|
114
|
+
message: "Aggregate expressions are not supported by this adapter"
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
86
117
|
//#endregion
|
|
87
118
|
Object.defineProperty(exports, "CasExhaustedError", {
|
|
88
119
|
enumerable: true,
|
|
@@ -108,9 +139,33 @@ Object.defineProperty(exports, "DepthLimitExceededError", {
|
|
|
108
139
|
return DepthLimitExceededError;
|
|
109
140
|
}
|
|
110
141
|
});
|
|
142
|
+
Object.defineProperty(exports, "aggregateExpressionsNotSupported", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function() {
|
|
145
|
+
return aggregateExpressionsNotSupported;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(exports, "aggregateFailure", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function() {
|
|
151
|
+
return aggregateFailure;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
111
154
|
Object.defineProperty(exports, "bucketTimeZoneUnavailable", {
|
|
112
155
|
enumerable: true,
|
|
113
156
|
get: function() {
|
|
114
157
|
return bucketTimeZoneUnavailable;
|
|
115
158
|
}
|
|
116
159
|
});
|
|
160
|
+
Object.defineProperty(exports, "isConflict", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function() {
|
|
163
|
+
return isConflict;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(exports, "spaceClosedError", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function() {
|
|
169
|
+
return spaceClosedError;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $t as AtscriptDbView, B as TDbDefaultValue, H as TDbFieldMeta, U as TDbForeignKey, cn as AtscriptQueryNode, ft as TDerivedColumn, gt as TExistingTableOption, k as TColumnDiff, mt as TExistingColumn, rt as TDbStorageType, sn as AtscriptQueryFieldRef, yn as AtscriptDbReadable } from "./buckets-DJiYlMXc.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/schema/schema-hash.d.ts
|
|
4
4
|
interface TFieldSnapshot {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $t as AtscriptDbView, B as TDbDefaultValue, H as TDbFieldMeta, U as TDbForeignKey, cn as AtscriptQueryNode, ft as TDerivedColumn, gt as TExistingTableOption, k as TColumnDiff, mt as TExistingColumn, rt as TDbStorageType, sn as AtscriptQueryFieldRef, yn as AtscriptDbReadable } from "./buckets-CNdTOnei.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/schema/schema-hash.d.ts
|
|
4
4
|
interface TFieldSnapshot {
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_db_error = require("./db-error-
|
|
3
|
-
const require_column_diff = require("./column-diff-
|
|
4
|
-
const require_aggregate_fns = require("./aggregate-fns-
|
|
5
|
-
const require_nested_writer = require("./nested-writer-
|
|
2
|
+
const require_db_error = require("./db-error-DRQH4sLY.cjs");
|
|
3
|
+
const require_column_diff = require("./column-diff-CUU4GvYg.cjs");
|
|
4
|
+
const require_aggregate_fns = require("./aggregate-fns-C-UJRobm.cjs");
|
|
5
|
+
const require_nested_writer = require("./nested-writer-BUQvk6QT.cjs");
|
|
6
6
|
const require_derived_rules = require("./derived-rules-YstgIxG-.cjs");
|
|
7
7
|
const require_object = require("./object-Djg28csK.cjs");
|
|
8
8
|
const require_consts = require("./consts-BzRfCcH2.cjs");
|
|
9
9
|
const require_ops = require("./ops.cjs");
|
|
10
|
-
const require_validator = require("./validator-
|
|
10
|
+
const require_validator = require("./validator-UcuJxHNT.cjs");
|
|
11
11
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
12
12
|
let _uniqu_core = require("@uniqu/core");
|
|
13
13
|
let node_crypto = require("node:crypto");
|
|
@@ -236,8 +236,14 @@ var DbSpace = class {
|
|
|
236
236
|
_readables = /* @__PURE__ */ new WeakMap();
|
|
237
237
|
/** All tables created in this space — used for reverse FK lookup during cascade. */
|
|
238
238
|
_allTables = /* @__PURE__ */ new Set();
|
|
239
|
+
/** Every table / view handle the space created — flagged closed on {@link close}. */
|
|
240
|
+
_handles = /* @__PURE__ */ new Set();
|
|
239
241
|
/** Lazily created adapter for administrative ops (drop table/view) that don't need a registered readable. */
|
|
240
242
|
_adminAdapter;
|
|
243
|
+
/** Every adapter this space created (tables, views, admin) — disposed on close. */
|
|
244
|
+
_adapters = /* @__PURE__ */ new Set();
|
|
245
|
+
_onClose;
|
|
246
|
+
_closing;
|
|
241
247
|
logger;
|
|
242
248
|
/** Encryption service for `@db.encrypted` fields — validated eagerly at construction. */
|
|
243
249
|
_encryption;
|
|
@@ -252,6 +258,7 @@ var DbSpace = class {
|
|
|
252
258
|
else {
|
|
253
259
|
const options = loggerOrOptions ?? {};
|
|
254
260
|
this.logger = options.logger ?? require_column_diff.NoopLogger;
|
|
261
|
+
this._onClose = options.onClose;
|
|
255
262
|
if (options.encryption) this._encryption = new DbEncryption(options.encryption);
|
|
256
263
|
}
|
|
257
264
|
}
|
|
@@ -260,6 +267,7 @@ var DbSpace = class {
|
|
|
260
267
|
* appropriate instance. Uses `@db.view` or `@db.view.for` presence to distinguish.
|
|
261
268
|
*/
|
|
262
269
|
get(type, logger) {
|
|
270
|
+
this._assertOpen();
|
|
263
271
|
if (require_column_diff.isViewType(type)) return this.getView(type, logger);
|
|
264
272
|
return this.getTable(type, logger);
|
|
265
273
|
}
|
|
@@ -268,6 +276,7 @@ var DbSpace = class {
|
|
|
268
276
|
* Creates the table + adapter on first access, caches for subsequent calls.
|
|
269
277
|
*/
|
|
270
278
|
getTable(type, logger) {
|
|
279
|
+
this._assertOpen();
|
|
271
280
|
let readable = this._readables.get(type);
|
|
272
281
|
if (!readable) {
|
|
273
282
|
assertNotAlias(type);
|
|
@@ -280,6 +289,7 @@ var DbSpace = class {
|
|
|
280
289
|
readable.setFkLookupResolver((tableName) => this._getFkLookupTarget(tableName));
|
|
281
290
|
readable.setEncryption(this._encryption);
|
|
282
291
|
this._readables.set(type, readable);
|
|
292
|
+
this._handles.add(readable);
|
|
283
293
|
}
|
|
284
294
|
return readable;
|
|
285
295
|
}
|
|
@@ -288,12 +298,14 @@ var DbSpace = class {
|
|
|
288
298
|
* Creates the view + adapter on first access, caches for subsequent calls.
|
|
289
299
|
*/
|
|
290
300
|
getView(type, logger) {
|
|
301
|
+
this._assertOpen();
|
|
291
302
|
let readable = this._readables.get(type);
|
|
292
303
|
if (!readable) {
|
|
293
304
|
assertNotAlias(type);
|
|
294
305
|
readable = new require_column_diff.AtscriptDbView(type, this._createAdapter(), logger || this.logger, (t) => this.get(t));
|
|
295
306
|
readable.setEncryption(this._encryption);
|
|
296
307
|
this._readables.set(type, readable);
|
|
308
|
+
this._handles.add(readable);
|
|
297
309
|
}
|
|
298
310
|
return readable;
|
|
299
311
|
}
|
|
@@ -302,6 +314,7 @@ var DbSpace = class {
|
|
|
302
314
|
* Creates the table/view + adapter on first access if needed.
|
|
303
315
|
*/
|
|
304
316
|
getAdapter(type) {
|
|
317
|
+
this._assertOpen();
|
|
305
318
|
return this.get(type).dbAdapter;
|
|
306
319
|
}
|
|
307
320
|
/**
|
|
@@ -309,6 +322,7 @@ var DbSpace = class {
|
|
|
309
322
|
* See `BaseDbAdapter.dropTableByName` for an adapter that does not support it.
|
|
310
323
|
*/
|
|
311
324
|
async dropTableByName(tableName) {
|
|
325
|
+
this._assertOpen();
|
|
312
326
|
await this._getAdminAdapter().dropTableByName(tableName);
|
|
313
327
|
}
|
|
314
328
|
/**
|
|
@@ -316,6 +330,7 @@ var DbSpace = class {
|
|
|
316
330
|
* See `BaseDbAdapter.dropViewByName` for an adapter that does not support it.
|
|
317
331
|
*/
|
|
318
332
|
async dropViewByName(viewName) {
|
|
333
|
+
this._assertOpen();
|
|
319
334
|
await this._getAdminAdapter().dropViewByName(viewName);
|
|
320
335
|
}
|
|
321
336
|
/**
|
|
@@ -324,6 +339,7 @@ var DbSpace = class {
|
|
|
324
339
|
* @since 0.1.128
|
|
325
340
|
*/
|
|
326
341
|
async dropTablesByName(tableNames) {
|
|
342
|
+
this._assertOpen();
|
|
327
343
|
await this._getAdminAdapter().dropTablesByName(tableNames);
|
|
328
344
|
}
|
|
329
345
|
/**
|
|
@@ -333,6 +349,7 @@ var DbSpace = class {
|
|
|
333
349
|
* @since 0.1.128
|
|
334
350
|
*/
|
|
335
351
|
async getReferencingForeignKeys(tableName) {
|
|
352
|
+
this._assertOpen();
|
|
336
353
|
return this._getAdminAdapter().getReferencingForeignKeys?.(tableName);
|
|
337
354
|
}
|
|
338
355
|
/**
|
|
@@ -351,8 +368,46 @@ var DbSpace = class {
|
|
|
351
368
|
_createAdapter() {
|
|
352
369
|
const adapter = this.adapterFactory();
|
|
353
370
|
adapter.registerSpace?.(this);
|
|
371
|
+
this._adapters.add(adapter);
|
|
354
372
|
return adapter;
|
|
355
373
|
}
|
|
374
|
+
/** `true` once {@link close} was called. @since 0.1.148 */
|
|
375
|
+
get closed() {
|
|
376
|
+
return this._closing !== void 0;
|
|
377
|
+
}
|
|
378
|
+
/** Throws `SPACE_CLOSED` once the space is closed. */
|
|
379
|
+
_assertOpen() {
|
|
380
|
+
if (this._closing) throw require_db_error.spaceClosedError();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Closes the space: marks it closed, disposes every adapter it created, then
|
|
384
|
+
* runs the `onClose` hook (the `createAdapter` helpers close their driver
|
|
385
|
+
* there). Idempotent — every call returns the first call's promise. Every
|
|
386
|
+
* step is attempted; failures are collected into an `AggregateError`.
|
|
387
|
+
*
|
|
388
|
+
* It does not cancel or drain in-flight queries: call it after the server
|
|
389
|
+
* stopped accepting requests. After close, `get*` and operations on existing
|
|
390
|
+
* table/view handles throw `DbError("SPACE_CLOSED")`.
|
|
391
|
+
* @since 0.1.148
|
|
392
|
+
*/
|
|
393
|
+
close() {
|
|
394
|
+
return this._closing ??= this._doClose();
|
|
395
|
+
}
|
|
396
|
+
async _doClose() {
|
|
397
|
+
for (const readable of this._handles) readable._spaceClosed = true;
|
|
398
|
+
const errors = [];
|
|
399
|
+
for (const adapter of this._adapters) try {
|
|
400
|
+
await adapter.dispose?.();
|
|
401
|
+
} catch (error) {
|
|
402
|
+
errors.push(error);
|
|
403
|
+
}
|
|
404
|
+
try {
|
|
405
|
+
await this._onClose?.();
|
|
406
|
+
} catch (error) {
|
|
407
|
+
errors.push(error);
|
|
408
|
+
}
|
|
409
|
+
if (errors.length > 0) throw require_db_error.aggregateFailure("DbSpace close failed", errors);
|
|
410
|
+
}
|
|
356
411
|
/**
|
|
357
412
|
* Finds all child tables with FKs pointing to the given parent table name.
|
|
358
413
|
* Accesses `table.foreignKeys` which triggers `_flatten()` if needed.
|
|
@@ -376,6 +431,9 @@ var DbSpace = class {
|
|
|
376
431
|
for (const table of this._allTables) if (table.tableName === tableName) return { count: (filter) => table.count({ filter }) };
|
|
377
432
|
}
|
|
378
433
|
};
|
|
434
|
+
if (typeof Symbol.asyncDispose === "symbol") DbSpace.prototype[Symbol.asyncDispose] = function() {
|
|
435
|
+
return this.close();
|
|
436
|
+
};
|
|
379
437
|
//#endregion
|
|
380
438
|
//#region src/table/db-entity.ts
|
|
381
439
|
/**
|
|
@@ -438,6 +496,8 @@ exports.ResolvedRelationFilter = require_nested_writer.ResolvedRelationFilter;
|
|
|
438
496
|
exports.TableMetadata = require_column_diff.TableMetadata;
|
|
439
497
|
exports.UniquSelect = require_column_diff.UniquSelect;
|
|
440
498
|
exports.acceptedOperatorsHint = require_column_diff.acceptedOperatorsHint;
|
|
499
|
+
exports.aggregateExpressionsNotSupported = require_db_error.aggregateExpressionsNotSupported;
|
|
500
|
+
exports.aggregateFailure = require_db_error.aggregateFailure;
|
|
441
501
|
exports.aliasTargetOf = require_column_diff.aliasTargetOf;
|
|
442
502
|
exports.andFilters = require_nested_writer.andFilters;
|
|
443
503
|
exports.assertGeoPoint = require_column_diff.assertGeoPoint;
|
|
@@ -461,6 +521,7 @@ exports.createDbValidatorPlugin = require_validator.createDbValidatorPlugin;
|
|
|
461
521
|
exports.createFailureCollector = require_column_diff.createFailureCollector;
|
|
462
522
|
exports.decomposePatch = require_column_diff.decomposePatch;
|
|
463
523
|
exports.deletePath = require_object.deletePath;
|
|
524
|
+
exports.evaluateExpr = require_nested_writer.evaluateExpr;
|
|
464
525
|
exports.findAncestorInSet = require_object.findAncestorInSet;
|
|
465
526
|
exports.fkColumns = require_column_diff.fkColumns;
|
|
466
527
|
exports.forEachResolvedRelation = require_nested_writer.forEachResolvedRelation;
|
|
@@ -469,6 +530,7 @@ exports.geoIndexNotFoundMessage = require_column_diff.geoIndexNotFoundMessage;
|
|
|
469
530
|
exports.getDbFieldOp = require_ops.getDbFieldOp;
|
|
470
531
|
exports.getKeyProps = require_validator.getKeyProps;
|
|
471
532
|
exports.getPath = require_object.getPath;
|
|
533
|
+
exports.groupSourceVerdict = require_column_diff.groupSourceVerdict;
|
|
472
534
|
exports.guardAggregate = require_column_diff.guardAggregate;
|
|
473
535
|
exports.guardFilter = require_column_diff.guardFilter;
|
|
474
536
|
exports.guardPath = require_column_diff.guardPath;
|
|
@@ -478,6 +540,7 @@ exports.hasRelationOp = require_nested_writer.hasRelationOp;
|
|
|
478
540
|
exports.isAtscriptDbView = require_column_diff.isAtscriptDbView;
|
|
479
541
|
exports.isBucketableField = require_column_diff.isBucketableField;
|
|
480
542
|
exports.isColumnTypeChanged = require_column_diff.isColumnTypeChanged;
|
|
543
|
+
exports.isConflict = require_db_error.isConflict;
|
|
481
544
|
exports.isDbEntityType = isDbEntityType;
|
|
482
545
|
exports.isDbFieldOp = require_ops.isDbFieldOp;
|
|
483
546
|
exports.isEmptyObject = require_object.isEmptyObject;
|
|
@@ -504,6 +567,7 @@ exports.isViewType = require_column_diff.isViewType;
|
|
|
504
567
|
exports.jsonValueAncestor = require_column_diff.jsonValueAncestor;
|
|
505
568
|
exports.narrowerFilterOps = require_column_diff.narrowerFilterOps;
|
|
506
569
|
exports.normalizeComputedSelect = require_column_diff.normalizeComputedSelect;
|
|
570
|
+
exports.numericOperandProblem = require_column_diff.numericOperandProblem;
|
|
507
571
|
exports.reconcileCas = require_ops.reconcileCas;
|
|
508
572
|
exports.relationStaticFilter = require_nested_writer.relationStaticFilter;
|
|
509
573
|
exports.resolveCalendarBuckets = require_column_diff.resolveCalendarBuckets;
|
|
@@ -515,6 +579,7 @@ exports.separateFieldOps = require_ops.separateFieldOps;
|
|
|
515
579
|
exports.sortFieldNames = require_column_diff.sortFieldNames;
|
|
516
580
|
exports.tableNameOf = require_nested_writer.tableNameOf;
|
|
517
581
|
exports.translateQueryTree = require_nested_writer.translateQueryTree;
|
|
582
|
+
exports.uniqueKeyTuple = require_nested_writer.uniqueKeyTuple;
|
|
518
583
|
exports.unsupportedOperatorMessage = require_column_diff.unsupportedOperatorMessage;
|
|
519
584
|
exports.vectorIndexNotFoundMessage = require_column_diff.vectorIndexNotFoundMessage;
|
|
520
585
|
Object.defineProperty(exports, "walkFilter", {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TDbReferentialAction, $t as AtscriptDbView, A as TCrudOp, An as containsRelationFilter, At as TSearchIndexInfo, B as TDbDefaultValue, Bn as NoopLogger, Bt as Uniquery, C as NavPropsOf, Cn as REL_FILTER_MAX_NODES, Ct as TInsertOptions, D as TCascadeResolver, Dn as TRelationFilterTable, Dt as TReferencingForeignKey, E as PrimaryKeyOf, En as TRelationFilterJunction, Et as TPrimaryKeyChange, F as TDbActionProcessor, Fn as DbEncryption, Ft as TValueFormatterPair, G as TDbIndexField, Gn as UniquSelect, Gt as isGeoPointType, H as TDbFieldMeta, Hn as TExprAggregate, Ht as WithRelation, I as TDbActionTargetSummary, In as TDbEncryptionOptions, It as TViewJsonType, J as TDbInsertIgnoreSlot, Jt as BaseDbAdapter, K as TDbIndexType, Kt as ALL_BUCKET_UNITS, L as TDbAvailableActions, Ln as DocumentFieldMapper, Lt as TWriteOptions, M as TDbActionInfo, Mn as hasRelationOp, Mt as TTableOptionDiff, N as TDbActionIntent, Nn as isResolvedRelationFilter, Nt as TTableResolver, O as TCascadeTarget, On as TRelationStaticFilter, Ot as TRelationInfo, P as TDbActionLevel, Pn as relationStaticFilter, Pt as TTouchManyOptions, Q as TDbObjectKind, Qt as TDbSpaceOptions, R as TDbCollation, Rn as FieldMappingStrategy, Rt as TWriteTableResolver, S as FlatOf, Sn as REL_FILTER_MAX_DEPTH, St as TIdentification, T as OwnPropsOf, Tn as TRelGuardState, Tt as TMetadataOverrides, U as TDbForeignKey, Un as TFirstLast, Ut as TableMetadata, V as TDbDeleteResult, Vn as TGenericLogger, Vt as UniqueryControls, W as TDbIndex, Wn as TRowOrderKey, Wt as isGeoIndexableType, X as TDbInsertManyResult, Xt as DbSpace, Y as TDbInsertManyIgnoreResult, Yt as TViewCapability, Z as TDbInsertResult, Zt as TAdapterFactory, _ as DbPatch, _n as NativeIntegrity, _t as TFieldMeta, a as isJsonValueField, an as AtscriptOrderItem, at as TDbWriteAction, b as FieldOpsFor, bn as DbResponse, bt as TIdDescriptor, c as resolveCalendarBuckets, cn as AtscriptQueryNode, ct as TDbWriteGuard, d as AggregateFn, dn as TViewPlan, dt as TDerivedChangeReason, en as TViewColumnMapping, et as TDbRelation, f as AggregateQuery, fn as evaluateExpr, ft as TDerivedColumn, g as DbControls, gn as IntegrityStrategy, gt as TExistingTableOption, h as AtscriptDbWritable, hn as AtscriptDbTable, ht as TExistingForeignKey, i as isBucketableField, in as AtscriptExprNode, it as TDbUpdateResult, j as TCrudPermissions, jn as forEachResolvedRelation, jt as TSyncColumnResult, k as TColumnDiff, kn as andFilters, kt as TRowResolveOptions, l as AggregateControls, ln as AtscriptRef, lt as TDbWriteGuardContext, mn as translateQueryTree, mt as TExistingColumn, n as TComputedSelect, nn as isViewType, nt as TDbRemoveGuardContext, o as jsonValueAncestor, on as AtscriptQueryComparison, ot as TDbWriteCheck, p as AggregateResult, pn as isFieldRef, pt as TEnsureTableOptions, q as TDbInsertIgnoreResult, qt as ALL_VIEW_CAPABILITIES, r as TResolvedBucket, rn as aliasTargetOf, rt as TDbStorageType, s as normalizeComputedSelect, sn as AtscriptQueryFieldRef, st as TDbWriteCheckContext, t as TBucketFieldSource, tn as isAtscriptDbView, tt as TDbRemoveGuard, u as AggregateExpr, un as TViewJoin, ut as TDeleteOptions, v as DbQuery, vn as TCascadePin, vt as TFkLookupResolver, w as NullableOptional, wn as ResolvedRelationFilter, wt as TMetaResponse, x as FilterExpr, xn as resolveDesignType, xt as TIdResolveOptions, y as DbRow, yn as AtscriptDbReadable, yt as TFkLookupTarget, z as TDbDefaultFn, zn as TReadControls, zt as TypedWithRelation } from "./buckets-DJiYlMXc.cjs";
|
|
2
2
|
import { _ as separateFieldOps, a as $mul, c as $update, d as TDbFieldOp, f as TFieldOps, g as separateCas, h as reconcileCas, i as $insert, l as $upsert, m as isDbFieldOp, n as $dec, o as $remove, p as getDbFieldOp, r as $inc, s as $replace, t as $cas, u as TDbCas } from "./ops-AqhV7s9o.cjs";
|
|
3
3
|
import { a as isPlainObject, i as isEmptyObject, n as findAncestorInSet, o as selfOrAncestor, r as getPath, t as deletePath } from "./object-CtPYTIvy.cjs";
|
|
4
|
-
import { c as CalendarBucketLabel, d as WeekStart, g as ALL_AGGREGATE_FNS, l as ComputedExpr, o as BucketExpr, s as BucketUnit, u as ResolvedBucket } from "./agg-
|
|
5
|
-
import { a as buildValidationContext, c as isNavRelation, d as getKeyProps, f as CasExhaustedError, g as
|
|
4
|
+
import { c as CalendarBucketLabel, d as WeekStart, g as ALL_AGGREGATE_FNS, l as ComputedExpr, o as BucketExpr, s as BucketUnit, u as ResolvedBucket } from "./agg-42CSpGDR.cjs";
|
|
5
|
+
import { _ as aggregateFailure, a as buildValidationContext, c as isNavRelation, d as getKeyProps, f as CasExhaustedError, g as aggregateExpressionsNotSupported, h as DbErrorCode, l as TArrayPatch, m as DbError, n as ValidatorMode, p as CasMismatchError, r as buildDbValidator, s as forceNavNonOptional, t as ValidationContext, u as TDbPatch, v as bucketTimeZoneUnavailable, y as isConflict } from "./validator-tBNvM1qc.cjs";
|
|
6
6
|
import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
|
|
7
|
-
import { r as fkColumns, s as isColumnTypeChanged } from "./fk-diff-
|
|
8
|
-
import { i as tableNameOf } from "./relation-helpers-
|
|
9
|
-
import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, RELATION_OPS, RelationOp, RelationOp as RelationOp$1,
|
|
10
|
-
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
7
|
+
import { r as fkColumns, s as isColumnTypeChanged } from "./fk-diff-BQ4krij8.cjs";
|
|
8
|
+
import { i as tableNameOf } from "./relation-helpers-kX7jjgME.cjs";
|
|
9
|
+
import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, RELATION_OPS, RelationOp, RelationOp as RelationOp$1, ResolvedRowOrderKey, ResolvedSelectExpr, Uniquery as Uniquery$1, computeInsights, isPrimitive, isRelationOp, walkFilter } from "@uniqu/core";
|
|
10
|
+
import { AtscriptExprNode as AtscriptExprNode$1, TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
11
11
|
|
|
12
12
|
//#region src/shared/consts.d.ts
|
|
13
13
|
/**
|
|
@@ -149,6 +149,7 @@ interface TGuardedQuery {
|
|
|
149
149
|
$select?: unknown;
|
|
150
150
|
$groupBy?: unknown;
|
|
151
151
|
$having?: unknown;
|
|
152
|
+
$rowOrder?: unknown;
|
|
152
153
|
};
|
|
153
154
|
}
|
|
154
155
|
/**
|
|
@@ -244,6 +245,28 @@ type TBucketSourceVerdict = {
|
|
|
244
245
|
code: "encrypted" | "jsonDescendant" | "notTimestamp" | "notFilterable" | "notDimension" | "noBuckets";
|
|
245
246
|
reason: string;
|
|
246
247
|
};
|
|
248
|
+
/** {@link groupSourceVerdict}'s answer — the `reason` clause has no trailing period. */
|
|
249
|
+
type TGroupSourceVerdict = {
|
|
250
|
+
ok: true;
|
|
251
|
+
} | {
|
|
252
|
+
ok: false;
|
|
253
|
+
code: "encrypted" | "notFilterable" | "notDimension";
|
|
254
|
+
reason: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Whether the stored leaf `fd` may be a `$groupBy` key (since 0.1.148) — the
|
|
258
|
+
* one rule for the core's strict-table check and moost-db's capability index
|
|
259
|
+
* (`/meta.fields[P].groupable` and the HTTP gate). First failing rule wins:
|
|
260
|
+
*
|
|
261
|
+
* 1. `encrypted` — `@db.encrypted`;
|
|
262
|
+
* 2. `notFilterable` — the adapter cannot filter (so cannot group) the storage;
|
|
263
|
+
* 3. `notDimension` — a strict table ({@link isStrictTable}) and the field is
|
|
264
|
+
* not a dimension.
|
|
265
|
+
*
|
|
266
|
+
* A calendar-bucket alias is not a field: it groups by its source, whose
|
|
267
|
+
* dimension rule is {@link bucketSourceVerdict}'s (callers skip aliases).
|
|
268
|
+
*/
|
|
269
|
+
declare function groupSourceVerdict(fd: TDbFieldMeta, table: Pick<TBucketSourceTable, "dimensions" | "measures">, adapter: Pick<BaseDbAdapter, "canFilterField">): TGroupSourceVerdict;
|
|
247
270
|
/**
|
|
248
271
|
* Whether the stored leaf `fd` may be the source of a calendar bucket
|
|
249
272
|
* (since 0.1.133) — every schema and adapter rule, once, for the core path
|
|
@@ -302,8 +325,9 @@ interface TQueryPathRefs {
|
|
|
302
325
|
*
|
|
303
326
|
* Aggregate mode is `aggregate` when given, else the presence of `$groupBy`.
|
|
304
327
|
* In aggregate mode `$select` computed entries are collected by kind — an
|
|
305
|
-
* aggregate's `$field`
|
|
306
|
-
*
|
|
328
|
+
* aggregate's `$field` (a row-level expression's names, a `first` / `last`
|
|
329
|
+
* field) into `aggregate`, a calendar bucket's into `bucket`, a `$rowOrder`
|
|
330
|
+
* key into `sort` — and their aliases (`$as`, else uniqu's `resolveAlias`) are exempted from
|
|
307
331
|
* `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
|
|
308
332
|
* lists grouped fields only.
|
|
309
333
|
*
|
|
@@ -414,10 +438,11 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
|
|
|
414
438
|
* ({@link checkHavingKeys} — after the path guard so an unknown key still
|
|
415
439
|
* reads `Unknown field`), then the `$having` values (`guardHavingValues`).
|
|
416
440
|
*
|
|
417
|
-
* `
|
|
418
|
-
*
|
|
441
|
+
* `resolved` is the query's normalized computed `$select`
|
|
442
|
+
* (`resolveComputedSelect`) when the caller already ran it (resolved here
|
|
443
|
+
* otherwise).
|
|
419
444
|
*/
|
|
420
|
-
declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?:
|
|
445
|
+
declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: TComputedSelect): void;
|
|
421
446
|
//#endregion
|
|
422
447
|
//#region src/with-optimistic-retry.d.ts
|
|
423
448
|
interface WithOptimisticRetryOptions {
|
|
@@ -458,6 +483,14 @@ interface WithOptimisticRetryOptions {
|
|
|
458
483
|
*/
|
|
459
484
|
declare function withOptimisticRetry<TRow extends Record<string, unknown>>(table: AtscriptDbTable, filter: Record<string, unknown>, mutator: (row: TRow) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined, opts?: WithOptimisticRetryOptions): Promise<TDbUpdateResult>;
|
|
460
485
|
//#endregion
|
|
486
|
+
//#region src/shared/keys.d.ts
|
|
487
|
+
/**
|
|
488
|
+
* Identity of the key tuple `fields` of `row` for uniqueness checks, or
|
|
489
|
+
* `undefined` when any component is null / missing (a NULL never collides).
|
|
490
|
+
* Equal across driver representations (see {@link keyString}).
|
|
491
|
+
*/
|
|
492
|
+
declare function uniqueKeyTuple(row: Record<string, unknown>, fields: readonly string[]): string | undefined;
|
|
493
|
+
//#endregion
|
|
461
494
|
//#region src/shared/index-messages.d.ts
|
|
462
495
|
/**
|
|
463
496
|
* Wording of the "index not found" errors — one source for the core, every
|
|
@@ -556,4 +589,16 @@ declare function createFailureCollector(what: string): {
|
|
|
556
589
|
throwIfAny: () => void;
|
|
557
590
|
};
|
|
558
591
|
//#endregion
|
|
559
|
-
|
|
592
|
+
//#region src/query/aggregate-expr.d.ts
|
|
593
|
+
/**
|
|
594
|
+
* Why a field cannot be an arithmetic operand, or `undefined` when it can: it
|
|
595
|
+
* must be a `number` (not a decimal — those are exact, an expression is IEEE
|
|
596
|
+
* double — and not a timestamp-tagged number) with plain column storage. The
|
|
597
|
+
* runtime twin of `@db.compute`'s operand rule, so declared and query-time
|
|
598
|
+
* arithmetic accept the same fields.
|
|
599
|
+
*
|
|
600
|
+
* @since 0.1.148
|
|
601
|
+
*/
|
|
602
|
+
declare function numericOperandProblem(fd: TDbFieldMeta): string | undefined;
|
|
603
|
+
//#endregion
|
|
604
|
+
export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, type AtscriptExprNode, type AtscriptOrderItem, type AtscriptQueryComparison, type AtscriptQueryFieldRef, type AtscriptQueryNode, type AtscriptRef, BaseDbAdapter, type BucketExpr, type BucketUnit, type CalendarBucketLabel, CasExhaustedError, CasMismatchError, type ComputedExpr, DEFAULT_DB_SPACE, type DbControls, DbEncryption, DbError, type DbErrorCode, type DbPatch, type DbQuery, type DbResponse, type DbRow, DbSpace, type DbValidationContext, DocumentFieldMapper, ENCRYPTED_REASON, FieldMappingStrategy, type FieldOpsFor, type FilterExpr, type FilterVisitor, type FlatOf, IntegrityStrategy, NativeIntegrity, type NavPropsOf, NoopLogger, type NullableOptional, type OwnPropsOf, type PrimaryKeyOf, RELATION_OPS, REL_FILTER_MAX_DEPTH, REL_FILTER_MAX_NODES, type RelationOp, RelationalFieldMapper, type ResolvedBucket, ResolvedRelationFilter, type TAdapterFactory, type TArrayPatch, type TBucketFieldSource, type TBucketSourceTable, type TBucketSourceVerdict, type TCascadeResolver, type TCascadeTarget, type TColumnDiff, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbActionTargetSummary, type TDbAvailableActions, type TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, type TDbInsertIgnoreResult, type TDbInsertIgnoreSlot, type TDbInsertManyIgnoreResult, type TDbInsertManyResult, type TDbInsertResult, type TDbObjectKind, type TDbPatch, type TDbReferentialAction, type TDbRelation, type TDbRemoveGuard, type TDbRemoveGuardContext, type TDbSpaceOptions, type TDbStorageType, type TDbUpdateResult, type TDbWriteAction, type TDbWriteCheck, type TDbWriteCheckContext, type TDbWriteGuard, type TDbWriteGuardContext, type TDeleteOptions, type TDerivedChangeReason, type TDerivedColumn, type TEnsureTableOptions, type TExistingColumn, type TExistingForeignKey, type TExistingTableOption, type TExprAggregate, type TFieldMeta, type TFieldOps, type TFilterPredicate, type TFilterRef, type TFirstLast, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGroupSourceVerdict, type TGuardedQuery, type TIdDescriptor, type TIdResolveOptions, type TIdentification, type TInsertOptions, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReadControls, type TReferencingForeignKey, type TRelationFilterJunction, type TRelationFilterTable, type TRelationInfo, type TRelationStaticFilter, type TResolvedBucket, type TRowOrderKey, type TRowResolveOptions, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TTouchManyOptions, type TValueFormatterPair, type TViewCapability, type TViewColumnMapping, type TViewJoin, type TViewJsonType, type TViewPlan, type TWriteOptions, type TWriteTableResolver, TableMetadata, type TypedWithRelation, UniquSelect, type Uniquery, type UniqueryControls, type ValidationContext, type ValidatorMode, type WeekStart, type WithOptimisticRetryOptions, type WithRelation, acceptedOperatorsHint, aggregateExpressionsNotSupported, aggregateFailure, aliasTargetOf, andFilters, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, containsRelationFilter, createDbValidatorPlugin, createFailureCollector, decomposePatch, deletePath, evaluateExpr, findAncestorInSet, fkColumns, forEachResolvedRelation, forceNavNonOptional, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, groupSourceVerdict, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, hasRelationOp, isAtscriptDbView, isBucketableField, isColumnTypeChanged, isConflict, isDbEntityType, isDbFieldOp, isEmptyObject, isFieldRef, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, isRelationOp, isResolvedRelationFilter, isViewType, jsonValueAncestor, narrowerFilterOps, normalizeComputedSelect, numericOperandProblem, reconcileCas, relationStaticFilter, resolveCalendarBuckets, resolveDesignType, searchIndexNotFoundMessage, selfOrAncestor, separateCas, separateFieldOps, sortFieldNames, tableNameOf, translateQueryTree, uniqueKeyTuple, unsupportedOperatorMessage, vectorIndexNotFoundMessage, walkFilter, withOptimisticRetry };
|