@haddowg/json-api-client 1.20.0 → 1.21.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
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-DGoH9XA9.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-DGoH9XA9.mjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/index.cjs CHANGED
@@ -1335,7 +1335,7 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1335
1335
  if (listFilter !== void 0) req.listFilter = listFilter;
1336
1336
  if (params.relatedQuery !== void 0) req.relatedListFilter = relatedListFilter(ctx, type);
1337
1337
  if (signal !== void 0) req.signal = signal;
1338
- negotiateProfiles(ctx, type, params, req, relationForCount);
1338
+ negotiateProfiles(ctx, type, params, req, relationForCount, operation);
1339
1339
  }
1340
1340
  const doc = await execute(ctx.request, req);
1341
1341
  const relation = (operation === "fetchRelated" || operation === "fetchRelationship") && vars["rel"] !== void 0 ? ctx.descriptor[type]?.relations[vars["rel"]] : void 0;
@@ -1385,16 +1385,18 @@ function sendsRelatedQuery(relatedQuery) {
1385
1385
  }
1386
1386
  /**
1387
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
1388
+ * `withCount` read or write needs the Countable profile in `Accept`, else the server rejects it
1389
+ * (400) under strict query-param validation. The profile URI is read from the descriptor (never
1390
+ * hardcoded): the relation's `countable` for a related or relationship read, the operation's
1391
+ * `resourceCountable` entry for a single-resource read or a write, else the type's `countable`.
1392
+ * A `relatedQuery` on a collection or single read likewise adds the type's Relationship Queries
1392
1393
  * profile, after any Countable one.
1393
1394
  */
