@ibgib/core-gib 0.1.8 → 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.
- package/dist/agent-helpers.d.mts +45 -0
- package/dist/agent-helpers.d.mts.map +1 -0
- package/dist/agent-helpers.mjs +36 -0
- package/dist/agent-helpers.mjs.map +1 -0
- package/dist/keystone/keystone-config-builder.respec.d.mts +2 -0
- package/dist/keystone/keystone-config-builder.respec.d.mts.map +1 -0
- package/dist/keystone/keystone-config-builder.respec.mjs +34 -0
- package/dist/keystone/keystone-config-builder.respec.mjs.map +1 -0
- package/dist/keystone/keystone-constants.d.mts +2 -0
- package/dist/keystone/keystone-constants.d.mts.map +1 -1
- package/dist/keystone/keystone-constants.mjs +2 -0
- package/dist/keystone/keystone-constants.mjs.map +1 -1
- package/dist/keystone/keystone-helpers.d.mts +54 -1
- package/dist/keystone/keystone-helpers.d.mts.map +1 -1
- package/dist/keystone/keystone-helpers.mjs +185 -1
- package/dist/keystone/keystone-helpers.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.d.mts +49 -16
- package/dist/keystone/keystone-service-v1.d.mts.map +1 -1
- package/dist/keystone/keystone-service-v1.mjs +151 -328
- package/dist/keystone/keystone-service-v1.mjs.map +1 -1
- package/dist/keystone/keystone-service-v1.respec.mjs +401 -20
- package/dist/keystone/keystone-service-v1.respec.mjs.map +1 -1
- package/dist/keystone/keystone-types.d.mts +22 -0
- package/dist/keystone/keystone-types.d.mts.map +1 -1
- package/dist/sync/sync-constants.d.mts +17 -0
- package/dist/sync/sync-constants.d.mts.map +1 -0
- package/dist/sync/sync-constants.mjs +16 -0
- package/dist/sync/sync-constants.mjs.map +1 -0
- package/dist/sync/sync-helpers.d.mts +15 -0
- package/dist/sync/sync-helpers.d.mts.map +1 -0
- package/dist/sync/sync-helpers.mjs +46 -0
- package/dist/sync/sync-helpers.mjs.map +1 -0
- package/dist/sync/sync-local-spaces.respec.d.mts +2 -0
- package/dist/sync/sync-local-spaces.respec.d.mts.map +1 -0
- package/dist/sync/sync-local-spaces.respec.mjs +159 -0
- package/dist/sync/sync-local-spaces.respec.mjs.map +1 -0
- package/dist/sync/sync-saga-coordinator.d.mts +118 -0
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -0
- package/dist/sync/sync-saga-coordinator.mjs +399 -0
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -0
- package/dist/sync/sync-saga-coordinator.respec.d.mts +2 -0
- package/dist/sync/sync-saga-coordinator.respec.d.mts.map +1 -0
- package/dist/sync/sync-saga-coordinator.respec.mjs +40 -0
- package/dist/sync/sync-saga-coordinator.respec.mjs.map +1 -0
- package/dist/sync/sync-types.d.mts +103 -0
- package/dist/sync/sync-types.d.mts.map +1 -0
- package/dist/sync/sync-types.mjs +2 -0
- package/dist/sync/sync-types.mjs.map +1 -0
- package/dist/test/mock-space.d.mts +39 -0
- package/dist/test/mock-space.d.mts.map +1 -0
- package/dist/test/mock-space.mjs +79 -0
- package/dist/test/mock-space.mjs.map +1 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +163 -201
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
- package/dist/witness/space/space-helper.d.mts.map +1 -1
- package/dist/witness/space/space-helper.mjs +43 -4
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/dist/witness/space/space-helper.respec.d.mts +2 -0
- package/dist/witness/space/space-helper.respec.d.mts.map +1 -0
- package/dist/witness/space/space-helper.respec.mjs +30 -0
- package/dist/witness/space/space-helper.respec.mjs.map +1 -0
- package/package.json +2 -2
- package/src/agent-helpers.mts +58 -0
- package/src/keystone/keystone-config-builder.respec.mts +49 -0
- package/src/keystone/keystone-constants.mts +2 -0
- package/src/keystone/keystone-helpers.mts +211 -2
- package/src/keystone/keystone-service-v1.mts +183 -367
- package/src/keystone/keystone-service-v1.respec.mts +484 -21
- package/src/keystone/keystone-types.mts +24 -0
- package/src/sync/sync-constants.mts +24 -0
- package/src/sync/sync-helpers.mts +59 -0
- package/src/sync/sync-local-spaces.respec.mts +200 -0
- package/src/sync/sync-saga-coordinator.mts +477 -0
- package/src/sync/sync-saga-coordinator.respec.mts +52 -0
- package/src/sync/sync-types.mts +120 -0
- package/src/test/mock-space.mts +85 -0
- package/src/witness/space/inner-space/inner-space-v1.respec.mts +181 -228
- package/src/witness/space/space-helper.mts +42 -4
- package/src/witness/space/space-helper.respec.mts +42 -0
- package/tmp.md +11 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
|
+
import { Ib } from "@ibgib/ts-gib/dist/types.mjs";
|
|
3
|
+
import { SYNC_ATOM } from "./sync-constants.mjs";
|
|
4
|
+
import { SyncData_V1, SyncIbInfo_V1 } from "./sync-types.mjs";
|
|
5
|
+
|
|
6
|
+
const GLOBAL_LOG_A_LOT = false; // Todo: import from core constants if needed
|
|
7
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructs the standard 'ib' string for a Sync frame.
|
|
11
|
+
*/
|
|
12
|
+
export async function getSyncIb({
|
|
13
|
+
data,
|
|
14
|
+
}: {
|
|
15
|
+
data: SyncData_V1,
|
|
16
|
+
}): Promise<Ib> {
|
|
17
|
+
const lc = `[${getSyncIb.name}]`;
|
|
18
|
+
try {
|
|
19
|
+
// sync uuid stage
|
|
20
|
+
// e.g. "sync 1234-5678 init"
|
|
21
|
+
const ib = [
|
|
22
|
+
SYNC_ATOM,
|
|
23
|
+
data.uuid,
|
|
24
|
+
data.stage
|
|
25
|
+
].join(' ');
|
|
26
|
+
|
|
27
|
+
return ib;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parses a standard Sync 'ib' string.
|
|
36
|
+
*/
|
|
37
|
+
export async function parseSyncIb({
|
|
38
|
+
ib,
|
|
39
|
+
}: {
|
|
40
|
+
ib: Ib,
|
|
41
|
+
}): Promise<SyncIbInfo_V1> {
|
|
42
|
+
const lc = `[${parseSyncIb.name}]`;
|
|
43
|
+
try {
|
|
44
|
+
const parts = ib.split(' ');
|
|
45
|
+
if (parts.length !== 3) {
|
|
46
|
+
throw new Error(`Invalid sync ib. Expected 3 parts [atom uuid stage]. Got ${parts.length}. (E: 7c8d9...)`);
|
|
47
|
+
}
|
|
48
|
+
const [atom, uuid, stage] = parts;
|
|
49
|
+
|
|
50
|
+
if (atom !== SYNC_ATOM) {
|
|
51
|
+
throw new Error(`Invalid sync ib. Expected atom '${SYNC_ATOM}', got '${atom}'. (E: 8f9e1...)`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { atom, uuid, stage: stage as any };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises';
|
|
2
|
+
import { default as pathUtils } from 'path';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
respecfully, lastOfAll
|
|
6
|
+
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
7
|
+
const maam = `[${import.meta.url}]`, sir = maam;
|
|
8
|
+
|
|
9
|
+
import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/factory.mjs';
|
|
10
|
+
import { rel8 } from '@ibgib/ts-gib/dist/V1/transforms/rel8.mjs';
|
|
11
|
+
import { getIbGibAddr, } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
12
|
+
import { IBGIB_ENCODING } from '../witness/space/filesystem-space/filesystem-constants.mjs';
|
|
13
|
+
import { NodeFilesystemSpace_V1 } from '../witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-v1.mjs';
|
|
14
|
+
import { NodeFilesystemSpaceData_V1 } from '../witness/space/filesystem-space/node-filesystem-space/node-filesystem-space-types.mjs';
|
|
15
|
+
import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
|
|
16
|
+
import { SyncStage } from './sync-constants.mjs';
|
|
17
|
+
import { getTimestampInTicks, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
18
|
+
import { GIB, IBGIB_DELIMITER } from '@ibgib/ts-gib/dist/V1/constants.mjs';
|
|
19
|
+
import { putInSpace, getFromSpace } from '../witness/space/space-helper.mjs';
|
|
20
|
+
import { KeystoneService_V1 } from '../keystone/keystone-service-v1.mjs';
|
|
21
|
+
import { KeystoneIbGib_V1 } from '../keystone/keystone-types.mjs';
|
|
22
|
+
import { mut8 } from '@ibgib/ts-gib/dist/V1/transforms/mut8.mjs';
|
|
23
|
+
|
|
24
|
+
const logalot = true;
|
|
25
|
+
const lc = `[sync-local-spaces.respec]`;
|
|
26
|
+
|
|
27
|
+
// Helper to create a temp space
|
|
28
|
+
const createTempSpace = async ({
|
|
29
|
+
baseDir,
|
|
30
|
+
name
|
|
31
|
+
}: {
|
|
32
|
+
baseDir: string,
|
|
33
|
+
name: string
|
|
34
|
+
}): Promise<NodeFilesystemSpace_V1> => {
|
|
35
|
+
const uuid = await getUUID();
|
|
36
|
+
const initialData: NodeFilesystemSpaceData_V1 = {
|
|
37
|
+
version: '1',
|
|
38
|
+
classname: NodeFilesystemSpace_V1.name,
|
|
39
|
+
uuid,
|
|
40
|
+
name,
|
|
41
|
+
description: `Temp space for ${name}`,
|
|
42
|
+
baseDir,
|
|
43
|
+
baseSubPath: 'ibgib', // keep short to avoid long path issues
|
|
44
|
+
spaceSubPath: name,
|
|
45
|
+
ibgibsSubPath: 'ibgibs',
|
|
46
|
+
metaSubPath: 'meta',
|
|
47
|
+
binSubPath: 'bin',
|
|
48
|
+
dnaSubPath: 'dna',
|
|
49
|
+
encoding: IBGIB_ENCODING,
|
|
50
|
+
mitigateLongPaths: true,
|
|
51
|
+
// other defaults
|
|
52
|
+
catchAllErrors: false,
|
|
53
|
+
trace: false,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// mimic constructor logic if needed, or just new it up
|
|
57
|
+
const space = new NodeFilesystemSpace_V1(initialData);
|
|
58
|
+
// Explicitly initialize if needed (based on findings, constructor calls super which calls initialize?
|
|
59
|
+
// Actually source had it commented out in ctor. Let's call it via a witness "put" which should verify initialization)
|
|
60
|
+
return space;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// class MockKeystoneService implements KeystoneService_V1 {
|
|
64
|
+
// async getIdentity(): Promise<KeystoneIbGib_V1> {
|
|
65
|
+
// // Return a dummy identity
|
|
66
|
+
// const res = await Factory_V1.firstGen({
|
|
67
|
+
// ib: 'identity',
|
|
68
|
+
// data: { uuid: await getUUID() },
|
|
69
|
+
// dna: true,
|
|
70
|
+
// });
|
|
71
|
+
// return res.newIbGib as KeystoneIbGib_V1;
|
|
72
|
+
// }
|
|
73
|
+
// // Implement other methods as no-ops or simple mocks
|
|
74
|
+
// async sign(ibGib: any): Promise<any> { return ibGib; }
|
|
75
|
+
// async verify(ibGib: any): Promise<boolean> { return true; }
|
|
76
|
+
// // Add other required properties/methods of KeystoneService_V1 if any (checking interface might be needed)
|
|
77
|
+
// // Assuming for now these are the core ones used by Coordinator.
|
|
78
|
+
// // If strict interface, might need more.
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
await respecfully(sir, `Sync Local Spaces`, async () => {
|
|
82
|
+
|
|
83
|
+
const TEST_ROOT = pathUtils.join(process.cwd(), 'tmp_sync_test_' + await getUUID());
|
|
84
|
+
|
|
85
|
+
lastOfAll(sir, async () => {
|
|
86
|
+
if (!logalot) {
|
|
87
|
+
await rm(TEST_ROOT, { recursive: true, force: true });
|
|
88
|
+
} else {
|
|
89
|
+
console.log(`${lc} Leaving TEST_ROOT for inspection: ${TEST_ROOT}`);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await respecfully(sir, `Basic Push Sync (Source -> Dest)`, async () => {
|
|
94
|
+
// // 1. Setup Spaces
|
|
95
|
+
// const srcDir = pathUtils.join(TEST_ROOT, 'source');
|
|
96
|
+
// const destDir = pathUtils.join(TEST_ROOT, 'dest');
|
|
97
|
+
|
|
98
|
+
// const sourceSpace = await createTempSpace({ baseDir: srcDir, name: 'source' });
|
|
99
|
+
// const destSpace = await createTempSpace({ baseDir: destDir, name: 'dest' });
|
|
100
|
+
|
|
101
|
+
// // 2. Seed Source Data
|
|
102
|
+
// // 2.1 Create a "Stone" (Primitive-like or just immutable data)
|
|
103
|
+
// const stoneRes = await Factory_V1.firstGen({
|
|
104
|
+
// ib: 'stone_data',
|
|
105
|
+
// data: { some: 'data', timestamp: getTimestampInTicks() },
|
|
106
|
+
// dna: false,
|
|
107
|
+
// });
|
|
108
|
+
// const stone = stoneRes.newIbGib;
|
|
109
|
+
// const stoneAddr = getIbGibAddr({ ibGib: stone });
|
|
110
|
+
|
|
111
|
+
// // 2.2 Create a "Living" Timeline (Root -> Child)
|
|
112
|
+
// const rootRes = await Factory_V1.firstGen({
|
|
113
|
+
// ib: 'timeline_root',
|
|
114
|
+
// data: { type: 'root' },
|
|
115
|
+
// dna: true,
|
|
116
|
+
// });
|
|
117
|
+
// const root = rootRes.newIbGib;
|
|
118
|
+
// const rootAddr = getIbGibAddr({ ibGib: root });
|
|
119
|
+
|
|
120
|
+
// const childRes = await mut8({
|
|
121
|
+
// type: 'fork',
|
|
122
|
+
// src: root,
|
|
123
|
+
// dna: true,
|
|
124
|
+
// data: { type: 'child', n: 1 }
|
|
125
|
+
// });
|
|
126
|
+
// const child = childRes.newIbGib;
|
|
127
|
+
// const childAddr = getIbGibAddr({ ibGib: child });
|
|
128
|
+
|
|
129
|
+
// // Put into Source
|
|
130
|
+
// await putInSpace({
|
|
131
|
+
// space: sourceSpace,
|
|
132
|
+
// ibGibs: [stone, root, child]
|
|
133
|
+
// });
|
|
134
|
+
|
|
135
|
+
// // 3. Setup Sync Coordinator
|
|
136
|
+
// const mockKeystone = new MockKeystoneService() as unknown as KeystoneService_V1;
|
|
137
|
+
// const identity = await mockKeystone.getIdentity();
|
|
138
|
+
// const coordinator = new SyncSagaCoordinator(mockKeystone);
|
|
139
|
+
|
|
140
|
+
// // Define domain (roots to sync)
|
|
141
|
+
// const domainIbGibs = [root]; // We only explicitly track the "Living" root. Stone is standalone?
|
|
142
|
+
// // Actually for the test let's explicitly include both or rely on dependency graph.
|
|
143
|
+
// // If 'stone' is not related to 'root', it won't be picked up unless we add it to domain.
|
|
144
|
+
// // Let's Rel8 the stone to the child to test dependency traversal.
|
|
145
|
+
|
|
146
|
+
// const childWithRelRes = await rel8({
|
|
147
|
+
// src: child,
|
|
148
|
+
// rel8nsToAddByAddr: { 'linked_stone': [stoneAddr] },
|
|
149
|
+
// dna: true,
|
|
150
|
+
// });
|
|
151
|
+
// const childWithRel = childWithRelRes.newIbGib;
|
|
152
|
+
// const childWithRelAddr = getIbGibAddr({ ibGib: childWithRel });
|
|
153
|
+
|
|
154
|
+
// // Update Source with linked child
|
|
155
|
+
// await putInSpace({
|
|
156
|
+
// space: sourceSpace,
|
|
157
|
+
// ibGibs: [childWithRel]
|
|
158
|
+
// });
|
|
159
|
+
|
|
160
|
+
// // 4. Run Sync
|
|
161
|
+
// const syncRes = await coordinator.sync({
|
|
162
|
+
// source: sourceSpace,
|
|
163
|
+
// dest: destSpace,
|
|
164
|
+
// domainIbGibs: [childWithRel], // Sync starting from the tip
|
|
165
|
+
// identity
|
|
166
|
+
// });
|
|
167
|
+
|
|
168
|
+
// // 5. Verify Dest
|
|
169
|
+
// // Check Stone
|
|
170
|
+
// const getStone = await getFromSpace({
|
|
171
|
+
// space: destSpace,
|
|
172
|
+
// addr: stoneAddr
|
|
173
|
+
// });
|
|
174
|
+
// if (!getStone.success || !getStone.ibGibs?.[0]) {
|
|
175
|
+
// throw new Error(`Dest failed to get Stone: ${stoneAddr}`);
|
|
176
|
+
// }
|
|
177
|
+
// console.log(`${lc} Verified Stone synced.`);
|
|
178
|
+
|
|
179
|
+
// // Check ChildWithRel (Tip)
|
|
180
|
+
// const getChild = await getFromSpace({
|
|
181
|
+
// space: destSpace,
|
|
182
|
+
// addr: childWithRelAddr
|
|
183
|
+
// });
|
|
184
|
+
// if (!getChild.success || !getChild.ibGibs?.[0]) {
|
|
185
|
+
// throw new Error(`Dest failed to get ChildWithRel: ${childWithRelAddr}`);
|
|
186
|
+
// }
|
|
187
|
+
// console.log(`${lc} Verified Timeline Tip synced.`);
|
|
188
|
+
|
|
189
|
+
// // Check Root (Dependency)
|
|
190
|
+
// const getRoot = await getFromSpace({
|
|
191
|
+
// space: destSpace,
|
|
192
|
+
// addr: rootAddr
|
|
193
|
+
// });
|
|
194
|
+
// if (!getRoot.success || !getRoot.ibGibs?.[0]) {
|
|
195
|
+
// throw new Error(`Dest failed to get Root: ${rootAddr}`);
|
|
196
|
+
// }
|
|
197
|
+
// console.log(`${lc} Verified Root synced.`);
|
|
198
|
+
|
|
199
|
+
});
|
|
200
|
+
});
|