@based/schema 0.0.7 → 0.0.8
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/checkDefaultAndValue.d.ts +3 -0
- package/dist/set/checkDefaultAndValue.js +33 -0
- package/dist/set/checkDefaultAndValue.js.map +1 -0
- package/dist/set/collections.js +50 -10
- package/dist/set/collections.js.map +1 -1
- package/dist/set/error.d.ts +4 -1
- package/dist/set/error.js +3 -0
- package/dist/set/error.js.map +1 -1
- package/dist/set/number.js +18 -6
- package/dist/set/number.js.map +1 -1
- 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/rest.js +29 -10
- package/dist/set/rest.js.map +1 -1
- package/dist/set/string.js +10 -3
- package/dist/set/string.js.map +1 -1
- package/dist/set/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/set/collections.ts +64 -10
- package/src/set/error.ts +3 -0
- package/src/set/number.ts +20 -6
- package/src/set/parseDefaultAndValue.ts +44 -0
- package/src/set/rest.ts +62 -10
- package/src/set/string.ts +32 -5
- package/src/set/types.ts +1 -1
- package/test/setWalker.ts +86 -5
|
@@ -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
|
+
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
|
+
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=checkDefaultAndValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkDefaultAndValue.js","sourceRoot":"","sources":["../../src/set/checkDefaultAndValue.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,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;YAC1E,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,KAAK,CACH,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;AAtCY,QAAA,oBAAoB,wBAsChC"}
|
package/dist/set/collections.js
CHANGED
|
@@ -30,12 +30,12 @@ const set = async (path, value, fieldSchema, typeSchema, target, handlers, noCol
|
|
|
30
30
|
else {
|
|
31
31
|
if (value.$add) {
|
|
32
32
|
for (let i = 0; i < value.$add.length; i++) {
|
|
33
|
-
q.push((0, _1.fieldWalker)(
|
|
33
|
+
q.push((0, _1.fieldWalker)(path, value.$add[i], fieldDef, typeSchema, target, handlers, true));
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
if (value.$delete) {
|
|
37
37
|
for (let i = 0; i < value.$add.length; i++) {
|
|
38
|
-
q.push((0, _1.fieldWalker)(
|
|
38
|
+
q.push((0, _1.fieldWalker)(path, value.$delete[i], fieldDef, typeSchema, target, handlers, true));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
await Promise.all(q);
|
|
@@ -64,13 +64,17 @@ const object = async (path, value, fieldSchema, typeSchema, target, handlers, no
|
|
|
64
64
|
await Promise.all(q);
|
|
65
65
|
};
|
|
66
66
|
exports.object = object;
|
|
67
|
+
// unshift // only allow 1 command
|
|
67
68
|
const array = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
68
69
|
const isArray = Array.isArray(value);
|
|
70
|
+
let parsedValue = value;
|
|
71
|
+
let opCount = 0;
|
|
69
72
|
if (typeof value === 'object' && !isArray) {
|
|
70
73
|
if (value.$insert) {
|
|
74
|
+
opCount++;
|
|
71
75
|
if (typeof value.$insert !== 'object' ||
|
|
72
76
|
value.$insert.$idx === undefined) {
|
|
73
|
-
(0, error_1.error)(
|
|
77
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
74
78
|
}
|
|
75
79
|
else {
|
|
76
80
|
const insert = Array.isArray(value.$insert.$value)
|
|
@@ -78,33 +82,69 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
78
82
|
: [value.$insert.$value];
|
|
79
83
|
const q = [];
|
|
80
84
|
for (let i = 0; i < insert.length; i++) {
|
|
81
|
-
q.push((0, _1.fieldWalker)(
|
|
85
|
+
q.push((0, _1.fieldWalker)(path, insert[i], fieldSchema.values, typeSchema, target, handlers, true));
|
|
82
86
|
}
|
|
83
87
|
await Promise.all(q);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
|
-
if (value.$remove
|
|
87
|
-
|
|
90
|
+
if (value.$remove) {
|
|
91
|
+
opCount++;
|
|
92
|
+
if (opCount > 1) {
|
|
93
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
94
|
+
}
|
|
95
|
+
if (value.$remove.$idx === undefined) {
|
|
96
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
97
|
+
}
|
|
88
98
|
}
|
|
89
99
|
if (value.$push) {
|
|
100
|
+
opCount++;
|
|
101
|
+
if (opCount > 1) {
|
|
102
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
103
|
+
}
|
|
90
104
|
const q = [];
|
|
91
105
|
const push = Array.isArray(value.$push) ? value.$push : [value.$push];
|
|
92
106
|
for (let i = 0; i < push.length; i++) {
|
|
93
|
-
q.push((0, _1.fieldWalker)(
|
|
107
|
+
q.push((0, _1.fieldWalker)(path, push[i], fieldSchema.values, typeSchema, target, handlers, true));
|
|
108
|
+
}
|
|
109
|
+
await Promise.all(q);
|
|
110
|
+
parsedValue = { $push: push };
|
|
111
|
+
}
|
|
112
|
+
if (value.$unshift) {
|
|
113
|
+
opCount++;
|
|
114
|
+
if (opCount > 1) {
|
|
115
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
116
|
+
}
|
|
117
|
+
const q = [];
|
|
118
|
+
const unshift = Array.isArray(value.$unshift)
|
|
119
|
+
? value.$unshift
|
|
120
|
+
: [value.$unshift];
|
|
121
|
+
for (let i = 0; i < unshift.length; i++) {
|
|
122
|
+
q.push((0, _1.fieldWalker)(path, unshift[i], fieldSchema.values, typeSchema, target, handlers, true));
|
|
94
123
|
}
|
|
95
124
|
await Promise.all(q);
|
|
125
|
+
parsedValue = { $unshift: unshift };
|
|
96
126
|
}
|
|
97
127
|
if (value.$assign) {
|
|
128
|
+
opCount++;
|
|
129
|
+
if (opCount > 1) {
|
|
130
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
131
|
+
}
|
|
98
132
|
if (typeof value.$assign !== 'object' ||
|
|
99
133
|
value.$assign.$idx === undefined) {
|
|
100
|
-
(0, error_1.error)(
|
|
134
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
101
135
|
}
|
|
102
136
|
else {
|
|
103
|
-
await (0, _1.fieldWalker)(
|
|
137
|
+
await (0, _1.fieldWalker)(path, value.$assign.$value, fieldSchema.values, typeSchema, target, handlers, true);
|
|
104
138
|
}
|
|
105
139
|
}
|
|
106
140
|
if (!noCollect) {
|
|
107
|
-
handlers.collect({
|
|
141
|
+
handlers.collect({
|
|
142
|
+
path,
|
|
143
|
+
value: parsedValue,
|
|
144
|
+
typeSchema,
|
|
145
|
+
fieldSchema,
|
|
146
|
+
target,
|
|
147
|
+
});
|
|
108
148
|
}
|
|
109
149
|
return;
|
|
110
150
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../../src/set/collections.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAC3C,wBAA+B;AAExB,MAAM,GAAG,GAAkB,KAAK,EACrC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,MAAM,CAAC,GAAoB,EAAE,CAAA;IAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAA;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,WAAW,GAAG,EAAE,CAAA;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,CAAC,CAAC,IAAI,CACJ,IAAA,cAAW,EAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE;gBAChE,GAAG,QAAQ;gBACX,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;oBACrB,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACzB,CAAC;aACF,CAAC,CACH,CAAA;SACF;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACpB,IAAI,CAAC,SAAS,EAAE;YACd,QAAQ,CAAC,OAAO,CAAC;gBACf,IAAI;gBACJ,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;gBAC9B,UAAU;gBACV,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,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,GAAE,CAAC,CAAA;AAAjE,QAAA,MAAM,UAA2D"}
|
package/dist/set/error.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ export declare enum ParseError {
|
|
|
5
5
|
'subceedsMinimum' = 3,
|
|
6
6
|
'fieldDoesNotExist' = 4,
|
|
7
7
|
'incorrectFormat' = 5,
|
|
8
|
-
'referenceIsIncorrectType' = 6
|
|
8
|
+
'referenceIsIncorrectType' = 6,
|
|
9
|
+
'valueAndDefault' = 7,
|
|
10
|
+
'defaultNotSupported' = 8,
|
|
11
|
+
'multipleOperationsNotAllowed' = 9
|
|
9
12
|
}
|
|
10
13
|
export declare const error: (path: (number | string)[], error: ParseError, type?: string) => never;
|
package/dist/set/error.js
CHANGED
|
@@ -10,6 +10,9 @@ var ParseError;
|
|
|
10
10
|
ParseError[ParseError["fieldDoesNotExist"] = 4] = "fieldDoesNotExist";
|
|
11
11
|
ParseError[ParseError["incorrectFormat"] = 5] = "incorrectFormat";
|
|
12
12
|
ParseError[ParseError["referenceIsIncorrectType"] = 6] = "referenceIsIncorrectType";
|
|
13
|
+
ParseError[ParseError["valueAndDefault"] = 7] = "valueAndDefault";
|
|
14
|
+
ParseError[ParseError["defaultNotSupported"] = 8] = "defaultNotSupported";
|
|
15
|
+
ParseError[ParseError["multipleOperationsNotAllowed"] = 9] = "multipleOperationsNotAllowed";
|
|
13
16
|
})(ParseError = exports.ParseError || (exports.ParseError = {}));
|
|
14
17
|
const error = (path, error, type // nice to give as option
|
|
15
18
|
) => {
|
package/dist/set/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/set/error.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/set/error.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAWX;AAXD,WAAY,UAAU;IACpB,uEAAoB,CAAA;IACpB,qEAAmB,CAAA;IACnB,+DAAgB,CAAA;IAChB,iEAAiB,CAAA;IACjB,qEAAmB,CAAA;IACnB,iEAAiB,CAAA;IACjB,mFAA0B,CAAA;IAC1B,iEAAiB,CAAA;IACjB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;AAChC,CAAC,EAXW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAWrB;AAEM,MAAM,KAAK,GAAG,CACnB,IAAyB,EACzB,KAAiB,EACjB,IAAa,CAAC,yBAAyB;EACvC,EAAE;IACF,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACpE,CAAC,CAAA;AANY,QAAA,KAAK,SAMjB"}
|
package/dist/set/number.js
CHANGED
|
@@ -6,6 +6,15 @@ const validate = (path, value, fieldSchema) => {
|
|
|
6
6
|
if (typeof value !== 'number') {
|
|
7
7
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
8
8
|
}
|
|
9
|
+
if (fieldSchema.type === 'integer' && value - Math.floor(value) !== 0) {
|
|
10
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
11
|
+
}
|
|
12
|
+
if (fieldSchema.multipleOf &&
|
|
13
|
+
value / fieldSchema.multipleOf -
|
|
14
|
+
Math.floor(value / fieldSchema.multipleOf) !==
|
|
15
|
+
0) {
|
|
16
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
17
|
+
}
|
|
9
18
|
if (fieldSchema.maximum) {
|
|
10
19
|
if (fieldSchema.exclusiveMaximum && value > value) {
|
|
11
20
|
(0, error_1.error)(path, error_1.ParseError.exceedsMaximum);
|
|
@@ -32,8 +41,14 @@ const shared = (path, value, fieldSchema) => {
|
|
|
32
41
|
if (value.$decrement) {
|
|
33
42
|
validate([...path, '$decrement'], value.$decrement, fieldSchema);
|
|
34
43
|
}
|
|
35
|
-
if (value.$value) {
|
|
36
|
-
validate(
|
|
44
|
+
if (value.$value !== undefined) {
|
|
45
|
+
validate(path, value.$value, fieldSchema);
|
|
46
|
+
}
|
|
47
|
+
if (value.$default !== undefined) {
|
|
48
|
+
if (value.$value !== undefined) {
|
|
49
|
+
(0, error_1.error)(path, error_1.ParseError.valueAndDefault);
|
|
50
|
+
}
|
|
51
|
+
validate(path, value.$default, fieldSchema);
|
|
37
52
|
}
|
|
38
53
|
}
|
|
39
54
|
else {
|
|
@@ -50,7 +65,7 @@ const timestamp = async (path, value, fieldSchema, typeSchema, target, handlers,
|
|
|
50
65
|
const d = new Date(value);
|
|
51
66
|
value = d.valueOf();
|
|
52
67
|
if (isNaN(value)) {
|
|
53
|
-
|
|
68
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
}
|
|
@@ -80,9 +95,6 @@ const number = async (path, value, fieldSchema, typeSchema, target, handlers, no
|
|
|
80
95
|
};
|
|
81
96
|
exports.number = number;
|
|
82
97
|
const integer = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
83
|
-
if (typeof value === 'number' && value - Math.floor(value) !== 0) {
|
|
84
|
-
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
85
|
-
}
|
|
86
98
|
const parsedValue = shared(path, value, fieldSchema);
|
|
87
99
|
if (!noCollect) {
|
|
88
100
|
handlers.collect({
|
package/dist/set/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/set/number.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAO3C,MAAM,QAAQ,GAAG,CACf,IAAyB,EACzB,KAAU,EACV,WAG6B,EACrB,EAAE;IACV,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,eAAe,CAAC,CAAA;KACxC;IACD,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AU,CAAC,eAAe,CAAC,CAAA;aACxC;SACF;KACF;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;IACpD,IAAI,CAAC,SAAS,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC;YACf,IAAI;YACJ,KAAK,EAAE,WAAW;YAClB,UAAU;YACV,WAAW;YACX,MAAM;SACP,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AA9BY,QAAA,SAAS,aA8BrB;AAEM,MAAM,MAAM,GAAqB,KAAK,EAC3C,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;IACpD,IAAI,CAAC,SAAS,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC;YACf,IAAI;YACJ,KAAK,EAAE,WAAW;YAClB,UAAU;YACV,WAAW;YACX,MAAM;SACP,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAnBY,QAAA,MAAM,UAmBlB;AAEM,MAAM,OAAO,GAAsB,KAAK,EAC7C,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,EACT,EAAE;IACF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;IACpD,IAAI,CAAC,SAAS,EAAE;QACd,QAAQ,CAAC,OAAO,CAAC;YACf,IAAI;YACJ,KAAK,EAAE,WAAW;YAClB,UAAU;YACV,WAAW;YACX,MAAM;SACP,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAnBY,QAAA,OAAO,WAmBnB"}
|
|
@@ -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
|
+
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
|
+
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,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;YAC1E,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,KAAK,CACH,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;AAtCY,QAAA,oBAAoB,wBAsChC"}
|
package/dist/set/rest.js
CHANGED
|
@@ -4,17 +4,31 @@ exports.json = exports.enumParser = exports.boolean = exports.cardinality = void
|
|
|
4
4
|
const utils_1 = require("@saulx/utils");
|
|
5
5
|
const hash_1 = require("@saulx/hash");
|
|
6
6
|
const error_1 = require("./error");
|
|
7
|
-
const
|
|
7
|
+
const parseDefaultAndValue_1 = require("./parseDefaultAndValue");
|
|
8
|
+
const cardinality = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
8
9
|
if (value && typeof value === 'object') {
|
|
9
|
-
value
|
|
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
|
+
}
|
|
10
19
|
}
|
|
11
20
|
else {
|
|
12
21
|
value = (0, hash_1.hash)(value).toString(16);
|
|
13
22
|
}
|
|
14
|
-
|
|
23
|
+
if (!noCollect) {
|
|
24
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
25
|
+
}
|
|
15
26
|
};
|
|
16
27
|
exports.cardinality = cardinality;
|
|
17
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
|
+
}
|
|
18
32
|
if (typeof value !== 'boolean') {
|
|
19
33
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
20
34
|
}
|
|
@@ -25,18 +39,23 @@ const boolean = async (path, value, fieldSchema, typeSchema, target, handlers, n
|
|
|
25
39
|
exports.boolean = boolean;
|
|
26
40
|
const enumParser = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
27
41
|
const enumValues = fieldSchema.enum;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
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;
|
|
32
49
|
}
|
|
33
|
-
return;
|
|
34
50
|
}
|
|
51
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
35
52
|
}
|
|
36
|
-
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
37
53
|
};
|
|
38
54
|
exports.enumParser = enumParser;
|
|
39
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
|
+
}
|
|
40
59
|
try {
|
|
41
60
|
const parsedValue = JSON.stringify(value);
|
|
42
61
|
if (!noCollect) {
|
|
@@ -50,7 +69,7 @@ const json = async (path, value, fieldSchema, typeSchema, target, handlers, noCo
|
|
|
50
69
|
}
|
|
51
70
|
}
|
|
52
71
|
catch (err) {
|
|
53
|
-
|
|
72
|
+
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
54
73
|
}
|
|
55
74
|
};
|
|
56
75
|
exports.json = json;
|
package/dist/set/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/set/rest.ts"],"names":[],"mappings":";;;AACA,wCAAwC;AACxC,sCAA4D;AAC5D,mCAA2C;
|
|
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,EAC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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"}
|
package/dist/set/string.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.text = exports.string = void 0;
|
|
7
7
|
const error_1 = require("./error");
|
|
8
8
|
const validator_1 = __importDefault(require("validator"));
|
|
9
|
+
const parseDefaultAndValue_1 = require("./parseDefaultAndValue");
|
|
9
10
|
const formatPatterns = {
|
|
10
11
|
email: validator_1.default.isEmail,
|
|
11
12
|
URL: validator_1.default.isURL,
|
|
@@ -90,6 +91,9 @@ const validate = (path, value, fieldSchema) => {
|
|
|
90
91
|
}
|
|
91
92
|
};
|
|
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
|
+
}
|
|
93
97
|
validate(path, value, fieldSchema);
|
|
94
98
|
if (!noCollect) {
|
|
95
99
|
handlers.collect({ path, value, typeSchema, fieldSchema, target });
|
|
@@ -114,14 +118,16 @@ const text = async (path, value, fieldSchema, typeSchema, target, handlers, noCo
|
|
|
114
118
|
if (valueType !== 'object') {
|
|
115
119
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
116
120
|
}
|
|
121
|
+
if (target.$language &&
|
|
122
|
+
(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect))) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
117
125
|
for (const key in value) {
|
|
118
126
|
const newPath = [...path, key];
|
|
119
127
|
if (typeof value[key] === 'object') {
|
|
120
128
|
if (value[key].$value) {
|
|
121
129
|
(0, exports.text)([...path, key, '$value'], value[key].$value, fieldSchema, typeSchema, target, handlers, true);
|
|
122
130
|
}
|
|
123
|
-
// if (value[key].$default) {
|
|
124
|
-
// }
|
|
125
131
|
if (!noCollect) {
|
|
126
132
|
handlers.collect({
|
|
127
133
|
path: newPath,
|
|
@@ -133,7 +139,8 @@ const text = async (path, value, fieldSchema, typeSchema, target, handlers, noCo
|
|
|
133
139
|
}
|
|
134
140
|
continue;
|
|
135
141
|
}
|
|
136
|
-
|
|
142
|
+
// if
|
|
143
|
+
// validate(newPath, value[key], fieldSchema)
|
|
137
144
|
if (!noCollect) {
|
|
138
145
|
handlers.collect({
|
|
139
146
|
path: newPath,
|
package/dist/set/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/set/string.ts"],"names":[],"mappings":";;;;;;AACA,mCAA2C;AAE3C,0DAAkC;
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/set/string.ts"],"names":[],"mappings":";;;;;;AACA,mCAA2C;AAE3C,0DAAkC;AAClC,iEAA6D;AAE7D,MAAM,cAAc,GAGhB;IACF,KAAK,EAAE,mBAAU,CAAC,OAAO;IACzB,GAAG,EAAE,mBAAU,CAAC,KAAK;IACrB,UAAU,EAAE,mBAAU,CAAC,YAAY;IACnC,EAAE,EAAE,mBAAU,CAAC,IAAI;IACnB,OAAO,EAAE,mBAAU,CAAC,SAAS;IAC7B,IAAI,EAAE,mBAAU,CAAC,MAAM;IACvB,IAAI,EAAE,mBAAU,CAAC,MAAM;IACvB,GAAG,EAAE,mBAAU,CAAC,KAAK;IACrB,KAAK,EAAE,mBAAU,CAAC,OAAO;IACzB,YAAY,EAAE,mBAAU,CAAC,cAAc;IACvC,YAAY,EAAE,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GAAG,CAAC;gBACjB,UAAU;gBACV,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;SACH;KACF;AACH,CAAC,CAAA;AApFY,QAAA,IAAI,QAoFhB"}
|
package/dist/set/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasedSchemaType, BasedSetHandlers, BasedSetTarget, BasedSchemaFields } from '../types';
|
|
2
|
-
export type Parser<K extends keyof BasedSchemaFields> = (path: (string | number)[], value: any, fieldSchema: BasedSchemaFields[K], typeSchema: BasedSchemaType, target: BasedSetTarget, handlers: BasedSetHandlers, noCollect?: boolean) => Promise<void>;
|
|
2
|
+
export type Parser<K extends keyof BasedSchemaFields> = (path: (string | number)[], value: any, fieldSchema: BasedSchemaFields[K], typeSchema: BasedSchemaType, target: BasedSetTarget, handlers: BasedSetHandlers, noCollect?: boolean) => Promise<void | boolean>;
|
|
3
3
|
export type Parsers = {
|
|
4
4
|
[Key in keyof BasedSchemaFields]: Parser<Key>;
|
|
5
5
|
};
|
package/package.json
CHANGED
package/src/set/collections.ts
CHANGED
|
@@ -40,7 +40,7 @@ export const set: Parser<'set'> = async (
|
|
|
40
40
|
for (let i = 0; i < value.$add.length; i++) {
|
|
41
41
|
q.push(
|
|
42
42
|
fieldWalker(
|
|
43
|
-
|
|
43
|
+
path,
|
|
44
44
|
value.$add[i],
|
|
45
45
|
fieldDef,
|
|
46
46
|
typeSchema,
|
|
@@ -55,7 +55,7 @@ export const set: Parser<'set'> = async (
|
|
|
55
55
|
for (let i = 0; i < value.$add.length; i++) {
|
|
56
56
|
q.push(
|
|
57
57
|
fieldWalker(
|
|
58
|
-
|
|
58
|
+
path,
|
|
59
59
|
value.$delete[i],
|
|
60
60
|
fieldDef,
|
|
61
61
|
typeSchema,
|
|
@@ -110,6 +110,7 @@ export const object: Parser<'object'> = async (
|
|
|
110
110
|
await Promise.all(q)
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// unshift // only allow 1 command
|
|
113
114
|
export const array: Parser<'array'> = async (
|
|
114
115
|
path,
|
|
115
116
|
value,
|
|
@@ -120,13 +121,16 @@ export const array: Parser<'array'> = async (
|
|
|
120
121
|
noCollect
|
|
121
122
|
) => {
|
|
122
123
|
const isArray = Array.isArray(value)
|
|
124
|
+
let parsedValue = value
|
|
125
|
+
let opCount = 0
|
|
123
126
|
if (typeof value === 'object' && !isArray) {
|
|
124
127
|
if (value.$insert) {
|
|
128
|
+
opCount++
|
|
125
129
|
if (
|
|
126
130
|
typeof value.$insert !== 'object' ||
|
|
127
131
|
value.$insert.$idx === undefined
|
|
128
132
|
) {
|
|
129
|
-
error(
|
|
133
|
+
error(path, ParseError.incorrectFormat)
|
|
130
134
|
} else {
|
|
131
135
|
const insert = Array.isArray(value.$insert.$value)
|
|
132
136
|
? value.$insert.$value
|
|
@@ -135,7 +139,7 @@ export const array: Parser<'array'> = async (
|
|
|
135
139
|
for (let i = 0; i < insert.length; i++) {
|
|
136
140
|
q.push(
|
|
137
141
|
fieldWalker(
|
|
138
|
-
|
|
142
|
+
path,
|
|
139
143
|
insert[i],
|
|
140
144
|
fieldSchema.values,
|
|
141
145
|
typeSchema,
|
|
@@ -148,16 +152,27 @@ export const array: Parser<'array'> = async (
|
|
|
148
152
|
await Promise.all(q)
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
|
-
if (value.$remove
|
|
152
|
-
|
|
155
|
+
if (value.$remove) {
|
|
156
|
+
opCount++
|
|
157
|
+
if (opCount > 1) {
|
|
158
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
159
|
+
}
|
|
160
|
+
if (value.$remove.$idx === undefined) {
|
|
161
|
+
error(path, ParseError.incorrectFormat)
|
|
162
|
+
}
|
|
153
163
|
}
|
|
154
164
|
if (value.$push) {
|
|
165
|
+
opCount++
|
|
166
|
+
if (opCount > 1) {
|
|
167
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
168
|
+
}
|
|
169
|
+
|
|
155
170
|
const q: Promise<void>[] = []
|
|
156
171
|
const push = Array.isArray(value.$push) ? value.$push : [value.$push]
|
|
157
172
|
for (let i = 0; i < push.length; i++) {
|
|
158
173
|
q.push(
|
|
159
174
|
fieldWalker(
|
|
160
|
-
|
|
175
|
+
path,
|
|
161
176
|
push[i],
|
|
162
177
|
fieldSchema.values,
|
|
163
178
|
typeSchema,
|
|
@@ -168,16 +183,48 @@ export const array: Parser<'array'> = async (
|
|
|
168
183
|
)
|
|
169
184
|
}
|
|
170
185
|
await Promise.all(q)
|
|
186
|
+
parsedValue = { $push: push }
|
|
187
|
+
}
|
|
188
|
+
if (value.$unshift) {
|
|
189
|
+
opCount++
|
|
190
|
+
if (opCount > 1) {
|
|
191
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const q: Promise<void>[] = []
|
|
195
|
+
const unshift = Array.isArray(value.$unshift)
|
|
196
|
+
? value.$unshift
|
|
197
|
+
: [value.$unshift]
|
|
198
|
+
for (let i = 0; i < unshift.length; i++) {
|
|
199
|
+
q.push(
|
|
200
|
+
fieldWalker(
|
|
201
|
+
path,
|
|
202
|
+
unshift[i],
|
|
203
|
+
fieldSchema.values,
|
|
204
|
+
typeSchema,
|
|
205
|
+
target,
|
|
206
|
+
handlers,
|
|
207
|
+
true
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
await Promise.all(q)
|
|
212
|
+
parsedValue = { $unshift: unshift }
|
|
171
213
|
}
|
|
172
214
|
if (value.$assign) {
|
|
215
|
+
opCount++
|
|
216
|
+
if (opCount > 1) {
|
|
217
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
218
|
+
}
|
|
219
|
+
|
|
173
220
|
if (
|
|
174
221
|
typeof value.$assign !== 'object' ||
|
|
175
222
|
value.$assign.$idx === undefined
|
|
176
223
|
) {
|
|
177
|
-
error(
|
|
224
|
+
error(path, ParseError.incorrectFormat)
|
|
178
225
|
} else {
|
|
179
226
|
await fieldWalker(
|
|
180
|
-
|
|
227
|
+
path,
|
|
181
228
|
value.$assign.$value,
|
|
182
229
|
fieldSchema.values,
|
|
183
230
|
typeSchema,
|
|
@@ -187,8 +234,15 @@ export const array: Parser<'array'> = async (
|
|
|
187
234
|
)
|
|
188
235
|
}
|
|
189
236
|
}
|
|
237
|
+
|
|
190
238
|
if (!noCollect) {
|
|
191
|
-
handlers.collect({
|
|
239
|
+
handlers.collect({
|
|
240
|
+
path,
|
|
241
|
+
value: parsedValue,
|
|
242
|
+
typeSchema,
|
|
243
|
+
fieldSchema,
|
|
244
|
+
target,
|
|
245
|
+
})
|
|
192
246
|
}
|
|
193
247
|
return
|
|
194
248
|
}
|
package/src/set/error.ts
CHANGED
package/src/set/number.ts
CHANGED
|
@@ -17,6 +17,17 @@ const validate = (
|
|
|
17
17
|
if (typeof value !== 'number') {
|
|
18
18
|
error(path, ParseError.incorrectFormat)
|
|
19
19
|
}
|
|
20
|
+
if (fieldSchema.type === 'integer' && value - Math.floor(value) !== 0) {
|
|
21
|
+
error(path, ParseError.incorrectFormat)
|
|
22
|
+
}
|
|
23
|
+
if (
|
|
24
|
+
fieldSchema.multipleOf &&
|
|
25
|
+
value / fieldSchema.multipleOf -
|
|
26
|
+
Math.floor(value / fieldSchema.multipleOf) !==
|
|
27
|
+
0
|
|
28
|
+
) {
|
|
29
|
+
error(path, ParseError.incorrectFormat)
|
|
30
|
+
}
|
|
20
31
|
if (fieldSchema.maximum) {
|
|
21
32
|
if (fieldSchema.exclusiveMaximum && value > value) {
|
|
22
33
|
error(path, ParseError.exceedsMaximum)
|
|
@@ -49,8 +60,14 @@ const shared = (
|
|
|
49
60
|
if (value.$decrement) {
|
|
50
61
|
validate([...path, '$decrement'], value.$decrement, fieldSchema)
|
|
51
62
|
}
|
|
52
|
-
if (value.$value) {
|
|
53
|
-
validate(
|
|
63
|
+
if (value.$value !== undefined) {
|
|
64
|
+
validate(path, value.$value, fieldSchema)
|
|
65
|
+
}
|
|
66
|
+
if (value.$default !== undefined) {
|
|
67
|
+
if (value.$value !== undefined) {
|
|
68
|
+
error(path, ParseError.valueAndDefault)
|
|
69
|
+
}
|
|
70
|
+
validate(path, value.$default, fieldSchema)
|
|
54
71
|
}
|
|
55
72
|
} else {
|
|
56
73
|
validate(path, value, fieldSchema)
|
|
@@ -74,7 +91,7 @@ export const timestamp: Parser<'timestamp'> = async (
|
|
|
74
91
|
const d = new Date(value)
|
|
75
92
|
value = d.valueOf()
|
|
76
93
|
if (isNaN(value)) {
|
|
77
|
-
|
|
94
|
+
error(path, ParseError.incorrectFormat)
|
|
78
95
|
}
|
|
79
96
|
}
|
|
80
97
|
}
|
|
@@ -120,9 +137,6 @@ export const integer: Parser<'integer'> = async (
|
|
|
120
137
|
handlers,
|
|
121
138
|
noCollect
|
|
122
139
|
) => {
|
|
123
|
-
if (typeof value === 'number' && value - Math.floor(value) !== 0) {
|
|
124
|
-
error(path, ParseError.incorrectFormat)
|
|
125
|
-
}
|
|
126
140
|
const parsedValue = shared(path, value, fieldSchema)
|
|
127
141
|
if (!noCollect) {
|
|
128
142
|
handlers.collect({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BasedSchemaFields } from '../types'
|
|
2
|
+
import { Parser } from './types'
|
|
3
|
+
import { error, ParseError } from './error'
|
|
4
|
+
import parsers from './parsers'
|
|
5
|
+
|
|
6
|
+
export const parseValueAndDefault: Parser<keyof BasedSchemaFields> = async (
|
|
7
|
+
path,
|
|
8
|
+
value,
|
|
9
|
+
fieldSchema,
|
|
10
|
+
typeSchema,
|
|
11
|
+
target,
|
|
12
|
+
handlers,
|
|
13
|
+
noCollect
|
|
14
|
+
): Promise<boolean> => {
|
|
15
|
+
let handled = false
|
|
16
|
+
if (typeof value === 'object') {
|
|
17
|
+
const typeDef = fieldSchema.type ?? ('enum' in fieldSchema ? 'enum' : '')
|
|
18
|
+
const parse = parsers[typeDef]
|
|
19
|
+
if (value.$value !== undefined) {
|
|
20
|
+
// TODO: for errors handle path a bit smarter...
|
|
21
|
+
parse(path, value.$value, fieldSchema, typeSchema, target, handlers, true)
|
|
22
|
+
handled = true
|
|
23
|
+
}
|
|
24
|
+
if (value.$default !== undefined) {
|
|
25
|
+
if (value.$value !== undefined) {
|
|
26
|
+
error(path, ParseError.valueAndDefault)
|
|
27
|
+
}
|
|
28
|
+
parse(
|
|
29
|
+
path,
|
|
30
|
+
value.$default,
|
|
31
|
+
fieldSchema,
|
|
32
|
+
typeSchema,
|
|
33
|
+
target,
|
|
34
|
+
handlers,
|
|
35
|
+
true
|
|
36
|
+
)
|
|
37
|
+
handled = true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (handled && !noCollect) {
|
|
41
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
42
|
+
}
|
|
43
|
+
return handled
|
|
44
|
+
}
|
package/src/set/rest.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Parser } from './types'
|
|
|
2
2
|
import { deepEqual } from '@saulx/utils'
|
|
3
3
|
import { hashObjectIgnoreKeyOrder, hash } from '@saulx/hash'
|
|
4
4
|
import { error, ParseError } from './error'
|
|
5
|
+
import { parseValueAndDefault } from './parseDefaultAndValue'
|
|
5
6
|
|
|
6
7
|
export const cardinality: Parser<'cardinality'> = async (
|
|
7
8
|
path,
|
|
@@ -9,14 +10,24 @@ export const cardinality: Parser<'cardinality'> = async (
|
|
|
9
10
|
fieldSchema,
|
|
10
11
|
typeSchema,
|
|
11
12
|
target,
|
|
12
|
-
handlers
|
|
13
|
+
handlers,
|
|
14
|
+
noCollect
|
|
13
15
|
) => {
|
|
14
16
|
if (value && typeof value === 'object') {
|
|
15
|
-
value
|
|
17
|
+
if (value.$default !== undefined) {
|
|
18
|
+
error(path, ParseError.defaultNotSupported)
|
|
19
|
+
}
|
|
20
|
+
if (value.$value !== undefined) {
|
|
21
|
+
value = hashObjectIgnoreKeyOrder(value.$value).toString(16)
|
|
22
|
+
} else {
|
|
23
|
+
value = hashObjectIgnoreKeyOrder(value).toString(16)
|
|
24
|
+
}
|
|
16
25
|
} else {
|
|
17
26
|
value = hash(value).toString(16)
|
|
18
27
|
}
|
|
19
|
-
|
|
28
|
+
if (!noCollect) {
|
|
29
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
30
|
+
}
|
|
20
31
|
}
|
|
21
32
|
|
|
22
33
|
export const boolean: Parser<'boolean'> = async (
|
|
@@ -28,9 +39,24 @@ export const boolean: Parser<'boolean'> = async (
|
|
|
28
39
|
handlers,
|
|
29
40
|
noCollect
|
|
30
41
|
) => {
|
|
42
|
+
if (
|
|
43
|
+
await parseValueAndDefault(
|
|
44
|
+
path,
|
|
45
|
+
value,
|
|
46
|
+
fieldSchema,
|
|
47
|
+
typeSchema,
|
|
48
|
+
target,
|
|
49
|
+
handlers,
|
|
50
|
+
noCollect
|
|
51
|
+
)
|
|
52
|
+
) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
31
56
|
if (typeof value !== 'boolean') {
|
|
32
57
|
error(path, ParseError.incorrectFormat)
|
|
33
58
|
}
|
|
59
|
+
|
|
34
60
|
if (!noCollect) {
|
|
35
61
|
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
36
62
|
}
|
|
@@ -46,15 +72,27 @@ export const enumParser: Parser<'enum'> = async (
|
|
|
46
72
|
noCollect
|
|
47
73
|
) => {
|
|
48
74
|
const enumValues = fieldSchema.enum
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
75
|
+
if (
|
|
76
|
+
!(await parseValueAndDefault(
|
|
77
|
+
path,
|
|
78
|
+
value,
|
|
79
|
+
fieldSchema,
|
|
80
|
+
typeSchema,
|
|
81
|
+
target,
|
|
82
|
+
handlers,
|
|
83
|
+
noCollect
|
|
84
|
+
))
|
|
85
|
+
) {
|
|
86
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
87
|
+
if (deepEqual(enumValues[i], value)) {
|
|
88
|
+
if (!noCollect) {
|
|
89
|
+
handlers.collect({ path, value: i, typeSchema, fieldSchema, target })
|
|
90
|
+
}
|
|
91
|
+
return
|
|
53
92
|
}
|
|
54
|
-
return
|
|
55
93
|
}
|
|
94
|
+
error(path, ParseError.incorrectFormat)
|
|
56
95
|
}
|
|
57
|
-
error(path, ParseError.incorrectFormat)
|
|
58
96
|
}
|
|
59
97
|
|
|
60
98
|
export const json: Parser<'json'> = async (
|
|
@@ -66,6 +104,20 @@ export const json: Parser<'json'> = async (
|
|
|
66
104
|
handlers,
|
|
67
105
|
noCollect
|
|
68
106
|
) => {
|
|
107
|
+
if (
|
|
108
|
+
await parseValueAndDefault(
|
|
109
|
+
path,
|
|
110
|
+
value,
|
|
111
|
+
fieldSchema,
|
|
112
|
+
typeSchema,
|
|
113
|
+
target,
|
|
114
|
+
handlers,
|
|
115
|
+
noCollect
|
|
116
|
+
)
|
|
117
|
+
) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
69
121
|
try {
|
|
70
122
|
const parsedValue = JSON.stringify(value)
|
|
71
123
|
if (!noCollect) {
|
|
@@ -78,6 +130,6 @@ export const json: Parser<'json'> = async (
|
|
|
78
130
|
})
|
|
79
131
|
}
|
|
80
132
|
} catch (err) {
|
|
81
|
-
|
|
133
|
+
error(path, ParseError.incorrectFormat)
|
|
82
134
|
}
|
|
83
135
|
}
|
package/src/set/string.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Parser } from './types'
|
|
|
2
2
|
import { error, ParseError } from './error'
|
|
3
3
|
import { BasedSchemaFieldString, BasedSchemaFieldText } from '../types'
|
|
4
4
|
import validators from 'validator'
|
|
5
|
+
import { parseValueAndDefault } from './parseDefaultAndValue'
|
|
5
6
|
|
|
6
7
|
const formatPatterns: Record<
|
|
7
8
|
BasedSchemaFieldString['format'],
|
|
@@ -104,6 +105,19 @@ export const string: Parser<'string'> = async (
|
|
|
104
105
|
handlers,
|
|
105
106
|
noCollect
|
|
106
107
|
) => {
|
|
108
|
+
if (
|
|
109
|
+
await parseValueAndDefault(
|
|
110
|
+
path,
|
|
111
|
+
value,
|
|
112
|
+
fieldSchema,
|
|
113
|
+
typeSchema,
|
|
114
|
+
target,
|
|
115
|
+
handlers,
|
|
116
|
+
noCollect
|
|
117
|
+
)
|
|
118
|
+
) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
107
121
|
validate(path, value, fieldSchema)
|
|
108
122
|
if (!noCollect) {
|
|
109
123
|
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
@@ -138,6 +152,21 @@ export const text: Parser<'text'> = async (
|
|
|
138
152
|
error(path, ParseError.incorrectFormat)
|
|
139
153
|
}
|
|
140
154
|
|
|
155
|
+
if (
|
|
156
|
+
target.$language &&
|
|
157
|
+
(await parseValueAndDefault(
|
|
158
|
+
path,
|
|
159
|
+
value,
|
|
160
|
+
fieldSchema,
|
|
161
|
+
typeSchema,
|
|
162
|
+
target,
|
|
163
|
+
handlers,
|
|
164
|
+
noCollect
|
|
165
|
+
))
|
|
166
|
+
) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
|
|
141
170
|
for (const key in value) {
|
|
142
171
|
const newPath = [...path, key]
|
|
143
172
|
|
|
@@ -153,10 +182,6 @@ export const text: Parser<'text'> = async (
|
|
|
153
182
|
true
|
|
154
183
|
)
|
|
155
184
|
}
|
|
156
|
-
|
|
157
|
-
// if (value[key].$default) {
|
|
158
|
-
// }
|
|
159
|
-
|
|
160
185
|
if (!noCollect) {
|
|
161
186
|
handlers.collect({
|
|
162
187
|
path: newPath,
|
|
@@ -169,7 +194,9 @@ export const text: Parser<'text'> = async (
|
|
|
169
194
|
continue
|
|
170
195
|
}
|
|
171
196
|
|
|
172
|
-
|
|
197
|
+
// if
|
|
198
|
+
|
|
199
|
+
// validate(newPath, value[key], fieldSchema)
|
|
173
200
|
|
|
174
201
|
if (!noCollect) {
|
|
175
202
|
handlers.collect({
|
package/src/set/types.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type Parser<K extends keyof BasedSchemaFields> = (
|
|
|
13
13
|
target: BasedSetTarget,
|
|
14
14
|
handlers: BasedSetHandlers,
|
|
15
15
|
noCollect?: boolean
|
|
16
|
-
) => Promise<void>
|
|
16
|
+
) => Promise<void | boolean>
|
|
17
17
|
|
|
18
18
|
export type Parsers = {
|
|
19
19
|
[Key in keyof BasedSchemaFields]: Parser<Key>
|
package/test/setWalker.ts
CHANGED
|
@@ -12,6 +12,9 @@ const schema: BasedSchema = {
|
|
|
12
12
|
blub: {
|
|
13
13
|
type: 'number',
|
|
14
14
|
},
|
|
15
|
+
flap: {
|
|
16
|
+
type: 'number',
|
|
17
|
+
},
|
|
15
18
|
snurp: {
|
|
16
19
|
type: 'array',
|
|
17
20
|
values: {
|
|
@@ -210,16 +213,16 @@ test.serial('collect correctly', async (t) => {
|
|
|
210
213
|
const result = [
|
|
211
214
|
{ path: ['visits'], value: '3a9009740ee' },
|
|
212
215
|
{ path: ['blub'], value: { $increment: 1 } },
|
|
213
|
-
{ path: ['bla'], value: false },
|
|
214
216
|
{ path: ['time'], value: now },
|
|
215
|
-
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
216
|
-
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
217
217
|
{ path: ['form', 'snurp'], value: 'blx12' },
|
|
218
|
-
{ path: ['form', 'things'], value: 2 },
|
|
219
|
-
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
220
218
|
{ path: ['snurp', 0, 'x', 0], value: 1 },
|
|
221
219
|
{ path: ['snurp', 0, 'x', 1], value: 2 },
|
|
222
220
|
{ path: ['snurp', 0, 'x', 2], value: 3 },
|
|
221
|
+
{ path: ['bla'], value: false },
|
|
222
|
+
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
223
|
+
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
224
|
+
{ path: ['form', 'things'], value: 2 },
|
|
225
|
+
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
223
226
|
{ path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
|
|
224
227
|
{ path: ['form', 'blab'], value: { $add: ['bl456'] } },
|
|
225
228
|
{
|
|
@@ -234,5 +237,83 @@ test.serial('collect correctly', async (t) => {
|
|
|
234
237
|
},
|
|
235
238
|
]
|
|
236
239
|
|
|
240
|
+
console.log(results)
|
|
241
|
+
|
|
237
242
|
t.deepEqual(results, result)
|
|
243
|
+
|
|
244
|
+
console.info('DID COMPARSION!')
|
|
245
|
+
|
|
246
|
+
const results2: any[] = []
|
|
247
|
+
await setWalker(
|
|
248
|
+
schema,
|
|
249
|
+
{
|
|
250
|
+
$id: 'bl1',
|
|
251
|
+
blub: {
|
|
252
|
+
$value: 4,
|
|
253
|
+
},
|
|
254
|
+
flap: {
|
|
255
|
+
$default: 1,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
260
|
+
console.dir(
|
|
261
|
+
{
|
|
262
|
+
path,
|
|
263
|
+
value,
|
|
264
|
+
},
|
|
265
|
+
{ depth: 10 }
|
|
266
|
+
)
|
|
267
|
+
results2.push({
|
|
268
|
+
path,
|
|
269
|
+
value,
|
|
270
|
+
})
|
|
271
|
+
},
|
|
272
|
+
referenceFilterCondition: async (id, filter) => {
|
|
273
|
+
return true
|
|
274
|
+
},
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
t.deepEqual(results2, [
|
|
279
|
+
{ path: ['blub'], value: { $value: 4 } },
|
|
280
|
+
{ path: ['flap'], value: { $default: 1 } },
|
|
281
|
+
])
|
|
282
|
+
|
|
283
|
+
const results3: any[] = []
|
|
284
|
+
await setWalker(
|
|
285
|
+
schema,
|
|
286
|
+
{
|
|
287
|
+
$id: 'bl1',
|
|
288
|
+
snurpArray: {
|
|
289
|
+
$push: 1,
|
|
290
|
+
},
|
|
291
|
+
specialArray: {
|
|
292
|
+
$push: { $value: 'flap' },
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
297
|
+
console.dir(
|
|
298
|
+
{
|
|
299
|
+
path,
|
|
300
|
+
value,
|
|
301
|
+
},
|
|
302
|
+
{ depth: 10 }
|
|
303
|
+
)
|
|
304
|
+
results3.push({
|
|
305
|
+
path,
|
|
306
|
+
value,
|
|
307
|
+
})
|
|
308
|
+
},
|
|
309
|
+
referenceFilterCondition: async (id, filter) => {
|
|
310
|
+
return true
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
t.deepEqual(results3, [
|
|
316
|
+
{ path: ['snurpArray'], value: { $push: [1] } },
|
|
317
|
+
{ path: ['specialArray'], value: { $push: [{ $value: 'flap' }] } },
|
|
318
|
+
])
|
|
238
319
|
})
|