@based/schema 5.0.0-alpha.9 → 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.
- package/dist/def/addEdges.js +26 -3
- package/dist/def/createEmptyDef.d.ts +13 -9
- package/dist/def/createEmptyDef.js +7 -3
- package/dist/def/defaultMap.js +28 -24
- package/dist/def/fillEmptyMain.d.ts +2 -2
- package/dist/def/fillEmptyMain.js +13 -4
- package/dist/def/index.d.ts +0 -1
- package/dist/def/index.js +0 -1
- package/dist/def/makeSeparateSort.js +6 -6
- package/dist/def/makeSeparateTextSort.js +12 -12
- package/dist/def/refSet.d.ts +7 -0
- package/dist/def/refSet.js +25 -0
- package/dist/def/selvaBuffer.js +77 -28
- package/dist/def/typeDef.d.ts +9 -3
- package/dist/def/typeDef.js +136 -59
- package/dist/def/typeIndexes.d.ts +40 -0
- package/dist/def/typeIndexes.js +50 -0
- package/dist/def/types.d.ts +36 -57
- package/dist/def/types.js +22 -28
- package/dist/def/utils.d.ts +5 -3
- package/dist/def/utils.js +44 -2
- package/dist/def/validation.d.ts +2 -0
- package/dist/def/validation.js +89 -41
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/infer.d.ts +82 -0
- package/dist/infer.js +5 -0
- package/dist/lang.d.ts +3 -1
- package/dist/lang.js +6 -0
- package/dist/parse/assert.d.ts +4 -0
- package/dist/parse/assert.js +19 -2
- package/dist/parse/index.d.ts +2 -0
- package/dist/parse/index.js +58 -4
- package/dist/parse/props.d.ts +1 -0
- package/dist/parse/props.js +171 -54
- package/dist/serialize.d.ts +14 -0
- package/dist/serialize.js +543 -0
- package/dist/types.d.ts +74 -20
- package/dist/types.js +3 -1
- package/package.json +6 -4
- package/dist/def/getPropLen.d.ts +0 -3
- package/dist/def/getPropLen.js +0 -23
- package/dist/def/makePacked.d.ts +0 -3
- package/dist/def/makePacked.js +0 -50
- package/dist/def/readFromPacked.d.ts +0 -3
- package/dist/def/readFromPacked.js +0 -140
- package/dist/mermaid.d.ts +0 -3
- package/dist/mermaid.js +0 -24
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LangName } from './lang.js';
|
|
2
|
-
import { Validation } from './def/validation.js';
|
|
1
|
+
import type { LangName } from './lang.js';
|
|
2
|
+
import type { Validation } from './def/validation.js';
|
|
3
3
|
type Role = 'title' | 'source' | 'media' | string;
|
|
4
4
|
export declare const numberDisplays: readonly ["short", "human", "ratio", "bytes", "euro", "dollar", "pound", "meter"];
|
|
5
5
|
export declare const dateDisplays: readonly ["date", "date-time", "date-time-text", "date-time-human", "time", "time-precise"];
|
|
6
|
-
export declare const stringFormats: readonly ["alpha", "alphaLocales", "alphanumeric", "alphanumericLocales", "ascii", "base32", "base58", "base64", "BIC", "btcAddress", "clike", "code", "creditCard", "css", "currency", "dataURI", "EAN", "email", "ethereumAddress", "FQDN", "hexadecimal", "hexColor", "HSL", "html", "IBAN", "identityCard", "IMEI", "IP", "IPRange", "ISBN", "ISIN", "ISO31661Alpha2", "ISO31661Alpha3", "ISO4217", "ISO6391", "ISO8601", "ISRC", "ISSN", "javascript", "json", "JWT", "latLong", "licensePlate", "lowercase", "luhnNumber", "MACAddress", "magnetURI", "markdown", "MD5", "mimeType", "mobilePhone", "mobilePhoneLocales", "octal", "passportNumber", "port", "postalCode", "postalCodeLocales", "python", "RFC3339", "rgbColor", "rust", "semVer", "slug", "
|
|
6
|
+
export declare const stringFormats: readonly ["alpha", "alphaLocales", "alphanumeric", "alphanumericLocales", "ascii", "base32", "base58", "base64", "BIC", "btcAddress", "clike", "code", "creditCard", "css", "currency", "dataURI", "EAN", "email", "ethereumAddress", "FQDN", "hexadecimal", "hexColor", "HSL", "html", "IBAN", "identityCard", "IMEI", "IP", "IPRange", "ISBN", "ISIN", "ISO31661Alpha2", "ISO31661Alpha3", "ISO4217", "ISO6391", "ISO8601", "ISRC", "ISSN", "javascript", "json", "JWT", "latLong", "licensePlate", "lowercase", "luhnNumber", "MACAddress", "magnetURI", "markdown", "MD5", "mimeType", "mobilePhone", "mobilePhoneLocales", "octal", "password", "passportNumber", "port", "postalCode", "postalCodeLocales", "python", "RFC3339", "rgbColor", "rust", "semVer", "slug", "surrogatePair", "taxID", "typescript", "uppercase", "URL", "UUID", "VAT", "multiline"];
|
|
7
7
|
type DateDisplay = (typeof dateDisplays)[number];
|
|
8
8
|
type NumberDisplay = (typeof numberDisplays)[number] | `round-${number}`;
|
|
9
9
|
type StringFormat = (typeof stringFormats)[number];
|
|
@@ -26,6 +26,7 @@ type Prop<V extends PropValues> = {
|
|
|
26
26
|
role?: Role;
|
|
27
27
|
readOnly?: boolean;
|
|
28
28
|
examples?: string[];
|
|
29
|
+
validation?: Validation;
|
|
29
30
|
} & V;
|
|
30
31
|
type EnumItem = string | number | boolean;
|
|
31
32
|
type NeverInItems = {
|
|
@@ -33,16 +34,19 @@ type NeverInItems = {
|
|
|
33
34
|
};
|
|
34
35
|
export type SchemaReferences = Prop<{
|
|
35
36
|
type?: 'references';
|
|
37
|
+
default?: number[];
|
|
36
38
|
items: SchemaReference & NeverInItems;
|
|
37
39
|
}>;
|
|
38
40
|
export type SchemaReferencesOneWay = Prop<{
|
|
39
41
|
type?: 'references';
|
|
42
|
+
default?: number[];
|
|
40
43
|
items: SchemaReferenceOneWay & NeverInItems;
|
|
41
44
|
}>;
|
|
42
45
|
export type SchemaText = Prop<{
|
|
43
46
|
type: 'text';
|
|
44
47
|
default?: Record<string, string>;
|
|
45
48
|
format?: StringFormat;
|
|
49
|
+
compression?: 'none' | 'deflate';
|
|
46
50
|
}>;
|
|
47
51
|
type NumberType = 'number' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32';
|
|
48
52
|
export type SchemaNumber = Prop<{
|
|
@@ -68,7 +72,7 @@ export type SchemaString = Prop<{
|
|
|
68
72
|
}>;
|
|
69
73
|
export type SchemaBinary = Prop<{
|
|
70
74
|
type: 'binary';
|
|
71
|
-
default?:
|
|
75
|
+
default?: Uint8Array;
|
|
72
76
|
maxBytes?: number;
|
|
73
77
|
mime?: Mime;
|
|
74
78
|
format?: StringFormat;
|
|
@@ -83,31 +87,56 @@ export type SchemaBoolean = Prop<{
|
|
|
83
87
|
}>;
|
|
84
88
|
export type SchemaCardinality = Prop<{
|
|
85
89
|
type: 'cardinality';
|
|
86
|
-
default?: string;
|
|
87
90
|
maxBytes?: number;
|
|
88
91
|
mime?: Mime;
|
|
89
92
|
format?: NumberDisplay;
|
|
90
93
|
}>;
|
|
94
|
+
type VectorDefaultType = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
95
|
+
export type SchemaVectorBaseType = NumberType | 'float32' | 'float64';
|
|
91
96
|
export type SchemaVector = Prop<{
|
|
92
97
|
type: 'vector';
|
|
93
|
-
default?:
|
|
98
|
+
default?: VectorDefaultType;
|
|
99
|
+
/**
|
|
100
|
+
* Number of elements in the vector.
|
|
101
|
+
*/
|
|
94
102
|
size: number;
|
|
103
|
+
/**
|
|
104
|
+
* Base type of the vector.
|
|
105
|
+
* float64 == number
|
|
106
|
+
*/
|
|
107
|
+
baseType?: SchemaVectorBaseType;
|
|
108
|
+
}>;
|
|
109
|
+
export type SchemaColvec = Prop<{
|
|
110
|
+
type: 'colvec';
|
|
111
|
+
default?: VectorDefaultType;
|
|
112
|
+
/**
|
|
113
|
+
* Number of elements in the vector.
|
|
114
|
+
*/
|
|
115
|
+
size: number;
|
|
116
|
+
/**
|
|
117
|
+
* Base type of the vector.
|
|
118
|
+
* float64 == number
|
|
119
|
+
*/
|
|
120
|
+
baseType?: SchemaVectorBaseType;
|
|
95
121
|
}>;
|
|
96
122
|
export type SchemaTimestamp = Prop<{
|
|
97
123
|
type: 'timestamp';
|
|
98
|
-
default?: number | Date;
|
|
124
|
+
default?: number | Date | string;
|
|
99
125
|
on?: 'create' | 'update';
|
|
100
126
|
display?: DateDisplay;
|
|
127
|
+
min?: number | string;
|
|
128
|
+
max?: number | string;
|
|
129
|
+
step?: number | 'any' | string;
|
|
101
130
|
}>;
|
|
102
131
|
export type SchemaReferenceOneWay = Prop<{
|
|
103
132
|
type?: 'reference';
|
|
104
|
-
default?:
|
|
133
|
+
default?: number;
|
|
105
134
|
ref: string;
|
|
106
135
|
mime?: Mime;
|
|
107
136
|
}>;
|
|
108
137
|
export type SchemaReference = Prop<{
|
|
109
138
|
type?: 'reference';
|
|
110
|
-
default?:
|
|
139
|
+
default?: number;
|
|
111
140
|
ref: string;
|
|
112
141
|
prop: string;
|
|
113
142
|
dependent?: boolean;
|
|
@@ -129,7 +158,7 @@ export type SchemaReferencesWithQuery = SchemaReferencesOneWay & {
|
|
|
129
158
|
};
|
|
130
159
|
export type SchemaEnum = Prop<{
|
|
131
160
|
type?: 'enum';
|
|
132
|
-
default?: EnumItem;
|
|
161
|
+
default?: EnumItem | undefined;
|
|
133
162
|
enum: EnumItem[];
|
|
134
163
|
}>;
|
|
135
164
|
export type SchemaAlias = Omit<SchemaString, 'type'> & {
|
|
@@ -144,21 +173,34 @@ export type SchemaSet<ItemsType extends SetItems = SetItems> = Prop<{
|
|
|
144
173
|
} ? ItemsType['default'][] : undefined;
|
|
145
174
|
items: ItemsType & NeverInItems;
|
|
146
175
|
}>;
|
|
147
|
-
type NonRefSchemaProps<isStrict = false> = SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaAlias | SchemaText | SchemaEnum | SchemaJson | SchemaBinary | SchemaCardinality | SchemaVector | (isStrict extends true ? SchemaSet<SetItems<true>> : SchemaPropShorthand | SchemaSet);
|
|
176
|
+
type NonRefSchemaProps<isStrict = false> = SchemaTimestamp | SchemaBoolean | SchemaNumber | SchemaString | SchemaAlias | SchemaText | SchemaEnum | SchemaJson | SchemaBinary | SchemaCardinality | SchemaVector | SchemaColvec | (isStrict extends true ? SchemaSet<SetItems<true>> : SchemaPropShorthand | SchemaSet);
|
|
148
177
|
export type SchemaProp<isStrict = false> = SchemaReferencesWithQuery | SchemaReferenceWithQuery | NonRefSchemaProps<isStrict> | SchemaReferences | SchemaReference | SchemaObject | SchemaBinary;
|
|
149
178
|
export type SchemaPropOneWay<isStrict = false> = SchemaReferencesOneWay | SchemaReferenceOneWay | SchemaObjectOneWay | NonRefSchemaProps<isStrict>;
|
|
150
179
|
export type SchemaAnyProp = SchemaPropOneWay | SchemaProp;
|
|
151
|
-
export type SchemaHook = string | Function;
|
|
152
180
|
export type SchemaProps<isStrict = false> = Record<AllowedKey, SchemaProp<isStrict>> & {
|
|
153
181
|
id?: never;
|
|
154
182
|
};
|
|
183
|
+
type BasedDbQuery = any;
|
|
184
|
+
type Operator = string;
|
|
185
|
+
export type SchemaHooks = {
|
|
186
|
+
create?: (payload: Record<string, any>) => void | Record<string, any>;
|
|
187
|
+
update?: (payload: Record<string, any>) => void | Record<string, any>;
|
|
188
|
+
read?: (result: Record<string, any>) => void | null | Record<string, any>;
|
|
189
|
+
search?: (query: BasedDbQuery, fields: Set<string>) => void;
|
|
190
|
+
include?: (query: BasedDbQuery, fields: Map<string, {
|
|
191
|
+
field: string;
|
|
192
|
+
opts?: any;
|
|
193
|
+
}>) => void;
|
|
194
|
+
filter?: (query: BasedDbQuery, field: string, operator: Operator, value: any) => void;
|
|
195
|
+
groupBy?: (query: BasedDbQuery, field: string) => void;
|
|
196
|
+
aggregate?: (query: BasedDbQuery, fields: Set<string>) => void;
|
|
197
|
+
};
|
|
155
198
|
type GenericSchemaType<isStrict = false> = {
|
|
156
|
-
hooks?:
|
|
157
|
-
create?: SchemaHook;
|
|
158
|
-
update?: SchemaHook;
|
|
159
|
-
delete?: SchemaHook;
|
|
160
|
-
};
|
|
199
|
+
hooks?: SchemaHooks;
|
|
161
200
|
id?: number;
|
|
201
|
+
blockCapacity?: number;
|
|
202
|
+
insertOnly?: boolean;
|
|
203
|
+
partial?: boolean;
|
|
162
204
|
props: SchemaProps<isStrict>;
|
|
163
205
|
};
|
|
164
206
|
export type StrictSchemaType = GenericSchemaType<true>;
|
|
@@ -172,16 +214,25 @@ export type SchemaTypes<isStrict = false> = Record<SchemaTypeName, SchemaType<is
|
|
|
172
214
|
export type SchemaPropsOneWay<isStrict = false> = Record<AllowedKey, SchemaPropOneWay<isStrict>> & {
|
|
173
215
|
id?: never;
|
|
174
216
|
};
|
|
217
|
+
type MigrateFn = (node: Record<string, any>) => Record<string, any> | [string, Record<string, any>];
|
|
218
|
+
export type MigrateFns = Record<string, MigrateFn>;
|
|
175
219
|
type GenericSchema<isStrict = false> = {
|
|
220
|
+
version?: string;
|
|
176
221
|
types?: SchemaTypes<isStrict>;
|
|
177
222
|
props?: SchemaPropsOneWay<isStrict>;
|
|
178
223
|
locales?: Partial<SchemaLocales>;
|
|
224
|
+
defaultTimezone?: string;
|
|
225
|
+
migrations?: {
|
|
226
|
+
version: string;
|
|
227
|
+
migrate: MigrateFns;
|
|
228
|
+
}[];
|
|
179
229
|
};
|
|
180
230
|
export type StrictSchema = GenericSchema<true>;
|
|
181
|
-
export type
|
|
182
|
-
export type
|
|
231
|
+
export type NonStrictSchema = GenericSchema<false>;
|
|
232
|
+
export type Schema = NonStrictSchema | StrictSchema;
|
|
233
|
+
export type SchemaLocales = Record<LangName, true | {
|
|
183
234
|
required?: boolean;
|
|
184
|
-
fallback?: LangName
|
|
235
|
+
fallback?: LangName;
|
|
185
236
|
}>;
|
|
186
237
|
export type SchemaPropTypeMap = {
|
|
187
238
|
references: SchemaReferences;
|
|
@@ -198,8 +249,11 @@ export type SchemaPropTypeMap = {
|
|
|
198
249
|
binary: SchemaBinary;
|
|
199
250
|
cardinality: SchemaCardinality;
|
|
200
251
|
vector: SchemaVector;
|
|
252
|
+
colvec: SchemaColvec;
|
|
201
253
|
} & Record<NumberType, SchemaNumber>;
|
|
202
254
|
export type SchemaPropTypes = keyof SchemaPropTypeMap;
|
|
203
255
|
export declare const isPropType: <T extends SchemaPropTypes>(type: T, prop: SchemaProp) => prop is SchemaPropTypeMap[T];
|
|
256
|
+
export declare const MAX_ID = 4294967295;
|
|
257
|
+
export declare const MIN_ID = 1;
|
|
204
258
|
export {};
|
|
205
259
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
|
@@ -71,6 +71,7 @@ export const stringFormats = [
|
|
|
71
71
|
'mobilePhone',
|
|
72
72
|
'mobilePhoneLocales',
|
|
73
73
|
'octal',
|
|
74
|
+
'password',
|
|
74
75
|
'passportNumber',
|
|
75
76
|
'port',
|
|
76
77
|
'postalCode',
|
|
@@ -81,7 +82,6 @@ export const stringFormats = [
|
|
|
81
82
|
'rust',
|
|
82
83
|
'semVer',
|
|
83
84
|
'slug',
|
|
84
|
-
'strongPassword',
|
|
85
85
|
'surrogatePair',
|
|
86
86
|
'taxID',
|
|
87
87
|
'typescript',
|
|
@@ -95,4 +95,6 @@ export const stringFormats = [
|
|
|
95
95
|
export const isPropType = (type, prop) => {
|
|
96
96
|
return getPropType(prop) === type;
|
|
97
97
|
};
|
|
98
|
+
export const MAX_ID = 4294967295;
|
|
99
|
+
export const MIN_ID = 1;
|
|
98
100
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/schema",
|
|
3
|
-
"version": "5.0.0
|
|
4
|
-
"license": "MIT",
|
|
3
|
+
"version": "5.0.0",
|
|
5
4
|
"files": [
|
|
6
5
|
"dist",
|
|
7
6
|
"README.md",
|
|
@@ -11,6 +10,8 @@
|
|
|
11
10
|
"main": "./dist/index.js",
|
|
12
11
|
"exports": {
|
|
13
12
|
"./def": "./dist/def/index.js",
|
|
13
|
+
"./lang": "./dist/lang.js",
|
|
14
|
+
"./prop-types": "./dist/def/typeIndexes.js",
|
|
14
15
|
".": "./dist/index.js"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
@@ -24,12 +25,13 @@
|
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@saulx/prettier-config": "2.0.0",
|
|
26
27
|
"@saulx/tsconfig": "^1.1.0",
|
|
27
|
-
"@types/node": "22.5.3",
|
|
28
|
+
"@types/node": "^22.5.3",
|
|
28
29
|
"tsx": "^4.19.0",
|
|
29
30
|
"typescript": "^5.6.3"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@
|
|
33
|
+
"@based/utils": "^1.0.0",
|
|
34
|
+
"@std/semver": "npm:@jsr/std__semver@^1.0.5",
|
|
33
35
|
"picocolors": "^1.1.0"
|
|
34
36
|
}
|
|
35
37
|
}
|
package/dist/def/getPropLen.d.ts
DELETED
package/dist/def/getPropLen.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getPropType } from '../parse/utils.js';
|
|
2
|
-
import { isPropType } from '../types.js';
|
|
3
|
-
import { SIZE_MAP } from './types.js';
|
|
4
|
-
export function getPropLen(schemaProp) {
|
|
5
|
-
let len = SIZE_MAP[getPropType(schemaProp)];
|
|
6
|
-
if (isPropType('string', schemaProp) ||
|
|
7
|
-
isPropType('alias', schemaProp) ||
|
|
8
|
-
isPropType('cardinality', schemaProp)) {
|
|
9
|
-
if (typeof schemaProp === 'object') {
|
|
10
|
-
if (schemaProp.maxBytes < 61) {
|
|
11
|
-
len = schemaProp.maxBytes + 1;
|
|
12
|
-
}
|
|
13
|
-
else if ('max' in schemaProp && schemaProp.max < 31) {
|
|
14
|
-
len = schemaProp.max * 2 + 1;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
else if (isPropType('vector', schemaProp)) {
|
|
19
|
-
len = 4 * schemaProp.size;
|
|
20
|
-
}
|
|
21
|
-
return len;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=getPropLen.js.map
|
package/dist/def/makePacked.d.ts
DELETED
package/dist/def/makePacked.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export function makePacked(result, typeName, vals, len) {
|
|
2
|
-
const encoder = new TextEncoder();
|
|
3
|
-
result.buf = new Uint8Array(len);
|
|
4
|
-
result.buf[0] = result.idUint8[0];
|
|
5
|
-
result.buf[1] = result.idUint8[1];
|
|
6
|
-
const fieldNames = [];
|
|
7
|
-
const tNameBuf = encoder.encode(typeName);
|
|
8
|
-
fieldNames.push(tNameBuf);
|
|
9
|
-
let fieldNameLen = tNameBuf.byteLength + 1;
|
|
10
|
-
let i = 2;
|
|
11
|
-
if (result.mainLen) {
|
|
12
|
-
result.buf[i] = 0;
|
|
13
|
-
for (const f of vals) {
|
|
14
|
-
if (!f.separate) {
|
|
15
|
-
i++;
|
|
16
|
-
result.buf[i] = f.typeIndex;
|
|
17
|
-
const name = encoder.encode(f.path.join('.'));
|
|
18
|
-
fieldNames.push(name);
|
|
19
|
-
fieldNameLen += name.byteLength + 1;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
i++;
|
|
23
|
-
result.buf[i] = 0;
|
|
24
|
-
}
|
|
25
|
-
for (const f of vals) {
|
|
26
|
-
if (f.separate) {
|
|
27
|
-
i++;
|
|
28
|
-
result.buf[i] = f.prop;
|
|
29
|
-
i++;
|
|
30
|
-
result.buf[i] = f.typeIndex;
|
|
31
|
-
const name = encoder.encode(f.path.join('.'));
|
|
32
|
-
fieldNames.push(name);
|
|
33
|
-
fieldNameLen += name.byteLength + 1;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
result.propNames = new Uint8Array(fieldNameLen);
|
|
37
|
-
let lastWritten = 0;
|
|
38
|
-
for (const f of fieldNames) {
|
|
39
|
-
result.propNames[lastWritten] = f.byteLength;
|
|
40
|
-
result.propNames.set(f, lastWritten + 1);
|
|
41
|
-
lastWritten += f.byteLength + 1;
|
|
42
|
-
}
|
|
43
|
-
let bufLen = result.buf.length;
|
|
44
|
-
result.packed = new Uint8Array(2 + bufLen + result.propNames.length);
|
|
45
|
-
result.packed[0] = bufLen;
|
|
46
|
-
result.packed[1] = bufLen >>>= 8;
|
|
47
|
-
result.packed.set(result.buf, 2);
|
|
48
|
-
result.packed.set(result.propNames, result.buf.length + 2);
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=makePacked.js.map
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { REVERSE_SIZE_MAP } from './types.js';
|
|
2
|
-
import { DEFAULT_MAP } from './defaultMap.js';
|
|
3
|
-
import { VALIDATION_MAP } from './validation.js';
|
|
4
|
-
export const readFromPacked = (packed) => {
|
|
5
|
-
const size = (packed[0] | (packed[1] << 8)) >>> 0;
|
|
6
|
-
const props = [];
|
|
7
|
-
const b = packed.subarray(2, 2 + size);
|
|
8
|
-
let collectMain = false;
|
|
9
|
-
const mainProps = [];
|
|
10
|
-
const typeId = b.subarray(0, 2);
|
|
11
|
-
const typeIdNr = (typeId[0] | (typeId[1] << 8)) >>> 0;
|
|
12
|
-
for (let i = 2; i < b.length; i++) {
|
|
13
|
-
const prop = b[i];
|
|
14
|
-
if (collectMain) {
|
|
15
|
-
if (prop === 0) {
|
|
16
|
-
collectMain = false;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
mainProps.push({
|
|
20
|
-
prop: 0,
|
|
21
|
-
typeIndex: b[i],
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
if (prop == 0) {
|
|
27
|
-
collectMain = true;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
props.push({ prop, typeIndex: b[i + 1] });
|
|
31
|
-
i++;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const decoder = new TextDecoder();
|
|
36
|
-
const fields = [];
|
|
37
|
-
const f = packed.subarray(2 + size, packed.length);
|
|
38
|
-
for (let i = 0; i < f.length; i++) {
|
|
39
|
-
const size = f[i];
|
|
40
|
-
fields.push(decoder.decode(f.subarray(i + 1, i + 1 + size)));
|
|
41
|
-
i += size;
|
|
42
|
-
}
|
|
43
|
-
for (let i = 0; i < mainProps.length; i++) {
|
|
44
|
-
mainProps[i].path = fields[i + 1];
|
|
45
|
-
}
|
|
46
|
-
for (let i = 0; i < props.length; i++) {
|
|
47
|
-
props[i].path = fields[i + 1 + mainProps.length];
|
|
48
|
-
}
|
|
49
|
-
// Fixed len strings not supported
|
|
50
|
-
// Refs also not supported
|
|
51
|
-
// Text not supported yet
|
|
52
|
-
// Ref not supported yet
|
|
53
|
-
// compression: 1 (0)
|
|
54
|
-
const result = {
|
|
55
|
-
cnt: 0,
|
|
56
|
-
checksum: 0,
|
|
57
|
-
total: 0,
|
|
58
|
-
type: fields[0],
|
|
59
|
-
lastId: 0,
|
|
60
|
-
blockCapacity: 0,
|
|
61
|
-
mainLen: mainProps.length,
|
|
62
|
-
buf: b,
|
|
63
|
-
propNames: f,
|
|
64
|
-
packed,
|
|
65
|
-
props: {},
|
|
66
|
-
reverseProps: {}, // in a bit
|
|
67
|
-
id: typeIdNr,
|
|
68
|
-
idUint8: typeId,
|
|
69
|
-
separate: [],
|
|
70
|
-
main: {},
|
|
71
|
-
tree: {},
|
|
72
|
-
// not nessecary...
|
|
73
|
-
hasSeperateSort: false,
|
|
74
|
-
seperateSort: {
|
|
75
|
-
size: 0,
|
|
76
|
-
buffer: new Uint8Array([]),
|
|
77
|
-
bufferTmp: new Uint8Array([]),
|
|
78
|
-
props: [],
|
|
79
|
-
},
|
|
80
|
-
hasSeperateTextSort: false,
|
|
81
|
-
seperateTextSort: {
|
|
82
|
-
localeToIndex: new Map(),
|
|
83
|
-
localeStringToIndex: new Map(),
|
|
84
|
-
noUndefined: new Uint8Array([]),
|
|
85
|
-
size: 0,
|
|
86
|
-
buffer: new Uint8Array([]),
|
|
87
|
-
bufferTmp: new Uint8Array([]),
|
|
88
|
-
props: [],
|
|
89
|
-
},
|
|
90
|
-
mainEmpty: new Uint8Array([]),
|
|
91
|
-
mainEmptyAllZeroes: true,
|
|
92
|
-
// need this...
|
|
93
|
-
locales: {},
|
|
94
|
-
localeSize: 0,
|
|
95
|
-
};
|
|
96
|
-
let s = 0;
|
|
97
|
-
for (const p of mainProps) {
|
|
98
|
-
const len = REVERSE_SIZE_MAP[p.typeIndex];
|
|
99
|
-
const prop = {
|
|
100
|
-
prop: p.prop,
|
|
101
|
-
separate: false,
|
|
102
|
-
__isPropDef: true,
|
|
103
|
-
validation: VALIDATION_MAP[p.typeIndex],
|
|
104
|
-
start: s,
|
|
105
|
-
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
106
|
-
typeIndex: p.typeIndex,
|
|
107
|
-
path: p.path.split('.'),
|
|
108
|
-
len,
|
|
109
|
-
};
|
|
110
|
-
result.props[p.path] = prop;
|
|
111
|
-
result.main[prop.start] = prop;
|
|
112
|
-
s += len;
|
|
113
|
-
}
|
|
114
|
-
for (const p of props) {
|
|
115
|
-
const prop = {
|
|
116
|
-
prop: p.prop,
|
|
117
|
-
separate: true,
|
|
118
|
-
__isPropDef: true,
|
|
119
|
-
validation: VALIDATION_MAP[p.typeIndex],
|
|
120
|
-
start: 0,
|
|
121
|
-
typeIndex: p.typeIndex,
|
|
122
|
-
default: DEFAULT_MAP[p.typeIndex], // tmp
|
|
123
|
-
path: p.path.split('.'),
|
|
124
|
-
len: 0,
|
|
125
|
-
compression: 1,
|
|
126
|
-
};
|
|
127
|
-
result.props[p.path] = prop;
|
|
128
|
-
result.reverseProps[prop.prop] = prop;
|
|
129
|
-
}
|
|
130
|
-
// make this into a typeDef
|
|
131
|
-
// return {
|
|
132
|
-
// type: fields[0],
|
|
133
|
-
// fields,
|
|
134
|
-
// typeId,
|
|
135
|
-
// props,
|
|
136
|
-
// mainProps,
|
|
137
|
-
// }
|
|
138
|
-
return result;
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=readFromPacked.js.map
|
package/dist/mermaid.d.ts
DELETED
package/dist/mermaid.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getPropType } from './parse/utils.js';
|
|
2
|
-
import { isPropType } from './types.js';
|
|
3
|
-
export const mermaid = (schema) => {
|
|
4
|
-
let mermaid = 'classDiagram';
|
|
5
|
-
if (schema.types) {
|
|
6
|
-
for (const type in schema.types) {
|
|
7
|
-
for (const key in schema.types[type].props) {
|
|
8
|
-
const prop = schema.types[type].props[key];
|
|
9
|
-
const propType = getPropType(prop);
|
|
10
|
-
if (isPropType('reference', prop)) {
|
|
11
|
-
mermaid += `\n${type} --> ${prop.ref} : ${key}`;
|
|
12
|
-
}
|
|
13
|
-
else if (isPropType('references', prop)) {
|
|
14
|
-
mermaid += `\n${type} --> ${prop.items.ref} : ${key}[]`;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
mermaid += `\n${type} : ${propType} ${key}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return mermaid;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=mermaid.js.map
|