@haddowg/json-api-client 1.19.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 +3 -2
- package/dist/ajv.d.cts +1 -1
- package/dist/ajv.d.mts +1 -1
- package/dist/index.cjs +25 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +25 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{validate-COy9e4mh.d.cts → validate-DGoH9XA9.d.cts} +79 -34
- package/dist/validate-DGoH9XA9.d.cts.map +1 -0
- package/dist/{validate-COy9e4mh.d.mts → validate-DGoH9XA9.d.mts} +79 -34
- package/dist/validate-DGoH9XA9.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/validate-COy9e4mh.d.cts.map +0 -1
- package/dist/validate-COy9e4mh.d.mts.map +0 -1
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
|
|
124
|
-
|
|
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
package/dist/ajv.d.mts
CHANGED
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;
|
|
@@ -1346,8 +1346,8 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
|
|
|
1346
1346
|
}
|
|
1347
1347
|
/**
|
|
1348
1348
|
* The filter vocabulary a read's `filter` is matched against: the type's for its collection read.
|
|
1349
|
-
* A related or relationship read takes the relation's own when its descriptor declares one,
|
|
1350
|
-
* the related type's when the relation has one related type.
|
|
1349
|
+
* A related or relationship read takes the relation's own when its descriptor declares one, even an
|
|
1350
|
+
* empty one, else the related type's when the relation has one related type.
|
|
1351
1351
|
*/
|
|
1352
1352
|
function filterSpec(ctx, type, operation, rel) {
|
|
1353
1353
|
if (operation === "fetchMany") return ctx.descriptor[type];
|
|
@@ -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
|
|
1389
|
-
* (400) under strict query-param validation. The profile URI is read from the descriptor
|
|
1390
|
-
* `countable`
|
|
1391
|
-
* `
|
|
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
|
|
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
|
-
/**
|
|
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)
|
|
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
|
|
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
|
|
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;
|
|
@@ -1345,8 +1345,8 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
|
|
|
1345
1345
|
}
|
|
1346
1346
|
/**
|
|
1347
1347
|
* The filter vocabulary a read's `filter` is matched against: the type's for its collection read.
|
|
1348
|
-
* A related or relationship read takes the relation's own when its descriptor declares one,
|
|
1349
|
-
* the related type's when the relation has one related type.
|
|
1348
|
+
* A related or relationship read takes the relation's own when its descriptor declares one, even an
|
|
1349
|
+
* empty one, else the related type's when the relation has one related type.
|
|
1350
1350
|
*/
|
|
1351
1351
|
function filterSpec(ctx, type, operation, rel) {
|
|
1352
1352
|
if (operation === "fetchMany") return ctx.descriptor[type];
|
|
@@ -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
|
|
1388
|
-
* (400) under strict query-param validation. The profile URI is read from the descriptor
|
|
1389
|
-
* `countable`
|
|
1390
|
-
* `
|
|
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
|
|
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
|
-
/**
|
|
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)
|
|
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 {
|