ochre-sdk 1.3.25 → 1.3.27

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 (97) hide show
  1. package/dist/categories.d.mts +56 -56
  2. package/dist/categories.mjs +39 -39
  3. package/dist/constants.d.mts +8 -8
  4. package/dist/constants.mjs +6 -6
  5. package/dist/errors.d.mts +12 -12
  6. package/dist/errors.mjs +22 -23
  7. package/dist/fetchers/container-items.d.mts +28 -28
  8. package/dist/fetchers/container-items.mjs +27 -27
  9. package/dist/fetchers/gallery.d.mts +13 -13
  10. package/dist/fetchers/gallery.mjs +2 -2
  11. package/dist/fetchers/item-children.d.mts +12 -12
  12. package/dist/fetchers/item-children.mjs +2 -2
  13. package/dist/fetchers/item-links.d.mts +10 -10
  14. package/dist/fetchers/item-links.mjs +6 -6
  15. package/dist/fetchers/item-locations.d.mts +20 -20
  16. package/dist/fetchers/item-locations.mjs +3 -3
  17. package/dist/fetchers/item-ocr-data.d.mts +23 -23
  18. package/dist/fetchers/item-ocr-data.mjs +44 -44
  19. package/dist/fetchers/item.d.mts +23 -18
  20. package/dist/fetchers/item.mjs +15 -15
  21. package/dist/fetchers/map-layers.d.mts +15 -15
  22. package/dist/fetchers/map-layers.mjs +12 -11
  23. package/dist/fetchers/request.d.mts +40 -40
  24. package/dist/fetchers/request.mjs +37 -37
  25. package/dist/fetchers/set/items.d.mts +15 -15
  26. package/dist/fetchers/set/items.mjs +1 -1
  27. package/dist/fetchers/set/property-values.d.mts +16 -16
  28. package/dist/fetchers/set/property-values.mjs +43 -43
  29. package/dist/fetchers/tree/items.d.mts +27 -27
  30. package/dist/fetchers/tree/items.mjs +1 -1
  31. package/dist/fetchers/website-metadata.d.mts +4 -4
  32. package/dist/fetchers/website-metadata.mjs +9 -9
  33. package/dist/fetchers/website.d.mts +10 -10
  34. package/dist/fetchers/website.mjs +12 -12
  35. package/dist/getters.d.mts +83 -83
  36. package/dist/getters.mjs +74 -74
  37. package/dist/helpers.d.mts +4 -4
  38. package/dist/helpers.mjs +7 -7
  39. package/dist/index.d.mts +3 -3
  40. package/dist/index.mjs +5 -5
  41. package/dist/languages.d.mts +58 -58
  42. package/dist/languages.mjs +21 -21
  43. package/dist/ocr.d.mts +27 -27
  44. package/dist/ocr.mjs +29 -29
  45. package/dist/parsers/helpers.d.mts +23 -23
  46. package/dist/parsers/helpers.mjs +8 -8
  47. package/dist/parsers/index.d.mts +2 -2
  48. package/dist/parsers/index.mjs +15 -15
  49. package/dist/parsers/languages.d.mts +49 -49
  50. package/dist/parsers/languages.mjs +49 -49
  51. package/dist/parsers/multilingual.d.mts +174 -174
  52. package/dist/parsers/multilingual.mjs +146 -146
  53. package/dist/parsers/partial-date.d.mts +12 -12
  54. package/dist/parsers/partial-date.mjs +11 -11
  55. package/dist/parsers/property-token.d.mts +20 -20
  56. package/dist/parsers/property-token.mjs +16 -16
  57. package/dist/parsers/string.d.mts +33 -33
  58. package/dist/parsers/string.mjs +62 -64
  59. package/dist/parsers/website/bounds.d.mts +6 -6
  60. package/dist/parsers/website/bounds.mjs +5 -5
  61. package/dist/parsers/website/components.d.mts +46 -31
  62. package/dist/parsers/website/components.mjs +84 -51
  63. package/dist/parsers/website/index.d.mts +2 -2
  64. package/dist/parsers/website/index.mjs +45 -48
  65. package/dist/parsers/website/links.d.mts +24 -24
  66. package/dist/parsers/website/links.mjs +18 -18
  67. package/dist/parsers/website/messages.d.mts +16 -16
  68. package/dist/parsers/website/messages.mjs +14 -14
  69. package/dist/parsers/website/options.d.mts +1 -1
  70. package/dist/parsers/website/properties.d.mts +17 -8
  71. package/dist/parsers/website/properties.mjs +31 -10
  72. package/dist/parsers/website/reader.d.mts +55 -47
  73. package/dist/parsers/website/reader.mjs +66 -51
  74. package/dist/parsers/website/slug.d.mts +50 -50
  75. package/dist/parsers/website/slug.mjs +36 -36
  76. package/dist/parsers/website/styles.d.mts +18 -18
  77. package/dist/parsers/website/styles.mjs +19 -19
  78. package/dist/parsers/website/walk.d.mts +46 -46
  79. package/dist/parsers/website/walk.mjs +34 -34
  80. package/dist/query.d.mts +63 -63
  81. package/dist/query.mjs +137 -140
  82. package/dist/reflection.d.mts +51 -51
  83. package/dist/reflection.mjs +45 -45
  84. package/dist/schemas.d.mts +44 -44
  85. package/dist/schemas.mjs +50 -50
  86. package/dist/types/index.d.mts +192 -192
  87. package/dist/types/utilities.d.mts +5 -5
  88. package/dist/types/website.d.mts +74 -62
  89. package/dist/xml/dates.d.mts +9 -9
  90. package/dist/xml/dates.mjs +9 -9
  91. package/dist/xml/metadata.d.mts +14 -14
  92. package/dist/xml/metadata.mjs +18 -18
  93. package/dist/xml/schemas.mjs +24 -24
  94. package/dist/xml/types.d.mts +9 -9
  95. package/dist/xquery.d.mts +49 -49
  96. package/dist/xquery.mjs +50 -50
  97. package/package.json +10 -10
