@lde/search 0.31.0 → 0.32.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/adapter.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  export { assertTypeInSchema, physicalFields, irAlias, displayFieldName, displayFieldPattern, displayLangOf, searchableFields, facetableFields, filterableFields, sortableFields, outputFields, isInternalField, isInlineReference, nestedReferenceType, nestedFieldName, localLookupTargetsOf, referencedTargetsOf, storedTargetOf, TARGET_FIELD, identityFieldOf, identityFieldName, inheritedFacetPolicies, referenceFields, referenceTypeNamed, rootTypeNamed, inlineFramingDepth, fieldNamed, datasetField, ID_FIELD, AND_KEY, OR_KEY, labelFieldOf, labelFieldNameOf, labelSourceNamesOf, labelTargetNamesOf, documentKeyOf, DEFAULT_LABEL_FIELD, isRangeFacet, isBinnedRangeFacet, isAbsoluteIri, isoToUnixSeconds, unixSecondsToIso, } from './schema.js';
10
10
  export type { PhysicalFields } from './schema.js';
11
+ export { missingRequiredFields } from './project.js';
11
12
  export { physicalNameTokens } from './physical-name.js';
12
13
  export { matchLanguage } from './language.js';
13
14
  export { joinGraph, MAX_JOIN_DEPTH } from './join-graph.js';
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,YAAY,EACZ,WAAW,GACZ,MAAM,YAAY,CAAC"}
package/dist/adapter.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * this; the main entry point carries that (small) authoring surface.
8
8
  */
9
9
  export { assertTypeInSchema, physicalFields, irAlias, displayFieldName, displayFieldPattern, displayLangOf, searchableFields, facetableFields, filterableFields, sortableFields, outputFields, isInternalField, isInlineReference, nestedReferenceType, nestedFieldName, localLookupTargetsOf, referencedTargetsOf, storedTargetOf, TARGET_FIELD, identityFieldOf, identityFieldName, inheritedFacetPolicies, referenceFields, referenceTypeNamed, rootTypeNamed, inlineFramingDepth, fieldNamed, datasetField, ID_FIELD, AND_KEY, OR_KEY, labelFieldOf, labelFieldNameOf, labelSourceNamesOf, labelTargetNamesOf, documentKeyOf, DEFAULT_LABEL_FIELD, isRangeFacet, isBinnedRangeFacet, isAbsoluteIri, isoToUnixSeconds, unixSecondsToIso, } from './schema.js';
10
+ export { missingRequiredFields } from './project.js';
10
11
  export { physicalNameTokens } from './physical-name.js';
11
12
  export { matchLanguage } from './language.js';
12
13
  export { joinGraph, MAX_JOIN_DEPTH } from './join-graph.js';
package/dist/project.d.ts CHANGED
@@ -57,4 +57,22 @@ export declare function projectDocument(node: FramedNode, searchType: SearchType
57
57
  * array or a chained generator merging several readers.
58
58
  */
59
59
  export declare function projectRoots(quads: Iterable<Quad>, roots: readonly string[], schema: SearchSchema, searchType: RootType, context?: ProjectionContext): AsyncIterable<SearchDocument>;
60
+ /**
61
+ * The `required` fields a projected document
62
+ * lacks, by name – a field of an inline reference’s referent as
63
+ * `reference.field` – or none when it has them all.
64
+ *
65
+ * An engine cannot always hold a document to `required` itself. A text field
66
+ * spreads over a display field per language and a search and sort field per
67
+ * locale, so *a value in some language* is no one physical field it can make
68
+ * mandatory; and a field of a Reference Type is required of every referent,
69
+ * which a flag on a nested engine field cannot say. A writer asks this before
70
+ * it writes, so a document the API would fail to serve is left out instead.
71
+ *
72
+ * An array or boolean field is never missing: the API serves an absent one as
73
+ * empty or false. Neither is a field of a {@link ReferenceStrategy.local local}
74
+ * lookup’s target: the API relaxes `required` there, because a referrer
75
+ * states only what it knows about the endpoint.
76
+ */
77
+ export declare function missingRequiredFields(document: ProjectedNode, searchType: SearchType, schema?: SearchSchema): readonly string[];
60
78
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAGL,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAoBL,KAAK,eAAe,EAIpB,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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H,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAChD,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAC1C;IACC,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,YAAY,EACrB,OAAO,GAAE,iBAAyC,GACjD,cAAc,CAgBhB;AAmLD;;;;;;;;;;;;GAYG;AACH,wBAAuB,YAAY,CACjC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EACrB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,QAAQ,EACpB,OAAO,GAAE,iBAAyC,GACjD,aAAa,CAAC,cAAc,CAAC,CAc/B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,YAAY,GACpB,SAAS,MAAM,EAAE,CAmCnB"}
package/dist/project.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fold } from '@lde/text-normalization';
2
2
  import { matchLanguage } from './language.js';
