@based/schema 2.2.9 → 2.2.11
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/{display → src/display}/index.d.ts +1 -1
- package/dist/src/display/index.js +16 -0
- package/dist/{display → src/display}/number.js +1 -3
- package/dist/{display → src/display}/string.js +1 -3
- package/dist/{display → src/display}/timestamp.js +1 -3
- package/dist/{error.js → src/error.js} +2 -5
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +6 -0
- package/dist/{languages.js → src/languages.js} +1 -4
- package/dist/src/set/fields/array.d.ts +2 -0
- package/dist/{set → src/set}/fields/array.js +10 -14
- package/dist/src/set/fields/index.d.ts +3 -0
- package/dist/src/set/fields/index.js +71 -0
- package/dist/{set → src/set}/fields/number.d.ts +1 -1
- package/dist/{set → src/set}/fields/number.js +15 -21
- package/dist/{set → src/set}/fields/object.d.ts +1 -1
- package/dist/src/set/fields/object.js +28 -0
- package/dist/{set → src/set}/fields/references.d.ts +1 -1
- package/dist/{set → src/set}/fields/references.js +13 -18
- package/dist/src/set/fields/set.d.ts +2 -0
- package/dist/{set → src/set}/fields/set.js +4 -8
- package/dist/{set → src/set}/fields/string.d.ts +1 -1
- package/dist/{set → src/set}/fields/string.js +90 -95
- package/dist/{set → src/set}/index.d.ts +2 -2
- package/dist/{set → src/set}/index.js +21 -25
- package/dist/{set → src/set}/isValidId.d.ts +1 -1
- package/dist/{set → src/set}/isValidId.js +1 -5
- package/dist/{types.d.ts → src/types.d.ts} +7 -7
- package/dist/src/types.js +23 -0
- package/dist/src/updateSchema.d.ts +2 -0
- package/dist/src/updateSchema.js +12 -0
- package/dist/src/validateSchema.d.ts +4 -0
- package/dist/{validateSchema.js → src/validateSchema.js} +5 -11
- package/dist/{walker → src/walker}/args.d.ts +4 -4
- package/dist/{walker → src/walker}/args.js +8 -12
- package/dist/src/walker/index.d.ts +6 -0
- package/dist/src/walker/index.js +31 -0
- package/dist/{walker → src/walker}/parse.d.ts +1 -1
- package/dist/{walker → src/walker}/parse.js +7 -11
- package/dist/{walker → src/walker}/types.d.ts +3 -3
- package/dist/{walker → src/walker}/types.js +2 -5
- package/dist/test/array.d.ts +1 -0
- package/dist/test/array.js +342 -0
- package/dist/test/display.d.ts +1 -0
- package/dist/test/display.js +103 -0
- package/dist/test/number.d.ts +1 -0
- package/dist/test/number.js +374 -0
- package/dist/test/reference.d.ts +1 -0
- package/dist/test/reference.js +186 -0
- package/dist/test/rest.d.ts +1 -0
- package/dist/test/rest.js +168 -0
- package/dist/test/set.d.ts +1 -0
- package/dist/test/set.js +95 -0
- package/dist/test/string.d.ts +1 -0
- package/dist/test/string.js +120 -0
- package/dist/test/text.d.ts +1 -0
- package/dist/test/text.js +324 -0
- package/dist/test/utils/index.d.ts +11 -0
- package/dist/test/utils/index.js +17 -0
- package/dist/test/validateSchema.d.ts +1 -0
- package/dist/test/validateSchema.js +38 -0
- package/dist/test/walker.d.ts +1 -0
- package/dist/test/walker.js +289 -0
- package/package.json +8 -13
- package/dist/display/dateString copy.d.ts +0 -3
- package/dist/display/dateString copy.js +0 -127
- package/dist/display/dateString.d.ts +0 -3
- package/dist/display/dateString.js +0 -127
- package/dist/display/display.d.ts +0 -1
- package/dist/display/display.js +0 -8
- package/dist/display/index.js +0 -26
- package/dist/display/number copy.d.ts +0 -3
- package/dist/display/number copy.js +0 -81
- package/dist/display.d.ts +0 -2
- package/dist/display.js +0 -8
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -22
- package/dist/set/fields/array.d.ts +0 -2
- package/dist/set/fields/index.d.ts +0 -3
- package/dist/set/fields/index.js +0 -74
- package/dist/set/fields/object.js +0 -33
- package/dist/set/fields/set.d.ts +0 -2
- package/dist/set/types.d.ts +0 -0
- package/dist/set/types.js +0 -1
- package/dist/types.js +0 -27
- package/dist/updateSchema.d.ts +0 -2
- package/dist/updateSchema.js +0 -16
- package/dist/validateSchema.d.ts +0 -4
- package/dist/walker/index.d.ts +0 -6
- package/dist/walker/index.js +0 -49
- /package/dist/{display → src/display}/number.d.ts +0 -0
- /package/dist/{display → src/display}/string.d.ts +0 -0
- /package/dist/{display → src/display}/timestamp.d.ts +0 -0
- /package/dist/{error.d.ts → src/error.d.ts} +0 -0
- /package/dist/{languages.d.ts → src/languages.d.ts} +0 -0
|
@@ -1,73 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.text = exports.string = void 0;
|
|
7
|
-
const error_1 = require("../../error");
|
|
8
|
-
const validator_1 = __importDefault(require("validator"));
|
|
1
|
+
import { ParseError } from '../../error.js';
|
|
2
|
+
import validators from 'validator';
|
|
9
3
|
const formatPatterns = {
|
|
10
|
-
email:
|
|
11
|
-
URL:
|
|
12
|
-
MACAddress:
|
|
13
|
-
IP:
|
|
14
|
-
IPRange:
|
|
15
|
-
FQDN:
|
|
16
|
-
IBAN:
|
|
17
|
-
BIC:
|
|
18
|
-
alpha:
|
|
19
|
-
alphaLocales:
|
|
20
|
-
alphanumeric:
|
|
21
|
-
alphanumericLocales:
|
|
22
|
-
passportNumber:
|
|
23
|
-
port:
|
|
24
|
-
lowercase:
|
|
25
|
-
uppercase:
|
|
26
|
-
ascii:
|
|
27
|
-
semVer:
|
|
28
|
-
surrogatePair:
|
|
29
|
-
IMEI:
|
|
30
|
-
hexadecimal:
|
|
31
|
-
octal:
|
|
32
|
-
hexColor:
|
|
33
|
-
rgbColor:
|
|
34
|
-
HSL:
|
|
35
|
-
ISRC:
|
|
36
|
-
MD5:
|
|
37
|
-
JWT:
|
|
38
|
-
UUID:
|
|
39
|
-
luhnNumber:
|
|
40
|
-
creditCard:
|
|
41
|
-
identityCard:
|
|
42
|
-
EAN:
|
|
43
|
-
ISIN:
|
|
44
|
-
ISBN:
|
|
45
|
-
ISSN:
|
|
46
|
-
mobilePhone:
|
|
47
|
-
mobilePhoneLocales:
|
|
48
|
-
postalCode:
|
|
49
|
-
postalCodeLocales:
|
|
50
|
-
ethereumAddress:
|
|
51
|
-
currency:
|
|
52
|
-
btcAddress:
|
|
53
|
-
ISO6391:
|
|
54
|
-
ISO8601:
|
|
55
|
-
RFC3339:
|
|
56
|
-
ISO31661Alpha2:
|
|
57
|
-
ISO31661Alpha3:
|
|
58
|
-
ISO4217:
|
|
59
|
-
base32:
|
|
60
|
-
base58:
|
|
61
|
-
base64:
|
|
62
|
-
dataURI:
|
|
63
|
-
magnetURI:
|
|
64
|
-
mimeType:
|
|
65
|
-
latLong:
|
|
66
|
-
slug:
|
|
67
|
-
strongPassword:
|
|
68
|
-
taxID:
|
|
69
|
-
licensePlate:
|
|
70
|
-
VAT:
|
|
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,
|
|
71
65
|
code: () => true,
|
|
72
66
|
javascript: () => true,
|
|
73
67
|
typescript: () => true,
|
|
@@ -75,61 +69,63 @@ const formatPatterns = {
|
|
|
75
69
|
rust: () => true,
|
|
76
70
|
css: () => true,
|
|
77
71
|
html: () => true,
|
|
72
|
+
json: () => true,
|
|
73
|
+
markdown: () => true,
|
|
74
|
+
clike: () => true,
|
|
78
75
|
};
|
|
79
76
|
const validateString = (args, value) => {
|
|
80
77
|
if (typeof value !== 'string') {
|
|
81
|
-
args.error(
|
|
78
|
+
args.error(ParseError.incorrectFormat);
|
|
82
79
|
return false;
|
|
83
80
|
}
|
|
84
81
|
if (args.fieldSchema.minLength && value.length < args.fieldSchema.minLength) {
|
|
85
|
-
args.error(
|
|
82
|
+
args.error(ParseError.subceedsMinimum);
|
|
86
83
|
return false;
|
|
87
84
|
}
|
|
88
85
|
if (args.fieldSchema.maxLength && value.length > args.fieldSchema.maxLength) {
|
|
89
|
-
args.error(
|
|
86
|
+
args.error(ParseError.exceedsMaximum);
|
|
90
87
|
return false;
|
|
91
88
|
}
|
|
92
89
|
if (args.fieldSchema.pattern) {
|
|
93
90
|
const re = new RegExp(args.fieldSchema.pattern);
|
|
94
91
|
if (!re.test(value)) {
|
|
95
|
-
args.error(
|
|
92
|
+
args.error(ParseError.incorrectFormat);
|
|
96
93
|
return false;
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
96
|
if (args.fieldSchema.format &&
|
|
100
97
|
!formatPatterns[args.fieldSchema.format](value)) {
|
|
101
|
-
args.error(
|
|
98
|
+
args.error(ParseError.incorrectFormat);
|
|
102
99
|
return false;
|
|
103
100
|
}
|
|
104
101
|
return true;
|
|
105
102
|
};
|
|
106
|
-
const string = async (args) => {
|
|
103
|
+
export const string = async (args) => {
|
|
107
104
|
if (!validateString(args, args.value)) {
|
|
108
105
|
return;
|
|
109
106
|
}
|
|
110
107
|
args.collect();
|
|
111
108
|
};
|
|
112
|
-
exports.string = string;
|
|
113
109
|
// --- bla
|
|
114
110
|
// if typeof === string
|
|
115
|
-
const text = async (args) => {
|
|
111
|
+
export const text = async (args) => {
|
|
116
112
|
const value = args.value;
|
|
117
113
|
args.stop();
|
|
118
114
|
if (value === null) {
|
|
119
|
-
args.error(
|
|
115
|
+
args.error(ParseError.incorrectFormat);
|
|
120
116
|
return;
|
|
121
117
|
}
|
|
122
118
|
if (typeof value === 'object') {
|
|
123
119
|
for (const key in value) {
|
|
124
120
|
if (key === '$merge') {
|
|
125
121
|
if (typeof value.$merge !== 'boolean') {
|
|
126
|
-
args.error(
|
|
122
|
+
args.error(ParseError.incorrectFormat);
|
|
127
123
|
return;
|
|
128
124
|
}
|
|
129
125
|
}
|
|
130
126
|
else if (key === '$delete') {
|
|
131
127
|
if (value[key] !== true) {
|
|
132
|
-
args.error(
|
|
128
|
+
args.error(ParseError.incorrectFormat);
|
|
133
129
|
return;
|
|
134
130
|
}
|
|
135
131
|
args.collect({ $delete: true });
|
|
@@ -145,13 +141,13 @@ const text = async (args) => {
|
|
|
145
141
|
}
|
|
146
142
|
else if (key === '$default') {
|
|
147
143
|
if (value[key] === null) {
|
|
148
|
-
args.error(
|
|
144
|
+
args.error(ParseError.incorrectFormat);
|
|
149
145
|
return;
|
|
150
146
|
}
|
|
151
147
|
if (typeof value[key] === 'object') {
|
|
152
148
|
for (const k in value[key]) {
|
|
153
149
|
if (!validateString(args, args.value[key][k])) {
|
|
154
|
-
args.error(
|
|
150
|
+
args.error(ParseError.incorrectFormat);
|
|
155
151
|
return;
|
|
156
152
|
}
|
|
157
153
|
args
|
|
@@ -164,15 +160,15 @@ const text = async (args) => {
|
|
|
164
160
|
}
|
|
165
161
|
}
|
|
166
162
|
else if (typeof value[key] !== 'string') {
|
|
167
|
-
args.error(
|
|
163
|
+
args.error(ParseError.incorrectFormat);
|
|
168
164
|
return;
|
|
169
165
|
}
|
|
170
166
|
else if (!args.target.$language) {
|
|
171
|
-
args.error(
|
|
167
|
+
args.error(ParseError.noLanguageFound);
|
|
172
168
|
return;
|
|
173
169
|
}
|
|
174
170
|
else if (!validateString(args, value[key])) {
|
|
175
|
-
args.error(
|
|
171
|
+
args.error(ParseError.incorrectFormat);
|
|
176
172
|
return;
|
|
177
173
|
}
|
|
178
174
|
else {
|
|
@@ -192,7 +188,7 @@ const text = async (args) => {
|
|
|
192
188
|
for (const k in value[key]) {
|
|
193
189
|
if (k === '$delete') {
|
|
194
190
|
if (value[key].$delete !== true) {
|
|
195
|
-
args.error(
|
|
191
|
+
args.error(ParseError.incorrectFormat);
|
|
196
192
|
return;
|
|
197
193
|
}
|
|
198
194
|
args
|
|
@@ -205,7 +201,7 @@ const text = async (args) => {
|
|
|
205
201
|
}
|
|
206
202
|
else if (k === '$value') {
|
|
207
203
|
if (!validateString(args, value[key].$value)) {
|
|
208
|
-
args.create({ key }).error(
|
|
204
|
+
args.create({ key }).error(ParseError.incorrectFormat);
|
|
209
205
|
}
|
|
210
206
|
else {
|
|
211
207
|
args
|
|
@@ -219,7 +215,7 @@ const text = async (args) => {
|
|
|
219
215
|
}
|
|
220
216
|
else if (k === '$default') {
|
|
221
217
|
if (!validateString(args, value[key].$default)) {
|
|
222
|
-
args.create({ key }).error(
|
|
218
|
+
args.create({ key }).error(ParseError.incorrectFormat);
|
|
223
219
|
}
|
|
224
220
|
else {
|
|
225
221
|
args
|
|
@@ -234,14 +230,14 @@ const text = async (args) => {
|
|
|
234
230
|
else {
|
|
235
231
|
args
|
|
236
232
|
.create({ path: [...args.path, key, k] })
|
|
237
|
-
.error(
|
|
233
|
+
.error(ParseError.fieldDoesNotExist);
|
|
238
234
|
return;
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
238
|
else {
|
|
243
239
|
if (!validateString(args, args.value[key])) {
|
|
244
|
-
args.error(
|
|
240
|
+
args.error(ParseError.incorrectFormat);
|
|
245
241
|
return;
|
|
246
242
|
}
|
|
247
243
|
args
|
|
@@ -254,7 +250,7 @@ const text = async (args) => {
|
|
|
254
250
|
}
|
|
255
251
|
}
|
|
256
252
|
else {
|
|
257
|
-
args.create({ key }).error(
|
|
253
|
+
args.create({ key }).error(ParseError.languageNotSupported);
|
|
258
254
|
}
|
|
259
255
|
}
|
|
260
256
|
if (!args._stopObject) {
|
|
@@ -263,15 +259,15 @@ const text = async (args) => {
|
|
|
263
259
|
return;
|
|
264
260
|
}
|
|
265
261
|
if (typeof value !== 'string') {
|
|
266
|
-
args.error(
|
|
262
|
+
args.error(ParseError.incorrectFormat);
|
|
267
263
|
return;
|
|
268
264
|
}
|
|
269
265
|
if (!args.target.$language) {
|
|
270
|
-
args.error(
|
|
266
|
+
args.error(ParseError.noLanguageFound);
|
|
271
267
|
return;
|
|
272
268
|
}
|
|
273
269
|
if (!validateString(args, args.value)) {
|
|
274
|
-
args.error(
|
|
270
|
+
args.error(ParseError.incorrectFormat);
|
|
275
271
|
return;
|
|
276
272
|
}
|
|
277
273
|
args
|
|
@@ -287,5 +283,4 @@ const text = async (args) => {
|
|
|
287
283
|
});
|
|
288
284
|
}
|
|
289
285
|
};
|
|
290
|
-
exports.text = text;
|
|
291
286
|
//# sourceMappingURL=string.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BasedSchema, BasedSetTarget } from '../types';
|
|
2
|
-
import { AsyncOperation } from '../walker';
|
|
1
|
+
import { BasedSchema, BasedSetTarget } from '../types.js';
|
|
2
|
+
import { AsyncOperation } from '../walker/index.js';
|
|
3
3
|
export declare const setWalker: (schema: BasedSchema, value: any, asyncOperationHandler?: AsyncOperation<BasedSetTarget>) => Promise<BasedSetTarget>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const walker_1 = require("../walker");
|
|
6
|
-
const fields_1 = require("./fields");
|
|
7
|
-
const isValidId_1 = require("./isValidId");
|
|
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';
|
|
8
5
|
const opts = {
|
|
9
6
|
parsers: {
|
|
10
7
|
keys: {
|
|
11
8
|
$delete: async (args) => {
|
|
12
9
|
if (args.prev === args.root) {
|
|
13
|
-
args.error(
|
|
10
|
+
args.error(ParseError.cannotDeleteNodeFromModify);
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
13
|
if (args.value === true) {
|
|
@@ -24,19 +21,19 @@ const opts = {
|
|
|
24
21
|
if (Array.isArray(args.value)) {
|
|
25
22
|
for (const field of args.value) {
|
|
26
23
|
if (typeof field !== 'string') {
|
|
27
|
-
args.error(
|
|
24
|
+
args.error(ParseError.incorrectFormat);
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
return;
|
|
32
29
|
}
|
|
33
30
|
if (typeof args.value !== 'string') {
|
|
34
|
-
args.error(
|
|
31
|
+
args.error(ParseError.incorrectFormat);
|
|
35
32
|
}
|
|
36
33
|
},
|
|
37
34
|
$merge: async (args) => {
|
|
38
35
|
if (typeof args.value !== 'boolean') {
|
|
39
|
-
args.error(
|
|
36
|
+
args.error(ParseError.incorrectFormat);
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
39
|
if (args.prev !== args.root) {
|
|
@@ -45,8 +42,8 @@ const opts = {
|
|
|
45
42
|
return;
|
|
46
43
|
},
|
|
47
44
|
$id: async (args) => {
|
|
48
|
-
if (!
|
|
49
|
-
args.error(
|
|
45
|
+
if (!isValidId(args.schema, args.value)) {
|
|
46
|
+
args.error(ParseError.incorrectFormat);
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
52
49
|
},
|
|
@@ -54,7 +51,7 @@ const opts = {
|
|
|
54
51
|
if (!(args.schema.translations || [])
|
|
55
52
|
.concat(args.schema.language)
|
|
56
53
|
.includes(args.value)) {
|
|
57
|
-
args.error(
|
|
54
|
+
args.error(ParseError.languageNotSupported);
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
60
57
|
},
|
|
@@ -66,7 +63,7 @@ const opts = {
|
|
|
66
63
|
args.prev.stop();
|
|
67
64
|
args.stop();
|
|
68
65
|
if (args.prev.value.$default) {
|
|
69
|
-
args.error(
|
|
66
|
+
args.error(ParseError.valueAndDefault);
|
|
70
67
|
return;
|
|
71
68
|
}
|
|
72
69
|
return {
|
|
@@ -109,14 +106,14 @@ const opts = {
|
|
|
109
106
|
}
|
|
110
107
|
for (const key in args.prev.value) {
|
|
111
108
|
if (key !== '$default') {
|
|
112
|
-
args.prev.create({ key }).error(
|
|
109
|
+
args.prev.create({ key }).error(ParseError.fieldDoesNotExist);
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
},
|
|
116
113
|
},
|
|
117
|
-
fields
|
|
114
|
+
fields,
|
|
118
115
|
catch: async (args) => {
|
|
119
|
-
args.error(
|
|
116
|
+
args.error(ParseError.fieldDoesNotExist);
|
|
120
117
|
},
|
|
121
118
|
},
|
|
122
119
|
init: async (value, schema, error) => {
|
|
@@ -136,7 +133,7 @@ const opts = {
|
|
|
136
133
|
type = schema.prefixToTypeMapping[value.$id.slice(0, 2)];
|
|
137
134
|
}
|
|
138
135
|
if (!type) {
|
|
139
|
-
error(
|
|
136
|
+
error(ParseError.incorrectFieldType, { target });
|
|
140
137
|
return { target };
|
|
141
138
|
}
|
|
142
139
|
}
|
|
@@ -145,14 +142,14 @@ const opts = {
|
|
|
145
142
|
}
|
|
146
143
|
if (value.type) {
|
|
147
144
|
if (type && value.type !== type) {
|
|
148
|
-
error(
|
|
145
|
+
error(ParseError.incorrectNodeType, { target });
|
|
149
146
|
return { target };
|
|
150
147
|
}
|
|
151
148
|
type = value.type;
|
|
152
149
|
}
|
|
153
150
|
const typeSchema = type === 'root' ? schema.root : schema.types[type];
|
|
154
151
|
if (!typeSchema) {
|
|
155
|
-
error(
|
|
152
|
+
error(ParseError.incorrectNodeType, { target });
|
|
156
153
|
return { target };
|
|
157
154
|
}
|
|
158
155
|
target.type = type;
|
|
@@ -160,7 +157,7 @@ const opts = {
|
|
|
160
157
|
target.$id = value.$id;
|
|
161
158
|
if ('$merge' in value) {
|
|
162
159
|
if (typeof value.$merge !== 'boolean') {
|
|
163
|
-
error(
|
|
160
|
+
error(ParseError.incorrectFormat, { target });
|
|
164
161
|
}
|
|
165
162
|
target.$merge = value.$merge;
|
|
166
163
|
}
|
|
@@ -176,8 +173,7 @@ const opts = {
|
|
|
176
173
|
args.root.target.collected.push(args);
|
|
177
174
|
},
|
|
178
175
|
};
|
|
179
|
-
const setWalker = (schema, value, asyncOperationHandler) => {
|
|
180
|
-
return
|
|
176
|
+
export const setWalker = (schema, value, asyncOperationHandler) => {
|
|
177
|
+
return walk(schema, opts, value, asyncOperationHandler);
|
|
181
178
|
};
|
|
182
|
-
exports.setWalker = setWalker;
|
|
183
179
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BasedSchema } from '../types';
|
|
1
|
+
import { BasedSchema } from '../types.js';
|
|
2
2
|
export declare const isValidId: (schema: BasedSchema, id: any) => boolean;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidId = void 0;
|
|
4
|
-
const isValidId = (schema, id) => {
|
|
1
|
+
export const isValidId = (schema, id) => {
|
|
5
2
|
if (typeof id !== 'string') {
|
|
6
3
|
return false;
|
|
7
4
|
}
|
|
@@ -17,5 +14,4 @@ const isValidId = (schema, id) => {
|
|
|
17
14
|
}
|
|
18
15
|
return true;
|
|
19
16
|
};
|
|
20
|
-
exports.isValidId = isValidId;
|
|
21
17
|
//# sourceMappingURL=isValidId.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Language } from './languages';
|
|
1
|
+
import type { Language } from './languages.js';
|
|
2
2
|
import type { PartialDeep } from 'type-fest';
|
|
3
|
-
import { ParseError } from './error';
|
|
4
|
-
import { ArgsClass, Path } from './walker';
|
|
5
|
-
import { StringFormat } from './display/string';
|
|
6
|
-
import { NumberFormat } from './display/number';
|
|
7
|
-
import { DateFormat } from './display/timestamp';
|
|
3
|
+
import { ParseError } from './error.js';
|
|
4
|
+
import { ArgsClass, Path } from './walker/index.js';
|
|
5
|
+
import { StringFormat } from './display/string.js';
|
|
6
|
+
import { NumberFormat } from './display/number.js';
|
|
7
|
+
import { DateFormat } from './display/timestamp.js';
|
|
8
8
|
export type AllowedTypes = (string | {
|
|
9
9
|
type?: string;
|
|
10
10
|
$filter: any | any[];
|
|
@@ -49,7 +49,7 @@ export type BasedSchemaStringShared = {
|
|
|
49
49
|
contentMediaEncoding?: string;
|
|
50
50
|
contentMediaType?: BasedSchemaContentMediaType;
|
|
51
51
|
pattern?: BasedSchemaPattern;
|
|
52
|
-
format?: 'email' | 'URL' | 'MACAddress' | 'IP' | 'IPRange' | 'FQDN' | 'IBAN' | 'BIC' | 'alpha' | 'alphaLocales' | 'alphanumeric' | 'alphanumericLocales' | 'passportNumber' | 'port' | 'lowercase' | 'uppercase' | 'ascii' | 'semVer' | 'surrogatePair' | 'IMEI' | 'hexadecimal' | 'octal' | 'hexColor' | 'rgbColor' | 'HSL' | 'ISRC' | 'MD5' | 'JWT' | 'UUID' | 'luhnNumber' | 'creditCard' | 'identityCard' | 'EAN' | 'ISIN' | 'ISBN' | 'ISSN' | 'mobilePhone' | 'mobilePhoneLocales' | 'postalCode' | 'postalCodeLocales' | 'ethereumAddress' | 'currency' | 'btcAddress' | 'ISO6391' | 'ISO8601' | 'RFC3339' | 'ISO31661Alpha2' | 'ISO31661Alpha3' | 'ISO4217' | 'base32' | 'base58' | 'base64' | 'dataURI' | 'magnetURI' | 'mimeType' | 'latLong' | 'slug' | 'strongPassword' | 'taxID' | 'licensePlate' | 'VAT' | 'code' | 'typescript' | 'javascript' | 'python' | 'rust' | 'css' | 'html';
|
|
52
|
+
format?: 'email' | 'URL' | 'MACAddress' | 'IP' | 'IPRange' | 'FQDN' | 'IBAN' | 'BIC' | 'alpha' | 'alphaLocales' | 'alphanumeric' | 'alphanumericLocales' | 'passportNumber' | 'port' | 'lowercase' | 'uppercase' | 'ascii' | 'semVer' | 'surrogatePair' | 'IMEI' | 'hexadecimal' | 'octal' | 'hexColor' | 'rgbColor' | 'HSL' | 'ISRC' | 'MD5' | 'JWT' | 'UUID' | 'luhnNumber' | 'creditCard' | 'identityCard' | 'EAN' | 'ISIN' | 'ISBN' | 'ISSN' | 'mobilePhone' | 'mobilePhoneLocales' | 'postalCode' | 'postalCodeLocales' | 'ethereumAddress' | 'currency' | 'btcAddress' | 'ISO6391' | 'ISO8601' | 'RFC3339' | 'ISO31661Alpha2' | 'ISO31661Alpha3' | 'ISO4217' | 'base32' | 'base58' | 'base64' | 'dataURI' | 'magnetURI' | 'mimeType' | 'latLong' | 'slug' | 'strongPassword' | 'taxID' | 'licensePlate' | 'VAT' | 'code' | 'typescript' | 'javascript' | 'python' | 'rust' | 'css' | 'html' | 'json' | 'markdown' | 'clike';
|
|
53
53
|
display?: StringFormat;
|
|
54
54
|
multiline?: boolean;
|
|
55
55
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { languages as allLanguages } from './languages.js';
|
|
2
|
+
export const basedSchemaFieldTypes = [
|
|
3
|
+
'array',
|
|
4
|
+
'object',
|
|
5
|
+
'record',
|
|
6
|
+
'set',
|
|
7
|
+
'string',
|
|
8
|
+
'boolean',
|
|
9
|
+
'number',
|
|
10
|
+
'json',
|
|
11
|
+
'integer',
|
|
12
|
+
'timestamp',
|
|
13
|
+
'reference',
|
|
14
|
+
'references',
|
|
15
|
+
'text',
|
|
16
|
+
'enum',
|
|
17
|
+
'cardinality',
|
|
18
|
+
];
|
|
19
|
+
export const isCollection = (type) => {
|
|
20
|
+
return type === 'array' || type === 'object' || type === 'record';
|
|
21
|
+
};
|
|
22
|
+
export const languages = Object.keys(allLanguages);
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const updateSchema = async (_newSchema, oldSchema = {
|
|
2
|
+
$defs: {},
|
|
3
|
+
types: {},
|
|
4
|
+
language: 'en',
|
|
5
|
+
root: { fields: {} },
|
|
6
|
+
prefixToTypeMapping: {},
|
|
7
|
+
}) => {
|
|
8
|
+
// add sha
|
|
9
|
+
// put isRequired on the new schema in REQUIRED arrays
|
|
10
|
+
return oldSchema;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=updateSchema.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedSchemaPartial, BasedSchemaFieldPartial, BasedSchemaTypePartial } from './types.js';
|
|
2
|
+
export declare const validateType: (_fromSchema: BasedSchemaPartial, typeName: string, type: BasedSchemaTypePartial) => void;
|
|
3
|
+
export declare const validateField: (_fromSchema: BasedSchemaPartial, _path: string[], _field: BasedSchemaFieldPartial) => void;
|
|
4
|
+
export declare const validateSchema: (schema: BasedSchemaPartial) => BasedSchemaPartial;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateSchema = exports.validateField = exports.validateType = void 0;
|
|
4
1
|
// gaurd in the schema for refs in arrays
|
|
5
|
-
const validateType = (
|
|
2
|
+
export const validateType = (_fromSchema, typeName, type) => {
|
|
6
3
|
if (type.prefix &&
|
|
7
4
|
(typeof type.prefix !== 'string' || type.prefix.length !== 2)) {
|
|
8
5
|
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"`);
|
|
9
6
|
}
|
|
10
7
|
};
|
|
11
|
-
|
|
12
|
-
const validateField = (fromSchema, path, field) => {
|
|
8
|
+
export const validateField = (_fromSchema, _path, _field) => {
|
|
13
9
|
//
|
|
14
10
|
};
|
|
15
|
-
|
|
16
|
-
const validateSchema = (schema) => {
|
|
11
|
+
export const validateSchema = (schema) => {
|
|
17
12
|
// rewrite schema things like required / required: []
|
|
18
13
|
if (typeof schema !== 'object') {
|
|
19
14
|
throw new Error('Schema is not an object');
|
|
@@ -28,14 +23,13 @@ const validateSchema = (schema) => {
|
|
|
28
23
|
// first defs ofc
|
|
29
24
|
}
|
|
30
25
|
if (schema.root) {
|
|
31
|
-
|
|
26
|
+
validateType(schema, 'root', schema.root);
|
|
32
27
|
}
|
|
33
28
|
if (schema.types) {
|
|
34
29
|
for (const type in schema.types) {
|
|
35
|
-
|
|
30
|
+
validateType(schema, type, schema.types[type]);
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
return schema;
|
|
39
34
|
};
|
|
40
|
-
exports.validateSchema = validateSchema;
|
|
41
35
|
//# sourceMappingURL=validateSchema.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BasedSchema } from '../types';
|
|
2
|
-
import { BasedSchemaType, BasedSchemaFields } from '../types';
|
|
3
|
-
import { ArgsOpts, Path, Opts, Stopped, Collect } from './types';
|
|
4
|
-
import { ParseError } from '../error';
|
|
1
|
+
import { BasedSchema } from '../types.js';
|
|
2
|
+
import { BasedSchemaType, BasedSchemaFields } from '../types.js';
|
|
3
|
+
import { ArgsOpts, Path, Opts, Stopped, Collect } from './types.js';
|
|
4
|
+
import { ParseError } from '../error.js';
|
|
5
5
|
export declare class ArgsClass<T, K extends keyof BasedSchemaFields = keyof BasedSchemaFields> {
|
|
6
6
|
errors: any[];
|
|
7
7
|
id: number;
|