@reboot-dev/reboot 0.31.0 → 0.33.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/index.d.ts CHANGED
@@ -41,6 +41,9 @@ export declare class ExternalContext {
41
41
  get __external(): any;
42
42
  generateIdempotentStateId(stateType: string, serviceName: string, method: string, idempotency: IdempotencyOptions): Promise<string>;
43
43
  }
44
+ export declare class InitializeContext extends ExternalContext {
45
+ static fromNativeExternal(external: any): InitializeContext;
46
+ }
44
47
  export declare function getContext(): Context;
45
48
  export declare function isWithinUntil(): boolean;
46
49
  export declare function isWithinLoop(): boolean;
@@ -54,6 +57,8 @@ export declare class Context {
54
57
  get __external(): any;
55
58
  get auth(): Auth | null;
56
59
  get stateId(): string;
60
+ get stateTypeName(): string;
61
+ get method(): string;
57
62
  get callerBearerToken(): string | null;
58
63
  get cookie(): string;
59
64
  get appInternal(): boolean;
@@ -197,7 +202,7 @@ export declare class Application {
197
202
  #private;
198
203
  constructor({ servicers, initialize, initializeBearerToken, tokenVerifier, }: {
199
204
  servicers: ServicerFactory[];
200
- initialize?: (context: ExternalContext) => Promise<void>;
205
+ initialize?: (context: InitializeContext) => Promise<void>;
201
206
  initializeBearerToken?: string;
202
207
  tokenVerifier?: TokenVerifier;
203
208
  });
package/index.js CHANGED
@@ -9,8 +9,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Reboot_external, _ExternalContext_external, _a, _Context_external, _Context_isInternalConstructing, _Context_stateId, _ReaderContext_kind, _WriterContext_kind, _TransactionContext_kind, _WorkflowContext_kind, _Application_servicers, _Application_tokenVerifier, _Application_express, _Application_http, _Application_servers, _Application_createExternalContext, _Application_external;
13
- import { auth_pb, errors_pb, protobuf_es, tasks_pb, } from "@reboot-dev/reboot-api";
12
+ var _Reboot_external, _ExternalContext_external, _a, _Context_external, _Context_isInternalConstructing, _Context_stateId, _Context_method, _Context_stateTypeName, _ReaderContext_kind, _WriterContext_kind, _TransactionContext_kind, _WorkflowContext_kind, _Application_servicers, _Application_tokenVerifier, _Application_express, _Application_http, _Application_servers, _Application_createExternalContext, _Application_external;
13
+ import { auth_pb, errors_pb, protobuf_es, toCamelCase, tasks_pb, } from "@reboot-dev/reboot-api";
14
14
  import { strict as assert } from "assert";
15
15
  import { AsyncLocalStorage } from "node:async_hooks";
16
16
  import { fork } from "node:child_process";
@@ -126,6 +126,11 @@ export class ExternalContext {
126
126
  }
127
127
  }
128
128
  _ExternalContext_external = new WeakMap();
129
+ export class InitializeContext extends ExternalContext {
130
+ static fromNativeExternal(external) {
131
+ return new InitializeContext({ external });
132
+ }
133
+ }
129
134
  const contextStorage = new AsyncLocalStorage();
130
135
  export function getContext() {
131
136
  const store = contextStorage.getStore();
@@ -166,6 +171,8 @@ export class Context {
166
171
  constructor(external, cancelled) {
167
172
  _Context_external.set(this, void 0);
168
173
  _Context_stateId.set(this, void 0);
174
+ _Context_method.set(this, void 0);
175
+ _Context_stateTypeName.set(this, void 0);
169
176
  if (!__classPrivateFieldGet(_a, _a, "f", _Context_isInternalConstructing)) {
170
177
  throw new TypeError("Context is not publicly constructable");
171
178
  }
@@ -205,6 +212,18 @@ export class Context {
205
212
  }
206
213
  return __classPrivateFieldGet(this, _Context_stateId, "f");
207
214
  }
215
+ get stateTypeName() {
216
+ if (__classPrivateFieldGet(this, _Context_stateTypeName, "f") === undefined) {
217
+ __classPrivateFieldSet(this, _Context_stateTypeName, reboot_native.Context_stateTypeName(__classPrivateFieldGet(this, _Context_external, "f")), "f");
218
+ }
219
+ return __classPrivateFieldGet(this, _Context_stateTypeName, "f");
220
+ }
221
+ get method() {
222
+ if (__classPrivateFieldGet(this, _Context_method, "f") === undefined) {
223
+ __classPrivateFieldSet(this, _Context_method, toCamelCase(reboot_native.Context_method(__classPrivateFieldGet(this, _Context_external, "f"))), "f");
224
+ }
225
+ return __classPrivateFieldGet(this, _Context_method, "f");
226
+ }
208
227
  get callerBearerToken() {
209
228
  return reboot_native.Context_callerBearerToken(__classPrivateFieldGet(this, _Context_external, "f"));
210
229
  }
@@ -218,7 +237,7 @@ export class Context {
218
237
  return reboot_native.Context_generateIdempotentStateId(__classPrivateFieldGet(this, _Context_external, "f"), stateType, serviceName, method, idempotency);
219
238
  }
220
239
  }
221
- _a = Context, _Context_external = new WeakMap(), _Context_stateId = new WeakMap();
240
+ _a = Context, _Context_external = new WeakMap(), _Context_stateId = new WeakMap(), _Context_method = new WeakMap(), _Context_stateTypeName = new WeakMap();
222
241
  _Context_isInternalConstructing = { value: false };
223
242
  export class ReaderContext extends Context {
224
243
  constructor(external, cancelled) {
@@ -521,7 +540,13 @@ export class Application {
521
540
  return await __classPrivateFieldGet(this, _Application_createExternalContext, "f").call(this, args);
522
541
  }), "f");
523
542
  __classPrivateFieldSet(this, _Application_servers, new Map(), "f");
524
- __classPrivateFieldSet(this, _Application_external, reboot_native.Application_constructor(ExternalContext.fromNativeExternal, servicers, {
543
+ __classPrivateFieldSet(this, _Application_external, reboot_native.Application_constructor((external, kind) => {
544
+ if (kind === "external") {
545
+ return ExternalContext.fromNativeExternal(external);
546
+ }
547
+ assert(kind === "initialize");
548
+ return InitializeContext.fromNativeExternal(external);
549
+ }, servicers, {
525
550
  start: async (consensusId, port, createExternalContext) => {
526
551
  // Store `createExternalContext` function before listening
527
552
  // so we don't attempt to serve any traffic and try and use
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "@bufbuild/protobuf": "1.3.2",
4
4
  "@bufbuild/protoplugin": "1.3.2",
5
5
  "@bufbuild/protoc-gen-es": "1.3.2",
6
- "@reboot-dev/reboot-api": "0.31.0",
6
+ "@reboot-dev/reboot-api": "0.33.0",
7
7
  "chalk": "^4.1.2",
8
8
  "node-addon-api": "^7.0.0",
9
9
  "node-gyp": ">=10.2.0",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "type": "module",
20
20
  "name": "@reboot-dev/reboot",
21
- "version": "0.31.0",
21
+ "version": "0.33.0",
22
22
  "description": "npm package for Reboot",
23
23
  "scripts": {
24
24
  "preinstall": "node preinstall.cjs",
@@ -41,7 +41,7 @@
41
41
  "protoc-gen-es": "./protoc-gen-es.js"
42
42
  },
43
43
  "engines": {
44
- "node": ">=18.0.0"
44
+ "node": ">=20.10.0"
45
45
  },
46
46
  "engineStrict": true,
47
47
  "gypfile": true,
package/reboot_native.cc CHANGED
@@ -2173,7 +2173,9 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2173
2173
  .Value(env)
2174
2174
  .Call(
2175
2175
  env.Global(),
2176
- {js_external_context});
2176
+ {js_external_context,
2177
+ // (check_line_length skip)
2178
+ Napi::String::New(env, "external")});
2177
2179
  });
2178
2180
  });
2179
2181
 
@@ -2236,7 +2238,8 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2236
2238
  .Value(env)
2237
2239
  .Call(
2238
2240
  env.Global(),
2239
- {js_external_context})
2241
+ {js_external_context,
2242
+ Napi::String::New(env, "initialize")})
2240
2243
  .As<Napi::Object>();
2241
2244
 
2242
2245
  return js_initialize
@@ -2374,6 +2377,43 @@ Napi::Value Context_stateId(const Napi::CallbackInfo& info) {
2374
2377
  return Napi::String::New(info.Env(), state_id);
2375
2378
  }
2376
2379
 
2380
+
2381
+ Napi::Value Context_stateTypeName(const Napi::CallbackInfo& info) {
2382
+ Napi::External<py::object> js_external_context =
2383
+ info[0].As<Napi::External<py::object>>();
2384
+
2385
+ // CHECK(...CheckTypeTag(...));
2386
+
2387
+ py::object* py_context = js_external_context.Data();
2388
+
2389
+ std::string state_type_name = RunCallbackOnPythonEventLoop(
2390
+ [py_context]() {
2391
+ py::str state_type_name = py_context->attr("state_type_name");
2392
+ return std::string(state_type_name);
2393
+ });
2394
+
2395
+ return Napi::String::New(info.Env(), state_type_name);
2396
+ }
2397
+
2398
+
2399
+ Napi::Value Context_method(const Napi::CallbackInfo& info) {
2400
+ Napi::External<py::object> js_external_context =
2401
+ info[0].As<Napi::External<py::object>>();
2402
+
2403
+ // CHECK(...CheckTypeTag(...));
2404
+
2405
+ py::object* py_context = js_external_context.Data();
2406
+
2407
+ std::string method = RunCallbackOnPythonEventLoop(
2408
+ [py_context]() {
2409
+ py::str method = py_context->attr("method");
2410
+ return std::string(method);
2411
+ });
2412
+
2413
+ return Napi::String::New(info.Env(), method);
2414
+ }
2415
+
2416
+
2377
2417
  Napi::Value Context_callerBearerToken(
2378
2418
  const Napi::CallbackInfo& info) {
2379
2419
  Napi::External<py::object> js_external_context =
@@ -2879,6 +2919,14 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
2879
2919
  Napi::String::New(env, "Context_stateId"),
2880
2920
  Napi::Function::New<Context_stateId>(env));
2881
2921
 
2922
+ exports.Set(
2923
+ Napi::String::New(env, "Context_stateTypeName"),
2924
+ Napi::Function::New<Context_stateTypeName>(env));
2925
+
2926
+ exports.Set(
2927
+ Napi::String::New(env, "Context_method"),
2928
+ Napi::Function::New<Context_method>(env));
2929
+
2882
2930
  exports.Set(
2883
2931
  Napi::String::New(env, "Context_callerBearerToken"),
2884
2932
  Napi::Function::New<Context_callerBearerToken>(env));
package/reboot_native.cjs CHANGED
@@ -76,6 +76,8 @@ exports.Reboot_down = reboot_native.exports.Reboot_down;
76
76
  exports.Reboot_url = reboot_native.exports.Reboot_url;
77
77
  exports.Context_auth = reboot_native.exports.Context_auth;
78
78
  exports.Context_stateId = reboot_native.exports.Context_stateId;
79
+ exports.Context_stateTypeName = reboot_native.exports.Context_stateTypeName;
80
+ exports.Context_method = reboot_native.exports.Context_method;
79
81
  exports.Context_callerBearerToken =
80
82
  reboot_native.exports.Context_callerBearerToken;
81
83
  exports.Context_cookie = reboot_native.exports.Context_cookie;
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const REBOOT_VERSION = "0.31.0";
1
+ export declare const REBOOT_VERSION = "0.33.0";
package/version.js CHANGED
@@ -1 +1 @@
1
- export const REBOOT_VERSION = "0.31.0";
1
+ export const REBOOT_VERSION = "0.33.0";