@entifix/next-shell 0.21.0 → 0.22.1

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.
Files changed (37) hide show
  1. package/README.md +3 -1
  2. package/dist/lib/command-palette/use-records-source.d.ts.map +1 -1
  3. package/dist/lib/command-palette/use-records-source.js +13 -3
  4. package/dist/lib/command-palette/use-records-source.js.map +1 -1
  5. package/dist/lib/crud/index.d.ts +1 -0
  6. package/dist/lib/crud/index.d.ts.map +1 -1
  7. package/dist/lib/crud/index.js +1 -0
  8. package/dist/lib/crud/index.js.map +1 -1
  9. package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
  10. package/dist/lib/crud/make-entity-crud.js +39 -7
  11. package/dist/lib/crud/make-entity-crud.js.map +1 -1
  12. package/dist/lib/crud/make-entity-crud.types.d.ts +43 -1
  13. package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
  14. package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
  15. package/dist/lib/crud/use-entity-link-sources.d.ts.map +1 -1
  16. package/dist/lib/crud/use-entity-link-sources.js +5 -1
  17. package/dist/lib/crud/use-entity-link-sources.js.map +1 -1
  18. package/dist/lib/crud/use-entity-total.d.ts +27 -0
  19. package/dist/lib/crud/use-entity-total.d.ts.map +1 -0
  20. package/dist/lib/crud/use-entity-total.js +39 -0
  21. package/dist/lib/crud/use-entity-total.js.map +1 -0
  22. package/dist/lib/search/record-search-route.d.ts +2 -0
  23. package/dist/lib/search/record-search-route.d.ts.map +1 -1
  24. package/dist/lib/search/record-search-route.js +83 -21
  25. package/dist/lib/search/record-search-route.js.map +1 -1
  26. package/dist/lib/search/record-search-source.d.ts +61 -9
  27. package/dist/lib/search/record-search-source.d.ts.map +1 -1
  28. package/dist/lib/search/record-search-source.js +162 -58
  29. package/dist/lib/search/record-search-source.js.map +1 -1
  30. package/dist/lib/search/record-search.types.d.ts +10 -3
  31. package/dist/lib/search/record-search.types.d.ts.map +1 -1
  32. package/dist/lib/search/record-search.types.js.map +1 -1
  33. package/dist/lib/search/search-records.d.ts +3 -1
  34. package/dist/lib/search/search-records.d.ts.map +1 -1
  35. package/dist/lib/search/search-records.js +2 -1
  36. package/dist/lib/search/search-records.js.map +1 -1
  37. package/package.json +9 -9
@@ -1,4 +1,4 @@
1
- import { type Entity, type EntityConstructor } from '@entifix/core';
1
+ import { type Entity, type EntityConstructor, type Locale } from '@entifix/core';
2
2
  import type { RecordSearchOption } from './record-search.types.js';
3
3
  /**
4
4
  * What a host declares in order to make one entity searchable from the palette.
@@ -16,29 +16,81 @@ export interface RecordSearchSourceConfig<TEntity extends Entity> {
16
16
  readonly entityConstructor: EntityConstructor<TEntity>;
17
17
  /** Where the owning service listens, **without** the `/api` suffix. */
18
18
  readonly baseUrl: string;
19
- /** The `filterable` string member a term is matched against with `like`. */
19
+ /**
20
+ * The `filterable` member a term is matched against: a string or localized
21
+ * member, matched with `like` — or, with {@link reference}, the member that
22
+ * holds the referenced record's id, matched with `=in=`.
23
+ */
20
24
  readonly searchProperty: string;
21
- /** The `sortable` member read as a record's label. */
22
- readonly labelProperty: string;
25
+ /**
26
+ * The `sortable` member read as a record's label. Omitted, the record names
27
+ * itself as every other surface names it — its `labelMember`, else the
28
+ * first member that can name it — and one nothing names is sent `unnamed`,
29
+ * by its short id; the group is then sorted by {@link searchProperty}, which
30
+ * must be `sortable`. Never given with {@link reference}, which labels.
31
+ */
32
+ readonly labelProperty?: string;
23
33
  /** An optional secondary line — a code, a role. */
24
34
  readonly sublabelProperty?: string;
25
35
  /** The group heading, as the entity's own `pluralKey`. */
26
36
  readonly labelKey: string;
27
37
  /** Where selecting a record lands. Locale-free; the caller prefixes it. */
28
38
  readonly href: (id: string) => string;
39
+ /**
40
+ * Search through the record {@link searchProperty} refers to, when that is
41
+ * what a person knows the record by: a stock item by its product's name.
42
+ * The term is matched against the referenced entity's label at its owner,
43
+ * and the records referring to the matches are read and labelled with
44
+ * their names.
45
+ */
46
+ readonly reference?: RecordSearchReference;
47
+ }
48
+ /** The entity a source is searched through, and where its owner listens. */
49
+ export interface RecordSearchReference {
50
+ readonly entityConstructor: EntityConstructor<any>;
51
+ /** Where the target's owning service listens, **without** the `/api` suffix. */
52
+ readonly baseUrl: string;
53
+ /**
54
+ * The target member the term is matched against and the records are
55
+ * labelled by — a filterable, sortable string or localized member. Defaults
56
+ * to the target's declared `labelMember`.
57
+ */
58
+ readonly labelProperty?: string;
59
+ }
60
+ /** One referenced record a term matched: its id, and what it is called. */
61
+ export interface RecordSearchMatch {
62
+ readonly id: string;
63
+ readonly label: string;
29
64
  }
30
65
  /** A declared source, reduced to what the fan-out actually calls. */
