@digitalculture/ochre-sdk 0.13.10 → 0.14.1

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
@@ -14,11 +14,11 @@ type Data<T extends DataCategory = DataCategory, U extends DataCategory = (T ext
14
14
  /**
15
15
  * Represents the category of the data
16
16
  */
17
- type DataCategory = "tree" | "set" | "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue";
17
+ type DataCategory = "resource" | "spatialUnit" | "concept" | "period" | "bibliography" | "person" | "propertyValue" | "text" | "tree" | "set";
18
18
  /**
19
19
  * Represents the item of the data, with proper type narrowing based on category
20
20
  */
21
- type Item<T extends DataCategory = DataCategory, U extends DataCategory = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? 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 "tree" ? Tree<Exclude<U, "tree">> : T extends "set" ? Set<U> : Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue | Tree<Exclude<U, "tree">> | Set<U>;
21
+ type Item<T extends DataCategory = DataCategory, U extends DataCategory = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? 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<Exclude<U, "tree">> : T extends "set" ? Set<U> : Resource | SpatialUnit | Concept | Period | Bibliography | Person | PropertyValue | Tree<Exclude<U, "tree">> | Set<U>;
22
22
  /**
23
23
  * Basic identification information used across multiple types
24
24
  */
@@ -380,6 +380,7 @@ type Bibliography = {
380
380
  identification: Identification | null;
381
381
  projectIdentification: Identification | null;
382
382
  context: Context | null;
383
+ image: Image | null;
383
384
  citation: {
384
385
  details: string | null;
385
386
  format: string | null;
@@ -394,10 +395,7 @@ type Bibliography = {
394
395
  startIssue: string;
395
396
  startVolume: string;
396
397
  } | null;
397
- source: {
398
- resource: Pick<Resource, "uuid" | "publicationDateTime" | "type" | "identification"> | null;
399
- documentUrl: string | null;
400
- };
398
+ sourceResources: Array<Pick<Resource, "uuid" | "category" | "publicationDateTime" | "type" | "identification" | "href">>;
401
399
  periods: Array<Period>;
402
400
  authors: Array<Person>;
403
401
  properties: Array<Property>;
@@ -460,6 +458,44 @@ type Property<T extends PropertyValueContentType = PropertyValueContentType> = {
460
458
  comment: string | null;
461
459
  properties: Array<Property>;
462
460
  };
461
+ /**
462
+ * Represents a resource item with associated metadata, content and relationships
463
+ */
464
+ type Text = {
465
+ uuid: string;
466
+ category: "text";
467
+ metadata: Metadata | null;
468
+ publicationDateTime: Date | null;
469
+ type: string | null;
470
+ language: string | null;
471
+ number: number;
472
+ context: Context | null;
473
+ license: License | null;
474
+ copyright: string | null;
475
+ watermark: string | null;
476
+ identification: Identification;
477
+ image: Image | null;
478
+ creators: Array<Person>;
479
+ editors: Array<Person>;
480
+ notes: Array<Note>;
481
+ description: string;
482
+ periods: Array<Period>;
483
+ links: Array<Link>;
484
+ reverseLinks: Array<Link>;
485
+ properties: Array<Property>;
486
+ bibliographies: Array<Bibliography>;
487
+ sections: Array<Section>;
488
+ };
489
+ /**
490
+ * Represents a section of a text
491
+ */
492
+ type Section = {
493
+ uuid: string;
494
+ variant: "translation" | "phonemic";
495
+ type: string;
496
+ identification: Identification;
497
+ projectIdentification: Identification | null;
498
+ };
463
499
  /**
464
500
  * Represents a tree structure containing resources, spatial units and concepts
465
501
  */
@@ -475,7 +511,7 @@ type Tree<U extends Exclude<DataCategory, "tree"> = Exclude<DataCategory, "tree"
475
511
  identification: Identification;
476
512
  creators: Array<Person>;
477
513
  properties: Array<Property>;
478
- 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 "set" ? Array<Set<DataCategory>> : Array<Item>;
514
+ 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<DataCategory>> : Array<Item>;
479
515
  };
480
516
  /**
481
517
  * Represents a gallery with its identification, project identification, resources and max length
@@ -1237,4 +1273,4 @@ declare function filterProperties(property: Property, filter: {
1237
1273
  value: string | number | boolean | Date;
1238
1274
  }, options?: PropertyOptions): boolean;
1239
1275
  //#endregion
1240
- export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, 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 };
1276
+ export { Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, Data, DataCategory, Event, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Section, Set, SpatialUnit, Style, Text, 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
@@ -2,10 +2,37 @@ import * as z from "zod";
2
2
 
3
3
  //#region src/schemas.ts
4
4
  /**
5
+ * Validates a pseudo-UUID string
6
+ * @param value - The string to validate
7
+ * @returns True if the string is a valid pseudo-UUID, false otherwise
8
+ * @internal
9
+ */
10
+ function isPseudoUuid(value) {
11
+ return /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i.test(value);
12
+ }
13
+ /**
5
14
  * Schema for validating UUIDs
6
15
  * @internal
7
16
  */
8
- const uuidSchema = z.uuid({ error: "Invalid UUID provided" });
17
+ const uuidSchema = z.string().refine(isPseudoUuid, { error: "Invalid UUID" });
18
+ /**
19
+ * Schema for validating filters
20
+ * @internal
21
+ */
22
+ const filterSchema = z.string().optional();
23
+ /**
24
+ * Schema for validating data options
25
+ * @internal
26
+ */
27
+ const dataOptionsSchema = z.object({
28
+ filter: z.string().optional().default(""),
29
+ start: z.number().positive({ error: "Start must be positive" }).optional().default(1),
30
+ limit: z.number().positive({ error: "Limit must be positive" }).optional().default(40)
31
+ }).optional().default({
32
+ filter: "",
33
+ start: 1,
34
+ limit: 40
35
+ });
9
36
  /**
10
37
  * Schema for validating website properties
11
38
  * @internal
@@ -72,8 +99,9 @@ const categorySchema = z.enum([
72
99
  "bibliography",
73
100
  "person",
74
101
  "propertyValue",
75
- "set",
76
- "tree"
102
+ "text",
103
+ "tree",
104
+ "set"
77
105
  ]);
78
106
  /**
79
107
  * Schema for validating property value content types
@@ -95,7 +123,7 @@ const propertyValueContentTypeSchema = z.enum([
95
123
  * @internal
96
124
  */
97
125
  const gallerySchema = z.object({
98
- uuid: z.uuid({ error: "Invalid UUID" }),
126
+ uuid: z.string().refine(isPseudoUuid, { error: "Invalid UUID" }),
99
127
  filter: z.string().optional(),
100
128
  page: z.number().positive({ error: "Page must be positive" }),
101
129
  perPage: z.number().positive({ error: "Per page must be positive" })
@@ -1305,13 +1333,18 @@ function parsePeriods(periods) {
1305
1333
  * @returns Parsed Bibliography object
1306
1334
  */
1307
1335
  function parseBibliography(bibliography, metadata) {
1308
- let resource = null;
1309
- if (bibliography.source?.resource) resource = {
1310
- uuid: bibliography.source.resource.uuid,
1311
- publicationDateTime: bibliography.source.resource.publicationDateTime ? new Date(bibliography.source.resource.publicationDateTime) : null,
1312
- type: bibliography.source.resource.type,
1313
- identification: parseIdentification(bibliography.source.resource.identification)
1314
- };
1336
+ const sourceResources = [];
1337
+ if (bibliography.source?.resource) {
1338
+ const resourcesToParse = Array.isArray(bibliography.source.resource) ? bibliography.source.resource : [bibliography.source.resource];
1339
+ for (const resource of resourcesToParse) sourceResources.push({
1340
+ uuid: resource.uuid,
1341
+ category: "resource",
1342
+ publicationDateTime: new Date(resource.publicationDateTime),
1343
+ type: resource.type,
1344
+ identification: parseIdentification(resource.identification),
1345
+ href: resource.href ?? null
1346
+ });
1347
+ }
1315
1348
  let shortCitation = null;
1316
1349
  let longCitation = null;
1317
1350
  if (bibliography.citationFormatSpan) try {
@@ -1335,6 +1368,7 @@ function parseBibliography(bibliography, metadata) {
1335
1368
  identification: bibliography.identification ? parseIdentification(bibliography.identification) : null,
1336
1369
  projectIdentification: bibliography.project?.identification ? parseIdentification(bibliography.project.identification) : null,
1337
1370
  context: bibliography.context ? parseContext(bibliography.context) : null,
1371
+ image: bibliography.image ? parseImage(bibliography.image) : null,
1338
1372
  citation: {
1339
1373
  details: bibliography.citationDetails ?? null,
1340
1374
  format: bibliography.citationFormat ?? null,
@@ -1349,10 +1383,7 @@ function parseBibliography(bibliography, metadata) {
1349
1383
  startIssue: parseFakeString(bibliography.entryInfo.startIssue),
1350
1384
  startVolume: parseFakeString(bibliography.entryInfo.startVolume)
1351
1385
  } : null,
1352
- source: {
1353
- resource,
1354
- documentUrl: bibliography.sourceDocument ? `https://ochre.lib.uchicago.edu/ochre?uuid=${bibliography.sourceDocument.uuid}&load` : null
1355
- },
1386
+ sourceResources,
1356
1387
  periods: bibliography.periods ? parsePeriods(Array.isArray(bibliography.periods.period) ? bibliography.periods.period : [bibliography.periods.period]) : [],
1357
1388
  authors: bibliography.authors ? parsePersons(Array.isArray(bibliography.authors.person) ? bibliography.authors.person : [bibliography.authors.person]) : [],
1358
1389
  properties: bibliography.properties ? parseProperties(Array.isArray(bibliography.properties.property) ? bibliography.properties.property : [bibliography.properties.property]) : []
@@ -1404,6 +1435,83 @@ function parsePropertyValues(propertyValues) {
1404
1435
  return returnPropertyValues;
1405
1436
  }
1406
1437
  /**
1438
+ * Parses raw text data into a standardized Text object
1439
+ *
1440
+ * @param text - Raw text data in OCHRE format
1441
+ * @returns Parsed Text object
1442
+ */
1443
+ function parseText(text, metadata) {
1444
+ return {
1445
+ uuid: text.uuid,
1446
+ category: "text",
1447
+ metadata: metadata ?? null,
1448
+ publicationDateTime: text.publicationDateTime ? new Date(text.publicationDateTime) : null,
1449
+ type: text.type ?? null,
1450
+ language: text.language ?? null,
1451
+ number: text.n ?? 0,
1452
+ context: text.context ? parseContext(text.context) : null,
1453
+ license: "availability" in text && text.availability ? parseLicense(text.availability) : null,
1454
+ copyright: "copyright" in text && text.copyright != null ? parseStringContent(text.copyright) : null,
1455
+ watermark: "watermark" in text && text.watermark != null ? parseStringContent(text.watermark) : null,
1456
+ identification: parseIdentification(text.identification),
1457
+ image: text.image ? parseImage(text.image) : null,
1458
+ creators: text.creators ? parsePersons(Array.isArray(text.creators.creator) ? text.creators.creator : [text.creators.creator]) : [],
1459
+ editors: text.editions ? parsePersons(Array.isArray(text.editions.editor) ? text.editions.editor : [text.editions.editor]) : [],
1460
+ notes: text.notes ? parseNotes(Array.isArray(text.notes.note) ? text.notes.note : [text.notes.note]) : [],
1461
+ description: text.description ? parseStringContent(text.description) : "",
1462
+ periods: text.periods ? parsePeriods(Array.isArray(text.periods.period) ? text.periods.period : [text.periods.period]) : [],
1463
+ links: text.links ? parseLinks(Array.isArray(text.links) ? text.links : [text.links]) : [],
1464
+ reverseLinks: text.reverseLinks ? parseLinks(Array.isArray(text.reverseLinks) ? text.reverseLinks : [text.reverseLinks]) : [],
1465
+ properties: text.properties ? parseProperties(Array.isArray(text.properties.property) ? text.properties.property : [text.properties.property]) : [],
1466
+ bibliographies: text.bibliographies ? parseBibliographies(Array.isArray(text.bibliographies.bibliography) ? text.bibliographies.bibliography : [text.bibliographies.bibliography]) : [],
1467
+ sections: text.sections ? parseSections(text.sections) : []
1468
+ };
1469
+ }
1470
+ /**
1471
+ * Parses an array of raw texts into standardized Text objects
1472
+ *
1473
+ * @param texts - Array of raw texts in OCHRE format
1474
+ * @returns Array of parsed Text objects
1475
+ */
1476
+ function parseTexts(texts) {
1477
+ const returnTexts = [];
1478
+ for (const text of texts) returnTexts.push(parseText(text));
1479
+ return returnTexts;
1480
+ }
1481
+ /**
1482
+ * Parses a raw section data into a standardized Section object
1483
+ *
1484
+ * @param section - Raw section data in OCHRE format
1485
+ * @returns Parsed Section object
1486
+ */
1487
+ function parseSection(section, variant) {
1488
+ return {
1489
+ uuid: section.uuid,
1490
+ variant,
1491
+ type: section.type,
1492
+ identification: parseIdentification(section.identification),
1493
+ projectIdentification: section.project?.identification ? parseIdentification(section.project.identification) : null
1494
+ };
1495
+ }
1496
+ /**
1497
+ * Parses raw sections data into a standardized Section object
1498
+ *
1499
+ * @param sections - Raw sections data in OCHRE format
1500
+ * @param sections.translation - Translation sections
1501
+ * @param sections.phonemic - Phonemic sections
1502
+ * @param sections.translation.section - Translation sections
1503
+ * @param sections.phonemic.section - Phonemic sections
1504
+ * @returns Parsed Section object
1505
+ */
1506
+ function parseSections(sections) {
1507
+ const returnSections = [];
1508
+ const translationSections = sections.translation ? Array.isArray(sections.translation.section) ? sections.translation.section : [sections.translation.section] : [];
1509
+ const phonemicSections = sections.phonemic ? Array.isArray(sections.phonemic.section) ? sections.phonemic.section : [sections.phonemic.section] : [];
1510
+ for (const section of translationSections) returnSections.push(parseSection(section, "translation"));
1511
+ for (const section of phonemicSections) returnSections.push(parseSection(section, "phonemic"));
1512
+ return returnSections;
1513
+ }
1514
+ /**
1407
1515
  * Parses a raw tree structure into a standardized Tree object
1408
1516
  *
1409
1517
  * @param tree - Raw tree data in OCHRE format
@@ -1446,6 +1554,10 @@ function parseTree(tree, itemCategory, metadata) {
1446
1554
  if (!("propertyValue" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no property values");
1447
1555
  items = parsePropertyValues(Array.isArray(tree.items.propertyValue) ? tree.items.propertyValue : [tree.items.propertyValue]);
1448
1556
  break;
1557
+ case "text":
1558
+ if (!("text" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no texts");
1559
+ items = parseTexts(Array.isArray(tree.items.text) ? tree.items.text : [tree.items.text]);
1560
+ break;
1449
1561
  case "set": {
1450
1562
  if (!("set" in tree.items)) throw new Error("Invalid OCHRE data: Tree has no sets");
1451
1563
  const setItems = [];
@@ -1509,6 +1621,10 @@ function parseSet(set, itemCategory, metadata) {
1509
1621
  if (!("propertyValue" in set.items)) throw new Error("Invalid OCHRE data: Set has no property values");
1510
1622
  items = parsePropertyValues(Array.isArray(set.items.propertyValue) ? set.items.propertyValue : [set.items.propertyValue]);
1511
1623
  break;
1624
+ case "text":
1625
+ if (!("text" in set.items)) throw new Error("Invalid OCHRE data: Set has no texts");
1626
+ items = parseTexts(Array.isArray(set.items.text) ? set.items.text : [set.items.text]);
1627
+ break;
1512
1628
  default: throw new Error("Invalid OCHRE data: Set has no items or is malformed");
1513
1629
  }
1514
1630
  return {
@@ -1720,7 +1836,6 @@ function parseWebElementProperties(componentProperty, elementResource) {
1720
1836
  properties.fileSize = resourceLink.fileSize;
1721
1837
  properties.isInteractive = isInteractive;
1722
1838
  properties.isControlsDisplayed = isControlsDisplayed;
1723
- properties.isLightingDisplayed = isLightingDisplayed;
1724
1839
  break;
1725
1840
  }
1726
1841
  case "advanced-search": {
@@ -2981,6 +3096,10 @@ async function fetchItem(uuid, category, itemCategory, options) {
2981
3096
  if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
2982
3097
  item = parsePropertyValue(data.ochre.propertyValue, metadata);
2983
3098
  break;
3099
+ case "text":
3100
+ if (!("text" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'text' key");
3101
+ item = parseText(data.ochre.text, metadata);
3102
+ break;
2984
3103
  case "set":
2985
3104
  if (!("set" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'set' key");
2986
3105
  item = parseSet(data.ochre.set, itemCategory, metadata);
@@ -3196,7 +3315,6 @@ const KNOWN_ABBREVIATIONS = {
3196
3315
  ssmc: "8ff977dd-d440-40f5-ad93-8ad7e2d39e74",
3197
3316
  "sosc-core-at-smart": "db26c953-9b2a-4691-a909-5e8726b531d7"
3198
3317
  };
3199
- const V2_ABBREVIATIONS = /* @__PURE__ */ new Set();
3200
3318
  /**
3201
3319
  * Fetches and parses a website configuration from the OCHRE API
3202
3320
  *
@@ -3230,7 +3348,7 @@ async function fetchWebsite(abbreviation, options) {
3230
3348
  try {
3231
3349
  const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
3232
3350
  const customFetch = options?.customFetch;
3233
- const isVersion2 = V2_ABBREVIATIONS.has(cleanAbbreviation) ? true : options?.isVersion2 ?? false;
3351
+ const isVersion2 = cleanAbbreviation.endsWith("-v2") ? true : options?.isVersion2 ?? false;
3234
3352
  let metadata = null;
3235
3353
  let tree = null;
3236
3354
  if (isVersion2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.13.10",
3
+ "version": "0.14.1",
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",