@digitalculture/ochre-sdk 0.18.17 → 0.18.19
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 -154
- package/dist/index.mjs +72 -179
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -15,11 +15,11 @@ type Data<T extends DataCategory = DataCategory, U extends DataCategory | Array<
|
|
|
15
15
|
/**
|
|
16
16
|
* Represents the category of the data
|
|
17
17
|
*/
|
|
18
|
-
type DataCategory = "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue" | "text" | "tree" | "set";
|
|
18
|
+
type DataCategory = "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyVariable" | "propertyValue" | "text" | "tree" | "set";
|
|
19
19
|
/**
|
|
20
20
|
* Represents the item of the data, with proper type narrowing based on category
|
|
21
21
|
*/
|
|
22
|
-
type Item<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)> = T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyValue" ? PropertyValue : T extends "text" ? Text : T extends "tree" ? Tree<U extends Array<DataCategory> ? Exclude<U[number], "tree"> : Exclude<U, "tree">> : T extends "set" ? Set<U extends Array<DataCategory> ? U : Array<U>> : Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue | Tree<U extends Array<DataCategory> ? Exclude<U[number], "tree"> : Exclude<U, "tree">> | Set<U extends Array<DataCategory> ? U : Array<U>>;
|
|
22
|
+
type Item<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)> = T extends "resource" ? Resource : T extends "spatialUnit" ? SpatialUnit : T extends "concept" ? Concept : T extends "period" ? Period : T extends "bibliography" ? Bibliography : T extends "person" ? Person : T extends "propertyVariable" ? PropertyVariable : T extends "propertyValue" ? PropertyValue : T extends "text" ? Text : T extends "tree" ? Tree<U extends Array<DataCategory> ? Exclude<U[number], "tree"> : Exclude<U, "tree">> : T extends "set" ? Set<U extends Array<DataCategory> ? U : Array<U>> : Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyVariable | PropertyValue | Tree<U extends Array<DataCategory> ? Exclude<U[number], "tree"> : Exclude<U, "tree">> | Set<U extends Array<DataCategory> ? U : Array<U>>;
|
|
23
23
|
/**
|
|
24
24
|
* Basic identification information used across multiple types
|
|
25
25
|
*/
|
|
@@ -37,9 +37,15 @@ type Metadata = {
|
|
|
37
37
|
website: string | null;
|
|
38
38
|
};
|
|
39
39
|
dateFormat: string | null;
|
|
40
|
+
page: "item" | "entry" | null;
|
|
40
41
|
} | null;
|
|
41
42
|
collection: {
|
|
42
43
|
identification: Identification;
|
|
44
|
+
page: "item" | "entry";
|
|
45
|
+
} | null;
|
|
46
|
+
publication: {
|
|
47
|
+
identification: Identification;
|
|
48
|
+
page: "item" | "entry";
|
|
43
49
|
} | null;
|
|
44
50
|
item: {
|
|
45
51
|
identification: Identification;
|
|
@@ -406,7 +412,7 @@ type Set<U extends Array<DataCategory> = Array<DataCategory>> = {
|
|
|
406
412
|
isSuppressingBlanks: boolean;
|
|
407
413
|
description: string;
|
|
408
414
|
creators: Array<Person>;
|
|
409
|
-
items: [DataCategory] extends [U] ? Array<Item> : U extends "resource" ? Array<Resource> : U extends "spatialUnit" ? Array<SpatialUnit> : U extends "concept" ? Array<Concept> : U extends "period" ? Array<Period> : U extends "bibliography" ? Array<Bibliography> : U extends "person" ? Array<Person> : U extends "propertyValue" ? Array<PropertyValue> : U extends "tree" ? Array<Tree<Exclude<DataCategory, "tree">>> : U extends "set" ? Array<Set<Array<DataCategory>>> : Array<Item>;
|
|
415
|
+
items: [DataCategory] extends [U] ? Array<Item> : U extends "resource" ? Array<Resource> : U extends "spatialUnit" ? Array<SpatialUnit> : U extends "concept" ? Array<Concept> : U extends "period" ? Array<Period> : U extends "bibliography" ? Array<Bibliography> : U extends "person" ? Array<Person> : U extends "propertyVariable" ? Array<PropertyVariable> : U extends "propertyValue" ? Array<PropertyValue> : U extends "tree" ? Array<Tree<Exclude<DataCategory, "tree">>> : U extends "set" ? Array<Set<Array<DataCategory>>> : Array<Item>;
|
|
410
416
|
};
|
|
411
417
|
/**
|
|
412
418
|
* Represents a bibliography entry with citation and publication information
|
|
@@ -468,6 +474,25 @@ type Period = {
|
|
|
468
474
|
coordinates: Array<Coordinate>;
|
|
469
475
|
description: string | null;
|
|
470
476
|
};
|
|
477
|
+
/**
|
|
478
|
+
* Represents a property variable
|
|
479
|
+
*/
|
|
480
|
+
type PropertyVariable = {
|
|
481
|
+
uuid: string;
|
|
482
|
+
category: "propertyVariable";
|
|
483
|
+
belongsTo: {
|
|
484
|
+
uuid: string;
|
|
485
|
+
abbreviation: string;
|
|
486
|
+
} | null;
|
|
487
|
+
metadata: Metadata | null;
|
|
488
|
+
persistentUrl: string | null;
|
|
489
|
+
type: string;
|
|
490
|
+
number: number;
|
|
491
|
+
publicationDateTime: Date | null;
|
|
492
|
+
context: Context | null;
|
|
493
|
+
availability: License | null;
|
|
494
|
+
identification: Identification;
|
|
495
|
+
};
|
|
471
496
|
/**
|
|
472
497
|
* Represents a property value with type information
|
|
473
498
|
*/
|
|
@@ -590,7 +615,7 @@ type Tree<U extends Exclude<DataCategory, "tree"> = Exclude<DataCategory, "tree"
|
|
|
590
615
|
identification: Identification;
|
|
591
616
|
creators: Array<Person>;
|
|
592
617
|
properties: Array<Property>;
|
|
593
|
-
items: [Exclude<DataCategory, "tree">] extends [U] ? Array<Item> : U extends "resource" ? Array<Resource> : U extends "spatialUnit" ? Array<SpatialUnit> : U extends "concept" ? Array<Concept> : U extends "period" ? Array<Period> : U extends "bibliography" ? Array<Bibliography> : U extends "person" ? Array<Person> : U extends "propertyValue" ? Array<PropertyValue> : U extends "text" ? Array<Text> : U extends "set" ? Array<Set<U extends Array<DataCategory> ? U : Array<U>>> : Array<Item>;
|
|
618
|
+
items: [Exclude<DataCategory, "tree">] extends [U] ? Array<Item> : U extends "resource" ? Array<Resource> : U extends "spatialUnit" ? Array<SpatialUnit> : U extends "concept" ? Array<Concept> : U extends "period" ? Array<Period> : U extends "bibliography" ? Array<Bibliography> : U extends "person" ? Array<Person> : U extends "propertyVariable" ? Array<PropertyVariable> : U extends "propertyValue" ? Array<PropertyValue> : U extends "text" ? Array<Text> : U extends "set" ? Array<Set<U extends Array<DataCategory> ? U : Array<U>>> : Array<Item>;
|
|
594
619
|
};
|
|
595
620
|
/**
|
|
596
621
|
* Represents a gallery with its identification, project identification, resources and max length
|
|
@@ -1031,24 +1056,7 @@ type WebBlock<T extends WebBlockLayout = WebBlockLayout> = {
|
|
|
1031
1056
|
* @param options - The options for the fetch
|
|
1032
1057
|
* @param options.fetch - The fetch function to use
|
|
1033
1058
|
* @param options.version - The version of the OCHRE API to use
|
|
1034
|
-
* @returns The parsed gallery or
|
|
1035
|
-
*
|
|
1036
|
-
* @example
|
|
1037
|
-
* ```ts
|
|
1038
|
-
* const gallery = await fetchGallery("9c4da06b-f15e-40af-a747-0933eaf3587e", "1978", 1, 12);
|
|
1039
|
-
* if (gallery === null) {
|
|
1040
|
-
* console.error("Failed to fetch gallery");
|
|
1041
|
-
* return;
|
|
1042
|
-
* }
|
|
1043
|
-
* console.log(`Fetched gallery: ${gallery.identification.label}`);
|
|
1044
|
-
* console.log(`Contains ${gallery.resources.length.toLocaleString()} resources`);
|
|
1045
|
-
* ```
|
|
1046
|
-
*
|
|
1047
|
-
* @remarks
|
|
1048
|
-
* The returned gallery includes:
|
|
1049
|
-
* - Gallery metadata and identification
|
|
1050
|
-
* - Project identification
|
|
1051
|
-
* - Resources (gallery items)
|
|
1059
|
+
* @returns The parsed gallery or an error message if the fetch/parse fails
|
|
1052
1060
|
*/
|
|
1053
1061
|
declare function fetchGallery(uuid: string, filter: string, page: number, pageSize: number, options?: {
|
|
1054
1062
|
fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
@@ -1066,34 +1074,7 @@ declare function fetchGallery(uuid: string, filter: string, page: number, pageSi
|
|
|
1066
1074
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
1067
1075
|
*
|
|
1068
1076
|
* @param uuid - The UUID of the OCHRE item to fetch
|
|
1069
|
-
* @returns Object containing the parsed OCHRE item
|
|
1070
|
-
*
|
|
1071
|
-
* @example
|
|
1072
|
-
* ```ts
|
|
1073
|
-
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000");
|
|
1074
|
-
* if (result === null) {
|
|
1075
|
-
* console.error("Failed to fetch OCHRE item");
|
|
1076
|
-
* return;
|
|
1077
|
-
* }
|
|
1078
|
-
* const { metadata, belongsTo, item, category } = result;
|
|
1079
|
-
* console.log(`Fetched OCHRE item: ${item.identification.label} with category ${category}`);
|
|
1080
|
-
* ```
|
|
1081
|
-
*
|
|
1082
|
-
* Or, if you want to fetch a specific category, you can do so by passing the category as an argument:
|
|
1083
|
-
* ```ts
|
|
1084
|
-
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000", "resource");
|
|
1085
|
-
* const { metadata, belongsTo, item, category } = result;
|
|
1086
|
-
* console.log(item.category); // "resource"
|
|
1087
|
-
* ```
|
|
1088
|
-
*
|
|
1089
|
-
* @remarks
|
|
1090
|
-
* The returned OCHRE item includes:
|
|
1091
|
-
* - Item metadata
|
|
1092
|
-
* - Item belongsTo information
|
|
1093
|
-
* - Item content
|
|
1094
|
-
* - Item category
|
|
1095
|
-
*
|
|
1096
|
-
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
1077
|
+
* @returns Object containing the parsed OCHRE item, or an error message if the fetch/parse fails
|
|
1097
1078
|
*/
|
|
1098
1079
|
declare function fetchItem<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(uuid: string, category?: T, itemCategories?: U, options?: {
|
|
1099
1080
|
fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
@@ -1101,13 +1082,9 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
|
|
|
1101
1082
|
}): Promise<{
|
|
1102
1083
|
error: null;
|
|
1103
1084
|
item: Item<T, U>;
|
|
1104
|
-
category: T;
|
|
1105
|
-
itemCategories: U;
|
|
1106
1085
|
} | {
|
|
1107
1086
|
error: string;
|
|
1108
|
-
item:
|
|
1109
|
-
category: never;
|
|
1110
|
-
itemCategories: never;
|
|
1087
|
+
item: null;
|
|
1111
1088
|
}>;
|
|
1112
1089
|
//#endregion
|
|
1113
1090
|
//#region src/utils/fetchers/items-by-property-values.d.ts
|
|
@@ -1235,29 +1212,6 @@ declare function fetchPropertyValuesByPropertyVariables(params: {
|
|
|
1235
1212
|
*
|
|
1236
1213
|
* @param abbreviation - The abbreviation identifier for the website
|
|
1237
1214
|
* @returns The parsed website configuration or null if the fetch/parse fails
|
|
1238
|
-
*
|
|
1239
|
-
* @example
|
|
1240
|
-
* ```ts
|
|
1241
|
-
* const website = await fetchWebsite("guerrilla-television");
|
|
1242
|
-
* if (website === null) {
|
|
1243
|
-
* console.error("Failed to fetch website");
|
|
1244
|
-
* return;
|
|
1245
|
-
* }
|
|
1246
|
-
* console.log(`Fetched website: ${website.identification.label}`);
|
|
1247
|
-
* console.log(`Contains ${website.pages.length.toLocaleString()} pages`);
|
|
1248
|
-
* ```
|
|
1249
|
-
*
|
|
1250
|
-
* @remarks
|
|
1251
|
-
* The returned website configuration includes:
|
|
1252
|
-
* - Website metadata and identification
|
|
1253
|
-
* - Page structure and content
|
|
1254
|
-
* - Layout and styling properties
|
|
1255
|
-
* - Navigation configuration
|
|
1256
|
-
* - Sidebar elements
|
|
1257
|
-
* - Project information
|
|
1258
|
-
* - Creator details
|
|
1259
|
-
*
|
|
1260
|
-
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
1261
1215
|
*/
|
|
1262
1216
|
declare function fetchWebsite(abbreviation: string, options?: {
|
|
1263
1217
|
fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
@@ -1278,14 +1232,6 @@ type PropertyOptions = {
|
|
|
1278
1232
|
* @param uuid - The UUID to search for
|
|
1279
1233
|
* @param options - Search options, including whether to include nested properties
|
|
1280
1234
|
* @returns The matching Property object, or null if not found
|
|
1281
|
-
*
|
|
1282
|
-
* @example
|
|
1283
|
-
* ```ts
|
|
1284
|
-
* const property = getPropertyByUuid(properties, "123e4567-e89b-12d3-a456-426614174000", { includeNestedProperties: true });
|
|
1285
|
-
* if (property) {
|
|
1286
|
-
* console.log(property.values);
|
|
1287
|
-
* }
|
|
1288
|
-
* ```
|
|
1289
1235
|
*/
|
|
1290
1236
|
declare function getPropertyByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Property | null;
|
|
1291
1237
|
/**
|
|
@@ -1295,16 +1241,6 @@ declare function getPropertyByUuid(properties: Array<Property>, uuid: string, op
|
|
|
1295
1241
|
* @param uuid - The UUID to search for
|
|
1296
1242
|
* @param options - Search options, including whether to include nested properties
|
|
1297
1243
|
* @returns Array of property values as strings, or null if property not found
|
|
1298
|
-
*
|
|
1299
|
-
* @example
|
|
1300
|
-
* ```ts
|
|
1301
|
-
* const values = getPropertyValuesByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
|
|
1302
|
-
* if (values) {
|
|
1303
|
-
* for (const value of values) {
|
|
1304
|
-
* console.log(value);
|
|
1305
|
-
* }
|
|
1306
|
-
* }
|
|
1307
|
-
* ```
|
|
1308
1244
|
*/
|
|
1309
1245
|
declare function getPropertyValuesByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
|
|
1310
1246
|
/**
|
|
@@ -1314,14 +1250,6 @@ declare function getPropertyValuesByUuid(properties: Array<Property>, uuid: stri
|
|
|
1314
1250
|
* @param uuid - The UUID to search for
|
|
1315
1251
|
* @param options - Search options, including whether to include nested properties
|
|
1316
1252
|
* @returns The first property value as string, or null if property not found
|
|
1317
|
-
*
|
|
1318
|
-
* @example
|
|
1319
|
-
* ```ts
|
|
1320
|
-
* const title = getPropertyValueByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
|
|
1321
|
-
* if (title) {
|
|
1322
|
-
* console.log(`Document title: ${title}`);
|
|
1323
|
-
* }
|
|
1324
|
-
* ```
|
|
1325
1253
|
*/
|
|
1326
1254
|
declare function getPropertyValueByUuid(properties: Array<Property>, uuid: string, options?: PropertyOptions): string | number | boolean | Date | null;
|
|
1327
1255
|
/**
|
|
@@ -1331,14 +1259,6 @@ declare function getPropertyValueByUuid(properties: Array<Property>, uuid: strin
|
|
|
1331
1259
|
* @param label - The label to search for
|
|
1332
1260
|
* @param options - Search options, including whether to include nested properties
|
|
1333
1261
|
* @returns The matching Property object, or null if not found
|
|
1334
|
-
*
|
|
1335
|
-
* @example
|
|
1336
|
-
* ```ts
|
|
1337
|
-
* const property = getPropertyByLabel(properties, "author", { includeNestedProperties: true });
|
|
1338
|
-
* if (property) {
|
|
1339
|
-
* console.log(property.values);
|
|
1340
|
-
* }
|
|
1341
|
-
* ```
|
|
1342
1262
|
*/
|
|
1343
1263
|
declare function getPropertyByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Property | null;
|
|
1344
1264
|
/**
|
|
@@ -1348,16 +1268,6 @@ declare function getPropertyByLabel(properties: Array<Property>, label: string,
|
|
|
1348
1268
|
* @param label - The label to search for
|
|
1349
1269
|
* @param options - Search options, including whether to include nested properties
|
|
1350
1270
|
* @returns Array of property values as strings, or null if property not found
|
|
1351
|
-
*
|
|
1352
|
-
* @example
|
|
1353
|
-
* ```ts
|
|
1354
|
-
* const values = getPropertyValuesByLabel(properties, "keywords");
|
|
1355
|
-
* if (values) {
|
|
1356
|
-
* for (const value of values) {
|
|
1357
|
-
* console.log(value);
|
|
1358
|
-
* }
|
|
1359
|
-
* }
|
|
1360
|
-
* ```
|
|
1361
1271
|
*/
|
|
1362
1272
|
declare function getPropertyValuesByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): Array<string | number | boolean | Date | null> | null;
|
|
1363
1273
|
/**
|
|
@@ -1367,14 +1277,6 @@ declare function getPropertyValuesByLabel(properties: Array<Property>, label: st
|
|
|
1367
1277
|
* @param label - The label to search for
|
|
1368
1278
|
* @param options - Search options, including whether to include nested properties
|
|
1369
1279
|
* @returns The first property value as string, or null if property not found
|
|
1370
|
-
*
|
|
1371
|
-
* @example
|
|
1372
|
-
* ```ts
|
|
1373
|
-
* const title = getPropertyValueByLabel(properties, "title");
|
|
1374
|
-
* if (title) {
|
|
1375
|
-
* console.log(`Document title: ${title}`);
|
|
1376
|
-
* }
|
|
1377
|
-
* ```
|
|
1378
1280
|
*/
|
|
1379
1281
|
declare function getPropertyValueByLabel(properties: Array<Property>, label: string, options?: PropertyOptions): string | number | boolean | Date | null;
|
|
1380
1282
|
/**
|
|
@@ -1383,12 +1285,6 @@ declare function getPropertyValueByLabel(properties: Array<Property>, label: str
|
|
|
1383
1285
|
* @param properties - Array of properties to get unique properties from
|
|
1384
1286
|
* @param options - Search options, including whether to include nested properties
|
|
1385
1287
|
* @returns Array of unique properties
|
|
1386
|
-
*
|
|
1387
|
-
* @example
|
|
1388
|
-
* ```ts
|
|
1389
|
-
* const properties = getAllUniqueProperties(properties, { includeNestedProperties: true });
|
|
1390
|
-
* console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
|
|
1391
|
-
* ```
|
|
1392
1288
|
*/
|
|
1393
1289
|
declare function getUniqueProperties(properties: Array<Property>, options?: PropertyOptions): Array<Property>;
|
|
1394
1290
|
/**
|
|
@@ -1397,12 +1293,6 @@ declare function getUniqueProperties(properties: Array<Property>, options?: Prop
|
|
|
1397
1293
|
* @param properties - Array of properties to get unique property labels from
|
|
1398
1294
|
* @param options - Search options, including whether to include nested properties
|
|
1399
1295
|
* @returns Array of unique property labels
|
|
1400
|
-
*
|
|
1401
|
-
* @example
|
|
1402
|
-
* ```ts
|
|
1403
|
-
* const properties = getAllUniquePropertyLabels(properties, { includeNestedProperties: true });
|
|
1404
|
-
* console.log(`Available properties: ${properties.join(", ")}`);
|
|
1405
|
-
* ```
|
|
1406
1296
|
*/
|
|
1407
1297
|
declare function getUniquePropertyLabels(properties: Array<Property>, options?: PropertyOptions): Array<string>;
|
|
1408
1298
|
/**
|
|
@@ -1414,17 +1304,6 @@ declare function getUniquePropertyLabels(properties: Array<Property>, options?:
|
|
|
1414
1304
|
* @param filter.value - The value to filter by
|
|
1415
1305
|
* @param options - Search options, including whether to include nested properties
|
|
1416
1306
|
* @returns True if the property matches the filter criteria, false otherwise
|
|
1417
|
-
*
|
|
1418
|
-
* @example
|
|
1419
|
-
* ```ts
|
|
1420
|
-
* const matches = filterProperties(property, {
|
|
1421
|
-
* label: "category",
|
|
1422
|
-
* value: "book"
|
|
1423
|
-
* });
|
|
1424
|
-
* if (matches) {
|
|
1425
|
-
* console.log("Property matches filter criteria");
|
|
1426
|
-
* }
|
|
1427
|
-
* ```
|
|
1428
1307
|
*/
|
|
1429
1308
|
declare function filterProperties(property: Property, filter: {
|
|
1430
1309
|
label: string;
|
|
@@ -1460,4 +1339,4 @@ declare function flattenItemProperties<T extends DataCategory = DataCategory, U
|
|
|
1460
1339
|
*/
|
|
1461
1340
|
declare function getLeafPropertyValues<T extends PropertyValueContentType = PropertyValueContentType>(propertyValues: Array<PropertyValueContent<T>>): Array<PropertyValueContent<T>>;
|
|
1462
1341
|
//#endregion
|
|
1463
|
-
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, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchItemsByUuidsAndLinks, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
|
1342
|
+
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, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchItemsByUuidsAndLinks, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/dist/index.mjs
CHANGED
|
@@ -187,6 +187,7 @@ const categorySchema = z.enum([
|
|
|
187
187
|
"period",
|
|
188
188
|
"bibliography",
|
|
189
189
|
"person",
|
|
190
|
+
"propertyVariable",
|
|
190
191
|
"propertyValue",
|
|
191
192
|
"text",
|
|
192
193
|
"tree",
|
|
@@ -277,14 +278,6 @@ const DEFAULT_OPTIONS = { includeNestedProperties: false };
|
|
|
277
278
|
* @param uuid - The UUID to search for
|
|
278
279
|
* @param options - Search options, including whether to include nested properties
|
|
279
280
|
* @returns The matching Property object, or null if not found
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```ts
|
|
283
|
-
* const property = getPropertyByUuid(properties, "123e4567-e89b-12d3-a456-426614174000", { includeNestedProperties: true });
|
|
284
|
-
* if (property) {
|
|
285
|
-
* console.log(property.values);
|
|
286
|
-
* }
|
|
287
|
-
* ```
|
|
288
281
|
*/
|
|
289
282
|
function getPropertyByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
290
283
|
const { includeNestedProperties } = options;
|
|
@@ -305,16 +298,6 @@ function getPropertyByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
|
305
298
|
* @param uuid - The UUID to search for
|
|
306
299
|
* @param options - Search options, including whether to include nested properties
|
|
307
300
|
* @returns Array of property values as strings, or null if property not found
|
|
308
|
-
*
|
|
309
|
-
* @example
|
|
310
|
-
* ```ts
|
|
311
|
-
* const values = getPropertyValuesByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
|
|
312
|
-
* if (values) {
|
|
313
|
-
* for (const value of values) {
|
|
314
|
-
* console.log(value);
|
|
315
|
-
* }
|
|
316
|
-
* }
|
|
317
|
-
* ```
|
|
318
301
|
*/
|
|
319
302
|
function getPropertyValuesByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
320
303
|
const { includeNestedProperties } = options;
|
|
@@ -335,14 +318,6 @@ function getPropertyValuesByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
|
335
318
|
* @param uuid - The UUID to search for
|
|
336
319
|
* @param options - Search options, including whether to include nested properties
|
|
337
320
|
* @returns The first property value as string, or null if property not found
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```ts
|
|
341
|
-
* const title = getPropertyValueByUuid(properties, "123e4567-e89b-12d3-a456-426614174000");
|
|
342
|
-
* if (title) {
|
|
343
|
-
* console.log(`Document title: ${title}`);
|
|
344
|
-
* }
|
|
345
|
-
* ```
|
|
346
321
|
*/
|
|
347
322
|
function getPropertyValueByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
348
323
|
const { includeNestedProperties } = options;
|
|
@@ -363,14 +338,6 @@ function getPropertyValueByUuid(properties, uuid, options = DEFAULT_OPTIONS) {
|
|
|
363
338
|
* @param label - The label to search for
|
|
364
339
|
* @param options - Search options, including whether to include nested properties
|
|
365
340
|
* @returns The matching Property object, or null if not found
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* ```ts
|
|
369
|
-
* const property = getPropertyByLabel(properties, "author", { includeNestedProperties: true });
|
|
370
|
-
* if (property) {
|
|
371
|
-
* console.log(property.values);
|
|
372
|
-
* }
|
|
373
|
-
* ```
|
|
374
341
|
*/
|
|
375
342
|
function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
376
343
|
const { includeNestedProperties } = options;
|
|
@@ -391,16 +358,6 @@ function getPropertyByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
|
391
358
|
* @param label - The label to search for
|
|
392
359
|
* @param options - Search options, including whether to include nested properties
|
|
393
360
|
* @returns Array of property values as strings, or null if property not found
|
|
394
|
-
*
|
|
395
|
-
* @example
|
|
396
|
-
* ```ts
|
|
397
|
-
* const values = getPropertyValuesByLabel(properties, "keywords");
|
|
398
|
-
* if (values) {
|
|
399
|
-
* for (const value of values) {
|
|
400
|
-
* console.log(value);
|
|
401
|
-
* }
|
|
402
|
-
* }
|
|
403
|
-
* ```
|
|
404
361
|
*/
|
|
405
362
|
function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
406
363
|
const { includeNestedProperties } = options;
|
|
@@ -421,14 +378,6 @@ function getPropertyValuesByLabel(properties, label, options = DEFAULT_OPTIONS)
|
|
|
421
378
|
* @param label - The label to search for
|
|
422
379
|
* @param options - Search options, including whether to include nested properties
|
|
423
380
|
* @returns The first property value as string, or null if property not found
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* const title = getPropertyValueByLabel(properties, "title");
|
|
428
|
-
* if (title) {
|
|
429
|
-
* console.log(`Document title: ${title}`);
|
|
430
|
-
* }
|
|
431
|
-
* ```
|
|
432
381
|
*/
|
|
433
382
|
function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
434
383
|
const { includeNestedProperties } = options;
|
|
@@ -448,12 +397,6 @@ function getPropertyValueByLabel(properties, label, options = DEFAULT_OPTIONS) {
|
|
|
448
397
|
* @param properties - Array of properties to get unique properties from
|
|
449
398
|
* @param options - Search options, including whether to include nested properties
|
|
450
399
|
* @returns Array of unique properties
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```ts
|
|
454
|
-
* const properties = getAllUniqueProperties(properties, { includeNestedProperties: true });
|
|
455
|
-
* console.log(`Available properties: ${properties.map((p) => p.label).join(", ")}`);
|
|
456
|
-
* ```
|
|
457
400
|
*/
|
|
458
401
|
function getUniqueProperties(properties, options = DEFAULT_OPTIONS) {
|
|
459
402
|
const { includeNestedProperties } = options;
|
|
@@ -477,12 +420,6 @@ function getUniqueProperties(properties, options = DEFAULT_OPTIONS) {
|
|
|
477
420
|
* @param properties - Array of properties to get unique property labels from
|
|
478
421
|
* @param options - Search options, including whether to include nested properties
|
|
479
422
|
* @returns Array of unique property labels
|
|
480
|
-
*
|
|
481
|
-
* @example
|
|
482
|
-
* ```ts
|
|
483
|
-
* const properties = getAllUniquePropertyLabels(properties, { includeNestedProperties: true });
|
|
484
|
-
* console.log(`Available properties: ${properties.join(", ")}`);
|
|
485
|
-
* ```
|
|
486
423
|
*/
|
|
487
424
|
function getUniquePropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
488
425
|
const { includeNestedProperties } = options;
|
|
@@ -509,17 +446,6 @@ function getUniquePropertyLabels(properties, options = DEFAULT_OPTIONS) {
|
|
|
509
446
|
* @param filter.value - The value to filter by
|
|
510
447
|
* @param options - Search options, including whether to include nested properties
|
|
511
448
|
* @returns True if the property matches the filter criteria, false otherwise
|
|
512
|
-
*
|
|
513
|
-
* @example
|
|
514
|
-
* ```ts
|
|
515
|
-
* const matches = filterProperties(property, {
|
|
516
|
-
* label: "category",
|
|
517
|
-
* value: "book"
|
|
518
|
-
* });
|
|
519
|
-
* if (matches) {
|
|
520
|
-
* console.log("Property matches filter criteria");
|
|
521
|
-
* }
|
|
522
|
-
* ```
|
|
523
449
|
*/
|
|
524
450
|
function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
|
|
525
451
|
const { includeNestedProperties } = options;
|
|
@@ -576,12 +502,6 @@ function getStringItemByLanguage(content, language) {
|
|
|
576
502
|
*
|
|
577
503
|
* @param string - Input string to parse
|
|
578
504
|
* @returns String with emails converted to HTML links
|
|
579
|
-
*
|
|
580
|
-
* @example
|
|
581
|
-
* ```ts
|
|
582
|
-
* const parsed = parseEmail("Contact us at info@example.com");
|
|
583
|
-
* // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>"
|
|
584
|
-
* ```
|
|
585
505
|
*/
|
|
586
506
|
function parseEmail(string) {
|
|
587
507
|
const splitString = string.split(" ");
|
|
@@ -661,13 +581,6 @@ function parseWhitespace(contentString, whitespace) {
|
|
|
661
581
|
*
|
|
662
582
|
* @param string - FakeString value to convert
|
|
663
583
|
* @returns Converted string value
|
|
664
|
-
*
|
|
665
|
-
* @example
|
|
666
|
-
* ```ts
|
|
667
|
-
* parseFakeString(true); // Returns "Yes"
|
|
668
|
-
* parseFakeString(123); // Returns "123"
|
|
669
|
-
* parseFakeString("test"); // Returns "test"
|
|
670
|
-
* ```
|
|
671
584
|
*/
|
|
672
585
|
function parseFakeString(string) {
|
|
673
586
|
return String(string).replaceAll("'", "'").replaceAll("{", String.raw`\{`).replaceAll("}", String.raw`\}`);
|
|
@@ -1105,12 +1018,22 @@ function parseMetadata(metadata) {
|
|
|
1105
1018
|
};
|
|
1106
1019
|
let collectionIdentification = null;
|
|
1107
1020
|
if (metadata.collection) collectionIdentification = parseIdentification(metadata.collection.identification);
|
|
1021
|
+
let publicationIdentification = null;
|
|
1022
|
+
if (metadata.publication) publicationIdentification = parseIdentification(metadata.publication.identification);
|
|
1108
1023
|
return {
|
|
1109
1024
|
project: projectIdentification ? {
|
|
1110
1025
|
identification: projectIdentification,
|
|
1111
|
-
dateFormat: metadata.project?.dateFormat ?? null
|
|
1026
|
+
dateFormat: metadata.project?.dateFormat ?? null,
|
|
1027
|
+
page: metadata.project?.page ?? null
|
|
1028
|
+
} : null,
|
|
1029
|
+
collection: metadata.collection != null && collectionIdentification ? {
|
|
1030
|
+
identification: collectionIdentification,
|
|
1031
|
+
page: metadata.collection.page
|
|
1032
|
+
} : null,
|
|
1033
|
+
publication: metadata.publication != null && publicationIdentification ? {
|
|
1034
|
+
identification: publicationIdentification,
|
|
1035
|
+
page: metadata.publication.page
|
|
1112
1036
|
} : null,
|
|
1113
|
-
collection: collectionIdentification ? { identification: collectionIdentification } : null,
|
|
1114
1037
|
item: metadata.item ? {
|
|
1115
1038
|
identification,
|
|
1116
1039
|
category: metadata.item.category,
|
|
@@ -1228,13 +1151,13 @@ function parsePersons(persons) {
|
|
|
1228
1151
|
* @returns Parsed Link object
|
|
1229
1152
|
*/
|
|
1230
1153
|
function parseLink(linkRaw) {
|
|
1231
|
-
const links = "resource" in linkRaw ? linkRaw.resource : "spatialUnit" in linkRaw ? linkRaw.spatialUnit : "concept" in linkRaw ? linkRaw.concept : "set" in linkRaw ? linkRaw.set : "tree" in linkRaw ? linkRaw.tree : "person" in linkRaw ? linkRaw.person : "bibliography" in linkRaw ? linkRaw.bibliography : "propertyValue" in linkRaw ? linkRaw.propertyValue : null;
|
|
1154
|
+
const links = "resource" in linkRaw ? linkRaw.resource : "spatialUnit" in linkRaw ? linkRaw.spatialUnit : "concept" in linkRaw ? linkRaw.concept : "set" in linkRaw ? linkRaw.set : "tree" in linkRaw ? linkRaw.tree : "person" in linkRaw ? linkRaw.person : "bibliography" in linkRaw ? linkRaw.bibliography : "propertyVariable" in linkRaw ? linkRaw.propertyVariable : "propertyValue" in linkRaw ? linkRaw.propertyValue : null;
|
|
1232
1155
|
if (!links) throw new Error(`Invalid link provided: ${JSON.stringify(linkRaw, null, 2)}`);
|
|
1233
1156
|
const linksToParse = Array.isArray(links) ? links : [links];
|
|
1234
1157
|
const returnLinks = [];
|
|
1235
1158
|
for (const link of linksToParse) {
|
|
1236
1159
|
const returnLink = {
|
|
1237
|
-
category: "resource" in linkRaw ? "resource" : "spatialUnit" in linkRaw ? "spatialUnit" : "concept" in linkRaw ? "concept" : "set" in linkRaw ? "set" : "person" in linkRaw ? "person" : "tree" in linkRaw ? "tree" : "bibliography" in linkRaw ? "bibliography" : "propertyValue" in linkRaw ? "propertyValue" : null,
|
|
1160
|
+
category: "resource" in linkRaw ? "resource" : "spatialUnit" in linkRaw ? "spatialUnit" : "concept" in linkRaw ? "concept" : "set" in linkRaw ? "set" : "person" in linkRaw ? "person" : "tree" in linkRaw ? "tree" : "bibliography" in linkRaw ? "bibliography" : "propertyVariable" in linkRaw ? "propertyVariable" : "propertyValue" in linkRaw ? "propertyValue" : null,
|
|
1238
1161
|
content: "content" in link ? link.content != null ? parseFakeString(link.content) : null : null,
|
|
1239
1162
|
href: "href" in link && link.href != null ? link.href : null,
|
|
1240
1163
|
fileFormat: "fileFormat" in link && link.fileFormat != null ? link.fileFormat : null,
|
|
@@ -1715,6 +1638,38 @@ function parseBibliography(bibliography, metadata, persistentUrl, belongsTo) {
|
|
|
1715
1638
|
};
|
|
1716
1639
|
}
|
|
1717
1640
|
/**
|
|
1641
|
+
* Parses raw property variable data into a standardized PropertyVariable structure
|
|
1642
|
+
*
|
|
1643
|
+
* @param propertyVariable - Raw property variable data in OCHRE format
|
|
1644
|
+
* @returns Parsed PropertyVariable object
|
|
1645
|
+
*/
|
|
1646
|
+
function parsePropertyVariable(propertyVariable, metadata, persistentUrl, belongsTo) {
|
|
1647
|
+
return {
|
|
1648
|
+
uuid: propertyVariable.uuid,
|
|
1649
|
+
category: "propertyVariable",
|
|
1650
|
+
belongsTo: belongsTo ?? null,
|
|
1651
|
+
metadata: metadata ?? null,
|
|
1652
|
+
persistentUrl: persistentUrl ?? null,
|
|
1653
|
+
type: propertyVariable.type,
|
|
1654
|
+
number: propertyVariable.n,
|
|
1655
|
+
publicationDateTime: propertyVariable.publicationDateTime ? parseISO(propertyVariable.publicationDateTime) : null,
|
|
1656
|
+
context: propertyVariable.context ? parseContext(propertyVariable.context) : null,
|
|
1657
|
+
availability: propertyVariable.availability ? parseLicense(propertyVariable.availability) : null,
|
|
1658
|
+
identification: parseIdentification(propertyVariable.identification)
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Parses an array of raw property variables into standardized PropertyVariable objects
|
|
1663
|
+
*
|
|
1664
|
+
* @param propertyVariables - Array of raw property variables in OCHRE format
|
|
1665
|
+
* @returns Array of parsed PropertyVariable objects
|
|
1666
|
+
*/
|
|
1667
|
+
function parsePropertyVariables(propertyVariables) {
|
|
1668
|
+
const returnPropertyVariables = [];
|
|
1669
|
+
for (const propertyVariable of propertyVariables) returnPropertyVariables.push(parsePropertyVariable(propertyVariable));
|
|
1670
|
+
return returnPropertyVariables;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1718
1673
|
* Parses an array of raw bibliographies into standardized Bibliography objects
|
|
1719
1674
|
*
|
|
1720
1675
|
* @param bibliographies - Array of raw bibliographies in OCHRE format
|
|
@@ -1881,6 +1836,10 @@ function parseTree(tree, itemCategories, metadata, persistentUrl, belongsTo) {
|
|
|
1881
1836
|
if (!("person" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no persons");
|
|
1882
1837
|
items = parsePersons(Array.isArray(tree.items.person) ? tree.items.person : [tree.items.person]);
|
|
1883
1838
|
break;
|
|
1839
|
+
case "propertyVariable":
|
|
1840
|
+
if (!("propertyVariable" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no property variables");
|
|
1841
|
+
items = parsePropertyVariables(Array.isArray(tree.items.propertyVariable) ? tree.items.propertyVariable : [tree.items.propertyVariable]);
|
|
1842
|
+
break;
|
|
1884
1843
|
case "propertyValue":
|
|
1885
1844
|
if (!("propertyValue" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no property values");
|
|
1886
1845
|
items = parsePropertyValues(Array.isArray(tree.items.propertyValue) ? tree.items.propertyValue : [tree.items.propertyValue]);
|
|
@@ -1961,6 +1920,10 @@ function parseSet(set, itemCategories, metadata, persistentUrl, belongsTo) {
|
|
|
1961
1920
|
if (!("person" in set.items) || set.items.person == null) throw new Error("Invalid OCHRE data: Set has no persons");
|
|
1962
1921
|
items.push(...parsePersons(Array.isArray(set.items.person) ? set.items.person : [set.items.person]));
|
|
1963
1922
|
break;
|
|
1923
|
+
case "propertyVariable":
|
|
1924
|
+
if (!("propertyVariable" in set.items) || set.items.propertyVariable == null) throw new Error("Invalid OCHRE data: Set has no property variables");
|
|
1925
|
+
items.push(...parsePropertyVariables(Array.isArray(set.items.propertyVariable) ? set.items.propertyVariable : [set.items.propertyVariable]));
|
|
1926
|
+
break;
|
|
1964
1927
|
case "propertyValue":
|
|
1965
1928
|
if (!("propertyValue" in set.items) || set.items.propertyValue == null) throw new Error("Invalid OCHRE data: Set has no property values");
|
|
1966
1929
|
items.push(...parsePropertyValues(Array.isArray(set.items.propertyValue) ? set.items.propertyValue : [set.items.propertyValue]));
|
|
@@ -3359,24 +3322,7 @@ function parseWebsite(websiteTree, metadata, belongsTo, { version = DEFAULT_API_
|
|
|
3359
3322
|
* @param options - The options for the fetch
|
|
3360
3323
|
* @param options.fetch - The fetch function to use
|
|
3361
3324
|
* @param options.version - The version of the OCHRE API to use
|
|
3362
|
-
* @returns The parsed gallery or
|
|
3363
|
-
*
|
|
3364
|
-
* @example
|
|
3365
|
-
* ```ts
|
|
3366
|
-
* const gallery = await fetchGallery("9c4da06b-f15e-40af-a747-0933eaf3587e", "1978", 1, 12);
|
|
3367
|
-
* if (gallery === null) {
|
|
3368
|
-
* console.error("Failed to fetch gallery");
|
|
3369
|
-
* return;
|
|
3370
|
-
* }
|
|
3371
|
-
* console.log(`Fetched gallery: ${gallery.identification.label}`);
|
|
3372
|
-
* console.log(`Contains ${gallery.resources.length.toLocaleString()} resources`);
|
|
3373
|
-
* ```
|
|
3374
|
-
*
|
|
3375
|
-
* @remarks
|
|
3376
|
-
* The returned gallery includes:
|
|
3377
|
-
* - Gallery metadata and identification
|
|
3378
|
-
* - Project identification
|
|
3379
|
-
* - Resources (gallery items)
|
|
3325
|
+
* @returns The parsed gallery or an error message if the fetch/parse fails
|
|
3380
3326
|
*/
|
|
3381
3327
|
async function fetchGallery(uuid, filter, page, pageSize, options) {
|
|
3382
3328
|
try {
|
|
@@ -3424,17 +3370,6 @@ async function fetchGallery(uuid, filter, page, pageSize, options) {
|
|
|
3424
3370
|
*
|
|
3425
3371
|
* @param uuid - The UUID of the OCHRE item to fetch
|
|
3426
3372
|
* @returns A tuple containing either [null, OchreData] on success or [error message, null] on failure
|
|
3427
|
-
*
|
|
3428
|
-
* @example
|
|
3429
|
-
* ```ts
|
|
3430
|
-
* const [error, data] = await fetchByUuid("123e4567-e89b-12d3-a456-426614174000");
|
|
3431
|
-
* if (error !== null) {
|
|
3432
|
-
* console.error(`Failed to fetch: ${error}`);
|
|
3433
|
-
* return;
|
|
3434
|
-
* }
|
|
3435
|
-
* // Process data...
|
|
3436
|
-
* ```
|
|
3437
|
-
*
|
|
3438
3373
|
* @internal
|
|
3439
3374
|
*/
|
|
3440
3375
|
async function fetchByUuid(uuid, options) {
|
|
@@ -3457,34 +3392,7 @@ async function fetchByUuid(uuid, options) {
|
|
|
3457
3392
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
3458
3393
|
*
|
|
3459
3394
|
* @param uuid - The UUID of the OCHRE item to fetch
|
|
3460
|
-
* @returns Object containing the parsed OCHRE item
|
|
3461
|
-
*
|
|
3462
|
-
* @example
|
|
3463
|
-
* ```ts
|
|
3464
|
-
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000");
|
|
3465
|
-
* if (result === null) {
|
|
3466
|
-
* console.error("Failed to fetch OCHRE item");
|
|
3467
|
-
* return;
|
|
3468
|
-
* }
|
|
3469
|
-
* const { metadata, belongsTo, item, category } = result;
|
|
3470
|
-
* console.log(`Fetched OCHRE item: ${item.identification.label} with category ${category}`);
|
|
3471
|
-
* ```
|
|
3472
|
-
*
|
|
3473
|
-
* Or, if you want to fetch a specific category, you can do so by passing the category as an argument:
|
|
3474
|
-
* ```ts
|
|
3475
|
-
* const result = await fetchItem("123e4567-e89b-12d3-a456-426614174000", "resource");
|
|
3476
|
-
* const { metadata, belongsTo, item, category } = result;
|
|
3477
|
-
* console.log(item.category); // "resource"
|
|
3478
|
-
* ```
|
|
3479
|
-
*
|
|
3480
|
-
* @remarks
|
|
3481
|
-
* The returned OCHRE item includes:
|
|
3482
|
-
* - Item metadata
|
|
3483
|
-
* - Item belongsTo information
|
|
3484
|
-
* - Item content
|
|
3485
|
-
* - Item category
|
|
3486
|
-
*
|
|
3487
|
-
* If the fetch/parse fails, the returned object will have an `error` property.
|
|
3395
|
+
* @returns Object containing the parsed OCHRE item, or an error message if the fetch/parse fails
|
|
3488
3396
|
*/
|
|
3489
3397
|
async function fetchItem(uuid, category, itemCategories, options) {
|
|
3490
3398
|
try {
|
|
@@ -3494,7 +3402,7 @@ async function fetchItem(uuid, category, itemCategories, options) {
|
|
|
3494
3402
|
version
|
|
3495
3403
|
});
|
|
3496
3404
|
if (error !== null) throw new Error(error);
|
|
3497
|
-
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
3405
|
+
const categoryKey = category ?? getItemCategory(Object.keys(data.ochre));
|
|
3498
3406
|
const belongsTo = {
|
|
3499
3407
|
uuid: data.ochre.uuidBelongsTo,
|
|
3500
3408
|
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
@@ -3529,6 +3437,10 @@ async function fetchItem(uuid, category, itemCategories, options) {
|
|
|
3529
3437
|
if (!("person" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'person' key");
|
|
3530
3438
|
item = parsePerson(data.ochre.person, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3531
3439
|
break;
|
|
3440
|
+
case "propertyVariable":
|
|
3441
|
+
if (!("propertyVariable" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyVariable' key");
|
|
3442
|
+
item = parsePropertyVariable(data.ochre.propertyVariable, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3443
|
+
break;
|
|
3532
3444
|
case "propertyValue":
|
|
3533
3445
|
if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
|
|
3534
3446
|
item = parsePropertyValue(data.ochre.propertyValue, metadata, data.ochre.persistentUrl, belongsTo);
|
|
@@ -3549,16 +3461,12 @@ async function fetchItem(uuid, category, itemCategories, options) {
|
|
|
3549
3461
|
}
|
|
3550
3462
|
return {
|
|
3551
3463
|
error: null,
|
|
3552
|
-
item
|
|
3553
|
-
category,
|
|
3554
|
-
itemCategories
|
|
3464
|
+
item
|
|
3555
3465
|
};
|
|
3556
3466
|
} catch (error) {
|
|
3557
3467
|
return {
|
|
3558
3468
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
3559
|
-
item:
|
|
3560
|
-
category: void 0,
|
|
3561
|
-
itemCategories: void 0
|
|
3469
|
+
item: null
|
|
3562
3470
|
};
|
|
3563
3471
|
}
|
|
3564
3472
|
}
|
|
@@ -3682,6 +3590,10 @@ async function fetchItemsByPropertyValues(params, categoryParams, options) {
|
|
|
3682
3590
|
const persons = parsePersons(Array.isArray(data.result.ochre.items.person) ? data.result.ochre.items.person : [data.result.ochre.items.person]);
|
|
3683
3591
|
items.push(...persons);
|
|
3684
3592
|
}
|
|
3593
|
+
if ("propertyVariable" in data.result.ochre.items && data.result.ochre.items.propertyVariable != null) {
|
|
3594
|
+
const propertyVariables = parsePropertyVariables(Array.isArray(data.result.ochre.items.propertyVariable) ? data.result.ochre.items.propertyVariable : [data.result.ochre.items.propertyVariable]);
|
|
3595
|
+
items.push(...propertyVariables);
|
|
3596
|
+
}
|
|
3685
3597
|
if ("propertyValue" in data.result.ochre.items && data.result.ochre.items.propertyValue != null) {
|
|
3686
3598
|
const propertyValues = parsePropertyValues(Array.isArray(data.result.ochre.items.propertyValue) ? data.result.ochre.items.propertyValue : [data.result.ochre.items.propertyValue]);
|
|
3687
3599
|
items.push(...propertyValues);
|
|
@@ -3814,6 +3726,10 @@ async function fetchItemsByUuidsAndLinks(params, categoryParams, options) {
|
|
|
3814
3726
|
const persons = parsePersons(Array.isArray(data.result.ochre.person) ? data.result.ochre.person : [data.result.ochre.person]);
|
|
3815
3727
|
items.push(...persons);
|
|
3816
3728
|
}
|
|
3729
|
+
if ("propertyVariable" in data.result.ochre && data.result.ochre.propertyVariable != null && itemCategory === null) {
|
|
3730
|
+
const propertyVariables = parsePropertyVariables(Array.isArray(data.result.ochre.propertyVariable) ? data.result.ochre.propertyVariable : [data.result.ochre.propertyVariable]);
|
|
3731
|
+
items.push(...propertyVariables);
|
|
3732
|
+
}
|
|
3817
3733
|
if ("propertyValue" in data.result.ochre && data.result.ochre.propertyValue != null && itemCategory === null) {
|
|
3818
3734
|
const propertyValues = parsePropertyValues(Array.isArray(data.result.ochre.propertyValue) ? data.result.ochre.propertyValue : [data.result.ochre.propertyValue]);
|
|
3819
3735
|
items.push(...propertyValues);
|
|
@@ -4010,29 +3926,6 @@ function parseApiVersionSuffix(abbreviation) {
|
|
|
4010
3926
|
*
|
|
4011
3927
|
* @param abbreviation - The abbreviation identifier for the website
|
|
4012
3928
|
* @returns The parsed website configuration or null if the fetch/parse fails
|
|
4013
|
-
*
|
|
4014
|
-
* @example
|
|
4015
|
-
* ```ts
|
|
4016
|
-
* const website = await fetchWebsite("guerrilla-television");
|
|
4017
|
-
* if (website === null) {
|
|
4018
|
-
* console.error("Failed to fetch website");
|
|
4019
|
-
* return;
|
|
4020
|
-
* }
|
|
4021
|
-
* console.log(`Fetched website: ${website.identification.label}`);
|
|
4022
|
-
* console.log(`Contains ${website.pages.length.toLocaleString()} pages`);
|
|
4023
|
-
* ```
|
|
4024
|
-
*
|
|
4025
|
-
* @remarks
|
|
4026
|
-
* The returned website configuration includes:
|
|
4027
|
-
* - Website metadata and identification
|
|
4028
|
-
* - Page structure and content
|
|
4029
|
-
* - Layout and styling properties
|
|
4030
|
-
* - Navigation configuration
|
|
4031
|
-
* - Sidebar elements
|
|
4032
|
-
* - Project information
|
|
4033
|
-
* - Creator details
|
|
4034
|
-
*
|
|
4035
|
-
* The abbreviation is case-insensitive and should match the website's configured abbreviation in OCHRE.
|
|
4036
3929
|
*/
|
|
4037
3930
|
async function fetchWebsite(abbreviation, options) {
|
|
4038
3931
|
try {
|
package/package.json
CHANGED