@digitalculture/ochre-sdk 0.6.6 → 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 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, type, language = "eng") {
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
  }
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<T extends PropertyValueContentType> = {
350
- content: T extends "number" ? number : T extends "integer" ? number : T extends "decimal" ? number : T extends "dateTime" ? Date | null : string;
351
- booleanValue: T extends "boolean" ? boolean : null;
352
- type: T;
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<PropertyValueContentType>>;
363
+ values: Array<PropertyValueContent>;
363
364
  comment: string | null;
364
365
  properties: Array<Property>;
365
366
  };
@@ -955,9 +956,10 @@ type OchreConcept = {
955
956
  type OchrePropertyValueContent = {
956
957
  uuid?: string;
957
958
  publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
958
- type: string;
959
+ type?: string;
959
960
  category?: string;
960
961
  slug?: FakeString;
962
+ unit?: string;
961
963
  booleanValue?: boolean;
962
964
  content?: FakeString | OchreStringItem | Array<OchreStringItem>;
963
965
  };
@@ -1538,7 +1540,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
1538
1540
  * @returns Array of parsed Event objects
1539
1541
  */
1540
1542
  declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
1541
- declare function parseProperty<T extends PropertyValueContentType>(property: OchreProperty, type: T, language?: string): Property;
1543
+ declare function parseProperty(property: OchreProperty, language?: string): Property;
1542
1544
  /**
1543
1545
  * Parses raw properties into standardized Property objects
1544
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<T extends PropertyValueContentType> = {
350
- content: T extends "number" ? number : T extends "integer" ? number : T extends "decimal" ? number : T extends "dateTime" ? Date | null : string;
351
- booleanValue: T extends "boolean" ? boolean : null;
352
- type: T;
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<PropertyValueContentType>>;
363
+ values: Array<PropertyValueContent>;
363
364
  comment: string | null;
364
365
  properties: Array<Property>;
365
366
  };
@@ -955,9 +956,10 @@ type OchreConcept = {
955
956
  type OchrePropertyValueContent = {
956
957
  uuid?: string;
957
958
  publicationDateTime?: string; // YYYY-MM-DDThh:mm:ssZ
958
- type: string;
959
+ type?: string;
959
960
  category?: string;
960
961
  slug?: FakeString;
962
+ unit?: string;
961
963
  booleanValue?: boolean;
962
964
  content?: FakeString | OchreStringItem | Array<OchreStringItem>;
963
965
  };
@@ -1538,7 +1540,7 @@ declare function parseObservations(observations: Array<OchreObservation>): Array
1538
1540
  * @returns Array of parsed Event objects
1539
1541
  */
1540
1542
  declare function parseEvents(events: Array<OchreEvent>): Array<Event>;
1541
- declare function parseProperty<T extends PropertyValueContentType>(property: OchreProperty, type: T, language?: string): Property;
1543
+ declare function parseProperty(property: OchreProperty, language?: string): Property;
1542
1544
  /**
1543
1545
  * Parses raw properties into standardized Property objects
1544
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, type, language = "eng") {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.6.6",
3
+ "version": "0.7.0",
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",