@ibgib/core-gib 0.1.9 → 0.1.10

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.
Files changed (60) hide show
  1. package/dist/agent-helpers.d.mts +45 -0
  2. package/dist/agent-helpers.d.mts.map +1 -0
  3. package/dist/agent-helpers.mjs +36 -0
  4. package/dist/agent-helpers.mjs.map +1 -0
  5. package/dist/keystone/keystone-config-builder.respec.mjs +4 -4
  6. package/dist/keystone/keystone-config-builder.respec.mjs.map +1 -1
  7. package/dist/keystone/keystone-service-v1.respec.mjs +65 -62
  8. package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
  9. package/dist/sync/sync-constants.d.mts +17 -0
  10. package/dist/sync/sync-constants.d.mts.map +1 -0
  11. package/dist/sync/sync-constants.mjs +16 -0
  12. package/dist/sync/sync-constants.mjs.map +1 -0
  13. package/dist/sync/sync-helpers.d.mts +15 -0
  14. package/dist/sync/sync-helpers.d.mts.map +1 -0
  15. package/dist/sync/sync-helpers.mjs +46 -0
  16. package/dist/sync/sync-helpers.mjs.map +1 -0
  17. package/dist/sync/sync-local-spaces.respec.d.mts +2 -0
  18. package/dist/sync/sync-local-spaces.respec.d.mts.map +1 -0
  19. package/dist/sync/sync-local-spaces.respec.mjs +159 -0
  20. package/dist/sync/sync-local-spaces.respec.mjs.map +1 -0
  21. package/dist/sync/sync-saga-coordinator.d.mts +118 -0
  22. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -0
  23. package/dist/sync/sync-saga-coordinator.mjs +399 -0
  24. package/dist/sync/sync-saga-coordinator.mjs.map +1 -0
  25. package/dist/sync/sync-saga-coordinator.respec.d.mts +2 -0
  26. package/dist/sync/sync-saga-coordinator.respec.d.mts.map +1 -0
  27. package/dist/sync/sync-saga-coordinator.respec.mjs +40 -0
  28. package/dist/sync/sync-saga-coordinator.respec.mjs.map +1 -0
  29. package/dist/sync/sync-types.d.mts +103 -0
  30. package/dist/sync/sync-types.d.mts.map +1 -0
  31. package/dist/sync/sync-types.mjs +2 -0
  32. package/dist/sync/sync-types.mjs.map +1 -0
  33. package/dist/test/mock-space.d.mts +39 -0
  34. package/dist/test/mock-space.d.mts.map +1 -0
  35. package/dist/test/mock-space.mjs +79 -0
  36. package/dist/test/mock-space.mjs.map +1 -0
  37. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +163 -201
  38. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
  39. package/dist/witness/space/space-helper.d.mts.map +1 -1
  40. package/dist/witness/space/space-helper.mjs +43 -4
  41. package/dist/witness/space/space-helper.mjs.map +1 -1
  42. package/dist/witness/space/space-helper.respec.d.mts +2 -0
  43. package/dist/witness/space/space-helper.respec.d.mts.map +1 -0
  44. package/dist/witness/space/space-helper.respec.mjs +30 -0
  45. package/dist/witness/space/space-helper.respec.mjs.map +1 -0
  46. package/package.json +2 -2
  47. package/src/agent-helpers.mts +58 -0
  48. package/src/keystone/keystone-config-builder.respec.mts +3 -3
  49. package/src/keystone/keystone-service-v1.respec.mts +66 -60
  50. package/src/sync/sync-constants.mts +24 -0
  51. package/src/sync/sync-helpers.mts +59 -0
  52. package/src/sync/sync-local-spaces.respec.mts +200 -0
  53. package/src/sync/sync-saga-coordinator.mts +477 -0
  54. package/src/sync/sync-saga-coordinator.respec.mts +52 -0
  55. package/src/sync/sync-types.mts +120 -0
  56. package/src/test/mock-space.mts +85 -0
  57. package/src/witness/space/inner-space/inner-space-v1.respec.mts +181 -228
  58. package/src/witness/space/space-helper.mts +42 -4
  59. package/src/witness/space/space-helper.respec.mts +42 -0
  60. package/tmp.md +11 -0
