@based/schema 0.0.15 → 1.0.1
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/error.d.ts → error.d.ts} +4 -2
- package/dist/{set/error.js → error.js} +2 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/set/fields/array.d.ts +2 -0
- package/dist/set/fields/array.js +96 -0
- package/dist/set/fields/array.js.map +1 -0
- package/dist/set/fields/index.d.ts +3 -0
- package/dist/set/fields/index.js +72 -0
- package/dist/set/fields/index.js.map +1 -0
- package/dist/set/fields/number.d.ts +4 -0
- package/dist/set/fields/number.js +121 -0
- package/dist/set/fields/number.js.map +1 -0
- package/dist/set/fields/object.d.ts +3 -0
- package/dist/set/fields/object.js +33 -0
- package/dist/set/fields/object.js.map +1 -0
- package/dist/set/fields/references.d.ts +3 -0
- package/dist/set/fields/references.js +106 -0
- package/dist/set/fields/references.js.map +1 -0
- package/dist/set/fields/set.d.ts +2 -0
- package/dist/set/fields/set.js +63 -0
- package/dist/set/fields/set.js.map +1 -0
- package/dist/set/fields/string.d.ts +3 -0
- package/dist/set/fields/string.js +190 -0
- package/dist/set/fields/string.js.map +1 -0
- package/dist/set/index.d.ts +2 -5
- package/dist/set/index.js +98 -126
- package/dist/set/index.js.map +1 -1
- package/dist/set/isValidId.d.ts +2 -0
- package/dist/set/isValidId.js +21 -0
- package/dist/set/isValidId.js.map +1 -0
- package/dist/set/types.d.ts +0 -5
- package/dist/set/types.js +0 -2
- package/dist/types.d.ts +7 -1
- package/dist/types.js.map +1 -1
- package/dist/walker/args.d.ts +31 -0
- package/dist/walker/args.js +120 -0
- package/dist/walker/args.js.map +1 -0
- package/dist/walker/index.d.ts +6 -0
- package/dist/walker/index.js +40 -0
- package/dist/walker/index.js.map +1 -0
- package/dist/walker/parse.d.ts +2 -0
- package/dist/walker/parse.js +157 -0
- package/dist/walker/parse.js.map +1 -0
- package/dist/walker/types.d.ts +44 -0
- package/dist/walker/types.js +9 -0
- package/dist/walker/types.js.map +1 -0
- package/package.json +2 -2
- package/src/{set/error.ts → error.ts} +3 -1
- package/src/index.ts +2 -2
- package/src/set/fields/array.ts +111 -0
- package/src/set/fields/index.ts +69 -0
- package/src/set/fields/number.ts +134 -0
- package/src/set/fields/object.ts +30 -0
- package/src/set/fields/references.ts +114 -0
- package/src/set/fields/set.ts +63 -0
- package/src/set/fields/string.ts +199 -0
- package/src/set/index.ts +103 -188
- package/src/set/isValidId.ts +23 -0
- package/src/set/types.ts +0 -20
- package/src/types.ts +4 -2
- package/src/walker/args.ts +159 -0
- package/src/walker/index.ts +35 -0
- package/src/walker/parse.ts +193 -0
- package/src/walker/types.ts +75 -0
- package/test/number.ts +289 -543
- package/test/reference.ts +150 -198
- package/test/rest.ts +227 -0
- package/test/string.ts +139 -183
- package/test/utils/index.ts +23 -0
- package/test/walker.ts +579 -16
- package/dist/set/collections.d.ts +0 -5
- package/dist/set/collections.js +0 -229
- package/dist/set/collections.js.map +0 -1
- package/dist/set/error.js.map +0 -1
- package/dist/set/number.d.ts +0 -4
- package/dist/set/number.js +0 -124
- package/dist/set/number.js.map +0 -1
- package/dist/set/parseDefaultAndValue.d.ts +0 -3
- package/dist/set/parseDefaultAndValue.js +0 -35
- package/dist/set/parseDefaultAndValue.js.map +0 -1
- package/dist/set/parsers.d.ts +0 -3
- package/dist/set/parsers.js +0 -42
- package/dist/set/parsers.js.map +0 -1
- package/dist/set/references.d.ts +0 -3
- package/dist/set/references.js +0 -84
- package/dist/set/references.js.map +0 -1
- package/dist/set/rest.d.ts +0 -5
- package/dist/set/rest.js +0 -76
- package/dist/set/rest.js.map +0 -1
- package/dist/set/string.d.ts +0 -3
- package/dist/set/string.js +0 -173
- package/dist/set/string.js.map +0 -1
- package/dist/set2/index.d.ts +0 -0
- package/dist/set2/index.js +0 -71
- package/dist/set2/index.js.map +0 -1
- package/dist/walker.d.ts +0 -49
- package/dist/walker.js +0 -120
- package/dist/walker.js.map +0 -1
- package/src/set/collections.ts +0 -338
- package/src/set/number.ts +0 -167
- package/src/set/parseDefaultAndValue.ts +0 -54
- package/src/set/parsers.ts +0 -20
- package/src/set/references.ts +0 -113
- package/src/set/rest.ts +0 -135
- package/src/set/string.ts +0 -254
- package/src/set2/index.ts +0 -71
- package/src/walker.ts +0 -191
- package/test/setWalker.ts +0 -494
- package/test/text.ts +0 -171
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasedSetHandlers } from '
|
|
1
|
+
import { BasedSetHandlers } from './types';
|
|
2
2
|
export declare enum ParseError {
|
|
3
3
|
'incorrectFieldType' = 0,
|
|
4
4
|
'incorrectNodeType' = 1,
|
|
@@ -11,6 +11,8 @@ export declare enum ParseError {
|
|
|
11
11
|
'defaultNotSupported' = 8,
|
|
12
12
|
'multipleOperationsNotAllowed' = 9,
|
|
13
13
|
'requiredFieldNotDefined' = 10,
|
|
14
|
-
'languageNotSupported' = 11
|
|
14
|
+
'languageNotSupported' = 11,
|
|
15
|
+
'invalidJSON' = 12,
|
|
16
|
+
'noLanguageFound' = 13
|
|
15
17
|
}
|
|
16
18
|
export declare const error: (handlers: BasedSetHandlers, error: ParseError, path?: (number | string)[]) => void;
|
|
@@ -15,6 +15,8 @@ var ParseError;
|
|
|
15
15
|
ParseError[ParseError["multipleOperationsNotAllowed"] = 9] = "multipleOperationsNotAllowed";
|
|
16
16
|
ParseError[ParseError["requiredFieldNotDefined"] = 10] = "requiredFieldNotDefined";
|
|
17
17
|
ParseError[ParseError["languageNotSupported"] = 11] = "languageNotSupported";
|
|
18
|
+
ParseError[ParseError["invalidJSON"] = 12] = "invalidJSON";
|
|
19
|
+
ParseError[ParseError["noLanguageFound"] = 13] = "noLanguageFound";
|
|
18
20
|
})(ParseError = exports.ParseError || (exports.ParseError = {}));
|
|
19
21
|
const error = (handlers, error, path) => {
|
|
20
22
|
const message = path
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,IAAY,UAeX;AAfD,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;IAC9B,kFAAyB,CAAA;IACzB,4EAAsB,CAAA;IACtB,0DAAa,CAAA;IACb,kEAAiB,CAAA;AACnB,CAAC,EAfW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAerB;AAEM,MAAM,KAAK,GAAG,CACnB,QAA0B,EAC1B,KAAiB,EACjB,IAA0B,EAC1B,EAAE;IACF,MAAM,OAAO,GAAG,IAAI;QAClB,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC1C,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAA;IAE1B,QAAQ,CAAC,aAAa,CAAC;QACrB,OAAO;QACP,IAAI,EAAE,KAAK;KACZ,CAAC,CAAA;AACJ,CAAC,CAAA;AAbY,QAAA,KAAK,SAajB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./validateSchema"), exports);
|
|
19
|
-
__exportStar(require("./set"), exports);
|
|
20
19
|
__exportStar(require("./walker"), exports);
|
|
20
|
+
__exportStar(require("./set"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,mDAAgC;AAEhC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,mDAAgC;AAEhC,2CAAwB;AAExB,wCAAqB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.array = void 0;
|
|
4
|
+
const utils_1 = require("@saulx/utils");
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
const parseArray = async (args, value) => {
|
|
7
|
+
const fromValue = Array.isArray(value) ? value : [value];
|
|
8
|
+
const q = [];
|
|
9
|
+
const arr = new Array(fromValue.length);
|
|
10
|
+
for (let i = 0; i < fromValue.length; i++) {
|
|
11
|
+
q.push(args.parse({
|
|
12
|
+
path: [i],
|
|
13
|
+
value: fromValue[i],
|
|
14
|
+
fieldSchema: args.fieldSchema.values,
|
|
15
|
+
collect: (args, v) => {
|
|
16
|
+
(0, utils_1.setByPath)(arr, args.path, v);
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
await Promise.all(q);
|
|
21
|
+
return arr;
|
|
22
|
+
};
|
|
23
|
+
const operations = {
|
|
24
|
+
$insert: async (args, value) => {
|
|
25
|
+
if (typeof value.$insert !== 'object' ||
|
|
26
|
+
typeof value.$insert.$idx !== 'number') {
|
|
27
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
value.$insert.$value = await parseArray(args, value.$insert.$value);
|
|
31
|
+
args.collect(value);
|
|
32
|
+
},
|
|
33
|
+
$push: async (args, value) => {
|
|
34
|
+
value.$push = await parseArray(args, value.$push);
|
|
35
|
+
args.collect(value);
|
|
36
|
+
},
|
|
37
|
+
$unshift: async (args, value) => {
|
|
38
|
+
value.$unshift = await parseArray(args, value.$push);
|
|
39
|
+
args.collect(value);
|
|
40
|
+
},
|
|
41
|
+
$remove: async (args, value) => {
|
|
42
|
+
if (typeof value.$remove.$idx !== 'number') {
|
|
43
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
args.collect(value);
|
|
47
|
+
},
|
|
48
|
+
$assign: async (args, value) => {
|
|
49
|
+
if (typeof value.$assign !== 'object' ||
|
|
50
|
+
typeof value.$assign.$idx !== 'number') {
|
|
51
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await args.parse({
|
|
55
|
+
key: value.$assign.$idx,
|
|
56
|
+
value: args.fieldSchema.values,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const array = async (args) => {
|
|
61
|
+
args.stop();
|
|
62
|
+
if (typeof args.value !== 'object') {
|
|
63
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let value = '$value' in args.value ? args.value.$value : args.value;
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
const q = [];
|
|
69
|
+
args.collect({ $delete: true });
|
|
70
|
+
for (let i = 0; i < value.length; i++) {
|
|
71
|
+
q.push(args.parse({
|
|
72
|
+
key: i,
|
|
73
|
+
value: args.value[i],
|
|
74
|
+
fieldSchema: args.fieldSchema.values,
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
await Promise.all(q);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let hasOperation = false;
|
|
81
|
+
for (const key in value) {
|
|
82
|
+
if (operations[key]) {
|
|
83
|
+
if (hasOperation) {
|
|
84
|
+
args.error(error_1.ParseError.multipleOperationsNotAllowed);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
await operations[key](args, value);
|
|
88
|
+
hasOperation = true;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
args.error(error_1.ParseError.fieldDoesNotExist);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.array = array;
|
|
96
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/set/fields/array.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;AACxC,uCAAwC;AAIxC,MAAM,UAAU,GAAG,KAAK,EACtB,IAAwC,EACxC,KAAU,EACM,EAAE;IAClB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACxD,MAAM,CAAC,GAAmB,EAAE,CAAA;IAC5B,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzC,CAAC,CAAC,IAAI,CACJ,IAAI,CAAC,KAAK,CAAC;YACT,IAAI,EAAE,CAAC,CAAC,CAAC;YACT,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;YACnB,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM;YACpC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;gBACnB,IAAA,iBAAS,EAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;YAC9B,CAAC;SACF,CAAC,CACH,CAAA;KACF;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACpB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,UAAU,GAKZ;IACF,OAAO,EAAE,KAAK,EAAE,IAAI,EAA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KAAK,EAAE;QACvB,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE;YACnB,IAAI,YAAY,EAAE;gBAChB,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,4BAA4B,CAAC,CAAA;gBACnD,OAAM;aACP;YACD,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAClC,YAAY,GAAG,IAAI,CAAA;SACpB;aAAM;YACL,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,iBAAiB,CAAC,CAAA;SACzC;KACF;AACH,CAAC,CAAA;AAnCY,QAAA,KAAK,SAmCjB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fields = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
const array_1 = require("./array");
|
|
6
|
+
const object_1 = require("./object");
|
|
7
|
+
const number_1 = require("./number");
|
|
8
|
+
const string_1 = require("./string");
|
|
9
|
+
const references_1 = require("./references");
|
|
10
|
+
const set_1 = require("./set");
|
|
11
|
+
const hash_1 = require("@saulx/hash");
|
|
12
|
+
const utils_1 = require("@saulx/utils");
|
|
13
|
+
exports.fields = {
|
|
14
|
+
array: array_1.array,
|
|
15
|
+
object: object_1.object,
|
|
16
|
+
record: object_1.record,
|
|
17
|
+
number: number_1.number,
|
|
18
|
+
integer: number_1.integer,
|
|
19
|
+
timestamp: number_1.timestamp,
|
|
20
|
+
string: string_1.string,
|
|
21
|
+
set: set_1.set,
|
|
22
|
+
text: string_1.text,
|
|
23
|
+
reference: references_1.reference,
|
|
24
|
+
references: references_1.references,
|
|
25
|
+
cardinality: async (args) => {
|
|
26
|
+
let hashedValue;
|
|
27
|
+
if (args.value && typeof args.value === 'object') {
|
|
28
|
+
args.stop();
|
|
29
|
+
if (args.value.$default !== undefined) {
|
|
30
|
+
args.error(error_1.ParseError.defaultNotSupported);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (args.value.$value !== undefined) {
|
|
34
|
+
hashedValue = (0, hash_1.hashObjectIgnoreKeyOrder)(args.value.$value).toString(16);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
hashedValue = (0, hash_1.hashObjectIgnoreKeyOrder)(args.value).toString(16);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
hashedValue = (0, hash_1.hash)(args.value).toString(16);
|
|
42
|
+
}
|
|
43
|
+
args.collect(hashedValue);
|
|
44
|
+
},
|
|
45
|
+
boolean: async (args) => {
|
|
46
|
+
if (typeof args.value !== 'boolean') {
|
|
47
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
args.collect();
|
|
51
|
+
},
|
|
52
|
+
json: async (args) => {
|
|
53
|
+
try {
|
|
54
|
+
const parsedValue = JSON.stringify(args.value);
|
|
55
|
+
args.collect(parsedValue);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
args.error(error_1.ParseError.invalidJSON);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
enum: async (args) => {
|
|
62
|
+
const enumValues = args.fieldSchema.enum;
|
|
63
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
64
|
+
if ((0, utils_1.deepEqual)(enumValues[i], args.value)) {
|
|
65
|
+
args.collect(i);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/set/fields/index.ts"],"names":[],"mappings":";;;AACA,uCAAwC;AAExC,mCAA+B;AAC/B,qCAAyC;AACzC,qCAAqD;AACrD,qCAAuC;AACvC,6CAAoD;AACpD,+BAA2B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CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;YACtC,OAAM;SACP;QACD,IAAI,CAAC,OAAO,EAAE,CAAA;IAChB,CAAC;IAED,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACnB,IAAI;YACF,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC9C,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,WAAW,CAAC,CAAA;SACnC;IACH,CAAC;IACD,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,IAAI,IAAA,iBAAS,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;gBACxC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;gBACf,OAAM;aACP;SACF;QACD,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;IACxC,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timestamp = exports.integer = exports.number = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
const validateNumber = (args, value, ignoreMinMax) => {
|
|
6
|
+
const { fieldSchema } = args;
|
|
7
|
+
if (typeof value !== 'number') {
|
|
8
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (fieldSchema.type === 'integer' && value - Math.floor(value) !== 0) {
|
|
12
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (fieldSchema.multipleOf &&
|
|
16
|
+
value / fieldSchema.multipleOf -
|
|
17
|
+
Math.floor(value / fieldSchema.multipleOf) !==
|
|
18
|
+
0) {
|
|
19
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (ignoreMinMax) {
|
|
23
|
+
// TODO: maybe add async validator getting the actual value from the db OR checking the result of the $incr/$decr operation
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (fieldSchema.maximum) {
|
|
27
|
+
if (fieldSchema.exclusiveMaximum) {
|
|
28
|
+
if (value >= fieldSchema.maximum) {
|
|
29
|
+
args.error(error_1.ParseError.exceedsMaximum);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (value > fieldSchema.maximum) {
|
|
34
|
+
args.error(error_1.ParseError.exceedsMaximum);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (fieldSchema.minimum) {
|
|
39
|
+
if (fieldSchema.exclusiveMinimum) {
|
|
40
|
+
if (value <= fieldSchema.minimum) {
|
|
41
|
+
args.error(error_1.ParseError.subceedsMinimum);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (value < fieldSchema.minimum) {
|
|
46
|
+
args.error(error_1.ParseError.subceedsMinimum);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
const validate = (args, value) => {
|
|
53
|
+
if (value === null) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value !== 'object') {
|
|
57
|
+
return validateNumber(args, value);
|
|
58
|
+
}
|
|
59
|
+
if ('$value' in value) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
args.stop();
|
|
63
|
+
for (const key in value) {
|
|
64
|
+
if (key === '$default') {
|
|
65
|
+
if (!validateNumber(args, value.$default)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (key === '$increment') {
|
|
70
|
+
if (!validateNumber(args, value.$increment, true)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (key === '$decrement') {
|
|
75
|
+
if (!validateNumber(args, value.$decrement, true)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
args.create({ key }).error(error_1.ParseError.fieldDoesNotExist);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
const number = async (args) => {
|
|
87
|
+
if (!validate(args, args.value)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
args.collect();
|
|
91
|
+
};
|
|
92
|
+
exports.number = number;
|
|
93
|
+
const integer = async (args) => {
|
|
94
|
+
if (!validate(args, args.value)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
args.collect();
|
|
98
|
+
};
|
|
99
|
+
exports.integer = integer;
|
|
100
|
+
const timestamp = async (args) => {
|
|
101
|
+
if (typeof args.value === 'string') {
|
|
102
|
+
if (args.value === 'now') {
|
|
103
|
+
// TODO: + 1s + 10s etc
|
|
104
|
+
args.value = Date.now();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const d = new Date(args.value);
|
|
108
|
+
args.value = d.valueOf();
|
|
109
|
+
if (isNaN(args.value)) {
|
|
110
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!validateNumber(args, args.value)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
args.collect();
|
|
119
|
+
};
|
|
120
|
+
exports.timestamp = timestamp;
|
|
121
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/set/fields/number.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAMxC,MAAM,cAAc,GAAG,CACrB,IAA4C,EAC5C,KAAa,EACb,YAAsB,EACb,EAAE;IACX,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAO,KAAK,CAAA;KACb;IAED,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACrE,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAO,KAAK,CAAA;KACb;IAED,IACE,WAAW,CAAC,UAAU;QACtB,KAAK,GAAG,WAAW,CAAC,UAAU;YAC5B,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC;YAC1C,CAAC,EACH;QACA,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAO,KAAK,CAAA;KACb;IAED,IAAI,YAAY,EAAE;QAChB,2HAA2H;QAC3H,OAAO,IAAI,CAAA;KACZ;IAED,IAAI,WAAW,CAAC,OAAO,EAAE;QACvB,IAAI,WAAW,CAAC,gBAAgB,EAAE;YAChC,IAAI,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE;gBAChC,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,cAAc,CAAC,CAAA;gBACrC,OAAO,KAAK,CAAA;aACb;SACF;aAAM,IAAI,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE;YACtC,IAAI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I,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;QACrC,OAAM;KACP;IACD,IAAI,CAAC,OAAO,EAAE,CAAA;AAChB,CAAC,CAAA;AAlBY,QAAA,SAAS,aAkBrB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.record = exports.object = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
const object = async (args) => {
|
|
6
|
+
if (typeof args.value !== 'object') {
|
|
7
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const isArray = Array.isArray(args.value);
|
|
11
|
+
if (isArray) {
|
|
12
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
args.collect();
|
|
16
|
+
return args;
|
|
17
|
+
};
|
|
18
|
+
exports.object = object;
|
|
19
|
+
const record = async (args) => {
|
|
20
|
+
if (typeof args.value !== 'object') {
|
|
21
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const isArray = Array.isArray(args.value);
|
|
25
|
+
if (isArray) {
|
|
26
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
args.collect();
|
|
30
|
+
return args;
|
|
31
|
+
};
|
|
32
|
+
exports.record = record;
|
|
33
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/set/fields/object.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAGjC,MAAM,MAAM,GAA0B,KAAK,EAAE,IAAI,EAAE,EAAE;IAC1D,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;QAClC,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAM;KACP;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,OAAO,EAAE;QACX,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAM;KACP;IACD,IAAI,CAAC,OAAO,EAAE,CAAA;IACd,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAZY,QAAA,MAAM,UAYlB;AAEM,MAAM,MAAM,GAA0B,KAAK,EAAE,IAAI,EAAE,EAAE;IAC1D,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;QAClC,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAM;KACP;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,OAAO,EAAE;QACX,IAAI,CAAC,KAAK,CAAC,kBAAU,CAAC,eAAe,CAAC,CAAA;QACtC,OAAM;KACP;IACD,IAAI,CAAC,OAAO,EAAE,CAAA;IACd,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAZY,QAAA,MAAM,UAYlB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 isValidId_1 = require("../isValidId");
|
|
6
|
+
async function parseOperator(args, key) {
|
|
7
|
+
if (Array.isArray(args.value[key])) {
|
|
8
|
+
const n = args.create({
|
|
9
|
+
key,
|
|
10
|
+
skipCollection: true,
|
|
11
|
+
value: args.value[key],
|
|
12
|
+
});
|
|
13
|
+
await n.parse();
|
|
14
|
+
if (n.value?.$value) {
|
|
15
|
+
return n.value.$value;
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const n = args.create({
|
|
20
|
+
value: args.value[key],
|
|
21
|
+
key,
|
|
22
|
+
skipCollection: true,
|
|
23
|
+
});
|
|
24
|
+
await (0, exports.reference)(n);
|
|
25
|
+
return [n.value];
|
|
26
|
+
}
|
|
27
|
+
const reference = async (args) => {
|
|
28
|
+
// TODO: setting an object here , handling $alias (both async hooks)
|
|
29
|
+
// block if path contains $remove
|
|
30
|
+
if (!(0, isValidId_1.isValidId)(args.schema, args.value)) {
|
|
31
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if ('allowedTypes' in args.fieldSchema) {
|
|
35
|
+
const prefix = args.value.slice(0, 2);
|
|
36
|
+
const targetType = args.schema.prefixToTypeMapping[prefix];
|
|
37
|
+
let typeMatches = false;
|
|
38
|
+
for (const t of args.fieldSchema.allowedTypes) {
|
|
39
|
+
if (typeof t === 'string') {
|
|
40
|
+
if (t === targetType) {
|
|
41
|
+
typeMatches = true;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (t.type && t.type === targetType) {
|
|
47
|
+
typeMatches = true;
|
|
48
|
+
if (t.$filter) {
|
|
49
|
+
// TODO: ASYNC HOOK
|
|
50
|
+
// if(!(await args.target.referenceFilterCondition(value, t.$filter))){
|
|
51
|
+
// error(args, ParseError.referenceIsIncorrectType)
|
|
52
|
+
// return
|
|
53
|
+
// }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (!t.type && t.$filter) {
|
|
57
|
+
// if(!(await args.target.referenceFilterCondition))
|
|
58
|
+
// error(args, ParseError.referenceIsIncorrectType, )
|
|
59
|
+
// return
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (typeMatches === false) {
|
|
64
|
+
args.error(error_1.ParseError.referenceIsIncorrectType);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
args.collect();
|
|
69
|
+
};
|
|
70
|
+
exports.reference = reference;
|
|
71
|
+
const references = async (args) => {
|
|
72
|
+
const { value } = args;
|
|
73
|
+
if (typeof value !== 'object' || value === null) {
|
|
74
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
args.stop();
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
const parseValues = await Promise.all(value.map(async (id, key) => {
|
|
80
|
+
const n = args.create({
|
|
81
|
+
value: id,
|
|
82
|
+
key,
|
|
83
|
+
skipCollection: true,
|
|
84
|
+
});
|
|
85
|
+
await (0, exports.reference)(n);
|
|
86
|
+
return n.value;
|
|
87
|
+
}));
|
|
88
|
+
args.value = { $value: parseValues };
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for (const key in args.value) {
|
|
92
|
+
if (key === '$add') {
|
|
93
|
+
args.value.$add = await parseOperator(args, key);
|
|
94
|
+
}
|
|
95
|
+
else if (key === '$remove') {
|
|
96
|
+
args.value.$remove = await parseOperator(args, key);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
args.create({ key }).error(error_1.ParseError.fieldDoesNotExist);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
args.collect();
|
|
104
|
+
};
|
|
105
|
+
exports.references = references;
|
|
106
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.js","sourceRoot":"","sources":["../../../src/set/fields/references.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAGxC,4CAAwC;AAExC,KAAK,UAAU,aAAa,CAC1B,IAAgC,EAChC,GAAW;IAEX,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;QAClC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;YACpB,GAAG;YAC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AAC,KAAK,CAAA;QAChB,CAAC,CAAC,CACH,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;KACrC;SAAM;QACL,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;YAC5B,IAAI,GAAG,KAAK,MAAM,EAAE;gBAClB,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;aACjD;iBAAM,IAAI,GAAG,KAAK,SAAS,EAAE;gBAC5B,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;aACpD;iBAAM;gBACL,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAU,CAAC,iBAAiB,CAAC,CAAA;aACzD;SACF;KACF;IAED,IAAI,CAAC,OAAO,EAAE,CAAA;AAChB,CAAC,CAAA;AApCY,QAAA,UAAU,cAoCtB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.set = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
async function parseOperator(args, key) {
|
|
6
|
+
if (Array.isArray(args.value[key])) {
|
|
7
|
+
const n = args.create({
|
|
8
|
+
key,
|
|
9
|
+
skipCollection: true,
|
|
10
|
+
value: args.value[key],
|
|
11
|
+
});
|
|
12
|
+
await n.parse();
|
|
13
|
+
if (n.value?.$value) {
|
|
14
|
+
return n.value.$value;
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const n = args.create({
|
|
19
|
+
key,
|
|
20
|
+
skipCollection: true,
|
|
21
|
+
value: args.value[key],
|
|
22
|
+
fieldSchema: args.fieldSchema.items,
|
|
23
|
+
});
|
|
24
|
+
await n.parse();
|
|
25
|
+
return [n.value];
|
|
26
|
+
}
|
|
27
|
+
const set = async (args) => {
|
|
28
|
+
if (typeof args.value !== 'object' || args.value === null) {
|
|
29
|
+
args.error(error_1.ParseError.incorrectFormat);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
args.stop();
|
|
33
|
+
const isArray = Array.isArray(args.value);
|
|
34
|
+
if (isArray) {
|
|
35
|
+
const newArgs = [];
|
|
36
|
+
for (let i = 0; i < args.value.length; i++) {
|
|
37
|
+
newArgs.push(args.create({
|
|
38
|
+
key: i,
|
|
39
|
+
value: args.value[i],
|
|
40
|
+
fieldSchema: args.fieldSchema.items,
|
|
41
|
+
skipCollection: true,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
await Promise.all(newArgs.map((args) => args.parse()));
|
|
45
|
+
args.value = { $value: newArgs.map((args) => args.value) };
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (const key in args.value) {
|
|
49
|
+
if (key === '$add') {
|
|
50
|
+
args.value.$add = await parseOperator(args, key);
|
|
51
|
+
}
|
|
52
|
+
else if (key === '$remove') {
|
|
53
|
+
args.value.$remove = await parseOperator(args, key);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
args.create({ key }).error(error_1.ParseError.fieldDoesNotExist);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
args.collect();
|
|
61
|
+
};
|
|
62
|
+
exports.set = set;
|
|
63
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.js","sourceRoot":"","sources":["../../../src/set/fields/set.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAGxC,KAAK,UAAU,aAAa,CAC1B,IAAyB,EACzB,GAAW;IAEX,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;QAClC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC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