@atscript/db 0.1.130 → 0.1.132

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-B7eYWS5q.d.cts → buckets-BvoYYQ2Q.d.cts} +1348 -1142
  6. package/dist/{db-readable-Bn1bV_eC.d.mts → buckets-D2XPrwSC.d.mts} +1348 -1142
  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-C2UCnGHd.d.cts → db-space-BQQEgB3d.d.mts} +2 -2
  10. package/dist/{db-space-DdIPYD0Q.d.mts → db-space-Cslq5Dux.d.cts} +2 -2
  11. package/dist/{db-view-hkwQ-fHJ.cjs → db-view-CuFAhzwF.cjs} +487 -123
  12. package/dist/{db-view-BkF2xEGd.mjs → db-view-DVGWWhA3.mjs} +439 -123
  13. package/dist/index.cjs +13 -4
  14. package/dist/index.d.cts +105 -38
  15. package/dist/index.d.mts +105 -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-hkwQ-fHJ.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-CuFAhzwF.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,7 @@ 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.ALL_BUCKET_UNITS = require_db_view.ALL_BUCKET_UNITS;
385
386
  exports.ApplicationIntegrity = require_db_view.ApplicationIntegrity;
386
387
  exports.AtscriptDbReadable = require_db_view.AtscriptDbReadable;
387
388
  exports.AtscriptDbTable = require_db_view.AtscriptDbTable;
@@ -401,10 +402,13 @@ exports.NoopLogger = require_db_view.NoopLogger;
401
402
  exports.RelationalFieldMapper = require_db_view.RelationalFieldMapper;
402
403
  exports.TableMetadata = require_db_view.TableMetadata;
403
404
  exports.UniquSelect = require_db_view.UniquSelect;
405
+ exports.acceptedOperatorsHint = require_db_view.acceptedOperatorsHint;
404
406
  exports.assertGeoPoint = require_db_view.assertGeoPoint;
405
407
  exports.assertNoVersionWrites = require_db_view.assertNoVersionWrites;
408
+ exports.bucketTimeZoneUnavailable = require_db_error.bucketTimeZoneUnavailable;
406
409
  exports.buildDbValidator = require_validator.buildDbValidator;
407
410
  exports.buildValidationContext = require_validator.buildValidationContext;
411
+ exports.canFilterLeaf = require_db_view.canFilterLeaf;
408
412
  exports.checkHavingKeys = require_db_view.checkHavingKeys;
409
413
  exports.classifyQueryPath = require_db_view.classifyQueryPath;
410
414
  exports.collectQueryPaths = require_db_view.collectQueryPaths;
@@ -427,10 +431,12 @@ exports.guardPath = require_db_view.guardPath;
427
431
  exports.guardPaths = require_db_view.guardPaths;
428
432
  exports.guardQuery = require_db_view.guardQuery;
429
433
  exports.isAtscriptDbView = require_db_view.isAtscriptDbView;
434
+ exports.isBucketableField = require_db_view.isBucketableField;
430
435
  exports.isDbFieldOp = require_ops.isDbFieldOp;
431
436
  exports.isEmptyObject = require_validator.isEmptyObject;
432
437
  exports.isGeoIndexableType = require_db_view.isGeoIndexableType;
433
438
  exports.isGeoPointType = require_db_view.isGeoPointType;
439
+ exports.isJsonValueField = require_db_view.isJsonValueField;
434
440
  exports.isNavRelation = require_validator.isNavRelation;
435
441
  exports.isPlainObject = require_validator.isPlainObject;
