@based/schema 5.0.0-alpha.2 → 5.0.0-alpha.21

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.
Files changed (50) hide show
  1. package/dist/def/DEFAULT_MAP.d.ts +3 -0
  2. package/dist/def/DEFAULT_MAP.js +29 -0
  3. package/dist/def/addEdges.d.ts +4 -0
  4. package/dist/def/addEdges.js +76 -0
  5. package/dist/def/createEmptyDef.d.ts +42 -0
  6. package/dist/def/createEmptyDef.js +45 -0
  7. package/dist/def/defaultMap.d.ts +3 -0
  8. package/dist/def/defaultMap.js +28 -0
  9. package/dist/def/fillEmptyMain.d.ts +5 -0
  10. package/dist/def/fillEmptyMain.js +61 -0
  11. package/dist/def/getPropLen.d.ts +3 -0
  12. package/dist/def/getPropLen.js +23 -0
  13. package/dist/def/index.d.ts +8 -0
  14. package/dist/def/index.js +9 -0
  15. package/dist/def/makePacked.d.ts +3 -0
  16. package/dist/def/makePacked.js +50 -0
  17. package/dist/def/makeSeparateSort.d.ts +3 -0
  18. package/dist/def/makeSeparateSort.js +27 -0
  19. package/dist/def/makeSeparateTextSort.d.ts +3 -0
  20. package/dist/def/makeSeparateTextSort.js +38 -0
  21. package/dist/def/readFromPacked.d.ts +3 -0
  22. package/dist/def/readFromPacked.js +140 -0
  23. package/dist/def/selvaBuffer.d.ts +5 -0
  24. package/dist/def/selvaBuffer.js +145 -0
  25. package/dist/def/timestamp.d.ts +2 -0
  26. package/dist/def/timestamp.js +67 -0
  27. package/dist/def/typeDef.d.ts +13 -0
  28. package/dist/def/typeDef.js +231 -0
  29. package/dist/def/types.d.ts +186 -0
  30. package/dist/def/types.js +138 -0
  31. package/dist/def/utils.d.ts +8 -0
  32. package/dist/def/utils.js +62 -0
  33. package/dist/def/validation.d.ts +7 -0
  34. package/dist/def/validation.js +259 -0
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.js +2 -1
  37. package/dist/lang.d.ts +3 -1
  38. package/dist/lang.js +2 -0
  39. package/dist/parse/assert.js +1 -2
  40. package/dist/parse/index.d.ts +1 -1
  41. package/dist/parse/index.js +8 -5
  42. package/dist/parse/props.d.ts +1 -0
  43. package/dist/parse/props.js +118 -54
  44. package/dist/serialize.d.ts +14 -0
  45. package/dist/serialize.js +473 -0
  46. package/dist/types.d.ts +29 -9
  47. package/dist/types.js +2 -0
  48. package/dist/validation/validation.d.ts +2 -0
  49. package/dist/validation/validation.js +6 -0
  50. package/package.json +8 -4
@@ -0,0 +1,138 @@
1
+ // WARN: The following type codes are used in js and zig but selva has its own typing.
2
+ export const NULL = 0;
3
+ export const TIMESTAMP = 1;
4
+ export const NUMBER = 4;
5
+ export const CARDINALITY = 5;
6
+ export const INT8 = 20;
7
+ export const UINT8 = 6;
8
+ export const INT16 = 21;
9
+ export const UINT16 = 22;
10
+ export const INT32 = 23;
11
+ export const UINT32 = 7;
12
+ export const BOOLEAN = 9;
13
+ export const ENUM = 10;
14
+ export const STRING = 11;
15
+ export const TEXT = 12;
16
+ export const REFERENCE = 13;
17
+ export const REFERENCES = 14;
18
+ export const WEAK_REFERENCE = 15;
19
+ export const WEAK_REFERENCES = 16;
20
+ export const MICRO_BUFFER = 17;
21
+ export const ALIAS = 18;
22
+ export const ALIASES = 19;
23
+ export const BINARY = 25;
24
+ export const ID = 26;
25
+ export const VECTOR = 27;
26
+ export const JSON = 28;
27
+ export const OBJECT = 29;
28
+ export const COLVEC = 30;
29
+ export const TYPE_INDEX_MAP = {
30
+ alias: ALIAS,
31
+ aliases: ALIASES,
32
+ microbuffer: MICRO_BUFFER,
33
+ references: REFERENCES,
34
+ reference: REFERENCE,
35
+ timestamp: TIMESTAMP,
36
+ boolean: BOOLEAN,
37
+ number: NUMBER,
38
+ string: STRING,
39
+ text: TEXT,
40
+ uint16: UINT16,
41
+ uint32: UINT32,
42
+ int16: INT16,
43
+ int32: INT32,
44
+ uint8: UINT8,
45
+ enum: ENUM,
46
+ int8: INT8,
47
+ id: NULL,
48
+ binary: BINARY,
49
+ vector: VECTOR,
50
+ cardinality: CARDINALITY,
51
+ json: JSON,
52
+ object: OBJECT,
53
+ colvec: COLVEC,
54
+ };
55
+ const numberTypeValues = [
56
+ NUMBER,
57
+ UINT16,
58
+ UINT32,
59
+ INT16,
60
+ INT32,
61
+ UINT8,
62
+ INT8,
63
+ CARDINALITY,
64
+ ];
65
+ export function isNumberType(type) {
66
+ return numberTypeValues.includes(type);
67
+ }
68
+ export const BLOCK_CAPACITY_MIN = 1025;
69
+ export const BLOCK_CAPACITY_MAX = 2147483647;
70
+ export const BLOCK_CAPACITY_DEFAULT = 100_000;
71
+ export const SIZE_MAP = {
72
+ timestamp: 8, // 64bit
73
+ // double-precision 64-bit binary format IEEE 754 value
74
+ number: 8, // 64bit
75
+ int8: 1,
76
+ uint8: 1,
77
+ int16: 2,
78
+ uint16: 2,
79
+ int32: 4,
80
+ uint32: 4,
81
+ boolean: 1,
82
+ reference: 0, // separate
83
+ enum: 1, // enum
84
+ string: 0, // separate
85
+ text: 0, // separate
86
+ cardinality: 0, // separate
87
+ references: 0, // separate
88
+ microbuffer: 0, // separate
89
+ alias: 0,
90
+ aliases: 0,
91
+ id: 4,
92
+ binary: 0,
93
+ vector: 0, // separate
94
+ json: 0,
95
+ object: 0,
96
+ colvec: 0, // separate
97
+ };
98
+ const reverseMap = {};
99
+ for (const k in TYPE_INDEX_MAP) {
100
+ reverseMap[TYPE_INDEX_MAP[k]] = k;
101
+ }
102
+ export const REVERSE_SIZE_MAP = {};
103
+ for (const k in SIZE_MAP) {
104
+ REVERSE_SIZE_MAP[TYPE_INDEX_MAP[k]] = SIZE_MAP[k];
105
+ }
106
+ export const REVERSE_TYPE_INDEX_MAP = reverseMap;
107
+ export const ID_FIELD_DEF = {
108
+ typeIndex: TYPE_INDEX_MAP['id'],
109
+ separate: true,
110
+ path: ['id'],
111
+ start: 0,
112
+ prop: 255,
113
+ default: 0,
114
+ len: 4,
115
+ validation: () => true,
116
+ __isPropDef: true,
117
+ };
118
+ export const EMPTY_MICRO_BUFFER = {
119
+ typeIndex: TYPE_INDEX_MAP['microbuffer'],
120
+ separate: true,
121
+ path: [''],
122
+ start: 0,
123
+ default: undefined,
124
+ prop: 0,
125
+ len: 1,
126
+ validation: () => true,
127
+ __isPropDef: true,
128
+ };
129
+ export const getPropTypeName = (propType) => {
130
+ return REVERSE_TYPE_INDEX_MAP[propType];
131
+ };
132
+ export const isPropDef = (prop) => {
133
+ if ('__isPropDef' in prop && prop.__isPropDef === true) {
134
+ return true;
135
+ }
136
+ return false;
137
+ };
138
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,8 @@
1
+ import { PropDef, PropDefEdge } from './types.js';
2
+ import { SchemaProp } from '../types.js';
3
+ export declare function isSeparate(schemaProp: SchemaProp, len: number): boolean;
4
+ export declare const propIsSigned: (prop: PropDef | PropDefEdge) => boolean;
5
+ export declare const propIsNumerical: (prop: PropDef | PropDefEdge) => boolean;
6
+ export declare function getPropLen(schemaProp: SchemaProp): any;
7
+ export declare const parseMinMaxStep: (val: any) => string | number;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { INT16, INT32, INT8, UINT16, UINT32, UINT8, NUMBER, TIMESTAMP, SIZE_MAP, } from './types.js';
2
+ import { isPropType } from '../types.js';
3
+ import { getPropType } from '../parse/utils.js';
4
+ import { convertToTimestamp } from '@saulx/utils';
5
+ export function isSeparate(schemaProp, len) {
6
+ return len === 0 || isPropType('vector', schemaProp) || isPropType('colvec', schemaProp);
7
+ }
8
+ export const propIsSigned = (prop) => {
9
+ const t = prop.typeIndex;
10
+ if (t === INT16 || t === INT32 || t === INT8) {
11
+ return true;
12
+ }
13
+ return false;
14
+ };
15
+ export const propIsNumerical = (prop) => {
16
+ const t = prop.typeIndex;
17
+ if (t === INT16 ||
18
+ t === INT32 ||
19
+ t === INT8 ||
20
+ t === UINT8 ||
21
+ t === UINT16 ||
22
+ t === UINT32 ||
23
+ t === NUMBER ||
24
+ t === TIMESTAMP) {
25
+ return true;
26
+ }
27
+ return false;
28
+ };
29
+ export function getPropLen(schemaProp) {
30
+ let len = SIZE_MAP[getPropType(schemaProp)];
31
+ if (isPropType('string', schemaProp) ||
32
+ isPropType('alias', schemaProp) ||
33
+ isPropType('cardinality', schemaProp)) {
34
+ if (typeof schemaProp === 'object') {
35
+ if (schemaProp.maxBytes < 61) {
36
+ len = schemaProp.maxBytes + 1;
37
+ }
38
+ else if ('max' in schemaProp && schemaProp.max < 31) {
39
+ len = schemaProp.max * 2 + 1;
40
+ }
41
+ }
42
+ }
43
+ else if (isPropType('vector', schemaProp)) {
44
+ len = 4 * schemaProp.size;
45
+ }
46
+ else if (isPropType('colvec', schemaProp)) {
47
+ len = schemaProp.size;
48
+ }
49
+ return len;
50
+ }
51
+ export const parseMinMaxStep = (val) => {
52
+ if (typeof val === 'number') {
53
+ return val;
54
+ }
55
+ if (typeof val === 'string') {
56
+ if (!val.includes('now')) {
57
+ return convertToTimestamp(val);
58
+ }
59
+ return val;
60
+ }
61
+ };
62
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,7 @@
1
+ import { TypeIndex, PropDef, PropDefEdge } from './types.js';
2
+ export type Validation = (payload: any, prop: PropDef | PropDefEdge) => boolean;
3
+ export declare const VALIDATION_MAP: Record<TypeIndex, Validation>;
4
+ export declare const defaultValidation: () => boolean;
5
+ export declare const isValidId: (id: number) => boolean;
6
+ export declare const isValidString: (v: any) => boolean;
7
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1,259 @@
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
+ console.log('DERP ', value, typeof value);
14
+ if (value instanceof Uint8Array) {
15
+ return true;
16
+ }
17
+ return false;
18
+ },
19
+ [TYPE_INDEX_MAP.boolean]: (value) => {
20
+ if (typeof value !== 'boolean') {
21
+ return false;
22
+ }
23
+ return true;
24
+ },
25
+ [TYPE_INDEX_MAP.cardinality]: (val) => {
26
+ return (typeof val === 'string' ||
27
+ (val instanceof Uint8Array && val.byteLength === 8));
28
+ },
29
+ [TYPE_INDEX_MAP.timestamp]: (value, t) => {
30
+ if (typeof value !== 'number' || value % t.step !== 0) {
31
+ return false;
32
+ }
33
+ if (t.min !== undefined) {
34
+ if (typeof t.min === 'number') {
35
+ if (value < t.min) {
36
+ return false;
37
+ }
38
+ }
39
+ else if (value < convertToTimestamp(t.min)) {
40
+ return false;
41
+ }
42
+ }
43
+ else {
44
+ return value > -1;
45
+ }
46
+ if (t.max !== undefined) {
47
+ if (typeof t.max === 'number') {
48
+ if (value > t.max) {
49
+ return false;
50
+ }
51
+ }
52
+ else if (value > convertToTimestamp(t.max)) {
53
+ return false;
54
+ }
55
+ }
56
+ return true;
57
+ },
58
+ [TYPE_INDEX_MAP.int16]: (value, t) => {
59
+ if (typeof value !== 'number' || value % t.step !== 0) {
60
+ return false;
61
+ }
62
+ if (value > 32767 || value < -32768) {
63
+ return false;
64
+ }
65
+ if (t.min !== undefined && value < t.min) {
66
+ return false;
67
+ }
68
+ if (t.max !== undefined && value > t.max) {
69
+ return false;
70
+ }
71
+ return true;
72
+ },
73
+ [TYPE_INDEX_MAP.int32]: (value, t) => {
74
+ if (typeof value !== 'number' || value % t.step !== 0) {
75
+ return false;
76
+ }
77
+ if (value > 2147483647 || value < -2147483648) {
78
+ return false;
79
+ }
80
+ if (t.min !== undefined && value < t.min) {
81
+ return false;
82
+ }
83
+ if (t.max !== undefined && value > t.max) {
84
+ return false;
85
+ }
86
+ return true;
87
+ },
88
+ [TYPE_INDEX_MAP.int8]: (value, t) => {
89
+ // use % for steps size
90
+ if (typeof value !== 'number' || value % t.step !== 0) {
91
+ return false;
92
+ }
93
+ if (value > 127 || value < -128) {
94
+ return false;
95
+ }
96
+ if (t.min !== undefined && value < t.min) {
97
+ return false;
98
+ }
99
+ if (t.max !== undefined && value > t.max) {
100
+ return false;
101
+ }
102
+ return true;
103
+ },
104
+ [TYPE_INDEX_MAP.uint8]: (value, t) => {
105
+ if (typeof value !== 'number' || value % t.step !== 0) {
106
+ return false;
107
+ }
108
+ if (value > 255 || value < 0) {
109
+ return false;
110
+ }
111
+ if (t.min !== undefined && value < t.min) {
112
+ return false;
113
+ }
114
+ if (t.max !== undefined && value > t.max) {
115
+ return false;
116
+ }
117
+ return true;
118
+ },
119
+ [TYPE_INDEX_MAP.uint16]: (value, t) => {
120
+ if (typeof value !== 'number' || value % t.step !== 0) {
121
+ return false;
122
+ }
123
+ if (value > 65535 || value < 0) {
124
+ return false;
125
+ }
126
+ if (t.min !== undefined && value < t.min) {
127
+ return false;
128
+ }
129
+ if (t.max !== undefined && value > t.max) {
130
+ return false;
131
+ }
132
+ return true;
133
+ },
134
+ [TYPE_INDEX_MAP.uint32]: (value, t) => {
135
+ if (typeof value !== 'number' || value % t.step !== 0) {
136
+ return false;
137
+ }
138
+ if (value > 4294967295 || value < 0) {
139
+ return false;
140
+ }
141
+ if (t.min !== undefined && value < t.min) {
142
+ return false;
143
+ }
144
+ if (t.max !== undefined && value > t.max) {
145
+ return false;
146
+ }
147
+ return true;
148
+ },
149
+ [TYPE_INDEX_MAP.number]: (value, t) => {
150
+ if (t.step) {
151
+ const div = value / t.step;
152
+ if (Math.abs(div - Math.round(div)) > EPSILON) {
153
+ return false;
154
+ }
155
+ }
156
+ if (typeof value !== 'number') {
157
+ return false;
158
+ }
159
+ if (t.min !== undefined && value < t.min) {
160
+ return false;
161
+ }
162
+ if (t.max !== undefined && value > t.max) {
163
+ return false;
164
+ }
165
+ return true;
166
+ },
167
+ [TYPE_INDEX_MAP.enum]: (value, prop) => {
168
+ if (value === null) {
169
+ return true;
170
+ }
171
+ const arr = prop.enum;
172
+ for (let i = 0; i < arr.length; i++) {
173
+ if (value === arr[i]) {
174
+ return true;
175
+ }
176
+ }
177
+ return false;
178
+ },
179
+ [TYPE_INDEX_MAP.id]: (value) => {
180
+ if (typeof value !== 'number' || value % 1 !== 0) {
181
+ return false;
182
+ }
183
+ return true;
184
+ },
185
+ [TYPE_INDEX_MAP.json]: (value) => {
186
+ return true;
187
+ },
188
+ [TYPE_INDEX_MAP.microbuffer]: (value) => {
189
+ if (!(value instanceof Uint8Array)) {
190
+ return false;
191
+ }
192
+ return true;
193
+ },
194
+ [TYPE_INDEX_MAP.reference]: (v) => {
195
+ if (typeof v !== 'number') {
196
+ return false;
197
+ }
198
+ if (v === 0 || v > MAX_ID) {
199
+ return false;
200
+ }
201
+ return true;
202
+ },
203
+ [TYPE_INDEX_MAP.references]: (v) => {
204
+ if (typeof v !== 'number') {
205
+ return false;
206
+ }
207
+ if (v === 0 || v > MAX_ID) {
208
+ return false;
209
+ }
210
+ return true;
211
+ },
212
+ [TYPE_INDEX_MAP.string]: (value, t) => {
213
+ // add max etc all here - make a ref to the original SCHEMA on DEF
214
+ if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
215
+ return false;
216
+ }
217
+ return true;
218
+ },
219
+ [TYPE_INDEX_MAP.text]: (value, t) => {
220
+ // add max etc all here - make a ref to the original SCHEMA on DEF
221
+ if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
222
+ return false;
223
+ }
224
+ return true;
225
+ },
226
+ [TYPE_INDEX_MAP.aliases]: (value) => {
227
+ if (!Array.isArray(value)) {
228
+ return false;
229
+ }
230
+ const len = value.length;
231
+ for (let i = 0; i < len; i++) {
232
+ if (typeof value[i] !== 'string') {
233
+ return false;
234
+ }
235
+ }
236
+ return true;
237
+ },
238
+ [TYPE_INDEX_MAP.vector]: (value) => {
239
+ // Array should be supported
240
+ if (!(value instanceof Float32Array)) {
241
+ return false;
242
+ }
243
+ return true;
244
+ },
245
+ };
246
+ export const defaultValidation = () => true;
247
+ export const isValidId = (id) => {
248
+ if (typeof id != 'number' || id < MIN_ID || id > MAX_ID) {
249
+ return false;
250
+ }
251
+ return true;
252
+ };
253
+ export const isValidString = (v) => {
254
+ const isVal = typeof v === 'string' ||
255
+ v instanceof Uint8Array ||
256
+ ArrayBuffer.isView(v);
257
+ return isVal;
258
+ };
259
+ //# sourceMappingURL=validation.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './types.js';
2
2
  export * from './parse/index.js';
3
3
  export * from './lang.js';
4
- export * from './mermaid.js';
4
+ export * from './def/validation.js';
5
+ export * from './serialize.js';
5
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './types.js';
2
2
  export * from './parse/index.js';
3
3
  export * from './lang.js';
4
- export * from './mermaid.js';
4
+ export * from './def/validation.js';
5
+ export * from './serialize.js';
5
6
  //# sourceMappingURL=index.js.map
package/dist/lang.d.ts CHANGED
@@ -144,8 +144,10 @@ declare const langCodes: {
144
144
  readonly yi: 142;
145
145
  readonly yo: 143;
146
146
  readonly zu: 144;
147
+ readonly ka: 145;
148
+ readonly cnr: 146;
147
149
  };
148
- export declare const langCodesMap: Map<string, 0 | 2 | 1 | 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>;
150
+ export declare const langCodesMap: Map<string, 0 | 2 | 1 | 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 | 145 | 146>;
149
151
  export declare const inverseLangMap: Map<any, any>;
150
152
  export type LangName = keyof typeof langCodes;
151
153
  export type LangCode = (typeof langCodes)[LangName];
package/dist/lang.js CHANGED
@@ -144,6 +144,8 @@ const langCodes = {
144
144
  yi: 142,
145
145
  yo: 143,
146
146
  zu: 144,
147
+ ka: 145,
148
+ cnr: 146,
147
149
  };
148
150
  export const langCodesMap = new Map(Object.entries(langCodes));
149
151
  export const inverseLangMap = new Map();
@@ -1,4 +1,3 @@
1
- import { isFloat32Array } from 'util/types';
2
1
  import { EXPECTED_ARR, EXPECTED_BOOL, EXPECTED_FN, EXPECTED_NUM, EXPECTED_OBJ, EXPECTED_STR, } from './errors.js';
3
2
  export const expectObject = (obj, msg) => {
4
3
  if (typeof obj !== 'object' || obj === null) {
@@ -6,7 +5,7 @@ export const expectObject = (obj, msg) => {
6
5
  }
7
6
  };
8
7
  export const expectFloat32Array = (arr) => {
9
- if (!isFloat32Array(arr)) {
8
+ if (!(arr instanceof Float32Array)) {
10
9
  throw Error(EXPECTED_ARR);
11
10
  }
12
11
  };
@@ -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(): void;
15
+ parse(): StrictSchema;
16
16
  }
17
17
  export declare const print: (schema: Schema, path: string[]) => string;
18
18
  export declare const parse: (schema: Schema) => {
@@ -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;
@@ -63,6 +64,9 @@ export class SchemaParser {
63
64
  expectObject(locales);
64
65
  for (const locale in locales) {
65
66
  const opts = locales[locale];
67
+ if (opts === true) {
68
+ continue;
69
+ }
66
70
  expectObject(opts);
67
71
  for (const key in opts) {
68
72
  const val = opts[key];
@@ -70,7 +74,7 @@ export class SchemaParser {
70
74
  expectBoolean(val);
71
75
  }
72
76
  else if (key === 'fallback') {
73
- if (!Array.isArray(val) || !val.every((v) => typeof v === 'string')) {
77
+ if (Array.isArray(val) || typeof val !== 'string') {
74
78
  throw Error(INVALID_VALUE);
75
79
  }
76
80
  }
@@ -97,6 +101,7 @@ export class SchemaParser {
97
101
  throw Error(UNKNOWN_PROP);
98
102
  }
99
103
  }
104
+ return this.schema;
100
105
  }
101
106
  }
102
107
  export const print = (schema, path) => {
@@ -120,9 +125,7 @@ export const print = (schema, path) => {
120
125
  export const parse = (schema) => {
121
126
  const parser = new SchemaParser(schema);
122
127
  try {
123
- parser.parse();
124
- // @ts-ignore
125
- return { schema };
128
+ return { schema: parser.parse() };
126
129
  }
127
130
  catch (e) {
128
131
  const cause = parser.path.slice(0, Math.min(4, parser.lvl) + 1);
@@ -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