@uigraph/sdk 1.1.37 → 1.1.38
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.cjs +58 -28
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +58 -28
- package/package.json +1 -1
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;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.mts
CHANGED
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;
|