@xyo-network/diviner-indexing-memory 3.6.0-rc.4 → 3.6.0-rc.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.
@@ -39,17 +39,60 @@ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = Ind
39
39
  addToResolvers?: boolean;
40
40
  additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
41
41
  allowNameResolution?: boolean;
42
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
43
- parents?: import("@xyo-network/archivist-model").ArchivistParents;
44
- requireAllParents?: boolean;
45
- schema: "network.xyo.archivist.config";
46
- storage?: import("@xyo-network/archivist-model").ArchivistStorage;
47
- storeParentReads?: boolean;
48
- }, "schema"> & {
49
- schema: "network.xyo.archivist.config";
50
- }, "schema"> & {
51
- schema: string;
52
- };
42
+ config: import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
43
+ schema: Schema;
44
+ readonly archiving?: {
45
+ readonly archivists?: string[] | undefined;
46
+ readonly queries?: string[] | undefined;
47
+ } | undefined;
48
+ readonly allowedQueries?: string[] | undefined;
49
+ readonly archivist?: import("@xyo-network/module-model").ModuleIdentifier | undefined;
50
+ readonly certify?: boolean | undefined;
51
+ readonly consoleLogger?: import("@xylabs/logger").LogLevel | undefined;
52
+ readonly labels?: {
53
+ [x: string]: string | undefined;
54
+ } | undefined;
55
+ readonly name?: import("@xyo-network/module-model").ModuleName | undefined;
56
+ readonly paging?: {
57
+ [x: string]: {
58
+ size?: number | undefined;
59
+ };
60
+ } | undefined;
61
+ readonly retry?: {
62
+ backoff?: number | undefined;
63
+ interval?: number | undefined;
64
+ retries?: number | undefined;
65
+ } | undefined;
66
+ readonly security?: {
67
+ readonly allowAnonymous?: boolean | undefined;
68
+ readonly allowed?: {
69
+ [x: string]: (Lowercase<string> | Lowercase<string>[])[];
70
+ } | undefined;
71
+ readonly disallowed?: {
72
+ [x: string]: Lowercase<string>[];
73
+ } | undefined;
74
+ } | undefined;
75
+ readonly sign?: boolean | undefined;
76
+ readonly storeQueries?: boolean | undefined;
77
+ readonly timestamp?: boolean | undefined;
78
+ parents?: {
79
+ commit?: Lowercase<string>[] | undefined;
80
+ read?: Lowercase<string>[] | undefined;
81
+ write?: Lowercase<string>[] | undefined;
82
+ } | undefined;
83
+ requireAllParents?: boolean | undefined;
84
+ storage?: {
85
+ indexes?: {
86
+ key: {
87
+ [x: string]: import("@xyo-network/archivist-model").IndexDirection;
88
+ };
89
+ multiEntry?: boolean | undefined;
90
+ name?: string | undefined;
91
+ unique?: boolean | undefined;
92
+ }[] | undefined;
93
+ } | undefined;
94
+ storeParentReads?: boolean | undefined;
95
+ }>;
53
96
  ephemeralQueryAccountEnabled?: boolean;
54
97
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
55
98
  }, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
@@ -63,20 +106,50 @@ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = Ind
63
106
  addToResolvers?: boolean;
64
107
  additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
65
108
  allowNameResolution?: boolean;
