@powerhousedao/reactor-api 6.2.3-dev.4 → 6.2.3-dev.40

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.
Files changed (40) hide show
  1. package/README.md +7 -2
  2. package/dist/{adapter-gateway-apollo-CxJNBVyD.mjs → adapter-gateway-apollo-B54G_cXT.mjs} +15 -13
  3. package/dist/{adapter-gateway-apollo-CxJNBVyD.mjs.map → adapter-gateway-apollo-B54G_cXT.mjs.map} +1 -1
  4. package/dist/{adapter-gateway-apollo-DowrX6E_.mjs → adapter-gateway-apollo-D2DNlPY0.mjs} +3 -3
  5. package/dist/{adapter-gateway-mercurius-CZVy88Za.mjs → adapter-gateway-mercurius-rbKlwF9m.mjs} +4 -4
  6. package/dist/{adapter-gateway-mercurius-CZVy88Za.mjs.map → adapter-gateway-mercurius-rbKlwF9m.mjs.map} +1 -1
  7. package/dist/{adapter-gateway-stitching-CaZjvRzx.mjs → adapter-gateway-stitching-Dzv10u8D.mjs} +15 -10
  8. package/dist/{adapter-gateway-stitching-CaZjvRzx.mjs.map → adapter-gateway-stitching-Dzv10u8D.mjs.map} +1 -1
  9. package/dist/{adapter-http-express-B39rPhqH.mjs → adapter-http-express-CWqziB1p.mjs} +7 -7
  10. package/dist/adapter-http-express-CWqziB1p.mjs.map +1 -0
  11. package/dist/{adapter-http-fastify-BwXO6rqE.mjs → adapter-http-fastify-CYZQ6FFv.mjs} +10 -9
  12. package/dist/adapter-http-fastify-CYZQ6FFv.mjs.map +1 -0
  13. package/dist/index.d.mts +1248 -593
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +1784 -487
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/{utils-XWVecaNn.mjs → pieces-DRY6haAO.mjs} +177 -9
  18. package/dist/pieces-DRY6haAO.mjs.map +1 -0
  19. package/dist/rolldown-runtime-8H4AJuhK.mjs +16 -0
  20. package/dist/run-node-handler-CQjyjOuN.mjs +52 -0
  21. package/dist/run-node-handler-CQjyjOuN.mjs.map +1 -0
  22. package/dist/src/packages/https-hooks.d.mts +4 -4
  23. package/dist/src/packages/https-hooks.d.mts.map +1 -1
  24. package/dist/src/packages/https-hooks.mjs +2 -2
  25. package/dist/src/packages/https-hooks.mjs.map +1 -1
  26. package/dist/src/packages/vite-loader.d.mts +19 -9
  27. package/dist/src/packages/vite-loader.d.mts.map +1 -1
  28. package/dist/src/packages/vite-loader.mjs +114 -46
  29. package/dist/src/packages/vite-loader.mjs.map +1 -1
  30. package/dist/{types-DcYyNcHJ.d.mts → types-DlTiz6AA.d.mts} +27 -4
  31. package/dist/types-DlTiz6AA.d.mts.map +1 -0
  32. package/dist/{websocket-DncAB9XK.mjs → websocket-_SH5aBcy.mjs} +3 -3
  33. package/dist/{websocket-DncAB9XK.mjs.map → websocket-_SH5aBcy.mjs.map} +1 -1
  34. package/package.json +18 -18
  35. package/dist/adapter-http-express-B39rPhqH.mjs.map +0 -1
  36. package/dist/adapter-http-fastify-BwXO6rqE.mjs.map +0 -1
  37. package/dist/path-normalize-BOQwY9wR.mjs +0 -23
  38. package/dist/path-normalize-BOQwY9wR.mjs.map +0 -1
  39. package/dist/types-DcYyNcHJ.d.mts.map +0 -1
  40. package/dist/utils-XWVecaNn.mjs.map +0 -1
@@ -1,30 +1,40 @@
1
- import { a as ISubscribablePackageLoader, o as ISubscriptionOptions } from "../../types-DcYyNcHJ.mjs";
2
- import { ILogger } from "document-model";
1
+ import { o as ISubscribablePackageLoader, s as ISubscriptionOptions, u as PackagePieceEntry } from "../../types-DlTiz6AA.mjs";
3
2
  import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
3
+ import { ILogger } from "document-model";
4
4
  import { Logger, ViteDevServer } from "vite";
5
5
  import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
6
-
7
6
  //#region src/packages/vite-loader.d.mts
8
- declare function createViteLogger(logger: ILogger, prefix?: string): Logger;
9
- declare class VitePackageLoader implements ISubscribablePackageLoader {
7
+ export declare function createViteLogger(logger: ILogger, prefix?: string): Logger;
8
+ export interface VitePackageLoaderOptions {
9
+ /** Modules, as paths or file URLs, whose dependencies a package the project
10
+ * does not install may resolve from. This loader's own module always is. */
11
+ resolveFrom?: string[];
12
+ }
13
+ export declare class VitePackageLoader implements ISubscribablePackageLoader {
10
14
  #private;
11
15
  private readonly logger;
12
16
  private readonly vite;
17
+ private readonly importers;
13
18
  readonly name = "VitePackageLoader";
14
- static build(vite: ViteDevServer): VitePackageLoader;
15
- constructor(vite: ViteDevServer);
19
+ static build(vite: ViteDevServer, options?: VitePackageLoaderOptions): VitePackageLoader;
20
+ constructor(vite: ViteDevServer, options?: VitePackageLoaderOptions);
16
21
  private getDocumentModelsPath;
17
22
  private getSubgraphsPath;
18
23
  private getProcessorsPath;
24
+ private getPiecesPath;
25
+ private aliasedRoot;
26
+ private pieceRoot;
19
27
  loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
20
28
  loadUpgradeManifests(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
21
29
  loadSubgraphs(identifier: string): Promise<SubgraphClass[]>;
22
30
  loadProcessors(identifier: string): Promise<ProcessorFactoryBuilder | null>;
31
+ loadPieces(identifier: string): Promise<PackagePieceEntry[]>;
23
32
  onDocumentModelsChange(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
24
33
  onSubgraphsChange(identifier: string, handler: (subgraphs: SubgraphClass[]) => void, options?: ISubscriptionOptions): () => void;
25
34
  onProcessorsChange(identifier: string, handler: (processors: ProcessorFactoryBuilder | null) => void, options?: ISubscriptionOptions): () => void;
35
+ onPiecesChange(identifier: string, handler: (pieces: PackagePieceEntry[]) => void, options?: ISubscriptionOptions): () => void;
26
36
  }
27
- declare function startViteServer(root: string, logger?: Logger): Promise<ViteDevServer>;
37
+ export declare function startViteServer(root: string, logger?: Logger): Promise<ViteDevServer>;
28
38
  //#endregion
29
- export { VitePackageLoader, createViteLogger, startViteServer };
39
+ export {};
30
40
  //# sourceMappingURL=vite-loader.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;;iBAqBgB,gBAAA,CAAiB,MAAA,EAAQ,OAAA,EAAS,MAAA,YAAW,MAAA;AAAA,cA2BhD,iBAAA,YAA6B,0BAAA;EAAA;mBACvB,MAAA;EAAA,iBAEA,IAAA;EAAA,SAER,IAAA;EAAA,OAEF,KAAA,CAAM,IAAA,EAAM,aAAA,GAAa,iBAAA;cAIpB,IAAA,EAAM,aAAA;EAAA,QAIV,qBAAA;EAAA,QAIA,gBAAA;EAAA,QAIA,iBAAA;EAID,kBAAA,CAAmB,UAAA,UAAoB,SAAA,aAAiB,OAAA,CAAA,mBAAA;EA2CzD,oBAAA,CACJ,UAAA,WACC,OAAA,CAAQ,eAAA;EA+BL,aAAA,CAAc,UAAA,WAAqB,OAAA,CAAQ,aAAA;EA4B3C,cAAA,CACJ,UAAA,WACC,OAAA,CAAQ,uBAAA;EA+BX,sBAAA,CACE,UAAA,UACA,OAAA,GAAU,cAAA,EAAgB,mBAAA,aAC1B,OAAA,GAAU,oBAAA;EAwBZ,iBAAA,CACE,UAAA,UACA,OAAA,GAAU,SAAA,EAAW,aAAA,aACrB,OAAA,GAAU,oBAAA;EAuBZ,kBAAA,CACE,UAAA,UACA,OAAA,GAAU,UAAA,EAAY,uBAAA,kBACtB,OAAA,GAAU,oBAAA;AAAA;AAAA,iBAwBQ,eAAA,CAAgB,IAAA,UAAc,MAAA,GAAS,MAAA,GAAM,OAAA,CAAA,aAAA"}
1
+ {"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;wBA8BgB,iBAAiB,QAAQ,SAAS,kBAAW;iBA2B5C;;;EAGf;;qBAQW,6BAA6B;;mBACvB;mBAEA;mBAEA;WAER;SAEF,MAAM,MAAM,eAAe,UAAU,2BAAwB;EAIpE,YAAY,MAAM,eAAe,UAAS;UAyDlC;UAIA;UAIA;UAIA;UAMA;UASA;EAcD,mBAAmB,oBAAoB,sBAAiB,QAAA;EA8BzD,qBACJ,qBACC,QAAQ;EAoBL,cAAc,qBAAqB,QAAQ;EAyB3C,eACJ,qBACC,QAAQ;EAkBL,WAAW,qBAAqB,QAAQ;EAsB9C,uBACE,oBACA,UAAU,gBAAgB,gCAC1B,UAAU;EAwBZ,kBACE,oBACA,UAAU,WAAW,0BACrB,UAAU;EAuBZ,mBACE,oBACA,UAAU,YAAY,yCACtB,UAAU;EAuBZ,eACE,oBACA,UAAU,QAAQ,8BAClB,UAAU;;wBA2BQ,gBAAgB,cAAc,SAAS,SAAM,QAAA"}
@@ -1,8 +1,9 @@
1
1
 
2
- !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]="9da64ff1-d15d-5b85-94b1-f1b0dad67551")}catch(e){}}();
3
- import { a as isSubgraphClass, c as isSubpath, o as debounce, s as extractUpgradeManifests } from "../../utils-XWVecaNn.mjs";
2
+ !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]="33a7684d-ff05-56ac-b4f5-910a2adca3e5")}catch(e){}}();
3
+ import { a as pieceListLocation, f as isSubgraphClass, h as isSubpath, i as packageRootOf, m as extractUpgradeManifests, n as PIECES_SUBPATH, p as debounce, s as piecesFromListModule, t as BUILT_PIECE_LIST } from "../../pieces-DRY6haAO.mjs";
4
4
  import { childLogger } from "document-model";
