@digitalculture/ochre-sdk 0.14.7 → 0.14.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
@@ -162,7 +162,7 @@ type Link = {
162
162
  type ImageMapArea = {
163
163
  uuid: string;
164
164
  publicationDateTime: Date | null;
165
- type: string;
165
+ category: string;
166
166
  title: string;
167
167
  shape: "rectangle" | "circle" | "polygon";
168
168
  coords: Array<number>;
@@ -247,17 +247,25 @@ type Observation = {
247
247
  * Represents an event with date, label and optional agent
248
248
  */
249
249
  type Event = {
250
- date: Date | null;
250
+ dateTime: Date | null;
251
+ date: string | null;
251
252
  label: string;
252
253
  agent: {
253
254
  uuid: string;
255
+ publicationDateTime: Date | null;
254
256
  content: string;
255
257
  } | null;
256
258
  location: {
257
259
  uuid: string;
260
+ publicationDateTime: Date | null;
258
261
  content: string;
259
262
  } | null;
260
263
  comment: string | null;
264
+ other: {
265
+ uuid: string | null;
266
+ category: string | null;
267
+ content: string;
268
+ } | null;
261
269
  value: string | null;
262
270
  };
263
271
  /**
@@ -816,6 +824,8 @@ type WebElementComponent = {
816
824
  component: "map";
817
825
  mapId: string;
818
826
  customBasemap: string | null;
827
+ initialBounds: [[number, number], [number, number]] | null;
828
+ maximumBounds: [[number, number], [number, number]] | null;
819
829
  isControlsDisplayed: boolean;
820
830
  isInteractive: boolean;
821
831
  isClustered: boolean;
package/dist/index.mjs CHANGED
@@ -151,6 +151,32 @@ const whitespaceSchema = z.string().transform((str) => str.split(" ")).pipe(z.ar
151
151
  * @internal
152
152
  */
153
153
  const emailSchema = z.email({ error: "Invalid email" });
154
+ /**
155
+ * Schema for parsing and validating a string in the format "[[number, number], [number, number]]"
156
+ * into an array with exactly two bounds
157
+ * @internal
158
+ */
159
+ const boundsSchema = z.string().transform((str, ctx) => {
160
+ const trimmed = str.trim();
161
+ if (!trimmed.startsWith("[[") || !trimmed.endsWith("]]")) {
162
+ ctx.addIssue({
163
+ code: "invalid_format",
164
+ format: "string",
165
+ message: "String must start with '[[' and end with ']]'"
166
+ });
167
+ return z.NEVER;
168
+ }
169
+ try {
170
+ return JSON.parse(trimmed);
171
+ } catch {
172
+ ctx.addIssue({
173
+ code: "invalid_format",
174
+ format: "string",
175
+ message: "Invalid JSON format"
176
+ });
177
+ return z.NEVER;
178
+ }
179
+ }).pipe(z.tuple([z.tuple([z.number(), z.number()]), z.tuple([z.number(), z.number()])], { message: "Must contain exactly 2 coordinate pairs" }));
154
180
 
155
181
  //#endregion
156
182
  //#region src/utils/getters.ts
@@ -1148,17 +1174,25 @@ function parseObservations(observations) {
1148
1174
  function parseEvents(events) {
1149
1175
  const returnEvents = [];
1150
1176
  for (const event of events) returnEvents.push({
1151
- date: event.dateTime != null ? new Date(event.dateTime) : null,
1177
+ dateTime: event.dateTime != null ? new Date(event.dateTime) : null,
1178
+ date: event.partialDates?.year != null ? `${event.partialDates.year}-01-01/${event.partialDates.endYear ?? event.partialDates.year}-12-31` : null,
1152
1179
  label: parseStringContent(event.label),
1153
1180
  location: event.location ? {
1154
1181
  uuid: event.location.uuid,
1182
+ publicationDateTime: event.location.publicationDateTime != null ? new Date(event.location.publicationDateTime) : null,
1155
1183
  content: parseStringContent(event.location)
1156
1184
  } : null,
1157
1185
  agent: event.agent ? {
1158
1186
  uuid: event.agent.uuid,
1187
+ publicationDateTime: event.agent.publicationDateTime != null ? new Date(event.agent.publicationDateTime) : null,
1159
1188
  content: parseStringContent(event.agent)
1160
1189
  } : null,
1161
1190
  comment: event.comment ? parseStringContent(event.comment) : null,
1191
+ other: event.other != null ? {
1192
+ uuid: event.other.uuid ?? null,
1193
+ category: event.other.category ?? null,
1194
+ content: parseStringContent(event.other)
1195
+ } : null,
1162
1196
  value: event.value ? parseFakeString(event.value) : null
1163
1197
  });
1164
1198
  return returnEvents;
@@ -1295,7 +1329,7 @@ function parseImageMap(imageMap) {
1295
1329
  for (const area of imageMapAreasToParse) returnImageMap.area.push({
1296
1330
  uuid: area.uuid,
1297
1331
  publicationDateTime: area.publicationDateTime != null ? new Date(area.publicationDateTime) : null,
1298
- type: area.type,
1332
+ category: area.type,
1299
1333
  title: parseFakeString(area.title),
1300
1334
  shape: area.shape === "rect" ? "rectangle" : area.shape === "circle" ? "circle" : "polygon",
1301
1335
  coords: area.coords.split(",").map((coord) => Number.parseInt(coord)),
@@ -1822,6 +1856,11 @@ function parseConcepts(concepts) {
1822
1856
  for (const concept of conceptsToParse) returnConcepts.push(parseConcept(concept));
1823
1857
  return returnConcepts;
1824
1858
  }
1859
+ function parseBounds(bounds) {
1860
+ const result = boundsSchema.safeParse(bounds);
1861
+ if (!result.success) throw new Error(`Invalid bounds: ${result.error.message}`);
1862
+ return result.data;
1863
+ }
1825
1864
  /**
1826
1865
  * Parses raw web element properties into a standardized WebElementComponent structure
1827
1866
  *
@@ -2193,6 +2232,12 @@ function parseWebElementProperties(componentProperty, elementResource) {
2193
2232
  let customBasemap = null;
2194
2233
  const customBasemapProperty = getPropertyValueByLabel(componentProperty.properties, "custom-basemap");
2195
2234
  if (customBasemapProperty !== null) customBasemap = customBasemapProperty;
2235
+ let initialBounds = null;
2236
+ const initialBoundsProperty = getPropertyValueByLabel(componentProperty.properties, "initial-bounds");
2237
+ if (initialBoundsProperty !== null) initialBounds = parseBounds(String(initialBoundsProperty));
2238
+ let maximumBounds = null;
2239
+ const maximumBoundsProperty = getPropertyValueByLabel(componentProperty.properties, "maximum-bounds");
2240
+ if (maximumBoundsProperty !== null) maximumBounds = parseBounds(String(maximumBoundsProperty));
2196
2241
  let isControlsDisplayed = false;
2197
2242
  const isControlsDisplayedProperty = getPropertyValueByLabel(componentProperty.properties, "controls-displayed");
2198
2243
  if (isControlsDisplayedProperty !== null) isControlsDisplayed = isControlsDisplayedProperty === true;
@@ -2200,10 +2245,12 @@ function parseWebElementProperties(componentProperty, elementResource) {
2200
2245
  const isFullHeightProperty = getPropertyValueByLabel(componentProperty.properties, "is-full-height");
2201
2246
  if (isFullHeightProperty !== null) isFullHeight = isFullHeightProperty === true;
2202
2247
  properties.mapId = mapLink.uuid;
2248
+ properties.customBasemap = customBasemap;
2249
+ properties.initialBounds = initialBounds;
2250
+ properties.maximumBounds = maximumBounds;
2203
2251
  properties.isInteractive = isInteractive;
2204
2252
  properties.isClustered = isClustered;
2205
2253
  properties.isUsingPins = isUsingPins;
2206
- properties.customBasemap = customBasemap;
2207
2254
  properties.isControlsDisplayed = isControlsDisplayed;
2208
2255
  properties.isFullHeight = isFullHeight;
2209
2256
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.14.7",
3
+ "version": "0.14.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",