@based/schema 5.0.0-alpha.16 → 5.0.0-alpha.17

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.
@@ -1,7 +1,14 @@
1
1
  import { SchemaObject, StrictSchemaType, SchemaLocales } from '../index.js';
2
- import { SchemaTypeDef, SchemaTypesParsedById, SchemaTypesParsed } from './types.js';
2
+ import { SchemaTypeDef, SchemaTypesParsed } from './types.js';
3
3
  import { StrictSchema } from '../types.js';
4
4
  export declare const DEFAULT_BLOCK_CAPACITY = 100000;
5
- export declare const updateTypeDefs: (schema: StrictSchema, schemaTypesParsed: SchemaTypesParsed, schemaTypesParsedById: SchemaTypesParsedById) => void;
5
+ export declare const updateTypeDefs: (schema: StrictSchema) => {
6
+ schemaTypesParsed: {
7
+ [key: string]: SchemaTypeDef;
8
+ };
9
+ schemaTypesParsedById: {
10
+ [id: number]: SchemaTypeDef;
11
+ };
12
+ };
6
13
  export declare const createSchemaTypeDef: (typeName: string, type: StrictSchemaType | SchemaObject, parsed: SchemaTypesParsed, locales: Partial<SchemaLocales>, result?: Partial<SchemaTypeDef>, path?: string[], top?: boolean) => SchemaTypeDef;
7
14
  //# sourceMappingURL=typeDef.d.ts.map
@@ -8,11 +8,12 @@ import { getPropLen } from './getPropLen.js';
8
8
  import { isSeparate, parseMinMaxStep } from './utils.js';
9
9
  import { addEdges } from './addEdges.js';
10
10
  import { createEmptyDef } from './createEmptyDef.js';
11
- import { hashObjectIgnoreKeyOrder } from '@saulx/hash';
12
11
  import { fillEmptyMain, isZeroes } from './fillEmptyMain.js';
13
12
  import { defaultValidation, VALIDATION_MAP } from './validation.js';
14
13
  export const DEFAULT_BLOCK_CAPACITY = 100_000;
15
- export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById) => {
14
+ export const updateTypeDefs = (schema) => {
15
+ const schemaTypesParsed = {};
16
+ const schemaTypesParsedById = {};
16
17
  for (const field in schemaTypesParsed) {
17
18
  if (field in schema.types) {
18
19
  continue;
@@ -23,25 +24,17 @@ export const updateTypeDefs = (schema, schemaTypesParsed, schemaTypesParsedById)
23
24
  }
24
25
  for (const field in schema.types) {
25
26
  const type = schema.types[field];
26
- if (schemaTypesParsed[field] &&
27
- schemaTypesParsed[field].checksum === hashObjectIgnoreKeyOrder(type) // bit weird..
28
- ) {
29
- continue;
30
- }
31
- else {
32
- if (!type.id) {
33
- throw new Error('NEED ID ON TYPE');
34
- }
35
- const def = createSchemaTypeDef(field, type, schemaTypesParsed, schema.locales ?? {
36
- en: {},
37
- });
38
- // TODO this should come from somewhere else
39
- def.blockCapacity =
40
- field === '_root' ? 2147483647 : DEFAULT_BLOCK_CAPACITY;
41
- schemaTypesParsed[field] = def;
42
- schemaTypesParsedById[type.id] = def;
27
+ if (!type.id) {
28
+ throw new Error('NEED ID ON TYPE');
43
29
  }
30
+ const def = createSchemaTypeDef(field, type, schemaTypesParsed, schema.locales ?? {
31
+ en: {},
32
+ });
33
+ def.blockCapacity = field === '_root' ? 2147483647 : DEFAULT_BLOCK_CAPACITY;
34
+ schemaTypesParsed[field] = def;
35
+ schemaTypesParsedById[type.id] = def;
44
36
  }
37
+ return { schemaTypesParsed, schemaTypesParsedById };
45
38
  };
46
39
  export const createSchemaTypeDef = (typeName, type, parsed, locales, result = createEmptyDef(typeName, type, locales), path = [], top = true) => {
47
40
  if (result.id == 0 && top) {
package/dist/lang.d.ts CHANGED
@@ -147,7 +147,7 @@ declare const langCodes: {
147
147
  readonly ka: 145;
148
148
  readonly cnr: 146;
149
149
  };
150
- export declare const langCodesMap: Map<string, 0 | 2 | 1 | 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 | 145 | 146>;
150
+ 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 | 145 | 146>;
151
151
  export declare const inverseLangMap: Map<any, any>;
152
152
  export type LangName = keyof typeof langCodes;
153
153
  export type LangCode = (typeof langCodes)[LangName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "5.0.0-alpha.16",
3
+ "version": "5.0.0-alpha.17",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -1,3 +0,0 @@
1
- import { SchemaTypeDef, PropDef } from './types.js';
2
- export declare function makePacked(result: Partial<SchemaTypeDef>, typeName: string, vals: PropDef[], len: number): void;
3
- //# sourceMappingURL=makePacked.d.ts.map
@@ -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,3 +0,0 @@
1
- import { SchemaTypeDef } from './types.js';
2
- export declare const readFromPacked: (packed: Uint8Array) => SchemaTypeDef;
3
- //# sourceMappingURL=readFromPacked.d.ts.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
@@ -1,3 +0,0 @@
1
- import { StrictSchema } from './types.js';
2
- export declare const mermaid: (schema: StrictSchema) => string;
3
- //# sourceMappingURL=mermaid.d.ts.map
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