@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.
Files changed (49) hide show
  1. package/dist/def/addEdges.js +30 -3
  2. package/dist/def/createEmptyDef.d.ts +13 -9
  3. package/dist/def/createEmptyDef.js +7 -3
  4. package/dist/def/defaultMap.d.ts +3 -0
  5. package/dist/def/defaultMap.js +31 -0
  6. package/dist/def/fillEmptyMain.d.ts +2 -2
  7. package/dist/def/fillEmptyMain.js +14 -8
  8. package/dist/def/index.d.ts +2 -1
  9. package/dist/def/index.js +2 -1
  10. package/dist/def/makeSeparateSort.js +6 -6
  11. package/dist/def/makeSeparateTextSort.js +12 -12
  12. package/dist/def/refSet.d.ts +7 -0
  13. package/dist/def/refSet.js +25 -0
  14. package/dist/def/selvaBuffer.js +77 -28
  15. package/dist/def/typeDef.d.ts +9 -3
  16. package/dist/def/typeDef.js +143 -56
  17. package/dist/def/typeIndexes.d.ts +40 -0
  18. package/dist/def/typeIndexes.js +50 -0
  19. package/dist/def/types.d.ts +38 -60
  20. package/dist/def/types.js +24 -61
  21. package/dist/def/utils.d.ts +5 -3
  22. package/dist/def/utils.js +44 -2
  23. package/dist/def/validation.d.ts +7 -0
  24. package/dist/def/validation.js +261 -0
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +3 -1
  27. package/dist/infer.d.ts +82 -0
  28. package/dist/infer.js +5 -0
  29. package/dist/lang.d.ts +3 -1
  30. package/dist/lang.js +6 -0
  31. package/dist/parse/assert.d.ts +4 -0
  32. package/dist/parse/assert.js +19 -2
  33. package/dist/parse/index.d.ts +2 -0
  34. package/dist/parse/index.js +58 -4
  35. package/dist/parse/props.d.ts +1 -0
  36. package/dist/parse/props.js +171 -54
  37. package/dist/serialize.d.ts +14 -0
  38. package/dist/serialize.js +543 -0
  39. package/dist/types.d.ts +75 -19
  40. package/dist/types.js +3 -1
  41. package/package.json +7 -5
  42. package/dist/def/getPropLen.d.ts +0 -3
  43. package/dist/def/getPropLen.js +0 -23
  44. package/dist/def/makePacked.d.ts +0 -3
  45. package/dist/def/makePacked.js +0 -50
  46. package/dist/def/readFromPacked.d.ts +0 -3
  47. package/dist/def/readFromPacked.js +0 -137
  48. package/dist/mermaid.d.ts +0 -3
  49. package/dist/mermaid.js +0 -24
@@ -1,7 +1,11 @@
1
1
  import { getPropType } from '../index.js';
2
- import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, } from './types.js';
3
- import { getPropLen, isSeparate } from './utils.js';
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: TYPE_INDEX_MAP[edgeType],
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
- seperateSort: {
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
- seperateTextSort: {
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 '@saulx/hash';
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
- seperateSort: {
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
- seperateTextSort: {
34
+ separateTextSort: {
31
35
  size: 0, // prop len
32
36
  props: [],
33
37
  buffer: new Uint8Array([]),
@@ -0,0 +1,3 @@
1
+ import { TypeIndex } from './types.js';
2
+ export declare const DEFAULT_MAP: Record<TypeIndex, any>;
3
+ //# sourceMappingURL=defaultMap.d.ts.map
@@ -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 { BINARY, BOOLEAN, CREATED, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, UPDATED, } from './types.js';
2
- // Lets add validation of values in here - need to validate DEFAULT!
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 === BOOLEAN || t === INT8 || t === UINT8 || t === ENUM) {
14
- mainEmpty[s] = val === true ? 1 : 0;
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 === NUMBER ||
27
- t === TIMESTAMP ||
28
- t === CREATED ||
29
- t === UPDATED) {
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
  }
@@ -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.seperateSort.buffer = new Uint8Array(max + 1);
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.seperateSort.buffer[f.prop] = 1;
20
- result.seperateSort.props.push(f);
21
- result.seperateSort.size++;
19
+ result.separateSort.buffer[f.prop] = 1;
20
+ result.separateSort.props.push(f);
21
+ result.separateSort.size++;
22
22
  }
23
23
  }
24
- result.seperateSort.bufferTmp = new Uint8Array(max + 1);
25
- result.seperateSort.buffer.set(result.seperateSort.bufferTmp);
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.seperateTextSort.buffer = new Uint8Array(bufLen);
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.seperateTextSort.localeStringToIndex.set(code, new Uint8Array([index + 1, codeLang]));
19
- result.seperateTextSort.localeToIndex.set(codeLang, index + 1);
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.seperateTextSort.buffer[index] = result.localeSize;
26
- for (const [, locales] of result.seperateTextSort.localeStringToIndex) {
27
- result.seperateTextSort.buffer[locales[0] + index] = locales[1];
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.seperateTextSort.props.push(f);
30
- result.seperateTextSort.size += result.localeSize;
29
+ result.separateTextSort.props.push(f);
30
+ result.separateTextSort.size += result.localeSize;
31
31
  }
32
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);
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,7 @@
1
+ export default class RefSet {
2
+ #private;
3
+ add(srcType: number, srcField: number, dstType: number, dstField: number): boolean;
4
+ clear(): void;
5
+ values(): SetIterator<number>;
6
+ }
7
+ //# sourceMappingURL=refSet.d.ts.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
@@ -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] = 1;
4
- selvaTypeMap[VECTOR] = 1;
5
- selvaTypeMap[BINARY] = 2;
6
- selvaTypeMap[CARDINALITY] = 2;
7
- selvaTypeMap[JSON] = 2;
8
- selvaTypeMap[STRING] = 2;
9
- selvaTypeMap[TEXT] = 3;
10
- selvaTypeMap[REFERENCE] = 4;
11
- selvaTypeMap[REFERENCES] = 5;
12
- selvaTypeMap[WEAK_REFERENCE] = 6;
13
- selvaTypeMap[WEAK_REFERENCES] = 7;
14
- selvaTypeMap[ALIAS] = 8;
15
- selvaTypeMap[ALIASES] = 9;
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
- return prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00;
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
- return Object.values(schema).map((t, i) => {
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
- 1 + sepPropCount(props),
106
- 1 + refFields,
107
- ...propDefBuffer(schema, {
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
  }
@@ -1,7 +1,13 @@
1
1
  import { SchemaObject, StrictSchemaType, SchemaLocales } from '../index.js';
2
- import { SchemaTypeDef, SchemaTypesParsedById, SchemaTypesParsed } from './types.js';
2
+ import { SchemaTypeDef, SchemaTypesParsed } from './types.js';
3
3
  import { StrictSchema } from '../types.js';
4
- export declare const DEFAULT_BLOCK_CAPACITY = 100000;
5
- export declare const updateTypeDefs: (schema: StrictSchema, schemaTypesParsed: SchemaTypesParsed, schemaTypesParsedById: SchemaTypesParsedById) => void;
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