@digitalculture/ochre-sdk 0.15.7 → 0.15.9

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;
@@ -472,6 +481,7 @@ type PropertyValueContent<T extends PropertyValueContentType> = {
472
481
  * Represents a property with label, values and nested properties
473
482
  */
474
483
  type Property<T extends PropertyValueContentType = PropertyValueContentType> = {
484
+ hierarchyLevel: number | null;
475
485
  uuid: string;
476
486
  label: string;
477
487
  values: Array<PropertyValueContent<T>>;
@@ -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,
@@ -1297,6 +1298,7 @@ function parseProperty(property, language = "eng") {
1297
1298
  }
1298
1299
  });
1299
1300
  return {
1301
+ hierarchyLevel: property.i ?? null,
1300
1302
  uuid: property.label.uuid,
1301
1303
  label: parseStringContent(property.label, language).replace(/\s*\.{3}$/, "").trim(),
1302
1304
  values,
@@ -1363,12 +1365,13 @@ function parseImageMap(imageMap) {
1363
1365
  * @param period - Raw period data in OCHRE format
1364
1366
  * @returns Parsed Period object
1365
1367
  */
1366
- function parsePeriod(period, metadata) {
1368
+ function parsePeriod(period, metadata, persistentUrl) {
1367
1369
  return {
1368
1370
  uuid: period.uuid,
1369
1371
  category: "period",
1370
1372
  metadata: metadata ?? null,
1371
1373
  publicationDateTime: period.publicationDateTime != null ? new Date(period.publicationDateTime) : null,
1374
+ persistentUrl: persistentUrl ?? null,
1372
1375
  type: period.type ?? null,
1373
1376
  number: period.n ?? null,
1374
1377
  identification: parseIdentification(period.identification),
@@ -1393,7 +1396,7 @@ function parsePeriods(periods) {
1393
1396
  * @param bibliography - Raw bibliography data in OCHRE format
1394
1397
  * @returns Parsed Bibliography object
1395
1398
  */
1396
- function parseBibliography(bibliography, metadata) {
1399
+ function parseBibliography(bibliography, metadata, persistentUrl) {
1397
1400
  const sourceResources = [];
1398
1401
  if (bibliography.source?.resource) {
1399
1402
  const resourcesToParse = Array.isArray(bibliography.source.resource) ? bibliography.source.resource : [bibliography.source.resource];
@@ -1424,6 +1427,7 @@ function parseBibliography(bibliography, metadata) {
1424
1427
  category: "bibliography",
1425
1428
  metadata: metadata ?? null,
1426
1429
  publicationDateTime: bibliography.publicationDateTime != null ? new Date(bibliography.publicationDateTime) : null,
1430
+ persistentUrl: persistentUrl ?? null,
1427
1431
  type: bibliography.type ?? null,
1428
1432
  number: bibliography.n ?? null,
1429
1433
  identification: bibliography.identification ? parseIdentification(bibliography.identification) : null,
@@ -1469,13 +1473,14 @@ function parseBibliographies(bibliographies) {
1469
1473
  * @param propertyValue - Raw property value data in OCHRE format
1470
1474
  * @returns Parsed PropertyValue object
1471
1475
  */
1472
- function parsePropertyValue(propertyValue, metadata) {
1476
+ function parsePropertyValue(propertyValue, metadata, persistentUrl) {
1473
1477
  return {
1474
1478
  uuid: propertyValue.uuid,
1475
1479
  category: "propertyValue",
1476
1480
  metadata: metadata ?? null,
1477
1481
  number: propertyValue.n,
1478
1482
  publicationDateTime: propertyValue.publicationDateTime ? new Date(propertyValue.publicationDateTime) : null,
1483
+ persistentUrl: persistentUrl ?? null,
1479
1484
  context: propertyValue.context ? parseContext(propertyValue.context) : null,
1480
1485
  availability: propertyValue.availability ? parseLicense(propertyValue.availability) : null,
1481
1486
  identification: parseIdentification(propertyValue.identification),
@@ -1504,12 +1509,13 @@ function parsePropertyValues(propertyValues) {
1504
1509
  * @param text - Raw text data in OCHRE format
1505
1510
  * @returns Parsed Text object
1506
1511
  */
1507
- function parseText(text, metadata) {
1512
+ function parseText(text, metadata, persistentUrl) {
1508
1513
  return {
1509
1514
  uuid: text.uuid,
1510
1515
  category: "text",
1511
1516
  metadata: metadata ?? null,
1512
1517
  publicationDateTime: text.publicationDateTime ? new Date(text.publicationDateTime) : null,
1518
+ persistentUrl: persistentUrl ?? null,
1513
1519
  type: text.type ?? null,
1514
1520
  language: text.language ?? null,
1515
1521
  number: text.n ?? 0,
@@ -1582,7 +1588,7 @@ function parseSections(sections) {
1582
1588
  * @param tree - Raw tree data in OCHRE format
1583
1589
  * @returns Parsed Tree object or null if invalid
1584
1590
  */
1585
- function parseTree(tree, itemCategory, metadata) {
1591
+ function parseTree(tree, itemCategory, metadata, persistentUrl) {
1586
1592
  if (typeof tree.items === "string") throw new TypeError("Invalid OCHRE data: Tree has no items");
1587
1593
  let creators = [];
1588
1594
  if (tree.creators) creators = parsePersons(Array.isArray(tree.creators.creator) ? tree.creators.creator : [tree.creators.creator]);
@@ -1637,6 +1643,7 @@ function parseTree(tree, itemCategory, metadata) {
1637
1643
  category: "tree",
1638
1644
  metadata: metadata ?? null,
1639
1645
  publicationDateTime: new Date(tree.publicationDateTime),
1646
+ persistentUrl: persistentUrl ?? null,
1640
1647
  identification: parseIdentification(tree.identification),
1641
1648
  creators,
1642
1649
  license: parseLicense(tree.availability),
@@ -1653,7 +1660,7 @@ function parseTree(tree, itemCategory, metadata) {
1653
1660
  * @param set - Raw set data in OCHRE format
1654
1661
  * @returns Parsed Set object
1655
1662
  */
1656
- function parseSet(set, itemCategories, metadata) {
1663
+ function parseSet(set, itemCategories, metadata, persistentUrl) {
1657
1664
  if (typeof set.items === "string") throw new TypeError("Invalid OCHRE data: Set has no items");
1658
1665
  const parsedItemCategories = itemCategories ?? getItemCategories(Object.keys(set.items));
1659
1666
  let items = [];
@@ -1698,6 +1705,7 @@ function parseSet(set, itemCategories, metadata) {
1698
1705
  metadata: metadata ?? null,
1699
1706
  itemCategories: parsedItemCategories,
1700
1707
  publicationDateTime: set.publicationDateTime ? new Date(set.publicationDateTime) : null,
1708
+ persistentUrl: persistentUrl ?? null,
1701
1709
  date: set.date ?? null,
1702
1710
  license: parseLicense(set.availability),
1703
1711
  identification: parseIdentification(set.identification),
@@ -1719,12 +1727,13 @@ function parseSet(set, itemCategories, metadata) {
1719
1727
  * @param resource - Raw resource data in OCHRE format
1720
1728
  * @returns Parsed Resource object
1721
1729
  */
1722
- function parseResource(resource, metadata) {
1730
+ function parseResource(resource, metadata, persistentUrl) {
1723
1731
  return {
1724
1732
  uuid: resource.uuid,
1725
1733
  category: "resource",
1726
1734
  metadata: metadata ?? null,
1727
1735
  publicationDateTime: resource.publicationDateTime ? new Date(resource.publicationDateTime) : null,
1736
+ persistentUrl: persistentUrl ?? null,
1728
1737
  type: resource.type,
1729
1738
  number: resource.n,
1730
1739
  fileFormat: resource.fileFormat ?? null,
@@ -1773,12 +1782,13 @@ function parseResources(resources) {
1773
1782
  * @param spatialUnit - Raw spatial unit in OCHRE format
1774
1783
  * @returns Parsed SpatialUnit object
1775
1784
  */
1776
- function parseSpatialUnit(spatialUnit, metadata) {
1785
+ function parseSpatialUnit(spatialUnit, metadata, persistentUrl) {
1777
1786
  return {
1778
1787
  uuid: spatialUnit.uuid,
1779
1788
  category: "spatialUnit",
1780
1789
  metadata: metadata ?? null,
1781
1790
  publicationDateTime: spatialUnit.publicationDateTime != null ? new Date(spatialUnit.publicationDateTime) : null,
1791
+ persistentUrl: persistentUrl ?? null,
1782
1792
  number: spatialUnit.n,
1783
1793
  context: "context" in spatialUnit && spatialUnit.context ? parseContext(spatialUnit.context) : null,
1784
1794
  license: "availability" in spatialUnit && spatialUnit.availability ? parseLicense(spatialUnit.availability) : null,
@@ -1815,12 +1825,13 @@ function parseSpatialUnits(spatialUnits) {
1815
1825
  * @param concept - Raw concept data in OCHRE format
1816
1826
  * @returns Parsed Concept object
1817
1827
  */
1818
- function parseConcept(concept, metadata) {
1828
+ function parseConcept(concept, metadata, persistentUrl) {
1819
1829
  return {
1820
1830
  uuid: concept.uuid,
1821
1831
  category: "concept",
1822
1832
  metadata: metadata ?? null,
1823
1833
  publicationDateTime: concept.publicationDateTime ? new Date(concept.publicationDateTime) : null,
1834
+ persistentUrl: persistentUrl ?? null,
1824
1835
  number: concept.n,
1825
1836
  license: "availability" in concept && concept.availability ? parseLicense(concept.availability) : null,
1826
1837
  context: "context" in concept && concept.context ? parseContext(concept.context) : null,
@@ -2183,7 +2194,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2183
2194
  let isFullHeight = true;
2184
2195
  const isFullHeightProperty = getPropertyValueByLabel(componentProperty.properties, "is-full-height");
2185
2196
  if (isFullHeightProperty !== null) isFullHeight = isFullHeightProperty === true;
2186
- let captionSource = getPropertyValueByLabel(componentProperty.properties, "caption-source");
2197
+ let captionSource = getPropertyValueByLabel(componentProperty.properties, "source-caption");
2187
2198
  captionSource ??= "name";
2188
2199
  let altTextSource = getPropertyValueByLabel(componentProperty.properties, "alt-text-source");
2189
2200
  altTextSource ??= "name";
@@ -3158,43 +3169,43 @@ async function fetchItem(uuid, category, itemCategory, options) {
3158
3169
  switch (categoryKey) {
3159
3170
  case "resource":
3160
3171
  if (!("resource" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'resource' key");
3161
- item = parseResource(data.ochre.resource, metadata);
3172
+ item = parseResource(data.ochre.resource, metadata, data.ochre.persistentUrl);
3162
3173
  break;
3163
3174
  case "spatialUnit":
3164
3175
  if (!("spatialUnit" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");
3165
- item = parseSpatialUnit(data.ochre.spatialUnit, metadata);
3176
+ item = parseSpatialUnit(data.ochre.spatialUnit, metadata, data.ochre.persistentUrl);
3166
3177
  break;
3167
3178
  case "concept":
3168
3179
  if (!("concept" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'concept' key");
3169
- item = parseConcept(data.ochre.concept, metadata);
3180
+ item = parseConcept(data.ochre.concept, metadata, data.ochre.persistentUrl);
3170
3181
  break;
3171
3182
  case "period":
3172
3183
  if (!("period" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'period' key");
3173
- item = parsePeriod(data.ochre.period, metadata);
3184
+ item = parsePeriod(data.ochre.period, metadata, data.ochre.persistentUrl);
3174
3185
  break;
3175
3186
  case "bibliography":
3176
3187
  if (!("bibliography" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");
3177
- item = parseBibliography(data.ochre.bibliography, metadata);
3188
+ item = parseBibliography(data.ochre.bibliography, metadata, data.ochre.persistentUrl);
3178
3189
  break;
3179
3190
  case "person":
3180
3191
  if (!("person" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'person' key");
3181
- item = parsePerson(data.ochre.person, metadata);
3192
+ item = parsePerson(data.ochre.person, metadata, data.ochre.persistentUrl);
3182
3193
  break;
3183
3194
  case "propertyValue":
3184
3195
  if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
3185
- item = parsePropertyValue(data.ochre.propertyValue, metadata);
3196
+ item = parsePropertyValue(data.ochre.propertyValue, metadata, data.ochre.persistentUrl);
3186
3197
  break;
3187
3198
  case "text":
3188
3199
  if (!("text" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'text' key");
3189
- item = parseText(data.ochre.text, metadata);
3200
+ item = parseText(data.ochre.text, metadata, data.ochre.persistentUrl);
3190
3201
  break;
3191
3202
  case "set":
3192
3203
  if (!("set" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'set' key");
3193
- item = parseSet(data.ochre.set, itemCategory, metadata);
3204
+ item = parseSet(data.ochre.set, itemCategory, metadata, data.ochre.persistentUrl);
3194
3205
  break;
3195
3206
  case "tree":
3196
3207
  if (!("tree" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'tree' key");
3197
- item = parseTree(data.ochre.tree, itemCategory, metadata);
3208
+ item = parseTree(data.ochre.tree, itemCategory, metadata, data.ochre.persistentUrl);
3198
3209
  break;
3199
3210
  default: throw new Error("Invalid category");
3200
3211
  }
@@ -3244,7 +3255,7 @@ const responseItemSchema = z.object({
3244
3255
  uuid: z.string().refine(isUUID).optional(),
3245
3256
  category: z.string().optional(),
3246
3257
  type: z.string().optional(),
3247
- dataType: z.string(),
3258
+ dataType: z.string().optional(),
3248
3259
  publicationDateTime: z.string().optional(),
3249
3260
  content: z.string().optional(),
3250
3261
  rawValue: z.string().optional()
@@ -3316,7 +3327,7 @@ async function fetchPropertyQuery(scopeUuids, propertyUuids, options) {
3316
3327
  uuid: valueUuid ?? null,
3317
3328
  category: item.value.category ?? null,
3318
3329
  type: item.value.type ?? null,
3319
- dataType: item.value.dataType,
3330
+ dataType: item.value.dataType ?? null,
3320
3331
  publicationDateTime: item.value.publicationDateTime ?? null,
3321
3332
  content: item.value.rawValue ?? item.value.content ?? "",
3322
3333
  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.7",
3
+ "version": "0.15.9",
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",