@reboot-dev/reboot 0.38.3 → 0.39.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.js CHANGED
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Reboot_external, _ExternalContext_external, _a, _Context_external, _Context_isInternalConstructing, _ReaderContext_kind, _WriterContext_kind, _TransactionContext_kind, _WorkflowContext_kind, _Application_servicers, _Application_tokenVerifier, _Application_express, _Application_http, _Application_servers, _Application_createExternalContext, _Application_external;
13
- import { assert, auth_pb, errors_pb, nodejs_pb, parse, protobuf_es, stringify, tasks_pb, toCamelCase, } from "@reboot-dev/reboot-api";
13
+ import { assert, auth_pb, check_bufbuild_protobuf_library, errors_pb, nodejs_pb, parse, protobuf_es, stringify, tasks_pb, toCamelCase, } from "@reboot-dev/reboot-api";
14
14
  import { AsyncLocalStorage } from "node:async_hooks";
15
15
  import { fork } from "node:child_process";
16
16
  import { createRequire } from "node:module";
@@ -19,6 +19,7 @@ import { z } from "zod/v4";
19
19
  import * as reboot_native from "./reboot_native.cjs";
20
20
  import { ensureError } from "./utils/errors.js";
21
21
  import { ensurePythonVenv } from "./venv.js";
22
+ check_bufbuild_protobuf_library(protobuf_es.Message);
22
23
  const require = createRequire(import.meta.url);
23
24
  const express = require("express");
24
25
  export { reboot_native };
@@ -318,7 +319,7 @@ export function clearField(field, target) {
318
319
  break;
319
320
  case "scalar":
320
321
  target[localName] = implicitPresence
321
- ? protobuf_es.codegenInfo.scalarDefaultValue(field.T)
322
+ ? protobuf_es.codegenInfo.scalarDefaultValue(field.T, field.L)
322
323
  : undefined;
323
324
  break;
324
325
  case "message":
@@ -533,7 +534,7 @@ export class Application {
533
534
  assert(kind === "initialize");
534
535
  return InitializeContext.fromNativeExternal(external);
535
536
  }, servicers, {
536
- start: async (consensusId, port, createExternalContext) => {
537
+ start: async (serverId, port, createExternalContext) => {
537
538
  // Store `createExternalContext` function before listening
538
539
  // so we don't attempt to serve any traffic and try and use
539
540
  // an `undefined` function.
@@ -554,11 +555,11 @@ export class Application {
554
555
  }
555
556
  });
556
557
  });
557
- __classPrivateFieldGet(this, _Application_servers, "f").set(consensusId, server);
558
+ __classPrivateFieldGet(this, _Application_servers, "f").set(serverId, server);
558
559
  return port;
559
560
  },
560
- stop: async (consensusId) => {
561
- const server = __classPrivateFieldGet(this, _Application_servers, "f").get(consensusId);
561
+ stop: async (serverId) => {
562
+ const server = __classPrivateFieldGet(this, _Application_servers, "f").get(serverId);
562
563
  if (server !== undefined) {
563
564
  await new Promise((resolve, reject) => {
564
565
  server.close((err) => {
@@ -570,7 +571,7 @@ export class Application {
570
571
  }
571
572
  });
572
573
  });
573
- __classPrivateFieldGet(this, _Application_servers, "f").delete(consensusId);
574
+ __classPrivateFieldGet(this, _Application_servers, "f").delete(serverId);
574
575
  }
575
576
  },
576
577
  }, async (context) => {
@@ -884,18 +885,18 @@ export async function untilChanges(idempotencyAlias, context, callable, { equals
884
885
  return false;
885
886
  }), { schema }));
886
887
  }
