@xyo-network/diviner-stateful 2.93.4 → 2.93.6

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.
@@ -26,6 +26,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
26
26
  schema: string;
27
27
  };
28
28
  ephemeralQueryAccountEnabled?: boolean | undefined;
29
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
29
30
  } = import("@xylabs/object").BaseParamsFields & {
30
31
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
31
32
  addToResolvers?: boolean | undefined;
@@ -44,6 +45,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
44
45
  schema: string;
45
46
  };
46
47
  ephemeralQueryAccountEnabled?: boolean | undefined;
48
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
47
49
  }, TModule extends AnyModule<TParams> = AnyModule<TParams>, TState extends StateDictionary = StateDictionary>(ModuleBase: TModule) => (abstract new (...args: any[]) => {
48
50
  _lastState?: WithMeta<ModuleState<TState>> | undefined;
49
51
  /**
@@ -73,6 +75,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
73
75
  schema: string;
74
76
  };
75
77
  ephemeralQueryAccountEnabled?: boolean | undefined;
78
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
76
79
  }, import("@xyo-network/archivist-model").ArchivistModuleEventData, {
77
80
  schema: string;
78
81
  } & import("@xyo-network/payload-model").PayloadFields>>;
@@ -92,11 +95,26 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
92
95
  schema: string;
93
96
  };
94
97
  ephemeralQueryAccountEnabled?: boolean | undefined;
98
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
95
99
  }, {
96
100
  schema: string;
97
101
  } & import("@xyo-network/payload-model").PayloadFields, {
98
102
  schema: string;
99
- } & import("@xyo-network/payload-model").PayloadFields>>;
103
+ } & import("@xyo-network/payload-model").PayloadFields, import("@xyo-network/diviner-model").DivinerModuleEventData<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
104
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
105
+ addToResolvers?: boolean | undefined;
106
+ 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 & {
107
+ schema: "network.xyo.module.config";
108
+ }, "schema"> & {
109
+ schema: string;
110
+ };
111
+ ephemeralQueryAccountEnabled?: boolean | undefined;
112
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
113
+ }, import("@xyo-network/module-model").ModuleEventData<object>>, {
114
+ schema: string;
115
+ } & import("@xyo-network/payload-model").PayloadFields, {
116
+ schema: string;
117
+ } & import("@xyo-network/payload-model").PayloadFields>>>;
100
118
  /**
101
119
  * Retrieves the Payload Diviner for the specified store
102
120
  * @param store The store to retrieve the Payload Diviner for
@@ -113,17 +131,12 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
113
131
  schema: string;
114
132
  };
115
133
  ephemeralQueryAccountEnabled?: boolean | undefined;
134
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
116
135
  }, {
117
136
  schema: string;
118
137
  } & import("@xyo-network/payload-model").PayloadFields, {
119
138
  schema: string;
120
- } & import("@xyo-network/payload-model").PayloadFields>>;
121
- /**
122
- * Retrieves the last state of the Diviner process. Used to recover state after
123
- * preemptions, reboots, etc.
124
- */
125
- retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined>;
126
- readonly downResolver: Omit<import("@xyo-network/module-model").ObjectResolverInstance<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
139
+ } & import("@xyo-network/payload-model").PayloadFields, import("@xyo-network/diviner-model").DivinerModuleEventData<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
127
140
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
128
141
  addToResolvers?: boolean | undefined;
129
142
  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 & {
@@ -132,19 +145,19 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
132
145
  schema: string;
133
146
  };
134
147
  ephemeralQueryAccountEnabled?: boolean | undefined;
135
- }, import("@xyo-network/module-model").ModuleEventData<object>>>, "resolve">;
148
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
149
+ }, import("@xyo-network/module-model").ModuleEventData<object>>, {
150
+ schema: string;
151
+ } & import("@xyo-network/payload-model").PayloadFields, {
152
+ schema: string;
153
+ } & import("@xyo-network/payload-model").PayloadFields>>>;
154
+ /**
155
+ * Retrieves the last state of the Diviner process. Used to recover state after
156
+ * preemptions, reboots, etc.
157
+ */
158
+ retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined>;
136
159
  readonly pipeline?: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many" | undefined;
