@haddowg/json-api-client 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,13 +39,14 @@ const client = createClient({
39
39
 
40
40
  `ClientOptions`:
41
41
 
42
- | Option | Type | Notes |
43
- | ----------- | ------------------------------------------- | ------------------------------------------------------------ |
44
- | `baseUrl` | `string` | Base URL the generated path templates resolve against. |
45
- | `transport` | `(req) => Promise<res>` | The transport seam; defaults to a `fetch` adapter. |
46
- | `headers` | `() => HeadersInit \| Promise<HeadersInit>` | Per-request header provider (bearer auth, etc.). |
47
- | `atomic` | `AtomicDescriptor \| null` | Atomic endpoint; the generated `createClient` threads it in. |
48
- | `validate` | `ValidationOption` | Opt-in per-field validation seam (off by default). |
42
+ | Option | Type | Notes |
43
+ | ----------------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------- |
44
+ | `baseUrl` | `string` | Base URL the generated path templates resolve against. |
45
+ | `transport` | `(req) => Promise<res>` | The transport seam; defaults to a `fetch` adapter. |
46
+ | `headers` | `() => HeadersInit \| Promise<HeadersInit>` | Per-request header provider (bearer auth, etc.). |
47
+ | `allowCrossOriginLinks` | `boolean` | Follow a `$next()`/`$prev()` link to another origin, sent without `headers`. Off by default. |
48
+ | `atomic` | `AtomicDescriptor \| null` | Atomic endpoint; the generated `createClient` threads it in. |
49
+ | `validate` | `ValidationOption` | Opt-in per-field validation seam (off by default). |
49
50
 
50
51
  ## Reads
51
52
 
@@ -65,7 +66,7 @@ const albums = await client.albums.list({
65
66
 
66
67
  albums[0]!.title // string
67
68
  albums[0]!.artist?.name // hydrated artist resource (its attributes are typed)
68
- albums.$page.kind // 'page' | 'offset' | 'cursor' | 'none'
69
+ albums.$page.kind // 'page' (typed from the descriptor's paginator)
69
70
  albums.$meta?.['page'] // raw top-level meta
70
71
  ```
71
72
 
package/dist/ajv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Validator, n as SchemaMap } from "./validate-C5uKB1UK.cjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-BLXEfy75.cjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/ajv.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Validator, n as SchemaMap } from "./validate-C5uKB1UK.mjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-BLXEfy75.mjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/errors.ts
3
3
  /**
4
- * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
4
+ * Thrown by the always-on light structural guards when a parsed response is not a
5
5
  * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
6
6
  * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
7
7
  * runtime relies on was violated, not an application error the server reported. The opt-in
@@ -231,7 +231,7 @@ const defineGetter = (target, key, get) => {
231
231
  });
232
232
  };
233
233
  /**
234
- * Materialise a JSON:API document into a hydrated graph (ADR 0002 / CONTEXT.md):
234
+ * Materialise a JSON:API document into a hydrated graph (ADR 0002):
235
235
  *
236
236
  * - single resource -> a flattened resource object (own enumerable type/id/attributes/
237
237
  * relations + non-enumerable `$`-accessors);
@@ -357,7 +357,7 @@ function attachResourceEnvelope(node, raw, env, rels) {
357
357
  * edge-local `$edge`/`$pivot`. Identity is by `type:id`, never reference.
358
358
  *
359
359
  * `relationEdge` (set for a to-one) carries the relationship object's self/related links and
360
- * meta, which ride the value's `$edge` per CONTEXT.md.
360
+ * meta, which ride the value's `$edge` (docs/materialisation.md).
361
361
  */
362
362
  function buildEdgeView(node, member, relationEdge) {
363
363
  const view = {};
@@ -576,7 +576,7 @@ const isPlainObject$1 = (value) => typeof value === "object" && value !== null &
576
576
  * value — a `Range`/`DateRange` deepObject (`{ min, max }`) — and recurses into nested bracketed
577
577
  * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array joins with `,`;
578
578
  * a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
579
- * wire as `filter[k]=[object Object]` and be silently ignored by the server (D23).
579
+ * wire as `filter[k]=[object Object]` and be silently ignored by the server.
580
580
  */
581
581
  const appendFilterValue = (parts, key, value) => {
582
582
  if (isPlainObject$1(value)) {
@@ -793,7 +793,7 @@ const describe = (value) => value === null ? "null" : Array.isArray(value) ? "an
793
793
  * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
794
794
  *
795
795
  * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
796
- * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
796
+ * `JsonPointerBuilder::forLinkageMeta`), so a `meta/pivot/<field>` tail on
797
797
  * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
798
798
  *
799
799
  * A query-side pointer is left untouched (those are already user-facing — see
@@ -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 `rawOutput` answers in the media type the caller picks
1188
- * with `options.accept`: JSON:API as above, or a `string`, a `Blob` or `ArrayBuffer`, or parsed
1189
- * JSON by the media type's kind.
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.output === "none" || doc === void 0) return;
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) {
@@ -1515,9 +1563,11 @@ exports.execute = execute;
1515
1563
  exports.executeRaw = executeRaw;
1516
1564
  exports.fetchTransport = fetchTransport;
1517
1565
  exports.hasErrorCode = hasErrorCode;
1566
+ exports.isActionLocation = isActionLocation;
1518
1567
  exports.isPolymorphic = isPolymorphic;
1519
1568
  exports.materialise = materialise;
1520
1569
  exports.mediaType = mediaType;
1570
+ exports.readActionLocation = readActionLocation;
1521
1571
  exports.relatedPaginator = relatedPaginator;
1522
1572
  exports.relatedPaginatorKind = relatedPaginatorKind;
1523
1573
  exports.remapPointer = remapPointer;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as ReadResult, $t as PageKeys, A as BinaryBody, An as RelationDescriptor, At as ATOMIC_MEDIA_TYPE, B as ErrorCodeOf, Bt as Link, C as TransportRawBody, Cn as PaginatorDescriptor, Ct as AtomicRef, D as ActionCallOptions, Dn as PivotDescriptor, Dt as AtomicUpdateInput, E as fetchTransport, En as PaginatorStrategy, Et as AtomicUpdateHandle, F as CreateInput, Fn as isPolymorphic, Ft as mediaType, G as HydratedMember, Gt as ResourceEnvelope, H as FieldsMap, Ht as MaterialiseContext, I as DefaultActionTypes, It as ArrayEnvelope, J as IncludedRelations, Jt as relatedPaginator, K as IdentifierMember, Kt as ResourceLinks, L as DefaultAttributes, Lt as DocumentEnvelope, M as Client, Mn as ResourceDescriptor, Mt as LocalIdentifier, N as Collection, Nn as ResourceExamples, Nt as MediaTypeParams, O as ActionsAccessor, On as RawMediaKind, Ot as runAtomic, P as CountToken, Pn as StrategyDescriptor, Pt as ResourceIdentifier, Q as PivotInput, Qt as Page, R as DefaultWriteAttributes, Rt as Edge, S as JsonApiTransport, Sn as OperationExamples, St as AtomicRecorder, T as TransportResponse, Tn as PaginatorRole, Tt as AtomicResults, U as FilterKey, Ut as NavigateOptions, V as FieldSelectionMap, Vt as LinkObject, W as FilterQuery, Wt as RelationView, X as ListPageParams, Xt as CANONICAL_PAGE_KEYS, Y as LinkageRef, Yt as relatedPaginatorKind, Z as MemberName, Zt as ExactPageParams, _ as serializeQuery, _n as CountableDescriptor, _t as WriteOptions, a as Validator, an as ResolvedPaginator, at as RelationshipAccessor, b as HeadersInit, bn as MediaExamples, bt as AtomicDeleteHandle, c as resolveValidator, cn as ActionDescriptor, ct as ResourceObjectView, d as JsonApiContext, dn as ActionScope, dt as SortToken, en as PageLinks, et as ReadableRelationName, f as JsonApiRequest, fn as ApiDescriptor, ft as TypeAccessor, g as executeRaw, gn as ClientIdPolicy, gt as WithLinks, h as execute, hn as Cardinality, ht as UpdateInput, i as ValidationOption, in as PageParamsOf, it as RelationReadQuery, j as BinaryResponseType, jn as RelationMutations, jt as JSON_API_MEDIA_TYPE, k as AtomicResultOf, kn as RawOutputMedia, kt as ATOMIC_EXT, l as validateDocument, ln as ActionInput, lt as SingleReadQuery, m as ReadQuery, mn as AtomicDescriptor, mt as TypedReadQuery, n as SchemaMap, nn as PageOf, nt as RelationPageParams, o as WireResource, on as TypedPage, ot as ResourceAccessors, p as RawResponseType, pn as ApiExamples, pt as TypeName, q as IncludePath, qt as materialise, r as ValidationConfig, rn as PageParams, rt as RelationPaginator, s as assertJsonApiDocument, sn as resolvePaginator, st as ResourceHandle, t as ResolvedValidator, tn as PageMeta, tt as RelationName, u as Document, un as ActionOutput, ut as SortQuery, v as ClientOptions, vn as InputMedia, vt as AtomicCreateHandle, w as TransportRequest, wn as PaginatorKind, wt as AtomicResult, x as createClient, xn as MenuDescriptor, xt as AtomicHandle, y as HANDLE_RESERVED, yn as InputMediaKind, yt as AtomicCreateInput, z as EdgeMembers, zt as EdgeEnvelope } from "./validate-C5uKB1UK.cjs";
1
+ import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as OperationExamples, At as AtomicRef, B as ErrorCodeOf, Bn as ResourceDescriptor, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMediaKind, Dt as AtomicDeleteHandle, E as fetchTransport, En as InputMedia, Et as AtomicCreateInput, F as CreateInput, Fn as PivotDescriptor, Ft as runAtomic, G as HydratedMember, Gt as Edge, H as FieldsMap, Hn as StrategyDescriptor, Ht as mediaType, I as DefaultActionTypes, In as RawMediaKind, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawOutputMedia, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorKind, Mt as AtomicResults, N as Collection, Nn as PaginatorRole, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as MediaExamples, Ot as AtomicHandle, P as CountToken, Pn as PaginatorStrategy, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RelationDescriptor, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as isPolymorphic, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceExamples, Vt as ResourceIdentifier, W as FilterQuery, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as PaginatorDescriptor, jt as AtomicResult, k as AtomicResultOf, kn as MenuDescriptor, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationMutations, zt as LocalIdentifier } from "./validate-BLXEfy75.cjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -23,7 +23,7 @@ interface JsonApiErrorObject<C extends string = string> {
23
23
  /**
24
24
  * The user-facing input path, remapped from `source.pointer` for write errors
25
25
  * (e.g. `/data/attributes/title` -> `title`). Populated by the runtime, which
26
- * built the envelope and therefore knows the inverse mapping. See CONTEXT.md.
26
+ * built the envelope and therefore knows the inverse mapping. See docs/errors.md.
27
27
  */
28
28
  path?: string;
29
29
  /**
@@ -34,7 +34,7 @@ interface JsonApiErrorObject<C extends string = string> {
34
34
  opIndex?: number;
35
35
  }
36
36
  /**
37
- * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
37
+ * Thrown by the always-on light structural guards when a parsed response is not a
38
38
  * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
39
39
  * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
40
40
  * runtime relies on was violated, not an application error the server reported. The opt-in
@@ -163,7 +163,7 @@ declare function toRelationshipDocument(refs: unknown, cardinality: 'one' | 'man
163
163
  * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
164
164
  *
165
165
  * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
166
- * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
166
+ * `JsonPointerBuilder::forLinkageMeta`), so a `meta/pivot/<field>` tail on
167
167
  * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
168
168
  *
169
169
  * A query-side pointer is left untouched (those are already user-facing — see
@@ -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, isPolymorphic, 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, IncludedResource, IncludedType, 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, RelatedIncludedResource, RelatedIncludedType, 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 PageKeys, A as BinaryBody, An as RelationDescriptor, At as ATOMIC_MEDIA_TYPE, B as ErrorCodeOf, Bt as Link, C as TransportRawBody, Cn as PaginatorDescriptor, Ct as AtomicRef, D as ActionCallOptions, Dn as PivotDescriptor, Dt as AtomicUpdateInput, E as fetchTransport, En as PaginatorStrategy, Et as AtomicUpdateHandle, F as CreateInput, Fn as isPolymorphic, Ft as mediaType, G as HydratedMember, Gt as ResourceEnvelope, H as FieldsMap, Ht as MaterialiseContext, I as DefaultActionTypes, It as ArrayEnvelope, J as IncludedRelations, Jt as relatedPaginator, K as IdentifierMember, Kt as ResourceLinks, L as DefaultAttributes, Lt as DocumentEnvelope, M as Client, Mn as ResourceDescriptor, Mt as LocalIdentifier, N as Collection, Nn as ResourceExamples, Nt as MediaTypeParams, O as ActionsAccessor, On as RawMediaKind, Ot as runAtomic, P as CountToken, Pn as StrategyDescriptor, Pt as ResourceIdentifier, Q as PivotInput, Qt as Page, R as DefaultWriteAttributes, Rt as Edge, S as JsonApiTransport, Sn as OperationExamples, St as AtomicRecorder, T as TransportResponse, Tn as PaginatorRole, Tt as AtomicResults, U as FilterKey, Ut as NavigateOptions, V as FieldSelectionMap, Vt as LinkObject, W as FilterQuery, Wt as RelationView, X as ListPageParams, Xt as CANONICAL_PAGE_KEYS, Y as LinkageRef, Yt as relatedPaginatorKind, Z as MemberName, Zt as ExactPageParams, _ as serializeQuery, _n as CountableDescriptor, _t as WriteOptions, a as Validator, an as ResolvedPaginator, at as RelationshipAccessor, b as HeadersInit, bn as MediaExamples, bt as AtomicDeleteHandle, c as resolveValidator, cn as ActionDescriptor, ct as ResourceObjectView, d as JsonApiContext, dn as ActionScope, dt as SortToken, en as PageLinks, et as ReadableRelationName, f as JsonApiRequest, fn as ApiDescriptor, ft as TypeAccessor, g as executeRaw, gn as ClientIdPolicy, gt as WithLinks, h as execute, hn as Cardinality, ht as UpdateInput, i as ValidationOption, in as PageParamsOf, it as RelationReadQuery, j as BinaryResponseType, jn as RelationMutations, jt as JSON_API_MEDIA_TYPE, k as AtomicResultOf, kn as RawOutputMedia, kt as ATOMIC_EXT, l as validateDocument, ln as ActionInput, lt as SingleReadQuery, m as ReadQuery, mn as AtomicDescriptor, mt as TypedReadQuery, n as SchemaMap, nn as PageOf, nt as RelationPageParams, o as WireResource, on as TypedPage, ot as ResourceAccessors, p as RawResponseType, pn as ApiExamples, pt as TypeName, q as IncludePath, qt as materialise, r as ValidationConfig, rn as PageParams, rt as RelationPaginator, s as assertJsonApiDocument, sn as resolvePaginator, st as ResourceHandle, t as ResolvedValidator, tn as PageMeta, tt as RelationName, u as Document, un as ActionOutput, ut as SortQuery, v as ClientOptions, vn as InputMedia, vt as AtomicCreateHandle, w as TransportRequest, wn as PaginatorKind, wt as AtomicResult, x as createClient, xn as MenuDescriptor, xt as AtomicHandle, y as HANDLE_RESERVED, yn as InputMediaKind, yt as AtomicCreateInput, z as EdgeMembers, zt as EdgeEnvelope } from "./validate-C5uKB1UK.mjs";
1
+ import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as OperationExamples, At as AtomicRef, B as ErrorCodeOf, Bn as ResourceDescriptor, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMediaKind, Dt as AtomicDeleteHandle, E as fetchTransport, En as InputMedia, Et as AtomicCreateInput, F as CreateInput, Fn as PivotDescriptor, Ft as runAtomic, G as HydratedMember, Gt as Edge, H as FieldsMap, Hn as StrategyDescriptor, Ht as mediaType, I as DefaultActionTypes, In as RawMediaKind, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawOutputMedia, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorKind, Mt as AtomicResults, N as Collection, Nn as PaginatorRole, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as MediaExamples, Ot as AtomicHandle, P as CountToken, Pn as PaginatorStrategy, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RelationDescriptor, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as isPolymorphic, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceExamples, Vt as ResourceIdentifier, W as FilterQuery, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as PaginatorDescriptor, jt as AtomicResult, k as AtomicResultOf, kn as MenuDescriptor, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationMutations, zt as LocalIdentifier } from "./validate-BLXEfy75.mjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -23,7 +23,7 @@ interface JsonApiErrorObject<C extends string = string> {
23
23
  /**
24
24
  * The user-facing input path, remapped from `source.pointer` for write errors
25
25
  * (e.g. `/data/attributes/title` -> `title`). Populated by the runtime, which
26
- * built the envelope and therefore knows the inverse mapping. See CONTEXT.md.
26
+ * built the envelope and therefore knows the inverse mapping. See docs/errors.md.
27
27
  */
28
28
  path?: string;
29
29
  /**
@@ -34,7 +34,7 @@ interface JsonApiErrorObject<C extends string = string> {
34
34
  opIndex?: number;
35
35
  }
36
36
  /**
37
- * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
37
+ * Thrown by the always-on light structural guards when a parsed response is not a
38
38
  * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
39
39
  * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
40
40
  * runtime relies on was violated, not an application error the server reported. The opt-in
@@ -163,7 +163,7 @@ declare function toRelationshipDocument(refs: unknown, cardinality: 'one' | 'man
163
163
  * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
164
164
  *
165
165
  * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
166
- * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
166
+ * `JsonPointerBuilder::forLinkageMeta`), so a `meta/pivot/<field>` tail on
167
167
  * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
168
168
  *
169
169
  * A query-side pointer is left untouched (those are already user-facing — see
@@ -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, isPolymorphic, 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, IncludedResource, IncludedType, 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, RelatedIncludedResource, RelatedIncludedType, 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
@@ -1,6 +1,6 @@
1
1
  //#region src/errors.ts
2
2
  /**
3
- * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
3
+ * Thrown by the always-on light structural guards when a parsed response is not a
4
4
  * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
5
5
  * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
6
6
  * runtime relies on was violated, not an application error the server reported. The opt-in
@@ -230,7 +230,7 @@ const defineGetter = (target, key, get) => {
230
230
  });
231
231
  };
232
232
  /**
233
- * Materialise a JSON:API document into a hydrated graph (ADR 0002 / CONTEXT.md):
233
+ * Materialise a JSON:API document into a hydrated graph (ADR 0002):
234
234
  *
235
235
  * - single resource -> a flattened resource object (own enumerable type/id/attributes/
236
236
  * relations + non-enumerable `$`-accessors);
@@ -356,7 +356,7 @@ function attachResourceEnvelope(node, raw, env, rels) {
356
356
  * edge-local `$edge`/`$pivot`. Identity is by `type:id`, never reference.
357
357
  *
358
358
  * `relationEdge` (set for a to-one) carries the relationship object's self/related links and
359
- * meta, which ride the value's `$edge` per CONTEXT.md.
359
+ * meta, which ride the value's `$edge` (docs/materialisation.md).
360
360
  */
361
361
  function buildEdgeView(node, member, relationEdge) {
362
362
  const view = {};
@@ -575,7 +575,7 @@ const isPlainObject$1 = (value) => typeof value === "object" && value !== null &
575
575
  * value — a `Range`/`DateRange` deepObject (`{ min, max }`) — and recurses into nested bracketed
576
576
  * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array joins with `,`;
577
577
  * a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
578
- * wire as `filter[k]=[object Object]` and be silently ignored by the server (D23).
578
+ * wire as `filter[k]=[object Object]` and be silently ignored by the server.
579
579
  */
580
580
  const appendFilterValue = (parts, key, value) => {
581
581
  if (isPlainObject$1(value)) {
@@ -792,7 +792,7 @@ const describe = (value) => value === null ? "null" : Array.isArray(value) ? "an
792
792
  * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
793
793
  *
794
794
  * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
795
- * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
795
+ * `JsonPointerBuilder::forLinkageMeta`), so a `meta/pivot/<field>` tail on
796
796
  * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
797
797
  *
798
798
  * A query-side pointer is left untouched (those are already user-facing — see
@@ -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 `rawOutput` answers in the media type the caller picks
1187
- * with `options.accept`: JSON:API as above, or a `string`, a `Blob` or `ArrayBuffer`, or parsed
1188
- * JSON by the media type's kind.
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.output === "none" || doc === void 0) return;
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) {
@@ -1501,6 +1549,6 @@ function isPolymorphic(relation) {
1501
1549
  return relation.polymorphic ?? relation.types.length > 1;
1502
1550
  }
1503
1551
  //#endregion
1504
- export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, StructuralGuardError, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, hasErrorCode, isPolymorphic, materialise, mediaType, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
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 };
1505
1553
 
1506
1554
  //# sourceMappingURL=index.mjs.map