@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.
- package/dist/def/DEFAULT_MAP.d.ts +3 -0
- package/dist/def/DEFAULT_MAP.js +29 -0
- package/dist/def/addEdges.d.ts +4 -0
- package/dist/def/addEdges.js +76 -0
- package/dist/def/createEmptyDef.d.ts +42 -0
- package/dist/def/createEmptyDef.js +45 -0
- package/dist/def/defaultMap.d.ts +3 -0
- package/dist/def/defaultMap.js +28 -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 +8 -0
- package/dist/def/index.js +9 -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 +145 -0
- package/dist/def/timestamp.d.ts +2 -0
- package/dist/def/timestamp.js +67 -0
- package/dist/def/typeDef.d.ts +13 -0
- package/dist/def/typeDef.js +231 -0
- package/dist/def/types.d.ts +186 -0
- package/dist/def/types.js +138 -0
- package/dist/def/utils.d.ts +8 -0
- package/dist/def/utils.js +62 -0
- package/dist/def/validation.d.ts +7 -0
- package/dist/def/validation.js +259 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/lang.d.ts +3 -1
- package/dist/lang.js +2 -0
- package/dist/parse/assert.js +1 -2
- package/dist/parse/index.d.ts +1 -1
- package/dist/parse/index.js +8 -5
- package/dist/parse/props.d.ts +1 -0
- package/dist/parse/props.js +118 -54
- package/dist/serialize.d.ts +14 -0
- package/dist/serialize.js +473 -0
- package/dist/types.d.ts +29 -9
- package/dist/types.js +2 -0
- package/dist/validation/validation.d.ts +2 -0
- package/dist/validation/validation.js +6 -0
- package/package.json +8 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, EMPTY_MICRO_BUFFER, CARDINALITY, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, COLVEC, } from './types.js';
|
|
2
|
+
const selvaFieldType = {
|
|
3
|
+
NULL: 0,
|
|
4
|
+
MICRO_BUFFER: 1,
|
|
5
|
+
STRING: 2,
|
|
6
|
+
TEXT: 3,
|
|
7
|
+
REFERENCE: 4,
|
|
8
|
+
REFERENCES: 5,
|
|
9
|
+
WEAK_REFERENCE: 6,
|
|
10
|
+
WEAK_REFERENCES: 7,
|
|
11
|
+
ALIAS: 8,
|
|
12
|
+
ALIASES: 9,
|
|
13
|
+
COLVEC: 10,
|
|
14
|
+
};
|
|
15
|
+
const selvaTypeMap = new Uint8Array(32); // 1.2x faster than JS array
|
|
16
|
+
selvaTypeMap[MICRO_BUFFER] = selvaFieldType.MICRO_BUFFER;
|
|
17
|
+
selvaTypeMap[VECTOR] = selvaFieldType.MICRO_BUFFER;
|
|
18
|
+
selvaTypeMap[BINARY] = selvaFieldType.STRING;
|
|
19
|
+
selvaTypeMap[CARDINALITY] = selvaFieldType.STRING;
|
|
20
|
+
selvaTypeMap[JSON] = selvaFieldType.STRING;
|
|
21
|
+
selvaTypeMap[STRING] = selvaFieldType.STRING;
|
|
22
|
+
selvaTypeMap[TEXT] = selvaFieldType.TEXT;
|
|
23
|
+
selvaTypeMap[REFERENCE] = selvaFieldType.REFERENCE;
|
|
24
|
+
selvaTypeMap[REFERENCES] = selvaFieldType.REFERENCES;
|
|
25
|
+
selvaTypeMap[WEAK_REFERENCE] = selvaFieldType.WEAK_REFERENCE;
|
|
26
|
+
selvaTypeMap[WEAK_REFERENCES] = selvaFieldType.WEAK_REFERENCES;
|
|
27
|
+
selvaTypeMap[ALIAS] = selvaFieldType.ALIAS;
|
|
28
|
+
selvaTypeMap[ALIASES] = selvaFieldType.ALIASES;
|
|
29
|
+
selvaTypeMap[COLVEC] = selvaFieldType.COLVEC;
|
|
30
|
+
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
31
|
+
const EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP = 0x80;
|
|
32
|
+
function blockCapacity(blockCapacity) {
|
|
33
|
+
const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
|
|
34
|
+
const view = new DataView(buf.buffer);
|
|
35
|
+
view.setUint32(0, blockCapacity, true);
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
function sepPropCount(props) {
|
|
39
|
+
return props.filter((prop) => prop.separate).length;
|
|
40
|
+
}
|
|
41
|
+
function makeEdgeConstraintFlags(prop, inverseProp) {
|
|
42
|
+
return ((prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00) |
|
|
43
|
+
(prop.typeIndex === REFERENCE && inverseProp && inverseProp.typeIndex === REFERENCES
|
|
44
|
+
? EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP
|
|
45
|
+
: 0x00));
|
|
46
|
+
}
|
|
47
|
+
const propDefBuffer = (schema, prop, isEdge) => {
|
|
48
|
+
const type = prop.typeIndex;
|
|
49
|
+
const selvaType = selvaTypeMap[type];
|
|
50
|
+
if (prop.len && (type === MICRO_BUFFER || type === VECTOR)) {
|
|
51
|
+
const buf = new Uint8Array(3);
|
|
52
|
+
const view = new DataView(buf.buffer);
|
|
53
|
+
buf[0] = selvaType;
|
|
54
|
+
view.setUint16(1, prop.len, true);
|
|
55
|
+
return [...buf];
|
|
56
|
+
}
|
|
57
|
+
else if (prop.len && (type === COLVEC)) {
|
|
58
|
+
const buf = new Uint8Array(5);
|
|
59
|
+
const view = new DataView(buf.buffer);
|
|
60
|
+
buf[0] = selvaType;
|
|
61
|
+
view.setUint16(1, prop.len, true);
|
|
62
|
+
view.setUint16(3, 4, true); // TODO Other types than f32
|
|
63
|
+
return [...buf];
|
|
64
|
+
}
|
|
65
|
+
else if (type === REFERENCE || type === REFERENCES) {
|
|
66
|
+
const buf = new Uint8Array(9);
|
|
67
|
+
const view = new DataView(buf.buffer);
|
|
68
|
+
const dstType = schema[prop.inverseTypeName];
|
|
69
|
+
let eschema = [];
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
buf[0] = selvaType + 2 * !!isEdge; // field type
|
|
72
|
+
buf[1] = makeEdgeConstraintFlags(prop, dstType.props[prop.inversePropName]); // flags
|
|
73
|
+
view.setUint16(2, dstType.id, true); // dst_node_type
|
|
74
|
+
view.setUint32(5, 0, true); // schema_len
|
|
75
|
+
if (!isEdge) {
|
|
76
|
+
prop.inverseTypeId = dstType.id;
|
|
77
|
+
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
78
|
+
buf[4] = prop.inversePropNumber;
|
|
79
|
+
if (prop.edges) {
|
|
80
|
+
const edgesS = Object.values(prop.edges);
|
|
81
|
+
if (edgesS.length) {
|
|
82
|
+
const props = edgesS
|
|
83
|
+
.filter((v) => v.separate === true)
|
|
84
|
+
.sort((a, b) => (a.prop > b.prop ? 1 : -1));
|
|
85
|
+
const p = [
|
|
86
|
+
{
|
|
87
|
+
...EMPTY_MICRO_BUFFER,
|
|
88
|
+
len: prop.edgeMainLen || 1, // allow zero here... else useless padding
|
|
89
|
+
__isEdgeDef: true,
|
|
90
|
+
},
|
|
91
|
+
// or handle this here...
|
|
92
|
+
...props,
|
|
93
|
+
];
|
|
94
|
+
eschema = p
|
|
95
|
+
.map((prop) => propDefBuffer(schema, prop, true))
|
|
96
|
+
.flat(1);
|
|
97
|
+
eschema.unshift(0, 0, 0, 0, sepPropCount(p), 0);
|
|
98
|
+
view.setUint32(5, eschema.length, true);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return [...buf, ...eschema];
|
|
103
|
+
}
|
|
104
|
+
else if (type === STRING ||
|
|
105
|
+
type === BINARY ||
|
|
106
|
+
type === CARDINALITY ||
|
|
107
|
+
type === JSON) {
|
|
108
|
+
return [selvaType, prop.len < 50 ? prop.len : 0];
|
|
109
|
+
}
|
|
110
|
+
{
|
|
111
|
+
return [selvaType];
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
// TODO rewrite
|
|
115
|
+
export function schemaToSelvaBuffer(schema) {
|
|
116
|
+
return Object.values(schema).map((t, i) => {
|
|
117
|
+
const props = Object.values(t.props);
|
|
118
|
+
const rest = [];
|
|
119
|
+
const nrFields = 1 + sepPropCount(props);
|
|
120
|
+
let refFields = 0;
|
|
121
|
+
if (nrFields >= 250) {
|
|
122
|
+
throw new Error('Too many fields');
|
|
123
|
+
}
|
|
124
|
+
for (const f of props) {
|
|
125
|
+
if (f.separate) {
|
|
126
|
+
if (f.typeIndex === REFERENCE || f.typeIndex === REFERENCES) {
|
|
127
|
+
refFields++;
|
|
128
|
+
}
|
|
129
|
+
rest.push(f);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
rest.sort((a, b) => a.prop - b.prop);
|
|
133
|
+
return Uint8Array.from([
|
|
134
|
+
...blockCapacity(t.blockCapacity),
|
|
135
|
+
nrFields,
|
|
136
|
+
1 + refFields,
|
|
137
|
+
...propDefBuffer(schema, {
|
|
138
|
+
...EMPTY_MICRO_BUFFER,
|
|
139
|
+
len: t.mainLen === 0 ? 1 : t.mainLen,
|
|
140
|
+
}),
|
|
141
|
+
...rest.map((f) => propDefBuffer(schema, f)).flat(1),
|
|
142
|
+
]).buffer;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=selvaBuffer.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const timeToNumber = (ex) => {
|
|
2
|
+
if (ex === 's') {
|
|
3
|
+
return 1000;
|
|
4
|
+
}
|
|
5
|
+
if (ex === 'm') {
|
|
6
|
+
return 1000 * 60;
|
|
7
|
+
}
|
|
8
|
+
if (ex === 'h') {
|
|
9
|
+
return 1000 * 60 * 60;
|
|
10
|
+
}
|
|
11
|
+
if (ex === 'd') {
|
|
12
|
+
return 1000 * 60 * 60 * 24;
|
|
13
|
+
}
|
|
14
|
+
if (ex === 'y') {
|
|
15
|
+
return 31556952000;
|
|
16
|
+
}
|
|
17
|
+
return 1;
|
|
18
|
+
};
|
|
19
|
+
export const convertToTimestamp = (value) => {
|
|
20
|
+
if (value instanceof Date) {
|
|
21
|
+
return value.valueOf();
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
if (value === 'now') {
|
|
25
|
+
return Date.now();
|
|
26
|
+
}
|
|
27
|
+
const y = value.replace(/([+-])/g, ' $1 ');
|
|
28
|
+
const arr = y.split(/ +/);
|
|
29
|
+
let newValue = 0;
|
|
30
|
+
let now;
|
|
31
|
+
let op = 1;
|
|
32
|
+
for (const seg of arr) {
|
|
33
|
+
if (seg === '-') {
|
|
34
|
+
op = -1;
|
|
35
|
+
}
|
|
36
|
+
else if (seg === '+') {
|
|
37
|
+
op = 1;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
var v = 0;
|
|
41
|
+
if (seg === 'now') {
|
|
42
|
+
if (!now) {
|
|
43
|
+
now = Date.now();
|
|
44
|
+
}
|
|
45
|
+
v = now;
|
|
46
|
+
}
|
|
47
|
+
else if (/[smhdy]$/.test(seg)) {
|
|
48
|
+
const ex = seg[seg.length - 1];
|
|
49
|
+
const number = parseInt(seg, 10);
|
|
50
|
+
v = number * timeToNumber(ex);
|
|
51
|
+
}
|
|
52
|
+
else if (seg) {
|
|
53
|
+
v = new Date(seg).valueOf();
|
|
54
|
+
}
|
|
55
|
+
if (op === -1) {
|
|
56
|
+
newValue -= v;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
newValue += v;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return newValue;
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=timestamp.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SchemaObject, StrictSchemaType, SchemaLocales } from '../index.js';
|
|
2
|
+
import { SchemaTypeDef, SchemaTypesParsed } from './types.js';
|
|
3
|
+
import { StrictSchema } from '../types.js';
|
|
4
|
+
export declare const updateTypeDefs: (schema: StrictSchema) => {
|
|
5
|
+
schemaTypesParsed: {
|
|
6
|
+
[key: string]: SchemaTypeDef;
|
|
7
|
+
};
|
|
8
|
+
schemaTypesParsedById: {
|
|
9
|
+
[id: number]: SchemaTypeDef;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const createSchemaTypeDef: (typeName: string, type: StrictSchemaType | SchemaObject, parsed: SchemaTypesParsed, locales: Partial<SchemaLocales>, result?: Partial<SchemaTypeDef>, path?: string[], top?: boolean) => SchemaTypeDef;
|
|
13
|
+
//# sourceMappingURL=typeDef.d.ts.map
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { isPropType, getPropType, } from '../index.js';
|
|
2
|
+
import { setByPath } from '@saulx/utils';
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, BLOCK_CAPACITY_MAX, BLOCK_CAPACITY_DEFAULT, BLOCK_CAPACITY_MIN, } from './types.js';
|
|
4
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
5
|
+
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
6
|
+
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
7
|
+
import { getPropLen, isSeparate, parseMinMaxStep } from './utils.js';
|
|
8
|
+
import { addEdges } from './addEdges.js';
|
|
9
|
+
import { createEmptyDef } from './createEmptyDef.js';
|
|
10
|
+
import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
|
|
11
|
+
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
12
|
+
export const updateTypeDefs = (schema) => {
|
|
13
|
+
const schemaTypesParsed = {};
|
|
14
|
+
const schemaTypesParsedById = {};
|
|
15
|
+
for (const typeName in schemaTypesParsed) {
|
|
16
|
+
if (typeName in schema.types) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const id = schemaTypesParsed[typeName].id;
|
|
20
|
+
delete schemaTypesParsed[typeName];
|
|
21
|
+
delete schemaTypesParsedById[id];
|
|
22
|
+
}
|
|
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');
|
|
27
|
+
}
|
|
28
|
+
const def = createSchemaTypeDef(typeName, type, schemaTypesParsed, schema.locales ?? {
|
|
29
|
+
en: {},
|
|
30
|
+
});
|
|
31
|
+
schemaTypesParsed[typeName] = def;
|
|
32
|
+
schemaTypesParsedById[type.id] = def;
|
|
33
|
+
}
|
|
34
|
+
return { schemaTypesParsed, schemaTypesParsedById };
|
|
35
|
+
};
|
|
36
|
+
export const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
|
|
37
|
+
if (top) {
|
|
38
|
+
if (result.id == 0) {
|
|
39
|
+
if ('id' in type) {
|
|
40
|
+
result.id = type.id;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`Invalid schema type id ${result.type}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (result.blockCapacity == 0) {
|
|
47
|
+
if ('blockCapacity' in type) {
|
|
48
|
+
if (typeof type.blockCapacity !== 'number' || type.blockCapacity < BLOCK_CAPACITY_MIN || type.blockCapacity > BLOCK_CAPACITY_MAX) {
|
|
49
|
+
throw new Error('Invalid blockCapacity');
|
|
50
|
+
}
|
|
51
|
+
result.blockCapacity = type.blockCapacity;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
result.blockCapacity = typeName === '_root' ? BLOCK_CAPACITY_MAX : BLOCK_CAPACITY_DEFAULT;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (result.insertOnly == false && 'insertOnly' in type) {
|
|
58
|
+
result.insertOnly = !!type.insertOnly;
|
|
59
|
+
}
|
|
60
|
+
if (result.partial == false && 'partial' in type) {
|
|
61
|
+
result.partial = !!type.partial;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
result.locales = locales;
|
|
65
|
+
result.localeSize = Object.keys(locales).length;
|
|
66
|
+
result.idUint8[0] = result.id & 255;
|
|
67
|
+
result.idUint8[1] = result.id >> 8;
|
|
68
|
+
const target = type.props;
|
|
69
|
+
for (const key in target) {
|
|
70
|
+
// Create prop def
|
|
71
|
+
const schemaProp = target[key];
|
|
72
|
+
const propPath = [...path, key];
|
|
73
|
+
const propType = getPropType(schemaProp);
|
|
74
|
+
if (propType === 'object') {
|
|
75
|
+
createSchemaTypeDef(typeName, schemaProp, parsed, locales, result, propPath, false);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const len = getPropLen(schemaProp);
|
|
79
|
+
if (isPropType('string', schemaProp) ||
|
|
80
|
+
isPropType('alias', schemaProp) ||
|
|
81
|
+
isPropType('cardinality', schemaProp)) {
|
|
82
|
+
if (typeof schemaProp === 'object') {
|
|
83
|
+
if (!(schemaProp.maxBytes < 61) ||
|
|
84
|
+
!('max' in schemaProp && schemaProp.max < 31)) {
|
|
85
|
+
result.separateSortProps++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
result.separateSortProps++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (isPropType('text', schemaProp)) {
|
|
93
|
+
result.separateSortText++;
|
|
94
|
+
}
|
|
95
|
+
else if (isPropType('colvec', schemaProp)) {
|
|
96
|
+
if (!result.insertOnly) {
|
|
97
|
+
throw new Error('colvec requires insertOnly');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const isseparate = isSeparate(schemaProp, len);
|
|
101
|
+
const typeIndex = TYPE_INDEX_MAP[propType];
|
|
102
|
+
const prop = {
|
|
103
|
+
typeIndex,
|
|
104
|
+
__isPropDef: true,
|
|
105
|
+
separate: isseparate,
|
|
106
|
+
path: propPath,
|
|
107
|
+
start: 0,
|
|
108
|
+
validation: schemaProp.validation ??
|
|
109
|
+
VALIDATION_MAP[typeIndex] ??
|
|
110
|
+
defaultValidation,
|
|
111
|
+
len,
|
|
112
|
+
default: schemaProp.default ?? DEFAULT_MAP[typeIndex],
|
|
113
|
+
prop: isseparate ? ++result.cnt : 0,
|
|
114
|
+
};
|
|
115
|
+
if (schemaProp.max !== undefined) {
|
|
116
|
+
prop.max = parseMinMaxStep(schemaProp.max);
|
|
117
|
+
}
|
|
118
|
+
if (schemaProp.min !== undefined) {
|
|
119
|
+
prop.min = parseMinMaxStep(schemaProp.min);
|
|
120
|
+
}
|
|
121
|
+
if (schemaProp.step !== undefined) {
|
|
122
|
+
prop.step = parseMinMaxStep(schemaProp.step);
|
|
123
|
+
}
|
|
124
|
+
if (prop.typeIndex !== NUMBER && prop.step === undefined) {
|
|
125
|
+
prop.step = 1;
|
|
126
|
+
}
|
|
127
|
+
if (isPropType('enum', schemaProp)) {
|
|
128
|
+
prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
|
|
129
|
+
prop.reverseEnum = {};
|
|
130
|
+
for (let i = 0; i < prop.enum.length; i++) {
|
|
131
|
+
prop.reverseEnum[prop.enum[i]] = i;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (isPropType('references', schemaProp)) {
|
|
135
|
+
if (result.partial) {
|
|
136
|
+
throw new Error('references is not supported with partial');
|
|
137
|
+
}
|
|
138
|
+
prop.inversePropName = schemaProp.items.prop;
|
|
139
|
+
prop.inverseTypeName = schemaProp.items.ref;
|
|
140
|
+
prop.dependent = schemaProp.items.dependent;
|
|
141
|
+
addEdges(prop, schemaProp.items);
|
|
142
|
+
}
|
|
143
|
+
else if (isPropType('reference', schemaProp)) {
|
|
144
|
+
if (result.partial) {
|
|
145
|
+
throw new Error('reference is not supported with partial');
|
|
146
|
+
}
|
|
147
|
+
prop.inversePropName = schemaProp.prop;
|
|
148
|
+
prop.inverseTypeName = schemaProp.ref;
|
|
149
|
+
prop.dependent = schemaProp.dependent;
|
|
150
|
+
addEdges(prop, schemaProp);
|
|
151
|
+
}
|
|
152
|
+
else if (typeof schemaProp === 'object') {
|
|
153
|
+
if (isPropType('string', schemaProp) ||
|
|
154
|
+
isPropType('text', schemaProp)) {
|
|
155
|
+
prop.compression =
|
|
156
|
+
'compression' in schemaProp && schemaProp.compression === 'none'
|
|
157
|
+
? 0
|
|
158
|
+
: 1;
|
|
159
|
+
}
|
|
160
|
+
else if (isPropType('timestamp', schemaProp) && 'on' in schemaProp) {
|
|
161
|
+
if (schemaProp.on[0] === 'c') {
|
|
162
|
+
result.createTs ??= [];
|
|
163
|
+
result.createTs.push(prop);
|
|
164
|
+
}
|
|
165
|
+
else if (schemaProp.on[0] === 'u') {
|
|
166
|
+
result.createTs ??= [];
|
|
167
|
+
result.createTs.push(prop);
|
|
168
|
+
result.updateTs ??= [];
|
|
169
|
+
result.updateTs.push(prop);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
result.props[propPath.join('.')] = prop;
|
|
174
|
+
if (isseparate) {
|
|
175
|
+
result.separate.push(prop);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (top) {
|
|
180
|
+
// Put top level together
|
|
181
|
+
const vals = Object.values(result.props);
|
|
182
|
+
vals.sort((a, b) => {
|
|
183
|
+
if (b.separate &&
|
|
184
|
+
(a.typeIndex === REFERENCES || a.typeIndex === REFERENCE)) {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
return a.prop - b.prop;
|
|
188
|
+
});
|
|
189
|
+
let lastProp = 0;
|
|
190
|
+
for (const p of vals) {
|
|
191
|
+
if (p.separate) {
|
|
192
|
+
p.prop = ++lastProp;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
let len = 2;
|
|
196
|
+
for (const f of vals) {
|
|
197
|
+
if (f.separate) {
|
|
198
|
+
len += 2;
|
|
199
|
+
setByPath(result.tree, f.path, f);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
if (!result.mainLen) {
|
|
203
|
+
len += 2;
|
|
204
|
+
}
|
|
205
|
+
len += 1;
|
|
206
|
+
f.start = result.mainLen;
|
|
207
|
+
result.mainLen += f.len;
|
|
208
|
+
setByPath(result.tree, f.path, f);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
result.mainEmpty = fillEmptyMain(vals, result.mainLen);
|
|
212
|
+
result.mainEmptyAllZeroes = isZeroes(result.mainEmpty);
|
|
213
|
+
if (result.separateSortText > 0) {
|
|
214
|
+
makeSeparateTextSort(result);
|
|
215
|
+
}
|
|
216
|
+
if (result.separateSortProps > 0) {
|
|
217
|
+
makeSeparateSort(result);
|
|
218
|
+
}
|
|
219
|
+
for (const p in result.props) {
|
|
220
|
+
const x = result.props[p];
|
|
221
|
+
if (!x.separate) {
|
|
222
|
+
result.main[x.start] = x;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
result.reverseProps[x.prop] = x;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=typeDef.js.map
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { LangCode, SchemaLocales } from '../index.js';
|
|
2
|
+
import { Validation } from './validation.js';
|
|
3
|
+
export declare const NULL = 0;
|
|
4
|
+
export declare const TIMESTAMP = 1;
|
|
5
|
+
export declare const NUMBER = 4;
|
|
6
|
+
export declare const CARDINALITY = 5;
|
|
7
|
+
export declare const INT8 = 20;
|
|
8
|
+
export declare const UINT8 = 6;
|
|
9
|
+
export declare const INT16 = 21;
|
|
10
|
+
export declare const UINT16 = 22;
|
|
11
|
+
export declare const INT32 = 23;
|
|
12
|
+
export declare const UINT32 = 7;
|
|
13
|
+
export declare const BOOLEAN = 9;
|
|
14
|
+
export declare const ENUM = 10;
|
|
15
|
+
export declare const STRING = 11;
|
|
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 OBJECT = 29;
|
|
29
|
+
export declare const COLVEC = 30;
|
|
30
|
+
export declare const TYPE_INDEX_MAP: {
|
|
31
|
+
alias: number;
|
|
32
|
+
aliases: number;
|
|
33
|
+
microbuffer: number;
|
|
34
|
+
references: number;
|
|
35
|
+
reference: number;
|
|
36
|
+
timestamp: number;
|
|
37
|
+
boolean: number;
|
|
38
|
+
number: number;
|
|
39
|
+
string: number;
|
|
40
|
+
text: number;
|
|
41
|
+
uint16: number;
|
|
42
|
+
uint32: number;
|
|
43
|
+
int16: number;
|
|
44
|
+
int32: number;
|
|
45
|
+
uint8: number;
|
|
46
|
+
enum: number;
|
|
47
|
+
int8: number;
|
|
48
|
+
id: number;
|
|
49
|
+
binary: number;
|
|
50
|
+
vector: number;
|
|
51
|
+
cardinality: number;
|
|
52
|
+
json: number;
|
|
53
|
+
object: number;
|
|
54
|
+
colvec: number;
|
|
55
|
+
};
|
|
56
|
+
export declare const enum numberTypes {
|
|
57
|
+
number = 4,
|
|
58
|
+
uint16 = 22,
|
|
59
|
+
uint32 = 7,
|
|
60
|
+
int16 = 21,
|
|
61
|
+
int32 = 23,
|
|
62
|
+
uint8 = 6,
|
|
63
|
+
int8 = 20,
|
|
64
|
+
cardinality = 5
|
|
65
|
+
}
|
|
66
|
+
export declare function isNumberType(type: TypeIndex): boolean;
|
|
67
|
+
export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
|
|
68
|
+
export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
|
|
69
|
+
export type PropDef = {
|
|
70
|
+
__isPropDef: true;
|
|
71
|
+
prop: number;
|
|
72
|
+
typeIndex: TypeIndex;
|
|
73
|
+
separate: boolean;
|
|
74
|
+
path: string[];
|
|
75
|
+
start: number;
|
|
76
|
+
len: number;
|
|
77
|
+
inverseTypeName?: string;
|
|
78
|
+
inversePropName?: string;
|
|
79
|
+
compression?: 0 | 1;
|
|
80
|
+
inverseTypeId?: number;
|
|
81
|
+
inversePropNumber?: number;
|
|
82
|
+
enum?: any[];
|
|
83
|
+
dependent?: boolean;
|
|
84
|
+
validation: Validation;
|
|
85
|
+
default: any;
|
|
86
|
+
edgeMainLen?: 0;
|
|
87
|
+
reverseEnum?: {
|
|
88
|
+
[key: string]: number;
|
|
89
|
+
};
|
|
90
|
+
edgesSeperateCnt?: number;
|
|
91
|
+
edges?: {
|
|
92
|
+
[key: string]: PropDefEdge;
|
|
93
|
+
};
|
|
94
|
+
reverseSeperateEdges?: {
|
|
95
|
+
[prop: string]: PropDefEdge;
|
|
96
|
+
};
|
|
97
|
+
reverseMainEdges?: {
|
|
98
|
+
[start: string]: PropDefEdge;
|
|
99
|
+
};
|
|
100
|
+
edgeMainEmpty?: Uint8Array;
|
|
101
|
+
__isEdge?: boolean;
|
|
102
|
+
max?: any;
|
|
103
|
+
min?: any;
|
|
104
|
+
step?: any;
|
|
105
|
+
};
|
|
106
|
+
export type PropDefEdge = Partial<PropDef> & {
|
|
107
|
+
__isPropDef: true;
|
|
108
|
+
typeIndex: TypeIndex;
|
|
109
|
+
len: number;
|
|
110
|
+
prop: number;
|
|
111
|
+
name: string;
|
|
112
|
+
edgesTotalLen?: number;
|
|
113
|
+
__isEdge: true;
|
|
114
|
+
};
|
|
115
|
+
export type PropDefAggregate = Partial<PropDef> & {
|
|
116
|
+
__isPropDef: true;
|
|
117
|
+
typeIndex: TypeIndex;
|
|
118
|
+
len: number;
|
|
119
|
+
prop: number;
|
|
120
|
+
name: string;
|
|
121
|
+
};
|
|
122
|
+
export type SchemaPropTree = {
|
|
123
|
+
[key: string]: SchemaPropTree | PropDef;
|
|
124
|
+
};
|
|
125
|
+
export type SchemaSortUndefinedHandler = {
|
|
126
|
+
size: number;
|
|
127
|
+
buffer: Uint8Array;
|
|
128
|
+
bufferTmp: Uint8Array;
|
|
129
|
+
props: PropDef[];
|
|
130
|
+
};
|
|
131
|
+
export declare const BLOCK_CAPACITY_MIN = 1025;
|
|
132
|
+
export declare const BLOCK_CAPACITY_MAX = 2147483647;
|
|
133
|
+
export declare const BLOCK_CAPACITY_DEFAULT = 100000;
|
|
134
|
+
export type SchemaTypeDef = {
|
|
135
|
+
cnt: number;
|
|
136
|
+
checksum: number;
|
|
137
|
+
type: string;
|
|
138
|
+
lastId: number;
|
|
139
|
+
blockCapacity: number;
|
|
140
|
+
mainLen: number;
|
|
141
|
+
insertOnly: boolean;
|
|
142
|
+
partial: boolean;
|
|
143
|
+
buf: Uint8Array;
|
|
144
|
+
propNames: Uint8Array;
|
|
145
|
+
props: {
|
|
146
|
+
[path: string]: PropDef;
|
|
147
|
+
};
|
|
148
|
+
reverseProps: {
|
|
149
|
+
[field: string]: PropDef;
|
|
150
|
+
};
|
|
151
|
+
id: number;
|
|
152
|
+
idUint8: Uint8Array;
|
|
153
|
+
separate: PropDef[];
|
|
154
|
+
main: {
|
|
155
|
+
[start: string]: PropDef;
|
|
156
|
+
};
|
|
157
|
+
mainEmpty: Uint8Array;
|
|
158
|
+
mainEmptyAllZeroes: boolean;
|
|
159
|
+
tree: SchemaPropTree;
|
|
160
|
+
separateSortProps: number;
|
|
161
|
+
separateSortText: number;
|
|
162
|
+
hasSeperateSort: boolean;
|
|
163
|
+
seperateSort: SchemaSortUndefinedHandler;
|
|
164
|
+
hasSeperateTextSort: boolean;
|
|
165
|
+
seperateTextSort: SchemaSortUndefinedHandler & {
|
|
166
|
+
noUndefined: Uint8Array;
|
|
167
|
+
localeStringToIndex: Map<string, Uint8Array>;
|
|
168
|
+
localeToIndex: Map<LangCode, number>;
|
|
169
|
+
};
|
|
170
|
+
createTs?: PropDef[];
|
|
171
|
+
updateTs?: PropDef[];
|
|
172
|
+
locales: Partial<SchemaLocales>;
|
|
173
|
+
localeSize: number;
|
|
174
|
+
};
|
|
175
|
+
export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
|
|
176
|
+
export declare const REVERSE_SIZE_MAP: Record<TypeIndex, number>;
|
|
177
|
+
export declare const REVERSE_TYPE_INDEX_MAP: Record<TypeIndex, InternalSchemaProp>;
|
|
178
|
+
export declare const ID_FIELD_DEF: PropDef;
|
|
179
|
+
export declare const EMPTY_MICRO_BUFFER: PropDef;
|
|
180
|
+
export declare const getPropTypeName: (propType: TypeIndex) => InternalSchemaProp;
|
|
181
|
+
export declare const isPropDef: (prop: any) => prop is PropDef;
|
|
182
|
+
export type SchemaTypesParsed = {
|
|
183
|
+
[key: string]: SchemaTypeDef;
|
|
184
|
+
};
|
|
185
|
+
export type SchemaTypesParsedById = Record<number, SchemaTypeDef>;
|
|
186
|
+
//# sourceMappingURL=types.d.ts.map
|