@powerhousedao/reactor-api 6.0.0-dev.256 → 6.0.0-dev.258
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-IZuGzFaY.mjs +134 -0
- package/dist/adapter-gateway-apollo-IZuGzFaY.mjs.map +1 -0
- package/dist/adapter-gateway-mercurius-CLmTtNJC.mjs +132 -0
- package/dist/adapter-gateway-mercurius-CLmTtNJC.mjs.map +1 -0
- package/dist/adapter-http-express-DO4ui7AV.mjs +135 -0
- package/dist/adapter-http-express-DO4ui7AV.mjs.map +1 -0
- package/dist/adapter-http-fastify-B248RJtm.mjs +208 -0
- package/dist/adapter-http-fastify-B248RJtm.mjs.map +1 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +25 -598
- package/dist/index.mjs.map +1 -1
- package/dist/src/packages/vite-loader.d.mts +1 -1
- package/dist/src/packages/vite-loader.mjs +1 -1
- package/dist/{types-Do4QTfT3.d.mts → types-DnHgkahK.d.mts} +1 -1
- package/dist/{types-Do4QTfT3.d.mts.map → types-DnHgkahK.d.mts.map} +1 -1
- package/dist/{utils-CHCRSWig.mjs → utils-BFkbSO_H.mjs} +13 -6
- package/dist/utils-BFkbSO_H.mjs.map +1 -0
- package/dist/websocket-DncAB9XK.mjs +18 -0
- package/dist/websocket-DncAB9XK.mjs.map +1 -0
- package/package.json +13 -13
- package/dist/utils-CHCRSWig.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
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, c as loadDocumentModels, d as BaseSubgraph, i as buildGraphqlOperations, l as loadProcessors, n as buildGraphQlDriveDocument, o as debounce, r as buildGraphqlOperation, t as buildGraphQlDocument, u as loadSubgraphs } from "./utils-
|
|
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]="54de2de8-0918-5f80-961f-f2a72e390510")}catch(e){}}();
|
|
3
|
+
import { a as isSubgraphClass, c as loadDocumentModels, d as BaseSubgraph, i as buildGraphqlOperations, l as loadProcessors, n as buildGraphQlDriveDocument, o as debounce, r as buildGraphqlOperation, t as buildGraphQlDocument, u as loadSubgraphs } from "./utils-BFkbSO_H.mjs";
|
|
4
4
|
import { AnalyticsQueryEngine } from "@powerhousedao/analytics-engine-core";
|
|
5
5
|
import { AnalyticsModel, AnalyticsResolvers, typedefs } from "@powerhousedao/analytics-engine-graphql";
|
|
6
6
|
import { gql } from "graphql-tag";
|
|
7
7
|
import { GraphQLError, Kind, parse, print } from "graphql";
|
|
8
8
|
import { ConsoleLogger, childLogger, documentModelDocumentModelModule } from "document-model";
|
|
9
|
-
import { ApolloGateway, LocalCompose, RemoteGraphQLDataSource } from "@apollo/gateway";
|
|
10
|
-
import { ApolloServer, HeaderMap } from "@apollo/server";
|
|
11
|
-
import { ApolloServerPluginInlineTraceDisabled } from "@apollo/server/plugin/disabled";
|
|
12
|
-
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
|
|
13
|
-
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
|
|
14
|
-
import mercuriusGateway from "@mercuriusjs/gateway";
|
|
15
|
-
import Fastify from "fastify";
|
|
16
|
-
import mercurius from "mercurius";
|
|
17
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
18
|
-
import bodyParser from "body-parser";
|
|
19
|
-
import cors from "cors";
|
|
20
|
-
import devcert from "devcert";
|
|
21
|
-
import expressLib, { Router } from "express";
|
|
22
|
-
import fs, { watchFile } from "node:fs";
|
|
23
|
-
import http from "node:http";
|
|
24
|
-
import https from "node:https";
|
|
25
9
|
import path from "node:path";
|
|
26
10
|
import { match } from "path-to-regexp";
|
|
27
|
-
import fastifyCors from "@fastify/cors";
|
|
28
|
-
import fastifyFormbody from "@fastify/formbody";
|
|
29
|
-
import fastifyMiddie from "@fastify/middie";
|
|
30
11
|
import { verifyAuthBearerToken } from "@renown/sdk";
|
|
31
12
|
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
32
13
|
import { typeDefs } from "@powerhousedao/document-engineering/graphql";
|
|
@@ -44,6 +25,7 @@ import { getConfig } from "@powerhousedao/config/node";
|
|
|
44
25
|
import { reactorDriveDocumentModelModule } from "@powerhousedao/reactor-drive";
|
|
45
26
|
import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
|
|
46
27
|
import EventEmitter from "node:events";
|
|
28
|
+
import fs, { watchFile } from "node:fs";
|
|
47
29
|
import { PostgresAnalyticsStore } from "@powerhousedao/analytics-engine-pg";
|
|
48
30
|
import { AttachmentBuilder } from "@powerhousedao/reactor-attachments";
|
|
49
31
|
import { setupMcpServer } from "@powerhousedao/reactor-mcp";
|
|
@@ -524,584 +506,29 @@ function createAuthFetchMiddleware(authService) {
|
|
|
524
506
|
};
|
|
525
507
|
}
|
|
526
508
|
//#endregion
|
|
527
|
-
//#region src/graphql/
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
console.warn("Failed to load graphql-ws WebSocket server. Subscriptions will not work.", error);
|
|
534
|
-
}
|
|
535
|
-
const useServer = useServerImpl || (() => {
|
|
536
|
-
throw new Error("WebSocket server not available in test mode. Set NODE_ENV=production to enable.");
|
|
537
|
-
});
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/graphql/gateway/adapter-gateway-apollo.ts
|
|
540
|
-
var AuthenticatedDataSource = class extends RemoteGraphQLDataSource {
|
|
541
|
-
willSendRequest(options) {
|
|
542
|
-
const { authorization } = options.context.headers;
|
|
543
|
-
if (authorization && options?.request.http) options.request.http.headers.set("authorization", authorization);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
var ApolloGatewayAdapter = class {
|
|
547
|
-
#logger;
|
|
548
|
-
#servers = [];
|
|
549
|
-
#supergraphServer = null;
|
|
550
|
-
#gatewayOptions = null;
|
|
551
|
-
#getSubgraphs = null;
|
|
552
|
-
constructor(logger) {
|
|
553
|
-
this.#logger = logger;
|
|
554
|
-
}
|
|
555
|
-
async start(_httpServer) {}
|
|
556
|
-
async createHandler(schema, contextFactory) {
|
|
557
|
-
const server = new ApolloServer({
|
|
558
|
-
schema,
|
|
559
|
-
logger: this.#logger,
|
|
560
|
-
introspection: true,
|
|
561
|
-
stopOnTerminationSignals: false,
|
|
562
|
-
plugins: [ApolloServerPluginInlineTraceDisabled(), ApolloServerPluginLandingPageLocalDefault()]
|
|
563
|
-
});
|
|
564
|
-
await server.start();
|
|
565
|
-
this.#servers.push(server);
|
|
566
|
-
return createApolloFetchHandler(server, contextFactory);
|
|
567
|
-
}
|
|
568
|
-
async createSupergraphHandler(getSubgraphs, httpServer, contextFactory) {
|
|
569
|
-
if (this.#supergraphServer) throw new Error("Supergraph server is already running");
|
|
570
|
-
this.#getSubgraphs = getSubgraphs;
|
|
571
|
-
this.#supergraphServer = new ApolloServer({
|
|
572
|
-
gateway: new ApolloGateway({
|
|
573
|
-
supergraphSdl: async (options) => {
|
|
574
|
-
this.#gatewayOptions = options;
|
|
575
|
-
return await this.#buildSupergraphSdl();
|
|
576
|
-
},
|
|
577
|
-
buildService: (serviceConfig) => new AuthenticatedDataSource(serviceConfig)
|
|
578
|
-
}),
|
|
579
|
-
logger: this.#logger,
|
|
580
|
-
introspection: true,
|
|
581
|
-
stopOnTerminationSignals: false,
|
|
582
|
-
plugins: [
|
|
583
|
-
ApolloServerPluginDrainHttpServer({ httpServer }),
|
|
584
|
-
ApolloServerPluginInlineTraceDisabled(),
|
|
585
|
-
ApolloServerPluginLandingPageLocalDefault()
|
|
586
|
-
]
|
|
587
|
-
});
|
|
588
|
-
await this.#supergraphServer.start();
|
|
589
|
-
return createApolloFetchHandler(this.#supergraphServer, contextFactory);
|
|
590
|
-
}
|
|
591
|
-
async updateSupergraph() {
|
|
592
|
-
if (!this.#gatewayOptions || !this.#getSubgraphs) return;
|
|
593
|
-
const { supergraphSdl } = await this.#buildSupergraphSdl();
|
|
594
|
-
this.#gatewayOptions.update(supergraphSdl);
|
|
595
|
-
}
|
|
596
|
-
async #buildSupergraphSdl() {
|
|
597
|
-
if (!this.#gatewayOptions || !this.#getSubgraphs) throw new Error("Gateway is not ready");
|
|
598
|
-
return new LocalCompose({ localServiceList: this.#getSubgraphs().map((s) => ({
|
|
599
|
-
name: s.name,
|
|
600
|
-
typeDefs: s.typeDefs,
|
|
601
|
-
url: s.url
|
|
602
|
-
})) }).initialize(this.#gatewayOptions);
|
|
603
|
-
}
|
|
604
|
-
attachWebSocket(wsServer, schema, contextFactory) {
|
|
605
|
-
return useServer({
|
|
606
|
-
schema,
|
|
607
|
-
context: async (ctx) => {
|
|
608
|
-
return contextFactory(ctx.connectionParams ?? {});
|
|
609
|
-
}
|
|
610
|
-
}, wsServer);
|
|
611
|
-
}
|
|
612
|
-
async stop() {
|
|
613
|
-
await Promise.all(this.#servers.map((s) => s.stop()));
|
|
614
|
-
this.#servers.length = 0;
|
|
615
|
-
if (this.#supergraphServer) {
|
|
616
|
-
await this.#supergraphServer.stop();
|
|
617
|
-
this.#supergraphServer = null;
|
|
618
|
-
}
|
|
619
|
-
this.#gatewayOptions = null;
|
|
620
|
-
this.#getSubgraphs = null;
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
/**
|
|
624
|
-
* Wrap an existing ApolloServer as a Fetch API handler.
|
|
625
|
-
* Does not manage server lifecycle; caller is responsible for start/stop.
|
|
626
|
-
*/
|
|
627
|
-
function createApolloFetchHandler(server, contextFactory) {
|
|
628
|
-
return async (request) => {
|
|
629
|
-
const url = new URL(request.url);
|
|
630
|
-
const headers = new HeaderMap();
|
|
631
|
-
request.headers.forEach((value, key) => headers.set(key, value));
|
|
632
|
-
let body = void 0;
|
|
633
|
-
if (request.method !== "GET" && request.method !== "HEAD") try {
|
|
634
|
-
body = await request.json();
|
|
635
|
-
} catch {}
|
|
636
|
-
const result = await server.executeHTTPGraphQLRequest({
|
|
637
|
-
httpGraphQLRequest: {
|
|
638
|
-
method: request.method.toUpperCase(),
|
|
639
|
-
headers,
|
|
640
|
-
search: url.search,
|
|
641
|
-
body
|
|
642
|
-
},
|
|
643
|
-
context: () => contextFactory(request)
|
|
644
|
-
});
|
|
645
|
-
const responseHeaders = new Headers();
|
|
646
|
-
for (const [key, value] of result.headers) responseHeaders.set(key, value);
|
|
647
|
-
let responseBody;
|
|
648
|
-
if (result.body.kind === "complete") responseBody = result.body.string;
|
|
649
|
-
else {
|
|
650
|
-
const chunks = [];
|
|
651
|
-
for await (const chunk of result.body.asyncIterator) chunks.push(chunk);
|
|
652
|
-
responseBody = chunks.join("");
|
|
653
|
-
}
|
|
654
|
-
return new Response(responseBody, {
|
|
655
|
-
status: result.status ?? 200,
|
|
656
|
-
headers: responseHeaders
|
|
657
|
-
});
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
//#endregion
|
|
661
|
-
//#region src/graphql/gateway/adapter-gateway-mercurius.ts
|
|
662
|
-
/**
|
|
663
|
-
* Threads the original Fetch API Request through Mercurius's internal
|
|
664
|
-
* fastify.inject() call so that contextFactory (which uses the auth WeakMap
|
|
665
|
-
* from auth-middleware.ts) receives the same Request object that auth
|
|
666
|
-
* middleware populated before calling the handler.
|
|
667
|
-
*/
|
|
668
|
-
const requestAls = new AsyncLocalStorage();
|
|
669
|
-
const mercuriusGatewayPlugin = mercuriusGateway;
|
|
670
|
-
var MercuriusGatewayAdapter = class {
|
|
671
|
-
#logger;
|
|
672
|
-
#subgraphApps = [];
|
|
673
|
-
#supergraphApp = null;
|
|
674
|
-
#getSubgraphs = null;
|
|
675
|
-
#supergraphContextFactory = null;
|
|
676
|
-
constructor(logger) {
|
|
677
|
-
this.#logger = logger;
|
|
678
|
-
}
|
|
679
|
-
async start(_httpServer) {}
|
|
680
|
-
async createHandler(schema, contextFactory) {
|
|
681
|
-
const app = await buildMercuriusApp(schema, contextFactory, this.#logger);
|
|
682
|
-
this.#subgraphApps.push(app);
|
|
683
|
-
return buildFetchHandler(app);
|
|
684
|
-
}
|
|
685
|
-
async createSupergraphHandler(getSubgraphs, _httpServer, contextFactory) {
|
|
686
|
-
if (this.#supergraphApp) throw new Error("Supergraph is already running");
|
|
687
|
-
this.#getSubgraphs = getSubgraphs;
|
|
688
|
-
this.#supergraphContextFactory = contextFactory;
|
|
689
|
-
this.#supergraphApp = await buildGatewayApp(getSubgraphs(), contextFactory, this.#logger);
|
|
690
|
-
const adapter = this;
|
|
691
|
-
return (request) => {
|
|
692
|
-
if (!adapter.#supergraphApp) return Promise.resolve(new Response("Gateway not ready", { status: 503 }));
|
|
693
|
-
return requestAls.run(request, () => injectRequest(adapter.#supergraphApp, request));
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
async updateSupergraph() {
|
|
697
|
-
if (!this.#getSubgraphs || !this.#supergraphContextFactory) return;
|
|
698
|
-
const newApp = await buildGatewayApp(this.#getSubgraphs(), this.#supergraphContextFactory, this.#logger);
|
|
699
|
-
const oldApp = this.#supergraphApp;
|
|
700
|
-
this.#supergraphApp = newApp;
|
|
701
|
-
if (oldApp) await oldApp.close();
|
|
702
|
-
}
|
|
703
|
-
attachWebSocket(wsServer, schema, contextFactory) {
|
|
704
|
-
return useServer({
|
|
705
|
-
schema,
|
|
706
|
-
context: async (ctx) => contextFactory(ctx.connectionParams ?? {})
|
|
707
|
-
}, wsServer);
|
|
708
|
-
}
|
|
709
|
-
async stop() {
|
|
710
|
-
await Promise.all(this.#subgraphApps.map((app) => app.close()));
|
|
711
|
-
this.#subgraphApps.length = 0;
|
|
712
|
-
if (this.#supergraphApp) {
|
|
713
|
-
await this.#supergraphApp.close();
|
|
714
|
-
this.#supergraphApp = null;
|
|
509
|
+
//#region src/graphql/gateway/factory.ts
|
|
510
|
+
async function createGatewayAdapter(type, logger) {
|
|
511
|
+
switch (type) {
|
|
512
|
+
case "apollo": {
|
|
513
|
+
const { ApolloGatewayAdapter } = await import("./adapter-gateway-apollo-IZuGzFaY.mjs");
|
|
514
|
+
return new ApolloGatewayAdapter(logger);
|
|
715
515
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
};
|
|
720
|
-
function makeContextFn(contextFactory, logger) {
|
|
721
|
-
return (_req, _reply) => {
|
|
722
|
-
const request = requestAls.getStore();
|
|
723
|
-
if (!request) {
|
|
724
|
-
logger.error("[mercurius] No Fetch Request in AsyncLocalStorage");
|
|
725
|
-
throw new Error("No Fetch Request in AsyncLocalStorage");
|
|
516
|
+
case "mercurius": {
|
|
517
|
+
const { MercuriusGatewayAdapter } = await import("./adapter-gateway-mercurius-CLmTtNJC.mjs");
|
|
518
|
+
return new MercuriusGatewayAdapter(logger);
|
|
726
519
|
}
|
|
727
|
-
return contextFactory(request);
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
async function buildMercuriusApp(schema, contextFactory, logger) {
|
|
731
|
-
const app = Fastify({ logger: false });
|
|
732
|
-
await app.register(mercurius, {
|
|
733
|
-
schema,
|
|
734
|
-
graphiql: false,
|
|
735
|
-
context: makeContextFn(contextFactory, logger),
|
|
736
|
-
resolvers: { _Service: { sdl: (parent) => (parent.sdl ?? "").replace(/\btype\s+(Query|Mutation|Subscription)\s*\{/g, "extend type $1 {") } }
|
|
737
|
-
});
|
|
738
|
-
await app.ready();
|
|
739
|
-
return app;
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Builds a Mercurius federation gateway that composes the given subgraph
|
|
743
|
-
* services. Each service URL must be reachable so that the gateway can fetch
|
|
744
|
-
* its SDL via `_service { sdl }` (Apollo Federation protocol).
|
|
745
|
-
*/
|
|
746
|
-
async function buildGatewayApp(subgraphs, contextFactory, logger) {
|
|
747
|
-
const app = Fastify({ logger: false });
|
|
748
|
-
await app.register(mercuriusGatewayPlugin, {
|
|
749
|
-
gateway: { services: subgraphs.map((s) => ({
|
|
750
|
-
name: s.name,
|
|
751
|
-
url: s.url
|
|
752
|
-
})) },
|
|
753
|
-
graphiql: false,
|
|
754
|
-
context: makeContextFn(contextFactory, logger)
|
|
755
|
-
});
|
|
756
|
-
await app.ready();
|
|
757
|
-
return app;
|
|
758
|
-
}
|
|
759
|
-
function buildFetchHandler(app) {
|
|
760
|
-
return (request) => requestAls.run(request, () => injectRequest(app, request));
|
|
761
|
-
}
|
|
762
|
-
async function injectRequest(app, request) {
|
|
763
|
-
const body = request.method !== "GET" && request.method !== "HEAD" ? await request.text() : void 0;
|
|
764
|
-
const headers = {};
|
|
765
|
-
request.headers.forEach((value, key) => {
|
|
766
|
-
headers[key] = value;
|
|
767
|
-
});
|
|
768
|
-
const response = await app.inject({
|
|
769
|
-
method: request.method,
|
|
770
|
-
url: "/graphql",
|
|
771
|
-
headers,
|
|
772
|
-
payload: body
|
|
773
|
-
});
|
|
774
|
-
const responseHeaders = {};
|
|
775
|
-
for (const [key, value] of Object.entries(response.headers)) if (value !== void 0) responseHeaders[key] = String(value);
|
|
776
|
-
return new Response(response.payload, {
|
|
777
|
-
status: response.statusCode,
|
|
778
|
-
headers: responseHeaders
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
//#endregion
|
|
782
|
-
//#region src/graphql/gateway/adapter-http-express.ts
|
|
783
|
-
var ExpressHttpAdapter = class {
|
|
784
|
-
#app;
|
|
785
|
-
#router;
|
|
786
|
-
#handlers = /* @__PURE__ */ new Map();
|
|
787
|
-
constructor(existingApp) {
|
|
788
|
-
this.#app = existingApp ?? expressLib();
|
|
789
|
-
this.#router = Router();
|
|
790
|
-
this.#app.use(this.#router);
|
|
791
|
-
}
|
|
792
|
-
setupSentryErrorHandler(sentry) {
|
|
793
|
-
sentry.setupExpressErrorHandler(this.#app);
|
|
794
|
-
}
|
|
795
|
-
get handle() {
|
|
796
|
-
return this.#app;
|
|
797
|
-
}
|
|
798
|
-
mountRawMiddleware(middleware) {
|
|
799
|
-
this.#app.use(middleware);
|
|
800
|
-
}
|
|
801
|
-
mountNodeRoute(method, path, handler) {
|
|
802
|
-
const m = method.toLowerCase();
|
|
803
|
-
this.#app[m](path, (req, res) => handler(req, res, req.body));
|
|
804
|
-
}
|
|
805
|
-
setupMiddleware({ corsOptions, bodyLimit = "50mb" }) {
|
|
806
|
-
this.#router.use(cors(corsOptions));
|
|
807
|
-
this.#router.use(bodyParser.json({ limit: bodyLimit }));
|
|
808
|
-
this.#router.use(bodyParser.urlencoded({
|
|
809
|
-
extended: true,
|
|
810
|
-
limit: bodyLimit
|
|
811
|
-
}));
|
|
812
|
-
this.#router.use((req, res, next) => {
|
|
813
|
-
for (const { handler, matcher } of this.#handlers.values()) if (matcher(req.path)) {
|
|
814
|
-
this.#serveFetchHandler(handler, req, res, next);
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
next();
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
mount(path, handler, { exact = false } = {}) {
|
|
821
|
-
if (exact) this.#router.use(path, (req, res, next) => this.#serveFetchHandler(handler, req, res, next));
|
|
822
|
-
else this.#handlers.set(path, {
|
|
823
|
-
handler,
|
|
824
|
-
matcher: match(path)
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
getRoute(routePath, handler) {
|
|
828
|
-
this.#app.get(routePath, (req, res) => {
|
|
829
|
-
const url = `${req.protocol}://${req.get("host") ?? "localhost"}${req.originalUrl}`;
|
|
830
|
-
const headers = new Headers();
|
|
831
|
-
for (const [key, value] of Object.entries(req.headers)) if (typeof value === "string") headers.set(key, value);
|
|
832
|
-
else if (Array.isArray(value)) headers.set(key, value.join(", "));
|
|
833
|
-
const fetchRequest = new Request(url, {
|
|
834
|
-
method: "GET",
|
|
835
|
-
headers
|
|
836
|
-
});
|
|
837
|
-
Promise.resolve(handler(fetchRequest)).then(async (response) => {
|
|
838
|
-
res.status(response.status);
|
|
839
|
-
response.headers.forEach((value, key) => {
|
|
840
|
-
res.setHeader(key, value);
|
|
841
|
-
});
|
|
842
|
-
res.send(await response.text());
|
|
843
|
-
}).catch((err) => {
|
|
844
|
-
res.status(500).send(String(err));
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
async listen(port, tls) {
|
|
849
|
-
let server;
|
|
850
|
-
if (tls === true) {
|
|
851
|
-
const { cert, key } = await devcert.certificateFor("localhost");
|
|
852
|
-
if (!cert || !key) throw new Error("Invalid certificate generated");
|
|
853
|
-
server = https.createServer({
|
|
854
|
-
cert,
|
|
855
|
-
key
|
|
856
|
-
}, this.#app);
|
|
857
|
-
} else if (tls && "keyPath" in tls) {
|
|
858
|
-
const currentDir = process.cwd();
|
|
859
|
-
server = https.createServer({
|
|
860
|
-
key: fs.readFileSync(path.join(currentDir, tls.keyPath)),
|
|
861
|
-
cert: fs.readFileSync(path.join(currentDir, tls.certPath))
|
|
862
|
-
}, this.#app);
|
|
863
|
-
} else if (tls && "cert" in tls) server = https.createServer({
|
|
864
|
-
cert: tls.cert,
|
|
865
|
-
key: tls.key
|
|
866
|
-
}, this.#app);
|
|
867
|
-
else server = http.createServer(this.#app);
|
|
868
|
-
return new Promise((resolve, reject) => {
|
|
869
|
-
server.once("error", reject);
|
|
870
|
-
server.listen(port, () => {
|
|
871
|
-
server.off("error", reject);
|
|
872
|
-
resolve(server);
|
|
873
|
-
});
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
#serveFetchHandler(handler, req, res, next) {
|
|
877
|
-
const url = `${req.protocol}://${req.get("host") ?? "localhost"}${req.originalUrl}`;
|
|
878
|
-
const headers = new Headers();
|
|
879
|
-
for (const [key, value] of Object.entries(req.headers)) if (typeof value === "string") headers.set(key, value);
|
|
880
|
-
else if (Array.isArray(value)) headers.set(key, value.join(", "));
|
|
881
|
-
let body;
|
|
882
|
-
if (req.method !== "GET" && req.method !== "HEAD" && req.body !== void 0) body = JSON.stringify(req.body);
|
|
883
|
-
const fetchRequest = new Request(url, {
|
|
884
|
-
method: req.method,
|
|
885
|
-
headers,
|
|
886
|
-
body
|
|
887
|
-
});
|
|
888
|
-
Promise.resolve(handler(fetchRequest)).then(async (response) => {
|
|
889
|
-
res.status(response.status);
|
|
890
|
-
response.headers.forEach((value, key) => {
|
|
891
|
-
res.setHeader(key, value);
|
|
892
|
-
});
|
|
893
|
-
const responseBody = await response.text();
|
|
894
|
-
res.send(responseBody);
|
|
895
|
-
}).catch(next);
|
|
896
520
|
}
|
|
897
|
-
};
|
|
898
|
-
function createExpressHttpAdapter(existingApp) {
|
|
899
|
-
return { adapter: new ExpressHttpAdapter(existingApp) };
|
|
900
521
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
* - Converts legacy optional-param syntax ":param?" → "{/:param}?"
|
|
907
|
-
*/
|
|
908
|
-
function normalizePath(path) {
|
|
909
|
-
return path.replace(/\/+/g, "/").replace(/:(\w+)\?/g, "{/:$1}");
|
|
910
|
-
}
|
|
911
|
-
/** Parses body-limit strings like "50mb" to bytes. */
|
|
912
|
-
function parseBodyLimit(limit) {
|
|
913
|
-
const m = /^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i.exec(limit.trim());
|
|
914
|
-
if (!m) return 52428800;
|
|
915
|
-
const n = parseFloat(m[1]);
|
|
916
|
-
return Math.round(n * ({
|
|
917
|
-
b: 1,
|
|
918
|
-
kb: 1024,
|
|
919
|
-
mb: 1048576,
|
|
920
|
-
gb: 1073741824
|
|
921
|
-
}[(m[2] ?? "b").toLowerCase()] ?? 1));
|
|
922
|
-
}
|
|
923
|
-
var FastifyHttpAdapter = class {
|
|
924
|
-
#fetchRoutes = [];
|
|
925
|
-
#getRoutes = /* @__PURE__ */ new Map();
|
|
926
|
-
#nodeRoutes = [];
|
|
927
|
-
#setupOps = [];
|
|
928
|
-
#instance;
|
|
929
|
-
get handle() {
|
|
930
|
-
return this.#instance;
|
|
931
|
-
}
|
|
932
|
-
setupMiddleware({ corsOptions, bodyLimit = "50mb" }) {
|
|
933
|
-
this.#setupOps.push({
|
|
934
|
-
kind: "cors",
|
|
935
|
-
options: corsOptions,
|
|
936
|
-
bodyLimit: parseBodyLimit(bodyLimit)
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
mount(path, handler, { exact = false } = {}) {
|
|
940
|
-
this.#fetchRoutes.push({
|
|
941
|
-
handler,
|
|
942
|
-
matcher: match(normalizePath(path), { end: !exact }),
|
|
943
|
-
prefix: exact
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
getRoute(path, handler) {
|
|
947
|
-
this.#getRoutes.set(path, {
|
|
948
|
-
handler,
|
|
949
|
-
matcher: match(normalizePath(path))
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
mountNodeRoute(method, path, handler) {
|
|
953
|
-
this.#nodeRoutes.push({
|
|
954
|
-
method,
|
|
955
|
-
matcher: match(normalizePath(path)),
|
|
956
|
-
handler
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
mountRawMiddleware(middleware) {
|
|
960
|
-
if (this.#instance) this.#instance.use(middleware);
|
|
961
|
-
else this.#setupOps.push({
|
|
962
|
-
kind: "middie",
|
|
963
|
-
middleware
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
setupSentryErrorHandler(sentry) {
|
|
967
|
-
if (!this.#instance) return;
|
|
968
|
-
sentry.setupFastifyErrorHandler(this.#instance);
|
|
969
|
-
}
|
|
970
|
-
async listen(port, tls) {
|
|
971
|
-
let httpServer;
|
|
972
|
-
if (tls === true) {
|
|
973
|
-
const { cert, key } = await devcert.certificateFor("localhost");
|
|
974
|
-
if (!cert || !key) throw new Error("Invalid certificate generated");
|
|
975
|
-
httpServer = https.createServer({
|
|
976
|
-
cert,
|
|
977
|
-
key
|
|
978
|
-
});
|
|
979
|
-
} else if (tls && "keyPath" in tls) {
|
|
980
|
-
const cwd = process.cwd();
|
|
981
|
-
httpServer = https.createServer({
|
|
982
|
-
key: fs.readFileSync(path.join(cwd, tls.keyPath)),
|
|
983
|
-
cert: fs.readFileSync(path.join(cwd, tls.certPath))
|
|
984
|
-
});
|
|
985
|
-
} else if (tls && "cert" in tls) httpServer = https.createServer({
|
|
986
|
-
cert: tls.cert,
|
|
987
|
-
key: tls.key
|
|
988
|
-
});
|
|
989
|
-
else httpServer = http.createServer();
|
|
990
|
-
const instance = Fastify({
|
|
991
|
-
serverFactory: (handler) => {
|
|
992
|
-
httpServer.on("request", handler);
|
|
993
|
-
return httpServer;
|
|
994
|
-
},
|
|
995
|
-
bodyLimit: this.#setupOps.find((op) => op.kind === "cors")?.bodyLimit ?? 52428800,
|
|
996
|
-
logger: false
|
|
997
|
-
});
|
|
998
|
-
this.#instance = instance;
|
|
999
|
-
await instance.register(fastifyMiddie);
|
|
1000
|
-
await instance.register(fastifyFormbody);
|
|
1001
|
-
for (const op of this.#setupOps) if (op.kind === "cors") await instance.register(fastifyCors, op.options);
|
|
1002
|
-
else instance.use(op.middleware);
|
|
1003
|
-
instance.route({
|
|
1004
|
-
method: [
|
|
1005
|
-
"DELETE",
|
|
1006
|
-
"GET",
|
|
1007
|
-
"HEAD",
|
|
1008
|
-
"PATCH",
|
|
1009
|
-
"POST",
|
|
1010
|
-
"PUT"
|
|
1011
|
-
],
|
|
1012
|
-
url: "/*",
|
|
1013
|
-
handler: (req, reply) => this.#dispatch(req, reply)
|
|
1014
|
-
});
|
|
1015
|
-
await instance.ready();
|
|
1016
|
-
return new Promise((resolve, reject) => {
|
|
1017
|
-
httpServer.once("error", reject);
|
|
1018
|
-
httpServer.listen(port, () => {
|
|
1019
|
-
httpServer.off("error", reject);
|
|
1020
|
-
resolve(httpServer);
|
|
1021
|
-
});
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
#dispatch(req, reply) {
|
|
1025
|
-
const pathname = new URL(req.url, "http://localhost").pathname;
|
|
1026
|
-
const method = req.method.toUpperCase();
|
|
1027
|
-
for (const entry of this.#nodeRoutes) {
|
|
1028
|
-
if (entry.method !== method) continue;
|
|
1029
|
-
const result = entry.matcher(pathname);
|
|
1030
|
-
if (!result) continue;
|
|
1031
|
-
req.raw.params = result.params;
|
|
1032
|
-
reply.hijack();
|
|
1033
|
-
entry.handler(req.raw, reply.raw, req.body);
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
if (method === "GET") {
|
|
1037
|
-
for (const entry of this.#getRoutes.values()) if (entry.matcher(pathname)) return this.#serveGetEntry(entry, req, reply);
|
|
522
|
+
async function createHttpAdapter(type) {
|
|
523
|
+
switch (type) {
|
|
524
|
+
case "express": {
|
|
525
|
+
const { createExpressHttpAdapter } = await import("./adapter-http-express-DO4ui7AV.mjs");
|
|
526
|
+
return createExpressHttpAdapter();
|
|
1038
527
|
}
|
|
1039
|
-
|
|
1040
|
-
const
|
|
1041
|
-
|
|
528
|
+
case "fastify": {
|
|
529
|
+
const { createFastifyHttpAdapter } = await import("./adapter-http-fastify-B248RJtm.mjs");
|
|
530
|
+
return createFastifyHttpAdapter();
|
|
1042
531
|
}
|
|
1043
|
-
reply.status(404).send({
|
|
1044
|
-
message: `Route ${req.method}:${pathname} not found`,
|
|
1045
|
-
error: "Not Found",
|
|
1046
|
-
statusCode: 404
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
async #serveGetEntry(entry, req, reply) {
|
|
1050
|
-
const url = buildUrl(req);
|
|
1051
|
-
const headers = buildHeaders(req);
|
|
1052
|
-
const fetchReq = new Request(url, {
|
|
1053
|
-
method: "GET",
|
|
1054
|
-
headers
|
|
1055
|
-
});
|
|
1056
|
-
const response = await entry.handler(fetchReq);
|
|
1057
|
-
writeResponse(reply, response);
|
|
1058
|
-
return reply.send(await response.text());
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
async function serveFetchHandler(handler, req, reply) {
|
|
1062
|
-
const url = buildUrl(req);
|
|
1063
|
-
const headers = buildHeaders(req);
|
|
1064
|
-
let body;
|
|
1065
|
-
if (req.method !== "GET" && req.method !== "HEAD" && req.body !== void 0) body = JSON.stringify(req.body);
|
|
1066
|
-
const response = await handler(new Request(url, {
|
|
1067
|
-
method: req.method,
|
|
1068
|
-
headers,
|
|
1069
|
-
body
|
|
1070
|
-
}));
|
|
1071
|
-
writeResponse(reply, response);
|
|
1072
|
-
return reply.send(await response.text());
|
|
1073
|
-
}
|
|
1074
|
-
function buildUrl(req) {
|
|
1075
|
-
const host = req.headers.host ?? "localhost";
|
|
1076
|
-
return `${req.protocol}://${host}${req.url}`;
|
|
1077
|
-
}
|
|
1078
|
-
function buildHeaders(req) {
|
|
1079
|
-
const headers = new Headers();
|
|
1080
|
-
for (const [key, value] of Object.entries(req.headers)) if (typeof value === "string") headers.set(key, value);
|
|
1081
|
-
else if (Array.isArray(value)) headers.set(key, value.join(", "));
|
|
1082
|
-
return headers;
|
|
1083
|
-
}
|
|
1084
|
-
function writeResponse(reply, response) {
|
|
1085
|
-
reply.status(response.status);
|
|
1086
|
-
response.headers.forEach((value, key) => {
|
|
1087
|
-
reply.header(key, value);
|
|
1088
|
-
});
|
|
1089
|
-
}
|
|
1090
|
-
function createFastifyHttpAdapter() {
|
|
1091
|
-
return { adapter: new FastifyHttpAdapter() };
|
|
1092
|
-
}
|
|
1093
|
-
//#endregion
|
|
1094
|
-
//#region src/graphql/gateway/factory.ts
|
|
1095
|
-
function createGatewayAdapter(type, logger) {
|
|
1096
|
-
switch (type) {
|
|
1097
|
-
case "apollo": return new ApolloGatewayAdapter(logger);
|
|
1098
|
-
case "mercurius": return new MercuriusGatewayAdapter(logger);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
function createHttpAdapter(type) {
|
|
1102
|
-
switch (type) {
|
|
1103
|
-
case "express": return createExpressHttpAdapter();
|
|
1104
|
-
case "fastify": return createFastifyHttpAdapter();
|
|
1105
532
|
}
|
|
1106
533
|
}
|
|
1107
534
|
//#endregion
|
|
@@ -4986,10 +4413,10 @@ const ADMIN_USERS = getAdminUsers();
|
|
|
4986
4413
|
//#endregion
|
|
4987
4414
|
//#region src/graphql/system/version.ts
|
|
4988
4415
|
function getVersion() {
|
|
4989
|
-
return "6.0.0-dev.
|
|
4416
|
+
return "6.0.0-dev.258";
|
|
4990
4417
|
}
|
|
4991
4418
|
function getGitHash() {
|
|
4992
|
-
return "
|
|
4419
|
+
return "4638044dd3799e2ee3869f9d7b999aaea2188896";
|
|
4993
4420
|
}
|
|
4994
4421
|
function getGitUrl() {
|
|
4995
4422
|
return buildTreeUrl(getGitHash());
|
|
@@ -6319,7 +5746,7 @@ function makeDbClosers(knexInstance, pglite) {
|
|
|
6319
5746
|
* Sets up the subgraph manager and registers subgraphs
|
|
6320
5747
|
*/
|
|
6321
5748
|
async function setupGraphQLManager(httpAdapter, authFetchMiddleware, httpServer, wsServer, client, relationalDb, analyticsStore, syncManager, subgraphs, logger, auth, documentPermissionService, enableDocumentModelSubgraphs, port, authorizationService, reactorDriveClient) {
|
|
6322
|
-
const graphqlManager = new GraphQLManager(config.basePath, httpServer, wsServer, client, relationalDb, analyticsStore, syncManager, logger, httpAdapter, createGatewayAdapter("apollo", logger), {
|
|
5749
|
+
const graphqlManager = new GraphQLManager(config.basePath, httpServer, wsServer, client, relationalDb, analyticsStore, syncManager, logger, httpAdapter, await createGatewayAdapter("apollo", logger), {
|
|
6323
5750
|
enabled: auth?.enabled ?? false,
|
|
6324
5751
|
admins: auth?.admins ?? []
|
|
6325
5752
|
}, documentPermissionService, { enableDocumentModelSubgraphs }, port, authorizationService, reactorDriveClient);
|
|
@@ -6391,7 +5818,7 @@ async function startServer(httpAdapter, port, httpsOptions, logger) {
|
|
|
6391
5818
|
*/
|
|
6392
5819
|
async function _setupCommonInfrastructure(options) {
|
|
6393
5820
|
const port = options.port ?? DEFAULT_PORT;
|
|
6394
|
-
const { adapter: httpAdapter } = createHttpAdapter("express");
|
|
5821
|
+
const { adapter: httpAdapter } = await createHttpAdapter("express");
|
|
6395
5822
|
let admins = [];
|
|
6396
5823
|
let authEnabled = false;
|
|
6397
5824
|
if (options.configFile) {
|
|
@@ -6717,4 +6144,4 @@ var PackageManagementService = class {
|
|
|
6717
6144
|
export { ADMIN_USERS, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentInputSchema, AuthService, AuthSubgraph, BaseSubgraph, ChannelMetaInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentOperationsFilterInputSchema, DocumentPermissionService, FindDocumentsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, ImportPackageLoader, InMemoryPackageStorage, JobChangesDocument, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, SearchFilterInputSchema, SetPreferredEditorDocument, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, ViewFilterInputSchema, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, createAuthFetchMiddleware, createGatewayAdapter, createHttpAdapter, createMergedSchema, createReactorGraphQLClient, createSchema, definedNonNullAnySchema, driveIdFromUrl, generateDocumentModelSchema, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelTypeDefs, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getVersion, initAnalyticsStoreSql, initializeAndStartAPI, isDefinedNonNullAny, isSubgraphClass, parseDriveUrl, renderGraphqlPlayground };
|
|
6718
6145
|
|
|
6719
6146
|
//# sourceMappingURL=index.mjs.map
|
|
6720
|
-
//# debugId=
|
|
6147
|
+
//# debugId=54de2de8-0918-5f80-961f-f2a72e390510
|