@based/schema 5.0.0-alpha.11 → 5.0.0-alpha.13
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/createEmptyDef.d.ts +2 -0
- package/dist/def/createEmptyDef.js +2 -0
- package/dist/def/index.d.ts +0 -1
- package/dist/def/index.js +0 -1
- package/dist/def/selvaBuffer.js +7 -3
- package/dist/def/typeDef.js +5 -9
- package/dist/def/types.d.ts +13 -1
- package/dist/def/types.js +13 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/parse/assert.js +1 -2
- package/dist/serialize.js +4 -1
- package/package.json +2 -2
package/dist/def/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ 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';
|
|
7
6
|
export * from './defaultMap.js';
|
|
8
7
|
export * from './validation.js';
|
package/dist/def/index.js
CHANGED
|
@@ -3,7 +3,6 @@ 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';
|
|
8
7
|
export * from './defaultMap.js';
|
|
9
8
|
export * from './validation.js';
|
package/dist/def/selvaBuffer.js
CHANGED
|
@@ -14,6 +14,7 @@ selvaTypeMap[WEAK_REFERENCES] = 7;
|
|
|
14
14
|
selvaTypeMap[ALIAS] = 8;
|
|
15
15
|
selvaTypeMap[ALIASES] = 9;
|
|
16
16
|
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
17
|
+
const EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP = 0x80;
|
|
17
18
|
function blockCapacity(blockCapacity) {
|
|
18
19
|
const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
|
|
19
20
|
const view = new DataView(buf.buffer);
|
|
@@ -23,8 +24,11 @@ function blockCapacity(blockCapacity) {
|
|
|
23
24
|
function sepPropCount(props) {
|
|
24
25
|
return props.filter((prop) => prop.separate).length;
|
|
25
26
|
}
|
|
26
|
-
function makeEdgeConstraintFlags(prop) {
|
|
27
|
-
return prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00
|
|
27
|
+
function makeEdgeConstraintFlags(prop, inverseProp) {
|
|
28
|
+
return ((prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00) |
|
|
29
|
+
(prop.typeIndex === REFERENCE && inverseProp && inverseProp.typeIndex === REFERENCES
|
|
30
|
+
? EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP
|
|
31
|
+
: 0x00));
|
|
28
32
|
}
|
|
29
33
|
const propDefBuffer = (schema, prop, isEdge) => {
|
|
30
34
|
const type = prop.typeIndex;
|
|
@@ -43,7 +47,7 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
43
47
|
let eschema = [];
|
|
44
48
|
// @ts-ignore
|
|
45
49
|
buf[0] = selvaType + 2 * !!isEdge; // field type
|
|
46
|
-
buf[1] = makeEdgeConstraintFlags(prop); // flags
|
|
50
|
+
buf[1] = makeEdgeConstraintFlags(prop, dstType.props[prop.inversePropName]); // flags
|
|
47
51
|
view.setUint16(2, dstType.id, true); // dst_node_type
|
|
48
52
|
view.setUint32(5, 0, true); // schema_len
|
|
49
53
|
if (!isEdge) {
|
package/dist/def/typeDef.js
CHANGED
|
@@ -2,7 +2,6 @@ import { isPropType, getPropType, } from '../index.js';
|
|
|
2
2
|
import { setByPath } from '@saulx/utils';
|
|
3
3
|
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, } from './types.js';
|
|
4
4
|
import { DEFAULT_MAP } from './defaultMap.js';
|
|
5
|
-
import { makePacked } from './makePacked.js';
|
|
6
5
|
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
7
6
|
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
8
7
|
import { getPropLen } from './getPropLen.js';
|
|
@@ -58,8 +57,6 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
58
57
|
result.idUint8[0] = result.id & 255;
|
|
59
58
|
result.idUint8[1] = result.id >> 8;
|
|
60
59
|
const target = type.props;
|
|
61
|
-
let separateSortProps = 0;
|
|
62
|
-
let separateSortText = 0;
|
|
63
60
|
for (const key in target) {
|
|
64
61
|
// Create prop def
|
|
65
62
|
const schemaProp = target[key];
|
|
@@ -76,15 +73,15 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
76
73
|
if (typeof schemaProp === 'object') {
|
|
77
74
|
if (!(schemaProp.maxBytes < 61) ||
|
|
78
75
|
!('max' in schemaProp && schemaProp.max < 31)) {
|
|
79
|
-
separateSortProps++;
|
|
76
|
+
result.separateSortProps++;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
else {
|
|
83
|
-
separateSortProps++;
|
|
80
|
+
result.separateSortProps++;
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
else if (isPropType('text', schemaProp)) {
|
|
87
|
-
separateSortText++;
|
|
84
|
+
result.separateSortText++;
|
|
88
85
|
}
|
|
89
86
|
const isseparate = isSeparate(schemaProp, len);
|
|
90
87
|
const typeIndex = TYPE_INDEX_MAP[propType];
|
|
@@ -193,11 +190,10 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
193
190
|
}
|
|
194
191
|
result.mainEmpty = fillEmptyMain(vals, result.mainLen);
|
|
195
192
|
result.mainEmptyAllZeroes = isZeroes(result.mainEmpty);
|
|
196
|
-
|
|
197
|
-
if (separateSortText > 0) {
|
|
193
|
+
if (result.separateSortText > 0) {
|
|
198
194
|
makeSeparateTextSort(result);
|
|
199
195
|
}
|
|
200
|
-
if (separateSortProps > 0) {
|
|
196
|
+
if (result.separateSortProps > 0) {
|
|
201
197
|
makeSeparateSort(result);
|
|
202
198
|
}
|
|
203
199
|
for (const p in result.props) {
|
package/dist/def/types.d.ts
CHANGED
|
@@ -51,6 +51,17 @@ export declare const TYPE_INDEX_MAP: {
|
|
|
51
51
|
json: number;
|
|
52
52
|
object: number;
|
|
53
53
|
};
|
|
54
|
+
export declare const enum numberTypes {
|
|
55
|
+
number = 4,
|
|
56
|
+
uint16 = 22,
|
|
57
|
+
uint32 = 7,
|
|
58
|
+
int16 = 21,
|
|
59
|
+
int32 = 23,
|
|
60
|
+
uint8 = 6,
|
|
61
|
+
int8 = 20,
|
|
62
|
+
cardinality = 5
|
|
63
|
+
}
|
|
64
|
+
export declare function isNumberType(type: TypeIndex): boolean;
|
|
54
65
|
export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
|
|
55
66
|
export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
|
|
56
67
|
export type PropDef = {
|
|
@@ -125,7 +136,6 @@ export type SchemaTypeDef = {
|
|
|
125
136
|
mainLen: number;
|
|
126
137
|
buf: Uint8Array;
|
|
127
138
|
propNames: Uint8Array;
|
|
128
|
-
packed: Uint8Array;
|
|
129
139
|
props: {
|
|
130
140
|
[path: string]: PropDef;
|
|
131
141
|
};
|
|
@@ -141,6 +151,8 @@ export type SchemaTypeDef = {
|
|
|
141
151
|
mainEmpty: Uint8Array;
|
|
142
152
|
mainEmptyAllZeroes: boolean;
|
|
143
153
|
tree: SchemaPropTree;
|
|
154
|
+
separateSortProps: number;
|
|
155
|
+
separateSortText: number;
|
|
144
156
|
hasSeperateSort: boolean;
|
|
145
157
|
seperateSort: SchemaSortUndefinedHandler;
|
|
146
158
|
hasSeperateTextSort: boolean;
|
package/dist/def/types.js
CHANGED
|
@@ -50,6 +50,19 @@ export const TYPE_INDEX_MAP = {
|
|
|
50
50
|
json: JSON,
|
|
51
51
|
object: OBJECT,
|
|
52
52
|
};
|
|
53
|
+
const numberTypeValues = [
|
|
54
|
+
NUMBER,
|
|
55
|
+
UINT16,
|
|
56
|
+
UINT32,
|
|
57
|
+
INT16,
|
|
58
|
+
INT32,
|
|
59
|
+
UINT8,
|
|
60
|
+
INT8,
|
|
61
|
+
CARDINALITY,
|
|
62
|
+
];
|
|
63
|
+
export function isNumberType(type) {
|
|
64
|
+
return numberTypeValues.includes(type);
|
|
65
|
+
}
|
|
53
66
|
export const SIZE_MAP = {
|
|
54
67
|
timestamp: 8, // 64bit
|
|
55
68
|
// double-precision 64-bit binary format IEEE 754 value
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/parse/assert.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isFloat32Array } from 'util/types';
|
|
2
1
|
import { EXPECTED_ARR, EXPECTED_BOOL, EXPECTED_FN, EXPECTED_NUM, EXPECTED_OBJ, EXPECTED_STR, } from './errors.js';
|
|
3
2
|
export const expectObject = (obj, msg) => {
|
|
4
3
|
if (typeof obj !== 'object' || obj === null) {
|
|
@@ -6,7 +5,7 @@ export const expectObject = (obj, msg) => {
|
|
|
6
5
|
}
|
|
7
6
|
};
|
|
8
7
|
export const expectFloat32Array = (arr) => {
|
|
9
|
-
if (!
|
|
8
|
+
if (!(arr instanceof Float32Array)) {
|
|
10
9
|
throw Error(EXPECTED_ARR);
|
|
11
10
|
}
|
|
12
11
|
};
|
package/dist/serialize.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as deflate from 'fflate';
|
|
2
2
|
import { REVERSE_TYPE_INDEX_MAP, TYPE_INDEX_MAP } from './def/types.js';
|
|
3
|
-
const hasNative = '__basedDb__native__' in global;
|
|
4
3
|
const ENCODER = new TextEncoder();
|
|
5
4
|
let schemaBuffer;
|
|
5
|
+
// 3 level
|
|
6
|
+
// 0 for queries (min)
|
|
7
|
+
// 1 for modify
|
|
8
|
+
// 2 fulls schema
|
|
6
9
|
const walk = (obj, prev, prev2, fromObject, schemaBuffer) => {
|
|
7
10
|
let start = schemaBuffer.len;
|
|
8
11
|
// HANDLE ENUM
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/schema",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"fflate": "0.8.1",
|
|
33
|
-
"@saulx/utils": "^6.
|
|
33
|
+
"@saulx/utils": "^6.6.0",
|
|
34
34
|
"picocolors": "^1.1.0"
|
|
35
35
|
}
|
|
36
36
|
}
|