@xyo-network/diviner-indexing-memory 2.99.2 → 2.99.3

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.
@@ -0,0 +1,136 @@
1
+ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
2
+ import { AbstractDiviner } from '@xyo-network/diviner-abstract';
3
+ import { IndexingDivinerConfig, IndexingDivinerParams, IndexingDivinerStage, IndexingDivinerState } from '@xyo-network/diviner-indexing-model';
4
+ import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
5
+ import { DivinerWrapper } from '@xyo-network/diviner-wrapper';
6
+ import { ModuleState } from '@xyo-network/module-model';
7
+ import { Payload, Schema, WithMeta } from '@xyo-network/payload-model';
8
+ export type ConfigStoreKey = 'indexStore' | 'stateStore';
9
+ export type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>;
10
+ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = IndexingDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
11
+ static readonly allowRandomAccount = false;
12
+ static readonly configSchemas: Schema[];
13
+ static readonly defaultConfigSchema: Schema;
14
+ private _lastState?;
15
+ private _pollId?;
16
+ get payloadDivinerLimit(): number;
17
+ get pollFrequency(): number;
18
+ /**
19
+ * Works via batched iteration of the source archivist to populate the index.
20
+ * @returns A promise that resolves when the background process is complete
21
+ */
22
+ protected backgroundDivine: () => Promise<void>;
23
+ /**
24
+ * Commit the internal state of the Diviner process. This is similar
25
+ * to a transaction completion in a database and should only be called
26
+ * when results have been successfully persisted to the appropriate
27
+ * external stores.
28
+ * @param nextState The state to commit
29
+ */
30
+ protected commitState(nextState: ModuleState<IndexingDivinerState>): Promise<void>;
31
+ protected divineHandler(payloads?: TIn[]): Promise<WithMeta<TOut>[]>;
32
+ /**
33
+ * Retrieves the archivist for the specified store
34
+ * @param store The store to retrieve the archivist for
35
+ * @returns The archivist for the specified store
36
+ */
37
+ protected getArchivistForStore(store: ConfigStore): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModule<import("@xylabs/object").BaseParamsFields & {
38
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
39
+ addToResolvers?: boolean | undefined;
40
+ allowNameResolution?: boolean | undefined;
41
+ 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 & {
42
+ parents?: import("@xyo-network/archivist-model").ArchivistParents | undefined;
43
+ requireAllParents?: boolean | undefined;
44
+ schema: "network.xyo.archivist.config";
45
+ storeParentReads?: boolean | undefined;
46
+ }, "schema"> & {
47
+ schema: "network.xyo.archivist.config";
48
+ }, "schema"> & {
49
+ schema: string;
50
+ };
51
+ ephemeralQueryAccountEnabled?: boolean | undefined;
52
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
53
+ }, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
54
+ /**
55
+ * Retrieves the BoundWitness Diviner for the specified store
56
+ * @param store The store to retrieve the BoundWitness Diviner for
57
+ * @returns The BoundWitness Diviner for the specified store
58
+ */
59
+ protected getBoundWitnessDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
60
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
61
+ addToResolvers?: boolean | undefined;
62
+ allowNameResolution?: boolean | undefined;
63
+ 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 & {
64
+ schema: "network.xyo.diviner.config";
65
+ }, "schema"> & {
66
+ schema: "network.xyo.diviner.config";
67
+ }, "schema"> & {
68
+ schema: string;
69
+ };
70
+ ephemeralQueryAccountEnabled?: boolean | undefined;
71
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
72
+ }, DivinerModuleEventData>, {
73
+ schema: string;
74
+ } & import("@xyo-network/payload-model").PayloadFields, {
75
+ schema: string;
76
+ } & import("@xyo-network/payload-model").PayloadFields>>;
77
+ /**
78
+ * Gets the Diviner for the supplied Indexing Diviner stage
79
+ * @param transform The Indexing Diviner stage
80
+ * @returns The diviner corresponding to the Indexing Diviner stage
81
+ */
82
+ protected getIndexingDivinerStage(transform: IndexingDivinerStage): Promise<DivinerInstance<import("@xylabs/object").BaseParamsFields & {
83
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
84
+ addToResolvers?: boolean | undefined;
85
+ allowNameResolution?: boolean | undefined;
86
+ 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 & {
87
+ schema: "network.xyo.diviner.config";
88
+ }, "schema"> & {
89
+ schema: "network.xyo.diviner.config";
90
+ }, "schema"> & {
91
+ schema: string;
92
+ };
93
+ ephemeralQueryAccountEnabled?: boolean | undefined;
94
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
95
+ }, {
96
+ schema: string;
97
+ } & import("@xyo-network/payload-model").PayloadFields, {
98
+ schema: string;
99
+ } & import("@xyo-network/payload-model").PayloadFields, DivinerModuleEventData>>;
100
+ /**
101
+ * Retrieves the Payload Diviner for the specified store
102
+ * @param store The store to retrieve the Payload Diviner for
103
+ * @returns The Payload Diviner for the specified store
104
+ */
105
+ protected getPayloadDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
106
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
107
+ addToResolvers?: boolean | undefined;
108
+ allowNameResolution?: boolean | undefined;
109
+ 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 & {
110
+ schema: "network.xyo.diviner.config";
111
+ }, "schema"> & {
112
+ schema: "network.xyo.diviner.config";
113
+ }, "schema"> & {
114
+ schema: string;
115
+ };
116
+ ephemeralQueryAccountEnabled?: boolean | undefined;
117
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
118
+ }, DivinerModuleEventData>, {
119
+ schema: string;
120
+ } & import("@xyo-network/payload-model").PayloadFields, {
121
+ schema: string;
122
+ } & import("@xyo-network/payload-model").PayloadFields>>;
123
+ /**
124
+ * Retrieves the last state of the Diviner process. Used to recover state after
125
+ * preemptions, reboots, etc.
126
+ */
127
+ protected retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined>;
128
+ protected startHandler(): Promise<boolean>;
129
+ protected stopHandler(_timeout?: number | undefined): Promise<boolean>;
130
+ /**
131
+ * Runs the background divine process on a loop with a delay
132
+ * specified by the `config.pollFrequ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xG,gBAAyB,mBAAmB,EAAE,MAAM,CAA8B;IAElF,OAAO,CAAC,UAAU,CAAC,CAAmC;IACtD,OAAO,CAAC,OAAO,CAAC,CAAQ;IAExB,IAAI,mBAAmB,WAEtB;IAED,IAAI,aAAa,WAEhB;IAED;;;OAGG;IACH,SAAS,CAAC,gBAAgB,QAAa,QAAQ,IAAI,CAAC,CAmBnD;IAED;;;;;;OAMG;cACa,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,oBAAoB,CAAC;cAS/C,aAAa,CAAC,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAsBvF;;;;OAIG;cACa,oBAAoB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;IAMvD;;;;OAIG;cACa,8BAA8B,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;IAMjE;;;;OAIG;cACa,uBAAuB,CAAC,SAAS,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;IASvE;;;;OAIG;cACa,yBAAyB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;IAM5D;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;cAyC9D,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"}
@@ -0,0 +1,136 @@
1
+ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
2
+ import { AbstractDiviner } from '@xyo-network/diviner-abstract';
3
+ import { IndexingDivinerConfig, IndexingDivinerParams, IndexingDivinerStage, IndexingDivinerState } from '@xyo-network/diviner-indexing-model';
4
+ import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
5
+ import { DivinerWrapper } from '@xyo-network/diviner-wrapper';
6
+ import { ModuleState } from '@xyo-network/module-model';
7
+ import { Payload, Schema, WithMeta } from '@xyo-network/payload-model';
8
+ export type ConfigStoreKey = 'indexStore' | 'stateStore';
9
+ export type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>;
10
+ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = IndexingDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
11
+ static readonly allowRandomAccount = false;
12
+ static readonly configSchemas: Schema[];
13
+ static readonly defaultConfigSchema: Schema;
14
+ private _lastState?;
15
+ private _pollId?;
16
+ get payloadDivinerLimit(): number;
17
+ get pollFrequency(): number;
18
+ /**
19
+ * Works via batched iteration of the source archivist to populate the index.
20
+ * @returns A promise that resolves when the background process is complete
21
+ */
22
+ protected backgroundDivine: () => Promise<void>;
23
+ /**
24
+ * Commit the internal state of the Diviner process. This is similar
25
+ * to a transaction completion in a database and should only be called
26
+ * when results have been successfully persisted to the appropriate
27
+ * external stores.
28
+ * @param nextState The state to commit
29
+ */
30
+ protected commitState(nextState: ModuleState<IndexingDivinerState>): Promise<void>;
31
+ protected divineHandler(payloads?: TIn[]): Promise<WithMeta<TOut>[]>;
32
+ /**
33
+ * Retrieves the archivist for the specified store
34
+ * @param store The store to retrieve the archivist for
35
+ * @returns The archivist for the specified store
36
+ */
37
+ protected getArchivistForStore(store: ConfigStore): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModule<import("@xylabs/object").BaseParamsFields & {
38
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
39
+ addToResolvers?: boolean | undefined;
40
+ allowNameResolution?: boolean | undefined;
41
+ 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 & {
42
+ parents?: import("@xyo-network/archivist-model").ArchivistParents | undefined;
43
+ requireAllParents?: boolean | undefined;
44
+ schema: "network.xyo.archivist.config";
45
+ storeParentReads?: boolean | undefined;
46
+ }, "schema"> & {
47
+ schema: "network.xyo.archivist.config";
48
+ }, "schema"> & {
49
+ schema: string;
50
+ };
51
+ ephemeralQueryAccountEnabled?: boolean | undefined;
52
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
53
+ }, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
54
+ /**
55
+ * Retrieves the BoundWitness Diviner for the specified store
56
+ * @param store The store to retrieve the BoundWitness Diviner for
57
+ * @returns The BoundWitness Diviner for the specified store
58
+ */
59
+ protected getBoundWitnessDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
60
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
61
+ addToResolvers?: boolean | undefined;
62
+ allowNameResolution?: boolean | undefined;
63
+ 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 & {
64
+ schema: "network.xyo.diviner.config";
65
+ }, "schema"> & {
66
+ schema: "network.xyo.diviner.config";
67
+ }, "schema"> & {
68
+ schema: string;
69
+ };
70
+ ephemeralQueryAccountEnabled?: boolean | undefined;
71
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
72
+ }, DivinerModuleEventData>, {
73
+ schema: string;
74
+ } & import("@xyo-network/payload-model").PayloadFields, {
75
+ schema: string;
76
+ } & import("@xyo-network/payload-model").PayloadFields>>;
77
+ /**
78
+ * Gets the Diviner for the supplied Indexing Diviner stage
79
+ * @param transform The Indexing Diviner stage
80
+ * @returns The diviner corresponding to the Indexing Diviner stage
81
+ */
82
+ protected getIndexingDivinerStage(transform: IndexingDivinerStage): Promise<DivinerInstance<import("@xylabs/object").BaseParamsFields & {
83
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
84
+ addToResolvers?: boolean | undefined;
85
+ allowNameResolution?: boolean | undefined;
86
+ 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 & {
87
+ schema: "network.xyo.diviner.config";
88
+ }, "schema"> & {
89
+ schema: "network.xyo.diviner.config";
90
+ }, "schema"> & {
91
+ schema: string;
92
+ };
93
+ ephemeralQueryAccountEnabled?: boolean | undefined;
94
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
95
+ }, {
96
+ schema: string;
97
+ } & import("@xyo-network/payload-model").PayloadFields, {
98
+ schema: string;
99
+ } & import("@xyo-network/payload-model").PayloadFields, DivinerModuleEventData>>;
100
+ /**
101
+ * Retrieves the Payload Diviner for the specified store
102
+ * @param store The store to retrieve the Payload Diviner for
103
+ * @returns The Payload Diviner for the specified store
104
+ */
105
+ protected getPayloadDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
106
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
107
+ addToResolvers?: boolean | undefined;
108
+ allowNameResolution?: boolean | undefined;
109
+ 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 & {
110
+ schema: "network.xyo.diviner.config";
111
+ }, "schema"> & {
112
+ schema: "network.xyo.diviner.config";
113
+ }, "schema"> & {
114
+ schema: string;
115
+ };
116
+ ephemeralQueryAccountEnabled?: boolean | undefined;
117
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
118
+ }, DivinerModuleEventData>, {
119
+ schema: string;
120
+ } & import("@xyo-network/payload-model").PayloadFields, {
121
+ schema: string;
122
+ } & import("@xyo-network/payload-model").PayloadFields>>;
123
+ /**
124
+ * Retrieves the last state of the Diviner process. Used to recover state after
125
+ * preemptions, reboots, etc.
126
+ */
127
+ protected retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined>;
128
+ protected startHandler(): Promise<boolean>;
129
+ protected stopHandler(_timeout?: number | undefined): Promise<boolean>;
130
+ /**
131
+ * Runs the background divine process on a loop with a delay
132
+ * specified by the `config.pollFrequency`
133
+ */
134
+ private poll;
135
+ }
136
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +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,EAAqB,eAA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Q,CAAC,IAAI,CAAC,EAAE,CAAC;IAsBvF;;;;OAIG;cACa,oBAAoB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;IAMvD;;;;OAIG;cACa,8BAA8B,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;IAMjE;;;;OAIG;cACa,uBAAuB,CAAC,SAAS,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;IASvE;;;;OAIG;cACa,yBAAyB,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;;;;;;IAM5D;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;cAyC9D,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"}
@@ -0,0 +1,136 @@
1
+ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
2
+ import { AbstractDiviner } from '@xyo-network/diviner-abstract';
3
+ import { IndexingDivinerConfig, IndexingDivinerParams, IndexingDivinerStage, IndexingDivinerState } from '@xyo-network/diviner-indexing-model';
4
+ import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
5
+ import { DivinerWrapper } from '@xyo-network/diviner-wrapper';
6
+ import { ModuleState } from '@xyo-network/module-model';
7
+ import { Payload, Schema, WithMeta } from '@xyo-network/payload-model';
8
+ export type ConfigStoreKey = 'indexStore' | 'stateStore';
9
+ export type ConfigStore = Extract<keyof IndexingDivinerConfig, ConfigStoreKey>;
10
+ export declare class IndexingDiviner<TParams extends IndexingDivinerParams = IndexingDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
11
+ static readonly allowRandomAccount = false;
12
+ static readonly configSchemas: Schema[];
13
+ static readonly defaultConfigSchema: Schema;
14
+ private _lastState?;
15
+ private _pollId?;
16
+ get payloadDivinerLimit(): number;
17
+ get pollFrequency(): number;
18
+ /**
19
+ * Works via batched iteration of the source archivist to populate the index.
20
+ * @returns A promise that resolves when the background process is complete
21
+ */
22
+ protected backgroundDivine: () => Promise<void>;
23
+ /**
24
+ * Commit the internal state of the Diviner process. This is similar
25
+ * to a transaction completion in a database and should only be called
26
+ * when results have been successfully persisted to the appropriate
27
+ * external stores.
28
+ * @param nextState The state to commit
29
+ */
30
+ protected commitState(nextState: ModuleState<IndexingDivinerState>): Promise<void>;
31
+ protected divineHandler(payloads?: TIn[]): Promise<WithMeta<TOut>[]>;
32
+ /**
33
+ * Retrieves the archivist for the specified store
34
+ * @param store The store to retrieve the archivist for
35
+ * @returns The archivist for the specified store
36
+ */
37
+ protected getArchivistForStore(store: ConfigStore): Promise<ArchivistWrapper<import("@xyo-network/archivist-model").ArchivistModule<import("@xylabs/object").BaseParamsFields & {
38
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
39
+ addToResolvers?: boolean | undefined;
40
+ allowNameResolution?: boolean | undefined;
41
+ 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 & {
42
+ parents?: import("@xyo-network/archivist-model").ArchivistParents | undefined;
43
+ requireAllParents?: boolean | undefined;
44
+ schema: "network.xyo.archivist.config";
45
+ storeParentReads?: boolean | undefined;
46
+ }, "schema"> & {
47
+ schema: "network.xyo.archivist.config";
48
+ }, "schema"> & {
49
+ schema: string;
50
+ };
51
+ ephemeralQueryAccountEnabled?: boolean | undefined;
52
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
53
+ }, import("@xyo-network/archivist-model").ArchivistModuleEventData>>>;
54
+ /**
55
+ * Retrieves the BoundWitness Diviner for the specified store
56
+ * @param store The store to retrieve the BoundWitness Diviner for
57
+ * @returns The BoundWitness Diviner for the specified store
58
+ */
59
+ protected getBoundWitnessDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
60
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
61
+ addToResolvers?: boolean | undefined;
62
+ allowNameResolution?: boolean | undefined;
63
+ 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 & {
64
+ schema: "network.xyo.diviner.config";
65
+ }, "schema"> & {
66
+ schema: "network.xyo.diviner.config";
67
+ }, "schema"> & {
68
+ schema: string;
69
+ };
70
+ ephemeralQueryAccountEnabled?: boolean | undefined;
71
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
72
+ }, DivinerModuleEventData>, {
73
+ schema: string;
74
+ } & import("@xyo-network/payload-model").PayloadFields, {
75
+ schema: string;
76
+ } & import("@xyo-network/payload-model").PayloadFields>>;
77
+ /**
78
+ * Gets the Diviner for the supplied Indexing Diviner stage
79
+ * @param transform The Indexing Diviner stage
80
+ * @returns The diviner corresponding to the Indexing Diviner stage
81
+ */
82
+ protected getIndexingDivinerStage(transform: IndexingDivinerStage): Promise<DivinerInstance<import("@xylabs/object").BaseParamsFields & {
83
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
84
+ addToResolvers?: boolean | undefined;
85
+ allowNameResolution?: boolean | undefined;
86
+ 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 & {
87
+ schema: "network.xyo.diviner.config";
88
+ }, "schema"> & {
89
+ schema: "network.xyo.diviner.config";
90
+ }, "schema"> & {
91
+ schema: string;
92
+ };
93
+ ephemeralQueryAccountEnabled?: boolean | undefined;
94
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
95
+ }, {
96
+ schema: string;
97
+ } & import("@xyo-network/payload-model").PayloadFields, {
98
+ schema: string;
99
+ } & import("@xyo-network/payload-model").PayloadFields, DivinerModuleEventData>>;
100
+ /**
101
+ * Retrieves the Payload Diviner for the specified store
102
+ * @param store The store to retrieve the Payload Diviner for
103
+ * @returns The Payload Diviner for the specified store
104
+ */
105
+ protected getPayloadDivinerForStore(store: ConfigStore): Promise<DivinerWrapper<import("@xyo-network/diviner-model").DivinerModule<import("@xylabs/object").BaseParamsFields & {
106
+ account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
107
+ addToResolvers?: boolean | undefined;
108
+ allowNameResolution?: boolean | undefined;
109
+ 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 & {
110
+ schema: "network.xyo.diviner.config";
111
+ }, "schema"> & {
112
+ schema: "network.xyo.diviner.config";
113
+ }, "schema"> & {
114
+ schema: string;
115
+ };
116
+ ephemeralQueryAccountEnabled?: boolean | undefined;
117
+ moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[] | undefined;
118
+ }, DivinerModuleEventData>, {
119
+ schema: string;
120
+ } & import("@xyo-network/payload-model").PayloadFields, {
121
+ schema: string;
122
+ } & import("@xyo-network/payload-model").PayloadFields>>;
123
+ /**
124
+ * Retrieves the last state of the Diviner process. Used to recover state after
125
+ * preemptions, reboots, etc.
126
+ */
127
+ protected retrieveState(): Promise<ModuleState<IndexingDivinerState> | undefined>;
128
+ protected startHandler(): Promise<boolean>;
129
+ protected stopHandler(_timeout?: number | undefined): Promise<boolean>;
130
+ /**
131
+ * Runs the background divine process on a loop with a delay
132
+ * specified by the `config.pollFrequency`
133
+ */
134
+ private poll;
135
+ }
136
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +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,EAAqB,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAyD,WAAW,EAAqB,MAAM,2BAA2B,CAAA;AAEjI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAEtE,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,qBAAqB,EAAE,cAAc,CAAC,CAAA;AAI9E,qBACa,eA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,WAAW,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;cAyC9D,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"}
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ IndexingDiviner: () => IndexingDiviner
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/Diviner.ts
29
+ var import_assert = require("@xylabs/assert");
30
+ var import_timer = require("@xylabs/timer");
31
+ var import_archivist_wrapper = require("@xyo-network/archivist-wrapper");
32
+ var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
33
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
34
+ var import_diviner_abstract = require("@xyo-network/diviner-abstract");
35
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
36
+ var import_diviner_indexing_model = require("@xyo-network/diviner-indexing-model");
37
+ var import_diviner_model = require("@xyo-network/diviner-model");
38
+ var import_diviner_wrapper = require("@xyo-network/diviner-wrapper");
39
+ var import_module_model = require("@xyo-network/module-model");
40
+ var import_payload_builder = require("@xyo-network/payload-builder");
41
+ function _ts_decorate(decorators, target, key, desc) {
42
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
43
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
44
+ r = Reflect.decorate(decorators, target, key, desc);
45
+ else
46
+ for (var i = decorators.length - 1; i >= 0; i--)
47
+ if (d = decorators[i])
48
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
49
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
50
+ }
51
+ __name(_ts_decorate, "_ts_decorate");
52
+ var moduleName = "IndexingDiviner";
53
+ var IndexingDiviner = class extends import_diviner_abstract.AbstractDiviner {
54
+ static {
55
+ __name(this, "IndexingDiviner");
56
+ }
57
+ static allowRandomAccount = false;
58
+ static configSchemas = [
59
+ ...super.configSchemas,
60
+ import_diviner_indexing_model.IndexingDivinerConfigSchema
61
+ ];
62
+ static defaultConfigSchema = import_diviner_indexing_model.IndexingDivinerConfigSchema;
63
+ _lastState;
64
+ _pollId;
65
+ get payloadDivinerLimit() {
66
+ return this.config.payloadDivinerLimit ?? 1e3;
67
+ }
68
+ get pollFrequency() {
69
+ return this.config.pollFrequency ?? 1e4;
70
+ }
71
+ /**
72
+ * Works via batched iteration of the source archivist to populate the index.
73
+ * @returns A promise that resolves when the background process is complete
74
+ */
75
+ backgroundDivine = async () => {
76
+ const lastState = await this.retrieveState();
77
+ const indexCandidateDiviner = await this.getIndexingDivinerStage("stateToIndexCandidateDiviner");
78
+ const results = lastState ? await indexCandidateDiviner.divine([
79
+ lastState
80
+ ]) : await indexCandidateDiviner.divine();
81
+ const nextState = results.find(import_module_model.isModuleStateWithMeta);
82
+ const indexCandidates = results.filter((x) => !(0, import_module_model.isModuleStateWithMeta)(x));
83
+ const toIndexTransformDiviner = await this.getIndexingDivinerStage("indexCandidateToIndexDiviner");
84
+ const indexes = await toIndexTransformDiviner.divine(indexCandidates);
85
+ const indexArchivist = await this.getArchivistForStore("indexStore");
86
+ await indexArchivist.insert(indexes);
87
+ if (nextState) {
88
+ await this.commitState(nextState);
89
+ }
90
+ };
91
+ /**
92
+ * Commit the internal state of the Diviner process. This is similar
93
+ * to a transaction completion in a database and should only be called
94
+ * when results have been successfully persisted to the appropriate
95
+ * external stores.
96
+ * @param nextState The state to commit
97
+ */
98
+ async commitState(nextState) {
99
+ if (nextState.state.offset === this._lastState?.state.offset)
100
+ return;
101
+ this._lastState = nextState;
102
+ const archivist = await this.getArchivistForStore("stateStore");
103
+ const [bw] = await (await new import_boundwitness_builder.BoundWitnessBuilder().payload(nextState)).witness(this.account).build();
104
+ await archivist.insert([
105
+ bw,
106
+ nextState
107
+ ]);
108
+ }
109
+ async divineHandler(payloads = []) {
110
+ const indexPayloadDiviner = await this.getPayloadDivinerForStore("indexStore");
111
+ const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage("divinerQueryToIndexQueryDiviner");
112
+ const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage("indexQueryResponseToDivinerQueryResponseDiviner");
113
+ const results = (await Promise.all(payloads.map(async (payload) => {
114
+ const indexQuery = await divinerQueryToIndexQueryDiviner.divine([
115
+ payload
116
+ ]);
117
+ const indexedResults = await indexPayloadDiviner.divine(indexQuery);
118
+ const response = await Promise.all(indexedResults.flat().map((indexedResult) => indexQueryResponseToDivinerQueryResponseDiviner.divine([
119
+ payload,
120
+ indexedResult
121
+ ])));
122
+ return response.flat();
123
+ }))).flat();
124
+ return await Promise.all(results.map((result) => import_payload_builder.PayloadBuilder.build(result)));
125
+ }
126
+ /**
127
+ * Retrieves the archivist for the specified store
128
+ * @param store The store to retrieve the archivist for
129
+ * @returns The archivist for the specified store
130
+ */
131
+ async getArchivistForStore(store) {
132
+ const name = (0, import_assert.assertEx)(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`);
133
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist [${name}]`);
134
+ return import_archivist_wrapper.ArchivistWrapper.wrap(mod, this.account);
135
+ }
136
+ /**
137
+ * Retrieves the BoundWitness Diviner for the specified store
138
+ * @param store The store to retrieve the BoundWitness Diviner for
139
+ * @returns The BoundWitness Diviner for the specified store
140
+ */
141
+ async getBoundWitnessDivinerForStore(store) {
142
+ const name = (0, import_assert.assertEx)(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`);
143
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner [${name}]`);
144
+ return import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account);
145
+ }
146
+ /**
147
+ * Gets the Diviner for the supplied Indexing Diviner stage
148
+ * @param transform The Indexing Diviner stage
149
+ * @returns The diviner corresponding to the Indexing Diviner stage
150
+ */
151
+ async getIndexingDivinerStage(transform) {
152
+ const nameOrAddress = (0, import_assert.assertEx)(this.config?.indexingDivinerStages?.[transform], () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`);
153
+ const mod = await this.resolve(nameOrAddress);
154
+ return (0, import_assert.assertEx)((0, import_diviner_model.asDivinerInstance)(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`);
155
+ }
156
+ /**
157
+ * Retrieves the Payload Diviner for the specified store
158
+ * @param store The store to retrieve the Payload Diviner for
159
+ * @returns The Payload Diviner for the specified store
160
+ */
161
+ async getPayloadDivinerForStore(store) {
162
+ const name = (0, import_assert.assertEx)(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`);
163
+ const mod = (0, import_assert.assertEx)(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner [${name}]`);
164
+ return import_diviner_wrapper.DivinerWrapper.wrap(mod, this.account);
165
+ }
166
+ /**
167
+ * Retrieves the last state of the Diviner process. Used to recover state after
168
+ * preemptions, reboots, etc.
169
+ */
170
+ async retrieveState() {
171
+ if (this._lastState)
172
+ return this._lastState;
173
+ let hash = "";
174
+ const diviner = await this.getBoundWitnessDivinerForStore("stateStore");
175
+ const query = await new import_payload_builder.PayloadBuilder({
176
+ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema
177
+ }).fields({
178
+ address: this.account.address,
179
+ limit: 1,
180
+ offset: 0,
181
+ order: "desc",
182
+ payload_schemas: [
183
+ import_module_model.ModuleStateSchema
184
+ ]
185
+ }).build();
186
+ const boundWitnesses = await diviner.divine([
187
+ query
188
+ ]);
189
+ if (boundWitnesses.length > 0) {
190
+ const boundWitness = boundWitnesses[0];
191
+ if ((0, import_boundwitness_model.isBoundWitness)(boundWitness)) {
192
+ hash = boundWitness.addresses.map((address, index) => ({
193
+ address,
194
+ index
195
+ })).filter(({ address }) => address === this.account.address).reduce((prev, curr) => boundWitness.payload_schemas?.[curr?.index] === import_module_model.ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev, "");
196
+ }
197
+ }
198
+ if (hash !== "") {
199
+ const archivist = await this.getArchivistForStore("stateStore");
200
+ const payload = (await archivist.get([
201
+ hash
202
+ ])).find(import_module_model.isModuleState);
203
+ if (payload) {
204
+ return payload;
205
+ }
206
+ }
207
+ return void 0;
208
+ }
209
+ async startHandler() {
210
+ await super.startHandler();
211
+ this.poll();
212
+ return true;
213
+ }
214
+ async stopHandler(_timeout) {
215
+ if (this._pollId) {
216
+ clearTimeout(this._pollId);
217
+ this._pollId = void 0;
218
+ }
219
+ return await super.stopHandler();
220
+ }
221
+ /**
222
+ * Runs the background divine process on a loop with a delay
223
+ * specified by the `config.pollFrequency`
224
+ */
225
+ poll() {
226
+ this._pollId = (0, import_timer.setTimeoutEx)(async () => {
227
+ try {
228
+ await Promise.resolve();
229
+ await this.backgroundDivine();
230
+ } catch (e) {
231
+ console.log(e);
232
+ } finally {
233
+ if (this._pollId)
234
+ (0, import_timer.clearTimeoutEx)(this._pollId);
235
+ this._pollId = void 0;
236
+ this.poll();
237
+ }
238
+ }, this.pollFrequency);
239
+ }
240
+ };
241
+ IndexingDiviner = _ts_decorate([
242
+ (0, import_module_model.creatableModule)()
243
+ ], IndexingDiviner);
244
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts"],"sourcesContent":["export * from './Diviner'\n","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 { asDivinerInstance, DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { creatableModule, isModuleState, isModuleStateWithMeta, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } 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(isModuleStateWithMeta<IndexingDivinerState>)\n const indexCandidates = results.filter((x) => !isModuleStateWithMeta(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 (await new BoundWitnessBuilder().payload(nextState)).witness(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<WithMeta<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 (await Promise.all(results.map((result) => PayloadBuilder.build(result)))) as WithMeta<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 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: 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('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload as WithMeta<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.pollFrequency)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AAEzB,mBAA6C;AAC7C,+BAAiC;AACjC,kCAAoC;AACpC,gCAA+B;AAC/B,8BAAgC;AAChC,wCAAgF;AAChF,oCAMO;AACP,2BAA2E;AAC3E,6BAA+B;AAC/B,0BAAsG;AACtG,6BAA+B;;;;;;;;;;;;AAO/B,IAAMA,aAAa;AAGZ,IAAMC,kBAAN,cASGC,wCAAAA;SAAAA;;;EACR,OAAyBC,qBAAqB;EAC9C,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAE/CE;EACAC;EAER,IAAIC,sBAAsB;AACxB,WAAO,KAAKC,OAAOD,uBAAuB;EAC5C;EAEA,IAAIE,gBAAgB;AAClB,WAAO,KAAKD,OAAOC,iBAAiB;EACtC;;;;;EAMUC,mBAAmB,YAAA;AAE3B,UAAMC,YAAY,MAAM,KAAKC,cAAa;AAE1C,UAAMC,wBAAwB,MAAM,KAAKC,wBAAwB,8BAAA;AACjE,UAA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,IAAI;QAACrB;OAAK,GAAGnD,KAAKyE,iCAAAA;AACnD,UAAIzD,SAAS;AACX,eAAOA;MACT;IACF;AACA,WAAO0D;EACT;EAEA,MAAyBC,eAAiC;AACxD,UAAM,MAAMA,aAAAA;AACZ,SAAKC,KAAI;AACT,WAAO;EACT;EAEA,MAAyBC,YAAYC,UAAiD;AACpF,QAAI,KAAK1F,SAAS;AAChB2F,mBAAa,KAAK3F,OAAO;AACzB,WAAKA,UAAUsF;IACjB;AACA,WAAO,MAAM,MAAMG,YAAAA;EACrB;;;;;EAMQD,OAAO;AACb,SAAKxF,cAAU4F,2BAAa,YAAA;AAC1B,UAAI;AACF,cAAMtD,QAAQc,QAAO;AACrB,cAAM,KAAKhD,iBAAgB;MAC7B,SAASyF,GAAG;AACVC,gBAAQC,IAAIF,CAAAA;MACd,UAAA;AACE,YAAI,KAAK7F;AAASgG,2CAAe,KAAKhG,OAAO;AAC7C,aAAKA,UAAUsF;AACf,aAAKE,KAAI;MACX;IACF,GAAG,KAAKrF,aAAa;EACvB;AACF;AApNaV,kBAAAA,aAAAA;MADZwG,qCAAAA;GACYxG,eAAAA;","names":["moduleName","IndexingDiviner","AbstractDiviner","allowRandomAccount","configSchemas","IndexingDivinerConfigSchema","defaultConfigSchema","_lastState","_pollId","payloadDivinerLimit","config","pollFrequency","backgroundDivine","lastState","retrieveState","indexCandidateDiviner","getIndexingDivinerStage","results","divine","nextState","find","isModuleStateWithMeta","indexCandidates","filter","x","toIndexTransformDiviner","indexes","indexArchivist","getArchivistForStore","insert","commitState","state","offset","archivist","bw","BoundWitnessBuilder","payload","witness","account","build","divineHandler","payloads","indexPayloadDiviner","getPayloadDivinerForStore","divinerQueryToIndexQueryDiviner","indexQueryResponseToDivinerQueryResponseDiviner","Promise","all","map","indexQuery","indexedResults","response","flat","indexedResult","result","PayloadBuilder","store","name","assertEx","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStore","boundWitnessDiviner","DivinerWrapper","transform","nameOrAddress","indexingDivinerStages","asDivinerInstance","payloadDiviner","hash","diviner","query","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","length","boundWitness","isBoundWitness","addresses","index","reduce","prev","curr","payload_hashes","get","isModuleState","undefined","startHandler","poll","stopHandler","_timeout","clearTimeout","setTimeoutEx","e","console","log","clearTimeoutEx","creatableModule"]}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,223 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/Diviner.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { clearTimeoutEx, setTimeoutEx } from "@xylabs/timer";
7
+ import { ArchivistWrapper } from "@xyo-network/archivist-wrapper";
8
+ import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
9
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
10
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
11
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
12
+ import { IndexingDivinerConfigSchema } from "@xyo-network/diviner-indexing-model";
13
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
14
+ import { DivinerWrapper } from "@xyo-network/diviner-wrapper";
15
+ import { creatableModule, isModuleState, isModuleStateWithMeta, ModuleStateSchema } from "@xyo-network/module-model";
16
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
17
+ function _ts_decorate(decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
20
+ r = Reflect.decorate(decorators, target, key, desc);
21
+ else
22
+ for (var i = decorators.length - 1; i >= 0; i--)
23
+ if (d = decorators[i])
24
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
26
+ }
27
+ __name(_ts_decorate, "_ts_decorate");
28
+ var moduleName = "IndexingDiviner";
29
+ var IndexingDiviner = class extends AbstractDiviner {
30
+ static {
31
+ __name(this, "IndexingDiviner");
32
+ }
33
+ static allowRandomAccount = false;
34
+ static configSchemas = [
35
+ ...super.configSchemas,
36
+ IndexingDivinerConfigSchema
37
+ ];
38
+ static defaultConfigSchema = IndexingDivinerConfigSchema;
39
+ _lastState;
40
+ _pollId;
41
+ get payloadDivinerLimit() {
42
+ return this.config.payloadDivinerLimit ?? 1e3;
43
+ }
44
+ get pollFrequency() {
45
+ return this.config.pollFrequency ?? 1e4;
46
+ }
47
+ /**
48
+ * Works via batched iteration of the source archivist to populate the index.
49
+ * @returns A promise that resolves when the background process is complete
50
+ */
51
+ backgroundDivine = async () => {
52
+ const lastState = await this.retrieveState();
53
+ const indexCandidateDiviner = await this.getIndexingDivinerStage("stateToIndexCandidateDiviner");
54
+ const results = lastState ? await indexCandidateDiviner.divine([
55
+ lastState
56
+ ]) : await indexCandidateDiviner.divine();
57
+ const nextState = results.find(isModuleStateWithMeta);
58
+ const indexCandidates = results.filter((x) => !isModuleStateWithMeta(x));
59
+ const toIndexTransformDiviner = await this.getIndexingDivinerStage("indexCandidateToIndexDiviner");
60
+ const indexes = await toIndexTransformDiviner.divine(indexCandidates);
61
+ const indexArchivist = await this.getArchivistForStore("indexStore");
62
+ await indexArchivist.insert(indexes);
63
+ if (nextState) {
64
+ await this.commitState(nextState);
65
+ }
66
+ };
67
+ /**
68
+ * Commit the internal state of the Diviner process. This is similar
69
+ * to a transaction completion in a database and should only be called
70
+ * when results have been successfully persisted to the appropriate
71
+ * external stores.
72
+ * @param nextState The state to commit
73
+ */
74
+ async commitState(nextState) {
75
+ if (nextState.state.offset === this._lastState?.state.offset)
76
+ return;
77
+ this._lastState = nextState;
78
+ const archivist = await this.getArchivistForStore("stateStore");
79
+ const [bw] = await (await new BoundWitnessBuilder().payload(nextState)).witness(this.account).build();
80
+ await archivist.insert([
81
+ bw,
82
+ nextState
83
+ ]);
84
+ }
85
+ async divineHandler(payloads = []) {
86
+ const indexPayloadDiviner = await this.getPayloadDivinerForStore("indexStore");
87
+ const divinerQueryToIndexQueryDiviner = await this.getIndexingDivinerStage("divinerQueryToIndexQueryDiviner");
88
+ const indexQueryResponseToDivinerQueryResponseDiviner = await this.getIndexingDivinerStage("indexQueryResponseToDivinerQueryResponseDiviner");
89
+ const results = (await Promise.all(payloads.map(async (payload) => {
90
+ const indexQuery = await divinerQueryToIndexQueryDiviner.divine([
91
+ payload
92
+ ]);
93
+ const indexedResults = await indexPayloadDiviner.divine(indexQuery);
94
+ const response = await Promise.all(indexedResults.flat().map((indexedResult) => indexQueryResponseToDivinerQueryResponseDiviner.divine([
95
+ payload,
96
+ indexedResult
97
+ ])));
98
+ return response.flat();
99
+ }))).flat();
100
+ return await Promise.all(results.map((result) => PayloadBuilder.build(result)));
101
+ }
102
+ /**
103
+ * Retrieves the archivist for the specified store
104
+ * @param store The store to retrieve the archivist for
105
+ * @returns The archivist for the specified store
106
+ */
107
+ async getArchivistForStore(store) {
108
+ const name = assertEx(this.config?.[store]?.archivist, () => `${moduleName}: Config for ${store}.archivist not specified`);
109
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.archivist [${name}]`);
110
+ return ArchivistWrapper.wrap(mod, this.account);
111
+ }
112
+ /**
113
+ * Retrieves the BoundWitness Diviner for the specified store
114
+ * @param store The store to retrieve the BoundWitness Diviner for
115
+ * @returns The BoundWitness Diviner for the specified store
116
+ */
117
+ async getBoundWitnessDivinerForStore(store) {
118
+ const name = assertEx(this.config?.[store]?.boundWitnessDiviner, () => `${moduleName}: Config for ${store}.boundWitnessDiviner not specified`);
119
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.boundWitnessDiviner [${name}]`);
120
+ return DivinerWrapper.wrap(mod, this.account);
121
+ }
122
+ /**
123
+ * Gets the Diviner for the supplied Indexing Diviner stage
124
+ * @param transform The Indexing Diviner stage
125
+ * @returns The diviner corresponding to the Indexing Diviner stage
126
+ */
127
+ async getIndexingDivinerStage(transform) {
128
+ const nameOrAddress = assertEx(this.config?.indexingDivinerStages?.[transform], () => `${moduleName}: Config for indexingDivinerStages.${transform} not specified`);
129
+ const mod = await this.resolve(nameOrAddress);
130
+ return assertEx(asDivinerInstance(mod), () => `${moduleName}: Failed to resolve indexing diviner stage for ${transform}`);
131
+ }
132
+ /**
133
+ * Retrieves the Payload Diviner for the specified store
134
+ * @param store The store to retrieve the Payload Diviner for
135
+ * @returns The Payload Diviner for the specified store
136
+ */
137
+ async getPayloadDivinerForStore(store) {
138
+ const name = assertEx(this.config?.[store]?.payloadDiviner, () => `${moduleName}: Config for ${store}.payloadDiviner not specified`);
139
+ const mod = assertEx(await this.resolve(name), () => `${moduleName}: Failed to resolve ${store}.payloadDiviner [${name}]`);
140
+ return DivinerWrapper.wrap(mod, this.account);
141
+ }
142
+ /**
143
+ * Retrieves the last state of the Diviner process. Used to recover state after
144
+ * preemptions, reboots, etc.
145
+ */
146
+ async retrieveState() {
147
+ if (this._lastState)
148
+ return this._lastState;
149
+ let hash = "";
150
+ const diviner = await this.getBoundWitnessDivinerForStore("stateStore");
151
+ const query = await new PayloadBuilder({
152
+ schema: BoundWitnessDivinerQuerySchema
153
+ }).fields({
154
+ address: this.account.address,
155
+ limit: 1,
156
+ offset: 0,
157
+ order: "desc",
158
+ payload_schemas: [
159
+ ModuleStateSchema
160
+ ]
161
+ }).build();
162
+ const boundWitnesses = await diviner.divine([
163
+ query
164
+ ]);
165
+ if (boundWitnesses.length > 0) {
166
+ const boundWitness = boundWitnesses[0];
167
+ if (isBoundWitness(boundWitness)) {
168
+ hash = boundWitness.addresses.map((address, index) => ({
169
+ address,
170
+ index
171
+ })).filter(({ address }) => address === this.account.address).reduce((prev, curr) => boundWitness.payload_schemas?.[curr?.index] === ModuleStateSchema ? boundWitness.payload_hashes[curr?.index] : prev, "");
172
+ }
173
+ }
174
+ if (hash !== "") {
175
+ const archivist = await this.getArchivistForStore("stateStore");
176
+ const payload = (await archivist.get([
177
+ hash
178
+ ])).find(isModuleState);
179
+ if (payload) {
180
+ return payload;
181
+ }
182
+ }
183
+ return void 0;
184
+ }
185
+ async startHandler() {
186
+ await super.startHandler();
187
+ this.poll();
188
+ return true;
189
+ }
190
+ async stopHandler(_timeout) {
191
+ if (this._pollId) {
192
+ clearTimeout(this._pollId);
193
+ this._pollId = void 0;
194
+ }
195
+ return await super.stopHandler();
196
+ }
197
+ /**
198
+ * Runs the background divine process on a loop with a delay
199
+ * specified by the `config.pollFrequency`
200
+ */
201
+ poll() {
202
+ this._pollId = setTimeoutEx(async () => {
203
+ try {
204
+ await Promise.resolve();
205
+ await this.backgroundDivine();
206
+ } catch (e) {
207
+ console.log(e);
208
+ } finally {
209
+ if (this._pollId)
210
+ clearTimeoutEx(this._pollId);
211
+ this._pollId = void 0;
212
+ this.poll();
213
+ }
214
+ }, this.pollFrequency);
215
+ }
216
+ };
217
+ IndexingDiviner = _ts_decorate([
218
+ creatableModule()
219
+ ], IndexingDiviner);
220
+ export {
221
+ IndexingDiviner
222
+ };
223
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 { asDivinerInstance, DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { DivinerWrapper } from '@xyo-network/diviner-wrapper'\nimport { creatableModule, isModuleState, isModuleStateWithMeta, ModuleState, ModuleStateSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema, WithMeta } 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(isModuleStateWithMeta<IndexingDivinerState>)\n const indexCandidates = results.filter((x) => !isModuleStateWithMeta(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 (await new BoundWitnessBuilder().payload(nextState)).witness(this.account).build()\n await archivist.insert([bw, nextState])\n }\n\n protected override async divineHandler(payloads: TIn[] = []): Promise<WithMeta<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 (await Promise.all(results.map((result) => PayloadBuilder.build(result)))) as WithMeta<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 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: 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('stateStore')\n const payload = (await archivist.get([hash])).find(isModuleState<IndexingDivinerState>)\n if (payload) {\n return payload as WithMeta<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.pollFrequency)\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AAEzB,SAASC,gBAAgBC,oBAAoB;AAC7C,SAASC,wBAAwB;AACjC,SAASC,2BAA2B;AACpC,SAASC,sBAAsB;AAC/B,SAASC,uBAAuB;AAChC,SAA0CC,sCAAsC;AAChF,SAEEC,mCAIK;AACP,SAASC,yBAAkE;AAC3E,SAASC,sBAAsB;AAC/B,SAASC,iBAAiBC,eAAeC,uBAAoCC,yBAAyB;AACtG,SAASC,sBAAsB;;;;;;;;;;;;AAO/B,IAAMC,aAAa;AAGZ,IAAMC,kBAAN,cASGC,gBAAAA;SAAAA;;;EACR,OAAyBC,qBAAqB;EAC9C,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAE/CE;EACAC;EAER,IAAIC,sBAAsB;AACxB,WAAO,KAAKC,OAAOD,uBAAuB;EAC5C;EAEA,IAAIE,gBAAgB;AAClB,WAAO,KAAKD,OAAOC,iBAAiB;EACtC;;;;;EAMUC,mBAAmB,YAAA;AAE3B,UAAMC,YAAY,MAAM,KAAKC,cAAa;AAE1C,UAAMC,wBAAwB,MAAM,KAAKC,wBAAwB,8BAAA;AACjE,UAAMC,UAAUJ,YAAY,MAAME,sBAAsBG,OAAO;MAACL;KAAU,IAAI,MAAME,sBAAsBG,OAAM;AAEhH,UAAMC,YAAYF,QAAQG,KAAKC,qBAAAA;AAC/B,UAAMC,kBAAkBL,QAAQM,OAAO,CAACC,MAAM,CAACH,sBAAsBG,CAAAA,CAAAA;AAErE,UAA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KAAK1F,SAAS;AAChB2F,mBAAa,KAAK3F,OAAO;AACzB,WAAKA,UAAUsF;IACjB;AACA,WAAO,MAAM,MAAMG,YAAAA;EACrB;;;;;EAMQD,OAAO;AACb,SAAKxF,UAAU4F,aAAa,YAAA;AAC1B,UAAI;AACF,cAAMtD,QAAQc,QAAO;AACrB,cAAM,KAAKhD,iBAAgB;MAC7B,SAASyF,GAAG;AACVC,gBAAQC,IAAIF,CAAAA;MACd,UAAA;AACE,YAAI,KAAK7F;AAASgG,yBAAe,KAAKhG,OAAO;AAC7C,aAAKA,UAAUsF;AACf,aAAKE,KAAI;MACX;IACF,GAAG,KAAKrF,aAAa;EACvB;AACF;AApNaV,kBAAAA,aAAAA;EADZwG,gBAAAA;GACYxG,eAAAA;","names":["assertEx","clearTimeoutEx","setTimeoutEx","ArchivistWrapper","BoundWitnessBuilder","isBoundWitness","AbstractDiviner","BoundWitnessDivinerQuerySchema","IndexingDivinerConfigSchema","asDivinerInstance","DivinerWrapper","creatableModule","isModuleState","isModuleStateWithMeta","ModuleStateSchema","PayloadBuilder","moduleName","IndexingDiviner","AbstractDiviner","allowRandomAccount","configSchemas","IndexingDivinerConfigSchema","defaultConfigSchema","_lastState","_pollId","payloadDivinerLimit","config","pollFrequency","backgroundDivine","lastState","retrieveState","indexCandidateDiviner","getIndexingDivinerStage","results","divine","nextState","find","isModuleStateWithMeta","indexCandidates","filter","x","toIndexTransformDiviner","indexes","indexArchivist","getArchivistForStore","insert","commitState","state","offset","archivist","bw","BoundWitnessBuilder","payload","witness","account","build","divineHandler","payloads","indexPayloadDiviner","getPayloadDivinerForStore","divinerQueryToIndexQueryDiviner","indexQueryResponseToDivinerQueryResponseDiviner","Promise","all","map","indexQuery","indexedResults","response","flat","indexedResult","result","PayloadBuilder","store","name","assertEx","mod","resolve","ArchivistWrapper","wrap","getBoundWitnessDivinerForStore","boundWitnessDiviner","DivinerWrapper","transform","nameOrAddress","indexingDivinerStages","asDivinerInstance","payloadDiviner","hash","diviner","query","schema","BoundWitnessDivinerQuerySchema","fields","address","limit","order","payload_schemas","ModuleStateSchema","boundWitnesses","length","boundWitness","isBoundWitness","addresses","index","reduce","prev","curr","payload_hashes","get","isModuleState","undefined","startHandler","poll","stopHandler","_timeout","clearTimeout","setTimeoutEx","e","console","log","clearTimeoutEx","creatableModule"]}
package/package.json CHANGED
@@ -10,24 +10,24 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.1.11",
14
- "@xylabs/hex": "^3.1.11",
15
- "@xylabs/timer": "^3.1.11",
16
- "@xyo-network/archivist-wrapper": "~2.99.2",
17
- "@xyo-network/boundwitness-builder": "~2.99.2",
18
- "@xyo-network/boundwitness-model": "~2.99.2",
19
- "@xyo-network/diviner-abstract": "~2.99.2",
20
- "@xyo-network/diviner-boundwitness-model": "~2.99.2",
21
- "@xyo-network/diviner-indexing-model": "~2.99.2",
22
- "@xyo-network/diviner-model": "~2.99.2",
23
- "@xyo-network/diviner-wrapper": "~2.99.2",
24
- "@xyo-network/module-model": "~2.99.2",
25
- "@xyo-network/payload-builder": "~2.99.2",
26
- "@xyo-network/payload-model": "~2.99.2"
13
+ "@xylabs/assert": "^3.3.2",
14
+ "@xylabs/hex": "^3.3.2",
15
+ "@xylabs/timer": "^3.3.2",
16
+ "@xyo-network/archivist-wrapper": "~2.99.3",
17
+ "@xyo-network/boundwitness-builder": "~2.99.3",
18
+ "@xyo-network/boundwitness-model": "~2.99.3",
19
+ "@xyo-network/diviner-abstract": "~2.99.3",
20
+ "@xyo-network/diviner-boundwitness-model": "~2.99.3",
21
+ "@xyo-network/diviner-indexing-model": "~2.99.3",
22
+ "@xyo-network/diviner-model": "~2.99.3",
23
+ "@xyo-network/diviner-wrapper": "~2.99.3",
24
+ "@xyo-network/module-model": "~2.99.3",
25
+ "@xyo-network/payload-builder": "~2.99.3",
26
+ "@xyo-network/payload-model": "~2.99.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@xylabs/ts-scripts-yarn3": "^3.9.1",
30
- "@xylabs/tsconfig": "^3.9.1",
29
+ "@xylabs/ts-scripts-yarn3": "^3.10.0",
30
+ "@xylabs/tsconfig": "^3.10.0",
31
31
  "typescript": "^5.4.5"
32
32
  },
33
33
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -69,6 +69,6 @@
69
69
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
70
70
  },
71
71
  "sideEffects": false,
72
- "version": "2.99.2",
72
+ "version": "2.99.3",
73
73
  "type": "module"
74
74
  }