137
160
  readonly status: import("@xyo-network/module-model").ModuleStatus;
138
- readonly upResolver: Omit<import("@xyo-network/module-model").ObjectResolverInstance<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
139
- account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
140
- addToResolvers?: boolean | undefined;
141
- 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 & {
142
- schema: "network.xyo.module.config";
143
- }, "schema"> & {
144
- schema: string;
145
- };
146
- ephemeralQueryAccountEnabled?: boolean | undefined;
147
- }, import("@xyo-network/module-model").ModuleEventData<object>>>, "resolve">;
148
161
  address: Lowercase<string>;
149
162
  config: TParams["config"];
150
163
  id: string;
@@ -210,6 +223,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
210
223
  schema: string;
211
224
  };
212
225
  ephemeralQueryAccountEnabled?: boolean | undefined;
226
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
213
227
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
214
228
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
215
229
  addToResolvers?: boolean | undefined;
@@ -219,6 +233,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
219
233
  schema: string;
220
234
  };
221
235
  ephemeralQueryAccountEnabled?: boolean | undefined;
236
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
222
237
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(): import("@xylabs/promise").Promisable<T_2 | undefined>;
223
238
  resolve<T_3 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
224
239
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -229,6 +244,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
229
244
  schema: string;
230
245
  };
231
246
  ephemeralQueryAccountEnabled?: boolean | undefined;
247
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
232
248
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
233
249
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
234
250
  addToResolvers?: boolean | undefined;
@@ -238,6 +254,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
238
254
  schema: string;
239
255
  };
240
256
  ephemeralQueryAccountEnabled?: boolean | undefined;
257
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
241
258
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(all: "*", options?: import("@xyo-network/module-model").ObjectFilterOptions<T_3> | undefined): import("@xylabs/promise").Promisable<T_3[]>;
242
259
  resolve<T_4 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
243
260
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -248,6 +265,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
248
265
  schema: string;
249
266
  };
250
267
  ephemeralQueryAccountEnabled?: boolean | undefined;
268
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
251
269
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
252
270
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
253
271
  addToResolvers?: boolean | undefined;
@@ -257,6 +275,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
257
275
  schema: string;
258
276
  };
259
277
  ephemeralQueryAccountEnabled?: boolean | undefined;
278
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
260
279
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(id: string, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_4> | undefined): import("@xylabs/promise").Promisable<T_4 | undefined>;
261
280
  resolve<T_5 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
262
281
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -267,6 +286,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
267
286
  schema: string;
268
287
  };
269
288
  ephemeralQueryAccountEnabled?: boolean | undefined;
289
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
270
290
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
271
291
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
272
292
  addToResolvers?: boolean | undefined;
@@ -276,6 +296,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
276
296
  schema: string;
277
297
  };
278
298
  ephemeralQueryAccountEnabled?: boolean | undefined;
299
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
279
300
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(filter: import("@xyo-network/module-model").ObjectFilter<T_5>, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_5> | undefined): import("@xylabs/promise").Promisable<T_5[]>;
280
301
  resolve<T_6 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
281
302
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -286,6 +307,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
286
307
  schema: string;
287
308
  };
288
309
  ephemeralQueryAccountEnabled?: boolean | undefined;
310
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
289
311
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
290
312
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
291
313
  addToResolvers?: boolean | undefined;
@@ -295,6 +317,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
295
317
  schema: string;
296
318
  };
297
319
  ephemeralQueryAccountEnabled?: boolean | undefined;
320
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
298
321
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(filter?: import("@xyo-network/module-model").ObjectFilter<T_6> | undefined, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_6> | undefined): import("@xylabs/promise").Promisable<T_6[]>;
299
322
  resolve<T_7 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
300
323
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -305,6 +328,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
305
328
  schema: string;
306
329
  };
307
330
  ephemeralQueryAccountEnabled?: boolean | undefined;
