@based/schema 4.1.1 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lang.d.ts +153 -0
- package/dist/lang.js +153 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +24 -0
- package/dist/parse/assert.d.ts +2 -1
- package/dist/parse/assert.js +9 -3
- package/dist/parse/errors.d.ts +2 -0
- package/dist/parse/errors.js +2 -0
- package/dist/parse/index.d.ts +5 -4
- package/dist/parse/index.js +43 -41
- package/dist/parse/props.js +168 -75
- package/dist/parse/utils.d.ts +2 -2
- package/dist/parse/utils.js +11 -2
- package/dist/types.d.ts +72 -23
- package/dist/types.js +93 -0
- package/package.json +4 -3
- package/dist/parsePayload/index.d.ts +0 -3
- package/dist/parsePayload/index.js +0 -2
- package/dist/parseSchema/assert.d.ts +0 -6
- package/dist/parseSchema/assert.js +0 -27
- package/dist/parseSchema/errors.d.ts +0 -19
- package/dist/parseSchema/errors.js +0 -19
- package/dist/parseSchema/index.d.ts +0 -20
- package/dist/parseSchema/index.js +0 -132
- package/dist/parseSchema/props.d.ts +0 -7
- package/dist/parseSchema/props.js +0 -256
- package/dist/parseSchema/utils.d.ts +0 -3
- package/dist/parseSchema/utils.js +0 -29
- package/dist/src/compat/index.d.ts +0 -6
- package/dist/src/compat/index.js +0 -217
- package/dist/src/compat/oldSchemaType.d.ts +0 -93
- package/dist/src/compat/oldSchemaType.js +0 -2
- package/dist/src/display/index.d.ts +0 -2
- package/dist/src/display/index.js +0 -16
- package/dist/src/display/number.d.ts +0 -4
- package/dist/src/display/number.js +0 -97
- package/dist/src/display/string.d.ts +0 -5
- package/dist/src/display/string.js +0 -26
- package/dist/src/display/timestamp.d.ts +0 -5
- package/dist/src/display/timestamp.js +0 -134
- package/dist/src/error.d.ts +0 -21
- package/dist/src/error.js +0 -23
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -7
- package/dist/src/languages.d.ts +0 -188
- package/dist/src/languages.js +0 -188
- package/dist/src/set/fields/array.d.ts +0 -2
- package/dist/src/set/fields/array.js +0 -119
- package/dist/src/set/fields/index.d.ts +0 -3
- package/dist/src/set/fields/index.js +0 -85
- package/dist/src/set/fields/number.d.ts +0 -4
- package/dist/src/set/fields/number.js +0 -123
- package/dist/src/set/fields/object.d.ts +0 -3
- package/dist/src/set/fields/object.js +0 -28
- package/dist/src/set/fields/references.d.ts +0 -3
- package/dist/src/set/fields/references.js +0 -136
- package/dist/src/set/fields/set.d.ts +0 -2
- package/dist/src/set/fields/set.js +0 -59
- package/dist/src/set/fields/string.d.ts +0 -3
- package/dist/src/set/fields/string.js +0 -289
- package/dist/src/set/index.d.ts +0 -3
- package/dist/src/set/index.js +0 -205
- package/dist/src/set/isValidId.d.ts +0 -2
- package/dist/src/set/isValidId.js +0 -17
- package/dist/src/types.d.ts +0 -205
- package/dist/src/types.js +0 -113
- package/dist/src/updateSchema.d.ts +0 -2
- package/dist/src/updateSchema.js +0 -12
- package/dist/src/validateSchema/basedSchemaTypeValidator.d.ts +0 -3
- package/dist/src/validateSchema/basedSchemaTypeValidator.js +0 -45
- package/dist/src/validateSchema/fieldValidators.d.ts +0 -27
- package/dist/src/validateSchema/fieldValidators.js +0 -360
- package/dist/src/validateSchema/index.d.ts +0 -17
- package/dist/src/validateSchema/index.js +0 -109
- package/dist/src/validateSchema/utils.d.ts +0 -25
- package/dist/src/validateSchema/utils.js +0 -61
- package/dist/src/walker/args.d.ts +0 -36
- package/dist/src/walker/args.js +0 -158
- package/dist/src/walker/index.d.ts +0 -6
- package/dist/src/walker/index.js +0 -31
- package/dist/src/walker/parse.d.ts +0 -3
- package/dist/src/walker/parse.js +0 -182
- package/dist/src/walker/types.d.ts +0 -45
- package/dist/src/walker/types.js +0 -7
- package/dist/test/array.d.ts +0 -1
- package/dist/test/array.js +0 -342
- package/dist/test/compat.d.ts +0 -1
- package/dist/test/compat.js +0 -97
- package/dist/test/data/newSchemas.d.ts +0 -2
- package/dist/test/data/newSchemas.js +0 -489
- package/dist/test/data/oldSchemas.d.ts +0 -2
- package/dist/test/data/oldSchemas.js +0 -5058
- package/dist/test/display.d.ts +0 -1
- package/dist/test/display.js +0 -103
- package/dist/test/json.d.ts +0 -1
- package/dist/test/json.js +0 -40
- package/dist/test/number.d.ts +0 -1
- package/dist/test/number.js +0 -374
- package/dist/test/reference.d.ts +0 -1
- package/dist/test/reference.js +0 -188
- package/dist/test/rest.d.ts +0 -1
- package/dist/test/rest.js +0 -168
- package/dist/test/set.d.ts +0 -1
- package/dist/test/set.js +0 -95
- package/dist/test/string.d.ts +0 -1
- package/dist/test/string.js +0 -120
- package/dist/test/text.d.ts +0 -1
- package/dist/test/text.js +0 -324
- package/dist/test/utils/index.d.ts +0 -11
- package/dist/test/utils/index.js +0 -17
- package/dist/test/validateSchema/basic.d.ts +0 -1
- package/dist/test/validateSchema/basic.js +0 -94
- package/dist/test/validateSchema/fields.d.ts +0 -1
- package/dist/test/validateSchema/fields.js +0 -436
- package/dist/test/validateSchema/languages.d.ts +0 -1
- package/dist/test/validateSchema/languages.js +0 -124
- package/dist/test/validateSchema/realWorld.d.ts +0 -1
- package/dist/test/validateSchema/realWorld.js +0 -13
- package/dist/test/walker.d.ts +0 -1
- package/dist/test/walker.js +0 -289
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { expectBoolean, expectFunction, expectObject, expectString, expectNumber, } from './assert.js';
|
|
2
|
-
import { EXPECTED_ARR, EXPECTED_DATE, EXPECTED_OBJ, EXPECTED_PRIMITIVE, EXPECTED_VALUE_IN_ENUM, INVALID_VALUE, MIN_MAX, OUT_OF_RANGE, TEXT_REQUIRES_LOCALES, TYPE_MISMATCH, UNKNOWN_PROP, } from './errors.js';
|
|
3
|
-
import { getPropType } from './utils.js';
|
|
4
|
-
const shared = {
|
|
5
|
-
type() { },
|
|
6
|
-
required(val) {
|
|
7
|
-
expectBoolean(val);
|
|
8
|
-
},
|
|
9
|
-
query(val) {
|
|
10
|
-
expectFunction(val);
|
|
11
|
-
},
|
|
12
|
-
path(val, prop, ctx) {
|
|
13
|
-
expectString(val);
|
|
14
|
-
const path = val.split('.');
|
|
15
|
-
let t = ctx.type;
|
|
16
|
-
for (const key of path) {
|
|
17
|
-
if ('items' in t) {
|
|
18
|
-
t = t.items;
|
|
19
|
-
}
|
|
20
|
-
if ('ref' in t) {
|
|
21
|
-
t = ctx.schema.types[t.ref];
|
|
22
|
-
}
|
|
23
|
-
t = t.props[key];
|
|
24
|
-
expectObject(t);
|
|
25
|
-
}
|
|
26
|
-
if (t.type !== getPropType(prop)) {
|
|
27
|
-
throw Error(TYPE_MISMATCH);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
function propParser(required, optional, allowShorthand) {
|
|
32
|
-
return (prop, ctx) => {
|
|
33
|
-
if (typeof prop === 'string') {
|
|
34
|
-
// allow string
|
|
35
|
-
if (allowShorthand === 0) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
throw Error(EXPECTED_OBJ);
|
|
39
|
-
}
|
|
40
|
-
if (Array.isArray(prop)) {
|
|
41
|
-
// allow array
|
|
42
|
-
if (allowShorthand === 1) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
throw Error(EXPECTED_OBJ);
|
|
46
|
-
}
|
|
47
|
-
for (const key in required) {
|
|
48
|
-
required[key](prop[key], prop, ctx);
|
|
49
|
-
}
|
|
50
|
-
for (const key in prop) {
|
|
51
|
-
const val = prop[key];
|
|
52
|
-
if (key in optional) {
|
|
53
|
-
optional[key](val, prop, ctx);
|
|
54
|
-
}
|
|
55
|
-
else if (key in shared) {
|
|
56
|
-
shared[key](val, prop, ctx);
|
|
57
|
-
}
|
|
58
|
-
else if (!(key in required)) {
|
|
59
|
-
if (key[0] === '$' && 'ref' in prop) {
|
|
60
|
-
optional.edge(val, prop, ctx, key);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw Error(UNKNOWN_PROP);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const p = {};
|
|
70
|
-
p.boolean = propParser({}, {
|
|
71
|
-
default(val) {
|
|
72
|
-
expectBoolean(val);
|
|
73
|
-
},
|
|
74
|
-
}, 0);
|
|
75
|
-
p.enum = propParser({
|
|
76
|
-
enum(items) {
|
|
77
|
-
if (!Array.isArray(items)) {
|
|
78
|
-
throw Error(EXPECTED_ARR);
|
|
79
|
-
}
|
|
80
|
-
if (items.length > 255) {
|
|
81
|
-
throw Error('Max enum length (255) exceeded');
|
|
82
|
-
}
|
|
83
|
-
for (const item of items) {
|
|
84
|
-
if (typeof item === 'object') {
|
|
85
|
-
throw Error(EXPECTED_PRIMITIVE);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
}, {
|
|
90
|
-
default(val, prop) {
|
|
91
|
-
if (!prop.enum.includes(val)) {
|
|
92
|
-
throw Error(EXPECTED_VALUE_IN_ENUM);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
}, 1);
|
|
96
|
-
p.number = propParser({
|
|
97
|
-
min(val) {
|
|
98
|
-
expectNumber(val);
|
|
99
|
-
},
|
|
100
|
-
max(val, prop) {
|
|
101
|
-
expectNumber(val);
|
|
102
|
-
if (prop.min > val) {
|
|
103
|
-
throw Error(MIN_MAX);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
step(val) {
|
|
107
|
-
if (typeof val !== 'number' && val !== 'any') {
|
|
108
|
-
throw Error(INVALID_VALUE);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
}, {
|
|
112
|
-
default(val, prop) {
|
|
113
|
-
expectNumber(val);
|
|
114
|
-
if (val > prop.max || val < prop.min) {
|
|
115
|
-
throw Error(OUT_OF_RANGE);
|
|
116
|
-
}
|
|
117
|
-
if (prop.step !== 'any') {
|
|
118
|
-
const min = typeof prop.min !== 'number' || prop.min === Infinity ? 0 : prop.min;
|
|
119
|
-
const v = val - min;
|
|
120
|
-
if (~~(v / prop.step) * prop.step !== v) {
|
|
121
|
-
throw Error(INVALID_VALUE);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
}, 0);
|
|
126
|
-
p.object = propParser({
|
|
127
|
-
props(val, prop, ctx) {
|
|
128
|
-
ctx.parseProps(val, ctx.type);
|
|
129
|
-
},
|
|
130
|
-
}, {
|
|
131
|
-
default(val) {
|
|
132
|
-
console.warn('TODO object default value');
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
p.reference = propParser({
|
|
136
|
-
ref(ref, _prop, { schema }) {
|
|
137
|
-
schema.types[ref].props;
|
|
138
|
-
},
|
|
139
|
-
prop(propKey, prop, { schema, type, inQuery }) {
|
|
140
|
-
const propAllowed = type && !inQuery;
|
|
141
|
-
if (propAllowed) {
|
|
142
|
-
expectString(propKey);
|
|
143
|
-
let targetProp = schema.types[prop.ref].props[propKey];
|
|
144
|
-
if ('items' in targetProp) {
|
|
145
|
-
targetProp = targetProp.items;
|
|
146
|
-
}
|
|
147
|
-
if ('ref' in targetProp && 'prop' in targetProp) {
|
|
148
|
-
let t = schema.types[targetProp.ref].props[targetProp.prop];
|
|
149
|
-
if ('items' in t) {
|
|
150
|
-
t = t.items;
|
|
151
|
-
}
|
|
152
|
-
if (t === prop) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
throw Error(INVALID_VALUE);
|
|
157
|
-
}
|
|
158
|
-
if (propKey !== undefined) {
|
|
159
|
-
throw Error('ref prop not supported on root or edge p');
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
}, {
|
|
163
|
-
default(val) {
|
|
164
|
-
expectString(val);
|
|
165
|
-
},
|
|
166
|
-
edge(val, prop, ctx, key) {
|
|
167
|
-
const edgeAllowed = ctx.type && !ctx.inQuery;
|
|
168
|
-
if (edgeAllowed) {
|
|
169
|
-
let t = ctx.schema.types[prop.ref].props[prop.prop];
|
|
170
|
-
t = t.items || t;
|
|
171
|
-
if (t[key]) {
|
|
172
|
-
throw Error('Edge can not be defined on both props');
|
|
173
|
-
}
|
|
174
|
-
const edgePropType = getPropType(val);
|
|
175
|
-
p[edgePropType](val, ctx);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
throw Error('ref edge not supported on root or edge p');
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
p.set = propParser({
|
|
182
|
-
items(items, prop, ctx) {
|
|
183
|
-
expectObject(items);
|
|
184
|
-
const itemsType = getPropType(items);
|
|
185
|
-
if (itemsType === 'string' ||
|
|
186
|
-
itemsType === 'number' ||
|
|
187
|
-
itemsType === 'timestamp' ||
|
|
188
|
-
itemsType === 'boolean') {
|
|
189
|
-
ctx.inQuery = 'query' in prop;
|
|
190
|
-
p[itemsType](items, ctx);
|
|
191
|
-
ctx.inQuery = false;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
throw new Error(INVALID_VALUE);
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
}, {
|
|
198
|
-
default(val, prop) {
|
|
199
|
-
console.warn('TODO SET DEFAULT VALUE');
|
|
200
|
-
// if (typeof val === 'object') {
|
|
201
|
-
// throwErr(ERRORS.EXPECTED_PRIMITIVE, prop, 'default')
|
|
202
|
-
// }
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
p.references = propParser({
|
|
206
|
-
items(items, prop, ctx) {
|
|
207
|
-
expectObject(items);
|
|
208
|
-
const itemsType = getPropType(items);
|
|
209
|
-
if (itemsType === 'reference') {
|
|
210
|
-
ctx.inQuery = 'query' in prop;
|
|
211
|
-
p[itemsType](items, ctx);
|
|
212
|
-
ctx.inQuery = false;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
throw new Error(INVALID_VALUE);
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
}, {
|
|
219
|
-
default(val, prop) {
|
|
220
|
-
console.warn('TODO SET DEFAULT VALUE');
|
|
221
|
-
// if (typeof val === 'object') {
|
|
222
|
-
// throwErr(ERRORS.EXPECTED_PRIMITIVE, prop, 'default')
|
|
223
|
-
// }
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
p.string = propParser({}, {
|
|
227
|
-
default(val) {
|
|
228
|
-
expectString(val);
|
|
229
|
-
},
|
|
230
|
-
}, 0);
|
|
231
|
-
p.text = propParser({
|
|
232
|
-
type(_val, _prop, { schema }) {
|
|
233
|
-
if (schema.locales) {
|
|
234
|
-
for (const _ in schema.locales) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
throw Error(TEXT_REQUIRES_LOCALES);
|
|
239
|
-
},
|
|
240
|
-
}, {
|
|
241
|
-
default(val, prop) {
|
|
242
|
-
console.warn('MAKE DEFAULT VALUE FOR TEXT');
|
|
243
|
-
// if (typeof val !== 'string') {
|
|
244
|
-
// throwErr(ERRORS.EXPECTED_STR, prop, 'default')
|
|
245
|
-
// }
|
|
246
|
-
},
|
|
247
|
-
}, 0);
|
|
248
|
-
p.timestamp = propParser({}, {
|
|
249
|
-
default(val) {
|
|
250
|
-
if (typeof val !== 'number' && !(val instanceof Date)) {
|
|
251
|
-
throw Error(EXPECTED_DATE);
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
}, 0);
|
|
255
|
-
export default p;
|
|
256
|
-
//# sourceMappingURL=props.js.map
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { INVALID_TYPE, MISSING_TYPE } from './errors.js';
|
|
2
|
-
export const getPropType = (prop) => {
|
|
3
|
-
if (typeof prop === 'string') {
|
|
4
|
-
return prop;
|
|
5
|
-
}
|
|
6
|
-
if ('type' in prop) {
|
|
7
|
-
if (typeof prop.type !== 'string') {
|
|
8
|
-
throw Error(INVALID_TYPE);
|
|
9
|
-
}
|
|
10
|
-
return prop.type;
|
|
11
|
-
}
|
|
12
|
-
if ('ref' in prop) {
|
|
13
|
-
return 'reference';
|
|
14
|
-
}
|
|
15
|
-
if ('items' in prop) {
|
|
16
|
-
if (getPropType(prop.items) === 'reference') {
|
|
17
|
-
return 'references';
|
|
18
|
-
}
|
|
19
|
-
return 'set';
|
|
20
|
-
}
|
|
21
|
-
if ('props' in prop) {
|
|
22
|
-
return 'object';
|
|
23
|
-
}
|
|
24
|
-
if ('enum' in prop || Array.isArray(prop)) {
|
|
25
|
-
return 'enum';
|
|
26
|
-
}
|
|
27
|
-
throw Error(MISSING_TYPE);
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BasedSchemaPartial } from '../types.js';
|
|
2
|
-
import { BasedOldSchema } from './oldSchemaType.js';
|
|
3
|
-
type OldSchema = Partial<BasedOldSchema>;
|
|
4
|
-
export declare const convertNewToOld: (newSchema: BasedSchemaPartial) => OldSchema;
|
|
5
|
-
export declare const convertOldToNew: (oldSchema: OldSchema) => BasedSchemaPartial;
|
|
6
|
-
export {};
|
package/dist/src/compat/index.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const oldToNewType = {
|
|
2
|
-
id: { type: 'string', format: 'basedId' },
|
|
3
|
-
int: { type: 'integer' },
|
|
4
|
-
url: { type: 'string', format: 'URL' },
|
|
5
|
-
email: { type: 'string', format: 'email' },
|
|
6
|
-
float: { type: 'number' },
|
|
7
|
-
phone: { type: 'string', format: 'mobilePhone' },
|
|
8
|
-
digest: { type: 'string', format: 'strongPassword' },
|
|
9
|
-
};
|
|
10
|
-
const newToOldType = {
|
|
11
|
-
mobilePhone: { type: 'phone' },
|
|
12
|
-
basedId: { type: 'id' },
|
|
13
|
-
integer: { type: 'int' },
|
|
14
|
-
URL: { type: 'url' },
|
|
15
|
-
email: { type: 'email' },
|
|
16
|
-
strongPassword: { type: 'digest' },
|
|
17
|
-
};
|
|
18
|
-
const convertNewToOldMeta = (props) => {
|
|
19
|
-
let meta;
|
|
20
|
-
for (const i in props) {
|
|
21
|
-
if (i[0] !== '$') {
|
|
22
|
-
const v = props[i];
|
|
23
|
-
meta ??= {};
|
|
24
|
-
if (i === 'allowedType') {
|
|
25
|
-
meta.refTypes = v;
|
|
26
|
-
}
|
|
27
|
-
else if (i === 'display' && v === 'bytes') {
|
|
28
|
-
meta.format = v;
|
|
29
|
-
}
|
|
30
|
-
else if (i === 'title') {
|
|
31
|
-
meta.name = v;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
meta[i] = v;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return meta;
|
|
39
|
-
};
|
|
40
|
-
const convertOldToNewMeta = (props) => {
|
|
41
|
-
const meta = {};
|
|
42
|
-
for (const i in props) {
|
|
43
|
-
const v = props[i];
|
|
44
|
-
if (i === 'refTypes') {
|
|
45
|
-
meta.allowedType = v; // TODO
|
|
46
|
-
}
|
|
47
|
-
else if (i === 'format' && v === 'bytes') {
|
|
48
|
-
meta.display = 'bytes';
|
|
49
|
-
}
|
|
50
|
-
else if (i === 'name') {
|
|
51
|
-
meta.title = v;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
meta[i] = v;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return meta;
|
|
58
|
-
};
|
|
59
|
-
const convertNewFieldToOldField = (newField) => {
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
const { type, bidirectional, properties, values, items, ...props } = newField;
|
|
62
|
-
const meta = convertNewToOldMeta(props);
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
const overwrite = newToOldType[type] || newToOldType[props.format];
|
|
65
|
-
const oldField = overwrite
|
|
66
|
-
? { ...overwrite }
|
|
67
|
-
: {
|
|
68
|
-
type,
|
|
69
|
-
};
|
|
70
|
-
if (meta) {
|
|
71
|
-
oldField.meta = meta;
|
|
72
|
-
}
|
|
73
|
-
if (bidirectional) {
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
oldField.bidirectional = bidirectional;
|
|
76
|
-
}
|
|
77
|
-
if (properties) {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
oldField.properties = {};
|
|
80
|
-
for (const key in properties) {
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
oldField.properties[key] = convertNewFieldToOldField(properties[key]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (values) {
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
oldField.values = convertNewFieldToOldField(values);
|
|
88
|
-
}
|
|
89
|
-
if (items) {
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
oldField.items = convertNewFieldToOldField(items);
|
|
92
|
-
}
|
|
93
|
-
return oldField;
|
|
94
|
-
};
|
|
95
|
-
const convertNewTypeToOldType = (newType) => {
|
|
96
|
-
const { prefix, fields, ...props } = newType;
|
|
97
|
-
const oldType = {};
|
|
98
|
-
const meta = convertNewToOldMeta(props);
|
|
99
|
-
if (prefix) {
|
|
100
|
-
oldType.prefix = prefix;
|
|
101
|
-
}
|
|
102
|
-
if (meta) {
|
|
103
|
-
oldType.meta = meta;
|
|
104
|
-
}
|
|
105
|
-
if (fields) {
|
|
106
|
-
oldType.fields = {};
|
|
107
|
-
for (const key in fields) {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
oldType.fields[key] = convertNewFieldToOldField(fields[key]);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return oldType;
|
|
113
|
-
};
|
|
114
|
-
export const convertNewToOld = (newSchema) => {
|
|
115
|
-
const { root, types, language, translations, prefixToTypeMapping } = newSchema;
|
|
116
|
-
const oldSchema = {};
|
|
117
|
-
if (prefixToTypeMapping) {
|
|
118
|
-
oldSchema.prefixToTypeMapping = prefixToTypeMapping;
|
|
119
|
-
}
|
|
120
|
-
if (language) {
|
|
121
|
-
oldSchema.languages = [language];
|
|
122
|
-
}
|
|
123
|
-
if (translations) {
|
|
124
|
-
oldSchema.languages ??= [];
|
|
125
|
-
oldSchema.languages.push(...translations);
|
|
126
|
-
}
|
|
127
|
-
if (root) {
|
|
128
|
-
oldSchema.rootType = convertNewTypeToOldType(root);
|
|
129
|
-
}
|
|
130
|
-
if (types) {
|
|
131
|
-
oldSchema.types = {};
|
|
132
|
-
for (const key in types) {
|
|
133
|
-
oldSchema.types[key] = convertNewTypeToOldType(types[key]);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return oldSchema;
|
|
137
|
-
};
|
|
138
|
-
const convertOldFieldToNewField = (oldField) => {
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
const { type, bidirectional, properties, values, items, meta = {} } = oldField;
|
|
141
|
-
const overwrite = oldToNewType[type] || oldToNewType[meta.format];
|
|
142
|
-
const newField = overwrite
|
|
143
|
-
? {
|
|
144
|
-
...overwrite,
|
|
145
|
-
...convertOldToNewMeta(meta),
|
|
146
|
-
}
|
|
147
|
-
: {
|
|
148
|
-
type,
|
|
149
|
-
...convertOldToNewMeta(meta),
|
|
150
|
-
};
|
|
151
|
-
if (bidirectional) {
|
|
152
|
-
// @ts-ignore
|
|
153
|
-
newField.bidirectional = bidirectional;
|
|
154
|
-
}
|
|
155
|
-
if (properties) {
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
newField.properties = {};
|
|
158
|
-
for (const key in properties) {
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
newField.properties[key] = convertOldFieldToNewField(properties[key]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (values) {
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
newField.values = convertOldFieldToNewField(values);
|
|
166
|
-
}
|
|
167
|
-
if (items) {
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
newField.items = convertOldFieldToNewField(items);
|
|
170
|
-
}
|
|
171
|
-
return newField;
|
|
172
|
-
};
|
|
173
|
-
const convertOldTypeToNewType = (oldType) => {
|
|
174
|
-
const { prefix, fields, meta } = oldType;
|
|
175
|
-
const newType = {
|
|
176
|
-
fields: {},
|
|
177
|
-
};
|
|
178
|
-
if (prefix) {
|
|
179
|
-
newType.prefix = prefix;
|
|
180
|
-
}
|
|
181
|
-
if (meta) {
|
|
182
|
-
Object.assign(newType, convertOldToNewMeta(meta));
|
|
183
|
-
}
|
|
184
|
-
if (fields) {
|
|
185
|
-
for (const key in fields) {
|
|
186
|
-
newType.fields[key] = convertOldFieldToNewField(fields[key]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return newType;
|
|
190
|
-
};
|
|
191
|
-
export const convertOldToNew = (oldSchema) => {
|
|
192
|
-
const { rootType, types, languages, prefixToTypeMapping } = oldSchema;
|
|
193
|
-
const newSchema = {};
|
|
194
|
-
if (prefixToTypeMapping) {
|
|
195
|
-
newSchema.prefixToTypeMapping = prefixToTypeMapping;
|
|
196
|
-
}
|
|
197
|
-
if (languages?.length) {
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
newSchema.language = languages[0];
|
|
200
|
-
const translations = languages.slice(1);
|
|
201
|
-
if (translations.length) {
|
|
202
|
-
// @ts-ignore
|
|
203
|
-
newSchema.translations = translations;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (rootType) {
|
|
207
|
-
newSchema.root = convertOldTypeToNewType(rootType);
|
|
208
|
-
}
|
|
209
|
-
if (types) {
|
|
210
|
-
newSchema.types = {};
|
|
211
|
-
for (const key in types) {
|
|
212
|
-
newSchema.types[key] = convertOldTypeToNewType(types[key]);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return newSchema;
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
type FieldType = 'float' | 'boolean' | 'number' | 'int' | 'string' | 'text' | 'id' | 'digest' | 'url' | 'email' | 'phone' | 'geo' | 'type' | 'timestamp';
|
|
2
|
-
export type FieldSchemaObject = {
|
|
3
|
-
type: 'object';
|
|
4
|
-
properties: {
|
|
5
|
-
[key: string]: FieldSchema;
|
|
6
|
-
};
|
|
7
|
-
meta?: any;
|
|
8
|
-
timeseries?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type FieldSchemaJson = {
|
|
11
|
-
type: 'json';
|
|
12
|
-
properties?: {
|
|
13
|
-
[key: string]: FieldSchema;
|
|
14
|
-
};
|
|
15
|
-
meta?: any;
|
|
16
|
-
timeseries?: boolean;
|
|
17
|
-
};
|
|
18
|
-
type FieldSchemaRecord = {
|
|
19
|
-
type: 'record';
|
|
20
|
-
values: FieldSchema;
|
|
21
|
-
meta?: any;
|
|
22
|
-
timeseries?: boolean;
|
|
23
|
-
};
|
|
24
|
-
type FieldSchemaReferences = {
|
|
25
|
-
type: 'reference' | 'references';
|
|
26
|
-
bidirectional?: {
|
|
27
|
-
fromField: string;
|
|
28
|
-
};
|
|
29
|
-
meta?: any;
|
|
30
|
-
timeseries?: boolean;
|
|
31
|
-
};
|
|
32
|
-
type FieldSchemaOther = {
|
|
33
|
-
type: FieldType;
|
|
34
|
-
meta?: any;
|
|
35
|
-
timeseries?: boolean;
|
|
36
|
-
};
|
|
37
|
-
export type FieldSchemaArrayLike = {
|
|
38
|
-
type: 'set' | 'array';
|
|
39
|
-
items: FieldSchema;
|
|
40
|
-
meta?: any;
|
|
41
|
-
timeseries?: boolean;
|
|
42
|
-
};
|
|
43
|
-
export type FieldSchema = FieldSchemaObject | FieldSchemaRecord | FieldSchemaArrayLike | FieldSchemaJson | FieldSchemaReferences | FieldSchemaOther;
|
|
44
|
-
type FieldInputSchemaArrayLike = {
|
|
45
|
-
type: 'set' | 'array';
|
|
46
|
-
items: FieldInputSchema;
|
|
47
|
-
meta?: any;
|
|
48
|
-
timeseries?: boolean;
|
|
49
|
-
};
|
|
50
|
-
type FieldInputSchemaRecord = {
|
|
51
|
-
type: 'record';
|
|
52
|
-
values: FieldInputSchema;
|
|
53
|
-
meta?: any;
|
|
54
|
-
timeseries?: boolean;
|
|
55
|
-
};
|
|
56
|
-
export type FieldInputSchemaObject = {
|
|
57
|
-
type: 'object';
|
|
58
|
-
properties: {
|
|
59
|
-
[key: string]: FieldInputSchema;
|
|
60
|
-
};
|
|
61
|
-
meta?: any;
|
|
62
|
-
timeseries?: boolean;
|
|
63
|
-
};
|
|
64
|
-
type FieldInputSchema = FieldSchema | FieldInputSchemaArrayLike | FieldInputSchemaRecord | FieldInputSchemaObject | DeleteField;
|
|
65
|
-
type DeleteField = {
|
|
66
|
-
$delete: boolean;
|
|
67
|
-
};
|
|
68
|
-
type Fields = Record<string, FieldSchema>;
|
|
69
|
-
type HierarchySchema = false | {
|
|
70
|
-
[key: string]: false | {
|
|
71
|
-
excludeAncestryWith: string[];
|
|
72
|
-
} | {
|
|
73
|
-
includeAncestryWith: string[];
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
export type TypeSchema = {
|
|
77
|
-
prefix?: string;
|
|
78
|
-
hierarchy?: HierarchySchema;
|
|
79
|
-
fields?: Fields;
|
|
80
|
-
meta?: any;
|
|
81
|
-
};
|
|
82
|
-
type Types = {
|
|
83
|
-
[key: string]: TypeSchema;
|
|
84
|
-
};
|
|
85
|
-
export type BasedOldSchema = {
|
|
86
|
-
sha?: string;
|
|
87
|
-
languages?: string[];
|
|
88
|
-
types: Types;
|
|
89
|
-
rootType?: Pick<TypeSchema, 'fields' | 'prefix' | 'meta'>;
|
|
90
|
-
idSeedCounter?: number;
|
|
91
|
-
prefixToTypeMapping?: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import timestampDisplay from './timestamp.js';
|
|
2
|
-
import numberDisplay from './number.js';
|
|
3
|
-
import stringDisplay from './string.js';
|
|
4
|
-
export const display = (value, field) => {
|
|
5
|
-
if (field.type === 'timestamp' && typeof value === 'number') {
|
|
6
|
-
return timestampDisplay(value, field.display);
|
|
7
|
-
}
|
|
8
|
-
if (field.type === 'number' && typeof value === 'number') {
|
|
9
|
-
return numberDisplay(value, field.display);
|
|
10
|
-
}
|
|
11
|
-
if (field.type === 'string' && typeof value === 'string') {
|
|
12
|
-
return stringDisplay(value, field.display);
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const basedSchemaNumberFormats: readonly [any, "short", "human", "ratio", "bytes", "euro", "dollar", "pound"];
|
|
2
|
-
export type NumberFormat = (typeof basedSchemaNumberFormats)[number] | `round-${number}`;
|
|
3
|
-
declare const parseNumber: (nr: number | string, format?: NumberFormat) => string | number;
|
|
4
|
-
export default parseNumber;
|