@phreshos/node 0.1.14 → 0.1.15

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  export { gatewayAddress } from "./address.js";
2
2
  export { ClientEndpoint, ClientService, Endpoint, Process, Program, ServerEndpoint, ServerService, System, type ProgramProcessRunEvent, type ProgramProcessRunOptions } from "./system.js";
3
- export { Service, clientPermissionCatalog, isPermissionName, type ClientLaunch, type Launch, type Permission, type PermissionChange, type PermissionDefinition, type PermissionDefinitions, type PermissionInput, type PermissionName, type PermissionValue, type PermissionValueDomain, type Permissions, type ProgramPermissions, type ProgramDefinition, type ServerLaunch, type ServiceKey, type ShellEvent, type ShellOptions, type ProgramStartup, type Storage, } from "@phreshos/core";
3
+ export { Service, clientPermissionCatalog, isPermissionName, type ClientLaunch, type Launch, type Permission, type PermissionDefinition, type PermissionDefinitions, type PermissionInput, type PermissionName, type PermissionRequest, type PermissionValue, type PermissionValueDomain, type Permissions, type ProgramPermissions, type ProgramDefinition, type ServerLaunch, type ServiceKey, type ShellEvent, type ShellOptions, type ProgramStartup, type Storage, } 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";
@@ -1,13 +1,13 @@
1
1
  import { type ProgramPermissions, type ProgramSql, type ProgramStore } from "@phreshos/core";
2
2
  type Call = <Result = unknown>(event: string, ...values: unknown[]) => Promise<Result>;
