@xyo-network/diviner-stateful 2.84.1

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 (91) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/Config.d.cts +21 -0
  4. package/dist/browser/Config.d.cts.map +1 -0
  5. package/dist/browser/Config.d.mts +21 -0
  6. package/dist/browser/Config.d.mts.map +1 -0
  7. package/dist/browser/Config.d.ts +21 -0
  8. package/dist/browser/Config.d.ts.map +1 -0
  9. package/dist/browser/Diviner.d.cts +49 -0
  10. package/dist/browser/Diviner.d.cts.map +1 -0
  11. package/dist/browser/Diviner.d.mts +49 -0
  12. package/dist/browser/Diviner.d.mts.map +1 -0
  13. package/dist/browser/Diviner.d.ts +49 -0
  14. package/dist/browser/Diviner.d.ts.map +1 -0
  15. package/dist/browser/DivinerMixin.d.cts +3758 -0
  16. package/dist/browser/DivinerMixin.d.cts.map +1 -0
  17. package/dist/browser/DivinerMixin.d.mts +3758 -0
  18. package/dist/browser/DivinerMixin.d.mts.map +1 -0
  19. package/dist/browser/DivinerMixin.d.ts +3758 -0
  20. package/dist/browser/DivinerMixin.d.ts.map +1 -0
  21. package/dist/browser/Params.d.cts +8 -0
  22. package/dist/browser/Params.d.cts.map +1 -0
  23. package/dist/browser/Params.d.mts +8 -0
  24. package/dist/browser/Params.d.mts.map +1 -0
  25. package/dist/browser/Params.d.ts +8 -0
  26. package/dist/browser/Params.d.ts.map +1 -0
  27. package/dist/browser/Schema.d.cts +3 -0
  28. package/dist/browser/Schema.d.cts.map +1 -0
  29. package/dist/browser/Schema.d.mts +3 -0
  30. package/dist/browser/Schema.d.mts.map +1 -0
  31. package/dist/browser/Schema.d.ts +3 -0
  32. package/dist/browser/Schema.d.ts.map +1 -0
  33. package/dist/browser/index.cjs +238 -0
  34. package/dist/browser/index.cjs.map +1 -0
  35. package/dist/browser/index.d.cts +6 -0
  36. package/dist/browser/index.d.cts.map +1 -0
  37. package/dist/browser/index.d.mts +6 -0
  38. package/dist/browser/index.d.mts.map +1 -0
  39. package/dist/browser/index.d.ts +6 -0
  40. package/dist/browser/index.d.ts.map +1 -0
  41. package/dist/browser/index.js +218 -0
  42. package/dist/browser/index.js.map +1 -0
  43. package/dist/node/Config.d.cts +21 -0
  44. package/dist/node/Config.d.cts.map +1 -0
  45. package/dist/node/Config.d.mts +21 -0
  46. package/dist/node/Config.d.mts.map +1 -0
  47. package/dist/node/Config.d.ts +21 -0
  48. package/dist/node/Config.d.ts.map +1 -0
  49. package/dist/node/Diviner.d.cts +49 -0
  50. package/dist/node/Diviner.d.cts.map +1 -0
  51. package/dist/node/Diviner.d.mts +49 -0
  52. package/dist/node/Diviner.d.mts.map +1 -0
  53. package/dist/node/Diviner.d.ts +49 -0
  54. package/dist/node/Diviner.d.ts.map +1 -0
  55. package/dist/node/DivinerMixin.d.cts +3758 -0
  56. package/dist/node/DivinerMixin.d.cts.map +1 -0
  57. package/dist/node/DivinerMixin.d.mts +3758 -0
  58. package/dist/node/DivinerMixin.d.mts.map +1 -0
  59. package/dist/node/DivinerMixin.d.ts +3758 -0
  60. package/dist/node/DivinerMixin.d.ts.map +1 -0
  61. package/dist/node/Params.d.cts +8 -0
  62. package/dist/node/Params.d.cts.map +1 -0
  63. package/dist/node/Params.d.mts +8 -0
  64. package/dist/node/Params.d.mts.map +1 -0
  65. package/dist/node/Params.d.ts +8 -0
  66. package/dist/node/Params.d.ts.map +1 -0
  67. package/dist/node/Schema.d.cts +3 -0
  68. package/dist/node/Schema.d.cts.map +1 -0
  69. package/dist/node/Schema.d.mts +3 -0
  70. package/dist/node/Schema.d.mts.map +1 -0
  71. package/dist/node/Schema.d.ts +3 -0
  72. package/dist/node/Schema.d.ts.map +1 -0
  73. package/dist/node/index.d.cts +6 -0
  74. package/dist/node/index.d.cts.map +1 -0
  75. package/dist/node/index.d.mts +6 -0
  76. package/dist/node/index.d.mts.map +1 -0
  77. package/dist/node/index.d.ts +6 -0
  78. package/dist/node/index.d.ts.map +1 -0
  79. package/dist/node/index.js +259 -0
  80. package/dist/node/index.js.map +1 -0
  81. package/dist/node/index.mjs +232 -0
  82. package/dist/node/index.mjs.map +1 -0
  83. package/package.json +78 -0
  84. package/src/Config.ts +24 -0
  85. package/src/Diviner.ts +127 -0
  86. package/src/DivinerMixin.ts +144 -0
  87. package/src/Params.ts +9 -0
  88. package/src/Schema.ts +2 -0
  89. package/src/index.ts +5 -0
  90. package/src/spec/TestManifest.json +51 -0
  91. package/typedoc.json +5 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EAEf,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAGvF,MAAM,MAAM,SAAS,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,cAAc,CAAC,OAAO,CAAC,CAAA;AAIpI;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0CN,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { StatefulDivinerConfig } from './Config';
