ochre-sdk 0.22.8 → 0.22.10
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/index.mjs +25 -21
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -879,13 +879,6 @@ const setItemsSortSchema = z.discriminatedUnion("target", [
|
|
|
879
879
|
language: z.string().default("eng")
|
|
880
880
|
}).strict()
|
|
881
881
|
]).default({ target: "none" });
|
|
882
|
-
function hasPropertyQueryWithPropertyVariable(query) {
|
|
883
|
-
if (query == null) return false;
|
|
884
|
-
if ("target" in query) return query.target === "property" && query.propertyVariable != null;
|
|
885
|
-
const groupQueries = "and" in query ? query.and : query.or;
|
|
886
|
-
for (const groupQuery of groupQueries) if (hasPropertyQueryWithPropertyVariable(groupQuery)) return true;
|
|
887
|
-
return false;
|
|
888
|
-
}
|
|
889
882
|
/**
|
|
890
883
|
* Schema for validating the parameters for the Set property values fetching function
|
|
891
884
|
* @internal
|
|
@@ -902,12 +895,6 @@ const setPropertyValuesParamsSchema = z.object({
|
|
|
902
895
|
periods: false
|
|
903
896
|
}),
|
|
904
897
|
isLimitedToLeafPropertyValues: z.boolean().default(false)
|
|
905
|
-
}).superRefine((value, ctx) => {
|
|
906
|
-
if (!hasPropertyQueryWithPropertyVariable(value.queries)) ctx.addIssue({
|
|
907
|
-
code: "custom",
|
|
908
|
-
path: ["queries"],
|
|
909
|
-
message: "At least one property query with propertyVariable is required"
|
|
910
|
-
});
|
|
911
898
|
});
|
|
912
899
|
const setItemsParamsSchema = z.object({
|
|
913
900
|
setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
|
|
@@ -3158,6 +3145,7 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
|
|
|
3158
3145
|
* @param params.setScopeUuids - An array of set scope UUIDs to filter by
|
|
3159
3146
|
* @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
|
|
3160
3147
|
* @param params.queries - Recursive query tree used to filter matching items
|
|
3148
|
+
* @param params.propertyVariableUuids - Property variable UUIDs to aggregate, if any
|
|
3161
3149
|
* @param params.attributes - Whether to return values for bibliographies and periods
|
|
3162
3150
|
* @param params.attributes.bibliographies - Whether to return values for bibliographies
|
|
3163
3151
|
* @param params.attributes.periods - Whether to return values for periods
|
|
@@ -3165,10 +3153,9 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
|
|
|
3165
3153
|
* @returns An XQuery string
|
|
3166
3154
|
*/
|
|
3167
3155
|
function buildXQuery(params) {
|
|
3168
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = params;
|
|
3156
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyVariableUuids, attributes, isLimitedToLeafPropertyValues } = params;
|
|
3169
3157
|
let setScopeFilter = "/set/items/*";
|
|
3170
3158
|
if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
|
|
3171
|
-
const propertyVariableFilters = getPropertyVariableUuidsFromQueries(queries).map((uuid) => `@uuid="${uuid}"`).join(" or ");
|
|
3172
3159
|
const baseItemsExpression = `doc()/ochre${setScopeFilter}`;
|
|
3173
3160
|
const compiledQueryPlan = buildQueryPlan({ queries: getItemFilterQueriesFromPropertyValueQueries(queries) });
|
|
3174
3161
|
const itemsQueryExpressions = [];
|
|
@@ -3176,17 +3163,23 @@ function buildXQuery(params) {
|
|
|
3176
3163
|
if (compiledQueryPlan.queryExpression != null) itemsQueryExpressions.push(compiledQueryPlan.queryExpression);
|
|
3177
3164
|
if (belongsToCollectionQueryExpression != null) itemsQueryExpressions.push(belongsToCollectionQueryExpression);
|
|
3178
3165
|
const itemsQueryExpression = buildAndCtsQueryExpression(itemsQueryExpressions);
|
|
3179
|
-
const
|
|
3166
|
+
const valueFilter = isLimitedToLeafPropertyValues ? "[not(@i)]" : "";
|
|
3167
|
+
const queryBlocks = [];
|
|
3168
|
+
const returnedSequences = [];
|
|
3169
|
+
if (propertyVariableUuids.length > 0) {
|
|
3170
|
+
const propertyVariableFilters = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
|
|
3171
|
+
queryBlocks.push(`let $matching-props := $items//property[label[${propertyVariableFilters}]]
|
|
3180
3172
|
|
|
3181
3173
|
let $property-values :=
|
|
3182
3174
|
for $p in $matching-props
|
|
3183
|
-
for $v in $p/value${
|
|
3175
|
+
for $v in $p/value${valueFilter}
|
|
3184
3176
|
let $item-uuid := $v/ancestor::*[parent::items]/@uuid
|
|
3185
3177
|
let $variable-uuid := $p/label/@uuid
|
|
3186
3178
|
return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}" variableUuid="{$variable-uuid}">{
|
|
3187
3179
|
if ($v/content) then string-join($v/content[@xml:lang="eng"]//text(), "") else $v/text()
|
|
3188
|
-
}</propertyValue>`
|
|
3189
|
-
|
|
3180
|
+
}</propertyValue>`);
|
|
3181
|
+
returnedSequences.push("$property-values");
|
|
3182
|
+
}
|
|
3190
3183
|
if (attributes.bibliographies) {
|
|
3191
3184
|
queryBlocks.push(`let $bibliography-values :=
|
|
3192
3185
|
for $item in $items
|
|
@@ -3231,10 +3224,21 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
3231
3224
|
try {
|
|
3232
3225
|
if (options?.version != null && options.version !== 2) throw new Error("Set property value queries only support API version 2");
|
|
3233
3226
|
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = setPropertyValuesParamsSchema.parse(params);
|
|
3227
|
+
const propertyVariableUuids = getPropertyVariableUuidsFromQueries(queries);
|
|
3228
|
+
if (propertyVariableUuids.length === 0 && !attributes.bibliographies && !attributes.periods) return {
|
|
3229
|
+
propertyValues: [],
|
|
3230
|
+
propertyValuesByPropertyVariableUuid: {},
|
|
3231
|
+
attributeValues: {
|
|
3232
|
+
bibliographies: null,
|
|
3233
|
+
periods: null
|
|
3234
|
+
},
|
|
3235
|
+
error: null
|
|
3236
|
+
};
|
|
3234
3237
|
const xquery = buildXQuery({
|
|
3235
3238
|
setScopeUuids,
|
|
3236
3239
|
belongsToCollectionScopeUuids,
|
|
3237
3240
|
queries,
|
|
3241
|
+
propertyVariableUuids,
|
|
3238
3242
|
attributes,
|
|
3239
3243
|
isLimitedToLeafPropertyValues
|
|
3240
3244
|
});
|
|
@@ -3912,7 +3916,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
3912
3916
|
let paginationVariant = getPropertyValueContentByLabel(componentProperty.properties, "pagination-variant");
|
|
3913
3917
|
paginationVariant ??= "default";
|
|
3914
3918
|
let loadingVariant = getPropertyValueContentByLabel(componentProperty.properties, "loading-variant");
|
|
3915
|
-
loadingVariant ??= "
|
|
3919
|
+
loadingVariant ??= "skeleton";
|
|
3916
3920
|
let imageQuality = getPropertyValueContentByLabel(componentProperty.properties, "image-quality");
|
|
3917
3921
|
imageQuality ??= "low";
|
|
3918
3922
|
let isUsingQueryParams = getPropertyValueContentByLabel(componentProperty.properties, "is-using-query-params");
|
|
@@ -4226,7 +4230,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
4226
4230
|
let paginationVariant = getPropertyValueContentByLabel(componentProperty.properties, "pagination-variant");
|
|
4227
4231
|
paginationVariant ??= "default";
|
|
4228
4232
|
let loadingVariant = getPropertyValueContentByLabel(componentProperty.properties, "loading-variant");
|
|
4229
|
-
loadingVariant ??= "
|
|
4233
|
+
loadingVariant ??= "skeleton";
|
|
4230
4234
|
let layout = getPropertyValueContentByLabel(componentProperty.properties, "layout");
|
|
4231
4235
|
layout ??= "image-start";
|
|
4232
4236
|
properties = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@types/node": "^24.12.2",
|
|
54
54
|
"bumpp": "^11.0.1",
|
|
55
55
|
"eslint": "^10.2.0",
|
|
56
|
-
"prettier": "^3.8.
|
|
57
|
-
"tsdown": "^0.21.
|
|
56
|
+
"prettier": "^3.8.3",
|
|
57
|
+
"tsdown": "^0.21.9",
|
|
58
58
|
"typescript": "^6.0.2",
|
|
59
59
|
"vitest": "^4.1.4"
|
|
60
60
|
},
|