@haddowg/json-api-client 1.26.0 → 1.28.0

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.
@@ -40,6 +40,33 @@ interface PivotDescriptor {
40
40
  required?: readonly string[];
41
41
  /** The fields whose value may be `null`. Absent means none. */
42
42
  nullable?: readonly string[];
43
+ /**
44
+ * The members the object takes beside {@link fields}, when the server opens it: each one's
45
+ * wire-format hint (`unknown` for any value) and whether it may be `null`. `false` closes an
46
+ * identifier meta object. Absent closes every other object, and leaves an identifier meta object
47
+ * open, as a server that doesn't say leaves it.
48
+ */
49
+ additional?: AdditionalMembersDescriptor | false;
50
+ /**
51
+ * The values a field may take when the server lists them, from its `enum` or `const`: the field
52
+ * is typed as one of these literals, plus `null` when it is nullable, instead of by its hint. A
53
+ * field hinted `array` lists the values of its items, and is typed as a list of them. Absent for
54
+ * a field that takes any value of its hint, and absent altogether in a descriptor generated
55
+ * without it.
56
+ */
57
+ values?: Readonly<Record<string, readonly MetaLiteral[]>>;
58
+ }
59
+ /** A literal a meta member may take: one of the values its `enum` or `const` lists. */
60
+ type MetaLiteral = string | number | boolean;
61
+ /**
62
+ * The undeclared members an open meta object takes: their wire-format hint, the values they are
63
+ * limited to when the server lists them, or their items are for a hint of `array`, and whether
64
+ * `null`.
65
+ */
66
+ interface AdditionalMembersDescriptor {
67
+ format: string;
68
+ nullable?: boolean;
69
+ values?: readonly MetaLiteral[];
43
70
  }
44
71
  /**
45
72
  * The members a document declares in its top-level `meta`, read from the per-operation document
@@ -51,6 +78,21 @@ interface PivotDescriptor {
51
78
  type DocumentMetaDescriptor = PivotDescriptor;
52
79
  /** An operation of a type whose document may declare its top-level `meta`. */
53
80
  type DocumentMetaOperation = 'fetchMany' | 'fetchOne' | 'create' | 'update' | 'delete';
81
+ /** A write of a type whose request document may declare its top-level `meta`. */
82
+ type RequestMetaOperation = 'create' | 'update' | 'delete';
83
+ /**
84
+ * The `meta` of a type's resource objects, read from the components the server marks
85
+ * `x-resource-meta`: `read` what a response renders, `create` and `update` what a write's
86
+ * `data.meta` takes. `atomicCreate` and `atomicUpdate` are the `data.meta` of an `add` or `update`
87
+ * inside an atomic batch, present only when they differ from `create` and `update`.
88
+ */
89
+ interface ResourceMetaDescriptor {
90
+ read?: PivotDescriptor;
91
+ create?: PivotDescriptor;
92
+ update?: PivotDescriptor;
93
+ atomicCreate?: PivotDescriptor;
94
+ atomicUpdate?: PivotDescriptor;
95
+ }
54
96
  interface RelationDescriptor {
55
97
  cardinality: Cardinality;
56
98
  /** Related JSON:API type(s). */
@@ -179,6 +221,25 @@ interface RelationDescriptor {
179
221
  * read's members for a to-many, its single read's for a to-one. Absent when it declares none.
180
222
  */
181
223
  documentMeta?: DocumentMetaDescriptor;
224
+ /**
225
+ * The top-level `meta` each relationship write takes, keyed by its verb, read from the request
226
+ * document the server marks `x-request-meta`. A verb that declares none has no entry, and the
227
+ * map is absent when none does.
228
+ */
229
+ requestMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
230
+ /**
231
+ * The top-level `meta` each operation on the relation takes inside an atomic batch, keyed by its
232
+ * verb like {@link requestMeta}, read from the atomic relationship operation kinds the type has
233
+ * of its own for the relation. A verb that declares none has no entry, and the map is absent
234
+ * when none does.
235
+ */
236
+ atomicRequestMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
237
+ /**
238
+ * The top-level `meta` of the meta-only `200` each relationship write answers with instead of
239
+ * the linkage, keyed by its verb. A verb answering with the linkage has no entry, and the map is
240
+ * absent when none answers meta-only.
241
+ */
242
+ mutationMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
182
243
  }
183
244
  /** A built-in pagination strategy. */
184
245
  type PaginatorStrategy = 'page' | 'offset' | 'cursor' | 'fixed';
@@ -257,6 +318,8 @@ interface InputMedia {
257
318
  */
258
319
  interface AcceptedDescriptor {
259
320
  jobType: string;
321
+ /** The top-level `meta` the job document declares. Absent when it declares none. */
322
+ meta?: DocumentMetaDescriptor;
260
323
  }
261
324
  /**
262
325
  * A custom action declared on a type (`#[AsJsonApiAction]`). The runtime reaches it via
@@ -368,6 +431,12 @@ interface ActionDescriptor {
368
431
  * result is then that `200`'s `meta` or the resource. Absent otherwise.
369
432
  */
370
433
  metaResult?: boolean;
434
+ /**
435
+ * The top-level `meta` the action's request document takes, read from the document the server
436
+ * marks `x-request-meta`. An action with input `none` sends a meta-only document carrying it.
437
+ * Absent when the action declares none.
438
+ */
439
+ requestMeta?: DocumentMetaDescriptor;
371
440
  }
372
441
  /**
373
442
  * The `withCount` capability of a type's read endpoints (the Countable profile, core ADR
@@ -468,6 +537,23 @@ interface ResourceDescriptor {
468
537
  * is includable, or the document types `included` only as `{type, id}`.
469
538
  */
470
539
  included?: readonly string[];
540
+ /**
541
+ * The attributes whose single keys a sparse fieldset may select, under the Nested Fieldsets
542
+ * profile: attribute name -> the pattern a key must match (a regular expression source,
543
+ * unanchored and without delimiters), `\*` for a list whose items take keys. Each adds
544
+ * `<attribute>.${string}` to the members `fields` takes for this type. Absent when no attribute
545
+ * declares a nested fieldset.
546
+ */
547
+ nestedFieldsets?: Readonly<Record<string, string>>;
548
+ /**
549
+ * The paths into nested objects a sparse fieldset may select of the attributes in
550
+ * {@link nestedFieldsets}: attribute name -> one entry per path, each the pattern of every key
551
+ * along it after the attribute's own, such as `['geo', '(?:lat|lng)']` for `location.geo.lat`,
552
+ * or `['\\*', '(?:sku|qty)']` for `lines.*.sku`, where `\*` stands for every item of a list.
553
+ * A key that is a plain name is escaped the way the server escapes it. Absent when no nested fieldset
554
+ * key holds an object or a list whose own keys may be selected.
555
+ */
556
+ nestedFieldsetPaths?: Readonly<Record<string, readonly (readonly string[])[]>>;
471
557
  /**
472
558
  * The sort tokens the COLLECTION read accepts in `sort` — signed field names (`title`,
473
559
  * `-title`). Drives `sort` narrowing. Absent when the collection advertises no sorting (so
@@ -525,6 +611,20 @@ interface ResourceDescriptor {
525
611
  * {@link ActionDescriptor.documentMeta}.
526
612
  */
527
613
  documentMeta?: Readonly<Partial<Record<DocumentMetaOperation, DocumentMetaDescriptor>>>;
614
+ /**
615
+ * The top-level `meta` each of the type's writes takes, keyed `create`, `update` or `delete`,
616
+ * read from the request document the server marks `x-request-meta`. A delete declaring it takes
617
+ * a meta-only request document. A write that declares none has no entry, and the map is absent
618
+ * when none does.
619
+ */
620
+ requestMeta?: Readonly<Partial<Record<RequestMetaOperation, DocumentMetaDescriptor>>>;
621
+ /**
622
+ * The top-level `meta` each of the type's operations takes inside an atomic batch, keyed like
623
+ * {@link requestMeta}, read from the atomic operation kinds the type has of its own.
624
+ */
625
+ atomicRequestMeta?: Readonly<Partial<Record<RequestMetaOperation, DocumentMetaDescriptor>>>;
626
+ /** The `meta` of the type's resource objects, as a read renders it and a write sends it. */
627
+ resourceMeta?: ResourceMetaDescriptor;
528
628
  }
529
629
  /** A write that can answer `202 Accepted`. */
530
630
  type AcceptedOperation = 'create' | 'update';
@@ -584,15 +684,18 @@ interface PollOptions {
584
684
  signal?: AbortSignal;
585
685
  }
586
686
  /**
587
- * A write the server accepted for later (`202 Accepted`). `Job` is the job it answered with and
588
- * `Result` what the write resolves to once the job is done.
687
+ * A write the server accepted for later (`202 Accepted`). `Job` is the job it answered with,
688
+ * `Result` what the write resolves to once the job is done, and `Meta` the job document's
689
+ * top-level `meta`.
589
690
  */
