@based/schema 2.2.10 → 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 +87 -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} +6 -6
- 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,
|
|
@@ -81,58 +75,57 @@ const formatPatterns = {
|
|
|
81
75
|
};
|
|
82
76
|
const validateString = (args, value) => {
|
|
83
77
|
if (typeof value !== 'string') {
|
|
84
|
-
args.error(
|
|
78
|
+
args.error(ParseError.incorrectFormat);
|
|
85
79
|
return false;
|
|
86
80
|
}
|
|
87
81
|
if (args.fieldSchema.minLength && value.length < args.fieldSchema.minLength) {
|
|
88
|
-
args.error(
|
|
82
|
+
args.error(ParseError.subceedsMinimum);
|
|
89
83
|
return false;
|
|
90
84
|
}
|
|
91
85
|
if (args.fieldSchema.maxLength && value.length > args.fieldSchema.maxLength) {
|
|
92
|
-
args.error(
|
|
86
|
+
args.error(ParseError.exceedsMaximum);
|
|
93
87
|
return false;
|
|
94
88
|
}
|
|
95
89
|
if (args.fieldSchema.pattern) {
|
|
96
90
|
const re = new RegExp(args.fieldSchema.pattern);
|
|
97
91
|
if (!re.test(value)) {
|
|
98
|
-
args.error(
|
|
92
|
+
args.error(ParseError.incorrectFormat);
|
|
99
93
|
return false;
|
|
100
94
|
}
|
|
101
95
|
}
|
|
102
96
|
if (args.fieldSchema.format &&
|
|
103
97
|
!formatPatterns[args.fieldSchema.format](value)) {
|
|
104
|
-
args.error(
|
|
98
|
+
args.error(ParseError.incorrectFormat);
|
|
105
99
|
return false;
|
|
106
100
|
}
|
|
107
101
|
return true;
|
|
108
102
|
};
|
|
109
|
-
const string = async (args) => {
|
|
103
|
+
export const string = async (args) => {
|
|
110
104
|
if (!validateString(args, args.value)) {
|
|
111
105
|
return;
|
|
112
106
|
}
|
|
113
107
|
args.collect();
|
|
114
108
|
};
|
|
115
|
-
exports.string = string;
|
|
116
109
|
// --- bla
|
|
117
110
|
// if typeof === string
|
|
118
|
-
const text = async (args) => {
|
|
111
|
+
export const text = async (args) => {
|
|
119
112
|
const value = args.value;
|
|
120
113
|
args.stop();
|
|
121
114
|
if (value === null) {
|
|
122
|
-
args.error(
|
|
115
|
+
args.error(ParseError.incorrectFormat);
|
|
123
116
|
return;
|
|
124
117
|
}
|
|
125
118
|
if (typeof value === 'object') {
|
|
126
119
|
for (const key in value) {
|
|
127
120
|
if (key === '$merge') {
|
|
128
121
|
if (typeof value.$merge !== 'boolean') {
|
|
129
|
-
args.error(
|
|
122
|
+
args.error(ParseError.incorrectFormat);
|
|
130
123
|
return;
|
|
131
124
|
}
|
|
132
125
|
}
|
|
133
126
|
else if (key === '$delete') {
|
|
134
127
|
if (value[key] !== true) {
|
|
135
|
-
args.error(
|
|
128
|
+
args.error(ParseError.incorrectFormat);
|
|
136
129
|
return;
|
|
137
130
|
}
|
|
138
131
|
args.collect({ $delete: true });
|
|
@@ -148,13 +141,13 @@ const text = async (args) => {
|
|
|
148
141
|
}
|
|
149
142
|
else if (key === '$default') {
|
|
150
143
|
if (value[key] === null) {
|
|
151
|
-
args.error(
|
|
144
|
+
args.error(ParseError.incorrectFormat);
|
|
152
145
|
return;
|
|
153
146
|
}
|
|
154
147
|
if (typeof value[key] === 'object') {
|
|
155
148
|
for (const k in value[key]) {
|
|
156
149
|
if (!validateString(args, args.value[key][k])) {
|
|
157
|
-
args.error(
|
|
150
|
+
args.error(ParseError.incorrectFormat);
|
|
158
151
|
return;
|
|
159
152
|
}
|
|
160
153
|
args
|
|
@@ -167,15 +160,15 @@ const text = async (args) => {
|
|
|
167
160
|
}
|
|
168
161
|
}
|
|
169
162
|
else if (typeof value[key] !== 'string') {
|
|
170
|
-
args.error(
|
|
163
|
+
args.error(ParseError.incorrectFormat);
|
|
171
164
|
return;
|
|
172
165
|
}
|
|
173
166
|
else if (!args.target.$language) {
|
|
174
|
-
args.error(
|
|
167
|
+
args.error(ParseError.noLanguageFound);
|
|
175
168
|
return;
|
|
176
169
|
}
|
|
177
170
|
else if (!validateString(args, value[key])) {
|
|
178
|
-
args.error(
|
|
171
|
+
args.error(ParseError.incorrectFormat);
|
|
179
172
|
return;
|
|
180
173
|
}
|
|
181
174
|
else {
|
|
@@ -195,7 +188,7 @@ const text = async (args) => {
|
|
|
195
188
|
for (const k in value[key]) {
|
|
196
189
|
if (k === '$delete') {
|
|
197
190
|
if (value[key].$delete !== true) {
|
|
198
|
-
args.error(
|
|
191
|
+
args.error(ParseError.incorrectFormat);
|
|
199
192
|
return;
|
|
200
193
|
}
|
|
201
194
|
args
|
|
@@ -208,7 +201,7 @@ const text = async (args) => {
|
|
|
208
201
|
}
|
|
209
202
|
else if (k === '$value') {
|
|
210
203
|
if (!validateString(args, value[key].$value)) {
|
|
211
|
-
args.create({ key }).error(
|
|
204
|
+
args.create({ key }).error(ParseError.incorrectFormat);
|
|
212
205
|
}
|
|
213
206
|
else {
|
|
214
207
|
args
|
|
@@ -222,7 +215,7 @@ const text = async (args) => {
|
|
|
222
215
|
}
|
|
223
216
|
else if (k === '$default') {
|
|
224
217
|
if (!validateString(args, value[key].$default)) {
|
|
225
|
-
args.create({ key }).error(
|
|
218
|
+
args.create({ key }).error(ParseError.incorrectFormat);
|
|
226
219
|
}
|
|
227
220
|
else {
|
|
228
221
|
args
|
|
@@ -237,14 +230,14 @@ const text = async (args) => {
|
|
|
237
230
|
else {
|
|
238
231
|
args
|
|
239
232
|
.create({ path: [...args.path, key, k] })
|
|
240
|
-
.error(
|
|
233
|
+
.error(ParseError.fieldDoesNotExist);
|
|
241
234
|
return;
|
|
242
235
|
}
|
|
243
236
|
}
|
|
244
237
|
}
|
|
245
238
|
else {
|
|
246
239
|
if (!validateString(args, args.value[key])) {
|
|
247
|
-
args.error(
|
|
240
|
+
args.error(ParseError.incorrectFormat);
|
|
248
241
|
return;
|
|
249
242
|
}
|
|
250
243
|
args
|
|
@@ -257,7 +250,7 @@ const text = async (args) => {
|
|
|
257
250
|
}
|
|
258
251
|
}
|
|
259
252
|
else {
|
|
260
|
-
args.create({ key }).error(
|
|
253
|
+
args.create({ key }).error(ParseError.languageNotSupported);
|
|
261
254
|
}
|
|
262
255
|
}
|
|
263
256
|
if (!args._stopObject) {
|
|
@@ -266,15 +259,15 @@ const text = async (args) => {
|
|
|
266
259
|
return;
|
|
267
260
|
}
|
|
268
261
|
if (typeof value !== 'string') {
|
|
269
|
-
args.error(
|
|
262
|
+
args.error(ParseError.incorrectFormat);
|
|
270
263
|
return;
|
|
271
264
|
}
|
|
272
265
|
if (!args.target.$language) {
|
|
273
|
-
args.error(
|
|
266
|
+
args.error(ParseError.noLanguageFound);
|
|
274
267
|
return;
|
|
275
268
|
}
|
|
276
269
|
if (!validateString(args, args.value)) {
|
|
277
|
-
args.error(
|
|
270
|
+
args.error(ParseError.incorrectFormat);
|
|
278
271
|
return;
|
|
279
272
|
}
|
|
280
273
|
args
|
|
@@ -290,5 +283,4 @@ const text = async (args) => {
|
|
|
290
283
|
});
|
|
291
284
|
}
|
|
292
285
|
};
|
|
293
|
-
exports.text = text;
|
|
294
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[];
|
|
@@ -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;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const parse_1 = require("./parse");
|
|
6
|
-
const utils_1 = require("@saulx/utils");
|
|
1
|
+
import { Stopped } from './types.js';
|
|
2
|
+
import { parse } from './parse.js';
|
|
3
|
+
import { deepEqual } from '@saulx/utils';
|
|
7
4
|
let id = 0;
|
|
8
|
-
class ArgsClass {
|
|
5
|
+
export class ArgsClass {
|
|
9
6
|
constructor(opts, prev) {
|
|
10
7
|
this.id = ++id;
|
|
11
8
|
this.fromBackTrack = [];
|
|
@@ -81,10 +78,10 @@ class ArgsClass {
|
|
|
81
78
|
stop(onllyStopFieldSchemaParser) {
|
|
82
79
|
const target = this;
|
|
83
80
|
if (onllyStopFieldSchemaParser) {
|
|
84
|
-
target.stopped =
|
|
81
|
+
target.stopped = Stopped.onlyStopFieldParser;
|
|
85
82
|
}
|
|
86
83
|
else {
|
|
87
|
-
target.stopped =
|
|
84
|
+
target.stopped = Stopped.stopAll;
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
create(opts) {
|
|
@@ -102,7 +99,7 @@ class ArgsClass {
|
|
|
102
99
|
}
|
|
103
100
|
async parse(opts) {
|
|
104
101
|
if (!opts) {
|
|
105
|
-
return
|
|
102
|
+
return parse(this);
|
|
106
103
|
}
|
|
107
104
|
else {
|
|
108
105
|
const newArgs = new ArgsClass(opts, this);
|
|
@@ -126,7 +123,7 @@ class ArgsClass {
|
|
|
126
123
|
let p = this;
|
|
127
124
|
while (p) {
|
|
128
125
|
if (p.prev) {
|
|
129
|
-
if (
|
|
126
|
+
if (deepEqual(p.prev.path, p.path)) {
|
|
130
127
|
p = p.prev;
|
|
131
128
|
}
|
|
132
129
|
else {
|
|
@@ -158,5 +155,4 @@ class ArgsClass {
|
|
|
158
155
|
this.root._opts.error(code, this);
|
|
159
156
|
}
|
|
160
157
|
}
|
|
161
|
-
exports.ArgsClass = ArgsClass;
|
|
162
158
|
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BasedSchema } from '../types.js';
|
|
2
|
+
import { ArgsClass } from './args.js';
|
|
3
|
+
import { AsyncOperation, Opts } from './types.js';
|
|
4
|
+
export declare const walk: <T>(schema: BasedSchema, opts: Opts<T>, value: any, asyncOperationHandler?: AsyncOperation<T>) => Promise<T>;
|
|
5
|
+
export { ArgsClass };
|
|
6
|
+
export * from './types.js';
|