@atscript/db-client 0.1.206 → 0.1.207

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.
@@ -1,7 +1,7 @@
1
- import { AggregateQuery, AggregateQuery as AggregateQuery$1, AggregateResult, AggregateResult as AggregateResult$1, AggregateStage, BucketExpr, BucketUnit, CalendarBucketLabel, ComputedExpr, FilterExpr, NestedAggregateQuery, NestedAggregateQuery as NestedAggregateQuery$1, NestedAggregateResult, NestedAggregateResult as NestedAggregateResult$1, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, ValidGroupBy, ValidGroupBy as ValidGroupBy$1, ValidNested, ValidNested as ValidNested$1, WeekStart } from "@uniqu/core";
1
+ import { AggregateControls, AggregateControls as AggregateControls$1, AggregateQuery, AggregateResult, AggregateStage, BucketExpr, BucketUnit, CalendarBucketLabel, FilterExpr, FilterExpr as FilterExpr$1, NestedAggregateControls, NestedAggregateControls as NestedAggregateControls$1, NestedAggregateQuery, NestedAggregateResult, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, UniqueryInsights, UniqueryInsights as UniqueryInsights$1, ValidAggSort, ValidGroupBy, ValidNested, WeekStart } from "@uniqu/core";
2
2
  import { TAtscriptAnnotatedType, TAtscriptTypeObject } from "@atscript/typescript/utils";
3
- import { DbInsert, DbPatch, DbResponse, DbRow, TDbActionInfo, TDbActionTargetSummary, TDbAvailableActions, TDbDeleteResult, TDbDeleteResult as TDbDeleteResult$1, TDbInsertIgnoreResult, TDbInsertIgnoreResult as TDbInsertIgnoreResult$1, TDbInsertManyIgnoreResult, TDbInsertManyIgnoreResult as TDbInsertManyIgnoreResult$1, TDbInsertManyResult, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult, TDbUpdateResult as TDbUpdateResult$1, TDbVersion, TFieldMeta, TMetaResponse, TRelationInfo, TSearchIndexInfo } from "@atscript/db";
4
3
  import { DbValidationContext, ValidatorMode, ValidatorMode as ValidatorMode$1 } from "@atscript/db/validator";
4
+ import { AggregateControlsCheck, AggregateRows, DbInsert, DbPatch, DbResponse, DbRow, TDbActionInfo, TDbActionTargetSummary, TDbAvailableActions, TDbDeleteResult, TDbDeleteResult as TDbDeleteResult$1, TDbInsertIgnoreResult, TDbInsertIgnoreResult as TDbInsertIgnoreResult$1, TDbInsertManyIgnoreResult, TDbInsertManyIgnoreResult as TDbInsertManyIgnoreResult$1, TDbInsertManyResult, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult, TDbUpdateResult as TDbUpdateResult$1, TDbVersion, TFieldMeta, TMetaResponse, TRelationInfo, TSearchIndexInfo } from "@atscript/db";
5
5
 
6
6
  //#region src/meta-store.d.ts
7
7
  /** Options for {@link MetaStore}. */
