@sentio/runtime 4.0.0-rc.1 → 4.0.0-rc.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,108 @@
1
+ import { DBResponse, TemplateInstance, TimeseriesResult, DBRequest_DBUpsert, ProcessStreamResponseSchema, ProcessStreamResponseV3Schema, DBRequestSchema, HandlerType, ProcessConfigResponse, StartRequest, DataBinding, PreparedData, ProcessResult, PreprocessResult, ProcessStreamResponse_Partitions, UpdateTemplatesRequest } from '@sentio/protos';
2
+ import { Subject } from 'rxjs';
3
+ import { MessageInitShape } from '@bufbuild/protobuf';
4
+ import { AsyncLocalStorage } from 'node:async_hooks';
5
+
6
+ type ProcessStreamResponseInit = MessageInitShape<typeof ProcessStreamResponseSchema>;
7
+ type ProcessStreamResponseV3Init = MessageInitShape<typeof ProcessStreamResponseV3Schema>;
8
+ type Request = NonNullable<MessageInitShape<typeof DBRequestSchema>['op']>;
9
+ type RequestType = NonNullable<Request['case']>;
10
+ declare const timeoutError: Error;
11
+ interface IStoreContext {
12
+ sendRequest(request: Request, timeoutSecs?: number): Promise<DBResponse>;
13
+ result(dbResult: DBResponse): void;
14
+ error(processId: number, e: any): void;
15
+ close(): void;
16
+ }
17
+ interface IDataBindingContext extends IStoreContext {
18
+ sendTemplateRequest(templates: Array<TemplateInstance>, unbind: boolean): void;
19
+ sendTimeseriesRequest(timeseries: Array<TimeseriesResult>): void;
20
+ }
21
+ declare abstract class AbstractStoreContext implements IStoreContext {
22
+ readonly processId: number;
23
+ private static opCounter;
24
+ protected defers: Map<bigint, {
25
+ resolve: (value: any) => void;
26
+ reject: (reason?: any) => void;
27
+ requestType?: RequestType;
28
+ }>;
29
+ private statsInterval;
30
+ private pendings;
31
+ constructor(processId: number);
32
+ newPromise<T>(opId: bigint, requestType?: RequestType): Promise<T>;
33
+ abstract doSend(resp: ProcessStreamResponseInit | ProcessStreamResponseV3Init): void;
34
+ sendRequest(request: Request, timeoutSecs?: number): Promise<DBResponse>;
35
+ result(dbResult: DBResponse): void;
36
+ error(processId: number, e: any): void;
37
+ close(): void;
38
+ upsertBatch: {
39
+ opId: bigint;
40
+ request: DBRequest_DBUpsert;
41
+ promise: Promise<DBResponse>;
42
+ timer: NodeJS.Timeout;
43
+ } | undefined;
44
+ private sendUpsertInBatch;
45
+ private sendBatch;
46
+ awaitPendings(): Promise<void>;
47
+ }
48
+ declare class StoreContext extends AbstractStoreContext {
49
+ readonly subject: Subject<ProcessStreamResponseInit>;
50
+ constructor(subject: Subject<ProcessStreamResponseInit>, processId: number);
51
+ doSend(resp: ProcessStreamResponseInit): void;
52
+ }
53
+ declare class DataBindingContext extends AbstractStoreContext implements IDataBindingContext {
54
+ readonly processId: number;
55
+ readonly subject: Subject<ProcessStreamResponseV3Init>;
56
+ constructor(processId: number, subject: Subject<ProcessStreamResponseV3Init>);
57
+ sendTemplateRequest(templates: Array<TemplateInstance>, unbind: boolean): void;
58
+ sendTimeseriesRequest(timeseries: Array<TimeseriesResult>): void;
59
+ doSend(resp: ProcessStreamResponseV3Init): void;
60
+ }
61
+
62
+ declare abstract class Plugin {
63
+ name: string;
64
+ supportedHandlers: HandlerType[];
65
+ configure(config: ProcessConfigResponse, forChainId?: string): Promise<void>;
66
+ start(start: StartRequest): Promise<void>;
67
+ /**
68
+ * @deprecated The method should not be used, use ctx.states instead
69
+ */
70
+ stateDiff(config: ProcessConfigResponse): boolean;
71
+ processBinding(request: DataBinding, preparedData: PreparedData | undefined): Promise<ProcessResult>;
72
+ preprocessBinding(request: DataBinding, preprocessStore: {
73
+ [k: string]: any;
74
+ }): Promise<PreprocessResult>;
75
+ partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions>;
76
+ /**
77
+ * method used by action server only
78
+ * @param port
79
+ */
80
+ startServer(port?: number): Promise<void>;
81
+ /**
82
+ * method used by action server only
83
+ */
84
+ shutdownServer(): void;
85
+ }
86
+ declare class PluginManager {
87
+ static INSTANCE: PluginManager;
88
+ dbContextLocalStorage: AsyncLocalStorage<IStoreContext | IDataBindingContext | undefined>;
89
+ plugins: Plugin[];
90
+ typesToPlugin: Map<HandlerType, Plugin>;
91
+ register(plugin: Plugin): void;
92
+ configure(config: ProcessConfigResponse): Promise<void>;
93
+ start(start: StartRequest, actionServerPort?: number): Promise<void[]>;
94
+ startServer(port?: number): Promise<void[]>;
95
+ shutdown(): void;
96
+ /**
97
+ * @deprecated The method should not be used, use ctx.states instead
98
+ */
99
+ stateDiff(config: ProcessConfigResponse): boolean;
100
+ processBinding(request: DataBinding, preparedData: PreparedData | undefined, dbContext?: IDataBindingContext | IStoreContext): Promise<ProcessResult>;
101
+ partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions>;
102
+ preprocessBinding(request: DataBinding, preprocessStore: {
103
+ [k: string]: any;
104
+ }, dbContext?: IDataBindingContext | IStoreContext): Promise<PreprocessResult>;
105
+ updateTemplates(request: UpdateTemplatesRequest): Promise<void>;
106
+ }
107
+
108
+ export { AbstractStoreContext as A, DataBindingContext as D, type IStoreContext as I, Plugin as P, StoreContext as S, PluginManager as a, type IDataBindingContext as b, timeoutError as t };