@haddowg/json-api-client 1.0.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.
@@ -0,0 +1,198 @@
1
+ import { $ as SortQuery, A as DefaultActionTypes, At as RelationView, B as IncludePath, Bt as AtomicDescriptor, C as fetchTransport, Ct as mediaType, D as Collection, Dt as EdgeEnvelope, E as Client, Et as Edge, F as FieldsMap, Ft as ActionDescriptor, G as ReadResult, Gt as RelationDescriptor, H as LinkageRef, Ht as ClientIdPolicy, I as FilterKey, It as ActionInput, J as RelationshipAccessor, K as RelationName, Kt as RelationMutations, L as FilterQuery, Lt as ActionOutput, M as DefaultWriteAttributes, Mt as ResourceLinks, N as EdgeMembers, Nt as materialise, O as CountToken, Ot as MaterialiseContext, P as FieldSelectionMap, Pt as relatedPaginatorKind, Q as SingleReadQuery, R as HydratedMember, Rt as ActionScope, S as TransportResponse, St as ResourceIdentifier, T as AtomicResultOf, Tt as DocumentEnvelope, U as MemberName, Ut as CountableDescriptor, V as IncludedRelations, Vt as Cardinality, W as PivotInput, Wt as PaginatorKind, X as ResourceHandle, Y as ResourceAccessors, Z as ResourceObjectView, _ as HANDLE_RESERVED, _t as ATOMIC_EXT, a as Validator, at as WriteOptions, b as JsonApiTransport, bt as LocalIdentifier, c as resolveValidator, ct as AtomicDeleteHandle, d as JsonApiContext, dt as AtomicRef, et as SortToken, f as JsonApiRequest, ft as AtomicResult, g as ClientOptions, gt as runAtomic, h as serializeQuery, ht as AtomicUpdateInput, i as ValidationOption, it as UpdateInput, j as DefaultAttributes, jt as ResourceEnvelope, k as CreateInput, kt as Page, l as validateDocument, lt as AtomicHandle, m as execute, mt as AtomicUpdateHandle, n as SchemaMap, nt as TypeName, o as WireResource, ot as AtomicCreateHandle, p as ReadQuery, pt as AtomicResults, q as RelationReadQuery, qt as ResourceDescriptor, r as ValidationConfig, rt as TypedReadQuery, s as assertJsonApiDocument, st as AtomicCreateInput, t as ResolvedValidator, tt as TypeAccessor, u as Document, ut as AtomicRecorder, v as HeadersInit, vt as ATOMIC_MEDIA_TYPE, w as ActionsAccessor, wt as ArrayEnvelope, x as TransportRequest, xt as MediaTypeParams, y as createClient, yt as JSON_API_MEDIA_TYPE, z as IdentifierMember, zt as ApiDescriptor } from "./validate-BmyPbJCK.cjs";
2
+
3
+ //#region src/errors.d.ts
4
+ /** A single JSON:API error object (spec: error objects). */
5
+ interface JsonApiErrorObject {
6
+ id?: string;
7
+ status?: string;
8
+ code?: string;
9
+ title?: string;
10
+ detail?: string;
11
+ source?: {
12
+ pointer?: string;
13
+ parameter?: string;
14
+ header?: string;
15
+ };
16
+ meta?: Record<string, unknown>;
17
+ /**
18
+ * The user-facing input path, remapped from `source.pointer` for write errors
19
+ * (e.g. `/data/attributes/title` -> `title`). Populated by the runtime, which
20
+ * built the envelope and therefore knows the inverse mapping. See CONTEXT.md.
21
+ */
22
+ path?: string;
23
+ /**
24
+ * The zero-based index of the failing operation within an atomic batch, parsed from a
25
+ * `source.pointer` carrying an `/atomic:operations/{n}` prefix. Populated only for atomic
26
+ * errors; `path` then holds the flat path within that operation's input.
27
+ */
28
+ opIndex?: number;
29
+ }
30
+ /**
31
+ * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
32
+ * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
33
+ * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
34
+ * runtime relies on was violated, not an application error the server reported. The opt-in
35
+ * per-field validator throws its engine's own error type, never this one.
36
+ */
37
+ declare class StructuralGuardError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ /**
41
+ * Thrown for any non-2xx JSON:API response. Carries the parsed error document plus
42
+ * expressive status matchers and pointer-grouping helpers.
43
+ */
44
+ declare class JsonApiError extends Error {
45
+ readonly status: number;
46
+ readonly errors: JsonApiErrorObject[];
47
+ constructor(status: number, errors: JsonApiErrorObject[], message?: string);
48
+ hasStatus(status: number): boolean;
49
+ is4xx(): boolean;
50
+ is5xx(): boolean;
51
+ isBadRequest(): boolean;
52
+ isUnauthorized(): boolean;
53
+ isForbidden(): boolean;
54
+ isNotFound(): boolean;
55
+ isNotAcceptable(): boolean;
56
+ isConflict(): boolean;
57
+ isUnsupportedMediaType(): boolean;
58
+ isUnprocessable(): boolean;
59
+ /** Alias of {@link isUnprocessable} — the JSON:API validation status. */
60
+ isValidationError(): boolean;
61
+ isRateLimited(): boolean;
62
+ /**
63
+ * Group errors by user-facing input path (falls back to the raw pointer, then the
64
+ * query parameter). The payoff for form/validation UX — 422 `source.pointer`s are
65
+ * remapped to the flat shape the caller actually supplied.
66
+ */
67
+ byPath(): Record<string, JsonApiErrorObject[]>;
68
+ }
69
+ //#endregion
70
+ //#region src/serialize-write.d.ts
71
+ /**
72
+ * A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
73
+ * batch — `{ type, lid }` (a reference to a resource created earlier in the same transaction).
74
+ * May carry writable pivot meta on a to-many member.
75
+ */
76
+ interface WriteIdentifier {
77
+ type: string;
78
+ id?: string;
79
+ lid?: string;
80
+ meta?: {
81
+ pivot: Record<string, unknown>;
82
+ } & Record<string, unknown>;
83
+ }
84
+ /** A relationship document: `{ data: <linkage> }`. */
85
+ interface RelationshipDocument {
86
+ data: WriteIdentifier | WriteIdentifier[] | null;
87
+ }
88
+ /** The JSON:API write document {@link toDocument} produces. */
89
+ interface WriteDocument {
90
+ data: {
91
+ type: string;
92
+ id?: string;
93
+ attributes?: Record<string, unknown>;
94
+ relationships?: Record<string, RelationshipDocument>;
95
+ };
96
+ }
97
+ /** Options for {@link toDocument}. */
98
+ interface ToDocumentOptions {
99
+ /**
100
+ * The resource id, supplied for an UPDATE (it comes from the handle, not the input). When
101
+ * present it is always written as `data.id`. Omit for a CREATE — then `input.id` is written
102
+ * only per the type's `clientId` policy.
103
+ */
104
+ id?: string;
105
+ }
106
+ /**
107
+ * Build a JSON:API write document from FLAT input. Each input key is routed via the
108
+ * descriptor: a declared relation -> `data.relationships[name] = { data: <linkage> }`;
109
+ * anything else -> `data.attributes[name]`. Relationship linkage is coerced by cardinality:
110
+ *
111
+ * - to-one accepts an identifier `{type,id}`, a materialised resource object (its `{type,id}`
112
+ * are extracted), or `null` (-> `data: null`, clearing the relationship);
113
+ * - to-many accepts an array of those; a member may carry a `$pivot` object, rendered as the
114
+ * member identifier's `meta.pivot` (writable pivot fields).
115
+ *
116
+ * `data.type` is always the accessor `type`. `data.id` is written from `opts.id` (an update),
117
+ * else from `input.id` only when the type's `clientId` policy allows it (omitted when
118
+ * `forbidden`, passed through when `optional`/`required`).
119
+ */
120
+ declare function toDocument(descriptor: ApiDescriptor, type: string, input: Record<string, unknown>, opts?: ToDocumentOptions): WriteDocument;
121
+ /**
122
+ * Build a relationship-mutation document `{ data: <linkage> }` for the
123
+ * `/{type}/{id}/relationships/{rel}` endpoints, coercing the caller's refs by cardinality:
124
+ *
125
+ * - to-one accepts an identifier `{type,id}`, a materialised resource object, or `null`
126
+ * (-> `data: null`, clearing the relationship);
127
+ * - to-many accepts an array of those; a member may carry `$pivot`, rendered as the member
128
+ * identifier's `meta.pivot`.
129
+ *
130
+ * The same {@link coerceLinkage} the whole-resource writer uses, so a relationship written
131
+ * standalone and one embedded in a resource serialise identically.
132
+ */
133
+ declare function toRelationshipDocument(refs: unknown, cardinality: 'one' | 'many'): RelationshipDocument;
134
+ /**
135
+ * Invert a write error's `source.pointer` to the caller's FLAT input path, descriptor-aware:
136
+ *
137
+ * - `/data/attributes/title` -> `title`
138
+ * - `/data/relationships/artist/data` -> `artist`
139
+ * - `/data/id` -> `id` (client-id create conflict)
140
+ * - `/data/attributes/releaseInfo/label` -> `releaseInfo.label` (nested map)
141
+ * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
142
+ *
143
+ * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
144
+ * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
145
+ * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
146
+ *
147
+ * A query-side pointer is left untouched (those are already user-facing — see
148
+ * {@link withRemappedPaths}). An unrecognised / non-write pointer is returned verbatim.
149
+ * `/data/type` and a bare `/data` are passed through (the client owns those; the caller
150
+ * never supplies them).
151
+ */
152
+ declare function remapPointer(descriptor: ApiDescriptor, type: string, pointer: string): string;
153
+ /**
154
+ * Invert a relationship-MUTATION error's `source.pointer` to the caller's flat path, for the
155
+ * `/{type}/{id}/relationships/{rel}` endpoints. Two pointer shapes reach here:
156
+ *
157
+ * - the LINKAGE document shape (validation on the linkage members), rooted at `data` — the
158
+ * relation name is supplied by the route, not the wire:
159
+ * - `/data` -> `<rel>` (to-one clear/set)
160
+ * - `/data/meta/pivot/position` -> `<rel>.$pivot.position` (to-one pivot, rare)
161
+ * - `/data/0/meta/pivot/position` -> `<rel>[0].$pivot.position`
162
+ * - the RESOURCE-document shape that core's relationship prohibitions emit unchanged
163
+ * (`FullReplacementProhibited`/`RemovalProhibited`/`AdditionProhibited`/
164
+ * `RelationshipTypeInappropriate` all point at `/data/relationships/<name>`) — short-circuited
165
+ * to the relation name (drop the `relationships/<name>` prefix) rather than treating
166
+ * `relationships` as a linkage sub-segment.
167
+ *
168
+ * A non-`data` pointer is returned verbatim.
169
+ */
170
+ declare function remapRelationshipPointer(rel: string, hasPivot: boolean, pointer: string): string;
171
+ /**
172
+ * Return a {@link JsonApiError} with each error object's `path` populated by remapping its
173
+ * `source.pointer` (descriptor-aware) — so {@link JsonApiError.byPath} groups by the flat input
174
+ * shape. Errors with no write pointer (e.g. a `source.parameter` query-side error, or no
175
+ * source) are passed through unchanged. The original error is not mutated.
176
+ */
177
+ declare function withRemappedPaths(error: JsonApiError, descriptor: ApiDescriptor, type: string): JsonApiError;
178
+ /**
179
+ * The relationship-mutation twin of {@link withRemappedPaths}: remap each error's pointer
180
+ * keyed by the relation name from the route. Handles both the linkage-document shape (rooted
181
+ * at `data`) and the resource-document shape core's prohibition exceptions emit
182
+ * (`/data/relationships/<rel>`). `hasPivot` lets a member-level `meta` field surface as
183
+ * `$pivot`. The original error is not mutated.
184
+ */
185
+ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string, hasPivot: boolean): JsonApiError;
186
+ /**
187
+ * Invert an atomic-batch error's `source.pointer` to `(opIndex, flatPath)`: an atomic 422
188
+ * points at `/atomic:operations/{n}/data/...`, so strip the `atomic:operations/{n}` prefix to
189
+ * the op index, resolve that op's wire type (`typeForOp`), and delegate the remaining `/data`
190
+ * tail to the same {@link remapPointer} a standalone write uses (so the flat path is identical
191
+ * — `title`, `releaseInfo.label`, `artist`, …). A pointer without the atomic prefix is remapped
192
+ * verbatim under the (whole-batch) document at op index `undefined`. The original error is not
193
+ * mutated.
194
+ */
195
+ declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
196
+ //#endregion
197
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, ActionDescriptor, ActionInput, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, Cardinality, Client, ClientIdPolicy, ClientOptions, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, LinkageRef, LocalIdentifier, MaterialiseContext, MediaTypeParams, MemberName, Page, PaginatorKind, PivotInput, ReadQuery, ReadResult, RelationDescriptor, RelationMutations, RelationName, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StructuralGuardError, ToDocumentOptions, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, fetchTransport, materialise, mediaType, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
198
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/serialize-write.ts"],"mappings":";;;;UACiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,MAAA;IAAW,OAAA;IAAkB,SAAA;IAAoB,MAAA;EAAA;EACjD,IAAA,GAAO,MAAM;EADF;;;;;EAOX,IAAA;EAMA;;AAAO;AAUT;;EAVE,OAAA;AAAA;;;;;AAW2B;AAU7B;;cAXa,oBAAA,SAA6B,KAAK;cACjC,OAAA;AAAA;;;;;cAUD,YAAA,SAAqB,KAAA;EAAA,SACvB,MAAA;EAAA,SACA,MAAA,EAAQ,kBAAA;cAEL,MAAA,UAAgB,MAAA,EAAQ,kBAAA,IAAsB,OAAA;EAO1D,SAAA,CAAU,MAAA;EAIV,KAAA;EAIA,KAAA;EAIA,YAAA;EAIA,cAAA;EAIA,WAAA;EAIA,UAAA;EAIA,eAAA;EAIA,UAAA;EAIA,sBAAA;EAIA,eAAA;EAxBA;EA6BA,iBAAA;EAIA,aAAA;EArBA;;;;;EA8BA,MAAA,IAAU,MAAA,SAAe,kBAAA;AAAA;;;;;;;;UClFjB,eAAA;EACR,IAAA;EACA,EAAA;EACA,GAAA;EACA,IAAA;IAAS,KAAA,EAAO,MAAA;EAAA,IAA4B,MAAM;AAAA;;UAInC,oBAAA;EACf,IAAA,EAAM,eAAA,GAAkB,eAAe;AAAA;ADNZ;AAAA,UCUZ,aAAA;EACf,IAAA;IACE,IAAA;IACA,EAAA;IACA,UAAA,GAAa,MAAA;IACb,aAAA,GAAgB,MAAA,SAAe,oBAAA;EAAA;AAAA;;UAKlB,iBAAA;EDViB;;;;;ECgBhC,EAAE;AAAA;;;;;;;;;;;;;;;iBAiBY,UAAA,CACd,UAAA,EAAY,aAAA,EACZ,IAAA,UACA,KAAA,EAAO,MAAA,mBACP,IAAA,GAAO,iBAAA,GACN,aAAA;;;;;;AD+B0C;;;;AClGmB;;;iBAmHhD,sBAAA,CACd,IAAA,WACA,WAAA,mBACC,oBAAoB;;;;;;;;;AAlG6B;AAIpD;;;;;;;;AACyC;iBAwLzB,YAAA,CAAa,UAAA,EAAY,aAAa,EAAE,IAAA,UAAc,OAAA;;;;;;;;;;;;;;;;;AA/Kf;iBA+PvC,wBAAA,CAAyB,GAAA,UAAa,QAAA,WAAmB,OAAA;;;;AApPrE;AAiBJ;;iBAqPgB,iBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,IAAA,WACC,YAAA;;;;;;;;iBAWa,6BAAA,CACd,KAAA,EAAO,YAAA,EACP,GAAA,UACA,QAAA,YACC,YAAY;;;;;;;;AAnQC;AAgDhB;iBAgOgB,uBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}
@@ -0,0 +1,198 @@
1
+ import { $ as SortQuery, A as DefaultActionTypes, At as RelationView, B as IncludePath, Bt as AtomicDescriptor, C as fetchTransport, Ct as mediaType, D as Collection, Dt as EdgeEnvelope, E as Client, Et as Edge, F as FieldsMap, Ft as ActionDescriptor, G as ReadResult, Gt as RelationDescriptor, H as LinkageRef, Ht as ClientIdPolicy, I as FilterKey, It as ActionInput, J as RelationshipAccessor, K as RelationName, Kt as RelationMutations, L as FilterQuery, Lt as ActionOutput, M as DefaultWriteAttributes, Mt as ResourceLinks, N as EdgeMembers, Nt as materialise, O as CountToken, Ot as MaterialiseContext, P as FieldSelectionMap, Pt as relatedPaginatorKind, Q as SingleReadQuery, R as HydratedMember, Rt as ActionScope, S as TransportResponse, St as ResourceIdentifier, T as AtomicResultOf, Tt as DocumentEnvelope, U as MemberName, Ut as CountableDescriptor, V as IncludedRelations, Vt as Cardinality, W as PivotInput, Wt as PaginatorKind, X as ResourceHandle, Y as ResourceAccessors, Z as ResourceObjectView, _ as HANDLE_RESERVED, _t as ATOMIC_EXT, a as Validator, at as WriteOptions, b as JsonApiTransport, bt as LocalIdentifier, c as resolveValidator, ct as AtomicDeleteHandle, d as JsonApiContext, dt as AtomicRef, et as SortToken, f as JsonApiRequest, ft as AtomicResult, g as ClientOptions, gt as runAtomic, h as serializeQuery, ht as AtomicUpdateInput, i as ValidationOption, it as UpdateInput, j as DefaultAttributes, jt as ResourceEnvelope, k as CreateInput, kt as Page, l as validateDocument, lt as AtomicHandle, m as execute, mt as AtomicUpdateHandle, n as SchemaMap, nt as TypeName, o as WireResource, ot as AtomicCreateHandle, p as ReadQuery, pt as AtomicResults, q as RelationReadQuery, qt as ResourceDescriptor, r as ValidationConfig, rt as TypedReadQuery, s as assertJsonApiDocument, st as AtomicCreateInput, t as ResolvedValidator, tt as TypeAccessor, u as Document, ut as AtomicRecorder, v as HeadersInit, vt as ATOMIC_MEDIA_TYPE, w as ActionsAccessor, wt as ArrayEnvelope, x as TransportRequest, xt as MediaTypeParams, y as createClient, yt as JSON_API_MEDIA_TYPE, z as IdentifierMember, zt as ApiDescriptor } from "./validate-BmyPbJCK.mjs";
2
+
3
+ //#region src/errors.d.ts
4
+ /** A single JSON:API error object (spec: error objects). */
5
+ interface JsonApiErrorObject {
6
+ id?: string;
7
+ status?: string;
8
+ code?: string;
9
+ title?: string;
10
+ detail?: string;
11
+ source?: {
12
+ pointer?: string;
13
+ parameter?: string;
14
+ header?: string;
15
+ };
16
+ meta?: Record<string, unknown>;
17
+ /**
18
+ * The user-facing input path, remapped from `source.pointer` for write errors
19
+ * (e.g. `/data/attributes/title` -> `title`). Populated by the runtime, which
20
+ * built the envelope and therefore knows the inverse mapping. See CONTEXT.md.
21
+ */
22
+ path?: string;
23
+ /**
24
+ * The zero-based index of the failing operation within an atomic batch, parsed from a
25
+ * `source.pointer` carrying an `/atomic:operations/{n}` prefix. Populated only for atomic
26
+ * errors; `path` then holds the flat path within that operation's input.
27
+ */
28
+ opIndex?: number;
29
+ }
30
+ /**
31
+ * Thrown by the always-on light structural guards (ADR 0004) when a parsed response is not a
32
+ * JSON:API document, or a `data`/`included` member is not a resource object carrying `type`+`id`.
33
+ * Distinct from {@link JsonApiError} (a non-2xx server response): this signals the wire shape the
34
+ * runtime relies on was violated, not an application error the server reported. The opt-in
35
+ * per-field validator throws its engine's own error type, never this one.
36
+ */
37
+ declare class StructuralGuardError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ /**
41
+ * Thrown for any non-2xx JSON:API response. Carries the parsed error document plus
42
+ * expressive status matchers and pointer-grouping helpers.
43
+ */
44
+ declare class JsonApiError extends Error {
45
+ readonly status: number;
46
+ readonly errors: JsonApiErrorObject[];
47
+ constructor(status: number, errors: JsonApiErrorObject[], message?: string);
48
+ hasStatus(status: number): boolean;
49
+ is4xx(): boolean;
50
+ is5xx(): boolean;
51
+ isBadRequest(): boolean;
52
+ isUnauthorized(): boolean;
53
+ isForbidden(): boolean;
54
+ isNotFound(): boolean;
55
+ isNotAcceptable(): boolean;
56
+ isConflict(): boolean;
57
+ isUnsupportedMediaType(): boolean;
58
+ isUnprocessable(): boolean;
59
+ /** Alias of {@link isUnprocessable} — the JSON:API validation status. */
60
+ isValidationError(): boolean;
61
+ isRateLimited(): boolean;
62
+ /**
63
+ * Group errors by user-facing input path (falls back to the raw pointer, then the
64
+ * query parameter). The payoff for form/validation UX — 422 `source.pointer`s are
65
+ * remapped to the flat shape the caller actually supplied.
66
+ */
67
+ byPath(): Record<string, JsonApiErrorObject[]>;
68
+ }
69
+ //#endregion
70
+ //#region src/serialize-write.d.ts
71
+ /**
72
+ * A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
73
+ * batch — `{ type, lid }` (a reference to a resource created earlier in the same transaction).
74
+ * May carry writable pivot meta on a to-many member.
75
+ */
76
+ interface WriteIdentifier {
77
+ type: string;
78
+ id?: string;
79
+ lid?: string;
80
+ meta?: {
81
+ pivot: Record<string, unknown>;
82
+ } & Record<string, unknown>;
83
+ }
84
+ /** A relationship document: `{ data: <linkage> }`. */
85
+ interface RelationshipDocument {
86
+ data: WriteIdentifier | WriteIdentifier[] | null;
87
+ }
88
+ /** The JSON:API write document {@link toDocument} produces. */
89
+ interface WriteDocument {
90
+ data: {
91
+ type: string;
92
+ id?: string;
93
+ attributes?: Record<string, unknown>;
94
+ relationships?: Record<string, RelationshipDocument>;
95
+ };
96
+ }
97
+ /** Options for {@link toDocument}. */
98
+ interface ToDocumentOptions {
99
+ /**
100
+ * The resource id, supplied for an UPDATE (it comes from the handle, not the input). When
101
+ * present it is always written as `data.id`. Omit for a CREATE — then `input.id` is written
102
+ * only per the type's `clientId` policy.
103
+ */
104
+ id?: string;
105
+ }
106
+ /**
107
+ * Build a JSON:API write document from FLAT input. Each input key is routed via the
108
+ * descriptor: a declared relation -> `data.relationships[name] = { data: <linkage> }`;
109
+ * anything else -> `data.attributes[name]`. Relationship linkage is coerced by cardinality:
110
+ *
111
+ * - to-one accepts an identifier `{type,id}`, a materialised resource object (its `{type,id}`
112
+ * are extracted), or `null` (-> `data: null`, clearing the relationship);
113
+ * - to-many accepts an array of those; a member may carry a `$pivot` object, rendered as the
114
+ * member identifier's `meta.pivot` (writable pivot fields).
115
+ *
116
+ * `data.type` is always the accessor `type`. `data.id` is written from `opts.id` (an update),
117
+ * else from `input.id` only when the type's `clientId` policy allows it (omitted when
118
+ * `forbidden`, passed through when `optional`/`required`).
119
+ */
120
+ declare function toDocument(descriptor: ApiDescriptor, type: string, input: Record<string, unknown>, opts?: ToDocumentOptions): WriteDocument;
121
+ /**
122
+ * Build a relationship-mutation document `{ data: <linkage> }` for the
123
+ * `/{type}/{id}/relationships/{rel}` endpoints, coercing the caller's refs by cardinality:
124
+ *
125
+ * - to-one accepts an identifier `{type,id}`, a materialised resource object, or `null`
126
+ * (-> `data: null`, clearing the relationship);
127
+ * - to-many accepts an array of those; a member may carry `$pivot`, rendered as the member
128
+ * identifier's `meta.pivot`.
129
+ *
130
+ * The same {@link coerceLinkage} the whole-resource writer uses, so a relationship written
131
+ * standalone and one embedded in a resource serialise identically.
132
+ */
133
+ declare function toRelationshipDocument(refs: unknown, cardinality: 'one' | 'many'): RelationshipDocument;
134
+ /**
135
+ * Invert a write error's `source.pointer` to the caller's FLAT input path, descriptor-aware:
136
+ *
137
+ * - `/data/attributes/title` -> `title`
138
+ * - `/data/relationships/artist/data` -> `artist`
139
+ * - `/data/id` -> `id` (client-id create conflict)
140
+ * - `/data/attributes/releaseInfo/label` -> `releaseInfo.label` (nested map)
141
+ * - `/data/relationships/orderedTracks/data/0/meta/pivot/position` -> `orderedTracks[0].$pivot.position`
142
+ *
143
+ * Pivot values nest under a member's `meta.pivot` (symmetric with reads — see
144
+ * `JsonPointerBuilder::forLinkageMeta` / bundle ADR 0103), so a `meta/pivot/<field>` tail on
145
+ * a member of a pivot-bearing to-many is surfaced as `.$pivot.<field>`.
146
+ *
147
+ * A query-side pointer is left untouched (those are already user-facing — see
148
+ * {@link withRemappedPaths}). An unrecognised / non-write pointer is returned verbatim.
149
+ * `/data/type` and a bare `/data` are passed through (the client owns those; the caller
150
+ * never supplies them).
151
+ */
152
+ declare function remapPointer(descriptor: ApiDescriptor, type: string, pointer: string): string;
153
+ /**
154
+ * Invert a relationship-MUTATION error's `source.pointer` to the caller's flat path, for the
155
+ * `/{type}/{id}/relationships/{rel}` endpoints. Two pointer shapes reach here:
156
+ *
157
+ * - the LINKAGE document shape (validation on the linkage members), rooted at `data` — the
158
+ * relation name is supplied by the route, not the wire:
159
+ * - `/data` -> `<rel>` (to-one clear/set)
160
+ * - `/data/meta/pivot/position` -> `<rel>.$pivot.position` (to-one pivot, rare)
161
+ * - `/data/0/meta/pivot/position` -> `<rel>[0].$pivot.position`
162
+ * - the RESOURCE-document shape that core's relationship prohibitions emit unchanged
163
+ * (`FullReplacementProhibited`/`RemovalProhibited`/`AdditionProhibited`/
164
+ * `RelationshipTypeInappropriate` all point at `/data/relationships/<name>`) — short-circuited
165
+ * to the relation name (drop the `relationships/<name>` prefix) rather than treating
166
+ * `relationships` as a linkage sub-segment.
167
+ *
168
+ * A non-`data` pointer is returned verbatim.
169
+ */
170
+ declare function remapRelationshipPointer(rel: string, hasPivot: boolean, pointer: string): string;
171
+ /**
172
+ * Return a {@link JsonApiError} with each error object's `path` populated by remapping its
173
+ * `source.pointer` (descriptor-aware) — so {@link JsonApiError.byPath} groups by the flat input
174
+ * shape. Errors with no write pointer (e.g. a `source.parameter` query-side error, or no
175
+ * source) are passed through unchanged. The original error is not mutated.
176
+ */
177
+ declare function withRemappedPaths(error: JsonApiError, descriptor: ApiDescriptor, type: string): JsonApiError;
178
+ /**
179
+ * The relationship-mutation twin of {@link withRemappedPaths}: remap each error's pointer
180
+ * keyed by the relation name from the route. Handles both the linkage-document shape (rooted
181
+ * at `data`) and the resource-document shape core's prohibition exceptions emit
182
+ * (`/data/relationships/<rel>`). `hasPivot` lets a member-level `meta` field surface as
183
+ * `$pivot`. The original error is not mutated.
184
+ */
185
+ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string, hasPivot: boolean): JsonApiError;
186
+ /**
187
+ * Invert an atomic-batch error's `source.pointer` to `(opIndex, flatPath)`: an atomic 422
188
+ * points at `/atomic:operations/{n}/data/...`, so strip the `atomic:operations/{n}` prefix to
189
+ * the op index, resolve that op's wire type (`typeForOp`), and delegate the remaining `/data`
190
+ * tail to the same {@link remapPointer} a standalone write uses (so the flat path is identical
191
+ * — `title`, `releaseInfo.label`, `artist`, …). A pointer without the atomic prefix is remapped
192
+ * verbatim under the (whole-batch) document at op index `undefined`. The original error is not
193
+ * mutated.
194
+ */
195
+ declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
196
+ //#endregion
197
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, ActionDescriptor, ActionInput, ActionOutput, ActionScope, ActionsAccessor, ApiDescriptor, ArrayEnvelope, AtomicCreateHandle, AtomicCreateInput, AtomicDeleteHandle, AtomicDescriptor, AtomicHandle, AtomicRecorder, AtomicRef, AtomicResult, AtomicResultOf, AtomicResults, AtomicUpdateHandle, AtomicUpdateInput, Cardinality, Client, ClientIdPolicy, ClientOptions, Collection, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, HANDLE_RESERVED, HeadersInit, HydratedMember, IdentifierMember, IncludePath, IncludedRelations, JSON_API_MEDIA_TYPE, JsonApiContext, JsonApiError, JsonApiErrorObject, JsonApiRequest, JsonApiTransport, LinkageRef, LocalIdentifier, MaterialiseContext, MediaTypeParams, MemberName, Page, PaginatorKind, PivotInput, ReadQuery, ReadResult, RelationDescriptor, RelationMutations, RelationName, RelationReadQuery, RelationView, RelationshipAccessor, RelationshipDocument, ResolvedValidator, ResourceAccessors, ResourceDescriptor, ResourceEnvelope, ResourceHandle, ResourceIdentifier, ResourceLinks, ResourceObjectView, SchemaMap, SingleReadQuery, SortQuery, SortToken, StructuralGuardError, ToDocumentOptions, TransportRequest, TransportResponse, TypeAccessor, TypeName, TypedReadQuery, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, fetchTransport, materialise, mediaType, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
198
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/serialize-write.ts"],"mappings":";;;;UACiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,MAAA;IAAW,OAAA;IAAkB,SAAA;IAAoB,MAAA;EAAA;EACjD,IAAA,GAAO,MAAM;EADF;;;;;EAOX,IAAA;EAMA;;AAAO;AAUT;;EAVE,OAAA;AAAA;;;;;AAW2B;AAU7B;;cAXa,oBAAA,SAA6B,KAAK;cACjC,OAAA;AAAA;;;;;cAUD,YAAA,SAAqB,KAAA;EAAA,SACvB,MAAA;EAAA,SACA,MAAA,EAAQ,kBAAA;cAEL,MAAA,UAAgB,MAAA,EAAQ,kBAAA,IAAsB,OAAA;EAO1D,SAAA,CAAU,MAAA;EAIV,KAAA;EAIA,KAAA;EAIA,YAAA;EAIA,cAAA;EAIA,WAAA;EAIA,UAAA;EAIA,eAAA;EAIA,UAAA;EAIA,sBAAA;EAIA,eAAA;EAxBA;EA6BA,iBAAA;EAIA,aAAA;EArBA;;;;;EA8BA,MAAA,IAAU,MAAA,SAAe,kBAAA;AAAA;;;;;;;;UClFjB,eAAA;EACR,IAAA;EACA,EAAA;EACA,GAAA;EACA,IAAA;IAAS,KAAA,EAAO,MAAA;EAAA,IAA4B,MAAM;AAAA;;UAInC,oBAAA;EACf,IAAA,EAAM,eAAA,GAAkB,eAAe;AAAA;ADNZ;AAAA,UCUZ,aAAA;EACf,IAAA;IACE,IAAA;IACA,EAAA;IACA,UAAA,GAAa,MAAA;IACb,aAAA,GAAgB,MAAA,SAAe,oBAAA;EAAA;AAAA;;UAKlB,iBAAA;EDViB;;;;;ECgBhC,EAAE;AAAA;;;;;;;;;;;;;;;iBAiBY,UAAA,CACd,UAAA,EAAY,aAAA,EACZ,IAAA,UACA,KAAA,EAAO,MAAA,mBACP,IAAA,GAAO,iBAAA,GACN,aAAA;;;;;;AD+B0C;;;;AClGmB;;;iBAmHhD,sBAAA,CACd,IAAA,WACA,WAAA,mBACC,oBAAoB;;;;;;;;;AAlG6B;AAIpD;;;;;;;;AACyC;iBAwLzB,YAAA,CAAa,UAAA,EAAY,aAAa,EAAE,IAAA,UAAc,OAAA;;;;;;;;;;;;;;;;;AA/Kf;iBA+PvC,wBAAA,CAAyB,GAAA,UAAa,QAAA,WAAmB,OAAA;;;;AApPrE;AAiBJ;;iBAqPgB,iBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,IAAA,WACC,YAAA;;;;;;;;iBAWa,6BAAA,CACd,KAAA,EAAO,YAAA,EACP,GAAA,UACA,QAAA,YACC,YAAY;;;;;;;;AAnQC;AAgDhB;iBAgOgB,uBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}