@powerhousedao/switchboard 6.2.3-dev.81 → 6.2.3-dev.82
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/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +17 -0
- package/dist/index.mjs +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/{server-cE1BWLQu.mjs → server-ChIFIbah.mjs} +15 -8
- package/dist/{server-cE1BWLQu.mjs.map → server-ChIFIbah.mjs.map} +1 -1
- package/dist/server.d.mts +7 -0
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/package.json +16 -16
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/goldens/supergraph.graphql +8 -3
package/dist/server.d.mts
CHANGED
|
@@ -110,6 +110,11 @@ export type StartServerOptions = {
|
|
|
110
110
|
* a caller-provided `reactor`.
|
|
111
111
|
*/
|
|
112
112
|
signalHandlers?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* `/ready` waits for this too: drives the caller seeds after the server
|
|
115
|
+
* starts. A rejection leaves the server not ready.
|
|
116
|
+
*/
|
|
117
|
+
readyAfter?: Promise<unknown>;
|
|
113
118
|
/**
|
|
114
119
|
* Registry URL for the HttpPackageLoader. Enables `PackagesSubgraph`
|
|
115
120
|
* (install/uninstall mutations) plus dynamic package resolution.
|
|
@@ -259,6 +264,8 @@ export type SwitchboardDeps = {
|
|
|
259
264
|
fatalErrorShutdown?: boolean;
|
|
260
265
|
/** See {@link StartServerOptions.signalHandlers}. */
|
|
261
266
|
signalHandlers?: boolean;
|
|
267
|
+
/** See {@link StartServerOptions.readyAfter}. */
|
|
268
|
+
readyAfter?: Promise<unknown>;
|
|
262
269
|
/** The privacy add-on's signer, for a caller-provided reactor. */
|
|
263
270
|
privacySigner?: ISigner;
|
|
264
271
|
};
|
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KC9GU;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;YCXU;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;;;;;;YAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/privacy.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KC9GU;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;YCXU;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;;;;;;YAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;EAKA,aAAa;;;;;;;EAOb;EACA;;;;;;;EAOA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;EAMA,oBAAoB;;;EAGpB;;;;EAIA;;;EAGA;IACE;;;;IAIA;MAAc;MAAY;QAAW;QAAkB;;;;;EAGzD,UAAU;EACV,kBAAkB;EACl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;;;;;;;;;;;;qBAovCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-BO0n9R02.mjs";
|
|
3
|
-
import { a as resolvePgliteStorageDirs, i as isPortAvailable, l as applySwitchboardReactorDefaults, n as deriveAttachmentServiceConfig, o as startSwitchboard, r as initSwitchboardProcess, t as createReactorKysely } from "./server-
|
|
3
|
+
import { a as resolvePgliteStorageDirs, i as isPortAvailable, l as applySwitchboardReactorDefaults, n as deriveAttachmentServiceConfig, o as startSwitchboard, r as initSwitchboardProcess, t as createReactorKysely } from "./server-ChIFIbah.mjs";
|
|
4
4
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
5
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
-
//# debugId=
|
|
5
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fe48a176-486d-5c9a-ae5a-3789450eb115")}catch(e){}}();
|
|
6
|
+
//# debugId=fe48a176-486d-5c9a-ae5a-3789450eb115
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/switchboard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.3-dev.
|
|
4
|
+
"version": "6.2.3-dev.82",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -88,24 +88,24 @@
|
|
|
88
88
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
89
89
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
90
90
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
91
|
-
"@powerhousedao/config": "6.2.3-dev.
|
|
92
|
-
"@powerhousedao/host-core": "6.2.3-dev.
|
|
93
|
-
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.
|
|
94
|
-
"@powerhousedao/reactor": "6.2.3-dev.
|
|
95
|
-
"@powerhousedao/reactor-api": "6.2.3-dev.
|
|
96
|
-
"@powerhousedao/reactor-attachments": "6.2.3-dev.
|
|
97
|
-
"@powerhousedao/reactor-drive": "6.2.3-dev.
|
|
98
|
-
"@powerhousedao/reactor-group": "6.2.3-dev.
|
|
99
|
-
"@powerhousedao/reactor-privacy": "6.2.3-dev.
|
|
100
|
-
"@powerhousedao/reactor-workflow": "6.2.3-dev.
|
|
101
|
-
"@powerhousedao/shared": "6.2.3-dev.
|
|
102
|
-
"@powerhousedao/vetra": "6.2.3-dev.
|
|
103
|
-
"@powerhousedao/workflow": "6.2.3-dev.
|
|
91
|
+
"@powerhousedao/config": "6.2.3-dev.82",
|
|
92
|
+
"@powerhousedao/host-core": "6.2.3-dev.82",
|
|
93
|
+
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.82",
|
|
94
|
+
"@powerhousedao/reactor": "6.2.3-dev.82",
|
|
95
|
+
"@powerhousedao/reactor-api": "6.2.3-dev.82",
|
|
96
|
+
"@powerhousedao/reactor-attachments": "6.2.3-dev.82",
|
|
97
|
+
"@powerhousedao/reactor-drive": "6.2.3-dev.82",
|
|
98
|
+
"@powerhousedao/reactor-group": "6.2.3-dev.82",
|
|
99
|
+
"@powerhousedao/reactor-privacy": "6.2.3-dev.82",
|
|
100
|
+
"@powerhousedao/reactor-workflow": "6.2.3-dev.82",
|
|
101
|
+
"@powerhousedao/shared": "6.2.3-dev.82",
|
|
102
|
+
"@powerhousedao/vetra": "6.2.3-dev.82",
|
|
103
|
+
"@powerhousedao/workflow": "6.2.3-dev.82",
|
|
104
104
|
"@pyroscope/nodejs": "^0.4.5",
|
|
105
|
-
"@renown/sdk": "6.2.3-dev.
|
|
105
|
+
"@renown/sdk": "6.2.3-dev.82",
|
|
106
106
|
"@sentry/node": "^10.53.1",
|
|
107
107
|
"@sentry/opentelemetry": "^10.53.1",
|
|
108
|
-
"document-model": "6.2.3-dev.
|
|
108
|
+
"document-model": "6.2.3-dev.82",
|
|
109
109
|
"dotenv": "^16.4.7",
|
|
110
110
|
"express": "^4.22.1",
|
|
111
111
|
"graphql": "^16",
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { ILogger } from "document-model";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { startSwitchboard, SwitchboardDeps } from "../src/server.mjs";
|
|
8
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
9
|
+
|
|
10
|
+
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
11
|
+
|
|
12
|
+
const SLUG = "ready-drive";
|
|
13
|
+
|
|
14
|
+
function stubLogger(): ILogger {
|
|
15
|
+
const logger = {
|
|
16
|
+
verbose: vi.fn(),
|
|
17
|
+
debug: vi.fn(),
|
|
18
|
+
info: vi.fn(),
|
|
19
|
+
warn: vi.fn(),
|
|
20
|
+
error: vi.fn(),
|
|
21
|
+
child: vi.fn(),
|
|
22
|
+
};
|
|
23
|
+
logger.child.mockReturnValue(logger);
|
|
24
|
+
return logger as unknown as ILogger;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ENV = ["PH_REACTOR_DATABASE_URL", "FEATURE_PLUGIN_HOST_ENABLED"];
|
|
28
|
+
let previousEnv: (readonly [string, string | undefined])[] = [];
|
|
29
|
+
let tempRoots: string[] = [];
|
|
30
|
+
let running: Promise<Switchboard>[] = [];
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
previousEnv = ENV.map((name) => [name, process.env[name]] as const);
|
|
34
|
+
delete process.env.FEATURE_PLUGIN_HOST_ENABLED;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
for (const booting of running.reverse()) {
|
|
39
|
+
await (await booting).shutdown();
|
|
40
|
+
}
|
|
41
|
+
running = [];
|
|
42
|
+
for (const [name, value] of previousEnv) {
|
|
43
|
+
if (value === undefined) delete process.env[name];
|
|
44
|
+
else process.env[name] = value;
|
|
45
|
+
}
|
|
46
|
+
for (const root of tempRoots) {
|
|
47
|
+
await rm(root, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
tempRoots = [];
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function freePort(): Promise<number> {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const server = createServer();
|
|
55
|
+
server.once("error", reject);
|
|
56
|
+
server.listen(0, () => {
|
|
57
|
+
const address = server.address();
|
|
58
|
+
server.close(() =>
|
|
59
|
+
typeof address === "object" && address
|
|
60
|
+
? resolve(address.port)
|
|
61
|
+
: reject(new Error("no port")),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Starts a boot without awaiting it, so `/ready` can be watched coming up. */
|
|
68
|
+
async function startBoot(deps: SwitchboardDeps = {}) {
|
|
69
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-ready-"));
|
|
70
|
+
tempRoots.push(tempRoot);
|
|
71
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
72
|
+
const port = await freePort();
|
|
73
|
+
const booting = bootSwitchboard(
|
|
74
|
+
{
|
|
75
|
+
server: { port, strictPort: true },
|
|
76
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
77
|
+
features: { workflows: false, mcp: false },
|
|
78
|
+
packages: { disableLocal: true },
|
|
79
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
80
|
+
drive: { slug: SLUG, global: { name: "Ready Drive" } },
|
|
81
|
+
},
|
|
82
|
+
{ logger: stubLogger(), ...deps },
|
|
83
|
+
);
|
|
84
|
+
running.push(booting);
|
|
85
|
+
return { origin: `http://localhost:${port}`, booting };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function readyStatus(origin: string): Promise<number | undefined> {
|
|
89
|
+
try {
|
|
90
|
+
return (await fetch(`${origin}/ready`)).status;
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function untilReady(origin: string, timeoutMs = 60_000) {
|
|
97
|
+
const deadline = Date.now() + timeoutMs;
|
|
98
|
+
while (Date.now() < deadline) {
|
|
99
|
+
if ((await readyStatus(origin)) === 200) return;
|
|
100
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`${origin}/ready never turned 200`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
describe("switchboard readiness", () => {
|
|
106
|
+
it("serves the default drive once /ready is 200", async () => {
|
|
107
|
+
const { origin, booting } = await startBoot();
|
|
108
|
+
|
|
109
|
+
await untilReady(origin);
|
|
110
|
+
const drive = await fetch(`${origin}/d/${SLUG}`);
|
|
111
|
+
|
|
112
|
+
expect(drive.status).toBe(200);
|
|
113
|
+
await booting;
|
|
114
|
+
}, 60_000);
|
|
115
|
+
|
|
116
|
+
it("waits for the drives a caller seeds after start", async () => {
|
|
117
|
+
let seeded!: () => void;
|
|
118
|
+
const readyAfter = new Promise<void>((resolve) => {
|
|
119
|
+
seeded = resolve;
|
|
120
|
+
});
|
|
121
|
+
const { origin, booting } = await startBoot({ readyAfter });
|
|
122
|
+
await booting;
|
|
123
|
+
|
|
124
|
+
// Long past the point an unheld boot turns ready.
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
126
|
+
expect(await readyStatus(origin)).toBe(503);
|
|
127
|
+
|
|
128
|
+
seeded();
|
|
129
|
+
await untilReady(origin, 10_000);
|
|
130
|
+
}, 60_000);
|
|
131
|
+
|
|
132
|
+
it("stays not ready when that seeding fails", async () => {
|
|
133
|
+
const readyAfter = Promise.reject(new Error("seeding failed"));
|
|
134
|
+
readyAfter.catch(() => undefined);
|
|
135
|
+
const { origin, booting } = await startBoot({ readyAfter });
|
|
136
|
+
await booting;
|
|
137
|
+
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
139
|
+
expect(await readyStatus(origin)).toBe(503);
|
|
140
|
+
}, 60_000);
|
|
141
|
+
});
|
|
@@ -3904,13 +3904,18 @@ type ReactorInfo {
|
|
|
3904
3904
|
}
|
|
3905
3905
|
|
|
3906
3906
|
"""
|
|
3907
|
-
Reads only. info and
|
|
3908
|
-
reads are made as the caller through the reactor read
|
|
3909
|
-
one of the host's admins.
|
|
3907
|
+
Reads only. info, documentModels and loadsModelsOnDemand serve every caller;
|
|
3908
|
+
drive and document reads are made as the caller through the reactor read
|
|
3909
|
+
gate; the rest need one of the host's admins.
|
|
3910
3910
|
"""
|
|
3911
3911
|
type ReactorInspection {
|
|
3912
3912
|
info: ReactorInfo!
|
|
3913
3913
|
documentModels: [InspectionDocumentModel!]!
|
|
3914
|
+
"""
|
|
3915
|
+
True when a document model loads the first time a document of its type
|
|
3916
|
+
arrives, so documentModels names only those loaded so far.
|
|
3917
|
+
"""
|
|
3918
|
+
loadsModelsOnDemand: Boolean!
|
|
3914
3919
|
drives(cursor: String, limit: Int): InspectionDrivePage!
|
|
3915
3920
|
"""
|
|
3916
3921
|
Reads every file node's document. Throttled per caller.
|