@xyo-network/chain-orchestration 1.3.15 → 1.3.17
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 +42 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/archivist/index.d.ts +1 -0
- package/dist/types/archivist/index.d.ts.map +1 -1
- package/dist/types/archivist/wrapWithCachingArchivist.d.ts +5 -0
- package/dist/types/archivist/wrapWithCachingArchivist.d.ts.map +1 -0
- package/dist/types/initBridgedModule.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/archivist/index.ts +1 -0
- package/src/archivist/wrapWithCachingArchivist.ts +30 -0
- package/src/initBridgedModule.ts +11 -3
package/dist/neutral/index.mjs
CHANGED
|
@@ -55,6 +55,39 @@ var initArchivistSync = /* @__PURE__ */ __name(async (name, inArchivist, outArch
|
|
|
55
55
|
}, tracer);
|
|
56
56
|
}, "initArchivistSync");
|
|
57
57
|
|
|
58
|
+
// src/archivist/wrapWithCachingArchivist.ts
|
|
59
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from "@xyo-network/archivist-memory";
|
|
60
|
+
import { MemoryNode as MemoryNode2 } from "@xyo-network/node-memory";
|
|
61
|
+
var DefaultCachingArchivistConfig = {
|
|
62
|
+
max: 1e4,
|
|
63
|
+
requireAllParents: true,
|
|
64
|
+
schema: MemoryArchivistConfigSchema
|
|
65
|
+
};
|
|
66
|
+
var wrapWithCachingArchivist = /* @__PURE__ */ __name(async (archivist, config = DefaultCachingArchivistConfig) => {
|
|
67
|
+
const { id } = archivist;
|
|
68
|
+
const name = `${id}-CachingArchivist`;
|
|
69
|
+
const materializedConfig = {
|
|
70
|
+
...DefaultCachingArchivistConfig,
|
|
71
|
+
name,
|
|
72
|
+
...config
|
|
73
|
+
};
|
|
74
|
+
const node = await MemoryNode2.create({
|
|
75
|
+
account: "random"
|
|
76
|
+
});
|
|
77
|
+
const cachingArchivist = await MemoryArchivist.create({
|
|
78
|
+
account: "random",
|
|
79
|
+
config: materializedConfig
|
|
80
|
+
});
|
|
81
|
+
for (const mod of [
|
|
82
|
+
archivist,
|
|
83
|
+
cachingArchivist
|
|
84
|
+
]) {
|
|
85
|
+
await node.register(mod);
|
|
86
|
+
await node.attach(mod.address);
|
|
87
|
+
}
|
|
88
|
+
return cachingArchivist;
|
|
89
|
+
}, "wrapWithCachingArchivist");
|
|
90
|
+
|
|
58
91
|
// src/bridge.ts
|
|
59
92
|
import { HttpBridge, HttpBridgeConfigSchema } from "@xyo-network/bridge-http";
|
|
60
93
|
import { Mutex } from "async-mutex";
|
|
@@ -97,8 +130,12 @@ var initBridgedModule = /* @__PURE__ */ __name(async ({ bridge, moduleName }) =>
|
|
|
97
130
|
if (existing) return existing;
|
|
98
131
|
const mod = assertEx(await bridge.resolve(moduleName), () => `Error: Could not resolve ${moduleName}`);
|
|
99
132
|
const moduleInstance = assertEx(asAttachableModuleInstance(mod), () => `Error: Could not convert ${moduleName} to attachable module instance`);
|
|
100
|
-
|
|
101
|
-
|
|
133
|
+
let moduleMap = bridgedModuleDictionary[bridge.address];
|
|
134
|
+
if (moduleMap === void 0) {
|
|
135
|
+
moduleMap = {};
|
|
136
|
+
bridgedModuleDictionary[bridge.address] = moduleMap;
|
|
137
|
+
}
|
|
138
|
+
moduleMap[moduleName] = moduleInstance;
|
|
102
139
|
return moduleInstance;
|
|
103
140
|
});
|
|
104
141
|
}, "initBridgedModule");
|
|
@@ -109,9 +146,11 @@ var initBridgedArchivistModule = /* @__PURE__ */ __name(async ({ bridge, moduleN
|
|
|
109
146
|
})), () => `Error: Could not convert ${moduleName} to attachable archivist instance`);
|
|
110
147
|
}, "initBridgedArchivistModule");
|
|
111
148
|
export {
|
|
149
|
+
DefaultCachingArchivistConfig,
|
|
112
150
|
initArchivistSync,
|
|
113
151
|
initBridge,
|
|
114
152
|
initBridgedArchivistModule,
|
|
115
|
-
initBridgedModule
|
|
153
|
+
initBridgedModule,
|
|
154
|
+
wrapWithCachingArchivist
|
|
116
155
|
};
|
|
117
156
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/archivist/initArchivistSync.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 { 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()\nconst bridgedModuleDictionary: Record<Address, Record<ModuleIdentifier, AttachableModuleInstance>> = {}\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 bridgedModuleDictionary[bridge.address] = bridgedModuleDictionary[bridge.address] || {}\n bridgedModuleDictionary[bridge.address][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;MACAG;MACAS,QAAQ;QAAEC,QAAQC;QAAqBhB;MAAK;IAC9C,CAAA;AAEA,UAAMQ,KAAKS,SAASL,6BAAAA;AACpB,UAAMJ,KAAKU,OAAON,8BAA8BO,OAAO;AAEvD,UAAMC,WAAW,MAAMC,eAAeX,OAAO;MAC3CC,SAAS;MACTG,QAAQ;QACNd;QACAe,QAAQO;QACRC,OAAO;UACL;YACEC,UAAU;YACVC,KAAKb,8BAA8BO;YACnCO,UAAU;UACZ;;QAEFC,aAAa;UACX;YACExB;YACAyB,gBAAgB;YAChBb,QAAQ;YACRc,OAAOC,KAAKC,IAAG;YACfC,MAAM;UACR;;MAEJ;IACF,CAAA;AAEA,UAAMxB,KAAKS,SAASG,QAAAA;AACpB,UAAMZ,KAAKU,OAAOE,SAASD,OAAO;AAElC,WAAOX;EACT,GAAGH,MAAAA;AACL,GAlDiC;;;ACVjC,SAAS4B,YAAYC,8BAA8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V,QAAQC,WAAU,MAAE;AAC/B,SAAOK,SACLK,8BAA8B,MAAMZ,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","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","initBridgedArchivistModule","asAttachableArchivistInstance"]}
|
|
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;MACAG;MACAS,QAAQ;QAAEC,QAAQC;QAAqBhB;MAAK;IAC9C,CAAA;AAEA,UAAMQ,KAAKS,SAASL,6BAAAA;AACpB,UAAMJ,KAAKU,OAAON,8BAA8BO,OAAO;AAEvD,UAAMC,WAAW,MAAMC,eAAeX,OAAO;MAC3CC,SAAS;MACTG,QAAQ;QACNd;QACAe,QAAQO;QACRC,OAAO;UACL;YACEC,UAAU;YACVC,KAAKb,8BAA8BO;YACnCO,UAAU;UACZ;;QAEFC,aAAa;UACX;YACExB;YACAyB,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;QACRC,UAAU;UAAEC,gBAAgB;QAAK;MACnC;IACF,CAAA;AACA,UAAMZ,OAAOa,MAAK;AAClBpB,uBAAmBqB,IAAIlB,SAASI,MAAAA;AAChC,WAAOA;EACT,CAAA;AACF,GAjB0B;;;ACP1B,SAASe,gBAAgB;AAGzB,SAASC,qCAAqC;AAG9C,SAASC,kCAAkC;AAE3C,SAASC,SAAAA,cAAa;AAEtB,IAAMC,aAAY,IAAIC,OAAAA;AAGtB,IAAMC,0BAAmD,CAAC;AAEnD,IAAMC,oBAET,8BAAO,EAAEC,QAAQC,WAAU,MAAE;AAC/B,SAAO,MAAML,WAAUM,aAAa,YAAA;AAClC,UAAMC,WAAWL,0BAA0BE,OAAOI,OAAO,IAAIH,UAAAA;AAC7D,QAAIE,SAAU,QAAOA;AACrB,UAAME,MAAMC,SAAS,MAAMN,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","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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/archivist/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/archivist/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,+BAA+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 DefaultCachingArchivistConfig: MemoryArchivistConfig;
|
|
4
|
+
export declare const wrapWithCachingArchivist: (archivist: AttachableArchivistInstance, config?: Partial<MemoryArchivistConfig>) => Promise<AttachableArchivistInstance>;
|
|
5
|
+
//# sourceMappingURL=wrapWithCachingArchivist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initBridgedModule.d.ts","sourceRoot":"","sources":["../../src/initBridgedModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"initBridgedModule.d.ts","sourceRoot":"","sources":["../../src/initBridgedModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAE/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAQ9D,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAC3C;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,EAAE,wBAAwB,CAiBnF,CAAA;AAED,eAAO,MAAM,0BAA0B,EAAE,aAAa,CACpD;IAAE,MAAM,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,EAAE,2BAA2B,CAMtF,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.17",
|
|
5
5
|
"description": "XYO Layer One SDK Orchestration",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -35,26 +35,26 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@opentelemetry/api": "^1.9.0",
|
|
38
|
-
"@xylabs/assert": "^4.
|
|
39
|
-
"@xyo-network/archivist-model": "^3.14.
|
|
40
|
-
"@xyo-network/bridge-http": "3.14.
|
|
41
|
-
"@xyo-network/bridge-model": "^3.14.
|
|
42
|
-
"@xyo-network/chain-modules": "^1.3.
|
|
43
|
-
"@xyo-network/chain-utils": "^1.3.
|
|
44
|
-
"@xyo-network/diviner-model": "^3.14.
|
|
45
|
-
"@xyo-network/module-model": "^3.14.
|
|
46
|
-
"@xyo-network/node-memory": "^3.14.
|
|
47
|
-
"@xyo-network/sentinel-memory": "^3.14.
|
|
48
|
-
"@xyo-network/sentinel-model": "^3.14.
|
|
49
|
-
"@xyo-network/xl1-protocol": "^1.3.
|
|
38
|
+
"@xylabs/assert": "^4.9.3",
|
|
39
|
+
"@xyo-network/archivist-model": "^3.14.17",
|
|
40
|
+
"@xyo-network/bridge-http": "3.14.17",
|
|
41
|
+
"@xyo-network/bridge-model": "^3.14.17",
|
|
42
|
+
"@xyo-network/chain-modules": "^1.3.17",
|
|
43
|
+
"@xyo-network/chain-utils": "^1.3.17",
|
|
44
|
+
"@xyo-network/diviner-model": "^3.14.17",
|
|
45
|
+
"@xyo-network/module-model": "^3.14.17",
|
|
46
|
+
"@xyo-network/node-memory": "^3.14.17",
|
|
47
|
+
"@xyo-network/sentinel-memory": "^3.14.17",
|
|
48
|
+
"@xyo-network/sentinel-model": "^3.14.17",
|
|
49
|
+
"@xyo-network/xl1-protocol": "^1.3.12",
|
|
50
50
|
"async-mutex": "^0.5.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^22.15.
|
|
54
|
-
"@xylabs/hex": "^4.
|
|
53
|
+
"@types/node": "^22.15.14",
|
|
54
|
+
"@xylabs/hex": "^4.9.3",
|
|
55
55
|
"@xylabs/ts-scripts-yarn3": "^6.5.5",
|
|
56
56
|
"@xylabs/tsconfig": "^6.5.5",
|
|
57
|
-
"knip": "^5.
|
|
57
|
+
"knip": "^5.54.1",
|
|
58
58
|
"typescript": "^5.8.3"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
package/src/archivist/index.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
package/src/initBridgedModule.ts
CHANGED
|
@@ -9,7 +9,9 @@ import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
|
9
9
|
import { Mutex } from 'async-mutex'
|
|
10
10
|
|
|
11
11
|
const initMutex = new Mutex()
|
|
12
|
-
|
|
12
|
+
type ModuleDictionary = Record<ModuleIdentifier, AttachableModuleInstance | undefined>
|
|
13
|
+
type BridgedModuleDictionary = Record<Address, ModuleDictionary | undefined>
|
|
14
|
+
const bridgedModuleDictionary: BridgedModuleDictionary = {}
|
|
13
15
|
|
|
14
16
|
export const initBridgedModule: Initializable<
|
|
15
17
|
{ bridge: BridgeInstance; moduleName: ModuleIdentifier }, AttachableModuleInstance
|
|
@@ -19,8 +21,14 @@ export const initBridgedModule: Initializable<
|
|
|
19
21
|
if (existing) return existing
|
|
20
22
|
const mod = assertEx(await bridge.resolve(moduleName), () => `Error: Could not resolve ${moduleName}`)
|
|
21
23
|
const moduleInstance = assertEx(asAttachableModuleInstance(mod), () => `Error: Could not convert ${moduleName} to attachable module instance`)
|
|
22
|
-
|
|
23
|
-
bridgedModuleDictionary[bridge.address]
|
|
24
|
+
// Initialize the nested dictionary if needed
|
|
25
|
+
let moduleMap = bridgedModuleDictionary[bridge.address]
|
|
26
|
+
if (moduleMap === undefined) {
|
|
27
|
+
moduleMap = {}
|
|
28
|
+
bridgedModuleDictionary[bridge.address] = moduleMap
|
|
29
|
+
}
|
|
30
|
+
// Store and return the module instance
|
|
31
|
+
moduleMap[moduleName] = moduleInstance
|
|
24
32
|
return moduleInstance
|
|
25
33
|
})
|
|
26
34
|
}
|