ochre-sdk 1.3.11 → 1.3.13
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/README.md +1 -4
- package/dist/constants.mjs +3 -0
- package/dist/fetchers/item-locations.d.mts +41 -0
- package/dist/fetchers/item-locations.mjs +99 -0
- package/dist/fetchers/map-layers.d.mts +30 -0
- package/dist/fetchers/map-layers.mjs +161 -0
- package/dist/fetchers/website.mjs +10 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -2
- package/dist/parsers/index.d.mts +3 -2
- package/dist/parsers/index.mjs +17 -8
- package/dist/parsers/website/components.mjs +8 -3
- package/dist/parsers/website/index.mjs +5 -2
- package/dist/parsers/website/styles.d.mts +2 -2
- package/dist/parsers/website/styles.mjs +1 -0
- package/dist/schemas.d.mts +13 -4
- package/dist/schemas.mjs +8 -6
- package/dist/types/index.d.mts +30 -1
- package/dist/types/website.d.mts +5 -3
- package/dist/xml/schemas.d.mts +329 -10
- package/dist/xml/schemas.mjs +39 -17
- package/dist/xml/types.d.mts +36 -3
- package/package.json +3 -3
- package/dist/fetchers/set/item-locations.d.mts +0 -35
- package/dist/fetchers/set/item-locations.mjs +0 -83
package/dist/xml/schemas.mjs
CHANGED
|
@@ -191,6 +191,8 @@ const XMLCoordinate = v.variant("type", [v.object({
|
|
|
191
191
|
latitude: XMLNumber,
|
|
192
192
|
longitude: XMLNumber,
|
|
193
193
|
altitude: XMLOptionalNumber,
|
|
194
|
+
WKID: XMLOptionalNumber,
|
|
195
|
+
rawValue: v.optional(v.string("XMLCoordinates: rawValue is string and optional")),
|
|
194
196
|
source: v.optional(XMLCoordinatesSource)
|
|
195
197
|
}, "XMLCoordinates: Shape error"), v.object({
|
|
196
198
|
type: v.literal("plane", "XMLCoordinates: type is plane"),
|
|
@@ -205,6 +207,10 @@ const XMLCoordinate = v.variant("type", [v.object({
|
|
|
205
207
|
source: v.optional(XMLCoordinatesSource)
|
|
206
208
|
}, "XMLCoordinates: Shape error")], "XMLCoordinates: Shape error");
|
|
207
209
|
const XMLCoordinates = v.object({ coord: v.array(XMLCoordinate) }, "XMLCoordinates: Shape error");
|
|
210
|
+
const XMLMapData = v.optional(v.object({ geoJSON: v.object({
|
|
211
|
+
multiPolygon: v.object({ payload: v.string("XMLMapData: multiPolygon is string and required") }),
|
|
212
|
+
EPSG: XMLNumber
|
|
213
|
+
}) }, "XMLMapData: mapData is object with geoJSON"));
|
|
208
214
|
const XMLImage = v.object({
|
|
209
215
|
publicationDateTime: v.optional(customDateTime("XMLImage: publicationDateTime is not a valid datetime")),
|
|
210
216
|
identification: v.optional(XMLIdentification),
|
|
@@ -558,10 +564,7 @@ const XMLSpatialUnit = v.object({
|
|
|
558
564
|
...XMLBaseItem.entries,
|
|
559
565
|
image: v.optional(XMLImage),
|
|
560
566
|
coordinates: v.optional(XMLCoordinates),
|
|
561
|
-
mapData:
|
|
562
|
-
multiPolygon: v.object({ payload: v.string("XMLSpatialUnit: multiPolygon is string and required") }),
|
|
563
|
-
EPSG: XMLNumber
|
|
564
|
-
}) }, "XMLSpatialUnit: mapData is object with geoJSON")),
|
|
567
|
+
mapData: XMLMapData,
|
|
565
568
|
observations: v.optional(v.object({ observation: v.array(XMLObservation) })),
|
|
566
569
|
observation: v.optional(v.array(XMLObservation)),
|
|
567
570
|
properties: v.optional(v.object({ property: v.array(XMLProperty) })),
|
|
@@ -928,21 +931,39 @@ const XMLSetItems = v.intersect([XMLItemLinks, v.object({
|
|
|
928
931
|
pageSize: XMLNumber
|
|
929
932
|
}, "XMLSetItems: Shape error")]);
|
|
930
933
|
const XMLSetItemsData = v.object({ result: v.object({ ochre: v.object({ items: XMLSetItems }, "XMLSetItemsData: ochre") }) }, "XMLSetItemsData: Shape error");
|
|
931
|
-
const
|
|
932
|
-
uuid: v.string("
|
|
933
|
-
category: v.string("
|
|
934
|
-
|
|
934
|
+
const XMLItemLocation = v.object({
|
|
935
|
+
uuid: v.string("XMLItemLocation: uuid is string and required"),
|
|
936
|
+
category: v.string("XMLItemLocation: category is string and required"),
|
|
937
|
+
scopeUuid: v.string("XMLItemLocation: scopeUuid is string and required"),
|
|
938
|
+
publicationDateTime: v.optional(customDateTime("XMLItemLocation: publicationDateTime is not a valid datetime")),
|
|
935
939
|
identification: XMLIdentification,
|
|
936
940
|
coordinates: v.optional(XMLCoordinates),
|
|
941
|
+
mapData: XMLMapData,
|
|
937
942
|
value: v.optional(v.array(v.intersect([v.object({
|
|
938
|
-
variable: v.string("
|
|
939
|
-
uuid: v.string("
|
|
940
|
-
}, "
|
|
941
|
-
}, "
|
|
942
|
-
const
|
|
943
|
+
variable: v.string("XMLItemLocation: value variable is string and required"),
|
|
944
|
+
uuid: v.string("XMLItemLocation: value uuid is string and required")
|
|
945
|
+
}, "XMLItemLocation: value is object with variable and uuid"), XMLContent])))
|
|
946
|
+
}, "XMLItemLocation: Shape error");
|
|
947
|
+
const XMLItemLocationsData = v.object({ result: v.object({ ochre: v.object({ items: v.object({
|
|
943
948
|
totalCount: XMLNumber,
|
|
944
|
-
itemLocation: v.optional(v.array(
|
|
945
|
-
}, "
|
|
949
|
+
itemLocation: v.optional(v.array(XMLItemLocation, "XMLItemLocationsData: itemLocation is array of XMLItemLocation"))
|
|
950
|
+
}, "XMLItemLocationsData: items is object with totalCount") }, "XMLItemLocationsData: ochre") }) }, "XMLItemLocationsData: Shape error");
|
|
951
|
+
const XMLMapLayer = v.object({
|
|
952
|
+
uuid: v.string("XMLMapLayer: uuid is string and required"),
|
|
953
|
+
category: v.string("XMLMapLayer: category is string and required"),
|
|
954
|
+
type: v.optional(v.string("XMLMapLayer: type is string and optional")),
|
|
955
|
+
href: v.optional(v.string("XMLMapLayer: href is string and optional")),
|
|
956
|
+
WKID: XMLOptionalNumber,
|
|
957
|
+
identification: XMLIdentification
|
|
958
|
+
}, "XMLMapLayer: Shape error");
|
|
959
|
+
const XMLMapSource = v.object({
|
|
960
|
+
uuid: v.string("XMLMapSource: uuid is string and required"),
|
|
961
|
+
category: v.string("XMLMapSource: category is string and required"),
|
|
962
|
+
WKID: XMLOptionalNumber,
|
|
963
|
+
identification: XMLIdentification,
|
|
964
|
+
mapLayer: v.optional(v.array(XMLMapLayer, "XMLMapSource: mapLayer is array of XMLMapLayer"))
|
|
965
|
+
}, "XMLMapSource: Shape error");
|
|
966
|
+
const XMLMapSourcesData = v.object({ result: v.object({ ochre: v.object({ mapSources: v.object({ mapSource: v.optional(v.array(XMLMapSource, "XMLMapSourcesData: mapSource is array of XMLMapSource")) }, "XMLMapSourcesData: mapSources is object") }, "XMLMapSourcesData: ochre") }) }, "XMLMapSourcesData: Shape error");
|
|
946
967
|
const XMLData = v.object({ result: v.object({ ochre: v.intersect([v.object({
|
|
947
968
|
uuid: v.pipe(v.string("XMLData: uuid is string and required"), v.check(isPseudoUuid, "XMLData: uuid is not a valid pseudo-UUID")),
|
|
948
969
|
belongsTo: v.string("XMLData: belongsTo is string and required"),
|
|
@@ -958,7 +979,8 @@ const XMLWebsiteData = v.object({ result: v.object({ ochre: v.object({
|
|
|
958
979
|
publicationDateTime: customDateTime("XMLWebsiteData: publicationDateTime is not a valid datetime"),
|
|
959
980
|
metadata: XMLMetadata,
|
|
960
981
|
persistentUrl: v.optional(v.pipe(v.string("XMLWebsiteData: persistentUrl is string and optional"), v.url("XMLWebsiteData: persistentUrl is not a valid URL"))),
|
|
961
|
-
tree: v.array(XMLWebsiteTree)
|
|
982
|
+
tree: v.array(XMLWebsiteTree),
|
|
983
|
+
styleLabels: v.optional(v.object({ styleLabel: v.optional(v.array(v.intersect([v.object({ valueUuid: v.string("XMLWebsiteData: styleLabel valueUuid is string and required") }, "XMLWebsiteData: styleLabel is object with valueUuid"), XMLContent]))) }))
|
|
962
984
|
}, "XMLWebsiteData: ochre is object with website tree") }, "XMLWebsiteData: result is object with ochre") }, "XMLWebsiteData: Shape error");
|
|
963
985
|
//#endregion
|
|
964
|
-
export { XMLData, XMLDataItem, XMLGalleryData, XMLItemLinksData, XMLLink,
|
|
986
|
+
export { XMLData, XMLDataItem, XMLGalleryData, XMLItemLinksData, XMLItemLocationsData, XMLLink, XMLMapSourcesData, XMLSetItemsData, XMLWebsiteData };
|
package/dist/xml/types.d.mts
CHANGED
|
@@ -139,6 +139,8 @@ export type XMLCoordinate = {
|
|
|
139
139
|
latitude: number;
|
|
140
140
|
longitude: number;
|
|
141
141
|
altitude?: number;
|
|
142
|
+
WKID?: number;
|
|
143
|
+
rawValue?: string;
|
|
142
144
|
source?: XMLCoordinatesSource;
|
|
143
145
|
} | {
|
|
144
146
|
type: "plane";
|
|
@@ -887,23 +889,49 @@ export type XMLSetItemsData = {
|
|
|
887
889
|
};
|
|
888
890
|
};
|
|
889
891
|
};
|
|
890
|
-
export type
|
|
892
|
+
export type XMLItemLocation = {
|
|
891
893
|
uuid: string;
|
|
892
894
|
category: string;
|
|
895
|
+
scopeUuid: string;
|
|
893
896
|
publicationDateTime?: Date;
|
|
894
897
|
identification: XMLIdentification;
|
|
895
898
|
coordinates?: XMLCoordinates;
|
|
899
|
+
mapData?: XMLSpatialUnit["mapData"];
|
|
896
900
|
value?: Array<{
|
|
897
901
|
variable: string;
|
|
898
902
|
uuid: string;
|
|
899
903
|
} & XMLContent>;
|
|
900
904
|
};
|
|
901
|
-
export type
|
|
905
|
+
export type XMLItemLocationsData = {
|
|
902
906
|
result: {
|
|
903
907
|
ochre: {
|
|
904
908
|
items: {
|
|
905
909
|
totalCount: number;
|
|
906
|
-
itemLocation?: Array<
|
|
910
|
+
itemLocation?: Array<XMLItemLocation>;
|
|
911
|
+
};
|
|
912
|
+
};
|
|
913
|
+
};
|
|
914
|
+
};
|
|
915
|
+
export type XMLMapLayer = {
|
|
916
|
+
uuid: string;
|
|
917
|
+
category: string;
|
|
918
|
+
type?: string;
|
|
919
|
+
href?: string;
|
|
920
|
+
WKID?: number;
|
|
921
|
+
identification: XMLIdentification;
|
|
922
|
+
};
|
|
923
|
+
export type XMLMapSource = {
|
|
924
|
+
uuid: string;
|
|
925
|
+
category: string;
|
|
926
|
+
WKID?: number;
|
|
927
|
+
identification: XMLIdentification;
|
|
928
|
+
mapLayer?: Array<XMLMapLayer>;
|
|
929
|
+
};
|
|
930
|
+
export type XMLMapSourcesData = {
|
|
931
|
+
result: {
|
|
932
|
+
ochre: {
|
|
933
|
+
mapSources: {
|
|
934
|
+
mapSource?: Array<XMLMapSource>;
|
|
907
935
|
};
|
|
908
936
|
};
|
|
909
937
|
};
|
|
@@ -930,6 +958,11 @@ export type XMLWebsiteData = {
|
|
|
930
958
|
metadata: XMLMetadata;
|
|
931
959
|
persistentUrl?: string;
|
|
932
960
|
tree: Array<XMLWebsiteTree>;
|
|
961
|
+
styleLabels?: {
|
|
962
|
+
styleLabel?: Array<{
|
|
963
|
+
valueUuid: string;
|
|
964
|
+
} & XMLContent>;
|
|
965
|
+
};
|
|
933
966
|
};
|
|
934
967
|
};
|
|
935
968
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
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",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"scripts": {
|
|
67
67
|
"dev": "tsdown src/index.ts --watch",
|
|
68
68
|
"build": "tsdown",
|
|
69
|
-
"lint": "knip && eslint
|
|
70
|
-
"lint:fix": "knip --fix && eslint --
|
|
69
|
+
"lint": "knip && eslint .",
|
|
70
|
+
"lint:fix": "knip --fix && eslint --fix .",
|
|
71
71
|
"format": "oxfmt --check",
|
|
72
72
|
"format:fix": "oxfmt",
|
|
73
73
|
"check-types": "tsc --noEmit",
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Query, SetItemLocation } from "../../types/index.mjs";
|
|
2
|
-
import { FetchBaseOptions, FetchLanguages } from "../../parsers/helpers.mjs";
|
|
3
|
-
//#region src/fetchers/set/item-locations.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Fetches the location of every Set item that matches a query, without paging
|
|
6
|
-
*
|
|
7
|
-
* Each item carries only its identification, its publication date, its coordinates and the values of
|
|
8
|
-
* the requested property variables (inherited values included), which is what a
|
|
9
|
-
* map needs to draw and colour every match while a list pages through the same
|
|
10
|
-
* query with {@link fetchSetItems}.
|
|
11
|
-
*
|
|
12
|
-
* @param parameters - The parameters for the fetch
|
|
13
|
-
* @param parameters.setScopeUuids - The Set scope UUIDs to filter by
|
|
14
|
-
* @param parameters.queries - Recursive query tree used to filter matching items
|
|
15
|
-
* @param parameters.propertyVariableUuids - The property variables whose values each item should carry
|
|
16
|
-
* @param options - Options for the fetch
|
|
17
|
-
* @param options.fetch - The fetch function to use
|
|
18
|
-
* @returns The item locations, or an error if the fetch/parse fails
|
|
19
|
-
*/
|
|
20
|
-
export declare function fetchSetItemLocations<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
|
|
21
|
-
setScopeUuids: Array<string>;
|
|
22
|
-
queries?: Query | null;
|
|
23
|
-
propertyVariableUuids?: Array<string>;
|
|
24
|
-
}, options?: FetchBaseOptions<TLanguages>): Promise<{
|
|
25
|
-
totalCount: number;
|
|
26
|
-
items: Array<SetItemLocation<FetchLanguages<TLanguages>>>;
|
|
27
|
-
error: null;
|
|
28
|
-
detailedError: null;
|
|
29
|
-
} | {
|
|
30
|
-
totalCount: null;
|
|
31
|
-
items: null;
|
|
32
|
-
error: string;
|
|
33
|
-
detailedError: string;
|
|
34
|
-
}>;
|
|
35
|
-
//#endregion
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { normalizeItemCategory } from "../../categories.mjs";
|
|
2
|
-
import { getErrorOutput } from "../../errors.mjs";
|
|
3
|
-
import { requestOchre } from "../request.mjs";
|
|
4
|
-
import { setItemLocationsParametersSchema } from "../../schemas.mjs";
|
|
5
|
-
import { parseRequiredContentLike } from "../../parsers/helpers.mjs";
|
|
6
|
-
import { parseRequestedLanguages, resolveContentLanguages } from "../../parsers/languages.mjs";
|
|
7
|
-
import { parseCoordinates, parseIdentification } from "../../parsers/index.mjs";
|
|
8
|
-
import { XMLSetItemLocationsData } from "../../xml/schemas.mjs";
|
|
9
|
-
import { getContentLanguage, stringLiteral } from "../../xquery.mjs";
|
|
10
|
-
import { compileContainerItemsQuery } from "../../query.mjs";
|
|
11
|
-
import * as v from "valibot";
|
|
12
|
-
//#region src/fetchers/set/item-locations.ts
|
|
13
|
-
async function fetchSetItemLocations(parameters, options) {
|
|
14
|
-
try {
|
|
15
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyVariableUuids } = v.parse(setItemLocationsParametersSchema, parameters);
|
|
16
|
-
const output = await requestOchre({
|
|
17
|
-
xquery: compileContainerItemsQuery({
|
|
18
|
-
container: "set",
|
|
19
|
-
scopeUuids: setScopeUuids,
|
|
20
|
-
belongsToCollectionScopeUuids,
|
|
21
|
-
queries,
|
|
22
|
-
contentLanguage: getContentLanguage(options),
|
|
23
|
-
body: ({ items }) => ` let $propertyVariableUuids := (${Array.from(propertyVariableUuids, (uuid) => stringLiteral(uuid)).join(", ")})
|
|
24
|
-
|
|
25
|
-
return <items totalCount="{count(${items})}">{
|
|
26
|
-
for $item in ${items}
|
|
27
|
-
return <itemLocation uuid="{$item/@uuid}" category="{local-name($item)}">{
|
|
28
|
-
$item/@publicationDateTime,
|
|
29
|
-
$item/identification,
|
|
30
|
-
$item/coordinates,
|
|
31
|
-
for $value in $item//properties//property[label/@uuid = $propertyVariableUuids]/value[@uuid]
|
|
32
|
-
return <value variable="{$value/../label/@uuid}" uuid="{$value/@uuid}">{$value/content}</value>
|
|
33
|
-
}</itemLocation>
|
|
34
|
-
}</items>`
|
|
35
|
-
}),
|
|
36
|
-
schema: XMLSetItemLocationsData,
|
|
37
|
-
label: "OCHRE Set item locations",
|
|
38
|
-
options
|
|
39
|
-
});
|
|
40
|
-
const languages = resolveContentLanguages(output.result.ochre.items, parseRequestedLanguages(options?.languages));
|
|
41
|
-
const itemsByUuid = /* @__PURE__ */ new Map();
|
|
42
|
-
const itemLocations = output.result.ochre.items.itemLocation ?? [];
|
|
43
|
-
for (const itemLocation of itemLocations) {
|
|
44
|
-
const category = normalizeItemCategory(itemLocation.category);
|
|
45
|
-
if (category == null || itemsByUuid.has(itemLocation.uuid)) continue;
|
|
46
|
-
const propertyValues = [];
|
|
47
|
-
const seenPropertyValues = /* @__PURE__ */ new Set();
|
|
48
|
-
const values = itemLocation.value ?? [];
|
|
49
|
-
for (const value of values) {
|
|
50
|
-
const key = `${value.variable}:${value.uuid}`;
|
|
51
|
-
if (seenPropertyValues.has(key)) continue;
|
|
52
|
-
seenPropertyValues.add(key);
|
|
53
|
-
propertyValues.push({
|
|
54
|
-
variableUuid: value.variable,
|
|
55
|
-
valueUuid: value.uuid,
|
|
56
|
-
label: parseRequiredContentLike(value, { languages })
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
itemsByUuid.set(itemLocation.uuid, {
|
|
60
|
-
uuid: itemLocation.uuid,
|
|
61
|
-
category,
|
|
62
|
-
publicationDateTime: itemLocation.publicationDateTime ?? null,
|
|
63
|
-
identification: parseIdentification(itemLocation.identification, { languages }),
|
|
64
|
-
coordinates: parseCoordinates(itemLocation.coordinates, { languages }),
|
|
65
|
-
propertyValues
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
totalCount: output.result.ochre.items.totalCount,
|
|
70
|
-
items: itemsByUuid.values().toArray(),
|
|
71
|
-
error: null,
|
|
72
|
-
detailedError: null
|
|
73
|
-
};
|
|
74
|
-
} catch (error) {
|
|
75
|
-
return {
|
|
76
|
-
totalCount: null,
|
|
77
|
-
items: null,
|
|
78
|
-
...getErrorOutput(error, "Failed to fetch Set item locations")
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
//#endregion
|
|
83
|
-
export { fetchSetItemLocations };
|