@based/schema 5.0.0-alpha.8 → 5.0.0-alpha.9
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 +5 -1
- package/dist/def/defaultMap.d.ts +3 -0
- package/dist/def/defaultMap.js +27 -0
- package/dist/def/fillEmptyMain.js +2 -5
- package/dist/def/index.d.ts +2 -0
- package/dist/def/index.js +2 -0
- package/dist/def/readFromPacked.js +5 -2
- package/dist/def/typeDef.js +13 -3
- package/dist/def/types.d.ts +4 -5
- package/dist/def/types.js +2 -33
- package/dist/def/validation.d.ts +5 -0
- package/dist/def/validation.js +213 -0
- package/dist/lang.d.ts +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
package/dist/def/addEdges.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getPropType } from '../index.js';
|
|
2
2
|
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, ENUM, } from './types.js';
|
|
3
3
|
import { getPropLen, isSeparate } from './utils.js';
|
|
4
|
+
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
4
5
|
export const addEdges = (prop, refProp) => {
|
|
5
6
|
for (const key in refProp) {
|
|
6
7
|
if (key[0] === '$') {
|
|
@@ -18,12 +19,15 @@ export const addEdges = (prop, refProp) => {
|
|
|
18
19
|
if (separate) {
|
|
19
20
|
prop.edgesSeperateCnt++;
|
|
20
21
|
}
|
|
22
|
+
const typeIndex = TYPE_INDEX_MAP[edgeType];
|
|
23
|
+
// add default
|
|
21
24
|
const edge = {
|
|
22
25
|
__isPropDef: true,
|
|
23
26
|
__isEdge: true,
|
|
24
27
|
prop: separate ? prop.edgesSeperateCnt : 0,
|
|
28
|
+
validation: edgeProp.validate ?? VALIDATION_MAP[typeIndex] ?? defaultValidation,
|
|
25
29
|
name: key,
|
|
26
|
-
typeIndex
|
|
30
|
+
typeIndex,
|
|
27
31
|
len,
|
|
28
32
|
separate,
|
|
29
33
|
path: [...prop.path, key],
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TYPE_INDEX_MAP } from './types.js';
|
|
2
|
+
// TODO update defaults
|
|
3
|
+
export const DEFAULT_MAP = {
|
|
4
|
+
[TYPE_INDEX_MAP.alias]: '',
|
|
5
|
+
[TYPE_INDEX_MAP.binary]: undefined,
|
|
6
|
+
[TYPE_INDEX_MAP.boolean]: false,
|
|
7
|
+
[TYPE_INDEX_MAP.cardinality]: 0,
|
|
8
|
+
[TYPE_INDEX_MAP.number]: 0,
|
|
9
|
+
[TYPE_INDEX_MAP.timestamp]: 0,
|
|
10
|
+
[TYPE_INDEX_MAP.enum]: 0,
|
|
11
|
+
[TYPE_INDEX_MAP.id]: 0,
|
|
12
|
+
[TYPE_INDEX_MAP.int16]: 0,
|
|
13
|
+
[TYPE_INDEX_MAP.int32]: 0,
|
|
14
|
+
[TYPE_INDEX_MAP.int8]: 0,
|
|
15
|
+
[TYPE_INDEX_MAP.uint8]: 0,
|
|
16
|
+
[TYPE_INDEX_MAP.uint16]: 0,
|
|
17
|
+
[TYPE_INDEX_MAP.uint32]: 0,
|
|
18
|
+
[TYPE_INDEX_MAP.json]: undefined,
|
|
19
|
+
[TYPE_INDEX_MAP.microbuffer]: undefined,
|
|
20
|
+
[TYPE_INDEX_MAP.reference]: undefined,
|
|
21
|
+
[TYPE_INDEX_MAP.references]: [],
|
|
22
|
+
[TYPE_INDEX_MAP.string]: '',
|
|
23
|
+
[TYPE_INDEX_MAP.aliases]: [],
|
|
24
|
+
[TYPE_INDEX_MAP.text]: '',
|
|
25
|
+
[TYPE_INDEX_MAP.vector]: undefined, // maybe not can set a vec with 0
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=defaultMap.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BINARY, BOOLEAN,
|
|
1
|
+
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from './types.js';
|
|
2
2
|
// Lets add validation of values in here - need to validate DEFAULT!
|
|
3
3
|
export const ENCODER = new TextEncoder();
|
|
4
4
|
export const fillEmptyMain = (vals, mainLen) => {
|
|
@@ -23,10 +23,7 @@ export const fillEmptyMain = (vals, mainLen) => {
|
|
|
23
23
|
mainEmpty[s] = val;
|
|
24
24
|
mainEmpty[s + 1] = val >>>= 8;
|
|
25
25
|
}
|
|
26
|
-
else if (t === NUMBER ||
|
|
27
|
-
t === TIMESTAMP ||
|
|
28
|
-
t === CREATED ||
|
|
29
|
-
t === UPDATED) {
|
|
26
|
+
else if (t === NUMBER || t === TIMESTAMP) {
|
|
30
27
|
const view = new DataView(mainEmpty.buffer, s, 8);
|
|
31
28
|
view.setFloat64(0, val, true);
|
|
32
29
|
}
|
package/dist/def/index.d.ts
CHANGED
package/dist/def/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REVERSE_SIZE_MAP } from './types.js';
|
|
2
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
|
+
import { VALIDATION_MAP } from './validation.js';
|
|
2
4
|
export const readFromPacked = (packed) => {
|
|
3
5
|
const size = (packed[0] | (packed[1] << 8)) >>> 0;
|
|
4
6
|
const props = [];
|
|
@@ -49,7 +51,6 @@ export const readFromPacked = (packed) => {
|
|
|
49
51
|
// Text not supported yet
|
|
50
52
|
// Ref not supported yet
|
|
51
53
|
// compression: 1 (0)
|
|
52
|
-
// YET
|
|
53
54
|
const result = {
|
|
54
55
|
cnt: 0,
|
|
55
56
|
checksum: 0,
|
|
@@ -99,6 +100,7 @@ export const readFromPacked = (packed) => {
|
|
|
99
100
|
prop: p.prop,
|
|
100
101
|
separate: false,
|
|
101
102
|
__isPropDef: true,
|
|
103
|
+
validation: VALIDATION_MAP[p.typeIndex],
|
|
102
104
|
start: s,
|
|
103
105
|
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
104
106
|
typeIndex: p.typeIndex,
|
|
@@ -114,6 +116,7 @@ export const readFromPacked = (packed) => {
|
|
|
114
116
|
prop: p.prop,
|
|
115
117
|
separate: true,
|
|
116
118
|
__isPropDef: true,
|
|
119
|
+
validation: VALIDATION_MAP[p.typeIndex],
|
|
117
120
|
start: 0,
|
|
118
121
|
typeIndex: p.typeIndex,
|
|
119
122
|
default: DEFAULT_MAP[p.typeIndex], // tmp
|
package/dist/def/typeDef.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isPropType, getPropType, } from '../index.js';
|
|
2
2
|
import { setByPath } from '@saulx/utils';
|
|
3
|
-
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE,
|
|
3
|
+
import { TYPE_INDEX_MAP, REFERENCES, REFERENCE, } from './types.js';
|
|
4
|
+
import { DEFAULT_MAP } from './defaultMap.js';
|
|
4
5
|
import { makePacked } from './makePacked.js';
|
|
5
6
|
import { makeSeparateTextSort } from './makeSeparateTextSort.js';
|
|
6
7
|
import { makeSeparateSort } from './makeSeparateSort.js';
|
|
@@ -10,6 +11,7 @@ import { addEdges } from './addEdges.js';
|
|
|
10
11
|
import { createEmptyDef } from './createEmptyDef.js';
|
|
11
12
|
import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
|
|
12
13
|
import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
|
|
14
|
+
import { defaultValidation, VALIDATION_MAP } from './validation.js';
|
|
13
15
|
export const DEFAULT_BLOCK_CAPACITY = 100_000;
|
|
14
16
|
export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById) => {
|
|
15
17
|
for (const field in schemaTypesParsed) {
|
|
@@ -84,16 +86,24 @@ export const createSchemaTypeDef = (typeName, type, parsed, locales, result = cr
|
|
|
84
86
|
separateSortText++;
|
|
85
87
|
}
|
|
86
88
|
const isseparate = isSeparate(schemaProp, len);
|
|
89
|
+
const typeIndex = TYPE_INDEX_MAP[propType];
|
|
87
90
|
const prop = {
|
|
88
|
-
typeIndex
|
|
91
|
+
typeIndex,
|
|
89
92
|
__isPropDef: true,
|
|
90
93
|
separate: isseparate,
|
|
91
94
|
path: propPath,
|
|
92
95
|
start: 0,
|
|
96
|
+
validation: schemaProp.validate ?? VALIDATION_MAP[typeIndex] ?? defaultValidation,
|
|
93
97
|
len,
|
|
94
|
-
default: schemaProp.default ?? DEFAULT_MAP[
|
|
98
|
+
default: schemaProp.default ?? DEFAULT_MAP[typeIndex],
|
|
95
99
|
prop: isseparate ? ++result.cnt : 0,
|
|
96
100
|
};
|
|
101
|
+
if (schemaProp.max) {
|
|
102
|
+
prop.max = schemaProp.max;
|
|
103
|
+
}
|
|
104
|
+
if (schemaProp.min) {
|
|
105
|
+
prop.min = schemaProp.min;
|
|
106
|
+
}
|
|
97
107
|
if (isPropType('enum', schemaProp)) {
|
|
98
108
|
prop.enum = Array.isArray(schemaProp) ? schemaProp : schemaProp.enum;
|
|
99
109
|
prop.reverseEnum = {};
|
package/dist/def/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { LangCode, SchemaLocales } from '../index.js';
|
|
2
|
+
import { Validation } from './validation.js';
|
|
2
3
|
export declare const NULL = 0;
|
|
3
4
|
export declare const TIMESTAMP = 1;
|
|
4
|
-
export declare const CREATED = 2;
|
|
5
|
-
export declare const UPDATED = 3;
|
|
6
5
|
export declare const NUMBER = 4;
|
|
7
6
|
export declare const CARDINALITY = 5;
|
|
8
7
|
export declare const INT8 = 20;
|
|
@@ -34,8 +33,6 @@ export declare const TYPE_INDEX_MAP: {
|
|
|
34
33
|
reference: number;
|
|
35
34
|
timestamp: number;
|
|
36
35
|
boolean: number;
|
|
37
|
-
created: number;
|
|
38
|
-
updated: number;
|
|
39
36
|
number: number;
|
|
40
37
|
string: number;
|
|
41
38
|
text: number;
|
|
@@ -69,6 +66,7 @@ export type PropDef = {
|
|
|
69
66
|
inversePropNumber?: number;
|
|
70
67
|
enum?: any[];
|
|
71
68
|
dependent?: boolean;
|
|
69
|
+
validation: Validation;
|
|
72
70
|
default: any;
|
|
73
71
|
edgeMainLen?: 0;
|
|
74
72
|
reverseEnum?: {
|
|
@@ -86,6 +84,8 @@ export type PropDef = {
|
|
|
86
84
|
};
|
|
87
85
|
edgeMainEmpty?: Uint8Array;
|
|
88
86
|
__isEdge?: boolean;
|
|
87
|
+
max?: number;
|
|
88
|
+
min?: number;
|
|
89
89
|
};
|
|
90
90
|
export type PropDefEdge = Partial<PropDef> & {
|
|
91
91
|
__isPropDef: true;
|
|
@@ -152,7 +152,6 @@ export type SchemaTypeDef = {
|
|
|
152
152
|
localeSize: number;
|
|
153
153
|
};
|
|
154
154
|
export declare const SIZE_MAP: Record<InternalSchemaProp, number>;
|
|
155
|
-
export declare const DEFAULT_MAP: Record<TypeIndex, any>;
|
|
156
155
|
export declare const REVERSE_SIZE_MAP: Record<TypeIndex, number>;
|
|
157
156
|
export declare const REVERSE_TYPE_INDEX_MAP: Record<TypeIndex, InternalSchemaProp>;
|
|
158
157
|
export declare const ID_FIELD_DEF: PropDef;
|
package/dist/def/types.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// WARN: The following type codes are used in js and zig but selva has its own typing.
|
|
2
2
|
export const NULL = 0;
|
|
3
3
|
export const TIMESTAMP = 1;
|
|
4
|
-
export const CREATED = 2;
|
|
5
|
-
export const UPDATED = 3;
|
|
6
4
|
export const NUMBER = 4;
|
|
7
5
|
export const CARDINALITY = 5;
|
|
8
6
|
export const INT8 = 20;
|
|
@@ -34,8 +32,6 @@ export const TYPE_INDEX_MAP = {
|
|
|
34
32
|
reference: REFERENCE,
|
|
35
33
|
timestamp: TIMESTAMP,
|
|
36
34
|
boolean: BOOLEAN,
|
|
37
|
-
created: CREATED,
|
|
38
|
-
updated: UPDATED,
|
|
39
35
|
number: NUMBER,
|
|
40
36
|
string: STRING,
|
|
41
37
|
text: TEXT,
|
|
@@ -54,8 +50,6 @@ export const TYPE_INDEX_MAP = {
|
|
|
54
50
|
};
|
|
55
51
|
export const SIZE_MAP = {
|
|
56
52
|
timestamp: 8, // 64bit
|
|
57
|
-
created: 8,
|
|
58
|
-
updated: 8,
|
|
59
53
|
// double-precision 64-bit binary format IEEE 754 value
|
|
60
54
|
number: 8, // 64bit
|
|
61
55
|
int8: 1,
|
|
@@ -83,33 +77,6 @@ const reverseMap = {};
|
|
|
83
77
|
for (const k in TYPE_INDEX_MAP) {
|
|
84
78
|
reverseMap[TYPE_INDEX_MAP[k]] = k;
|
|
85
79
|
}
|
|
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
80
|
export const REVERSE_SIZE_MAP = {};
|
|
114
81
|
for (const k in SIZE_MAP) {
|
|
115
82
|
REVERSE_SIZE_MAP[TYPE_INDEX_MAP[k]] = SIZE_MAP[k];
|
|
@@ -123,6 +90,7 @@ export const ID_FIELD_DEF = {
|
|
|
123
90
|
prop: 255,
|
|
124
91
|
default: 0,
|
|
125
92
|
len: 4,
|
|
93
|
+
validation: () => true,
|
|
126
94
|
__isPropDef: true,
|
|
127
95
|
};
|
|
128
96
|
export const EMPTY_MICRO_BUFFER = {
|
|
@@ -133,6 +101,7 @@ export const EMPTY_MICRO_BUFFER = {
|
|
|
133
101
|
default: undefined,
|
|
134
102
|
prop: 0,
|
|
135
103
|
len: 1,
|
|
104
|
+
validation: () => true,
|
|
136
105
|
__isPropDef: true,
|
|
137
106
|
};
|
|
138
107
|
export const getPropTypeName = (propType) => {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TypeIndex, PropDef, PropDefEdge } from './types.js';
|
|
2
|
+
export type Validation = (payload: any, prop: PropDef | PropDefEdge) => boolean;
|
|
3
|
+
export declare const VALIDATION_MAP: Record<TypeIndex, Validation>;
|
|
4
|
+
export declare const defaultValidation: () => boolean;
|
|
5
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { TYPE_INDEX_MAP } from './types.js';
|
|
2
|
+
export const VALIDATION_MAP = {
|
|
3
|
+
[TYPE_INDEX_MAP.alias]: (value) => {
|
|
4
|
+
if (typeof value !== 'string') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
},
|
|
9
|
+
[TYPE_INDEX_MAP.binary]: (value) => {
|
|
10
|
+
if (value instanceof Uint8Array) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
},
|
|
15
|
+
[TYPE_INDEX_MAP.boolean]: (value) => {
|
|
16
|
+
if (typeof value !== 'boolean') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
[TYPE_INDEX_MAP.cardinality]: (val) => {
|
|
22
|
+
return (typeof val === 'string' ||
|
|
23
|
+
(val instanceof Uint8Array && val.byteLength === 8));
|
|
24
|
+
},
|
|
25
|
+
[TYPE_INDEX_MAP.timestamp]: (value, t) => {
|
|
26
|
+
if (typeof value === 'string') {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (t.min !== undefined && value < t.min) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (t.max !== undefined && value > t.max) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
[TYPE_INDEX_MAP.int16]: (value, t) => {
|
|
41
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (value > 32767 || value < -32768) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (t.min !== undefined && value < t.min) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (t.max !== undefined && value > t.max) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
[TYPE_INDEX_MAP.int32]: (value, t) => {
|
|
56
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (value > 2147483647 || value < -2147483648) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (t.min !== undefined && value < t.min) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (t.max !== undefined && value > t.max) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
[TYPE_INDEX_MAP.int8]: (value, t) => {
|
|
71
|
+
// use % for steps size
|
|
72
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (value > 127 || value < -128) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (t.min !== undefined && value < t.min) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (t.max !== undefined && value > t.max) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
},
|
|
86
|
+
[TYPE_INDEX_MAP.uint8]: (value, t) => {
|
|
87
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (value > 255 || value < 0) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (t.min !== undefined && value < t.min) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (t.max !== undefined && value > t.max) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
[TYPE_INDEX_MAP.uint16]: (value, t) => {
|
|
102
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (value > 65535 || value < 0) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (t.min !== undefined && value < t.min) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (t.max !== undefined && value > t.max) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
},
|
|
116
|
+
[TYPE_INDEX_MAP.uint32]: (value, t) => {
|
|
117
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (value > 4294967295 || value < 0) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (t.min !== undefined && value < t.min) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (t.max !== undefined && value > t.max) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
},
|
|
131
|
+
[TYPE_INDEX_MAP.number]: (value, t) => {
|
|
132
|
+
if (typeof value !== 'number') {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (t.min !== undefined && value < t.min) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
if (t.max !== undefined && value > t.max) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
},
|
|
143
|
+
[TYPE_INDEX_MAP.enum]: (value, prop) => {
|
|
144
|
+
if (value === null) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
const arr = prop.enum;
|
|
148
|
+
for (let i = 0; i < arr.length; i++) {
|
|
149
|
+
if (value === arr[i]) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
},
|
|
155
|
+
[TYPE_INDEX_MAP.id]: (value) => {
|
|
156
|
+
if (typeof value !== 'number' || value % 1 !== 0) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
},
|
|
161
|
+
[TYPE_INDEX_MAP.json]: (value) => {
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
[TYPE_INDEX_MAP.microbuffer]: (value) => {
|
|
165
|
+
if (!(value instanceof Uint8Array)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
},
|
|
170
|
+
[TYPE_INDEX_MAP.reference]: (value) => {
|
|
171
|
+
// if (typeof value !== 'number' && value != null) {
|
|
172
|
+
// return false
|
|
173
|
+
// }
|
|
174
|
+
return true;
|
|
175
|
+
},
|
|
176
|
+
[TYPE_INDEX_MAP.references]: (v) => {
|
|
177
|
+
if (typeof v !== 'number') {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
if (v === 0) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
[TYPE_INDEX_MAP.string]: (value, t) => {
|
|
186
|
+
// add max etc all here - make a ref to the original SCHEMA
|
|
187
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
},
|
|
192
|
+
[TYPE_INDEX_MAP.aliases]: (value) => {
|
|
193
|
+
if (!Array.isArray(value)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const len = value.length;
|
|
197
|
+
for (let i = 0; i < len; i++) {
|
|
198
|
+
if (typeof value[i] !== 'string') {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
},
|
|
204
|
+
[TYPE_INDEX_MAP.vector]: (value) => {
|
|
205
|
+
// Array should be supported
|
|
206
|
+
if (!(value instanceof Float32Array)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
export const defaultValidation = () => true;
|
|
213
|
+
//# sourceMappingURL=validation.js.map
|
package/dist/lang.d.ts
CHANGED
|
@@ -145,7 +145,7 @@ declare const langCodes: {
|
|
|
145
145
|
readonly yo: 143;
|
|
146
146
|
readonly zu: 144;
|
|
147
147
|
};
|
|
148
|
-
export declare const langCodesMap: Map<string, 0 |
|
|
148
|
+
export declare const langCodesMap: Map<string, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144>;
|
|
149
149
|
export declare const inverseLangMap: Map<any, any>;
|
|
150
150
|
export type LangName = keyof typeof langCodes;
|
|
151
151
|
export type LangCode = (typeof langCodes)[LangName];
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LangName } from './lang.js';
|
|
2
|
+
import { Validation } from './def/validation.js';
|
|
2
3
|
type Role = 'title' | 'source' | 'media' | string;
|
|
3
4
|
export declare const numberDisplays: readonly ["short", "human", "ratio", "bytes", "euro", "dollar", "pound", "meter"];
|
|
4
5
|
export declare const dateDisplays: readonly ["date", "date-time", "date-time-text", "date-time-human", "time", "time-precise"];
|
|
@@ -14,6 +15,7 @@ type QueryFn = Function;
|
|
|
14
15
|
type PropValues = {
|
|
15
16
|
type?: string;
|
|
16
17
|
default?: any;
|
|
18
|
+
validation?: Validation;
|
|
17
19
|
};
|
|
18
20
|
type Prop<V extends PropValues> = {
|
|
19
21
|
required?: boolean;
|