@based/schema 4.1.0 → 5.0.0-alpha.0
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 +152 -0
- package/dist/lang.js +149 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +24 -0
- package/dist/parse/assert.d.ts +1 -1
- package/dist/parse/assert.js +2 -2
- 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 +160 -68
- package/dist/parse/utils.d.ts +2 -2
- package/dist/parse/utils.js +11 -2
- package/dist/types.d.ts +66 -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
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
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type { Language } from './languages.js';
|
|
2
|
-
import type { PartialDeep } from 'type-fest';
|
|
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
|
-
export declare const basedSchemaFieldTypes: readonly ["array", "object", "record", "set", "string", "boolean", "number", "json", "integer", "timestamp", "created", "updated", "reference", "references", "text", "enum", "cardinality", "any"];
|
|
9
|
-
export type BasedSchemaFieldType = (typeof basedSchemaFieldTypes)[number];
|
|
10
|
-
export declare const isCollection: (type: string) => boolean;
|
|
11
|
-
export type BasedSchemaPattern = string;
|
|
12
|
-
export type BasedSchemaLanguage = Language;
|
|
13
|
-
export declare const languages: string[];
|
|
14
|
-
export type BasedSchemaTypePrefix = string;
|
|
15
|
-
export type BasedSchemaContentMediaType = 'text/html' | 'text/plain' | 'text/markdown' | 'image/png' | 'image/jpeg' | 'video/mp4' | 'image/*' | 'video/*' | 'audio/*' | '*/*' | `${string}/${string}`;
|
|
16
|
-
export type BasedSchemaFieldShared = {
|
|
17
|
-
hooks?: {
|
|
18
|
-
interval?: number;
|
|
19
|
-
hook: string;
|
|
20
|
-
} | {
|
|
21
|
-
interval?: number;
|
|
22
|
-
hook: string;
|
|
23
|
-
}[];
|
|
24
|
-
type?: BasedSchemaFieldType;
|
|
25
|
-
$id?: string;
|
|
26
|
-
$schema?: string;
|
|
27
|
-
isRequired?: boolean;
|
|
28
|
-
title?: string;
|
|
29
|
-
description?: string;
|
|
30
|
-
index?: number;
|
|
31
|
-
readOnly?: boolean;
|
|
32
|
-
writeOnly?: boolean;
|
|
33
|
-
$comment?: string;
|
|
34
|
-
examples?: any[];
|
|
35
|
-
default?: any;
|
|
36
|
-
customValidator?: (value: any, path: (number | string)[], target: BasedSetTarget) => Promise<boolean>;
|
|
37
|
-
$defs?: {
|
|
38
|
-
[key: string]: BasedSchemaField;
|
|
39
|
-
};
|
|
40
|
-
$delete?: boolean;
|
|
41
|
-
};
|
|
42
|
-
export declare const basedSchemaStringFormatValues: readonly ["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", "basedId", "basedType"];
|
|
43
|
-
export type BasedSchemaStringShared = {
|
|
44
|
-
minLength?: number;
|
|
45
|
-
maxLength?: number;
|
|
46
|
-
contentMediaEncoding?: string;
|
|
47
|
-
contentMediaType?: BasedSchemaContentMediaType;
|
|
48
|
-
pattern?: BasedSchemaPattern;
|
|
49
|
-
format?: (typeof basedSchemaStringFormatValues)[number];
|
|
50
|
-
display?: StringFormat;
|
|
51
|
-
multiline?: boolean;
|
|
52
|
-
};
|
|
53
|
-
export type BasedSchemaNumberDefaults = {
|
|
54
|
-
multipleOf?: number;
|
|
55
|
-
minimum?: number;
|
|
56
|
-
maximum?: number;
|
|
57
|
-
exclusiveMaximum?: boolean;
|
|
58
|
-
exclusiveMinimum?: boolean;
|
|
59
|
-
};
|
|
60
|
-
export type NumberDefaults = BasedSchemaNumberDefaults;
|
|
61
|
-
export type BasedNumberDisplay = NumberFormat;
|
|
62
|
-
export type BasedTimestampDisplay = DateFormat;
|
|
63
|
-
export type BasedSchemaFieldString = {
|
|
64
|
-
type: 'string';
|
|
65
|
-
} & BasedSchemaFieldShared & BasedSchemaStringShared;
|
|
66
|
-
export type BasedSchemaFieldEnum = {
|
|
67
|
-
enum: any[];
|
|
68
|
-
type?: '';
|
|
69
|
-
} & BasedSchemaFieldShared;
|
|
70
|
-
export type BasedSchemaFieldCardinality = {
|
|
71
|
-
type: 'cardinality';
|
|
72
|
-
} & BasedSchemaFieldShared;
|
|
73
|
-
export type BasedSchemaFieldNumber = NumberDefaults & {
|
|
74
|
-
type: 'number';
|
|
75
|
-
display?: BasedNumberDisplay;
|
|
76
|
-
} & BasedSchemaFieldShared;
|
|
77
|
-
export type BasedSchemaFieldInteger = NumberDefaults & {
|
|
78
|
-
type: 'integer';
|
|
79
|
-
display?: BasedNumberDisplay;
|
|
80
|
-
} & BasedSchemaFieldShared;
|
|
81
|
-
export type BasedSchemaFieldTimeStamp = NumberDefaults & {
|
|
82
|
-
type: 'timestamp';
|
|
83
|
-
display?: BasedTimestampDisplay;
|
|
84
|
-
} & BasedSchemaFieldShared;
|
|
85
|
-
export type BasedSchemaFieldBoolean = {
|
|
86
|
-
type: 'boolean';
|
|
87
|
-
} & BasedSchemaFieldShared;
|
|
88
|
-
export type BasedSchemaFieldJSON = {
|
|
89
|
-
type: 'json';
|
|
90
|
-
format?: 'rich-text';
|
|
91
|
-
} & BasedSchemaFieldShared;
|
|
92
|
-
export type BasedSchemaFieldAny = {
|
|
93
|
-
type: 'any';
|
|
94
|
-
} & BasedSchemaFieldShared;
|
|
95
|
-
export type BasedSchemaFieldPrimitive = BasedSchemaFieldString | BasedSchemaFieldNumber | BasedSchemaFieldInteger | BasedSchemaFieldTimeStamp | BasedSchemaFieldJSON | BasedSchemaFieldBoolean | BasedSchemaFieldEnum;
|
|
96
|
-
export type BasedSchemaFieldText = {
|
|
97
|
-
type: 'text';
|
|
98
|
-
required?: BasedSchemaLanguage[];
|
|
99
|
-
} & BasedSchemaFieldShared & BasedSchemaStringShared;
|
|
100
|
-
export type BasedSchemaFieldObject = {
|
|
101
|
-
type: 'object';
|
|
102
|
-
properties: {
|
|
103
|
-
[name: string]: BasedSchemaField;
|
|
104
|
-
};
|
|
105
|
-
required?: string[];
|
|
106
|
-
} & BasedSchemaFieldShared;
|
|
107
|
-
export type BasedSchemaFieldRecord = {
|
|
108
|
-
type: 'record';
|
|
109
|
-
values: BasedSchemaField;
|
|
110
|
-
} & BasedSchemaFieldShared;
|
|
111
|
-
export type BasedSchemaFieldArray = {
|
|
112
|
-
type: 'array';
|
|
113
|
-
items: BasedSchemaField;
|
|
114
|
-
} & BasedSchemaFieldShared;
|
|
115
|
-
export type BasedSchemaFieldSet = {
|
|
116
|
-
type: 'set';
|
|
117
|
-
items: BasedSchemaFieldPrimitive;
|
|
118
|
-
} & BasedSchemaFieldShared;
|
|
119
|
-
export type BasedSchemaFieldEnumerable = BasedSchemaFieldText | BasedSchemaFieldObject | BasedSchemaFieldRecord | BasedSchemaFieldArray | BasedSchemaFieldSet;
|
|
120
|
-
export type BasedSchemaFieldReference = {
|
|
121
|
-
type: 'reference';
|
|
122
|
-
allowedType: string;
|
|
123
|
-
inverseProperty?: string;
|
|
124
|
-
} & BasedSchemaFieldShared;
|
|
125
|
-
export type BasedSchemaFieldReferences = {
|
|
126
|
-
type: 'references';
|
|
127
|
-
allowedType: string;
|
|
128
|
-
inverseProperty?: string;
|
|
129
|
-
sortable?: boolean;
|
|
130
|
-
} & BasedSchemaFieldShared;
|
|
131
|
-
export type BasedSchemaFields = {
|
|
132
|
-
string: BasedSchemaFieldString;
|
|
133
|
-
number: BasedSchemaFieldNumber;
|
|
134
|
-
integer: BasedSchemaFieldInteger;
|
|
135
|
-
timestamp: BasedSchemaFieldTimeStamp;
|
|
136
|
-
json: BasedSchemaFieldJSON;
|
|
137
|
-
boolean: BasedSchemaFieldBoolean;
|
|
138
|
-
enum: BasedSchemaFieldEnum;
|
|
139
|
-
array: BasedSchemaFieldArray;
|
|
140
|
-
object: BasedSchemaFieldObject;
|
|
141
|
-
set: BasedSchemaFieldSet;
|
|
142
|
-
record: BasedSchemaFieldRecord;
|
|
143
|
-
reference: BasedSchemaFieldReference;
|
|
144
|
-
references: BasedSchemaFieldReferences;
|
|
145
|
-
text: BasedSchemaFieldText;
|
|
146
|
-
cardinality: BasedSchemaFieldCardinality;
|
|
147
|
-
any: BasedSchemaFieldAny;
|
|
148
|
-
};
|
|
149
|
-
export type BasedSchemaField = BasedSchemaFields[keyof BasedSchemaFields] | (BasedSchemaFieldShared & {
|
|
150
|
-
type?: '';
|
|
151
|
-
isRequired?: boolean;
|
|
152
|
-
$ref: string;
|
|
153
|
-
});
|
|
154
|
-
export type BasedSchemaType = {
|
|
155
|
-
directory?: string;
|
|
156
|
-
fields: {
|
|
157
|
-
[name: string]: BasedSchemaField;
|
|
158
|
-
};
|
|
159
|
-
title?: string;
|
|
160
|
-
description?: string;
|
|
161
|
-
prefix?: BasedSchemaTypePrefix;
|
|
162
|
-
examples?: any[];
|
|
163
|
-
required?: string[];
|
|
164
|
-
$defs?: {
|
|
165
|
-
[key: string]: BasedSchemaField;
|
|
166
|
-
};
|
|
167
|
-
$delete?: boolean;
|
|
168
|
-
};
|
|
169
|
-
export type BasedSchema = {
|
|
170
|
-
language: BasedSchemaLanguage;
|
|
171
|
-
translations?: BasedSchemaLanguage[];
|
|
172
|
-
languageFallbacks?: Partial<Record<BasedSchemaLanguage, BasedSchemaLanguage[]>>;
|
|
173
|
-
root: BasedSchemaType;
|
|
174
|
-
$defs: {
|
|
175
|
-
[name: string]: BasedSchemaField;
|
|
176
|
-
};
|
|
177
|
-
types: {
|
|
178
|
-
[type: string]: BasedSchemaType;
|
|
179
|
-
};
|
|
180
|
-
prefixToTypeMapping: {
|
|
181
|
-
[prefix: string]: string;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
export type BasedSchemaTypePartial = PartialDeep<BasedSchemaType>;
|
|
185
|
-
export type BasedSchemaFieldPartial = PartialDeep<BasedSchemaField>;
|
|
186
|
-
export type BasedSchemaPartial = PartialDeep<BasedSchema>;
|
|
187
|
-
export type BasedSetTarget = {
|
|
188
|
-
type: string;
|
|
189
|
-
$alias?: string;
|
|
190
|
-
$id?: string;
|
|
191
|
-
schema: BasedSchema;
|
|
192
|
-
$merge?: boolean;
|
|
193
|
-
$language?: BasedSchemaLanguage;
|
|
194
|
-
required: (number | string)[][];
|
|
195
|
-
collected: BasedSchemaCollectProps[];
|
|
196
|
-
errors: {
|
|
197
|
-
code: ParseError;
|
|
198
|
-
path: Path;
|
|
199
|
-
}[];
|
|
200
|
-
};
|
|
201
|
-
export type BasedSchemaCollectProps = ArgsClass<BasedSetTarget> & {
|
|
202
|
-
root: ArgsClass<BasedSetTarget> & {
|
|
203
|
-
typeSchema: BasedSchemaType;
|
|
204
|
-
};
|
|
205
|
-
};
|
package/dist/src/types.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { languages as allLanguages } from './languages.js';
|
|
2
|
-
// Schema type
|
|
3
|
-
// inspiration from https://json-schema.org/understanding-json-schema/index.html
|
|
4
|
-
// but added a few extra types
|
|
5
|
-
// reference
|
|
6
|
-
// references
|
|
7
|
-
// set
|
|
8
|
-
// record
|
|
9
|
-
// https://json-schema.org/learn/examples/geographical-location.schema.json
|
|
10
|
-
// contentSchema can be used for JSON types as well
|
|
11
|
-
// contentSchema can be used for reference / refrences
|
|
12
|
-
// TODO parser / validator / parseOut / parseIn (parsIn after validator)
|
|
13
|
-
// for refs etc check https://json-schema.org/understanding-json-schema/structuring.html#defs
|
|
14
|
-
export const basedSchemaFieldTypes = [
|
|
15
|
-
'array',
|
|
16
|
-
'object',
|
|
17
|
-
'record',
|
|
18
|
-
'set',
|
|
19
|
-
'string',
|
|
20
|
-
'boolean',
|
|
21
|
-
'number',
|
|
22
|
-
'json',
|
|
23
|
-
'integer',
|
|
24
|
-
'timestamp',
|
|
25
|
-
'created',
|
|
26
|
-
'updated',
|
|
27
|
-
'reference',
|
|
28
|
-
'references',
|
|
29
|
-
'text',
|
|
30
|
-
'enum',
|
|
31
|
-
'cardinality',
|
|
32
|
-
'any',
|
|
33
|
-
];
|
|
34
|
-
export const isCollection = (type) => {
|
|
35
|
-
return type === 'array' || type === 'object' || type === 'record';
|
|
36
|
-
};
|
|
37
|
-
export const languages = Object.keys(allLanguages);
|
|
38
|
-
export const basedSchemaStringFormatValues = [
|
|
39
|
-
'email',
|
|
40
|
-
'URL',
|
|
41
|
-
'MACAddress',
|
|
42
|
-
'IP',
|
|
43
|
-
'IPRange',
|
|
44
|
-
'FQDN',
|
|
45
|
-
'IBAN',
|
|
46
|
-
'BIC',
|
|
47
|
-
'alpha',
|
|
48
|
-
'alphaLocales',
|
|
49
|
-
'alphanumeric',
|
|
50
|
-
'alphanumericLocales',
|
|
51
|
-
'passportNumber',
|
|
52
|
-
'port',
|
|
53
|
-
'lowercase',
|
|
54
|
-
'uppercase',
|
|
55
|
-
'ascii',
|
|
56
|
-
'semVer',
|
|
57
|
-
'surrogatePair',
|
|
58
|
-
'IMEI',
|
|
59
|
-
'hexadecimal',
|
|
60
|
-
'octal',
|
|
61
|
-
'hexColor',
|
|
62
|
-
'rgbColor',
|
|
63
|
-
'HSL',
|
|
64
|
-
'ISRC',
|
|
65
|
-
'MD5',
|
|
66
|
-
'JWT',
|
|
67
|
-
'UUID',
|
|
68
|
-
'luhnNumber',
|
|
69
|
-
'creditCard',
|
|
70
|
-
'identityCard',
|
|
71
|
-
'EAN',
|
|
72
|
-
'ISIN',
|
|
73
|
-
'ISBN',
|
|
74
|
-
'ISSN',
|
|
75
|
-
'mobilePhone',
|
|
76
|
-
'mobilePhoneLocales',
|
|
77
|
-
'postalCode',
|
|
78
|
-
'postalCodeLocales',
|
|
79
|
-
'ethereumAddress',
|
|
80
|
-
'currency',
|
|
81
|
-
'btcAddress',
|
|
82
|
-
'ISO6391',
|
|
83
|
-
'ISO8601',
|
|
84
|
-
'RFC3339',
|
|
85
|
-
'ISO31661Alpha2',
|
|
86
|
-
'ISO31661Alpha3',
|
|
87
|
-
'ISO4217',
|
|
88
|
-
'base32',
|
|
89
|
-
'base58',
|
|
90
|
-
'base64',
|
|
91
|
-
'dataURI',
|
|
92
|
-
'magnetURI',
|
|
93
|
-
'mimeType',
|
|
94
|
-
'latLong',
|
|
95
|
-
'slug',
|
|
96
|
-
'strongPassword',
|
|
97
|
-
'taxID',
|
|
98
|
-
'licensePlate',
|
|
99
|
-
'VAT',
|
|
100
|
-
'code',
|
|
101
|
-
'typescript',
|
|
102
|
-
'javascript',
|
|
103
|
-
'python',
|
|
104
|
-
'rust',
|
|
105
|
-
'css',
|
|
106
|
-
'html',
|
|
107
|
-
'json',
|
|
108
|
-
'markdown',
|
|
109
|
-
'clike',
|
|
110
|
-
'basedId',
|
|
111
|
-
'basedType',
|
|
112
|
-
];
|
|
113
|
-
//# sourceMappingURL=types.js.map
|
package/dist/src/updateSchema.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { deepEqual } from '@saulx/utils';
|
|
2
|
-
import { ParseError } from '../error.js';
|
|
3
|
-
import { mustBeBoolean, mustBeString, mustBeStringArray } from './utils.js';
|
|
4
|
-
import { mustBeFields } from './fieldValidators.js';
|
|
5
|
-
export const basedSchemaTypeValidator = {
|
|
6
|
-
directory: {
|
|
7
|
-
validator: mustBeString,
|
|
8
|
-
optional: true,
|
|
9
|
-
},
|
|
10
|
-
fields: {
|
|
11
|
-
validator: mustBeFields,
|
|
12
|
-
},
|
|
13
|
-
title: {
|
|
14
|
-
validator: mustBeString,
|
|
15
|
-
optional: true,
|
|
16
|
-
},
|
|
17
|
-
description: {
|
|
18
|
-
validator: mustBeString,
|
|
19
|
-
optional: true,
|
|
20
|
-
},
|
|
21
|
-
prefix: {
|
|
22
|
-
validator: (value, path) => {
|
|
23
|
-
if (deepEqual(path, ['root', 'prefix'])) {
|
|
24
|
-
return value === 'ro'
|
|
25
|
-
? []
|
|
26
|
-
: [{ code: ParseError.incorrectFormat, path }];
|
|
27
|
-
}
|
|
28
|
-
return /^[a-z]{2}$/.test(value)
|
|
29
|
-
? []
|
|
30
|
-
: [{ code: ParseError.incorrectFormat, path }];
|
|
31
|
-
},
|
|
32
|
-
optional: true,
|
|
33
|
-
},
|
|
34
|
-
examples: { optional: true },
|
|
35
|
-
required: {
|
|
36
|
-
validator: mustBeStringArray,
|
|
37
|
-
optional: true,
|
|
38
|
-
},
|
|
39
|
-
$defs: { optional: true },
|
|
40
|
-
$delete: {
|
|
41
|
-
validator: mustBeBoolean,
|
|
42
|
-
optional: true,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=basedSchemaTypeValidator.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BasedSchema, BasedSchemaFieldAny, BasedSchemaFieldArray, BasedSchemaFieldBoolean, BasedSchemaFieldCardinality, BasedSchemaFieldEnum, BasedSchemaFieldInteger, BasedSchemaFieldJSON, BasedSchemaFieldNumber, BasedSchemaFieldObject, BasedSchemaFieldRecord, BasedSchemaFieldReference, BasedSchemaFieldReferences, BasedSchemaFieldSet, BasedSchemaFieldShared, BasedSchemaFieldString, BasedSchemaFieldText, BasedSchemaFieldTimeStamp, BasedSchemaNumberDefaults, BasedSchemaPartial, BasedSchemaStringShared } from '../types.js';
|
|
2
|
-
import { ValidateSchemaError, Validator } from './index.js';
|
|
3
|
-
type MustBeFieldOptions = {
|
|
4
|
-
limitTo?: 'primitives' | 'enumerables';
|
|
5
|
-
};
|
|
6
|
-
export declare const mustBeField: (value: any, path: string[], newSchema: BasedSchemaPartial, oldSchema: BasedSchema, options?: MustBeFieldOptions) => ValidateSchemaError[];
|
|
7
|
-
export declare const mustBeFields: (value: any, path: string[], newSchema: BasedSchemaPartial, oldSchema: BasedSchema) => ValidateSchemaError[];
|
|
8
|
-
export declare const basedSchemaFieldSharedValidator: Validator<BasedSchemaFieldShared>;
|
|
9
|
-
export declare const basedSchemaStringSharedValidator: Validator<BasedSchemaStringShared>;
|
|
10
|
-
export declare const basedSchemaStringValidator: Validator<BasedSchemaFieldString>;
|
|
11
|
-
export declare const basedSchemaFieldEnumValidator: Validator<BasedSchemaFieldEnum>;
|
|
12
|
-
export declare const basedSchemaFieldCardinalityValidator: Validator<BasedSchemaFieldCardinality>;
|
|
13
|
-
export declare const basedSchemaNumberDefaultsValidator: Validator<BasedSchemaNumberDefaults>;
|
|
14
|
-
export declare const basedSchemaFieldNumberValidator: Validator<BasedSchemaFieldNumber>;
|
|
15
|
-
export declare const basedSchemaFieldIntegerValidator: Validator<BasedSchemaFieldInteger>;
|
|
16
|
-
export declare const basedSchemaFieldTimeStampValidator: Validator<BasedSchemaFieldTimeStamp>;
|
|
17
|
-
export declare const basedSchemaFieldBooleanValidator: Validator<BasedSchemaFieldBoolean>;
|
|
18
|
-
export declare const basedSchemaFieldJSONValidator: Validator<BasedSchemaFieldJSON>;
|
|
19
|
-
export declare const basedSchemaFieldAnyValidator: Validator<BasedSchemaFieldAny>;
|
|
20
|
-
export declare const basedSchemaFieldTextValidator: Validator<BasedSchemaFieldText>;
|
|
21
|
-
export declare const basedSchemaFieldObjectValidator: Validator<BasedSchemaFieldObject>;
|
|
22
|
-
export declare const basedSchemaFieldRecordValidator: Validator<BasedSchemaFieldRecord>;
|
|
23
|
-
export declare const basedSchemaFieldArrayValidator: Validator<BasedSchemaFieldArray>;
|
|
24
|
-
export declare const basedSchemaFieldSetValidator: Validator<BasedSchemaFieldSet>;
|
|
25
|
-
export declare const basedSchemaFieldReferenceValidator: Validator<BasedSchemaFieldReference>;
|
|
26
|
-
export declare const basedSchemaFieldReferencesValidator: Validator<BasedSchemaFieldReferences>;
|
|
27
|
-
export {};
|