@digitalculture/ochre-sdk 0.15.8 → 0.15.10

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 CHANGED
@@ -9,6 +9,7 @@ type Data<T extends DataCategory = DataCategory, U extends DataCategory = (T ext
9
9
  abbreviation: string;
10
10
  };
11
11
  publicationDateTime: Date;
12
+ persistentUrl: string | null;
12
13
  item: Item<T, U>;
13
14
  };
14
15
  /**
@@ -87,6 +88,7 @@ type Person = {
87
88
  category: "person";
88
89
  metadata: Metadata | null;
89
90
  publicationDateTime: Date | null;
91
+ persistentUrl: string | null;
90
92
  type: string | null;
91
93
  number: number | null;
92
94
  context: Context | null;
@@ -290,6 +292,7 @@ type Resource = {
290
292
  category: "resource";
291
293
  metadata: Metadata | null;
292
294
  publicationDateTime: Date | null;
295
+ persistentUrl: string | null;
293
296
  type: string;
294
297
  number: number;
295
298
  context: Context | null;
@@ -323,6 +326,7 @@ type SpatialUnit = {
323
326
  category: "spatialUnit";
324
327
  metadata: Metadata | null;
325
328
  publicationDateTime: Date | null;
329
+ persistentUrl: string | null;
326
330
  number: number;
327
331
  context: Context | null;
328
332
  license: License | null;
@@ -349,6 +353,7 @@ type Concept = {
349
353
  category: "concept";
350
354
  metadata: Metadata | null;
351
355
  publicationDateTime: Date | null;
356
+ persistentUrl: string | null;
352
357
  number: number;
353
358
  license: License | null;
354
359
  context: Context | null;
@@ -369,6 +374,7 @@ type Set<U extends DataCategory = DataCategory> = {
369
374
  metadata: Metadata | null;
370
375
  itemCategories: Array<U>;
371
376
  publicationDateTime: Date | null;
377
+ persistentUrl: string | null;
372
378
  type: string;
373
379
  number: number;
374
380
  date: string | null;
@@ -388,6 +394,7 @@ type Bibliography = {
388
394
  category: "bibliography";
389
395
  metadata: Metadata | null;
390
396
  publicationDateTime: Date | null;
397
+ persistentUrl: string | null;
391
398
  type: string | null;
392
399
  number: number | null;
393
400
  identification: Identification | null;
@@ -423,6 +430,7 @@ type Period = {
423
430
  category: "period";
424
431
  metadata: Metadata | null;
425
432
  publicationDateTime: Date | null;
433
+ persistentUrl: string | null;
426
434
  type: string | null;
427
435
  number: number | null;
428
436
  identification: Identification;
@@ -436,6 +444,7 @@ type PropertyValue = {
436
444
  uuid: string;
437
445
  category: "propertyValue";
438
446
  metadata: Metadata | null;
447
+ persistentUrl: string | null;
439
448
  number: number;
440
449
  publicationDateTime: Date | null;
441
450
  context: Context | null;
@@ -453,6 +462,7 @@ type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "
453
462
  * Represents a property value with type information
454
463
  */
