@haddowg/json-api-client 1.20.0 → 1.22.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
@@ -120,8 +120,9 @@ ordered[0]!.$pivot?.['position'] // edge-local pivot data
120
120
 
121
121
  ### `withCount` (the Countable profile)
122
122
 
123
- `withCount` is constrained to the type's count tokens and only available on `list` / related
124
- reads (no single-`get` endpoint advertises it). The client negotiates the Countable profile in
123
+ `withCount` is constrained to the count tokens of the operation that sends it: `list`, a related
124
+ read, and `get`, `create` and `update` where the server documents it there. One resource has no
125
+ collection, so those three never take `_self_`. The client negotiates the Countable profile in
125
126
  `Accept` automatically when `withCount` is present.
126
127
 
127
128
  ```ts
@@ -135,10 +136,12 @@ the same value as `$count`. Both are `undefined` when the server sent no finite
135
136
 
136
137
  ### `relatedQuery` (the Relationship Queries profile)
137
138
 
138
- Where a type's `list` or `get` advertises it, `relatedQuery` filters and sorts a relationship
139
- from the primary read, keyed by include path. Each entry's `filter` and `sort` take what the
140
- relation's own related read takes. The client negotiates the profile in `Accept`, beside the
141
- Countable one when `withCount` is set too.
139
+ Where the server documents it, `relatedQuery` filters and sorts a relationship of the resources
140
+ an operation answers with: `list`, `get`, `create`, `update`, the `.related()` read of a relation
141
+ over one type, and an action answering with a resource. It's keyed by relation name, and each
142
+ entry's `filter` and `sort` take what the relation's own related read takes, with no `sort` on a
143
+ to-one. The client negotiates the profile in `Accept`, beside the Countable one when `withCount`
144
+ is set too.
142
145
 
143
146
  ```ts
