@digitalculture/ochre-sdk 0.17.2 → 0.17.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +7 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -3606,7 +3606,7 @@ const responseItemSchema = z.object({
3606
3606
  /**
3607
3607
  * Schema for the OCHRE API response
3608
3608
  */
3609
- const responseSchema = z.object({ result: z.object({ item: z.union([responseItemSchema, z.array(responseItemSchema)]) }) });
3609
+ const responseSchema = z.object({ result: z.object({ ochre: z.object({ item: z.union([responseItemSchema, z.array(responseItemSchema)]) }) }) });
3610
3610
  /**
3611
3611
  * Build an XQuery string to fetch property query items from the OCHRE API
3612
3612
  * @param scopeUuids - An array of scope UUIDs to filter by
@@ -3614,16 +3614,17 @@ const responseSchema = z.object({ result: z.object({ item: z.union([responseItem
3614
3614
  * @param projectScopeUuid - The UUID of the project scope
3615
3615
  * @returns An XQuery string
3616
3616
  */
3617
- function buildXQuery(scopeUuids, propertyUuids, projectScopeUuid) {
3617
+ function buildXQuery(scopeUuids, propertyUuids, projectScopeUuid, options) {
3618
+ const version = options?.version ?? DEFAULT_API_VERSION;
3618
3619
  let collectionScopeFilter = "";
3619
3620
  if (scopeUuids.length > 0) collectionScopeFilter = `[properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${scopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]]`;
3620
3621
  const propertyFilters = propertyUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3621
- return `for $q in input()/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${collectionScopeFilter}/properties//property[label[${propertyFilters}]]
3622
+ return `<ochre>{${`for $q in ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${collectionScopeFilter}/properties//property[label[${propertyFilters}]]
3622
3623
  return <item>
3623
3624
  <property>{xs:string($q/label/@uuid)}</property>
3624
3625
  <value> {$q/*[2]/@*} {$q/*[2]/content[1]/string/text()} </value>
3625
3626
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
3626
- </item>`;
3627
+ </item>`}}</ochre>`;
3627
3628
  }
3628
3629
  /**
3629
3630
  * Fetches and parses a property query from the OCHRE API
@@ -3656,12 +3657,12 @@ async function fetchPropertyQuery(params, options) {
3656
3657
  const customFetch = options?.customFetch;
3657
3658
  const version = options?.version ?? DEFAULT_API_VERSION;
3658
3659
  const { scopeUuids, propertyUuids, projectScopeUuid } = params;
3659
- const xquery = buildXQuery(scopeUuids, propertyUuids, projectScopeUuid);
3660
+ const xquery = buildXQuery(scopeUuids, propertyUuids, projectScopeUuid, { version });
3660
3661
  const response = await (customFetch ?? fetch)(version === 2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"`);
3661
3662
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
3662
3663
  const data = await response.json();
3663
3664
  const parsedResultRaw = responseSchema.parse(data);
3664
- const parsedItems = Array.isArray(parsedResultRaw.result.item) ? parsedResultRaw.result.item : [parsedResultRaw.result.item];
3665
+ const parsedItems = Array.isArray(parsedResultRaw.result.ochre.item) ? parsedResultRaw.result.ochre.item : [parsedResultRaw.result.ochre.item];
3665
3666
  const items = {};
3666
3667
  for (const item of parsedItems) {
3667
3668
  const categoryUuid = item.category.uuid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
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",