66
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
67
- schema: "network.xyo.diviner.config";
68
- }, "schema"> & {
69
- schema: "network.xyo.diviner.config";
70
- }, "schema"> & {
71
- schema: string;
72
- };
109
+ config: import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
110
+ schema: Schema;
111
+ readonly archiving?: {
112
+ readonly archivists?: string[] | undefined;
113
+ readonly queries?: string[] | undefined;
114
+ } | undefined;
115
+ readonly allowedQueries?: string[] | undefined;
116
+ readonly archivist?: import("@xyo-network/module-model").ModuleIdentifier | undefined;
117
+ readonly certify?: boolean | undefined;
118
+ readonly consoleLogger?: import("@xylabs/logger").LogLevel | undefined;
119
+ readonly labels?: {
120
+ [x: string]: string | undefined;
121
+ } | undefined;
122
+ readonly name?: import("@xyo-network/module-model").ModuleName | undefined;
123
+ readonly paging?: {
124
+ [x: string]: {
125
+ size?: number | undefined;
126
+ };
127
+ } | undefined;
128
+ readonly retry?: {
129
+ backoff?: number | undefined;
130
+ interval?: number | undefined;
131
+ retries?: number | undefined;
132
+ } | undefined;
133
+ readonly security?: {
134
+ readonly allowAnonymous?: boolean | undefined;
135
+ readonly allowed?: {
136
+ [x: string]: (Lowercase<string> | Lowercase<string>[])[];
137
+ } | undefined;
138
+ readonly disallowed?: {
139
+ [x: string]: Lowercase<string>[];
140
+ } | undefined;
141
+ } | undefined;
142
+ readonly sign?: boolean | undefined;
143
+ readonly storeQueries?: boolean | undefined;
144
+ readonly timestamp?: boolean | undefined;
145
+ }>;
73
146
  ephemeralQueryAccountEnabled?: boolean;
