@atscript/db 0.1.131 → 0.1.133

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 (39) hide show
  1. package/dist/agg.cjs +19 -5
  2. package/dist/agg.d.cts +3 -4
  3. package/dist/agg.d.mts +3 -4
  4. package/dist/agg.mjs +2 -5
  5. package/dist/{db-readable-D8aa-wfP.d.mts → buckets-BENuu_tK.d.mts} +1346 -1141
  6. package/dist/{db-readable-Cmrg9aLU.d.cts → buckets-CTWy7Y1k.d.cts} +1346 -1141
  7. package/dist/{db-error-COrO58t5.mjs → db-error-D5uilS_A.mjs} +13 -1
  8. package/dist/{db-error-C4JuLcvb.cjs → db-error-DTkkeu5b.cjs} +18 -0
  9. package/dist/{db-space-B4MjNjY4.d.mts → db-space-Bv3Ar_Xd.d.mts} +1 -1
  10. package/dist/{db-space-rQFgz3-k.d.cts → db-space-DROLifb-.d.cts} +1 -1
  11. package/dist/{db-view-DUDnyQ3b.cjs → db-view-B5-bQ5AV.cjs} +552 -120
  12. package/dist/{db-view-BYH4HJ-U.mjs → db-view-caPATLmX.mjs} +486 -120
  13. package/dist/index.cjs +16 -4
  14. package/dist/index.d.cts +163 -38
  15. package/dist/index.d.mts +163 -38
  16. package/dist/index.mjs +5 -5
  17. package/dist/{nested-writer-CkDo-ZfH.mjs → nested-writer-CqL24ojl.mjs} +1 -1
  18. package/dist/{nested-writer-DxPhmWFz.cjs → nested-writer-wk1EFUNY.cjs} +1 -1
  19. package/dist/ops.cjs +1 -1
  20. package/dist/ops.mjs +1 -1
  21. package/dist/rel.cjs +2 -2
  22. package/dist/rel.d.cts +1 -1
  23. package/dist/rel.d.mts +1 -1
  24. package/dist/rel.mjs +2 -2
  25. package/dist/{relation-loader-CUGcxJ18.mjs → relation-loader-B68R1LET.mjs} +1 -1
  26. package/dist/{relation-loader-C8GOpNYJ.cjs → relation-loader-BD4xANQJ.cjs} +1 -1
  27. package/dist/sync.cjs +1 -1
  28. package/dist/sync.d.cts +2 -2
  29. package/dist/sync.d.mts +2 -2
  30. package/dist/sync.mjs +1 -1
  31. package/dist/{validator-lkCJKuoo.cjs → validator-BtZbcLN2.cjs} +1 -1
  32. package/dist/{validator-wBARmD68.d.cts → validator-CewfnGZj.d.cts} +9 -2
  33. package/dist/{validator-wBARmD68.d.mts → validator-CewfnGZj.d.mts} +9 -2
  34. package/dist/{validator-CeD_fqyW.mjs → validator-Ch7UIQl9.mjs} +1 -1
  35. package/dist/validator.cjs +2 -2
  36. package/dist/validator.d.cts +1 -1
  37. package/dist/validator.d.mts +1 -1
  38. package/dist/validator.mjs +2 -2
  39. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_db_error = require("./db-error-C4JuLcvb.cjs");
3
- const require_db_view = require("./db-view-DUDnyQ3b.cjs");
4
- const require_validator = require("./validator-lkCJKuoo.cjs");
2
+ const require_db_error = require("./db-error-DTkkeu5b.cjs");
3
+ const require_db_view = require("./db-view-B5-bQ5AV.cjs");
4
+ const require_validator = require("./validator-BtZbcLN2.cjs");
5
5
  const require_consts = require("./consts-BzRfCcH2.cjs");
6
6
  const require_ops = require("./ops.cjs");
7
- let node_crypto = require("node:crypto");
8
7
  let _uniqu_core = require("@uniqu/core");
8
+ let node_crypto = require("node:crypto");
9
9
  //#region src/encryption.ts
10
10
  const ENVELOPE_VERSION = "aes1";
11
11
  const ALGORITHM = "aes-256-gcm";
@@ -382,6 +382,8 @@ exports.$remove = require_ops.$remove;
382
382
  exports.$replace = require_ops.$replace;
383
383
  exports.$update = require_ops.$update;
384
384
  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;