436
442
  Object.defineProperty(exports, "isPrimitive", {
@@ -439,7 +445,10 @@ Object.defineProperty(exports, "isPrimitive", {
439
445
  return _uniqu_core.isPrimitive;
440
446
  }
441
447
  });
448
+ exports.jsonValueAncestor = require_db_view.jsonValueAncestor;
449
+ exports.narrowerFilterOps = require_db_view.narrowerFilterOps;
442
450
  exports.reconcileCas = require_ops.reconcileCas;
451
+ exports.resolveCalendarBuckets = require_db_view.resolveCalendarBuckets;
443
452
  exports.resolveDesignType = require_db_view.resolveDesignType;
444
453
  exports.separateCas = require_ops.separateCas;
445
454
  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-B7eYWS5q.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-BvoYYQ2Q.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-C2UCnGHd.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-Cslq5Dux.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,29 @@ 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 non-timestamp field → `INVALID_QUERY`; a unit
110
+ * the adapter's `calendarBucketUnits()` lacks → `BUCKET_NOT_SUPPORTED`
103
111
  * - every filter / `$sort` / `$select` / `$groupBy` / `$having` / aggregate
104
112
  * 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.
113
+ * capability its position (for a filter entry: its predicate class, see
114
+ * {@link canFilterLeaf}) needs → `INVALID_QUERY` (see {@link guardPaths}).
115
+ * Runs after the checks above so `ENC_*` codes keep firing first for
116
+ * encrypted subtrees.
108
117
  */
109
118
  /** Validates a `[lng, lat]` tuple (GeoJSON coordinate order). */
110
119
  declare function assertGeoPoint(point: unknown, path: string): asserts point is [number, number];
111
120
  /**
112
121
  * Walks a filter expression, rejecting encrypted-field references and
113
- * validating `$geoWithin` operator nodes.
122
+ * validating operator operands: `$geoWithin` shapes and the boolean
123
+ * `$exists` operand (this is the one owner of that rule).
114
124
  */
115
125
  declare function guardFilter(meta: TableMetadata, adapter: BaseDbAdapter, filter: FilterExpr$1 | undefined, encCode?: "ENC_FIELD_FILTER" | "ENC_FIELD_AGG"): void;
116
126
  /** The query positions a field path can appear in. */
117
- type TQueryPathOp = "filter" | "sort" | "select" | "groupBy" | "having" | "aggregate";
127
+ 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
128
  /** Query shape accepted by {@link guardPaths} / {@link collectQueryPaths} — the raw (pre-translation) uniqu controls. */
119
129
  interface TGuardedQuery {
120
130
  filter?: FilterExpr$1;
@@ -137,23 +147,64 @@ declare function unsupportedOperatorMessage(op: string): string;
137
147
  * walker so programmatic callers get the same acceptance set.
138
148
  */
139
149
  declare function sortFieldNames(sort: unknown): string[];
150
+ /**
151
+ * The operator class a filter entry needs from its field (since 0.1.132):
152
+ * - `compare` — value comparison (bare values, `$eq`, `$gt`, `$in`, `$regex`, any mix);
153
+ * - `geo` — a `$geoWithin` entry;
154
+ * - `exists` — an entry whose sole operator is `$exists`.
155
+ */
156
+ type TFilterPredicate = "compare" | "geo" | "exists";
157
+ /** One filter entry, collected per occurrence: its key and the predicate class its operators need. */
158
+ interface TFilterRef {
159
+ path: string;
160
+ predicate: TFilterPredicate;
161
+ }
162
+ /** The adapter-shaped capability {@link canFilterLeaf} consults (a `BaseDbAdapter` or a readable). */
163
+ type TFilterCapabilitySource = Pick<BaseDbAdapter, "canFilterField" | "isGeoSearchable">;
164
+ /** The operator each non-`compare` predicate class stands for, in `filterOps` order. */
165
+ /**
166
+ * Whether a stored leaf physically supports a filter predicate of this class
167
+ * — the one rule the core path guard and moost-db's HTTP capability index
168
+ * both apply:
169
+ *
170
+ * - `compare` → `adapter.canFilterField(fd)`;
171
+ * - `exists` → any stored column: it tests whether the column holds a value
172
+ * (SQL `IS [NOT] NULL`), never its content, so the scalar veto (JSON /
173
+ * array storage on relational adapters) does not apply;
174
+ * - `geo` → a `db.geoPoint` leaf on a geo-searchable adapter.
175
+ *
176
+ * `@db.encrypted` vetoes every class.
177
+ */
178
+ declare function canFilterLeaf(fd: TDbFieldMeta, predicate: TFilterPredicate, adapter: TFilterCapabilitySource): boolean;
179
+ /**
180
+ * The operators of the non-`compare` predicate classes a leaf physically
181
+ * accepts — named in a value-comparison rejection by the core guard, and
182
+ * listed (under the HTTP policy) as `/meta.fields[P].filterOps`.
183
+ */
184
+ declare function narrowerFilterOps(fd: TDbFieldMeta, adapter: TFilterCapabilitySource): string[];
185
+ /** The rejection suffix naming {@link narrowerFilterOps} — `""` when there are none. */
186
+ declare function acceptedOperatorsHint(ops: readonly string[]): string;
140
187
  /** Every logical path a parsed query references, grouped by position (since 0.1.128). */
141
188
  interface TQueryPathRefs {
142
- /** Filter keys (recursing through `$and` / `$or` / `$not`), minus the geo predicates below. */
143
- filter: string[];
144
189
  /**
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.
190
+ * Filter entries (recursing through `$and` / `$or` / `$not`), one per
191
+ * occurrence, each with its predicate class (since 0.1.132; replaces the
192
+ * `string[]` + `geoFilter` split).
148
193
  */
149
- geoFilter: string[];
194
+ filter: TFilterRef[];
150
195
  sort: string[];
151
196
  select: string[];
197
+ /** Grouped FIELD paths — calendar-bucket aliases are not listed (their sources are in {@link bucket}). */
152
198
  groupBy: string[];
153
199
  having: string[];
154
200
  /** Aggregate `$field`s (`*` excluded). Only populated in aggregate mode. */
155
201
  aggregate: string[];
156
- /** `true` in aggregate mode: `$select` entries are aggregate expressions, aliases are exempt in `$sort` / `$having`. */
202
+ /** Calendar-bucket source `$field`s (since 0.1.132). Only populated in aggregate mode. */
203
+ bucket: string[];
204
+ /**
205
+ * `true` in aggregate mode: `$select` computed entries (aggregates, calendar
206
+ * buckets) are collected and their aliases are exempt in `$sort` / `$having`.
207
+ */
157
208
  aggregateMode: boolean;
158
209
  /**
159
210
  * First filter-node `$`-key that is not `$and` / `$or` / `$not`. uniqu's
@@ -168,10 +219,13 @@ interface TQueryPathRefs {
168
219
  * visited — they are validated against their target relation separately.
169
220
  *
170
221
  * 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).
222
+ * In aggregate mode `$select` computed entries are collected by kind — an
223
+ * aggregate's `$field` into `aggregate`, a calendar bucket's into `bucket` —
224
+ * and their aliases (`$as`, else uniqu's `resolveAlias`) are exempted from
225
+ * `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
226
+ * lists grouped fields only.
227
+ *
228
+ * Entry shapes are not checked here — see `resolveCalendarBuckets`.
175
229
  */
176
230
  declare function collectQueryPaths(query: TGuardedQuery, aggregate?: boolean): TQueryPathRefs;
177
231
  /** What a logical path is on THIS readable / adapter (since 0.1.128). */
@@ -211,21 +265,22 @@ declare function classifyQueryPath(source: TQueryPathSource, path: string): {
211
265
  * metadata and adapter capability — the classification of
212
266
  * {@link classifyQueryPath} plus the position's physical requirement:
213
267
  *
214
- * - a leaf → physical capability (`canFilterField` / `canSortField`;
215
- * `$select` always passes);
268
+ * - a leaf → physical capability (`canSortField` for `$sort`; for a filter
269
+ * entry {@link canFilterLeaf} of its `predicate` class; `canFilterField`
270
+ * for `$groupBy` / `$having` / aggregate `$field`s; `$select` always passes);
271
+ * a calendar-bucket source must also be a timestamp field
272
+ * (`isBucketableField`);
216
273
  * - a nested-object parent → only `$select`, and only when it expands to
217
274
  * leaf columns (`selectExpansion`);
218
275
  * - everything else is rejected.
219
276
  *
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.
277
+ * `predicate` is a filter entry's class; other positions leave the default.
223
278
  *
224
279
  * Messages are the short programmatic forms; the HTTP wording (moost-db's
225
280
  * `FieldCapabilityIndex`, with `$with` hints and leaf lists) is what clients
226
281
  * see and is authoritative — the HTTP gate always answers first.
227
282
  */
228
- declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, geoPredicate?: boolean): void;
283
+ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, predicate?: TFilterPredicate): void;
229
284
  /**
230
285
  * Core backstop for every read / aggregate / mutation-filter entry point:
231
286
  * each referenced path (see {@link collectQueryPaths}) must exist on THIS
@@ -233,21 +288,29 @@ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: st
233
288
  * {@link guardPath}). Adapters may therefore assume every path they receive
234
289
  * is physical.
235
290
  *
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`.
291
+ * Entry shapes are the caller's to normalize first (`resolveCalendarBuckets`
292
+ * — {@link guardQuery} / {@link guardAggregate} do).
293
+ *
294
+ * In aggregate mode (`aggregate = true`) `$select` computed entries have
295
+ * their `$field` checked (aggregates as `aggregate`, calendar buckets as
296
+ * `bucket`), `$groupBy` fields are checked, and computed aliases (`$as` or
297
+ * the default) are exempt in `$sort` / `$having`.
239
298
  *
240
299
  * Returns the collected refs so callers can run further structural rules
241
300
  * (see {@link checkHavingKeys}) without walking the query again.
242
301
  */
243
302
  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. */
303
+ /**
304
+ * Shared read-path guard: filter + $sort encryption checks, the `$select`
305
+ * normalizer (a calendar bucket is invalid outside a grouped query), then
306
+ * the path guard.
307
+ */
245
308
  declare function guardQuery(meta: TableMetadata, adapter: BaseDbAdapter, query: TGuardedQuery | undefined): void;
246
309
  /**
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
310
+ * `$having` is a post-aggregation filter, so a key is either a computed
311
+ * alias (aggregate or calendar bucket — already exempt in
312
+ * {@link collectQueryPaths}) or a `$groupBy` field (exact logical-path
313
+ * match: `metadata.clicks` grouped stays valid). Any other key — a real but non-grouped column included — is
251
314
  * rejected here, once, for SDK and HTTP callers alike, instead of by the
252
315
  * engine (PostgreSQL / MySQL error, SQLite tolerance, Mongo `[]`). Returns
253
316
  * the first offending key as an error entry (`path` = the bare key, as the
@@ -259,11 +322,15 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
259
322
  } | undefined;
260
323
  /**
261
324
  * Aggregate-path guard: $groupBy / $select / $having encryption refs + filter
262
- * + $sort, then the path guard, then the `$having` key rule
325
+ * + $sort, then the path guard, then the adapter's calendar-bucket units
326
+ * (`BUCKET_NOT_SUPPORTED`), then the `$having` key rule
263
327
  * ({@link checkHavingKeys} — after the path guard so an unknown key still
264
328
  * reads `Unknown field`).
329
+ *
330
+ * `buckets` are the query's resolved calendar buckets when the caller already
331
+ * ran `resolveCalendarBuckets` (resolved here otherwise).
265
332
  */
266
- declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1): void;
333
+ declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: readonly ResolvedBucket$1[]): void;
267
334
  //#endregion
