@powerhousedao/reactor-api 1.21.2 → 1.22.0
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/index.d.ts +8 -503
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -27020
- package/dist/src/processors/analytics-processor.d.ts +9 -0
- package/dist/src/processors/analytics-processor.d.ts.map +1 -0
- package/dist/src/processors/analytics-processor.js +9 -0
- package/dist/src/processors/index.d.ts +5 -0
- package/dist/src/processors/index.d.ts.map +1 -0
- package/dist/src/processors/index.js +4 -0
- package/dist/src/processors/manager.d.ts +14 -0
- package/dist/src/processors/manager.d.ts.map +1 -0
- package/dist/src/processors/manager.js +40 -0
- package/dist/src/processors/operational-processor.d.ts +8 -0
- package/dist/src/processors/operational-processor.d.ts.map +1 -0
- package/dist/src/processors/operational-processor.js +12 -0
- package/dist/src/processors/processor.d.ts +20 -0
- package/dist/src/processors/processor.d.ts.map +1 -0
- package/dist/src/processors/processor.js +45 -0
- package/dist/src/server.d.ts +18 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +51 -0
- package/dist/src/subgraphs/analytics/index.d.ts +16 -0
- package/dist/src/subgraphs/analytics/index.d.ts.map +1 -0
- package/dist/src/subgraphs/analytics/index.js +85 -0
- package/dist/src/subgraphs/auth/env/getters.d.ts +3 -0
- package/dist/src/subgraphs/auth/env/getters.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/env/getters.js +26 -0
- package/dist/src/subgraphs/auth/env/index.d.ts +8 -0
- package/dist/src/subgraphs/auth/env/index.d.ts.map +1 -0
- package/{src/subgraphs/auth/env/index.ts → dist/src/subgraphs/auth/env/index.js} +4 -6
- package/dist/src/subgraphs/auth/index.d.ts +11 -0
- package/dist/src/subgraphs/auth/index.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/index.js +259 -0
- package/dist/src/subgraphs/auth/types.d.ts +35 -0
- package/dist/src/subgraphs/auth/types.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/types.js +1 -0
- package/dist/src/subgraphs/auth/utils/helpers.d.ts +12 -0
- package/dist/src/subgraphs/auth/utils/helpers.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/utils/helpers.js +100 -0
- package/dist/src/subgraphs/auth/utils/session.d.ts +22 -0
- package/dist/src/subgraphs/auth/utils/session.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/utils/session.js +100 -0
- package/dist/src/subgraphs/auth/utils/user.d.ts +12 -0
- package/dist/src/subgraphs/auth/utils/user.d.ts.map +1 -0
- package/dist/src/subgraphs/auth/utils/user.js +26 -0
- package/dist/src/subgraphs/base/index.d.ts +16 -0
- package/dist/src/subgraphs/base/index.d.ts.map +1 -0
- package/dist/src/subgraphs/base/index.js +25 -0
- package/dist/src/subgraphs/drive/index.d.ts +11 -0
- package/dist/src/subgraphs/drive/index.d.ts.map +1 -0
- package/dist/src/subgraphs/drive/index.js +341 -0
- package/dist/src/subgraphs/drive/temp-hack-rwa-type-defs.d.ts +57 -0
- package/dist/src/subgraphs/drive/temp-hack-rwa-type-defs.d.ts.map +1 -0
- package/dist/src/subgraphs/drive/temp-hack-rwa-type-defs.js +1 -0
- package/dist/src/subgraphs/index.d.ts +10 -0
- package/dist/src/subgraphs/index.d.ts.map +1 -0
- package/dist/src/subgraphs/index.js +20 -0
- package/dist/src/subgraphs/manager.d.ts +23 -0
- package/dist/src/subgraphs/manager.d.ts.map +1 -0
- package/dist/src/subgraphs/manager.js +102 -0
- package/dist/src/subgraphs/system/env/getters.d.ts +2 -0
- package/dist/src/subgraphs/system/env/getters.d.ts.map +1 -0
- package/dist/src/subgraphs/system/env/getters.js +3 -0
- package/dist/src/subgraphs/system/env/index.d.ts +2 -0
- package/dist/src/subgraphs/system/env/index.d.ts.map +1 -0
- package/{src/subgraphs/system/env/index.ts → dist/src/subgraphs/system/env/index.js} +1 -3
- package/dist/src/subgraphs/system/index.d.ts +19 -0
- package/dist/src/subgraphs/system/index.d.ts.map +1 -0
- package/dist/src/subgraphs/system/index.js +63 -0
- package/dist/src/subgraphs/system/types.d.ts +5 -0
- package/dist/src/subgraphs/system/types.d.ts.map +1 -0
- package/dist/src/subgraphs/system/types.js +1 -0
- package/dist/src/subgraphs/types.d.ts +27 -0
- package/dist/src/subgraphs/types.d.ts.map +1 -0
- package/dist/src/subgraphs/types.js +1 -0
- package/dist/src/sync/utils.d.ts +13 -0
- package/dist/src/sync/utils.d.ts.map +1 -0
- package/dist/src/sync/utils.js +37 -0
- package/dist/src/types.d.ts +29 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils/create-schema.d.ts +7 -0
- package/dist/src/utils/create-schema.d.ts.map +1 -0
- package/dist/src/utils/create-schema.js +122 -0
- package/dist/src/utils/db.d.ts +4 -0
- package/dist/src/utils/db.d.ts.map +1 -0
- package/dist/src/utils/db.js +20 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +24 -0
- package/package.json +18 -9
- package/CHANGELOG.md +0 -39
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -7
- package/src/processors/analytics-processor.ts +0 -18
- package/src/processors/index.ts +0 -4
- package/src/processors/manager.ts +0 -75
- package/src/processors/operational-processor.ts +0 -20
- package/src/processors/processor.ts +0 -75
- package/src/server.ts +0 -65
- package/src/subgraphs/analytics/index.ts +0 -119
- package/src/subgraphs/auth/env/getters.ts +0 -30
- package/src/subgraphs/auth/index.ts +0 -321
- package/src/subgraphs/auth/types.ts +0 -39
- package/src/subgraphs/auth/utils/helpers.ts +0 -132
- package/src/subgraphs/auth/utils/session.ts +0 -144
- package/src/subgraphs/auth/utils/user.ts +0 -40
- package/src/subgraphs/base/index.ts +0 -34
- package/src/subgraphs/drive/index.ts +0 -434
- package/src/subgraphs/drive/temp-hack-rwa-type-defs.ts +0 -39
- package/src/subgraphs/index.ts +0 -24
- package/src/subgraphs/manager.ts +0 -128
- package/src/subgraphs/system/env/getters.ts +0 -7
- package/src/subgraphs/system/index.ts +0 -73
- package/src/subgraphs/system/types.ts +0 -5
- package/src/subgraphs/types.ts +0 -29
- package/src/sync/utils.ts +0 -85
- package/src/types.ts +0 -43
- package/src/utils/create-schema.ts +0 -160
- package/src/utils/db.ts +0 -26
- package/src/utils/index.ts +0 -2
- package/test/benchmarks/load.bench.ts +0 -78
- package/test/benchmarks/sync.bench.ts +0 -151
- package/test/data/BlocktowerAndromeda.zip +0 -0
- package/test/router.test.ts +0 -48
- package/tsconfig.json +0 -21
- package/tsdoc.json +0 -3
- package/tsup.config.ts +0 -17
- package/types.d.ts +0 -5
- package/vitest.config.ts +0 -28
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { Subgraph } from "#subgraphs/base/index.js";
|
|
2
|
+
import { processAcknowledge, processGetStrands, processPushUpdate, } from "#sync/utils.js";
|
|
3
|
+
import { pascalCase } from "change-case";
|
|
4
|
+
import { addListener, childLogger, generateUUID, } from "document-drive";
|
|
5
|
+
import { gql } from "graphql-tag";
|
|
6
|
+
const driveKindTypeNames = {
|
|
7
|
+
file: "DocumentDrive_FileNode",
|
|
8
|
+
folder: "DocumentDrive_FolderNode",
|
|
9
|
+
};
|
|
10
|
+
export class DriveSubgraph extends Subgraph {
|
|
11
|
+
logger = childLogger([
|
|
12
|
+
"DriveSubgraph",
|
|
13
|
+
Math.floor(Math.random() * 999).toString(),
|
|
14
|
+
]);
|
|
15
|
+
constructor(args) {
|
|
16
|
+
super(args);
|
|
17
|
+
this.logger.verbose(`constructor()`);
|
|
18
|
+
}
|
|
19
|
+
name = "d/:drive";
|
|
20
|
+
typeDefs = gql `
|
|
21
|
+
type DriveMeta {
|
|
22
|
+
preferredEditor: String
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
extend type DocumentDrive_DocumentDriveState {
|
|
26
|
+
meta: DriveMeta
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Query {
|
|
30
|
+
system: System
|
|
31
|
+
drive: DocumentDrive_DocumentDriveState
|
|
32
|
+
document(id: String!): IDocument
|
|
33
|
+
documents: [String!]!
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type Mutation {
|
|
37
|
+
registerPullResponderListener(
|
|
38
|
+
filter: InputListenerFilter!
|
|
39
|
+
): DocumentDrive_Listener
|
|
40
|
+
pushUpdates(strands: [InputStrandUpdate!]): [ListenerRevision!]!
|
|
41
|
+
acknowledge(
|
|
42
|
+
listenerId: String!
|
|
43
|
+
revisions: [ListenerRevisionInput]
|
|
44
|
+
): Boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
input InputOperationSignerUser {
|
|
48
|
+
address: String!
|
|
49
|
+
networkId: String!
|
|
50
|
+
chainId: Int!
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type OperationSignerUser {
|
|
54
|
+
address: String!
|
|
55
|
+
networkId: String!
|
|
56
|
+
chainId: Int!
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
input InputOperationSignerApp {
|
|
60
|
+
name: String!
|
|
61
|
+
key: String!
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type OperationSignerApp {
|
|
65
|
+
name: String!
|
|
66
|
+
key: String!
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type OperationSigner {
|
|
70
|
+
app: OperationSignerApp
|
|
71
|
+
user: OperationSignerUser
|
|
72
|
+
signatures: [[String!]]!
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
input InputOperationSigner {
|
|
76
|
+
app: InputOperationSignerApp
|
|
77
|
+
user: InputOperationSignerUser
|
|
78
|
+
signatures: [[String!]]!
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type OperationContext {
|
|
82
|
+
signer: OperationSigner
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
input InputOperationContext {
|
|
86
|
+
signer: InputOperationSigner
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
input InputOperationUpdate {
|
|
90
|
+
index: Int!
|
|
91
|
+
skip: Int
|
|
92
|
+
type: String!
|
|
93
|
+
id: String!
|
|
94
|
+
input: String!
|
|
95
|
+
hash: String!
|
|
96
|
+
timestamp: String!
|
|
97
|
+
error: String
|
|
98
|
+
context: InputOperationContext
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type OperationUpdate {
|
|
102
|
+
index: Int!
|
|
103
|
+
skip: Int
|
|
104
|
+
type: String!
|
|
105
|
+
id: String!
|
|
106
|
+
input: String!
|
|
107
|
+
hash: String!
|
|
108
|
+
timestamp: String!
|
|
109
|
+
error: String
|
|
110
|
+
context: OperationContext
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
type StrandUpdate {
|
|
114
|
+
driveId: String!
|
|
115
|
+
documentId: String!
|
|
116
|
+
scope: String!
|
|
117
|
+
branch: String!
|
|
118
|
+
operations: [OperationUpdate!]!
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
input InputStrandUpdate {
|
|
122
|
+
driveId: String!
|
|
123
|
+
documentId: String!
|
|
124
|
+
scope: String!
|
|
125
|
+
branch: String!
|
|
126
|
+
operations: [InputOperationUpdate!]!
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
input InputListenerFilter {
|
|
130
|
+
documentType: [String!]
|
|
131
|
+
documentId: [String!]
|
|
132
|
+
scope: [String!]
|
|
133
|
+
branch: [String!]
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
enum UpdateStatus {
|
|
137
|
+
SUCCESS
|
|
138
|
+
MISSING
|
|
139
|
+
CONFLICT
|
|
140
|
+
ERROR
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
input ListenerRevisionInput {
|
|
144
|
+
driveId: String!
|
|
145
|
+
documentId: String!
|
|
146
|
+
scope: String!
|
|
147
|
+
branch: String!
|
|
148
|
+
status: UpdateStatus!
|
|
149
|
+
revision: Int!
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type ListenerRevision {
|
|
153
|
+
driveId: String!
|
|
154
|
+
documentId: String!
|
|
155
|
+
scope: String!
|
|
156
|
+
branch: String!
|
|
157
|
+
status: UpdateStatus!
|
|
158
|
+
revision: Int!
|
|
159
|
+
error: String
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type System {
|
|
163
|
+
sync: Sync
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
type Sync {
|
|
167
|
+
strands(listenerId: ID!, since: String): [StrandUpdate!]!
|
|
168
|
+
}
|
|
169
|
+
`;
|
|
170
|
+
resolvers = {
|
|
171
|
+
Asset: {
|
|
172
|
+
__resolveType: (obj) => {
|
|
173
|
+
return obj.type;
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
Node: {
|
|
177
|
+
__resolveType: (obj) => {
|
|
178
|
+
return obj.documentType ? "FileNode" : "FolderNode";
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
Document: {
|
|
182
|
+
operations: async (obj, { first, skip }, ctx) => {
|
|
183
|
+
const limit = first ?? 0;
|
|
184
|
+
const start = skip ?? 0;
|
|
185
|
+
return obj.operations.global.slice(start, start + limit);
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
Query: {
|
|
189
|
+
drive: async (_, args, ctx) => {
|
|
190
|
+
this.logger.verbose(`drive()`, args);
|
|
191
|
+
if (!ctx.driveId)
|
|
192
|
+
throw new Error("Drive ID is required");
|
|
193
|
+
const drive = await this.reactor.getDrive(ctx.driveId);
|
|
194
|
+
return {
|
|
195
|
+
meta: drive.meta,
|
|
196
|
+
...drive.state.global,
|
|
197
|
+
nodes: drive.state.global.nodes.map((n) => ({
|
|
198
|
+
...n,
|
|
199
|
+
__typename: driveKindTypeNames[n.kind] || "UnkownDriveNode",
|
|
200
|
+
})),
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
documents: async (_, args, ctx) => {
|
|
204
|
+
this.logger.verbose(`documents(drive: ${ctx.driveId})`, args);
|
|
205
|
+
if (!ctx.driveId)
|
|
206
|
+
throw new Error("Drive ID is required");
|
|
207
|
+
const documents = await this.reactor.getDocuments(ctx.driveId);
|
|
208
|
+
return documents;
|
|
209
|
+
},
|
|
210
|
+
document: async (_, { id }, ctx) => {
|
|
211
|
+
this.logger.verbose(`document(drive: ${ctx.driveId}, id: ${id})`);
|
|
212
|
+
if (!ctx.driveId)
|
|
213
|
+
throw new Error("Drive ID is required");
|
|
214
|
+
const document = await this.reactor.getDocument(ctx.driveId, id);
|
|
215
|
+
const dms = this.reactor.getDocumentModelModules();
|
|
216
|
+
const dm = dms.find(({ documentModel }) => documentModel.id === document.documentType);
|
|
217
|
+
const globalState = document.state.global;
|
|
218
|
+
if (!globalState)
|
|
219
|
+
throw new Error("Document not found");
|
|
220
|
+
const typeName = pascalCase((dm?.documentModel.name || "").replaceAll("/", " "));
|
|
221
|
+
const response = {
|
|
222
|
+
...document,
|
|
223
|
+
id,
|
|
224
|
+
revision: document.revision.global,
|
|
225
|
+
state: document.state.global,
|
|
226
|
+
operations: document.operations.global.map((op) => ({
|
|
227
|
+
...op,
|
|
228
|
+
inputText: typeof op.input === "string"
|
|
229
|
+
? op.input
|
|
230
|
+
: JSON.stringify(op.input),
|
|
231
|
+
})),
|
|
232
|
+
initialState: document.initialState.state.global,
|
|
233
|
+
__typename: typeName,
|
|
234
|
+
};
|
|
235
|
+
return response;
|
|
236
|
+
},
|
|
237
|
+
system: () => ({ sync: {} }),
|
|
238
|
+
},
|
|
239
|
+
Mutation: {
|
|
240
|
+
registerPullResponderListener: async (_, { filter }, ctx) => {
|
|
241
|
+
this.logger.verbose(`registerPullResponderListener(drive: ${ctx.driveId})`, filter);
|
|
242
|
+
if (!ctx.driveId)
|
|
243
|
+
throw new Error("Drive ID is required");
|
|
244
|
+
const uuid = generateUUID();
|
|
245
|
+
const listener = {
|
|
246
|
+
block: false,
|
|
247
|
+
callInfo: {
|
|
248
|
+
data: "",
|
|
249
|
+
name: "PullResponder",
|
|
250
|
+
transmitterType: "PullResponder",
|
|
251
|
+
},
|
|
252
|
+
filter: {
|
|
253
|
+
branch: filter.branch ?? [],
|
|
254
|
+
documentId: filter.documentId ?? [],
|
|
255
|
+
documentType: filter.documentType ?? [],
|
|
256
|
+
scope: filter.scope ?? [],
|
|
257
|
+
},
|
|
258
|
+
label: `Pullresponder #${uuid}`,
|
|
259
|
+
listenerId: uuid,
|
|
260
|
+
system: false,
|
|
261
|
+
};
|
|
262
|
+
const result = await this.reactor.queueDriveAction(ctx.driveId, addListener({ listener }));
|
|
263
|
+
if (result.status !== "SUCCESS" && result.error) {
|
|
264
|
+
throw new Error(`Listener couldn't be registered: ${result.error.message}`);
|
|
265
|
+
}
|
|
266
|
+
return listener;
|
|
267
|
+
},
|
|
268
|
+
pushUpdates: async (_, { strands: strandsGql }, ctx) => {
|
|
269
|
+
if (!ctx.driveId)
|
|
270
|
+
throw new Error("Drive ID is required");
|
|
271
|
+
this.logger.verbose(`pushUpdates(drive: ${ctx.driveId})`, strandsGql);
|
|
272
|
+
// translate data types
|
|
273
|
+
const strands = strandsGql.map((strandGql) => {
|
|
274
|
+
return {
|
|
275
|
+
operations: strandGql.operations.map((op) => ({
|
|
276
|
+
...op,
|
|
277
|
+
input: JSON.parse(op.input),
|
|
278
|
+
skip: op.skip ?? 0,
|
|
279
|
+
scope: strandGql.scope,
|
|
280
|
+
branch: "main",
|
|
281
|
+
})),
|
|
282
|
+
documentId: strandGql.documentId,
|
|
283
|
+
driveId: strandGql.driveId,
|
|
284
|
+
scope: strandGql.scope,
|
|
285
|
+
branch: strandGql.branch,
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
// return a list of listener revisions
|
|
289
|
+
return await Promise.all(strands.map((strand) => processPushUpdate(this.reactor, strand)));
|
|
290
|
+
},
|
|
291
|
+
acknowledge: async (_, { listenerId, revisions, }, ctx) => {
|
|
292
|
+
this.logger.verbose(`acknowledge(drive: ${ctx.driveId}, listenerId: ${listenerId})`, revisions);
|
|
293
|
+
if (!listenerId || !revisions)
|
|
294
|
+
return false;
|
|
295
|
+
if (!ctx.driveId)
|
|
296
|
+
throw new Error("Drive ID is required");
|
|
297
|
+
// translate data types
|
|
298
|
+
const validEntries = revisions
|
|
299
|
+
.filter((r) => r !== null)
|
|
300
|
+
.map((e) => ({
|
|
301
|
+
driveId: e.driveId,
|
|
302
|
+
documentId: e.documentId,
|
|
303
|
+
scope: e.scope,
|
|
304
|
+
branch: e.branch,
|
|
305
|
+
revision: e.revision,
|
|
306
|
+
status: e.status,
|
|
307
|
+
}));
|
|
308
|
+
// return a boolean indicating if the acknowledge was successful
|
|
309
|
+
return await processAcknowledge(this.reactor, ctx.driveId, listenerId, validEntries);
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
System: {},
|
|
313
|
+
Sync: {
|
|
314
|
+
strands: async (_, { listenerId, since, }, ctx) => {
|
|
315
|
+
this.logger.verbose(`strands(drive: ${ctx.driveId}, listenerId: ${listenerId}, since:${since})`);
|
|
316
|
+
if (!ctx.driveId)
|
|
317
|
+
throw new Error("Drive ID is required");
|
|
318
|
+
// get the requested strand updates
|
|
319
|
+
const strands = await processGetStrands(this.reactor, ctx.driveId, listenerId, since);
|
|
320
|
+
// translate data types
|
|
321
|
+
return strands.map((update) => ({
|
|
322
|
+
driveId: update.driveId,
|
|
323
|
+
documentId: update.documentId,
|
|
324
|
+
scope: update.scope,
|
|
325
|
+
branch: update.branch,
|
|
326
|
+
operations: update.operations.map((op) => ({
|
|
327
|
+
index: op.index,
|
|
328
|
+
skip: op.skip,
|
|
329
|
+
name: op.type,
|
|
330
|
+
input: JSON.stringify(op.input),
|
|
331
|
+
hash: op.hash,
|
|
332
|
+
timestamp: op.timestamp,
|
|
333
|
+
type: op.type,
|
|
334
|
+
context: op.context,
|
|
335
|
+
id: op.id,
|
|
336
|
+
})),
|
|
337
|
+
}));
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
type Maybe<T> = T | null;
|
|
2
|
+
export type Scalars = {
|
|
3
|
+
ID: {
|
|
4
|
+
input: string;
|
|
5
|
+
output: string;
|
|
6
|
+
};
|
|
7
|
+
String: {
|
|
8
|
+
input: string;
|
|
9
|
+
output: string;
|
|
10
|
+
};
|
|
11
|
+
Boolean: {
|
|
12
|
+
input: boolean;
|
|
13
|
+
output: boolean;
|
|
14
|
+
};
|
|
15
|
+
Int: {
|
|
16
|
+
input: number;
|
|
17
|
+
output: number;
|
|
18
|
+
};
|
|
19
|
+
Float: {
|
|
20
|
+
input: number;
|
|
21
|
+
output: number;
|
|
22
|
+
};
|
|
23
|
+
DateTime: {
|
|
24
|
+
input: string;
|
|
25
|
+
output: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type Asset = Cash | FixedIncome;
|
|
29
|
+
export type AssetType = "Cash" | "FixedIncome";
|
|
30
|
+
export type Cash = {
|
|
31
|
+
balance: Scalars["Float"]["output"];
|
|
32
|
+
currency: Scalars["String"]["output"];
|
|
33
|
+
id: Scalars["ID"]["output"];
|
|
34
|
+
spvId: Scalars["ID"]["output"];
|
|
35
|
+
type: AssetType | AssetType;
|
|
36
|
+
};
|
|
37
|
+
export type FixedIncome = {
|
|
38
|
+
CUSIP: Maybe<Scalars["String"]["output"]>;
|
|
39
|
+
ISIN: Maybe<Scalars["String"]["output"]>;
|
|
40
|
+
assetProceeds: Scalars["Float"]["output"];
|
|
41
|
+
coupon: Maybe<Scalars["Float"]["output"]>;
|
|
42
|
+
fixedIncomeTypeId: Scalars["ID"]["output"];
|
|
43
|
+
id: Scalars["ID"]["output"];
|
|
44
|
+
maturity: Maybe<Scalars["DateTime"]["output"]>;
|
|
45
|
+
name: Scalars["String"]["output"];
|
|
46
|
+
notional: Scalars["Float"]["output"];
|
|
47
|
+
purchaseDate: Scalars["DateTime"]["output"];
|
|
48
|
+
purchasePrice: Scalars["Float"]["output"];
|
|
49
|
+
purchaseProceeds: Scalars["Float"]["output"];
|
|
50
|
+
realizedSurplus: Scalars["Float"]["output"];
|
|
51
|
+
salesProceeds: Scalars["Float"]["output"];
|
|
52
|
+
spvId: Scalars["ID"]["output"];
|
|
53
|
+
totalDiscount: Scalars["Float"]["output"];
|
|
54
|
+
type: AssetType | AssetType;
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=temp-hack-rwa-type-defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temp-hack-rwa-type-defs.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/drive/temp-hack-rwa-type-defs.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,OAAO,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IAC7C,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,KAAK,GAAG,IAAI,GAAG,WAAW,CAAC;AAEvC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,aAAa,CAAC;AAC/C,MAAM,MAAM,IAAI,GAAG;IACjB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;IACtC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1C,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1C,iBAAiB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC3C,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;IAClC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrC,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5C,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC7C,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5C,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1C,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Subgraph } from "./base/index.js";
|
|
2
|
+
export * as analyticsSubgraph from "./analytics/index.js";
|
|
3
|
+
export * as driveSubgraph from "./drive/index.js";
|
|
4
|
+
export * as systemSubgraph from "./system/index.js";
|
|
5
|
+
export * as authSubgraph from "./auth/index.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { Subgraph } from "./base/index.js";
|
|
8
|
+
export type SubgraphClass = typeof Subgraph;
|
|
9
|
+
export declare function isSubgraphClass(candidate: unknown): candidate is SubgraphClass;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/subgraphs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,iBAAiB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,MAAM,aAAa,GAAG,OAAO,QAAQ,CAAC;AAC5C,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,GACjB,SAAS,IAAI,aAAa,CAW5B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Subgraph } from "./base/index.js";
|
|
2
|
+
export * as analyticsSubgraph from "./analytics/index.js";
|
|
3
|
+
export * as driveSubgraph from "./drive/index.js";
|
|
4
|
+
export * as systemSubgraph from "./system/index.js";
|
|
5
|
+
export * as authSubgraph from "./auth/index.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { Subgraph } from "./base/index.js";
|
|
8
|
+
export function isSubgraphClass(candidate) {
|
|
9
|
+
if (typeof candidate !== "function")
|
|
10
|
+
return false;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
12
|
+
let proto = Object.getPrototypeOf(candidate);
|
|
13
|
+
while (proto) {
|
|
14
|
+
if (Object.prototype.isPrototypeOf.call(proto, Subgraph))
|
|
15
|
+
return true;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
17
|
+
proto = Object.getPrototypeOf(proto);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Db } from "#types.js";
|
|
2
|
+
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
3
|
+
import { IDocumentDriveServer } from "document-drive";
|
|
4
|
+
import express from "express";
|
|
5
|
+
import { SubgraphClass } from "./index.js";
|
|
6
|
+
export declare class SubgraphManager {
|
|
7
|
+
#private;
|
|
8
|
+
private readonly path;
|
|
9
|
+
private readonly app;
|
|
10
|
+
private readonly reactor;
|
|
11
|
+
private readonly operationalStore;
|
|
12
|
+
private readonly analyticsStore;
|
|
13
|
+
private reactorRouter;
|
|
14
|
+
private contextFields;
|
|
15
|
+
private subgraphs;
|
|
16
|
+
constructor(path: string, app: express.Express, reactor: IDocumentDriveServer, operationalStore: Db, analyticsStore: IAnalyticsStore);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
updateRouter(): Promise<void>;
|
|
19
|
+
registerSubgraph(subgraph: SubgraphClass): Promise<void>;
|
|
20
|
+
getAdditionalContextFields: () => Record<string, any>;
|
|
21
|
+
setAdditionalContextFields(fields: Record<string, any>): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/subgraphs/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAK/B,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAGvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,OAA4B,MAAM,SAAS,CAAC;AAInD,OAAO,EAAY,aAAa,EAAE,MAAM,YAAY,CAAC;AAIrD,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,CAAkB;gBAGhB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,OAAO,CAAC,OAAO,EACpB,OAAO,EAAE,oBAAoB,EAC7B,gBAAgB,EAAE,EAAE,EACpB,cAAc,EAAE,eAAe;IAS5C,IAAI;IAqBJ,YAAY;IA4CZ,gBAAgB,CAAC,QAAQ,EAAE,aAAa;IAmB9C,0BAA0B,4BAExB;IAEF,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGvD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createSchema } from "#utils/create-schema.js";
|
|
2
|
+
import { ApolloServer } from "@apollo/server";
|
|
3
|
+
import { expressMiddleware } from "@apollo/server/express4";
|
|
4
|
+
import { ApolloServerPluginInlineTraceDisabled } from "@apollo/server/plugin/disabled";
|
|
5
|
+
import bodyParser from "body-parser";
|
|
6
|
+
import cors from "cors";
|
|
7
|
+
import { Router } from "express";
|
|
8
|
+
import { AnalyticsSubgraph } from "./analytics/index.js";
|
|
9
|
+
import { AuthSubgraph } from "./auth/index.js";
|
|
10
|
+
import { DriveSubgraph } from "./drive/index.js";
|
|
11
|
+
import { SystemSubgraph } from "./system/index.js";
|
|
12
|
+
export class SubgraphManager {
|
|
13
|
+
path;
|
|
14
|
+
app;
|
|
15
|
+
reactor;
|
|
16
|
+
operationalStore;
|
|
17
|
+
analyticsStore;
|
|
18
|
+
reactorRouter = Router();
|
|
19
|
+
contextFields = {};
|
|
20
|
+
subgraphs = [];
|
|
21
|
+
constructor(path, app, reactor, operationalStore, analyticsStore) {
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.app = app;
|
|
24
|
+
this.reactor = reactor;
|
|
25
|
+
this.operationalStore = operationalStore;
|
|
26
|
+
this.analyticsStore = analyticsStore;
|
|
27
|
+
// Setup Default subgraphs
|
|
28
|
+
this.registerSubgraph(AuthSubgraph);
|
|
29
|
+
this.registerSubgraph(SystemSubgraph);
|
|
30
|
+
this.registerSubgraph(DriveSubgraph);
|
|
31
|
+
this.registerSubgraph(AnalyticsSubgraph);
|
|
32
|
+
}
|
|
33
|
+
async init() {
|
|
34
|
+
console.log(`Initializing Subgraph Manager...`);
|
|
35
|
+
const models = this.reactor.getDocumentModelModules();
|
|
36
|
+
const driveModel = models.find((it) => it.documentModel.name === "DocumentDrive");
|
|
37
|
+
if (!driveModel) {
|
|
38
|
+
throw new Error("DocumentDrive model required");
|
|
39
|
+
}
|
|
40
|
+
this.reactor.on("documentModelModules", () => {
|
|
41
|
+
this.updateRouter().catch((error) => console.error(error));
|
|
42
|
+
});
|
|
43
|
+
this.app.use(this.path, (req, res, next) => this.reactorRouter(req, res, next));
|
|
44
|
+
await this.updateRouter();
|
|
45
|
+
}
|
|
46
|
+
async updateRouter() {
|
|
47
|
+
const newRouter = Router();
|
|
48
|
+
newRouter.use(cors());
|
|
49
|
+
newRouter.use(bodyParser.json());
|
|
50
|
+
// Run each subgraph on the same http server, but at different paths
|
|
51
|
+
for (const subgraph of this.subgraphs) {
|
|
52
|
+
const subgraphConfig = this.#getLocalSubgraphConfig(subgraph.name);
|
|
53
|
+
if (!subgraphConfig)
|
|
54
|
+
continue;
|
|
55
|
+
// get schema
|
|
56
|
+
const schema = createSchema(this.reactor, subgraphConfig.resolvers, subgraphConfig.typeDefs);
|
|
57
|
+
// create apollo server
|
|
58
|
+
const server = new ApolloServer({
|
|
59
|
+
schema,
|
|
60
|
+
introspection: true,
|
|
61
|
+
plugins: [ApolloServerPluginInlineTraceDisabled()],
|
|
62
|
+
});
|
|
63
|
+
// start apollo server
|
|
64
|
+
await server.start();
|
|
65
|
+
// setup path
|
|
66
|
+
const path = `/${subgraphConfig.name}`;
|
|
67
|
+
newRouter.use(path,
|
|
68
|
+
// @ts-expect-error todo check type defs
|
|
69
|
+
expressMiddleware(server, {
|
|
70
|
+
context: ({ req }) => ({
|
|
71
|
+
headers: req.headers,
|
|
72
|
+
driveId: req.params.drive ?? undefined,
|
|
73
|
+
driveServer: this.reactor,
|
|
74
|
+
db: this.operationalStore,
|
|
75
|
+
...this.getAdditionalContextFields(),
|
|
76
|
+
}),
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
this.reactorRouter = newRouter;
|
|
80
|
+
}
|
|
81
|
+
async registerSubgraph(subgraph) {
|
|
82
|
+
const subgraphInstance = new subgraph({
|
|
83
|
+
operationalStore: this.operationalStore,
|
|
84
|
+
analyticsStore: this.analyticsStore,
|
|
85
|
+
reactor: this.reactor,
|
|
86
|
+
subgraphManager: this,
|
|
87
|
+
});
|
|
88
|
+
await subgraphInstance.onSetup();
|
|
89
|
+
this.subgraphs.unshift(subgraphInstance);
|
|
90
|
+
console.log(`> Registered ${this.path.endsWith("/") ? this.path : this.path + "/"}${subgraphInstance.name} subgraph.`);
|
|
91
|
+
await this.updateRouter();
|
|
92
|
+
}
|
|
93
|
+
#getLocalSubgraphConfig(subgraphName) {
|
|
94
|
+
return this.subgraphs.find((it) => it.name === subgraphName);
|
|
95
|
+
}
|
|
96
|
+
getAdditionalContextFields = () => {
|
|
97
|
+
return this.contextFields;
|
|
98
|
+
};
|
|
99
|
+
setAdditionalContextFields(fields) {
|
|
100
|
+
this.contextFields = { ...this.contextFields, ...fields };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getters.d.ts","sourceRoot":"","sources":["../../../../../src/subgraphs/system/env/getters.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAO,MAAM,EAMtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/subgraphs/system/env/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,UAAkB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Subgraph } from "#subgraphs/index.js";
|
|
2
|
+
import { DriveInput } from "document-drive";
|
|
3
|
+
import { SystemContext } from "./types.js";
|
|
4
|
+
export declare class SystemSubgraph extends Subgraph {
|
|
5
|
+
name: string;
|
|
6
|
+
typeDefs: import("graphql").DocumentNode;
|
|
7
|
+
resolvers: {
|
|
8
|
+
Query: {
|
|
9
|
+
drives: () => Promise<string[]>;
|
|
10
|
+
};
|
|
11
|
+
Mutation: {
|
|
12
|
+
addDrive: (parent: unknown, args: DriveInput & {
|
|
13
|
+
preferredEditor?: string;
|
|
14
|
+
}, ctx: SystemContext) => Promise<import("document-drive").DocumentDriveState>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
onSetup(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/system/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,IAAI,SAAY;IAEhB,QAAQ,iCAsBN;IAEF,SAAS;;;;;+BAQK,OAAO,QACT,UAAU,GAAG;gBAAE,eAAe,CAAC,EAAE,MAAM,CAAA;aAAE,OAC1C,aAAa;;MAkBtB;IAEI,OAAO;CAYd"}
|