@based/schema 5.0.0-alpha.1 → 5.0.0-alpha.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/def/addEdges.d.ts +4 -0
- package/dist/def/addEdges.js +76 -0
- package/dist/def/createEmptyDef.d.ts +38 -0
- package/dist/def/createEmptyDef.js +41 -0
- package/dist/def/defaultMap.d.ts +3 -0
- package/dist/def/defaultMap.js +27 -0
- package/dist/def/fillEmptyMain.d.ts +5 -0
- package/dist/def/fillEmptyMain.js +61 -0
- package/dist/def/getPropLen.d.ts +3 -0
- package/dist/def/getPropLen.js +23 -0
- package/dist/def/index.d.ts +9 -0
- package/dist/def/index.js +10 -0
- package/dist/def/makePacked.d.ts +3 -0
- package/dist/def/makePacked.js +50 -0
- package/dist/def/makeSeparateSort.d.ts +3 -0
- package/dist/def/makeSeparateSort.js +27 -0
- package/dist/def/makeSeparateTextSort.d.ts +3 -0
- package/dist/def/makeSeparateTextSort.js +38 -0
- package/dist/def/readFromPacked.d.ts +3 -0
- package/dist/def/readFromPacked.js +140 -0
- package/dist/def/selvaBuffer.d.ts +5 -0
- package/dist/def/selvaBuffer.js +115 -0
- package/dist/def/typeDef.d.ts +7 -0
- package/dist/def/typeDef.js +215 -0
- package/dist/def/types.d.ts +168 -0
- package/dist/def/types.js +119 -0
- package/dist/def/utils.d.ts +8 -0
- package/dist/def/utils.js +59 -0
- package/dist/def/validation.d.ts +7 -0
- package/dist/def/validation.js +258 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lang.d.ts +1 -1
- package/dist/parse/index.d.ts +1 -1
- package/dist/parse/index.js +5 -5
- package/dist/parse/props.d.ts +1 -0
- package/dist/parse/props.js +107 -51
- package/dist/serialize.d.ts +5 -0
- package/dist/serialize.js +139 -0
- package/dist/types.d.ts +36 -13
- package/dist/types.js +2 -0
- package/package.json +9 -4
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { convertToTimestamp } from '@saulx/utils';
|
|
2
|
+
import { TYPE_INDEX_MAP } from './types.js';
|
|
3
|
+
import { MAX_ID, MIN_ID } from '../types.js';
|
|
4
|
+
const EPSILON = 1e-9; // Small tolerance for floating point comparisons
|
|
5
|
+
export const VALIDATION_MAP = {
|
|
6
|
+
[TYPE_INDEX_MAP.alias]: (value) => {
|
|
7
|
+
if (typeof value !== 'string') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
},
|
|
12
|
+
[TYPE_INDEX_MAP.binary]: (value) => {
|
|
13
|
+
if (value instanceof Uint8Array) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
},
|
|
18
|
+
[TYPE_INDEX_MAP.boolean]: (value) => {
|
|
19
|
+
if (typeof value !== 'boolean') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
[TYPE_INDEX_MAP.cardinality]: (val) => {
|
|
25
|
+
return (typeof val === 'string' ||
|
|
26
|
+
(val instanceof Uint8Array && val.byteLength === 8));
|
|
27
|
+
},
|
|
28
|
+
[TYPE_INDEX_MAP.timestamp]: (value, t) => {
|
|
29
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (t.min !== undefined) {
|
|
33
|
+
if (typeof t.min === 'number') {
|
|
34
|
+
if (value < t.min) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (value < convertToTimestamp(t.min)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return value > -1;
|
|
44
|
+
}
|
|
45
|
+
if (t.max !== undefined) {
|
|
46
|
+
if (typeof t.max === 'number') {
|
|
47
|
+
if (value > t.max) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (value > convertToTimestamp(t.max)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
[TYPE_INDEX_MAP.int16]: (value, t) => {
|
|
58
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (value > 32767 || value < -32768) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (t.min !== undefined && value < t.min) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (t.max !== undefined && value > t.max) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
[TYPE_INDEX_MAP.int32]: (value, t) => {
|
|
73
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (value > 2147483647 || value < -2147483648) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (t.min !== undefined && value < t.min) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (t.max !== undefined && value > t.max) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
},
|
|
87
|
+
[TYPE_INDEX_MAP.int8]: (value, t) => {
|
|
88
|
+
// use % for steps size
|
|
89
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (value > 127 || value < -128) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (t.min !== undefined && value < t.min) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (t.max !== undefined && value > t.max) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
},
|
|
103
|
+
[TYPE_INDEX_MAP.uint8]: (value, t) => {
|
|
104
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (value > 255 || value < 0) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (t.min !== undefined && value < t.min) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (t.max !== undefined && value > t.max) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
[TYPE_INDEX_MAP.uint16]: (value, t) => {
|
|
119
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (value > 65535 || value < 0) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (t.min !== undefined && value < t.min) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (t.max !== undefined && value > t.max) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
},
|
|
133
|
+
[TYPE_INDEX_MAP.uint32]: (value, t) => {
|
|
134
|
+
if (typeof value !== 'number' || value % t.step !== 0) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (value > 4294967295 || value < 0) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (t.min !== undefined && value < t.min) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (t.max !== undefined && value > t.max) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
},
|
|
148
|
+
[TYPE_INDEX_MAP.number]: (value, t) => {
|
|
149
|
+
if (t.step) {
|
|
150
|
+
const div = value / t.step;
|
|
151
|
+
if (Math.abs(div - Math.round(div)) > EPSILON) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (typeof value !== 'number') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (t.min !== undefined && value < t.min) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if (t.max !== undefined && value > t.max) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
[TYPE_INDEX_MAP.enum]: (value, prop) => {
|
|
167
|
+
if (value === null) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
const arr = prop.enum;
|
|
171
|
+
for (let i = 0; i < arr.length; i++) {
|
|
172
|
+
if (value === arr[i]) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
},
|
|
178
|
+
[TYPE_INDEX_MAP.id]: (value) => {
|
|
179
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
},
|
|
184
|
+
[TYPE_INDEX_MAP.json]: (value) => {
|
|
185
|
+
return true;
|
|
186
|
+
},
|
|
187
|
+
[TYPE_INDEX_MAP.microbuffer]: (value) => {
|
|
188
|
+
if (!(value instanceof Uint8Array)) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
},
|
|
193
|
+
[TYPE_INDEX_MAP.reference]: (v) => {
|
|
194
|
+
if (typeof v !== 'number') {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
if (v === 0 || v > MAX_ID) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
},
|
|
202
|
+
[TYPE_INDEX_MAP.references]: (v) => {
|
|
203
|
+
if (typeof v !== 'number') {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (v === 0 || v > MAX_ID) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
},
|
|
211
|
+
[TYPE_INDEX_MAP.string]: (value, t) => {
|
|
212
|
+
// add max etc all here - make a ref to the original SCHEMA on DEF
|
|
213
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
},
|
|
218
|
+
[TYPE_INDEX_MAP.text]: (value, t) => {
|
|
219
|
+
// add max etc all here - make a ref to the original SCHEMA on DEF
|
|
220
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return true;
|
|
224
|
+
},
|
|
225
|
+
[TYPE_INDEX_MAP.aliases]: (value) => {
|
|
226
|
+
if (!Array.isArray(value)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
const len = value.length;
|
|
230
|
+
for (let i = 0; i < len; i++) {
|
|
231
|
+
if (typeof value[i] !== 'string') {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
},
|
|
237
|
+
[TYPE_INDEX_MAP.vector]: (value) => {
|
|
238
|
+
// Array should be supported
|
|
239
|
+
if (!(value instanceof Float32Array)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
export const defaultValidation = () => true;
|
|
246
|
+
export const isValidId = (id) => {
|
|
247
|
+
if (typeof id != 'number' || id < MIN_ID || id > MAX_ID) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return true;
|
|
251
|
+
};
|
|
252
|
+
export const isValidString = (v) => {
|
|
253
|
+
const isVal = typeof v === 'string' ||
|
|
254
|
+
v instanceof Uint8Array ||
|
|
255
|
+
ArrayBuffer.isView(v);
|
|
256
|
+
return isVal;
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=validation.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/lang.d.ts
CHANGED
|
@@ -145,7 +145,7 @@ declare const langCodes: {
|
|
|
145
145
|
readonly yo: 143;
|
|
146
146
|
readonly zu: 144;
|
|
147
147
|
};
|
|
148
|
-
export declare const langCodesMap: Map<string, 0 |
|
|
148
|
+
export declare const langCodesMap: Map<string, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144>;
|
|
149
149
|
export declare const inverseLangMap: Map<any, any>;
|
|
150
150
|
export type LangName = keyof typeof langCodes;
|
|
151
151
|
export type LangCode = (typeof langCodes)[LangName];
|
package/dist/parse/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class SchemaParser {
|
|
|
12
12
|
parseTypes(): void;
|
|
13
13
|
parseProps(props: any, schemaType?: SchemaType): void;
|
|
14
14
|
parseLocales(): void;
|
|
15
|
-
parse():
|
|
15
|
+
parse(): StrictSchema;
|
|
16
16
|
}
|
|
17
17
|
export declare const print: (schema: Schema, path: string[]) => string;
|
|
18
18
|
export declare const parse: (schema: Schema) => {
|
package/dist/parse/index.js
CHANGED
|
@@ -3,10 +3,11 @@ import { getPropType } from './utils.js';
|
|
|
3
3
|
import propParsers from './props.js';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
5
|
import { expectBoolean, expectObject } from './assert.js';
|
|
6
|
+
import { deepCopy } from '@saulx/utils';
|
|
6
7
|
export { getPropType };
|
|
7
8
|
export class SchemaParser {
|
|
8
9
|
constructor(schema) {
|
|
9
|
-
this.schema = schema;
|
|
10
|
+
this.schema = deepCopy(schema);
|
|
10
11
|
}
|
|
11
12
|
isItems;
|
|
12
13
|
inQuery;
|
|
@@ -20,7 +21,7 @@ export class SchemaParser {
|
|
|
20
21
|
expectObject(types);
|
|
21
22
|
for (const type in types) {
|
|
22
23
|
this.lvl++;
|
|
23
|
-
if (type
|
|
24
|
+
if (type === '_root') {
|
|
24
25
|
throw new Error(INVALID_KEY);
|
|
25
26
|
}
|
|
26
27
|
this.path[this.lvl] = type;
|
|
@@ -97,6 +98,7 @@ export class SchemaParser {
|
|
|
97
98
|
throw Error(UNKNOWN_PROP);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
return this.schema;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
export const print = (schema, path) => {
|
|
@@ -120,9 +122,7 @@ export const print = (schema, path) => {
|
|
|
120
122
|
export const parse = (schema) => {
|
|
121
123
|
const parser = new SchemaParser(schema);
|
|
122
124
|
try {
|
|
123
|
-
parser.parse();
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
return { schema };
|
|
125
|
+
return { schema: parser.parse() };
|
|
126
126
|
}
|
|
127
127
|
catch (e) {
|
|
128
128
|
const cause = parser.path.slice(0, Math.min(4, parser.lvl) + 1);
|
package/dist/parse/props.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import type { SchemaParser } from './index.js';
|
|
|
3
3
|
type PropsFns<PropType> = Record<string, (val: any, prop: PropType, ctx: SchemaParser, key?: string) => void>;
|
|
4
4
|
declare function propParser<PropType extends SchemaAnyProp>(required: PropsFns<PropType>, optional: PropsFns<PropType>, allowShorthand?: number): (prop: any, ctx: SchemaParser) => void;
|
|
5
5
|
declare const p: Record<string, ReturnType<typeof propParser>>;
|
|
6
|
+
export declare const isDefault: (val: any, prop: any, ctx: any) => any;
|
|
6
7
|
export default p;
|
|
7
8
|
//# sourceMappingURL=props.d.ts.map
|
package/dist/parse/props.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { convertToTimestamp } from '@saulx/utils';
|
|
2
|
+
import { NUMBER, TYPE_INDEX_MAP, } from '../def/types.js';
|
|
3
|
+
import { VALIDATION_MAP } from '../def/validation.js';
|
|
1
4
|
import { stringFormats, dateDisplays, numberDisplays, } from '../types.js';
|
|
2
|
-
import { expectBoolean,
|
|
3
|
-
import { EXPECTED_ARR,
|
|
5
|
+
import { expectBoolean, expectFunction, expectNumber, expectObject, expectString, } from './assert.js';
|
|
6
|
+
import { EXPECTED_ARR, EXPECTED_OBJ, EXPECTED_PRIMITIVE, INVALID_VALUE, MIN_MAX, MISSING_TYPE, TEXT_REQUIRES_LOCALES, TYPE_MISMATCH, UNKNOWN_PROP, NOT_ALLOWED_IN_ITEMS, } from './errors.js';
|
|
4
7
|
import { getPropType } from './utils.js';
|
|
8
|
+
import { DEFAULT_MAP } from '../def/defaultMap.js';
|
|
9
|
+
import { parseMinMaxStep } from '../def/utils.js';
|
|
5
10
|
let stringFormatsSet;
|
|
6
11
|
let numberDisplaysSet;
|
|
7
12
|
let dateDisplaysSet;
|
|
@@ -38,10 +43,21 @@ const shared = {
|
|
|
38
43
|
throw Error(TYPE_MISMATCH);
|
|
39
44
|
}
|
|
40
45
|
},
|
|
41
|
-
title(val) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
title(val) {
|
|
47
|
+
expectString(val);
|
|
48
|
+
},
|
|
49
|
+
description(val) {
|
|
50
|
+
expectString(val);
|
|
51
|
+
},
|
|
52
|
+
readOnly(val) {
|
|
53
|
+
expectBoolean(val);
|
|
54
|
+
},
|
|
55
|
+
examples(val) {
|
|
56
|
+
expectString(val);
|
|
57
|
+
},
|
|
58
|
+
validation(val) {
|
|
59
|
+
expectFunction(val);
|
|
60
|
+
},
|
|
45
61
|
};
|
|
46
62
|
function propParser(required, optional, allowShorthand) {
|
|
47
63
|
return (prop, ctx) => {
|
|
@@ -91,9 +107,45 @@ function propParser(required, optional, allowShorthand) {
|
|
|
91
107
|
};
|
|
92
108
|
}
|
|
93
109
|
const p = {};
|
|
110
|
+
export const isDefault = (val, prop, ctx) => {
|
|
111
|
+
let typeIndex;
|
|
112
|
+
typeIndex = TYPE_INDEX_MAP[prop.type];
|
|
113
|
+
if ('enum' in prop) {
|
|
114
|
+
typeIndex = TYPE_INDEX_MAP['enum'];
|
|
115
|
+
}
|
|
116
|
+
if (prop.type === 'timestamp') {
|
|
117
|
+
val = convertToTimestamp(val);
|
|
118
|
+
}
|
|
119
|
+
const validation = prop.validation || VALIDATION_MAP[typeIndex];
|
|
120
|
+
const propDef = {
|
|
121
|
+
typeIndex,
|
|
122
|
+
__isPropDef: true,
|
|
123
|
+
start: 0,
|
|
124
|
+
path: [],
|
|
125
|
+
prop: 0,
|
|
126
|
+
len: 0,
|
|
127
|
+
separate: false,
|
|
128
|
+
enum: prop.enum,
|
|
129
|
+
validation,
|
|
130
|
+
default: DEFAULT_MAP[typeIndex],
|
|
131
|
+
step: parseMinMaxStep(prop.step ?? typeIndex === NUMBER ? 0 : 1),
|
|
132
|
+
max: parseMinMaxStep(prop.max),
|
|
133
|
+
min: parseMinMaxStep(prop.min),
|
|
134
|
+
};
|
|
135
|
+
if (!validation(val, propDef)) {
|
|
136
|
+
throw new Error(`Incorrect default for type "${prop.type ?? 'enum'}"`);
|
|
137
|
+
}
|
|
138
|
+
if ('enum' in prop) {
|
|
139
|
+
if (val === undefined) {
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
return prop.enum.findIndex((v) => v === val) + 1;
|
|
143
|
+
}
|
|
144
|
+
return val;
|
|
145
|
+
};
|
|
94
146
|
p.boolean = propParser(STUB, {
|
|
95
|
-
default(val) {
|
|
96
|
-
|
|
147
|
+
default(val, prop, ctx) {
|
|
148
|
+
return isDefault(val, prop, ctx);
|
|
97
149
|
},
|
|
98
150
|
}, 0);
|
|
99
151
|
p.vector = propParser({
|
|
@@ -101,8 +153,8 @@ p.vector = propParser({
|
|
|
101
153
|
expectNumber(val);
|
|
102
154
|
},
|
|
103
155
|
}, {
|
|
104
|
-
default(val) {
|
|
105
|
-
|
|
156
|
+
default(val, prop, ctx) {
|
|
157
|
+
return isDefault(val, prop, ctx);
|
|
106
158
|
},
|
|
107
159
|
}, 0);
|
|
108
160
|
p.enum = propParser({
|
|
@@ -120,10 +172,8 @@ p.enum = propParser({
|
|
|
120
172
|
}
|
|
121
173
|
},
|
|
122
174
|
}, {
|
|
123
|
-
default(val, prop) {
|
|
124
|
-
|
|
125
|
-
throw Error(EXPECTED_VALUE_IN_ENUM);
|
|
126
|
-
}
|
|
175
|
+
default(val, prop, ctx) {
|
|
176
|
+
return isDefault(val, prop, ctx);
|
|
127
177
|
},
|
|
128
178
|
}, 1);
|
|
129
179
|
const numberOpts = {
|
|
@@ -146,18 +196,8 @@ const numberOpts = {
|
|
|
146
196
|
throw Error(INVALID_VALUE);
|
|
147
197
|
}
|
|
148
198
|
},
|
|
149
|
-
default(val, prop) {
|
|
150
|
-
|
|
151
|
-
if (val > prop.max || val < prop.min) {
|
|
152
|
-
throw Error(OUT_OF_RANGE);
|
|
153
|
-
}
|
|
154
|
-
if (prop.step !== 'any') {
|
|
155
|
-
const min = typeof prop.min !== 'number' || prop.min === Infinity ? 0 : prop.min;
|
|
156
|
-
const v = val - min;
|
|
157
|
-
if (~~(v / prop.step) * prop.step !== v) {
|
|
158
|
-
throw Error(INVALID_VALUE);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
199
|
+
default(val, prop, ctx) {
|
|
200
|
+
return isDefault(val, prop, ctx);
|
|
161
201
|
},
|
|
162
202
|
};
|
|
163
203
|
p.number = propParser(STUB, numberOpts, 0);
|
|
@@ -171,11 +211,7 @@ p.object = propParser({
|
|
|
171
211
|
props(val, prop, ctx) {
|
|
172
212
|
ctx.parseProps(val, ctx.type);
|
|
173
213
|
},
|
|
174
|
-
}, {
|
|
175
|
-
default(val) {
|
|
176
|
-
console.warn('TODO object default value');
|
|
177
|
-
},
|
|
178
|
-
});
|
|
214
|
+
}, {});
|
|
179
215
|
p.set = propParser({
|
|
180
216
|
items(items, prop, ctx) {
|
|
181
217
|
expectObject(items);
|
|
@@ -218,16 +254,13 @@ p.references = propParser({
|
|
|
218
254
|
}
|
|
219
255
|
},
|
|
220
256
|
}, {
|
|
221
|
-
default(val, prop) {
|
|
222
|
-
|
|
223
|
-
// if (typeof val === 'object') {
|
|
224
|
-
// throwErr(ERRORS.EXPECTED_PRIMITIVE, prop, 'default')
|
|
225
|
-
// }
|
|
257
|
+
default(val, prop, ctx) {
|
|
258
|
+
return isDefault(val, prop, ctx);
|
|
226
259
|
},
|
|
227
260
|
});
|
|
228
261
|
const binaryOpts = {
|
|
229
|
-
default(val) {
|
|
230
|
-
|
|
262
|
+
default(val, prop, ctx) {
|
|
263
|
+
return isDefault(val, prop, ctx);
|
|
231
264
|
},
|
|
232
265
|
format(val) {
|
|
233
266
|
expectString(val);
|
|
@@ -270,8 +303,10 @@ p.text = propParser({
|
|
|
270
303
|
throw Error(TEXT_REQUIRES_LOCALES);
|
|
271
304
|
},
|
|
272
305
|
}, {
|
|
306
|
+
format: binaryOpts.format,
|
|
273
307
|
default(val, prop) {
|
|
274
|
-
console.warn('MAKE DEFAULT VALUE FOR TEXT')
|
|
308
|
+
// console.warn('MAKE DEFAULT VALUE FOR TEXT')
|
|
309
|
+
return true;
|
|
275
310
|
},
|
|
276
311
|
}, 0);
|
|
277
312
|
p.timestamp = propParser(STUB, {
|
|
@@ -280,11 +315,27 @@ p.timestamp = propParser(STUB, {
|
|
|
280
315
|
dateDisplaysSet ??= new Set(dateDisplays);
|
|
281
316
|
dateDisplaysSet.has(val);
|
|
282
317
|
},
|
|
283
|
-
|
|
284
|
-
if (typeof val !== '
|
|
285
|
-
throw Error(
|
|
318
|
+
min(val) {
|
|
319
|
+
if (typeof val !== 'string' && typeof val !== 'number') {
|
|
320
|
+
throw Error(INVALID_VALUE);
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
max(val) {
|
|
324
|
+
if (typeof val !== 'string' && typeof val !== 'number') {
|
|
325
|
+
throw Error(INVALID_VALUE);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
step(val) {
|
|
329
|
+
if (typeof val !== 'string' && typeof val !== 'number') {
|
|
330
|
+
throw Error(INVALID_VALUE);
|
|
331
|
+
}
|
|
332
|
+
if (typeof val === 'string' && val.includes('now')) {
|
|
333
|
+
throw Error(INVALID_VALUE);
|
|
286
334
|
}
|
|
287
335
|
},
|
|
336
|
+
default(val, prop, ctx) {
|
|
337
|
+
return isDefault(val, prop, ctx);
|
|
338
|
+
},
|
|
288
339
|
on(val) {
|
|
289
340
|
if (val !== 'create' && val !== 'update') {
|
|
290
341
|
throw Error(INVALID_VALUE);
|
|
@@ -297,7 +348,7 @@ p.reference = propParser({
|
|
|
297
348
|
throw Error(MISSING_TYPE);
|
|
298
349
|
}
|
|
299
350
|
},
|
|
300
|
-
prop(propKey, prop, { schema, type, inQuery, path }) {
|
|
351
|
+
prop(propKey, prop, { schema, type, inQuery, path, lvl }) {
|
|
301
352
|
const propAllowed = type && !inQuery;
|
|
302
353
|
if (propAllowed) {
|
|
303
354
|
expectString(propKey);
|
|
@@ -315,7 +366,7 @@ p.reference = propParser({
|
|
|
315
366
|
if (create) {
|
|
316
367
|
const ref = path[1];
|
|
317
368
|
let prop = '';
|
|
318
|
-
for (let i = 3; i <
|
|
369
|
+
for (let i = 3; i < lvl; i += 2) {
|
|
319
370
|
prop += prop ? `.${path[i]}` : path[i];
|
|
320
371
|
}
|
|
321
372
|
targetProp.readOnly = true;
|
|
@@ -348,8 +399,8 @@ p.reference = propParser({
|
|
|
348
399
|
},
|
|
349
400
|
}, {
|
|
350
401
|
mime: binaryOpts.mime,
|
|
351
|
-
default(val) {
|
|
352
|
-
|
|
402
|
+
default(val, prop, ctx) {
|
|
403
|
+
return isDefault(val, prop, ctx);
|
|
353
404
|
},
|
|
354
405
|
edge(val, prop, ctx, key) {
|
|
355
406
|
const edgeAllowed = ctx.type && !ctx.inQuery;
|
|
@@ -377,14 +428,19 @@ p.reference = propParser({
|
|
|
377
428
|
},
|
|
378
429
|
});
|
|
379
430
|
p.alias = propParser(STUB, {
|
|
380
|
-
default(val) {
|
|
381
|
-
|
|
431
|
+
default(val, prop, ctx) {
|
|
432
|
+
return isDefault(val, prop, ctx);
|
|
382
433
|
},
|
|
383
434
|
format: binaryOpts.format,
|
|
384
435
|
}, 0);
|
|
385
|
-
p.
|
|
386
|
-
default(val) {
|
|
387
|
-
|
|
436
|
+
p.cardinality = propParser(STUB, {
|
|
437
|
+
default(val, prop, ctx) {
|
|
438
|
+
return isDefault(val, prop, ctx);
|
|
439
|
+
},
|
|
440
|
+
}, 0);
|
|
441
|
+
p.json = propParser(STUB, {
|
|
442
|
+
default(val, prop, ctx) {
|
|
443
|
+
return isDefault(val, prop, ctx);
|
|
388
444
|
},
|
|
389
445
|
}, 0);
|
|
390
446
|
export default p;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StrictSchema } from './types.js';
|
|
2
|
+
export declare const serialize: (schema: any, noCompression?: boolean) => Uint8Array;
|
|
3
|
+
export declare const deSerializeInner: (buf: Uint8Array, obj: any, start: number) => number;
|
|
4
|
+
export declare const deSerialize: (buf: Uint8Array) => StrictSchema;
|
|
5
|
+
//# sourceMappingURL=serialize.d.ts.map
|