@atscript/db-client 0.1.203 → 0.1.205

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, SelectExpr, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, ValidGroupBy, ValidGroupBy as ValidGroupBy$1, ValidNested, ValidNested as ValidNested$1, WeekStart } from "@uniqu/core";
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";
2
2
  import { TAtscriptAnnotatedType, TAtscriptTypeObject } from "@atscript/typescript/utils";
3
- import { DbValidationContext, ValidatorMode, ValidatorMode as ValidatorMode$1 } from "@atscript/db/validator";
4
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
+ import { DbValidationContext, ValidatorMode, ValidatorMode as ValidatorMode$1 } from "@atscript/db/validator";
5
5
 
6
6
  //#region src/meta-store.d.ts
7
7
  /** Options for {@link MetaStore}. */
@@ -271,12 +271,19 @@ type ResponseDataOf<T> = T extends {
271
271
  };
272
272
  } ? unknown extends D ? T extends (new (...a: any[]) => infer I) ? I : Record<string, unknown> : D : Record<string, unknown>;
273
273
  /**
274
- * `$select` controls of a read over `T` whose controller declares the display-only
275
- * fields `D` (`@DbDecorations`): `$select` also accepts `keyof D`; filter, sort
276
- * and every other control stay over the own fields. Since 0.1.148.
274
+ * `X` without the keys `K`, its literal keys kept: `Omit` over a type with an
275
+ * index signature (`UniqueryControls`' `$`-keyword pass-through) keeps only
276
+ * the signature, which erased `$sort` / `$with` / `$limit`.
277
277
  */
