@phreshos/node 0.1.6 → 0.1.7
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/main.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/project.js +6 -0
- package/dist/system.js +34 -33
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { gatewayAddress } from "./address.js";
|
|
2
2
|
export { Client, ClientService, Endpoint, Process, Program, Server, ServerService, System, type ProgramProcessRunEvent, type ProgramProcessRunOptions } from "./system.js";
|
|
3
|
-
export { Service, type
|
|
3
|
+
export { Service, type ClientLaunch, type Launch, type ProgramDefinition, type ServerLaunch, type ServiceKey, } from "@phreshos/core";
|
|
4
4
|
export { resolveHome } from "./home.js";
|
|
5
5
|
export { Project, type Manifest, type PackedProject, type ProjectMode, type ProjectOptions, type ProjectRunOptions } from "./project.js";
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { gatewayAddress } from "./address.js";
|
|
2
2
|
export { Client, ClientService, Endpoint, Process, Program, Server, ServerService, System } from "./system.js";
|
|
3
|
-
export { Service } from "@phreshos/core";
|
|
3
|
+
export { Service, } from "@phreshos/core";
|
|
4
4
|
export { resolveHome } from "./home.js";
|
|
5
5
|
export { Project } from "./project.js";
|
package/dist/project.js
CHANGED
|
@@ -70,6 +70,7 @@ export class Project {
|
|
|
70
70
|
...server && { server: {
|
|
71
71
|
location: resolve(this.directory, server.location),
|
|
72
72
|
start: server.start,
|
|
73
|
+
service: server.service,
|
|
73
74
|
installCommand: config.server?.installCommand,
|
|
74
75
|
uninstallCommand: config.server?.uninstallCommand,
|
|
75
76
|
...serverExecution(server)
|
|
@@ -77,6 +78,7 @@ export class Project {
|
|
|
77
78
|
...client && { client: {
|
|
78
79
|
location: /^https?:\/\//i.test(client.location) ? client.location : resolve(this.directory, client.location),
|
|
79
80
|
start: client.start,
|
|
81
|
+
service: client.service,
|
|
80
82
|
title: config.client?.title,
|
|
81
83
|
size: config.client?.size,
|
|
82
84
|
position: config.client?.position,
|
|
@@ -203,6 +205,8 @@ function validateConfig(config) {
|
|
|
203
205
|
throw new Error(`A declared ${half} half must have a location`);
|
|
204
206
|
if (declared.start !== undefined && typeof declared.start !== "boolean")
|
|
205
207
|
throw new Error(`A declared ${half} Endpoint's start default must be true or false`);
|
|
208
|
+
if (declared.service !== undefined && typeof declared.service !== "boolean")
|
|
209
|
+
throw new Error(`A declared ${half} Endpoint's service default must be true or false`);
|
|
206
210
|
}
|
|
207
211
|
if (!(config.server && (config.server.start ?? true)) && !(config.client && (config.client.start ?? true))) {
|
|
208
212
|
throw new Error("A Program's default Process must start a Server Endpoint, a Client Endpoint, or both");
|
|
@@ -269,6 +273,7 @@ function packageDefinition(config, version) {
|
|
|
269
273
|
...config.server && { server: {
|
|
270
274
|
location: "server",
|
|
271
275
|
start: config.server.start,
|
|
276
|
+
service: config.server.service,
|
|
272
277
|
installCommand: config.server.installCommand,
|
|
273
278
|
uninstallCommand: config.server.uninstallCommand,
|
|
274
279
|
...serverExecution(config.server)
|
|
@@ -276,6 +281,7 @@ function packageDefinition(config, version) {
|
|
|
276
281
|
...config.client && { client: {
|
|
277
282
|
location: "client",
|
|
278
283
|
start: config.client.start,
|
|
284
|
+
service: config.client.service,
|
|
279
285
|
title: config.client.title,
|
|
280
286
|
size: config.client.size,
|
|
281
287
|
position: config.client.position,
|
package/dist/system.js
CHANGED
|
@@ -62,8 +62,12 @@ export class System {
|
|
|
62
62
|
requireConnected(this);
|
|
63
63
|
if (!isServiceKey(key))
|
|
64
64
|
throw new Error("A complete service key is required");
|
|
65
|
-
const normalized = Object.freeze({
|
|
66
|
-
|
|
65
|
+
const normalized = Object.freeze({
|
|
66
|
+
...(key.program === undefined ? {} : { program: key.program }),
|
|
67
|
+
process: key.process,
|
|
68
|
+
endpoint: key.endpoint
|
|
69
|
+
});
|
|
70
|
+
const identity = JSON.stringify([key.program ?? null, key.process, key.endpoint]);
|
|
67
71
|
return systemState(this).handles.obtain(`service:${identity}`, () => normalized.endpoint === "server"
|
|
68
72
|
? new ServerServiceHandle(this, normalized)
|
|
69
73
|
: new ClientServiceHandle(this, normalized));
|
|
@@ -182,11 +186,15 @@ class ProgramHandle extends ProgramBase {
|
|
|
182
186
|
get description() { return this.snapshot.description; }
|
|
183
187
|
get hasAgent() { return this.snapshot.hasAgent; }
|
|
184
188
|
get server() {
|
|
185
|
-
return this.snapshot.server ? Object.freeze({
|
|
189
|
+
return this.snapshot.server ? Object.freeze({
|
|
190
|
+
start: this.snapshot.server.start,
|
|
191
|
+
service: this.snapshot.server.service
|
|
192
|
+
}) : null;
|
|
186
193
|
}
|
|
187
194
|
get client() {
|
|
188
195
|
return this.snapshot.client ? Object.freeze({
|
|
189
196
|
start: this.snapshot.client.start,
|
|
197
|
+
service: this.snapshot.client.service,
|
|
190
198
|
title: this.snapshot.client.title,
|
|
191
199
|
size: this.snapshot.client.size,
|
|
192
200
|
position: this.snapshot.client.position,
|
|
@@ -396,11 +404,12 @@ class EndpointOperations extends Events {
|
|
|
396
404
|
const value = await this.inspect();
|
|
397
405
|
return value.running;
|
|
398
406
|
}
|
|
399
|
-
async start(
|
|
407
|
+
async start(launch = {}) { await this.operation("start", launch); }
|
|
400
408
|
async stop() { await this.operation("stop"); }
|
|
401
|
-
async
|
|
402
|
-
|
|
403
|
-
|
|
409
|
+
async isService() {
|
|
410
|
+
return await transport(this.system).api({
|
|
411
|
+
capability: "endpoint", operation: "isService", process: this.owner.identity, endpoint: this.endpoint
|
|
412
|
+
});
|
|
404
413
|
}
|
|
405
414
|
publish(event, payload) {
|
|
406
415
|
void transport(this.system).control({ capability: "endpoint", operation: "publish", input: {
|
|
@@ -412,9 +421,9 @@ class EndpointOperations extends Events {
|
|
|
412
421
|
process: this.owner.identity, endpoint: this.endpoint
|
|
413
422
|
} });
|
|
414
423
|
}
|
|
415
|
-
async operation(operation,
|
|
424
|
+
async operation(operation, launch) {
|
|
416
425
|
await transport(this.system).control({ capability: "endpoint", operation, input: {
|
|
417
|
-
process: this.owner.identity, endpoint: this.endpoint, ...(
|
|
426
|
+
process: this.owner.identity, endpoint: this.endpoint, ...(launch ? { launch } : {})
|
|
418
427
|
} });
|
|
419
428
|
}
|
|
420
429
|
}
|
|
@@ -434,7 +443,8 @@ class ServerEndpoint extends ServerBase {
|
|
|
434
443
|
}
|
|
435
444
|
process() { return this.base.process(); }
|
|
436
445
|
exists() { return this.base.exists(); }
|
|
437
|
-
|
|
446
|
+
isService() { return this.base.isService(); }
|
|
447
|
+
start(launch) { return this.base.start(launch); }
|
|
438
448
|
stop() { return this.base.stop(); }
|
|
439
449
|
publish(event, payload) { return this.base.publish(event, payload); }
|
|
440
450
|
async ask(event, payload) {
|
|
@@ -450,9 +460,6 @@ class ServerEndpoint extends ServerBase {
|
|
|
450
460
|
async waitReady(timeout) {
|
|
451
461
|
await transport(this.system).control({ capability: "endpoint", operation: "waitReady", input: { process: this.owner.identity, endpoint: "server", timeout } });
|
|
452
462
|
}
|
|
453
|
-
async service() {
|
|
454
|
-
return await this.base.service();
|
|
455
|
-
}
|
|
456
463
|
}
|
|
457
464
|
class ClientEndpoint extends ClientBase {
|
|
458
465
|
endpoint = "client";
|
|
@@ -468,12 +475,10 @@ class ClientEndpoint extends ClientBase {
|
|
|
468
475
|
}
|
|
469
476
|
process() { return this.base.process(); }
|
|
470
477
|
exists() { return this.base.exists(); }
|
|
471
|
-
|
|
478
|
+
isService() { return this.base.isService(); }
|
|
479
|
+
start(launch) { return this.base.start(launch); }
|
|
472
480
|
stop() { return this.base.stop(); }
|
|
473
481
|
publish(event, payload) { return this.base.publish(event, payload); }
|
|
474
|
-
async service() {
|
|
475
|
-
return await this.base.service();
|
|
476
|
-
}
|
|
477
482
|
}
|
|
478
483
|
class SystemWindow extends Events {
|
|
479
484
|
system;
|
|
@@ -508,18 +513,18 @@ class SystemWindow extends Events {
|
|
|
508
513
|
class ServiceBase {
|
|
509
514
|
system;
|
|
510
515
|
key;
|
|
511
|
-
name;
|
|
512
516
|
lifecycle;
|
|
513
517
|
constructor(system, key) {
|
|
514
518
|
this.system = system;
|
|
515
519
|
this.key = key;
|
|
516
|
-
this.lifecycle = new Events(["
|
|
520
|
+
this.lifecycle = new Events(["start", "stop"], (event, signal, timeout) => transport(system).api({
|
|
517
521
|
capability: "service", operation: "wait", scope: "lifecycle", key, event, timeout
|
|
518
522
|
}, signal));
|
|
519
|
-
this.name = key.name;
|
|
520
523
|
}
|
|
521
|
-
async
|
|
522
|
-
|
|
524
|
+
async exists() { return await transport(this.system).api({ capability: "service", operation: "exists", key: this.key }); }
|
|
525
|
+
publish(event, payload) {
|
|
526
|
+
void transport(this.system).api({ capability: "service", operation: "publish", key: this.key, event, payload });
|
|
527
|
+
}
|
|
523
528
|
}
|
|
524
529
|
/** Node-SDK handle for a Service provided by a Server Endpoint. */
|
|
525
530
|
export class ServerService extends CoreServerService {
|
|
@@ -528,7 +533,6 @@ export class ServerService extends CoreServerService {
|
|
|
528
533
|
class ServerServiceHandle extends ServerService {
|
|
529
534
|
system;
|
|
530
535
|
key;
|
|
531
|
-
name;
|
|
532
536
|
lifecycle;
|
|
533
537
|
base;
|
|
534
538
|
constructor(system, key) {
|
|
@@ -536,17 +540,16 @@ class ServerServiceHandle extends ServerService {
|
|
|
536
540
|
this.system = system;
|
|
537
541
|
this.key = key;
|
|
538
542
|
this.base = new ServiceBase(system, key);
|
|
539
|
-
this.name = key.name;
|
|
540
543
|
this.lifecycle = this.base.lifecycle;
|
|
541
544
|
bindEvents(this, new Events([], (event, signal, timeout) => transport(system).api({
|
|
542
545
|
capability: "service", operation: "wait", scope: "events", key, event, timeout
|
|
543
546
|
}, signal)));
|
|
544
547
|
}
|
|
545
|
-
|
|
546
|
-
waitReady(timeout) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
548
|
+
exists() { return this.base.exists(); }
|
|
549
|
+
async waitReady(timeout) {
|
|
550
|
+
await transport(this.system).api({ capability: "service", operation: "waitReady", key: this.key, timeout });
|
|
551
|
+
}
|
|
552
|
+
publish = (event, payload) => this.base.publish(event, payload);
|
|
550
553
|
async ask(event, payload) {
|
|
551
554
|
return await transport(this.system).api({ capability: "service", operation: "ask", key: this.key, event, payload });
|
|
552
555
|
}
|
|
@@ -561,20 +564,18 @@ export class ClientService extends CoreClientService {
|
|
|
561
564
|
constructor() { super(); }
|
|
562
565
|
}
|
|
563
566
|
class ClientServiceHandle extends ClientService {
|
|
564
|
-
name;
|
|
565
567
|
lifecycle;
|
|
566
568
|
base;
|
|
567
569
|
constructor(system, key) {
|
|
568
570
|
super();
|
|
569
571
|
this.base = new ServiceBase(system, key);
|
|
570
|
-
this.name = key.name;
|
|
571
572
|
this.lifecycle = this.base.lifecycle;
|
|
572
573
|
bindEvents(this, new Events([], (event, signal, timeout) => transport(system).api({
|
|
573
574
|
capability: "service", operation: "wait", scope: "events", key, event, timeout
|
|
574
575
|
}, signal)));
|
|
575
576
|
}
|
|
576
|
-
|
|
577
|
-
|
|
577
|
+
exists() { return this.base.exists(); }
|
|
578
|
+
publish = (event, payload) => this.base.publish(event, payload);
|
|
578
579
|
}
|
|
579
580
|
async function listProcesses(system, program) {
|
|
580
581
|
const processes = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Node.js access to PhreshOS and Program projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepack": "node --run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@phreshos/core": "^0.1.
|
|
39
|
+
"@phreshos/core": "^0.1.29",
|
|
40
40
|
"adm-zip": "^0.6.0",
|
|
41
41
|
"jiti": "^2.7.0"
|
|
42
42
|
},
|