Skip to content
Snippets Groups Projects
Commit 9df2e110 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

Merge branch 'MONSTER/-/591e9294-49e1-485b-b411-8c796e7ff048' into 'master'

Release 1.22.0

See merge request oss/libraries/javascript/monster!32
parents 8d49ffea 02427bf8
No related branches found
No related tags found
No related merge requests found
Showing
with 27 additions and 13 deletions
/** Monster 1.21.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isObject}from"../types/is.js";import{AbstractConstraint}from"./abstract.js";class IsObject extends AbstractConstraint{isValid(s){return isObject(s)?Promise.resolve(s):Promise.reject(s)}}assignToNamespace("Monster.Constraints",IsObject);export{Monster,IsObject};
\ No newline at end of file
/** Monster 1.21.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.Constraints";export{namespace};
\ No newline at end of file
/** Monster 1.21.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractOperator}from"./abstractoperator.js";class OrOperator extends AbstractOperator{isValid(s){var o=this;return new Promise(function(t,r){let a,e;o.operantA.isValid(s).then(function(){t()}).catch(function(){(a=!1)===e&&r()}),o.operantB.isValid(s).then(function(){t()}).catch(function(){(e=!1)===a&&r()})})}}assignToNamespace("Monster.Constraints",OrOperator);export{Monster,OrOperator};
\ No newline at end of file
/** Monster 1.21.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{AbstractConstraint}from"./abstract.js";class Valid extends AbstractConstraint{isValid(s){return Promise.resolve(s)}}assignToNamespace("Monster.Constraints",Valid);export{Monster,Valid};
\ No newline at end of file
/** Monster 1.21.1, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../namespace.js";import{isFunction,isObject,isString}from"../types/is.js";import{validateString}from"../types/validate.js";import{clone}from"../util/clone.js";import{DELIMITER,Pathfinder,WILDCARD}from"./pathfinder.js";function buildMap(t,e,a,n,r){const o=new Map;let i;if(isFunction(e)){if(i=e(t),!(i instanceof Map))throw new TypeError("the selector callback must return a map")}else{if(!isString(e))throw new TypeError("value is neither a string nor a function");i=new Map,buildFlatMap.call(i,t,e)}return i instanceof Map&&i.forEach((t,e,i)=>{isFunction(r)&&!0!==r.call(i,t,e)||(e=build(t,n,e),t=build(t,a),o.set(e,t))}),o}function buildFlatMap(i,t,a,n){var r=this;const o=new Map;var e=r.size;void 0===a&&(a=[]);let l=t.split(DELIMITER),s,p=[];do{if(s=l.shift(),p.push(s),s===WILDCARD){let t=new Pathfinder(i),e;try{e=t.getVia(p.join(DELIMITER))}catch(t){e=new Map}for(const[d,h]of e){let e=clone(a);p.map(t=>{e.push(t===WILDCARD?d:t)});var c=e.join(DELIMITER);let t=buildFlatMap.call(r,h,l.join(DELIMITER),e,h);isObject(t)&&(t["^"]=n),o.set(c,t)}}}while(0<l.length);if(e===r.size)for(var[f,u]of o)r.set(f,u);return i}function build(t,a,n){if(void 0===a)return n||t;validateString(a);const e=[...a.matchAll(/(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm)];let r=new Pathfinder(t);return 0===e.length?r.getVia(a):(e.forEach(e=>{var i=e?.groups,e=i?.placeholder;if(void 0!==e){i=i?.path;let t=r.getVia(i);void 0===t&&(t=n),a=a.replaceAll(e,t)}}),a)}assignToNamespace("Monster.Data",buildMap);export{Monster,buildMap};
\ No newline at end of file
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{PROPERTY_KEY_INTERNALDATA}from"../constants.js";import{assignToNamespace,Monster}from"../namespace.js";import{Base}from"../types/base.js";import{parseDataURL}from"../types/dataurl.js";import{isString}from"../types/is.js";import{clone}from"../util/clone.js";import{ProxyObserver}from"../types/proxyobserver.js";import{validateObject}from"../types/validate.js";import{extend}from"./extend.js";import{Pathfinder}from"./pathfinder.js";const internalDataSymbol=Symbol.for(PROPERTY_KEY_INTERNALDATA);class Datasource extends Base{constructor(){super(),this[internalDataSymbol]=new ProxyObserver({options:extend({},this.defaults),data:void 0})}get defaults(){return{}}setOption(t,e){return new Pathfinder(this[internalDataSymbol].getSubject().options).setVia(t,e),this}setOptions(t){isString(t)&&(t=parseOptionsJSON(t));var e=this;return extend(e[internalDataSymbol].getSubject().options,e.defaults,t),e}getOption(t,e){let r;try{r=new Pathfinder(this[internalDataSymbol].getRealSubject().options).getVia(t)}catch(t){}return void 0===r?e:r}read(){throw new Error("this method must be implemented by derived classes")}write(){throw new Error("this method must be implemented by derived classes")}get(){return clone(this[internalDataSymbol].getRealSubject().data)}set(t){return this[internalDataSymbol].getSubject().data=t,this}}function parseOptionsJSON(e){if(isString(e)){try{e=parseDataURL(e).content}catch(t){}try{var t=JSON.parse(e);return validateObject(t),t}catch(t){throw new Error("the options does not contain a valid json definition (actual: "+e+").")}}return{}}assignToNamespace("Monster.Data",Datasource);export{Monster,Datasource};
\ No newline at end of file
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";const namespace="Monster.Data.Datasource";export{namespace};
\ No newline at end of file
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../../namespace.js";import{isObject}from"../../types/is.js";import{Datasource}from"../datasource.js";class RestAPI extends Datasource{constructor(t,e){super();const s={};isObject(t)&&(s.read=t),isObject(e)&&(s.write=e),this.setOptions(s)}get defaults(){return Object.assign({},super.defaults,{write:{init:{method:"POST"},acceptedStatus:[200,201],url:void 0},read:{init:{method:"GET"},acceptedStatus:[200],url:void 0}})}read(){const s=this;let r,t=s.getOption("read.init");return isObject(t)||(t={}),fetch(s.getOption("read.url"),t).then(t=>{r=t;const e=s.getOption("read.acceptedStatus",[200]);if(-1===e.indexOf(t.status))throw Error("the data cannot be read (response "+t.status+")");return t.text()}).then(e=>{let t;try{t=JSON.parse(e)}catch(t){throw 100<e.length&&(e=e.substring(0,97)+"..."),new Error("the response does not contain a valid json (actual: "+e+").")}return s.set(t),r})}write(){const s=this;let t=s.getOption("write.init");return isObject(t)||(t={}),"object"!=typeof t.headers&&(t.headers={"Content-Type":"application/json"}),t.body=JSON.stringify(s.get()),fetch(s.getOption("write.url"),t).then(t=>{const e=s.getOption("write.acceptedStatus",[200,2001]);if(-1===e.indexOf(t.status))throw Error("the data cannot be written (response "+t.status+")");return t})}}assignToNamespace("Monster.Data.Datasource",RestAPI);export{Monster,RestAPI};
\ No newline at end of file
/** Monster 1.22.0, © 2021 schukai GmbH, Released under the AGPL 3.0 License. */
"use strict";import{assignToNamespace,Monster}from"../../namespace.js";import{validateString}from"../../types/validate.js";import{Datasource}from"../datasource.js";const storageObjectSymbol=Symbol("storageObject");class Storage extends Datasource{constructor(e){super(),this.setOption("key",validateString(e))}get defaults(){return Object.assign({},super.defaults,{key:void 0})}[storageObjectSymbol](){throw new Error("this method must be implemented by derived classes")}read(){const s=this,o=s[storageObjectSymbol]();return new Promise(function(e){var t=JSON.parse(o.getItem(s.getOption("key")));s.set(t),e()})}write(){const t=this,s=t[storageObjectSymbol]();return new Promise(function(e){void 0===t.get()?s.removeItem(t.getOption("key")):s.setItem(t.getOption("key"),JSON.stringify(t.get())),e()})}}assignToNamespace("Monster.Data.Datasource",Storage);export{Monster,Storage,storageObjectSymbol};
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment