ochre-sdk 0.19.14 → 0.20.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/index.d.mts +22 -21
- package/dist/index.mjs +168 -92
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -643,6 +643,17 @@ type PropertyValueQueryItem = {
|
|
|
643
643
|
content: string | number | boolean | null;
|
|
644
644
|
label: string | null;
|
|
645
645
|
};
|
|
646
|
+
/**
|
|
647
|
+
* Represents a query for Set items
|
|
648
|
+
*/
|
|
649
|
+
type Query = {
|
|
650
|
+
target: "title" | "description" | "image" | "periods" | "bibliography" | "propertyValue";
|
|
651
|
+
value: string;
|
|
652
|
+
matchMode: "includes" | "exact";
|
|
653
|
+
isCaseSensitive: boolean;
|
|
654
|
+
language: string;
|
|
655
|
+
operator?: "AND" | "OR";
|
|
656
|
+
};
|
|
646
657
|
//#endregion
|
|
647
658
|
//#region src/types/website.d.ts
|
|
648
659
|
/**
|
|
@@ -1144,48 +1155,38 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
|
|
|
1144
1155
|
item: never;
|
|
1145
1156
|
}>;
|
|
1146
1157
|
//#endregion
|
|
1147
|
-
//#region src/utils/fetchers/set/items
|
|
1158
|
+
//#region src/utils/fetchers/set/items.d.ts
|
|
1148
1159
|
/**
|
|
1149
|
-
* Fetches and parses items
|
|
1160
|
+
* Fetches and parses Set items from the OCHRE API
|
|
1150
1161
|
*
|
|
1151
1162
|
* @param params - The parameters for the fetch
|
|
1152
1163
|
* @param params.setScopeUuids - The Set scope UUIDs to filter by
|
|
1153
1164
|
* @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
|
|
1154
|
-
* @param params.propertyVariableUuids - The property variable UUIDs to
|
|
1155
|
-
* @param params.
|
|
1165
|
+
* @param params.propertyVariableUuids - The property variable UUIDs to filter by
|
|
1166
|
+
* @param params.queries - Ordered queries to combine with AND/OR
|
|
1156
1167
|
* @param params.page - The page number (1-indexed)
|
|
1157
1168
|
* @param params.pageSize - The number of items per page
|
|
1158
|
-
* @param
|
|
1159
|
-
* @param categoryParams - The category parameters for the fetch
|
|
1160
|
-
* @param categoryParams.category - The category of the items to fetch
|
|
1161
|
-
* @param categoryParams.itemCategories - The categories of the items to fetch
|
|
1169
|
+
* @param itemCategories - The categories of the items to fetch
|
|
1162
1170
|
* @param options - Options for the fetch
|
|
1163
1171
|
* @param options.fetch - The fetch function to use
|
|
1164
1172
|
* @param options.version - The version of the OCHRE API to use
|
|
1165
|
-
* @returns The parsed items
|
|
1173
|
+
* @returns The parsed Set items or null if the fetch/parse fails
|
|
1166
1174
|
*/
|
|
1167
|
-
declare function
|
|
1175
|
+
declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategory>>(params: {
|
|
1168
1176
|
setScopeUuids: Array<string>;
|
|
1169
1177
|
belongsToCollectionScopeUuids: Array<string>;
|
|
1170
1178
|
propertyVariableUuids: Array<string>;
|
|
1171
|
-
|
|
1172
|
-
dataType: Exclude<PropertyValueContentType, "coordinate">;
|
|
1173
|
-
value: string;
|
|
1174
|
-
}>;
|
|
1179
|
+
queries: Array<Query>;
|
|
1175
1180
|
page: number;
|
|
1176
1181
|
pageSize?: number;
|
|
1177
|
-
|
|
1178
|
-
}, categoryParams?: {
|
|
1179
|
-
category?: T;
|
|
1180
|
-
itemCategories?: U;
|
|
1181
|
-
}, options?: {
|
|
1182
|
+
}, itemCategories?: U, options?: {
|
|
1182
1183
|
fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
1183
1184
|
version?: ApiVersion;
|
|
1184
1185
|
}): Promise<{
|
|
1185
1186
|
totalCount: number;
|
|
1186
1187
|
page: number;
|
|
1187
1188
|
pageSize: number;
|
|
1188
|
-
items: Array<Item<
|
|
1189
|
+
items: Array<Item<"set", U>>;
|
|
1189
1190
|
error: null;
|
|
1190
1191
|
} | {
|
|
1191
1192
|
totalCount: null;
|
|
@@ -1382,4 +1383,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
|
|
|
1382
1383
|
*/
|
|
1383
1384
|
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>;
|
|
1384
1385
|
//#endregion
|
|
1385
|
-
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, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem,
|
|
1386
|
+
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, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/dist/index.mjs
CHANGED
|
@@ -551,6 +551,14 @@ function parseOptionalDate(dateTime) {
|
|
|
551
551
|
function cleanObject(object) {
|
|
552
552
|
return Object.fromEntries(Object.entries(object).filter(([_, value]) => value != null));
|
|
553
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Build a string literal for an XQuery string
|
|
556
|
+
* @param value - The string value to escape
|
|
557
|
+
* @returns The escaped string literal
|
|
558
|
+
*/
|
|
559
|
+
function stringLiteral(value) {
|
|
560
|
+
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
561
|
+
}
|
|
554
562
|
|
|
555
563
|
//#endregion
|
|
556
564
|
//#region src/utils/helpers.ts
|
|
@@ -593,24 +601,23 @@ function flattenItemProperties(item) {
|
|
|
593
601
|
* @internal
|
|
594
602
|
*/
|
|
595
603
|
const uuidSchema = z.string().refine(isPseudoUuid, { error: "Invalid pseudo-UUID" });
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
604
|
+
const fakeStringSchema = z.union([
|
|
605
|
+
z.string(),
|
|
606
|
+
z.number(),
|
|
607
|
+
z.boolean()
|
|
608
|
+
]);
|
|
609
|
+
const richTextStringContentSchema = z.union([fakeStringSchema, z.object({
|
|
610
|
+
content: fakeStringSchema.optional(),
|
|
602
611
|
rend: z.string().optional(),
|
|
603
612
|
whitespace: z.string().optional()
|
|
604
|
-
});
|
|
613
|
+
})]);
|
|
605
614
|
/**
|
|
606
615
|
* Schema for validating rich text string content
|
|
607
616
|
* @internal
|
|
608
617
|
*/
|
|
609
618
|
const richTextStringSchema = z.object({
|
|
610
619
|
string: z.union([
|
|
611
|
-
|
|
612
|
-
z.number(),
|
|
613
|
-
z.boolean(),
|
|
620
|
+
fakeStringSchema,
|
|
614
621
|
richTextStringContentSchema,
|
|
615
622
|
z.array(richTextStringContentSchema)
|
|
616
623
|
]),
|
|
@@ -761,30 +768,48 @@ const setPropertyValuesByPropertyVariablesParamsSchema = z.object({
|
|
|
761
768
|
belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
|
|
762
769
|
propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required")
|
|
763
770
|
});
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
"
|
|
771
|
-
"
|
|
772
|
-
"
|
|
773
|
-
"
|
|
774
|
-
"
|
|
775
|
-
"
|
|
771
|
+
const setItemsParamsSchema = z.object({
|
|
772
|
+
setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
|
|
773
|
+
belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
|
|
774
|
+
propertyVariableUuids: z.array(uuidSchema).default([]),
|
|
775
|
+
queries: z.array(z.object({
|
|
776
|
+
target: z.enum([
|
|
777
|
+
"title",
|
|
778
|
+
"description",
|
|
779
|
+
"image",
|
|
780
|
+
"periods",
|
|
781
|
+
"bibliography",
|
|
782
|
+
"propertyValue"
|
|
776
783
|
]),
|
|
777
|
-
value: z.string()
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
]
|
|
787
|
-
|
|
784
|
+
value: z.string(),
|
|
785
|
+
matchMode: z.enum(["includes", "exact"]),
|
|
786
|
+
isCaseSensitive: z.boolean(),
|
|
787
|
+
language: z.string().default("eng"),
|
|
788
|
+
operator: z.enum(["AND", "OR"]).optional()
|
|
789
|
+
})).default([]),
|
|
790
|
+
page: z.number().min(1, "Page must be positive").default(1),
|
|
791
|
+
pageSize: z.number().min(1, "Page size must be positive").default(DEFAULT_PAGE_SIZE)
|
|
792
|
+
}).superRefine((value, ctx) => {
|
|
793
|
+
for (const [index, query] of value.queries.entries()) {
|
|
794
|
+
if (index === 0 && query.operator != null) ctx.addIssue({
|
|
795
|
+
code: "custom",
|
|
796
|
+
path: [
|
|
797
|
+
"queries",
|
|
798
|
+
index,
|
|
799
|
+
"operator"
|
|
800
|
+
],
|
|
801
|
+
message: "The first query rule must not include an operator"
|
|
802
|
+
});
|
|
803
|
+
if (index > 0 && query.operator == null) ctx.addIssue({
|
|
804
|
+
code: "custom",
|
|
805
|
+
path: [
|
|
806
|
+
"queries",
|
|
807
|
+
index,
|
|
808
|
+
"operator"
|
|
809
|
+
],
|
|
810
|
+
message: "Query rules after the first must include an operator"
|
|
811
|
+
});
|
|
812
|
+
}
|
|
788
813
|
});
|
|
789
814
|
|
|
790
815
|
//#endregion
|
|
@@ -859,12 +884,12 @@ function parseMetadata(metadata) {
|
|
|
859
884
|
page: metadata.project?.page ?? null
|
|
860
885
|
} : null,
|
|
861
886
|
collection: metadata.collection ? {
|
|
862
|
-
uuid: metadata.collection
|
|
887
|
+
uuid: metadata.collection.uuid,
|
|
863
888
|
identification: parseIdentification(metadata.collection.identification),
|
|
864
889
|
page: metadata.collection.page
|
|
865
890
|
} : null,
|
|
866
891
|
publication: metadata.publication ? {
|
|
867
|
-
uuid: metadata.publication
|
|
892
|
+
uuid: metadata.publication.uuid,
|
|
868
893
|
identification: parseIdentification(metadata.publication.identification),
|
|
869
894
|
page: metadata.publication.page
|
|
870
895
|
} : null,
|
|
@@ -2030,132 +2055,189 @@ async function fetchItem(uuid, category, itemCategories, options) {
|
|
|
2030
2055
|
}
|
|
2031
2056
|
|
|
2032
2057
|
//#endregion
|
|
2033
|
-
//#region src/utils/fetchers/set/items
|
|
2058
|
+
//#region src/utils/fetchers/set/items.ts
|
|
2059
|
+
/**
|
|
2060
|
+
* Build a string match predicate for an XQuery string
|
|
2061
|
+
* @param params - The parameters for the predicate
|
|
2062
|
+
* @param params.path - The path to the string
|
|
2063
|
+
* @param params.value - The value to match
|
|
2064
|
+
* @param params.matchMode - The match mode (includes or exact)
|
|
2065
|
+
* @param params.isCaseSensitive - Whether to match case-sensitively
|
|
2066
|
+
* @returns The string match predicate
|
|
2067
|
+
*/
|
|
2068
|
+
function buildStringMatchPredicate(params) {
|
|
2069
|
+
const { path, value, matchMode, isCaseSensitive } = params;
|
|
2070
|
+
const comparedPath = isCaseSensitive ? path : `lower-case(${path})`;
|
|
2071
|
+
const comparedValueLiteral = stringLiteral(isCaseSensitive ? value : value.toLowerCase());
|
|
2072
|
+
if (matchMode === "includes") return `contains(${comparedPath}, ${comparedValueLiteral})`;
|
|
2073
|
+
return `${comparedPath} = ${comparedValueLiteral}`;
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Build a query predicate for an XQuery string
|
|
2077
|
+
* @param query - The query to build the predicate for
|
|
2078
|
+
* @returns The query predicate
|
|
2079
|
+
*/
|
|
2080
|
+
function buildQueryPredicate(query) {
|
|
2081
|
+
const stringMatchParams = {
|
|
2082
|
+
value: query.value,
|
|
2083
|
+
matchMode: query.matchMode,
|
|
2084
|
+
isCaseSensitive: query.isCaseSensitive,
|
|
2085
|
+
language: query.language
|
|
2086
|
+
};
|
|
2087
|
+
switch (query.target) {
|
|
2088
|
+
case "title": return buildStringMatchPredicate({
|
|
2089
|
+
path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2090
|
+
...stringMatchParams
|
|
2091
|
+
});
|
|
2092
|
+
case "description": return buildStringMatchPredicate({
|
|
2093
|
+
path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2094
|
+
...stringMatchParams
|
|
2095
|
+
});
|
|
2096
|
+
case "periods": return buildStringMatchPredicate({
|
|
2097
|
+
path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2098
|
+
...stringMatchParams
|
|
2099
|
+
});
|
|
2100
|
+
case "bibliography": return buildStringMatchPredicate({
|
|
2101
|
+
path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2102
|
+
...stringMatchParams
|
|
2103
|
+
});
|
|
2104
|
+
case "image": return buildStringMatchPredicate({
|
|
2105
|
+
path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2106
|
+
...stringMatchParams
|
|
2107
|
+
});
|
|
2108
|
+
case "propertyValue": return `.//properties//property[${buildStringMatchPredicate({
|
|
2109
|
+
path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
|
|
2110
|
+
...stringMatchParams
|
|
2111
|
+
})}]`;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2034
2114
|
/**
|
|
2035
|
-
* Build an XQuery string to fetch items
|
|
2115
|
+
* Build an XQuery string to fetch Set items from the OCHRE API
|
|
2036
2116
|
* @param params - The parameters for the fetch
|
|
2037
2117
|
* @param params.setScopeUuids - An array of Set scope UUIDs to filter by
|
|
2038
2118
|
* @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
|
|
2039
|
-
* @param params.propertyVariableUuids - An array of property variable UUIDs to
|
|
2040
|
-
* @param params.
|
|
2119
|
+
* @param params.propertyVariableUuids - An array of property variable UUIDs to filter by
|
|
2120
|
+
* @param params.queries - Ordered queries to combine with AND/OR
|
|
2041
2121
|
* @param params.page - The page number (1-indexed)
|
|
2042
2122
|
* @param params.pageSize - The number of items per page
|
|
2043
|
-
* @param params.includeChildItems - Whether to include child items of the same category
|
|
2044
2123
|
* @param options - Options for the fetch
|
|
2045
2124
|
* @param options.version - The version of the OCHRE API to use
|
|
2046
2125
|
* @returns An XQuery string
|
|
2047
2126
|
*/
|
|
2048
2127
|
function buildXQuery$1(params, options) {
|
|
2049
2128
|
const version = options?.version ?? DEFAULT_API_VERSION;
|
|
2050
|
-
const { propertyVariableUuids,
|
|
2129
|
+
const { propertyVariableUuids, queries, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = params;
|
|
2051
2130
|
const startPosition = (page - 1) * pageSize + 1;
|
|
2052
2131
|
const endPosition = page * pageSize;
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2132
|
+
const setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
|
|
2133
|
+
const queryFilters = queries.map((query, index) => {
|
|
2134
|
+
const predicate = `(${buildQueryPredicate(query)})`;
|
|
2135
|
+
if (index === 0) return predicate;
|
|
2136
|
+
return `${query.operator === "OR" ? "or" : "and"} ${predicate}`;
|
|
2137
|
+
}).join(" ");
|
|
2138
|
+
const filterPredicates = [];
|
|
2139
|
+
if (belongsToCollectionScopeUuids.length > 0) {
|
|
2140
|
+
const belongsToCollectionScopeValues = belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
|
|
2141
|
+
filterPredicates.push(`.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeValues})]]`);
|
|
2142
|
+
}
|
|
2143
|
+
if (propertyVariableUuids.length > 0) {
|
|
2144
|
+
const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
|
|
2145
|
+
filterPredicates.push(`.//properties//property[label[${propertyVariables}]]`);
|
|
2146
|
+
}
|
|
2147
|
+
if (queryFilters.length > 0) filterPredicates.push(`(${queryFilters})`);
|
|
2148
|
+
const itemFilters = filterPredicates.length > 0 ? `[${filterPredicates.join(" and ")}]` : "";
|
|
2063
2149
|
return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
|
|
2064
2150
|
${setScopeFilter}
|
|
2065
|
-
${
|
|
2066
|
-
//property[label[${propertyVariables}]][${propertyValuesFilters}]]
|
|
2151
|
+
${itemFilters}
|
|
2067
2152
|
|
|
2068
2153
|
let $totalCount := count($items)
|
|
2069
2154
|
|
|
2070
2155
|
return <items totalCount="{$totalCount}" page="${page}" pageSize="${pageSize}">{
|
|
2071
2156
|
for $item in $items[position() ge ${startPosition} and position() le ${endPosition}]
|
|
2072
|
-
let $category := local-name($item)
|
|
2073
2157
|
return element { node-name($item) } {
|
|
2074
|
-
$item/@*, $
|
|
2158
|
+
$item/@*, $item/node()
|
|
2075
2159
|
}
|
|
2076
2160
|
}</items>`}}</ochre>`;
|
|
2077
2161
|
}
|
|
2078
2162
|
/**
|
|
2079
|
-
* Fetches and parses items
|
|
2163
|
+
* Fetches and parses Set items from the OCHRE API
|
|
2080
2164
|
*
|
|
2081
2165
|
* @param params - The parameters for the fetch
|
|
2082
2166
|
* @param params.setScopeUuids - The Set scope UUIDs to filter by
|
|
2083
2167
|
* @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
|
|
2084
|
-
* @param params.propertyVariableUuids - The property variable UUIDs to
|
|
2085
|
-
* @param params.
|
|
2168
|
+
* @param params.propertyVariableUuids - The property variable UUIDs to filter by
|
|
2169
|
+
* @param params.queries - Ordered queries to combine with AND/OR
|
|
2086
2170
|
* @param params.page - The page number (1-indexed)
|
|
2087
2171
|
* @param params.pageSize - The number of items per page
|
|
2088
|
-
* @param
|
|
2089
|
-
* @param categoryParams - The category parameters for the fetch
|
|
2090
|
-
* @param categoryParams.category - The category of the items to fetch
|
|
2091
|
-
* @param categoryParams.itemCategories - The categories of the items to fetch
|
|
2172
|
+
* @param itemCategories - The categories of the items to fetch
|
|
2092
2173
|
* @param options - Options for the fetch
|
|
2093
2174
|
* @param options.fetch - The fetch function to use
|
|
2094
2175
|
* @param options.version - The version of the OCHRE API to use
|
|
2095
|
-
* @returns The parsed items
|
|
2176
|
+
* @returns The parsed Set items or null if the fetch/parse fails
|
|
2096
2177
|
*/
|
|
2097
|
-
async function
|
|
2178
|
+
async function fetchSetItems(params, itemCategories, options) {
|
|
2098
2179
|
try {
|
|
2099
2180
|
const version = options?.version ?? DEFAULT_API_VERSION;
|
|
2100
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids,
|
|
2101
|
-
const { category, itemCategories } = categoryParams ?? {};
|
|
2181
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, queries, page, pageSize } = setItemsParamsSchema.parse(params);
|
|
2102
2182
|
const xquery = buildXQuery$1({
|
|
2103
2183
|
setScopeUuids,
|
|
2104
2184
|
belongsToCollectionScopeUuids,
|
|
2105
2185
|
propertyVariableUuids,
|
|
2106
|
-
|
|
2107
|
-
includeChildItems,
|
|
2186
|
+
queries,
|
|
2108
2187
|
page,
|
|
2109
2188
|
pageSize
|
|
2110
2189
|
}, { version });
|
|
2111
2190
|
const response = await (options?.fetch ?? fetch)(version === 2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"`);
|
|
2112
2191
|
if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
|
|
2113
2192
|
const data = await response.json();
|
|
2114
|
-
if (Array.isArray(data.result) || Object.keys(data.result
|
|
2115
|
-
if (
|
|
2116
|
-
|
|
2193
|
+
if (Array.isArray(data.result) || Object.keys(data.result).length === 0) throw new Error("No items found");
|
|
2194
|
+
if (itemCategories != null) {
|
|
2195
|
+
const itemCategoriesSet = new Set(Object.keys(data.result.ochre.items));
|
|
2196
|
+
const missingCategories = itemCategories.filter((category) => !itemCategoriesSet.has(category));
|
|
2197
|
+
if (missingCategories.length > 0) throw new Error(`No Set items found for item categories: ${missingCategories.join(", ")}`);
|
|
2198
|
+
}
|
|
2117
2199
|
const items = [];
|
|
2118
|
-
if ("resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
|
|
2200
|
+
if ((itemCategories == null || itemCategories.includes("resource")) && "resource" in data.result.ochre.items && data.result.ochre.items.resource != null) {
|
|
2119
2201
|
const resources = parseResources(Array.isArray(data.result.ochre.items.resource) ? data.result.ochre.items.resource : [data.result.ochre.items.resource]);
|
|
2120
2202
|
items.push(...resources);
|
|
2121
2203
|
}
|
|
2122
|
-
if ("spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
|
|
2204
|
+
if ((itemCategories == null || itemCategories.includes("spatialUnit")) && "spatialUnit" in data.result.ochre.items && data.result.ochre.items.spatialUnit != null) {
|
|
2123
2205
|
const spatialUnits = parseSpatialUnits(Array.isArray(data.result.ochre.items.spatialUnit) ? data.result.ochre.items.spatialUnit : [data.result.ochre.items.spatialUnit]);
|
|
2124
2206
|
items.push(...spatialUnits);
|
|
2125
2207
|
}
|
|
2126
|
-
if ("concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
|
|
2208
|
+
if ((itemCategories == null || itemCategories.includes("concept")) && "concept" in data.result.ochre.items && data.result.ochre.items.concept != null) {
|
|
2127
2209
|
const concepts = parseConcepts(Array.isArray(data.result.ochre.items.concept) ? data.result.ochre.items.concept : [data.result.ochre.items.concept]);
|
|
2128
2210
|
items.push(...concepts);
|
|
2129
2211
|
}
|
|
2130
|
-
if ("period" in data.result.ochre.items && data.result.ochre.items.period != null) {
|
|
2212
|
+
if ((itemCategories == null || itemCategories.includes("period")) && "period" in data.result.ochre.items && data.result.ochre.items.period != null) {
|
|
2131
2213
|
const periods = parsePeriods(Array.isArray(data.result.ochre.items.period) ? data.result.ochre.items.period : [data.result.ochre.items.period]);
|
|
2132
2214
|
items.push(...periods);
|
|
2133
2215
|
}
|
|
2134
|
-
if ("bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
|
|
2216
|
+
if ((itemCategories == null || itemCategories.includes("bibliography")) && "bibliography" in data.result.ochre.items && data.result.ochre.items.bibliography != null) {
|
|
2135
2217
|
const bibliographies = parseBibliographies(Array.isArray(data.result.ochre.items.bibliography) ? data.result.ochre.items.bibliography : [data.result.ochre.items.bibliography]);
|
|
2136
2218
|
items.push(...bibliographies);
|
|
2137
2219
|
}
|
|
2138
|
-
if ("person" in data.result.ochre.items && data.result.ochre.items.person != null) {
|
|
2220
|
+
if ((itemCategories == null || itemCategories.includes("person")) && "person" in data.result.ochre.items && data.result.ochre.items.person != null) {
|
|
2139
2221
|
const persons = parsePersons(Array.isArray(data.result.ochre.items.person) ? data.result.ochre.items.person : [data.result.ochre.items.person]);
|
|
2140
2222
|
items.push(...persons);
|
|
2141
2223
|
}
|
|
2142
|
-
if ("propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
|
|
2224
|
+
if ((itemCategories == null || itemCategories.includes("propertyVariable")) && "propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
|
|
2143
2225
|
const propertyVariables = parsePropertyVariables(Array.isArray(data.result.ochre.items.propertyVariable) ? data.result.ochre.items.propertyVariable : [data.result.ochre.items.propertyVariable]);
|
|
2144
2226
|
items.push(...propertyVariables);
|
|
2145
2227
|
}
|
|
2146
|
-
if ("propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
|
|
2228
|
+
if ((itemCategories == null || itemCategories.includes("propertyValue")) && "propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
|
|
2147
2229
|
const propertyValues = parsePropertyValues(Array.isArray(data.result.ochre.items.propertyValue) ? data.result.ochre.items.propertyValue : [data.result.ochre.items.propertyValue]);
|
|
2148
2230
|
items.push(...propertyValues);
|
|
2149
2231
|
}
|
|
2150
|
-
if ("text" in data.result.ochre.items && data.result.ochre.items.text != null) {
|
|
2232
|
+
if ((itemCategories == null || itemCategories.includes("text")) && "text" in data.result.ochre.items && data.result.ochre.items.text != null) {
|
|
2151
2233
|
const texts = parseTexts(Array.isArray(data.result.ochre.items.text) ? data.result.ochre.items.text : [data.result.ochre.items.text]);
|
|
2152
2234
|
items.push(...texts);
|
|
2153
2235
|
}
|
|
2154
|
-
if ("set" in data.result.ochre.items && data.result.ochre.items.set != null) {
|
|
2236
|
+
if ((itemCategories == null || itemCategories.includes("set")) && "set" in data.result.ochre.items && data.result.ochre.items.set != null) {
|
|
2155
2237
|
const sets = parseSets(Array.isArray(data.result.ochre.items.set) ? data.result.ochre.items.set : [data.result.ochre.items.set]);
|
|
2156
2238
|
items.push(...sets);
|
|
2157
2239
|
}
|
|
2158
|
-
if ("tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
|
|
2240
|
+
if ((itemCategories == null || itemCategories.includes("tree")) && "tree" in data.result.ochre.items && data.result.ochre.items.tree != null) {
|
|
2159
2241
|
const trees = parseTrees(Array.isArray(data.result.ochre.items.tree) ? data.result.ochre.items.tree : [data.result.ochre.items.tree]);
|
|
2160
2242
|
items.push(...trees);
|
|
2161
2243
|
}
|
|
@@ -2173,7 +2255,7 @@ async function fetchSetItemsByPropertyValues(params, categoryParams, options) {
|
|
|
2173
2255
|
page: null,
|
|
2174
2256
|
pageSize: null,
|
|
2175
2257
|
items: null,
|
|
2176
|
-
error: error instanceof Error ? error.message : "Failed to fetch items
|
|
2258
|
+
error: error instanceof Error ? error.message : "Failed to fetch Set items"
|
|
2177
2259
|
};
|
|
2178
2260
|
}
|
|
2179
2261
|
}
|
|
@@ -2187,15 +2269,9 @@ const propertyValueQueryItemSchema = z.object({
|
|
|
2187
2269
|
uuid: z.string(),
|
|
2188
2270
|
itemUuid: z.string().optional(),
|
|
2189
2271
|
dataType: z.string(),
|
|
2190
|
-
rawValue:
|
|
2191
|
-
z.string(),
|
|
2192
|
-
z.number(),
|
|
2193
|
-
z.boolean()
|
|
2194
|
-
]).optional(),
|
|
2272
|
+
rawValue: fakeStringSchema.optional(),
|
|
2195
2273
|
content: z.union([
|
|
2196
|
-
|
|
2197
|
-
z.number(),
|
|
2198
|
-
z.boolean(),
|
|
2274
|
+
fakeStringSchema,
|
|
2199
2275
|
richTextStringSchema,
|
|
2200
2276
|
z.array(richTextStringSchema)
|
|
2201
2277
|
]).optional()
|
|
@@ -3915,4 +3991,4 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
3915
3991
|
}
|
|
3916
3992
|
|
|
3917
3993
|
//#endregion
|
|
3918
|
-
export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem,
|
|
3994
|
+
export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
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",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"zod": "^4.3.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@antfu/eslint-config": "^7.
|
|
49
|
+
"@antfu/eslint-config": "^7.6.1",
|
|
50
50
|
"@types/node": "^24.10.13",
|
|
51
51
|
"bumpp": "^10.4.1",
|
|
52
|
-
"eslint": "^10.0.
|
|
52
|
+
"eslint": "^10.0.2",
|
|
53
53
|
"prettier": "^3.8.1",
|
|
54
54
|
"tsdown": "^0.20.3",
|
|
55
55
|
"typescript": "^5.9.3",
|