@digitalculture/ochre-sdk 0.9.2 → 0.9.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.
package/dist/index.cjs CHANGED
@@ -13,4 +13,4 @@ return <item>
13
13
  <property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
14
14
  <value>{$q/*[2]/@uuid} {$q/*[2]/content[1]/string/text()}</value>
15
15
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
16
- </item>`;return i}async function Ve(e,t,n){try{let r=Be(e,t.map(e=>e.uuid)),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=ze.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Le,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Le).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function He(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${n}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!r.ok)throw Error(`Failed to fetch metadata`);let i=await r.json(),a=L(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:L(i.result.item.identification).label,type:i.result.item.type},project:{name:o.label,website:o.website??null}};return{item:s,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Ue(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?L(r.result.ochre.metadata.project.identification):null,a=await je(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}exports.fetchByUuidMetadata=He,exports.fetchGallery=Me,exports.fetchItem=Pe,exports.fetchPropertyQuery=Ve,exports.fetchWebsite=Ue,exports.filterProperties=D,exports.getPropertyByLabel=S,exports.getPropertyByUuid=y,exports.getPropertyValueByLabel=w,exports.getPropertyValueByUuid=x,exports.getPropertyValuesByLabel=C,exports.getPropertyValuesByUuid=b,exports.getUniqueProperties=T,exports.getUniquePropertyLabels=E;
16
+ </item>`;return i}async function Ve(e,t,n){try{let r=Be(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=ze.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Le,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Le).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function He(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${n}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!r.ok)throw Error(`Failed to fetch metadata`);let i=await r.json(),a=L(i.result.project.identification),o={...a,website:i.result.project.identification.website??null},s={item:{uuid:e,name:L(i.result.item.identification).label,type:i.result.item.type},project:{name:o.label,website:o.website??null}};return{item:s,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Ue(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?L(r.result.ochre.metadata.project.identification):null,a=await je(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}exports.fetchByUuidMetadata=He,exports.fetchGallery=Me,exports.fetchItem=Pe,exports.fetchPropertyQuery=Ve,exports.fetchWebsite=Ue,exports.filterProperties=D,exports.getPropertyByLabel=S,exports.getPropertyByUuid=y,exports.getPropertyValueByLabel=w,exports.getPropertyValueByUuid=x,exports.getPropertyValuesByLabel=C,exports.getPropertyValuesByUuid=b,exports.getUniqueProperties=T,exports.getUniquePropertyLabels=E;
package/dist/index.d.cts CHANGED
@@ -862,13 +862,13 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
862
862
  * Fetches and parses a property query from the OCHRE API
863
863
  *
864
864
  * @param scopeUuids - The scope UUIDs to filter by
865
- * @param propertyUuids - The property UUIDs to fetch
865
+ * @param propertyUuids - The property UUIDs to query by
866
866
  * @param customFetch - A custom fetch function to use instead of the default fetch
867
867
  * @returns The parsed property query or null if the fetch/parse fails
868
868
  *
869
869
  * @example
870
870
  * ```ts
871
- * const propertyQuery = await fetchPropertyQuery([{ uuid: "0c0aae37-7246-495b-9547-e25dbf5b99a3" }], [{ uuid: "9c4da06b-f15e-40af-a747-0933eaf3587e", type: "string", identification: { label: "1978" } }]);
871
+ * const propertyQuery = await fetchPropertyQuery(["0c0aae37-7246-495b-9547-e25dbf5b99a3"], ["9c4da06b-f15e-40af-a747-0933eaf3587e"]);
872
872
  * if (propertyQuery === null) {
873
873
  * console.error("Failed to fetch property query");
874
874
  * return;
@@ -880,11 +880,7 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
880
880
  * The returned property query includes:
881
881
  * - Property items
882
882
  */
883
- declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<{
884
- uuid: string;
885
- type: string;
886
- identification: Identification;
887
- }>, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
883
+ declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<string>, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
888
884
  items: Array<PropertyQueryItem> | null;
889
885
  error: null;
890
886
  } | {
package/dist/index.d.ts CHANGED
@@ -862,13 +862,13 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
862
862
  * Fetches and parses a property query from the OCHRE API
863
863
  *
864
864
  * @param scopeUuids - The scope UUIDs to filter by
865
- * @param propertyUuids - The property UUIDs to fetch
865
+ * @param propertyUuids - The property UUIDs to query by
866
866
  * @param customFetch - A custom fetch function to use instead of the default fetch
867
867
  * @returns The parsed property query or null if the fetch/parse fails
868
868
  *
869
869
  * @example
870
870
  * ```ts
871
- * const propertyQuery = await fetchPropertyQuery([{ uuid: "0c0aae37-7246-495b-9547-e25dbf5b99a3" }], [{ uuid: "9c4da06b-f15e-40af-a747-0933eaf3587e", type: "string", identification: { label: "1978" } }]);
871
+ * const propertyQuery = await fetchPropertyQuery(["0c0aae37-7246-495b-9547-e25dbf5b99a3"], ["9c4da06b-f15e-40af-a747-0933eaf3587e"]);
872
872
  * if (propertyQuery === null) {
873
873
  * console.error("Failed to fetch property query");
874
874
  * return;
@@ -880,11 +880,7 @@ declare function fetchItem<T extends DataCategory, U extends DataCategory>(uuid:
880
880
  * The returned property query includes:
881
881
  * - Property items
882
882
  */
883
- declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<{
884
- uuid: string;
885
- type: string;
886
- identification: Identification;
887
- }>, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
883
+ declare function fetchPropertyQuery(scopeUuids: Array<string>, propertyUuids: Array<string>, customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>): Promise<{
888
884
  items: Array<PropertyQueryItem> | null;
889
885
  error: null;
890
886
  } | {
package/dist/index.js CHANGED
@@ -13,4 +13,4 @@ return <item>
13
13
  <property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
14
14
  <value>{$q/*[2]/@uuid} {$q/*[2]/content[1]/string/text()}</value>
15
15
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
16
- </item>`;return i}async function Ne(e,t,n){try{let r=Me(e,t.map(e=>e.uuid)),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=je.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Ae,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Ae).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function Pe(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${r}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!i.ok)throw Error(`Failed to fetch metadata`);let a=await i.json(),o=M(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:M(a.result.item.identification).label,type:a.result.item.type},project:{name:s.label,website:s.website??null}};return{item:c,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Fe(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?M(r.result.ochre.metadata.project.identification):null,a=await we(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}export{Pe as fetchByUuidMetadata,Te as fetchGallery,De as fetchItem,Ne as fetchPropertyQuery,Fe as fetchWebsite,y as filterProperties,m as getPropertyByLabel,d as getPropertyByUuid,g as getPropertyValueByLabel,p as getPropertyValueByUuid,h as getPropertyValuesByLabel,f as getPropertyValuesByUuid,_ as getUniqueProperties,v as getUniquePropertyLabels};
16
+ </item>`;return i}async function Ne(e,t,n){try{let r=Me(e,t),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(r)}&format=json`);if(!i.ok)throw Error(`OCHRE API responded with status: ${i.status}`);let a=await i.json(),o=je.parse(a),s=Array.isArray(o.result.item)?o.result.item:[o.result.item],c={};for(let e of s){let t=e.category.uuid,n=e.value.uuid,r=e.value.content??e.value.rawValue??``;r in c?c[r].resultUuids.push(t):c[r]={value:{uuid:n??Ae,category:e.value.category??null,type:e.value.type??null,dataType:e.value.dataType,publicationDateTime:e.value.publicationDateTime??null,content:e.value.content??e.value.rawValue??``,label:e.value.rawValue!=null&&e.value.content!=null?e.value.content:null},resultUuids:[t]}}let l=Object.values(c).filter(e=>e.value.uuid!==Ae).toSorted((e,t)=>{let n=e.value.label??e.value.content,r=t.value.label??t.value.content;return n.localeCompare(r,`en-US`)});return{items:l,error:null}}catch(e){return console.error(e),{items:null,error:e instanceof Error?e.message:`Failed to fetch property query`}}}async function Pe(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[@uuid='${r}']/metadata return ($q/item, $q/project)`)}&format=json`);if(!i.ok)throw Error(`Failed to fetch metadata`);let a=await i.json(),o=M(a.result.project.identification),s={...o,website:a.result.project.identification.website??null},c={item:{uuid:e,name:M(a.result.item.identification).label,type:a.result.item.type},project:{name:s.label,website:s.website??null}};return{item:c,error:null}}catch(e){return{item:null,error:e instanceof Error?e.message:`Unknown error`}}}async function Fe(e,t){try{let n=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?xquery=for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${e.toLocaleLowerCase(`en-US`)}']] return $q&format=json`);if(!n.ok)throw Error(`Failed to fetch website`);let r=await n.json();if(!(`ochre`in r.result)||!(`tree`in r.result.ochre))throw Error(`Failed to fetch website`);let i=r.result.ochre.metadata.project?.identification?M(r.result.ochre.metadata.project.identification):null,a=await we(r.result.ochre.tree,i?.label??``,r.result.ochre.metadata.project?.identification.website??null);return[null,a]}catch(e){return console.error(e),[e instanceof Error?e.message:`Unknown error`,null]}}export{Pe as fetchByUuidMetadata,Te as fetchGallery,De as fetchItem,Ne as fetchPropertyQuery,Fe as fetchWebsite,y as filterProperties,m as getPropertyByLabel,d as getPropertyByUuid,g as getPropertyValueByLabel,p as getPropertyValueByUuid,h as getPropertyValuesByLabel,f as getPropertyValuesByUuid,_ as getUniqueProperties,v as getUniquePropertyLabels};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.9.2",
3
+ "version": "0.9.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",