590
- interface Accepted<Job, Result = unknown> {
691
+ interface Accepted<Job, Result = unknown, Meta = Record<string, unknown> | undefined> {
591
692
  /**
592
693
  * The job, materialised as its type's resource, or the document's top-level `meta` when the
593
694
  * server answered with a meta-only document.
594
695
  */
595
696
  readonly job: Job;
697
+ /** The `202` document's top-level `meta`, typed with the members the operation declares. */
698
+ readonly meta: Meta;
596
699
  /** The job URL, from `Content-Location`, which {@link $poll} reads until the job is done. */
597
700
  readonly contentLocation: string;
598
701
  /**
@@ -779,6 +882,25 @@ type PageParamsOf<P extends Page> = PaginatorKind extends P['kind'] ? Readonly<R
779
882
  kind: A;
780
883
  } : unknown);
781
884
  //#endregion
885
+ //#region src/nested-fieldset.d.ts
886
+ /**
887
+ * The keys a sparse fieldset selected of each attribute it narrowed, under the Nested Fieldsets
888
+ * profile (https://haddowg.github.io/json-api/profiles/nested-fieldsets/): attribute name -> the
889
+ * paths `fields[type]=<attribute>.<path>` named, in request order, each once. A path into a nested
890
+ * object, such as `geo.lat`, names one key per level, and a path through a list names its items
891
+ * `*`, such as `*.sku`. An attribute the fieldset also lists whole
892
+ * is left out, and so is a path whose key the fieldset also lists whole, since the server renders
893
+ * those whole. A path ending in `*` names the list itself, so `lines.*` lists `lines` whole and
894
+ * `shipping.parcels.*` selects `parcels` whole. Empty when nothing was narrowed.
895
+ */
896
+ type NestedFieldset = Readonly<Record<string, readonly string[]>>;
897
+ /**
898
+ * The {@link NestedFieldset} of one type's `fields[type]` members. The path is everything after the
899
+ * first full stop, as the server reads it, and a member with an empty key at any level selects
900
+ * nothing.
901
+ */
902
+ declare function nestedFieldset(listed: readonly string[] | undefined): NestedFieldset;
903
+ //#endregion
782
904
  //#region src/materialise.d.ts
783
905
  /** A trimmed, by-reference top-level envelope shared by every resource from one response. */
784
906
  interface DocumentEnvelope {
@@ -828,6 +950,11 @@ interface ResourceEnvelope {
828
950
  readonly $self: string | undefined;
829
951
  readonly $document: DocumentEnvelope;
830
952
  readonly $raw: RawResource;
953
+ /**
954
+ * The keys the request's sparse fieldset selected of each attribute it narrowed, under the Nested
955
+ * Fieldsets profile. An attribute named here holds only those of its keys the resource has.
956
+ */
957
+ readonly $nestedFieldset: NestedFieldset;
831
958
  $rel(name: string): RelationView | undefined;
832
959
  /**
833
960
  * A relationship's count, from its `meta.total` (a `withCount` read): a finite number, else
@@ -876,6 +1003,11 @@ interface MaterialiseContext {
876
1003
  * before the document is materialised. Absent => no per-field validation (the default).
877
1004
  */
878
1005
  validate?: ResolvedValidator | undefined;
1006
+ /**
1007
+ * The sparse fieldsets the request sent, by type, which tell an attribute narrowed to some of
1008
+ * its keys from one rendered whole (see {@link ResourceEnvelope.$nestedFieldset}).
1009
+ */
1010
+ fields?: Readonly<Record<string, readonly string[]>> | undefined;
879
1011
  }
880
1012
  /** A raw JSON:API resource object (or bare identifier) off the wire. */
881
1013
  interface RawResource {
@@ -993,7 +1125,7 @@ type AtomicRef = ResourceIdentifier | {
993
1125
  */
994
1126
  type AtomicCreateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = {
995
1127
  type: T;
996
- } & CreateInput<D, W, T>;
1128
+ } & CreateInput<D, W, T, 'atomicCreate'>;
997
1129
  /**
998
1130
  * Flat update input for type `T`: the `type` discriminant + the target's identity (`id`, OR a
999
1131
  * `lid` for a resource created earlier in the same batch) plus the type's flat update
@@ -1003,11 +1135,22 @@ type AtomicUpdateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = ({
1003
1135
  type: T;
1004
1136
  id: string;
1005
1137
  lid?: never;
1006
- } & UpdateInput<D, W, T>) | ({
1138
+ } & UpdateInput<D, W, T, 'atomicUpdate'>) | ({
1007
1139
  type: T;
1008
1140
  lid: string;
1009
1141
  id?: never;
1010
- } & UpdateInput<D, W, T>);
1142
+ } & UpdateInput<D, W, T, 'atomicUpdate'>);
1143
+ /**
1144
+ * The options argument of an atomic operation of type `T`: the operation's `meta`, typed by the
1145
+ * type's `atomicRequestMeta` and required when a member is. A type declaring none takes any.
1146
+ */
1147
+ type AtomicOperationArgs<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation> = OptionsArg<RequiresRequestMeta<RequestMetaOf<D, T, Op, true>>, MetaOption<RequestMetaOf<D, T, Op, true>>>;
1148
+ /**
1149
+ * The options argument of an atomic operation with verb `V` on relation `R` of type `T`: its
1150
+ * `meta`, typed by the relation's `atomicRequestMeta` and required when a member is. A relation
1151
+ * declaring none takes any.
1152
+ */
1153
+ type AtomicRelationshipArgs<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = OptionsArg<RequiresRequestMeta<RelationRequestMetaOf<D, T, R, V, true>>, MetaOption<RelationRequestMetaOf<D, T, R, V, true>>>;
1011
1154
  /**
1012
1155
  * The handle a {@link AtomicRecorder.create} returns. It is a `lid`-bearing relationship ref
1013
1156
  * (`{ type, lid }`) — pass it (or spread it) into a later op's relation slot to wire the
@@ -1038,6 +1181,18 @@ interface AtomicDeleteHandle {
1038
1181
  readonly kind: 'delete';
1039
1182
  readonly opIndex: number;
1040
1183
  }
1184
+ /**
1185
+ * The handle a relationship operation returns (the `add`, `remove`, `replace` or `set` of
1186
+ * {@link AtomicRecorder.rel}): the target's type `T`, its `relationship` `R`, its op `kind`
1187
+ * (`'relationship'`) and its `opIndex`. Its positional result is the linkage the server answered
1188
+ * with.
1189
+ */
1190
+ interface AtomicRelationshipHandle<T extends string = string, R extends string = string> {
1191
+ readonly type: T;
1192
+ readonly relationship: R;
1193
+ readonly kind: 'relationship';
1194
+ readonly opIndex: number;
1195
+ }
1041
1196
  /**
1042
1197
  * Any handle a recorder method returns — the element type of the callback's result tuple, used
1043
1198
  * as the inference constraint for the typed-tuple `atomic` form. The discriminant is left open
@@ -1048,7 +1203,28 @@ interface AtomicDeleteHandle {
1048
1203
  * is a real `TypeName<D>`, so the open constraint is sound; `AtomicResultOf` re-infers the precise
1049
1204
  * `T` per element (guarded by `TypeName<D>` there).
1050
1205
  */
1051
- type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | AtomicDeleteHandle;
1206
+ type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | AtomicDeleteHandle | AtomicRelationshipHandle<string, string>;
1207
+ /**
1208
+ * A relationship verb inside an atomic batch: present only when relation `R`'s cardinality matches
1209
+ * the verb's and the relation advertises it in its `mutations` flags, as the standalone accessor's
1210
+ * verbs are gated, and `never` otherwise.
1211
+ */
1212
+ type AtomicRelationMutation<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = TakesVerb<D, T, R, V> extends true ? (members: RelationshipMembers<D, T, R, V>, ...opts: AtomicRelationshipArgs<D, T, R, V>) => AtomicRelationshipHandle<T, R> : never;
1213
+ /**
1214
+ * What {@link AtomicRecorder.rel} returns: relation `R` of a resource of type `T`, whose verbs
1215
+ * each record one relationship operation. A to-many takes `add`, `remove` and `replace` and a
1216
+ * to-one `set`, each only when the relation advertises it.
1217
+ */
1218
+ interface AtomicRelationshipRecorder<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> {
1219
+ /** Add `members` to the to-many: an `add` op on its relationship. */
1220
+ add: AtomicRelationMutation<D, T, R, 'add'>;
1221
+ /** Remove `members` from the to-many: a `remove` op on its relationship. */
1222
+ remove: AtomicRelationMutation<D, T, R, 'remove'>;
1223
+ /** Replace every member of the to-many with `members`: an `update` op on its relationship. */
1224
+ replace: AtomicRelationMutation<D, T, R, 'replace'>;
1225
+ /** Set the to-one to `member`, or clear it with `null`: an `update` op on its relationship. */
1226
+ set: AtomicRelationMutation<D, T, R, 'set'>;
1227
+ }
1052
1228
  /**
1053
1229
  * The recorder handed to the `client.atomic` callback. Each method appends an op (preserving
1054
1230
  * order) and returns a handle carrying the op's discriminant `T`, `kind`, and `opIndex`. The
@@ -1058,9 +1234,19 @@ type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | At
1058
1234
  * just-created resource wires into a later op without a server id.
1059
1235
  */
1060
1236
  interface AtomicRecorder<D extends ApiDescriptor, W> {
1061
- create<T extends TypeName<D>>(input: AtomicCreateInput<D, W, T>): AtomicCreateHandle<T>;
1062
- update<T extends TypeName<D>>(input: AtomicUpdateInput<D, W, T>): AtomicUpdateHandle<T>;
1063
- delete(ref: AtomicRef): AtomicDeleteHandle;
1237
+ create<T extends TypeName<D>>(input: AtomicCreateInput<D, W, T>, ...opts: AtomicOperationArgs<D, T, 'create'>): AtomicCreateHandle<T>;
1238
+ update<T extends TypeName<D>>(input: AtomicUpdateInput<D, W, T>, ...opts: AtomicOperationArgs<D, T, 'update'>): AtomicUpdateHandle<T>;
1239
+ delete<T extends TypeName<D>>(ref: AtomicRef & {
1240
+ type: T;
1241
+ }, ...opts: AtomicOperationArgs<D, T, 'delete'>): AtomicDeleteHandle;
1242
+ /**
1243
+ * Relation `relationship` of the resource `ref` names, by its server `id` or the `lid` of a
1244
+ * resource created earlier in the batch. Its verbs record operations on the relationship. Only
1245
+ * a relation that takes at least one verb is accepted.
1246
+ */
1247
+ rel<T extends TypeName<D>, R extends WritableRelationName<D, T>>(ref: AtomicRef & {
1248
+ type: T;
1249
+ }, relationship: R): AtomicRelationshipRecorder<D, T, R>;
1064
1250
  }
1065
1251
  /** One positional result of an atomic batch: the materialised `data` (a resource/`null`) plus any op `meta`. */
1066
1252
  interface AtomicResult<Data = unknown> {
@@ -1157,15 +1343,21 @@ interface EdgeMembers<Pivot = Record<string, unknown>, Meta extends Record<strin
1157
1343
  /**
1158
1344
  * The resource-level `$`-accessors on a materialised resource object. `Links` types `$links`: the
1159
1345
  * type's generated links interface when its resources declare links, else the loose
1160
- * {@link ResourceLinks}.
1346
+ * {@link ResourceLinks}. `Meta` types `$meta`, the resource object's own `meta`: the members its
1347
+ * type declares, else the loose record.
1161
1348
  */
1162
- interface ResourceAccessors<Links = ResourceLinks> {
1163
- readonly $meta: Record<string, unknown> | undefined;
1349
+ interface ResourceAccessors<Links = ResourceLinks, Meta = Record<string, unknown> | undefined> {
1350
+ readonly $meta: Meta;
1164
1351
  readonly $links: Links | undefined;
1165
1352
  /** The `self` link's href, whether the wire carried a bare URL or a link object. */
1166
1353
  readonly $self: string | undefined;
1167
1354
  readonly $document: DocumentEnvelope;
1168
1355
  readonly $raw: Record<string, unknown>;
1356
+ /**
1357
+ * The keys the request's sparse fieldset selected of each attribute it narrowed, under the Nested
1358
+ * Fieldsets profile. Empty when the request narrowed no attribute of this type.
1359
+ */
1360
+ readonly $nestedFieldset: NestedFieldset;
1169
1361
  $rel(name: string): RelationView | undefined;
1170
1362
  }
1171
1363
  /** Every wire type declared by the descriptor `D`. */
@@ -1219,6 +1411,44 @@ type SelectedFields<F, T extends string> = F extends FieldSelectionMap ? T exten
1219
1411
  * object's keys are exactly the requested members — the static mirror of a sparse fieldset.
1220
1412
  */
1221
1413
  type PickSelected<Obj, Sel> = [Sel] extends [AllFields] ? Obj : Pick<Obj, Extract<keyof Obj, Sel>>;
1414
+ /** The attribute a nested fieldset member names: `values` for `values.cap`. */
1415
+ type NestedFieldsetAttribute<Sel> = Sel extends `${infer Attribute}.${string}` ? Attribute : never;
1416
+ /** The paths of attribute `Attr` the nested fieldset members in `Sel` select: everything after the first dot. */
1417
+ type SelectedKeysOf<Sel, Attr extends string> = Sel extends `${Attr}.${infer Key}` ? Key : never;
1418
+ /** The first key of each path in `K`: `geo` for `geo.lat`, `*` for `*.sku`. */
1419
+ type PathHead<K extends string> = K extends `${infer Head}.${string}` ? Head : K;
1420
+ /** What the paths in `K` select inside key `Head`: `lat` for `geo.lat`. */
1421
+ type PathTail<K extends string, Head extends string> = K extends `${Head}.${infer Tail}` ? Tail : never;
1422
+ /** Whether `T` is a union of more than one member. */
1423
+ type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
1424
+ /** The keys of `V` whose value is one string literal, such as a union variant's discriminator. */
1425
+ type LiteralStringKey<V> = { [P in keyof V]-?: V[P] extends string ? (string extends V[P] ? never : P) : never }[keyof V];
1426
+ /**
1427
+ * The key every member of the union `U` holds as one string literal, which names its variant, or
1428
+ * `never` when `U` is not a union.
1429
+ */
1430
+ type DiscriminatorKey<U> = true extends IsUnion<U> ? Exclude<keyof U, U extends unknown ? Exclude<keyof U, LiteralStringKey<U>> : never> : never;
1431
+ /** One object type for an intersection, each key keeping whether it is optional. */
1432
+ type Flatten<T> = { [P in keyof T]: T[P] };
1433
+ /**
1434
+ * An attribute value narrowed to the paths `K`, each key optional, since a value without a selected
1435
+ * key leaves it out. A path into a nested object (`geo.lat`) narrows that object the same way,
1436
+ * unless `K` also lists its key whole. A list narrowed through `*` (`*.sku`) keeps every item, each
1437
+ * narrowed to the rest of the path, unless `K` also lists `*` whole. A value that is one of several
1438
+ * variants, as an attribute, a nested key or a list's item, narrows each variant on its own and
1439
+ * keeps the key naming it. `null` stays as it is, and a key type the client can't list keeps every
1440
+ * key.
1441
+ */
1442
+ type KeySelected<V, K extends string> = KeySelectedAs<V, K, DiscriminatorKey<Exclude<V, null | undefined | readonly unknown[]>>>;
1443
+ /** {@link KeySelected}, given the key `D` naming the variant of a union value. */
1444
+ type KeySelectedAs<V, K extends string, D> = V extends readonly (infer Item)[] ? string extends K ? Partial<Item>[] : '*' extends K ? V : KeySelected<Item, PathTail<K, '*'>>[] : V extends object ? string extends K ? Partial<V> : [D] extends [never] ? NarrowedObject<V, K> : Flatten<NarrowedObject<V, K> & Pick<V, Extract<D, keyof V>>> : V;
1445
+ /** The keys of the object `V` the paths `K` select, each optional and narrowed in turn. */
1446
+ type NarrowedObject<V, K extends string> = { [P in Extract<PathHead<K>, keyof V>]?: P extends K ? V[P] : KeySelected<V[P], PathTail<K, P>> };
1447
+ /**
1448
+ * {@link PickSelected} for attributes: an attribute the selection names only through nested fieldset members
1449
+ * (`values.cap`) is present and narrowed to those keys, while one it lists whole stays whole.
1450
+ */
1451
+ type PickSelectedAttributes<Obj, Sel> = [Sel] extends [AllFields] ? Obj : Pick<Obj, Extract<keyof Obj, Sel>> & { [K in keyof Obj as K extends Exclude<NestedFieldsetAttribute<Sel>, Sel> ? K : never]: KeySelected<Obj[K], SelectedKeysOf<Sel, K & string>> };
1222
1452
  /**
1223
1453
  * The related wire type(s) of relation `R` on type `T`. A union when polymorphic; the
1224
1454
  * member is narrowed to types that actually exist in the descriptor so the hydrated
@@ -1302,7 +1532,7 @@ interface CountAccessor<D extends ApiDescriptor, T extends TypeName<D>, Counted
1302
1532
  type ResourceObjectView<D extends ApiDescriptor, A, T extends TypeName<D>, Inc = never, F = unknown, Counted = never> = {
1303
1533
  type: T;
1304
1534
  id: string;
1305
- } & PickSelected<AttributesOf<A, T>, SelectedFields<F, T>> & Relations<D, A, T, Inc, F> & ResourceAccessors<LinksOf<A, T>> & CountAccessor<D, T, Counted>;
1535
+ } & PickSelectedAttributes<AttributesOf<A, T>, SelectedFields<F, T>> & Relations<D, A, T, Inc, F> & ResourceAccessors<LinksOf<A, T>, ResourceMetaOf<D, T>> & CountAccessor<D, T, Counted>;
1306
1536
  /**
1307
1537
  * The element type of the `include` array for type `T`: a path from the descriptor's
1308
1538
  * `includable` enum — the exact set the server advertises, including nested dotted paths
@@ -1501,7 +1731,15 @@ type FieldsMap<D extends ApiDescriptor> = { [T in TypeName<D>]?: readonly Member
1501
1731
  * `attributes` keys) or a relation a response renders. The descriptor carries the literal member
1502
1732
  * names, so `fields` entries are constrained to real members.
1503
1733
  */
1504
- type MemberName<D extends ApiDescriptor, T extends TypeName<D>> = Extract<keyof D[T]['attributes'], string> | ReadableRelationName<D, T>;
1734
+ type MemberName<D extends ApiDescriptor, T extends TypeName<D>> = Extract<keyof D[T]['attributes'], string> | ReadableRelationName<D, T> | NestedFieldsetMember<D, T>;
1735
+ /**
1736
+ * A nested fieldset member of type `T`: `<attribute>.${string}` for each attribute whose single keys a sparse
1737
+ * fieldset may select (the descriptor's `nestedFieldsets`), under the Nested Fieldsets profile.
1738
+ * `never` when the type declares none.
1739
+ */
1740
+ type NestedFieldsetMember<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
1741
+ nestedFieldsets: infer S;
1742
+ } ? `${Extract<keyof S, string>}.${string}` : never;
1505
1743
  /**
1506
1744
  * The `relatedQuery` entry for relation `R` of type `T`: its `filter` and `sort` typed as the
1507
1745
  * relation's own related read types them (see {@link RelationFilterQuery} and
@@ -1663,18 +1901,54 @@ type RequiredPivotField<P> = P extends {
1663
1901
  } ? P extends {
1664
1902
  required: infer Req;
1665
1903
  } ? Extract<keyof Fl, ListMember<Req>> : keyof Fl : never;
1666
- /** One pivot field's TS type: its format hint's type, plus `null` when the field is nullable. */
1904
+ /**
1905
+ * One pivot field's TS type: one of the literals its `values` lists, else its format hint's type,
1906
+ * plus `null` when the field is nullable.
1907
+ */
1667
1908
  type PivotValue<P, K> = P extends {
1668
1909
  fields: infer Fl;
1669
- } ? K extends keyof Fl ? FormatToTs<Fl[K]> | (K extends ListMember<P extends {
1910
+ } ? K extends keyof Fl ? (P extends {
1911
+ values: infer V;
1912
+ } ? K extends keyof V ? ListedValue<V[K], Fl[K]> : FormatToTs<Fl[K]> : FormatToTs<Fl[K]>) | (K extends ListMember<P extends {
1670
1913
  nullable: infer N;
1671
1914
  } ? N : never> ? null : never) : never : never;
1915
+ /**
1916
+ * The literals a `values` entry lists, or hint `H`'s type when the entry lists none. A list, hinted
1917
+ * `array`, lists the values of its items, so it is a list of those literals.
1918
+ */
1919
+ type ListedValue<L, H> = L extends readonly (infer M)[] ? [M] extends [never] ? FormatToTs<H> : H extends 'array' ? readonly M[] : M : FormatToTs<H>;
1672
1920
  /** The fields of a {@link PivotDescriptor}. */
1673
1921
  type PivotFieldNames<P> = P extends {
1674
1922
  fields: infer Fl;
1675
1923
  } ? keyof Fl : never;
1676
1924
  /** The `meta.pivot` object a {@link PivotDescriptor} describes. */
1677
1925
  type PivotObject<P> = { readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? K : never]: PivotValue<P, K> } & { readonly [K in PivotFieldNames<P> as K extends RequiredPivotField<P> ? never : K]?: PivotValue<P, K> };
1926
+ /** The value an open {@link PivotDescriptor} takes for each member beside its fields. */
1927
+ type AdditionalValue<P> = P extends {
1928
+ additional: infer X;
1929
+ } ? X extends {
1930
+ format: infer H;
1931
+ } ? (X extends {
1932
+ values: infer L;
1933
+ } ? ListedValue<L, H> : FormatToTs<H>) | (X extends {
1934
+ nullable: true;
1935
+ } ? null : never) : never : never;
1936
+ /** The value of any declared field of a {@link PivotDescriptor}. */
1937
+ type DeclaredValue<P> = P extends {
1938
+ fields: infer Fl;
1939
+ } ? { [K in keyof Fl]: PivotValue<P, K> }[keyof Fl] : never;
1940
+ /**
1941
+ * The undeclared members an open {@link PivotDescriptor} takes, as an index signature whose value
1942
+ * also admits each declared field's and `Extra`, the other members the object carries, so the
1943
+ * declared ones keep their types. `unknown`, adding nothing, for a closed object.
1944
+ */
1945
+ type AdditionalMembers<P, Extra = never> = P extends {
1946
+ additional: {
1947
+ format: unknown;
1948
+ };
1949
+ } ? {
1950
+ readonly [member: string]: AdditionalValue<P> | DeclaredValue<P> | Extra | undefined;
1951
+ } : unknown;
1678
1952
  /** The legacy hint-only pivot shape: every field present and non-null. */
1679
1953
  type LegacyPivot<P> = { readonly [K in keyof P]: FormatToTs<P[K]> };
1680
1954
  /**
@@ -1685,17 +1959,29 @@ type LegacyPivot<P> = { readonly [K in keyof P]: FormatToTs<P[K]> };
1685
1959
  */
1686
1960
  type PivotFieldsOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
1687
1961
  readPivot: infer P;
1688
- } ? PivotObject<P> : D[T]['relations'][R] extends {
1962
+ } ? PivotObject<P> & AdditionalMembers<P> : D[T]['relations'][R] extends {
1689
1963
  pivotFields: infer P;
1690
1964
  } ? LegacyPivot<P> : Record<string, unknown>;
1691
1965
  /**
1692
1966
  * The `$edge.meta` of each linkage member of relation `R`: the members the descriptor's
1693
- * `identifierMeta` declares, typed like a pivot, over an open record that still carries
1694
- * `pivot` and any other meta. A relation declaring none keeps the open record.
1967
+ * `identifierMeta` declares, typed like a pivot, with the relation's `pivot` beside them. An
1968
+ * identifier meta that says whether it is open takes only those, and the undeclared members it
1969
+ * opens to; one that doesn't say is an open record. A relation declaring none keeps the open
1970
+ * record.
1695
1971
  */
1696
1972
  type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
1697
1973
  identifierMeta: infer P;
1698
- } ? PivotObject<P> & Record<string, unknown> : Record<string, unknown>;
1974
+ } ? P extends {
1975
+ additional: false | {
1976
+ format: unknown;
1977
+ };
1978
+ } ? PivotObject<P> & EdgePivot<D, T, R> & AdditionalMembers<P, PivotFieldsOf<D, T, R>> : PivotObject<P> & Record<string, unknown> : Record<string, unknown>;
1979
+ /** The `pivot` a pivot relation's identifier meta carries beside its declared members. */
1980
+ type EdgePivot<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
1981
+ pivot: true;
1982
+ } ? {
1983
+ readonly pivot?: PivotFieldsOf<D, T, R>;
1984
+ } : unknown;
1699
1985
  /**
1700
1986
  * The typed `meta.pivot` a request may send on each member of relation `R`, from the descriptor's
1701
1987
  * `writePivot` (only writable fields, optional unless required). Falls back like
@@ -1703,7 +1989,7 @@ type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends Relati
1703
1989
  */
1704
1990
  type WritePivotOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
1705
1991
  writePivot: infer P;
1706
- } ? PivotObject<P> : D[T]['relations'][R] extends {
1992
+ } ? PivotObject<P> & AdditionalMembers<P> : D[T]['relations'][R] extends {
1707
1993
  pivotFields: infer P;
1708
1994
  } ? LegacyPivot<P> : PivotInput;