3
3
  import { buildSubjectIndex, frameSubjects, } from './frame-by-type.js';
4
- import { assertTypeInSchema, displayFieldName, documentKeyOf, fieldNamed, identityFieldOf, inheritedFacetPolicies, inlineFramingDepth, irAlias, isAbsoluteIri, isInternalField, isInlineReference, isoToUnixSeconds, localLookupTargetsOf, physicalFields, referencedTargetsOf, referenceTypeNamed, storedTargetOf, TARGET_FIELD, } from './schema.js';
4
+ import { assertTypeInSchema, displayFieldName, displayLangOf, documentKeyOf, fieldNamed, identityFieldOf, inheritedFacetPolicies, inlineFramingDepth, irAlias, isAbsoluteIri, isInternalField, isInlineReference, isoToUnixSeconds, localLookupTargetsOf, physicalFields, referencedTargetsOf, referenceTypeNamed, storedTargetOf, TARGET_FIELD, } from './schema.js';
5
5
  /** The context a projection runs with when its caller supplied none. */
6
6
  const NO_PROJECTION_CONTEXT = {};
7
7
  /**
@@ -191,6 +191,66 @@ export async function* projectRoots(quads, roots, schema, searchType, context =
191
191
  yield projectDocument(node, searchType, schema, context);
192
192
  }
193
193
  }
194
+ /**
195
+ * The `required` fields a projected document
196
+ * lacks, by name – a field of an inline reference’s referent as
197
+ * `reference.field` – or none when it has them all.
198
+ *
199
+ * An engine cannot always hold a document to `required` itself. A text field
200
+ * spreads over a display field per language and a search and sort field per
201
+ * locale, so *a value in some language* is no one physical field it can make
202
+ * mandatory; and a field of a Reference Type is required of every referent,
203
+ * which a flag on a nested engine field cannot say. A writer asks this before
204
+ * it writes, so a document the API would fail to serve is left out instead.
205
+ *
206
+ * An array or boolean field is never missing: the API serves an absent one as
207
+ * empty or false. Neither is a field of a {@link ReferenceStrategy.local local}
208
+ * lookup’s target: the API relaxes `required` there, because a referrer
209
+ * states only what it knows about the endpoint.
210
+ */
211
+ export function missingRequiredFields(document, searchType, schema) {
212
+ const missing = new Set();
213
+ for (const field of searchType.fields) {
214
+ if (isInternalField(field)) {
215
+ continue;
216
+ }
217
+ if (field.required === true &&
218
+ field.array !== true &&
219
+ field.kind !== 'boolean' &&
220
+ !hasValue(document, field, searchType)) {
221
+ missing.add(field.name);
222
+ }
223
+ const referenceType = schema !== undefined &&
224
+ field.kind === 'reference' &&
225
+ field.ref?.strategy === 'inline'
226
+ ? referenceTypeNamed(schema, field.ref.typeName)
227
+ : undefined;
228
+ const nested = document[field.name];
229
+ if (referenceType === undefined || nested === undefined) {
230
+ continue;
231
+ }
232
+ for (const referent of Array.isArray(nested) ? nested : [nested]) {
233
+ for (const name of missingRequiredFields(referent, referenceType, schema)) {
234
+ missing.add(`${field.name}.${name}`);
235
+ }
236
+ }
237
+ }
238
+ return [...missing];
239
+ }
240
+ /** Whether a projected document carries a value for `field`: for text, in any
241
+ * of the physical fields it spreads over – never in a sibling field whose
242
+ * name only looks like one of them (`title_short` beside `title`). */
243
+ function hasValue(document, field, searchType) {
244
+ if (field.kind !== 'text') {
245
+ return document[field.name] !== undefined;
246
+ }
247
+ const { search, sort } = physicalFields(field);
248
+ return Object.keys(document).some((key) => document[key] !== undefined &&
249
+ (search.includes(key) ||
250
+ sort.includes(key) ||
251
+ (displayLangOf(field, key) !== undefined &&
252
+ fieldNamed(searchType, key) === undefined)));
253
+ }
194
254
  function applyField(document, node, field, searchType, schema, context, nested) {
195
255
  // The three value sources, mutually exclusive by declaration
196
256
  // (`validateSearchType`): a projection value, a computed value, a graph path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/search",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "Engine- and domain-agnostic core for RDF-backed search: a unified declarative field model (SearchField/SearchType/SearchSchema), a neutral query IR, the SearchEngine port with logical result types, and a streaming CONSTRUCT-to-document projection. Bakes in no engine, protocol, or domain.",
5
5
  "repository": {
6
6
  "url": "git+https://github.com/ldelements/lde.git",