@based/schema 5.0.0-alpha.14 → 5.0.0-alpha.15

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.
@@ -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
- 1 + sepPropCount(props),
113
+ nrFields,
110
114
  1 + refFields,
111
115
  ...propDefBuffer(schema, {
112
116
  ...EMPTY_MICRO_BUFFER,
package/dist/mermaid.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { StrictSchema } from './types.js';
2
- export declare const mermaid2: (schema: StrictSchema) => string;
3
2
  export declare const mermaid: (schema: StrictSchema) => string;
4
3
  //# sourceMappingURL=mermaid.d.ts.map
package/dist/mermaid.js CHANGED
@@ -1,80 +1,23 @@
1
1
  import { getPropType } from './parse/utils.js';
2
- import { isPropType, } from './types.js';
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
- const parse = (type, props, indent = '') => {
54
- for (const key in props) {
55
- const prop = props[key];
56
- if (isPropType('reference', prop)) {
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
- mermaid += `\n${type} : ${indent}${key} __${propType}__`;
65
- if (isPropType('object', prop)) {
66
- parse(type, prop.props, `${indent}.`);
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.14",
3
+ "version": "5.0.0-alpha.15",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",