@sentio/runtime 2.59.0-rc.3 → 2.59.0-rc.30

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.
@@ -313,6 +313,59 @@ export interface UsageTracker {
313
313
  versionField: string;
314
314
  }
315
315
 
316
+ export interface AuthChecker {
317
+ projectIdField: string;
318
+ projectSlugField: string;
319
+ projectOwnerField: string;
320
+ projectPermission: AuthChecker_Permission;
321
+ loaderName: string;
322
+ }
323
+
324
+ export enum AuthChecker_Permission {
325
+ NONE = 0,
326
+ READ = 1,
327
+ WRITE = 2,
328
+ ADMIN = 3,
329
+ UNRECOGNIZED = -1,
330
+ }
331
+
332
+ export function authChecker_PermissionFromJSON(object: any): AuthChecker_Permission {
333
+ switch (object) {
334
+ case 0:
335
+ case "NONE":
336
+ return AuthChecker_Permission.NONE;
337
+ case 1:
338
+ case "READ":
339
+ return AuthChecker_Permission.READ;
340
+ case 2:
341
+ case "WRITE":
342
+ return AuthChecker_Permission.WRITE;
343
+ case 3:
344
+ case "ADMIN":
345
+ return AuthChecker_Permission.ADMIN;
346
+ case -1:
347
+ case "UNRECOGNIZED":
348
+ default:
349
+ return AuthChecker_Permission.UNRECOGNIZED;
350
+ }
351
+ }
352
+
353
+ export function authChecker_PermissionToJSON(object: AuthChecker_Permission): string {
354
+ switch (object) {
355
+ case AuthChecker_Permission.NONE:
356
+ return "NONE";
357
+ case AuthChecker_Permission.READ:
358
+ return "READ";
359
+ case AuthChecker_Permission.WRITE:
360
+ return "WRITE";
361
+ case AuthChecker_Permission.ADMIN:
362
+ return "ADMIN";
363
+ case AuthChecker_Permission.UNRECOGNIZED:
364
+ default:
365
+ return "UNRECOGNIZED";
366
+ }
367
+ }
368
+
316
369
  export interface AccessMeta {
317
370
  projectIdField: string;
318
371
  projectSlugField: string;
@@ -423,6 +476,7 @@ export interface Project {
423
476
  /** @deprecated */
424
477
  enableMaterializedView: boolean;
425
478
  defaultTimerange: TimeRangeLite | undefined;
479
+ communityProject?: CommunityProject | undefined;
426
480
  }
427
481
 
428
482
  export enum Project_Visibility {
@@ -502,6 +556,11 @@ export interface Project_ProjectMember {
502
556
  role: string;
503
557
  }
504
558
 
559
+ export interface CommunityProject {
560
+ dashAlias: string;
561
+ curated?: boolean | undefined;
562
+ }
563
+
505
564
  export interface ProjectInfo {
506
565
  id: string;
507
566
  displayName: string;
@@ -645,6 +704,7 @@ export interface Formula {
645
704
  id: string;
646
705
  disabled: boolean;
647
706
  functions: Function[];
707
+ color: string;
648
708
  }
649
709
 
650
710
  export interface Argument {
@@ -1585,6 +1645,7 @@ export interface Account {
1585
1645
  address: string;
1586
1646
  paymentMethod: PayMethod;
1587
1647
  usageOverCapLimit: string;
1648
+ status: string;
1588
1649
  }
1589
1650
 
1590
1651
  export interface ImportedProject {
@@ -2175,6 +2236,125 @@ export const UsageTracker = {
2175
2236
  },
2176
2237
  };
2177
2238
 
2239
+ function createBaseAuthChecker(): AuthChecker {
2240
+ return { projectIdField: "", projectSlugField: "", projectOwnerField: "", projectPermission: 0, loaderName: "" };
2241
+ }
2242
+
2243
+ export const AuthChecker = {
2244
+ encode(message: AuthChecker, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
2245
+ if (message.projectIdField !== "") {
2246
+ writer.uint32(10).string(message.projectIdField);
2247
+ }
2248
+ if (message.projectSlugField !== "") {
2249
+ writer.uint32(18).string(message.projectSlugField);
2250
+ }
2251
+ if (message.projectOwnerField !== "") {
2252
+ writer.uint32(26).string(message.projectOwnerField);
2253
+ }
2254
+ if (message.projectPermission !== 0) {
2255
+ writer.uint32(32).int32(message.projectPermission);
2256
+ }
2257
+ if (message.loaderName !== "") {
2258
+ writer.uint32(42).string(message.loaderName);
2259
+ }
2260
+ return writer;
2261
+ },
2262
+
2263
+ decode(input: _m0.Reader | Uint8Array, length?: number): AuthChecker {
2264
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
2265
+ let end = length === undefined ? reader.len : reader.pos + length;
2266
+ const message = createBaseAuthChecker();
2267
+ while (reader.pos < end) {
2268
+ const tag = reader.uint32();
2269
+ switch (tag >>> 3) {
2270
+ case 1:
2271
+ if (tag !== 10) {
2272
+ break;
2273
+ }
2274
+
2275
+ message.projectIdField = reader.string();
2276
+ continue;
2277
+ case 2:
2278
+ if (tag !== 18) {
2279
+ break;
2280
+ }
2281
+
2282
+ message.projectSlugField = reader.string();
2283
+ continue;
2284
+ case 3:
2285
+ if (tag !== 26) {
2286
+ break;
2287
+ }
2288
+
2289
+ message.projectOwnerField = reader.string();
2290
+ continue;
2291
+ case 4:
2292
+ if (tag !== 32) {
2293
+ break;
2294
+ }
2295
+
2296
+ message.projectPermission = reader.int32() as any;
2297
+ continue;
2298
+ case 5:
2299
+ if (tag !== 42) {
2300
+ break;
2301
+ }
2302
+
2303
+ message.loaderName = reader.string();
2304
+ continue;
2305
+ }
2306
+ if ((tag & 7) === 4 || tag === 0) {
2307
+ break;
2308
+ }
2309
+ reader.skipType(tag & 7);
2310
+ }
2311
+ return message;
2312
+ },
2313
+
2314
+ fromJSON(object: any): AuthChecker {
2315
+ return {
2316
+ projectIdField: isSet(object.projectIdField) ? globalThis.String(object.projectIdField) : "",
2317
+ projectSlugField: isSet(object.projectSlugField) ? globalThis.String(object.projectSlugField) : "",
2318
+ projectOwnerField: isSet(object.projectOwnerField) ? globalThis.String(object.projectOwnerField) : "",
2319
+ projectPermission: isSet(object.projectPermission) ? authChecker_PermissionFromJSON(object.projectPermission) : 0,
2320
+ loaderName: isSet(object.loaderName) ? globalThis.String(object.loaderName) : "",
2321
+ };
2322
+ },
2323
+
2324
+ toJSON(message: AuthChecker): unknown {
2325
+ const obj: any = {};
2326
+ if (message.projectIdField !== "") {
2327
+ obj.projectIdField = message.projectIdField;
2328
+ }
2329
+ if (message.projectSlugField !== "") {
2330
+ obj.projectSlugField = message.projectSlugField;
2331
+ }
2332
+ if (message.projectOwnerField !== "") {
2333
+ obj.projectOwnerField = message.projectOwnerField;
2334
+ }
2335
+ if (message.projectPermission !== 0) {
2336
+ obj.projectPermission = authChecker_PermissionToJSON(message.projectPermission);
2337
+ }
2338
+ if (message.loaderName !== "") {
2339
+ obj.loaderName = message.loaderName;
2340
+ }
2341
+ return obj;
2342
+ },
2343
+
2344
+ create(base?: DeepPartial<AuthChecker>): AuthChecker {
2345
+ return AuthChecker.fromPartial(base ?? {});
2346
+ },
2347
+ fromPartial(object: DeepPartial<AuthChecker>): AuthChecker {
2348
+ const message = createBaseAuthChecker();
2349
+ message.projectIdField = object.projectIdField ?? "";
2350
+ message.projectSlugField = object.projectSlugField ?? "";
2351
+ message.projectOwnerField = object.projectOwnerField ?? "";
2352
+ message.projectPermission = object.projectPermission ?? 0;
2353
+ message.loaderName = object.loaderName ?? "";
2354
+ return message;
2355
+ },
2356
+ };
2357
+
2178
2358
  function createBaseAccessMeta(): AccessMeta {
2179
2359
  return {
2180
2360
  projectIdField: "",
@@ -2838,6 +3018,7 @@ function createBaseProject(): Project {
2838
3018
  enableDisk: false,
2839
3019
  enableMaterializedView: false,
2840
3020
  defaultTimerange: undefined,
3021
+ communityProject: undefined,
2841
3022
  };
2842
3023
  }
2843
3024
 
@@ -2909,6 +3090,9 @@ export const Project = {
2909
3090
  if (message.defaultTimerange !== undefined) {
2910
3091
  TimeRangeLite.encode(message.defaultTimerange, writer.uint32(170).fork()).ldelim();
2911
3092
  }
3093
+ if (message.communityProject !== undefined) {
3094
+ CommunityProject.encode(message.communityProject, writer.uint32(178).fork()).ldelim();
3095
+ }
2912
3096
  return writer;
2913
3097
  },
2914
3098
 
@@ -3059,6 +3243,13 @@ export const Project = {
3059
3243
 
3060
3244
  message.defaultTimerange = TimeRangeLite.decode(reader, reader.uint32());
3061
3245
  continue;
3246
+ case 22:
3247
+ if (tag !== 178) {
3248
+ break;
3249
+ }
3250
+
3251
+ message.communityProject = CommunityProject.decode(reader, reader.uint32());
3252
+ continue;
3062
3253
  }
3063
3254
  if ((tag & 7) === 4 || tag === 0) {
3064
3255
  break;
@@ -3096,6 +3287,7 @@ export const Project = {
3096
3287
  ? globalThis.Boolean(object.enableMaterializedView)
3097
3288
  : false,
3098
3289
  defaultTimerange: isSet(object.defaultTimerange) ? TimeRangeLite.fromJSON(object.defaultTimerange) : undefined,
3290
+ communityProject: isSet(object.communityProject) ? CommunityProject.fromJSON(object.communityProject) : undefined,
3099
3291
  };
3100
3292
  },
3101
3293
 
@@ -3161,6 +3353,9 @@ export const Project = {
3161
3353
  if (message.defaultTimerange !== undefined) {
3162
3354
  obj.defaultTimerange = TimeRangeLite.toJSON(message.defaultTimerange);
3163
3355
  }
3356
+ if (message.communityProject !== undefined) {
3357
+ obj.communityProject = CommunityProject.toJSON(message.communityProject);
3358
+ }
3164
3359
  return obj;
3165
3360
  },
3166
3361
 
@@ -3193,6 +3388,9 @@ export const Project = {
3193
3388
  message.defaultTimerange = (object.defaultTimerange !== undefined && object.defaultTimerange !== null)
3194
3389
  ? TimeRangeLite.fromPartial(object.defaultTimerange)
3195
3390
  : undefined;
3391
+ message.communityProject = (object.communityProject !== undefined && object.communityProject !== null)
3392
+ ? CommunityProject.fromPartial(object.communityProject)
3393
+ : undefined;
3196
3394
  return message;
3197
3395
  },
3198
3396
  };
@@ -3271,6 +3469,80 @@ export const Project_ProjectMember = {
3271
3469
  },
3272
3470
  };
3273
3471
 
3472
+ function createBaseCommunityProject(): CommunityProject {
3473
+ return { dashAlias: "", curated: undefined };
3474
+ }
3475
+
3476
+ export const CommunityProject = {
3477
+ encode(message: CommunityProject, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
3478
+ if (message.dashAlias !== "") {
3479
+ writer.uint32(10).string(message.dashAlias);
3480
+ }
3481
+ if (message.curated !== undefined) {
3482
+ writer.uint32(16).bool(message.curated);
3483
+ }
3484
+ return writer;
3485
+ },
3486
+
3487
+ decode(input: _m0.Reader | Uint8Array, length?: number): CommunityProject {
3488
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
3489
+ let end = length === undefined ? reader.len : reader.pos + length;
3490
+ const message = createBaseCommunityProject();
3491
+ while (reader.pos < end) {
3492
+ const tag = reader.uint32();
3493
+ switch (tag >>> 3) {
3494
+ case 1:
3495
+ if (tag !== 10) {
3496
+ break;
3497
+ }
3498
+
3499
+ message.dashAlias = reader.string();
3500
+ continue;
3501
+ case 2:
3502
+ if (tag !== 16) {
3503
+ break;
3504
+ }
3505
+
3506
+ message.curated = reader.bool();
3507
+ continue;
3508
+ }
3509
+ if ((tag & 7) === 4 || tag === 0) {
3510
+ break;
3511
+ }
3512
+ reader.skipType(tag & 7);
3513
+ }
3514
+ return message;
3515
+ },
3516
+
3517
+ fromJSON(object: any): CommunityProject {
3518
+ return {
3519
+ dashAlias: isSet(object.dashAlias) ? globalThis.String(object.dashAlias) : "",
3520
+ curated: isSet(object.curated) ? globalThis.Boolean(object.curated) : undefined,
3521
+ };
3522
+ },
3523
+
3524
+ toJSON(message: CommunityProject): unknown {
3525
+ const obj: any = {};
3526
+ if (message.dashAlias !== "") {
3527
+ obj.dashAlias = message.dashAlias;
3528
+ }
3529
+ if (message.curated !== undefined) {
3530
+ obj.curated = message.curated;
3531
+ }
3532
+ return obj;
3533
+ },
3534
+
3535
+ create(base?: DeepPartial<CommunityProject>): CommunityProject {
3536
+ return CommunityProject.fromPartial(base ?? {});
3537
+ },
3538
+ fromPartial(object: DeepPartial<CommunityProject>): CommunityProject {
3539
+ const message = createBaseCommunityProject();
3540
+ message.dashAlias = object.dashAlias ?? "";
3541
+ message.curated = object.curated ?? undefined;
3542
+ return message;
3543
+ },
3544
+ };
3545
+
3274
3546
  function createBaseProjectInfo(): ProjectInfo {
3275
3547
  return {
3276
3548
  id: "",
@@ -5434,7 +5706,7 @@ export const Duration = {
5434
5706
  };
5435
5707
 
5436
5708
  function createBaseFormula(): Formula {
5437
- return { expression: "", alias: "", id: "", disabled: false, functions: [] };
5709
+ return { expression: "", alias: "", id: "", disabled: false, functions: [], color: "" };
5438
5710
  }
5439
5711
 
5440
5712
  export const Formula = {
@@ -5454,6 +5726,9 @@ export const Formula = {
5454
5726
  for (const v of message.functions) {
5455
5727
  Function.encode(v!, writer.uint32(50).fork()).ldelim();
5456
5728
  }
5729
+ if (message.color !== "") {
5730
+ writer.uint32(58).string(message.color);
5731
+ }
5457
5732
  return writer;
5458
5733
  },
5459
5734
 
@@ -5499,6 +5774,13 @@ export const Formula = {
5499
5774
 
5500
5775
  message.functions.push(Function.decode(reader, reader.uint32()));
5501
5776
  continue;
5777
+ case 7:
5778
+ if (tag !== 58) {
5779
+ break;
5780
+ }
5781
+
5782
+ message.color = reader.string();
5783
+ continue;
5502
5784
  }
5503
5785
  if ((tag & 7) === 4 || tag === 0) {
5504
5786
  break;
@@ -5517,6 +5799,7 @@ export const Formula = {
5517
5799
  functions: globalThis.Array.isArray(object?.functions)
5518
5800
  ? object.functions.map((e: any) => Function.fromJSON(e))
5519
5801
  : [],
5802
+ color: isSet(object.color) ? globalThis.String(object.color) : "",
5520
5803
  };
5521
5804
  },
5522
5805
 
@@ -5537,6 +5820,9 @@ export const Formula = {
5537
5820
  if (message.functions?.length) {
5538
5821
  obj.functions = message.functions.map((e) => Function.toJSON(e));
5539
5822
  }
5823
+ if (message.color !== "") {
5824
+ obj.color = message.color;
5825
+ }
5540
5826
  return obj;
5541
5827
  },
5542
5828
 
@@ -5550,6 +5836,7 @@ export const Formula = {
5550
5836
  message.id = object.id ?? "";
5551
5837
  message.disabled = object.disabled ?? false;
5552
5838
  message.functions = object.functions?.map((e) => Function.fromPartial(e)) || [];
5839
+ message.color = object.color ?? "";
5553
5840
  return message;
5554
5841
  },
5555
5842
  };
@@ -10202,6 +10489,7 @@ function createBaseAccount(): Account {
10202
10489
  address: "",
10203
10490
  paymentMethod: 0,
10204
10491
  usageOverCapLimit: "",
10492
+ status: "",
10205
10493
  };
10206
10494
  }
10207
10495
 
@@ -10234,6 +10522,9 @@ export const Account = {
10234
10522
  if (message.usageOverCapLimit !== "") {
10235
10523
  writer.uint32(90).string(message.usageOverCapLimit);
10236
10524
  }
10525
+ if (message.status !== "") {
10526
+ writer.uint32(98).string(message.status);
10527
+ }
10237
10528
  return writer;
10238
10529
  },
10239
10530
 
@@ -10307,6 +10598,13 @@ export const Account = {
10307
10598
 
10308
10599
  message.usageOverCapLimit = reader.string();
10309
10600
  continue;
10601
+ case 12:
10602
+ if (tag !== 98) {
10603
+ break;
10604
+ }
10605
+
10606
+ message.status = reader.string();
10607
+ continue;
10310
10608
  }
10311
10609
  if ((tag & 7) === 4 || tag === 0) {
10312
10610
  break;
@@ -10327,6 +10625,7 @@ export const Account = {
10327
10625
  address: isSet(object.address) ? globalThis.String(object.address) : "",
10328
10626
  paymentMethod: isSet(object.paymentMethod) ? payMethodFromJSON(object.paymentMethod) : 0,
10329
10627
  usageOverCapLimit: isSet(object.usageOverCapLimit) ? globalThis.String(object.usageOverCapLimit) : "",
10628
+ status: isSet(object.status) ? globalThis.String(object.status) : "",
10330
10629
  };
10331
10630
  },
10332
10631
 
@@ -10359,6 +10658,9 @@ export const Account = {
10359
10658
  if (message.usageOverCapLimit !== "") {
10360
10659
  obj.usageOverCapLimit = message.usageOverCapLimit;
10361
10660
  }
10661
+ if (message.status !== "") {
10662
+ obj.status = message.status;
10663
+ }
10362
10664
  return obj;
10363
10665
  },
10364
10666
 
@@ -10376,6 +10678,7 @@ export const Account = {
10376
10678
  message.address = object.address ?? "";
10377
10679
  message.paymentMethod = object.paymentMethod ?? 0;
10378
10680
  message.usageOverCapLimit = object.usageOverCapLimit ?? "";
10681
+ message.status = object.status ?? "";
10379
10682
  return message;
10380
10683
  },
10381
10684
  };
package/src/index.ts CHANGED
@@ -8,3 +8,10 @@ export { GLOBAL_CONFIG, type GlobalConfig } from './global-config.js'
8
8
  export * from './db-context.js'
9
9
  export * from './provider.js'
10
10
  export * from './metrics.js'
11
+ export {
12
+ type DataBinding,
13
+ type Data_EthLog,
14
+ type Data_EthBlock,
15
+ type Data_EthTransaction,
16
+ type Data_EthTrace
17
+ } from './gen/processor/protos/processor.js'
package/src/metrics.ts CHANGED
@@ -77,25 +77,29 @@ export const dbMetrics = {
77
77
  get: new C('store_get_send'),
78
78
  upsert: new C('store_upsert_send'),
79
79
  list: new C('store_list_send'),
80
- delete: new C('store_delete_send')
80
+ delete: new C('store_delete_send'),
81
+ update: new C('store_update_send')
81
82
  },
82
83
  recv_counts: {
83
84
  get: new C('store_get_recv'),
84
85
  upsert: new C('store_upsert_recv'),
85
86
  list: new C('store_list_recv'),
86
- delete: new C('store_delete_recv')
87
+ delete: new C('store_delete_recv'),
88
+ update: new C('store_update_recv')
87
89
  },
88
90
  request_times: {
89
91
  get: new C('store_get_time'),
90
92
  upsert: new C('store_upsert_time'),
91
93
  list: new C('store_list_time'),
92
- delete: new C('store_delete_time')
94
+ delete: new C('store_delete_time'),
95
+ update: new C('store_update_time')
93
96
  },
94
97
  request_errors: {
95
98
  get: new C('store_get_error'),
96
99
  upsert: new C('store_upsert_error'),
97
100
  list: new C('store_list_error'),
98
- delete: new C('store_delete_error')
101
+ delete: new C('store_delete_error'),
102
+ update: new C('store_update_error')
99
103
  },
100
104
  batched_total_count: new C('batched_total_count'),
101
105
  batched_request_count: new C('batched_request_count'),
package/src/plugin.ts CHANGED
@@ -5,6 +5,8 @@ import {
5
5
  PreprocessResult,
6
6
  ProcessConfigResponse,
7
7
  ProcessResult,
8
+ ProcessStreamResponse_Partitions,
9
+ ProcessStreamResponse_Partitions_Partition_SysValue,
8
10
  StartRequest
9
11
  } from '@sentio/protos'
10
12
  import { IStoreContext, StoreContext } from './db-context.js'
@@ -33,6 +35,20 @@ export abstract class Plugin {
33
35
  return PreprocessResult.create()
34
36
  }
35
37
 
38
+ async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
39
+ return {
40
+ partitions: request.handlerIds.reduce(
41
+ (acc, id) => ({
42
+ ...acc,
43
+ [id]: {
44
+ sysValue: ProcessStreamResponse_Partitions_Partition_SysValue.UNRECOGNIZED
45
+ }
46
+ }),
47
+ {}
48
+ )
49
+ }
50
+ }
51
+
36
52
  /**
37
53
  * method used by action server only
38
54
  * @param port
@@ -104,6 +120,14 @@ export class PluginManager {
104
120
  })
105
121
  }
106
122
 
123
+ async partition(request: DataBinding): Promise<ProcessStreamResponse_Partitions> {
124
+ const plugin = this.typesToPlugin.get(request.handlerType)
125
+ if (!plugin) {
126
+ throw new Error(`No plugin for ${request.handlerType}`)
127
+ }
128
+ return plugin.partition(request)
129
+ }
130
+
107
131
  preprocessBinding(
108
132
  request: DataBinding,
109
133
  preprocessStore: { [k: string]: any },
@@ -1,4 +1,4 @@
1
- import { CallContext } from 'nice-grpc'
1
+ import { CallContext, ServerError, Status } from 'nice-grpc'
2
2
  import { Piscina } from 'piscina'
3
3
  import {
4
4
  DataBinding,
@@ -22,6 +22,7 @@ import { processMetrics } from './metrics.js'
22
22
  import { MessageChannel } from 'node:worker_threads'
23
23
  import { ProcessorServiceImpl } from './service.js'
24
24
  import { TemplateInstanceState } from './state.js'
25
+ import { PluginManager } from './plugin.js'
25
26
 
26
27
  const { process_binding_count, process_binding_time, process_binding_error } = processMetrics
27
28
 
@@ -70,17 +71,6 @@ export class ServiceManager extends ProcessorServiceImpl {
70
71
  return await super.stop(request, context)
71
72
  }
72
73
 
73
- async process(request: DataBinding, dbContext?: ChannelStoreContext): Promise<ProcessResult> {
74
- if (!this.pool) {
75
- await this.initPool()
76
- }
77
-
78
- return this.pool.run(
79
- { request, workerPort: dbContext?.workerPort },
80
- { transferList: dbContext?.workerPort ? [dbContext?.workerPort] : [] }
81
- )
82
- }
83
-
84
74
  private readonly contexts = new Contexts()
85
75
 
86
76
  protected async handleRequests(
@@ -88,6 +78,8 @@ export class ServiceManager extends ProcessorServiceImpl {
88
78
  subject: Subject<DeepPartial<ProcessStreamResponse>>
89
79
  ) {
90
80
  for await (const request of requests) {
81
+ let lastBinding: DataBinding | undefined = undefined
82
+
91
83
  try {
92
84
  // console.debug('received request:', request)
93
85
  if (request.binding) {
@@ -103,27 +95,23 @@ export class ServiceManager extends ProcessorServiceImpl {
103
95
  continue
104
96
  }
105
97
 
106
- const binding = request.binding
107
-
108
- const dbContext = this.contexts.new(request.processId, subject)
109
-
110
- const start = Date.now()
111
- this.process(binding, dbContext)
112
- .then(async (result) => {
98
+ if (this.enablePartition) {
99
+ PluginManager.INSTANCE.partition(request.binding).then((partitions) => {
113
100
  subject.next({
114
- result,
115
- processId: request.processId
101
+ processId: request.processId,
102
+ partitions
116
103
  })
117
104
  })
118
- .catch((e) => {
119
- dbContext.error(request.processId, e)
120
- process_binding_error.add(1)
121
- })
122
- .finally(() => {
123
- const cost = Date.now() - start
124
- process_binding_time.add(cost)
125
- this.contexts.delete(request.processId)
126
- })
105
+ lastBinding = request.binding
106
+ } else {
107
+ this.doProcess(request.processId, request.binding, subject)
108
+ }
109
+ }
110
+ if (request.start) {
111
+ if (!lastBinding) {
112
+ throw new ServerError(Status.INVALID_ARGUMENT, 'start request received without binding')
113
+ }
114
+ this.doProcess(request.processId, lastBinding, subject)
127
115
  }
128
116
  if (request.dbResult) {
129
117
  const dbContext = this.contexts.get(request.processId)
@@ -140,6 +128,39 @@ export class ServiceManager extends ProcessorServiceImpl {
140
128
  }
141
129
  }
142
130
 
131
+ private doProcess(processId: number, binding: DataBinding, subject: Subject<DeepPartial<ProcessStreamResponse>>) {
132
+ const dbContext = this.contexts.new(processId, subject)
133
+
134
+ const start = Date.now()
135
+ this.process(binding, dbContext)
136
+ .then(async (result) => {
137
+ subject.next({
138
+ result,
139
+ processId: processId
140
+ })
141
+ })
142
+ .catch((e) => {
143
+ dbContext.error(processId, e)
144
+ process_binding_error.add(1)
145
+ })
146
+ .finally(() => {
147
+ const cost = Date.now() - start
148
+ process_binding_time.add(cost)
149
+ this.contexts.delete(processId)
150
+ })
151
+ }
152
+
153
+ async process(request: DataBinding, dbContext?: ChannelStoreContext): Promise<ProcessResult> {
154
+ if (!this.pool) {
155
+ await this.initPool()
156
+ }
157
+
158
+ return this.pool.run(
159
+ { request, workerPort: dbContext?.workerPort },
160
+ { transferList: dbContext?.workerPort ? [dbContext?.workerPort] : [] }
161
+ )
162
+ }
163
+
143
164
  private async initPool() {
144
165
  if (this.pool) {
145
166
  await this.pool.close()