ochre-sdk 0.22.7 → 0.22.9
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.d.mts +2 -0
- package/dist/index.mjs +25 -19
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -802,6 +802,7 @@ type StylesheetCategory = Extract<DataCategory, "propertyVariable" | "propertyVa
|
|
|
802
802
|
type StylesheetItem = {
|
|
803
803
|
uuid: string;
|
|
804
804
|
category: "propertyVariable";
|
|
805
|
+
icon: string | null;
|
|
805
806
|
styles: {
|
|
806
807
|
default: Array<Style>;
|
|
807
808
|
tablet: Array<Style>;
|
|
@@ -811,6 +812,7 @@ type StylesheetItem = {
|
|
|
811
812
|
uuid: string;
|
|
812
813
|
category: "propertyValue";
|
|
813
814
|
variableUuid: string;
|
|
815
|
+
icon: string | null;
|
|
814
816
|
styles: {
|
|
815
817
|
default: Array<Style>;
|
|
816
818
|
tablet: Array<Style>;
|
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
|
});
|
|
@@ -3747,12 +3751,14 @@ function parseStylesheets(styles) {
|
|
|
3747
3751
|
uuid: style.valueUuid,
|
|
3748
3752
|
category: "propertyValue",
|
|
3749
3753
|
variableUuid: style.variableUuid,
|
|
3754
|
+
icon: style.lucideIcon ?? null,
|
|
3750
3755
|
styles: stylesByViewport
|
|
3751
3756
|
};
|
|
3752
3757
|
}
|
|
3753
3758
|
return {
|
|
3754
3759
|
uuid: style.variableUuid,
|
|
3755
3760
|
category: "propertyVariable",
|
|
3761
|
+
icon: style.lucideIcon ?? null,
|
|
3756
3762
|
styles: stylesByViewport
|
|
3757
3763
|
};
|
|
3758
3764
|
});
|