ochre-sdk 0.21.2 → 0.21.4
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 +33 -6
- package/dist/index.mjs +52 -27
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -675,7 +675,7 @@ type SetItemsSort = {
|
|
|
675
675
|
*/
|
|
676
676
|
type QueryLeaf = {
|
|
677
677
|
target: "property";
|
|
678
|
-
|
|
678
|
+
propertyVariable?: string;
|
|
679
679
|
dataType: Exclude<Exclude<PropertyValueContentType, "coordinate">, "date" | "dateTime">;
|
|
680
680
|
propertyValues?: Array<string>;
|
|
681
681
|
from?: never;
|
|
@@ -686,9 +686,22 @@ type QueryLeaf = {
|
|
|
686
686
|
isNegated?: boolean;
|
|
687
687
|
} | {
|
|
688
688
|
target: "property";
|
|
689
|
-
|
|
689
|
+
propertyVariable: string;
|
|
690
690
|
dataType: "date" | "dateTime";
|
|
691
691
|
propertyValues?: never;
|
|
692
|
+
value: string;
|
|
693
|
+
from?: never;
|
|
694
|
+
to?: never;
|
|
695
|
+
matchMode: "includes" | "exact";
|
|
696
|
+
isCaseSensitive: boolean;
|
|
697
|
+
language: string;
|
|
698
|
+
isNegated?: boolean;
|
|
699
|
+
} | {
|
|
700
|
+
target: "property";
|
|
701
|
+
propertyVariable: string;
|
|
702
|
+
dataType: "date" | "dateTime";
|
|
703
|
+
propertyValues?: never;
|
|
704
|
+
value?: never;
|
|
692
705
|
from: string;
|
|
693
706
|
to?: string;
|
|
694
707
|
matchMode: "includes" | "exact";
|
|
@@ -697,9 +710,10 @@ type QueryLeaf = {
|
|
|
697
710
|
isNegated?: boolean;
|
|
698
711
|
} | {
|
|
699
712
|
target: "property";
|
|
700
|
-
|
|
713
|
+
propertyVariable: string;
|
|
701
714
|
dataType: "date" | "dateTime";
|
|
702
715
|
propertyValues?: never;
|
|
716
|
+
value?: never;
|
|
703
717
|
from?: string;
|
|
704
718
|
to: string;
|
|
705
719
|
matchMode: "includes" | "exact";
|
|
@@ -793,6 +807,19 @@ type StylesheetItem = {
|
|
|
793
807
|
mobile: Array<Style>;
|
|
794
808
|
};
|
|
795
809
|
};
|
|
810
|
+
type WebsitePropertyQueryNode = {
|
|
811
|
+
target: "property";
|
|
812
|
+
propertyVariable: string;
|
|
813
|
+
dataType: Exclude<PropertyValueContentType, "coordinate">;
|
|
814
|
+
matchMode: "includes" | "exact";
|
|
815
|
+
isCaseSensitive: boolean;
|
|
816
|
+
language: string;
|
|
817
|
+
};
|
|
818
|
+
type WebsitePropertyQuery = WebsitePropertyQueryNode | {
|
|
819
|
+
and: Array<WebsitePropertyQuery>;
|
|
820
|
+
} | {
|
|
821
|
+
or: Array<WebsitePropertyQuery>;
|
|
822
|
+
};
|
|
796
823
|
/**
|
|
797
824
|
* Represents the OCHRE website type
|
|
798
825
|
*/
|
|
@@ -1089,9 +1116,9 @@ type WebElementComponent = {
|
|
|
1089
1116
|
} | {
|
|
1090
1117
|
component: "query";
|
|
1091
1118
|
linkUuids: Array<string>;
|
|
1092
|
-
|
|
1119
|
+
items: Array<{
|
|
1093
1120
|
label: string;
|
|
1094
|
-
|
|
1121
|
+
queries: Array<WebsitePropertyQuery>;
|
|
1095
1122
|
startIcon: string | null;
|
|
1096
1123
|
endIcon: string | null;
|
|
1097
1124
|
}>;
|
|
@@ -1503,4 +1530,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
|
|
|
1503
1530
|
*/
|
|
1504
1531
|
declare function flattenItemProperties<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(item: Item<T, U>): Item<T, U>;
|
|
1505
1532
|
//#endregion
|
|
1506
|
-
export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
|
1533
|
+
export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/dist/index.mjs
CHANGED
|
@@ -759,7 +759,7 @@ const boundsSchema = z.string().transform((str, ctx) => {
|
|
|
759
759
|
const setQueryLeafSchema = z.union([
|
|
760
760
|
z.object({
|
|
761
761
|
target: z.literal("property"),
|
|
762
|
-
|
|
762
|
+
propertyVariable: uuidSchema.optional(),
|
|
763
763
|
dataType: z.enum([
|
|
764
764
|
"string",
|
|
765
765
|
"integer",
|
|
@@ -774,15 +774,28 @@ const setQueryLeafSchema = z.union([
|
|
|
774
774
|
language: z.string().default("eng"),
|
|
775
775
|
isNegated: z.boolean().optional().default(false)
|
|
776
776
|
}).strict().superRefine((value, ctx) => {
|
|
777
|
-
if (value.
|
|
777
|
+
if (value.propertyVariable == null && value.propertyValues == null) ctx.addIssue({
|
|
778
778
|
code: "custom",
|
|
779
779
|
message: "Property queries must include at least one propertyVariable or propertyValue"
|
|
780
780
|
});
|
|
781
781
|
}),
|
|
782
782
|
z.object({
|
|
783
783
|
target: z.literal("property"),
|
|
784
|
-
|
|
784
|
+
propertyVariable: uuidSchema,
|
|
785
785
|
dataType: z.enum(["date", "dateTime"]),
|
|
786
|
+
value: z.string(),
|
|
787
|
+
from: z.never().optional(),
|
|
788
|
+
to: z.never().optional(),
|
|
789
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
790
|
+
isCaseSensitive: z.boolean(),
|
|
791
|
+
language: z.string().default("eng"),
|
|
792
|
+
isNegated: z.boolean().optional().default(false)
|
|
793
|
+
}).strict(),
|
|
794
|
+
z.object({
|
|
795
|
+
target: z.literal("property"),
|
|
796
|
+
propertyVariable: uuidSchema,
|
|
797
|
+
dataType: z.enum(["date", "dateTime"]),
|
|
798
|
+
value: z.never().optional(),
|
|
786
799
|
from: z.string(),
|
|
787
800
|
to: z.string().optional(),
|
|
788
801
|
matchMode: z.enum(["includes", "exact"]),
|
|
@@ -792,8 +805,9 @@ const setQueryLeafSchema = z.union([
|
|
|
792
805
|
}).strict(),
|
|
793
806
|
z.object({
|
|
794
807
|
target: z.literal("property"),
|
|
795
|
-
|
|
808
|
+
propertyVariable: uuidSchema,
|
|
796
809
|
dataType: z.enum(["date", "dateTime"]),
|
|
810
|
+
value: z.never().optional(),
|
|
797
811
|
from: z.string().optional(),
|
|
798
812
|
to: z.string(),
|
|
799
813
|
matchMode: z.enum(["includes", "exact"]),
|
|
@@ -854,11 +868,11 @@ const setItemsSortSchema = z.discriminatedUnion("target", [
|
|
|
854
868
|
language: z.string().default("eng")
|
|
855
869
|
}).strict()
|
|
856
870
|
]).default({ target: "none" });
|
|
857
|
-
function
|
|
871
|
+
function hasPropertyQueryWithPropertyVariable(query) {
|
|
858
872
|
if (query == null) return false;
|
|
859
|
-
if ("target" in query) return query.target === "property" &&
|
|
873
|
+
if ("target" in query) return query.target === "property" && query.propertyVariable != null;
|
|
860
874
|
const groupQueries = "and" in query ? query.and : query.or;
|
|
861
|
-
for (const groupQuery of groupQueries) if (
|
|
875
|
+
for (const groupQuery of groupQueries) if (hasPropertyQueryWithPropertyVariable(groupQuery)) return true;
|
|
862
876
|
return false;
|
|
863
877
|
}
|
|
864
878
|
/**
|
|
@@ -878,10 +892,10 @@ const setPropertyValuesParamsSchema = z.object({
|
|
|
878
892
|
}),
|
|
879
893
|
isLimitedToLeafPropertyValues: z.boolean().default(false)
|
|
880
894
|
}).superRefine((value, ctx) => {
|
|
881
|
-
if (!
|
|
895
|
+
if (!hasPropertyQueryWithPropertyVariable(value.queries)) ctx.addIssue({
|
|
882
896
|
code: "custom",
|
|
883
897
|
path: ["queries"],
|
|
884
|
-
message: "At least one property query with
|
|
898
|
+
message: "At least one property query with propertyVariable is required"
|
|
885
899
|
});
|
|
886
900
|
});
|
|
887
901
|
const setItemsParamsSchema = z.object({
|
|
@@ -2393,10 +2407,8 @@ function buildDateRangePredicate(params) {
|
|
|
2393
2407
|
/**
|
|
2394
2408
|
* Build a property label predicate for an XQuery string.
|
|
2395
2409
|
*/
|
|
2396
|
-
function buildPropertyLabelPredicate(
|
|
2397
|
-
|
|
2398
|
-
for (const propertyVariable of propertyVariables) labelPredicates.push(`@uuid=${stringLiteral(propertyVariable)}`);
|
|
2399
|
-
return `label[${buildOrPredicate(labelPredicates)}]`;
|
|
2410
|
+
function buildPropertyLabelPredicate(propertyVariable) {
|
|
2411
|
+
return `label[@uuid=${stringLiteral(propertyVariable)}]`;
|
|
2400
2412
|
}
|
|
2401
2413
|
function buildOrCtsQueryExpression(queries) {
|
|
2402
2414
|
if (queries.length === 1) return queries[0] ?? "cts:false-query()";
|
|
@@ -2503,11 +2515,11 @@ function buildItemStringIncludesGroupMember(query) {
|
|
|
2503
2515
|
};
|
|
2504
2516
|
}
|
|
2505
2517
|
function buildPropertyStringIncludesGroupMember(query) {
|
|
2506
|
-
const
|
|
2518
|
+
const propertyVariable = query.propertyVariable;
|
|
2507
2519
|
const predicateParts = [];
|
|
2508
2520
|
const valueExpression = buildFlattenedContentValuesExpression(`value[not(@inherited="true")]/content[@xml:lang="${query.language}"]`);
|
|
2509
2521
|
const propertyValue = query.propertyValues[0] ?? "";
|
|
2510
|
-
if (
|
|
2522
|
+
if (propertyVariable != null) predicateParts.push(buildPropertyLabelPredicate(propertyVariable));
|
|
2511
2523
|
return {
|
|
2512
2524
|
rawPredicate: buildPropertyPredicateExpression([...predicateParts, buildRawStringMatchPredicate({
|
|
2513
2525
|
valueExpression,
|
|
@@ -2714,10 +2726,11 @@ function buildPropertyClause(params) {
|
|
|
2714
2726
|
const { query, version, queryKey } = params;
|
|
2715
2727
|
const predicateParts = [];
|
|
2716
2728
|
const declarations = [];
|
|
2717
|
-
const
|
|
2729
|
+
const propertyVariable = query.propertyVariable;
|
|
2718
2730
|
let candidateQueryVar = null;
|
|
2719
|
-
if (
|
|
2720
|
-
if (query.dataType === "date" || query.dataType === "dateTime") predicateParts.push(
|
|
2731
|
+
if (propertyVariable != null) predicateParts.push(buildPropertyLabelPredicate(propertyVariable));
|
|
2732
|
+
if (query.dataType === "date" || query.dataType === "dateTime") if ("value" in query && query.value != null) predicateParts.push(`value/@rawValue = ${stringLiteral(query.value)}`);
|
|
2733
|
+
else predicateParts.push(buildDateRangePredicate({
|
|
2721
2734
|
from: query.from,
|
|
2722
2735
|
to: query.to
|
|
2723
2736
|
}));
|
|
@@ -3257,7 +3270,7 @@ function getPropertyVariableUuidsFromQueries(queries) {
|
|
|
3257
3270
|
for (const query of pendingQueries) {
|
|
3258
3271
|
if ("target" in query) {
|
|
3259
3272
|
if (query.target !== "property") continue;
|
|
3260
|
-
|
|
3273
|
+
if (query.propertyVariable != null) propertyVariableUuids.add(query.propertyVariable);
|
|
3261
3274
|
continue;
|
|
3262
3275
|
}
|
|
3263
3276
|
pendingQueries.push(..."and" in query ? query.and : query.or);
|
|
@@ -4250,25 +4263,37 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
4250
4263
|
case "query": {
|
|
4251
4264
|
const setLinks = links.filter((link) => link.category === "set");
|
|
4252
4265
|
if (setLinks.every((link) => link.uuid === null)) throw new Error(`Set links not found for the following component: “${componentName}”`);
|
|
4253
|
-
const
|
|
4266
|
+
const items = [];
|
|
4254
4267
|
if (componentProperty.properties.length === 0) throw new Error(`Query properties not found for the following component: “${componentName}”`);
|
|
4255
|
-
for (const
|
|
4256
|
-
const querySubProperties =
|
|
4268
|
+
for (const queryItem of componentProperty.properties) {
|
|
4269
|
+
const querySubProperties = queryItem.properties;
|
|
4257
4270
|
const label = getPropertyValueByLabel(querySubProperties, "query-prompt");
|
|
4258
4271
|
if (label === null) continue;
|
|
4259
|
-
const
|
|
4272
|
+
const queries = (getPropertyByLabel(querySubProperties, "use-property")?.values.filter((value) => value.uuid !== null) ?? []).map((propertyVariable) => {
|
|
4273
|
+
if (propertyVariable.uuid === null) throw new Error(`Property variable UUID not found for the following component: “${componentName}”`);
|
|
4274
|
+
const dataType = propertyVariable.dataType;
|
|
4275
|
+
if (dataType === "coordinate") throw new Error(`Query prompts with data type "coordinate" are not supported for the following component: “${componentName}”`);
|
|
4276
|
+
return {
|
|
4277
|
+
target: "property",
|
|
4278
|
+
propertyVariable: propertyVariable.uuid,
|
|
4279
|
+
dataType,
|
|
4280
|
+
matchMode: "exact",
|
|
4281
|
+
isCaseSensitive: true,
|
|
4282
|
+
language: "eng"
|
|
4283
|
+
};
|
|
4284
|
+
});
|
|
4260
4285
|
let startIcon = getPropertyValueByLabel(querySubProperties, "start-icon");
|
|
4261
4286
|
startIcon ??= null;
|
|
4262
4287
|
let endIcon = getPropertyValueByLabel(querySubProperties, "end-icon");
|
|
4263
4288
|
endIcon ??= null;
|
|
4264
|
-
|
|
4289
|
+
items.push({
|
|
4265
4290
|
label,
|
|
4266
|
-
|
|
4291
|
+
queries,
|
|
4267
4292
|
startIcon,
|
|
4268
4293
|
endIcon
|
|
4269
4294
|
});
|
|
4270
4295
|
}
|
|
4271
|
-
if (
|
|
4296
|
+
if (items.length === 0) throw new Error(`No queries found for the following component: “${componentName}”`);
|
|
4272
4297
|
const options = {
|
|
4273
4298
|
attributeFilters: {
|
|
4274
4299
|
bibliographies: elementResource.options?.filterBibliography ?? false,
|
|
@@ -4299,7 +4324,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
4299
4324
|
properties = {
|
|
4300
4325
|
component: "query",
|
|
4301
4326
|
linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
|
|
4302
|
-
|
|
4327
|
+
items,
|
|
4303
4328
|
options,
|
|
4304
4329
|
displayedProperties: displayedProperties?.values.filter((value) => value.uuid !== null).map((value) => ({
|
|
4305
4330
|
uuid: value.uuid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.4",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"bumpp": "^11.0.1",
|
|
52
52
|
"eslint": "^10.1.0",
|
|
53
53
|
"prettier": "^3.8.1",
|
|
54
|
-
"tsdown": "^0.21.
|
|
54
|
+
"tsdown": "^0.21.7",
|
|
55
55
|
"typescript": "^6.0.2"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|