@haddowg/json-api-client 1.7.0 → 1.9.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 +64 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +62 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{validate-BQwvkQIU.d.cts → validate-CvUPfKwB.d.cts} +90 -10
- package/dist/validate-CvUPfKwB.d.cts.map +1 -0
- package/dist/{validate-BQwvkQIU.d.mts → validate-CvUPfKwB.d.mts} +90 -10
- package/dist/validate-CvUPfKwB.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/validate-BQwvkQIU.d.cts.map +0 -1
- package/dist/validate-BQwvkQIU.d.mts.map +0 -1
package/dist/ajv.d.cts
CHANGED
package/dist/ajv.d.mts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1045,6 +1045,48 @@ function parseResults(doc, ctx) {
|
|
|
1045
1045
|
});
|
|
1046
1046
|
}
|
|
1047
1047
|
//#endregion
|
|
1048
|
+
//#region src/location.ts
|
|
1049
|
+
/**
|
|
1050
|
+
* Whether a value is an {@link ActionLocation}, for an action that answers with either a resource
|
|
1051
|
+
* or a URL. A materialised resource always has an `id`, which a location never has.
|
|
1052
|
+
*/
|
|
1053
|
+
function isActionLocation(value) {
|
|
1054
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || "id" in value) return false;
|
|
1055
|
+
const record = value;
|
|
1056
|
+
return typeof record["url"] === "string" && typeof record["type"] === "string";
|
|
1057
|
+
}
|
|
1058
|
+
/** A link's `href` and the object it came from, whether written as a string or a link object. */
|
|
1059
|
+
function linkObject(link) {
|
|
1060
|
+
if (typeof link === "string") return {
|
|
1061
|
+
href: link,
|
|
1062
|
+
link: {}
|
|
1063
|
+
};
|
|
1064
|
+
if (typeof link === "object" && link !== null && !Array.isArray(link)) {
|
|
1065
|
+
const object = link;
|
|
1066
|
+
return typeof object["href"] === "string" ? {
|
|
1067
|
+
href: object["href"],
|
|
1068
|
+
link: object
|
|
1069
|
+
} : void 0;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* The URL a location document carries, or `undefined` when the document is something else, such
|
|
1074
|
+
* as a resource document from an action that answers with either.
|
|
1075
|
+
*/
|
|
1076
|
+
function readActionLocation(doc, declared) {
|
|
1077
|
+
if (doc.data !== void 0) return;
|
|
1078
|
+
const location = linkObject(doc.links?.["location"]);
|
|
1079
|
+
if (location === void 0) return;
|
|
1080
|
+
const out = {
|
|
1081
|
+
url: location.href,
|
|
1082
|
+
type: typeof location.link["type"] === "string" ? location.link["type"] : declared.mediaType
|
|
1083
|
+
};
|
|
1084
|
+
const meta = location.link["meta"];
|
|
1085
|
+
const expiresAt = (typeof meta === "object" && meta !== null ? meta["expiresAt"] : void 0) ?? doc.meta?.["expiresAt"];
|
|
1086
|
+
if (typeof expiresAt === "string") out.expiresAt = expiresAt;
|
|
1087
|
+
return out;
|
|
1088
|
+
}
|
|
1089
|
+
//#endregion
|
|
1048
1090
|
//#region src/transport.ts
|
|
1049
1091
|
/** The default transport, backed by the global `fetch`. */
|
|
1050
1092
|
const fetchTransport = async (req) => {
|
|
@@ -1184,9 +1226,10 @@ async function runWrite(ctx, spec) {
|
|
|
1184
1226
|
*
|
|
1185
1227
|
* The response is shaped by the action's `output`: `document` materialises into the resource /
|
|
1186
1228
|
* collection view, `meta` returns the document's top-level `meta`, `none` resolves `undefined` (a
|
|
1187
|
-
* `204` / no body). An action declaring `
|
|
1188
|
-
*
|
|
1189
|
-
* JSON
|
|
1229
|
+
* `204` / no body). An action declaring a `location` returns the URL of a location document as an
|
|
1230
|
+
* `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
|
|
1231
|
+
* the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
|
|
1232
|
+
* `ArrayBuffer`, or parsed JSON by the media type's kind.
|
|
1190
1233
|
*/
|
|
1191
1234
|
async function runAction(ctx, action, vars, input, options = {}) {
|
|
1192
1235
|
const req = {
|
|
@@ -1219,7 +1262,12 @@ async function runAction(ctx, action, vars, input, options = {}) {
|
|
|
1219
1262
|
return raw.kind === "json" && text !== void 0 ? JSON.parse(text) : text;
|
|
1220
1263
|
}
|
|
1221
1264
|
const doc = await execute(ctx.request, req);
|
|
1222
|
-
if (action.
|
|
1265
|
+
if (action.location !== void 0) {
|
|
1266
|
+
const location = doc === void 0 ? void 0 : readActionLocation(doc, action.location);
|
|
1267
|
+
if (location !== void 0) return location;
|
|
1268
|
+
if (action.output === "location") throw new Error("The action answered without the location document it declares.");
|
|
1269
|
+
}
|
|
1270
|
+
if (action.output === "none" || action.output === "location" || doc === void 0) return;
|
|
1223
1271
|
if (action.output === "meta") return doc.meta;
|
|
1224
1272
|
return materialise(doc, ctx.materialise);
|
|
1225
1273
|
} catch (error) {
|
|
@@ -1493,6 +1541,15 @@ function createClient(descriptor, options) {
|
|
|
1493
1541
|
});
|
|
1494
1542
|
}
|
|
1495
1543
|
//#endregion
|
|
1544
|
+
//#region src/descriptor.ts
|
|
1545
|
+
/**
|
|
1546
|
+
* Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
|
|
1547
|
+
* flag is absent, listing more than one related type.
|
|
1548
|
+
*/
|
|
1549
|
+
function isPolymorphic(relation) {
|
|
1550
|
+
return relation.polymorphic ?? relation.types.length > 1;
|
|
1551
|
+
}
|
|
1552
|
+
//#endregion
|
|
1496
1553
|
exports.ATOMIC_EXT = ATOMIC_EXT;
|
|
1497
1554
|
exports.ATOMIC_MEDIA_TYPE = ATOMIC_MEDIA_TYPE;
|
|
1498
1555
|
exports.CANONICAL_PAGE_KEYS = CANONICAL_PAGE_KEYS;
|
|
@@ -1506,8 +1563,11 @@ exports.execute = execute;
|
|
|
1506
1563
|
exports.executeRaw = executeRaw;
|
|
1507
1564
|
exports.fetchTransport = fetchTransport;
|
|
1508
1565
|
exports.hasErrorCode = hasErrorCode;
|
|
1566
|
+
exports.isActionLocation = isActionLocation;
|
|
1567
|
+
exports.isPolymorphic = isPolymorphic;
|
|
1509
1568
|
exports.materialise = materialise;
|
|
1510
1569
|
exports.mediaType = mediaType;
|
|
1570
|
+
exports.readActionLocation = readActionLocation;
|
|
1511
1571
|
exports.relatedPaginator = relatedPaginator;
|
|
1512
1572
|
exports.relatedPaginatorKind = relatedPaginatorKind;
|
|
1513
1573
|
exports.remapPointer = remapPointer;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ReadResult, $t as
|
|
1
|
+
import { $ as ReadResult, $t as CANONICAL_PAGE_KEYS, A as BinaryBody, An as PaginatorStrategy, At as AtomicUpdateInput, B as ErrorCodeOf, Bt as DocumentEnvelope, C as TransportRawBody, Cn as InputMediaKind, Ct as AtomicDeleteHandle, D as ActionCallOptions, Dn as PaginatorDescriptor, Dt as AtomicResult, E as fetchTransport, En as OperationExamples, Et as AtomicRef, F as CreateInput, Fn as RelationMutations, Ft as LocalIdentifier, G as HydratedMember, Gt as MaterialiseContext, H as FieldsMap, Ht as EdgeEnvelope, I as DefaultActionTypes, In as ResourceDescriptor, It as MediaTypeParams, J as IncludedRelations, Jt as ResourceEnvelope, K as IdentifierMember, Kt as NavigateOptions, L as DefaultAttributes, Ln as ResourceExamples, Lt as ResourceIdentifier, M as Client, Mn as RawMediaKind, Mt as ATOMIC_EXT, N as Collection, Nn as RawOutputMedia, Nt as ATOMIC_MEDIA_TYPE, O as ActionsAccessor, On as PaginatorKind, Ot as AtomicResults, P as CountToken, Pn as RelationDescriptor, Pt as JSON_API_MEDIA_TYPE, Q as PivotInput, Qt as relatedPaginatorKind, R as DefaultWriteAttributes, Rn as StrategyDescriptor, Rt as mediaType, S as JsonApiTransport, Sn as InputMedia, St as AtomicCreateInput, T as TransportResponse, Tn as MenuDescriptor, Tt as AtomicRecorder, U as FilterKey, Ut as Link, V as FieldSelectionMap, Vt as Edge, W as FilterQuery, Wt as LinkObject, X as ListPageParams, Xt as materialise, Y as LinkageRef, Yt as ResourceLinks, Z as MemberName, Zt as relatedPaginator, _ as serializeQuery, _n as ApiExamples, _t as WriteOptions, a as Validator, an as PageOf, at as RelationshipAccessor, b as HeadersInit, bn as ClientIdPolicy, bt as readActionLocation, c as resolveValidator, cn as ResolvedPaginator, ct as ResourceObjectView, d as JsonApiContext, dn as ActionDescriptor, dt as SortToken, en as ExactPageParams, et as ReadableRelationName, f as JsonApiRequest, fn as ActionInput, ft as TypeAccessor, g as executeRaw, gn as ApiDescriptor, gt as WithLinks, h as execute, hn as ActionScope, ht as UpdateInput, i as ValidationOption, in as PageMeta, it as RelationReadQuery, j as BinaryResponseType, jn as PivotDescriptor, jt as runAtomic, k as AtomicResultOf, kn as PaginatorRole, kt as AtomicUpdateHandle, l as validateDocument, ln as TypedPage, lt as SingleReadQuery, m as ReadQuery, mn as ActionOutput, mt as TypedReadQuery, n as SchemaMap, nn as PageKeys, nt as RelationPageParams, o as WireResource, on as PageParams, ot as ResourceAccessors, p as RawResponseType, pn as ActionLocationDescriptor, pt as TypeName, q as IncludePath, qt as RelationView, r as ValidationConfig, rn as PageLinks, rt as RelationPaginator, s as assertJsonApiDocument, sn as PageParamsOf, st as ResourceHandle, t as ResolvedValidator, tn as Page, tt as RelationName, u as Document, un as resolvePaginator, ut as SortQuery, v as ClientOptions, vn as AtomicDescriptor, vt as ActionLocation, w as TransportRequest, wn as MediaExamples, wt as AtomicHandle, x as createClient, xn as CountableDescriptor, xt as AtomicCreateHandle, y as HANDLE_RESERVED, yn as Cardinality, yt as isActionLocation, z as EdgeMembers, zn as isPolymorphic, zt as ArrayEnvelope } from "./validate-CvUPfKwB.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/errors.d.ts
|
|
4
4
|
/**
|
|
@@ -216,5 +216,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
|
|
|
216
216
|
*/
|
|
217
217
|
declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
|
|
218
218
|
//#endregion
|
|
219
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, ActionCallOptions, ActionDescriptor, ActionInput, 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, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, InputMedia, InputMediaKind, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, materialise, mediaType, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
219
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, InputMedia, InputMediaKind, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
220
220
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as ReadResult, $t as
|
|
1
|
+
import { $ as ReadResult, $t as CANONICAL_PAGE_KEYS, A as BinaryBody, An as PaginatorStrategy, At as AtomicUpdateInput, B as ErrorCodeOf, Bt as DocumentEnvelope, C as TransportRawBody, Cn as InputMediaKind, Ct as AtomicDeleteHandle, D as ActionCallOptions, Dn as PaginatorDescriptor, Dt as AtomicResult, E as fetchTransport, En as OperationExamples, Et as AtomicRef, F as CreateInput, Fn as RelationMutations, Ft as LocalIdentifier, G as HydratedMember, Gt as MaterialiseContext, H as FieldsMap, Ht as EdgeEnvelope, I as DefaultActionTypes, In as ResourceDescriptor, It as MediaTypeParams, J as IncludedRelations, Jt as ResourceEnvelope, K as IdentifierMember, Kt as NavigateOptions, L as DefaultAttributes, Ln as ResourceExamples, Lt as ResourceIdentifier, M as Client, Mn as RawMediaKind, Mt as ATOMIC_EXT, N as Collection, Nn as RawOutputMedia, Nt as ATOMIC_MEDIA_TYPE, O as ActionsAccessor, On as PaginatorKind, Ot as AtomicResults, P as CountToken, Pn as RelationDescriptor, Pt as JSON_API_MEDIA_TYPE, Q as PivotInput, Qt as relatedPaginatorKind, R as DefaultWriteAttributes, Rn as StrategyDescriptor, Rt as mediaType, S as JsonApiTransport, Sn as InputMedia, St as AtomicCreateInput, T as TransportResponse, Tn as MenuDescriptor, Tt as AtomicRecorder, U as FilterKey, Ut as Link, V as FieldSelectionMap, Vt as Edge, W as FilterQuery, Wt as LinkObject, X as ListPageParams, Xt as materialise, Y as LinkageRef, Yt as ResourceLinks, Z as MemberName, Zt as relatedPaginator, _ as serializeQuery, _n as ApiExamples, _t as WriteOptions, a as Validator, an as PageOf, at as RelationshipAccessor, b as HeadersInit, bn as ClientIdPolicy, bt as readActionLocation, c as resolveValidator, cn as ResolvedPaginator, ct as ResourceObjectView, d as JsonApiContext, dn as ActionDescriptor, dt as SortToken, en as ExactPageParams, et as ReadableRelationName, f as JsonApiRequest, fn as ActionInput, ft as TypeAccessor, g as executeRaw, gn as ApiDescriptor, gt as WithLinks, h as execute, hn as ActionScope, ht as UpdateInput, i as ValidationOption, in as PageMeta, it as RelationReadQuery, j as BinaryResponseType, jn as PivotDescriptor, jt as runAtomic, k as AtomicResultOf, kn as PaginatorRole, kt as AtomicUpdateHandle, l as validateDocument, ln as TypedPage, lt as SingleReadQuery, m as ReadQuery, mn as ActionOutput, mt as TypedReadQuery, n as SchemaMap, nn as PageKeys, nt as RelationPageParams, o as WireResource, on as PageParams, ot as ResourceAccessors, p as RawResponseType, pn as ActionLocationDescriptor, pt as TypeName, q as IncludePath, qt as RelationView, r as ValidationConfig, rn as PageLinks, rt as RelationPaginator, s as assertJsonApiDocument, sn as PageParamsOf, st as ResourceHandle, t as ResolvedValidator, tn as Page, tt as RelationName, u as Document, un as resolvePaginator, ut as SortQuery, v as ClientOptions, vn as AtomicDescriptor, vt as ActionLocation, w as TransportRequest, wn as MediaExamples, wt as AtomicHandle, x as createClient, xn as CountableDescriptor, xt as AtomicCreateHandle, y as HANDLE_RESERVED, yn as Cardinality, yt as isActionLocation, z as EdgeMembers, zn as isPolymorphic, zt as ArrayEnvelope } from "./validate-CvUPfKwB.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/errors.d.ts
|
|
4
4
|
/**
|
|
@@ -216,5 +216,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
|
|
|
216
216
|
*/
|
|
217
217
|
declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
|
|
218
218
|
//#endregion
|
|
219
|
-
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, ActionCallOptions, ActionDescriptor, ActionInput, 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, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, InputMedia, InputMediaKind, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, materialise, mediaType, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
219
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, InputMedia, InputMediaKind, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
220
220
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1044,6 +1044,48 @@ function parseResults(doc, ctx) {
|
|
|
1044
1044
|
});
|
|
1045
1045
|
}
|
|
1046
1046
|
//#endregion
|
|
1047
|
+
//#region src/location.ts
|
|
1048
|
+
/**
|
|
1049
|
+
* Whether a value is an {@link ActionLocation}, for an action that answers with either a resource
|
|
1050
|
+
* or a URL. A materialised resource always has an `id`, which a location never has.
|
|
1051
|
+
*/
|
|
1052
|
+
function isActionLocation(value) {
|
|
1053
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || "id" in value) return false;
|
|
1054
|
+
const record = value;
|
|
1055
|
+
return typeof record["url"] === "string" && typeof record["type"] === "string";
|
|
1056
|
+
}
|
|
1057
|
+
/** A link's `href` and the object it came from, whether written as a string or a link object. */
|
|
1058
|
+
function linkObject(link) {
|
|
1059
|
+
if (typeof link === "string") return {
|
|
1060
|
+
href: link,
|
|
1061
|
+
link: {}
|
|
1062
|
+
};
|
|
1063
|
+
if (typeof link === "object" && link !== null && !Array.isArray(link)) {
|
|
1064
|
+
const object = link;
|
|
1065
|
+
return typeof object["href"] === "string" ? {
|
|
1066
|
+
href: object["href"],
|
|
1067
|
+
link: object
|
|
1068
|
+
} : void 0;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* The URL a location document carries, or `undefined` when the document is something else, such
|
|
1073
|
+
* as a resource document from an action that answers with either.
|
|
1074
|
+
*/
|
|
1075
|
+
function readActionLocation(doc, declared) {
|
|
1076
|
+
if (doc.data !== void 0) return;
|
|
1077
|
+
const location = linkObject(doc.links?.["location"]);
|
|
1078
|
+
if (location === void 0) return;
|
|
1079
|
+
const out = {
|
|
1080
|
+
url: location.href,
|
|
1081
|
+
type: typeof location.link["type"] === "string" ? location.link["type"] : declared.mediaType
|
|
1082
|
+
};
|
|
1083
|
+
const meta = location.link["meta"];
|
|
1084
|
+
const expiresAt = (typeof meta === "object" && meta !== null ? meta["expiresAt"] : void 0) ?? doc.meta?.["expiresAt"];
|
|
1085
|
+
if (typeof expiresAt === "string") out.expiresAt = expiresAt;
|
|
1086
|
+
return out;
|
|
1087
|
+
}
|
|
1088
|
+
//#endregion
|
|
1047
1089
|
//#region src/transport.ts
|
|
1048
1090
|
/** The default transport, backed by the global `fetch`. */
|
|
1049
1091
|
const fetchTransport = async (req) => {
|
|
@@ -1183,9 +1225,10 @@ async function runWrite(ctx, spec) {
|
|
|
1183
1225
|
*
|
|
1184
1226
|
* The response is shaped by the action's `output`: `document` materialises into the resource /
|
|
1185
1227
|
* collection view, `meta` returns the document's top-level `meta`, `none` resolves `undefined` (a
|
|
1186
|
-
* `204` / no body). An action declaring `
|
|
1187
|
-
*
|
|
1188
|
-
* JSON
|
|
1228
|
+
* `204` / no body). An action declaring a `location` returns the URL of a location document as an
|
|
1229
|
+
* `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
|
|
1230
|
+
* the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
|
|
1231
|
+
* `ArrayBuffer`, or parsed JSON by the media type's kind.
|
|
1189
1232
|
*/
|
|
1190
1233
|
async function runAction(ctx, action, vars, input, options = {}) {
|
|
1191
1234
|
const req = {
|
|
@@ -1218,7 +1261,12 @@ async function runAction(ctx, action, vars, input, options = {}) {
|
|
|
1218
1261
|
return raw.kind === "json" && text !== void 0 ? JSON.parse(text) : text;
|
|
1219
1262
|
}
|
|
1220
1263
|
const doc = await execute(ctx.request, req);
|
|
1221
|
-
if (action.
|
|
1264
|
+
if (action.location !== void 0) {
|
|
1265
|
+
const location = doc === void 0 ? void 0 : readActionLocation(doc, action.location);
|
|
1266
|
+
if (location !== void 0) return location;
|
|
1267
|
+
if (action.output === "location") throw new Error("The action answered without the location document it declares.");
|
|
1268
|
+
}
|
|
1269
|
+
if (action.output === "none" || action.output === "location" || doc === void 0) return;
|
|
1222
1270
|
if (action.output === "meta") return doc.meta;
|
|
1223
1271
|
return materialise(doc, ctx.materialise);
|
|
1224
1272
|
} catch (error) {
|
|
@@ -1492,6 +1540,15 @@ function createClient(descriptor, options) {
|
|
|
1492
1540
|
});
|
|
1493
1541
|
}
|
|
1494
1542
|
//#endregion
|
|
1495
|
-
|
|
1543
|
+
//#region src/descriptor.ts
|
|
1544
|
+
/**
|
|
1545
|
+
* Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
|
|
1546
|
+
* flag is absent, listing more than one related type.
|
|
1547
|
+
*/
|
|
1548
|
+
function isPolymorphic(relation) {
|
|
1549
|
+
return relation.polymorphic ?? relation.types.length > 1;
|
|
1550
|
+
}
|
|
1551
|
+
//#endregion
|
|
1552
|
+
export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, StructuralGuardError, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
|
|
1496
1553
|
|
|
1497
1554
|
//# sourceMappingURL=index.mjs.map
|