@haddowg/json-api-client 1.13.0 → 1.15.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/dist/ajv.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Validator, n as SchemaMap } from "./validate-CTW0O49H.cjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-BbaMiYmY.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-CTW0O49H.mjs";
1
+ import { a as Validator, n as SchemaMap } from "./validate-BbaMiYmY.mjs";
2
2
  import { ValidateFunction } from "ajv";
3
3
 
4
4
  //#region src/ajv.d.ts
package/dist/index.cjs CHANGED
@@ -582,26 +582,32 @@ const isPlainObject$1 = (value) => typeof value === "object" && value !== null &
582
582
  /**
583
583
  * Append a filter value under its (already-bracketed) key. A plain object is a STRUCTURED filter
584
584
  * value — a `Range`/`DateRange` deepObject (`{ min, max }`) — and recurses into nested bracketed
585
- * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array joins with `,`;
586
- * a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
585
+ * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array goes out once per
586
+ * member as `filter[k][]=` for a filter that takes a list, so a member may hold a comma, and joins
587
+ * with `,` otherwise; a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
587
588
  * wire as `filter[k]=[object Object]` and be silently ignored by the server.
588
589
  */
589
- const appendFilterValue = (parts, key, value) => {
590
+ const appendFilterValue = (parts, key, value, list = false) => {
590
591
  if (isPlainObject$1(value)) {
591
592
  for (const [subKey, subValue] of Object.entries(value)) appendFilterValue(parts, `${key}[${subKey}]`, subValue);
592
593
  return;
593
594
  }
595
+ if (list && Array.isArray(value)) {
596
+ for (const member of value) append(parts, `${key}[]`, member);
597
+ return;
598
+ }
594
599
  append(parts, key, Array.isArray(value) ? value.join(",") : value);
595
600
  };
596
601
  /**
597
602
  * Serialise a read query to a query string (no leading `?`). Bracketed keys
598
603
  * (`filter[title]`, `page[number]`, `fields[albums]`) are kept literal; only values
599
- * are percent-encoded. Empty/undefined entries are skipped; key order is deterministic
604
+ * are percent-encoded. `isListFilter` names the filter keys that take a list, whose array value
605
+ * goes out as `filter[<key>][]` once per member. Empty/undefined entries are skipped; key order is deterministic
600
606
  * (family order, then insertion order within a family) so URLs are stable for caching.
601
607
  */
602
- function serializeQuery(query) {
608
+ function serializeQuery(query, isListFilter) {
603
609
  const parts = [];
604
- if (query.filter) for (const [key, value] of Object.entries(query.filter)) appendFilterValue(parts, `filter[${key}]`, value);
610
+ if (query.filter) for (const [key, value] of Object.entries(query.filter)) appendFilterValue(parts, `filter[${key}]`, value, isListFilter?.(key) ?? false);
605
611
  if (query.sort !== void 0) append(parts, "sort", Array.isArray(query.sort) ? query.sort.join(",") : query.sort);
606
612
  if (query.include) append(parts, "include", query.include.join(","));
607
613
  if (query.fields) for (const [type, names] of Object.entries(query.fields)) parts.push(`fields[${type}]=${encodeURIComponent(names.join(","))}`);
@@ -642,7 +648,7 @@ async function send(ctx, req, responseType) {
642
648
  sendHeaders = link.sameOrigin;
643
649
  } else url = isAbsolute(req.path) ? req.path : ctx.baseUrl + req.path;
644
650
  if (req.query) {
645
- const qs = serializeQuery(req.query);
651
+ const qs = serializeQuery(req.query, req.listFilter);
646
652
  if (qs) url += (url.includes("?") ? "&" : "?") + qs;
647
653
  }
648
654
  const negotiated = mediaType({
@@ -1053,6 +1059,32 @@ function parseResults(doc, ctx) {
1053
1059
  });
1054
1060
  }
1055
1061
  //#endregion
1062
+ //#region src/filters.ts
1063
+ /**
1064
+ * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
1065
+ * key first, then the filter family with the longest prefix whose suffix pattern accepts the rest
1066
+ * of the key. A family never matches its bare prefix. `undefined` when nothing in `spec` takes a
1067
+ * list, so every filter value is sent as before.
1068
+ */
1069
+ function listFilterMatcher(spec) {
1070
+ const lists = new Set(spec?.listFilters ?? []);
1071
+ const families = (spec?.filterFamilies ?? []).filter((family) => family.list === true);
1072
+ if (lists.size === 0 && families.length === 0) return;
1073
+ const exact = new Set(spec?.filterable ?? []);
1074
+ const byLength = [...spec?.filterFamilies ?? []].sort((a, b) => b.prefix.length - a.prefix.length);
1075
+ return (key) => {
1076
+ if (lists.has(key)) return true;
1077
+ if (exact.has(key)) return false;
1078
+ for (const family of byLength) {
1079
+ const prefix = `${family.prefix}.`;
1080
+ if (!key.startsWith(prefix)) continue;
1081
+ const suffix = key.slice(prefix.length);
1082
+ if (suffix !== "" && new RegExp(`^(?:${family.suffixPattern})$`, "u").test(suffix)) return family.list === true;
1083
+ }
1084
+ return false;
1085
+ };
1086
+ }
1087
+ //#endregion
1056
1088
  //#region src/location.ts
1057
1089
  /**
1058
1090
  * Whether a value is an {@link ActionLocation}, for an action that answers with either a resource
@@ -1159,6 +1191,8 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1159
1191
  if (query !== void 0) {
1160
1192
  const { signal, ...params } = query;
1161
1193
  req.query = params;
1194
+ const listFilter = listFilterMatcher(filterSpec(ctx, type, operation, vars["rel"]));
1195
+ if (listFilter !== void 0) req.listFilter = listFilter;
1162
1196
  if (signal !== void 0) req.signal = signal;
1163
1197
  negotiateProfiles(ctx, type, params, req, relationForCount);
1164
1198
  }
@@ -1170,6 +1204,15 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1170
1204
  return doc === void 0 ? void 0 : materialise(doc, ctx.materialise, linkage, primaryType, paginatorOverride);
1171
1205
  }
1172
1206
  /**
1207
+ * The filter vocabulary a read's `filter` is matched against: the type's for its collection read,
1208
+ * and the related type's for a related or relationship read of a relation with one related type.
1209
+ */
1210
+ function filterSpec(ctx, type, operation, rel) {
1211
+ if (operation === "fetchMany") return ctx.descriptor[type];
1212
+ const types = rel === void 0 ? void 0 : ctx.descriptor[type]?.relations[rel]?.types;
1213
+ return types?.length === 1 ? ctx.descriptor[types[0]] : void 0;
1214
+ }
1215
+ /**
1173
1216
  * Add any profiles a query's parameters require to the request's negotiated `profiles`. A
1174
1217
  * `withCount` read needs the type's Countable profile in `Accept` — else the server rejects it
1175
1218
  * (400) under strict query-param validation. The profile URI is read from the descriptor's
@@ -1237,7 +1280,8 @@ async function runWrite(ctx, spec) {
1237
1280
  * `204` / no body). An action declaring a `location` returns the URL of a location document as an
1238
1281
  * `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
1239
1282
  * the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
1240
- * `ArrayBuffer`, or parsed JSON by the media type's kind.
1283
+ * `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
1284
+ * sends `options.filter` in the query string as a collection read does.
1241
1285
  */
1242
1286
  async function runAction(ctx, action, vars, input, options = {}) {
1243
1287
  const req = {
@@ -1245,6 +1289,11 @@ async function runAction(ctx, action, vars, input, options = {}) {
1245
1289
  path: fill(action.path, vars)
1246
1290
  };
1247
1291
  if (options.signal !== void 0) req.signal = options.signal;
1292
+ if (options.filter !== void 0) {
1293
+ req.query = { filter: options.filter };
1294
+ const listFilter = listFilterMatcher(action);
1295
+ if (listFilter !== void 0) req.listFilter = listFilter;
1296
+ }
1248
1297
  let remap;
1249
1298
  const media = requestMedia(action, options.contentType);
1250
1299
  if (media !== void 0 && media.kind !== "document") {
@@ -1574,6 +1623,7 @@ exports.findError = findError;
1574
1623
  exports.hasErrorCode = hasErrorCode;
1575
1624
  exports.isActionLocation = isActionLocation;
1576
1625
  exports.isPolymorphic = isPolymorphic;
1626
+ exports.listFilterMatcher = listFilterMatcher;
1577
1627
  exports.materialise = materialise;
1578
1628
  exports.mediaType = mediaType;
1579
1629
  exports.readActionLocation = readActionLocation;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as OperationExamples, At as AtomicRef, B as ErrorCodeOf, Bn as ResourceDescriptor, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMediaKind, Dt as AtomicDeleteHandle, E as fetchTransport, En as InputMedia, Et as AtomicCreateInput, F as CreateInput, Fn as PivotDescriptor, Ft as runAtomic, G as HydratedMember, Gt as Edge, H as FieldsMap, Hn as SortFamilyDescriptor, Ht as mediaType, I as DefaultActionTypes, In as RawMediaKind, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawOutputMedia, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorKind, Mt as AtomicResults, N as Collection, Nn as PaginatorRole, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as MediaExamples, Ot as AtomicHandle, P as CountToken, Pn as PaginatorStrategy, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RelationDescriptor, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as StrategyDescriptor, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceExamples, Vt as ResourceIdentifier, W as FilterQuery, Wn as isPolymorphic, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as PaginatorDescriptor, jt as AtomicResult, k as AtomicResultOf, kn as MenuDescriptor, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationMutations, zt as LocalIdentifier } from "./validate-CTW0O49H.cjs";
1
+ import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as MenuDescriptor, At as AtomicRef, B as ErrorCodeOf, Bn as RelationMutations, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMedia, Dt as AtomicDeleteHandle, E as fetchTransport, En as FilterFamilyDescriptor, Et as AtomicCreateInput, F as CreateInput, Fn as PaginatorStrategy, Ft as runAtomic, G as HydratedMember, Gn as isPolymorphic, Gt as Edge, H as FieldsMap, Hn as ResourceExamples, Ht as mediaType, I as DefaultActionTypes, In as PivotDescriptor, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawMediaKind, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorDescriptor, Mt as AtomicResults, N as Collection, Nn as PaginatorKind, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as InputMediaKind, Ot as AtomicHandle, P as CountToken, Pn as PaginatorRole, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RawOutputMedia, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as SortFamilyDescriptor, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceDescriptor, Vt as ResourceIdentifier, W as FilterQuery, Wn as StrategyDescriptor, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as OperationExamples, jt as AtomicResult, k as AtomicResultOf, kn as MediaExamples, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationDescriptor, zt as LocalIdentifier } from "./validate-BbaMiYmY.cjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -111,6 +111,21 @@ declare function findError(err: unknown, code: string): JsonApiErrorObject | und
111
111
  */
112
112
  type ErrorFinder<C extends string, M = {}> = <K extends C>(err: unknown, code: K) => CodedErrorObject<K, M> | undefined;
113
113
  //#endregion
114
+ //#region src/filters.d.ts
115
+ /** The filter vocabulary {@link listFilterMatcher} reads: a type's, or a collection action's. */
116
+ interface FilterSpec {
117
+ filterable?: readonly string[];
118
+ listFilters?: readonly string[];
119
+ filterFamilies?: readonly FilterFamilyDescriptor[];
120
+ }
121
+ /**
122
+ * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
123
+ * key first, then the filter family with the longest prefix whose suffix pattern accepts the rest
124
+ * of the key. A family never matches its bare prefix. `undefined` when nothing in `spec` takes a
125
+ * list, so every filter value is sent as before.
126
+ */
127
+ declare function listFilterMatcher(spec: FilterSpec | undefined): ((key: string) => boolean) | undefined;
128
+ //#endregion
114
129
  //#region src/serialize-write.d.ts
115
130
  /**
116
131
  * A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
@@ -238,5 +253,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
238
253
  */
239
254
  declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
240
255
  //#endregion
241
- export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, 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, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, 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, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
256
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, 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, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, 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, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
242
257
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/serialize-write.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA,GAAO,CAAA;EACP,KAAA;EACA,MAAA;EACA,MAAA;IAAW,OAAA;IAAkB,SAAA;IAAoB,MAAA;EAAA;EACjD,IAAA,GAAO,MAAM;EAAN;;;;AAYA;EANP,IAAA;EAgBgC;;;;;EAVhC,OAAA;AAAA;AAW2B;AAa7B;;;;;;AAb6B,cADhB,oBAAA,SAA6B,KAAK;cACjC,OAAA;AAAA;;;;;;;;cAaD,YAAA,oCAAgD,KAAA;EAAA,SAClD,MAAA;EAAA,SACA,MAAA,EAAQ,kBA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AA,EAAY,aAAA,EACZ,IAAA,UACA,KAAA,EAAO,MAAA,mBACP,IAAA,GAAO,iBAAA,GACN,aAAA;;;;;;;;;;;;;iBAgDa,sBAAA,CACd,IAAA,WACA,WAAA,mBACC,oBAAoB;;AFXwB;AAgB/C;;;;;;;;;AAA6E;AAS7E;;;;;;iBE6EgB,YAAA,CAAa,UAAA,EAAY,aAAa,EAAE,IAAA,UAAc,OAAA;;;;;;;;;;AF7EyB;AAO/F;;;;;;;iBEsJgB,wBAAA,CAAyB,GAAA,UAAa,QAAA,WAAmB,OAAA;;;;;;;iBAkBzD,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;;AFzLqB;AAOpC;;;;;;;iBE+LgB,uBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as OperationExamples, At as AtomicRef, B as ErrorCodeOf, Bn as ResourceDescriptor, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMediaKind, Dt as AtomicDeleteHandle, E as fetchTransport, En as InputMedia, Et as AtomicCreateInput, F as CreateInput, Fn as PivotDescriptor, Ft as runAtomic, G as HydratedMember, Gt as Edge, H as FieldsMap, Hn as SortFamilyDescriptor, Ht as mediaType, I as DefaultActionTypes, In as RawMediaKind, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawOutputMedia, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorKind, Mt as AtomicResults, N as Collection, Nn as PaginatorRole, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as MediaExamples, Ot as AtomicHandle, P as CountToken, Pn as PaginatorStrategy, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RelationDescriptor, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as StrategyDescriptor, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceExamples, Vt as ResourceIdentifier, W as FilterQuery, Wn as isPolymorphic, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as PaginatorDescriptor, jt as AtomicResult, k as AtomicResultOf, kn as MenuDescriptor, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationMutations, zt as LocalIdentifier } from "./validate-CTW0O49H.mjs";
1
+ import { $ as MemberName, $t as ResourceLinks, A as BinaryBody, An as MenuDescriptor, At as AtomicRef, B as ErrorCodeOf, Bn as RelationMutations, Bt as MediaTypeParams, C as TransportRawBody, Cn as Cardinality, Ct as isActionLocation, D as ActionCallOptions, Dn as InputMedia, Dt as AtomicDeleteHandle, E as fetchTransport, En as FilterFamilyDescriptor, Et as AtomicCreateInput, F as CreateInput, Fn as PaginatorStrategy, Ft as runAtomic, G as HydratedMember, Gn as isPolymorphic, Gt as Edge, H as FieldsMap, Hn as ResourceExamples, Ht as mediaType, I as DefaultActionTypes, In as PivotDescriptor, It as ATOMIC_EXT, J as IncludedRelations, Jt as LinkObject, K as IdentifierMember, Kt as EdgeEnvelope, L as DefaultAttributes, Ln as RawMediaKind, Lt as ATOMIC_MEDIA_TYPE, M as Client, Mn as PaginatorDescriptor, Mt as AtomicResults, N as Collection, Nn as PaginatorKind, Nt as AtomicUpdateHandle, O as ActionsAccessor, On as InputMediaKind, Ot as AtomicHandle, P as CountToken, Pn as PaginatorRole, Pt as AtomicUpdateInput, Q as ListPageParams, Qt as ResourceEnvelope, R as DefaultWriteAttributes, Rn as RawOutputMedia, Rt as JSON_API_MEDIA_TYPE, S as JsonApiTransport, Sn as AtomicDescriptor, St as ActionLocation, T as TransportResponse, Tn as CountableDescriptor, Tt as AtomicCreateHandle, U as FilterKey, Un as SortFamilyDescriptor, Ut as ArrayEnvelope, V as FieldSelectionMap, Vn as ResourceDescriptor, Vt as ResourceIdentifier, W as FilterQuery, Wn as StrategyDescriptor, Wt as DocumentEnvelope, X as IncludedType, Xt as NavigateOptions, Y as IncludedResource, Yt as MaterialiseContext, Z as LinkageRef, Zt as RelationView, _ as serializeQuery, _n as ActionLocationDescriptor, _t as TypeName, a as Validator, an as Page, at as RelationName, b as HeadersInit, bn as ApiDescriptor, bt as WithLinks, c as resolveValidator, cn as PageMeta, ct as RelationReadQuery, d as JsonApiContext, dn as PageParamsOf, dt as ResourceHandle, en as materialise, et as PivotInput, f as JsonApiRequest, fn as ResolvedPaginator, ft as ResourceObjectView, g as executeRaw, gn as ActionInput, gt as TypeAccessor, h as execute, hn as ActionDescriptor, ht as SortToken, i as ValidationOption, in as ExactPageParams, it as RelatedIncludedType, j as BinaryResponseType, jn as OperationExamples, jt as AtomicResult, k as AtomicResultOf, kn as MediaExamples, kt as AtomicRecorder, l as validateDocument, ln as PageOf, lt as RelationshipAccessor, m as ReadQuery, mn as resolvePaginator, mt as SortQuery, n as SchemaMap, nn as relatedPaginatorKind, nt as ReadableRelationName, o as WireResource, on as PageKeys, ot as RelationPageParams, p as RawResponseType, pn as TypedPage, pt as SingleReadQuery, q as IncludePath, qt as Link, r as ValidationConfig, rn as CANONICAL_PAGE_KEYS, rt as RelatedIncludedResource, s as assertJsonApiDocument, sn as PageLinks, st as RelationPaginator, t as ResolvedValidator, tn as relatedPaginator, tt as ReadResult, u as Document, un as PageParams, ut as ResourceAccessors, v as ClientOptions, vn as ActionOutput, vt as TypedReadQuery, w as TransportRequest, wn as ClientIdPolicy, wt as readActionLocation, x as createClient, xn as ApiExamples, xt as WriteOptions, y as HANDLE_RESERVED, yn as ActionScope, yt as UpdateInput, z as EdgeMembers, zn as RelationDescriptor, zt as LocalIdentifier } from "./validate-BbaMiYmY.mjs";
2
2
 
3
3
  //#region src/errors.d.ts
4
4
  /**
@@ -111,6 +111,21 @@ declare function findError(err: unknown, code: string): JsonApiErrorObject | und
111
111
  */
112
112
  type ErrorFinder<C extends string, M = {}> = <K extends C>(err: unknown, code: K) => CodedErrorObject<K, M> | undefined;
113
113
  //#endregion
114
+ //#region src/filters.d.ts
115
+ /** The filter vocabulary {@link listFilterMatcher} reads: a type's, or a collection action's. */
116
+ interface FilterSpec {
117
+ filterable?: readonly string[];
118
+ listFilters?: readonly string[];
119
+ filterFamilies?: readonly FilterFamilyDescriptor[];
120
+ }
121
+ /**
122
+ * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
123
+ * key first, then the filter family with the longest prefix whose suffix pattern accepts the rest
124
+ * of the key. A family never matches its bare prefix. `undefined` when nothing in `spec` takes a
125
+ * list, so every filter value is sent as before.
126
+ */
127
+ declare function listFilterMatcher(spec: FilterSpec | undefined): ((key: string) => boolean) | undefined;
128
+ //#endregion
114
129
  //#region src/serialize-write.d.ts
115
130
  /**
116
131
  * A JSON:API resource identifier in a write document: `{ type, id }` or — inside an atomic
@@ -238,5 +253,5 @@ declare function withRemappedRelationshipPaths(error: JsonApiError, rel: string,
238
253
  */
239
254
  declare function withRemappedAtomicPaths(error: JsonApiError, descriptor: ApiDescriptor, typeForOp: (opIndex: number) => string | undefined): JsonApiError;
240
255
  //#endregion
241
- export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, FieldSelectionMap, FieldsMap, FilterKey, FilterQuery, 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, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, 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, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
256
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, 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, CountToken, CountableDescriptor, CreateInput, DefaultActionTypes, DefaultAttributes, DefaultWriteAttributes, Document, DocumentEnvelope, Edge, EdgeEnvelope, EdgeMembers, ErrorCodeGuard, ErrorCodeOf, ErrorFinder, ExactPageParams, 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, MaterialiseContext, MediaExamples, MediaTypeParams, MemberName, MenuDescriptor, NavigateOptions, OperationExamples, Page, PageKeys, PageLinks, PageMeta, PageOf, PageParams, PageParamsOf, PaginatorDescriptor, PaginatorKind, PaginatorRole, PaginatorStrategy, PivotDescriptor, PivotInput, RawMediaKind, RawOutputMedia, RawResponseType, ReadQuery, ReadResult, ReadableRelationName, RelatedIncludedResource, RelatedIncludedType, RelationDescriptor, RelationMutations, RelationName, RelationPageParams, RelationPaginator, RelationReadQuery, 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, UpdateInput, ValidationConfig, ValidationOption, Validator, WireResource, WithLinks, WriteDocument, WriteOptions, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
242
257
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/serialize-write.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,kBAAA;EACf,EAAA;EACA,MAAA;EACA,IAAA,GAAO,CAAA;EACP,KAAA;EACA,MAAA;EACA,MAAA;IAAW,OAAA;IAAkB,SAAA;IAAoB,MAAA;EAAA;EACjD,IAAA,GAAO,MAAM;EAAN;;;;AAYA;EANP,IAAA;EAgBgC;;;;;EAVhC,OAAA;AAAA;AAW2B;AAa7B;;;;;;AAb6B,cADhB,oBAAA,SAA6B,KAAK;cACjC,OAAA;AAAA;;;;;;;;cAaD,YAAA,oCAAgD,KAAA;EAAA,SAClD,MAAA;EAAA,SACA,MAAA,EAAQ,kBAAA,CAAmB,CAAA;cAExB,MAAA,UAAgB,MAAA,EAAQ,kBAAA,CAAmB,CAAA,KAAM,OAAA;EAO7D,SAAA,CAAU,MAAA;EAIV,KAAA;EAIA,KAAA;EAIA,YAAA;EAIA,cAAA;EAIA,WAAA;EAIA,UAAA;EAIA,eAAA;EAIA,UAAA;EAIA,sBAAA;EAIA,eAAA;EApBA;EAyBA,iBAAA;EAIA,aAAA;EAjBA;;;;;EA0BA,MAAA,IAAU,MAAA,SAAe,kBAAA,CAAmB,CAAA;AAAA;;;;AAAC;AAgB/C;;iBAAgB,YAAA,CAAa,GAAA,WAAc,IAAA,WAAe,GAAA,IAAO,YAAY;;;;;;KASjE,cAAA,sBAAoC,GAAA,WAAc,IAAA,EAAM,CAAA,KAAM,GAAA,IAAO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AAA,EACP,GAAA,UACA,QAAA,YACC,YAAY;;AFzLqB;AAOpC;;;;;;;iBE+LgB,uBAAA,CACd,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,aAAA,EACZ,SAAA,GAAY,OAAA,kCACX,YAAA"}
package/dist/index.mjs CHANGED
@@ -581,26 +581,32 @@ const isPlainObject$1 = (value) => typeof value === "object" && value !== null &
581
581
  /**
582
582
  * Append a filter value under its (already-bracketed) key. A plain object is a STRUCTURED filter
583
583
  * value — a `Range`/`DateRange` deepObject (`{ min, max }`) — and recurses into nested bracketed
584
- * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array joins with `,`;
585
- * a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
584
+ * keys (`filter[k][min]=`), matching the server's deepObject wire shape; an array goes out once per
585
+ * member as `filter[k][]=` for a filter that takes a list, so a member may hold a comma, and joins
586
+ * with `,` otherwise; a scalar is appended directly. Without the object branch a `{ min, max }` value would reach the
586
587
  * wire as `filter[k]=[object Object]` and be silently ignored by the server.
587
588
  */
588
- const appendFilterValue = (parts, key, value) => {
589
+ const appendFilterValue = (parts, key, value, list = false) => {
589
590
  if (isPlainObject$1(value)) {
590
591
  for (const [subKey, subValue] of Object.entries(value)) appendFilterValue(parts, `${key}[${subKey}]`, subValue);
591
592
  return;
592
593
  }
594
+ if (list && Array.isArray(value)) {
595
+ for (const member of value) append(parts, `${key}[]`, member);
596
+ return;
597
+ }
593
598
  append(parts, key, Array.isArray(value) ? value.join(",") : value);
594
599
  };
595
600
  /**
596
601
  * Serialise a read query to a query string (no leading `?`). Bracketed keys
597
602
  * (`filter[title]`, `page[number]`, `fields[albums]`) are kept literal; only values
598
- * are percent-encoded. Empty/undefined entries are skipped; key order is deterministic
603
+ * are percent-encoded. `isListFilter` names the filter keys that take a list, whose array value
604
+ * goes out as `filter[<key>][]` once per member. Empty/undefined entries are skipped; key order is deterministic
599
605
  * (family order, then insertion order within a family) so URLs are stable for caching.
600
606
  */
601
- function serializeQuery(query) {
607
+ function serializeQuery(query, isListFilter) {
602
608
  const parts = [];
603
- if (query.filter) for (const [key, value] of Object.entries(query.filter)) appendFilterValue(parts, `filter[${key}]`, value);
609
+ if (query.filter) for (const [key, value] of Object.entries(query.filter)) appendFilterValue(parts, `filter[${key}]`, value, isListFilter?.(key) ?? false);
604
610
  if (query.sort !== void 0) append(parts, "sort", Array.isArray(query.sort) ? query.sort.join(",") : query.sort);
605
611
  if (query.include) append(parts, "include", query.include.join(","));
606
612
  if (query.fields) for (const [type, names] of Object.entries(query.fields)) parts.push(`fields[${type}]=${encodeURIComponent(names.join(","))}`);
@@ -641,7 +647,7 @@ async function send(ctx, req, responseType) {
641
647
  sendHeaders = link.sameOrigin;
642
648
  } else url = isAbsolute(req.path) ? req.path : ctx.baseUrl + req.path;
643
649
  if (req.query) {
644
- const qs = serializeQuery(req.query);
650
+ const qs = serializeQuery(req.query, req.listFilter);
645
651
  if (qs) url += (url.includes("?") ? "&" : "?") + qs;
646
652
  }
647
653
  const negotiated = mediaType({
@@ -1052,6 +1058,32 @@ function parseResults(doc, ctx) {
1052
1058
  });
1053
1059
  }
1054
1060
  //#endregion
1061
+ //#region src/filters.ts
1062
+ /**
1063
+ * Whether a `filter[...]` key takes a list, by the rule the server matches keys with: an exact
1064
+ * key first, then the filter family with the longest prefix whose suffix pattern accepts the rest
1065
+ * of the key. A family never matches its bare prefix. `undefined` when nothing in `spec` takes a
1066
+ * list, so every filter value is sent as before.
1067
+ */
1068
+ function listFilterMatcher(spec) {
1069
+ const lists = new Set(spec?.listFilters ?? []);
1070
+ const families = (spec?.filterFamilies ?? []).filter((family) => family.list === true);
1071
+ if (lists.size === 0 && families.length === 0) return;
1072
+ const exact = new Set(spec?.filterable ?? []);
1073
+ const byLength = [...spec?.filterFamilies ?? []].sort((a, b) => b.prefix.length - a.prefix.length);
1074
+ return (key) => {
1075
+ if (lists.has(key)) return true;
1076
+ if (exact.has(key)) return false;
1077
+ for (const family of byLength) {
1078
+ const prefix = `${family.prefix}.`;
1079
+ if (!key.startsWith(prefix)) continue;
1080
+ const suffix = key.slice(prefix.length);
1081
+ if (suffix !== "" && new RegExp(`^(?:${family.suffixPattern})$`, "u").test(suffix)) return family.list === true;
1082
+ }
1083
+ return false;
1084
+ };
1085
+ }
1086
+ //#endregion
1055
1087
  //#region src/location.ts
1056
1088
  /**
1057
1089
  * Whether a value is an {@link ActionLocation}, for an action that answers with either a resource
@@ -1158,6 +1190,8 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1158
1190
  if (query !== void 0) {
1159
1191
  const { signal, ...params } = query;
1160
1192
  req.query = params;
1193
+ const listFilter = listFilterMatcher(filterSpec(ctx, type, operation, vars["rel"]));
1194
+ if (listFilter !== void 0) req.listFilter = listFilter;
1161
1195
  if (signal !== void 0) req.signal = signal;
1162
1196
  negotiateProfiles(ctx, type, params, req, relationForCount);
1163
1197
  }
@@ -1169,6 +1203,15 @@ async function run(ctx, type, operation, vars, query, linkage = false, relationF
1169
1203
  return doc === void 0 ? void 0 : materialise(doc, ctx.materialise, linkage, primaryType, paginatorOverride);
1170
1204
  }
1171
1205
  /**
1206
+ * The filter vocabulary a read's `filter` is matched against: the type's for its collection read,
1207
+ * and the related type's for a related or relationship read of a relation with one related type.
1208
+ */
1209
+ function filterSpec(ctx, type, operation, rel) {
1210
+ if (operation === "fetchMany") return ctx.descriptor[type];
1211
+ const types = rel === void 0 ? void 0 : ctx.descriptor[type]?.relations[rel]?.types;
1212
+ return types?.length === 1 ? ctx.descriptor[types[0]] : void 0;
1213
+ }
1214
+ /**
1172
1215
  * Add any profiles a query's parameters require to the request's negotiated `profiles`. A
1173
1216
  * `withCount` read needs the type's Countable profile in `Accept` — else the server rejects it
1174
1217
  * (400) under strict query-param validation. The profile URI is read from the descriptor's
@@ -1236,7 +1279,8 @@ async function runWrite(ctx, spec) {
1236
1279
  * `204` / no body). An action declaring a `location` returns the URL of a location document as an
1237
1280
  * `ActionLocation` and never follows it. An action declaring `rawOutput` answers in the media type
1238
1281
  * the caller picks with `options.accept`: JSON:API as above, or a `string`, a `Blob` or
1239
- * `ArrayBuffer`, or parsed JSON by the media type's kind.
1282
+ * `ArrayBuffer`, or parsed JSON by the media type's kind. A collection action that takes filters
1283
+ * sends `options.filter` in the query string as a collection read does.
1240
1284
  */
1241
1285
  async function runAction(ctx, action, vars, input, options = {}) {
1242
1286
  const req = {
@@ -1244,6 +1288,11 @@ async function runAction(ctx, action, vars, input, options = {}) {
1244
1288
  path: fill(action.path, vars)
1245
1289
  };
1246
1290
  if (options.signal !== void 0) req.signal = options.signal;
1291
+ if (options.filter !== void 0) {
1292
+ req.query = { filter: options.filter };
1293
+ const listFilter = listFilterMatcher(action);
1294
+ if (listFilter !== void 0) req.listFilter = listFilter;
1295
+ }
1247
1296
  let remap;
1248
1297
  const media = requestMedia(action, options.contentType);
1249
1298
  if (media !== void 0 && media.kind !== "document") {
@@ -1557,6 +1606,6 @@ function isPolymorphic(relation) {
1557
1606
  return relation.polymorphic ?? relation.types.length > 1;
1558
1607
  }
1559
1608
  //#endregion
1560
- export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, StructuralGuardError, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
1609
+ export { ATOMIC_EXT, ATOMIC_MEDIA_TYPE, CANONICAL_PAGE_KEYS, HANDLE_RESERVED, JSON_API_MEDIA_TYPE, JsonApiError, StructuralGuardError, assertJsonApiDocument, createClient, execute, executeRaw, fetchTransport, findError, hasErrorCode, isActionLocation, isPolymorphic, listFilterMatcher, materialise, mediaType, readActionLocation, relatedPaginator, relatedPaginatorKind, remapPointer, remapRelationshipPointer, resolvePaginator, resolveValidator, runAtomic, serializeQuery, toDocument, toRelationshipDocument, validateDocument, withRemappedAtomicPaths, withRemappedPaths, withRemappedRelationshipPaths };
1561
1610
 
1562
1611
  //# sourceMappingURL=index.mjs.map