@based/schema 0.0.6 → 0.0.7
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/deepPartial.d.ts +0 -0
- package/dist/deepPartial.js +3 -0
- package/dist/deepPartial.js.map +1 -0
- package/dist/set/collections.js +37 -53
- package/dist/set/collections.js.map +1 -1
- package/dist/set/enum.d.ts +2 -0
- package/dist/set/enum.js +15 -0
- package/dist/set/enum.js.map +1 -0
- package/dist/set/fieldValidator.d.ts +6 -0
- package/dist/set/fieldValidator.js +144 -0
- package/dist/set/fieldValidator.js.map +1 -0
- package/dist/set/handleError.d.ts +1 -0
- package/dist/set/handleError.js +9 -0
- package/dist/set/handleError.js.map +1 -0
- package/dist/set/index.d.ts +1 -1
- package/dist/set/index.js +5 -3
- package/dist/set/index.js.map +1 -1
- package/dist/set/number copy.d.ts +4 -0
- package/dist/set/number copy.js +57 -0
- package/dist/set/number copy.js.map +1 -0
- package/dist/set/number.js +72 -31
- package/dist/set/number.js.map +1 -1
- package/dist/set/references.js +10 -14
- package/dist/set/references.js.map +1 -1
- package/dist/set/rest copy.d.ts +5 -0
- package/dist/set/rest copy.js +53 -0
- package/dist/set/rest copy.js.map +1 -0
- package/dist/set/rest.js +18 -14
- package/dist/set/rest.js.map +1 -1
- package/dist/set/string.js +34 -21
- package/dist/set/string.js.map +1 -1
- package/dist/set/types.d.ts +1 -1
- package/dist/setWalker.d.ts +11 -0
- package/dist/setWalker.js +189 -0
- package/dist/setWalker.js.map +1 -0
- package/dist/transformers.d.ts +3 -0
- package/dist/transformers.js +18 -0
- package/dist/transformers.js.map +1 -0
- package/dist/typeWalker.d.ts +3 -0
- package/dist/typeWalker.js +18 -0
- package/dist/typeWalker.js.map +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +34 -0
- package/dist/validate.js.map +1 -0
- package/dist/validateFields.d.ts +4 -0
- package/dist/validateFields.js +34 -0
- package/dist/validateFields.js.map +1 -0
- package/dist/validateSchema copy.d.ts +4 -0
- package/dist/validateSchema copy.js +34 -0
- package/dist/validateSchema copy.js.map +1 -0
- package/package.json +1 -1
- package/src/set/collections.ts +51 -82
- package/src/set/index.ts +6 -3
- package/src/set/number.ts +93 -35
- package/src/set/references.ts +14 -14
- package/src/set/rest.ts +21 -14
- package/src/set/string.ts +48 -23
- package/src/set/types.ts +2 -1
- package/test/setWalker.ts +7 -0
- package/dist/parse.d.ts +0 -2
- package/dist/parse.js +0 -9
- package/dist/parse.js.map +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setWalker = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const utils_1 = require("@saulx/utils");
|
|
6
|
+
// collect is a pretty good place for checking if a user is allowed to set something
|
|
7
|
+
// also make collect async
|
|
8
|
+
const fieldWalker = (path, value, fieldSchema, typeSchema, target, collect) => {
|
|
9
|
+
if ('$ref' in fieldSchema) {
|
|
10
|
+
// TODO: when we have this it has to get it from the schema and redo the parsing with the correct fieldSchema
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const valueType = typeof value;
|
|
14
|
+
const valueIsObject = value && valueType === 'object';
|
|
15
|
+
if (valueIsObject && value.$delete === true) {
|
|
16
|
+
collect(path, value, typeSchema, fieldSchema, target);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if ('enum' in fieldSchema) {
|
|
20
|
+
const enumValues = fieldSchema.enum;
|
|
21
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
22
|
+
if ((0, utils_1.deepEqual)(enumValues[i], value)) {
|
|
23
|
+
collect(path, i, typeSchema, fieldSchema, target);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Type: "${target.type}" Field: "${path.join('.')}" is not a valid value for enum`);
|
|
28
|
+
}
|
|
29
|
+
if ('type' in fieldSchema && (0, types_1.isCollection)(fieldSchema.type)) {
|
|
30
|
+
const typeDef = fieldSchema.type;
|
|
31
|
+
const isArray = Array.isArray(value);
|
|
32
|
+
if (typeDef === 'array') {
|
|
33
|
+
if (!isArray) {
|
|
34
|
+
throw new Error(`Type: "${target.type}" Field: "${path.join('.')}" is not of type "array"`);
|
|
35
|
+
}
|
|
36
|
+
for (let i = 0; i < value.length; i++) {
|
|
37
|
+
fieldWalker([...path, i], value[i],
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
fieldSchema.values, typeSchema, target, collect);
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
else if (isArray) {
|
|
44
|
+
throw new Error(`Type: "${target.type}" Field: "${path.join('.')}" is not of type "${typeDef}"`);
|
|
45
|
+
}
|
|
46
|
+
if (valueType !== 'object') {
|
|
47
|
+
throw new Error(`Type: "${target.type}" Field: "${path.join('.')}" is not of type "${typeDef}"`);
|
|
48
|
+
}
|
|
49
|
+
for (const key in value) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
const propDef = fieldSchema.properties[key];
|
|
52
|
+
if (!propDef) {
|
|
53
|
+
throw new Error(`Field does not exist in schema "${[...path, key].join('.')}" on type "${target.type}"`);
|
|
54
|
+
}
|
|
55
|
+
fieldWalker([...path, key], value[key], propDef, typeSchema, target, collect);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if ('type' in fieldSchema) {
|
|
60
|
+
const typeDef = fieldSchema.type;
|
|
61
|
+
if (typeDef === 'set') {
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
const parsedArray = [];
|
|
64
|
+
const fieldDef = fieldSchema.items;
|
|
65
|
+
for (let i = 0; i < value.length; i++) {
|
|
66
|
+
fieldWalker([...path, i], value[i], fieldDef, typeSchema, target, (path, value) => {
|
|
67
|
+
parsedArray.push(value);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
collect(path, parsedArray, typeSchema, fieldSchema, target);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// TODO PARSE IF VALID
|
|
74
|
+
// $add / $remove
|
|
75
|
+
collect(path, value, typeSchema, fieldSchema, target);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeDef === 'json') {
|
|
80
|
+
try {
|
|
81
|
+
const parsedValue = JSON.stringify(value);
|
|
82
|
+
collect(path, parsedValue, typeSchema, fieldSchema, target);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
throw new Error(`${value} cannot be parsed to json "${path.join('.')}" on type "${target.type}"`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if ((typeDef === 'number' || typeDef === 'integer') &&
|
|
90
|
+
valueType !== 'number') {
|
|
91
|
+
throw new Error(`${value} is not a number "${path.join('.')}" on type "${target.type}"`);
|
|
92
|
+
}
|
|
93
|
+
if (typeDef === 'integer' && value - Math.floor(value) !== 0) {
|
|
94
|
+
throw new Error(`${value} is not an integer "${path.join('.')}" on type "${target.type}"`);
|
|
95
|
+
}
|
|
96
|
+
if (typeDef === 'string') {
|
|
97
|
+
if (valueType !== 'string') {
|
|
98
|
+
throw new Error(`${value} is not a string "${path.join('.')}" on type "${target.type}"`);
|
|
99
|
+
}
|
|
100
|
+
if (fieldSchema.minLength && value.length < fieldSchema.minLength) {
|
|
101
|
+
throw new Error(`${value} is smaller then minLength "${fieldSchema.minLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
102
|
+
}
|
|
103
|
+
if (fieldSchema.maxLength && value.length > fieldSchema.maxLength) {
|
|
104
|
+
throw new Error(`${value} is larger then maxLength "${fieldSchema.maxLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (typeDef === 'text') {
|
|
108
|
+
if (target.$language && valueType === 'string') {
|
|
109
|
+
if (fieldSchema.minLength && value.length < fieldSchema.minLength) {
|
|
110
|
+
throw new Error(`${value} is smaller then minLength "${fieldSchema.minLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
111
|
+
}
|
|
112
|
+
if (fieldSchema.maxLength && value.length > fieldSchema.maxLength) {
|
|
113
|
+
throw new Error(`${value} is larger then maxLength "${fieldSchema.maxLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
114
|
+
}
|
|
115
|
+
collect(path, { [target.$language]: value }, typeSchema, fieldSchema, target);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (valueType !== 'object') {
|
|
119
|
+
throw new Error(`${value} is not a language object "${path.join('.')}" on type "${target.type}"`);
|
|
120
|
+
}
|
|
121
|
+
for (const key in value) {
|
|
122
|
+
if (fieldSchema.minLength &&
|
|
123
|
+
value[key].length < fieldSchema.minLength) {
|
|
124
|
+
throw new Error(`${value[key]} is smaller then minLength "${fieldSchema.minLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
125
|
+
}
|
|
126
|
+
if (fieldSchema.maxLength &&
|
|
127
|
+
value[key].length > fieldSchema.maxLength) {
|
|
128
|
+
throw new Error(`${value[key]} is larger then maxLength "${fieldSchema.maxLength}" "${path.join('.')}" on type "${target.type}"`);
|
|
129
|
+
}
|
|
130
|
+
if (typeof value[key] === 'object' && value[key].$delete === true) {
|
|
131
|
+
collect([...path, key], null, typeSchema, fieldSchema, target);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (typeof value[key] !== 'string') {
|
|
135
|
+
throw new Error(`${value} is not a string "${[...path, key].join('.')}" on type "${target.type}"`);
|
|
136
|
+
}
|
|
137
|
+
collect([...path, key], value[key], typeSchema, fieldSchema, target);
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
collect(path, value, typeSchema, fieldSchema, target);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const setWalker = (schema, value, collect) => {
|
|
146
|
+
let type;
|
|
147
|
+
if (value.$id) {
|
|
148
|
+
type = schema.prefixToTypeMapping[value.$id.slice(0, 2)];
|
|
149
|
+
if (!type) {
|
|
150
|
+
throw new Error(`Cannot find type for $id ${value.$id}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (value.type) {
|
|
154
|
+
if (type && value.type !== type) {
|
|
155
|
+
throw new Error(`type from "$id" ${value.$id} does not match "type" field ${value.type}`);
|
|
156
|
+
}
|
|
157
|
+
type = value.type;
|
|
158
|
+
}
|
|
159
|
+
const schemaType = schema.types[type];
|
|
160
|
+
if (!schemaType) {
|
|
161
|
+
throw new Error(`Cannot find schema definition for type ${type}`);
|
|
162
|
+
}
|
|
163
|
+
const target = {
|
|
164
|
+
type,
|
|
165
|
+
};
|
|
166
|
+
if (value.$id) {
|
|
167
|
+
target.$id = value.$id;
|
|
168
|
+
}
|
|
169
|
+
else if (value.$alias) {
|
|
170
|
+
target.$alias = value.$alias;
|
|
171
|
+
}
|
|
172
|
+
for (const key in value) {
|
|
173
|
+
if (key[0] === '$') {
|
|
174
|
+
console.info('key is operator', key);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const fieldSchema = schemaType.fields[key];
|
|
178
|
+
if (!fieldSchema) {
|
|
179
|
+
throw new Error(`Field does not exist in schema "${key}" on type "${type}"`);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
fieldWalker([key], value[key], fieldSchema, schemaType, target, collect);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return target;
|
|
187
|
+
};
|
|
188
|
+
exports.setWalker = setWalker;
|
|
189
|
+
//# sourceMappingURL=setWalker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setWalker.js","sourceRoot":"","sources":["../src/setWalker.ts"],"names":[],"mappings":";;;AAAA,mCAMgB;AAChB,wCAAwC;AAExC,oFAAoF;AACpF,0BAA0B;AAE1B,MAAM,WAAW,GAAG,CAClB,IAAyB,EACzB,KAAU,EACV,WAA6B,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,KAAK,CACb,mBAAmB,KAAK,CAAC,GAAG,gCAAgC,KAAK,CAAC,IAAI,EAAE,CACzE,CAAA;SACF;QACD,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;KAClB;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAErC,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAA;KAClE;IAED,MAAM,MAAM,GAAW;QACrB,IAAI;KACL,CAAA;IAED,IAAI,KAAK,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;KACvB;SAAM,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;KAC7B;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YAClB,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;SACrC;aAAM;YACL,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC1C,IAAI,CAAC,WAAW,EAAE;gBAChB,MAAM,IAAI,KAAK,CACb,mCAAmC,GAAG,cAAc,IAAI,GAAG,CAC5D,CAAA;aACF;iBAAM;gBACL,WAAW,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;aACzE;SACF;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AA7DY,QAAA,SAAS,aA6DrB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaTypePartial } from './types';
|
|
2
|
+
export declare const transformField: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const transformType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformType = exports.transformField = void 0;
|
|
4
|
+
const transformField = (fromSchema, typeName, type) => {
|
|
5
|
+
if (type.prefix &&
|
|
6
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
7
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
exports.transformField = transformField;
|
|
11
|
+
const transformType = (fromSchema, typeName, type) => {
|
|
12
|
+
if (type.prefix &&
|
|
13
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
14
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.transformType = transformType;
|
|
18
|
+
//# sourceMappingURL=transformers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"","sources":["../src/transformers.ts"],"names":[],"mappings":";;;AAOO,MAAM,cAAc,GAAG,CAC5B,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,cAAc,kBAa1B;AAEM,MAAM,aAAa,GAAG,CAC3B,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,aAAa,iBAazB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaTypePartial } from './types';
|
|
2
|
+
export declare const transformField: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const transformType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformType = exports.transformField = void 0;
|
|
4
|
+
const transformField = (fromSchema, typeName, type) => {
|
|
5
|
+
if (type.prefix &&
|
|
6
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
7
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
exports.transformField = transformField;
|
|
11
|
+
const transformType = (fromSchema, typeName, type) => {
|
|
12
|
+
if (type.prefix &&
|
|
13
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
14
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.transformType = transformType;
|
|
18
|
+
//# sourceMappingURL=typeWalker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeWalker.js","sourceRoot":"","sources":["../src/typeWalker.ts"],"names":[],"mappings":";;;AAOO,MAAM,cAAc,GAAG,CAC5B,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,cAAc,kBAa1B;AAEM,MAAM,aAAa,GAAG,CAC3B,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,aAAa,iBAazB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaFieldPartial, BasedSchemaTypePartial } from './types';
|
|
2
|
+
export declare const parseType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const parseField: (fromSchema: BasedSchemaPartial, path: string[], field: BasedSchemaFieldPartial) => void;
|
|
4
|
+
export declare const validateSchema: (schema: BasedSchemaPartial) => BasedSchemaPartial;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSchema = exports.parseField = exports.parseType = void 0;
|
|
4
|
+
const parseType = (fromSchema, typeName, type) => {
|
|
5
|
+
if (type.prefix &&
|
|
6
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
7
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
exports.parseType = parseType;
|
|
11
|
+
const parseField = (fromSchema, path, field) => { };
|
|
12
|
+
exports.parseField = parseField;
|
|
13
|
+
const validateSchema = (schema) => {
|
|
14
|
+
// rewrite schema things like required / required: []
|
|
15
|
+
if (typeof schema !== 'object') {
|
|
16
|
+
throw new Error('Schema is not an object');
|
|
17
|
+
}
|
|
18
|
+
if (schema.languages && !Array.isArray(schema.languages)) {
|
|
19
|
+
throw new Error('Languages needs to be an array');
|
|
20
|
+
}
|
|
21
|
+
if (schema.$defs) {
|
|
22
|
+
// first defs ofc
|
|
23
|
+
}
|
|
24
|
+
if (schema.root) {
|
|
25
|
+
}
|
|
26
|
+
if (schema.types) {
|
|
27
|
+
for (const type in schema.types) {
|
|
28
|
+
(0, exports.parseType)(schema, type, schema.types[type]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return schema;
|
|
32
|
+
};
|
|
33
|
+
exports.validateSchema = validateSchema;
|
|
34
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":";;;AAOO,MAAM,SAAS,GAAG,CACvB,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,SAAS,aAarB;AAEM,MAAM,UAAU,GAAG,CACxB,UAA8B,EAC9B,IAAc,EACd,KAA8B,EAC9B,EAAE,GAAE,CAAC,CAAA;AAJM,QAAA,UAAU,cAIhB;AAEA,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;KAChB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;YAC/B,IAAA,iBAAS,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;SAC5C;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AA3BY,QAAA,cAAc,kBA2B1B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaFieldPartial, BasedSchemaTypePartial } from './types';
|
|
2
|
+
export declare const parseType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const parseField: (fromSchema: BasedSchemaPartial, path: string[], field: BasedSchemaFieldPartial) => void;
|
|
4
|
+
export declare const validateSchema: (schema: BasedSchemaPartial) => BasedSchemaPartial;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSchema = exports.parseField = exports.parseType = void 0;
|
|
4
|
+
const parseType = (fromSchema, typeName, type) => {
|
|
5
|
+
if (type.prefix &&
|
|
6
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
7
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
exports.parseType = parseType;
|
|
11
|
+
const parseField = (fromSchema, path, field) => { };
|
|
12
|
+
exports.parseField = parseField;
|
|
13
|
+
const validateSchema = (schema) => {
|
|
14
|
+
// rewrite schema things like required / required: []
|
|
15
|
+
if (typeof schema !== 'object') {
|
|
16
|
+
throw new Error('Schema is not an object');
|
|
17
|
+
}
|
|
18
|
+
if (schema.languages && !Array.isArray(schema.languages)) {
|
|
19
|
+
throw new Error('Languages needs to be an array');
|
|
20
|
+
}
|
|
21
|
+
if (schema.$defs) {
|
|
22
|
+
// first defs ofc
|
|
23
|
+
}
|
|
24
|
+
if (schema.root) {
|
|
25
|
+
}
|
|
26
|
+
if (schema.types) {
|
|
27
|
+
for (const type in schema.types) {
|
|
28
|
+
(0, exports.parseType)(schema, type, schema.types[type]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return schema;
|
|
32
|
+
};
|
|
33
|
+
exports.validateSchema = validateSchema;
|
|
34
|
+
//# sourceMappingURL=validateFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateFields.js","sourceRoot":"","sources":["../src/validateFields.ts"],"names":[],"mappings":";;;AAOO,MAAM,SAAS,GAAG,CACvB,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,SAAS,aAarB;AAEM,MAAM,UAAU,GAAG,CACxB,UAA8B,EAC9B,IAAc,EACd,KAA8B,EAC9B,EAAE,GAAE,CAAC,CAAA;AAJM,QAAA,UAAU,cAIhB;AAEA,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;KAChB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE;YAC/B,IAAA,iBAAS,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;SAC5C;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AA3BY,QAAA,cAAc,kBA2B1B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaFieldPartial, BasedSchemaTypePartial } from './types';
|
|
2
|
+
export declare const parseType: (fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const parseField: (fromSchema: BasedSchemaPartial, path: string[], field: BasedSchemaFieldPartial) => void;
|
|
4
|
+
export declare const validateSchema: (schema: BasedSchemaPartial) => BasedSchemaPartial;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSchema = exports.parseField = exports.parseType = void 0;
|
|
4
|
+
const parseType = (fromSchema, typeName, type) => {
|
|
5
|
+
if (type.prefix &&
|
|
6
|
+
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
7
|
+
throw new Error(`Incorrect prefix "${type.prefix}" for type "${typeName}" has to be a string of 2 alphanumerical characters e.g. "Az", "ab", "cc", "10"`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
exports.parseType = parseType;
|
|
11
|
+
const parseField = (fromSchema, path, field) => { };
|
|
12
|
+
exports.parseField = parseField;
|
|
13
|
+
const validateSchema = (schema) => {
|
|
14
|
+
// rewrite schema things like required / required: []
|
|
15
|
+
if (typeof schema !== 'object') {
|
|
16
|
+
throw new Error('Schema is not an object');
|
|
17
|
+
}
|
|
18
|
+
if (schema.languages && !Array.isArray(schema.languages)) {
|
|
19
|
+
throw new Error('Languages needs to be an array');
|
|
20
|
+
}
|
|
21
|
+
if (schema.$defs) {
|
|
22
|
+
// first defs ofc
|
|
23
|
+
}
|
|
24
|
+
if (schema.root) {
|
|
25
|
+
}
|
|
26
|
+
if (schema.types) {
|
|
27
|
+
for (const type in schema.types) {
|
|
28
|
+
(0, exports.parseType)(schema, type, schema.types[type]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return schema;
|
|
32
|
+
};
|
|
33
|
+
exports.validateSchema = validateSchema;
|
|
34
|
+
//# sourceMappingURL=validateSchema%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSchema copy.js","sourceRoot":"","sources":["../src/validateSchema copy.ts"],"names":[],"mappings":";;;AAOO,MAAM,SAAS,GAA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,
|
|
9
9
|
typeSchema,
|
|
10
10
|
target,
|
|
11
|
-
handlers
|
|
11
|
+
handlers,
|
|
12
|
+
noCollect
|
|
12
13
|
) => {
|
|
13
14
|
const q: Promise<void>[] = []
|
|
14
15
|
const fieldDef = fieldSchema.items
|
|
15
16
|
if (Array.isArray(value)) {
|
|
16
|
-
const handlerNest = {
|
|
17
|
-
...handlers,
|
|
18
|
-
collect: ({ value }) => {
|
|
19
|
-
parsedArray.push(value)
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
17
|
const parsedArray = []
|
|
23
18
|
for (let i = 0; i < value.length; i++) {
|
|
24
19
|
q.push(
|
|
25
|
-
fieldWalker(
|
|
26
|
-
|
|
27
|
-
value
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
handlerNest
|
|
32
|
-
)
|
|
20
|
+
fieldWalker([...path, i], value[i], fieldDef, typeSchema, target, {
|
|
21
|
+
...handlers,
|
|
22
|
+
collect: ({ value }) => {
|
|
23
|
+
parsedArray.push(value)
|
|
24
|
+
},
|
|
25
|
+
})
|
|
33
26
|
)
|
|
34
27
|
}
|
|
35
28
|
await Promise.all(q)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const handlerNest = {
|
|
45
|
-
...handlers,
|
|
46
|
-
collect: () => {},
|
|
29
|
+
if (!noCollect) {
|
|
30
|
+
handlers.collect({
|
|
31
|
+
path,
|
|
32
|
+
value: { $value: parsedArray },
|
|
33
|
+
typeSchema,
|
|
34
|
+
fieldSchema,
|
|
35
|
+
target,
|
|
36
|
+
})
|
|
47
37
|
}
|
|
38
|
+
} else {
|
|
48
39
|
if (value.$add) {
|
|
49
40
|
for (let i = 0; i < value.$add.length; i++) {
|
|
50
41
|
q.push(
|
|
@@ -54,7 +45,8 @@ export const set: Parser<'set'> = async (
|
|
|
54
45
|
fieldDef,
|
|
55
46
|
typeSchema,
|
|
56
47
|
target,
|
|
57
|
-
|
|
48
|
+
handlers,
|
|
49
|
+
true
|
|
58
50
|
)
|
|
59
51
|
)
|
|
60
52
|
}
|
|
@@ -68,13 +60,16 @@ export const set: Parser<'set'> = async (
|
|
|
68
60
|
fieldDef,
|
|
69
61
|
typeSchema,
|
|
70
62
|
target,
|
|
71
|
-
|
|
63
|
+
handlers,
|
|
64
|
+
true
|
|
72
65
|
)
|
|
73
66
|
)
|
|
74
67
|
}
|
|
75
68
|
}
|
|
76
69
|
await Promise.all(q)
|
|
77
|
-
|
|
70
|
+
if (!noCollect) {
|
|
71
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
72
|
+
}
|
|
78
73
|
}
|
|
79
74
|
}
|
|
80
75
|
|
|
@@ -84,7 +79,8 @@ export const object: Parser<'object'> = async (
|
|
|
84
79
|
fieldSchema,
|
|
85
80
|
typeSchema,
|
|
86
81
|
target,
|
|
87
|
-
handlers
|
|
82
|
+
handlers,
|
|
83
|
+
noCollect
|
|
88
84
|
) => {
|
|
89
85
|
if (typeof value !== 'object') {
|
|
90
86
|
error(path, ParseError.incorrectFormat)
|
|
@@ -106,7 +102,8 @@ export const object: Parser<'object'> = async (
|
|
|
106
102
|
propDef,
|
|
107
103
|
typeSchema,
|
|
108
104
|
target,
|
|
109
|
-
handlers
|
|
105
|
+
handlers,
|
|
106
|
+
noCollect
|
|
110
107
|
)
|
|
111
108
|
)
|
|
112
109
|
}
|
|
@@ -119,7 +116,8 @@ export const array: Parser<'array'> = async (
|
|
|
119
116
|
fieldSchema,
|
|
120
117
|
typeSchema,
|
|
121
118
|
target,
|
|
122
|
-
handlers
|
|
119
|
+
handlers,
|
|
120
|
+
noCollect
|
|
123
121
|
) => {
|
|
124
122
|
const isArray = Array.isArray(value)
|
|
125
123
|
if (typeof value === 'object' && !isArray) {
|
|
@@ -130,33 +128,20 @@ export const array: Parser<'array'> = async (
|
|
|
130
128
|
) {
|
|
131
129
|
error([...path, '$insert'], ParseError.incorrectFormat)
|
|
132
130
|
} else {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
131
|
+
const insert = Array.isArray(value.$insert.$value)
|
|
132
|
+
? value.$insert.$value
|
|
133
|
+
: [value.$insert.$value]
|
|
137
134
|
const q: Promise<void>[] = []
|
|
138
|
-
|
|
139
|
-
for (let i = 0; i < value.$insert.$value.length; i++) {
|
|
140
|
-
q.push(
|
|
141
|
-
fieldWalker(
|
|
142
|
-
[...path, 'insert', i],
|
|
143
|
-
value.$insert.$value[i],
|
|
144
|
-
fieldSchema.values,
|
|
145
|
-
typeSchema,
|
|
146
|
-
target,
|
|
147
|
-
nestedHandler
|
|
148
|
-
)
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
135
|
+
for (let i = 0; i < insert.length; i++) {
|
|
152
136
|
q.push(
|
|
153
137
|
fieldWalker(
|
|
154
|
-
[...path, '
|
|
155
|
-
|
|
138
|
+
[...path, 'insert', i],
|
|
139
|
+
insert[i],
|
|
156
140
|
fieldSchema.values,
|
|
157
141
|
typeSchema,
|
|
158
142
|
target,
|
|
159
|
-
|
|
143
|
+
handlers,
|
|
144
|
+
true
|
|
160
145
|
)
|
|
161
146
|
)
|
|
162
147
|
}
|
|
@@ -168,32 +153,17 @@ export const array: Parser<'array'> = async (
|
|
|
168
153
|
}
|
|
169
154
|
if (value.$push) {
|
|
170
155
|
const q: Promise<void>[] = []
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
collect: () => {},
|
|
174
|
-
}
|
|
175
|
-
if (Array.isArray(value.$push)) {
|
|
176
|
-
for (let i = 0; i < value.$push.length; i++) {
|
|
177
|
-
q.push(
|
|
178
|
-
fieldWalker(
|
|
179
|
-
[...path, i],
|
|
180
|
-
value.$push[i],
|
|
181
|
-
fieldSchema.values,
|
|
182
|
-
typeSchema,
|
|
183
|
-
target,
|
|
184
|
-
nestedHandler
|
|
185
|
-
)
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
156
|
+
const push = Array.isArray(value.$push) ? value.$push : [value.$push]
|
|
157
|
+
for (let i = 0; i < push.length; i++) {
|
|
189
158
|
q.push(
|
|
190
159
|
fieldWalker(
|
|
191
|
-
[...path,
|
|
192
|
-
|
|
160
|
+
[...path, i],
|
|
161
|
+
push[i],
|
|
193
162
|
fieldSchema.values,
|
|
194
163
|
typeSchema,
|
|
195
164
|
target,
|
|
196
|
-
|
|
165
|
+
handlers,
|
|
166
|
+
true
|
|
197
167
|
)
|
|
198
168
|
)
|
|
199
169
|
}
|
|
@@ -212,21 +182,19 @@ export const array: Parser<'array'> = async (
|
|
|
212
182
|
fieldSchema.values,
|
|
213
183
|
typeSchema,
|
|
214
184
|
target,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
collect: () => {},
|
|
218
|
-
}
|
|
185
|
+
handlers,
|
|
186
|
+
true
|
|
219
187
|
)
|
|
220
188
|
}
|
|
221
189
|
}
|
|
222
|
-
|
|
190
|
+
if (!noCollect) {
|
|
191
|
+
handlers.collect({ path, value, typeSchema, fieldSchema, target })
|
|
192
|
+
}
|
|
223
193
|
return
|
|
224
194
|
}
|
|
225
|
-
|
|
226
195
|
if (!isArray) {
|
|
227
196
|
error(path, ParseError.incorrectFieldType)
|
|
228
197
|
}
|
|
229
|
-
|
|
230
198
|
const q: Promise<void>[] = []
|
|
231
199
|
for (let i = 0; i < value.length; i++) {
|
|
232
200
|
q.push(
|
|
@@ -236,7 +204,8 @@ export const array: Parser<'array'> = async (
|
|
|
236
204
|
fieldSchema.values,
|
|
237
205
|
typeSchema,
|
|
238
206
|
target,
|
|
239
|
-
handlers
|
|
207
|
+
handlers,
|
|
208
|
+
noCollect
|
|
240
209
|
)
|
|
241
210
|
)
|
|
242
211
|
}
|