5
5
  import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
6
7
  import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
7
8
  import { readPackage } from "read-pkg";
8
9
  import { createLogger, createServer } from "vite";
@@ -17,12 +18,42 @@ function createViteLogger(logger, prefix = "") {
17
18
  var VitePackageLoader = class VitePackageLoader {
18
19
  logger = childLogger(["reactor-api", "vite-loader"]);
19
20
  vite;
21
+ importers;
20
22
  name = "VitePackageLoader";
21
- static build(vite) {
22
- return new VitePackageLoader(vite);
23
+ static build(vite, options) {
24
+ return new VitePackageLoader(vite, options);
23
25
  }
24
- constructor(vite) {
26
+ constructor(vite, options = {}) {
25
27
  this.vite = vite;
28
+ this.importers = [...options.resolveFrom ?? [], import.meta.url].map((from) => from.startsWith("file:") ? fileURLToPath(from) : from);
29
+ }
30
+ async #resolve(identifier, subpath) {
31
+ const aliased = path.isAbsolute(identifier) ? void 0 : this.aliasedRoot(identifier);
32
+ const specifier = path.posix.join(aliased ?? identifier, subpath);
33
+ const importers = !aliased && !path.isAbsolute(identifier) ? [void 0, ...this.importers] : [void 0];
34
+ const container = this.vite.environments.ssr.pluginContainer;
35
+ for (const importer of importers) try {
36
+ const resolved = await container.resolveId(specifier, importer);
37
+ if (resolved && !resolved.external) return resolved.id;
38
+ } catch (e) {
39
+ this.logger.debug("Could not resolve @specifier: @error", specifier, e);
40
+ }
41
+ }
42
+ async #load(identifier, subpath) {
43
+ const id = await this.#resolve(identifier, subpath);
44
+ if (id === void 0) {
45
+ this.logger.debug("No @subpath module in @pkg", subpath, identifier);
46
+ return;
47
+ }
48
+ try {
49
+ return {
50
+ id,
51
+ namespace: await this.vite.ssrLoadModule(id)
52
+ };
53
+ } catch (e) {
54
+ this.logger.error("Failed to load @subpath of @pkg from @id: @error", subpath, identifier, id, e instanceof Error ? e.message : e);
55
+ return;
56
+ }
26
57
  }
27
58
  getDocumentModelsPath(identifier) {
28
59
  return path.posix.join(identifier, "./document-models");
@@ -33,50 +64,56 @@ var VitePackageLoader = class VitePackageLoader {
33
64
  getProcessorsPath(identifier) {
34
65
  return path.posix.join(identifier, "./processors");
35
66
  }
67
+ getPiecesPath(identifier) {
68
+ return path.posix.join(identifier, `./${PIECES_SUBPATH}`);
69
+ }
70
+ aliasedRoot(identifier) {
71
+ const alias = this.vite.config.resolve.alias;
72
+ const hit = (Array.isArray(alias) ? alias : []).find((entry) => entry.find === identifier);
73
+ return typeof hit?.replacement === "string" ? hit.replacement : void 0;
74
+ }
75
+ pieceRoot(identifier, listId) {
76
+ if (!path.isAbsolute(identifier)) {
77
+ const aliased = this.aliasedRoot(identifier);
78
+ if (aliased) return aliased;
79
+ if (listId) return packageRootOf(path.dirname(listId));
80
+ }
81
+ try {
82
+ return pieceListLocation(identifier).root;
83
+ } catch {
84
+ return;
85
+ }
86
+ }
36
87
  loadDocumentModels(identifier, immediate = false) {
37
88
  return this.#loadDocumentModelsWithDebounce(immediate, identifier);
38
89
  }
39
90
  #loadDocumentModelsWithDebounce = debounce(this.#loadDocumentModels.bind(this), 500);
40
91
  async #loadDocumentModels(identifier) {
41
- const fullPath = this.getDocumentModelsPath(identifier);
42
- this.logger.debug("Loading document models from", fullPath);
43
- try {
44
- const localDMs = await this.vite.ssrLoadModule(fullPath);
45
- const exports = Object.values(localDMs);
46
- const documentModels = [];
47
- for (const dm of exports) if (dm.documentModel) documentModels.push(dm);
48
- this.logger.verbose(` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`);
49
- return documentModels;
50
- } catch (e) {
51
- this.logger.debug(` ➜ No Document Models found for: ${identifier}`, e);
52
- }
53
- return [];
92
+ this.logger.debug("Loading document models from", this.getDocumentModelsPath(identifier));
93
+ const loaded = await this.#load(identifier, "document-models");
94
+ if (!loaded) return [];
95
+ const documentModels = Object.values(loaded.namespace).filter((dm) => dm !== null && typeof dm === "object" && "documentModel" in dm);
96
+ this.logger.verbose(` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`);
97
+ return documentModels;
54
98
  }
55
99
  async loadUpgradeManifests(identifier) {
56
- const candidatePaths = [this.getDocumentModelsPath(identifier), path.posix.join(this.getDocumentModelsPath(identifier), "upgrade-manifests")];
57
- for (const fullPath of candidatePaths) try {
58
- const manifests = extractUpgradeManifests(await this.vite.ssrLoadModule(fullPath));
100
+ for (const subpath of ["document-models", "document-models/upgrade-manifests"]) {
101
+ const loaded = await this.#load(identifier, subpath);
102
+ if (!loaded) continue;
103
+ const manifests = extractUpgradeManifests(loaded.namespace);
59
104
  if (manifests.length > 0) {
60
105
  this.logger.verbose(` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`);
61
106
  return manifests;
62
107
  }
63
- } catch (e) {
64
- this.logger.debug(` ➜ No Upgrade Manifests found at ${fullPath} for: ${identifier}`, e);
65
108
  }
66
109
  return [];
67
110
  }
68
111
  async loadSubgraphs(identifier) {
69
- const fullPath = this.getSubgraphsPath(identifier);
70
- this.logger.verbose("Loading subgraphs from", fullPath);
71
- let localSubgraphs = {};
72
- try {
73
- localSubgraphs = await this.vite.ssrLoadModule(fullPath);
74
- } catch (e) {
75
- this.logger.debug(` ➜ No Subgraphs found for: ${identifier}`, e);
76
- return [];
77
- }
112
+ this.logger.verbose("Loading subgraphs from", this.getSubgraphsPath(identifier));
113
+ const loaded = await this.#load(identifier, "subgraphs");
114
+ if (!loaded) return [];
78
115
  const subgraphs = [];
79
- for (const [name, subgraph] of Object.entries(localSubgraphs)) {
116
+ for (const [name, subgraph] of Object.entries(loaded.namespace)) {
80
117
  const SubgraphClass = subgraph[name];
81
118
  if (isSubgraphClass(SubgraphClass)) subgraphs.push(SubgraphClass);
82
119
  }
@@ -84,23 +121,36 @@ var VitePackageLoader = class VitePackageLoader {
84
121
  return subgraphs;
85
122
  }
86
123
  async loadProcessors(identifier) {
87
- const fullPath = this.getProcessorsPath(identifier);
88
- this.logger.verbose("Loading processors from", fullPath);
89
- try {
90
- const factory = (await this.vite.ssrLoadModule(fullPath))?.processorFactory;
91
- if (factory && typeof factory === "function") {
92
- this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);
93
- return factory;
94
- }
95
- } catch (e) {
96
- this.logger.debug(` ➜ No Processor Factory found for: ${identifier}`, e);
124
+ this.logger.verbose("Loading processors from", this.getProcessorsPath(identifier));
125
+ const factory = (await this.#load(identifier, "processors"))?.namespace.processorFactory;
126
+ if (typeof factory === "function") {
127
+ this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);
128
+ return factory;
97
129
  }
98
130
  this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);
99
131
  return null;
100
132
  }
133
+ async loadPieces(identifier) {
134
+ this.logger.verbose("Loading pieces from", this.getPiecesPath(identifier));
135
+ const loaded = await this.#load(identifier, PIECES_SUBPATH);
136
+ if (!loaded) return [];
137
+ const root = this.pieceRoot(identifier, loaded.id);
138
+ if (root === void 0) {
139
+ this.logger.debug(` ➜ No package root found for: ${identifier}`);
140
+ return [];
141
+ }
142
+ const pieces = piecesFromListModule(loaded.namespace, {
143
+ root,
144
+ identifier,
145
+ logger: this.logger
146
+ });
147
+ this.logger.debug(` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`);
148
+ return pieces;
149
+ }
101
150
  onDocumentModelsChange(identifier, handler, options) {
102
151
  const listener = async (changedPath) => {
103
- if (isSubpath(this.getDocumentModelsPath(identifier), changedPath)) handler(await this.loadDocumentModels(identifier));
152
+ const documentModelsPath = this.getDocumentModelsPath(identifier);
153
+ if (isSubpath(documentModelsPath, changedPath)) handler(await this.loadDocumentModels(identifier));
104
154
  };
105
155
  this.vite.watcher.on("change", listener);
106
156
  this.vite.watcher.on("add", listener);
@@ -139,8 +189,26 @@ var VitePackageLoader = class VitePackageLoader {
139
189
  this.vite.watcher.off("unlink", listener);
140
190
  };
141
191
  }
192
+ onPiecesChange(identifier, handler, options) {
193
+ const watched = [this.getPiecesPath(identifier)];
194
+ const root = this.pieceRoot(identifier);
195
+ if (root !== void 0) watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));
196
+ const listener = async (changedPath) => {
197
+ if (!watched.some((dir) => isSubpath(dir, changedPath))) return;
198
+ handler(await this.loadPieces(identifier));
199
+ };
200
+ this.vite.watcher.on("change", listener);
201
+ this.vite.watcher.on("add", listener);
202
+ this.vite.watcher.on("unlink", listener);
203
+ return () => {
204
+ this.vite.watcher.off("change", listener);
205
+ this.vite.watcher.off("add", listener);
206
+ this.vite.watcher.off("unlink", listener);
207
+ };
208
+ }
142
209
  };
143
210
  async function startViteServer(root, logger) {
211
+ const packageJson = await readPackage({ cwd: root });
144
212
  return await createServer({
145
213
  root,
146
214
  configFile: false,
@@ -153,7 +221,7 @@ async function startViteServer(root, logger) {
153
221
  build: { rollupOptions: { input: [] } },
154
222
  resolve: {
155
223
  tsconfigPaths: true,
156
- alias: { [(await readPackage({ cwd: root })).name]: root }
224
+ alias: { [packageJson.name]: root }
157
225
  },
158
226
  plugins: [viteCommonjs(), {
159
227
  name: "suppress-hmr",
@@ -167,4 +235,4 @@ async function startViteServer(root, logger) {
167
235
  export { VitePackageLoader, createViteLogger, startViteServer };
168
236
 
169
237
  //# sourceMappingURL=vite-loader.mjs.map
170
- //# debugId=9da64ff1-d15d-5b85-94b1-f1b0dad67551
238
+ //# debugId=33a7684d-ff05-56ac-b4f5-910a2adca3e5
@@ -1 +1 @@
1
- {"version":3,"file":"vite-loader.mjs","sources":["../../../src/packages/vite-loader.mts"],"sourcesContent":["import { viteCommonjs } from \"@originjs/vite-plugin-commonjs\";\nimport type {\n ProcessorFactoryBuilder,\n SubgraphClass,\n} from \"@powerhousedao/reactor-api\";\nimport type {\n DocumentModelModule,\n UpgradeManifest,\n} from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport { readPackage } from \"read-pkg\";\nimport type { Logger, PluginOption, ViteDevServer } from \"vite\";\nimport { createLogger, createServer } from \"vite\";\nimport { isSubgraphClass } from \"../graphql/utils.js\";\nimport type {\n ISubscribablePackageLoader,\n ISubscriptionOptions,\n} from \"./types.js\";\nimport { debounce, extractUpgradeManifests, isSubpath } from \"./util.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n // Wrapped rather than assigned: the logger methods are bound to their own\n // instance, and re-homing them onto Vite's logger object made every Vite\n // log line throw.\n //\n // Vite's text goes through as a replacement, never as the format string: it\n // is somebody else's prose, not a template. `ILogger` substitutes `@token`,\n // and Vite log lines are full of npm scopes, so `pre-transforming\n // @powerhousedao/design-system` came out as `pre-transforming\n // null/design-system`. Substituting into `@line` instead emits it verbatim.\n //\n // Vite's second argument is dropped for the same reason. It is `LogOptions`\n // -- `{ clear, timestamp }` -- and forwarding it made it the replacement for\n // whatever `@token` the line happened to contain, or got appended as JSON.\n // Only `error` keeps it, where it carries the error itself.\n customLogger.info = (msg) => logger.info(\"@line\", msg);\n customLogger.warn = (msg) => logger.warn(\"@line\", msg);\n customLogger.error = (msg, options) =>\n options?.error\n ? logger.error(\"@line\", msg, options.error)\n : logger.error(\"@line\", msg);\n return customLogger;\n}\n\nexport class VitePackageLoader implements ISubscribablePackageLoader {\n private readonly logger = childLogger([\"reactor-api\", \"vite-loader\"]);\n\n private readonly vite: ViteDevServer;\n\n readonly name = \"VitePackageLoader\";\n\n static build(vite: ViteDevServer) {\n return new VitePackageLoader(vite);\n }\n\n constructor(vite: ViteDevServer) {\n this.vite = vite;\n }\n\n private getDocumentModelsPath(identifier: string): string {\n return path.posix.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.posix.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.posix.join(identifier, \"./processors\");\n }\n\n public loadDocumentModels(identifier: string, immediate = false) {\n return this.#loadDocumentModelsWithDebounce(immediate, identifier);\n }\n\n #loadDocumentModelsWithDebounce = debounce(\n this.#loadDocumentModels.bind(this),\n 500,\n );\n\n async #loadDocumentModels(\n identifier: string,\n ): Promise<DocumentModelModule[]> {\n const fullPath = this.getDocumentModelsPath(identifier);\n this.logger.debug(\"Loading document models from\", fullPath);\n\n try {\n const localDMs = (await this.vite.ssrLoadModule(fullPath)) as Record<\n string,\n DocumentModelModule\n >;\n\n const exports = Object.values(localDMs);\n\n // duck type\n const documentModels: DocumentModelModule[] = [];\n for (const dm of exports) {\n if (dm.documentModel) {\n documentModels.push(dm);\n }\n }\n\n this.logger.verbose(\n ` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`,\n );\n\n return documentModels;\n } catch (e) {\n this.logger.debug(` ➜ No Document Models found for: ${identifier}`, e);\n }\n\n return [];\n }\n\n async loadUpgradeManifests(\n identifier: string,\n ): Promise<UpgradeManifest<readonly number[]>[]> {\n // Projects generated before the aggregate index re-exported the\n // manifests only expose them at document-models/upgrade-manifests, so\n // try both without requiring a regeneration.\n const candidatePaths = [\n this.getDocumentModelsPath(identifier),\n path.posix.join(this.getDocumentModelsPath(identifier), \"upgrade-manifests\"),\n ];\n for (const fullPath of candidatePaths) {\n try {\n const namespace = (await this.vite.ssrLoadModule(fullPath)) as Record<\n string,\n unknown\n >;\n const manifests = extractUpgradeManifests(namespace);\n if (manifests.length > 0) {\n this.logger.verbose(\n ` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`,\n );\n return manifests;\n }\n } catch (e) {\n this.logger.debug(\n ` ➜ No Upgrade Manifests found at ${fullPath} for: ${identifier}`,\n e,\n );\n }\n }\n return [];\n }\n\n async loadSubgraphs(identifier: string): Promise<SubgraphClass[]> {\n const fullPath = this.getSubgraphsPath(identifier);\n\n this.logger.verbose(\"Loading subgraphs from\", fullPath);\n\n let localSubgraphs: Record<string, Record<string, SubgraphClass>> = {};\n try {\n localSubgraphs = await this.vite.ssrLoadModule(fullPath);\n } catch (e) {\n this.logger.debug(` ➜ No Subgraphs found for: ${identifier}`, e);\n return [];\n }\n\n const subgraphs: SubgraphClass[] = [];\n for (const [name, subgraph] of Object.entries(localSubgraphs)) {\n const SubgraphClass = subgraph[name];\n if (isSubgraphClass(SubgraphClass)) {\n subgraphs.push(SubgraphClass);\n }\n }\n\n this.logger.debug(\n ` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`,\n );\n\n return subgraphs;\n }\n\n async loadProcessors(\n identifier: string,\n ): Promise<ProcessorFactoryBuilder | null> {\n const fullPath = this.getProcessorsPath(identifier);\n\n this.logger.verbose(\"Loading processors from\", fullPath);\n\n try {\n const pkgModule = await this.vite.ssrLoadModule(fullPath);\n\n const factory = (\n pkgModule as Record<string, ProcessorFactoryBuilder | undefined>\n )?.processorFactory;\n\n if (factory && typeof factory === \"function\") {\n this.logger.verbose(\n ` ➜ Loaded Processor Factory from: ${identifier}`,\n );\n return factory;\n }\n } catch (e) {\n this.logger.debug(\n ` ➜ No Processor Factory found for: ${identifier}`,\n e,\n );\n }\n\n this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);\n\n // return empty processor factory\n return null;\n }\n\n onDocumentModelsChange(\n identifier: string,\n handler: (documentModels: DocumentModelModule[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const listener = async (changedPath: string) => {\n const documentModelsPath = this.getDocumentModelsPath(identifier);\n if (isSubpath(documentModelsPath, changedPath)) {\n const documentModels = await this.loadDocumentModels(identifier);\n handler(documentModels);\n }\n };\n\n // \"change\" alone misses files that are created or deleted: a removed\n // document-models/ entry would never report an empty result, and the\n // package's registered models would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onSubgraphsChange(\n identifier: string,\n handler: (subgraphs: SubgraphClass[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const subgraphsPath = this.getSubgraphsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(subgraphsPath, changedPath)) {\n const subgraphs = await this.loadSubgraphs(identifier);\n handler(subgraphs);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // subgraphs/ entry would never report an empty result, and the\n // package's registered subgraphs would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onProcessorsChange(\n identifier: string,\n handler: (processors: ProcessorFactoryBuilder | null) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const processorsPath = this.getProcessorsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(processorsPath, changedPath)) {\n const processors = await this.loadProcessors(identifier);\n handler(processors);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // processors/ entry would never report an empty result, and the\n // package's registered processor factories would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n}\n\nexport async function startViteServer(root: string, logger?: Logger) {\n const packageJson = await readPackage({ cwd: root });\n\n const vite = await createServer({\n root,\n configFile: false,\n logger,\n server: { middlewareMode: true, watch: { ignored: [\"**/.ph/**\"] } },\n appType: \"custom\",\n build: {\n rollupOptions: {\n input: [],\n },\n },\n resolve: {\n tsconfigPaths: true,\n alias: {\n [packageJson.name]: root,\n },\n },\n plugins: [\n // cast: the plugin ships types built against an older vite, and the\n // mismatched Plugin type crashes tsc 6 during assignability checking\n viteCommonjs() as PluginOption,\n {\n name: \"suppress-hmr\",\n handleHotUpdate() {\n return []; // return empty array to suppress server refresh\n },\n },\n ],\n });\n\n return vite;\n}\n"],"names":["#loadDocumentModelsWithDebounce","#loadDocumentModels"],"mappings":";;;;;;;;;AAqBA,SAAgB,iBAAiB,QAAiB,SAAS,IAAI;CAC7D,MAAM,eAAe,aAAa,QAAQ,EACxC,QACD,CAAC;AAeF,cAAa,QAAQ,Q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AS;AACzC,QAAK,KAAK,QAAQ,IAAI,OAAO,SAAS;AACtC,QAAK,KAAK,QAAQ,IAAI,UAAU,SAAS;;;;AAK/C,eAAsB,gBAAgB,MAAc,QAAiB;AAiCnE,QA9Ba,MAAM,aAAa;EAC9B;EACA,YAAY;EACZ;EACA,QAAQ;GAAE,gBAAgB;GAAM,OAAO,EAAE,SAAS,CAAC,YAAY,EAAE;GAAE;EACnE,SAAS;EACT,OAAO,EACL,eAAe,EACb,OAAO,EAAE,EACV,EACF;EACD,SAAS;GACP,eAAe;GACf,OAAO,IAfS,MAAM,YAAY,EAAE,KAAK,MAAM,CAAC,EAgBjC,OAAO,MACrB;GACF;EACD,SAAS,CAGP,cAAc,EACd;GACE,MAAM;GACN,kBAAkB;AAChB,WAAO,EAAE;;GAEZ,CACF;EACF,CAAC","debug_id":"9da64ff1-d15d-5b85-94b1-f1b0dad67551"}
1
+ {"version":3,"file":"vite-loader.mjs","sources":["../../../src/packages/vite-loader.mts"],"sourcesContent":["import { viteCommonjs } from \"@originjs/vite-plugin-commonjs\";\nimport type {\n ProcessorFactoryBuilder,\n SubgraphClass,\n} from \"@powerhousedao/reactor-api\";\nimport type {\n DocumentModelModule,\n UpgradeManifest,\n} from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readPackage } from \"read-pkg\";\nimport type { Logger, PluginOption, ViteDevServer } from \"vite\";\nimport { createLogger, createServer } from \"vite\";\nimport { isSubgraphClass } from \"../graphql/utils.js\";\nimport {\n BUILT_PIECE_LIST,\n PIECES_SUBPATH,\n packageRootOf,\n pieceListLocation,\n piecesFromListModule,\n} from \"./pieces.js\";\nimport type {\n ISubscribablePackageLoader,\n ISubscriptionOptions,\n PackagePieceEntry,\n} from \"./types.js\";\nimport { debounce, extractUpgradeManifests, isSubpath } from \"./util.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n // Wrapped rather than assigned: the logger methods are bound to their own\n // instance, and re-homing them onto Vite's logger object made every Vite\n // log line throw.\n //\n // Vite's text goes through as a replacement, never as the format string: it\n // is somebody else's prose, not a template. `ILogger` substitutes `@token`,\n // and Vite log lines are full of npm scopes, so `pre-transforming\n // @powerhousedao/design-system` came out as `pre-transforming\n // null/design-system`. Substituting into `@line` instead emits it verbatim.\n //\n // Vite's second argument is dropped for the same reason. It is `LogOptions`\n // -- `{ clear, timestamp }` -- and forwarding it made it the replacement for\n // whatever `@token` the line happened to contain, or got appended as JSON.\n // Only `error` keeps it, where it carries the error itself.\n customLogger.info = (msg) => logger.info(\"@line\", msg);\n customLogger.warn = (msg) => logger.warn(\"@line\", msg);\n customLogger.error = (msg, options) =>\n options?.error\n ? logger.error(\"@line\", msg, options.error)\n : logger.error(\"@line\", msg);\n return customLogger;\n}\n\nexport interface VitePackageLoaderOptions {\n /** Modules, as paths or file URLs, whose dependencies a package the project\n * does not install may resolve from. This loader's own module always is. */\n resolveFrom?: string[];\n}\n\ninterface LoadedModule {\n id: string;\n namespace: Record<string, unknown>;\n}\n\nexport class VitePackageLoader implements ISubscribablePackageLoader {\n private readonly logger = childLogger([\"reactor-api\", \"vite-loader\"]);\n\n private readonly vite: ViteDevServer;\n\n private readonly importers: string[];\n\n readonly name = \"VitePackageLoader\";\n\n static build(vite: ViteDevServer, options?: VitePackageLoaderOptions) {\n return new VitePackageLoader(vite, options);\n }\n\n constructor(vite: ViteDevServer, options: VitePackageLoaderOptions = {}) {\n this.vite = vite;\n this.importers = [...(options.resolveFrom ?? []), import.meta.url].map(\n (from) => (from.startsWith(\"file:\") ? fileURLToPath(from) : from),\n );\n }\n\n // The project first, then the host's own dependencies. A bare name or a path\n // Vite cannot resolve is a package without that module, not an error.\n async #resolve(identifier: string, subpath: string) {\n const aliased = path.isAbsolute(identifier)\n ? undefined\n : this.aliasedRoot(identifier);\n const specifier = path.posix.join(aliased ?? identifier, subpath);\n const bare = !aliased && !path.isAbsolute(identifier);\n const importers = bare ? [undefined, ...this.importers] : [undefined];\n const container = this.vite.environments.ssr.pluginContainer;\n for (const importer of importers) {\n try {\n const resolved = await container.resolveId(specifier, importer);\n if (resolved && !resolved.external) return resolved.id;\n } catch (e) {\n this.logger.debug(\"Could not resolve @specifier: @error\", specifier, e);\n }\n }\n return undefined;\n }\n\n // Resolved before it is loaded, so only a module that exists and fails is\n // reported; one a package does not have is a debug-level miss.\n async #load(\n identifier: string,\n subpath: string,\n ): Promise<LoadedModule | undefined> {\n const id = await this.#resolve(identifier, subpath);\n if (id === undefined) {\n this.logger.debug(\"No @subpath module in @pkg\", subpath, identifier);\n return undefined;\n }\n try {\n const namespace = (await this.vite.ssrLoadModule(id)) as Record<\n string,\n unknown\n >;\n return { id, namespace };\n } catch (e) {\n this.logger.error(\n \"Failed to load @subpath of @pkg from @id: @error\",\n subpath,\n identifier,\n id,\n e instanceof Error ? e.message : e,\n );\n return undefined;\n }\n }\n\n private getDocumentModelsPath(identifier: string): string {\n return path.posix.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.posix.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.posix.join(identifier, \"./processors\");\n }\n\n private getPiecesPath(identifier: string): string {\n return path.posix.join(identifier, `./${PIECES_SUBPATH}`);\n }\n\n // The dev server aliases the local project by its own package name, so a\n // package that is this project is rooted at the source tree vite serves.\n private aliasedRoot(identifier: string): string | undefined {\n const alias = this.vite.config.resolve.alias;\n const entries = Array.isArray(alias) ? alias : [];\n const hit = entries.find((entry) => entry.find === identifier);\n return typeof hit?.replacement === \"string\" ? hit.replacement : undefined;\n }\n\n // What a declared piece path is relative to. Not the module vite loaded: a\n // list read from source still points at the built output beside it.\n private pieceRoot(identifier: string, listId?: string): string | undefined {\n if (!path.isAbsolute(identifier)) {\n const aliased = this.aliasedRoot(identifier);\n if (aliased) return aliased;\n // A built list resolved from wherever the package is installed.\n if (listId) return packageRootOf(path.dirname(listId));\n }\n try {\n return pieceListLocation(identifier).root;\n } catch {\n return undefined;\n }\n }\n\n public loadDocumentModels(identifier: string, immediate = false) {\n return this.#loadDocumentModelsWithDebounce(immediate, identifier);\n }\n\n #loadDocumentModelsWithDebounce = debounce(\n this.#loadDocumentModels.bind(this),\n 500,\n );\n\n async #loadDocumentModels(\n identifier: string,\n ): Promise<DocumentModelModule[]> {\n this.logger.debug(\n \"Loading document models from\",\n this.getDocumentModelsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"document-models\");\n if (!loaded) return [];\n\n // duck type\n const documentModels = Object.values(loaded.namespace).filter(\n (dm): dm is DocumentModelModule =>\n dm !== null && typeof dm === \"object\" && \"documentModel\" in dm,\n );\n this.logger.verbose(\n ` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`,\n );\n return documentModels;\n }\n\n async loadUpgradeManifests(\n identifier: string,\n ): Promise<UpgradeManifest<readonly number[]>[]> {\n // Projects generated before the aggregate index re-exported the\n // manifests only expose them at document-models/upgrade-manifests.\n for (const subpath of [\n \"document-models\",\n \"document-models/upgrade-manifests\",\n ]) {\n const loaded = await this.#load(identifier, subpath);\n if (!loaded) continue;\n const manifests = extractUpgradeManifests(loaded.namespace);\n if (manifests.length > 0) {\n this.logger.verbose(\n ` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`,\n );\n return manifests;\n }\n }\n return [];\n }\n\n async loadSubgraphs(identifier: string): Promise<SubgraphClass[]> {\n this.logger.verbose(\n \"Loading subgraphs from\",\n this.getSubgraphsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"subgraphs\");\n if (!loaded) return [];\n\n const subgraphs: SubgraphClass[] = [];\n for (const [name, subgraph] of Object.entries(\n loaded.namespace as Record<string, Record<string, SubgraphClass>>,\n )) {\n const SubgraphClass = subgraph[name];\n if (isSubgraphClass(SubgraphClass)) {\n subgraphs.push(SubgraphClass);\n }\n }\n\n this.logger.debug(\n ` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`,\n );\n\n return subgraphs;\n }\n\n async loadProcessors(\n identifier: string,\n ): Promise<ProcessorFactoryBuilder | null> {\n this.logger.verbose(\n \"Loading processors from\",\n this.getProcessorsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"processors\");\n const factory = loaded?.namespace.processorFactory;\n if (typeof factory === \"function\") {\n this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);\n return factory as ProcessorFactoryBuilder;\n }\n\n this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);\n return null;\n }\n\n // The list only, never a piece: in dev it is usually the TypeScript source,\n // and what it names is still the built bundle a worker will load.\n async loadPieces(identifier: string): Promise<PackagePieceEntry[]> {\n this.logger.verbose(\"Loading pieces from\", this.getPiecesPath(identifier));\n const loaded = await this.#load(identifier, PIECES_SUBPATH);\n if (!loaded) return [];\n\n const root = this.pieceRoot(identifier, loaded.id);\n if (root === undefined) {\n this.logger.debug(` ➜ No package root found for: ${identifier}`);\n return [];\n }\n\n const pieces = piecesFromListModule(loaded.namespace, {\n root,\n identifier,\n logger: this.logger,\n });\n this.logger.debug(\n ` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`,\n );\n return pieces;\n }\n\n onDocumentModelsChange(\n identifier: string,\n handler: (documentModels: DocumentModelModule[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const listener = async (changedPath: string) => {\n const documentModelsPath = this.getDocumentModelsPath(identifier);\n if (isSubpath(documentModelsPath, changedPath)) {\n const documentModels = await this.loadDocumentModels(identifier);\n handler(documentModels);\n }\n };\n\n // \"change\" alone misses files that are created or deleted: a removed\n // document-models/ entry would never report an empty result, and the\n // package's registered models would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onSubgraphsChange(\n identifier: string,\n handler: (subgraphs: SubgraphClass[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const subgraphsPath = this.getSubgraphsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(subgraphsPath, changedPath)) {\n const subgraphs = await this.loadSubgraphs(identifier);\n handler(subgraphs);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // subgraphs/ entry would never report an empty result, and the\n // package's registered subgraphs would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onProcessorsChange(\n identifier: string,\n handler: (processors: ProcessorFactoryBuilder | null) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const processorsPath = this.getProcessorsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(processorsPath, changedPath)) {\n const processors = await this.loadProcessors(identifier);\n handler(processors);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // processors/ entry would never report an empty result, and the\n // package's registered processor factories would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onPiecesChange(\n identifier: string,\n handler: (pieces: PackagePieceEntry[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n // Both the source list and the build output: the list says which pieces a\n // package ships, and only the build decides whether one is there to run.\n const watched = [this.getPiecesPath(identifier)];\n const root = this.pieceRoot(identifier);\n if (root !== undefined) {\n watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));\n }\n const listener = async (changedPath: string) => {\n if (!watched.some((dir) => isSubpath(dir, changedPath))) return;\n handler(await this.loadPieces(identifier));\n };\n // \"change\" alone misses files that are created or deleted, and a piece\n // appearing for the first time is exactly the build this watches for.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n}\n\nexport async function startViteServer(root: string, logger?: Logger) {\n const packageJson = await readPackage({ cwd: root });\n\n const vite = await createServer({\n root,\n configFile: false,\n logger,\n server: { middlewareMode: true, watch: { ignored: [\"**/.ph/**\"] } },\n appType: \"custom\",\n build: {\n rollupOptions: {\n input: [],\n },\n },\n resolve: {\n tsconfigPaths: true,\n alias: {\n [packageJson.name]: root,\n },\n },\n plugins: [\n // cast: the plugin ships types built against an older vite, and the\n // mismatched Plugin type crashes tsc 6 during assignability checking\n viteCommonjs() as PluginOption,\n {\n name: \"suppress-hmr\",\n handleHotUpdate() {\n return []; // return empty array to suppress server refresh\n },\n },\n ],\n });\n\n return vite;\n}\n"],"names":[],"mappings":";;;;;;;;;;AA8BA,SAAgB,iBAAiB,QAAiB,SAAS,IAAI;CAC7D,MAAM,eAAe,aAAa,QAAQ,EACxC,OACF,CAAC;CAeD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,SAAS,KAAK,YACzB,SAAS,QACL,OAAO,MAAM,SAAS,KAAK,QAAQ,KAAK,IACxC,OAAO,MAAM,SAAS,GAAG;CAC/B,OAAO;AACT;AAaA,IAAa,oBAAb,MAAa,kBAAwD;CACnE,SAA0B,YAAY,CAAC,eAAe,aAAa,CAAC;CAEpE;CAEA;CAEA,OAAgB;CAEhB,OAAO,MAAM,MAAqB,SAAoC;EACpE,OAAO,IAAI,kBAAkB,MAAM,OAAO;CAC5C;CAEA,YAAY,MAAqB,UAAoC,CAAC,GAAG;EACvE,KAAK,OAAO;EACZ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OAAO,GACJ,YAAY,OAAO,KACtB;EACF;EACA,SAAS,CAGP,aAAa,GACb;GACE,MAAM;GACN,kBAAkB;IAChB,OAAO,CAAC;GACV;EACF,CACF;CACF,CAAC;AAGH","debug_id":"33a7684d-ff05-56ac-b4f5-910a2adca3e5"}
@@ -1,8 +1,22 @@
1
- import { ILogger } from "document-model";
2
1
  import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
2
+ import { ILogger } from "document-model";
3
3
  import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
4
-
5
4
  //#region src/packages/types.d.ts
5
+ interface PackagePiece {
6
+ name: string;
7
+ /** Built output, relative to the package root: a directory in npm shape. */
8
+ bundle?: string;
9
+ /** Built output, relative to the package root: a single module file. */
10
+ entry?: string;
11
+ }
12
+ interface PackagePieceEntry {
13
+ name: string;
14
+ /** The version of the package that ships it. */
15
+ version: string;
16
+ entryPath?: string;
17
+ bundleDir?: string;
18
+ entryUrl?: string;
19
+ }
6
20
  interface IPackageLoader {
7
21
  name: string;
8
22
  loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
@@ -13,6 +27,8 @@ interface IPackageLoader {
13
27
  loadUpgradeManifests?(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
14
28
  loadSubgraphs(identifier: string, immediate?: boolean): Promise<SubgraphClass[]>;
15
29
  loadProcessors(identifier: string, immediate?: boolean): Promise<ProcessorFactoryBuilder | null>;
30
+ /** The pieces a package ships, each located absolutely on this disk. */
31
+ loadPieces(identifier: string, immediate?: boolean): Promise<PackagePieceEntry[]>;
16
32
  }
17
33
  interface ISubscriptionOptions {
18
34
  debounce?: number;
@@ -21,6 +37,7 @@ interface ISubscribablePackageLoader extends IPackageLoader {
21
37
  onDocumentModelsChange?(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
22
38
  onSubgraphsChange?(identifier: string, handler: (subgraphs: SubgraphClass[]) => void, options?: ISubscriptionOptions): () => void;
23
39
  onProcessorsChange?(identifier: string, handler: (processors: ProcessorFactoryBuilder | null) => void, options?: ISubscriptionOptions): () => void;
40
+ onPiecesChange?(identifier: string, handler: (pieces: PackagePieceEntry[]) => void, options?: ISubscriptionOptions): () => void;
24
41
  }
25
42
  interface IPackageManager {
26
43
  onDocumentModelsChange(handler: (documentModels: Record<string, DocumentModelModule[]>) => void): void;
@@ -42,7 +59,13 @@ type PackageManagerResult = {
42
59
  upgradeManifests: UpgradeManifest<readonly number[]>[];
43
60
  subgraphs: Map<string, SubgraphClass[]>;
44
61
  processors: Map<string, ProcessorFactoryBuilder[]>;
62
+ pieces: Map<string, PackagePieceEntry[]>;
45
63
  };
64
+ interface IPackagePieceSource {
65
+ getPieces(): Map<string, PackagePieceEntry[]>;
66
+ onPiecesChange(handler: (pieces: Map<string, PackagePieceEntry[]>) => void): void;
67
+ }
46
68
  //#endregion
47
- export { ISubscribablePackageLoader as a, IPackageManagerOptions as i, IPackageLoaderOptions as n, ISubscriptionOptions as o, IPackageManager as r, PackageManagerResult as s, IPackageLoader as t };
48
- //# sourceMappingURL=types-DcYyNcHJ.d.mts.map
69
+ export { IPackagePieceSource as a, PackageManagerResult as c, IPackageManagerOptions as i, PackagePiece as l, IPackageLoaderOptions as n, ISubscribablePackageLoader as o, IPackageManager as r, ISubscriptionOptions as s, IPackageLoader as t, PackagePieceEntry as u };
70
+ export {};
71
+ //# sourceMappingURL=types-DlTiz6AA.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DlTiz6AA.d.mts","names":[],"sources":["../src/packages/types.ts"],"mappings":";;;;UAYiB;EACf;;EAEA;;EAEA;;UAQe;EACf;;EAEA;EACA;EACA;EACA;;UAGe;EACf;EACA,mBACE,oBACA,sBACC,QAAQ;;;;;EAKX,sBACE,qBACC,QAAQ;EACX,cACE,oBACA,sBACC,QAAQ;EACX,eACE,oBACA,sBACC,QAAQ;;EAEX,WACE,oBACA,sBACC,QAAQ;;UAGI;EACf;;UAGe,mCAAmC;EAClD,wBACE,oBACA,UAAU,gBAAgB,gCAC1B,UAAU;EAEZ,mBACE,oBACA,UAAU,WAAW,0BACrB,UAAU;EAEZ,oBACE,oBACA,UAAU,YAAY,yCACtB,UAAU;EAEZ,gBACE,oBACA,UAAU,QAAQ,8BAClB,UAAU;;UAIG;EACf,uBACE,UAAU,gBAAgB,eAAe;;;;;EAM3C,cAAc;;KAGJ;EACV,SAAS;;KAGC;EACV;EACA;;KAWU;EACV,gBAAgB;EAChB,kBAAkB;EAClB,WAAW,YAAY;EACvB,YAAY,YAAY;EACxB,QAAQ,YAAY;;UAKL;EACf,aAAa,YAAY;EACzB,eACE,UAAU,QAAQ,YAAY"}
@@ -1,6 +1,6 @@
1
1
  //#region src/graphql/websocket.ts
2
2
 
3
- !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]="663fe2c0-10df-557e-b45d-57d4135d09f2")}catch(e){}}();
3
+ !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]="bddc5b47-cb23-58b9-bb18-09b08c412430")}catch(e){}}();
4
4
  let useServerImpl = null;
5
5
  if (process.env.VITEST !== "true" && process.env.NODE_ENV !== "test") try {
6
6
  const { useServer } = await import("graphql-ws/use/ws");
@@ -14,5 +14,5 @@ const useServer = useServerImpl || (() => {
14
14
  //#endregion
15
15
  export { useServer as t };
16
16
 
17
- //# sourceMappingURL=websocket-DncAB9XK.mjs.map
18
- //# debugId=663fe2c0-10df-557e-b45d-57d4135d09f2
17
+ //# sourceMappingURL=websocket-_SH5aBcy.mjs.map
18
+ //# debugId=bddc5b47-cb23-58b9-bb18-09b08c412430
@@ -1 +1 @@
1
- {"version":3,"file":"websocket-DncAB9XK.mjs","sources":["../src/graphql/websocket.ts"],"sourcesContent":["import type { useServer as wsUseServer } from \"graphql-ws/use/ws\";\n\nlet useServerImpl: typeof wsUseServer | null = null;\n\nif (process.env.VITEST !== \"true\" && process.env.NODE_ENV !== \"test\") {\n try {\n const { useServer } = await import(\"graphql-ws/use/ws\");\n useServerImpl = useServer;\n } catch (error) {\n console.warn(\n \"Failed to load graphql-ws WebSocket server. Subscriptions will not work.\",\n error,\n );\n }\n}\n\nexport const useServer =\n useServerImpl ||\n (() => {\n throw new Error(\n \"WebSocket server not available in test mode. Set NODE_ENV=production to enable.\",\n );\n });\n"],"names":[],"mappings":";;;AAEA,IAAI,gBAA2C;AAE/C,IAAI,QAAQ,IAAI,WAAW,UAAU,QAAQ,IAAI,aAAa,OAC5D,KAAI;CACF,MAAM,EAAE,cAAc,MAAM,OAAO;AACnC,iBAAgB;SACT,OAAO;AACd,SAAQ,KACN,4EACA,MACD;;AAIL,MAAa,YACX,wBACO;AACL,OAAM,IAAI,MACR,kFACD","debug_id":"663fe2c0-10df-557e-b45d-57d4135d09f2"}
1
+ {"version":3,"file":"websocket-_SH5aBcy.mjs","sources":["../src/graphql/websocket.ts"],"sourcesContent":["import type { useServer as wsUseServer } from \"graphql-ws/use/ws\";\n\nlet useServerImpl: typeof wsUseServer | null = null;\n\nif (process.env.VITEST !== \"true\" && process.env.NODE_ENV !== \"test\") {\n try {\n const { useServer } = await import(\"graphql-ws/use/ws\");\n useServerImpl = useServer;\n } catch (error) {\n console.warn(\n \"Failed to load graphql-ws WebSocket server. Subscriptions will not work.\",\n error,\n );\n }\n}\n\nexport const useServer =\n useServerImpl ||\n (() => {\n throw new Error(\n \"WebSocket server not available in test mode. Set NODE_ENV=production to enable.\",\n );\n });\n"],"names":[],"mappings":";;;AAEA,IAAI,gBAA2C;AAE/C,IAAI,QAAQ,IAAI,WAAW,UAAU,QAAQ,IAAI,aAAa,QAC5D,IAAI;CACF,MAAM,EAAE,cAAc,MAAM,OAAO;CACnC,gBAAgB;AAClB,SAAS,OAAO;CACd,QAAQ,KACN,4EACA,KACF;AACF;AAGF,MAAa,YACX,wBACO;CACL,MAAM,IAAI,MACR,iFACF;AACF","debug_id":"bddc5b47-cb23-58b9-bb18-09b08c412430"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/reactor-api",
3
- "version": "6.2.3-dev.4",
3
+ "version": "6.2.3-dev.40",
4
4
  "description": "GraphQL API layer for the Powerhouse reactor — auto-generated subgraphs per document model plus the core reactor subgraph for drive and document management.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -59,26 +59,26 @@
59
59
  "@graphql-tools/schema": "10.0.31",
60
60
  "@graphql-tools/utils": "11.0.0",
61
61
  "@originjs/vite-plugin-commonjs": "^1.0.3",
62
- "@powerhousedao/analytics-engine-core": "6.2.3-dev.4",
63
- "@powerhousedao/analytics-engine-graphql": "6.2.3-dev.4",
64
- "@powerhousedao/analytics-engine-pg": "6.2.3-dev.4",
65
- "@powerhousedao/config": "6.2.3-dev.4",
62
+ "@powerhousedao/analytics-engine-core": "6.2.3-dev.40",
63
+ "@powerhousedao/analytics-engine-graphql": "6.2.3-dev.40",
64
+ "@powerhousedao/analytics-engine-pg": "6.2.3-dev.40",
65
+ "@powerhousedao/config": "6.2.3-dev.40",
66
66
  "@powerhousedao/document-engineering": "1.40.5",
67
- "@powerhousedao/pglite-fs": "6.2.3-dev.4",
68
- "@powerhousedao/reactor": "6.2.3-dev.4",
69
- "@powerhousedao/reactor-attachments": "6.2.3-dev.4",
70
- "@powerhousedao/reactor-drive": "6.2.3-dev.4",
71
- "@powerhousedao/reactor-group": "6.2.3-dev.4",
72
- "@powerhousedao/reactor-mcp": "6.2.3-dev.4",
73
- "@powerhousedao/shared": "6.2.3-dev.4",
74
- "@renown/sdk": "6.2.3-dev.4",
67
+ "@powerhousedao/pglite-fs": "6.2.3-dev.40",
68
+ "@powerhousedao/reactor": "6.2.3-dev.40",
69
+ "@powerhousedao/reactor-attachments": "6.2.3-dev.40",
70
+ "@powerhousedao/reactor-drive": "6.2.3-dev.40",
71
+ "@powerhousedao/reactor-group": "6.2.3-dev.40",
72
+ "@powerhousedao/reactor-mcp": "6.2.3-dev.40",
73
+ "@powerhousedao/shared": "6.2.3-dev.40",
74
+ "@renown/sdk": "6.2.3-dev.40",
75
75
  "body-parser": "^1.20.3",
76
76
  "change-case": "5.4.4",
77
77
  "cors": "^2.8.5",
78
78
  "devcert": "^1.2.2",
79
- "document-model": "6.2.3-dev.4",
79
+ "document-model": "6.2.3-dev.40",
80
80
  "dotenv": "^16.4.5",
81
- "express": "4.21.1",
81
+ "express": "^4.22.1",
82
82
  "graphql-sse": "2.6.0",
83
83
  "graphql-subscriptions": "^3.0.0",
84
84
  "graphql-type-json": "^0.3.2",
@@ -115,7 +115,7 @@
115
115
  "@types/ws": "^8.18.1",
116
116
  "graphql": "^16",
117
117
  "graphql-tag": "^2",
118
- "tsdown": "0.21.1",
118
+ "tsdown": "0.23.0",
119
119
  "msw": "^2.7.3",
120
120
  "vitest": "4.1.1"
121
121
  },
@@ -157,11 +157,11 @@
157
157
  "scripts": {
158
158
  "tsc": "tsc",
159
159
  "build": "tsdown",
160
- "lint": "eslint",
160
+ "lint": "cd ../.. && oxlint packages/reactor-api",
161
161
  "test": "vitest --run",
162
162
  "test:integration": "cross-env RUN_HUB_SPOKE_INTEGRATION=1 vitest --run test/hub-spoke-catchup.integration.test.ts",
163
163
  "bench": "vitest bench",
164
- "codegen": "graphql-codegen --config codegen.ts && prettier --write src/graphql/reactor/gen/*.ts && eslint --fix src/graphql/reactor/gen/*.ts --no-warn-ignored",
164
+ "codegen": "graphql-codegen --config codegen.ts && oxlint --fix src/graphql/reactor/gen/*.ts && oxfmt src/graphql/reactor/gen/*.ts",
165
165
  "codegen:watch": "graphql-codegen --config codegen.ts --watch",
166
166
  "dev": "tsx src/dev.ts",
167
167
  "capture-hub-dump": "tsx scripts/capture-hub-dump.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter-http-express-B39rPhqH.mjs","sources":["../src/graphql/gateway/adapter-http-express.ts"],"sourcesContent":["import bodyParser from \"body-parser\";\nimport cors from \"cors\";\nimport type { CorsOptions } from \"cors\";\nimport devcert from \"devcert\";\nimport type express from \"express\";\nimport type { Express } from \"express\";\nimport { Router } from \"express\";\nimport expressLib from \"express\";\nimport type { IRouter } from \"express\";\nimport fs from \"node:fs\";\nimport http from \"node:http\";\nimport https from \"node:https\";\nimport path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport type { ReadableStream as WebReadableStream } from \"node:stream/web\";\nimport { match, type MatchFunction, type ParamData } from \"path-to-regexp\";\nimport type {\n FetchHandler,\n HttpMethod,\n IHttpAdapter,\n NodeRouteOptions,\n AdapterRouteHandle,\n TlsOptions,\n} from \"./types.js\";\nimport { normalizePath } from \"./path-normalize.js\";\n\ntype GetHandler = (r: Request) => Response | Promise<Response>;\n\ntype NodeHandler = (\n req: http.IncomingMessage,\n res: http.ServerResponse,\n body?: unknown,\n) => void | Promise<void>;\n\ntype RouteEntry =\n | {\n kind: \"fetch\";\n path: string;\n matcher: MatchFunction<ParamData>;\n prefix: boolean;\n handler: FetchHandler;\n }\n | {\n kind: \"get\";\n path: string;\n matcher: MatchFunction<ParamData>;\n handler: GetHandler;\n }\n | {\n kind: \"node\";\n method: string;\n path: string;\n matcher: MatchFunction<ParamData>;\n handler: NodeHandler;\n /** Dispatched ahead of the body parsers, with the stream unread. */\n rawBody: boolean;\n };\n\nexport class ExpressHttpAdapter implements IHttpAdapter {\n readonly #app: Express;\n readonly #router: IRouter;\n\n /**\n * Every route lives in this registry and is served by one\n * permanently-registered dispatcher (installed by setupMiddleware), because\n * Express 4 has no route-removal API: routes registered directly on the\n * app or router can never be taken back. Entries iterate in registration\n * order; mounting a path that already holds a route of the same kind (and\n * method, for node routes) replaces the old entry, so re-mounting is\n * last-write-wins without accumulating.\n */\n readonly #routes = new Map<number, RouteEntry>();\n #nextHandle = 0;\n\n constructor(existingApp?: Express) {\n this.#app = existingApp ?? expressLib();\n this.#router = Router();\n this.#app.use(this.#router);\n }\n\n setupSentryErrorHandler(sentry: object): void {\n const s = sentry as {\n setupExpressErrorHandler(app: Express): void;\n };\n s.setupExpressErrorHandler(this.#app);\n }\n\n get handle(): unknown {\n return this.#app;\n }\n\n mountRawMiddleware(middleware: unknown): void {\n // Connect/Express middleware shape; the caller owns its typing.\n this.#app.use(middleware as express.RequestHandler);\n }\n\n mountNodeRoute(\n method: HttpMethod,\n path: string,\n handler: (\n req: http.IncomingMessage,\n res: http.ServerResponse,\n body?: unknown,\n ) => void | Promise<void>,\n { rawBody = false, prefix = false }: NodeRouteOptions = {},\n ): AdapterRouteHandle {\n this.#replaceDuplicates(\"node\", path, method.toUpperCase());\n const handle = this.#nextHandle++;\n this.#routes.set(handle, {\n kind: \"node\",\n method: method.toUpperCase(),\n path,\n matcher: match(normalizePath(path), { end: !prefix }),\n rawBody,\n handler,\n });\n return { dispose: () => this.#routes.delete(handle) };\n }\n\n setupMiddleware({\n corsOptions,\n bodyLimit = \"50mb\",\n }: {\n corsOptions?: CorsOptions;\n bodyLimit?: string;\n }): void {\n this.#router.use(cors(corsOptions));\n\n // Ahead of the parsers: a raw route's whole point is that nothing has read\n // the stream. Behind them, `req` is a consumed stream and only a\n // re-encoded `req.body` survives — which cannot carry a signature over the\n // octets the client actually sent.\n this.#router.use((req, res, next) => {\n this.#dispatchNodeRoute(req, res, next, true);\n });\n\n this.#router.use(bodyParser.json({ limit: bodyLimit }));\n this.#router.use(\n bodyParser.urlencoded({ extended: true, limit: bodyLimit }),\n );\n\n // The single dispatch point for every registered route, registered\n // AFTER the body parsers so node routes receive a parsed req.body.\n // A request matching no route falls through to app-level middleware\n // (mountRawMiddleware) and then Express's default 404.\n this.#router.use((req, res, next) => {\n const pathname = req.path;\n\n // Node routes first, then GET routes, then Fetch mounts — the same\n // order the Fastify adapter uses. A node route is the most specific\n // registration there is (method plus exact path), while a Fetch mount is\n // often a prefix; letting the prefix win would silently shadow an exact\n // route, and would do it in only one of the two adapters.\n if (this.#dispatchNodeRoute(req, res, () => undefined, false)) return;\n\n if (req.method === \"GET\" || req.method === \"HEAD\") {\n for (const entry of this.#routes.values()) {\n if (entry.kind !== \"get\" || !entry.matcher(pathname)) continue;\n this.#serveGetEntry(entry, req, res);\n return;\n }\n }\n\n for (const entry of this.#routes.values()) {\n if (entry.kind !== \"fetch\" || !entry.matcher(pathname)) continue;\n this.#serveFetchHandler(entry.handler, req, res, next);\n return;\n }\n\n next();\n });\n }\n\n /**\n * Serves the first node route matching this request, or calls `next()`.\n * `raw` selects which half of the registry to consider, so the two passes —\n * one before the body parsers, one after — never serve the same route twice.\n */\n #dispatchNodeRoute(\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n raw: boolean,\n ): boolean {\n const pathname = req.path;\n for (const entry of this.#routes.values()) {\n if (entry.kind !== \"node\") continue;\n if (entry.rawBody !== raw) continue;\n if (entry.method !== req.method) continue;\n const matched = entry.matcher(pathname);\n if (!matched) continue;\n req.params = matched.params as Record<string, string>;\n // Fire-and-forget, as before: the node handler manages its own response\n // and the adapter does not await its promise.\n void entry.handler(req, res, entry.rawBody ? undefined : req.body);\n return true;\n }\n next();\n return false;\n }\n\n mount(\n path: string,\n handler: FetchHandler,\n { prefix, exact }: { prefix?: boolean; exact?: boolean } = {},\n ): AdapterRouteHandle {\n // `exact` never meant exact: it selected prefix matching. Kept as an alias\n // so existing callers keep working while the name is retired.\n const asPrefix = prefix ?? exact ?? false;\n this.#replaceDuplicates(\"fetch\", path);\n const handle = this.#nextHandle++;\n this.#routes.set(handle, {\n kind: \"fetch\",\n path,\n matcher: match(normalizePath(path), { end: !asPrefix }),\n prefix: asPrefix,\n handler,\n });\n return { dispose: () => this.#routes.delete(handle) };\n }\n\n getRoute(\n path: string,\n handler: (request: Request) => Response | Promise<Response>,\n ): AdapterRouteHandle {\n this.#replaceDuplicates(\"get\", path);\n const handle = this.#nextHandle++;\n this.#routes.set(handle, {\n kind: \"get\",\n path,\n matcher: match(normalizePath(path)),\n handler,\n });\n return { dispose: () => this.#routes.delete(handle) };\n }\n\n /**\n * Drop any existing entry the new registration would duplicate (same kind\n * and path, plus method for node routes) so a re-mount replaces instead of\n * shadowing. Map iteration tolerates concurrent deletion.\n */\n #replaceDuplicates(\n kind: RouteEntry[\"kind\"],\n path: string,\n method?: string,\n ): void {\n for (const [handle, entry] of this.#routes) {\n if (entry.kind !== kind || entry.path !== path) continue;\n if (kind === \"node\" && entry.kind === \"node\" && entry.method !== method) {\n continue;\n }\n this.#routes.delete(handle);\n }\n }\n\n async listen(port: number, tls?: TlsOptions): Promise<http.Server> {\n let server: http.Server;\n\n if (tls === true) {\n const { cert, key } = (await devcert.certificateFor(\"localhost\")) as {\n cert: Buffer;\n key: Buffer;\n };\n if (!cert || !key) {\n throw new Error(\"Invalid certificate generated\");\n }\n server = https.createServer({ cert, key }, this.#app);\n } else if (tls && \"keyPath\" in tls) {\n const currentDir = process.cwd();\n server = https.createServer(\n {\n key: fs.readFileSync(path.join(currentDir, tls.keyPath)),\n cert: fs.readFileSync(path.join(currentDir, tls.certPath)),\n },\n this.#app,\n );\n } else if (tls && \"cert\" in tls) {\n server = https.createServer({ cert: tls.cert, key: tls.key }, this.#app);\n } else {\n server = http.createServer(this.#app);\n }\n\n return new Promise<http.Server>((resolve, reject) => {\n server.once(\"error\", reject);\n server.listen(port, () => {\n server.off(\"error\", reject);\n resolve(server);\n });\n });\n }\n\n #serveFetchHandler(\n handler: FetchHandler,\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n ): void {\n // Build the full URL for the Fetch Request\n const protocol = req.protocol;\n const host = req.get(\"host\") ?? \"localhost\";\n const url = `${protocol}://${host}${req.originalUrl}`;\n\n // Convert Node.js incoming headers to Fetch Headers\n const headers = new Headers();\n for (const [key, value] of Object.entries(req.headers)) {\n if (typeof value === \"string\") {\n headers.set(key, value);\n } else if (Array.isArray(value)) {\n headers.set(key, value.join(\", \"));\n }\n }\n\n // bodyParser has already run, so req.body is a parsed JS value.\n // Re-serialize it so the Fetch Request body stream is readable.\n let body: string | undefined;\n if (\n req.method !== \"GET\" &&\n req.method !== \"HEAD\" &&\n req.body !== undefined\n ) {\n body = JSON.stringify(req.body);\n }\n\n const fetchRequest = new Request(url, {\n method: req.method,\n headers,\n body,\n });\n\n Promise.resolve(handler(fetchRequest))\n .then(async (response) => {\n res.status(response.status);\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n if (response.body === null) {\n res.send(await response.text());\n return;\n }\n // Stream the body to the socket instead of awaiting .text(): a\n // stream-backed body (e.g. graphql-sse) only closes when the\n // subscription completes, so awaiting would hang the request.\n // `response.body` is typed against the global (lib) ReadableStream\n // declaration, while Readable.fromWeb wants node:stream/web's; at\n // runtime they are the same stream, so the cast is safe.\n const bodyStream = response.body as WebReadableStream;\n const nodeStream = Readable.fromWeb(bodyStream);\n req.on(\"close\", () => {\n // The client went away mid-stream; stop pulling from the source.\n nodeStream.destroy();\n });\n nodeStream.on(\"error\", (err) => {\n if (res.headersSent) {\n // The response has already started; nothing left to say.\n res.destroy();\n } else {\n next(err);\n }\n });\n nodeStream.pipe(res);\n })\n .catch(next);\n }\n\n #serveGetEntry(\n entry: Extract<RouteEntry, { kind: \"get\" }>,\n req: express.Request,\n res: express.Response,\n ): void {\n const protocol = req.protocol;\n const host = req.get(\"host\") ?? \"localhost\";\n const url = `${protocol}://${host}${req.originalUrl}`;\n const headers = new Headers();\n for (const [key, value] of Object.entries(req.headers)) {\n if (typeof value === \"string\") {\n headers.set(key, value);\n } else if (Array.isArray(value)) {\n headers.set(key, value.join(\", \"));\n }\n }\n // GET is forced (matching the pre-refactor behavior, which also\n // normalized HEAD requests through the GET route handler).\n const fetchRequest = new Request(url, { method: \"GET\", headers });\n Promise.resolve(entry.handler(fetchRequest))\n .then(async (response) => {\n res.status(response.status);\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n if (response.body === null) {\n res.send(await response.text());\n return;\n }\n // Stream the body to the socket instead of awaiting .text(): a\n // stream-backed body (e.g. graphql-sse) only closes when the\n // subscription completes, so awaiting would hang the request.\n // `response.body` is typed against the global (lib) ReadableStream\n // declaration, while Readable.fromWeb wants node:stream/web's; at\n // runtime they are the same stream, so the cast is safe.\n const bodyStream = response.body as WebReadableStream;\n const nodeStream = Readable.fromWeb(bodyStream);\n req.on(\"close\", () => {\n // The client went away mid-stream; stop pulling from the source.\n nodeStream.destroy();\n });\n nodeStream.on(\"error\", (err) => {\n if (res.headersSent) {\n // The response has already started; nothing left to say.\n res.destroy();\n } else {\n res.status(500).send(String(err));\n }\n });\n nodeStream.pipe(res);\n })\n .catch((err: unknown) => {\n res.status(500).send(String(err));\n });\n }\n}\n\nexport function createExpressHttpAdapter(existingApp?: Express): {\n adapter: IHttpAdapter;\n} {\n return { adapter: new ExpressHttpAdapter(existingApp) };\n}\n"],"names":["#app","#router","#routes","#replaceDuplicates","#nextHandle","#dispatchNodeRoute","#serveGetEntry","#serveFetchHandler"],"mappings":";;;;;;;;;;;;;;AA0DA,IAAa,qBAAb,MAAwD;CACtD;CACA;;;;;;;;;;CAWA,0BAAmB,IAAI,KAAyB;CAChD,cAAc;CAEd,YAAY,aAAuB;AACjC,QAAA,MAAY,eAAe,YAAY;AACvC,QAAA,SAAe,QAAQ;AACvB,QAAA,IAAU,IAAI,MAAA,OAAa;;CAG7B,wBAAwB,QAAsB;AAClC,SAGR,yBAAyB,MAAA,IAAU;;CAGvC,IAAI,SAAkB;AACpB,SAAO,MAAA;;CAGT,mBAAmB,YAA2B;AAE5C,QAAA,IAAU,IAAI,WAAqC;;CAGrD,eACE,QACA,MACA,SAKA,EAAE,UAAU,OAAO,SAAS,UAA4B,EAAE,EACtC;AACpB,QAAA,kBAAwB,QAAQ,MAAM,OAAO,aAAa,CAAC;EAC3D,MAAM,SAAS,MAAA;AACf,QAAA,OAAa,IAAI,QAAQ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