wraplet 0.23.0 → 0.25.0
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/storage.cjs +1 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.js +1 -1
- package/dist/storage.js.map +1 -1
- package/package.json +1 -1
package/dist/storage.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={d:(e,s)=>{for(var
|
|
1
|
+
var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ElementStorage:()=>r});class s extends Error{}class r{element;attribute;defaults;validators;data;options;constructor(t,e,s,r,i={}){this.element=t,this.attribute=e,this.defaults=s,this.validators=r,this.options={keepFresh:!0,elementOptionsMerger:(t,e)=>({...t,...e}),...i},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(t,e){if(!this.validators[t](e))throw new s(`Attempted to set an invalid value for the key ${String(t)}.`);const r=this.getAttributeValue(this.attribute),i=JSON.parse(r);i[t]=e,this.setAll(i)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();t in e&&(delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e)))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.removeAttribute(this.attribute),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const t=this.getAttributeValue(this.attribute);if("{"!==t.charAt(0))throw new s("Data has to be defined as an object.");const e=JSON.parse(t);if(!this.validateData(e))throw new s("Invalid storage value.");return this.options.elementOptionsMerger(this.defaults,e)}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)||"{}"}}var i=exports;for(var l in e)i[l]=e[l];e.__esModule&&Object.defineProperty(i,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=storage.cjs.map
|
package/dist/storage.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,0CCGhD,MAAMC,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,SACAC,WACAC,KACAC,QACA,WAAAC,CAAYN,EAASC,EAAWC,EAAUC,EAAYE,EAAU,CAAC,GAC7DE,KAAKP,QAAUA,EACfO,KAAKN,UAAYA,EACjBM,KAAKL,SAAWA,EAChBK,KAAKJ,WAAaA,EAClBI,KAAKF,QAAU,CACXG,WAAW,EACXC,qBAAsB,CAACC,EAAgBC,KAC5B,IAAKD,KAAmBC,OAEhCN,GAEPE,KAAKH,KAAOG,KAAKK,gBACrB,CACA,GAAAC,CAAI9B,GAEA,OAAOA,KADMwB,KAAKO,QAEtB,CACA,GAAA1B,CAAIL,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BAErC,OAAOU,KAAKF,QAAQI,qBAAqBF,KAAKL,SAAUE,EAC5D,CACA,YAAAgC,CAAahC,GACT,IAAK,MAAMrB,KAAOqB,EACd,IAAKG,KAAKJ,WAAWpB,GAAKqB,EAAKrB,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAAwC,CAAkBtB,GACd,OAAOM,KAAKP,QAAQqC,aAAapC,IAAc,IACnD,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n defaults;\n validators;\n data;\n options;\n constructor(element, attribute, defaults, validators, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = this.getAttributeValue(this.attribute);\n const data = JSON.parse(attributeValue);\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.removeAttribute(this.attribute);\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute) || \"{}\";\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","StorageValidationError","Error","ElementStorage","element","attribute","defaults","validators","data","options","constructor","this","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","fetchFreshData","has","getAll","getMultiple","keys","reduce","acc","refresh","set","String","attributeValue","getAttributeValue","JSON","parse","setAll","setMultiple","oldData","setAttribute","stringify","deleteMultiple","deleteAll","removeAttribute","dataString","charAt","validateData","getAttribute"],"sourceRoot":""}
|
package/dist/storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e{element;attribute;defaults;validators;data;options;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.defaults=s,this.validators=i,this.options={keepFresh:!0,elementOptionsMerger:(t,e)=>({...t,...e}),...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(e,s){
|
|
1
|
+
class t extends Error{}class e{element;attribute;defaults;validators;data;options;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.defaults=s,this.validators=i,this.options={keepFresh:!0,elementOptionsMerger:(t,e)=>({...t,...e}),...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(e,s){if(!this.validators[e](s))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`);const i=this.getAttributeValue(this.attribute),r=JSON.parse(i);r[e]=s,this.setAll(r)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();t in e&&(delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e)))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.removeAttribute(this.attribute),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const e=this.getAttributeValue(this.attribute);if("{"!==e.charAt(0))throw new t("Data has to be defined as an object.");const s=JSON.parse(e);if(!this.validateData(s))throw new t("Invalid storage value.");return this.options.elementOptionsMerger(this.defaults,s)}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)||"{}"}}export{e as ElementStorage};
|
|
2
2
|
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","mappings":"AAQO,MAAMA,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,SACAC,WACAC,KACAC,QACA,WAAAC,CAAYN,EAASC,EAAWC,EAAUC,EAAYE,EAAU,CAAC,GAC7DE,KAAKP,QAAUA,EACfO,KAAKN,UAAYA,EACjBM,KAAKL,SAAWA,EAChBK,KAAKJ,WAAaA,EAClBI,KAAKF,QAAU,CACXG,WAAW,EACXC,qBAAsB,CAACC,EAAgBC,KAC5B,IAAKD,KAAmBC,OAEhCN,GAEPE,KAAKH,KAAOG,KAAKK,gBACrB,CACA,GAAAC,CAAIC,GAEA,OAAOA,KADMP,KAAKQ,QAEtB,CACA,GAAAC,CAAIF,GAEA,OADaP,KAAKQ,SACND,EAChB,CACA,WAAAG,CAAYC,GACR,MAAMd,EAAOG,KAAKQ,SAClB,OAAOG,EAAKC,OAAO,CAACC,EAAKN,KACrBM,EAAIN,GAAOV,EAAKU,GACTM,GACR,CAAC,EACR,CACA,MAAAL,GAII,OAHIR,KAAKF,QAAQG,WACbD,KAAKc,UAEFd,KAAKH,IAChB,CACA,GAAAkB,CAAIR,EAAKS,GACL,
|
|
1
|
+
{"version":3,"file":"storage.js","mappings":"AAQO,MAAMA,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,SACAC,WACAC,KACAC,QACA,WAAAC,CAAYN,EAASC,EAAWC,EAAUC,EAAYE,EAAU,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GACI5B,KAAKP,QAAQoC,gBAAgB7B,KAAKN,WAClCM,KAAKc,SACT,CACA,OAAAA,GACId,KAAKH,KAAOG,KAAKK,gBACrB,CACA,cAAAA,GACI,MAAMyB,EAAa9B,KAAKmB,kBAAkBnB,KAAKN,WAC/C,GAA6B,MAAzBoC,EAAWC,OAAO,GAClB,MAAM,IAAIzC,EAAuB,wCAErC,MAAMO,EAAOuB,KAAKC,MAAMS,GACxB,IAAK9B,KAAKgC,aAAanC,GACnB,MAAM,IAAIP,EAAuB,0BAErC,OAAOU,KAAKF,QAAQI,qBAAqBF,KAAKL,SAAUE,EAC5D,CACA,YAAAmC,CAAanC,GACT,IAAK,MAAMU,KAAOV,EACd,IAAKG,KAAKJ,WAAWW,GAAKV,EAAKU,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAAY,CAAkBzB,GACd,OAAOM,KAAKP,QAAQwC,aAAavC,IAAc,IACnD,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n defaults;\n validators;\n data;\n options;\n constructor(element, attribute, defaults, validators, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = this.getAttributeValue(this.attribute);\n const data = JSON.parse(attributeValue);\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.removeAttribute(this.attribute);\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute) || \"{}\";\n }\n}\n"],"names":["StorageValidationError","Error","ElementStorage","element","attribute","defaults","validators","data","options","constructor","this","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","fetchFreshData","has","key","getAll","get","getMultiple","keys","reduce","acc","refresh","set","value","String","attributeValue","getAttributeValue","JSON","parse","setAll","setMultiple","oldData","setAttribute","stringify","deleteMultiple","deleteAll","removeAttribute","dataString","charAt","validateData","getAttribute"],"sourceRoot":""}
|