@lace-cloud/host 0.28.0 → 0.30.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/dist/index.d.mts CHANGED
@@ -47,6 +47,15 @@ type EngineInitialize = {
47
47
  };
48
48
  type ServerState = 'stopped' | 'starting' | 'running' | 'error';
49
49
 
50
+ /**
51
+ * End an engine spawned by `spawnEngine`: close its stdin, which is the
52
+ * engine's signal to shut down and exit on its own, and resolve once it has
53
+ * ended (`hasEnded`), so every line it wrote has reached the log before the
54
+ * caller goes on. A signal is sent only to an engine still running after
55
+ * `graceMs`.
56
+ */
57
+ declare function endEngine(proc: ChildProcess, graceMs?: number): Promise<void>;
58
+
50
59
  /**
51
60
  * The engine binary could not be started, so no engine ran. `cause` is the
52
61
  * spawn error itself, whether the platform refused the spawn at once (thrown:
@@ -70,7 +79,9 @@ declare class EngineSpawnError extends Error {
70
79
  *
71
80
  * Each stdout line is logged as the engine wrote it, except the token line,
72
81
  * which is logged masked. A binary that cannot be started rejects with
73
- * `EngineSpawnError`.
82
+ * `EngineSpawnError`. A failed handshake ends the engine at once and rejects
83
+ * once it has ended (`endEngine`), so whatever the engine wrote on its way
84
+ * out is logged before the rejection.
74
85
  *
75
86
  * The engine's stdin is a pipe whose write end this process owns, and its
76
87
  * lifetime is the engine's lifetime: the engine reads it and shuts down at end
@@ -83,12 +94,6 @@ declare function spawnEngine(binaryPath: string, log: (msg: string) => void): Pr
83
94
  process: ChildProcess;
84
95
  handshake: EngineHandshake;
85
96
  }>;
86
- /**
87
- * End an engine spawned by `spawnEngine`: close its stdin, which is the
88
- * engine's signal to shut down and exit on its own, and resolve once it has.
89
- * A signal is sent only to an engine still running after `graceMs`.
90
- */
91
- declare function endEngine(proc: ChildProcess, graceMs?: number): Promise<void>;
92
97
 
93
98
  /**
94
99
  * `Any` contains an arbitrary serialized protocol buffer message along with a
@@ -785,7 +790,19 @@ interface SessionGenerateRequest {
785
790
  }
786
791
  declare const SessionGenerateRequest: MessageFns<SessionGenerateRequest>;
787
792
  interface SessionGenerateResponse {
793
+ /**
794
+ * Every file the write produced, sorted: Generate writes the whole
795
+ * render, whatever bytes a file held before. Empty when nothing was
796
+ * ungenerated.
797
+ */
788
798
  files_written: string[];
799
+ /**
800
+ * The files of files_written whose bytes differ from the tree the write
801
+ * replaced, a file the tree did not hold included, sorted.
802
+ */
803
+ files_changed: string[];
804
+ /** The source tf the write deleted, sorted. */
805
+ files_removed: string[];
789
806
  /** the `module validate -o json` document for the Terraform on disk */
790
807
  validate_json: string;
791
808
  /**
@@ -1246,7 +1263,10 @@ interface GenerateProgress {
1246
1263
  }
1247
1264
  declare const GenerateProgress: MessageFns<GenerateProgress>;
1248
1265
  interface GenerateSuccess {
1266
+ /** The three file lists of the Generate's own SessionGenerateResponse. */
1249
1267
  files_written: string[];
1268
+ files_changed: string[];
1269
+ files_removed: string[];
1250
1270
  /** the `module validate -o json` document for the Terraform on disk */
1251
1271
  validate_json: string;
1252
1272
  /** the Generate this event belongs to */
package/dist/index.d.ts CHANGED
@@ -47,6 +47,15 @@ type EngineInitialize = {
47
47
  };
48
48
  type ServerState = 'stopped' | 'starting' | 'running' | 'error';
49
49
 
