ochre-sdk 1.2.0 → 1.3.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/fetchers/set/item-locations.mjs +4 -2
- package/dist/fetchers/set/property-values.d.mts +2 -0
- package/dist/fetchers/set/property-values.mjs +10 -6
- package/dist/query.mjs +2 -5
- package/dist/schemas.d.mts +1 -0
- package/dist/schemas.mjs +2 -1
- package/dist/types/index.d.mts +1 -0
- package/dist/xml/schemas.d.mts +23 -2
- package/dist/xml/schemas.mjs +2 -2
- package/dist/xml/types.d.mts +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { normalizeItemCategory } from "../../categories.mjs";
|
|
|
2
2
|
import { getErrorOutput } from "../../errors.mjs";
|
|
3
3
|
import { requestOchre } from "../request.mjs";
|
|
4
4
|
import { setItemLocationsParametersSchema } from "../../schemas.mjs";
|
|
5
|
+
import { parseRequiredContentLike } from "../../parsers/helpers.mjs";
|
|
5
6
|
import { parseRequestedLanguages, resolveContentLanguages } from "../../parsers/languages.mjs";
|
|
6
7
|
import { parseCoordinates, parseIdentification } from "../../parsers/index.mjs";
|
|
7
8
|
import { XMLSetItemLocationsData } from "../../xml/schemas.mjs";
|
|
@@ -26,7 +27,7 @@ async function fetchSetItemLocations(parameters, options) {
|
|
|
26
27
|
$item/identification,
|
|
27
28
|
$item/coordinates,
|
|
28
29
|
for $value in $item//properties//property[label/@uuid = $propertyVariableUuids]/value[@uuid]
|
|
29
|
-
return <value variable="{$value/../label/@uuid}" uuid="{$value/@uuid}"
|
|
30
|
+
return <value variable="{$value/../label/@uuid}" uuid="{$value/@uuid}">{$value/content}</value>
|
|
30
31
|
}</itemLocation>
|
|
31
32
|
}</items>`
|
|
32
33
|
}),
|
|
@@ -49,7 +50,8 @@ async function fetchSetItemLocations(parameters, options) {
|
|
|
49
50
|
seenPropertyValues.add(key);
|
|
50
51
|
propertyValues.push({
|
|
51
52
|
variableUuid: value.variable,
|
|
52
|
-
valueUuid: value.uuid
|
|
53
|
+
valueUuid: value.uuid,
|
|
54
|
+
label: parseRequiredContentLike(value, { languages })
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
itemsByUuid.set(itemLocation.uuid, {
|
|
@@ -11,6 +11,7 @@ import { OchreRequestOptions } from "../request.mjs";
|
|
|
11
11
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
12
12
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
13
13
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
14
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
14
15
|
* @param options - Options for the fetch
|
|
15
16
|
* @param options.fetch - The fetch function to use
|
|
16
17
|
* @returns Parsed Set property values and requested attribute values.
|
|
@@ -24,6 +25,7 @@ export declare function fetchSetPropertyValues(parameters: {
|
|
|
24
25
|
periods: boolean;
|
|
25
26
|
};
|
|
26
27
|
isLimitedToLeafPropertyValues?: boolean;
|
|
28
|
+
language?: string;
|
|
27
29
|
}, options?: OchreRequestOptions): Promise<{
|
|
28
30
|
propertyValues: Array<PropertyValueQueryItem>;
|
|
29
31
|
propertyValuesByPropertyVariableUuid: Record<string, Array<PropertyValueQueryItem>>;
|
|
@@ -150,10 +150,12 @@ const responseSchema = v.object({ result: v.object({ ochre: v.object({
|
|
|
150
150
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
151
151
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
152
152
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
153
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
153
154
|
* @returns An XQuery string
|
|
154
155
|
*/
|
|
155
156
|
function buildXQuery(parameters) {
|
|
156
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = parameters;
|
|
157
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues, language } = parameters;
|
|
158
|
+
const languageLiteral = stringLiteral(language);
|
|
157
159
|
const valueFilter = isLimitedToLeafPropertyValues ? "[not(@i)]" : "";
|
|
158
160
|
const returnedSequences = [];
|
|
159
161
|
const xqueryDeclarations = ["declare namespace map = \"http://marklogic.com/xdmp/map\";", `declare function local:increment-count($counts, $key) {
|
|
@@ -173,7 +175,7 @@ declare function local:normalize-data-type($data-type) {
|
|
|
173
175
|
|
|
174
176
|
declare function local:value-display-text($v) {
|
|
175
177
|
if ($v/content)
|
|
176
|
-
then string-join($v/content[@xml:lang
|
|
178
|
+
then string-join($v/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
177
179
|
else string($v)
|
|
178
180
|
};
|
|
179
181
|
|
|
@@ -332,7 +334,7 @@ let $_bibliography-aggregation := xdmp:eager(
|
|
|
332
334
|
let $seen := map:map()
|
|
333
335
|
return
|
|
334
336
|
for $bibliography in $item/bibliographies/bibliography${notSupplemental}
|
|
335
|
-
let $label := string-join($bibliography/identification/label/content[@xml:lang
|
|
337
|
+
let $label := string-join($bibliography/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
336
338
|
where string-length($label) gt 0
|
|
337
339
|
return local:add-attribute-facet($bibliography-counts, $seen, $label)
|
|
338
340
|
)
|
|
@@ -352,7 +354,7 @@ let $_period-aggregation := xdmp:eager(
|
|
|
352
354
|
let $seen := map:map()
|
|
353
355
|
return
|
|
354
356
|
for $period in $item/periods/period${notSupplemental}
|
|
355
|
-
let $label := string-join($period/identification/label/content[@xml:lang
|
|
357
|
+
let $label := string-join($period/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
356
358
|
where string-length($label) gt 0
|
|
357
359
|
return local:add-attribute-facet($period-counts, $seen, $label)
|
|
358
360
|
)
|
|
@@ -439,6 +441,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
439
441
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
440
442
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
441
443
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
444
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
442
445
|
* @param options - Options for the fetch
|
|
443
446
|
* @param options.fetch - The fetch function to use
|
|
444
447
|
* @returns Parsed Set property values and requested attribute values.
|
|
@@ -446,7 +449,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
446
449
|
*/
|
|
447
450
|
async function fetchSetPropertyValues(parameters, options) {
|
|
448
451
|
try {
|
|
449
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
452
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues, language } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
450
453
|
const propertyFacetSelectors = getPropertyFacetSelectors(queries);
|
|
451
454
|
if (propertyFacetSelectors.length === 0 && !attributes.bibliographies && !attributes.periods) return {
|
|
452
455
|
propertyValues: [],
|
|
@@ -464,7 +467,8 @@ async function fetchSetPropertyValues(parameters, options) {
|
|
|
464
467
|
queries,
|
|
465
468
|
propertyFacetSelectors,
|
|
466
469
|
attributes,
|
|
467
|
-
isLimitedToLeafPropertyValues
|
|
470
|
+
isLimitedToLeafPropertyValues,
|
|
471
|
+
language
|
|
468
472
|
});
|
|
469
473
|
const output = await requestOchre({
|
|
470
474
|
xquery,
|
package/dist/query.mjs
CHANGED
|
@@ -229,11 +229,8 @@ function buildAndCtsQueryExpression(queryExpressions) {
|
|
|
229
229
|
return buildAndCtsQueryExpressionInternal(queryExpressions);
|
|
230
230
|
}
|
|
231
231
|
function buildContentLanguageQuery(language) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
attributeName: "xml:lang",
|
|
235
|
-
value: searchValue(language)
|
|
236
|
-
});
|
|
232
|
+
const languageValue = searchValue(language);
|
|
233
|
+
return `cts:element-attribute-value-query(xs:QName("content"), xs:QName("xml:lang"), ${languageValue.expression}, fn:concat("lang=", ${languageValue.expression}))`;
|
|
237
234
|
}
|
|
238
235
|
function buildPropertyLabelQuery(propertyVariable) {
|
|
239
236
|
return buildPlainElementAttributeValueQueryExpression({
|
package/dist/schemas.d.mts
CHANGED
|
@@ -54,6 +54,7 @@ export declare const setPropertyValuesParametersSchema: v.ObjectSchema<{
|
|
|
54
54
|
readonly periods: false;
|
|
55
55
|
}>;
|
|
56
56
|
readonly isLimitedToLeafPropertyValues: v.GenericSchema<unknown, boolean>;
|
|
57
|
+
readonly language: v.GenericSchema<unknown, string>;
|
|
57
58
|
}, undefined>;
|
|
58
59
|
/**
|
|
59
60
|
* Schema for validating the parameters for the item OCR data fetching function
|
package/dist/schemas.mjs
CHANGED
|
@@ -237,7 +237,8 @@ const setPropertyValuesParametersSchema = v.object({
|
|
|
237
237
|
bibliographies: false,
|
|
238
238
|
periods: false
|
|
239
239
|
}),
|
|
240
|
-
isLimitedToLeafPropertyValues: defaultBoolean(false)
|
|
240
|
+
isLimitedToLeafPropertyValues: defaultBoolean(false),
|
|
241
|
+
language: defaultString("eng")
|
|
241
242
|
});
|
|
242
243
|
/**
|
|
243
244
|
* Schema for validating the parameters for the item OCR data fetching function
|
package/dist/types/index.d.mts
CHANGED
package/dist/xml/schemas.d.mts
CHANGED
|
@@ -4668,10 +4668,31 @@ export declare const XMLSetItemLocationsData: v.ObjectSchema<{
|
|
|
4668
4668
|
}, "XMLCoordinatesSource: Shape error">], undefined>, undefined>;
|
|
4669
4669
|
}, "XMLCoordinates: Shape error">], "XMLCoordinates: Shape error">, undefined>;
|
|
4670
4670
|
}, "XMLCoordinates: Shape error">, undefined>;
|
|
4671
|
-
readonly value: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
4671
|
+
readonly value: v.OptionalSchema<v.ArraySchema<v.IntersectSchema<[v.ObjectSchema<{
|
|
4672
4672
|
readonly variable: v.StringSchema<"XMLSetItemLocation: value variable is string and required">;
|
|
4673
4673
|
readonly uuid: v.StringSchema<"XMLSetItemLocation: value uuid is string and required">;
|
|
4674
|
-
}, "XMLSetItemLocation: value is object with variable and uuid">,
|
|
4674
|
+
}, "XMLSetItemLocation: value is object with variable and uuid">, v.ObjectSchema<{
|
|
4675
|
+
readonly content: v.ArraySchema<v.ObjectSchema<{
|
|
4676
|
+
readonly links: v.OptionalSchema<v.LazySchema<v.GenericSchema<unknown, XMLLink$1>>, undefined>;
|
|
4677
|
+
readonly properties: v.OptionalSchema<v.ObjectSchema<{
|
|
4678
|
+
readonly property: v.ArraySchema<v.LazySchema<v.GenericSchema<unknown, XMLProperty>>, "XMLRichTextEnvelope: properties is array of XMLProperty">;
|
|
4679
|
+
}, undefined>, undefined>;
|
|
4680
|
+
readonly annotation: v.OptionalSchema<v.StringSchema<"XMLRichTextEnvelope: annotation is string and optional">, undefined>;
|
|
4681
|
+
readonly string: v.ArraySchema<v.ObjectSchema<{
|
|
4682
|
+
string: v.OptionalSchema<v.ArraySchema<v.LazySchema<v.GenericSchema<unknown, XMLString>>, "XMLString: string is array of XMLString">, undefined>;
|
|
4683
|
+
links: v.OptionalSchema<v.LazySchema<v.GenericSchema<unknown, XMLLink$1>>, undefined>;
|
|
4684
|
+
properties: v.OptionalSchema<v.ObjectSchema<{
|
|
4685
|
+
readonly property: v.ArraySchema<v.LazySchema<v.GenericSchema<unknown, XMLProperty>>, "XMLRichTextEnvelope: properties is array of XMLProperty">;
|
|
4686
|
+
}, undefined>, undefined>;
|
|
4687
|
+
annotation: v.OptionalSchema<v.StringSchema<"XMLRichTextEnvelope: annotation is string and optional">, undefined>;
|
|
4688
|
+
payload: v.OptionalSchema<v.StringSchema<"XMLString: payload is string and optional">, undefined>;
|
|
4689
|
+
rend: v.OptionalSchema<v.StringSchema<"XMLString: rend is string and optional">, undefined>;
|
|
4690
|
+
whitespace: v.OptionalSchema<v.StringSchema<"XMLString: whitespace is string and optional">, undefined>;
|
|
4691
|
+
}, "XMLString: Shape error">, undefined>;
|
|
4692
|
+
readonly title: v.OptionalSchema<v.StringSchema<"XMLContent: title is string and optional">, undefined>;
|
|
4693
|
+
readonly lang: v.StringSchema<"XMLContent: lang is string and required">;
|
|
4694
|
+
}, undefined>, "XMLContent: content is array of object with string, title, and lang">;
|
|
4695
|
+
}, "XMLContent: Shape error">], undefined>, undefined>, undefined>;
|
|
4675
4696
|
}, "XMLSetItemLocation: Shape error">, "XMLSetItemLocationsData: itemLocation is array of XMLSetItemLocation">, undefined>;
|
|
4676
4697
|
}, "XMLSetItemLocationsData: items is object with totalCount">;
|
|
4677
4698
|
}, "XMLSetItemLocationsData: ochre">;
|
package/dist/xml/schemas.mjs
CHANGED
|
@@ -933,10 +933,10 @@ const XMLSetItemLocation = v.object({
|
|
|
933
933
|
category: v.string("XMLSetItemLocation: category is string and required"),
|
|
934
934
|
identification: XMLIdentification,
|
|
935
935
|
coordinates: v.optional(XMLCoordinates),
|
|
936
|
-
value: v.optional(v.array(v.object({
|
|
936
|
+
value: v.optional(v.array(v.intersect([v.object({
|
|
937
937
|
variable: v.string("XMLSetItemLocation: value variable is string and required"),
|
|
938
938
|
uuid: v.string("XMLSetItemLocation: value uuid is string and required")
|
|
939
|
-
}, "XMLSetItemLocation: value is object with variable and uuid")))
|
|
939
|
+
}, "XMLSetItemLocation: value is object with variable and uuid"), XMLContent])))
|
|
940
940
|
}, "XMLSetItemLocation: Shape error");
|
|
941
941
|
const XMLSetItemLocationsData = v.object({ result: v.object({ ochre: v.object({ items: v.object({
|
|
942
942
|
totalCount: XMLNumber,
|
package/dist/xml/types.d.mts
CHANGED