331
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
308
332
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
309
333
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
310
334
  addToResolvers?: boolean | undefined;
@@ -314,6 +338,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
314
338
  schema: string;
315
339
  };
316
340
  ephemeralQueryAccountEnabled?: boolean | undefined;
341
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
317
342
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(idOrFilter?: string | import("@xyo-network/module-model").ObjectFilter<T_7> | undefined, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_7> | undefined): import("@xylabs/promise").Promisable<T_7 | T_7[] | undefined>;
318
343
  describe: () => Promise<import("@xyo-network/module-model").ModuleDescription>;
319
344
  discover: () => import("@xylabs/promise").Promisable<({
@@ -1 +1 @@
1
- {"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EAEf,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAEhD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,eAAe,CAAC,qBAAq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AAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,cAAc,CAAC,OAAO,CAAC,CAAA;AAIpI;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0HAKlB,OAAO,6BAd8E,GAAG,EAAE;;IAmBpG;;;;;;OAMG;2BAC0B,SAAS,YAAY,MAAM,CAAC,CAAC;IAU1D;;;;OAIG;;;;;;;;;;;;;;;;;;;IASH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAWH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAQH;;;OAGG;qBACoB,QAAQ,SAAS,YAAY,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0C5E,CAAA"}
@@ -26,6 +26,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
26
26
  schema: string;
27
27
  };
28
28
  ephemeralQueryAccountEnabled?: boolean | undefined;
29
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
29
30
  } = import("@xylabs/object").BaseParamsFields & {
30
31
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
31
32
  addToResolvers?: boolean | undefined;
@@ -44,6 +45,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
44
45
  schema: string;
45
46
  };
46
47
  ephemeralQueryAccountEnabled?: boolean | undefined;
48
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
47
49
  }, TModule extends AnyModule<TParams> = AnyModule<TParams>, TState extends StateDictionary = StateDictionary>(ModuleBase: TModule) => (abstract new (...args: any[]) => {
48
50
  _lastState?: WithMeta<ModuleState<TState>> | undefined;
49
51
  /**
@@ -73,6 +75,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
73
75
  schema: string;
74
76
  };
75
77
  ephemeralQueryAccountEnabled?: boolean | undefined;
78
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
76
79
  }, import("@xyo-network/archivist-model").ArchivistModuleEventData, {
77
80
  schema: string;
78
81
  } & import("@xyo-network/payload-model").PayloadFields>>;
@@ -92,11 +95,26 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
92
95
  schema: string;
93
96
  };
94
97
  ephemeralQueryAccountEnabled?: boolean | undefined;
98
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
95
99
  }, {
96
100
  schema: string;
97
101
  } & import("@xyo-network/payload-model").PayloadFields, {
98
102
  schema: string;
99
- } & import("@xyo-network/payload-model").PayloadFields>>;
103
+ } & import("@xyo-network/payload-model").PayloadFields, import("@xyo-network/diviner-model").DivinerModuleEventData<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
104
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
105
+ addToResolvers?: boolean | undefined;
106
+ 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 & {
107
+ schema: "network.xyo.module.config";
108
+ }, "schema"> & {
109
+ schema: string;
110
+ };
111
+ ephemeralQueryAccountEnabled?: boolean | undefined;
112
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
113
+ }, import("@xyo-network/module-model").ModuleEventData<object>>, {
114
+ schema: string;
115
+ } & import("@xyo-network/payload-model").PayloadFields, {
116
+ schema: string;
117
+ } & import("@xyo-network/payload-model").PayloadFields>>>;
100
118
  /**
101
119
  * Retrieves the Payload Diviner for the specified store
102
120
  * @param store The store to retrieve the Payload Diviner for
@@ -113,17 +131,12 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
113
131
  schema: string;
114
132
  };
115
133
  ephemeralQueryAccountEnabled?: boolean | undefined;
134
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
116
135
  }, {
117
136
  schema: string;
118
137
  } & import("@xyo-network/payload-model").PayloadFields, {
119
138
  schema: string;
120
- } & import("@xyo-network/payload-model").PayloadFields>>;
121
- /**
122
- * Retrieves the last state of the Diviner process. Used to recover state after
123
- * preemptions, reboots, etc.
124
- */
125
- retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined>;
126
- readonly downResolver: Omit<import("@xyo-network/module-model").ObjectResolverInstance<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
139
+ } & import("@xyo-network/payload-model").PayloadFields, import("@xyo-network/diviner-model").DivinerModuleEventData<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
127
140
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
128
141
  addToResolvers?: boolean | undefined;
129
142
  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 & {
@@ -132,19 +145,19 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
132
145
  schema: string;
133
146
  };
134
147
  ephemeralQueryAccountEnabled?: boolean | undefined;
135
- }, import("@xyo-network/module-model").ModuleEventData<object>>>, "resolve">;
148
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
149
+ }, import("@xyo-network/module-model").ModuleEventData<object>>, {
150
+ schema: string;
151
+ } & import("@xyo-network/payload-model").PayloadFields, {
152
+ schema: string;
153
+ } & import("@xyo-network/payload-model").PayloadFields>>>;
154
+ /**
155
+ * Retrieves the last state of the Diviner process. Used to recover state after
156
+ * preemptions, reboots, etc.
157
+ */
158
+ retrieveState(): Promise<WithMeta<ModuleState<TState>> | undefined>;
136
159
  readonly pipeline?: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many" | undefined;