1394
- function negotiateProfiles(ctx, type, query, req, relationForCount) {
1395
+ function negotiateProfiles(ctx, type, query, req, relationForCount, operation) {
1395
1396
  const profiles = [];
1396
1397
  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;
1398
+ const descriptor = ctx.descriptor[type];
1399
+ const profile = relationForCount !== void 0 ? descriptor?.relations[relationForCount]?.countable?.profile : (isResourceCountOperation(operation) ? descriptor?.resourceCountable?.[operation]?.profile : void 0) ?? descriptor?.countable?.profile;
1398
1400
  if (profile !== void 0) profiles.push(profile);
1399
1401
  }
1400
1402
  if (relationForCount === void 0 && sendsRelatedQuery(query.relatedQuery)) {
@@ -1403,11 +1405,19 @@ function negotiateProfiles(ctx, type, query, req, relationForCount) {
1403
1405
  }
1404
1406
  if (profiles.length > 0) req.profiles = [...req.profiles ?? [], ...profiles];
1405
1407
  }
1406
- /** Project a write's opts to the read-query families the response honours (`include`/`fields`). */
1408
+ /** Whether an operation is one answering with one resource that may take `withCount`. */
1409
+ function isResourceCountOperation(operation) {
1410
+ return operation === "fetchOne" || operation === "create" || operation === "update";
1411
+ }
1412
+ /**
1413
+ * Project a write's opts to the read-query families the response honours: `include`, `fields`
1414
+ * and `withCount`.
1415
+ */
1407
1416
  function writeQuery(opts) {
1408
1417
  if (opts === void 0) return;
1409
1418
  const query = {};
1410
1419
  if (opts.include !== void 0) query.include = [...opts.include];
1420
+ if (opts.withCount !== void 0) query.withCount = [...opts.withCount];
1411
1421
  if (opts.fields !== void 0) {
1412
1422
  const fields = {};
1413
1423
  for (const [k, v] of Object.entries(opts.fields)) fields[k] = [...v];
@@ -1447,7 +1457,11 @@ async function runWrite(ctx, spec) {
1447
1457
  path: fillPath(ctx, spec.type, template, spec.vars),
1448
1458
  body: spec.body
1449
1459
  };
1450
- if (spec.query !== void 0) req.query = spec.query;
1460
+ if (spec.query !== void 0) {
1461
+ req.query = spec.query;
1462
+ negotiateProfiles(ctx, spec.type, spec.query, req, void 0, spec.operation);
1463
+ if (req.profiles !== void 0) req.contentType = JSON_API_MEDIA_TYPE;
1464
+ }
1451
1465
  if (spec.wait?.signal !== void 0) req.signal = spec.wait.signal;
1452
1466
  let res;
1453
1467
  try {
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 ClientIdPolicy, $t as AtomicResults, A as AcceptedOf, An as PageMeta, At as SortToken, B as CountedRelationName, Bn as isAccepted, Bt as WithLinks, C as createClient, Cn as relatedPaginator, Cr as isPolymorphic, Ct as RelationshipAccessor, D as TransportResponse, Dn as Page, Dt as ResourceObjectView, E as TransportRequest, En as ExactPageParams, Et as ResourceHandle, F as BinaryResponseType, Fn as TypedPage, Ft as UpdateInput, G as DefaultWriteAttributes, Gn as ActionInput, Gt as readActionLocation, H as CreateMethod, Hn as AcceptedDescriptor, Ht as WriteResult, I as Client, In as resolvePaginator, It as UpdateMethod, J as FieldSelectionMap, Jn as ActionScope, Jt as AtomicDeleteHandle, K as EdgeMembers, Kn as ActionLocationDescriptor, Kt as AtomicCreateHandle, L as Collection, Ln as Accepted, Lt as WaitOptions, M as ActionsAccessor, Mn as PageParams, Mt as TypeName, N as AtomicResultOf, Nn as PageParamsOf, Nt as TypedReadQuery, O as fetchTransport, On as PageKeys, Ot as SingleReadQuery, P as BinaryBody, Pn as ResolvedPaginator, Pt as TypedRelationReadQuery, Q as HydratedMember, Qn as Cardinality, Qt as AtomicResult, R as CountAccessor, Rn as PollOptions, Rt as WaitValue, S as HeadersInit, Sn as materialise, Sr as StrategyDescriptor, St as RelationSortQuery, T as TransportRawBody, Tn as CANONICAL_PAGE_KEYS, Tt as ResourceCountToken, U as DefaultActionTypes, Un as AcceptedOperation, Ut as ActionLocation, V as CreateInput, Vn as parseRetryAfter, Vt as WriteOptions, W as DefaultAttributes, Wn as ActionDescriptor, Wt as isActionLocation, X as FilterKey, Xn as ApiExamples, Xt as AtomicRecorder, Y as FieldsMap, Yn as ApiDescriptor, Yt as AtomicHandle, Z as FilterQuery, Zn as AtomicDescriptor, Zt as AtomicRef, _ as executeRaw, _n as NavigateOptions, _r as RelationMutations, _t as RelationFilterQuery, a as Validator, an as JSON_API_MEDIA_TYPE, ar as MenuDescriptor, at as ListPageParams, b as ClientOptions, bn as ResourceEnvelope, br as ResourceExamples, bt as RelationPaginator, c as resolveValidator, cn as ResourceIdentifier, cr as PaginatorKind, ct as PivotInput, d as ExecutedResponse, dn as DocumentEnvelope, dr as PivotDescriptor, dt as RelatedIncludedResource, en as AtomicUpdateHandle, er as CountableDescriptor, et as IncludePath, f as JsonApiContext, fn as Edge, fr as RawMediaKind, ft as RelatedIncludedType, g as execute, gn as MaterialiseContext, gr as RelationDescriptor, gt as RelationCollection, h as ReadQuery, hn as LinkObject, hr as RelatedQueryOperation, ht as RelatedQueryParam, i as ValidationOption, in as ATOMIC_MEDIA_TYPE, ir as MediaExamples, it as LinkageRef, j as ActionCallOptions, jn as PageOf, jt as TypeAccessor, k as AcceptedJob, kn as PageLinks, kt as SortQuery, l as validateDocument, ln as mediaType, lr as PaginatorRole, lt as ReadResult, m as RawResponseType, mn as Link, mr as RelatedQueryDescriptor, mt as RelatedQueryEntry, n as SchemaMap, nn as runAtomic, nr as InputMedia, nt as IncludedResource, o as WireResource, on as LocalIdentifier, or as OperationExamples, ot as LooseRelatedQueryEntry, p as JsonApiRequest, pn as EdgeEnvelope, pr as RawOutputMedia, pt as RelatedQuery, q as ErrorCodeOf, qn as ActionOutput, qt as AtomicCreateInput, r as ValidationConfig, rn as ATOMIC_EXT, rr as InputMediaKind, rt as IncludedType, s as assertJsonApiDocument, sn as MediaTypeParams, sr as PaginatorDescriptor, st as MemberName, t as ResolvedValidator, tn as AtomicUpdateInput, tr as FilterFamilyDescriptor, tt as IncludedRelations, u as Document, un as ArrayEnvelope, ur as PaginatorStrategy, ut as ReadableRelationName, v as executeResponse, vn as RelationArrayEnvelope, vr as ResourceCountOperation, vt as RelationName, w as JsonApiTransport, wn as relatedPaginatorKind, wt as ResourceAccessors, x as HANDLE_RESERVED, xn as ResourceLinks, xr as SortFamilyDescriptor, xt as RelationReadQuery, y as serializeQuery, yn as RelationView, yr as ResourceDescriptor, yt as RelationPageParams, z as CountToken, zn as PollTimeoutError, zt as WaitedWriteResult } from "./validate-DGoH9XA9.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, 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, ResourceCountOperation, ResourceCountToken, 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 };
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 ClientIdPolicy, $t as AtomicResults, A as AcceptedOf, An as PageMeta, At as SortToken, B as CountedRelationName, Bn as isAccepted, Bt as WithLinks, C as createClient, Cn as relatedPaginator, Cr as isPolymorphic, Ct as RelationshipAccessor, D as TransportResponse, Dn as Page, Dt as ResourceObjectView, E as TransportRequest, En as ExactPageParams, Et as ResourceHandle, F as BinaryResponseType, Fn as TypedPage, Ft as UpdateInput, G as DefaultWriteAttributes, Gn as ActionInput, Gt as readActionLocation, H as CreateMethod, Hn as AcceptedDescriptor, Ht as WriteResult, I as Client, In as resolvePaginator, It as UpdateMethod, J as FieldSelectionMap, Jn as ActionScope, Jt as AtomicDeleteHandle, K as EdgeMembers, Kn as ActionLocationDescriptor, Kt as AtomicCreateHandle, L as Collection, Ln as Accepted, Lt as WaitOptions, M as ActionsAccessor, Mn as PageParams, Mt as TypeName, N as AtomicResultOf, Nn as PageParamsOf, Nt as TypedReadQuery, O as fetchTransport, On as PageKeys, Ot as SingleReadQuery, P as BinaryBody, Pn as ResolvedPaginator, Pt as TypedRelationReadQuery, Q as HydratedMember, Qn as Cardinality, Qt as AtomicResult, R as CountAccessor, Rn as PollOptions, Rt as WaitValue, S as HeadersInit, Sn as materialise, Sr as StrategyDescriptor, St as RelationSortQuery, T as TransportRawBody, Tn as CANONICAL_PAGE_KEYS, Tt as ResourceCountToken, U as DefaultActionTypes, Un as AcceptedOperation, Ut as ActionLocation, V as CreateInput, Vn as parseRetryAfter, Vt as WriteOptions, W as DefaultAttributes, Wn as ActionDescriptor, Wt as isActionLocation, X as FilterKey, Xn as ApiExamples, Xt as AtomicRecorder, Y as FieldsMap, Yn as ApiDescriptor, Yt as AtomicHandle, Z as FilterQuery, Zn as AtomicDescriptor, Zt as AtomicRef, _ as executeRaw, _n as NavigateOptions, _r as RelationMutations, _t as RelationFilterQuery, a as Validator, an as JSON_API_MEDIA_TYPE, ar as MenuDescriptor, at as ListPageParams, b as ClientOptions, bn as ResourceEnvelope, br as ResourceExamples, bt as RelationPaginator, c as resolveValidator, cn as ResourceIdentifier, cr as PaginatorKind, ct as PivotInput, d as ExecutedResponse, dn as DocumentEnvelope, dr as PivotDescriptor, dt as RelatedIncludedResource, en as AtomicUpdateHandle, er as CountableDescriptor, et as IncludePath, f as JsonApiContext, fn as Edge, fr as RawMediaKind, ft as RelatedIncludedType, g as execute, gn as MaterialiseContext, gr as RelationDescriptor, gt as RelationCollection, h as ReadQuery, hn as LinkObject, hr as RelatedQueryOperation, ht as RelatedQueryParam, i as ValidationOption, in as ATOMIC_MEDIA_TYPE, ir as MediaExamples, it as LinkageRef, j as ActionCallOptions, jn as PageOf, jt as TypeAccessor, k as AcceptedJob, kn as PageLinks, kt as SortQuery, l as validateDocument, ln as mediaType, lr as PaginatorRole, lt as ReadResult, m as RawResponseType, mn as Link, mr as RelatedQueryDescriptor, mt as RelatedQueryEntry, n as SchemaMap, nn as runAtomic, nr as InputMedia, nt as IncludedResource, o as WireResource, on as LocalIdentifier, or as OperationExamples, ot as LooseRelatedQueryEntry, p as JsonApiRequest, pn as EdgeEnvelope, pr as RawOutputMedia, pt as RelatedQuery, q as ErrorCodeOf, qn as ActionOutput, qt as AtomicCreateInput, r as ValidationConfig, rn as ATOMIC_EXT, rr as InputMediaKind, rt as IncludedType, s as assertJsonApiDocument, sn as MediaTypeParams, sr as PaginatorDescriptor, st as MemberName, t as ResolvedValidator, tn as AtomicUpdateInput, tr as FilterFamilyDescriptor, tt as IncludedRelations, u as Document, un as ArrayEnvelope, ur as PaginatorStrategy, ut as ReadableRelationName, v as executeResponse, vn as RelationArrayEnvelope, vr as ResourceCountOperation, vt as RelationName, w as JsonApiTransport, wn as relatedPaginatorKind, wt as ResourceAccessors, x as HANDLE_RESERVED, xn as ResourceLinks, xr as SortFamilyDescriptor, xt as RelationReadQuery, y as serializeQuery, yn as RelationView, yr as ResourceDescriptor, yt as RelationPageParams, z as CountToken, zn as PollTimeoutError, zt as WaitedWriteResult } from "./validate-DGoH9XA9.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, 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, ResourceCountOperation, ResourceCountToken, 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 };
257
257
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1334,7 +1334,7 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1334
1334
  if (listFilter !== void 0) req.listFilter = listFilter;
1335
1335
  if (params.relatedQuery !== void 0) req.relatedListFilter = relatedListFilter(ctx, type);
1336
1336
  if (signal !== void 0) req.signal = signal;
1337
- negotiateProfiles(ctx, type, params, req, relationForCount);
1337
+ negotiateProfiles(ctx, type, params, req, relationForCount, operation);
1338
1338
  }
1339
1339
  const doc = await execute(ctx.request, req);
1340
1340
  const relation = (operation === "fetchRelated" || operation === "fetchRelationship") && vars["rel"] !== void 0 ? ctx.descriptor[type]?.relations[vars["rel"]] : void 0;
@@ -1384,16 +1384,18 @@ function sendsRelatedQuery(relatedQuery) {
1384
1384
  }
1385
1385
  /**
1386
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
1387
+ * `withCount` read or write needs the Countable profile in `Accept`, else the server rejects it
1388
+ * (400) under strict query-param validation. The profile URI is read from the descriptor (never
1389
+ * hardcoded): the relation's `countable` for a related or relationship read, the operation's
1390
+ * `resourceCountable` entry for a single-resource read or a write, else the type's `countable`.
1391
+ * A `relatedQuery` on a collection or single read likewise adds the type's Relationship Queries
1391
1392
  * profile, after any Countable one.
1392
1393
  */
1393
- function negotiateProfiles(ctx, type, query, req, relationForCount) {
1394
+ function negotiateProfiles(ctx, type, query, req, relationForCount, operation) {
1394
1395
  const profiles = [];
1395
1396
  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;
1397
+ const descriptor = ctx.descriptor[type];
1398
+ const profile = relationForCount !== void 0 ? descriptor?.relations[relationForCount]?.countable?.profile : (isResourceCountOperation(operation) ? descriptor?.resourceCountable?.[operation]?.profile : void 0) ?? descriptor?.countable?.profile;
1397
1399
  if (profile !== void 0) profiles.push(profile);
1398
1400
  }
1399
1401
  if (relationForCount === void 0 && sendsRelatedQuery(query.relatedQuery)) {
@@ -1402,11 +1404,19 @@ function negotiateProfiles(ctx, type, query, req, relationForCount) {
1402
1404
  }
1403
1405
  if (profiles.length > 0) req.profiles = [...req.profiles ?? [], ...profiles];
1404
1406
  }
1405
- /** Project a write's opts to the read-query families the response honours (`include`/`fields`). */
1407
+ /** Whether an operation is one answering with one resource that may take `withCount`. */
1408
+ function isResourceCountOperation(operation) {
1409
+ return operation === "fetchOne" || operation === "create" || operation === "update";
1410
+ }
1411
+ /**
1412
+ * Project a write's opts to the read-query families the response honours: `include`, `fields`
1413
+ * and `withCount`.
1414
+ */
1406
1415
  function writeQuery(opts) {
1407
1416
  if (opts === void 0) return;
1408
1417
  const query = {};
1409
1418
  if (opts.include !== void 0) query.include = [...opts.include];
1419
+ if (opts.withCount !== void 0) query.withCount = [...opts.withCount];
1410
1420
  if (opts.fields !== void 0) {
1411
1421
  const fields = {};
1412
1422
  for (const [k, v] of Object.entries(opts.fields)) fields[k] = [...v];
@@ -1446,7 +1456,11 @@ async function runWrite(ctx, spec) {
1446
1456
  path: fillPath(ctx, spec.type, template, spec.vars),
1447
1457
  body: spec.body
1448
1458
  };
1449
- if (spec.query !== void 0) req.query = spec.query;
1459
+ if (spec.query !== void 0) {
1460
+ req.query = spec.query;
1461
+ negotiateProfiles(ctx, spec.type, spec.query, req, void 0, spec.operation);
1462
+ if (req.profiles !== void 0) req.contentType = JSON_API_MEDIA_TYPE;
1463
+ }
1450
1464
  if (spec.wait?.signal !== void 0) req.signal = spec.wait.signal;
1451
1465
  let res;
1452
1466
  try {