@coasys/ad4m-connect 0.12.0-rc1-dev.3 → 0.12.0-rc1-dev.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/core.js +1 -1
- package/dist/index.js +1 -1
- package/dist/web.js +1 -1
- package/package.json +3 -3
package/dist/core.js
CHANGED
|
@@ -1579,7 +1579,7 @@ FETCH links
|
|
|
1579
1579
|
${s.filter(l=>l).join(", ")}
|
|
1580
1580
|
), UnsortedInstances),
|
|
1581
1581
|
${c.filter(l=>l).join(", ")}
|
|
1582
|
-
`}static async countQueryToSurrealQL(e,t){let n={...t};return delete n.limit,delete n.offset,await this.queryToSurrealQL(e,n)}static async count(e,t={},n=!0){if(n){let i=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(i),{totalCount:o}=await this.instancesFromSurrealResult(e,t,a);return o}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,n){let i=this.getPropertyMetadata(e);if(!i){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,i),o=i.resolveLanguage;t==null||t===""||(o&&(t=await this._perspective.createExpression(t,o)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],n))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(o=>({name:"value",value:this.resolveRelationId(o)})),n):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async addRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async removeRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let n=this.constructor.getModelMetadata(),i=Object.values(n.properties).some(
|
|
1582
|
+
`}static async countQueryToSurrealQL(e,t){let n={...t};return delete n.limit,delete n.offset,await this.queryToSurrealQL(e,n)}static async count(e,t={},n=!0){if(n){let i=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(i),{totalCount:o}=await this.instancesFromSurrealResult(e,t,a);return o}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,n){let i=this.getPropertyMetadata(e);if(!i){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,i),o=i.resolveLanguage;t==null||t===""||(o&&(t=await this._perspective.createExpression(t,o)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],n))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(o=>({name:"value",value:this.resolveRelationId(o)})),n):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async addRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async removeRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let n=this.constructor.getModelMetadata(),i=Object.values(n.properties).some(o=>o.required||o.flag||o.initial!==void 0),a=[];if(i){let o={};for(let[c,u]of Object.entries(this))if(u!=null&&!(Array.isArray(u)&&u.length>0)&&!u?.action){let l=n.properties[c];if(l?.resolveLanguage&&l.resolveLanguage!=="literal"&&typeof u=="object"){a.push(c);continue}o[c]=u}let s=await this.perspective.stringOrTemplateObjectToSubjectClassName(this);await this.perspective.createSubject(s,this._baseExpression,o,e)}await this.innerUpdate(!i,e);for(let o of a){let s=this[o];s!=null&&await this.setProperty(o,s,e)}t?(await this.perspective.commitBatch(e),await this.getData()):this.takeSnapshot()}cleanCopy(){let t=this.constructor.getModelMetadata(),n={},i=new Set([...Object.keys(t.properties),...Object.keys(t.relations)]);for(let a of i){let o=this[a];o!=null&&a!=="author"&&a!=="timestamp"&&(n[a]=o)}return n}async innerUpdate(e=!0,t){let n=this.constructor;this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy());let i=this._snapshot?new Set(this.changedFields()):null,a=n.getModelMetadata(),o=new Set([...Object.keys(a.properties),...Object.keys(a.relations)]),s=Object.entries(this);for(let[c,u]of s)if(!!o.has(c)&&!(i&&!i.has(c))&&u!=null){if(u?.action)switch(u.action){case"setter":await this.setRelationValues(c,u.value,t);break;case"adder":await this.addRelationValue(c,u.value,t);break;case"remover":await this.removeRelationValue(c,u.value,t);break;default:await this.setRelationValues(c,u.value,t);break}else if(Array.isArray(u))await this.setRelationValues(c,u,t);else if(u!=null&&u!==""&&e){if(this.getRelationOptions(c)||this.getPropertyMetadata(c)?.flag)continue;await this.setProperty(c,u,t)}}}async get(e){let t;return e?"include"in e||"properties"in e?t=e:t={include:e}:t=void 0,this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy()),await this.getData(t)}async delete(e){let t=this.constructor.getModelMetadata();if(Object.values(t.properties).some(i=>i.required||i.flag||i.initial!==void 0))await this._perspective.removeSubject(this,this._baseExpression,e);else try{let i=await this._perspective.get(new le({source:this._baseExpression}));i.length>0&&await this._perspective.removeLinks(i,e)}catch(i){console.warn(`delete(): failed to remove outgoing links for ${this._baseExpression}:`,i)}try{let i=await this._perspective.get(new le({target:this._baseExpression}));i.length>0&&await this._perspective.removeLinks(i,e)}catch(i){console.warn(`delete(): failed to clean up incoming links for ${this._baseExpression}:`,i)}}static async create(e,t={},n){let i=new this(e);if(Object.assign(i,t),n?.parent&&!n?.batchId){let a=await e.createBatch();await i.save(a);let o=oa(n.parent,this),s=new pt({source:n.parent.id,predicate:o,target:i.id});return await e.add(s,"shared",a),await e.commitBatch(a),await i.get(),i}if(await i.save(n?.batchId),n?.parent){let a=oa(n.parent,this),o=new pt({source:n.parent.id,predicate:a,target:i.id});await e.add(o,"shared",n?.batchId)}return i}static async update(e,t,n){let i=new this(e,t);return await i.get(),Object.assign(i,n),await i.save(),i}static async remove(e,t){return this.delete(e,t)}static async delete(e,t){await new this(e,t).delete()}static async register(e){await e.ensureSDNASubjectClass(this)}static async transaction(e,t){let n=await e.createBatch(),i=await t({batchId:n});return await e.commitBatch(n),i}static query(e,t){return new Ju(e,this,t)}static fromJSONSchema(e,t){if(e?.properties&&Object.prototype.hasOwnProperty.call(e.properties,"author"))throw new Error('JSON Schema must not define a top-level "author" property because Ad4mModel already exposes it. Please rename the property (e.g., "writer").');let n=this.determineNamespace(e,t),i=class extends jt{};if(!t.name||t.name.trim()==="")throw new Error("options.name is required and cannot be empty");i.className=t.name,i.prototype.className=t.name;let a={},o={};if(e.properties)for(let[c,u]of Object.entries(e.properties)){let l=this.determinePredicate(e,c,u,n,t),d=e.required?.includes(c)||!1,p=ll(u.type);if(Nd(u)){o[c]={through:l,local:this.getPropertyOption(c,u,t,"local")},Object.defineProperty(i.prototype,c,{configurable:!0,writable:!0,value:[]});let h=`add${ds(c)}`,m=`remove${ds(c)}`,g=`set${ds(c)}`;i.prototype[h]=function(){},i.prototype[m]=function(){},i.prototype[g]=function(){}}else{let h=this.getPropertyOption(c,u,t,"resolveLanguage");!h&&t.resolveLanguage&&(h=t.resolveLanguage);let m=this.getPropertyOption(c,u,t,"local"),g=this.getPropertyOption(c,u,t,"readOnly");if(g===void 0){let v=u["x-ad4m"]?.writable;g=v!==void 0?!v:!1}let S=!g,b=this.getPropertyOption(c,u,t,"initial");if(Dd(u)&&!h&&(h="literal",console.warn(`Property "${c}" is an object type. It will be stored as JSON. Consider flattening complex objects for better semantic querying.`)),h==null&&WS(u)&&(h="literal"),h==null&&(h="literal"),d&&!b&&(Dd(u)?b="literal://json:{}":b="ad4m://undefined"),a[c]={through:l,required:d,writable:S,...h&&{resolveLanguage:h},...m!==void 0&&{local:m},...b&&{initial:b}},Object.defineProperty(i.prototype,c,{configurable:!0,writable:!0,value:this.getDefaultValueForType(p)}),S){let v=xs(c);i.prototype[v]=function(){}}}}for(let[c,u]of Object.entries(a))Ay(i,c,u);for(let[c,u]of Object.entries(o))Oy(i,c,{predicate:u.through||"",kind:"hasMany",...u.getter!==void 0&&{getter:u.getter},...u.local!==void 0&&{local:u.local}});return i.prototype.__jsonSchema=e,i.prototype.__jsonSchemaOptions=t,Ny({name:t.name})(i),i}static determineNamespace(e,t){if(t.namespace)return t.namespace;if(e["x-ad4m"]?.namespace)return e["x-ad4m"].namespace;if(e.title)return`${e.title.toLowerCase()}://`;if(e.$id)try{let i=new URL(e.$id).pathname.split("/").filter(a=>a);if(i.length>0)return`${i[i.length-1].replace(/\.schema\.json$/,"").replace(/\.json$/,"").toLowerCase()}://`}catch{}throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
1583
1583
|
- options.namespace
|
|
1584
1584
|
- schema["x-ad4m"].namespace
|
|
1585
1585
|
- schema.title
|
package/dist/index.js
CHANGED
|
@@ -1579,7 +1579,7 @@ FETCH links
|
|
|
1579
1579
|
${s.filter(l=>l).join(", ")}
|
|
1580
1580
|
), UnsortedInstances),
|
|
1581
1581
|
${c.filter(l=>l).join(", ")}
|
|
1582
|
-
`}static async countQueryToSurrealQL(e,t){let n={...t};return delete n.limit,delete n.offset,await this.queryToSurrealQL(e,n)}static async count(e,t={},n=!0){if(n){let i=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(i),{totalCount:o}=await this.instancesFromSurrealResult(e,t,a);return o}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,n){let i=this.getPropertyMetadata(e);if(!i){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,i),o=i.resolveLanguage;t==null||t===""||(o&&(t=await this._perspective.createExpression(t,o)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],n))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(o=>({name:"value",value:this.resolveRelationId(o)})),n):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async addRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async removeRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let n=this.constructor.getModelMetadata(),i=Object.values(n.properties).some(
|
|
1582
|
+
`}static async countQueryToSurrealQL(e,t){let n={...t};return delete n.limit,delete n.offset,await this.queryToSurrealQL(e,n)}static async count(e,t={},n=!0){if(n){let i=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(i),{totalCount:o}=await this.instancesFromSurrealResult(e,t,a);return o}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,n){let i=this.getPropertyMetadata(e);if(!i){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,i),o=i.resolveLanguage;t==null||t===""||(o&&(t=await this._perspective.createExpression(t,o)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],n))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(o=>({name:"value",value:this.resolveRelationId(o)})),n):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async addRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async removeRelationValue(e,t,n){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(o=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(o)}],n))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],n))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let n=this.constructor.getModelMetadata(),i=Object.values(n.properties).some(o=>o.required||o.flag||o.initial!==void 0),a=[];if(i){let o={};for(let[c,u]of Object.entries(this))if(u!=null&&!(Array.isArray(u)&&u.length>0)&&!u?.action){let l=n.properties[c];if(l?.resolveLanguage&&l.resolveLanguage!=="literal"&&typeof u=="object"){a.push(c);continue}o[c]=u}let s=await this.perspective.stringOrTemplateObjectToSubjectClassName(this);await this.perspective.createSubject(s,this._baseExpression,o,e)}await this.innerUpdate(!i,e);for(let o of a){let s=this[o];s!=null&&await this.setProperty(o,s,e)}t?(await this.perspective.commitBatch(e),await this.getData()):this.takeSnapshot()}cleanCopy(){let t=this.constructor.getModelMetadata(),n={},i=new Set([...Object.keys(t.properties),...Object.keys(t.relations)]);for(let a of i){let o=this[a];o!=null&&a!=="author"&&a!=="timestamp"&&(n[a]=o)}return n}async innerUpdate(e=!0,t){let n=this.constructor;this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy());let i=this._snapshot?new Set(this.changedFields()):null,a=n.getModelMetadata(),o=new Set([...Object.keys(a.properties),...Object.keys(a.relations)]),s=Object.entries(this);for(let[c,u]of s)if(!!o.has(c)&&!(i&&!i.has(c))&&u!=null){if(u?.action)switch(u.action){case"setter":await this.setRelationValues(c,u.value,t);break;case"adder":await this.addRelationValue(c,u.value,t);break;case"remover":await this.removeRelationValue(c,u.value,t);break;default:await this.setRelationValues(c,u.value,t);break}else if(Array.isArray(u))await this.setRelationValues(c,u,t);else if(u!=null&&u!==""&&e){if(this.getRelationOptions(c)||this.getPropertyMetadata(c)?.flag)continue;await this.setProperty(c,u,t)}}}async get(e){let t;return e?"include"in e||"properties"in e?t=e:t={include:e}:t=void 0,this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy()),await this.getData(t)}async delete(e){let t=this.constructor.getModelMetadata();if(Object.values(t.properties).some(i=>i.required||i.flag||i.initial!==void 0))await this._perspective.removeSubject(this,this._baseExpression,e);else try{let i=await this._perspective.get(new fe({source:this._baseExpression}));i.length>0&&await this._perspective.removeLinks(i,e)}catch(i){console.warn(`delete(): failed to remove outgoing links for ${this._baseExpression}:`,i)}try{let i=await this._perspective.get(new fe({target:this._baseExpression}));i.length>0&&await this._perspective.removeLinks(i,e)}catch(i){console.warn(`delete(): failed to clean up incoming links for ${this._baseExpression}:`,i)}}static async create(e,t={},n){let i=new this(e);if(Object.assign(i,t),n?.parent&&!n?.batchId){let a=await e.createBatch();await i.save(a);let o=Ma(n.parent,this),s=new St({source:n.parent.id,predicate:o,target:i.id});return await e.add(s,"shared",a),await e.commitBatch(a),await i.get(),i}if(await i.save(n?.batchId),n?.parent){let a=Ma(n.parent,this),o=new St({source:n.parent.id,predicate:a,target:i.id});await e.add(o,"shared",n?.batchId)}return i}static async update(e,t,n){let i=new this(e,t);return await i.get(),Object.assign(i,n),await i.save(),i}static async remove(e,t){return this.delete(e,t)}static async delete(e,t){await new this(e,t).delete()}static async register(e){await e.ensureSDNASubjectClass(this)}static async transaction(e,t){let n=await e.createBatch(),i=await t({batchId:n});return await e.commitBatch(n),i}static query(e,t){return new Ql(e,this,t)}static fromJSONSchema(e,t){if(e?.properties&&Object.prototype.hasOwnProperty.call(e.properties,"author"))throw new Error('JSON Schema must not define a top-level "author" property because Ad4mModel already exposes it. Please rename the property (e.g., "writer").');let n=this.determineNamespace(e,t),i=class extends Zt{};if(!t.name||t.name.trim()==="")throw new Error("options.name is required and cannot be empty");i.className=t.name,i.prototype.className=t.name;let a={},o={};if(e.properties)for(let[c,u]of Object.entries(e.properties)){let l=this.determinePredicate(e,c,u,n,t),f=e.required?.includes(c)||!1,d=ip(u.type);if(Uh(u)){o[c]={through:l,local:this.getPropertyOption(c,u,t,"local")},Object.defineProperty(i.prototype,c,{configurable:!0,writable:!0,value:[]});let h=`add${Xs(c)}`,m=`remove${Xs(c)}`,g=`set${Xs(c)}`;i.prototype[h]=function(){},i.prototype[m]=function(){},i.prototype[g]=function(){}}else{let h=this.getPropertyOption(c,u,t,"resolveLanguage");!h&&t.resolveLanguage&&(h=t.resolveLanguage);let m=this.getPropertyOption(c,u,t,"local"),g=this.getPropertyOption(c,u,t,"readOnly");if(g===void 0){let v=u["x-ad4m"]?.writable;g=v!==void 0?!v:!1}let w=!g,b=this.getPropertyOption(c,u,t,"initial");if(jh(u)&&!h&&(h="literal",console.warn(`Property "${c}" is an object type. It will be stored as JSON. Consider flattening complex objects for better semantic querying.`)),h==null&&kS(u)&&(h="literal"),h==null&&(h="literal"),f&&!b&&(jh(u)?b="literal://json:{}":b="ad4m://undefined"),a[c]={through:l,required:f,writable:w,...h&&{resolveLanguage:h},...m!==void 0&&{local:m},...b&&{initial:b}},Object.defineProperty(i.prototype,c,{configurable:!0,writable:!0,value:this.getDefaultValueForType(d)}),w){let v=lc(c);i.prototype[v]=function(){}}}}for(let[c,u]of Object.entries(a))sb(i,c,u);for(let[c,u]of Object.entries(o))cb(i,c,{predicate:u.through||"",kind:"hasMany",...u.getter!==void 0&&{getter:u.getter},...u.local!==void 0&&{local:u.local}});return i.prototype.__jsonSchema=e,i.prototype.__jsonSchemaOptions=t,ub({name:t.name})(i),i}static determineNamespace(e,t){if(t.namespace)return t.namespace;if(e["x-ad4m"]?.namespace)return e["x-ad4m"].namespace;if(e.title)return`${e.title.toLowerCase()}://`;if(e.$id)try{let i=new URL(e.$id).pathname.split("/").filter(a=>a);if(i.length>0)return`${i[i.length-1].replace(/\.schema\.json$/,"").replace(/\.json$/,"").toLowerCase()}://`}catch{}throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
1583
1583
|
- options.namespace
|
|
1584
1584
|
- schema["x-ad4m"].namespace
|
|
1585
1585
|
- schema.title
|
package/dist/web.js
CHANGED
|
@@ -1958,7 +1958,7 @@ FETCH links
|
|
|
1958
1958
|
${o.filter(u=>u).join(", ")}
|
|
1959
1959
|
), UnsortedInstances),
|
|
1960
1960
|
${c.filter(u=>u).join(", ")}
|
|
1961
|
-
`}static async countQueryToSurrealQL(e,t){let r={...t};return delete r.limit,delete r.offset,await this.queryToSurrealQL(e,r)}static async count(e,t={},r=!0){if(r){let n=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(n),{totalCount:s}=await this.instancesFromSurrealResult(e,t,a);return s}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,r){let n=this.getPropertyMetadata(e);if(!n){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,n),s=n.resolveLanguage;t==null||t===""||(s&&(t=await this._perspective.createExpression(t,s)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],r))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(s=>({name:"value",value:this.resolveRelationId(s)})),r):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async addRelationValue(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(s=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(s)}],r))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async removeRelationValue(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(s=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(s)}],r))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let r=this.constructor.getModelMetadata(),n=Object.values(r.properties).some(
|
|
1961
|
+
`}static async countQueryToSurrealQL(e,t){let r={...t};return delete r.limit,delete r.offset,await this.queryToSurrealQL(e,r)}static async count(e,t={},r=!0){if(r){let n=await this.queryToSurrealQL(e,t),a=await e.querySurrealDB(n),{totalCount:s}=await this.instancesFromSurrealResult(e,t,a);return s}else return(await e.infer(await this.countQueryToProlog(e,t)))?.[0]?.TotalCount||0}async setProperty(e,t,r){let n=this.getPropertyMetadata(e);if(!n){console.warn(`Property "${e}" has no metadata, skipping`);return}let a=this.generatePropertySetterAction(e,n),s=n.resolveLanguage;t==null||t===""||(s&&(t=await this._perspective.createExpression(t,s)),await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:t}],r))}resolveRelationId(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.id=="string"?e.id:String(e)}async setRelationValues(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"setter");t!=null&&(Array.isArray(t)?await this._perspective.executeAction(a,this._baseExpression,t.map(s=>({name:"value",value:this.resolveRelationId(s)})),r):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async addRelationValue(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"adder");t!=null&&(Array.isArray(t)?await Promise.all(t.map(s=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(s)}],r))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async removeRelationValue(e,t,r){if(!this.getRelationOptions(e)){console.warn(`Relation "${e}" has no metadata, skipping`);return}let a=this.generateRelationAction(e,"remover");t!=null&&(Array.isArray(t)?await Promise.all(t.map(s=>this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(s)}],r))):await this._perspective.executeAction(a,this._baseExpression,[{name:"value",value:this.resolveRelationId(t)}],r))}async save(e){if(this._snapshot){await this.innerUpdate(!0,e),e?this.takeSnapshot():await this.getData();return}let t=!1;e||(e=await this.perspective.createBatch(),t=!0);let r=this.constructor.getModelMetadata(),n=Object.values(r.properties).some(s=>s.required||s.flag||s.initial!==void 0),a=[];if(n){let s={};for(let[c,l]of Object.entries(this))if(l!=null&&!(Array.isArray(l)&&l.length>0)&&!l?.action){let u=r.properties[c];if(u?.resolveLanguage&&u.resolveLanguage!=="literal"&&typeof l=="object"){a.push(c);continue}s[c]=l}let o=await this.perspective.stringOrTemplateObjectToSubjectClassName(this);await this.perspective.createSubject(o,this._baseExpression,s,e)}await this.innerUpdate(!n,e);for(let s of a){let o=this[s];o!=null&&await this.setProperty(s,o,e)}t?(await this.perspective.commitBatch(e),await this.getData()):this.takeSnapshot()}cleanCopy(){let t=this.constructor.getModelMetadata(),r={},n=new Set([...Object.keys(t.properties),...Object.keys(t.relations)]);for(let a of n){let s=this[a];s!=null&&a!=="author"&&a!=="timestamp"&&(r[a]=s)}return r}async innerUpdate(e=!0,t){let r=this.constructor;this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy());let n=this._snapshot?new Set(this.changedFields()):null,a=r.getModelMetadata(),s=new Set([...Object.keys(a.properties),...Object.keys(a.relations)]),o=Object.entries(this);for(let[c,l]of o)if(!!s.has(c)&&!(n&&!n.has(c))&&l!=null){if(l?.action)switch(l.action){case"setter":await this.setRelationValues(c,l.value,t);break;case"adder":await this.addRelationValue(c,l.value,t);break;case"remover":await this.removeRelationValue(c,l.value,t);break;default:await this.setRelationValues(c,l.value,t);break}else if(Array.isArray(l))await this.setRelationValues(c,l,t);else if(l!=null&&l!==""&&e){if(this.getRelationOptions(c)||this.getPropertyMetadata(c)?.flag)continue;await this.setProperty(c,l,t)}}}async get(e){let t;return e?"include"in e||"properties"in e?t=e:t={include:e}:t=void 0,this._subjectClassName=await this._perspective.stringOrTemplateObjectToSubjectClassName(this.cleanCopy()),await this.getData(t)}async delete(e){let t=this.constructor.getModelMetadata();if(Object.values(t.properties).some(n=>n.required||n.flag||n.initial!==void 0))await this._perspective.removeSubject(this,this._baseExpression,e);else try{let n=await this._perspective.get(new te({source:this._baseExpression}));n.length>0&&await this._perspective.removeLinks(n,e)}catch(n){console.warn(`delete(): failed to remove outgoing links for ${this._baseExpression}:`,n)}try{let n=await this._perspective.get(new te({target:this._baseExpression}));n.length>0&&await this._perspective.removeLinks(n,e)}catch(n){console.warn(`delete(): failed to clean up incoming links for ${this._baseExpression}:`,n)}}static async create(e,t={},r){let n=new this(e);if(Object.assign(n,t),r?.parent&&!r?.batchId){let a=await e.createBatch();await n.save(a);let s=Mr(r.parent,this),o=new Ve({source:r.parent.id,predicate:s,target:n.id});return await e.add(o,"shared",a),await e.commitBatch(a),await n.get(),n}if(await n.save(r?.batchId),r?.parent){let a=Mr(r.parent,this),s=new Ve({source:r.parent.id,predicate:a,target:n.id});await e.add(s,"shared",r?.batchId)}return n}static async update(e,t,r){let n=new this(e,t);return await n.get(),Object.assign(n,r),await n.save(),n}static async remove(e,t){return this.delete(e,t)}static async delete(e,t){await new this(e,t).delete()}static async register(e){await e.ensureSDNASubjectClass(this)}static async transaction(e,t){let r=await e.createBatch(),n=await t({batchId:r});return await e.commitBatch(r),n}static query(e,t){return new no(e,this,t)}static fromJSONSchema(e,t){if(e?.properties&&Object.prototype.hasOwnProperty.call(e.properties,"author"))throw new Error('JSON Schema must not define a top-level "author" property because Ad4mModel already exposes it. Please rename the property (e.g., "writer").');let r=this.determineNamespace(e,t),n=class extends ut{};if(!t.name||t.name.trim()==="")throw new Error("options.name is required and cannot be empty");n.className=t.name,n.prototype.className=t.name;let a={},s={};if(e.properties)for(let[c,l]of Object.entries(e.properties)){let u=this.determinePredicate(e,c,l,r,t),y=e.required?.includes(c)||!1,g=bo(l.type);if(cl(l)){s[c]={through:u,local:this.getPropertyOption(c,l,t,"local")},Object.defineProperty(n.prototype,c,{configurable:!0,writable:!0,value:[]});let p=`add${ga(c)}`,h=`remove${ga(c)}`,w=`set${ga(c)}`;n.prototype[p]=function(){},n.prototype[h]=function(){},n.prototype[w]=function(){}}else{let p=this.getPropertyOption(c,l,t,"resolveLanguage");!p&&t.resolveLanguage&&(p=t.resolveLanguage);let h=this.getPropertyOption(c,l,t,"local"),w=this.getPropertyOption(c,l,t,"readOnly");if(w===void 0){let k=l["x-ad4m"]?.writable;w=k!==void 0?!k:!1}let E=!w,I=this.getPropertyOption(c,l,t,"initial");if(ll(l)&&!p&&(p="literal",console.warn(`Property "${c}" is an object type. It will be stored as JSON. Consider flattening complex objects for better semantic querying.`)),p==null&&zh(l)&&(p="literal"),p==null&&(p="literal"),y&&!I&&(ll(l)?I="literal://json:{}":I="ad4m://undefined"),a[c]={through:u,required:y,writable:E,...p&&{resolveLanguage:p},...h!==void 0&&{local:h},...I&&{initial:I}},Object.defineProperty(n.prototype,c,{configurable:!0,writable:!0,value:this.getDefaultValueForType(g)}),E){let k=Aa(c);n.prototype[k]=function(){}}}}for(let[c,l]of Object.entries(a))Ad(n,c,l);for(let[c,l]of Object.entries(s))kd(n,c,{predicate:l.through||"",kind:"hasMany",...l.getter!==void 0&&{getter:l.getter},...l.local!==void 0&&{local:l.local}});return n.prototype.__jsonSchema=e,n.prototype.__jsonSchemaOptions=t,Id({name:t.name})(n),n}static determineNamespace(e,t){if(t.namespace)return t.namespace;if(e["x-ad4m"]?.namespace)return e["x-ad4m"].namespace;if(e.title)return`${e.title.toLowerCase()}://`;if(e.$id)try{let n=new URL(e.$id).pathname.split("/").filter(a=>a);if(n.length>0)return`${n[n.length-1].replace(/\.schema\.json$/,"").replace(/\.json$/,"").toLowerCase()}://`}catch{}throw new Error(`Cannot infer namespace for JSON Schema. Please provide one of:
|
|
1962
1962
|
- options.namespace
|
|
1963
1963
|
- schema["x-ad4m"].namespace
|
|
1964
1964
|
- schema.title
|
package/package.json
CHANGED
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"email": "nicolas@coasys.org"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@coasys/ad4m": "0.12.0-rc1-dev.2",
|
|
41
40
|
"@apollo/client": "3.7.10",
|
|
42
41
|
"@types/node": "^16.11.11",
|
|
43
42
|
"esbuild": "^0.15.5",
|
|
@@ -46,7 +45,8 @@
|
|
|
46
45
|
"np": "^7.6.2",
|
|
47
46
|
"npm-run-all": "^4.1.5",
|
|
48
47
|
"typescript": "^4.6.2",
|
|
49
|
-
"vite": "^4.1.1"
|
|
48
|
+
"vite": "^4.1.1",
|
|
49
|
+
"@coasys/ad4m": "0.12.0-rc1-dev.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@undecaf/barcode-detector-polyfill": "^0.9.15",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@coasys/ad4m": "*"
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
"version": "0.12.0-rc1-dev.
|
|
64
|
+
"version": "0.12.0-rc1-dev.4",
|
|
65
65
|
"scripts": {
|
|
66
66
|
"release": "np --no-2fa --no-tests --tag=latest",
|
|
67
67
|
"release:beta": "np --no-2fa --no-tests --tag=beta --any-branch",
|