@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,29 @@
|
|
|
1
|
+
import { TYPE_INDEX_MAP } from './types.js';
|
|
2
|
+
// TODO update defaults
|
|
3
|
+
export const DEFAULT_MAP = {
|
|
4
|
+
[TYPE_INDEX_MAP.alias]: '',
|
|
5
|
+
[TYPE_INDEX_MAP.binary]: undefined,
|
|
6
|
+
[TYPE_INDEX_MAP.boolean]: false,
|
|
7
|
+
[TYPE_INDEX_MAP.cardinality]: 0,
|
|
8
|
+
[TYPE_INDEX_MAP.created]: 0,
|
|
9
|
+
[TYPE_INDEX_MAP.updated]: 0,
|
|
10
|
+
[TYPE_INDEX_MAP.number]: 0,
|
|
11
|
+
[TYPE_INDEX_MAP.timestamp]: 0,
|
|
12
|
+
[TYPE_INDEX_MAP.enum]: 0,
|
|
13
|
+
[TYPE_INDEX_MAP.id]: 0,
|
|
14
|
+
[TYPE_INDEX_MAP.int16]: 0,
|
|
15
|
+
[TYPE_INDEX_MAP.int32]: 0,
|
|
16
|
+
[TYPE_INDEX_MAP.int8]: 0,
|
|
17
|
+
[TYPE_INDEX_MAP.uint8]: 0,
|
|
18
|
+
[TYPE_INDEX_MAP.uint16]: 0,
|
|
19
|
+
[TYPE_INDEX_MAP.uint32]: 0,
|
|
20
|
+
[TYPE_INDEX_MAP.json]: undefined,
|
|
21
|
+
[TYPE_INDEX_MAP.microbuffer]: undefined,
|
|
22
|
+
[TYPE_INDEX_MAP.reference]: undefined,
|
|
23
|
+
[TYPE_INDEX_MAP.references]: [],
|
|
24
|
+
[TYPE_INDEX_MAP.string]: '',
|
|
25
|
+
[TYPE_INDEX_MAP.aliases]: [],
|
|
26
|
+
[TYPE_INDEX_MAP.text]: '',
|
|
27
|
+
[TYPE_INDEX_MAP.vector]: undefined, // maybe not can set a vec with 0
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=DEFAULT_MAP.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { getPropType } from '../index.js';
|
|
2
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, NUMBER, } from './types.js';
|
|
4
|
+
import { getPropLen, isSeparate, parseMinMaxStep } from './utils.js';
|
|
5
|
+
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
6
|
+
export const addEdges = (prop, refProp) => {
|
|
7
|
+
for (const key in refProp) {
|
|
8
|
+
if (key[0] === '$') {
|
|
9
|
+
if (!prop.edges) {
|
|
10
|
+
prop.edgeMainLen = 0;
|
|
11
|
+
prop.edges = {};
|
|
12
|
+
prop.reverseSeperateEdges = {};
|
|
13
|
+
prop.reverseMainEdges = {};
|
|
14
|
+
prop.edgesSeperateCnt = 0;
|
|
15
|
+
}
|
|
16
|
+
const edgeProp = refProp[key];
|
|
17
|
+
const edgeType = getPropType(edgeProp);
|
|
18
|
+
const len = getPropLen(edgeProp);
|
|
19
|
+
const separate = isSeparate(edgeProp, len);
|
|
20
|
+
if (separate) {
|
|
21
|
+
prop.edgesSeperateCnt++;
|
|
22
|
+
}
|
|
23
|
+
const typeIndex = TYPE_INDEX_MAP[edgeType];
|
|
24
|
+
// add default
|
|
25
|
+
const edge = {
|
|
26
|
+
__isPropDef: true,
|
|
27
|
+
__isEdge: true,
|
|
28
|
+
prop: separate ? prop.edgesSeperateCnt : 0,
|
|
29
|
+
validation: edgeProp.validation ?? VALIDATION_MAP[typeIndex] ?? defaultValidation,
|
|
30
|
+
name: key,
|
|
31
|
+
typeIndex,
|
|
32
|
+
len,
|
|
33
|
+
separate,
|
|
34
|
+
path: [...prop.path, key],
|
|
35
|
+
default: edgeProp.default ?? DEFAULT_MAP[typeIndex],
|
|
36
|
+
start: prop.edgeMainLen,
|
|
37
|
+
};
|
|
38
|
+
if (edgeProp.max !== undefined) {
|
|
39
|
+
edge.max = parseMinMaxStep(edgeProp.max);
|
|
40
|
+
}
|
|
41
|
+
if (edgeProp.min !== undefined) {
|
|
42
|
+
edge.min = parseMinMaxStep(edgeProp.min);
|
|
43
|
+
}
|
|
44
|
+
if (edgeProp.step !== undefined) {
|
|
45
|
+
edge.step = parseMinMaxStep(edgeProp.step);
|
|
46
|
+
}
|
|
47
|
+
if (edge.typeIndex !== NUMBER && edge.step === undefined) {
|
|
48
|
+
edge.step = 1;
|
|
49
|
+
}
|
|
50
|
+
prop.edgeMainLen += edge.len;
|
|
51
|
+
if (edge.typeIndex === ENUM) {
|
|
52
|
+
edge.enum = Array.isArray(refProp[key])
|
|
53
|
+
? refProp[key]
|
|
54
|
+
: refProp[key].enum;
|
|
55
|
+
edge.reverseEnum = {};
|
|
56
|
+
for (let i = 0; i < edge.enum.length; i++) {
|
|
57
|
+
edge.reverseEnum[edge.enum[i]] = i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (edge.typeIndex === REFERENCES) {
|
|
61
|
+
edge.inverseTypeName = refProp[key].items.ref;
|
|
62
|
+
}
|
|
63
|
+
else if (edge.typeIndex === REFERENCE) {
|
|
64
|
+
edge.inverseTypeName = refProp[key].ref;
|
|
65
|
+
}
|
|
66
|
+
prop.edges[key] = edge;
|
|
67
|
+
if (separate) {
|
|
68
|
+
prop.reverseSeperateEdges[edge.prop] = edge;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
prop.reverseMainEdges[edge.start] = edge;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=addEdges.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
insertOnly: boolean;
|
|
6
|
+
partial: boolean;
|
|
7
|
+
checksum: number;
|
|
8
|
+
type: string;
|
|
9
|
+
props: {};
|
|
10
|
+
reverseProps: {};
|
|
11
|
+
idUint8: Uint8Array;
|
|
12
|
+
id: number;
|
|
13
|
+
mainEmpty: Uint8Array;
|
|
14
|
+
mainLen: number;
|
|
15
|
+
separate: any[];
|
|
16
|
+
tree: {};
|
|
17
|
+
total: number;
|
|
18
|
+
lastId: number;
|
|
19
|
+
locales: {};
|
|
20
|
+
main: {};
|
|
21
|
+
separateSortProps: number;
|
|
22
|
+
separateSortText: number;
|
|
23
|
+
localeSize: number;
|
|
24
|
+
hasSeperateSort: boolean;
|
|
25
|
+
seperateSort: {
|
|
26
|
+
size: number;
|
|
27
|
+
props: any[];
|
|
28
|
+
buffer: Uint8Array;
|
|
29
|
+
bufferTmp: Uint8Array;
|
|
30
|
+
};
|
|
31
|
+
hasSeperateTextSort: boolean;
|
|
32
|
+
seperateTextSort: {
|
|
33
|
+
size: number;
|
|
34
|
+
props: any[];
|
|
35
|
+
buffer: Uint8Array;
|
|
36
|
+
noUndefined: Uint8Array;
|
|
37
|
+
bufferTmp: Uint8Array;
|
|
38
|
+
localeStringToIndex: Map<any, any>;
|
|
39
|
+
localeToIndex: Map<any, any>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=createEmptyDef.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
2
|
+
export const createEmptyDef = (typeName, type, locales) => {
|
|
3
|
+
return {
|
|
4
|
+
cnt: 0,
|
|
5
|
+
blockCapacity: 0,
|
|
6
|
+
insertOnly: false,
|
|
7
|
+
partial: false,
|
|
8
|
+
checksum: hashObjectIgnoreKeyOrder(type),
|
|
9
|
+
type: typeName,
|
|
10
|
+
props: {},
|
|
11
|
+
reverseProps: {},
|
|
12
|
+
idUint8: new Uint8Array([0, 0]),
|
|
13
|
+
// empty main buffer
|
|
14
|
+
id: 0,
|
|
15
|
+
mainEmpty: new Uint8Array(0),
|
|
16
|
+
mainLen: 0,
|
|
17
|
+
separate: [],
|
|
18
|
+
tree: {},
|
|
19
|
+
total: 0,
|
|
20
|
+
lastId: 0,
|
|
21
|
+
locales: {},
|
|
22
|
+
main: {},
|
|
23
|
+
separateSortProps: 0,
|
|
24
|
+
separateSortText: 0,
|
|
25
|
+
localeSize: 0,
|
|
26
|
+
hasSeperateSort: false,
|
|
27
|
+
seperateSort: {
|
|
28
|
+
size: 0,
|
|
29
|
+
props: [],
|
|
30
|
+
buffer: new Uint8Array([]),
|
|
31
|
+
bufferTmp: new Uint8Array([]),
|
|
32
|
+
},
|
|
33
|
+
hasSeperateTextSort: false,
|
|
34
|
+
seperateTextSort: {
|
|
35
|
+
size: 0, // prop len
|
|
36
|
+
props: [],
|
|
37
|
+
buffer: new Uint8Array([]),
|
|
38
|
+
noUndefined: new Uint8Array(new Array(Object.keys(locales).length).fill(0)),
|
|
39
|
+
bufferTmp: new Uint8Array([]),
|
|
40
|
+
localeStringToIndex: new Map(),
|
|
41
|
+
localeToIndex: new Map(),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=createEmptyDef.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TYPE_INDEX_MAP } from './types.js';
|
|
2
|
+
// TODO update defaults
|
|
3
|
+
export const DEFAULT_MAP = {
|
|
4
|
+
[TYPE_INDEX_MAP.alias]: '',
|
|
5
|
+
[TYPE_INDEX_MAP.binary]: new Uint8Array([]),
|
|
6
|
+
[TYPE_INDEX_MAP.boolean]: false,
|
|
7
|
+
[TYPE_INDEX_MAP.cardinality]: 0,
|
|
8
|
+
[TYPE_INDEX_MAP.number]: 0,
|
|
9
|
+
[TYPE_INDEX_MAP.timestamp]: 0,
|
|
10
|
+
[TYPE_INDEX_MAP.enum]: 0,
|
|
11
|
+
[TYPE_INDEX_MAP.id]: 0,
|
|
12
|
+
[TYPE_INDEX_MAP.int16]: 0,
|
|
13
|
+
[TYPE_INDEX_MAP.int32]: 0,
|
|
14
|
+
[TYPE_INDEX_MAP.int8]: 0,
|
|
15
|
+
[TYPE_INDEX_MAP.uint8]: 0,
|
|
16
|
+
[TYPE_INDEX_MAP.uint16]: 0,
|
|
17
|
+
[TYPE_INDEX_MAP.uint32]: 0,
|
|
18
|
+
[TYPE_INDEX_MAP.json]: null,
|
|
19
|
+
[TYPE_INDEX_MAP.microbuffer]: undefined,
|
|
20
|
+
[TYPE_INDEX_MAP.reference]: undefined,
|
|
21
|
+
[TYPE_INDEX_MAP.references]: [],
|
|
22
|
+
[TYPE_INDEX_MAP.string]: '',
|
|
23
|
+
[TYPE_INDEX_MAP.aliases]: [],
|
|
24
|
+
[TYPE_INDEX_MAP.text]: {},
|
|
25
|
+
[TYPE_INDEX_MAP.vector]: undefined, // maybe not can set a vec with 0
|
|
26
|
+
[TYPE_INDEX_MAP.colvec]: undefined, // maybe not can set a vec with 0
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=defaultMap.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PropDef } from './types.js';
|
|
2
|
+
export declare const ENCODER: TextEncoder;
|
|
3
|
+
export declare const fillEmptyMain: (vals: PropDef[], mainLen: number) => Uint8Array;
|
|
4
|
+
export declare const isZeroes: (buf: Uint8Array) => boolean;
|
|
5
|
+
//# sourceMappingURL=fillEmptyMain.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { convertToTimestamp } from '@saulx/utils';
|
|
2
|
+
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from './types.js';
|
|
3
|
+
// Lets add validation of values in here - need to validate DEFAULT!
|
|
4
|
+
export const ENCODER = new TextEncoder();
|
|
5
|
+
export const fillEmptyMain = (vals, mainLen) => {
|
|
6
|
+
const mainEmpty = new Uint8Array(mainLen);
|
|
7
|
+
for (const f of vals) {
|
|
8
|
+
if (f.separate) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const t = f.typeIndex;
|
|
12
|
+
const s = f.start;
|
|
13
|
+
let val = f.default;
|
|
14
|
+
if (t === ENUM) {
|
|
15
|
+
mainEmpty[s] =
|
|
16
|
+
typeof f.default === 'number' ? f.default : f.reverseEnum[val];
|
|
17
|
+
}
|
|
18
|
+
else if (t === INT8 || t === UINT8) {
|
|
19
|
+
mainEmpty[s] = val;
|
|
20
|
+
}
|
|
21
|
+
else if (t === BOOLEAN) {
|
|
22
|
+
mainEmpty[s] = val === true ? 1 : 0;
|
|
23
|
+
}
|
|
24
|
+
else if (t === UINT32 || t === INT32) {
|
|
25
|
+
mainEmpty[s] = val;
|
|
26
|
+
mainEmpty[s + 1] = val >>>= 8;
|
|
27
|
+
mainEmpty[s + 2] = val >>>= 8;
|
|
28
|
+
mainEmpty[s + 3] = val >>>= 8;
|
|
29
|
+
}
|
|
30
|
+
else if (t === UINT16 || t === INT16) {
|
|
31
|
+
mainEmpty[s] = val;
|
|
32
|
+
mainEmpty[s + 1] = val >>>= 8;
|
|
33
|
+
}
|
|
34
|
+
else if (t === NUMBER || t === TIMESTAMP) {
|
|
35
|
+
const view = new DataView(mainEmpty.buffer, s, 8);
|
|
36
|
+
view.setFloat64(0, convertToTimestamp(val), true);
|
|
37
|
+
}
|
|
38
|
+
else if (t === STRING) {
|
|
39
|
+
val = ENCODER.encode(val);
|
|
40
|
+
mainEmpty[s] = val.byteLength;
|
|
41
|
+
mainEmpty.set(val, s + 1);
|
|
42
|
+
}
|
|
43
|
+
else if (t === BINARY) {
|
|
44
|
+
if (val !== undefined) {
|
|
45
|
+
mainEmpty.set(val, s);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return mainEmpty;
|
|
50
|
+
};
|
|
51
|
+
export const isZeroes = (buf) => {
|
|
52
|
+
let i = 0;
|
|
53
|
+
while (i < buf.byteLength) {
|
|
54
|
+
if (buf[i] !== 0) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=fillEmptyMain.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
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './typeDef.js';
|
|
3
|
+
export * from './utils.js';
|
|
4
|
+
export * from './selvaBuffer.js';
|
|
5
|
+
export * from './createEmptyDef.js';
|
|
6
|
+
export * from './defaultMap.js';
|
|
7
|
+
export * from './validation.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// flap
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './typeDef.js';
|
|
4
|
+
export * from './utils.js';
|
|
5
|
+
export * from './selvaBuffer.js';
|
|
6
|
+
export * from './createEmptyDef.js';
|
|
7
|
+
export * from './defaultMap.js';
|
|
8
|
+
export * from './validation.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { REVERSE_SIZE_MAP } from './types.js';
|
|
2
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
|
+
import { VALIDATION_MAP } from './validation.js';
|
|
4
|
+
export const readFromPacked = (packed) => {
|
|
5
|
+
const size = (packed[0] | (packed[1] << 8)) >>> 0;
|
|
6
|
+
const props = [];
|
|
7
|
+
const b = packed.subarray(2, 2 + size);
|
|
8
|
+
let collectMain = false;
|
|
9
|
+
const mainProps = [];
|
|
10
|
+
const typeId = b.subarray(0, 2);
|
|
11
|
+
const typeIdNr = (typeId[0] | (typeId[1] << 8)) >>> 0;
|
|
12
|
+
for (let i = 2; i < b.length; i++) {
|
|
13
|
+
const prop = b[i];
|
|
14
|
+
if (collectMain) {
|
|
15
|
+
if (prop === 0) {
|
|
16
|
+
collectMain = false;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
mainProps.push({
|
|
20
|
+
prop: 0,
|
|
21
|
+
typeIndex: b[i],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (prop == 0) {
|
|
27
|
+
collectMain = true;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
props.push({ prop, typeIndex: b[i + 1] });
|
|
31
|
+
i++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const decoder = new TextDecoder();
|
|
36
|
+
const fields = [];
|
|
37
|
+
const f = packed.subarray(2 + size, packed.length);
|
|
38
|
+
for (let i = 0; i < f.length; i++) {
|
|
39
|
+
const size = f[i];
|
|
40
|
+
fields.push(decoder.decode(f.subarray(i + 1, i + 1 + size)));
|
|
41
|
+
i += size;
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < mainProps.length; i++) {
|
|
44
|
+
mainProps[i].path = fields[i + 1];
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < props.length; i++) {
|
|
47
|
+
props[i].path = fields[i + 1 + mainProps.length];
|
|
48
|
+
}
|
|
49
|
+
// Fixed len strings not supported
|
|
50
|
+
// Refs also not supported
|
|
51
|
+
// Text not supported yet
|
|
52
|
+
// Ref not supported yet
|
|
53
|
+
// compression: 1 (0)
|
|
54
|
+
const result = {
|
|
55
|
+
cnt: 0,
|
|
56
|
+
checksum: 0,
|
|
57
|
+
total: 0,
|
|
58
|
+
type: fields[0],
|
|
59
|
+
lastId: 0,
|
|
60
|
+
blockCapacity: 0,
|
|
61
|
+
mainLen: mainProps.length,
|
|
62
|
+
buf: b,
|
|
63
|
+
propNames: f,
|
|
64
|
+
packed,
|
|
65
|
+
props: {},
|
|
66
|
+
reverseProps: {}, // in a bit
|
|
67
|
+
id: typeIdNr,
|
|
68
|
+
idUint8: typeId,
|
|
69
|
+
separate: [],
|
|
70
|
+
main: {},
|
|
71
|
+
tree: {},
|
|
72
|
+
// not nessecary...
|
|
73
|
+
hasSeperateSort: false,
|
|
74
|
+
seperateSort: {
|
|
75
|
+
size: 0,
|
|
76
|
+
buffer: new Uint8Array([]),
|
|
77
|
+
bufferTmp: new Uint8Array([]),
|
|
78
|
+
props: [],
|
|
79
|
+
},
|
|
80
|
+
hasSeperateTextSort: false,
|
|
81
|
+
seperateTextSort: {
|
|
82
|
+
localeToIndex: new Map(),
|
|
83
|
+
localeStringToIndex: new Map(),
|
|
84
|
+
noUndefined: new Uint8Array([]),
|
|
85
|
+
size: 0,
|
|
86
|
+
buffer: new Uint8Array([]),
|
|
87
|
+
bufferTmp: new Uint8Array([]),
|
|
88
|
+
props: [],
|
|
89
|
+
},
|
|
90
|
+
mainEmpty: new Uint8Array([]),
|
|
91
|
+
mainEmptyAllZeroes: true,
|
|
92
|
+
// need this...
|
|
93
|
+
locales: {},
|
|
94
|
+
localeSize: 0,
|
|
95
|
+
};
|
|
96
|
+
let s = 0;
|
|
97
|
+
for (const p of mainProps) {
|
|
98
|
+
const len = REVERSE_SIZE_MAP[p.typeIndex];
|
|
99
|
+
const prop = {
|
|
100
|
+
prop: p.prop,
|
|
101
|
+
separate: false,
|
|
102
|
+
__isPropDef: true,
|
|
103
|
+
validation: VALIDATION_MAP[p.typeIndex],
|
|
104
|
+
start: s,
|
|
105
|
+
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
106
|
+
typeIndex: p.typeIndex,
|
|
107
|
+
path: p.path.split('.'),
|
|
108
|
+
len,
|
|
109
|
+
};
|
|
110
|
+
result.props[p.path] = prop;
|
|
111
|
+
result.main[prop.start] = prop;
|
|
112
|
+
s += len;
|
|
113
|
+
}
|
|
114
|
+
for (const p of props) {
|
|
115
|
+
const prop = {
|
|
116
|
+
prop: p.prop,
|
|
117
|
+
separate: true,
|
|
118
|
+
__isPropDef: true,
|
|
119
|
+
validation: VALIDATION_MAP[p.typeIndex],
|
|
120
|
+
start: 0,
|
|
121
|
+
typeIndex: p.typeIndex,
|
|
122
|
+
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
123
|
+
path: p.path.split('.'),
|
|
124
|
+
len: 0,
|
|
125
|
+
compression: 1,
|
|
126
|
+
};
|
|
127
|
+
result.props[p.path] = prop;
|
|
128
|
+
result.reverseProps[prop.prop] = prop;
|
|
129
|
+
}
|
|
130
|
+
// make this into a typeDef
|
|
131
|
+
// return {
|
|
132
|
+
// type: fields[0],
|
|
133
|
+
// fields,
|
|
134
|
+
// typeId,
|
|
135
|
+
// props,
|
|
136
|
+
// mainProps,
|
|
137
|
+
// }
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=readFromPacked.js.map
|