@powerhousedao/reactor-api 1.29.4 → 1.29.5-dev.1
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/src/server.d.ts +5 -5
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/subgraphs/drive/index.d.ts +2 -2
- package/dist/src/subgraphs/drive/index.d.ts.map +1 -1
- package/dist/src/subgraphs/drive/index.js +1 -1
- package/dist/src/subgraphs/manager.d.ts +5 -1
- package/dist/src/subgraphs/manager.d.ts.map +1 -1
- package/dist/src/subgraphs/manager.js +85 -37
- package/dist/src/utils/create-schema.d.ts +4 -4
- package/dist/src/utils/create-schema.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
package/dist/src/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
3
|
-
import { Express } from "express";
|
|
4
|
-
import { Pool } from "pg";
|
|
5
|
-
import { API } from "./types.js";
|
|
1
|
+
import { type PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { type IDocumentDriveServer } from "document-drive";
|
|
3
|
+
import { type Express } from "express";
|
|
4
|
+
import { type Pool } from "pg";
|
|
5
|
+
import { type API } from "./types.js";
|
|
6
6
|
type Options = {
|
|
7
7
|
express?: Express;
|
|
8
8
|
port?: number;
|
package/dist/src/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAOnD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAKhD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAGtC,KAAK,OAAO,GAAG;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,IAAI,GAAG,SAAS,CAAC;IAC1C,KAAK,CAAC,EACF;QACE,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,GACD,OAAO,GACP,SAAS,CAAC;CACf,CAAC;AAIF,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,GAAG,CAAC,CAgDd"}
|
package/dist/src/server.js
CHANGED
|
@@ -28,7 +28,6 @@ export async function startAPI(reactor, options) {
|
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
try {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
32
31
|
const { cert, key } = (await devcert.certificateFor("localhost"));
|
|
33
32
|
if (!cert || !key) {
|
|
34
33
|
throw new Error("Invalid certificate generated");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Subgraph } from "#subgraphs/base/index.js";
|
|
2
|
-
import { Context, SubgraphArgs } from "#subgraphs/types.js";
|
|
3
|
-
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
2
|
+
import { type Context, type SubgraphArgs } from "#subgraphs/types.js";
|
|
3
|
+
import { type GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
4
4
|
export declare class DriveSubgraph extends Subgraph {
|
|
5
5
|
private logger;
|
|
6
6
|
constructor(args: SubgraphArgs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/drive/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/drive/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOtE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AAyB7F,qBAAa,aAAc,SAAQ,QAAQ;IACzC,OAAO,CAAC,MAAM,CAGX;gBAES,IAAI,EAAE,YAAY;IAM9B,IAAI,SAAc;IAClB,QAAQ,iCAqJN;IAEF,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAmPpC;CACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Subgraph } from "#subgraphs/base/index.js";
|
|
2
2
|
import { processAcknowledge, processGetStrands, processPushUpdate, } from "#sync/utils.js";
|
|
3
3
|
import { pascalCase } from "change-case";
|
|
4
|
-
import { childLogger, generateUUID, PullResponderTransmitter } from "document-drive";
|
|
4
|
+
import { childLogger, generateUUID, PullResponderTransmitter, } from "document-drive";
|
|
5
5
|
import { gql } from "graphql-tag";
|
|
6
6
|
const driveKindTypeNames = {
|
|
7
7
|
file: "DocumentDrive_FileNode",
|
|
@@ -16,7 +16,11 @@ export declare class SubgraphManager {
|
|
|
16
16
|
constructor(path: string, app: express.Express, reactor: IDocumentDriveServer, operationalStore: Db, analyticsStore: IAnalyticsStore);
|
|
17
17
|
init(): Promise<void>;
|
|
18
18
|
updateRouter(): Promise<void>;
|
|
19
|
-
|
|
19
|
+
private createApolloServer;
|
|
20
|
+
private setupSubgraphs;
|
|
21
|
+
private createApolloGateway;
|
|
22
|
+
private setupApolloExpressMiddleware;
|
|
23
|
+
registerSubgraph(subgraph: SubgraphClass, supergraph?: string): Promise<void>;
|
|
20
24
|
getAdditionalContextFields: () => Record<string, any>;
|
|
21
25
|
setAdditionalContextFields(fields: Record<string, any>): void;
|
|
22
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/subgraphs/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/subgraphs/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,WAAW,CAAC;AAOpC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAG5E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAMnC,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D,qBAAa,eAAe;;IAMxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc;IATjC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,SAAS,CAAkC;gBAGhC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,OAAO,CAAC,OAAO,EACpB,OAAO,EAAE,oBAAoB,EAC7B,gBAAgB,EAAE,EAAE,EACpB,cAAc,EAAE,eAAe;IAS5C,IAAI;IAmBJ,YAAY;IAQlB,OAAO,CAAC,kBAAkB;YAWZ,cAAc;IAiC5B,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,4BAA4B;IAsB9B,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,UAAU,SAAK;IA2B/D,0BAA0B,4BAExB;IAEF,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGvD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSchema } from "#utils/create-schema.js";
|
|
2
|
+
import { ApolloGateway, IntrospectAndCompose } from "@apollo/gateway";
|
|
2
3
|
import { ApolloServer } from "@apollo/server";
|
|
3
4
|
import { expressMiddleware } from "@apollo/server/express4";
|
|
4
5
|
import { ApolloServerPluginInlineTraceDisabled } from "@apollo/server/plugin/disabled";
|
|
@@ -18,7 +19,7 @@ export class SubgraphManager {
|
|
|
18
19
|
analyticsStore;
|
|
19
20
|
reactorRouter = Router();
|
|
20
21
|
contextFields = {};
|
|
21
|
-
subgraphs =
|
|
22
|
+
subgraphs = {};
|
|
22
23
|
constructor(path, app, reactor, operationalStore, analyticsStore) {
|
|
23
24
|
this.path = path;
|
|
24
25
|
this.app = app;
|
|
@@ -42,47 +43,85 @@ export class SubgraphManager {
|
|
|
42
43
|
this.updateRouter().catch((error) => console.error(error));
|
|
43
44
|
});
|
|
44
45
|
this.app.use(this.path, (req, res, next) => this.reactorRouter(req, res, next));
|
|
45
|
-
await this.updateRouter();
|
|
46
46
|
}
|
|
47
47
|
async updateRouter() {
|
|
48
48
|
const newRouter = Router();
|
|
49
49
|
newRouter.use(cors());
|
|
50
50
|
newRouter.use(bodyParser.json());
|
|
51
|
-
|
|
52
|
-
for (const subgraph of this.subgraphs) {
|
|
53
|
-
const subgraphConfig = this.#getLocalSubgraphConfig(subgraph.name);
|
|
54
|
-
if (!subgraphConfig)
|
|
55
|
-
continue;
|
|
56
|
-
// get schema
|
|
57
|
-
const schema = createSchema(this.reactor, subgraphConfig.resolvers, subgraphConfig.typeDefs);
|
|
58
|
-
// create apollo server
|
|
59
|
-
const server = new ApolloServer({
|
|
60
|
-
schema,
|
|
61
|
-
introspection: true,
|
|
62
|
-
plugins: [
|
|
63
|
-
ApolloServerPluginInlineTraceDisabled(),
|
|
64
|
-
ApolloServerPluginLandingPageLocalDefault(),
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
// start apollo server
|
|
68
|
-
await server.start();
|
|
69
|
-
// setup path
|
|
70
|
-
const path = `/${subgraphConfig.name}`;
|
|
71
|
-
newRouter.use(path,
|
|
72
|
-
// @ts-expect-error todo check type defs
|
|
73
|
-
expressMiddleware(server, {
|
|
74
|
-
context: ({ req }) => ({
|
|
75
|
-
headers: req.headers,
|
|
76
|
-
driveId: req.params.drive ?? undefined,
|
|
77
|
-
driveServer: this.reactor,
|
|
78
|
-
db: this.operationalStore,
|
|
79
|
-
...this.getAdditionalContextFields(),
|
|
80
|
-
}),
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
51
|
+
await this.setupSubgraphs(newRouter);
|
|
83
52
|
this.reactorRouter = newRouter;
|
|
84
53
|
}
|
|
85
|
-
|
|
54
|
+
createApolloServer(schema) {
|
|
55
|
+
return new ApolloServer({
|
|
56
|
+
schema,
|
|
57
|
+
introspection: true,
|
|
58
|
+
plugins: [
|
|
59
|
+
ApolloServerPluginInlineTraceDisabled(),
|
|
60
|
+
ApolloServerPluginLandingPageLocalDefault(),
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async setupSubgraphs(router) {
|
|
65
|
+
for (const supergraph of Object.keys(this.subgraphs)) {
|
|
66
|
+
const supergraphEndpoints = {};
|
|
67
|
+
for (const subgraph of this.subgraphs[supergraph]) {
|
|
68
|
+
const subgraphConfig = this.#getLocalSubgraphConfig(subgraph.name);
|
|
69
|
+
if (!subgraphConfig)
|
|
70
|
+
continue;
|
|
71
|
+
// create subgraph schema
|
|
72
|
+
const schema = createSchema(this.reactor, subgraphConfig.resolvers, subgraphConfig.typeDefs);
|
|
73
|
+
// create and start apollo server
|
|
74
|
+
const server = this.createApolloServer(schema);
|
|
75
|
+
await server.start();
|
|
76
|
+
const path = `/${subgraphConfig.name}`;
|
|
77
|
+
this.setupApolloExpressMiddleware(server, router, path);
|
|
78
|
+
if (supergraph !== "") {
|
|
79
|
+
supergraphEndpoints[path] = server;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(supergraphEndpoints).length > 0) {
|
|
83
|
+
const supergraphServer = this.createApolloGateway(supergraphEndpoints);
|
|
84
|
+
await supergraphServer.start();
|
|
85
|
+
const path = `/${supergraph}`;
|
|
86
|
+
this.setupApolloExpressMiddleware(supergraphServer, router, path);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
createApolloGateway(endpoints) {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
92
|
+
const gateway = new ApolloGateway({
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
94
|
+
supergraphSdl: new IntrospectAndCompose({
|
|
95
|
+
subgraphs: Object.keys(endpoints).map((path) => ({
|
|
96
|
+
name: path.replaceAll("/", ""),
|
|
97
|
+
url: `http://localhost:${process.env.PORT ?? 4001}${path}`,
|
|
98
|
+
})),
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
return new ApolloServer({
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
103
|
+
gateway,
|
|
104
|
+
plugins: [
|
|
105
|
+
ApolloServerPluginInlineTraceDisabled(),
|
|
106
|
+
ApolloServerPluginLandingPageLocalDefault(),
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
setupApolloExpressMiddleware(server, router, path) {
|
|
111
|
+
router.use(path,
|
|
112
|
+
// @ts-expect-error todo check type defs
|
|
113
|
+
expressMiddleware(server, {
|
|
114
|
+
context: ({ req }) => ({
|
|
115
|
+
headers: req.headers,
|
|
116
|
+
driveId: req.params.drive ?? undefined,
|
|
117
|
+
driveServer: this.reactor,
|
|
118
|
+
db: this.operationalStore,
|
|
119
|
+
...this.getAdditionalContextFields(),
|
|
120
|
+
}),
|
|
121
|
+
}));
|
|
122
|
+
this.reactorRouter = router;
|
|
123
|
+
}
|
|
124
|
+
async registerSubgraph(subgraph, supergraph = "") {
|
|
86
125
|
const subgraphInstance = new subgraph({
|
|
87
126
|
operationalStore: this.operationalStore,
|
|
88
127
|
analyticsStore: this.analyticsStore,
|
|
@@ -90,12 +129,21 @@ export class SubgraphManager {
|
|
|
90
129
|
subgraphManager: this,
|
|
91
130
|
});
|
|
92
131
|
await subgraphInstance.onSetup();
|
|
93
|
-
this.subgraphs
|
|
132
|
+
if (!this.subgraphs[supergraph]) {
|
|
133
|
+
this.subgraphs[supergraph] = [];
|
|
134
|
+
}
|
|
135
|
+
this.subgraphs[supergraph].push(subgraphInstance);
|
|
94
136
|
console.log(`> Registered ${this.path.endsWith("/") ? this.path : this.path + "/"}${subgraphInstance.name} subgraph.`);
|
|
95
137
|
await this.updateRouter();
|
|
96
138
|
}
|
|
97
139
|
#getLocalSubgraphConfig(subgraphName) {
|
|
98
|
-
|
|
140
|
+
let entry;
|
|
141
|
+
for (const supergraph of Object.keys(this.subgraphs)) {
|
|
142
|
+
entry = this.subgraphs[supergraph].find((it) => it.name === subgraphName);
|
|
143
|
+
if (entry)
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
return entry;
|
|
99
147
|
}
|
|
100
148
|
getAdditionalContextFields = () => {
|
|
101
149
|
return this.contextFields;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Context } from "#subgraphs/types.js";
|
|
2
|
-
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
3
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
4
|
-
import { DocumentNode } from "graphql";
|
|
1
|
+
import { type Context } from "#subgraphs/types.js";
|
|
2
|
+
import { type GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
3
|
+
import { type IDocumentDriveServer } from "document-drive";
|
|
4
|
+
import { type DocumentNode } from "graphql";
|
|
5
5
|
export declare const createSchema: (documentDriveServer: IDocumentDriveServer, resolvers: GraphQLResolverMap<Context>, typeDefs: DocumentNode) => import("graphql").GraphQLSchema;
|
|
6
6
|
export declare const getDocumentModelTypeDefs: (documentDriveServer: IDocumentDriveServer, typeDefs: DocumentNode) => DocumentNode;
|
|
7
7
|
//# sourceMappingURL=create-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-schema.d.ts","sourceRoot":"","sources":["../../../src/utils/create-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-schema.d.ts","sourceRoot":"","sources":["../../../src/utils/create-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AAG7F,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,YAAY,GACvB,qBAAqB,oBAAoB,EACzC,WAAW,kBAAkB,CAAC,OAAO,CAAC,EACtC,UAAU,YAAY,oCAOpB,CAAC;AAEL,eAAO,MAAM,wBAAwB,GACnC,qBAAqB,oBAAoB,EACzC,UAAU,YAAY,iBAwIvB,CAAC"}
|