@powerhousedao/reactor-api 6.2.3-dev.7 → 6.2.3-dev.71
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/README.md +7 -2
- package/dist/{adapter-gateway-apollo-CxJNBVyD.mjs → adapter-gateway-apollo-D-EdZ4e-.mjs} +23 -23
- package/dist/adapter-gateway-apollo-D-EdZ4e-.mjs.map +1 -0
- package/dist/{adapter-gateway-mercurius-CZVy88Za.mjs → adapter-gateway-mercurius-CdxLge5p.mjs} +4 -12
- package/dist/adapter-gateway-mercurius-CdxLge5p.mjs.map +1 -0
- package/dist/{adapter-http-express-B39rPhqH.mjs → adapter-http-express-P0t-mdMV.mjs} +10 -10
- package/dist/adapter-http-express-P0t-mdMV.mjs.map +1 -0
- package/dist/{adapter-http-fastify-BwXO6rqE.mjs → adapter-http-fastify-D0OP5q9K.mjs} +13 -12
- package/dist/adapter-http-fastify-D0OP5q9K.mjs.map +1 -0
- package/dist/base-document-models-uUQKgXcf.mjs +1415 -0
- package/dist/base-document-models-uUQKgXcf.mjs.map +1 -0
- package/dist/create-schema-BUk-IQCT.d.mts +144 -0
- package/dist/create-schema-BUk-IQCT.d.mts.map +1 -0
- package/dist/index.d.mts +2029 -739
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4558 -1715
- package/dist/index.mjs.map +1 -1
- package/dist/package-subgraph-check-CsTPajAN.mjs +137 -0
- package/dist/package-subgraph-check-CsTPajAN.mjs.map +1 -0
- package/dist/pglite-node-C-UQXrjU.mjs +576 -0
- package/dist/pglite-node-C-UQXrjU.mjs.map +1 -0
- package/dist/rolldown-runtime-8H4AJuhK.mjs +16 -0
- package/dist/run-node-handler-CQjyjOuN.mjs +52 -0
- package/dist/run-node-handler-CQjyjOuN.mjs.map +1 -0
- package/dist/src/graphql/subgraph-types.d.mts +43 -0
- package/dist/src/graphql/subgraph-types.d.mts.map +1 -0
- package/dist/src/graphql/subgraph-types.mjs +14 -0
- package/dist/src/graphql/subgraph-types.mjs.map +1 -0
- package/dist/src/packages/https-hooks.d.mts +4 -4
- package/dist/src/packages/https-hooks.d.mts.map +1 -1
- package/dist/src/packages/https-hooks.mjs +2 -2
- package/dist/src/packages/https-hooks.mjs.map +1 -1
- package/dist/src/packages/vite-loader.d.mts +21 -10
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +134 -82
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/src/pglite/pglite-node.d.mts +130 -0
- package/dist/src/pglite/pglite-node.d.mts.map +1 -0
- package/dist/src/pglite/pglite-node.mjs +4 -0
- package/dist/{utils-XWVecaNn.mjs → subgraph-extraction-cSpPp3Hq.mjs} +541 -17
- package/dist/subgraph-extraction-cSpPp3Hq.mjs.map +1 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs +10 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs.map +1 -0
- package/dist/types-CCI5IDgT.d.mts +82 -0
- package/dist/types-CCI5IDgT.d.mts.map +1 -0
- package/package.json +30 -20
- package/dist/adapter-gateway-apollo-CxJNBVyD.mjs.map +0 -1
- package/dist/adapter-gateway-apollo-DowrX6E_.mjs +0 -4
- package/dist/adapter-gateway-mercurius-CZVy88Za.mjs.map +0 -1
- package/dist/adapter-gateway-stitching-CaZjvRzx.mjs +0 -316
- package/dist/adapter-gateway-stitching-CaZjvRzx.mjs.map +0 -1
- package/dist/adapter-http-express-B39rPhqH.mjs.map +0 -1
- package/dist/adapter-http-fastify-BwXO6rqE.mjs.map +0 -1
- package/dist/path-normalize-BOQwY9wR.mjs +0 -23
- package/dist/path-normalize-BOQwY9wR.mjs.map +0 -1
- package/dist/types-DcYyNcHJ.d.mts +0 -48
- package/dist/types-DcYyNcHJ.d.mts.map +0 -1
- package/dist/utils-XWVecaNn.mjs.map +0 -1
- package/dist/websocket-DncAB9XK.mjs +0 -18
- package/dist/websocket-DncAB9XK.mjs.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { __exportAll as t };
|
|
15
|
+
!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]="e3b80eba-208e-51a9-b437-5ac76accf5d0")}catch(e){}}();
|
|
16
|
+
//# debugId=e3b80eba-208e-51a9-b437-5ac76accf5d0
|
|
@@ -0,0 +1,52 @@
|
|
|
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]="b96f00d4-5192-57bc-b435-7cc0f7c0f5c8")}catch(e){}}();
|
|
3
|
+
import { childLogger } from "document-model";
|
|
4
|
+
//#region src/graphql/gateway/path-normalize.ts
|
|
5
|
+
/**
|
|
6
|
+
* Normalises a route path for path-to-regexp v8:
|
|
7
|
+
* - Collapses duplicate slashes (e.g. "//explorer" → "/explorer")
|
|
8
|
+
* - Converts legacy optional-param syntax "/:param?" → "{/:param}". The
|
|
9
|
+
* slash must move inside the group: in p-r v8 a group whose content
|
|
10
|
+
* begins with "/" is what makes the slash and the parameter optional
|
|
11
|
+
* together, while a literal "/" left in front of the group compiles to
|
|
12
|
+
* a pattern that matches nothing (and v8 rejects a bare ":param?").
|
|
13
|
+
*
|
|
14
|
+
* Shared by both http adapters so registry dispatch matches the same path
|
|
15
|
+
* shapes regardless of which framework is in use.
|
|
16
|
+
*/
|
|
17
|
+
function normalizePath(path) {
|
|
18
|
+
return path.replace(/\/+/g, "/").replace(/\/:(\w+)\?/g, "{/:$1}");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/graphql/gateway/run-node-handler.ts
|
|
22
|
+
const logger = childLogger(["reactor-api", "node-route"]);
|
|
23
|
+
/**
|
|
24
|
+
* Runs a node route handler without awaiting it. A throw or rejection is
|
|
25
|
+
* logged and answered with a 500, or ends the socket if headers already went
|
|
26
|
+
* out; it never reaches the process as an unhandled rejection.
|
|
27
|
+
*/
|
|
28
|
+
function runNodeHandler(handler, req, res, body) {
|
|
29
|
+
const fail = (err) => {
|
|
30
|
+
logger.error("Node route handler failed for @method @url: @error", req.method, req.url, err);
|
|
31
|
+
if (res.headersSent) {
|
|
32
|
+
res.destroy();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
res.statusCode = 500;
|
|
36
|
+
res.setHeader("Content-Type", "application/json");
|
|
37
|
+
res.end(JSON.stringify({ error: "Internal error" }));
|
|
38
|
+
};
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
result = handler(req, res, body);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
fail(err);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (result) result.catch(fail);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { normalizePath as n, runNodeHandler as t };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=run-node-handler-CQjyjOuN.mjs.map
|
|
52
|
+
//# debugId=b96f00d4-5192-57bc-b435-7cc0f7c0f5c8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-node-handler-CQjyjOuN.mjs","sources":["../src/graphql/gateway/path-normalize.ts","../src/graphql/gateway/run-node-handler.ts"],"sourcesContent":["/**\n * Normalises a route path for path-to-regexp v8:\n * - Collapses duplicate slashes (e.g. \"//explorer\" → \"/explorer\")\n * - Converts legacy optional-param syntax \"/:param?\" → \"{/:param}\". The\n * slash must move inside the group: in p-r v8 a group whose content\n * begins with \"/\" is what makes the slash and the parameter optional\n * together, while a literal \"/\" left in front of the group compiles to\n * a pattern that matches nothing (and v8 rejects a bare \":param?\").\n *\n * Shared by both http adapters so registry dispatch matches the same path\n * shapes regardless of which framework is in use.\n */\nexport function normalizePath(path: string): string {\n return path.replace(/\\/+/g, \"/\").replace(/\\/:(\\w+)\\?/g, \"{/:$1}\");\n}\n","import { childLogger } from \"document-model\";\nimport type http from \"node:http\";\n\nconst logger = childLogger([\"reactor-api\", \"node-route\"]);\n\nexport type NodeHandler = (\n req: http.IncomingMessage,\n res: http.ServerResponse,\n body?: unknown,\n) => void | Promise<void>;\n\n/**\n * Runs a node route handler without awaiting it. A throw or rejection is\n * logged and answered with a 500, or ends the socket if headers already went\n * out; it never reaches the process as an unhandled rejection.\n */\nexport function runNodeHandler(\n handler: NodeHandler,\n req: http.IncomingMessage,\n res: http.ServerResponse,\n body: unknown,\n): void {\n const fail = (err: unknown): void => {\n logger.error(\n \"Node route handler failed for @method @url: @error\",\n req.method,\n req.url,\n err,\n );\n if (res.headersSent) {\n res.destroy();\n return;\n }\n res.statusCode = 500;\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ error: \"Internal error\" }));\n };\n\n let result: void | Promise<void>;\n try {\n result = handler(req, res, body);\n } catch (err) {\n fail(err);\n return;\n }\n if (result) {\n result.catch(fail);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAYA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,QAAQ,eAAe,QAAQ;AAClE;;;ACXA,MAAM,SAAS,YAAY,CAAC,eAAe,YAAY,CAAC;;;;;;AAaxD,SAAgB,eACd,SACA,KACA,KACA,MACM;CACN,MAAM,QAAQ,QAAuB;EACnC,OAAO,MACL,sDACA,IAAI,QACJ,IAAI,KACJ,GACF;EACA,IAAI,IAAI,aAAa;GACnB,IAAI,QAAQ;GACZ;EACF;EACA,IAAI,aAAa;EACjB,IAAI,UAAU,gBAAgB,kBAAkB;EAChD,IAAI,IAAI,KAAK,UAAU,EAAE,OAAO,iBAAiB,CAAC,CAAC;CACrD;CAEA,IAAI;CACJ,IAAI;EACF,SAAS,QAAQ,KAAK,KAAK,IAAI;CACjC,SAAS,KAAK;EACZ,KAAK,GAAG;EACR;CACF;CACA,IAAI,QACF,OAAO,MAAM,IAAI;AAErB","debug_id":"b96f00d4-5192-57bc-b435-7cc0f7c0f5c8"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { o as ReservedTypeNames } from "../../create-schema-BUk-IQCT.mjs";
|
|
2
|
+
import { DocumentNode } from "graphql";
|
|
3
|
+
import { DocumentModelGlobalState } from "@powerhousedao/shared/document-model";
|
|
4
|
+
//#region src/graphql/subgraph-type-ownership.d.ts
|
|
5
|
+
type OwnershipConflict = {
|
|
6
|
+
claim: string;
|
|
7
|
+
owner: string;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/graphql/subgraph-schema-owner.d.ts
|
|
11
|
+
/** Owner of the types every generated document-model schema carries. */
|
|
12
|
+
export declare const DOCUMENT_MODEL_SCHEMA_OWNER = "document-model schema";
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/graphql/subgraph-types.d.ts
|
|
15
|
+
/** A package's own subgraph, in the order the package exports it. */
|
|
16
|
+
export type PackageSubgraph = {
|
|
17
|
+
name: string;
|
|
18
|
+
typeDefs: DocumentNode;
|
|
19
|
+
};
|
|
20
|
+
export type PackageSubgraphConflicts = {
|
|
21
|
+
/** Who takes the name; "package" is a later same-name subgraph. */
|
|
22
|
+
nameHeldBy?: "core" | "document model" | "package";
|
|
23
|
+
/** Types and root fields the subgraph loses. */
|
|
24
|
+
claims: OwnershipConflict[];
|
|
25
|
+
};
|
|
26
|
+
export type RefusedDocumentModel = {
|
|
27
|
+
name: string;
|
|
28
|
+
reason: string;
|
|
29
|
+
/** Only the model's own subgraph is refused; its types are served. */
|
|
30
|
+
subgraphOnly: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type PackageSubgraphReport = {
|
|
33
|
+
/** By subgraph name; subgraphs without a conflict are left out. */
|
|
34
|
+
conflicts: Map<string, PackageSubgraphConflicts>;
|
|
35
|
+
/** The package's models, or their subgraphs, the server refuses. */
|
|
36
|
+
refusedModels: RefusedDocumentModel[];
|
|
37
|
+
};
|
|
38
|
+
/** Loaded on call: the check pulls in the base models and core schemas. */
|
|
39
|
+
export declare function findPackageSubgraphConflicts(subgraphs: readonly PackageSubgraph[], documentModels: readonly DocumentModelGlobalState[]): Promise<PackageSubgraphReport>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export type { OwnershipConflict, ReservedTypeNames };
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=subgraph-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph-types.d.mts","names":[],"sources":["../../../src/graphql/subgraph-type-ownership.ts","../../../src/graphql/subgraph-schema-owner.ts","../../../src/graphql/subgraph-types.ts"],"mappings":";;;;KAqJY;EAAsB;EAAe;;;;;qBCpJpC;;;;YCSD;EAAoB;EAAc,UAAU;;YAE5C;;EAEV;;EAEA,QAAQ;;YAGE;EACV;EACA;;EAEA;;YAGU;;EAEV,WAAW,YAAY;;EAEvB,eAAe;;;wBAIK,6BACpB,oBAAoB,mBACpB,yBAAyB,6BACxB,QAAQ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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]="31efa70a-ce7c-5c46-b58e-114594b7ff58")}catch(e){}}();
|
|
3
|
+
import { t as DOCUMENT_MODEL_SCHEMA_OWNER } from "../../subgraph-schema-owner-BEjuk2Xv.mjs";
|
|
4
|
+
//#region src/graphql/subgraph-types.ts
|
|
5
|
+
/** Loaded on call: the check pulls in the base models and core schemas. */
|
|
6
|
+
async function findPackageSubgraphConflicts(subgraphs, documentModels) {
|
|
7
|
+
const { checkPackageSubgraphs } = await import("../../package-subgraph-check-CsTPajAN.mjs");
|
|
8
|
+
return checkPackageSubgraphs(subgraphs, documentModels);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DOCUMENT_MODEL_SCHEMA_OWNER, findPackageSubgraphConflicts };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=subgraph-types.mjs.map
|
|
14
|
+
//# debugId=31efa70a-ce7c-5c46-b58e-114594b7ff58
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph-types.mjs","sources":["../../../src/graphql/subgraph-types.ts"],"sourcesContent":["import type { DocumentModelGlobalState } from \"@powerhousedao/shared/document-model\";\nimport type { DocumentNode } from \"graphql\";\nimport type { OwnershipConflict } from \"./subgraph-type-ownership.js\";\n\nexport type { ReservedTypeNames } from \"../utils/create-schema.js\";\nexport type { OwnershipConflict } from \"./subgraph-type-ownership.js\";\n\nexport { DOCUMENT_MODEL_SCHEMA_OWNER } from \"./subgraph-schema-owner.js\";\n\n/** A package's own subgraph, in the order the package exports it. */\nexport type PackageSubgraph = { name: string; typeDefs: DocumentNode };\n\nexport type PackageSubgraphConflicts = {\n /** Who takes the name; \"package\" is a later same-name subgraph. */\n nameHeldBy?: \"core\" | \"document model\" | \"package\";\n /** Types and root fields the subgraph loses. */\n claims: OwnershipConflict[];\n};\n\nexport type RefusedDocumentModel = {\n name: string;\n reason: string;\n /** Only the model's own subgraph is refused; its types are served. */\n subgraphOnly: boolean;\n};\n\nexport type PackageSubgraphReport = {\n /** By subgraph name; subgraphs without a conflict are left out. */\n conflicts: Map<string, PackageSubgraphConflicts>;\n /** The package's models, or their subgraphs, the server refuses. */\n refusedModels: RefusedDocumentModel[];\n};\n\n/** Loaded on call: the check pulls in the base models and core schemas. */\nexport async function findPackageSubgraphConflicts(\n subgraphs: readonly PackageSubgraph[],\n documentModels: readonly DocumentModelGlobalState[],\n): Promise<PackageSubgraphReport> {\n const { checkPackageSubgraphs } = await import(\"./package-subgraph-check.js\");\n return checkPackageSubgraphs(subgraphs, documentModels);\n}\n"],"names":[],"mappings":";;;;;AAkCA,eAAsB,6BACpB,WACA,gBACgC;CAChC,MAAM,EAAE,0BAA0B,MAAM,OAAO;CAC/C,OAAO,sBAAsB,WAAW,cAAc;AACxD","debug_id":"31efa70a-ce7c-5c46-b58e-114594b7ff58"}
|
|
@@ -25,15 +25,15 @@ type NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;
|
|
|
25
25
|
/**
|
|
26
26
|
* Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.
|
|
27
27
|
*/
|
|
28
|
-
declare function resolve(specifier: string, context: ResolveContext, nextResolve: NextResolve): Promise<ResolveResult>;
|
|
28
|
+
export declare function resolve(specifier: string, context: ResolveContext, nextResolve: NextResolve): Promise<ResolveResult>;
|
|
29
29
|
/**
|
|
30
30
|
* Load hook: fetches module source from HTTP/HTTPS URLs.
|
|
31
31
|
*/
|
|
32
|
-
declare function load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<LoadResult>;
|
|
32
|
+
export declare function load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<LoadResult>;
|
|
33
33
|
/**
|
|
34
34
|
* Path to this hooks file for use with node:module register()
|
|
35
35
|
*/
|
|
36
|
-
declare const httpsHooksPath: string;
|
|
36
|
+
export declare const httpsHooksPath: string;
|
|
37
37
|
//#endregion
|
|
38
|
-
export {
|
|
38
|
+
export {};
|
|
39
39
|
//# sourceMappingURL=https-hooks.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"https-hooks.d.mts","names":[],"sources":["../../../src/packages/https-hooks.mts"],"mappings":";;;;;KASK
|
|
1
|
+
{"version":3,"file":"https-hooks.d.mts","names":[],"sources":["../../../src/packages/https-hooks.mts"],"mappings":";;;;;KASK;EAAmB;EAAoB;;KACvC;EACH;EACA;EACA;;KAEG,eACH,mBACA,SAAS,mBACN,QAAQ;KAER;EAAgB;;KAChB;EAAe;EAAgB;EAAwB;;KACvD,YAAY,aAAa,SAAS,gBAAgB,QAAQ;;;;wBAKzC,QACpB,mBACA,SAAS,gBACT,aAAa,cACZ,QAAQ;;;;wBAgEW,KACpB,aACA,SAAS,aACT,UAAU,WACT,QAAQ;;;;qBAoFE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
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]="
|
|
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]="8149a6c4-bab0-57e3-a471-cfc77d529bbf")}catch(e){}}();
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { get } from "node:http";
|
|
5
5
|
import { get as get$1 } from "node:https";
|
|
@@ -99,4 +99,4 @@ const httpsHooksPath = import.meta.url;
|
|
|
99
99
|
export { httpsHooksPath, load, resolve };
|
|
100
100
|
|
|
101
101
|
//# sourceMappingURL=https-hooks.mjs.map
|
|
102
|
-
//# debugId=
|
|
102
|
+
//# debugId=8149a6c4-bab0-57e3-a471-cfc77d529bbf
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"https-hooks.mjs","sources":["../../../src/packages/https-hooks.mts"],"sourcesContent":["import { get as httpGet } from \"node:http\";\nimport { get } from \"node:https\";\nimport { pathToFileURL } from \"node:url\";\n\n/**\n * Node.js module loader hooks that enable importing from HTTP/HTTPS URLs.\n * See: https://nodejs.org/docs/latest-v24.x/api/module.html#import-from-https\n */\n\ntype ResolveContext = { parentURL?: string; conditions?: string[] };\ntype ResolveResult = {\n url: string;\n shortCircuit?: boolean;\n format?: string;\n};\ntype NextResolve = (\n specifier: string,\n context: ResolveContext,\n) => Promise<ResolveResult>;\n\ntype LoadContext = { format?: string };\ntype LoadResult = { format: string; shortCircuit?: boolean; source: string };\ntype NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;\n\n/**\n * Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.\n */\nexport async function resolve(\n specifier: string,\n context: ResolveContext,\n nextResolve: NextResolve,\n): Promise<ResolveResult> {\n const { parentURL } = context;\n\n // If the specifier is already an HTTP(S) URL, resolve it directly\n if (specifier.startsWith(\"https://\") || specifier.startsWith(\"http://\")) {\n return { url: specifier, shortCircuit: true, format: \"module\" };\n }\n\n // If the parent is an HTTP(S) URL and specifier is relative, resolve against it.\n // Only handle relative specifiers (./ or ../), not bare package specifiers.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\")) &&\n (specifier.startsWith(\"./\") || specifier.startsWith(\"../\"))\n ) {\n const resolved = new URL(specifier, parentURL).href;\n return { url: resolved, shortCircuit: true, format: \"module\" };\n }\n\n // Bare specifiers from HTTP modules need a node_modules root to resolve\n // against. Under pnpm's strict isolation the deps a registry-built bundle\n // needs split into two classes:\n // - Peer deps the *consumer* declared (react, react-dom, graphql, …) —\n // live at the consumer project root.\n // - Things reactor-api keeps external by design (the reactor-api package\n // itself, for class identity; internal helpers) — live in reactor-api's\n // own tree.\n // Neither root sees the other under strict mode, so try the consumer first\n // (its declared peers win on version) and fall back to reactor-api's tree.\n //\n // At this point: specifier is not an http(s):// URL (branch 1) and not\n // relative (branch 2). Only redirect bare package specifiers; let absolute\n // paths and other URL schemes (e.g. \"node:fs\", \"file://…\") fall through.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\"))\n ) {\n const isBareSpecifier =\n !specifier.startsWith(\"/\") && !/^[a-z][a-z0-9+.-]*:/i.test(specifier);\n if (isBareSpecifier) {\n const consumerRoot = pathToFileURL(process.cwd() + \"/\").href;\n try {\n return await nextResolve(specifier, {\n ...context,\n parentURL: consumerRoot,\n });\n } catch (e) {\n const code = (e as NodeJS.ErrnoException | undefined)?.code;\n if (code !== \"ERR_MODULE_NOT_FOUND\") throw e;\n return nextResolve(specifier, {\n ...context,\n parentURL: import.meta.url,\n });\n }\n }\n }\n\n // Let Node.js handle all other specifiers\n return nextResolve(specifier, context);\n}\n\n/**\n * Load hook: fetches module source from HTTP/HTTPS URLs.\n */\nexport async function load(\n url: string,\n context: LoadContext,\n nextLoad: NextLoad,\n): Promise<LoadResult> {\n // Handle HTTPS URLs\n if (url.startsWith(\"https://\")) {\n const source = await fetchModule(url, get);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Handle HTTP URLs (for local development)\n if (url.startsWith(\"http://\")) {\n const source = await fetchModule(url, httpGet);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Let Node.js handle all other URLs\n return nextLoad(url, context);\n}\n\n/**\n * Rewrite `createRequire(import.meta.url)` in HTTP-loaded modules so that\n * `createRequire` receives a local file URL instead of an HTTP URL it cannot handle.\n *\n * The base is baked in at hook time as a string literal. Injecting a live\n * `process.cwd()` call into the module source (the previous approach) crashes\n * with \"process.cwd is not a function\": HTTP-loaded modules execute in the\n * module-customization realm, which has no full `process`. This hook itself\n * runs where `process.cwd()` works, so we resolve the base here and embed the\n * resulting file URL as a literal — no runtime `process` access in the loaded\n * module. Any package whose bundle contains `createRequire(import.meta.url)`\n * (common CJS interop) failed to load before this.\n */\nfunction patchCreateRequire(source: string): string {\n const requireBase = pathToFileURL(process.cwd() + \"/\").href;\n return source.replace(\n /createRequire\\(import\\.meta\\.url\\)/g,\n `createRequire(${JSON.stringify(requireBase)})`,\n );\n}\n\nfunction fetchModule(\n url: string,\n getter: typeof get | typeof httpGet,\n): Promise<string> {\n return new Promise((resolve, reject) => {\n getter(url, (res) => {\n // Handle redirects\n if (\n res.statusCode &&\n res.statusCode >= 300 &&\n res.statusCode < 400 &&\n res.headers.location\n ) {\n const redirectUrl = res.headers.location;\n const redirectGetter = redirectUrl.startsWith(\"https://\")\n ? get\n : httpGet;\n fetchModule(redirectUrl, redirectGetter).then(resolve).catch(reject);\n return;\n }\n\n if (res.statusCode && res.statusCode >= 400) {\n reject(new Error(`Failed to fetch ${url}: ${res.statusCode}`));\n return;\n }\n\n let data = \"\";\n res.setEncoding(\"utf8\");\n res.on(\"data\", (chunk) => (data += chunk));\n res.on(\"end\", () => resolve(data));\n res.on(\"error\", reject);\n }).on(\"error\", reject);\n });\n}\n\n/**\n * Path to this hooks file for use with node:module register()\n */\nexport const httpsHooksPath: string = import.meta.url;\n"],"names":["get","httpGet"],"mappings":";;;;;;;;;AA2BA,eAAsB,QACpB,WACA,SACA,aACwB;CACxB,MAAM,EAAE,cAAc;
|
|
1
|
+
{"version":3,"file":"https-hooks.mjs","sources":["../../../src/packages/https-hooks.mts"],"sourcesContent":["import { get as httpGet } from \"node:http\";\nimport { get } from \"node:https\";\nimport { pathToFileURL } from \"node:url\";\n\n/**\n * Node.js module loader hooks that enable importing from HTTP/HTTPS URLs.\n * See: https://nodejs.org/docs/latest-v24.x/api/module.html#import-from-https\n */\n\ntype ResolveContext = { parentURL?: string; conditions?: string[] };\ntype ResolveResult = {\n url: string;\n shortCircuit?: boolean;\n format?: string;\n};\ntype NextResolve = (\n specifier: string,\n context: ResolveContext,\n) => Promise<ResolveResult>;\n\ntype LoadContext = { format?: string };\ntype LoadResult = { format: string; shortCircuit?: boolean; source: string };\ntype NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;\n\n/**\n * Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.\n */\nexport async function resolve(\n specifier: string,\n context: ResolveContext,\n nextResolve: NextResolve,\n): Promise<ResolveResult> {\n const { parentURL } = context;\n\n // If the specifier is already an HTTP(S) URL, resolve it directly\n if (specifier.startsWith(\"https://\") || specifier.startsWith(\"http://\")) {\n return { url: specifier, shortCircuit: true, format: \"module\" };\n }\n\n // If the parent is an HTTP(S) URL and specifier is relative, resolve against it.\n // Only handle relative specifiers (./ or ../), not bare package specifiers.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\")) &&\n (specifier.startsWith(\"./\") || specifier.startsWith(\"../\"))\n ) {\n const resolved = new URL(specifier, parentURL).href;\n return { url: resolved, shortCircuit: true, format: \"module\" };\n }\n\n // Bare specifiers from HTTP modules need a node_modules root to resolve\n // against. Under pnpm's strict isolation the deps a registry-built bundle\n // needs split into two classes:\n // - Peer deps the *consumer* declared (react, react-dom, graphql, …) —\n // live at the consumer project root.\n // - Things reactor-api keeps external by design (the reactor-api package\n // itself, for class identity; internal helpers) — live in reactor-api's\n // own tree.\n // Neither root sees the other under strict mode, so try the consumer first\n // (its declared peers win on version) and fall back to reactor-api's tree.\n //\n // At this point: specifier is not an http(s):// URL (branch 1) and not\n // relative (branch 2). Only redirect bare package specifiers; let absolute\n // paths and other URL schemes (e.g. \"node:fs\", \"file://…\") fall through.\n if (\n parentURL &&\n (parentURL.startsWith(\"https://\") || parentURL.startsWith(\"http://\"))\n ) {\n const isBareSpecifier =\n !specifier.startsWith(\"/\") && !/^[a-z][a-z0-9+.-]*:/i.test(specifier);\n if (isBareSpecifier) {\n const consumerRoot = pathToFileURL(process.cwd() + \"/\").href;\n try {\n return await nextResolve(specifier, {\n ...context,\n parentURL: consumerRoot,\n });\n } catch (e) {\n const code = (e as NodeJS.ErrnoException | undefined)?.code;\n if (code !== \"ERR_MODULE_NOT_FOUND\") throw e;\n return nextResolve(specifier, {\n ...context,\n parentURL: import.meta.url,\n });\n }\n }\n }\n\n // Let Node.js handle all other specifiers\n return nextResolve(specifier, context);\n}\n\n/**\n * Load hook: fetches module source from HTTP/HTTPS URLs.\n */\nexport async function load(\n url: string,\n context: LoadContext,\n nextLoad: NextLoad,\n): Promise<LoadResult> {\n // Handle HTTPS URLs\n if (url.startsWith(\"https://\")) {\n const source = await fetchModule(url, get);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Handle HTTP URLs (for local development)\n if (url.startsWith(\"http://\")) {\n const source = await fetchModule(url, httpGet);\n return {\n format: \"module\",\n shortCircuit: true,\n source: patchCreateRequire(source),\n };\n }\n\n // Let Node.js handle all other URLs\n return nextLoad(url, context);\n}\n\n/**\n * Rewrite `createRequire(import.meta.url)` in HTTP-loaded modules so that\n * `createRequire` receives a local file URL instead of an HTTP URL it cannot handle.\n *\n * The base is baked in at hook time as a string literal. Injecting a live\n * `process.cwd()` call into the module source (the previous approach) crashes\n * with \"process.cwd is not a function\": HTTP-loaded modules execute in the\n * module-customization realm, which has no full `process`. This hook itself\n * runs where `process.cwd()` works, so we resolve the base here and embed the\n * resulting file URL as a literal — no runtime `process` access in the loaded\n * module. Any package whose bundle contains `createRequire(import.meta.url)`\n * (common CJS interop) failed to load before this.\n */\nfunction patchCreateRequire(source: string): string {\n const requireBase = pathToFileURL(process.cwd() + \"/\").href;\n return source.replace(\n /createRequire\\(import\\.meta\\.url\\)/g,\n `createRequire(${JSON.stringify(requireBase)})`,\n );\n}\n\nfunction fetchModule(\n url: string,\n getter: typeof get | typeof httpGet,\n): Promise<string> {\n return new Promise((resolve, reject) => {\n getter(url, (res) => {\n // Handle redirects\n if (\n res.statusCode &&\n res.statusCode >= 300 &&\n res.statusCode < 400 &&\n res.headers.location\n ) {\n const redirectUrl = res.headers.location;\n const redirectGetter = redirectUrl.startsWith(\"https://\")\n ? get\n : httpGet;\n fetchModule(redirectUrl, redirectGetter).then(resolve).catch(reject);\n return;\n }\n\n if (res.statusCode && res.statusCode >= 400) {\n reject(new Error(`Failed to fetch ${url}: ${res.statusCode}`));\n return;\n }\n\n let data = \"\";\n res.setEncoding(\"utf8\");\n res.on(\"data\", (chunk) => (data += chunk));\n res.on(\"end\", () => resolve(data));\n res.on(\"error\", reject);\n }).on(\"error\", reject);\n });\n}\n\n/**\n * Path to this hooks file for use with node:module register()\n */\nexport const httpsHooksPath: string = import.meta.url;\n"],"names":["get","httpGet"],"mappings":";;;;;;;;;AA2BA,eAAsB,QACpB,WACA,SACA,aACwB;CACxB,MAAM,EAAE,cAAc;CAGtB,IAAI,UAAU,WAAW,UAAU,KAAK,UAAU,WAAW,SAAS,GACpE,OAAO;EAAE,KAAK;EAAW,cAAc;EAAM,QAAQ;CAAS;CAKhE,IACE,cACC,UAAU,WAAW,UAAU,KAAK,UAAU,WAAW,SAAS,OAClE,UAAU,WAAW,IAAI,KAAK,UAAU,WAAW,KAAK,IAGzD,OAAO;EAAE,KADQ,IAAI,IAAI,WAAW,SAAS,CAAC,CAAC;EACvB,cAAc;EAAM,QAAQ;CAAS;CAiB/D,IACE,cACC,UAAU,WAAW,UAAU,KAAK,UAAU,WAAW,SAAS,IAGjE;MAAA,CAAC,UAAU,WAAW,GAAG,KAAK,CAAC,uBAAuB,KAAK,SAAS,GACjD;GACnB,MAAM,eAAe,cAAc,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC;GACxD,IAAI;IACF,OAAO,MAAM,YAAY,WAAW;KAClC,GAAG;KACH,WAAW;IACb,CAAC;GACH,SAAS,GAAG;IAEV,IADc,GAAyC,SAC1C,wBAAwB,MAAM;IAC3C,OAAO,YAAY,WAAW;KAC5B,GAAG;KACH,WAAW,YAAY;IACzB,CAAC;GACH;EACF;;CAIF,OAAO,YAAY,WAAW,OAAO;AACvC;;;;AAKA,eAAsB,KACpB,KACA,SACA,UACqB;CAErB,IAAI,IAAI,WAAW,UAAU,GAE3B,OAAO;EACL,QAAQ;EACR,cAAc;EACd,QAAQ,mBAAmB,MAJR,YAAY,KAAKA,KAAG,CAIN;CACnC;CAIF,IAAI,IAAI,WAAW,SAAS,GAE1B,OAAO;EACL,QAAQ;EACR,cAAc;EACd,QAAQ,mBAAmB,MAJR,YAAY,KAAKC,GAAO,CAIV;CACnC;CAIF,OAAO,SAAS,KAAK,OAAO;AAC9B;;;;;;;;;;;;;;AAeA,SAAS,mBAAmB,QAAwB;CAClD,MAAM,cAAc,cAAc,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC;CACvD,OAAO,OAAO,QACZ,uCACA,iBAAiB,KAAK,UAAU,WAAW,EAAE,EAC/C;AACF;AAEA,SAAS,YACP,KACA,QACiB;CACjB,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,OAAO,MAAM,QAAQ;GAEnB,IACE,IAAI,cACJ,IAAI,cAAc,OAClB,IAAI,aAAa,OACjB,IAAI,QAAQ,UACZ;IACA,MAAM,cAAc,IAAI,QAAQ;IAIhC,YAAY,aAHW,YAAY,WAAW,UAAU,IACpDD,QACAC,GACmC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,MAAM,MAAM;IACnE;GACF;GAEA,IAAI,IAAI,cAAc,IAAI,cAAc,KAAK;IAC3C,uBAAO,IAAI,MAAM,mBAAmB,IAAI,IAAI,IAAI,YAAY,CAAC;IAC7D;GACF;GAEA,IAAI,OAAO;GACX,IAAI,YAAY,MAAM;GACtB,IAAI,GAAG,SAAS,UAAW,QAAQ,KAAM;GACzC,IAAI,GAAG,aAAa,QAAQ,IAAI,CAAC;GACjC,IAAI,GAAG,SAAS,MAAM;EACxB,CAAC,CAAC,CAAC,GAAG,SAAS,MAAM;CACvB,CAAC;AACH;;;;AAKA,MAAa,iBAAyB,YAAY","debug_id":"8149a6c4-bab0-57e3-a471-cfc77d529bbf"}
|
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ILogger } from "document-model";
|
|
1
|
+
import { d as ReportError, o as ISubscribablePackageLoader, s as ISubscriptionOptions, u as PackagePieceEntry } from "../../types-CCI5IDgT.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
|
-
|
|
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
|
+
reportError?: ReportError;
|
|
13
|
+
}
|
|
14
|
+
export declare class VitePackageLoader implements ISubscribablePackageLoader {
|
|
10
15
|
#private;
|
|
11
16
|
private readonly logger;
|
|
12
17
|
private readonly vite;
|
|
18
|
+
private readonly importers;
|
|
13
19
|
readonly name = "VitePackageLoader";
|
|
14
|
-
static build(vite: ViteDevServer): VitePackageLoader;
|
|
15
|
-
constructor(vite: ViteDevServer);
|
|
20
|
+
static build(vite: ViteDevServer, options?: VitePackageLoaderOptions): VitePackageLoader;
|
|
21
|
+
constructor(vite: ViteDevServer, options?: VitePackageLoaderOptions);
|
|
16
22
|
private getDocumentModelsPath;
|
|
17
23
|
private getSubgraphsPath;
|
|
18
24
|
private getProcessorsPath;
|
|
19
|
-
|
|
25
|
+
private getPiecesPath;
|
|
26
|
+
private aliasedRoot;
|
|
27
|
+
private pieceRoot;
|
|
28
|
+
loadDocumentModels(identifier: string): Promise<DocumentModelModule[]>;
|
|
20
29
|
loadUpgradeManifests(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
|
|
21
30
|
loadSubgraphs(identifier: string): Promise<SubgraphClass[]>;
|
|
22
31
|
loadProcessors(identifier: string): Promise<ProcessorFactoryBuilder | null>;
|
|
32
|
+
loadPieces(identifier: string): Promise<PackagePieceEntry[]>;
|
|
23
33
|
onDocumentModelsChange(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
|
|
24
34
|
onSubgraphsChange(identifier: string, handler: (subgraphs: SubgraphClass[]) => void, options?: ISubscriptionOptions): () => void;
|
|
25
35
|
onProcessorsChange(identifier: string, handler: (processors: ProcessorFactoryBuilder | null) => void, options?: ISubscriptionOptions): () => void;
|
|
36
|
+
onPiecesChange(identifier: string, handler: (pieces: PackagePieceEntry[]) => void, options?: ISubscriptionOptions): () => void;
|
|
26
37
|
}
|
|
27
|
-
declare function startViteServer(root: string, logger?: Logger): Promise<ViteDevServer>;
|
|
38
|
+
export declare function startViteServer(root: string, logger?: Logger): Promise<ViteDevServer>;
|
|
28
39
|
//#endregion
|
|
29
|
-
export {
|
|
40
|
+
export {};
|
|
30
41
|
//# sourceMappingURL=vite-loader.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;wBAqCgB,iBAAiB,QAAQ,SAAS,kBAAW;iBA2B5C;;;EAGf;EACA,cAAc;;qBAQH,6BAA6B;;mBACvB;mBAEA;mBAEA;WAIR;SAEF,MAAM,MAAM,eAAe,UAAU,2BAAwB;EAIpE,YAAY,MAAM,eAAe,UAAS;UA+DlC;UAIA;UAIA;UAIA;UAMA;UASA;EAcF,mBAAmB,qBAAqB,QAAQ;EAehD,qBACJ,qBACC,QAAQ;EAoBL,cAAc,qBAAqB,QAAQ;EAiB3C,eACJ,qBACC,QAAQ;EAkBL,WAAW,qBAAqB,QAAQ;EAmE9C,uBACE,oBACA,UAAU,gBAAgB,gCAC1B,UAAU;EAYZ,kBACE,oBACA,UAAU,WAAW,0BACrB,UAAU;EAYZ,mBACE,oBACA,UAAU,YAAY,yCACtB,UAAU;EAYZ,eACE,oBACA,UAAU,QAAQ,8BAClB,UAAU;;wBAmBQ,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]="
|
|
3
|
-
import { a as
|
|
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]="617a3ed8-6fe0-5cfb-b6f9-2d2ab2656cc3")}catch(e){}}();
|
|
3
|
+
import { _ as PACKAGE_MODULE_FAILED, a as packageRootOf, b as isSubpath, c as piecesFromListModule, g as runDetached, l as extractDocumentModels, n as BUILT_PIECE_LIST, o as pieceListLocation, r as PIECES_SUBPATH, t as extractSubgraphs, v as debounce, y as extractUpgradeManifests } from "../../subgraph-extraction-cSpPp3Hq.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,45 @@ function createViteLogger(logger, prefix = "") {
|
|
|
17
18
|
var VitePackageLoader = class VitePackageLoader {
|
|
18
19
|
logger = childLogger(["reactor-api", "vite-loader"]);
|
|
19
20
|
vite;
|
|
21
|
+
importers;
|
|
22
|
+
#reportError;
|
|
20
23
|
name = "VitePackageLoader";
|
|
21
|
-
static build(vite) {
|
|
22
|
-
return new VitePackageLoader(vite);
|
|
24
|
+
static build(vite, options) {
|
|
25
|
+
return new VitePackageLoader(vite, options);
|
|
23
26
|
}
|
|
24
|
-
constructor(vite) {
|
|
27
|
+
constructor(vite, options = {}) {
|
|
25
28
|
this.vite = vite;
|
|
29
|
+
this.importers = [...options.resolveFrom ?? [], import.meta.url].map((from) => from.startsWith("file:") ? fileURLToPath(from) : from);
|
|
30
|
+
this.#reportError = options.reportError;
|
|
31
|
+
}
|
|
32
|
+
async #resolve(identifier, subpath) {
|
|
33
|
+
const aliased = path.isAbsolute(identifier) ? void 0 : this.aliasedRoot(identifier);
|
|
34
|
+
const specifier = path.posix.join(aliased ?? identifier, subpath);
|
|
35
|
+
const importers = !aliased && !path.isAbsolute(identifier) ? [void 0, ...this.importers] : [void 0];
|
|
36
|
+
const container = this.vite.environments.ssr.pluginContainer;
|
|
37
|
+
for (const importer of importers) try {
|
|
38
|
+
const resolved = await container.resolveId(specifier, importer);
|
|
39
|
+
if (resolved && !resolved.external) return resolved.id;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
this.logger.debug("Could not resolve @specifier: @error", specifier, e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async #load(identifier, subpath) {
|
|
45
|
+
const id = await this.#resolve(identifier, subpath);
|
|
46
|
+
if (id === void 0) {
|
|
47
|
+
this.logger.debug("No @subpath module in @pkg", subpath, identifier);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return {
|
|
52
|
+
id,
|
|
53
|
+
namespace: await this.vite.ssrLoadModule(id)
|
|
54
|
+
};
|
|
55
|
+
} catch (e) {
|
|
56
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
57
|
+
this.logger.error("Failed to load @subpath of @pkg from @id: @error", subpath, identifier, id, message);
|
|
58
|
+
throw Object.assign(new Error(`Failed to load ${id}: ${message}`, { cause: e }), { code: PACKAGE_MODULE_FAILED });
|
|
59
|
+
}
|
|
26
60
|
}
|
|
27
61
|
getDocumentModelsPath(identifier) {
|
|
28
62
|
return path.posix.join(identifier, "./document-models");
|
|
@@ -33,114 +67,132 @@ var VitePackageLoader = class VitePackageLoader {
|
|
|
33
67
|
getProcessorsPath(identifier) {
|
|
34
68
|
return path.posix.join(identifier, "./processors");
|
|
35
69
|
}
|
|
36
|
-
|
|
37
|
-
return
|
|
70
|
+
getPiecesPath(identifier) {
|
|
71
|
+
return path.posix.join(identifier, `./${PIECES_SUBPATH}`);
|
|
72
|
+
}
|
|
73
|
+
aliasedRoot(identifier) {
|
|
74
|
+
const alias = this.vite.config.resolve.alias;
|
|
75
|
+
const hit = (Array.isArray(alias) ? alias : []).find((entry) => entry.find === identifier);
|
|
76
|
+
return typeof hit?.replacement === "string" ? hit.replacement : void 0;
|
|
38
77
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
78
|
+
pieceRoot(identifier, listId) {
|
|
79
|
+
if (!path.isAbsolute(identifier)) {
|
|
80
|
+
const aliased = this.aliasedRoot(identifier);
|
|
81
|
+
if (aliased) return aliased;
|
|
82
|
+
if (listId) return packageRootOf(path.dirname(listId));
|
|
83
|
+
}
|
|
43
84
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
85
|
+
return pieceListLocation(identifier).root;
|
|
86
|
+
} catch {
|
|
87
|
+
return;
|
|
52
88
|
}
|
|
53
|
-
|
|
89
|
+
}
|
|
90
|
+
async loadDocumentModels(identifier) {
|
|
91
|
+
this.logger.debug("Loading document models from", this.getDocumentModelsPath(identifier));
|
|
92
|
+
const loaded = await this.#load(identifier, "document-models");
|
|
93
|
+
if (!loaded) return [];
|
|
94
|
+
const documentModels = extractDocumentModels(loaded.namespace);
|
|
95
|
+
this.logger.verbose(` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`);
|
|
96
|
+
return documentModels;
|
|
54
97
|
}
|
|
55
98
|
async loadUpgradeManifests(identifier) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
99
|
+
for (const subpath of ["document-models", "document-models/upgrade-manifests"]) {
|
|
100
|
+
const loaded = await this.#load(identifier, subpath);
|
|
101
|
+
if (!loaded) continue;
|
|
102
|
+
const manifests = extractUpgradeManifests(loaded.namespace);
|
|
59
103
|
if (manifests.length > 0) {
|
|
60
104
|
this.logger.verbose(` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`);
|
|
61
105
|
return manifests;
|
|
62
106
|
}
|
|
63
|
-
} catch (e) {
|
|
64
|
-
this.logger.debug(` ➜ No Upgrade Manifests found at ${fullPath} for: ${identifier}`, e);
|
|
65
107
|
}
|
|
66
108
|
return [];
|
|
67
109
|
}
|
|
68
110
|
async loadSubgraphs(identifier) {
|
|
69
|
-
|
|
70
|
-
this
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
localSubgraphs = await this.vite.ssrLoadModule(fullPath);
|
|
74
|
-
} catch (e) {
|
|
75
|
-
this.logger.debug(` ➜ No Subgraphs found for: ${identifier}`, e);
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const subgraphs = [];
|
|
79
|
-
for (const [name, subgraph] of Object.entries(localSubgraphs)) {
|
|
80
|
-
const SubgraphClass = subgraph[name];
|
|
81
|
-
if (isSubgraphClass(SubgraphClass)) subgraphs.push(SubgraphClass);
|
|
82
|
-
}
|
|
111
|
+
this.logger.verbose("Loading subgraphs from", this.getSubgraphsPath(identifier));
|
|
112
|
+
const loaded = await this.#load(identifier, "subgraphs");
|
|
113
|
+
if (!loaded) return [];
|
|
114
|
+
const subgraphs = extractSubgraphs(loaded.namespace);
|
|
83
115
|
this.logger.debug(` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`);
|
|
84
116
|
return subgraphs;
|
|
85
117
|
}
|
|
86
118
|
async loadProcessors(identifier) {
|
|
87
|
-
|
|
88
|
-
this
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
119
|
+
this.logger.verbose("Loading processors from", this.getProcessorsPath(identifier));
|
|
120
|
+
const factory = (await this.#load(identifier, "processors"))?.namespace.processorFactory;
|
|
121
|
+
if (typeof factory === "function") {
|
|
122
|
+
this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);
|
|
123
|
+
return factory;
|
|
97
124
|
}
|
|
98
125
|
this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);
|
|
99
126
|
return null;
|
|
100
127
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
async loadPieces(identifier) {
|
|
129
|
+
this.logger.verbose("Loading pieces from", this.getPiecesPath(identifier));
|
|
130
|
+
const loaded = await this.#load(identifier, PIECES_SUBPATH);
|
|
131
|
+
if (!loaded) return [];
|
|
132
|
+
const root = this.pieceRoot(identifier, loaded.id);
|
|
133
|
+
if (root === void 0) {
|
|
134
|
+
this.logger.debug(` ➜ No package root found for: ${identifier}`);
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const pieces = piecesFromListModule(loaded.namespace, {
|
|
138
|
+
root,
|
|
139
|
+
identifier,
|
|
140
|
+
logger: this.logger
|
|
141
|
+
});
|
|
142
|
+
this.logger.debug(` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`);
|
|
143
|
+
return pieces;
|
|
144
|
+
}
|
|
145
|
+
#watch(label, matches, load, handler, options) {
|
|
146
|
+
let subscribed = true;
|
|
147
|
+
const reloadOnce = debounce(() => runDetached(label, async () => {
|
|
148
|
+
if (!subscribed) return;
|
|
149
|
+
let value;
|
|
150
|
+
try {
|
|
151
|
+
value = await load();
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (e.code === "ERR_PACKAGE_MODULE_FAILED") return;
|
|
154
|
+
throw e;
|
|
155
|
+
}
|
|
156
|
+
if (subscribed) handler(value);
|
|
157
|
+
}, {
|
|
158
|
+
logger: this.logger,
|
|
159
|
+
report: this.#reportError
|
|
160
|
+
}), options?.debounce ?? 100);
|
|
161
|
+
const listener = (changedPath) => {
|
|
162
|
+
if (matches(changedPath)) reloadOnce();
|
|
104
163
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
164
|
+
const events = [
|
|
165
|
+
"change",
|
|
166
|
+
"add",
|
|
167
|
+
"unlink"
|
|
168
|
+
];
|
|
169
|
+
for (const event of events) this.vite.watcher.on(event, listener);
|
|
108
170
|
return () => {
|
|
109
|
-
|
|
110
|
-
this.vite.watcher.off(
|
|
111
|
-
this.vite.watcher.off("unlink", listener);
|
|
171
|
+
subscribed = false;
|
|
172
|
+
for (const event of events) this.vite.watcher.off(event, listener);
|
|
112
173
|
};
|
|
113
174
|
}
|
|
175
|
+
onDocumentModelsChange(identifier, handler, options) {
|
|
176
|
+
const documentModelsPath = this.getDocumentModelsPath(identifier);
|
|
177
|
+
return this.#watch(`Reloading the document models of ${identifier}`, (changedPath) => isSubpath(documentModelsPath, changedPath), () => this.loadDocumentModels(identifier), handler, options);
|
|
178
|
+
}
|
|
114
179
|
onSubgraphsChange(identifier, handler, options) {
|
|
115
180
|
const subgraphsPath = this.getSubgraphsPath(identifier);
|
|
116
|
-
|
|
117
|
-
if (isSubpath(subgraphsPath, changedPath)) handler(await this.loadSubgraphs(identifier));
|
|
118
|
-
};
|
|
119
|
-
this.vite.watcher.on("change", listener);
|
|
120
|
-
this.vite.watcher.on("add", listener);
|
|
121
|
-
this.vite.watcher.on("unlink", listener);
|
|
122
|
-
return () => {
|
|
123
|
-
this.vite.watcher.off("change", listener);
|
|
124
|
-
this.vite.watcher.off("add", listener);
|
|
125
|
-
this.vite.watcher.off("unlink", listener);
|
|
126
|
-
};
|
|
181
|
+
return this.#watch(`Reloading the subgraphs of ${identifier}`, (changedPath) => isSubpath(subgraphsPath, changedPath), () => this.loadSubgraphs(identifier), handler, options);
|
|
127
182
|
}
|
|
128
183
|
onProcessorsChange(identifier, handler, options) {
|
|
129
184
|
const processorsPath = this.getProcessorsPath(identifier);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
135
|
-
|
|
136
|
-
return () =>
|
|
137
|
-
this.vite.watcher.off("change", listener);
|
|
138
|
-
this.vite.watcher.off("add", listener);
|
|
139
|
-
this.vite.watcher.off("unlink", listener);
|
|
140
|
-
};
|
|
185
|
+
return this.#watch(`Reloading the processors of ${identifier}`, (changedPath) => isSubpath(processorsPath, changedPath), () => this.loadProcessors(identifier), handler, options);
|
|
186
|
+
}
|
|
187
|
+
onPiecesChange(identifier, handler, options) {
|
|
188
|
+
const watched = [this.getPiecesPath(identifier)];
|
|
189
|
+
const root = this.pieceRoot(identifier);
|
|
190
|
+
if (root !== void 0) watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));
|
|
191
|
+
return this.#watch(`Reloading the pieces of ${identifier}`, (changedPath) => watched.some((dir) => isSubpath(dir, changedPath)), () => this.loadPieces(identifier), handler, options);
|
|
141
192
|
}
|
|
142
193
|
};
|
|
143
194
|
async function startViteServer(root, logger) {
|
|
195
|
+
const packageJson = await readPackage({ cwd: root });
|
|
144
196
|
return await createServer({
|
|
145
197
|
root,
|
|
146
198
|
configFile: false,
|
|
@@ -153,7 +205,7 @@ async function startViteServer(root, logger) {
|
|
|
153
205
|
build: { rollupOptions: { input: [] } },
|
|
154
206
|
resolve: {
|
|
155
207
|
tsconfigPaths: true,
|
|
156
|
-
alias: { [
|
|
208
|
+
alias: { [packageJson.name]: root }
|
|
157
209
|
},
|
|
158
210
|
plugins: [viteCommonjs(), {
|
|
159
211
|
name: "suppress-hmr",
|
|
@@ -167,4 +219,4 @@ async function startViteServer(root, logger) {
|
|
|
167
219
|
export { VitePackageLoader, createViteLogger, startViteServer };
|
|
168
220
|
|
|
169
221
|
//# sourceMappingURL=vite-loader.mjs.map
|
|
170
|
-
//# debugId=
|
|
222
|
+
//# debugId=617a3ed8-6fe0-5cfb-b6f9-2d2ab2656cc3
|