137
160
  readonly status: import("@xyo-network/module-model").ModuleStatus;
138
- readonly upResolver: Omit<import("@xyo-network/module-model").ObjectResolverInstance<ModuleInstance<import("@xylabs/object").BaseParamsFields & {
139
- account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
140
- addToResolvers?: boolean | undefined;
141
- 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 & {
142
- schema: "network.xyo.module.config";
143
- }, "schema"> & {
144
- schema: string;
145
- };
146
- ephemeralQueryAccountEnabled?: boolean | undefined;
147
- }, import("@xyo-network/module-model").ModuleEventData<object>>>, "resolve">;
148
161
  address: Lowercase<string>;
149
162
  config: TParams["config"];
150
163
  id: string;
@@ -210,6 +223,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
210
223
  schema: string;
211
224
  };
212
225
  ephemeralQueryAccountEnabled?: boolean | undefined;
226
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
213
227
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
214
228
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
215
229
  addToResolvers?: boolean | undefined;
@@ -219,6 +233,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
219
233
  schema: string;
220
234
  };
221
235
  ephemeralQueryAccountEnabled?: boolean | undefined;
236
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
222
237
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(): import("@xylabs/promise").Promisable<T_2 | undefined>;
223
238
  resolve<T_3 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
224
239
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -229,6 +244,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
229
244
  schema: string;
230
245
  };
231
246
  ephemeralQueryAccountEnabled?: boolean | undefined;
247
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
232
248
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
233
249
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
234
250
  addToResolvers?: boolean | undefined;
@@ -238,6 +254,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
238
254
  schema: string;
239
255
  };
240
256
  ephemeralQueryAccountEnabled?: boolean | undefined;
257
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
241
258
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(all: "*", options?: import("@xyo-network/module-model").ObjectFilterOptions<T_3> | undefined): import("@xylabs/promise").Promisable<T_3[]>;
242
259
  resolve<T_4 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
243
260
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -248,6 +265,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
248
265
  schema: string;
249
266
  };
250
267
  ephemeralQueryAccountEnabled?: boolean | undefined;
268
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
251
269
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
252
270
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
253
271
  addToResolvers?: boolean | undefined;
@@ -257,6 +275,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
257
275
  schema: string;
258
276
  };
259
277
  ephemeralQueryAccountEnabled?: boolean | undefined;
278
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
260
279
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(id: string, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_4> | undefined): import("@xylabs/promise").Promisable<T_4 | undefined>;
261
280
  resolve<T_5 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
262
281
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -267,6 +286,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
267
286
  schema: string;
268
287
  };
269
288
  ephemeralQueryAccountEnabled?: boolean | undefined;
