@lace-cloud/host 0.35.0 → 0.36.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 +36 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +21 -6
- package/dist/index.d.ts +21 -6
- package/dist/index.mjs +37 -11
- 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,
|
|
@@ -3726,7 +3726,7 @@ var InitializeRequest = {
|
|
|
3726
3726
|
}
|
|
3727
3727
|
};
|
|
3728
3728
|
function createBaseInitializeResponse() {
|
|
3729
|
-
return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [] };
|
|
3729
|
+
return { server_version: "", protocol_version: "", supported_protocols: [], command_paths: [], contract: "" };
|
|
3730
3730
|
}
|
|
3731
3731
|
var InitializeResponse = {
|
|
3732
3732
|
encode(message, writer = new import_wire4.BinaryWriter()) {
|
|
@@ -3742,6 +3742,9 @@ var InitializeResponse = {
|
|
|
3742
3742
|
for (const v of message.command_paths) {
|
|
3743
3743
|
writer.uint32(42).string(v);
|
|
3744
3744
|
}
|
|
3745
|
+
if (message.contract !== "") {
|
|
3746
|
+
writer.uint32(50).string(message.contract);
|
|
3747
|
+
}
|
|
3745
3748
|
return writer;
|
|
3746
3749
|
},
|
|
3747
3750
|
decode(input, length) {
|
|
@@ -3779,6 +3782,13 @@ var InitializeResponse = {
|
|
|
3779
3782
|
message.command_paths.push(reader.string());
|
|
3780
3783
|
continue;
|
|
3781
3784
|
}
|
|
3785
|
+
case 6: {
|
|
3786
|
+
if (tag !== 50) {
|
|
3787
|
+
break;
|
|
3788
|
+
}
|
|
3789
|
+
message.contract = reader.string();
|
|
3790
|
+
continue;
|
|
3791
|
+
}
|
|
3782
3792
|
}
|
|
3783
3793
|
if ((tag & 7) === 4 || tag === 0) {
|
|
3784
3794
|
break;
|
|
@@ -3792,7 +3802,8 @@ var InitializeResponse = {
|
|
|
3792
3802
|
server_version: isSet3(object.serverVersion) ? globalThis.String(object.serverVersion) : isSet3(object.server_version) ? globalThis.String(object.server_version) : "",
|
|
3793
3803
|
protocol_version: isSet3(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet3(object.protocol_version) ? globalThis.String(object.protocol_version) : "",
|
|
3794
3804
|
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)) : []
|
|
3805
|
+
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)) : [],
|
|
3806
|
+
contract: isSet3(object.contract) ? globalThis.String(object.contract) : ""
|
|
3796
3807
|
};
|
|
3797
3808
|
},
|
|
3798
3809
|
toJSON(message) {
|
|
@@ -3809,6 +3820,9 @@ var InitializeResponse = {
|
|
|
3809
3820
|
if (message.command_paths?.length) {
|
|
3810
3821
|
obj.commandPaths = message.command_paths;
|
|
3811
3822
|
}
|
|
3823
|
+
if (message.contract !== "") {
|
|
3824
|
+
obj.contract = message.contract;
|
|
3825
|
+
}
|
|
3812
3826
|
return obj;
|
|
3813
3827
|
},
|
|
3814
3828
|
create(base) {
|
|
@@ -3820,6 +3834,7 @@ var InitializeResponse = {
|
|
|
3820
3834
|
message.protocol_version = object.protocol_version ?? "";
|
|
3821
3835
|
message.supported_protocols = object.supported_protocols?.map((e) => e) || [];
|
|
3822
3836
|
message.command_paths = object.command_paths?.map((e) => e) || [];
|
|
3837
|
+
message.contract = object.contract ?? "";
|
|
3823
3838
|
return message;
|
|
3824
3839
|
}
|
|
3825
3840
|
};
|
|
@@ -10915,6 +10930,7 @@ function endEngine(proc, graceMs = EXIT_GRACE_MS) {
|
|
|
10915
10930
|
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
10916
10931
|
var VERSION_RE = /^LACE_ENGINE_VERSION=(.+)$/;
|
|
10917
10932
|
var PROTOCOL_RE = /^LACE_ENGINE_PROTOCOL_VERSION=(\d+)$/;
|
|
10933
|
+
var CONTRACT_RE = /^LACE_ENGINE_CONTRACT=([0-9a-f]{64})$/;
|
|
10918
10934
|
var PORT_RE = /^LACE_ENGINE_PORT=(\d+)$/;
|
|
10919
10935
|
var TOKEN_PREFIX = "LACE_ENGINE_TOKEN=";
|
|
10920
10936
|
var TOKEN_RE = new RegExp(`^${TOKEN_PREFIX}([0-9a-fA-F]{64})$`);
|
|
@@ -10951,6 +10967,7 @@ function spawnEngine(binaryPath, log) {
|
|
|
10951
10967
|
const rl = readline.createInterface({ input: proc.stdout });
|
|
10952
10968
|
let version;
|
|
10953
10969
|
let protocolVersion;
|
|
10970
|
+
let contract = "";
|
|
10954
10971
|
let port;
|
|
10955
10972
|
let token;
|
|
10956
10973
|
let settled = false;
|
|
@@ -10978,6 +10995,11 @@ function spawnEngine(binaryPath, log) {
|
|
|
10978
10995
|
protocolVersion = match[1];
|
|
10979
10996
|
return;
|
|
10980
10997
|
}
|
|
10998
|
+
match = line.match(CONTRACT_RE);
|
|
10999
|
+
if (match) {
|
|
11000
|
+
contract = match[1];
|
|
11001
|
+
return;
|
|
11002
|
+
}
|
|
10981
11003
|
match = line.match(PORT_RE);
|
|
10982
11004
|
if (match) {
|
|
10983
11005
|
port = Number(match[1]);
|
|
@@ -10997,7 +11019,7 @@ function spawnEngine(binaryPath, log) {
|
|
|
10997
11019
|
clearTimeout(timer);
|
|
10998
11020
|
resolve({
|
|
10999
11021
|
process: proc,
|
|
11000
|
-
handshake: { version, protocolVersion, port, token }
|
|
11022
|
+
handshake: { version, protocolVersion, contract, port, token }
|
|
11001
11023
|
});
|
|
11002
11024
|
}
|
|
11003
11025
|
});
|
|
@@ -11162,10 +11184,10 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11162
11184
|
}
|
|
11163
11185
|
/**
|
|
11164
11186
|
* Spawns the engine and connects to it. The handshake's protocol version
|
|
11165
|
-
*
|
|
11166
|
-
* (`
|
|
11167
|
-
* of `Initialize`'s answer): an engine that names
|
|
11168
|
-
* `
|
|
11187
|
+
* and contract are compared with the ones this library was built from
|
|
11188
|
+
* before any RPC is sent (`checkEngineIdentity`, `@lace-cloud/proto`, the
|
|
11189
|
+
* check the canvas makes of `Initialize`'s answer): an engine that names
|
|
11190
|
+
* another, or no contract, rejects with `EngineIdentityMismatchError`. A binary that cannot be started rejects
|
|
11169
11191
|
* with `EngineSpawnError`, whose `code` is the spawn error's (`ENOENT`
|
|
11170
11192
|
* when no executable is found, `EINVAL` when Windows refuses to start a
|
|
11171
11193
|
* `.cmd` or `.bat`).
|
|
@@ -11192,7 +11214,11 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11192
11214
|
this.maybeRestart();
|
|
11193
11215
|
}
|
|
11194
11216
|
});
|
|
11195
|
-
(0, import_proto4.
|
|
11217
|
+
(0, import_proto4.checkEngineIdentity)({
|
|
11218
|
+
version: handshake.version,
|
|
11219
|
+
protocol: handshake.protocolVersion,
|
|
11220
|
+
contract: handshake.contract
|
|
11221
|
+
});
|
|
11196
11222
|
this._handshake = handshake;
|
|
11197
11223
|
this._transport = new LaceTransport(handshake.port, handshake.token);
|
|
11198
11224
|
this._initialized = await this._transport.initialize(handshake.version);
|
|
@@ -11274,7 +11300,7 @@ var ServerManager = class extends import_node_events.EventEmitter {
|
|
|
11274
11300
|
0 && (module.exports = {
|
|
11275
11301
|
BundleState,
|
|
11276
11302
|
BundleStateEvent,
|
|
11277
|
-
|
|
11303
|
+
EngineIdentityMismatchError,
|
|
11278
11304
|
EngineSpawnError,
|
|
11279
11305
|
InitializeResponse,
|
|
11280
11306
|
InvokeEvent,
|