@haddowg/json-api-client 1.28.0 → 1.30.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/dist/ajv.cjs +1 -1
- package/dist/ajv.d.cts +1 -1
- package/dist/ajv.d.mts +1 -1
- package/dist/ajv.mjs +1 -1
- package/dist/index.cjs +280 -23
- package/dist/index.d.cts +35 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +35 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +273 -24
- package/dist/index.mjs.map +1 -1
- package/dist/{validate-DMRQn0XN.cjs → validate-B2Dtn9dI.cjs} +14 -1
- package/dist/{validate-BvO7NhkT.mjs → validate-CtXB1MGk.mjs} +15 -2
- package/dist/validate-CtXB1MGk.mjs.map +1 -0
- package/dist/{validate-Dj6pkoNM.d.mts → validate-ugcQVpb0.d.cts} +261 -50
- package/dist/validate-ugcQVpb0.d.cts.map +1 -0
- package/dist/{validate-Dj6pkoNM.d.cts → validate-ugcQVpb0.d.mts} +261 -50
- package/dist/validate-ugcQVpb0.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/validate-BvO7NhkT.mjs.map +0 -1
- package/dist/validate-Dj6pkoNM.d.cts.map +0 -1
- package/dist/validate-Dj6pkoNM.d.mts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as DeleteResult, $n as MaterialiseContext, $r as ApiExamples, $t as ResourceAccessors, A as TransportResponse, Ai as StrategyDescriptor, An as readActionLocation, Ar as PageMeta, At as ReadAttributesOf, B as Client, Bn as AtomicRelationshipRecorder, Br as PollOptions, Bt as RelatedReadRelatedQuery, C as ClientOptions, Ci as RelationMutations, Cn as WithLinks, Cr as NestedFieldset, Ct as MutationMetaOf, D as JsonApiTransport, Di as ResourceExamples, Dn as WriteResult, Dr as Page, Dt as OptionsArg, E as createClient, Ei as ResourceDescriptor, En as WritePivotOf, Er as ExactPageParams, Et as OperationMeta, F as ActionCallOptions, Fn as AtomicOperationArgs, Fr as TypedPage, Ft as RelatedMeta, G as CountedRelationName, Gn as runAtomic, Gr as AcceptedOperation, Gt as RelationPaginator, H as CollectionMeta, Hn as AtomicResults, Hr as isAccepted, Ht as RelationFilterQuery, I as ActionsAccessor, In as AtomicRecorder, Ir as nextPageParams, It as RelatedQuery, J as CreateMethod, Jn as Edge, Jr as ActionLocationDescriptor, Jt as RelationSortQuery, K as CreateAttributesOf, Kn as ArrayEnvelope, Kr as ActionDescriptor, Kt as RelationReadQuery, L as AtomicResultOf, Ln as AtomicRef, Lr as prevPageParams, Lt as RelatedQueryEntry, M as AcceptedJob, Mn as AtomicCreateInput, Mr as PageParams, Mt as ReadableRelationName, N as AcceptedMeta, Nn as AtomicDeleteHandle, Nr as PageParamsOf, Nt as RelatedIncludedResource, O as TransportRawBody, Oi as ResourceMetaDescriptor, On as ActionLocation, Or as PageKeys, Ot as PivotFieldsOf, P as AcceptedOf, Pn as AtomicHandle, Pr as ResolvedPaginator, Pt as RelatedIncludedType, Q as DeleteArgs, Qn as LinkObject, Qr as ApiDescriptor, Qt as RequiresRequestMeta, R as BinaryBody, Rn as AtomicRelationshipArgs, Rr as resolvePaginator, Rt as RelatedQueryParam, S as serializeQuery, Si as RelationDescriptor, Sn as WithDocumentMeta, Sr as mediaType, St as MetaOption, T as HeadersInit, Ti as ResourceCountOperation, Tn as WriteOptions, Tr as CANONICAL_PAGE_KEYS, Tt as NestedFieldsetMember, U as CountAccessor, Un as AtomicUpdateHandle, Ur as parseRetryAfter, Ut as RelationName, V as Collection, Vn as AtomicResult, Vr as PollTimeoutError, Vt as RelationCollection, W as CountToken, Wn as AtomicUpdateInput, Wr as AcceptedDescriptor, Wt as RelationPageParams, X as DefaultAttributes, Xn as EdgeMember, Xr as ActionScope, Xt as RelationshipMembers, Y as DefaultActionTypes, Yn as EdgeEnvelope, Yr as ActionOutput, Yt as RelationshipAccessor, Z as DefaultWriteAttributes, Zn as Link, Zr as AdditionalMembersDescriptor, Zt as RequestMetaOf, _ as RawResponseType, _i as PivotDescriptor, _n as UpdateInput, _r as ATOMIC_MEDIA_TYPE, _t as LooseRelatedQuery, a as ValidationOption, ai as DocumentMetaOperation, an as ResourceWriteOperation, ar as RelationArrayEnvelope, at as FilterKey, b as executeRaw, bi as RelatedQueryDescriptor, bn as WaitValue, br as MediaTypeParams, bt as MemberTypeOf, c as assertJsonApiDocument, ci as InputMediaKind, cn as SingletonUpdateInput, cr as ResourceLinks, ct as IdentifierMember, d as sparseSchemas, di as MetaLiteral, dn as TakesVerb, dr as isMaterialised, dt as IncludedResource, ei as AtomicDescriptor, en as ResourceCountToken, er as MaterialisedOverlay, et as DocumentMeta, f as validateDocument, fi as OperationExamples, fn as TypeAccessor, fr as materialise, ft as IncludedType, g as JsonApiRequest, gi as PaginatorStrategy, gn as TypedRelationReadQuery, gr as ATOMIC_EXT, gt as ListPageParams, h as JsonApiContext, hi as PaginatorRole, hn as TypedRelatedReadQuery, hr as setMaterialisedOverlay, ht as ListFilterMember, i as ValidationContext, ii as DocumentMetaDescriptor, in as ResourceWriteMeta, ir as PendingPlacement, it as FieldsMap, j as fetchTransport, ji as isPolymorphic, jn as AtomicCreateHandle, jr as PageOf, jt as ReadResult, k as TransportRequest, ki as SortFamilyDescriptor, kn as isActionLocation, kr as PageLinks, kt as PivotInput, l as resolveValidator, li as MediaExamples, ln as SortQuery, lr as edgeViewOf, lt as IncludePath, m as ExecutedResponse, mi as PaginatorKind, mn as TypedReadQuery, mr as relatedPaginatorKind, mt as LinkageRef, n as SchemaMap, ni as ClientIdPolicy, nn as ResourceMetaOf, nr as PendingCreate, nt as ErrorCodeOf, o as Validator, oi as FilterFamilyDescriptor, on as SingleReadQuery, or as RelationView, ot as FilterQuery, p as Document, pi as PaginatorDescriptor, pn as TypeName, pr as relatedPaginator, pt as IsSingleton, q as CreateInput, qn as DocumentEnvelope, qr as ActionInput, qt as RelationRequestMetaOf, r as ValidationConfig, ri as CountableDescriptor, rn as ResourceObjectView, rr as PendingMember, rt as FieldSelectionMap, s as WireResource, si as InputMedia, sn as SingletonAccessor, sr as ResourceEnvelope, st as HydratedMember, t as ResolvedValidator, ti as Cardinality, tn as ResourceHandle, tr as NavigateOptions, tt as EdgeMembers, u as sparseSchema, ui as MenuDescriptor, un as SortToken, ur as identifierViewOf, ut as IncludedRelations, v as ReadQuery, vi as RawMediaKind, vn as UpdateMethod, vr as JSON_API_MEDIA_TYPE, vt as LooseRelatedQueryEntry, w as HANDLE_RESERVED, wi as RequestMetaOperation, wn as WritableRelationName, wr as nestedFieldset, wt as MutationVerb, x as executeResponse, xi as RelatedQueryOperation, xn as WaitedWriteResult, xr as ResourceIdentifier, xt as MetaObject, y as execute, yi as RawOutputMedia, yn as WaitOptions, yr as LocalIdentifier, yt as MemberName, z as BinaryResponseType, zn as AtomicRelationshipHandle, zr as Accepted, zt as RelatedQueryRelation } from "./validate-ugcQVpb0.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/errors.d.ts
|
|
4
4
|
/**
|
|
@@ -146,6 +146,39 @@ interface LoadAllOptions {
|
|
|
146
146
|
*/
|
|
147
147
|
declare function loadAll<T>(first: Collection<T> | PromiseLike<Collection<T>>, options?: LoadAllOptions): Promise<T[]>;
|
|
148
148
|
//#endregion
|
|
149
|
+
//#region src/request-stamp.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* Request stamps: when the request behind a result started, relative to every other request made in
|
|
152
|
+
* this process.
|
|
153
|
+
*
|
|
154
|
+
* The client takes a stamp as each request starts and records it on the top-level value it
|
|
155
|
+
* materialises from the response: a read's resource, collection or linkage (`$next()`/`$prev()`
|
|
156
|
+
* pages included), a write's returned resource, and an atomic batch's results. A cache can then
|
|
157
|
+
* tell which of two results carrying the same resource is the newer, whatever order their
|
|
158
|
+
* responses arrived in.
|
|
159
|
+
*
|
|
160
|
+
* The stamp is a per-process counter rather than `Date.now()`: two requests started in the same
|
|
161
|
+
* millisecond still get distinct, ordered stamps, and a clock change can't reorder them. It means
|
|
162
|
+
* nothing outside the process that issued it, so a value that crossed one (through JSON on a server
|
|
163
|
+
* render, or storage) carries none. Stamps live in a `WeakMap` keyed by the result, so the result
|
|
164
|
+
* keeps its shape and nothing is added to it.
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* A new stamp, later than every stamp handed out before it. The client takes one as each request
|
|
170
|
+
* starts; anything ordering its own events against the client's requests takes them here too.
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
declare function nextRequestStamp(): number;
|
|
174
|
+
/**
|
|
175
|
+
* The stamp of the request `value` was materialised from: a top-level result the client returned.
|
|
176
|
+
* `undefined` for anything else, such as a plain copy of a result, a nested resource, or data the
|
|
177
|
+
* client never returned.
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
declare function requestStampOf(value: unknown): number | undefined;
|
|
181
|
+
//#endregion
|
|
149
182
|
//#region src/serialize-write.d.ts
|
|
150
183
|
/**
|
|
151
184
|
* A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
|
|
@@ -299,5 +332,5 @@ declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDes
|
|
|
299
332
|
hasPivot: boolean;
|
|
300
333
|
} | undefined): JsonApiError;
|
|
301
334
|
//#endregion
|
|
302
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedMeta, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, AdditionalMembersDescriptor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicOperationArgs, AtomicRecorder, AtomicRef, AtomicRelationshipArgs, AtomicRelationshipHandle, AtomicRelationshipRecorder, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CollectionMeta, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, DeleteArgs, DeleteResult, Document, DocumentEnvelope, DocumentMeta, DocumentMetaDescriptor, DocumentMetaOperation, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, ExecutedResponse, FieldSelectionMap, FieldsMap, FilterFamilyDescriptor, FilterKey, FilterQuery, FilterSpec, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, IncludedResource, IncludedType, InputMedia, InputMediaKind, IsSingleton, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListFilterMember, ListPageParams, LoadAllOptions, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, MetaLiteral, MetaObject, MetaOption, MutationMetaOf, MutationVerb, NavigateOptions, type NestedFieldset, NestedFieldsetMember, OperationExamples, OperationMeta, OptionsArg, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedMeta, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationRequestMetaOf, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, RelationshipMembers, RequestMetaOf, RequestMetaOperation, RequiresRequestMeta, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceMetaDescriptor, ResourceMetaOf, ResourceObjectView, ResourceWriteMeta, ResourceWriteOperation, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, TakesVerb, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationContext, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithDocumentMeta, WithLinks, WritableRelationName, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, nestedFieldset, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, sparseSchema, sparseSchemas, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedDocumentMetaPaths, withRemappedPaths, withRemappedRelationshipPaths, withTopLevelMeta };
|
|
335
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedMeta, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, AdditionalMembersDescriptor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicOperationArgs, AtomicRecorder, AtomicRef, AtomicRelationshipArgs, AtomicRelationshipHandle, AtomicRelationshipRecorder, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CollectionMeta, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateAttributesOf, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, DeleteArgs, DeleteResult, Document, DocumentEnvelope, DocumentMeta, DocumentMetaDescriptor, DocumentMetaOperation, Edge, EdgeEnvelope, EdgeMember, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, ExecutedResponse, FieldSelectionMap, FieldsMap, FilterFamilyDescriptor, FilterKey, FilterQuery, FilterSpec, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, IncludedResource, IncludedType, InputMedia, InputMediaKind, IsSingleton, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListFilterMember, ListPageParams, LoadAllOptions, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MaterialisedOverlay, MediaExamples, MediaTypeParams, MemberName, MemberTypeOf, MenuDescriptor, MetaLiteral, MetaObject, MetaOption, MutationMetaOf, MutationVerb, NavigateOptions, type NestedFieldset, NestedFieldsetMember, OperationExamples, OperationMeta, OptionsArg, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PendingCreate, PendingMember, PendingPlacement, PivotDescriptor, PivotFieldsOf, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadAttributesOf, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedMeta, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationRequestMetaOf, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, RelationshipMembers, RequestMetaOf, RequestMetaOperation, RequiresRequestMeta, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceMetaDescriptor, ResourceMetaOf, ResourceObjectView, ResourceWriteMeta, ResourceWriteOperation, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, TakesVerb, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationContext, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithDocumentMeta, WithLinks, WritableRelationName, WriteDocument, WriteOptions, WritePivotOf, WriteResult, assertJsonApiDocument, createClient, edgeViewOf, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, identifierViewOf, isAccepted, isActionLocation, isMaterialised, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, nestedFieldset, nextPageParams, nextRequestStamp, parseRetryAfter, prevPageParams, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, requestStampOf, resolvePaginator, resolveValidator, runAtomic, serializeQuery, setMaterialisedOverlay, sparseSchema, sparseSchemas, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedDocumentMetaPaths, withRemappedPaths, withRemappedRelationshipPaths, withTopLevelMeta };
|
|
303
336
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/filters.ts","../src/load-all.ts","../src/serialize-write.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA,GAAO,CAAA;EACP,KAAA;EACA,MAAA;EACA,MAAA;IAAW,OAAA;IAAkB,SAAA;IAAoB,MAAA;EAAA;EACjD,IAAA,GAAO,MAAM;EAAN;;;;AAYA;EANP,IAAA;EAgBgC;;;;;EAVhC,OAAA;AAAA;AAW2B;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/filters.ts","../src/load-all.ts","../src/request-stamp.ts","../src/serialize-write.ts"],"mappings":"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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,71 @@
|
|
|
1
|
-
import { a as validateDocument, c as JsonApiError, d as hasErrorCode, i as sparseSchemas, l as StructuralGuardError, n as resolveValidator, o as fieldsOfUrl, r as sparseSchema, s as nestedFieldset, t as assertJsonApiDocument, u as findError } from "./validate-
|
|
1
|
+
import { a as validateDocument, c as JsonApiError, d as hasErrorCode, i as sparseSchemas, l as StructuralGuardError, n as resolveValidator, o as fieldsOfUrl, r as sparseSchema, s as nestedFieldset, t as assertJsonApiDocument, u as findError } from "./validate-CtXB1MGk.mjs";
|
|
2
|
+
//#region src/request-stamp.ts
|
|
3
|
+
/**
|
|
4
|
+
* Request stamps: when the request behind a result started, relative to every other request made in
|
|
5
|
+
* this process.
|
|
6
|
+
*
|
|
7
|
+
* The client takes a stamp as each request starts and records it on the top-level value it
|
|
8
|
+
* materialises from the response: a read's resource, collection or linkage (`$next()`/`$prev()`
|
|
9
|
+
* pages included), a write's returned resource, and an atomic batch's results. A cache can then
|
|
10
|
+
* tell which of two results carrying the same resource is the newer, whatever order their
|
|
11
|
+
* responses arrived in.
|
|
12
|
+
*
|
|
13
|
+
* The stamp is a per-process counter rather than `Date.now()`: two requests started in the same
|
|
14
|
+
* millisecond still get distinct, ordered stamps, and a clock change can't reorder them. It means
|
|
15
|
+
* nothing outside the process that issued it, so a value that crossed one (through JSON on a server
|
|
16
|
+
* render, or storage) carries none. Stamps live in a `WeakMap` keyed by the result, so the result
|
|
17
|
+
* keeps its shape and nothing is added to it.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
/** The last stamp handed out; `0` is older than any request (no request is ever stamped `0`). */
|
|
22
|
+
let clock = 0;
|
|
23
|
+
/**
|
|
24
|
+
* A new stamp, later than every stamp handed out before it. The client takes one as each request
|
|
25
|
+
* starts; anything ordering its own events against the client's requests takes them here too.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function nextRequestStamp() {
|
|
29
|
+
clock += 1;
|
|
30
|
+
return clock;
|
|
31
|
+
}
|
|
32
|
+
const stamps = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
/**
|
|
34
|
+
* Record `stamp` as the start of the request `value` was materialised from, when it is an object.
|
|
35
|
+
* Returns `value`.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
function stampRequest(value, stamp) {
|
|
39
|
+
if (typeof value === "object" && value !== null) stamps.set(value, stamp);
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
const documentStamps = /* @__PURE__ */ new WeakMap();
|
|
43
|
+
/**
|
|
44
|
+
* Record `stamp` on the response document it was parsed from, so whatever is built from the
|
|
45
|
+
* document can be stamped without the caller carrying the number.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function stampDocument(doc, stamp) {
|
|
49
|
+
if (doc !== void 0) documentStamps.set(doc, stamp);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Stamp `value` with the request stamp of `doc`, when `doc` carries one. Returns `value`.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
function stampFromDocument(doc, value) {
|
|
56
|
+
const stamp = doc === void 0 ? void 0 : documentStamps.get(doc);
|
|
57
|
+
return stamp === void 0 ? value : stampRequest(value, stamp);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The stamp of the request `value` was materialised from: a top-level result the client returned.
|
|
61
|
+
* `undefined` for anything else, such as a plain copy of a result, a nested resource, or data the
|
|
62
|
+
* client never returned.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
function requestStampOf(value) {
|
|
66
|
+
return typeof value === "object" && value !== null ? stamps.get(value) : void 0;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
2
69
|
//#region src/types.ts
|
|
3
70
|
/** The JSON:API media type. */
|
|
4
71
|
const JSON_API_MEDIA_TYPE = "application/vnd.api+json";
|
|
@@ -107,7 +174,10 @@ function serializeQuery(query, isListFilter, isRelatedListFilter) {
|
|
|
107
174
|
* parsed error objects (tolerating a non-JSON error body with an empty list).
|
|
108
175
|
*/
|
|
109
176
|
async function execute(ctx, req) {
|
|
110
|
-
|
|
177
|
+
const stamp = nextRequestStamp();
|
|
178
|
+
const doc = parseDocument((await send(ctx, req)).body);
|
|
179
|
+
stampDocument(doc, stamp);
|
|
180
|
+
return doc;
|
|
111
181
|
}
|
|
112
182
|
/**
|
|
113
183
|
* Execute a request as {@link execute} does, keeping the response's status and headers. With
|
|
@@ -115,11 +185,15 @@ async function execute(ctx, req) {
|
|
|
115
185
|
* so the caller can read its `Location`.
|
|
116
186
|
*/
|
|
117
187
|
async function executeResponse(ctx, req, seeOther = false) {
|
|
188
|
+
const stamp = nextRequestStamp();
|
|
118
189
|
const res = await send(ctx, req, void 0, seeOther);
|
|
190
|
+
const document = res.status === 303 ? void 0 : parseDocument(res.body);
|
|
191
|
+
stampDocument(document, stamp);
|
|
119
192
|
return {
|
|
120
193
|
status: res.status,
|
|
121
194
|
headers: res.headers,
|
|
122
|
-
document
|
|
195
|
+
document,
|
|
196
|
+
stamp
|
|
123
197
|
};
|
|
124
198
|
}
|
|
125
199
|
async function executeRaw(ctx, req, as) {
|
|
@@ -365,6 +439,40 @@ function resolvePaginator(paginator, page) {
|
|
|
365
439
|
arm
|
|
366
440
|
};
|
|
367
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* The `page` params for the page after `list`, read from its `next` link, or `undefined` on the
|
|
444
|
+
* last page (or before anything has loaded). Works the same for every strategy, because the
|
|
445
|
+
* server's link already carries the right parameters: counts come back as numbers, cursors as
|
|
446
|
+
* strings, under the wire keys the strategy uses, with the menu arm's `kind` when the link names
|
|
447
|
+
* one. Feed the result back as the `page` of the next read:
|
|
448
|
+
*
|
|
449
|
+
* ```ts
|
|
450
|
+
* const next = nextPageParams(albums)
|
|
451
|
+
* if (next) albums = await client.albums.list({ page: next })
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
function nextPageParams(list) {
|
|
455
|
+
return pageParams(list?.$page, list?.$page.links.next);
|
|
456
|
+
}
|
|
457
|
+
/** The `page` params for the page before `list`, from its `prev` link. See {@link nextPageParams}. */
|
|
458
|
+
function prevPageParams(list) {
|
|
459
|
+
return pageParams(list?.$page, list?.$page.links.prev);
|
|
460
|
+
}
|
|
461
|
+
const CURSOR_ROLES = ["after", "before"];
|
|
462
|
+
function pageParams(page, link) {
|
|
463
|
+
if (page === void 0 || link === void 0) return;
|
|
464
|
+
const keys = Object.entries(page.keys);
|
|
465
|
+
const query = link.includes("?") ? link.slice(link.indexOf("?") + 1).split("#")[0] : "";
|
|
466
|
+
const params = {};
|
|
467
|
+
new URLSearchParams(query).forEach((value, name) => {
|
|
468
|
+
const member = /^page\[([^\]]+)\]$/.exec(name)?.[1];
|
|
469
|
+
if (member === void 0) return;
|
|
470
|
+
const role = keys.find(([, key]) => key === member)?.[0];
|
|
471
|
+
const count = Number(value);
|
|
472
|
+
params[member] = role !== void 0 && !CURSOR_ROLES.includes(role) && value !== "" && Number.isFinite(count) ? count : value;
|
|
473
|
+
});
|
|
474
|
+
return params;
|
|
475
|
+
}
|
|
368
476
|
//#endregion
|
|
369
477
|
//#region src/materialise.ts
|
|
370
478
|
const isObject$2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -382,6 +490,59 @@ const defineGetter = (target, key, get) => {
|
|
|
382
490
|
configurable: true
|
|
383
491
|
});
|
|
384
492
|
};
|
|
493
|
+
let overlay;
|
|
494
|
+
/**
|
|
495
|
+
* Install the cache layer's {@link MaterialisedOverlay}, or remove it with `undefined`. One layer is
|
|
496
|
+
* installed at a time; without one, `$optimistic` is `undefined`, `$pending()` is empty and `$count`
|
|
497
|
+
* is the response's count.
|
|
498
|
+
*
|
|
499
|
+
* @internal
|
|
500
|
+
*/
|
|
501
|
+
function setMaterialisedOverlay(next) {
|
|
502
|
+
overlay = next;
|
|
503
|
+
}
|
|
504
|
+
const NO_IDENTIFIERS = Object.freeze([]);
|
|
505
|
+
const NO_CREATES = Object.freeze([]);
|
|
506
|
+
/** The value each per-edge view reads through to. */
|
|
507
|
+
const SOURCES = /* @__PURE__ */ new WeakMap();
|
|
508
|
+
/** The raw (response) count of each node's relations, by node. */
|
|
509
|
+
const RAW_COUNTS = /* @__PURE__ */ new WeakMap();
|
|
510
|
+
/** `target` followed by the values it reads through to, nearest first. */
|
|
511
|
+
function chainOf(target) {
|
|
512
|
+
const chain = [];
|
|
513
|
+
let at = target;
|
|
514
|
+
while (at !== void 0 && !chain.includes(at)) {
|
|
515
|
+
chain.push(at);
|
|
516
|
+
at = SOURCES.get(at);
|
|
517
|
+
}
|
|
518
|
+
return chain;
|
|
519
|
+
}
|
|
520
|
+
/** The raw count of relation `name` the first value in `chain` with one carries. */
|
|
521
|
+
function rawCount(chain, name) {
|
|
522
|
+
for (const value of chain) {
|
|
523
|
+
const count = RAW_COUNTS.get(value);
|
|
524
|
+
if (count !== void 0) return count(name);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/** {@link rawCount} for the chain starting at `target`, without building the chain. */
|
|
528
|
+
function rawCountOf(target, name) {
|
|
529
|
+
let at = target;
|
|
530
|
+
while (at !== void 0) {
|
|
531
|
+
const count = RAW_COUNTS.get(at);
|
|
532
|
+
if (count !== void 0) return count(name);
|
|
533
|
+
at = SOURCES.get(at);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** Define the overlay-backed accessors (`$optimistic`, `$pending`, `$count`) of a resource value. */
|
|
537
|
+
function attachOverlayAccessors(target) {
|
|
538
|
+
defineGetter(target, "$optimistic", () => overlay?.optimistic(chainOf(target)));
|
|
539
|
+
define(target, "$pending", (name) => overlay?.pending(chainOf(target), name) ?? NO_IDENTIFIERS);
|
|
540
|
+
define(target, "$count", (name) => {
|
|
541
|
+
if (overlay === void 0) return rawCountOf(target, name);
|
|
542
|
+
const chain = chainOf(target);
|
|
543
|
+
return overlay.count(chain, name, rawCount(chain, name));
|
|
544
|
+
});
|
|
545
|
+
}
|
|
385
546
|
/** A relationship object's `meta.total` when it is a finite number, else `undefined`. */
|
|
386
547
|
const relationTotal = (rel) => {
|
|
387
548
|
const total = rel?.meta?.["total"];
|
|
@@ -413,6 +574,21 @@ const relationTotal = (rel) => {
|
|
|
413
574
|
* top-level collection read (statically-known); both override the sniff-from-`data[0]` fallback.
|
|
414
575
|
*/
|
|
415
576
|
function materialise(doc, ctx, linkage = false, primaryType, paginatorOverride) {
|
|
577
|
+
const value = materialiseDocument(doc, ctx, linkage, primaryType, paginatorOverride);
|
|
578
|
+
if (typeof value === "object" && value !== null) MATERIALISED.add(value);
|
|
579
|
+
return stampFromDocument(doc, value);
|
|
580
|
+
}
|
|
581
|
+
const MATERIALISED = /* @__PURE__ */ new WeakSet();
|
|
582
|
+
/**
|
|
583
|
+
* Whether `value` is a top-level result `materialise` built: a resource, a collection or a linkage
|
|
584
|
+
* value, including the pages `$next()` and `$prev()` re-materialise. A plain copy of one, such as
|
|
585
|
+
* data that went through `JSON.stringify` on a server and back, has lost its `$`-accessors and
|
|
586
|
+
* answers `false`, which is how a hydrated cache entry is told from a fresh read.
|
|
587
|
+
*/
|
|
588
|
+
function isMaterialised(value) {
|
|
589
|
+
return typeof value === "object" && value !== null && MATERIALISED.has(value);
|
|
590
|
+
}
|
|
591
|
+
function materialiseDocument(doc, ctx, linkage, primaryType, paginatorOverride) {
|
|
416
592
|
assertJsonApiDocument(doc);
|
|
417
593
|
if (ctx.validate !== void 0) validateDocument(doc, ctx.validate, ctx.fields);
|
|
418
594
|
const env = {};
|
|
@@ -494,7 +670,10 @@ function resolveMember(member, env, index, nodes, ctx, relationEdge) {
|
|
|
494
670
|
if (included) return buildEdgeView(buildNode(included, env, index, nodes, ctx), member, relationEdge);
|
|
495
671
|
return buildIdentifierView(member, relationEdge);
|
|
496
672
|
}
|
|
497
|
-
/**
|
|
673
|
+
/**
|
|
674
|
+
* Attach the resource-level `$`-accessors ($meta/$links/$self/$document/$raw/$nestedFieldset/$rel,
|
|
675
|
+
* and the overlay-backed $count/$optimistic/$pending).
|
|
676
|
+
*/
|
|
498
677
|
function attachResourceEnvelope(node, raw, env, rels, selection) {
|
|
499
678
|
defineGetter(node, "$meta", () => raw.meta);
|
|
500
679
|
defineGetter(node, "$links", () => raw.links);
|
|
@@ -511,7 +690,8 @@ function attachResourceEnvelope(node, raw, env, rels, selection) {
|
|
|
511
690
|
if (rel.meta !== void 0) view.meta = rel.meta;
|
|
512
691
|
return view;
|
|
513
692
|
});
|
|
514
|
-
|
|
693
|
+
RAW_COUNTS.set(node, (name) => Object.hasOwn(rels, name) ? relationTotal(rels[name]) : void 0);
|
|
694
|
+
attachOverlayAccessors(node);
|
|
515
695
|
}
|
|
516
696
|
/**
|
|
517
697
|
* A per-edge VIEW over a node: a distinct wrapper per membership that reads through to the
|
|
@@ -521,22 +701,48 @@ function attachResourceEnvelope(node, raw, env, rels, selection) {
|
|
|
521
701
|
* `relationEdge` (set for a to-one) carries the relationship object's self/related links and
|
|
522
702
|
* meta, which ride the value's `$edge` (docs/materialisation.md).
|
|
523
703
|
*/
|
|
524
|
-
function buildEdgeView(node, member, relationEdge) {
|
|
704
|
+
function buildEdgeView(node, member, relationEdge, pick) {
|
|
525
705
|
const view = {};
|
|
526
|
-
Object.assign(view, node);
|
|
706
|
+
if (pick === void 0) Object.assign(view, node);
|
|
707
|
+
else for (const [k, v] of Object.entries(node)) if (k === "type" || k === "id" || pick(k)) view[k] = v;
|
|
708
|
+
SOURCES.set(view, node);
|
|
527
709
|
for (const k of [
|
|
528
710
|
"$meta",
|
|
529
711
|
"$links",
|
|
530
712
|
"$self",
|
|
531
713
|
"$document",
|
|
532
714
|
"$raw",
|
|
533
|
-
"$nestedFieldset"
|
|
534
|
-
"$rel",
|
|
535
|
-
"$count"
|
|
715
|
+
"$nestedFieldset"
|
|
536
716
|
]) delegate(view, node, k);
|
|
717
|
+
const rel = node.$rel;
|
|
718
|
+
define(view, "$rel", typeof rel === "function" ? rel.bind(node) : () => void 0);
|
|
719
|
+
attachOverlayAccessors(view);
|
|
537
720
|
attachEdgeEnvelope(view, member, false, relationEdge);
|
|
538
721
|
return view;
|
|
539
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* A per-edge view over `node` for the membership `member` describes, as `materialise` builds one
|
|
725
|
+
* for an included member: it copies `node`'s own enumerable members (those `pick` keeps, when
|
|
726
|
+
* given; `type` and `id` always), reads its resource-level `$`-accessors through to `node`, and
|
|
727
|
+
* owns its `$edge`/`$pivot` from `member.meta`. `node` may be any resource value, a materialised
|
|
728
|
+
* one or a plain object; accessors it lacks read as `undefined`.
|
|
729
|
+
*
|
|
730
|
+
* For a cache layer placing a member in a slot (`@haddowg/json-api-query`'s optimistic drafts).
|
|
731
|
+
*
|
|
732
|
+
* @internal
|
|
733
|
+
*/
|
|
734
|
+
function edgeViewOf(node, member, pick) {
|
|
735
|
+
return buildEdgeView(node, member, void 0, pick);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* An identifier view for `member`, as `materialise` builds one for a linked member that isn't
|
|
739
|
+
* included: `{ type, id, meta? }` with its `$edge`/`$pivot`.
|
|
740
|
+
*
|
|
741
|
+
* @internal
|
|
742
|
+
*/
|
|
743
|
+
function identifierViewOf(member) {
|
|
744
|
+
return buildIdentifierView(member);
|
|
745
|
+
}
|
|
540
746
|
/** An identifier VIEW for a linked-but-not-included member: a clean `{type,id,meta?}` + edge. */
|
|
541
747
|
function buildIdentifierView(member, relationEdge) {
|
|
542
748
|
const view = {
|
|
@@ -544,6 +750,7 @@ function buildIdentifierView(member, relationEdge) {
|
|
|
544
750
|
id: member.id
|
|
545
751
|
};
|
|
546
752
|
if (member.meta !== void 0) view.meta = member.meta;
|
|
753
|
+
defineGetter(view, "$optimistic", () => overlay?.optimistic([view]));
|
|
547
754
|
attachEdgeEnvelope(view, member, true, relationEdge);
|
|
548
755
|
return view;
|
|
549
756
|
}
|
|
@@ -591,7 +798,9 @@ function augmentArray(members, doc, ctx, linkage, primaryType, paginatorOverride
|
|
|
591
798
|
const arr = [...members];
|
|
592
799
|
const links = doc.links;
|
|
593
800
|
defineGetter(arr, "$links", () => links);
|
|
594
|
-
defineGetter(arr, "$meta", ()
|
|
801
|
+
defineGetter(arr, "$meta", function() {
|
|
802
|
+
return withTotal(doc.meta, this);
|
|
803
|
+
});
|
|
595
804
|
attachPage(arr, paginatorOverride === void 0 ? resolvePaginator(primaryPaginator(doc, ctx, primaryType)) : typeof paginatorOverride === "string" ? resolvePaginator(paginatorOverride) : paginatorOverride, pageMeta(doc.meta), links, ctx, linkage);
|
|
596
805
|
return arr;
|
|
597
806
|
}
|
|
@@ -611,7 +820,10 @@ function augmentRelationArray(members, rel, paginator, ctx, hydrated) {
|
|
|
611
820
|
const links = rel.links;
|
|
612
821
|
defineGetter(arr, "$links", () => links);
|
|
613
822
|
defineGetter(arr, "$meta", () => rel.meta);
|
|
614
|
-
defineGetter(arr, "$count", ()
|
|
823
|
+
defineGetter(arr, "$count", function() {
|
|
824
|
+
const raw = relationTotal(rel);
|
|
825
|
+
return overlay === void 0 ? raw : overlay.count([this], void 0, raw);
|
|
826
|
+
});
|
|
615
827
|
attachPage(arr, paginator, pageMeta(rel.meta), links, ctx, !hydrated, hydrated ? (link) => relatedPageLink(link, links) : void 0);
|
|
616
828
|
return arr;
|
|
617
829
|
}
|
|
@@ -636,7 +848,12 @@ function attachPage(arr, paginator, meta, links, ctx, linkage, follow = (link) =
|
|
|
636
848
|
};
|
|
637
849
|
if (paginator.arm !== void 0) page.arm = paginator.arm;
|
|
638
850
|
if (meta !== void 0) page.meta = meta;
|
|
639
|
-
defineGetter(arr, "$page", ()
|
|
851
|
+
defineGetter(arr, "$page", function() {
|
|
852
|
+
return pageWithTotal(page, this);
|
|
853
|
+
});
|
|
854
|
+
define(arr, "$pending", function() {
|
|
855
|
+
return overlay?.creates?.([this]) ?? NO_CREATES;
|
|
856
|
+
});
|
|
640
857
|
const go = (link, signal) => navigateLink(link === void 0 ? void 0 : follow(link), ctx, linkage, paginator, signal);
|
|
641
858
|
define(arr, "$next", (options) => go(page.links.next, options?.signal));
|
|
642
859
|
define(arr, "$prev", (options) => go(page.links.prev, options?.signal));
|
|
@@ -664,6 +881,37 @@ const linkHref = (link) => {
|
|
|
664
881
|
if (typeof link === "string") return link;
|
|
665
882
|
if (isObject$2(link) && typeof link["href"] === "string") return link["href"];
|
|
666
883
|
};
|
|
884
|
+
/** `meta` with its `total` moved as the overlay reports for `target`, when both say so. */
|
|
885
|
+
function withTotal(meta, target) {
|
|
886
|
+
const raw = meta?.["total"];
|
|
887
|
+
if (overlay?.total === void 0 || typeof raw !== "number" || !Number.isFinite(raw)) return meta;
|
|
888
|
+
const total = overlay.total([target], raw);
|
|
889
|
+
return total === raw ? meta : cachedCopy(meta, total, () => ({
|
|
890
|
+
...meta,
|
|
891
|
+
total
|
|
892
|
+
}));
|
|
893
|
+
}
|
|
894
|
+
/** `page` with its `meta.total` moved as the overlay reports for `target`. */
|
|
895
|
+
function pageWithTotal(page, target) {
|
|
896
|
+
const meta = page.meta === void 0 ? void 0 : withTotal(page.meta, target);
|
|
897
|
+
if (meta === void 0 || meta === page.meta) return page;
|
|
898
|
+
return cachedCopy(page, meta["total"], () => ({
|
|
899
|
+
...page,
|
|
900
|
+
meta
|
|
901
|
+
}));
|
|
902
|
+
}
|
|
903
|
+
/** The copies made of each value per total, so an unchanged total reads back the same object. */
|
|
904
|
+
const COPIES = /* @__PURE__ */ new WeakMap();
|
|
905
|
+
function cachedCopy(value, total, make) {
|
|
906
|
+
const copies = COPIES.get(value) ?? /* @__PURE__ */ new Map();
|
|
907
|
+
COPIES.set(value, copies);
|
|
908
|
+
let copy = copies.get(total);
|
|
909
|
+
if (copy === void 0) {
|
|
910
|
+
copy = make();
|
|
911
|
+
copies.set(total, copy);
|
|
912
|
+
}
|
|
913
|
+
return copy;
|
|
914
|
+
}
|
|
667
915
|
const pageMeta = (meta) => isObject$2(meta?.["page"]) ? meta["page"] : void 0;
|
|
668
916
|
/**
|
|
669
917
|
* The document's paginator (from the primary type's descriptor). Prefers the statically-known
|
|
@@ -1089,15 +1337,16 @@ async function runAtomic(request, materialiseCtx, descriptor, path, build) {
|
|
|
1089
1337
|
ext: [ATOMIC_EXT]
|
|
1090
1338
|
};
|
|
1091
1339
|
let doc;
|
|
1340
|
+
let stamp;
|
|
1092
1341
|
try {
|
|
1093
|
-
doc = await
|
|
1342
|
+
({document: doc, stamp} = await executeResponse(request, req));
|
|
1094
1343
|
} catch (error) {
|
|
1095
1344
|
if (error instanceof JsonApiError) throw withRemappedAtomicPaths(error, descriptor, (opIndex) => typeByOp[opIndex], (opIndex) => relationByOp.get(opIndex));
|
|
1096
1345
|
throw error;
|
|
1097
1346
|
}
|
|
1098
|
-
const results = parseResults(doc, materialiseCtx, (opIndex) => relationByOp.has(opIndex));
|
|
1099
|
-
if (!(Array.isArray(returned) && returned.every((h) => h !== null && typeof h === "object" && "opIndex" in h))) return results;
|
|
1100
|
-
return returned.map((handle) => handle.kind === "delete" ? void 0 : results[handle.opIndex]);
|
|
1347
|
+
const results = parseResults(doc, materialiseCtx, (opIndex) => relationByOp.has(opIndex), stamp);
|
|
1348
|
+
if (!(Array.isArray(returned) && returned.every((h) => h !== null && typeof h === "object" && "opIndex" in h))) return stampRequest(results, stamp);
|
|
1349
|
+
return stampRequest(returned.map((handle) => handle.kind === "delete" ? void 0 : results[handle.opIndex]), stamp);
|
|
1101
1350
|
}
|
|
1102
1351
|
/**
|
|
1103
1352
|
* Build the resource `data` for an `add`/`update` op from flat input via {@link toDocument}
|
|
@@ -1137,15 +1386,15 @@ function toRef(ref, what) {
|
|
|
1137
1386
|
}
|
|
1138
1387
|
/**
|
|
1139
1388
|
* Parse `{ "atomic:results": [...] }` positionally, materialising each result's `data`: a
|
|
1140
|
-
* relationship op's as linkage, any other's as a resource
|
|
1141
|
-
* batch) yields `[]`.
|
|
1389
|
+
* relationship op's as linkage, any other's as a resource, each stamped with the batch's request
|
|
1390
|
+
* start. An absent results array (an all-`204` batch) yields `[]`.
|
|
1142
1391
|
*/
|
|
1143
|
-
function parseResults(doc, ctx, isLinkage) {
|
|
1392
|
+
function parseResults(doc, ctx, isLinkage, stamp) {
|
|
1144
1393
|
const results = doc?.["atomic:results"];
|
|
1145
1394
|
if (!Array.isArray(results)) return [];
|
|
1146
1395
|
return results.map((result, opIndex) => {
|
|
1147
1396
|
const entry = isObject(result) ? result : {};
|
|
1148
|
-
const out = { data: entry["data"] === void 0 ? void 0 : materialise({ data: entry["data"] }, ctx, isLinkage(opIndex)) };
|
|
1397
|
+
const out = { data: entry["data"] === void 0 ? void 0 : stampRequest(materialise({ data: entry["data"] }, ctx, isLinkage(opIndex)), stamp) };
|
|
1149
1398
|
if (isObject(entry["meta"])) out.meta = entry["meta"];
|
|
1150
1399
|
return out;
|
|
1151
1400
|
});
|
|
@@ -1437,7 +1686,7 @@ async function runWrite(ctx, spec) {
|
|
|
1437
1686
|
if (error instanceof JsonApiError) throw spec.remap(error);
|
|
1438
1687
|
throw error;
|
|
1439
1688
|
}
|
|
1440
|
-
const complete = (doc) => doc === void 0 ? void 0 : spec.metaOnly === true && !("data" in doc) ? doc.meta : materialise(doc, withFields(ctx.materialise, spec.query?.fields), spec.linkage ?? false);
|
|
1689
|
+
const complete = (doc) => stampFromDocument(doc, doc === void 0 ? void 0 : spec.metaOnly === true && !("data" in doc) ? doc.meta : materialise(doc, withFields(ctx.materialise, spec.query?.fields), spec.linkage ?? false));
|
|
1441
1690
|
if (res.status === 202 && spec.accepted !== void 0) return answerAccepted(ctx, spec.accepted, res, complete, spec.wait);
|
|
1442
1691
|
return complete(res.document);
|
|
1443
1692
|
}
|
|
@@ -1518,7 +1767,7 @@ async function runAction(ctx, action, vars, input, options = {}) {
|
|
|
1518
1767
|
return raw.kind === "json" && text !== void 0 ? JSON.parse(text) : text;
|
|
1519
1768
|
}
|
|
1520
1769
|
const res = await executeResponse(ctx.request, req);
|
|
1521
|
-
const complete = (doc) => actionValue(ctx, action, doc);
|
|
1770
|
+
const complete = (doc) => stampFromDocument(doc, actionValue(ctx, action, doc));
|
|
1522
1771
|
if (res.status === 202 && action.accepted !== void 0) {
|
|
1523
1772
|
const wait = waitOptions(options.wait);
|
|
1524
1773
|
const signal = wait?.signal ?? options.signal;
|
|
@@ -1877,6 +2126,6 @@ async function loadAll(first, options = {}) {
|
|
|
1877
2126
|
return all;
|
|
1878
2127
|
}
|
|
1879
2128
|
//#endregion
|
|
1880
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, PollTimeoutError, StructuralGuardError, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, nestedFieldset, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, sparseSchema, sparseSchemas, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedDocumentMetaPaths, withRemappedPaths, withRemappedRelationshipPaths, withTopLevelMeta };
|
|
2129
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, PollTimeoutError, StructuralGuardError, assertJsonApiDocument, createClient, edgeViewOf, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, identifierViewOf, isAccepted, isActionLocation, isMaterialised, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, nestedFieldset, nextPageParams, nextRequestStamp, parseRetryAfter, prevPageParams, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, requestStampOf, resolvePaginator, resolveValidator, runAtomic, serializeQuery, setMaterialisedOverlay, sparseSchema, sparseSchemas, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedDocumentMetaPaths, withRemappedPaths, withRemappedRelationshipPaths, withTopLevelMeta };
|
|
1881
2130
|
|
|
1882
2131
|
//# sourceMappingURL=index.mjs.map
|