@@ -307,6 +307,14 @@ type NavOf<T> = T extends {
307
307
  type IdOf<T> = T extends {
308
308
  __pk: infer PK;
309
309
  } ? PK : unknown;
310
+ /**
311
+ * The write model of `T`: a `@db.view.writable` view's table (the type-only
312
+ * `static __write` the atscript 0.2.30+ d.ts declares on such a view), else `T`
313
+ * itself. `Client` / `ClientLike` default their `W` to it (since 0.1.207).
314
+ */
315
+ type WriteOf<T> = T extends {
316
+ __write: infer W extends AtscriptClientShape;
317
+ } ? W : T;
310
318
  /**
311
319
  * Narrow a read-method response type by the literal `$with` array in the
312
320
  * query, mirroring the backend's `DbResponse<Data, Nav, Q>` algebra. Nav
@@ -365,8 +373,9 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
365
373
  * `getActionForm` (`null`) and `getActionFormTexts` (`undefined`); and rejects the rest.
366
374
  *
367
375
  * `W` (since 0.1.205; before: the display-only fields `D`) is the write model: `insert`,
368
- * `update`, `replace` and `remove` are typed by it, every read by `T` — `ClientLike<typeof
369
- * TicketRow, typeof Ticket>` for a writable view over its table. Defaults to `T`.
376
+ * `update`, `replace` and `remove` are typed by it, every read by `T`. Defaults to
377
+ * `WriteOf<T>` (since 0.1.207; before: `T`): a `@db.view.writable` view's table, else `T` —
378
+ * `ClientLike<typeof TicketRow>` reads through the view and writes `Ticket`.
370
379
  *
371
380
  * `O` (since 0.1.199) is the per-call options the read / write methods take: an implementation
372
381
  * with options of its own declares them as `O`, an interface extending {@link TClientCallOptions}
@@ -375,7 +384,7 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
375
384
  * (and `insert`'s `onConflict` / `returning`).
376
385
  * @since 0.1.196
377
386
  */
378
- type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, W, O>, keyof Client<T, W, O>>;
387
+ type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = WriteOf<T>, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, W, O>, keyof Client<T, W, O>>;
379
388
  //#endregion
380
389
  //#region src/client-error.d.ts
381
390
  /**
@@ -692,16 +701,6 @@ type SingleInsertOf<T> = [keyof InsertOf<T>] extends [never] ? Record<string, an
692
701
  } : InsertOf<T>;
693
702
  /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape (over the read model `T`). */
694
703
  type InsertedRow<T> = Response<T, Record<never, never>>;
695
- /** A two-level aggregate query: one with `controls.$from`. */
696
- type NestedShape = {
697
- controls: {
698
- $from: object;
699
- };
700
- };
701
- /** The compile-time check an aggregate query must pass: two-level or flat. */
702
- type AggregateCheck<T, Q> = Q extends NestedShape ? ValidNested<T, Q> : ValidGroupBy<T, Q>;
703
- /** The rows `aggregate()` answers for query `Q`. */
704
- type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q extends NestedShape ? NestedAggregateResult<T, Q>[] : Q["controls"]["$select"] extends readonly (string | ComputedExpr)[] ? AggregateResult<T, Q["controls"]["$select"]>[] : Record<string, unknown>[];
705
704
  /**
706
705
  * HTTP client for moost-db REST endpoints.
707
706
  *
@@ -723,14 +722,16 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
723
722
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
724
723
  * ```
725
724
  *
726
- * `W` (since 0.1.205; before: the display-only fields `D`) is the write model,
727
- * `T` by default: `insert`, `update`, `replace` and `remove` are typed by `W`,
728
- * every read — rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids,
729
- * the row `insert(…, { returning: true })` answers — by `T`. A writable view
730
- * reads through the view and writes its table:
725
+ * `W` (since 0.1.205; before: the display-only fields `D`) is the write model:
726
+ * `insert`, `update`, `replace` and `remove` are typed by `W`, every read —
727
+ * rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids, the row
728
+ * `insert(…, { returning: true })` answers — by `T`. It defaults to
729
+ * {@link WriteOf}`<T>` (since 0.1.207; before: `T`): a `@db.view.writable`
730
+ * view's table, else `T`. A writable view reads through the view and writes its
731
+ * table with no second argument:
731
732
  *
732
733
  * ```typescript
733
- * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
734
+ * const tickets = new Client<typeof TicketRow>('/api/tickets')
734
735
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
735
736
  * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
736
737
  * ```
@@ -741,7 +742,7 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
741
742
  * `Client` itself reads only `signal` (and `insert`'s `onConflict` /
742
743
  * `returning`).
743
744
  */
744
- declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> {
745
+ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = WriteOf<T>, O extends TClientCallOptions = TClientCallOptions> {
745
746
  private readonly _path;
746
747
  private readonly _baseUrl;
747
748
  private readonly _fetch;
@@ -800,8 +801,22 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W exte
800
801
  * - a query with `controls.$from` is a two-level aggregate: `$from` groups the filtered
801
802
  * rows, the root controls aggregate its rows and name its columns (its `$groupBy`
802
803
  * keys and aliases) — typed by `ValidNested`, rows by `NestedAggregateResult`.
804
+ *
805
+ * Since 0.1.207 the type parameter is the controls (`C`): the `filter` is typed by `T`'s
806
+ * fields — relation predicates (`$some` / `$none` / …) included — so a misspelled filter
807
+ * field fails to compile; a flat query's `$sort` keys must be `$groupBy` keys or `$select`
808
+ * fields / aliases (`ValidAggSort`); `sum` / `avg` of a decimal is typed `string` (the
809
+ * server answers a decimal string). The check and the rows are `@atscript/db`'s
810
+ * `AggregateCheck` / `AggregateRows` (re-exported here). A query built at runtime (a
811
+ * value typed `AggregateQuery`) is passed with a cast (`query as never`).
803
812
  */
804
- aggregate<const Q extends AggregateQuery<Own<T>> | NestedAggregateQuery<Own<T>>>(query: Q & AggregateCheck<Own<T>, Q>, opts?: O): Promise<AggregateRows<Own<T>, Q>>;
813
+ aggregate<const C extends AggregateControls<Own<T>> | NestedAggregateControls<Own<T>>>(query: {
814
+ filter?: FilterExpr<Own<T>, Nav<T>>;
815
+ controls: C & AggregateControlsCheck<Own<T>, C>;
816
+ insights?: UniqueryInsights;
817
+ }, opts?: O): Promise<AggregateRows<Own<T>, {
818
+ controls: C;
819
+ }>>;
805
820
  /**
806
821
  * `GET /pages` — paginated query with typed filter and relations.
807
822
  *
@@ -1141,4 +1156,4 @@ declare function formatIdentifier(id: Record<string, unknown> | undefined, prefe
1141
1156
  */
1142
1157
  declare function encodeNavigateId(id: Record<string, unknown>, preferredId: readonly string[]): string;
1143
1158
  //#endregion
1144
- export { ReadQuery as $, AtscriptClientShape as A, DbRow as B, ClientValidationError as C, defaultMetaStore as Ct, AggregateQuery$1 as D, VersionMismatchErrorBody as E, ClientOptions as F, MetaResponse as G, FilterExpr as H, ClientResponse as I, NestedAggregateResult$1 as J, NavOf as K, DataOf as L, BucketUnit as M, CalendarBucketLabel as N, AggregateResult$1 as O, ClientLike as P, ReadControls as Q, DbInsert as R, ClientError as S, clearMetaStore as St, VersionMismatchError as T, IdOf as U, FieldMeta as V, InsertOf as W, PageResult as X, OwnOf as Y, PatchOf as Z, ActionDisabledErrorBody as _, ValidGroupBy$1 as _t, ReadRow as a, StageRow as at, ActionTargetErrorBody as b, MetaStore as bt, encodeNavigateId as c, TDbInsertIgnoreResult$1 as ct, ClientValidator as d, TDbInsertResult$1 as dt, RelationInfo as et, ClientValidatorOptions as f, TDbQueryTarget as ft, ActionDisabledError as g, UniqueryControls as gt, createClientValidator as h, Uniquery$1 as ht, InsertedRow as i, ServerError as it, BucketExpr as j, AggregateStage as k, formatIdentifier as l, TDbInsertManyIgnoreResult$1 as lt, ValidatorMode$1 as m, TypedWithRelation as mt, AggregateRows as n, RowOf as nt, SingleInsertOf as o, TClientCallOptions as ot, DbValidationContext as p, TDbUpdateResult$1 as pt, NestedAggregateQuery$1 as q, Client as r, SearchIndexInfo as rt, actionIdentifier as s, TDbDeleteResult$1 as st, AggregateCheck as t, ResponseDataOf as tt, formatIdentifierField as u, TDbInsertManyResult$1 as ut, ActionNotFoundError as v, ValidNested$1 as vt, TransportError as w, ActionUnsupportedError as x, MetaStoreOptions as xt, ActionTargetError as y, WeekStart as yt, DbPatch as z };
1159
+ export { ReadQuery as $, BucketExpr as A, FieldMeta as B, VersionMismatchError as C, MetaStore as Ct, AggregateResult as D, AggregateQuery as E, defaultMetaStore as Et, ClientResponse as F, NavOf as G, IdOf as H, DataOf as I, NestedAggregateResult as J, NestedAggregateControls$1 as K, DbInsert as L, CalendarBucketLabel as M, ClientLike as N, AggregateStage as O, ClientOptions as P, ReadControls as Q, DbPatch as R, TransportError as S, WriteOf as St, AggregateControls$1 as T, clearMetaStore as Tt, InsertOf as U, FilterExpr$1 as V, MetaResponse as W, PageResult as X, OwnOf as Y, PatchOf as Z, ActionTargetError as _, UniqueryInsights$1 as _t, actionIdentifier as a, StageRow as at, ClientError as b, ValidNested as bt, formatIdentifierField as c, TDbInsertIgnoreResult$1 as ct, DbValidationContext as d, TDbInsertResult$1 as dt, RelationInfo as et, ValidatorMode$1 as f, TDbQueryTarget as ft, ActionNotFoundError as g, UniqueryControls as gt, ActionDisabledErrorBody as h, Uniquery$1 as ht, SingleInsertOf as i, ServerError as it, BucketUnit as j, AtscriptClientShape as k, ClientValidator as l, TDbInsertManyIgnoreResult$1 as lt, ActionDisabledError as m, TypedWithRelation as mt, InsertedRow as n, RowOf as nt, encodeNavigateId as o, TClientCallOptions as ot, createClientValidator as p, TDbUpdateResult$1 as pt, NestedAggregateQuery as q, ReadRow as r, SearchIndexInfo as rt, formatIdentifier as s, TDbDeleteResult$1 as st, Client as t, ResponseDataOf as tt, ClientValidatorOptions as u, TDbInsertManyResult$1 as ut, ActionTargetErrorBody as v, ValidAggSort as vt, VersionMismatchErrorBody as w, MetaStoreOptions as wt, ClientValidationError as x, WeekStart as xt, ActionUnsupportedError as y, ValidGroupBy as yt, DbRow as z };
@@ -1,7 +1,7 @@
1
- import { AggregateQuery, AggregateQuery as AggregateQuery$1, AggregateResult, AggregateResult as AggregateResult$1, AggregateStage, BucketExpr, BucketUnit, CalendarBucketLabel, ComputedExpr, FilterExpr, NestedAggregateQuery, NestedAggregateQuery as NestedAggregateQuery$1, NestedAggregateResult, NestedAggregateResult as NestedAggregateResult$1, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, ValidGroupBy, ValidGroupBy as ValidGroupBy$1, ValidNested, ValidNested as ValidNested$1, WeekStart } from "@uniqu/core";
1
+ import { AggregateControls, AggregateControls as AggregateControls$1, AggregateQuery, AggregateResult, AggregateStage, BucketExpr, BucketUnit, CalendarBucketLabel, FilterExpr, FilterExpr as FilterExpr$1, NestedAggregateControls, NestedAggregateControls as NestedAggregateControls$1, NestedAggregateQuery, NestedAggregateResult, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, UniqueryInsights, UniqueryInsights as UniqueryInsights$1, ValidAggSort, ValidGroupBy, ValidNested, WeekStart } from "@uniqu/core";
2
2
  import { TAtscriptAnnotatedType, TAtscriptTypeObject } from "@atscript/typescript/utils";
3
+ import { AggregateControlsCheck, AggregateRows, DbInsert, DbPatch, DbResponse, DbRow, TDbActionInfo, TDbActionTargetSummary, TDbAvailableActions, TDbDeleteResult, TDbDeleteResult as TDbDeleteResult$1, TDbInsertIgnoreResult, TDbInsertIgnoreResult as TDbInsertIgnoreResult$1, TDbInsertManyIgnoreResult, TDbInsertManyIgnoreResult as TDbInsertManyIgnoreResult$1, TDbInsertManyResult, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult, TDbUpdateResult as TDbUpdateResult$1, TDbVersion, TFieldMeta, TMetaResponse, TRelationInfo, TSearchIndexInfo } from "@atscript/db";
3
4
  import { DbValidationContext, ValidatorMode, ValidatorMode as ValidatorMode$1 } from "@atscript/db/validator";
4
- import { DbInsert, DbPatch, DbResponse, DbRow, TDbActionInfo, TDbActionTargetSummary, TDbAvailableActions, TDbDeleteResult, TDbDeleteResult as TDbDeleteResult$1, TDbInsertIgnoreResult, TDbInsertIgnoreResult as TDbInsertIgnoreResult$1, TDbInsertManyIgnoreResult, TDbInsertManyIgnoreResult as TDbInsertManyIgnoreResult$1, TDbInsertManyResult, TDbInsertManyResult as TDbInsertManyResult$1, TDbInsertResult, TDbInsertResult as TDbInsertResult$1, TDbUpdateResult, TDbUpdateResult as TDbUpdateResult$1, TDbVersion, TFieldMeta, TMetaResponse, TRelationInfo, TSearchIndexInfo } from "@atscript/db";
5
5
 
6
6
  //#region src/meta-store.d.ts
7
7
  /** Options for {@link MetaStore}. */
@@ -307,6 +307,14 @@ type NavOf<T> = T extends {
307
307
  type IdOf<T> = T extends {
308
308
  __pk: infer PK;
309
309
  } ? PK : unknown;
310
+ /**
311
+ * The write model of `T`: a `@db.view.writable` view's table (the type-only
312
+ * `static __write` the atscript 0.2.30+ d.ts declares on such a view), else `T`
313
+ * itself. `Client` / `ClientLike` default their `W` to it (since 0.1.207).
314
+ */
315
+ type WriteOf<T> = T extends {
316
+ __write: infer W extends AtscriptClientShape;
317
+ } ? W : T;
310
318
  /**
311
319
  * Narrow a read-method response type by the literal `$with` array in the
312
320
  * query, mirroring the backend's `DbResponse<Data, Nav, Q>` algebra. Nav
@@ -365,8 +373,9 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
365
373
  * `getActionForm` (`null`) and `getActionFormTexts` (`undefined`); and rejects the rest.
366
374
  *
367
375
  * `W` (since 0.1.205; before: the display-only fields `D`) is the write model: `insert`,
368
- * `update`, `replace` and `remove` are typed by it, every read by `T` — `ClientLike<typeof
369
- * TicketRow, typeof Ticket>` for a writable view over its table. Defaults to `T`.
376
+ * `update`, `replace` and `remove` are typed by it, every read by `T`. Defaults to
377
+ * `WriteOf<T>` (since 0.1.207; before: `T`): a `@db.view.writable` view's table, else `T` —
378
+ * `ClientLike<typeof TicketRow>` reads through the view and writes `Ticket`.
370
379
  *
371
380
  * `O` (since 0.1.199) is the per-call options the read / write methods take: an implementation
372
381
  * with options of its own declares them as `O`, an interface extending {@link TClientCallOptions}
@@ -375,7 +384,7 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
375
384
  * (and `insert`'s `onConflict` / `returning`).
376
385
  * @since 0.1.196
377
386
  */
378
- type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, W, O>, keyof Client<T, W, O>>;
387
+ type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = WriteOf<T>, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, W, O>, keyof Client<T, W, O>>;
379
388
  //#endregion
380
389
  //#region src/client-error.d.ts
381
390
  /**
@@ -692,16 +701,6 @@ type SingleInsertOf<T> = [keyof InsertOf<T>] extends [never] ? Record<string, an
692
701
  } : InsertOf<T>;
693
702
  /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape (over the read model `T`). */
694
703
  type InsertedRow<T> = Response<T, Record<never, never>>;
695
- /** A two-level aggregate query: one with `controls.$from`. */
696
- type NestedShape = {
697
- controls: {
698
- $from: object;
699
- };
700
- };
701
- /** The compile-time check an aggregate query must pass: two-level or flat. */
702
- type AggregateCheck<T, Q> = Q extends NestedShape ? ValidNested<T, Q> : ValidGroupBy<T, Q>;
703
- /** The rows `aggregate()` answers for query `Q`. */
704
- type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q extends NestedShape ? NestedAggregateResult<T, Q>[] : Q["controls"]["$select"] extends readonly (string | ComputedExpr)[] ? AggregateResult<T, Q["controls"]["$select"]>[] : Record<string, unknown>[];
705
704
  /**
706
705
  * HTTP client for moost-db REST endpoints.
707
706
  *
@@ -723,14 +722,16 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
723
722
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
724
723
  * ```
725
724
  *
726
- * `W` (since 0.1.205; before: the display-only fields `D`) is the write model,
727
- * `T` by default: `insert`, `update`, `replace` and `remove` are typed by `W`,
728
- * every read — rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids,
729
- * the row `insert(…, { returning: true })` answers — by `T`. A writable view
730
- * reads through the view and writes its table:
725
+ * `W` (since 0.1.205; before: the display-only fields `D`) is the write model:
726
+ * `insert`, `update`, `replace` and `remove` are typed by `W`, every read —
727
+ * rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids, the row
728
+ * `insert(…, { returning: true })` answers — by `T`. It defaults to
729
+ * {@link WriteOf}`<T>` (since 0.1.207; before: `T`): a `@db.view.writable`
730
+ * view's table, else `T`. A writable view reads through the view and writes its
731
+ * table with no second argument:
731
732
  *
732
733
  * ```typescript
733
- * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
734
+ * const tickets = new Client<typeof TicketRow>('/api/tickets')
734
735
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
735
736
  * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
736
737
  * ```
@@ -741,7 +742,7 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
741
742
  * `Client` itself reads only `signal` (and `insert`'s `onConflict` /
742
743
  * `returning`).
743
744
  */
744
- declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> {
745
+ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = WriteOf<T>, O extends TClientCallOptions = TClientCallOptions> {
745
746
  private readonly _path;
746
747
  private readonly _baseUrl;
747
748
  private readonly _fetch;
@@ -800,8 +801,22 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W exte
800
801
  * - a query with `controls.$from` is a two-level aggregate: `$from` groups the filtered
801
802
  * rows, the root controls aggregate its rows and name its columns (its `$groupBy`
802
803
  * keys and aliases) — typed by `ValidNested`, rows by `NestedAggregateResult`.
804
+ *
805
+ * Since 0.1.207 the type parameter is the controls (`C`): the `filter` is typed by `T`'s
806
+ * fields — relation predicates (`$some` / `$none` / …) included — so a misspelled filter
807
+ * field fails to compile; a flat query's `$sort` keys must be `$groupBy` keys or `$select`
808
+ * fields / aliases (`ValidAggSort`); `sum` / `avg` of a decimal is typed `string` (the
809
+ * server answers a decimal string). The check and the rows are `@atscript/db`'s
810
+ * `AggregateCheck` / `AggregateRows` (re-exported here). A query built at runtime (a
811
+ * value typed `AggregateQuery`) is passed with a cast (`query as never`).
803
812
  */
804
- aggregate<const Q extends AggregateQuery<Own<T>> | NestedAggregateQuery<Own<T>>>(query: Q & AggregateCheck<Own<T>, Q>, opts?: O): Promise<AggregateRows<Own<T>, Q>>;
813
+ aggregate<const C extends AggregateControls<Own<T>> | NestedAggregateControls<Own<T>>>(query: {
814
+ filter?: FilterExpr<Own<T>, Nav<T>>;
815
+ controls: C & AggregateControlsCheck<Own<T>, C>;
816
+ insights?: UniqueryInsights;
817
+ }, opts?: O): Promise<AggregateRows<Own<T>, {
818
+ controls: C;
819
+ }>>;
805
820
  /**
806
821
  * `GET /pages` — paginated query with typed filter and relations.
807
822
  *
@@ -1141,4 +1156,4 @@ declare function formatIdentifier(id: Record<string, unknown> | undefined, prefe
1141
1156
  */
1142
1157
  declare function encodeNavigateId(id: Record<string, unknown>, preferredId: readonly string[]): string;
1143
1158
  //#endregion
1144
- export { ReadQuery as $, AtscriptClientShape as A, DbRow as B, ClientValidationError as C, defaultMetaStore as Ct, AggregateQuery$1 as D, VersionMismatchErrorBody as E, ClientOptions as F, MetaResponse as G, FilterExpr as H, ClientResponse as I, NestedAggregateResult$1 as J, NavOf as K, DataOf as L, BucketUnit as M, CalendarBucketLabel as N, AggregateResult$1 as O, ClientLike as P, ReadControls as Q, DbInsert as R, ClientError as S, clearMetaStore as St, VersionMismatchError as T, IdOf as U, FieldMeta as V, InsertOf as W, PageResult as X, OwnOf as Y, PatchOf as Z, ActionDisabledErrorBody as _, ValidGroupBy$1 as _t, ReadRow as a, StageRow as at, ActionTargetErrorBody as b, MetaStore as bt, encodeNavigateId as c, TDbInsertIgnoreResult$1 as ct, ClientValidator as d, TDbInsertResult$1 as dt, RelationInfo as et, ClientValidatorOptions as f, TDbQueryTarget as ft, ActionDisabledError as g, UniqueryControls as gt, createClientValidator as h, Uniquery$1 as ht, InsertedRow as i, ServerError as it, BucketExpr as j, AggregateStage as k, formatIdentifier as l, TDbInsertManyIgnoreResult$1 as lt, ValidatorMode$1 as m, TypedWithRelation as mt, AggregateRows as n, RowOf as nt, SingleInsertOf as o, TClientCallOptions as ot, DbValidationContext as p, TDbUpdateResult$1 as pt, NestedAggregateQuery$1 as q, Client as r, SearchIndexInfo as rt, actionIdentifier as s, TDbDeleteResult$1 as st, AggregateCheck as t, ResponseDataOf as tt, formatIdentifierField as u, TDbInsertManyResult$1 as ut, ActionNotFoundError as v, ValidNested$1 as vt, TransportError as w, ActionUnsupportedError as x, MetaStoreOptions as xt, ActionTargetError as y, WeekStart as yt, DbPatch as z };
1159
+ export { ReadQuery as $, BucketExpr as A, FieldMeta as B, VersionMismatchError as C, MetaStore as Ct, AggregateResult as D, AggregateQuery as E, defaultMetaStore as Et, ClientResponse as F, NavOf as G, IdOf as H, DataOf as I, NestedAggregateResult as J, NestedAggregateControls$1 as K, DbInsert as L, CalendarBucketLabel as M, ClientLike as N, AggregateStage as O, ClientOptions as P, ReadControls as Q, DbPatch as R, TransportError as S, WriteOf as St, AggregateControls$1 as T, clearMetaStore as Tt, InsertOf as U, FilterExpr$1 as V, MetaResponse as W, PageResult as X, OwnOf as Y, PatchOf as Z, ActionTargetError as _, UniqueryInsights$1 as _t, actionIdentifier as a, StageRow as at, ClientError as b, ValidNested as bt, formatIdentifierField as c, TDbInsertIgnoreResult$1 as ct, DbValidationContext as d, TDbInsertResult$1 as dt, RelationInfo as et, ValidatorMode$1 as f, TDbQueryTarget as ft, ActionNotFoundError as g, UniqueryControls as gt, ActionDisabledErrorBody as h, Uniquery$1 as ht, SingleInsertOf as i, ServerError as it, BucketUnit as j, AtscriptClientShape as k, ClientValidator as l, TDbInsertManyIgnoreResult$1 as lt, ActionDisabledError as m, TypedWithRelation as mt, InsertedRow as n, RowOf as nt, encodeNavigateId as o, TClientCallOptions as ot, createClientValidator as p, TDbUpdateResult$1 as pt, NestedAggregateQuery as q, ReadRow as r, SearchIndexInfo as rt, formatIdentifier as s, TDbDeleteResult$1 as st, Client as t, ResponseDataOf as tt, ClientValidatorOptions as u, TDbInsertManyResult$1 as ut, ActionTargetErrorBody as v, ValidAggSort as vt, VersionMismatchErrorBody as w, MetaStoreOptions as wt, ClientValidationError as x, WeekStart as xt, ActionUnsupportedError as y, ValidGroupBy as yt, DbRow as z };
package/dist/index.cjs CHANGED
@@ -151,14 +151,16 @@ function clearMetaStore() {
151
151
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
152
152
  * ```
153
153
  *
154
- * `W` (since 0.1.205; before: the display-only fields `D`) is the write model,
155
- * `T` by default: `insert`, `update`, `replace` and `remove` are typed by `W`,
156
- * every read — rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids,
157
- * the row `insert(…, { returning: true })` answers — by `T`. A writable view
158
- * reads through the view and writes its table:
154
+ * `W` (since 0.1.205; before: the display-only fields `D`) is the write model:
155
+ * `insert`, `update`, `replace` and `remove` are typed by `W`, every read —
156
+ * rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids, the row
157
+ * `insert(…, { returning: true })` answers — by `T`. It defaults to
158
+ * {@link WriteOf}`<T>` (since 0.1.207; before: `T`): a `@db.view.writable`
159
+ * view's table, else `T`. A writable view reads through the view and writes its
160
+ * table with no second argument:
159
161
  *
160
162
  * ```typescript
161
- * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
163
+ * const tickets = new Client<typeof TicketRow>('/api/tickets')
162
164
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
163
165
  * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
164
166
  * ```
@@ -243,6 +245,14 @@ var Client = class {
243
245
  * - a query with `controls.$from` is a two-level aggregate: `$from` groups the filtered
244
246
  * rows, the root controls aggregate its rows and name its columns (its `$groupBy`
245
247
  * keys and aliases) — typed by `ValidNested`, rows by `NestedAggregateResult`.
248
+ *
249
+ * Since 0.1.207 the type parameter is the controls (`C`): the `filter` is typed by `T`'s
250
+ * fields — relation predicates (`$some` / `$none` / …) included — so a misspelled filter
251
+ * field fails to compile; a flat query's `$sort` keys must be `$groupBy` keys or `$select`
252
+ * fields / aliases (`ValidAggSort`); `sum` / `avg` of a decimal is typed `string` (the
253
+ * server answers a decimal string). The check and the rows are `@atscript/db`'s
254
+ * `AggregateCheck` / `AggregateRows` (re-exported here). A query built at runtime (a
255
+ * value typed `AggregateQuery`) is passed with a cast (`query as never`).
246
256
  */
247
257
  async aggregate(query, opts) {
248
258
  return this._get("query", query, opts?.signal);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as ReadQuery, A as AtscriptClientShape, B as DbRow, C as ClientValidationError, Ct as defaultMetaStore, D as AggregateQuery, E as VersionMismatchErrorBody, F as ClientOptions, G as MetaResponse, H as FilterExpr, I as ClientResponse, J as NestedAggregateResult, K as NavOf, L as DataOf, M as BucketUnit, N as CalendarBucketLabel, O as AggregateResult, P as ClientLike, Q as ReadControls, R as DbInsert, S as ClientError, St as clearMetaStore, T as VersionMismatchError, U as IdOf, V as FieldMeta, W as InsertOf, X as PageResult, Y as OwnOf, Z as PatchOf, _ as ActionDisabledErrorBody, _t as ValidGroupBy, a as ReadRow, at as StageRow, b as ActionTargetErrorBody, bt as MetaStore, c as encodeNavigateId, ct as TDbInsertIgnoreResult, d as ClientValidator, dt as TDbInsertResult, et as RelationInfo, f as ClientValidatorOptions, ft as TDbQueryTarget, g as ActionDisabledError, gt as UniqueryControls, ht as Uniquery, i as InsertedRow, it as ServerError, j as BucketExpr, k as AggregateStage, l as formatIdentifier, lt as TDbInsertManyIgnoreResult, m as ValidatorMode, mt as TypedWithRelation, n as AggregateRows, nt as RowOf, o as SingleInsertOf, ot as TClientCallOptions, pt as TDbUpdateResult, q as NestedAggregateQuery, r as Client, rt as SearchIndexInfo, s as actionIdentifier, st as TDbDeleteResult, t as AggregateCheck, tt as ResponseDataOf, u as formatIdentifierField, ut as TDbInsertManyResult, v as ActionNotFoundError, vt as ValidNested, w as TransportError, x as ActionUnsupportedError, xt as MetaStoreOptions, y as ActionTargetError, yt as WeekStart, z as DbPatch } from "./client-BRXq9YfV.cjs";
1
+ import { $ as ReadQuery, A as BucketExpr, B as FieldMeta, C as VersionMismatchError, Ct as MetaStore, D as AggregateResult, E as AggregateQuery, Et as defaultMetaStore, F as ClientResponse, G as NavOf, H as IdOf, I as DataOf, J as NestedAggregateResult, K as NestedAggregateControls, L as DbInsert, M as CalendarBucketLabel, N as ClientLike, O as AggregateStage, P as ClientOptions, Q as ReadControls, R as DbPatch, S as TransportError, St as WriteOf, T as AggregateControls, Tt as clearMetaStore, U as InsertOf, V as FilterExpr, W as MetaResponse, X as PageResult, Y as OwnOf, Z as PatchOf, _ as ActionTargetError, _t as UniqueryInsights, a as actionIdentifier, at as StageRow, b as ClientError, bt as ValidNested, c as formatIdentifierField, ct as TDbInsertIgnoreResult, dt as TDbInsertResult, et as RelationInfo, f as ValidatorMode, ft as TDbQueryTarget, g as ActionNotFoundError, gt as UniqueryControls, h as ActionDisabledErrorBody, ht as Uniquery, i as SingleInsertOf, it as ServerError, j as BucketUnit, k as AtscriptClientShape, l as ClientValidator, lt as TDbInsertManyIgnoreResult, m as ActionDisabledError, mt as TypedWithRelation, n as InsertedRow, nt as RowOf, o as encodeNavigateId, ot as TClientCallOptions, pt as TDbUpdateResult, q as NestedAggregateQuery, r as ReadRow, rt as SearchIndexInfo, s as formatIdentifier, st as TDbDeleteResult, t as Client, tt as ResponseDataOf, u as ClientValidatorOptions, ut as TDbInsertManyResult, v as ActionTargetErrorBody, vt as ValidAggSort, w as VersionMismatchErrorBody, wt as MetaStoreOptions, x as ClientValidationError, xt as WeekStart, y as ActionUnsupportedError, yt as ValidGroupBy, z as DbRow } from "./client-GVIGbuz_.cjs";
2
2
  import { BucketSeriesOptions, NextBucketOptions, bucketSeries, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
3
3
  import { TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
- import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbActionTargetSummary, TDbAvailableActions } from "@atscript/db";
5
- export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionTargetError, type ActionTargetErrorBody, ActionUnsupportedError, type AggregateCheck, type AggregateQuery, type AggregateResult, type AggregateRows, type AggregateStage, type AtscriptClientShape, type BucketExpr, type BucketSeriesOptions, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientLike, type ClientOptions, type ClientResponse, ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbInsert, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type InsertOf, type InsertedRow, type MetaResponse, MetaStore, type MetaStoreOptions, type NavOf, type NestedAggregateQuery, type NestedAggregateResult, type NextBucketOptions, type OwnOf, type PageResult, type PatchOf, type ReadControls, type ReadQuery, type ReadRow, type RelationInfo, type ResponseDataOf, type RowOf, type SearchIndexInfo, type ServerError, type SingleInsertOf, type StageRow, type TClientCallOptions, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbActionTargetSummary, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertIgnoreResult, type TDbInsertManyIgnoreResult, type TDbInsertManyResult, type TDbInsertResult, type TDbQueryTarget, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidNested, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, actionIdentifier, bucketSeries, bucketStartInstant, clearMetaStore, defaultMetaStore, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
4
+ import { AggregateCheck, AggregateControlsCheck, AggregateRows, TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbActionTargetSummary, TDbAvailableActions } from "@atscript/db";
5
+ export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionTargetError, type ActionTargetErrorBody, ActionUnsupportedError, type AggregateCheck, type AggregateControls, type AggregateControlsCheck, type AggregateQuery, type AggregateResult, type AggregateRows, type AggregateStage, type AtscriptClientShape, type BucketExpr, type BucketSeriesOptions, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientLike, type ClientOptions, type ClientResponse, ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbInsert, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type InsertOf, type InsertedRow, type MetaResponse, MetaStore, type MetaStoreOptions, type NavOf, type NestedAggregateControls, type NestedAggregateQuery, type NestedAggregateResult, type NextBucketOptions, type OwnOf, type PageResult, type PatchOf, type ReadControls, type ReadQuery, type ReadRow, type RelationInfo, type ResponseDataOf, type RowOf, type SearchIndexInfo, type ServerError, type SingleInsertOf, type StageRow, type TClientCallOptions, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbActionTargetSummary, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertIgnoreResult, type TDbInsertManyIgnoreResult, type TDbInsertManyResult, type TDbInsertResult, type TDbQueryTarget, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type UniqueryInsights, type ValidAggSort, type ValidGroupBy, type ValidNested, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, type WriteOf, actionIdentifier, bucketSeries, bucketStartInstant, clearMetaStore, defaultMetaStore, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as ReadQuery, A as AtscriptClientShape, B as DbRow, C as ClientValidationError, Ct as defaultMetaStore, D as AggregateQuery, E as VersionMismatchErrorBody, F as ClientOptions, G as MetaResponse, H as FilterExpr, I as ClientResponse, J as NestedAggregateResult, K as NavOf, L as DataOf, M as BucketUnit, N as CalendarBucketLabel, O as AggregateResult, P as ClientLike, Q as ReadControls, R as DbInsert, S as ClientError, St as clearMetaStore, T as VersionMismatchError, U as IdOf, V as FieldMeta, W as InsertOf, X as PageResult, Y as OwnOf, Z as PatchOf, _ as ActionDisabledErrorBody, _t as ValidGroupBy, a as ReadRow, at as StageRow, b as ActionTargetErrorBody, bt as MetaStore, c as encodeNavigateId, ct as TDbInsertIgnoreResult, d as ClientValidator, dt as TDbInsertResult, et as RelationInfo, f as ClientValidatorOptions, ft as TDbQueryTarget, g as ActionDisabledError, gt as UniqueryControls, ht as Uniquery, i as InsertedRow, it as ServerError, j as BucketExpr, k as AggregateStage, l as formatIdentifier, lt as TDbInsertManyIgnoreResult, m as ValidatorMode, mt as TypedWithRelation, n as AggregateRows, nt as RowOf, o as SingleInsertOf, ot as TClientCallOptions, pt as TDbUpdateResult, q as NestedAggregateQuery, r as Client, rt as SearchIndexInfo, s as actionIdentifier, st as TDbDeleteResult, t as AggregateCheck, tt as ResponseDataOf, u as formatIdentifierField, ut as TDbInsertManyResult, v as ActionNotFoundError, vt as ValidNested, w as TransportError, x as ActionUnsupportedError, xt as MetaStoreOptions, y as ActionTargetError, yt as WeekStart, z as DbPatch } from "./client-DggC00AO.mjs";
1
+ import { $ as ReadQuery, A as BucketExpr, B as FieldMeta, C as VersionMismatchError, Ct as MetaStore, D as AggregateResult, E as AggregateQuery, Et as defaultMetaStore, F as ClientResponse, G as NavOf, H as IdOf, I as DataOf, J as NestedAggregateResult, K as NestedAggregateControls, L as DbInsert, M as CalendarBucketLabel, N as ClientLike, O as AggregateStage, P as ClientOptions, Q as ReadControls, R as DbPatch, S as TransportError, St as WriteOf, T as AggregateControls, Tt as clearMetaStore, U as InsertOf, V as FilterExpr, W as MetaResponse, X as PageResult, Y as OwnOf, Z as PatchOf, _ as ActionTargetError, _t as UniqueryInsights, a as actionIdentifier, at as StageRow, b as ClientError, bt as ValidNested, c as formatIdentifierField, ct as TDbInsertIgnoreResult, dt as TDbInsertResult, et as RelationInfo, f as ValidatorMode, ft as TDbQueryTarget, g as ActionNotFoundError, gt as UniqueryControls, h as ActionDisabledErrorBody, ht as Uniquery, i as SingleInsertOf, it as ServerError, j as BucketUnit, k as AtscriptClientShape, l as ClientValidator, lt as TDbInsertManyIgnoreResult, m as ActionDisabledError, mt as TypedWithRelation, n as InsertedRow, nt as RowOf, o as encodeNavigateId, ot as TClientCallOptions, pt as TDbUpdateResult, q as NestedAggregateQuery, r as ReadRow, rt as SearchIndexInfo, s as formatIdentifier, st as TDbDeleteResult, t as Client, tt as ResponseDataOf, u as ClientValidatorOptions, ut as TDbInsertManyResult, v as ActionTargetErrorBody, vt as ValidAggSort, w as VersionMismatchErrorBody, wt as MetaStoreOptions, x as ClientValidationError, xt as WeekStart, y as ActionUnsupportedError, yt as ValidGroupBy, z as DbRow } from "./client-BnqkM3eZ.mjs";
2
2
  import { BucketSeriesOptions, NextBucketOptions, bucketSeries, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
3
3
  import { TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
- import { TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbActionTargetSummary, TDbAvailableActions } from "@atscript/db";
5
- export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionTargetError, type ActionTargetErrorBody, ActionUnsupportedError, type AggregateCheck, type AggregateQuery, type AggregateResult, type AggregateRows, type AggregateStage, type AtscriptClientShape, type BucketExpr, type BucketSeriesOptions, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientLike, type ClientOptions, type ClientResponse, ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbInsert, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type InsertOf, type InsertedRow, type MetaResponse, MetaStore, type MetaStoreOptions, type NavOf, type NestedAggregateQuery, type NestedAggregateResult, type NextBucketOptions, type OwnOf, type PageResult, type PatchOf, type ReadControls, type ReadQuery, type ReadRow, type RelationInfo, type ResponseDataOf, type RowOf, type SearchIndexInfo, type ServerError, type SingleInsertOf, type StageRow, type TClientCallOptions, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbActionTargetSummary, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertIgnoreResult, type TDbInsertManyIgnoreResult, type TDbInsertManyResult, type TDbInsertResult, type TDbQueryTarget, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type ValidGroupBy, type ValidNested, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, actionIdentifier, bucketSeries, bucketStartInstant, clearMetaStore, defaultMetaStore, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
4
+ import { AggregateCheck, AggregateControlsCheck, AggregateRows, TCrudOp, TCrudPermissions, TDbActionInfo, TDbActionIntent, TDbActionLevel, TDbActionProcessor, TDbActionTargetSummary, TDbAvailableActions } from "@atscript/db";
5
+ export { ActionDisabledError, type ActionDisabledErrorBody, ActionNotFoundError, ActionTargetError, type ActionTargetErrorBody, ActionUnsupportedError, type AggregateCheck, type AggregateControls, type AggregateControlsCheck, type AggregateQuery, type AggregateResult, type AggregateRows, type AggregateStage, type AtscriptClientShape, type BucketExpr, type BucketSeriesOptions, type BucketUnit, type CalendarBucketLabel, Client, ClientError, type ClientLike, type ClientOptions, type ClientResponse, ClientValidationError, type ClientValidator, type ClientValidatorOptions, type DataOf, type DbInsert, type DbPatch, type DbRow, type FieldMeta, type FilterExpr, type IdOf, type InsertOf, type InsertedRow, type MetaResponse, MetaStore, type MetaStoreOptions, type NavOf, type NestedAggregateControls, type NestedAggregateQuery, type NestedAggregateResult, type NextBucketOptions, type OwnOf, type PageResult, type PatchOf, type ReadControls, type ReadQuery, type ReadRow, type RelationInfo, type ResponseDataOf, type RowOf, type SearchIndexInfo, type ServerError, type SingleInsertOf, type StageRow, type TClientCallOptions, type TCrudOp, type TCrudPermissions, type TDbActionInfo, type TDbActionIntent, type TDbActionLevel, type TDbActionProcessor, type TDbActionTargetSummary, type TDbAvailableActions, type TDbDeleteResult, type TDbInsertIgnoreResult, type TDbInsertManyIgnoreResult, type TDbInsertManyResult, type TDbInsertResult, type TDbQueryTarget, type TDbUpdateResult, type TSerializedAnnotatedType, TransportError, type TypedWithRelation, type Uniquery, type UniqueryControls, type UniqueryInsights, type ValidAggSort, type ValidGroupBy, type ValidNested, type ValidatorMode, VersionMismatchError, type VersionMismatchErrorBody, type WeekStart, type WriteOf, actionIdentifier, bucketSeries, bucketStartInstant, clearMetaStore, defaultMetaStore, encodeNavigateId, formatIdentifier, formatIdentifierField, nextBucketLabel };
package/dist/index.mjs CHANGED
@@ -150,14 +150,16 @@ function clearMetaStore() {
150
150
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
151
151
  * ```
152
152
  *
153
- * `W` (since 0.1.205; before: the display-only fields `D`) is the write model,
154
- * `T` by default: `insert`, `update`, `replace` and `remove` are typed by `W`,
155
- * every read — rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids,
156
- * the row `insert(…, { returning: true })` answers — by `T`. A writable view
157
- * reads through the view and writes its table:
153
+ * `W` (since 0.1.205; before: the display-only fields `D`) is the write model:
154
+ * `insert`, `update`, `replace` and `remove` are typed by `W`, every read —
155
+ * rows, `$select`, filter, sort, `$groupBy`, `one()`, action ids, the row
156
+ * `insert(…, { returning: true })` answers — by `T`. It defaults to
157
+ * {@link WriteOf}`<T>` (since 0.1.207; before: `T`): a `@db.view.writable`
158
+ * view's table, else `T`. A writable view reads through the view and writes its
159
+ * table with no second argument:
158
160
  *
159
161
  * ```typescript
160
- * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
162
+ * const tickets = new Client<typeof TicketRow>('/api/tickets')
161
163
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
162
164
  * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
163
165
  * ```
@@ -242,6 +244,14 @@ var Client = class {
242
244
  * - a query with `controls.$from` is a two-level aggregate: `$from` groups the filtered
243
245
  * rows, the root controls aggregate its rows and name its columns (its `$groupBy`
244
246
  * keys and aliases) — typed by `ValidNested`, rows by `NestedAggregateResult`.
247
+ *
248
+ * Since 0.1.207 the type parameter is the controls (`C`): the `filter` is typed by `T`'s
249
+ * fields — relation predicates (`$some` / `$none` / …) included — so a misspelled filter
250
+ * field fails to compile; a flat query's `$sort` keys must be `$groupBy` keys or `$select`
251
+ * fields / aliases (`ValidAggSort`); `sum` / `avg` of a decimal is typed `string` (the
252
+ * server answers a decimal string). The check and the rows are `@atscript/db`'s
253
+ * `AggregateCheck` / `AggregateRows` (re-exported here). A query built at runtime (a
254
+ * value typed `AggregateQuery`) is passed with a cast (`query as never`).
245
255
  */
246
256
  async aggregate(query, opts) {
247
257
  return this._get("query", query, opts?.signal);
@@ -1,2 +1,2 @@
1
- import { C as ClientValidationError, d as ClientValidator, f as ClientValidatorOptions, h as createClientValidator, m as ValidatorMode, p as DbValidationContext } from "./client-BRXq9YfV.cjs";
1
+ import { d as DbValidationContext, f as ValidatorMode, l as ClientValidator, p as createClientValidator, u as ClientValidatorOptions, x as ClientValidationError } from "./client-GVIGbuz_.cjs";
2
2
  export { ClientValidationError, ClientValidator, ClientValidatorOptions, type DbValidationContext, type ValidatorMode, createClientValidator };
@@ -1,2 +1,2 @@
1
- import { C as ClientValidationError, d as ClientValidator, f as ClientValidatorOptions, h as createClientValidator, m as ValidatorMode, p as DbValidationContext } from "./client-DggC00AO.mjs";
1
+ import { d as DbValidationContext, f as ValidatorMode, l as ClientValidator, p as createClientValidator, u as ClientValidatorOptions, x as ClientValidationError } from "./client-BnqkM3eZ.mjs";
2
2
  export { ClientValidationError, ClientValidator, ClientValidatorOptions, type DbValidationContext, type ValidatorMode, createClientValidator };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-client",
3
- "version": "0.1.206",
3
+ "version": "0.1.207",
4
4
  "description": "Browser-compatible HTTP client for @atscript/moost-db REST endpoints.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -43,18 +43,18 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@uniqu/core": "^0.2.2",
47
- "@uniqu/url": "^0.2.2"
46
+ "@uniqu/core": "^0.2.3",
47
+ "@uniqu/url": "^0.2.3"
48
48
  },
49
49
  "devDependencies": {
50
- "@atscript/core": "^0.2.29",
51
- "@atscript/typescript": "^0.2.29",
52
- "unplugin-atscript": "^0.2.29",
53
- "@atscript/db": "0.1.206"
50
+ "@atscript/core": "^0.2.30",
51
+ "@atscript/typescript": "^0.2.30",
52
+ "unplugin-atscript": "^0.2.30",
53
+ "@atscript/db": "0.1.207"
54
54
  },
55
55
  "peerDependencies": {
56
- "@atscript/typescript": "^0.2.29",
57
- "@atscript/db": "^0.1.206"
56
+ "@atscript/typescript": "^0.2.30",
57
+ "@atscript/db": "^0.1.207"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "vp pack",