50
+ /**
51
+ * End an engine spawned by `spawnEngine`: close its stdin, which is the
52
+ * engine's signal to shut down and exit on its own, and resolve once it has
53
+ * ended (`hasEnded`), so every line it wrote has reached the log before the
54
+ * caller goes on. A signal is sent only to an engine still running after
55
+ * `graceMs`.
56
+ */
57
+ declare function endEngine(proc: ChildProcess, graceMs?: number): Promise<void>;
58
+
50
59
  /**
51
60
  * The engine binary could not be started, so no engine ran. `cause` is the
52
61
  * spawn error itself, whether the platform refused the spawn at once (thrown:
@@ -70,7 +79,9 @@ declare class EngineSpawnError extends Error {
70
79
  *
71
80
  * Each stdout line is logged as the engine wrote it, except the token line,
72
81
  * which is logged masked. A binary that cannot be started rejects with
73
- * `EngineSpawnError`.
82
+ * `EngineSpawnError`. A failed handshake ends the engine at once and rejects
83
+ * once it has ended (`endEngine`), so whatever the engine wrote on its way
84
+ * out is logged before the rejection.
74
85
  *
75
86
  * The engine's stdin is a pipe whose write end this process owns, and its
76
87
  * lifetime is the engine's lifetime: the engine reads it and shuts down at end
@@ -83,12 +94,6 @@ declare function spawnEngine(binaryPath: string, log: (msg: string) => void): Pr
83
94
  process: ChildProcess;
84
95
  handshake: EngineHandshake;
85
96
  }>;
86
- /**
87
- * End an engine spawned by `spawnEngine`: close its stdin, which is the
88
- * engine's signal to shut down and exit on its own, and resolve once it has.
89
- * A signal is sent only to an engine still running after `graceMs`.
90
- */
91
- declare function endEngine(proc: ChildProcess, graceMs?: number): Promise<void>;
92
97
 
93
98
  /**
94
99
  * `Any` contains an arbitrary serialized protocol buffer message along with a
@@ -785,7 +790,19 @@ interface SessionGenerateRequest {
785
790
  }
786
791
  declare const SessionGenerateRequest: MessageFns<SessionGenerateRequest>;
787
792
  interface SessionGenerateResponse {
793
+ /**
794
+ * Every file the write produced, sorted: Generate writes the whole
795
+ * render, whatever bytes a file held before. Empty when nothing was
796
+ * ungenerated.
797
+ */
788
798
  files_written: string[];
799
+ /**
800
+ * The files of files_written whose bytes differ from the tree the write
801
+ * replaced, a file the tree did not hold included, sorted.
802
+ */
803
+ files_changed: string[];
804
+ /** The source tf the write deleted, sorted. */
805
+ files_removed: string[];
789
806
  /** the `module validate -o json` document for the Terraform on disk */
790
807
  validate_json: string;
791
808
  /**
@@ -1246,7 +1263,10 @@ interface GenerateProgress {
1246
1263
  }
1247
1264
  declare const GenerateProgress: MessageFns<GenerateProgress>;
1248
1265
  interface GenerateSuccess {
1266
+ /** The three file lists of the Generate's own SessionGenerateResponse. */
1249
1267
  files_written: string[];
1268
+ files_changed: string[];
1269
+ files_removed: string[];
1250
1270
  /** the `module validate -o json` document for the Terraform on disk */
1251
1271
  validate_json: string;
1252
1272
  /** the Generate this event belongs to */
package/dist/index.mjs CHANGED
@@ -4404,13 +4404,19 @@ var SessionGenerateRequest = {
4404
4404
  }
4405
4405
  };
4406
4406
  function createBaseSessionGenerateResponse() {
4407
- return { files_written: [], validate_json: "", revision: 0 };
4407
+ return { files_written: [], files_changed: [], files_removed: [], validate_json: "", revision: 0 };
4408
4408
  }