1709
1995
  /** Whether a {@link DocumentMetaDescriptor} requires a member, so its document always carries `meta`. */
@@ -1715,6 +2001,20 @@ type RequiresMeta<P> = [RequiredPivotField<P>] extends [never] ? false : true;
1715
2001
  type DeclaredMetaObject<P> = P extends {
1716
2002
  fields: infer Fl;
1717
2003
  } ? { readonly [K in keyof Fl as K extends RequiredPivotField<P> ? K : never]: PivotValue<P, K> } & { readonly [K in keyof Fl as K extends RequiredPivotField<P> ? never : K]?: PivotValue<P, K> } : never;
2004
+ /**
2005
+ * A declared `meta` object: the members a {@link PivotDescriptor} declares, each required one
2006
+ * present, and the undeclared members it takes when the server opens it. A closed object takes no
2007
+ * other member.
2008
+ */
2009
+ type MetaObject<P> = P extends {
2010
+ fields: infer Fl;
2011
+ } ? [keyof Fl] extends [never] ? P extends {
2012
+ additional: {
2013
+ format: unknown;
2014
+ };
2015
+ } ? AdditionalMembers<P> : {
2016
+ readonly [member: string]: never;
2017
+ } : DeclaredMetaObject<P> & AdditionalMembers<P> : never;
1718
2018
  /**
1719
2019
  * The top-level `meta` a {@link DocumentMetaDescriptor} types: its members, or `undefined` when
1720
2020
  * none is required, since the document may then carry no `meta`. A collection's also has the
@@ -1723,7 +2023,78 @@ type DeclaredMetaObject<P> = P extends {
1723
2023
  */
