@atscript/db 0.1.135 → 0.1.137

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.
Files changed (49) hide show
  1. package/dist/{agg-DKuf_v2L.d.cts → agg-CV7y8nC6.d.cts} +13 -3
  2. package/dist/{agg-BtlGeRfj.d.mts → agg-D5DHsAby.d.mts} +13 -3
  3. package/dist/agg.cjs +35 -3
  4. package/dist/agg.d.cts +2 -2
  5. package/dist/agg.d.mts +2 -2
  6. package/dist/agg.mjs +34 -1
  7. package/dist/aggregate-fns-CGBv3E8S.cjs +87 -0
  8. package/dist/aggregate-fns-CfsveE1w.mjs +58 -0
  9. package/dist/{buckets-GruoVxH5.d.mts → buckets-BFG2RYRW.d.mts} +662 -31
  10. package/dist/{buckets-D6PBXKRJ.d.cts → buckets-C-27xmtq.d.cts} +662 -31
  11. package/dist/column-diff-BmqvgBWw.d.cts +24 -0
  12. package/dist/{db-view-Doh8vPg3.mjs → column-diff-BwOA5101.mjs} +795 -125
  13. package/dist/{db-view-Dm7MpUGB.cjs → column-diff-CgxgFKzx.cjs} +873 -125
  14. package/dist/column-diff-DPkbZIVE.d.mts +24 -0
  15. package/dist/index.cjs +79 -55
  16. package/dist/index.d.cts +12 -10
  17. package/dist/index.d.mts +12 -10
  18. package/dist/index.mjs +30 -11
  19. package/dist/{nested-writer-wk1EFUNY.cjs → nested-writer-BZNCuqI6.cjs} +16 -2
  20. package/dist/{nested-writer-CqL24ojl.mjs → nested-writer-FWD5oOYh.mjs} +11 -3
  21. package/dist/plugin.cjs +217 -77
  22. package/dist/plugin.mjs +217 -78
  23. package/dist/rel.cjs +2 -2
  24. package/dist/rel.d.cts +2 -20
  25. package/dist/rel.d.mts +2 -20
  26. package/dist/rel.mjs +2 -2
  27. package/dist/relation-helpers-D3Zu0Mta.d.mts +30 -0
  28. package/dist/relation-helpers-DxrvS6ar.d.cts +30 -0
  29. package/dist/{relation-loader-BD4xANQJ.cjs → relation-loader-6ZB_5KFq.cjs} +1 -1
  30. package/dist/{relation-loader-B68R1LET.mjs → relation-loader-CTFaZpVa.mjs} +1 -1
  31. package/dist/shared.cjs +5 -1
  32. package/dist/shared.d.cts +16 -3
  33. package/dist/shared.d.mts +16 -3
  34. package/dist/shared.mjs +2 -2
  35. package/dist/sync.cjs +38 -321
  36. package/dist/sync.d.cts +29 -17
  37. package/dist/sync.d.mts +29 -17
  38. package/dist/sync.mjs +6 -289
  39. package/dist/{validation-utils-MWOP1Ts4.mjs → validation-utils-B4h-GW4d.mjs} +29 -7
  40. package/dist/{validation-utils-B7SXPkm7.cjs → validation-utils-Dg0hW6dn.cjs} +52 -6
  41. package/dist/{validator-CewfnGZj.d.mts → validator-Drb2N-YL.d.cts} +1 -1
  42. package/dist/{validator-CewfnGZj.d.cts → validator-Drb2N-YL.d.mts} +1 -1
  43. package/dist/validator.d.cts +1 -1
  44. package/dist/validator.d.mts +1 -1
  45. package/package.json +1 -1
  46. package/dist/agg-CvXDGnKi.mjs +0 -61
  47. package/dist/agg-EcIbAFnJ.cjs +0 -78
  48. package/dist/db-space-9CH5neN7.d.mts +0 -439
  49. package/dist/db-space-BdtBNTeH.d.cts +0 -439
@@ -0,0 +1,24 @@
1
+ import { D as TColumnDiff, R as TDbFieldMeta, rt as TExistingColumn } from "./buckets-BFG2RYRW.mjs";
2
+
3
+ //#region src/schema/column-diff.d.ts
4
+ /**
5
+ * Whether a live column's type differs from the type the adapter's
6
+ * `typeMapper` gives the field — the one rule schema sync diffs column types
7
+ * by (case-insensitive). Exported for adapters that must agree with it (the
8
+ * PostgreSQL recreate converts exactly the columns this reports changed).
9
+ * @since 0.1.137
10
+ */
11
+ declare function isColumnTypeChanged(existingType: string, expectedType: string): boolean;
12
+ /**
13
+ * Computes the difference between desired schema fields and existing database columns.
14
+ *
15
+ * @param desired - Field descriptors from the Atscript type (after flattening).
16
+ * @param existing - Columns currently in the database (from introspection).
17
+ * @param typeMapper - Optional function to map field metadata to DB-native type strings.
18
+ * Receives the full field meta (design type, annotations, PK status, etc.)
19
+ * so adapters can produce context-aware types (e.g., `VARCHAR(255)` from maxLength).
20
+ * Required for type change detection.
21
+ */
22
+ declare function computeColumnDiff(desired: readonly TDbFieldMeta[], existing: TExistingColumn[], typeMapper?: (field: TDbFieldMeta) => string): TColumnDiff;
23
+ //#endregion
24
+ export { isColumnTypeChanged as n, computeColumnDiff as t };
package/dist/index.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_db_error = require("./db-error-DTkkeu5b.cjs");
3
- const require_db_view = require("./db-view-Dm7MpUGB.cjs");
3
+ const require_column_diff = require("./column-diff-CgxgFKzx.cjs");
4
+ const require_aggregate_fns = require("./aggregate-fns-CGBv3E8S.cjs");
5
+ const require_nested_writer = require("./nested-writer-BZNCuqI6.cjs");
4
6
  const require_validator = require("./validator-BtZbcLN2.cjs");
5
7
  const require_consts = require("./consts-BzRfCcH2.cjs");
6
8
  const require_ops = require("./ops.cjs");
@@ -238,7 +240,7 @@ var DbSpace = class {
238
240
  if (loggerOrOptions && typeof loggerOrOptions.error === "function") this.logger = loggerOrOptions;
239
241
  else {
240
242
  const options = loggerOrOptions ?? {};
241
- this.logger = options.logger ?? require_db_view.NoopLogger;
243
+ this.logger = options.logger ?? require_column_diff.NoopLogger;
242
244
  if (options.encryption) this._encryption = new DbEncryption(options.encryption);
243
245
  }
244
246
  }