268
335
  //#region src/with-optimistic-retry.d.ts
269
336
  interface WithOptimisticRetryOptions {
@@ -362,4 +429,4 @@ declare function createFailureCollector(what: string): {
362
429
  throwIfAny: () => void;
363
430
  };
364
431
  //#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 };
432
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, 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, 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 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, 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 };
package/dist/index.d.mts 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-Bn1bV_eC.mjs";
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-D2XPrwSC.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 { 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-DdIPYD0Q.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 } from "./validator-wBARmD68.mjs";
3
+ import { BucketExpr, BucketUnit, CalendarBucketLabel, ComputedExpr, ResolvedBucket, WeekStart } from "./agg.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-BQQEgB3d.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";
5
6
  import { n as createDbValidatorPlugin, t as DbValidationContext } from "./db-validator-plugin-BWy60OvG.mjs";
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,29 @@ 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 non-timestamp field → `INVALID_QUERY`; a unit
110
+ * the adapter's `calendarBucketUnits()` lacks → `BUCKET_NOT_SUPPORTED`
103
111
  * - every filter / `$sort` / `$select` / `$groupBy` / `$having` / aggregate
104
112
  * 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.
113
+ * capability its position (for a filter entry: its predicate class, see
114
+ * {@link canFilterLeaf}) needs → `INVALID_QUERY` (see {@link guardPaths}).
115
+ * Runs after the checks above so `ENC_*` codes keep firing first for
116
+ * encrypted subtrees.
108
117
  */
