@based/schema 5.0.0-alpha.5 → 5.0.0-alpha.6
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 +51 -0
- package/dist/def/createEmptyDef.d.ts +37 -0
- package/dist/def/createEmptyDef.js +39 -0
- package/dist/def/getPropLen.d.ts +3 -0
- package/dist/def/getPropLen.js +23 -0
- package/dist/def/index.d.ts +1 -0
- package/dist/def/index.js +1 -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.js +9 -2
- package/dist/def/selvaBuffer.d.ts +1 -1
- package/dist/def/selvaBuffer.js +18 -19
- package/dist/def/typeDef.js +11 -197
- package/dist/def/types.d.ts +6 -2
- package/dist/def/utils.d.ts +3 -0
- package/dist/def/utils.js +25 -1
- package/dist/lang.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getPropType } from '../index.js';
|
|
2
|
+
import { SIZE_MAP, TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, } from './types.js';
|
|
3
|
+
export const addEdges = (prop, refProp) => {
|
|
4
|
+
let edgesCnt = 0;
|
|
5
|
+
for (const key in refProp) {
|
|
6
|
+
if (key[0] === '$') {
|
|
7
|
+
if (!prop.edges) {
|
|
8
|
+
prop.edges = {};
|
|
9
|
+
prop.reverseEdges = {};
|
|
10
|
+
prop.edgesTotalLen = 0;
|
|
11
|
+
}
|
|
12
|
+
edgesCnt++;
|
|
13
|
+
const edgeType = getPropType(refProp[key]);
|
|
14
|
+
const edge = {
|
|
15
|
+
__isPropDef: true,
|
|
16
|
+
__isEdge: true,
|
|
17
|
+
prop: edgesCnt,
|
|
18
|
+
name: key,
|
|
19
|
+
typeIndex: TYPE_INDEX_MAP[edgeType],
|
|
20
|
+
len: SIZE_MAP[edgeType],
|
|
21
|
+
separate: true,
|
|
22
|
+
path: [...prop.path, key],
|
|
23
|
+
};
|
|
24
|
+
if (edge.len == 0) {
|
|
25
|
+
prop.edgesTotalLen = 0;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// [field] [size] [data]
|
|
29
|
+
prop.edgesTotalLen += 1 + 2 + edge.len; // field len
|
|
30
|
+
}
|
|
31
|
+
if (edge.typeIndex === ENUM) {
|
|
32
|
+
edge.enum = Array.isArray(refProp[key])
|
|
33
|
+
? refProp[key]
|
|
34
|
+
: refProp[key].enum;
|
|
35
|
+
edge.reverseEnum = {};
|
|
36
|
+
for (let i = 0; i < edge.enum.length; i++) {
|
|
37
|
+
edge.reverseEnum[edge.enum[i]] = i;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (edge.typeIndex === REFERENCES) {
|
|
41
|
+
edge.inverseTypeName = refProp[key].items.ref;
|
|
42
|
+
}
|
|
43
|
+
else if (edge.typeIndex === REFERENCE) {
|
|
44
|
+
edge.inverseTypeName = refProp[key].ref;
|
|
45
|
+
}
|
|
46
|
+
prop.edges[key] = edge;
|
|
47
|
+
prop.reverseEdges[edge.prop] = edge;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=addEdges.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SchemaLocales, SchemaObject, StrictSchemaType } from '../types.js';
|
|
2
|
+
export declare const createEmptyDef: (typeName: string, type: StrictSchemaType | SchemaObject, locales: Partial<SchemaLocales>) => {
|
|
3
|
+
cnt: number;
|
|
4
|
+
blockCapacity: number;
|
|
5
|
+
checksum: number;
|
|
6
|
+
type: string;
|
|
7
|
+
props: {};
|
|
8
|
+
reverseProps: {};
|
|
9
|
+
idUint8: Uint8Array;
|
|
10
|
+
id: number;
|
|
11
|
+
mainLen: number;
|
|
12
|
+
separate: any[];
|
|
13
|
+
tree: {};
|
|
14
|
+
total: number;
|
|
15
|
+
lastId: number;
|
|
16
|
+
locales: {};
|
|
17
|
+
main: {};
|
|
18
|
+
localeSize: number;
|
|
19
|
+
hasSeperateSort: boolean;
|
|
20
|
+
seperateSort: {
|
|
21
|
+
size: number;
|
|
22
|
+
props: any[];
|
|
23
|
+
buffer: Uint8Array;
|
|
24
|
+
bufferTmp: Uint8Array;
|
|
25
|
+
};
|
|
26
|
+
hasSeperateTextSort: boolean;
|
|
27
|
+
seperateTextSort: {
|
|
28
|
+
size: number;
|
|
29
|
+
props: any[];
|
|
30
|
+
buffer: Uint8Array;
|
|
31
|
+
noUndefined: Uint8Array;
|
|
32
|
+
bufferTmp: Uint8Array;
|
|
33
|
+
localeStringToIndex: Map<any, any>;
|
|
34
|
+
localeToIndex: Map<any, any>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=createEmptyDef.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
2
|
+
export const createEmptyDef = (typeName, type, locales) => {
|
|
3
|
+
return {
|
|
4
|
+
cnt: 0,
|
|
5
|
+
blockCapacity: 0,
|
|
6
|
+
checksum: hashObjectIgnoreKeyOrder(type),
|
|
7
|
+
type: typeName,
|
|
8
|
+
props: {},
|
|
9
|
+
reverseProps: {},
|
|
10
|
+
idUint8: new Uint8Array([0, 0]),
|
|
11
|
+
id: 0,
|
|
12
|
+
mainLen: 0,
|
|
13
|
+
separate: [],
|
|
14
|
+
tree: {},
|
|
15
|
+
total: 0,
|
|
16
|
+
lastId: 0,
|
|
17
|
+
locales: {},
|
|
18
|
+
main: {},
|
|
19
|
+
localeSize: 0,
|
|
20
|
+
hasSeperateSort: false,
|
|
21
|
+
seperateSort: {
|
|
22
|
+
size: 0,
|
|
23
|
+
props: [],
|
|
24
|
+
buffer: new Uint8Array([]),
|
|
25
|
+
bufferTmp: new Uint8Array([]),
|
|
26
|
+
},
|
|
27
|
+
hasSeperateTextSort: false,
|
|
28
|
+
seperateTextSort: {
|
|
29
|
+
size: 0, // prop len
|
|
30
|
+
props: [],
|
|
31
|
+
buffer: new Uint8Array([]),
|
|
32
|
+
noUndefined: new Uint8Array(new Array(Object.keys(locales).length).fill(0)),
|
|
33
|
+
bufferTmp: new Uint8Array([]),
|
|
34
|
+
localeStringToIndex: new Map(),
|
|
35
|
+
localeToIndex: new Map(),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=createEmptyDef.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getPropType } from '../parse/utils.js';
|
|
2
|
+
import { isPropType } from '../types.js';
|
|
3
|
+
import { SIZE_MAP } from './types.js';
|
|
4
|
+
export function getPropLen(schemaProp) {
|
|
5
|
+
let len = SIZE_MAP[getPropType(schemaProp)];
|
|
6
|
+
if (isPropType('string', schemaProp) ||
|
|
7
|
+
isPropType('alias', schemaProp) ||
|
|
8
|
+
isPropType('cardinality', schemaProp)) {
|
|
9
|
+
if (typeof schemaProp === 'object') {
|
|
10
|
+
if (schemaProp.maxBytes < 61) {
|
|
11
|
+
len = schemaProp.maxBytes + 1;
|
|
12
|
+
}
|
|
13
|
+
else if ('max' in schemaProp && schemaProp.max < 31) {
|
|
14
|
+
len = schemaProp.max * 2 + 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (isPropType('vector', schemaProp)) {
|
|
19
|
+
len = 4 * schemaProp.size;
|
|
20
|
+
}
|
|
21
|
+
return len;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=getPropLen.js.map
|
package/dist/def/index.d.ts
CHANGED
package/dist/def/index.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function makePacked(result, typeName, vals, len) {
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
result.buf = new Uint8Array(len);
|
|
4
|
+
result.buf[0] = result.idUint8[0];
|
|
5
|
+
result.buf[1] = result.idUint8[1];
|
|
6
|
+
const fieldNames = [];
|
|
7
|
+
const tNameBuf = encoder.encode(typeName);
|
|
8
|
+
fieldNames.push(tNameBuf);
|
|
9
|
+
let fieldNameLen = tNameBuf.byteLength + 1;
|
|
10
|
+
let i = 2;
|
|
11
|
+
if (result.mainLen) {
|
|
12
|
+
result.buf[i] = 0;
|
|
13
|
+
for (const f of vals) {
|
|
14
|
+
if (!f.separate) {
|
|
15
|
+
i++;
|
|
16
|
+
result.buf[i] = f.typeIndex;
|
|
17
|
+
const name = encoder.encode(f.path.join('.'));
|
|
18
|
+
fieldNames.push(name);
|
|
19
|
+
fieldNameLen += name.byteLength + 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
i++;
|
|
23
|
+
result.buf[i] = 0;
|
|
24
|
+
}
|
|
25
|
+
for (const f of vals) {
|
|
26
|
+
if (f.separate) {
|
|
27
|
+
i++;
|
|
28
|
+
result.buf[i] = f.prop;
|
|
29
|
+
i++;
|
|
30
|
+
result.buf[i] = f.typeIndex;
|
|
31
|
+
const name = encoder.encode(f.path.join('.'));
|
|
32
|
+
fieldNames.push(name);
|
|
33
|
+
fieldNameLen += name.byteLength + 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
result.propNames = new Uint8Array(fieldNameLen);
|
|
37
|
+
let lastWritten = 0;
|
|
38
|
+
for (const f of fieldNames) {
|
|
39
|
+
result.propNames[lastWritten] = f.byteLength;
|
|
40
|
+
result.propNames.set(f, lastWritten + 1);
|
|
41
|
+
lastWritten += f.byteLength + 1;
|
|
42
|
+
}
|
|
43
|
+
let bufLen = result.buf.length;
|
|
44
|
+
result.packed = new Uint8Array(2 + bufLen + result.propNames.length);
|
|
45
|
+
result.packed[0] = bufLen;
|
|
46
|
+
result.packed[1] = bufLen >>>= 8;
|
|
47
|
+
result.packed.set(result.buf, 2);
|
|
48
|
+
result.packed.set(result.propNames, result.buf.length + 2);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=makePacked.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { STRING, ALIAS, CARDINALITY } from './types.js';
|
|
2
|
+
export function makeSeparateSort(result) {
|
|
3
|
+
result.hasSeperateSort = true;
|
|
4
|
+
let max = 0;
|
|
5
|
+
for (const f of result.separate) {
|
|
6
|
+
if (f.typeIndex === STRING ||
|
|
7
|
+
f.typeIndex === ALIAS ||
|
|
8
|
+
f.typeIndex === CARDINALITY) {
|
|
9
|
+
if (f.prop > max) {
|
|
10
|
+
max = f.prop;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
result.seperateSort.buffer = new Uint8Array(max + 1);
|
|
15
|
+
for (const f of result.separate) {
|
|
16
|
+
if (f.typeIndex === STRING ||
|
|
17
|
+
f.typeIndex === ALIAS ||
|
|
18
|
+
f.typeIndex === CARDINALITY) {
|
|
19
|
+
result.seperateSort.buffer[f.prop] = 1;
|
|
20
|
+
result.seperateSort.props.push(f);
|
|
21
|
+
result.seperateSort.size++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
result.seperateSort.bufferTmp = new Uint8Array(max + 1);
|
|
25
|
+
result.seperateSort.buffer.set(result.seperateSort.bufferTmp);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=makeSeparateSort.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { langCodesMap } from '../lang.js';
|
|
2
|
+
import { TEXT } from './types.js';
|
|
3
|
+
export function makeSeparateTextSort(result) {
|
|
4
|
+
result.hasSeperateTextSort = true;
|
|
5
|
+
let max = 0;
|
|
6
|
+
for (const f of result.separate) {
|
|
7
|
+
if (f.typeIndex === TEXT) {
|
|
8
|
+
if (f.prop > max) {
|
|
9
|
+
max = f.prop;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const bufLen = (max + 1) * (result.localeSize + 1);
|
|
14
|
+
result.seperateTextSort.buffer = new Uint8Array(bufLen);
|
|
15
|
+
let index = 0;
|
|
16
|
+
for (const code in result.locales) {
|
|
17
|
+
const codeLang = langCodesMap.get(code);
|
|
18
|
+
result.seperateTextSort.localeStringToIndex.set(code, new Uint8Array([index + 1, codeLang]));
|
|
19
|
+
result.seperateTextSort.localeToIndex.set(codeLang, index + 1);
|
|
20
|
+
index++;
|
|
21
|
+
}
|
|
22
|
+
for (const f of result.separate) {
|
|
23
|
+
if (f.typeIndex === TEXT) {
|
|
24
|
+
const index = f.prop * (result.localeSize + 1);
|
|
25
|
+
result.seperateTextSort.buffer[index] = result.localeSize;
|
|
26
|
+
for (const [, locales] of result.seperateTextSort.localeStringToIndex) {
|
|
27
|
+
result.seperateTextSort.buffer[locales[0] + index] = locales[1];
|
|
28
|
+
}
|
|
29
|
+
result.seperateTextSort.props.push(f);
|
|
30
|
+
result.seperateTextSort.size += result.localeSize;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
result.seperateTextSort.props.sort((a, b) => (a.prop > b.prop ? 1 : -1));
|
|
34
|
+
result.seperateTextSort.bufferTmp = new Uint8Array(bufLen);
|
|
35
|
+
result.seperateTextSort.bufferTmp.fill(0);
|
|
36
|
+
result.seperateTextSort.bufferTmp.set(result.seperateTextSort.buffer);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=makeSeparateTextSort.js.map
|
|
@@ -78,6 +78,9 @@ export const readFromPacked = (packed) => {
|
|
|
78
78
|
},
|
|
79
79
|
hasSeperateTextSort: false,
|
|
80
80
|
seperateTextSort: {
|
|
81
|
+
localeToIndex: new Map(),
|
|
82
|
+
localeStringToIndex: new Map(),
|
|
83
|
+
noUndefined: new Uint8Array([]),
|
|
81
84
|
size: 0,
|
|
82
85
|
buffer: new Uint8Array([]),
|
|
83
86
|
bufferTmp: new Uint8Array([]),
|
|
@@ -90,7 +93,7 @@ export const readFromPacked = (packed) => {
|
|
|
90
93
|
let s = 0;
|
|
91
94
|
for (const p of mainProps) {
|
|
92
95
|
const len = REVERSE_SIZE_MAP[p.typeIndex];
|
|
93
|
-
|
|
96
|
+
const prop = {
|
|
94
97
|
prop: p.prop,
|
|
95
98
|
separate: false,
|
|
96
99
|
__isPropDef: true,
|
|
@@ -99,10 +102,12 @@ export const readFromPacked = (packed) => {
|
|
|
99
102
|
path: p.path.split('.'),
|
|
100
103
|
len,
|
|
101
104
|
};
|
|
105
|
+
result.props[p.path] = prop;
|
|
106
|
+
result.main[prop.start] = prop;
|
|
102
107
|
s += len;
|
|
103
108
|
}
|
|
104
109
|
for (const p of props) {
|
|
105
|
-
|
|
110
|
+
const prop = {
|
|
106
111
|
prop: p.prop,
|
|
107
112
|
separate: true,
|
|
108
113
|
__isPropDef: true,
|
|
@@ -112,6 +117,8 @@ export const readFromPacked = (packed) => {
|
|
|
112
117
|
len: 0,
|
|
113
118
|
compression: 1,
|
|
114
119
|
};
|
|
120
|
+
result.props[p.path] = prop;
|
|
121
|
+
result.reverseProps[prop.prop] = prop;
|
|
115
122
|
}
|
|
116
123
|
// make this into a typeDef
|
|
117
124
|
// return {
|
package/dist/def/selvaBuffer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ALIAS, ALIASES, BINARY, BOOLEAN, CREATED, EMPTY_MICRO_BUFFER, ENUM, CARDINALITY, INT16, INT32, INT8, MICRO_BUFFER, NULL, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, UPDATED, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, } from './types.js';
|
|
2
|
-
const selvaTypeMap =
|
|
2
|
+
const selvaTypeMap = new Uint8Array(32); // 1.2x faster than JS array
|
|
3
3
|
selvaTypeMap[NULL] = 0;
|
|
4
4
|
selvaTypeMap[TIMESTAMP] = 4;
|
|
5
5
|
selvaTypeMap[CREATED] = 1;
|
|
@@ -28,8 +28,9 @@ selvaTypeMap[VECTOR] = 17;
|
|
|
28
28
|
selvaTypeMap[JSON] = 11;
|
|
29
29
|
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
30
30
|
function blockCapacity(blockCapacity) {
|
|
31
|
-
const buf =
|
|
32
|
-
buf.
|
|
31
|
+
const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
|
|
32
|
+
const view = new DataView(buf.buffer);
|
|
33
|
+
view.setUint32(0, blockCapacity, true);
|
|
33
34
|
return buf;
|
|
34
35
|
}
|
|
35
36
|
function sepPropCount(props) {
|
|
@@ -42,20 +43,22 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
42
43
|
const type = prop.typeIndex;
|
|
43
44
|
const selvaType = selvaTypeMap[type];
|
|
44
45
|
if (prop.len && (type === MICRO_BUFFER || type === VECTOR)) {
|
|
45
|
-
const buf =
|
|
46
|
+
const buf = new Uint8Array(3);
|
|
47
|
+
const view = new DataView(buf.buffer);
|
|
46
48
|
buf[0] = selvaType;
|
|
47
|
-
|
|
48
|
-
return [...buf
|
|
49
|
+
view.setUint16(1, prop.len, true);
|
|
50
|
+
return [...buf];
|
|
49
51
|
}
|
|
50
52
|
else if (type === REFERENCE || type === REFERENCES) {
|
|
51
|
-
const buf =
|
|
53
|
+
const buf = new Uint8Array(9);
|
|
54
|
+
const view = new DataView(buf.buffer);
|
|
52
55
|
const dstType = schema[prop.inverseTypeName];
|
|
53
56
|
let eschema = [];
|
|
54
57
|
// @ts-ignore
|
|
55
58
|
buf[0] = selvaType + 2 * !!isEdge; // field type
|
|
56
59
|
buf[1] = makeEdgeConstraintFlags(prop); // flags
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
view.setUint16(2, dstType.id, true); // dst_node_type
|
|
61
|
+
view.setUint32(5, 0, true); // schema_len
|
|
59
62
|
if (!isEdge) {
|
|
60
63
|
prop.inverseTypeId = dstType.id;
|
|
61
64
|
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
@@ -66,10 +69,10 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
66
69
|
.map((prop) => propDefBuffer(schema, prop, true))
|
|
67
70
|
.flat(1);
|
|
68
71
|
eschema.unshift(0, 0, 0, 0, sepPropCount(props), 0);
|
|
69
|
-
|
|
72
|
+
view.setUint32(5, eschema.length, true);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
|
-
return [...buf
|
|
75
|
+
return [...buf, ...eschema];
|
|
73
76
|
}
|
|
74
77
|
else if (type === STRING ||
|
|
75
78
|
type === BINARY ||
|
|
@@ -81,12 +84,8 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
81
84
|
return [selvaType];
|
|
82
85
|
}
|
|
83
86
|
};
|
|
84
|
-
//
|
|
87
|
+
// TODO rewrite
|
|
85
88
|
export function schemaToSelvaBuffer(schema) {
|
|
86
|
-
if (typeof Buffer === 'undefined') {
|
|
87
|
-
// TMP
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
89
|
return Object.values(schema).map((t, i) => {
|
|
91
90
|
const props = Object.values(t.props);
|
|
92
91
|
const rest = [];
|
|
@@ -100,8 +99,8 @@ export function schemaToSelvaBuffer(schema) {
|
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
rest.sort((a, b) => a.prop - b.prop);
|
|
103
|
-
return
|
|
104
|
-
...blockCapacity(t.blockCapacity)
|
|
102
|
+
return Uint8Array.from([
|
|
103
|
+
...blockCapacity(t.blockCapacity),
|
|
105
104
|
1 + sepPropCount(props),
|
|
106
105
|
1 + refFields,
|
|
107
106
|
...propDefBuffer(schema, {
|
|
@@ -109,7 +108,7 @@ export function schemaToSelvaBuffer(schema) {
|
|
|
109
108
|
len: t.mainLen === 0 ? 1 : t.mainLen,
|
|
110
109
|
}),
|
|
111
110
|
...rest.map((f) => propDefBuffer(schema, f)).flat(1),
|
|
112
|
-
]);
|
|
111
|
+
]).buffer;
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
114
|
//# sourceMappingURL=selvaBuffer.js.map
|
package/dist/def/typeDef.js
CHANGED
|
@@ -1,174 +1,15 @@
|
|
|
1
1
|
import { isPropType, getPropType, } from '../index.js';
|
|
2
2
|
import { setByPath } from '@saulx/utils';
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, } from './types.js';
|
|
4
|
+
import { makePacked } from './makePacked.js';
|
|
5
|
+
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
6
|
+
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
7
|
+
import { getPropLen } from './getPropLen.js';
|
|
8
|
+
import { isSeparate } from './utils.js';
|
|
9
|
+
import { addEdges } from './addEdges.js';
|
|
10
|
+
import { createEmptyDef } from './createEmptyDef.js';
|
|
3
11
|
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
4
|
-
import { SIZE_MAP, TYPE_INDEX_MAP, STRING, ALIAS, CARDINALITY, REFERENCES, REFERENCE, TEXT, ENUM, } from './types.js';
|
|
5
|
-
// TMP
|
|
6
12
|
export const DEFAULT_BLOCK_CAPACITY = 100_000;
|
|
7
|
-
function getPropLen(schemaProp) {
|
|
8
|
-
let len = SIZE_MAP[getPropType(schemaProp)];
|
|
9
|
-
if (isPropType('string', schemaProp) ||
|
|
10
|
-
isPropType('alias', schemaProp) ||
|
|
11
|
-
isPropType('cardinality', schemaProp)) {
|
|
12
|
-
if (typeof schemaProp === 'object') {
|
|
13
|
-
if (schemaProp.maxBytes < 61) {
|
|
14
|
-
len = schemaProp.maxBytes + 1;
|
|
15
|
-
}
|
|
16
|
-
else if ('max' in schemaProp && schemaProp.max < 31) {
|
|
17
|
-
len = schemaProp.max * 2 + 1;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else if (isPropType('vector', schemaProp)) {
|
|
22
|
-
len = 4 * schemaProp.size;
|
|
23
|
-
}
|
|
24
|
-
return len;
|
|
25
|
-
}
|
|
26
|
-
function isSeparate(schemaProp, len) {
|
|
27
|
-
return len === 0 || isPropType('vector', schemaProp);
|
|
28
|
-
}
|
|
29
|
-
const addEdges = (prop, refProp) => {
|
|
30
|
-
let edgesCnt = 0;
|
|
31
|
-
for (const key in refProp) {
|
|
32
|
-
if (key[0] === '$') {
|
|
33
|
-
if (!prop.edges) {
|
|
34
|
-
prop.edges = {};
|
|
35
|
-
prop.reverseEdges = {};
|
|
36
|
-
prop.edgesTotalLen = 0;
|
|
37
|
-
}
|
|
38
|
-
edgesCnt++;
|
|
39
|
-
const edgeType = getPropType(refProp[key]);
|
|
40
|
-
const edge = {
|
|
41
|
-
__isPropDef: true,
|
|
42
|
-
__isEdge: true,
|
|
43
|
-
prop: edgesCnt,
|
|
44
|
-
name: key,
|
|
45
|
-
typeIndex: TYPE_INDEX_MAP[edgeType],
|
|
46
|
-
len: SIZE_MAP[edgeType],
|
|
47
|
-
separate: true,
|
|
48
|
-
path: [...prop.path, key],
|
|
49
|
-
};
|
|
50
|
-
if (edge.len == 0) {
|
|
51
|
-
prop.edgesTotalLen = 0;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// [field] [size] [data]
|
|
55
|
-
prop.edgesTotalLen += 1 + 2 + edge.len; // field len
|
|
56
|
-
}
|
|
57
|
-
if (edge.typeIndex === ENUM) {
|
|
58
|
-
edge.enum = Array.isArray(refProp[key])
|
|
59
|
-
? refProp[key]
|
|
60
|
-
: refProp[key].enum;
|
|
61
|
-
edge.reverseEnum = {};
|
|
62
|
-
for (let i = 0; i < edge.enum.length; i++) {
|
|
63
|
-
edge.reverseEnum[edge.enum[i]] = i;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (edge.typeIndex === REFERENCES) {
|
|
67
|
-
edge.inverseTypeName = refProp[key].items.ref;
|
|
68
|
-
}
|
|
69
|
-
else if (edge.typeIndex === REFERENCE) {
|
|
70
|
-
edge.inverseTypeName = refProp[key].ref;
|
|
71
|
-
}
|
|
72
|
-
prop.edges[key] = edge;
|
|
73
|
-
prop.reverseEdges[edge.prop] = edge;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
function makePacked(result, typeName, vals, len) {
|
|
78
|
-
const encoder = new TextEncoder();
|
|
79
|
-
result.buf = new Uint8Array(len);
|
|
80
|
-
result.buf[0] = result.idUint8[0];
|
|
81
|
-
result.buf[1] = result.idUint8[1];
|
|
82
|
-
const fieldNames = [];
|
|
83
|
-
const tNameBuf = encoder.encode(typeName);
|
|
84
|
-
fieldNames.push(tNameBuf);
|
|
85
|
-
let fieldNameLen = tNameBuf.byteLength + 1;
|
|
86
|
-
let i = 2;
|
|
87
|
-
if (result.mainLen) {
|
|
88
|
-
result.buf[i] = 0;
|
|
89
|
-
for (const f of vals) {
|
|
90
|
-
if (!f.separate) {
|
|
91
|
-
i++;
|
|
92
|
-
result.buf[i] = f.typeIndex;
|
|
93
|
-
const name = encoder.encode(f.path.join('.'));
|
|
94
|
-
fieldNames.push(name);
|
|
95
|
-
fieldNameLen += name.byteLength + 1;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
i++;
|
|
99
|
-
result.buf[i] = 0;
|
|
100
|
-
}
|
|
101
|
-
for (const f of vals) {
|
|
102
|
-
if (f.separate) {
|
|
103
|
-
i++;
|
|
104
|
-
result.buf[i] = f.prop;
|
|
105
|
-
i++;
|
|
106
|
-
result.buf[i] = f.typeIndex;
|
|
107
|
-
const name = encoder.encode(f.path.join('.'));
|
|
108
|
-
fieldNames.push(name);
|
|
109
|
-
fieldNameLen += name.byteLength + 1;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
result.propNames = new Uint8Array(fieldNameLen);
|
|
113
|
-
let lastWritten = 0;
|
|
114
|
-
for (const f of fieldNames) {
|
|
115
|
-
result.propNames[lastWritten] = f.byteLength;
|
|
116
|
-
result.propNames.set(f, lastWritten + 1);
|
|
117
|
-
lastWritten += f.byteLength + 1;
|
|
118
|
-
}
|
|
119
|
-
let bufLen = result.buf.length;
|
|
120
|
-
result.packed = new Uint8Array(2 + bufLen + result.propNames.length);
|
|
121
|
-
result.packed[0] = bufLen;
|
|
122
|
-
result.packed[1] = bufLen >>>= 8;
|
|
123
|
-
result.packed.set(result.buf, 2);
|
|
124
|
-
result.packed.set(result.propNames, result.buf.length + 2);
|
|
125
|
-
}
|
|
126
|
-
function makeSeparateTextSort(result) {
|
|
127
|
-
result.hasSeperateTextSort = true;
|
|
128
|
-
let max = 0;
|
|
129
|
-
for (const f of result.separate) {
|
|
130
|
-
if (f.typeIndex === TEXT) {
|
|
131
|
-
if (f.prop > max) {
|
|
132
|
-
max = f.prop;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
result.seperateTextSort.buffer = new Uint8Array(max * result.localeSize + 1);
|
|
137
|
-
for (const f of result.separate) {
|
|
138
|
-
if (f.typeIndex === TEXT) {
|
|
139
|
-
result.seperateTextSort.buffer[f.prop] = 1;
|
|
140
|
-
result.seperateTextSort.props.push(f);
|
|
141
|
-
result.seperateTextSort.size += result.localeSize;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
result.seperateTextSort.bufferTmp = new Uint8Array(max * result.localeSize + 1);
|
|
145
|
-
result.seperateTextSort.buffer.set(result.seperateTextSort.bufferTmp);
|
|
146
|
-
}
|
|
147
|
-
function makeSeparateSort(result) {
|
|
148
|
-
result.hasSeperateSort = true;
|
|
149
|
-
let max = 0;
|
|
150
|
-
for (const f of result.separate) {
|
|
151
|
-
if (f.typeIndex === STRING ||
|
|
152
|
-
f.typeIndex === ALIAS ||
|
|
153
|
-
f.typeIndex === CARDINALITY) {
|
|
154
|
-
if (f.prop > max) {
|
|
155
|
-
max = f.prop;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
result.seperateSort.buffer = new Uint8Array(max + 1);
|
|
160
|
-
for (const f of result.separate) {
|
|
161
|
-
if (f.typeIndex === STRING ||
|
|
162
|
-
f.typeIndex === ALIAS ||
|
|
163
|
-
f.typeIndex === CARDINALITY) {
|
|
164
|
-
result.seperateSort.buffer[f.prop] = 1;
|
|
165
|
-
result.seperateSort.props.push(f);
|
|
166
|
-
result.seperateSort.size++;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
result.seperateSort.bufferTmp = new Uint8Array(max + 1);
|
|
170
|
-
result.seperateSort.buffer.set(result.seperateSort.bufferTmp);
|
|
171
|
-
}
|
|
172
13
|
export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById) => {
|
|
173
14
|
for (const field in schemaTypesParsed) {
|
|
174
15
|
if (field in schema.types) {
|
|
@@ -199,35 +40,7 @@ export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById)
|
|
|
199
40
|
}
|
|
200
41
|
}
|
|
201
42
|
};
|
|
202
|
-
export const createSchemaTypeDef = (typeName, type, parsed, locales, result = {
|
|
203
|
-
cnt: 0,
|
|
204
|
-
checksum: hashObjectIgnoreKeyOrder(type),
|
|
205
|
-
type: typeName,
|
|
206
|
-
props: {},
|
|
207
|
-
reverseProps: {},
|
|
208
|
-
idUint8: new Uint8Array([0, 0]),
|
|
209
|
-
id: 0,
|
|
210
|
-
mainLen: 0,
|
|
211
|
-
separate: [],
|
|
212
|
-
tree: {},
|
|
213
|
-
total: 0,
|
|
214
|
-
lastId: 0,
|
|
215
|
-
main: {},
|
|
216
|
-
hasSeperateSort: false,
|
|
217
|
-
seperateSort: {
|
|
218
|
-
size: 0,
|
|
219
|
-
props: [],
|
|
220
|
-
buffer: new Uint8Array([]),
|
|
221
|
-
bufferTmp: new Uint8Array([]),
|
|
222
|
-
},
|
|
223
|
-
hasSeperateTextSort: false,
|
|
224
|
-
seperateTextSort: {
|
|
225
|
-
size: 0, // prop len
|
|
226
|
-
props: [],
|
|
227
|
-
buffer: new Uint8Array([]),
|
|
228
|
-
bufferTmp: new Uint8Array([]),
|
|
229
|
-
},
|
|
230
|
-
}, path = [], top = true) => {
|
|
43
|
+
export const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
|
|
231
44
|
if (result.id == 0 && top) {
|
|
232
45
|
if ('id' in type) {
|
|
233
46
|
result.id = type.id;
|
|
@@ -256,7 +69,8 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = {
|
|
|
256
69
|
isPropType('alias', schemaProp) ||
|
|
257
70
|
isPropType('cardinality', schemaProp)) {
|
|
258
71
|
if (typeof schemaProp === 'object') {
|
|
259
|
-
if (!(schemaProp.maxBytes < 61) ||
|
|
72
|
+
if (!(schemaProp.maxBytes < 61) ||
|
|
73
|
+
!('max' in schemaProp && schemaProp.max < 31)) {
|
|
260
74
|
separateSortProps++;
|
|
261
75
|
}
|
|
262
76
|
}
|
package/dist/def/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SchemaLocales } from '../index.js';
|
|
1
|
+
import type { LangCode, SchemaLocales } from '../index.js';
|
|
2
2
|
export declare const NULL = 0;
|
|
3
3
|
export declare const TIMESTAMP = 1;
|
|
4
4
|
export declare const CREATED = 2;
|
|
@@ -126,7 +126,11 @@ export type SchemaTypeDef = {
|
|
|
126
126
|
hasSeperateSort: boolean;
|
|
127
127
|
seperateSort: SchemaSortUndefinedHandler;
|
|
128
128
|
hasSeperateTextSort: boolean;
|
|
129
|
-
seperateTextSort: SchemaSortUndefinedHandler
|
|
129
|
+
seperateTextSort: SchemaSortUndefinedHandler & {
|
|
130
|
+
noUndefined: Uint8Array;
|
|
131
|
+
localeStringToIndex: Map<string, Uint8Array>;
|
|
132
|
+
localeToIndex: Map<LangCode, number>;
|
|
133
|
+
};
|
|
130
134
|
createTs?: PropDef[];
|
|
131
135
|
updateTs?: PropDef[];
|
|
132
136
|
locales: Partial<SchemaLocales>;
|
package/dist/def/utils.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from './types.js';
|
|
2
|
+
import { SchemaProp } from '../types.js';
|
|
3
|
+
export declare function isSeparate(schemaProp: SchemaProp, len: number): boolean;
|
|
2
4
|
export declare const propIsSigned: (prop: PropDef | PropDefEdge) => boolean;
|
|
3
5
|
export declare const propIsNumerical: (prop: PropDef | PropDefEdge) => boolean;
|
|
6
|
+
export declare function getPropLen(schemaProp: SchemaProp): any;
|
|
4
7
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/def/utils.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { INT16, INT32, INT8, UINT16, UINT32, UINT8, NUMBER, TIMESTAMP, } from './types.js';
|
|
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
|
+
export function isSeparate(schemaProp, len) {
|
|
5
|
+
return len === 0 || isPropType('vector', schemaProp);
|
|
6
|
+
}
|
|
2
7
|
export const propIsSigned = (prop) => {
|
|
3
8
|
const t = prop.typeIndex;
|
|
4
9
|
if (t === INT16 || t === INT32 || t === INT8) {
|
|
@@ -20,4 +25,23 @@ export const propIsNumerical = (prop) => {
|
|
|
20
25
|
}
|
|
21
26
|
return false;
|
|
22
27
|
};
|
|
28
|
+
export function getPropLen(schemaProp) {
|
|
29
|
+
let len = SIZE_MAP[getPropType(schemaProp)];
|
|
30
|
+
if (isPropType('string', schemaProp) ||
|
|
31
|
+
isPropType('alias', schemaProp) ||
|
|
32
|
+
isPropType('cardinality', schemaProp)) {
|
|
33
|
+
if (typeof schemaProp === 'object') {
|
|
34
|
+
if (schemaProp.maxBytes < 61) {
|
|
35
|
+
len = schemaProp.maxBytes + 1;
|
|
36
|
+
}
|
|
37
|
+
else if ('max' in schemaProp && schemaProp.max < 31) {
|
|
38
|
+
len = schemaProp.max * 2 + 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (isPropType('vector', schemaProp)) {
|
|
43
|
+
len = 4 * schemaProp.size;
|
|
44
|
+
}
|
|
45
|
+
return len;
|
|
46
|
+
}
|
|
23
47
|
//# sourceMappingURL=utils.js.map
|
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 | 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>;
|
|
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];
|