@xyo-network/diviner-stateful 2.106.0-rc.5 → 2.107.0

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 (85) hide show
  1. package/dist/browser/Config.d.cts +0 -9
  2. package/dist/browser/Config.d.cts.map +1 -1
  3. package/dist/browser/Config.d.mts +0 -9
  4. package/dist/browser/Config.d.mts.map +1 -1
  5. package/dist/browser/Config.d.ts +0 -9
  6. package/dist/browser/Config.d.ts.map +1 -1
  7. package/dist/browser/Diviner.d.cts +21 -53
  8. package/dist/browser/Diviner.d.cts.map +1 -1
  9. package/dist/browser/Diviner.d.mts +21 -53
  10. package/dist/browser/Diviner.d.mts.map +1 -1
  11. package/dist/browser/Diviner.d.ts +21 -53
  12. package/dist/browser/Diviner.d.ts.map +1 -1
  13. package/dist/browser/DivinerMixin.d.cts +195 -370
  14. package/dist/browser/DivinerMixin.d.cts.map +1 -1
  15. package/dist/browser/DivinerMixin.d.mts +195 -370
  16. package/dist/browser/DivinerMixin.d.mts.map +1 -1
  17. package/dist/browser/DivinerMixin.d.ts +195 -370
  18. package/dist/browser/DivinerMixin.d.ts.map +1 -1
  19. package/dist/browser/Params.d.cts +0 -3
  20. package/dist/browser/Params.d.cts.map +1 -1
  21. package/dist/browser/Params.d.mts +0 -3
  22. package/dist/browser/Params.d.mts.map +1 -1
  23. package/dist/browser/Params.d.ts +0 -3
  24. package/dist/browser/Params.d.ts.map +1 -1
  25. package/dist/browser/index.cjs +1 -262
  26. package/dist/browser/index.cjs.map +1 -1
  27. package/dist/browser/index.js +1 -241
  28. package/dist/browser/index.js.map +1 -1
  29. package/dist/neutral/Config.d.cts +0 -9
  30. package/dist/neutral/Config.d.cts.map +1 -1
  31. package/dist/neutral/Config.d.mts +0 -9
  32. package/dist/neutral/Config.d.mts.map +1 -1
  33. package/dist/neutral/Config.d.ts +0 -9
  34. package/dist/neutral/Config.d.ts.map +1 -1
  35. package/dist/neutral/Diviner.d.cts +21 -53
  36. package/dist/neutral/Diviner.d.cts.map +1 -1
  37. package/dist/neutral/Diviner.d.mts +21 -53
  38. package/dist/neutral/Diviner.d.mts.map +1 -1
  39. package/dist/neutral/Diviner.d.ts +21 -53
  40. package/dist/neutral/Diviner.d.ts.map +1 -1
  41. package/dist/neutral/DivinerMixin.d.cts +195 -370
  42. package/dist/neutral/DivinerMixin.d.cts.map +1 -1
  43. package/dist/neutral/DivinerMixin.d.mts +195 -370
  44. package/dist/neutral/DivinerMixin.d.mts.map +1 -1
  45. package/dist/neutral/DivinerMixin.d.ts +195 -370
  46. package/dist/neutral/DivinerMixin.d.ts.map +1 -1
  47. package/dist/neutral/Params.d.cts +0 -3
  48. package/dist/neutral/Params.d.cts.map +1 -1
  49. package/dist/neutral/Params.d.mts +0 -3
  50. package/dist/neutral/Params.d.mts.map +1 -1
  51. package/dist/neutral/Params.d.ts +0 -3
  52. package/dist/neutral/Params.d.ts.map +1 -1
  53. package/dist/neutral/index.cjs +1 -262
  54. package/dist/neutral/index.cjs.map +1 -1
  55. package/dist/neutral/index.js +1 -241
  56. package/dist/neutral/index.js.map +1 -1
  57. package/dist/node/Config.d.cts +0 -9
  58. package/dist/node/Config.d.cts.map +1 -1
  59. package/dist/node/Config.d.mts +0 -9
  60. package/dist/node/Config.d.mts.map +1 -1
  61. package/dist/node/Config.d.ts +0 -9
  62. package/dist/node/Config.d.ts.map +1 -1
  63. package/dist/node/Diviner.d.cts +21 -53
  64. package/dist/node/Diviner.d.cts.map +1 -1
  65. package/dist/node/Diviner.d.mts +21 -53
  66. package/dist/node/Diviner.d.mts.map +1 -1
  67. package/dist/node/Diviner.d.ts +21 -53
  68. package/dist/node/Diviner.d.ts.map +1 -1
  69. package/dist/node/DivinerMixin.d.cts +195 -370
  70. package/dist/node/DivinerMixin.d.cts.map +1 -1
  71. package/dist/node/DivinerMixin.d.mts +195 -370
  72. package/dist/node/DivinerMixin.d.mts.map +1 -1
  73. package/dist/node/DivinerMixin.d.ts +195 -370
  74. package/dist/node/DivinerMixin.d.ts.map +1 -1
  75. package/dist/node/Params.d.cts +0 -3
  76. package/dist/node/Params.d.cts.map +1 -1
  77. package/dist/node/Params.d.mts +0 -3
  78. package/dist/node/Params.d.mts.map +1 -1
  79. package/dist/node/Params.d.ts +0 -3
  80. package/dist/node/Params.d.ts.map +1 -1
  81. package/dist/node/index.cjs +1 -285
  82. package/dist/node/index.cjs.map +1 -1
  83. package/dist/node/index.js +1 -257
  84. package/dist/node/index.js.map +1 -1
  85. package/package.json +23 -24
