merge
This commit is contained in:
commit
c6cafeb2c0
|
@ -40,4 +40,4 @@ flow-typed/npm/*
|
|||
|
||||
.idea
|
||||
npm-debug.log.*
|
||||
dist
|
||||
lib
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/common/compileCode.js"],"names":["compileCode","code","func","safeCode","trimmed","trim","endsWith","substring","length","e","message"],"mappings":"wGAAA;AACA;;AAEO,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAAAC,IAAI,EAAI;AACjC,MAAIC,IAAJ;AACA,MAAIC,QAAJ;;AAEA,MAAI,kBAAS,SAAT,EAAoBF,IAApB,CAAJ,EAA+B;AAC7BE,IAAAA,QAAQ,GAAGF,IAAX;AACD,GAFD,MAEO;AACL,QAAIG,OAAO,GAAGH,IAAI,CAACI,IAAL,EAAd;AACAD,IAAAA,OAAO,GAAGA,OAAO,CAACE,QAAR,CAAiB,GAAjB;AACNF,IAAAA,OAAO,CAACG,SAAR,CAAkB,CAAlB,EAAqBH,OAAO,CAACI,MAAR,GAAiB,CAAtC,CADM;AAENJ,IAAAA,OAFJ;AAGAD,IAAAA,QAAQ,qBAAcC,OAAd,MAAR;AACD;;AAED,MAAI;AACFF,IAAAA,IAAI,GAAG,+BAAMC,QAAN,CAAP;AACD,GAFD,CAEE,OAAOM,CAAP,EAAU;AACVA,IAAAA,CAAC,CAACC,OAAF,oCAAsCT,IAAtC,gBAAgDQ,CAAC,CAACC,OAAlD;AACA,UAAMD,CAAN;AACD;;AAED,SAAOP,IAAP;AACD,CAtBM,C","sourcesContent":["import { compileCode as cCode } from \"@nx-js/compiler-util\"\nimport { includes } from \"lodash/fp\"\n\nexport const compileCode = code => {\n let func\n let safeCode\n\n if (includes(\"return \")(code)) {\n safeCode = code\n } else {\n let trimmed = code.trim()\n trimmed = trimmed.endsWith(\";\")\n ? trimmed.substring(0, trimmed.length - 1)\n : trimmed\n safeCode = `return (${trimmed})`\n }\n\n try {\n func = cCode(safeCode)\n } catch (e) {\n e.message = `Error compiling code : ${code} : ${e.message}`\n throw e\n }\n\n return func\n}\n"],"file":"compileCode.js"}
|
||||
{"version":3,"sources":["../../src/common/compileCode.js"],"names":["compileCode","code","func","safeCode","trimmed","trim","endsWith","substring","length","e","message"],"mappings":"wGAAA;AACA;;AAEO,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAAAC,IAAI,EAAI;AACjC,MAAIC,IAAJ;AACA,MAAIC,QAAJ;;AAEA,MAAI,kBAAS,SAAT,EAAoBF,IAApB,CAAJ,EAA+B;AAC7BE,IAAAA,QAAQ,GAAGF,IAAX;AACD,GAFD,MAEO;AACL,QAAIG,OAAO,GAAGH,IAAI,CAACI,IAAL,EAAd;AACAD,IAAAA,OAAO,GAAGA,OAAO,CAACE,QAAR,CAAiB,GAAjB;AACNF,IAAAA,OAAO,CAACG,SAAR,CAAkB,CAAlB,EAAqBH,OAAO,CAACI,MAAR,GAAiB,CAAtC,CADM;AAENJ,IAAAA,OAFJ;AAGAD,IAAAA,QAAQ,qBAAcC,OAAd,MAAR;AACD;;AAED,MAAI;AACFF,IAAAA,IAAI,GAAG,+BAAMC,QAAN,CAAP;AACD,GAFD,CAEE,OAAOM,CAAP,EAAU;AACVA,IAAAA,CAAC,CAACC,OAAF,oCAAsCT,IAAtC,gBAAgDQ,CAAC,CAACC,OAAlD;AACA,UAAMD,CAAN;AACD;;AAED,SAAOP,IAAP;AACD,CAtBM,C","sourcesContent":["import { compileCode as cCode } from \"@nx-js/compiler-util\"\r\nimport { includes } from \"lodash/fp\"\r\n\r\nexport const compileCode = code => {\r\n let func\r\n let safeCode\r\n\r\n if (includes(\"return \")(code)) {\r\n safeCode = code\r\n } else {\r\n let trimmed = code.trim()\r\n trimmed = trimmed.endsWith(\";\")\r\n ? trimmed.substring(0, trimmed.length - 1)\r\n : trimmed\r\n safeCode = `return (${trimmed})`\r\n }\r\n\r\n try {\r\n func = cCode(safeCode)\r\n } catch (e) {\r\n e.message = `Error compiling code : ${code} : ${e.message}`\r\n throw e\r\n }\r\n\r\n return func\r\n}\r\n"],"file":"compileCode.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/common/errors.js"],"names":["BadRequestError","message","httpStatusCode","Error","UnauthorisedError","ForbiddenError","NotFoundError","ConflictError"],"mappings":"i9CAAaA,e;AACX,2BAAYC,OAAZ,EAAqB;AACnB,8BAAMA,OAAN;AACA,UAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,yEAJkCC,K;;;AAOxBC,iB;AACX,6BAAYH,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,2EAJoCC,K;;;AAO1BE,c;AACX,0BAAYJ,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,wEAJiCC,K;;;AAOvBG,a;AACX,yBAAYL,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,uEAJgCC,K;;;AAOtBI,a;AACX,yBAAYN,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,uEAJgCC,K","sourcesContent":["export class BadRequestError extends Error {\n constructor(message) {\n super(message)\n this.httpStatusCode = 400\n }\n}\n\nexport class UnauthorisedError extends Error {\n constructor(message) {\n super(message)\n this.httpStatusCode = 401\n }\n}\n\nexport class ForbiddenError extends Error {\n constructor(message) {\n super(message)\n this.httpStatusCode = 403\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message) {\n super(message)\n this.httpStatusCode = 404\n }\n}\n\nexport class ConflictError extends Error {\n constructor(message) {\n super(message)\n this.httpStatusCode = 409\n }\n}\n"],"file":"errors.js"}
|
||||
{"version":3,"sources":["../../src/common/errors.js"],"names":["BadRequestError","message","httpStatusCode","Error","UnauthorisedError","ForbiddenError","NotFoundError","ConflictError"],"mappings":"i9CAAaA,e;AACX,2BAAYC,OAAZ,EAAqB;AACnB,8BAAMA,OAAN;AACA,UAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,yEAJkCC,K;;;AAOxBC,iB;AACX,6BAAYH,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,2EAJoCC,K;;;AAO1BE,c;AACX,0BAAYJ,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,wEAJiCC,K;;;AAOvBG,a;AACX,yBAAYL,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,uEAJgCC,K;;;AAOtBI,a;AACX,yBAAYN,OAAZ,EAAqB;AACnB,gCAAMA,OAAN;AACA,WAAKC,cAAL,GAAsB,GAAtB,CAFmB;AAGpB,G,uEAJgCC,K","sourcesContent":["export class BadRequestError extends Error {\r\n constructor(message) {\r\n super(message)\r\n this.httpStatusCode = 400\r\n }\r\n}\r\n\r\nexport class UnauthorisedError extends Error {\r\n constructor(message) {\r\n super(message)\r\n this.httpStatusCode = 401\r\n }\r\n}\r\n\r\nexport class ForbiddenError extends Error {\r\n constructor(message) {\r\n super(message)\r\n this.httpStatusCode = 403\r\n }\r\n}\r\n\r\nexport class NotFoundError extends Error {\r\n constructor(message) {\r\n super(message)\r\n this.httpStatusCode = 404\r\n }\r\n}\r\n\r\nexport class ConflictError extends Error {\r\n constructor(message) {\r\n super(message)\r\n this.httpStatusCode = 409\r\n }\r\n}\r\n"],"file":"errors.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/common/eventAggregator.js"],"names":["publish","handlers","eventName","context","handler","subscribe","push","createEventAggregator","eventAggregator"],"mappings":"iZAAA,+B;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAAAC,QAAQ,6HAAI,iBAAOC,SAAP,oLAAkBC,OAAlB,2DAA4B,EAA5B;AACrB,2BAAID,SAAJ,EAAeD,QAAf,CADqB;;AAGJA,cAAAA,QAAQ,CAACC,SAAD,CAHJ,sGAGfE,OAHe;AAIlBA,gBAAAA,OAAO,CAACF,SAAD,EAAYC,OAAZ,CAJW,gTAAJ,mEAAxB;;;;AAQA,IAAME,SAAS,GAAG,SAAZA,SAAY,CAAAJ,QAAQ,UAAI,UAACC,SAAD,EAAYE,OAAZ,EAAwB;AACpD,QAAI,CAAC,aAAIF,SAAJ,EAAeD,QAAf,CAAL,EAA+B;AAC7BA,MAAAA,QAAQ,CAACC,SAAD,CAAR,GAAsB,EAAtB;AACD;AACDD,IAAAA,QAAQ,CAACC,SAAD,CAAR,CAAoBI,IAApB,CAAyBF,OAAzB;AACD,GALyB,EAA1B;;AAOO,IAAMG,qBAAqB,GAAG,SAAxBA,qBAAwB,GAAM;AACzC,MAAMN,QAAQ,GAAG,EAAjB;AACA,MAAMO,eAAe,GAAG;AACtBR,IAAAA,OAAO,EAAEA,OAAO,CAACC,QAAD,CADM;AAEtBI,IAAAA,SAAS,EAAEA,SAAS,CAACJ,QAAD,CAFE,EAAxB;;AAIA,SAAOO,eAAP;AACD,CAPM,C;;AASQD,qB","sourcesContent":["import { has } from \"lodash/fp\"\n\nconst publish = handlers => async (eventName, context = {}) => {\n if (!has(eventName)(handlers)) return\n\n for (const handler of handlers[eventName]) {\n await handler(eventName, context)\n }\n}\n\nconst subscribe = handlers => (eventName, handler) => {\n if (!has(eventName)(handlers)) {\n handlers[eventName] = []\n }\n handlers[eventName].push(handler)\n}\n\nexport const createEventAggregator = () => {\n const handlers = {}\n const eventAggregator = {\n publish: publish(handlers),\n subscribe: subscribe(handlers),\n }\n return eventAggregator\n}\n\nexport default createEventAggregator\n"],"file":"eventAggregator.js"}
|
||||
{"version":3,"sources":["../../src/common/eventAggregator.js"],"names":["publish","handlers","eventName","context","handler","subscribe","push","createEventAggregator","eventAggregator"],"mappings":"iZAAA,+B;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAAAC,QAAQ,6HAAI,iBAAOC,SAAP,oLAAkBC,OAAlB,2DAA4B,EAA5B;AACrB,2BAAID,SAAJ,EAAeD,QAAf,CADqB;;AAGJA,cAAAA,QAAQ,CAACC,SAAD,CAHJ,sGAGfE,OAHe;AAIlBA,gBAAAA,OAAO,CAACF,SAAD,EAAYC,OAAZ,CAJW,gTAAJ,mEAAxB;;;;AAQA,IAAME,SAAS,GAAG,SAAZA,SAAY,CAAAJ,QAAQ,UAAI,UAACC,SAAD,EAAYE,OAAZ,EAAwB;AACpD,QAAI,CAAC,aAAIF,SAAJ,EAAeD,QAAf,CAAL,EAA+B;AAC7BA,MAAAA,QAAQ,CAACC,SAAD,CAAR,GAAsB,EAAtB;AACD;AACDD,IAAAA,QAAQ,CAACC,SAAD,CAAR,CAAoBI,IAApB,CAAyBF,OAAzB;AACD,GALyB,EAA1B;;AAOO,IAAMG,qBAAqB,GAAG,SAAxBA,qBAAwB,GAAM;AACzC,MAAMN,QAAQ,GAAG,EAAjB;AACA,MAAMO,eAAe,GAAG;AACtBR,IAAAA,OAAO,EAAEA,OAAO,CAACC,QAAD,CADM;AAEtBI,IAAAA,SAAS,EAAEA,SAAS,CAACJ,QAAD,CAFE,EAAxB;;AAIA,SAAOO,eAAP;AACD,CAPM,C;;AASQD,qB","sourcesContent":["import { has } from \"lodash/fp\"\r\n\r\nconst publish = handlers => async (eventName, context = {}) => {\r\n if (!has(eventName)(handlers)) return\r\n\r\n for (const handler of handlers[eventName]) {\r\n await handler(eventName, context)\r\n }\r\n}\r\n\r\nconst subscribe = handlers => (eventName, handler) => {\r\n if (!has(eventName)(handlers)) {\r\n handlers[eventName] = []\r\n }\r\n handlers[eventName].push(handler)\r\n}\r\n\r\nexport const createEventAggregator = () => {\r\n const handlers = {}\r\n const eventAggregator = {\r\n publish: publish(handlers),\r\n subscribe: subscribe(handlers),\r\n }\r\n return eventAggregator\r\n}\r\n\r\nexport default createEventAggregator\r\n"],"file":"eventAggregator.js"}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/common/validationCommon.js"],"names":["stringNotEmpty","s","trim","length","makerule","field","error","isValid","validationError","rule","item","applyRuleSet","ruleSet","itemToValidate","applyRule","isSomething","itemTovalidate"],"mappings":"wXAAA;AACA,gC;;AAEO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,CAAC,UAAI,wBAAYA,CAAZ,KAAkBA,CAAC,CAACC,IAAF,GAASC,MAAT,GAAkB,CAAxC,EAAxB,C;;AAEA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,KAAD,EAAQC,KAAR,EAAeC,OAAf,UAA4B,EAAEF,KAAK,EAALA,KAAF,EAASC,KAAK,EAALA,KAAT,EAAgBC,OAAO,EAAPA,OAAhB,EAA5B,EAAjB,C;;AAEA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,IAAD,EAAOC,IAAP,4BAAsBD,IAAtB,IAA4BC,IAAI,EAAJA,IAA5B,KAAxB,C;;AAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAAAC,OAAO,UAAI,UAAAC,cAAc;AACnD,oBAAED,OAAF,EAAW,CAAC,aAAIE,SAAS,CAACD,cAAD,CAAb,CAAD,EAAiC,gBAAOE,kBAAP,CAAjC,CAAX,CADmD,GAAlB,EAA5B,C;;AAGA,IAAMD,SAAS,GAAG,SAAZA,SAAY,CAAAE,cAAc,UAAI,UAAAP,IAAI;AAC7CA,MAAAA,IAAI,CAACF,OAAL,CAAaS,cAAb,IAA+B,IAA/B,GAAsCR,eAAe,CAACC,IAAD,EAAOO,cAAP,CADR,GAAR,EAAhC,C","sourcesContent":["import { filter, map } from \"lodash/fp\"\nimport { $, isSomething } from \"./index\"\n\nexport const stringNotEmpty = s => isSomething(s) && s.trim().length > 0\n\nexport const makerule = (field, error, isValid) => ({ field, error, isValid })\n\nexport const validationError = (rule, item) => ({ ...rule, item })\n\nexport const applyRuleSet = ruleSet => itemToValidate =>\n $(ruleSet, [map(applyRule(itemToValidate)), filter(isSomething)])\n\nexport const applyRule = itemTovalidate => rule =>\n rule.isValid(itemTovalidate) ? null : validationError(rule, itemTovalidate)\n"],"file":"validationCommon.js"}
|
||||
{"version":3,"sources":["../../src/common/validationCommon.js"],"names":["stringNotEmpty","s","trim","length","makerule","field","error","isValid","validationError","rule","item","applyRuleSet","ruleSet","itemToValidate","applyRule","isSomething","itemTovalidate"],"mappings":"wXAAA;AACA,gC;;AAEO,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,CAAC,UAAI,wBAAYA,CAAZ,KAAkBA,CAAC,CAACC,IAAF,GAASC,MAAT,GAAkB,CAAxC,EAAxB,C;;AAEA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,KAAD,EAAQC,KAAR,EAAeC,OAAf,UAA4B,EAAEF,KAAK,EAALA,KAAF,EAASC,KAAK,EAALA,KAAT,EAAgBC,OAAO,EAAPA,OAAhB,EAA5B,EAAjB,C;;AAEA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,IAAD,EAAOC,IAAP,4BAAsBD,IAAtB,IAA4BC,IAAI,EAAJA,IAA5B,KAAxB,C;;AAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe,CAAAC,OAAO,UAAI,UAAAC,cAAc;AACnD,oBAAED,OAAF,EAAW,CAAC,aAAIE,SAAS,CAACD,cAAD,CAAb,CAAD,EAAiC,gBAAOE,kBAAP,CAAjC,CAAX,CADmD,GAAlB,EAA5B,C;;AAGA,IAAMD,SAAS,GAAG,SAAZA,SAAY,CAAAE,cAAc,UAAI,UAAAP,IAAI;AAC7CA,MAAAA,IAAI,CAACF,OAAL,CAAaS,cAAb,IAA+B,IAA/B,GAAsCR,eAAe,CAACC,IAAD,EAAOO,cAAP,CADR,GAAR,EAAhC,C","sourcesContent":["import { filter, map } from \"lodash/fp\"\r\nimport { $, isSomething } from \"./index\"\r\n\r\nexport const stringNotEmpty = s => isSomething(s) && s.trim().length > 0\r\n\r\nexport const makerule = (field, error, isValid) => ({ field, error, isValid })\r\n\r\nexport const validationError = (rule, item) => ({ ...rule, item })\r\n\r\nexport const applyRuleSet = ruleSet => itemToValidate =>\r\n $(ruleSet, [map(applyRule(itemToValidate)), filter(isSomething)])\r\n\r\nexport const applyRule = itemTovalidate => rule =>\r\n rule.isValid(itemTovalidate) ? null : validationError(rule, itemTovalidate)\r\n"],"file":"validationCommon.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"kpBAAA;AACA;AACA;AACA","sourcesContent":["export { validateRecord } from \"./records/validateRecord\";\nexport { events } from \"./common/events\";\nexport { safeParseField } from \"./schema/types\";\nexport { default as schemaValidator } from \"./schemaValidation\";"],"file":"index.js"}
|
||||
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"kpBAAA;AACA;AACA;AACA","sourcesContent":["export { validateRecord } from \"./records/validateRecord\";\r\nexport { events } from \"./common/events\";\r\nexport { safeParseField } from \"./schema/types\";\r\nexport { default as schemaValidator } from \"./schemaValidation\";"],"file":"index.js"}
|
|
@ -1,17 +1,16 @@
|
|||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.getNewRecord = void 0;var _shortid = require("shortid");
|
||||
var _types = require("../schema/types");function _createForOfIteratorHelper(o) {if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) {var i = 0;var F = function F() {};return { s: F, n: function n() {if (i >= o.length) return { done: true };return { done: false, value: o[i++] };}, e: function e(_e) {throw _e;}, f: F };}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var it,normalCompletion = true,didErr = false,err;return { s: function s() {it = o[Symbol.iterator]();}, n: function n() {var step = it.next();normalCompletion = step.done;return step;}, e: function e(_e2) {didErr = true;err = _e2;}, f: function f() {try {if (!normalCompletion && it["return"] != null) it["return"]();} finally {if (didErr) throw err;}} };}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(n);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}
|
||||
|
||||
var getNewRecord = function getNewRecord(schema, modelName) {
|
||||
var model = schema.findModel(modelName);
|
||||
|
||||
var record = {
|
||||
_id: (0, _shortid.generate)(),
|
||||
_modelId: model.id };var _iterator = _createForOfIteratorHelper(
|
||||
modelId: model._id };
|
||||
|
||||
|
||||
model.fields),_step;try {for (_iterator.s(); !(_step = _iterator.n()).done;) {var field = _step.value;
|
||||
record[field.name] = (0, _types.getNewFieldValue)(field);
|
||||
}} catch (err) {_iterator.e(err);} finally {_iterator.f();}
|
||||
for (var field in model.schema.properties) {
|
||||
record[field] = field["default"];
|
||||
}
|
||||
|
||||
return record;
|
||||
};exports.getNewRecord = getNewRecord;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/records/getNewRecord.js"],"names":["getNewRecord","schema","modelName","model","findModel","record","_id","_modelId","id","fields","field","name"],"mappings":"yGAAA;AACA,wC;;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,MAAD,EAASC,SAAT,EAAuB;AACjD,MAAMC,KAAK,GAAGF,MAAM,CAACG,SAAP,CAAiBF,SAAjB,CAAd;;AAEA,MAAMG,MAAM,GAAG;AACbC,IAAAA,GAAG,EAAE,wBADQ;AAEbC,IAAAA,QAAQ,EAAEJ,KAAK,CAACK,EAFH,EAAf,CAHiD;;;AAQ/BL,EAAAA,KAAK,CAACM,MARyB,aAQjD,oDAAgC,KAAvBC,KAAuB;AAC9BL,MAAAA,MAAM,CAACK,KAAK,CAACC,IAAP,CAAN,GAAqB,6BAAiBD,KAAjB,CAArB;AACD,KAVgD;;AAYjD,SAAOL,MAAP;AACD,CAbM,C","sourcesContent":["import { generate } from \"shortid\"\nimport { getNewFieldValue } from \"../schema/types\"\n\nexport const getNewRecord = (schema, modelName) => {\n const model = schema.findModel(modelName)\n\n const record = {\n _id: generate(),\n _modelId: model.id,\n }\n\n for (let field of model.fields) {\n record[field.name] = getNewFieldValue(field)\n }\n\n return record\n}\n"],"file":"getNewRecord.js"}
|
||||
{"version":3,"sources":["../../src/records/getNewRecord.js"],"names":["getNewRecord","schema","modelName","model","findModel","record","_id","modelId","field","properties"],"mappings":"yGAAA;;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,MAAD,EAASC,SAAT,EAAuB;AACjD,MAAMC,KAAK,GAAGF,MAAM,CAACG,SAAP,CAAiBF,SAAjB,CAAd;;AAEA,MAAMG,MAAM,GAAG;AACbC,IAAAA,GAAG,EAAE,wBADQ;AAEbC,IAAAA,OAAO,EAAEJ,KAAK,CAACG,GAFF,EAAf;;;AAKA,OAAK,IAAIE,KAAT,IAAkBL,KAAK,CAACF,MAAN,CAAaQ,UAA/B,EAA2C;AACzCJ,IAAAA,MAAM,CAACG,KAAD,CAAN,GAAgBA,KAAK,WAArB;AACD;;AAED,SAAOH,MAAP;AACD,CAbM,C","sourcesContent":["import { generate } from \"shortid\"\r\n\r\nexport const getNewRecord = (schema, modelName) => {\r\n const model = schema.findModel(modelName)\r\n\r\n const record = {\r\n _id: generate(),\r\n modelId: model._id,\r\n }\r\n\r\n for (let field in model.schema.properties) {\r\n record[field] = field.default\r\n }\r\n\r\n return record\r\n}\r\n"],"file":"getNewRecord.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/records/recordValidationRules.js"],"names":["getNewRecordValidationRule","invalidField","messageWhenInvalid","expressionWhenValid","commonRecordValidationRules","fieldNotEmpty","fieldName","fieldBetween","min","max","toString","fieldGreaterThan"],"mappings":"6JAAO,IAAMA,0BAA0B,GAAG,SAA7BA,0BAA6B;AACxCC,YADwC;AAExCC,kBAFwC;AAGxCC,mBAHwC;AAIpC;AACJF,MAAAA,YAAY,EAAZA,YADI;AAEJC,MAAAA,kBAAkB,EAAlBA,kBAFI;AAGJC,MAAAA,mBAAmB,EAAnBA,mBAHI,EAJoC,GAAnC,C;;;AAUA,IAAMC,2BAA2B,GAAG;AACzCC,EAAAA,aAAa,EAAE,uBAAAC,SAAS;AACtBN,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB;AAGbA,MAAAA,SAHa,2BAGaA,SAHb,mBADJ,GADiB;;;AAQzCC,EAAAA,YAAY,EAAE,sBAACD,SAAD,EAAYE,GAAZ,EAAiBC,GAAjB;AACZT,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB,8BAEQE,GAAG,CAACE,QAAJ,EAFR,kBAE8BD,GAAG,CAACC,QAAJ,EAF9B;AAGbJ,MAAAA,SAHa,mBAGKE,GAHL,0BAGwBF,SAHxB,mBAG0CG,GAH1C,OADd,GAR2B;;;AAezCE,EAAAA,gBAAgB,EAAE,0BAACL,SAAD,EAAYE,GAAZ,EAAiBC,GAAjB;AAChBT,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB,mCAEaE,GAAG,CAACE,QAAJ,EAFb,kBAEmCD,GAAG,CAACC,QAAJ,EAFnC;AAGbJ,MAAAA,SAHa,mBAGKE,GAHL,QADV,GAfuB,EAApC,C","sourcesContent":["export const getNewRecordValidationRule = (\n invalidField,\n messageWhenInvalid,\n expressionWhenValid\n) => ({\n invalidField,\n messageWhenInvalid,\n expressionWhenValid,\n})\n\nexport const commonRecordValidationRules = {\n fieldNotEmpty: fieldName =>\n getNewRecordValidationRule(\n fieldName,\n `${fieldName} is empty`,\n `record['${fieldName}'] && record['${fieldName}'].length > 0`\n ),\n\n fieldBetween: (fieldName, min, max) =>\n getNewRecordValidationRule(\n fieldName,\n `${fieldName} must be between ${min.toString()} and ${max.toString()}`,\n `record['${fieldName}'] >= ${min} && record['${fieldName}'] <= ${max} `\n ),\n\n fieldGreaterThan: (fieldName, min, max) =>\n getNewRecordValidationRule(\n fieldName,\n `${fieldName} must be greater than ${min.toString()} and ${max.toString()}`,\n `record['${fieldName}'] >= ${min} `\n ),\n}\n"],"file":"recordValidationRules.js"}
|
||||
{"version":3,"sources":["../../src/records/recordValidationRules.js"],"names":["getNewRecordValidationRule","invalidField","messageWhenInvalid","expressionWhenValid","commonRecordValidationRules","fieldNotEmpty","fieldName","fieldBetween","min","max","toString","fieldGreaterThan"],"mappings":"6JAAO,IAAMA,0BAA0B,GAAG,SAA7BA,0BAA6B;AACxCC,YADwC;AAExCC,kBAFwC;AAGxCC,mBAHwC;AAIpC;AACJF,MAAAA,YAAY,EAAZA,YADI;AAEJC,MAAAA,kBAAkB,EAAlBA,kBAFI;AAGJC,MAAAA,mBAAmB,EAAnBA,mBAHI,EAJoC,GAAnC,C;;;AAUA,IAAMC,2BAA2B,GAAG;AACzCC,EAAAA,aAAa,EAAE,uBAAAC,SAAS;AACtBN,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB;AAGbA,MAAAA,SAHa,2BAGaA,SAHb,mBADJ,GADiB;;;AAQzCC,EAAAA,YAAY,EAAE,sBAACD,SAAD,EAAYE,GAAZ,EAAiBC,GAAjB;AACZT,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB,8BAEQE,GAAG,CAACE,QAAJ,EAFR,kBAE8BD,GAAG,CAACC,QAAJ,EAF9B;AAGbJ,MAAAA,SAHa,mBAGKE,GAHL,0BAGwBF,SAHxB,mBAG0CG,GAH1C,OADd,GAR2B;;;AAezCE,EAAAA,gBAAgB,EAAE,0BAACL,SAAD,EAAYE,GAAZ,EAAiBC,GAAjB;AAChBT,MAAAA,0BAA0B;AACxBM,MAAAA,SADwB;AAErBA,MAAAA,SAFqB,mCAEaE,GAAG,CAACE,QAAJ,EAFb,kBAEmCD,GAAG,CAACC,QAAJ,EAFnC;AAGbJ,MAAAA,SAHa,mBAGKE,GAHL,QADV,GAfuB,EAApC,C","sourcesContent":["export const getNewRecordValidationRule = (\r\n invalidField,\r\n messageWhenInvalid,\r\n expressionWhenValid\r\n) => ({\r\n invalidField,\r\n messageWhenInvalid,\r\n expressionWhenValid,\r\n})\r\n\r\nexport const commonRecordValidationRules = {\r\n fieldNotEmpty: fieldName =>\r\n getNewRecordValidationRule(\r\n fieldName,\r\n `${fieldName} is empty`,\r\n `record['${fieldName}'] && record['${fieldName}'].length > 0`\r\n ),\r\n\r\n fieldBetween: (fieldName, min, max) =>\r\n getNewRecordValidationRule(\r\n fieldName,\r\n `${fieldName} must be between ${min.toString()} and ${max.toString()}`,\r\n `record['${fieldName}'] >= ${min} && record['${fieldName}'] <= ${max} `\r\n ),\r\n\r\n fieldGreaterThan: (fieldName, min, max) =>\r\n getNewRecordValidationRule(\r\n fieldName,\r\n `${fieldName} must be greater than ${min.toString()} and ${max.toString()}`,\r\n `record['${fieldName}'] >= ${min} `\r\n ),\r\n}\r\n"],"file":"recordValidationRules.js"}
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/schema/createActions.js"],"names":["createTrigger","actionName","eventName","optionsCreator","condition","createAction","name","behaviourSource","behaviourName","initialOptions"],"mappings":"iIAAO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,WAAO;AAClCC,IAAAA,UAAU,EAAE,EADsB;AAElCC,IAAAA,SAAS,EAAE,EAFuB;AAGlC;AACA;AACA;AACAC,IAAAA,cAAc,EAAE,EANkB;AAOlC;AACA;AACAC,IAAAA,SAAS,EAAE,EATuB,EAAP,EAAtB,C;;;AAYA,IAAMC,YAAY,GAAG,SAAfA,YAAe,WAAO;AACjCC,IAAAA,IAAI,EAAE,EAD2B;AAEjCC,IAAAA,eAAe,EAAE,EAFgB;AAGjC;AACAC,IAAAA,aAAa,EAAE,EAJkB;AAKjC;AACA;AACA;AACAC,IAAAA,cAAc,EAAE,EARiB,EAAP,EAArB,C","sourcesContent":["export const createTrigger = () => ({\n actionName: \"\",\n eventName: \"\",\n // function, has access to event context,\n // returns object that is used as parameter to action\n // only used if triggered by event\n optionsCreator: \"\",\n // action runs if true,\n // has access to event context\n condition: \"\",\n})\n\nexport const createAction = () => ({\n name: \"\",\n behaviourSource: \"\",\n // name of function in actionSource\n behaviourName: \"\",\n // parameter passed into behaviour.\n // any other parms passed at runtime e.g.\n // by trigger, or manually, will be merged into this\n initialOptions: {},\n})\n"],"file":"createActions.js"}
|
||||
{"version":3,"sources":["../../src/schema/createActions.js"],"names":["createTrigger","actionName","eventName","optionsCreator","condition","createAction","name","behaviourSource","behaviourName","initialOptions"],"mappings":"iIAAO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,WAAO;AAClCC,IAAAA,UAAU,EAAE,EADsB;AAElCC,IAAAA,SAAS,EAAE,EAFuB;AAGlC;AACA;AACA;AACAC,IAAAA,cAAc,EAAE,EANkB;AAOlC;AACA;AACAC,IAAAA,SAAS,EAAE,EATuB,EAAP,EAAtB,C;;;AAYA,IAAMC,YAAY,GAAG,SAAfA,YAAe,WAAO;AACjCC,IAAAA,IAAI,EAAE,EAD2B;AAEjCC,IAAAA,eAAe,EAAE,EAFgB;AAGjC;AACAC,IAAAA,aAAa,EAAE,EAJkB;AAKjC;AACA;AACA;AACAC,IAAAA,cAAc,EAAE,EARiB,EAAP,EAArB,C","sourcesContent":["export const createTrigger = () => ({\r\n actionName: \"\",\r\n eventName: \"\",\r\n // function, has access to event context,\r\n // returns object that is used as parameter to action\r\n // only used if triggered by event\r\n optionsCreator: \"\",\r\n // action runs if true,\r\n // has access to event context\r\n condition: \"\",\r\n})\r\n\r\nexport const createAction = () => ({\r\n name: \"\",\r\n behaviourSource: \"\",\r\n // name of function in actionSource\r\n behaviourName: \"\",\r\n // parameter passed into behaviour.\r\n // any other parms passed at runtime e.g.\r\n // by trigger, or manually, will be merged into this\r\n initialOptions: {},\r\n})\r\n"],"file":"createActions.js"}
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/schema/fullSchema.js"],"names":["fullSchema","models","views","findModel","idOrName","find","m","id","name","toLowerCase","findView","findField","modelIdOrName","fieldName","model","fields","f","viewsForModel","modelId","filter","v"],"mappings":"uGAAO,IAAMA,UAAU,GAAG,SAAbA,UAAa,CAACC,MAAD,EAASC,KAAT,EAAmB;AAC3C,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,QAAQ;AACxBH,MAAAA,MAAM,CAACI,IAAP;AACE,gBAAAC,CAAC,UAAIA,CAAC,CAACC,EAAF,KAASH,QAAT,IAAqBE,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBL,QAAQ,CAACK,WAAT,EAAlD,EADH,CADwB,GAA1B;;;AAKA,MAAMC,QAAQ,GAAG,SAAXA,QAAW,CAAAN,QAAQ;AACvBF,MAAAA,KAAK,CAACG,IAAN;AACE,gBAAAC,CAAC,UAAIA,CAAC,CAACC,EAAF,KAASH,QAAT,IAAqBE,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBL,QAAQ,CAACK,WAAT,EAAlD,EADH,CADuB,GAAzB;;;AAKA,MAAME,SAAS,GAAG,SAAZA,SAAY,CAACC,aAAD,EAAgBC,SAAhB,EAA8B;AAC9C,QAAMC,KAAK,GAAGb,MAAM,CAACI,IAAP;AACZ,cAAAC,CAAC;AACCA,QAAAA,CAAC,CAACC,EAAF,KAASK,aAAT;AACAN,QAAAA,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBG,aAAa,CAACH,WAAd,EAF1B,GADW,CAAd;;AAKA,WAAOK,KAAK,CAACC,MAAN,CAAaV,IAAb;AACL,cAAAW,CAAC,UAAIA,CAAC,CAACR,IAAF,CAAOC,WAAP,OAAyBI,SAAS,CAACJ,WAAV,EAA7B,EADI,CAAP;;AAGD,GATD;;AAWA,MAAMQ,aAAa,GAAG,SAAhBA,aAAgB,CAAAC,OAAO,UAAIhB,KAAK,CAACiB,MAAN,CAAa,UAAAC,CAAC,UAAIA,CAAC,CAACF,OAAF,KAAcA,OAAlB,EAAd,CAAJ,EAA7B;;AAEA,SAAO;AACLjB,IAAAA,MAAM,EAANA,MADK;AAELC,IAAAA,KAAK,EAALA,KAFK;AAGLC,IAAAA,SAAS,EAATA,SAHK;AAILQ,IAAAA,SAAS,EAATA,SAJK;AAKLD,IAAAA,QAAQ,EAARA,QALK;AAMLO,IAAAA,aAAa,EAAbA,aANK,EAAP;;AAQD,CAhCM,C","sourcesContent":["export const fullSchema = (models, views) => {\n const findModel = idOrName =>\n models.find(\n m => m.id === idOrName || m.name.toLowerCase() === idOrName.toLowerCase()\n )\n\n const findView = idOrName =>\n views.find(\n m => m.id === idOrName || m.name.toLowerCase() === idOrName.toLowerCase()\n )\n\n const findField = (modelIdOrName, fieldName) => {\n const model = models.find(\n m =>\n m.id === modelIdOrName ||\n m.name.toLowerCase() === modelIdOrName.toLowerCase()\n )\n return model.fields.find(\n f => f.name.toLowerCase() === fieldName.toLowerCase()\n )\n }\n\n const viewsForModel = modelId => views.filter(v => v.modelId === modelId)\n\n return {\n models,\n views,\n findModel,\n findField,\n findView,\n viewsForModel,\n }\n}\n"],"file":"fullSchema.js"}
|
||||
{"version":3,"sources":["../../src/schema/fullSchema.js"],"names":["fullSchema","models","views","findModel","idOrName","find","m","id","name","toLowerCase","findView","findField","modelIdOrName","fieldName","model","fields","f","viewsForModel","modelId","filter","v"],"mappings":"uGAAO,IAAMA,UAAU,GAAG,SAAbA,UAAa,CAACC,MAAD,EAASC,KAAT,EAAmB;AAC3C,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,QAAQ;AACxBH,MAAAA,MAAM,CAACI,IAAP;AACE,gBAAAC,CAAC,UAAIA,CAAC,CAACC,EAAF,KAASH,QAAT,IAAqBE,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBL,QAAQ,CAACK,WAAT,EAAlD,EADH,CADwB,GAA1B;;;AAKA,MAAMC,QAAQ,GAAG,SAAXA,QAAW,CAAAN,QAAQ;AACvBF,MAAAA,KAAK,CAACG,IAAN;AACE,gBAAAC,CAAC,UAAIA,CAAC,CAACC,EAAF,KAASH,QAAT,IAAqBE,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBL,QAAQ,CAACK,WAAT,EAAlD,EADH,CADuB,GAAzB;;;AAKA,MAAME,SAAS,GAAG,SAAZA,SAAY,CAACC,aAAD,EAAgBC,SAAhB,EAA8B;AAC9C,QAAMC,KAAK,GAAGb,MAAM,CAACI,IAAP;AACZ,cAAAC,CAAC;AACCA,QAAAA,CAAC,CAACC,EAAF,KAASK,aAAT;AACAN,QAAAA,CAAC,CAACE,IAAF,CAAOC,WAAP,OAAyBG,aAAa,CAACH,WAAd,EAF1B,GADW,CAAd;;AAKA,WAAOK,KAAK,CAACC,MAAN,CAAaV,IAAb;AACL,cAAAW,CAAC,UAAIA,CAAC,CAACR,IAAF,CAAOC,WAAP,OAAyBI,SAAS,CAACJ,WAAV,EAA7B,EADI,CAAP;;AAGD,GATD;;AAWA,MAAMQ,aAAa,GAAG,SAAhBA,aAAgB,CAAAC,OAAO,UAAIhB,KAAK,CAACiB,MAAN,CAAa,UAAAC,CAAC,UAAIA,CAAC,CAACF,OAAF,KAAcA,OAAlB,EAAd,CAAJ,EAA7B;;AAEA,SAAO;AACLjB,IAAAA,MAAM,EAANA,MADK;AAELC,IAAAA,KAAK,EAALA,KAFK;AAGLC,IAAAA,SAAS,EAATA,SAHK;AAILQ,IAAAA,SAAS,EAATA,SAJK;AAKLD,IAAAA,QAAQ,EAARA,QALK;AAMLO,IAAAA,aAAa,EAAbA,aANK,EAAP;;AAQD,CAhCM,C","sourcesContent":["export const fullSchema = (models, views) => {\r\n const findModel = idOrName =>\r\n models.find(\r\n m => m.id === idOrName || m.name.toLowerCase() === idOrName.toLowerCase()\r\n )\r\n\r\n const findView = idOrName =>\r\n views.find(\r\n m => m.id === idOrName || m.name.toLowerCase() === idOrName.toLowerCase()\r\n )\r\n\r\n const findField = (modelIdOrName, fieldName) => {\r\n const model = models.find(\r\n m =>\r\n m.id === modelIdOrName ||\r\n m.name.toLowerCase() === modelIdOrName.toLowerCase()\r\n )\r\n return model.fields.find(\r\n f => f.name.toLowerCase() === fieldName.toLowerCase()\r\n )\r\n }\r\n\r\n const viewsForModel = modelId => views.filter(v => v.modelId === modelId)\r\n\r\n return {\r\n models,\r\n views,\r\n findModel,\r\n findField,\r\n findView,\r\n viewsForModel,\r\n }\r\n}\r\n"],"file":"fullSchema.js"}
|
|
@ -1,20 +1,25 @@
|
|||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.canDeleteModel = exports.newModel = void 0;var _shortid = require("shortid");function _createForOfIteratorHelper(o) {if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) {var i = 0;var F = function F() {};return { s: F, n: function n() {if (i >= o.length) return { done: true };return { done: false, value: o[i++] };}, e: function e(_e) {throw _e;}, f: F };}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var it,normalCompletion = true,didErr = false,err;return { s: function s() {it = o[Symbol.iterator]();}, n: function n() {var step = it.next();normalCompletion = step.done;return step;}, e: function e(_e2) {didErr = true;err = _e2;}, f: function f() {try {if (!normalCompletion && it["return"] != null) it["return"]();} finally {if (didErr) throw err;}} };}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(n);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}
|
||||
|
||||
var newModel = function newModel() {return {
|
||||
id: (0, _shortid.generate)(),
|
||||
_id: (0, _shortid.generate)(),
|
||||
name: "",
|
||||
fields: [],
|
||||
validationRules: [],
|
||||
primaryField: "",
|
||||
views: [] };};
|
||||
type: "model",
|
||||
key: "name",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: { type: "string" } },
|
||||
|
||||
required: ["name"] } };};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array} models
|
||||
* @param {string} modelId
|
||||
* @returns {}
|
||||
*/exports.newModel = newModel;
|
||||
*
|
||||
* @param {Array} models
|
||||
* @param {string} modelId
|
||||
* @returns {}
|
||||
*/exports.newModel = newModel;
|
||||
var canDeleteModel = function canDeleteModel(models, modelId) {
|
||||
var errors = [];var _iterator = _createForOfIteratorHelper(
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/schema/models.js"],"names":["newModel","id","name","fields","validationRules","primaryField","views","canDeleteModel","models","modelId","errors","model","links","filter","f","type","typeOptions","link","push","canDelete","length"],"mappings":"8HAAA,kC;;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,WAAO;AAC7BC,IAAAA,EAAE,EAAE,wBADyB;AAE7BC,IAAAA,IAAI,EAAE,EAFuB;AAG7BC,IAAAA,MAAM,EAAE,EAHqB;AAI7BC,IAAAA,eAAe,EAAE,EAJY;AAK7BC,IAAAA,YAAY,EAAE,EALe;AAM7BC,IAAAA,KAAK,EAAE,EANsB,EAAP,EAAjB;;;AASP;;;;;;AAMO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,MAAD,EAASC,OAAT,EAAqB;AACjD,MAAMC,MAAM,GAAG,EAAf,CADiD;;AAG/BF,EAAAA,MAH+B,aAGjD,oDAA0B,KAAjBG,KAAiB;AACxB,UAAMC,KAAK,GAAGD,KAAK,CAACR,MAAN,CAAaU,MAAb;AACZ,gBAAAC,CAAC,UAAIA,CAAC,CAACC,IAAF,KAAW,MAAX,IAAqBD,CAAC,CAACE,WAAF,CAAcP,OAAd,KAA0BA,OAAnD,EADW,CAAd,CADwB;;;AAKPG,MAAAA,KALO,cAKxB,uDAAwB,KAAfK,IAAe;AACtBP,UAAAA,MAAM,CAACQ,IAAP;AACUP,UAAAA,KAAK,CAACT,IADhB,uDAC+De,IAAI,CAACf,IADpE;;AAGD,SATuB;AAUzB,KAbgD;;AAejD,SAAO;AACLQ,IAAAA,MAAM,EAANA,MADK;AAELS,IAAAA,SAAS,EAAET,MAAM,CAACU,MAAP,GAAgB,CAFtB,EAAP;;AAID,CAnBM,C","sourcesContent":["import { generate } from \"shortid\"\n\nexport const newModel = () => ({\n id: generate(),\n name: \"\",\n fields: [],\n validationRules: [],\n primaryField: \"\",\n views: [],\n})\n\n/**\n *\n * @param {Array} models\n * @param {string} modelId\n * @returns {}\n */\nexport const canDeleteModel = (models, modelId) => {\n const errors = []\n\n for (let model of models) {\n const links = model.fields.filter(\n f => f.type === \"link\" && f.typeOptions.modelId === modelId\n )\n\n for (let link of links) {\n errors.push(\n `The \"${model.name}\" model links to this model, via field \"${link.name}\"`\n )\n }\n }\n\n return {\n errors,\n canDelete: errors.length > 0,\n }\n}\n"],"file":"models.js"}
|
||||
{"version":3,"sources":["../../src/schema/models.js"],"names":["newModel","_id","name","type","key","schema","properties","required","canDeleteModel","models","modelId","errors","model","links","fields","filter","f","typeOptions","link","push","canDelete","length"],"mappings":"8HAAA,kC;;AAEO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,WAAO;AAC7BC,IAAAA,GAAG,EAAE,wBADwB;AAE7BC,IAAAA,IAAI,EAAE,EAFuB;AAG7BC,IAAAA,IAAI,EAAE,OAHuB;AAI7BC,IAAAA,GAAG,EAAE,MAJwB;AAK7BC,IAAAA,MAAM,EAAE;AACNF,MAAAA,IAAI,EAAE,QADA;AAENG,MAAAA,UAAU,EAAE;AACVJ,QAAAA,IAAI,EAAE,EAAEC,IAAI,EAAE,QAAR,EADI,EAFN;;AAKNI,MAAAA,QAAQ,EAAE,CAAC,MAAD,CALJ,EALqB,EAAP,EAAjB;;;;AAcP;;;;;;AAMO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,MAAD,EAASC,OAAT,EAAqB;AACjD,MAAMC,MAAM,GAAG,EAAf,CADiD;;AAG/BF,EAAAA,MAH+B,aAGjD,oDAA0B,KAAjBG,KAAiB;AACxB,UAAMC,KAAK,GAAGD,KAAK,CAACE,MAAN,CAAaC,MAAb;AACZ,gBAAAC,CAAC,UAAIA,CAAC,CAACb,IAAF,KAAW,MAAX,IAAqBa,CAAC,CAACC,WAAF,CAAcP,OAAd,KAA0BA,OAAnD,EADW,CAAd,CADwB;;;AAKPG,MAAAA,KALO,cAKxB,uDAAwB,KAAfK,IAAe;AACtBP,UAAAA,MAAM,CAACQ,IAAP;AACUP,UAAAA,KAAK,CAACV,IADhB,uDAC+DgB,IAAI,CAAChB,IADpE;;AAGD,SATuB;AAUzB,KAbgD;;AAejD,SAAO;AACLS,IAAAA,MAAM,EAANA,MADK;AAELS,IAAAA,SAAS,EAAET,MAAM,CAACU,MAAP,GAAgB,CAFtB,EAAP;;AAID,CAnBM,C","sourcesContent":["import { generate } from \"shortid\"\r\n\r\nexport const newModel = () => ({\r\n _id: generate(),\r\n name: \"\",\r\n type: \"model\",\r\n key: \"name\",\r\n schema: {\r\n type: \"object\",\r\n properties: {\r\n name: { type: \"string\" },\r\n },\r\n required: [\"name\"],\r\n },\r\n})\r\n\r\n/**\r\n *\r\n * @param {Array} models\r\n * @param {string} modelId\r\n * @returns {}\r\n */\r\nexport const canDeleteModel = (models, modelId) => {\r\n const errors = []\r\n\r\n for (let model of models) {\r\n const links = model.fields.filter(\r\n f => f.type === \"link\" && f.typeOptions.modelId === modelId\r\n )\r\n\r\n for (let link of links) {\r\n errors.push(\r\n `The \"${model.name}\" model links to this model, via field \"${link.name}\"`\r\n )\r\n }\r\n }\r\n\r\n return {\r\n errors,\r\n canDelete: errors.length > 0,\r\n }\r\n}\r\n"],"file":"models.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/array.js"],"names":["arrayFunctions","mapToParsedArrary","type","i","safeParseValue","parsedSuccess","arrayTryParse","isArray","defaultCase","parsedFailed","typeName","options","maxLength","defaultValue","isValid","isSafeInteger","requirementDescription","parse","toNumberOrNull","minLength","n","typeConstraints","val","opts","length","name","sampleValue","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;;;;;;;AAQA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB;AACrB,oCAAc;AACZ,iBAAS,kBAAS,EAAT,CADG,EAAd,CADqB,GAAvB;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAAAC,IAAI;AAC5B;AACE,iBAAI,UAAAC,CAAC,UAAID,IAAI,CAACE,cAAL,CAAoBD,CAApB,CAAJ,EAAL,CADF;AAEEE,8BAFF,CAD4B,GAA9B;;;AAMA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAAAJ,IAAI;AACxB,2BAAW,CAACK,WAAD,EAAUN,iBAAiB,CAACC,IAAD,CAA3B,CAAX,EAA+C,CAACM,kBAAD,EAAcC,yBAAd,CAA/C,CADwB,GAA1B;;AAGA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAAAR,IAAI,0BAAaA,IAAb,QAArB;;AAEA,IAAMS,OAAO,GAAG;AACdC,EAAAA,SAAS,EAAE;AACTC,IAAAA,YAAY,EAAE,KADL;AAETC,IAAAA,OAAO,EAAEC,oBAFA;AAGTC,IAAAA,sBAAsB,EAAE,4BAHf;AAITC,IAAAA,KAAK,EAAEC,qBAJE,EADG;;AAOdC,EAAAA,SAAS,EAAE;AACTN,IAAAA,YAAY,EAAE,CADL;AAETC,IAAAA,OAAO,EAAE,iBAAAM,CAAC,UAAI,0BAAcA,CAAd,KAAoBA,CAAC,IAAI,CAA7B,EAFD;AAGTJ,IAAAA,sBAAsB,EAAE,4BAHf;AAITC,IAAAA,KAAK,EAAEC,qBAJE,EAPG,EAAhB;;;;AAeA,IAAMG,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN,UAAeD,GAAG,KAAK,IAAR,IAAgBA,GAAG,CAACE,MAAJ,IAAcD,IAAI,CAACJ,SAAlD,EADF;AAEE,UAACG,GAAD,EAAMC,IAAN,gCAA8BA,IAAI,CAACJ,SAAnC,uBAFF,CADsB;;AAKtB;AACE,UAACG,GAAD,EAAMC,IAAN,UAAeD,GAAG,KAAK,IAAR,IAAgBA,GAAG,CAACE,MAAJ,IAAcD,IAAI,CAACX,SAAlD,EADF;AAEE,UAACU,GAAD,EAAMC,IAAN,4CAA0CA,IAAI,CAACX,SAA/C,eAFF,CALsB,CAAxB,C;;;;AAWe,kBAAAV,IAAI;AACjB;AACEQ,IAAAA,QAAQ,CAACR,IAAI,CAACuB,IAAN,CADV;AAEEnB,IAAAA,aAAa,CAACJ,IAAD,CAFf;AAGEF,IAAAA,cAAc,CAACE,IAAD,CAHhB;AAIES,IAAAA,OAJF;AAKEU,IAAAA,eALF;AAME,KAACnB,IAAI,CAACwB,WAAN,CANF;AAOEC,IAAAA,IAAI,CAACC,SAPP,CADiB,G","sourcesContent":["import { map, constant, isArray } from \"lodash/fp\"\nimport {\n typeFunctions,\n makerule,\n parsedFailed,\n getDefaultExport,\n parsedSuccess,\n} from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n toNumberOrNull,\n $$,\n isSafeInteger,\n} from \"../../common/index.js\"\n\nconst arrayFunctions = () =>\n typeFunctions({\n default: constant([]),\n })\n\nconst mapToParsedArrary = type =>\n $$(\n map(i => type.safeParseValue(i)),\n parsedSuccess\n )\n\nconst arrayTryParse = type =>\n switchCase([isArray, mapToParsedArrary(type)], [defaultCase, parsedFailed])\n\nconst typeName = type => `array<${type}>`\n\nconst options = {\n maxLength: {\n defaultValue: 10000,\n isValid: isSafeInteger,\n requirementDescription: \"must be a positive integer\",\n parse: toNumberOrNull,\n },\n minLength: {\n defaultValue: 0,\n isValid: n => isSafeInteger(n) && n >= 0,\n requirementDescription: \"must be a positive integer\",\n parse: toNumberOrNull,\n },\n}\n\nconst typeConstraints = [\n makerule(\n (val, opts) => val === null || val.length >= opts.minLength,\n (val, opts) => `must choose ${opts.minLength} or more options`\n ),\n makerule(\n (val, opts) => val === null || val.length <= opts.maxLength,\n (val, opts) => `cannot choose more than ${opts.maxLength} options`\n ),\n]\n\nexport default type =>\n getDefaultExport(\n typeName(type.name),\n arrayTryParse(type),\n arrayFunctions(type),\n options,\n typeConstraints,\n [type.sampleValue],\n JSON.stringify\n )\n"],"file":"array.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/array.js"],"names":["arrayFunctions","mapToParsedArrary","type","i","safeParseValue","parsedSuccess","arrayTryParse","isArray","defaultCase","parsedFailed","typeName","options","maxLength","defaultValue","isValid","isSafeInteger","requirementDescription","parse","toNumberOrNull","minLength","n","typeConstraints","val","opts","length","name","sampleValue","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;;;;;;;AAQA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB;AACrB,oCAAc;AACZ,iBAAS,kBAAS,EAAT,CADG,EAAd,CADqB,GAAvB;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAAAC,IAAI;AAC5B;AACE,iBAAI,UAAAC,CAAC,UAAID,IAAI,CAACE,cAAL,CAAoBD,CAApB,CAAJ,EAAL,CADF;AAEEE,8BAFF,CAD4B,GAA9B;;;AAMA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAAAJ,IAAI;AACxB,2BAAW,CAACK,WAAD,EAAUN,iBAAiB,CAACC,IAAD,CAA3B,CAAX,EAA+C,CAACM,kBAAD,EAAcC,yBAAd,CAA/C,CADwB,GAA1B;;AAGA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAAAR,IAAI,0BAAaA,IAAb,QAArB;;AAEA,IAAMS,OAAO,GAAG;AACdC,EAAAA,SAAS,EAAE;AACTC,IAAAA,YAAY,EAAE,KADL;AAETC,IAAAA,OAAO,EAAEC,oBAFA;AAGTC,IAAAA,sBAAsB,EAAE,4BAHf;AAITC,IAAAA,KAAK,EAAEC,qBAJE,EADG;;AAOdC,EAAAA,SAAS,EAAE;AACTN,IAAAA,YAAY,EAAE,CADL;AAETC,IAAAA,OAAO,EAAE,iBAAAM,CAAC,UAAI,0BAAcA,CAAd,KAAoBA,CAAC,IAAI,CAA7B,EAFD;AAGTJ,IAAAA,sBAAsB,EAAE,4BAHf;AAITC,IAAAA,KAAK,EAAEC,qBAJE,EAPG,EAAhB;;;;AAeA,IAAMG,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN,UAAeD,GAAG,KAAK,IAAR,IAAgBA,GAAG,CAACE,MAAJ,IAAcD,IAAI,CAACJ,SAAlD,EADF;AAEE,UAACG,GAAD,EAAMC,IAAN,gCAA8BA,IAAI,CAACJ,SAAnC,uBAFF,CADsB;;AAKtB;AACE,UAACG,GAAD,EAAMC,IAAN,UAAeD,GAAG,KAAK,IAAR,IAAgBA,GAAG,CAACE,MAAJ,IAAcD,IAAI,CAACX,SAAlD,EADF;AAEE,UAACU,GAAD,EAAMC,IAAN,4CAA0CA,IAAI,CAACX,SAA/C,eAFF,CALsB,CAAxB,C;;;;AAWe,kBAAAV,IAAI;AACjB;AACEQ,IAAAA,QAAQ,CAACR,IAAI,CAACuB,IAAN,CADV;AAEEnB,IAAAA,aAAa,CAACJ,IAAD,CAFf;AAGEF,IAAAA,cAAc,CAACE,IAAD,CAHhB;AAIES,IAAAA,OAJF;AAKEU,IAAAA,eALF;AAME,KAACnB,IAAI,CAACwB,WAAN,CANF;AAOEC,IAAAA,IAAI,CAACC,SAPP,CADiB,G","sourcesContent":["import { map, constant, isArray } from \"lodash/fp\"\r\nimport {\r\n typeFunctions,\r\n makerule,\r\n parsedFailed,\r\n getDefaultExport,\r\n parsedSuccess,\r\n} from \"./typeHelpers\"\r\nimport {\r\n switchCase,\r\n defaultCase,\r\n toNumberOrNull,\r\n $$,\r\n isSafeInteger,\r\n} from \"../../common/index.js\"\r\n\r\nconst arrayFunctions = () =>\r\n typeFunctions({\r\n default: constant([]),\r\n })\r\n\r\nconst mapToParsedArrary = type =>\r\n $$(\r\n map(i => type.safeParseValue(i)),\r\n parsedSuccess\r\n )\r\n\r\nconst arrayTryParse = type =>\r\n switchCase([isArray, mapToParsedArrary(type)], [defaultCase, parsedFailed])\r\n\r\nconst typeName = type => `array<${type}>`\r\n\r\nconst options = {\r\n maxLength: {\r\n defaultValue: 10000,\r\n isValid: isSafeInteger,\r\n requirementDescription: \"must be a positive integer\",\r\n parse: toNumberOrNull,\r\n },\r\n minLength: {\r\n defaultValue: 0,\r\n isValid: n => isSafeInteger(n) && n >= 0,\r\n requirementDescription: \"must be a positive integer\",\r\n parse: toNumberOrNull,\r\n },\r\n}\r\n\r\nconst typeConstraints = [\r\n makerule(\r\n (val, opts) => val === null || val.length >= opts.minLength,\r\n (val, opts) => `must choose ${opts.minLength} or more options`\r\n ),\r\n makerule(\r\n (val, opts) => val === null || val.length <= opts.maxLength,\r\n (val, opts) => `cannot choose more than ${opts.maxLength} options`\r\n ),\r\n]\r\n\r\nexport default type =>\r\n getDefaultExport(\r\n typeName(type.name),\r\n arrayTryParse(type),\r\n arrayFunctions(type),\r\n options,\r\n typeConstraints,\r\n [type.sampleValue],\r\n JSON.stringify\r\n )\r\n"],"file":"array.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/bool.js"],"names":["boolFunctions","boolTryParse","isBoolean","parsedSuccess","isNull","defaultCase","parsedFailed","options","allowNulls","defaultValue","isValid","requirementDescription","parse","toBoolOrNull","typeConstraints","val","opts","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;;;;;;AAOA,IAAMA,aAAa,GAAG,gCAAc;AAClC,aAAS,kBAAS,IAAT,CADyB,EAAd,CAAtB;;;AAIA,IAAMC,YAAY,GAAG;AACnB,CAACC,aAAD,EAAYC,0BAAZ,CADmB;AAEnB,CAACC,UAAD,EAASD,0BAAT,CAFmB;AAGnB,CAAC,oBAAQ,MAAR,EAAgB,GAAhB,EAAqB,KAArB,EAA4B,IAA5B,CAAD,EAAoC,oBAAM,gCAAc,IAAd,CAAN,EAApC,CAHmB;AAInB,CAAC,oBAAQ,OAAR,EAAiB,GAAjB,EAAsB,IAAtB,EAA4B,KAA5B,CAAD,EAAqC,oBAAM,gCAAc,KAAd,CAAN,EAArC,CAJmB;AAKnB,CAACE,kBAAD,EAAcC,yBAAd,CALmB,CAArB;;;AAQA,IAAMC,OAAO,GAAG;AACdC,EAAAA,UAAU,EAAE;AACVC,IAAAA,YAAY,EAAE,IADJ;AAEVC,IAAAA,OAAO,EAAER,aAFC;AAGVS,IAAAA,sBAAsB,EAAE,yBAHd;AAIVC,IAAAA,KAAK,EAAEC,mBAJG,EADE,EAAhB;;;;AASA,IAAMC,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN,UAAeA,IAAI,CAACR,UAAL,KAAoB,IAApB,IAA4BO,GAAG,KAAK,IAAnD,EADF;AAEE,oBAAM,sBAAN,EAFF,CADsB,CAAxB,C;;;;AAOe;AACb,MADa;AAEbd,YAFa;AAGbD,aAHa;AAIbO,OAJa;AAKbO,eALa;AAMb,IANa;AAObG,IAAI,CAACC,SAPQ,C","sourcesContent":["import { constant, isBoolean, isNull } from \"lodash/fp\"\nimport {\n typeFunctions,\n makerule,\n parsedFailed,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n isOneOf,\n toBoolOrNull,\n} from \"../../common/index.js\"\n\nconst boolFunctions = typeFunctions({\n default: constant(null),\n})\n\nconst boolTryParse = switchCase(\n [isBoolean, parsedSuccess],\n [isNull, parsedSuccess],\n [isOneOf(\"true\", \"1\", \"yes\", \"on\"), () => parsedSuccess(true)],\n [isOneOf(\"false\", \"0\", \"no\", \"off\"), () => parsedSuccess(false)],\n [defaultCase, parsedFailed]\n)\n\nconst options = {\n allowNulls: {\n defaultValue: true,\n isValid: isBoolean,\n requirementDescription: \"must be a true or false\",\n parse: toBoolOrNull,\n },\n}\n\nconst typeConstraints = [\n makerule(\n (val, opts) => opts.allowNulls === true || val !== null,\n () => \"field cannot be null\"\n ),\n]\n\nexport default getDefaultExport(\n \"bool\",\n boolTryParse,\n boolFunctions,\n options,\n typeConstraints,\n true,\n JSON.stringify\n)\n"],"file":"bool.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/bool.js"],"names":["boolFunctions","boolTryParse","isBoolean","parsedSuccess","isNull","defaultCase","parsedFailed","options","allowNulls","defaultValue","isValid","requirementDescription","parse","toBoolOrNull","typeConstraints","val","opts","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;;;;;;AAOA,IAAMA,aAAa,GAAG,gCAAc;AAClC,aAAS,kBAAS,IAAT,CADyB,EAAd,CAAtB;;;AAIA,IAAMC,YAAY,GAAG;AACnB,CAACC,aAAD,EAAYC,0BAAZ,CADmB;AAEnB,CAACC,UAAD,EAASD,0BAAT,CAFmB;AAGnB,CAAC,oBAAQ,MAAR,EAAgB,GAAhB,EAAqB,KAArB,EAA4B,IAA5B,CAAD,EAAoC,oBAAM,gCAAc,IAAd,CAAN,EAApC,CAHmB;AAInB,CAAC,oBAAQ,OAAR,EAAiB,GAAjB,EAAsB,IAAtB,EAA4B,KAA5B,CAAD,EAAqC,oBAAM,gCAAc,KAAd,CAAN,EAArC,CAJmB;AAKnB,CAACE,kBAAD,EAAcC,yBAAd,CALmB,CAArB;;;AAQA,IAAMC,OAAO,GAAG;AACdC,EAAAA,UAAU,EAAE;AACVC,IAAAA,YAAY,EAAE,IADJ;AAEVC,IAAAA,OAAO,EAAER,aAFC;AAGVS,IAAAA,sBAAsB,EAAE,yBAHd;AAIVC,IAAAA,KAAK,EAAEC,mBAJG,EADE,EAAhB;;;;AASA,IAAMC,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN,UAAeA,IAAI,CAACR,UAAL,KAAoB,IAApB,IAA4BO,GAAG,KAAK,IAAnD,EADF;AAEE,oBAAM,sBAAN,EAFF,CADsB,CAAxB,C;;;;AAOe;AACb,MADa;AAEbd,YAFa;AAGbD,aAHa;AAIbO,OAJa;AAKbO,eALa;AAMb,IANa;AAObG,IAAI,CAACC,SAPQ,C","sourcesContent":["import { constant, isBoolean, isNull } from \"lodash/fp\"\r\nimport {\r\n typeFunctions,\r\n makerule,\r\n parsedFailed,\r\n parsedSuccess,\r\n getDefaultExport,\r\n} from \"./typeHelpers\"\r\nimport {\r\n switchCase,\r\n defaultCase,\r\n isOneOf,\r\n toBoolOrNull,\r\n} from \"../../common/index.js\"\r\n\r\nconst boolFunctions = typeFunctions({\r\n default: constant(null),\r\n})\r\n\r\nconst boolTryParse = switchCase(\r\n [isBoolean, parsedSuccess],\r\n [isNull, parsedSuccess],\r\n [isOneOf(\"true\", \"1\", \"yes\", \"on\"), () => parsedSuccess(true)],\r\n [isOneOf(\"false\", \"0\", \"no\", \"off\"), () => parsedSuccess(false)],\r\n [defaultCase, parsedFailed]\r\n)\r\n\r\nconst options = {\r\n allowNulls: {\r\n defaultValue: true,\r\n isValid: isBoolean,\r\n requirementDescription: \"must be a true or false\",\r\n parse: toBoolOrNull,\r\n },\r\n}\r\n\r\nconst typeConstraints = [\r\n makerule(\r\n (val, opts) => opts.allowNulls === true || val !== null,\r\n () => \"field cannot be null\"\r\n ),\r\n]\r\n\r\nexport default getDefaultExport(\r\n \"bool\",\r\n boolTryParse,\r\n boolFunctions,\r\n options,\r\n typeConstraints,\r\n true,\r\n JSON.stringify\r\n)\r\n"],"file":"bool.js"}
|
|
@ -1,78 +1,18 @@
|
|||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _fp = require("lodash/fp");
|
||||
var _typeHelpers = require("./typeHelpers");
|
||||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _default2 = {
|
||||
isType: function isType(schema) {return (
|
||||
schema.anyOf &&
|
||||
schema.anyOf.filter(function (s) {return s.type === "string" && s.format === "date-time";}).
|
||||
length > 0);},
|
||||
|
||||
fromSchema: function fromSchema(schema) {return {
|
||||
type: "datetime",
|
||||
"default": schema["default"] };},
|
||||
|
||||
toSchema: function toSchema() {return {
|
||||
anyOf: [{ type: "string", format: "date-time" }, { "const": "" }],
|
||||
"default": "" };},
|
||||
|
||||
|
||||
|
||||
|
||||
var _common = require("../../common");
|
||||
|
||||
var dateFunctions = (0, _typeHelpers.typeFunctions)({
|
||||
"default": (0, _fp.constant)(null),
|
||||
now: function now() {return new Date();} });
|
||||
|
||||
|
||||
var isValidDate = function isValidDate(d) {return d instanceof Date && !isNaN(d);};
|
||||
|
||||
var parseStringToDate = function parseStringToDate(s) {return (
|
||||
(0, _common.switchCase)(
|
||||
[isValidDate, _typeHelpers.parsedSuccess],
|
||||
[_common.defaultCase, _typeHelpers.parsedFailed])(
|
||||
new Date(s)));};
|
||||
|
||||
var isNullOrEmpty = function isNullOrEmpty(d) {return (0, _fp.isNull)(d) || (d || "").toString() === "";};
|
||||
|
||||
var isDateOrEmpty = function isDateOrEmpty(d) {return (0, _fp.isDate)(d) || isNullOrEmpty(d);};
|
||||
|
||||
var dateTryParse = (0, _common.switchCase)(
|
||||
[isDateOrEmpty, _typeHelpers.parsedSuccess],
|
||||
[_fp.isString, parseStringToDate],
|
||||
[_common.defaultCase, _typeHelpers.parsedFailed]);
|
||||
|
||||
|
||||
var options = {
|
||||
maxValue: {
|
||||
defaultValue: null,
|
||||
//defaultValue: new Date(32503680000000),
|
||||
isValid: isDateOrEmpty,
|
||||
requirementDescription: "must be a valid date",
|
||||
parse: _common.toDateOrNull },
|
||||
|
||||
minValue: {
|
||||
defaultValue: null,
|
||||
//defaultValue: new Date(-8520336000000),
|
||||
isValid: isDateOrEmpty,
|
||||
requirementDescription: "must be a valid date",
|
||||
parse: _common.toDateOrNull } };
|
||||
|
||||
|
||||
|
||||
var typeConstraints = [
|
||||
(0, _typeHelpers.makerule)(
|
||||
function (val, opts) {return (
|
||||
val === null || isNullOrEmpty(opts.minValue) || val >= opts.minValue);},
|
||||
function (val, opts) {return "value (".concat(
|
||||
val.toString(), ") must be greater than or equal to ").concat(
|
||||
opts.minValue);}),
|
||||
|
||||
|
||||
(0, _typeHelpers.makerule)(
|
||||
function (val, opts) {return (
|
||||
val === null || isNullOrEmpty(opts.maxValue) || val <= opts.maxValue);},
|
||||
function (val, opts) {return "value (".concat(
|
||||
val.toString(), ") must be less than or equal to ").concat(
|
||||
opts.minValue, " options");})];var _default =
|
||||
|
||||
|
||||
|
||||
|
||||
(0, _typeHelpers.getDefaultExport)(
|
||||
"datetime",
|
||||
dateTryParse,
|
||||
dateFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
new Date(1984, 4, 1),
|
||||
function (date) {return JSON.stringify(date).replace(new RegExp('"', "g"), "");});exports["default"] = _default;
|
||||
"default": function _default() {return {
|
||||
type: "datetime",
|
||||
"default": "" };} };exports["default"] = _default2;
|
||||
//# sourceMappingURL=datetime.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/datetime.js"],"names":["dateFunctions","now","Date","isValidDate","d","isNaN","parseStringToDate","s","parsedSuccess","defaultCase","parsedFailed","isNullOrEmpty","toString","isDateOrEmpty","dateTryParse","isString","options","maxValue","defaultValue","isValid","requirementDescription","parse","toDateOrNull","minValue","typeConstraints","val","opts","date","JSON","stringify","replace","RegExp"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;AAEA,IAAMA,aAAa,GAAG,gCAAc;AAClC,aAAS,kBAAS,IAAT,CADyB;AAElCC,EAAAA,GAAG,EAAE,uBAAM,IAAIC,IAAJ,EAAN,EAF6B,EAAd,CAAtB;;;AAKA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAAAC,CAAC,UAAIA,CAAC,YAAYF,IAAb,IAAqB,CAACG,KAAK,CAACD,CAAD,CAA/B,EAArB;;AAEA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,CAAAC,CAAC;AACzB;AACE,KAACJ,WAAD,EAAcK,0BAAd,CADF;AAEE,KAACC,mBAAD,EAAcC,yBAAd,CAFF;AAGE,QAAIR,IAAJ,CAASK,CAAT,CAHF,CADyB,GAA3B;;AAMA,IAAMI,aAAa,GAAG,SAAhBA,aAAgB,CAAAP,CAAC,UAAI,gBAAOA,CAAP,KAAa,CAACA,CAAC,IAAI,EAAN,EAAUQ,QAAV,OAAyB,EAA1C,EAAvB;;AAEA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAAAT,CAAC,UAAI,gBAAOA,CAAP,KAAaO,aAAa,CAACP,CAAD,CAA9B,EAAvB;;AAEA,IAAMU,YAAY,GAAG;AACnB,CAACD,aAAD,EAAgBL,0BAAhB,CADmB;AAEnB,CAACO,YAAD,EAAWT,iBAAX,CAFmB;AAGnB,CAACG,mBAAD,EAAcC,yBAAd,CAHmB,CAArB;;;AAMA,IAAMM,OAAO,GAAG;AACdC,EAAAA,QAAQ,EAAE;AACRC,IAAAA,YAAY,EAAE,IADN;AAER;AACAC,IAAAA,OAAO,EAAEN,aAHD;AAIRO,IAAAA,sBAAsB,EAAE,sBAJhB;AAKRC,IAAAA,KAAK,EAAEC,oBALC,EADI;;AAQdC,EAAAA,QAAQ,EAAE;AACRL,IAAAA,YAAY,EAAE,IADN;AAER;AACAC,IAAAA,OAAO,EAAEN,aAHD;AAIRO,IAAAA,sBAAsB,EAAE,sBAJhB;AAKRC,IAAAA,KAAK,EAAEC,oBALC,EARI,EAAhB;;;;AAiBA,IAAME,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR,IAAgBd,aAAa,CAACe,IAAI,CAACH,QAAN,CAA7B,IAAgDE,GAAG,IAAIC,IAAI,CAACH,QAD9D,GADF;AAGE,UAACE,GAAD,EAAMC,IAAN;AACYD,EAAAA,GAAG,CAACb,QAAJ,EADZ;AAEIc,EAAAA,IAAI,CAACH,QAFT,GAHF,CADsB;;;AAStB;AACE,UAACE,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR,IAAgBd,aAAa,CAACe,IAAI,CAACT,QAAN,CAA7B,IAAgDQ,GAAG,IAAIC,IAAI,CAACT,QAD9D,GADF;AAGE,UAACQ,GAAD,EAAMC,IAAN;AACYD,EAAAA,GAAG,CAACb,QAAJ,EADZ;AAEIc,EAAAA,IAAI,CAACH,QAFT,eAHF,CATsB,CAAxB,C;;;;;AAmBe;AACb,UADa;AAEbT,YAFa;AAGbd,aAHa;AAIbgB,OAJa;AAKbQ,eALa;AAMb,IAAItB,IAAJ,CAAS,IAAT,EAAe,CAAf,EAAkB,CAAlB,CANa;AAOb,UAAAyB,IAAI,UAAIC,IAAI,CAACC,SAAL,CAAeF,IAAf,EAAqBG,OAArB,CAA6B,IAAIC,MAAJ,CAAW,GAAX,EAAgB,GAAhB,CAA7B,EAAmD,EAAnD,CAAJ,EAPS,C","sourcesContent":["import { constant, isDate, isString, isNull } from \"lodash/fp\"\nimport {\n makerule,\n typeFunctions,\n parsedFailed,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport { switchCase, defaultCase, toDateOrNull } from \"../../common\"\n\nconst dateFunctions = typeFunctions({\n default: constant(null),\n now: () => new Date(),\n})\n\nconst isValidDate = d => d instanceof Date && !isNaN(d)\n\nconst parseStringToDate = s =>\n switchCase(\n [isValidDate, parsedSuccess],\n [defaultCase, parsedFailed]\n )(new Date(s))\n\nconst isNullOrEmpty = d => isNull(d) || (d || \"\").toString() === \"\"\n\nconst isDateOrEmpty = d => isDate(d) || isNullOrEmpty(d)\n\nconst dateTryParse = switchCase(\n [isDateOrEmpty, parsedSuccess],\n [isString, parseStringToDate],\n [defaultCase, parsedFailed]\n)\n\nconst options = {\n maxValue: {\n defaultValue: null,\n //defaultValue: new Date(32503680000000),\n isValid: isDateOrEmpty,\n requirementDescription: \"must be a valid date\",\n parse: toDateOrNull,\n },\n minValue: {\n defaultValue: null,\n //defaultValue: new Date(-8520336000000),\n isValid: isDateOrEmpty,\n requirementDescription: \"must be a valid date\",\n parse: toDateOrNull,\n },\n}\n\nconst typeConstraints = [\n makerule(\n (val, opts) =>\n val === null || isNullOrEmpty(opts.minValue) || val >= opts.minValue,\n (val, opts) =>\n `value (${val.toString()}) must be greater than or equal to ${\n opts.minValue\n }`\n ),\n makerule(\n (val, opts) =>\n val === null || isNullOrEmpty(opts.maxValue) || val <= opts.maxValue,\n (val, opts) =>\n `value (${val.toString()}) must be less than or equal to ${\n opts.minValue\n } options`\n ),\n]\n\nexport default getDefaultExport(\n \"datetime\",\n dateTryParse,\n dateFunctions,\n options,\n typeConstraints,\n new Date(1984, 4, 1),\n date => JSON.stringify(date).replace(new RegExp('\"', \"g\"), \"\")\n)\n"],"file":"datetime.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/datetime.js"],"names":["isType","schema","anyOf","filter","s","type","format","length","fromSchema","toSchema"],"mappings":"uHAAe;AACbA,EAAAA,MAAM,EAAE,gBAAAC,MAAM;AACZA,MAAAA,MAAM,CAACC,KAAP;AACAD,MAAAA,MAAM,CAACC,KAAP,CAAaC,MAAb,CAAoB,UAAAC,CAAC,UAAIA,CAAC,CAACC,IAAF,KAAW,QAAX,IAAuBD,CAAC,CAACE,MAAF,KAAa,WAAxC,EAArB;AACGC,MAAAA,MADH,GACY,CAHA,GADD;;AAMbC,EAAAA,UAAU,EAAE,oBAAAP,MAAM,UAAK;AACrBI,MAAAA,IAAI,EAAE,UADe;AAErB,iBAASJ,MAAM,WAFM,EAAL,EANL;;AAUbQ,EAAAA,QAAQ,EAAE,4BAAO;AACfP,MAAAA,KAAK,EAAE,CAAC,EAAEG,IAAI,EAAE,QAAR,EAAkBC,MAAM,EAAE,WAA1B,EAAD,EAA0C,EAAE,SAAO,EAAT,EAA1C,CADQ;AAEf,iBAAS,EAFM,EAAP,EAVG;;AAcb,aAAS,4BAAO;AACdD,MAAAA,IAAI,EAAE,UADQ;AAEd,iBAAS,EAFK,EAAP,EAdI,E","sourcesContent":["export default {\r\n isType: schema =>\r\n schema.anyOf &&\r\n schema.anyOf.filter(s => s.type === \"string\" && s.format === \"date-time\")\r\n .length > 0,\r\n\r\n fromSchema: schema => ({\r\n type: \"datetime\",\r\n default: schema.default,\r\n }),\r\n toSchema: () => ({\r\n anyOf: [{ type: \"string\", format: \"date-time\" }, { const: \"\" }],\r\n default: \"\",\r\n }),\r\n default: () => ({\r\n type: \"datetime\",\r\n default: \"\",\r\n }),\r\n}\r\n"],"file":"datetime.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/file.js"],"names":["illegalCharacters","isLegalFilename","filePath","fn","fileName","length","split","f","fileNothing","relativePath","size","fileFunctions","fileTryParse","v","isValidFile","parsedSuccess","isNull","defaultCase","parsedFailed","splitKey","last","options","typeConstraints","JSON","stringify"],"mappings":"iIAAA;AACA;;;;;;AAMA;;;;;;;;AAQA,IAAMA,iBAAiB,GAAG,mBAA1B;;AAEO,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,QAAQ,EAAI;AACzC,MAAMC,EAAE,GAAGC,QAAQ,CAACF,QAAD,CAAnB;AACA;AACEC,IAAAA,EAAE,CAACE,MAAH,IAAa,GAAb;AACA,0BAAaF,EAAE,CAACG,KAAH,CAAS,EAAT,CAAb,EAA2BN,iBAAiB,CAACM,KAAlB,CAAwB,EAAxB,CAA3B,EAAwDD,MAAxD,KAAmE,CADnE;AAEA,qBAAK,UAAAE,CAAC,UAAIA,CAAC,KAAK,IAAV,EAAN,EAAsB,qBAASL,QAAT,CAAtB,CAHF;;AAKD,CAPM,C;;AASP,IAAMM,WAAW,GAAG,SAAdA,WAAc,WAAO,EAAEC,YAAY,EAAE,EAAhB,EAAoBC,IAAI,EAAE,CAA1B,EAAP,EAApB;;AAEA,IAAMC,aAAa,GAAG,gCAAc;AAClC,aAASH,WADyB,EAAd,CAAtB;;;AAIA,IAAMI,YAAY,GAAG,SAAfA,YAAe,CAAAC,CAAC;AACpB;AACE,KAACC,WAAD,EAAcC,0BAAd,CADF;AAEE,KAACC,UAAD,EAAS,oBAAM,gCAAcR,WAAW,EAAzB,CAAN,EAAT,CAFF;AAGE,KAACS,kBAAD,EAAcC,yBAAd,CAHF;AAIEL,IAAAA,CAJF,CADoB,GAAtB;;AAOA,IAAMT,QAAQ,GAAG,SAAXA,QAAW,CAAAF,QAAQ,UAAI,cAAEA,QAAF,EAAY,CAACiB,eAAD,EAAWC,QAAX,CAAZ,CAAJ,EAAzB;;AAEA,IAAMN,WAAW,GAAG,SAAdA,WAAc,CAAAP,CAAC;AACnB,KAAC,gBAAOA,CAAP,CAAD;AACA,iBAAI,cAAJ,EAAoBA,CAApB,CADA;AAEA,iBAAI,MAAJ,EAAYA,CAAZ,CAFA;AAGA,sBAASA,CAAC,CAACG,IAAX,CAHA;AAIA,sBAASH,CAAC,CAACE,YAAX,CAJA;AAKAR,IAAAA,eAAe,CAACM,CAAC,CAACE,YAAH,CANI,GAArB;;AAQA,IAAMY,OAAO,GAAG,EAAhB;;AAEA,IAAMC,eAAe,GAAG,EAAxB,C;;AAEe;AACb,MADa;AAEbV,YAFa;AAGbD,aAHa;AAIbU,OAJa;AAKbC,eALa;AAMb,EAAEb,YAAY,EAAE,eAAhB,EAAiCC,IAAI,EAAE,IAAvC,EANa;AAOba,IAAI,CAACC,SAPQ,C","sourcesContent":["import { last, has, isString, intersection, isNull, isNumber } from \"lodash/fp\"\nimport {\n typeFunctions,\n parsedFailed,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n none,\n $,\n splitKey,\n} from \"../../common/index.js\"\n\nconst illegalCharacters = \"*?\\\\/:<>|\\0\\b\\f\\v\"\n\nexport const isLegalFilename = filePath => {\n const fn = fileName(filePath)\n return (\n fn.length <= 255 &&\n intersection(fn.split(\"\"))(illegalCharacters.split(\"\")).length === 0 &&\n none(f => f === \"..\")(splitKey(filePath))\n )\n}\n\nconst fileNothing = () => ({ relativePath: \"\", size: 0 })\n\nconst fileFunctions = typeFunctions({\n default: fileNothing,\n})\n\nconst fileTryParse = v =>\n switchCase(\n [isValidFile, parsedSuccess],\n [isNull, () => parsedSuccess(fileNothing())],\n [defaultCase, parsedFailed]\n )(v)\n\nconst fileName = filePath => $(filePath, [splitKey, last])\n\nconst isValidFile = f =>\n !isNull(f) &&\n has(\"relativePath\")(f) &&\n has(\"size\")(f) &&\n isNumber(f.size) &&\n isString(f.relativePath) &&\n isLegalFilename(f.relativePath)\n\nconst options = {}\n\nconst typeConstraints = []\n\nexport default getDefaultExport(\n \"file\",\n fileTryParse,\n fileFunctions,\n options,\n typeConstraints,\n { relativePath: \"some_file.jpg\", size: 1000 },\n JSON.stringify\n)\n"],"file":"file.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/file.js"],"names":["illegalCharacters","isLegalFilename","filePath","fn","fileName","length","split","f","fileNothing","relativePath","size","fileFunctions","fileTryParse","v","isValidFile","parsedSuccess","isNull","defaultCase","parsedFailed","splitKey","last","options","typeConstraints","JSON","stringify"],"mappings":"iIAAA;AACA;;;;;;AAMA;;;;;;;;AAQA,IAAMA,iBAAiB,GAAG,mBAA1B;;AAEO,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,QAAQ,EAAI;AACzC,MAAMC,EAAE,GAAGC,QAAQ,CAACF,QAAD,CAAnB;AACA;AACEC,IAAAA,EAAE,CAACE,MAAH,IAAa,GAAb;AACA,0BAAaF,EAAE,CAACG,KAAH,CAAS,EAAT,CAAb,EAA2BN,iBAAiB,CAACM,KAAlB,CAAwB,EAAxB,CAA3B,EAAwDD,MAAxD,KAAmE,CADnE;AAEA,qBAAK,UAAAE,CAAC,UAAIA,CAAC,KAAK,IAAV,EAAN,EAAsB,qBAASL,QAAT,CAAtB,CAHF;;AAKD,CAPM,C;;AASP,IAAMM,WAAW,GAAG,SAAdA,WAAc,WAAO,EAAEC,YAAY,EAAE,EAAhB,EAAoBC,IAAI,EAAE,CAA1B,EAAP,EAApB;;AAEA,IAAMC,aAAa,GAAG,gCAAc;AAClC,aAASH,WADyB,EAAd,CAAtB;;;AAIA,IAAMI,YAAY,GAAG,SAAfA,YAAe,CAAAC,CAAC;AACpB;AACE,KAACC,WAAD,EAAcC,0BAAd,CADF;AAEE,KAACC,UAAD,EAAS,oBAAM,gCAAcR,WAAW,EAAzB,CAAN,EAAT,CAFF;AAGE,KAACS,kBAAD,EAAcC,yBAAd,CAHF;AAIEL,IAAAA,CAJF,CADoB,GAAtB;;AAOA,IAAMT,QAAQ,GAAG,SAAXA,QAAW,CAAAF,QAAQ,UAAI,cAAEA,QAAF,EAAY,CAACiB,eAAD,EAAWC,QAAX,CAAZ,CAAJ,EAAzB;;AAEA,IAAMN,WAAW,GAAG,SAAdA,WAAc,CAAAP,CAAC;AACnB,KAAC,gBAAOA,CAAP,CAAD;AACA,iBAAI,cAAJ,EAAoBA,CAApB,CADA;AAEA,iBAAI,MAAJ,EAAYA,CAAZ,CAFA;AAGA,sBAASA,CAAC,CAACG,IAAX,CAHA;AAIA,sBAASH,CAAC,CAACE,YAAX,CAJA;AAKAR,IAAAA,eAAe,CAACM,CAAC,CAACE,YAAH,CANI,GAArB;;AAQA,IAAMY,OAAO,GAAG,EAAhB;;AAEA,IAAMC,eAAe,GAAG,EAAxB,C;;AAEe;AACb,MADa;AAEbV,YAFa;AAGbD,aAHa;AAIbU,OAJa;AAKbC,eALa;AAMb,EAAEb,YAAY,EAAE,eAAhB,EAAiCC,IAAI,EAAE,IAAvC,EANa;AAOba,IAAI,CAACC,SAPQ,C","sourcesContent":["import { last, has, isString, intersection, isNull, isNumber } from \"lodash/fp\"\r\nimport {\r\n typeFunctions,\r\n parsedFailed,\r\n parsedSuccess,\r\n getDefaultExport,\r\n} from \"./typeHelpers\"\r\nimport {\r\n switchCase,\r\n defaultCase,\r\n none,\r\n $,\r\n splitKey,\r\n} from \"../../common/index.js\"\r\n\r\nconst illegalCharacters = \"*?\\\\/:<>|\\0\\b\\f\\v\"\r\n\r\nexport const isLegalFilename = filePath => {\r\n const fn = fileName(filePath)\r\n return (\r\n fn.length <= 255 &&\r\n intersection(fn.split(\"\"))(illegalCharacters.split(\"\")).length === 0 &&\r\n none(f => f === \"..\")(splitKey(filePath))\r\n )\r\n}\r\n\r\nconst fileNothing = () => ({ relativePath: \"\", size: 0 })\r\n\r\nconst fileFunctions = typeFunctions({\r\n default: fileNothing,\r\n})\r\n\r\nconst fileTryParse = v =>\r\n switchCase(\r\n [isValidFile, parsedSuccess],\r\n [isNull, () => parsedSuccess(fileNothing())],\r\n [defaultCase, parsedFailed]\r\n )(v)\r\n\r\nconst fileName = filePath => $(filePath, [splitKey, last])\r\n\r\nconst isValidFile = f =>\r\n !isNull(f) &&\r\n has(\"relativePath\")(f) &&\r\n has(\"size\")(f) &&\r\n isNumber(f.size) &&\r\n isString(f.relativePath) &&\r\n isLegalFilename(f.relativePath)\r\n\r\nconst options = {}\r\n\r\nconst typeConstraints = []\r\n\r\nexport default getDefaultExport(\r\n \"file\",\r\n fileTryParse,\r\n fileFunctions,\r\n options,\r\n typeConstraints,\r\n { relativePath: \"some_file.jpg\", size: 1000 },\r\n JSON.stringify\r\n)\r\n"],"file":"file.js"}
|
|
@ -1,85 +1,54 @@
|
|||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.detectType = exports.validateTypeConstraints = exports.getDefaultOptions = exports.validateFieldParse = exports.safeParseField = exports.getNewFieldValue = exports.getSampleFieldValue = exports.getType = exports.all = void 0;var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _lodash = require("lodash");
|
||||
var _fp = require("lodash/fp");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var _common = require("../../common");
|
||||
var _typeHelpers = require("./typeHelpers");
|
||||
var _string = _interopRequireDefault(require("./string"));
|
||||
var _bool = _interopRequireDefault(require("./bool"));
|
||||
var _number = _interopRequireDefault(require("./number"));
|
||||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.listTypes = listTypes;exports.newField = newField;exports.fieldsToSchema = fieldsToSchema;exports.schemaToFields = schemaToFields;var _boolean2 = _interopRequireDefault(require("./boolean"));
|
||||
var _datetime = _interopRequireDefault(require("./datetime"));
|
||||
var _array = _interopRequireDefault(require("./array"));
|
||||
var _link = _interopRequireDefault(require("./link"));
|
||||
var _file = _interopRequireDefault(require("./file"));
|
||||
var _errors = require("../../common/errors");
|
||||
var _number = _interopRequireDefault(require("./number"));
|
||||
var _select = _interopRequireDefault(require("./select"));
|
||||
var _text = _interopRequireDefault(require("./text"));
|
||||
|
||||
var allTypes = function allTypes() {
|
||||
var basicTypes = {
|
||||
string: _string["default"],
|
||||
number: _number["default"],
|
||||
datetime: _datetime["default"],
|
||||
bool: _bool["default"],
|
||||
link: _link["default"],
|
||||
file: _file["default"] };
|
||||
var allTypes = {
|
||||
"boolean": _boolean2["default"],
|
||||
datetime: _datetime["default"],
|
||||
link: _link["default"],
|
||||
number: _number["default"],
|
||||
select: _select["default"],
|
||||
text: _text["default"] };
|
||||
|
||||
|
||||
var arrays = (0, _common.$)(basicTypes, [
|
||||
_fp.keys,
|
||||
(0, _fp.map)(function (k) {
|
||||
var kvType = {};
|
||||
var concreteArray = (0, _array["default"])(basicTypes[k]);
|
||||
kvType[concreteArray.name] = concreteArray;
|
||||
return kvType;
|
||||
}),
|
||||
function (types) {return _lodash.assign.apply(void 0, [{}].concat((0, _toConsumableArray2["default"])(types)));}]);
|
||||
function listTypes() {
|
||||
return Object.keys(allTypes);
|
||||
}
|
||||
|
||||
function newField(name, type) {
|
||||
var field = allTypes[type]["default"]();
|
||||
field.name = name;
|
||||
field.required = false;
|
||||
return field;
|
||||
}
|
||||
|
||||
return (0, _lodash.merge)({}, basicTypes, arrays);
|
||||
};
|
||||
function fieldsToSchema(fields) {
|
||||
var required = fields.filter(function (f) {return f.required;}).map(function (f) {return f.name;});
|
||||
|
||||
var all = allTypes();exports.all = all;
|
||||
return {
|
||||
type: "object",
|
||||
required: required,
|
||||
properties: fields.reduce(function (sch, field) {
|
||||
sch[field.name] = allTypes[field.type].toSchema(field);
|
||||
return sch;
|
||||
}, {}) };
|
||||
|
||||
var getType = function getType(typeName) {
|
||||
if (!(0, _fp.has)(typeName)(all))
|
||||
throw new _errors.BadRequestError("Do not recognise type ".concat(typeName));
|
||||
return all[typeName];
|
||||
};exports.getType = getType;
|
||||
}
|
||||
|
||||
var getSampleFieldValue = function getSampleFieldValue(field) {return getType(field.type).sampleValue;};exports.getSampleFieldValue = getSampleFieldValue;
|
||||
|
||||
var getNewFieldValue = function getNewFieldValue(field) {return getType(field.type).getNew(field);};exports.getNewFieldValue = getNewFieldValue;
|
||||
|
||||
var safeParseField = function safeParseField(field, record) {return (
|
||||
getType(field.type).safeParseField(field, record));};exports.safeParseField = safeParseField;
|
||||
|
||||
var validateFieldParse = function validateFieldParse(field, record) {return (
|
||||
(0, _fp.has)(field.name)(record) ?
|
||||
getType(field.type).tryParse(record[field.name]) :
|
||||
(0, _typeHelpers.parsedSuccess)(undefined));}; // fields may be undefined by default
|
||||
exports.validateFieldParse = validateFieldParse;
|
||||
var getDefaultOptions = function getDefaultOptions(type) {return getType(type).getDefaultOptions();};exports.getDefaultOptions = getDefaultOptions;
|
||||
|
||||
var validateTypeConstraints = function validateTypeConstraints(field, record) {return (
|
||||
getType(field.type).validateTypeConstraints(field, record));};exports.validateTypeConstraints = validateTypeConstraints;
|
||||
|
||||
var detectType = function detectType(value) {
|
||||
if ((0, _fp.isString)(value)) return _string["default"];
|
||||
if ((0, _fp.isBoolean)(value)) return _bool["default"];
|
||||
if ((0, _fp.isNumber)(value)) return _number["default"];
|
||||
if ((0, _fp.isDate)(value)) return _datetime["default"];
|
||||
if ((0, _fp.isArray)(value)) return (0, _array["default"])(detectType(value[0]));
|
||||
if ((0, _fp.isObject)(value) && (0, _fp.has)("key")(value) && (0, _fp.has)("value")(value)) return _link["default"];
|
||||
if ((0, _fp.isObject)(value) && (0, _fp.has)("relativePath")(value) && (0, _fp.has)("size")(value))
|
||||
return _file["default"];
|
||||
|
||||
throw new _errors.BadRequestError("cannot determine type: ".concat(JSON.stringify(value)));
|
||||
};exports.detectType = detectType;
|
||||
function schemaToFields(modelSchema) {
|
||||
return Object.keys(modelSchema.properties).map(function (key) {
|
||||
var schema = modelSchema.properties[key];
|
||||
for (var type in allTypes) {
|
||||
if (allTypes[type].isType(schema)) {
|
||||
var field = allTypes[type].fromSchema(schema);
|
||||
field.required = modelSchema.required.includes(key);
|
||||
field.name = key;
|
||||
return field;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,42 +1,26 @@
|
|||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _fp = require("lodash/fp");
|
||||
var _typeHelpers = require("./typeHelpers");
|
||||
var _index = require("../../common/index.js");
|
||||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _default2 = {
|
||||
isType: function isType(schema) {return schema.type === "object" && schema.properties.modelId;},
|
||||
|
||||
fromSchema: function fromSchema(schema) {return {
|
||||
type: "link",
|
||||
modelId: schema.properties.modelId["const"],
|
||||
viewId: schema.properties.viewId["const"],
|
||||
"default": schema["default"] };},
|
||||
|
||||
|
||||
toSchema: function toSchema(field) {return {
|
||||
type: "object",
|
||||
properties: {
|
||||
_id: { type: "string" },
|
||||
viewId: field.viewId ? { "const": field.viewId } : undefined,
|
||||
modelId: field.modelId ? { "const": field.modelId } : undefined },
|
||||
|
||||
required: ["_id"],
|
||||
"default": { _id: "" } };},
|
||||
|
||||
|
||||
|
||||
var linkNothing = function linkNothing() {return "";};
|
||||
|
||||
var linkFunctions = (0, _typeHelpers.typeFunctions)({
|
||||
"default": linkNothing });
|
||||
|
||||
|
||||
var linkTryParse = function linkTryParse(v) {return (
|
||||
(0, _index.switchCase)(
|
||||
[_fp.isString, function (s) {return (0, _typeHelpers.parsedSuccess)(s);}],
|
||||
[_fp.isNull, function () {return (0, _typeHelpers.parsedSuccess)(linkNothing());}],
|
||||
[_fp.isUndefined, function () {return (0, _typeHelpers.parsedSuccess)(linkNothing());}],
|
||||
[_index.defaultCase, function (s) {return (0, _typeHelpers.parsedSuccess)(s.toString());}])(
|
||||
v));};
|
||||
|
||||
var options = {
|
||||
modelId: {
|
||||
defaultValue: "",
|
||||
isValid: _index.isNonEmptyString,
|
||||
requirementDescription: "must choose a model",
|
||||
parse: function parse(s) {return s;} } };
|
||||
|
||||
|
||||
|
||||
var typeConstraints = [];var _default =
|
||||
|
||||
(0, _typeHelpers.getDefaultExport)(
|
||||
"link",
|
||||
linkTryParse,
|
||||
linkFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
"abcd1234",
|
||||
JSON.stringify);exports["default"] = _default;
|
||||
"default": function _default() {return {
|
||||
type: "link",
|
||||
modelId: null,
|
||||
viewId: null };} };exports["default"] = _default2;
|
||||
//# sourceMappingURL=link.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/link.js"],"names":["linkNothing","linkFunctions","linkTryParse","v","isString","s","isNull","isUndefined","defaultCase","toString","options","modelId","defaultValue","isValid","isNonEmptyString","requirementDescription","parse","typeConstraints","JSON","stringify"],"mappings":"uGAAA;AACA;AACA;;;;;;AAMA,IAAMA,WAAW,GAAG,SAAdA,WAAc,WAAM,EAAN,EAApB;;AAEA,IAAMC,aAAa,GAAG,gCAAc;AAClC,aAASD,WADyB,EAAd,CAAtB;;;AAIA,IAAME,YAAY,GAAG,SAAfA,YAAe,CAAAC,CAAC;AACpB;AACE,KAACC,YAAD,EAAW,UAAAC,CAAC,UAAI,gCAAcA,CAAd,CAAJ,EAAZ,CADF;AAEE,KAACC,UAAD,EAAS,oBAAM,gCAAcN,WAAW,EAAzB,CAAN,EAAT,CAFF;AAGE,KAACO,eAAD,EAAc,oBAAM,gCAAcP,WAAW,EAAzB,CAAN,EAAd,CAHF;AAIE,KAACQ,kBAAD,EAAc,UAAAH,CAAC,UAAI,gCAAcA,CAAC,CAACI,QAAF,EAAd,CAAJ,EAAf,CAJF;AAKEN,IAAAA,CALF,CADoB,GAAtB;;AAQA,IAAMO,OAAO,GAAG;AACdC,EAAAA,OAAO,EAAE;AACPC,IAAAA,YAAY,EAAE,EADP;AAEPC,IAAAA,OAAO,EAAEC,uBAFF;AAGPC,IAAAA,sBAAsB,EAAE,qBAHjB;AAIPC,IAAAA,KAAK,EAAE,eAAAX,CAAC,UAAIA,CAAJ,EAJD,EADK,EAAhB;;;;AASA,IAAMY,eAAe,GAAG,EAAxB,C;;AAEe;AACb,MADa;AAEbf,YAFa;AAGbD,aAHa;AAIbS,OAJa;AAKbO,eALa;AAMb,UANa;AAObC,IAAI,CAACC,SAPQ,C","sourcesContent":["import { isString, isUndefined, isNull } from \"lodash/fp\"\nimport { typeFunctions, parsedSuccess, getDefaultExport } from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n isNonEmptyString,\n} from \"../../common/index.js\"\n\nconst linkNothing = () => \"\"\n\nconst linkFunctions = typeFunctions({\n default: linkNothing,\n})\n\nconst linkTryParse = v =>\n switchCase(\n [isString, s => parsedSuccess(s)],\n [isNull, () => parsedSuccess(linkNothing())],\n [isUndefined, () => parsedSuccess(linkNothing())],\n [defaultCase, s => parsedSuccess(s.toString())]\n )(v)\n\nconst options = {\n modelId: {\n defaultValue: \"\",\n isValid: isNonEmptyString,\n requirementDescription: \"must choose a model\",\n parse: s => s,\n },\n}\n\nconst typeConstraints = []\n\nexport default getDefaultExport(\n \"link\",\n linkTryParse,\n linkFunctions,\n options,\n typeConstraints,\n \"abcd1234\",\n JSON.stringify\n)\n"],"file":"link.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/link.js"],"names":["isType","schema","type","properties","modelId","fromSchema","viewId","toSchema","field","_id","undefined","required"],"mappings":"uHAAe;AACbA,EAAAA,MAAM,EAAE,gBAAAC,MAAM,UAAIA,MAAM,CAACC,IAAP,KAAgB,QAAhB,IAA4BD,MAAM,CAACE,UAAP,CAAkBC,OAAlD,EADD;;AAGbC,EAAAA,UAAU,EAAE,oBAAAJ,MAAM,UAAK;AACrBC,MAAAA,IAAI,EAAE,MADe;AAErBE,MAAAA,OAAO,EAAEH,MAAM,CAACE,UAAP,CAAkBC,OAAlB,SAFY;AAGrBE,MAAAA,MAAM,EAAEL,MAAM,CAACE,UAAP,CAAkBG,MAAlB,SAHa;AAIrB,iBAASL,MAAM,WAJM,EAAL,EAHL;;;AAUbM,EAAAA,QAAQ,EAAE,kBAAAC,KAAK,UAAK;AAClBN,MAAAA,IAAI,EAAE,QADY;AAElBC,MAAAA,UAAU,EAAE;AACVM,QAAAA,GAAG,EAAE,EAAEP,IAAI,EAAE,QAAR,EADK;AAEVI,QAAAA,MAAM,EAAEE,KAAK,CAACF,MAAN,GAAe,EAAE,SAAOE,KAAK,CAACF,MAAf,EAAf,GAAyCI,SAFvC;AAGVN,QAAAA,OAAO,EAAEI,KAAK,CAACJ,OAAN,GAAgB,EAAE,SAAOI,KAAK,CAACJ,OAAf,EAAhB,GAA2CM,SAH1C,EAFM;;AAOlBC,MAAAA,QAAQ,EAAE,CAAC,KAAD,CAPQ;AAQlB,iBAAS,EAAEF,GAAG,EAAE,EAAP,EARS,EAAL,EAVF;;;AAqBb,aAAS,4BAAO;AACdP,MAAAA,IAAI,EAAE,MADQ;AAEdE,MAAAA,OAAO,EAAE,IAFK;AAGdE,MAAAA,MAAM,EAAE,IAHM,EAAP,EArBI,E","sourcesContent":["export default {\r\n isType: schema => schema.type === \"object\" && schema.properties.modelId,\r\n\r\n fromSchema: schema => ({\r\n type: \"link\",\r\n modelId: schema.properties.modelId.const,\r\n viewId: schema.properties.viewId.const,\r\n default: schema.default,\r\n }),\r\n\r\n toSchema: field => ({\r\n type: \"object\",\r\n properties: {\r\n _id: { type: \"string\" },\r\n viewId: field.viewId ? { const: field.viewId } : undefined,\r\n modelId: field.modelId ? { const: field.modelId } : undefined,\r\n },\r\n required: [\"_id\"],\r\n default: { _id: \"\" },\r\n }),\r\n\r\n default: () => ({\r\n type: \"link\",\r\n modelId: null,\r\n viewId: null,\r\n }),\r\n}\r\n"],"file":"link.js"}
|
|
@ -1,94 +1,14 @@
|
|||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _fp = require("lodash/fp");
|
||||
var _typeHelpers = require("./typeHelpers");
|
||||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _default2 = {
|
||||
isType: function isType(schema) {return schema.type === "number";},
|
||||
fromSchema: function fromSchema(schema) {return schema;},
|
||||
toSchema: function toSchema(field) {return {
|
||||
type: "number",
|
||||
maximum: field.maximum,
|
||||
minimum: field.minimum,
|
||||
"default": undefined };},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var _index = require("../../common/index.js");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var numberFunctions = (0, _typeHelpers.typeFunctions)({
|
||||
"default": (0, _fp.constant)(null) });
|
||||
|
||||
|
||||
var parseStringtoNumberOrNull = function parseStringtoNumberOrNull(s) {
|
||||
var num = Number(s);
|
||||
return isNaN(num) ? (0, _typeHelpers.parsedFailed)(s) : (0, _typeHelpers.parsedSuccess)(num);
|
||||
};
|
||||
|
||||
var numberTryParse = (0, _index.switchCase)(
|
||||
[_fp.isNumber, _typeHelpers.parsedSuccess],
|
||||
[_fp.isString, parseStringtoNumberOrNull],
|
||||
[_fp.isNull, _typeHelpers.parsedSuccess],
|
||||
[_index.defaultCase, _typeHelpers.parsedFailed]);
|
||||
|
||||
|
||||
var options = {
|
||||
maxValue: {
|
||||
defaultValue: Number.MAX_SAFE_INTEGER,
|
||||
isValid: _index.isSafeInteger,
|
||||
requirementDescription: "must be a valid integer",
|
||||
parse: _index.toNumberOrNull },
|
||||
|
||||
minValue: {
|
||||
defaultValue: 0 - Number.MAX_SAFE_INTEGER,
|
||||
isValid: _index.isSafeInteger,
|
||||
requirementDescription: "must be a valid integer",
|
||||
parse: _index.toNumberOrNull },
|
||||
|
||||
decimalPlaces: {
|
||||
defaultValue: 0,
|
||||
isValid: function isValid(n) {return (0, _index.isSafeInteger)(n) && n >= 0;},
|
||||
requirementDescription: "must be a positive integer",
|
||||
parse: _index.toNumberOrNull } };
|
||||
|
||||
|
||||
|
||||
var getDecimalPlaces = function getDecimalPlaces(val) {
|
||||
var splitDecimal = val.toString().split(".");
|
||||
if (splitDecimal.length === 1) return 0;
|
||||
return splitDecimal[1].length;
|
||||
};
|
||||
|
||||
var typeConstraints = [
|
||||
(0, _typeHelpers.makerule)(
|
||||
function (val, opts) {return (
|
||||
val === null || opts.minValue === null || val >= opts.minValue);},
|
||||
function (val, opts) {return "value (".concat(
|
||||
val.toString(), ") must be greater than or equal to ").concat(
|
||||
opts.minValue);}),
|
||||
|
||||
|
||||
(0, _typeHelpers.makerule)(
|
||||
function (val, opts) {return (
|
||||
val === null || opts.maxValue === null || val <= opts.maxValue);},
|
||||
function (val, opts) {return "value (".concat(
|
||||
val.toString(), ") must be less than or equal to ").concat(
|
||||
opts.minValue, " options");}),
|
||||
|
||||
|
||||
(0, _typeHelpers.makerule)(
|
||||
function (val, opts) {return (
|
||||
val === null || opts.decimalPlaces >= getDecimalPlaces(val));},
|
||||
function (val, opts) {return "value (".concat(
|
||||
val.toString(), ") must have ").concat(
|
||||
opts.decimalPlaces, " decimal places or less");})];var _default =
|
||||
|
||||
|
||||
|
||||
|
||||
(0, _typeHelpers.getDefaultExport)(
|
||||
"number",
|
||||
numberTryParse,
|
||||
numberFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
1,
|
||||
function (num) {return num.toString();});exports["default"] = _default;
|
||||
"default": function _default() {return {
|
||||
type: "number",
|
||||
maximum: null,
|
||||
minimum: null };} };exports["default"] = _default2;
|
||||
//# sourceMappingURL=number.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/number.js"],"names":["numberFunctions","parseStringtoNumberOrNull","s","num","Number","isNaN","numberTryParse","isNumber","parsedSuccess","isString","isNull","defaultCase","parsedFailed","options","maxValue","defaultValue","MAX_SAFE_INTEGER","isValid","isSafeInteger","requirementDescription","parse","toNumberOrNull","minValue","decimalPlaces","n","getDecimalPlaces","val","splitDecimal","toString","split","length","typeConstraints","opts"],"mappings":"uGAAA;AACA;;;;;;;AAOA;;;;;;;AAOA,IAAMA,eAAe,GAAG,gCAAc;AACpC,aAAS,kBAAS,IAAT,CAD2B,EAAd,CAAxB;;;AAIA,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B,CAAAC,CAAC,EAAI;AACrC,MAAMC,GAAG,GAAGC,MAAM,CAACF,CAAD,CAAlB;AACA,SAAOG,KAAK,CAACF,GAAD,CAAL,GAAa,+BAAaD,CAAb,CAAb,GAA+B,gCAAcC,GAAd,CAAtC;AACD,CAHD;;AAKA,IAAMG,cAAc,GAAG;AACrB,CAACC,YAAD,EAAWC,0BAAX,CADqB;AAErB,CAACC,YAAD,EAAWR,yBAAX,CAFqB;AAGrB,CAACS,UAAD,EAASF,0BAAT,CAHqB;AAIrB,CAACG,kBAAD,EAAcC,yBAAd,CAJqB,CAAvB;;;AAOA,IAAMC,OAAO,GAAG;AACdC,EAAAA,QAAQ,EAAE;AACRC,IAAAA,YAAY,EAAEX,MAAM,CAACY,gBADb;AAERC,IAAAA,OAAO,EAAEC,oBAFD;AAGRC,IAAAA,sBAAsB,EAAE,yBAHhB;AAIRC,IAAAA,KAAK,EAAEC,qBAJC,EADI;;AAOdC,EAAAA,QAAQ,EAAE;AACRP,IAAAA,YAAY,EAAE,IAAIX,MAAM,CAACY,gBADjB;AAERC,IAAAA,OAAO,EAAEC,oBAFD;AAGRC,IAAAA,sBAAsB,EAAE,yBAHhB;AAIRC,IAAAA,KAAK,EAAEC,qBAJC,EAPI;;AAadE,EAAAA,aAAa,EAAE;AACbR,IAAAA,YAAY,EAAE,CADD;AAEbE,IAAAA,OAAO,EAAE,iBAAAO,CAAC,UAAI,0BAAcA,CAAd,KAAoBA,CAAC,IAAI,CAA7B,EAFG;AAGbL,IAAAA,sBAAsB,EAAE,4BAHX;AAIbC,IAAAA,KAAK,EAAEC,qBAJM,EAbD,EAAhB;;;;AAqBA,IAAMI,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAAC,GAAG,EAAI;AAC9B,MAAMC,YAAY,GAAGD,GAAG,CAACE,QAAJ,GAAeC,KAAf,CAAqB,GAArB,CAArB;AACA,MAAIF,YAAY,CAACG,MAAb,KAAwB,CAA5B,EAA+B,OAAO,CAAP;AAC/B,SAAOH,YAAY,CAAC,CAAD,CAAZ,CAAgBG,MAAvB;AACD,CAJD;;AAMA,IAAMC,eAAe,GAAG;AACtB;AACE,UAACL,GAAD,EAAMM,IAAN;AACEN,IAAAA,GAAG,KAAK,IAAR,IAAgBM,IAAI,CAACV,QAAL,KAAkB,IAAlC,IAA0CI,GAAG,IAAIM,IAAI,CAACV,QADxD,GADF;AAGE,UAACI,GAAD,EAAMM,IAAN;AACYN,EAAAA,GAAG,CAACE,QAAJ,EADZ;AAEII,EAAAA,IAAI,CAACV,QAFT,GAHF,CADsB;;;AAStB;AACE,UAACI,GAAD,EAAMM,IAAN;AACEN,IAAAA,GAAG,KAAK,IAAR,IAAgBM,IAAI,CAAClB,QAAL,KAAkB,IAAlC,IAA0CY,GAAG,IAAIM,IAAI,CAAClB,QADxD,GADF;AAGE,UAACY,GAAD,EAAMM,IAAN;AACYN,EAAAA,GAAG,CAACE,QAAJ,EADZ;AAEII,EAAAA,IAAI,CAACV,QAFT,eAHF,CATsB;;;AAiBtB;AACE,UAACI,GAAD,EAAMM,IAAN;AACEN,IAAAA,GAAG,KAAK,IAAR,IAAgBM,IAAI,CAACT,aAAL,IAAsBE,gBAAgB,CAACC,GAAD,CADxD,GADF;AAGE,UAACA,GAAD,EAAMM,IAAN;AACYN,EAAAA,GAAG,CAACE,QAAJ,EADZ;AAEII,EAAAA,IAAI,CAACT,aAFT,8BAHF,CAjBsB,CAAxB,C;;;;;AA2Be;AACb,QADa;AAEbjB,cAFa;AAGbN,eAHa;AAIba,OAJa;AAKbkB,eALa;AAMb,CANa;AAOb,UAAA5B,GAAG,UAAIA,GAAG,CAACyB,QAAJ,EAAJ,EAPU,C","sourcesContent":["import { constant, isNumber, isString, isNull } from \"lodash/fp\"\nimport {\n makerule,\n typeFunctions,\n parsedFailed,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n toNumberOrNull,\n isSafeInteger,\n} from \"../../common/index.js\"\n\nconst numberFunctions = typeFunctions({\n default: constant(null),\n})\n\nconst parseStringtoNumberOrNull = s => {\n const num = Number(s)\n return isNaN(num) ? parsedFailed(s) : parsedSuccess(num)\n}\n\nconst numberTryParse = switchCase(\n [isNumber, parsedSuccess],\n [isString, parseStringtoNumberOrNull],\n [isNull, parsedSuccess],\n [defaultCase, parsedFailed]\n)\n\nconst options = {\n maxValue: {\n defaultValue: Number.MAX_SAFE_INTEGER,\n isValid: isSafeInteger,\n requirementDescription: \"must be a valid integer\",\n parse: toNumberOrNull,\n },\n minValue: {\n defaultValue: 0 - Number.MAX_SAFE_INTEGER,\n isValid: isSafeInteger,\n requirementDescription: \"must be a valid integer\",\n parse: toNumberOrNull,\n },\n decimalPlaces: {\n defaultValue: 0,\n isValid: n => isSafeInteger(n) && n >= 0,\n requirementDescription: \"must be a positive integer\",\n parse: toNumberOrNull,\n },\n}\n\nconst getDecimalPlaces = val => {\n const splitDecimal = val.toString().split(\".\")\n if (splitDecimal.length === 1) return 0\n return splitDecimal[1].length\n}\n\nconst typeConstraints = [\n makerule(\n (val, opts) =>\n val === null || opts.minValue === null || val >= opts.minValue,\n (val, opts) =>\n `value (${val.toString()}) must be greater than or equal to ${\n opts.minValue\n }`\n ),\n makerule(\n (val, opts) =>\n val === null || opts.maxValue === null || val <= opts.maxValue,\n (val, opts) =>\n `value (${val.toString()}) must be less than or equal to ${\n opts.minValue\n } options`\n ),\n makerule(\n (val, opts) =>\n val === null || opts.decimalPlaces >= getDecimalPlaces(val),\n (val, opts) =>\n `value (${val.toString()}) must have ${\n opts.decimalPlaces\n } decimal places or less`\n ),\n]\n\nexport default getDefaultExport(\n \"number\",\n numberTryParse,\n numberFunctions,\n options,\n typeConstraints,\n 1,\n num => num.toString()\n)\n"],"file":"number.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/number.js"],"names":["isType","schema","type","fromSchema","toSchema","field","maximum","minimum","undefined"],"mappings":"uHAAe;AACbA,EAAAA,MAAM,EAAE,gBAAAC,MAAM,UAAIA,MAAM,CAACC,IAAP,KAAgB,QAApB,EADD;AAEbC,EAAAA,UAAU,EAAE,oBAAAF,MAAM,UAAIA,MAAJ,EAFL;AAGbG,EAAAA,QAAQ,EAAE,kBAAAC,KAAK,UAAK;AAClBH,MAAAA,IAAI,EAAE,QADY;AAElBI,MAAAA,OAAO,EAAED,KAAK,CAACC,OAFG;AAGlBC,MAAAA,OAAO,EAAEF,KAAK,CAACE,OAHG;AAIlB,iBAASC,SAJS,EAAL,EAHF;;AASb,aAAS,4BAAO;AACdN,MAAAA,IAAI,EAAE,QADQ;AAEdI,MAAAA,OAAO,EAAE,IAFK;AAGdC,MAAAA,OAAO,EAAE,IAHK,EAAP,EATI,E","sourcesContent":["export default {\r\n isType: schema => schema.type === \"number\",\r\n fromSchema: schema => schema,\r\n toSchema: field => ({\r\n type: \"number\",\r\n maximum: field.maximum,\r\n minimum: field.minimum,\r\n default: undefined,\r\n }),\r\n default: () => ({\r\n type: \"number\",\r\n maximum: null,\r\n minimum: null,\r\n }),\r\n}\r\n"],"file":"number.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/object.js"],"names":["objectFunctions","definition","allTypes","initialise","defClone","k","getNew","parseObject","record","type","safeParseValue","objectTryParse","isNull","parsedSuccess","isObject","defaultCase","parsedFailed","typeName","defaultOptions","typeConstraints","sampleValue","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;AAMA;;AAEA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAACC,UAAD,EAAaC,QAAb;AACtB,oCAAc;AACZ,iBAAS,sBAAS,IAAT,CADG;AAEZC,MAAAA,UAAU,EAAE;AACV,wBAAE,kBAAKF,UAAL,CAAF,EAAoB;AAClB,2BAAI,YAAM;AACR,gBAAMG,QAAQ,GAAG,mBAAMH,UAAN,CAAjB;AACA,iBAAK,IAAMI,CAAX,IAAgBD,QAAhB,EAA0B;AACxBA,cAAAA,QAAQ,CAACC,CAAD,CAAR,GAAcH,QAAQ,CAACG,CAAD,CAAR,CAAYC,MAAZ,EAAd;AACD;AACD,mBAAOF,QAAP;AACD,WAND,CADkB,CAApB,CADU,GAFA,EAAd,CADsB,GAAxB;;;;AAeA,IAAMG,WAAW,GAAG,SAAdA,WAAc,CAACN,UAAD,EAAaC,QAAb,UAA0B,UAAAM,MAAM,EAAI;AACtD,QAAMJ,QAAQ,GAAG,mBAAMH,UAAN,CAAjB;AACA,SAAK,IAAMI,CAAX,IAAgBD,QAAhB,EAA0B;AACxB,UAAMK,IAAI,GAAGP,QAAQ,CAACE,QAAQ,CAACC,CAAD,CAAT,CAArB;AACAD,MAAAA,QAAQ,CAACC,CAAD,CAAR,GAAc,iBAAIG,MAAJ,EAAYH,CAAZ;AACVI,MAAAA,IAAI,CAACC,cAAL,CAAoBF,MAAM,CAACH,CAAD,CAA1B,CADU;AAEVI,MAAAA,IAAI,CAACH,MAAL,EAFJ;AAGD;AACD,WAAO,gCAAcF,QAAd,CAAP;AACD,GATmB,EAApB;;AAWA,IAAMO,cAAc,GAAG,SAAjBA,cAAiB,CAACV,UAAD,EAAaC,QAAb;AACrB;AACE,KAACU,cAAD,EAASC,0BAAT,CADF;AAEE,KAACC,gBAAD,EAAWP,WAAW,CAACN,UAAD,EAAaC,QAAb,CAAtB,CAFF;AAGE,KAACa,kBAAD,EAAcC,yBAAd,CAHF,CADqB,GAAvB,C;;;AAOe;AACbC,QADa;AAEbhB,UAFa;AAGbC,QAHa;AAIbgB,cAJa;AAKbC,eALa;AAMbC,WANa;;AAQb;AACEH,IAAAA,QADF;AAEEN,IAAAA,cAAc,CAACV,UAAD,EAAaC,QAAb,CAFhB;AAGEF,IAAAA,eAAe,CAACC,UAAD,EAAaC,QAAb,CAHjB;AAIEgB,IAAAA,cAJF;AAKEC,IAAAA,eALF;AAMEC,IAAAA,WANF;AAOEC,IAAAA,IAAI,CAACC,SAPP,CARa,G","sourcesContent":["import { keys, isObject, has, clone, map, isNull, constant } from \"lodash\"\nimport {\n typeFunctions,\n parsedFailed,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport { switchCase, defaultCase, $ } from \"../../common/index.js\"\n\nconst objectFunctions = (definition, allTypes) =>\n typeFunctions({\n default: constant(null),\n initialise: () =>\n $(keys(definition), [\n map(() => {\n const defClone = clone(definition)\n for (const k in defClone) {\n defClone[k] = allTypes[k].getNew()\n }\n return defClone\n }),\n ]),\n })\n\nconst parseObject = (definition, allTypes) => record => {\n const defClone = clone(definition)\n for (const k in defClone) {\n const type = allTypes[defClone[k]]\n defClone[k] = has(record, k)\n ? type.safeParseValue(record[k])\n : type.getNew()\n }\n return parsedSuccess(defClone)\n}\n\nconst objectTryParse = (definition, allTypes) =>\n switchCase(\n [isNull, parsedSuccess],\n [isObject, parseObject(definition, allTypes)],\n [defaultCase, parsedFailed]\n )\n\nexport default (\n typeName,\n definition,\n allTypes,\n defaultOptions,\n typeConstraints,\n sampleValue\n) =>\n getDefaultExport(\n typeName,\n objectTryParse(definition, allTypes),\n objectFunctions(definition, allTypes),\n defaultOptions,\n typeConstraints,\n sampleValue,\n JSON.stringify\n )\n"],"file":"object.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/object.js"],"names":["objectFunctions","definition","allTypes","initialise","defClone","k","getNew","parseObject","record","type","safeParseValue","objectTryParse","isNull","parsedSuccess","isObject","defaultCase","parsedFailed","typeName","defaultOptions","typeConstraints","sampleValue","JSON","stringify"],"mappings":"uGAAA;AACA;;;;;;AAMA;;AAEA,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAACC,UAAD,EAAaC,QAAb;AACtB,oCAAc;AACZ,iBAAS,sBAAS,IAAT,CADG;AAEZC,MAAAA,UAAU,EAAE;AACV,wBAAE,kBAAKF,UAAL,CAAF,EAAoB;AAClB,2BAAI,YAAM;AACR,gBAAMG,QAAQ,GAAG,mBAAMH,UAAN,CAAjB;AACA,iBAAK,IAAMI,CAAX,IAAgBD,QAAhB,EAA0B;AACxBA,cAAAA,QAAQ,CAACC,CAAD,CAAR,GAAcH,QAAQ,CAACG,CAAD,CAAR,CAAYC,MAAZ,EAAd;AACD;AACD,mBAAOF,QAAP;AACD,WAND,CADkB,CAApB,CADU,GAFA,EAAd,CADsB,GAAxB;;;;AAeA,IAAMG,WAAW,GAAG,SAAdA,WAAc,CAACN,UAAD,EAAaC,QAAb,UAA0B,UAAAM,MAAM,EAAI;AACtD,QAAMJ,QAAQ,GAAG,mBAAMH,UAAN,CAAjB;AACA,SAAK,IAAMI,CAAX,IAAgBD,QAAhB,EAA0B;AACxB,UAAMK,IAAI,GAAGP,QAAQ,CAACE,QAAQ,CAACC,CAAD,CAAT,CAArB;AACAD,MAAAA,QAAQ,CAACC,CAAD,CAAR,GAAc,iBAAIG,MAAJ,EAAYH,CAAZ;AACVI,MAAAA,IAAI,CAACC,cAAL,CAAoBF,MAAM,CAACH,CAAD,CAA1B,CADU;AAEVI,MAAAA,IAAI,CAACH,MAAL,EAFJ;AAGD;AACD,WAAO,gCAAcF,QAAd,CAAP;AACD,GATmB,EAApB;;AAWA,IAAMO,cAAc,GAAG,SAAjBA,cAAiB,CAACV,UAAD,EAAaC,QAAb;AACrB;AACE,KAACU,cAAD,EAASC,0BAAT,CADF;AAEE,KAACC,gBAAD,EAAWP,WAAW,CAACN,UAAD,EAAaC,QAAb,CAAtB,CAFF;AAGE,KAACa,kBAAD,EAAcC,yBAAd,CAHF,CADqB,GAAvB,C;;;AAOe;AACbC,QADa;AAEbhB,UAFa;AAGbC,QAHa;AAIbgB,cAJa;AAKbC,eALa;AAMbC,WANa;;AAQb;AACEH,IAAAA,QADF;AAEEN,IAAAA,cAAc,CAACV,UAAD,EAAaC,QAAb,CAFhB;AAGEF,IAAAA,eAAe,CAACC,UAAD,EAAaC,QAAb,CAHjB;AAIEgB,IAAAA,cAJF;AAKEC,IAAAA,eALF;AAMEC,IAAAA,WANF;AAOEC,IAAAA,IAAI,CAACC,SAPP,CARa,G","sourcesContent":["import { keys, isObject, has, clone, map, isNull, constant } from \"lodash\"\r\nimport {\r\n typeFunctions,\r\n parsedFailed,\r\n parsedSuccess,\r\n getDefaultExport,\r\n} from \"./typeHelpers\"\r\nimport { switchCase, defaultCase, $ } from \"../../common/index.js\"\r\n\r\nconst objectFunctions = (definition, allTypes) =>\r\n typeFunctions({\r\n default: constant(null),\r\n initialise: () =>\r\n $(keys(definition), [\r\n map(() => {\r\n const defClone = clone(definition)\r\n for (const k in defClone) {\r\n defClone[k] = allTypes[k].getNew()\r\n }\r\n return defClone\r\n }),\r\n ]),\r\n })\r\n\r\nconst parseObject = (definition, allTypes) => record => {\r\n const defClone = clone(definition)\r\n for (const k in defClone) {\r\n const type = allTypes[defClone[k]]\r\n defClone[k] = has(record, k)\r\n ? type.safeParseValue(record[k])\r\n : type.getNew()\r\n }\r\n return parsedSuccess(defClone)\r\n}\r\n\r\nconst objectTryParse = (definition, allTypes) =>\r\n switchCase(\r\n [isNull, parsedSuccess],\r\n [isObject, parseObject(definition, allTypes)],\r\n [defaultCase, parsedFailed]\r\n )\r\n\r\nexport default (\r\n typeName,\r\n definition,\r\n allTypes,\r\n defaultOptions,\r\n typeConstraints,\r\n sampleValue\r\n) =>\r\n getDefaultExport(\r\n typeName,\r\n objectTryParse(definition, allTypes),\r\n objectFunctions(definition, allTypes),\r\n defaultOptions,\r\n typeConstraints,\r\n sampleValue,\r\n JSON.stringify\r\n )\r\n"],"file":"object.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../../src/schema/types/string.js"],"names":["stringFunctions","stringTryParse","isString","parsedSuccess","isNull","defaultCase","v","toString","options","maxLength","defaultValue","isValid","n","requirementDescription","parse","toNumberOrNull","values","length","s","allowDeclaredValuesOnly","isBoolean","toBoolOrNull","typeConstraints","val","opts","str"],"mappings":"uGAAA;AACA;;;;;;AAMA;;;;;;;;;AASA,IAAMA,eAAe,GAAG,gCAAc;AACpC,aAAS,kBAAS,IAAT,CAD2B,EAAd,CAAxB;;;AAIA,IAAMC,cAAc,GAAG;AACrB,CAACC,YAAD,EAAWC,0BAAX,CADqB;AAErB,CAACC,UAAD,EAASD,0BAAT,CAFqB;AAGrB,CAACE,kBAAD,EAAc,UAAAC,CAAC,UAAI,gCAAcA,CAAC,CAACC,QAAF,EAAd,CAAJ,EAAf,CAHqB,CAAvB;;;AAMA,IAAMC,OAAO,GAAG;AACdC,EAAAA,SAAS,EAAE;AACTC,IAAAA,YAAY,EAAE,IADL;AAETC,IAAAA,OAAO,EAAE,iBAAAC,CAAC,UAAIA,CAAC,KAAK,IAAN,IAAe,0BAAcA,CAAd,KAAoBA,CAAC,GAAG,CAA3C,EAFD;AAGTC,IAAAA,sBAAsB;AACpB,uEAJO;AAKTC,IAAAA,KAAK,EAAEC,qBALE,EADG;;AAQdC,EAAAA,MAAM,EAAE;AACNN,IAAAA,YAAY,EAAE,IADR;AAENC,IAAAA,OAAO,EAAE,iBAAAL,CAAC;AACRA,QAAAA,CAAC,KAAK,IAAN,IAAe,4BAAgBA,CAAhB,KAAsBA,CAAC,CAACW,MAAF,GAAW,CAAjC,IAAsCX,CAAC,CAACW,MAAF,GAAW,KADxD,GAFJ;AAINJ,IAAAA,sBAAsB;AACpB,0EALI;AAMNC,IAAAA,KAAK,EAAE,eAAAI,CAAC,UAAIA,CAAJ,EANF,EARM;;AAgBdC,EAAAA,uBAAuB,EAAE;AACvBT,IAAAA,YAAY,EAAE,KADS;AAEvBC,IAAAA,OAAO,EAAES,aAFc;AAGvBP,IAAAA,sBAAsB,EAAE,+CAHD;AAIvBC,IAAAA,KAAK,EAAEO,mBAJgB,EAhBX,EAAhB;;;;AAwBA,IAAMC,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR,IAAgBC,IAAI,CAACf,SAAL,KAAmB,IAAnC,IAA2Cc,GAAG,CAACN,MAAJ,IAAcO,IAAI,CAACf,SADhE,GADF;AAGE,UAACc,GAAD,EAAMC,IAAN,oDAAkDA,IAAI,CAACf,SAAvD,GAHF,CADsB;;AAMtB;AACE,UAACc,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR;AACAC,IAAAA,IAAI,CAACL,uBAAL,KAAiC,KADjC;AAEA,sBAASI,GAAT,EAAcC,IAAI,CAACR,MAAnB,CAHF,GADF;AAKE,UAAAO,GAAG,sBAAQA,GAAR,sDALL,CANsB,CAAxB,C;;;;AAee;AACb,QADa;AAEbtB,cAFa;AAGbD,eAHa;AAIbQ,OAJa;AAKbc,eALa;AAMb,OANa;AAOb,UAAAG,GAAG,UAAIA,GAAJ,EAPU,C","sourcesContent":["import { constant, isString, isNull, includes, isBoolean } from \"lodash/fp\"\nimport {\n typeFunctions,\n makerule,\n parsedSuccess,\n getDefaultExport,\n} from \"./typeHelpers\"\nimport {\n switchCase,\n defaultCase,\n toBoolOrNull,\n toNumberOrNull,\n isSafeInteger,\n isArrayOfString,\n} from \"../../common/index.js\"\n\nconst stringFunctions = typeFunctions({\n default: constant(null),\n})\n\nconst stringTryParse = switchCase(\n [isString, parsedSuccess],\n [isNull, parsedSuccess],\n [defaultCase, v => parsedSuccess(v.toString())]\n)\n\nconst options = {\n maxLength: {\n defaultValue: null,\n isValid: n => n === null || (isSafeInteger(n) && n > 0),\n requirementDescription:\n \"max length must be null (no limit) or a greater than zero integer\",\n parse: toNumberOrNull,\n },\n values: {\n defaultValue: null,\n isValid: v =>\n v === null || (isArrayOfString(v) && v.length > 0 && v.length < 10000),\n requirementDescription:\n \"'values' must be null (no values) or an array of at least one string\",\n parse: s => s,\n },\n allowDeclaredValuesOnly: {\n defaultValue: false,\n isValid: isBoolean,\n requirementDescription: \"allowDeclaredValuesOnly must be true or false\",\n parse: toBoolOrNull,\n },\n}\n\nconst typeConstraints = [\n makerule(\n (val, opts) =>\n val === null || opts.maxLength === null || val.length <= opts.maxLength,\n (val, opts) => `value exceeds maximum length of ${opts.maxLength}`\n ),\n makerule(\n (val, opts) =>\n val === null ||\n opts.allowDeclaredValuesOnly === false ||\n includes(val)(opts.values),\n val => `\"${val}\" does not exist in the list of allowed values`\n ),\n]\n\nexport default getDefaultExport(\n \"string\",\n stringTryParse,\n stringFunctions,\n options,\n typeConstraints,\n \"abcde\",\n str => str\n)\n"],"file":"string.js"}
|
||||
{"version":3,"sources":["../../../src/schema/types/string.js"],"names":["stringFunctions","stringTryParse","isString","parsedSuccess","isNull","defaultCase","v","toString","options","maxLength","defaultValue","isValid","n","requirementDescription","parse","toNumberOrNull","values","length","s","allowDeclaredValuesOnly","isBoolean","toBoolOrNull","typeConstraints","val","opts","str"],"mappings":"uGAAA;AACA;;;;;;AAMA;;;;;;;;;AASA,IAAMA,eAAe,GAAG,gCAAc;AACpC,aAAS,kBAAS,IAAT,CAD2B,EAAd,CAAxB;;;AAIA,IAAMC,cAAc,GAAG;AACrB,CAACC,YAAD,EAAWC,0BAAX,CADqB;AAErB,CAACC,UAAD,EAASD,0BAAT,CAFqB;AAGrB,CAACE,kBAAD,EAAc,UAAAC,CAAC,UAAI,gCAAcA,CAAC,CAACC,QAAF,EAAd,CAAJ,EAAf,CAHqB,CAAvB;;;AAMA,IAAMC,OAAO,GAAG;AACdC,EAAAA,SAAS,EAAE;AACTC,IAAAA,YAAY,EAAE,IADL;AAETC,IAAAA,OAAO,EAAE,iBAAAC,CAAC,UAAIA,CAAC,KAAK,IAAN,IAAe,0BAAcA,CAAd,KAAoBA,CAAC,GAAG,CAA3C,EAFD;AAGTC,IAAAA,sBAAsB;AACpB,uEAJO;AAKTC,IAAAA,KAAK,EAAEC,qBALE,EADG;;AAQdC,EAAAA,MAAM,EAAE;AACNN,IAAAA,YAAY,EAAE,IADR;AAENC,IAAAA,OAAO,EAAE,iBAAAL,CAAC;AACRA,QAAAA,CAAC,KAAK,IAAN,IAAe,4BAAgBA,CAAhB,KAAsBA,CAAC,CAACW,MAAF,GAAW,CAAjC,IAAsCX,CAAC,CAACW,MAAF,GAAW,KADxD,GAFJ;AAINJ,IAAAA,sBAAsB;AACpB,0EALI;AAMNC,IAAAA,KAAK,EAAE,eAAAI,CAAC,UAAIA,CAAJ,EANF,EARM;;AAgBdC,EAAAA,uBAAuB,EAAE;AACvBT,IAAAA,YAAY,EAAE,KADS;AAEvBC,IAAAA,OAAO,EAAES,aAFc;AAGvBP,IAAAA,sBAAsB,EAAE,+CAHD;AAIvBC,IAAAA,KAAK,EAAEO,mBAJgB,EAhBX,EAAhB;;;;AAwBA,IAAMC,eAAe,GAAG;AACtB;AACE,UAACC,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR,IAAgBC,IAAI,CAACf,SAAL,KAAmB,IAAnC,IAA2Cc,GAAG,CAACN,MAAJ,IAAcO,IAAI,CAACf,SADhE,GADF;AAGE,UAACc,GAAD,EAAMC,IAAN,oDAAkDA,IAAI,CAACf,SAAvD,GAHF,CADsB;;AAMtB;AACE,UAACc,GAAD,EAAMC,IAAN;AACED,IAAAA,GAAG,KAAK,IAAR;AACAC,IAAAA,IAAI,CAACL,uBAAL,KAAiC,KADjC;AAEA,sBAASI,GAAT,EAAcC,IAAI,CAACR,MAAnB,CAHF,GADF;AAKE,UAAAO,GAAG,sBAAQA,GAAR,sDALL,CANsB,CAAxB,C;;;;AAee;AACb,QADa;AAEbtB,cAFa;AAGbD,eAHa;AAIbQ,OAJa;AAKbc,eALa;AAMb,OANa;AAOb,UAAAG,GAAG,UAAIA,GAAJ,EAPU,C","sourcesContent":["import { constant, isString, isNull, includes, isBoolean } from \"lodash/fp\"\r\nimport {\r\n typeFunctions,\r\n makerule,\r\n parsedSuccess,\r\n getDefaultExport,\r\n} from \"./typeHelpers\"\r\nimport {\r\n switchCase,\r\n defaultCase,\r\n toBoolOrNull,\r\n toNumberOrNull,\r\n isSafeInteger,\r\n isArrayOfString,\r\n} from \"../../common/index.js\"\r\n\r\nconst stringFunctions = typeFunctions({\r\n default: constant(null),\r\n})\r\n\r\nconst stringTryParse = switchCase(\r\n [isString, parsedSuccess],\r\n [isNull, parsedSuccess],\r\n [defaultCase, v => parsedSuccess(v.toString())]\r\n)\r\n\r\nconst options = {\r\n maxLength: {\r\n defaultValue: null,\r\n isValid: n => n === null || (isSafeInteger(n) && n > 0),\r\n requirementDescription:\r\n \"max length must be null (no limit) or a greater than zero integer\",\r\n parse: toNumberOrNull,\r\n },\r\n values: {\r\n defaultValue: null,\r\n isValid: v =>\r\n v === null || (isArrayOfString(v) && v.length > 0 && v.length < 10000),\r\n requirementDescription:\r\n \"'values' must be null (no values) or an array of at least one string\",\r\n parse: s => s,\r\n },\r\n allowDeclaredValuesOnly: {\r\n defaultValue: false,\r\n isValid: isBoolean,\r\n requirementDescription: \"allowDeclaredValuesOnly must be true or false\",\r\n parse: toBoolOrNull,\r\n },\r\n}\r\n\r\nconst typeConstraints = [\r\n makerule(\r\n (val, opts) =>\r\n val === null || opts.maxLength === null || val.length <= opts.maxLength,\r\n (val, opts) => `value exceeds maximum length of ${opts.maxLength}`\r\n ),\r\n makerule(\r\n (val, opts) =>\r\n val === null ||\r\n opts.allowDeclaredValuesOnly === false ||\r\n includes(val)(opts.values),\r\n val => `\"${val}\" does not exist in the list of allowed values`\r\n ),\r\n]\r\n\r\nexport default getDefaultExport(\r\n \"string\",\r\n stringTryParse,\r\n stringFunctions,\r\n options,\r\n typeConstraints,\r\n \"abcde\",\r\n str => str\r\n)\r\n"],"file":"string.js"}
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/schema/views.js"],"names":["newView","modelId","id","name"],"mappings":"oGAAA;;AAEO,IAAMA,OAAO,GAAG,SAAVA,OAAU,QAACC,OAAD,uEAAW,IAAX,QAAqB;AAC1CC,IAAAA,EAAE,EAAE,wBADsC;AAE1CC,IAAAA,IAAI,EAAE,EAFoC;AAG1CF,IAAAA,OAAO,EAAPA,OAH0C,EAArB,EAAhB,C","sourcesContent":["import { generate } from \"shortid\"\n\nexport const newView = (modelId = null) => ({\n id: generate(),\n name: \"\",\n modelId,\n})\n"],"file":"views.js"}
|
||||
{"version":3,"sources":["../../src/schema/views.js"],"names":["newView","modelId","id","name"],"mappings":"oGAAA;;AAEO,IAAMA,OAAO,GAAG,SAAVA,OAAU,QAACC,OAAD,uEAAW,IAAX,QAAqB;AAC1CC,IAAAA,EAAE,EAAE,wBADsC;AAE1CC,IAAAA,IAAI,EAAE,EAFoC;AAG1CF,IAAAA,OAAO,EAAPA,OAH0C,EAArB,EAAhB,C","sourcesContent":["import { generate } from \"shortid\"\r\n\r\nexport const newView = (modelId = null) => ({\r\n id: generate(),\r\n name: \"\",\r\n modelId,\r\n})\r\n"],"file":"views.js"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../../src/schemaValidation/index.js"],"names":["ajv","Ajv"],"mappings":"4LAAA;;AAEA,IAAMA,GAAG,GAAG,IAAIC,eAAJ,EAAZ,C;;AAEeD,G","sourcesContent":["import Ajv from \"ajv\";\n\nconst ajv = new Ajv();\n\nexport default ajv;"],"file":"index.js"}
|
||||
{"version":3,"sources":["../../src/schemaValidation/index.js"],"names":["ajv","Ajv"],"mappings":"4LAAA;;AAEA,IAAMA,GAAG,GAAG,IAAIC,eAAJ,EAAZ,C;;AAEeD,G","sourcesContent":["import Ajv from \"ajv\";\r\n\r\nconst ajv = new Ajv();\r\n\r\nexport default ajv;"],"file":"index.js"}
|
|
@ -1,16 +1,15 @@
|
|||
import { generate } from "shortid"
|
||||
import { getNewFieldValue } from "../schema/types"
|
||||
|
||||
export const getNewRecord = (schema, modelName) => {
|
||||
const model = schema.findModel(modelName)
|
||||
|
||||
const record = {
|
||||
_id: generate(),
|
||||
_modelId: model.id,
|
||||
modelId: model._id,
|
||||
}
|
||||
|
||||
for (let field of model.fields) {
|
||||
record[field.name] = getNewFieldValue(field)
|
||||
for (let field in model.schema.properties) {
|
||||
record[field] = field.default
|
||||
}
|
||||
|
||||
return record
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import { generate } from "shortid"
|
||||
|
||||
export const newModel = () => ({
|
||||
id: generate(),
|
||||
_id: generate(),
|
||||
name: "",
|
||||
fields: [],
|
||||
validationRules: [],
|
||||
primaryField: "",
|
||||
views: [],
|
||||
type: "model",
|
||||
key: "name",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
required: ["name"],
|
||||
},
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
import { map, constant, isArray } from "lodash/fp"
|
||||
import {
|
||||
typeFunctions,
|
||||
makerule,
|
||||
parsedFailed,
|
||||
getDefaultExport,
|
||||
parsedSuccess,
|
||||
} from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
toNumberOrNull,
|
||||
$$,
|
||||
isSafeInteger,
|
||||
} from "../../common/index.js"
|
||||
|
||||
const arrayFunctions = () =>
|
||||
typeFunctions({
|
||||
default: constant([]),
|
||||
})
|
||||
|
||||
const mapToParsedArrary = type =>
|
||||
$$(
|
||||
map(i => type.safeParseValue(i)),
|
||||
parsedSuccess
|
||||
)
|
||||
|
||||
const arrayTryParse = type =>
|
||||
switchCase([isArray, mapToParsedArrary(type)], [defaultCase, parsedFailed])
|
||||
|
||||
const typeName = type => `array<${type}>`
|
||||
|
||||
const options = {
|
||||
maxLength: {
|
||||
defaultValue: 10000,
|
||||
isValid: isSafeInteger,
|
||||
requirementDescription: "must be a positive integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
minLength: {
|
||||
defaultValue: 0,
|
||||
isValid: n => isSafeInteger(n) && n >= 0,
|
||||
requirementDescription: "must be a positive integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
}
|
||||
|
||||
const typeConstraints = [
|
||||
makerule(
|
||||
(val, opts) => val === null || val.length >= opts.minLength,
|
||||
(val, opts) => `must choose ${opts.minLength} or more options`
|
||||
),
|
||||
makerule(
|
||||
(val, opts) => val === null || val.length <= opts.maxLength,
|
||||
(val, opts) => `cannot choose more than ${opts.maxLength} options`
|
||||
),
|
||||
]
|
||||
|
||||
export default type =>
|
||||
getDefaultExport(
|
||||
typeName(type.name),
|
||||
arrayTryParse(type),
|
||||
arrayFunctions(type),
|
||||
options,
|
||||
typeConstraints,
|
||||
[type.sampleValue],
|
||||
JSON.stringify
|
||||
)
|
|
@ -1,52 +0,0 @@
|
|||
import { constant, isBoolean, isNull } from "lodash/fp"
|
||||
import {
|
||||
typeFunctions,
|
||||
makerule,
|
||||
parsedFailed,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
isOneOf,
|
||||
toBoolOrNull,
|
||||
} from "../../common/index.js"
|
||||
|
||||
const boolFunctions = typeFunctions({
|
||||
default: constant(null),
|
||||
})
|
||||
|
||||
const boolTryParse = switchCase(
|
||||
[isBoolean, parsedSuccess],
|
||||
[isNull, parsedSuccess],
|
||||
[isOneOf("true", "1", "yes", "on"), () => parsedSuccess(true)],
|
||||
[isOneOf("false", "0", "no", "off"), () => parsedSuccess(false)],
|
||||
[defaultCase, parsedFailed]
|
||||
)
|
||||
|
||||
const options = {
|
||||
allowNulls: {
|
||||
defaultValue: true,
|
||||
isValid: isBoolean,
|
||||
requirementDescription: "must be a true or false",
|
||||
parse: toBoolOrNull,
|
||||
},
|
||||
}
|
||||
|
||||
const typeConstraints = [
|
||||
makerule(
|
||||
(val, opts) => opts.allowNulls === true || val !== null,
|
||||
() => "field cannot be null"
|
||||
),
|
||||
]
|
||||
|
||||
export default getDefaultExport(
|
||||
"bool",
|
||||
boolTryParse,
|
||||
boolFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
true,
|
||||
JSON.stringify
|
||||
)
|
|
@ -0,0 +1,12 @@
|
|||
export default {
|
||||
isType: schema => schema.type === "boolean",
|
||||
fromSchema: schema => schema,
|
||||
toSchema: field => ({
|
||||
type: "boolean",
|
||||
default: field.default,
|
||||
}),
|
||||
default: () => ({
|
||||
type: "boolean",
|
||||
default: false,
|
||||
}),
|
||||
}
|
|
@ -1,78 +1,19 @@
|
|||
import { constant, isDate, isString, isNull } from "lodash/fp"
|
||||
import {
|
||||
makerule,
|
||||
typeFunctions,
|
||||
parsedFailed,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import { switchCase, defaultCase, toDateOrNull } from "../../common"
|
||||
export default {
|
||||
isType: schema =>
|
||||
schema.anyOf &&
|
||||
schema.anyOf.filter(s => s.type === "string" && s.format === "date-time")
|
||||
.length > 0,
|
||||
|
||||
const dateFunctions = typeFunctions({
|
||||
default: constant(null),
|
||||
now: () => new Date(),
|
||||
})
|
||||
|
||||
const isValidDate = d => d instanceof Date && !isNaN(d)
|
||||
|
||||
const parseStringToDate = s =>
|
||||
switchCase(
|
||||
[isValidDate, parsedSuccess],
|
||||
[defaultCase, parsedFailed]
|
||||
)(new Date(s))
|
||||
|
||||
const isNullOrEmpty = d => isNull(d) || (d || "").toString() === ""
|
||||
|
||||
const isDateOrEmpty = d => isDate(d) || isNullOrEmpty(d)
|
||||
|
||||
const dateTryParse = switchCase(
|
||||
[isDateOrEmpty, parsedSuccess],
|
||||
[isString, parseStringToDate],
|
||||
[defaultCase, parsedFailed]
|
||||
)
|
||||
|
||||
const options = {
|
||||
maxValue: {
|
||||
defaultValue: null,
|
||||
//defaultValue: new Date(32503680000000),
|
||||
isValid: isDateOrEmpty,
|
||||
requirementDescription: "must be a valid date",
|
||||
parse: toDateOrNull,
|
||||
},
|
||||
minValue: {
|
||||
defaultValue: null,
|
||||
//defaultValue: new Date(-8520336000000),
|
||||
isValid: isDateOrEmpty,
|
||||
requirementDescription: "must be a valid date",
|
||||
parse: toDateOrNull,
|
||||
},
|
||||
fromSchema: schema => ({
|
||||
type: "datetime",
|
||||
default: schema.default,
|
||||
}),
|
||||
toSchema: () => ({
|
||||
anyOf: [{ type: "string", format: "date-time" }, { const: "" }],
|
||||
default: "",
|
||||
}),
|
||||
default: () => ({
|
||||
type: "datetime",
|
||||
default: "",
|
||||
}),
|
||||
}
|
||||
|
||||
const typeConstraints = [
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || isNullOrEmpty(opts.minValue) || val >= opts.minValue,
|
||||
(val, opts) =>
|
||||
`value (${val.toString()}) must be greater than or equal to ${
|
||||
opts.minValue
|
||||
}`
|
||||
),
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || isNullOrEmpty(opts.maxValue) || val <= opts.maxValue,
|
||||
(val, opts) =>
|
||||
`value (${val.toString()}) must be less than or equal to ${
|
||||
opts.minValue
|
||||
} options`
|
||||
),
|
||||
]
|
||||
|
||||
export default getDefaultExport(
|
||||
"datetime",
|
||||
dateTryParse,
|
||||
dateFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
new Date(1984, 4, 1),
|
||||
date => JSON.stringify(date).replace(new RegExp('"', "g"), "")
|
||||
)
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
import { last, has, isString, intersection, isNull, isNumber } from "lodash/fp"
|
||||
import {
|
||||
typeFunctions,
|
||||
parsedFailed,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
none,
|
||||
$,
|
||||
splitKey,
|
||||
} from "../../common/index.js"
|
||||
|
||||
const illegalCharacters = "*?\\/:<>|\0\b\f\v"
|
||||
|
||||
export const isLegalFilename = filePath => {
|
||||
const fn = fileName(filePath)
|
||||
return (
|
||||
fn.length <= 255 &&
|
||||
intersection(fn.split(""))(illegalCharacters.split("")).length === 0 &&
|
||||
none(f => f === "..")(splitKey(filePath))
|
||||
)
|
||||
}
|
||||
|
||||
const fileNothing = () => ({ relativePath: "", size: 0 })
|
||||
|
||||
const fileFunctions = typeFunctions({
|
||||
default: fileNothing,
|
||||
})
|
||||
|
||||
const fileTryParse = v =>
|
||||
switchCase(
|
||||
[isValidFile, parsedSuccess],
|
||||
[isNull, () => parsedSuccess(fileNothing())],
|
||||
[defaultCase, parsedFailed]
|
||||
)(v)
|
||||
|
||||
const fileName = filePath => $(filePath, [splitKey, last])
|
||||
|
||||
const isValidFile = f =>
|
||||
!isNull(f) &&
|
||||
has("relativePath")(f) &&
|
||||
has("size")(f) &&
|
||||
isNumber(f.size) &&
|
||||
isString(f.relativePath) &&
|
||||
isLegalFilename(f.relativePath)
|
||||
|
||||
const options = {}
|
||||
|
||||
const typeConstraints = []
|
||||
|
||||
export default getDefaultExport(
|
||||
"file",
|
||||
fileTryParse,
|
||||
fileFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
{ relativePath: "some_file.jpg", size: 1000 },
|
||||
JSON.stringify
|
||||
)
|
|
@ -1,84 +1,53 @@
|
|||
import { assign, merge } from "lodash"
|
||||
import {
|
||||
map,
|
||||
isString,
|
||||
isNumber,
|
||||
isBoolean,
|
||||
isDate,
|
||||
keys,
|
||||
isObject,
|
||||
isArray,
|
||||
has,
|
||||
} from "lodash/fp"
|
||||
import { $ } from "../../common"
|
||||
import { parsedSuccess } from "./typeHelpers"
|
||||
import string from "./string"
|
||||
import bool from "./bool"
|
||||
import number from "./number"
|
||||
import boolean from "./boolean"
|
||||
import datetime from "./datetime"
|
||||
import array from "./array"
|
||||
import link from "./link"
|
||||
import file from "./file"
|
||||
import { BadRequestError } from "../../common/errors"
|
||||
import number from "./number"
|
||||
import select from "./select"
|
||||
import text from "./text"
|
||||
|
||||
const allTypes = () => {
|
||||
const basicTypes = {
|
||||
string,
|
||||
number,
|
||||
datetime,
|
||||
bool,
|
||||
link,
|
||||
file,
|
||||
const allTypes = {
|
||||
boolean,
|
||||
datetime,
|
||||
link,
|
||||
number,
|
||||
select,
|
||||
text,
|
||||
}
|
||||
|
||||
export function listTypes() {
|
||||
return Object.keys(allTypes)
|
||||
}
|
||||
|
||||
export function newField(name, type) {
|
||||
const field = allTypes[type].default()
|
||||
field.name = name
|
||||
field.required = false
|
||||
return field
|
||||
}
|
||||
|
||||
export function fieldsToSchema(fields) {
|
||||
const required = fields.filter(f => f.required).map(f => f.name)
|
||||
|
||||
return {
|
||||
type: "object",
|
||||
required,
|
||||
properties: fields.reduce((sch, field) => {
|
||||
sch[field.name] = allTypes[field.type].toSchema(field)
|
||||
return sch
|
||||
}, {}),
|
||||
}
|
||||
|
||||
const arrays = $(basicTypes, [
|
||||
keys,
|
||||
map(k => {
|
||||
const kvType = {}
|
||||
const concreteArray = array(basicTypes[k])
|
||||
kvType[concreteArray.name] = concreteArray
|
||||
return kvType
|
||||
}),
|
||||
types => assign({}, ...types),
|
||||
])
|
||||
|
||||
return merge({}, basicTypes, arrays)
|
||||
}
|
||||
|
||||
export const all = allTypes()
|
||||
|
||||
export const getType = typeName => {
|
||||
if (!has(typeName)(all))
|
||||
throw new BadRequestError(`Do not recognise type ${typeName}`)
|
||||
return all[typeName]
|
||||
}
|
||||
|
||||
export const getSampleFieldValue = field => getType(field.type).sampleValue
|
||||
|
||||
export const getNewFieldValue = field => getType(field.type).getNew(field)
|
||||
|
||||
export const safeParseField = (field, record) =>
|
||||
getType(field.type).safeParseField(field, record)
|
||||
|
||||
export const validateFieldParse = (field, record) =>
|
||||
has(field.name)(record)
|
||||
? getType(field.type).tryParse(record[field.name])
|
||||
: parsedSuccess(undefined) // fields may be undefined by default
|
||||
|
||||
export const getDefaultOptions = type => getType(type).getDefaultOptions()
|
||||
|
||||
export const validateTypeConstraints = (field, record) =>
|
||||
getType(field.type).validateTypeConstraints(field, record)
|
||||
|
||||
export const detectType = value => {
|
||||
if (isString(value)) return string
|
||||
if (isBoolean(value)) return bool
|
||||
if (isNumber(value)) return number
|
||||
if (isDate(value)) return datetime
|
||||
if (isArray(value)) return array(detectType(value[0]))
|
||||
if (isObject(value) && has("key")(value) && has("value")(value)) return link
|
||||
if (isObject(value) && has("relativePath")(value) && has("size")(value))
|
||||
return file
|
||||
|
||||
throw new BadRequestError(`cannot determine type: ${JSON.stringify(value)}`)
|
||||
export function schemaToFields(modelSchema) {
|
||||
return Object.keys(modelSchema.properties).map(key => {
|
||||
const schema = modelSchema.properties[key]
|
||||
for (let type in allTypes) {
|
||||
if (allTypes[type].isType(schema)) {
|
||||
const field = allTypes[type].fromSchema(schema)
|
||||
field.required = modelSchema.required.includes(key)
|
||||
field.name = key
|
||||
return field
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,42 +1,27 @@
|
|||
import { isString, isUndefined, isNull } from "lodash/fp"
|
||||
import { typeFunctions, parsedSuccess, getDefaultExport } from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
isNonEmptyString,
|
||||
} from "../../common/index.js"
|
||||
export default {
|
||||
isType: schema => schema.type === "object" && schema.properties.modelId,
|
||||
|
||||
const linkNothing = () => ""
|
||||
fromSchema: schema => ({
|
||||
type: "link",
|
||||
modelId: schema.properties.modelId.const,
|
||||
viewId: schema.properties.viewId.const,
|
||||
default: schema.default,
|
||||
}),
|
||||
|
||||
const linkFunctions = typeFunctions({
|
||||
default: linkNothing,
|
||||
})
|
||||
toSchema: field => ({
|
||||
type: "object",
|
||||
properties: {
|
||||
_id: { type: "string" },
|
||||
viewId: field.viewId ? { const: field.viewId } : undefined,
|
||||
modelId: field.modelId ? { const: field.modelId } : undefined,
|
||||
},
|
||||
required: ["_id"],
|
||||
default: { _id: "" },
|
||||
}),
|
||||
|
||||
const linkTryParse = v =>
|
||||
switchCase(
|
||||
[isString, s => parsedSuccess(s)],
|
||||
[isNull, () => parsedSuccess(linkNothing())],
|
||||
[isUndefined, () => parsedSuccess(linkNothing())],
|
||||
[defaultCase, s => parsedSuccess(s.toString())]
|
||||
)(v)
|
||||
|
||||
const options = {
|
||||
modelId: {
|
||||
defaultValue: "",
|
||||
isValid: isNonEmptyString,
|
||||
requirementDescription: "must choose a model",
|
||||
parse: s => s,
|
||||
},
|
||||
default: () => ({
|
||||
type: "link",
|
||||
modelId: null,
|
||||
viewId: null,
|
||||
}),
|
||||
}
|
||||
|
||||
const typeConstraints = []
|
||||
|
||||
export default getDefaultExport(
|
||||
"link",
|
||||
linkTryParse,
|
||||
linkFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
"abcd1234",
|
||||
JSON.stringify
|
||||
)
|
||||
|
|
|
@ -1,94 +1,15 @@
|
|||
import { constant, isNumber, isString, isNull } from "lodash/fp"
|
||||
import {
|
||||
makerule,
|
||||
typeFunctions,
|
||||
parsedFailed,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
toNumberOrNull,
|
||||
isSafeInteger,
|
||||
} from "../../common/index.js"
|
||||
|
||||
const numberFunctions = typeFunctions({
|
||||
default: constant(null),
|
||||
})
|
||||
|
||||
const parseStringtoNumberOrNull = s => {
|
||||
const num = Number(s)
|
||||
return isNaN(num) ? parsedFailed(s) : parsedSuccess(num)
|
||||
export default {
|
||||
isType: schema => schema.type === "number",
|
||||
fromSchema: schema => schema,
|
||||
toSchema: field => ({
|
||||
type: "number",
|
||||
maximum: field.maximum,
|
||||
minimum: field.minimum,
|
||||
default: undefined,
|
||||
}),
|
||||
default: () => ({
|
||||
type: "number",
|
||||
maximum: null,
|
||||
minimum: null,
|
||||
}),
|
||||
}
|
||||
|
||||
const numberTryParse = switchCase(
|
||||
[isNumber, parsedSuccess],
|
||||
[isString, parseStringtoNumberOrNull],
|
||||
[isNull, parsedSuccess],
|
||||
[defaultCase, parsedFailed]
|
||||
)
|
||||
|
||||
const options = {
|
||||
maxValue: {
|
||||
defaultValue: Number.MAX_SAFE_INTEGER,
|
||||
isValid: isSafeInteger,
|
||||
requirementDescription: "must be a valid integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
minValue: {
|
||||
defaultValue: 0 - Number.MAX_SAFE_INTEGER,
|
||||
isValid: isSafeInteger,
|
||||
requirementDescription: "must be a valid integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
decimalPlaces: {
|
||||
defaultValue: 0,
|
||||
isValid: n => isSafeInteger(n) && n >= 0,
|
||||
requirementDescription: "must be a positive integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
}
|
||||
|
||||
const getDecimalPlaces = val => {
|
||||
const splitDecimal = val.toString().split(".")
|
||||
if (splitDecimal.length === 1) return 0
|
||||
return splitDecimal[1].length
|
||||
}
|
||||
|
||||
const typeConstraints = [
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || opts.minValue === null || val >= opts.minValue,
|
||||
(val, opts) =>
|
||||
`value (${val.toString()}) must be greater than or equal to ${
|
||||
opts.minValue
|
||||
}`
|
||||
),
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || opts.maxValue === null || val <= opts.maxValue,
|
||||
(val, opts) =>
|
||||
`value (${val.toString()}) must be less than or equal to ${
|
||||
opts.minValue
|
||||
} options`
|
||||
),
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || opts.decimalPlaces >= getDecimalPlaces(val),
|
||||
(val, opts) =>
|
||||
`value (${val.toString()}) must have ${
|
||||
opts.decimalPlaces
|
||||
} decimal places or less`
|
||||
),
|
||||
]
|
||||
|
||||
export default getDefaultExport(
|
||||
"number",
|
||||
numberTryParse,
|
||||
numberFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
1,
|
||||
num => num.toString()
|
||||
)
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
import { keys, isObject, has, clone, map, isNull, constant } from "lodash"
|
||||
import {
|
||||
typeFunctions,
|
||||
parsedFailed,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import { switchCase, defaultCase, $ } from "../../common/index.js"
|
||||
|
||||
const objectFunctions = (definition, allTypes) =>
|
||||
typeFunctions({
|
||||
default: constant(null),
|
||||
initialise: () =>
|
||||
$(keys(definition), [
|
||||
map(() => {
|
||||
const defClone = clone(definition)
|
||||
for (const k in defClone) {
|
||||
defClone[k] = allTypes[k].getNew()
|
||||
}
|
||||
return defClone
|
||||
}),
|
||||
]),
|
||||
})
|
||||
|
||||
const parseObject = (definition, allTypes) => record => {
|
||||
const defClone = clone(definition)
|
||||
for (const k in defClone) {
|
||||
const type = allTypes[defClone[k]]
|
||||
defClone[k] = has(record, k)
|
||||
? type.safeParseValue(record[k])
|
||||
: type.getNew()
|
||||
}
|
||||
return parsedSuccess(defClone)
|
||||
}
|
||||
|
||||
const objectTryParse = (definition, allTypes) =>
|
||||
switchCase(
|
||||
[isNull, parsedSuccess],
|
||||
[isObject, parseObject(definition, allTypes)],
|
||||
[defaultCase, parsedFailed]
|
||||
)
|
||||
|
||||
export default (
|
||||
typeName,
|
||||
definition,
|
||||
allTypes,
|
||||
defaultOptions,
|
||||
typeConstraints,
|
||||
sampleValue
|
||||
) =>
|
||||
getDefaultExport(
|
||||
typeName,
|
||||
objectTryParse(definition, allTypes),
|
||||
objectFunctions(definition, allTypes),
|
||||
defaultOptions,
|
||||
typeConstraints,
|
||||
sampleValue,
|
||||
JSON.stringify
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
export default {
|
||||
isType: schema => schema.type === "string" && schema.enum,
|
||||
|
||||
fromSchema: schema => ({
|
||||
type: "select",
|
||||
enum: schema.enum,
|
||||
default: schema.default,
|
||||
}),
|
||||
|
||||
toSchema: field => ({
|
||||
type: "string",
|
||||
enum: field.enum,
|
||||
default: field.default,
|
||||
}),
|
||||
|
||||
default: () => ({
|
||||
type: "select",
|
||||
enum: [],
|
||||
default: "",
|
||||
}),
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
import { constant, isString, isNull, includes, isBoolean } from "lodash/fp"
|
||||
import {
|
||||
typeFunctions,
|
||||
makerule,
|
||||
parsedSuccess,
|
||||
getDefaultExport,
|
||||
} from "./typeHelpers"
|
||||
import {
|
||||
switchCase,
|
||||
defaultCase,
|
||||
toBoolOrNull,
|
||||
toNumberOrNull,
|
||||
isSafeInteger,
|
||||
isArrayOfString,
|
||||
} from "../../common/index.js"
|
||||
|
||||
const stringFunctions = typeFunctions({
|
||||
default: constant(null),
|
||||
})
|
||||
|
||||
const stringTryParse = switchCase(
|
||||
[isString, parsedSuccess],
|
||||
[isNull, parsedSuccess],
|
||||
[defaultCase, v => parsedSuccess(v.toString())]
|
||||
)
|
||||
|
||||
const options = {
|
||||
maxLength: {
|
||||
defaultValue: null,
|
||||
isValid: n => n === null || (isSafeInteger(n) && n > 0),
|
||||
requirementDescription:
|
||||
"max length must be null (no limit) or a greater than zero integer",
|
||||
parse: toNumberOrNull,
|
||||
},
|
||||
values: {
|
||||
defaultValue: null,
|
||||
isValid: v =>
|
||||
v === null || (isArrayOfString(v) && v.length > 0 && v.length < 10000),
|
||||
requirementDescription:
|
||||
"'values' must be null (no values) or an array of at least one string",
|
||||
parse: s => s,
|
||||
},
|
||||
allowDeclaredValuesOnly: {
|
||||
defaultValue: false,
|
||||
isValid: isBoolean,
|
||||
requirementDescription: "allowDeclaredValuesOnly must be true or false",
|
||||
parse: toBoolOrNull,
|
||||
},
|
||||
}
|
||||
|
||||
const typeConstraints = [
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null || opts.maxLength === null || val.length <= opts.maxLength,
|
||||
(val, opts) => `value exceeds maximum length of ${opts.maxLength}`
|
||||
),
|
||||
makerule(
|
||||
(val, opts) =>
|
||||
val === null ||
|
||||
opts.allowDeclaredValuesOnly === false ||
|
||||
includes(val)(opts.values),
|
||||
val => `"${val}" does not exist in the list of allowed values`
|
||||
),
|
||||
]
|
||||
|
||||
export default getDefaultExport(
|
||||
"string",
|
||||
stringTryParse,
|
||||
stringFunctions,
|
||||
options,
|
||||
typeConstraints,
|
||||
"abcde",
|
||||
str => str
|
||||
)
|
|
@ -0,0 +1,24 @@
|
|||
export default {
|
||||
isType: schema => schema.type === "string" && !schema.format,
|
||||
|
||||
fromSchema: schema => ({
|
||||
type: "text",
|
||||
maxLength: schema.maxLength,
|
||||
minLength: schema.minLength,
|
||||
default: schema.default,
|
||||
}),
|
||||
|
||||
toSchema: field => ({
|
||||
type: "string",
|
||||
maxLength: field.maxLength,
|
||||
minLength: field.minLength,
|
||||
default: "",
|
||||
}),
|
||||
|
||||
default: () => ({
|
||||
type: "text",
|
||||
maxLength: null,
|
||||
minLength: 0,
|
||||
default: "",
|
||||
}),
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
import { merge } from "lodash"
|
||||
import { constant, isUndefined, has, mapValues, cloneDeep } from "lodash/fp"
|
||||
import { isNotEmpty } from "../../common/index.js"
|
||||
|
||||
export const getSafeFieldParser = (tryParse, defaultValueFunctions) => (
|
||||
field,
|
||||
record
|
||||
) => {
|
||||
if (has(field.name)(record)) {
|
||||
return getSafeValueParser(
|
||||
tryParse,
|
||||
defaultValueFunctions
|
||||
)(record[field.name])
|
||||
}
|
||||
return defaultValueFunctions[field.getUndefinedValue]()
|
||||
}
|
||||
|
||||
export const getSafeValueParser = (
|
||||
tryParse,
|
||||
defaultValueFunctions
|
||||
) => value => {
|
||||
const parsed = tryParse(value)
|
||||
if (parsed.success) {
|
||||
return parsed.value
|
||||
}
|
||||
return defaultValueFunctions.default()
|
||||
}
|
||||
|
||||
export const getNewValue = (tryParse, defaultValueFunctions) => field => {
|
||||
const getInitialValue =
|
||||
isUndefined(field) || isUndefined(field.getInitialValue)
|
||||
? "default"
|
||||
: field.getInitialValue
|
||||
|
||||
return has(getInitialValue)(defaultValueFunctions)
|
||||
? defaultValueFunctions[getInitialValue]()
|
||||
: getSafeValueParser(tryParse, defaultValueFunctions)(getInitialValue)
|
||||
}
|
||||
|
||||
export const typeFunctions = specificFunctions =>
|
||||
merge(
|
||||
{
|
||||
value: constant,
|
||||
null: constant(null),
|
||||
},
|
||||
specificFunctions
|
||||
)
|
||||
|
||||
export const validateTypeConstraints = validationRules => (field, record) => {
|
||||
const fieldValue = record[field.name]
|
||||
const validateRule = r =>
|
||||
!r.isValid(fieldValue, field.typeOptions)
|
||||
? r.getMessage(fieldValue, field.typeOptions)
|
||||
: ""
|
||||
|
||||
const errors = []
|
||||
for (const r of validationRules) {
|
||||
const err = validateRule(r)
|
||||
if (isNotEmpty(err)) errors.push(err)
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
const getDefaultOptions = mapValues(v => v.defaultValue)
|
||||
|
||||
export const makerule = (isValid, getMessage) => ({ isValid, getMessage })
|
||||
export const parsedFailed = val => ({ success: false, value: val })
|
||||
export const parsedSuccess = val => ({ success: true, value: val })
|
||||
export const getDefaultExport = (
|
||||
name,
|
||||
tryParse,
|
||||
functions,
|
||||
options,
|
||||
validationRules,
|
||||
sampleValue,
|
||||
stringify
|
||||
) => ({
|
||||
getNew: getNewValue(tryParse, functions),
|
||||
safeParseField: getSafeFieldParser(tryParse, functions),
|
||||
safeParseValue: getSafeValueParser(tryParse, functions),
|
||||
tryParse,
|
||||
name,
|
||||
getDefaultOptions: () => getDefaultOptions(cloneDeep(options)),
|
||||
optionDefinitions: options,
|
||||
validateTypeConstraints: validateTypeConstraints(validationRules),
|
||||
sampleValue,
|
||||
stringify: val => (val === null || val === undefined ? "" : stringify(val)),
|
||||
getDefaultValue: functions.default,
|
||||
})
|
|
@ -0,0 +1,38 @@
|
|||
import { newModel } from "../schema/models"
|
||||
import { newView } from "../schema/views"
|
||||
import { fullSchema } from "../schema/fullSchema"
|
||||
import { newField, schemaToFields, fieldsToSchema } from "../schema/types"
|
||||
|
||||
export function testSchema() {
|
||||
const addFieldToModel = (model, field) => {
|
||||
const defaultField = newField(field.name, field.type || "text")
|
||||
Object.assign(defaultField, field)
|
||||
const currentFields = schemaToFields(model.schema)
|
||||
model.schema = fieldsToSchema([...currentFields, field])
|
||||
}
|
||||
|
||||
const contactModel = newModel()
|
||||
contactModel.name = "Contact"
|
||||
addFieldToModel(contactModel, { name: "Is Active", type: "boolean" })
|
||||
addFieldToModel(contactModel, { name: "Created", type: "datetime" })
|
||||
addFieldToModel(contactModel, {
|
||||
name: "Status",
|
||||
type: "select",
|
||||
enum: ["new", "complete"],
|
||||
})
|
||||
|
||||
const activeContactsView = newView(contactModel.id)
|
||||
activeContactsView.name = "Active Contacts"
|
||||
activeContactsView.map = "if (doc['Is Active']) emit(doc.Name, doc)"
|
||||
|
||||
const dealModel = newModel()
|
||||
dealModel.name = "Deal"
|
||||
addFieldToModel(dealModel, { name: "Estimated Value", type: "number" })
|
||||
addFieldToModel(dealModel, {
|
||||
name: "Contact",
|
||||
type: "link",
|
||||
modelId: contactModel.id,
|
||||
})
|
||||
|
||||
return fullSchema([contactModel, dealModel], [activeContactsView])
|
||||
}
|
|
@ -1,285 +0,0 @@
|
|||
import { getNewFieldValue, safeParseField } from "../src/types"
|
||||
import { getNewField } from "../src/templateApi/fields"
|
||||
import { isDefined } from "../src/common"
|
||||
|
||||
const getField = type => {
|
||||
const field = getNewField(type)
|
||||
return field
|
||||
}
|
||||
|
||||
const nothingReference = { key: "" }
|
||||
const nothingFile = { relativePath: "", size: 0 }
|
||||
|
||||
describe("types > getNew", () => {
|
||||
const defaultAlwaysNull = type => () => {
|
||||
const field = getField(type)
|
||||
field.getInitialValue = "default"
|
||||
const value = getNewFieldValue(field)
|
||||
expect(value).toBe(null)
|
||||
}
|
||||
|
||||
it(
|
||||
"bool should return null when fields getInitialValue is 'default'",
|
||||
defaultAlwaysNull("bool")
|
||||
)
|
||||
|
||||
it(
|
||||
"string should return null when fields getInitialValue is 'default'",
|
||||
defaultAlwaysNull("string")
|
||||
)
|
||||
|
||||
it(
|
||||
"number should return null when fields getInitialValue is 'default'",
|
||||
defaultAlwaysNull("number")
|
||||
)
|
||||
|
||||
it(
|
||||
"datetime should return null when fields getInitialValue is 'default'",
|
||||
defaultAlwaysNull("datetime")
|
||||
)
|
||||
|
||||
it("reference should return {key:''} when fields getInitialValue is 'default'", () => {
|
||||
const field = getField("reference")
|
||||
field.getInitialValue = "default"
|
||||
const value = getNewFieldValue(field)
|
||||
expect(value).toEqual(nothingReference)
|
||||
})
|
||||
|
||||
it("file should return {relativePath:'', size:0} when fields getInitialValue is 'default'", () => {
|
||||
const field = getField("file")
|
||||
field.getInitialValue = "default"
|
||||
const value = getNewFieldValue(field)
|
||||
expect(value).toEqual(nothingFile)
|
||||
})
|
||||
|
||||
it("array should return empty array when field getInitialValue is 'default'", () => {
|
||||
const field = getField("array<string>")
|
||||
field.getInitialValue = "default"
|
||||
const value = getNewFieldValue(field)
|
||||
expect(value).toEqual([])
|
||||
})
|
||||
|
||||
it("datetime should return Now when getInitialValue is 'now'", () => {
|
||||
const field = getField("datetime")
|
||||
field.getInitialValue = "now"
|
||||
const before = new Date()
|
||||
const value = getNewFieldValue(field)
|
||||
const after = new Date()
|
||||
expect(value >= before && value <= after).toBeTruthy()
|
||||
})
|
||||
|
||||
const test_getNewFieldValue = (type, val, expected) => () => {
|
||||
const field = getField(type)
|
||||
field.getInitialValue = val
|
||||
const value = getNewFieldValue(field)
|
||||
expect(value).toEqual(expected)
|
||||
}
|
||||
|
||||
it("bool should parse value in getInitialValue if function not recognised", () => {
|
||||
test_getNewFieldValue("bool", "true", true)()
|
||||
test_getNewFieldValue("bool", "on", true)()
|
||||
test_getNewFieldValue("bool", "1", true)()
|
||||
test_getNewFieldValue("bool", "yes", true)()
|
||||
test_getNewFieldValue("bool", "false", false)()
|
||||
test_getNewFieldValue("bool", "off", false)()
|
||||
test_getNewFieldValue("bool", "0", false)()
|
||||
test_getNewFieldValue("bool", "no", false)()
|
||||
})
|
||||
|
||||
it("bool should return null if function not recognised and value cannot be parsed", () => {
|
||||
test_getNewFieldValue("bool", "blah", null)()
|
||||
test_getNewFieldValue("bool", 111, null)()
|
||||
})
|
||||
|
||||
it("number should parse value in getInitialValue if function not recognised", () => {
|
||||
test_getNewFieldValue("number", "1", 1)()
|
||||
test_getNewFieldValue("number", "45", 45)()
|
||||
test_getNewFieldValue("number", "4.11", 4.11)()
|
||||
})
|
||||
|
||||
it("number should return null if function not recognised and value cannot be parsed", () => {
|
||||
test_getNewFieldValue("number", "blah", null)()
|
||||
test_getNewFieldValue("number", true, null)()
|
||||
})
|
||||
|
||||
it("string should parse value in getInitialValue if function not recognised", () => {
|
||||
test_getNewFieldValue("string", "hello there", "hello there")()
|
||||
test_getNewFieldValue("string", 45, "45")()
|
||||
test_getNewFieldValue("string", true, "true")()
|
||||
})
|
||||
|
||||
it("array should return empty array when function not recognised", () => {
|
||||
test_getNewFieldValue("array<string>", "blah", [])()
|
||||
test_getNewFieldValue("array<bool>", true, [])()
|
||||
test_getNewFieldValue("array<number>", 1, [])()
|
||||
test_getNewFieldValue("array<datetime>", "", [])()
|
||||
test_getNewFieldValue("array<reference>", "", [])()
|
||||
test_getNewFieldValue("array<file>", "", [])()
|
||||
})
|
||||
|
||||
it("reference should {key:''} when function not recognised", () => {
|
||||
test_getNewFieldValue("reference", "blah", nothingReference)()
|
||||
})
|
||||
|
||||
it("file should return {relativePath:'',size:0} when function not recognised", () => {
|
||||
test_getNewFieldValue("file", "blah", nothingFile)()
|
||||
})
|
||||
})
|
||||
|
||||
describe("types > getSafeFieldValue", () => {
|
||||
const test_getSafeFieldValue = (type, member, value, expectedParse) => () => {
|
||||
const field = getField(type)
|
||||
field.getDefaultValue = "default"
|
||||
field.name = member
|
||||
const record = {}
|
||||
if (isDefined(value)) record[member] = value
|
||||
const parsedvalue = safeParseField(field, record)
|
||||
expect(parsedvalue).toEqual(expectedParse)
|
||||
}
|
||||
|
||||
it(
|
||||
"should get default field value when member is undefined on record",
|
||||
test_getSafeFieldValue("string", "forename", undefined, null)
|
||||
)
|
||||
|
||||
it("should return null as null (except array and reference)", () => {
|
||||
test_getSafeFieldValue("string", "forename", null, null)()
|
||||
test_getSafeFieldValue("bool", "isalive", null, null)()
|
||||
test_getSafeFieldValue("datetime", "created", null, null)()
|
||||
test_getSafeFieldValue("number", "age", null, null)()
|
||||
test_getSafeFieldValue("array<string>", "tags", null, [])()
|
||||
test_getSafeFieldValue("reference", "moretags", null, nothingReference)()
|
||||
test_getSafeFieldValue("file", "moretags", null, nothingFile)()
|
||||
})
|
||||
|
||||
it("bool should parse a defined set of true/false aliases", () => {
|
||||
test_getSafeFieldValue("bool", "isalive", true, true)()
|
||||
test_getSafeFieldValue("bool", "isalive", "true", true)()
|
||||
test_getSafeFieldValue("bool", "isalive", "on", true)()
|
||||
test_getSafeFieldValue("bool", "isalive", "1", true)()
|
||||
test_getSafeFieldValue("bool", "isalive", "yes", true)()
|
||||
test_getSafeFieldValue("bool", "isalive", false, false)()
|
||||
test_getSafeFieldValue("bool", "isalive", "false", false)()
|
||||
test_getSafeFieldValue("bool", "isalive", "off", false)()
|
||||
test_getSafeFieldValue("bool", "isalive", "0", false)()
|
||||
test_getSafeFieldValue("bool", "isalive", "no", false)()
|
||||
})
|
||||
|
||||
it(
|
||||
"bool should parse invalid values as null",
|
||||
test_getSafeFieldValue("bool", "isalive", "blah", null)
|
||||
)
|
||||
|
||||
it("number should parse numbers and strings that are numbers", () => {
|
||||
test_getSafeFieldValue("number", "age", 204, 204)()
|
||||
test_getSafeFieldValue("number", "age", "1", 1)()
|
||||
test_getSafeFieldValue("number", "age", "45", 45)()
|
||||
test_getSafeFieldValue("number", "age", "4.11", 4.11)()
|
||||
})
|
||||
|
||||
it(
|
||||
"number should parse invalid values as null",
|
||||
test_getSafeFieldValue("number", "age", "blah", null)
|
||||
)
|
||||
|
||||
it(
|
||||
"string should parse strings",
|
||||
test_getSafeFieldValue("string", "forename", "bob", "bob")
|
||||
)
|
||||
|
||||
it("string should parse any other basic type", () => {
|
||||
test_getSafeFieldValue("string", "forename", true, "true")()
|
||||
test_getSafeFieldValue("string", "forename", 1, "1")()
|
||||
})
|
||||
|
||||
it("date should parse dates in various precisions", () => {
|
||||
// dont forget that JS Date's month is zero based
|
||||
test_getSafeFieldValue(
|
||||
"datetime",
|
||||
"createddate",
|
||||
"2018-02-14",
|
||||
new Date(2018, 1, 14)
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"datetime",
|
||||
"createddate",
|
||||
"2018-2-14",
|
||||
new Date(2018, 1, 14)
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"datetime",
|
||||
"createddate",
|
||||
"2018-02-14 11:00:00.000",
|
||||
new Date(2018, 1, 14, 11)
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"datetime",
|
||||
"createddate",
|
||||
"2018-02-14 11:30",
|
||||
new Date(2018, 1, 14, 11, 30)
|
||||
)()
|
||||
})
|
||||
|
||||
it("date should parse invalid dates as null", () => {
|
||||
// dont forget that JS Date's month is zero based
|
||||
test_getSafeFieldValue("datetime", "createddate", "2018-13-14", null)()
|
||||
test_getSafeFieldValue("datetime", "createddate", "2018-2-33", null)()
|
||||
test_getSafeFieldValue("datetime", "createddate", "bla", null)()
|
||||
})
|
||||
|
||||
it("array should parse array", () => {
|
||||
test_getSafeFieldValue(
|
||||
"array<string>",
|
||||
"tags",
|
||||
["bob", "the", "dog"],
|
||||
["bob", "the", "dog"]
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"array<bool>",
|
||||
"tags",
|
||||
[true, false],
|
||||
[true, false]
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"array<number>",
|
||||
"tags",
|
||||
[1, 2, 3, 4],
|
||||
[1, 2, 3, 4]
|
||||
)()
|
||||
test_getSafeFieldValue(
|
||||
"array<reference>",
|
||||
"tags",
|
||||
[{ key: "/customer/1234", value: "bob" }],
|
||||
[{ key: "/customer/1234", value: "bob" }]
|
||||
)()
|
||||
})
|
||||
|
||||
it("array should convert the generic's child type", () => {
|
||||
test_getSafeFieldValue("array<string>", "tags", [1, true], ["1", "true"])()
|
||||
test_getSafeFieldValue(
|
||||
"array<bool>",
|
||||
"tags",
|
||||
["yes", "true", "no", "false", true, false],
|
||||
[true, true, false, false, true, false]
|
||||
)()
|
||||
test_getSafeFieldValue("array<number>", "tags", ["1", 23], [1, 23])()
|
||||
})
|
||||
|
||||
it("reference should parse reference", () => {
|
||||
test_getSafeFieldValue(
|
||||
"reference",
|
||||
"customer",
|
||||
{ key: "/customer/1234", value: "bob" },
|
||||
{ key: "/customer/1234", value: "bob" }
|
||||
)()
|
||||
})
|
||||
|
||||
it("reference should parse reference", () => {
|
||||
test_getSafeFieldValue(
|
||||
"file",
|
||||
"profilepic",
|
||||
{ relativePath: "path/to/pic.jpg", size: 120 },
|
||||
{ relativePath: "path/to/pic.jpg", size: 120 }
|
||||
)()
|
||||
})
|
||||
})
|
|
@ -1,38 +0,0 @@
|
|||
import { newModel } from "../src/schema/models"
|
||||
import { newView } from "../src/schema/views"
|
||||
import { getNewField } from "../src/schema/fields"
|
||||
import { fullSchema } from "../src/schema/fullSchema"
|
||||
import { commonRecordValidationRules } from "../src/records/recordValidationRules"
|
||||
|
||||
export function testSchema() {
|
||||
const addFieldToModel = (model, { type, name }) => {
|
||||
const field = getNewField(type || "string")
|
||||
field.name = name
|
||||
model.fields.push(field)
|
||||
}
|
||||
|
||||
const contactModel = newModel()
|
||||
contactModel.name = "Contact"
|
||||
contactModel.primaryField = "Name"
|
||||
|
||||
addFieldToModel(contactModel, { name: "Name" })
|
||||
addFieldToModel(contactModel, { name: "Is Active", type: "bool" })
|
||||
addFieldToModel(contactModel, { name: "Created", type: "datetime" })
|
||||
addFieldToModel(contactModel, { name: "Status", type: "string" })
|
||||
|
||||
contactModel.validationRules.push(
|
||||
commonRecordValidationRules.fieldNotEmpty("Name")
|
||||
)
|
||||
|
||||
const activeContactsView = newView(contactModel.id)
|
||||
activeContactsView.name = "Active Contacts"
|
||||
activeContactsView.map = "if (doc['Is Active']) emit(doc.Name, doc)"
|
||||
|
||||
const dealModel = newModel()
|
||||
dealModel.name = "Deal"
|
||||
addFieldToModel(dealModel, { name: "Name" })
|
||||
addFieldToModel(dealModel, { name: "Estimated Value", type: "number" })
|
||||
addFieldToModel(dealModel, { name: "Contact", type: "link" })
|
||||
|
||||
return fullSchema([contactModel, dealModel], [activeContactsView])
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
import { newField, fieldsToSchema, schemaToFields } from "../src/schema/types"
|
||||
|
||||
describe("fields to JSON schema", () => {
|
||||
|
||||
it("should convert text field to string", () => {
|
||||
|
||||
const field = newField("surname", "text")
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.properties.surname.type).toBe("string")
|
||||
expect(schema.properties.surname.format).toBeUndefined()
|
||||
expect(schema.properties.surname.default).toBe("")
|
||||
})
|
||||
|
||||
it("should add required field", () => {
|
||||
|
||||
const field = newField("surname", "text")
|
||||
let schema = fieldsToSchema([field])
|
||||
expect(schema.required).toEqual([])
|
||||
|
||||
field.required = true
|
||||
schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.required).toEqual(["surname"])
|
||||
})
|
||||
|
||||
it("should convert boolean field to boolean", () => {
|
||||
|
||||
const field = newField("active", "boolean")
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.properties.active.type).toBe("boolean")
|
||||
expect(schema.properties.active.default).toBe(false)
|
||||
})
|
||||
|
||||
it("should convert datetime field to formatted string", () => {
|
||||
|
||||
const field = newField("surname", "datetime")
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
const datetimeCondition = schema.properties.surname.anyOf.find(s => s.type === "string" && s.format === "date-time")
|
||||
expect(datetimeCondition).toBeDefined()
|
||||
|
||||
const blankCondition = schema.properties.surname.anyOf.find(s => s.const === "")
|
||||
expect(blankCondition).toBeDefined()
|
||||
|
||||
expect(schema.properties.surname.default).toBe("")
|
||||
|
||||
})
|
||||
|
||||
it("should convert link field to object", () => {
|
||||
|
||||
const field = newField("contact", "link")
|
||||
field.modelId = "1234"
|
||||
field.viewId = "5678"
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.properties.contact.type).toBe("object")
|
||||
expect(schema.properties.contact.required).toEqual(["_id"])
|
||||
expect(schema.properties.contact.default).toEqual({ _id: "" })
|
||||
expect(schema.properties.contact.properties).toEqual({
|
||||
_id: { type: "string" },
|
||||
modelId: { const: "1234" },
|
||||
viewId: { const: "5678" },
|
||||
})
|
||||
})
|
||||
|
||||
it("should convert number field to number", () => {
|
||||
|
||||
const field = newField("age", "number")
|
||||
field.maximum = 1234
|
||||
field.minimum = -5678
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.properties).toEqual({
|
||||
age: { type: "number", maximum: 1234, minimum: -5678}
|
||||
})
|
||||
})
|
||||
|
||||
it("should convert select to text with enum", () => {
|
||||
|
||||
const field = newField("status", "select")
|
||||
field.enum = ["new", "complete"]
|
||||
const schema = fieldsToSchema([field])
|
||||
|
||||
expect(schema.properties).toEqual({
|
||||
status: {
|
||||
type: "string",
|
||||
enum: ["new", "complete"],
|
||||
default: "",
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("JSON Schema to fields", () => {
|
||||
|
||||
it("should convert unformatted string to text", () => {
|
||||
const schema = schemaWithProperty("name",
|
||||
{
|
||||
type: "string",
|
||||
maxLength: 100,
|
||||
minLength: 4,
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "name",
|
||||
type: "text",
|
||||
maxLength: 100,
|
||||
minLength: 4,
|
||||
required: false,
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should convert date-time formatted string to datetime", () => {
|
||||
const schema = schemaWithProperty("createdDate",
|
||||
{
|
||||
anyOf: [
|
||||
{
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
},
|
||||
{ const: "" },
|
||||
]
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "createdDate",
|
||||
type: "datetime",
|
||||
required: false,
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should convert number to number", () => {
|
||||
const schema = schemaWithProperty("age",
|
||||
{
|
||||
type: "number",
|
||||
maximum: 100,
|
||||
minimum: 3,
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "age",
|
||||
type: "number",
|
||||
required: false,
|
||||
maximum: 100,
|
||||
minimum: 3,
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should convert string with enum to select", () => {
|
||||
const schema = schemaWithProperty("status",
|
||||
{
|
||||
type: "string",
|
||||
enum: ["new", "complete"]
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "status",
|
||||
type: "select",
|
||||
required: false,
|
||||
enum: ["new", "complete"],
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should convert boolean to boolean", () => {
|
||||
const schema = schemaWithProperty("active",
|
||||
{
|
||||
type: "boolean",
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "active",
|
||||
type: "boolean",
|
||||
required: false,
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should convert object with modelId & viewId to link", () => {
|
||||
const schema = schemaWithProperty("contact",
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
_id: { type: "string" },
|
||||
modelId: { const: "1234" },
|
||||
viewId: { const: null },
|
||||
}
|
||||
})
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields).toEqual([
|
||||
{
|
||||
name: "contact",
|
||||
type: "link",
|
||||
required: false,
|
||||
modelId: "1234",
|
||||
viewId: null,
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it("should flag required field", () => {
|
||||
const schema = schemaWithProperty("name",
|
||||
{
|
||||
type: "string",
|
||||
maxLength: 100,
|
||||
minLength: 4,
|
||||
})
|
||||
schema.required = ["name"]
|
||||
const fields = schemaToFields(schema)
|
||||
|
||||
expect(fields[0].required).toBe(true)
|
||||
})
|
||||
|
||||
function schemaWithProperty(name, prop) {
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: [],
|
||||
}
|
||||
schema.properties[name] = prop
|
||||
return schema
|
||||
}
|
||||
|
||||
})
|
|
@ -1,22 +1,17 @@
|
|||
const couchdb = require("../../db")
|
||||
const {
|
||||
events,
|
||||
schemaValidator
|
||||
} = require("../../../common");
|
||||
const { schemaValidator } = require("@budibase/common")
|
||||
|
||||
exports.save = async function(ctx) {
|
||||
const db = new CouchDB(ctx.params.instanceId);
|
||||
const record = ctx.request.body;
|
||||
|
||||
// validation with ajv
|
||||
const model = await db.get(ctx.params.modelId);
|
||||
const validate = schemaValidator.compile({
|
||||
properties: model.schema
|
||||
});
|
||||
const valid = validate(record);
|
||||
const model = await db.get(record.modelId)
|
||||
const validate = schemaValidator.compile(model.schema)
|
||||
const valid = validate(record)
|
||||
|
||||
if (!valid) {
|
||||
ctx.status = 400;
|
||||
ctx.status = 400
|
||||
ctx.body = {
|
||||
status: 400,
|
||||
errors: validate.errors
|
||||
|
@ -33,24 +28,19 @@ exports.save = async function(ctx) {
|
|||
status: 200,
|
||||
record: response
|
||||
}
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
const response = await db.post({
|
||||
modelId: ctx.params.modelId,
|
||||
type: "record",
|
||||
...record
|
||||
})
|
||||
|
||||
record.type = "record"
|
||||
const response = await db.post(record)
|
||||
record._rev = response.rev
|
||||
// await ctx.publish(events.recordApi.save.onRecordCreated, {
|
||||
// record: record,
|
||||
// })
|
||||
|
||||
ctx.body = {
|
||||
message: "Record created successfully.",
|
||||
status: 200,
|
||||
record: response
|
||||
};
|
||||
ctx.body = record
|
||||
ctx.status = 200
|
||||
ctx.message = `${model.name} ${record._rev ? "updated" : "created"} successfully`
|
||||
}
|
||||
|
||||
exports.fetch = async function(ctx) {
|
||||
|
@ -65,16 +55,12 @@ exports.fetch = async function(ctx) {
|
|||
}
|
||||
|
||||
exports.find = async function(ctx) {
|
||||
const db = couchdb.db.use(ctx.params.databaseId)
|
||||
|
||||
const record = await db.get(ctx.params.recordId);
|
||||
|
||||
ctx.body = record;
|
||||
ctx.status = 200;
|
||||
const db = couchdb.db.use(ctx.params.instanceId)
|
||||
ctx.body = await db.get(ctx.params.recordId)
|
||||
}
|
||||
|
||||
exports.destroy = async function(ctx) {
|
||||
const databaseId = ctx.params.instanceId;
|
||||
const db = new CouchDB(databaseId)
|
||||
ctx.body = await db.destroy(ctx.params.recordId, ctx.params.revId);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -137,7 +137,7 @@ module.exports = (config, app) => {
|
|||
await next();
|
||||
} catch (err) {
|
||||
console.trace(err);
|
||||
ctx.status = err.status || 500;
|
||||
ctx.status = err.status || err.statusCode || 500;
|
||||
ctx.body = {
|
||||
message: err.message,
|
||||
status: ctx.status
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const Router = require("@koa/router");
|
||||
const controller = require("../../controllers/record");
|
||||
const Router = require("@koa/router")
|
||||
const controller = require("../../controllers/record")
|
||||
|
||||
const router = Router();
|
||||
const router = Router()
|
||||
|
||||
router
|
||||
.get("/api/:instanceId/:viewName/records", controller.fetch)
|
||||
.get("/api/:instanceId/:modelId/records", controller.fetch)
|
||||
.get("/api/:instanceId/records/:recordId", controller.find)
|
||||
.post("/api/:instanceId/:modelId/records", controller.save)
|
||||
.delete("/api/:instanceId/records/:recordId/:revId", controller.destroy);
|
||||
.post("/api/:instanceId/records", controller.save)
|
||||
.delete("/api/:instanceId/records/:recordId/:revId", controller.destroy)
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router
|
||||
|
|
|
@ -5,8 +5,8 @@ const TEST_APP_ID = "test-app";
|
|||
|
||||
exports.destroyDatabase = couchdb.db.destroy;
|
||||
|
||||
exports.createModel = async instanceId => {
|
||||
const model = {
|
||||
exports.createModel = async (instanceId, model) => {
|
||||
model = model || {
|
||||
"name": "TestModel",
|
||||
"type": "model",
|
||||
"key": "name",
|
||||
|
@ -21,9 +21,11 @@ exports.createModel = async instanceId => {
|
|||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[`all_${response.id}`]: {
|
||||
map: function(doc) {
|
||||
emit([doc.modelId], doc._id);
|
||||
}
|
||||
map: `function(doc) {
|
||||
if (doc.modelId === "${response.id}") {
|
||||
emit(doc[doc.key], doc._id);
|
||||
}
|
||||
}`
|
||||
}
|
||||
};
|
||||
await db.insert(designDoc, designDoc._id);
|
||||
|
@ -85,4 +87,13 @@ exports.createInstanceDatabase = async instanceId => {
|
|||
exports.insertDocument = async (databaseId, document) => {
|
||||
const { id, ...documentFields } = document;
|
||||
await couchdb.db.use(databaseId).insert(documentFields, id);
|
||||
}
|
||||
}
|
||||
|
||||
exports.createSchema = async (request, instanceId, schema) => {
|
||||
for (let model of schema.models) {
|
||||
await request.post(`/api/${instanceId}/models`).send(model)
|
||||
}
|
||||
for (let view of schema.views) {
|
||||
await request.post(`/api/${instanceId}/views`).send(view)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
const supertest = require("supertest");
|
||||
const app = require("../../../../app");
|
||||
const { createInstanceDatabase, createModel, destroyDatabase } = require("./couchTestUtils");
|
||||
const { getNewRecord } = require("../../../../../common/lib/records/getNewRecord")
|
||||
const { testSchema } = require("../../../../../common/lib/testUtils/testSchema")
|
||||
|
||||
const TEST_INSTANCE_ID = "testing-123";
|
||||
|
||||
describe("/records", () => {
|
||||
let request;
|
||||
let server;
|
||||
|
||||
beforeAll(async () => {
|
||||
server = await app({
|
||||
config: {
|
||||
port: 3000
|
||||
}
|
||||
});
|
||||
request = supertest(server);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
server.close();
|
||||
})
|
||||
|
||||
describe("save, load, update, delete", () => {
|
||||
const schema = testSchema()
|
||||
|
||||
beforeAll(async () => {
|
||||
await createInstanceDatabase(TEST_INSTANCE_ID);
|
||||
await createModel(TEST_INSTANCE_ID, schema.findModel("Contact"))
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await destroyDatabase(TEST_INSTANCE_ID);
|
||||
});
|
||||
|
||||
let record = getNewRecord(schema, "Contact")
|
||||
record.name = "Test Contact"
|
||||
record.Status = "new"
|
||||
|
||||
it("returns a success message when the record is created", done => {
|
||||
request
|
||||
.post(`/api/${TEST_INSTANCE_ID}/records`)
|
||||
.send(record)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(async (err, res) => {
|
||||
expect(res.res.statusMessage.toLowerCase()).toEqual("contact created successfully")
|
||||
expect(res.body.name).toEqual("Test Contact")
|
||||
expect(res.body._rev).toBeDefined()
|
||||
record = res.body
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
it("updates a record successfully", async () => {
|
||||
record.name = "Updated Name"
|
||||
const res = await request
|
||||
.post(`/api/${TEST_INSTANCE_ID}/records`)
|
||||
.send(record)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
|
||||
expect(res.res.statusMessage.toLowerCase()).toEqual("contact updated successfully")
|
||||
expect(res.body.name).toEqual("Updated Name")
|
||||
record = res.body
|
||||
})
|
||||
|
||||
it("should load a record", async () => {
|
||||
const res = await request
|
||||
.get(`/api/${TEST_INSTANCE_ID}/records/${record._id}`)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
expect(res.body).toEqual(record)
|
||||
})
|
||||
|
||||
it("should list all records for given modelId", async () => {
|
||||
const secondRecord = getNewRecord(schema, "Contact")
|
||||
secondRecord.name = "Second Contact"
|
||||
secondRecord.Status = "new"
|
||||
|
||||
await request
|
||||
.post(`/api/${TEST_INSTANCE_ID}/records`)
|
||||
.send(secondRecord)
|
||||
.set("Accept", "application/json")
|
||||
|
||||
const res = await request
|
||||
.get(`/api/${TEST_INSTANCE_ID}/${record.modelId}/records`)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
|
||||
expect(res.body.length).toBe(2)
|
||||
console.log(JSON.stringify(res.body, undefined, 2))
|
||||
expect(res.body.find(c => c.name === record.name)).toBeDefined()
|
||||
expect(res.body.find(c => c.name === secondRecord.name)).toBeDefined()
|
||||
})
|
||||
|
||||
it("should return 404 when load, after a delete", async () => {
|
||||
await request
|
||||
.delete(`/api/${TEST_INSTANCE_ID}/records/${record._id}/${record._rev}`)
|
||||
.expect(200)
|
||||
|
||||
await request
|
||||
.get(`/api/${TEST_INSTANCE_ID}/records/${record._id}`)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(404)
|
||||
})
|
||||
|
||||
it("load should return 404 when record does not exist", async () => {
|
||||
await request
|
||||
.get(`/api/${TEST_INSTANCE_ID}/records/not-a-valid-id`)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(404)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue