@digitalculture/ochre-sdk 0.6.5 → 0.7.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.cjs +41 -19
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +41 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -134,6 +134,17 @@ var categorySchema = import_zod.z.enum([
|
|
|
134
134
|
"set",
|
|
135
135
|
"tree"
|
|
136
136
|
]);
|
|
137
|
+
var propertyValueContentTypeSchema = import_zod.z.enum([
|
|
138
|
+
"string",
|
|
139
|
+
"integer",
|
|
140
|
+
"decimal",
|
|
141
|
+
"boolean",
|
|
142
|
+
"date",
|
|
143
|
+
"dateTime",
|
|
144
|
+
"time",
|
|
145
|
+
"coordinate",
|
|
146
|
+
"IDREF"
|
|
147
|
+
]);
|
|
137
148
|
var gallerySchema = import_zod.z.object({
|
|
138
149
|
uuid: import_zod.z.string().uuid({ message: "Invalid UUID" }),
|
|
139
150
|
filter: import_zod.z.string().optional(),
|
|
@@ -1016,7 +1027,7 @@ function parseEvents(events) {
|
|
|
1016
1027
|
}
|
|
1017
1028
|
return returnEvents;
|
|
1018
1029
|
}
|
|
1019
|
-
function parseProperty(property,
|
|
1030
|
+
function parseProperty(property, language = "eng") {
|
|
1020
1031
|
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
1021
1032
|
const values = valuesToParse.map((value) => {
|
|
1022
1033
|
let content = null;
|
|
@@ -1026,14 +1037,15 @@ function parseProperty(property, type, language = "eng") {
|
|
|
1026
1037
|
const returnValue = {
|
|
1027
1038
|
content,
|
|
1028
1039
|
booleanValue,
|
|
1029
|
-
type,
|
|
1040
|
+
type: "string",
|
|
1030
1041
|
category: "value",
|
|
1031
1042
|
uuid: null,
|
|
1032
|
-
publicationDateTime: null
|
|
1043
|
+
publicationDateTime: null,
|
|
1044
|
+
unit: null
|
|
1033
1045
|
};
|
|
1034
1046
|
return returnValue;
|
|
1035
1047
|
} else {
|
|
1036
|
-
switch (type) {
|
|
1048
|
+
switch (value.type) {
|
|
1037
1049
|
case "integer":
|
|
1038
1050
|
case "decimal": {
|
|
1039
1051
|
content = Number(value.content);
|
|
@@ -1049,19 +1061,32 @@ function parseProperty(property, type, language = "eng") {
|
|
|
1049
1061
|
} else if (value.content != null) {
|
|
1050
1062
|
content = parseStringContent({ content: value.content });
|
|
1051
1063
|
}
|
|
1052
|
-
if (type === "boolean") {
|
|
1064
|
+
if (value.type === "boolean") {
|
|
1053
1065
|
booleanValue = value.booleanValue ?? null;
|
|
1054
1066
|
}
|
|
1055
1067
|
break;
|
|
1056
1068
|
}
|
|
1057
1069
|
}
|
|
1070
|
+
let parsedType = "string";
|
|
1071
|
+
if (value.type != null) {
|
|
1072
|
+
const { data, error } = propertyValueContentTypeSchema.safeParse(
|
|
1073
|
+
value.type
|
|
1074
|
+
);
|
|
1075
|
+
if (error) {
|
|
1076
|
+
throw new Error(
|
|
1077
|
+
`Invalid property value content type: "${value.type}"`
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
parsedType = data;
|
|
1081
|
+
}
|
|
1058
1082
|
const returnValue = {
|
|
1059
1083
|
content,
|
|
1060
1084
|
booleanValue,
|
|
1061
|
-
type,
|
|
1085
|
+
type: parsedType,
|
|
1062
1086
|
category: value.category ?? "value",
|
|
1063
1087
|
uuid: value.uuid ?? null,
|
|
1064
|
-
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
1088
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null,
|
|
1089
|
+
unit: value.unit ?? null
|
|
1065
1090
|
};
|
|
1066
1091
|
return returnValue;
|
|
1067
1092
|
}
|
|
@@ -1078,9 +1103,7 @@ function parseProperty(property, type, language = "eng") {
|
|
|
1078
1103
|
function parseProperties(properties, language = "eng") {
|
|
1079
1104
|
const returnProperties = [];
|
|
1080
1105
|
for (const property of properties) {
|
|
1081
|
-
returnProperties.push(
|
|
1082
|
-
parseProperty(property, "string", language)
|
|
1083
|
-
);
|
|
1106
|
+
returnProperties.push(parseProperty(property, language));
|
|
1084
1107
|
}
|
|
1085
1108
|
return returnProperties;
|
|
1086
1109
|
}
|
|
@@ -1420,14 +1443,11 @@ function parseResource(resource) {
|
|
|
1420
1443
|
creators: resource.creators ? parsePersons(
|
|
1421
1444
|
Array.isArray(resource.creators.creator) ? resource.creators.creator : [resource.creators.creator]
|
|
1422
1445
|
) : [],
|
|
1423
|
-
notes: (
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
Array.isArray(resource.notes.note) ? resource.notes.note : [resource.notes.note]
|
|
1427
|
-
) : []
|
|
1428
|
-
),
|
|
1446
|
+
notes: resource.notes ? parseNotes(
|
|
1447
|
+
Array.isArray(resource.notes.note) ? resource.notes.note : [resource.notes.note]
|
|
1448
|
+
) : [],
|
|
1429
1449
|
description: resource.description ? ["string", "number", "boolean"].includes(typeof resource.description) ? parseFakeString(resource.description) : parseStringContent(resource.description) : "",
|
|
1430
|
-
document: resource.document ? parseDocument(resource.document.content) : null,
|
|
1450
|
+
document: resource.document && "content" in resource.document ? parseDocument(resource.document.content) : null,
|
|
1431
1451
|
href: resource.href ?? null,
|
|
1432
1452
|
imageMap: resource.imagemap ? parseImageMap(resource.imagemap) : null,
|
|
1433
1453
|
periods: resource.periods ? parsePeriods(
|
|
@@ -1570,7 +1590,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1570
1590
|
const imageLinks = links.filter(
|
|
1571
1591
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1572
1592
|
);
|
|
1573
|
-
let document = elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1593
|
+
let document = elementResource.document && "content" in elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1574
1594
|
if (document === null) {
|
|
1575
1595
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
1576
1596
|
if (documentLink) {
|
|
@@ -2656,7 +2676,9 @@ async function fetchGallery(uuid, filter, page, perPage) {
|
|
|
2656
2676
|
const gallery = {
|
|
2657
2677
|
identification: galleryIdentification,
|
|
2658
2678
|
projectIdentification: galleryProjectIdentification,
|
|
2659
|
-
resources:
|
|
2679
|
+
resources: parseResources(
|
|
2680
|
+
data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? data.result.gallery.resource : [data.result.gallery.resource] : []
|
|
2681
|
+
),
|
|
2660
2682
|
maxLength: data.result.gallery.maxLength
|
|
2661
2683
|
};
|
|
2662
2684
|
return { item: gallery, error: null };
|
package/dist/index.d.cts
CHANGED
|
@@ -346,20 +346,21 @@ type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "
|
|
|
346
346
|
/**
|
|
347
347
|
* Represents a property value with type information
|
|
348
348
|
*/
|
|
349
|
-
type PropertyValueContent
|
|
350
|
-
content:
|
|
351
|
-
booleanValue:
|
|
352
|
-
type:
|
|
349
|
+
type PropertyValueContent = {
|
|
350
|
+
content: string | number | boolean | Date | null;
|
|
351
|
+
booleanValue: boolean | null;
|
|
352
|
+
type: PropertyValueContentType;
|
|
353
353
|
category: string;
|
|
354
354
|
uuid: string | null;
|
|
355
355
|
publicationDateTime: Date | null;
|
|
356
|
+
unit: string | null;
|
|
356
357
|
};
|
|
357
358
|
/**
|
|
358
359
|
* Represents a property with label, values and nested properties
|
|
359
360
|
*/
|
|
360
361
|
type Property = {
|
|
361
362
|
label: string;
|
|
362
|
-
values: Array<PropertyValueContent
|
|
363
|
+
values: Array<PropertyValueContent>;
|
|
363
364
|
comment: string | null;
|
|
364
365
|
properties: Array<Property>;
|
|
365
366
|
};
|
|
@@ -898,9 +899,11 @@ type OchreResource = {
|
|
|
898
899
|
image?: OchreImage;
|
|
899
900
|
creators?: { creator: OchrePerson | Array<OchrePerson> };
|
|
900
901
|
notes?: { note: OchreNote | Array<OchreNote> };
|
|
901
|
-
document?:
|
|
902
|
-
|
|
903
|
-
|
|
902
|
+
document?:
|
|
903
|
+
| {
|
|
904
|
+
content: OchreStringRichText | Array<OchreStringRichText>;
|
|
905
|
+
}
|
|
906
|
+
| object;
|
|
904
907
|
imagemap?: OchreImageMap;
|
|
905
908
|
periods?: { period: OchrePeriod | Array<OchrePeriod> };
|
|
906
909
|
links?: OchreLink | Array<OchreLink>;
|
|
@@ -953,9 +956,10 @@ type OchreConcept = {
|
|
|
953
956
|
type OchrePropertyValueContent = {
|
|
954
957
|
uuid?: string;
|
|
955
958
|
publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
|
|
956
|
-
type
|
|
959
|
+
type?: string;
|
|
957
960
|
category?: string;
|
|
958
961
|
slug?: FakeString;
|
|
962
|
+
unit?: string;
|
|
959
963
|
booleanValue?: boolean;
|
|
960
964
|
content?: FakeString | OchreStringItem | Array<OchreStringItem>;
|
|
961
965
|
};
|
|
@@ -1536,7 +1540,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
|
|
|
1536
1540
|
* @returns Array of parsed Event objects
|
|
1537
1541
|
*/
|
|
1538
1542
|
declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
|
|
1539
|
-
declare function parseProperty
|
|
1543
|
+
declare function parseProperty(property: OchreProperty, language?: string): Property;
|
|
1540
1544
|
/**
|
|
1541
1545
|
* Parses raw properties into standardized Property objects
|
|
1542
1546
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -346,20 +346,21 @@ type PropertyValueContentType = "string" | "integer" | "decimal" | "boolean" | "
|
|
|
346
346
|
/**
|
|
347
347
|
* Represents a property value with type information
|
|
348
348
|
*/
|
|
349
|
-
type PropertyValueContent
|
|
350
|
-
content:
|
|
351
|
-
booleanValue:
|
|
352
|
-
type:
|
|
349
|
+
type PropertyValueContent = {
|
|
350
|
+
content: string | number | boolean | Date | null;
|
|
351
|
+
booleanValue: boolean | null;
|
|
352
|
+
type: PropertyValueContentType;
|
|
353
353
|
category: string;
|
|
354
354
|
uuid: string | null;
|
|
355
355
|
publicationDateTime: Date | null;
|
|
356
|
+
unit: string | null;
|
|
356
357
|
};
|
|
357
358
|
/**
|
|
358
359
|
* Represents a property with label, values and nested properties
|
|
359
360
|
*/
|
|
360
361
|
type Property = {
|
|
361
362
|
label: string;
|
|
362
|
-
values: Array<PropertyValueContent
|
|
363
|
+
values: Array<PropertyValueContent>;
|
|
363
364
|
comment: string | null;
|
|
364
365
|
properties: Array<Property>;
|
|
365
366
|
};
|
|
@@ -898,9 +899,11 @@ type OchreResource = {
|
|
|
898
899
|
image?: OchreImage;
|
|
899
900
|
creators?: { creator: OchrePerson | Array<OchrePerson> };
|
|
900
901
|
notes?: { note: OchreNote | Array<OchreNote> };
|
|
901
|
-
document?:
|
|
902
|
-
|
|
903
|
-
|
|
902
|
+
document?:
|
|
903
|
+
| {
|
|
904
|
+
content: OchreStringRichText | Array<OchreStringRichText>;
|
|
905
|
+
}
|
|
906
|
+
| object;
|
|
904
907
|
imagemap?: OchreImageMap;
|
|
905
908
|
periods?: { period: OchrePeriod | Array<OchrePeriod> };
|
|
906
909
|
links?: OchreLink | Array<OchreLink>;
|
|
@@ -953,9 +956,10 @@ type OchreConcept = {
|
|
|
953
956
|
type OchrePropertyValueContent = {
|
|
954
957
|
uuid?: string;
|
|
955
958
|
publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
|
|
956
|
-
type
|
|
959
|
+
type?: string;
|
|
957
960
|
category?: string;
|
|
958
961
|
slug?: FakeString;
|
|
962
|
+
unit?: string;
|
|
959
963
|
booleanValue?: boolean;
|
|
960
964
|
content?: FakeString | OchreStringItem | Array<OchreStringItem>;
|
|
961
965
|
};
|
|
@@ -1536,7 +1540,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
|
|
|
1536
1540
|
* @returns Array of parsed Event objects
|
|
1537
1541
|
*/
|
|
1538
1542
|
declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
|
|
1539
|
-
declare function parseProperty
|
|
1543
|
+
declare function parseProperty(property: OchreProperty, language?: string): Property;
|
|
1540
1544
|
/**
|
|
1541
1545
|
* Parses raw properties into standardized Property objects
|
|
1542
1546
|
*
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,17 @@ var categorySchema = z.enum([
|
|
|
60
60
|
"set",
|
|
61
61
|
"tree"
|
|
62
62
|
]);
|
|
63
|
+
var propertyValueContentTypeSchema = z.enum([
|
|
64
|
+
"string",
|
|
65
|
+
"integer",
|
|
66
|
+
"decimal",
|
|
67
|
+
"boolean",
|
|
68
|
+
"date",
|
|
69
|
+
"dateTime",
|
|
70
|
+
"time",
|
|
71
|
+
"coordinate",
|
|
72
|
+
"IDREF"
|
|
73
|
+
]);
|
|
63
74
|
var gallerySchema = z.object({
|
|
64
75
|
uuid: z.string().uuid({ message: "Invalid UUID" }),
|
|
65
76
|
filter: z.string().optional(),
|
|
@@ -942,7 +953,7 @@ function parseEvents(events) {
|
|
|
942
953
|
}
|
|
943
954
|
return returnEvents;
|
|
944
955
|
}
|
|
945
|
-
function parseProperty(property,
|
|
956
|
+
function parseProperty(property, language = "eng") {
|
|
946
957
|
const valuesToParse = "value" in property && property.value ? Array.isArray(property.value) ? property.value : [property.value] : [];
|
|
947
958
|
const values = valuesToParse.map((value) => {
|
|
948
959
|
let content = null;
|
|
@@ -952,14 +963,15 @@ function parseProperty(property, type, language = "eng") {
|
|
|
952
963
|
const returnValue = {
|
|
953
964
|
content,
|
|
954
965
|
booleanValue,
|
|
955
|
-
type,
|
|
966
|
+
type: "string",
|
|
956
967
|
category: "value",
|
|
957
968
|
uuid: null,
|
|
958
|
-
publicationDateTime: null
|
|
969
|
+
publicationDateTime: null,
|
|
970
|
+
unit: null
|
|
959
971
|
};
|
|
960
972
|
return returnValue;
|
|
961
973
|
} else {
|
|
962
|
-
switch (type) {
|
|
974
|
+
switch (value.type) {
|
|
963
975
|
case "integer":
|
|
964
976
|
case "decimal": {
|
|
965
977
|
content = Number(value.content);
|
|
@@ -975,19 +987,32 @@ function parseProperty(property, type, language = "eng") {
|
|
|
975
987
|
} else if (value.content != null) {
|
|
976
988
|
content = parseStringContent({ content: value.content });
|
|
977
989
|
}
|
|
978
|
-
if (type === "boolean") {
|
|
990
|
+
if (value.type === "boolean") {
|
|
979
991
|
booleanValue = value.booleanValue ?? null;
|
|
980
992
|
}
|
|
981
993
|
break;
|
|
982
994
|
}
|
|
983
995
|
}
|
|
996
|
+
let parsedType = "string";
|
|
997
|
+
if (value.type != null) {
|
|
998
|
+
const { data, error } = propertyValueContentTypeSchema.safeParse(
|
|
999
|
+
value.type
|
|
1000
|
+
);
|
|
1001
|
+
if (error) {
|
|
1002
|
+
throw new Error(
|
|
1003
|
+
`Invalid property value content type: "${value.type}"`
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
parsedType = data;
|
|
1007
|
+
}
|
|
984
1008
|
const returnValue = {
|
|
985
1009
|
content,
|
|
986
1010
|
booleanValue,
|
|
987
|
-
type,
|
|
1011
|
+
type: parsedType,
|
|
988
1012
|
category: value.category ?? "value",
|
|
989
1013
|
uuid: value.uuid ?? null,
|
|
990
|
-
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null
|
|
1014
|
+
publicationDateTime: value.publicationDateTime != null ? new Date(value.publicationDateTime) : null,
|
|
1015
|
+
unit: value.unit ?? null
|
|
991
1016
|
};
|
|
992
1017
|
return returnValue;
|
|
993
1018
|
}
|
|
@@ -1004,9 +1029,7 @@ function parseProperty(property, type, language = "eng") {
|
|
|
1004
1029
|
function parseProperties(properties, language = "eng") {
|
|
1005
1030
|
const returnProperties = [];
|
|
1006
1031
|
for (const property of properties) {
|
|
1007
|
-
returnProperties.push(
|
|
1008
|
-
parseProperty(property, "string", language)
|
|
1009
|
-
);
|
|
1032
|
+
returnProperties.push(parseProperty(property, language));
|
|
1010
1033
|
}
|
|
1011
1034
|
return returnProperties;
|
|
1012
1035
|
}
|
|
@@ -1346,14 +1369,11 @@ function parseResource(resource) {
|
|
|
1346
1369
|
creators: resource.creators ? parsePersons(
|
|
1347
1370
|
Array.isArray(resource.creators.creator) ? resource.creators.creator : [resource.creators.creator]
|
|
1348
1371
|
) : [],
|
|
1349
|
-
notes: (
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
Array.isArray(resource.notes.note) ? resource.notes.note : [resource.notes.note]
|
|
1353
|
-
) : []
|
|
1354
|
-
),
|
|
1372
|
+
notes: resource.notes ? parseNotes(
|
|
1373
|
+
Array.isArray(resource.notes.note) ? resource.notes.note : [resource.notes.note]
|
|
1374
|
+
) : [],
|
|
1355
1375
|
description: resource.description ? ["string", "number", "boolean"].includes(typeof resource.description) ? parseFakeString(resource.description) : parseStringContent(resource.description) : "",
|
|
1356
|
-
document: resource.document ? parseDocument(resource.document.content) : null,
|
|
1376
|
+
document: resource.document && "content" in resource.document ? parseDocument(resource.document.content) : null,
|
|
1357
1377
|
href: resource.href ?? null,
|
|
1358
1378
|
imageMap: resource.imagemap ? parseImageMap(resource.imagemap) : null,
|
|
1359
1379
|
periods: resource.periods ? parsePeriods(
|
|
@@ -1496,7 +1516,7 @@ async function parseWebElementProperties(componentProperty, elementResource) {
|
|
|
1496
1516
|
const imageLinks = links.filter(
|
|
1497
1517
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1498
1518
|
);
|
|
1499
|
-
let document = elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1519
|
+
let document = elementResource.document && "content" in elementResource.document ? parseDocument(elementResource.document.content) : null;
|
|
1500
1520
|
if (document === null) {
|
|
1501
1521
|
const documentLink = links.find((link) => link.type === "internalDocument");
|
|
1502
1522
|
if (documentLink) {
|
|
@@ -2582,7 +2602,9 @@ async function fetchGallery(uuid, filter, page, perPage) {
|
|
|
2582
2602
|
const gallery = {
|
|
2583
2603
|
identification: galleryIdentification,
|
|
2584
2604
|
projectIdentification: galleryProjectIdentification,
|
|
2585
|
-
resources:
|
|
2605
|
+
resources: parseResources(
|
|
2606
|
+
data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? data.result.gallery.resource : [data.result.gallery.resource] : []
|
|
2607
|
+
),
|
|
2586
2608
|
maxLength: data.result.gallery.maxLength
|
|
2587
2609
|
};
|
|
2588
2610
|
return { item: gallery, error: null };
|
package/package.json
CHANGED