@digitalculture/ochre-sdk 0.17.2 → 0.17.3

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 +5 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -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,7 +3657,7 @@ 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();
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.3",
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",