ochre-sdk 1.0.53 → 1.0.55

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.
@@ -1,5 +1,5 @@
1
1
  import * as v from "valibot";
2
- //#region src/utils.ts
2
+ //#region src/utilities.ts
3
3
  const PSEUDO_UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;
4
4
  function isRecord(value) {
5
5
  return typeof value === "object" && value != null;
@@ -88,7 +88,7 @@ function appendDetailedError(lines, error, fallbackMessage, depth, seenErrors) {
88
88
  }
89
89
  if (error.cause != null) {
90
90
  const causeLines = [];
91
- if (appendDetailedCause(causeLines, error.cause, depth, seenErrors)) lines.push("", ...causeLines);
91
+ if (didAppendDetailedCause(causeLines, error.cause, depth, seenErrors)) lines.push("", ...causeLines);
92
92
  }
93
93
  return;
94
94
  }
@@ -96,7 +96,7 @@ function appendDetailedError(lines, error, fallbackMessage, depth, seenErrors) {
96
96
  const value = formatCauseValue(error);
97
97
  if (value != null) lines.push(`${indent}Value: ${value}`);
98
98
  }
99
- function appendDetailedCause(lines, cause, depth, seenErrors) {
99
+ function didAppendDetailedCause(lines, cause, depth, seenErrors) {
100
100
  const indent = " ".repeat(depth);
101
101
  if (isSchemaValidationIssues(cause)) {
102
102
  lines.push(`${indent}Schema validation`);
@@ -169,4 +169,4 @@ function flattenProperties(properties) {
169
169
  return result;
170
170
  }
171
171
  //#endregion
172
- export { createSchemaValidationError, flattenProperties, getDetailedError, getErrorMessage, getErrorOutput, isPseudoUuid, stringLiteral };
172
+ export { createSchemaValidationError, flattenProperties, getErrorOutput, isPseudoUuid, stringLiteral };
@@ -1,4 +1,4 @@
1
- import { isPseudoUuid } from "../utils.mjs";
1
+ import { isPseudoUuid } from "../utilities.mjs";
2
2
  import * as v from "valibot";
3
3
  import { isValid, parseISO } from "date-fns";
4
4
  //#region src/xml/schemas.ts
@@ -58,10 +58,10 @@ const XMLContent = v.object({ content: v.array(v.object({
58
58
  }), "XMLContent: content is array of object with string, title, and lang") }, "XMLContent: Shape error");
59
59
  const XMLNumber = v.pipe(v.union([v.string("XMLNumber: string is string and required"), XMLString]), v.check(isXMLNumber, "XMLNumber: string is not a number"), v.transform(parseXMLNumber));
60
60
  const XMLOptionalNumber = v.optional(v.pipe(v.union([v.string("XMLNumber: string is string and required"), XMLString]), v.check(isOptionalXMLNumber, "XMLNumber: string is not a number"), v.transform(parseOptionalXMLNumber)));
61
- const XMLBoolean = v.pipe(v.union([v.string("XMLBoolean: string is string and required"), XMLString]), v.check((val) => {
62
- const payload = getXMLStringPayload(val);
61
+ const XMLBoolean = v.pipe(v.union([v.string("XMLBoolean: string is string and required"), XMLString]), v.check((value) => {
62
+ const payload = getXMLStringPayload(value);
63
63
  return payload === "true" || payload === "false";
64
- }, "XMLBoolean: string is not a boolean"), v.transform((val) => getXMLStringPayload(val) === "true"));
64
+ }, "XMLBoolean: string is not a boolean"), v.transform((value) => getXMLStringPayload(value) === "true"));
65
65
  function customDateTime(message) {
66
66
  return v.pipe(v.union([v.string(message), XMLString]), v.check(isXMLDate, message ?? "Invalid datetime format. Expected ISO date/time or YYYY-MM-DD HH:mm:ss"), v.transform(parseXMLDate));
67
67
  }
@@ -416,6 +416,11 @@ const XMLTree = v.object({
416
416
  ...XMLBaseItem.entries,
417
417
  date: v.optional(v.union([customDateTime("XMLTree: date is not a valid datetime"), XMLString])),
418
418
  links: v.optional(v.lazy(() => XMLLink)),
419
+ reverseLinks: v.optional(v.union([
420
+ v.lazy(() => XMLLink),
421
+ v.lazy(() => XMLDataItem),
422
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
423
+ ])),
419
424
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
420
425
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
421
426
  bibliographies: v.optional(v.object({ bibliography: v.array(v.lazy(() => XMLBibliography)) })),
@@ -440,6 +445,11 @@ const XMLSet = v.object({
440
445
  suppressBlanks: v.optional(XMLBoolean),
441
446
  tabularStructure: v.optional(XMLBoolean),
442
447
  links: v.optional(v.lazy(() => XMLLink)),
448
+ reverseLinks: v.optional(v.union([
449
+ v.lazy(() => XMLLink),
450
+ v.lazy(() => XMLDataItem),
451
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
452
+ ])),
443
453
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
444
454
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
445
455
  items: v.optional(v.object({
@@ -491,6 +501,11 @@ const XMLBibliography = v.object({
491
501
  authors: v.optional(v.object({ person: v.array(v.lazy(() => XMLPerson)) })),
492
502
  periods: v.optional(v.object({ period: v.array(v.lazy(() => XMLPeriod)) })),
493
503
  links: v.optional(v.lazy(() => XMLLink)),
504
+ reverseLinks: v.optional(v.union([
505
+ v.lazy(() => XMLLink),
506
+ v.lazy(() => XMLDataItem),
507
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
508
+ ])),
494
509
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
495
510
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
496
511
  bibliographies: v.optional(v.object({ bibliography: v.array(v.lazy(() => XMLBibliography)) })),
@@ -499,9 +514,14 @@ const XMLBibliography = v.object({
499
514
  const XMLInterpretation = v.object({
500
515
  interpretationNo: XMLNumber,
501
516
  date: v.optional(customDateTime("XMLInterpretation: date is not a valid datetime")),
502
- observers: v.optional(v.object({ observer: v.array(v.lazy(() => XMLPerson)) })),
517
+ interpreters: v.optional(v.object({ interpreter: v.array(v.lazy(() => XMLPerson)) })),
503
518
  periods: v.optional(v.object({ period: v.array(v.lazy(() => XMLPeriod)) })),
504
519
  links: v.optional(v.lazy(() => XMLLink)),
520
+ reverseLinks: v.optional(v.union([
521
+ v.lazy(() => XMLLink),
522
+ v.lazy(() => XMLDataItem),
523
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
524
+ ])),
505
525
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
506
526
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
507
527
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
@@ -510,6 +530,7 @@ const XMLConcept = v.object({
510
530
  ...XMLBaseItem.entries,
511
531
  image: v.optional(XMLImage),
512
532
  interpretations: v.optional(v.object({ interpretation: v.array(XMLInterpretation) })),
533
+ interpretation: v.optional(v.array(XMLInterpretation)),
513
534
  coordinates: v.optional(XMLCoordinates),
514
535
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
515
536
  concept: v.optional(v.array(v.lazy(() => XMLConcept)))
@@ -520,6 +541,11 @@ const XMLObservation = v.object({
520
541
  observers: v.optional(v.object({ observer: v.array(v.lazy(() => XMLPerson)) })),
521
542
  periods: v.optional(v.object({ period: v.array(v.lazy(() => XMLPeriod)) })),
522
543
  links: v.optional(v.lazy(() => XMLLink)),
544
+ reverseLinks: v.optional(v.union([
545
+ v.lazy(() => XMLLink),
546
+ v.lazy(() => XMLDataItem),
547
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
548
+ ])),
523
549
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
524
550
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
525
551
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
@@ -533,6 +559,7 @@ const XMLSpatialUnit = v.object({
533
559
  EPSG: XMLNumber
534
560
  }) }, "XMLSpatialUnit: mapData is object with geoJSON")),
535
561
  observations: v.optional(v.object({ observation: v.array(XMLObservation) })),
562
+ observation: v.optional(v.array(XMLObservation)),
536
563
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
537
564
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) })),
538
565
  spatialUnit: v.optional(v.array(v.lazy(() => XMLSpatialUnit)))
@@ -542,6 +569,11 @@ const XMLPeriod = v.object({
542
569
  type: v.optional(v.string("XMLPeriod: type is string and optional")),
543
570
  coordinates: v.optional(XMLCoordinates),
544
571
  links: v.optional(v.lazy(() => XMLDataItem)),
572
+ reverseLinks: v.optional(v.union([
573
+ v.lazy(() => XMLLink),
574
+ v.lazy(() => XMLDataItem),
575
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
576
+ ])),
545
577
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
546
578
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
547
579
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) })),
@@ -561,6 +593,11 @@ const XMLPerson = v.object({
561
593
  coordinates: v.optional(XMLCoordinates),
562
594
  periods: v.optional(v.object({ period: v.array(XMLPeriod) })),
563
595
  links: v.optional(v.lazy(() => XMLLink)),
596
+ reverseLinks: v.optional(v.union([
597
+ v.lazy(() => XMLLink),
598
+ v.lazy(() => XMLDataItem),
599
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
600
+ ])),
564
601
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
565
602
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
566
603
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
@@ -569,6 +606,11 @@ const XMLPropertyValue = v.object({
569
606
  ...XMLBaseItem.entries,
570
607
  coordinates: v.optional(XMLCoordinates),
571
608
  links: v.optional(v.lazy(() => XMLLink)),
609
+ reverseLinks: v.optional(v.union([
610
+ v.lazy(() => XMLLink),
611
+ v.lazy(() => XMLDataItem),
612
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
613
+ ])),
572
614
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
573
615
  properties: v.optional(v.object({ property: v.array(XMLProperty) })),
574
616
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
@@ -578,6 +620,11 @@ const XMLPropertyVariable = v.object({
578
620
  type: v.optional(v.string("XMLPropertyVariable: type is string and optional")),
579
621
  coordinates: v.optional(XMLCoordinates),
580
622
  links: v.optional(v.lazy(() => XMLLink)),
623
+ reverseLinks: v.optional(v.union([
624
+ v.lazy(() => XMLLink),
625
+ v.lazy(() => XMLDataItem),
626
+ v.array(v.union([v.lazy(() => XMLLink), v.lazy(() => XMLDataItem)]))
627
+ ])),
581
628
  notes: v.optional(v.object({ note: v.array(XMLNote) })),
582
629
  bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
583
630
  }, "XMLPropertyVariable: Shape error");
@@ -657,9 +704,9 @@ const XMLLink = v.pipe(v.object({
657
704
  text: v.optional(v.array(XMLLinkedText)),
658
705
  set: v.optional(v.array(XMLLinkedSet)),
659
706
  dictionaryUnit: v.optional(v.array(XMLDictionaryUnit))
660
- }, "XMLLink: Shape error"), v.check((val) => {
661
- if (Object.keys(val).length > 0) return true;
662
- for (const knownCategory of ITEM_CATEGORIES) if (val[knownCategory] != null) return true;
707
+ }, "XMLLink: Shape error"), v.check((value) => {
708
+ if (Object.keys(value).length > 0) return true;
709
+ for (const knownCategory of ITEM_CATEGORIES) if (value[knownCategory] != null) return true;
663
710
  return false;
664
711
  }, "XMLLink: at least one link category is required"));
665
712
  const XMLWebsiteContextLevel = v.intersect([XMLString, v.object({
@@ -790,20 +837,25 @@ const XMLDataItem = v.union([
790
837
  ], "XMLDataItem: Shape error");
791
838
  const XMLTopLevelDataItem = v.pipe(XMLDataItem, v.check((dataItem) => {
792
839
  if ("tree" in dataItem) return true;
793
- if ("bibliography" in dataItem) {
794
- for (const bibliography of dataItem.bibliography) for (const child of bibliography.bibliography ?? []) if ((child.bibliography?.length ?? 0) > 0) return false;
840
+ if ("bibliography" in dataItem) for (const bibliography of dataItem.bibliography) {
841
+ const children = bibliography.bibliography ?? [];
842
+ for (const child of children) if ((child.bibliography?.length ?? 0) > 0) return false;
795
843
  }
796
- if ("concept" in dataItem) {
797
- for (const concept of dataItem.concept) for (const child of concept.concept ?? []) if ((child.concept?.length ?? 0) > 0) return false;
844
+ if ("concept" in dataItem) for (const concept of dataItem.concept) {
845
+ const children = concept.concept ?? [];
846
+ for (const child of children) if ((child.concept?.length ?? 0) > 0) return false;
798
847
  }
799
- if ("spatialUnit" in dataItem) {
800
- for (const spatialUnit of dataItem.spatialUnit) for (const child of spatialUnit.spatialUnit ?? []) if ((child.spatialUnit?.length ?? 0) > 0) return false;
848
+ if ("spatialUnit" in dataItem) for (const spatialUnit of dataItem.spatialUnit) {
849
+ const children = spatialUnit.spatialUnit ?? [];
850
+ for (const child of children) if ((child.spatialUnit?.length ?? 0) > 0) return false;
801
851
  }
802
- if ("period" in dataItem) {
803
- for (const period of dataItem.period) for (const child of period.period ?? []) if ((child.period?.length ?? 0) > 0) return false;
852
+ if ("period" in dataItem) for (const period of dataItem.period) {
853
+ const children = period.period ?? [];
854
+ for (const child of children) if ((child.period?.length ?? 0) > 0) return false;
804
855
  }
805
- if ("resource" in dataItem) {
806
- for (const resource of dataItem.resource) for (const child of resource.resource ?? []) if ((child.resource?.length ?? 0) > 0) return false;
856
+ if ("resource" in dataItem) for (const resource of dataItem.resource) {
857
+ const children = resource.resource ?? [];
858
+ for (const child of children) if ((child.resource?.length ?? 0) > 0) return false;
807
859
  }
808
860
  return true;
809
861
  }, "XMLDataItem: standalone recursive item children cannot contain nested recursive children"));
@@ -299,6 +299,7 @@ type XMLBibliography = Partial<XMLBaseItem> & {
299
299
  period: Array<XMLPeriod>;
300
300
  };
301
301
  links?: XMLLink;
302
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
302
303
  notes?: {
303
304
  note: Array<XMLNote>;
304
305
  };
@@ -401,13 +402,14 @@ type XMLDictionaryUnit = XMLLinkedBaseItem;
401
402
  type XMLInterpretation = {
402
403
  interpretationNo: XMLNumber;
403
404
  date?: Date;
404
- observers?: {
405
- observer: Array<XMLPerson>;
405
+ interpreters?: {
406
+ interpreter: Array<XMLPerson>;
406
407
  };
407
408
  periods?: {
408
409
  period: Array<XMLPeriod>;
409
410
  };
410
411
  links?: XMLLink;
412
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
411
413
  notes?: {
412
414
  note: Array<XMLNote>;
413
415
  };
@@ -424,6 +426,7 @@ type XMLConcept = XMLBaseItem & {
424
426
  interpretations?: {
425
427
  interpretation: Array<XMLInterpretation>;
426
428
  };
429
+ interpretation?: Array<XMLInterpretation>;
427
430
  coordinates?: XMLCoordinates;
428
431
  properties?: {
429
432
  property: Array<XMLProperty>;
@@ -440,6 +443,7 @@ type XMLObservation = {
440
443
  period: Array<XMLPeriod>;
441
444
  };
442
445
  links?: XMLLink;
446
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
443
447
  notes?: {
444
448
  note: Array<XMLNote>;
445
449
  };
@@ -464,6 +468,7 @@ type XMLSpatialUnit = XMLBaseItem & {
464
468
  observations?: {
465
469
  observation: Array<XMLObservation>;
466
470
  };
471
+ observation?: Array<XMLObservation>;
467
472
  properties?: {
468
473
  property: Array<XMLProperty>;
469
474
  };
@@ -476,6 +481,7 @@ type XMLPeriod = XMLBaseItem & {
476
481
  type?: string;
477
482
  coordinates?: XMLCoordinates;
478
483
  links?: XMLDataItem;
484
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
479
485
  notes?: {
480
486
  note: Array<XMLNote>;
481
487
  };
@@ -501,6 +507,7 @@ type XMLPerson = XMLBaseItem & Partial<XMLContent> & {
501
507
  period: Array<XMLPeriod>;
502
508
  };
503
509
  links?: XMLLink;
510
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
504
511
  notes?: {
505
512
  note: Array<XMLNote>;
506
513
  };
@@ -515,6 +522,7 @@ type XMLPropertyVariable = XMLBaseItem & {
515
522
  type?: string;
516
523
  coordinates?: XMLCoordinates;
517
524
  links?: XMLLink;
525
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
518
526
  notes?: {
519
527
  note: Array<XMLNote>;
520
528
  };
@@ -525,6 +533,7 @@ type XMLPropertyVariable = XMLBaseItem & {
525
533
  type XMLPropertyValue = XMLBaseItem & {
526
534
  coordinates?: XMLCoordinates;
527
535
  links?: XMLLink;
536
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
528
537
  notes?: {
529
538
  note: Array<XMLNote>;
530
539
  };
@@ -588,14 +597,14 @@ type XMLText = XMLBaseItem & {
588
597
  notes?: {
589
598
  note: Array<XMLNote>;
590
599
  };
591
- sections?: {
600
+ sections?: XMLString | {
592
601
  translation?: Array<{
593
602
  section: Array<XMLSection>;
594
603
  }>;
595
604
  phonemic?: Array<{
596
605
  section: Array<XMLSection>;
597
606
  }>;
598
- } | XMLString;
607
+ };
599
608
  periods?: {
600
609
  period: Array<XMLPeriod>;
601
610
  };
@@ -633,6 +642,7 @@ type XMLTree = XMLBaseItem & {
633
642
  type?: string;
634
643
  date?: Date | XMLString;
635
644
  links?: XMLLink;
645
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
636
646
  notes?: {
637
647
  note: Array<XMLNote>;
638
648
  };
@@ -747,6 +757,7 @@ type XMLSet = XMLBaseItem & {
747
757
  suppressBlanks?: XMLBoolean;
748
758
  tabularStructure?: XMLBoolean;
749
759
  links?: XMLLink;
760
+ reverseLinks?: XMLLink | XMLDataItem | Array<XMLLink | XMLDataItem>;
750
761
  notes?: {
751
762
  note: Array<XMLNote>;
752
763
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
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",
@@ -47,16 +47,16 @@
47
47
  "dependencies": {
48
48
  "date-fns": "^4.4.0",
49
49
  "fast-equals": "^6.0.0",
50
- "fast-xml-parser": "^5.9.2",
50
+ "fast-xml-parser": "^5.9.3",
51
51
  "valibot": "^1.4.1"
52
52
  },
53
53
  "devDependencies": {
54
- "@antfu/eslint-config": "^9.0.0",
54
+ "@antfu/eslint-config": "^9.1.0",
55
55
  "@types/node": "^24.13.2",
56
56
  "bumpp": "^11.1.0",
57
57
  "eslint": "^10.5.0",
58
- "knip": "^6.17.1",
59
- "oxfmt": "^0.55.0",
58
+ "knip": "^6.20.0",
59
+ "oxfmt": "^0.56.0",
60
60
  "tsdown": "^0.22.3",
61
61
  "typescript": "^6.0.3",
62
62
  "vitest": "^4.1.9"