74
147
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
75
- }, DivinerModuleEventData>, {
76
- schema: string;
77
- } & import("@xyo-network/payload-model").PayloadFields, {
78
- schema: string;
79
- } & import("@xyo-network/payload-model").PayloadFields>>;
148
+ }, DivinerModuleEventData>, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
149
+ schema: Schema;
150
+ }>, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
151
+ schema: Schema;
152
+ }>>>;
80
153
  /**
81
154
  * Gets the Diviner for the supplied Indexing Diviner stage
82
155
  * @param transform The Indexing Diviner stage
@@ -87,20 +160,50 @@ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = Ind
87
160
  addToResolvers?: boolean;
88
161
  additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
89
162
  allowNameResolution?: boolean;
90
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
91
- schema: "network.xyo.diviner.config";
92
- }, "schema"> & {
93
- schema: "network.xyo.diviner.config";
94
- }, "schema"> & {
95
- schema: string;
96
- };
163
+ config: import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
164
+ schema: Schema;
165
+ readonly archiving?: {
166
+ readonly archivists?: string[] | undefined;
167
+ readonly queries?: string[] | undefined;
168
+ } | undefined;
169
+ readonly allowedQueries?: string[] | undefined;
170
+ readonly archivist?: import("@xyo-network/module-model").ModuleIdentifier | undefined;
171
+ readonly certify?: boolean | undefined;
172
+ readonly consoleLogger?: import("@xylabs/logger").LogLevel | undefined;
173
+ readonly labels?: {
174
+ [x: string]: string | undefined;
175
+ } | undefined;
176
+ readonly name?: import("@xyo-network/module-model").ModuleName | undefined;
177
+ readonly paging?: {
178
+ [x: string]: {
179
+ size?: number | undefined;
180
+ };
181
+ } | undefined;
182
+ readonly retry?: {
183
+ backoff?: number | undefined;
184
+ interval?: number | undefined;
185
+ retries?: number | undefined;
186
+ } | undefined;
187
+ readonly security?: {
188
+ readonly allowAnonymous?: boolean | undefined;
189
+ readonly allowed?: {
190
+ [x: string]: (Lowercase<string> | Lowercase<string>[])[];
191
+ } | undefined;
192
+ readonly disallowed?: {
193
+ [x: string]: Lowercase<string>[];
194
+ } | undefined;
195
+ } | undefined;
196
+ readonly sign?: boolean | undefined;
197
+ readonly storeQueries?: boolean | undefined;
198
+ readonly timestamp?: boolean | undefined;
199
+ }>;
97
200
  ephemeralQueryAccountEnabled?: boolean;
98
201
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
99
- }, {
100
- schema: string;
101
- } & import("@xyo-network/payload-model").PayloadFields, {
102
- schema: string;
103
- } & import("@xyo-network/payload-model").PayloadFields, DivinerModuleEventData>>;
202
+ }, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
203
+ schema: Schema;
204
+ }>, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
205
+ schema: Schema;
206
+ }>, DivinerModuleEventData>>;
104
207
  /**
105
208
  * Retrieves the Payload Diviner for the specified store
106
209
  * @param store The store to retrieve the Payload Diviner for
@@ -111,20 +214,50 @@ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = Ind
111
214
  addToResolvers?: boolean;
112
215
  additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
113
216
  allowNameResolution?: boolean;
114
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & {
115
- schema: "network.xyo.diviner.config";
116
- }, "schema"> & {
117
- schema: "network.xyo.diviner.config";
118
- }, "schema"> & {
119
- schema: string;
120
- };
217
+ config: import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
218
+ schema: Schema;
219
+ readonly archiving?: {
220
+ readonly archivists?: string[] | undefined;
221
+ readonly queries?: string[] | undefined;
222
+ } | undefined;
223
+ readonly allowedQueries?: string[] | undefined;
224
+ readonly archivist?: import("@xyo-network/module-model").ModuleIdentifier | undefined;
225
+ readonly certify?: boolean | undefined;
226
+ readonly consoleLogger?: import("@xylabs/logger").LogLevel | undefined;
227
+ readonly labels?: {
228
+ [x: string]: string | undefined;
229
+ } | undefined;
230
+ readonly name?: import("@xyo-network/module-model").ModuleName | undefined;
231
+ readonly paging?: {
232
+ [x: string]: {
233
+ size?: number | undefined;
234
+ };
235
+ } | undefined;
236
+ readonly retry?: {
237
+ backoff?: number | undefined;
238
+ interval?: number | undefined;
239
+ retries?: number | undefined;
240
+ } | undefined;
241
+ readonly security?: {
242
+ readonly allowAnonymous?: boolean | undefined;
243
+ readonly allowed?: {
244
+ [x: string]: (Lowercase<string> | Lowercase<string>[])[];
245
+ } | undefined;
246
+ readonly disallowed?: {
247
+ [x: string]: Lowercase<string>[];
248
+ } | undefined;
249
+ } | undefined;
250
+ readonly sign?: boolean | undefined;
251
+ readonly storeQueries?: boolean | undefined;
252
+ readonly timestamp?: boolean | undefined;
253
+ }>;
121
254
  ephemeralQueryAccountEnabled?: boolean;
122
255
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
123
- }, DivinerModuleEventData>, {
124
- schema: string;
125
- } & import("@xyo-network/payload-model").PayloadFields, {
126
- schema: string;
127
- } & import("@xyo-network/payload-model").PayloadFields>>;
256
+ }, DivinerModuleEventData>, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
257
+ schema: Schema;
258
+ }>, import("@xyo-network/payload-model").DeepRestrictToStringKeys<{
259
+ schema: Schema;
260
+ }>>>;
128
261
  /**
129
262
  * Retrieves the last state of the Diviner process. Used to recover state after
130
263
  * preemptions, reboots, etc.
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EACL,qBAAqB,EAErB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EACc,eAAe,EAAE,sBAAsB,EAC3D,MA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yB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAM5D;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;cA0C9D,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;cAMhC,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrF;;;OAGG;IACH,OAAO,CAAC,IAAI;CAcb"}
@@ -14,7 +14,7 @@ import { asDivinerInstance } from "@xyo-network/diviner-model";
14
14
  import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
15
15
  import { creatableModule, isModuleState, ModuleStateSchema } from "@xyo-network/module-model";
16
16
  import { PayloadBuilder } from "@xyo-network/payload-builder";
17
- import { StorageMetaConstants } from "@xyo-network/payload-model";
17
+ import { SequenceConstants } from "@xyo-network/payload-model";
18
18
  function _ts_decorate(decorators, target, key, desc) {
19
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -149,7 +149,7 @@ var IndexingDiviner = class extends AbstractDiviner {
149
149
  }).fields({
150
150
  address: accountAddress,
151
151
  limit: 1,
152
- cursor: StorageMetaConstants.minLocalSequence,
152
+ cursor: SequenceConstants.minLocalSequence,
153
153
  order: "desc",
154
154
  payload_schemas: [
155
155
  ModuleStateSchema
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'\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 {\n IndexingDivinerConfig,\n IndexingDivinerConfigSchema,\n IndexingDivinerParams,\n IndexingDivinerStage,\n IndexingDivinerState,\n} from '@xyo-network/diviner-indexing-model'\nimport {\n asDivinerInstance, DivinerInstance, DivinerModuleEventData,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport {\n creatableModule, isModuleState, ModuleState, ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, StorageMetaConstants, WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nexport type ConfigStoreKey = 'indexStore' | 'stateStore'\n\nexport type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>\n\nconst moduleName = 'IndexingDiviner'\n\n@creatableModule<IndexingDiviner>()\nexport class IndexingDiviner<\n TParams extends IndexingDivinerParams = IndexingDivinerParams,\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> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly allowRandomAccount = false\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexingDivinerConfigSchema\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string\n\n get payloadDivinerLimit() {\n return this.config.payloadDivinerLimit ?? 1000\n }\n\n get pollFrequency() {\n return this.config.pollFrequency ?? 10_000\n }\n\n /**\n * Works via batched iteration of the source archivist to populate the index.\n * @returns A promise that resolves when the background process is complete\n */\n protected backgroundDivine = async (): Promise<void> => {\n // Load last state\n const lastState = await this.retrieveState()\n // Get next batch of results\n const indexCandidateDiviner = await this.getIndexingDivinerStage('stateToIndexCandidateDiviner')\n const results = lastState ? await indexCandidateDiviner.divine([lastState]) : await indexCandidateDiviner.divine()\n // Filter next state out from results\n const nextState = results.find(isModuleState<IndexingDivinerState>)\n const indexCandidates = results.filter(x => !isModuleState(x))\n // Transform candidates to indexes\n const toIndexTransformDiviner = await this.getIndexingDivinerStage('indexCandidateToIndexDiviner')\n const indexes = await toIndexTransformDiviner.divine(indexCandidates)\n // Insert index results\n const indexArchivist = await this.getArchivistForStore('indexStore')\n await indexArchivist.insert(indexes)\n // Update state\n if (nextState) {\n await this.commitState(nextState)\n }\n }\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<IndexingDivinerState>) {\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('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const indexPayloadDiviner = await this.getPayloadDivinerForStore('indexStore')\n const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage('divinerQueryToIndexQueryDiviner')\n const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage('indexQueryResponseToDivinerQueryResponseDiviner')\n const results = (\n await Promise.all(\n payloads.map(async (payload) => {\n const indexQuery = await divinerQueryToIndexQueryDiviner.divine([payload])\n // Divine the results\n const indexedResults = await indexPayloadDiviner.divine(indexQuery)\n // Transform the results to the response shape\n const response = await Promise.all(\n indexedResults.flat().map(indexedResult => indexQueryResponseToDivinerQueryResponseDiviner.divine([payload, indexedResult])),\n )\n return response.flat()\n }),\n )\n ).flat()\n // TODO: Infer this type over casting to this type\n return results as TOut[]\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 getArchivistForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist [${name}]`)\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 getBoundWitnessDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner [${name}]`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Gets the Diviner for the supplied Indexing Diviner stage\n * @param transform The Indexing Diviner stage\n * @returns The diviner corresponding to the Indexing Diviner stage\n */\n protected async getIndexingDivinerStage(transform: IndexingDivinerStage) {\n const nameOrAddress = assertEx(\n this.config?.indexingDivinerStages?.[transform],\n () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`,\n )\n const mod = await this.resolve(nameOrAddress)\n return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`) as DivinerInstance\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 getPayloadDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner [${name}]`)\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<IndexingDivinerState> | undefined> {\n const accountAddress = this.account.address\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: accountAddress,\n limit: 1,\n cursor: StorageMetaConstants.minLocalSequence,\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 === accountAddress)\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('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload as WithStorageMeta<ModuleState<IndexingDivinerState>>\n }\n }\n return undefined\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n this.poll()\n return true\n }\n\n protected override async stopHandler(_timeout?: number | undefined): Promise<boolean> {\n if (this._pollId) {\n clearTimeout(this._pollId)\n this._pollId = undefined\n }\n return await super.stopHandler()\n }\n\n /**\n * Runs the background divine process on a loop with a delay\n * specified by the `config.pollFrequency`\n */\n private poll() {\n this._pollId = setTimeoutEx(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\n if (this._pollId) clearTimeoutEx(this._pollId)\n this._pollId = undefined\n this.poll()\n }\n }, this.pollFr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KAAKlG,OAAO;AAC7C,aAAKA,UAAUwF;AACf,aAAKE,KAAI;MACX;IACF,GAAG,KAAKvF,aAAa;EACvB;AACF;;;;","names":["assertEx","clearTimeoutEx","setTimeoutEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","IndexingDivinerConfigSchema","asDivinerInstance","DivinerWrapper","creatableModule","isModuleState","ModuleStateSchema","PayloadBuilder","StorageMetaConstants","moduleName","IndexingDiviner","AbstractDiviner","allowRandomAccount","configSchemas","IndexingDivinerConfigSchema","defaultConfigSchema","_lastState","_pollId","payloadDivinerLimit","config","pollFrequency","backgroundDivine","lastState","retrieveState","indexCandidateDiviner","getIndexingDivinerStage","results","divine","nextState","find","isModuleState","indexCandidates","filter","x","toIndexTransformDiviner","indexes","indexArchivist","getArchivistForStore","insert","commitState","state","offset","archivist","bw","BoundWitnessBuilder","payload","signer","account","build","divineHandler","payloads","indexPayloadDiviner","getPayloadDivinerForStore","divinerQueryToIndexQueryDiviner","indexQueryResponseToDivinerQueryResponseDiviner","Promise","all","map","indexQuery","indexedResults","response","flat","indexedResult","store","name","assertEx","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStore","boundWitnessDiviner","DivinerWrapper","transform","nameOrAddress","indexingDivinerStages","asDivinerInstance","payloadDiviner","accountAddress","address","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","cursor","StorageMetaConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","length","boundWitness","isBoundWitness","addresses","index","reduce","prev","curr","payload_hashes","get","undefined","startHandler","poll","stopHandler","_timeout","clearTimeout","setTimeoutEx","e","console","log","clearTimeoutEx"]}
1
+ {"version":3,"sources":["../../src/Diviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { Hash } from '@xylabs/hex'\nimport { clearTimeoutEx, setTimeoutEx } from '@xylabs/timer'\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 {\n IndexingDivinerConfig,\n IndexingDivinerConfigSchema,\n IndexingDivinerParams,\n IndexingDivinerStage,\n IndexingDivinerState,\n} from '@xyo-network/diviner-indexing-model'\nimport {\n asDivinerInstance, DivinerInstance, DivinerModuleEventData,\n} from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport {\n creatableModule, isModuleState, ModuleState, ModuleStateSchema,\n} from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport {\n Payload, Schema, SequenceConstants, WithStorageMeta,\n} from '@xyo-network/payload-model'\n\nexport type ConfigStoreKey = 'indexStore' | 'stateStore'\n\nexport type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>\n\nconst moduleName = 'IndexingDiviner'\n\n@creatableModule<IndexingDiviner>()\nexport class IndexingDiviner<\n TParams extends IndexingDivinerParams = IndexingDivinerParams,\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> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly allowRandomAccount = false\n static override readonly configSchemas: Schema[] = [...super.configSchemas, IndexingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = IndexingDivinerConfigSchema\n\n private _lastState?: ModuleState<IndexingDivinerState>\n private _pollId?: string\n\n get payloadDivinerLimit() {\n return this.config.payloadDivinerLimit ?? 1000\n }\n\n get pollFrequency() {\n return this.config.pollFrequency ?? 10_000\n }\n\n /**\n * Works via batched iteration of the source archivist to populate the index.\n * @returns A promise that resolves when the background process is complete\n */\n protected backgroundDivine = async (): Promise<void> => {\n // Load last state\n const lastState = await this.retrieveState()\n // Get next batch of results\n const indexCandidateDiviner = await this.getIndexingDivinerStage('stateToIndexCandidateDiviner')\n const results = lastState ? await indexCandidateDiviner.divine([lastState]) : await indexCandidateDiviner.divine()\n // Filter next state out from results\n const nextState = results.find(isModuleState<IndexingDivinerState>)\n const indexCandidates = results.filter(x => !isModuleState(x))\n // Transform candidates to indexes\n const toIndexTransformDiviner = await this.getIndexingDivinerStage('indexCandidateToIndexDiviner')\n const indexes = await toIndexTransformDiviner.divine(indexCandidates)\n // Insert index results\n const indexArchivist = await this.getArchivistForStore('indexStore')\n await indexArchivist.insert(indexes)\n // Update state\n if (nextState) {\n await this.commitState(nextState)\n }\n }\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<IndexingDivinerState>) {\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('stateStore')\n const [bw] = await new BoundWitnessBuilder().payload(nextState).signer(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const indexPayloadDiviner = await this.getPayloadDivinerForStore('indexStore')\n const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage('divinerQueryToIndexQueryDiviner')\n const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage('indexQueryResponseToDivinerQueryResponseDiviner')\n const results = (\n await Promise.all(\n payloads.map(async (payload) => {\n const indexQuery = await divinerQueryToIndexQueryDiviner.divine([payload])\n // Divine the results\n const indexedResults = await indexPayloadDiviner.divine(indexQuery)\n // Transform the results to the response shape\n const response = await Promise.all(\n indexedResults.flat().map(indexedResult => indexQueryResponseToDivinerQueryResponseDiviner.divine([payload, indexedResult])),\n )\n return response.flat()\n }),\n )\n ).flat()\n // TODO: Infer this type over casting to this type\n return results as TOut[]\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 getArchivistForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist [${name}]`)\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 getBoundWitnessDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner [${name}]`)\n return DivinerWrapper.wrap(mod, this.account)\n }\n\n /**\n * Gets the Diviner for the supplied Indexing Diviner stage\n * @param transform The Indexing Diviner stage\n * @returns The diviner corresponding to the Indexing Diviner stage\n */\n protected async getIndexingDivinerStage(transform: IndexingDivinerStage) {\n const nameOrAddress = assertEx(\n this.config?.indexingDivinerStages?.[transform],\n () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`,\n )\n const mod = await this.resolve(nameOrAddress)\n return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`) as DivinerInstance\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 getPayloadDivinerForStore(store: ConfigStore) {\n const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`)\n const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner [${name}]`)\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<IndexingDivinerState> | undefined> {\n const accountAddress = this.account.address\n if (this._lastState) return this._lastState\n let hash: Hash = ''\n const diviner = await this.getBoundWitnessDivinerForStore('stateStore')\n const query = await new PayloadBuilder<BoundWitnessDivinerQueryPayload>({ schema: BoundWitnessDivinerQuerySchema })\n .fields({\n address: accountAddress,\n limit: 1,\n cursor: SequenceConstants.minLocalSequence,\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 === accountAddress)\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('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload as WithStorageMeta<ModuleState<IndexingDivinerState>>\n }\n }\n return undefined\n }\n\n protected override async startHandler(): Promise<boolean> {\n await super.startHandler()\n this.poll()\n return true\n }\n\n protected override async stopHandler(_timeout?: number | undefined): Promise<boolean> {\n if (this._pollId) {\n clearTimeout(this._pollId)\n this._pollId = undefined\n }\n return await super.stopHandler()\n }\n\n /**\n * Runs the background divine process on a loop with a delay\n * specified by the `config.pollFrequency`\n */\n private poll() {\n this._pollId = setTimeoutEx(async () => {\n try {\n await Promise.resolve()\n await this.backgroundDivine()\n } catch (e) {\n console.log(e)\n } finally {\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gBAAQC,IAAIF,CAAAA;MACd,UAAA;AACE,YAAI,KAAK/F,QAASkG,gBAAe,KAAKlG,OAAO;AAC7C,aAAKA,UAAUwF;AACf,aAAKE,KAAI;MACX;IACF,GAAG,KAAKvF,aAAa;EACvB;AACF;;;;","names":["assertEx","clearTimeoutEx","setTimeoutEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","IndexingDivinerConfigSchema","asDivinerInstance","DivinerWrapper","creatableModule","isModuleState","ModuleStateSchema","PayloadBuilder","SequenceConstants","moduleName","IndexingDiviner","AbstractDiviner","allowRandomAccount","configSchemas","IndexingDivinerConfigSchema","defaultConfigSchema","_lastState","_pollId","payloadDivinerLimit","config","pollFrequency","backgroundDivine","lastState","retrieveState","indexCandidateDiviner","getIndexingDivinerStage","results","divine","nextState","find","isModuleState","indexCandidates","filter","x","toIndexTransformDiviner","indexes","indexArchivist","getArchivistForStore","insert","commitState","state","offset","archivist","bw","BoundWitnessBuilder","payload","signer","account","build","divineHandler","payloads","indexPayloadDiviner","getPayloadDivinerForStore","divinerQueryToIndexQueryDiviner","indexQueryResponseToDivinerQueryResponseDiviner","Promise","all","map","indexQuery","indexedResults","response","flat","indexedResult","store","name","assertEx","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStore","boundWitnessDiviner","DivinerWrapper","transform","nameOrAddress","indexingDivinerStages","asDivinerInstance","payloadDiviner","accountAddress","address","hash","diviner","query","PayloadBuilder","schema","BoundWitnessDivinerQuerySchema","fields","limit","cursor","SequenceConstants","minLocalSequence","order","payload_schemas","ModuleStateSchema","boundWitnesses","length","boundWitness","isBoundWitness","addresses","index","reduce","prev","curr","payload_hashes","get","undefined","startHandler","poll","stopHandler","_timeout","clearTimeout","setTimeoutEx","e","console","log","clearTimeoutEx"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-indexing-memory",
3
- "version": "3.6.0-rc.4",
3
+ "version": "3.6.0-rc.6",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,20 +29,20 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.4.13",
33
- "@xylabs/hex": "^4.4.13",
34
- "@xylabs/timer": "^4.4.13",
35
- "@xyo-network/archivist-wrapper": "^3.6.0-rc.4",
36
- "@xyo-network/boundwitness-builder": "^3.6.0-rc.4",
37
- "@xyo-network/boundwitness-model": "^3.6.0-rc.4",
38
- "@xyo-network/diviner-abstract": "^3.6.0-rc.4",
39
- "@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.4",
40
- "@xyo-network/diviner-indexing-model": "^3.6.0-rc.4",
41
- "@xyo-network/diviner-model": "^3.6.0-rc.4",
42
- "@xyo-network/diviner-wrapper": "^3.6.0-rc.4",
43
- "@xyo-network/module-model": "^3.6.0-rc.4",
44
- "@xyo-network/payload-builder": "^3.6.0-rc.4",
45
- "@xyo-network/payload-model": "^3.6.0-rc.4"
32
+ "@xylabs/assert": "^4.4.15",
33
+ "@xylabs/hex": "^4.4.15",
34
+ "@xylabs/timer": "^4.4.15",
35
+ "@xyo-network/archivist-wrapper": "^3.6.0-rc.6",
36
+ "@xyo-network/boundwitness-builder": "^3.6.0-rc.6",
37
+ "@xyo-network/boundwitness-model": "^3.6.0-rc.6",
38
+ "@xyo-network/diviner-abstract": "^3.6.0-rc.6",
39
+ "@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.6",
40
+ "@xyo-network/diviner-indexing-model": "^3.6.0-rc.6",
41
+ "@xyo-network/diviner-model": "^3.6.0-rc.6",
42
+ "@xyo-network/diviner-wrapper": "^3.6.0-rc.6",
43
+ "@xyo-network/module-model": "^3.6.0-rc.6",
44
+ "@xyo-network/payload-builder": "^3.6.0-rc.6",
45
+ "@xyo-network/payload-model": "^3.6.0-rc.6"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
package/src/Diviner.ts CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from '@xyo-network/module-model'
23
23
  import { PayloadBuilder } from '@xyo-network/payload-builder'
24
24
  import {
25
- Payload, Schema, StorageMetaConstants, WithStorageMeta,
25
+ Payload, Schema, SequenceConstants, WithStorageMeta,
26
26
  } from '@xyo-network/payload-model'
27
27
 
28
28
  export type ConfigStoreKey = 'indexStore' | 'stateStore'
@@ -180,7 +180,7 @@ export class IndexingDiviner<
180
180
  .fields({
181
181
  address: accountAddress,
182
182
  limit: 1,
183
- cursor: StorageMetaConstants.minLocalSequence,
183
+ cursor: SequenceConstants.minLocalSequence,
184
184
  order: 'desc',
185
185
  payload_schemas: [ModuleStateSchema],
186
186
  })