31
66
  export interface RecordSearchSource {
32
67
  readonly key: string;
33
68
  readonly entity: string;
34
69
  readonly labelKey: string;
35
- /** The upstream URL for one term. */
36
- readonly url: (term: string, limit: number) => string;
37
- /** `undefined` when the body is not a readable `entityPage` envelope. */
38
- readonly read: (body: unknown) => {
70
+ /**
71
+ * The upstream URL for one term, in the reader's locale — which a localized
72
+ * search or label member is filtered and sorted in.
73
+ */
74
+ readonly url: (term: string, limit: number, locale: Locale) => string;
75
+ /**
76
+ * `undefined` when the body is not a readable `entityPage` envelope. A
77
+ * localized label reads in `locale`. Given `names`, a record is labelled by
78
+ * the name of the record it refers to, and the items come in their order.
79
+ */
80
+ readonly read: (body: unknown, locale: Locale, names?: ReadonlyMap<string, string>) => {
39
81
  items: RecordSearchOption[];
40
82
  total: number;
41
83
  } | undefined;
84
+ /**
85
+ * Present for a source searched through a reference: the target's URL for
86
+ * one term, its matches, and this source's URL for the records referring to
87
+ * them. When it is, {@link url} is never called.
88
+ */
89
+ readonly through?: {
90
+ readonly url: (term: string, limit: number, locale: Locale) => string;
91
+ readonly read: (body: unknown, locale: Locale) => readonly RecordSearchMatch[] | undefined;
92
+ readonly urlFor: (ids: readonly string[], limit: number) => string;
93
+ };
42
94
  }
43
95
  /**
44
96
  * Declare a record search source, validating it against the entity's own
@@ -54,5 +106,5 @@ export interface RecordSearchSource {
54
106
  * from a palette is indistinguishable from a permission the caller lacks — but
55
107
  * the blast radius is wider than the picker's, which fails only its own render.
56
108
  */
57
- export declare const defineRecordSearchSource: <TEntity extends Entity>({ key, entityConstructor, baseUrl, searchProperty, labelProperty, sublabelProperty, labelKey, href, }: RecordSearchSourceConfig<TEntity>) => RecordSearchSource;
109
+ export declare const defineRecordSearchSource: <TEntity extends Entity>({ key, entityConstructor, baseUrl, searchProperty, labelProperty, sublabelProperty, labelKey, href, reference, }: RecordSearchSourceConfig<TEntity>) => RecordSearchSource;
58
110
  //# sourceMappingURL=record-search-source.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record-search-source.d.ts","sourceRoot":"","sources":["../../../src/lib/search/record-search-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EAMvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,MAAM;IAC9D,sEAAsE;IACtE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACvD,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,sDAAsD;IACtD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;CACvC;AAED,qEAAqE;AACrE,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AAE;QACjB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;QACtE,QAAQ,CAAC,IAAI,EAAE,CACb,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,KACX,SAAS,iBAAiB,EAAE,GAAG,SAAS,CAAC;QAC9C,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;KACpE,CAAC;CACH;AA6FD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,SAAS,MAAM,EAAE,kHAU9D,wBAAwB,CAAC,OAAO,CAAC,KAAG,kBAsNtC,CAAC"}
@@ -1,8 +1,58 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { describeEntityColumns, envelopeEntityName, readEntityPageEnvelope, serializeLoadRequestParams } from '@entifix/core';
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
3
+ import { describeEntityColumns, entityReferenceKey, envelopeEntityName, findMetaEntity, localizedQueryProperty, queryPropertyFor, readEntityPageEnvelope, recordLabel, serializeLoadRequestParams, shortId } from '@entifix/core';
3
4
  import { Effect, Exit } from 'effect';
4
5
  const descriptorOf = (columns, name)=>columns.find((column)=>column.name === name);
5
6
  const rejection = (entityName, member, because, fix)=>new Error(`Cannot search ${entityName} by "${member}": ${because} ${fix}`);
7
+ /**
8
+ * Where a record falls among the matches it refers to: in their order, and
9
+ * after them when it refers to none of them — never ahead of a named one.
10
+ */ const rankOf = (order, id)=>{
11
+ if (order === undefined) return 0;
12
+ const at = order.indexOf(id);
13
+ return at === -1 ? order.length : at;
14
+ };
15
+ const isText = (descriptor)=>descriptor.type === 'string' || descriptor.type === 'localized';
16
+ /**
17
+ * Built through `serializeLoadRequestParams`, never by hand. That is
18
+ * correctness rather than tidiness: `encodeRsqlValue` quotes a term carrying
19
+ * any of `;,()'"=!<>\` or whitespace, so `Acme, Inc.` stays one value instead
20
+ * of splitting the expression into two comparisons.
21
+ */ const pageUrl = (baseUrl, entity, filter, sortBy, limit)=>{
22
+ const request = _extends({
23
+ filtering: [
24
+ filter
25
+ ]
26
+ }, sortBy === undefined ? {} : {
27
+ sorting: [
28
+ {
29
+ 0: {
30
+ property: sortBy,
31
+ type: 'asc'
32
+ }
33
+ }
34
+ ]
35
+ }, {
36
+ page: 1,
37
+ pageSize: limit
38
+ });
39
+ return `${baseUrl}/api/${entity}?${serializeLoadRequestParams(request).toString()}`;
40
+ };
41
+ /** The target's label member, checked the way a source's own label is. */ const throughLabel = (entityName, search, reference)=>{
42
+ var _ref, _reference_labelProperty;
43
+ var _search_references, _findMetaEntity;
44
+ const target = reference.entityConstructor;
45
+ const referenced = entityReferenceKey(target);
46
+ if (((_search_references = search.references) == null ? void 0 : _search_references.entity) !== referenced) {
47
+ throw rejection(entityName, search.name, `the member does not reference ${referenced}, so its value is no ${target.name} id.`, `Declare \`references: { entity: '${referenced}' }\` on it, or search through the entity it does reference.`);
48
+ }
49
+ const name = (_ref = (_reference_labelProperty = reference.labelProperty) != null ? _reference_labelProperty : (_findMetaEntity = findMetaEntity(target)) == null ? void 0 : _findMetaEntity.labelMember) != null ? _ref : undefined;
50
+ const label = name === undefined ? undefined : descriptorOf(describeEntityColumns(target), name);
51
+ if (label === undefined || !label.filterable || !label.sortable || !isText(label)) {
52
+ throw rejection(entityName, search.name, `${target.name} is not named by a filterable, sortable text member${name === undefined ? '' : ` ("${name}" is not one)`}, so a term cannot be matched against it.`, "Name one as the reference's `labelProperty`, or declare the target's `labelMember`.");
53
+ }
54
+ return label;
55
+ };
6
56
  /**
7
57
  * Declare a record search source, validating it against the entity's own
8
58
  * metadata **now** rather than on the first keystroke.
@@ -16,7 +66,7 @@ const rejection = (entityName, member, because, fix)=>new Error(`Cannot search $
16
66
  * boot rather than just search. That is deliberate — a source silently missing
17
67
  * from a palette is indistinguishable from a permission the caller lacks — but
18
68
  * the blast radius is wider than the picker's, which fails only its own render.
19
- */ export const defineRecordSearchSource = ({ key, entityConstructor, baseUrl, searchProperty, labelProperty, sublabelProperty, labelKey, href })=>{
69
+ */ export const defineRecordSearchSource = ({ key, entityConstructor, baseUrl, searchProperty, labelProperty, sublabelProperty, labelKey, href, reference })=>{
20
70
  const entity = envelopeEntityName(entityConstructor);
21
71
  const entityName = entityConstructor.name;
22
72
  const columns = describeEntityColumns(entityConstructor);
@@ -28,27 +78,35 @@ const rejection = (entityName, member, because, fix)=>new Error(`Cannot search $
28
78
  if (!search.filterable) {
29
79
  throw rejection(entityName, searchProperty, 'the member is not filterable, so the service would reject the query.', 'Declare it `filterable` on the entity, or search another member.');
30
80
  }
81
+ const through = reference === undefined ? undefined : throughLabel(entityName, search, reference);
31
82
  // A `like` against anything else reaches `coerceValue`, which rejects a
32
83
  // partial term — so an enum member reads as declarable and is permanently
33
- // broken: every keystroke short of a whole value answers `400`.
34
- if (search.type !== 'string') {
35
- throw rejection(entityName, searchProperty, `the member is a ${search.type}, and a partial term is not a valid value for it.`, 'Search a string member instead.');
36
- }
37
- const label = descriptorOf(columns, labelProperty);
38
- if (label === undefined) {
39
- throw rejection(entityName, labelProperty, 'the entity declares no such label member.', 'Name a member the entity actually has.');
84
+ // broken: every keystroke short of a whole value answers `400`. A localized
85
+ // member is text too, searched in the reader's locale. A member searched
86
+ // through a reference is matched by `=in=`, so it holds an id instead.
87
+ if (through === undefined && !isText(search)) {
88
+ throw rejection(entityName, searchProperty, `the member is a ${search.type}, and a partial term is not a valid value for it.`, 'Search a string or localized member instead.');
40
89
  }
41
- // The group is sorted by the label, so the flag is load-bearing: without it
42
- // the service rejects the sort and the group degrades whole. Unsorted was the
43
- // alternative and is worse — the services apply no default order, so results
44
- // would arrive in storage order and shuffle as records are rewritten.
45
- // A localized label sorts one locale at a time, and a search that fans out
46
- // across services holds none: the bare member would answer `400`.
47
- if (label.type === 'localized') {
48
- throw rejection(entityName, labelProperty, 'the label member is localized, and the search has no locale to sort it in.', 'Label records by a string member.');
90
+ if (through !== undefined && labelProperty !== undefined) {
91
+ throw rejection(entityName, labelProperty, 'a source searched through a reference is labelled by the records it refers to.', 'Drop `labelProperty`, or the reference.');
49
92
  }
50
- if (!label.sortable) {
51
- throw rejection(entityName, labelProperty, 'the label member is not sortable, so the service would reject the sort.', 'Declare it `sortable` on the entity, or label records by another member.');
93
+ const label = labelProperty === undefined ? undefined : descriptorOf(columns, labelProperty);
94
+ if (labelProperty !== undefined) {
95
+ if (label === undefined) {
96
+ throw rejection(entityName, labelProperty, 'the entity declares no such label member.', 'Name a member the entity actually has.');
97
+ }
98
+ // The group is sorted by the label, so the flag is load-bearing: without
99
+ // it the service rejects the sort and the group degrades whole. Unsorted
100
+ // was the alternative and is worse — the services apply no default order,
101
+ // so results would arrive in storage order and shuffle as records are
102
+ // rewritten. A localized label sorts in the reader's locale.
103
+ if (!label.sortable) {
104
+ throw rejection(entityName, labelProperty, 'the label member is not sortable, so the service would reject the sort.', 'Declare it `sortable` on the entity, or label records by another member.');
105
+ }
106
+ } else if (through === undefined && !search.sortable) {
107
+ // A record that names itself has no one member to sort by, so the group
108
+ // is sorted by what the term matched — for the same reason as above.
109
+ throw rejection(entityName, searchProperty, 'with no label member the group is sorted by the search member, and it is not sortable.', 'Declare it `sortable`, or name a `labelProperty`.');
52
110
  }
53
111
  let sublabel;
54
112
  if (sublabelProperty !== undefined) {
@@ -57,63 +115,109 @@ const rejection = (entityName, member, because, fix)=>new Error(`Cannot search $
57
115
  throw rejection(entityName, sublabelProperty, 'the entity declares no such sublabel member.', 'Name a member the entity actually has, or drop `sublabelProperty`.');
58
116
  }
59
117
  }
60
- const read = (body)=>{
118
+ /**
119
+ * What a record is called when no member was declared to label it: what
120
+ * every other surface calls it, read in the reader's locale — or, when
121
+ * nothing names it, its short id, sent `unnamed` for the caller to put the
122
+ * entity's noun to. A reference is not resolved here: the record is named
123
+ * by its own id rather than by an id that points elsewhere.
124
+ */ const ownLabel = (row, id, locale)=>{
125
+ const named = recordLabel(entityConstructor, row);
126
+ const text = named.kind === 'value' ? localizedQueryProperty(named.member, locale).read(named.value) : undefined;
127
+ return text === undefined ? {
128
+ label: shortId(id),
129
+ unnamed: true
130
+ } : {
131
+ label: text
132
+ };
133
+ };
134
+ const labelOf = (row, id, locale)=>{
135
+ if (label === undefined) return ownLabel(row, id, locale);
136
+ const raw = localizedQueryProperty(label, locale).read(row[label.name]);
137
+ // A blank label is as useless as a missing one, so both fall back to the
138
+ // id — an unnamed record must stay distinguishable from the one above it.
139
+ // Same rule the relation picker's `labelOf` applies.
140
+ return {
141
+ label: raw === undefined || raw === '' ? id : raw
142
+ };
143
+ };
144
+ const read = (body, locale, names)=>{
61
145
  const page = Effect.runSyncExit(readEntityPageEnvelope(entityConstructor, body));
62
146
  if (Exit.isFailure(page)) return undefined;
147
+ const order = names === undefined ? undefined : [
148
+ ...names.keys()
149
+ ];
63
150
  const items = page.value.items.filter((record)=>record.id != null).map((record)=>{
151
+ var _names_get;
64
152
  const row = record;
65
- const raw = row[labelProperty];
66
153
  const id = String(record.id);
154
+ const sublabelText = sublabel === undefined ? undefined : localizedQueryProperty(sublabel, locale).read(row[sublabel.name]);
155
+ const named = names === undefined ? labelOf(row, id, locale) : {
156
+ label: (_names_get = names.get(String(row[searchProperty]))) != null ? _names_get : shortId(id)
157
+ };
67
158
  return _extends({
68
- id,
69
- // A blank label is as useless as a missing one, so both fall back to
70
- // the id — an unnamed record must stay distinguishable from the one
71
- // above it. Same rule the relation picker's `labelOf` applies.
72
- label: raw == null || raw === '' ? id : String(raw)
73
- }, sublabel !== undefined && row[sublabel.name] != null ? {
74
- sublabel: String(row[sublabel.name])
75
- } : {}, {
159
+ id
160
+ }, named, sublabelText === undefined ? {} : {
161
+ sublabel: sublabelText
162
+ }, {
76
163
  entity,
77
- href: href(id)
164
+ href: href(id),
165
+ rank: rankOf(order, String(row[searchProperty]))
78
166
  });
167
+ })// In the order the referenced records matched, which is their names'.
168
+ .sort((left, right)=>left.rank - right.rank).map((_0)=>{
169
+ let { rank: _rank } = _0, option = _object_without_properties_loose(_0, [
170
+ "rank"
171
+ ]);
172
+ return option;
79
173
  });
80
174
  return {
81
175
  items,
82
176
  total: page.value.total
83
177
  };
84
178
  };
85
- return {
179
+ const sortBy = (locale)=>label === undefined ? queryPropertyFor(search, locale) : queryPropertyFor(label, locale);
180
+ return _extends({
86
181
  key: key != null ? key : entity,
87
182
  entity,
88
183
  labelKey,
89
- /**
90
- * Built through `serializeLoadRequestParams`, never by hand. That is
91
- * correctness rather than tidiness: `encodeRsqlValue` quotes a term carrying
92
- * any of `;,()'"=!<>\` or whitespace, so `Acme, Inc.` stays one value
93
- * instead of splitting the expression into two comparisons.
94
- */ url: (term, limit)=>{
95
- const request = {
96
- filtering: [
97
- {
98
- property: search.key,
99
- operator: 'like',
100
- value: term
101
- }
102
- ],
103
- sorting: [
104
- {
105
- 0: {
106
- property: label.key,
107
- type: 'asc'
108
- }
109
- }
110
- ],
111
- page: 1,
112
- pageSize: limit
113
- };
114
- return `${baseUrl}/api/${entity}?${serializeLoadRequestParams(request).toString()}`;
115
- },
184
+ url: (term, limit, locale)=>pageUrl(baseUrl, entity, {
185
+ property: queryPropertyFor(search, locale),
186
+ operator: 'like',
187
+ value: term
188
+ }, sortBy(locale), limit),
116
189
  read
190
+ }, through === undefined || reference === undefined ? {} : {
191
+ through: throughOf(reference, through, (ids, limit)=>pageUrl(baseUrl, entity, {
192
+ property: search.key,
193
+ operator: 'in',
194
+ values: ids
195
+ }, // The order is the matches', applied by `read`.
196
+ undefined, limit))
197
+ });
198
+ };
199
+ /** The target half of a source searched through a reference. */ const throughOf = (reference, label, urlFor)=>{
200
+ const target = reference.entityConstructor;
201
+ const targetEntity = envelopeEntityName(target);
202
+ return {
203
+ url: (term, limit, locale)=>pageUrl(reference.baseUrl, targetEntity, {
204
+ property: queryPropertyFor(label, locale),
205
+ operator: 'like',
206
+ value: term
207
+ }, queryPropertyFor(label, locale), limit),
208
+ read: (body, locale)=>{
209
+ const page = Effect.runSyncExit(readEntityPageEnvelope(target, body));
210
+ if (Exit.isFailure(page)) return undefined;
211
+ return page.value.items.filter((record)=>record.id != null).map((record)=>{
212
+ const id = String(record.id);
213
+ const name = localizedQueryProperty(label, locale).read(record[label.name]);
214
+ return {
215
+ id,
216
+ label: name === undefined || name === '' ? shortId(id) : name
217
+ };
218
+ });
219
+ },
220
+ urlFor
117
221
  };
118
222
  };
119
223
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/search/record-search-source.ts"],"sourcesContent":["import {\n describeEntityColumns,\n type Entity,\n type EntityConstructor,\n type EntityFieldDescriptor,\n type EntityLoadRequest,\n envelopeEntityName,\n readEntityPageEnvelope,\n serializeLoadRequestParams,\n} from '@entifix/core';\nimport { Effect, Exit } from 'effect';\n\nimport type { RecordSearchOption } from './record-search.types.js';\n\n/**\n * What a host declares in order to make one entity searchable from the palette.\n *\n * The search and label members are **declared**, not derived, and that is not an\n * oversight in the metadata: `linkSearchProperty`/`linkLabelProperty` are\n * properties of a *referring* accessor — they say how the owner of a relation\n * looks up its target — and an entity has no member that says \"this is what I am\n * called\". So the host that mounts the screens says it, next to the route those\n * screens live at.\n */\nexport interface RecordSearchSourceConfig<TEntity extends Entity> {\n /** Stable id, unique per host. Defaults to the entity's wire name. */\n readonly key?: string;\n readonly entityConstructor: EntityConstructor<TEntity>;\n /** Where the owning service listens, **without** the `/api` suffix. */\n readonly baseUrl: string;\n /** The `filterable` string member a term is matched against with `like`. */\n readonly searchProperty: string;\n /** The `sortable` member read as a record's label. */\n readonly labelProperty: string;\n /** An optional secondary line — a code, a role. */\n readonly sublabelProperty?: string;\n /** The group heading, as the entity's own `pluralKey`. */\n readonly labelKey: string;\n /** Where selecting a record lands. Locale-free; the caller prefixes it. */\n readonly href: (id: string) => string;\n}\n\n/** A declared source, reduced to what the fan-out actually calls. */\nexport interface RecordSearchSource {\n readonly key: string;\n readonly entity: string;\n readonly labelKey: string;\n /** The upstream URL for one term. */\n readonly url: (term: string, limit: number) => string;\n /** `undefined` when the body is not a readable `entityPage` envelope. */\n readonly read: (\n body: unknown,\n ) => { items: RecordSearchOption[]; total: number } | undefined;\n}\n\nconst descriptorOf = (\n columns: EntityFieldDescriptor[],\n name: string,\n): EntityFieldDescriptor | undefined =>\n columns.find(column => column.name === name);\n\nconst rejection = (\n entityName: string,\n member: string,\n because: string,\n fix: string,\n): Error =>\n new Error(`Cannot search ${entityName} by \"${member}\": ${because} ${fix}`);\n\n/**\n * Declare a record search source, validating it against the entity's own\n * metadata **now** rather than on the first keystroke.\n *\n * Every check here guards a failure that is otherwise silent at both ends: the\n * service answers `400`, and a caller renders that as a group it could not\n * reach — which reads as \"there are no products\". `assertSearchable` took the\n * same posture for the relation picker, for the same reason.\n *\n * ⚠️ This throws at **module load**, so a bad declaration fails the whole app at\n * boot rather than just search. That is deliberate — a source silently missing\n * from a palette is indistinguishable from a permission the caller lacks — but\n * the blast radius is wider than the picker's, which fails only its own render.\n */\nexport const defineRecordSearchSource = <TEntity extends Entity>({\n key,\n entityConstructor,\n baseUrl,\n searchProperty,\n labelProperty,\n sublabelProperty,\n labelKey,\n href,\n}: RecordSearchSourceConfig<TEntity>): RecordSearchSource => {\n const entity = envelopeEntityName(entityConstructor);\n const entityName = entityConstructor.name;\n const columns = describeEntityColumns(entityConstructor);\n\n const search = descriptorOf(columns, searchProperty);\n if (search === undefined) {\n throw rejection(\n entityName,\n searchProperty,\n 'the entity declares no such member.',\n 'Name a member the entity actually has.',\n );\n }\n // `filterable` is simultaneously the server-side RSQL allowlist.\n if (!search.filterable) {\n throw rejection(\n entityName,\n searchProperty,\n 'the member is not filterable, so the service would reject the query.',\n 'Declare it `filterable` on the entity, or search another member.',\n );\n }\n // A `like` against anything else reaches `coerceValue`, which rejects a\n // partial term — so an enum member reads as declarable and is permanently\n // broken: every keystroke short of a whole value answers `400`.\n if (search.type !== 'string') {\n throw rejection(\n entityName,\n searchProperty,\n `the member is a ${search.type}, and a partial term is not a valid value for it.`,\n 'Search a string member instead.',\n );\n }\n\n const label = descriptorOf(columns, labelProperty);\n if (label === undefined) {\n throw rejection(\n entityName,\n labelProperty,\n 'the entity declares no such label member.',\n 'Name a member the entity actually has.',\n );\n }\n // The group is sorted by the label, so the flag is load-bearing: without it\n // the service rejects the sort and the group degrades whole. Unsorted was the\n // alternative and is worse — the services apply no default order, so results\n // would arrive in storage order and shuffle as records are rewritten.\n // A localized label sorts one locale at a time, and a search that fans out\n // across services holds none: the bare member would answer `400`.\n if (label.type === 'localized') {\n throw rejection(\n entityName,\n labelProperty,\n 'the label member is localized, and the search has no locale to sort it in.',\n 'Label records by a string member.',\n );\n }\n if (!label.sortable) {\n throw rejection(\n entityName,\n labelProperty,\n 'the label member is not sortable, so the service would reject the sort.',\n 'Declare it `sortable` on the entity, or label records by another member.',\n );\n }\n\n let sublabel: EntityFieldDescriptor | undefined;\n if (sublabelProperty !== undefined) {\n sublabel = descriptorOf(columns, sublabelProperty);\n if (sublabel === undefined) {\n throw rejection(\n entityName,\n sublabelProperty,\n 'the entity declares no such sublabel member.',\n 'Name a member the entity actually has, or drop `sublabelProperty`.',\n );\n }\n }\n\n const read = (\n body: unknown,\n ): { items: RecordSearchOption[]; total: number } | undefined => {\n const page = Effect.runSyncExit(\n readEntityPageEnvelope(entityConstructor, body),\n );\n if (Exit.isFailure(page)) return undefined;\n\n const items = page.value.items\n .filter(record => (record as Entity).id != null)\n .map(record => {\n const row = record as unknown as Record<string, unknown>;\n const raw = row[labelProperty];\n const id = String((record as Entity).id);\n return {\n id,\n // A blank label is as useless as a missing one, so both fall back to\n // the id — an unnamed record must stay distinguishable from the one\n // above it. Same rule the relation picker's `labelOf` applies.\n label: raw == null || raw === '' ? id : String(raw),\n ...(sublabel !== undefined && row[sublabel.name] != null\n ? { sublabel: String(row[sublabel.name]) }\n : {}),\n entity,\n href: href(id),\n } satisfies RecordSearchOption;\n });\n\n return { items, total: page.value.total };\n };\n\n return {\n key: key ?? entity,\n entity,\n labelKey,\n /**\n * Built through `serializeLoadRequestParams`, never by hand. That is\n * correctness rather than tidiness: `encodeRsqlValue` quotes a term carrying\n * any of `;,()'\"=!<>\\` or whitespace, so `Acme, Inc.` stays one value\n * instead of splitting the expression into two comparisons.\n */\n url: (term, limit) => {\n const request = {\n filtering: [\n {\n property: search.key,\n operator: 'like' as const,\n value: term,\n },\n ],\n sorting: [{ 0: { property: label.key, type: 'asc' as const } }],\n page: 1,\n pageSize: limit,\n } as unknown as EntityLoadRequest;\n\n return `${baseUrl}/api/${entity}?${serializeLoadRequestParams(request).toString()}`;\n },\n read,\n };\n};\n"],"names":["describeEntityColumns","envelopeEntityName","readEntityPageEnvelope","serializeLoadRequestParams","Effect","Exit","descriptorOf","columns","name","find","column","rejection","entityName","member","because","fix","Error","defineRecordSearchSource","key","entityConstructor","baseUrl","searchProperty","labelProperty","sublabelProperty","labelKey","href","entity","search","undefined","filterable","type","label","sortable","sublabel","read","body","page","runSyncExit","isFailure","items","value","filter","record","id","map","row","raw","String","total","url","term","limit","request","filtering","property","operator","sorting","pageSize","toString"],"mappings":";AAAA,SACEA,qBAAqB,EAKrBC,kBAAkB,EAClBC,sBAAsB,EACtBC,0BAA0B,QACrB,gBAAgB;AACvB,SAASC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AA6CtC,MAAMC,eAAe,CACnBC,SACAC,OAEAD,QAAQE,IAAI,CAACC,CAAAA,SAAUA,OAAOF,IAAI,KAAKA;AAEzC,MAAMG,YAAY,CAChBC,YACAC,QACAC,SACAC,MAEA,IAAIC,MAAM,CAAC,cAAc,EAAEJ,WAAW,KAAK,EAAEC,OAAO,GAAG,EAAEC,QAAQ,CAAC,EAAEC,KAAK;AAE3E;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAME,2BAA2B,CAAyB,EAC/DC,GAAG,EACHC,iBAAiB,EACjBC,OAAO,EACPC,cAAc,EACdC,a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ACD,KAAK,CAC3BE,MAAM,CAACC,CAAAA,SAAU,AAACA,OAAkBC,EAAE,IAAI,MAC1CC,GAAG,CAACF,CAAAA;YACH,MAAMG,MAAMH;YACZ,MAAMI,MAAMD,GAAG,CAACvB,cAAc;YAC9B,MAAMqB,KAAKI,OAAO,AAACL,OAAkBC,EAAE;YACvC,OAAO;gBACLA;gBACA,qEAAqE;gBACrE,oEAAoE;gBACpE,+DAA+D;gBAC/DZ,OAAOe,OAAO,QAAQA,QAAQ,KAAKH,KAAKI,OAAOD;eAC3Cb,aAAaL,aAAaiB,GAAG,CAACZ,SAASzB,IAAI,CAAC,IAAI,OAChD;gBAAEyB,UAAUc,OAAOF,GAAG,CAACZ,SAASzB,IAAI,CAAC;YAAE,IACvC,CAAC;gBACLkB;gBACAD,MAAMA,KAAKkB;;QAEf;QAEF,OAAO;YAAEJ;YAAOS,OAAOZ,KAAKI,KAAK,CAACQ,KAAK;QAAC;IAC1C;IAEA,OAAO;QACL9B,GAAG,EAAEA,cAAAA,MAAOQ;QACZA;QACAF;QACA;;;;;KAKC,GACDyB,KAAK,CAACC,MAAMC;YACV,MAAMC,UAAU;gBACdC,WAAW;oBACT;wBACEC,UAAU3B,OAAOT,GAAG;wBACpBqC,UAAU;wBACVf,OAAOU;oBACT;iBACD;gBACDM,SAAS;oBAAC;wBAAE,GAAG;4BAAEF,UAAUvB,MAAMb,GAAG;4BAAEY,MAAM;wBAAe;oBAAE;iBAAE;gBAC/DM,MAAM;gBACNqB,UAAUN;YACZ;YAEA,OAAO,GAAG/B,QAAQ,KAAK,EAAEM,OAAO,CAAC,EAAEvB,2BAA2BiD,SAASM,QAAQ,IAAI;QACrF;QACAxB;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../src/lib/search/record-search-source.ts"],"sourcesContent":["import {\n describeEntityColumns,\n type Entity,\n type EntityConstructor,\n type EntityFieldDescriptor,\n type EntityLoadRequest,\n entityReferenceKey,\n envelopeEntityName,\n findMetaEntity,\n type Locale,\n localizedQueryProperty,\n queryPropertyFor,\n readEntityPageEnvelope,\n recordLabel,\n serializeLoadRequestParams,\n shortId,\n} from '@entifix/core';\nimport { Effect, Exit } from 'effect';\n\nimport type { RecordSearchOption } from './record-search.types.js';\n\n/**\n * What a host declares in order to make one entity searchable from the palette.\n *\n * The search and label members are **declared**, not derived, and that is not an\n * oversight in the metadata: `linkSearchProperty`/`linkLabelProperty` are\n * properties of a *referring* accessor — they say how the owner of a relation\n * looks up its target — and an entity has no member that says \"this is what I am\n * called\". So the host that mounts the screens says it, next to the route those\n * screens live at.\n */\nexport interface RecordSearchSourceConfig<TEntity extends Entity> {\n /** Stable id, unique per host. Defaults to the entity's wire name. */\n readonly key?: string;\n readonly entityConstructor: EntityConstructor<TEntity>;\n /** Where the owning service listens, **without** the `/api` suffix. */\n readonly baseUrl: string;\n /**\n * The `filterable` member a term is matched against: a string or localized\n * member, matched with `like` — or, with {@link reference}, the member that\n * holds the referenced record's id, matched with `=in=`.\n */\n readonly searchProperty: string;\n /**\n * The `sortable` member read as a record's label. Omitted, the record names\n * itself as every other surface names it — its `labelMember`, else the\n * first member that can name it — and one nothing names is sent `unnamed`,\n * by its short id; the group is then sorted by {@link searchProperty}, which\n * must be `sortable`. Never given with {@link reference}, which labels.\n */\n readonly labelProperty?: string;\n /** An optional secondary line — a code, a role. */\n readonly sublabelProperty?: string;\n /** The group heading, as the entity's own `pluralKey`. */\n readonly labelKey: string;\n /** Where selecting a record lands. Locale-free; the caller prefixes it. */\n readonly href: (id: string) => string;\n /**\n * Search through the record {@link searchProperty} refers to, when that is\n * what a person knows the record by: a stock item by its product's name.\n * The term is matched against the referenced entity's label at its owner,\n * and the records referring to the matches are read and labelled with\n * their names.\n */\n readonly reference?: RecordSearchReference;\n}\n\n/** The entity a source is searched through, and where its owner listens. */\nexport interface RecordSearchReference {\n // Any entity: the target is another domain's class, typed by nothing here.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly entityConstructor: EntityConstructor<any>;\n /** Where the target's owning service listens, **without** the `/api` suffix. */\n readonly baseUrl: string;\n /**\n * The target member the term is matched against and the records are\n * labelled by — a filterable, sortable string or localized member. Defaults\n * to the target's declared `labelMember`.\n */\n readonly labelProperty?: string;\n}\n\n/** One referenced record a term matched: its id, and what it is called. */\nexport interface RecordSearchMatch {\n readonly id: string;\n readonly label: string;\n}\n\n/** A declared source, reduced to what the fan-out actually calls. */\nexport interface RecordSearchSource {\n readonly key: string;\n readonly entity: string;\n readonly labelKey: string;\n /**\n * The upstream URL for one term, in the reader's locale — which a localized\n * search or label member is filtered and sorted in.\n */\n readonly url: (term: string, limit: number, locale: Locale) => string;\n /**\n * `undefined` when the body is not a readable `entityPage` envelope. A\n * localized label reads in `locale`. Given `names`, a record is labelled by\n * the name of the record it refers to, and the items come in their order.\n */\n readonly read: (\n body: unknown,\n locale: Locale,\n names?: ReadonlyMap<string, string>,\n ) => { items: RecordSearchOption[]; total: number } | undefined;\n /**\n * Present for a source searched through a reference: the target's URL for\n * one term, its matches, and this source's URL for the records referring to\n * them. When it is, {@link url} is never called.\n */\n readonly through?: {\n readonly url: (term: string, limit: number, locale: Locale) => string;\n readonly read: (\n body: unknown,\n locale: Locale,\n ) => readonly RecordSearchMatch[] | undefined;\n readonly urlFor: (ids: readonly string[], limit: number) => string;\n };\n}\n\nconst descriptorOf = (\n columns: EntityFieldDescriptor[],\n name: string,\n): EntityFieldDescriptor | undefined =>\n columns.find(column => column.name === name);\n\nconst rejection = (\n entityName: string,\n member: string,\n because: string,\n fix: string,\n): Error =>\n new Error(`Cannot search ${entityName} by \"${member}\": ${because} ${fix}`);\n\n/**\n * Where a record falls among the matches it refers to: in their order, and\n * after them when it refers to none of them — never ahead of a named one.\n */\nconst rankOf = (order: readonly string[] | undefined, id: string): number => {\n if (order === undefined) return 0;\n const at = order.indexOf(id);\n return at === -1 ? order.length : at;\n};\n\nconst isText = (descriptor: EntityFieldDescriptor) =>\n descriptor.type === 'string' || descriptor.type === 'localized';\n\n/**\n * Built through `serializeLoadRequestParams`, never by hand. That is\n * correctness rather than tidiness: `encodeRsqlValue` quotes a term carrying\n * any of `;,()'\"=!<>\\` or whitespace, so `Acme, Inc.` stays one value instead\n * of splitting the expression into two comparisons.\n */\nconst pageUrl = (\n baseUrl: string,\n entity: string,\n filter:\n | { property: string; operator: 'like'; value: string }\n | { property: string; operator: 'in'; values: readonly string[] },\n sortBy: string | undefined,\n limit: number,\n): string => {\n const request = {\n filtering: [filter],\n ...(sortBy === undefined\n ? {}\n : { sorting: [{ 0: { property: sortBy, type: 'asc' as const } }] }),\n page: 1,\n pageSize: limit,\n } as unknown as EntityLoadRequest;\n return `${baseUrl}/api/${entity}?${serializeLoadRequestParams(request).toString()}`;\n};\n\n/** The target's label member, checked the way a source's own label is. */\nconst throughLabel = (\n entityName: string,\n search: EntityFieldDescriptor,\n reference: RecordSearchReference,\n): EntityFieldDescriptor => {\n const target = reference.entityConstructor;\n const referenced = entityReferenceKey(target);\n if (search.references?.entity !== referenced) {\n throw rejection(\n entityName,\n search.name,\n `the member does not reference ${referenced}, so its value is no ${target.name} id.`,\n `Declare \\`references: { entity: '${referenced}' }\\` on it, or search through the entity it does reference.`,\n );\n }\n const name =\n reference.labelProperty ?? findMetaEntity(target)?.labelMember ?? undefined;\n const label =\n name === undefined\n ? undefined\n : descriptorOf(describeEntityColumns(target), name);\n if (\n label === undefined ||\n !label.filterable ||\n !label.sortable ||\n !isText(label)\n ) {\n throw rejection(\n entityName,\n search.name,\n `${target.name} is not named by a filterable, sortable text member${name === undefined ? '' : ` (\"${name}\" is not one)`}, so a term cannot be matched against it.`,\n \"Name one as the reference's `labelProperty`, or declare the target's `labelMember`.\",\n );\n }\n return label;\n};\n\n/**\n * Declare a record search source, validating it against the entity's own\n * metadata **now** rather than on the first keystroke.\n *\n * Every check here guards a failure that is otherwise silent at both ends: the\n * service answers `400`, and a caller renders that as a group it could not\n * reach — which reads as \"there are no products\". `assertSearchable` took the\n * same posture for the relation picker, for the same reason.\n *\n * ⚠️ This throws at **module load**, so a bad declaration fails the whole app at\n * boot rather than just search. That is deliberate — a source silently missing\n * from a palette is indistinguishable from a permission the caller lacks — but\n * the blast radius is wider than the picker's, which fails only its own render.\n */\nexport const defineRecordSearchSource = <TEntity extends Entity>({\n key,\n entityConstructor,\n baseUrl,\n searchProperty,\n labelProperty,\n sublabelProperty,\n labelKey,\n href,\n reference,\n}: RecordSearchSourceConfig<TEntity>): RecordSearchSource => {\n const entity = envelopeEntityName(entityConstructor);\n const entityName = entityConstructor.name;\n const columns = describeEntityColumns(entityConstructor);\n\n const search = descriptorOf(columns, searchProperty);\n if (search === undefined) {\n throw rejection(\n entityName,\n searchProperty,\n 'the entity declares no such member.',\n 'Name a member the entity actually has.',\n );\n }\n // `filterable` is simultaneously the server-side RSQL allowlist.\n if (!search.filterable) {\n throw rejection(\n entityName,\n searchProperty,\n 'the member is not filterable, so the service would reject the query.',\n 'Declare it `filterable` on the entity, or search another member.',\n );\n }\n\n const through =\n reference === undefined\n ? undefined\n : throughLabel(entityName, search, reference);\n\n // A `like` against anything else reaches `coerceValue`, which rejects a\n // partial term — so an enum member reads as declarable and is permanently\n // broken: every keystroke short of a whole value answers `400`. A localized\n // member is text too, searched in the reader's locale. A member searched\n // through a reference is matched by `=in=`, so it holds an id instead.\n if (through === undefined && !isText(search)) {\n throw rejection(\n entityName,\n searchProperty,\n `the member is a ${search.type}, and a partial term is not a valid value for it.`,\n 'Search a string or localized member instead.',\n );\n }\n\n if (through !== undefined && labelProperty !== undefined) {\n throw rejection(\n entityName,\n labelProperty,\n 'a source searched through a reference is labelled by the records it refers to.',\n 'Drop `labelProperty`, or the reference.',\n );\n }\n\n const label =\n labelProperty === undefined\n ? undefined\n : descriptorOf(columns, labelProperty);\n if (labelProperty !== undefined) {\n if (label === undefined) {\n throw rejection(\n entityName,\n labelProperty,\n 'the entity declares no such label member.',\n 'Name a member the entity actually has.',\n );\n }\n // The group is sorted by the label, so the flag is load-bearing: without\n // it the service rejects the sort and the group degrades whole. Unsorted\n // was the alternative and is worse — the services apply no default order,\n // so results would arrive in storage order and shuffle as records are\n // rewritten. A localized label sorts in the reader's locale.\n if (!label.sortable) {\n throw rejection(\n entityName,\n labelProperty,\n 'the label member is not sortable, so the service would reject the sort.',\n 'Declare it `sortable` on the entity, or label records by another member.',\n );\n }\n } else if (through === undefined && !search.sortable) {\n // A record that names itself has no one member to sort by, so the group\n // is sorted by what the term matched — for the same reason as above.\n throw rejection(\n entityName,\n searchProperty,\n 'with no label member the group is sorted by the search member, and it is not sortable.',\n 'Declare it `sortable`, or name a `labelProperty`.',\n );\n }\n\n let sublabel: EntityFieldDescriptor | undefined;\n if (sublabelProperty !== undefined) {\n sublabel = descriptorOf(columns, sublabelProperty);\n if (sublabel === undefined) {\n throw rejection(\n entityName,\n sublabelProperty,\n 'the entity declares no such sublabel member.',\n 'Name a member the entity actually has, or drop `sublabelProperty`.',\n );\n }\n }\n\n /**\n * What a record is called when no member was declared to label it: what\n * every other surface calls it, read in the reader's locale — or, when\n * nothing names it, its short id, sent `unnamed` for the caller to put the\n * entity's noun to. A reference is not resolved here: the record is named\n * by its own id rather than by an id that points elsewhere.\n */\n const ownLabel = (\n row: Record<string, unknown>,\n id: string,\n locale: Locale,\n ): Pick<RecordSearchOption, 'label' | 'unnamed'> => {\n const named = recordLabel(entityConstructor, row);\n const text =\n named.kind === 'value'\n ? localizedQueryProperty(named.member, locale).read(named.value)\n : undefined;\n return text === undefined\n ? { label: shortId(id), unnamed: true }\n : { label: text };\n };\n\n const labelOf = (\n row: Record<string, unknown>,\n id: string,\n locale: Locale,\n ): Pick<RecordSearchOption, 'label' | 'unnamed'> => {\n if (label === undefined) return ownLabel(row, id, locale);\n const raw = localizedQueryProperty(label, locale).read(row[label.name]);\n // A blank label is as useless as a missing one, so both fall back to the\n // id — an unnamed record must stay distinguishable from the one above it.\n // Same rule the relation picker's `labelOf` applies.\n return { label: raw === undefined || raw === '' ? id : raw };\n };\n\n const read = (\n body: unknown,\n locale: Locale,\n names?: ReadonlyMap<string, string>,\n ): { items: RecordSearchOption[]; total: number } | undefined => {\n const page = Effect.runSyncExit(\n readEntityPageEnvelope(entityConstructor, body),\n );\n if (Exit.isFailure(page)) return undefined;\n\n const order = names === undefined ? undefined : [...names.keys()];\n const items = page.value.items\n .filter(record => (record as Entity).id != null)\n .map(record => {\n const row = record as unknown as Record<string, unknown>;\n const id = String((record as Entity).id);\n const sublabelText =\n sublabel === undefined\n ? undefined\n : localizedQueryProperty(sublabel, locale).read(row[sublabel.name]);\n const named =\n names === undefined\n ? labelOf(row, id, locale)\n : { label: names.get(String(row[searchProperty])) ?? shortId(id) };\n return {\n id,\n ...named,\n ...(sublabelText === undefined ? {} : { sublabel: sublabelText }),\n entity,\n href: href(id),\n rank: rankOf(order, String(row[searchProperty])),\n };\n })\n // In the order the referenced records matched, which is their names'.\n .sort((left, right) => left.rank - right.rank)\n .map(({ rank: _rank, ...option }) => option satisfies RecordSearchOption);\n\n return { items, total: page.value.total };\n };\n\n const sortBy = (locale: Locale) =>\n label === undefined\n ? queryPropertyFor(search, locale)\n : queryPropertyFor(label, locale);\n\n return {\n key: key ?? entity,\n entity,\n labelKey,\n url: (term, limit, locale) =>\n pageUrl(\n baseUrl,\n entity,\n {\n property: queryPropertyFor(search, locale),\n operator: 'like',\n value: term,\n },\n sortBy(locale),\n limit,\n ),\n read,\n ...(through === undefined || reference === undefined\n ? {}\n : {\n through: throughOf(reference, through, (ids, limit) =>\n pageUrl(\n baseUrl,\n entity,\n { property: search.key, operator: 'in', values: ids },\n // The order is the matches', applied by `read`.\n undefined,\n limit,\n ),\n ),\n }),\n };\n};\n\n/** The target half of a source searched through a reference. */\nconst throughOf = (\n reference: RecordSearchReference,\n label: EntityFieldDescriptor,\n urlFor: (ids: readonly string[], limit: number) => string,\n): NonNullable<RecordSearchSource['through']> => {\n const target = reference.entityConstructor;\n const targetEntity = envelopeEntityName(target);\n return {\n url: (term, limit, locale) =>\n pageUrl(\n reference.baseUrl,\n targetEntity,\n {\n property: queryPropertyFor(label, locale),\n operator: 'like',\n value: term,\n },\n queryPropertyFor(label, locale),\n limit,\n ),\n read: (body, locale) => {\n const page = Effect.runSyncExit(readEntityPageEnvelope(target, body));\n if (Exit.isFailure(page)) return undefined;\n return page.value.items\n .filter(record => (record as Entity).id != null)\n .map(record => {\n const id = String((record as Entity).id);\n const name = localizedQueryProperty(label, locale).read(\n (record as unknown as Record<string, unknown>)[label.name],\n );\n return {\n id,\n label: name === undefined || name === '' ? shortId(id) : name,\n };\n });\n },\n urlFor,\n };\n};\n"],"names":["describeEntityColumns","entityReferenceKey","envelopeEntityName","findMetaEntity","localizedQueryProperty","queryPropertyFor","readEntityPageEnvelope","recordLabel","serializeLoadRequestParams","shortId","Effect","Exit","descriptorOf","columns","name","find","column","rejection","entityName","member","because","fix","Error","rankOf","order","id","undefined","at","indexOf","length","isText","descriptor","type","pageUrl","baseUrl","entity","filter","sortBy","limit","request","filtering","sorting","property","page","pageSize","toString","throughLabel","search","reference","target","entityConstructor","referenced","references","labelProperty","labelMember","label","filterable","sortable","defineRecordSearchSource","key","searchProperty","sublabelProperty","labelKey","href","through","sublabel","ownLabel","row","locale","named","text","kind","read","value","unnamed","labelOf","raw","body","names","runSyncExit","isFailure","keys","items","record","map","String","sublabelText","get","rank","sort","left","right","_rank","option","total","url","term","operator","throughOf","ids","values","urlFor","targetEntity"],"mappings":";;AAAA,SACEA,qBAAqB,EAKrBC,kBAAkB,EAClBC,kBAAkB,EAClBC,cAAc,EAEdC,sBAAsB,EACtBC,gBAAgB,EAChBC,sBAAsB,EACtBC,WAAW,EACXC,0BAA0B,EAC1BC,OAAO,QACF,gBAAgB;AACvB,SAASC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AA0GtC,MAAMC,eAAe,CACnBC,SACAC,OAEAD,QAAQE,IAAI,CAACC,CAAAA,SAAUA,OAAOF,IAAI,KAAKA;AAEzC,MAAMG,YAAY,CAChBC,YACAC,QACAC,SACAC,MAEA,IAAIC,MA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QI,IAAI,CACrD,AAACW,MAA6C,CAAC5B,MAAMzC,IAAI,CAAC;gBAE5D,OAAO;oBACLW;oBACA8B,OAAOzC,SAASY,aAAaZ,SAAS,KAAKL,QAAQgB,MAAMX;gBAC3D;YACF;QACJ;QACAuF;IACF;AACF"}
@@ -32,6 +32,12 @@ export type RecordSearchUnavailableReason = string;
32
32
  export interface RecordSearchOption {
33
33
  readonly id: string;
34
34
  readonly label: string;
35
+ /**
36
+ * Nothing names this record: {@link label} is its short id, and a caller
37
+ * puts it into words with the entity's noun — "Order 8a564966" — the way a
38
+ * table names a record nothing names.
39
+ */
40
+ readonly unnamed?: true;
35
41
  /** A secondary line — a code, a role. Absent when the source declared none. */
36
42
  readonly sublabel?: string;
37
43
  /**
@@ -55,9 +61,10 @@ export interface RecordSearchGroup {
55
61
  readonly source: string;
56
62
  readonly entity: string;
57
63
  /**
58
- * The heading, as the entity's own `pluralKey`. A key rather than copy,
59
- * because the server has no locale — and the entity catalogs already carry one
60
- * for every source, so record search introduces no copy of its own.
64
+ * The heading, as the entity's own `pluralKey`. A key rather than copy:
65
+ * the entity catalogs already carry one for every source, so record search
66
+ * introduces no copy of its own. (The search runs in the reader's locale,
67
+ * but only a localized member's value depends on it.)
61
68
  */
62
69
  readonly labelKey: string;
63
70
  readonly items: readonly RecordSearchOption[];
@@ -1 +1 @@
1
- {"version":3,"file":"record-search.types.d.ts","sourceRoot":"","sources":["../../../src/lib/search/record-search.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;GAOG;AAEH;;;;;;;;;;;;GAYG;AACH;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEnD,iDAAiD;AACjD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,QAAQ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AC;CAC1D"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/search/record-search.types.ts"],"sourcesContent":["import type { FailureCategory } from '@entifix/core';\n\n/**\n * The wire contract of `GET /api/search` — the cross-domain record search the\n * command palette reads.\n *\n * Types only, so both halves can name them: the route handler builds these on\n * the server, and the browser's `searchRecords` returns them. A type crosses the\n * client/server entry split freely because it erases.\n */\n\n/**\n * Why a source produced no group.\n *\n * The split is the point, and it is not cosmetic. `forbidden` and\n * `noActiveOrganization` are the **normal** state for some callers on some\n * sources — an operator holds no membership, so every tenant-plane search\n * answers `409` — and rendering \"we could not reach this\" for the ordinary case\n * teaches an operator to ignore the warning. `timeout`/`network`/`unexpected`\n * are the ones that mean something is actually wrong.\n *\n * Every member is a key in the shared `errors` catalog, so a caller renders one\n * through the documented runtime-key hatch rather than inventing copy.\n */\n/**\n * Why a source produced nothing: the code of the failure it answered with,\n * decoded from its problem body — `noActiveOrganization`, `forbidden`,\n * `upstreamUnavailable` — or `timeout` when it never answered in time. A\n * code, so the browser renders it through the `errors` catalog like any other\n * refusal.\n */\nexport type RecordSearchUnavailableReason = string;\n\n/** One record a caller can show and route to. */\nexport interface RecordSearchOption {\n readonly id: string;\n readonly label: string;\n /** A secondary line — a code, a role. Absent when the source declared none. */\n readonly sublabel?: string;\n /**\n * `envelopeEntityName(Ctor)` — `key ?? name`.\n *\n * Repeated on every option rather than left to the group, because an option is\n * routed on its own once a caller has flattened the list: `['entity', entity]`\n * is exactly `entityQueryScope`'s output, and `entity:<entity>:<id>` is the\n * workspace tab address.\n */\n readonly entity: string;\n /**\n * Where selecting this record lands, **without** a locale prefix — the caller\n * adds one, the same way every other internal href in the back office works.\n */\n readonly href: string;\n}\n\n/** One source's answer. */\nexport interface RecordSearchGroup {\n /** The source's declared key. Stable, and the caller's ordering. */\n readonly source: string;\n readonly entity: string;\n /**\n * The heading, as the entity's own `pluralKey`. A key rather than copy,\n * because the server has no locale — and the entity catalogs already carry one\n * for every source, so record search introduces no copy of its own.\n */\n readonly labelKey: string;\n readonly items: readonly RecordSearchOption[];\n /**\n * Matches **before** the per-group limit, so \"3 more\" is renderable. A\n * reachable source with no matches is a present group with an empty `items`,\n * never an omission — that distinction is the whole reason\n * {@link RecordSearchResponse.unavailable} exists.\n */\n readonly total: number;\n}\n\n/** One source that produced nothing, and why. */\nexport interface RecordSearchUnavailable {\n readonly source: string;\n readonly entity: string;\n readonly reason: RecordSearchUnavailableReason;\n /** The failure's category: what decides whether this is scope or an outage. */\n readonly category: FailureCategory;\n /** The upstream status, when there was a response. Absent on a throw. */\n readonly status?: number;\n}\n\n/**\n * The whole answer.\n *\n * A degraded source is **named**, never a silently missing group. An empty group\n * is a confident claim that there are no matching records, and a search that\n * confidently reports nothing when it in fact could not look is the failure\n * mode this shape exists to prevent.\n */\nexport interface RecordSearchResponse {\n readonly term: string;\n readonly groups: readonly RecordSearchGroup[];\n readonly unavailable: readonly RecordSearchUnavailable[];\n}\n"],"names":[],"mappings":"AAuFA;;;;;;;CAOC,GACD,WAIC"}
1
+ {"version":3,"sources":["../../../src/lib/search/record-search.types.ts"],"sourcesContent":["import type { FailureCategory } from '@entifix/core';\n\n/**\n * The wire contract of `GET /api/search` — the cross-domain record search the\n * command palette reads.\n *\n * Types only, so both halves can name them: the route handler builds these on\n * the server, and the browser's `searchRecords` returns them. A type crosses the\n * client/server entry split freely because it erases.\n */\n\n/**\n * Why a source produced no group.\n *\n * The split is the point, and it is not cosmetic. `forbidden` and\n * `noActiveOrganization` are the **normal** state for some callers on some\n * sources — an operator holds no membership, so every tenant-plane search\n * answers `409` — and rendering \"we could not reach this\" for the ordinary case\n * teaches an operator to ignore the warning. `timeout`/`network`/`unexpected`\n * are the ones that mean something is actually wrong.\n *\n * Every member is a key in the shared `errors` catalog, so a caller renders one\n * through the documented runtime-key hatch rather than inventing copy.\n */\n/**\n * Why a source produced nothing: the code of the failure it answered with,\n * decoded from its problem body — `noActiveOrganization`, `forbidden`,\n * `upstreamUnavailable` — or `timeout` when it never answered in time. A\n * code, so the browser renders it through the `errors` catalog like any other\n * refusal.\n */\nexport type RecordSearchUnavailableReason = string;\n\n/** One record a caller can show and route to. */\nexport interface RecordSearchOption {\n readonly id: string;\n readonly label: string;\n /**\n * Nothing names this record: {@link label} is its short id, and a caller\n * puts it into words with the entity's noun — \"Order 8a564966\" — the way a\n * table names a record nothing names.\n */\n readonly unnamed?: true;\n /** A secondary line — a code, a role. Absent when the source declared none. */\n readonly sublabel?: string;\n /**\n * `envelopeEntityName(Ctor)` — `key ?? name`.\n *\n * Repeated on every option rather than left to the group, because an option is\n * routed on its own once a caller has flattened the list: `['entity', entity]`\n * is exactly `entityQueryScope`'s output, and `entity:<entity>:<id>` is the\n * workspace tab address.\n */\n readonly entity: string;\n /**\n * Where selecting this record lands, **without** a locale prefix — the caller\n * adds one, the same way every other internal href in the back office works.\n */\n readonly href: string;\n}\n\n/** One source's answer. */\nexport interface RecordSearchGroup {\n /** The source's declared key. Stable, and the caller's ordering. */\n readonly source: string;\n readonly entity: string;\n /**\n * The heading, as the entity's own `pluralKey`. A key rather than copy:\n * the entity catalogs already carry one for every source, so record search\n * introduces no copy of its own. (The search runs in the reader's locale,\n * but only a localized member's value depends on it.)\n */\n readonly labelKey: string;\n readonly items: readonly RecordSearchOption[];\n /**\n * Matches **before** the per-group limit, so \"3 more\" is renderable. A\n * reachable source with no matches is a present group with an empty `items`,\n * never an omission — that distinction is the whole reason\n * {@link RecordSearchResponse.unavailable} exists.\n */\n readonly total: number;\n}\n\n/** One source that produced nothing, and why. */\nexport interface RecordSearchUnavailable {\n readonly source: string;\n readonly entity: string;\n readonly reason: RecordSearchUnavailableReason;\n /** The failure's category: what decides whether this is scope or an outage. */\n readonly category: FailureCategory;\n /** The upstream status, when there was a response. Absent on a throw. */\n readonly status?: number;\n}\n\n/**\n * The whole answer.\n *\n * A degraded source is **named**, never a silently missing group. An empty group\n * is a confident claim that there are no matching records, and a search that\n * confidently reports nothing when it in fact could not look is the failure\n * mode this shape exists to prevent.\n */\nexport interface RecordSearchResponse {\n readonly term: string;\n readonly groups: readonly RecordSearchGroup[];\n readonly unavailable: readonly RecordSearchUnavailable[];\n}\n"],"names":[],"mappings":"AA8FA;;;;;;;CAOC,GACD,WAIC"}
@@ -8,6 +8,8 @@ export interface SearchRecordsOptions {
8
8
  readonly sources?: readonly string[];
9
9
  /** Records per group. */
10
10
  readonly limit?: number;
11
+ /** The reader's locale, which a localized member is searched and read in. */
12
+ readonly locale?: string;
11
13
  }
12
14
  /**
13
15
  * Ask the back office for records matching `term`.
@@ -21,5 +23,5 @@ export interface SearchRecordsOptions {
21
23
  * cross-origin call would carry no session and every group would come back
22
24
  * unavailable.
23
25
  */
24
- export declare const searchRecords: (term: string, { signal, sources, limit }?: SearchRecordsOptions) => Promise<RecordSearchResponse>;
26
+ export declare const searchRecords: (term: string, { signal, sources, limit, locale }?: SearchRecordsOptions) => Promise<RecordSearchResponse>;
25
27
  //# sourceMappingURL=search-records.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search-records.d.ts","sourceRoot":"","sources":["../../../src/lib/search/search-records.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,sFAAsF;AACtF,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,yBAAyB;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,EACZ,6BAA4B,oBAAyB,KACpD,OAAO,CAAC,oBAAoB,CAoB9B,CAAC"}
1
+ {"version":3,"file":"search-records.d.ts","sourceRoot":"","sources":["../../../src/lib/search/search-records.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,sFAAsF;AACtF,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,yBAAyB;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,EACZ,qCAAoC,oBAAyB,KAC5D,OAAO,CAAC,oBAAoB,CAqB9B,CAAC"}
@@ -11,7 +11,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
11
11
  * Same-origin on purpose: `entifix_at` is httpOnly and `sameSite: 'lax'`, so a
12
12
  * cross-origin call would carry no session and every group would come back
13
13
  * unavailable.
14
- */ export const searchRecords = async (term, { signal, sources, limit } = {})=>{
14
+ */ export const searchRecords = async (term, { signal, sources, limit, locale } = {})=>{
15
15
  const params = new URLSearchParams({
16
16
  q: term
17
17
  });
@@ -19,6 +19,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
19
19
  params.set('sources', sources.join(','));
20
20
  }
21
21
  if (limit !== undefined) params.set('limit', String(limit));
22
+ if (locale !== undefined) params.set('locale', locale);
22
23
  const response = await fetch(`${RECORD_SEARCH_PATH}?${params.toString()}`, _extends({
23
24
  cache: 'no-store'
24
25
  }, signal === undefined ? {} : {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/search/search-records.ts"],"sourcesContent":["import type { RecordSearchResponse } from './record-search.types.js';\n\n/** Where the aggregating route is mounted. Same-origin, so the cookie rides along. */\nexport const RECORD_SEARCH_PATH = '/api/search';\n\nexport interface SearchRecordsOptions {\n /** Aborts an in-flight request when the term moves on. */\n readonly signal?: AbortSignal;\n /** Narrow the fan-out to these source keys. Omit to ask every source. */\n readonly sources?: readonly string[];\n /** Records per group. */\n readonly limit?: number;\n}\n\n/**\n * Ask the back office for records matching `term`.\n *\n * Deliberately framework-free — no React, no router, no debounce, no retry. It\n * is a typed `fetch`, so the palette can own its own keystroke policy (which is\n * where debounce and abort belong) and a server component or a test can call the\n * same function.\n *\n * Same-origin on purpose: `entifix_at` is httpOnly and `sameSite: 'lax'`, so a\n * cross-origin call would carry no session and every group would come back\n * unavailable.\n */\nexport const searchRecords = async (\n term: string,\n { signal, sources, limit }: SearchRecordsOptions = {},\n): Promise<RecordSearchResponse> => {\n const params = new URLSearchParams({ q: term });\n if (sources !== undefined && sources.length > 0) {\n params.set('sources', sources.join(','));\n }\n if (limit !== undefined) params.set('limit', String(limit));\n\n const response = await fetch(`${RECORD_SEARCH_PATH}?${params.toString()}`, {\n cache: 'no-store',\n ...(signal === undefined ? {} : { signal }),\n });\n\n if (!response.ok) {\n // The route answers `401` for a lapsed session and `400` for a caller naming\n // a source that does not exist. Neither is a per-source degradation — those\n // arrive inside a `200` — so both are the caller's to handle.\n throw new Error(`record search failed with ${response.status}`);\n }\n\n return (await response.json()) as RecordSearchResponse;\n};\n"],"names":["RECORD_SEARCH_PATH","searchRecords","term","signal","sources","limit","params","URLSearchParams","q","undefined","length","set","join","String","response","fetch","toString","cache","ok","Error","status","json"],"mappings":";AAEA,oFAAoF,GACpF,OAAO,MAAMA,qBAAqB,cAAc;AAWhD;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,gBAAgB,OAC3BC,MACA,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAwB,GAAG,CAAC,CAAC;IAErD,MAAMC,SAAS,IAAIC,gBAAgB;QAAEC,GAAGN;IAAK;IAC7C,IAAIE,YAAYK,aAAaL,QAAQM,MAAM,GAAG,GAAG;QAC/CJ,OAAOK,GAAG,CAAC,WAAWP,QAAQQ,IAAI,CAAC;IACrC;IACA,IAAIP,UAAUI,WAAWH,OAAOK,GAAG,CAAC,SAASE,OAAOR;IAEpD,MAAMS,WAAW,MAAMC,MAAM,GAAGf,mBAAmB,CAAC,EAAEM,OAAOU,QAAQ,IAAI,EAAE;QACzEC,OAAO;OACHd,WAAWM,YAAY,CAAC,IAAI;QAAEN;IAAO;IAG3C,IAAI,CAACW,SAASI,EAAE,EAAE;QAChB,6EAA6E;QAC7E,4EAA4E;QAC5E,8DAA8D;QAC9D,MAAM,IAAIC,MAAM,CAAC,0BAA0B,EAAEL,SAASM,MAAM,EAAE;IAChE;IAEA,OAAQ,MAAMN,SAASO,IAAI;AAC7B,EAAE"}
1
+ {"version":3,"sources":["../../../src/lib/search/search-records.ts"],"sourcesContent":["import type { RecordSearchResponse } from './record-search.types.js';\n\n/** Where the aggregating route is mounted. Same-origin, so the cookie rides along. */\nexport const RECORD_SEARCH_PATH = '/api/search';\n\nexport interface SearchRecordsOptions {\n /** Aborts an in-flight request when the term moves on. */\n readonly signal?: AbortSignal;\n /** Narrow the fan-out to these source keys. Omit to ask every source. */\n readonly sources?: readonly string[];\n /** Records per group. */\n readonly limit?: number;\n /** The reader's locale, which a localized member is searched and read in. */\n readonly locale?: string;\n}\n\n/**\n * Ask the back office for records matching `term`.\n *\n * Deliberately framework-free — no React, no router, no debounce, no retry. It\n * is a typed `fetch`, so the palette can own its own keystroke policy (which is\n * where debounce and abort belong) and a server component or a test can call the\n * same function.\n *\n * Same-origin on purpose: `entifix_at` is httpOnly and `sameSite: 'lax'`, so a\n * cross-origin call would carry no session and every group would come back\n * unavailable.\n */\nexport const searchRecords = async (\n term: string,\n { signal, sources, limit, locale }: SearchRecordsOptions = {},\n): Promise<RecordSearchResponse> => {\n const params = new URLSearchParams({ q: term });\n if (sources !== undefined && sources.length > 0) {\n params.set('sources', sources.join(','));\n }\n if (limit !== undefined) params.set('limit', String(limit));\n if (locale !== undefined) params.set('locale', locale);\n\n const response = await fetch(`${RECORD_SEARCH_PATH}?${params.toString()}`, {\n cache: 'no-store',\n ...(signal === undefined ? {} : { signal }),\n });\n\n if (!response.ok) {\n // The route answers `401` for a lapsed session and `400` for a caller naming\n // a source that does not exist. Neither is a per-source degradation — those\n // arrive inside a `200` — so both are the caller's to handle.\n throw new Error(`record search failed with ${response.status}`);\n }\n\n return (await response.json()) as RecordSearchResponse;\n};\n"],"names":["RECORD_SEARCH_PATH","searchRecords","term","signal","sources","limit","locale","params","URLSearchParams","q","undefined","length","set","join","String","response","fetch","toString","cache","ok","Error","status","json"],"mappings":";AAEA,oFAAoF,GACpF,OAAO,MAAMA,qBAAqB,cAAc;AAahD;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,gBAAgB,OAC3BC,MACA,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,MAAM,EAAwB,GAAG,CAAC,CAAC;IAE7D,MAAMC,SAAS,IAAIC,gBAAgB;QAAEC,GAAGP;IAAK;IAC7C,IAAIE,YAAYM,aAAaN,QAAQO,MAAM,GAAG,GAAG;QAC/CJ,OAAOK,GAAG,CAAC,WAAWR,QAAQS,IAAI,CAAC;IACrC;IACA,IAAIR,UAAUK,WAAWH,OAAOK,GAAG,CAAC,SAASE,OAAOT;IACpD,IAAIC,WAAWI,WAAWH,OAAOK,GAAG,CAAC,UAAUN;IAE/C,MAAMS,WAAW,MAAMC,MAAM,GAAGhB,mBAAmB,CAAC,EAAEO,OAAOU,QAAQ,IAAI,EAAE;QACzEC,OAAO;OACHf,WAAWO,YAAY,CAAC,IAAI;QAAEP;IAAO;IAG3C,IAAI,CAACY,SAASI,EAAE,EAAE;QAChB,6EAA6E;QAC7E,4EAA4E;QAC5E,8DAA8D;QAC9D,MAAM,IAAIC,MAAM,CAAC,0BAA0B,EAAEL,SAASM,MAAM,EAAE;IAChE;IAEA,OAAQ,MAAMN,SAASO,IAAI;AAC7B,EAAE"}