@based/schema 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/set/collections.d.ts +5 -0
- package/dist/set/collections.js +211 -0
- package/dist/set/collections.js.map +1 -0
- package/dist/set/error.d.ts +15 -0
- package/dist/set/error.js +24 -0
- package/dist/set/error.js.map +1 -0
- package/dist/set/fields/object.d.ts.map +1 -1
- package/dist/set/fields/object.js.map +1 -1
- package/dist/set/fields/string.d.ts.map +1 -1
- package/dist/set/fields/string.js +7 -73
- package/dist/set/fields/string.js.map +1 -1
- package/dist/set/index.d.ts.map +1 -1
- package/dist/set/index.js +3 -0
- package/dist/set/index.js.map +1 -1
- package/dist/set/number.d.ts +4 -0
- package/dist/set/number.js +111 -0
- package/dist/set/number.js.map +1 -0
- package/dist/set/parseDefaultAndValue.d.ts +3 -0
- package/dist/set/parseDefaultAndValue.js +33 -0
- package/dist/set/parseDefaultAndValue.js.map +1 -0
- package/dist/set/parsers.d.ts +3 -0
- package/dist/set/parsers.js +42 -0
- package/dist/set/parsers.js.map +1 -0
- package/dist/set/references.d.ts +3 -0
- package/dist/set/references.js +77 -0
- package/dist/set/references.js.map +1 -0
- package/dist/set/rest.d.ts +5 -0
- package/dist/set/rest.js +76 -0
- package/dist/set/rest.js.map +1 -0
- package/dist/set/string.d.ts +3 -0
- package/dist/set/string.js +173 -0
- package/dist/set/string.js.map +1 -0
- package/package.json +1 -1
- package/src/set/fields/object.ts +1 -0
- package/src/set/fields/string.ts +7 -74
- package/src/set/index.ts +5 -0
- package/test/set.ts +3 -0
- package/test/text.ts +2 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseValueAndDefault = void 0;
|
|
7
|
+
const error_1 = require("./error");
|
|
8
|
+
const parsers_1 = __importDefault(require("./parsers"));
|
|
9
|
+
const parseValueAndDefault = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
10
|
+
let handled = false;
|
|
11
|
+
if (typeof value === 'object') {
|
|
12
|
+
const typeDef = fieldSchema.type ?? ('enum' in fieldSchema ? 'enum' : '');
|
|
13
|
+
const parse = parsers_1.default[typeDef];
|
|
14
|
+
if (value.$value !== undefined) {
|
|
15
|
+
// TODO: for errors handle path a bit smarter...
|
|
16
|
+
await parse(path, value.$value, fieldSchema, typeSchema, target, handlers, true);
|
|
17
|
+
handled = true;
|
|
18
|
+
}
|
|
19
|
+
if (value.$default !== undefined) {
|
|
20
|
+
if (value.$value !== undefined) {
|
|
21
|
+
(0, error_1.error)(path, error_1.ParseError.valueAndDefault);
|
|
22
|
+
}
|
|
23
|
+
await parse(path, value.$default, fieldSchema, typeSchema, target, handlers, true);
|
|
24
|
+
handled = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (handled && !noCollect) {
|
|
28
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
29
|
+
}
|
|
30
|
+
return handled;
|
|
31
|
+
};
|
|
32
|
+
exports.parseValueAndDefault = parseValueAndDefault;
|
|
33
|
+
//# sourceMappingURL=parseDefaultAndValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseDefaultAndValue.js","sourceRoot":"","sources":["../../src/set/parseDefaultAndValue.ts"],"names":[],"mappings":";;;;;;AAEA,mCAA2C;AAC3C,wDAA+B;AAExB,MAAM,oBAAoB,GAAoC,KAAK,EACxE,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACS,EAAE;IACpB,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACzE,MAAM,KAAK,GAAG,iBAAO,CAAC,OAAO,CAAC,CAAA;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE;YAC9B,gDAAgD;YAChD,MAAM,KAAK,CACT,IAAI,EACJ,KAAK,CAAC,MAAM,EACZ,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,CACL,CAAA;YACD,OAAO,GAAG,IAAI,CAAA;SACf;QACD,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE;gBAC9B,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,eAAe,CAAC,CAAA;aACxC;YACD,MAAM,KAAK,CACT,IAAI,EACJ,KAAK,CAAC,QAAQ,EACd,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,CACL,CAAA;YACD,OAAO,GAAG,IAAI,CAAA;SACf;KACF;IACD,IAAI,OAAO,IAAI,CAAC,SAAS,EAAE;QACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;KACnE;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AA9CY,QAAA,oBAAoB,wBA8ChC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const references = __importStar(require("./references"));
|
|
27
|
+
const collections = __importStar(require("./collections"));
|
|
28
|
+
const number = __importStar(require("./number"));
|
|
29
|
+
const string = __importStar(require("./string"));
|
|
30
|
+
const rest_1 = require("./rest");
|
|
31
|
+
const parsers = {
|
|
32
|
+
...string,
|
|
33
|
+
...references,
|
|
34
|
+
...collections,
|
|
35
|
+
...number,
|
|
36
|
+
enum: rest_1.enumParser,
|
|
37
|
+
boolean: rest_1.boolean,
|
|
38
|
+
cardinality: rest_1.cardinality,
|
|
39
|
+
json: rest_1.json,
|
|
40
|
+
};
|
|
41
|
+
exports.default = parsers;
|
|
42
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../src/set/parsers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,yDAA0C;AAC1C,2DAA4C;AAC5C,iDAAkC;AAClC,iDAAkC;AAElC,iCAA+D;AAE/D,MAAM,OAAO,GAAY;IACvB,GAAG,MAAM;IACT,GAAG,UAAU;IACb,GAAG,WAAW;IACd,GAAG,MAAM;IACT,IAAI,EAAE,iBAAU;IAChB,OAAO,EAAP,cAAO;IACP,WAAW,EAAX,kBAAW;IACX,IAAI,EAAJ,WAAI;CACL,CAAA;AAED,kBAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.references = exports.reference = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const reference = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
6
|
+
// $no root
|
|
7
|
+
// prob pass these as options
|
|
8
|
+
// value .default
|
|
9
|
+
// $value
|
|
10
|
+
if (typeof value !== 'string') {
|
|
11
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
12
|
+
}
|
|
13
|
+
if ('allowedTypes' in fieldSchema) {
|
|
14
|
+
const prefix = value.slice(0, 2);
|
|
15
|
+
const targetType = target.schema.prefixToTypeMapping[prefix];
|
|
16
|
+
if (!targetType) {
|
|
17
|
+
(0, error_1.error)(path, error_1.ParseError.referenceIsIncorrectType);
|
|
18
|
+
}
|
|
19
|
+
let typeMatches = false;
|
|
20
|
+
for (const t of fieldSchema.allowedTypes) {
|
|
21
|
+
if (typeof t === 'string') {
|
|
22
|
+
if (t === targetType) {
|
|
23
|
+
typeMatches = true;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (t.type && t.type === targetType) {
|
|
29
|
+
typeMatches = true;
|
|
30
|
+
if (t.$filter) {
|
|
31
|
+
if (!(await handlers.referenceFilterCondition(value, t.$filter))) {
|
|
32
|
+
(0, error_1.error)(path, error_1.ParseError.referenceIsIncorrectType);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (!t.type && t.$filter) {
|
|
37
|
+
if (!(await handlers.referenceFilterCondition(value, t.$filter))) {
|
|
38
|
+
(0, error_1.error)(path, error_1.ParseError.referenceIsIncorrectType);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (typeMatches === false) {
|
|
44
|
+
(0, error_1.error)(path, error_1.ParseError.referenceIsIncorrectType);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!noCollect) {
|
|
48
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.reference = reference;
|
|
52
|
+
const references = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
53
|
+
// default
|
|
54
|
+
// $no root
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
await Promise.all(value.map((v, i) => {
|
|
57
|
+
return (0, exports.reference)([...path, i], v,
|
|
58
|
+
// not nice slow
|
|
59
|
+
{ ...fieldSchema, type: 'reference' }, typeSchema, target, handlers, true);
|
|
60
|
+
}));
|
|
61
|
+
value = { $value: value };
|
|
62
|
+
}
|
|
63
|
+
else if (typeof value === 'object') {
|
|
64
|
+
if (value.$add) {
|
|
65
|
+
await Promise.all(value.$add.map((v, i) => {
|
|
66
|
+
return (0, exports.reference)([...path, '$add', i], v,
|
|
67
|
+
// not nice slow
|
|
68
|
+
{ ...fieldSchema, type: 'reference' }, typeSchema, target, handlers, true);
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!noCollect) {
|
|
73
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.references = references;
|
|
77
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.js","sourceRoot":"","sources":["../../src/set/references.ts"],"names":[],"mappings":";;;AACA,mCAA2C;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AC,CAAC,EAAE,CAAC,EAAE,EAAE;gBACtB,OAAO,IAAA,iBAAS,EACd,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,EACpB,CAAC;gBACD,gBAAgB;gBAChB,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EACrC,UAAU,EACV,MAAM,EACN,QAAQ,EACR,IAAI,CACL,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;KACF;IACD,IAAI,CAAC,SAAS,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;KACnE;AACH,CAAC,CAAA;AAhDY,QAAA,UAAU,cAgDtB"}
|
package/dist/set/rest.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.json = exports.enumParser = exports.boolean = exports.cardinality = void 0;
|
|
4
|
+
const utils_1 = require("@saulx/utils");
|
|
5
|
+
const hash_1 = require("@saulx/hash");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const parseDefaultAndValue_1 = require("./parseDefaultAndValue");
|
|
8
|
+
const cardinality = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
9
|
+
if (value && typeof value === 'object') {
|
|
10
|
+
if (value.$default !== undefined) {
|
|
11
|
+
(0, error_1.error)(path, error_1.ParseError.defaultNotSupported);
|
|
12
|
+
}
|
|
13
|
+
if (value.$value !== undefined) {
|
|
14
|
+
value = (0, hash_1.hashObjectIgnoreKeyOrder)(value.$value).toString(16);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
value = (0, hash_1.hashObjectIgnoreKeyOrder)(value).toString(16);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
value = (0, hash_1.hash)(value).toString(16);
|
|
22
|
+
}
|
|
23
|
+
if (!noCollect) {
|
|
24
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.cardinality = cardinality;
|
|
28
|
+
const boolean = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
29
|
+
if (await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== 'boolean') {
|
|
33
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
34
|
+
}
|
|
35
|
+
if (!noCollect) {
|
|
36
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.boolean = boolean;
|
|
40
|
+
const enumParser = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
41
|
+
const enumValues = fieldSchema.enum;
|
|
42
|
+
if (!(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect))) {
|
|
43
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
44
|
+
if ((0, utils_1.deepEqual)(enumValues[i], value)) {
|
|
45
|
+
if (!noCollect) {
|
|
46
|
+
handlers.collect({ path, value: i, typeSchema, fieldSchema, target });
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.enumParser = enumParser;
|
|
55
|
+
const json = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
56
|
+
if (await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const parsedValue = JSON.stringify(value);
|
|
61
|
+
if (!noCollect) {
|
|
62
|
+
handlers.collect({
|
|
63
|
+
path,
|
|
64
|
+
value: parsedValue,
|
|
65
|
+
typeSchema,
|
|
66
|
+
fieldSchema,
|
|
67
|
+
target,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.json = json;
|
|
76
|
+
//# sourceMappingURL=rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/set/rest.ts"],"names":[],"mappings":";;;AACA,wCAAwC;AACxC,sCAA4D;AAC5D,mCAA2C;AAC3C,iEAA6D;AAEtD,MAAM,WAAW,GAA0B,KAAK,EACrD,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACtC,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,mBAAmB,CAAC,CAAA;SAC5C;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE;YAC9B,KAAK,GAAG,IAAA,+BAAwB,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;SAC5D;aAAM;YACL,KAAK,GAAG,IAAA,+BAAwB,EAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;SACrD;KACF;SAAM;QACL,KAAK,GAAG,IAAA,WAAI,EAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;KACjC;IACD,IAAI,CAAC,SAAS,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC,EAAE,I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AE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;iBACtE;gBACD,OAAM;aACP;SACF;QACD,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,eAAe,CAAC,CAAA;KACxC;AACH,CAAC,CAAA;AA/BY,QAAA,UAAU,cA+BtB;AAEM,MAAM,IAAI,GAAmB,KAAK,EACvC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,IACE,MAAM,IAAA,2CAAoB,EACxB,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,CACV,EACD;QACA,OAAM;KACP;IAED,IAAI;QACF,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACzC,IAAI,CAAC,SAAS,EAAE;YACd,QAAQ,CAAC,OAAO,CAAC;gBACf,IAAI;gBACJ,KAAK,EAAE,WAAW;gBAClB,UAAU;gBACV,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;SACH;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,eAAe,CAAC,CAAA;KACxC;AACH,CAAC,CAAA;AArCY,QAAA,IAAI,QAqChB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.text = exports.string = void 0;
|
|
7
|
+
const error_1 = require("./error");
|
|
8
|
+
const validator_1 = __importDefault(require("validator"));
|
|
9
|
+
const parseDefaultAndValue_1 = require("./parseDefaultAndValue");
|
|
10
|
+
const formatPatterns = {
|
|
11
|
+
email: validator_1.default.isEmail,
|
|
12
|
+
URL: validator_1.default.isURL,
|
|
13
|
+
MACAddress: validator_1.default.isMACAddress,
|
|
14
|
+
IP: validator_1.default.isIP,
|
|
15
|
+
IPRange: validator_1.default.isIPRange,
|
|
16
|
+
FQDN: validator_1.default.isFQDN,
|
|
17
|
+
IBAN: validator_1.default.isIBAN,
|
|
18
|
+
BIC: validator_1.default.isBIC,
|
|
19
|
+
alpha: validator_1.default.isAlpha,
|
|
20
|
+
alphaLocales: validator_1.default.isAlphaLocales,
|
|
21
|
+
alphanumeric: validator_1.default.isAlphanumeric,
|
|
22
|
+
alphanumericLocales: validator_1.default.isAlphanumericLocales,
|
|
23
|
+
passportNumber: validator_1.default.isPassportNumber,
|
|
24
|
+
port: validator_1.default.isPort,
|
|
25
|
+
lowercase: validator_1.default.isLowercase,
|
|
26
|
+
uppercase: validator_1.default.isUppercase,
|
|
27
|
+
ascii: validator_1.default.isAscii,
|
|
28
|
+
semVer: validator_1.default.isSemVer,
|
|
29
|
+
surrogatePair: validator_1.default.isSurrogatePair,
|
|
30
|
+
IMEI: validator_1.default.isIMEI,
|
|
31
|
+
hexadecimal: validator_1.default.isHexadecimal,
|
|
32
|
+
octal: validator_1.default.isOctal,
|
|
33
|
+
hexColor: validator_1.default.isHexColor,
|
|
34
|
+
rgbColor: validator_1.default.isRgbColor,
|
|
35
|
+
HSL: validator_1.default.isHSL,
|
|
36
|
+
ISRC: validator_1.default.isISRC,
|
|
37
|
+
MD5: validator_1.default.isMD5,
|
|
38
|
+
JWT: validator_1.default.isJWT,
|
|
39
|
+
UUID: validator_1.default.isUUID,
|
|
40
|
+
luhnNumber: validator_1.default.isLuhnNumber,
|
|
41
|
+
creditCard: validator_1.default.isCreditCard,
|
|
42
|
+
identityCard: validator_1.default.isIdentityCard,
|
|
43
|
+
EAN: validator_1.default.isEAN,
|
|
44
|
+
ISIN: validator_1.default.isISIN,
|
|
45
|
+
ISBN: validator_1.default.isISBN,
|
|
46
|
+
ISSN: validator_1.default.isISSN,
|
|
47
|
+
mobilePhone: validator_1.default.isMobilePhone,
|
|
48
|
+
mobilePhoneLocales: validator_1.default.isMobilePhoneLocales,
|
|
49
|
+
postalCode: validator_1.default.isPostalCode,
|
|
50
|
+
postalCodeLocales: validator_1.default.isPostalCodeLocales,
|
|
51
|
+
ethereumAddress: validator_1.default.isEthereumAddress,
|
|
52
|
+
currency: validator_1.default.isCurrency,
|
|
53
|
+
btcAddress: validator_1.default.isBtcAddress,
|
|
54
|
+
ISO6391: validator_1.default.isISO6391,
|
|
55
|
+
ISO8601: validator_1.default.isISO8601,
|
|
56
|
+
RFC3339: validator_1.default.isRFC3339,
|
|
57
|
+
ISO31661Alpha2: validator_1.default.isISO31661Alpha2,
|
|
58
|
+
ISO31661Alpha3: validator_1.default.isISO31661Alpha3,
|
|
59
|
+
ISO4217: validator_1.default.isISO4217,
|
|
60
|
+
base32: validator_1.default.isBase32,
|
|
61
|
+
base58: validator_1.default.isBase58,
|
|
62
|
+
base64: validator_1.default.isBase64,
|
|
63
|
+
dataURI: validator_1.default.isDataURI,
|
|
64
|
+
magnetURI: validator_1.default.isMagnetURI,
|
|
65
|
+
mimeType: validator_1.default.isMimeType,
|
|
66
|
+
latLong: validator_1.default.isLatLong,
|
|
67
|
+
slug: validator_1.default.isSlug,
|
|
68
|
+
strongPassword: validator_1.default.isStrongPassword,
|
|
69
|
+
taxID: validator_1.default.isTaxID,
|
|
70
|
+
licensePlate: validator_1.default.isLicensePlate,
|
|
71
|
+
VAT: validator_1.default.isVAT,
|
|
72
|
+
};
|
|
73
|
+
const validate = (path, value, fieldSchema) => {
|
|
74
|
+
if (typeof value !== 'string') {
|
|
75
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
76
|
+
}
|
|
77
|
+
if (fieldSchema.minLength && value.length < fieldSchema.minLength) {
|
|
78
|
+
(0, error_1.error)(path, error_1.ParseError.subceedsMinimum);
|
|
79
|
+
}
|
|
80
|
+
if (fieldSchema.maxLength && value.length > fieldSchema.maxLength) {
|
|
81
|
+
(0, error_1.error)(path, error_1.ParseError.exceedsMaximum);
|
|
82
|
+
}
|
|
83
|
+
if (fieldSchema.pattern) {
|
|
84
|
+
const re = new RegExp(fieldSchema.pattern);
|
|
85
|
+
if (!re.test(value)) {
|
|
86
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (fieldSchema.format && !formatPatterns[fieldSchema.format](value)) {
|
|
90
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const string = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
94
|
+
if (await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
validate(path, value, fieldSchema);
|
|
98
|
+
if (!noCollect) {
|
|
99
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.string = string;
|
|
103
|
+
const text = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
104
|
+
const valueType = typeof value;
|
|
105
|
+
if (target.$language && valueType === 'string') {
|
|
106
|
+
validate(path, value, fieldSchema);
|
|
107
|
+
if (!noCollect) {
|
|
108
|
+
handlers.collect({
|
|
109
|
+
path,
|
|
110
|
+
value: { [target.$language]: value },
|
|
111
|
+
typeSchema,
|
|
112
|
+
fieldSchema,
|
|
113
|
+
target,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (valueType !== 'object') {
|
|
119
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
120
|
+
}
|
|
121
|
+
if (target.$language &&
|
|
122
|
+
(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect))) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
else if (await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, true)) {
|
|
126
|
+
if (!noCollect) {
|
|
127
|
+
handlers.collect({
|
|
128
|
+
path,
|
|
129
|
+
value,
|
|
130
|
+
typeSchema,
|
|
131
|
+
fieldSchema,
|
|
132
|
+
target,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (const key in value) {
|
|
138
|
+
const newPath = [...path, key];
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
if (!target.schema.languages.includes(key)) {
|
|
141
|
+
(0, error_1.error)(newPath, error_1.ParseError.languageNotSupported);
|
|
142
|
+
}
|
|
143
|
+
if (typeof value[key] === 'object') {
|
|
144
|
+
if (value[key].$value) {
|
|
145
|
+
await (0, exports.text)([...newPath, '$value'], value[key].$value, fieldSchema, typeSchema, target, handlers, true);
|
|
146
|
+
}
|
|
147
|
+
if (!noCollect) {
|
|
148
|
+
handlers.collect({
|
|
149
|
+
path: newPath,
|
|
150
|
+
value: null,
|
|
151
|
+
typeSchema,
|
|
152
|
+
fieldSchema,
|
|
153
|
+
target,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, { [key]: value[key] }, fieldSchema, typeSchema, target, handlers, true))) {
|
|
159
|
+
validate(newPath, value[key], fieldSchema);
|
|
160
|
+
}
|
|
161
|
+
if (!noCollect) {
|
|
162
|
+
handlers.collect({
|
|
163
|
+
path: newPath,
|
|
164
|
+
value: value[key],
|
|
165
|
+
typeSchema,
|
|
166
|
+
fieldSchema,
|
|
167
|
+
target,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
exports.text = text;
|
|
173
|
+
//# source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AAE,OAAO;gBACb,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;gBACjB,UAAU;gBACV,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;SACH;KACF;AACH,CAAC,CAAA;AAzHY,QAAA,IAAI,QAyHhB"}
|
package/package.json
CHANGED
package/src/set/fields/object.ts
CHANGED
package/src/set/fields/string.ts
CHANGED
|
@@ -164,6 +164,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
164
164
|
args
|
|
165
165
|
.create({
|
|
166
166
|
key: k,
|
|
167
|
+
fieldSchema: { type: 'string' },
|
|
167
168
|
value: { $default: args.value[key][k] },
|
|
168
169
|
})
|
|
169
170
|
.collect()
|
|
@@ -180,6 +181,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
180
181
|
} else {
|
|
181
182
|
args
|
|
182
183
|
.create({
|
|
184
|
+
fieldSchema: { type: 'string' },
|
|
183
185
|
key: args.target.$language,
|
|
184
186
|
value: { $default: args.value[key] },
|
|
185
187
|
})
|
|
@@ -196,6 +198,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
196
198
|
args
|
|
197
199
|
.create({
|
|
198
200
|
key,
|
|
201
|
+
fieldSchema: { type: 'string' },
|
|
199
202
|
value: args.value[key],
|
|
200
203
|
})
|
|
201
204
|
.collect()
|
|
@@ -206,6 +209,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
206
209
|
args
|
|
207
210
|
.create({
|
|
208
211
|
key,
|
|
212
|
+
fieldSchema: { type: 'string' },
|
|
209
213
|
value: args.value[key].$value,
|
|
210
214
|
})
|
|
211
215
|
.collect()
|
|
@@ -217,6 +221,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
217
221
|
args
|
|
218
222
|
.create({
|
|
219
223
|
key,
|
|
224
|
+
fieldSchema: { type: 'string' },
|
|
220
225
|
value: { $default: args.value[key].$default },
|
|
221
226
|
})
|
|
222
227
|
.collect()
|
|
@@ -236,6 +241,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
236
241
|
args
|
|
237
242
|
.create({
|
|
238
243
|
key,
|
|
244
|
+
fieldSchema: { type: 'string' },
|
|
239
245
|
value: args.value[key],
|
|
240
246
|
})
|
|
241
247
|
.collect()
|
|
@@ -269,6 +275,7 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
269
275
|
.create({
|
|
270
276
|
value,
|
|
271
277
|
key: args.target.$language,
|
|
278
|
+
fieldSchema: { type: 'string' },
|
|
272
279
|
})
|
|
273
280
|
.collect()
|
|
274
281
|
|
|
@@ -278,77 +285,3 @@ export const text: FieldParser<'text'> = async (args) => {
|
|
|
278
285
|
})
|
|
279
286
|
}
|
|
280
287
|
}
|
|
281
|
-
|
|
282
|
-
/*
|
|
283
|
-
const value = args.value
|
|
284
|
-
if (value !== null && typeof value === 'object') {
|
|
285
|
-
args.stop()
|
|
286
|
-
const result: any = {}
|
|
287
|
-
for (const key in value) {
|
|
288
|
-
if (key === '$value') {
|
|
289
|
-
const nValue = await next(args, key)
|
|
290
|
-
if (typeof nValue === 'object') {
|
|
291
|
-
deepMerge(result, nValue)
|
|
292
|
-
} else {
|
|
293
|
-
args.error(ParseError.incorrectFormat)
|
|
294
|
-
return
|
|
295
|
-
}
|
|
296
|
-
} else if (key === '$default') {
|
|
297
|
-
result.$default = await next(args, key)
|
|
298
|
-
} else if (args.schema.languages.includes(<BasedSchemaLanguage>key)) {
|
|
299
|
-
if (value[key] && typeof value[key] === 'object') {
|
|
300
|
-
for (const k in value[key]) {
|
|
301
|
-
if (k === '$value') {
|
|
302
|
-
if (!validateString(args, value[key].$value)) {
|
|
303
|
-
args.create({ key }).error(ParseError.incorrectFormat)
|
|
304
|
-
} else {
|
|
305
|
-
result[key] = value[key].$value
|
|
306
|
-
}
|
|
307
|
-
} else if (k === '$default') {
|
|
308
|
-
if (!validateString(args, value[key].$default)) {
|
|
309
|
-
args.create({ key }).error(ParseError.incorrectFormat)
|
|
310
|
-
} else {
|
|
311
|
-
setByPath(result, ['$default', key], value[key].$default)
|
|
312
|
-
}
|
|
313
|
-
} else {
|
|
314
|
-
args
|
|
315
|
-
.create({ path: [...args.path, key, k] })
|
|
316
|
-
.error(ParseError.fieldDoesNotExist)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
if (!validateString(args, args.value[key])) {
|
|
321
|
-
args.error(ParseError.incorrectFormat)
|
|
322
|
-
return
|
|
323
|
-
}
|
|
324
|
-
result[key] = args.value[key]
|
|
325
|
-
}
|
|
326
|
-
} else {
|
|
327
|
-
args.create({ key }).error(ParseError.languageNotSupported)
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
args.collect(result)
|
|
331
|
-
return
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (typeof value !== 'string') {
|
|
335
|
-
args.error(ParseError.incorrectFormat)
|
|
336
|
-
return
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (!args.target.$language) {
|
|
340
|
-
args.error(ParseError.noLanguageFound)
|
|
341
|
-
return
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (!validateString(args, args.value)) {
|
|
345
|
-
args.error(ParseError.incorrectFormat)
|
|
346
|
-
return
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
args.value = {
|
|
350
|
-
[args.target.$language]: value,
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
args.collect()
|
|
354
|
-
*/
|
package/src/set/index.ts
CHANGED
package/test/set.ts
CHANGED
|
@@ -79,7 +79,10 @@ test('$merge on object', async (t) => {
|
|
|
79
79
|
|
|
80
80
|
t.true(r.errors.length === 0)
|
|
81
81
|
t.deepEqual(resultCollect(r), [
|
|
82
|
+
{ path: ['x'], value: { $delete: true } },
|
|
83
|
+
|
|
82
84
|
{ path: ['x', 'bla'], value: 'x' },
|
|
85
|
+
|
|
83
86
|
{ path: ['x'], value: { $merge: false, bla: 'x' } },
|
|
84
87
|
])
|
|
85
88
|
})
|
package/test/text.ts
CHANGED
|
@@ -326,6 +326,8 @@ test('$default in collected path + $merge:false', async (t) => {
|
|
|
326
326
|
})
|
|
327
327
|
t.is(r.errors.length, 0)
|
|
328
328
|
t.deepEqual(resultCollect(r), [
|
|
329
|
+
{ path: ['text'], value: { $delete: true } },
|
|
330
|
+
|
|
329
331
|
{ path: ['text', 'en'], value: { $default: 'title' } },
|
|
330
332
|
{
|
|
331
333
|
path: ['text'],
|