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.
- package/dist/categories.d.mts +56 -56
- package/dist/categories.mjs +39 -39
- package/dist/constants.d.mts +8 -8
- package/dist/constants.mjs +6 -6
- package/dist/errors.d.mts +12 -12
- package/dist/errors.mjs +22 -23
- package/dist/fetchers/container-items.d.mts +28 -28
- package/dist/fetchers/container-items.mjs +27 -27
- package/dist/fetchers/gallery.d.mts +13 -13
- package/dist/fetchers/gallery.mjs +2 -2
- package/dist/fetchers/item-children.d.mts +12 -12
- package/dist/fetchers/item-children.mjs +2 -2
- package/dist/fetchers/item-links.d.mts +10 -10
- package/dist/fetchers/item-links.mjs +6 -6
- package/dist/fetchers/item-locations.d.mts +20 -20
- package/dist/fetchers/item-locations.mjs +3 -3
- package/dist/fetchers/item-ocr-data.d.mts +23 -23
- package/dist/fetchers/item-ocr-data.mjs +44 -44
- package/dist/fetchers/item.d.mts +23 -18
- package/dist/fetchers/item.mjs +15 -15
- package/dist/fetchers/map-layers.d.mts +15 -15
- package/dist/fetchers/map-layers.mjs +12 -11
- package/dist/fetchers/request.d.mts +40 -40
- package/dist/fetchers/request.mjs +37 -37
- package/dist/fetchers/set/items.d.mts +15 -15
- package/dist/fetchers/set/items.mjs +1 -1
- package/dist/fetchers/set/property-values.d.mts +16 -16
- package/dist/fetchers/set/property-values.mjs +43 -43
- package/dist/fetchers/tree/items.d.mts +27 -27
- package/dist/fetchers/tree/items.mjs +1 -1
- package/dist/fetchers/website-metadata.d.mts +4 -4
- package/dist/fetchers/website-metadata.mjs +9 -9
- package/dist/fetchers/website.d.mts +10 -10
- package/dist/fetchers/website.mjs +12 -12
- package/dist/getters.d.mts +83 -83
- package/dist/getters.mjs +74 -74
- package/dist/helpers.d.mts +4 -4
- package/dist/helpers.mjs +7 -7
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -5
- package/dist/languages.d.mts +58 -58
- package/dist/languages.mjs +21 -21
- package/dist/ocr.d.mts +27 -27
- package/dist/ocr.mjs +29 -29
- package/dist/parsers/helpers.d.mts +23 -23
- package/dist/parsers/helpers.mjs +8 -8
- package/dist/parsers/index.d.mts +2 -2
- package/dist/parsers/index.mjs +15 -15
- package/dist/parsers/languages.d.mts +49 -49
- package/dist/parsers/languages.mjs +49 -49
- package/dist/parsers/multilingual.d.mts +174 -174
- package/dist/parsers/multilingual.mjs +146 -146
- package/dist/parsers/partial-date.d.mts +12 -12
- package/dist/parsers/partial-date.mjs +11 -11
- package/dist/parsers/property-token.d.mts +20 -20
- package/dist/parsers/property-token.mjs +16 -16
- package/dist/parsers/string.d.mts +33 -33
- package/dist/parsers/string.mjs +62 -64
- package/dist/parsers/website/bounds.d.mts +6 -6
- package/dist/parsers/website/bounds.mjs +5 -5
- package/dist/parsers/website/components.d.mts +46 -31
- package/dist/parsers/website/components.mjs +84 -51
- package/dist/parsers/website/index.d.mts +2 -2
- package/dist/parsers/website/index.mjs +45 -48
- package/dist/parsers/website/links.d.mts +24 -24
- package/dist/parsers/website/links.mjs +18 -18
- package/dist/parsers/website/messages.d.mts +16 -16
- package/dist/parsers/website/messages.mjs +14 -14
- package/dist/parsers/website/options.d.mts +1 -1
- package/dist/parsers/website/properties.d.mts +17 -8
- package/dist/parsers/website/properties.mjs +31 -10
- package/dist/parsers/website/reader.d.mts +55 -47
- package/dist/parsers/website/reader.mjs +66 -51
- package/dist/parsers/website/slug.d.mts +50 -50
- package/dist/parsers/website/slug.mjs +36 -36
- package/dist/parsers/website/styles.d.mts +18 -18
- package/dist/parsers/website/styles.mjs +19 -19
- package/dist/parsers/website/walk.d.mts +46 -46
- package/dist/parsers/website/walk.mjs +34 -34
- package/dist/query.d.mts +63 -63
- package/dist/query.mjs +137 -140
- package/dist/reflection.d.mts +51 -51
- package/dist/reflection.mjs +45 -45
- package/dist/schemas.d.mts +44 -44
- package/dist/schemas.mjs +50 -50
- package/dist/types/index.d.mts +192 -192
- package/dist/types/utilities.d.mts +5 -5
- package/dist/types/website.d.mts +74 -62
- package/dist/xml/dates.d.mts +9 -9
- package/dist/xml/dates.mjs +9 -9
- package/dist/xml/metadata.d.mts +14 -14
- package/dist/xml/metadata.mjs +18 -18
- package/dist/xml/schemas.mjs +24 -24
- package/dist/xml/types.d.mts +9 -9
- package/dist/xquery.d.mts +49 -49
- package/dist/xquery.mjs +50 -50
- 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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
|
|
577
|
-
|
|
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
|
-
|
|
602
|
-
|
|
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
|
|
714
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
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
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
-
|
|
1022
|
-
|
|
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
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
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
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
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
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
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
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
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
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
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
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
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
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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 [];
|
package/dist/reflection.d.mts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
package/dist/reflection.mjs
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
// src/reflection.ts
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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);
|