ochre-sdk 0.20.0 → 0.20.2
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 +31 -1
- package/dist/index.mjs +99 -30
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -647,7 +647,37 @@ type PropertyValueQueryItem = {
|
|
|
647
647
|
* Represents a query for Set items
|
|
648
648
|
*/
|
|
649
649
|
type Query = {
|
|
650
|
-
target: "
|
|
650
|
+
target: "propertyValue";
|
|
651
|
+
dataType: Exclude<Exclude<PropertyValueContentType, "coordinate">, "date" | "dateTime">;
|
|
652
|
+
value: string;
|
|
653
|
+
from?: never;
|
|
654
|
+
to?: never;
|
|
655
|
+
matchMode: "includes" | "exact";
|
|
656
|
+
isCaseSensitive: boolean;
|
|
657
|
+
language: string;
|
|
658
|
+
operator?: "AND" | "OR";
|
|
659
|
+
} | {
|
|
660
|
+
target: "propertyValue";
|
|
661
|
+
dataType: "date" | "dateTime";
|
|
662
|
+
value: string;
|
|
663
|
+
from: string;
|
|
664
|
+
to?: string;
|
|
665
|
+
matchMode: "includes" | "exact";
|
|
666
|
+
isCaseSensitive: boolean;
|
|
667
|
+
language: string;
|
|
668
|
+
operator?: "AND" | "OR";
|
|
669
|
+
} | {
|
|
670
|
+
target: "propertyValue";
|
|
671
|
+
dataType: "date" | "dateTime";
|
|
672
|
+
value: string;
|
|
673
|
+
from?: string;
|
|
674
|
+
to: string;
|
|
675
|
+
matchMode: "includes" | "exact";
|
|
676
|
+
isCaseSensitive: boolean;
|
|
677
|
+
language: string;
|
|
678
|
+
operator?: "AND" | "OR";
|
|
679
|
+
} | {
|
|
680
|
+
target: "title" | "description" | "image" | "periods" | "bibliography";
|
|
651
681
|
value: string;
|
|
652
682
|
matchMode: "includes" | "exact";
|
|
653
683
|
isCaseSensitive: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -772,21 +772,60 @@ const setItemsParamsSchema = z.object({
|
|
|
772
772
|
setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
|
|
773
773
|
belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
|
|
774
774
|
propertyVariableUuids: z.array(uuidSchema).default([]),
|
|
775
|
-
queries: z.array(z.
|
|
776
|
-
|
|
777
|
-
"
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
775
|
+
queries: z.array(z.union([
|
|
776
|
+
z.object({
|
|
777
|
+
target: z.literal("propertyValue"),
|
|
778
|
+
dataType: z.enum([
|
|
779
|
+
"string",
|
|
780
|
+
"integer",
|
|
781
|
+
"decimal",
|
|
782
|
+
"boolean",
|
|
783
|
+
"time",
|
|
784
|
+
"IDREF"
|
|
785
|
+
]),
|
|
786
|
+
value: z.string(),
|
|
787
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
788
|
+
isCaseSensitive: z.boolean(),
|
|
789
|
+
language: z.string().default("eng"),
|
|
790
|
+
operator: z.enum(["AND", "OR"]).optional()
|
|
791
|
+
}).strict(),
|
|
792
|
+
z.object({
|
|
793
|
+
target: z.literal("propertyValue"),
|
|
794
|
+
dataType: z.enum(["date", "dateTime"]),
|
|
795
|
+
value: z.string(),
|
|
796
|
+
from: z.string(),
|
|
797
|
+
to: z.string().optional(),
|
|
798
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
799
|
+
isCaseSensitive: z.boolean(),
|
|
800
|
+
language: z.string().default("eng"),
|
|
801
|
+
operator: z.enum(["AND", "OR"]).optional()
|
|
802
|
+
}).strict(),
|
|
803
|
+
z.object({
|
|
804
|
+
target: z.literal("propertyValue"),
|
|
805
|
+
dataType: z.enum(["date", "dateTime"]),
|
|
806
|
+
value: z.string(),
|
|
807
|
+
from: z.string().optional(),
|
|
808
|
+
to: z.string(),
|
|
809
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
810
|
+
isCaseSensitive: z.boolean(),
|
|
811
|
+
language: z.string().default("eng"),
|
|
812
|
+
operator: z.enum(["AND", "OR"]).optional()
|
|
813
|
+
}).strict(),
|
|
814
|
+
z.object({
|
|
815
|
+
target: z.enum([
|
|
816
|
+
"title",
|
|
817
|
+
"description",
|
|
818
|
+
"image",
|
|
819
|
+
"periods",
|
|
820
|
+
"bibliography"
|
|
821
|
+
]),
|
|
822
|
+
value: z.string(),
|
|
823
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
824
|
+
isCaseSensitive: z.boolean(),
|
|
825
|
+
language: z.string().default("eng"),
|
|
826
|
+
operator: z.enum(["AND", "OR"]).optional()
|
|
827
|
+
}).strict()
|
|
828
|
+
])).default([]),
|
|
790
829
|
page: z.number().min(1, "Page must be positive").default(1),
|
|
791
830
|
pageSize: z.number().min(1, "Page size must be positive").default(DEFAULT_PAGE_SIZE)
|
|
792
831
|
}).superRefine((value, ctx) => {
|
|
@@ -2073,42 +2112,72 @@ function buildStringMatchPredicate(params) {
|
|
|
2073
2112
|
return `${comparedPath} = ${comparedValueLiteral}`;
|
|
2074
2113
|
}
|
|
2075
2114
|
/**
|
|
2115
|
+
* Build a date/dateTime range predicate for an XQuery string.
|
|
2116
|
+
*/
|
|
2117
|
+
function buildDateRangePredicate(params) {
|
|
2118
|
+
const { from, to } = params;
|
|
2119
|
+
const conditions = [];
|
|
2120
|
+
if (from != null) conditions.push(`(value/@rawValue ge ${stringLiteral(from)})`);
|
|
2121
|
+
if (to != null) conditions.push(`(value/@rawValue le ${stringLiteral(to)})`);
|
|
2122
|
+
return conditions.join(" and ");
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Build a property value predicate for an XQuery string
|
|
2126
|
+
* @param query - The propertyValue query
|
|
2127
|
+
* @returns The property value predicate
|
|
2128
|
+
*/
|
|
2129
|
+
function buildPropertyValuePredicate(query) {
|
|
2130
|
+
if (query.dataType === "IDREF") return `.//properties//property[value[@uuid=${stringLiteral(query.value)}]]`;
|
|
2131
|
+
if (query.dataType === "date" || query.dataType === "dateTime") return `.//properties//property[(label/@uuid=${stringLiteral(query.value)}) and ${buildDateRangePredicate({
|
|
2132
|
+
from: query.from,
|
|
2133
|
+
to: query.to
|
|
2134
|
+
})}]`;
|
|
2135
|
+
if (query.dataType === "time" || query.dataType === "integer" || query.dataType === "decimal" || query.dataType === "boolean") return `.//properties//property[value[@rawValue=${stringLiteral(query.value)}]]`;
|
|
2136
|
+
return `.//properties//property[${buildStringMatchPredicate({
|
|
2137
|
+
path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2138
|
+
value: query.value,
|
|
2139
|
+
matchMode: query.matchMode,
|
|
2140
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2141
|
+
})}]`;
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2076
2144
|
* Build a query predicate for an XQuery string
|
|
2077
2145
|
* @param query - The query to build the predicate for
|
|
2078
2146
|
* @returns The query predicate
|
|
2079
2147
|
*/
|
|
2080
2148
|
function buildQueryPredicate(query) {
|
|
2081
|
-
const stringMatchParams = {
|
|
2082
|
-
value: query.value,
|
|
2083
|
-
matchMode: query.matchMode,
|
|
2084
|
-
isCaseSensitive: query.isCaseSensitive,
|
|
2085
|
-
language: query.language
|
|
2086
|
-
};
|
|
2087
2149
|
switch (query.target) {
|
|
2088
2150
|
case "title": return buildStringMatchPredicate({
|
|
2089
2151
|
path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2090
|
-
|
|
2152
|
+
value: query.value,
|
|
2153
|
+
matchMode: query.matchMode,
|
|
2154
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2091
2155
|
});
|
|
2092
2156
|
case "description": return buildStringMatchPredicate({
|
|
2093
2157
|
path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2094
|
-
|
|
2158
|
+
value: query.value,
|
|
2159
|
+
matchMode: query.matchMode,
|
|
2160
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2095
2161
|
});
|
|
2096
2162
|
case "periods": return buildStringMatchPredicate({
|
|
2097
2163
|
path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2098
|
-
|
|
2164
|
+
value: query.value,
|
|
2165
|
+
matchMode: query.matchMode,
|
|
2166
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2099
2167
|
});
|
|
2100
2168
|
case "bibliography": return buildStringMatchPredicate({
|
|
2101
2169
|
path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2102
|
-
|
|
2170
|
+
value: query.value,
|
|
2171
|
+
matchMode: query.matchMode,
|
|
2172
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2103
2173
|
});
|
|
2104
2174
|
case "image": return buildStringMatchPredicate({
|
|
2105
2175
|
path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2106
|
-
|
|
2176
|
+
value: query.value,
|
|
2177
|
+
matchMode: query.matchMode,
|
|
2178
|
+
isCaseSensitive: query.isCaseSensitive
|
|
2107
2179
|
});
|
|
2108
|
-
case "propertyValue": return
|
|
2109
|
-
path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2110
|
-
...stringMatchParams
|
|
2111
|
-
})}]`;
|
|
2180
|
+
case "propertyValue": return buildPropertyValuePredicate(query);
|
|
2112
2181
|
}
|
|
2113
2182
|
}
|
|
2114
2183
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.2",
|
|
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",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@antfu/eslint-config": "^7.6.1",
|
|
50
|
-
"@types/node": "^24.10.
|
|
50
|
+
"@types/node": "^24.10.14",
|
|
51
51
|
"bumpp": "^10.4.1",
|
|
52
52
|
"eslint": "^10.0.2",
|
|
53
53
|
"prettier": "^3.8.1",
|