@based/schema 3.0.1 → 3.1.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/dist/src/compat/newToOld.d.ts +2 -2
- package/dist/src/compat/newToOld.js +31 -173
- package/dist/src/compat/oldToNew.d.ts +1 -1
- package/dist/src/compat/oldToNew.js +25 -200
- package/dist/src/set/fields/string.js +1 -0
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -0
- package/package.json +1 -1
- package/dist/display/index.d.ts +0 -2
- package/dist/display/index.js +0 -26
- package/dist/display/number.d.ts +0 -3
- package/dist/display/number.js +0 -89
- package/dist/display/string.d.ts +0 -3
- package/dist/display/string.js +0 -23
- package/dist/display/timestamp.d.ts +0 -3
- package/dist/display/timestamp.js +0 -127
- package/dist/error.d.ts +0 -19
- package/dist/error.js +0 -24
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -22
- package/dist/languages.d.ts +0 -187
- package/dist/languages.js +0 -190
- package/dist/set/fields/array.d.ts +0 -2
- package/dist/set/fields/array.js +0 -123
- package/dist/set/fields/index.d.ts +0 -3
- package/dist/set/fields/index.js +0 -74
- package/dist/set/fields/number.d.ts +0 -4
- package/dist/set/fields/number.js +0 -129
- package/dist/set/fields/object.d.ts +0 -3
- package/dist/set/fields/object.js +0 -33
- package/dist/set/fields/references.d.ts +0 -3
- package/dist/set/fields/references.js +0 -128
- package/dist/set/fields/set.d.ts +0 -2
- package/dist/set/fields/set.js +0 -63
- package/dist/set/fields/string.d.ts +0 -3
- package/dist/set/fields/string.js +0 -284
- package/dist/set/index.d.ts +0 -3
- package/dist/set/index.js +0 -183
- package/dist/set/isValidId.d.ts +0 -2
- package/dist/set/isValidId.js +0 -21
- package/dist/set/types.d.ts +0 -0
- package/dist/set/types.js +0 -1
- package/dist/types.d.ts +0 -205
- 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/validateSchema.js +0 -41
- package/dist/walker/args.d.ts +0 -36
- package/dist/walker/args.js +0 -162
- package/dist/walker/index.d.ts +0 -6
- package/dist/walker/index.js +0 -49
- package/dist/walker/parse.d.ts +0 -3
- package/dist/walker/parse.js +0 -186
- package/dist/walker/types.d.ts +0 -45
- package/dist/walker/types.js +0 -10
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import { BasedSchema } from '../types.js';
|
|
1
2
|
import { BasedOldSchema } from './oldSchemaType.js';
|
|
2
|
-
|
|
3
|
-
export declare const convertNewToOld: (schema: BasedSchemaPartial) => Partial<BasedOldSchema>;
|
|
3
|
+
export declare const convertNewToOld: (schema: BasedSchema) => Partial<BasedOldSchema>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const metaChecker = (field) => {
|
|
2
2
|
return (field === 'validation' ||
|
|
3
|
-
|
|
3
|
+
field === 'format' ||
|
|
4
4
|
field === 'index' ||
|
|
5
5
|
field === 'description' ||
|
|
6
6
|
field === 'title' ||
|
|
@@ -30,189 +30,47 @@ const metaChecker = (field) => {
|
|
|
30
30
|
field === 'maximum' ||
|
|
31
31
|
field === 'exclusiveMaximum' ||
|
|
32
32
|
field === 'exclusiveMinimum' ||
|
|
33
|
-
field === '$delete'
|
|
34
|
-
field === 'display');
|
|
33
|
+
field === '$delete');
|
|
35
34
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
// createdAt: { type: 'timestamp' },
|
|
39
|
-
// updatedAt: { type: 'timestamp' },
|
|
40
|
-
// type: { type: 'string' },
|
|
41
|
-
// parents: { type: 'references' },
|
|
42
|
-
// children: { type: 'references' },
|
|
43
|
-
// ancestors: { type: 'references' },
|
|
44
|
-
// descendants: { type: 'references' },
|
|
45
|
-
// aliases: {
|
|
46
|
-
// type: 'set',
|
|
47
|
-
// items: { type: 'string' },
|
|
48
|
-
// },
|
|
35
|
+
const excludedFields = (field) => {
|
|
36
|
+
return field === 'language' || field === 'translations' || field === '$defs';
|
|
49
37
|
};
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (i === '
|
|
55
|
-
|
|
38
|
+
export const convertNewToOld = (schema) => {
|
|
39
|
+
const tmpSchema = {};
|
|
40
|
+
const walker = (target, source) => {
|
|
41
|
+
for (const i in source) {
|
|
42
|
+
if (source[i] && typeof source[i] === 'object' && i in target === false) {
|
|
43
|
+
target[i] = source[i].length ? [] : {};
|
|
44
|
+
walker(target[i], source[i]);
|
|
56
45
|
}
|
|
57
|
-
else if (
|
|
58
|
-
|
|
46
|
+
else if (!metaChecker(i)) {
|
|
47
|
+
target[i] = source[i];
|
|
59
48
|
}
|
|
60
49
|
else {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
properties: migrateFields(field.properties, true),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else if (field?.type === 'json') {
|
|
76
|
-
return {
|
|
77
|
-
...field,
|
|
78
|
-
...metaParser(field),
|
|
79
|
-
type: 'json',
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
else if (field?.type === 'array') {
|
|
83
|
-
const values = migrateField(field.values);
|
|
84
|
-
if (!values) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
...metaParser(field),
|
|
89
|
-
type: 'array',
|
|
90
|
-
items: values,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
else if (field?.type === 'set') {
|
|
94
|
-
return {
|
|
95
|
-
...metaParser(field),
|
|
96
|
-
type: 'set',
|
|
97
|
-
items: migrateField(field.items),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
else if (field?.type === 'record') {
|
|
101
|
-
return {
|
|
102
|
-
...metaParser(field),
|
|
103
|
-
type: 'record',
|
|
104
|
-
values: migrateField(field.values),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else if (field?.type === 'reference' || field?.type === 'references') {
|
|
108
|
-
return {
|
|
109
|
-
...metaParser(field),
|
|
110
|
-
type: field?.type,
|
|
111
|
-
...(field.bidirectional ? { bidirectional: field.bidirectional } : null),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
else if (field?.type === 'integer') {
|
|
115
|
-
return {
|
|
116
|
-
...metaParser(field),
|
|
117
|
-
type: 'int',
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
else if (field?.format === 'strongPassword') {
|
|
121
|
-
return { ...metaParser(field), type: 'digest' };
|
|
122
|
-
}
|
|
123
|
-
else if (field?.format === 'basedId') {
|
|
124
|
-
return { ...metaParser(field), type: 'id' };
|
|
125
|
-
}
|
|
126
|
-
else if (field?.format === 'URL') {
|
|
127
|
-
return { ...metaParser(field), type: 'url' };
|
|
128
|
-
}
|
|
129
|
-
else if (field?.format === 'email') {
|
|
130
|
-
return {
|
|
131
|
-
...metaParser(field),
|
|
132
|
-
type: 'email',
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
else if (field?.format === 'mobilePhone') {
|
|
136
|
-
return {
|
|
137
|
-
...metaParser(field),
|
|
138
|
-
type: 'phone',
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
else if (field?.format === 'latLong') {
|
|
142
|
-
return {
|
|
143
|
-
...metaParser(field),
|
|
144
|
-
type: 'geo',
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
return { ...metaParser(field), type: field?.type };
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
const migrateFields = (oldFields, recursing = false) => {
|
|
152
|
-
const result = {};
|
|
153
|
-
if (oldFields) {
|
|
154
|
-
for (const key in oldFields) {
|
|
155
|
-
if (oldFields.hasOwnProperty(key)) {
|
|
156
|
-
if (!recursing && Object.keys(DEFAULT_FIELDS).includes(key)) {
|
|
157
|
-
continue;
|
|
50
|
+
target.meta = {};
|
|
51
|
+
for (const i in source) {
|
|
52
|
+
if (metaChecker(i) && typeof source[i] !== 'object') {
|
|
53
|
+
if (i === 'title') {
|
|
54
|
+
target.meta = { ...target.meta, name: source[i] };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
target.meta = { ...target.meta, [i]: source[i] };
|
|
58
|
+
}
|
|
59
|
+
delete source[i];
|
|
60
|
+
}
|
|
158
61
|
}
|
|
159
|
-
const field = migrateField(oldFields[key]);
|
|
160
|
-
if (!field) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
result[key] = field;
|
|
164
62
|
}
|
|
165
63
|
}
|
|
166
|
-
}
|
|
167
|
-
return result;
|
|
168
|
-
};
|
|
169
|
-
const migrateTypes = (oldSchema) => {
|
|
170
|
-
const result = {
|
|
171
|
-
types: {},
|
|
172
64
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
};
|
|
180
|
-
if (type.prefix) {
|
|
181
|
-
result.types[key].prefix = type.prefix;
|
|
182
|
-
}
|
|
65
|
+
walker(tmpSchema, schema);
|
|
66
|
+
if ((tmpSchema.meta = {}))
|
|
67
|
+
delete tmpSchema.meta;
|
|
68
|
+
for (const i in tmpSchema) {
|
|
69
|
+
if (excludedFields(i)) {
|
|
70
|
+
delete tmpSchema[i];
|
|
183
71
|
}
|
|
184
72
|
}
|
|
185
|
-
|
|
186
|
-
};
|
|
187
|
-
const convertRoot = (schema) => {
|
|
188
|
-
const result = {
|
|
189
|
-
fields: {},
|
|
190
|
-
...metaParser(schema.root),
|
|
191
|
-
...(schema.root?.prefix ? { prefix: schema.root.prefix } : null),
|
|
192
|
-
};
|
|
193
|
-
for (const i in schema.root?.fields) {
|
|
194
|
-
const field = schema.root?.fields[i];
|
|
195
|
-
result.fields[i] = {
|
|
196
|
-
...metaParser(field),
|
|
197
|
-
...migrateField(field),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
return result;
|
|
201
|
-
};
|
|
202
|
-
export const convertNewToOld = (schema) => {
|
|
203
|
-
const tmpSchema = migrateTypes(schema);
|
|
204
|
-
if (schema.prefixToTypeMapping) {
|
|
205
|
-
tmpSchema.prefixToTypeMapping = schema.prefixToTypeMapping;
|
|
206
|
-
}
|
|
207
|
-
tmpSchema.languages = [];
|
|
208
|
-
if (schema.language) {
|
|
209
|
-
tmpSchema.languages.push(schema.language);
|
|
210
|
-
}
|
|
211
|
-
if (schema.translations) {
|
|
212
|
-
tmpSchema.languages.push(...schema.translations);
|
|
213
|
-
}
|
|
214
|
-
tmpSchema.rootType = convertRoot(schema);
|
|
215
|
-
delete tmpSchema.root;
|
|
73
|
+
tmpSchema.languages = [schema.language, ...schema?.translations];
|
|
216
74
|
return tmpSchema;
|
|
217
75
|
};
|
|
218
76
|
//# sourceMappingURL=newToOld.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BasedSchema } from '../types.js';
|
|
2
2
|
import { BasedOldSchema } from './oldSchemaType.js';
|
|
3
|
-
export declare const convertOldToNew: (oldSchema:
|
|
3
|
+
export declare const convertOldToNew: (oldSchema: BasedOldSchema) => BasedSchema;
|
|
@@ -1,210 +1,35 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// ancestors: { type: 'references' },
|
|
9
|
-
// descendants: { type: 'references' },
|
|
10
|
-
// aliases: {
|
|
11
|
-
// type: 'set',
|
|
12
|
-
// items: { type: 'string' },
|
|
13
|
-
// },
|
|
14
|
-
};
|
|
15
|
-
const metaParser = (obj) => {
|
|
16
|
-
const metaObj = obj?.meta;
|
|
17
|
-
const tmp = {};
|
|
18
|
-
for (const i in metaObj) {
|
|
19
|
-
if (i === 'name') {
|
|
20
|
-
tmp.title = metaObj[i];
|
|
21
|
-
}
|
|
22
|
-
else if (i === 'validation' ||
|
|
23
|
-
i === 'progress' ||
|
|
24
|
-
i === 'format' ||
|
|
25
|
-
i === 'ui') {
|
|
26
|
-
if (metaObj[i] === 'url') {
|
|
27
|
-
// tmp.format = 'URL'
|
|
28
|
-
}
|
|
29
|
-
if ((metaObj[i] === 'bytes' && obj.type === 'number') ||
|
|
30
|
-
metaObj.type === 'float') {
|
|
31
|
-
tmp.display = 'bytes';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
tmp[i] = metaObj[i];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return tmp;
|
|
39
|
-
};
|
|
40
|
-
const migrateField = (oldField) => {
|
|
41
|
-
switch (oldField.type) {
|
|
42
|
-
case 'object':
|
|
43
|
-
return {
|
|
44
|
-
...metaParser(oldField),
|
|
45
|
-
type: 'object',
|
|
46
|
-
properties: migrateFields(oldField.properties, true),
|
|
47
|
-
};
|
|
48
|
-
case 'json':
|
|
49
|
-
return {
|
|
50
|
-
...oldField,
|
|
51
|
-
...metaParser(oldField),
|
|
52
|
-
type: 'json',
|
|
53
|
-
};
|
|
54
|
-
case 'array':
|
|
55
|
-
const values = migrateField(oldField.items);
|
|
56
|
-
if (!values) {
|
|
57
|
-
return null;
|
|
1
|
+
export const convertOldToNew = (oldSchema) => {
|
|
2
|
+
const tempSchema = {};
|
|
3
|
+
const walker = (source, target) => {
|
|
4
|
+
for (const i in source) {
|
|
5
|
+
if (i === 'languages' && source[i].length) {
|
|
6
|
+
target.language = source[i][0];
|
|
7
|
+
target.translations = source[i].filter((_, i) => i !== 0);
|
|
58
8
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case 'record':
|
|
71
|
-
return {
|
|
72
|
-
...metaParser(oldField),
|
|
73
|
-
type: 'record',
|
|
74
|
-
values: migrateField(oldField.values),
|
|
75
|
-
};
|
|
76
|
-
case 'reference':
|
|
77
|
-
case 'references':
|
|
78
|
-
return {
|
|
79
|
-
...metaParser(oldField),
|
|
80
|
-
type: oldField.type,
|
|
81
|
-
...(oldField.bidirectional
|
|
82
|
-
? { bidirectional: oldField.bidirectional }
|
|
83
|
-
: null),
|
|
84
|
-
};
|
|
85
|
-
case 'float':
|
|
86
|
-
return {
|
|
87
|
-
...metaParser(oldField),
|
|
88
|
-
type: 'number',
|
|
89
|
-
};
|
|
90
|
-
case 'int':
|
|
91
|
-
return {
|
|
92
|
-
...metaParser(oldField),
|
|
93
|
-
type: 'integer',
|
|
94
|
-
};
|
|
95
|
-
case 'digest':
|
|
96
|
-
return {
|
|
97
|
-
...metaParser(oldField),
|
|
98
|
-
format: 'strongPassword',
|
|
99
|
-
type: 'string',
|
|
100
|
-
};
|
|
101
|
-
case 'id':
|
|
102
|
-
return {
|
|
103
|
-
format: 'basedId',
|
|
104
|
-
...metaParser(oldField),
|
|
105
|
-
type: 'string',
|
|
106
|
-
};
|
|
107
|
-
case 'url':
|
|
108
|
-
return {
|
|
109
|
-
...metaParser(oldField),
|
|
110
|
-
format: 'URL',
|
|
111
|
-
type: 'string',
|
|
112
|
-
};
|
|
113
|
-
case 'email':
|
|
114
|
-
return {
|
|
115
|
-
format: 'email',
|
|
116
|
-
...metaParser(oldField),
|
|
117
|
-
type: 'string',
|
|
118
|
-
};
|
|
119
|
-
case 'phone':
|
|
120
|
-
return {
|
|
121
|
-
...metaParser(oldField),
|
|
122
|
-
format: 'mobilePhone',
|
|
123
|
-
type: 'string',
|
|
124
|
-
};
|
|
125
|
-
case 'geo':
|
|
126
|
-
return {
|
|
127
|
-
...metaParser(oldField),
|
|
128
|
-
format: 'latLong',
|
|
129
|
-
type: 'string',
|
|
130
|
-
};
|
|
131
|
-
case 'type':
|
|
132
|
-
return {
|
|
133
|
-
...metaParser(oldField),
|
|
134
|
-
type: 'string',
|
|
135
|
-
};
|
|
136
|
-
case 'number':
|
|
137
|
-
return {
|
|
138
|
-
...metaParser(oldField),
|
|
139
|
-
type: 'number',
|
|
140
|
-
};
|
|
141
|
-
default:
|
|
142
|
-
return {
|
|
143
|
-
...metaParser(oldField),
|
|
144
|
-
type: oldField.type,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
const migrateFields = (oldFields, recursing = false) => {
|
|
149
|
-
const result = {};
|
|
150
|
-
if (oldFields) {
|
|
151
|
-
for (const key in oldFields) {
|
|
152
|
-
if (true) {
|
|
153
|
-
if (!recursing && Object.keys(DEFAULT_FIELDS).includes(key)) {
|
|
154
|
-
continue;
|
|
9
|
+
else if (typeof source[i] === 'object' && i in target === false) {
|
|
10
|
+
if (i === 'meta' &&
|
|
11
|
+
!Object.keys(source[i]).includes('properties' || 'type')) {
|
|
12
|
+
for (const j in source[i]) {
|
|
13
|
+
if (j === 'name') {
|
|
14
|
+
target.title = source[i][j];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
target[j] = source[i][j];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
155
20
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
21
|
+
else {
|
|
22
|
+
target[i] = source[i].length ? [] : {};
|
|
23
|
+
walker(source[i], target[i]);
|
|
159
24
|
}
|
|
160
|
-
|
|
25
|
+
}
|
|
26
|
+
else if (i !== 'meta') {
|
|
27
|
+
target[i] = source[i];
|
|
161
28
|
}
|
|
162
29
|
}
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
};
|
|
166
|
-
const migrateTypes = (oldSchema) => {
|
|
167
|
-
const result = {
|
|
168
|
-
types: {},
|
|
169
|
-
};
|
|
170
|
-
for (const key in oldSchema.types) {
|
|
171
|
-
if (oldSchema.types.hasOwnProperty(key)) {
|
|
172
|
-
const type = oldSchema.types[key];
|
|
173
|
-
result.types[key] = {
|
|
174
|
-
...metaParser(type),
|
|
175
|
-
prefix: type.prefix,
|
|
176
|
-
fields: migrateFields(type.fields),
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
};
|
|
182
|
-
const convertRoot = (oldSchema) => {
|
|
183
|
-
const result = {
|
|
184
|
-
fields: {},
|
|
185
|
-
...metaParser(oldSchema.rootType?.meta),
|
|
186
|
-
...(oldSchema.rootType?.prefix
|
|
187
|
-
? { prefix: oldSchema.rootType.prefix }
|
|
188
|
-
: null),
|
|
189
30
|
};
|
|
190
|
-
|
|
191
|
-
const field = oldSchema.rootType?.fields[i];
|
|
192
|
-
result.fields[i] = {
|
|
193
|
-
...metaParser(field?.meta),
|
|
194
|
-
...migrateField(field),
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
198
|
-
};
|
|
199
|
-
export const convertOldToNew = (oldSchema) => {
|
|
200
|
-
const tempSchema = migrateTypes(oldSchema);
|
|
31
|
+
walker(oldSchema, tempSchema);
|
|
201
32
|
tempSchema.$defs = {};
|
|
202
|
-
tempSchema.language = oldSchema.languages[0];
|
|
203
|
-
tempSchema.prefixToTypeMapping = oldSchema.prefixToTypeMapping;
|
|
204
|
-
tempSchema.translations = oldSchema.languages.filter((_, i) => i !== 0);
|
|
205
|
-
tempSchema.root = convertRoot(oldSchema);
|
|
206
|
-
delete tempSchema.rootType;
|
|
207
|
-
delete tempSchema.sha;
|
|
208
33
|
return tempSchema;
|
|
209
34
|
};
|
|
210
35
|
//# sourceMappingURL=oldToNew.js.map
|
|
@@ -74,6 +74,7 @@ const formatPatterns = {
|
|
|
74
74
|
clike: () => true,
|
|
75
75
|
// Can add some more checks for this...
|
|
76
76
|
basedId: (value) => typeof value === 'string' && value.length < 16,
|
|
77
|
+
basedType: (value) => typeof value === 'string' && value.length < 64,
|
|
77
78
|
};
|
|
78
79
|
const validateString = (args, value) => {
|
|
79
80
|
if (typeof value !== 'string') {
|
package/dist/src/types.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type BasedSchemaFieldShared = {
|
|
|
43
43
|
};
|
|
44
44
|
$delete?: boolean;
|
|
45
45
|
};
|
|
46
|
-
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"];
|
|
46
|
+
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"];
|
|
47
47
|
export type BasedSchemaStringShared = {
|
|
48
48
|
minLength?: number;
|
|
49
49
|
maxLength?: number;
|
package/dist/src/types.js
CHANGED
package/package.json
CHANGED
package/dist/display/index.d.ts
DELETED
package/dist/display/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.display = void 0;
|
|
7
|
-
const timestamp_1 = __importDefault(require("./timestamp"));
|
|
8
|
-
const number_1 = __importDefault(require("./number"));
|
|
9
|
-
const string_1 = __importDefault(require("./string"));
|
|
10
|
-
const display = (value, field) => {
|
|
11
|
-
if (field.type === 'timestamp' && typeof value === 'number') {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
return (0, timestamp_1.default)(value, field.display);
|
|
14
|
-
}
|
|
15
|
-
if (field.type === 'number' && typeof value === 'number') {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return (0, number_1.default)(value, field.display);
|
|
18
|
-
}
|
|
19
|
-
if (field.type === 'string' && typeof value === 'string') {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
return (0, string_1.default)(value, field.display);
|
|
22
|
-
}
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
exports.display = display;
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
package/dist/display/number.d.ts
DELETED
package/dist/display/number.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const parseNumber = (nr, format) => {
|
|
4
|
-
if (!format) {
|
|
5
|
-
return nr;
|
|
6
|
-
}
|
|
7
|
-
if (typeof nr === 'number') {
|
|
8
|
-
if (format === 'euro' || format === 'dollar' || format === 'pound') {
|
|
9
|
-
const p = String(parseNumber(nr, 'short'));
|
|
10
|
-
const fraction = format === 'euro' ? ',' : '.';
|
|
11
|
-
const [s, f] = p.split('.');
|
|
12
|
-
return `${format === 'euro'
|
|
13
|
-
? '€'
|
|
14
|
-
: format === 'pound'
|
|
15
|
-
? '£'
|
|
16
|
-
: format === 'dollar'
|
|
17
|
-
? '$'
|
|
18
|
-
: ''}${s}${f ? `${fraction}${f}` : ''}`;
|
|
19
|
-
}
|
|
20
|
-
else if (format.startsWith('round-')) {
|
|
21
|
-
const [, fixed] = format.split('round-');
|
|
22
|
-
const n = Number(fixed);
|
|
23
|
-
if (!n) {
|
|
24
|
-
return `${nr.toFixed()}`;
|
|
25
|
-
}
|
|
26
|
-
return `${nr.toFixed(n)}`;
|
|
27
|
-
}
|
|
28
|
-
else if (format === 'bytes') {
|
|
29
|
-
const kb = nr / 1024;
|
|
30
|
-
const mb = kb / 1024;
|
|
31
|
-
const gb = mb / 1024;
|
|
32
|
-
if (gb >= 1) {
|
|
33
|
-
return `${gb.toFixed(2)} gb`;
|
|
34
|
-
}
|
|
35
|
-
else if (mb >= 1) {
|
|
36
|
-
return `${mb.toFixed(2)} mb`;
|
|
37
|
-
}
|
|
38
|
-
else if (kb >= 1) {
|
|
39
|
-
return `${kb.toFixed(2)} kb`;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return `${nr} ${nr === 1 ? 'byte' : 'bytes'}`;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else if (format === 'ratio') {
|
|
46
|
-
return `${Math.round(nr * 10000) / 100}%`;
|
|
47
|
-
}
|
|
48
|
-
else if (format === 'short') {
|
|
49
|
-
if (nr >= 10e9) {
|
|
50
|
-
nr = nr / 1e9;
|
|
51
|
-
nr = nr.toFixed(1);
|
|
52
|
-
if (nr[nr.length - 1] === '0') {
|
|
53
|
-
nr = nr.slice(0, -2);
|
|
54
|
-
}
|
|
55
|
-
return nr + 'b';
|
|
56
|
-
}
|
|
57
|
-
else if (nr >= 10e6) {
|
|
58
|
-
nr = nr / 1e6;
|
|
59
|
-
nr = nr.toFixed(1);
|
|
60
|
-
if (nr[nr.length - 1] === '0') {
|
|
61
|
-
nr = nr.slice(0, -2);
|
|
62
|
-
}
|
|
63
|
-
return nr + 'm';
|
|
64
|
-
}
|
|
65
|
-
else if (nr >= 10e3) {
|
|
66
|
-
nr = nr / 1e3;
|
|
67
|
-
nr = nr.toFixed(1);
|
|
68
|
-
if (nr[nr.length - 1] === '0') {
|
|
69
|
-
nr = nr.slice(0, -2);
|
|
70
|
-
}
|
|
71
|
-
return nr + 'k';
|
|
72
|
-
}
|
|
73
|
-
nr = nr.toFixed(2);
|
|
74
|
-
if (nr[nr.length - 1] === '0') {
|
|
75
|
-
nr = nr.slice(0, -3);
|
|
76
|
-
}
|
|
77
|
-
return String(nr);
|
|
78
|
-
}
|
|
79
|
-
else if (format === 'human') {
|
|
80
|
-
return nr.toFixed(2);
|
|
81
|
-
}
|
|
82
|
-
return String(nr);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
return nr;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
exports.default = parseNumber;
|
|
89
|
-
//# sourceMappingURL=number.js.map
|
package/dist/display/string.d.ts
DELETED
package/dist/display/string.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const parseString = (value, format) => {
|
|
4
|
-
if (!format) {
|
|
5
|
-
return value;
|
|
6
|
-
}
|
|
7
|
-
if (!value) {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
if (format === 'lowercase') {
|
|
11
|
-
return value.toLowerCase();
|
|
12
|
-
}
|
|
13
|
-
if (format === 'uppercase') {
|
|
14
|
-
return value.toUpperCase();
|
|
15
|
-
}
|
|
16
|
-
if (format === 'capitalize') {
|
|
17
|
-
const a = value[0];
|
|
18
|
-
return a.toUpperCase() + (value ? value.slice(1) : '');
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
};
|
|
22
|
-
exports.default = parseString;
|
|
23
|
-
//# sourceMappingURL=string.js.map
|