385
387
  exports.ApplicationIntegrity = require_db_view.ApplicationIntegrity;
386
388
  exports.AtscriptDbReadable = require_db_view.AtscriptDbReadable;
387
389
  exports.AtscriptDbTable = require_db_view.AtscriptDbTable;
@@ -394,6 +396,7 @@ exports.DbEncryption = DbEncryption;
394
396
  exports.DbError = require_db_error.DbError;
395
397
  exports.DbSpace = DbSpace;
396
398
  exports.DocumentFieldMapper = require_db_view.DocumentFieldMapper;
399
+ exports.ENCRYPTED_REASON = require_db_view.ENCRYPTED_REASON;
397
400
  exports.FieldMappingStrategy = require_db_view.FieldMappingStrategy;
398
401
  exports.IntegrityStrategy = require_db_view.IntegrityStrategy;
399
402
  exports.NativeIntegrity = require_db_view.NativeIntegrity;
@@ -401,10 +404,14 @@ exports.NoopLogger = require_db_view.NoopLogger;
401
404
  exports.RelationalFieldMapper = require_db_view.RelationalFieldMapper;
402
405
  exports.TableMetadata = require_db_view.TableMetadata;
403
406
  exports.UniquSelect = require_db_view.UniquSelect;
407
+ exports.acceptedOperatorsHint = require_db_view.acceptedOperatorsHint;
404
408
  exports.assertGeoPoint = require_db_view.assertGeoPoint;
405
409
  exports.assertNoVersionWrites = require_db_view.assertNoVersionWrites;
410
+ exports.bucketSourceVerdict = require_db_view.bucketSourceVerdict;
411
+ exports.bucketTimeZoneUnavailable = require_db_error.bucketTimeZoneUnavailable;
406
412
  exports.buildDbValidator = require_validator.buildDbValidator;
407
413
  exports.buildValidationContext = require_validator.buildValidationContext;
414
+ exports.canFilterLeaf = require_db_view.canFilterLeaf;
408
415
  exports.checkHavingKeys = require_db_view.checkHavingKeys;
409
416
  exports.classifyQueryPath = require_db_view.classifyQueryPath;
410
417
  exports.collectQueryPaths = require_db_view.collectQueryPaths;
@@ -427,10 +434,12 @@ exports.guardPath = require_db_view.guardPath;
427
434
  exports.guardPaths = require_db_view.guardPaths;
428
435
  exports.guardQuery = require_db_view.guardQuery;
429
436
  exports.isAtscriptDbView = require_db_view.isAtscriptDbView;
437
+ exports.isBucketableField = require_db_view.isBucketableField;
430
438
  exports.isDbFieldOp = require_ops.isDbFieldOp;
431
439
  exports.isEmptyObject = require_validator.isEmptyObject;
432
440
  exports.isGeoIndexableType = require_db_view.isGeoIndexableType;
433
441
  exports.isGeoPointType = require_db_view.isGeoPointType;
442
+ exports.isJsonValueField = require_db_view.isJsonValueField;
434
443
  exports.isNavRelation = require_validator.isNavRelation;
435
444
  exports.isPlainObject = require_validator.isPlainObject;