278
- type DecoratedControls<T, D> = Omit<UniqueryControls<OwnOf<T>, NavOf<T>>, "$select"> & {
279
- $select?: SelectExpr<OwnOf<T> & D>;
278
+ type OmitKeys<X, K extends PropertyKey> = { [P in keyof X as P extends K ? never : P]: X[P] };
279
+ /**
280
+ * The controls of a read over `T` — `query()`, `pages()`, `one()`, the geo
281
+ * reads (since 0.1.205; before: `DecoratedControls`): `$select`, `$sort`,
282
+ * `$with`, … typed by `T`'s fields (a view's `@db.compute.host` fields are
283
+ * among them: selectable, never filtered or sorted — the server answers 400).
284
+ */
285
+ type ReadControls<T> = OmitKeys<UniqueryControls<OwnOf<T>, NavOf<T>>, "$with"> & {
286
+ /** Relations to load; a readonly list (`as const`) too. */$with?: readonly TypedWithRelation<NavOf<T>>[];
280
287
  /**
281
288
  * `false` — a `$search` read computes no relevance score: rows come in
282
289
  * `$sort` order, or primary-key order without one. A `$vector` read refuses
@@ -284,9 +291,9 @@ type DecoratedControls<T, D> = Omit<UniqueryControls<OwnOf<T>, NavOf<T>>, "$sele
284
291
  */
285
292
  $rank?: boolean;
286
293
  };
287
- /** A read query over `T` — {@link DecoratedControls} for the controls. Since 0.1.148. */
288
- type DecoratedQuery<T, D> = Omit<Uniquery$1<OwnOf<T>, NavOf<T>>, "controls"> & {
289
- controls?: DecoratedControls<T, D>;
294
+ /** A read query over `T` — {@link ReadControls} for the controls. Since 0.1.205. */
295
+ type ReadQuery<T> = Omit<Uniquery$1<OwnOf<T>, NavOf<T>>, "controls"> & {
296
+ controls?: ReadControls<T>;
290
297
  };
291
298
  /** Extract own (non-nav) properties from an Atscript annotated type. */
292
299
  type OwnOf<T> = T extends {
@@ -357,14 +364,18 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
357
364
  * `undefined`) and `metaStore` (may be `undefined`); answers "none" from `availableActions`,
358
365
  * `getActionForm` (`null`) and `getActionFormTexts` (`undefined`); and rejects the rest.
359
366
  *
367
+ * `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`.
370
+ *
360
371
  * `O` (since 0.1.199) is the per-call options the read / write methods take: an implementation
361
372
  * with options of its own declares them as `O`, an interface extending {@link TClientCallOptions}
362
- * (`ClientLike<T, D, MyCallOptions>`), instead of augmenting `TClientCallOptions` — which would
373
+ * (`ClientLike<T, T, MyCallOptions>`), instead of augmenting `TClientCallOptions` — which would
363
374
  * let a plain `Client` accept them too and ignore them. `Client` itself reads only `signal`
364
375
  * (and `insert`'s `onConflict` / `returning`).
365
376
  * @since 0.1.196
366
377
  */
367
- type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, D, O>, keyof Client<T, D, O>>;
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>>;
368
379
  //#endregion
369
380
  //#region src/client-error.d.ts
370
381
  /**
@@ -660,13 +671,11 @@ type Own<T> = OwnOf<T>;
660
671
  type Nav<T> = NavOf<T>;
661
672
  type Id<T> = IdOf<T>;
662
673
  type Response<T, Q> = ClientResponse<T, Q>;
663
- /** A read row: the response over the own fields plus the declared decorations `D`, each optional. */
664
- type DecoratedRow<T, Q, D> = Response<T, Q> & Partial<D>;
665
674
  /**
666
- * A `query()` / `pages()` row: {@link DecoratedRow}, plus `$score` on a vector read
675
+ * A `query()` / `pages()` row: the response over `T`, plus `$score` on a vector read
667
676
  * (`$search` with `$vector`, since 0.1.183): higher = closer, on the scale of `$threshold`.
668
677
  */
669
- type ReadRow<T, Q, D> = DecoratedRow<T, Q, D> & (Q extends {
678
+ type ReadRow<T, Q> = Response<T, Q> & (Q extends {
670
679
  controls: {
671
680
  $search: string;
672
681
  $vector: string;
@@ -681,8 +690,8 @@ type ReadRow<T, Q, D> = DecoratedRow<T, Q, D> & (Q extends {
681
690
  type SingleInsertOf<T> = [keyof InsertOf<T>] extends [never] ? Record<string, any> & {
682
691
  readonly [Symbol.iterator]?: never;
683
692
  } : InsertOf<T>;
684
- /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape. */
685
- type InsertedRow<T, D> = DecoratedRow<T, Record<never, never>, D>;
693
+ /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape (over the read model `T`). */
694
+ type InsertedRow<T> = Response<T, Record<never, never>>;
686
695
  /** A two-level aggregate query: one with `controls.$from`. */
687
696
  type NestedShape = {
688
697
  controls: {
@@ -714,15 +723,16 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
714
723
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
715
724
  * ```
716
725
  *
717
- * `D` (since 0.1.148) types the display-only fields the controller declares
718
- * with `@DbDecorations`: `$select` of the read methods accepts their keys and
719
- * rows carry them as optional properties. Filter and sort stay over `T`'s own
720
- * fields — a decoration is never filterable or sortable.
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:
721
731
  *
722
732
  * ```typescript
723
- * const tickets = new Client<typeof Ticket, TicketDecorations>('/api/tickets')
733
+ * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
724
734
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
725
- * rows[0].ownerName // string | undefined
735
+ * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
726
736
  * ```
727
737
  *
728
738
  * `O` (since 0.1.199) types the per-call options the read / write methods
@@ -731,7 +741,7 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
731
741
  * `Client` itself reads only `signal` (and `insert`'s `onConflict` /
732
742
  * `returning`).
733
743
  */
734
- declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>, O extends TClientCallOptions = TClientCallOptions> {
744
+ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> {
735
745
  private readonly _path;
736
746
  private readonly _baseUrl;
737
747
  private readonly _fetch;
@@ -757,7 +767,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
757
767
  * relations not listed in `$with` are stripped from the row type. A vector
758
768
  * read (`controls: { $search, $vector }`) types `$score` on every row.
759
769
  */
760
- query<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, opts?: O): Promise<ReadRow<T, Q, D>[]>;
770
+ query<const Q extends ReadQuery<T> = ReadQuery<T>>(query?: Q, opts?: O): Promise<ReadRow<T, Q>[]>;
761
771
  /**
762
772
  * `GET /query` with `$count: true` — returns record count.
763
773
  */
@@ -798,7 +808,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
798
808
  * Response rows narrow by the literal `$with` array — same algebra as
799
809
  * {@link query}, `$score` on a vector read included.
800
810
  */
801
- pages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<ReadRow<T, Q, D>>>;
811
+ pages<const Q extends ReadQuery<T> = ReadQuery<T>>(query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<ReadRow<T, Q>>>;
802
812
  /**
803
813
  * `GET /geo` — distance-ranked geospatial search (tables with `@db.index.geo`).
804
814
  *
@@ -808,13 +818,13 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
808
818
  * in `query.controls`; filter / `$select` / `$with` / `$skip` / `$limit`
809
819
  * compose as usual.
810
820
  */
811
- geoSearch<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, opts?: O): Promise<Array<DecoratedRow<T, Q, D> & {
821
+ geoSearch<const Q extends ReadQuery<T> = ReadQuery<T>>(point: [number, number], query?: Q, opts?: O): Promise<Array<Response<T, Q> & {
812
822
  $distance: number;
813
823
  }>>;
814
824
  /**
815
825
  * `GET /geo` with `$page` / `$size` — paginated distance-ranked search.
816
826
  */
817
- geoPages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<DecoratedRow<T, Q, D> & {
827
+ geoPages<const Q extends ReadQuery<T> = ReadQuery<T>>(point: [number, number], query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<Response<T, Q> & {
818
828
  $distance: number;
819
829
  }>>;
820
830
  /**
@@ -824,19 +834,19 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
824
834
  * `query.controls` — same algebra as {@link query}.
825
835
  */
826
836
  one<const Q extends {
827
- controls?: DecoratedControls<T, D>;
837
+ controls?: ReadControls<T>;
828
838
  } = {
829
- controls?: DecoratedControls<T, D>;
830
- }>(id: Id<T>, query?: Q, opts?: O): Promise<DecoratedRow<T, Q, D> | null>;
839
+ controls?: ReadControls<T>;
840
+ }>(id: Id<T>, query?: Q, opts?: O): Promise<Response<T, Q> | null>;
831
841
  /**
832
842
  * `POST /` — insert many records.
833
843
  */
834
- insert(data: InsertOf<T>[], opts?: O): Promise<TDbInsertManyResult>;
844
+ insert(data: InsertOf<W>[], opts?: O): Promise<TDbInsertManyResult>;
835
845
  /**
836
846
  * `POST /?$onConflict=ignore` — insert many records, skipping the ones that
837
847
  * collide; the result reports inserted and skipped input indices (since 0.1.148).
838
848
  */
839
- insert(data: InsertOf<T>[], opts: O & {
849
+ insert(data: InsertOf<W>[], opts: O & {
840
850
  onConflict: "ignore";
841
851
  }): Promise<TDbInsertManyIgnoreResult>;
842
852
  /**
@@ -846,31 +856,31 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
846
856
  * the server could not apply the preference (the caller may not read the
847
857
  * row, or a skipped conflict).
848
858
  */
849
- insert(data: SingleInsertOf<T>, opts: O & {
859
+ insert(data: SingleInsertOf<W>, opts: O & {
850
860
  returning: true;
851
861
  }): Promise<TDbInsertResult & {
852
- row?: InsertedRow<T, D>;
862
+ row?: InsertedRow<T>;
853
863
  }>;
854
864
  /**
855
865
  * `POST /?$onConflict=ignore` with `Prefer: return=representation` — as
856
866
  * above; a skipped row answers `{ conflict: true }` without `row`.
857
867
  */
858
- insert(data: SingleInsertOf<T>, opts: O & {
868
+ insert(data: SingleInsertOf<W>, opts: O & {
859
869
  returning: true;
860
870
  onConflict: "ignore";
861
871
  }): Promise<TDbInsertIgnoreResult & {
862
- row?: InsertedRow<T, D>;
872
+ row?: InsertedRow<T>;
863
873
  }>;
864
874
  /**
865
875
  * `POST /` — insert one record. The version column (if any) is optional —
866
876
  * the server initialises it; `$cas` is rejected (no meaning on insert).
867
877
  */
868
- insert(data: InsertOf<T>, opts?: O): Promise<TDbInsertResult>;
878
+ insert(data: InsertOf<W>, opts?: O): Promise<TDbInsertResult>;
869
879
  /**
870
880
  * `POST /?$onConflict=ignore` — insert one record, skipping it when it
871
881
  * collides on the primary key or a unique index (since 0.1.148).
872
882
  */
873
- insert(data: InsertOf<T>, opts: O & {
883
+ insert(data: InsertOf<W>, opts: O & {
874
884
  onConflict: "ignore";
875
885
  }): Promise<TDbInsertIgnoreResult>;
876
886
  /**
@@ -882,16 +892,16 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
882
892
  * {@link VersionMismatchError}; a PK-only body with a version is a real
883
893
  * write (the server bumps the version).
884
894
  */
885
- update(data: PatchOf<T> | PatchOf<T>[], opts?: O): Promise<TDbUpdateResult>;
895
+ update(data: PatchOf<W> | PatchOf<W>[], opts?: O): Promise<TDbUpdateResult>;
886
896
  /**
887
897
  * `PUT /` — full replace one or many records by primary key. Same OCC
888
898
  * shapes as {@link update}; the version column itself is optional.
889
899
  */
890
- replace(data: RowOf<T> | RowOf<T>[], opts?: O): Promise<TDbUpdateResult>;
900
+ replace(data: RowOf<W> | RowOf<W>[], opts?: O): Promise<TDbUpdateResult>;
891
901
  /**
892
902
  * `DELETE /:id` or `DELETE /?k1=v1&k2=v2` — remove a record by primary key.
893
903
  */
894
- remove(id: Id<T>, opts?: O): Promise<TDbDeleteResult>;
904
+ remove(id: Id<W>, opts?: O): Promise<TDbDeleteResult>;
895
905
  /**
896
906
  * `GET /meta` — table/view metadata (cached after first call).
897
907
  *
@@ -1131,4 +1141,4 @@ declare function formatIdentifier(id: Record<string, unknown> | undefined, prefe
1131
1141
  */
1132
1142
  declare function encodeNavigateId(id: Record<string, unknown>, preferredId: readonly string[]): string;
1133
1143
  //#endregion
1134
- export { RelationInfo as $, AggregateStage as A, DbPatch as B, ClientError as C, VersionMismatchErrorBody as D, VersionMismatchError as E, ClientLike as F, InsertOf as G, FieldMeta as H, ClientOptions as I, NestedAggregateQuery$1 as J, MetaResponse as K, ClientResponse as L, BucketExpr as M, BucketUnit as N, AggregateQuery$1 as O, CalendarBucketLabel as P, PatchOf as Q, DataOf as R, ActionUnsupportedError as S, defaultMetaStore as St, TransportError as T, FilterExpr as U, DbRow as V, IdOf as W, OwnOf as X, NestedAggregateResult$1 as Y, PageResult as Z, ActionDisabledError as _, ValidNested$1 as _t, InsertedRow as a, TClientCallOptions as at, ActionTargetError as b, MetaStoreOptions as bt, actionIdentifier as c, TDbInsertManyIgnoreResult$1 as ct, formatIdentifierField as d, TDbQueryTarget as dt, ResponseDataOf as et, ClientValidator as f, TDbUpdateResult$1 as ft, createClientValidator as g, ValidGroupBy$1 as gt, ValidatorMode$1 as h, UniqueryControls as ht, DecoratedRow as i, StageRow as it, AtscriptClientShape as j, AggregateResult$1 as k, encodeNavigateId as l, TDbInsertManyResult$1 as lt, DbValidationContext as m, Uniquery$1 as mt, AggregateRows as n, SearchIndexInfo as nt, ReadRow as o, TDbDeleteResult$1 as ot, ClientValidatorOptions as p, TypedWithRelation as pt, NavOf as q, Client as r, ServerError as rt, SingleInsertOf as s, TDbInsertIgnoreResult$1 as st, AggregateCheck as t, RowOf as tt, formatIdentifier as u, TDbInsertResult$1 as ut, ActionDisabledErrorBody as v, WeekStart as vt, ClientValidationError as w, ActionTargetErrorBody as x, clearMetaStore as xt, ActionNotFoundError as y, MetaStore as yt, DbInsert as z };
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 };
@@ -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, SelectExpr, StageRow, TypedWithRelation, Uniquery, Uniquery as Uniquery$1, UniqueryControls, ValidGroupBy, ValidGroupBy as ValidGroupBy$1, ValidNested, ValidNested as ValidNested$1, WeekStart } from "@uniqu/core";
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";
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 { 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}. */
@@ -271,12 +271,19 @@ type ResponseDataOf<T> = T extends {
271
271
  };
272
272
  } ? unknown extends D ? T extends (new (...a: any[]) => infer I) ? I : Record<string, unknown> : D : Record<string, unknown>;
273
273
  /**
274
- * `$select` controls of a read over `T` whose controller declares the display-only
275
- * fields `D` (`@DbDecorations`): `$select` also accepts `keyof D`; filter, sort
276
- * and every other control stay over the own fields. Since 0.1.148.
274
+ * `X` without the keys `K`, its literal keys kept: `Omit` over a type with an
275
+ * index signature (`UniqueryControls`' `$`-keyword pass-through) keeps only
276
+ * the signature, which erased `$sort` / `$with` / `$limit`.
277
277
  */
278
- type DecoratedControls<T, D> = Omit<UniqueryControls<OwnOf<T>, NavOf<T>>, "$select"> & {
279
- $select?: SelectExpr<OwnOf<T> & D>;
278
+ type OmitKeys<X, K extends PropertyKey> = { [P in keyof X as P extends K ? never : P]: X[P] };
279
+ /**
280
+ * The controls of a read over `T` — `query()`, `pages()`, `one()`, the geo
281
+ * reads (since 0.1.205; before: `DecoratedControls`): `$select`, `$sort`,
282
+ * `$with`, … typed by `T`'s fields (a view's `@db.compute.host` fields are
283
+ * among them: selectable, never filtered or sorted — the server answers 400).
284
+ */
285
+ type ReadControls<T> = OmitKeys<UniqueryControls<OwnOf<T>, NavOf<T>>, "$with"> & {
286
+ /** Relations to load; a readonly list (`as const`) too. */$with?: readonly TypedWithRelation<NavOf<T>>[];
280
287
  /**
281
288
  * `false` — a `$search` read computes no relevance score: rows come in
282
289
  * `$sort` order, or primary-key order without one. A `$vector` read refuses
@@ -284,9 +291,9 @@ type DecoratedControls<T, D> = Omit<UniqueryControls<OwnOf<T>, NavOf<T>>, "$sele
284
291
  */
285
292
  $rank?: boolean;
286
293
  };
287
- /** A read query over `T` — {@link DecoratedControls} for the controls. Since 0.1.148. */
288
- type DecoratedQuery<T, D> = Omit<Uniquery$1<OwnOf<T>, NavOf<T>>, "controls"> & {
289
- controls?: DecoratedControls<T, D>;
294
+ /** A read query over `T` — {@link ReadControls} for the controls. Since 0.1.205. */
295
+ type ReadQuery<T> = Omit<Uniquery$1<OwnOf<T>, NavOf<T>>, "controls"> & {
296
+ controls?: ReadControls<T>;
290
297
  };
291
298
  /** Extract own (non-nav) properties from an Atscript annotated type. */
292
299
  type OwnOf<T> = T extends {
@@ -357,14 +364,18 @@ interface TDbQueryTarget<T = AtscriptClientShape> {
357
364
  * `undefined`) and `metaStore` (may be `undefined`); answers "none" from `availableActions`,
358
365
  * `getActionForm` (`null`) and `getActionFormTexts` (`undefined`); and rejects the rest.
359
366
  *
367
+ * `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`.
370
+ *
360
371
  * `O` (since 0.1.199) is the per-call options the read / write methods take: an implementation
361
372
  * with options of its own declares them as `O`, an interface extending {@link TClientCallOptions}
362
- * (`ClientLike<T, D, MyCallOptions>`), instead of augmenting `TClientCallOptions` — which would
373
+ * (`ClientLike<T, T, MyCallOptions>`), instead of augmenting `TClientCallOptions` — which would
363
374
  * let a plain `Client` accept them too and ignore them. `Client` itself reads only `signal`
364
375
  * (and `insert`'s `onConflict` / `returning`).
365
376
  * @since 0.1.196
366
377
  */
367
- type ClientLike<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>, O extends TClientCallOptions = TClientCallOptions> = Pick<Client<T, D, O>, keyof Client<T, D, O>>;
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>>;
368
379
  //#endregion
369
380
  //#region src/client-error.d.ts
370
381
  /**
@@ -660,13 +671,11 @@ type Own<T> = OwnOf<T>;
660
671
  type Nav<T> = NavOf<T>;
661
672
  type Id<T> = IdOf<T>;
662
673
  type Response<T, Q> = ClientResponse<T, Q>;
663
- /** A read row: the response over the own fields plus the declared decorations `D`, each optional. */
664
- type DecoratedRow<T, Q, D> = Response<T, Q> & Partial<D>;
665
674
  /**
666
- * A `query()` / `pages()` row: {@link DecoratedRow}, plus `$score` on a vector read
675
+ * A `query()` / `pages()` row: the response over `T`, plus `$score` on a vector read
667
676
  * (`$search` with `$vector`, since 0.1.183): higher = closer, on the scale of `$threshold`.
668
677
  */
669
- type ReadRow<T, Q, D> = DecoratedRow<T, Q, D> & (Q extends {
678
+ type ReadRow<T, Q> = Response<T, Q> & (Q extends {
670
679
  controls: {
671
680
  $search: string;
672
681
  $vector: string;
@@ -681,8 +690,8 @@ type ReadRow<T, Q, D> = DecoratedRow<T, Q, D> & (Q extends {
681
690
  type SingleInsertOf<T> = [keyof InsertOf<T>] extends [never] ? Record<string, any> & {
682
691
  readonly [Symbol.iterator]?: never;
683
692
  } : InsertOf<T>;
684
- /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape. */
685
- type InsertedRow<T, D> = DecoratedRow<T, Record<never, never>, D>;
693
+ /** The stored row `insert(row, { returning: true })` answers: the `one()` row shape (over the read model `T`). */
694
+ type InsertedRow<T> = Response<T, Record<never, never>>;
686
695
  /** A two-level aggregate query: one with `controls.$from`. */
687
696
  type NestedShape = {
688
697
  controls: {
@@ -714,15 +723,16 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
714
723
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
715
724
  * ```
716
725
  *
717
- * `D` (since 0.1.148) types the display-only fields the controller declares
718
- * with `@DbDecorations`: `$select` of the read methods accepts their keys and
719
- * rows carry them as optional properties. Filter and sort stay over `T`'s own
720
- * fields — a decoration is never filterable or sortable.
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:
721
731
  *
722
732
  * ```typescript
723
- * const tickets = new Client<typeof Ticket, TicketDecorations>('/api/tickets')
733
+ * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
724
734
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
725
- * rows[0].ownerName // string | undefined
735
+ * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
726
736
  * ```
727
737
  *
728
738
  * `O` (since 0.1.199) types the per-call options the read / write methods
@@ -731,7 +741,7 @@ type AggregateRows<T, Q extends AggregateQuery<T> | NestedAggregateQuery<T>> = Q
731
741
  * `Client` itself reads only `signal` (and `insert`'s `onConflict` /
732
742
  * `returning`).
733
743
  */
734
- declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D extends object = Record<never, never>, O extends TClientCallOptions = TClientCallOptions> {
744
+ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, W extends AtscriptClientShape = T, O extends TClientCallOptions = TClientCallOptions> {
735
745
  private readonly _path;
736
746
  private readonly _baseUrl;
737
747
  private readonly _fetch;
@@ -757,7 +767,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
757
767
  * relations not listed in `$with` are stripped from the row type. A vector
758
768
  * read (`controls: { $search, $vector }`) types `$score` on every row.
759
769
  */
760
- query<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, opts?: O): Promise<ReadRow<T, Q, D>[]>;
770
+ query<const Q extends ReadQuery<T> = ReadQuery<T>>(query?: Q, opts?: O): Promise<ReadRow<T, Q>[]>;
761
771
  /**
762
772
  * `GET /query` with `$count: true` — returns record count.
763
773
  */
@@ -798,7 +808,7 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
798
808
  * Response rows narrow by the literal `$with` array — same algebra as
799
809
  * {@link query}, `$score` on a vector read included.
800
810
  */
801
- pages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<ReadRow<T, Q, D>>>;
811
+ pages<const Q extends ReadQuery<T> = ReadQuery<T>>(query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<ReadRow<T, Q>>>;
802
812
  /**
803
813
  * `GET /geo` — distance-ranked geospatial search (tables with `@db.index.geo`).
804
814
  *
@@ -808,13 +818,13 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
808
818
  * in `query.controls`; filter / `$select` / `$with` / `$skip` / `$limit`
809
819
  * compose as usual.
810
820
  */
811
- geoSearch<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, opts?: O): Promise<Array<DecoratedRow<T, Q, D> & {
821
+ geoSearch<const Q extends ReadQuery<T> = ReadQuery<T>>(point: [number, number], query?: Q, opts?: O): Promise<Array<Response<T, Q> & {
812
822
  $distance: number;
813
823
  }>>;
814
824
  /**
815
825
  * `GET /geo` with `$page` / `$size` — paginated distance-ranked search.
816
826
  */
817
- geoPages<const Q extends DecoratedQuery<T, D> = DecoratedQuery<T, D>>(point: [number, number], query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<DecoratedRow<T, Q, D> & {
827
+ geoPages<const Q extends ReadQuery<T> = ReadQuery<T>>(point: [number, number], query?: Q, page?: number, size?: number, opts?: O): Promise<PageResult<Response<T, Q> & {
818
828
  $distance: number;
819
829
  }>>;
820
830
  /**
@@ -824,19 +834,19 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
824
834
  * `query.controls` — same algebra as {@link query}.
825
835
  */
826
836
  one<const Q extends {
827
- controls?: DecoratedControls<T, D>;
837
+ controls?: ReadControls<T>;
828
838
  } = {
829
- controls?: DecoratedControls<T, D>;
830
- }>(id: Id<T>, query?: Q, opts?: O): Promise<DecoratedRow<T, Q, D> | null>;
839
+ controls?: ReadControls<T>;
840
+ }>(id: Id<T>, query?: Q, opts?: O): Promise<Response<T, Q> | null>;
831
841
  /**
832
842
  * `POST /` — insert many records.
833
843
  */
834
- insert(data: InsertOf<T>[], opts?: O): Promise<TDbInsertManyResult>;
844
+ insert(data: InsertOf<W>[], opts?: O): Promise<TDbInsertManyResult>;
835
845
  /**
836
846
  * `POST /?$onConflict=ignore` — insert many records, skipping the ones that
837
847
  * collide; the result reports inserted and skipped input indices (since 0.1.148).
838
848
  */
839
- insert(data: InsertOf<T>[], opts: O & {
849
+ insert(data: InsertOf<W>[], opts: O & {
840
850
  onConflict: "ignore";
841
851
  }): Promise<TDbInsertManyIgnoreResult>;
842
852
  /**
@@ -846,31 +856,31 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
846
856
  * the server could not apply the preference (the caller may not read the
847
857
  * row, or a skipped conflict).
848
858
  */
849
- insert(data: SingleInsertOf<T>, opts: O & {
859
+ insert(data: SingleInsertOf<W>, opts: O & {
850
860
  returning: true;
851
861
  }): Promise<TDbInsertResult & {
852
- row?: InsertedRow<T, D>;
862
+ row?: InsertedRow<T>;
853
863
  }>;
854
864
  /**
855
865
  * `POST /?$onConflict=ignore` with `Prefer: return=representation` — as
856
866
  * above; a skipped row answers `{ conflict: true }` without `row`.
857
867
  */
858
- insert(data: SingleInsertOf<T>, opts: O & {
868
+ insert(data: SingleInsertOf<W>, opts: O & {
859
869
  returning: true;
860
870
  onConflict: "ignore";
861
871
  }): Promise<TDbInsertIgnoreResult & {
862
- row?: InsertedRow<T, D>;
872
+ row?: InsertedRow<T>;
863
873
  }>;
864
874
  /**
865
875
  * `POST /` — insert one record. The version column (if any) is optional —
866
876
  * the server initialises it; `$cas` is rejected (no meaning on insert).
867
877
  */
868
- insert(data: InsertOf<T>, opts?: O): Promise<TDbInsertResult>;
878
+ insert(data: InsertOf<W>, opts?: O): Promise<TDbInsertResult>;
869
879
  /**
870
880
  * `POST /?$onConflict=ignore` — insert one record, skipping it when it
871
881
  * collides on the primary key or a unique index (since 0.1.148).
872
882
  */
873
- insert(data: InsertOf<T>, opts: O & {
883
+ insert(data: InsertOf<W>, opts: O & {
874
884
  onConflict: "ignore";
875
885
  }): Promise<TDbInsertIgnoreResult>;
876
886
  /**
@@ -882,16 +892,16 @@ declare class Client<T extends AtscriptClientShape = AtscriptClientShape, D exte
882
892
  * {@link VersionMismatchError}; a PK-only body with a version is a real
883
893
  * write (the server bumps the version).
884
894
  */
885
- update(data: PatchOf<T> | PatchOf<T>[], opts?: O): Promise<TDbUpdateResult>;
895
+ update(data: PatchOf<W> | PatchOf<W>[], opts?: O): Promise<TDbUpdateResult>;
886
896
  /**
887
897
  * `PUT /` — full replace one or many records by primary key. Same OCC
888
898
  * shapes as {@link update}; the version column itself is optional.
889
899
  */
890
- replace(data: RowOf<T> | RowOf<T>[], opts?: O): Promise<TDbUpdateResult>;
900
+ replace(data: RowOf<W> | RowOf<W>[], opts?: O): Promise<TDbUpdateResult>;
891
901
  /**
892
902
  * `DELETE /:id` or `DELETE /?k1=v1&k2=v2` — remove a record by primary key.
893
903
  */
894
- remove(id: Id<T>, opts?: O): Promise<TDbDeleteResult>;
904
+ remove(id: Id<W>, opts?: O): Promise<TDbDeleteResult>;
895
905
  /**
896
906
  * `GET /meta` — table/view metadata (cached after first call).
897
907
  *
@@ -1131,4 +1141,4 @@ declare function formatIdentifier(id: Record<string, unknown> | undefined, prefe
1131
1141
  */
1132
1142
  declare function encodeNavigateId(id: Record<string, unknown>, preferredId: readonly string[]): string;
1133
1143
  //#endregion
1134
- export { RelationInfo as $, AggregateStage as A, DbPatch as B, ClientError as C, VersionMismatchErrorBody as D, VersionMismatchError as E, ClientLike as F, InsertOf as G, FieldMeta as H, ClientOptions as I, NestedAggregateQuery$1 as J, MetaResponse as K, ClientResponse as L, BucketExpr as M, BucketUnit as N, AggregateQuery$1 as O, CalendarBucketLabel as P, PatchOf as Q, DataOf as R, ActionUnsupportedError as S, defaultMetaStore as St, TransportError as T, FilterExpr as U, DbRow as V, IdOf as W, OwnOf as X, NestedAggregateResult$1 as Y, PageResult as Z, ActionDisabledError as _, ValidNested$1 as _t, InsertedRow as a, TClientCallOptions as at, ActionTargetError as b, MetaStoreOptions as bt, actionIdentifier as c, TDbInsertManyIgnoreResult$1 as ct, formatIdentifierField as d, TDbQueryTarget as dt, ResponseDataOf as et, ClientValidator as f, TDbUpdateResult$1 as ft, createClientValidator as g, ValidGroupBy$1 as gt, ValidatorMode$1 as h, UniqueryControls as ht, DecoratedRow as i, StageRow as it, AtscriptClientShape as j, AggregateResult$1 as k, encodeNavigateId as l, TDbInsertManyResult$1 as lt, DbValidationContext as m, Uniquery$1 as mt, AggregateRows as n, SearchIndexInfo as nt, ReadRow as o, TDbDeleteResult$1 as ot, ClientValidatorOptions as p, TypedWithRelation as pt, NavOf as q, Client as r, ServerError as rt, SingleInsertOf as s, TDbInsertIgnoreResult$1 as st, AggregateCheck as t, RowOf as tt, formatIdentifier as u, TDbInsertResult$1 as ut, ActionDisabledErrorBody as v, WeekStart as vt, ClientValidationError as w, ActionTargetErrorBody as x, clearMetaStore as xt, ActionNotFoundError as y, MetaStore as yt, DbInsert as z };
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 };
package/dist/index.cjs CHANGED
@@ -151,15 +151,16 @@ function clearMetaStore() {
151
151
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
152
152
  * ```
153
153
  *
154
- * `D` (since 0.1.148) types the display-only fields the controller declares
155
- * with `@DbDecorations`: `$select` of the read methods accepts their keys and
156
- * rows carry them as optional properties. Filter and sort stay over `T`'s own
157
- * fields — a decoration is never filterable or sortable.
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:
158
159
  *
159
160
  * ```typescript
160
- * const tickets = new Client<typeof Ticket, TicketDecorations>('/api/tickets')
161
+ * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
161
162
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
162
- * rows[0].ownerName // string | undefined
163
+ * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
163
164
  * ```
164
165
  *
165
166
  * `O` (since 0.1.199) types the per-call options the read / write methods
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as RelationInfo, A as AggregateStage, B as DbPatch, C as ClientError, D as VersionMismatchErrorBody, E as VersionMismatchError, F as ClientLike, G as InsertOf, H as FieldMeta, I as ClientOptions, J as NestedAggregateQuery, K as MetaResponse, L as ClientResponse, M as BucketExpr, N as BucketUnit, O as AggregateQuery, P as CalendarBucketLabel, Q as PatchOf, R as DataOf, S as ActionUnsupportedError, St as defaultMetaStore, T as TransportError, U as FilterExpr, V as DbRow, W as IdOf, X as OwnOf, Y as NestedAggregateResult, Z as PageResult, _ as ActionDisabledError, _t as ValidNested, a as InsertedRow, at as TClientCallOptions, b as ActionTargetError, bt as MetaStoreOptions, c as actionIdentifier, ct as TDbInsertManyIgnoreResult, d as formatIdentifierField, dt as TDbQueryTarget, et as ResponseDataOf, f as ClientValidator, ft as TDbUpdateResult, gt as ValidGroupBy, h as ValidatorMode, ht as UniqueryControls, i as DecoratedRow, it as StageRow, j as AtscriptClientShape, k as AggregateResult, l as encodeNavigateId, lt as TDbInsertManyResult, mt as Uniquery, n as AggregateRows, nt as SearchIndexInfo, o as ReadRow, ot as TDbDeleteResult, p as ClientValidatorOptions, pt as TypedWithRelation, q as NavOf, r as Client, rt as ServerError, s as SingleInsertOf, st as TDbInsertIgnoreResult, t as AggregateCheck, tt as RowOf, u as formatIdentifier, ut as TDbInsertResult, v as ActionDisabledErrorBody, vt as WeekStart, w as ClientValidationError, x as ActionTargetErrorBody, xt as clearMetaStore, y as ActionNotFoundError, yt as MetaStore, z as DbInsert } from "./client-CVcoc72F.cjs";
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";
2
2
  import { BucketSeriesOptions, NextBucketOptions, bucketSeries, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
3
3
  import { TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
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 DecoratedRow, 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 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 };
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 };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as RelationInfo, A as AggregateStage, B as DbPatch, C as ClientError, D as VersionMismatchErrorBody, E as VersionMismatchError, F as ClientLike, G as InsertOf, H as FieldMeta, I as ClientOptions, J as NestedAggregateQuery, K as MetaResponse, L as ClientResponse, M as BucketExpr, N as BucketUnit, O as AggregateQuery, P as CalendarBucketLabel, Q as PatchOf, R as DataOf, S as ActionUnsupportedError, St as defaultMetaStore, T as TransportError, U as FilterExpr, V as DbRow, W as IdOf, X as OwnOf, Y as NestedAggregateResult, Z as PageResult, _ as ActionDisabledError, _t as ValidNested, a as InsertedRow, at as TClientCallOptions, b as ActionTargetError, bt as MetaStoreOptions, c as actionIdentifier, ct as TDbInsertManyIgnoreResult, d as formatIdentifierField, dt as TDbQueryTarget, et as ResponseDataOf, f as ClientValidator, ft as TDbUpdateResult, gt as ValidGroupBy, h as ValidatorMode, ht as UniqueryControls, i as DecoratedRow, it as StageRow, j as AtscriptClientShape, k as AggregateResult, l as encodeNavigateId, lt as TDbInsertManyResult, mt as Uniquery, n as AggregateRows, nt as SearchIndexInfo, o as ReadRow, ot as TDbDeleteResult, p as ClientValidatorOptions, pt as TypedWithRelation, q as NavOf, r as Client, rt as ServerError, s as SingleInsertOf, st as TDbInsertIgnoreResult, t as AggregateCheck, tt as RowOf, u as formatIdentifier, ut as TDbInsertResult, v as ActionDisabledErrorBody, vt as WeekStart, w as ClientValidationError, x as ActionTargetErrorBody, xt as clearMetaStore, y as ActionNotFoundError, yt as MetaStore, z as DbInsert } from "./client-CM--7NfJ.mjs";
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";
2
2
  import { BucketSeriesOptions, NextBucketOptions, bucketSeries, bucketStartInstant, nextBucketLabel } from "@uniqu/core";
3
3
  import { TSerializedAnnotatedType } from "@atscript/typescript/utils";
4
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 DecoratedRow, 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 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 };
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 };
package/dist/index.mjs CHANGED
@@ -150,15 +150,16 @@ function clearMetaStore() {
150
150
  * const page = await users.pages({ filter: { active: true } }, 1, 20)
151
151
  * ```
152
152
  *
153
- * `D` (since 0.1.148) types the display-only fields the controller declares
154
- * with `@DbDecorations`: `$select` of the read methods accepts their keys and
155
- * rows carry them as optional properties. Filter and sort stay over `T`'s own
156
- * fields — a decoration is never filterable or sortable.
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:
157
158
  *
158
159
  * ```typescript
159
- * const tickets = new Client<typeof Ticket, TicketDecorations>('/api/tickets')
160
+ * const tickets = new Client<typeof TicketRow, typeof Ticket>('/api/tickets')
160
161
  * const rows = await tickets.query({ controls: { $select: ['title', 'ownerName'] } })
161
- * rows[0].ownerName // string | undefined
162
+ * await tickets.update({ id: 1, title: 'Renamed' }) // typed by Ticket
162
163
  * ```
163
164
  *
164
165
  * `O` (since 0.1.199) types the per-call options the read / write methods
@@ -1,2 +1,2 @@
1
- import { f as ClientValidator, g as createClientValidator, h as ValidatorMode, m as DbValidationContext, p as ClientValidatorOptions, w as ClientValidationError } from "./client-CVcoc72F.cjs";
1
+ import { C as ClientValidationError, d as ClientValidator, f as ClientValidatorOptions, h as createClientValidator, m as ValidatorMode, p as DbValidationContext } from "./client-BRXq9YfV.cjs";
2
2
  export { ClientValidationError, ClientValidator, ClientValidatorOptions, type DbValidationContext, type ValidatorMode, createClientValidator };
@@ -1,2 +1,2 @@
1
- import { f as ClientValidator, g as createClientValidator, h as ValidatorMode, m as DbValidationContext, p as ClientValidatorOptions, w as ClientValidationError } from "./client-CM--7NfJ.mjs";
1
+ import { C as ClientValidationError, d as ClientValidator, f as ClientValidatorOptions, h as createClientValidator, m as ValidatorMode, p as DbValidationContext } from "./client-DggC00AO.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.203",
3
+ "version": "0.1.205",
4
4
  "description": "Browser-compatible HTTP client for @atscript/moost-db REST endpoints.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -47,14 +47,14 @@
47
47
  "@uniqu/url": "^0.2.2"
48
48
  },
49
49
  "devDependencies": {
50
- "@atscript/core": "^0.2.28",
51
- "@atscript/typescript": "^0.2.28",
52
- "unplugin-atscript": "^0.2.28",
53
- "@atscript/db": "0.1.203"
50
+ "@atscript/core": "^0.2.29",
51
+ "@atscript/typescript": "^0.2.29",
52
+ "unplugin-atscript": "^0.2.29",
53
+ "@atscript/db": "0.1.205"
54
54
  },
55
55
  "peerDependencies": {
56
- "@atscript/typescript": "^0.2.28",
57
- "@atscript/db": "^0.1.203"
56
+ "@atscript/typescript": "^0.2.29",
57
+ "@atscript/db": "^0.1.205"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "vp pack",