@lace-cloud/host 0.35.0 → 0.37.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/README.md +20 -8
- package/dist/index.cjs +58 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +30 -8
- package/dist/index.d.ts +30 -8
- package/dist/index.mjs +59 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install @lace-cloud/host
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import {
|
|
21
|
-
|
|
21
|
+
EngineIdentityMismatchError,
|
|
22
22
|
EngineSpawnError,
|
|
23
23
|
ServerManager,
|
|
24
24
|
serveEngineBridge,
|
|
@@ -35,19 +35,31 @@ const server = new ServerManager({
|
|
|
35
35
|
});
|
|
36
36
|
server.on('state', (state) => console.log(`engine: ${state}`));
|
|
37
37
|
|
|
38
|
-
// start() compares the protocol version on the engine's
|
|
39
|
-
//
|
|
40
|
-
// another is ended and start()
|
|
41
|
-
// which carries the engine's
|
|
42
|
-
//
|
|
38
|
+
// start() compares the protocol version and the contract on the engine's
|
|
39
|
+
// handshake with the ones this library was built from before it sends any
|
|
40
|
+
// RPC. An engine that names another, or no contract, is ended and start()
|
|
41
|
+
// rejects with EngineIdentityMismatchError, which carries the engine's
|
|
42
|
+
// version, both protocol versions and both contracts; `behind` says which
|
|
43
|
+
// side is older ('engine' or 'host'), and is undefined when the protocol
|
|
44
|
+
// numbers match and only the contracts differ: the engine and this host
|
|
45
|
+
// were built from different trees. A binary that cannot be started
|
|
43
46
|
// rejects with EngineSpawnError: `cause` is the spawn error and `code` its
|
|
44
47
|
// system code (`ENOENT` when no executable is found, `EINVAL` when Windows
|
|
45
48
|
// refuses to start a `.cmd` or `.bat`). What to show is the host's.
|
|
46
49
|
try {
|
|
47
50
|
await server.start();
|
|
48
51
|
} catch (err) {
|
|
49
|
-
if (err instanceof
|
|
50
|
-
|
|
52
|
+
if (err instanceof EngineIdentityMismatchError) {
|
|
53
|
+
switch (err.behind) {
|
|
54
|
+
case 'engine':
|
|
55
|
+
console.error(`Lace CLI ${err.engineVersion} is too old for this host: update it`);
|
|
56
|
+
break;
|
|
57
|
+
case 'host':
|
|
58
|
+
console.error(`Lace CLI ${err.engineVersion} is newer than this host: update the host`);
|
|
59
|
+
break;
|
|
60
|
+
case undefined:
|
|
61
|
+
console.error(err.message);
|
|
62
|
+
}
|
|
51
63
|
}
|
|
52
64
|
if (err instanceof EngineSpawnError && err.code === 'ENOENT') {
|
|
53
65
|
console.error('lace was not found: install the Lace CLI or set its path');
|
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BundleState: () => BundleState,
|
|
34
34
|
BundleStateEvent: () => BundleStateEvent,
|
|
35
|
-
|
|
35
|
+
EngineIdentityMismatchError: () => import_proto5.EngineIdentityMismatchError,
|
|
36
36
|
EngineSpawnError: () => EngineSpawnError,
|
|
37
37
|
InitializeResponse: () => InitializeResponse,
|
|
38
38
|
InvokeEvent: () => InvokeEvent,
|
|
@@ -600,6 +600,9 @@ function reasonFromJSON(object) {
|
|
|
600
600
|
case 22:
|
|
601
601
|
case "REASON_NO_LOCKFILE":
|
|
602
602
|
return 22 /* REASON_NO_LOCKFILE */;
|
|
603
|
+
case 23:
|
|
604
|
+
case "REASON_NO_COMMIT":
|
|
605
|
+
return 23 /* REASON_NO_COMMIT */;
|
|
603
606
|
case -1:
|
|
604
607
|
case "UNRECOGNIZED":
|
|
605
608
|
default:
|
|
@@ -654,6 +657,8 @@ function reasonToJSON(object) {
|
|
|
654
657
|
return "REASON_ALREADY_IMPORTED";
|
|
655
658
|
case 22 /* REASON_NO_LOCKFILE */:
|
|
656
659
|
return "REASON_NO_LOCKFILE";
|
|
660
|
+
case 23 /* REASON_NO_COMMIT */:
|
|
661
|
+
return "REASON_NO_COMMIT";
|
|
657
662
|
case -1 /* UNRECOGNIZED */:
|
|
658
663
|
default:
|
|
659
664
|
return "UNRECOGNIZED";
|
|
@@ -3726,7 +3731,7 @@ var InitializeRequest = {
|
|
|
3726
3731
|
}
|
|
3727
3732
|
};
|
|
3728
3733
|
function createBaseInitializeResponse() {
|
|
3729
|
-
return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [] };
|
|
3734
|
+
return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [], contract: "" };
|
|
3730
3735
|
}
|
|
3731
3736
|
var InitializeResponse = {
|
|
3732
3737
|
encode(message, writer = new import_wire4.BinaryWriter()) {
|
|
@@ -3742,6 +3747,9 @@ var InitializeResponse = {
|
|
|
3742
3747
|
for (const v of message.command_paths) {
|
|
3743
3748
|
writer.uint32(42).string(v);
|
|
3744
3749
|
}
|
|
3750
|
+
if (message.contract !== "") {
|
|
3751
|
+
writer.uint32(50).string(message.contract);
|
|
3752
|
+
}
|
|
3745
3753
|
return writer;
|
|
3746
3754
|
},
|
|
3747
3755
|
decode(input, length) {
|
|
@@ -3779,6 +3787,13 @@ var InitializeResponse = {
|
|
|
3779
3787
|
message.command_paths.push(reader.string());
|
|
3780
3788
|
continue;
|
|
3781
3789
|
}
|
|
3790
|
+
case 6: {
|
|
3791
|
+
if (tag !== 50) {
|
|
3792
|
+
break;
|
|
3793
|
+
}
|
|
3794
|
+
message.contract = reader.string();
|
|
3795
|
+
continue;
|
|
3796
|
+
}
|
|
3782
3797
|
}
|
|
3783
3798
|
if ((tag & 7) === 4 || tag === 0) {
|
|
3784
3799
|
break;
|
|
@@ -3792,7 +3807,8 @@ var InitializeResponse = {
|
|
|
3792
3807
|
server_version: isSet3(object.serverVersion) ? globalThis.String(object.serverVersion) : isSet3(object.server_version) ? globalThis.String(object.server_version) : "",
|
|
3793
3808
|
protocol_version: isSet3(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet3(object.protocol_version) ? globalThis.String(object.protocol_version) : "",
|
|
3794
3809
|
supported_protocols: globalThis.Array.isArray(object?.supportedProtocols) ? object.supportedProtocols.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.supported_protocols) ? object.supported_protocols.map((e) => globalThis.String(e)) : [],
|
|
3795
|
-
command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : []
|
|
3810
|
+
command_paths: globalThis.Array.isArray(object?.commandPaths) ? object.commandPaths.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.command_paths) ? object.command_paths.map((e) => globalThis.String(e)) : [],
|
|
3811
|
+
contract: isSet3(object.contract) ? globalThis.String(object.contract) : ""
|
|
3796
3812
|
};
|
|
3797
3813
|
},
|
|
3798
3814
|
toJSON(message) {
|
|
@@ -3809,6 +3825,9 @@ var InitializeResponse = {
|
|
|
3809
3825
|
if (message.command_paths?.length) {
|
|
3810
3826
|
obj.commandPaths = message.command_paths;
|
|
3811
3827
|
}
|
|
3828
|
+
if (message.contract !== "") {
|
|
3829
|
+
obj.contract = message.contract;
|
|
3830
|
+
}
|
|
3812
3831
|
return obj;
|
|
3813
3832
|
},
|
|
3814
3833
|
create(base) {
|
|
@@ -3820,6 +3839,7 @@ var InitializeResponse = {
|
|
|
3820
3839
|
message.protocol_version = object.protocol_version ?? "";
|
|
3821
3840
|
message.supported_protocols = object.supported_protocols?.map((e) => e) || [];
|
|
3822
3841
|
message.command_paths = object.command_paths?.map((e) => e) || [];
|
|
3842
|
+
message.contract = object.contract ?? "";
|
|
3823
3843
|
return message;
|
|
3824
3844
|
}
|
|
3825
3845
|
};
|
|
@@ -9309,7 +9329,7 @@ var BundleApplyResult = {
|
|
|
9309
9329
|
}
|
|
9310
9330
|
};
|
|
9311
9331
|
function createBaseCreatedRef() {
|
|
9312
|
-
return { scope: "", id: "", module_key: "", source_id: "" };
|
|
9332
|
+
return { scope: "", id: "", module_key: "", source_id: "", group_id: "" };
|
|
9313
9333
|
}
|
|
9314
9334
|
var CreatedRef = {
|
|
9315
9335
|
encode(message, writer = new import_wire4.BinaryWriter()) {
|
|
@@ -9325,6 +9345,9 @@ var CreatedRef = {
|
|
|
9325
9345
|
if (message.source_id !== "") {
|
|
9326
9346
|
writer.uint32(34).string(message.source_id);
|
|
9327
9347
|
}
|
|
9348
|
+
if (message.group_id !== "") {
|
|
9349
|
+
writer.uint32(42).string(message.group_id);
|
|
9350
|
+
}
|
|
9328
9351
|
return writer;
|
|
9329
9352
|
},
|
|
9330
9353
|
decode(input, length) {
|
|
@@ -9362,6 +9385,13 @@ var CreatedRef = {
|
|
|
9362
9385
|
message.source_id = reader.string();
|
|
9363
9386
|
continue;
|
|
9364
9387
|
}
|
|
9388
|
+
case 5: {
|
|
9389
|
+
if (tag !== 42) {
|
|
9390
|
+
break;
|
|
9391
|
+
}
|
|
9392
|
+
message.group_id = reader.string();
|
|
9393
|
+
continue;
|
|
9394
|
+
}
|
|
9365
9395
|
}
|
|
9366
9396
|
if ((tag & 7) === 4 || tag === 0) {
|
|
9367
9397
|
break;
|
|
@@ -9375,7 +9405,8 @@ var CreatedRef = {
|
|
|
9375
9405
|
scope: isSet3(object.scope) ? globalThis.String(object.scope) : "",
|
|
9376
9406
|
id: isSet3(object.id) ? globalThis.String(object.id) : "",
|
|
9377
9407
|
module_key: isSet3(object.moduleKey) ? globalThis.String(object.moduleKey) : isSet3(object.module_key) ? globalThis.String(object.module_key) : "",
|
|
9378
|
-
source_id: isSet3(object.sourceId) ? globalThis.String(object.sourceId) : isSet3(object.source_id) ? globalThis.String(object.source_id) : ""
|
|
9408
|
+
source_id: isSet3(object.sourceId) ? globalThis.String(object.sourceId) : isSet3(object.source_id) ? globalThis.String(object.source_id) : "",
|
|
9409
|
+
group_id: isSet3(object.groupId) ? globalThis.String(object.groupId) : isSet3(object.group_id) ? globalThis.String(object.group_id) : ""
|
|
9379
9410
|
};
|
|
9380
9411
|
},
|
|
9381
9412
|
toJSON(message) {
|
|
@@ -9392,6 +9423,9 @@ var CreatedRef = {
|
|
|
9392
9423
|
if (message.source_id !== "") {
|
|
9393
9424
|
obj.sourceId = message.source_id;
|
|
9394
9425
|
}
|
|
9426
|
+
if (message.group_id !== "") {
|
|
9427
|
+
obj.groupId = message.group_id;
|
|
9428
|
+
}
|
|
9395
9429
|
return obj;
|
|
9396
9430
|
},
|
|
9397
9431
|
create(base) {
|
|
@@ -9403,6 +9437,7 @@ var CreatedRef = {
|
|
|
9403
9437
|
message.id = object.id ?? "";
|
|
9404
9438
|
message.module_key = object.module_key ?? "";
|
|
9405
9439
|
message.source_id = object.source_id ?? "";
|
|
9440
|
+
message.group_id = object.group_id ?? "";
|
|
9406
9441
|
return message;
|
|
9407
9442
|
}
|
|
9408
9443
|
};
|
|
@@ -10915,6 +10950,7 @@ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
|
|
|
10915
10950
|
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
10916
10951
|
var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
|
|
10917
10952
|
var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
|
|
10953
|
+
var CONTRACT_RE = /^LACE_ENGINE_CONTRACT=([0-9a-f]{64})$/;
|
|
10918
10954
|
var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
|
|
10919
10955
|
var TOKEN_PREFIX = "LACE_ENGINE_TOKEN=";
|
|
10920
10956
|
var TOKEN_RE = new RegExp(`^${TOKEN_PREFIX}([0-9a-fA-F]{64})$`);
|
|
@@ -10951,6 +10987,7 @@ function spawnEngine(binaryPath, log) {
|
|
|
10951
10987
|
const rl = readline.createInterface({ input: proc.stdout });
|
|
10952
10988
|
let version;
|
|
10953
10989
|
let protocolVersion;
|
|
10990
|
+
let contract = "";
|
|
10954
10991
|
let port;
|
|
10955
10992
|
let token;
|
|
10956
10993
|
let settled = false;
|
|
@@ -10978,6 +11015,11 @@ function spawnEngine(binaryPath, log) {
|
|
|
10978
11015
|
protocolVersion = match[1];
|
|
10979
11016
|
return;
|
|
10980
11017
|
}
|
|
11018
|
+
match = line.match(CONTRACT_RE);
|
|
11019
|
+
if (match) {
|
|
11020
|
+
contract = match[1];
|
|
11021
|
+
return;
|
|
11022
|
+
}
|
|
10981
11023
|
match = line.match(PORT_RE);
|
|
10982
11024
|
if (match) {
|
|
10983
11025
|
port = Number(match[1]);
|
|
@@ -10997,7 +11039,7 @@ function spawnEngine(binaryPath, log) {
|
|
|
10997
11039
|
clearTimeout(timer);
|
|
10998
11040
|
resolve({
|
|
10999
11041
|
process: proc,
|
|
11000
|
-
handshake: { version, protocolVersion, port, token }
|
|
11042
|
+
handshake: { version, protocolVersion, contract, port, token }
|
|
11001
11043
|
});
|
|
11002
11044
|
}
|
|
11003
11045
|
});
|
|
@@ -11162,10 +11204,10 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11162
11204
|
}
|
|
11163
11205
|
/**
|
|
11164
11206
|
* Spawns the engine and connects to it. The handshake's protocol version
|
|
11165
|
-
*
|
|
11166
|
-
* (`
|
|
11167
|
-
* of `Initialize`'s answer): an engine that names
|
|
11168
|
-
* `
|
|
11207
|
+
* and contract are compared with the ones this library was built from
|
|
11208
|
+
* before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
|
|
11209
|
+
* check the canvas makes of `Initialize`'s answer): an engine that names
|
|
11210
|
+
* another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
|
|
11169
11211
|
* with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
|
|
11170
11212
|
* when no executable is found, `EINVAL` when Windows refuses to start a
|
|
11171
11213
|
* `.cmd` or `.bat`).
|
|
@@ -11192,7 +11234,11 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11192
11234
|
this.maybeRestart();
|
|
11193
11235
|
}
|
|
11194
11236
|
});
|
|
11195
|
-
(0, import_proto4.
|
|
11237
|
+
(0, import_proto4.checkEngineIdentity)({
|
|
11238
|
+
version: handshake.version,
|
|
11239
|
+
protocol: handshake.protocolVersion,
|
|
11240
|
+
contract: handshake.contract
|
|
11241
|
+
});
|
|
11196
11242
|
this._handshake = handshake;
|
|
11197
11243
|
this._transport = new LaceTransport(handshake.port, handshake.token);
|
|
11198
11244
|
this._initialized = await this._transport.initialize(handshake.version);
|
|
@@ -11274,7 +11320,7 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11274
11320
|
0 && (module.exports = {
|
|
11275
11321
|
BundleState,
|
|
11276
11322
|
BundleStateEvent,
|
|
11277
|
-
|
|
11323
|
+
EngineIdentityMismatchError,
|
|
11278
11324
|
EngineSpawnError,
|
|
11279
11325
|
InitializeResponse,
|
|
11280
11326
|
InvokeEvent,
|