@powerhousedao/reactor-api 6.2.2-dev.9 → 6.2.2
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/dist/{adapter-gateway-apollo-CxV_hMTv.mjs → adapter-gateway-apollo-DdamNLPT.mjs} +10 -4
- package/dist/adapter-gateway-apollo-DdamNLPT.mjs.map +1 -0
- package/dist/adapter-http-express-CgVPgEMm.mjs +225 -0
- package/dist/adapter-http-express-CgVPgEMm.mjs.map +1 -0
- package/dist/{adapter-http-fastify-B248RJtm.mjs → adapter-http-fastify-D98iRljY.mjs} +38 -26
- package/dist/adapter-http-fastify-D98iRljY.mjs.map +1 -0
- package/dist/index.d.mts +584 -50
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1258 -174
- package/dist/index.mjs.map +1 -1
- package/dist/path-normalize-DWWFLiy6.mjs +23 -0
- package/dist/path-normalize-DWWFLiy6.mjs.map +1 -0
- package/dist/src/packages/https-hooks.mjs +1 -1
- package/dist/src/packages/vite-loader.d.mts +3 -2
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +33 -8
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/{types-DnHgkahK.d.mts → types-Bz2niABC.d.mts} +13 -2
- package/dist/types-Bz2niABC.d.mts.map +1 -0
- package/dist/{utils-iibOQ50e.mjs → utils-lHoPB-ft.mjs} +130 -23
- package/dist/utils-lHoPB-ft.mjs.map +1 -0
- package/package.json +22 -19
- package/dist/adapter-gateway-apollo-CxV_hMTv.mjs.map +0 -1
- package/dist/adapter-http-express-D5OpUIbV.mjs +0 -137
- package/dist/adapter-http-express-D5OpUIbV.mjs.map +0 -1
- package/dist/adapter-http-fastify-B248RJtm.mjs.map +0 -1
- package/dist/types-DnHgkahK.d.mts.map +0 -1
- package/dist/utils-iibOQ50e.mjs.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/graphql/gateway/path-normalize.ts
|
|
2
|
+
/**
|
|
3
|
+
* Normalises a route path for path-to-regexp v8:
|
|
4
|
+
* - Collapses duplicate slashes (e.g. "//explorer" → "/explorer")
|
|
5
|
+
* - Converts legacy optional-param syntax "/:param?" → "{/:param}". The
|
|
6
|
+
* slash must move inside the group: in p-r v8 a group whose content
|
|
7
|
+
* begins with "/" is what makes the slash and the parameter optional
|
|
8
|
+
* together, while a literal "/" left in front of the group compiles to
|
|
9
|
+
* a pattern that matches nothing (and v8 rejects a bare ":param?").
|
|
10
|
+
*
|
|
11
|
+
* Shared by both http adapters so registry dispatch matches the same path
|
|
12
|
+
* shapes regardless of which framework is in use.
|
|
13
|
+
*/
|
|
14
|
+
|
|
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]="f2d4c602-31b8-5f1c-aa79-49d1d196b0c0")}catch(e){}}();
|
|
16
|
+
function normalizePath(path) {
|
|
17
|
+
return path.replace(/\/+/g, "/").replace(/\/:(\w+)\?/g, "{/:$1}");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { normalizePath as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=path-normalize-DWWFLiy6.mjs.map
|
|
23
|
+
//# debugId=f2d4c602-31b8-5f1c-aa79-49d1d196b0c0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-normalize-DWWFLiy6.mjs","sources":["../src/graphql/gateway/path-normalize.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"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,SAAgB,cAAc,MAAsB;AAClD,QAAO,KAAK,QAAQ,QAAQ,IAAI,CAAC,QAAQ,eAAe,SAAS","debug_id":"f2d4c602-31b8-5f1c-aa79-49d1d196b0c0"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
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]="c7cff29c-399f-5fdb-84b9-d0be2e6093bb")}catch(e){}}();
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
3
4
|
import { get } from "node:http";
|
|
4
5
|
import { get as get$1 } from "node:https";
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
6
|
//#region src/packages/https-hooks.mts
|
|
7
7
|
/**
|
|
8
8
|
* Resolve hook: resolves relative specifiers against HTTP/HTTPS parent URLs.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as ISubscribablePackageLoader, o as ISubscriptionOptions } from "../../types-
|
|
1
|
+
import { a as ISubscribablePackageLoader, o as ISubscriptionOptions } from "../../types-Bz2niABC.mjs";
|
|
2
2
|
import { ILogger } from "document-model";
|
|
3
|
-
import { DocumentModelModule } from "@powerhousedao/shared/document-model";
|
|
3
|
+
import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
4
4
|
import { Logger, ViteDevServer } from "vite";
|
|
5
5
|
import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
|
|
6
6
|
|
|
@@ -17,6 +17,7 @@ declare class VitePackageLoader implements ISubscribablePackageLoader {
|
|
|
17
17
|
private getSubgraphsPath;
|
|
18
18
|
private getProcessorsPath;
|
|
19
19
|
loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
|
|
20
|
+
loadUpgradeManifests(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
|
|
20
21
|
loadSubgraphs(identifier: string): Promise<SubgraphClass[]>;
|
|
21
22
|
loadProcessors(identifier: string): Promise<ProcessorFactoryBuilder | null>;
|
|
22
23
|
onDocumentModelsChange(identifier: string, handler: (documentModels: DocumentModelModule[]) => void, options?: ISubscriptionOptions): () => void;
|
|
@@ -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":";;;;;;;iBAqBgB,gBAAA,CAAiB,MAAA,EAAQ,OAAA,EAAS,MAAA,YAAW,MAAA;AAAA,cAUhD,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,6 +1,6 @@
|
|
|
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 isSubgraphClass, o as debounce, s 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]="e3971ec2-a824-5da6-9a2a-805e72db81bf")}catch(e){}}();
|
|
3
|
+
import { a as isSubgraphClass, c as isSubpath, o as debounce, s as extractUpgradeManifests } from "../../utils-lHoPB-ft.mjs";
|
|
4
4
|
import { childLogger } from "document-model";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
@@ -25,13 +25,13 @@ var VitePackageLoader = class VitePackageLoader {
|
|
|
25
25
|
this.vite = vite;
|
|
26
26
|
}
|
|
27
27
|
getDocumentModelsPath(identifier) {
|
|
28
|
-
return path.join(identifier, "./document-models");
|
|
28
|
+
return path.posix.join(identifier, "./document-models");
|
|
29
29
|
}
|
|
30
30
|
getSubgraphsPath(identifier) {
|
|
31
|
-
return path.join(identifier, "./subgraphs");
|
|
31
|
+
return path.posix.join(identifier, "./subgraphs");
|
|
32
32
|
}
|
|
33
33
|
getProcessorsPath(identifier) {
|
|
34
|
-
return path.join(identifier, "./processors");
|
|
34
|
+
return path.posix.join(identifier, "./processors");
|
|
35
35
|
}
|
|
36
36
|
loadDocumentModels(identifier, immediate = false) {
|
|
37
37
|
return this.#loadDocumentModelsWithDebounce(immediate, identifier);
|
|
@@ -52,6 +52,19 @@ var VitePackageLoader = class VitePackageLoader {
|
|
|
52
52
|
}
|
|
53
53
|
return [];
|
|
54
54
|
}
|
|
55
|
+
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));
|
|
59
|
+
if (manifests.length > 0) {
|
|
60
|
+
this.logger.verbose(` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`);
|
|
61
|
+
return manifests;
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
this.logger.debug(` ➜ No Upgrade Manifests found at ${fullPath} for: ${identifier}`, e);
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
55
68
|
async loadSubgraphs(identifier) {
|
|
56
69
|
const fullPath = this.getSubgraphsPath(identifier);
|
|
57
70
|
this.logger.verbose("Loading subgraphs from", fullPath);
|
|
@@ -90,18 +103,26 @@ var VitePackageLoader = class VitePackageLoader {
|
|
|
90
103
|
if (isSubpath(this.getDocumentModelsPath(identifier), changedPath)) handler(await this.loadDocumentModels(identifier));
|
|
91
104
|
};
|
|
92
105
|
this.vite.watcher.on("change", listener);
|
|
106
|
+
this.vite.watcher.on("add", listener);
|
|
107
|
+
this.vite.watcher.on("unlink", listener);
|
|
93
108
|
return () => {
|
|
94
109
|
this.vite.watcher.off("change", listener);
|
|
110
|
+
this.vite.watcher.off("add", listener);
|
|
111
|
+
this.vite.watcher.off("unlink", listener);
|
|
95
112
|
};
|
|
96
113
|
}
|
|
97
114
|
onSubgraphsChange(identifier, handler, options) {
|
|
98
115
|
const subgraphsPath = this.getSubgraphsPath(identifier);
|
|
99
|
-
const listener =
|
|
116
|
+
const listener = async (changedPath) => {
|
|
100
117
|
if (isSubpath(subgraphsPath, changedPath)) handler(await this.loadSubgraphs(identifier));
|
|
101
|
-
}
|
|
118
|
+
};
|
|
102
119
|
this.vite.watcher.on("change", listener);
|
|
120
|
+
this.vite.watcher.on("add", listener);
|
|
121
|
+
this.vite.watcher.on("unlink", listener);
|
|
103
122
|
return () => {
|
|
104
123
|
this.vite.watcher.off("change", listener);
|
|
124
|
+
this.vite.watcher.off("add", listener);
|
|
125
|
+
this.vite.watcher.off("unlink", listener);
|
|
105
126
|
};
|
|
106
127
|
}
|
|
107
128
|
onProcessorsChange(identifier, handler, options) {
|
|
@@ -110,8 +131,12 @@ var VitePackageLoader = class VitePackageLoader {
|
|
|
110
131
|
if (isSubpath(processorsPath, changedPath)) handler(await this.loadProcessors(identifier));
|
|
111
132
|
};
|
|
112
133
|
this.vite.watcher.on("change", listener);
|
|
134
|
+
this.vite.watcher.on("add", listener);
|
|
135
|
+
this.vite.watcher.on("unlink", listener);
|
|
113
136
|
return () => {
|
|
114
137
|
this.vite.watcher.off("change", listener);
|
|
138
|
+
this.vite.watcher.off("add", listener);
|
|
139
|
+
this.vite.watcher.off("unlink", listener);
|
|
115
140
|
};
|
|
116
141
|
}
|
|
117
142
|
};
|
|
@@ -142,4 +167,4 @@ async function startViteServer(root, logger) {
|
|
|
142
167
|
export { VitePackageLoader, createViteLogger, startViteServer };
|
|
143
168
|
|
|
144
169
|
//# sourceMappingURL=vite-loader.mjs.map
|
|
145
|
-
//# debugId=
|
|
170
|
+
//# debugId=e3971ec2-a824-5da6-9a2a-805e72db81bf
|
|
@@ -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 { DocumentModelModule } 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, isSubpath } from \"./util.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n customLogger.info = logger.info;\n customLogger.warn = logger.warn;\n customLogger.error = logger.error;\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.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.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 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 this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", 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 = debounce(async (changedPath: string) => {\n if (isSubpath(subgraphsPath, changedPath)) {\n const subgraphs = await this.loadSubgraphs(identifier);\n handler(subgraphs);\n }\n }, options?.debounce ?? 100);\n this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", 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 this.vite.watcher.on(\"change\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", 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":";;;;;;;;;AAkBA,SAAgB,iBAAiB,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,UAAU,SAAS;AAExC,eAAa;AACX,QAAK,KAAK,QAAQ,IAAI,UAAU,SAAS;;;CAI7C,mBACE,YACA,SACA,SACY;EACZ,MAAM,iBAAiB,KAAK,kBAAkB,WAAW;EACzD,MAAM,WAAW,OAAO,gBAAwB;AAC9C,OAAI,UAAU,gBAAgB,YAAY,CAExC,SADmB,MAAM,KAAK,eAAe,WAAW,CACrC;;AAGvB,OAAK,KAAK,QAAQ,GAAG,UAAU,SAAS;AAExC,eAAa;AACX,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":"02fc7276-e4d6-5195-b4ce-5791df961225"}
|
|
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 customLogger.info = logger.info;\n customLogger.warn = logger.warn;\n customLogger.error = logger.error;\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;AACF,cAAa,OAAO,OAAO;AAC3B,cAAa,OAAO,OAAO;AAC3B,cAAa,QAAQ,OAAO;AAC5B,QAAO;;AAGT,IAAa,oBAAb,MAAa,kBAAwD;CACnE,SAA0B,YAAY,CAAC,eAAe,cAAc,CAAC;CAErE;CAEA,OAAgB;CAEhB,OAAO,MAAM,MAAqB;AAChC,SAAO,IAAI,kBAAkB,KAAK;;CAGpC,YAAY,MAAqB;AAC/B,OAAK,OAAO;;CAGd,sBAA8B,YAA4B;AACxD,SAAO,KAAK,MAAM,KAAK,YAAY,oBAAoB;;CAGzD,iBAAyB,YAA4B;AACnD,SAAO,KAA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CAAC","debug_id":"e3971ec2-a824-5da6-9a2a-805e72db81bf"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { ILogger } from "document-model";
|
|
2
|
-
import { DocumentModelModule } from "@powerhousedao/shared/document-model";
|
|
2
|
+
import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
3
3
|
import { ProcessorFactoryBuilder, SubgraphClass } from "@powerhousedao/reactor-api";
|
|
4
4
|
|
|
5
5
|
//#region src/packages/types.d.ts
|
|
6
6
|
interface IPackageLoader {
|
|
7
7
|
name: string;
|
|
8
8
|
loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Loads the upgrade manifests a package exports alongside its document
|
|
11
|
+
* models. Optional: loaders that predate versioned models may omit it.
|
|
12
|
+
*/
|
|
13
|
+
loadUpgradeManifests?(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
|
|
9
14
|
loadSubgraphs(identifier: string, immediate?: boolean): Promise<SubgraphClass[]>;
|
|
10
15
|
loadProcessors(identifier: string, immediate?: boolean): Promise<ProcessorFactoryBuilder | null>;
|
|
11
16
|
}
|
|
@@ -19,6 +24,11 @@ interface ISubscribablePackageLoader extends IPackageLoader {
|
|
|
19
24
|
}
|
|
20
25
|
interface IPackageManager {
|
|
21
26
|
onDocumentModelsChange(handler: (documentModels: Record<string, DocumentModelModule[]>) => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Remove a package from all package maps and emit the change events.
|
|
29
|
+
* Used when a dynamically installed package is uninstalled.
|
|
30
|
+
*/
|
|
31
|
+
removePackage(packageName: string): void;
|
|
22
32
|
}
|
|
23
33
|
type IPackageLoaderOptions = {
|
|
24
34
|
logger?: ILogger;
|
|
@@ -29,9 +39,10 @@ type IPackageManagerOptions = {
|
|
|
29
39
|
};
|
|
30
40
|
type PackageManagerResult = {
|
|
31
41
|
documentModels: DocumentModelModule[];
|
|
42
|
+
upgradeManifests: UpgradeManifest<readonly number[]>[];
|
|
32
43
|
subgraphs: Map<string, SubgraphClass[]>;
|
|
33
44
|
processors: Map<string, ProcessorFactoryBuilder[]>;
|
|
34
45
|
};
|
|
35
46
|
//#endregion
|
|
36
47
|
export { ISubscribablePackageLoader as a, IPackageManagerOptions as i, IPackageLoaderOptions as n, ISubscriptionOptions as o, IPackageManager as r, PackageManagerResult as s, IPackageLoader as t };
|
|
37
|
-
//# sourceMappingURL=types-
|
|
48
|
+
//# sourceMappingURL=types-Bz2niABC.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Bz2niABC.d.mts","names":[],"sources":["../src/packages/types.ts"],"mappings":";;;;;UAUiB,cAAA;EACf,IAAA;EACA,kBAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,mBAAA;EALkB;;;;EAU7B,oBAAA,EACE,UAAA,WACC,OAAA,CAAQ,eAAA;EACX,aAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,aAAA;EACX,cAAA,CACE,UAAA,UACA,SAAA,aACC,OAAA,CAAQ,uBAAA;AAAA;AAAA,UAGI,oBAAA;EACf,QAAA;AAAA;AAAA,UAGe,0BAAA,SAAmC,cAAA;EAClD,sBAAA,EACE,UAAA,UACA,OAAA,GAAU,cAAA,EAAgB,mBAAA,aAC1B,OAAA,GAAU,oBAAA;EAEZ,iBAAA,EACE,UAAA,UACA,OAAA,GAAU,SAAA,EAAW,aAAA,aACrB,OAAA,GAAU,oBAAA;EAEZ,kBAAA,EACE,UAAA,UACA,OAAA,GAAU,UAAA,EAAY,uBAAA,kBACtB,OAAA,GAAU,oBAAA;AAAA;AAAA,UAIG,eAAA;EACf,sBAAA,CACE,OAAA,GAAU,cAAA,EAAgB,MAAA,SAAe,mBAAA;EArC3C;;;;EA2CA,aAAA,CAAc,WAAA;AAAA;AAAA,KAGJ,qBAAA;EACV,MAAA,GAAS,OAAA;AAAA;AAAA,KAGC,sBAAA;EACV,QAAA;EACA,UAAA;AAAA;AAAA,KAWU,oBAAA;EACV,cAAA,EAAgB,mBAAA;EAChB,gBAAA,EAAkB,eAAA;EAClB,SAAA,EAAW,GAAA,SAAY,aAAA;EACvB,UAAA,EAAY,GAAA,SAAY,uBAAA;AAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
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]="be942ef6-aaec-563e-8853-7a72a137c7fc")}catch(e){}}();
|
|
3
3
|
import { gql } from "graphql-tag";
|
|
4
4
|
import { GraphQLError } from "graphql";
|
|
5
|
-
import { DRIVE_AUTH_ERROR_MESSAGES } from "@powerhousedao/reactor";
|
|
5
|
+
import { DRIVE_AUTH_ERROR_MESSAGES, RECOVERABLE_GRAPHQL_ERROR_CODES } from "@powerhousedao/reactor";
|
|
6
6
|
import { childLogger } from "document-model";
|
|
7
7
|
import path from "node:path";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
9
|
//#region src/graphql/errors.ts
|
|
9
10
|
/** Caller (authenticated or anonymous) lacks permission for the document. */
|
|
10
11
|
var ForbiddenError = class extends GraphQLError {
|
|
@@ -20,6 +21,45 @@ var AuthenticationRequiredError = class extends GraphQLError {
|
|
|
20
21
|
super(`${base}${detail ? ` ${detail}` : ""}`, { extensions: { code: "UNAUTHENTICATED" } });
|
|
21
22
|
}
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* The reactor holds no decision model, so no authorization preflight can be
|
|
26
|
+
* answered.
|
|
27
|
+
*
|
|
28
|
+
* Distinct from a denial, and deliberately so: a caller that cannot get a
|
|
29
|
+
* prediction should render its controls as it did before it asked and let the
|
|
30
|
+
* submit path refuse. Reading this as a denial would disable every control on a
|
|
31
|
+
* switchboard running without authEnforcement. The code is what a client
|
|
32
|
+
* branches on, since the message is not a contract.
|
|
33
|
+
*/
|
|
34
|
+
var AuthEvaluationUnsupportedError = class extends GraphQLError {
|
|
35
|
+
constructor() {
|
|
36
|
+
super("Authorization evaluation is unavailable: this reactor runs without the authEnforcement feature flag, so it holds no decision model", { extensions: { code: "AUTH_EVALUATION_UNSUPPORTED" } });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A stored operation cannot be represented in the schema, so it is reported
|
|
41
|
+
* rather than served.
|
|
42
|
+
*
|
|
43
|
+
* The schema declares an action's id, type, timestamp, input and scope
|
|
44
|
+
* non-null; an operation written before the API rejected an action without an
|
|
45
|
+
* id violates that. Left to the executor, the missing value nullifies the
|
|
46
|
+
* action, which bubbles up through the non-null chain until it nullifies the
|
|
47
|
+
* envelope's whole operation list, and the caller receives a partial response
|
|
48
|
+
* beside "Cannot return null for non-nullable field Action.id" - which says
|
|
49
|
+
* nothing about which operation, and which a sync client can only read as a
|
|
50
|
+
* permanent GraphQL rejection, stopping its poll timer for good.
|
|
51
|
+
*
|
|
52
|
+
* Thrown instead, with a code that says the failure is worth polling through:
|
|
53
|
+
* the document holding the operation needs repairing, but the channel serves
|
|
54
|
+
* every other document, and a peer that stopped polling would stop receiving
|
|
55
|
+
* those too. The code is what a client branches on, since the message is not a
|
|
56
|
+
* contract.
|
|
57
|
+
*/
|
|
58
|
+
var MalformedStoredOperationError = class extends GraphQLError {
|
|
59
|
+
constructor(detail) {
|
|
60
|
+
super(`Stored operation cannot be served: ${detail}`, { extensions: { code: RECOVERABLE_GRAPHQL_ERROR_CODES.malformedStoredOperation } });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
23
63
|
//#endregion
|
|
24
64
|
//#region src/services/authorization.service.ts
|
|
25
65
|
/**
|
|
@@ -197,6 +237,36 @@ function createAuthorizationService(config, documentPermissionService, getParent
|
|
|
197
237
|
return new DocumentPermissionsAuthorizationService(documentPermissionService, getParentIds, config);
|
|
198
238
|
}
|
|
199
239
|
//#endregion
|
|
240
|
+
//#region src/services/canonical-document-id.ts
|
|
241
|
+
/**
|
|
242
|
+
* Raised when a caller-supplied identifier cannot be resolved to a canonical
|
|
243
|
+
* document id. Carries no detail on purpose: resolution failures must not act
|
|
244
|
+
* as a document-existence oracle, so consumers map this to their generic
|
|
245
|
+
* fail-closed response.
|
|
246
|
+
*/
|
|
247
|
+
var CanonicalDocumentIdResolutionError = class extends Error {
|
|
248
|
+
constructor() {
|
|
249
|
+
super("Document identifier could not be resolved");
|
|
250
|
+
this.name = "CanonicalDocumentIdResolutionError";
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* The sanctioned string-to-CanonicalDocumentId cast: both the GraphQL layer
|
|
255
|
+
* and server routes must resolve caller identifiers through this helper so
|
|
256
|
+
* decision and data layers always agree on the subject document.
|
|
257
|
+
*/
|
|
258
|
+
function createCanonicalDocumentIdResolver(client) {
|
|
259
|
+
return async (identifier) => {
|
|
260
|
+
let resolved;
|
|
261
|
+
try {
|
|
262
|
+
resolved = await client.resolveIdOrSlug(identifier);
|
|
263
|
+
} catch {
|
|
264
|
+
throw new CanonicalDocumentIdResolutionError();
|
|
265
|
+
}
|
|
266
|
+
return resolved;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
200
270
|
//#region src/graphql/base-subgraph.ts
|
|
201
271
|
var BaseSubgraph = class {
|
|
202
272
|
name = "example";
|
|
@@ -213,22 +283,27 @@ var BaseSubgraph = class {
|
|
|
213
283
|
syncManager;
|
|
214
284
|
documentPermissionService;
|
|
215
285
|
authorizationService;
|
|
286
|
+
syncServingGate;
|
|
216
287
|
/**
|
|
217
288
|
* Per-request memo of raw identifier to canonical document id, keyed on the
|
|
218
289
|
* request context object so entries are released when the request ends. Lets
|
|
219
290
|
* batch resolvers resolve each distinct identifier at most once.
|
|
220
291
|
*/
|
|
221
292
|
#canonicalIdMemo = /* @__PURE__ */ new WeakMap();
|
|
293
|
+
#resolveCanonical;
|
|
222
294
|
constructor(args) {
|
|
295
|
+
this.#resolveCanonical = createCanonicalDocumentIdResolver(args.reactorClient);
|
|
223
296
|
this.reactorClient = args.reactorClient;
|
|
224
297
|
this.graphqlManager = args.graphqlManager;
|
|
225
298
|
this.relationalDb = args.relationalDb;
|
|
226
299
|
this.syncManager = args.syncManager;
|
|
227
300
|
this.documentPermissionService = args.documentPermissionService;
|
|
228
301
|
this.authorizationService = args.authorizationService;
|
|
302
|
+
this.syncServingGate = args.syncServingGate;
|
|
229
303
|
this.path = args.path ?? "";
|
|
230
304
|
}
|
|
231
305
|
async onSetup() {}
|
|
306
|
+
async onDisconnect() {}
|
|
232
307
|
/**
|
|
233
308
|
* Resolves a caller-supplied identifier (id or slug) to its canonical
|
|
234
309
|
* document id, memoized per request. Both the decision layer and the data
|
|
@@ -245,13 +320,12 @@ var BaseSubgraph = class {
|
|
|
245
320
|
}
|
|
246
321
|
const cached = cache.get(identifier);
|
|
247
322
|
if (cached !== void 0) return cached;
|
|
248
|
-
let
|
|
323
|
+
let canonical;
|
|
249
324
|
try {
|
|
250
|
-
|
|
325
|
+
canonical = await this.#resolveCanonical(identifier);
|
|
251
326
|
} catch {
|
|
252
327
|
throw new ForbiddenError();
|
|
253
328
|
}
|
|
254
|
-
const canonical = resolved;
|
|
255
329
|
cache.set(identifier, canonical);
|
|
256
330
|
return canonical;
|
|
257
331
|
}
|
|
@@ -285,6 +359,22 @@ var BaseSubgraph = class {
|
|
|
285
359
|
return this.authorizationService.canRead(documentId, ctx.user?.address);
|
|
286
360
|
}
|
|
287
361
|
/**
|
|
362
|
+
* The principal a request decides as: the authenticated caller's address, and
|
|
363
|
+
* the did:key of the app instance whose token authenticated it.
|
|
364
|
+
*
|
|
365
|
+
* Both, because a policy can name either. The key is what a document records
|
|
366
|
+
* as its creator, so a subject built without one cannot match the creator's
|
|
367
|
+
* standing permission over the auth scope -- the document's own creator would
|
|
368
|
+
* be refused an operation the write path accepts, since a signed action
|
|
369
|
+
* carries the same key. Anonymous callers supply neither.
|
|
370
|
+
*/
|
|
371
|
+
viewSubject(ctx) {
|
|
372
|
+
return {
|
|
373
|
+
address: ctx.user?.address,
|
|
374
|
+
key: ctx.user?.appKey
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
288
378
|
* Asserts read access, resolving a slug first. Returns a handle whose
|
|
289
379
|
* `fetchIdentifier` the caller reuses for the data fetch; a denial throws.
|
|
290
380
|
*/
|
|
@@ -328,6 +418,15 @@ var BaseSubgraph = class {
|
|
|
328
418
|
//#endregion
|
|
329
419
|
//#region src/packages/import-resolver.ts
|
|
330
420
|
/**
|
|
421
|
+
* Imports a specifier that may be either a bare package specifier or a
|
|
422
|
+
* filesystem path. Absolute paths are converted to file:// URLs, because the
|
|
423
|
+
* ESM loader reads the drive letter in a Windows path as a URL scheme
|
|
424
|
+
* (`import('D:\\...')` fails with ERR_UNSUPPORTED_ESM_URL_SCHEME).
|
|
425
|
+
*/
|
|
426
|
+
async function importSpecifier(target) {
|
|
427
|
+
return await (path.isAbsolute(target) ? import(pathToFileURL(target).href) : import(target));
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
331
430
|
* Attempts to import from suggested Node.js paths
|
|
332
431
|
*/
|
|
333
432
|
async function tryNodeSuggestedPaths(packageName, subPath) {
|
|
@@ -338,10 +437,7 @@ async function tryNodeSuggestedPaths(packageName, subPath) {
|
|
|
338
437
|
`${packageName}/dist/${subPath}.js`
|
|
339
438
|
];
|
|
340
439
|
for (const suggestedPath of suggestedPaths) try {
|
|
341
|
-
return await
|
|
342
|
-
/* @vite-ignore */
|
|
343
|
-
suggestedPath
|
|
344
|
-
);
|
|
440
|
+
return await importSpecifier(suggestedPath);
|
|
345
441
|
} catch {}
|
|
346
442
|
return null;
|
|
347
443
|
}
|
|
@@ -352,7 +448,7 @@ async function tryImportMetaResolve(packageName, subPath) {
|
|
|
352
448
|
try {
|
|
353
449
|
const resolvedUrl = import.meta.resolve?.(`${packageName}/package.json`);
|
|
354
450
|
if (!resolvedUrl) return null;
|
|
355
|
-
const packageRoot = path.dirname(
|
|
451
|
+
const packageRoot = path.dirname(fileURLToPath(resolvedUrl));
|
|
356
452
|
const pathsToTry = [
|
|
357
453
|
path.join(packageRoot, "dist", "node", subPath, "index.mjs"),
|
|
358
454
|
path.join(packageRoot, "dist", "node", `${subPath}.mjs`),
|
|
@@ -362,10 +458,7 @@ async function tryImportMetaResolve(packageName, subPath) {
|
|
|
362
458
|
path.join(packageRoot, `${subPath}.js`)
|
|
363
459
|
];
|
|
364
460
|
for (const attemptPath of pathsToTry) try {
|
|
365
|
-
return await
|
|
366
|
-
/* @vite-ignore */
|
|
367
|
-
attemptPath
|
|
368
|
-
);
|
|
461
|
+
return await importSpecifier(attemptPath);
|
|
369
462
|
} catch {}
|
|
370
463
|
} catch {}
|
|
371
464
|
return null;
|
|
@@ -401,10 +494,7 @@ function getCommonWorkspacePaths(packageName, subPath) {
|
|
|
401
494
|
*/
|
|
402
495
|
async function tryWorkspacePatterns(patterns) {
|
|
403
496
|
for (const workspacePath of patterns) try {
|
|
404
|
-
return await
|
|
405
|
-
/* @vite-ignore */
|
|
406
|
-
workspacePath
|
|
407
|
-
);
|
|
497
|
+
return await importSpecifier(workspacePath);
|
|
408
498
|
} catch {}
|
|
409
499
|
return null;
|
|
410
500
|
}
|
|
@@ -448,20 +538,37 @@ async function loadProcessors(packageName) {
|
|
|
448
538
|
* Returns null if the dependency cannot be loaded.
|
|
449
539
|
*/
|
|
450
540
|
async function loadDependency(packageName, subPath) {
|
|
451
|
-
const fullPath = `${packageName}/${subPath}`;
|
|
541
|
+
const fullPath = path.isAbsolute(packageName) ? pathToFileURL(path.join(packageName, subPath)).href : `${packageName}/${subPath}`;
|
|
452
542
|
try {
|
|
453
543
|
return await import(
|
|
454
544
|
/* @vite-ignore */
|
|
455
545
|
fullPath
|
|
456
546
|
);
|
|
457
547
|
} catch (e) {
|
|
458
|
-
if (e instanceof Error && "code" in e && (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "ERR_UNSUPPORTED_DIR_IMPORT")) {
|
|
548
|
+
if (e instanceof Error && "code" in e && (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "ERR_UNSUPPORTED_DIR_IMPORT" || e.code === "ERR_UNSUPPORTED_ESM_URL_SCHEME")) {
|
|
459
549
|
const result = await resolveLinkedPackage(packageName, subPath);
|
|
460
550
|
if (result) return result;
|
|
461
551
|
}
|
|
462
552
|
throw e;
|
|
463
553
|
}
|
|
464
554
|
}
|
|
555
|
+
function isUpgradeManifest(value) {
|
|
556
|
+
return typeof value === "object" && value !== null && "documentType" in value && "supportedVersions" in value && "upgrades" in value;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Collects upgrade manifests from a package's document-models namespace.
|
|
560
|
+
* Handles both the aggregate `upgradeManifests` array export and individual
|
|
561
|
+
* manifest exports; dedupes by documentType.
|
|
562
|
+
*/
|
|
563
|
+
function extractUpgradeManifests(namespace) {
|
|
564
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
565
|
+
const add = (value) => {
|
|
566
|
+
if (isUpgradeManifest(value)) manifests.set(value.documentType, value);
|
|
567
|
+
};
|
|
568
|
+
for (const value of Object.values(namespace)) if (Array.isArray(value)) value.forEach(add);
|
|
569
|
+
else add(value);
|
|
570
|
+
return Array.from(manifests.values());
|
|
571
|
+
}
|
|
465
572
|
function debounce(func, delay = 250) {
|
|
466
573
|
let timer;
|
|
467
574
|
return (immediate = false, ...args) => {
|
|
@@ -537,7 +644,7 @@ function buildGraphQlDriveDocument(doc) {
|
|
|
537
644
|
};
|
|
538
645
|
}
|
|
539
646
|
//#endregion
|
|
540
|
-
export { isSubgraphClass as a,
|
|
647
|
+
export { createAuthorizationService as _, isSubgraphClass as a, MalformedStoredOperationError as b, isSubpath as c, loadSubgraphs as d, BaseSubgraph as f, AuthorizedDocumentHandle as g, AuthorizationPolicy as h, buildGraphqlOperations as i, loadDocumentModels as l, createCanonicalDocumentIdResolver as m, buildGraphQlDriveDocument as n, debounce as o, CanonicalDocumentIdResolutionError as p, buildGraphqlOperation as r, extractUpgradeManifests as s, buildGraphQlDocument as t, loadProcessors as u, AuthEvaluationUnsupportedError as v, ForbiddenError as y };
|
|
541
648
|
|
|
542
|
-
//# sourceMappingURL=utils-
|
|
543
|
-
//# debugId=
|
|
649
|
+
//# sourceMappingURL=utils-lHoPB-ft.mjs.map
|
|
650
|
+
//# debugId=be942ef6-aaec-563e-8853-7a72a137c7fc
|