@xyo-network/chain-orchestration 1.3.17 → 1.3.18
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/neutral/index.mjs +70 -66
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/archivist/index.d.ts +1 -1
- package/dist/types/archivist/index.d.ts.map +1 -1
- package/dist/types/archivist/initArchivistSync.d.ts.map +1 -1
- package/dist/types/archivist/wrapWithReadCachingArchivist.d.ts +5 -0
- package/dist/types/archivist/wrapWithReadCachingArchivist.d.ts.map +1 -0
- package/package.json +16 -15
- package/src/archivist/index.ts +1 -1
- package/src/archivist/initArchivistSync.ts +36 -39
- package/src/archivist/wrapWithReadCachingArchivist.ts +56 -0
- package/dist/types/archivist/wrapWithCachingArchivist.d.ts +0 -5
- package/dist/types/archivist/wrapWithCachingArchivist.d.ts.map +0 -1
- package/src/archivist/wrapWithCachingArchivist.ts +0 -30
package/dist/neutral/index.mjs
CHANGED
|
@@ -3,90 +3,94 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/archivist/initArchivistSync.ts
|
|
5
5
|
import { ArchivistSyncDiviner } from "@xyo-network/chain-modules";
|
|
6
|
-
import { spanAsync } from "@xyo-network/chain-utils";
|
|
7
6
|
import { DivinerConfigSchema } from "@xyo-network/diviner-model";
|
|
8
7
|
import { MemoryNode } from "@xyo-network/node-memory";
|
|
9
8
|
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
10
9
|
import { SentinelConfigSchema } from "@xyo-network/sentinel-model";
|
|
11
10
|
var initArchivistSync = /* @__PURE__ */ __name(async (name, inArchivist, outArchivist, frequency = 1e3, traceProvider) => {
|
|
12
11
|
const tracer = traceProvider?.getTracer(`archivist-sync-diviner [${name}]`);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return node;
|
|
55
|
-
}, tracer);
|
|
12
|
+
const node = await MemoryNode.create({
|
|
13
|
+
account: "random"
|
|
14
|
+
});
|
|
15
|
+
const finalizedArchivistSyncDiviner = await ArchivistSyncDiviner.create({
|
|
16
|
+
account: "random",
|
|
17
|
+
inArchivist,
|
|
18
|
+
outArchivist,
|
|
19
|
+
tracer,
|
|
20
|
+
config: {
|
|
21
|
+
schema: DivinerConfigSchema,
|
|
22
|
+
name
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
await node.register(finalizedArchivistSyncDiviner);
|
|
26
|
+
await node.attach(finalizedArchivistSyncDiviner.address);
|
|
27
|
+
const sentinel = await MemorySentinel.create({
|
|
28
|
+
account: "random",
|
|
29
|
+
config: {
|
|
30
|
+
name,
|
|
31
|
+
schema: SentinelConfigSchema,
|
|
32
|
+
tasks: [
|
|
33
|
+
{
|
|
34
|
+
required: true,
|
|
35
|
+
mod: finalizedArchivistSyncDiviner.address,
|
|
36
|
+
endPoint: "divine"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
automations: [
|
|
40
|
+
{
|
|
41
|
+
frequency,
|
|
42
|
+
frequencyUnits: "millis",
|
|
43
|
+
schema: "network.xyo.automation.interval",
|
|
44
|
+
start: Date.now(),
|
|
45
|
+
type: "interval"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
await node.register(sentinel);
|
|
51
|
+
await node.attach(sentinel.address);
|
|
52
|
+
return node;
|
|
56
53
|
}, "initArchivistSync");
|
|
57
54
|
|
|
58
|
-
// src/archivist/
|
|
55
|
+
// src/archivist/wrapWithReadCachingArchivist.ts
|
|
59
56
|
import { MemoryArchivist, MemoryArchivistConfigSchema } from "@xyo-network/archivist-memory";
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
requireAllParents: true,
|
|
57
|
+
var DefaultReadCachingArchivistConfig = {
|
|
58
|
+
max: 1e5,
|
|
59
|
+
// requireAllParents: true,
|
|
64
60
|
schema: MemoryArchivistConfigSchema
|
|
65
61
|
};
|
|
66
|
-
var
|
|
62
|
+
var getDynamicDefaultReadCachingArchivistConfig = /* @__PURE__ */ __name((archivist) => {
|
|
67
63
|
const { id } = archivist;
|
|
68
64
|
const name = `${id}-CachingArchivist`;
|
|
65
|
+
const dynamicDefaults = {
|
|
66
|
+
name
|
|
67
|
+
};
|
|
68
|
+
return dynamicDefaults;
|
|
69
|
+
}, "getDynamicDefaultReadCachingArchivistConfig");
|
|
70
|
+
var getDynamicReadCachingArchivistConfig = /* @__PURE__ */ __name((archivist) => {
|
|
71
|
+
const dynamicConfig = {};
|
|
72
|
+
return dynamicConfig;
|
|
73
|
+
}, "getDynamicReadCachingArchivistConfig");
|
|
74
|
+
var wrapWithReadCachingArchivist = /* @__PURE__ */ __name(async (archivist, config = DefaultReadCachingArchivistConfig) => {
|
|
75
|
+
const dynamicDefaultReadCachingArchivistConfig = getDynamicDefaultReadCachingArchivistConfig(archivist);
|
|
76
|
+
const dynamicReadCachingArchivistConfig = getDynamicReadCachingArchivistConfig(archivist);
|
|
69
77
|
const materializedConfig = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
// Use the static defaults
|
|
79
|
+
...DefaultReadCachingArchivistConfig,
|
|
80
|
+
// Use the dynamic defaults
|
|
81
|
+
...dynamicDefaultReadCachingArchivistConfig,
|
|
82
|
+
// Use the supplied config
|
|
83
|
+
...config,
|
|
84
|
+
// Use they dynamic config
|
|
85
|
+
...dynamicReadCachingArchivistConfig
|
|
73
86
|
};
|
|
74
|
-
const node = await MemoryNode2.create({
|
|
75
|
-
account: "random"
|
|
76
|
-
});
|
|
77
87
|
const cachingArchivist = await MemoryArchivist.create({
|
|
78
88
|
account: "random",
|
|
79
89
|
config: materializedConfig
|
|
80
90
|
});
|
|
81
|
-
|
|
82
|
-
archivist,
|
|
83
|
-
cachingArchivist
|
|
84
|
-
]) {
|
|
85
|
-
await node.register(mod);
|
|
86
|
-
await node.attach(mod.address);
|
|
87
|
-
}
|
|
91
|
+
await initArchivistSync(`${cachingArchivist.id}-Sync`, archivist, cachingArchivist, 1e3);
|
|
88
92
|
return cachingArchivist;
|
|
89
|
-
}, "
|
|
93
|
+
}, "wrapWithReadCachingArchivist");
|
|
90
94
|
|
|
91
95
|
// src/bridge.ts
|
|
92
96
|
import { HttpBridge, HttpBridgeConfigSchema } from "@xyo-network/bridge-http";
|
|
@@ -146,11 +150,11 @@ var initBridgedArchivistModule = /* @__PURE__ */ __name(async ({ bridge, moduleN
|
|
|
146
150
|
})), () => `Error: Could not convert ${moduleName} to attachable archivist instance`);
|
|
147
151
|
}, "initBridgedArchivistModule");
|
|
148
152
|
export {
|
|
149
|
-
|
|
153
|
+
DefaultReadCachingArchivistConfig,
|
|
150
154
|
initArchivistSync,
|
|
151
155
|
initBridge,
|
|
152
156
|
initBridgedArchivistModule,
|
|
153
157
|
initBridgedModule,
|
|
154
|
-
|
|
158
|
+
wrapWithReadCachingArchivist
|
|
155
159
|
};
|
|
156
160
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/archivist/initArchivistSync.ts","../../src/archivist/wrapWithCachingArchivist.ts","../../src/bridge.ts","../../src/initBridgedModule.ts"],"sourcesContent":["import type { TracerProvider } from '@opentelemetry/api'\nimport type { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { ArchivistSyncDiviner } from '@xyo-network/chain-modules'\nimport { spanAsync } from '@xyo-network/chain-utils'\nimport { DivinerConfigSchema } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { MemoryNode } from '@xyo-network/node-memory'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { SentinelConfigSchema } from '@xyo-network/sentinel-model'\n\nexport const initArchivistSync = async (\n name: ModuleIdentifier,\n inArchivist: ArchivistInstance,\n outArchivist: ArchivistInstance,\n frequency = 1000,\n traceProvider?: TracerProvider,\n) => {\n const tracer = traceProvider?.getTracer(`archivist-sync-diviner [${name}]`)\n return await spanAsync(`initArchivistSync [${name}]`, async () => {\n const node = await MemoryNode.create({ account: 'random' })\n const finalizedArchivistSyncDiviner = await ArchivistSyncDiviner.create({\n account: 'random',\n inArchivist,\n outArchivist,\n tracer,\n config: { schema: DivinerConfigSchema, name },\n })\n\n await node.register(finalizedArchivistSyncDiviner)\n await node.attach(finalizedArchivistSyncDiviner.address)\n\n const sentinel = await MemorySentinel.create({\n account: 'random',\n config: {\n name,\n schema: SentinelConfigSchema,\n tasks: [\n {\n required: true,\n mod: finalizedArchivistSyncDiviner.address,\n endPoint: 'divine',\n },\n ],\n automations: [\n {\n frequency,\n frequencyUnits: 'millis',\n schema: 'network.xyo.automation.interval',\n start: Date.now(),\n type: 'interval',\n },\n ],\n },\n })\n\n await node.register(sentinel)\n await node.attach(sentinel.address)\n\n return node\n }, tracer)\n}\n","import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory'\nimport { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'\nimport type { AttachableArchivistInstance } from '@xyo-network/archivist-model'\nimport { MemoryNode } from '@xyo-network/node-memory'\n\nexport const DefaultCachingArchivistConfig: MemoryArchivistConfig = {\n max: 10_000,\n requireAllParents: true,\n schema: MemoryArchivistConfigSchema,\n}\n\nexport const wrapWithCachingArchivist = async (\n archivist: AttachableArchivistInstance,\n config: Partial<MemoryArchivistConfig> = DefaultCachingArchivistConfig,\n): Promise<AttachableArchivistInstance> => {\n const { id } = archivist\n const name = `${id}-CachingArchivist`\n const materializedConfig: MemoryArchivistConfig = {\n ...DefaultCachingArchivistConfig, name, ...config,\n }\n const node = await MemoryNode.create({ account: 'random' })\n const cachingArchivist = await MemoryArchivist.create({ account: 'random', config: materializedConfig })\n\n for (const mod of [archivist, cachingArchivist]) {\n await node.register(mod)\n await node.attach(mod.address)\n }\n\n return cachingArchivist\n}\n","import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge-http'\nimport type { AttachableBridgeInstance } from '@xyo-network/bridge-model'\nimport { Mutex } from 'async-mutex'\n\nconst initMutex = new Mutex()\nconst bridgeSingletonMap = new Map<string, AttachableBridgeInstance>()\n\nexport const initBridge = async (nodeUrl: string): Promise<AttachableBridgeInstance> => {\n return await initMutex.runExclusive(async () => {\n const existing = bridgeSingletonMap.get(nodeUrl)\n if (existing) return existing\n const bridge = await HttpBridge.create({\n account: 'random',\n config: {\n name: 'HttpBridge',\n client: { url: nodeUrl, discoverRoots: 'start' },\n schema: HttpBridgeConfigSchema,\n security: { allowAnonymous: true },\n },\n })\n await bridge.start()\n bridgeSingletonMap.set(nodeUrl, bridge)\n return bridge\n })\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport type { AttachableArchivistInstance } from '@xyo-network/archivist-model'\nimport { asAttachableArchivistInstance } from '@xyo-network/archivist-model'\nimport type { BridgeInstance } from '@xyo-network/bridge-model'\nimport type { AttachableModuleInstance, ModuleIdentifier } from '@xyo-network/module-model'\nimport { asAttachableModuleInstance } from '@xyo-network/module-model'\nimport type { Initializable } from '@xyo-network/xl1-protocol'\nimport { Mutex } from 'async-mutex'\n\nconst initMutex = new Mutex()\ntype ModuleDictionary = Record<ModuleIdentifier, AttachableModuleInstance | undefined>\ntype BridgedModuleDictionary = Record<Address, ModuleDictionary | undefined>\nconst bridgedModuleDictionary: BridgedModuleDictionary = {}\n\nexport const initBridgedModule: Initializable<\n { bridge: BridgeInstance; moduleName: ModuleIdentifier }, AttachableModuleInstance\n> = async ({ bridge, moduleName }): Promise<AttachableModuleInstance> => {\n return await initMutex.runExclusive(async () => {\n const existing = bridgedModuleDictionary?.[bridge.address]?.[moduleName]\n if (existing) return existing\n const mod = assertEx(await bridge.resolve(moduleName), () => `Error: Could not resolve ${moduleName}`)\n const moduleInstance = assertEx(asAttachableModuleInstance(mod), () => `Error: Could not convert ${moduleName} to attachable module instance`)\n // Initialize the nested dictionary if needed\n let moduleMap = bridgedModuleDictionary[bridge.address]\n if (moduleMap === undefined) {\n moduleMap = {}\n bridgedModuleDictionary[bridge.address] = moduleMap\n }\n // Store and return the module instance\n moduleMap[moduleName] = moduleInstance\n return moduleInstance\n })\n}\n\nexport const initBridgedArchivistModule: Initializable<\n { bridge: BridgeInstance; moduleName: ModuleIdentifier }, AttachableArchivistInstance\n> = async ({ bridge, moduleName }): Promise<AttachableArchivistInstance> => {\n return assertEx(\n asAttachableArchivistInstance(await initBridgedModule({ bridge, moduleName })),\n () => `Error: Could not convert ${moduleName} to attachable archivist instance`,\n )\n}\n"],"mappings":";;;;AAEA,SAASA,4BAA4B;AACrC,SAASC,iBAAiB;AAC1B,SAASC,2BAA2B;AAEpC,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,4BAA4B;AAE9B,IAAMC,oBAAoB,8BAC/BC,MACAC,aACAC,cACAC,YAAY,KACZC,kBAAAA;AAEA,QAAMC,SAASD,eAAeE,UAAU,2BAA2BN,IAAAA,GAAO;AAC1E,SAAO,MAAMO,UAAU,sBAAsBP,IAAAA,KAAS,YAAA;AACpD,UAAMQ,OAAO,MAAMC,WAAWC,OAAO;MAAEC,SAAS;IAAS,CAAA;AACzD,UAAMC,gCAAgC,MAAMC,qBAAqBH,OAAO;MACtEC,SAAS;MACTV;MACAC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EAAEZ,QAAQC,WAAU,MAAE;AAC/B,SAAOK,SACLO,8BAA8B,MAAMd,kBAAkB;IAAEC;IAAQC;EAAW,CAAA,CAAA,GAC3E,MAAM,4BAA4BA,UAAAA,mCAA6C;AAEnF,GALI;","names":["ArchivistSyncDiviner","spanAsync","DivinerConfigSchema","MemoryNode","MemorySentinel","SentinelConfigSchema","initArchivistSync","name","inArchivist","outArchivist","frequency","traceProvider","tracer","getTracer","spanAsync","node","MemoryNode","create","account","finalizedArchivistSyncDiviner","ArchivistSyncDiviner","config","schema","DivinerConfigSchema","register","attach","address","sentinel","MemorySentinel","SentinelConfigSchema","tasks","required","mod","endPoint","automations","frequencyUnits","start","Date","now","type","MemoryArchivist","MemoryArchivistConfigSchema","MemoryNode","DefaultCachingArchivistConfig","max","requireAllParents","schema","MemoryArchivistConfigSchema","wrapWithCachingArchivist","archivist","config","id","name","materializedConfig","node","MemoryNode","create","account","cachingArchivist","MemoryArchivist","mod","register","attach","address","HttpBridge","HttpBridgeConfigSchema","Mutex","initMutex","Mutex","bridgeSingletonMap","Map","initBridge","nodeUrl","runExclusive","existing","get","bridge","HttpBridge","create","account","config","name","client","url","discoverRoots","schema","HttpBridgeConfigSchema","security","allowAnonymous","start","set","assertEx","asAttachableArchivistInstance","asAttachableModuleInstance","Mutex","initMutex","Mutex","bridgedModuleDictionary","initBridgedModule","bridge","moduleName","runExclusive","existing","address","mod","assertEx","resolve","moduleInstance","asAttachableModuleInstance","moduleMap","undefined","initBridgedArchivistModule","asAttachableArchivistInstance"]}
|
|
1
|
+
{"version":3,"sources":["../../src/archivist/initArchivistSync.ts","../../src/archivist/wrapWithReadCachingArchivist.ts","../../src/bridge.ts","../../src/initBridgedModule.ts"],"sourcesContent":["import type { TracerProvider } from '@opentelemetry/api'\nimport type { ArchivistInstance } from '@xyo-network/archivist-model'\nimport { ArchivistSyncDiviner } from '@xyo-network/chain-modules'\nimport { DivinerConfigSchema } from '@xyo-network/diviner-model'\nimport type { ModuleIdentifier } from '@xyo-network/module-model'\nimport { MemoryNode } from '@xyo-network/node-memory'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { SentinelConfigSchema } from '@xyo-network/sentinel-model'\n\nexport const initArchivistSync = async (\n name: ModuleIdentifier,\n inArchivist: ArchivistInstance,\n outArchivist: ArchivistInstance,\n frequency = 1000,\n traceProvider?: TracerProvider,\n) => {\n const tracer = traceProvider?.getTracer(`archivist-sync-diviner [${name}]`)\n const node = await MemoryNode.create({ account: 'random' })\n const finalizedArchivistSyncDiviner = await ArchivistSyncDiviner.create({\n account: 'random',\n inArchivist,\n outArchivist,\n tracer,\n config: { schema: DivinerConfigSchema, name },\n })\n\n await node.register(finalizedArchivistSyncDiviner)\n await node.attach(finalizedArchivistSyncDiviner.address)\n\n const sentinel = await MemorySentinel.create({\n account: 'random',\n config: {\n name,\n schema: SentinelConfigSchema,\n tasks: [\n {\n required: true,\n mod: finalizedArchivistSyncDiviner.address,\n endPoint: 'divine',\n },\n ],\n automations: [\n {\n frequency,\n frequencyUnits: 'millis',\n schema: 'network.xyo.automation.interval',\n start: Date.now(),\n type: 'interval',\n },\n ],\n },\n })\n\n await node.register(sentinel)\n await node.attach(sentinel.address)\n\n return node\n}\n","import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory'\nimport { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'\nimport type { AttachableArchivistInstance } from '@xyo-network/archivist-model'\n\nimport { initArchivistSync } from './initArchivistSync.ts'\n\nexport const DefaultReadCachingArchivistConfig: MemoryArchivistConfig = {\n max: 100_000,\n // requireAllParents: true,\n schema: MemoryArchivistConfigSchema,\n}\n\nconst getDynamicDefaultReadCachingArchivistConfig = (archivist: AttachableArchivistInstance): Partial<MemoryArchivistConfig> => {\n const { id } = archivist\n const name = `${id}-CachingArchivist`\n const dynamicDefaults: Partial<MemoryArchivistConfig> = { name }\n return dynamicDefaults\n}\n\nconst getDynamicReadCachingArchivistConfig = (archivist: AttachableArchivistInstance): Partial<MemoryArchivistConfig> => {\n // const parents = {\n // read: [archivist.address], write: [], commit: [],\n // }\n // const dynamicConfig: Partial<MemoryArchivistConfig> = { parents }\n const dynamicConfig: Partial<MemoryArchivistConfig> = {}\n return dynamicConfig\n}\n\nexport const wrapWithReadCachingArchivist = async (\n archivist: AttachableArchivistInstance,\n config: Partial<MemoryArchivistConfig> = DefaultReadCachingArchivistConfig,\n): Promise<AttachableArchivistInstance> => {\n const dynamicDefaultReadCachingArchivistConfig = getDynamicDefaultReadCachingArchivistConfig(archivist)\n const dynamicReadCachingArchivistConfig = getDynamicReadCachingArchivistConfig(archivist)\n\n // Create a materialized config with precedence\n const materializedConfig: MemoryArchivistConfig = {\n // Use the static defaults\n ...DefaultReadCachingArchivistConfig,\n // Use the dynamic defaults\n ...dynamicDefaultReadCachingArchivistConfig,\n // Use the supplied config\n ...config,\n // Use they dynamic config\n ...dynamicReadCachingArchivistConfig,\n }\n const cachingArchivist = await MemoryArchivist.create({ account: 'random', config: materializedConfig })\n await initArchivistSync(\n `${cachingArchivist.id}-Sync`,\n archivist,\n cachingArchivist,\n 1000,\n )\n\n return cachingArchivist\n}\n","import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge-http'\nimport type { AttachableBridgeInstance } from '@xyo-network/bridge-model'\nimport { Mutex } from 'async-mutex'\n\nconst initMutex = new Mutex()\nconst bridgeSingletonMap = new Map<string, AttachableBridgeInstance>()\n\nexport const initBridge = async (nodeUrl: string): Promise<AttachableBridgeInstance> => {\n return await initMutex.runExclusive(async () => {\n const existing = bridgeSingletonMap.get(nodeUrl)\n if (existing) return existing\n const bridge = await HttpBridge.create({\n account: 'random',\n config: {\n name: 'HttpBridge',\n client: { url: nodeUrl, discoverRoots: 'start' },\n schema: HttpBridgeConfigSchema,\n security: { allowAnonymous: true },\n },\n })\n await bridge.start()\n bridgeSingletonMap.set(nodeUrl, bridge)\n return bridge\n })\n}\n","import { assertEx } from '@xylabs/assert'\nimport type { Address } from '@xylabs/hex'\nimport type { AttachableArchivistInstance } from '@xyo-network/archivist-model'\nimport { asAttachableArchivistInstance } from '@xyo-network/archivist-model'\nimport type { BridgeInstance } from '@xyo-network/bridge-model'\nimport type { AttachableModuleInstance, ModuleIdentifier } from '@xyo-network/module-model'\nimport { asAttachableModuleInstance } from '@xyo-network/module-model'\nimport type { Initializable } from '@xyo-network/xl1-protocol'\nimport { Mutex } from 'async-mutex'\n\nconst initMutex = new Mutex()\ntype ModuleDictionary = Record<ModuleIdentifier, AttachableModuleInstance | undefined>\ntype BridgedModuleDictionary = Record<Address, ModuleDictionary | undefined>\nconst bridgedModuleDictionary: BridgedModuleDictionary = {}\n\nexport const initBridgedModule: Initializable<\n { bridge: BridgeInstance; moduleName: ModuleIdentifier }, AttachableModuleInstance\n> = async ({ bridge, moduleName }): Promise<AttachableModuleInstance> => {\n return await initMutex.runExclusive(async () => {\n const existing = bridgedModuleDictionary?.[bridge.address]?.[moduleName]\n if (existing) return existing\n const mod = assertEx(await bridge.resolve(moduleName), () => `Error: Could not resolve ${moduleName}`)\n const moduleInstance = assertEx(asAttachableModuleInstance(mod), () => `Error: Could not convert ${moduleName} to attachable module instance`)\n // Initialize the nested dictionary if needed\n let moduleMap = bridgedModuleDictionary[bridge.address]\n if (moduleMap === undefined) {\n moduleMap = {}\n bridgedModuleDictionary[bridge.address] = moduleMap\n }\n // Store and return the module instance\n moduleMap[moduleName] = moduleInstance\n return moduleInstance\n })\n}\n\nexport const initBridgedArchivistModule: Initializable<\n { bridge: BridgeInstance; moduleName: ModuleIdentifier }, AttachableArchivistInstance\n> = async ({ bridge, moduleName }): Promise<AttachableArchivistInstance> => {\n return assertEx(\n asAttachableArchivistInstance(await initBridgedModule({ bridge, moduleName })),\n () => `Error: Could not convert ${moduleName} to attachable archivist instance`,\n )\n}\n"],"mappings":";;;;AAEA,SAASA,4BAA4B;AACrC,SAASC,2BAA2B;AAEpC,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,4B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,OAAOO,QAAQN,UAAAA,GAAa,MAAM,4BAA4BA,UAAAA,EAAY;AACrG,UAAMO,iBAAiBF,SAASG,2BAA2BJ,GAAAA,GAAM,MAAM,4BAA4BJ,UAAAA,gCAA0C;AAE7I,QAAIS,YAAYZ,wBAAwBE,OAAOI,OAAO;AACtD,QAAIM,cAAcC,QAAW;AAC3BD,kBAAY,CAAC;AACbZ,8BAAwBE,OAAOI,OAAO,IAAIM;IAC5C;AAEAA,cAAUT,UAAAA,IAAcO;AACxB,WAAOA;EACT,CAAA;AACF,GAhBI;AAkBG,IAAMI,6BAET,8BAAO,EAAEZ,QAAQC,WAAU,MAAE;AAC/B,SAAOK,SACLO,8BAA8B,MAAMd,kBAAkB;IAAEC;IAAQC;EAAW,CAAA,CAAA,GAC3E,MAAM,4BAA4BA,UAAAA,mCAA6C;AAEnF,GALI;","names":["ArchivistSyncDiviner","DivinerConfigSchema","MemoryNode","MemorySentinel","SentinelConfigSchema","initArchivistSync","name","inArchivist","outArchivist","frequency","traceProvider","tracer","getTracer","node","MemoryNode","create","account","finalizedArchivistSyncDiviner","ArchivistSyncDiviner","config","schema","DivinerConfigSchema","register","attach","address","sentinel","MemorySentinel","SentinelConfigSchema","tasks","required","mod","endPoint","automations","frequencyUnits","start","Date","now","type","MemoryArchivist","MemoryArchivistConfigSchema","DefaultReadCachingArchivistConfig","max","schema","MemoryArchivistConfigSchema","getDynamicDefaultReadCachingArchivistConfig","archivist","id","name","dynamicDefaults","getDynamicReadCachingArchivistConfig","dynamicConfig","wrapWithReadCachingArchivist","config","dynamicDefaultReadCachingArchivistConfig","dynamicReadCachingArchivistConfig","materializedConfig","cachingArchivist","MemoryArchivist","create","account","initArchivistSync","HttpBridge","HttpBridgeConfigSchema","Mutex","initMutex","Mutex","bridgeSingletonMap","Map","initBridge","nodeUrl","runExclusive","existing","get","bridge","HttpBridge","create","account","config","name","client","url","discoverRoots","schema","HttpBridgeConfigSchema","security","allowAnonymous","start","set","assertEx","asAttachableArchivistInstance","asAttachableModuleInstance","Mutex","initMutex","Mutex","bridgedModuleDictionary","initBridgedModule","bridge","moduleName","runExclusive","existing","address","mod","assertEx","resolve","moduleInstance","asAttachableModuleInstance","moduleMap","undefined","initBridgedArchivistModule","asAttachableArchivistInstance"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/archivist/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/archivist/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initArchivistSync.d.ts","sourceRoot":"","sources":["../../../src/archivist/initArchivistSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"initArchivistSync.d.ts","sourceRoot":"","sources":["../../../src/archivist/initArchivistSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAGrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAIrD,eAAO,MAAM,iBAAiB,GAC5B,MAAM,gBAAgB,EACtB,aAAa,iBAAiB,EAC9B,cAAc,iBAAiB,EAC/B,kBAAgB,EAChB,gBAAgB,cAAc;;;;;;;;;;0DA2C/B,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory';
|
|
2
|
+
import type { AttachableArchivistInstance } from '@xyo-network/archivist-model';
|
|
3
|
+
export declare const DefaultReadCachingArchivistConfig: MemoryArchivistConfig;
|
|
4
|
+
export declare const wrapWithReadCachingArchivist: (archivist: AttachableArchivistInstance, config?: Partial<MemoryArchivistConfig>) => Promise<AttachableArchivistInstance>;
|
|
5
|
+
//# sourceMappingURL=wrapWithReadCachingArchivist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapWithReadCachingArchivist.d.ts","sourceRoot":"","sources":["../../../src/archivist/wrapWithReadCachingArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAI/E,eAAO,MAAM,iCAAiC,EAAE,qBAI/C,CAAA;AAkBD,eAAO,MAAM,4BAA4B,GACvC,WAAW,2BAA2B,EACtC,SAAQ,OAAO,CAAC,qBAAqB,CAAqC,KACzE,OAAO,CAAC,2BAA2B,CAwBrC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/chain-orchestration",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.18",
|
|
5
5
|
"description": "XYO Layer One SDK Orchestration",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -35,26 +35,27 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@opentelemetry/api": "^1.9.0",
|
|
38
|
-
"@xylabs/assert": "^4.9.
|
|
39
|
-
"@xyo-network/archivist-
|
|
40
|
-
"@xyo-network/
|
|
41
|
-
"@xyo-network/bridge-
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/chain-
|
|
44
|
-
"@xyo-network/
|
|
45
|
-
"@xyo-network/
|
|
46
|
-
"@xyo-network/
|
|
47
|
-
"@xyo-network/
|
|
48
|
-
"@xyo-network/sentinel-
|
|
38
|
+
"@xylabs/assert": "^4.9.4",
|
|
39
|
+
"@xyo-network/archivist-memory": "^3.14.18",
|
|
40
|
+
"@xyo-network/archivist-model": "^3.14.18",
|
|
41
|
+
"@xyo-network/bridge-http": "^3.14.18",
|
|
42
|
+
"@xyo-network/bridge-model": "^3.14.18",
|
|
43
|
+
"@xyo-network/chain-modules": "^1.3.18",
|
|
44
|
+
"@xyo-network/chain-utils": "^1.3.18",
|
|
45
|
+
"@xyo-network/diviner-model": "^3.14.18",
|
|
46
|
+
"@xyo-network/module-model": "^3.14.18",
|
|
47
|
+
"@xyo-network/node-memory": "^3.14.18",
|
|
48
|
+
"@xyo-network/sentinel-memory": "^3.14.18",
|
|
49
|
+
"@xyo-network/sentinel-model": "^3.14.18",
|
|
49
50
|
"@xyo-network/xl1-protocol": "^1.3.12",
|
|
50
51
|
"async-mutex": "^0.5.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^22.15.
|
|
54
|
-
"@xylabs/hex": "^4.9.
|
|
54
|
+
"@types/node": "^22.15.17",
|
|
55
|
+
"@xylabs/hex": "^4.9.4",
|
|
55
56
|
"@xylabs/ts-scripts-yarn3": "^6.5.5",
|
|
56
57
|
"@xylabs/tsconfig": "^6.5.5",
|
|
57
|
-
"knip": "^5.
|
|
58
|
+
"knip": "^5.55.1",
|
|
58
59
|
"typescript": "^5.8.3"
|
|
59
60
|
},
|
|
60
61
|
"engines": {
|
package/src/archivist/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './initArchivistSync.ts'
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './wrapWithReadCachingArchivist.ts'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { TracerProvider } from '@opentelemetry/api'
|
|
2
2
|
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
3
|
import { ArchivistSyncDiviner } from '@xyo-network/chain-modules'
|
|
4
|
-
import { spanAsync } from '@xyo-network/chain-utils'
|
|
5
4
|
import { DivinerConfigSchema } from '@xyo-network/diviner-model'
|
|
6
5
|
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
7
6
|
import { MemoryNode } from '@xyo-network/node-memory'
|
|
@@ -16,46 +15,44 @@ export const initArchivistSync = async (
|
|
|
16
15
|
traceProvider?: TracerProvider,
|
|
17
16
|
) => {
|
|
18
17
|
const tracer = traceProvider?.getTracer(`archivist-sync-diviner [${name}]`)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
18
|
+
const node = await MemoryNode.create({ account: 'random' })
|
|
19
|
+
const finalizedArchivistSyncDiviner = await ArchivistSyncDiviner.create({
|
|
20
|
+
account: 'random',
|
|
21
|
+
inArchivist,
|
|
22
|
+
outArchivist,
|
|
23
|
+
tracer,
|
|
24
|
+
config: { schema: DivinerConfigSchema, name },
|
|
25
|
+
})
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
await node.register(finalizedArchivistSyncDiviner)
|
|
28
|
+
await node.attach(finalizedArchivistSyncDiviner.address)
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
30
|
+
const sentinel = await MemorySentinel.create({
|
|
31
|
+
account: 'random',
|
|
32
|
+
config: {
|
|
33
|
+
name,
|
|
34
|
+
schema: SentinelConfigSchema,
|
|
35
|
+
tasks: [
|
|
36
|
+
{
|
|
37
|
+
required: true,
|
|
38
|
+
mod: finalizedArchivistSyncDiviner.address,
|
|
39
|
+
endPoint: 'divine',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
automations: [
|
|
43
|
+
{
|
|
44
|
+
frequency,
|
|
45
|
+
frequencyUnits: 'millis',
|
|
46
|
+
schema: 'network.xyo.automation.interval',
|
|
47
|
+
start: Date.now(),
|
|
48
|
+
type: 'interval',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
})
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
await node.register(sentinel)
|
|
55
|
+
await node.attach(sentinel.address)
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
}, tracer)
|
|
57
|
+
return node
|
|
61
58
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory'
|
|
2
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
3
|
+
import type { AttachableArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
+
|
|
5
|
+
import { initArchivistSync } from './initArchivistSync.ts'
|
|
6
|
+
|
|
7
|
+
export const DefaultReadCachingArchivistConfig: MemoryArchivistConfig = {
|
|
8
|
+
max: 100_000,
|
|
9
|
+
// requireAllParents: true,
|
|
10
|
+
schema: MemoryArchivistConfigSchema,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getDynamicDefaultReadCachingArchivistConfig = (archivist: AttachableArchivistInstance): Partial<MemoryArchivistConfig> => {
|
|
14
|
+
const { id } = archivist
|
|
15
|
+
const name = `${id}-CachingArchivist`
|
|
16
|
+
const dynamicDefaults: Partial<MemoryArchivistConfig> = { name }
|
|
17
|
+
return dynamicDefaults
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getDynamicReadCachingArchivistConfig = (archivist: AttachableArchivistInstance): Partial<MemoryArchivistConfig> => {
|
|
21
|
+
// const parents = {
|
|
22
|
+
// read: [archivist.address], write: [], commit: [],
|
|
23
|
+
// }
|
|
24
|
+
// const dynamicConfig: Partial<MemoryArchivistConfig> = { parents }
|
|
25
|
+
const dynamicConfig: Partial<MemoryArchivistConfig> = {}
|
|
26
|
+
return dynamicConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const wrapWithReadCachingArchivist = async (
|
|
30
|
+
archivist: AttachableArchivistInstance,
|
|
31
|
+
config: Partial<MemoryArchivistConfig> = DefaultReadCachingArchivistConfig,
|
|
32
|
+
): Promise<AttachableArchivistInstance> => {
|
|
33
|
+
const dynamicDefaultReadCachingArchivistConfig = getDynamicDefaultReadCachingArchivistConfig(archivist)
|
|
34
|
+
const dynamicReadCachingArchivistConfig = getDynamicReadCachingArchivistConfig(archivist)
|
|
35
|
+
|
|
36
|
+
// Create a materialized config with precedence
|
|
37
|
+
const materializedConfig: MemoryArchivistConfig = {
|
|
38
|
+
// Use the static defaults
|
|
39
|
+
...DefaultReadCachingArchivistConfig,
|
|
40
|
+
// Use the dynamic defaults
|
|
41
|
+
...dynamicDefaultReadCachingArchivistConfig,
|
|
42
|
+
// Use the supplied config
|
|
43
|
+
...config,
|
|
44
|
+
// Use they dynamic config
|
|
45
|
+
...dynamicReadCachingArchivistConfig,
|
|
46
|
+
}
|
|
47
|
+
const cachingArchivist = await MemoryArchivist.create({ account: 'random', config: materializedConfig })
|
|
48
|
+
await initArchivistSync(
|
|
49
|
+
`${cachingArchivist.id}-Sync`,
|
|
50
|
+
archivist,
|
|
51
|
+
cachingArchivist,
|
|
52
|
+
1000,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
return cachingArchivist
|
|
56
|
+
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory';
|
|
2
|
-
import type { AttachableArchivistInstance } from '@xyo-network/archivist-model';
|
|
3
|
-
export declare const DefaultCachingArchivistConfig: MemoryArchivistConfig;
|
|
4
|
-
export declare const wrapWithCachingArchivist: (archivist: AttachableArchivistInstance, config?: Partial<MemoryArchivistConfig>) => Promise<AttachableArchivistInstance>;
|
|
5
|
-
//# sourceMappingURL=wrapWithCachingArchivist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapWithCachingArchivist.d.ts","sourceRoot":"","sources":["../../../src/archivist/wrapWithCachingArchivist.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAE1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAG/E,eAAO,MAAM,6BAA6B,EAAE,qBAI3C,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,WAAW,2BAA2B,EACtC,SAAQ,OAAO,CAAC,qBAAqB,CAAiC,KACrE,OAAO,CAAC,2BAA2B,CAerC,CAAA"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { MemoryArchivistConfig } from '@xyo-network/archivist-memory'
|
|
2
|
-
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
3
|
-
import type { AttachableArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import { MemoryNode } from '@xyo-network/node-memory'
|
|
5
|
-
|
|
6
|
-
export const DefaultCachingArchivistConfig: MemoryArchivistConfig = {
|
|
7
|
-
max: 10_000,
|
|
8
|
-
requireAllParents: true,
|
|
9
|
-
schema: MemoryArchivistConfigSchema,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const wrapWithCachingArchivist = async (
|
|
13
|
-
archivist: AttachableArchivistInstance,
|
|
14
|
-
config: Partial<MemoryArchivistConfig> = DefaultCachingArchivistConfig,
|
|
15
|
-
): Promise<AttachableArchivistInstance> => {
|
|
16
|
-
const { id } = archivist
|
|
17
|
-
const name = `${id}-CachingArchivist`
|
|
18
|
-
const materializedConfig: MemoryArchivistConfig = {
|
|
19
|
-
...DefaultCachingArchivistConfig, name, ...config,
|
|
20
|
-
}
|
|
21
|
-
const node = await MemoryNode.create({ account: 'random' })
|
|
22
|
-
const cachingArchivist = await MemoryArchivist.create({ account: 'random', config: materializedConfig })
|
|
23
|
-
|
|
24
|
-
for (const mod of [archivist, cachingArchivist]) {
|
|
25
|
-
await node.register(mod)
|
|
26
|
-
await node.attach(mod.address)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return cachingArchivist
|
|
30
|
-
}
|