ochre-sdk 1.0.78 → 1.1.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/README.md +31 -3
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/categories.d.mts +249 -0
- package/dist/categories.mjs +259 -0
- package/dist/constants.d.mts +14 -0
- package/dist/constants.mjs +18 -1
- package/dist/errors.d.mts +23 -0
- package/dist/{utilities.mjs → errors.mjs} +33 -84
- package/dist/fetchers/gallery.mjs +15 -51
- package/dist/fetchers/item-children.mjs +20 -66
- package/dist/fetchers/item-links.mjs +26 -79
- package/dist/fetchers/item-ocr-data.d.mts +2 -2
- package/dist/fetchers/item-ocr-data.mjs +11 -15
- package/dist/fetchers/item.d.mts +0 -15
- package/dist/fetchers/item.mjs +20 -72
- package/dist/fetchers/request.d.mts +70 -0
- package/dist/fetchers/request.mjs +100 -0
- package/dist/fetchers/set/items.mjs +27 -73
- package/dist/fetchers/set/property-values.d.mts +2 -3
- package/dist/fetchers/set/property-values.mjs +96 -130
- package/dist/fetchers/website-metadata.mjs +35 -57
- package/dist/fetchers/website.d.mts +2 -3
- package/dist/fetchers/website.mjs +22 -31
- package/dist/getters.d.mts +78 -148
- package/dist/getters.mjs +127 -208
- package/dist/helpers.d.mts +0 -4
- package/dist/helpers.mjs +19 -6
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +6 -4
- package/dist/ocr.d.mts +37 -0
- package/dist/ocr.mjs +52 -0
- package/dist/parsers/helpers.d.mts +21 -1
- package/dist/parsers/helpers.mjs +26 -6
- package/dist/parsers/index.d.mts +0 -8
- package/dist/parsers/index.mjs +118 -259
- package/dist/parsers/languages.d.mts +72 -0
- package/dist/parsers/languages.mjs +132 -0
- package/dist/parsers/multilingual.d.mts +49 -74
- package/dist/parsers/multilingual.mjs +88 -189
- package/dist/parsers/property-token.d.mts +34 -0
- package/dist/parsers/property-token.mjs +29 -0
- package/dist/parsers/string.d.mts +19 -0
- package/dist/parsers/string.mjs +45 -25
- package/dist/parsers/website/bounds.d.mts +10 -0
- package/dist/parsers/website/bounds.mjs +28 -0
- package/dist/parsers/website/components.d.mts +91 -0
- package/dist/parsers/website/components.mjs +681 -0
- package/dist/parsers/website/index.d.mts +0 -7
- package/dist/parsers/website/index.mjs +92 -1153
- package/dist/parsers/website/links.d.mts +36 -0
- package/dist/parsers/website/links.mjs +58 -0
- package/dist/parsers/website/messages.d.mts +24 -0
- package/dist/parsers/website/messages.mjs +31 -0
- package/dist/parsers/website/options.d.mts +6 -0
- package/dist/parsers/website/options.mjs +114 -0
- package/dist/parsers/website/properties.d.mts +12 -0
- package/dist/parsers/website/properties.mjs +158 -0
- package/dist/parsers/website/reader.d.mts +54 -4
- package/dist/parsers/website/reader.mjs +65 -20
- package/dist/parsers/website/slug.d.mts +64 -0
- package/dist/parsers/website/slug.mjs +82 -0
- package/dist/parsers/website/styles.d.mts +28 -0
- package/dist/parsers/website/styles.mjs +103 -0
- package/dist/parsers/website/walk.d.mts +68 -0
- package/dist/parsers/website/walk.mjs +116 -0
- package/dist/query.d.mts +66 -18
- package/dist/query.mjs +202 -48
- package/dist/reflection.d.mts +64 -0
- package/dist/reflection.mjs +79 -0
- package/dist/schemas.d.mts +7 -0
- package/dist/schemas.mjs +12 -3
- package/dist/types/index.d.mts +1 -31
- package/dist/types/utilities.d.mts +9 -0
- package/dist/types/utilities.mjs +1 -0
- package/dist/types/website.d.mts +49 -58
- package/dist/xml/metadata.d.mts +16 -0
- package/dist/xml/metadata.mjs +32 -11
- package/dist/xml/schemas.d.mts +5970 -3
- package/dist/xml/schemas.mjs +43 -45
- package/dist/xml/types.d.mts +13 -30
- package/dist/xquery.d.mts +46 -0
- package/dist/xquery.mjs +66 -0
- package/package.json +3 -3
- package/dist/utilities.d.mts +0 -54
package/README.md
CHANGED
|
@@ -176,12 +176,40 @@ types, query types, property getters, and small data helpers:
|
|
|
176
176
|
|
|
177
177
|
- `Item`, `SetItem`, `ItemLink`, `Website`, `WebElementOf`,
|
|
178
178
|
`WebElementComponentOf`, `WebBlockByLayout`, `Query`, and related types.
|
|
179
|
-
- `
|
|
180
|
-
`
|
|
181
|
-
|
|
179
|
+
- `getProperty`, `getPropertyValues`, `getPropertyValue`,
|
|
180
|
+
`getUniqueProperties`, `getUniquePropertyVariableLabels`, and
|
|
181
|
+
`isPropertyMatchingFilter` for reading properties off a parsed item.
|
|
182
182
|
- `flattenItemProperties` and `DEFAULT_PAGE_SIZE` for common collection UI
|
|
183
183
|
workflows.
|
|
184
184
|
|
|
185
|
+
### Property Access
|
|
186
|
+
|
|
187
|
+
Every property lookup takes a `PropertySelector`, which names a property either
|
|
188
|
+
by its variable UUID or by its variable label. A label can be narrowed by the
|
|
189
|
+
values the property carries.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { getProperty, getPropertyValue, getPropertyValues } from "ochre-sdk";
|
|
193
|
+
|
|
194
|
+
const properties = result.item.properties;
|
|
195
|
+
|
|
196
|
+
getProperty(properties, { uuid: "<variable-uuid>" });
|
|
197
|
+
getProperty(properties, { label: "Material" });
|
|
198
|
+
getProperty(properties, { label: "Material", valueContent: "Ceramic" });
|
|
199
|
+
|
|
200
|
+
getPropertyValues(properties, { label: "Material" });
|
|
201
|
+
getPropertyValue(properties, { label: "Material" })?.content;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Labels are matched case-insensitively, and spaces and underscores are treated
|
|
205
|
+
as hyphens, so `"Media type"`, `"media_type"` and `"media-type"` all name the
|
|
206
|
+
same property.
|
|
207
|
+
|
|
208
|
+
Pass `{ includeNestedProperties: true }` to descend into nested properties, and
|
|
209
|
+
`{ limitToLeafPropertyValues: false }` to keep non-leaf values. Leaf filtering
|
|
210
|
+
applies to `getPropertyValues` and `getPropertyValue`; `getProperty` returns a
|
|
211
|
+
property exactly as the item carries it.
|
|
212
|
+
|
|
185
213
|
## Development
|
|
186
214
|
|
|
187
215
|
The package source lives in `src/`, and `src/index.ts` is the public entrypoint.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { ContextItemCategory, HeadingItemCategory, ItemCategory, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemLinkCategory, TreeItemCategory } from "./types/index.mjs";
|
|
2
|
+
//#region src/categories.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every category an item hierarchy entry can carry, including the
|
|
5
|
+
* pseudo-category OCHRE uses to group entries
|
|
6
|
+
*/
|
|
7
|
+
export type HierarchyEntryCategory = ItemLinkCategory | "heading";
|
|
8
|
+
/**
|
|
9
|
+
* The one table describing the OCHRE item categories
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare const ITEM_CATEGORY_FACTS: {
|
|
13
|
+
readonly tree: {
|
|
14
|
+
readonly aliases: readonly ["tree"];
|
|
15
|
+
readonly label: "tree";
|
|
16
|
+
readonly hasCollection: true;
|
|
17
|
+
readonly isTreeItem: false;
|
|
18
|
+
readonly isSetItem: true;
|
|
19
|
+
readonly isHeadingItem: false;
|
|
20
|
+
readonly isContextItem: false;
|
|
21
|
+
readonly isContainer: true;
|
|
22
|
+
readonly hasEmbeddedItems: true;
|
|
23
|
+
};
|
|
24
|
+
readonly bibliography: {
|
|
25
|
+
readonly aliases: readonly ["bibliography"];
|
|
26
|
+
readonly label: "bibliography";
|
|
27
|
+
readonly hasCollection: true;
|
|
28
|
+
readonly isTreeItem: true;
|
|
29
|
+
readonly isSetItem: true;
|
|
30
|
+
readonly isHeadingItem: false;
|
|
31
|
+
readonly isContextItem: true;
|
|
32
|
+
readonly isContainer: false;
|
|
33
|
+
readonly hasEmbeddedItems: true;
|
|
34
|
+
};
|
|
35
|
+
readonly concept: {
|
|
36
|
+
readonly aliases: readonly ["concept"];
|
|
37
|
+
readonly label: "concept";
|
|
38
|
+
readonly hasCollection: true;
|
|
39
|
+
readonly isTreeItem: true;
|
|
40
|
+
readonly isSetItem: true;
|
|
41
|
+
readonly isHeadingItem: false;
|
|
42
|
+
readonly isContextItem: true;
|
|
43
|
+
readonly isContainer: false;
|
|
44
|
+
readonly hasEmbeddedItems: true;
|
|
45
|
+
};
|
|
46
|
+
readonly spatialUnit: {
|
|
47
|
+
readonly aliases: readonly ["spatialUnit"];
|
|
48
|
+
readonly label: "spatial unit";
|
|
49
|
+
readonly hasCollection: true;
|
|
50
|
+
readonly isTreeItem: true;
|
|
51
|
+
readonly isSetItem: true;
|
|
52
|
+
readonly isHeadingItem: false;
|
|
53
|
+
readonly isContextItem: true;
|
|
54
|
+
readonly isContainer: false;
|
|
55
|
+
readonly hasEmbeddedItems: true;
|
|
56
|
+
};
|
|
57
|
+
readonly period: {
|
|
58
|
+
readonly aliases: readonly ["period"];
|
|
59
|
+
readonly label: "period";
|
|
60
|
+
readonly hasCollection: true;
|
|
61
|
+
readonly isTreeItem: true;
|
|
62
|
+
readonly isSetItem: true;
|
|
63
|
+
readonly isHeadingItem: false;
|
|
64
|
+
readonly isContextItem: true;
|
|
65
|
+
readonly isContainer: false;
|
|
66
|
+
readonly hasEmbeddedItems: true;
|
|
67
|
+
};
|
|
68
|
+
readonly person: {
|
|
69
|
+
readonly aliases: readonly ["person"];
|
|
70
|
+
readonly label: "person";
|
|
71
|
+
readonly hasCollection: true;
|
|
72
|
+
readonly isTreeItem: true;
|
|
73
|
+
readonly isSetItem: true;
|
|
74
|
+
readonly isHeadingItem: true;
|
|
75
|
+
readonly isContextItem: false;
|
|
76
|
+
readonly isContainer: false;
|
|
77
|
+
readonly hasEmbeddedItems: false;
|
|
78
|
+
};
|
|
79
|
+
readonly propertyVariable: {
|
|
80
|
+
readonly aliases: readonly ["propertyVariable", "variable"];
|
|
81
|
+
readonly label: "property variable";
|
|
82
|
+
readonly hasCollection: true;
|
|
83
|
+
readonly isTreeItem: true;
|
|
84
|
+
readonly isSetItem: true;
|
|
85
|
+
readonly isHeadingItem: true;
|
|
86
|
+
readonly isContextItem: true;
|
|
87
|
+
readonly isContainer: false;
|
|
88
|
+
readonly hasEmbeddedItems: false;
|
|
89
|
+
};
|
|
90
|
+
readonly propertyValue: {
|
|
91
|
+
readonly aliases: readonly ["propertyValue", "value"];
|
|
92
|
+
readonly label: "property value";
|
|
93
|
+
readonly hasCollection: true;
|
|
94
|
+
readonly isTreeItem: true;
|
|
95
|
+
readonly isSetItem: true;
|
|
96
|
+
readonly isHeadingItem: true;
|
|
97
|
+
readonly isContextItem: true;
|
|
98
|
+
readonly isContainer: false;
|
|
99
|
+
readonly hasEmbeddedItems: false;
|
|
100
|
+
};
|
|
101
|
+
readonly resource: {
|
|
102
|
+
readonly aliases: readonly ["resource"];
|
|
103
|
+
readonly label: "resource";
|
|
104
|
+
readonly hasCollection: true;
|
|
105
|
+
readonly isTreeItem: true;
|
|
106
|
+
readonly isSetItem: true;
|
|
107
|
+
readonly isHeadingItem: true;
|
|
108
|
+
readonly isContextItem: true;
|
|
109
|
+
readonly isContainer: false;
|
|
110
|
+
readonly hasEmbeddedItems: true;
|
|
111
|
+
};
|
|
112
|
+
readonly text: {
|
|
113
|
+
readonly aliases: readonly ["text"];
|
|
114
|
+
readonly label: "text";
|
|
115
|
+
readonly hasCollection: true;
|
|
116
|
+
readonly isTreeItem: true;
|
|
117
|
+
readonly isSetItem: true;
|
|
118
|
+
readonly isHeadingItem: true;
|
|
119
|
+
readonly isContextItem: true;
|
|
120
|
+
readonly isContainer: false;
|
|
121
|
+
readonly hasEmbeddedItems: false;
|
|
122
|
+
};
|
|
123
|
+
readonly set: {
|
|
124
|
+
readonly aliases: readonly ["set"];
|
|
125
|
+
readonly label: "set";
|
|
126
|
+
readonly hasCollection: true;
|
|
127
|
+
readonly isTreeItem: true;
|
|
128
|
+
readonly isSetItem: true;
|
|
129
|
+
readonly isHeadingItem: true;
|
|
130
|
+
readonly isContextItem: false;
|
|
131
|
+
readonly isContainer: true;
|
|
132
|
+
readonly hasEmbeddedItems: true;
|
|
133
|
+
};
|
|
134
|
+
readonly dictionaryUnit: {
|
|
135
|
+
readonly aliases: readonly ["dictionaryUnit"];
|
|
136
|
+
readonly label: "dictionary unit";
|
|
137
|
+
readonly hasCollection: false;
|
|
138
|
+
readonly isTreeItem: false;
|
|
139
|
+
readonly isSetItem: false;
|
|
140
|
+
readonly isHeadingItem: false;
|
|
141
|
+
readonly isContextItem: false;
|
|
142
|
+
readonly isContainer: false;
|
|
143
|
+
readonly hasEmbeddedItems: false;
|
|
144
|
+
};
|
|
145
|
+
readonly heading: {
|
|
146
|
+
readonly aliases: readonly ["heading"];
|
|
147
|
+
readonly label: "heading";
|
|
148
|
+
readonly hasCollection: false;
|
|
149
|
+
readonly isTreeItem: false;
|
|
150
|
+
readonly isSetItem: false;
|
|
151
|
+
readonly isHeadingItem: false;
|
|
152
|
+
readonly isContextItem: false;
|
|
153
|
+
readonly isContainer: false;
|
|
154
|
+
readonly hasEmbeddedItems: false;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Every element name OCHRE serves an item category under, canonical name first
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
export declare const ITEM_CATEGORY_ALIASES: {
|
|
162
|
+
readonly tree: readonly ["tree"];
|
|
163
|
+
readonly bibliography: readonly ["bibliography"];
|
|
164
|
+
readonly concept: readonly ["concept"];
|
|
165
|
+
readonly spatialUnit: readonly ["spatialUnit"];
|
|
166
|
+
readonly period: readonly ["period"];
|
|
167
|
+
readonly person: readonly ["person"];
|
|
168
|
+
readonly propertyVariable: readonly ["propertyVariable", "variable"];
|
|
169
|
+
readonly propertyValue: readonly ["propertyValue", "value"];
|
|
170
|
+
readonly resource: readonly ["resource"];
|
|
171
|
+
readonly text: readonly ["text"];
|
|
172
|
+
readonly set: readonly ["set"];
|
|
173
|
+
readonly dictionaryUnit: readonly ["dictionaryUnit"];
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* The canonical category each element name maps to
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
export declare const ITEM_CATEGORY_BY_ALIAS: ReadonlyMap<string, HierarchyEntryCategory>;
|
|
180
|
+
/**
|
|
181
|
+
* The OCHRE collections an item document can live in
|
|
182
|
+
*
|
|
183
|
+
* Document URIs are bare item UUIDs, so a lookup by UUID does not need these.
|
|
184
|
+
* A search does: `fn:collection("ochre/<category>")`.
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
export declare const OCHRE_COLLECTION_CATEGORIES: Array<ItemCategory>;
|
|
188
|
+
/**
|
|
189
|
+
* The item categories that can sit directly inside a Tree
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
export declare const TREE_ITEM_CATEGORIES: Array<TreeItemCategory>;
|
|
193
|
+
/**
|
|
194
|
+
* The item categories that can sit directly inside a Set
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
export declare const SET_ITEM_CATEGORIES: Array<ItemCategory>;
|
|
198
|
+
/**
|
|
199
|
+
* The item categories that can sit under a heading
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
export declare const HEADING_ITEM_CATEGORIES: Array<HeadingItemCategory>;
|
|
203
|
+
/**
|
|
204
|
+
* The item categories that hold other items under a `containedItemCategory`
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
export declare const ITEM_CONTAINER_CATEGORIES: Array<ItemContainerCategory>;
|
|
208
|
+
/**
|
|
209
|
+
* The item categories that carry an embedded item hierarchy
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
export declare const ITEM_CATEGORIES_WITH_EMBEDDED_ITEMS: Array<ItemCategoryWithEmbeddedItems>;
|
|
213
|
+
/**
|
|
214
|
+
* Each element name that can appear in a context path, and the category it means
|
|
215
|
+
* @internal
|
|
216
|
+
*/
|
|
217
|
+
export declare const CONTEXT_CATEGORY_ALIASES: ReadonlyArray<{
|
|
218
|
+
alias: string;
|
|
219
|
+
category: ContextItemCategory;
|
|
220
|
+
}>;
|
|
221
|
+
/**
|
|
222
|
+
* Whether an item of this category holds other items
|
|
223
|
+
* @param category - The item category
|
|
224
|
+
* @returns True when the category accepts a `containedItemCategory`
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
export declare function isItemContainerCategory(category: ItemCategory): category is ItemContainerCategory;
|
|
228
|
+
/**
|
|
229
|
+
* Whether an item of this category carries an embedded item hierarchy
|
|
230
|
+
* @param category - The item category
|
|
231
|
+
* @returns True when the category exposes embedded items
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
export declare function isItemCategoryWithEmbeddedItems(category: ItemCategory): category is ItemCategoryWithEmbeddedItems;
|
|
235
|
+
/**
|
|
236
|
+
* Whether an item of this category can sit under a heading
|
|
237
|
+
* @param category - The item category
|
|
238
|
+
* @returns True when the category is allowed under a heading
|
|
239
|
+
* @internal
|
|
240
|
+
*/
|
|
241
|
+
export declare function isHeadingItemCategory(category: TreeItemCategory): category is HeadingItemCategory;
|
|
242
|
+
/**
|
|
243
|
+
* Resolve an OCHRE element name to the category it means
|
|
244
|
+
* @param category - The element name, which may be an alias
|
|
245
|
+
* @returns The canonical category, or null when the name is not one
|
|
246
|
+
* @internal
|
|
247
|
+
*/
|
|
248
|
+
export declare function normalizeItemCategory(category: string | undefined): ItemCategory | null;
|
|
249
|
+
//#endregion
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
//#region src/categories.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one table describing the OCHRE item categories
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
const ITEM_CATEGORY_FACTS = {
|
|
7
|
+
tree: {
|
|
8
|
+
aliases: ["tree"],
|
|
9
|
+
label: "tree",
|
|
10
|
+
hasCollection: true,
|
|
11
|
+
isTreeItem: false,
|
|
12
|
+
isSetItem: true,
|
|
13
|
+
isHeadingItem: false,
|
|
14
|
+
isContextItem: false,
|
|
15
|
+
isContainer: true,
|
|
16
|
+
hasEmbeddedItems: true
|
|
17
|
+
},
|
|
18
|
+
bibliography: {
|
|
19
|
+
aliases: ["bibliography"],
|
|
20
|
+
label: "bibliography",
|
|
21
|
+
hasCollection: true,
|
|
22
|
+
isTreeItem: true,
|
|
23
|
+
isSetItem: true,
|
|
24
|
+
isHeadingItem: false,
|
|
25
|
+
isContextItem: true,
|
|
26
|
+
isContainer: false,
|
|
27
|
+
hasEmbeddedItems: true
|
|
28
|
+
},
|
|
29
|
+
concept: {
|
|
30
|
+
aliases: ["concept"],
|
|
31
|
+
label: "concept",
|
|
32
|
+
hasCollection: true,
|
|
33
|
+
isTreeItem: true,
|
|
34
|
+
isSetItem: true,
|
|
35
|
+
isHeadingItem: false,
|
|
36
|
+
isContextItem: true,
|
|
37
|
+
isContainer: false,
|
|
38
|
+
hasEmbeddedItems: true
|
|
39
|
+
},
|
|
40
|
+
spatialUnit: {
|
|
41
|
+
aliases: ["spatialUnit"],
|
|
42
|
+
label: "spatial unit",
|
|
43
|
+
hasCollection: true,
|
|
44
|
+
isTreeItem: true,
|
|
45
|
+
isSetItem: true,
|
|
46
|
+
isHeadingItem: false,
|
|
47
|
+
isContextItem: true,
|
|
48
|
+
isContainer: false,
|
|
49
|
+
hasEmbeddedItems: true
|
|
50
|
+
},
|
|
51
|
+
period: {
|
|
52
|
+
aliases: ["period"],
|
|
53
|
+
label: "period",
|
|
54
|
+
hasCollection: true,
|
|
55
|
+
isTreeItem: true,
|
|
56
|
+
isSetItem: true,
|
|
57
|
+
isHeadingItem: false,
|
|
58
|
+
isContextItem: true,
|
|
59
|
+
isContainer: false,
|
|
60
|
+
hasEmbeddedItems: true
|
|
61
|
+
},
|
|
62
|
+
person: {
|
|
63
|
+
aliases: ["person"],
|
|
64
|
+
label: "person",
|
|
65
|
+
hasCollection: true,
|
|
66
|
+
isTreeItem: true,
|
|
67
|
+
isSetItem: true,
|
|
68
|
+
isHeadingItem: true,
|
|
69
|
+
isContextItem: false,
|
|
70
|
+
isContainer: false,
|
|
71
|
+
hasEmbeddedItems: false
|
|
72
|
+
},
|
|
73
|
+
propertyVariable: {
|
|
74
|
+
aliases: ["propertyVariable", "variable"],
|
|
75
|
+
label: "property variable",
|
|
76
|
+
hasCollection: true,
|
|
77
|
+
isTreeItem: true,
|
|
78
|
+
isSetItem: true,
|
|
79
|
+
isHeadingItem: true,
|
|
80
|
+
isContextItem: true,
|
|
81
|
+
isContainer: false,
|
|
82
|
+
hasEmbeddedItems: false
|
|
83
|
+
},
|
|
84
|
+
propertyValue: {
|
|
85
|
+
aliases: ["propertyValue", "value"],
|
|
86
|
+
label: "property value",
|
|
87
|
+
hasCollection: true,
|
|
88
|
+
isTreeItem: true,
|
|
89
|
+
isSetItem: true,
|
|
90
|
+
isHeadingItem: true,
|
|
91
|
+
isContextItem: true,
|
|
92
|
+
isContainer: false,
|
|
93
|
+
hasEmbeddedItems: false
|
|
94
|
+
},
|
|
95
|
+
resource: {
|
|
96
|
+
aliases: ["resource"],
|
|
97
|
+
label: "resource",
|
|
98
|
+
hasCollection: true,
|
|
99
|
+
isTreeItem: true,
|
|
100
|
+
isSetItem: true,
|
|
101
|
+
isHeadingItem: true,
|
|
102
|
+
isContextItem: true,
|
|
103
|
+
isContainer: false,
|
|
104
|
+
hasEmbeddedItems: true
|
|
105
|
+
},
|
|
106
|
+
text: {
|
|
107
|
+
aliases: ["text"],
|
|
108
|
+
label: "text",
|
|
109
|
+
hasCollection: true,
|
|
110
|
+
isTreeItem: true,
|
|
111
|
+
isSetItem: true,
|
|
112
|
+
isHeadingItem: true,
|
|
113
|
+
isContextItem: true,
|
|
114
|
+
isContainer: false,
|
|
115
|
+
hasEmbeddedItems: false
|
|
116
|
+
},
|
|
117
|
+
set: {
|
|
118
|
+
aliases: ["set"],
|
|
119
|
+
label: "set",
|
|
120
|
+
hasCollection: true,
|
|
121
|
+
isTreeItem: true,
|
|
122
|
+
isSetItem: true,
|
|
123
|
+
isHeadingItem: true,
|
|
124
|
+
isContextItem: false,
|
|
125
|
+
isContainer: true,
|
|
126
|
+
hasEmbeddedItems: true
|
|
127
|
+
},
|
|
128
|
+
dictionaryUnit: {
|
|
129
|
+
aliases: ["dictionaryUnit"],
|
|
130
|
+
label: "dictionary unit",
|
|
131
|
+
hasCollection: false,
|
|
132
|
+
isTreeItem: false,
|
|
133
|
+
isSetItem: false,
|
|
134
|
+
isHeadingItem: false,
|
|
135
|
+
isContextItem: false,
|
|
136
|
+
isContainer: false,
|
|
137
|
+
hasEmbeddedItems: false
|
|
138
|
+
},
|
|
139
|
+
heading: {
|
|
140
|
+
aliases: ["heading"],
|
|
141
|
+
label: "heading",
|
|
142
|
+
hasCollection: false,
|
|
143
|
+
isTreeItem: false,
|
|
144
|
+
isSetItem: false,
|
|
145
|
+
isHeadingItem: false,
|
|
146
|
+
isContextItem: false,
|
|
147
|
+
isContainer: false,
|
|
148
|
+
hasEmbeddedItems: false
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Every element name OCHRE serves an item category under, canonical name first
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
const ITEM_CATEGORY_ALIASES = {
|
|
156
|
+
tree: ITEM_CATEGORY_FACTS.tree.aliases,
|
|
157
|
+
bibliography: ITEM_CATEGORY_FACTS.bibliography.aliases,
|
|
158
|
+
concept: ITEM_CATEGORY_FACTS.concept.aliases,
|
|
159
|
+
spatialUnit: ITEM_CATEGORY_FACTS.spatialUnit.aliases,
|
|
160
|
+
period: ITEM_CATEGORY_FACTS.period.aliases,
|
|
161
|
+
person: ITEM_CATEGORY_FACTS.person.aliases,
|
|
162
|
+
propertyVariable: ITEM_CATEGORY_FACTS.propertyVariable.aliases,
|
|
163
|
+
propertyValue: ITEM_CATEGORY_FACTS.propertyValue.aliases,
|
|
164
|
+
resource: ITEM_CATEGORY_FACTS.resource.aliases,
|
|
165
|
+
text: ITEM_CATEGORY_FACTS.text.aliases,
|
|
166
|
+
set: ITEM_CATEGORY_FACTS.set.aliases,
|
|
167
|
+
dictionaryUnit: ITEM_CATEGORY_FACTS.dictionaryUnit.aliases
|
|
168
|
+
};
|
|
169
|
+
function categoriesWhere(isIncluded) {
|
|
170
|
+
const categories = [];
|
|
171
|
+
for (const [category, facts] of Object.entries(ITEM_CATEGORY_FACTS)) if (isIncluded(facts)) categories.push(category);
|
|
172
|
+
return categories;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The canonical category each element name maps to
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
const ITEM_CATEGORY_BY_ALIAS = new Map(Object.entries(ITEM_CATEGORY_FACTS).flatMap(([category, facts]) => facts.aliases.map((alias) => [alias, category])));
|
|
179
|
+
/**
|
|
180
|
+
* The OCHRE collections an item document can live in
|
|
181
|
+
*
|
|
182
|
+
* Document URIs are bare item UUIDs, so a lookup by UUID does not need these.
|
|
183
|
+
* A search does: `fn:collection("ochre/<category>")`.
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
const OCHRE_COLLECTION_CATEGORIES = categoriesWhere((facts) => facts.hasCollection);
|
|
187
|
+
/**
|
|
188
|
+
* The item categories that can sit directly inside a Tree
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
const TREE_ITEM_CATEGORIES = categoriesWhere((facts) => facts.isTreeItem);
|
|
192
|
+
/**
|
|
193
|
+
* The item categories that can sit directly inside a Set
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
const SET_ITEM_CATEGORIES = categoriesWhere((facts) => facts.isSetItem);
|
|
197
|
+
/**
|
|
198
|
+
* The item categories that can sit under a heading
|
|
199
|
+
* @internal
|
|
200
|
+
*/
|
|
201
|
+
const HEADING_ITEM_CATEGORIES = categoriesWhere((facts) => facts.isHeadingItem);
|
|
202
|
+
/**
|
|
203
|
+
* The item categories that hold other items under a `containedItemCategory`
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
const ITEM_CONTAINER_CATEGORIES = categoriesWhere((facts) => facts.isContainer);
|
|
207
|
+
/**
|
|
208
|
+
* The item categories that carry an embedded item hierarchy
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
const ITEM_CATEGORIES_WITH_EMBEDDED_ITEMS = categoriesWhere((facts) => facts.hasEmbeddedItems);
|
|
212
|
+
/**
|
|
213
|
+
* Each element name that can appear in a context path, and the category it means
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
const CONTEXT_CATEGORY_ALIASES = Object.entries(ITEM_CATEGORY_FACTS).flatMap(([category, facts]) => facts.isContextItem ? facts.aliases.map((alias) => ({
|
|
217
|
+
alias,
|
|
218
|
+
category
|
|
219
|
+
})) : []);
|
|
220
|
+
/**
|
|
221
|
+
* Whether an item of this category holds other items
|
|
222
|
+
* @param category - The item category
|
|
223
|
+
* @returns True when the category accepts a `containedItemCategory`
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
function isItemContainerCategory(category) {
|
|
227
|
+
return ITEM_CATEGORY_FACTS[category].isContainer;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Whether an item of this category carries an embedded item hierarchy
|
|
231
|
+
* @param category - The item category
|
|
232
|
+
* @returns True when the category exposes embedded items
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
235
|
+
function isItemCategoryWithEmbeddedItems(category) {
|
|
236
|
+
return ITEM_CATEGORY_FACTS[category].hasEmbeddedItems;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Whether an item of this category can sit under a heading
|
|
240
|
+
* @param category - The item category
|
|
241
|
+
* @returns True when the category is allowed under a heading
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
function isHeadingItemCategory(category) {
|
|
245
|
+
return ITEM_CATEGORY_FACTS[category].isHeadingItem;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Resolve an OCHRE element name to the category it means
|
|
249
|
+
* @param category - The element name, which may be an alias
|
|
250
|
+
* @returns The canonical category, or null when the name is not one
|
|
251
|
+
* @internal
|
|
252
|
+
*/
|
|
253
|
+
function normalizeItemCategory(category) {
|
|
254
|
+
if (category == null) return null;
|
|
255
|
+
const normalizedCategory = ITEM_CATEGORY_BY_ALIAS.get(category);
|
|
256
|
+
return normalizedCategory != null && ITEM_CATEGORY_FACTS[normalizedCategory].isSetItem ? normalizedCategory : null;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
export { CONTEXT_CATEGORY_ALIASES, HEADING_ITEM_CATEGORIES, ITEM_CATEGORIES_WITH_EMBEDDED_ITEMS, ITEM_CATEGORY_ALIASES, ITEM_CATEGORY_BY_ALIAS, ITEM_CATEGORY_FACTS, ITEM_CONTAINER_CATEGORIES, OCHRE_COLLECTION_CATEGORIES, SET_ITEM_CATEGORIES, TREE_ITEM_CATEGORIES, isHeadingItemCategory, isItemCategoryWithEmbeddedItems, isItemContainerCategory, normalizeItemCategory };
|
package/dist/constants.d.mts
CHANGED
|
@@ -3,6 +3,20 @@ import { X2jOptions } from "fast-xml-parser";
|
|
|
3
3
|
export declare const XML_ARRAY_TAGS: ReadonlyArray<string>;
|
|
4
4
|
export declare const XML_PARSER_OPTIONS: X2jOptions;
|
|
5
5
|
export declare const DEFAULT_LANGUAGES: readonly ["eng"];
|
|
6
|
+
/**
|
|
7
|
+
* The default page size to use for fetching paginated items
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_PAGE_SIZE = 48;
|
|
10
|
+
export declare const OCHRE_ENDPOINT = "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php";
|
|
11
|
+
export declare const PERMANENT_IDENTIFICATION_URL_PREFIX = "https://pi.lib.uchicago.edu/1001/org/ochre/";
|
|
12
|
+
/**
|
|
13
|
+
* Build the URL of an OCHRE item document
|
|
14
|
+
* @param uuid - The UUID of the OCHRE item
|
|
15
|
+
* @param searchParameters - Extra query string parameters to append
|
|
16
|
+
* @returns The item document URL
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function getOchreItemUrl(uuid: string, searchParameters?: string): string;
|
|
6
20
|
export declare const BELONGS_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
|
|
7
21
|
export declare const PRESENTATION_ITEM_UUID = "f1c131b6-1498-48a4-95bf-a9edae9fd518";
|
|
8
22
|
export declare const TEXT_ANNOTATION_UUID = "b9ca2732-78f4-416e-b77f-dae7647e68a9";
|
package/dist/constants.mjs
CHANGED
|
@@ -72,6 +72,23 @@ const XML_PARSER_OPTIONS = {
|
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
const DEFAULT_LANGUAGES = ["eng"];
|
|
75
|
+
/**
|
|
76
|
+
* The default page size to use for fetching paginated items
|
|
77
|
+
*/
|
|
78
|
+
const DEFAULT_PAGE_SIZE = 48;
|
|
79
|
+
const OCHRE_ENDPOINT = "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php";
|
|
80
|
+
const PERMANENT_IDENTIFICATION_URL_PREFIX = "https://pi.lib.uchicago.edu/1001/org/ochre/";
|
|
81
|
+
/**
|
|
82
|
+
* Build the URL of an OCHRE item document
|
|
83
|
+
* @param uuid - The UUID of the OCHRE item
|
|
84
|
+
* @param searchParameters - Extra query string parameters to append
|
|
85
|
+
* @returns The item document URL
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
function getOchreItemUrl(uuid, searchParameters) {
|
|
89
|
+
const suffix = searchParameters == null ? "" : `&${searchParameters}`;
|
|
90
|
+
return `${OCHRE_ENDPOINT}?uuid=${uuid}${suffix}`;
|
|
91
|
+
}
|
|
75
92
|
const BELONGS_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
|
|
76
93
|
const PRESENTATION_ITEM_UUID = "f1c131b6-1498-48a4-95bf-a9edae9fd518";
|
|
77
94
|
const TEXT_ANNOTATION_UUID = "b9ca2732-78f4-416e-b77f-dae7647e68a9";
|
|
@@ -82,4 +99,4 @@ const TEXT_ANNOTATION_TEXT_STYLING_UUID = "3e6f86ab-df81-45ae-8257-e2867357df56"
|
|
|
82
99
|
const TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID = "e1647bef-d801-4100-bdde-d081c422f763";
|
|
83
100
|
const TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID = "d4266f0b-3f8d-4b32-8c15-4b229c8bb11e";
|
|
84
101
|
//#endregion
|
|
85
|
-
export { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, PRESENTATION_ITEM_UUID, TEXT_ANNOTATION_ENTRY_PAGE_VARIANT_UUID, TEXT_ANNOTATION_HOVER_CARD_UUID, TEXT_ANNOTATION_ITEM_PAGE_VARIANT_UUID, TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID, TEXT_ANNOTATION_TEXT_STYLING_UUID, TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID, TEXT_ANNOTATION_UUID, XML_ARRAY_TAGS, XML_PARSER_OPTIONS };
|
|
102
|
+
export { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, DEFAULT_PAGE_SIZE, OCHRE_ENDPOINT, PERMANENT_IDENTIFICATION_URL_PREFIX, PRESENTATION_ITEM_UUID, TEXT_ANNOTATION_ENTRY_PAGE_VARIANT_UUID, TEXT_ANNOTATION_HOVER_CARD_UUID, TEXT_ANNOTATION_ITEM_PAGE_VARIANT_UUID, TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID, TEXT_ANNOTATION_TEXT_STYLING_UUID, TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID, TEXT_ANNOTATION_UUID, XML_ARRAY_TAGS, XML_PARSER_OPTIONS, getOchreItemUrl };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/errors.d.ts
|
|
3
|
+
type SchemaValidationIssue = v.BaseIssue<unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Render an error as a short message and a fully detailed report
|
|
6
|
+
* @param error - The thrown value
|
|
7
|
+
* @param fallbackMessage - The message to use when the value is not an Error
|
|
8
|
+
* @returns The message and the detailed report
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function getErrorOutput(error: unknown, fallbackMessage: string): {
|
|
12
|
+
error: string;
|
|
13
|
+
detailedError: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Wrap schema validation issues in an error {@link getErrorOutput} can render
|
|
17
|
+
* @param message - The failure message
|
|
18
|
+
* @param issues - The validation issues to carry as the cause
|
|
19
|
+
* @returns The error
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function createSchemaValidationError(message: string, issues: ReadonlyArray<SchemaValidationIssue>): Error;
|
|
23
|
+
//#endregion
|