@reboot-dev/reboot 0.20.0 → 0.21.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.
@@ -18,8 +18,10 @@ export declare class Reboot {
18
18
  stop(): Promise<void>;
19
19
  up(servicers: any, options?: {
20
20
  tokenVerifier?: TokenVerifier;
21
+ localEnvoy?: boolean;
21
22
  }): Promise<ApplicationConfig>;
22
23
  down(): Promise<void>;
24
+ url(): string;
23
25
  }
24
26
  export declare class ExternalContext {
25
27
  #private;
@@ -81,11 +81,14 @@ export class Reboot {
81
81
  async up(servicers, options) {
82
82
  // TODO(benh): determine module and file name so that we can
83
83
  // namespace if we have more than one implementation of servicers.
84
- return await reboot_native.Reboot_up(__classPrivateFieldGet(this, _Reboot_external, "f"), servicers, options?.tokenVerifier);
84
+ return await reboot_native.Reboot_up(__classPrivateFieldGet(this, _Reboot_external, "f"), servicers, options?.tokenVerifier, options?.localEnvoy);
85
85
  }
86
86
  async down() {
87
87
  await reboot_native.Reboot_down(__classPrivateFieldGet(this, _Reboot_external, "f"));
88
88
  }
89
+ url() {
90
+ return reboot_native.Reboot_url(__classPrivateFieldGet(this, _Reboot_external, "f"));
91
+ }
89
92
  }
90
93
  _Reboot_external = new WeakMap();
91
94
  export class ExternalContext {
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.20.0",
6
+ "@reboot-dev/reboot-api": "0.21.0",
7
7
  "chalk": "^4.1.2",
8
8
  "node-addon-api": "^7.0.0",
9
9
  "node-gyp": ">=10.2.0",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "type": "module",
16
16
  "name": "@reboot-dev/reboot",
17
- "version": "0.20.0",
17
+ "version": "0.21.0",
18
18
  "description": "npm package for Reboot",
19
19
  "scripts": {
20
20
  "postinstall": "rbt || exit 0",
@@ -49,8 +49,8 @@
49
49
  "rbt-esbuild.d.ts",
50
50
  "rbt-esbuild.js",
51
51
  "rbt.js",
52
- "reboot.d.ts",
53
- "reboot.js",
52
+ "index.d.ts",
53
+ "index.js",
54
54
  "reboot_native.cc",
55
55
  "reboot_native.cjs",
56
56
  "reboot_native.d.ts",
@@ -63,7 +63,7 @@
63
63
  ],
64
64
  "exports": {
65
65
  "./package.json": "./package.json",
66
- ".": "./reboot.js",
66
+ ".": "./index.js",
67
67
  "./utils": "./utils/index.js"
68
68
  }
69
69
  }
package/reboot_native.cc CHANGED
@@ -1264,6 +1264,11 @@ Napi::Value Reboot_up(const Napi::CallbackInfo& info) {
1264
1264
  js_token_verifier = NapiSafeReference(info[2].As<Napi::Object>());
1265
1265
  }
1266
1266
 
1267
+ bool local_envoy = false;
1268
+ if (!info[3].IsUndefined()) {
1269
+ local_envoy = info[3].As<Napi::Boolean>();
1270
+ }
1271
+
1267
1272
  auto env = info.Env();
1268
1273
  auto servicer_details = make_servicer_details(env, js_servicers);
1269
1274
 
@@ -1275,6 +1280,7 @@ Napi::Value Reboot_up(const Napi::CallbackInfo& info) {
1275
1280
  [js_external_reboot, // Ensures `py_reboot` remains valid.
1276
1281
  py_reboot,
1277
1282
  js_token_verifier,
1283
+ local_envoy,
1278
1284
  servicer_details = std::move(servicer_details),
1279
1285
  deferred = std::move(deferred)]() {
1280
1286
  py::list py_servicers = make_py_servicers(servicer_details);
@@ -1294,7 +1300,7 @@ Napi::Value Reboot_up(const Napi::CallbackInfo& info) {
1294
1300
  // clone a process like we do with multiprocessing
1295
1301
  // in Python.
1296
1302
  "in_process"_a = true,
1297
- "local_envoy"_a = false),
1303
+ "local_envoy"_a = local_envoy),
1298
1304
  "name"_a = "Reboot.up(...) in nodejs");
1299
1305
 
1300
1306
  py_task.attr("add_done_callback")(py::cpp_function(
@@ -1475,6 +1481,29 @@ Napi::Value Reboot_stop(const Napi::CallbackInfo& info) {
1475
1481
  return promise;
1476
1482
  }
1477
1483
 
1484
+ // NOTE: We block on a promise here, so this method should not be called outside
1485
+ // of tests.
1486
+ Napi::Value Reboot_url(const Napi::CallbackInfo& info) {
1487
+ // NOTE: we immediately get a safe reference to the `Napi::External`
1488
+ // so that Node will not garbage collect it and the `py::object*` we
1489
+ // get out of it will remain valid.
1490
+ auto js_external_reboot = NapiSafeReference(
1491
+ info[0].As<Napi::External<py::object>>());
1492
+
1493
+ // CHECK(...CheckTypeTag(...));
1494
+
1495
+ py::object* py_reboot = js_external_reboot.Value(info.Env()).Data();
1496
+
1497
+ std::promise<std::string> promise;
1498
+
1499
+ adaptor->ScheduleCallbackOnPythonEventLoop(
1500
+ [py_reboot, &promise]() {
1501
+ py::str url = py_reboot->attr("url")();
1502
+ promise.set_value(std::string(url));
1503
+ });
1504
+
1505
+ return Napi::String::New(info.Env(), promise.get_future().get());
1506
+ }
1478
1507
 
1479
1508
  Napi::Value Service_constructor(const Napi::CallbackInfo& info) {
1480
1509
  Napi::Object js_args = info[0].As<Napi::Object>();
@@ -1786,14 +1815,6 @@ Napi::Value ExternalContext_constructor(const Napi::CallbackInfo& info) {
1786
1815
  return py::none();
1787
1816
  }
1788
1817
  };
1789
- auto convert_bool =
1790
- [](const std::optional<bool>& optional) -> py::object {
1791
- if (optional.has_value()) {
1792
- return py::bool_(*optional);
1793
- } else {
1794
- return py::none();
1795
- }
1796
- };
1797
1818
 
1798
1819
  promise.set_value(
1799
1820
  new py::object(py_external.attr("ExternalContext")(
@@ -2806,6 +2827,10 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
2806
2827
  Napi::String::New(env, "Reboot_down"),
2807
2828
  Napi::Function::New<Reboot_down>(env));
2808
2829
 
2830
+ exports.Set(
2831
+ Napi::String::New(env, "Reboot_url"),
2832
+ Napi::Function::New<Reboot_url>(env));
2833
+
2809
2834
  exports.Set(
2810
2835
  Napi::String::New(env, "Service_constructor"),
2811
2836
  Napi::Function::New<Service_constructor>(env));
package/reboot_native.cjs CHANGED
@@ -64,6 +64,7 @@ exports.Reboot_start = reboot_native.exports.Reboot_start;
64
64
  exports.Reboot_stop = reboot_native.exports.Reboot_stop;
65
65
  exports.Reboot_up = reboot_native.exports.Reboot_up;
66
66
  exports.Reboot_down = reboot_native.exports.Reboot_down;
67
+ exports.Reboot_url = reboot_native.exports.Reboot_url;
67
68
  exports.Context_auth = reboot_native.exports.Context_auth;
68
69
  exports.Context_stateId = reboot_native.exports.Context_stateId;
69
70
  exports.Context_iteration = reboot_native.exports.Context_iteration;
@@ -4,11 +4,10 @@ import {
4
4
  Context,
5
5
  ExternalContext,
6
6
  Servicer,
7
+ TokenVerifier,
7
8
  TransactionContext,
8
9
  WorkflowContext,
9
- WriterContext,
10
- TokenVerifier,
11
- } from "./reboot.js";
10
+ } from "./index.js";
12
11
 
13
12
  // The Nodejs addon API does not expose TypeScript types so we alias
14
13
  // our C++ `Napi::External` type to `NapiExternal` to make it more
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const REBOOT_VERSION = "0.20.0";
1
+ export declare const REBOOT_VERSION = "0.21.0";
package/version.js CHANGED
@@ -1 +1 @@
1
- export const REBOOT_VERSION = "0.20.0";
1
+ export const REBOOT_VERSION = "0.21.0";