144
147
  const runs = await client['campaign-template-runs'].list({
package/dist/ajv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Validator, n as SchemaMap } from "./validate-0UvXQg-n.cjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-Rgo7Zm0U.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-0UvXQg-n.mjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-Rgo7Zm0U.mjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/index.cjs CHANGED
@@ -184,7 +184,7 @@ const appendFilterValue = (parts, key, value, list = false) => {
184
184
  * (`filter[title]`, `page[number]`, `fields[albums]`) are kept literal; only values
185
185
  * are percent-encoded. `isListFilter` names the filter keys that take a list, whose array value
186
186
  * goes out as `filter[<key>][]` once per member, and `isRelatedListFilter` does the same for a
187
- * `relatedQuery` entry's filters by include path. Empty/undefined entries are skipped; key order is deterministic
187
+ * `relatedQuery` entry's filters by relation. Empty/undefined entries are skipped; key order is deterministic
188
188
  * (family order, then insertion order within a family) so URLs are stable for caching.
189
189
  */
190
190
  function serializeQuery(query, isListFilter, isRelatedListFilter) {
@@ -194,9 +194,9 @@ function serializeQuery(query, isListFilter, isRelatedListFilter) {
194
194
  if (query.include) append(parts, "include", query.include.join(","));
195
195
  if (query.fields) for (const [type, names] of Object.entries(query.fields)) parts.push(`fields[${type}]=${encodeURIComponent(names.join(","))}`);
196
196
  if (query.withCount && query.withCount.length > 0) append(parts, "withCount", query.withCount.join(","));
197
- for (const [path, entry] of Object.entries(query.relatedQuery ?? {})) {
198
- for (const [key, value] of Object.entries(entry?.filter ?? {})) appendFilterValue(parts, `relatedQuery[${path}][filter][${key}]`, value, isRelatedListFilter?.(path, key) ?? false);
199
- if (entry?.sort !== void 0) append(parts, `relatedQuery[${path}][sort]`, typeof entry.sort === "string" ? entry.sort : entry.sort.join(","));
197
+ for (const [relation, entry] of Object.entries(query.relatedQuery ?? {})) {
198
+ for (const [key, value] of Object.entries(entry?.filter ?? {})) appendFilterValue(parts, `relatedQuery[${relation}][filter][${key}]`, value, isRelatedListFilter?.(relation, key) ?? false);
199
+ if (entry?.sort !== void 0) append(parts, `relatedQuery[${relation}][sort]`, typeof entry.sort === "string" ? entry.sort : entry.sort.join(","));
200
200
  }
201
201
  if (query.page) for (const [key, value] of Object.entries(query.page)) append(parts, `page[${key}]`, Array.isArray(value) ? value.join(",") : value);
202
202
  return parts.join("&");
@@ -1199,6 +1199,15 @@ function parseResults(doc, ctx) {
1199
1199
  });
1200
1200
  }
1201
1201
  //#endregion
1202
+ //#region src/descriptor.ts
1203
+ /**
1204
+ * Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
1205
+ * flag is absent, listing more than one related type.
1206
+ */
1207
+ function isPolymorphic(relation) {
1208
+ return relation.polymorphic ?? relation.types.length > 1;
1209
+ }
1210
+ //#endregion
1202
1211
  //#region src/filters.ts
1203
1212
  /**
1204
1213
  * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
@@ -1333,9 +1342,9 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1333
1342
  req.query = params;
1334
1343
  const listFilter = listFilterMatcher(filterSpec(ctx, type, operation, vars["rel"]));
1335
1344
  if (listFilter !== void 0) req.listFilter = listFilter;
1336
- if (params.relatedQuery !== void 0) req.relatedListFilter = relatedListFilter(ctx, type);
1337
1345
  if (signal !== void 0) req.signal = signal;
1338
- negotiateProfiles(ctx, type, params, req, relationForCount);
1346
+ negotiateProfiles(ctx, type, params, req, relationForCount, operation);
1347
+ applyRelatedQuery(ctx, renderedType(ctx, type, operation, vars["rel"]), params, req);
1339
1348
  }
1340
1349
  const doc = await execute(ctx.request, req);
1341
1350
  const relation = (operation === "fetchRelated" || operation === "fetchRelationship") && vars["rel"] !== void 0 ? ctx.descriptor[type]?.relations[vars["rel"]] : void 0;
@@ -1357,57 +1366,65 @@ function filterSpec(ctx, type, operation, rel) {
1357
1366
  return types?.length === 1 ? ctx.descriptor[types[0]] : void 0;
1358
1367
  }
1359
1368
  /**
1360
- * Whether a `relatedQuery` entry's filter key takes a list, matched against the vocabulary of the
1361
- * relation its include path ends on, as that relation's related read matches it. A path through a
1362
- * polymorphic relation continues from the first member type declaring the next relation.
1369
+ * The type whose resources an operation answers with, which keys its `relatedQuery`: the type
1370
+ * itself, or a related read's related type when the relation is monomorphic. A relationship read
1371
+ * answers with linkage, so it has none.
1363
1372
  */
1364
- function relatedListFilter(ctx, type) {
1365
- const matchers = /* @__PURE__ */ new Map();
1366
- return (path, key) => {
1367
- if (!matchers.has(path)) matchers.set(path, listFilterMatcher(relatedQuerySpec(ctx, type, path)));
1368
- return matchers.get(path)?.(key) ?? false;
1369
- };
1370
- }
1371
- /** The filter vocabulary of the relation an include path from `type` ends on. */
1372
- function relatedQuerySpec(ctx, type, path) {
1373
- const names = path.split(".");
1374
- let owners = [type];
1375
- for (const [index, name] of names.entries()) {
1376
- const owner = owners.find((t) => ctx.descriptor[t]?.relations[name] !== void 0);
1377
- if (owner === void 0) return;
1378
- if (index === names.length - 1) return filterSpec(ctx, owner, "fetchRelated", name);
1379
- owners = ctx.descriptor[owner].relations[name].types;
1380
- }
1373
+ function renderedType(ctx, type, operation, rel) {
1374
+ if (operation === "fetchRelationship") return;
1375
+ if (operation !== "fetchRelated") return type;
1376
+ const relation = rel === void 0 ? void 0 : ctx.descriptor[type]?.relations[rel];
1377
+ return relation === void 0 || isPolymorphic(relation) ? void 0 : relation.types[0];
1381
1378
  }
1382
- /** Whether a `relatedQuery` carries a filter or sort for any path, so it reaches the wire. */
1379
+ /** Whether a `relatedQuery` carries a filter or sort for any relation, so it reaches the wire. */
1383
1380
  function sendsRelatedQuery(relatedQuery) {
1384
1381
  return Object.values(relatedQuery ?? {}).some((entry) => Object.keys(entry?.filter ?? {}).length > 0 || entry?.sort !== void 0 && entry.sort.length > 0);
1385
1382
  }
1386
1383
  /**
1387
- * Add any profiles a query's parameters require to the request's negotiated `profiles`. A
1388
- * `withCount` read needs the type's Countable profile in `Accept` — else the server rejects it
1389
- * (400) under strict query-param validation. The profile URI is read from the descriptor's
1390
- * `countable` block (never hardcoded); absent when the type advertises no Countable profile. A
1391
- * `relatedQuery` on a collection or single read likewise adds the type's Relationship Queries
1392
- * profile, after any Countable one.
1384
+ * Prepare a request's `relatedQuery` for resources of type `rendered`: match each entry's list
1385
+ * filters against its relation's related-read vocabulary, and negotiate the type's Relationship
1386
+ * Queries profile, after any Countable one, when the query sends an entry.
1393
1387
  */
1394
- function negotiateProfiles(ctx, type, query, req, relationForCount) {
1388
+ function applyRelatedQuery(ctx, rendered, query, req) {
1389
+ if (rendered === void 0 || !sendsRelatedQuery(query.relatedQuery)) return;
1390
+ const matchers = /* @__PURE__ */ new Map();
1391
+ req.relatedListFilter = (rel, key) => {
1392
+ if (!matchers.has(rel)) matchers.set(rel, listFilterMatcher(filterSpec(ctx, rendered, "fetchRelated", rel)));
1393
+ return matchers.get(rel)?.(key) ?? false;
1394
+ };
1395
+ const profile = ctx.descriptor[rendered]?.relatedQuery?.profile;
1396
+ if (profile !== void 0 && !(req.profiles ?? []).includes(profile)) req.profiles = [...req.profiles ?? [], profile];
1397
+ }
1398
+ /**
1399
+ * Add the Countable profile a query's `withCount` requires to the request's negotiated
1400
+ * `profiles`. A `withCount` read or write needs it in `Accept`, else the server rejects it (400)
1401
+ * under strict query-param validation. The profile URI is read from the descriptor (never
1402
+ * hardcoded): the relation's `countable` for a related or relationship read, the operation's
1403
+ * `resourceCountable` entry for a single-resource read or a write, else the type's `countable`.
1404
+ */
1405
+ function negotiateProfiles(ctx, type, query, req, relationForCount, operation) {
1395
1406
  const profiles = [];
1396
1407
  if (query.withCount !== void 0 && query.withCount.length > 0) {
1397
- const profile = relationForCount !== void 0 ? ctx.descriptor[type]?.relations[relationForCount]?.countable?.profile : ctx.descriptor[type]?.countable?.profile;
1408
+ const descriptor = ctx.descriptor[type];
1409
+ const profile = relationForCount !== void 0 ? descriptor?.relations[relationForCount]?.countable?.profile : (isResourceCountOperation(operation) ? descriptor?.resourceCountable?.[operation]?.profile : void 0) ?? descriptor?.countable?.profile;
1398
1410
  if (profile !== void 0) profiles.push(profile);
1399
1411
  }
1400
- if (relationForCount === void 0 && sendsRelatedQuery(query.relatedQuery)) {
1401
- const profile = ctx.descriptor[type]?.relatedQuery?.profile;
1402
- if (profile !== void 0 && !profiles.includes(profile)) profiles.push(profile);
1403
- }
1404
1412
  if (profiles.length > 0) req.profiles = [...req.profiles ?? [], ...profiles];
1405
1413
  }
1406
- /** Project a write's opts to the read-query families the response honours (`include`/`fields`). */
1414
+ /** Whether an operation is one answering with one resource that may take `withCount`. */
1415
+ function isResourceCountOperation(operation) {
1416
+ return operation === "fetchOne" || operation === "create" || operation === "update";
1417
+ }
1418
+ /**
1419
+ * Project a write's opts to the read-query families the response honours: `include`, `fields`,
1420
+ * `withCount` and `relatedQuery`.
1421
+ */
1407
1422
  function writeQuery(opts) {
1408
1423
  if (opts === void 0) return;
1409
1424
  const query = {};
1410
1425
  if (opts.include !== void 0) query.include = [...opts.include];
1426
+ if (opts.withCount !== void 0) query.withCount = [...opts.withCount];
1427
+ if (opts.relatedQuery !== void 0) query.relatedQuery = opts.relatedQuery;
1411
1428
  if (opts.fields !== void 0) {
1412
1429
  const fields = {};
1413
1430
  for (const [k, v] of Object.entries(opts.fields)) fields[k] = [...v];
@@ -1447,7 +1464,12 @@ async function runWrite(ctx, spec) {
1447
1464
  path: fillPath(ctx, spec.type, template, spec.vars),
1448
1465
  body: spec.body
1449
1466
  };
1450
- if (spec.query !== void 0) req.query = spec.query;
1467
+ if (spec.query !== void 0) {
1468
+ req.query = spec.query;
1469
+ negotiateProfiles(ctx, spec.type, spec.query, req, void 0, spec.operation);
1470
+ applyRelatedQuery(ctx, spec.type, spec.query, req);
1471
+ if (req.profiles !== void 0) req.contentType = JSON_API_MEDIA_TYPE;
1472
+ }
1451
1473
  if (spec.wait?.signal !== void 0) req.signal = spec.wait.signal;
1452
1474
  let res;
1453
1475
  try {
@@ -1481,7 +1503,8 @@ async function runWrite(ctx, spec) {
1481
1503
  * `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
1482
1504
  * the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
1483
1505
  * `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
1484
- * sends `options.filter` in the query string as a collection read does. A `202` the action
1506
+ * sends `options.filter` in the query string as a collection read does, and an action answering
1507
+ * with a resource sends `options.relatedQuery` as a read does. A `202` the action
1485
1508
  * declares resolves to an `Accepted` job, or with `options.wait` to the value its job URL ends at.
1486
1509
  */
1487
1510
  async function runAction(ctx, action, vars, input, options = {}) {
@@ -1495,6 +1518,13 @@ async function runAction(ctx, action, vars, input, options = {}) {
1495
1518
  const listFilter = listFilterMatcher(action);
1496
1519
  if (listFilter !== void 0) req.listFilter = listFilter;
1497
1520
  }
1521
+ if (options.relatedQuery !== void 0) {
1522
+ req.query = {
1523
+ ...req.query,
1524
+ relatedQuery: options.relatedQuery
1525
+ };
1526
+ applyRelatedQuery(ctx, action.outputType, req.query, req);
1527
+ }
1498
1528
  let remap;
1499
1529
  const media = requestMedia(action, options.contentType);
1500
1530
  if (media !== void 0 && media.kind !== "document") {
@@ -1511,6 +1541,7 @@ async function runAction(ctx, action, vars, input, options = {}) {
1511
1541
  req.contentType = sentContentType(action.contentType ?? "*/*", void 0, req.body);
1512
1542
  req.raw = true;
1513
1543
  }
1544
+ if (req.profiles !== void 0 && req.contentType === void 0) req.contentType = JSON_API_MEDIA_TYPE;
1514
1545
  const raw = responseMedia(action, options.accept);
1515
1546
  try {
1516
1547
  if (raw !== void 0) {
@@ -1816,15 +1847,6 @@ function createClient(descriptor, options) {
1816
1847
  });
1817
1848
  }
1818
1849
  //#endregion
1819
- //#region src/descriptor.ts
1820
- /**
1821
- * Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
1822
- * flag is absent, listing more than one related type.
1823
- */
1824
- function isPolymorphic(relation) {
1825
- return relation.polymorphic ?? relation.types.length > 1;
1826
- }
1827
- //#endregion
1828
1850
  exports.ATOMIC_EXT = ATOMIC_EXT;
1829
1851
  exports.ATOMIC_MEDIA_TYPE = ATOMIC_MEDIA_TYPE;
1830
1852
  exports.CANONICAL_PAGE_KEYS = CANONICAL_PAGE_KEYS;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as IdentifierMember, $n as CountableDescriptor, $t as AtomicUpdateHandle, A as AcceptedOf, An as PageOf, At as TypeAccessor, B as CountedRelationName, Bn as parseRetryAfter, Bt as WriteOptions, C as createClient, Cn as relatedPaginatorKind, Ct as RelationshipAccessor, D as TransportResponse, Dn as PageKeys, Dt as SingleReadQuery, E as TransportRequest, En as Page, Et as ResourceObjectView, F as BinaryResponseType, Fn as resolvePaginator, Ft as UpdateMethod, G as DefaultWriteAttributes, Gn as ActionLocationDescriptor, Gt as AtomicCreateHandle, H as CreateMethod, Hn as AcceptedOperation, Ht as ActionLocation, I as Client, In as Accepted, It as WaitOptions, J as FieldSelectionMap, Jn as ApiDescriptor, Jt as AtomicHandle, K as EdgeMembers, Kn as ActionOutput, Kt as AtomicCreateInput, L as Collection, Ln as PollOptions, Lt as WaitValue, M as ActionsAccessor, Mn as PageParamsOf, Mt as TypedReadQuery, N as AtomicResultOf, Nn as ResolvedPaginator, Nt as TypedRelationReadQuery, O as fetchTransport, On as PageLinks, Ot as SortQuery, P as BinaryBody, Pn as TypedPage, Pt as UpdateInput, Q as HydratedMember, Qn as ClientIdPolicy, Qt as AtomicResults, R as CountAccessor, Rn as PollTimeoutError, Rt as WaitedWriteResult, S as HeadersInit, Sn as relatedPaginator, St as RelationSortQuery, T as TransportRawBody, Tn as ExactPageParams, Tt as ResourceHandle, U as DefaultActionTypes, Un as ActionDescriptor, Ut as isActionLocation, V as CreateInput, Vn as AcceptedDescriptor, Vt as WriteResult, W as DefaultAttributes, Wn as ActionInput, Wt as readActionLocation, X as FilterKey, Xn as AtomicDescriptor, Xt as AtomicRef, Y as FieldsMap, Yn as ApiExamples, Yt as AtomicRecorder, Z as FilterQuery, Zn as Cardinality, Zt as AtomicResult, _ as executeRaw, _n as RelationArrayEnvelope, _r as ResourceDescriptor, _t as RelationFilterQuery, a as Validator, an as LocalIdentifier, ar as OperationExamples, at as ListPageParams, b as ClientOptions, bn as ResourceLinks, br as StrategyDescriptor, bt as RelationPaginator, c as resolveValidator, cn as mediaType, cr as PaginatorRole, ct as PivotInput, d as ExecutedResponse, dn as Edge, dr as RawMediaKind, dt as RelatedIncludedResource, en as AtomicUpdateInput, er as FilterFamilyDescriptor, et as IncludePath, f as JsonApiContext, fn as EdgeEnvelope, fr as RawOutputMedia, ft as RelatedIncludedType, g as execute, gn as NavigateOptions, gr as RelationMutations, gt as RelationCollection, h as ReadQuery, hn as MaterialiseContext, hr as RelationDescriptor, ht as RelatedQueryParam, i as ValidationOption, in as JSON_API_MEDIA_TYPE, ir as MenuDescriptor, it as LinkageRef, j as ActionCallOptions, jn as PageParams, jt as TypeName, k as AcceptedJob, kn as PageMeta, kt as SortToken, l as validateDocument, ln as ArrayEnvelope, lr as PaginatorStrategy, lt as ReadResult, m as RawResponseType, mn as LinkObject, mr as RelatedQueryOperation, mt as RelatedQueryEntry, n as SchemaMap, nn as ATOMIC_EXT, nr as InputMediaKind, nt as IncludedResource, o as WireResource, on as MediaTypeParams, or as PaginatorDescriptor, ot as LooseRelatedQueryEntry, p as JsonApiRequest, pn as Link, pr as RelatedQueryDescriptor, pt as RelatedQuery, q as ErrorCodeOf, qn as ActionScope, qt as AtomicDeleteHandle, r as ValidationConfig, rn as ATOMIC_MEDIA_TYPE, rr as MediaExamples, rt as IncludedType, s as assertJsonApiDocument, sn as ResourceIdentifier, sr as PaginatorKind, st as MemberName, t as ResolvedValidator, tn as runAtomic, tr as InputMedia, tt as IncludedRelations, u as Document, un as DocumentEnvelope, ur as PivotDescriptor, ut as ReadableRelationName, v as executeResponse, vn as RelationView, vr as ResourceExamples, vt as RelationName, w as JsonApiTransport, wn as CANONICAL_PAGE_KEYS, wt as ResourceAccessors, x as HANDLE_RESERVED, xn as materialise, xr as isPolymorphic, xt as RelationReadQuery, y as serializeQuery, yn as ResourceEnvelope, yr as SortFamilyDescriptor, yt as RelationPageParams, z as CountToken, zn as isAccepted, zt as WithLinks } from "./validate-0UvXQg-n.cjs";
1
+ import { $ as IdentifierMember, $n as ApiDescriptor, $t as AtomicHandle, A as AcceptedOf, An as ExactPageParams, At as ResourceObjectView, B as CountedRelationName, Bn as resolvePaginator, Bt as UpdateMethod, C as createClient, Cn as RelationView, Cr as ResourceDescriptor, Ct as RelationPaginator, D as TransportResponse, Dn as relatedPaginator, Dr as isPolymorphic, Dt as ResourceAccessors, E as TransportRequest, En as materialise, Er as StrategyDescriptor, Et as RelationshipAccessor, F as BinaryResponseType, Fn as PageOf, Ft as TypeName, G as DefaultWriteAttributes, Gn as parseRetryAfter, Gt as WriteOptions, H as CreateMethod, Hn as PollOptions, Ht as WaitValue, I as Client, In as PageParams, It as TypedReadQuery, J as FieldSelectionMap, Jn as ActionDescriptor, Jt as isActionLocation, K as EdgeMembers, Kn as AcceptedDescriptor, Kt as WriteResult, L as Collection, Ln as PageParamsOf, Lt as TypedRelatedReadQuery, M as ActionsAccessor, Mn as PageKeys, Mt as SortQuery, N as AtomicResultOf, Nn as PageLinks, Nt as SortToken, O as fetchTransport, On as relatedPaginatorKind, Ot as ResourceCountToken, P as BinaryBody, Pn as PageMeta, Pt as TypeAccessor, Q as HydratedMember, Qn as ActionScope, Qt as AtomicDeleteHandle, R as CountAccessor, Rn as ResolvedPaginator, Rt as TypedRelationReadQuery, S as HeadersInit, Sn as RelationArrayEnvelope, Sr as ResourceCountOperation, St as RelationPageParams, T as TransportRawBody, Tn as ResourceLinks, Tr as SortFamilyDescriptor, Tt as RelationSortQuery, U as DefaultActionTypes, Un as PollTimeoutError, Ut as WaitedWriteResult, V as CreateInput, Vn as Accepted, Vt as WaitOptions, W as DefaultAttributes, Wn as isAccepted, Wt as WithLinks, X as FilterKey, Xn as ActionLocationDescriptor, Xt as AtomicCreateHandle, Y as FieldsMap, Yn as ActionInput, Yt as readActionLocation, Z as FilterQuery, Zn as ActionOutput, Zt as AtomicCreateInput, _ as executeRaw, _n as EdgeEnvelope, _r as RawOutputMedia, _t as RelatedQueryRelation, a as Validator, an as AtomicUpdateInput, ar as FilterFamilyDescriptor, at as ListPageParams, b as ClientOptions, bn as MaterialiseContext, br as RelationDescriptor, bt as RelationFilterQuery, c as resolveValidator, cn as ATOMIC_MEDIA_TYPE, cr as MediaExamples, ct as MemberName, d as ExecutedResponse, dn as MediaTypeParams, dr as PaginatorDescriptor, dt as ReadableRelationName, en as AtomicRecorder, er as ApiExamples, et as IncludePath, f as JsonApiContext, fn as ResourceIdentifier, fr as PaginatorKind, ft as RelatedIncludedResource, g as execute, gn as Edge, gr as RawMediaKind, gt as RelatedQueryParam, h as ReadQuery, hn as DocumentEnvelope, hr as PivotDescriptor, ht as RelatedQueryEntry, i as ValidationOption, in as AtomicUpdateHandle, ir as CountableDescriptor, it as LinkageRef, j as ActionCallOptions, jn as Page, jt as SingleReadQuery, k as AcceptedJob, kn as CANONICAL_PAGE_KEYS, kt as ResourceHandle, l as validateDocument, ln as JSON_API_MEDIA_TYPE, lr as MenuDescriptor, lt as PivotInput, m as RawResponseType, mn as ArrayEnvelope, mr as PaginatorStrategy, mt as RelatedQuery, n as SchemaMap, nn as AtomicResult, nr as Cardinality, nt as IncludedResource, o as WireResource, on as runAtomic, or as InputMedia, ot as LooseRelatedQuery, p as JsonApiRequest, pn as mediaType, pr as PaginatorRole, pt as RelatedIncludedType, q as ErrorCodeOf, qn as AcceptedOperation, qt as ActionLocation, r as ValidationConfig, rn as AtomicResults, rr as ClientIdPolicy, rt as IncludedType, s as assertJsonApiDocument, sn as ATOMIC_EXT, sr as InputMediaKind, st as LooseRelatedQueryEntry, t as ResolvedValidator, tn as AtomicRef, tr as AtomicDescriptor, tt as IncludedRelations, u as Document, un as LocalIdentifier, ur as OperationExamples, ut as ReadResult, v as executeResponse, vn as Link, vr as RelatedQueryDescriptor, vt as RelatedReadRelatedQuery, w as JsonApiTransport, wn as ResourceEnvelope, wr as ResourceExamples, wt as RelationReadQuery, x as HANDLE_RESERVED, xn as NavigateOptions, xr as RelationMutations, xt as RelationName, y as serializeQuery, yn as LinkObject, yr as RelatedQueryOperation, yt as RelationCollection, z as CountToken, zn as TypedPage, zt as UpdateInput } from "./validate-Rgo7Zm0U.cjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -253,5 +253,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
253
253
  */
254
254
  declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
255
255
  //#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, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, 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, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, 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 };
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, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, 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, 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 };
257
257
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as IdentifierMember, $n as CountableDescriptor, $t as AtomicUpdateHandle, A as AcceptedOf, An as PageOf, At as TypeAccessor, B as CountedRelationName, Bn as parseRetryAfter, Bt as WriteOptions, C as createClient, Cn as relatedPaginatorKind, Ct as RelationshipAccessor, D as TransportResponse, Dn as PageKeys, Dt as SingleReadQuery, E as TransportRequest, En as Page, Et as ResourceObjectView, F as BinaryResponseType, Fn as resolvePaginator, Ft as UpdateMethod, G as DefaultWriteAttributes, Gn as ActionLocationDescriptor, Gt as AtomicCreateHandle, H as CreateMethod, Hn as AcceptedOperation, Ht as ActionLocation, I as Client, In as Accepted, It as WaitOptions, J as FieldSelectionMap, Jn as ApiDescriptor, Jt as AtomicHandle, K as EdgeMembers, Kn as ActionOutput, Kt as AtomicCreateInput, L as Collection, Ln as PollOptions, Lt as WaitValue, M as ActionsAccessor, Mn as PageParamsOf, Mt as TypedReadQuery, N as AtomicResultOf, Nn as ResolvedPaginator, Nt as TypedRelationReadQuery, O as fetchTransport, On as PageLinks, Ot as SortQuery, P as BinaryBody, Pn as TypedPage, Pt as UpdateInput, Q as HydratedMember, Qn as ClientIdPolicy, Qt as AtomicResults, R as CountAccessor, Rn as PollTimeoutError, Rt as WaitedWriteResult, S as HeadersInit, Sn as relatedPaginator, St as RelationSortQuery, T as TransportRawBody, Tn as ExactPageParams, Tt as ResourceHandle, U as DefaultActionTypes, Un as ActionDescriptor, Ut as isActionLocation, V as CreateInput, Vn as AcceptedDescriptor, Vt as WriteResult, W as DefaultAttributes, Wn as ActionInput, Wt as readActionLocation, X as FilterKey, Xn as AtomicDescriptor, Xt as AtomicRef, Y as FieldsMap, Yn as ApiExamples, Yt as AtomicRecorder, Z as FilterQuery, Zn as Cardinality, Zt as AtomicResult, _ as executeRaw, _n as RelationArrayEnvelope, _r as ResourceDescriptor, _t as RelationFilterQuery, a as Validator, an as LocalIdentifier, ar as OperationExamples, at as ListPageParams, b as ClientOptions, bn as ResourceLinks, br as StrategyDescriptor, bt as RelationPaginator, c as resolveValidator, cn as mediaType, cr as PaginatorRole, ct as PivotInput, d as ExecutedResponse, dn as Edge, dr as RawMediaKind, dt as RelatedIncludedResource, en as AtomicUpdateInput, er as FilterFamilyDescriptor, et as IncludePath, f as JsonApiContext, fn as EdgeEnvelope, fr as RawOutputMedia, ft as RelatedIncludedType, g as execute, gn as NavigateOptions, gr as RelationMutations, gt as RelationCollection, h as ReadQuery, hn as MaterialiseContext, hr as RelationDescriptor, ht as RelatedQueryParam, i as ValidationOption, in as JSON_API_MEDIA_TYPE, ir as MenuDescriptor, it as LinkageRef, j as ActionCallOptions, jn as PageParams, jt as TypeName, k as AcceptedJob, kn as PageMeta, kt as SortToken, l as validateDocument, ln as ArrayEnvelope, lr as PaginatorStrategy, lt as ReadResult, m as RawResponseType, mn as LinkObject, mr as RelatedQueryOperation, mt as RelatedQueryEntry, n as SchemaMap, nn as ATOMIC_EXT, nr as InputMediaKind, nt as IncludedResource, o as WireResource, on as MediaTypeParams, or as PaginatorDescriptor, ot as LooseRelatedQueryEntry, p as JsonApiRequest, pn as Link, pr as RelatedQueryDescriptor, pt as RelatedQuery, q as ErrorCodeOf, qn as ActionScope, qt as AtomicDeleteHandle, r as ValidationConfig, rn as ATOMIC_MEDIA_TYPE, rr as MediaExamples, rt as IncludedType, s as assertJsonApiDocument, sn as ResourceIdentifier, sr as PaginatorKind, st as MemberName, t as ResolvedValidator, tn as runAtomic, tr as InputMedia, tt as IncludedRelations, u as Document, un as DocumentEnvelope, ur as PivotDescriptor, ut as ReadableRelationName, v as executeResponse, vn as RelationView, vr as ResourceExamples, vt as RelationName, w as JsonApiTransport, wn as CANONICAL_PAGE_KEYS, wt as ResourceAccessors, x as HANDLE_RESERVED, xn as materialise, xr as isPolymorphic, xt as RelationReadQuery, y as serializeQuery, yn as ResourceEnvelope, yr as SortFamilyDescriptor, yt as RelationPageParams, z as CountToken, zn as isAccepted, zt as WithLinks } from "./validate-0UvXQg-n.mjs";
1
+ import { $ as IdentifierMember, $n as ApiDescriptor, $t as AtomicHandle, A as AcceptedOf, An as ExactPageParams, At as ResourceObjectView, B as CountedRelationName, Bn as resolvePaginator, Bt as UpdateMethod, C as createClient, Cn as RelationView, Cr as ResourceDescriptor, Ct as RelationPaginator, D as TransportResponse, Dn as relatedPaginator, Dr as isPolymorphic, Dt as ResourceAccessors, E as TransportRequest, En as materialise, Er as StrategyDescriptor, Et as RelationshipAccessor, F as BinaryResponseType, Fn as PageOf, Ft as TypeName, G as DefaultWriteAttributes, Gn as parseRetryAfter, Gt as WriteOptions, H as CreateMethod, Hn as PollOptions, Ht as WaitValue, I as Client, In as PageParams, It as TypedReadQuery, J as FieldSelectionMap, Jn as ActionDescriptor, Jt as isActionLocation, K as EdgeMembers, Kn as AcceptedDescriptor, Kt as WriteResult, L as Collection, Ln as PageParamsOf, Lt as TypedRelatedReadQuery, M as ActionsAccessor, Mn as PageKeys, Mt as SortQuery, N as AtomicResultOf, Nn as PageLinks, Nt as SortToken, O as fetchTransport, On as relatedPaginatorKind, Ot as ResourceCountToken, P as BinaryBody, Pn as PageMeta, Pt as TypeAccessor, Q as HydratedMember, Qn as ActionScope, Qt as AtomicDeleteHandle, R as CountAccessor, Rn as ResolvedPaginator, Rt as TypedRelationReadQuery, S as HeadersInit, Sn as RelationArrayEnvelope, Sr as ResourceCountOperation, St as RelationPageParams, T as TransportRawBody, Tn as ResourceLinks, Tr as SortFamilyDescriptor, Tt as RelationSortQuery, U as DefaultActionTypes, Un as PollTimeoutError, Ut as WaitedWriteResult, V as CreateInput, Vn as Accepted, Vt as WaitOptions, W as DefaultAttributes, Wn as isAccepted, Wt as WithLinks, X as FilterKey, Xn as ActionLocationDescriptor, Xt as AtomicCreateHandle, Y as FieldsMap, Yn as ActionInput, Yt as readActionLocation, Z as FilterQuery, Zn as ActionOutput, Zt as AtomicCreateInput, _ as executeRaw, _n as EdgeEnvelope, _r as RawOutputMedia, _t as RelatedQueryRelation, a as Validator, an as AtomicUpdateInput, ar as FilterFamilyDescriptor, at as ListPageParams, b as ClientOptions, bn as MaterialiseContext, br as RelationDescriptor, bt as RelationFilterQuery, c as resolveValidator, cn as ATOMIC_MEDIA_TYPE, cr as MediaExamples, ct as MemberName, d as ExecutedResponse, dn as MediaTypeParams, dr as PaginatorDescriptor, dt as ReadableRelationName, en as AtomicRecorder, er as ApiExamples, et as IncludePath, f as JsonApiContext, fn as ResourceIdentifier, fr as PaginatorKind, ft as RelatedIncludedResource, g as execute, gn as Edge, gr as RawMediaKind, gt as RelatedQueryParam, h as ReadQuery, hn as DocumentEnvelope, hr as PivotDescriptor, ht as RelatedQueryEntry, i as ValidationOption, in as AtomicUpdateHandle, ir as CountableDescriptor, it as LinkageRef, j as ActionCallOptions, jn as Page, jt as SingleReadQuery, k as AcceptedJob, kn as CANONICAL_PAGE_KEYS, kt as ResourceHandle, l as validateDocument, ln as JSON_API_MEDIA_TYPE, lr as MenuDescriptor, lt as PivotInput, m as RawResponseType, mn as ArrayEnvelope, mr as PaginatorStrategy, mt as RelatedQuery, n as SchemaMap, nn as AtomicResult, nr as Cardinality, nt as IncludedResource, o as WireResource, on as runAtomic, or as InputMedia, ot as LooseRelatedQuery, p as JsonApiRequest, pn as mediaType, pr as PaginatorRole, pt as RelatedIncludedType, q as ErrorCodeOf, qn as AcceptedOperation, qt as ActionLocation, r as ValidationConfig, rn as AtomicResults, rr as ClientIdPolicy, rt as IncludedType, s as assertJsonApiDocument, sn as ATOMIC_EXT, sr as InputMediaKind, st as LooseRelatedQueryEntry, t as ResolvedValidator, tn as AtomicRef, tr as AtomicDescriptor, tt as IncludedRelations, u as Document, un as LocalIdentifier, ur as OperationExamples, ut as ReadResult, v as executeResponse, vn as Link, vr as RelatedQueryDescriptor, vt as RelatedReadRelatedQuery, w as JsonApiTransport, wn as ResourceEnvelope, wr as ResourceExamples, wt as RelationReadQuery, x as HANDLE_RESERVED, xn as NavigateOptions, xr as RelationMutations, xt as RelationName, y as serializeQuery, yn as LinkObject, yr as RelatedQueryOperation, yt as RelationCollection, z as CountToken, zn as TypedPage, zt as UpdateInput } from "./validate-Rgo7Zm0U.mjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -253,5 +253,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
253
253
  */
254
254
  declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
255
255
  //#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, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListPageParams, LocalIdentifier, 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, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, 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 };
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, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, 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, 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 };
257
257
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -183,7 +183,7 @@ const appendFilterValue = (parts, key, value, list = false) => {
183
183
  * (`filter[title]`, `page[number]`, `fields[albums]`) are kept literal; only values
184
184
  * are percent-encoded. `isListFilter` names the filter keys that take a list, whose array value
185
185
  * goes out as `filter[<key>][]` once per member, and `isRelatedListFilter` does the same for a
186
- * `relatedQuery` entry's filters by include path. Empty/undefined entries are skipped; key order is deterministic
186
+ * `relatedQuery` entry's filters by relation. Empty/undefined entries are skipped; key order is deterministic
187
187
  * (family order, then insertion order within a family) so URLs are stable for caching.
188
188
  */
189
189
  function serializeQuery(query, isListFilter, isRelatedListFilter) {
@@ -193,9 +193,9 @@ function serializeQuery(query, isListFilter, isRelatedListFilter) {
193
193
  if (query.include) append(parts, "include", query.include.join(","));
194
194
  if (query.fields) for (const [type, names] of Object.entries(query.fields)) parts.push(`fields[${type}]=${encodeURIComponent(names.join(","))}`);
195
195
  if (query.withCount && query.withCount.length > 0) append(parts, "withCount", query.withCount.join(","));
196
- for (const [path, entry] of Object.entries(query.relatedQuery ?? {})) {
197
- for (const [key, value] of Object.entries(entry?.filter ?? {})) appendFilterValue(parts, `relatedQuery[${path}][filter][${key}]`, value, isRelatedListFilter?.(path, key) ?? false);
198
- if (entry?.sort !== void 0) append(parts, `relatedQuery[${path}][sort]`, typeof entry.sort === "string" ? entry.sort : entry.sort.join(","));
196
+ for (const [relation, entry] of Object.entries(query.relatedQuery ?? {})) {
197
+ for (const [key, value] of Object.entries(entry?.filter ?? {})) appendFilterValue(parts, `relatedQuery[${relation}][filter][${key}]`, value, isRelatedListFilter?.(relation, key) ?? false);
198
+ if (entry?.sort !== void 0) append(parts, `relatedQuery[${relation}][sort]`, typeof entry.sort === "string" ? entry.sort : entry.sort.join(","));
199
199
  }
200
200
  if (query.page) for (const [key, value] of Object.entries(query.page)) append(parts, `page[${key}]`, Array.isArray(value) ? value.join(",") : value);
201
201
  return parts.join("&");
@@ -1198,6 +1198,15 @@ function parseResults(doc, ctx) {
1198
1198
  });
1199
1199
  }
1200
1200
  //#endregion
1201
+ //#region src/descriptor.ts
1202
+ /**
1203
+ * Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
1204
+ * flag is absent, listing more than one related type.
1205
+ */
1206
+ function isPolymorphic(relation) {
1207
+ return relation.polymorphic ?? relation.types.length > 1;
1208
+ }
1209
+ //#endregion
1201
1210
  //#region src/filters.ts
1202
1211
  /**
1203
1212
  * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
@@ -1332,9 +1341,9 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1332
1341
  req.query = params;
1333
1342
  const listFilter = listFilterMatcher(filterSpec(ctx, type, operation, vars["rel"]));
1334
1343
  if (listFilter !== void 0) req.listFilter = listFilter;
1335
- if (params.relatedQuery !== void 0) req.relatedListFilter = relatedListFilter(ctx, type);
1336
1344
  if (signal !== void 0) req.signal = signal;
1337
- negotiateProfiles(ctx, type, params, req, relationForCount);
1345
+ negotiateProfiles(ctx, type, params, req, relationForCount, operation);
1346
+ applyRelatedQuery(ctx, renderedType(ctx, type, operation, vars["rel"]), params, req);
1338
1347
  }
1339
1348
  const doc = await execute(ctx.request, req);
1340
1349
  const relation = (operation === "fetchRelated" || operation === "fetchRelationship") && vars["rel"] !== void 0 ? ctx.descriptor[type]?.relations[vars["rel"]] : void 0;
@@ -1356,57 +1365,65 @@ function filterSpec(ctx, type, operation, rel) {
1356
1365
  return types?.length === 1 ? ctx.descriptor[types[0]] : void 0;
1357
1366
  }
1358
1367
  /**
1359
- * Whether a `relatedQuery` entry's filter key takes a list, matched against the vocabulary of the
1360
- * relation its include path ends on, as that relation's related read matches it. A path through a
1361
- * polymorphic relation continues from the first member type declaring the next relation.
1368
+ * The type whose resources an operation answers with, which keys its `relatedQuery`: the type
1369
+ * itself, or a related read's related type when the relation is monomorphic. A relationship read
1370
+ * answers with linkage, so it has none.
1362
1371
  */
1363
- function relatedListFilter(ctx, type) {
1364
- const matchers = /* @__PURE__ */ new Map();
1365
- return (path, key) => {
1366
- if (!matchers.has(path)) matchers.set(path, listFilterMatcher(relatedQuerySpec(ctx, type, path)));
1367
- return matchers.get(path)?.(key) ?? false;
1368
- };
1369
- }
1370
- /** The filter vocabulary of the relation an include path from `type` ends on. */
1371
- function relatedQuerySpec(ctx, type, path) {
1372
- const names = path.split(".");
1373
- let owners = [type];
1374
- for (const [index, name] of names.entries()) {
1375
- const owner = owners.find((t) => ctx.descriptor[t]?.relations[name] !== void 0);
1376
- if (owner === void 0) return;
1377
- if (index === names.length - 1) return filterSpec(ctx, owner, "fetchRelated", name);
1378
- owners = ctx.descriptor[owner].relations[name].types;
1379
- }
1372
+ function renderedType(ctx, type, operation, rel) {
1373
+ if (operation === "fetchRelationship") return;
1374
+ if (operation !== "fetchRelated") return type;
1375
+ const relation = rel === void 0 ? void 0 : ctx.descriptor[type]?.relations[rel];
1376
+ return relation === void 0 || isPolymorphic(relation) ? void 0 : relation.types[0];
1380
1377
  }
1381
- /** Whether a `relatedQuery` carries a filter or sort for any path, so it reaches the wire. */
1378
+ /** Whether a `relatedQuery` carries a filter or sort for any relation, so it reaches the wire. */
1382
1379
  function sendsRelatedQuery(relatedQuery) {
1383
1380
  return Object.values(relatedQuery ?? {}).some((entry) => Object.keys(entry?.filter ?? {}).length > 0 || entry?.sort !== void 0 && entry.sort.length > 0);
1384
1381
  }
1385
1382
  /**
1386
- * Add any profiles a query's parameters require to the request's negotiated `profiles`. A
1387
- * `withCount` read needs the type's Countable profile in `Accept` — else the server rejects it
1388
- * (400) under strict query-param validation. The profile URI is read from the descriptor's
1389
- * `countable` block (never hardcoded); absent when the type advertises no Countable profile. A
1390
- * `relatedQuery` on a collection or single read likewise adds the type's Relationship Queries
1391
- * profile, after any Countable one.
1383
+ * Prepare a request's `relatedQuery` for resources of type `rendered`: match each entry's list
1384
+ * filters against its relation's related-read vocabulary, and negotiate the type's Relationship
1385
+ * Queries profile, after any Countable one, when the query sends an entry.
1392
1386
  */
1393
- function negotiateProfiles(ctx, type, query, req, relationForCount) {
1387
+ function applyRelatedQuery(ctx, rendered, query, req) {
1388
+ if (rendered === void 0 || !sendsRelatedQuery(query.relatedQuery)) return;
1389
+ const matchers = /* @__PURE__ */ new Map();
1390
+ req.relatedListFilter = (rel, key) => {
1391
+ if (!matchers.has(rel)) matchers.set(rel, listFilterMatcher(filterSpec(ctx, rendered, "fetchRelated", rel)));
1392
+ return matchers.get(rel)?.(key) ?? false;
1393
+ };
1394
+ const profile = ctx.descriptor[rendered]?.relatedQuery?.profile;
1395
+ if (profile !== void 0 && !(req.profiles ?? []).includes(profile)) req.profiles = [...req.profiles ?? [], profile];
1396
+ }
1397
+ /**
1398
+ * Add the Countable profile a query's `withCount` requires to the request's negotiated
1399
+ * `profiles`. A `withCount` read or write needs it in `Accept`, else the server rejects it (400)
1400
+ * under strict query-param validation. The profile URI is read from the descriptor (never
1401
+ * hardcoded): the relation's `countable` for a related or relationship read, the operation's
1402
+ * `resourceCountable` entry for a single-resource read or a write, else the type's `countable`.
1403
+ */
1404
+ function negotiateProfiles(ctx, type, query, req, relationForCount, operation) {
1394
1405
  const profiles = [];
1395
1406
  if (query.withCount !== void 0 && query.withCount.length > 0) {
1396
- const profile = relationForCount !== void 0 ? ctx.descriptor[type]?.relations[relationForCount]?.countable?.profile : ctx.descriptor[type]?.countable?.profile;
1407
+ const descriptor = ctx.descriptor[type];
1408
+ const profile = relationForCount !== void 0 ? descriptor?.relations[relationForCount]?.countable?.profile : (isResourceCountOperation(operation) ? descriptor?.resourceCountable?.[operation]?.profile : void 0) ?? descriptor?.countable?.profile;
1397
1409
  if (profile !== void 0) profiles.push(profile);
1398
1410
  }
1399
- if (relationForCount === void 0 && sendsRelatedQuery(query.relatedQuery)) {
1400
- const profile = ctx.descriptor[type]?.relatedQuery?.profile;
1401
- if (profile !== void 0 && !profiles.includes(profile)) profiles.push(profile);
1402
- }
1403
1411
  if (profiles.length > 0) req.profiles = [...req.profiles ?? [], ...profiles];
1404
1412
  }
1405
- /** Project a write's opts to the read-query families the response honours (`include`/`fields`). */
1413
+ /** Whether an operation is one answering with one resource that may take `withCount`. */
1414
+ function isResourceCountOperation(operation) {
1415
+ return operation === "fetchOne" || operation === "create" || operation === "update";
1416
+ }
1417
+ /**
1418
+ * Project a write's opts to the read-query families the response honours: `include`, `fields`,
1419
+ * `withCount` and `relatedQuery`.
1420
+ */
1406
1421
  function writeQuery(opts) {
1407
1422
  if (opts === void 0) return;
1408
1423
  const query = {};
1409
1424
  if (opts.include !== void 0) query.include = [...opts.include];
1425
+ if (opts.withCount !== void 0) query.withCount = [...opts.withCount];
1426
+ if (opts.relatedQuery !== void 0) query.relatedQuery = opts.relatedQuery;
1410
1427
  if (opts.fields !== void 0) {
1411
1428
  const fields = {};
1412
1429
  for (const [k, v] of Object.entries(opts.fields)) fields[k] = [...v];
@@ -1446,7 +1463,12 @@ async function runWrite(ctx, spec) {
1446
1463
  path: fillPath(ctx, spec.type, template, spec.vars),
1447
1464
  body: spec.body
1448
1465
  };
1449
- if (spec.query !== void 0) req.query = spec.query;
1466
+ if (spec.query !== void 0) {
1467
+ req.query = spec.query;
1468
+ negotiateProfiles(ctx, spec.type, spec.query, req, void 0, spec.operation);
1469
+ applyRelatedQuery(ctx, spec.type, spec.query, req);
1470
+ if (req.profiles !== void 0) req.contentType = JSON_API_MEDIA_TYPE;
1471
+ }
1450
1472
  if (spec.wait?.signal !== void 0) req.signal = spec.wait.signal;
1451
1473
  let res;
1452
1474
  try {
@@ -1480,7 +1502,8 @@ async function runWrite(ctx, spec) {
1480
1502
  * `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
1481
1503
  * the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
1482
1504
  * `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
1483
- * sends `options.filter` in the query string as a collection read does. A `202` the action
1505
+ * sends `options.filter` in the query string as a collection read does, and an action answering
1506
+ * with a resource sends `options.relatedQuery` as a read does. A `202` the action
1484
1507
  * declares resolves to an `Accepted` job, or with `options.wait` to the value its job URL ends at.
1485
1508
  */
1486
1509
  async function runAction(ctx, action, vars, input, options = {}) {
@@ -1494,6 +1517,13 @@ async function runAction(ctx, action, vars, input, options = {}) {
1494
1517
  const listFilter = listFilterMatcher(action);
1495
1518
  if (listFilter !== void 0) req.listFilter = listFilter;
1496
1519
  }
1520
+ if (options.relatedQuery !== void 0) {
1521
+ req.query = {
1522
+ ...req.query,
1523
+ relatedQuery: options.relatedQuery
1524
+ };
1525
+ applyRelatedQuery(ctx, action.outputType, req.query, req);
1526
+ }
1497
1527
  let remap;
1498
1528
  const media = requestMedia(action, options.contentType);
1499
1529
  if (media !== void 0 && media.kind !== "document") {
@@ -1510,6 +1540,7 @@ async function runAction(ctx, action, vars, input, options = {}) {
1510
1540
  req.contentType = sentContentType(action.contentType ?? "*/*", void 0, req.body);
1511
1541
  req.raw = true;
1512
1542
  }
1543
+ if (req.profiles !== void 0 && req.contentType === void 0) req.contentType = JSON_API_MEDIA_TYPE;
1513
1544
  const raw = responseMedia(action, options.accept);
1514
1545
  try {
1515
1546
  if (raw !== void 0) {
@@ -1815,15 +1846,6 @@ function createClient(descriptor, options) {
1815
1846
  });
1816
1847
  }
1817
1848
  //#endregion
1818
- //#region src/descriptor.ts
1819
- /**
1820
- * Whether a relation is polymorphic: flagged {@link RelationDescriptor.polymorphic}, or, when the
1821
- * flag is absent, listing more than one related type.
1822
- */
1823
- function isPolymorphic(relation) {
1824
- return relation.polymorphic ?? relation.types.length > 1;
1825
- }
1826
- //#endregion
1827
1849
  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, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
1828
1850
 
1829
1851
  //# sourceMappingURL=index.mjs.map