@based/schema 5.0.0-alpha.8 → 5.0.0
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 +30 -3
- package/dist/def/createEmptyDef.d.ts +13 -9
- package/dist/def/createEmptyDef.js +7 -3
- package/dist/def/defaultMap.d.ts +3 -0
- package/dist/def/defaultMap.js +31 -0
- package/dist/def/fillEmptyMain.d.ts +2 -2
- package/dist/def/fillEmptyMain.js +14 -8
- package/dist/def/index.d.ts +2 -1
- package/dist/def/index.js +2 -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 +143 -56
- package/dist/def/typeIndexes.d.ts +40 -0
- package/dist/def/typeIndexes.js +50 -0
- package/dist/def/types.d.ts +38 -60
- package/dist/def/types.js +24 -61
- package/dist/def/utils.d.ts +5 -3
- package/dist/def/utils.js +44 -2
- package/dist/def/validation.d.ts +7 -0
- package/dist/def/validation.js +261 -0
- 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 +58 -4
- package/dist/parse/props.d.ts +1 -0
- package/dist/parse/props.js +171 -54
- package/dist/serialize.d.ts +14 -0
- package/dist/serialize.js +543 -0
- package/dist/types.d.ts +75 -19
- package/dist/types.js +3 -1
- package/package.json +7 -5
- 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 -137
- package/dist/mermaid.d.ts +0 -3
- package/dist/mermaid.js +0 -24
package/dist/def/addEdges.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { getPropType } from '../index.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
|
+
import { fillEmptyMain } from './fillEmptyMain.js';
|
|
4
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, NUMBER, } from './types.js';
|
|
5
|
+
import { getPropLen, isSeparate, parseMinMaxStep } from './utils.js';
|
|
6
|
+
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
4
7
|
export const addEdges = (prop, refProp) => {
|
|
8
|
+
const mainEdges = [];
|
|
5
9
|
for (const key in refProp) {
|
|
6
10
|
if (key[0] === '$') {
|
|
7
11
|
if (!prop.edges) {
|
|
@@ -18,17 +22,39 @@ export const addEdges = (prop, refProp) => {
|
|
|
18
22
|
if (separate) {
|
|
19
23
|
prop.edgesSeperateCnt++;
|
|
20
24
|
}
|
|
25
|
+
const typeIndex = TYPE_INDEX_MAP[edgeType];
|
|
26
|
+
if (edgeProp.default !== undefined) {
|
|
27
|
+
prop.hasDefaultEdges = true;
|
|
28
|
+
}
|
|
29
|
+
// add default
|
|
21
30
|
const edge = {
|
|
22
31
|
__isPropDef: true,
|
|
23
32
|
__isEdge: true,
|
|
24
33
|
prop: separate ? prop.edgesSeperateCnt : 0,
|
|
34
|
+
validation: edgeProp.validation ?? VALIDATION_MAP[typeIndex] ?? defaultValidation,
|
|
25
35
|
name: key,
|
|
26
|
-
typeIndex
|
|
36
|
+
typeIndex,
|
|
27
37
|
len,
|
|
28
38
|
separate,
|
|
29
39
|
path: [...prop.path, key],
|
|
40
|
+
default: edgeProp.default ?? DEFAULT_MAP[typeIndex],
|
|
30
41
|
start: prop.edgeMainLen,
|
|
31
42
|
};
|
|
43
|
+
if (!separate) {
|
|
44
|
+
mainEdges.push(edge);
|
|
45
|
+
}
|
|
46
|
+
if (edgeProp.max !== undefined) {
|
|
47
|
+
edge.max = parseMinMaxStep(edgeProp.max);
|
|
48
|
+
}
|
|
49
|
+
if (edgeProp.min !== undefined) {
|
|
50
|
+
edge.min = parseMinMaxStep(edgeProp.min);
|
|
51
|
+
}
|
|
52
|
+
if (edgeProp.step !== undefined) {
|
|
53
|
+
edge.step = parseMinMaxStep(edgeProp.step);
|
|
54
|
+
}
|
|
55
|
+
if (edge.typeIndex !== NUMBER && edge.step === undefined) {
|
|
56
|
+
edge.step = 1;
|
|
57
|
+
}
|
|
32
58
|
prop.edgeMainLen += edge.len;
|
|
33
59
|
if (edge.typeIndex === ENUM) {
|
|
34
60
|
edge.enum = Array.isArray(refProp[key])
|
|
@@ -54,5 +80,6 @@ export const addEdges = (prop, refProp) => {
|
|
|
54
80
|
}
|
|
55
81
|
}
|
|
56
82
|
}
|
|
83
|
+
prop.edgeMainEmpty = fillEmptyMain(mainEdges, prop.edgeMainLen);
|
|
57
84
|
};
|
|
58
85
|
//# sourceMappingURL=addEdges.js.map
|
|
@@ -2,13 +2,15 @@ import { SchemaLocales, SchemaObject, StrictSchemaType } from '../types.js';
|
|
|
2
2
|
export declare const createEmptyDef: (typeName: string, type: StrictSchemaType | SchemaObject, locales: Partial<SchemaLocales>) => {
|
|
3
3
|
cnt: number;
|
|
4
4
|
blockCapacity: number;
|
|
5
|
+
insertOnly: boolean;
|
|
6
|
+
partial: boolean;
|
|
5
7
|
checksum: number;
|
|
6
8
|
type: string;
|
|
7
9
|
props: {};
|
|
8
10
|
reverseProps: {};
|
|
9
|
-
idUint8: Uint8Array
|
|
11
|
+
idUint8: Uint8Array<ArrayBuffer>;
|
|
10
12
|
id: number;
|
|
11
|
-
mainEmpty: Uint8Array
|
|
13
|
+
mainEmpty: Uint8Array<ArrayBuffer>;
|
|
12
14
|
mainLen: number;
|
|
13
15
|
separate: any[];
|
|
14
16
|
tree: {};
|
|
@@ -16,21 +18,23 @@ export declare const createEmptyDef: (typeName: string, type: StrictSchemaType |
|
|
|
16
18
|
lastId: number;
|
|
17
19
|
locales: {};
|
|
18
20
|
main: {};
|
|
21
|
+
separateSortProps: number;
|
|
22
|
+
separateSortText: number;
|
|
19
23
|
localeSize: number;
|
|
20
24
|
hasSeperateSort: boolean;
|
|
21
|
-
|
|
25
|
+
separateSort: {
|
|
22
26
|
size: number;
|
|
23
27
|
props: any[];
|
|
24
|
-
buffer: Uint8Array
|
|
25
|
-
bufferTmp: Uint8Array
|
|
28
|
+
buffer: Uint8Array<ArrayBuffer>;
|
|
29
|
+
bufferTmp: Uint8Array<ArrayBuffer>;
|
|
26
30
|
};
|
|
27
31
|
hasSeperateTextSort: boolean;
|
|
28
|
-
|
|
32
|
+
separateTextSort: {
|
|
29
33
|
size: number;
|
|
30
34
|
props: any[];
|
|
31
|
-
buffer: Uint8Array
|
|
32
|
-
noUndefined: Uint8Array
|
|
33
|
-
bufferTmp: Uint8Array
|
|
35
|
+
buffer: Uint8Array<ArrayBuffer>;
|
|
36
|
+
noUndefined: Uint8Array<ArrayBuffer>;
|
|
37
|
+
bufferTmp: Uint8Array<ArrayBuffer>;
|
|
34
38
|
localeStringToIndex: Map<any, any>;
|
|
35
39
|
localeToIndex: Map<any, any>;
|
|
36
40
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { hashObjectIgnoreKeyOrder } from '@
|
|
1
|
+
import { hashObjectIgnoreKeyOrder } from '@based/hash';
|
|
2
2
|
export const createEmptyDef = (typeName, type, locales) => {
|
|
3
3
|
return {
|
|
4
4
|
cnt: 0,
|
|
5
5
|
blockCapacity: 0,
|
|
6
|
+
insertOnly: false,
|
|
7
|
+
partial: false,
|
|
6
8
|
checksum: hashObjectIgnoreKeyOrder(type),
|
|
7
9
|
type: typeName,
|
|
8
10
|
props: {},
|
|
@@ -18,16 +20,18 @@ export const createEmptyDef = (typeName, type, locales) => {
|
|
|
18
20
|
lastId: 0,
|
|
19
21
|
locales: {},
|
|
20
22
|
main: {},
|
|
23
|
+
separateSortProps: 0,
|
|
24
|
+
separateSortText: 0,
|
|
21
25
|
localeSize: 0,
|
|
22
26
|
hasSeperateSort: false,
|
|
23
|
-
|
|
27
|
+
separateSort: {
|
|
24
28
|
size: 0,
|
|
25
29
|
props: [],
|
|
26
30
|
buffer: new Uint8Array([]),
|
|
27
31
|
bufferTmp: new Uint8Array([]),
|
|
28
32
|
},
|
|
29
33
|
hasSeperateTextSort: false,
|
|
30
|
-
|
|
34
|
+
separateTextSort: {
|
|
31
35
|
size: 0, // prop len
|
|
32
36
|
props: [],
|
|
33
37
|
buffer: new Uint8Array([]),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ALIAS, BINARY, JSON, BOOLEAN, CARDINALITY, TIMESTAMP, INT16, INT32, INT8, UINT8, UINT16, UINT32, NUMBER, ENUM, ID, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, ALIASES, VECTOR, COLVEC, WEAK_REFERENCE, WEAK_REFERENCES, NULL, OBJECT, } from './types.js';
|
|
2
|
+
export const DEFAULT_MAP = {
|
|
3
|
+
[NULL]: 0,
|
|
4
|
+
[OBJECT]: 0,
|
|
5
|
+
[WEAK_REFERENCE]: 0,
|
|
6
|
+
[WEAK_REFERENCES]: 0,
|
|
7
|
+
[ALIAS]: '',
|
|
8
|
+
[BINARY]: new Uint8Array(),
|
|
9
|
+
[BOOLEAN]: false,
|
|
10
|
+
[CARDINALITY]: [],
|
|
11
|
+
[NUMBER]: 0,
|
|
12
|
+
[TIMESTAMP]: 0,
|
|
13
|
+
[ENUM]: 0,
|
|
14
|
+
[ID]: 0,
|
|
15
|
+
[INT16]: 0,
|
|
16
|
+
[INT32]: 0,
|
|
17
|
+
[INT8]: 0,
|
|
18
|
+
[UINT8]: 0,
|
|
19
|
+
[UINT16]: 0,
|
|
20
|
+
[UINT32]: 0,
|
|
21
|
+
[JSON]: null,
|
|
22
|
+
[MICRO_BUFFER]: undefined,
|
|
23
|
+
[REFERENCE]: undefined,
|
|
24
|
+
[REFERENCES]: [],
|
|
25
|
+
[STRING]: '',
|
|
26
|
+
[ALIASES]: [],
|
|
27
|
+
[TEXT]: {},
|
|
28
|
+
[VECTOR]: undefined, // maybe not can set a vec with 0
|
|
29
|
+
[COLVEC]: undefined, // maybe not can set a vec with 0
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=defaultMap.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PropDef } from './types.js';
|
|
1
|
+
import { PropDef, PropDefEdge } from './types.js';
|
|
2
2
|
export declare const ENCODER: TextEncoder;
|
|
3
|
-
export declare const fillEmptyMain: (vals: PropDef[], mainLen: number) => Uint8Array
|
|
3
|
+
export declare const fillEmptyMain: (vals: (PropDef | PropDefEdge)[], mainLen: number) => Uint8Array<ArrayBuffer>;
|
|
4
4
|
export declare const isZeroes: (buf: Uint8Array) => boolean;
|
|
5
5
|
//# sourceMappingURL=fillEmptyMain.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { convertToTimestamp, writeInt64 } from '@based/utils';
|
|
2
|
+
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from './types.js';
|
|
3
3
|
export const ENCODER = new TextEncoder();
|
|
4
4
|
export const fillEmptyMain = (vals, mainLen) => {
|
|
5
5
|
const mainEmpty = new Uint8Array(mainLen);
|
|
@@ -10,8 +10,14 @@ export const fillEmptyMain = (vals, mainLen) => {
|
|
|
10
10
|
const t = f.typeIndex;
|
|
11
11
|
const s = f.start;
|
|
12
12
|
let val = f.default;
|
|
13
|
-
if (t ===
|
|
14
|
-
mainEmpty[s] =
|
|
13
|
+
if (t === ENUM) {
|
|
14
|
+
mainEmpty[s] = f.default ?? 0;
|
|
15
|
+
}
|
|
16
|
+
else if (t === INT8 || t === UINT8) {
|
|
17
|
+
mainEmpty[s] = val;
|
|
18
|
+
}
|
|
19
|
+
else if (t === BOOLEAN) {
|
|
20
|
+
mainEmpty[s] = val ? 1 : 0;
|
|
15
21
|
}
|
|
16
22
|
else if (t === UINT32 || t === INT32) {
|
|
17
23
|
mainEmpty[s] = val;
|
|
@@ -23,10 +29,10 @@ export const fillEmptyMain = (vals, mainLen) => {
|
|
|
23
29
|
mainEmpty[s] = val;
|
|
24
30
|
mainEmpty[s + 1] = val >>>= 8;
|
|
25
31
|
}
|
|
26
|
-
else if (t ===
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
else if (t === TIMESTAMP) {
|
|
33
|
+
writeInt64(mainEmpty, convertToTimestamp(val), s);
|
|
34
|
+
}
|
|
35
|
+
else if (t === NUMBER) {
|
|
30
36
|
const view = new DataView(mainEmpty.buffer, s, 8);
|
|
31
37
|
view.setFloat64(0, val, true);
|
|
32
38
|
}
|
package/dist/def/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './types.js';
|
|
|
2
2
|
export * from './typeDef.js';
|
|
3
3
|
export * from './utils.js';
|
|
4
4
|
export * from './selvaBuffer.js';
|
|
5
|
-
export * from './readFromPacked.js';
|
|
6
5
|
export * from './createEmptyDef.js';
|
|
6
|
+
export * from './defaultMap.js';
|
|
7
|
+
export * from './validation.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/def/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './types.js';
|
|
|
3
3
|
export * from './typeDef.js';
|
|
4
4
|
export * from './utils.js';
|
|
5
5
|
export * from './selvaBuffer.js';
|
|
6
|
-
export * from './readFromPacked.js';
|
|
7
6
|
export * from './createEmptyDef.js';
|
|
7
|
+
export * from './defaultMap.js';
|
|
8
|
+
export * from './validation.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -11,17 +11,17 @@ export function makeSeparateSort(result) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
result.
|
|
14
|
+
result.separateSort.buffer = new Uint8Array(max + 1);
|
|
15
15
|
for (const f of result.separate) {
|
|
16
16
|
if (f.typeIndex === STRING ||
|
|
17
17
|
f.typeIndex === ALIAS ||
|
|
18
18
|
f.typeIndex === CARDINALITY) {
|
|
19
|
-
result.
|
|
20
|
-
result.
|
|
21
|
-
result.
|
|
19
|
+
result.separateSort.buffer[f.prop] = 1;
|
|
20
|
+
result.separateSort.props.push(f);
|
|
21
|
+
result.separateSort.size++;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
result.
|
|
25
|
-
result.
|
|
24
|
+
result.separateSort.bufferTmp = new Uint8Array(max + 1);
|
|
25
|
+
result.separateSort.buffer.set(result.separateSort.bufferTmp);
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=makeSeparateSort.js.map
|
|
@@ -11,28 +11,28 @@ export function makeSeparateTextSort(result) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
const bufLen = (max + 1) * (result.localeSize + 1);
|
|
14
|
-
result.
|
|
14
|
+
result.separateTextSort.buffer = new Uint8Array(bufLen);
|
|
15
15
|
let index = 0;
|
|
16
16
|
for (const code in result.locales) {
|
|
17
17
|
const codeLang = langCodesMap.get(code);
|
|
18
|
-
result.
|
|
19
|
-
result.
|
|
18
|
+
result.separateTextSort.localeStringToIndex.set(code, new Uint8Array([index + 1, codeLang]));
|
|
19
|
+
result.separateTextSort.localeToIndex.set(codeLang, index + 1);
|
|
20
20
|
index++;
|
|
21
21
|
}
|
|
22
22
|
for (const f of result.separate) {
|
|
23
23
|
if (f.typeIndex === TEXT) {
|
|
24
24
|
const index = f.prop * (result.localeSize + 1);
|
|
25
|
-
result.
|
|
26
|
-
for (const [, locales] of result.
|
|
27
|
-
result.
|
|
25
|
+
result.separateTextSort.buffer[index] = result.localeSize;
|
|
26
|
+
for (const [, locales] of result.separateTextSort.localeStringToIndex) {
|
|
27
|
+
result.separateTextSort.buffer[locales[0] + index] = locales[1];
|
|
28
28
|
}
|
|
29
|
-
result.
|
|
30
|
-
result.
|
|
29
|
+
result.separateTextSort.props.push(f);
|
|
30
|
+
result.separateTextSort.size += result.localeSize;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
result.
|
|
34
|
-
result.
|
|
35
|
-
result.
|
|
36
|
-
result.
|
|
33
|
+
result.separateTextSort.props.sort((a, b) => (a.prop > b.prop ? 1 : -1));
|
|
34
|
+
result.separateTextSort.bufferTmp = new Uint8Array(bufLen);
|
|
35
|
+
result.separateTextSort.bufferTmp.fill(0);
|
|
36
|
+
result.separateTextSort.bufferTmp.set(result.separateTextSort.buffer);
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=makeSeparateTextSort.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const packOne = (nodeType, field) => ((nodeType & 0xffff) << 8) | (field & 0xff);
|
|
2
|
+
const packTwo = (a, b) => (a << 24) | (b & 0xffffff);
|
|
3
|
+
const makeTuple = (aType, aField, bType, bField) => {
|
|
4
|
+
const a = packOne(aType, aField);
|
|
5
|
+
const b = packOne(bType, bField);
|
|
6
|
+
return a < b ? packTwo(a, b) : packTwo(b, a);
|
|
7
|
+
};
|
|
8
|
+
export default class RefSet {
|
|
9
|
+
#s = new Set();
|
|
10
|
+
add(srcType, srcField, dstType, dstField) {
|
|
11
|
+
const t = makeTuple(srcType, srcField, dstType, dstField);
|
|
12
|
+
if (this.#s.has(t)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
this.#s.add(t);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.#s.clear();
|
|
20
|
+
}
|
|
21
|
+
values() {
|
|
22
|
+
return this.#s.values();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=refSet.js.map
|
package/dist/def/selvaBuffer.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
import { ALIAS, ALIASES, BINARY, EMPTY_MICRO_BUFFER, CARDINALITY, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, } from './types.js';
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, EMPTY_MICRO_BUFFER, CARDINALITY, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, COLVEC, VECTOR_BASE_TYPE_SIZE_MAP, } from './types.js';
|
|
2
|
+
import RefSet from './refSet.js';
|
|
3
|
+
const selvaFieldType = {
|
|
4
|
+
NULL: 0,
|
|
5
|
+
MICRO_BUFFER: 1,
|
|
6
|
+
STRING: 2,
|
|
7
|
+
TEXT: 3,
|
|
8
|
+
REFERENCE: 4,
|
|
9
|
+
REFERENCES: 5,
|
|
10
|
+
WEAK_REFERENCE: 6,
|
|
11
|
+
WEAK_REFERENCES: 7,
|
|
12
|
+
ALIAS: 8,
|
|
13
|
+
ALIASES: 9,
|
|
14
|
+
COLVEC: 10,
|
|
15
|
+
};
|
|
2
16
|
const selvaTypeMap = new Uint8Array(32); // 1.2x faster than JS array
|
|
3
|
-
selvaTypeMap[MICRO_BUFFER] =
|
|
4
|
-
selvaTypeMap[VECTOR] =
|
|
5
|
-
selvaTypeMap[BINARY] =
|
|
6
|
-
selvaTypeMap[CARDINALITY] =
|
|
7
|
-
selvaTypeMap[JSON] =
|
|
8
|
-
selvaTypeMap[STRING] =
|
|
9
|
-
selvaTypeMap[TEXT] =
|
|
10
|
-
selvaTypeMap[REFERENCE] =
|
|
11
|
-
selvaTypeMap[REFERENCES] =
|
|
12
|
-
selvaTypeMap[WEAK_REFERENCE] =
|
|
13
|
-
selvaTypeMap[WEAK_REFERENCES] =
|
|
14
|
-
selvaTypeMap[ALIAS] =
|
|
15
|
-
selvaTypeMap[ALIASES] =
|
|
17
|
+
selvaTypeMap[MICRO_BUFFER] = selvaFieldType.MICRO_BUFFER;
|
|
18
|
+
selvaTypeMap[VECTOR] = selvaFieldType.MICRO_BUFFER;
|
|
19
|
+
selvaTypeMap[BINARY] = selvaFieldType.STRING;
|
|
20
|
+
selvaTypeMap[CARDINALITY] = selvaFieldType.STRING;
|
|
21
|
+
selvaTypeMap[JSON] = selvaFieldType.STRING;
|
|
22
|
+
selvaTypeMap[STRING] = selvaFieldType.STRING;
|
|
23
|
+
selvaTypeMap[TEXT] = selvaFieldType.TEXT;
|
|
24
|
+
selvaTypeMap[REFERENCE] = selvaFieldType.REFERENCE;
|
|
25
|
+
selvaTypeMap[REFERENCES] = selvaFieldType.REFERENCES;
|
|
26
|
+
selvaTypeMap[WEAK_REFERENCE] = selvaFieldType.WEAK_REFERENCE;
|
|
27
|
+
selvaTypeMap[WEAK_REFERENCES] = selvaFieldType.WEAK_REFERENCES;
|
|
28
|
+
selvaTypeMap[ALIAS] = selvaFieldType.ALIAS;
|
|
29
|
+
selvaTypeMap[ALIASES] = selvaFieldType.ALIASES;
|
|
30
|
+
selvaTypeMap[COLVEC] = selvaFieldType.COLVEC;
|
|
16
31
|
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
32
|
+
const EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP = 0x80;
|
|
17
33
|
function blockCapacity(blockCapacity) {
|
|
18
34
|
const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
|
|
19
35
|
const view = new DataView(buf.buffer);
|
|
@@ -23,10 +39,22 @@ function blockCapacity(blockCapacity) {
|
|
|
23
39
|
function sepPropCount(props) {
|
|
24
40
|
return props.filter((prop) => prop.separate).length;
|
|
25
41
|
}
|
|
26
|
-
function makeEdgeConstraintFlags(prop) {
|
|
27
|
-
|
|
42
|
+
function makeEdgeConstraintFlags(refSet, nodeTypeId, prop, dstNodeTypeId, inverseProp) {
|
|
43
|
+
let flags = 0;
|
|
44
|
+
flags |= prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00;
|
|
45
|
+
flags |=
|
|
46
|
+
prop.typeIndex === REFERENCE &&
|
|
47
|
+
inverseProp &&
|
|
48
|
+
inverseProp.typeIndex === REFERENCES
|
|
49
|
+
? EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP
|
|
50
|
+
: 0x00;
|
|
51
|
+
if (refSet) {
|
|
52
|
+
const x = refSet.add(nodeTypeId, prop.prop, dstNodeTypeId, inverseProp.prop);
|
|
53
|
+
flags |= x ? 0x00 : EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP;
|
|
54
|
+
}
|
|
55
|
+
return flags;
|
|
28
56
|
}
|
|
29
|
-
const propDefBuffer = (schema, prop, isEdge) => {
|
|
57
|
+
const propDefBuffer = (refSet, nodeTypeId, schema, prop, isEdge) => {
|
|
30
58
|
const type = prop.typeIndex;
|
|
31
59
|
const selvaType = selvaTypeMap[type];
|
|
32
60
|
if (prop.len && (type === MICRO_BUFFER || type === VECTOR)) {
|
|
@@ -36,6 +64,15 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
36
64
|
view.setUint16(1, prop.len, true);
|
|
37
65
|
return [...buf];
|
|
38
66
|
}
|
|
67
|
+
else if (prop.len && type === COLVEC) {
|
|
68
|
+
const buf = new Uint8Array(5);
|
|
69
|
+
const view = new DataView(buf.buffer);
|
|
70
|
+
buf[0] = selvaType;
|
|
71
|
+
const baseSize = VECTOR_BASE_TYPE_SIZE_MAP[prop.vectorBaseType];
|
|
72
|
+
view.setUint16(1, prop.len / baseSize, true); // elements
|
|
73
|
+
view.setUint16(3, baseSize, true); // element size
|
|
74
|
+
return [...buf];
|
|
75
|
+
}
|
|
39
76
|
else if (type === REFERENCE || type === REFERENCES) {
|
|
40
77
|
const buf = new Uint8Array(9);
|
|
41
78
|
const view = new DataView(buf.buffer);
|
|
@@ -43,12 +80,10 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
43
80
|
let eschema = [];
|
|
44
81
|
// @ts-ignore
|
|
45
82
|
buf[0] = selvaType + 2 * !!isEdge; // field type
|
|
46
|
-
buf[1] = makeEdgeConstraintFlags(prop); // flags
|
|
83
|
+
buf[1] = makeEdgeConstraintFlags(refSet, nodeTypeId, prop, dstType.id, dstType.props[prop.inversePropName]); // flags
|
|
47
84
|
view.setUint16(2, dstType.id, true); // dst_node_type
|
|
48
85
|
view.setUint32(5, 0, true); // schema_len
|
|
49
86
|
if (!isEdge) {
|
|
50
|
-
prop.inverseTypeId = dstType.id;
|
|
51
|
-
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
52
87
|
buf[4] = prop.inversePropNumber;
|
|
53
88
|
if (prop.edges) {
|
|
54
89
|
const edgesS = Object.values(prop.edges);
|
|
@@ -66,9 +101,9 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
66
101
|
...props,
|
|
67
102
|
];
|
|
68
103
|
eschema = p
|
|
69
|
-
.map((prop) => propDefBuffer(schema, prop, true))
|
|
104
|
+
.map((prop) => propDefBuffer(null, 0, schema, prop, true))
|
|
70
105
|
.flat(1);
|
|
71
|
-
eschema.unshift(0, 0, 0, 0, sepPropCount(p), 0);
|
|
106
|
+
eschema.unshift(0, 0, 0, 0, sepPropCount(p), 0, 0, 0);
|
|
72
107
|
view.setUint32(5, eschema.length, true);
|
|
73
108
|
}
|
|
74
109
|
}
|
|
@@ -87,28 +122,42 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
87
122
|
};
|
|
88
123
|
// TODO rewrite
|
|
89
124
|
export function schemaToSelvaBuffer(schema) {
|
|
90
|
-
|
|
125
|
+
const refSet = new RefSet();
|
|
126
|
+
return Object.values(schema).map((t) => {
|
|
91
127
|
const props = Object.values(t.props);
|
|
92
128
|
const rest = [];
|
|
129
|
+
const nrFields = 1 + sepPropCount(props);
|
|
93
130
|
let refFields = 0;
|
|
131
|
+
let virtualFields = 0;
|
|
132
|
+
if (nrFields >= 250) {
|
|
133
|
+
throw new Error('Too many fields');
|
|
134
|
+
}
|
|
94
135
|
for (const f of props) {
|
|
95
136
|
if (f.separate) {
|
|
96
137
|
if (f.typeIndex === REFERENCE || f.typeIndex === REFERENCES) {
|
|
97
138
|
refFields++;
|
|
98
139
|
}
|
|
140
|
+
else if (f.typeIndex === ALIAS ||
|
|
141
|
+
f.typeIndex === ALIASES ||
|
|
142
|
+
f.typeIndex === COLVEC) {
|
|
143
|
+
// We assume that these are always the last props!
|
|
144
|
+
virtualFields++;
|
|
145
|
+
}
|
|
99
146
|
rest.push(f);
|
|
100
147
|
}
|
|
101
148
|
}
|
|
102
149
|
rest.sort((a, b) => a.prop - b.prop);
|
|
103
150
|
return Uint8Array.from([
|
|
104
|
-
...blockCapacity(t.blockCapacity),
|
|
105
|
-
|
|
106
|
-
1 + refFields,
|
|
107
|
-
|
|
151
|
+
...blockCapacity(t.blockCapacity), // u32 blockCapacity
|
|
152
|
+
nrFields, // u8 nrFields
|
|
153
|
+
1 + refFields, // u8 nrFixedFields
|
|
154
|
+
virtualFields, // u8 nrVirtualFields
|
|
155
|
+
0, // u8 spare1
|
|
156
|
+
...propDefBuffer(null, t.id, schema, {
|
|
108
157
|
...EMPTY_MICRO_BUFFER,
|
|
109
158
|
len: t.mainLen === 0 ? 1 : t.mainLen,
|
|
110
159
|
}),
|
|
111
|
-
...rest.map((f) => propDefBuffer(schema, f)).flat(1),
|
|
160
|
+
...rest.map((f) => propDefBuffer(refSet, t.id, schema, f)).flat(1),
|
|
112
161
|
]).buffer;
|
|
113
162
|
});
|
|
114
163
|
}
|
package/dist/def/typeDef.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { SchemaObject, StrictSchemaType, SchemaLocales } from '../index.js';
|
|
2
|
-
import { SchemaTypeDef,
|
|
2
|
+
import { SchemaTypeDef, SchemaTypesParsed } from './types.js';
|
|
3
3
|
import { StrictSchema } from '../types.js';
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
4
|
+
export declare const updateTypeDefs: (schema: StrictSchema) => {
|
|
5
|
+
schemaTypesParsed: {
|
|
6
|
+
[key: string]: SchemaTypeDef;
|
|
7
|
+
};
|
|
8
|
+
schemaTypesParsedById: {
|
|
9
|
+
[id: number]: SchemaTypeDef;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
6
12
|
export declare const createSchemaTypeDef: (typeName: string, type: StrictSchemaType | SchemaObject, parsed: SchemaTypesParsed, locales: Partial<SchemaLocales>, result?: Partial<SchemaTypeDef>, path?: string[], top?: boolean) => SchemaTypeDef;
|
|
7
13
|
//# sourceMappingURL=typeDef.d.ts.map
|