1724
2024
  type DocumentMeta<P> = P extends {
1725
2025
  fields: object;
1726
- } ? RequiresMeta<P> extends true ? DeclaredMetaObject<P> : DeclaredMetaObject<P> | undefined : Record<string, unknown> | undefined;
2026
+ } ? RequiresMeta<P> extends true ? MetaObject<P> : MetaObject<P> | undefined : Record<string, unknown> | undefined;
2027
+ /**
2028
+ * The `meta` of type `T`'s resource objects, as `$meta` reads it: the members its `resourceMeta`
2029
+ * declares for a read, else the loose record. A resource object may carry no `meta`.
2030
+ */
2031
+ type ResourceMetaOf<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
2032
+ resourceMeta: {
2033
+ read: infer P;
2034
+ };
2035
+ } ? MetaObject<P> | undefined : Record<string, unknown> | undefined;
2036
+ /** A write's `data.meta`, by where it is sent: a create or an update, alone or in an atomic batch. */
2037
+ type ResourceWriteOperation = 'create' | 'update' | 'atomicCreate' | 'atomicUpdate';
2038
+ /** The write a {@link ResourceWriteOperation} inside an atomic batch takes its `data.meta` from otherwise. */
2039
+ type StandaloneWrite<Op extends ResourceWriteOperation> = Op extends 'atomicCreate' ? 'create' : Op extends 'atomicUpdate' ? 'update' : Op;
2040
+ /**
2041
+ * The `$meta` a write input of type `T` takes, sent as `data.meta`: the members its
2042
+ * `resourceMeta` declares for `Op`, an atomic one falling back to its standalone write's, else the
2043
+ * loose record a type declaring none takes.
2044
+ */
2045
+ type ResourceWriteMeta<D extends ApiDescriptor, T extends TypeName<D>, Op extends ResourceWriteOperation> = D[T] extends {
2046
+ resourceMeta: infer M;
2047
+ } ? Op extends keyof M ? MetaObject<M[Op]> : StandaloneWrite<Op> extends keyof M ? MetaObject<M[StandaloneWrite<Op>]> : Record<string, unknown> : Record<string, unknown>;
2048
+ /**
2049
+ * The top-level `meta` write `Op` of type `T` takes: the members its `requestMeta` declares, or,
2050
+ * with `Atomic`, its `atomicRequestMeta`'s. `never` when it declares none.
2051
+ */
2052
+ type RequestMetaOf<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation, Atomic extends boolean = false> = D[T] extends { [K in Atomic extends true ? 'atomicRequestMeta' : 'requestMeta']: infer M } ? Op extends keyof M ? M[Op] extends {
2053
+ fields: object;
2054
+ } ? MetaObject<M[Op]> : never : never : never;
2055
+ /**
2056
+ * The `meta` option of a write whose request document declares `M`: required when `M` has a
2057
+ * required member, else optional. A write declaring none takes the open record, as its document
2058
+ * may carry any `meta`.
2059
+ */
2060
+ type MetaOption<M> = [M] extends [never] ? {
2061
+ meta?: Record<string, unknown>;
2062
+ } : RequiresRequestMeta<M> extends true ? {
2063
+ meta: M;
2064
+ } : {
2065
+ meta?: M;
2066
+ };
2067
+ /** Whether a declared request `meta` has a required member, so a call must send it. */
2068
+ type RequiresRequestMeta<M> = [M] extends [never] ? false : [RequiredKeysOf<M>] extends [never] ? false : true;
2069
+ /** The keys of an object type whose members are required. */
2070
+ type RequiredKeysOf<M> = { [K in keyof M]-?: string extends K ? never : {} extends Pick<M, K> ? never : K }[keyof M];
2071
+ /** The options argument of a call taking options `O`: required when `Req` is `true`, else optional. */
2072
+ type OptionsArg<Req, O> = Req extends true ? [opts: O] : [opts?: O];
2073
+ /** The `meta` option of write `Op` on type `T`, as {@link MetaOption} types it. */
2074
+ type WriteMetaOption<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation> = MetaOption<RequestMetaOf<D, T, Op>>;
2075
+ /** Whether write `Op` on type `T` must send its `meta`. */
2076
+ type RequiresWriteMeta<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation> = RequiresRequestMeta<RequestMetaOf<D, T, Op>>;
2077
+ /**
2078
+ * The arguments of type `T`'s delete: none when it declares no request `meta`, since it then takes
2079
+ * no body, else an options object carrying it, required when a member is.
2080
+ */
2081
+ type DeleteArgs<D extends ApiDescriptor, T extends TypeName<D>> = [RequestMetaOf<D, T, 'delete'>] extends [never] ? [] : OptionsArg<RequiresWriteMeta<D, T, 'delete'>, WriteMetaOption<D, T, 'delete'>>;
2082
+ /**
2083
+ * The top-level `meta` of the meta-only `200` relation `R`'s write with verb `V` answers with, or
2084
+ * `never` when it answers with the linkage.
2085
+ */
2086
+ type MutationMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends keyof RelationMutations> = D[T]['relations'][R] extends {
2087
+ mutationMeta: infer M;
2088
+ } ? V extends keyof M ? M[V] extends {
2089
+ fields: object;
2090
+ } ? DocumentMeta<M[V]> : never : never : never;
2091
+ /**
2092
+ * The top-level `meta` relation `R`'s write with verb `V` takes, or, with `Atomic`, the operation's
2093
+ * inside an atomic batch. `never` when it declares none.
2094
+ */
2095
+ type RelationRequestMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends keyof RelationMutations, Atomic extends boolean = false> = D[T]['relations'][R] extends { [K in Atomic extends true ? 'atomicRequestMeta' : 'requestMeta']: infer M } ? V extends keyof M ? M[V] extends {
2096
+ fields: object;
2097
+ } ? MetaObject<M[V]> : never : never : never;
1727
2098
  /**
1728
2099
  * The typed top-level `meta` of operation `Op` on type `T` (`fetchMany`, `fetchOne`, `create`,
1729
2100
  * `update` or `delete`), or `never` when its document declares none.
@@ -1803,6 +2174,23 @@ interface RelationshipAccessor<D extends ApiDescriptor, A, T extends TypeName<D>
1803
2174
  replace: RelationMutation<D, T, R, 'replace', readonly WriteRef<D, T, R>[]>;
1804
2175
  set: RelationMutation<D, T, R, 'set', LinkageRefOf<RelatedType<D, T, R>> | null>;
1805
2176
  }
2177
+ /**
2178
+ * True when relation `R` of type `T` takes verb `V`: it has the verb's cardinality, a to-one for
2179
+ * `set` and a to-many for the rest, and advertises the verb in its `mutations` flags, as the
2180
+ * relationship accessor gates it (see {@link AdvertisesVerb}).
2181
+ */
2182
+ type TakesVerb<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = D[T]['relations'][R]['cardinality'] extends VerbCardinality<V> ? AdvertisesVerb<D, T, R, V> : false;
2183
+ /**
2184
+ * The relations of type `T` that take at least one verb (see {@link TakesVerb}), the names
2185
+ * {@link AtomicRecorder.rel} accepts.
2186
+ */
2187
+ type WritableRelationName<D extends ApiDescriptor, T extends TypeName<D>> = { [R in RelationName<D, T>]: true extends { [V in MutationVerb]: TakesVerb<D, T, R, V> }[MutationVerb] ? R : never }[RelationName<D, T>];
2188
+ /**
2189
+ * The members a relationship write with verb `V` on relation `R` takes, as the relationship
2190
+ * accessor's verbs take them: refs with an optional `$pivot` to add or replace, refs to remove, and
2191
+ * one ref or `null` to set.
2192
+ */
2193
+ type RelationshipMembers<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = V extends 'set' ? LinkageRefOf<RelatedType<D, T, R>> | null : V extends 'remove' ? readonly LinkageRefOf<RelatedType<D, T, R>>[] : readonly WriteRef<D, T, R>[];
1806
2194
  /**
1807
2195
  * A linkage ref for a to-many membership WRITE on relation `R` (`add`/`replace`, or a create or
1808
2196
  * update input), with `$pivot` typed from the relation's `writePivot` — so a `belongsToMany` add
@@ -1854,7 +2242,12 @@ type AdvertisesVerb<D extends ApiDescriptor, T extends TypeName<D>, R extends Re
1854
2242
  * — or a verb the relation forbids (e.g. a to-many lacking `replace`) — is a compile error.
1855
2243
  * The result is the materialised linkage value or `void` (a `204` response).
1856
2244
  */