4
+ /**
5
+ * The parameters for a Stateful Diviner
6
+ */
7
+ export type StatefulDivinerParams = DivinerParams<AnyConfigSchema<StatefulDivinerConfig>>;
8
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { StatefulDivinerConfig } from './Config';
4
+ /**
5
+ * The parameters for a Stateful Diviner
6
+ */
7
+ export type StatefulDivinerParams = DivinerParams<AnyConfigSchema<StatefulDivinerConfig>>;
8
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { DivinerParams } from '@xyo-network/diviner-model';
2
+ import { AnyConfigSchema } from '@xyo-network/module-model';
3
+ import { StatefulDivinerConfig } from './Config';
4
+ /**
5
+ * The parameters for a Stateful Diviner
6
+ */
7
+ export type StatefulDivinerParams = DivinerParams<AnyConfigSchema<StatefulDivinerConfig>>;
8
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../src/Params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const StatefulDivinerSchema: "network.xyo.diviner.stateful";
2
+ export type StatefulDivinerSchema = typeof StatefulDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,gCAA0C,CAAA;AAC5E,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const StatefulDivinerSchema: "network.xyo.diviner.stateful";
2
+ export type StatefulDivinerSchema = typeof StatefulDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,gCAA0C,CAAA;AAC5E,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const StatefulDivinerSchema: "network.xyo.diviner.stateful";
2
+ export type StatefulDivinerSchema = typeof StatefulDivinerSchema;
3
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,gCAA0C,CAAA;AAC5E,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './DivinerMixin';
4
+ export * from './Params';
5
+ export * from './Schema';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './DivinerMixin';
4
+ export * from './Params';
5
+ export * from './Schema';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ export * from './DivinerMixin';
4
+ export * from './Params';
5
+ export * from './Schema';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ StatefulDiviner: () => StatefulDiviner,
24
+ StatefulDivinerConfigSchema: () => StatefulDivinerConfigSchema,
25
+ StatefulDivinerSchema: () => StatefulDivinerSchema,
26
+ StatefulModuleMixin: () => StatefulModuleMixin
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Schema.ts
31
+ var StatefulDivinerSchema = "network.xyo.diviner.stateful";
32
+
33
+ // src/Config.ts
34
+ var StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config`;
35
+
36
+ // src/Diviner.ts
37
+ var import_assert = require("@xylabs/assert");
38
+ var import_abstract_diviner = require("@xyo-network/abstract-diviner");
39
+ var import_archivist_wrapper = require("@xyo-network/archivist-wrapper");
40
+ var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
41
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
42
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
43
+ var import_diviner_model = require("@xyo-network/diviner-model");
44
+ var import_diviner_wrapper = require("@xyo-network/diviner-wrapper");
45
+ var import_module_model = require("@xyo-network/module-model");
46
+ var import_payload_builder = require("@xyo-network/payload-builder");
47
+ var moduleName = "StatefulDiviner";
48
+ var StatefulDiviner = class extends import_abstract_diviner.AbstractDiviner {
49
+ static configSchemas = [import_diviner_model.DivinerConfigSchema, StatefulDivinerConfigSchema];
50
+ /**
51
+ * The last state
52
+ */
53
+ _lastState;
54
+ /**
55
+ * Commit the internal state of the Diviner process. This is similar
56
+ * to a transaction completion in a database and should only be called
57
+ * when results have been successfully persisted to the appropriate
58
+ * external stores.
59
+ * @param nextState The state to commit
60
+ */
61
+ async commitState(nextState) {
62
+ var _a;
63
+ if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset))
64
+ return;
65
+ this._lastState = nextState;
66
+ const archivist = await this.getArchivistForStateStore();
67
+ const [bw] = await new import_boundwitness_builder.BoundWitnessBuilder().payload(nextState).witness(this.account).build();
68
+ await archivist.insert([bw, nextState]);
69
+ }
70
+ /**
71
+ * Retrieves the archivist for the specified store
72
+ * @param store The store to retrieve the archivist for
73
+ * @returns The archivist for the specified store
74
+ */
75
+ async getArchivistForStateStore() {
76
+ var _a;
77
+ const name = (0, import_assert.assertEx)((_a = this.config) == null ? void 0 : _a.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`);
78
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`);
79
+ return import_archivist_wrapper.ArchivistWrapper.wrap(mod, this.account);
80
+ }
81
+ /**
82
+ * Retrieves the BoundWitness Diviner for the specified store
83
+ * @param store The store to retrieve the BoundWitness Diviner for
84
+ * @returns The BoundWitness Diviner for the specified store
85
+ */
86
+ async getBoundWitnessDivinerForStateStore() {
87
+ var _a;
88
+ const name = (0, import_assert.assertEx)((_a = this.config) == null ? void 0 : _a.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`);
89
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`);
90
+ return import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account);
91
+ }
92
+ /**
93
+ * Retrieves the Payload Diviner for the specified store
94
+ * @param store The store to retrieve the Payload Diviner for
95
+ * @returns The Payload Diviner for the specified store
96
+ */
97
+ async getPayloadDivinerForStateStore() {
98
+ var _a, _b;
99
+ const name = (0, import_assert.assertEx)((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`);
100
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`);
101
+ return import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account);
102
+ }
103
+ /**
104
+ * Retrieves the last state of the Diviner process. Used to recover state after
105
+ * preemptions, reboots, etc.
106
+ */
107
+ async retrieveState() {
108
+ if (this._lastState)
109
+ return this._lastState;
110
+ let hash = "";
111
+ const diviner = await this.getBoundWitnessDivinerForStateStore();
112
+ const query = await new import_payload_builder.PayloadBuilder({ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema }).fields({
113
+ address: this.account.address,
114
+ limit: 1,
115
+ offset: 0,
116
+ order: "desc",
117
+ payload_schemas: [import_module_model.ModuleStateSchema]
118
+ }).build();
119
+ const boundWitnesses = await diviner.divine([query]);
120
+ if (boundWitnesses.length > 0) {
121
+ const boundWitness = boundWitnesses[0];
122
+ if ((0, import_boundwitness_model.isBoundWitness)(boundWitness)) {
123
+ hash = boundWitness.addresses.map((address, index) => ({ address, index })).filter(({ address }) => address === this.account.address).reduce(
124
+ (prev, curr) => {
125
+ var _a;
126
+ return ((_a = boundWitness.payload_schemas) == null ? void 0 : _a[curr == null ? void 0 : curr.index]) === import_module_model.ModuleStateSchema ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
127
+ },
128
+ ""
129
+ );
130
+ }
131
+ }
132
+ if (hash) {
133
+ const archivist = await this.getArchivistForStateStore();
134
+ const payload = (await archivist.get([hash])).find(import_module_model.isModuleState);
135
+ if (payload) {
136
+ return payload;
137
+ }
138
+ }
139
+ return void 0;
140
+ }
141
+ };
142
+
143
+ // src/DivinerMixin.ts
144
+ var import_assert2 = require("@xylabs/assert");
145
+ var import_archivist = require("@xyo-network/archivist");
146
+ var import_boundwitness_builder2 = require("@xyo-network/boundwitness-builder");
147
+ var import_boundwitness_model2 = require("@xyo-network/boundwitness-model");
148
+ var import_diviner_boundwitness_model2 = require("@xyo-network/diviner-boundwitness-model");
149
+ var import_diviner_model2 = require("@xyo-network/diviner-model");
150
+ var import_module_model2 = require("@xyo-network/module-model");
151
+ var import_payload_builder2 = require("@xyo-network/payload-builder");
152
+ var moduleName2 = "StatefulModuleMixin";
153
+ var StatefulModuleMixin = (ModuleBase) => {
154
+ class StatefulModuleBase extends ModuleBase {
155
+ _lastState;
156
+ /**
157
+ * Commit the internal state of the Diviner process. This is similar
158
+ * to a transaction completion in a database and should only be called
159
+ * when results have been successfully persisted to the appropriate
160
+ * external stores.
161
+ * @param nextState The state to commit
162
+ */
163
+ async commitState(nextState) {
164
+ var _a;
165
+ if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset))
166
+ return;
167
+ this._lastState = nextState;
168
+ const archivist = await this.getArchivistForStore();
169
+ const [bw] = await new import_boundwitness_builder2.BoundWitnessBuilder().payload(nextState).build();
170
+ await archivist.insert([bw, nextState]);
171
+ }
172
+ /**
173
+ * Retrieves the archivist for the specified store
174
+ * @param store The store to retrieve the archivist for
175
+ * @returns The archivist for the specified store
176
+ */
177
+ async getArchivistForStore() {
178
+ var _a, _b;
179
+ const name = (0, import_assert2.assertEx)((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.archivist, () => `${moduleName2}: Config for stateStore.archivist not specified`);
180
+ const mod = (0, import_assert2.assertEx)(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.archivist`);
181
+ const instance = (0, import_archivist.asArchivistInstance)(mod);
182
+ return (0, import_assert2.assertEx)(instance, () => `${moduleName2}: Failed to wrap archivist instance`);
183
+ }
184
+ /**
185
+ * Retrieves the BoundWitness Diviner for the specified store
186
+ * @param store The store to retrieve the BoundWitness Diviner for
187
+ * @returns The BoundWitness Diviner for the specified store
188
+ */
189
+ async getBoundWitnessDivinerForStore() {
190
+ var _a, _b;
191
+ const name = (0, import_assert2.assertEx)(
192
+ (_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.boundWitnessDiviner,
193
+ () => `${moduleName2}: Config for stateStore.boundWitnessDiviner not specified`
194
+ );
195
+ const mod = (0, import_assert2.assertEx)(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.boundWitnessDiviner`);
196
+ const instance = (0, import_diviner_model2.asDivinerInstance)(mod);
197
+ return (0, import_assert2.assertEx)(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
198
+ }
199
+ /**
200
+ * Retrieves the Payload Diviner for the specified store
201
+ * @param store The store to retrieve the Payload Diviner for
202
+ * @returns The Payload Diviner for the specified store
203
+ */
204
+ async getPayloadDivinerForStateStore() {
205
+ var _a, _b;
206
+ const name = (0, import_assert2.assertEx)((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName2}: Config for stateStore.payloadDiviner not specified`);
207
+ const mod = (0, import_assert2.assertEx)(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.payloadDiviner`);
208
+ const instance = (0, import_diviner_model2.asDivinerInstance)(mod);
209
+ return (0, import_assert2.assertEx)(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
210
+ }
211
+ /**
212
+ * Retrieves the last state of the Diviner process. Used to recover state after
213
+ * preemptions, reboots, etc.
214
+ */
215
+ async retrieveState() {
216
+ if (this._lastState)
217
+ return this._lastState;
218
+ let hash = "";
219
+ const diviner = await this.getBoundWitnessDivinerForStore();
220
+ const query = await new import_payload_builder2.PayloadBuilder({ schema: import_diviner_boundwitness_model2.BoundWitnessDivinerQuerySchema }).fields({
221
+ // address: this.account.address,
222
+ limit: 1,
223
+ offset: 0,
224
+ order: "desc",
225
+ payload_schemas: [import_module_model2.ModuleStateSchema]
226
+ }).build();
227
+ const boundWitnesses = await diviner.divine([query]);
228
+ if (boundWitnesses.length > 0) {
229
+ const boundWitness = boundWitnesses[0];
230
+ if ((0, import_boundwitness_model2.isBoundWitness)(boundWitness)) {
231
+ hash = boundWitness.addresses.map((address, index) => ({ address, index })).reduce(
232
+ (prev, curr) => {
233
+ var _a;
234
+ return ((_a = boundWitness.payload_schemas) == null ? void 0 : _a[curr == null ? void 0 : curr.index]) === import_module_model2.ModuleStateSchema ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
235
+ },
236
+ ""
237
+ );
238
+ }
239
+ }
240
+ if (hash) {
241
+ const archivist = await this.getArchivistForStore();
242
+ const payload = (await archivist.get([hash])).find(import_module_model2.isModuleState);
243
+ if (payload) {
244
+ return payload;
245
+ }
246
+ }
247
+ return void 0;
248
+ }
249
+ }
250
+ return StatefulModuleBase;
251
+ };
252
+ // Annotate the CommonJS export names for ESM import in node:
253
+ 0 && (module.exports = {
254
+ StatefulDiviner,
255
+ StatefulDivinerConfigSchema,
256
+ StatefulDivinerSchema,
257
+ StatefulModuleMixin
258
+ });
259
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Schema.ts","../../src/Config.ts","../../src/Diviner.ts","../../src/DivinerMixin.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\nexport * from './DivinerMixin'\nexport * from './Params'\nexport * from './Schema'\n","export const StatefulDivinerSchema = 'network.xyo.diviner.stateful' as const\nexport type StatefulDivinerSchema = typeof StatefulDivinerSchema\n","import { DivinerConfig } from '@xyo-network/diviner-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: string\n boundWitnessDiviner: string\n payloadDiviner: string\n }\n}>\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { ArchivistWrapper } from '@xyo-network/archivist-wrapper'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { DivinerConfigSchema, DivinerModule, 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 } 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<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n TState extends StateDictionary = StateDictionary,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: string[] = [DivinerConfigSchema, StatefulDivinerConfigSchema]\n\n /**\n * The last state\n */\n protected _lastState?: 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: 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).witness(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<ModuleState<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: string = ''\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 .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '',\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\n }\n }\n return undefined\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { asArchivistInstance } from '@xyo-network/archivist'\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'\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?: 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: 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).witness(this.account).build()\n const [bw] = 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<ModuleState<TState> | undefined> {\n if (this._lastState) return this._lastState\n let hash: string = ''\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 .reduce(\n (prev, curr) => (boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev),\n '',\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\n }\n }\n return undefined\n }\n }\n return StatefulModuleBase\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,wBAAwB;;;ACO9B,IAAM,8BAA8B,GAAG,qBAAqB;;;ACPnE,oBAAyB;AACzB,8BAAgC;AAChC,+BAAiC;AACjC,kCAAoC;AACpC,gCAA+B;AAC/B,wCAAgF;AAChF,2BAA2E;AAC3E,6BAA+B;AAC/B,0BAA+E;AAC/E,6BAA+B;AAM/B,IAAM,aAAa;AAKZ,IAAe,kBAAf,cAMG,wCAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,0CAAqB,2BAA2B;AAAA;AAAA;AAAA;AAAA,EAK1F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASV,MAAgB,YAAY,WAAgC;AAzC9D;AA2CI,QAAI,UAAU,MAAM,aAAW,UAAK,eAAL,mBAAiB,MAAM;AAAQ;AAC9D,SAAK,aAAa;AAClB,UAAM,YAAY,MAAM,KAAK,0BAA0B;AACvD,UAAM,CAAC,EAAE,IAAI,MAAM,IAAI,gDAAoB,EAAE,QAAQ,SAAS,EAAE,QAAQ,KAAK,OAAO,EAAE,MAAM;AAC5F,UAAM,UAAU,OAAO,CAAC,IAAI,SAAS,CAAC;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,4BAA4B;AAvD9C;AAwDI,UAAM,WAAO,yBAAS,UAAK,WAAL,mBAAa,WAAW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AO;AAAA;AAAA,QAEN,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,iBAAiB,CAAC,sCAAiB;AAAA,MACrC,CAAC,EACA,MAAM;AACT,YAAM,iBAAiB,MAAM,QAAQ,OAAO,CAAC,KAAK,CAAC;AACnD,UAAI,eAAe,SAAS,GAAG;AAC7B,cAAM,eAAe,eAAe,CAAC;AACrC,gBAAI,2CAAe,YAAY,GAAG;AAEhC,iBAAO,aAAa,UACjB,IAAI,CAAC,SAAS,WAAW,EAAE,SAAS,MAAM,EAAE,EAE5C;AAAA,YACC,CAAC,MAAM,SAAM;AA5H3B;AA4H+B,yCAAa,oBAAb,mBAA+B,6BAAM,YAAW,yCAAoB,aAAa,eAAe,6BAAM,KAAK,IAAI;AAAA;AAAA,YAChI;AAAA,UACF;AAAA,QACJ;AAAA,MACF;AAGA,UAAI,MAAM;AAER,cAAM,YAAY,MAAM,KAAK,qBAAqB;AAClD,cAAM,WAAW,MAAM,UAAU,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,kCAAqB;AACxE,YAAI,SAAS;AACX,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":["import_assert","import_boundwitness_builder","import_boundwitness_model","import_diviner_boundwitness_model","import_diviner_model","import_module_model","import_payload_builder","moduleName"]}
@@ -0,0 +1,232 @@
1
+ // src/Schema.ts
2
+ var StatefulDivinerSchema = "network.xyo.diviner.stateful";
3
+
4
+ // src/Config.ts
5
+ var StatefulDivinerConfigSchema = `${StatefulDivinerSchema}.config`;
6
+
7
+ // src/Diviner.ts
8
+ import { assertEx } from "@xylabs/assert";
9
+ import { AbstractDiviner } from "@xyo-network/abstract-diviner";
10
+ import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
11
+ import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
12
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
13
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
14
+ import { DivinerConfigSchema } from "@xyo-network/diviner-model";
15
+ import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
16
+ import { isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
17
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
18
+ var moduleName = "StatefulDiviner";
19
+ var StatefulDiviner = class extends AbstractDiviner {
20
+ static configSchemas = [DivinerConfigSchema, StatefulDivinerConfigSchema];
21
+ /**
22
+ * The last state
23
+ */
24
+ _lastState;
25
+ /**
26
+ * Commit the internal state of the Diviner process. This is similar
27
+ * to a transaction completion in a database and should only be called
28
+ * when results have been successfully persisted to the appropriate
29
+ * external stores.
30
+ * @param nextState The state to commit
31
+ */
32
+ async commitState(nextState) {
33
+ var _a;
34
+ if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset))
35
+ return;
36
+ this._lastState = nextState;
37
+ const archivist = await this.getArchivistForStateStore();
38
+ const [bw] = await new BoundWitnessBuilder().payload(nextState).witness(this.account).build();
39
+ await archivist.insert([bw, nextState]);
40
+ }
41
+ /**
42
+ * Retrieves the archivist for the specified store
43
+ * @param store The store to retrieve the archivist for
44
+ * @returns The archivist for the specified store
45
+ */
46
+ async getArchivistForStateStore() {
47
+ var _a;
48
+ const name = assertEx((_a = this.config) == null ? void 0 : _a.stateStore.archivist, () => `${moduleName}: Config for stateStore.archivist not specified`);
49
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.archivist`);
50
+ return ArchivistWrapper.wrap(mod, this.account);
51
+ }
52
+ /**
53
+ * Retrieves the BoundWitness Diviner for the specified store
54
+ * @param store The store to retrieve the BoundWitness Diviner for
55
+ * @returns The BoundWitness Diviner for the specified store
56
+ */
57
+ async getBoundWitnessDivinerForStateStore() {
58
+ var _a;
59
+ const name = assertEx((_a = this.config) == null ? void 0 : _a.stateStore.boundWitnessDiviner, () => `${moduleName}: Config for stateStore.boundWitnessDiviner not specified`);
60
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.boundWitnessDiviner`);
61
+ return DivinerWrapper.wrap(mod, this.account);
62
+ }
63
+ /**
64
+ * Retrieves the Payload Diviner for the specified store
65
+ * @param store The store to retrieve the Payload Diviner for
66
+ * @returns The Payload Diviner for the specified store
67
+ */
68
+ async getPayloadDivinerForStateStore() {
69
+ var _a, _b;
70
+ const name = assertEx((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName}: Config for stateStore.payloadDiviner not specified`);
71
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve stateStore.payloadDiviner`);
72
+ return DivinerWrapper.wrap(mod, this.account);
73
+ }
74
+ /**
75
+ * Retrieves the last state of the Diviner process. Used to recover state after
76
+ * preemptions, reboots, etc.
77
+ */
78
+ async retrieveState() {
79
+ if (this._lastState)
80
+ return this._lastState;
81
+ let hash = "";
82
+ const diviner = await this.getBoundWitnessDivinerForStateStore();
83
+ const query = await new PayloadBuilder({ schema: BoundWitnessDivinerQuerySchema }).fields({
84
+ address: this.account.address,
85
+ limit: 1,
86
+ offset: 0,
87
+ order: "desc",
88
+ payload_schemas: [ModuleStateSchema]
89
+ }).build();
90
+ const boundWitnesses = await diviner.divine([query]);
91
+ if (boundWitnesses.length > 0) {
92
+ const boundWitness = boundWitnesses[0];
93
+ if (isBoundWitness(boundWitness)) {
94
+ hash = boundWitness.addresses.map((address, index) => ({ address, index })).filter(({ address }) => address === this.account.address).reduce(
95
+ (prev, curr) => {
96
+ var _a;
97
+ return ((_a = boundWitness.payload_schemas) == null ? void 0 : _a[curr == null ? void 0 : curr.index]) === ModuleStateSchema ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
98
+ },
99
+ ""
100
+ );
101
+ }
102
+ }
103
+ if (hash) {
104
+ const archivist = await this.getArchivistForStateStore();
105
+ const payload = (await archivist.get([hash])).find(isModuleState);
106
+ if (payload) {
107
+ return payload;
108
+ }
109
+ }
110
+ return void 0;
111
+ }
112
+ };
113
+
114
+ // src/DivinerMixin.ts
115
+ import { assertEx as assertEx2 } from "@xylabs/assert";
116
+ import { asArchivistInstance } from "@xyo-network/archivist";
117
+ import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
118
+ import { isBoundWitness as isBoundWitness2 } from "@xyo-network/boundwitness-model";
119
+ import { BoundWitnessDivinerQuerySchema as BoundWitnessDivinerQuerySchema2 } from "@xyo-network/diviner-boundwitness-model";
120
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
121
+ import {
122
+ isModuleState as isModuleState2,
123
+ ModuleStateSchema as ModuleStateSchema2
124
+ } from "@xyo-network/module-model";
125
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
126
+ var moduleName2 = "StatefulModuleMixin";
127
+ var StatefulModuleMixin = (ModuleBase) => {
128
+ class StatefulModuleBase extends ModuleBase {
129
+ _lastState;
130
+ /**
131
+ * Commit the internal state of the Diviner process. This is similar
132
+ * to a transaction completion in a database and should only be called
133
+ * when results have been successfully persisted to the appropriate
134
+ * external stores.
135
+ * @param nextState The state to commit
136
+ */
137
+ async commitState(nextState) {
138
+ var _a;
139
+ if (nextState.state.offset === ((_a = this._lastState) == null ? void 0 : _a.state.offset))
140
+ return;
141
+ this._lastState = nextState;
142
+ const archivist = await this.getArchivistForStore();
143
+ const [bw] = await new BoundWitnessBuilder2().payload(nextState).build();
144
+ await archivist.insert([bw, nextState]);
145
+ }
146
+ /**
147
+ * Retrieves the archivist for the specified store
148
+ * @param store The store to retrieve the archivist for
149
+ * @returns The archivist for the specified store
150
+ */
151
+ async getArchivistForStore() {
152
+ var _a, _b;
153
+ const name = assertEx2((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.archivist, () => `${moduleName2}: Config for stateStore.archivist not specified`);
154
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.archivist`);
155
+ const instance = asArchivistInstance(mod);
156
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap archivist instance`);
157
+ }
158
+ /**
159
+ * Retrieves the BoundWitness Diviner for the specified store
160
+ * @param store The store to retrieve the BoundWitness Diviner for
161
+ * @returns The BoundWitness Diviner for the specified store
162
+ */
163
+ async getBoundWitnessDivinerForStore() {
164
+ var _a, _b;
165
+ const name = assertEx2(
166
+ (_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.boundWitnessDiviner,
167
+ () => `${moduleName2}: Config for stateStore.boundWitnessDiviner not specified`
168
+ );
169
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.boundWitnessDiviner`);
170
+ const instance = asDivinerInstance(mod);
171
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
172
+ }
173
+ /**
174
+ * Retrieves the Payload Diviner for the specified store
175
+ * @param store The store to retrieve the Payload Diviner for
176
+ * @returns The Payload Diviner for the specified store
177
+ */
178
+ async getPayloadDivinerForStateStore() {
179
+ var _a, _b;
180
+ const name = assertEx2((_b = (_a = this.config) == null ? void 0 : _a.stateStore) == null ? void 0 : _b.payloadDiviner, () => `${moduleName2}: Config for stateStore.payloadDiviner not specified`);
181
+ const mod = assertEx2(await this.resolve(name), () => `${moduleName2}: Failed to resolve stateStore.payloadDiviner`);
182
+ const instance = asDivinerInstance(mod);
183
+ return assertEx2(instance, () => `${moduleName2}: Failed to wrap diviner instance`);
184
+ }
185
+ /**
186
+ * Retrieves the last state of the Diviner process. Used to recover state after
187
+ * preemptions, reboots, etc.
188
+ */
189
+ async retrieveState() {
190
+ if (this._lastState)
191
+ return this._lastState;
192
+ let hash = "";
193
+ const diviner = await this.getBoundWitnessDivinerForStore();
194
+ const query = await new PayloadBuilder2({ schema: BoundWitnessDivinerQuerySchema2 }).fields({
195
+ // address: this.account.address,
196
+ limit: 1,
197
+ offset: 0,
198
+ order: "desc",
199
+ payload_schemas: [ModuleStateSchema2]
200
+ }).build();
201
+ const boundWitnesses = await diviner.divine([query]);
202
+ if (boundWitnesses.length > 0) {
203
+ const boundWitness = boundWitnesses[0];
204
+ if (isBoundWitness2(boundWitness)) {
205
+ hash = boundWitness.addresses.map((address, index) => ({ address, index })).reduce(
206
+ (prev, curr) => {
207
+ var _a;
208
+ return ((_a = boundWitness.payload_schemas) == null ? void 0 : _a[curr == null ? void 0 : curr.index]) === ModuleStateSchema2 ? boundWitness.payload_hashes[curr == null ? void 0 : curr.index] : prev;
209
+ },
210
+ ""
211
+ );
212
+ }
213
+ }
214
+ if (hash) {
215
+ const archivist = await this.getArchivistForStore();
216
+ const payload = (await archivist.get([hash])).find(isModuleState2);
217
+ if (payload) {
218
+ return payload;
219
+ }
220
+ }
221
+ return void 0;
222
+ }
223
+ }
224
+ return StatefulModuleBase;
225
+ };
226
+ export {
227
+ StatefulDiviner,
228
+ StatefulDivinerConfigSchema,
229
+ StatefulDivinerSchema,
230
+ StatefulModuleMixin
231
+ };
232
+ //# sourceMappingURL=index.mjs.map