289
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
270
290
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
271
291
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
272
292
  addToResolvers?: boolean | undefined;
@@ -276,6 +296,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
276
296
  schema: string;
277
297
  };
278
298
  ephemeralQueryAccountEnabled?: boolean | undefined;
299
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
279
300
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(filter: import("@xyo-network/module-model").ObjectFilter<T_5>, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_5> | undefined): import("@xylabs/promise").Promisable<T_5[]>;
280
301
  resolve<T_6 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
281
302
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -286,6 +307,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
286
307
  schema: string;
287
308
  };
288
309
  ephemeralQueryAccountEnabled?: boolean | undefined;
310
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
289
311
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
290
312
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
291
313
  addToResolvers?: boolean | undefined;
@@ -295,6 +317,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
295
317
  schema: string;
296
318
  };
297
319
  ephemeralQueryAccountEnabled?: boolean | undefined;
320
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
298
321
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(filter?: import("@xyo-network/module-model").ObjectFilter<T_6> | undefined, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_6> | undefined): import("@xylabs/promise").Promisable<T_6[]>;
299
322
  resolve<T_7 extends ModuleInstance<import("@xylabs/object").BaseParamsFields & {
300
323
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
@@ -305,6 +328,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
305
328
  schema: string;
306
329
  };
307
330
  ephemeralQueryAccountEnabled?: boolean | undefined;
331
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
308
332
  }, import("@xyo-network/module-model").ModuleEventData<object>> = ModuleInstance<import("@xylabs/object").BaseParamsFields & {
309
333
  account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
310
334
  addToResolvers?: boolean | undefined;
@@ -314,6 +338,7 @@ export declare const StatefulModuleMixin: <TParams extends import("@xylabs/objec
314
338
  schema: string;
315
339
  };
316
340
  ephemeralQueryAccountEnabled?: boolean | undefined;
341
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
317
342
  }, import("@xyo-network/module-model").ModuleEventData<object>>>(idOrFilter?: string | import("@xyo-network/module-model").ObjectFilter<T_7> | undefined, options?: import("@xyo-network/module-model").ObjectFilterOptions<T_7> | undefined): import("@xylabs/promise").Promisable<T_7 | T_7[] | undefined>;
318
343
  describe: () => Promise<import("@xyo-network/module-model").ModuleDescription>;