1857
- type RelationMutation<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb, Refs> = D[T]['relations'][R]['cardinality'] extends VerbCardinality<V> ? AdvertisesVerb<D, T, R, V> extends true ? (refs: Refs) => Promise<LinkageValue<D, T, R> | void> : never : never;
2245
+ type RelationMutation<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb, Refs> = D[T]['relations'][R]['cardinality'] extends VerbCardinality<V> ? AdvertisesVerb<D, T, R, V> extends true ? (refs: Refs, ...opts: OptionsArg<RequiresRequestMeta<RelationRequestMetaOf<D, T, R, V>>, MetaOption<RelationRequestMetaOf<D, T, R, V>>>) => Promise<MutationResult<D, T, R, V>> : never : never;
2246
+ /**
2247
+ * What relation `R`'s write with verb `V` resolves to: the `meta` of the meta-only `200` it
2248
+ * declares, else the materialised linkage, or `void` for a `204`.
2249
+ */
2250
+ type MutationResult<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends MutationVerb> = [MutationMetaOf<D, T, R, V>] extends [never] ? LinkageValue<D, T, R> | void : NonNullable<MutationMetaOf<D, T, R, V>>;
1858
2251
  /** The relationship accessors of type `T`, keyed by relation name. */
1859
2252
  type RelationshipAccessors<D extends ApiDescriptor, A, T extends TypeName<D>> = { -readonly [R in keyof D[T]['relations'] as Extract<R, string>]: RelationshipAccessor<D, A, T, Extract<R, string>> };
1860
2253
  /**
@@ -1919,12 +2312,16 @@ type CreateId<D extends ApiDescriptor, T extends TypeName<D>> = D[T]['clientId']
1919
2312
  * slots, plus an `id` keyed by the client-id policy. The runtime builds the JSON:API
1920
2313
  * envelope (routing keys to attributes/relationships via the descriptor).
1921
2314
  */
1922
- type CreateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = CreateAttributesOf<W, T> & RelationInputs<D, T> & CreateId<D, T>;
2315
+ type CreateInput<D extends ApiDescriptor, W, T extends TypeName<D>, Op extends 'create' | 'atomicCreate' = 'create'> = CreateAttributesOf<W, T> & RelationInputs<D, T> & CreateId<D, T> & {
2316
+ /** The resource object's `meta`, sent as `data.meta`. */$meta?: ResourceWriteMeta<D, T, Op>;
2317
+ };
1923
2318
  /**
1924
2319
  * The flat input to `client.<type>.id(id).update(patch)`: the type's update attributes (all
1925
2320
  * optional) + relation slots. The id rides the handle, never the input.
1926
2321
  */
1927
- type UpdateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = UpdateAttributesOf<W, T> & RelationInputs<D, T>;
2322
+ type UpdateInput<D extends ApiDescriptor, W, T extends TypeName<D>, Op extends 'update' | 'atomicUpdate' = 'update'> = UpdateAttributesOf<W, T> & RelationInputs<D, T> & {
2323
+ /** The resource object's `meta`, sent as `data.meta`. */$meta?: ResourceWriteMeta<D, T, Op>;
2324
+ };
1928
2325
  /**
1929
2326
  * The flat input to a singleton's `client.<type>.update(input)`: the {@link UpdateInput} plus the
1930
2327
  * resource's `id`, which the request body must carry although the path has none. Take it from the
@@ -1967,12 +2364,18 @@ type AcceptedOf<D extends ApiDescriptor, T extends TypeName<D>, Op extends Accep
1967
2364
  type AcceptedJob<D extends ApiDescriptor, A, J> = J extends {
1968
2365
  jobType: infer JT extends string;
1969
2366
  } ? JT extends TypeName<D> ? ReadResult<D, A, JT> : Readonly<Record<string, unknown>> : never;
2367
+ /** The top-level `meta` of the job document an accepted write's `202` declares, else the loose record. */
2368
+ type AcceptedMeta<J> = J extends {
2369
+ meta: infer P extends {
2370
+ fields: object;
2371
+ };
2372
+ } ? DocumentMeta<P> : Record<string, unknown> | undefined;
1970
2373
  /**
1971
2374
  * What write `Op` on type `T` resolves to without waiting: its result `R`, or, when it declares a
1972
2375
  * `202`, `R` or an {@link Accepted} job whose poll resolves to the resource without the write's
1973
2376
  * `include` or `fields`.
1974
2377
  */
1975
- type WriteResult<D extends ApiDescriptor, A, T extends TypeName<D>, Op extends AcceptedOperation, R> = [AcceptedOf<D, T, Op>] extends [never] ? R : R | Accepted<AcceptedJob<D, A, AcceptedOf<D, T, Op>>, ReadResult<D, A, T>>;
2378
+ type WriteResult<D extends ApiDescriptor, A, T extends TypeName<D>, Op extends AcceptedOperation, R> = [AcceptedOf<D, T, Op>] extends [never] ? R : R | Accepted<AcceptedJob<D, A, AcceptedOf<D, T, Op>>, ReadResult<D, A, T>, AcceptedMeta<AcceptedOf<D, T, Op>>>;
1976
2379
  /**
1977
2380
  * The `wait` a caller may pass to write `Op` on type `T`: a boolean or {@link PollOptions} when it
1978
2381
  * declares a `202`, else nothing.
@@ -1988,21 +2391,21 @@ type WaitedWriteResult<D extends ApiDescriptor, A, T extends TypeName<D>, Op ext
1988
2391
  * accepted job and resolves to the created resource; without it the call may resolve to an
1989
2392
  * {@link Accepted}.
1990
2393
  */
