@digitalculture/ochre-sdk 0.12.18 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +19 -4
- package/dist/index.mjs +29 -19
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9,10 +9,16 @@ type Data<T extends DataCategory, U extends DataCategory> = {
|
|
|
9
9
|
abbreviation: string;
|
|
10
10
|
};
|
|
11
11
|
publicationDateTime: Date;
|
|
12
|
-
|
|
13
|
-
item: Tree<T, U> | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
|
|
12
|
+
item: Item<T, U>;
|
|
14
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Represents the category of the data
|
|
16
|
+
*/
|
|
15
17
|
type DataCategory = "tree" | "set" | "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue";
|
|
18
|
+
/**
|
|
19
|
+
* Represents the item of the data
|
|
20
|
+
*/
|
|
21
|
+
type Item<T extends DataCategory, U extends DataCategory> = Tree<T, U> | Set<T> | Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue;
|
|
16
22
|
/**
|
|
17
23
|
* Basic identification information used across multiple types
|
|
18
24
|
*/
|
|
@@ -79,6 +85,7 @@ type License = {
|
|
|
79
85
|
type Person = {
|
|
80
86
|
uuid: string;
|
|
81
87
|
category: "person";
|
|
88
|
+
metadata: Metadata | null;
|
|
82
89
|
publicationDateTime: Date | null;
|
|
83
90
|
type: string | null;
|
|
84
91
|
number: number | null;
|
|
@@ -273,6 +280,7 @@ type Interpretation = {
|
|
|
273
280
|
type Resource = {
|
|
274
281
|
uuid: string;
|
|
275
282
|
category: "resource";
|
|
283
|
+
metadata: Metadata | null;
|
|
276
284
|
publicationDateTime: Date | null;
|
|
277
285
|
type: string;
|
|
278
286
|
number: number;
|
|
@@ -305,6 +313,7 @@ type Resource = {
|
|
|
305
313
|
type SpatialUnit = {
|
|
306
314
|
uuid: string;
|
|
307
315
|
category: "spatialUnit";
|
|
316
|
+
metadata: Metadata | null;
|
|
308
317
|
publicationDateTime: Date | null;
|
|
309
318
|
number: number;
|
|
310
319
|
context: Context | null;
|
|
@@ -330,6 +339,7 @@ type SpatialUnit = {
|
|
|
330
339
|
type Concept = {
|
|
331
340
|
uuid: string;
|
|
332
341
|
category: "concept";
|
|
342
|
+
metadata: Metadata | null;
|
|
333
343
|
publicationDateTime: Date | null;
|
|
334
344
|
number: number;
|
|
335
345
|
license: License | null;
|
|
@@ -347,6 +357,7 @@ type Concept = {
|
|
|
347
357
|
type Set<T extends DataCategory> = {
|
|
348
358
|
uuid: string;
|
|
349
359
|
category: "set";
|
|
360
|
+
metadata: Metadata | null;
|
|
350
361
|
itemCategory: T;
|
|
351
362
|
publicationDateTime: Date | null;
|
|
352
363
|
type: string;
|
|
@@ -366,6 +377,7 @@ type Bibliography = {
|
|
|
366
377
|
uuid: string | null;
|
|
367
378
|
zoteroId: string | null;
|
|
368
379
|
category: "bibliography";
|
|
380
|
+
metadata: Metadata | null;
|
|
369
381
|
publicationDateTime: Date | null;
|
|
370
382
|
type: string | null;
|
|
371
383
|
number: number | null;
|
|
@@ -400,6 +412,7 @@ type Bibliography = {
|
|
|
400
412
|
type Period = {
|
|
401
413
|
uuid: string;
|
|
402
414
|
category: "period";
|
|
415
|
+
metadata: Metadata | null;
|
|
403
416
|
publicationDateTime: Date | null;
|
|
404
417
|
type: string | null;
|
|
405
418
|
number: number | null;
|
|
@@ -412,6 +425,7 @@ type Period = {
|
|
|
412
425
|
type PropertyValue = {
|
|
413
426
|
uuid: string;
|
|
414
427
|
category: "propertyValue";
|
|
428
|
+
metadata: Metadata | null;
|
|
415
429
|
number: number;
|
|
416
430
|
publicationDateTime: Date | null;
|
|
417
431
|
context: Context | null;
|
|
@@ -456,6 +470,7 @@ type Property<T extends PropertyValueContentType = PropertyValueContentType> = {
|
|
|
456
470
|
type Tree<T extends DataCategory, U extends DataCategory> = {
|
|
457
471
|
uuid: string;
|
|
458
472
|
category: "tree";
|
|
473
|
+
metadata: Metadata | null;
|
|
459
474
|
publicationDateTime: Date | null;
|
|
460
475
|
type: string;
|
|
461
476
|
number: number;
|
|
@@ -954,7 +969,7 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
|
|
|
954
969
|
uuid: string;
|
|
955
970
|
abbreviation: string;
|
|
956
971
|
};
|
|
957
|
-
item:
|
|
972
|
+
item: Item<T, U>;
|
|
958
973
|
category: T;
|
|
959
974
|
} | {
|
|
960
975
|
error: string;
|
|
@@ -1225,4 +1240,4 @@ declare function filterProperties(property: Property, filter: {
|
|
|
1225
1240
|
value: string | number | boolean | Date;
|
|
1226
1241
|
}, options?: PropertyOptions): boolean;
|
|
1227
1242
|
//#endregion
|
|
1228
|
-
export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
|
1243
|
+
export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinates, CoordinatesItem, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Set, SpatialUnit, Style, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchPropertyQuery, fetchWebsite, filterProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/dist/index.mjs
CHANGED
|
@@ -856,10 +856,11 @@ function parseLicense(license) {
|
|
|
856
856
|
* @param person - Raw person data from OCHRE format
|
|
857
857
|
* @returns Parsed Person object
|
|
858
858
|
*/
|
|
859
|
-
function parsePerson(person) {
|
|
859
|
+
function parsePerson(person, metadata) {
|
|
860
860
|
return {
|
|
861
861
|
uuid: person.uuid,
|
|
862
862
|
category: "person",
|
|
863
|
+
metadata: metadata ?? null,
|
|
863
864
|
publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
|
|
864
865
|
type: person.type ?? null,
|
|
865
866
|
number: person.n ?? null,
|
|
@@ -1269,10 +1270,11 @@ function parseImageMap(imageMap) {
|
|
|
1269
1270
|
* @param period - Raw period data in OCHRE format
|
|
1270
1271
|
* @returns Parsed Period object
|
|
1271
1272
|
*/
|
|
1272
|
-
function parsePeriod(period) {
|
|
1273
|
+
function parsePeriod(period, metadata) {
|
|
1273
1274
|
return {
|
|
1274
1275
|
uuid: period.uuid,
|
|
1275
1276
|
category: "period",
|
|
1277
|
+
metadata: metadata ?? null,
|
|
1276
1278
|
publicationDateTime: period.publicationDateTime != null ? new Date(period.publicationDateTime) : null,
|
|
1277
1279
|
type: period.type ?? null,
|
|
1278
1280
|
number: period.n ?? null,
|
|
@@ -1297,7 +1299,7 @@ function parsePeriods(periods) {
|
|
|
1297
1299
|
* @param bibliography - Raw bibliography data in OCHRE format
|
|
1298
1300
|
* @returns Parsed Bibliography object
|
|
1299
1301
|
*/
|
|
1300
|
-
function parseBibliography(bibliography) {
|
|
1302
|
+
function parseBibliography(bibliography, metadata) {
|
|
1301
1303
|
let resource = null;
|
|
1302
1304
|
if (bibliography.source?.resource) resource = {
|
|
1303
1305
|
uuid: bibliography.source.resource.uuid,
|
|
@@ -1321,6 +1323,7 @@ function parseBibliography(bibliography) {
|
|
|
1321
1323
|
uuid: bibliography.uuid ?? null,
|
|
1322
1324
|
zoteroId: bibliography.zoteroId ?? null,
|
|
1323
1325
|
category: "bibliography",
|
|
1326
|
+
metadata: metadata ?? null,
|
|
1324
1327
|
publicationDateTime: bibliography.publicationDateTime != null ? new Date(bibliography.publicationDateTime) : null,
|
|
1325
1328
|
type: bibliography.type ?? null,
|
|
1326
1329
|
number: bibliography.n ?? null,
|
|
@@ -1367,10 +1370,11 @@ function parseBibliographies(bibliographies) {
|
|
|
1367
1370
|
* @param propertyValue - Raw property value data in OCHRE format
|
|
1368
1371
|
* @returns Parsed PropertyValue object
|
|
1369
1372
|
*/
|
|
1370
|
-
function parsePropertyValue(propertyValue) {
|
|
1373
|
+
function parsePropertyValue(propertyValue, metadata) {
|
|
1371
1374
|
return {
|
|
1372
1375
|
uuid: propertyValue.uuid,
|
|
1373
1376
|
category: "propertyValue",
|
|
1377
|
+
metadata: metadata ?? null,
|
|
1374
1378
|
number: propertyValue.n,
|
|
1375
1379
|
publicationDateTime: propertyValue.publicationDateTime ? new Date(propertyValue.publicationDateTime) : null,
|
|
1376
1380
|
context: propertyValue.context ? parseContext(propertyValue.context) : null,
|
|
@@ -1400,7 +1404,7 @@ function parsePropertyValues(propertyValues) {
|
|
|
1400
1404
|
* @param tree - Raw tree data in OCHRE format
|
|
1401
1405
|
* @returns Parsed Tree object or null if invalid
|
|
1402
1406
|
*/
|
|
1403
|
-
function parseTree(tree, itemCategory, itemSubCategory) {
|
|
1407
|
+
function parseTree(tree, itemCategory, itemSubCategory, metadata) {
|
|
1404
1408
|
if (typeof tree.items === "string") throw new TypeError("Invalid OCHRE data: Tree has no items");
|
|
1405
1409
|
let creators = [];
|
|
1406
1410
|
if (tree.creators) creators = parsePersons(Array.isArray(tree.creators.creator) ? tree.creators.creator : [tree.creators.creator]);
|
|
@@ -1449,6 +1453,7 @@ function parseTree(tree, itemCategory, itemSubCategory) {
|
|
|
1449
1453
|
return {
|
|
1450
1454
|
uuid: tree.uuid,
|
|
1451
1455
|
category: "tree",
|
|
1456
|
+
metadata: metadata ?? null,
|
|
1452
1457
|
publicationDateTime: new Date(tree.publicationDateTime),
|
|
1453
1458
|
identification: parseIdentification(tree.identification),
|
|
1454
1459
|
creators,
|
|
@@ -1466,7 +1471,7 @@ function parseTree(tree, itemCategory, itemSubCategory) {
|
|
|
1466
1471
|
* @param set - Raw set data in OCHRE format
|
|
1467
1472
|
* @returns Parsed Set object
|
|
1468
1473
|
*/
|
|
1469
|
-
function parseSet(set, itemCategory) {
|
|
1474
|
+
function parseSet(set, itemCategory, metadata) {
|
|
1470
1475
|
if (typeof set.items === "string") throw new TypeError("Invalid OCHRE data: Set has no items");
|
|
1471
1476
|
const parsedItemCategory = itemCategory ?? getItemCategory(Object.keys(set.items));
|
|
1472
1477
|
let items = [];
|
|
@@ -1504,6 +1509,7 @@ function parseSet(set, itemCategory) {
|
|
|
1504
1509
|
return {
|
|
1505
1510
|
uuid: set.uuid,
|
|
1506
1511
|
category: "set",
|
|
1512
|
+
metadata: metadata ?? null,
|
|
1507
1513
|
itemCategory,
|
|
1508
1514
|
publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
|
|
1509
1515
|
date: set.date ?? null,
|
|
@@ -1527,10 +1533,11 @@ function parseSet(set, itemCategory) {
|
|
|
1527
1533
|
* @param resource - Raw resource data in OCHRE format
|
|
1528
1534
|
* @returns Parsed Resource object
|
|
1529
1535
|
*/
|
|
1530
|
-
function parseResource(resource) {
|
|
1536
|
+
function parseResource(resource, metadata) {
|
|
1531
1537
|
return {
|
|
1532
1538
|
uuid: resource.uuid,
|
|
1533
1539
|
category: "resource",
|
|
1540
|
+
metadata: metadata ?? null,
|
|
1534
1541
|
publicationDateTime: resource.publicationDateTime ? new Date(resource.publicationDateTime) : null,
|
|
1535
1542
|
type: resource.type,
|
|
1536
1543
|
number: resource.n,
|
|
@@ -1580,10 +1587,11 @@ function parseResources(resources) {
|
|
|
1580
1587
|
* @param spatialUnit - Raw spatial unit in OCHRE format
|
|
1581
1588
|
* @returns Parsed SpatialUnit object
|
|
1582
1589
|
*/
|
|
1583
|
-
function parseSpatialUnit(spatialUnit) {
|
|
1590
|
+
function parseSpatialUnit(spatialUnit, metadata) {
|
|
1584
1591
|
return {
|
|
1585
1592
|
uuid: spatialUnit.uuid,
|
|
1586
1593
|
category: "spatialUnit",
|
|
1594
|
+
metadata: metadata ?? null,
|
|
1587
1595
|
publicationDateTime: spatialUnit.publicationDateTime != null ? new Date(spatialUnit.publicationDateTime) : null,
|
|
1588
1596
|
number: spatialUnit.n,
|
|
1589
1597
|
context: "context" in spatialUnit && spatialUnit.context ? parseContext(spatialUnit.context) : null,
|
|
@@ -1621,10 +1629,11 @@ function parseSpatialUnits(spatialUnits) {
|
|
|
1621
1629
|
* @param concept - Raw concept data in OCHRE format
|
|
1622
1630
|
* @returns Parsed Concept object
|
|
1623
1631
|
*/
|
|
1624
|
-
function parseConcept(concept) {
|
|
1632
|
+
function parseConcept(concept, metadata) {
|
|
1625
1633
|
return {
|
|
1626
1634
|
uuid: concept.uuid,
|
|
1627
1635
|
category: "concept",
|
|
1636
|
+
metadata: metadata ?? null,
|
|
1628
1637
|
publicationDateTime: concept.publicationDateTime ? new Date(concept.publicationDateTime) : null,
|
|
1629
1638
|
number: concept.n,
|
|
1630
1639
|
license: "availability" in concept && concept.availability ? parseLicense(concept.availability) : null,
|
|
@@ -2920,49 +2929,50 @@ async function fetchItem(uuid, category, setCategory, options) {
|
|
|
2920
2929
|
});
|
|
2921
2930
|
if (error !== null) throw new Error(error);
|
|
2922
2931
|
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
2932
|
+
const metadata = parseMetadata(data.ochre.metadata);
|
|
2923
2933
|
let item;
|
|
2924
2934
|
switch (categoryKey) {
|
|
2925
2935
|
case "resource":
|
|
2926
2936
|
if (!("resource" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'resource' key");
|
|
2927
|
-
item = parseResource(data.ochre.resource);
|
|
2937
|
+
item = parseResource(data.ochre.resource, metadata);
|
|
2928
2938
|
break;
|
|
2929
2939
|
case "spatialUnit":
|
|
2930
2940
|
if (!("spatialUnit" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");
|
|
2931
|
-
item = parseSpatialUnit(data.ochre.spatialUnit);
|
|
2941
|
+
item = parseSpatialUnit(data.ochre.spatialUnit, metadata);
|
|
2932
2942
|
break;
|
|
2933
2943
|
case "concept":
|
|
2934
2944
|
if (!("concept" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'concept' key");
|
|
2935
|
-
item = parseConcept(data.ochre.concept);
|
|
2945
|
+
item = parseConcept(data.ochre.concept, metadata);
|
|
2936
2946
|
break;
|
|
2937
2947
|
case "period":
|
|
2938
2948
|
if (!("period" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'period' key");
|
|
2939
|
-
item = parsePeriod(data.ochre.period);
|
|
2949
|
+
item = parsePeriod(data.ochre.period, metadata);
|
|
2940
2950
|
break;
|
|
2941
2951
|
case "bibliography":
|
|
2942
2952
|
if (!("bibliography" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");
|
|
2943
|
-
item = parseBibliography(data.ochre.bibliography);
|
|
2953
|
+
item = parseBibliography(data.ochre.bibliography, metadata);
|
|
2944
2954
|
break;
|
|
2945
2955
|
case "person":
|
|
2946
2956
|
if (!("person" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'person' key");
|
|
2947
|
-
item = parsePerson(data.ochre.person);
|
|
2957
|
+
item = parsePerson(data.ochre.person, metadata);
|
|
2948
2958
|
break;
|
|
2949
2959
|
case "propertyValue":
|
|
2950
2960
|
if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
|
|
2951
|
-
item = parsePropertyValue(data.ochre.propertyValue);
|
|
2961
|
+
item = parsePropertyValue(data.ochre.propertyValue, metadata);
|
|
2952
2962
|
break;
|
|
2953
2963
|
case "set":
|
|
2954
2964
|
if (!("set" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
2955
|
-
item = parseSet(data.ochre.set, setCategory);
|
|
2965
|
+
item = parseSet(data.ochre.set, setCategory, metadata);
|
|
2956
2966
|
break;
|
|
2957
2967
|
case "tree":
|
|
2958
2968
|
if (!("tree" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'tree' key");
|
|
2959
|
-
item = parseTree(data.ochre.tree, category, setCategory);
|
|
2969
|
+
item = parseTree(data.ochre.tree, category, setCategory, metadata);
|
|
2960
2970
|
break;
|
|
2961
2971
|
default: throw new Error("Invalid category");
|
|
2962
2972
|
}
|
|
2963
2973
|
return {
|
|
2964
2974
|
error: null,
|
|
2965
|
-
metadata
|
|
2975
|
+
metadata,
|
|
2966
2976
|
belongsTo: {
|
|
2967
2977
|
uuid: data.ochre.uuidBelongsTo,
|
|
2968
2978
|
abbreviation: parseFakeString(data.ochre.belongsTo)
|
package/package.json
CHANGED