@fungi.computer/computer 0.8.5 → 0.8.6

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.
@@ -7,3 +7,15 @@ export declare function recordComputerName(sql: WatchdogSqliteOwner["sql"], name
7
7
  * reached this Computer.
8
8
  */
9
9
  export declare function computerName(sql: WatchdogSqliteOwner["sql"], wokenAs: string | undefined): string | undefined;
10
+ /**
11
+ * Learn the name of a Computer no named wake has reached, from names its host
12
+ * already knows. A candidate is accepted only when the Computer's own
13
+ * namespace derives this object's id from it; anything else is refused and
14
+ * never stored. Call it only where recording is wanted, never after an
15
+ * erasure that must stay erased.
16
+ */
17
+ export declare function learnComputerName<Id extends {
18
+ equals(other: Id): boolean;
19
+ }>(sql: WatchdogSqliteOwner["sql"], id: Id, namespace: Readonly<{
20
+ idFromName(name: string): Id;
21
+ }> | undefined, candidates: readonly string[]): string | undefined;
@@ -25,6 +25,23 @@ export function recordComputerName(sql, name) {
25
25
  export function computerName(sql, wokenAs) {
26
26
  return wokenAs ?? storedComputerName(sql);
27
27
  }
28
+ /**
29
+ * Learn the name of a Computer no named wake has reached, from names its host
30
+ * already knows. A candidate is accepted only when the Computer's own
31
+ * namespace derives this object's id from it; anything else is refused and
32
+ * never stored. Call it only where recording is wanted, never after an
33
+ * erasure that must stay erased.
34
+ */
35
+ export function learnComputerName(sql, id, namespace, candidates) {
36
+ const known = storedComputerName(sql);
37
+ if (known !== undefined || namespace === undefined)
38
+ return known;
39
+ const name = candidates.find((candidate) => id.equals(namespace.idFromName(candidate)));
40
+ if (name === undefined)
41
+ return undefined;
42
+ recordComputerName(sql, name);
43
+ return name;
44
+ }
28
45
  function storedComputerName(sql) {
29
46
  const recorded = sql
30
47
  .exec("SELECT 1 FROM sqlite_master WHERE type='table' AND name='computer_name'")
package/dist/index.d.ts CHANGED
@@ -52,6 +52,10 @@ export type ComputerEnv = OnBoxVmEnv & Readonly<{
52
52
  }) => Fetcher;
53
53
  /** Platform kill switch for container-backed Computer operations. */
54
54
  HOSTED_COMPUTERS?: string;
55
+ /** This Computer's own namespace; derives and verifies its object id. */
56
+ COMPUTER?: Readonly<{
57
+ idFromName(name: string): DurableObjectId;
58
+ }>;
55
59
  LOADER?: NonNullable<WorkerShellBackendOptions["loader"]>;
56
60
  }>;
57
61
  /** A command could not be placed on an attached backend. */
@@ -84,6 +88,8 @@ declare class ContainerComputer extends ContainerComputerBase {
84
88
  * name-addressed wake has reached this Computer yet.
85
89
  */
86
90
  protected computerName(): string | undefined;
91
+ /** Names this host knows this Computer may have; each is verified, not trusted. */
92
+ protected nameCandidates(): readonly string[];
87
93
  getWorkspaceContainer(): import("@fungi.computer/cloudflare-computer/backends/container").WorkspaceContainerAPI;
88
94
  /**
89
95
  * This Computer's attached backends, in attach order. The standalone
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
53
53
  import { boundExecStream } from "./exec-output.js";
54
54
  export { createLocalBackendReplayStore } from "./local-backend-replay.js";
55
55
  import { computerInternetAccess } from "./internet-access.js";
56
- import { computerName, recordComputerName } from "./computer-name.js";
56
+ import { computerName, learnComputerName, recordComputerName, } from "./computer-name.js";
57
57
  import { getWorkspace, SQLiteWorkspaceProvider, Workspace, WorkspaceProxy, WorkspaceServiceProxy, } from "@fungi.computer/cloudflare-computer";
58
58
  import { WorkerShellBackend, } from "@fungi.computer/cloudflare-computer/backends/worker-shell";
59
59
  import jqCommands from "@fungi.computer/cloudflare-computer/shell/jq";
@@ -249,7 +249,16 @@ class ContainerComputer extends ContainerComputerBase {
249
249
  * name-addressed wake has reached this Computer yet.
250
250
  */
251
251
  computerName() {
252
- return computerName(this.state.storage.sql, this.state.id.name);
252
+ const known = computerName(this.state.storage.sql, this.state.id.name);
253
+ if (known !== undefined)
254
+ return known;
255
+ // An object that predates the record learns its name from the names its
256
+ // host already knows, verified against this object's id.
257
+ return learnComputerName(this.state.storage.sql, this.state.id, this.bindings.COMPUTER, this.nameCandidates());
258
+ }
259
+ /** Names this host knows this Computer may have; each is verified, not trusted. */
260
+ nameCandidates() {
261
+ return [];
253
262
  }
254
263
  getWorkspaceContainer() {
255
264
  assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Cloudflare Computer host for one durable Fungi Computer",
6
6
  "type": "module",