436
445
  Object.defineProperty(exports, "isPrimitive", {
@@ -439,7 +448,10 @@ Object.defineProperty(exports, "isPrimitive", {
439
448
  return _uniqu_core.isPrimitive;
440
449
  }
441
450
  });
451
+ exports.jsonValueAncestor = require_db_view.jsonValueAncestor;
452
+ exports.narrowerFilterOps = require_db_view.narrowerFilterOps;
442
453
  exports.reconcileCas = require_ops.reconcileCas;
454
+ exports.resolveCalendarBuckets = require_db_view.resolveCalendarBuckets;
443
455
  exports.resolveDesignType = require_db_view.resolveDesignType;
444
456
  exports.separateCas = require_ops.separateCas;
445
457
  exports.separateFieldOps = require_ops.separateFieldOps;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,10 @@
1
- import { $ as TDbWriteAction, A as TCrudPermissions, At as findAncestorInSet, B as TDbForeignKey, C as NullableOptional, Ct as TWriteOptions, D as TCascadeTarget, Dt as UniqueryControls, E as TCascadeResolver, Et as Uniquery, F as TDbCollation, Ft as UniquSelect, G as TDbInsertResult, H as TDbIndexField, I as TDbDefaultFn, J as TDbRelation, K as TDbObjectKind, L as TDbDefaultValue, M as TDbActionIntent, Mt as isGeoPointType, N as TDbActionLevel, Nt as NoopLogger, O as TColumnDiff, Ot as WithRelation, P as TDbActionProcessor, Pt as TGenericLogger, Q as TDbUpdateResult, R as TDbDeleteResult, S as NavPropsOf, St as TValueFormatterPair, T as PrimaryKeyOf, Tt as TypedWithRelation, U as TDbIndexType, V as TDbIndex, W as TDbInsertManyResult, X as TDbRemoveGuardContext, Y as TDbRemoveGuard, Z as TDbStorageType, _ as DbQuery, _t as TSearchIndexInfo, a as TDbEncryptionOptions, at as TExistingForeignKey, b as FilterExpr, bt as TTableResolver, c as BaseDbAdapter, ct as TFkLookupResolver, d as AggregateFn, dt as TIdentification, et as TDbWriteGuard, f as AggregateQuery, ft as TMetaResponse, g as DbPatch, gt as TRelationInfo, h as DbControls, ht as TReferencingForeignKey, i as DbEncryption, it as TExistingColumn, j as TDbActionInfo, jt as isGeoIndexableType, k as TCrudOp, kt as TableMetadata, l as AggregateControls, lt as TFkLookupTarget, m as AtscriptDbWritable, mt as TPrimaryKeyChange, n as DbResponse, nt as TDeleteOptions, o as DocumentFieldMapper, ot as TExistingTableOption, p as AggregateResult, pt as TMetadataOverrides, q as TDbReferentialAction, r as resolveDesignType, rt as TEnsureTableOptions, s as FieldMappingStrategy, st as TFieldMeta, t as AtscriptDbReadable, tt as TDbWriteGuardContext, u as AggregateExpr, ut as TIdDescriptor, v as DbRow, vt as TSyncColumnResult, w as OwnPropsOf, wt as TWriteTableResolver, x as FlatOf, xt as TTouchManyOptions, y as FieldOpsFor, yt as TTableOptionDiff, z as TDbFieldMeta } from "./db-readable-Cmrg9aLU.cjs";
1
+ import { $ as TDbWriteGuardContext, A as TDbActionIntent, At as isGeoPointType, B as TDbIndexField, Bt as NoopLogger, C as PrimaryKeyOf, Ct as TypedWithRelation, D as TCrudOp, Dt as TableMetadata, E as TColumnDiff, Et as WithRelation, F as TDbDefaultValue, Ft as resolveDesignType, G as TDbReferentialAction, H as TDbInsertManyResult, Ht as UniquSelect, I as TDbDeleteResult, It as DbEncryption, J as TDbRemoveGuardContext, K as TDbRelation, L as TDbFieldMeta, Lt as TDbEncryptionOptions, M as TDbActionProcessor, Mt as BaseDbAdapter, N as TDbCollation, Nt as AtscriptDbReadable, O as TCrudPermissions, Ot as findAncestorInSet, P as TDbDefaultFn, Pt as DbResponse, Q as TDbWriteGuard, R as TDbForeignKey, Rt as DocumentFieldMapper, S as OwnPropsOf, St as TWriteTableResolver, T as TCascadeTarget, Tt as UniqueryControls, U as TDbInsertResult, V as TDbIndexType, Vt as TGenericLogger, W as TDbObjectKind, X as TDbUpdateResult, Y as TDbStorageType, Z as TDbWriteAction, _ as FieldOpsFor, _t as TTableOptionDiff, a as jsonValueAncestor, at as TFieldMeta, b as NavPropsOf, bt as TValueFormatterPair, c as AggregateExpr, ct as TIdDescriptor, d as AggregateResult, dt as TMetadataOverrides, et as TDeleteOptions, f as AtscriptDbWritable, ft as TPrimaryKeyChange, g as DbRow, gt as TSyncColumnResult, h as DbQuery, ht as TSearchIndexInfo, i as isJsonValueField, it as TExistingTableOption, j as TDbActionLevel, jt as ALL_BUCKET_UNITS, k as TDbActionInfo, kt as isGeoIndexableType, l as AggregateFn, lt as TIdentification, m as DbPatch, mt as TRelationInfo, n as TResolvedBucket, nt as TExistingColumn, o as resolveCalendarBuckets, ot as TFkLookupResolver, p as DbControls, pt as TReferencingForeignKey, 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 TMetaResponse, v as FilterExpr, vt as TTableResolver, w as TCascadeResolver, wt as Uniquery, x as NullableOptional, xt as TWriteOptions, y as FlatOf, yt as TTouchManyOptions, z as TDbIndex, zt as FieldMappingStrategy } from "./buckets-CTWy7Y1k.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 { 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-rQFgz3-k.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 } from "./validator-wBARmD68.cjs";
3
+ import { BucketExpr, BucketUnit, CalendarBucketLabel, ComputedExpr, ResolvedBucket, WeekStart } from "./agg.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-DROLifb-.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";
5
6
  import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.cjs";
6
- import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
7
+ import { AggregateQuery as AggregateQuery$1, FilterExpr as FilterExpr$1, FilterVisitor, ResolvedBucket as ResolvedBucket$1, Uniquery as Uniquery$1, computeInsights, isPrimitive, walkFilter } from "@uniqu/core";
7
8
 
8
9
  //#region src/shared/consts.d.ts
9
10
  /**
@@ -23,7 +24,8 @@ declare const DEFAULT_DB_SPACE = "default";
23
24
  declare class RelationalFieldMapper extends FieldMappingStrategy {
24
25
  reconstructFromRead(row: Record<string, unknown>, meta: TableMetadata): Record<string, unknown>;
25
26
  translateQuery(query: Uniquery$1, meta: TableMetadata): DbQuery;
26
- translateAggregateQuery(query: AggregateQuery$1, meta: TableMetadata): DbQuery;
27
+ /** The flattened column of a logical path (`contact.email` → `contact__email`). */
28
+ protected physicalPath(logical: string, meta: TableMetadata): string;
27
29
  /**
28
30
  * Overrides the base `translateFilter` to use `leafByLogical` for key resolution
29
31
  * (handles flattened nested paths like `contact.email` → `contact__email`).
@@ -100,21 +102,31 @@ declare class ApplicationIntegrity extends IntegrityStrategy {
100
102
  * - `$geoWithin` on a non-geoPoint field → `FILTER_TYPE_MISMATCH`
101
103
  * - `$geoWithin` with a malformed circle → `INVALID_QUERY`
102
104
  * - `$geoWithin` on an adapter without geo support → `GEO_NOT_SUPPORTED`
105
+ * - `$exists` with a non-boolean operand → `INVALID_QUERY`
106
+ * - malformed `$select` computed entries / `$groupBy` entries, calendar
107
+ * buckets outside grouped queries or with a bad unit / zone / alias →
108
+ * `INVALID_QUERY` (the shared normalizer, `resolveCalendarBuckets`)
109
+ * - a calendar bucket over a field that is not a bucket source
110
+ * (`bucketSourceVerdict`) → `INVALID_QUERY`, or `BUCKET_NOT_SUPPORTED`
111
+ * when the adapter has no calendar buckets at all; a unit the adapter's
112
+ * `calendarBucketUnits()` lacks → `BUCKET_NOT_SUPPORTED`
103
113
  * - every filter / `$sort` / `$select` / `$groupBy` / `$having` / aggregate
104
114
  * path must resolve to physical storage on THIS adapter and pass the
105
- * adapter's `canFilterField` / `canSortField` → `INVALID_QUERY`
106
- * (see {@link guardPaths}). Runs after the checks above so `ENC_*` codes
107
- * keep firing first for encrypted subtrees.
115
+ * capability its position (for a filter entry: its predicate class, see
116
+ * {@link canFilterLeaf}) needs → `INVALID_QUERY` (see {@link guardPaths}).
117
+ * Runs after the checks above so `ENC_*` codes keep firing first for
118
+ * encrypted subtrees.
108
119
  */
109
120
  /** Validates a `[lng, lat]` tuple (GeoJSON coordinate order). */
110
121
  declare function assertGeoPoint(point: unknown, path: string): asserts point is [number, number];
111
122
  /**
112
123
  * Walks a filter expression, rejecting encrypted-field references and
113
- * validating `$geoWithin` operator nodes.
124
+ * validating operator operands: `$geoWithin` shapes and the boolean
125
+ * `$exists` operand (this is the one owner of that rule).
114
126
  */
115
127
  declare function guardFilter(meta: TableMetadata, adapter: BaseDbAdapter, filter: FilterExpr$1 | undefined, encCode?: "ENC_FIELD_FILTER" | "ENC_FIELD_AGG"): void;
116
128
  /** The query positions a field path can appear in. */
117
- type TQueryPathOp = "filter" | "sort" | "select" | "groupBy" | "having" | "aggregate";
129
+ type TQueryPathOp = "filter" | "sort" | "select" | "groupBy" | "having" | "aggregate" /** The source field of a calendar bucket (`{ $bucket, $field }` in `$select`). Since 0.1.132. */ | "bucket";
118
130
  /** Query shape accepted by {@link guardPaths} / {@link collectQueryPaths} — the raw (pre-translation) uniqu controls. */
119
131
  interface TGuardedQuery {
120
132
  filter?: FilterExpr$1;
@@ -137,23 +149,120 @@ declare function unsupportedOperatorMessage(op: string): string;
137
149
  * walker so programmatic callers get the same acceptance set.
138
150
  */
139
151
  declare function sortFieldNames(sort: unknown): string[];
152
+ /**
153
+ * The operator class a filter entry needs from its field (since 0.1.132):
154
+ * - `compare` — value comparison (bare values, `$eq`, `$gt`, `$in`, `$regex`, any mix);
155
+ * - `geo` — a `$geoWithin` entry;
156
+ * - `exists` — an entry whose sole operator is `$exists`.
157
+ */
158
+ type TFilterPredicate = "compare" | "geo" | "exists";
159
+ /** One filter entry, collected per occurrence: its key and the predicate class its operators need. */
160
+ interface TFilterRef {
161
+ path: string;
162
+ predicate: TFilterPredicate;
163
+ }
164
+ /**
165
+ * The reason clause for a leaf the adapter cannot filter (value comparison).
166
+ * @internal Shared wording for moost-db's capability index — not consumer API.
167
+ */
168
+ declare const ADAPTER_FILTER_REASON = "adapter cannot filter on this storage type";
169
+ /**
170
+ * The reason clause for an `@db.encrypted` leaf in a comparing / ordering position.
171
+ * @internal Shared wording for moost-db's capability index — not consumer API.
172
+ */
173
+ declare const ENCRYPTED_REASON = "field is @db.encrypted (ciphertext cannot be compared or ordered)";
174
+ /** The adapter-shaped capability {@link canFilterLeaf} consults (a `BaseDbAdapter` or a readable). */
175
+ type TFilterCapabilitySource = Pick<BaseDbAdapter, "canFilterField" | "isGeoSearchable">;
176
+ /** The operator each non-`compare` predicate class stands for, in `filterOps` order. */
177
+ /**
178
+ * Whether a stored leaf physically supports a filter predicate of this class
179
+ * — the one rule the core path guard and moost-db's HTTP capability index
180
+ * both apply:
181
+ *
182
+ * - `compare` → `adapter.canFilterField(fd)`;
183
+ * - `exists` → any stored column: it tests whether the column holds a value
184
+ * (SQL `IS [NOT] NULL`), never its content, so the scalar veto (JSON /
185
+ * array storage on relational adapters) does not apply;
186
+ * - `geo` → a `db.geoPoint` leaf on a geo-searchable adapter.
187
+ *
188
+ * `@db.encrypted` vetoes every class.
189
+ */
190
+ declare function canFilterLeaf(fd: TDbFieldMeta, predicate: TFilterPredicate, adapter: TFilterCapabilitySource): boolean;
191
+ /**
192
+ * The operators of the non-`compare` predicate classes a leaf physically
193
+ * accepts — named in a value-comparison rejection by the core guard, and
194
+ * listed (under the HTTP policy) as `/meta.fields[P].filterOps`.
195
+ */
196
+ declare function narrowerFilterOps(fd: TDbFieldMeta, adapter: TFilterCapabilitySource): string[];
197
+ /** The rejection suffix naming {@link narrowerFilterOps} — `""` when there are none. */
198
+ declare function acceptedOperatorsHint(ops: readonly string[]): string;
199
+ /**
200
+ * The table side of a {@link bucketSourceVerdict}: `TableMetadata` itself,
201
+ * or moost-db's capability index assembling the same names from a readable.
202
+ */
203
+ interface TBucketSourceTable {
204
+ /** Paths of the `isJsonValueField` descriptors — see `jsonValueAncestor`. */
205
+ jsonValueParents: ReadonlySet<string>;
206
+ /** Declared dimensions / measures — see {@link isStrictTable}. */
207
+ dimensions: readonly string[];
208
+ measures: readonly string[];
209
+ }
210
+ /**
211
+ * {@link bucketSourceVerdict}'s answer. `reason` is the shared clause (no
212
+ * trailing period) both layers put after the dash: the core's
213
+ * `Cannot bucket "P" — <reason>`, moost-db's
214
+ * `Bucketing field "P" is not permitted — <reason>.`
215
+ */
216
+ type TBucketSourceVerdict = {
217
+ ok: true;
218
+ } | {
219
+ ok: false;
220
+ code: "encrypted" | "jsonDescendant" | "notTimestamp" | "notFilterable" | "notDimension" | "noBuckets";
221
+ reason: string;
222
+ };
223
+ /**
224
+ * Whether the stored leaf `fd` may be the source of a calendar bucket
225
+ * (since 0.1.133) — every schema and adapter rule, once, for the core path
226
+ * guard ({@link guardPath} op `bucket`) and moost-db's capability index
227
+ * (`/meta.fields[P].bucketable` and the HTTP gate) alike. First failing rule
228
+ * wins, in this order:
229
+ *
230
+ * 1. `encrypted` — `@db.encrypted` (ciphertext has no calendar);
231
+ * 2. `jsonDescendant` — inside a JSON value (`jsonValueAncestor`):
232
+ * relational adapters cannot address it and nested-object adapters must
233
+ * not diverge from them;
234
+ * 3. `notTimestamp` — not a `number.timestamp` leaf;
235
+ * 4. `notFilterable` — the adapter cannot filter (so cannot group) the storage;
236
+ * 5. `notDimension` — a strict table ({@link isStrictTable}) and the field
237
+ * is not a dimension;
238
+ * 6. `noBuckets` — the adapter reports no `calendarBucketUnits()`.
239
+ *
240
+ * Whether the adapter supports the requested UNIT is a per-query rule, not
241
+ * a field's (the core's `BUCKET_NOT_SUPPORTED`). Caller-specific policy
242
+ * layers on top: moost-db rejects `@db.writeOnly` sources before asking.
243
+ */
244
+ declare function bucketSourceVerdict(fd: TDbFieldMeta, table: TBucketSourceTable, adapter: Pick<BaseDbAdapter, "canFilterField" | "calendarBucketUnits">): TBucketSourceVerdict;
140
245
  /** Every logical path a parsed query references, grouped by position (since 0.1.128). */
141
246
  interface TQueryPathRefs {
142
- /** Filter keys (recursing through `$and` / `$or` / `$not`), minus the geo predicates below. */
143
- filter: string[];
144
247
  /**
145
- * Filter keys whose predicate is `$geoWithin`. Their shape and index support
146
- * are validated by `guardFilter`, so the core path guard skips the adapter's
147
- * scalar filter veto for them; the HTTP gate checks them like any filter path.
248
+ * Filter entries (recursing through `$and` / `$or` / `$not`), one per
249
+ * occurrence, each with its predicate class (since 0.1.132; replaces the
250
+ * `string[]` + `geoFilter` split).
148
251
  */
149
- geoFilter: string[];
252
+ filter: TFilterRef[];
150
253
  sort: string[];
151
254
  select: string[];
255
+ /** Grouped FIELD paths — calendar-bucket aliases are not listed (their sources are in {@link bucket}). */
152
256
  groupBy: string[];
153
257
  having: string[];
154
258
  /** Aggregate `$field`s (`*` excluded). Only populated in aggregate mode. */
155
259
  aggregate: string[];
156
- /** `true` in aggregate mode: `$select` entries are aggregate expressions, aliases are exempt in `$sort` / `$having`. */
260
+ /** Calendar-bucket source `$field`s (since 0.1.132). Only populated in aggregate mode. */
261
+ bucket: string[];
262
+ /**
263
+ * `true` in aggregate mode: `$select` computed entries (aggregates, calendar
264
+ * buckets) are collected and their aliases are exempt in `$sort` / `$having`.
265
+ */
157
266
  aggregateMode: boolean;
158
267
  /**
159
268
  * First filter-node `$`-key that is not `$and` / `$or` / `$not`. uniqu's
@@ -168,10 +277,13 @@ interface TQueryPathRefs {
168
277
  * visited — they are validated against their target relation separately.
169
278
  *
170
279
  * Aggregate mode is `aggregate` when given, else the presence of `$groupBy`.
171
- * In aggregate mode `$select` entries are aggregate expressions whose
172
- * `$field` is collected and whose alias (`$as`, else `fn_field` — the core's
173
- * `resolveAlias`) is exempted from `$sort` / `$having`; outside it non-string
174
- * `$select` entries are ignored (the projection seal handles them).
280
+ * In aggregate mode `$select` computed entries are collected by kind — an
281
+ * aggregate's `$field` into `aggregate`, a calendar bucket's into `bucket` —
282
+ * and their aliases (`$as`, else uniqu's `resolveAlias`) are exempted from
283
+ * `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
284
+ * lists grouped fields only.
285
+ *
286
+ * Entry shapes are not checked here — see `resolveCalendarBuckets`.
175
287
  */
176
288
  declare function collectQueryPaths(query: TGuardedQuery, aggregate?: boolean): TQueryPathRefs;
177
289
  /** What a logical path is on THIS readable / adapter (since 0.1.128). */
@@ -211,21 +323,22 @@ declare function classifyQueryPath(source: TQueryPathSource, path: string): {
211
323
  * metadata and adapter capability — the classification of
212
324
  * {@link classifyQueryPath} plus the position's physical requirement:
213
325
  *
214
- * - a leaf → physical capability (`canFilterField` / `canSortField`;
215
- * `$select` always passes);
326
+ * - a leaf → physical capability (`canSortField` for `$sort`; for a filter
327
+ * entry {@link canFilterLeaf} of its `predicate` class; `canFilterField`
328
+ * for `$groupBy` / `$having` / aggregate `$field`s; `$select` always passes);
329
+ * a calendar-bucket source must pass `bucketSourceVerdict` (the rules
330
+ * moost-db's capability index applies too);
216
331
  * - a nested-object parent → only `$select`, and only when it expands to
217
332
  * leaf columns (`selectExpansion`);
218
333
  * - everything else is rejected.
219
334
  *
220
- * `geoPredicate` marks a filter entry whose operator is `$geoWithin`: its
221
- * shape and index support were already validated by {@link guardFilter}, so
222
- * the adapter's scalar `canFilterField` veto does not apply.
335
+ * `predicate` is a filter entry's class; other positions leave the default.
223
336
  *
224
337
  * Messages are the short programmatic forms; the HTTP wording (moost-db's
225
338
  * `FieldCapabilityIndex`, with `$with` hints and leaf lists) is what clients
226
339
  * see and is authoritative — the HTTP gate always answers first.
227
340
  */
228
- declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, geoPredicate?: boolean): void;
341
+ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, predicate?: TFilterPredicate): void;
229
342
  /**
230
343
  * Core backstop for every read / aggregate / mutation-filter entry point:
231
344
  * each referenced path (see {@link collectQueryPaths}) must exist on THIS
@@ -233,21 +346,29 @@ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: st
233
346
  * {@link guardPath}). Adapters may therefore assume every path they receive
234
347
  * is physical.
235
348
  *
236
- * In aggregate mode (`aggregate = true`) `$select` entries are aggregate
237
- * expressions whose `$field` is checked, `$groupBy` fields are checked, and
238
- * aggregate aliases (`$as` or `fn_field`) are exempt in `$sort` / `$having`.
349
+ * Entry shapes are the caller's to normalize first (`resolveCalendarBuckets`
350
+ * — {@link guardQuery} / {@link guardAggregate} do).
351
+ *
352
+ * In aggregate mode (`aggregate = true`) `$select` computed entries have
353
+ * their `$field` checked (aggregates as `aggregate`, calendar buckets as
354
+ * `bucket`), `$groupBy` fields are checked, and computed aliases (`$as` or
355
+ * the default) are exempt in `$sort` / `$having`.
239
356
  *
240
357
  * Returns the collected refs so callers can run further structural rules
241
358
  * (see {@link checkHavingKeys}) without walking the query again.
242
359
  */
243
360
  declare function guardPaths(meta: TableMetadata, adapter: BaseDbAdapter, query: TGuardedQuery | undefined, aggregate?: boolean): TQueryPathRefs | undefined;
244
- /** Shared read-path guard: filter + $sort encryption checks, then the path guard. */
361
+ /**
362
+ * Shared read-path guard: filter + $sort encryption checks, the `$select`
363
+ * normalizer (a calendar bucket is invalid outside a grouped query), then
364
+ * the path guard.
365
+ */
245
366
  declare function guardQuery(meta: TableMetadata, adapter: BaseDbAdapter, query: TGuardedQuery | undefined): void;
246
367
  /**
247
- * `$having` is a post-aggregation filter, so a key is either an aggregate
248
- * alias (`$as`, else `fn_field` — already exempt in {@link collectQueryPaths})
249
- * or a `$groupBy` field (exact logical-path match: `metadata.clicks` grouped
250
- * stays valid). Any other key — a real but non-grouped column included — is
368
+ * `$having` is a post-aggregation filter, so a key is either a computed
369
+ * alias (aggregate or calendar bucket — already exempt in
370
+ * {@link collectQueryPaths}) or a `$groupBy` field (exact logical-path
371
+ * match: `metadata.clicks` grouped stays valid). Any other key — a real but non-grouped column included — is
251
372
  * rejected here, once, for SDK and HTTP callers alike, instead of by the
252
373
  * engine (PostgreSQL / MySQL error, SQLite tolerance, Mongo `[]`). Returns
253
374
  * the first offending key as an error entry (`path` = the bare key, as the
@@ -259,11 +380,15 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
259
380
  } | undefined;
260
381
  /**
261
382
  * Aggregate-path guard: $groupBy / $select / $having encryption refs + filter
262
- * + $sort, then the path guard, then the `$having` key rule
383
+ * + $sort, then the path guard, then the adapter's calendar-bucket units
384
+ * (`BUCKET_NOT_SUPPORTED`), then the `$having` key rule
263
385
  * ({@link checkHavingKeys} — after the path guard so an unknown key still
264
386
  * reads `Unknown field`).
387
+ *
388
+ * `buckets` are the query's resolved calendar buckets when the caller already
389
+ * ran `resolveCalendarBuckets` (resolved here otherwise).
265
390
  */
266
- declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1): void;
391
+ declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: readonly ResolvedBucket$1[]): void;
267
392
  //#endregion
268
393
  //#region src/with-optimistic-retry.d.ts
269
394
  interface WithOptimisticRetryOptions {
@@ -362,4 +487,4 @@ declare function createFailureCollector(what: string): {
362
487
  throwIfAny: () => void;
363
488
  };
364
489
  //#endregion
365
- export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, 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, CasExhaustedError, CasMismatchError, DEFAULT_DB_SPACE, type DbControls, DbEncryption, DbError, type DbErrorCode, type DbPatch, type DbQuery, type DbResponse, type DbRow, DbSpace, type DbValidationContext, DocumentFieldMapper, FieldMappingStrategy, type FieldOpsFor, type FilterExpr, type FilterVisitor, type FlatOf, IntegrityStrategy, NativeIntegrity, type NavPropsOf, NoopLogger, type NullableOptional, type OwnPropsOf, type PrimaryKeyOf, RelationalFieldMapper, type TAdapterFactory, type TArrayPatch, 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 TFkLookupResolver, type TFkLookupTarget, type TGenericLogger, type TGuardedQuery, type TIdDescriptor, type TIdentification, type TMetaResponse, type TMetadataOverrides, type TPrimaryKeyChange, type TQueryPathKind, type TQueryPathOp, type TQueryPathRefs, type TQueryPathSource, type TReferencingForeignKey, type TRelationInfo, 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 WithOptimisticRetryOptions, type WithRelation, assertGeoPoint, assertNoVersionWrites, buildDbValidator, buildValidationContext, checkHavingKeys, classifyQueryPath, collectQueryPaths, computeInsights, createDbValidatorPlugin, createFailureCollector, decomposePatch, findAncestorInSet, forceNavNonOptional, getDbFieldOp, getKeyProps, guardAggregate, guardFilter, guardPath, guardPaths, guardQuery, isAtscriptDbView, isDbFieldOp, isEmptyObject, isGeoIndexableType, isGeoPointType, isNavRelation, isPlainObject, isPrimitive, reconcileCas, resolveDesignType, separateCas, separateFieldOps, sortFieldNames, translateQueryTree, unsupportedOperatorMessage, walkFilter, withOptimisticRetry };
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 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 };