@based/schema 5.0.0-alpha.6 → 5.0.0-alpha.8
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 +24 -17
- package/dist/def/createEmptyDef.d.ts +1 -0
- package/dist/def/createEmptyDef.js +2 -0
- package/dist/def/fillEmptyMain.d.ts +5 -0
- package/dist/def/fillEmptyMain.js +56 -0
- package/dist/def/readFromPacked.js +5 -1
- package/dist/def/selvaBuffer.js +34 -33
- package/dist/def/typeDef.js +7 -1
- package/dist/def/types.d.ts +20 -4
- package/dist/def/types.js +30 -3
- package/dist/parse/index.d.ts +1 -1
- package/dist/parse/index.js +4 -4
- package/dist/parse/props.js +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +4 -3
package/dist/def/addEdges.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
import { getPropType } from '../index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, } from './types.js';
|
|
3
|
+
import { getPropLen, isSeparate } from './utils.js';
|
|
3
4
|
export const addEdges = (prop, refProp) => {
|
|
4
|
-
let edgesCnt = 0;
|
|
5
5
|
for (const key in refProp) {
|
|
6
6
|
if (key[0] === '$') {
|
|
7
7
|
if (!prop.edges) {
|
|
8
|
+
prop.edgeMainLen = 0;
|
|
8
9
|
prop.edges = {};
|
|
9
|
-
prop.
|
|
10
|
-
prop.
|
|
10
|
+
prop.reverseSeperateEdges = {};
|
|
11
|
+
prop.reverseMainEdges = {};
|
|
12
|
+
prop.edgesSeperateCnt = 0;
|
|
13
|
+
}
|
|
14
|
+
const edgeProp = refProp[key];
|
|
15
|
+
const edgeType = getPropType(edgeProp);
|
|
16
|
+
const len = getPropLen(edgeProp);
|
|
17
|
+
const separate = isSeparate(edgeProp, len);
|
|
18
|
+
if (separate) {
|
|
19
|
+
prop.edgesSeperateCnt++;
|
|
11
20
|
}
|
|
12
|
-
edgesCnt++;
|
|
13
|
-
const edgeType = getPropType(refProp[key]);
|
|
14
21
|
const edge = {
|
|
15
22
|
__isPropDef: true,
|
|
16
23
|
__isEdge: true,
|
|
17
|
-
prop:
|
|
24
|
+
prop: separate ? prop.edgesSeperateCnt : 0,
|
|
18
25
|
name: key,
|
|
19
26
|
typeIndex: TYPE_INDEX_MAP[edgeType],
|
|
20
|
-
len
|
|
21
|
-
separate
|
|
27
|
+
len,
|
|
28
|
+
separate,
|
|
22
29
|
path: [...prop.path, key],
|
|
30
|
+
start: prop.edgeMainLen,
|
|
23
31
|
};
|
|
24
|
-
|
|
25
|
-
prop.edgesTotalLen = 0;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// [field] [size] [data]
|
|
29
|
-
prop.edgesTotalLen += 1 + 2 + edge.len; // field len
|
|
30
|
-
}
|
|
32
|
+
prop.edgeMainLen += edge.len;
|
|
31
33
|
if (edge.typeIndex === ENUM) {
|
|
32
34
|
edge.enum = Array.isArray(refProp[key])
|
|
33
35
|
? refProp[key]
|
|
@@ -44,7 +46,12 @@ export const addEdges = (prop, refProp) => {
|
|
|
44
46
|
edge.inverseTypeName = refProp[key].ref;
|
|
45
47
|
}
|
|
46
48
|
prop.edges[key] = edge;
|
|
47
|
-
|
|
49
|
+
if (separate) {
|
|
50
|
+
prop.reverseSeperateEdges[edge.prop] = edge;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
prop.reverseMainEdges[edge.start] = edge;
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
};
|
|
@@ -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,56 @@
|
|
|
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!
|
|
3
|
+
export const ENCODER = new TextEncoder();
|
|
4
|
+
export const fillEmptyMain = (vals, mainLen) => {
|
|
5
|
+
const mainEmpty = new Uint8Array(mainLen);
|
|
6
|
+
for (const f of vals) {
|
|
7
|
+
if (f.separate) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const t = f.typeIndex;
|
|
11
|
+
const s = f.start;
|
|
12
|
+
let val = f.default;
|
|
13
|
+
if (t === BOOLEAN || t === INT8 || t === UINT8 || t === ENUM) {
|
|
14
|
+
mainEmpty[s] = val === true ? 1 : 0;
|
|
15
|
+
}
|
|
16
|
+
else if (t === UINT32 || t === INT32) {
|
|
17
|
+
mainEmpty[s] = val;
|
|
18
|
+
mainEmpty[s + 1] = val >>>= 8;
|
|
19
|
+
mainEmpty[s + 2] = val >>>= 8;
|
|
20
|
+
mainEmpty[s + 3] = val >>>= 8;
|
|
21
|
+
}
|
|
22
|
+
else if (t === UINT16 || t === INT16) {
|
|
23
|
+
mainEmpty[s] = val;
|
|
24
|
+
mainEmpty[s + 1] = val >>>= 8;
|
|
25
|
+
}
|
|
26
|
+
else if (t === NUMBER ||
|
|
27
|
+
t === TIMESTAMP ||
|
|
28
|
+
t === CREATED ||
|
|
29
|
+
t === UPDATED) {
|
|
30
|
+
const view = new DataView(mainEmpty.buffer, s, 8);
|
|
31
|
+
view.setFloat64(0, val, true);
|
|
32
|
+
}
|
|
33
|
+
else if (t === STRING) {
|
|
34
|
+
val = ENCODER.encode(val);
|
|
35
|
+
mainEmpty[s] = val.byteLength;
|
|
36
|
+
mainEmpty.set(val, s + 1);
|
|
37
|
+
}
|
|
38
|
+
else if (t === BINARY) {
|
|
39
|
+
if (val !== undefined) {
|
|
40
|
+
mainEmpty.set(val, s);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return mainEmpty;
|
|
45
|
+
};
|
|
46
|
+
export const isZeroes = (buf) => {
|
|
47
|
+
let i = 0;
|
|
48
|
+
while (i < buf.byteLength) {
|
|
49
|
+
if (buf[i] !== 0) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
i++;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=fillEmptyMain.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { REVERSE_SIZE_MAP } from './types.js';
|
|
1
|
+
import { DEFAULT_MAP, REVERSE_SIZE_MAP, } from './types.js';
|
|
2
2
|
export const readFromPacked = (packed) => {
|
|
3
3
|
const size = (packed[0] | (packed[1] << 8)) >>> 0;
|
|
4
4
|
const props = [];
|
|
@@ -86,6 +86,8 @@ export const readFromPacked = (packed) => {
|
|
|
86
86
|
bufferTmp: new Uint8Array([]),
|
|
87
87
|
props: [],
|
|
88
88
|
},
|
|
89
|
+
mainEmpty: new Uint8Array([]),
|
|
90
|
+
mainEmptyAllZeroes: true,
|
|
89
91
|
// need this...
|
|
90
92
|
locales: {},
|
|
91
93
|
localeSize: 0,
|
|
@@ -98,6 +100,7 @@ export const readFromPacked = (packed) => {
|
|
|
98
100
|
separate: false,
|
|
99
101
|
__isPropDef: true,
|
|
100
102
|
start: s,
|
|
103
|
+
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
101
104
|
typeIndex: p.typeIndex,
|
|
102
105
|
path: p.path.split('.'),
|
|
103
106
|
len,
|
|
@@ -113,6 +116,7 @@ export const readFromPacked = (packed) => {
|
|
|
113
116
|
__isPropDef: true,
|
|
114
117
|
start: 0,
|
|
115
118
|
typeIndex: p.typeIndex,
|
|
119
|
+
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
116
120
|
path: p.path.split('.'),
|
|
117
121
|
len: 0,
|
|
118
122
|
compression: 1,
|
package/dist/def/selvaBuffer.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
import { ALIAS, ALIASES, BINARY,
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, EMPTY_MICRO_BUFFER, CARDINALITY, MICRO_BUFFER, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, JSON, } from './types.js';
|
|
2
2
|
const selvaTypeMap = new Uint8Array(32); // 1.2x faster than JS array
|
|
3
|
-
selvaTypeMap[
|
|
4
|
-
selvaTypeMap[
|
|
5
|
-
selvaTypeMap[
|
|
6
|
-
selvaTypeMap[
|
|
7
|
-
selvaTypeMap[
|
|
8
|
-
selvaTypeMap[
|
|
9
|
-
selvaTypeMap[
|
|
10
|
-
selvaTypeMap[
|
|
11
|
-
selvaTypeMap[
|
|
12
|
-
selvaTypeMap[
|
|
13
|
-
selvaTypeMap[
|
|
14
|
-
selvaTypeMap[
|
|
15
|
-
selvaTypeMap[
|
|
16
|
-
selvaTypeMap[ENUM] = 10;
|
|
17
|
-
selvaTypeMap[STRING] = 11;
|
|
18
|
-
selvaTypeMap[TEXT] = 12;
|
|
19
|
-
selvaTypeMap[REFERENCE] = 13;
|
|
20
|
-
selvaTypeMap[REFERENCES] = 14;
|
|
21
|
-
selvaTypeMap[WEAK_REFERENCE] = 15;
|
|
22
|
-
selvaTypeMap[WEAK_REFERENCES] = 16;
|
|
23
|
-
selvaTypeMap[MICRO_BUFFER] = 17;
|
|
24
|
-
selvaTypeMap[ALIAS] = 18;
|
|
25
|
-
selvaTypeMap[ALIASES] = 19;
|
|
26
|
-
selvaTypeMap[BINARY] = 11;
|
|
27
|
-
selvaTypeMap[VECTOR] = 17;
|
|
28
|
-
selvaTypeMap[JSON] = 11;
|
|
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;
|
|
29
16
|
const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
|
|
30
17
|
function blockCapacity(blockCapacity) {
|
|
31
18
|
const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
|
|
@@ -64,12 +51,26 @@ const propDefBuffer = (schema, prop, isEdge) => {
|
|
|
64
51
|
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
65
52
|
buf[4] = prop.inversePropNumber;
|
|
66
53
|
if (prop.edges) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
const edgesS = Object.values(prop.edges);
|
|
55
|
+
if (edgesS.length) {
|
|
56
|
+
const props = edgesS
|
|
57
|
+
.filter((v) => v.separate === true)
|
|
58
|
+
.sort((a, b) => (a.prop > b.prop ? 1 : -1));
|
|
59
|
+
const p = [
|
|
60
|
+
{
|
|
61
|
+
...EMPTY_MICRO_BUFFER,
|
|
62
|
+
len: prop.edgeMainLen || 1, // allow zero here... else useless padding
|
|
63
|
+
__isEdgeDef: true,
|
|
64
|
+
},
|
|
65
|
+
// or handle this here...
|
|
66
|
+
...props,
|
|
67
|
+
];
|
|
68
|
+
eschema = p
|
|
69
|
+
.map((prop) => propDefBuffer(schema, prop, true))
|
|
70
|
+
.flat(1);
|
|
71
|
+
eschema.unshift(0, 0, 0, 0, sepPropCount(p), 0);
|
|
72
|
+
view.setUint32(5, eschema.length, true);
|
|
73
|
+
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
return [...buf, ...eschema];
|
package/dist/def/typeDef.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isPropType, getPropType, } from '../index.js';
|
|
2
2
|
import { setByPath } from '@saulx/utils';
|
|
3
|
-
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, } from './types.js';
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, DEFAULT_MAP, } from './types.js';
|
|
4
4
|
import { makePacked } from './makePacked.js';
|
|
5
5
|
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
6
6
|
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
@@ -9,6 +9,7 @@ import { isSeparate } from './utils.js';
|
|
|
9
9
|
import { addEdges } from './addEdges.js';
|
|
10
10
|
import { createEmptyDef } from './createEmptyDef.js';
|
|
11
11
|
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
12
|
+
import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
|
|
12
13
|
export const DEFAULT_BLOCK_CAPACITY = 100_000;
|
|
13
14
|
export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById) => {
|
|
14
15
|
for (const field in schemaTypesParsed) {
|
|
@@ -57,6 +58,7 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
57
58
|
let separateSortProps = 0;
|
|
58
59
|
let separateSortText = 0;
|
|
59
60
|
for (const key in target) {
|
|
61
|
+
// Create prop def
|
|
60
62
|
const schemaProp = target[key];
|
|
61
63
|
const propPath = [...path, key];
|
|
62
64
|
const propType = getPropType(schemaProp);
|
|
@@ -89,6 +91,7 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
89
91
|
path: propPath,
|
|
90
92
|
start: 0,
|
|
91
93
|
len,
|
|
94
|
+
default: schemaProp.default ?? DEFAULT_MAP[TYPE_INDEX_MAP[propType]],
|
|
92
95
|
prop: isseparate ? ++result.cnt : 0,
|
|
93
96
|
};
|
|
94
97
|
if (isPropType('enum', schemaProp)) {
|
|
@@ -138,6 +141,7 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
if (top) {
|
|
144
|
+
// Put top level together
|
|
141
145
|
const vals = Object.values(result.props);
|
|
142
146
|
vals.sort((a, b) => {
|
|
143
147
|
if (b.separate &&
|
|
@@ -168,6 +172,8 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
168
172
|
setByPath(result.tree, f.path, f);
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
result.mainEmpty = fillEmptyMain(vals, result.mainLen);
|
|
176
|
+
result.mainEmptyAllZeroes = isZeroes(result.mainEmpty);
|
|
171
177
|
makePacked(result, typeName, vals, len);
|
|
172
178
|
if (separateSortText > 0) {
|
|
173
179
|
makeSeparateTextSort(result);
|
package/dist/def/types.d.ts
CHANGED
|
@@ -68,18 +68,24 @@ export type PropDef = {
|
|
|
68
68
|
inverseTypeId?: number;
|
|
69
69
|
inversePropNumber?: number;
|
|
70
70
|
enum?: any[];
|
|
71
|
+
dependent?: boolean;
|
|
72
|
+
default: any;
|
|
73
|
+
edgeMainLen?: 0;
|
|
71
74
|
reverseEnum?: {
|
|
72
75
|
[key: string]: number;
|
|
73
76
|
};
|
|
74
|
-
|
|
77
|
+
edgesSeperateCnt?: number;
|
|
75
78
|
edges?: {
|
|
76
79
|
[key: string]: PropDefEdge;
|
|
77
80
|
};
|
|
78
|
-
|
|
81
|
+
reverseSeperateEdges?: {
|
|
79
82
|
[prop: string]: PropDefEdge;
|
|
80
83
|
};
|
|
84
|
+
reverseMainEdges?: {
|
|
85
|
+
[start: string]: PropDefEdge;
|
|
86
|
+
};
|
|
87
|
+
edgeMainEmpty?: Uint8Array;
|
|
81
88
|
__isEdge?: boolean;
|
|
82
|
-
dependent?: boolean;
|
|
83
89
|
};
|
|
84
90
|
export type PropDefEdge = Partial<PropDef> & {
|
|
85
91
|
__isPropDef: true;
|
|
@@ -90,6 +96,13 @@ export type PropDefEdge = Partial<PropDef> & {
|
|
|
90
96
|
edgesTotalLen?: number;
|
|
91
97
|
__isEdge: true;
|
|
92
98
|
};
|
|
99
|
+
export type PropDefAggregate = Partial<PropDef> & {
|
|
100
|
+
__isPropDef: true;
|
|
101
|
+
typeIndex: TypeIndex;
|
|
102
|
+
len: number;
|
|
103
|
+
prop: number;
|
|
104
|
+
name: string;
|
|
105
|
+
};
|
|
93
106
|
export type SchemaPropTree = {
|
|
94
107
|
[key: string]: SchemaPropTree | PropDef;
|
|
95
108
|
};
|
|
@@ -122,6 +135,8 @@ export type SchemaTypeDef = {
|
|
|
122
135
|
main: {
|
|
123
136
|
[start: string]: PropDef;
|
|
124
137
|
};
|
|
138
|
+
mainEmpty: Uint8Array;
|
|
139
|
+
mainEmptyAllZeroes: boolean;
|
|
125
140
|
tree: SchemaPropTree;
|
|
126
141
|
hasSeperateSort: boolean;
|
|
127
142
|
seperateSort: SchemaSortUndefinedHandler;
|
|
@@ -137,7 +152,8 @@ export type SchemaTypeDef = {
|
|
|
137
152
|
localeSize: number;
|
|
138
153
|
};
|
|
139
154
|
export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
|
|
140
|
-
export declare
|
|
155
|
+
export declare const DEFAULT_MAP: Record<TypeIndex, any>;
|
|
156
|
+
export declare const REVERSE_SIZE_MAP: Record<TypeIndex, number>;
|
|
141
157
|
export declare const REVERSE_TYPE_INDEX_MAP: Record<TypeIndex, InternalSchemaProp>;
|
|
142
158
|
export declare const ID_FIELD_DEF: PropDef;
|
|
143
159
|
export declare const EMPTY_MICRO_BUFFER: PropDef;
|
package/dist/def/types.js
CHANGED
|
@@ -83,9 +83,34 @@ const reverseMap = {};
|
|
|
83
83
|
for (const k in TYPE_INDEX_MAP) {
|
|
84
84
|
reverseMap[TYPE_INDEX_MAP[k]] = k;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
};
|
|
113
|
+
export const REVERSE_SIZE_MAP = {};
|
|
89
114
|
for (const k in SIZE_MAP) {
|
|
90
115
|
REVERSE_SIZE_MAP[TYPE_INDEX_MAP[k]] = SIZE_MAP[k];
|
|
91
116
|
}
|
|
@@ -96,6 +121,7 @@ export const ID_FIELD_DEF = {
|
|
|
96
121
|
path: ['id'],
|
|
97
122
|
start: 0,
|
|
98
123
|
prop: 255,
|
|
124
|
+
default: 0,
|
|
99
125
|
len: 4,
|
|
100
126
|
__isPropDef: true,
|
|
101
127
|
};
|
|
@@ -104,6 +130,7 @@ export const EMPTY_MICRO_BUFFER = {
|
|
|
104
130
|
separate: true,
|
|
105
131
|
path: [''],
|
|
106
132
|
start: 0,
|
|
133
|
+
default: undefined,
|
|
107
134
|
prop: 0,
|
|
108
135
|
len: 1,
|
|
109
136
|
__isPropDef: true,
|
package/dist/parse/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class SchemaParser {
|
|
|
12
12
|
parseTypes(): void;
|
|
13
13
|
parseProps(props: any, schemaType?: SchemaType): void;
|
|
14
14
|
parseLocales(): void;
|
|
15
|
-
parse():
|
|
15
|
+
parse(): StrictSchema;
|
|
16
16
|
}
|
|
17
17
|
export declare const print: (schema: Schema, path: string[]) => string;
|
|
18
18
|
export declare const parse: (schema: Schema) => {
|
package/dist/parse/index.js
CHANGED
|
@@ -3,10 +3,11 @@ import { getPropType } from './utils.js';
|
|
|
3
3
|
import propParsers from './props.js';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
5
|
import { expectBoolean, expectObject } from './assert.js';
|
|
6
|
+
import { deepCopy } from '@saulx/utils';
|
|
6
7
|
export { getPropType };
|
|
7
8
|
export class SchemaParser {
|
|
8
9
|
constructor(schema) {
|
|
9
|
-
this.schema = schema;
|
|
10
|
+
this.schema = deepCopy(schema);
|
|
10
11
|
}
|
|
11
12
|
isItems;
|
|
12
13
|
inQuery;
|
|
@@ -97,6 +98,7 @@ export class SchemaParser {
|
|
|
97
98
|
throw Error(UNKNOWN_PROP);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
return this.schema;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
export const print = (schema, path) => {
|
|
@@ -120,9 +122,7 @@ export const print = (schema, path) => {
|
|
|
120
122
|
export const parse = (schema) => {
|
|
121
123
|
const parser = new SchemaParser(schema);
|
|
122
124
|
try {
|
|
123
|
-
parser.parse();
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
return { schema };
|
|
125
|
+
return { schema: parser.parse() };
|
|
126
126
|
}
|
|
127
127
|
catch (e) {
|
|
128
128
|
const cause = parser.path.slice(0, Math.min(4, parser.lvl) + 1);
|
package/dist/parse/props.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export type SchemaReferencesOneWay = Prop<{
|
|
|
40
40
|
export type SchemaText = Prop<{
|
|
41
41
|
type: 'text';
|
|
42
42
|
default?: Record<string, string>;
|
|
43
|
+
format?: StringFormat;
|
|
43
44
|
}>;
|
|
44
45
|
type NumberType = 'number' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32';
|
|
45
46
|
export type SchemaNumber = Prop<{
|
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.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"package.json",
|
|
9
9
|
"!dist/**/*.map"
|
|
10
10
|
],
|
|
11
|
+
"main": "./dist/index.js",
|
|
11
12
|
"exports": {
|
|
12
13
|
"./def": "./dist/def/index.js",
|
|
13
14
|
".": "./dist/index.js"
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"typescript": "^5.6.3"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@saulx/utils": "^
|
|
32
|
+
"@saulx/utils": "^6.1.1",
|
|
32
33
|
"picocolors": "^1.1.0"
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
|
+
}
|