package/dist/query.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BELONGS_TO_COLLECTION_UUID } from "./constants.mjs";
2
- import { OCHRE_RESPONSE_PADDING, compileOchreQuery, stringLiteral } from "./xquery.mjs";
3
2
  import { OCR_WORD_CONTENT_ATTRIBUTE, OCR_WORD_QNAMES, buildOcrWordPath } from "./ocr.mjs";
3
+ import { OCHRE_RESPONSE_PADDING, compileOchreQuery, stringLiteral } from "./xquery.mjs";
4
4
  // src/query.ts
5
5
  const CTS_INCLUDES_STOP_WORDS = /* @__PURE__ */ new Set([
6
6
  "and",
@@ -88,9 +88,7 @@ function shouldUseFullValueFallbackForIncludes(parameters) {
88
88
  if (rawSpaceTerms.length !== terms.length) return true;
89
89
  for (const rawTerm of rawSpaceTerms) {
90
90
  const wildcardStrippedTerm = getWildcardStrippedValue(rawTerm);
91
- if (hasWildcardCharacters(rawTerm)) return true;
92
- if (!CTS_INCLUDES_TOKEN_WORD_REGEX.test(wildcardStrippedTerm)) return true;
93
- if (CTS_INCLUDES_STOP_WORDS.has(rawTerm.toLowerCase())) return true;
91
+ if (hasWildcardCharacters(rawTerm) || !CTS_INCLUDES_TOKEN_WORD_REGEX.test(wildcardStrippedTerm) || CTS_INCLUDES_STOP_WORDS.has(rawTerm.toLowerCase())) return true;
94
92
  }
95
93
  for (const [index, rawTerm] of rawSpaceTerms.entries()) if (rawTerm !== (terms[index] ?? "")) return true;
96
94
  return false;
@@ -240,12 +238,12 @@ function buildValueIdReferenceQuery() {
240
238
  });
241
239
  }
242
240
  /**
243
- * Match a field's `content` in a language, falling back to another language
244
- * only for fields that carry no content in the first one
245
- *
246
- * Placed inside the field element (a label, a note, a property value), so the
247
- * missing-language check is scoped to that one field. Without a distinct
248
- * fallback it is the single-language query this always compiled to.
241
+ Match a field's `content` in a language, falling back to another language
242
+ only for fields that carry no content in the first one
243
+
244
+ Placed inside the field element (a label, a note, a property value), so the
245
+ missing-language check is scoped to that one field. Without a distinct
246
+ fallback it is the single-language query this always compiled to.
249
247
  */
250
248
  function buildLocalizedContentQueryExpression(parameters) {
251
249
  const { language, fallbackLanguage, buildMatchQuery } = parameters;
@@ -519,10 +517,10 @@ function tokenizeOcrExactValue(value) {
519
517
  return terms;
520
518
  }
521
519
  /**
522
- * Word queries against the OCR layer cannot carry a stemming option: the OCHRE
523
- * database has unstemmed word searches turned off, and asking a word query for
524
- * `unstemmed` fails with `XDMP-WORDSEARCH`. Omitting the option altogether
525
- * resolves the term against the database default instead.
520
+ Word queries against the OCR layer cannot carry a stemming option: the OCHRE
521
+ database has unstemmed word searches turned off, and asking a word query for
522
+ `unstemmed` fails with `XDMP-WORDSEARCH`. Omitting the option altogether
523
+ resolves the term against the database default instead.
526
524
  */
527
525
  function buildOcrWordQueryExpression(parameters) {
528
526
  const { value, isCaseSensitive } = parameters;
@@ -543,21 +541,21 @@ function buildOcrValueQueryExpression(parameters) {
543
541
  })})`;
544
542
  }
545
543
  /**
546
- * Compile an OCR text search into a query over the `<ocr>` layers of a
547
- * Resource document
548
- *
549
- * Each word node in a layer holds a single OCR word in its `CONTENT`
550
- * attribute, so `includes` matches every search term as a word inside that
551
- * attribute, and `exact` requires every term to equal a whole `CONTENT` value.
552
- * A Resource carries one layer per page, so each term is its own element query
553
- * and the terms may fall on different pages, which is also all the indexes can
554
- * tell apart.
555
- *
556
- * The conjunction is only an index narrowing for `exact`. Attribute values
557
- * carry no word positions, so `cts:near-query` over them silently degenerates
558
- * into a conjunction and cannot express a phrase at all. Word order and
559
- * adjacency are instead enforced by {@link registerOcrPhraseHelper} over the
560
- * documents this narrowing returns.
544
+ Compile an OCR text search into a query over the `<ocr>` layers of a
545
+ Resource document
546
+
547
+ Each word node in a layer holds a single OCR word in its `CONTENT`
548
+ attribute, so `includes` matches every search term as a word inside that
549
+ attribute, and `exact` requires every term to equal a whole `CONTENT` value.
550
+ A Resource carries one layer per page, so each term is its own element query
551
+ and the terms may fall on different pages, which is also all the indexes can
552
+ tell apart.
553
+
554
+ The conjunction is only an index narrowing for `exact`. Attribute values
555
+ carry no word positions, so `cts:near-query` over them silently degenerates
556
+ into a conjunction and cannot express a phrase at all. Word order and
557
+ adjacency are instead enforced by {@link registerOcrPhraseHelper} over the
558
+ documents this narrowing returns.
561
559
  */
562
560
  function buildOcrQueryExpression(query) {
563
561
  const { value, matchMode, isCaseSensitive } = query;
@@ -573,8 +571,8 @@ function buildOcrQueryExpression(query) {
573
571
  }))));
574
572
  }
575
573
  /**
576
- * Declare the filter that holds an `exact` multi-term search to a run of
577
- * adjacent OCR words, which no CTS query over the layer can express
574
+ Declare the filter that holds an `exact` multi-term search to a run of
575
+ adjacent OCR words, which no CTS query over the layer can express
578
576
  */
579
577
  function registerOcrPhraseHelper(context) {
580
578
  const helperName = "local:ocrHasPhrase";
@@ -598,8 +596,8 @@ function registerOcrPhraseHelper(context) {
598
596
  return helperName;
599
597
  }
600
598
  /**
601
- * Bind the UUIDs of the Resource documents whose OCR layer matches a query,
602
- * reusing the binding when the same search is requested more than once
599
+ Bind the UUIDs of the Resource documents whose OCR layer matches a query,
600
+ reusing the binding when the same search is requested more than once
603
601
  */
604
602
  function registerOcrBinding(context, query) {
605
603
  const key = [
@@ -710,9 +708,8 @@ function buildLeafValueQueryExpression(parameters) {
710
708
  }
711
709
  }
712
710
  }
713
- function indentBlock(value, spaces) {
714
- const prefix = " ".repeat(spaces);
715
- return value.split("\n").map((line) => line === "" ? line : `${prefix}${line}`).join("\n");
711
+ function indentBlock(value) {
712
+ return value.split("\n").map((line) => line === "" ? line : ` ${line}`).join("\n");
716
713
  }
717
714
  function createQueryCompilerContext(baseItemsExpression) {
718
715
  return {
@@ -734,7 +731,7 @@ function registerConstantHelper(parameters) {
734
731
  const helperName = `local:queryHelper${context.nextHelperSerial}`;
735
732
  context.nextHelperSerial += 1;
736
733
  context.helperNamesByKey.set(key, helperName);
737
- context.helperDeclarations.push(`declare function ${helperName}() as cts:query {\n${indentBlock(bodyExpression, 2)}\n};`);
734
+ context.helperDeclarations.push(`declare function ${helperName}() as cts:query {\n${indentBlock(bodyExpression)}\n};`);
738
735
  return {
739
736
  name: helperName,
740
737
  callExpression: `${helperName}()`
@@ -750,7 +747,7 @@ function registerParameterizedHelper(parameters) {
750
747
  const helperName = `local:queryHelper${context.nextHelperSerial}`;
751
748
  context.nextHelperSerial += 1;
752
749
  context.helperNamesByKey.set(key, helperName);
753
- context.helperDeclarations.push(`declare function ${helperName}($value as xs:string) as cts:query {\n${indentBlock(bodyExpression, 2)}\n};`);
750
+ context.helperDeclarations.push(`declare function ${helperName}($value as xs:string) as cts:query {\n${indentBlock(bodyExpression)}\n};`);
754
751
  return {
755
752
  name: helperName,
756
753
  call: (valueExpression) => `${helperName}(${valueExpression})`
@@ -982,13 +979,13 @@ function buildCtsItemsPlan(queryExpression) {
982
979
  };
983
980
  }
984
981
  /**
985
- * Plan a leaf that falls back to a second language for fields missing the first
986
- *
987
- * The strict query needs a `cts:not-query` scoped to one field, which CTS
988
- * resolves against the Set's single fragment and so rules out every item the
989
- * moment any item holds the first language. The search therefore runs a
990
- * superset (the leaf in either language), and `cts:contains` then applies the
991
- * strict query to each matched item projection, where the negation is exact.
982
+ Plan a leaf that falls back to a second language for fields missing the first
983
+
984
+ The strict query needs a `cts:not-query` scoped to one field, which CTS
985
+ resolves against the Set's single fragment and so rules out every item the
986
+ moment any item holds the first language. The search therefore runs a
987
+ superset (the leaf in either language), and `cts:contains` then applies the
988
+ strict query to each matched item projection, where the negation is exact.
992
989
  */
993
990
  function buildFallbackItemsPlan(parameters) {
994
991
  const { supersetQueryExpression, strictQueryExpression } = parameters;
@@ -1000,14 +997,14 @@ function buildFallbackItemsPlan(parameters) {
1000
997
  };
1001
998
  }
1002
999
  /**
1003
- * Plan a negated leaf as an item path predicate
1004
- *
1005
- * A Set holds every one of its items in one fragment, and CTS resolves
1006
- * `cts:not-query` from the fragment indexes without filtering the match down to
1007
- * the node it came from. Negating inside the search query would therefore drop
1008
- * every item of a Set as soon as one of them matched, and keep every item of a
1009
- * Set that held no match at all. `cts:contains` evaluates the leaf against one
1010
- * item projection instead, which is the scope the negation is asking about.
1000
+ Plan a negated leaf as an item path predicate
1001
+
1002
+ A Set holds every one of its items in one fragment, and CTS resolves
1003
+ `cts:not-query` from the fragment indexes without filtering the match down to
1004
+ the node it came from. Negating inside the search query would therefore drop
1005
+ every item of a Set as soon as one of them matched, and keep every item of a
1006
+ Set that held no match at all. `cts:contains` evaluates the leaf against one
1007
+ item projection instead, which is the scope the negation is asking about.
1011
1008
  */
1012
1009
  function buildNegatedItemsPlan(queryExpression) {
1013
1010
  return {
@@ -1018,8 +1015,8 @@ function buildNegatedItemsPlan(queryExpression) {
1018
1015
  };
1019
1016
  }
1020
1017
  /**
1021
- * Splice the children of same-kind child plans into their parent, so that a
1022
- * nested group of the same operator does not cost an extra search
1018
+ Splice the children of same-kind child plans into their parent, so that a
1019
+ nested group of the same operator does not cost an extra search
1023
1020
  */
1024
1021
  function flattenItemsPlans(childPlans, kind) {
1025
1022
  const flattenedPlans = [];
@@ -1036,11 +1033,11 @@ function appendUniquePredicates(predicates, addedPredicates) {
1036
1033
  for (const predicate of addedPredicates) if (!predicates.includes(predicate)) predicates.push(predicate);
1037
1034
  }
1038
1035
  /**
1039
- * Fold the children of an `and` group into one plan
1040
- *
1041
- * Conjunction is the direction the item path predicates already run in, so
1042
- * every child that is a plain search collapses into a single search, and only
1043
- * the children that resolved to a union stay separate.
1036
+ Fold the children of an `and` group into one plan
1037
+
1038
+ Conjunction is the direction the item path predicates already run in, so
1039
+ every child that is a plain search collapses into a single search, and only
1040
+ the children that resolved to a union stay separate.
1044
1041
  */
1045
1042
  function buildAndItemsPlan(childPlans) {
1046
1043
  const mergedPlan = {
@@ -1067,10 +1064,10 @@ function buildAndItemsPlan(childPlans) {
1067
1064
  };
1068
1065
  }
1069
1066
  /**
1070
- * Fold the children of an `or` group into one plan
1071
- *
1072
- * Item path predicates cannot be disjoined, so a child carrying one becomes its
1073
- * own arm of a node union. Everything else is still a single CTS query.
1067
+ Fold the children of an `or` group into one plan
1068
+
1069
+ Item path predicates cannot be disjoined, so a child carrying one becomes its
1070
+ own arm of a node union. Everything else is still a single CTS query.
1074
1071
  */
1075
1072
  function buildOrItemsPlan(childPlans) {
1076
1073
  const mergedQueryExpressions = [];
@@ -1158,43 +1155,43 @@ function buildBelongsToCollectionQueryExpression(belongsToCollectionScopeUuids,
1158
1155
  });
1159
1156
  }
1160
1157
  /**
1161
- * Compile a query tree into the XQuery `let` clauses that bind `$items` to the
1162
- * matching Set items
1163
- *
1164
- * Most queries compile to a single `cts:search` over the Set item projections.
1165
- * An `ocr` leaf cannot: the projections drop the `<ocr>` layer, so it resolves
1166
- * to a search over the Resource documents whose matching UUIDs are joined back
1167
- * in as an item path predicate. A negated leaf cannot either, because CTS
1168
- * answers a negation for the whole fragment rather than for the item that
1169
- * matched, so it is filtered per item instead. Path predicates only ever AND,
1170
- * so such a leaf that sits under an `or` becomes its own arm of a node union
1171
- * instead, and one that sits under an `and` alongside a union becomes an
1172
- * intersection.
1173
- *
1174
- * The searchable path has to stay inline in `cts:search`: binding it to a
1175
- * variable first makes every query XDMP-UNSEARCHABLE.
1176
- * @param parameters - The parameters for the compilation
1177
- * @param parameters.queries - Recursive query tree to compile, if any
1178
- * @param parameters.baseItemsExpression - The inline XQuery path selecting the items to search
1179
- * @param parameters.scopeQueryExpression - An optional CTS query ANDed into every compiled search
1180
- * @returns The prolog declaring the query helpers, and the `let` clauses binding `$items`
1158
+ Compile a query tree into the XQuery `let` clauses that bind `$items` to the
1159
+ matching Set items
1160
+
1161
+ Most queries compile to a single `cts:search` over the Set item projections.
1162
+ An `ocr` leaf cannot: the projections drop the `<ocr>` layer, so it resolves
1163
+ to a search over the Resource documents whose matching UUIDs are joined back
1164
+ in as an item path predicate. A negated leaf cannot either, because CTS
1165
+ answers a negation for the whole fragment rather than for the item that
1166
+ matched, so it is filtered per item instead. Path predicates only ever AND,
1167
+ so such a leaf that sits under an `or` becomes its own arm of a node union
1168
+ instead, and one that sits under an `and` alongside a union becomes an
1169
+ intersection.
1170
+
1171
+ The searchable path has to stay inline in `cts:search`: binding it to a
1172
+ variable first makes every query XDMP-UNSEARCHABLE.
1173
+ @param parameters - The parameters for the compilation
1174
+ @param parameters.queries - Recursive query tree to compile, if any
1175
+ @param parameters.baseItemsExpression - The inline XQuery path selecting the items to search
1176
+ @param parameters.scopeQueryExpression - An optional CTS query ANDed into every compiled search
1177
+ @returns The prolog declaring the query helpers, and the `let` clauses binding `$items`
1181
1178
  */
1182
1179
  const ITEMS_VARIABLE = "$items";
1183
1180
  /**
1184
- * The scope variable and searchable path of each item container
1185
- *
1186
- * A path has to stay inline in `cts:search`: binding it to a variable first
1187
- * materializes the sequence and makes every query `XDMP-UNSEARCHABLE`, even a
1188
- * plain word query. Each references its own scope variable, which
1189
- * {@link compileContainerItemsQuery} declares.
1190
- *
1191
- * A Tree nests its items under headings to any depth, so its path walks the
1192
- * descendant axis and then keeps only the nodes a heading or `items` holds
1193
- * directly, which is what distinguishes an item from the elements inside one.
1194
- * Excluding `heading` matters twice: a heading is not an item, and searching
1195
- * over headings would match every item under a heading whose own text matches.
1196
- * The union form `items/(* | heading/*)` is deliberately not used, because
1197
- * MarkLogic rejects a union as `XDMP-UNSEARCHABLE`.
1181
+ The scope variable and searchable path of each item container
1182
+
1183
+ A path has to stay inline in `cts:search`: binding it to a variable first
1184
+ materializes the sequence and makes every query `XDMP-UNSEARCHABLE`, even a
1185
+ plain word query. Each references its own scope variable, which
1186
+ {@link compileContainerItemsQuery} declares.
1187
+
1188
+ A Tree nests its items under headings to any depth, so its path walks the
1189
+ descendant axis and then keeps only the nodes a heading or `items` holds
1190
+ directly, which is what distinguishes an item from the elements inside one.
1191
+ Excluding `heading` matters twice: a heading is not an item, and searching
1192
+ over headings would match every item under a heading whose own text matches.
1193
+ The union form `items/(* | heading/*)` is deliberately not used, because
1194
+ MarkLogic rejects a union as `XDMP-UNSEARCHABLE`.
1198
1195
  */
1199
1196
  const ITEMS_CONTAINERS = {
1200
1197
  set: {
@@ -1207,18 +1204,18 @@ const ITEMS_CONTAINERS = {
1207
1204
  }
1208
1205
  };
1209
1206
  /**
1210
- * Compile a query tree into the clauses that bind the matching Set items
1211
- *
1212
- * The returned `itemsClause` binds {@link ITEMS_VARIABLE} and has to be placed
1213
- * inside an XQuery body, with `prolog` declared ahead of it.
1214
- * {@link compileContainerItemsQuery} does both and is what fetchers should use;
1215
- * this is exposed for tests that assert on the compiled CTS.
1216
- * @param parameters - The plan parameters
1217
- * @param parameters.queries - The query tree to compile, or null to match every item
1218
- * @param parameters.baseItemsExpression - The inline searchable path to filter
1219
- * @param parameters.scopeQueryExpression - An extra query AND-ed into every search
1220
- * @returns The prolog, the clauses binding the items, and the bound CTS queries
1221
- * @internal
1207
+ Compile a query tree into the clauses that bind the matching Set items
1208
+
1209
+ The returned `itemsClause` binds {@link ITEMS_VARIABLE} and has to be placed
1210
+ inside an XQuery body, with `prolog` declared ahead of it.
1211
+ {@link compileContainerItemsQuery} does both and is what fetchers should use;
1212
+ this is exposed for tests that assert on the compiled CTS.
1213
+ @param parameters - The plan parameters
1214
+ @param parameters.queries - The query tree to compile, or null to match every item
1215
+ @param parameters.baseItemsExpression - The inline searchable path to filter
1216
+ @param parameters.scopeQueryExpression - An extra query AND-ed into every search
1217
+ @returns The prolog, the clauses binding the items, and the bound CTS queries
1218
+ @internal
1222
1219
  */
1223
1220
  function buildQueryPlan(parameters) {
1224
1221
  const { queries, baseItemsExpression, scopeQueryExpression } = parameters;
@@ -1264,24 +1261,24 @@ function buildQueryPlan(parameters) {
1264
1261
  };
1265
1262
  }
1266
1263
  /**
1267
- * Compile an item query over a Set or a Tree into a complete XQuery document
1268
- *
1269
- * Owns everything a caller would otherwise have to know and restate: the
1270
- * version declaration, the scope variable, the supplemental-stripping prolog,
1271
- * the inline searchable path for the container, where the compiled helper
1272
- * prolog goes and that it is only declared when non-empty, the `<ochre>`
1273
- * wrapper, and the name of the variable holding the matching items. The body
1274
- * receives that name, so it is identical for either container.
1275
- * @param parameters - The query parameters
1276
- * @param parameters.container - Whether the scope UUIDs name Sets or Trees
1277
- * @param parameters.scopeUuids - The container UUIDs to search within
1278
- * @param parameters.belongsToCollectionScopeUuids - Collection scope UUIDs to narrow to
1279
- * @param parameters.queries - The query tree to compile, or null to match every item
1280
- * @param parameters.declarations - Extra prolog declarations, placed before the compiled prolog
1281
- * @param parameters.body - Builds the body from the name of the variable holding the items
1282
- * @param parameters.contentLanguage - Keep only this language of every multilingual field in the result
1283
- * @returns A complete XQuery document
1284
- * @internal
1264
+ Compile an item query over a Set or a Tree into a complete XQuery document
1265
+
1266
+ Owns everything a caller would otherwise have to know and restate: the
1267
+ version declaration, the scope variable, the supplemental-stripping prolog,
1268
+ the inline searchable path for the container, where the compiled helper
1269
+ prolog goes and that it is only declared when non-empty, the `<ochre>`
1270
+ wrapper, and the name of the variable holding the matching items. The body
1271
+ receives that name, so it is identical for either container.
1272
+ @param parameters - The query parameters
1273
+ @param parameters.container - Whether the scope UUIDs name Sets or Trees
1274
+ @param parameters.scopeUuids - The container UUIDs to search within
1275
+ @param parameters.belongsToCollectionScopeUuids - Collection scope UUIDs to narrow to
1276
+ @param parameters.queries - The query tree to compile, or null to match every item
1277
+ @param parameters.declarations - Extra prolog declarations, placed before the compiled prolog
1278
+ @param parameters.body - Builds the body from the name of the variable holding the items
1279
+ @param parameters.contentLanguage - Keep only this language of every multilingual field in the result
1280
+ @returns A complete XQuery document
1281
+ @internal
1285
1282
  */
1286
1283
  function compileContainerItemsQuery(parameters) {
1287
1284
  const { container, scopeUuids, belongsToCollectionScopeUuids, queries, declarations = [], body, contentLanguage } = parameters;
@@ -1308,14 +1305,14 @@ ${body({
1308
1305
  });
1309
1306
  }
1310
1307
  /**
1311
- * Reduce a property-value facet query tree to the leaves that filter items
1312
- *
1313
- * A facet request carries property leaves that name a variable without naming
1314
- * a value, which select what to aggregate rather than which items to keep.
1315
- * Those are dropped, and groups left with a single child collapse into it.
1316
- * @param queries - The query tree to reduce
1317
- * @returns The reduced tree, or null when nothing filters items
1318
- * @internal
1308
+ Reduce a property-value facet query tree to the leaves that filter items
1309
+
1310
+ A facet request carries property leaves that name a variable without naming
1311
+ a value, which select what to aggregate rather than which items to keep.
1312
+ Those are dropped, and groups left with a single child collapse into it.
1313
+ @param queries - The query tree to reduce
1314
+ @returns The reduced tree, or null when nothing filters items
1315
+ @internal
1319
1316
  */
1320
1317
  function getItemFilterQueries(queries) {
1321
1318
  if (queries == null) return null;
@@ -1332,10 +1329,10 @@ function getItemFilterQueries(queries) {
1332
1329
  return getQueryGroupOperator(queries) === "and" ? { and: filteredChildren } : { or: filteredChildren };
1333
1330
  }
1334
1331
  /**
1335
- * Collect the property variables a query tree asks to be aggregated
1336
- * @param queries - The query tree to walk
1337
- * @returns One selector per distinct property variable and relation pair
1338
- * @internal
1332
+ Collect the property variables a query tree asks to be aggregated
1333
+ @param queries - The query tree to walk
1334
+ @returns One selector per distinct property variable and relation pair
1335
+ @internal
1339
1336
  */
1340
1337
  function getPropertyFacetSelectors(queries) {
1341
1338
  if (queries == null) return [];
@@ -1,62 +1,62 @@
1
1
  /**
2
- * Reading values whose shape is not known at compile time
3
- *
4
- * The SDK used to do this with five copies of a
5
- * `value is Record<string, unknown>` predicate over
6
- * `typeof value === "object" && value != null`. That predicate lies three ways:
7
- * it is true for arrays, `Date`, `Map` and every other object; it claims a
8
- * string index signature the value does not have, so every read produces
9
- * `unknown` and callers add a second cast to get anything out of it; and being
10
- * an `&&` of unrelated checks, its `false` branch does not mean "not a record",
11
- * which is what a type predicate promises.
12
- *
13
- * These take `unknown` and hand back `unknown`. They assert nothing they have
14
- * not checked, so the one unavoidable cast at the boundary lives here instead
15
- * of being repeated at every call site. Where the shape *is* known, validate it
16
- * with a valibot schema and `v.is` rather than reaching for these.
17
- */
2
+ Reading values whose shape is not known at compile time
3
+
4
+ The SDK used to do this with five copies of a
5
+ `value is Record<string, unknown>` predicate over
6
+ `typeof value === "object" && value != null`. That predicate lies three ways:
7
+ it is true for arrays, `Date`, `Map` and every other object; it claims a
8
+ string index signature the value does not have, so every read produces
9
+ `unknown` and callers add a second cast to get anything out of it; and being
10
+ an `&&` of unrelated checks, its `false` branch does not mean "not a record",
11
+ which is what a type predicate promises.
12
+
13
+ These take `unknown` and hand back `unknown`. They assert nothing they have
14
+ not checked, so the one unavoidable cast at the boundary lives here instead
15
+ of being repeated at every call site. Where the shape *is* known, validate it
16
+ with a valibot schema and `v.is` rather than reaching for these.
17
+ */
18
18
  /**
19
- * Whether a value is a non-null object
20
- *
21
- * Narrows to `object`, which is honest: arrays, `Date` and class instances are
22
- * objects too. Callers that need to tell them apart still have to ask.
23
- * @param value - The value to test
24
- * @returns True when the value is a non-null object
25
- * @internal
26
- */
19
+ Whether a value is a non-null object
20
+
21
+ Narrows to `object`, which is honest: arrays, `Date` and class instances are
22
+ objects too. Callers that need to tell them apart still have to ask.
23
+ @param value - The value to test
24
+ @returns True when the value is a non-null object
25
+ @internal
26
+ */
27
27
  export declare function isObject(value: unknown): value is object;
28
28
  /**
29
- * Read one property from a value of unknown shape
30
- *
31
- * Uses `Reflect.get`, so there is no cast: a missing property, a non-object and
32
- * a property holding `undefined` are all `undefined`, and the caller has to
33
- * narrow whatever comes back.
34
- * @param value - The value to read from
35
- * @param key - The property to read
36
- * @returns The property value, or undefined when there is none
37
- * @internal
38
- */
29
+ Read one property from a value of unknown shape
30
+
31
+ Uses `Reflect.get`, so there is no cast: a missing property, a non-object and
32
+ a property holding `undefined` are all `undefined`, and the caller has to
33
+ narrow whatever comes back.
34
+ @param value - The value to read from
35
+ @param key - The property to read
36
+ @returns The property value, or undefined when there is none
37
+ @internal
38
+ */
39
39
  export declare function readProperty(value: unknown, key: PropertyKey): unknown;
40
40
  /**
41
- * Read the own enumerable string-keyed entries of a value of unknown shape
42
- * @param value - The value to read from
43
- * @returns The entries, or an empty array when the value is not an object
44
- * @internal
45
- */
41
+ Read the own enumerable string-keyed entries of a value of unknown shape
42
+ @param value - The value to read from
43
+ @returns The entries, or an empty array when the value is not an object
44
+ @internal
45
+ */
46
46
  export declare function readEntries(value: unknown): Array<[string, unknown]>;
47
47
  /**
48
- * Read a property that should hold an array, from a value of unknown shape
49
- * @param value - The value to read from
50
- * @param key - The property to read
51
- * @returns The array, or an empty array when the property is absent or not one
52
- * @internal
53
- */
48
+ Read a property that should hold an array, from a value of unknown shape
49
+ @param value - The value to read from
50
+ @param key - The property to read
51
+ @returns The array, or an empty array when the property is absent or not one
52
+ @internal
53
+ */
54
54
  export declare function readArrayProperty(value: unknown, key: PropertyKey): ReadonlyArray<unknown>;
55
55
  /**
56
- * Read a property that should hold a string, from a value of unknown shape
57
- * @param value - The value to read from
58
- * @param key - The property to read
59
- * @returns The string, or null when the property is absent or not one
60
- * @internal
61
- */
56
+ Read a property that should hold a string, from a value of unknown shape
57
+ @param value - The value to read from
58
+ @param key - The property to read
59
+ @returns The string, or null when the property is absent or not one
60
+ @internal
61
+ */
62
62
  export declare function readStringProperty(value: unknown, key: PropertyKey): string | null;
@@ -1,75 +1,75 @@
1
1
  // src/reflection.ts
2
2
  /**
3
- * Reading values whose shape is not known at compile time
4
- *
5
- * The SDK used to do this with five copies of a
6
- * `value is Record<string, unknown>` predicate over
7
- * `typeof value === "object" && value != null`. That predicate lies three ways:
8
- * it is true for arrays, `Date`, `Map` and every other object; it claims a
9
- * string index signature the value does not have, so every read produces
10
- * `unknown` and callers add a second cast to get anything out of it; and being
11
- * an `&&` of unrelated checks, its `false` branch does not mean "not a record",
12
- * which is what a type predicate promises.
13
- *
14
- * These take `unknown` and hand back `unknown`. They assert nothing they have
15
- * not checked, so the one unavoidable cast at the boundary lives here instead
16
- * of being repeated at every call site. Where the shape *is* known, validate it
17
- * with a valibot schema and `v.is` rather than reaching for these.
3
+ Reading values whose shape is not known at compile time
4
+
5
+ The SDK used to do this with five copies of a
6
+ `value is Record<string, unknown>` predicate over
7
+ `typeof value === "object" && value != null`. That predicate lies three ways:
8
+ it is true for arrays, `Date`, `Map` and every other object; it claims a
9
+ string index signature the value does not have, so every read produces
10
+ `unknown` and callers add a second cast to get anything out of it; and being
11
+ an `&&` of unrelated checks, its `false` branch does not mean "not a record",
12
+ which is what a type predicate promises.
13
+
14
+ These take `unknown` and hand back `unknown`. They assert nothing they have
15
+ not checked, so the one unavoidable cast at the boundary lives here instead
16
+ of being repeated at every call site. Where the shape *is* known, validate it
17
+ with a valibot schema and `v.is` rather than reaching for these.
18
18
  */
19
19
  /**
20
- * Whether a value is a non-null object
21
- *
22
- * Narrows to `object`, which is honest: arrays, `Date` and class instances are
23
- * objects too. Callers that need to tell them apart still have to ask.
24
- * @param value - The value to test
25
- * @returns True when the value is a non-null object
26
- * @internal
20
+ Whether a value is a non-null object
21
+
22
+ Narrows to `object`, which is honest: arrays, `Date` and class instances are
23
+ objects too. Callers that need to tell them apart still have to ask.
24
+ @param value - The value to test
25
+ @returns True when the value is a non-null object
26
+ @internal
27
27
  */
28
28
  function isObject(value) {
29
29
  return typeof value === "object" && value !== null;
30
30
  }
31
31
  /**
32
- * Read one property from a value of unknown shape
33
- *
34
- * Uses `Reflect.get`, so there is no cast: a missing property, a non-object and
35
- * a property holding `undefined` are all `undefined`, and the caller has to
36
- * narrow whatever comes back.
37
- * @param value - The value to read from
38
- * @param key - The property to read
39
- * @returns The property value, or undefined when there is none
40
- * @internal
32
+ Read one property from a value of unknown shape
33
+
34
+ Uses `Reflect.get`, so there is no cast: a missing property, a non-object and
35
+ a property holding `undefined` are all `undefined`, and the caller has to
36
+ narrow whatever comes back.
37
+ @param value - The value to read from
38
+ @param key - The property to read
39
+ @returns The property value, or undefined when there is none
40
+ @internal
41
41
  */
42
42
  function readProperty(value, key) {
43
43
  if (!isObject(value)) return;
44
44
  return Reflect.get(value, key);
45
45
  }
46
46
  /**
47
- * Read the own enumerable string-keyed entries of a value of unknown shape
48
- * @param value - The value to read from
49
- * @returns The entries, or an empty array when the value is not an object
50
- * @internal
47
+ Read the own enumerable string-keyed entries of a value of unknown shape
48
+ @param value - The value to read from
49
+ @returns The entries, or an empty array when the value is not an object
50
+ @internal
51
51
  */
52
52
  function readEntries(value) {
53
53
  if (!isObject(value)) return [];
54
54
  return Object.entries(value);
55
55
  }
56
56
  /**
57
- * Read a property that should hold an array, from a value of unknown shape
58
- * @param value - The value to read from
59
- * @param key - The property to read
60
- * @returns The array, or an empty array when the property is absent or not one
61
- * @internal
57
+ Read a property that should hold an array, from a value of unknown shape
58
+ @param value - The value to read from
59
+ @param key - The property to read
60
+ @returns The array, or an empty array when the property is absent or not one
61
+ @internal
62
62
  */
63
63
  function readArrayProperty(value, key) {
64
64
  const property = readProperty(value, key);
65
65
  return Array.isArray(property) ? property : [];
66
66
  }
67
67
  /**
68
- * Read a property that should hold a string, from a value of unknown shape
69
- * @param value - The value to read from
70
- * @param key - The property to read
71
- * @returns The string, or null when the property is absent or not one
72
- * @internal
68
+ Read a property that should hold a string, from a value of unknown shape
69
+ @param value - The value to read from
70
+ @param key - The property to read
71
+ @returns The string, or null when the property is absent or not one
72
+ @internal
73
73
  */
74
74
  function readStringProperty(value, key) {
75
75
  const property = readProperty(value, key);