@haddowg/json-api-client 1.22.0 → 1.24.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
@@ -108,6 +108,18 @@ tracks.$page.kind
108
108
  const linkage = await client.albums.id('1').rel('tracks').get()
109
109
  ```
110
110
 
111
+ ### A singleton
112
+
113
+ A singleton type serves each caller one resource at a path with no id (`/inbox`). Its accessor is
114
+ a handle on that resource, with no `list`, `create`, `id()` or `delete`. The update body needs the
115
+ resource's id, so the input carries it:
116
+
117
+ ```ts
118
+ const inbox = await client.inboxes.get() // GET /inbox
119
+ await client.inboxes.update({ id: inbox.id, seenUpTo: new Date().toISOString() }) // PATCH /inbox
120
+ const owner = await client.inboxes.owner.related() // GET /inbox/owner
121
+ ```
122
+
111
123
  ### Pivot data on a many-to-many edge
112
124
 
113
125
  Each member of a `belongsToMany` to-many carries its per-edge pivot under `$pivot` (typed sugar
package/dist/ajv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Validator, n as SchemaMap } from "./validate-Rgo7Zm0U.cjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-9lr5GAdA.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-Rgo7Zm0U.mjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-9lr5GAdA.mjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/index.cjs CHANGED
@@ -1683,16 +1683,17 @@ function actionsAccessor(ctx, type, scope, vars) {
1683
1683
  return out;
1684
1684
  }
1685
1685
  /**
1686
- * Build the relationship accessor for `client.<type>.id(id).<rel>`: reads
1686
+ * Build the relationship accessor for `client.<type>.id(id).<rel>`, or a singleton's
1687
+ * `client.<type>.<rel>` with no `id` in `vars`: reads
1687
1688
  * (`.get()` linkage / `.related()` collection) plus mutations — to-many `.add` (POST) /
1688
1689
  * `.remove` (DELETE) / `.replace` (PATCH) and to-one `.set` (PATCH). Every mutation posts
1689
1690
  * a `{ data: <linkage> }` body to `fetchRelationship` and materialises the response as
1690
1691
  * linkage (or `undefined`/`void` for a `204`). The cardinality is read off the descriptor
1691
1692
  * so the linkage is coerced correctly; the static types gate which verb is callable.
1692
1693
  */
1693
- function relationshipAccessor(ctx, type, id, rel) {
1694
+ function relationshipAccessor(ctx, type, owner, rel) {
1694
1695
  const vars = {
1695
- id,
1696
+ ...owner,
1696
1697
  rel
1697
1698
  };
1698
1699
  const relation = ctx.descriptor[type]?.relations[rel];
@@ -1738,39 +1739,72 @@ const HANDLE_RESERVED = /* @__PURE__ */ new Set([
1738
1739
  "actions",
1739
1740
  "then"
1740
1741
  ]);
1742
+ /**
1743
+ * Run a type's update. `vars` fill its path (`{ id }`, or nothing for a singleton) and `id` is
1744
+ * the one the body carries.
1745
+ */
1746
+ function runUpdate(ctx, type, vars, id, patch, opts) {
1747
+ return runWrite(ctx, {
1748
+ type,
1749
+ operation: "update",
1750
+ vars,
1751
+ method: "PATCH",
1752
+ body: toDocument(ctx.descriptor, type, patch, { id }),
1753
+ query: writeQuery(opts),
1754
+ remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
1755
+ accepted: ctx.descriptor[type]?.accepted?.update,
1756
+ wait: waitOptions(opts?.wait)
1757
+ });
1758
+ }
1759
+ /**
1760
+ * Wrap a handle's verbs in a Proxy resolving each relation not shadowed by a reserved member to
1761
+ * its relationship accessor, addressed by `vars`.
1762
+ */
1763
+ function withRelations(ctx, type, vars, base) {
1764
+ const relations = ctx.descriptor[type]?.relations ?? {};
1765
+ return new Proxy(base, { get(target, prop, receiver) {
1766
+ if (typeof prop === "string" && !HANDLE_RESERVED.has(prop) && prop in relations) return relationshipAccessor(ctx, type, vars, prop);
1767
+ return Reflect.get(target, prop, receiver);
1768
+ } });
1769
+ }
1741
1770
  /** Build the id-scoped resource handle (a Proxy resolving relation accessors by name). */
1742
1771
  function resourceHandle(ctx, type, id) {
1743
- const relations = ctx.descriptor[type]?.relations ?? {};
1744
- const base = {
1772
+ const vars = { id };
1773
+ return withRelations(ctx, type, vars, {
1745
1774
  type,
1746
1775
  id,
1747
- get: (query) => run(ctx, type, "fetchOne", { id }, query),
1748
- update: (patch, opts) => runWrite(ctx, {
1749
- type,
1750
- operation: "update",
1751
- vars: { id },
1752
- method: "PATCH",
1753
- body: toDocument(ctx.descriptor, type, patch, { id }),
1754
- query: writeQuery(opts),
1755
- remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
1756
- accepted: ctx.descriptor[type]?.accepted?.update,
1757
- wait: waitOptions(opts?.wait)
1758
- }),
1776
+ get: (query) => run(ctx, type, "fetchOne", vars, query),
1777
+ update: (patch, opts) => runUpdate(ctx, type, vars, id, patch, opts),
1759
1778
  delete: () => runWrite(ctx, {
1760
1779
  type,
1761
1780
  operation: "delete",
1762
- vars: { id },
1781
+ vars,
1763
1782
  method: "DELETE",
1764
1783
  body: void 0,
1765
1784
  remap: (error) => withRemappedPaths(error, ctx.descriptor, type)
1766
1785
  }),
1767
- rel: (name) => relationshipAccessor(ctx, type, id, name),
1768
- actions: actionsAccessor(ctx, type, "resource", { id })
1769
- };
1770
- return new Proxy(base, { get(target, prop, receiver) {
1771
- if (typeof prop === "string" && !HANDLE_RESERVED.has(prop) && prop in relations) return relationshipAccessor(ctx, type, id, prop);
1772
- return Reflect.get(target, prop, receiver);
1773
- } });
1786
+ rel: (name) => relationshipAccessor(ctx, type, vars, name),
1787
+ actions: actionsAccessor(ctx, type, "resource", vars)
1788
+ });
1789
+ }
1790
+ /**
1791
+ * Build the accessor of a singleton type (`client.inboxes`): a handle on the caller's one
1792
+ * resource, whose paths carry no id. Its update takes the resource's `id` in the input, since
1793
+ * the server reads it from the body.
1794
+ */
1795
+ function singletonAccessor(ctx, type) {
1796
+ const vars = {};
1797
+ return withRelations(ctx, type, vars, {
1798
+ type,
1799
+ get: (query) => run(ctx, type, "fetchOne", vars, query),
1800
+ update: (input, opts) => {
1801
+ const { id, ...patch } = input;
1802
+ if (typeof id !== "string" || id === "") return Promise.reject(/* @__PURE__ */ new Error(`Updating the "${type}" singleton needs its id in the input, such as the id of the resource its get() read.`));
1803
+ return runUpdate(ctx, type, vars, id, patch, opts);
1804
+ },
1805
+ rel: (name) => relationshipAccessor(ctx, type, vars, name),
1806
+ actions: actionsAccessor(ctx, type, "resource", vars)
1807
+ });
1774
1808
  }
1775
1809
  /** Build the collection-scoped accessor for one wire type (`client.albums`). */
1776
1810
  function typeAccessor(ctx, type) {
@@ -1794,7 +1828,8 @@ function typeAccessor(ctx, type) {
1794
1828
  }
1795
1829
  /**
1796
1830
  * Build a descriptor-driven read client. Generic at runtime (a Proxy over the descriptor),
1797
- * not per-type codegen: `client.<type>` yields a {@link TypeAccessor}, `.id(id)` a handle,
1831
+ * not per-type codegen: `client.<type>` yields a {@link TypeAccessor}, or a
1832
+ * {@link SingletonAccessor} for a singleton type, `.id(id)` a handle,
1798
1833
  * and a handle's relation accessors drive the relationship/related endpoints. Navigation
1799
1834
  * (`$next()`/`$prev()`, related links) is wired through `materialise`'s `navigate` seam,
1800
1835
  * which resolves the server's link against `baseUrl`, executes it and re-materialises.
@@ -1836,7 +1871,7 @@ function createClient(descriptor, options) {
1836
1871
  if (typeof prop !== "string" || !(prop in descriptor)) return;
1837
1872
  let accessor = accessors.get(prop);
1838
1873
  if (accessor === void 0) {
1839
- accessor = typeAccessor(ctx, prop);
1874
+ accessor = descriptor[prop]?.singleton === true ? singletonAccessor(ctx, prop) : typeAccessor(ctx, prop);
1840
1875
  accessors.set(prop, accessor);
1841
1876
  }
1842
1877
  return accessor;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { $ as IdentifierMember, $n as ActionInput, $t as readActionLocation, A as AcceptedOf, An as materialise, Ar as StrategyDescriptor, At as ResourceCountToken, B as CountedRelationName, Bn as PageParams, Bt as TypedReadQuery, C as createClient, Cn as LinkObject, Cr as RelatedQueryOperation, Ct as RelationName, D as TransportResponse, Dn as RelationView, Dr as ResourceDescriptor, Dt as RelationSortQuery, E as TransportRequest, En as RelationArrayEnvelope, Er as ResourceCountOperation, Et as RelationReadQuery, F as BinaryResponseType, Fn as Page, Ft as SingletonUpdateInput, G as DefaultWriteAttributes, Gn as Accepted, Gt as WaitOptions, H as CreateMethod, Hn as ResolvedPaginator, Ht as TypedRelationReadQuery, I as Client, In as PageKeys, It as SortQuery, J as FieldSelectionMap, Jn as isAccepted, Jt as WithLinks, K as EdgeMembers, Kn as PollOptions, Kt as WaitValue, L as Collection, Ln as PageLinks, Lt as SortToken, M as ActionsAccessor, Mn as relatedPaginatorKind, Mt as ResourceObjectView, N as AtomicResultOf, Nn as CANONICAL_PAGE_KEYS, Nt as SingleReadQuery, O as fetchTransport, On as ResourceEnvelope, Or as ResourceExamples, Ot as RelationshipAccessor, P as BinaryBody, Pn as ExactPageParams, Pt as SingletonAccessor, Q as HydratedMember, Qn as ActionDescriptor, Qt as isActionLocation, R as CountAccessor, Rn as PageMeta, Rt as TypeAccessor, S as HeadersInit, Sn as Link, Sr as RelatedQueryDescriptor, St as RelationFilterQuery, T as TransportRawBody, Tn as NavigateOptions, Tr as RelationMutations, Tt as RelationPaginator, U as DefaultActionTypes, Un as TypedPage, Ut as UpdateInput, V as CreateInput, Vn as PageParamsOf, Vt as TypedRelatedReadQuery, W as DefaultAttributes, Wn as resolvePaginator, Wt as UpdateMethod, X as FilterKey, Xn as AcceptedDescriptor, Xt as WriteResult, Y as FieldsMap, Yn as parseRetryAfter, Yt as WriteOptions, Z as FilterQuery, Zn as AcceptedOperation, Zt as ActionLocation, _ as executeRaw, _n as mediaType, _r as PaginatorRole, _t as RelatedQueryEntry, a as Validator, an as AtomicRef, ar as AtomicDescriptor, at as LinkageRef, b as ClientOptions, bn as Edge, br as RawMediaKind, bt as RelatedReadRelatedQuery, c as resolveValidator, cn as AtomicUpdateHandle, cr as CountableDescriptor, ct as LooseRelatedQuery, d as ExecutedResponse, dn as ATOMIC_EXT, dr as InputMediaKind, dt as PivotInput, en as AtomicCreateHandle, er as ActionLocationDescriptor, et as IncludePath, f as JsonApiContext, fn as ATOMIC_MEDIA_TYPE, fr as MediaExamples, ft as ReadResult, g as execute, gn as ResourceIdentifier, gr as PaginatorKind, gt as RelatedQuery, h as ReadQuery, hn as MediaTypeParams, hr as PaginatorDescriptor, ht as RelatedIncludedType, i as ValidationOption, in as AtomicRecorder, ir as ApiExamples, it as IsSingleton, j as ActionCallOptions, jn as relatedPaginator, jr as isPolymorphic, jt as ResourceHandle, k as AcceptedJob, kn as ResourceLinks, kr as SortFamilyDescriptor, kt as ResourceAccessors, l as validateDocument, ln as AtomicUpdateInput, lr as FilterFamilyDescriptor, lt as LooseRelatedQueryEntry, m as RawResponseType, mn as LocalIdentifier, mr as OperationExamples, mt as RelatedIncludedResource, n as SchemaMap, nn as AtomicDeleteHandle, nr as ActionScope, nt as IncludedResource, o as WireResource, on as AtomicResult, or as Cardinality, ot as ListFilterMember, p as JsonApiRequest, pn as JSON_API_MEDIA_TYPE, pr as MenuDescriptor, pt as ReadableRelationName, q as ErrorCodeOf, qn as PollTimeoutError, qt as WaitedWriteResult, r as ValidationConfig, rn as AtomicHandle, rr as ApiDescriptor, rt as IncludedType, s as assertJsonApiDocument, sn as AtomicResults, sr as ClientIdPolicy, st as ListPageParams, t as ResolvedValidator, tn as AtomicCreateInput, tr as ActionOutput, tt as IncludedRelations, u as Document, un as runAtomic, ur as InputMedia, ut as MemberName, v as executeResponse, vn as ArrayEnvelope, vr as PaginatorStrategy, vt as RelatedQueryParam, w as JsonApiTransport, wn as MaterialiseContext, wr as RelationDescriptor, wt as RelationPageParams, x as HANDLE_RESERVED, xn as EdgeEnvelope, xr as RawOutputMedia, xt as RelationCollection, y as serializeQuery, yn as DocumentEnvelope, yr as PivotDescriptor, yt as RelatedQueryRelation, z as CountToken, zn as PageOf, zt as TypeName } from "./validate-9lr5GAdA.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, 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 };
256
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, ExecutedResponse, FieldSelectionMap, FieldsMap, FilterFamilyDescriptor, FilterKey, FilterQuery, FilterSpec, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, IncludedResource, IncludedType, InputMedia, InputMediaKind, IsSingleton, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListFilterMember, ListPageParams, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
257
257
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { $ as IdentifierMember, $n as ActionInput, $t as readActionLocation, A as AcceptedOf, An as materialise, Ar as StrategyDescriptor, At as ResourceCountToken, B as CountedRelationName, Bn as PageParams, Bt as TypedReadQuery, C as createClient, Cn as LinkObject, Cr as RelatedQueryOperation, Ct as RelationName, D as TransportResponse, Dn as RelationView, Dr as ResourceDescriptor, Dt as RelationSortQuery, E as TransportRequest, En as RelationArrayEnvelope, Er as ResourceCountOperation, Et as RelationReadQuery, F as BinaryResponseType, Fn as Page, Ft as SingletonUpdateInput, G as DefaultWriteAttributes, Gn as Accepted, Gt as WaitOptions, H as CreateMethod, Hn as ResolvedPaginator, Ht as TypedRelationReadQuery, I as Client, In as PageKeys, It as SortQuery, J as FieldSelectionMap, Jn as isAccepted, Jt as WithLinks, K as EdgeMembers, Kn as PollOptions, Kt as WaitValue, L as Collection, Ln as PageLinks, Lt as SortToken, M as ActionsAccessor, Mn as relatedPaginatorKind, Mt as ResourceObjectView, N as AtomicResultOf, Nn as CANONICAL_PAGE_KEYS, Nt as SingleReadQuery, O as fetchTransport, On as ResourceEnvelope, Or as ResourceExamples, Ot as RelationshipAccessor, P as BinaryBody, Pn as ExactPageParams, Pt as SingletonAccessor, Q as HydratedMember, Qn as ActionDescriptor, Qt as isActionLocation, R as CountAccessor, Rn as PageMeta, Rt as TypeAccessor, S as HeadersInit, Sn as Link, Sr as RelatedQueryDescriptor, St as RelationFilterQuery, T as TransportRawBody, Tn as NavigateOptions, Tr as RelationMutations, Tt as RelationPaginator, U as DefaultActionTypes, Un as TypedPage, Ut as UpdateInput, V as CreateInput, Vn as PageParamsOf, Vt as TypedRelatedReadQuery, W as DefaultAttributes, Wn as resolvePaginator, Wt as UpdateMethod, X as FilterKey, Xn as AcceptedDescriptor, Xt as WriteResult, Y as FieldsMap, Yn as parseRetryAfter, Yt as WriteOptions, Z as FilterQuery, Zn as AcceptedOperation, Zt as ActionLocation, _ as executeRaw, _n as mediaType, _r as PaginatorRole, _t as RelatedQueryEntry, a as Validator, an as AtomicRef, ar as AtomicDescriptor, at as LinkageRef, b as ClientOptions, bn as Edge, br as RawMediaKind, bt as RelatedReadRelatedQuery, c as resolveValidator, cn as AtomicUpdateHandle, cr as CountableDescriptor, ct as LooseRelatedQuery, d as ExecutedResponse, dn as ATOMIC_EXT, dr as InputMediaKind, dt as PivotInput, en as AtomicCreateHandle, er as ActionLocationDescriptor, et as IncludePath, f as JsonApiContext, fn as ATOMIC_MEDIA_TYPE, fr as MediaExamples, ft as ReadResult, g as execute, gn as ResourceIdentifier, gr as PaginatorKind, gt as RelatedQuery, h as ReadQuery, hn as MediaTypeParams, hr as PaginatorDescriptor, ht as RelatedIncludedType, i as ValidationOption, in as AtomicRecorder, ir as ApiExamples, it as IsSingleton, j as ActionCallOptions, jn as relatedPaginator, jr as isPolymorphic, jt as ResourceHandle, k as AcceptedJob, kn as ResourceLinks, kr as SortFamilyDescriptor, kt as ResourceAccessors, l as validateDocument, ln as AtomicUpdateInput, lr as FilterFamilyDescriptor, lt as LooseRelatedQueryEntry, m as RawResponseType, mn as LocalIdentifier, mr as OperationExamples, mt as RelatedIncludedResource, n as SchemaMap, nn as AtomicDeleteHandle, nr as ActionScope, nt as IncludedResource, o as WireResource, on as AtomicResult, or as Cardinality, ot as ListFilterMember, p as JsonApiRequest, pn as JSON_API_MEDIA_TYPE, pr as MenuDescriptor, pt as ReadableRelationName, q as ErrorCodeOf, qn as PollTimeoutError, qt as WaitedWriteResult, r as ValidationConfig, rn as AtomicHandle, rr as ApiDescriptor, rt as IncludedType, s as assertJsonApiDocument, sn as AtomicResults, sr as ClientIdPolicy, st as ListPageParams, t as ResolvedValidator, tn as AtomicCreateInput, tr as ActionOutput, tt as IncludedRelations, u as Document, un as runAtomic, ur as InputMedia, ut as MemberName, v as executeResponse, vn as ArrayEnvelope, vr as PaginatorStrategy, vt as RelatedQueryParam, w as JsonApiTransport, wn as MaterialiseContext, wr as RelationDescriptor, wt as RelationPageParams, x as HANDLE_RESERVED, xn as EdgeEnvelope, xr as RawOutputMedia, xt as RelationCollection, y as serializeQuery, yn as DocumentEnvelope, yr as PivotDescriptor, yt as RelatedQueryRelation, z as CountToken, zn as PageOf, zt as TypeName } from "./validate-9lr5GAdA.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, 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 };
256
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, type Accepted, AcceptedDescriptor, AcceptedJob, AcceptedOf, AcceptedOperation, ActionCallOptions, ActionDescriptor, ActionInput, ActionLocation, ActionLocationDescriptor, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ApiExamples, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, BinaryBody, BinaryResponseType, CANONICAL_PAGE_KEYS, Cardinality, Client, ClientIdPolicy, ClientOptions, CodedErrorObject, Collection, CountAccessor, CountToken, CountableDescriptor, CountedRelationName, CreateInput, CreateMethod, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, ExecutedResponse, FieldSelectionMap, FieldsMap, FilterFamilyDescriptor, FilterKey, FilterQuery, FilterSpec, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, IncludedResource, IncludedType, InputMedia, InputMediaKind, IsSingleton, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, Link, LinkObject, LinkageRef, ListFilterMember, ListPageParams, LocalIdentifier, LooseRelatedQuery, LooseRelatedQueryEntry, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, type PollOptions, PollTimeoutError, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelatedQuery, RelatedQueryDescriptor, RelatedQueryEntry, RelatedQueryOperation, RelatedQueryParam, RelatedQueryRelation, RelatedReadRelatedQuery, RelationArrayEnvelope, RelationCollection, RelationDescriptor, RelationFilterQuery, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, RelationSortQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedPaginator, ResolvedValidator, ResourceAccessors, ResourceCountOperation, ResourceCountToken, ResourceDescriptor, ResourceEnvelope, ResourceExamples, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SingletonAccessor, SingletonUpdateInput, SortFamilyDescriptor, SortQuery, SortToken, StrategyDescriptor, StructuralGuardError, ToDocumentOptions, TransportRawBody, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedPage, TypedReadQuery, TypedRelatedReadQuery, TypedRelationReadQuery, UpdateInput, UpdateMethod, ValidationConfig, ValidationOption, Validator, WaitOptions, WaitValue, WaitedWriteResult, WireResource, WithLinks, WriteDocument, WriteOptions, WriteResult, assertJsonApiDocument, createClient, execute, executeRaw, executeResponse, fetchTransport, findError, hasErrorCode, isAccepted, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, parseRetryAfter, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
257
257
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1682,16 +1682,17 @@ function actionsAccessor(ctx, type, scope, vars) {
1682
1682
  return out;
1683
1683
  }
1684
1684
  /**
1685
- * Build the relationship accessor for `client.<type>.id(id).<rel>`: reads
1685
+ * Build the relationship accessor for `client.<type>.id(id).<rel>`, or a singleton's
1686
+ * `client.<type>.<rel>` with no `id` in `vars`: reads
1686
1687
  * (`.get()` linkage / `.related()` collection) plus mutations — to-many `.add` (POST) /
1687
1688
  * `.remove` (DELETE) / `.replace` (PATCH) and to-one `.set` (PATCH). Every mutation posts
1688
1689
  * a `{ data: <linkage> }` body to `fetchRelationship` and materialises the response as
1689
1690
  * linkage (or `undefined`/`void` for a `204`). The cardinality is read off the descriptor
1690
1691
  * so the linkage is coerced correctly; the static types gate which verb is callable.
1691
1692
  */
1692
- function relationshipAccessor(ctx, type, id, rel) {
1693
+ function relationshipAccessor(ctx, type, owner, rel) {
1693
1694
  const vars = {
1694
- id,
1695
+ ...owner,
1695
1696
  rel
1696
1697
  };
1697
1698
  const relation = ctx.descriptor[type]?.relations[rel];
@@ -1737,39 +1738,72 @@ const HANDLE_RESERVED = /* @__PURE__ */ new Set([
1737
1738
  "actions",
1738
1739
  "then"
1739
1740
  ]);
1741
+ /**
1742
+ * Run a type's update. `vars` fill its path (`{ id }`, or nothing for a singleton) and `id` is
1743
+ * the one the body carries.
1744
+ */
1745
+ function runUpdate(ctx, type, vars, id, patch, opts) {
1746
+ return runWrite(ctx, {
1747
+ type,
1748
+ operation: "update",
1749
+ vars,
1750
+ method: "PATCH",
1751
+ body: toDocument(ctx.descriptor, type, patch, { id }),
1752
+ query: writeQuery(opts),
1753
+ remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
1754
+ accepted: ctx.descriptor[type]?.accepted?.update,
1755
+ wait: waitOptions(opts?.wait)
1756
+ });
1757
+ }
1758
+ /**
1759
+ * Wrap a handle's verbs in a Proxy resolving each relation not shadowed by a reserved member to
1760
+ * its relationship accessor, addressed by `vars`.
1761
+ */
1762
+ function withRelations(ctx, type, vars, base) {
1763
+ const relations = ctx.descriptor[type]?.relations ?? {};
1764
+ return new Proxy(base, { get(target, prop, receiver) {
1765
+ if (typeof prop === "string" && !HANDLE_RESERVED.has(prop) && prop in relations) return relationshipAccessor(ctx, type, vars, prop);
1766
+ return Reflect.get(target, prop, receiver);
1767
+ } });
1768
+ }
1740
1769
  /** Build the id-scoped resource handle (a Proxy resolving relation accessors by name). */
1741
1770
  function resourceHandle(ctx, type, id) {
1742
- const relations = ctx.descriptor[type]?.relations ?? {};
1743
- const base = {
1771
+ const vars = { id };
1772
+ return withRelations(ctx, type, vars, {
1744
1773
  type,
1745
1774
  id,
1746
- get: (query) => run(ctx, type, "fetchOne", { id }, query),
1747
- update: (patch, opts) => runWrite(ctx, {
1748
- type,
1749
- operation: "update",
1750
- vars: { id },
1751
- method: "PATCH",
1752
- body: toDocument(ctx.descriptor, type, patch, { id }),
1753
- query: writeQuery(opts),
1754
- remap: (error) => withRemappedPaths(error, ctx.descriptor, type),
1755
- accepted: ctx.descriptor[type]?.accepted?.update,
1756
- wait: waitOptions(opts?.wait)
1757
- }),
1775
+ get: (query) => run(ctx, type, "fetchOne", vars, query),
1776
+ update: (patch, opts) => runUpdate(ctx, type, vars, id, patch, opts),
1758
1777
  delete: () => runWrite(ctx, {
1759
1778
  type,
1760
1779
  operation: "delete",
1761
- vars: { id },
1780
+ vars,
1762
1781
  method: "DELETE",
1763
1782
  body: void 0,
1764
1783
  remap: (error) => withRemappedPaths(error, ctx.descriptor, type)
1765
1784
  }),
1766
- rel: (name) => relationshipAccessor(ctx, type, id, name),
1767
- actions: actionsAccessor(ctx, type, "resource", { id })
1768
- };
1769
- return new Proxy(base, { get(target, prop, receiver) {
1770
- if (typeof prop === "string" && !HANDLE_RESERVED.has(prop) && prop in relations) return relationshipAccessor(ctx, type, id, prop);
1771
- return Reflect.get(target, prop, receiver);
1772
- } });
1785
+ rel: (name) => relationshipAccessor(ctx, type, vars, name),
1786
+ actions: actionsAccessor(ctx, type, "resource", vars)
1787
+ });
1788
+ }
1789
+ /**
1790
+ * Build the accessor of a singleton type (`client.inboxes`): a handle on the caller's one
1791
+ * resource, whose paths carry no id. Its update takes the resource's `id` in the input, since
1792
+ * the server reads it from the body.
1793
+ */
1794
+ function singletonAccessor(ctx, type) {
1795
+ const vars = {};
1796
+ return withRelations(ctx, type, vars, {
1797
+ type,
1798
+ get: (query) => run(ctx, type, "fetchOne", vars, query),
1799
+ update: (input, opts) => {
1800
+ const { id, ...patch } = input;
1801
+ if (typeof id !== "string" || id === "") return Promise.reject(/* @__PURE__ */ new Error(`Updating the "${type}" singleton needs its id in the input, such as the id of the resource its get() read.`));
1802
+ return runUpdate(ctx, type, vars, id, patch, opts);
1803
+ },
1804
+ rel: (name) => relationshipAccessor(ctx, type, vars, name),
1805
+ actions: actionsAccessor(ctx, type, "resource", vars)
1806
+ });
1773
1807
  }
1774
1808
  /** Build the collection-scoped accessor for one wire type (`client.albums`). */
1775
1809
  function typeAccessor(ctx, type) {
@@ -1793,7 +1827,8 @@ function typeAccessor(ctx, type) {
1793
1827
  }
1794
1828
  /**
1795
1829
  * Build a descriptor-driven read client. Generic at runtime (a Proxy over the descriptor),
1796
- * not per-type codegen: `client.<type>` yields a {@link TypeAccessor}, `.id(id)` a handle,
1830
+ * not per-type codegen: `client.<type>` yields a {@link TypeAccessor}, or a
1831
+ * {@link SingletonAccessor} for a singleton type, `.id(id)` a handle,
1797
1832
  * and a handle's relation accessors drive the relationship/related endpoints. Navigation
1798
1833
  * (`$next()`/`$prev()`, related links) is wired through `materialise`'s `navigate` seam,
1799
1834
  * which resolves the server's link against `baseUrl`, executes it and re-materialises.
@@ -1835,7 +1870,7 @@ function createClient(descriptor, options) {
1835
1870
  if (typeof prop !== "string" || !(prop in descriptor)) return;
1836
1871
  let accessor = accessors.get(prop);
1837
1872
  if (accessor === void 0) {
1838
- accessor = typeAccessor(ctx, prop);
1873
+ accessor = descriptor[prop]?.singleton === true ? singletonAccessor(ctx, prop) : typeAccessor(ctx, prop);
1839
1874
  accessors.set(prop, accessor);
1840
1875
  }
1841
1876
  return accessor;