319
344
  discover: () => import("@xylabs/promise").Promisable<({
@@ -1 +1 @@
1
- {"version":3,"file":"DivinerMixin.d.ts","sourceRoot":"","sources":["../../src/DivinerMixin.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EAEf,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0HAKlB,OAAO,6BAd8E,GAAG,EAAE;;IAmBpG;;;;;;OAMG;2BAC0B,SAAS,YAAY,MAAM,CAAC,CAAC;IAU1D;;;;OAIG;;;;;;;;;;;;;;;;;;IASH;;;;OAIG;;;;;;;;;;;;;;;;;IAWH;;;;OAIG;;;;;;;;;;;;;;;;;IAQH;;;OAGG;qBACoB,QAAQ,SAAS,YAAY,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA0C5E,CAAA"}
@@ -1 +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'\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 { 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, 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<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?: 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 (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<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).witness(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":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAO,IAAMA,wBAAwB;;;ACQ9B,IAAMC,8BAA8B,GAAGC,qBAAAA;;;ACR9C,oBAAyB;AAEzB,+BAAiC;AACjC,kCAAoC;AACpC,gCAA+B;AAC/B,8BAAgC;AAChC,wCAAgF;AAChF,2BAA2E;AAC3E,6BAA+B;AAC/B,0BAA+E;AAC/E,6BAA+B;AAM/B,IAAMC,aAAa;AAKZ,IAAeC,kBAAf,cAMGC,wCAAAA;EA3BV,OA2BUA;;;EACR,OAAyBC,gBAA0B;IAACC;IAAqBC;;;;;EAK/DC;;;;;;;;EASV,MAAgBC,YAAYC,WAA0C;AAEpE,QAAIA,UAAUC,MAAMC,WAAW,KAAKJ,YAAYG,MAAMC;AAAQ;AAC9D,SAAKJ,aAAaE;AAClB,UAAMG,YAAY,MAAM,KAAKC,0BAAyB;AACtD,UAAM,CAACC,EAAAA,IAAM,OAAO,MAAM,IAAIC,gDAAAA,EAAsBC,QAAQP,SAAAA,G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B;UAACC;;MACpB,CAAA,EACC1B,MAAK;AACR,YAAM2B,iBAAiB,MAAMV,QAAQW,OAAO;QAACV;OAAM;AACnD,UAAIS,eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,gBAAII,2CAAeD,YAAAA,GAAe;AAEhCd,iBAAOc,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAUR,aAAaL,kBAAkBa,MAAMH,KAAAA,MAAWT,yCAAoBI,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,kCAAAA;AACnD,YAAI3C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO4C;IACT;EACF;AACA,SAAOtD;AACT,GAjHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","DivinerConfigSchema","StatefulDivinerConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","witness","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","import_assert","import_boundwitness_builder","import_boundwitness_model","import_diviner_boundwitness_model","import_diviner_model","import_module_model","import_payload_builder","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/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'\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 { DivinerConfigSchema, 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, 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: string[] = [DivinerConfigSchema, 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 (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<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).witness(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":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAO,IAAMA,wBAAwB;;;ACQ9B,IAAMC,8BAA8B,GAAGC,qBAAAA;;;ACR9C,oBAAyB;AAEzB,+BAAiC;AACjC,kCAAoC;AACpC,gCAA+B;AAC/B,8BAAgC;AAChC,wCAAgF;AAChF,2BAA6E;AAC7E,6BAA+B;AAC/B,0BAA+E;AAC/E,6BAA+B;AAM/B,IAAMC,aAAa;AAKZ,IAAeC,kBAAf,cAUGC,wCAAAA;EA/BV,OA+BUA;;;EACR,OAAyBC,gBAA0B;IAACC;IAAqBC;;;;;EAK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AM6B,gBAAoE;AACxE,UAAI,KAAKzB;AAAY,eAAO,KAAKA;AACjC,UAAI0B,OAAa;AACjB,YAAMC,UAAU,MAAM,KAAKP,+BAA8B;AACzD,YAAMQ,QAAQ,MAAM,IAAIC,uCAAgD;QAAEC,QAAQC;MAA+B,CAAA,EAC9GC,OAAO;;QAENC,OAAO;QACP7B,QAAQ;QACR8B,OAAO;QACPC,iBAAiB;UAACC;;MACpB,CAAA,EACC1B,MAAK;AACR,YAAM2B,iBAAiB,MAAMV,QAAQW,OAAO;QAACV;OAAM;AACnD,UAAIS,eAAeE,SAAS,GAAG;AAC7B,cAAMC,eAAeH,eAAe,CAAA;AACpC,gBAAII,2CAAeD,YAAAA,GAAe;AAEhCd,iBAAOc,aAAaE,UACjBC,IAAI,CAACC,SAASC,WAAW;YAAED;YAASC;UAAM,EAAA,EAG1CC,OACC,CAACC,MAAMC,SAAUR,aAAaL,kBAAkBa,MAAMH,KAAAA,MAAWT,yCAAoBI,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,kCAAAA;AACnD,YAAI3C,SAAS;AACX,iBAAOA;QACT;MACF;AACA,aAAO4C;IACT;EACF;AACA,SAAOtD;AACT,GAjHmC;","names":["StatefulDivinerSchema","StatefulDivinerConfigSchema","StatefulDivinerSchema","moduleName","StatefulDiviner","AbstractDiviner","configSchemas","DivinerConfigSchema","StatefulDivinerConfigSchema","_lastState","commitState","nextState","state","offset","archivist","getArchivistForStateStore","bw","BoundWitnessBuilder","payload","witness","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","import_assert","import_boundwitness_builder","import_boundwitness_model","import_diviner_boundwitness_model","import_diviner_model","import_module_model","import_payload_builder","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"]}