3
- type ProgramAddress = Readonly<{
3
+ type HandleAddress = Readonly<{
4
4
  identity: string;
5
5
  reference: string;
6
6
  }>;
7
7
  /** Program-owned key-value storage carried through the owner-local Gateway. */
8
- export declare function programStore(call: Call, handle: ProgramAddress): ProgramStore;
8
+ export declare function programStore(call: Call, handle: HandleAddress): ProgramStore;
9
9
  /** Program-owned SQL capability carried through the owner-local Gateway. */
10
- export declare function programSql(call: Call, handle: ProgramAddress, database: "database" | "logs"): ProgramSql;
10
+ export declare function programSql(call: Call, handle: HandleAddress, database: "database" | "logs"): ProgramSql;
11
11
  /** Program permission management carried through the owner-local Gateway. */
12
- export declare function programPermissions(call: Call, handle: ProgramAddress): ProgramPermissions;
12
+ export declare function programPermissions(call: Call, handle: HandleAddress): ProgramPermissions;
13
13
  export {};
@@ -1,4 +1,4 @@
1
- import { parsePermission, parsePermissionChange, parsePermissions } from "@phreshos/core";
1
+ import { parsePermission, parsePermissions } from "@phreshos/core";
2
2
  /** Program-owned key-value storage carried through the owner-local Gateway. */
3
3
  export function programStore(call, handle) {
4
4
  const operate = (storeOperation, key, value, ttl) => (call("/program/store", handle, storeOperation, key, value, ttl));
@@ -25,8 +25,9 @@ export function programPermissions(call, handle) {
25
25
  return {
26
26
  async get(name) { return parsePermission(name, await operate("get", name)); },
27
27
  async all() { return parsePermissions(await operate("all")); },
28
- async set(name, permission) { return parsePermissionChange(name, await operate("set", name, permission)); },
29
- async delete(name) { return parsePermissionChange(name, await operate("delete", name)); }
28
+ async allows(name, permission = true) { return await operate("allows", name, permission) === true; },
29
+ async set(name, permission) { await operate("set", name, permission); },
30
+ async delete(name) { await operate("delete", name); }
30
31
  };
31
32
  }
32
33
  function written(statement, rest) {
@@ -21,14 +21,15 @@ export interface WindowState {
21
21
  layer: WindowLayer;
22
22
  location: string;
23
23
  }
24
- export interface ProcessState {
24
+ export interface ProcessIdentityState {
25
25
  reference: string;
26
26
  identity: string;
27
27
  name: string | null;
28
28
  program: string;
29
- parent: ProcessAddress | null;
30
29
  options: Record<string, string>;
31
30
  startedAt: Date;
31
+ }
32
+ export interface ProcessState extends ProcessIdentityState {
32
33
  server: {
33
34
  ready: boolean;
34
35
  service: boolean;
@@ -39,10 +40,6 @@ export interface ProcessState {
39
40
  window: WindowState;
40
41
  } | null;
41
42
  }
42
- export interface ProcessAddress {
43
- reference: string;
44
- identity: string;
45
- }
46
43
  export type Observation = Readonly<{
47
44
  scope: "endpoint";
48
45
  process: string;
@@ -97,4 +94,6 @@ export type ProgramAddress = Readonly<{
97
94
  identity: string;
98
95
  reference: string;
99
96
  }>;
97
+ /** Read the immutable facts needed to retain one Process handle. */
98
+ export declare function processIdentityState(value: unknown): ProcessIdentityState;
100
99
  export {};
@@ -270,26 +270,40 @@ function programState(value) {
270
270
  };
271
271
  }
272
272
  function processState(value) {
273
- if (!record(value) || typeof value.reference !== "string" || typeof value.identity !== "string" || typeof value.program !== "string" || !record(value.options)) {
273
+ const identity = processIdentityState(value);
274
+ const source = value;
275
+ return {
276
+ ...identity,
277
+ server: record(source.server) ? { ready: source.server.ready === true, service: source.server.service === true } : null,
278
+ client: record(source.client) ? {
279
+ service: source.client.service === true,
280
+ sameOrigin: source.client.sameOrigin === true,
281
+ window: windowState(source.client.window)
282
+ } : null
283
+ };
284
+ }
285
+ /** Read the immutable facts needed to retain one Process handle. */
286
+ export function processIdentityState(value) {
287
+ if (!record(value) || typeof value.reference !== "string" || typeof value.identity !== "string" || !record(value.options)) {
274
288
  throw new Error("The System returned an invalid Process");
275
289
  }
290
+ const program = typeof value.program === "string"
291
+ ? value.program
292
+ : record(value.program) && typeof value.program.identity === "string"
293
+ ? value.program.identity
294
+ : null;
276
295
  const startedAt = value.startedAt instanceof Date ? value.startedAt : new Date(String(value.startedAt));
296
+ if (program === null)
297
+ throw new Error("The System returned an invalid Process owner");
277
298
  if (Number.isNaN(startedAt.getTime()))
278
299
  throw new Error("The System returned an invalid Process start time");
279
300
  return {
280
301
  reference: value.reference,
281
302
  identity: value.identity,
282
303
  name: typeof value.name === "string" ? value.name : null,
283
- program: value.program,
284
- parent: address(value.parent),
304
+ program,
285
305
  options: value.options,
286
- startedAt,
287
- server: record(value.server) ? { ready: value.server.ready === true, service: value.server.service === true } : null,
288
- client: record(value.client) ? {
289
- service: value.client.service === true,
290
- sameOrigin: value.client.sameOrigin === true,
291
- window: windowState(value.client.window)
292
- } : null
306
+ startedAt
293
307
  };
294
308
  }
295
309
  function windowState(value) {
@@ -306,11 +320,6 @@ function windowState(value) {
306
320
  location: value.location
307
321
  };
308
322
  }
309
- function address(value) {
310
- if (!record(value) || typeof value.reference !== "string" || typeof value.identity !== "string")
311
- return null;
312
- return { reference: value.reference, identity: value.identity };
313
- }
314
323
  function windowMessage(event, process) {
315
324
  const window = process.client.window;
316
325
  if (event === "move")
package/dist/system.js CHANGED
@@ -7,7 +7,7 @@ import { resolveHome } from "./home.js";
7
7
  import { filesystemStorage, nativeStorage } from "./storage.js";
8
8
  import { programPermissions, programSql, programStore } from "./program-resources.js";
9
9
  import { EndpointTrafficHandle, ServerTrafficHandle } from "./traffic.js";
10
- import SystemRepresentation, {} from "./representation.js";
10
+ import SystemRepresentation, { processIdentityState } from "./representation.js";
11
11
  import { GatewayConnection, openConnection } from "./transport.js";
12
12
  import Uploads from "./uploads.js";
13
13
  import shell from "./shell.js";
@@ -384,13 +384,11 @@ class ProcessHandle extends ProcessBase {
384
384
  async parent() {
385
385
  if (!await this.exists())
386
386
  throw new Error(`Process "${this.identity}" no longer exists`);
387
- const snapshot = processState(this.system, this);
388
- if (snapshot.parent === null)
389
- return null;
390
- const parent = await this.system.process.find(snapshot.parent.identity);
391
- if (!parent)
392
- throw new Error("The parent Process no longer exists");
393
- return parent;
387
+ const value = await representation(this.system).call("/process/parent", {
388
+ identity: this.identity,
389
+ reference: processReference(this)
390
+ });
391
+ return value === null ? null : processHandle(this.system, processIdentityState(value));
394
392
  }
395
393
  async option(name) { return processState(this.system, this).options[name]; }
396
394
  async exit() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/node",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
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",
39
+ "@phreshos/core": "^0.1.40",
40
40
  "@the-link/ipc": "^0.2.1",
41
41
  "@the-link/messagepack": "^0.1.0",
42
42
  "adm-zip": "^0.6.0",