From 10c82b368913c96a0bc17ba0a12031ad958098e7 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 14:58:28 -0700 Subject: [PATCH 1/8] feat(stream): Relax makeStream queue argument types --- packages/stream/index.js | 4 ++-- packages/stream/types.d.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/stream/index.js b/packages/stream/index.js index 4ab2588338..1a2ce9188c 100644 --- a/packages/stream/index.js +++ b/packages/stream/index.js @@ -54,8 +54,8 @@ harden(makeQueue); * @template TWrite * @template TReadReturn * @template TWriteReturn - * @param {import('./types.js').AsyncQueue>} acks - * @param {import('./types.js').AsyncQueue>} data + * @param {import('./types.js').AsyncSpring>} acks + * @param {import('./types.js').AsyncSink>} data */ export const makeStream = (acks, data) => { const stream = harden({ diff --git a/packages/stream/types.d.ts b/packages/stream/types.d.ts index ecdecb9118..c5a95930de 100644 --- a/packages/stream/types.d.ts +++ b/packages/stream/types.d.ts @@ -1,8 +1,15 @@ -export interface AsyncQueue { +export interface AsyncSink { put(value: TValue | Promise): void; +} + +export interface AsyncSpring { get(): Promise; } +export interface AsyncQueue + extends AsyncSpring, + AsyncSink {} + // Stream is nearly identical to AsyncGenerator and AsyncGenerator should // probably be identical to this definition of Stream. // Stream does not make the mistake of conflating the read and write return @@ -40,8 +47,8 @@ export declare function makeStream< TReadReturn = undefined, TWriteReturn = undefined, >( - acks: AsyncQueue>, - data: AsyncQueue>, + acks: AsyncSpring>, + data: AsyncSink>, ): Stream; export declare function makePipe< From 163bd884f357ff796d785d2c2328b46ffc114be8 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:04:45 -0700 Subject: [PATCH 2/8] types(daemon): ts-check all the sources --- packages/daemon/src/pet-name.js | 2 ++ packages/daemon/src/pubsub.js | 2 ++ packages/daemon/src/serve-private-path.js | 2 ++ packages/daemon/src/serve-private-port-http.js | 2 ++ packages/daemon/src/web-page-bundler.js | 2 ++ packages/daemon/src/web-page.js | 1 + packages/daemon/src/worker-node.js | 1 + 7 files changed, 12 insertions(+) diff --git a/packages/daemon/src/pet-name.js b/packages/daemon/src/pet-name.js index 1502133a99..337a836135 100644 --- a/packages/daemon/src/pet-name.js +++ b/packages/daemon/src/pet-name.js @@ -1,3 +1,5 @@ +// @ts-check + const { quote: q } = assert; const validNamePattern = /^[a-z][a-z0-9-]{0,127}$/; diff --git a/packages/daemon/src/pubsub.js b/packages/daemon/src/pubsub.js index 407814cf17..9be31ae94d 100644 --- a/packages/daemon/src/pubsub.js +++ b/packages/daemon/src/pubsub.js @@ -1,3 +1,5 @@ +// @ts-check + import { makePromiseKit } from '@endo/promise-kit'; import { makeStream } from '@endo/stream'; diff --git a/packages/daemon/src/serve-private-path.js b/packages/daemon/src/serve-private-path.js index 8a17e4b077..fb6629c397 100644 --- a/packages/daemon/src/serve-private-path.js +++ b/packages/daemon/src/serve-private-path.js @@ -1,3 +1,5 @@ +// @ts-check + import { makeNetstringCapTP } from './connection.js'; const { quote: q } = assert; diff --git a/packages/daemon/src/serve-private-port-http.js b/packages/daemon/src/serve-private-port-http.js index de176d82c3..9344196c6a 100644 --- a/packages/daemon/src/serve-private-port-http.js +++ b/packages/daemon/src/serve-private-port-http.js @@ -1,3 +1,5 @@ +// @ts-check + import { E } from '@endo/far'; import { mapReader, mapWriter } from '@endo/stream'; import { diff --git a/packages/daemon/src/web-page-bundler.js b/packages/daemon/src/web-page-bundler.js index e8ffda7407..3431106e3a 100644 --- a/packages/daemon/src/web-page-bundler.js +++ b/packages/daemon/src/web-page-bundler.js @@ -1,3 +1,5 @@ +// @ts-check + // This is a built-in unsafe plugin for lazily constructing the web-page.js // bundle for booting up web caplets. // The hard-coded 'web-page-js' formula is a hard-coded 'import-unsafe' formula diff --git a/packages/daemon/src/web-page.js b/packages/daemon/src/web-page.js index 796fcf075d..bfc7ee47bc 100644 --- a/packages/daemon/src/web-page.js +++ b/packages/daemon/src/web-page.js @@ -1,3 +1,4 @@ +// @ts-check /* global window, document */ import '@endo/init/debug.js'; diff --git a/packages/daemon/src/worker-node.js b/packages/daemon/src/worker-node.js index f5e8221610..9360ec8567 100644 --- a/packages/daemon/src/worker-node.js +++ b/packages/daemon/src/worker-node.js @@ -1,3 +1,4 @@ +// @ts-check /* global process */ // Establish a perimeter: From 89f6554a8d720f7aea77980fef8cda0604723950 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Wed, 11 Oct 2023 17:53:26 -0700 Subject: [PATCH 3/8] fix(daemon): Clarify types of server daemon powers --- packages/daemon/src/daemon-node-powers.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/daemon/src/daemon-node-powers.js b/packages/daemon/src/daemon-node-powers.js index f78b0f9046..260694f905 100644 --- a/packages/daemon/src/daemon-node-powers.js +++ b/packages/daemon/src/daemon-node-powers.js @@ -223,6 +223,12 @@ export const makeNetworkPowers = ({ http, ws, net }) => { return readFrom; }; + /** + * @param {object} args + * @param {number} args.port + * @param {string} [args.host] + * @param {Promise} args.cancelled + */ const servePort = async ({ port, host = '0.0.0.0', cancelled }) => serveListener( server => @@ -232,6 +238,11 @@ export const makeNetworkPowers = ({ http, ws, net }) => { cancelled, ); + /** + * @param {object} args + * @param {string} args.path + * @param {Promise} args.cancelled + */ const servePath = async ({ path, cancelled }) => serveListener( server => From 6d0bb32a735a21213e75a383c92bdf08bd04488a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:16:43 -0700 Subject: [PATCH 4/8] fix(daemon): Realign pet store and host types --- packages/daemon/src/types.d.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index bc67d624d4..bdc337e19f 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -141,13 +141,13 @@ export interface Topic< } export interface PetStore { - lookup(petName: string): string | undefined; - reverseLookup(formulaIdentifier: string): Array; list(): Array; - follow(): Promise>>; write(petName: string, formulaIdentifier: string): Promise; remove(petName: string); rename(fromPetName: string, toPetName: string); + lookup(petName: string): string | undefined; + reverseLookup(formulaIdentifier: string): Array; + follow(): Promise>>; } export type RequestFn = ( @@ -184,9 +184,10 @@ export interface EndoGuest { export interface EndoHost { listMessages(): Promise>; followMessages(): ERef>; + lookup(petName: string): Promise; resolve(requestNumber: number, petName: string); reject(requestNumber: number, message: string); - lookup(ref: object): Promise>; + reverseLookup(ref: object): Promise>; remove(petName: string); rename(fromPetName: string, toPetName: string); list(): Array; // pet names From 29a9f5c078910dc5b4c5cad2546049cf9e48a008 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:17:47 -0700 Subject: [PATCH 5/8] fix(daemon): Relocate type reference for AsyncQueue --- packages/daemon/src/pubsub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/pubsub.js b/packages/daemon/src/pubsub.js index 9be31ae94d..1a03ba5853 100644 --- a/packages/daemon/src/pubsub.js +++ b/packages/daemon/src/pubsub.js @@ -11,7 +11,7 @@ const freeze = /** @type {(v: T | Readonly) => T} */ (Object.freeze); /** * @template TValue TValue * @param {TValue} value - * @returns {import('./types.js').AsyncQueue} + * @returns {import('@endo/stream').AsyncQueue} */ export const makeNullQueue = value => harden({ From a470ce6a0c3dd1c6c4484389a5229edf9820c08f Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:18:28 -0700 Subject: [PATCH 6/8] fix(daemon): Narrow type of window location for web page bootstrap --- packages/daemon/src/web-page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/web-page.js b/packages/daemon/src/web-page.js index bfc7ee47bc..02b80c75aa 100644 --- a/packages/daemon/src/web-page.js +++ b/packages/daemon/src/web-page.js @@ -22,7 +22,7 @@ const endowments = Object.freeze({ console, }); -const url = new URL('/', window.location); +const url = new URL('/', `${window.location}`); url.protocol = 'ws'; const bootstrap = Far('WebFacet', { From 83b3be447363a032e3f3d2e003d8b07dac5d876e Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:20:15 -0700 Subject: [PATCH 7/8] fix(daemon): Fix locator type reference --- packages/daemon/src/worker-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/worker-node.js b/packages/daemon/src/worker-node.js index 9360ec8567..168afbff5a 100644 --- a/packages/daemon/src/worker-node.js +++ b/packages/daemon/src/worker-node.js @@ -25,7 +25,7 @@ if (process.argv.length < 7) { const [workerUuid, sockPath, statePath, ephemeralStatePath, cachePath] = process.argv.slice(2); -/** @type {import('../index.js').Locator} */ +/** @type {import('./types.js').Locator} */ const locator = { sockPath, statePath, From 2f8aa51c97356327ca101af58a8c7aa8e74099cf Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Thu, 12 Oct 2023 15:20:48 -0700 Subject: [PATCH 8/8] fix(daemon): Loosen type for panic message --- packages/daemon/src/mail.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/daemon/src/mail.js b/packages/daemon/src/mail.js index e02adf1077..9e8bda7858 100644 --- a/packages/daemon/src/mail.js +++ b/packages/daemon/src/mail.js @@ -103,7 +103,9 @@ export const makeMailboxMaker = ({ } return undefined; } - throw Error(`panic: Unknown message type ${type}`); + throw new Error( + `panic: Unknown message type ${/** @type {any} */ (message).type}`, + ); }; const listMessages = async () =>