1991
- type CreateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>> = [AcceptedOf<D, T, 'create'>] extends [never] ? <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'create'>[] = []>(input: CreateInput<D, W, T>, opts?: WriteOptions<D, T, Inc, F, 'create', Cnt>) => Promise<WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>> : {
1992
- (input: CreateInput<D, W, T>, opts: WaitOptions): Promise<ReadResult<D, A, T>>;
1993
- <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'create'>[] = []>(input: CreateInput<D, W, T>, opts?: WriteOptions<D, T, Inc, F, 'create', Cnt> & {
2394
+ type CreateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>> = [AcceptedOf<D, T, 'create'>] extends [never] ? <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'create'>[] = []>(input: CreateInput<D, W, T>, ...opts: OptionsArg<RequiresWriteMeta<D, T, 'create'>, WriteOptions<D, T, Inc, F, 'create', Cnt> & WriteMetaOption<D, T, 'create'>>) => Promise<WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>> : {
2395
+ (input: CreateInput<D, W, T>, opts: WaitOptions & WriteMetaOption<D, T, 'create'>): Promise<ReadResult<D, A, T>>;
2396
+ <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'create'>[] = []>(input: CreateInput<D, W, T>, ...opts: OptionsArg<RequiresWriteMeta<D, T, 'create'>, WriteOptions<D, T, Inc, F, 'create', Cnt> & {
1994
2397
  wait?: false;
1995
- }): Promise<WriteResult<D, A, T, 'create', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>>>;
2398
+ } & WriteMetaOption<D, T, 'create'>>): Promise<WriteResult<D, A, T, 'create', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>>>;
1996
2399
  };
1997
2400
  /**
1998
2401
  * `client.<type>.id(id).update`, which takes `wait` as {@link CreateMethod} does. `I` is the input
1999
2402
  * it takes: a singleton's update takes {@link SingletonUpdateInput}.
2000
2403
  */
2001
- type UpdateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>, I = UpdateInput<D, W, T>> = [AcceptedOf<D, T, 'update'>] extends [never] ? <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'update'>[] = []>(patch: I, opts?: WriteOptions<D, T, Inc, F, 'update', Cnt>) => Promise<WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>> : {
2002
- (patch: I, opts: WaitOptions): Promise<ReadResult<D, A, T>>;
2003
- <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'update'>[] = []>(patch: I, opts?: WriteOptions<D, T, Inc, F, 'update', Cnt> & {
2404
+ type UpdateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>, I = UpdateInput<D, W, T>> = [AcceptedOf<D, T, 'update'>] extends [never] ? <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'update'>[] = []>(patch: I, ...opts: OptionsArg<RequiresWriteMeta<D, T, 'update'>, WriteOptions<D, T, Inc, F, 'update', Cnt> & WriteMetaOption<D, T, 'update'>>) => Promise<WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>> : {
2405
+ (patch: I, opts: WaitOptions & WriteMetaOption<D, T, 'update'>): Promise<ReadResult<D, A, T>>;
2406
+ <const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'update'>[] = []>(patch: I, ...opts: OptionsArg<RequiresWriteMeta<D, T, 'update'>, WriteOptions<D, T, Inc, F, 'update', Cnt> & {
2004
2407
  wait?: false;
2005
- }): Promise<WriteResult<D, A, T, 'update', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>>>;
2408
+ } & WriteMetaOption<D, T, 'update'>>): Promise<WriteResult<D, A, T, 'update', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>>>;
2006
2409
  };
2007
2410
  /**
2008
2411
  * The materialised positional result of a single atomic op handle:
@@ -2011,12 +2414,15 @@ type UpdateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>, I = Upda
2011
2414
  * wrapping the materialised resource view of `T` (the same {@link ResourceObjectView} a
2012
2415
  * standalone create/update read returns — `data` is typed, not `unknown`, plus the optional op
2013
2416
  * `meta`);
2014
- * - an {@link AtomicDeleteHandle} -> `undefined` (a remove carries no data).
2417
+ * - an {@link AtomicDeleteHandle} -> `undefined` (a remove carries no data);
2418
+ * - an {@link AtomicRelationshipHandle} for relation `R` of `T` -> the `AtomicResult` wrapping the
2419
+ * linkage the server answered with, as the relationship accessor's verbs return it, or
2420
+ * `undefined` data when it answered with an empty result.
2015
2421
  *
2016
2422
  * Drives the per-op positional typing of {@link AtomicResults} (the callback's returned tuple of
2017
2423
  * handles maps to a tuple of these).
2018
2424
  */
2019
- type AtomicResultOf<D extends ApiDescriptor, A, Handle> = Handle extends AtomicDeleteHandle ? undefined : Handle extends AtomicCreateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : Handle extends AtomicUpdateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : never;
2425
+ type AtomicResultOf<D extends ApiDescriptor, A, Handle> = Handle extends AtomicDeleteHandle ? undefined : Handle extends AtomicRelationshipHandle<infer T, infer R> ? T extends TypeName<D> ? R extends RelationName<D, T> ? AtomicResult<LinkageValue<D, T, R> | undefined> : never : never : Handle extends AtomicCreateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : Handle extends AtomicUpdateHandle<infer T> ? T extends TypeName<D> ? AtomicResult<ResourceObjectView<D, A, T>> : never : never;
2020
2426
  /** The custom actions declared on type `T` (the descriptor's `actions` block, or `{}`). */
2021
2427
  type ActionsOf<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
2022
2428
  actions: infer Acts;
@@ -2065,7 +2471,7 @@ type ActionValue<D extends ApiDescriptor, A, Act extends ActionDescriptor, E> =
2065
2471
  /** The {@link Accepted} job of an action that declares a `202`, or `never`. */
2066
2472
  type ActionAccepted<D extends ApiDescriptor, A, Act extends ActionDescriptor, E> = Act extends {
2067
2473
  accepted: object;
2068
- } ? Accepted<AcceptedJob<D, A, Act['accepted']>, ActionValue<D, A, Act, E>> : never;
2474
+ } ? Accepted<AcceptedJob<D, A, Act['accepted']>, ActionValue<D, A, Act, E>, AcceptedMeta<Act['accepted']>> : never;
2069
2475
  /** The `wait` option of an action that declares a `202`; `unknown` (adding nothing) otherwise. */
2070
2476
  type ActionWaitOption<Act> = Act extends {
2071
2477
  accepted: object;
@@ -2142,6 +2548,8 @@ interface ActionCallOptions {
2142
2548
  relatedQuery?: LooseRelatedQuery;
2143
2549
  /** Poll a `202 Accepted` job until it's done, for an action that declares one. */
2144
2550
  wait?: boolean | PollOptions;
2551
+ /** The request document's top-level `meta`, for an action whose request declares it. */
2552
+ meta?: Readonly<Record<string, unknown>>;
2145
2553
  }
2146
2554
  /** A filter key a collection action accepts (its `filterable` literal union), or `never`. */
2147
2555
  type ActionFilterKey<Act> = Act extends {
@@ -2271,18 +2679,18 @@ type WithInput<D extends ApiDescriptor, W, Act, E> = Act extends {
2271
2679
  */
2272
2680
  type ActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescriptor, E> = Act extends {
2273
2681
  inputMedia: readonly InputMedia[];
2274
- } ? <const C extends ContentTypeOf<Act> = Extract<DefaultContentType<Act>, ContentTypeOf<Act>>, const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(input: InputBodyFor<D, W, Act, E, C>, options?: {
2682
+ } ? <const C extends ContentTypeOf<Act> = Extract<DefaultContentType<Act>, ContentTypeOf<Act>>, const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(input: InputBodyFor<D, W, Act, E, C>, ...options: ActionOptionsArg<Act, {
2275
2683
  signal?: AbortSignal;
2276
2684
  contentType?: C;
2277
- } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
2685
+ } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
2278
2686
  rawOutput: readonly RawOutputMedia[];
2279
2687
  } ? Act extends {
2280
2688
  input: 'none';
2281
- } ? <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(options?: {
2689
+ } ? <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(...options: ActionOptionsArg<Act, {
2282
2690
  signal?: AbortSignal;
2283
- } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>) => ActionResultIn<D, A, Act, E, M, RT> : <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(input: WithInput<D, W, Act, E>, options?: {
2691
+ } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>>) => ActionResultIn<D, A, Act, E, M, RT> : <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(input: WithInput<D, W, Act, E>, ...options: ActionOptionsArg<Act, {
2284
2692
  signal?: AbortSignal;
2285
- } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
2693
+ } & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
2286
2694
  accepted: object;
2287
2695
  } ? AcceptedActionMethod<D, A, W, Act, E> : Act extends {
2288
2696
  filterable: readonly string[];
@@ -2290,13 +2698,15 @@ type ActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescriptor, E
2290
2698
  filterFamilies: readonly unknown[];
2291
2699
  } | {
2292
2700
  relatedQuery: true;
2701
+ } | {
2702
+ requestMeta: object;
2293
2703
  } ? Act extends {
2294
2704
  input: 'none';
2295
- } ? (options?: {
2705
+ } ? (...options: ActionOptionsArg<Act, {
2296
2706
  signal?: AbortSignal;
2297
- } & ActionQueryOptions<D, Act>) => ActionResult<D, A, Act, E> : (input: WithInput<D, W, Act, E>, options?: {
2707
+ } & ActionQueryOptions<D, Act>>) => ActionResult<D, A, Act, E> : (input: WithInput<D, W, Act, E>, ...options: ActionOptionsArg<Act, {
2298
2708
  signal?: AbortSignal;
2299
- } & ActionQueryOptions<D, Act>) => ActionResult<D, A, Act, E> : Act extends {
2709
+ } & ActionQueryOptions<D, Act>>) => ActionResult<D, A, Act, E> : Act extends {
2300
2710
  input: 'none';
2301
2711
  } ? () => ActionResult<D, A, Act, E> : (input: WithInput<D, W, Act, E>) => ActionResult<D, A, Act, E>;
2302
2712
  /**
@@ -2308,20 +2718,33 @@ type AcceptedActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescr
2308
2718
  } ? {
2309
2719
  (options: {
2310
2720
  signal?: AbortSignal;
2311
- } & ActionQueryOptions<D, Act> & WaitOptions): Promise<ActionValue<D, A, Act, E>>;
2312
- (options?: {
2721
+ } & ActionQueryOptions<D, Act> & WaitOptions & ActionMetaOption<Act>): Promise<ActionValue<D, A, Act, E>>;
2722
+ (...options: ActionOptionsArg<Act, {
2313
2723
  signal?: AbortSignal;
2314
2724
  wait?: false;
2315
- } & ActionQueryOptions<D, Act>): ActionResult<D, A, Act, E>;
2725
+ } & ActionQueryOptions<D, Act>>): ActionResult<D, A, Act, E>;
2316
2726
  } : {
2317
2727
  (input: WithInput<D, W, Act, E>, options: {
2318
2728
  signal?: AbortSignal;
2319
- } & ActionQueryOptions<D, Act> & WaitOptions): Promise<ActionValue<D, A, Act, E>>;
2320
- (input: WithInput<D, W, Act, E>, options?: {
2729
+ } & ActionQueryOptions<D, Act> & WaitOptions & ActionMetaOption<Act>): Promise<ActionValue<D, A, Act, E>>;
2730
+ (input: WithInput<D, W, Act, E>, ...options: ActionOptionsArg<Act, {
2321
2731
  signal?: AbortSignal;
2322
2732
  wait?: false;
2323
- } & ActionQueryOptions<D, Act>): ActionResult<D, A, Act, E>;
2733
+ } & ActionQueryOptions<D, Act>>): ActionResult<D, A, Act, E>;
2324
2734
  };
2735
+ /** The top-level `meta` an action's request document declares, or `never`. */
2736
+ type ActionRequestMeta<Act> = Act extends {
2737
+ requestMeta: infer P extends {
2738
+ fields: object;
2739
+ };
2740
+ } ? MetaObject<P> : never;
2741
+ /**
2742
+ * The `meta` option of an action whose request document declares it, required when a member is;
2743
+ * `unknown` (adding nothing) for one that declares none.
2744
+ */
2745
+ type ActionMetaOption<Act> = [ActionRequestMeta<Act>] extends [never] ? unknown : MetaOption<ActionRequestMeta<Act>>;
2746
+ /** An action's options argument: `O` and its `meta`, required when the action must send `meta`. */
2747
+ type ActionOptionsArg<Act, O> = OptionsArg<RequiresRequestMeta<ActionRequestMeta<Act>>, O & ActionMetaOption<Act>>;
2325
2748
  /**
2326
2749
  * The typed map of a type's custom actions at one scope (`collection` on the
2327
2750
  * {@link TypeAccessor}, `resource` on the {@link ResourceHandle}). Each entry is an
@@ -2342,8 +2765,12 @@ type ResourceHandle<D extends ApiDescriptor, A, W, T extends TypeName<D>, Act =
2342
2765
  readonly type: T;
2343
2766
  readonly id: string;
2344
2767
  get<const Inc extends readonly IncludePath<D, T>[] = [], const F extends FieldsMap<D> = {}, const Cnt extends readonly ResourceCountToken<D, T, 'fetchOne'>[] = []>(query?: SingleReadQuery<D, T, Inc, F, Cnt>): Promise<WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'fetchOne'>>>;
2345
- update: UpdateMethod<D, A, W, T>; /** Resolves to the `meta` of the meta-only `200` the delete declares, else `undefined`. */
2346
- delete(): Promise<DeleteResult<D, T>>;
2768
+ update: UpdateMethod<D, A, W, T>;
2769
+ /**
2770
+ * Resolves to the `meta` of the meta-only `200` the delete declares, else `undefined`. A delete
2771
+ * whose request document declares its `meta` takes it in the options.
2772
+ */
2773
+ delete(...opts: DeleteArgs<D, T>): Promise<DeleteResult<D, T>>;
2347
2774
  rel<R extends RelationName<D, T>>(name: R): RelationshipAccessor<D, A, T, R>; /** The type's resource-scoped custom actions, keyed by name (sub `{id}` from this handle). */
2348
2775
  readonly actions: ActionsAccessor<D, A, W, T, 'resource', Act>;
2349
2776
  } & RelationshipAccessors<D, A, T>;
@@ -2680,14 +3107,23 @@ interface WireResource {
2680
3107
  id?: string;
2681
3108
  [key: string]: unknown;
2682
3109
  }
3110
+ /**
3111
+ * What the request a resource answered tells a validator. `fields` is the sparse fieldset the
3112
+ * request sent for the resource's type, `fields[type]`, absent when it sent none.
3113
+ */
3114
+ interface ValidationContext {
3115
+ readonly fields?: readonly string[];
3116
+ }
2683
3117
  /**
2684
3118
  * The opt-in per-resource validator: validate one wire `resource` against its JSON `schema`
2685
3119
  * (the bundle's per-type resource-object schema). The engine is the user's — throw (or
2686
3120
  * aggregate-then-throw) on an invalid resource; return for a valid one. With the bare-function
2687
3121
  * seam form there is no per-type schema, so `schema` is `undefined` and the function owns the
2688
- * whole decision.
3122
+ * whole decision. With the schema-driven form, `schema` is already relaxed for the request's
3123
+ * sparse fieldset (see {@link sparseSchema}). `context` carries that fieldset either way, so a
3124
+ * bare validator can relax its own schema.
2689
3125
  */
2690
- type Validator = (resource: WireResource, schema: unknown) => void;
3126
+ type Validator = (resource: WireResource, schema: unknown, context?: ValidationContext) => void;
2691
3127
  /** A per-type JSON Schema map (the codegen-emitted `schemas` constant), keyed by JSON:API type. */
2692
3128
  type SchemaMap = Readonly<Record<string, unknown>>;
2693
3129
  /**
@@ -2705,9 +3141,12 @@ interface ValidationConfig {
2705
3141
  * `undefined`). Absent => no per-field validation (zero overhead, no engine dependency).
2706
3142
  */
2707
3143
  type ValidationOption = ValidationConfig | Validator;
2708
- /** A normalised validator: resolve a resource's schema (or `undefined`) and validate it. */
3144
+ /**
3145
+ * A normalised validator: resolve a resource's schema (or `undefined`) and validate it. `fields`
3146
+ * is the request's sparse fieldset for the resource's type, when it sent one.
3147
+ */
2709
3148
  interface ResolvedValidator {
2710
- validate(resource: WireResource): void;
3149
+ validate(resource: WireResource, fields?: readonly string[]): void;
2711
3150
  }
2712
3151
  /**
2713
3152
  * Normalise the `validate?` option to a single per-resource validator. The config form looks the
@@ -2716,6 +3155,21 @@ interface ResolvedValidator {
2716
3155
  * delegating the whole decision to the caller. Returns `undefined` when validation is off.
2717
3156
  */
2718
3157
  declare function resolveValidator(option: ValidationOption | undefined): ResolvedValidator | undefined;
3158
+ /**
3159
+ * A cache of {@link sparseSchema} results, by schema and fieldset, so each pair is relaxed once.
3160
+ * A schema with no fieldset comes back as it is.
3161
+ */
3162
+ declare function sparseSchemas(): (schema: unknown, fields: readonly string[] | undefined) => unknown;
3163
+ /**
3164
+ * A resource object schema relaxed for a response to a request whose sparse fieldset for the type
3165
+ * named `members`. An attribute or relation the fieldset leaves out is no longer required, and an
3166
+ * attribute it narrows to some of its keys, such as `address.city`, `location.geo.lat` or
3167
+ * `lines.*.sku`, requires only the keys selected at each level along those paths. A member the
3168
+ * fieldset also lists whole is left as declared, as the server renders it whole. Everything else
3169
+ * in the schema is kept, so a selected value is still checked, but for its `$id`: the copy is a
3170
+ * schema of its own.
3171
+ */
3172
+ declare function sparseSchema(schema: unknown, members: readonly string[]): unknown;
2719
3173
  /**
2720
3174
  * The light structural guards every parsed response passes through (ADR 0004): assert the body
2721
3175
  * is a JSON:API document and that each `data`/`included` member carries a string `type` (and,
@@ -2734,7 +3188,7 @@ declare function assertJsonApiDocument(body: unknown): asserts body is Document;
2734
3188
  * against its per-type schema. Called only when a validator is configured (off by default). The
2735
3189
  * structural guards have already proven each member carries `type`+`id`, so the cast is sound.
2736
3190
  */
2737
- declare function validateDocument(body: Document, validator: ResolvedValidator): void;
3191
+ declare function validateDocument(body: Document, validator: ResolvedValidator, fields?: Readonly<Record<string, readonly string[]>>): void;
2738
3192
  //#endregion
2739
- export { FilterKey as $, PollTimeoutError as $n, WithDocumentMeta as $t, AcceptedOf as A, MaterialiseContext as An, RelatedQueryDescriptor as Ar, RelationPaginator as At, CountToken as B, ExactPageParams as Bn, SingletonUpdateInput as Bt, createClient as C, mediaType as Cn, PaginatorDescriptor as Cr, RelatedQueryParam as Ct, TransportResponse as D, EdgeEnvelope as Dn, PivotDescriptor as Dr, RelationFilterQuery as Dt, TransportRequest as E, Edge as En, PaginatorStrategy as Er, RelationCollection as Et, BinaryResponseType as F, ResourceLinks as Fn, ResourceDescriptor as Fr, ResourceCountToken as Ft, DefaultAttributes as G, PageOf as Gn, TypedReadQuery as Gt, CreateInput as H, PageKeys as Hn, SortToken as Ht, Client as I, materialise as In, ResourceExamples as Ir, ResourceHandle as It, DocumentMeta as J, ResolvedPaginator as Jn, UpdateInput as Jt, DefaultWriteAttributes as K, PageParams as Kn, TypedRelatedReadQuery as Kt, Collection as L, relatedPaginator as Ln, SortFamilyDescriptor as Lr, ResourceObjectView as Lt, ActionsAccessor as M, RelationArrayEnvelope as Mn, RelationDescriptor as Mr, RelationSortQuery as Mt, AtomicResultOf as N, RelationView as Nn, RelationMutations as Nr, RelationshipAccessor as Nt, fetchTransport as O, Link as On, RawMediaKind as Or, RelationName as Ot, BinaryBody as P, ResourceEnvelope as Pn, ResourceCountOperation as Pr, ResourceAccessors as Pt, FieldsMap as Q, PollOptions as Qn, WaitedWriteResult as Qt, CollectionMeta as R, relatedPaginatorKind as Rn, StrategyDescriptor as Rr, SingleReadQuery as Rt, HeadersInit as S, ResourceIdentifier as Sn, OperationExamples as Sr, RelatedQueryEntry as St, TransportRawBody as T, DocumentEnvelope as Tn, PaginatorRole as Tr, RelatedReadRelatedQuery as Tt, CreateMethod as U, PageLinks as Un, TypeAccessor as Ut, CountedRelationName as V, Page as Vn, SortQuery as Vt, DefaultActionTypes as W, PageMeta as Wn, TypeName as Wt, ErrorCodeOf as X, resolvePaginator as Xn, WaitOptions as Xt, EdgeMembers as Y, TypedPage as Yn, UpdateMethod as Yt, FieldSelectionMap as Z, Accepted as Zn, WaitValue as Zt, executeRaw as _, ATOMIC_EXT as _n, FilterFamilyDescriptor as _r, ReadableRelationName as _t, Validator as a, readActionLocation as an, ActionInput as ar, IncludedResource as at, ClientOptions as b, LocalIdentifier as bn, MediaExamples as br, RelatedMeta as bt, resolveValidator as c, AtomicDeleteHandle as cn, ActionScope as cr, LinkageRef as ct, ExecutedResponse as d, AtomicRef as dn, AtomicDescriptor as dr, LooseRelatedQuery as dt, WithLinks as en, isAccepted as er, FilterQuery as et, JsonApiContext as f, AtomicResult as fn, Cardinality as fr, LooseRelatedQueryEntry as ft, execute as g, runAtomic as gn, DocumentMetaOperation as gr, ReadResult as gt, ReadQuery as h, AtomicUpdateInput as hn, DocumentMetaDescriptor as hr, PivotInput as ht, ValidationOption as i, isActionLocation as in, ActionDescriptor as ir, IncludedRelations as it, ActionCallOptions as j, NavigateOptions as jn, RelatedQueryOperation as jr, RelationReadQuery as jt, AcceptedJob as k, LinkObject as kn, RawOutputMedia as kr, RelationPageParams as kt, validateDocument as l, AtomicHandle as ln, ApiDescriptor as lr, ListFilterMember as lt, RawResponseType as m, AtomicUpdateHandle as mn, CountableDescriptor as mr, OperationMeta as mt, SchemaMap as n, WriteResult as nn, AcceptedDescriptor as nr, IdentifierMember as nt, WireResource as o, AtomicCreateHandle as on, ActionLocationDescriptor as or, IncludedType as ot, JsonApiRequest as p, AtomicResults as pn, ClientIdPolicy as pr, MemberName as pt, DeleteResult as q, PageParamsOf as qn, TypedRelationReadQuery as qt, ValidationConfig as r, ActionLocation as rn, AcceptedOperation as rr, IncludePath as rt, assertJsonApiDocument as s, AtomicCreateInput as sn, ActionOutput as sr, IsSingleton as st, ResolvedValidator as t, WriteOptions as tn, parseRetryAfter as tr, HydratedMember as tt, Document as u, AtomicRecorder as un, ApiExamples as ur, ListPageParams as ut, executeResponse as v, ATOMIC_MEDIA_TYPE as vn, InputMedia as vr, RelatedIncludedResource as vt, JsonApiTransport as w, ArrayEnvelope as wn, PaginatorKind as wr, RelatedQueryRelation as wt, HANDLE_RESERVED as x, MediaTypeParams as xn, MenuDescriptor as xr, RelatedQuery as xt, serializeQuery as y, JSON_API_MEDIA_TYPE as yn, InputMediaKind as yr, RelatedIncludedType as yt, CountAccessor as z, CANONICAL_PAGE_KEYS as zn, isPolymorphic as zr, SingletonAccessor as zt };
2740
- //# sourceMappingURL=validate-C9ekU8fM.d.cts.map
3193
+ export { DocumentMeta as $, LinkObject as $n, PaginatorRole as $r, ResourceObjectView as $t, TransportResponse as A, AtomicOperationArgs as An, ActionDescriptor as Ar, RelatedIncludedType as At, Client as B, runAtomic as Bn, ClientIdPolicy as Br, RelationPageParams as Bt, ClientOptions as C, ActionLocation as Cn, Accepted as Cr, NestedFieldsetMember as Ct, JsonApiTransport as D, AtomicCreateInput as Dn, parseRetryAfter as Dr, ReadResult as Dt, createClient as E, AtomicCreateHandle as En, isAccepted as Er, PivotInput as Et, ActionCallOptions as F, AtomicRelationshipRecorder as Fn, AdditionalMembersDescriptor as Fr, RelatedQueryRelation as Ft, CountedRelationName as G, MediaTypeParams as Gn, InputMedia as Gr, RelationshipAccessor as Gt, CollectionMeta as H, ATOMIC_MEDIA_TYPE as Hn, DocumentMetaDescriptor as Hr, RelationReadQuery as Ht, ActionsAccessor as I, AtomicResult as In, ApiDescriptor as Ir, RelatedReadRelatedQuery as It, DefaultActionTypes as J, ArrayEnvelope as Jn, MenuDescriptor as Jr, RequiresRequestMeta as Jt, CreateInput as K, ResourceIdentifier as Kn, InputMediaKind as Kr, RelationshipMembers as Kt, AtomicResultOf as L, AtomicResults as Ln, ApiExamples as Lr, RelationCollection as Lt, AcceptedJob as M, AtomicRef as Mn, ActionLocationDescriptor as Mr, RelatedQuery as Mt, AcceptedMeta as N, AtomicRelationshipArgs as Nn, ActionOutput as Nr, RelatedQueryEntry as Nt, TransportRawBody as O, AtomicDeleteHandle as On, AcceptedDescriptor as Or, ReadableRelationName as Ot, AcceptedOf as P, AtomicRelationshipHandle as Pn, ActionScope as Pr, RelatedQueryParam as Pt, DeleteResult as Q, Link as Qn, PaginatorKind as Qr, ResourceMetaOf as Qt, BinaryBody as R, AtomicUpdateHandle as Rn, AtomicDescriptor as Rr, RelationFilterQuery as Rt, serializeQuery as S, WriteResult as Sn, resolvePaginator as Sr, MutationVerb as St, HeadersInit as T, readActionLocation as Tn, PollTimeoutError as Tr, OptionsArg as Tt, CountAccessor as U, JSON_API_MEDIA_TYPE as Un, DocumentMetaOperation as Ur, RelationRequestMetaOf as Ut, Collection as V, ATOMIC_EXT as Vn, CountableDescriptor as Vr, RelationPaginator as Vt, CountToken as W, LocalIdentifier as Wn, FilterFamilyDescriptor as Wr, RelationSortQuery as Wt, DefaultWriteAttributes as X, Edge as Xn, OperationExamples as Xr, ResourceCountToken as Xt, DefaultAttributes as Y, DocumentEnvelope as Yn, MetaLiteral as Yr, ResourceAccessors as Yt, DeleteArgs as Z, EdgeEnvelope as Zn, PaginatorDescriptor as Zr, ResourceHandle as Zt, RawResponseType as _, WaitedWriteResult as _n, PageOf as _r, LooseRelatedQueryEntry as _t, ValidationOption as a, RelatedQueryOperation as ai, SortQuery as an, ResourceLinks as ar, FilterQuery as at, executeRaw as b, WritableRelationName as bn, ResolvedPaginator as br, MetaOption as bt, assertJsonApiDocument as c, RequestMetaOperation as ci, TypeAccessor as cn, relatedPaginatorKind as cr, IncludePath as ct, sparseSchemas as d, ResourceExamples as di, TypedRelatedReadQuery as dn, CANONICAL_PAGE_KEYS as dr, IncludedType as dt, PaginatorStrategy as ei, ResourceWriteMeta as en, MaterialiseContext as er, EdgeMembers as et, validateDocument as f, ResourceMetaDescriptor as fi, TypedRelationReadQuery as fn, ExactPageParams as fr, IsSingleton as ft, JsonApiRequest as g, WaitValue as gn, PageMeta as gr, LooseRelatedQuery as gt, JsonApiContext as h, isPolymorphic as hi, WaitOptions as hn, PageLinks as hr, ListPageParams as ht, ValidationContext as i, RelatedQueryDescriptor as ii, SingletonUpdateInput as in, ResourceEnvelope as ir, FilterKey as it, fetchTransport as j, AtomicRecorder as jn, ActionInput as jr, RelatedMeta as jt, TransportRequest as k, AtomicHandle as kn, AcceptedOperation as kr, RelatedIncludedResource as kt, resolveValidator as l, ResourceCountOperation as li, TypeName as ln, NestedFieldset as lr, IncludedRelations as lt, ExecutedResponse as m, StrategyDescriptor as mi, UpdateMethod as mn, PageKeys as mr, ListFilterMember as mt, SchemaMap as n, RawMediaKind as ni, SingleReadQuery as nn, RelationArrayEnvelope as nr, FieldSelectionMap as nt, Validator as o, RelationDescriptor as oi, SortToken as on, materialise as or, HydratedMember as ot, Document as p, SortFamilyDescriptor as pi, UpdateInput as pn, Page as pr, LinkageRef as pt, CreateMethod as q, mediaType as qn, MediaExamples as qr, RequestMetaOf as qt, ValidationConfig as r, RawOutputMedia as ri, SingletonAccessor as rn, RelationView as rr, FieldsMap as rt, WireResource as s, RelationMutations as si, TakesVerb as sn, relatedPaginator as sr, IdentifierMember as st, ResolvedValidator as t, PivotDescriptor as ti, ResourceWriteOperation as tn, NavigateOptions as tr, ErrorCodeOf as tt, sparseSchema as u, ResourceDescriptor as ui, TypedReadQuery as un, nestedFieldset as ur, IncludedResource as ut, ReadQuery as v, WithDocumentMeta as vn, PageParams as vr, MemberName as vt, HANDLE_RESERVED as w, isActionLocation as wn, PollOptions as wr, OperationMeta as wt, executeResponse as x, WriteOptions as xn, TypedPage as xr, MutationMetaOf as xt, execute as y, WithLinks as yn, PageParamsOf as yr, MetaObject as yt, BinaryResponseType as z, AtomicUpdateInput as zn, Cardinality as zr, RelationName as zt };
3194
+ //# sourceMappingURL=validate-Dj6pkoNM.d.cts.map