@based/schema 4.1.1 → 5.0.0-alpha.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/README.md +152 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lang.d.ts +153 -0
- package/dist/lang.js +153 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +24 -0
- package/dist/parse/assert.d.ts +2 -1
- package/dist/parse/assert.js +9 -3
- package/dist/parse/errors.d.ts +2 -0
- package/dist/parse/errors.js +2 -0
- package/dist/parse/index.d.ts +5 -4
- package/dist/parse/index.js +43 -41
- package/dist/parse/props.js +168 -75
- package/dist/parse/utils.d.ts +2 -2
- package/dist/parse/utils.js +11 -2
- package/dist/types.d.ts +72 -23
- package/dist/types.js +93 -0
- package/package.json +4 -3
- package/dist/parsePayload/index.d.ts +0 -3
- package/dist/parsePayload/index.js +0 -2
- package/dist/parseSchema/assert.d.ts +0 -6
- package/dist/parseSchema/assert.js +0 -27
- package/dist/parseSchema/errors.d.ts +0 -19
- package/dist/parseSchema/errors.js +0 -19
- package/dist/parseSchema/index.d.ts +0 -20
- package/dist/parseSchema/index.js +0 -132
- package/dist/parseSchema/props.d.ts +0 -7
- package/dist/parseSchema/props.js +0 -256
- package/dist/parseSchema/utils.d.ts +0 -3
- package/dist/parseSchema/utils.js +0 -29
- package/dist/src/compat/index.d.ts +0 -6
- package/dist/src/compat/index.js +0 -217
- package/dist/src/compat/oldSchemaType.d.ts +0 -93
- package/dist/src/compat/oldSchemaType.js +0 -2
- package/dist/src/display/index.d.ts +0 -2
- package/dist/src/display/index.js +0 -16
- package/dist/src/display/number.d.ts +0 -4
- package/dist/src/display/number.js +0 -97
- package/dist/src/display/string.d.ts +0 -5
- package/dist/src/display/string.js +0 -26
- package/dist/src/display/timestamp.d.ts +0 -5
- package/dist/src/display/timestamp.js +0 -134
- package/dist/src/error.d.ts +0 -21
- package/dist/src/error.js +0 -23
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -7
- package/dist/src/languages.d.ts +0 -188
- package/dist/src/languages.js +0 -188
- package/dist/src/set/fields/array.d.ts +0 -2
- package/dist/src/set/fields/array.js +0 -119
- package/dist/src/set/fields/index.d.ts +0 -3
- package/dist/src/set/fields/index.js +0 -85
- package/dist/src/set/fields/number.d.ts +0 -4
- package/dist/src/set/fields/number.js +0 -123
- package/dist/src/set/fields/object.d.ts +0 -3
- package/dist/src/set/fields/object.js +0 -28
- package/dist/src/set/fields/references.d.ts +0 -3
- package/dist/src/set/fields/references.js +0 -136
- package/dist/src/set/fields/set.d.ts +0 -2
- package/dist/src/set/fields/set.js +0 -59
- package/dist/src/set/fields/string.d.ts +0 -3
- package/dist/src/set/fields/string.js +0 -289
- package/dist/src/set/index.d.ts +0 -3
- package/dist/src/set/index.js +0 -205
- package/dist/src/set/isValidId.d.ts +0 -2
- package/dist/src/set/isValidId.js +0 -17
- package/dist/src/types.d.ts +0 -205
- package/dist/src/types.js +0 -113
- package/dist/src/updateSchema.d.ts +0 -2
- package/dist/src/updateSchema.js +0 -12
- package/dist/src/validateSchema/basedSchemaTypeValidator.d.ts +0 -3
- package/dist/src/validateSchema/basedSchemaTypeValidator.js +0 -45
- package/dist/src/validateSchema/fieldValidators.d.ts +0 -27
- package/dist/src/validateSchema/fieldValidators.js +0 -360
- package/dist/src/validateSchema/index.d.ts +0 -17
- package/dist/src/validateSchema/index.js +0 -109
- package/dist/src/validateSchema/utils.d.ts +0 -25
- package/dist/src/validateSchema/utils.js +0 -61
- package/dist/src/walker/args.d.ts +0 -36
- package/dist/src/walker/args.js +0 -158
- package/dist/src/walker/index.d.ts +0 -6
- package/dist/src/walker/index.js +0 -31
- package/dist/src/walker/parse.d.ts +0 -3
- package/dist/src/walker/parse.js +0 -182
- package/dist/src/walker/types.d.ts +0 -45
- package/dist/src/walker/types.js +0 -7
- package/dist/test/array.d.ts +0 -1
- package/dist/test/array.js +0 -342
- package/dist/test/compat.d.ts +0 -1
- package/dist/test/compat.js +0 -97
- package/dist/test/data/newSchemas.d.ts +0 -2
- package/dist/test/data/newSchemas.js +0 -489
- package/dist/test/data/oldSchemas.d.ts +0 -2
- package/dist/test/data/oldSchemas.js +0 -5058
- package/dist/test/display.d.ts +0 -1
- package/dist/test/display.js +0 -103
- package/dist/test/json.d.ts +0 -1
- package/dist/test/json.js +0 -40
- package/dist/test/number.d.ts +0 -1
- package/dist/test/number.js +0 -374
- package/dist/test/reference.d.ts +0 -1
- package/dist/test/reference.js +0 -188
- package/dist/test/rest.d.ts +0 -1
- package/dist/test/rest.js +0 -168
- package/dist/test/set.d.ts +0 -1
- package/dist/test/set.js +0 -95
- package/dist/test/string.d.ts +0 -1
- package/dist/test/string.js +0 -120
- package/dist/test/text.d.ts +0 -1
- package/dist/test/text.js +0 -324
- package/dist/test/utils/index.d.ts +0 -11
- package/dist/test/utils/index.js +0 -17
- package/dist/test/validateSchema/basic.d.ts +0 -1
- package/dist/test/validateSchema/basic.js +0 -94
- package/dist/test/validateSchema/fields.d.ts +0 -1
- package/dist/test/validateSchema/fields.js +0 -436
- package/dist/test/validateSchema/languages.d.ts +0 -1
- package/dist/test/validateSchema/languages.js +0 -124
- package/dist/test/validateSchema/realWorld.d.ts +0 -1
- package/dist/test/validateSchema/realWorld.js +0 -13
- package/dist/test/walker.d.ts +0 -1
- package/dist/test/walker.js +0 -289
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ParseError } from '../../error.js';
|
|
2
|
-
async function parseOperator(args, key) {
|
|
3
|
-
if (Array.isArray(args.value[key])) {
|
|
4
|
-
const n = args.create({
|
|
5
|
-
key,
|
|
6
|
-
skipCollection: true,
|
|
7
|
-
value: args.value[key],
|
|
8
|
-
});
|
|
9
|
-
await n.parse();
|
|
10
|
-
if (n.value?.$value) {
|
|
11
|
-
return n.value.$value;
|
|
12
|
-
}
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const n = args.create({
|
|
16
|
-
key,
|
|
17
|
-
skipCollection: true,
|
|
18
|
-
value: args.value[key],
|
|
19
|
-
fieldSchema: args.fieldSchema.items,
|
|
20
|
-
});
|
|
21
|
-
await n.parse();
|
|
22
|
-
return [n.value];
|
|
23
|
-
}
|
|
24
|
-
export const set = async (args) => {
|
|
25
|
-
if (typeof args.value !== 'object' || args.value === null) {
|
|
26
|
-
args.error(ParseError.incorrectFormat);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
args.stop();
|
|
30
|
-
const isArray = Array.isArray(args.value);
|
|
31
|
-
if (isArray) {
|
|
32
|
-
const newArgs = [];
|
|
33
|
-
for (let i = 0; i < args.value.length; i++) {
|
|
34
|
-
newArgs.push(args.create({
|
|
35
|
-
key: i,
|
|
36
|
-
value: args.value[i],
|
|
37
|
-
fieldSchema: args.fieldSchema.items,
|
|
38
|
-
skipCollection: true,
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
await Promise.all(newArgs.map((args) => args.parse()));
|
|
42
|
-
args.value = { $value: newArgs.map((args) => args.value) };
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
for (const key in args.value) {
|
|
46
|
-
if (key === '$add') {
|
|
47
|
-
args.value.$add = await parseOperator(args, key);
|
|
48
|
-
}
|
|
49
|
-
else if (key === '$remove') {
|
|
50
|
-
args.value.$remove = await parseOperator(args, key);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
args.create({ key }).error(ParseError.fieldDoesNotExist);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
args.collect();
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=set.js.map
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { ParseError } from '../../error.js';
|
|
2
|
-
import validators from 'validator';
|
|
3
|
-
const formatPatterns = {
|
|
4
|
-
email: validators.isEmail,
|
|
5
|
-
URL: validators.isURL,
|
|
6
|
-
MACAddress: validators.isMACAddress,
|
|
7
|
-
IP: validators.isIP,
|
|
8
|
-
IPRange: validators.isIPRange,
|
|
9
|
-
FQDN: validators.isFQDN,
|
|
10
|
-
IBAN: validators.isIBAN,
|
|
11
|
-
BIC: validators.isBIC,
|
|
12
|
-
alpha: validators.isAlpha,
|
|
13
|
-
alphaLocales: validators.isAlphaLocales,
|
|
14
|
-
alphanumeric: validators.isAlphanumeric,
|
|
15
|
-
alphanumericLocales: validators.isAlphanumericLocales,
|
|
16
|
-
passportNumber: validators.isPassportNumber,
|
|
17
|
-
port: validators.isPort,
|
|
18
|
-
lowercase: validators.isLowercase,
|
|
19
|
-
uppercase: validators.isUppercase,
|
|
20
|
-
ascii: validators.isAscii,
|
|
21
|
-
semVer: validators.isSemVer,
|
|
22
|
-
surrogatePair: validators.isSurrogatePair,
|
|
23
|
-
IMEI: validators.isIMEI,
|
|
24
|
-
hexadecimal: validators.isHexadecimal,
|
|
25
|
-
octal: validators.isOctal,
|
|
26
|
-
hexColor: validators.isHexColor,
|
|
27
|
-
rgbColor: validators.isRgbColor,
|
|
28
|
-
HSL: validators.isHSL,
|
|
29
|
-
ISRC: validators.isISRC,
|
|
30
|
-
MD5: validators.isMD5,
|
|
31
|
-
JWT: validators.isJWT,
|
|
32
|
-
UUID: validators.isUUID,
|
|
33
|
-
luhnNumber: validators.isLuhnNumber,
|
|
34
|
-
creditCard: validators.isCreditCard,
|
|
35
|
-
identityCard: validators.isIdentityCard,
|
|
36
|
-
EAN: validators.isEAN,
|
|
37
|
-
ISIN: validators.isISIN,
|
|
38
|
-
ISBN: validators.isISBN,
|
|
39
|
-
ISSN: validators.isISSN,
|
|
40
|
-
mobilePhone: validators.isMobilePhone,
|
|
41
|
-
mobilePhoneLocales: validators.isMobilePhoneLocales,
|
|
42
|
-
postalCode: validators.isPostalCode,
|
|
43
|
-
postalCodeLocales: validators.isPostalCodeLocales,
|
|
44
|
-
ethereumAddress: validators.isEthereumAddress,
|
|
45
|
-
currency: validators.isCurrency,
|
|
46
|
-
btcAddress: validators.isBtcAddress,
|
|
47
|
-
ISO6391: validators.isISO6391,
|
|
48
|
-
ISO8601: validators.isISO8601,
|
|
49
|
-
RFC3339: validators.isRFC3339,
|
|
50
|
-
ISO31661Alpha2: validators.isISO31661Alpha2,
|
|
51
|
-
ISO31661Alpha3: validators.isISO31661Alpha3,
|
|
52
|
-
ISO4217: validators.isISO4217,
|
|
53
|
-
base32: validators.isBase32,
|
|
54
|
-
base58: validators.isBase58,
|
|
55
|
-
base64: validators.isBase64,
|
|
56
|
-
dataURI: validators.isDataURI,
|
|
57
|
-
magnetURI: validators.isMagnetURI,
|
|
58
|
-
mimeType: validators.isMimeType,
|
|
59
|
-
latLong: validators.isLatLong,
|
|
60
|
-
slug: validators.isSlug,
|
|
61
|
-
strongPassword: validators.isStrongPassword,
|
|
62
|
-
taxID: validators.isTaxID,
|
|
63
|
-
licensePlate: validators.isLicensePlate,
|
|
64
|
-
VAT: validators.isVAT,
|
|
65
|
-
code: () => true,
|
|
66
|
-
javascript: () => true,
|
|
67
|
-
typescript: () => true,
|
|
68
|
-
python: () => true,
|
|
69
|
-
rust: () => true,
|
|
70
|
-
css: () => true,
|
|
71
|
-
html: () => true,
|
|
72
|
-
json: () => true,
|
|
73
|
-
markdown: () => true,
|
|
74
|
-
clike: () => true,
|
|
75
|
-
// Can add some more checks for this...
|
|
76
|
-
basedId: (value) => typeof value === 'string' && value.length < 16,
|
|
77
|
-
basedType: (value) => typeof value === 'string' && value.length < 64,
|
|
78
|
-
};
|
|
79
|
-
const validateString = (args, value) => {
|
|
80
|
-
if (typeof value !== 'string') {
|
|
81
|
-
args.error(ParseError.incorrectFormat);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (args.fieldSchema.minLength && value.length < args.fieldSchema.minLength) {
|
|
85
|
-
args.error(ParseError.subceedsMinimum);
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (args.fieldSchema.maxLength && value.length > args.fieldSchema.maxLength) {
|
|
89
|
-
args.error(ParseError.exceedsMaximum);
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (args.fieldSchema.pattern) {
|
|
93
|
-
const re = new RegExp(args.fieldSchema.pattern);
|
|
94
|
-
if (!re.test(value)) {
|
|
95
|
-
args.error(ParseError.incorrectFormat);
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (args.fieldSchema.format &&
|
|
100
|
-
!formatPatterns[args.fieldSchema.format](value)) {
|
|
101
|
-
args.error(ParseError.incorrectFormat);
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
};
|
|
106
|
-
export const string = async (args) => {
|
|
107
|
-
if (!validateString(args, args.value)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
args.collect();
|
|
111
|
-
};
|
|
112
|
-
// --- bla
|
|
113
|
-
// if typeof === string
|
|
114
|
-
export const text = async (args) => {
|
|
115
|
-
const value = args.value;
|
|
116
|
-
args.stop();
|
|
117
|
-
if (value === null) {
|
|
118
|
-
args.error(ParseError.incorrectFormat);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (typeof value === 'object') {
|
|
122
|
-
for (const key in value) {
|
|
123
|
-
if (key === '$merge') {
|
|
124
|
-
if (typeof value.$merge !== 'boolean') {
|
|
125
|
-
args.error(ParseError.incorrectFormat);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (key === '$delete') {
|
|
130
|
-
if (value[key] !== true) {
|
|
131
|
-
args.error(ParseError.incorrectFormat);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
args.collect({ $delete: true });
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
else if (key === '$value') {
|
|
138
|
-
const valueArgs = args.create({
|
|
139
|
-
path: args.path,
|
|
140
|
-
value: args.value[key],
|
|
141
|
-
});
|
|
142
|
-
valueArgs._stopObject = true;
|
|
143
|
-
await valueArgs.parse();
|
|
144
|
-
}
|
|
145
|
-
else if (key === '$default') {
|
|
146
|
-
if (value[key] === null) {
|
|
147
|
-
args.error(ParseError.incorrectFormat);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (typeof value[key] === 'object') {
|
|
151
|
-
for (const k in value[key]) {
|
|
152
|
-
if (!validateString(args, args.value[key][k])) {
|
|
153
|
-
args.error(ParseError.incorrectFormat);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
args
|
|
157
|
-
.create({
|
|
158
|
-
key: k,
|
|
159
|
-
fieldSchema: { type: 'string' },
|
|
160
|
-
value: { $default: args.value[key][k] },
|
|
161
|
-
})
|
|
162
|
-
.collect();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else if (typeof value[key] !== 'string') {
|
|
166
|
-
args.error(ParseError.incorrectFormat);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
else if (!args.target.$language) {
|
|
170
|
-
args.error(ParseError.noLanguageFound);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
else if (!validateString(args, value[key])) {
|
|
174
|
-
args.error(ParseError.incorrectFormat);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
args
|
|
179
|
-
.create({
|
|
180
|
-
fieldSchema: { type: 'string' },
|
|
181
|
-
key: args.target.$language,
|
|
182
|
-
value: { $default: args.value[key] },
|
|
183
|
-
})
|
|
184
|
-
.collect();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else if ((args.schema.translations || [])
|
|
188
|
-
.concat(args.schema.language)
|
|
189
|
-
.includes(key)) {
|
|
190
|
-
if (value[key] && typeof value[key] === 'object') {
|
|
191
|
-
for (const k in value[key]) {
|
|
192
|
-
if (k === '$delete') {
|
|
193
|
-
if (value[key].$delete !== true) {
|
|
194
|
-
args.error(ParseError.incorrectFormat);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
args
|
|
198
|
-
.create({
|
|
199
|
-
key,
|
|
200
|
-
fieldSchema: { type: 'string' },
|
|
201
|
-
value: args.value[key],
|
|
202
|
-
})
|
|
203
|
-
.collect();
|
|
204
|
-
}
|
|
205
|
-
else if (k === '$value') {
|
|
206
|
-
if (!validateString(args, value[key].$value)) {
|
|
207
|
-
args.create({ key }).error(ParseError.incorrectFormat);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
args
|
|
211
|
-
.create({
|
|
212
|
-
key,
|
|
213
|
-
fieldSchema: { type: 'string' },
|
|
214
|
-
value: args.value[key].$value,
|
|
215
|
-
})
|
|
216
|
-
.collect();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else if (k === '$default') {
|
|
220
|
-
if (!validateString(args, value[key].$default)) {
|
|
221
|
-
args.create({ key }).error(ParseError.incorrectFormat);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
args
|
|
225
|
-
.create({
|
|
226
|
-
key,
|
|
227
|
-
fieldSchema: { type: 'string' },
|
|
228
|
-
value: { $default: args.value[key].$default },
|
|
229
|
-
})
|
|
230
|
-
.collect();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
args
|
|
235
|
-
.create({ path: [...args.path, key, k] })
|
|
236
|
-
.error(ParseError.fieldDoesNotExist);
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
if (!validateString(args, args.value[key])) {
|
|
243
|
-
args.error(ParseError.incorrectFormat);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
args
|
|
247
|
-
.create({
|
|
248
|
-
key,
|
|
249
|
-
fieldSchema: { type: 'string' },
|
|
250
|
-
value: args.value[key],
|
|
251
|
-
})
|
|
252
|
-
.collect();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
args.create({ key }).error(ParseError.languageNotSupported);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (!args._stopObject) {
|
|
260
|
-
args.collect();
|
|
261
|
-
}
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (typeof value !== 'string') {
|
|
265
|
-
args.error(ParseError.incorrectFormat);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
if (!args.target.$language) {
|
|
269
|
-
args.error(ParseError.noLanguageFound);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (!validateString(args, args.value)) {
|
|
273
|
-
args.error(ParseError.incorrectFormat);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
args
|
|
277
|
-
.create({
|
|
278
|
-
value,
|
|
279
|
-
key: args.target.$language,
|
|
280
|
-
fieldSchema: { type: 'string' },
|
|
281
|
-
})
|
|
282
|
-
.collect();
|
|
283
|
-
if (!args._stopObject) {
|
|
284
|
-
args.collect({
|
|
285
|
-
[args.target.$language]: value,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
//# sourceMappingURL=string.js.map
|
package/dist/src/set/index.d.ts
DELETED
package/dist/src/set/index.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { ParseError } from '../error.js';
|
|
2
|
-
import { walk } from '../walker/index.js';
|
|
3
|
-
import { fields } from './fields/index.js';
|
|
4
|
-
import { isValidId } from './isValidId.js';
|
|
5
|
-
const opts = {
|
|
6
|
-
parsers: {
|
|
7
|
-
keys: {
|
|
8
|
-
$delete: async (args) => {
|
|
9
|
-
const type = args.fieldSchema?.type;
|
|
10
|
-
if (type === 'json') {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (args.prev === args.root) {
|
|
14
|
-
args.error(ParseError.cannotDeleteNodeFromModify);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (args.value === true) {
|
|
18
|
-
args.stop();
|
|
19
|
-
args.prev.collect();
|
|
20
|
-
args.prev.stop();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
$alias: async (args) => {
|
|
25
|
-
const type = args.fieldSchema?.type;
|
|
26
|
-
if (type === 'json') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (Array.isArray(args.value)) {
|
|
30
|
-
for (const field of args.value) {
|
|
31
|
-
if (typeof field !== 'string') {
|
|
32
|
-
args.error(ParseError.incorrectFormat);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (typeof args.value !== 'string') {
|
|
39
|
-
args.error(ParseError.incorrectFormat);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
$merge: async (args) => {
|
|
43
|
-
const type = args.fieldSchema?.type;
|
|
44
|
-
if (type === 'json') {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (typeof args.value !== 'boolean') {
|
|
48
|
-
args.error(ParseError.incorrectFormat);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (args.prev !== args.root) {
|
|
52
|
-
args.prev.collect({ $delete: true });
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
},
|
|
56
|
-
$id: async (args) => {
|
|
57
|
-
const type = args.fieldSchema?.type;
|
|
58
|
-
if (type === 'json') {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (!isValidId(args.schema, args.value)) {
|
|
62
|
-
args.error(ParseError.incorrectFormat);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
$language: async (args) => {
|
|
67
|
-
const type = args.fieldSchema?.type;
|
|
68
|
-
if (type === 'json') {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (!(args.schema.translations || [])
|
|
72
|
-
.concat(args.schema.language)
|
|
73
|
-
.includes(args.value)) {
|
|
74
|
-
args.error(ParseError.languageNotSupported);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
$value: async (args) => {
|
|
79
|
-
const type = args.fieldSchema?.type;
|
|
80
|
-
if (type === 'text' ||
|
|
81
|
-
type === 'set' ||
|
|
82
|
-
type == 'references' ||
|
|
83
|
-
type === 'json') {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
args.prev.stop();
|
|
87
|
-
args.stop();
|
|
88
|
-
if (args.prev.value.$default) {
|
|
89
|
-
args.error(ParseError.valueAndDefault);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
path: args.path.slice(0, -1),
|
|
94
|
-
value: args.value,
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
$default: async (args) => {
|
|
98
|
-
const type = args.fieldSchema?.type;
|
|
99
|
-
if (type === 'number' ||
|
|
100
|
-
type === 'integer' ||
|
|
101
|
-
type === 'text' ||
|
|
102
|
-
type === 'json') {
|
|
103
|
-
// default can exist with $incr and $decr
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
args.prev.stop();
|
|
107
|
-
args.stop();
|
|
108
|
-
if (type === 'references' || type === 'set' || type === 'array') {
|
|
109
|
-
const newArgs = args.create({
|
|
110
|
-
path: args.path.slice(0, -1),
|
|
111
|
-
skipCollection: true,
|
|
112
|
-
});
|
|
113
|
-
await newArgs.parse();
|
|
114
|
-
newArgs.skipCollection = false;
|
|
115
|
-
newArgs.value = { $default: newArgs.value };
|
|
116
|
-
newArgs.collect();
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
const collect = args._collectOverride ?? args.root._opts.collect;
|
|
120
|
-
const newArgs = args.create({
|
|
121
|
-
path: args.path.slice(0, -1),
|
|
122
|
-
collect: (a) => {
|
|
123
|
-
if (a.path.length === args.path.length - 1) {
|
|
124
|
-
collect(a.create({ value: { $default: a.value } }));
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// console.info('hello', a.path) can handle this later
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
await newArgs.parse();
|
|
132
|
-
}
|
|
133
|
-
for (const key in args.prev.value) {
|
|
134
|
-
if (key !== '$default') {
|
|
135
|
-
args.prev.create({ key }).error(ParseError.fieldDoesNotExist);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
fields,
|
|
141
|
-
catch: async (args) => {
|
|
142
|
-
args.error(ParseError.fieldDoesNotExist);
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
init: async (value, schema, error) => {
|
|
146
|
-
let type;
|
|
147
|
-
const target = {
|
|
148
|
-
type,
|
|
149
|
-
schema,
|
|
150
|
-
required: [],
|
|
151
|
-
collected: [],
|
|
152
|
-
errors: [],
|
|
153
|
-
};
|
|
154
|
-
if (value.$id) {
|
|
155
|
-
if (value.$id === 'root') {
|
|
156
|
-
type = 'root';
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
type = schema.prefixToTypeMapping[value.$id.slice(0, 2)];
|
|
160
|
-
}
|
|
161
|
-
if (!type) {
|
|
162
|
-
error(ParseError.incorrectFieldType, { target });
|
|
163
|
-
return { target };
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else if (value.$alias) {
|
|
167
|
-
target.$alias = value.$alias;
|
|
168
|
-
}
|
|
169
|
-
if (value.type) {
|
|
170
|
-
if (type && value.type !== type) {
|
|
171
|
-
error(ParseError.incorrectNodeType, { target });
|
|
172
|
-
return { target };
|
|
173
|
-
}
|
|
174
|
-
type = value.type;
|
|
175
|
-
}
|
|
176
|
-
const typeSchema = type === 'root' ? schema.root : schema.types[type];
|
|
177
|
-
if (!typeSchema) {
|
|
178
|
-
error(ParseError.incorrectNodeType, { target });
|
|
179
|
-
return { target };
|
|
180
|
-
}
|
|
181
|
-
target.type = type;
|
|
182
|
-
target.$language = value.$language;
|
|
183
|
-
target.$id = value.$id;
|
|
184
|
-
if ('$merge' in value) {
|
|
185
|
-
if (typeof value.$merge !== 'boolean') {
|
|
186
|
-
error(ParseError.incorrectFormat, { target });
|
|
187
|
-
}
|
|
188
|
-
target.$merge = value.$merge;
|
|
189
|
-
}
|
|
190
|
-
return { target, typeSchema };
|
|
191
|
-
},
|
|
192
|
-
error: (code, args) => {
|
|
193
|
-
args.target.errors.push({
|
|
194
|
-
code,
|
|
195
|
-
path: args.path ?? [],
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
collect: (args) => {
|
|
199
|
-
args.root.target.collected.push(args);
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
export const setWalker = (schema, value, asyncOperationHandler) => {
|
|
203
|
-
return walk(schema, opts, value, asyncOperationHandler);
|
|
204
|
-
};
|
|
205
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const isValidId = (schema, id) => {
|
|
2
|
-
if (typeof id !== 'string') {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
if (id === 'root') {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
if (id.length > 16) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const prefix = id.slice(0, 2);
|
|
12
|
-
if (!schema.prefixToTypeMapping[prefix]) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=isValidId.js.map
|