@haddowg/json-api-client 1.24.0 → 1.26.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.d.cts +1 -1
- package/dist/ajv.d.mts +1 -1
- package/dist/index.cjs +61 -11
- package/dist/index.d.cts +22 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +22 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +61 -12
- package/dist/index.mjs.map +1 -1
- package/dist/{validate-9lr5GAdA.d.cts → validate-C9ekU8fM.d.cts} +147 -24
- package/dist/validate-C9ekU8fM.d.cts.map +1 -0
- package/dist/{validate-9lr5GAdA.d.mts → validate-C9ekU8fM.d.mts} +147 -24
- package/dist/validate-C9ekU8fM.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/validate-9lr5GAdA.d.cts.map +0 -1
- package/dist/validate-9lr5GAdA.d.mts.map +0 -1
package/dist/ajv.d.cts
CHANGED
package/dist/ajv.d.mts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -651,8 +651,11 @@ function buildNode(raw, env, index, nodes, ctx) {
|
|
|
651
651
|
*/
|
|
652
652
|
function hydrateRelation(rel, cardinality, related, env, index, nodes, ctx) {
|
|
653
653
|
const data = rel.data;
|
|
654
|
-
if (Array.isArray(data))
|
|
655
|
-
|
|
654
|
+
if (Array.isArray(data)) {
|
|
655
|
+
const raws = data;
|
|
656
|
+
return augmentRelationArray(raws.map((member) => resolveMember(member, env, index, nodes, ctx)), rel, related, ctx, raws.some((member) => index.has(key(member.type, member.id))));
|
|
657
|
+
}
|
|
658
|
+
if (data === void 0 && cardinality === "many") return augmentRelationArray([], rel, related, ctx, false);
|
|
656
659
|
if (data === null || data === void 0) return data === null ? null : void 0;
|
|
657
660
|
if (isObject$2(data)) return resolveMember(data, env, index, nodes, ctx, {
|
|
658
661
|
links: rel.links,
|
|
@@ -769,18 +772,35 @@ function augmentArray(members, doc, ctx, linkage, primaryType, paginatorOverride
|
|
|
769
772
|
* `paginator` is the relation's (so an in-document compound-include to-many reports the same
|
|
770
773
|
* discriminant it would when fetched at its own relationship/related endpoint — "one model,
|
|
771
774
|
* three surfaces").
|
|
775
|
+
*
|
|
776
|
+
* A rendered to-many holds only its first page, and its page links usually address the
|
|
777
|
+
* relationship endpoint, which answers with identifiers. So `$next()`/`$prev()` keep the shape the
|
|
778
|
+
* array has: an included (`hydrated`) array reads the same page from the related endpoint, which
|
|
779
|
+
* answers with the resources, and an array of identifiers reads the page as linkage.
|
|
772
780
|
*/
|
|
773
|
-
function augmentRelationArray(members, rel, paginator, ctx) {
|
|
781
|
+
function augmentRelationArray(members, rel, paginator, ctx, hydrated) {
|
|
774
782
|
const arr = [...members];
|
|
775
783
|
const links = rel.links;
|
|
776
784
|
defineGetter(arr, "$links", () => links);
|
|
777
785
|
defineGetter(arr, "$meta", () => rel.meta);
|
|
778
786
|
defineGetter(arr, "$count", () => relationTotal(rel));
|
|
779
|
-
attachPage(arr, paginator, pageMeta(rel.meta), links, ctx,
|
|
787
|
+
attachPage(arr, paginator, pageMeta(rel.meta), links, ctx, !hydrated, hydrated ? (link) => relatedPageLink(link, links) : void 0);
|
|
780
788
|
return arr;
|
|
781
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* A relationship page link moved to the related endpoint: a link addressing the relationship's
|
|
792
|
+
* `self` path takes its `related` path and keeps its query, so it reads the same page as
|
|
793
|
+
* resources. Any other link, such as one already addressing the related endpoint, is unchanged.
|
|
794
|
+
*/
|
|
795
|
+
function relatedPageLink(link, links) {
|
|
796
|
+
const self = linkHref(links?.["self"]);
|
|
797
|
+
const related = linkHref(links?.["related"]);
|
|
798
|
+
if (self === void 0 || related === void 0) return link;
|
|
799
|
+
const at = link.indexOf("?");
|
|
800
|
+
return (at < 0 ? link : link.slice(0, at)) === self.split("?")[0] ? `${related.split("?")[0]}${at < 0 ? "" : link.slice(at)}` : link;
|
|
801
|
+
}
|
|
782
802
|
/** Attach `$page` + `$next()`/`$prev()` driven by link presence (count-free-safe). */
|
|
783
|
-
function attachPage(arr, paginator, meta, links, ctx, linkage) {
|
|
803
|
+
function attachPage(arr, paginator, meta, links, ctx, linkage, follow = (link) => link) {
|
|
784
804
|
const page = {
|
|
785
805
|
kind: paginator.kind,
|
|
786
806
|
keys: paginator.keys,
|
|
@@ -789,8 +809,9 @@ function attachPage(arr, paginator, meta, links, ctx, linkage) {
|
|
|
789
809
|
if (paginator.arm !== void 0) page.arm = paginator.arm;
|
|
790
810
|
if (meta !== void 0) page.meta = meta;
|
|
791
811
|
defineGetter(arr, "$page", () => page);
|
|
792
|
-
|
|
793
|
-
define(arr, "$
|
|
812
|
+
const go = (link, signal) => navigateLink(link === void 0 ? void 0 : follow(link), ctx, linkage, paginator, signal);
|
|
813
|
+
define(arr, "$next", (options) => go(page.links.next, options?.signal));
|
|
814
|
+
define(arr, "$prev", (options) => go(page.links.prev, options?.signal));
|
|
794
815
|
}
|
|
795
816
|
const navigateLink = (link, ctx, linkage, paginator, signal) => {
|
|
796
817
|
if (link === void 0) return Promise.resolve(void 0);
|
|
@@ -1478,7 +1499,7 @@ async function runWrite(ctx, spec) {
|
|
|
1478
1499
|
if (error instanceof JsonApiError) throw spec.remap(error);
|
|
1479
1500
|
throw error;
|
|
1480
1501
|
}
|
|
1481
|
-
const complete = (doc) => doc === void 0 ? void 0 : materialise(doc, ctx.materialise, spec.linkage ?? false);
|
|
1502
|
+
const complete = (doc) => doc === void 0 ? void 0 : spec.metaOnly === true && !("data" in doc) ? doc.meta : materialise(doc, ctx.materialise, spec.linkage ?? false);
|
|
1482
1503
|
if (res.status === 202 && spec.accepted !== void 0) return answerAccepted(ctx, spec.accepted, res, complete, spec.wait);
|
|
1483
1504
|
return complete(res.document);
|
|
1484
1505
|
}
|
|
@@ -1499,7 +1520,8 @@ async function runWrite(ctx, spec) {
|
|
|
1499
1520
|
*
|
|
1500
1521
|
* The response is shaped by the action's `output`: `document` materialises into the resource /
|
|
1501
1522
|
* collection view, `meta` returns the document's top-level `meta`, `none` resolves `undefined` (a
|
|
1502
|
-
* `204` / no body).
|
|
1523
|
+
* `204` / no body). A `metaResult` action returns the top-level `meta` of a document with no
|
|
1524
|
+
* `data`. An action declaring a `location` returns the URL of a location document as an
|
|
1503
1525
|
* `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
|
|
1504
1526
|
* the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
|
|
1505
1527
|
* `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
|
|
@@ -1574,7 +1596,7 @@ function actionValue(ctx, action, doc) {
|
|
|
1574
1596
|
if (action.output === "location") throw new Error("The action answered without the location document it declares.");
|
|
1575
1597
|
}
|
|
1576
1598
|
if (action.output === "none" || action.output === "location" || doc === void 0) return;
|
|
1577
|
-
if (action.output === "meta") return doc.meta;
|
|
1599
|
+
if (action.output === "meta" || action.metaResult === true && !("data" in doc)) return doc.meta;
|
|
1578
1600
|
return materialise(doc, ctx.materialise);
|
|
1579
1601
|
}
|
|
1580
1602
|
/**
|
|
@@ -1781,7 +1803,8 @@ function resourceHandle(ctx, type, id) {
|
|
|
1781
1803
|
vars,
|
|
1782
1804
|
method: "DELETE",
|
|
1783
1805
|
body: void 0,
|
|
1784
|
-
remap: (error) => withRemappedPaths(error, ctx.descriptor, type)
|
|
1806
|
+
remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
|
|
1807
|
+
metaOnly: ctx.descriptor[type]?.documentMeta?.delete !== void 0
|
|
1785
1808
|
}),
|
|
1786
1809
|
rel: (name) => relationshipAccessor(ctx, type, vars, name),
|
|
1787
1810
|
actions: actionsAccessor(ctx, type, "resource", vars)
|
|
@@ -1882,6 +1905,32 @@ function createClient(descriptor, options) {
|
|
|
1882
1905
|
});
|
|
1883
1906
|
}
|
|
1884
1907
|
//#endregion
|
|
1908
|
+
//#region src/load-all.ts
|
|
1909
|
+
/**
|
|
1910
|
+
* Follow `next` links from a first page until the last, and return every member in one plain
|
|
1911
|
+
* array. It takes any collection: a list, a related read, or a to-many relationship of a resource
|
|
1912
|
+
* you read, which holds only its first page of members when the server renders its linkage:
|
|
1913
|
+
*
|
|
1914
|
+
* ```ts
|
|
1915
|
+
* const album = await client.albums.get('1', { include: ['tracks'] })
|
|
1916
|
+
* const tracks = await loadAll(album.tracks)
|
|
1917
|
+
* ```
|
|
1918
|
+
*/
|
|
1919
|
+
async function loadAll(first, options = {}) {
|
|
1920
|
+
const { signal, maxPages = Number.POSITIVE_INFINITY } = options;
|
|
1921
|
+
let page = await first;
|
|
1922
|
+
const all = [];
|
|
1923
|
+
let count = 0;
|
|
1924
|
+
while (page !== void 0 && count < maxPages) {
|
|
1925
|
+
all.push(...page);
|
|
1926
|
+
count++;
|
|
1927
|
+
if (count >= maxPages) break;
|
|
1928
|
+
signal?.throwIfAborted();
|
|
1929
|
+
page = await page.$next(signal !== void 0 ? { signal } : void 0);
|
|
1930
|
+
}
|
|
1931
|
+
return all;
|
|
1932
|
+
}
|
|
1933
|
+
//#endregion
|
|
1885
1934
|
exports.ATOMIC_EXT = ATOMIC_EXT;
|
|
1886
1935
|
exports.ATOMIC_MEDIA_TYPE = ATOMIC_MEDIA_TYPE;
|
|
1887
1936
|
exports.CANONICAL_PAGE_KEYS = CANONICAL_PAGE_KEYS;
|
|
@@ -1902,6 +1951,7 @@ exports.isAccepted = isAccepted;
|
|
|
1902
1951
|
exports.isActionLocation = isActionLocation;
|
|
1903
1952
|
exports.isPolymorphic = isPolymorphic;
|
|
1904
1953
|
exports.listFilterMatcher = listFilterMatcher;
|
|
1954
|
+
exports.loadAll = loadAll;
|
|
1905
1955
|
exports.materialise = materialise;
|
|
1906
1956
|
exports.mediaType = mediaType;
|
|
1907
1957
|
exports.parseRetryAfter = parseRetryAfter;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as FilterKey, $n as PollTimeoutError, $t as WithDocumentMeta, A as AcceptedOf, An as MaterialiseContext, Ar as RelatedQueryDescriptor, At as RelationPaginator, B as CountToken, Bn as ExactPageParams, Bt as SingletonUpdateInput, C as createClient, Cn as mediaType, Cr as PaginatorDescriptor, Ct as RelatedQueryParam, D as TransportResponse, Dn as EdgeEnvelope, Dr as PivotDescriptor, Dt as RelationFilterQuery, E as TransportRequest, En as Edge, Er as PaginatorStrategy, Et as RelationCollection, F as BinaryResponseType, Fn as ResourceLinks, Fr as ResourceDescriptor, Ft as ResourceCountToken, G as DefaultAttributes, Gn as PageOf, Gt as TypedReadQuery, H as CreateInput, Hn as PageKeys, Ht as SortToken, I as Client, In as materialise, Ir as ResourceExamples, It as ResourceHandle, J as DocumentMeta, Jn as ResolvedPaginator, Jt as UpdateInput, K as DefaultWriteAttributes, Kn as PageParams, Kt as TypedRelatedReadQuery, L as Collection, Ln as relatedPaginator, Lr as SortFamilyDescriptor, Lt as ResourceObjectView, M as ActionsAccessor, Mn as RelationArrayEnvelope, Mr as RelationDescriptor, Mt as RelationSortQuery, N as AtomicResultOf, Nn as RelationView, Nr as RelationMutations, Nt as RelationshipAccessor, O as fetchTransport, On as Link, Or as RawMediaKind, Ot as RelationName, P as BinaryBody, Pn as ResourceEnvelope, Pr as ResourceCountOperation, Pt as ResourceAccessors, Q as FieldsMap, Qn as PollOptions, Qt as WaitedWriteResult, R as CollectionMeta, Rn as relatedPaginatorKind, Rr as StrategyDescriptor, Rt as SingleReadQuery, S as HeadersInit, Sn as ResourceIdentifier, Sr as OperationExamples, St as RelatedQueryEntry, T as TransportRawBody, Tn as DocumentEnvelope, Tr as PaginatorRole, Tt as RelatedReadRelatedQuery, U as CreateMethod, Un as PageLinks, Ut as TypeAccessor, V as CountedRelationName, Vn as Page, Vt as SortQuery, W as DefaultActionTypes, Wn as PageMeta, Wt as TypeName, X as ErrorCodeOf, Xn as resolvePaginator, Xt as WaitOptions, Y as EdgeMembers, Yn as TypedPage, Yt as UpdateMethod, Z as FieldSelectionMap, Zn as Accepted, Zt as WaitValue, _ as executeRaw, _n as ATOMIC_EXT, _r as FilterFamilyDescriptor, _t as ReadableRelationName, a as Validator, an as readActionLocation, ar as ActionInput, at as IncludedResource, b as ClientOptions, bn as LocalIdentifier, br as MediaExamples, bt as RelatedMeta, c as resolveValidator, cn as AtomicDeleteHandle, cr as ActionScope, ct as LinkageRef, d as ExecutedResponse, dn as AtomicRef, dr as AtomicDescriptor, dt as LooseRelatedQuery, en as WithLinks, er as isAccepted, et as FilterQuery, f as JsonApiContext, fn as AtomicResult, fr as Cardinality, ft as LooseRelatedQueryEntry, g as execute, gn as runAtomic, gr as DocumentMetaOperation, gt as ReadResult, h as ReadQuery, hn as AtomicUpdateInput, hr as DocumentMetaDescriptor, ht as PivotInput, i as ValidationOption, in as isActionLocation, ir as ActionDescriptor, it as IncludedRelations, j as ActionCallOptions, jn as NavigateOptions, jr as RelatedQueryOperation, jt as RelationReadQuery, k as AcceptedJob, kn as LinkObject, kr as RawOutputMedia, kt as RelationPageParams, l as validateDocument, ln as AtomicHandle, lr as ApiDescriptor, lt as ListFilterMember, m as RawResponseType, mn as AtomicUpdateHandle, mr as CountableDescriptor, mt as OperationMeta, n as SchemaMap, nn as WriteResult, nr as AcceptedDescriptor, nt as IdentifierMember, o as WireResource, on as AtomicCreateHandle, or as ActionLocationDescriptor, ot as IncludedType, p as JsonApiRequest, pn as AtomicResults, pr as ClientIdPolicy, pt as MemberName, q as DeleteResult, qn as PageParamsOf, qt as TypedRelationReadQuery, r as ValidationConfig, rn as ActionLocation, rr as AcceptedOperation, rt as IncludePath, s as assertJsonApiDocument, sn as AtomicCreateInput, sr as ActionOutput, st as IsSingleton, t as ResolvedValidator, tn as WriteOptions, tr as parseRetryAfter, tt as HydratedMember, u as Document, un as AtomicRecorder, ur as ApiExamples, ut as ListPageParams, v as executeResponse, vn as ATOMIC_MEDIA_TYPE, vr as InputMedia, vt as RelatedIncludedResource, w as JsonApiTransport, wn as ArrayEnvelope, wr as PaginatorKind, wt as RelatedQueryRelation, x as HANDLE_RESERVED, xn as MediaTypeParams, xr as MenuDescriptor, xt as RelatedQuery, y as serializeQuery, yn as JSON_API_MEDIA_TYPE, yr as InputMediaKind, yt as RelatedIncludedType, z as CountAccessor, zn as CANONICAL_PAGE_KEYS, zr as isPolymorphic, zt as SingletonAccessor } from "./validate-C9ekU8fM.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/errors.d.ts
|
|
4
4
|
/**
|
|
@@ -126,6 +126,26 @@ interface FilterSpec {
|
|
|
126
126
|
*/
|
|
127
127
|
declare function listFilterMatcher(spec: FilterSpec | undefined): ((key: string) => boolean) | undefined;
|
|
128
128
|
//#endregion
|
|
129
|
+
//#region src/load-all.d.ts
|
|
130
|
+
/** Options for {@link loadAll}. */
|
|
131
|
+
interface LoadAllOptions {
|
|
132
|
+
/** Stops the walk, rejecting with the signal's reason. */
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
/** Stop after this many pages, as a guard against an unexpectedly large collection. */
|
|
135
|
+
maxPages?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Follow `next` links from a first page until the last, and return every member in one plain
|
|
139
|
+
* array. It takes any collection: a list, a related read, or a to-many relationship of a resource
|
|
140
|
+
* you read, which holds only its first page of members when the server renders its linkage:
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* const album = await client.albums.get('1', { include: ['tracks'] })
|
|
144
|
+
* const tracks = await loadAll(album.tracks)
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function loadAll<T>(first: Collection<T> | PromiseLike<Collection<T>>, options?: LoadAllOptions): Promise<T[]>;
|
|
148
|
+
//#endregion
|
|
129
149
|
//#region src/serialize-write.d.ts
|
|
130
150
|
/**
|
|
131
151
|
* A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
|
|
@@ -253,5 +273,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
|
|
|
253
273
|
*/
|
|
254
274
|
declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
|
|
255
275
|
//#endregion
|
|
256
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, 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, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
276
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, 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, 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, NavigateOptions, OperationExamples, OperationMeta, 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, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithDocumentMeta, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
257
277
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/filters.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;AAa7B;;;;;;AAb6B,cADhB,oBAAA,SAA6B,KAAK;cACjC,OAAA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AA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as FilterKey, $n as PollTimeoutError, $t as WithDocumentMeta, A as AcceptedOf, An as MaterialiseContext, Ar as RelatedQueryDescriptor, At as RelationPaginator, B as CountToken, Bn as ExactPageParams, Bt as SingletonUpdateInput, C as createClient, Cn as mediaType, Cr as PaginatorDescriptor, Ct as RelatedQueryParam, D as TransportResponse, Dn as EdgeEnvelope, Dr as PivotDescriptor, Dt as RelationFilterQuery, E as TransportRequest, En as Edge, Er as PaginatorStrategy, Et as RelationCollection, F as BinaryResponseType, Fn as ResourceLinks, Fr as ResourceDescriptor, Ft as ResourceCountToken, G as DefaultAttributes, Gn as PageOf, Gt as TypedReadQuery, H as CreateInput, Hn as PageKeys, Ht as SortToken, I as Client, In as materialise, Ir as ResourceExamples, It as ResourceHandle, J as DocumentMeta, Jn as ResolvedPaginator, Jt as UpdateInput, K as DefaultWriteAttributes, Kn as PageParams, Kt as TypedRelatedReadQuery, L as Collection, Ln as relatedPaginator, Lr as SortFamilyDescriptor, Lt as ResourceObjectView, M as ActionsAccessor, Mn as RelationArrayEnvelope, Mr as RelationDescriptor, Mt as RelationSortQuery, N as AtomicResultOf, Nn as RelationView, Nr as RelationMutations, Nt as RelationshipAccessor, O as fetchTransport, On as Link, Or as RawMediaKind, Ot as RelationName, P as BinaryBody, Pn as ResourceEnvelope, Pr as ResourceCountOperation, Pt as ResourceAccessors, Q as FieldsMap, Qn as PollOptions, Qt as WaitedWriteResult, R as CollectionMeta, Rn as relatedPaginatorKind, Rr as StrategyDescriptor, Rt as SingleReadQuery, S as HeadersInit, Sn as ResourceIdentifier, Sr as OperationExamples, St as RelatedQueryEntry, T as TransportRawBody, Tn as DocumentEnvelope, Tr as PaginatorRole, Tt as RelatedReadRelatedQuery, U as CreateMethod, Un as PageLinks, Ut as TypeAccessor, V as CountedRelationName, Vn as Page, Vt as SortQuery, W as DefaultActionTypes, Wn as PageMeta, Wt as TypeName, X as ErrorCodeOf, Xn as resolvePaginator, Xt as WaitOptions, Y as EdgeMembers, Yn as TypedPage, Yt as UpdateMethod, Z as FieldSelectionMap, Zn as Accepted, Zt as WaitValue, _ as executeRaw, _n as ATOMIC_EXT, _r as FilterFamilyDescriptor, _t as ReadableRelationName, a as Validator, an as readActionLocation, ar as ActionInput, at as IncludedResource, b as ClientOptions, bn as LocalIdentifier, br as MediaExamples, bt as RelatedMeta, c as resolveValidator, cn as AtomicDeleteHandle, cr as ActionScope, ct as LinkageRef, d as ExecutedResponse, dn as AtomicRef, dr as AtomicDescriptor, dt as LooseRelatedQuery, en as WithLinks, er as isAccepted, et as FilterQuery, f as JsonApiContext, fn as AtomicResult, fr as Cardinality, ft as LooseRelatedQueryEntry, g as execute, gn as runAtomic, gr as DocumentMetaOperation, gt as ReadResult, h as ReadQuery, hn as AtomicUpdateInput, hr as DocumentMetaDescriptor, ht as PivotInput, i as ValidationOption, in as isActionLocation, ir as ActionDescriptor, it as IncludedRelations, j as ActionCallOptions, jn as NavigateOptions, jr as RelatedQueryOperation, jt as RelationReadQuery, k as AcceptedJob, kn as LinkObject, kr as RawOutputMedia, kt as RelationPageParams, l as validateDocument, ln as AtomicHandle, lr as ApiDescriptor, lt as ListFilterMember, m as RawResponseType, mn as AtomicUpdateHandle, mr as CountableDescriptor, mt as OperationMeta, n as SchemaMap, nn as WriteResult, nr as AcceptedDescriptor, nt as IdentifierMember, o as WireResource, on as AtomicCreateHandle, or as ActionLocationDescriptor, ot as IncludedType, p as JsonApiRequest, pn as AtomicResults, pr as ClientIdPolicy, pt as MemberName, q as DeleteResult, qn as PageParamsOf, qt as TypedRelationReadQuery, r as ValidationConfig, rn as ActionLocation, rr as AcceptedOperation, rt as IncludePath, s as assertJsonApiDocument, sn as AtomicCreateInput, sr as ActionOutput, st as IsSingleton, t as ResolvedValidator, tn as WriteOptions, tr as parseRetryAfter, tt as HydratedMember, u as Document, un as AtomicRecorder, ur as ApiExamples, ut as ListPageParams, v as executeResponse, vn as ATOMIC_MEDIA_TYPE, vr as InputMedia, vt as RelatedIncludedResource, w as JsonApiTransport, wn as ArrayEnvelope, wr as PaginatorKind, wt as RelatedQueryRelation, x as HANDLE_RESERVED, xn as MediaTypeParams, xr as MenuDescriptor, xt as RelatedQuery, y as serializeQuery, yn as JSON_API_MEDIA_TYPE, yr as InputMediaKind, yt as RelatedIncludedType, z as CountAccessor, zn as CANONICAL_PAGE_KEYS, zr as isPolymorphic, zt as SingletonAccessor } from "./validate-C9ekU8fM.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/errors.d.ts
|
|
4
4
|
/**
|
|
@@ -126,6 +126,26 @@ interface FilterSpec {
|
|
|
126
126
|
*/
|
|
127
127
|
declare function listFilterMatcher(spec: FilterSpec | undefined): ((key: string) => boolean) | undefined;
|
|
128
128
|
//#endregion
|
|
129
|
+
//#region src/load-all.d.ts
|
|
130
|
+
/** Options for {@link loadAll}. */
|
|
131
|
+
interface LoadAllOptions {
|
|
132
|
+
/** Stops the walk, rejecting with the signal's reason. */
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
/** Stop after this many pages, as a guard against an unexpectedly large collection. */
|
|
135
|
+
maxPages?: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Follow `next` links from a first page until the last, and return every member in one plain
|
|
139
|
+
* array. It takes any collection: a list, a related read, or a to-many relationship of a resource
|
|
140
|
+
* you read, which holds only its first page of members when the server renders its linkage:
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* const album = await client.albums.get('1', { include: ['tracks'] })
|
|
144
|
+
* const tracks = await loadAll(album.tracks)
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function loadAll<T>(first: Collection<T> | PromiseLike<Collection<T>>, options?: LoadAllOptions): Promise<T[]>;
|
|
148
|
+
//#endregion
|
|
129
149
|
//#region src/serialize-write.d.ts
|
|
130
150
|
/**
|
|
131
151
|
* A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
|
|
@@ -253,5 +273,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
|
|
|
253
273
|
*/
|
|
254
274
|
declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
|
|
255
275
|
//#endregion
|
|
256
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, 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, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
276
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, 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, 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, NavigateOptions, OperationExamples, OperationMeta, 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, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithDocumentMeta, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, loadAll, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
257
277
|
//# 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/serialize-write.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA,GAAO,CAAA;EACP,KAA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;iBASlC,iBAAA,CACd,IAAA,EAAM,UAAU,iBACb,GAAA;;;;;;;;
|
|
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;AAa7B;;;;;;AAb6B,cADhB,oBAAA,SAA6B,KAAK;cACjC,OAAA;AAAA;;;;;;;;cAaD,YAAA,oCAAgD,KAAA;EAAA,SAClD,MAAA;EAAA,SACA,MAAA,EAAQ,kBAAA,CAAmB,CAAA;cAExB,MAAA,UAAgB,MAAA,EAAQ,kBAAA,CAAmB,CAAA,KAAM,OAAA;EAO7D,SAAA,CAAU,MAAA;EAIV,KAAA;EAIA,KAAA;EAIA,YAAA;EAIA,cAAA;EAIA,WAAA;EAIA,UAAA;EAIA,eAAA;EAIA,UAAA;EAIA,sBAAA;EAIA,eAAA;EApBA;EAyBA,iBAAA;EAIA,aAAA;EAjBA;;;;;EA0BA,MAAA,IAAU,MAAA,SAAe,kBAAA,CAAmB,CAAA;AAAA;;;;AAAC;AAgB/C;;iBAAgB,YAAA,CAAa,GAAA,WAAc,IAAA,WAAe,GAAA,IAAO,YAAY;;;;;;KASjE,cAAA,sBAAoC,GAAA,WAAc,IAAA,EAAM,CAAA,KAAM,GAAA,IAAO,YAAA,CAAa,CAAA;AATjB;AAS7E;;;;AAT6E,KAgBjE,gBAAA,6BAA6C,kBAAA,CAAmB,CAAA;EAC1E,IAAA,EAAM,CAAA;AAAA,KACH,CAAA,eAAgB,CAAA;EAAM,IAAA,EAAM,CAAA,CAAE,CAAA;AAAA;;;;;;iBAOnB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B,OAAA;;;;;;;iBAkBzD,iBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,IAAA,WACC,YAAA;;;;;;;;iBAWa,6BAAA,CACd,KAAA,EAAO,YAAA,EACP,GAAA,UACA,QAAA,YACC,YAAY;;AHzLqB;AAOpC;;;;;;;iBG+LgB,uBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -650,8 +650,11 @@ function buildNode(raw, env, index, nodes, ctx) {
|
|
|
650
650
|
*/
|
|
651
651
|
function hydrateRelation(rel, cardinality, related, env, index, nodes, ctx) {
|
|
652
652
|
const data = rel.data;
|
|
653
|
-
if (Array.isArray(data))
|
|
654
|
-
|
|
653
|
+
if (Array.isArray(data)) {
|
|
654
|
+
const raws = data;
|
|
655
|
+
return augmentRelationArray(raws.map((member) => resolveMember(member, env, index, nodes, ctx)), rel, related, ctx, raws.some((member) => index.has(key(member.type, member.id))));
|
|
656
|
+
}
|
|
657
|
+
if (data === void 0 && cardinality === "many") return augmentRelationArray([], rel, related, ctx, false);
|
|
655
658
|
if (data === null || data === void 0) return data === null ? null : void 0;
|
|
656
659
|
if (isObject$2(data)) return resolveMember(data, env, index, nodes, ctx, {
|
|
657
660
|
links: rel.links,
|
|
@@ -768,18 +771,35 @@ function augmentArray(members, doc, ctx, linkage, primaryType, paginatorOverride
|
|
|
768
771
|
* `paginator` is the relation's (so an in-document compound-include to-many reports the same
|
|
769
772
|
* discriminant it would when fetched at its own relationship/related endpoint — "one model,
|
|
770
773
|
* three surfaces").
|
|
774
|
+
*
|
|
775
|
+
* A rendered to-many holds only its first page, and its page links usually address the
|
|
776
|
+
* relationship endpoint, which answers with identifiers. So `$next()`/`$prev()` keep the shape the
|
|
777
|
+
* array has: an included (`hydrated`) array reads the same page from the related endpoint, which
|
|
778
|
+
* answers with the resources, and an array of identifiers reads the page as linkage.
|
|
771
779
|
*/
|
|
772
|
-
function augmentRelationArray(members, rel, paginator, ctx) {
|
|
780
|
+
function augmentRelationArray(members, rel, paginator, ctx, hydrated) {
|
|
773
781
|
const arr = [...members];
|
|
774
782
|
const links = rel.links;
|
|
775
783
|
defineGetter(arr, "$links", () => links);
|
|
776
784
|
defineGetter(arr, "$meta", () => rel.meta);
|
|
777
785
|
defineGetter(arr, "$count", () => relationTotal(rel));
|
|
778
|
-
attachPage(arr, paginator, pageMeta(rel.meta), links, ctx,
|
|
786
|
+
attachPage(arr, paginator, pageMeta(rel.meta), links, ctx, !hydrated, hydrated ? (link) => relatedPageLink(link, links) : void 0);
|
|
779
787
|
return arr;
|
|
780
788
|
}
|
|
789
|
+
/**
|
|
790
|
+
* A relationship page link moved to the related endpoint: a link addressing the relationship's
|
|
791
|
+
* `self` path takes its `related` path and keeps its query, so it reads the same page as
|
|
792
|
+
* resources. Any other link, such as one already addressing the related endpoint, is unchanged.
|
|
793
|
+
*/
|
|
794
|
+
function relatedPageLink(link, links) {
|
|
795
|
+
const self = linkHref(links?.["self"]);
|
|
796
|
+
const related = linkHref(links?.["related"]);
|
|
797
|
+
if (self === void 0 || related === void 0) return link;
|
|
798
|
+
const at = link.indexOf("?");
|
|
799
|
+
return (at < 0 ? link : link.slice(0, at)) === self.split("?")[0] ? `${related.split("?")[0]}${at < 0 ? "" : link.slice(at)}` : link;
|
|
800
|
+
}
|
|
781
801
|
/** Attach `$page` + `$next()`/`$prev()` driven by link presence (count-free-safe). */
|
|
782
|
-
function attachPage(arr, paginator, meta, links, ctx, linkage) {
|
|
802
|
+
function attachPage(arr, paginator, meta, links, ctx, linkage, follow = (link) => link) {
|
|
783
803
|
const page = {
|
|
784
804
|
kind: paginator.kind,
|
|
785
805
|
keys: paginator.keys,
|
|
@@ -788,8 +808,9 @@ function attachPage(arr, paginator, meta, links, ctx, linkage) {
|
|
|
788
808
|
if (paginator.arm !== void 0) page.arm = paginator.arm;
|
|
789
809
|
if (meta !== void 0) page.meta = meta;
|
|
790
810
|
defineGetter(arr, "$page", () => page);
|
|
791
|
-
|
|
792
|
-
define(arr, "$
|
|
811
|
+
const go = (link, signal) => navigateLink(link === void 0 ? void 0 : follow(link), ctx, linkage, paginator, signal);
|
|
812
|
+
define(arr, "$next", (options) => go(page.links.next, options?.signal));
|
|
813
|
+
define(arr, "$prev", (options) => go(page.links.prev, options?.signal));
|
|
793
814
|
}
|
|
794
815
|
const navigateLink = (link, ctx, linkage, paginator, signal) => {
|
|
795
816
|
if (link === void 0) return Promise.resolve(void 0);
|
|
@@ -1477,7 +1498,7 @@ async function runWrite(ctx, spec) {
|
|
|
1477
1498
|
if (error instanceof JsonApiError) throw spec.remap(error);
|
|
1478
1499
|
throw error;
|
|
1479
1500
|
}
|
|
1480
|
-
const complete = (doc) => doc === void 0 ? void 0 : materialise(doc, ctx.materialise, spec.linkage ?? false);
|
|
1501
|
+
const complete = (doc) => doc === void 0 ? void 0 : spec.metaOnly === true && !("data" in doc) ? doc.meta : materialise(doc, ctx.materialise, spec.linkage ?? false);
|
|
1481
1502
|
if (res.status === 202 && spec.accepted !== void 0) return answerAccepted(ctx, spec.accepted, res, complete, spec.wait);
|
|
1482
1503
|
return complete(res.document);
|
|
1483
1504
|
}
|
|
@@ -1498,7 +1519,8 @@ async function runWrite(ctx, spec) {
|
|
|
1498
1519
|
*
|
|
1499
1520
|
* The response is shaped by the action's `output`: `document` materialises into the resource /
|
|
1500
1521
|
* collection view, `meta` returns the document's top-level `meta`, `none` resolves `undefined` (a
|
|
1501
|
-
* `204` / no body).
|
|
1522
|
+
* `204` / no body). A `metaResult` action returns the top-level `meta` of a document with no
|
|
1523
|
+
* `data`. An action declaring a `location` returns the URL of a location document as an
|
|
1502
1524
|
* `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
|
|
1503
1525
|
* the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
|
|
1504
1526
|
* `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
|
|
@@ -1573,7 +1595,7 @@ function actionValue(ctx, action, doc) {
|
|
|
1573
1595
|
if (action.output === "location") throw new Error("The action answered without the location document it declares.");
|
|
1574
1596
|
}
|
|
1575
1597
|
if (action.output === "none" || action.output === "location" || doc === void 0) return;
|
|
1576
|
-
if (action.output === "meta") return doc.meta;
|
|
1598
|
+
if (action.output === "meta" || action.metaResult === true && !("data" in doc)) return doc.meta;
|
|
1577
1599
|
return materialise(doc, ctx.materialise);
|
|
1578
1600
|
}
|
|
1579
1601
|
/**
|
|
@@ -1780,7 +1802,8 @@ function resourceHandle(ctx, type, id) {
|
|
|
1780
1802
|
vars,
|
|
1781
1803
|
method: "DELETE",
|
|
1782
1804
|
body: void 0,
|
|
1783
|
-
remap: (error) => withRemappedPaths(error, ctx.descriptor, type)
|
|
1805
|
+
remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
|
|
1806
|
+
metaOnly: ctx.descriptor[type]?.documentMeta?.delete !== void 0
|
|
1784
1807
|
}),
|
|
1785
1808
|
rel: (name) => relationshipAccessor(ctx, type, vars, name),
|
|
1786
1809
|
actions: actionsAccessor(ctx, type, "resource", vars)
|
|
@@ -1881,6 +1904,32 @@ function createClient(descriptor, options) {
|
|
|
1881
1904
|
});
|
|
1882
1905
|
}
|
|
1883
1906
|
//#endregion
|
|
1884
|
-
|
|
1907
|
+
//#region src/load-all.ts
|
|
1908
|
+
/**
|
|
1909
|
+
* Follow `next` links from a first page until the last, and return every member in one plain
|
|
1910
|
+
* array. It takes any collection: a list, a related read, or a to-many relationship of a resource
|
|
1911
|
+
* you read, which holds only its first page of members when the server renders its linkage:
|
|
1912
|
+
*
|
|
1913
|
+
* ```ts
|
|
1914
|
+
* const album = await client.albums.get('1', { include: ['tracks'] })
|
|
1915
|
+
* const tracks = await loadAll(album.tracks)
|
|
1916
|
+
* ```
|
|
1917
|
+
*/
|
|
1918
|
+
async function loadAll(first, options = {}) {
|
|
1919
|
+
const { signal, maxPages = Number.POSITIVE_INFINITY } = options;
|
|
1920
|
+
let page = await first;
|
|
1921
|
+
const all = [];
|
|
1922
|
+
let count = 0;
|
|
1923
|
+
while (page !== void 0 && count < maxPages) {
|
|
1924
|
+
all.push(...page);
|
|
1925
|
+
count++;
|
|
1926
|
+
if (count >= maxPages) break;
|
|
1927
|
+
signal?.throwIfAborted();
|
|
1928
|
+
page = await page.$next(signal !== void 0 ? { signal } : void 0);
|
|
1929
|
+
}
|
|
1930
|
+
return all;
|
|
1931
|
+
}
|
|
1932
|
+
//#endregion
|
|
1933
|
+
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, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
1885
1934
|
|
|
1886
1935
|
//# sourceMappingURL=index.mjs.map
|