mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 14:15:24 +00:00
feat: give plugins their own tables, migrations and sync entities
This commit is contained in:
1 parent
5796186a1c
commit
c496a093ca
47 files changed
+32595
-290
No files matched your search
@@ -1,6 +1,26 @@
|
||||
// Sort writes per destination: response order is lost when both sides are merged.
|
||||
//
|
||||
// Keyed on the self-reference field the rows actually carry rather than on the
|
||||
// entity name, so an entity a plugin adds gets the same treatment without this
|
||||
// process needing the server's entity registry.
|
||||
const SELF_REFERENCE_FIELDS = { hosts: "parentHostSyncId" };
|
||||
|
||||
function selfReferenceField(entityType, writes) {
|
||||
const known = SELF_REFERENCE_FIELDS[entityType];
|
||||
if (known) return known;
|
||||
// A plugin entity declares its own; detect it from the payload.
|
||||
const sample = writes.find((write) => write && write.row);
|
||||
if (!sample) return null;
|
||||
const candidate = Object.keys(sample.row).find(
|
||||
(key) => key === `parent${entityType}SyncId`,
|
||||
);
|
||||
return candidate || null;
|
||||
}
|
||||
|
||||
function orderSyncWrites(entityType, writes) {
|
||||
if (entityType !== "hosts") return writes;
|
||||
const field = selfReferenceField(entityType, writes);
|
||||
if (!field) return writes;
|
||||
|
||||
const destinations = new Map();
|
||||
for (const write of writes) {
|
||||
if (!destinations.has(write.baseUrl)) {
|
||||
@@ -16,9 +36,7 @@ function orderSyncWrites(entityType, writes) {
|
||||
if (visiting.has(write))
|
||||
throw new Error("Cyclic parent host sync dependency");
|
||||
visiting.add(write);
|
||||
const parent = destinations
|
||||
.get(write.baseUrl)
|
||||
.get(write.row.parentHostSyncId);
|
||||
const parent = destinations.get(write.baseUrl).get(write.row[field]);
|
||||
if (parent) visit(parent);
|
||||
visiting.delete(write);
|
||||
visited.add(write);
|
||||
|
||||
Reference in new issue
Block a user