109
118
  /** Validates a `[lng, lat]` tuple (GeoJSON coordinate order). */
110
119
  declare function assertGeoPoint(point: unknown, path: string): asserts point is [number, number];
111
120
  /**
112
121
  * Walks a filter expression, rejecting encrypted-field references and
113
- * validating `$geoWithin` operator nodes.
122
+ * validating operator operands: `$geoWithin` shapes and the boolean
123
+ * `$exists` operand (this is the one owner of that rule).
114
124
  */
115
125
  declare function guardFilter(meta: TableMetadata, adapter: BaseDbAdapter, filter: FilterExpr$1 | undefined, encCode?: "ENC_FIELD_FILTER" | "ENC_FIELD_AGG"): void;
116
126
  /** The query positions a field path can appear in. */
117
- type TQueryPathOp = "filter" | "sort" | "select" | "groupBy" | "having" | "aggregate";
127
+ 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
128
  /** Query shape accepted by {@link guardPaths} / {@link collectQueryPaths} — the raw (pre-translation) uniqu controls. */
119
129
  interface TGuardedQuery {
120
130
  filter?: FilterExpr$1;
@@ -137,23 +147,64 @@ declare function unsupportedOperatorMessage(op: string): string;
137
147
  * walker so programmatic callers get the same acceptance set.
138
148
  */
139
149
  declare function sortFieldNames(sort: unknown): string[];
150
+ /**
151
+ * The operator class a filter entry needs from its field (since 0.1.132):
152
+ * - `compare` — value comparison (bare values, `$eq`, `$gt`, `$in`, `$regex`, any mix);
153
+ * - `geo` — a `$geoWithin` entry;
154
+ * - `exists` — an entry whose sole operator is `$exists`.
155
+ */
156
+ type TFilterPredicate = "compare" | "geo" | "exists";
157
+ /** One filter entry, collected per occurrence: its key and the predicate class its operators need. */
158
+ interface TFilterRef {
159
+ path: string;
160
+ predicate: TFilterPredicate;
161
+ }
162
+ /** The adapter-shaped capability {@link canFilterLeaf} consults (a `BaseDbAdapter` or a readable). */
163
+ type TFilterCapabilitySource = Pick<BaseDbAdapter, "canFilterField" | "isGeoSearchable">;
164
+ /** The operator each non-`compare` predicate class stands for, in `filterOps` order. */
165
+ /**
166
+ * Whether a stored leaf physically supports a filter predicate of this class
167
+ * — the one rule the core path guard and moost-db's HTTP capability index
168
+ * both apply:
169
+ *
170
+ * - `compare` → `adapter.canFilterField(fd)`;
171
+ * - `exists` → any stored column: it tests whether the column holds a value
172
+ * (SQL `IS [NOT] NULL`), never its content, so the scalar veto (JSON /
173
+ * array storage on relational adapters) does not apply;
174
+ * - `geo` → a `db.geoPoint` leaf on a geo-searchable adapter.
175
+ *
176
+ * `@db.encrypted` vetoes every class.
177
+ */
178
+ declare function canFilterLeaf(fd: TDbFieldMeta, predicate: TFilterPredicate, adapter: TFilterCapabilitySource): boolean;
179
+ /**
180
+ * The operators of the non-`compare` predicate classes a leaf physically
181
+ * accepts — named in a value-comparison rejection by the core guard, and
182
+ * listed (under the HTTP policy) as `/meta.fields[P].filterOps`.
183
+ */
184
+ declare function narrowerFilterOps(fd: TDbFieldMeta, adapter: TFilterCapabilitySource): string[];
185
+ /** The rejection suffix naming {@link narrowerFilterOps} — `""` when there are none. */
186
+ declare function acceptedOperatorsHint(ops: readonly string[]): string;
140
187
  /** Every logical path a parsed query references, grouped by position (since 0.1.128). */
141
188
  interface TQueryPathRefs {
142
- /** Filter keys (recursing through `$and` / `$or` / `$not`), minus the geo predicates below. */
143
- filter: string[];
144
189
  /**
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.
190
+ * Filter entries (recursing through `$and` / `$or` / `$not`), one per
191
+ * occurrence, each with its predicate class (since 0.1.132; replaces the
192
+ * `string[]` + `geoFilter` split).
148
193
  */
149
- geoFilter: string[];
194
+ filter: TFilterRef[];
150
195
  sort: string[];
151
196
  select: string[];
197
+ /** Grouped FIELD paths — calendar-bucket aliases are not listed (their sources are in {@link bucket}). */
152
198
  groupBy: string[];
153
199
  having: string[];
154
200
  /** Aggregate `$field`s (`*` excluded). Only populated in aggregate mode. */
155
201
  aggregate: string[];
156
- /** `true` in aggregate mode: `$select` entries are aggregate expressions, aliases are exempt in `$sort` / `$having`. */
202
+ /** Calendar-bucket source `$field`s (since 0.1.132). Only populated in aggregate mode. */
203
+ bucket: string[];
204
+ /**
205
+ * `true` in aggregate mode: `$select` computed entries (aggregates, calendar
206
+ * buckets) are collected and their aliases are exempt in `$sort` / `$having`.
207
+ */
157
208
  aggregateMode: boolean;
158
209
  /**
159
210
  * First filter-node `$`-key that is not `$and` / `$or` / `$not`. uniqu's
@@ -168,10 +219,13 @@ interface TQueryPathRefs {
168
219
  * visited — they are validated against their target relation separately.
169
220
  *
170
221
  * 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).
222
+ * In aggregate mode `$select` computed entries are collected by kind — an
223
+ * aggregate's `$field` into `aggregate`, a calendar bucket's into `bucket` —
224
+ * and their aliases (`$as`, else uniqu's `resolveAlias`) are exempted from
225
+ * `$sort` / `$having`; a bucket alias is also dropped from `groupBy`, which
226
+ * lists grouped fields only.
227
+ *
228
+ * Entry shapes are not checked here — see `resolveCalendarBuckets`.
175
229
  */
176
230
  declare function collectQueryPaths(query: TGuardedQuery, aggregate?: boolean): TQueryPathRefs;
177
231
  /** What a logical path is on THIS readable / adapter (since 0.1.128). */
@@ -211,21 +265,22 @@ declare function classifyQueryPath(source: TQueryPathSource, path: string): {
211
265
  * metadata and adapter capability — the classification of
212
266
  * {@link classifyQueryPath} plus the position's physical requirement:
213
267
  *
214
- * - a leaf → physical capability (`canFilterField` / `canSortField`;
215
- * `$select` always passes);
268
+ * - a leaf → physical capability (`canSortField` for `$sort`; for a filter
269
+ * entry {@link canFilterLeaf} of its `predicate` class; `canFilterField`
270
+ * for `$groupBy` / `$having` / aggregate `$field`s; `$select` always passes);
271
+ * a calendar-bucket source must also be a timestamp field
272
+ * (`isBucketableField`);
216
273
  * - a nested-object parent → only `$select`, and only when it expands to
217
274
  * leaf columns (`selectExpansion`);
218
275
  * - everything else is rejected.
219
276
  *
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.
277
+ * `predicate` is a filter entry's class; other positions leave the default.
223
278
  *
224
279
  * Messages are the short programmatic forms; the HTTP wording (moost-db's
225
280
  * `FieldCapabilityIndex`, with `$with` hints and leaf lists) is what clients
226
281
  * see and is authoritative — the HTTP gate always answers first.
227
282
  */
228
- declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, geoPredicate?: boolean): void;
283
+ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: string, op: TQueryPathOp, predicate?: TFilterPredicate): void;
229
284
  /**
230
285
  * Core backstop for every read / aggregate / mutation-filter entry point:
231
286
  * each referenced path (see {@link collectQueryPaths}) must exist on THIS
@@ -233,21 +288,29 @@ declare function guardPath(meta: TableMetadata, adapter: BaseDbAdapter, path: st
233
288
  * {@link guardPath}). Adapters may therefore assume every path they receive
234
289
  * is physical.
235
290
  *
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`.
291
+ * Entry shapes are the caller's to normalize first (`resolveCalendarBuckets`
292
+ * — {@link guardQuery} / {@link guardAggregate} do).
293
+ *
294
+ * In aggregate mode (`aggregate = true`) `$select` computed entries have
295
+ * their `$field` checked (aggregates as `aggregate`, calendar buckets as
296
+ * `bucket`), `$groupBy` fields are checked, and computed aliases (`$as` or
297
+ * the default) are exempt in `$sort` / `$having`.
239
298
  *
240
299
  * Returns the collected refs so callers can run further structural rules
241
300
  * (see {@link checkHavingKeys}) without walking the query again.
242
301
  */
243
302
  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. */
303
+ /**
304
+ * Shared read-path guard: filter + $sort encryption checks, the `$select`
305
+ * normalizer (a calendar bucket is invalid outside a grouped query), then
306
+ * the path guard.
307
+ */
245
308
  declare function guardQuery(meta: TableMetadata, adapter: BaseDbAdapter, query: TGuardedQuery | undefined): void;
246
309
  /**
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
310
+ * `$having` is a post-aggregation filter, so a key is either a computed
311
+ * alias (aggregate or calendar bucket — already exempt in
312
+ * {@link collectQueryPaths}) or a `$groupBy` field (exact logical-path
313
+ * match: `metadata.clicks` grouped stays valid). Any other key — a real but non-grouped column included — is
251
314
  * rejected here, once, for SDK and HTTP callers alike, instead of by the
252
315
  * engine (PostgreSQL / MySQL error, SQLite tolerance, Mongo `[]`). Returns
253
316
  * the first offending key as an error entry (`path` = the bare key, as the
@@ -259,11 +322,15 @@ declare function checkHavingKeys(refs: TQueryPathRefs): {
259
322
  } | undefined;
260
323
  /**
261
324
  * Aggregate-path guard: $groupBy / $select / $having encryption refs + filter
262
- * + $sort, then the path guard, then the `$having` key rule
325
+ * + $sort, then the path guard, then the adapter's calendar-bucket units
326
+ * (`BUCKET_NOT_SUPPORTED`), then the `$having` key rule
263
327
  * ({@link checkHavingKeys} — after the path guard so an unknown key still
264
328
  * reads `Unknown field`).
329
+ *
330
+ * `buckets` are the query's resolved calendar buckets when the caller already
331
+ * ran `resolveCalendarBuckets` (resolved here otherwise).
265
332
  */
266
- declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1): void;
333
+ declare function guardAggregate(meta: TableMetadata, adapter: BaseDbAdapter, query: AggregateQuery$1, resolved?: readonly ResolvedBucket$1[]): void;
267
334
  //#endregion
268
335
  //#region src/with-optimistic-retry.d.ts
269
336
  interface WithOptimisticRetryOptions {
@@ -362,4 +429,4 @@ declare function createFailureCollector(what: string): {
362
429
  throwIfAny: () => void;
363
430
  };
364
431
  //#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 };
432
+ export { $cas, $dec, $inc, $insert, $mul, $remove, $replace, $update, $upsert, 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, 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 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, 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 };