@sentio/runtime 2.40.0-rc.32 → 2.40.0-rc.33

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.
@@ -59717,6 +59717,7 @@ var _StoreContext = class {
59717
59717
  }
59718
59718
  defers = /* @__PURE__ */ new Map();
59719
59719
  statsInterval;
59720
+ pendings = [];
59720
59721
  newPromise(opId, requestType) {
59721
59722
  return new Promise((resolve, reject) => {
59722
59723
  this.defers.set(opId, { resolve, reject, requestType });
@@ -59746,6 +59747,7 @@ var _StoreContext = class {
59746
59747
  });
59747
59748
  send_counts[requestType]?.add(1);
59748
59749
  if (requestType === "upsert" && STORE_UPSERT_NO_WAIT) {
59750
+ this.pendings.push(promise);
59749
59751
  return Promise.resolve({
59750
59752
  opId
59751
59753
  });
@@ -59776,10 +59778,6 @@ var _StoreContext = class {
59776
59778
  recv_counts[defer.requestType]?.add(1);
59777
59779
  }
59778
59780
  if (dbResult.error) {
59779
- if (defer.requestType == "upsert" && STORE_UPSERT_NO_WAIT) {
59780
- console.error("upsert no_wait enabled, the error may not be thrown in user function", dbResult.error);
59781
- throw new Error(dbResult.error);
59782
- }
59783
59781
  defer.reject(new Error(dbResult.error));
59784
59782
  } else {
59785
59783
  defer.resolve(dbResult);
@@ -59841,11 +59839,13 @@ var _StoreContext = class {
59841
59839
  timer: timeout
59842
59840
  };
59843
59841
  if (STORE_UPSERT_NO_WAIT) {
59842
+ this.pendings.push(promise);
59844
59843
  return {
59845
59844
  opId: this.upsertBatch.opId
59846
59845
  };
59846
+ } else {
59847
+ return promise;
59847
59848
  }
59848
- return promise;
59849
59849
  }
59850
59850
  }
59851
59851
  sendBatch() {
@@ -59865,6 +59865,9 @@ var _StoreContext = class {
59865
59865
  batched_total_count.add(request.entity.length);
59866
59866
  }
59867
59867
  }
59868
+ async awaitPendings() {
59869
+ await Promise.all(this.pendings);
59870
+ }
59868
59871
  };
59869
59872
  var StoreContext = _StoreContext;
59870
59873
  __publicField(StoreContext, "opCounter", 0n);
@@ -80407,7 +80410,8 @@ var ProcessorServiceImpl = class {
80407
80410
  const binding = request.binding;
80408
80411
  const dbContext = contexts.new(request.processId, subject);
80409
80412
  const start = Date.now();
80410
- PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext).then((result) => {
80413
+ PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext).then(async (result) => {
80414
+ await dbContext.awaitPendings();
80411
80415
  subject.next({
80412
80416
  result,
80413
80417
  processId: request.processId
package/lib/index.d.ts CHANGED
@@ -17,6 +17,7 @@ declare class StoreContext {
17
17
  private static opCounter;
18
18
  private defers;
19
19
  private statsInterval;
20
+ private pendings;
20
21
  constructor(subject: Subject<DeepPartial$1<ProcessStreamResponse>>, processId: number);
21
22
  newPromise<T>(opId: bigint, requestType?: RequestType): Promise<T>;
22
23
  sendRequest(request: DeepPartial$1<Request>, timeoutSecs?: number): Promise<DBResponse>;
@@ -31,6 +32,7 @@ declare class StoreContext {
31
32
  } | undefined;
32
33
  private sendUpsertInBatch;
33
34
  private sendBatch;
35
+ awaitPendings(): Promise<void>;
34
36
  }
35
37
 
36
38
  declare abstract class Plugin {
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  makeEthCallKey,
15
15
  mergeProcessResults,
16
16
  timeoutError
17
- } from "./chunk-KVYXDEGV.js";
17
+ } from "./chunk-4SVLLI4X.js";
18
18
 
19
19
  // src/state.ts
20
20
  var _State = class {
@@ -41,7 +41,7 @@ import {
41
41
  require_minimal,
42
42
  require_src,
43
43
  trace
44
- } from "./chunk-KVYXDEGV.js";
44
+ } from "./chunk-4SVLLI4X.js";
45
45
 
46
46
  // ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
47
47
  var require_universalify = __commonJS({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.40.0-rc.32",
3
+ "version": "2.40.0-rc.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
package/src/db-context.ts CHANGED
@@ -29,12 +29,12 @@ export const timeoutError = new Error('timeout')
29
29
 
30
30
  export class StoreContext {
31
31
  private static opCounter = 0n
32
-
33
32
  private defers = new Map<
34
33
  bigint,
35
34
  { resolve: (value: any) => void; reject: (reason?: any) => void; requestType?: RequestType }
36
35
  >()
37
36
  private statsInterval: NodeJS.Timeout | undefined
37
+ private pendings: Promise<unknown>[] = []
38
38
 
39
39
  constructor(
40
40
  readonly subject: Subject<DeepPartial<ProcessStreamResponse>>,
@@ -78,7 +78,7 @@ export class StoreContext {
78
78
  send_counts[requestType]?.add(1)
79
79
 
80
80
  if (requestType === 'upsert' && STORE_UPSERT_NO_WAIT) {
81
-
81
+ this.pendings.push(promise)
82
82
  return Promise.resolve({
83
83
  opId,
84
84
  } as DBResponse)
@@ -115,11 +115,6 @@ export class StoreContext {
115
115
  recv_counts[defer.requestType]?.add(1)
116
116
  }
117
117
  if (dbResult.error) {
118
- if (defer.requestType == 'upsert' && STORE_UPSERT_NO_WAIT) {
119
- console.error('upsert no_wait enabled, the error may not be thrown in user function', dbResult.error)
120
- throw new Error(dbResult.error)
121
- }
122
-
123
118
  defer.reject(new Error(dbResult.error))
124
119
  } else {
125
120
  defer.resolve(dbResult)
@@ -197,12 +192,13 @@ export class StoreContext {
197
192
  }
198
193
 
199
194
  if (STORE_UPSERT_NO_WAIT) {
195
+ this.pendings.push(promise)
200
196
  return {
201
197
  opId: this.upsertBatch.opId
202
198
  }
199
+ } else {
200
+ return promise
203
201
  }
204
-
205
- return promise
206
202
  }
207
203
  }
208
204
 
@@ -224,4 +220,8 @@ export class StoreContext {
224
220
  batched_total_count.add(request.entity.length)
225
221
  }
226
222
  }
223
+
224
+ async awaitPendings() {
225
+ await Promise.all(this.pendings)
226
+ }
227
227
  }
package/src/service.ts CHANGED
@@ -410,7 +410,9 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
410
410
  const dbContext = contexts.new(request.processId, subject)
411
411
  const start = Date.now()
412
412
  PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
413
- .then((result) => {
413
+ .then(async (result) => {
414
+ // await all pending db requests
415
+ await dbContext.awaitPendings()
414
416
  subject.next({
415
417
  result,
416
418
  processId: request.processId