@@ -0,0 +1,16 @@
1
+ export const SYNC_ATOM = "sync";
2
+ /**
3
+ * Protocol version string for V1.
4
+ */
5
+ export const SYNC_PROTOCOL_V1 = "sync 1.0.0";
6
+ export const SYNC_STAGE_INIT = "init";
7
+ export const SYNC_STAGE_REQUEST = "request";
8
+ export const SYNC_STAGE_DELTA = "delta";
9
+ export const SYNC_STAGE_COMMIT = "commit";
10
+ export const SyncStage = {
11
+ init: SYNC_STAGE_INIT,
12
+ request: SYNC_STAGE_REQUEST,
13
+ delta: SYNC_STAGE_DELTA,
14
+ commit: SYNC_STAGE_COMMIT,
15
+ };
16
+ //# sourceMappingURL=sync-constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-constants.mjs","sourceRoot":"","sources":["../../src/sync/sync-constants.mts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAC5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAQ1C,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,kBAAkB;IAC3B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE,iBAAiB;CACnB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Ib } from "@ibgib/ts-gib/dist/types.mjs";
2
+ import { SyncData_V1, SyncIbInfo_V1 } from "./sync-types.mjs";
3
+ /**
4
+ * Constructs the standard 'ib' string for a Sync frame.
5
+ */
6
+ export declare function getSyncIb({ data, }: {
7
+ data: SyncData_V1;
8
+ }): Promise<Ib>;
9
+ /**
10
+ * Parses a standard Sync 'ib' string.
11
+ */
12
+ export declare function parseSyncIb({ ib, }: {
13
+ ib: Ib;
14
+ }): Promise<SyncIbInfo_V1>;
15
+ //# sourceMappingURL=sync-helpers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-helpers.d.mts","sourceRoot":"","sources":["../../src/sync/sync-helpers.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,8BAA8B,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAK9D;;GAEG;AACH,wBAAsB,SAAS,CAAC,EAC5B,IAAI,GACP,EAAE;IACC,IAAI,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,EAAE,CAAC,CAgBd;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,EAC9B,EAAE,GACL,EAAE;IACC,EAAE,EAAE,EAAE,CAAC;CACV,GAAG,OAAO,CAAC,aAAa,CAAC,CAkBzB"}
@@ -0,0 +1,46 @@
1
+ import { extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
2
+ import { SYNC_ATOM } from "./sync-constants.mjs";
3
+ const GLOBAL_LOG_A_LOT = false; // Todo: import from core constants if needed
4
+ const logalot = GLOBAL_LOG_A_LOT;
5
+ /**
6
+ * Constructs the standard 'ib' string for a Sync frame.
7
+ */
8
+ export async function getSyncIb({ data, }) {
9
+ const lc = `[${getSyncIb.name}]`;
10
+ try {
11
+ // sync uuid stage
12
+ // e.g. "sync 1234-5678 init"
13
+ const ib = [
14
+ SYNC_ATOM,
15
+ data.uuid,
16
+ data.stage
17
+ ].join(' ');
18
+ return ib;
19
+ }
20
+ catch (error) {
21
+ console.error(`${lc} ${extractErrorMsg(error)}`);
22
+ throw error;
23
+ }
24
+ }
25
+ /**
26
+ * Parses a standard Sync 'ib' string.
27
+ */
28
+ export async function parseSyncIb({ ib, }) {
29
+ const lc = `[${parseSyncIb.name}]`;
30
+ try {
31
+ const parts = ib.split(' ');
32
+ if (parts.length !== 3) {
33
+ throw new Error(`Invalid sync ib. Expected 3 parts [atom uuid stage]. Got ${parts.length}. (E: 7c8d9...)`);
34
+ }
35
+ const [atom, uuid, stage] = parts;
36
+ if (atom !== SYNC_ATOM) {
37
+ throw new Error(`Invalid sync ib. Expected atom '${SYNC_ATOM}', got '${atom}'. (E: 8f9e1...)`);
38
+ }
39
+ return { atom, uuid, stage: stage };
40
+ }
41
+ catch (error) {
42
+ console.error(`${lc} ${extractErrorMsg(error)}`);
43
+ throw error;
44
+ }
45
+ }
46
+ //# sourceMappingURL=sync-helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-helpers.mjs","sourceRoot":"","sources":["../../src/sync/sync-helpers.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,6CAA6C;AAC7E,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC5B,IAAI,GAGP;IACG,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,IAAI,GAAG,CAAC;IACjC,IAAI,CAAC;QACD,kBAAkB;QAClB,6BAA6B;QAC7B,MAAM,EAAE,GAAG;YACP,SAAS;YACT,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,KAAK;SACb,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEZ,OAAO,EAAE,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAC9B,EAAE,GAGL;IACG,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC;IACnC,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,4DAA4D,KAAK,CAAC,MAAM,iBAAiB,CAAC,CAAC;QAC/G,CAAC;QACD,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;QAElC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,mCAAmC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC;QACnG,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAY,EAAE,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sync-local-spaces.respec.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-local-spaces.respec.d.mts","sourceRoot":"","sources":["../../src/sync/sync-local-spaces.respec.mts"],"names":[],"mappings":""}
@@ -0,0 +1,159 @@
1
+ import { rm } from 'node:fs/promises';
2
+ import { default as pathUtils } from 'path';
3
+ import { respecfully, lastOfAll } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
4
+ const maam = `[${import.meta.url}]`, sir = maam;
5
+ import { IBGIB_ENCODING } from '../witness/space/filesystem-space/filesystem-constants.mjs';
6
+ import { NodeFilesystemSpace_V1 } from '../witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs';
7
+ import { getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
8
+ const logalot = true;
9
+ const lc = `[sync-local-spaces.respec]`;
10
+ // Helper to create a temp space
11
+ const createTempSpace = async ({ baseDir, name }) => {
12
+ const uuid = await getUUID();
13
+ const initialData = {
14
+ version: '1',
15
+ classname: NodeFilesystemSpace_V1.name,
16
+ uuid,
17
+ name,
18
+ description: `Temp space for ${name}`,
19
+ baseDir,
20
+ baseSubPath: 'ibgib', // keep short to avoid long path issues
21
+ spaceSubPath: name,
22
+ ibgibsSubPath: 'ibgibs',
23
+ metaSubPath: 'meta',
24
+ binSubPath: 'bin',
25
+ dnaSubPath: 'dna',
26
+ encoding: IBGIB_ENCODING,
27
+ mitigateLongPaths: true,
28
+ // other defaults
29
+ catchAllErrors: false,
30
+ trace: false,
31
+ };
32
+ // mimic constructor logic if needed, or just new it up
33
+ const space = new NodeFilesystemSpace_V1(initialData);
34
+ // Explicitly initialize if needed (based on findings, constructor calls super which calls initialize?
35
+ // Actually source had it commented out in ctor. Let's call it via a witness "put" which should verify initialization)
36
+ return space;
37
+ };
38
+ // class MockKeystoneService implements KeystoneService_V1 {
39
+ // async getIdentity(): Promise<KeystoneIbGib_V1> {
40
+ // // Return a dummy identity
41
+ // const res = await Factory_V1.firstGen({
42
+ // ib: 'identity',
43
+ // data: { uuid: await getUUID() },
44
+ // dna: true,
45
+ // });
46
+ // return res.newIbGib as KeystoneIbGib_V1;
47
+ // }
48
+ // // Implement other methods as no-ops or simple mocks
49
+ // async sign(ibGib: any): Promise<any> { return ibGib; }
50
+ // async verify(ibGib: any): Promise<boolean> { return true; }
51
+ // // Add other required properties/methods of KeystoneService_V1 if any (checking interface might be needed)
52
+ // // Assuming for now these are the core ones used by Coordinator.
53
+ // // If strict interface, might need more.
54
+ // }
55
+ await respecfully(sir, `Sync Local Spaces`, async () => {
56
+ const TEST_ROOT = pathUtils.join(process.cwd(), 'tmp_sync_test_' + await getUUID());
57
+ lastOfAll(sir, async () => {
58
+ if (!logalot) {
59
+ await rm(TEST_ROOT, { recursive: true, force: true });
60
+ }
61
+ else {
62
+ console.log(`${lc} Leaving TEST_ROOT for inspection: ${TEST_ROOT}`);
63
+ }
64
+ });
65
+ await respecfully(sir, `Basic Push Sync (Source -> Dest)`, async () => {
66
+ // // 1. Setup Spaces
67
+ // const srcDir = pathUtils.join(TEST_ROOT, 'source');
68
+ // const destDir = pathUtils.join(TEST_ROOT, 'dest');
69
+ // const sourceSpace = await createTempSpace({ baseDir: srcDir, name: 'source' });
70
+ // const destSpace = await createTempSpace({ baseDir: destDir, name: 'dest' });
71
+ // // 2. Seed Source Data
72
+ // // 2.1 Create a "Stone" (Primitive-like or just immutable data)
73
+ // const stoneRes = await Factory_V1.firstGen({
74
+ // ib: 'stone_data',
75
+ // data: { some: 'data', timestamp: getTimestampInTicks() },
76
+ // dna: false,
77
+ // });
78
+ // const stone = stoneRes.newIbGib;
79
+ // const stoneAddr = getIbGibAddr({ ibGib: stone });
80
+ // // 2.2 Create a "Living" Timeline (Root -> Child)
81
+ // const rootRes = await Factory_V1.firstGen({
82
+ // ib: 'timeline_root',
83
+ // data: { type: 'root' },
84
+ // dna: true,
85
+ // });
86
+ // const root = rootRes.newIbGib;
87
+ // const rootAddr = getIbGibAddr({ ibGib: root });
88
+ // const childRes = await mut8({
89
+ // type: 'fork',
90
+ // src: root,
91
+ // dna: true,
92
+ // data: { type: 'child', n: 1 }
93
+ // });
94
+ // const child = childRes.newIbGib;
95
+ // const childAddr = getIbGibAddr({ ibGib: child });
96
+ // // Put into Source
97
+ // await putInSpace({
98
+ // space: sourceSpace,
99
+ // ibGibs: [stone, root, child]
100
+ // });
101
+ // // 3. Setup Sync Coordinator
102
+ // const mockKeystone = new MockKeystoneService() as unknown as KeystoneService_V1;
103
+ // const identity = await mockKeystone.getIdentity();
104
+ // const coordinator = new SyncSagaCoordinator(mockKeystone);
105
+ // // Define domain (roots to sync)
106
+ // const domainIbGibs = [root]; // We only explicitly track the "Living" root. Stone is standalone?
107
+ // // Actually for the test let's explicitly include both or rely on dependency graph.
108
+ // // If 'stone' is not related to 'root', it won't be picked up unless we add it to domain.
109
+ // // Let's Rel8 the stone to the child to test dependency traversal.
110
+ // const childWithRelRes = await rel8({
111
+ // src: child,
112
+ // rel8nsToAddByAddr: { 'linked_stone': [stoneAddr] },
113
+ // dna: true,
114
+ // });
115
+ // const childWithRel = childWithRelRes.newIbGib;
116
+ // const childWithRelAddr = getIbGibAddr({ ibGib: childWithRel });
117
+ // // Update Source with linked child
118
+ // await putInSpace({
119
+ // space: sourceSpace,
120
+ // ibGibs: [childWithRel]
121
+ // });
122
+ // // 4. Run Sync
123
+ // const syncRes = await coordinator.sync({
124
+ // source: sourceSpace,
125
+ // dest: destSpace,
126
+ // domainIbGibs: [childWithRel], // Sync starting from the tip
127
+ // identity
128
+ // });
129
+ // // 5. Verify Dest
130
+ // // Check Stone
131
+ // const getStone = await getFromSpace({
132
+ // space: destSpace,
133
+ // addr: stoneAddr
134
+ // });
135
+ // if (!getStone.success || !getStone.ibGibs?.[0]) {
136
+ // throw new Error(`Dest failed to get Stone: ${stoneAddr}`);
137
+ // }
138
+ // console.log(`${lc} Verified Stone synced.`);
139
+ // // Check ChildWithRel (Tip)
140
+ // const getChild = await getFromSpace({
141
+ // space: destSpace,
142
+ // addr: childWithRelAddr
143
+ // });
144
+ // if (!getChild.success || !getChild.ibGibs?.[0]) {
145
+ // throw new Error(`Dest failed to get ChildWithRel: ${childWithRelAddr}`);
146
+ // }
147
+ // console.log(`${lc} Verified Timeline Tip synced.`);
148
+ // // Check Root (Dependency)
149
+ // const getRoot = await getFromSpace({
150
+ // space: destSpace,
151
+ // addr: rootAddr
152
+ // });
153
+ // if (!getRoot.success || !getRoot.ibGibs?.[0]) {
154
+ // throw new Error(`Dest failed to get Root: ${rootAddr}`);
155
+ // }
156
+ // console.log(`${lc} Verified Root synced.`);
157
+ });
158
+ });
159
+ //# sourceMappingURL=sync-local-spaces.respec.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-local-spaces.respec.mjs","sourceRoot":"","sources":["../../src/sync/sync-local-spaces.respec.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,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;QAC/B,mFAAmF;QACnF,qDAAqD;QACrD,6DAA6D;QAE7D,mCAAmC;QACnC,oGAAoG;QACpG,sFAAsF;QACtF,4FAA4F;QAC5F,qEAAqE;QAErE,uCAAuC;QACvC,kBAAkB;QAClB,0DAA0D;QAC1D,iBAAiB;QACjB,MAAM;QACN,iDAAiD;QACjD,kEAAkE;QAElE,qCAAqC;QACrC,qBAAqB;QACrB,0BAA0B;QAC1B,6BAA6B;QAC7B,MAAM;QAEN,iBAAiB;QACjB,2CAA2C;QAC3C,2BAA2B;QAC3B,uBAAuB;QACvB,kEAAkE;QAClE,eAAe;QACf,MAAM;QAEN,oBAAoB;QACpB,iBAAiB;QACjB,wCAAwC;QACxC,wBAAwB;QACxB,sBAAsB;QACtB,MAAM;QACN,oDAAoD;QACpD,iEAAiE;QACjE,IAAI;QACJ,+CAA+C;QAE/C,8BAA8B;QAC9B,wCAAwC;QACxC,wBAAwB;QACxB,6BAA6B;QAC7B,MAAM;QACN,oDAAoD;QACpD,+EAA+E;QAC/E,IAAI;QACJ,sDAAsD;QAEtD,6BAA6B;QAC7B,uCAAuC;QACvC,wBAAwB;QACxB,qBAAqB;QACrB,MAAM;QACN,kDAAkD;QAClD,+DAA+D;QAC/D,IAAI;QACJ,8CAA8C;IAElD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
2
+ import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
3
+ import { KeystoneIbGib_V1 } from "../keystone/keystone-types.mjs";
4
+ import { KeystoneService_V1 } from "../keystone/keystone-service-v1.mjs";
5
+ import { SyncIbGib_V1 } from "./sync-types.mjs";
6
+ export interface SyncOptions {
7
+ /**
8
+ * The space containing the data we want to send.
9
+ */
10
+ source: IbGibSpaceAny;
11
+ /**
12
+ * The space receiving the data.
13
+ */
14
+ dest: IbGibSpaceAny;
15
+ /**
16
+ * The identity authorizing this sync.
17
+ */
18
+ identity: KeystoneIbGib_V1;
19
+ /**
20
+ * The secret for the identity (to sign the commit).
21
+ */
22
+ identitySecret: string;
23
+ }
24
+ /**
25
+ * Orchestrates the synchronization process between two spaces (Source and Destination).
26
+ *
27
+ * ## Architecture: Dependency Graph Synchronization
28
+ *
29
+ * Instead of a naive file-by-file sync or a holistic "Space" sync, this coordinator operates
30
+ * on a **Dependency Graph** derived from specific "Domain Roots" (e.g., a specific tag,
31
+ * folder, or application root).
32
+ *
33
+ * ### Workflow Pipeline
34
+ *
35
+ * 1. **Graph Generation**:
36
+ * * Generates a `FlatIbGibGraph` using `getDependencyGraph({ live: true })` starting
37
+ * from the provided `domainIbGibs`.
38
+ * * This ensures we capture the *latest* reachable state of all relevant timelines.
39
+ *
40
+ * 2. **Classification (`splitPerTjpAndOrDna`)**:
41
+ * * **Stones**: Immutable, non-living ibGibs (no TJP/DNA). Trivial to sync (copy if missing).
42
+ * * **Living**: Evolving timelines (TJP + DNA). Complex to sync (require ordering & merging).
43
+ *
44
+ * 3. **Timeline Ordering (`getTimelinesGroupedByTjp`)**:
45
+ * * Living ibGibs are grouped into timelines.
46
+ * * A "Timeline Dependency Graph" is built. Use Case: If a Comment Timeline refers to a
47
+ * Post Timeline, the Post Timeline must be synced *before* the Comment Timeline to
48
+ * ensure referential integrity at the destination.
49
+ * * **Topological Sort** determines the execution order. Circular dependencies are
50
+ * treated as siblings.
51
+ *
52
+ * 4. **Saga Execution ("Smart Coordinator, Dumb Space")**:
53
+ * * The Coordinator (running on the Client/Source) drives the entire process via a
54
+ * "Pull-Merge-Push" strategy to resolve conflicts.
55
+ *
56
+ * * **Phase 1: Knowledge Exchange (Init)**
57
+ * * Generates a "Knowledge Vector" (Map<Tjp, LatestAddr>) of the Source's graph.
58
+ * * Sends `SyncStage.Init` to Dest.
59
+ * * Dest responds with its own Knowledge Vector for overlapping timelines.
60
+ *
61
+ * * **Phase 2: Gap Analysis & Conflict Resolution**
62
+ * * Coordinator compares Source vs. Dest knowledge.
63
+ * * **Fast-Forward**: Source is strictly ahead of Dest. Mark new frames for PUSH.
64
+ * * **Fast-Backward**: Dest is strictly ahead of Source. Mark frames for PULL (to update Local).
65
+ * * **Conflict/Divergence**: Both have new frames from a common ancestor.
66
+ * * **LOCK**: `lockSpace({ scope: tjpGib })` on Dest to prevent race conditions.
67
+ * * **PULL**: Download conflicting branch from Dest.
68
+ * * **MERGE**: Execute merge logic locally (creating a new merge frame `A_merge`).
69
+ * * **PUSH**: Mark `A_merge` (and dependencies) for PUSH.
70
+ * * **UNLOCK**: Release Dest lock.
71
+ *
72
+ * * **Phase 3: Batch Streaming (Delta)**
73
+ * * **Stones**: Batch `putInSpace` all missing "Stone" ibGibs first.
74
+ * * **Timelines**: Batch `putInSpace` Living Timelines in topological order.
75
+ * * *Note*: The `SyncFrame` (Init/Delta/Commit) tracks protocol state, but data transfer
76
+ * happens via standard `putInSpace`.
77
+ *
78
+ * * **Phase 4: Commit**
79
+ * * Update Local Index (register new latests).
80
+ * * Send `SyncStage.Commit` to Dest to finalize session.
81
+ */
82
+ export declare class SyncSagaCoordinator {
83
+ protected keystone: KeystoneService_V1;
84
+ protected lc: string;
85
+ constructor(keystone: KeystoneService_V1);
86
+ /**
87
+ * Executes a synchronization saga.
88
+ *
89
+ * @param opts.source The local space (Client) driving the sync.
90
+ * @param opts.dest The remote space (Server/Other Peer) to sync with.
91
+ * @param opts.identity The Keystone Identity performing the sync.
92
+ * @param opts.domainIbGibs The root ibGibs that define the scope of the sync (the "Dependency Graph").
93
+ * @param opts.identitySecret Optional secret if needed (usually handled by `keystone` service).
94
+ */
95
+ sync({ source, dest, identity, domainIbGibs, identitySecret }: {
96
+ source: IbGibSpaceAny;
97
+ dest: IbGibSpaceAny;
98
+ identity: KeystoneIbGib_V1;
99
+ domainIbGibs: IbGib_V1[];
100
+ identitySecret?: string;
101
+ }): Promise<void>;
102
+ protected createSyncFrame({ uuid, stage, payload, identity }: {
103
+ uuid: string;
104
+ stage: any;
105
+ payload: any;
106
+ identity: KeystoneIbGib_V1;
107
+ }): Promise<SyncIbGib_V1>;
108
+ protected getLatestAddrsFromSpace({ space, tjpAddrs, }: {
109
+ space: IbGibSpaceAny;
110
+ tjpAddrs: string[];
111
+ }): Promise<{
112
+ [tjpAddr: string]: string;
113
+ }>;
114
+ protected sortTimelinesTopologically(timelines: {
115
+ [tjp: string]: IbGib_V1[];
116
+ }): string[];
117
+ }
118
+ //# sourceMappingURL=sync-saga-coordinator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-saga-coordinator.d.mts","sourceRoot":"","sources":["../../src/sync/sync-saga-coordinator.mts"],"names":[],"mappings":"AASA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAI3D,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EACU,YAAY,EAC5B,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IACtB;;OAEG;IACH,IAAI,EAAE,aAAa,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,qBAAa,mBAAmB;IAIxB,SAAS,CAAC,QAAQ,EAAE,kBAAkB;IAH1C,SAAS,CAAC,EAAE,EAAE,MAAM,CAAmC;gBAGzC,QAAQ,EAAE,kBAAkB;IAG1C;;;;;;;;OAQG;IACG,IAAI,CAAC,EACP,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,cAAc,EACjB,EAAE;QACC,MAAM,EAAE,aAAa,CA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