Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jaysalvat/smart-model

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jaysalvat/smart-model - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

6

build/smart-model.esm.js

@@ -6,3 +6,3 @@

* https://github.com/jaysalvat/smart-model
* @version 0.2.1 built 2021-02-19 12:37:35
* @version 0.2.2 built 2021-02-19 12:51:57
* @license ISC

@@ -220,2 +220,4 @@ * @author Jay Salvat http://jaysalvat.com

feed(data) {
data = clone(data);
Object.keys(data).forEach((key) => {

@@ -245,3 +247,3 @@ this[key] = data[key];

constructor(data) {
super(schema, data);
super(schema);

@@ -248,0 +250,0 @@ return new Proxy(this, new ModelHandler(schema, settings))

@@ -1,2 +0,2 @@

/*! smartModel v0.2.1 */
function e(e){return""===e||null==e}function t(e){return"function"==typeof e}function r(e){return Array.isArray(e)}function n(e){return e?JSON.parse(JSON.stringify(e)):e}function o(t,n,o){const s=[];if(t.required&&e(o))return s.push({message:`Invalid value 'required' on property '${n}'`,code:"required"}),s;if(void 0===o)return s;if(t.type){let c;const i=r(t.type)?t.type:[t.type];c=!(t.required||!e(o))||i.some((e=>typeof o==typeof e()||o instanceof e)),c||s.push({message:`Invalid type '${typeof o}' on property '${n}'`,code:"type"})}return t.rule&&Object.keys(t.rule).forEach((e=>{(0,t.rule[e])(o)&&s.push({message:`Invalid value '${e}' on property '${n}'`,code:e})})),s}class s extends Error{constructor(e){super(e.message),Object.assign(this,e)}}class c{constructor(e={},t={}){this.schema=e,this.settings=t}set(e,t,r){const c=this.schema,i=n(e[t]),u=(f=r,a=i,!(JSON.stringify(f)===JSON.stringify(a)));var f,a;const p=c[t];function l(n){return Reflect.apply(n,e,[t,r,i,c])}if(!p)return this.settings.strict||(e[t]=r),!0;if(l(e.onBeforeSet),u&&l(e.onBeforeUpdate),p.transform&&(r=p.transform(r)),this.settings.exceptions){const e=o(p,t,r);e.length&&e.forEach((e=>{throw new s({message:e.message,property:t,code:e.code})}))}return e[t]=r,l(e.onSet),u&&l(e.onUpdate),!0}get(e,r){const n=this.schema,o=n[r];let s=e[r];if(!o)return e[r];function c(t,r){return Reflect.apply(t,e,r)}return c(e.onBeforeGet,[r,s,n]),t(o)&&(s=c(o,[e])),t(o.format)&&(s=c(o.format,[s,e])),c(e.onGet,[r,s,n]),s}deleteProperty(e,t){const r=n(e[t]),o=this.schema;function c(t,r){return Reflect.apply(t,e,r)}if(o[t].required)throw new s({message:`Invalid delete on required propery ${t}`,property:t,code:"delete"});return Reflect.deleteProperty(e,t),c(e.onDelete,[t,r,o]),c(e.onUpdate,[t,undefined,o]),!0}}class i{constructor(e={},t={}){Object.keys(e).forEach((t=>{e[t].default&&(this[t]=e[t].default)})),this.feed(t)}feed(e){Object.keys(e).forEach((t=>{this[t]=e[t]}))}onSet(){}onGet(){}onDelete(){}onUpdate(){}onBeforeSet(){}onBeforeGet(){}onBeforeUpdate(){}}i.settings={strict:!1,exceptions:!0},i.create=function(e,t,n,s={}){s=Object.assign({},i.settings,s);const u={[e]:class extends i{constructor(e){return super(t,e),new Proxy(this,new c(t,s))}}}[e];return u.checkErrors=function(e,r){const n={};return Object.keys(t).forEach((s=>{const c=e[s];let i=o(t[s],s,c);i.length&&(r&&(i=i.filter((e=>!function(e){return[].concat([],e)}(r).includes(e.code)))),i.length&&(n[s]=i))})),!!Object.keys(n).length&&n},u.hydrate=function(e){return r(e)?e.map((e=>new u(e))):new u(e)},Object.assign(u.prototype,n),u};export default i;
/*! smartModel v0.2.2 */
function e(e){return""===e||null==e}function t(e){return"function"==typeof e}function r(e){return Array.isArray(e)}function n(e){return e?JSON.parse(JSON.stringify(e)):e}function o(t,n,o){const s=[];if(t.required&&e(o))return s.push({message:`Invalid value 'required' on property '${n}'`,code:"required"}),s;if(void 0===o)return s;if(t.type){let c;const i=r(t.type)?t.type:[t.type];c=!(t.required||!e(o))||i.some((e=>typeof o==typeof e()||o instanceof e)),c||s.push({message:`Invalid type '${typeof o}' on property '${n}'`,code:"type"})}return t.rule&&Object.keys(t.rule).forEach((e=>{(0,t.rule[e])(o)&&s.push({message:`Invalid value '${e}' on property '${n}'`,code:e})})),s}class s extends Error{constructor(e){super(e.message),Object.assign(this,e)}}class c{constructor(e={},t={}){this.schema=e,this.settings=t}set(e,t,r){const c=this.schema,i=n(e[t]),u=(f=r,a=i,!(JSON.stringify(f)===JSON.stringify(a)));var f,a;const p=c[t];function l(n){return Reflect.apply(n,e,[t,r,i,c])}if(!p)return this.settings.strict||(e[t]=r),!0;if(l(e.onBeforeSet),u&&l(e.onBeforeUpdate),p.transform&&(r=p.transform(r)),this.settings.exceptions){const e=o(p,t,r);e.length&&e.forEach((e=>{throw new s({message:e.message,property:t,code:e.code})}))}return e[t]=r,l(e.onSet),u&&l(e.onUpdate),!0}get(e,r){const n=this.schema,o=n[r];let s=e[r];if(!o)return e[r];function c(t,r){return Reflect.apply(t,e,r)}return c(e.onBeforeGet,[r,s,n]),t(o)&&(s=c(o,[e])),t(o.format)&&(s=c(o.format,[s,e])),c(e.onGet,[r,s,n]),s}deleteProperty(e,t){const r=n(e[t]),o=this.schema;function c(t,r){return Reflect.apply(t,e,r)}if(o[t].required)throw new s({message:`Invalid delete on required propery ${t}`,property:t,code:"delete"});return Reflect.deleteProperty(e,t),c(e.onDelete,[t,r,o]),c(e.onUpdate,[t,undefined,o]),!0}}class i{constructor(e={},t={}){Object.keys(e).forEach((t=>{e[t].default&&(this[t]=e[t].default)})),this.feed(t)}feed(e){e=n(e),Object.keys(e).forEach((t=>{this[t]=e[t]}))}onSet(){}onGet(){}onDelete(){}onUpdate(){}onBeforeSet(){}onBeforeGet(){}onBeforeUpdate(){}}i.settings={strict:!1,exceptions:!0},i.create=function(e,t,n,s={}){s=Object.assign({},i.settings,s);const u={[e]:class extends i{constructor(e){return super(t),new Proxy(this,new c(t,s))}}}[e];return u.checkErrors=function(e,r){const n={};return Object.keys(t).forEach((s=>{const c=e[s];let i=o(t[s],s,c);i.length&&(r&&(i=i.filter((e=>!function(e){return[].concat([],e)}(r).includes(e.code)))),i.length&&(n[s]=i))})),!!Object.keys(n).length&&n},u.hydrate=function(e){return r(e)?e.map((e=>new u(e))):new u(e)},Object.assign(u.prototype,n),u};export default i;

@@ -6,3 +6,3 @@

* https://github.com/jaysalvat/smart-model
* @version 0.2.1 built 2021-02-19 12:37:35
* @version 0.2.2 built 2021-02-19 12:51:57
* @license ISC

@@ -226,2 +226,4 @@ * @author Jay Salvat http://jaysalvat.com

feed(data) {
data = clone(data);
Object.keys(data).forEach((key) => {

@@ -251,3 +253,3 @@ this[key] = data[key];

constructor(data) {
super(schema, data);
super(schema);

@@ -254,0 +256,0 @@ return new Proxy(this, new ModelHandler(schema, settings))

@@ -1,2 +0,2 @@

/*! smartModel v0.2.1 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).smartModel={})}(this,(function(e){"use strict";function t(e){return""===e||null==e}function n(e){return"function"==typeof e}function r(e){return Array.isArray(e)}function o(e){return e?JSON.parse(JSON.stringify(e)):e}function s(e,n,o){const s=[];if(e.required&&t(o))return s.push({message:`Invalid value 'required' on property '${n}'`,code:"required"}),s;if(void 0===o)return s;if(e.type){let c;const i=r(e.type)?e.type:[e.type];c=!(e.required||!t(o))||i.some((e=>typeof o==typeof e()||o instanceof e)),c||s.push({message:`Invalid type '${typeof o}' on property '${n}'`,code:"type"})}return e.rule&&Object.keys(e.rule).forEach((t=>{(0,e.rule[t])(o)&&s.push({message:`Invalid value '${t}' on property '${n}'`,code:t})})),s}class c extends Error{constructor(e){super(e.message),Object.assign(this,e)}}class i{constructor(e={},t={}){this.schema=e,this.settings=t}set(e,t,n){const r=this.schema,i=o(e[t]),f=(u=n,a=i,!(JSON.stringify(u)===JSON.stringify(a)));var u,a;const p=r[t];function d(o){return Reflect.apply(o,e,[t,n,i,r])}if(!p)return this.settings.strict||(e[t]=n),!0;if(d(e.onBeforeSet),f&&d(e.onBeforeUpdate),p.transform&&(n=p.transform(n)),this.settings.exceptions){const e=s(p,t,n);e.length&&e.forEach((e=>{throw new c({message:e.message,property:t,code:e.code})}))}return e[t]=n,d(e.onSet),f&&d(e.onUpdate),!0}get(e,t){const r=this.schema,o=r[t];let s=e[t];if(!o)return e[t];function c(t,n){return Reflect.apply(t,e,n)}return c(e.onBeforeGet,[t,s,r]),n(o)&&(s=c(o,[e])),n(o.format)&&(s=c(o.format,[s,e])),c(e.onGet,[t,s,r]),s}deleteProperty(e,t){const n=o(e[t]),r=this.schema;function s(t,n){return Reflect.apply(t,e,n)}if(r[t].required)throw new c({message:`Invalid delete on required propery ${t}`,property:t,code:"delete"});return Reflect.deleteProperty(e,t),s(e.onDelete,[t,n,r]),s(e.onUpdate,[t,undefined,r]),!0}}class f{constructor(e={},t={}){Object.keys(e).forEach((t=>{e[t].default&&(this[t]=e[t].default)})),this.feed(t)}feed(e){Object.keys(e).forEach((t=>{this[t]=e[t]}))}onSet(){}onGet(){}onDelete(){}onUpdate(){}onBeforeSet(){}onBeforeGet(){}onBeforeUpdate(){}}f.settings={strict:!1,exceptions:!0},f.create=function(e,t,n,o={}){o=Object.assign({},f.settings,o);const c={[e]:class extends f{constructor(e){return super(t,e),new Proxy(this,new i(t,o))}}}[e];return c.checkErrors=function(e,n){const r={};return Object.keys(t).forEach((o=>{const c=e[o];let i=s(t[o],o,c);i.length&&(n&&(i=i.filter((e=>!function(e){return[].concat([],e)}(n).includes(e.code)))),i.length&&(r[o]=i))})),!!Object.keys(r).length&&r},c.hydrate=function(e){return r(e)?e.map((e=>new c(e))):new c(e)},Object.assign(c.prototype,n),c},e.default=f,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! smartModel v0.2.2 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).smartModel={})}(this,(function(e){"use strict";function t(e){return""===e||null==e}function n(e){return"function"==typeof e}function r(e){return Array.isArray(e)}function o(e){return e?JSON.parse(JSON.stringify(e)):e}function s(e,n,o){const s=[];if(e.required&&t(o))return s.push({message:`Invalid value 'required' on property '${n}'`,code:"required"}),s;if(void 0===o)return s;if(e.type){let c;const i=r(e.type)?e.type:[e.type];c=!(e.required||!t(o))||i.some((e=>typeof o==typeof e()||o instanceof e)),c||s.push({message:`Invalid type '${typeof o}' on property '${n}'`,code:"type"})}return e.rule&&Object.keys(e.rule).forEach((t=>{(0,e.rule[t])(o)&&s.push({message:`Invalid value '${t}' on property '${n}'`,code:t})})),s}class c extends Error{constructor(e){super(e.message),Object.assign(this,e)}}class i{constructor(e={},t={}){this.schema=e,this.settings=t}set(e,t,n){const r=this.schema,i=o(e[t]),f=(u=n,a=i,!(JSON.stringify(u)===JSON.stringify(a)));var u,a;const p=r[t];function d(o){return Reflect.apply(o,e,[t,n,i,r])}if(!p)return this.settings.strict||(e[t]=n),!0;if(d(e.onBeforeSet),f&&d(e.onBeforeUpdate),p.transform&&(n=p.transform(n)),this.settings.exceptions){const e=s(p,t,n);e.length&&e.forEach((e=>{throw new c({message:e.message,property:t,code:e.code})}))}return e[t]=n,d(e.onSet),f&&d(e.onUpdate),!0}get(e,t){const r=this.schema,o=r[t];let s=e[t];if(!o)return e[t];function c(t,n){return Reflect.apply(t,e,n)}return c(e.onBeforeGet,[t,s,r]),n(o)&&(s=c(o,[e])),n(o.format)&&(s=c(o.format,[s,e])),c(e.onGet,[t,s,r]),s}deleteProperty(e,t){const n=o(e[t]),r=this.schema;function s(t,n){return Reflect.apply(t,e,n)}if(r[t].required)throw new c({message:`Invalid delete on required propery ${t}`,property:t,code:"delete"});return Reflect.deleteProperty(e,t),s(e.onDelete,[t,n,r]),s(e.onUpdate,[t,undefined,r]),!0}}class f{constructor(e={},t={}){Object.keys(e).forEach((t=>{e[t].default&&(this[t]=e[t].default)})),this.feed(t)}feed(e){e=o(e),Object.keys(e).forEach((t=>{this[t]=e[t]}))}onSet(){}onGet(){}onDelete(){}onUpdate(){}onBeforeSet(){}onBeforeGet(){}onBeforeUpdate(){}}f.settings={strict:!1,exceptions:!0},f.create=function(e,t,n,o={}){o=Object.assign({},f.settings,o);const c={[e]:class extends f{constructor(e){return super(t),new Proxy(this,new i(t,o))}}}[e];return c.checkErrors=function(e,n){const r={};return Object.keys(t).forEach((o=>{const c=e[o];let i=s(t[o],o,c);i.length&&(n&&(i=i.filter((e=>!function(e){return[].concat([],e)}(n).includes(e.code)))),i.length&&(r[o]=i))})),!!Object.keys(r).length&&r},c.hydrate=function(e){return r(e)?e.map((e=>new c(e))):new c(e)},Object.assign(c.prototype,n),c},e.default=f,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@jaysalvat/smart-model",
"version": "0.2.1",
"version": "0.2.2",
"description": "Javascript object model",

@@ -5,0 +5,0 @@ "main": "./build/smart-model.umd.js",

import { toArray, isArray, checkErrors } from './utils.js'
import { clone, toArray, isArray, checkErrors } from './utils.js'
import ModelHandler from './ModelHandler.js'

@@ -17,2 +17,4 @@

feed(data) {
data = clone(data)
Object.keys(data).forEach((key) => {

@@ -42,3 +44,3 @@ this[key] = data[key]

constructor(data) {
super(schema, data)
super(schema)

@@ -45,0 +47,0 @@ return new Proxy(this, new ModelHandler(schema, settings))

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc