@based/schema 5.0.0-alpha.9 → 5.0.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/dist/def/addEdges.js +26 -3
- package/dist/def/createEmptyDef.d.ts +13 -9
- package/dist/def/createEmptyDef.js +7 -3
- package/dist/def/defaultMap.js +28 -24
- package/dist/def/fillEmptyMain.d.ts +2 -2
- package/dist/def/fillEmptyMain.js +13 -4
- package/dist/def/index.d.ts +0 -1
- package/dist/def/index.js +0 -1
- package/dist/def/makeSeparateSort.js +6 -6
- package/dist/def/makeSeparateTextSort.js +12 -12
- package/dist/def/refSet.d.ts +7 -0
- package/dist/def/refSet.js +25 -0
- package/dist/def/selvaBuffer.js +77 -28
- package/dist/def/typeDef.d.ts +9 -3
- package/dist/def/typeDef.js +136 -59
- package/dist/def/typeIndexes.d.ts +40 -0
- package/dist/def/typeIndexes.js +50 -0
- package/dist/def/types.d.ts +36 -57
- package/dist/def/types.js +22 -28
- package/dist/def/utils.d.ts +5 -3
- package/dist/def/utils.js +44 -2
- package/dist/def/validation.d.ts +2 -0
- package/dist/def/validation.js +89 -41
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/infer.d.ts +82 -0
- package/dist/infer.js +5 -0
- package/dist/lang.d.ts +3 -1
- package/dist/lang.js +6 -0
- package/dist/parse/assert.d.ts +4 -0
- package/dist/parse/assert.js +19 -2
- package/dist/parse/index.d.ts +2 -0
- package/dist/parse/index.js +61 -4
- package/dist/parse/props.d.ts +1 -0
- package/dist/parse/props.js +171 -54
- package/dist/parse/semver/_constants.d.ts +12 -0
- package/dist/parse/semver/_constants.js +21 -0
- package/dist/parse/semver/_shared.d.ts +44 -0
- package/dist/parse/semver/_shared.js +165 -0
- package/dist/parse/semver/_test_comparator_set.d.ts +3 -0
- package/dist/parse/semver/_test_comparator_set.js +60 -0
- package/dist/parse/semver/can_parse.d.ts +17 -0
- package/dist/parse/semver/can_parse.js +28 -0
- package/dist/parse/semver/compare.d.ts +28 -0
- package/dist/parse/semver/compare.js +36 -0
- package/dist/parse/semver/difference.d.ts +27 -0
- package/dist/parse/semver/difference.js +41 -0
- package/dist/parse/semver/equals.d.ts +24 -0
- package/dist/parse/semver/equals.js +28 -0
- package/dist/parse/semver/format.d.ts +22 -0
- package/dist/parse/semver/format.js +33 -0
- package/dist/parse/semver/format_range.d.ts +18 -0
- package/dist/parse/semver/format_range.js +29 -0
- package/dist/parse/semver/greater_or_equal.d.ts +25 -0
- package/dist/parse/semver/greater_or_equal.js +27 -0
- package/dist/parse/semver/greater_than.d.ts +25 -0
- package/dist/parse/semver/greater_than.js +29 -0
- package/dist/parse/semver/greater_than_range.d.ts +23 -0
- package/dist/parse/semver/greater_than_range.js +59 -0
- package/dist/parse/semver/increment.d.ts +51 -0
- package/dist/parse/semver/increment.js +175 -0
- package/dist/parse/semver/is_range.d.ts +23 -0
- package/dist/parse/semver/is_range.js +39 -0
- package/dist/parse/semver/is_semver.d.ts +34 -0
- package/dist/parse/semver/is_semver.js +54 -0
- package/dist/parse/semver/less_or_equal.d.ts +25 -0
- package/dist/parse/semver/less_or_equal.js +27 -0
- package/dist/parse/semver/less_than.d.ts +25 -0
- package/dist/parse/semver/less_than.js +27 -0
- package/dist/parse/semver/less_than_range.d.ts +23 -0
- package/dist/parse/semver/less_than_range.js +59 -0
- package/dist/parse/semver/max_satisfying.d.ts +22 -0
- package/dist/parse/semver/max_satisfying.js +31 -0
- package/dist/parse/semver/min_satisfying.d.ts +22 -0
- package/dist/parse/semver/min_satisfying.js +31 -0
- package/dist/parse/semver/mod.d.ts +298 -0
- package/dist/parse/semver/mod.js +301 -0
- package/dist/parse/semver/not_equals.d.ts +24 -0
- package/dist/parse/semver/not_equals.js +26 -0
- package/dist/parse/semver/parse.d.ts +25 -0
- package/dist/parse/semver/parse.js +43 -0
- package/dist/parse/semver/parse_range.d.ts +27 -0
- package/dist/parse/semver/parse_range.js +361 -0
- package/dist/parse/semver/range_intersects.d.ts +25 -0
- package/dist/parse/semver/range_intersects.js +83 -0
- package/dist/parse/semver/satisfies.d.ts +24 -0
- package/dist/parse/semver/satisfies.js +28 -0
- package/dist/parse/semver/try_parse.d.ts +21 -0
- package/dist/parse/semver/try_parse.js +28 -0
- package/dist/parse/semver/try_parse_range.d.ts +23 -0
- package/dist/parse/semver/try_parse_range.js +34 -0
- package/dist/parse/semver/types.d.ts +58 -0
- package/dist/parse/semver/types.js +4 -0
- package/dist/serialize.d.ts +14 -0
- package/dist/serialize.js +543 -0
- package/dist/types.d.ts +74 -20
- package/dist/types.js +3 -1
- package/package.json +5 -4
- package/dist/def/getPropLen.d.ts +0 -3
- package/dist/def/getPropLen.js +0 -23
- package/dist/def/makePacked.d.ts +0 -3
- package/dist/def/makePacked.js +0 -50
- package/dist/def/readFromPacked.d.ts +0 -3
- package/dist/def/readFromPacked.js +0 -140
- package/dist/mermaid.d.ts +0 -3
- package/dist/mermaid.js +0 -24
package/dist/def/typeDef.js
CHANGED
|
@@ -1,55 +1,108 @@
|
|
|
1
1
|
import { isPropType, getPropType, } from '../index.js';
|
|
2
|
-
import { setByPath } from '@
|
|
3
|
-
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, } from './types.js';
|
|
2
|
+
import { setByPath } from '@based/utils';
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, BLOCK_CAPACITY_MAX, BLOCK_CAPACITY_DEFAULT, BLOCK_CAPACITY_MIN, ALIAS, ALIASES, VECTOR, COLVEC, } from './types.js';
|
|
4
4
|
import { DEFAULT_MAP } from './defaultMap.js';
|
|
5
|
-
import { makePacked } from './makePacked.js';
|
|
6
5
|
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
7
6
|
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
8
|
-
import { getPropLen } from './
|
|
9
|
-
import { isSeparate } from './utils.js';
|
|
7
|
+
import { getPropLen, isSeparate, parseMinMaxStep, schemaVectorBaseTypeToEnum, } from './utils.js';
|
|
10
8
|
import { addEdges } from './addEdges.js';
|
|
11
9
|
import { createEmptyDef } from './createEmptyDef.js';
|
|
12
|
-
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
13
10
|
import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
|
|
14
11
|
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export const updateTypeDefs = (schema) => {
|
|
13
|
+
const schemaTypesParsed = {};
|
|
14
|
+
const schemaTypesParsedById = {};
|
|
15
|
+
for (const typeName in schemaTypesParsed) {
|
|
16
|
+
if (typeName in schema.types) {
|
|
19
17
|
continue;
|
|
20
18
|
}
|
|
21
|
-
const id = schemaTypesParsed[
|
|
22
|
-
delete schemaTypesParsed[
|
|
19
|
+
const id = schemaTypesParsed[typeName].id;
|
|
20
|
+
delete schemaTypesParsed[typeName];
|
|
23
21
|
delete schemaTypesParsedById[id];
|
|
24
22
|
}
|
|
25
|
-
for (const
|
|
26
|
-
const type = schema.types[
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
) {
|
|
30
|
-
continue;
|
|
23
|
+
for (const typeName in schema.types) {
|
|
24
|
+
const type = schema.types[typeName];
|
|
25
|
+
if (!type.id) {
|
|
26
|
+
throw new Error('NEED ID ON TYPE');
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const def = createSchemaTypeDef(typeName, type, schemaTypesParsed, schema.locales ?? {
|
|
29
|
+
en: {},
|
|
30
|
+
});
|
|
31
|
+
schemaTypesParsed[typeName] = def;
|
|
32
|
+
schemaTypesParsedById[type.id] = def;
|
|
33
|
+
}
|
|
34
|
+
// Update inverseProps in references
|
|
35
|
+
for (const schema of Object.values(schemaTypesParsed)) {
|
|
36
|
+
for (const prop of Object.values(schema.props)) {
|
|
37
|
+
if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
|
|
38
|
+
if (!prop.__isEdge) {
|
|
39
|
+
const dstType = schemaTypesParsed[prop.inverseTypeName];
|
|
40
|
+
prop.inverseTypeId = dstType.id;
|
|
41
|
+
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
|
-
const def = createSchemaTypeDef(field, type, schemaTypesParsed, schema.locales ?? {
|
|
37
|
-
en: {},
|
|
38
|
-
});
|
|
39
|
-
def.blockCapacity =
|
|
40
|
-
field === '_root' ? 2147483647 : DEFAULT_BLOCK_CAPACITY; // TODO this should come from somewhere else
|
|
41
|
-
schemaTypesParsed[field] = def;
|
|
42
|
-
schemaTypesParsedById[type.id] = def;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
return { schemaTypesParsed, schemaTypesParsedById };
|
|
45
47
|
};
|
|
48
|
+
function propIndexOffset(prop) {
|
|
49
|
+
if (!prop.separate) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
switch (prop.typeIndex) {
|
|
53
|
+
case REFERENCES:
|
|
54
|
+
case REFERENCE:
|
|
55
|
+
return -300;
|
|
56
|
+
case ALIAS:
|
|
57
|
+
case ALIASES:
|
|
58
|
+
case COLVEC:
|
|
59
|
+
return 300;
|
|
60
|
+
default:
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function reorderProps(props) {
|
|
65
|
+
props.sort((a, b) => a.prop + propIndexOffset(a) - (b.prop + propIndexOffset(b)));
|
|
66
|
+
// Reassign prop indices
|
|
67
|
+
let lastProp = 0;
|
|
68
|
+
for (const p of props) {
|
|
69
|
+
if (p.separate) {
|
|
70
|
+
p.prop = ++lastProp;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
46
74
|
export const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
|
|
75
|
+
if (top) {
|
|
76
|
+
if (result.id == 0) {
|
|
77
|
+
if ('id' in type) {
|
|
78
|
+
result.id = type.id;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error(`Invalid schema type id ${result.type}`);
|
|
82
|
+
}
|
|
50
83
|
}
|
|
51
|
-
|
|
52
|
-
|
|
84
|
+
if (result.blockCapacity == 0) {
|
|
85
|
+
if ('blockCapacity' in type) {
|
|
86
|
+
if (typeof type.blockCapacity !== 'number' ||
|
|
87
|
+
type.blockCapacity < BLOCK_CAPACITY_MIN ||
|
|
88
|
+
type.blockCapacity > BLOCK_CAPACITY_MAX) {
|
|
89
|
+
throw new Error('Invalid blockCapacity');
|
|
90
|
+
}
|
|
91
|
+
result.blockCapacity = type.blockCapacity;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
result.blockCapacity =
|
|
95
|
+
typeName === '_root' ? BLOCK_CAPACITY_MAX : BLOCK_CAPACITY_DEFAULT;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (result.insertOnly == false && 'insertOnly' in type) {
|
|
99
|
+
result.insertOnly = !!type.insertOnly;
|
|
100
|
+
}
|
|
101
|
+
if (result.partial == false && 'partial' in type) {
|
|
102
|
+
result.partial = !!type.partial;
|
|
103
|
+
}
|
|
104
|
+
if ('hooks' in type) {
|
|
105
|
+
result.hooks = type.hooks;
|
|
53
106
|
}
|
|
54
107
|
}
|
|
55
108
|
result.locales = locales;
|
|
@@ -57,8 +110,6 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
57
110
|
result.idUint8[0] = result.id & 255;
|
|
58
111
|
result.idUint8[1] = result.id >> 8;
|
|
59
112
|
const target = type.props;
|
|
60
|
-
let separateSortProps = 0;
|
|
61
|
-
let separateSortText = 0;
|
|
62
113
|
for (const key in target) {
|
|
63
114
|
// Create prop def
|
|
64
115
|
const schemaProp = target[key];
|
|
@@ -75,15 +126,20 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
75
126
|
if (typeof schemaProp === 'object') {
|
|
76
127
|
if (!(schemaProp.maxBytes < 61) ||
|
|
77
128
|
!('max' in schemaProp && schemaProp.max < 31)) {
|
|
78
|
-
separateSortProps++;
|
|
129
|
+
result.separateSortProps++;
|
|
79
130
|
}
|
|
80
131
|
}
|
|
81
132
|
else {
|
|
82
|
-
separateSortProps++;
|
|
133
|
+
result.separateSortProps++;
|
|
83
134
|
}
|
|
84
135
|
}
|
|
85
136
|
else if (isPropType('text', schemaProp)) {
|
|
86
|
-
separateSortText++;
|
|
137
|
+
result.separateSortText++;
|
|
138
|
+
}
|
|
139
|
+
else if (isPropType('colvec', schemaProp)) {
|
|
140
|
+
if (!result.insertOnly) {
|
|
141
|
+
throw new Error('colvec requires insertOnly');
|
|
142
|
+
}
|
|
87
143
|
}
|
|
88
144
|
const isseparate = isSeparate(schemaProp, len);
|
|
89
145
|
const typeIndex = TYPE_INDEX_MAP[propType];
|
|
@@ -93,16 +149,27 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
93
149
|
separate: isseparate,
|
|
94
150
|
path: propPath,
|
|
95
151
|
start: 0,
|
|
96
|
-
validation: schemaProp.
|
|
152
|
+
validation: schemaProp.validation ??
|
|
153
|
+
VALIDATION_MAP[typeIndex] ??
|
|
154
|
+
defaultValidation,
|
|
97
155
|
len,
|
|
98
156
|
default: schemaProp.default ?? DEFAULT_MAP[typeIndex],
|
|
99
157
|
prop: isseparate ? ++result.cnt : 0,
|
|
100
158
|
};
|
|
101
|
-
if (schemaProp.max) {
|
|
102
|
-
prop.max = schemaProp.max;
|
|
159
|
+
if (schemaProp.max !== undefined) {
|
|
160
|
+
prop.max = parseMinMaxStep(schemaProp.max);
|
|
103
161
|
}
|
|
104
|
-
if (schemaProp.min) {
|
|
105
|
-
prop.min = schemaProp.min;
|
|
162
|
+
if (schemaProp.min !== undefined) {
|
|
163
|
+
prop.min = parseMinMaxStep(schemaProp.min);
|
|
164
|
+
}
|
|
165
|
+
if (schemaProp.step !== undefined) {
|
|
166
|
+
prop.step = parseMinMaxStep(schemaProp.step);
|
|
167
|
+
}
|
|
168
|
+
if (prop.typeIndex !== NUMBER && prop.step === undefined) {
|
|
169
|
+
prop.step = 1;
|
|
170
|
+
}
|
|
171
|
+
if (prop.typeIndex === VECTOR || prop.typeIndex === COLVEC) {
|
|
172
|
+
prop.vectorBaseType = schemaVectorBaseTypeToEnum(schemaProp.baseType ?? 'number');
|
|
106
173
|
}
|
|
107
174
|
if (isPropType('enum', schemaProp)) {
|
|
108
175
|
prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
|
|
@@ -112,12 +179,18 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
112
179
|
}
|
|
113
180
|
}
|
|
114
181
|
else if (isPropType('references', schemaProp)) {
|
|
182
|
+
if (result.partial) {
|
|
183
|
+
throw new Error('references is not supported with partial');
|
|
184
|
+
}
|
|
115
185
|
prop.inversePropName = schemaProp.items.prop;
|
|
116
186
|
prop.inverseTypeName = schemaProp.items.ref;
|
|
117
187
|
prop.dependent = schemaProp.items.dependent;
|
|
118
188
|
addEdges(prop, schemaProp.items);
|
|
119
189
|
}
|
|
120
190
|
else if (isPropType('reference', schemaProp)) {
|
|
191
|
+
if (result.partial) {
|
|
192
|
+
throw new Error('reference is not supported with partial');
|
|
193
|
+
}
|
|
121
194
|
prop.inversePropName = schemaProp.prop;
|
|
122
195
|
prop.inverseTypeName = schemaProp.ref;
|
|
123
196
|
prop.dependent = schemaProp.dependent;
|
|
@@ -153,24 +226,26 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
153
226
|
if (top) {
|
|
154
227
|
// Put top level together
|
|
155
228
|
const vals = Object.values(result.props);
|
|
156
|
-
vals
|
|
157
|
-
if (b.separate &&
|
|
158
|
-
(a.typeIndex === REFERENCES || a.typeIndex === REFERENCE)) {
|
|
159
|
-
return -1;
|
|
160
|
-
}
|
|
161
|
-
return a.prop - b.prop;
|
|
162
|
-
});
|
|
163
|
-
let lastProp = 0;
|
|
164
|
-
for (const p of vals) {
|
|
165
|
-
if (p.separate) {
|
|
166
|
-
p.prop = ++lastProp;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
229
|
+
reorderProps(vals);
|
|
169
230
|
let len = 2;
|
|
231
|
+
let biggestSeperatePropDefault = 0;
|
|
170
232
|
for (const f of vals) {
|
|
171
233
|
if (f.separate) {
|
|
172
234
|
len += 2;
|
|
173
235
|
setByPath(result.tree, f.path, f);
|
|
236
|
+
if (f.default !== undefined) {
|
|
237
|
+
result.hasSeperateDefaults = true;
|
|
238
|
+
if (!result.separateDefaults) {
|
|
239
|
+
result.separateDefaults = {
|
|
240
|
+
props: new Map(),
|
|
241
|
+
bufferTmp: new Uint8Array(),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
result.separateDefaults.props.set(f.prop, f);
|
|
245
|
+
if (f.prop > biggestSeperatePropDefault) {
|
|
246
|
+
biggestSeperatePropDefault = f.prop;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
174
249
|
}
|
|
175
250
|
else {
|
|
176
251
|
if (!result.mainLen) {
|
|
@@ -182,13 +257,15 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
182
257
|
setByPath(result.tree, f.path, f);
|
|
183
258
|
}
|
|
184
259
|
}
|
|
260
|
+
if (result.hasSeperateDefaults) {
|
|
261
|
+
result.separateDefaults.bufferTmp = new Uint8Array(biggestSeperatePropDefault + 1);
|
|
262
|
+
}
|
|
185
263
|
result.mainEmpty = fillEmptyMain(vals, result.mainLen);
|
|
186
264
|
result.mainEmptyAllZeroes = isZeroes(result.mainEmpty);
|
|
187
|
-
|
|
188
|
-
if (separateSortText > 0) {
|
|
265
|
+
if (result.separateSortText > 0) {
|
|
189
266
|
makeSeparateTextSort(result);
|
|
190
267
|
}
|
|
191
|
-
if (separateSortProps > 0) {
|
|
268
|
+
if (result.separateSortProps > 0) {
|
|
192
269
|
makeSeparateSort(result);
|
|
193
270
|
}
|
|
194
271
|
for (const p in result.props) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const NULL = 0;
|
|
2
|
+
export declare const TIMESTAMP = 1;
|
|
3
|
+
export declare const NUMBER = 4;
|
|
4
|
+
export declare const CARDINALITY = 5;
|
|
5
|
+
export declare const INT8 = 20;
|
|
6
|
+
export declare const UINT8 = 6;
|
|
7
|
+
export declare const INT16 = 21;
|
|
8
|
+
export declare const UINT16 = 22;
|
|
9
|
+
export declare const INT32 = 23;
|
|
10
|
+
export declare const UINT32 = 7;
|
|
11
|
+
export declare const BOOLEAN = 9;
|
|
12
|
+
export declare const ENUM = 10;
|
|
13
|
+
export declare const STRING = 11;
|
|
14
|
+
export declare const TEXT = 12;
|
|
15
|
+
export declare const REFERENCE = 13;
|
|
16
|
+
export declare const REFERENCES = 14;
|
|
17
|
+
export declare const WEAK_REFERENCE = 15;
|
|
18
|
+
export declare const WEAK_REFERENCES = 16;
|
|
19
|
+
export declare const MICRO_BUFFER = 17;
|
|
20
|
+
export declare const ALIAS = 18;
|
|
21
|
+
export declare const ALIASES = 19;
|
|
22
|
+
export declare const BINARY = 25;
|
|
23
|
+
export declare const ID = 26;
|
|
24
|
+
export declare const VECTOR = 27;
|
|
25
|
+
export declare const JSON = 28;
|
|
26
|
+
export declare const OBJECT = 29;
|
|
27
|
+
export declare const COLVEC = 30;
|
|
28
|
+
export type TypeIndex = typeof NULL | typeof TIMESTAMP | typeof NUMBER | typeof CARDINALITY | typeof INT8 | typeof UINT8 | typeof INT16 | typeof UINT16 | typeof INT32 | typeof UINT32 | typeof BOOLEAN | typeof ENUM | typeof STRING | typeof TEXT | typeof REFERENCE | typeof REFERENCES | typeof WEAK_REFERENCE | typeof WEAK_REFERENCES | typeof MICRO_BUFFER | typeof ALIAS | typeof ALIASES | typeof BINARY | typeof ID | typeof VECTOR | typeof JSON | typeof OBJECT | typeof COLVEC;
|
|
29
|
+
export declare enum VectorBaseType {
|
|
30
|
+
Int8 = 1,
|
|
31
|
+
Uint8 = 2,
|
|
32
|
+
Int16 = 3,
|
|
33
|
+
Uint16 = 4,
|
|
34
|
+
Int32 = 5,
|
|
35
|
+
Uint32 = 6,
|
|
36
|
+
Float32 = 7,
|
|
37
|
+
Float64 = 8
|
|
38
|
+
}
|
|
39
|
+
export declare const isNumberType: (type: TypeIndex) => boolean;
|
|
40
|
+
//# sourceMappingURL=typeIndexes.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
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 var VectorBaseType;
|
|
30
|
+
(function (VectorBaseType) {
|
|
31
|
+
VectorBaseType[VectorBaseType["Int8"] = 1] = "Int8";
|
|
32
|
+
VectorBaseType[VectorBaseType["Uint8"] = 2] = "Uint8";
|
|
33
|
+
VectorBaseType[VectorBaseType["Int16"] = 3] = "Int16";
|
|
34
|
+
VectorBaseType[VectorBaseType["Uint16"] = 4] = "Uint16";
|
|
35
|
+
VectorBaseType[VectorBaseType["Int32"] = 5] = "Int32";
|
|
36
|
+
VectorBaseType[VectorBaseType["Uint32"] = 6] = "Uint32";
|
|
37
|
+
VectorBaseType[VectorBaseType["Float32"] = 7] = "Float32";
|
|
38
|
+
VectorBaseType[VectorBaseType["Float64"] = 8] = "Float64";
|
|
39
|
+
})(VectorBaseType || (VectorBaseType = {}));
|
|
40
|
+
export const isNumberType = (type) => {
|
|
41
|
+
return (type === NUMBER ||
|
|
42
|
+
type === UINT16 ||
|
|
43
|
+
type === UINT32 ||
|
|
44
|
+
type === INT16 ||
|
|
45
|
+
type === INT32 ||
|
|
46
|
+
type == UINT8 ||
|
|
47
|
+
type === INT8 ||
|
|
48
|
+
type === CARDINALITY);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=typeIndexes.js.map
|
package/dist/def/types.d.ts
CHANGED
|
@@ -1,56 +1,19 @@
|
|
|
1
|
-
import type { LangCode, SchemaLocales } from '../index.js';
|
|
1
|
+
import type { LangCode, SchemaHooks, SchemaLocales } from '../index.js';
|
|
2
2
|
import { Validation } from './validation.js';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare const TEXT = 12;
|
|
17
|
-
export declare const REFERENCE = 13;
|
|
18
|
-
export declare const REFERENCES = 14;
|
|
19
|
-
export declare const WEAK_REFERENCE = 15;
|
|
20
|
-
export declare const WEAK_REFERENCES = 16;
|
|
21
|
-
export declare const MICRO_BUFFER = 17;
|
|
22
|
-
export declare const ALIAS = 18;
|
|
23
|
-
export declare const ALIASES = 19;
|
|
24
|
-
export declare const BINARY = 25;
|
|
25
|
-
export declare const ID = 26;
|
|
26
|
-
export declare const VECTOR = 27;
|
|
27
|
-
export declare const JSON = 28;
|
|
28
|
-
export declare const TYPE_INDEX_MAP: {
|
|
29
|
-
alias: number;
|
|
30
|
-
aliases: number;
|
|
31
|
-
microbuffer: number;
|
|
32
|
-
references: number;
|
|
33
|
-
reference: number;
|
|
34
|
-
timestamp: number;
|
|
35
|
-
boolean: number;
|
|
36
|
-
number: number;
|
|
37
|
-
string: number;
|
|
38
|
-
text: number;
|
|
39
|
-
uint16: number;
|
|
40
|
-
uint32: number;
|
|
41
|
-
int16: number;
|
|
42
|
-
int32: number;
|
|
43
|
-
uint8: number;
|
|
44
|
-
enum: number;
|
|
45
|
-
int8: number;
|
|
46
|
-
id: number;
|
|
47
|
-
binary: number;
|
|
48
|
-
vector: number;
|
|
49
|
-
cardinality: number;
|
|
50
|
-
json: number;
|
|
51
|
-
};
|
|
3
|
+
import { TypeIndex, VectorBaseType } from './typeIndexes.js';
|
|
4
|
+
export * from './typeIndexes.js';
|
|
5
|
+
export declare const TYPE_INDEX_MAP: Record<string, TypeIndex>;
|
|
6
|
+
export declare const enum numberTypes {
|
|
7
|
+
number = 4,
|
|
8
|
+
uint16 = 22,
|
|
9
|
+
uint32 = 7,
|
|
10
|
+
int16 = 21,
|
|
11
|
+
int32 = 23,
|
|
12
|
+
uint8 = 6,
|
|
13
|
+
int8 = 20,
|
|
14
|
+
cardinality = 5
|
|
15
|
+
}
|
|
52
16
|
export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
|
|
53
|
-
export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
|
|
54
17
|
export type PropDef = {
|
|
55
18
|
__isPropDef: true;
|
|
56
19
|
prop: number;
|
|
@@ -68,7 +31,10 @@ export type PropDef = {
|
|
|
68
31
|
dependent?: boolean;
|
|
69
32
|
validation: Validation;
|
|
70
33
|
default: any;
|
|
34
|
+
vectorBaseType?: VectorBaseType;
|
|
35
|
+
vectorSize?: number;
|
|
71
36
|
edgeMainLen?: 0;
|
|
37
|
+
hasDefaultEdges?: boolean;
|
|
72
38
|
reverseEnum?: {
|
|
73
39
|
[key: string]: number;
|
|
74
40
|
};
|
|
@@ -84,8 +50,9 @@ export type PropDef = {
|
|
|
84
50
|
};
|
|
85
51
|
edgeMainEmpty?: Uint8Array;
|
|
86
52
|
__isEdge?: boolean;
|
|
87
|
-
max?:
|
|
88
|
-
min?:
|
|
53
|
+
max?: any;
|
|
54
|
+
min?: any;
|
|
55
|
+
step?: any;
|
|
89
56
|
};
|
|
90
57
|
export type PropDefEdge = Partial<PropDef> & {
|
|
91
58
|
__isPropDef: true;
|
|
@@ -112,17 +79,20 @@ export type SchemaSortUndefinedHandler = {
|
|
|
112
79
|
bufferTmp: Uint8Array;
|
|
113
80
|
props: PropDef[];
|
|
114
81
|
};
|
|
82
|
+
export declare const BLOCK_CAPACITY_MIN = 1025;
|
|
83
|
+
export declare const BLOCK_CAPACITY_MAX = 2147483647;
|
|
84
|
+
export declare const BLOCK_CAPACITY_DEFAULT = 100000;
|
|
115
85
|
export type SchemaTypeDef = {
|
|
116
86
|
cnt: number;
|
|
117
87
|
checksum: number;
|
|
118
|
-
total: number;
|
|
119
88
|
type: string;
|
|
120
89
|
lastId: number;
|
|
121
90
|
blockCapacity: number;
|
|
122
91
|
mainLen: number;
|
|
92
|
+
insertOnly: boolean;
|
|
93
|
+
partial: boolean;
|
|
123
94
|
buf: Uint8Array;
|
|
124
95
|
propNames: Uint8Array;
|
|
125
|
-
packed: Uint8Array;
|
|
126
96
|
props: {
|
|
127
97
|
[path: string]: PropDef;
|
|
128
98
|
};
|
|
@@ -138,19 +108,28 @@ export type SchemaTypeDef = {
|
|
|
138
108
|
mainEmpty: Uint8Array;
|
|
139
109
|
mainEmptyAllZeroes: boolean;
|
|
140
110
|
tree: SchemaPropTree;
|
|
111
|
+
separateSortProps: number;
|
|
112
|
+
separateSortText: number;
|
|
141
113
|
hasSeperateSort: boolean;
|
|
142
|
-
|
|
114
|
+
separateSort: SchemaSortUndefinedHandler;
|
|
143
115
|
hasSeperateTextSort: boolean;
|
|
144
|
-
|
|
116
|
+
separateTextSort: SchemaSortUndefinedHandler & {
|
|
145
117
|
noUndefined: Uint8Array;
|
|
146
118
|
localeStringToIndex: Map<string, Uint8Array>;
|
|
147
119
|
localeToIndex: Map<LangCode, number>;
|
|
148
120
|
};
|
|
121
|
+
hasSeperateDefaults: boolean;
|
|
122
|
+
separateDefaults?: {
|
|
123
|
+
props: Map<number, PropDef>;
|
|
124
|
+
bufferTmp: Uint8Array;
|
|
125
|
+
};
|
|
149
126
|
createTs?: PropDef[];
|
|
150
127
|
updateTs?: PropDef[];
|
|
151
128
|
locales: Partial<SchemaLocales>;
|
|
152
129
|
localeSize: number;
|
|
130
|
+
hooks?: SchemaHooks;
|
|
153
131
|
};
|
|
132
|
+
export declare const VECTOR_BASE_TYPE_SIZE_MAP: Record<VectorBaseType, number>;
|
|
154
133
|
export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
|
|
155
134
|
export declare const REVERSE_SIZE_MAP: Record<TypeIndex, number>;
|
|
156
135
|
export declare const REVERSE_TYPE_INDEX_MAP: Record<TypeIndex, InternalSchemaProp>;
|
package/dist/def/types.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
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;
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, BOOLEAN, CARDINALITY, COLVEC, ENUM, INT16, INT32, INT8, JSON, MICRO_BUFFER, NULL, NUMBER, OBJECT, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, VectorBaseType, } from './typeIndexes.js';
|
|
2
|
+
export * from './typeIndexes.js';
|
|
27
3
|
export const TYPE_INDEX_MAP = {
|
|
28
4
|
alias: ALIAS,
|
|
29
5
|
aliases: ALIASES,
|
|
@@ -47,6 +23,21 @@ export const TYPE_INDEX_MAP = {
|
|
|
47
23
|
vector: VECTOR,
|
|
48
24
|
cardinality: CARDINALITY,
|
|
49
25
|
json: JSON,
|
|
26
|
+
object: OBJECT,
|
|
27
|
+
colvec: COLVEC,
|
|
28
|
+
};
|
|
29
|
+
export const BLOCK_CAPACITY_MIN = 1025;
|
|
30
|
+
export const BLOCK_CAPACITY_MAX = 2147483647;
|
|
31
|
+
export const BLOCK_CAPACITY_DEFAULT = 100_000;
|
|
32
|
+
export const VECTOR_BASE_TYPE_SIZE_MAP = {
|
|
33
|
+
[VectorBaseType.Int8]: 1,
|
|
34
|
+
[VectorBaseType.Uint8]: 1,
|
|
35
|
+
[VectorBaseType.Int16]: 2,
|
|
36
|
+
[VectorBaseType.Uint16]: 2,
|
|
37
|
+
[VectorBaseType.Int32]: 4,
|
|
38
|
+
[VectorBaseType.Uint32]: 4,
|
|
39
|
+
[VectorBaseType.Float32]: 4,
|
|
40
|
+
[VectorBaseType.Float64]: 8,
|
|
50
41
|
};
|
|
51
42
|
export const SIZE_MAP = {
|
|
52
43
|
timestamp: 8, // 64bit
|
|
@@ -72,18 +63,21 @@ export const SIZE_MAP = {
|
|
|
72
63
|
binary: 0,
|
|
73
64
|
vector: 0, // separate
|
|
74
65
|
json: 0,
|
|
66
|
+
object: 0,
|
|
67
|
+
colvec: 0, // separate
|
|
75
68
|
};
|
|
76
69
|
const reverseMap = {};
|
|
77
70
|
for (const k in TYPE_INDEX_MAP) {
|
|
78
71
|
reverseMap[TYPE_INDEX_MAP[k]] = k;
|
|
79
72
|
}
|
|
73
|
+
// @ts-ignore
|
|
80
74
|
export const REVERSE_SIZE_MAP = {};
|
|
81
75
|
for (const k in SIZE_MAP) {
|
|
82
76
|
REVERSE_SIZE_MAP[TYPE_INDEX_MAP[k]] = SIZE_MAP[k];
|
|
83
77
|
}
|
|
84
78
|
export const REVERSE_TYPE_INDEX_MAP = reverseMap;
|
|
85
79
|
export const ID_FIELD_DEF = {
|
|
86
|
-
typeIndex:
|
|
80
|
+
typeIndex: NULL,
|
|
87
81
|
separate: true,
|
|
88
82
|
path: ['id'],
|
|
89
83
|
start: 0,
|
|
@@ -94,7 +88,7 @@ export const ID_FIELD_DEF = {
|
|
|
94
88
|
__isPropDef: true,
|
|
95
89
|
};
|
|
96
90
|
export const EMPTY_MICRO_BUFFER = {
|
|
97
|
-
typeIndex:
|
|
91
|
+
typeIndex: MICRO_BUFFER,
|
|
98
92
|
separate: true,
|
|
99
93
|
path: [''],
|
|
100
94
|
start: 0,
|
package/dist/def/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge } from './types.js';
|
|
2
|
-
import { SchemaProp } from '../types.js';
|
|
1
|
+
import { PropDef, PropDefEdge, VectorBaseType } from './types.js';
|
|
2
|
+
import { SchemaProp, SchemaVectorBaseType } from '../types.js';
|
|
3
3
|
export declare function isSeparate(schemaProp: SchemaProp, len: number): boolean;
|
|
4
4
|
export declare const propIsSigned: (prop: PropDef | PropDefEdge) => boolean;
|
|
5
5
|
export declare const propIsNumerical: (prop: PropDef | PropDefEdge) => boolean;
|
|
6
|
-
export declare
|
|
6
|
+
export declare const schemaVectorBaseTypeToEnum: (vector: SchemaVectorBaseType) => VectorBaseType;
|
|
7
|
+
export declare function getPropLen(schemaProp: SchemaProp): number;
|
|
8
|
+
export declare const parseMinMaxStep: (val: any) => string | number;
|
|
7
9
|
//# sourceMappingURL=utils.d.ts.map
|