@chialab/backbone
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -1,4 +0,4 @@ | ||
var v=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var i=(e,t,r)=>(v(e,t,"read from private field"),r?r.call(e):t.get(e)),d=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},k=(e,t,r,n)=>(v(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);import P from"ajv";import F from"ajv-formats";var x=new P({keywords:[{keyword:"__esModule"},{keyword:"formatOptions",valid:!0},{keyword:"form",metaSchema:{type:"object",properties:{type:{type:"string"}}}}],formats:{text:e=>typeof e=="string",html:e=>typeof e=="string",code:e=>typeof e=="string"},allowUnionTypes:!0,strictTypes:!1});F(x);function S(e,t=[]){return Array.isArray(e)?e.forEach(r=>S(r,t)):e.oneOf?S(e.oneOf,t):e.allOf?S(e.allOf,t):e.$ref&&t.push(e.$ref),t}var g=class{static register(t,r){if(this.registry.has(t))throw new Error(`Model "${t}" has already been registered.`);this.registry.set(t,r)}static get(t){if(!this.registry.has(t))throw new Error(`Model "${t}" is not registered.`);return this.registry.get(t)}static entries(){return this.registry.entries()}};g.registry=new Map;function U(e){return function(t){let r=t.setupSchema();r.$id=e,r.type="object",t.validator=x.addSchema(r,e).compile(r),g.register(e,t)}}function A(e){return function(t,r){t.constructor.setupProperty(r,{type:e})}}function j(e){return function(t,r){t.constructor.setupProperty(r,{anyOf:e.map(o=>typeof o=="string"?{type:o}:o)})}}function V(){return function(e,t){e.constructor.setupProperty(t,{readOnly:!0})}}function q(){return function(e,t){let n=e.constructor.setupSchema();(n.required=n.required||[]).push(t)}}function R(e,t={}){return function(r,n){r.constructor.setupProperty(n,{format:e,formatOptions:t})}}function H(e){return function(t,r){t.constructor.setupProperty(r,{default:e})}}function L(e){return function(t,r){t.constructor.setupProperty(r,{type:"string",enum:Array.isArray(e)?e:Object.values(e)})}}function K(e){return function(t,r){let n=t.constructor;e=e.filter(o=>o.schema),n.setupProperty(r,{type:"array",items:e.length>1?{allOf:e.map(o=>({$ref:o.schema.$id}))}:e.length===1?{$ref:e[0].schema.$id}:{}})}}function B(e){return function(t,r){let n=t.constructor,o=Array.isArray(e)?{oneOf:e.map(a=>typeof a=="string"?{type:a}:{$ref:a.schema.$id})}:{$ref:e.schema.$id};n.setupProperty(r,o)}}function _(e){return function(t,r){let n=t.constructor,o=(Array.isArray(e)?e:[e]).filter(a=>a.schema);n.setupProperty(r,{type:"array",uniqueItems:!0,items:o.length>1?{allOf:o.map(a=>({$ref:a.schema.$id}))}:o.length===1?{$ref:o[0].schema.$id}:{}})}}function G(e){return function(t,r){t.constructor.setupProperty(r,{form:e})}}function Q(e,t){return function(r,n){r.constructor.setupSerializer(n,{serialize:e,unserialize:t})}}var p,y=class{constructor(){d(this,p,{})}on(t,r){i(this,p)[t]=i(this,p)[t]||[],i(this,p)[t].push(r)}off(t,r){let n=i(this,p)[t];if(!n)return;let o=n.indexOf(r);o!==-1&&i(this,p)[t].splice(o,1)}trigger(t,r){let n=i(this,p)[t];!n||n.forEach(o=>o.call(this,r))}};p=new WeakMap;var c,T=class extends y{constructor(t=[]){super();d(this,c,void 0);k(this,c,t)}get length(){return i(this,c).length}add(...t){return t=t.filter(r=>!this.has(r)),i(this,c).push(...t),this.trigger("change",{added:t,removed:[],length:this.length}),this}insert(t,...r){return r.filter(n=>this.has(n)).forEach(n=>{i(this,c).splice(this.indexOf(n),1)}),i(this,c).splice(t,0,...r),this.trigger("change",{added:r,removed:[],length:this.length}),this}remove(...t){return t=t.filter(r=>this.has(r)),t.forEach(r=>{i(this,c).splice(this.indexOf(r),1)}),this.trigger("change",{added:[],removed:t,length:this.length}),this}indexOf(t){return i(this,c).indexOf(t)}item(t){return i(this,c)[t]||null}itemById(t){let r=i(this,c);for(let n=0,o=r.length;n<o;n++)if(r[n].getId()===t)return r[n];return null}has(t){return this.indexOf(t)!==-1}forEach(t){return i(this,c).forEach(t)}some(t){return i(this,c).some(t)}find(t){return i(this,c).find(t)}map(t){return i(this,c).map(t)}entries(){return i(this,c).entries()}filter(t){let r=this.constructor;return new r(i(this,c).filter(t))}reduce(t,r){return i(this,c).reduce(t,r)}get(){return i(this,c).slice(0)}clone(){return new T(this.get())}toJSON(){return this.get().map(t=>t.toJSON())}*[Symbol.iterator](){for(let t of i(this,c))yield t}},M=T;c=new WeakMap,M.className="Collection";function b(e,t,r,n=!1){let o={},a=t.schema,l=t.serializers||{};for(let s in e){if(a&&r&&!r(s,a.properties?.[s],a,e,t))continue;let u=e[s],f=l[s]?.serialize;f&&!n?o[s]=f(u,e,o):o[s]=u}return o}function O(e,t,r,n=!1){if(e instanceof w||t){t=t||e.constructor;let o=b(e,t,r,n);for(let a in o)o[a]=O(o[a],void 0,r,n);return o}return Array.isArray(e)||e instanceof M?e.map(o=>O(o,void 0,r,n)):e}function rt(e,t,r){let n=t.schema,o=t.serializers||{},a=n.properties||{},l={};for(let s in e)if(a[s]){let f=o[s]?.unserialize,z=e[s];f?l[s]=f(z,e,r):l[s]=z}return new t(l,r)}var m,w=class extends y{constructor(t,r){super();d(this,m,[]);let n=this.constructor,o=n.setupSerializers();if(t){let l=this.getSchema().properties||{};for(let s in l){let u=l[s];"default"in u&&!(s in t)&&(typeof u.default=="function"?t[s]=u.default(this,t):t[s]=u.default)}if(!r?.skipValidation&&!r?.editingMode){let s=n.validator;if(s&&!s(t))throw new Error(`Invalid init properties. | ||
${s.errors?.map(u=>JSON.stringify(u)).join(` | ||
`)}`)}for(let s in t){let u=o[s]?.unserialize,f=u?u(t[s],t,r):t[s];this[s]=f}}}static setupSchema(){return Object.prototype.hasOwnProperty.call(this,"schema")?this.schema:this.schema=this.schema?JSON.parse(JSON.stringify(this.schema)):{}}static setupSerializers(){return Object.prototype.hasOwnProperty.call(this,"serializers")?this.serializers:this.serializers={...this.serializers||{}}}static setupProperty(t,r){let n=this.setupSchema(),o=n.properties=n.properties||{},a=o[t]=o[t]||{};return Object.assign(a,r),a}static setupSerializer(t,r){let n=this.setupSerializers();n[t]=r}isNew(){return!this.hasChanges()}getId(){}getDisplayName(){return this.getId()}getDisplayFields(){return[]}getSchema(){return this.constructor.schema||{}}getModelType(){return this.getSchema().$id}getPropertyFormat(t){let o=(this.getSchema().properties||{})[t];if(!!o)return o.format}get(t){return this[t]}set(t,r=!1){let n=this.toJSON(),o=!1;for(let a in t){let l=t[a];(l!==this[a]||r)&&(o=!0,this[a]=l)}o&&(i(this,m).push(n),this.trigger("change"))}hasChanges(){return!!i(this,m).length}validate(){let t=this.constructor;return t.validator(O(this,t,void 0,!0))}getErrors(){let r=this.constructor.validator;return this.validate()?[]:r.errors||[]}toJSON(){return O(this)}};m=new WeakMap;var ot={serialize:e=>e&&!isNaN(e.getTime())?e.toISOString():void 0,unserialize:e=>e?new Date(e):void 0};export{j as AnyOf,M as Collection,ot as DateSerializer,H as Default,y as Emitter,L as Enum,G as Form,R as Format,_ as HasMany,B as HasOne,K as Items,w as Model,V as ReadOnly,g as Registry,q as Required,U as Schema,Q as Serialize,A as Type,S as collectReferences,x as schemaManager,O as serialize,rt as unserialize}; | ||
var v=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var s=(e,t,r)=>(v(e,t,"read from private field"),r?r.call(e):t.get(e)),d=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},k=(e,t,r,n)=>(v(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);import P from"ajv";import F from"ajv-formats";var x=new P({keywords:[{keyword:"__esModule"},{keyword:"formatOptions",valid:!0},{keyword:"form",metaSchema:{type:"object",properties:{type:{type:"string"}}}}],formats:{text:e=>typeof e=="string",html:e=>typeof e=="string",code:e=>typeof e=="string"},allowUnionTypes:!0,strictTypes:!1});F(x);function S(e,t=[]){return Array.isArray(e)?e.forEach(r=>S(r,t)):e.oneOf?S(e.oneOf,t):e.allOf?S(e.allOf,t):e.$ref&&t.push(e.$ref),t}var M=class{static register(t,r){if(this.registry.has(t))throw new Error(`Model "${t}" has already been registered.`);this.registry.set(t,r)}static get(t){if(!this.registry.has(t))throw new Error(`Model "${t}" is not registered.`);return this.registry.get(t)}static entries(){return this.registry.entries()}};M.registry=new Map;function U(e){return function(t){let r=t.setupSchema();r.$id=e,r.type="object",t.validator=x.addSchema(r,e).compile(r),M.register(e,t)}}function A(e){return function(t,r){t.constructor.setupProperty(r,{type:e})}}function j(e){return function(t,r){t.constructor.setupProperty(r,{anyOf:e.map(o=>typeof o=="string"?{type:o}:o)})}}function V(){return function(e,t){e.constructor.setupProperty(t,{readOnly:!0})}}function q(){return function(e,t){let n=e.constructor.setupSchema();(n.required=n.required||[]).push(t)}}function R(e,t={}){return function(r,n){r.constructor.setupProperty(n,{format:e,formatOptions:t})}}function H(e){return function(t,r){t.constructor.setupProperty(r,{default:e})}}function L(e){return function(t,r){t.constructor.setupProperty(r,{type:"string",enum:Array.isArray(e)?e:Object.values(e)})}}function K(e){return function(t,r){let n=t.constructor;e=e.filter(o=>o.schema),n.setupProperty(r,{type:"array",items:e.length>1?{allOf:e.map(o=>({$ref:o.schema.$id}))}:e.length===1?{$ref:e[0].schema.$id}:{}})}}function B(e){return function(t,r){let n=t.constructor,o=Array.isArray(e)?{oneOf:e.map(a=>typeof a=="string"?{type:a}:{$ref:a.schema.$id})}:{$ref:e.schema.$id};n.setupProperty(r,o)}}function _(e){return function(t,r){let n=t.constructor,o=(Array.isArray(e)?e:[e]).filter(a=>a.schema);n.setupProperty(r,{type:"array",uniqueItems:!0,items:o.length>1?{allOf:o.map(a=>({$ref:a.schema.$id}))}:o.length===1?{$ref:o[0].schema.$id}:{}})}}function G(e){return function(t,r){t.constructor.setupProperty(r,{form:e})}}function Q(e,t){return function(r,n){r.constructor.setupSerializer(n,{serialize:e,unserialize:t})}}var p,y=class{constructor(){d(this,p,{})}on(t,r){s(this,p)[t]=s(this,p)[t]||[],s(this,p)[t].push(r)}off(t,r){let n=s(this,p)[t];if(!n)return;let o=n.indexOf(r);o!==-1&&s(this,p)[t].splice(o,1)}trigger(t,r){let n=s(this,p)[t];!n||n.forEach(o=>o.call(this,r))}};p=new WeakMap;var c,T=class extends y{constructor(t=[]){super();d(this,c,void 0);k(this,c,t)}get length(){return s(this,c).length}add(...t){return t=t.filter(r=>!this.has(r)),s(this,c).push(...t),this.trigger("change",{added:t,removed:[],length:this.length}),this}insert(t,...r){return r.filter(n=>this.has(n)).forEach(n=>{s(this,c).splice(this.indexOf(n),1)}),s(this,c).splice(t,0,...r),this.trigger("change",{added:r,removed:[],length:this.length}),this}remove(...t){return t=t.filter(r=>this.has(r)),t.forEach(r=>{s(this,c).splice(this.indexOf(r),1)}),this.trigger("change",{added:[],removed:t,length:this.length}),this}indexOf(t){return s(this,c).indexOf(t)}item(t){return s(this,c)[t]||null}itemById(t){let r=s(this,c);for(let n=0,o=r.length;n<o;n++)if(r[n].getId()===t)return r[n];return null}has(t){return this.indexOf(t)!==-1}forEach(t){return s(this,c).forEach(t)}some(t){return s(this,c).some(t)}find(t){return s(this,c).find(t)}map(t){return s(this,c).map(t)}entries(){return s(this,c).entries()}filter(t){let r=this.constructor;return new r(s(this,c).filter(t))}reduce(t,r){return s(this,c).reduce(t,r)}get(){return s(this,c).slice(0)}clone(){return new T(this.get())}toJSON(){return this.get().map(t=>t.toJSON())}*[Symbol.iterator](){for(let t of s(this,c))yield t}},O=T;c=new WeakMap,O.className="Collection";function b(e,t,r,n=!1){let o={},a=t.schema,u=t.serializers||{};for(let i in e){if(a&&r&&!r(i,a.properties?.[i],a,e,t))continue;let l=e[i],f=u[i]?.serialize;f&&!n?o[i]=f(l,e,o):o[i]=l}return o}function m(e,t,r,n=!1){if(e instanceof w||t){t=t||e.constructor;let o=b(e,t,r,n);for(let a in o)o[a]=m(o[a],void 0,r,n);return o}return Array.isArray(e)||e instanceof O?e.map(o=>m(o,void 0,r,n)):e}function rt(e,t,r){let n=t.schema,o=t.serializers||{},a=n.properties||{},u={};for(let i in e)if(a[i]){let f=o[i]?.unserialize,z=e[i];f?u[i]=f(z,e,r):u[i]=z}return new t(u,r)}var g,w=class extends y{constructor(t,r){super();d(this,g,[]);let n=this.constructor,o=n.setupSerializers();if(t){let u=this.getSchema().properties||{};for(let i in u){let l=u[i];if(i in t){let f=o[i]?.unserialize;t[i]=f?f(t[i],t,r):t[i]}else"default"in l&&(typeof l.default=="function"?t[i]=l.default(this,t):t[i]=l.default)}if(!r?.skipValidation&&!r?.editingMode){let i=n.validator;if(i&&!i(m(t,n)))throw new Error(`Invalid init properties. | ||
${i.errors?.map(l=>JSON.stringify(l)).join(` | ||
`)}`)}for(let i in t)this[i]=t[i]}}static setupSchema(){return Object.prototype.hasOwnProperty.call(this,"schema")?this.schema:this.schema=this.schema?JSON.parse(JSON.stringify(this.schema)):{}}static setupSerializers(){return Object.prototype.hasOwnProperty.call(this,"serializers")?this.serializers:this.serializers={...this.serializers||{}}}static setupProperty(t,r){let n=this.setupSchema(),o=n.properties=n.properties||{},a=o[t]=o[t]||{};return Object.assign(a,r),a}static setupSerializer(t,r){let n=this.setupSerializers();n[t]=r}isNew(){return!this.hasChanges()}getId(){}getDisplayName(){return this.getId()}getDisplayFields(){return[]}getSchema(){return this.constructor.schema||{}}getModelType(){return this.getSchema().$id}getPropertyFormat(t){let o=(this.getSchema().properties||{})[t];if(!!o)return o.format}get(t){return this[t]}set(t,r=!1){let n=this.toJSON(),o=!1;for(let a in t){let u=t[a];(u!==this[a]||r)&&(o=!0,this[a]=u)}o&&(s(this,g).push(n),this.trigger("change"))}hasChanges(){return!!s(this,g).length}validate(){let t=this.constructor;return t.validator(m(this,t,void 0,!0))}getErrors(){let r=this.constructor.validator;return this.validate()?[]:r.errors||[]}toJSON(){return m(this)}};g=new WeakMap;var ot={serialize:e=>e&&!isNaN(e.getTime())?e.toISOString():void 0,unserialize:e=>e?new Date(e):void 0};export{j as AnyOf,O as Collection,ot as DateSerializer,H as Default,y as Emitter,L as Enum,G as Form,R as Format,_ as HasMany,B as HasOne,K as Items,w as Model,V as ReadOnly,M as Registry,q as Required,U as Schema,Q as Serialize,A as Type,S as collectReferences,x as schemaManager,m as serialize,rt as unserialize}; | ||
//# sourceMappingURL=backbone.js.map |
{ | ||
"name": "@chialab/backbone", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Models, Collections and Form helpers for JS apps.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92710
331