ochre-sdk 0.19.6 → 0.19.8

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
@@ -1079,23 +1079,29 @@ type WebBlock<T extends WebBlockLayout = WebBlockLayout> = {
1079
1079
  /**
1080
1080
  * Fetches and parses a gallery from the OCHRE API
1081
1081
  *
1082
- * @param uuid - The UUID of the gallery
1083
- * @param filter - The filter to apply to the gallery
1084
- * @param page - The page number to fetch
1085
- * @param pageSize - The number of items per page
1082
+ * @param params - The parameters for the fetch
1083
+ * @param params.uuid - The UUID of the gallery
1084
+ * @param params.filter - The filter to apply to the gallery
1085
+ * @param params.page - The page number to fetch
1086
+ * @param params.pageSize - The number of items per page
1086
1087
  * @param options - The options for the fetch
1087
1088
  * @param options.fetch - The fetch function to use
1088
1089
  * @param options.version - The version of the OCHRE API to use
1089
1090
  * @returns The parsed gallery or an error message if the fetch/parse fails
1090
1091
  */
1091
- declare function fetchGallery(uuid: string, filter: string, page: number, pageSize: number, options?: {
1092
+ declare function fetchGallery(params: {
1093
+ uuid: string;
1094
+ filter?: string;
1095
+ page: number;
1096
+ pageSize: number;
1097
+ }, options?: {
1092
1098
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1093
1099
  version?: ApiVersion;
1094
1100
  }): Promise<{
1095
- item: Gallery | null;
1101
+ gallery: Gallery | null;
1096
1102
  error: null;
1097
1103
  } | {
1098
- item: null;
1104
+ gallery: null;
1099
1105
  error: string;
1100
1106
  }>;
1101
1107
  //#endregion
@@ -1208,7 +1214,13 @@ declare function fetchPropertyValuesByPropertyVariables(params: {
1208
1214
  declare function fetchWebsite(abbreviation: string, options?: {
1209
1215
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1210
1216
  version?: ApiVersion;
1211
- }): Promise<[null, Website] | [string, null]>;
1217
+ }): Promise<{
1218
+ error: null;
1219
+ website: Website;
1220
+ } | {
1221
+ error: string;
1222
+ website: null;
1223
+ }>;
1212
1224
  //#endregion
1213
1225
  //#region src/utils/getters.d.ts
1214
1226
  /**
package/dist/index.mjs CHANGED
@@ -662,16 +662,6 @@ const propertyValueContentTypeSchema = z.enum([
662
662
  "IDREF"
663
663
  ]);
664
664
  /**
665
- * Schema for validating gallery parameters
666
- * @internal
667
- */
668
- const gallerySchema = z.object({
669
- uuid: z.string().refine(isPseudoUuid, { error: "Invalid UUID" }),
670
- filter: z.string().optional(),
671
- page: z.number().positive({ error: "Page must be positive" }),
672
- pageSize: z.number().positive({ error: "Page size must be positive" })
673
- }).strict();
674
- /**
675
665
  * Schema for validating and parsing render options
676
666
  * @internal
677
667
  */
@@ -721,6 +711,40 @@ const boundsSchema = z.string().transform((str, ctx) => {
721
711
  }
722
712
  }).pipe(z.tuple([z.tuple([z.number(), z.number()]), z.tuple([z.number(), z.number()])], { message: "Must contain exactly 2 coordinate pairs" }));
723
713
 
714
+ //#endregion
715
+ //#region src/utils/helpers.ts
716
+ /**
717
+ * The default API version to use
718
+ *
719
+ * @remarks
720
+ * Version 1 of the OCHRE API is deprecated and will be removed in the future.
721
+ * It points to the old Tamino server.
722
+ *
723
+ * Version 2 of the OCHRE API is the current version and is the default.
724
+ * It points to the new MarkLogic server.
725
+ */
726
+ const DEFAULT_API_VERSION = 2;
727
+ /**
728
+ * The default page size to use for fetching paginated items
729
+ */
730
+ const DEFAULT_PAGE_SIZE = 48;
731
+ /**
732
+ * Flatten the properties of an item
733
+ * @param item - The item whose properties to flatten
734
+ * @returns The item with the properties flattened
735
+ */
736
+ function flattenItemProperties(item) {
737
+ const allProperties = [];
738
+ if ("properties" in item) allProperties.push(...item.properties);
739
+ if ("observations" in item) for (const observation of item.observations) allProperties.push(...observation.properties);
740
+ if ("interpretations" in item) for (const interpretation of item.interpretations) allProperties.push(...interpretation.properties);
741
+ if ("bibliographies" in item) for (const bibliography of item.bibliographies) allProperties.push(...bibliography.properties);
742
+ return {
743
+ ...item,
744
+ properties: flattenProperties(allProperties)
745
+ };
746
+ }
747
+
724
748
  //#endregion
725
749
  //#region src/utils/parse/index.ts
726
750
  /**
@@ -1795,90 +1819,62 @@ function parseConcepts(concepts) {
1795
1819
  //#endregion
1796
1820
  //#region src/utils/fetchers/gallery.ts
1797
1821
  /**
1822
+ * Schema for validating gallery parameters
1823
+ */
1824
+ const galleryParamsSchema = z.object({
1825
+ uuid: uuidSchema,
1826
+ filter: z.string().optional(),
1827
+ page: z.number().positive({ error: "Page must be positive" }),
1828
+ pageSize: z.number().positive({ error: "Page size must be positive" })
1829
+ });
1830
+ /**
1798
1831
  * Fetches and parses a gallery from the OCHRE API
1799
1832
  *
1800
- * @param uuid - The UUID of the gallery
1801
- * @param filter - The filter to apply to the gallery
1802
- * @param page - The page number to fetch
1803
- * @param pageSize - The number of items per page
1833
+ * @param params - The parameters for the fetch
1834
+ * @param params.uuid - The UUID of the gallery
1835
+ * @param params.filter - The filter to apply to the gallery
1836
+ * @param params.page - The page number to fetch
1837
+ * @param params.pageSize - The number of items per page
1804
1838
  * @param options - The options for the fetch
1805
1839
  * @param options.fetch - The fetch function to use
1806
1840
  * @param options.version - The version of the OCHRE API to use
1807
1841
  * @returns The parsed gallery or an error message if the fetch/parse fails
1808
1842
  */
1809
- async function fetchGallery(uuid, filter, page, pageSize, options) {
1843
+ async function fetchGallery(params, options) {
1810
1844
  try {
1811
- const { uuid: parsedUuid, filter: parsedFilter, page: parsedPage, pageSize: parsedPageSize } = gallerySchema.parse({
1812
- uuid,
1813
- filter,
1814
- page,
1815
- pageSize
1816
- });
1817
- const response = await (options?.fetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`
1818
- for $q in input()/ochre[@uuid='${parsedUuid}']
1819
- let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${parsedFilter}'))]
1845
+ const version = options?.version ?? DEFAULT_API_VERSION;
1846
+ const { uuid, filter, page, pageSize } = galleryParamsSchema.parse(params);
1847
+ const response = await (options?.fetch ?? fetch)(`${version === 2 ? "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php" : "https://ochre.lib.uchicago.edu/ochre"}?xquery=${encodeURIComponent(`<ochre>{
1848
+ for $q in ${version === 2 ? "doc()" : "input()"}/ochre[@uuid='${uuid}']
1849
+ let $filtered := $q//items/resource[contains(lower-case(identification/label), lower-case('${filter}'))]
1820
1850
  let $maxLength := count($filtered)
1821
1851
  return <gallery maxLength='{$maxLength}'>
1822
1852
  {$q/metadata/project}
1823
1853
  {$q/metadata/item}
1824
- {$filtered[position() >= ${((parsedPage - 1) * parsedPageSize + 1).toString()} and position() < ${(parsedPage * parsedPageSize + 1).toString()}]}
1854
+ {$filtered[position() >= ${((page - 1) * pageSize + 1).toString()} and position() < ${(page * pageSize + 1).toString()}]}
1825
1855
  </gallery>
1826
- `)}&format=json`);
1856
+ }</ochre>`)}&format=json`);
1827
1857
  if (!response.ok) throw new Error("Error fetching gallery items, please try again later.");
1828
1858
  const data = await response.json();
1829
- if (!("gallery" in data.result)) throw new Error("Failed to fetch gallery");
1859
+ if (!("gallery" in data.result.ochre)) throw new Error("Failed to fetch gallery");
1830
1860
  return {
1831
- item: {
1832
- identification: parseIdentification(data.result.gallery.item.identification),
1833
- projectIdentification: parseIdentification(data.result.gallery.project.identification),
1834
- resources: parseResources(data.result.gallery.resource ? Array.isArray(data.result.gallery.resource) ? data.result.gallery.resource : [data.result.gallery.resource] : []),
1835
- maxLength: data.result.gallery.maxLength
1861
+ gallery: {
1862
+ identification: parseIdentification(data.result.ochre.gallery.item.identification),
1863
+ projectIdentification: parseIdentification(data.result.ochre.gallery.project.identification),
1864
+ resources: data.result.ochre.gallery.resource ? parseResources(Array.isArray(data.result.ochre.gallery.resource) ? data.result.ochre.gallery.resource : [data.result.ochre.gallery.resource]) : [],
1865
+ maxLength: data.result.ochre.gallery.maxLength
1836
1866
  },
1837
1867
  error: null
1838
1868
  };
1839
1869
  } catch (error) {
1840
1870
  console.error(error);
1841
1871
  return {
1842
- item: null,
1872
+ gallery: null,
1843
1873
  error: error instanceof Error ? error.message : "Failed to fetch gallery"
1844
1874
  };
1845
1875
  }
1846
1876
  }
1847
1877
 
1848
- //#endregion
1849
- //#region src/utils/helpers.ts
1850
- /**
1851
- * The default API version to use
1852
- *
1853
- * @remarks
1854
- * Version 1 of the OCHRE API is deprecated and will be removed in the future.
1855
- * It points to the old Tamino server.
1856
- *
1857
- * Version 2 of the OCHRE API is the current version and is the default.
1858
- * It points to the new MarkLogic server.
1859
- */
1860
- const DEFAULT_API_VERSION = 2;
1861
- /**
1862
- * The default page size to use for fetching paginated items
1863
- */
1864
- const DEFAULT_PAGE_SIZE = 48;
1865
- /**
1866
- * Flatten the properties of an item
1867
- * @param item - The item whose properties to flatten
1868
- * @returns The item with the properties flattened
1869
- */
1870
- function flattenItemProperties(item) {
1871
- const allProperties = [];
1872
- if ("properties" in item) allProperties.push(...item.properties);
1873
- if ("observations" in item) for (const observation of item.observations) allProperties.push(...observation.properties);
1874
- if ("interpretations" in item) for (const interpretation of item.interpretations) allProperties.push(...interpretation.properties);
1875
- if ("bibliographies" in item) for (const bibliography of item.bibliographies) allProperties.push(...bibliography.properties);
1876
- return {
1877
- ...item,
1878
- properties: flattenProperties(allProperties)
1879
- };
1880
- }
1881
-
1882
1878
  //#endregion
1883
1879
  //#region src/utils/fetchers/uuid.ts
1884
1880
  /**
@@ -3697,6 +3693,8 @@ function parseWebsiteProperties(properties, websiteTree, sidebar) {
3697
3693
  returnProperties.theme.isThemeToggleDisplayed = getPropertyValueByLabel(websiteProperties, "supports-theme-toggle") ?? true;
3698
3694
  returnProperties.theme.defaultTheme = getPropertyValueByLabel(websiteProperties, "default-theme") ?? "system";
3699
3695
  returnProperties.icon.logoUuid = getPropertyByLabel(websiteProperties, "logo")?.values[0]?.uuid ?? null;
3696
+ returnProperties.icon.faviconUuid = getPropertyByLabel(websiteProperties, "favicon-ico")?.values[0]?.uuid ?? null;
3697
+ returnProperties.icon.appleTouchIconUuid = getPropertyByLabel(websiteProperties, "favicon-img")?.values[0]?.uuid ?? null;
3700
3698
  returnProperties.navbar.isDisplayed = getPropertyValueByLabel(websiteProperties, "navbar-displayed") ?? true;
3701
3699
  returnProperties.navbar.variant = getPropertyValueByLabel(websiteProperties, "navbar-variant") ?? "default";
3702
3700
  returnProperties.navbar.alignment = getPropertyValueByLabel(websiteProperties, "navbar-alignment") ?? "start";
@@ -3841,10 +3839,16 @@ async function fetchWebsite(abbreviation, options) {
3841
3839
  abbreviation: parseFakeString(result.ochre.belongsTo)
3842
3840
  };
3843
3841
  }
3844
- return [null, parseWebsite(tree, metadata, belongsTo, { version })];
3842
+ return {
3843
+ error: null,
3844
+ website: parseWebsite(tree, metadata, belongsTo, { version })
3845
+ };
3845
3846
  } catch (error) {
3846
3847
  console.error(error);
3847
- return [error instanceof Error ? error.message : "Unknown error", null];
3848
+ return {
3849
+ error: error instanceof Error ? error.message : "Unknown error",
3850
+ website: null
3851
+ };
3848
3852
  }
3849
3853
  }
3850
3854
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.19.6",
3
+ "version": "0.19.8",
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",
@@ -46,7 +46,7 @@
46
46
  "zod": "^4.3.6"
47
47
  },
48
48
  "devDependencies": {
49
- "@antfu/eslint-config": "^7.4.2",
49
+ "@antfu/eslint-config": "^7.4.3",
50
50
  "@types/node": "^24.10.13",
51
51
  "bumpp": "^10.4.1",
52
52
  "eslint": "^10.0.0",
@@ -60,6 +60,8 @@
60
60
  "build": "tsdown",
61
61
  "lint": "eslint --cache .",
62
62
  "lint:fix": "eslint --cache . --fix",
63
+ "lint:nocache": "eslint .",
64
+ "lint:nocache:fix": "eslint . --fix",
63
65
  "format": "prettier --cache --check .",
64
66
  "format:fix": "prettier --cache --write --list-different .",
65
67
  "check-types": "tsc --noEmit",