@based/schema 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/set/collections.js +57 -13
- package/dist/set/collections.js.map +1 -1
- package/dist/set/error.d.ts +2 -1
- package/dist/set/error.js +1 -0
- package/dist/set/error.js.map +1 -1
- package/dist/set/index.js +20 -5
- package/dist/set/index.js.map +1 -1
- package/dist/set/string.js +15 -2
- package/dist/set/string.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/updateSchema.d.ts +2 -0
- package/dist/updateSchema.js +16 -0
- package/dist/updateSchema.js.map +1 -0
- package/dist/validateSchema.js +5 -1
- package/dist/validateSchema.js.map +1 -1
- package/package.json +1 -1
- package/src/set/collections.ts +68 -24
- package/src/set/error.ts +1 -0
- package/src/set/index.ts +23 -5
- package/src/set/string.ts +34 -3
- package/src/types.ts +4 -6
- package/src/updateSchema.ts +18 -0
- package/src/validateSchema.ts +6 -1
- package/test/setWalker.ts +133 -38
package/dist/set/collections.js
CHANGED
|
@@ -4,6 +4,9 @@ exports.record = exports.array = exports.object = exports.set = void 0;
|
|
|
4
4
|
const error_1 = require("./error");
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const set = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
7
|
+
if (value && typeof value === 'object' && value.$value) {
|
|
8
|
+
value = value.$value;
|
|
9
|
+
}
|
|
7
10
|
const q = [];
|
|
8
11
|
const fieldDef = fieldSchema.items;
|
|
9
12
|
if (Array.isArray(value)) {
|
|
@@ -33,9 +36,9 @@ const set = async (path, value, fieldSchema, typeSchema, target, handlers, noCol
|
|
|
33
36
|
q.push((0, _1.fieldWalker)(path, value.$add[i], fieldDef, typeSchema, target, handlers, true));
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
if (value.$
|
|
37
|
-
for (let i = 0; i < value.$
|
|
38
|
-
q.push((0, _1.fieldWalker)(path, value.$
|
|
39
|
+
if (value.$remove) {
|
|
40
|
+
for (let i = 0; i < value.$remove.length; i++) {
|
|
41
|
+
q.push((0, _1.fieldWalker)(path, value.$remove[i], fieldDef, typeSchema, target, handlers, true));
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
await Promise.all(q);
|
|
@@ -62,16 +65,33 @@ const object = async (path, value, fieldSchema, typeSchema, target, handlers, no
|
|
|
62
65
|
q.push((0, _1.fieldWalker)([...path, key], value[key], propDef, typeSchema, target, handlers, noCollect));
|
|
63
66
|
}
|
|
64
67
|
await Promise.all(q);
|
|
68
|
+
if (fieldSchema.required) {
|
|
69
|
+
for (const req of fieldSchema.required) {
|
|
70
|
+
if (!(req in value)) {
|
|
71
|
+
target.required.push([...path, req]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
65
75
|
};
|
|
66
76
|
exports.object = object;
|
|
67
77
|
// unshift // only allow 1 command
|
|
68
78
|
const array = async (path, value, fieldSchema, typeSchema, target, handlers, noCollect) => {
|
|
69
|
-
|
|
79
|
+
let isArray = Array.isArray(value);
|
|
70
80
|
let parsedValue = value;
|
|
71
81
|
let opCount = 0;
|
|
72
|
-
|
|
82
|
+
let has$Value = false;
|
|
83
|
+
if (typeof parsedValue === 'object' && !isArray) {
|
|
84
|
+
if (value.$value) {
|
|
85
|
+
opCount++;
|
|
86
|
+
has$Value = true;
|
|
87
|
+
parsedValue = value.$value;
|
|
88
|
+
isArray = Array.isArray(parsedValue);
|
|
89
|
+
}
|
|
73
90
|
if (value.$insert) {
|
|
74
91
|
opCount++;
|
|
92
|
+
if (opCount > 1) {
|
|
93
|
+
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
94
|
+
}
|
|
75
95
|
if (typeof value.$insert !== 'object' ||
|
|
76
96
|
value.$insert.$idx === undefined) {
|
|
77
97
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
@@ -101,6 +121,7 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
101
121
|
if (opCount > 1) {
|
|
102
122
|
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
103
123
|
}
|
|
124
|
+
// TODO: FIX PUSH PARSING
|
|
104
125
|
const q = [];
|
|
105
126
|
const push = Array.isArray(value.$push) ? value.$push : [value.$push];
|
|
106
127
|
for (let i = 0; i < push.length; i++) {
|
|
@@ -118,6 +139,7 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
118
139
|
const unshift = Array.isArray(value.$unshift)
|
|
119
140
|
? value.$unshift
|
|
120
141
|
: [value.$unshift];
|
|
142
|
+
// TODO: FIX UNSHIFT PARSING
|
|
121
143
|
for (let i = 0; i < unshift.length; i++) {
|
|
122
144
|
q.push((0, _1.fieldWalker)(path, unshift[i], fieldSchema.values, typeSchema, target, handlers, true));
|
|
123
145
|
}
|
|
@@ -130,14 +152,13 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
130
152
|
(0, error_1.error)(path, error_1.ParseError.multipleOperationsNotAllowed);
|
|
131
153
|
}
|
|
132
154
|
if (typeof value.$assign !== 'object' ||
|
|
133
|
-
value.$assign.$idx
|
|
155
|
+
typeof value.$assign.$idx !== 'number') {
|
|
134
156
|
(0, error_1.error)(path, error_1.ParseError.incorrectFormat);
|
|
135
157
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
158
|
+
await (0, _1.fieldWalker)([...path, value.$assign.$idx], value.$assign.$value, fieldSchema.values, typeSchema, target, handlers, noCollect);
|
|
159
|
+
return;
|
|
139
160
|
}
|
|
140
|
-
if (!noCollect) {
|
|
161
|
+
if (!has$Value && !noCollect) {
|
|
141
162
|
handlers.collect({
|
|
142
163
|
path,
|
|
143
164
|
value: parsedValue,
|
|
@@ -146,16 +167,39 @@ const array = async (path, value, fieldSchema, typeSchema, target, handlers, noC
|
|
|
146
167
|
target,
|
|
147
168
|
});
|
|
148
169
|
}
|
|
149
|
-
|
|
170
|
+
if (!has$Value) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
150
173
|
}
|
|
151
174
|
if (!isArray) {
|
|
152
175
|
(0, error_1.error)(path, error_1.ParseError.incorrectFieldType);
|
|
153
176
|
}
|
|
154
177
|
const q = [];
|
|
155
|
-
|
|
156
|
-
|
|
178
|
+
const collector = [];
|
|
179
|
+
const nHandler = noCollect
|
|
180
|
+
? handlers
|
|
181
|
+
: {
|
|
182
|
+
...handlers,
|
|
183
|
+
collect: (collect) => {
|
|
184
|
+
collector.push(collect);
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
for (let i = 0; i < parsedValue.length; i++) {
|
|
188
|
+
q.push((0, _1.fieldWalker)([...path, i], parsedValue[i], fieldSchema.values, typeSchema, target, nHandler, noCollect));
|
|
157
189
|
}
|
|
158
190
|
await Promise.all(q);
|
|
191
|
+
if (!noCollect) {
|
|
192
|
+
handlers.collect({
|
|
193
|
+
path,
|
|
194
|
+
typeSchema,
|
|
195
|
+
fieldSchema,
|
|
196
|
+
target,
|
|
197
|
+
value: { $delete: true },
|
|
198
|
+
});
|
|
199
|
+
for (const c of collector) {
|
|
200
|
+
handlers.collect(c);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
159
203
|
};
|
|
160
204
|
exports.array = array;
|
|
161
205
|
const record = async (path, value, fieldSchema) => { };
|
|
@@ -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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|
'valueAndDefault' = 7,
|
|
10
10
|
'defaultNotSupported' = 8,
|
|
11
|
-
'multipleOperationsNotAllowed' = 9
|
|
11
|
+
'multipleOperationsNotAllowed' = 9,
|
|
12
|
+
'requiredFieldNotDefined' = 10
|
|
12
13
|
}
|
|
13
14
|
export declare const error: (path: (number | string)[], error: ParseError, type?: string) => never;
|
package/dist/set/error.js
CHANGED
|
@@ -13,6 +13,7 @@ var ParseError;
|
|
|
13
13
|
ParseError[ParseError["valueAndDefault"] = 7] = "valueAndDefault";
|
|
14
14
|
ParseError[ParseError["defaultNotSupported"] = 8] = "defaultNotSupported";
|
|
15
15
|
ParseError[ParseError["multipleOperationsNotAllowed"] = 9] = "multipleOperationsNotAllowed";
|
|
16
|
+
ParseError[ParseError["requiredFieldNotDefined"] = 10] = "requiredFieldNotDefined";
|
|
16
17
|
})(ParseError = exports.ParseError || (exports.ParseError = {}));
|
|
17
18
|
const error = (path, error, type // nice to give as option
|
|
18
19
|
) => {
|
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,UAYX;AAZD,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;AAC3B,CAAC,EAZW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAYrB;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/index.js
CHANGED
|
@@ -55,6 +55,7 @@ const setWalker = async (schema, value, handlers) => {
|
|
|
55
55
|
const target = {
|
|
56
56
|
type,
|
|
57
57
|
schema,
|
|
58
|
+
required: [],
|
|
58
59
|
};
|
|
59
60
|
if (value.$id) {
|
|
60
61
|
target.$id = value.$id;
|
|
@@ -64,7 +65,7 @@ const setWalker = async (schema, value, handlers) => {
|
|
|
64
65
|
}
|
|
65
66
|
const q = [];
|
|
66
67
|
for (const key in value) {
|
|
67
|
-
if (key[0] !== '$') {
|
|
68
|
+
if (key[0] !== '$' && key !== 'type') {
|
|
68
69
|
const fieldSchema = schemaType.fields[key];
|
|
69
70
|
if (!fieldSchema) {
|
|
70
71
|
(0, error_1.error)([key], error_1.ParseError.fieldDoesNotExist);
|
|
@@ -75,10 +76,24 @@ const setWalker = async (schema, value, handlers) => {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
await Promise.all(q);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if (schemaType.required) {
|
|
80
|
+
for (const req of schemaType.required) {
|
|
81
|
+
if (!(req in value)) {
|
|
82
|
+
target.required.push([req]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (target.required?.length) {
|
|
87
|
+
const requireDefined = await Promise.all(target.required.map(async (req) => {
|
|
88
|
+
return handlers.checkRequiredFields(req);
|
|
89
|
+
}));
|
|
90
|
+
for (let i = 0; i < requireDefined.length; i++) {
|
|
91
|
+
if (!requireDefined[i]) {
|
|
92
|
+
const r = target.required[i];
|
|
93
|
+
(0, error_1.error)(r, error_1.ParseError.requiredFieldNotDefined);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
82
97
|
return target;
|
|
83
98
|
};
|
|
84
99
|
exports.setWalker = setWalker;
|
package/dist/set/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/set/index.ts"],"names":[],"mappings":";;;;;;AAOA,mCAA2C;AAC3C,wDAA+B;AAExB,MAAM,WAAW,GAAG,KAAK,EAC9B,IAAyB,EACzB,KAAU,EACV,WAA6B,EAC7B,UAA2B,EAC3B,MAAsB,EACtB,QAA0B,EAC1B,SAAmB,EACJ,EAAE;IACjB,IAAI,MAAM,IAAI,WAAW,EAAE;QACzB,6GAA6G;QAC7G,OAAM;KACP;IACD,MAAM,SAAS,GAAG,OAAO,KAAK,CAAA;IAE9B,MAAM,aAAa,GAAG,KAAK,IAAI,SAAS,KAAK,QAAQ,CAAA;IACrD,IAAI,aAAa,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,EAAE;QAC3C,IAAI,CAAC,SAAS,EAAE;YACd,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAA;SACnE;QACD,OAAM;KACP;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAEzE,IAAI,CAAC,OAAO,EAAE;QACZ,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,iBAAiB,CAAC,CAAA;KAC1C;IAED,IAAI,iBAAiB,IAAI,WAAW,EAAE;QACpC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAA;QACnD,IAAI,CAAC,CAAC,MAAM,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE;YACjD,IAAA,aAAK,EAAC,IAAI,EAAE,kBAAU,CAAC,eAAe,C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AAK,EAAC,CAAC,EAAE,kBAAU,CAAC,uBAAuB,CAAC,CAAA;aAC7C;SACF;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAtFY,QAAA,SAAS,aAsFrB"}
|
package/dist/set/string.js
CHANGED
|
@@ -122,6 +122,18 @@ const text = async (path, value, fieldSchema, typeSchema, target, handlers, noCo
|
|
|
122
122
|
(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, noCollect))) {
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
|
+
else if (await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, value, fieldSchema, typeSchema, target, handlers, true)) {
|
|
126
|
+
if (!noCollect) {
|
|
127
|
+
handlers.collect({
|
|
128
|
+
path,
|
|
129
|
+
value,
|
|
130
|
+
typeSchema,
|
|
131
|
+
fieldSchema,
|
|
132
|
+
target,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
125
137
|
for (const key in value) {
|
|
126
138
|
const newPath = [...path, key];
|
|
127
139
|
if (typeof value[key] === 'object') {
|
|
@@ -139,8 +151,9 @@ const text = async (path, value, fieldSchema, typeSchema, target, handlers, noCo
|
|
|
139
151
|
}
|
|
140
152
|
continue;
|
|
141
153
|
}
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
if (!(await (0, parseDefaultAndValue_1.parseValueAndDefault)(path, { $language: key, [key]: value[key] }, fieldSchema, typeSchema, target, handlers, true))) {
|
|
155
|
+
validate(newPath, value[key], fieldSchema);
|
|
156
|
+
}
|
|
144
157
|
if (!noCollect) {
|
|
145
158
|
handlers.collect({
|
|
146
159
|
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;AAClC,iEAA6D;AAE7D,MAAM,c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W,CAAC,CAAA;SAC3C;QAED,IAAI,CAAC,SAAS,EAAE;YACd,QAAQ,CAAC,OAAO,CAAC;gBACf,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;gBACjB,UAAU;gBACV,WAAW;gBACX,MAAM;aACP,CAAC,CAAA;SACH;KACF;AACH,CAAC,CAAA;AAnHY,QAAA,IAAI,QAmHhB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -170,6 +170,7 @@ export type BasedSetTarget = {
|
|
|
170
170
|
$id?: string;
|
|
171
171
|
schema: BasedSchema;
|
|
172
172
|
$language?: BasedSchemaLanguage;
|
|
173
|
+
required: (number | string)[][];
|
|
173
174
|
};
|
|
174
175
|
export type BasedSchemaCollectProps = {
|
|
175
176
|
path: (string | number)[];
|
|
@@ -180,6 +181,7 @@ export type BasedSchemaCollectProps = {
|
|
|
180
181
|
};
|
|
181
182
|
export type BasedSetHandlers = {
|
|
182
183
|
collect: (props: BasedSchemaCollectProps) => void;
|
|
184
|
+
checkRequiredFields: (path: (string | number)[]) => Promise<boolean>;
|
|
183
185
|
referenceFilterCondition: (referenceId: string, $filter: any) => Promise<boolean>;
|
|
184
186
|
};
|
|
185
187
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSchema = void 0;
|
|
4
|
+
const updateSchema = async (newSchema, oldSchema = {
|
|
5
|
+
$defs: {},
|
|
6
|
+
types: {},
|
|
7
|
+
languages: ['en'],
|
|
8
|
+
root: { fields: {} },
|
|
9
|
+
prefixToTypeMapping: {},
|
|
10
|
+
}) => {
|
|
11
|
+
// add sha
|
|
12
|
+
// put isRequired on the new schema in REQUIRED arrays
|
|
13
|
+
return oldSchema;
|
|
14
|
+
};
|
|
15
|
+
exports.updateSchema = updateSchema;
|
|
16
|
+
//# sourceMappingURL=updateSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateSchema.js","sourceRoot":"","sources":["../src/updateSchema.ts"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG,KAAK,EAC/B,SAA6B,EAC7B,YAAyB;IACvB,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,CAAC,IAAI,CAAC;IACjB,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACpB,mBAAmB,EAAE,EAAE;CACxB,EACqB,EAAE;IACxB,UAAU;IAEV,sDAAsD;IAEtD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAfY,QAAA,YAAY,gBAexB"}
|
package/dist/validateSchema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateSchema = exports.validateField = exports.validateType = void 0;
|
|
4
|
+
// gaurd in the schema for refs in arrays
|
|
4
5
|
const validateType = (fromSchema, typeName, type) => {
|
|
5
6
|
if (type.prefix &&
|
|
6
7
|
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
@@ -8,7 +9,9 @@ const validateType = (fromSchema, typeName, type) => {
|
|
|
8
9
|
}
|
|
9
10
|
};
|
|
10
11
|
exports.validateType = validateType;
|
|
11
|
-
const validateField = (fromSchema, path, field) => {
|
|
12
|
+
const validateField = (fromSchema, path, field) => {
|
|
13
|
+
//
|
|
14
|
+
};
|
|
12
15
|
exports.validateField = validateField;
|
|
13
16
|
const validateSchema = (schema) => {
|
|
14
17
|
// rewrite schema things like required / required: []
|
|
@@ -22,6 +25,7 @@ const validateSchema = (schema) => {
|
|
|
22
25
|
// first defs ofc
|
|
23
26
|
}
|
|
24
27
|
if (schema.root) {
|
|
28
|
+
(0, exports.validateType)(schema, 'root', schema.root);
|
|
25
29
|
}
|
|
26
30
|
if (schema.types) {
|
|
27
31
|
for (const type in schema.types) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateSchema.js","sourceRoot":"","sources":["../src/validateSchema.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"validateSchema.js","sourceRoot":"","sources":["../src/validateSchema.ts"],"names":[],"mappings":";;;AAOA,yCAAyC;AAElC,MAAM,YAAY,GAAG,CAC1B,UAA8B,EAC9B,QAAgB,EAChB,IAA4B,EAC5B,EAAE;IACF,IACE,IAAI,CAAC,MAAM;QACX,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,EAC7D;QACA,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,CAAC,MAAM,eAAe,QAAQ,iFAAiF,CACzI,CAAA;KACF;AACH,CAAC,CAAA;AAbY,QAAA,YAAY,gBAaxB;AAEM,MAAM,aAAa,GAAG,CAC3B,UAA8B,EAC9B,IAAc,EACd,KAA8B,EAC9B,EAAE;IACF,EAAE;AACJ,CAAC,CAAA;AANY,QAAA,aAAa,iBAMzB;AAEM,MAAM,cAAc,GAAG,CAC5B,MAA0B,EACN,EAAE;IACtB,qDAAqD;IAErD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;IAED,IAAI,MAAM,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;QACxD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;KAClD;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,iBAAiB;KAClB;IAED,IAAI,MAAM,CAAC,IAAI,EAAE;QACf,IAAA,oBAAY,EAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAC1C;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;YAC/B,IAAA,oBAAY,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;SAC/C;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AA5BY,QAAA,cAAc,kBA4B1B"}
|
package/package.json
CHANGED
package/src/set/collections.ts
CHANGED
|
@@ -11,6 +11,9 @@ export const set: Parser<'set'> = async (
|
|
|
11
11
|
handlers,
|
|
12
12
|
noCollect
|
|
13
13
|
) => {
|
|
14
|
+
if (value && typeof value === 'object' && value.$value) {
|
|
15
|
+
value = value.$value
|
|
16
|
+
}
|
|
14
17
|
const q: Promise<void>[] = []
|
|
15
18
|
const fieldDef = fieldSchema.items
|
|
16
19
|
if (Array.isArray(value)) {
|
|
@@ -51,12 +54,12 @@ export const set: Parser<'set'> = async (
|
|
|
51
54
|
)
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
if (value.$
|
|
55
|
-
for (let i = 0; i < value.$
|
|
57
|
+
if (value.$remove) {
|
|
58
|
+
for (let i = 0; i < value.$remove.length; i++) {
|
|
56
59
|
q.push(
|
|
57
60
|
fieldWalker(
|
|
58
61
|
path,
|
|
59
|
-
value.$
|
|
62
|
+
value.$remove[i],
|
|
60
63
|
fieldDef,
|
|
61
64
|
typeSchema,
|
|
62
65
|
target,
|
|
@@ -108,6 +111,13 @@ export const object: Parser<'object'> = async (
|
|
|
108
111
|
)
|
|
109
112
|
}
|
|
110
113
|
await Promise.all(q)
|
|
114
|
+
if (fieldSchema.required) {
|
|
115
|
+
for (const req of fieldSchema.required) {
|
|
116
|
+
if (!(req in value)) {
|
|
117
|
+
target.required.push([...path, req])
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
|
|
113
123
|
// unshift // only allow 1 command
|
|
@@ -120,12 +130,22 @@ export const array: Parser<'array'> = async (
|
|
|
120
130
|
handlers,
|
|
121
131
|
noCollect
|
|
122
132
|
) => {
|
|
123
|
-
|
|
133
|
+
let isArray = Array.isArray(value)
|
|
124
134
|
let parsedValue = value
|
|
125
135
|
let opCount = 0
|
|
126
|
-
|
|
136
|
+
let has$Value = false
|
|
137
|
+
if (typeof parsedValue === 'object' && !isArray) {
|
|
138
|
+
if (value.$value) {
|
|
139
|
+
opCount++
|
|
140
|
+
has$Value = true
|
|
141
|
+
parsedValue = value.$value
|
|
142
|
+
isArray = Array.isArray(parsedValue)
|
|
143
|
+
}
|
|
127
144
|
if (value.$insert) {
|
|
128
145
|
opCount++
|
|
146
|
+
if (opCount > 1) {
|
|
147
|
+
error(path, ParseError.multipleOperationsNotAllowed)
|
|
148
|
+
}
|
|
129
149
|
if (
|
|
130
150
|
typeof value.$insert !== 'object' ||
|
|
131
151
|
value.$insert.$idx === undefined
|
|
@@ -167,6 +187,7 @@ export const array: Parser<'array'> = async (
|
|
|
167
187
|
error(path, ParseError.multipleOperationsNotAllowed)
|
|
168
188
|
}
|
|
169
189
|
|
|
190
|
+
// TODO: FIX PUSH PARSING
|
|
170
191
|
const q: Promise<void>[] = []
|
|
171
192
|
const push = Array.isArray(value.$push) ? value.$push : [value.$push]
|
|
172
193
|
for (let i = 0; i < push.length; i++) {
|
|
@@ -190,11 +211,12 @@ export const array: Parser<'array'> = async (
|
|
|
190
211
|
if (opCount > 1) {
|
|
191
212
|
error(path, ParseError.multipleOperationsNotAllowed)
|
|
192
213
|
}
|
|
193
|
-
|
|
194
214
|
const q: Promise<void>[] = []
|
|
195
215
|
const unshift = Array.isArray(value.$unshift)
|
|
196
216
|
? value.$unshift
|
|
197
217
|
: [value.$unshift]
|
|
218
|
+
|
|
219
|
+
// TODO: FIX UNSHIFT PARSING
|
|
198
220
|
for (let i = 0; i < unshift.length; i++) {
|
|
199
221
|
q.push(
|
|
200
222
|
fieldWalker(
|
|
@@ -216,26 +238,24 @@ export const array: Parser<'array'> = async (
|
|
|
216
238
|
if (opCount > 1) {
|
|
217
239
|
error(path, ParseError.multipleOperationsNotAllowed)
|
|
218
240
|
}
|
|
219
|
-
|
|
220
241
|
if (
|
|
221
242
|
typeof value.$assign !== 'object' ||
|
|
222
|
-
value.$assign.$idx
|
|
243
|
+
typeof value.$assign.$idx !== 'number'
|
|
223
244
|
) {
|
|
224
245
|
error(path, ParseError.incorrectFormat)
|
|
225
|
-
} else {
|
|
226
|
-
await fieldWalker(
|
|
227
|
-
path,
|
|
228
|
-
value.$assign.$value,
|
|
229
|
-
fieldSchema.values,
|
|
230
|
-
typeSchema,
|
|
231
|
-
target,
|
|
232
|
-
handlers,
|
|
233
|
-
true
|
|
234
|
-
)
|
|
235
246
|
}
|
|
247
|
+
await fieldWalker(
|
|
248
|
+
[...path, value.$assign.$idx],
|
|
249
|
+
value.$assign.$value,
|
|
250
|
+
fieldSchema.values,
|
|
251
|
+
typeSchema,
|
|
252
|
+
target,
|
|
253
|
+
handlers,
|
|
254
|
+
noCollect
|
|
255
|
+
)
|
|
256
|
+
return
|
|
236
257
|
}
|
|
237
|
-
|
|
238
|
-
if (!noCollect) {
|
|
258
|
+
if (!has$Value && !noCollect) {
|
|
239
259
|
handlers.collect({
|
|
240
260
|
path,
|
|
241
261
|
value: parsedValue,
|
|
@@ -244,26 +264,50 @@ export const array: Parser<'array'> = async (
|
|
|
244
264
|
target,
|
|
245
265
|
})
|
|
246
266
|
}
|
|
247
|
-
|
|
267
|
+
if (!has$Value) {
|
|
268
|
+
return
|
|
269
|
+
}
|
|
248
270
|
}
|
|
249
271
|
if (!isArray) {
|
|
250
272
|
error(path, ParseError.incorrectFieldType)
|
|
251
273
|
}
|
|
252
274
|
const q: Promise<void>[] = []
|
|
253
|
-
|
|
275
|
+
const collector: any[] = []
|
|
276
|
+
const nHandler = noCollect
|
|
277
|
+
? handlers
|
|
278
|
+
: {
|
|
279
|
+
...handlers,
|
|
280
|
+
collect: (collect) => {
|
|
281
|
+
collector.push(collect)
|
|
282
|
+
},
|
|
283
|
+
}
|
|
284
|
+
for (let i = 0; i < parsedValue.length; i++) {
|
|
254
285
|
q.push(
|
|
255
286
|
fieldWalker(
|
|
256
287
|
[...path, i],
|
|
257
|
-
|
|
288
|
+
parsedValue[i],
|
|
258
289
|
fieldSchema.values,
|
|
259
290
|
typeSchema,
|
|
260
291
|
target,
|
|
261
|
-
|
|
292
|
+
nHandler,
|
|
262
293
|
noCollect
|
|
263
294
|
)
|
|
264
295
|
)
|
|
265
296
|
}
|
|
266
297
|
await Promise.all(q)
|
|
298
|
+
|
|
299
|
+
if (!noCollect) {
|
|
300
|
+
handlers.collect({
|
|
301
|
+
path,
|
|
302
|
+
typeSchema,
|
|
303
|
+
fieldSchema,
|
|
304
|
+
target,
|
|
305
|
+
value: { $delete: true },
|
|
306
|
+
})
|
|
307
|
+
for (const c of collector) {
|
|
308
|
+
handlers.collect(c)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
267
311
|
}
|
|
268
312
|
|
|
269
313
|
export const record: Parser<'record'> = async (path, value, fieldSchema) => {}
|
package/src/set/error.ts
CHANGED
package/src/set/index.ts
CHANGED
|
@@ -81,6 +81,7 @@ export const setWalker = async (
|
|
|
81
81
|
const target: BasedSetTarget = {
|
|
82
82
|
type,
|
|
83
83
|
schema,
|
|
84
|
+
required: [],
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
if (value.$id) {
|
|
@@ -92,7 +93,7 @@ export const setWalker = async (
|
|
|
92
93
|
const q: Promise<void>[] = []
|
|
93
94
|
|
|
94
95
|
for (const key in value) {
|
|
95
|
-
if (key[0] !== '$') {
|
|
96
|
+
if (key[0] !== '$' && key !== 'type') {
|
|
96
97
|
const fieldSchema = schemaType.fields[key]
|
|
97
98
|
if (!fieldSchema) {
|
|
98
99
|
error([key], ParseError.fieldDoesNotExist)
|
|
@@ -113,10 +114,27 @@ export const setWalker = async (
|
|
|
113
114
|
|
|
114
115
|
await Promise.all(q)
|
|
115
116
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
if (schemaType.required) {
|
|
118
|
+
for (const req of schemaType.required) {
|
|
119
|
+
if (!(req in value)) {
|
|
120
|
+
target.required.push([req])
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (target.required?.length) {
|
|
126
|
+
const requireDefined = await Promise.all(
|
|
127
|
+
target.required.map(async (req) => {
|
|
128
|
+
return handlers.checkRequiredFields(req)
|
|
129
|
+
})
|
|
130
|
+
)
|
|
131
|
+
for (let i = 0; i < requireDefined.length; i++) {
|
|
132
|
+
if (!requireDefined[i]) {
|
|
133
|
+
const r = target.required[i]
|
|
134
|
+
error(r, ParseError.requiredFieldNotDefined)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
120
138
|
|
|
121
139
|
return target
|
|
122
140
|
}
|
package/src/set/string.ts
CHANGED
|
@@ -165,6 +165,27 @@ export const text: Parser<'text'> = async (
|
|
|
165
165
|
))
|
|
166
166
|
) {
|
|
167
167
|
return
|
|
168
|
+
} else if (
|
|
169
|
+
await parseValueAndDefault(
|
|
170
|
+
path,
|
|
171
|
+
value,
|
|
172
|
+
fieldSchema,
|
|
173
|
+
typeSchema,
|
|
174
|
+
target,
|
|
175
|
+
handlers,
|
|
176
|
+
true
|
|
177
|
+
)
|
|
178
|
+
) {
|
|
179
|
+
if (!noCollect) {
|
|
180
|
+
handlers.collect({
|
|
181
|
+
path,
|
|
182
|
+
value,
|
|
183
|
+
typeSchema,
|
|
184
|
+
fieldSchema,
|
|
185
|
+
target,
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
return
|
|
168
189
|
}
|
|
169
190
|
|
|
170
191
|
for (const key in value) {
|
|
@@ -194,9 +215,19 @@ export const text: Parser<'text'> = async (
|
|
|
194
215
|
continue
|
|
195
216
|
}
|
|
196
217
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
218
|
+
if (
|
|
219
|
+
!(await parseValueAndDefault(
|
|
220
|
+
path,
|
|
221
|
+
{ $language: key, [key]: value[key] },
|
|
222
|
+
fieldSchema,
|
|
223
|
+
typeSchema,
|
|
224
|
+
target,
|
|
225
|
+
handlers,
|
|
226
|
+
true
|
|
227
|
+
))
|
|
228
|
+
) {
|
|
229
|
+
validate(newPath, value[key], fieldSchema)
|
|
230
|
+
}
|
|
200
231
|
|
|
201
232
|
if (!noCollect) {
|
|
202
233
|
handlers.collect({
|
package/src/types.ts
CHANGED
|
@@ -340,6 +340,7 @@ export type BasedSetTarget = {
|
|
|
340
340
|
$id?: string
|
|
341
341
|
schema: BasedSchema
|
|
342
342
|
$language?: BasedSchemaLanguage
|
|
343
|
+
required: (number | string)[][]
|
|
343
344
|
}
|
|
344
345
|
|
|
345
346
|
export type BasedSchemaCollectProps = {
|
|
@@ -353,13 +354,10 @@ export type BasedSchemaCollectProps = {
|
|
|
353
354
|
export type BasedSetHandlers = {
|
|
354
355
|
collect: (props: BasedSchemaCollectProps) => void
|
|
355
356
|
|
|
356
|
-
//
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
// (number|string)[]
|
|
360
|
-
// typeschema, target) => Promise<boolean>
|
|
357
|
+
// add collectNeedRequired
|
|
358
|
+
|
|
359
|
+
checkRequiredFields: (path: (string | number)[]) => Promise<boolean>
|
|
361
360
|
|
|
362
|
-
// $filter
|
|
363
361
|
referenceFilterCondition: (
|
|
364
362
|
referenceId: string,
|
|
365
363
|
$filter: any
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BasedSchema, BasedSchemaPartial } from './types'
|
|
2
|
+
|
|
3
|
+
export const updateSchema = async (
|
|
4
|
+
newSchema: BasedSchemaPartial,
|
|
5
|
+
oldSchema: BasedSchema = {
|
|
6
|
+
$defs: {},
|
|
7
|
+
types: {},
|
|
8
|
+
languages: ['en'],
|
|
9
|
+
root: { fields: {} },
|
|
10
|
+
prefixToTypeMapping: {},
|
|
11
|
+
}
|
|
12
|
+
): Promise<BasedSchema> => {
|
|
13
|
+
// add sha
|
|
14
|
+
|
|
15
|
+
// put isRequired on the new schema in REQUIRED arrays
|
|
16
|
+
|
|
17
|
+
return oldSchema
|
|
18
|
+
}
|
package/src/validateSchema.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
BasedSchemaField,
|
|
6
6
|
} from './types'
|
|
7
7
|
|
|
8
|
+
// gaurd in the schema for refs in arrays
|
|
9
|
+
|
|
8
10
|
export const validateType = (
|
|
9
11
|
fromSchema: BasedSchemaPartial,
|
|
10
12
|
typeName: string,
|
|
@@ -24,7 +26,9 @@ export const validateField = (
|
|
|
24
26
|
fromSchema: BasedSchemaPartial,
|
|
25
27
|
path: string[],
|
|
26
28
|
field: BasedSchemaFieldPartial
|
|
27
|
-
) => {
|
|
29
|
+
) => {
|
|
30
|
+
//
|
|
31
|
+
}
|
|
28
32
|
|
|
29
33
|
export const validateSchema = (
|
|
30
34
|
schema: BasedSchemaPartial
|
|
@@ -44,6 +48,7 @@ export const validateSchema = (
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
if (schema.root) {
|
|
51
|
+
validateType(schema, 'root', schema.root)
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
if (schema.types) {
|
package/test/setWalker.ts
CHANGED
|
@@ -121,27 +121,16 @@ const schema: BasedSchema = {
|
|
|
121
121
|
},
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// $value
|
|
125
|
-
// $default
|
|
126
|
-
|
|
127
124
|
// $noRoot
|
|
128
|
-
|
|
129
125
|
// $delete -> change for set / references
|
|
130
|
-
|
|
131
126
|
// $merge: false,
|
|
132
|
-
|
|
133
|
-
// $increment
|
|
134
|
-
// $decrement
|
|
135
|
-
|
|
136
127
|
// $assign
|
|
137
128
|
// $insert
|
|
138
129
|
// $remove
|
|
139
|
-
// $push: 7,
|
|
140
|
-
// $unshift ( $unshift: {$value: 123,$maxLen: 10,},)
|
|
141
130
|
// $alias: 'maTestWithAlias',
|
|
142
131
|
// aliases (set
|
|
143
132
|
|
|
144
|
-
// parse
|
|
133
|
+
// parse push and unshift
|
|
145
134
|
|
|
146
135
|
test.serial('collect correctly', async (t) => {
|
|
147
136
|
const results: { path: (string | number)[]; value: any }[] = []
|
|
@@ -159,7 +148,7 @@ test.serial('collect correctly', async (t) => {
|
|
|
159
148
|
$increment: 1,
|
|
160
149
|
},
|
|
161
150
|
bla: false,
|
|
162
|
-
time: now,
|
|
151
|
+
time: now,
|
|
163
152
|
setje: [1, 2, 3],
|
|
164
153
|
form: {
|
|
165
154
|
lastName: 'de beer',
|
|
@@ -204,6 +193,9 @@ test.serial('collect correctly', async (t) => {
|
|
|
204
193
|
value,
|
|
205
194
|
})
|
|
206
195
|
},
|
|
196
|
+
checkRequiredFields: async (path) => {
|
|
197
|
+
return true
|
|
198
|
+
},
|
|
207
199
|
referenceFilterCondition: async (id, filter) => {
|
|
208
200
|
return true
|
|
209
201
|
},
|
|
@@ -215,9 +207,10 @@ test.serial('collect correctly', async (t) => {
|
|
|
215
207
|
{ path: ['blub'], value: { $increment: 1 } },
|
|
216
208
|
{ path: ['time'], value: now },
|
|
217
209
|
{ path: ['form', 'snurp'], value: 'blx12' },
|
|
218
|
-
{
|
|
219
|
-
|
|
220
|
-
|
|
210
|
+
{
|
|
211
|
+
path: ['snurpArray', 0],
|
|
212
|
+
value: 100,
|
|
213
|
+
},
|
|
221
214
|
{ path: ['bla'], value: false },
|
|
222
215
|
{ path: ['form', 'lastName'], value: 'de beer' },
|
|
223
216
|
{ path: ['form', 'json'], value: '{"bla":1,"x":2,"y":3}' },
|
|
@@ -225,24 +218,21 @@ test.serial('collect correctly', async (t) => {
|
|
|
225
218
|
{ path: ['form', 'password'], value: 'mypassword!' },
|
|
226
219
|
{ path: ['form', 'bla'], value: { $value: ['bl123', 'bl234'] } },
|
|
227
220
|
{ path: ['form', 'blab'], value: { $add: ['bl456'] } },
|
|
228
|
-
{
|
|
229
|
-
path: ['snurpArray'],
|
|
230
|
-
value: { $assign: { $idx: 0, $value: 100 } },
|
|
231
|
-
},
|
|
232
221
|
{ path: ['setje'], value: { $value: [1, 2, 3] } },
|
|
233
222
|
{ path: ['form', 'blub'], value: { $value: ['x'] } },
|
|
234
223
|
{
|
|
235
224
|
path: ['specialArray'],
|
|
236
225
|
value: { $insert: { $value: ['a', 'b', 'c'], $idx: 0 } },
|
|
237
226
|
},
|
|
227
|
+
{ path: ['snurp'], value: { $delete: true } },
|
|
228
|
+
{ path: ['snurp', 0, 'x'], value: { $delete: true } },
|
|
229
|
+
{ path: ['snurp', 0, 'x', 0], value: 1 },
|
|
230
|
+
{ path: ['snurp', 0, 'x', 1], value: 2 },
|
|
231
|
+
{ path: ['snurp', 0, 'x', 2], value: 3 },
|
|
238
232
|
]
|
|
239
233
|
|
|
240
|
-
console.log(results)
|
|
241
|
-
|
|
242
234
|
t.deepEqual(results, result)
|
|
243
235
|
|
|
244
|
-
console.info('DID COMPARSION!')
|
|
245
|
-
|
|
246
236
|
const results2: any[] = []
|
|
247
237
|
await setWalker(
|
|
248
238
|
schema,
|
|
@@ -257,18 +247,14 @@ test.serial('collect correctly', async (t) => {
|
|
|
257
247
|
},
|
|
258
248
|
{
|
|
259
249
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
260
|
-
console.dir(
|
|
261
|
-
{
|
|
262
|
-
path,
|
|
263
|
-
value,
|
|
264
|
-
},
|
|
265
|
-
{ depth: 10 }
|
|
266
|
-
)
|
|
267
250
|
results2.push({
|
|
268
251
|
path,
|
|
269
252
|
value,
|
|
270
253
|
})
|
|
271
254
|
},
|
|
255
|
+
checkRequiredFields: async (path) => {
|
|
256
|
+
return false
|
|
257
|
+
},
|
|
272
258
|
referenceFilterCondition: async (id, filter) => {
|
|
273
259
|
return true
|
|
274
260
|
},
|
|
@@ -294,18 +280,14 @@ test.serial('collect correctly', async (t) => {
|
|
|
294
280
|
},
|
|
295
281
|
{
|
|
296
282
|
collect: ({ path, value, typeSchema, fieldSchema, target }) => {
|
|
297
|
-
console.dir(
|
|
298
|
-
{
|
|
299
|
-
path,
|
|
300
|
-
value,
|
|
301
|
-
},
|
|
302
|
-
{ depth: 10 }
|
|
303
|
-
)
|
|
304
283
|
results3.push({
|
|
305
284
|
path,
|
|
306
285
|
value,
|
|
307
286
|
})
|
|
308
287
|
},
|
|
288
|
+
checkRequiredFields: async (path) => {
|
|
289
|
+
return false
|
|
290
|
+
},
|
|
309
291
|
referenceFilterCondition: async (id, filter) => {
|
|
310
292
|
return true
|
|
311
293
|
},
|
|
@@ -317,3 +299,116 @@ test.serial('collect correctly', async (t) => {
|
|
|
317
299
|
{ path: ['specialArray'], value: { $push: [{ $value: 'flap' }] } },
|
|
318
300
|
])
|
|
319
301
|
})
|
|
302
|
+
|
|
303
|
+
test('required', async (t) => {
|
|
304
|
+
const schema: BasedSchema = {
|
|
305
|
+
types: {
|
|
306
|
+
bla: {
|
|
307
|
+
prefix: 'bl',
|
|
308
|
+
required: ['blub', 'flap', 'snurp'],
|
|
309
|
+
fields: {
|
|
310
|
+
blub: {
|
|
311
|
+
type: 'number',
|
|
312
|
+
},
|
|
313
|
+
flap: {
|
|
314
|
+
type: 'number',
|
|
315
|
+
},
|
|
316
|
+
snurp: {
|
|
317
|
+
type: 'object',
|
|
318
|
+
required: ['x'],
|
|
319
|
+
properties: {
|
|
320
|
+
x: {
|
|
321
|
+
type: 'object',
|
|
322
|
+
required: ['a', 'b', 'c'],
|
|
323
|
+
properties: {
|
|
324
|
+
a: { type: 'string' },
|
|
325
|
+
b: { type: 'string' },
|
|
326
|
+
c: { type: 'string' },
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
array: {
|
|
332
|
+
type: 'array',
|
|
333
|
+
values: {
|
|
334
|
+
type: 'object',
|
|
335
|
+
required: ['a', 'b', 'c'],
|
|
336
|
+
properties: {
|
|
337
|
+
a: { type: 'string' },
|
|
338
|
+
b: { type: 'string' },
|
|
339
|
+
c: { type: 'string' },
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
$defs: {},
|
|
347
|
+
languages: ['en'],
|
|
348
|
+
root: {
|
|
349
|
+
fields: {},
|
|
350
|
+
},
|
|
351
|
+
prefixToTypeMapping: {
|
|
352
|
+
bl: 'bla',
|
|
353
|
+
},
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const t1 = await setWalker(
|
|
357
|
+
schema,
|
|
358
|
+
{
|
|
359
|
+
type: 'bla',
|
|
360
|
+
blub: 1,
|
|
361
|
+
flap: 1,
|
|
362
|
+
snurp: {
|
|
363
|
+
x: { a: 'b' },
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
368
|
+
checkRequiredFields: async (paths) => {
|
|
369
|
+
return true
|
|
370
|
+
},
|
|
371
|
+
referenceFilterCondition: async (id, filter) => {
|
|
372
|
+
return true
|
|
373
|
+
},
|
|
374
|
+
}
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
t.deepEqual(t1.required, [
|
|
378
|
+
['snurp', 'x', 'b'],
|
|
379
|
+
['snurp', 'x', 'c'],
|
|
380
|
+
])
|
|
381
|
+
|
|
382
|
+
const t2 = await setWalker(
|
|
383
|
+
schema,
|
|
384
|
+
{
|
|
385
|
+
type: 'bla',
|
|
386
|
+
array: [
|
|
387
|
+
{
|
|
388
|
+
a: 'hello', // say cant set non existing field
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
collect: ({ path, value, typeSchema, fieldSchema, target }) => {},
|
|
394
|
+
checkRequiredFields: async (paths) => {
|
|
395
|
+
// should be [snurp.x.b, snurp.x.c]
|
|
396
|
+
console.log(paths)
|
|
397
|
+
return true
|
|
398
|
+
},
|
|
399
|
+
referenceFilterCondition: async (id, filter) => {
|
|
400
|
+
return true
|
|
401
|
+
},
|
|
402
|
+
}
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
t.deepEqual(t2.required, [
|
|
406
|
+
['array', 0, 'b'],
|
|
407
|
+
['array', 0, 'c'],
|
|
408
|
+
['blub'],
|
|
409
|
+
['flap'],
|
|
410
|
+
['snurp'],
|
|
411
|
+
])
|
|
412
|
+
|
|
413
|
+
t.true(true)
|
|
414
|
+
})
|