@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,53 +1,108 @@
1
1
  import { isPropType, getPropType, } from '../index.js';
2
- import { setByPath } from '@saulx/utils';
3
- import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, DEFAULT_MAP, } from './types.js';
4
- import { makePacked } from './makePacked.js';
2
+ import { setByPath } from '@based/utils';
3
+ import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, BLOCK_CAPACITY_MAX, BLOCK_CAPACITY_DEFAULT, BLOCK_CAPACITY_MIN, ALIAS, ALIASES, VECTOR, COLVEC, } from './types.js';
4
+ import { DEFAULT_MAP } from './defaultMap.js';
5
5
  import { makeSeparateTextSort } from './makeSeparateTextSort.js';
6
6
  import { makeSeparateSort } from './makeSeparateSort.js';
7
- import { getPropLen } from './getPropLen.js';
8
- import { isSeparate } from './utils.js';
7
+ import { getPropLen, isSeparate, parseMinMaxStep, schemaVectorBaseTypeToEnum, } from './utils.js';
9
8
  import { addEdges } from './addEdges.js';
10
9
  import { createEmptyDef } from './createEmptyDef.js';
11
- import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
12
10
  import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
13
- export const DEFAULT_BLOCK_CAPACITY = 100_000;
14
- export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById) => {
15
- for (const field in schemaTypesParsed) {
16
- if (field in schema.types) {
11
+ import { defaultValidation, VALIDATION_MAP } from './validation.js';
12
+ export const updateTypeDefs = (schema) => {
13
+ const schemaTypesParsed = {};
14
+ const schemaTypesParsedById = {};
15
+ for (const typeName in schemaTypesParsed) {
16
+ if (typeName in schema.types) {
17
17
  continue;
18
18
  }
19
- const id = schemaTypesParsed[field].id;
20
- delete schemaTypesParsed[field];
19
+ const id = schemaTypesParsed[typeName].id;
20
+ delete schemaTypesParsed[typeName];
21
21
  delete schemaTypesParsedById[id];
22
22
  }
23
- for (const field in schema.types) {
24
- const type = schema.types[field];
25
- if (schemaTypesParsed[field] &&
26
- schemaTypesParsed[field].checksum === hashObjectIgnoreKeyOrder(type) // bit weird..
27
- ) {
28
- continue;
23
+ for (const typeName in schema.types) {
24
+ const type = schema.types[typeName];
25
+ if (!type.id) {
26
+ throw new Error('NEED ID ON TYPE');
29
27
  }
30
- else {
31
- if (!type.id) {
32
- throw new Error('NEED ID ON TYPE');
28
+ const def = createSchemaTypeDef(typeName, type, schemaTypesParsed, schema.locales ?? {
29
+ en: {},
30
+ });
31
+ schemaTypesParsed[typeName] = def;
32
+ schemaTypesParsedById[type.id] = def;
33
+ }
34
+ // Update inverseProps in references
35
+ for (const schema of Object.values(schemaTypesParsed)) {
36
+ for (const prop of Object.values(schema.props)) {
37
+ if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
38
+ if (!prop.__isEdge) {
39
+ const dstType = schemaTypesParsed[prop.inverseTypeName];
40
+ prop.inverseTypeId = dstType.id;
41
+ prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
42
+ }
33
43
  }
34
- const def = createSchemaTypeDef(field, type, schemaTypesParsed, schema.locales ?? {
35
- en: {},
36
- });
37
- def.blockCapacity =
38
- field === '_root' ? 2147483647 : DEFAULT_BLOCK_CAPACITY; // TODO this should come from somewhere else
39
- schemaTypesParsed[field] = def;
40
- schemaTypesParsedById[type.id] = def;
41
44
  }
42
45
  }
46
+ return { schemaTypesParsed, schemaTypesParsedById };
43
47
  };
48
+ function propIndexOffset(prop) {
49
+ if (!prop.separate) {
50
+ return 0;
51
+ }
52
+ switch (prop.typeIndex) {
53
+ case REFERENCES:
54
+ case REFERENCE:
55
+ return -300;
56
+ case ALIAS:
57
+ case ALIASES:
58
+ case COLVEC:
59
+ return 300;
60
+ default:
61
+ return 0;
62
+ }
63
+ }
64
+ function reorderProps(props) {
65
+ props.sort((a, b) => a.prop + propIndexOffset(a) - (b.prop + propIndexOffset(b)));
66
+ // Reassign prop indices
67
+ let lastProp = 0;
68
+ for (const p of props) {
69
+ if (p.separate) {
70
+ p.prop = ++lastProp;
71
+ }
72
+ }
73
+ }
44
74
  export const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
45
- if (result.id == 0 && top) {
46
- if ('id' in type) {
47
- result.id = type.id;
75
+ if (top) {
76
+ if (result.id == 0) {
77
+ if ('id' in type) {
78
+ result.id = type.id;
79
+ }
80
+ else {
81
+ throw new Error(`Invalid schema type id ${result.type}`);
82
+ }
48
83
  }
49
- else {
50
- throw new Error(`Invalid schema type id ${result.type}`);
84
+ if (result.blockCapacity == 0) {
85
+ if ('blockCapacity' in type) {
86
+ if (typeof type.blockCapacity !== 'number' ||
87
+ type.blockCapacity < BLOCK_CAPACITY_MIN ||
88
+ type.blockCapacity > BLOCK_CAPACITY_MAX) {
89
+ throw new Error('Invalid blockCapacity');
90
+ }
91
+ result.blockCapacity = type.blockCapacity;
92
+ }
93
+ else {
94
+ result.blockCapacity =
95
+ typeName === '_root' ? BLOCK_CAPACITY_MAX : BLOCK_CAPACITY_DEFAULT;
96
+ }
97
+ }
98
+ if (result.insertOnly == false && 'insertOnly' in type) {
99
+ result.insertOnly = !!type.insertOnly;
100
+ }
101
+ if (result.partial == false && 'partial' in type) {
102
+ result.partial = !!type.partial;
103
+ }
104
+ if ('hooks' in type) {
105
+ result.hooks = type.hooks;
51
106
  }
52
107
  }
53
108
  result.locales = locales;
@@ -55,8 +110,6 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
55
110
  result.idUint8[0] = result.id & 255;
56
111
  result.idUint8[1] = result.id >> 8;
57
112
  const target = type.props;
58
- let separateSortProps = 0;
59
- let separateSortText = 0;
60
113
  for (const key in target) {
61
114
  // Create prop def
62
115
  const schemaProp = target[key];
@@ -73,27 +126,51 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
73
126
  if (typeof schemaProp === 'object') {
74
127
  if (!(schemaProp.maxBytes < 61) ||
75
128
  !('max' in schemaProp && schemaProp.max < 31)) {
76
- separateSortProps++;
129
+ result.separateSortProps++;
77
130
  }
78
131
  }
79
132
  else {
80
- separateSortProps++;
133
+ result.separateSortProps++;
81
134
  }
82
135
  }
83
136
  else if (isPropType('text', schemaProp)) {
84
- separateSortText++;
137
+ result.separateSortText++;
138
+ }
139
+ else if (isPropType('colvec', schemaProp)) {
140
+ if (!result.insertOnly) {
141
+ throw new Error('colvec requires insertOnly');
142
+ }
85
143
  }
86
144
  const isseparate = isSeparate(schemaProp, len);
145
+ const typeIndex = TYPE_INDEX_MAP[propType];
87
146
  const prop = {
88
- typeIndex: TYPE_INDEX_MAP[propType],
147
+ typeIndex,
89
148
  __isPropDef: true,
90
149
  separate: isseparate,
91
150
  path: propPath,
92
151
  start: 0,
152
+ validation: schemaProp.validation ??
153
+ VALIDATION_MAP[typeIndex] ??
154
+ defaultValidation,
93
155
  len,
94
- default: schemaProp.default ?? DEFAULT_MAP[TYPE_INDEX_MAP[propType]],
156
+ default: schemaProp.default ?? DEFAULT_MAP[typeIndex],
95
157
  prop: isseparate ? ++result.cnt : 0,
96
158
  };
159
+ if (schemaProp.max !== undefined) {
160
+ prop.max = parseMinMaxStep(schemaProp.max);
161
+ }
162
+ if (schemaProp.min !== undefined) {
163
+ prop.min = parseMinMaxStep(schemaProp.min);
164
+ }
165
+ if (schemaProp.step !== undefined) {
166
+ prop.step = parseMinMaxStep(schemaProp.step);
167
+ }
168
+ if (prop.typeIndex !== NUMBER && prop.step === undefined) {
169
+ prop.step = 1;
170
+ }
171
+ if (prop.typeIndex === VECTOR || prop.typeIndex === COLVEC) {
172
+ prop.vectorBaseType = schemaVectorBaseTypeToEnum(schemaProp.baseType ?? 'number');
173
+ }
97
174
  if (isPropType('enum', schemaProp)) {
98
175
  prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
99
176
  prop.reverseEnum = {};
@@ -102,12 +179,18 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
102
179
  }
103
180
  }
104
181
  else if (isPropType('references', schemaProp)) {
182
+ if (result.partial) {
183
+ throw new Error('references is not supported with partial');
184
+ }
105
185
  prop.inversePropName = schemaProp.items.prop;
106
186
  prop.inverseTypeName = schemaProp.items.ref;
107
187
  prop.dependent = schemaProp.items.dependent;
108
188
  addEdges(prop, schemaProp.items);
109
189
  }
110
190
  else if (isPropType('reference', schemaProp)) {
191
+ if (result.partial) {
192
+ throw new Error('reference is not supported with partial');
193
+ }
111
194
  prop.inversePropName = schemaProp.prop;
112
195
  prop.inverseTypeName = schemaProp.ref;
113
196
  prop.dependent = schemaProp.dependent;
@@ -143,24 +226,26 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
143
226
  if (top) {
144
227
  // Put top level together
145
228
  const vals = Object.values(result.props);
146
- vals.sort((a, b) => {
147
- if (b.separate &&
148
- (a.typeIndex === REFERENCES || a.typeIndex === REFERENCE)) {
149
- return -1;
150
- }
151
- return a.prop - b.prop;
152
- });
153
- let lastProp = 0;
154
- for (const p of vals) {
155
- if (p.separate) {
156
- p.prop = ++lastProp;
157
- }
158
- }
229
+ reorderProps(vals);
159
230
  let len = 2;
231
+ let biggestSeperatePropDefault = 0;
160
232
  for (const f of vals) {
161
233
  if (f.separate) {
162
234
  len += 2;
163
235
  setByPath(result.tree, f.path, f);
236
+ if (f.default !== undefined) {
237
+ result.hasSeperateDefaults = true;
238
+ if (!result.separateDefaults) {
239
+ result.separateDefaults = {
240
+ props: new Map(),
241
+ bufferTmp: new Uint8Array(),
242
+ };
243
+ }
244
+ result.separateDefaults.props.set(f.prop, f);
245
+ if (f.prop > biggestSeperatePropDefault) {
246
+ biggestSeperatePropDefault = f.prop;
247
+ }
248
+ }
164
249
  }
165
250
  else {
166
251
  if (!result.mainLen) {
@@ -172,13 +257,15 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
172
257
  setByPath(result.tree, f.path, f);
173
258
  }
174
259
  }
260
+ if (result.hasSeperateDefaults) {
261
+ result.separateDefaults.bufferTmp = new Uint8Array(biggestSeperatePropDefault + 1);
262
+ }
175
263
  result.mainEmpty = fillEmptyMain(vals, result.mainLen);
176
264
  result.mainEmptyAllZeroes = isZeroes(result.mainEmpty);
177
- makePacked(result, typeName, vals, len);
178
- if (separateSortText > 0) {
265
+ if (result.separateSortText > 0) {
179
266
  makeSeparateTextSort(result);
180
267
  }
181
- if (separateSortProps > 0) {
268
+ if (result.separateSortProps > 0) {
182
269
  makeSeparateSort(result);
183
270
  }
184
271
  for (const p in result.props) {
@@ -0,0 +1,40 @@
1
+ export declare const NULL = 0;
2
+ export declare const TIMESTAMP = 1;
3
+ export declare const NUMBER = 4;
4
+ export declare const CARDINALITY = 5;
5
+ export declare const INT8 = 20;
6
+ export declare const UINT8 = 6;
7
+ export declare const INT16 = 21;
8
+ export declare const UINT16 = 22;
9
+ export declare const INT32 = 23;
10
+ export declare const UINT32 = 7;
11
+ export declare const BOOLEAN = 9;
12
+ export declare const ENUM = 10;
13
+ export declare const STRING = 11;
14
+ export declare const TEXT = 12;
15
+ export declare const REFERENCE = 13;
16
+ export declare const REFERENCES = 14;
17
+ export declare const WEAK_REFERENCE = 15;
18
+ export declare const WEAK_REFERENCES = 16;
19
+ export declare const MICRO_BUFFER = 17;
20
+ export declare const ALIAS = 18;
21
+ export declare const ALIASES = 19;
22
+ export declare const BINARY = 25;
23
+ export declare const ID = 26;
24
+ export declare const VECTOR = 27;
25
+ export declare const JSON = 28;
26
+ export declare const OBJECT = 29;
27
+ export declare const COLVEC = 30;
28
+ export type TypeIndex = typeof NULL | typeof TIMESTAMP | typeof NUMBER | typeof CARDINALITY | typeof INT8 | typeof UINT8 | typeof INT16 | typeof UINT16 | typeof INT32 | typeof UINT32 | typeof BOOLEAN | typeof ENUM | typeof STRING | typeof TEXT | typeof REFERENCE | typeof REFERENCES | typeof WEAK_REFERENCE | typeof WEAK_REFERENCES | typeof MICRO_BUFFER | typeof ALIAS | typeof ALIASES | typeof BINARY | typeof ID | typeof VECTOR | typeof JSON | typeof OBJECT | typeof COLVEC;
29
+ export declare enum VectorBaseType {
30
+ Int8 = 1,
31
+ Uint8 = 2,
32
+ Int16 = 3,
33
+ Uint16 = 4,
34
+ Int32 = 5,
35
+ Uint32 = 6,
36
+ Float32 = 7,
37
+ Float64 = 8
38
+ }
39
+ export declare const isNumberType: (type: TypeIndex) => boolean;
40
+ //# sourceMappingURL=typeIndexes.d.ts.map
@@ -0,0 +1,50 @@
1
+ // WARN: The following type codes are used in js and zig but selva has its own typing.
2
+ export const NULL = 0;
3
+ export const TIMESTAMP = 1;
4
+ export const NUMBER = 4;
5
+ export const CARDINALITY = 5;
6
+ export const INT8 = 20;
7
+ export const UINT8 = 6;
8
+ export const INT16 = 21;
9
+ export const UINT16 = 22;
10
+ export const INT32 = 23;
11
+ export const UINT32 = 7;
12
+ export const BOOLEAN = 9;
13
+ export const ENUM = 10;
14
+ export const STRING = 11;
15
+ export const TEXT = 12;
16
+ export const REFERENCE = 13;
17
+ export const REFERENCES = 14;
18
+ export const WEAK_REFERENCE = 15;
19
+ export const WEAK_REFERENCES = 16;
20
+ export const MICRO_BUFFER = 17;
21
+ export const ALIAS = 18;
22
+ export const ALIASES = 19;
23
+ export const BINARY = 25;
24
+ export const ID = 26;
25
+ export const VECTOR = 27;
26
+ export const JSON = 28;
27
+ export const OBJECT = 29;
28
+ export const COLVEC = 30;
29
+ export var VectorBaseType;
30
+ (function (VectorBaseType) {
31
+ VectorBaseType[VectorBaseType["Int8"] = 1] = "Int8";
32
+ VectorBaseType[VectorBaseType["Uint8"] = 2] = "Uint8";
33
+ VectorBaseType[VectorBaseType["Int16"] = 3] = "Int16";
34
+ VectorBaseType[VectorBaseType["Uint16"] = 4] = "Uint16";
35
+ VectorBaseType[VectorBaseType["Int32"] = 5] = "Int32";
36
+ VectorBaseType[VectorBaseType["Uint32"] = 6] = "Uint32";
37
+ VectorBaseType[VectorBaseType["Float32"] = 7] = "Float32";
38
+ VectorBaseType[VectorBaseType["Float64"] = 8] = "Float64";
39
+ })(VectorBaseType || (VectorBaseType = {}));
40
+ export const isNumberType = (type) => {
41
+ return (type === NUMBER ||
42
+ type === UINT16 ||
43
+ type === UINT32 ||
44
+ type === INT16 ||
45
+ type === INT32 ||
46
+ type == UINT8 ||
47
+ type === INT8 ||
48
+ type === CARDINALITY);
49
+ };
50
+ //# sourceMappingURL=typeIndexes.js.map
@@ -1,59 +1,19 @@
1
- import type { LangCode, SchemaLocales } from '../index.js';
2
- export declare const NULL = 0;
3
- export declare const TIMESTAMP = 1;
4
- export declare const CREATED = 2;
5
- export declare const UPDATED = 3;
6
- export declare const NUMBER = 4;
7
- export declare const CARDINALITY = 5;
8
- export declare const INT8 = 20;
9
- export declare const UINT8 = 6;
10
- export declare const INT16 = 21;
11
- export declare const UINT16 = 22;
12
- export declare const INT32 = 23;
13
- export declare const UINT32 = 7;
14
- export declare const BOOLEAN = 9;
15
- export declare const ENUM = 10;
16
- export declare const STRING = 11;
17
- export declare const TEXT = 12;
18
- export declare const REFERENCE = 13;
19
- export declare const REFERENCES = 14;
20
- export declare const WEAK_REFERENCE = 15;
21
- export declare const WEAK_REFERENCES = 16;
22
- export declare const MICRO_BUFFER = 17;
23
- export declare const ALIAS = 18;
24
- export declare const ALIASES = 19;
25
- export declare const BINARY = 25;
26
- export declare const ID = 26;
27
- export declare const VECTOR = 27;
28
- export declare const JSON = 28;
29
- export declare const TYPE_INDEX_MAP: {
30
- alias: number;
31
- aliases: number;
32
- microbuffer: number;
33
- references: number;
34
- reference: number;
35
- timestamp: number;
36
- boolean: number;
37
- created: number;
38
- updated: number;
39
- number: number;
40
- string: number;
41
- text: number;
42
- uint16: number;
43
- uint32: number;
44
- int16: number;
45
- int32: number;
46
- uint8: number;
47
- enum: number;
48
- int8: number;
49
- id: number;
50
- binary: number;
51
- vector: number;
52
- cardinality: number;
53
- json: number;
54
- };
1
+ import type { LangCode, SchemaHooks, SchemaLocales } from '../index.js';
2
+ import { Validation } from './validation.js';
3
+ import { TypeIndex, VectorBaseType } from './typeIndexes.js';
4
+ export * from './typeIndexes.js';
5
+ export declare const TYPE_INDEX_MAP: Record<string, TypeIndex>;
6
+ export declare const enum numberTypes {
7
+ number = 4,
8
+ uint16 = 22,
9
+ uint32 = 7,
10
+ int16 = 21,
11
+ int32 = 23,
12
+ uint8 = 6,
13
+ int8 = 20,
14
+ cardinality = 5
15
+ }
55
16
  export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
56
- export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
57
17
  export type PropDef = {
58
18
  __isPropDef: true;
59
19
  prop: number;
@@ -69,8 +29,12 @@ export type PropDef = {
69
29
  inversePropNumber?: number;
70
30
  enum?: any[];
71
31
  dependent?: boolean;
32
+ validation: Validation;
72
33
  default: any;
34
+ vectorBaseType?: VectorBaseType;
35
+ vectorSize?: number;
73
36
  edgeMainLen?: 0;
37
+ hasDefaultEdges?: boolean;
74
38
  reverseEnum?: {
75
39
  [key: string]: number;
76
40
  };
@@ -86,6 +50,9 @@ export type PropDef = {
86
50
  };
87
51
  edgeMainEmpty?: Uint8Array;
88
52
  __isEdge?: boolean;
53
+ max?: any;
54
+ min?: any;
55
+ step?: any;
89
56
  };
90
57
  export type PropDefEdge = Partial<PropDef> & {
91
58
  __isPropDef: true;
@@ -112,17 +79,20 @@ export type SchemaSortUndefinedHandler = {
112
79
  bufferTmp: Uint8Array;
113
80
  props: PropDef[];
114
81
  };
82
+ export declare const BLOCK_CAPACITY_MIN = 1025;
83
+ export declare const BLOCK_CAPACITY_MAX = 2147483647;
84
+ export declare const BLOCK_CAPACITY_DEFAULT = 100000;
115
85
  export type SchemaTypeDef = {
116
86
  cnt: number;
117
87
  checksum: number;
118
- total: number;
119
88
  type: string;
120
89
  lastId: number;
121
90
  blockCapacity: number;
122
91
  mainLen: number;
92
+ insertOnly: boolean;
93
+ partial: boolean;
123
94
  buf: Uint8Array;
124
95
  propNames: Uint8Array;
125
- packed: Uint8Array;
126
96
  props: {
127
97
  [path: string]: PropDef;
128
98
  };
@@ -138,21 +108,29 @@ export type SchemaTypeDef = {
138
108
  mainEmpty: Uint8Array;
139
109
  mainEmptyAllZeroes: boolean;
140
110
  tree: SchemaPropTree;
111
+ separateSortProps: number;
112
+ separateSortText: number;
141
113
  hasSeperateSort: boolean;
142
- seperateSort: SchemaSortUndefinedHandler;
114
+ separateSort: SchemaSortUndefinedHandler;
143
115
  hasSeperateTextSort: boolean;
144
- seperateTextSort: SchemaSortUndefinedHandler & {
116
+ separateTextSort: SchemaSortUndefinedHandler & {
145
117
  noUndefined: Uint8Array;
146
118
  localeStringToIndex: Map<string, Uint8Array>;
147
119
  localeToIndex: Map<LangCode, number>;
148
120
  };
121
+ hasSeperateDefaults: boolean;
122
+ separateDefaults?: {
123
+ props: Map<number, PropDef>;
124
+ bufferTmp: Uint8Array;
125
+ };
149
126
  createTs?: PropDef[];
150
127
  updateTs?: PropDef[];
151
128
  locales: Partial<SchemaLocales>;
152
129
  localeSize: number;
130
+ hooks?: SchemaHooks;
153
131
  };
132
+ export declare const VECTOR_BASE_TYPE_SIZE_MAP: Record<VectorBaseType, number>;
154
133
  export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
155
- export declare const DEFAULT_MAP: Record<TypeIndex, any>;
156
134
  export declare const REVERSE_SIZE_MAP: Record<TypeIndex, number>;
157
135
  export declare const REVERSE_TYPE_INDEX_MAP: Record<TypeIndex, InternalSchemaProp>;
158
136
  export declare const ID_FIELD_DEF: PropDef;
package/dist/def/types.js CHANGED
@@ -1,31 +1,5 @@
1
- // WARN: The following type codes are used in js and zig but selva has its own typing.
2
- export const NULL = 0;
3
- export const TIMESTAMP = 1;
4
- export const CREATED = 2;
5
- export const UPDATED = 3;
6
- export const NUMBER = 4;
7
- export const CARDINALITY = 5;
8
- export const INT8 = 20;
9
- export const UINT8 = 6;
10
- export const INT16 = 21;
11
- export const UINT16 = 22;
12
- export const INT32 = 23;
13
- export const UINT32 = 7;
14
- export const BOOLEAN = 9;
15
- export const ENUM = 10;
16
- export const STRING = 11;
17
- export const TEXT = 12;
18
- export const REFERENCE = 13;
19
- export const REFERENCES = 14;
20
- export const WEAK_REFERENCE = 15;
21
- export const WEAK_REFERENCES = 16;
22
- export const MICRO_BUFFER = 17;
23
- export const ALIAS = 18;
24
- export const ALIASES = 19;
25
- export const BINARY = 25;
26
- export const ID = 26;
27
- export const VECTOR = 27;
28
- export const JSON = 28;
1
+ import { ALIAS, ALIASES, BINARY, BOOLEAN, CARDINALITY, COLVEC, ENUM, INT16, INT32, INT8, JSON, MICRO_BUFFER, NULL, NUMBER, OBJECT, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, VectorBaseType, } from './typeIndexes.js';
2
+ export * from './typeIndexes.js';
29
3
  export const TYPE_INDEX_MAP = {
30
4
  alias: ALIAS,
31
5
  aliases: ALIASES,
@@ -34,8 +8,6 @@ export const TYPE_INDEX_MAP = {
34
8
  reference: REFERENCE,
35
9
  timestamp: TIMESTAMP,
36
10
  boolean: BOOLEAN,
37
- created: CREATED,
38
- updated: UPDATED,
39
11
  number: NUMBER,
40
12
  string: STRING,
41
13
  text: TEXT,
@@ -51,11 +23,24 @@ export const TYPE_INDEX_MAP = {
51
23
  vector: VECTOR,
52
24
  cardinality: CARDINALITY,
53
25
  json: JSON,
26
+ object: OBJECT,
27
+ colvec: COLVEC,
28
+ };
29
+ export const BLOCK_CAPACITY_MIN = 1025;
30
+ export const BLOCK_CAPACITY_MAX = 2147483647;
31
+ export const BLOCK_CAPACITY_DEFAULT = 100_000;
32
+ export const VECTOR_BASE_TYPE_SIZE_MAP = {
33
+ [VectorBaseType.Int8]: 1,
34
+ [VectorBaseType.Uint8]: 1,
35
+ [VectorBaseType.Int16]: 2,
36
+ [VectorBaseType.Uint16]: 2,
37
+ [VectorBaseType.Int32]: 4,
38
+ [VectorBaseType.Uint32]: 4,
39
+ [VectorBaseType.Float32]: 4,
40
+ [VectorBaseType.Float64]: 8,
54
41
  };
55
42
  export const SIZE_MAP = {
56
43
  timestamp: 8, // 64bit
57
- created: 8,
58
- updated: 8,
59
44
  // double-precision 64-bit binary format IEEE 754 value
60
45
  number: 8, // 64bit
61
46
  int8: 1,
@@ -78,61 +63,39 @@ export const SIZE_MAP = {
78
63
  binary: 0,
79
64
  vector: 0, // separate
80
65
  json: 0,
66
+ object: 0,
67
+ colvec: 0, // separate
81
68
  };
82
69
  const reverseMap = {};
83
70
  for (const k in TYPE_INDEX_MAP) {
84
71
  reverseMap[TYPE_INDEX_MAP[k]] = k;
85
72
  }
86
- // TODO update defaults
87
- export const DEFAULT_MAP = {
88
- [TYPE_INDEX_MAP.alias]: '',
89
- [TYPE_INDEX_MAP.binary]: undefined,
90
- [TYPE_INDEX_MAP.boolean]: false,
91
- [TYPE_INDEX_MAP.cardinality]: 0,
92
- [TYPE_INDEX_MAP.created]: 0,
93
- [TYPE_INDEX_MAP.updated]: 0,
94
- [TYPE_INDEX_MAP.number]: 0,
95
- [TYPE_INDEX_MAP.timestamp]: 0,
96
- [TYPE_INDEX_MAP.enum]: 0,
97
- [TYPE_INDEX_MAP.id]: 0,
98
- [TYPE_INDEX_MAP.int16]: 0,
99
- [TYPE_INDEX_MAP.int32]: 0,
100
- [TYPE_INDEX_MAP.int8]: 0,
101
- [TYPE_INDEX_MAP.uint8]: 0,
102
- [TYPE_INDEX_MAP.uint16]: 0,
103
- [TYPE_INDEX_MAP.uint32]: 0,
104
- [TYPE_INDEX_MAP.json]: undefined,
105
- [TYPE_INDEX_MAP.microbuffer]: undefined,
106
- [TYPE_INDEX_MAP.reference]: undefined,
107
- [TYPE_INDEX_MAP.references]: [],
108
- [TYPE_INDEX_MAP.string]: '',
109
- [TYPE_INDEX_MAP.aliases]: [],
110
- [TYPE_INDEX_MAP.text]: '',
111
- [TYPE_INDEX_MAP.vector]: undefined, // maybe not can set a vec with 0
112
- };
73
+ // @ts-ignore
113
74
  export const REVERSE_SIZE_MAP = {};
114
75
  for (const k in SIZE_MAP) {
115
76
  REVERSE_SIZE_MAP[TYPE_INDEX_MAP[k]] = SIZE_MAP[k];
116
77
  }
117
78
  export const REVERSE_TYPE_INDEX_MAP = reverseMap;
118
79
  export const ID_FIELD_DEF = {
119
- typeIndex: TYPE_INDEX_MAP['id'],
80
+ typeIndex: NULL,
120
81
  separate: true,
121
82
  path: ['id'],
122
83
  start: 0,
123
84
  prop: 255,
124
85
  default: 0,
125
86
  len: 4,
87
+ validation: () => true,
126
88
  __isPropDef: true,
127
89
  };
128
90
  export const EMPTY_MICRO_BUFFER = {
129
- typeIndex: TYPE_INDEX_MAP['microbuffer'],
91
+ typeIndex: MICRO_BUFFER,
130
92
  separate: true,
131
93
  path: [''],
132
94
  start: 0,
133
95
  default: undefined,
134
96
  prop: 0,
135
97
  len: 1,
98
+ validation: () => true,
136
99
  __isPropDef: true,
137
100
  };
138
101
  export const getPropTypeName = (propType) => {
@@ -1,7 +1,9 @@
1
- import { PropDef, PropDefEdge } from './types.js';
2
- import { SchemaProp } from '../types.js';
1
+ import { PropDef, PropDefEdge, VectorBaseType } from './types.js';
2
+ import { SchemaProp, SchemaVectorBaseType } from '../types.js';
3
3
  export declare function isSeparate(schemaProp: SchemaProp, len: number): boolean;
4
4
  export declare const propIsSigned: (prop: PropDef | PropDefEdge) => boolean;
5
5
  export declare const propIsNumerical: (prop: PropDef | PropDefEdge) => boolean;
6
- export declare function getPropLen(schemaProp: SchemaProp): any;
6
+ export declare const schemaVectorBaseTypeToEnum: (vector: SchemaVectorBaseType) => VectorBaseType;
7
+ export declare function getPropLen(schemaProp: SchemaProp): number;
8
+ export declare const parseMinMaxStep: (val: any) => string | number;
7
9
  //# sourceMappingURL=utils.d.ts.map