@haddowg/json-api-client 1.26.0 → 1.27.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.
- package/README.md +6 -0
- package/dist/ajv.cjs +20 -2
- package/dist/ajv.d.cts +5 -1
- package/dist/ajv.d.cts.map +1 -1
- package/dist/ajv.d.mts +5 -1
- package/dist/ajv.d.mts.map +1 -1
- package/dist/ajv.mjs +20 -2
- package/dist/ajv.mjs.map +1 -1
- package/dist/index.cjs +192 -240
- package/dist/index.d.cts +32 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +32 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +175 -228
- package/dist/index.mjs.map +1 -1
- package/dist/validate-BvO7NhkT.mjs +418 -0
- package/dist/validate-BvO7NhkT.mjs.map +1 -0
- package/dist/{validate-C9ekU8fM.d.cts → validate-CMy8mJD2.d.cts} +486 -59
- package/dist/validate-CMy8mJD2.d.cts.map +1 -0
- package/dist/{validate-C9ekU8fM.d.mts → validate-CMy8mJD2.d.mts} +486 -59
- package/dist/validate-CMy8mJD2.d.mts.map +1 -0
- package/dist/validate-DMRQn0XN.cjs +481 -0
- package/package.json +1 -1
- package/dist/validate-C9ekU8fM.d.cts.map +0 -1
- package/dist/validate-C9ekU8fM.d.mts.map +0 -1
|
@@ -40,6 +40,18 @@ 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 undeclared members an open meta object takes: their wire-format hint, and whether `null`. */
|
|
52
|
+
interface AdditionalMembersDescriptor {
|
|
53
|
+
format: string;
|
|
54
|
+
nullable?: boolean;
|
|
43
55
|
}
|
|
44
56
|
/**
|
|
45
57
|
* The members a document declares in its top-level `meta`, read from the per-operation document
|
|
@@ -51,6 +63,21 @@ interface PivotDescriptor {
|
|
|
51
63
|
type DocumentMetaDescriptor = PivotDescriptor;
|
|
52
64
|
/** An operation of a type whose document may declare its top-level `meta`. */
|
|
53
65
|
type DocumentMetaOperation = 'fetchMany' | 'fetchOne' | 'create' | 'update' | 'delete';
|
|
66
|
+
/** A write of a type whose request document may declare its top-level `meta`. */
|
|
67
|
+
type RequestMetaOperation = 'create' | 'update' | 'delete';
|
|
68
|
+
/**
|
|
69
|
+
* The `meta` of a type's resource objects, read from the components the server marks
|
|
70
|
+
* `x-resource-meta`: `read` what a response renders, `create` and `update` what a write's
|
|
71
|
+
* `data.meta` takes. `atomicCreate` and `atomicUpdate` are the `data.meta` of an `add` or `update`
|
|
72
|
+
* inside an atomic batch, present only when they differ from `create` and `update`.
|
|
73
|
+
*/
|
|
74
|
+
interface ResourceMetaDescriptor {
|
|
75
|
+
read?: PivotDescriptor;
|
|
76
|
+
create?: PivotDescriptor;
|
|
77
|
+
update?: PivotDescriptor;
|
|
78
|
+
atomicCreate?: PivotDescriptor;
|
|
79
|
+
atomicUpdate?: PivotDescriptor;
|
|
80
|
+
}
|
|
54
81
|
interface RelationDescriptor {
|
|
55
82
|
cardinality: Cardinality;
|
|
56
83
|
/** Related JSON:API type(s). */
|
|
@@ -179,6 +206,25 @@ interface RelationDescriptor {
|
|
|
179
206
|
* read's members for a to-many, its single read's for a to-one. Absent when it declares none.
|
|
180
207
|
*/
|
|
181
208
|
documentMeta?: DocumentMetaDescriptor;
|
|
209
|
+
/**
|
|
210
|
+
* The top-level `meta` each relationship write takes, keyed by its verb, read from the request
|
|
211
|
+
* document the server marks `x-request-meta`. A verb that declares none has no entry, and the
|
|
212
|
+
* map is absent when none does.
|
|
213
|
+
*/
|
|
214
|
+
requestMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
|
|
215
|
+
/**
|
|
216
|
+
* The top-level `meta` each operation on the relation takes inside an atomic batch, keyed by its
|
|
217
|
+
* verb like {@link requestMeta}, read from the atomic relationship operation kinds the type has
|
|
218
|
+
* of its own for the relation. A verb that declares none has no entry, and the map is absent
|
|
219
|
+
* when none does.
|
|
220
|
+
*/
|
|
221
|
+
atomicRequestMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
|
|
222
|
+
/**
|
|
223
|
+
* The top-level `meta` of the meta-only `200` each relationship write answers with instead of
|
|
224
|
+
* the linkage, keyed by its verb. A verb answering with the linkage has no entry, and the map is
|
|
225
|
+
* absent when none answers meta-only.
|
|
226
|
+
*/
|
|
227
|
+
mutationMeta?: Readonly<Partial<Record<keyof RelationMutations, DocumentMetaDescriptor>>>;
|
|
182
228
|
}
|
|
183
229
|
/** A built-in pagination strategy. */
|
|
184
230
|
type PaginatorStrategy = 'page' | 'offset' | 'cursor' | 'fixed';
|
|
@@ -257,6 +303,8 @@ interface InputMedia {
|
|
|
257
303
|
*/
|
|
258
304
|
interface AcceptedDescriptor {
|
|
259
305
|
jobType: string;
|
|
306
|
+
/** The top-level `meta` the job document declares. Absent when it declares none. */
|
|
307
|
+
meta?: DocumentMetaDescriptor;
|
|
260
308
|
}
|
|
261
309
|
/**
|
|
262
310
|
* A custom action declared on a type (`#[AsJsonApiAction]`). The runtime reaches it via
|
|
@@ -368,6 +416,12 @@ interface ActionDescriptor {
|
|
|
368
416
|
* result is then that `200`'s `meta` or the resource. Absent otherwise.
|
|
369
417
|
*/
|
|
370
418
|
metaResult?: boolean;
|
|
419
|
+
/**
|
|
420
|
+
* The top-level `meta` the action's request document takes, read from the document the server
|
|
421
|
+
* marks `x-request-meta`. An action with input `none` sends a meta-only document carrying it.
|
|
422
|
+
* Absent when the action declares none.
|
|
423
|
+
*/
|
|
424
|
+
requestMeta?: DocumentMetaDescriptor;
|
|
371
425
|
}
|
|
372
426
|
/**
|
|
373
427
|
* The `withCount` capability of a type's read endpoints (the Countable profile, core ADR
|
|
@@ -468,6 +522,23 @@ interface ResourceDescriptor {
|
|
|
468
522
|
* is includable, or the document types `included` only as `{type, id}`.
|
|
469
523
|
*/
|
|
470
524
|
included?: readonly string[];
|
|
525
|
+
/**
|
|
526
|
+
* The attributes whose single keys a sparse fieldset may select, under the Nested Fieldsets
|
|
527
|
+
* profile: attribute name -> the pattern a key must match (a regular expression source,
|
|
528
|
+
* unanchored and without delimiters), `\*` for a list whose items take keys. Each adds
|
|
529
|
+
* `<attribute>.${string}` to the members `fields` takes for this type. Absent when no attribute
|
|
530
|
+
* declares a nested fieldset.
|
|
531
|
+
*/
|
|
532
|
+
nestedFieldsets?: Readonly<Record<string, string>>;
|
|
533
|
+
/**
|
|
534
|
+
* The paths into nested objects a sparse fieldset may select of the attributes in
|
|
535
|
+
* {@link nestedFieldsets}: attribute name -> one entry per path, each the pattern of every key
|
|
536
|
+
* along it after the attribute's own, such as `['geo', '(?:lat|lng)']` for `location.geo.lat`,
|
|
537
|
+
* or `['\\*', '(?:sku|qty)']` for `lines.*.sku`, where `\*` stands for every item of a list.
|
|
538
|
+
* A key that is a plain name is escaped the way the server escapes it. Absent when no nested fieldset
|
|
539
|
+
* key holds an object or a list whose own keys may be selected.
|
|
540
|
+
*/
|
|
541
|
+
nestedFieldsetPaths?: Readonly<Record<string, readonly (readonly string[])[]>>;
|
|
471
542
|
/**
|
|
472
543
|
* The sort tokens the COLLECTION read accepts in `sort` — signed field names (`title`,
|
|
473
544
|
* `-title`). Drives `sort` narrowing. Absent when the collection advertises no sorting (so
|
|
@@ -525,6 +596,20 @@ interface ResourceDescriptor {
|
|
|
525
596
|
* {@link ActionDescriptor.documentMeta}.
|
|
526
597
|
*/
|
|
527
598
|
documentMeta?: Readonly<Partial<Record<DocumentMetaOperation, DocumentMetaDescriptor>>>;
|
|
599
|
+
/**
|
|
600
|
+
* The top-level `meta` each of the type's writes takes, keyed `create`, `update` or `delete`,
|
|
601
|
+
* read from the request document the server marks `x-request-meta`. A delete declaring it takes
|
|
602
|
+
* a meta-only request document. A write that declares none has no entry, and the map is absent
|
|
603
|
+
* when none does.
|
|
604
|
+
*/
|
|
605
|
+
requestMeta?: Readonly<Partial<Record<RequestMetaOperation, DocumentMetaDescriptor>>>;
|
|
606
|
+
/**
|
|
607
|
+
* The top-level `meta` each of the type's operations takes inside an atomic batch, keyed like
|
|
608
|
+
* {@link requestMeta}, read from the atomic operation kinds the type has of its own.
|
|
609
|
+
*/
|
|
610
|
+
atomicRequestMeta?: Readonly<Partial<Record<RequestMetaOperation, DocumentMetaDescriptor>>>;
|
|
611
|
+
/** The `meta` of the type's resource objects, as a read renders it and a write sends it. */
|
|
612
|
+
resourceMeta?: ResourceMetaDescriptor;
|
|
528
613
|
}
|
|
529
614
|
/** A write that can answer `202 Accepted`. */
|
|
530
615
|
type AcceptedOperation = 'create' | 'update';
|
|
@@ -584,15 +669,18 @@ interface PollOptions {
|
|
|
584
669
|
signal?: AbortSignal;
|
|
585
670
|
}
|
|
586
671
|
/**
|
|
587
|
-
* A write the server accepted for later (`202 Accepted`). `Job` is the job it answered with
|
|
588
|
-
* `Result` what the write resolves to once the job is done
|
|
672
|
+
* A write the server accepted for later (`202 Accepted`). `Job` is the job it answered with,
|
|
673
|
+
* `Result` what the write resolves to once the job is done, and `Meta` the job document's
|
|
674
|
+
* top-level `meta`.
|
|
589
675
|
*/
|
|
590
|
-
interface Accepted<Job, Result = unknown> {
|
|
676
|
+
interface Accepted<Job, Result = unknown, Meta = Record<string, unknown> | undefined> {
|
|
591
677
|
/**
|
|
592
678
|
* The job, materialised as its type's resource, or the document's top-level `meta` when the
|
|
593
679
|
* server answered with a meta-only document.
|
|
594
680
|
*/
|
|
595
681
|
readonly job: Job;
|
|
682
|
+
/** The `202` document's top-level `meta`, typed with the members the operation declares. */
|
|
683
|
+
readonly meta: Meta;
|
|
596
684
|
/** The job URL, from `Content-Location`, which {@link $poll} reads until the job is done. */
|
|
597
685
|
readonly contentLocation: string;
|
|
598
686
|
/**
|
|
@@ -779,6 +867,25 @@ type PageParamsOf<P extends Page> = PaginatorKind extends P['kind'] ? Readonly<R
|
|
|
779
867
|
kind: A;
|
|
780
868
|
} : unknown);
|
|
781
869
|
//#endregion
|
|
870
|
+
//#region src/nested-fieldset.d.ts
|
|
871
|
+
/**
|
|
872
|
+
* The keys a sparse fieldset selected of each attribute it narrowed, under the Nested Fieldsets
|
|
873
|
+
* profile (https://haddowg.github.io/json-api/profiles/nested-fieldsets/): attribute name -> the
|
|
874
|
+
* paths `fields[type]=<attribute>.<path>` named, in request order, each once. A path into a nested
|
|
875
|
+
* object, such as `geo.lat`, names one key per level, and a path through a list names its items
|
|
876
|
+
* `*`, such as `*.sku`. An attribute the fieldset also lists whole
|
|
877
|
+
* is left out, and so is a path whose key the fieldset also lists whole, since the server renders
|
|
878
|
+
* those whole. A path ending in `*` names the list itself, so `lines.*` lists `lines` whole and
|
|
879
|
+
* `shipping.parcels.*` selects `parcels` whole. Empty when nothing was narrowed.
|
|
880
|
+
*/
|
|
881
|
+
type NestedFieldset = Readonly<Record<string, readonly string[]>>;
|
|
882
|
+
/**
|
|
883
|
+
* The {@link NestedFieldset} of one type's `fields[type]` members. The path is everything after the
|
|
884
|
+
* first full stop, as the server reads it, and a member with an empty key at any level selects
|
|
885
|
+
* nothing.
|
|
886
|
+
*/
|
|
887
|
+
declare function nestedFieldset(listed: readonly string[] | undefined): NestedFieldset;
|
|
888
|
+
//#endregion
|
|
782
889
|
//#region src/materialise.d.ts
|
|
783
890
|
/** A trimmed, by-reference top-level envelope shared by every resource from one response. */
|
|
784
891
|
interface DocumentEnvelope {
|
|
@@ -828,6 +935,11 @@ interface ResourceEnvelope {
|
|
|
828
935
|
readonly $self: string | undefined;
|
|
829
936
|
readonly $document: DocumentEnvelope;
|
|
830
937
|
readonly $raw: RawResource;
|
|
938
|
+
/**
|
|
939
|
+
* The keys the request's sparse fieldset selected of each attribute it narrowed, under the Nested
|
|
940
|
+
* Fieldsets profile. An attribute named here holds only those of its keys the resource has.
|
|
941
|
+
*/
|
|
942
|
+
readonly $nestedFieldset: NestedFieldset;
|
|
831
943
|
$rel(name: string): RelationView | undefined;
|
|
832
944
|
/**
|
|
833
945
|
* A relationship's count, from its `meta.total` (a `withCount` read): a finite number, else
|
|
@@ -876,6 +988,11 @@ interface MaterialiseContext {
|
|
|
876
988
|
* before the document is materialised. Absent => no per-field validation (the default).
|
|
877
989
|
*/
|
|
878
990
|
validate?: ResolvedValidator | undefined;
|
|
991
|
+
/**
|
|
992
|
+
* The sparse fieldsets the request sent, by type, which tell an attribute narrowed to some of
|
|
993
|
+
* its keys from one rendered whole (see {@link ResourceEnvelope.$nestedFieldset}).
|
|
994
|
+
*/
|
|
995
|
+
fields?: Readonly<Record<string, readonly string[]>> | undefined;
|
|
879
996
|
}
|
|
880
997
|
/** A raw JSON:API resource object (or bare identifier) off the wire. */
|
|
881
998
|
interface RawResource {
|
|
@@ -993,7 +1110,7 @@ type AtomicRef = ResourceIdentifier | {
|
|
|
993
1110
|
*/
|
|
994
1111
|
type AtomicCreateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = {
|
|
995
1112
|
type: T;
|
|
996
|
-
} & CreateInput<D, W, T>;
|
|
1113
|
+
} & CreateInput<D, W, T, 'atomicCreate'>;
|
|
997
1114
|
/**
|
|
998
1115
|
* Flat update input for type `T`: the `type` discriminant + the target's identity (`id`, OR a
|
|
999
1116
|
* `lid` for a resource created earlier in the same batch) plus the type's flat update
|
|
@@ -1003,11 +1120,22 @@ type AtomicUpdateInput<D extends ApiDescriptor, W, T extends TypeName<D>> = ({
|
|
|
1003
1120
|
type: T;
|
|
1004
1121
|
id: string;
|
|
1005
1122
|
lid?: never;
|
|
1006
|
-
} & UpdateInput<D, W, T>) | ({
|
|
1123
|
+
} & UpdateInput<D, W, T, 'atomicUpdate'>) | ({
|
|
1007
1124
|
type: T;
|
|
1008
1125
|
lid: string;
|
|
1009
1126
|
id?: never;
|
|
1010
|
-
} & UpdateInput<D, W, T>);
|
|
1127
|
+
} & UpdateInput<D, W, T, 'atomicUpdate'>);
|
|
1128
|
+
/**
|
|
1129
|
+
* The options argument of an atomic operation of type `T`: the operation's `meta`, typed by the
|
|
1130
|
+
* type's `atomicRequestMeta` and required when a member is. A type declaring none takes any.
|
|
1131
|
+
*/
|
|
1132
|
+
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>>>;
|
|
1133
|
+
/**
|
|
1134
|
+
* The options argument of an atomic operation with verb `V` on relation `R` of type `T`: its
|
|
1135
|
+
* `meta`, typed by the relation's `atomicRequestMeta` and required when a member is. A relation
|
|
1136
|
+
* declaring none takes any.
|
|
1137
|
+
*/
|
|
1138
|
+
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
1139
|
/**
|
|
1012
1140
|
* The handle a {@link AtomicRecorder.create} returns. It is a `lid`-bearing relationship ref
|
|
1013
1141
|
* (`{ type, lid }`) — pass it (or spread it) into a later op's relation slot to wire the
|
|
@@ -1038,6 +1166,18 @@ interface AtomicDeleteHandle {
|
|
|
1038
1166
|
readonly kind: 'delete';
|
|
1039
1167
|
readonly opIndex: number;
|
|
1040
1168
|
}
|
|
1169
|
+
/**
|
|
1170
|
+
* The handle a relationship operation returns (the `add`, `remove`, `replace` or `set` of
|
|
1171
|
+
* {@link AtomicRecorder.rel}): the target's type `T`, its `relationship` `R`, its op `kind`
|
|
1172
|
+
* (`'relationship'`) and its `opIndex`. Its positional result is the linkage the server answered
|
|
1173
|
+
* with.
|
|
1174
|
+
*/
|
|
1175
|
+
interface AtomicRelationshipHandle<T extends string = string, R extends string = string> {
|
|
1176
|
+
readonly type: T;
|
|
1177
|
+
readonly relationship: R;
|
|
1178
|
+
readonly kind: 'relationship';
|
|
1179
|
+
readonly opIndex: number;
|
|
1180
|
+
}
|
|
1041
1181
|
/**
|
|
1042
1182
|
* Any handle a recorder method returns — the element type of the callback's result tuple, used
|
|
1043
1183
|
* as the inference constraint for the typed-tuple `atomic` form. The discriminant is left open
|
|
@@ -1048,7 +1188,28 @@ interface AtomicDeleteHandle {
|
|
|
1048
1188
|
* is a real `TypeName<D>`, so the open constraint is sound; `AtomicResultOf` re-infers the precise
|
|
1049
1189
|
* `T` per element (guarded by `TypeName<D>` there).
|
|
1050
1190
|
*/
|
|
1051
|
-
type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | AtomicDeleteHandle
|
|
1191
|
+
type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | AtomicDeleteHandle | AtomicRelationshipHandle<string, string>;
|
|
1192
|
+
/**
|
|
1193
|
+
* A relationship verb inside an atomic batch: present only when relation `R`'s cardinality matches
|
|
1194
|
+
* the verb's and the relation advertises it in its `mutations` flags, as the standalone accessor's
|
|
1195
|
+
* verbs are gated, and `never` otherwise.
|
|
1196
|
+
*/
|
|
1197
|
+
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;
|
|
1198
|
+
/**
|
|
1199
|
+
* What {@link AtomicRecorder.rel} returns: relation `R` of a resource of type `T`, whose verbs
|
|
1200
|
+
* each record one relationship operation. A to-many takes `add`, `remove` and `replace` and a
|
|
1201
|
+
* to-one `set`, each only when the relation advertises it.
|
|
1202
|
+
*/
|
|
1203
|
+
interface AtomicRelationshipRecorder<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> {
|
|
1204
|
+
/** Add `members` to the to-many: an `add` op on its relationship. */
|
|
1205
|
+
add: AtomicRelationMutation<D, T, R, 'add'>;
|
|
1206
|
+
/** Remove `members` from the to-many: a `remove` op on its relationship. */
|
|
1207
|
+
remove: AtomicRelationMutation<D, T, R, 'remove'>;
|
|
1208
|
+
/** Replace every member of the to-many with `members`: an `update` op on its relationship. */
|
|
1209
|
+
replace: AtomicRelationMutation<D, T, R, 'replace'>;
|
|
1210
|
+
/** Set the to-one to `member`, or clear it with `null`: an `update` op on its relationship. */
|
|
1211
|
+
set: AtomicRelationMutation<D, T, R, 'set'>;
|
|
1212
|
+
}
|
|
1052
1213
|
/**
|
|
1053
1214
|
* The recorder handed to the `client.atomic` callback. Each method appends an op (preserving
|
|
1054
1215
|
* order) and returns a handle carrying the op's discriminant `T`, `kind`, and `opIndex`. The
|
|
@@ -1058,9 +1219,19 @@ type AtomicHandle = AtomicCreateHandle<string> | AtomicUpdateHandle<string> | At
|
|
|
1058
1219
|
* just-created resource wires into a later op without a server id.
|
|
1059
1220
|
*/
|
|
1060
1221
|
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
|
|
1222
|
+
create<T extends TypeName<D>>(input: AtomicCreateInput<D, W, T>, ...opts: AtomicOperationArgs<D, T, 'create'>): AtomicCreateHandle<T>;
|
|
1223
|
+
update<T extends TypeName<D>>(input: AtomicUpdateInput<D, W, T>, ...opts: AtomicOperationArgs<D, T, 'update'>): AtomicUpdateHandle<T>;
|
|
1224
|
+
delete<T extends TypeName<D>>(ref: AtomicRef & {
|
|
1225
|
+
type: T;
|
|
1226
|
+
}, ...opts: AtomicOperationArgs<D, T, 'delete'>): AtomicDeleteHandle;
|
|
1227
|
+
/**
|
|
1228
|
+
* Relation `relationship` of the resource `ref` names, by its server `id` or the `lid` of a
|
|
1229
|
+
* resource created earlier in the batch. Its verbs record operations on the relationship. Only
|
|
1230
|
+
* a relation that takes at least one verb is accepted.
|
|
1231
|
+
*/
|
|
1232
|
+
rel<T extends TypeName<D>, R extends WritableRelationName<D, T>>(ref: AtomicRef & {
|
|
1233
|
+
type: T;
|
|
1234
|
+
}, relationship: R): AtomicRelationshipRecorder<D, T, R>;
|
|
1064
1235
|
}
|
|
1065
1236
|
/** One positional result of an atomic batch: the materialised `data` (a resource/`null`) plus any op `meta`. */
|
|
1066
1237
|
interface AtomicResult<Data = unknown> {
|
|
@@ -1157,15 +1328,21 @@ interface EdgeMembers<Pivot = Record<string, unknown>, Meta extends Record<strin
|
|
|
1157
1328
|
/**
|
|
1158
1329
|
* The resource-level `$`-accessors on a materialised resource object. `Links` types `$links`: the
|
|
1159
1330
|
* type's generated links interface when its resources declare links, else the loose
|
|
1160
|
-
* {@link ResourceLinks}.
|
|
1331
|
+
* {@link ResourceLinks}. `Meta` types `$meta`, the resource object's own `meta`: the members its
|
|
1332
|
+
* type declares, else the loose record.
|
|
1161
1333
|
*/
|
|
1162
|
-
interface ResourceAccessors<Links = ResourceLinks> {
|
|
1163
|
-
readonly $meta:
|
|
1334
|
+
interface ResourceAccessors<Links = ResourceLinks, Meta = Record<string, unknown> | undefined> {
|
|
1335
|
+
readonly $meta: Meta;
|
|
1164
1336
|
readonly $links: Links | undefined;
|
|
1165
1337
|
/** The `self` link's href, whether the wire carried a bare URL or a link object. */
|
|
1166
1338
|
readonly $self: string | undefined;
|
|
1167
1339
|
readonly $document: DocumentEnvelope;
|
|
1168
1340
|
readonly $raw: Record<string, unknown>;
|
|
1341
|
+
/**
|
|
1342
|
+
* The keys the request's sparse fieldset selected of each attribute it narrowed, under the Nested
|
|
1343
|
+
* Fieldsets profile. Empty when the request narrowed no attribute of this type.
|
|
1344
|
+
*/
|
|
1345
|
+
readonly $nestedFieldset: NestedFieldset;
|
|
1169
1346
|
$rel(name: string): RelationView | undefined;
|
|
1170
1347
|
}
|
|
1171
1348
|
/** Every wire type declared by the descriptor `D`. */
|
|
@@ -1219,6 +1396,44 @@ type SelectedFields<F, T extends string> = F extends FieldSelectionMap ? T exten
|
|
|
1219
1396
|
* object's keys are exactly the requested members — the static mirror of a sparse fieldset.
|
|
1220
1397
|
*/
|
|
1221
1398
|
type PickSelected<Obj, Sel> = [Sel] extends [AllFields] ? Obj : Pick<Obj, Extract<keyof Obj, Sel>>;
|
|
1399
|
+
/** The attribute a nested fieldset member names: `values` for `values.cap`. */
|
|
1400
|
+
type NestedFieldsetAttribute<Sel> = Sel extends `${infer Attribute}.${string}` ? Attribute : never;
|
|
1401
|
+
/** The paths of attribute `Attr` the nested fieldset members in `Sel` select: everything after the first dot. */
|
|
1402
|
+
type SelectedKeysOf<Sel, Attr extends string> = Sel extends `${Attr}.${infer Key}` ? Key : never;
|
|
1403
|
+
/** The first key of each path in `K`: `geo` for `geo.lat`, `*` for `*.sku`. */
|
|
1404
|
+
type PathHead<K extends string> = K extends `${infer Head}.${string}` ? Head : K;
|
|
1405
|
+
/** What the paths in `K` select inside key `Head`: `lat` for `geo.lat`. */
|
|
1406
|
+
type PathTail<K extends string, Head extends string> = K extends `${Head}.${infer Tail}` ? Tail : never;
|
|
1407
|
+
/** Whether `T` is a union of more than one member. */
|
|
1408
|
+
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
|
|
1409
|
+
/** The keys of `V` whose value is one string literal, such as a union variant's discriminator. */
|
|
1410
|
+
type LiteralStringKey<V> = { [P in keyof V]-?: V[P] extends string ? (string extends V[P] ? never : P) : never }[keyof V];
|
|
1411
|
+
/**
|
|
1412
|
+
* The key every member of the union `U` holds as one string literal, which names its variant, or
|
|
1413
|
+
* `never` when `U` is not a union.
|
|
1414
|
+
*/
|
|
1415
|
+
type DiscriminatorKey<U> = true extends IsUnion<U> ? Exclude<keyof U, U extends unknown ? Exclude<keyof U, LiteralStringKey<U>> : never> : never;
|
|
1416
|
+
/** One object type for an intersection, each key keeping whether it is optional. */
|
|
1417
|
+
type Flatten<T> = { [P in keyof T]: T[P] };
|
|
1418
|
+
/**
|
|
1419
|
+
* An attribute value narrowed to the paths `K`, each key optional, since a value without a selected
|
|
1420
|
+
* key leaves it out. A path into a nested object (`geo.lat`) narrows that object the same way,
|
|
1421
|
+
* unless `K` also lists its key whole. A list narrowed through `*` (`*.sku`) keeps every item, each
|
|
1422
|
+
* narrowed to the rest of the path, unless `K` also lists `*` whole. A value that is one of several
|
|
1423
|
+
* variants, as an attribute, a nested key or a list's item, narrows each variant on its own and
|
|
1424
|
+
* keeps the key naming it. `null` stays as it is, and a key type the client can't list keeps every
|
|
1425
|
+
* key.
|
|
1426
|
+
*/
|
|
1427
|
+
type KeySelected<V, K extends string> = KeySelectedAs<V, K, DiscriminatorKey<Exclude<V, null | undefined | readonly unknown[]>>>;
|
|
1428
|
+
/** {@link KeySelected}, given the key `D` naming the variant of a union value. */
|
|
1429
|
+
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;
|
|
1430
|
+
/** The keys of the object `V` the paths `K` select, each optional and narrowed in turn. */
|
|
1431
|
+
type NarrowedObject<V, K extends string> = { [P in Extract<PathHead<K>, keyof V>]?: P extends K ? V[P] : KeySelected<V[P], PathTail<K, P>> };
|
|
1432
|
+
/**
|
|
1433
|
+
* {@link PickSelected} for attributes: an attribute the selection names only through nested fieldset members
|
|
1434
|
+
* (`values.cap`) is present and narrowed to those keys, while one it lists whole stays whole.
|
|
1435
|
+
*/
|
|
1436
|
+
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
1437
|
/**
|
|
1223
1438
|
* The related wire type(s) of relation `R` on type `T`. A union when polymorphic; the
|
|
1224
1439
|
* member is narrowed to types that actually exist in the descriptor so the hydrated
|
|
@@ -1302,7 +1517,7 @@ interface CountAccessor<D extends ApiDescriptor, T extends TypeName<D>, Counted
|
|
|
1302
1517
|
type ResourceObjectView<D extends ApiDescriptor, A, T extends TypeName<D>, Inc = never, F = unknown, Counted = never> = {
|
|
1303
1518
|
type: T;
|
|
1304
1519
|
id: string;
|
|
1305
|
-
} &
|
|
1520
|
+
} & 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
1521
|
/**
|
|
1307
1522
|
* The element type of the `include` array for type `T`: a path from the descriptor's
|
|
1308
1523
|
* `includable` enum — the exact set the server advertises, including nested dotted paths
|
|
@@ -1501,7 +1716,15 @@ type FieldsMap<D extends ApiDescriptor> = { [T in TypeName<D>]?: readonly Member
|
|
|
1501
1716
|
* `attributes` keys) or a relation a response renders. The descriptor carries the literal member
|
|
1502
1717
|
* names, so `fields` entries are constrained to real members.
|
|
1503
1718
|
*/
|
|
1504
|
-
type MemberName<D extends ApiDescriptor, T extends TypeName<D>> = Extract<keyof D[T]['attributes'], string> | ReadableRelationName<D, T>;
|
|
1719
|
+
type MemberName<D extends ApiDescriptor, T extends TypeName<D>> = Extract<keyof D[T]['attributes'], string> | ReadableRelationName<D, T> | NestedFieldsetMember<D, T>;
|
|
1720
|
+
/**
|
|
1721
|
+
* A nested fieldset member of type `T`: `<attribute>.${string}` for each attribute whose single keys a sparse
|
|
1722
|
+
* fieldset may select (the descriptor's `nestedFieldsets`), under the Nested Fieldsets profile.
|
|
1723
|
+
* `never` when the type declares none.
|
|
1724
|
+
*/
|
|
1725
|
+
type NestedFieldsetMember<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
|
|
1726
|
+
nestedFieldsets: infer S;
|
|
1727
|
+
} ? `${Extract<keyof S, string>}.${string}` : never;
|
|
1505
1728
|
/**
|
|
1506
1729
|
* The `relatedQuery` entry for relation `R` of type `T`: its `filter` and `sort` typed as the
|
|
1507
1730
|
* relation's own related read types them (see {@link RelationFilterQuery} and
|
|
@@ -1675,6 +1898,30 @@ type PivotFieldNames<P> = P extends {
|
|
|
1675
1898
|
} ? keyof Fl : never;
|
|
1676
1899
|
/** The `meta.pivot` object a {@link PivotDescriptor} describes. */
|
|
1677
1900
|
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> };
|
|
1901
|
+
/** The value an open {@link PivotDescriptor} takes for each member beside its fields. */
|
|
1902
|
+
type AdditionalValue<P> = P extends {
|
|
1903
|
+
additional: infer X;
|
|
1904
|
+
} ? X extends {
|
|
1905
|
+
format: infer H;
|
|
1906
|
+
} ? FormatToTs<H> | (X extends {
|
|
1907
|
+
nullable: true;
|
|
1908
|
+
} ? null : never) : never : never;
|
|
1909
|
+
/** The value of any declared field of a {@link PivotDescriptor}. */
|
|
1910
|
+
type DeclaredValue<P> = P extends {
|
|
1911
|
+
fields: infer Fl;
|
|
1912
|
+
} ? { [K in keyof Fl]: PivotValue<P, K> }[keyof Fl] : never;
|
|
1913
|
+
/**
|
|
1914
|
+
* The undeclared members an open {@link PivotDescriptor} takes, as an index signature whose value
|
|
1915
|
+
* also admits each declared field's and `Extra`, the other members the object carries, so the
|
|
1916
|
+
* declared ones keep their types. `unknown`, adding nothing, for a closed object.
|
|
1917
|
+
*/
|
|
1918
|
+
type AdditionalMembers<P, Extra = never> = P extends {
|
|
1919
|
+
additional: {
|
|
1920
|
+
format: unknown;
|
|
1921
|
+
};
|
|
1922
|
+
} ? {
|
|
1923
|
+
readonly [member: string]: AdditionalValue<P> | DeclaredValue<P> | Extra | undefined;
|
|
1924
|
+
} : unknown;
|
|
1678
1925
|
/** The legacy hint-only pivot shape: every field present and non-null. */
|
|
1679
1926
|
type LegacyPivot<P> = { readonly [K in keyof P]: FormatToTs<P[K]> };
|
|
1680
1927
|
/**
|
|
@@ -1685,17 +1932,29 @@ type LegacyPivot<P> = { readonly [K in keyof P]: FormatToTs<P[K]> };
|
|
|
1685
1932
|
*/
|
|
1686
1933
|
type PivotFieldsOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
1687
1934
|
readPivot: infer P;
|
|
1688
|
-
} ? PivotObject<P> : D[T]['relations'][R] extends {
|
|
1935
|
+
} ? PivotObject<P> & AdditionalMembers<P> : D[T]['relations'][R] extends {
|
|
1689
1936
|
pivotFields: infer P;
|
|
1690
1937
|
} ? LegacyPivot<P> : Record<string, unknown>;
|
|
1691
1938
|
/**
|
|
1692
1939
|
* The `$edge.meta` of each linkage member of relation `R`: the members the descriptor's
|
|
1693
|
-
* `identifierMeta` declares, typed like a pivot,
|
|
1694
|
-
*
|
|
1940
|
+
* `identifierMeta` declares, typed like a pivot, with the relation's `pivot` beside them. An
|
|
1941
|
+
* identifier meta that says whether it is open takes only those, and the undeclared members it
|
|
1942
|
+
* opens to; one that doesn't say is an open record. A relation declaring none keeps the open
|
|
1943
|
+
* record.
|
|
1695
1944
|
*/
|
|
1696
1945
|
type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
1697
1946
|
identifierMeta: infer P;
|
|
1698
|
-
} ?
|
|
1947
|
+
} ? P extends {
|
|
1948
|
+
additional: false | {
|
|
1949
|
+
format: unknown;
|
|
1950
|
+
};
|
|
1951
|
+
} ? PivotObject<P> & EdgePivot<D, T, R> & AdditionalMembers<P, PivotFieldsOf<D, T, R>> : PivotObject<P> & Record<string, unknown> : Record<string, unknown>;
|
|
1952
|
+
/** The `pivot` a pivot relation's identifier meta carries beside its declared members. */
|
|
1953
|
+
type EdgePivot<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
1954
|
+
pivot: true;
|
|
1955
|
+
} ? {
|
|
1956
|
+
readonly pivot?: PivotFieldsOf<D, T, R>;
|
|
1957
|
+
} : unknown;
|
|
1699
1958
|
/**
|
|
1700
1959
|
* The typed `meta.pivot` a request may send on each member of relation `R`, from the descriptor's
|
|
1701
1960
|
* `writePivot` (only writable fields, optional unless required). Falls back like
|
|
@@ -1703,7 +1962,7 @@ type EdgeMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends Relati
|
|
|
1703
1962
|
*/
|
|
1704
1963
|
type WritePivotOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>> = D[T]['relations'][R] extends {
|
|
1705
1964
|
writePivot: infer P;
|
|
1706
|
-
} ? PivotObject<P> : D[T]['relations'][R] extends {
|
|
1965
|
+
} ? PivotObject<P> & AdditionalMembers<P> : D[T]['relations'][R] extends {
|
|
1707
1966
|
pivotFields: infer P;
|
|
1708
1967
|
} ? LegacyPivot<P> : PivotInput;
|
|
1709
1968
|
/** Whether a {@link DocumentMetaDescriptor} requires a member, so its document always carries `meta`. */
|
|
@@ -1715,6 +1974,20 @@ type RequiresMeta<P> = [RequiredPivotField<P>] extends [never] ? false : true;
|
|
|
1715
1974
|
type DeclaredMetaObject<P> = P extends {
|
|
1716
1975
|
fields: infer Fl;
|
|
1717
1976
|
} ? { 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;
|
|
1977
|
+
/**
|
|
1978
|
+
* A declared `meta` object: the members a {@link PivotDescriptor} declares, each required one
|
|
1979
|
+
* present, and the undeclared members it takes when the server opens it. A closed object takes no
|
|
1980
|
+
* other member.
|
|
1981
|
+
*/
|
|
1982
|
+
type MetaObject<P> = P extends {
|
|
1983
|
+
fields: infer Fl;
|
|
1984
|
+
} ? [keyof Fl] extends [never] ? P extends {
|
|
1985
|
+
additional: {
|
|
1986
|
+
format: unknown;
|
|
1987
|
+
};
|
|
1988
|
+
} ? AdditionalMembers<P> : {
|
|
1989
|
+
readonly [member: string]: never;
|
|
1990
|
+
} : DeclaredMetaObject<P> & AdditionalMembers<P> : never;
|
|
1718
1991
|
/**
|
|
1719
1992
|
* The top-level `meta` a {@link DocumentMetaDescriptor} types: its members, or `undefined` when
|
|
1720
1993
|
* none is required, since the document may then carry no `meta`. A collection's also has the
|
|
@@ -1723,7 +1996,78 @@ type DeclaredMetaObject<P> = P extends {
|
|
|
1723
1996
|
*/
|
|
1724
1997
|
type DocumentMeta<P> = P extends {
|
|
1725
1998
|
fields: object;
|
|
1726
|
-
} ? RequiresMeta<P> extends true ?
|
|
1999
|
+
} ? RequiresMeta<P> extends true ? MetaObject<P> : MetaObject<P> | undefined : Record<string, unknown> | undefined;
|
|
2000
|
+
/**
|
|
2001
|
+
* The `meta` of type `T`'s resource objects, as `$meta` reads it: the members its `resourceMeta`
|
|
2002
|
+
* declares for a read, else the loose record. A resource object may carry no `meta`.
|
|
2003
|
+
*/
|
|
2004
|
+
type ResourceMetaOf<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
|
|
2005
|
+
resourceMeta: {
|
|
2006
|
+
read: infer P;
|
|
2007
|
+
};
|
|
2008
|
+
} ? MetaObject<P> | undefined : Record<string, unknown> | undefined;
|
|
2009
|
+
/** A write's `data.meta`, by where it is sent: a create or an update, alone or in an atomic batch. */
|
|
2010
|
+
type ResourceWriteOperation = 'create' | 'update' | 'atomicCreate' | 'atomicUpdate';
|
|
2011
|
+
/** The write a {@link ResourceWriteOperation} inside an atomic batch takes its `data.meta` from otherwise. */
|
|
2012
|
+
type StandaloneWrite<Op extends ResourceWriteOperation> = Op extends 'atomicCreate' ? 'create' : Op extends 'atomicUpdate' ? 'update' : Op;
|
|
2013
|
+
/**
|
|
2014
|
+
* The `$meta` a write input of type `T` takes, sent as `data.meta`: the members its
|
|
2015
|
+
* `resourceMeta` declares for `Op`, an atomic one falling back to its standalone write's, else the
|
|
2016
|
+
* loose record a type declaring none takes.
|
|
2017
|
+
*/
|
|
2018
|
+
type ResourceWriteMeta<D extends ApiDescriptor, T extends TypeName<D>, Op extends ResourceWriteOperation> = D[T] extends {
|
|
2019
|
+
resourceMeta: infer M;
|
|
2020
|
+
} ? Op extends keyof M ? MetaObject<M[Op]> : StandaloneWrite<Op> extends keyof M ? MetaObject<M[StandaloneWrite<Op>]> : Record<string, unknown> : Record<string, unknown>;
|
|
2021
|
+
/**
|
|
2022
|
+
* The top-level `meta` write `Op` of type `T` takes: the members its `requestMeta` declares, or,
|
|
2023
|
+
* with `Atomic`, its `atomicRequestMeta`'s. `never` when it declares none.
|
|
2024
|
+
*/
|
|
2025
|
+
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 {
|
|
2026
|
+
fields: object;
|
|
2027
|
+
} ? MetaObject<M[Op]> : never : never : never;
|
|
2028
|
+
/**
|
|
2029
|
+
* The `meta` option of a write whose request document declares `M`: required when `M` has a
|
|
2030
|
+
* required member, else optional. A write declaring none takes the open record, as its document
|
|
2031
|
+
* may carry any `meta`.
|
|
2032
|
+
*/
|
|
2033
|
+
type MetaOption<M> = [M] extends [never] ? {
|
|
2034
|
+
meta?: Record<string, unknown>;
|
|
2035
|
+
} : RequiresRequestMeta<M> extends true ? {
|
|
2036
|
+
meta: M;
|
|
2037
|
+
} : {
|
|
2038
|
+
meta?: M;
|
|
2039
|
+
};
|
|
2040
|
+
/** Whether a declared request `meta` has a required member, so a call must send it. */
|
|
2041
|
+
type RequiresRequestMeta<M> = [M] extends [never] ? false : [RequiredKeysOf<M>] extends [never] ? false : true;
|
|
2042
|
+
/** The keys of an object type whose members are required. */
|
|
2043
|
+
type RequiredKeysOf<M> = { [K in keyof M]-?: string extends K ? never : {} extends Pick<M, K> ? never : K }[keyof M];
|
|
2044
|
+
/** The options argument of a call taking options `O`: required when `Req` is `true`, else optional. */
|
|
2045
|
+
type OptionsArg<Req, O> = Req extends true ? [opts: O] : [opts?: O];
|
|
2046
|
+
/** The `meta` option of write `Op` on type `T`, as {@link MetaOption} types it. */
|
|
2047
|
+
type WriteMetaOption<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation> = MetaOption<RequestMetaOf<D, T, Op>>;
|
|
2048
|
+
/** Whether write `Op` on type `T` must send its `meta`. */
|
|
2049
|
+
type RequiresWriteMeta<D extends ApiDescriptor, T extends TypeName<D>, Op extends RequestMetaOperation> = RequiresRequestMeta<RequestMetaOf<D, T, Op>>;
|
|
2050
|
+
/**
|
|
2051
|
+
* The arguments of type `T`'s delete: none when it declares no request `meta`, since it then takes
|
|
2052
|
+
* no body, else an options object carrying it, required when a member is.
|
|
2053
|
+
*/
|
|
2054
|
+
type DeleteArgs<D extends ApiDescriptor, T extends TypeName<D>> = [RequestMetaOf<D, T, 'delete'>] extends [never] ? [] : OptionsArg<RequiresWriteMeta<D, T, 'delete'>, WriteMetaOption<D, T, 'delete'>>;
|
|
2055
|
+
/**
|
|
2056
|
+
* The top-level `meta` of the meta-only `200` relation `R`'s write with verb `V` answers with, or
|
|
2057
|
+
* `never` when it answers with the linkage.
|
|
2058
|
+
*/
|
|
2059
|
+
type MutationMetaOf<D extends ApiDescriptor, T extends TypeName<D>, R extends RelationName<D, T>, V extends keyof RelationMutations> = D[T]['relations'][R] extends {
|
|
2060
|
+
mutationMeta: infer M;
|
|
2061
|
+
} ? V extends keyof M ? M[V] extends {
|
|
2062
|
+
fields: object;
|
|
2063
|
+
} ? DocumentMeta<M[V]> : never : never : never;
|
|
2064
|
+
/**
|
|
2065
|
+
* The top-level `meta` relation `R`'s write with verb `V` takes, or, with `Atomic`, the operation's
|
|
2066
|
+
* inside an atomic batch. `never` when it declares none.
|
|
2067
|
+
*/
|
|
2068
|
+
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 {
|
|
2069
|
+
fields: object;
|
|
2070
|
+
} ? MetaObject<M[V]> : never : never : never;
|
|
1727
2071
|
/**
|
|
1728
2072
|
* The typed top-level `meta` of operation `Op` on type `T` (`fetchMany`, `fetchOne`, `create`,
|
|
1729
2073
|
* `update` or `delete`), or `never` when its document declares none.
|
|
@@ -1803,6 +2147,23 @@ interface RelationshipAccessor<D extends ApiDescriptor, A, T extends TypeName<D>
|
|
|
1803
2147
|
replace: RelationMutation<D, T, R, 'replace', readonly WriteRef<D, T, R>[]>;
|
|
1804
2148
|
set: RelationMutation<D, T, R, 'set', LinkageRefOf<RelatedType<D, T, R>> | null>;
|
|
1805
2149
|
}
|
|
2150
|
+
/**
|
|
2151
|
+
* True when relation `R` of type `T` takes verb `V`: it has the verb's cardinality, a to-one for
|
|
2152
|
+
* `set` and a to-many for the rest, and advertises the verb in its `mutations` flags, as the
|
|
2153
|
+
* relationship accessor gates it (see {@link AdvertisesVerb}).
|
|
2154
|
+
*/
|
|
2155
|
+
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;
|
|
2156
|
+
/**
|
|
2157
|
+
* The relations of type `T` that take at least one verb (see {@link TakesVerb}), the names
|
|
2158
|
+
* {@link AtomicRecorder.rel} accepts.
|
|
2159
|
+
*/
|
|
2160
|
+
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>];
|
|
2161
|
+
/**
|
|
2162
|
+
* The members a relationship write with verb `V` on relation `R` takes, as the relationship
|
|
2163
|
+
* accessor's verbs take them: refs with an optional `$pivot` to add or replace, refs to remove, and
|
|
2164
|
+
* one ref or `null` to set.
|
|
2165
|
+
*/
|
|
2166
|
+
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
2167
|
/**
|
|
1807
2168
|
* A linkage ref for a to-many membership WRITE on relation `R` (`add`/`replace`, or a create or
|
|
1808
2169
|
* update input), with `$pivot` typed from the relation's `writePivot` — so a `belongsToMany` add
|
|
@@ -1854,7 +2215,12 @@ type AdvertisesVerb<D extends ApiDescriptor, T extends TypeName<D>, R extends Re
|
|
|
1854
2215
|
* — or a verb the relation forbids (e.g. a to-many lacking `replace`) — is a compile error.
|
|
1855
2216
|
* The result is the materialised linkage value or `void` (a `204` response).
|
|
1856
2217
|
*/
|
|
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<
|
|
2218
|
+
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;
|
|
2219
|
+
/**
|
|
2220
|
+
* What relation `R`'s write with verb `V` resolves to: the `meta` of the meta-only `200` it
|
|
2221
|
+
* declares, else the materialised linkage, or `void` for a `204`.
|
|
2222
|
+
*/
|
|
2223
|
+
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
2224
|
/** The relationship accessors of type `T`, keyed by relation name. */
|
|
1859
2225
|
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
2226
|
/**
|
|
@@ -1919,12 +2285,16 @@ type CreateId<D extends ApiDescriptor, T extends TypeName<D>> = D[T]['clientId']
|
|
|
1919
2285
|
* slots, plus an `id` keyed by the client-id policy. The runtime builds the JSON:API
|
|
1920
2286
|
* envelope (routing keys to attributes/relationships via the descriptor).
|
|
1921
2287
|
*/
|
|
1922
|
-
type CreateInput<D extends ApiDescriptor, W, T extends TypeName<D
|
|
2288
|
+
type CreateInput<D extends ApiDescriptor, W, T extends TypeName<D>, Op extends 'create' | 'atomicCreate' = 'create'> = CreateAttributesOf<W, T> & RelationInputs<D, T> & CreateId<D, T> & {
|
|
2289
|
+
/** The resource object's `meta`, sent as `data.meta`. */$meta?: ResourceWriteMeta<D, T, Op>;
|
|
2290
|
+
};
|
|
1923
2291
|
/**
|
|
1924
2292
|
* The flat input to `client.<type>.id(id).update(patch)`: the type's update attributes (all
|
|
1925
2293
|
* optional) + relation slots. The id rides the handle, never the input.
|
|
1926
2294
|
*/
|
|
1927
|
-
type UpdateInput<D extends ApiDescriptor, W, T extends TypeName<D
|
|
2295
|
+
type UpdateInput<D extends ApiDescriptor, W, T extends TypeName<D>, Op extends 'update' | 'atomicUpdate' = 'update'> = UpdateAttributesOf<W, T> & RelationInputs<D, T> & {
|
|
2296
|
+
/** The resource object's `meta`, sent as `data.meta`. */$meta?: ResourceWriteMeta<D, T, Op>;
|
|
2297
|
+
};
|
|
1928
2298
|
/**
|
|
1929
2299
|
* The flat input to a singleton's `client.<type>.update(input)`: the {@link UpdateInput} plus the
|
|
1930
2300
|
* resource's `id`, which the request body must carry although the path has none. Take it from the
|
|
@@ -1967,12 +2337,18 @@ type AcceptedOf<D extends ApiDescriptor, T extends TypeName<D>, Op extends Accep
|
|
|
1967
2337
|
type AcceptedJob<D extends ApiDescriptor, A, J> = J extends {
|
|
1968
2338
|
jobType: infer JT extends string;
|
|
1969
2339
|
} ? JT extends TypeName<D> ? ReadResult<D, A, JT> : Readonly<Record<string, unknown>> : never;
|
|
2340
|
+
/** The top-level `meta` of the job document an accepted write's `202` declares, else the loose record. */
|
|
2341
|
+
type AcceptedMeta<J> = J extends {
|
|
2342
|
+
meta: infer P extends {
|
|
2343
|
+
fields: object;
|
|
2344
|
+
};
|
|
2345
|
+
} ? DocumentMeta<P> : Record<string, unknown> | undefined;
|
|
1970
2346
|
/**
|
|
1971
2347
|
* What write `Op` on type `T` resolves to without waiting: its result `R`, or, when it declares a
|
|
1972
2348
|
* `202`, `R` or an {@link Accepted} job whose poll resolves to the resource without the write's
|
|
1973
2349
|
* `include` or `fields`.
|
|
1974
2350
|
*/
|
|
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
|
|
2351
|
+
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
2352
|
/**
|
|
1977
2353
|
* The `wait` a caller may pass to write `Op` on type `T`: a boolean or {@link PollOptions} when it
|
|
1978
2354
|
* declares a `202`, else nothing.
|
|
@@ -1988,21 +2364,21 @@ type WaitedWriteResult<D extends ApiDescriptor, A, T extends TypeName<D>, Op ext
|
|
|
1988
2364
|
* accepted job and resolves to the created resource; without it the call may resolve to an
|
|
1989
2365
|
* {@link Accepted}.
|
|
1990
2366
|
*/
|
|
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
|
|
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
|
|
2367
|
+
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'>>> : {
|
|
2368
|
+
(input: CreateInput<D, W, T>, opts: WaitOptions & WriteMetaOption<D, T, 'create'>): Promise<ReadResult<D, A, T>>;
|
|
2369
|
+
<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
2370
|
wait?: false;
|
|
1995
|
-
}): Promise<WriteResult<D, A, T, 'create', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>>>;
|
|
2371
|
+
} & WriteMetaOption<D, T, 'create'>>): Promise<WriteResult<D, A, T, 'create', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'create'>>>>;
|
|
1996
2372
|
};
|
|
1997
2373
|
/**
|
|
1998
2374
|
* `client.<type>.id(id).update`, which takes `wait` as {@link CreateMethod} does. `I` is the input
|
|
1999
2375
|
* it takes: a singleton's update takes {@link SingletonUpdateInput}.
|
|
2000
2376
|
*/
|
|
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
|
|
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
|
|
2377
|
+
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'>>> : {
|
|
2378
|
+
(patch: I, opts: WaitOptions & WriteMetaOption<D, T, 'update'>): Promise<ReadResult<D, A, T>>;
|
|
2379
|
+
<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
2380
|
wait?: false;
|
|
2005
|
-
}): Promise<WriteResult<D, A, T, 'update', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>>>;
|
|
2381
|
+
} & WriteMetaOption<D, T, 'update'>>): Promise<WriteResult<D, A, T, 'update', WithDocumentMeta<ReadResult<D, A, T, Inc, F, Cnt[number]>, OperationMeta<D, T, 'update'>>>>;
|
|
2006
2382
|
};
|
|
2007
2383
|
/**
|
|
2008
2384
|
* The materialised positional result of a single atomic op handle:
|
|
@@ -2011,12 +2387,15 @@ type UpdateMethod<D extends ApiDescriptor, A, W, T extends TypeName<D>, I = Upda
|
|
|
2011
2387
|
* wrapping the materialised resource view of `T` (the same {@link ResourceObjectView} a
|
|
2012
2388
|
* standalone create/update read returns — `data` is typed, not `unknown`, plus the optional op
|
|
2013
2389
|
* `meta`);
|
|
2014
|
-
* - an {@link AtomicDeleteHandle} -> `undefined` (a remove carries no data)
|
|
2390
|
+
* - an {@link AtomicDeleteHandle} -> `undefined` (a remove carries no data);
|
|
2391
|
+
* - an {@link AtomicRelationshipHandle} for relation `R` of `T` -> the `AtomicResult` wrapping the
|
|
2392
|
+
* linkage the server answered with, as the relationship accessor's verbs return it, or
|
|
2393
|
+
* `undefined` data when it answered with an empty result.
|
|
2015
2394
|
*
|
|
2016
2395
|
* Drives the per-op positional typing of {@link AtomicResults} (the callback's returned tuple of
|
|
2017
2396
|
* handles maps to a tuple of these).
|
|
2018
2397
|
*/
|
|
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;
|
|
2398
|
+
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
2399
|
/** The custom actions declared on type `T` (the descriptor's `actions` block, or `{}`). */
|
|
2021
2400
|
type ActionsOf<D extends ApiDescriptor, T extends TypeName<D>> = D[T] extends {
|
|
2022
2401
|
actions: infer Acts;
|
|
@@ -2065,7 +2444,7 @@ type ActionValue<D extends ApiDescriptor, A, Act extends ActionDescriptor, E> =
|
|
|
2065
2444
|
/** The {@link Accepted} job of an action that declares a `202`, or `never`. */
|
|
2066
2445
|
type ActionAccepted<D extends ApiDescriptor, A, Act extends ActionDescriptor, E> = Act extends {
|
|
2067
2446
|
accepted: object;
|
|
2068
|
-
} ? Accepted<AcceptedJob<D, A, Act['accepted']>, ActionValue<D, A, Act, E>> : never;
|
|
2447
|
+
} ? Accepted<AcceptedJob<D, A, Act['accepted']>, ActionValue<D, A, Act, E>, AcceptedMeta<Act['accepted']>> : never;
|
|
2069
2448
|
/** The `wait` option of an action that declares a `202`; `unknown` (adding nothing) otherwise. */
|
|
2070
2449
|
type ActionWaitOption<Act> = Act extends {
|
|
2071
2450
|
accepted: object;
|
|
@@ -2142,6 +2521,8 @@ interface ActionCallOptions {
|
|
|
2142
2521
|
relatedQuery?: LooseRelatedQuery;
|
|
2143
2522
|
/** Poll a `202 Accepted` job until it's done, for an action that declares one. */
|
|
2144
2523
|
wait?: boolean | PollOptions;
|
|
2524
|
+
/** The request document's top-level `meta`, for an action whose request declares it. */
|
|
2525
|
+
meta?: Readonly<Record<string, unknown>>;
|
|
2145
2526
|
}
|
|
2146
2527
|
/** A filter key a collection action accepts (its `filterable` literal union), or `never`. */
|
|
2147
2528
|
type ActionFilterKey<Act> = Act extends {
|
|
@@ -2271,18 +2652,18 @@ type WithInput<D extends ApiDescriptor, W, Act, E> = Act extends {
|
|
|
2271
2652
|
*/
|
|
2272
2653
|
type ActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescriptor, E> = Act extends {
|
|
2273
2654
|
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
|
|
2655
|
+
} ? <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
2656
|
signal?: AbortSignal;
|
|
2276
2657
|
contentType?: C;
|
|
2277
|
-
} & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act
|
|
2658
|
+
} & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
|
|
2278
2659
|
rawOutput: readonly RawOutputMedia[];
|
|
2279
2660
|
} ? Act extends {
|
|
2280
2661
|
input: 'none';
|
|
2281
|
-
} ? <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(options
|
|
2662
|
+
} ? <const M extends AcceptOf<Act> = Extract<DefaultAccept<Act>, AcceptOf<Act>>, RT extends BinaryResponseType = 'blob'>(...options: ActionOptionsArg<Act, {
|
|
2282
2663
|
signal?: AbortSignal;
|
|
2283
|
-
} & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act
|
|
2664
|
+
} & 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
2665
|
signal?: AbortSignal;
|
|
2285
|
-
} & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act
|
|
2666
|
+
} & ResponseOptions<Act, M, RT> & ActionQueryOptions<D, Act> & ActionWaitOption<Act>>) => ActionResultIn<D, A, Act, E, M, RT> : Act extends {
|
|
2286
2667
|
accepted: object;
|
|
2287
2668
|
} ? AcceptedActionMethod<D, A, W, Act, E> : Act extends {
|
|
2288
2669
|
filterable: readonly string[];
|
|
@@ -2290,13 +2671,15 @@ type ActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescriptor, E
|
|
|
2290
2671
|
filterFamilies: readonly unknown[];
|
|
2291
2672
|
} | {
|
|
2292
2673
|
relatedQuery: true;
|
|
2674
|
+
} | {
|
|
2675
|
+
requestMeta: object;
|
|
2293
2676
|
} ? Act extends {
|
|
2294
2677
|
input: 'none';
|
|
2295
|
-
} ? (options
|
|
2678
|
+
} ? (...options: ActionOptionsArg<Act, {
|
|
2296
2679
|
signal?: AbortSignal;
|
|
2297
|
-
} & ActionQueryOptions<D, Act
|
|
2680
|
+
} & ActionQueryOptions<D, Act>>) => ActionResult<D, A, Act, E> : (input: WithInput<D, W, Act, E>, ...options: ActionOptionsArg<Act, {
|
|
2298
2681
|
signal?: AbortSignal;
|
|
2299
|
-
} & ActionQueryOptions<D, Act
|
|
2682
|
+
} & ActionQueryOptions<D, Act>>) => ActionResult<D, A, Act, E> : Act extends {
|
|
2300
2683
|
input: 'none';
|
|
2301
2684
|
} ? () => ActionResult<D, A, Act, E> : (input: WithInput<D, W, Act, E>) => ActionResult<D, A, Act, E>;
|
|
2302
2685
|
/**
|
|
@@ -2308,20 +2691,33 @@ type AcceptedActionMethod<D extends ApiDescriptor, A, W, Act extends ActionDescr
|
|
|
2308
2691
|
} ? {
|
|
2309
2692
|
(options: {
|
|
2310
2693
|
signal?: AbortSignal;
|
|
2311
|
-
} & ActionQueryOptions<D, Act> & WaitOptions): Promise<ActionValue<D, A, Act, E>>;
|
|
2312
|
-
(options
|
|
2694
|
+
} & ActionQueryOptions<D, Act> & WaitOptions & ActionMetaOption<Act>): Promise<ActionValue<D, A, Act, E>>;
|
|
2695
|
+
(...options: ActionOptionsArg<Act, {
|
|
2313
2696
|
signal?: AbortSignal;
|
|
2314
2697
|
wait?: false;
|
|
2315
|
-
} & ActionQueryOptions<D, Act
|
|
2698
|
+
} & ActionQueryOptions<D, Act>>): ActionResult<D, A, Act, E>;
|
|
2316
2699
|
} : {
|
|
2317
2700
|
(input: WithInput<D, W, Act, E>, options: {
|
|
2318
2701
|
signal?: AbortSignal;
|
|
2319
|
-
} & ActionQueryOptions<D, Act> & WaitOptions): Promise<ActionValue<D, A, Act, E>>;
|
|
2320
|
-
(input: WithInput<D, W, Act, E>, options
|
|
2702
|
+
} & ActionQueryOptions<D, Act> & WaitOptions & ActionMetaOption<Act>): Promise<ActionValue<D, A, Act, E>>;
|
|
2703
|
+
(input: WithInput<D, W, Act, E>, ...options: ActionOptionsArg<Act, {
|
|
2321
2704
|
signal?: AbortSignal;
|
|
2322
2705
|
wait?: false;
|
|
2323
|
-
} & ActionQueryOptions<D, Act
|
|
2706
|
+
} & ActionQueryOptions<D, Act>>): ActionResult<D, A, Act, E>;
|
|
2324
2707
|
};
|
|
2708
|
+
/** The top-level `meta` an action's request document declares, or `never`. */
|
|
2709
|
+
type ActionRequestMeta<Act> = Act extends {
|
|
2710
|
+
requestMeta: infer P extends {
|
|
2711
|
+
fields: object;
|
|
2712
|
+
};
|
|
2713
|
+
} ? MetaObject<P> : never;
|
|
2714
|
+
/**
|
|
2715
|
+
* The `meta` option of an action whose request document declares it, required when a member is;
|
|
2716
|
+
* `unknown` (adding nothing) for one that declares none.
|
|
2717
|
+
*/
|
|
2718
|
+
type ActionMetaOption<Act> = [ActionRequestMeta<Act>] extends [never] ? unknown : MetaOption<ActionRequestMeta<Act>>;
|
|
2719
|
+
/** An action's options argument: `O` and its `meta`, required when the action must send `meta`. */
|
|
2720
|
+
type ActionOptionsArg<Act, O> = OptionsArg<RequiresRequestMeta<ActionRequestMeta<Act>>, O & ActionMetaOption<Act>>;
|
|
2325
2721
|
/**
|
|
2326
2722
|
* The typed map of a type's custom actions at one scope (`collection` on the
|
|
2327
2723
|
* {@link TypeAccessor}, `resource` on the {@link ResourceHandle}). Each entry is an
|
|
@@ -2342,8 +2738,12 @@ type ResourceHandle<D extends ApiDescriptor, A, W, T extends TypeName<D>, Act =
|
|
|
2342
2738
|
readonly type: T;
|
|
2343
2739
|
readonly id: string;
|
|
2344
2740
|
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>;
|
|
2346
|
-
|
|
2741
|
+
update: UpdateMethod<D, A, W, T>;
|
|
2742
|
+
/**
|
|
2743
|
+
* Resolves to the `meta` of the meta-only `200` the delete declares, else `undefined`. A delete
|
|
2744
|
+
* whose request document declares its `meta` takes it in the options.
|
|
2745
|
+
*/
|
|
2746
|
+
delete(...opts: DeleteArgs<D, T>): Promise<DeleteResult<D, T>>;
|
|
2347
2747
|
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
2748
|
readonly actions: ActionsAccessor<D, A, W, T, 'resource', Act>;
|
|
2349
2749
|
} & RelationshipAccessors<D, A, T>;
|
|
@@ -2680,14 +3080,23 @@ interface WireResource {
|
|
|
2680
3080
|
id?: string;
|
|
2681
3081
|
[key: string]: unknown;
|
|
2682
3082
|
}
|
|
3083
|
+
/**
|
|
3084
|
+
* What the request a resource answered tells a validator. `fields` is the sparse fieldset the
|
|
3085
|
+
* request sent for the resource's type, `fields[type]`, absent when it sent none.
|
|
3086
|
+
*/
|
|
3087
|
+
interface ValidationContext {
|
|
3088
|
+
readonly fields?: readonly string[];
|
|
3089
|
+
}
|
|
2683
3090
|
/**
|
|
2684
3091
|
* The opt-in per-resource validator: validate one wire `resource` against its JSON `schema`
|
|
2685
3092
|
* (the bundle's per-type resource-object schema). The engine is the user's — throw (or
|
|
2686
3093
|
* aggregate-then-throw) on an invalid resource; return for a valid one. With the bare-function
|
|
2687
3094
|
* seam form there is no per-type schema, so `schema` is `undefined` and the function owns the
|
|
2688
|
-
* whole decision.
|
|
3095
|
+
* whole decision. With the schema-driven form, `schema` is already relaxed for the request's
|
|
3096
|
+
* sparse fieldset (see {@link sparseSchema}). `context` carries that fieldset either way, so a
|
|
3097
|
+
* bare validator can relax its own schema.
|
|
2689
3098
|
*/
|
|
2690
|
-
type Validator = (resource: WireResource, schema: unknown) => void;
|
|
3099
|
+
type Validator = (resource: WireResource, schema: unknown, context?: ValidationContext) => void;
|
|
2691
3100
|
/** A per-type JSON Schema map (the codegen-emitted `schemas` constant), keyed by JSON:API type. */
|
|
2692
3101
|
type SchemaMap = Readonly<Record<string, unknown>>;
|
|
2693
3102
|
/**
|
|
@@ -2705,9 +3114,12 @@ interface ValidationConfig {
|
|
|
2705
3114
|
* `undefined`). Absent => no per-field validation (zero overhead, no engine dependency).
|
|
2706
3115
|
*/
|
|
2707
3116
|
type ValidationOption = ValidationConfig | Validator;
|
|
2708
|
-
/**
|
|
3117
|
+
/**
|
|
3118
|
+
* A normalised validator: resolve a resource's schema (or `undefined`) and validate it. `fields`
|
|
3119
|
+
* is the request's sparse fieldset for the resource's type, when it sent one.
|
|
3120
|
+
*/
|
|
2709
3121
|
interface ResolvedValidator {
|
|
2710
|
-
validate(resource: WireResource): void;
|
|
3122
|
+
validate(resource: WireResource, fields?: readonly string[]): void;
|
|
2711
3123
|
}
|
|
2712
3124
|
/**
|
|
2713
3125
|
* Normalise the `validate?` option to a single per-resource validator. The config form looks the
|
|
@@ -2716,6 +3128,21 @@ interface ResolvedValidator {
|
|
|
2716
3128
|
* delegating the whole decision to the caller. Returns `undefined` when validation is off.
|
|
2717
3129
|
*/
|
|
2718
3130
|
declare function resolveValidator(option: ValidationOption | undefined): ResolvedValidator | undefined;
|
|
3131
|
+
/**
|
|
3132
|
+
* A cache of {@link sparseSchema} results, by schema and fieldset, so each pair is relaxed once.
|
|
3133
|
+
* A schema with no fieldset comes back as it is.
|
|
3134
|
+
*/
|
|
3135
|
+
declare function sparseSchemas(): (schema: unknown, fields: readonly string[] | undefined) => unknown;
|
|
3136
|
+
/**
|
|
3137
|
+
* A resource object schema relaxed for a response to a request whose sparse fieldset for the type
|
|
3138
|
+
* named `members`. An attribute or relation the fieldset leaves out is no longer required, and an
|
|
3139
|
+
* attribute it narrows to some of its keys, such as `address.city`, `location.geo.lat` or
|
|
3140
|
+
* `lines.*.sku`, requires only the keys selected at each level along those paths. A member the
|
|
3141
|
+
* fieldset also lists whole is left as declared, as the server renders it whole. Everything else
|
|
3142
|
+
* in the schema is kept, so a selected value is still checked, but for its `$id`: the copy is a
|
|
3143
|
+
* schema of its own.
|
|
3144
|
+
*/
|
|
3145
|
+
declare function sparseSchema(schema: unknown, members: readonly string[]): unknown;
|
|
2719
3146
|
/**
|
|
2720
3147
|
* The light structural guards every parsed response passes through (ADR 0004): assert the body
|
|
2721
3148
|
* is a JSON:API document and that each `data`/`included` member carries a string `type` (and,
|
|
@@ -2734,7 +3161,7 @@ declare function assertJsonApiDocument(body: unknown): asserts body is Document;
|
|
|
2734
3161
|
* against its per-type schema. Called only when a validator is configured (off by default). The
|
|
2735
3162
|
* structural guards have already proven each member carries `type`+`id`, so the cast is sound.
|
|
2736
3163
|
*/
|
|
2737
|
-
declare function validateDocument(body: Document, validator: ResolvedValidator): void;
|
|
3164
|
+
declare function validateDocument(body: Document, validator: ResolvedValidator, fields?: Readonly<Record<string, readonly string[]>>): void;
|
|
2738
3165
|
//#endregion
|
|
2739
|
-
export {
|
|
2740
|
-
//# sourceMappingURL=validate-
|
|
3166
|
+
export { DocumentMeta as $, LinkObject as $n, PaginatorStrategy 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, PaginatorRole 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, PaginatorDescriptor as Xr, ResourceCountToken as Xt, DefaultAttributes as Y, DocumentEnvelope as Yn, OperationExamples as Yr, ResourceAccessors as Yt, DeleteArgs as Z, EdgeEnvelope as Zn, PaginatorKind as Zr, ResourceHandle as Zt, RawResponseType as _, WaitedWriteResult as _n, PageOf as _r, LooseRelatedQueryEntry as _t, ValidationOption as a, RelationDescriptor 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, ResourceCountOperation as ci, TypeAccessor as cn, relatedPaginatorKind as cr, IncludePath as ct, sparseSchemas as d, ResourceMetaDescriptor as di, TypedRelatedReadQuery as dn, CANONICAL_PAGE_KEYS as dr, IncludedType as dt, PivotDescriptor as ei, ResourceWriteMeta as en, MaterialiseContext as er, EdgeMembers as et, validateDocument as f, SortFamilyDescriptor 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, WaitOptions as hn, PageLinks as hr, ListPageParams as ht, ValidationContext as i, RelatedQueryOperation 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, ResourceDescriptor as li, TypeName as ln, NestedFieldset as lr, IncludedRelations as lt, ExecutedResponse as m, isPolymorphic as mi, UpdateMethod as mn, PageKeys as mr, ListFilterMember as mt, SchemaMap as n, RawOutputMedia as ni, SingleReadQuery as nn, RelationArrayEnvelope as nr, FieldSelectionMap as nt, Validator as o, RelationMutations as oi, SortToken as on, materialise as or, HydratedMember as ot, Document as p, StrategyDescriptor 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, RelatedQueryDescriptor as ri, SingletonAccessor as rn, RelationView as rr, FieldsMap as rt, WireResource as s, RequestMetaOperation as si, TakesVerb as sn, relatedPaginator as sr, IdentifierMember as st, ResolvedValidator as t, RawMediaKind as ti, ResourceWriteOperation as tn, NavigateOptions as tr, ErrorCodeOf as tt, sparseSchema as u, ResourceExamples 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 };
|
|
3167
|
+
//# sourceMappingURL=validate-CMy8mJD2.d.cts.map
|