@sentio/runtime 2.61.0-rc.8 → 2.61.0
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.
- package/lib/chunk-3P4VIZX3.js +117 -0
- package/lib/{chunk-XIU7XZT7.js.map → chunk-3P4VIZX3.js.map} +1 -1
- package/lib/chunk-OMQ4A6ZL.js +26 -0
- package/lib/chunk-OMQ4A6ZL.js.map +1 -0
- package/lib/chunk-SAKSK7FD.js +38 -0
- package/lib/{chunk-2LXJZQSF.js.map → chunk-SAKSK7FD.js.map} +1 -1
- package/lib/chunk-WHWNPZZ3.js +3 -0
- package/lib/{chunk-6XHWJ2VS.js.map → chunk-WHWNPZZ3.js.map} +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -74
- package/lib/index.js.map +1 -1
- package/lib/{processor-Cbun9NKJ.d.ts → processor-DwZlMkFj.d.ts} +6 -11
- package/lib/processor-runner.js +21 -26835
- package/lib/processor-runner.js.map +1 -1
- package/lib/service-worker.js +2 -130
- package/lib/service-worker.js.map +1 -1
- package/lib/test-processor.test.d.ts +1 -1
- package/lib/test-processor.test.js.map +1 -1
- package/package.json +1 -1
- package/src/db-context.ts +3 -3
- package/src/full-service.ts +9 -12
- package/src/gen/processor/protos/processor.ts +53 -43
- package/src/gen/service/common/protos/common.ts +51 -0
- package/src/plugin.ts +12 -12
- package/src/service-v3.ts +41 -34
- package/lib/chunk-2LXJZQSF.js +0 -10975
- package/lib/chunk-6XHWJ2VS.js +0 -92
- package/lib/chunk-J4QKUO6L.js +0 -28408
- package/lib/chunk-J4QKUO6L.js.map +0 -1
- package/lib/chunk-XIU7XZT7.js +0 -59981
package/src/plugin.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import {
|
2
2
|
DataBinding,
|
3
3
|
HandlerType,
|
4
|
-
InitResponse,
|
5
4
|
PreparedData,
|
6
5
|
PreprocessResult,
|
7
6
|
ProcessConfigResponse,
|
8
7
|
ProcessResult,
|
9
8
|
ProcessStreamResponse_Partitions,
|
10
9
|
ProcessStreamResponse_Partitions_Partition_SysValue,
|
11
|
-
StartRequest
|
10
|
+
StartRequest,
|
11
|
+
UpdateTemplatesRequest
|
12
12
|
} from '@sentio/protos'
|
13
13
|
import { IStoreContext, StoreContext } from './db-context.js'
|
14
14
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
@@ -60,12 +60,6 @@ export abstract class Plugin {
|
|
60
60
|
* method used by action server only
|
61
61
|
*/
|
62
62
|
shutdownServer() {}
|
63
|
-
|
64
|
-
/**
|
65
|
-
* Initialize the plugin, for service v3.
|
66
|
-
* @param config
|
67
|
-
*/
|
68
|
-
async init(config: InitResponse): Promise<void> {}
|
69
63
|
}
|
70
64
|
|
71
65
|
export class PluginManager {
|
@@ -90,8 +84,10 @@ export class PluginManager {
|
|
90
84
|
}
|
91
85
|
}
|
92
86
|
|
93
|
-
async configure(config: ProcessConfigResponse
|
94
|
-
|
87
|
+
async configure(config: ProcessConfigResponse): Promise<void> {
|
88
|
+
for (const plugin of this.plugins) {
|
89
|
+
await plugin.configure(config)
|
90
|
+
}
|
95
91
|
}
|
96
92
|
|
97
93
|
start(start: StartRequest, actionServerPort?: number) {
|
@@ -149,7 +145,11 @@ export class PluginManager {
|
|
149
145
|
})
|
150
146
|
}
|
151
147
|
|
152
|
-
async
|
153
|
-
|
148
|
+
async updateTemplates(request: UpdateTemplatesRequest) {
|
149
|
+
for (const plugin of this.plugins) {
|
150
|
+
await plugin.start({
|
151
|
+
templateInstances: request.templateInstances
|
152
|
+
})
|
153
|
+
}
|
154
154
|
}
|
155
155
|
}
|
package/src/service-v3.ts
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
import {
|
2
|
-
ConfigureHandlersRequest,
|
3
|
-
ConfigureHandlersResponse,
|
4
2
|
DataBinding,
|
5
3
|
DeepPartial,
|
6
4
|
Empty,
|
7
5
|
HandlerType,
|
8
|
-
|
6
|
+
ProcessConfigRequest,
|
9
7
|
ProcessConfigResponse,
|
10
8
|
ProcessorV3ServiceImplementation,
|
11
9
|
ProcessResult,
|
12
10
|
ProcessStreamRequest,
|
13
11
|
ProcessStreamResponse,
|
14
|
-
|
15
|
-
StartRequest
|
12
|
+
ProcessStreamResponseV3,
|
13
|
+
StartRequest,
|
14
|
+
UpdateTemplatesRequest
|
16
15
|
} from '@sentio/protos'
|
17
|
-
import { CallContext } from 'nice-grpc'
|
16
|
+
import { CallContext, ServerError, Status } from 'nice-grpc'
|
18
17
|
import { AsyncIterable } from 'ix'
|
19
18
|
import { PluginManager } from './plugin.js'
|
20
19
|
import { Subject } from 'rxjs'
|
@@ -26,6 +25,7 @@ import { processMetrics } from './metrics.js'
|
|
26
25
|
import { recordRuntimeInfo } from './service.js'
|
27
26
|
import { DataBindingContext } from './db-context.js'
|
28
27
|
import { TemplateInstanceState } from './state.js'
|
28
|
+
import { freezeGlobalConfig } from './global-config.js'
|
29
29
|
|
30
30
|
const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
|
31
31
|
|
@@ -33,6 +33,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
33
33
|
readonly enablePartition: boolean
|
34
34
|
private readonly loader: () => Promise<any>
|
35
35
|
private readonly shutdownHandler?: () => void
|
36
|
+
private started = false
|
36
37
|
|
37
38
|
constructor(loader: () => Promise<any>, options?: any, shutdownHandler?: () => void) {
|
38
39
|
this.loader = loader
|
@@ -41,18 +42,37 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
41
42
|
this.enablePartition = options?.['enable-partition'] == true
|
42
43
|
}
|
43
44
|
|
44
|
-
async
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
async start(request: StartRequest, context: CallContext): Promise<Empty> {
|
46
|
+
if (this.started) {
|
47
|
+
return {}
|
48
|
+
}
|
49
|
+
|
50
|
+
freezeGlobalConfig()
|
51
|
+
|
52
|
+
try {
|
53
|
+
await this.loader()
|
54
|
+
} catch (e) {
|
55
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
|
56
|
+
}
|
57
|
+
|
58
|
+
await PluginManager.INSTANCE.start(request)
|
59
|
+
|
60
|
+
this.started = true
|
61
|
+
return {}
|
62
|
+
}
|
63
|
+
|
64
|
+
async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {
|
65
|
+
if (!this.started) {
|
66
|
+
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
67
|
+
}
|
68
|
+
|
69
|
+
const newConfig = ProcessConfigResponse.fromPartial({})
|
70
|
+
await PluginManager.INSTANCE.configure(newConfig)
|
71
|
+
return newConfig
|
52
72
|
}
|
53
73
|
|
54
74
|
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
|
55
|
-
const subject = new Subject<DeepPartial<
|
75
|
+
const subject = new Subject<DeepPartial<ProcessStreamResponseV3>>()
|
56
76
|
this.handleRequests(requests, subject)
|
57
77
|
.then(() => {
|
58
78
|
subject.complete()
|
@@ -88,7 +108,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
88
108
|
async handleRequest(
|
89
109
|
request: ProcessStreamRequest,
|
90
110
|
lastBinding: DataBinding | undefined,
|
91
|
-
subject: Subject<DeepPartial<
|
111
|
+
subject: Subject<DeepPartial<ProcessStreamResponseV3>>
|
92
112
|
) {
|
93
113
|
if (request.binding) {
|
94
114
|
process_binding_count.add(1)
|
@@ -141,7 +161,7 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
141
161
|
private startProcess(
|
142
162
|
processId: number,
|
143
163
|
binding: DataBinding,
|
144
|
-
subject: Subject<DeepPartial<
|
164
|
+
subject: Subject<DeepPartial<ProcessStreamResponseV3>>
|
145
165
|
) {
|
146
166
|
const context = this.contexts.new(processId, subject)
|
147
167
|
const start = Date.now()
|
@@ -194,22 +214,9 @@ export class ProcessorServiceImplV3 implements ProcessorV3ServiceImplementation
|
|
194
214
|
})
|
195
215
|
}
|
196
216
|
|
197
|
-
async
|
198
|
-
request
|
199
|
-
|
200
|
-
): Promise<DeepPartial<ConfigureHandlersResponse>> {
|
201
|
-
await PluginManager.INSTANCE.start(
|
202
|
-
StartRequest.fromPartial({
|
203
|
-
templateInstances: request.templateInstances
|
204
|
-
})
|
205
|
-
)
|
206
|
-
|
207
|
-
const newConfig = ProcessConfigResponse.fromPartial({})
|
208
|
-
await PluginManager.INSTANCE.configure(newConfig, request.chainId)
|
209
|
-
return {
|
210
|
-
accountConfigs: newConfig.accountConfigs,
|
211
|
-
contractConfigs: newConfig.contractConfigs
|
212
|
-
}
|
217
|
+
async updateTemplates(request: UpdateTemplatesRequest, context: CallContext): Promise<DeepPartial<Empty>> {
|
218
|
+
await PluginManager.INSTANCE.updateTemplates(request)
|
219
|
+
return {}
|
213
220
|
}
|
214
221
|
}
|
215
222
|
|
@@ -220,7 +227,7 @@ class Contexts {
|
|
220
227
|
return this.contexts.get(processId)
|
221
228
|
}
|
222
229
|
|
223
|
-
new(processId: number, subject: Subject<DeepPartial<
|
230
|
+
new(processId: number, subject: Subject<DeepPartial<ProcessStreamResponseV3>>) {
|
224
231
|
const context = new DataBindingContext(processId, subject)
|
225
232
|
this.contexts.set(processId, context)
|
226
233
|
return context
|