455
464
  type PropertyValueContent<T extends PropertyValueContentType> = {
465
+ hierarchyLevel: number | null;
456
466
  content: (T extends "integer" ? number : T extends "decimal" ? number : T extends "time" ? number : T extends "boolean" ? boolean : string) | null;
457
467
  dataType: T;
458
468
  label: string | null;
@@ -486,6 +496,7 @@ type Text = {
486
496
  category: "text";
487
497
  metadata: Metadata | null;
488
498
  publicationDateTime: Date | null;
499
+ persistentUrl: string | null;
489
500
  type: string | null;
490
501
  language: string | null;
491
502
  number: number;
@@ -525,6 +536,7 @@ type Tree<U extends Exclude<DataCategory, "tree"> = Exclude<DataCategory, "tree"
525
536
  category: "tree";
526
537
  metadata: Metadata | null;
527
538
  publicationDateTime: Date | null;
539
+ persistentUrl: string | null;
528
540
  type: string;
529
541
  number: number;
530
542
  date: string | null;
@@ -551,7 +563,7 @@ type PropertyQueryItem = {
551
563
  uuid: string | null;
552
564
  category: string | null;
553
565
  type: string | null;
554
- dataType: string;
566
+ dataType: string | null;
555
567
  publicationDateTime: string | null;
556
568
  content: string;
557
569
  label: string | null;
package/dist/index.mjs CHANGED
@@ -935,12 +935,13 @@ function parseLicense(license) {
935
935
  * @param person - Raw person data from OCHRE format
936
936
  * @returns Parsed Person object
937
937
  */
938
- function parsePerson(person, metadata) {
938
+ function parsePerson(person, metadata, persistentUrl) {
939
939
  return {
940
940
  uuid: person.uuid,
941
941
  category: "person",
942
942
  metadata: metadata ?? null,
943
943
  publicationDateTime: person.publicationDateTime != null ? new Date(person.publicationDateTime) : null,
944
+ persistentUrl: persistentUrl ?? null,
944
945
  type: person.type ?? null,
945
946
  number: person.n ?? null,
946
947
  context: person.context ? parseContext(person.context) : null,
@@ -1224,6 +1225,7 @@ function parseProperty(property, language = "eng") {
1224
1225
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1225
1226
  content = parseFakeString(value);
1226
1227
  return {
1228
+ hierarchyLevel: null,
1227
1229
  content,
1228
1230
  label: null,
1229
1231
  dataType: "string",
@@ -1279,6 +1281,7 @@ function parseProperty(property, language = "eng") {
1279
1281
  break;
1280
1282
  }
1281
1283
  return {
1284
+ hierarchyLevel: value.i ?? null,
1282
1285
  content,
1283
1286
  dataType: parsedType,
1284
1287
  isUncertain: value.isUncertain ?? false,
@@ -1295,6 +1298,9 @@ function parseProperty(property, language = "eng") {
1295
1298
  slug: value.slug ?? null
1296
1299
  };
1297
1300
  }
1301
+ }).toSorted((a, b) => {
1302
+ if (a.hierarchyLevel != null && b.hierarchyLevel != null) return b.hierarchyLevel - a.hierarchyLevel;
1303
+ return 0;
1298
1304
  });
1299
1305
  return {
1300
1306
  uuid: property.label.uuid,
@@ -1363,12 +1369,13 @@ function parseImageMap(imageMap) {
1363
1369
  * @param period - Raw period data in OCHRE format
1364
1370
  * @returns Parsed Period object
1365
1371
  */
1366
- function parsePeriod(period, metadata) {
1372
+ function parsePeriod(period, metadata, persistentUrl) {
1367
1373
  return {
1368
1374
  uuid: period.uuid,
1369
1375
  category: "period",
1370
1376
  metadata: metadata ?? null,
1371
1377
  publicationDateTime: period.publicationDateTime != null ? new Date(period.publicationDateTime) : null,
1378
+ persistentUrl: persistentUrl ?? null,
1372
1379
  type: period.type ?? null,
1373
1380
  number: period.n ?? null,
1374
1381
  identification: parseIdentification(period.identification),
@@ -1393,7 +1400,7 @@ function parsePeriods(periods) {
1393
1400
  * @param bibliography - Raw bibliography data in OCHRE format
1394
1401
  * @returns Parsed Bibliography object
1395
1402
  */
1396
- function parseBibliography(bibliography, metadata) {
1403
+ function parseBibliography(bibliography, metadata, persistentUrl) {
1397
1404
  const sourceResources = [];
1398
1405
  if (bibliography.source?.resource) {
1399
1406
  const resourcesToParse = Array.isArray(bibliography.source.resource) ? bibliography.source.resource : [bibliography.source.resource];
@@ -1424,6 +1431,7 @@ function parseBibliography(bibliography, metadata) {
1424
1431
  category: "bibliography",
1425
1432
  metadata: metadata ?? null,
1426
1433
  publicationDateTime: bibliography.publicationDateTime != null ? new Date(bibliography.publicationDateTime) : null,
1434
+ persistentUrl: persistentUrl ?? null,
1427
1435
  type: bibliography.type ?? null,
1428
1436
  number: bibliography.n ?? null,
1429
1437
  identification: bibliography.identification ? parseIdentification(bibliography.identification) : null,
@@ -1469,13 +1477,14 @@ function parseBibliographies(bibliographies) {
1469
1477
  * @param propertyValue - Raw property value data in OCHRE format
1470
1478
  * @returns Parsed PropertyValue object
1471
1479
  */
1472
- function parsePropertyValue(propertyValue, metadata) {
1480
+ function parsePropertyValue(propertyValue, metadata, persistentUrl) {
1473
1481
  return {
1474
1482
  uuid: propertyValue.uuid,
1475
1483
  category: "propertyValue",
1476
1484
  metadata: metadata ?? null,
1477
1485
  number: propertyValue.n,
1478
1486
  publicationDateTime: propertyValue.publicationDateTime ? new Date(propertyValue.publicationDateTime) : null,
1487
+ persistentUrl: persistentUrl ?? null,
1479
1488
  context: propertyValue.context ? parseContext(propertyValue.context) : null,
1480
1489
  availability: propertyValue.availability ? parseLicense(propertyValue.availability) : null,
1481
1490
  identification: parseIdentification(propertyValue.identification),
@@ -1504,12 +1513,13 @@ function parsePropertyValues(propertyValues) {
1504
1513
  * @param text - Raw text data in OCHRE format
1505
1514
  * @returns Parsed Text object
1506
1515
  */
1507
- function parseText(text, metadata) {
1516
+ function parseText(text, metadata, persistentUrl) {
1508
1517
  return {
1509
1518
  uuid: text.uuid,
1510
1519
  category: "text",
1511
1520
  metadata: metadata ?? null,
1512
1521
  publicationDateTime: text.publicationDateTime ? new Date(text.publicationDateTime) : null,
1522
+ persistentUrl: persistentUrl ?? null,
1513
1523
  type: text.type ?? null,
1514
1524
  language: text.language ?? null,
1515
1525
  number: text.n ?? 0,
@@ -1582,7 +1592,7 @@ function parseSections(sections) {
1582
1592
  * @param tree - Raw tree data in OCHRE format
1583
1593
  * @returns Parsed Tree object or null if invalid
1584
1594
  */
1585
- function parseTree(tree, itemCategory, metadata) {
1595
+ function parseTree(tree, itemCategory, metadata, persistentUrl) {
1586
1596
  if (typeof tree.items === "string") throw new TypeError("Invalid OCHRE data: Tree has no items");
1587
1597
  let creators = [];
1588
1598
  if (tree.creators) creators = parsePersons(Array.isArray(tree.creators.creator) ? tree.creators.creator : [tree.creators.creator]);
@@ -1637,6 +1647,7 @@ function parseTree(tree, itemCategory, metadata) {
1637
1647
  category: "tree",
1638
1648
  metadata: metadata ?? null,
1639
1649
  publicationDateTime: new Date(tree.publicationDateTime),
1650
+ persistentUrl: persistentUrl ?? null,
1640
1651
  identification: parseIdentification(tree.identification),
1641
1652
  creators,
1642
1653
  license: parseLicense(tree.availability),
@@ -1653,7 +1664,7 @@ function parseTree(tree, itemCategory, metadata) {
1653
1664
  * @param set - Raw set data in OCHRE format
1654
1665
  * @returns Parsed Set object
1655
1666
  */
1656
- function parseSet(set, itemCategories, metadata) {
1667
+ function parseSet(set, itemCategories, metadata, persistentUrl) {
1657
1668
  if (typeof set.items === "string") throw new TypeError("Invalid OCHRE data: Set has no items");
1658
1669
  const parsedItemCategories = itemCategories ?? getItemCategories(Object.keys(set.items));
1659
1670
  let items = [];
@@ -1698,6 +1709,7 @@ function parseSet(set, itemCategories, metadata) {
1698
1709
  metadata: metadata ?? null,
1699
1710
  itemCategories: parsedItemCategories,
1700
1711
  publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
1712
+ persistentUrl: persistentUrl ?? null,
1701
1713
  date: set.date ?? null,
1702
1714
  license: parseLicense(set.availability),
1703
1715
  identification: parseIdentification(set.identification),
@@ -1719,12 +1731,13 @@ function parseSet(set, itemCategories, metadata) {
1719
1731
  * @param resource - Raw resource data in OCHRE format
1720
1732
  * @returns Parsed Resource object
1721
1733
  */
1722
- function parseResource(resource, metadata) {
1734
+ function parseResource(resource, metadata, persistentUrl) {
1723
1735
  return {
1724
1736
  uuid: resource.uuid,
1725
1737
  category: "resource",
1726
1738
  metadata: metadata ?? null,
1727
1739
  publicationDateTime: resource.publicationDateTime ? new Date(resource.publicationDateTime) : null,
1740
+ persistentUrl: persistentUrl ?? null,
1728
1741
  type: resource.type,
1729
1742
  number: resource.n,
1730
1743
  fileFormat: resource.fileFormat ?? null,
@@ -1773,12 +1786,13 @@ function parseResources(resources) {
1773
1786
  * @param spatialUnit - Raw spatial unit in OCHRE format
1774
1787
  * @returns Parsed SpatialUnit object
1775
1788
  */
1776
- function parseSpatialUnit(spatialUnit, metadata) {
1789
+ function parseSpatialUnit(spatialUnit, metadata, persistentUrl) {
1777
1790
  return {
1778
1791
  uuid: spatialUnit.uuid,
1779
1792
  category: "spatialUnit",
1780
1793
  metadata: metadata ?? null,
1781
1794
  publicationDateTime: spatialUnit.publicationDateTime != null ? new Date(spatialUnit.publicationDateTime) : null,
1795
+ persistentUrl: persistentUrl ?? null,
1782
1796
  number: spatialUnit.n,
1783
1797
  context: "context" in spatialUnit && spatialUnit.context ? parseContext(spatialUnit.context) : null,
1784
1798
  license: "availability" in spatialUnit && spatialUnit.availability ? parseLicense(spatialUnit.availability) : null,
@@ -1815,12 +1829,13 @@ function parseSpatialUnits(spatialUnits) {
1815
1829
  * @param concept - Raw concept data in OCHRE format
1816
1830
  * @returns Parsed Concept object
1817
1831
  */
1818
- function parseConcept(concept, metadata) {
1832
+ function parseConcept(concept, metadata, persistentUrl) {
1819
1833
  return {
1820
1834
  uuid: concept.uuid,
1821
1835
  category: "concept",
1822
1836
  metadata: metadata ?? null,
1823
1837
  publicationDateTime: concept.publicationDateTime ? new Date(concept.publicationDateTime) : null,
1838
+ persistentUrl: persistentUrl ?? null,
1824
1839
  number: concept.n,
1825
1840
  license: "availability" in concept && concept.availability ? parseLicense(concept.availability) : null,
1826
1841
  context: "context" in concept && concept.context ? parseContext(concept.context) : null,
@@ -3158,43 +3173,43 @@ async function fetchItem(uuid, category, itemCategory, options) {
3158
3173
  switch (categoryKey) {
3159
3174
  case "resource":
3160
3175
  if (!("resource" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'resource' key");
3161
- item = parseResource(data.ochre.resource, metadata);
3176
+ item = parseResource(data.ochre.resource, metadata, data.ochre.persistentUrl);
3162
3177
  break;
3163
3178
  case "spatialUnit":
3164
3179
  if (!("spatialUnit" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");
3165
- item = parseSpatialUnit(data.ochre.spatialUnit, metadata);
3180
+ item = parseSpatialUnit(data.ochre.spatialUnit, metadata, data.ochre.persistentUrl);
3166
3181
  break;
3167
3182
  case "concept":
3168
3183
  if (!("concept" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'concept' key");
3169
- item = parseConcept(data.ochre.concept, metadata);
3184
+ item = parseConcept(data.ochre.concept, metadata, data.ochre.persistentUrl);
3170
3185
  break;
3171
3186
  case "period":
3172
3187
  if (!("period" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'period' key");
3173
- item = parsePeriod(data.ochre.period, metadata);
3188
+ item = parsePeriod(data.ochre.period, metadata, data.ochre.persistentUrl);
3174
3189
  break;
3175
3190
  case "bibliography":
3176
3191
  if (!("bibliography" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");
3177
- item = parseBibliography(data.ochre.bibliography, metadata);
3192
+ item = parseBibliography(data.ochre.bibliography, metadata, data.ochre.persistentUrl);
3178
3193
  break;
3179
3194
  case "person":
3180
3195
  if (!("person" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'person' key");
3181
- item = parsePerson(data.ochre.person, metadata);
3196
+ item = parsePerson(data.ochre.person, metadata, data.ochre.persistentUrl);
3182
3197
  break;
3183
3198
  case "propertyValue":
3184
3199
  if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
3185
- item = parsePropertyValue(data.ochre.propertyValue, metadata);
3200
+ item = parsePropertyValue(data.ochre.propertyValue, metadata, data.ochre.persistentUrl);
3186
3201
  break;
3187
3202
  case "text":
3188
3203
  if (!("text" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'text' key");
3189
- item = parseText(data.ochre.text, metadata);
3204
+ item = parseText(data.ochre.text, metadata, data.ochre.persistentUrl);
3190
3205
  break;
3191
3206
  case "set":
3192
3207
  if (!("set" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'set' key");
3193
- item = parseSet(data.ochre.set, itemCategory, metadata);
3208
+ item = parseSet(data.ochre.set, itemCategory, metadata, data.ochre.persistentUrl);
3194
3209
  break;
3195
3210
  case "tree":
3196
3211
  if (!("tree" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'tree' key");
3197
- item = parseTree(data.ochre.tree, itemCategory, metadata);
3212
+ item = parseTree(data.ochre.tree, itemCategory, metadata, data.ochre.persistentUrl);
3198
3213
  break;
3199
3214
  default: throw new Error("Invalid category");
3200
3215
  }
@@ -3244,7 +3259,7 @@ const responseItemSchema = z.object({
3244
3259
  uuid: z.string().refine(isUUID).optional(),
3245
3260
  category: z.string().optional(),
3246
3261
  type: z.string().optional(),
3247
- dataType: z.string(),
3262
+ dataType: z.string().optional(),
3248
3263
  publicationDateTime: z.string().optional(),
3249
3264
  content: z.string().optional(),
3250
3265
  rawValue: z.string().optional()
@@ -3316,7 +3331,7 @@ async function fetchPropertyQuery(scopeUuids, propertyUuids, options) {
3316
3331
  uuid: valueUuid ?? null,
3317
3332
  category: item.value.category ?? null,
3318
3333
  type: item.value.type ?? null,
3319
- dataType: item.value.dataType,
3334
+ dataType: item.value.dataType ?? null,
3320
3335
  publicationDateTime: item.value.publicationDateTime ?? null,
3321
3336
  content: item.value.rawValue ?? item.value.content ?? "",
3322
3337
  label: item.value.rawValue != null && item.value.content != null ? item.value.content : null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.15.8",
3
+ "version": "0.15.10",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",