4409
4409
  var SessionGenerateResponse = {
4410
4410
  encode(message, writer = new BinaryWriter4()) {
4411
4411
  for (const v of message.files_written) {
4412
4412
  writer.uint32(10).string(v);
4413
4413
  }
4414
+ for (const v of message.files_changed) {
4415
+ writer.uint32(50).string(v);
4416
+ }
4417
+ for (const v of message.files_removed) {
4418
+ writer.uint32(58).string(v);
4419
+ }
4414
4420
  if (message.validate_json !== "") {
4415
4421
  writer.uint32(34).string(message.validate_json);
4416
4422
  }
@@ -4433,6 +4439,20 @@ var SessionGenerateResponse = {
4433
4439
  message.files_written.push(reader.string());
4434
4440
  continue;
4435
4441
  }
4442
+ case 6: {
4443
+ if (tag !== 50) {
4444
+ break;
4445
+ }
4446
+ message.files_changed.push(reader.string());
4447
+ continue;
4448
+ }
4449
+ case 7: {
4450
+ if (tag !== 58) {
4451
+ break;
4452
+ }
4453
+ message.files_removed.push(reader.string());
4454
+ continue;
4455
+ }
4436
4456
  case 4: {
4437
4457
  if (tag !== 34) {
4438
4458
  break;
@@ -4458,6 +4478,8 @@ var SessionGenerateResponse = {
4458
4478
  fromJSON(object) {
4459
4479
  return {
4460
4480
  files_written: globalThis.Array.isArray(object?.filesWritten) ? object.filesWritten.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_written) ? object.files_written.map((e) => globalThis.String(e)) : [],
4481
+ files_changed: globalThis.Array.isArray(object?.filesChanged) ? object.filesChanged.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_changed) ? object.files_changed.map((e) => globalThis.String(e)) : [],
4482
+ files_removed: globalThis.Array.isArray(object?.filesRemoved) ? object.filesRemoved.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_removed) ? object.files_removed.map((e) => globalThis.String(e)) : [],
4461
4483
  validate_json: isSet3(object.validateJson) ? globalThis.String(object.validateJson) : isSet3(object.validate_json) ? globalThis.String(object.validate_json) : "",
4462
4484
  revision: isSet3(object.revision) ? globalThis.Number(object.revision) : 0
4463
4485
  };
@@ -4467,6 +4489,12 @@ var SessionGenerateResponse = {
4467
4489
  if (message.files_written?.length) {
4468
4490
  obj.filesWritten = message.files_written;
4469
4491
  }
4492
+ if (message.files_changed?.length) {
4493
+ obj.filesChanged = message.files_changed;
4494
+ }
4495
+ if (message.files_removed?.length) {
4496
+ obj.filesRemoved = message.files_removed;
4497
+ }
4470
4498
  if (message.validate_json !== "") {
4471
4499
  obj.validateJson = message.validate_json;
4472
4500
  }
@@ -4481,6 +4509,8 @@ var SessionGenerateResponse = {
4481
4509
  fromPartial(object) {
4482
4510
  const message = createBaseSessionGenerateResponse();
4483
4511
  message.files_written = object.files_written?.map((e) => e) || [];
4512
+ message.files_changed = object.files_changed?.map((e) => e) || [];
4513
+ message.files_removed = object.files_removed?.map((e) => e) || [];
4484
4514
  message.validate_json = object.validate_json ?? "";
4485
4515
  message.revision = object.revision ?? 0;
4486
4516
  return message;
@@ -8401,13 +8431,19 @@ var GenerateProgress = {
8401
8431
  }
8402
8432
  };
8403
8433
  function createBaseGenerateSuccess() {
8404
- return { files_written: [], validate_json: "", generate_id: "" };
8434
+ return { files_written: [], files_changed: [], files_removed: [], validate_json: "", generate_id: "" };
8405
8435
  }
8406
8436
  var GenerateSuccess = {
8407
8437
  encode(message, writer = new BinaryWriter4()) {
8408
8438
  for (const v of message.files_written) {
8409
8439
  writer.uint32(10).string(v);
8410
8440
  }
8441
+ for (const v of message.files_changed) {
8442
+ writer.uint32(42).string(v);
8443
+ }
8444
+ for (const v of message.files_removed) {
8445
+ writer.uint32(50).string(v);
8446
+ }
8411
8447
  if (message.validate_json !== "") {
8412
8448
  writer.uint32(26).string(message.validate_json);
8413
8449
  }
@@ -8430,6 +8466,20 @@ var GenerateSuccess = {
8430
8466
  message.files_written.push(reader.string());
8431
8467
  continue;
8432
8468
  }
8469
+ case 5: {
8470
+ if (tag !== 42) {
8471
+ break;
8472
+ }
8473
+ message.files_changed.push(reader.string());
8474
+ continue;
8475
+ }
8476
+ case 6: {
8477
+ if (tag !== 50) {
8478
+ break;
8479
+ }
8480
+ message.files_removed.push(reader.string());
8481
+ continue;
8482
+ }
8433
8483
  case 3: {
8434
8484
  if (tag !== 26) {
8435
8485
  break;
@@ -8455,6 +8505,8 @@ var GenerateSuccess = {
8455
8505
  fromJSON(object) {
8456
8506
  return {
8457
8507
  files_written: globalThis.Array.isArray(object?.filesWritten) ? object.filesWritten.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_written) ? object.files_written.map((e) => globalThis.String(e)) : [],
8508
+ files_changed: globalThis.Array.isArray(object?.filesChanged) ? object.filesChanged.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_changed) ? object.files_changed.map((e) => globalThis.String(e)) : [],
8509
+ files_removed: globalThis.Array.isArray(object?.filesRemoved) ? object.filesRemoved.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.files_removed) ? object.files_removed.map((e) => globalThis.String(e)) : [],
8458
8510
  validate_json: isSet3(object.validateJson) ? globalThis.String(object.validateJson) : isSet3(object.validate_json) ? globalThis.String(object.validate_json) : "",
8459
8511
  generate_id: isSet3(object.generateId) ? globalThis.String(object.generateId) : isSet3(object.generate_id) ? globalThis.String(object.generate_id) : ""
8460
8512
  };
@@ -8464,6 +8516,12 @@ var GenerateSuccess = {
8464
8516
  if (message.files_written?.length) {
8465
8517
  obj.filesWritten = message.files_written;
8466
8518
  }
8519
+ if (message.files_changed?.length) {
8520
+ obj.filesChanged = message.files_changed;
8521
+ }
8522
+ if (message.files_removed?.length) {
8523
+ obj.filesRemoved = message.files_removed;
8524
+ }
8467
8525
  if (message.validate_json !== "") {
8468
8526
  obj.validateJson = message.validate_json;
8469
8527
  }
@@ -8478,6 +8536,8 @@ var GenerateSuccess = {
8478
8536
  fromPartial(object) {
8479
8537
  const message = createBaseGenerateSuccess();
8480
8538
  message.files_written = object.files_written?.map((e) => e) || [];
8539
+ message.files_changed = object.files_changed?.map((e) => e) || [];
8540
+ message.files_removed = object.files_removed?.map((e) => e) || [];
8481
8541
  message.validate_json = object.validate_json ?? "";
8482
8542
  message.generate_id = object.generate_id ?? "";
8483
8543
  return message;
@@ -10760,8 +10820,24 @@ function serveEngineBridge(bridge, transport) {
10760
10820
  // src/engine-process.ts
10761
10821
  import { spawn } from "child_process";
10762
10822
  import * as readline from "readline";
10763
- var HANDSHAKE_TIMEOUT_MS = 1e4;
10823
+
10824
+ // src/engine-end.mjs
10764
10825
  var EXIT_GRACE_MS = 5e3;
10826
+ var hasEnded = (proc) => (proc.exitCode !== null || proc.signalCode !== null) && [proc.stdout, proc.stderr].every((stream) => stream === null || stream.closed);
10827
+ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
10828
+ if (hasEnded(proc)) return Promise.resolve();
10829
+ return new Promise((resolve) => {
10830
+ const timer = setTimeout(() => proc.kill(), graceMs);
10831
+ proc.once("close", () => {
10832
+ clearTimeout(timer);
10833
+ resolve();
10834
+ });
10835
+ proc.stdin?.end();
10836
+ });
10837
+ }
10838
+
10839
+ // src/engine-process.ts
10840
+ var HANDSHAKE_TIMEOUT_MS = 1e4;
10765
10841
  var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
10766
10842
  var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
10767
10843
  var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
@@ -10803,21 +10879,17 @@ function spawnEngine(binaryPath, log) {
10803
10879
  let port;
10804
10880
  let token;
10805
10881
  let settled = false;
10806
- const timer = setTimeout(() => {
10807
- if (settled) return;
10808
- settled = true;
10809
- rl.close();
10810
- proc.kill();
10811
- reject(new Error("Timed out waiting for engine handshake"));
10812
- }, HANDSHAKE_TIMEOUT_MS);
10813
10882
  const fail = (error) => {
10814
10883
  if (settled) return;
10815
10884
  settled = true;
10816
10885
  clearTimeout(timer);
10817
10886
  rl.close();
10818
- proc.kill();
10819
- reject(error);
10887
+ endEngine(proc, 0).then(() => reject(error));
10820
10888
  };
10889
+ const timer = setTimeout(
10890
+ () => fail(new Error("Timed out waiting for engine handshake")),
10891
+ HANDSHAKE_TIMEOUT_MS
10892
+ );
10821
10893
  rl.on("line", (line) => {
10822
10894
  if (settled) return;
10823
10895
  log(`[stdout] ${loggable(line)}`);
@@ -10864,18 +10936,6 @@ function spawnEngine(binaryPath, log) {
10864
10936
  });
10865
10937
  });
10866
10938
  }
10867
- var hasExited = (proc) => proc.exitCode !== null || proc.signalCode !== null;
10868
- function endEngine(proc, graceMs = EXIT_GRACE_MS) {
10869
- if (hasExited(proc)) return Promise.resolve();
10870
- return new Promise((resolve) => {
10871
- const timer = setTimeout(() => proc.kill(), graceMs);
10872
- proc.once("exit", () => {
10873
- clearTimeout(timer);
10874
- resolve();
10875
- });
10876
- proc.stdin?.end();
10877
- });
10878
- }
10879
10939
 
10880
10940
  // src/rpc-errors.ts
10881
10941
  import { status as GrpcStatus } from "@grpc/grpc-js";
@@ -11050,7 +11110,7 @@ var ServerManager = class extends EventEmitter {
11050
11110
  this.engineEnded();
11051
11111
  this.maybeRestart();
11052
11112
  });
11053
- proc.on("exit", (code) => {
11113
+ proc.on("close", (code) => {
11054
11114
  if (this.process !== proc) return;
11055
11115
  this.log(`Process exited with code ${code}`);
11056
11116
  this.engineEnded();
@@ -11089,7 +11149,7 @@ var ServerManager = class extends EventEmitter {
11089
11149
  await this.start();
11090
11150
  }
11091
11151
  // The manager's end is the engine's: what `stop` resolves on, so a caller
11092
- // can await the engine's exit.
11152
+ // can await the engine's end.
11093
11153
  dispose() {
11094
11154
  return this.stop();
11095
11155
  }