@sentio/runtime 2.36.2-rc.1 → 2.37.0-rc.11
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/db-context.d.ts +142 -0
- package/lib/db-context.d.ts.map +1 -0
- package/lib/db-context.js +50 -0
- package/lib/db-context.js.map +1 -0
- package/lib/full-service.d.ts +158 -2
- package/lib/full-service.d.ts.map +1 -1
- package/lib/full-service.js +2 -2
- package/lib/full-service.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +135 -14
- package/lib/gen/processor/protos/processor.d.ts.map +1 -1
- package/lib/gen/processor/protos/processor.js +749 -4
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/gen/service/common/protos/common.d.ts +1 -0
- package/lib/gen/service/common/protos/common.d.ts.map +1 -1
- package/lib/gen/service/common/protos/common.js +15 -0
- package/lib/gen/service/common/protos/common.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +1 -1
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +3 -2
- package/lib/logger.js.map +1 -1
- package/lib/logger.test.js.map +1 -1
- package/lib/plugin.d.ts +5 -1
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +6 -2
- package/lib/plugin.js.map +1 -1
- package/lib/processor-runner.js +5 -13
- package/lib/processor-runner.js.map +1 -1
- package/lib/service.d.ts +130 -5
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +38 -12
- package/lib/service.js.map +1 -1
- package/package.json +4 -2
- package/src/db-context.ts +57 -0
- package/src/full-service.ts +4 -3
- package/src/gen/processor/protos/processor.ts +1035 -155
- package/src/gen/service/common/protos/common.ts +17 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +3 -2
- package/src/plugin.ts +8 -2
- package/src/processor-runner.ts +5 -13
- package/src/service.ts +43 -15
@@ -1821,6 +1821,7 @@ export interface Notification {
|
|
1821
1821
|
project: Project | undefined;
|
1822
1822
|
attributes: { [key: string]: string };
|
1823
1823
|
read: boolean;
|
1824
|
+
repeat: number;
|
1824
1825
|
}
|
1825
1826
|
|
1826
1827
|
export interface Notification_AttributesEntry {
|
@@ -12123,6 +12124,7 @@ function createBaseNotification(): Notification {
|
|
12123
12124
|
project: undefined,
|
12124
12125
|
attributes: {},
|
12125
12126
|
read: false,
|
12127
|
+
repeat: 0,
|
12126
12128
|
};
|
12127
12129
|
}
|
12128
12130
|
|
@@ -12164,6 +12166,9 @@ export const Notification = {
|
|
12164
12166
|
if (message.read !== false) {
|
12165
12167
|
writer.uint32(104).bool(message.read);
|
12166
12168
|
}
|
12169
|
+
if (message.repeat !== 0) {
|
12170
|
+
writer.uint32(112).uint32(message.repeat);
|
12171
|
+
}
|
12167
12172
|
return writer;
|
12168
12173
|
},
|
12169
12174
|
|
@@ -12261,6 +12266,13 @@ export const Notification = {
|
|
12261
12266
|
|
12262
12267
|
message.read = reader.bool();
|
12263
12268
|
continue;
|
12269
|
+
case 14:
|
12270
|
+
if (tag !== 112) {
|
12271
|
+
break;
|
12272
|
+
}
|
12273
|
+
|
12274
|
+
message.repeat = reader.uint32();
|
12275
|
+
continue;
|
12264
12276
|
}
|
12265
12277
|
if ((tag & 7) === 4 || tag === 0) {
|
12266
12278
|
break;
|
@@ -12289,6 +12301,7 @@ export const Notification = {
|
|
12289
12301
|
}, {})
|
12290
12302
|
: {},
|
12291
12303
|
read: isSet(object.read) ? globalThis.Boolean(object.read) : false,
|
12304
|
+
repeat: isSet(object.repeat) ? globalThis.Number(object.repeat) : 0,
|
12292
12305
|
};
|
12293
12306
|
},
|
12294
12307
|
|
@@ -12336,6 +12349,9 @@ export const Notification = {
|
|
12336
12349
|
if (message.read !== false) {
|
12337
12350
|
obj.read = message.read;
|
12338
12351
|
}
|
12352
|
+
if (message.repeat !== 0) {
|
12353
|
+
obj.repeat = Math.round(message.repeat);
|
12354
|
+
}
|
12339
12355
|
return obj;
|
12340
12356
|
},
|
12341
12357
|
|
@@ -12366,6 +12382,7 @@ export const Notification = {
|
|
12366
12382
|
{},
|
12367
12383
|
);
|
12368
12384
|
message.read = object.read ?? false;
|
12385
|
+
message.repeat = object.repeat ?? 0;
|
12369
12386
|
return message;
|
12370
12387
|
},
|
12371
12388
|
};
|
package/src/index.ts
CHANGED
package/src/logger.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createLogger, format, transports } from 'winston'
|
2
2
|
|
3
|
-
export function
|
3
|
+
export function setupLogger(json: boolean, enableDebug: boolean) {
|
4
4
|
const utilFormatter = {
|
5
5
|
transform: (info: any) => {
|
6
6
|
const stringRes = []
|
@@ -32,8 +32,9 @@ export function setupJsonLogger() {
|
|
32
32
|
format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }),
|
33
33
|
utilFormatter,
|
34
34
|
format.errors({ stack: true }),
|
35
|
-
format.json()
|
35
|
+
json ? format.json() : format.simple()
|
36
36
|
),
|
37
|
+
level: enableDebug ? 'debug' : 'info',
|
37
38
|
transports: [new transports.Console()]
|
38
39
|
})
|
39
40
|
|
package/src/plugin.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos'
|
2
|
+
import { StoreContext } from './db-context.js'
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
2
4
|
|
3
5
|
export abstract class Plugin {
|
4
6
|
name: string
|
@@ -13,6 +15,7 @@ export abstract class Plugin {
|
|
13
15
|
stateDiff(config: ProcessConfigResponse): boolean {
|
14
16
|
return false
|
15
17
|
}
|
18
|
+
|
16
19
|
async processBinding(request: DataBinding): Promise<ProcessResult> {
|
17
20
|
return ProcessResult.create()
|
18
21
|
}
|
@@ -21,6 +24,7 @@ export abstract class Plugin {
|
|
21
24
|
export class PluginManager {
|
22
25
|
static INSTANCE = new PluginManager()
|
23
26
|
|
27
|
+
dbContextLocalStorage = new AsyncLocalStorage<StoreContext | undefined>()
|
24
28
|
plugins: Plugin[] = []
|
25
29
|
typesToPlugin = new Map<HandlerType, Plugin>()
|
26
30
|
|
@@ -54,11 +58,13 @@ export class PluginManager {
|
|
54
58
|
return this.plugins.some((plugin) => plugin.stateDiff(config))
|
55
59
|
}
|
56
60
|
|
57
|
-
processBinding(request: DataBinding): Promise<ProcessResult> {
|
61
|
+
processBinding(request: DataBinding, dbContext?: StoreContext): Promise<ProcessResult> {
|
58
62
|
const plugin = this.typesToPlugin.get(request.handlerType)
|
59
63
|
if (!plugin) {
|
60
64
|
throw new Error(`No plugin for ${request.handlerType}`)
|
61
65
|
}
|
62
|
-
return
|
66
|
+
return this.dbContextLocalStorage.run(dbContext, () => {
|
67
|
+
return plugin.processBinding(request)
|
68
|
+
})
|
63
69
|
}
|
64
70
|
}
|
package/src/processor-runner.ts
CHANGED
@@ -16,7 +16,7 @@ import { ProcessorServiceImpl } from './service.js'
|
|
16
16
|
import { Endpoints } from './endpoints.js'
|
17
17
|
import { FullProcessorServiceImpl } from './full-service.js'
|
18
18
|
import { ChainConfig } from './chain-config.js'
|
19
|
-
import {
|
19
|
+
import { setupLogger } from './logger.js'
|
20
20
|
|
21
21
|
const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
|
22
22
|
|
@@ -39,12 +39,8 @@ const optionDefinitions = [
|
|
39
39
|
|
40
40
|
const options = commandLineArgs(optionDefinitions, { partial: true })
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
if (options.debug) {
|
46
|
-
console.log('Starting with', options.target)
|
47
|
-
}
|
42
|
+
setupLogger(options['log-format'] === 'json', options.debug)
|
43
|
+
console.debug('Starting with', options.target)
|
48
44
|
|
49
45
|
Error.stackTraceLimit = 20
|
50
46
|
|
@@ -69,9 +65,7 @@ for (const [id, config] of Object.entries(chainsConfig)) {
|
|
69
65
|
}
|
70
66
|
}
|
71
67
|
|
72
|
-
|
73
|
-
console.log('Starting Server', options)
|
74
|
-
}
|
68
|
+
console.debug('Starting Server', options)
|
75
69
|
|
76
70
|
const server = createServer({
|
77
71
|
'grpc.max_send_message_length': 384 * 1024 * 1024,
|
@@ -82,9 +76,7 @@ const server = createServer({
|
|
82
76
|
.use(errorDetailsServerMiddleware)
|
83
77
|
const baseService = new ProcessorServiceImpl(async () => {
|
84
78
|
const m = await import(options.target)
|
85
|
-
|
86
|
-
console.log('Module loaded', m)
|
87
|
-
}
|
79
|
+
console.debug('Module loaded', m)
|
88
80
|
return m
|
89
81
|
}, server.shutdown)
|
90
82
|
const service = new FullProcessorServiceImpl(baseService)
|
package/src/service.ts
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
import { CallContext, ServerError, Status } from 'nice-grpc'
|
2
|
-
import {
|
2
|
+
import { DebugInfo, RichServerError } from 'nice-grpc-error-details'
|
3
|
+
import { from } from 'ix/Ix.dom.asynciterable.js'
|
4
|
+
import { withAbort } from 'ix/Ix.dom.asynciterable.operators.js'
|
3
5
|
|
4
6
|
import {
|
5
7
|
DataBinding,
|
8
|
+
Empty,
|
6
9
|
HandlerType,
|
7
10
|
ProcessBindingResponse,
|
8
11
|
ProcessBindingsRequest,
|
@@ -10,14 +13,15 @@ import {
|
|
10
13
|
ProcessConfigResponse,
|
11
14
|
ProcessorServiceImplementation,
|
12
15
|
ProcessResult,
|
13
|
-
|
14
|
-
|
16
|
+
ProcessStreamRequest,
|
17
|
+
StartRequest
|
15
18
|
} from '@sentio/protos'
|
16
19
|
|
17
20
|
import { PluginManager } from './plugin.js'
|
18
21
|
import { errorString, mergeProcessResults } from './utils.js'
|
19
22
|
import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js'
|
20
23
|
|
24
|
+
import { StoreContext } from './db-context.js'
|
21
25
|
;(BigInt.prototype as any).toJSON = function () {
|
22
26
|
return this.toString()
|
23
27
|
}
|
@@ -153,19 +157,43 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
153
157
|
return result
|
154
158
|
}
|
155
159
|
|
156
|
-
async *processBindingsStream(requests: AsyncIterable<
|
157
|
-
|
158
|
-
|
159
|
-
// let updated = false
|
160
|
-
// if (PluginManager.INSTANCE.stateDiff(this.processorConfig)) {
|
161
|
-
// await this.configure()
|
162
|
-
// updated = true
|
163
|
-
// }
|
164
|
-
yield {
|
165
|
-
result,
|
166
|
-
configUpdated: result.states?.configUpdated || false
|
167
|
-
}
|
160
|
+
async *processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext) {
|
161
|
+
if (!this.started) {
|
162
|
+
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
168
163
|
}
|
164
|
+
|
165
|
+
const dbContext = new StoreContext()
|
166
|
+
new Promise(async (resolve, reject) => {
|
167
|
+
for await (const request of requests) {
|
168
|
+
if (request.binding) {
|
169
|
+
const binding = request.binding
|
170
|
+
PluginManager.INSTANCE.processBinding(binding, dbContext)
|
171
|
+
.then((result) => {
|
172
|
+
dbContext.subject.next({
|
173
|
+
result,
|
174
|
+
processId: request.processId
|
175
|
+
})
|
176
|
+
// dbContext.subject.complete()
|
177
|
+
recordRuntimeInfo(result, binding.handlerType)
|
178
|
+
})
|
179
|
+
.catch((e) => {
|
180
|
+
dbContext.error(request.processId, e)
|
181
|
+
})
|
182
|
+
}
|
183
|
+
if (request.dbResult) {
|
184
|
+
dbContext.result(request.dbResult)
|
185
|
+
}
|
186
|
+
}
|
187
|
+
resolve(null)
|
188
|
+
})
|
189
|
+
.then(() => {
|
190
|
+
dbContext.subject.complete()
|
191
|
+
})
|
192
|
+
.catch((e) => {
|
193
|
+
// should not happen
|
194
|
+
dbContext.subject.error(e)
|
195
|
+
})
|
196
|
+
yield* from(dbContext.subject).pipe(withAbort(context.signal))
|
169
197
|
}
|
170
198
|
}
|
171
199
|
|