@based/schema 5.0.4-alpha.1 → 5.1.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.
- package/dist/dbSchema.d.ts +1 -1
- package/dist/dbSchema.js +72 -1
- package/dist/def/addEdges.js +6 -6
- package/dist/def/createEmptyDef.d.ts +1 -0
- package/dist/def/createEmptyDef.js +1 -0
- package/dist/def/defaultMap.js +1 -3
- package/dist/def/index.d.ts +0 -1
- package/dist/def/index.js +0 -1
- package/dist/def/typeDef.js +149 -106
- package/dist/def/typeIndexes.d.ts +1 -3
- package/dist/def/typeIndexes.js +0 -2
- package/dist/def/types.d.ts +10 -3
- package/dist/def/types.js +2 -0
- package/dist/def/validation.d.ts +14 -2
- package/dist/def/validation.js +174 -21
- package/dist/infer.d.ts +1 -1
- package/dist/parse/props.js +23 -69
- package/dist/parse/utils.js +9 -5
- package/dist/types.d.ts +22 -30
- package/dist/types.js +0 -21
- package/package.json +5 -3
- package/dist/def/refSet.d.ts +0 -7
- package/dist/def/refSet.js +0 -25
- package/dist/def/selvaBuffer.d.ts +0 -5
- package/dist/def/selvaBuffer.js +0 -164
package/dist/dbSchema.d.ts
CHANGED
package/dist/dbSchema.js
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { hash } from '@based/hash';
|
|
2
|
-
import { getPropType } from
|
|
2
|
+
import { getPropType } from './parse/utils.js';
|
|
3
3
|
import { deepCopy } from '@based/utils';
|
|
4
|
+
function _makeEdgeTypes(newTypes, typeName, props, propPrefix) {
|
|
5
|
+
const putEdgeProps = (from, to, edgeProps) => (newTypes[`_${[from, to].sort().join(':')}`] = { props: edgeProps });
|
|
6
|
+
for (const propName in props) {
|
|
7
|
+
const prop = props[propName];
|
|
8
|
+
const propType = getPropType(prop);
|
|
9
|
+
const nextPropPrefix = propPrefix ? `${propPrefix}.${propName}` : propName;
|
|
10
|
+
if (propType === 'object') {
|
|
11
|
+
_makeEdgeTypes(newTypes, typeName, prop.props, nextPropPrefix);
|
|
12
|
+
}
|
|
13
|
+
else if (propType === 'reference') {
|
|
14
|
+
const edgeProps = {};
|
|
15
|
+
Object.keys(prop)
|
|
16
|
+
.filter((k) => k[0] === '$')
|
|
17
|
+
.forEach((k) => (edgeProps[k] = prop[k]));
|
|
18
|
+
if (Object.keys(edgeProps).length > 0) {
|
|
19
|
+
putEdgeProps(`${typeName}.${nextPropPrefix}`, `${prop.ref}.${prop.prop}`, edgeProps);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (propType === 'references') {
|
|
23
|
+
const edgeProps = {};
|
|
24
|
+
Object.keys(prop.items)
|
|
25
|
+
.filter((k) => k[0] === '$')
|
|
26
|
+
.forEach((k) => (edgeProps[k] = prop.items[k]));
|
|
27
|
+
if (Object.keys(edgeProps).length > 0) {
|
|
28
|
+
putEdgeProps(`${typeName}.${nextPropPrefix}`, `${prop.items.ref}.${prop.items.prop}`, edgeProps);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function makeEdgeTypes(types) {
|
|
34
|
+
const newTypes = {};
|
|
35
|
+
for (const typeName in types) {
|
|
36
|
+
const type = types[typeName];
|
|
37
|
+
_makeEdgeTypes(newTypes, typeName, type.props, '');
|
|
38
|
+
}
|
|
39
|
+
return newTypes;
|
|
40
|
+
}
|
|
4
41
|
export const strictSchemaToDbSchema = (schema) => {
|
|
5
42
|
// @ts-ignore
|
|
6
43
|
let dbSchema = deepCopy(schema);
|
|
@@ -45,6 +82,40 @@ export const strictSchemaToDbSchema = (schema) => {
|
|
|
45
82
|
};
|
|
46
83
|
delete dbSchema.props;
|
|
47
84
|
}
|
|
85
|
+
const edgeTypes = makeEdgeTypes(dbSchema.types);
|
|
86
|
+
// Create inverse props for reference(s)
|
|
87
|
+
for (const et in edgeTypes) {
|
|
88
|
+
dbSchema.types[et] = edgeTypes[et];
|
|
89
|
+
for (const key in edgeTypes[et].props) {
|
|
90
|
+
const prop = edgeTypes[et].props[key];
|
|
91
|
+
const propType = getPropType(prop);
|
|
92
|
+
let refProp;
|
|
93
|
+
if (propType === 'reference') {
|
|
94
|
+
refProp = prop;
|
|
95
|
+
}
|
|
96
|
+
else if (propType === 'references') {
|
|
97
|
+
refProp = prop.items;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
continue; // not a ref
|
|
101
|
+
}
|
|
102
|
+
const type = dbSchema.types[refProp.ref];
|
|
103
|
+
const inverseKey = `_${et}_${key}`;
|
|
104
|
+
dbSchema.types[refProp.ref] = {
|
|
105
|
+
...type,
|
|
106
|
+
props: {
|
|
107
|
+
...type.props,
|
|
108
|
+
[inverseKey]: {
|
|
109
|
+
items: {
|
|
110
|
+
ref: et,
|
|
111
|
+
prop: key,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
refProp.prop = inverseKey;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
48
119
|
// Assign typeIds
|
|
49
120
|
for (const typeName in dbSchema.types) {
|
|
50
121
|
if (!('id' in dbSchema.types[typeName])) {
|
package/dist/def/addEdges.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getPropType } from '../index.js';
|
|
1
|
+
import { getPropType, getValidator } from '../index.js';
|
|
2
2
|
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
3
|
import { fillEmptyMain } from './fillEmptyMain.js';
|
|
4
4
|
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, NUMBER, } from './types.js';
|
|
5
5
|
import { getPropLen, isSeparate, parseMinMaxStep, sortMainProps, } from './utils.js';
|
|
6
|
-
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
7
6
|
export const addEdges = (prop, refProp) => {
|
|
8
7
|
const mainEdges = [];
|
|
9
8
|
for (const key in refProp) {
|
|
@@ -28,10 +27,11 @@ export const addEdges = (prop, refProp) => {
|
|
|
28
27
|
}
|
|
29
28
|
// add default
|
|
30
29
|
const edge = {
|
|
30
|
+
schema: edgeProp,
|
|
31
31
|
__isPropDef: true,
|
|
32
32
|
__isEdge: true,
|
|
33
33
|
prop: separate ? prop.edgesSeperateCnt : 0,
|
|
34
|
-
validation: edgeProp
|
|
34
|
+
validation: getValidator(edgeProp),
|
|
35
35
|
name: key,
|
|
36
36
|
typeIndex,
|
|
37
37
|
len,
|
|
@@ -44,13 +44,13 @@ export const addEdges = (prop, refProp) => {
|
|
|
44
44
|
mainEdges.push(edge);
|
|
45
45
|
}
|
|
46
46
|
if (edgeProp.max !== undefined) {
|
|
47
|
-
edge.max = parseMinMaxStep(edgeProp.max);
|
|
47
|
+
edgeProp.max = edge.max = parseMinMaxStep(edgeProp.max);
|
|
48
48
|
}
|
|
49
49
|
if (edgeProp.min !== undefined) {
|
|
50
|
-
edge.min = parseMinMaxStep(edgeProp.min);
|
|
50
|
+
edgeProp.min = edge.min = parseMinMaxStep(edgeProp.min);
|
|
51
51
|
}
|
|
52
52
|
if (edgeProp.step !== undefined) {
|
|
53
|
-
edge.step = parseMinMaxStep(edgeProp.step);
|
|
53
|
+
edgeProp.step = edge.step = parseMinMaxStep(edgeProp.step);
|
|
54
54
|
}
|
|
55
55
|
if (edge.typeIndex !== NUMBER && edge.step === undefined) {
|
|
56
56
|
edge.step = 1;
|
|
@@ -2,6 +2,7 @@ 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
|
+
capped: number;
|
|
5
6
|
insertOnly: boolean;
|
|
6
7
|
partial: boolean;
|
|
7
8
|
checksum: number;
|
package/dist/def/defaultMap.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
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,
|
|
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, NULL, OBJECT, } from './types.js';
|
|
2
2
|
export const DEFAULT_MAP = {
|
|
3
3
|
[NULL]: 0,
|
|
4
4
|
[OBJECT]: 0,
|
|
5
|
-
[WEAK_REFERENCE]: 0,
|
|
6
|
-
[WEAK_REFERENCES]: 0,
|
|
7
5
|
[ALIAS]: '',
|
|
8
6
|
[BINARY]: new Uint8Array(),
|
|
9
7
|
[BOOLEAN]: false,
|
package/dist/def/index.d.ts
CHANGED
package/dist/def/index.js
CHANGED
package/dist/def/typeDef.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPropType, getPropType, } from '../index.js';
|
|
1
|
+
import { isPropType, getPropType, getValidator, } from '../index.js';
|
|
2
2
|
import { setByPath } from '@based/utils';
|
|
3
3
|
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, NUMBER, BLOCK_CAPACITY_MAX, BLOCK_CAPACITY_DEFAULT, BLOCK_CAPACITY_MIN, VECTOR, COLVEC, CARDINALITY, } from './types.js';
|
|
4
4
|
import { DEFAULT_MAP } from './defaultMap.js';
|
|
@@ -8,7 +8,6 @@ import { getPropLen, isSeparate, parseMinMaxStep, reorderProps, schemaVectorBase
|
|
|
8
8
|
import { addEdges } from './addEdges.js';
|
|
9
9
|
import { createEmptyDef } from './createEmptyDef.js';
|
|
10
10
|
import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
|
|
11
|
-
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
12
11
|
export const updateTypeDefs = (schema) => {
|
|
13
12
|
const schemaTypesParsed = {};
|
|
14
13
|
const schemaTypesParsedById = {};
|
|
@@ -17,27 +16,58 @@ export const updateTypeDefs = (schema) => {
|
|
|
17
16
|
if (!type.id) {
|
|
18
17
|
throw new Error('NEED ID ON TYPE');
|
|
19
18
|
}
|
|
20
|
-
const def = createSchemaTypeDef(typeName, type,
|
|
19
|
+
const def = createSchemaTypeDef(typeName, type, schema.locales ?? {
|
|
21
20
|
en: {},
|
|
22
21
|
});
|
|
23
22
|
schemaTypesParsed[typeName] = def;
|
|
24
23
|
schemaTypesParsedById[type.id] = def;
|
|
25
24
|
}
|
|
26
|
-
// Update inverseProps in references
|
|
27
25
|
for (const schema of Object.values(schemaTypesParsed)) {
|
|
28
26
|
for (const prop of Object.values(schema.props)) {
|
|
29
27
|
if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
|
|
28
|
+
// FIXME Now references in edgeType are missing __isEdge
|
|
29
|
+
// However, we can soon just delete weak refs
|
|
30
|
+
if (!prop.__isEdge && !prop.inversePropName) {
|
|
31
|
+
prop.__isEdge = true;
|
|
32
|
+
}
|
|
30
33
|
if (!prop.__isEdge) {
|
|
34
|
+
// Update inverseProps in references
|
|
31
35
|
const dstType = schemaTypesParsed[prop.inverseTypeName];
|
|
32
36
|
prop.inverseTypeId = dstType.id;
|
|
33
37
|
prop.inversePropNumber = dstType.props[prop.inversePropName].prop;
|
|
38
|
+
if (prop.edges) {
|
|
39
|
+
if (dstType.props[prop.inversePropName].edges) {
|
|
40
|
+
// this currently is not allowed, but might be
|
|
41
|
+
const mergedEdges = {
|
|
42
|
+
...dstType.props[prop.inversePropName].edges,
|
|
43
|
+
...prop.edges,
|
|
44
|
+
};
|
|
45
|
+
dstType.props[prop.inversePropName].edges = mergedEdges;
|
|
46
|
+
prop.edges = mergedEdges;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
dstType.props[prop.inversePropName].edges = prop.edges;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Update edgeNodeTypeId
|
|
53
|
+
if (!prop.edgeNodeTypeId) {
|
|
54
|
+
if (prop.edges) {
|
|
55
|
+
const edgeTypeName = `_${[`${schema.type}.${prop.path.join('.')}`, `${dstType.type}.${dstType.props[prop.inversePropName].path.join('.')}`].sort().join(':')}`;
|
|
56
|
+
const edgeType = schemaTypesParsed[edgeTypeName];
|
|
57
|
+
prop.edgeNodeTypeId = edgeType.id;
|
|
58
|
+
dstType.props[prop.inversePropName].edgeNodeTypeId = edgeType.id;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
prop.edgeNodeTypeId = 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
34
64
|
}
|
|
35
65
|
}
|
|
36
66
|
}
|
|
37
67
|
}
|
|
38
68
|
return { schemaTypesParsed, schemaTypesParsedById };
|
|
39
69
|
};
|
|
40
|
-
const createSchemaTypeDef = (typeName, type,
|
|
70
|
+
const createSchemaTypeDef = (typeName, type, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
|
|
41
71
|
if (top) {
|
|
42
72
|
if (result.id == 0) {
|
|
43
73
|
if ('id' in type) {
|
|
@@ -61,6 +91,14 @@ const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmp
|
|
|
61
91
|
typeName === '_root' ? BLOCK_CAPACITY_MAX : BLOCK_CAPACITY_DEFAULT;
|
|
62
92
|
}
|
|
63
93
|
}
|
|
94
|
+
if (result.capped == 0) {
|
|
95
|
+
if ('capped' in type) {
|
|
96
|
+
if (typeof type.capped !== 'number' || type.capped < 0) {
|
|
97
|
+
throw new Error('Invalid capped');
|
|
98
|
+
}
|
|
99
|
+
result.capped = type.capped;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
64
102
|
if (result.insertOnly == false && 'insertOnly' in type) {
|
|
65
103
|
result.insertOnly = !!type.insertOnly;
|
|
66
104
|
}
|
|
@@ -82,116 +120,121 @@ const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmp
|
|
|
82
120
|
const propPath = [...path, key];
|
|
83
121
|
const propType = getPropType(schemaProp);
|
|
84
122
|
if (propType === 'object') {
|
|
85
|
-
createSchemaTypeDef(typeName, schemaProp,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
result.separateSortProps++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
123
|
+
createSchemaTypeDef(typeName, schemaProp, locales, result, propPath, false);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const len = getPropLen(schemaProp);
|
|
127
|
+
if (isPropType('string', schemaProp) ||
|
|
128
|
+
isPropType('alias', schemaProp) ||
|
|
129
|
+
isPropType('cardinality', schemaProp)) {
|
|
130
|
+
if (typeof schemaProp === 'object') {
|
|
131
|
+
if (!(schemaProp.maxBytes < 61) ||
|
|
132
|
+
!('max' in schemaProp && schemaProp.max < 31)) {
|
|
99
133
|
result.separateSortProps++;
|
|
100
134
|
}
|
|
101
135
|
}
|
|
102
|
-
else
|
|
103
|
-
result.
|
|
136
|
+
else {
|
|
137
|
+
result.separateSortProps++;
|
|
104
138
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
139
|
+
}
|
|
140
|
+
else if (isPropType('text', schemaProp)) {
|
|
141
|
+
result.separateSortText++;
|
|
142
|
+
}
|
|
143
|
+
else if (isPropType('colvec', schemaProp)) {
|
|
144
|
+
if (!result.insertOnly) {
|
|
145
|
+
throw new Error('colvec requires insertOnly');
|
|
109
146
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (schemaProp.step !== undefined) {
|
|
132
|
-
prop.step = parseMinMaxStep(schemaProp.step);
|
|
133
|
-
}
|
|
134
|
-
if (prop.typeIndex !== NUMBER && prop.step === undefined) {
|
|
135
|
-
prop.step = 1;
|
|
136
|
-
}
|
|
137
|
-
if (prop.typeIndex === VECTOR || prop.typeIndex === COLVEC) {
|
|
138
|
-
prop.vectorBaseType = schemaVectorBaseTypeToEnum(schemaProp.baseType ?? 'number');
|
|
139
|
-
}
|
|
140
|
-
if (prop.typeIndex === CARDINALITY) {
|
|
141
|
-
prop.cardinalityMode ??= cardinalityModeToEnum((schemaProp.mode ??= 'sparse'));
|
|
142
|
-
const prec = typeName == '_root' ? 14 : 8;
|
|
143
|
-
prop.cardinalityPrecision ??= schemaProp.precision ??= prec;
|
|
144
|
-
}
|
|
145
|
-
if (isPropType('enum', schemaProp)) {
|
|
146
|
-
prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
|
|
147
|
-
prop.reverseEnum = {};
|
|
148
|
-
for (let i = 0; i < prop.enum.length; i++) {
|
|
149
|
-
prop.reverseEnum[prop.enum[i]] = i;
|
|
150
|
-
}
|
|
147
|
+
}
|
|
148
|
+
const isseparate = isSeparate(schemaProp, len);
|
|
149
|
+
const typeIndex = TYPE_INDEX_MAP[propType];
|
|
150
|
+
const prop = {
|
|
151
|
+
schema: schemaProp,
|
|
152
|
+
typeIndex,
|
|
153
|
+
__isPropDef: true,
|
|
154
|
+
separate: isseparate,
|
|
155
|
+
path: propPath,
|
|
156
|
+
start: 0,
|
|
157
|
+
validation: getValidator(schemaProp),
|
|
158
|
+
len,
|
|
159
|
+
default: schemaProp.default ?? DEFAULT_MAP[typeIndex],
|
|
160
|
+
prop: isseparate ? ++result.cnt : 0,
|
|
161
|
+
};
|
|
162
|
+
if (schemaProp.hooks) {
|
|
163
|
+
result.propHooks ??= {};
|
|
164
|
+
for (const key in schemaProp.hooks) {
|
|
165
|
+
prop.hooks = schemaProp.hooks;
|
|
166
|
+
result.propHooks[key] ??= new Set();
|
|
167
|
+
result.propHooks[key].add(prop);
|
|
151
168
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
}
|
|
170
|
+
if (schemaProp.max !== undefined) {
|
|
171
|
+
schemaProp.max = prop.max = parseMinMaxStep(schemaProp.max);
|
|
172
|
+
}
|
|
173
|
+
if (schemaProp.min !== undefined) {
|
|
174
|
+
schemaProp.min = prop.min = parseMinMaxStep(schemaProp.min);
|
|
175
|
+
}
|
|
176
|
+
if (schemaProp.step !== undefined) {
|
|
177
|
+
schemaProp.step = prop.step = parseMinMaxStep(schemaProp.step);
|
|
178
|
+
}
|
|
179
|
+
if (prop.typeIndex !== NUMBER && prop.step === undefined) {
|
|
180
|
+
prop.step = 1;
|
|
181
|
+
}
|
|
182
|
+
if (prop.typeIndex === VECTOR || prop.typeIndex === COLVEC) {
|
|
183
|
+
prop.vectorBaseType = schemaVectorBaseTypeToEnum(schemaProp.baseType ?? 'number');
|
|
184
|
+
}
|
|
185
|
+
if (prop.typeIndex === CARDINALITY) {
|
|
186
|
+
prop.cardinalityMode ??= cardinalityModeToEnum((schemaProp.mode ??= 'sparse'));
|
|
187
|
+
const prec = typeName == '_root' ? 14 : 8;
|
|
188
|
+
prop.cardinalityPrecision ??= schemaProp.precision ??= prec;
|
|
189
|
+
}
|
|
190
|
+
if (isPropType('enum', schemaProp)) {
|
|
191
|
+
prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
|
|
192
|
+
prop.reverseEnum = {};
|
|
193
|
+
for (let i = 0; i < prop.enum.length; i++) {
|
|
194
|
+
prop.reverseEnum[prop.enum[i]] = i;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (isPropType('references', schemaProp)) {
|
|
198
|
+
if (result.partial) {
|
|
199
|
+
throw new Error('references is not supported with partial');
|
|
200
|
+
}
|
|
201
|
+
prop.inversePropName = schemaProp.items.prop;
|
|
202
|
+
prop.inverseTypeName = schemaProp.items.ref;
|
|
203
|
+
prop.dependent = schemaProp.items.dependent;
|
|
204
|
+
addEdges(prop, schemaProp.items);
|
|
205
|
+
}
|
|
206
|
+
else if (isPropType('reference', schemaProp)) {
|
|
207
|
+
if (result.partial) {
|
|
208
|
+
throw new Error('reference is not supported with partial');
|
|
209
|
+
}
|
|
210
|
+
prop.inversePropName = schemaProp.prop;
|
|
211
|
+
prop.inverseTypeName = schemaProp.ref;
|
|
212
|
+
prop.dependent = schemaProp.dependent;
|
|
213
|
+
addEdges(prop, schemaProp);
|
|
214
|
+
}
|
|
215
|
+
else if (typeof schemaProp === 'object') {
|
|
216
|
+
if (isPropType('string', schemaProp) || isPropType('text', schemaProp)) {
|
|
217
|
+
prop.compression =
|
|
218
|
+
'compression' in schemaProp && schemaProp.compression === 'none'
|
|
219
|
+
? 0
|
|
220
|
+
: 1;
|
|
221
|
+
}
|
|
222
|
+
else if (isPropType('timestamp', schemaProp) && 'on' in schemaProp) {
|
|
223
|
+
if (schemaProp.on[0] === 'c') {
|
|
224
|
+
result.createTs ??= [];
|
|
225
|
+
result.createTs.push(prop);
|
|
177
226
|
}
|
|
178
|
-
else if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
else if (schemaProp.on[0] === 'u') {
|
|
184
|
-
result.createTs ??= [];
|
|
185
|
-
result.createTs.push(prop);
|
|
186
|
-
result.updateTs ??= [];
|
|
187
|
-
result.updateTs.push(prop);
|
|
188
|
-
}
|
|
227
|
+
else if (schemaProp.on[0] === 'u') {
|
|
228
|
+
result.createTs ??= [];
|
|
229
|
+
result.createTs.push(prop);
|
|
230
|
+
result.updateTs ??= [];
|
|
231
|
+
result.updateTs.push(prop);
|
|
189
232
|
}
|
|
190
233
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
234
|
+
}
|
|
235
|
+
result.props[propPath.join('.')] = prop;
|
|
236
|
+
if (isseparate) {
|
|
237
|
+
result.separate.push(prop);
|
|
195
238
|
}
|
|
196
239
|
}
|
|
197
240
|
if (top) {
|
|
@@ -14,8 +14,6 @@ export declare const STRING = 11;
|
|
|
14
14
|
export declare const TEXT = 12;
|
|
15
15
|
export declare const REFERENCE = 13;
|
|
16
16
|
export declare const REFERENCES = 14;
|
|
17
|
-
export declare const WEAK_REFERENCE = 15;
|
|
18
|
-
export declare const WEAK_REFERENCES = 16;
|
|
19
17
|
export declare const MICRO_BUFFER = 17;
|
|
20
18
|
export declare const ALIAS = 18;
|
|
21
19
|
export declare const ALIASES = 19;
|
|
@@ -25,7 +23,7 @@ export declare const VECTOR = 27;
|
|
|
25
23
|
export declare const JSON = 28;
|
|
26
24
|
export declare const OBJECT = 29;
|
|
27
25
|
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
|
|
26
|
+
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 MICRO_BUFFER | typeof ALIAS | typeof ALIASES | typeof BINARY | typeof ID | typeof VECTOR | typeof JSON | typeof OBJECT | typeof COLVEC;
|
|
29
27
|
export declare enum VectorBaseType {
|
|
30
28
|
Int8 = 1,
|
|
31
29
|
Uint8 = 2,
|
package/dist/def/typeIndexes.js
CHANGED
|
@@ -15,8 +15,6 @@ export const STRING = 11;
|
|
|
15
15
|
export const TEXT = 12;
|
|
16
16
|
export const REFERENCE = 13;
|
|
17
17
|
export const REFERENCES = 14;
|
|
18
|
-
export const WEAK_REFERENCE = 15;
|
|
19
|
-
export const WEAK_REFERENCES = 16;
|
|
20
18
|
export const MICRO_BUFFER = 17;
|
|
21
19
|
export const ALIAS = 18;
|
|
22
20
|
export const ALIASES = 19;
|
package/dist/def/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LangCode, SchemaHooks, SchemaLocales } from '../index.js';
|
|
1
|
+
import type { LangCode, SchemaHooks, SchemaLocales, SchemaProp, SchemaPropHooks } from '../index.js';
|
|
2
2
|
import { Validation } from './validation.js';
|
|
3
3
|
import { TypeIndex, VectorBaseType } from './typeIndexes.js';
|
|
4
4
|
export * from './typeIndexes.js';
|
|
@@ -16,6 +16,7 @@ export declare const enum numberTypes {
|
|
|
16
16
|
export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
|
|
17
17
|
export type PropDef = {
|
|
18
18
|
__isPropDef: true;
|
|
19
|
+
schema: SchemaProp<true>;
|
|
19
20
|
prop: number;
|
|
20
21
|
typeIndex: TypeIndex;
|
|
21
22
|
separate: boolean;
|
|
@@ -35,6 +36,7 @@ export type PropDef = {
|
|
|
35
36
|
vectorSize?: number;
|
|
36
37
|
cardinalityMode?: number;
|
|
37
38
|
cardinalityPrecision?: number;
|
|
39
|
+
edgeNodeTypeId?: number;
|
|
38
40
|
edgeMainLen?: 0;
|
|
39
41
|
hasDefaultEdges?: boolean;
|
|
40
42
|
reverseEnum?: {
|
|
@@ -55,10 +57,12 @@ export type PropDef = {
|
|
|
55
57
|
max?: any;
|
|
56
58
|
min?: any;
|
|
57
59
|
step?: any;
|
|
60
|
+
hooks?: SchemaPropHooks;
|
|
58
61
|
};
|
|
59
62
|
export type PropDefEdge = Partial<PropDef> & {
|
|
60
63
|
__isPropDef: true;
|
|
61
64
|
typeIndex: TypeIndex;
|
|
65
|
+
schema: SchemaProp<true>;
|
|
62
66
|
len: number;
|
|
63
67
|
prop: number;
|
|
64
68
|
name: string;
|
|
@@ -88,11 +92,11 @@ export type SchemaTypeDef = {
|
|
|
88
92
|
cnt: number;
|
|
89
93
|
checksum: number;
|
|
90
94
|
type: string;
|
|
91
|
-
lastId: number;
|
|
92
95
|
blockCapacity: number;
|
|
93
|
-
|
|
96
|
+
capped: number;
|
|
94
97
|
insertOnly: boolean;
|
|
95
98
|
partial: boolean;
|
|
99
|
+
mainLen: number;
|
|
96
100
|
buf: Uint8Array;
|
|
97
101
|
propNames: Uint8Array;
|
|
98
102
|
props: {
|
|
@@ -130,6 +134,9 @@ export type SchemaTypeDef = {
|
|
|
130
134
|
locales: Partial<SchemaLocales>;
|
|
131
135
|
localeSize: number;
|
|
132
136
|
hooks?: SchemaHooks;
|
|
137
|
+
propHooks?: {
|
|
138
|
+
[K in keyof SchemaPropHooks]: Set<PropDef>;
|
|
139
|
+
};
|
|
133
140
|
};
|
|
134
141
|
export declare const VECTOR_BASE_TYPE_SIZE_MAP: Record<VectorBaseType, number>;
|
|
135
142
|
export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
|
package/dist/def/types.js
CHANGED
|
@@ -77,6 +77,7 @@ for (const k in SIZE_MAP) {
|
|
|
77
77
|
}
|
|
78
78
|
export const REVERSE_TYPE_INDEX_MAP = reverseMap;
|
|
79
79
|
export const ID_FIELD_DEF = {
|
|
80
|
+
schema: null,
|
|
80
81
|
typeIndex: NULL,
|
|
81
82
|
separate: true,
|
|
82
83
|
path: ['id'],
|
|
@@ -88,6 +89,7 @@ export const ID_FIELD_DEF = {
|
|
|
88
89
|
__isPropDef: true,
|
|
89
90
|
};
|
|
90
91
|
export const EMPTY_MICRO_BUFFER = {
|
|
92
|
+
schema: null,
|
|
91
93
|
typeIndex: MICRO_BUFFER,
|
|
92
94
|
separate: true,
|
|
93
95
|
path: [''],
|
package/dist/def/validation.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import { TypeIndex
|
|
2
|
-
|
|
1
|
+
import { TypeIndex } from './types.js';
|
|
2
|
+
import { SchemaProp, StrictSchema } from '../types.js';
|
|
3
|
+
export type Validation = (payload: any, schema: SchemaProp<true>) => boolean | string;
|
|
3
4
|
export declare const VALIDATION_MAP: Record<TypeIndex, Validation>;
|
|
4
5
|
export declare const defaultValidation: () => boolean;
|
|
5
6
|
export declare const isValidId: (id: number) => boolean;
|
|
6
7
|
export declare const isValidString: (v: any) => boolean;
|
|
8
|
+
type ValidationErrors = {
|
|
9
|
+
path: string[];
|
|
10
|
+
value: unknown;
|
|
11
|
+
error: string;
|
|
12
|
+
}[];
|
|
13
|
+
export declare const getValidator: (prop: SchemaProp<true>) => Validation;
|
|
14
|
+
export declare function validate<S extends StrictSchema = StrictSchema>(schema: S, type: keyof S['types'], payload: unknown): {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
errors: ValidationErrors;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
7
19
|
//# sourceMappingURL=validation.d.ts.map
|