887
- const launchSubprocessConsensus = (base64_args) => {
888
+ const launchSubprocessServer = (base64_args) => {
888
889
  // Create a child process via `fork` (which does not mean `fork` as
889
890
  // in POSIX fork/clone) that uses the exact same module that was
890
891
  // used to start the initial application, however we set some env
891
892
  // vars in order to trigger the child process to run as a
892
- // consensus subprocess.
893
+ // server subprocess.
893
894
  const subprocess = fork(process.argv[1], {
894
895
  env: {
895
896
  ...process.env,
896
- // Pass over the consensus args in an env var.
897
- REBOOT_NODEJS_CONSENSUS: "true",
898
- REBOOT_NODEJS_CONSENSUS_BASE64_ARGS: base64_args,
897
+ // Pass over the server args in an env var.
898
+ REBOOT_NODEJS_SERVER: "true",
899
+ REBOOT_NODEJS_SERVER_BASE64_ARGS: base64_args,
899
900
  },
900
901
  });
901
902
  return subprocess.pid;
@@ -904,7 +905,7 @@ const callback = (...args) => {
904
905
  console.log(new Date(), ...args);
905
906
  };
906
907
  ensurePythonVenv();
907
- reboot_native.initialize(callback, launchSubprocessConsensus);
908
+ reboot_native.initialize(callback, launchSubprocessServer);
908
909
  // TODO: move these into @reboot-dev/reboot-api and also generate them
909
910
  // via plugin, perhaps via a new plugin which emits the Zod schemas
910
911
  // for all protobuf messages, which might be easier after we've moved
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "dependencies": {
3
- "@bufbuild/protobuf": "1.3.2",
4
- "@bufbuild/protoplugin": "1.3.2",
5
- "@bufbuild/protoc-gen-es": "1.3.2",
6
- "@reboot-dev/reboot-api": "0.38.3",
3
+ "@bufbuild/protoplugin": "1.10.1",
4
+ "@bufbuild/protoc-gen-es": "1.10.1",
5
+ "@reboot-dev/reboot-api": "0.39.0",
7
6
  "chalk": "^4.1.2",
8
7
  "node-addon-api": "^7.0.0",
9
8
  "node-gyp": ">=10.2.0",
@@ -18,9 +17,12 @@
18
17
  "toobusy-js": "^0.5.1",
19
18
  "@standard-schema/spec": "1.0.0"
20
19
  },
20
+ "peerDependencies": {
21
+ "@bufbuild/protobuf": "1.10.1"
22
+ },
21
23
  "type": "module",
22
24
  "name": "@reboot-dev/reboot",
23
- "version": "0.38.3",
25
+ "version": "0.39.0",
24
26
  "description": "npm package for Reboot",
25
27
  "scripts": {
26
28
  "preinstall": "node preinstall.cjs",
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env tsx
2
- import { toCamelCase, toPascalCase, toSnakeCase, ZOD_ERROR_NAMES, } from "@reboot-dev/reboot-api";
2
+ import { toCamelCase, toPascalCase, toSnakeCase, typeSchema, ZOD_ERROR_NAMES, } from "@reboot-dev/reboot-api";
3
3
  import { strict as assert } from "assert";
4
4
  import chalk from "chalk";
5
5
  import { mkdtemp } from "fs/promises";
@@ -11,40 +11,6 @@ import { z } from "zod/v4";
11
11
  const args = process.argv.slice(2);
12
12
  const filesDirectory = args[0];
13
13
  const files = args.slice(1);
14
- const requestSchema = z.union([
15
- z.instanceof(z.ZodObject),
16
- z.record(z.string(), z.instanceof(z.ZodType)),
17
- ]);
18
- const responseSchema = z.union([
19
- z.instanceof(z.ZodObject),
20
- z.record(z.string(), z.instanceof(z.ZodType)),
21
- z.instanceof(z.ZodVoid),
22
- ]);
23
- const errorsSchema = z.union([
24
- z.tuple([z.instanceof(z.ZodObject)], z.instanceof(z.ZodObject)),
25
- z.instanceof(z.ZodDiscriminatedUnion),
26
- ]);
27
- const typeSchema = z.object({
28
- state: z.union([
29
- z.instanceof(z.ZodObject),
30
- z.record(z.string(), z.instanceof(z.ZodType)),
31
- ]),
32
- methods: z.record(z.string(), z.discriminatedUnion("kind", [
33
- z.object({
34
- kind: z.literal(["reader", "workflow"]),
35
- request: requestSchema,
36
- response: responseSchema,
37
- errors: errorsSchema.optional(),
38
- }),
39
- z.object({
40
- kind: z.literal(["writer", "transaction"]),
41
- factory: z.object({}).optional(),
42
- request: requestSchema,
43
- response: responseSchema,
44
- errors: errorsSchema.optional(),
45
- }),
46
- ])),
47
- });
48
14
  // TODO:
49
15
  //
50
16
  // z.date (use well-known proto)
@@ -501,6 +467,12 @@ const main = async () => {
501
467
  }
502
468
  process.exit(-1);
503
469
  }
470
+ // Doing 'as any' here because Typescript can't figure out the
471
+ // inferred Zod type if we import from another module and will
472
+ // throw 'TS2589: Type instantiation is excessively deep and
473
+ // possibly infinite.' error.
474
+ // It is safe to do so, because right before that we call
475
+ // 'safeParse()', which ensures that the type is correct.
504
476
  const type = result.data;
505
477
  generate(proto, {
506
478
  schema: type.state instanceof z.ZodObject ? type.state : z.object(type.state),
package/rbt.js CHANGED
@@ -52,9 +52,8 @@ async function main() {
52
52
  addExtensionlessToNodeOptions();
53
53
  // Using 'spawn' instead of 'spawnSync' to avoid blocking the event loop for
54
54
  // signal handling.
55
- const rbt = spawn(`${path.join(VENV_EXEC_PATH, "rbt")} ${process.argv.slice(2).join(" ")}`, {
56
- stdio: [process.stdin, process.stdout, process.stderr],
57
- shell: true,
55
+ const rbt = spawn(`${path.join(VENV_EXEC_PATH, "rbt")}`, process.argv.slice(2), {
56
+ stdio: "inherit",
58
57
  });
59
58
  process.on("SIGINT", () => {
60
59
  // Make sure to kill the child process before exiting.
package/reboot_native.cc CHANGED
@@ -286,7 +286,7 @@ struct PythonNodeAdaptor {
286
286
  static PythonNodeAdaptor* adaptor = new PythonNodeAdaptor();
287
287
 
288
288
  // References to nodejs functions so we don't have to look them up.
289
- static Napi::FunctionReference* js_launchSubprocessConsensus =
289
+ static Napi::FunctionReference* js_launchSubprocessServer =
290
290
  new Napi::FunctionReference();
291
291
 
292
292
 
@@ -419,7 +419,7 @@ void PythonNodeAdaptor::Initialize(
419
419
  try {
420
420
  py::object module = py::module::import("rebootdev.nodejs.python");
421
421
 
422
- module.attr("launch_subprocess_consensus") = py::cpp_function(
422
+ module.attr("launch_subprocess_server") = py::cpp_function(
423
423
  [](py::str py_base64_args) {
424
424
  py::object py_future =
425
425
  py::module::import("asyncio").attr("Future")();
@@ -429,7 +429,7 @@ void PythonNodeAdaptor::Initialize(
429
429
  py_future = new py::object(py_future)](Napi::Env env) {
430
430
  try {
431
431
  Napi::Number js_pid =
432
- js_launchSubprocessConsensus
432
+ js_launchSubprocessServer
433
433
  ->Call(
434
434
  {Napi::String::New(env, base64_args)})
435
435
  .As<Napi::Number>();
@@ -1091,7 +1091,7 @@ void Initialize(const Napi::CallbackInfo& info) {
1091
1091
  std::call_once(initialize_once, [&]() {
1092
1092
  Napi::Env env = info.Env();
1093
1093
 
1094
- js_launchSubprocessConsensus->Reset(
1094
+ js_launchSubprocessServer->Reset(
1095
1095
  info[1].As<Napi::Function>(),
1096
1096
  /* refcount = */ 1);
1097
1097
 
@@ -1768,7 +1768,7 @@ Napi::Value Reboot_up(const Napi::CallbackInfo& info) {
1768
1768
  local_envoy_port]() {
1769
1769
  return py_reboot->attr("up")(
1770
1770
  py_application,
1771
- // NOTE: while we support subprocess consensuses
1771
+ // NOTE: while we support subprocess servers
1772
1772
  // for `rbt dev` and `rbt serve` we do not support
1773
1773
  // them for tests because we don't have a way to
1774
1774
  // clone a process like we do with multiprocessing
@@ -2163,7 +2163,7 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2163
2163
  py::object py_web_framework_start = py::cpp_function(
2164
2164
  [js_web_framework_start = std::move(js_web_framework_start),
2165
2165
  js_from_native_external /* Need a copy because it is shared. */](
2166
- std::string consensus_id,
2166
+ std::string server_id,
2167
2167
  py::object py_port,
2168
2168
  py::object py_channel_manager) {
2169
2169
  std::optional<int> port;
@@ -2174,7 +2174,7 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2174
2174
  return PythonFutureFromNodePromise(
2175
2175
  [js_web_framework_start = std::move(js_web_framework_start),
2176
2176
  js_from_native_external = std::move(js_from_native_external),
2177
- consensus_id = std::move(consensus_id),
2177
+ server_id = std::move(server_id),
2178
2178
  port,
2179
2179
  py_channel_manager = new py::object(py_channel_manager)](
2180
2180
  Napi::Env env) mutable {
@@ -2268,7 +2268,7 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2268
2268
  .Value(env)
2269
2269
  .Call(
2270
2270
  env.Global(),
2271
- {Napi::String::New(env, consensus_id),
2271
+ {Napi::String::New(env, server_id),
2272
2272
  port.has_value()
2273
2273
  ? Napi::Number::New(env, *port)
2274
2274
  : env.Null(),
@@ -2283,16 +2283,16 @@ Napi::Value Application_constructor(const Napi::CallbackInfo& info) {
2283
2283
 
2284
2284
  py::object py_web_framework_stop = py::cpp_function(
2285
2285
  [js_web_framework_stop = std::move(js_web_framework_stop)](
2286
- std::string consensus_id) {
2286
+ std::string server_id) {
2287
2287
  return PythonFutureFromNodePromise(
2288
2288
  [js_web_framework_stop = std::move(js_web_framework_stop),
2289
- consensus_id = std::move(consensus_id)](
2289
+ server_id = std::move(server_id)](
2290
2290
  Napi::Env env) mutable {
2291
2291
  return js_web_framework_stop
2292
2292
  .Value(env)
2293
2293
  .Call(
2294
2294
  env.Global(),
2295
- {Napi::String::New(env, consensus_id)})
2295
+ {Napi::String::New(env, server_id)})
2296
2296
  .As<Napi::Object>();
2297
2297
  });
2298
2298
  });
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const REBOOT_VERSION = "0.38.3";
1
+ export declare const REBOOT_VERSION = "0.39.0";
package/version.js CHANGED
@@ -1 +1 @@
1
- export const REBOOT_VERSION = "0.38.3";
1
+ export const REBOOT_VERSION = "0.39.0";