@@ -1,242 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/Schema.ts
5
- var StatefulDivinerSchema = "network.xyo.diviner.stateful";
6
-
7
- // src/Config.ts
8
- var StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config`;
9
-
10
- // src/Diviner.ts
11
- import { assertEx } from "@xylabs/assert";
12
- import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
13
- import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
14
- import { isBoundWitness } from "@xyo-network/boundwitness-model";
15
- import { AbstractDiviner } from "@xyo-network/diviner-abstract";
16
- import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
17
- import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
18
- import { isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
19
- import { PayloadBuilder } from "@xyo-network/payload-builder";
20
- var moduleName = "StatefulDiviner";
21
- var StatefulDiviner = class extends AbstractDiviner {
22
- static {
23
- __name(this, "StatefulDiviner");
24
- }
25
- static configSchemas = [
26
- ...super.configSchemas,
27
- StatefulDivinerConfigSchema
28
- ];
29
- static defaultConfigSchema = StatefulDivinerConfigSchema;
30
- /**
31
- * The last state
32
- */
33
- _lastState;
34
- /**
35
- * Commit the internal state of the Diviner process. This is similar
36
- * to a transaction completion in a database and should only be called
37
- * when results have been successfully persisted to the appropriate
38
- * external stores.
39
- * @param nextState The state to commit
40
- */
41
- async commitState(nextState) {
42
- if (nextState.state.offset === this._lastState?.state.offset) return;
43
- this._lastState = nextState;
44
- const archivist = await this.getArchivistForStateStore();
45
- const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build();
46
- await archivist.insert([
47
- bw,
48
- nextState
49
- ]);
50
- }
51
- /**
52
- * Retrieves the archivist for the specified store
53
- * @param store The store to retrieve the archivist for
54
- * @returns The archivist for the specified store
55
- */
56
- async getArchivistForStateStore() {
57
- const name = assertEx(this.config?.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`);
58
- const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`);
59
- return ArchivistWrapper.wrap(mod, this.account);
60
- }
61
- /**
62
- * Retrieves the BoundWitness Diviner for the specified store
63
- * @param store The store to retrieve the BoundWitness Diviner for
64
- * @returns The BoundWitness Diviner for the specified store
65
- */
66
- async getBoundWitnessDivinerForStateStore() {
67
- const name = assertEx(this.config?.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`);
68
- const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`);
69
- return DivinerWrapper.wrap(mod, this.account);
70
- }
71
- /**
72
- * Retrieves the Payload Diviner for the specified store
73
- * @param store The store to retrieve the Payload Diviner for
74
- * @returns The Payload Diviner for the specified store
75
- */
76
- async getPayloadDivinerForStateStore() {
77
- const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`);
78
- const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`);
79
- return DivinerWrapper.wrap(mod, this.account);
80
- }
81
- /**
82
- * Retrieves the last state of the Diviner process. Used to recover state after
83
- * preemptions, reboots, etc.
84
- */
85
- async retrieveState() {
86
- if (this._lastState) return this._lastState;
87
- let hash = "";
88
- const diviner = await this.getBoundWitnessDivinerForStateStore();
89
- const query = await new PayloadBuilder({
90
- schema: BoundWitnessDivinerQuerySchema
91
- }).fields({
92
- address: this.account.address,
93
- limit: 1,
94
- offset: 0,
95
- order: "desc",
96
- payload_schemas: [
97
- ModuleStateSchema
98
- ]
99
- }).build();
100
- const boundWitnesses = await diviner.divine([
101
- query
102
- ]);
103
- if (boundWitnesses.length > 0) {
104
- const boundWitness = boundWitnesses[0];
105
- if (isBoundWitness(boundWitness)) {
106
- hash = boundWitness.addresses.map((address, index) => ({
107
- address,
108
- index
109
- })).filter(({ address }) => address === this.account.address).reduce((prev, curr) => boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev, "");
110
- }
111
- }
112
- if (hash) {
113
- const archivist = await this.getArchivistForStateStore();
114
- const payload = (await archivist.get([
115
- hash
116
- ])).find(isModuleState);
117
- if (payload) {
118
- return payload;
119
- }
120
- }
121
- return void 0;
122
- }
123
- };
124
-
125
- // src/DivinerMixin.ts
126
- import { assertEx as assertEx2 } from "@xylabs/assert";
127
- import { asArchivistInstance } from "@xyo-network/archivist-model";
128
- import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
129
- import { isBoundWitness as isBoundWitness2 } from "@xyo-network/boundwitness-model";
130
- import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
131
- import { asDivinerInstance } from "@xyo-network/diviner-model";
132
- import { isModuleState as isModuleState2, ModuleStateSchema as ModuleStateSchema2 } from "@xyo-network/module-model";
133
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
134
- var moduleName2 = "StatefulModuleMixin";
135
- var StatefulModuleMixin = /* @__PURE__ */ __name((ModuleBase) => {
136
- let StatefulModuleBase = class StatefulModuleBase extends ModuleBase {
137
- static {
138
- __name(this, "StatefulModuleBase");
139
- }
140
- _lastState;
141
- /**
142
- * Commit the internal state of the Diviner process. This is similar
143
- * to a transaction completion in a database and should only be called
144
- * when results have been successfully persisted to the appropriate
145
- * external stores.
146
- * @param nextState The state to commit
147
- */
148
- async commitState(nextState) {
149
- if (nextState.state.offset === this._lastState?.state.offset) return;
150
- this._lastState = nextState;
151
- const archivist = await this.getArchivistForStore();
152
- const [bw] = await (await new BoundWitnessBuilder2().payload(nextState)).build();
153
- await archivist.insert([
154
- bw,
155
- nextState
156
- ]);
157
- }
158
- /**
159
- * Retrieves the archivist for the specified store
160
- * @param store The store to retrieve the archivist for
161
- * @returns The archivist for the specified store
162
- */
163
- async getArchivistForStore() {
164
- const name = assertEx2(this.config?.stateStore?.archivist, () => `${moduleName2}: Config for stateStore.archivist not specified`);
165
- const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.archivist`);
166
- const instance = asArchivistInstance(mod);
167
- return assertEx2(instance, () => `${moduleName2}: Failed to wrap archivist instance`);
168
- }
169
- /**
170
- * Retrieves the BoundWitness Diviner for the specified store
171
- * @param store The store to retrieve the BoundWitness Diviner for
172
- * @returns The BoundWitness Diviner for the specified store
173
- */
174
- async getBoundWitnessDivinerForStore() {
175
- const name = assertEx2(this.config?.stateStore?.boundWitnessDiviner, () => `${moduleName2}: Config for stateStore.boundWitnessDiviner not specified`);
176
- const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.boundWitnessDiviner`);
177
- const instance = asDivinerInstance(mod);
178
- return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
179
- }
180
- /**
181
- * Retrieves the Payload Diviner for the specified store
182
- * @param store The store to retrieve the Payload Diviner for
183
- * @returns The Payload Diviner for the specified store
184
- */
185
- async getPayloadDivinerForStateStore() {
186
- const name = assertEx2(this.config?.stateStore?.payloadDiviner, () => `${moduleName2}: Config for stateStore.payloadDiviner not specified`);
187
- const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.payloadDiviner`);
188
- const instance = asDivinerInstance(mod);
189
- return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
190
- }
191
- /**
192
- * Retrieves the last state of the Diviner process. Used to recover state after
193
- * preemptions, reboots, etc.
194
- */
195
- async retrieveState() {
196
- if (this._lastState) return this._lastState;
197
- let hash = "";
198
- const diviner = await this.getBoundWitnessDivinerForStore();
199
- const query = await new PayloadBuilder2({
200
- schema: BoundWitnessDivinerQuerySchema2
201
- }).fields({
202
- // address: this.account.address,
203
- limit: 1,
204
- offset: 0,
205
- order: "desc",
206
- payload_schemas: [
207
- ModuleStateSchema2
208
- ]
209
- }).build();
210
- const boundWitnesses = await diviner.divine([
211
- query
212
- ]);
213
- if (boundWitnesses.length > 0) {
214
- const boundWitness = boundWitnesses[0];
215
- if (isBoundWitness2(boundWitness)) {
216
- hash = boundWitness.addresses.map((address, index) => ({
217
- address,
218
- index
219
- })).reduce((prev, curr) => boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema2 ? boundWitness.payload_hashes[curr?.index] : prev, "");
220
- }
221
- }
222
- if (hash) {
223
- const archivist = await this.getArchivistForStore();
224
- const payload = (await archivist.get([
225
- hash
226
- ])).find(isModuleState2);
227
- if (payload) {
228
- return payload;
229
- }
230
- }
231
- return void 0;
232
- }
233
- };
234
- return StatefulModuleBase;
235
- }, "StatefulModuleMixin");
236
- export {
237
- StatefulDiviner,
238
- StatefulDivinerConfigSchema,
239
- StatefulDivinerSchema,
240
- StatefulModuleMixin
241
- };
1
+ var W=Object.defineProperty;var m=(h,e)=>W(h,"name",{value:e,configurable:!0});var S="network.xyo.diviner.stateful";var v=`${S}.config`;import{assertEx as f}from"@xylabs/assert";import{ArchivistWrapper as F}from"@xyo-network/archivist-wrapper";import{BoundWitnessBuilder as b}from"@xyo-network/boundwitness-builder";import{isBoundWitness as B}from"@xyo-network/boundwitness-model";import{AbstractDiviner as _}from"@xyo-network/diviner-abstract";import{BoundWitnessDivinerQuerySchema as $}from"@xyo-network/diviner-boundwitness-model";import{DivinerWrapper as p}from"@xyo-network/diviner-wrapper";import{isModuleState as x,ModuleStateSchema as w}from"@xyo-network/module-model";import{PayloadBuilder as M}from"@xyo-network/payload-builder";var l="StatefulDiviner",g=class extends _{static{m(this,"StatefulDiviner")}static configSchemas=[...super.configSchemas,v];static defaultConfigSchema=v;_lastState;async commitState(e){if(e.state.offset===this._lastState?.state.offset)return;this._lastState=e;let a=await this.getArchivistForStateStore(),[t]=await new b().payload(e).signer(this.account).build();await a.insert([t,e])}async getArchivistForStateStore(){let e=f(this.config?.stateStore.archivist,()=>`${l}: Config for stateStore.archivist not specified`),a=f(await this.resolve(e),()=>`${l}: Failed to resolve stateStore.archivist`);return F.wrap(a,this.account)}async getBoundWitnessDivinerForStateStore(){let e=f(this.config?.stateStore.boundWitnessDiviner,()=>`${l}: Config for stateStore.boundWitnessDiviner not specified`),a=f(await this.resolve(e),()=>`${l}: Failed to resolve stateStore.boundWitnessDiviner`);return p.wrap(a,this.account)}async getPayloadDivinerForStateStore(){let e=f(this.config?.stateStore?.payloadDiviner,()=>`${l}: Config for stateStore.payloadDiviner not specified`),a=f(await this.resolve(e),()=>`${l}: Failed to resolve stateStore.payloadDiviner`);return p.wrap(a,this.account)}async retrieveState(){if(this._lastState)return this._lastState;let e="",a=await this.getBoundWitnessDivinerForStateStore(),t=await new M({schema:$}).fields({address:this.account.address,limit:1,offset:0,order:"desc",payload_schemas:[w]}).build(),s=await a.divine([t]);if(s.length>0){let i=s[0];B(i)&&(e=i.addresses.map((o,r)=>({address:o,index:r})).filter(({address:o})=>o===this.account.address).reduce((o,r)=>i.payload_schemas?.[r?.index]===w?i.payload_hashes[r?.index]:o,""))}if(e){let o=(await(await this.getArchivistForStateStore()).get([e])).find(x);if(o)return o}}};import{assertEx as n}from"@xylabs/assert";import{asArchivistInstance as A}from"@xyo-network/archivist-model";import{BoundWitnessBuilder as C}from"@xyo-network/boundwitness-builder";import{isBoundWitness as P}from"@xyo-network/boundwitness-model";import{BoundWitnessDivinerQuerySchema as q}from"@xyo-network/diviner-boundwitness-model";import{asDivinerInstance as y}from"@xyo-network/diviner-model";import{isModuleState as E,ModuleStateSchema as D}from"@xyo-network/module-model";import{PayloadBuilder as I}from"@xyo-network/payload-builder";var c="StatefulModuleMixin",rt=m(h=>class extends h{static{m(this,"StatefulModuleBase")}_lastState;async commitState(t){if(t.state.offset===this._lastState?.state.offset)return;this._lastState=t;let s=await this.getArchivistForStore(),[i]=await(await new C().payload(t)).build();await s.insert([i,t])}async getArchivistForStore(){let t=n(this.config?.stateStore?.archivist,()=>`${c}: Config for stateStore.archivist not specified`),s=n(await this.resolve(t),()=>`${c}: Failed to resolve stateStore.archivist`),i=A(s);return n(i,()=>`${c}: Failed to wrap archivist instance`)}async getBoundWitnessDivinerForStore(){let t=n(this.config?.stateStore?.boundWitnessDiviner,()=>`${c}: Config for stateStore.boundWitnessDiviner not specified`),s=n(await this.resolve(t),()=>`${c}: Failed to resolve stateStore.boundWitnessDiviner`),i=y(s);return n(i,()=>`${c}: Failed to wrap diviner instance`)}async getPayloadDivinerForStateStore(){let t=n(this.config?.stateStore?.payloadDiviner,()=>`${c}: Config for stateStore.payloadDiviner not specified`),s=n(await this.resolve(t),()=>`${c}: Failed to resolve stateStore.payloadDiviner`),i=y(s);return n(i,()=>`${c}: Failed to wrap diviner instance`)}async retrieveState(){if(this._lastState)return this._lastState;let t="",s=await this.getBoundWitnessDivinerForStore(),i=await new I({schema:q}).fields({limit:1,offset:0,order:"desc",payload_schemas:[D]}).build(),o=await s.divine([i]);if(o.length>0){let r=o[0];P(r)&&(t=r.addresses.map((d,u)=>({address:d,index:u})).reduce((d,u)=>r.payload_schemas?.[u?.index]===D?r.payload_hashes[u?.index]:d,""))}if(t){let d=(await(await this.getArchivistForStore()).get([t])).find(E);if(d)return d}}},"StatefulModuleMixin");export{g as StatefulDiviner,v as StatefulDivinerConfigSchema,S as StatefulDivinerSchema,rt as StatefulModuleMixin};
242
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config` as const\n/**\n * The schema for a Stateful Diviner config\n */\nexport type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema\n\n/**\n * The config for a Stateful Diviner\n */\nexport type StatefulDivinerConfig = DivinerConfig<{\n schema: StatefulDivinerConfigSchema\n stateStore: {\n archivist: ModuleIdentifier\n boundWitnessDiviner: ModuleIdentifier\n payloadDiviner: ModuleIdentifier\n }\n}>\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\n\nconst moduleName = 'StatefulDiviner'\n\n/**\n * A Diviner that maintains state\n */\nexport abstract class StatefulDiviner<\n TParams extends StatefulDivinerParams = StatefulDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n TState extends StateDictionary = StateDictionary,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, StatefulDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = StatefulDivinerConfigSchema\n\n /**\n * The last state\n */\n protected _lastState?: WithMeta<ModuleState<TState>>\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n protected async commitState(nextState: WithMeta<ModuleState<TState>>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStateStore()\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n protected async getArchivistForStateStore() {\n const name = assertEx(this.config?.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n return ArchivistWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n protected async getBoundWitnessDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n protected async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n protected async retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '' as Hash,\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStateStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\n\nexport type StatefulModuleParams = ModuleParams<AnyConfigSchema<StatefulDivinerConfig>>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyModule<TParams extends StatefulModuleParams = StatefulModuleParams> = new (...args: any[]) => ModuleInstance<TParams>\n\nconst moduleName = 'StatefulModuleMixin'\n\n/**\n * @ignore Inherit from StatefulDiviner instead\n * @param ModuleBase\n * @returns\n */\nexport const StatefulModuleMixin = <\n TParams extends StatefulModuleParams = StatefulModuleParams,\n TModule extends AnyModule<TParams> = AnyModule<TParams>,\n TState extends StateDictionary = StateDictionary,\n>(\n ModuleBase: TModule,\n) => {\n abstract class StatefulModuleBase extends ModuleBase {\n _lastState?: WithMeta<ModuleState<TState>>\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n async commitState(nextState: WithMeta<ModuleState<TState>>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore()\n // const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n const [bw] = await (await new BoundWitnessBuilder().payload(nextState)).build()\n await archivist.insert([bw, nextState])\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n async getArchivistForStore() {\n const name = assertEx(this.config?.stateStore?.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n // return ArchivistWrapper.wrap(mod, this.account)\n const instance = asArchivistInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap archivist instance`)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n async getBoundWitnessDivinerForStore() {\n const name = assertEx(\n this.config?.stateStore?.boundWitnessDiviner,\n () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`,\n )\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n // address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n // .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '' as Hash,\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":";;;;AAAO,IAAMA,wBAAwB;;;ACQ9B,IAAMC,8BAA8B,GAAGC,qBAAAA;;;ACR9C,SAASC,gBAAgB;AAEzB,SAASC,wBAAwB;AACjC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAC/B,SAASC,uBAAuB;AAChC,SAA0CC,sCAAsC;AAEhF,SAASC,sBAAsB;AAC/B,SAASC,eAA4BC,yBAA0C;AAC/E,SAASC,sBAAsB;AAM/B,IAAMC,aAAa;AAKZ,IAAeC,kBAAf,cAUGC,gBAAAA;EA/BV,OA+BUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;;;;EAK7CE;;;;;;;;EASV,MAAgBC,YAAYC,WAA0C;AAEpE,QAAIA,UAAUC,MAAMC,WAAW,KAAKJ,YAAYG,MAAMC,OAAQ;AAC9D,SAAKJ,aAAaE;AAClB,UAAMG,YAAY,MAAM,KAAKC,0BAAyB;AACtD,UAAM,CAACC,EAAAA,IAAM,MAAM,IAAIC,oBAAAA,EAAsBC,QAAQP,SAAAA,EAAWQ,OAAO,KAAKC,OAAO,EAAEC,MAAK;AAC1F,UAAMP,UAAUQ,OAAO;MAACN;MAAIL;KAAU;EACxC;;;;;;EAOA,MAAgBI,4BAA4B;AAC1C,UAAMQ,OAAO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eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,YAAII,gBAAeD,YAAAA,GAAe;AAEhCd,iBAAOc,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAUR,aAAaL,kBAAkBa,MAAMH,KAAAA,MAAWT,qBAAoBI,aAAaS,eAAeD,MAAMH,KAAAA,IAASE,MAChI,EAAA;QAEN;MACF;AAGA,UAAIrB,MAAM;AAER,cAAMrB,YAAY,MAAM,KAAKC,qBAAoB;AACjD,cAAMG,WAAW,MAAMJ,UAAU6C,IAAI;UAACxB;SAAK,GAAGyB,KAAKC,cAAAA;AACnD,YAAI3C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO4C;IACT;EACF;AACA,SAAOtD;AACT,GAjHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulModuleMixin","ModuleBase","StatefulModuleBase","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState","undefined"]}
1
+ {"version":3,"sources":["../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { ModuleIdentifier } from '@xyo-network/module-model'\n\nimport { StatefulDivinerSchema } from './Schema'\n\n/**\n * The schema for a Stateful Diviner config\n */\nexport const StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config` as const\n/**\n * The schema for a Stateful Diviner config\n */\nexport type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema\n\n/**\n * The config for a Stateful Diviner\n */\nexport type StatefulDivinerConfig = DivinerConfig<{\n schema: StatefulDivinerConfigSchema\n stateStore: {\n archivist: ModuleIdentifier\n boundWitnessDiviner: ModuleIdentifier\n payloadDiviner: ModuleIdentifier\n }\n}>\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { isModuleState, ModuleState, ModuleStateSchema, StateDictionary } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfigSchema } from './Config'\nimport { StatefulDivinerParams } from './Params'\n\nconst moduleName = 'StatefulDiviner'\n\n/**\n * A Diviner that maintains state\n */\nexport abstract class StatefulDiviner<\n TParams extends StatefulDivinerParams = StatefulDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n TState extends StateDictionary = StateDictionary,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, StatefulDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = StatefulDivinerConfigSchema\n\n /**\n * The last state\n */\n protected _lastState?: WithMeta<ModuleState<TState>>\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n protected async commitState(nextState: WithMeta<ModuleState<TState>>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStateStore()\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n protected async getArchivistForStateStore() {\n const name = assertEx(this.config?.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n return ArchivistWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n protected async getBoundWitnessDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n protected async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n protected async retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStateStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '' as Hash,\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStateStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport {\n AnyConfigSchema,\n isModuleState,\n ModuleInstance,\n ModuleParams,\n ModuleState,\n ModuleStateSchema,\n StateDictionary,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { WithMeta } from '@xyo-network/payload-model'\n\nimport { StatefulDivinerConfig } from './Config'\n\nexport type StatefulModuleParams = ModuleParams<AnyConfigSchema<StatefulDivinerConfig>>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyModule<TParams extends StatefulModuleParams = StatefulModuleParams> = new (...args: any[]) => ModuleInstance<TParams>\n\nconst moduleName = 'StatefulModuleMixin'\n\n/**\n * @ignore Inherit from StatefulDiviner instead\n * @param ModuleBase\n * @returns\n */\nexport const StatefulModuleMixin = <\n TParams extends StatefulModuleParams = StatefulModuleParams,\n TModule extends AnyModule<TParams> = AnyModule<TParams>,\n TState extends StateDictionary = StateDictionary,\n>(\n ModuleBase: TModule,\n) => {\n abstract class StatefulModuleBase extends ModuleBase {\n _lastState?: WithMeta<ModuleState<TState>>\n\n /**\n * Commit the internal state of the Diviner process. This is similar\n * to a transaction completion in a database and should only be called\n * when results have been successfully persisted to the appropriate\n * external stores.\n * @param nextState The state to commit\n */\n async commitState(nextState: WithMeta<ModuleState<TState>>) {\n // Don't commit state if no state has changed\n if (nextState.state.offset === this._lastState?.state.offset) return\n this._lastState = nextState\n const archivist = await this.getArchivistForStore()\n // const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n const [bw] = await (await new BoundWitnessBuilder().payload(nextState)).build()\n await archivist.insert([bw, nextState])\n }\n\n /**\n * Retrieves the archivist for the specified store\n * @param store The store to retrieve the archivist for\n * @returns The archivist for the specified store\n */\n async getArchivistForStore() {\n const name = assertEx(this.config?.stateStore?.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`)\n // return ArchivistWrapper.wrap(mod, this.account)\n const instance = asArchivistInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap archivist instance`)\n }\n\n /**\n * Retrieves the BoundWitness Diviner for the specified store\n * @param store The store to retrieve the BoundWitness Diviner for\n * @returns The BoundWitness Diviner for the specified store\n */\n async getBoundWitnessDivinerForStore() {\n const name = assertEx(\n this.config?.stateStore?.boundWitnessDiviner,\n () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`,\n )\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n /**\n * Retrieves the Payload Diviner for the specified store\n * @param store The store to retrieve the Payload Diviner for\n * @returns The Payload Diviner for the specified store\n */\n async getPayloadDivinerForStateStore() {\n const name = assertEx(this.config?.stateStore?.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`)\n // return DivinerWrapper.wrap(mod, this.account)\n const instance = asDivinerInstance(mod)\n return assertEx(instance, () => `${moduleName}: Failed to wrap diviner instance`)\n }\n /**\n * Retrieves the last state of the Diviner process. Used to recover state after\n * preemptions, reboots, etc.\n */\n async retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined> {\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore()\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n // address: this.account.address,\n limit: 1,\n offset: 0,\n order: 'desc',\n payload_schemas: [ModuleStateSchema],\n })\n .build()\n const boundWitnesses = await diviner.divine([query])\n if (boundWitnesses.length > 0) {\n const boundWitness = boundWitnesses[0]\n if (isBoundWitness(boundWitness)) {\n // Find the index for this address in the BoundWitness that is a ModuleState\n hash = boundWitness.addresses\n .map((address, index) => ({ address, index }))\n // .filter(({ address }) => address === this.account.address)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '' as Hash,\n )\n }\n }\n\n // If we able to located the last state\n if (hash) {\n // Get last state\n const archivist = await this.getArchivistForStore()\n const payload = (await archivist.get([hash])).find(isModuleState<TState>)\n if (payload) {\n return payload as WithMeta<ModuleState<TState>>\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":"+EAAO,IAAMA,EAAwB,+BCQ9B,IAAMC,EAA8B,GAAGC,CAAAA,UCR9C,OAASC,YAAAA,MAAgB,iBAEzB,OAASC,oBAAAA,MAAwB,iCACjC,OAASC,uBAAAA,MAA2B,oCACpC,OAASC,kBAAAA,MAAsB,kCAC/B,OAASC,mBAAAA,MAAuB,gCAChC,OAA0CC,kCAAAA,MAAsC,0CAEhF,OAASC,kBAAAA,MAAsB,+BAC/B,OAASC,iBAAAA,EAA4BC,qBAAAA,MAA0C,4BAC/E,OAASC,kBAAAA,MAAsB,+BAM/B,IAAMC,EAAa,kBAKGC,EAAf,cAUGC,CAA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ACXC,EAAU,MAAM,KAAKP,+BAA8B,EACnDQ,EAAQ,MAAM,IAAIC,EAAgD,CAAEC,OAAQC,CAA+B,CAAA,EAC9GC,OAAO,CAENC,MAAO,EACP7B,OAAQ,EACR8B,MAAO,OACPC,gBAAiB,CAACC,EACpB,CAAA,EACC1B,MAAK,EACF2B,EAAiB,MAAMV,EAAQW,OAAO,CAACV,EAAM,EACnD,GAAIS,EAAeE,OAAS,EAAG,CAC7B,IAAMC,EAAeH,EAAe,CAAA,EAChCI,EAAeD,CAAAA,IAEjBd,EAAOc,EAAaE,UACjBC,IAAI,CAACC,EAASC,KAAW,CAAED,QAAAA,EAASC,MAAAA,CAAM,EAAA,EAG1CC,OACC,CAACC,EAAMC,IAAUR,EAAaL,kBAAkBa,GAAMH,KAAAA,IAAWT,EAAoBI,EAAaS,eAAeD,GAAMH,KAAAA,EAASE,EAChI,EAAA,EAGR,CAGA,GAAIrB,EAAM,CAGR,IAAMjB,GAAW,MADC,MAAM,KAAKH,qBAAoB,GAChB4C,IAAI,CAACxB,EAAK,GAAGyB,KAAKC,CAAAA,EACnD,GAAI3C,EACF,OAAOA,CAEX,CAEF,CACF,EA/GiC","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","assertEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","DivinerWrapper","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","StatefulDivinerConfigSchema","defaultConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","signer","account","build","insert","name","assertEx","config","stateStore","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStateStore","boundWitnessDiviner","DivinerWrapper","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","index","filter","reduce","prev","curr","payload_hashes","get","find","isModuleState","assertEx","asArchivistInstance","BoundWitnessBuilder","isBoundWitness","BoundWitnessDivinerQuerySchema","asDivinerInstance","isModuleState","ModuleStateSchema","PayloadBuilder","moduleName","StatefulModuleMixin","__name","ModuleBase","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStore","bw","BoundWitnessBuilder","payload","build","insert","name","assertEx","config","stateStore","mod","resolve","instance","asArchivistInstance","getBoundWitnessDivinerForStore","boundWitnessDiviner","asDivinerInstance","getPayloadDivinerForStateStore","payloadDiviner","retrieveState","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","divine","length","boundWitness","isBoundWitness","addresses","map","address","index","reduce","prev","curr","payload_hashes","get","find","isModuleState"]}
@@ -1,16 +1,7 @@
1
1
  import { DivinerConfig } from '@xyo-network/diviner-model';
2
2
  import { ModuleIdentifier } from '@xyo-network/module-model';
3
- /**
4
- * The schema for a Stateful Diviner config
5
- */
6
3
  export declare const StatefulDivinerConfigSchema: "network.xyo.diviner.stateful.config";
7
- /**
8
- * The schema for a Stateful Diviner config
9
- */
10
4
  export type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema;
11
- /**
12
- * The config for a Stateful Diviner
13
- */
14
5
  export type StatefulDivinerConfig = DivinerConfig<{
15
6
  schema: StatefulDivinerConfigSchema;
16
7
  stateStore: {
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAI5D;;GAEG;AACH,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AACrF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAE5E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAO5D,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AAIrF,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAK5E,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
@@ -1,16 +1,7 @@
1
1
  import { DivinerConfig } from '@xyo-network/diviner-model';
2
2
  import { ModuleIdentifier } from '@xyo-network/module-model';
3
- /**
4
- * The schema for a Stateful Diviner config
5
- */
6
3
  export declare const StatefulDivinerConfigSchema: "network.xyo.diviner.stateful.config";
7
- /**
8
- * The schema for a Stateful Diviner config
9
- */
10
4
  export type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema;
11
- /**
12
- * The config for a Stateful Diviner
13
- */
14
5
  export type StatefulDivinerConfig = DivinerConfig<{
15
6
  schema: StatefulDivinerConfigSchema;
16
7
  stateStore: {
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAI5D;;GAEG;AACH,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AACrF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAE5E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAO5D,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AAIrF,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAK5E,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
@@ -1,16 +1,7 @@
1
1
  import { DivinerConfig } from '@xyo-network/diviner-model';
2
2
  import { ModuleIdentifier } from '@xyo-network/module-model';
3
- /**
4
- * The schema for a Stateful Diviner config
5
- */
6
3
  export declare const StatefulDivinerConfigSchema: "network.xyo.diviner.stateful.config";
7
- /**
8
- * The schema for a Stateful Diviner config
9
- */
10
4
  export type StatefulDivinerConfigSchema = typeof StatefulDivinerConfigSchema;
11
- /**
12
- * The config for a Stateful Diviner
13
- */
14
5
  export type StatefulDivinerConfig = DivinerConfig<{
15
6
  schema: StatefulDivinerConfigSchema;
16
7
  stateStore: {
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAI5D;;GAEG;AACH,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AACrF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAE5E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAO5D,eAAO,MAAM,2BAA2B,uCAA6C,CAAA;AAIrF,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAK5E,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAChD,MAAM,EAAE,2BAA2B,CAAA;IACnC,UAAU,EAAE;QACV,SAAS,EAAE,gBAAgB,CAAA;QAC3B,mBAAmB,EAAE,gBAAgB,CAAA;QACrC,cAAc,EAAE,gBAAgB,CAAA;KACjC,CAAA;CACF,CAAC,CAAA"}
@@ -5,57 +5,34 @@ import { DivinerWrapper } from '@xyo-network/diviner-wrapper';
5
5
  import { ModuleState, StateDictionary } from '@xyo-network/module-model';
6
6
  import { Payload, Schema, WithMeta } from '@xyo-network/payload-model';
7
7
  import { StatefulDivinerParams } from './Params';
8
- /**
9
- * A Diviner that maintains state
10
- */
11
8
  export declare abstract class StatefulDiviner<TParams extends StatefulDivinerParams = StatefulDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>, TState extends StateDictionary = StateDictionary> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
12
9
  static readonly configSchemas: Schema[];
13
10
  static readonly defaultConfigSchema: Schema;
14
- /**
15
- * The last state
16
- */
17
11
  protected _lastState?: WithMeta<ModuleState<TState>>;
18
- /**
19
- * Commit the internal state of the Diviner process. This is similar
20
- * to a transaction completion in a database and should only be called
21
- * when results have been successfully persisted to the appropriate
22
- * external stores.
23
- * @param nextState The state to commit
24
- */
25
12
  protected commitState(nextState: WithMeta<ModuleState<TState>>): Promise<void>;
26
- /**
27
- * Retrieves the archivist for the specified store
28
- * @param store The store to retrieve the archivist for
29
- * @returns The archivist for the specified store
30
- */
31
13
  protected getArchivistForStateStore(): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModule<import("@xylabs/object").BaseParamsFields & {
32
- account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
33
- addToResolvers?: boolean | undefined;
34
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[] | undefined;
35
- allowNameResolution?: boolean | undefined;
14
+ account?: import("@xyo-network/account-model").AccountInstance | "random";
15
+ addToResolvers?: boolean;
16
+ additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
17
+ allowNameResolution?: boolean;
36
18
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
37
- parents?: import("@xyo-network/archivist-model").ArchivistParents | undefined;
38
- requireAllParents?: boolean | undefined;
19
+ parents?: import("@xyo-network/archivist-model").ArchivistParents;
20
+ requireAllParents?: boolean;
39
21
  schema: "network.xyo.archivist.config";
40
- storeParentReads?: boolean | undefined;
22
+ storeParentReads?: boolean;
41
23
  }, "schema"> & {
42
24
  schema: "network.xyo.archivist.config";
43
25
  }, "schema"> & {
44
26
  schema: string;
45
27
  };
46
- ephemeralQueryAccountEnabled?: boolean | undefined;
47
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
28
+ ephemeralQueryAccountEnabled?: boolean;
29
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
48
30
  }, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
49
- /**
50
- * Retrieves the BoundWitness Diviner for the specified store
51
- * @param store The store to retrieve the BoundWitness Diviner for
52
- * @returns The BoundWitness Diviner for the specified store
53
- */
54
31
  protected getBoundWitnessDivinerForStateStore(): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
55
- account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
56
- addToResolvers?: boolean | undefined;
57
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[] | undefined;
58
- allowNameResolution?: boolean | undefined;
32
+ account?: import("@xyo-network/account-model").AccountInstance | "random";
33
+ addToResolvers?: boolean;
34
+ additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
35
+ allowNameResolution?: boolean;
59
36
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
60
37
  schema: "network.xyo.diviner.config";
61
38
  }, "schema"> & {
@@ -63,23 +40,18 @@ export declare abstract class StatefulDiviner<TParams extends StatefulDivinerPar
63
40
  }, "schema"> & {
64
41
  schema: string;
65
42
  };
66
- ephemeralQueryAccountEnabled?: boolean | undefined;
67
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
43
+ ephemeralQueryAccountEnabled?: boolean;
44
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
68
45
  }, DivinerModuleEventData>, {
69
46
  schema: string;
70
47
  } & import("@xyo-network/payload-model").PayloadFields, {
71
48
  schema: string;
72
49
  } & import("@xyo-network/payload-model").PayloadFields>>;
73
- /**
74
- * Retrieves the Payload Diviner for the specified store
75
- * @param store The store to retrieve the Payload Diviner for
76
- * @returns The Payload Diviner for the specified store
77
- */
78
50
  protected getPayloadDivinerForStateStore(): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
79
- account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
80
- addToResolvers?: boolean | undefined;
81
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[] | undefined;
82
- allowNameResolution?: boolean | undefined;
51
+ account?: import("@xyo-network/account-model").AccountInstance | "random";
52
+ addToResolvers?: boolean;
53
+ additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
54
+ allowNameResolution?: boolean;
83
55
  config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
84
56
  schema: "network.xyo.diviner.config";
85
57
  }, "schema"> & {
@@ -87,17 +59,13 @@ export declare abstract class StatefulDiviner<TParams extends StatefulDivinerPar
87
59
  }, "schema"> & {
88
60
  schema: string;
89
61
  };
90
- ephemeralQueryAccountEnabled?: boolean | undefined;
91
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
62
+ ephemeralQueryAccountEnabled?: boolean;
63
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
92
64
  }, DivinerModuleEventData>, {
93
65
  schema: string;
94
66
  } & import("@xyo-network/payload-model").PayloadFields, {
95
67
  schema: string;
96
68
  } & import("@xyo-network/payload-model").PayloadFields>>;
97
- /**
98
- * Retrieves the last state of the Diviner process. Used to recover state after
99
- * preemptions, reboots, etc.
100
- */
101
69
  protected retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined>;
102
70
  }
103
71
  //# sourceMappingURL=Diviner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAiB,WAAW,EAAqB,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE1G,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAGtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAIhD;;GAEG;AACH,8BAAsB,eAAe,CACnC,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,EAC7D,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC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