@digitalculture/ochre-sdk 0.9.3 → 0.9.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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,6 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
11
11
|
`)}&format=json`);if(!l.ok)throw Error(`Error fetching gallery items, please try again later.`);let u=await l.json();if(!(`gallery`in u.result))throw Error(`Failed to fetch gallery`);let d=L(u.result.gallery.item.identification),f=L(u.result.gallery.project.identification),p={identification:d,projectIdentification:f,resources:Y(u.result.gallery.resource?Array.isArray(u.result.gallery.resource)?u.result.gallery.resource:[u.result.gallery.resource]:[]),maxLength:u.result.gallery.maxLength};return{item:p,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Ne(e,t){try{let n=l.parse(e),r=await(t??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${n}&format=json&lang="*"`);if(!r.ok)throw Error(`Failed to fetch OCHRE data`);let i=await r.json();if(!(`ochre`in i))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,i]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function Pe(e,t,n,r){try{let[i,a]=await Ne(e,r);if(i!==null)throw Error(i);let o=I(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=be(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=xe(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=Ce(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=me(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=he(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ae(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=ge(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=ye(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=ve(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=ie(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:M(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const Fe=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,Ie=`30054cb2-909a-4f34-8db9-8fe7369d691d`,Le=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function $(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const Re=c.z.object({property:c.z.string().refine($),category:c.z.object({uuid:c.z.string().refine($),content:c.z.string()}),value:c.z.object({uuid:c.z.string().refine($).optional(),category:c.z.string().optional(),type:c.z.string().optional(),dataType:c.z.string(),publicationDateTime:c.z.iso.datetime().optional(),content:c.z.string().optional(),rawValue:c.z.string().optional()})}),ze=c.z.object({result:c.z.object({item:c.z.union([Re,c.z.array(Re)])})});function Be(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${Ie}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${Fe}"]/*${n}/properties//property[label[${r}]]
|
|
12
12
|
return <item>
|
|
13
13
|
<property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
|
|
14
|
-
<value>{$q/*[2]
|
|
14
|
+
<value>{$q/*[2]/@*} {$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
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.js
CHANGED
|
@@ -11,6 +11,6 @@ import{z as e}from"zod";const t=e.uuid({error:`Invalid UUID provided`}),n=e.obje
|
|
|
11
11
|
`)}&format=json`);if(!u.ok)throw Error(`Error fetching gallery items, please try again later.`);let d=await u.json();if(!(`gallery`in d.result))throw Error(`Failed to fetch gallery`);let f=M(d.result.gallery.item.identification),p=M(d.result.gallery.project.identification),m={identification:f,projectIdentification:p,resources:J(d.result.gallery.resource?Array.isArray(d.result.gallery.resource)?d.result.gallery.resource:[d.result.gallery.resource]:[]),maxLength:d.result.gallery.maxLength};return{item:m,error:null}}catch(e){return console.error(e),{item:null,error:e instanceof Error?e.message:`Failed to fetch gallery`}}}async function Ee(e,n){try{let r=t.parse(e),i=await(n??fetch)(`https://ochre.lib.uchicago.edu/ochre?uuid=${r}&format=json&lang="*"`);if(!i.ok)throw Error(`Failed to fetch OCHRE data`);let a=await i.json();if(!(`ochre`in a))throw Error(`Invalid OCHRE data: API response missing 'ochre' key`);return[null,a]}catch(e){return[e instanceof Error?e.message:`Unknown error`,null]}}async function De(e,t,n,r){try{let[i,a]=await Ee(e,r);if(i!==null)throw Error(i);let o=j(Object.keys(a.ochre)),s;switch(o){case`resource`:if(!(`resource`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'resource' key`);s=pe(a.ochre.resource);break;case`spatialUnit`:if(!(`spatialUnit`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'spatialUnit' key`);s=me(a.ochre.spatialUnit);break;case`concept`:if(!(`concept`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'concept' key`);s=ge(a.ochre.concept);break;case`period`:if(!(`period`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'period' key`);s=W(a.ochre.period);break;case`bibliography`:if(!(`bibliography`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'bibliography' key`);s=K(a.ochre.bibliography);break;case`person`:if(!(`person`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'person' key`);s=ne(a.ochre.person);break;case`propertyValue`:if(!(`propertyValue`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'propertyValue' key`);s=le(a.ochre.propertyValue);break;case`set`:if(!(`set`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'set' key`);s=fe(a.ochre.set,n);break;case`tree`:if(!(`tree`in a.ochre))throw Error(`Invalid OCHRE data: API response missing 'tree' key`);s=de(a.ochre.tree,t,n);break;default:throw Error(`Invalid category`)}let c=te(a.ochre.metadata),l={uuid:a.ochre.uuidBelongsTo,abbreviation:D(a.ochre.belongsTo)};return{error:null,metadata:c,belongsTo:l,item:s,category:t}}catch(e){return{error:e instanceof Error?e.message:`Unknown error`,metadata:void 0,belongsTo:void 0,item:void 0,category:void 0}}}const Oe=`0c0aae37-7246-495b-9547-e25dbf5b99a3`,ke=`30054cb2-909a-4f34-8db9-8fe7369d691d`,Ae=`e28e29af-b663-c0ac-ceb6-11a688fca0dd`;function Q(e){let t=/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;return t.test(e)}const $=e.object({property:e.string().refine(Q),category:e.object({uuid:e.string().refine(Q),content:e.string()}),value:e.object({uuid:e.string().refine(Q).optional(),category:e.string().optional(),type:e.string().optional(),dataType:e.string(),publicationDateTime:e.iso.datetime().optional(),content:e.string().optional(),rawValue:e.string().optional()})}),je=e.object({result:e.object({item:e.union([$,e.array($)])})});function Me(e,t){let n=``;if(e.length>0){let t=e.map(e=>`@uuid="${e}"`).join(` or `);n=`[properties/property[label/@uuid="${ke}"][value[${t}]]]`}let r=t.map(e=>`@uuid="${e}"`).join(` or `),i=`for $q in input()/ochre[@uuidBelongsTo="${Oe}"]/*${n}/properties//property[label[${r}]]
|
|
12
12
|
return <item>
|
|
13
13
|
<property>{xs:string($q/label/@uuid)}</property> {$q/*[2]}
|
|
14
|
-
<value>{$q/*[2]
|
|
14
|
+
<value>{$q/*[2]/@*} {$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
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