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

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.
@@ -14,6 +14,7 @@ selvaTypeMap[WEAK_REFERENCES] = 7;
14
14
  selvaTypeMap[ALIAS] = 8;
15
15
  selvaTypeMap[ALIASES] = 9;
16
16
  const EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT = 0x01;
17
+ const EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP = 0x80;
17
18
  function blockCapacity(blockCapacity) {
18
19
  const buf = new Uint8Array(Uint32Array.BYTES_PER_ELEMENT);
19
20
  const view = new DataView(buf.buffer);
@@ -23,8 +24,11 @@ function blockCapacity(blockCapacity) {
23
24
  function sepPropCount(props) {
24
25
  return props.filter((prop) => prop.separate).length;
25
26
  }
26
- function makeEdgeConstraintFlags(prop) {
27
- return prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00;
27
+ function makeEdgeConstraintFlags(prop, inverseProp) {
28
+ return ((prop.dependent ? EDGE_FIELD_CONSTRAINT_FLAG_DEPENDENT : 0x00) |
29
+ (prop.typeIndex === REFERENCE && inverseProp && inverseProp.typeIndex === REFERENCES
30
+ ? EDGE_FIELD_CONSTRAINT_FLAG_SKIP_DUMP
31
+ : 0x00));
28
32
  }
29
33
  const propDefBuffer = (schema, prop, isEdge) => {
30
34
  const type = prop.typeIndex;
@@ -43,7 +47,7 @@ const propDefBuffer = (schema, prop, isEdge) => {
43
47
  let eschema = [];
44
48
  // @ts-ignore
45
49
  buf[0] = selvaType + 2 * !!isEdge; // field type
46
- buf[1] = makeEdgeConstraintFlags(prop); // flags
50
+ buf[1] = makeEdgeConstraintFlags(prop, dstType.props[prop.inversePropName]); // flags
47
51
  view.setUint16(2, dstType.id, true); // dst_node_type
48
52
  view.setUint32(5, 0, true); // schema_len
49
53
  if (!isEdge) {
@@ -51,6 +51,17 @@ export declare const TYPE_INDEX_MAP: {
51
51
  json: number;
52
52
  object: number;
53
53
  };
54
+ export declare const enum numberTypes {
55
+ number = 4,
56
+ uint16 = 22,
57
+ uint32 = 7,
58
+ int16 = 21,
59
+ int32 = 23,
60
+ uint8 = 6,
61
+ int8 = 20,
62
+ cardinality = 5
63
+ }
64
+ export declare function isNumberType(type: TypeIndex): boolean;
54
65
  export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
55
66
  export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
56
67
  export type PropDef = {
package/dist/def/types.js CHANGED
@@ -50,6 +50,19 @@ export const TYPE_INDEX_MAP = {
50
50
  json: JSON,
51
51
  object: OBJECT,
52
52
  };
53
+ const numberTypeValues = [
54
+ NUMBER,
55
+ UINT16,
56
+ UINT32,
57
+ INT16,
58
+ INT32,
59
+ UINT8,
60
+ INT8,
61
+ CARDINALITY,
62
+ ];
63
+ export function isNumberType(type) {
64
+ return numberTypeValues.includes(type);
65
+ }
53
66
  export const SIZE_MAP = {
54
67
  timestamp: 8, // 64bit
55
68
  // double-precision 64-bit binary format IEEE 754 value
package/dist/lang.d.ts CHANGED
@@ -144,8 +144,10 @@ declare const langCodes: {
144
144
  readonly yi: 142;
145
145
  readonly yo: 143;
146
146
  readonly zu: 144;
147
+ readonly ka: 145;
148
+ readonly cnr: 146;
147
149
  };
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>;
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>;
149
151
  export declare const inverseLangMap: Map<any, any>;
150
152
  export type LangName = keyof typeof langCodes;
151
153
  export type LangCode = (typeof langCodes)[LangName];
package/dist/lang.js CHANGED
@@ -144,6 +144,8 @@ const langCodes = {
144
144
  yi: 142,
145
145
  yo: 143,
146
146
  zu: 144,
147
+ ka: 145,
148
+ cnr: 146,
147
149
  };
148
150
  export const langCodesMap = new Map(Object.entries(langCodes));
149
151
  export const inverseLangMap = new Map();
package/dist/mermaid.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { StrictSchema } from './types.js';
2
+ export declare const mermaid2: (schema: StrictSchema) => string;
2
3
  export declare const mermaid: (schema: StrictSchema) => string;
3
4
  //# sourceMappingURL=mermaid.d.ts.map
package/dist/mermaid.js CHANGED
@@ -1,23 +1,80 @@
1
1
  import { getPropType } from './parse/utils.js';
2
- import { isPropType } from './types.js';
3
- export const mermaid = (schema) => {
4
- let mermaid = 'classDiagram';
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
+ }
5
44
  if (schema.types) {
6
45
  for (const type in schema.types) {
7
- for (const key in schema.types[type].props) {
8
- const prop = schema.types[type].props[key];
46
+ mermaid += parse(type, schema.types[type].props);
47
+ }
48
+ }
49
+ return mermaid + relations;
50
+ };
51
+ export const mermaid = (schema) => {
52
+ 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 {
9
63
  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}`;
64
+ mermaid += `\n${type} : ${indent}${key} __${propType}__`;
65
+ if (isPropType('object', prop)) {
66
+ parse(type, prop.props, `${indent}.`);
18
67
  }
19
68
  }
20
69
  }
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
+ }
21
78
  }
22
79
  return mermaid;
23
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/schema",
3
- "version": "5.0.0-alpha.12",
3
+ "version": "5.0.0-alpha.14",
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.5.0",
33
+ "@saulx/utils": "^6.6.0",
34
34
  "picocolors": "^1.1.0"
35
35
  }
36
36
  }