@based/schema 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/compat/index.js +8 -2
- package/dist/src/compat/newToOld.d.ts +2 -2
- package/dist/src/compat/newToOld.js +31 -173
- package/dist/src/compat/oldToNew.d.ts +1 -1
- package/dist/src/compat/oldToNew.js +25 -200
- package/dist/src/set/fields/string.js +1 -0
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -0
- package/dist/test/compat.js +21 -0
- package/package.json +1 -1
- package/dist/display/index.d.ts +0 -2
- package/dist/display/index.js +0 -26
- package/dist/display/number.d.ts +0 -3
- package/dist/display/number.js +0 -89
- package/dist/display/string.d.ts +0 -3
- package/dist/display/string.js +0 -23
- package/dist/display/timestamp.d.ts +0 -3
- package/dist/display/timestamp.js +0 -127
- package/dist/error.d.ts +0 -19
- package/dist/error.js +0 -24
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -22
- package/dist/languages.d.ts +0 -187
- package/dist/languages.js +0 -190
- package/dist/set/fields/array.d.ts +0 -2
- package/dist/set/fields/array.js +0 -123
- package/dist/set/fields/index.d.ts +0 -3
- package/dist/set/fields/index.js +0 -74
- package/dist/set/fields/number.d.ts +0 -4
- package/dist/set/fields/number.js +0 -129
- package/dist/set/fields/object.d.ts +0 -3
- package/dist/set/fields/object.js +0 -33
- package/dist/set/fields/references.d.ts +0 -3
- package/dist/set/fields/references.js +0 -128
- package/dist/set/fields/set.d.ts +0 -2
- package/dist/set/fields/set.js +0 -63
- package/dist/set/fields/string.d.ts +0 -3
- package/dist/set/fields/string.js +0 -284
- package/dist/set/index.d.ts +0 -3
- package/dist/set/index.js +0 -183
- package/dist/set/isValidId.d.ts +0 -2
- package/dist/set/isValidId.js +0 -21
- package/dist/set/types.d.ts +0 -0
- package/dist/set/types.js +0 -1
- package/dist/types.d.ts +0 -205
- package/dist/types.js +0 -27
- package/dist/updateSchema.d.ts +0 -2
- package/dist/updateSchema.js +0 -16
- package/dist/validateSchema.d.ts +0 -4
- package/dist/validateSchema.js +0 -41
- package/dist/walker/args.d.ts +0 -36
- package/dist/walker/args.js +0 -162
- package/dist/walker/index.d.ts +0 -6
- package/dist/walker/index.js +0 -49
- package/dist/walker/parse.d.ts +0 -3
- package/dist/walker/parse.js +0 -186
- package/dist/walker/types.d.ts +0 -45
- package/dist/walker/types.js +0 -10
package/dist/set/fields/array.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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 collectOperation = (fromArgs, collected, value, makeNegative) => {
|
|
7
|
-
fromArgs.collect(value);
|
|
8
|
-
if (collected.length) {
|
|
9
|
-
const collect = fromArgs.root._opts.collect;
|
|
10
|
-
for (const args of collected) {
|
|
11
|
-
if (makeNegative) {
|
|
12
|
-
args.path[fromArgs.path.length] =
|
|
13
|
-
args.path[fromArgs.path.length] - makeNegative;
|
|
14
|
-
collect(args);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
collect(args);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const parseArray = async (args, value, idx = 0) => {
|
|
23
|
-
const fromValue = Array.isArray(value) ? value : [value];
|
|
24
|
-
const q = [];
|
|
25
|
-
const arr = new Array(fromValue.length);
|
|
26
|
-
const collectNested = ['object', 'record', 'text'].includes(args.fieldSchema.values.type);
|
|
27
|
-
const collected = [];
|
|
28
|
-
for (let i = 0; i < fromValue.length; i++) {
|
|
29
|
-
q.push(args.parse({
|
|
30
|
-
key: i + idx,
|
|
31
|
-
value: fromValue[i],
|
|
32
|
-
fieldSchema: args.fieldSchema.values,
|
|
33
|
-
collect: (nArgs) => {
|
|
34
|
-
const p = nArgs.path.slice(args.path.length);
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
p[0] = p[0] - idx;
|
|
37
|
-
(0, utils_1.setByPath)(arr, p, nArgs.value);
|
|
38
|
-
if (collectNested) {
|
|
39
|
-
collected.push(nArgs);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
await Promise.all(q);
|
|
45
|
-
return { arr, collected };
|
|
46
|
-
};
|
|
47
|
-
const operations = {
|
|
48
|
-
$insert: async (args, value) => {
|
|
49
|
-
if (typeof value.$insert.$idx !== 'number') {
|
|
50
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const { collected, arr } = await parseArray(args, value.$insert.$value, value.$insert.$idx);
|
|
54
|
-
value.$insert.$value = arr;
|
|
55
|
-
collectOperation(args, collected, value);
|
|
56
|
-
},
|
|
57
|
-
$push: async (args, value) => {
|
|
58
|
-
const { collected, arr } = await parseArray(args, value.$push.$value ?? value.$push);
|
|
59
|
-
value.$push = arr;
|
|
60
|
-
collectOperation(args, collected, value, arr.length);
|
|
61
|
-
},
|
|
62
|
-
$unshift: async (args, value) => {
|
|
63
|
-
const { collected, arr } = await parseArray(args, value.$unshift.$value ?? value.$unshift);
|
|
64
|
-
value.$unshift = arr;
|
|
65
|
-
collectOperation(args, collected, value);
|
|
66
|
-
},
|
|
67
|
-
$remove: async (args, value) => {
|
|
68
|
-
if (typeof value.$remove.$idx !== 'number') {
|
|
69
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
args.collect(value);
|
|
73
|
-
},
|
|
74
|
-
$assign: async (args, value) => {
|
|
75
|
-
if (typeof value.$assign !== 'object' ||
|
|
76
|
-
typeof value.$assign.$idx !== 'number') {
|
|
77
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
await args.parse({
|
|
81
|
-
key: value.$assign.$idx,
|
|
82
|
-
value: value.$assign.$value,
|
|
83
|
-
fieldSchema: args.fieldSchema.values,
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
const array = async (args) => {
|
|
88
|
-
args.stop();
|
|
89
|
-
if (typeof args.value !== 'object') {
|
|
90
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
let value = '$value' in args.value ? args.value.$value : args.value;
|
|
94
|
-
if (Array.isArray(value)) {
|
|
95
|
-
const q = [];
|
|
96
|
-
args.collect({ $delete: true });
|
|
97
|
-
for (let i = 0; i < value.length; i++) {
|
|
98
|
-
q.push(args.parse({
|
|
99
|
-
key: i,
|
|
100
|
-
value: args.value[i],
|
|
101
|
-
fieldSchema: args.fieldSchema.values,
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
await Promise.all(q);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
let hasOperation = false;
|
|
108
|
-
for (const key in value) {
|
|
109
|
-
if (operations[key]) {
|
|
110
|
-
if (hasOperation) {
|
|
111
|
-
args.error(error_1.ParseError.multipleOperationsNotAllowed);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
await operations[key](args, value);
|
|
115
|
-
hasOperation = true;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
args.error(error_1.ParseError.fieldDoesNotExist);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
exports.array = array;
|
|
123
|
-
//# sourceMappingURL=array.js.map
|
package/dist/set/fields/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
args.stop();
|
|
54
|
-
try {
|
|
55
|
-
const parsedValue = JSON.stringify(args.value);
|
|
56
|
-
args.collect(parsedValue);
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
args.error(error_1.ParseError.invalidJSON);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
enum: async (args) => {
|
|
63
|
-
// args.stop()
|
|
64
|
-
const enumValues = args.fieldSchema.enum;
|
|
65
|
-
for (let i = 0; i < enumValues.length; i++) {
|
|
66
|
-
if ((0, utils_1.deepEqual)(enumValues[i], args.value)) {
|
|
67
|
-
args.collect(i);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,129 +0,0 @@
|
|
|
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 (isNaN(value)) {
|
|
12
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (value === Infinity || value === -Infinity) {
|
|
16
|
-
args.error(error_1.ParseError.infinityNotSupported);
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (fieldSchema.type === 'integer' && value - Math.floor(value) !== 0) {
|
|
20
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (fieldSchema.multipleOf &&
|
|
24
|
-
value / fieldSchema.multipleOf -
|
|
25
|
-
Math.floor(value / fieldSchema.multipleOf) !==
|
|
26
|
-
0) {
|
|
27
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (ignoreMinMax) {
|
|
31
|
-
// TODO: will be handled in the actual modify command
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (fieldSchema.maximum) {
|
|
35
|
-
if (fieldSchema.exclusiveMaximum) {
|
|
36
|
-
if (value >= fieldSchema.maximum) {
|
|
37
|
-
args.error(error_1.ParseError.exceedsMaximum);
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (value > fieldSchema.maximum) {
|
|
42
|
-
args.error(error_1.ParseError.exceedsMaximum);
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (fieldSchema.minimum) {
|
|
47
|
-
if (fieldSchema.exclusiveMinimum) {
|
|
48
|
-
if (value <= fieldSchema.minimum) {
|
|
49
|
-
args.error(error_1.ParseError.subceedsMinimum);
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (value < fieldSchema.minimum) {
|
|
54
|
-
args.error(error_1.ParseError.subceedsMinimum);
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
59
|
-
};
|
|
60
|
-
const validate = (args, value) => {
|
|
61
|
-
if (value === null) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (typeof value !== 'object') {
|
|
65
|
-
return validateNumber(args, value);
|
|
66
|
-
}
|
|
67
|
-
if ('$value' in value) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
args.stop();
|
|
71
|
-
for (const key in value) {
|
|
72
|
-
if (key === '$default') {
|
|
73
|
-
if (!validateNumber(args, value.$default)) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else if (key === '$increment') {
|
|
78
|
-
if (!validateNumber(args, value.$increment, true)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else if (key === '$decrement') {
|
|
83
|
-
if (!validateNumber(args, value.$decrement, true)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
args.create({ key }).error(error_1.ParseError.fieldDoesNotExist);
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
};
|
|
94
|
-
const number = async (args) => {
|
|
95
|
-
if (!validate(args, args.value)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
args.collect();
|
|
99
|
-
};
|
|
100
|
-
exports.number = number;
|
|
101
|
-
const integer = async (args) => {
|
|
102
|
-
if (!validate(args, args.value)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
args.collect();
|
|
106
|
-
};
|
|
107
|
-
exports.integer = integer;
|
|
108
|
-
const timestamp = async (args) => {
|
|
109
|
-
if (typeof args.value === 'string') {
|
|
110
|
-
if (args.value === 'now') {
|
|
111
|
-
// TODO: + 1s + 10s etc
|
|
112
|
-
args.value = Date.now();
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const d = new Date(args.value);
|
|
116
|
-
args.value = d.valueOf();
|
|
117
|
-
if (isNaN(args.value)) {
|
|
118
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (!validateNumber(args, args.value)) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
args.collect();
|
|
127
|
-
};
|
|
128
|
-
exports.timestamp = timestamp;
|
|
129
|
-
//# sourceMappingURL=number.js.map
|
|
@@ -1,33 +0,0 @@
|
|
|
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' || args.value === null) {
|
|
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' || args.value === null) {
|
|
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
|
|
@@ -1,128 +0,0 @@
|
|
|
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 typeIsAllowed = (args, type) => {
|
|
28
|
-
if ('allowedTypes' in args.fieldSchema) {
|
|
29
|
-
let typeMatches = false;
|
|
30
|
-
for (const t of args.fieldSchema.allowedTypes) {
|
|
31
|
-
if (typeof t === 'string') {
|
|
32
|
-
if (t === type) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (t.type && t.type === type) {
|
|
38
|
-
typeMatches = true;
|
|
39
|
-
if (t.$filter) {
|
|
40
|
-
// stage on requires validation in target
|
|
41
|
-
// TODO: ASYNC REQUIRED HOOK
|
|
42
|
-
// if(!(await args.target.referenceFilterCondition(value, t.$filter))){
|
|
43
|
-
// error(args, ParseError.referenceIsIncorrectType)
|
|
44
|
-
// return
|
|
45
|
-
// }
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (!t.type && t.$filter) {
|
|
49
|
-
// if(!(await args.target.referenceFilterCondition))
|
|
50
|
-
// error(args, ParseError.referenceIsIncorrectType, )
|
|
51
|
-
// return
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (typeMatches === false) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
};
|
|
61
|
-
const reference = async (args) => {
|
|
62
|
-
// TODO: setting an object here , handling $alias (both async hooks)
|
|
63
|
-
// Block if path contains $remove (maybe not for $alias)
|
|
64
|
-
if (typeof args.value === 'object') {
|
|
65
|
-
if (args.root._opts.asyncOperationHandler) {
|
|
66
|
-
if (args.value.type && !typeIsAllowed(args, args.value.type)) {
|
|
67
|
-
args.error(error_1.ParseError.referenceIsIncorrectType);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!args.target.errors.length) {
|
|
71
|
-
args.value = await args.root._opts.asyncOperationHandler(args, 'modifyObject');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
args.error(error_1.ParseError.nestedModifyObjectNotAllowed);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (!(0, isValidId_1.isValidId)(args.schema, args.value)) {
|
|
80
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const prefix = args.value.slice(0, 2);
|
|
84
|
-
const targetType = args.schema.prefixToTypeMapping[prefix];
|
|
85
|
-
if (typeIsAllowed(args, targetType)) {
|
|
86
|
-
args.collect();
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
args.error(error_1.ParseError.referenceIsIncorrectType);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
exports.reference = reference;
|
|
93
|
-
const references = async (args) => {
|
|
94
|
-
const { value } = args;
|
|
95
|
-
if (typeof value !== 'object' || value === null) {
|
|
96
|
-
args.error(error_1.ParseError.incorrectFormat);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
args.stop();
|
|
100
|
-
if (Array.isArray(value)) {
|
|
101
|
-
const parseValues = await Promise.all(value.map(async (id, key) => {
|
|
102
|
-
const n = args.create({
|
|
103
|
-
value: id,
|
|
104
|
-
key,
|
|
105
|
-
skipCollection: true,
|
|
106
|
-
});
|
|
107
|
-
await (0, exports.reference)(n);
|
|
108
|
-
return n.value;
|
|
109
|
-
}));
|
|
110
|
-
args.value = { $value: parseValues };
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
for (const key in args.value) {
|
|
114
|
-
if (key === '$add') {
|
|
115
|
-
args.value.$add = await parseOperator(args, key);
|
|
116
|
-
}
|
|
117
|
-
else if (key === '$remove') {
|
|
118
|
-
args.value.$remove = await parseOperator(args, key);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
args.create({ key }).error(error_1.ParseError.fieldDoesNotExist);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
args.collect();
|
|
126
|
-
};
|
|
127
|
-
exports.references = references;
|
|
128
|
-
//# sourceMappingURL=references.js.map
|
package/dist/set/fields/set.d.ts
DELETED
package/dist/set/fields/set.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
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
|