@@ -257,9 +259,9 @@ var DbSpace = class {
257
259
  getTable(type, logger) {
258
260
  let readable = this._readables.get(type);
259
261
  if (!readable) {
260
- readable = new require_db_view.AtscriptDbTable(type, this.adapterFactory(), logger || this.logger, (t) => this.get(t), (t) => {
262
+ readable = new require_column_diff.AtscriptDbTable(type, this._createAdapter(), logger || this.logger, (t) => this.get(t), (t) => {
261
263
  const resolved = this.get(t);
262
- return resolved instanceof require_db_view.AtscriptDbTable ? resolved : void 0;
264
+ return resolved instanceof require_column_diff.AtscriptDbTable ? resolved : void 0;
263
265
  });
264
266
  this._allTables.add(readable);
265
267
  readable.setCascadeResolver((tableName) => this._getCascadeTargets(tableName));
@@ -276,7 +278,7 @@ var DbSpace = class {
276
278
  getView(type, logger) {
277
279
  let readable = this._readables.get(type);
278
280
  if (!readable) {
279
- readable = new require_db_view.AtscriptDbView(type, this.adapterFactory(), logger || this.logger, (t) => this.get(t));
281
+ readable = new require_column_diff.AtscriptDbView(type, this._createAdapter(), logger || this.logger, (t) => this.get(t));
280
282
  readable.setEncryption(this._encryption);
281
283
  this._readables.set(type, readable);
282
284
  }
@@ -291,17 +293,17 @@ var DbSpace = class {
291
293
  }
292
294
  /**
293
295
  * Drops a table by name. Used by schema sync to remove tables no longer in the schema.
296
+ * See `BaseDbAdapter.dropTableByName` for an adapter that does not support it.
294
297
  */
295
298
  async dropTableByName(tableName) {
296
- const adapter = this._getAdminAdapter();
297
- if (adapter.dropTableByName) await adapter.dropTableByName(tableName);
299
+ await this._getAdminAdapter().dropTableByName(tableName);
298
300
  }
299
301
  /**
300
302
  * Drops a view by name. Used by schema sync to remove views no longer in the schema.
303
+ * See `BaseDbAdapter.dropViewByName` for an adapter that does not support it.
301
304
  */
302
305
  async dropViewByName(viewName) {
303
- const adapter = this._getAdminAdapter();
304
- if (adapter.dropViewByName) await adapter.dropViewByName(viewName);
306
+ await this._getAdminAdapter().dropViewByName(viewName);
305
307
  }
306
308
  /**
307
309
  * Drops a group of mutually referencing tables as one operation.
@@ -327,7 +329,16 @@ var DbSpace = class {
327
329
  * schema for those from the driver/connection, not from a bound table.
328
330
  */
329
331
  _getAdminAdapter() {
330
- return this._adminAdapter ??= this.adapterFactory();
332
+ return this._adminAdapter ??= this._createAdapter();
333
+ }
334
+ /**
335
+ * A factory-fresh adapter that knows its space (see `BaseDbAdapter.registerSpace`).
336
+ * Optional call: an adapter built against an older `@atscript/db` copy lacks it.
337
+ */
338
+ _createAdapter() {
339
+ const adapter = this.adapterFactory();
340
+ adapter.registerSpace?.(this);
341
+ return adapter;
331
342
  }
332
343
  /**
333
344
  * Finds all child tables with FKs pointing to the given parent table name.
@@ -355,6 +366,14 @@ var DbSpace = class {
355
366
  //#endregion
356
367
  //#region src/query/query-tree.ts
357
368
  /**
369
+ * `true` when a query-tree operand is a field reference (`{ field, type? }`)
370
+ * rather than a literal — e.g. the right side of a field-to-field comparison.
371
+ * @since 0.1.136
372
+ */
373
+ function isFieldRef(value) {
374
+ return value !== null && typeof value === "object" && "field" in value;
375
+ }
376
+ /**
358
377
  * Translates a JS-emitted query tree into a FilterExpr.
359
378
  * Resolves field references (type + field path) to physical column names
360
379
  * via the provided resolver function.
@@ -365,11 +384,11 @@ function translateQueryTree(node, resolveField) {
365
384
  if ("$not" in node) return { $not: translateQueryTree(node.$not, resolveField) };
366
385
  const comp = node;
367
386
  const leftField = resolveField(comp.left);
368
- if (comp.right && typeof comp.right === "object" && "field" in comp.right) {
387
+ if (isFieldRef(comp.right)) {
369
388
  const rightField = resolveField(comp.right);
370
389
  return { [leftField]: { [comp.op]: { $field: rightField } } };
371
390
  }
372
- if (comp.op === "$exists") return { [leftField]: { $exists: true } };
391
+ if (comp.op === "$exists") return { [leftField]: { $exists: comp.right !== false } };
373
392
  return { [leftField]: { [comp.op]: comp.right } };
374
393
  }
375
394
  //#endregion
@@ -382,39 +401,40 @@ exports.$remove = require_ops.$remove;
382
401
  exports.$replace = require_ops.$replace;
383
402
  exports.$update = require_ops.$update;
384
403
  exports.$upsert = require_ops.$upsert;
385
- exports.ADAPTER_FILTER_REASON = require_db_view.ADAPTER_FILTER_REASON;
386
- exports.ALL_BUCKET_UNITS = require_db_view.ALL_BUCKET_UNITS;
387
- exports.ApplicationIntegrity = require_db_view.ApplicationIntegrity;
388
- exports.AtscriptDbReadable = require_db_view.AtscriptDbReadable;
389
- exports.AtscriptDbTable = require_db_view.AtscriptDbTable;
390
- exports.AtscriptDbView = require_db_view.AtscriptDbView;
391
- exports.BaseDbAdapter = require_db_view.BaseDbAdapter;
404
+ exports.ADAPTER_FILTER_REASON = require_column_diff.ADAPTER_FILTER_REASON;
405
+ exports.ALL_AGGREGATE_FNS = require_aggregate_fns.ALL_AGGREGATE_FNS;
406
+ exports.ALL_BUCKET_UNITS = require_column_diff.ALL_BUCKET_UNITS;
407
+ exports.ApplicationIntegrity = require_column_diff.ApplicationIntegrity;
408
+ exports.AtscriptDbReadable = require_column_diff.AtscriptDbReadable;
409
+ exports.AtscriptDbTable = require_column_diff.AtscriptDbTable;
410
+ exports.AtscriptDbView = require_column_diff.AtscriptDbView;
411
+ exports.BaseDbAdapter = require_column_diff.BaseDbAdapter;
392
412
  exports.CasExhaustedError = require_db_error.CasExhaustedError;
393
413
  exports.CasMismatchError = require_db_error.CasMismatchError;
394
414
  exports.DEFAULT_DB_SPACE = require_consts.DEFAULT_DB_SPACE;
395
415
  exports.DbEncryption = DbEncryption;
396
416
  exports.DbError = require_db_error.DbError;
397
417
  exports.DbSpace = DbSpace;
398
- exports.DocumentFieldMapper = require_db_view.DocumentFieldMapper;
399
- exports.ENCRYPTED_REASON = require_db_view.ENCRYPTED_REASON;
400
- exports.FieldMappingStrategy = require_db_view.FieldMappingStrategy;
401
- exports.IntegrityStrategy = require_db_view.IntegrityStrategy;
402
- exports.NativeIntegrity = require_db_view.NativeIntegrity;
403
- exports.NoopLogger = require_db_view.NoopLogger;
404
- exports.RelationalFieldMapper = require_db_view.RelationalFieldMapper;
405
- exports.TableMetadata = require_db_view.TableMetadata;
406
- exports.UniquSelect = require_db_view.UniquSelect;
407
- exports.acceptedOperatorsHint = require_db_view.acceptedOperatorsHint;
408
- exports.assertGeoPoint = require_db_view.assertGeoPoint;
409
- exports.assertNoVersionWrites = require_db_view.assertNoVersionWrites;
410
- exports.bucketSourceVerdict = require_db_view.bucketSourceVerdict;
418
+ exports.DocumentFieldMapper = require_column_diff.DocumentFieldMapper;
419
+ exports.ENCRYPTED_REASON = require_column_diff.ENCRYPTED_REASON;
420
+ exports.FieldMappingStrategy = require_column_diff.FieldMappingStrategy;
421
+ exports.IntegrityStrategy = require_column_diff.IntegrityStrategy;
422
+ exports.NativeIntegrity = require_column_diff.NativeIntegrity;
423
+ exports.NoopLogger = require_column_diff.NoopLogger;
424
+ exports.RelationalFieldMapper = require_column_diff.RelationalFieldMapper;
425
+ exports.TableMetadata = require_column_diff.TableMetadata;
426
+ exports.UniquSelect = require_column_diff.UniquSelect;
427
+ exports.acceptedOperatorsHint = require_column_diff.acceptedOperatorsHint;
428
+ exports.assertGeoPoint = require_column_diff.assertGeoPoint;
429
+ exports.assertNoVersionWrites = require_column_diff.assertNoVersionWrites;
430
+ exports.bucketSourceVerdict = require_column_diff.bucketSourceVerdict;
411
431
  exports.bucketTimeZoneUnavailable = require_db_error.bucketTimeZoneUnavailable;
412
432
  exports.buildDbValidator = require_validator.buildDbValidator;
413
433
  exports.buildValidationContext = require_validator.buildValidationContext;
414
- exports.canFilterLeaf = require_db_view.canFilterLeaf;
415
- exports.checkHavingKeys = require_db_view.checkHavingKeys;
416
- exports.classifyQueryPath = require_db_view.classifyQueryPath;
417
- exports.collectQueryPaths = require_db_view.collectQueryPaths;
434
+ exports.canFilterLeaf = require_column_diff.canFilterLeaf;
435
+ exports.checkHavingKeys = require_column_diff.checkHavingKeys;
436
+ exports.classifyQueryPath = require_column_diff.classifyQueryPath;
437
+ exports.collectQueryPaths = require_column_diff.collectQueryPaths;
418
438
  Object.defineProperty(exports, "computeInsights", {
419
439
  enumerable: true,
420
440
  get: function() {
@@ -422,24 +442,26 @@ Object.defineProperty(exports, "computeInsights", {
422
442
  }
423
443
  });
424
444
  exports.createDbValidatorPlugin = require_validator.createDbValidatorPlugin;
425
- exports.createFailureCollector = require_db_view.createFailureCollector;
426
- exports.decomposePatch = require_db_view.decomposePatch;
427
- exports.findAncestorInSet = require_db_view.findAncestorInSet;
445
+ exports.createFailureCollector = require_column_diff.createFailureCollector;
446
+ exports.decomposePatch = require_column_diff.decomposePatch;
447
+ exports.findAncestorInSet = require_column_diff.findAncestorInSet;
428
448
  exports.forceNavNonOptional = require_validator.forceNavNonOptional;
429
449
  exports.getDbFieldOp = require_ops.getDbFieldOp;
430
450
  exports.getKeyProps = require_validator.getKeyProps;
431
- exports.guardAggregate = require_db_view.guardAggregate;
432
- exports.guardFilter = require_db_view.guardFilter;
433
- exports.guardPath = require_db_view.guardPath;
434
- exports.guardPaths = require_db_view.guardPaths;
435
- exports.guardQuery = require_db_view.guardQuery;
436
- exports.isAtscriptDbView = require_db_view.isAtscriptDbView;
437
- exports.isBucketableField = require_db_view.isBucketableField;
451
+ exports.guardAggregate = require_column_diff.guardAggregate;
452
+ exports.guardFilter = require_column_diff.guardFilter;
453
+ exports.guardPath = require_column_diff.guardPath;
454
+ exports.guardPaths = require_column_diff.guardPaths;
455
+ exports.guardQuery = require_column_diff.guardQuery;
456
+ exports.isAtscriptDbView = require_column_diff.isAtscriptDbView;
457
+ exports.isBucketableField = require_column_diff.isBucketableField;
458
+ exports.isColumnTypeChanged = require_column_diff.isColumnTypeChanged;
438
459
  exports.isDbFieldOp = require_ops.isDbFieldOp;
439
460
  exports.isEmptyObject = require_validator.isEmptyObject;
440
- exports.isGeoIndexableType = require_db_view.isGeoIndexableType;
441
- exports.isGeoPointType = require_db_view.isGeoPointType;
442
- exports.isJsonValueField = require_db_view.isJsonValueField;
461
+ exports.isFieldRef = isFieldRef;
462
+ exports.isGeoIndexableType = require_column_diff.isGeoIndexableType;
463
+ exports.isGeoPointType = require_column_diff.isGeoPointType;
464
+ exports.isJsonValueField = require_column_diff.isJsonValueField;
443
465
  exports.isNavRelation = require_validator.isNavRelation;
444
466
  exports.isPlainObject = require_validator.isPlainObject;
445
467
  Object.defineProperty(exports, "isPrimitive", {
@@ -448,16 +470,18 @@ Object.defineProperty(exports, "isPrimitive", {
448
470
  return _uniqu_core.isPrimitive;
449
471
  }
450
472
  });
451
- exports.jsonValueAncestor = require_db_view.jsonValueAncestor;
452
- exports.narrowerFilterOps = require_db_view.narrowerFilterOps;
473
+ exports.jsonValueAncestor = require_column_diff.jsonValueAncestor;
474
+ exports.narrowerFilterOps = require_column_diff.narrowerFilterOps;
475
+ exports.normalizeComputedSelect = require_column_diff.normalizeComputedSelect;
453
476
  exports.reconcileCas = require_ops.reconcileCas;
454
- exports.resolveCalendarBuckets = require_db_view.resolveCalendarBuckets;
455
- exports.resolveDesignType = require_db_view.resolveDesignType;
477
+ exports.resolveCalendarBuckets = require_column_diff.resolveCalendarBuckets;
478
+ exports.resolveDesignType = require_column_diff.resolveDesignType;
456
479
  exports.separateCas = require_ops.separateCas;
457
480
  exports.separateFieldOps = require_ops.separateFieldOps;
458
- exports.sortFieldNames = require_db_view.sortFieldNames;
481
+ exports.sortFieldNames = require_column_diff.sortFieldNames;
482
+ exports.tableNameOf = require_nested_writer.tableNameOf;
459
483
  exports.translateQueryTree = translateQueryTree;
460
- exports.unsupportedOperatorMessage = require_db_view.unsupportedOperatorMessage;
484
+ exports.unsupportedOperatorMessage = require_column_diff.unsupportedOperatorMessage;
461
485
  Object.defineProperty(exports, "walkFilter", {
462
486
  enumerable: true,
463
487
  get: function() {
package/dist/index.d.cts CHANGED
@@ -1,9 +1,10 @@
1
- import { $ as TDbWriteGuardContext, A as TDbActionIntent, At as isGeoIndexableType, B as TDbIndexField, Bt as FieldMappingStrategy, C as PrimaryKeyOf, Ct as TWriteTableResolver, D as TCrudOp, Dt as WithRelation, E as TColumnDiff, Et as UniqueryControls, F as TDbDefaultValue, Ft as DbResponse, G as TDbReferentialAction, H as TDbInsertManyResult, Ht as TGenericLogger, I as TDbDeleteResult, It as resolveDesignType, J as TDbRemoveGuardContext, K as TDbRelation, L as TDbFieldMeta, Lt as DbEncryption, M as TDbActionProcessor, Mt as ALL_BUCKET_UNITS, N as TDbCollation, Nt as BaseDbAdapter, O as TCrudPermissions, Ot as TableMetadata, P as TDbDefaultFn, Pt as AtscriptDbReadable, Q as TDbWriteGuard, R as TDbForeignKey, Rt as TDbEncryptionOptions, S as OwnPropsOf, St as TWriteOptions, T as TCascadeTarget, Tt as Uniquery, U as TDbInsertResult, Ut as UniquSelect, V as TDbIndexType, Vt as NoopLogger, W as TDbObjectKind, X as TDbUpdateResult, Y as TDbStorageType, Z as TDbWriteAction, _ as FieldOpsFor, _t as TSyncColumnResult, a as jsonValueAncestor, at as TFieldMeta, b as NavPropsOf, bt as TTouchManyOptions, c as AggregateExpr, ct as TIdDescriptor, d as AggregateResult, dt as TMetaResponse, et as TDeleteOptions, f as AtscriptDbWritable, ft as TMetadataOverrides, g as DbRow, gt as TSearchIndexInfo, h as DbQuery, ht as TRelationInfo, i as isJsonValueField, it as TExistingTableOption, j as TDbActionLevel, jt as isGeoPointType, k as TDbActionInfo, kt as findAncestorInSet, l as AggregateFn, lt as TIdResolveOptions, m as DbPatch, mt as TReferencingForeignKey, n as TResolvedBucket, nt as TExistingColumn, o as resolveCalendarBuckets, ot as TFkLookupResolver, p as DbControls, pt as TPrimaryKeyChange, q as TDbRemoveGuard, r as isBucketableField, rt as TExistingForeignKey, s as AggregateControls, st as TFkLookupTarget, t as TBucketFieldSource, tt as TEnsureTableOptions, u as AggregateQuery, ut as TIdentification, v as FilterExpr, vt as TTableOptionDiff, w as TCascadeResolver, wt as TypedWithRelation, x as NullableOptional, xt as TValueFormatterPair, y as FlatOf, yt as TTableResolver, z as TDbIndex, zt as DocumentFieldMapper } from "./buckets-D6PBXKRJ.cjs";
1
+ import { $ as TDbWriteGuard, $t as AtscriptDbReadable, A as TDbActionInfo, At as findAncestorInSet, B as TDbIndex, Bt as TViewJsonType, C as OwnPropsOf, Ct as TWriteOptions, D as TColumnDiff, Dt as UniqueryControls, E as TCascadeTarget, Et as Uniquery, F as TDbDefaultFn, Ft as DbSpace, G as TDbObjectKind, Gt as AtscriptRef, H as TDbIndexType, Ht as AtscriptQueryComparison, I as TDbDefaultValue, It as TAdapterFactory, J as TDbRemoveGuard, Jt as isFieldRef, K as TDbReferentialAction, Kt as TViewJoin, L as TDbDeleteResult, Lt as TDbSpaceOptions, M as TDbActionLevel, Mt as isGeoPointType, N as TDbActionProcessor, Nt as ALL_BUCKET_UNITS, O as TCrudOp, Ot as WithRelation, P as TDbCollation, Pt as BaseDbAdapter, Q as TDbWriteAction, Qt as NativeIntegrity, R as TDbFieldMeta, Rt as AtscriptDbView, S as NullableOptional, St as TValueFormatterPair, T as TCascadeResolver, Tt as TypedWithRelation, U as TDbInsertManyResult, Ut as AtscriptQueryFieldRef, V as TDbIndexField, Vt as isAtscriptDbView, W as TDbInsertResult, Wt as AtscriptQueryNode, X as TDbStorageType, Xt as AtscriptDbTable, Y as TDbRemoveGuardContext, Yt as translateQueryTree, Z as TDbUpdateResult, Zt as IntegrityStrategy, _ as DbRow, _t as TSearchIndexInfo, a as jsonValueAncestor, an as FieldMappingStrategy, at as TExistingTableOption, b as FlatOf, bt as TTableResolver, c as AggregateControls, cn as UniquSelect, ct as TFkLookupTarget, d as AggregateQuery, dt as TIdentification, en as DbResponse, et as TDbWriteGuardContext, f as AggregateResult, ft as TMetaResponse, g as DbQuery, gt as TRelationInfo, h as DbPatch, ht as TReferencingForeignKey, i as isJsonValueField, in as DocumentFieldMapper, it as TExistingForeignKey, j as TDbActionIntent, jt as isGeoIndexableType, k as TCrudPermissions, kt as TableMetadata, l as AggregateExpr, lt as TIdDescriptor, m as DbControls, mt as TPrimaryKeyChange, n as TResolvedBucket, nn as DbEncryption, nt as TEnsureTableOptions, o as normalizeComputedSelect, on as NoopLogger, ot as TFieldMeta, p as AtscriptDbWritable, pt as TMetadataOverrides, q as TDbRelation, qt as TViewPlan, r as isBucketableField, rn as TDbEncryptionOptions, rt as TExistingColumn, s as resolveCalendarBuckets, sn as TGenericLogger, st as TFkLookupResolver, t as TBucketFieldSource, tn as resolveDesignType, tt as TDeleteOptions, u as AggregateFn, ut as TIdResolveOptions, v as FieldOpsFor, vt as TSyncColumnResult, w as PrimaryKeyOf, wt as TWriteTableResolver, x as NavPropsOf, xt as TTouchManyOptions, y as FilterExpr, yt as TTableOptionDiff, z as TDbForeignKey, zt as TViewColumnMapping } from "./buckets-C-27xmtq.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
- import { c as CalendarBucketLabel, d as WeekStart, l as ComputedExpr, o as BucketExpr, s as BucketUnit, u as ResolvedBucket } from "./agg-DKuf_v2L.cjs";
4
- import { a as TViewColumnMapping, c as AtscriptQueryFieldRef, d as TViewJoin, f as TViewPlan, g as NativeIntegrity, h as IntegrityStrategy, i as AtscriptDbView, l as AtscriptQueryNode, m as AtscriptDbTable, n as TAdapterFactory, o as isAtscriptDbView, p as translateQueryTree, r as TDbSpaceOptions, s as AtscriptQueryComparison, t as DbSpace, u as AtscriptRef } from "./db-space-BdtBNTeH.cjs";
5
- import { _ as DbErrorCode, a as buildValidationContext, c as isNavRelation, d as TArrayPatch, f as TDbPatch, g as DbError, h as CasMismatchError, l as isEmptyObject, m as CasExhaustedError, n as ValidatorMode, p as getKeyProps, r as buildDbValidator, s as forceNavNonOptional, t as ValidationContext, u as isPlainObject, v as bucketTimeZoneUnavailable } from "./validator-CewfnGZj.cjs";
3
+ 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-CV7y8nC6.cjs";
4
+ import { _ as DbErrorCode, a as buildValidationContext, c as isNavRelation, d as TArrayPatch, f as TDbPatch, g as DbError, h as CasMismatchError, l as isEmptyObject, m as CasExhaustedError, n as ValidatorMode, p as getKeyProps, r as buildDbValidator, s as forceNavNonOptional, t as ValidationContext, u as isPlainObject, v as bucketTimeZoneUnavailable } from "./validator-Drb2N-YL.cjs";
6
5
  import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
6
+ import { n as isColumnTypeChanged } from "./column-diff-BmqvgBWw.cjs";
7
+ import { i as tableNameOf } from "./relation-helpers-DxrvS6ar.cjs";
7
8
  import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, ResolvedBucket as ResolvedBucket$1, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
8
9
 
9
10
  //#region src/shared/consts.d.ts
@@ -105,7 +106,7 @@ declare class ApplicationIntegrity extends IntegrityStrategy {
105
106
  * - `$exists` with a non-boolean operand → `INVALID_QUERY`
106
107
  * - malformed `$select` computed entries / `$groupBy` entries, calendar
107
108
  * buckets outside grouped queries or with a bad unit / zone / alias →
108
- * `INVALID_QUERY` (the shared normalizer, `resolveCalendarBuckets`)
109
+ * `INVALID_QUERY` (the shared normalizer, `normalizeComputedSelect`)
109
110
  * - a calendar bucket over a field that is not a bucket source
110
111
  * (`bucketSourceVerdict`) → `INVALID_QUERY`, or `BUCKET_NOT_SUPPORTED`
111
112
  * when the adapter has no calendar buckets at all; a unit the adapter's
@@ -283,7 +284,7 @@ interface TQueryPathRefs {
283
284
  * `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
284
285
  * lists grouped fields only.
285
286
  *
286
- * Entry shapes are not checked here — see `resolveCalendarBuckets`.
287
+ * Entry shapes are not checked here — see `normalizeComputedSelect`.
287
288
  */
288
289
  declare function collectQueryPaths(query: TGuardedQuery, aggregate?: boolean): TQueryPathRefs;
289
290
  /** What a logical path is on THIS readable / adapter (since 0.1.128). */
@@ -346,7 +347,7 @@ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: st
346
347
  * {@link guardPath}). Adapters may therefore assume every path they receive
347
348
  * is physical.
348
349
  *
349
- * Entry shapes are the caller's to normalize first (`resolveCalendarBuckets`
350
+ * Entry shapes are the caller's to normalize first (`normalizeComputedSelect`
350
351
  * — {@link guardQuery} / {@link guardAggregate} do).
351
352
  *
352
353
  * In aggregate mode (`aggregate = true`) `$select` computed entries have
@@ -380,13 +381,14 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
380
381
  } | undefined;
381
382
  /**
382
383
  * Aggregate-path guard: $groupBy / $select / $having encryption refs + filter
383
- * + $sort, then the path guard, then the adapter's calendar-bucket units
384
+ * + $sort, then the path guard, then the adapter's aggregate functions
385
+ * (`AGG_FN_NOT_SUPPORTED`) and calendar-bucket units
384
386
  * (`BUCKET_NOT_SUPPORTED`), then the `$having` key rule
385
387
  * ({@link checkHavingKeys} — after the path guard so an unknown key still
386
388
  * reads `Unknown field`).
387
389
  *
388
390
  * `buckets` are the query's resolved calendar buckets when the caller already
389
- * ran `resolveCalendarBuckets` (resolved here otherwise).
391
+ * ran `normalizeComputedSelect` (resolved here otherwise).
390
392
  */
391
393
  declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: readonly ResolvedBucket$1[]): void;
392
394
  //#endregion
@@ -487,4 +489,4 @@ declare function createFailureCollector(what: string): {
487
489
  throwIfAny: () => void;
488
490
  };
489
491
  //#endregion
490
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_BUCKET_UNITS, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, 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, RelationalFieldMapper, type ResolvedBucket, 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 TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, 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 TDbWriteGuard, type TDbWriteGuardContext, type TDeleteOptions, type TEnsureTableOptions, type TExistingColumn, type TExistingForeignKey, type TExistingTableOption, type TFieldMeta, type TFieldOps, type TFilterPredicate, type TFilterRef, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGuardedQuery, type TIdDescriptor, type TIdResolveOptions, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReferencingForeignKey, type TRelationInfo, type TResolvedBucket, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TTouchManyOptions, type TValueFormatterPair, type TViewColumnMapping, type TViewJoin, 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, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isDbFieldOp, isEmptyObject, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
492
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, 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, RelationalFieldMapper, type ResolvedBucket, 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 TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, 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 TDbWriteGuard, type TDbWriteGuardContext, type TDeleteOptions, type TEnsureTableOptions, type TExistingColumn, type TExistingForeignKey, type TExistingTableOption, type TFieldMeta, type TFieldOps, type TFilterPredicate, type TFilterRef, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGuardedQuery, type TIdDescriptor, type TIdResolveOptions, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReferencingForeignKey, type TRelationInfo, type TResolvedBucket, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TTouchManyOptions, type TValueFormatterPair, 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, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isColumnTypeChanged, isDbFieldOp, isEmptyObject, isFieldRef, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, normalizeComputedSelect, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, tableNameOf, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
- import { $ as TDbWriteGuardContext, A as TDbActionIntent, At as isGeoIndexableType, B as TDbIndexField, Bt as FieldMappingStrategy, C as PrimaryKeyOf, Ct as TWriteTableResolver, D as TCrudOp, Dt as WithRelation, E as TColumnDiff, Et as UniqueryControls, F as TDbDefaultValue, Ft as DbResponse, G as TDbReferentialAction, H as TDbInsertManyResult, Ht as TGenericLogger, I as TDbDeleteResult, It as resolveDesignType, J as TDbRemoveGuardContext, K as TDbRelation, L as TDbFieldMeta, Lt as DbEncryption, M as TDbActionProcessor, Mt as ALL_BUCKET_UNITS, N as TDbCollation, Nt as BaseDbAdapter, O as TCrudPermissions, Ot as TableMetadata, P as TDbDefaultFn, Pt as AtscriptDbReadable, Q as TDbWriteGuard, R as TDbForeignKey, Rt as TDbEncryptionOptions, S as OwnPropsOf, St as TWriteOptions, T as TCascadeTarget, Tt as Uniquery, U as TDbInsertResult, Ut as UniquSelect, V as TDbIndexType, Vt as NoopLogger, W as TDbObjectKind, X as TDbUpdateResult, Y as TDbStorageType, Z as TDbWriteAction, _ as FieldOpsFor, _t as TSyncColumnResult, a as jsonValueAncestor, at as TFieldMeta, b as NavPropsOf, bt as TTouchManyOptions, c as AggregateExpr, ct as TIdDescriptor, d as AggregateResult, dt as TMetaResponse, et as TDeleteOptions, f as AtscriptDbWritable, ft as TMetadataOverrides, g as DbRow, gt as TSearchIndexInfo, h as DbQuery, ht as TRelationInfo, i as isJsonValueField, it as TExistingTableOption, j as TDbActionLevel, jt as isGeoPointType, k as TDbActionInfo, kt as findAncestorInSet, l as AggregateFn, lt as TIdResolveOptions, m as DbPatch, mt as TReferencingForeignKey, n as TResolvedBucket, nt as TExistingColumn, o as resolveCalendarBuckets, ot as TFkLookupResolver, p as DbControls, pt as TPrimaryKeyChange, q as TDbRemoveGuard, r as isBucketableField, rt as TExistingForeignKey, s as AggregateControls, st as TFkLookupTarget, t as TBucketFieldSource, tt as TEnsureTableOptions, u as AggregateQuery, ut as TIdentification, v as FilterExpr, vt as TTableOptionDiff, w as TCascadeResolver, wt as TypedWithRelation, x as NullableOptional, xt as TValueFormatterPair, y as FlatOf, yt as TTableResolver, z as TDbIndex, zt as DocumentFieldMapper } from "./buckets-GruoVxH5.mjs";
1
+ import { $ as TDbWriteGuard, $t as AtscriptDbReadable, A as TDbActionInfo, At as findAncestorInSet, B as TDbIndex, Bt as TViewJsonType, C as OwnPropsOf, Ct as TWriteOptions, D as TColumnDiff, Dt as UniqueryControls, E as TCascadeTarget, Et as Uniquery, F as TDbDefaultFn, Ft as DbSpace, G as TDbObjectKind, Gt as AtscriptRef, H as TDbIndexType, Ht as AtscriptQueryComparison, I as TDbDefaultValue, It as TAdapterFactory, J as TDbRemoveGuard, Jt as isFieldRef, K as TDbReferentialAction, Kt as TViewJoin, L as TDbDeleteResult, Lt as TDbSpaceOptions, M as TDbActionLevel, Mt as isGeoPointType, N as TDbActionProcessor, Nt as ALL_BUCKET_UNITS, O as TCrudOp, Ot as WithRelation, P as TDbCollation, Pt as BaseDbAdapter, Q as TDbWriteAction, Qt as NativeIntegrity, R as TDbFieldMeta, Rt as AtscriptDbView, S as NullableOptional, St as TValueFormatterPair, T as TCascadeResolver, Tt as TypedWithRelation, U as TDbInsertManyResult, Ut as AtscriptQueryFieldRef, V as TDbIndexField, Vt as isAtscriptDbView, W as TDbInsertResult, Wt as AtscriptQueryNode, X as TDbStorageType, Xt as AtscriptDbTable, Y as TDbRemoveGuardContext, Yt as translateQueryTree, Z as TDbUpdateResult, Zt as IntegrityStrategy, _ as DbRow, _t as TSearchIndexInfo, a as jsonValueAncestor, an as FieldMappingStrategy, at as TExistingTableOption, b as FlatOf, bt as TTableResolver, c as AggregateControls, cn as UniquSelect, ct as TFkLookupTarget, d as AggregateQuery, dt as TIdentification, en as DbResponse, et as TDbWriteGuardContext, f as AggregateResult, ft as TMetaResponse, g as DbQuery, gt as TRelationInfo, h as DbPatch, ht as TReferencingForeignKey, i as isJsonValueField, in as DocumentFieldMapper, it as TExistingForeignKey, j as TDbActionIntent, jt as isGeoIndexableType, k as TCrudPermissions, kt as TableMetadata, l as AggregateExpr, lt as TIdDescriptor, m as DbControls, mt as TPrimaryKeyChange, n as TResolvedBucket, nn as DbEncryption, nt as TEnsureTableOptions, o as normalizeComputedSelect, on as NoopLogger, ot as TFieldMeta, p as AtscriptDbWritable, pt as TMetadataOverrides, q as TDbRelation, qt as TViewPlan, r as isBucketableField, rn as TDbEncryptionOptions, rt as TExistingColumn, s as resolveCalendarBuckets, sn as TGenericLogger, st as TFkLookupResolver, t as TBucketFieldSource, tn as resolveDesignType, tt as TDeleteOptions, u as AggregateFn, ut as TIdResolveOptions, v as FieldOpsFor, vt as TSyncColumnResult, w as PrimaryKeyOf, wt as TWriteTableResolver, x as NavPropsOf, xt as TTouchManyOptions, y as FilterExpr, yt as TTableOptionDiff, z as TDbForeignKey, zt as TViewColumnMapping } from "./buckets-BFG2RYRW.mjs";
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.mjs";
3
- import { c as CalendarBucketLabel, d as WeekStart, l as ComputedExpr, o as BucketExpr, s as BucketUnit, u as ResolvedBucket } from "./agg-BtlGeRfj.mjs";
4
- import { a as TViewColumnMapping, c as AtscriptQueryFieldRef, d as TViewJoin, f as TViewPlan, g as NativeIntegrity, h as IntegrityStrategy, i as AtscriptDbView, l as AtscriptQueryNode, m as AtscriptDbTable, n as TAdapterFactory, o as isAtscriptDbView, p as translateQueryTree, r as TDbSpaceOptions, s as AtscriptQueryComparison, t as DbSpace, u as AtscriptRef } from "./db-space-9CH5neN7.mjs";
5
- import { _ as DbErrorCode, a as buildValidationContext, c as isNavRelation, d as TArrayPatch, f as TDbPatch, g as DbError, h as CasMismatchError, l as isEmptyObject, m as CasExhaustedError, n as ValidatorMode, p as getKeyProps, r as buildDbValidator, s as forceNavNonOptional, t as ValidationContext, u as isPlainObject, v as bucketTimeZoneUnavailable } from "./validator-CewfnGZj.mjs";
3
+ 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-D5DHsAby.mjs";
4
+ import { _ as DbErrorCode, a as buildValidationContext, c as isNavRelation, d as TArrayPatch, f as TDbPatch, g as DbError, h as CasMismatchError, l as isEmptyObject, m as CasExhaustedError, n as ValidatorMode, p as getKeyProps, r as buildDbValidator, s as forceNavNonOptional, t as ValidationContext, u as isPlainObject, v as bucketTimeZoneUnavailable } from "./validator-Drb2N-YL.mjs";
6
5
  import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs";
6
+ import { n as isColumnTypeChanged } from "./column-diff-DPkbZIVE.mjs";
7
+ import { i as tableNameOf } from "./relation-helpers-D3Zu0Mta.mjs";
7
8
  import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, ResolvedBucket as ResolvedBucket$1, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
8
9
 
9
10
  //#region src/shared/consts.d.ts
@@ -105,7 +106,7 @@ declare class ApplicationIntegrity extends IntegrityStrategy {
105
106
  * - `$exists` with a non-boolean operand → `INVALID_QUERY`
106
107
  * - malformed `$select` computed entries / `$groupBy` entries, calendar
107
108
  * buckets outside grouped queries or with a bad unit / zone / alias →
108
- * `INVALID_QUERY` (the shared normalizer, `resolveCalendarBuckets`)
109
+ * `INVALID_QUERY` (the shared normalizer, `normalizeComputedSelect`)
109
110
  * - a calendar bucket over a field that is not a bucket source
110
111
  * (`bucketSourceVerdict`) → `INVALID_QUERY`, or `BUCKET_NOT_SUPPORTED`
111
112
  * when the adapter has no calendar buckets at all; a unit the adapter's
@@ -283,7 +284,7 @@ interface TQueryPathRefs {
283
284
  * `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
284
285
  * lists grouped fields only.
285
286
  *
286
- * Entry shapes are not checked here — see `resolveCalendarBuckets`.
287
+ * Entry shapes are not checked here — see `normalizeComputedSelect`.
287
288
  */
288
289
  declare function collectQueryPaths(query: TGuardedQuery, aggregate?: boolean): TQueryPathRefs;
289
290
  /** What a logical path is on THIS readable / adapter (since 0.1.128). */
@@ -346,7 +347,7 @@ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: st
346
347
  * {@link guardPath}). Adapters may therefore assume every path they receive
347
348
  * is physical.
348
349
  *
349
- * Entry shapes are the caller's to normalize first (`resolveCalendarBuckets`
350
+ * Entry shapes are the caller's to normalize first (`normalizeComputedSelect`
350
351
  * — {@link guardQuery} / {@link guardAggregate} do).
351
352
  *
352
353
  * In aggregate mode (`aggregate = true`) `$select` computed entries have
@@ -380,13 +381,14 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
380
381
  } | undefined;
381
382
  /**
382
383
  * Aggregate-path guard: $groupBy / $select / $having encryption refs + filter
383
- * + $sort, then the path guard, then the adapter's calendar-bucket units
384
+ * + $sort, then the path guard, then the adapter's aggregate functions
385
+ * (`AGG_FN_NOT_SUPPORTED`) and calendar-bucket units
384
386
  * (`BUCKET_NOT_SUPPORTED`), then the `$having` key rule
385
387
  * ({@link checkHavingKeys} — after the path guard so an unknown key still
386
388
  * reads `Unknown field`).
387
389
  *
388
390
  * `buckets` are the query's resolved calendar buckets when the caller already
389
- * ran `resolveCalendarBuckets` (resolved here otherwise).
391
+ * ran `normalizeComputedSelect` (resolved here otherwise).
390
392
  */
391
393
  declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: readonly ResolvedBucket$1[]): void;
392
394
  //#endregion
@@ -487,4 +489,4 @@ declare function createFailureCollector(what: string): {
487
489
  throwIfAny: () => void;
488
490
  };
489
491
  //#endregion
490
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_BUCKET_UNITS, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, 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, RelationalFieldMapper, type ResolvedBucket, 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 TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, 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 TDbWriteGuard, type TDbWriteGuardContext, type TDeleteOptions, type TEnsureTableOptions, type TExistingColumn, type TExistingForeignKey, type TExistingTableOption, type TFieldMeta, type TFieldOps, type TFilterPredicate, type TFilterRef, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGuardedQuery, type TIdDescriptor, type TIdResolveOptions, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReferencingForeignKey, type TRelationInfo, type TResolvedBucket, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TTouchManyOptions, type TValueFormatterPair, type TViewColumnMapping, type TViewJoin, 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, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isDbFieldOp, isEmptyObject, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
492
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, type AggregateControls, type AggregateExpr, type AggregateFn, type AggregateQuery, type AggregateResult, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, type AtscriptDbWritable, 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, RelationalFieldMapper, type ResolvedBucket, 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 TDbCas, type TDbCollation, type TDbDefaultFn, type TDbDefaultValue, type TDbDeleteResult, type TDbEncryptionOptions, type TDbFieldMeta, type TDbFieldOp, type TDbForeignKey, type TDbIndex, type TDbIndexField, type TDbIndexType, 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 TDbWriteGuard, type TDbWriteGuardContext, type TDeleteOptions, type TEnsureTableOptions, type TExistingColumn, type TExistingForeignKey, type TExistingTableOption, type TFieldMeta, type TFieldOps, type TFilterPredicate, type TFilterRef, type TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGuardedQuery, type TIdDescriptor, type TIdResolveOptions, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReferencingForeignKey, type TRelationInfo, type TResolvedBucket, type TSearchIndexInfo, type TSyncColumnResult, type TTableOptionDiff, type TTableResolver, type TTouchManyOptions, type TValueFormatterPair, 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, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isColumnTypeChanged, isDbFieldOp, isEmptyObject, isFieldRef, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, normalizeComputedSelect, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, tableNameOf, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
package/dist/index.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  import { a as bucketTimeZoneUnavailable, n as CasMismatchError, r as DbError, t as CasExhaustedError } from "./db-error-D5uilS_A.mjs";
2
- import { A as unsupportedOperatorMessage, B as isJsonValueField, C as guardAggregate, D as guardQuery, E as guardPaths, F as TableMetadata, H as resolveCalendarBuckets, I as findAncestorInSet, L as isGeoIndexableType, M as DocumentFieldMapper, N as FieldMappingStrategy, O as narrowerFilterOps, P as UniquSelect, R as isGeoPointType, S as collectQueryPaths, T as guardPath, U as NoopLogger, V as jsonValueAncestor, _ as assertGeoPoint, a as decomposePatch, b as checkHavingKeys, c as BaseDbAdapter, d as NativeIntegrity, f as AtscriptDbReadable, g as acceptedOperatorsHint, h as ENCRYPTED_REASON, i as assertNoVersionWrites, j as RelationalFieldMapper, k as sortFieldNames, l as createFailureCollector, m as ADAPTER_FILTER_REASON, n as isAtscriptDbView, o as ApplicationIntegrity, p as resolveDesignType, r as AtscriptDbTable, s as ALL_BUCKET_UNITS, t as AtscriptDbView, u as IntegrityStrategy, v as bucketSourceVerdict, w as guardFilter, x as classifyQueryPath, y as canFilterLeaf, z as isBucketableField } from "./db-view-Doh8vPg3.mjs";
2
+ import { $ as jsonValueAncestor, A as bucketSourceVerdict, B as narrowerFilterOps, C as NativeIntegrity, D as ENCRYPTED_REASON, E as ADAPTER_FILTER_REASON, F as guardAggregate, G as FieldMappingStrategy, H as unsupportedOperatorMessage, I as guardFilter, J as findAncestorInSet, K as UniquSelect, L as guardPath, M as checkHavingKeys, N as classifyQueryPath, O as acceptedOperatorsHint, P as collectQueryPaths, Q as isJsonValueField, R as guardPaths, S as IntegrityStrategy, T as resolveDesignType, U as RelationalFieldMapper, V as sortFieldNames, W as DocumentFieldMapper, X as isGeoPointType, Y as isGeoIndexableType, Z as isBucketableField, _ as decomposePatch, b as BaseDbAdapter, et as normalizeComputedSelect, g as assertNoVersionWrites, h as AtscriptDbTable, j as canFilterLeaf, k as assertGeoPoint, m as isAtscriptDbView, n as isColumnTypeChanged, nt as NoopLogger, p as AtscriptDbView, q as TableMetadata, tt as resolveCalendarBuckets, v as ApplicationIntegrity, w as AtscriptDbReadable, x as createFailureCollector, y as ALL_BUCKET_UNITS, z as guardQuery } from "./column-diff-BwOA5101.mjs";
3
+ import { t as ALL_AGGREGATE_FNS } from "./aggregate-fns-CfsveE1w.mjs";
4
+ import { v as tableNameOf } from "./nested-writer-FWD5oOYh.mjs";
3
5
  import { a as forceNavNonOptional, c as getKeyProps, l as isEmptyObject, o as isNavRelation, r as buildValidationContext, s as createDbValidatorPlugin, t as buildDbValidator, u as isPlainObject } from "./validator-Ch7UIQl9.mjs";
4
6
  import { t as DEFAULT_DB_SPACE } from "./consts-C_-5_pFq.mjs";
5
7
  import { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, getDbFieldOp, isDbFieldOp, reconcileCas, separateCas, separateFieldOps } from "./ops.mjs";
@@ -256,7 +258,7 @@ var DbSpace = class {
256
258
  getTable(type, logger) {
257
259
  let readable = this._readables.get(type);
258
260
  if (!readable) {
259
- readable = new AtscriptDbTable(type, this.adapterFactory(), logger || this.logger, (t) => this.get(t), (t) => {
261
+ readable = new AtscriptDbTable(type, this._createAdapter(), logger || this.logger, (t) => this.get(t), (t) => {
260
262
  const resolved = this.get(t);
261
263
  return resolved instanceof AtscriptDbTable ? resolved : void 0;
262
264
  });
@@ -275,7 +277,7 @@ var DbSpace = class {
275
277
  getView(type, logger) {
276
278
  let readable = this._readables.get(type);
277
279
  if (!readable) {
278
- readable = new AtscriptDbView(type, this.adapterFactory(), logger || this.logger, (t) => this.get(t));
280
+ readable = new AtscriptDbView(type, this._createAdapter(), logger || this.logger, (t) => this.get(t));
279
281
  readable.setEncryption(this._encryption);
280
282
  this._readables.set(type, readable);
281
283
  }
@@ -290,17 +292,17 @@ var DbSpace = class {
290
292
  }
291
293
  /**
292
294
  * Drops a table by name. Used by schema sync to remove tables no longer in the schema.
295
+ * See `BaseDbAdapter.dropTableByName` for an adapter that does not support it.
293
296
  */
294
297
  async dropTableByName(tableName) {
295
- const adapter = this._getAdminAdapter();
296
- if (adapter.dropTableByName) await adapter.dropTableByName(tableName);
298
+ await this._getAdminAdapter().dropTableByName(tableName);
297
299
  }
298
300
  /**
299
301
  * Drops a view by name. Used by schema sync to remove views no longer in the schema.
302
+ * See `BaseDbAdapter.dropViewByName` for an adapter that does not support it.
300
303
  */
301
304
  async dropViewByName(viewName) {
302
- const adapter = this._getAdminAdapter();
303
- if (adapter.dropViewByName) await adapter.dropViewByName(viewName);
305
+ await this._getAdminAdapter().dropViewByName(viewName);
304
306
  }
305
307
  /**
306
308
  * Drops a group of mutually referencing tables as one operation.
@@ -326,7 +328,16 @@ var DbSpace = class {
326
328
  * schema for those from the driver/connection, not from a bound table.
327
329
  */
328
330
  _getAdminAdapter() {
329
- return this._adminAdapter ??= this.adapterFactory();
331
+ return this._adminAdapter ??= this._createAdapter();
332
+ }
333
+ /**
334
+ * A factory-fresh adapter that knows its space (see `BaseDbAdapter.registerSpace`).
335
+ * Optional call: an adapter built against an older `@atscript/db` copy lacks it.
336
+ */
337
+ _createAdapter() {
338
+ const adapter = this.adapterFactory();
339
+ adapter.registerSpace?.(this);
340
+ return adapter;
330
341
  }
331
342
  /**
332
343
  * Finds all child tables with FKs pointing to the given parent table name.
@@ -354,6 +365,14 @@ var DbSpace = class {
354
365
  //#endregion
355
366
  //#region src/query/query-tree.ts
356
367
  /**
368
+ * `true` when a query-tree operand is a field reference (`{ field, type? }`)
369
+ * rather than a literal — e.g. the right side of a field-to-field comparison.
370
+ * @since 0.1.136
371
+ */
372
+ function isFieldRef(value) {
373
+ return value !== null && typeof value === "object" && "field" in value;
374
+ }
375
+ /**
357
376
  * Translates a JS-emitted query tree into a FilterExpr.
358
377
  * Resolves field references (type + field path) to physical column names
359
378
  * via the provided resolver function.
@@ -364,12 +383,12 @@ function translateQueryTree(node, resolveField) {
364
383
  if ("$not" in node) return { $not: translateQueryTree(node.$not, resolveField) };
365
384
  const comp = node;
366
385
  const leftField = resolveField(comp.left);
367
- if (comp.right && typeof comp.right === "object" && "field" in comp.right) {
386
+ if (isFieldRef(comp.right)) {
368
387
  const rightField = resolveField(comp.right);
369
388
  return { [leftField]: { [comp.op]: { $field: rightField } } };
370
389
  }
371
- if (comp.op === "$exists") return { [leftField]: { $exists: true } };
390
+ if (comp.op === "$exists") return { [leftField]: { $exists: comp.right !== false } };
372
391
  return { [leftField]: { [comp.op]: comp.right } };
373
392
  }
374
393
  //#endregion
375
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_BUCKET_UNITS, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, BaseDbAdapter, CasExhaustedError, CasMismatchError, DEFAULT_DB_SPACE, DbEncryption, DbError, DbSpace, DocumentFieldMapper, ENCRYPTED_REASON, FieldMappingStrategy, IntegrityStrategy, NativeIntegrity, NoopLogger, RelationalFieldMapper, TableMetadata, UniquSelect, acceptedOperatorsHint, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isDbFieldOp, isEmptyObject, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
394
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, ADAPTER_FILTER_REASON, ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ApplicationIntegrity, AtscriptDbReadable, AtscriptDbTable, AtscriptDbView, BaseDbAdapter, CasExhaustedError, CasMismatchError, DEFAULT_DB_SPACE, DbEncryption, DbError, DbSpace, DocumentFieldMapper, ENCRYPTED_REASON, FieldMappingStrategy, IntegrityStrategy, NativeIntegrity, NoopLogger, RelationalFieldMapper, TableMetadata, UniquSelect, acceptedOperatorsHint, assertGeoPoint, assertNoVersionWrites, bucketSourceVerdict, bucketTimeZoneUnavailable, buildDbValidator, buildValidationContext, canFilterLeaf, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isBucketableField, isColumnTypeChanged, isDbFieldOp, isEmptyObject, isFieldRef, isGeoIndexableType, isGeoPointType, isJsonValueField, isNavRelation, isPlainObject, isPrimitive, jsonValueAncestor, narrowerFilterOps, normalizeComputedSelect, reconcileCas, resolveCalendarBuckets, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, tableNameOf, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
@@ -26,11 +26,19 @@ function findRemoteFK(targetTable, thisTableName, alias) {
26
26
  }
27
27
  }
28
28
  /**
29
+ * Table name of an annotated type — its `@db.table`, else its type id (`""`
30
+ * when neither is set). The rule relations, foreign keys and view plans use
31
+ * to name a referenced table.
32
+ * @since 0.1.136
33
+ */
34
+ function tableNameOf(type) {
35
+ return type?.metadata?.get("db.table") || type?.id || "";
36
+ }
37
+ /**
29
38
  * Resolves the target table name from a relation's target type metadata.
30
39
  */
31
40
  function resolveRelationTargetTable(relation) {
32
- const targetType = relation.targetType();
33
- return targetType?.metadata?.get("db.table") || targetType?.id || "";
41
+ return tableNameOf(relation.targetType());
34
42
  }
35
43
  //#endregion
36
44
  //#region src/table/error-utils.ts
@@ -742,6 +750,12 @@ Object.defineProperty(exports, "resolveRelationTargetTable", {
742
750
  return resolveRelationTargetTable;
743
751
  }
744
752
  });
753
+ Object.defineProperty(exports, "tableNameOf", {
754
+ enumerable: true,
755
+ get: function() {
756
+ return tableNameOf;
757
+ }
758
+ });
745
759
  Object.defineProperty(exports, "validateBatch", {
746
760
  enumerable: true,
747
761
  get: function() {
@@ -26,11 +26,19 @@ function findRemoteFK(targetTable, thisTableName, alias) {
26
26
  }
27
27
  }
28
28
  /**
29
+ * Table name of an annotated type — its `@db.table`, else its type id (`""`
30
+ * when neither is set). The rule relations, foreign keys and view plans use
31
+ * to name a referenced table.
32
+ * @since 0.1.136
33
+ */
34
+ function tableNameOf(type) {
35
+ return type?.metadata?.get("db.table") || type?.id || "";
36
+ }
37
+ /**
29
38
  * Resolves the target table name from a relation's target type metadata.
30
39
  */
31
40
  function resolveRelationTargetTable(relation) {
32
- const targetType = relation.targetType();
33
- return targetType?.metadata?.get("db.table") || targetType?.id || "";
41
+ return tableNameOf(relation.targetType());
34
42
  }
35
43
  //#endregion
36
44
  //#region src/table/error-utils.ts
@@ -646,4 +654,4 @@ async function viaReplace(targetTable, junctionTable, targets, parentPK, targetP
646
654
  }
647
655
  }
648
656
  //#endregion
649
- export { resolveRelationTargetTable as _, batchPatchNestedTo as a, batchReplaceNestedTo as c, preValidateNestedFrom as d, validateBatch as f, findRemoteFK as g, findFKForRelation as h, batchPatchNestedFrom as i, batchReplaceNestedVia as l, remapDeleteFkViolation as m, batchInsertNestedTo as n, batchPatchNestedVia as o, enrichFkViolation as p, batchInsertNestedVia as r, batchReplaceNestedFrom as s, batchInsertNestedFrom as t, checkDepthOverflow as u };
657
+ export { resolveRelationTargetTable as _, batchPatchNestedTo as a, batchReplaceNestedTo as c, preValidateNestedFrom as d, validateBatch as f, findRemoteFK as g, findFKForRelation as h, batchPatchNestedFrom as i, batchReplaceNestedVia as l, remapDeleteFkViolation as m, batchInsertNestedTo as n, batchPatchNestedVia as o, enrichFkViolation as p, batchInsertNestedVia as r, batchReplaceNestedFrom as s, batchInsertNestedFrom as t, checkDepthOverflow as u, tableNameOf as v };