@based/schema 5.0.0-alpha.14 → 5.0.0-alpha.16
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/selvaBuffer.js +5 -1
- package/dist/mermaid.d.ts +0 -1
- package/dist/mermaid.js +13 -70
- package/package.json +2 -2
package/dist/def/selvaBuffer.js
CHANGED
|
@@ -94,7 +94,11 @@ export function schemaToSelvaBuffer(schema) {
|
|
|
94
94
|
return Object.values(schema).map((t, i) => {
|
|
95
95
|
const props = Object.values(t.props);
|
|
96
96
|
const rest = [];
|
|
97
|
+
const nrFields = 1 + sepPropCount(props);
|
|
97
98
|
let refFields = 0;
|
|
99
|
+
if (nrFields >= 250) {
|
|
100
|
+
throw new Error('Too many fields');
|
|
101
|
+
}
|
|
98
102
|
for (const f of props) {
|
|
99
103
|
if (f.separate) {
|
|
100
104
|
if (f.typeIndex === REFERENCE || f.typeIndex === REFERENCES) {
|
|
@@ -106,7 +110,7 @@ export function schemaToSelvaBuffer(schema) {
|
|
|
106
110
|
rest.sort((a, b) => a.prop - b.prop);
|
|
107
111
|
return Uint8Array.from([
|
|
108
112
|
...blockCapacity(t.blockCapacity),
|
|
109
|
-
|
|
113
|
+
nrFields,
|
|
110
114
|
1 + refFields,
|
|
111
115
|
...propDefBuffer(schema, {
|
|
112
116
|
...EMPTY_MICRO_BUFFER,
|
package/dist/mermaid.d.ts
CHANGED
package/dist/mermaid.js
CHANGED
|
@@ -1,80 +1,23 @@
|
|
|
1
1
|
import { getPropType } from './parse/utils.js';
|
|
2
|
-
import { isPropType
|
|
3
|
-
export const mermaid2 = (schema) => {
|
|
4
|
-
let mermaid = 'erDiagram';
|
|
5
|
-
let relations = '';
|
|
6
|
-
const parse = (type, props, indent = '') => {
|
|
7
|
-
let entity = indent ? '' : `\n${type} {`;
|
|
8
|
-
for (const key in props) {
|
|
9
|
-
const prop = props[key];
|
|
10
|
-
if (isPropType('reference', prop)) {
|
|
11
|
-
entity += `\n${prop.ref} ${indent}${key}`;
|
|
12
|
-
relations += `\n${type} ||--o| ${prop.ref} : ${key}`;
|
|
13
|
-
}
|
|
14
|
-
else if (isPropType('references', prop)) {
|
|
15
|
-
entity += `\n${prop.items.ref} ${indent}${key}`;
|
|
16
|
-
relations += `\n${type} ||--o{ ${prop.items.ref} : ${key}`;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
entity += `\n${getPropType(prop)} ${indent}${key}`;
|
|
20
|
-
if (isPropType('object', prop)) {
|
|
21
|
-
entity += parse(type, prop.props, `${indent}_`);
|
|
22
|
-
}
|
|
23
|
-
else if (isPropType('enum', prop)) {
|
|
24
|
-
entity += '"';
|
|
25
|
-
if (prop.enum.length > 3) {
|
|
26
|
-
const [a, b, c] = prop.enum;
|
|
27
|
-
entity += [a, b, c, `+${prop.enum.length - 3}`].join(', ');
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
entity += prop.enum.join(', ');
|
|
31
|
-
}
|
|
32
|
-
entity += '"';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (!indent) {
|
|
37
|
-
entity += '\n}';
|
|
38
|
-
}
|
|
39
|
-
return entity;
|
|
40
|
-
};
|
|
41
|
-
if (schema.props) {
|
|
42
|
-
mermaid += parse('_root', schema.props);
|
|
43
|
-
}
|
|
44
|
-
if (schema.types) {
|
|
45
|
-
for (const type in schema.types) {
|
|
46
|
-
mermaid += parse(type, schema.types[type].props);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return mermaid + relations;
|
|
50
|
-
};
|
|
2
|
+
import { isPropType } from './types.js';
|
|
51
3
|
export const mermaid = (schema) => {
|
|
52
4
|
let mermaid = 'classDiagram';
|
|
53
|
-
|
|
54
|
-
for (const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
mermaid += `\n${type} --> ${prop.ref} : ${key}`;
|
|
58
|
-
}
|
|
59
|
-
else if (isPropType('references', prop)) {
|
|
60
|
-
mermaid += `\n${type} --> ${prop.items.ref} : ${key}[]`;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
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];
|
|
63
9
|
const propType = getPropType(prop);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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}`;
|
|
67
18
|
}
|
|
68
19
|
}
|
|
69
20
|
}
|
|
70
|
-
};
|
|
71
|
-
if (schema.props) {
|
|
72
|
-
parse('_root', schema.props);
|
|
73
|
-
}
|
|
74
|
-
if (schema.types) {
|
|
75
|
-
for (const type in schema.types) {
|
|
76
|
-
parse(type, schema.types[type].props);
|
|
77
|
-
}
|
|
78
21
|
}
|
|
79
22
|
return mermaid;
|
|
80
23
|
};
|
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.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"fflate": "0.8.1",
|
|
33
|
-
"@saulx/utils": "^6.
|
|
33
|
+
"@saulx/utils": "^6.7.0",
|
|
34
34
|
"picocolors": "^1.1.0"
|
|
35
35
|
}
|
|
36
36
|
}
|