@uigraph/sdk 1.1.37 → 1.1.39
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/{__index.BxD_9h1c.d.mts → __index.Bfg50WMf.d.mts} +6 -1
- package/dist/{__index.CTSMJl1o.d.cts → __index.ClK6nImE.d.cts} +6 -1
- package/dist/browser.cjs +13 -7
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.mts +1 -1
- package/dist/browser.mjs +13 -7
- package/dist/index.cjs +69 -34
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +69 -34
- package/package.json +1 -1
|
@@ -2,6 +2,11 @@ import { t as ComponentInputType } from "./__component-type.CO8FgnQE.mjs";
|
|
|
2
2
|
import { Edge, Node } from "@xyflow/react";
|
|
3
3
|
|
|
4
4
|
//#region src/types/component.d.ts
|
|
5
|
+
type LinkOrFileValue = {
|
|
6
|
+
fileId?: string;
|
|
7
|
+
url?: string;
|
|
8
|
+
file?: File;
|
|
9
|
+
};
|
|
5
10
|
type ServerComponentField = {
|
|
6
11
|
componentFieldId?: string | null;
|
|
7
12
|
isReadonly?: boolean | null;
|
|
@@ -114,4 +119,4 @@ interface RFComponentField {
|
|
|
114
119
|
data: unknown;
|
|
115
120
|
}
|
|
116
121
|
//#endregion
|
|
117
|
-
export { MermaidNode as a, SequenceParticipant as c,
|
|
122
|
+
export { MermaidNode as a, SequenceParticipant as c, LinkOrFileValue as d, ServerComponentField as f, MermaidEdge as i, SubgraphInfo as l, RFComponentField as n, SequenceDiagramData as o, ServerComponentFieldInput as p, ReactFlowData as r, SequenceMessage as s, CustomData as t, SubgraphLayout as u };
|
|
@@ -2,6 +2,11 @@ import { t as ComponentInputType } from "./__component-type.tW2Xh7Xk.cjs";
|
|
|
2
2
|
import { Edge, Node } from "@xyflow/react";
|
|
3
3
|
|
|
4
4
|
//#region src/types/component.d.ts
|
|
5
|
+
type LinkOrFileValue = {
|
|
6
|
+
fileId?: string;
|
|
7
|
+
url?: string;
|
|
8
|
+
file?: File;
|
|
9
|
+
};
|
|
5
10
|
type ServerComponentField = {
|
|
6
11
|
componentFieldId?: string | null;
|
|
7
12
|
isReadonly?: boolean | null;
|
|
@@ -114,4 +119,4 @@ interface RFComponentField {
|
|
|
114
119
|
data: unknown;
|
|
115
120
|
}
|
|
116
121
|
//#endregion
|
|
117
|
-
export { MermaidNode as a, SequenceParticipant as c,
|
|
122
|
+
export { MermaidNode as a, SequenceParticipant as c, LinkOrFileValue as d, ServerComponentField as f, MermaidEdge as i, SubgraphInfo as l, RFComponentField as n, SequenceDiagramData as o, ServerComponentFieldInput as p, ReactFlowData as r, SequenceMessage as s, CustomData as t, SubgraphLayout as u };
|
package/dist/browser.cjs
CHANGED
|
@@ -15,18 +15,24 @@ function buildDynamicZodSchema(fields) {
|
|
|
15
15
|
case require_component_type.ComponentInputType.DropdownSelect:
|
|
16
16
|
case require_component_type.ComponentInputType.DatePicker: {
|
|
17
17
|
var _field$label;
|
|
18
|
-
const stringSchema
|
|
19
|
-
zodType = field.required ? stringSchema
|
|
18
|
+
const stringSchema = zod.z.string();
|
|
19
|
+
zodType = field.required ? stringSchema.min(1, { message: `${(_field$label = field.label) !== null && _field$label !== void 0 ? _field$label : "Field"} is required` }) : stringSchema.optional();
|
|
20
20
|
break;
|
|
21
21
|
}
|
|
22
22
|
case require_component_type.ComponentInputType.FileUpload:
|
|
23
|
-
case require_component_type.ComponentInputType.LinkOrFileUpload:
|
|
23
|
+
case require_component_type.ComponentInputType.LinkOrFileUpload: {
|
|
24
24
|
var _field$label2;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const objectSchema = zod.z.object({
|
|
26
|
+
fileId: zod.z.string().optional(),
|
|
27
|
+
url: zod.z.string().optional(),
|
|
28
|
+
file: zod.z.instanceof(File).optional()
|
|
29
|
+
});
|
|
30
|
+
zodType = field.required ? objectSchema.refine((value) => {
|
|
31
|
+
var _value$url$length, _value$url, _value$fileId$length, _value$fileId;
|
|
32
|
+
return ((_value$url$length = (_value$url = value.url) === null || _value$url === void 0 ? void 0 : _value$url.length) !== null && _value$url$length !== void 0 ? _value$url$length : 0) > 0 || ((_value$fileId$length = (_value$fileId = value.fileId) === null || _value$fileId === void 0 ? void 0 : _value$fileId.length) !== null && _value$fileId$length !== void 0 ? _value$fileId$length : 0) > 0 || value.file instanceof File;
|
|
33
|
+
}, { message: `${(_field$label2 = field.label) !== null && _field$label2 !== void 0 ? _field$label2 : "Field"} is required` }) : objectSchema.optional();
|
|
29
34
|
break;
|
|
35
|
+
}
|
|
30
36
|
case require_component_type.ComponentInputType.URLInput: {
|
|
31
37
|
var _field$label3;
|
|
32
38
|
const urlSchema = zod.z.string({ message: "Invalid URL" });
|
package/dist/browser.d.cts
CHANGED
package/dist/browser.d.mts
CHANGED
package/dist/browser.mjs
CHANGED
|
@@ -13,18 +13,24 @@ function buildDynamicZodSchema(fields) {
|
|
|
13
13
|
case ComponentInputType.DropdownSelect:
|
|
14
14
|
case ComponentInputType.DatePicker: {
|
|
15
15
|
var _field$label;
|
|
16
|
-
const stringSchema
|
|
17
|
-
zodType = field.required ? stringSchema
|
|
16
|
+
const stringSchema = z.string();
|
|
17
|
+
zodType = field.required ? stringSchema.min(1, { message: `${(_field$label = field.label) !== null && _field$label !== void 0 ? _field$label : "Field"} is required` }) : stringSchema.optional();
|
|
18
18
|
break;
|
|
19
19
|
}
|
|
20
20
|
case ComponentInputType.FileUpload:
|
|
21
|
-
case ComponentInputType.LinkOrFileUpload:
|
|
21
|
+
case ComponentInputType.LinkOrFileUpload: {
|
|
22
22
|
var _field$label2;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const objectSchema = z.object({
|
|
24
|
+
fileId: z.string().optional(),
|
|
25
|
+
url: z.string().optional(),
|
|
26
|
+
file: z.instanceof(File).optional()
|
|
27
|
+
});
|
|
28
|
+
zodType = field.required ? objectSchema.refine((value) => {
|
|
29
|
+
var _value$url$length, _value$url, _value$fileId$length, _value$fileId;
|
|
30
|
+
return ((_value$url$length = (_value$url = value.url) === null || _value$url === void 0 ? void 0 : _value$url.length) !== null && _value$url$length !== void 0 ? _value$url$length : 0) > 0 || ((_value$fileId$length = (_value$fileId = value.fileId) === null || _value$fileId === void 0 ? void 0 : _value$fileId.length) !== null && _value$fileId$length !== void 0 ? _value$fileId$length : 0) > 0 || value.file instanceof File;
|
|
31
|
+
}, { message: `${(_field$label2 = field.label) !== null && _field$label2 !== void 0 ? _field$label2 : "Field"} is required` }) : objectSchema.optional();
|
|
27
32
|
break;
|
|
33
|
+
}
|
|
28
34
|
case ComponentInputType.URLInput: {
|
|
29
35
|
var _field$label3;
|
|
30
36
|
const urlSchema = z.string({ message: "Invalid URL" });
|
package/dist/index.cjs
CHANGED
|
@@ -779,45 +779,53 @@ function generateUUID() {
|
|
|
779
779
|
}
|
|
780
780
|
var AstToUiConverter = class {
|
|
781
781
|
static updateReactFlow({ nodes, edges, schema, sourceName, oldDataSources }) {
|
|
782
|
-
|
|
783
|
-
nodes,
|
|
784
|
-
edges,
|
|
785
|
-
schema,
|
|
786
|
-
sourceName,
|
|
787
|
-
oldDataSources
|
|
788
|
-
});
|
|
782
|
+
var _oldSource$schemaAst$;
|
|
789
783
|
const oldSource = oldDataSources.find((s) => s.name === sourceName);
|
|
790
784
|
const sourceNodePrefix = `${sourceName}-table-`;
|
|
791
785
|
const positions = this.calculateSmartLayout(schema);
|
|
792
|
-
const nodeTableMap = new Map(nodes.map((node) => {
|
|
793
|
-
var _oldSource$schemaAst$;
|
|
794
|
-
return [oldSource === null || oldSource === void 0 || (_oldSource$schemaAst$ = oldSource.schemaAst.tables.find((t) => {
|
|
795
|
-
var _localTable;
|
|
796
|
-
return t.name === ((_localTable = node.data.localTable) === null || _localTable === void 0 ? void 0 : _localTable.tableName);
|
|
797
|
-
})) === null || _oldSource$schemaAst$ === void 0 ? void 0 : _oldSource$schemaAst$.name, node];
|
|
798
|
-
}));
|
|
799
|
-
console.log("Old node table map:", nodeTableMap);
|
|
800
786
|
const tableNames = new Set(schema.tables.map((table) => table.name));
|
|
787
|
+
const sourceNodePool = nodes.filter((node) => node.id.startsWith(sourceNodePrefix));
|
|
788
|
+
const oldNodeByName = /* @__PURE__ */ new Map();
|
|
789
|
+
for (const node of sourceNodePool) {
|
|
790
|
+
var _localTable;
|
|
791
|
+
const tableName = (_localTable = node.data.localTable) === null || _localTable === void 0 ? void 0 : _localTable.tableName;
|
|
792
|
+
if (tableName) oldNodeByName.set(tableName, node);
|
|
793
|
+
}
|
|
794
|
+
const oldTableByName = /* @__PURE__ */ new Map();
|
|
795
|
+
for (const table of (_oldSource$schemaAst$ = oldSource === null || oldSource === void 0 ? void 0 : oldSource.schemaAst.tables) !== null && _oldSource$schemaAst$ !== void 0 ? _oldSource$schemaAst$ : []) oldTableByName.set(table.name, table);
|
|
796
|
+
const consumedNodeIds = /* @__PURE__ */ new Set();
|
|
797
|
+
function mergeWithPrev(baseNode, prevNode) {
|
|
798
|
+
var _prevNode$data, _prevNode$data$style, _prevNode$data2, _baseNode$data;
|
|
799
|
+
const mergedNode = _objectSpread2(_objectSpread2(_objectSpread2({}, prevNode), baseNode), {}, { data: _objectSpread2(_objectSpread2(_objectSpread2({}, (_prevNode$data = prevNode.data) !== null && _prevNode$data !== void 0 ? _prevNode$data : {}), baseNode.data), {}, { style: (_prevNode$data$style = (_prevNode$data2 = prevNode.data) === null || _prevNode$data2 === void 0 ? void 0 : _prevNode$data2.style) !== null && _prevNode$data$style !== void 0 ? _prevNode$data$style : (_baseNode$data = baseNode.data) === null || _baseNode$data === void 0 ? void 0 : _baseNode$data.style }) });
|
|
800
|
+
if (prevNode.style) mergedNode.style = prevNode.style;
|
|
801
|
+
if (prevNode.width !== void 0) mergedNode.width = prevNode.width;
|
|
802
|
+
if (prevNode.height !== void 0) mergedNode.height = prevNode.height;
|
|
803
|
+
return mergedNode;
|
|
804
|
+
}
|
|
801
805
|
const sourceNodes = schema.tables.map((table, index) => {
|
|
802
|
-
var _ref, _ref2, _prevNode$position
|
|
803
|
-
|
|
806
|
+
var _ref, _ref2, _prevNode$position;
|
|
807
|
+
let prevNode = oldNodeByName.get(table.name);
|
|
808
|
+
if (!prevNode || consumedNodeIds.has(prevNode.id)) {
|
|
809
|
+
prevNode = void 0;
|
|
810
|
+
const newSignature = this.tableSignature(table);
|
|
811
|
+
for (const [oldName, oldTable] of oldTableByName) {
|
|
812
|
+
if (tableNames.has(oldName)) continue;
|
|
813
|
+
const candidate = oldNodeByName.get(oldName);
|
|
814
|
+
if (!candidate || consumedNodeIds.has(candidate.id)) continue;
|
|
815
|
+
if (this.tableSignature(oldTable) === newSignature) {
|
|
816
|
+
prevNode = candidate;
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
804
821
|
const position = (_ref = (_ref2 = (_prevNode$position = prevNode === null || prevNode === void 0 ? void 0 : prevNode.position) !== null && _prevNode$position !== void 0 ? _prevNode$position : table.position) !== null && _ref2 !== void 0 ? _ref2 : positions[table.name]) !== null && _ref !== void 0 ? _ref : {
|
|
805
822
|
x: 100,
|
|
806
823
|
y: 100 + index * 210
|
|
807
824
|
};
|
|
808
825
|
const baseNode = this.tableAstToNode(sourceName, table, position, tableNames);
|
|
809
826
|
if (!prevNode) return baseNode;
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
if (prevNode.width !== void 0) mergedNode.width = prevNode.width;
|
|
813
|
-
if (prevNode.height !== void 0) mergedNode.height = prevNode.height;
|
|
814
|
-
return mergedNode;
|
|
815
|
-
}).filter((node) => {
|
|
816
|
-
var _schema$tables$find;
|
|
817
|
-
return nodeTableMap.has((_schema$tables$find = schema.tables.find((t) => {
|
|
818
|
-
var _localTable2;
|
|
819
|
-
return t.name === ((_localTable2 = node.data.localTable) === null || _localTable2 === void 0 ? void 0 : _localTable2.tableName);
|
|
820
|
-
})) === null || _schema$tables$find === void 0 ? void 0 : _schema$tables$find.name);
|
|
827
|
+
consumedNodeIds.add(prevNode.id);
|
|
828
|
+
return mergeWithPrev(baseNode, prevNode);
|
|
821
829
|
});
|
|
822
830
|
const validNodeIds = new Set(sourceNodes.map((node) => node.id));
|
|
823
831
|
const sourceEdges = schema.tables.flatMap((table) => this.createEdgesFromTable(sourceName, table, schema.tables).filter((edge) => validNodeIds.has(edge.source) && validNodeIds.has(edge.target)));
|
|
@@ -950,6 +958,28 @@ var AstToUiConverter = class {
|
|
|
950
958
|
} }
|
|
951
959
|
};
|
|
952
960
|
}
|
|
961
|
+
static tableSignature(table) {
|
|
962
|
+
const columns = [...table.columns].sort((a, b) => a.name.localeCompare(b.name)).map((col) => {
|
|
963
|
+
var _col$dataType$paramet, _col$dataType$paramet2;
|
|
964
|
+
const params = (_col$dataType$paramet = (_col$dataType$paramet2 = col.dataType.parameters) === null || _col$dataType$paramet2 === void 0 ? void 0 : _col$dataType$paramet2.join(",")) !== null && _col$dataType$paramet !== void 0 ? _col$dataType$paramet : "";
|
|
965
|
+
return [
|
|
966
|
+
col.name,
|
|
967
|
+
col.dataType.name,
|
|
968
|
+
params,
|
|
969
|
+
col.dataType.unsigned ? "u" : "",
|
|
970
|
+
col.dataType.timezone ? "tz" : "",
|
|
971
|
+
col.nullable ? "null" : "notnull",
|
|
972
|
+
col.autoIncrement ? "ai" : ""
|
|
973
|
+
].join(":");
|
|
974
|
+
});
|
|
975
|
+
const constraints = table.constraints.map((c) => JSON.stringify(c)).sort();
|
|
976
|
+
const indexes = [...table.indexes].map((idx) => JSON.stringify(idx)).sort();
|
|
977
|
+
return JSON.stringify({
|
|
978
|
+
columns,
|
|
979
|
+
constraints,
|
|
980
|
+
indexes
|
|
981
|
+
});
|
|
982
|
+
}
|
|
953
983
|
static extractPrimaryKeys(table) {
|
|
954
984
|
const pkConstraint = table.constraints.find((c) => c.type === "primary_key");
|
|
955
985
|
if (pkConstraint) return pkConstraint.columns;
|
|
@@ -1806,8 +1836,8 @@ function flattenMetaData(fields, fieldsValues) {
|
|
|
1806
1836
|
break;
|
|
1807
1837
|
case require_component_type.ComponentInputType.FileUpload:
|
|
1808
1838
|
case require_component_type.ComponentInputType.LinkOrFileUpload:
|
|
1809
|
-
var
|
|
1810
|
-
output[id] = (
|
|
1839
|
+
var _ref, _data$4;
|
|
1840
|
+
output[id] = (_ref = data === null || data === void 0 || (_data$4 = data[0]) === null || _data$4 === void 0 ? void 0 : _data$4.value) !== null && _ref !== void 0 ? _ref : null;
|
|
1811
1841
|
break;
|
|
1812
1842
|
case require_component_type.ComponentInputType.RichTextEditor:
|
|
1813
1843
|
var _data$5;
|
|
@@ -1817,8 +1847,8 @@ function flattenMetaData(fields, fieldsValues) {
|
|
|
1817
1847
|
output[id] = data !== null && data !== void 0 ? data : [];
|
|
1818
1848
|
break;
|
|
1819
1849
|
case require_component_type.ComponentInputType.BooleanToggle:
|
|
1820
|
-
var _data$0$
|
|
1821
|
-
output[id] = (_data$0$
|
|
1850
|
+
var _data$0$value3, _data$6;
|
|
1851
|
+
output[id] = (_data$0$value3 = data === null || data === void 0 || (_data$6 = data[0]) === null || _data$6 === void 0 ? void 0 : _data$6.value) !== null && _data$0$value3 !== void 0 ? _data$0$value3 : false;
|
|
1822
1852
|
break;
|
|
1823
1853
|
case require_component_type.ComponentInputType.DateRangePicker:
|
|
1824
1854
|
output[id] = data === null || data === void 0 ? void 0 : data[0];
|
|
@@ -1853,9 +1883,14 @@ function buildMetaData(fields, data) {
|
|
|
1853
1883
|
localData = [{ value: value != null ? Number(value) : null }];
|
|
1854
1884
|
break;
|
|
1855
1885
|
case require_component_type.ComponentInputType.FileUpload:
|
|
1856
|
-
case require_component_type.ComponentInputType.LinkOrFileUpload:
|
|
1857
|
-
|
|
1886
|
+
case require_component_type.ComponentInputType.LinkOrFileUpload: {
|
|
1887
|
+
const v = value;
|
|
1888
|
+
localData = [{ value: {
|
|
1889
|
+
fileId: v === null || v === void 0 ? void 0 : v.fileId,
|
|
1890
|
+
url: v === null || v === void 0 ? void 0 : v.url
|
|
1891
|
+
} }];
|
|
1858
1892
|
break;
|
|
1893
|
+
}
|
|
1859
1894
|
case require_component_type.ComponentInputType.RichTextEditor:
|
|
1860
1895
|
localData = [value];
|
|
1861
1896
|
break;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MermaidNode, c as SequenceParticipant, d as
|
|
1
|
+
import { a as MermaidNode, c as SequenceParticipant, d as LinkOrFileValue, f as ServerComponentField, i as MermaidEdge, l as SubgraphInfo, n as RFComponentField, o as SequenceDiagramData, p as ServerComponentFieldInput, r as ReactFlowData, s as SequenceMessage, t as CustomData, u as SubgraphLayout } from "./__index.ClK6nImE.cjs";
|
|
2
2
|
import { t as ComponentInputType } from "./__component-type.tW2Xh7Xk.cjs";
|
|
3
3
|
import { t as contextSchema } from "./__headless.DfSqiw4X.cjs";
|
|
4
4
|
import z$1, { z } from "zod";
|
|
@@ -333,6 +333,7 @@ declare class AstToUiConverter {
|
|
|
333
333
|
* Convert table AST to ReactFlow node
|
|
334
334
|
*/
|
|
335
335
|
private static tableAstToNode;
|
|
336
|
+
private static tableSignature;
|
|
336
337
|
/**
|
|
337
338
|
* Extract primary keys from table
|
|
338
339
|
*/
|
|
@@ -764,4 +765,4 @@ type UigOutput = {
|
|
|
764
765
|
//#region src/uig-converter/index.d.ts
|
|
765
766
|
declare function convertUiGraphToMermaid(input: UiGraphInput, options?: UiGraphOptions): UigOutput;
|
|
766
767
|
//#endregion
|
|
767
|
-
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceDiagramData, SequenceMessage, SequenceParticipant, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
|
|
768
|
+
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceDiagramData, SequenceMessage, SequenceParticipant, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MermaidNode, c as SequenceParticipant, d as
|
|
1
|
+
import { a as MermaidNode, c as SequenceParticipant, d as LinkOrFileValue, f as ServerComponentField, i as MermaidEdge, l as SubgraphInfo, n as RFComponentField, o as SequenceDiagramData, p as ServerComponentFieldInput, r as ReactFlowData, s as SequenceMessage, t as CustomData, u as SubgraphLayout } from "./__index.Bfg50WMf.mjs";
|
|
2
2
|
import { t as ComponentInputType } from "./__component-type.CO8FgnQE.mjs";
|
|
3
3
|
import { t as contextSchema } from "./__headless.BLqB7VsJ.mjs";
|
|
4
4
|
import z$1, { z } from "zod";
|
|
@@ -333,6 +333,7 @@ declare class AstToUiConverter {
|
|
|
333
333
|
* Convert table AST to ReactFlow node
|
|
334
334
|
*/
|
|
335
335
|
private static tableAstToNode;
|
|
336
|
+
private static tableSignature;
|
|
336
337
|
/**
|
|
337
338
|
* Extract primary keys from table
|
|
338
339
|
*/
|
|
@@ -764,4 +765,4 @@ type UigOutput = {
|
|
|
764
765
|
//#region src/uig-converter/index.d.ts
|
|
765
766
|
declare function convertUiGraphToMermaid(input: UiGraphInput, options?: UiGraphOptions): UigOutput;
|
|
766
767
|
//#endregion
|
|
767
|
-
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceDiagramData, SequenceMessage, SequenceParticipant, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
|
|
768
|
+
export { AstToSqlGenerator, AstToUiConverter, BasicDetailsSchema, CheckConstraintAST, ColumnAST, ComponentInputType, ConstraintAST, CustomData, DataTypeAST, DefaultValueAST, DialectIdSchema, DocumentCollectionSchema, DocumentIndexSchema, DynamoAttributeSchema, DynamoEditorSchema, DynamoGsiSchema, EditorSupportedDialectSchema, ForeignKeyConstraintAST, IndexAST, IndexColumnAST, IndexMethodAST, JsonEditorSchema, LinkOrFileValue, MermaidEdge, MermaidNode, MongoCollectionSchema, MongoEditorSchema, MongoIndexFieldSchema, MongoIndexSchema, MongoNestedFieldSchema, NestedFieldSchema, NoSqlFieldSchema, PrimaryKeyConstraintAST, RFComponentField, ReactFlowData, ReferentialActionAST, SchemaAST, SchemaDialect, SchemaUIRepresentation, SequenceDiagramData, SequenceMessage, SequenceParticipant, ServerComponentField, ServerComponentFieldInput, SqlToAstParser, SubgraphInfo, SubgraphLayout, TParsedColumn, TParsedForeignKey, TParsedIndex, TParsedSchema, TParsedTable, TableAST, TableOptionsAST, UniqueConstraintAST, buildMetaData, contextSchema, convertDynamoSchemaToAst, convertJsonSchemaToAst, convertMermaidToReactFlow, convertMermaidToReactFlowWithContext, convertMongoSchemaToAst, convertNoSQLToAst, convertUiGraphToMermaid, flattenMetaData, generateTableNodeId, generateUUID, sanitizeMermaidLabels, syncBaseData };
|
package/dist/index.mjs
CHANGED
|
@@ -773,45 +773,53 @@ function generateUUID() {
|
|
|
773
773
|
}
|
|
774
774
|
var AstToUiConverter = class {
|
|
775
775
|
static updateReactFlow({ nodes, edges, schema, sourceName, oldDataSources }) {
|
|
776
|
-
|
|
777
|
-
nodes,
|
|
778
|
-
edges,
|
|
779
|
-
schema,
|
|
780
|
-
sourceName,
|
|
781
|
-
oldDataSources
|
|
782
|
-
});
|
|
776
|
+
var _oldSource$schemaAst$;
|
|
783
777
|
const oldSource = oldDataSources.find((s) => s.name === sourceName);
|
|
784
778
|
const sourceNodePrefix = `${sourceName}-table-`;
|
|
785
779
|
const positions = this.calculateSmartLayout(schema);
|
|
786
|
-
const nodeTableMap = new Map(nodes.map((node) => {
|
|
787
|
-
var _oldSource$schemaAst$;
|
|
788
|
-
return [oldSource === null || oldSource === void 0 || (_oldSource$schemaAst$ = oldSource.schemaAst.tables.find((t) => {
|
|
789
|
-
var _localTable;
|
|
790
|
-
return t.name === ((_localTable = node.data.localTable) === null || _localTable === void 0 ? void 0 : _localTable.tableName);
|
|
791
|
-
})) === null || _oldSource$schemaAst$ === void 0 ? void 0 : _oldSource$schemaAst$.name, node];
|
|
792
|
-
}));
|
|
793
|
-
console.log("Old node table map:", nodeTableMap);
|
|
794
780
|
const tableNames = new Set(schema.tables.map((table) => table.name));
|
|
781
|
+
const sourceNodePool = nodes.filter((node) => node.id.startsWith(sourceNodePrefix));
|
|
782
|
+
const oldNodeByName = /* @__PURE__ */ new Map();
|
|
783
|
+
for (const node of sourceNodePool) {
|
|
784
|
+
var _localTable;
|
|
785
|
+
const tableName = (_localTable = node.data.localTable) === null || _localTable === void 0 ? void 0 : _localTable.tableName;
|
|
786
|
+
if (tableName) oldNodeByName.set(tableName, node);
|
|
787
|
+
}
|
|
788
|
+
const oldTableByName = /* @__PURE__ */ new Map();
|
|
789
|
+
for (const table of (_oldSource$schemaAst$ = oldSource === null || oldSource === void 0 ? void 0 : oldSource.schemaAst.tables) !== null && _oldSource$schemaAst$ !== void 0 ? _oldSource$schemaAst$ : []) oldTableByName.set(table.name, table);
|
|
790
|
+
const consumedNodeIds = /* @__PURE__ */ new Set();
|
|
791
|
+
function mergeWithPrev(baseNode, prevNode) {
|
|
792
|
+
var _prevNode$data, _prevNode$data$style, _prevNode$data2, _baseNode$data;
|
|
793
|
+
const mergedNode = _objectSpread2(_objectSpread2(_objectSpread2({}, prevNode), baseNode), {}, { data: _objectSpread2(_objectSpread2(_objectSpread2({}, (_prevNode$data = prevNode.data) !== null && _prevNode$data !== void 0 ? _prevNode$data : {}), baseNode.data), {}, { style: (_prevNode$data$style = (_prevNode$data2 = prevNode.data) === null || _prevNode$data2 === void 0 ? void 0 : _prevNode$data2.style) !== null && _prevNode$data$style !== void 0 ? _prevNode$data$style : (_baseNode$data = baseNode.data) === null || _baseNode$data === void 0 ? void 0 : _baseNode$data.style }) });
|
|
794
|
+
if (prevNode.style) mergedNode.style = prevNode.style;
|
|
795
|
+
if (prevNode.width !== void 0) mergedNode.width = prevNode.width;
|
|
796
|
+
if (prevNode.height !== void 0) mergedNode.height = prevNode.height;
|
|
797
|
+
return mergedNode;
|
|
798
|
+
}
|
|
795
799
|
const sourceNodes = schema.tables.map((table, index) => {
|
|
796
|
-
var _ref, _ref2, _prevNode$position
|
|
797
|
-
|
|
800
|
+
var _ref, _ref2, _prevNode$position;
|
|
801
|
+
let prevNode = oldNodeByName.get(table.name);
|
|
802
|
+
if (!prevNode || consumedNodeIds.has(prevNode.id)) {
|
|
803
|
+
prevNode = void 0;
|
|
804
|
+
const newSignature = this.tableSignature(table);
|
|
805
|
+
for (const [oldName, oldTable] of oldTableByName) {
|
|
806
|
+
if (tableNames.has(oldName)) continue;
|
|
807
|
+
const candidate = oldNodeByName.get(oldName);
|
|
808
|
+
if (!candidate || consumedNodeIds.has(candidate.id)) continue;
|
|
809
|
+
if (this.tableSignature(oldTable) === newSignature) {
|
|
810
|
+
prevNode = candidate;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
798
815
|
const position = (_ref = (_ref2 = (_prevNode$position = prevNode === null || prevNode === void 0 ? void 0 : prevNode.position) !== null && _prevNode$position !== void 0 ? _prevNode$position : table.position) !== null && _ref2 !== void 0 ? _ref2 : positions[table.name]) !== null && _ref !== void 0 ? _ref : {
|
|
799
816
|
x: 100,
|
|
800
817
|
y: 100 + index * 210
|
|
801
818
|
};
|
|
802
819
|
const baseNode = this.tableAstToNode(sourceName, table, position, tableNames);
|
|
803
820
|
if (!prevNode) return baseNode;
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (prevNode.width !== void 0) mergedNode.width = prevNode.width;
|
|
807
|
-
if (prevNode.height !== void 0) mergedNode.height = prevNode.height;
|
|
808
|
-
return mergedNode;
|
|
809
|
-
}).filter((node) => {
|
|
810
|
-
var _schema$tables$find;
|
|
811
|
-
return nodeTableMap.has((_schema$tables$find = schema.tables.find((t) => {
|
|
812
|
-
var _localTable2;
|
|
813
|
-
return t.name === ((_localTable2 = node.data.localTable) === null || _localTable2 === void 0 ? void 0 : _localTable2.tableName);
|
|
814
|
-
})) === null || _schema$tables$find === void 0 ? void 0 : _schema$tables$find.name);
|
|
821
|
+
consumedNodeIds.add(prevNode.id);
|
|
822
|
+
return mergeWithPrev(baseNode, prevNode);
|
|
815
823
|
});
|
|
816
824
|
const validNodeIds = new Set(sourceNodes.map((node) => node.id));
|
|
817
825
|
const sourceEdges = schema.tables.flatMap((table) => this.createEdgesFromTable(sourceName, table, schema.tables).filter((edge) => validNodeIds.has(edge.source) && validNodeIds.has(edge.target)));
|
|
@@ -944,6 +952,28 @@ var AstToUiConverter = class {
|
|
|
944
952
|
} }
|
|
945
953
|
};
|
|
946
954
|
}
|
|
955
|
+
static tableSignature(table) {
|
|
956
|
+
const columns = [...table.columns].sort((a, b) => a.name.localeCompare(b.name)).map((col) => {
|
|
957
|
+
var _col$dataType$paramet, _col$dataType$paramet2;
|
|
958
|
+
const params = (_col$dataType$paramet = (_col$dataType$paramet2 = col.dataType.parameters) === null || _col$dataType$paramet2 === void 0 ? void 0 : _col$dataType$paramet2.join(",")) !== null && _col$dataType$paramet !== void 0 ? _col$dataType$paramet : "";
|
|
959
|
+
return [
|
|
960
|
+
col.name,
|
|
961
|
+
col.dataType.name,
|
|
962
|
+
params,
|
|
963
|
+
col.dataType.unsigned ? "u" : "",
|
|
964
|
+
col.dataType.timezone ? "tz" : "",
|
|
965
|
+
col.nullable ? "null" : "notnull",
|
|
966
|
+
col.autoIncrement ? "ai" : ""
|
|
967
|
+
].join(":");
|
|
968
|
+
});
|
|
969
|
+
const constraints = table.constraints.map((c) => JSON.stringify(c)).sort();
|
|
970
|
+
const indexes = [...table.indexes].map((idx) => JSON.stringify(idx)).sort();
|
|
971
|
+
return JSON.stringify({
|
|
972
|
+
columns,
|
|
973
|
+
constraints,
|
|
974
|
+
indexes
|
|
975
|
+
});
|
|
976
|
+
}
|
|
947
977
|
static extractPrimaryKeys(table) {
|
|
948
978
|
const pkConstraint = table.constraints.find((c) => c.type === "primary_key");
|
|
949
979
|
if (pkConstraint) return pkConstraint.columns;
|
|
@@ -1800,8 +1830,8 @@ function flattenMetaData(fields, fieldsValues) {
|
|
|
1800
1830
|
break;
|
|
1801
1831
|
case ComponentInputType.FileUpload:
|
|
1802
1832
|
case ComponentInputType.LinkOrFileUpload:
|
|
1803
|
-
var
|
|
1804
|
-
output[id] = (
|
|
1833
|
+
var _ref, _data$4;
|
|
1834
|
+
output[id] = (_ref = data === null || data === void 0 || (_data$4 = data[0]) === null || _data$4 === void 0 ? void 0 : _data$4.value) !== null && _ref !== void 0 ? _ref : null;
|
|
1805
1835
|
break;
|
|
1806
1836
|
case ComponentInputType.RichTextEditor:
|
|
1807
1837
|
var _data$5;
|
|
@@ -1811,8 +1841,8 @@ function flattenMetaData(fields, fieldsValues) {
|
|
|
1811
1841
|
output[id] = data !== null && data !== void 0 ? data : [];
|
|
1812
1842
|
break;
|
|
1813
1843
|
case ComponentInputType.BooleanToggle:
|
|
1814
|
-
var _data$0$
|
|
1815
|
-
output[id] = (_data$0$
|
|
1844
|
+
var _data$0$value3, _data$6;
|
|
1845
|
+
output[id] = (_data$0$value3 = data === null || data === void 0 || (_data$6 = data[0]) === null || _data$6 === void 0 ? void 0 : _data$6.value) !== null && _data$0$value3 !== void 0 ? _data$0$value3 : false;
|
|
1816
1846
|
break;
|
|
1817
1847
|
case ComponentInputType.DateRangePicker:
|
|
1818
1848
|
output[id] = data === null || data === void 0 ? void 0 : data[0];
|
|
@@ -1847,9 +1877,14 @@ function buildMetaData(fields, data) {
|
|
|
1847
1877
|
localData = [{ value: value != null ? Number(value) : null }];
|
|
1848
1878
|
break;
|
|
1849
1879
|
case ComponentInputType.FileUpload:
|
|
1850
|
-
case ComponentInputType.LinkOrFileUpload:
|
|
1851
|
-
|
|
1880
|
+
case ComponentInputType.LinkOrFileUpload: {
|
|
1881
|
+
const v = value;
|
|
1882
|
+
localData = [{ value: {
|
|
1883
|
+
fileId: v === null || v === void 0 ? void 0 : v.fileId,
|
|
1884
|
+
url: v === null || v === void 0 ? void 0 : v.url
|
|
1885
|
+
} }];
|
|
1852
1886
|
break;
|
|
1887
|
+
}
|
|
1853
1888
|
case ComponentInputType.RichTextEditor:
|
|
1854
1889
|
localData = [value];
|
|
1855
1890
|
break;
|