@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,63 @@
|
|
|
1
|
+
import { Subgraph } from "#subgraphs/index.js";
|
|
2
|
+
import { GraphQLError } from "graphql";
|
|
3
|
+
import { gql } from "graphql-tag";
|
|
4
|
+
import { ADMIN_USERS } from "./env/index.js";
|
|
5
|
+
export class SystemSubgraph extends Subgraph {
|
|
6
|
+
name = "system";
|
|
7
|
+
typeDefs = gql `
|
|
8
|
+
type Query {
|
|
9
|
+
drives: [String!]!
|
|
10
|
+
driveIdBySlug(slug: String!): String
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Mutation {
|
|
14
|
+
addDrive(
|
|
15
|
+
global: DocumentDriveStateInput!
|
|
16
|
+
preferredEditor: String
|
|
17
|
+
): DocumentDrive_DocumentDriveState
|
|
18
|
+
deleteDrive(id: ID!): Boolean
|
|
19
|
+
setDriveIcon(id: String!, icon: String!): Boolean
|
|
20
|
+
setDriveName(id: String!, name: String!): Boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
input DocumentDriveStateInput {
|
|
24
|
+
name: String
|
|
25
|
+
id: String
|
|
26
|
+
slug: String
|
|
27
|
+
icon: String
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
resolvers = {
|
|
31
|
+
Query: {
|
|
32
|
+
drives: async () => {
|
|
33
|
+
return await this.reactor.getDrives();
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
Mutation: {
|
|
37
|
+
addDrive: async (parent, args, ctx) => {
|
|
38
|
+
try {
|
|
39
|
+
const isAdmin = ctx.isAdmin(ctx);
|
|
40
|
+
if (!isAdmin) {
|
|
41
|
+
throw new GraphQLError("Unauthorized");
|
|
42
|
+
}
|
|
43
|
+
const drive = await this.reactor.addDrive({ global: args.global, local: args.local }, args.preferredEditor);
|
|
44
|
+
return drive.state.global;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
throw new Error(e);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
async onSetup() {
|
|
54
|
+
await super.onSetup();
|
|
55
|
+
this.subgraphManager.setAdditionalContextFields({
|
|
56
|
+
isAdmin: (ctx) => {
|
|
57
|
+
return (ADMIN_USERS.length === 0 ||
|
|
58
|
+
(ctx.session.address &&
|
|
59
|
+
ADMIN_USERS.includes(ctx.session.address.toLocaleLowerCase())));
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/system/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IDocumentDriveServer } from "document-drive";
|
|
2
|
+
import { DocumentNode } from "graphql";
|
|
3
|
+
import type { IncomingHttpHeaders } from "http";
|
|
4
|
+
import { Db } from "#types.js";
|
|
5
|
+
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
6
|
+
import { SubgraphManager } from "./manager.js";
|
|
7
|
+
export type Context = {
|
|
8
|
+
driveServer: IDocumentDriveServer;
|
|
9
|
+
driveId?: string;
|
|
10
|
+
headers: IncomingHttpHeaders;
|
|
11
|
+
db: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type ISubgraph = {
|
|
14
|
+
name: string;
|
|
15
|
+
resolvers: Record<string, any>;
|
|
16
|
+
typeDefs: DocumentNode;
|
|
17
|
+
reactor: IDocumentDriveServer;
|
|
18
|
+
operationalStore: Db;
|
|
19
|
+
onSetup?: () => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export type SubgraphArgs = {
|
|
22
|
+
reactor: IDocumentDriveServer;
|
|
23
|
+
operationalStore: Db;
|
|
24
|
+
analyticsStore: IAnalyticsStore;
|
|
25
|
+
subgraphManager: SubgraphManager;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/subgraphs/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,OAAO,GAAG;IACpB,WAAW,EAAE,oBAAoB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,EAAE,EAAE,OAAO,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gBAAgB,EAAE,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gBAAgB,EAAE,EAAE,CAAC;IACrB,cAAc,EAAE,eAAe,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDocumentDriveServer, ListenerRevision, StrandUpdate } from "document-drive";
|
|
2
|
+
import { Operation, OperationScope } from "document-model";
|
|
3
|
+
export type InternalStrandUpdate = {
|
|
4
|
+
operations: Operation[];
|
|
5
|
+
documentId: string;
|
|
6
|
+
driveId: string;
|
|
7
|
+
scope: OperationScope;
|
|
8
|
+
branch: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const processPushUpdate: (reactor: IDocumentDriveServer, strand: InternalStrandUpdate) => Promise<ListenerRevision>;
|
|
11
|
+
export declare const processAcknowledge: (reactor: IDocumentDriveServer, driveId: string, listenerId: string, revisions: ListenerRevision[]) => Promise<boolean>;
|
|
12
|
+
export declare const processGetStrands: (reactor: IDocumentDriveServer, driveId: string, listenerId: string, since: string | undefined) => Promise<StrandUpdate[]>;
|
|
13
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACpB,gBAAgB,EAEhB,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,eAAO,MAAM,iBAAiB,YACnB,oBAAoB,UACrB,oBAAoB,KAC3B,OAAO,CAAC,gBAAgB,CAkC1B,CAAC;AAGF,eAAO,MAAM,kBAAkB,YACpB,oBAAoB,WACpB,MAAM,cACH,MAAM,aACP,gBAAgB,EAAE,KAC5B,OAAO,CAAC,OAAO,CAMjB,CAAC;AAGF,eAAO,MAAM,iBAAiB,YACnB,oBAAoB,WACpB,MAAM,cACH,MAAM,SACX,MAAM,GAAG,SAAS,KACxB,OAAO,CAAC,YAAY,EAAE,CAMxB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// processes a strand update and returns a listener revision
|
|
2
|
+
export const processPushUpdate = async (reactor, strand) => {
|
|
3
|
+
const result = await (strand.documentId !== undefined
|
|
4
|
+
? reactor.queueOperations(strand.driveId, strand.documentId, strand.operations)
|
|
5
|
+
: reactor.queueDriveOperations(strand.driveId, strand.operations));
|
|
6
|
+
const scopeOperations = result.document?.operations[strand.scope] ?? [];
|
|
7
|
+
if (scopeOperations.length === 0) {
|
|
8
|
+
return {
|
|
9
|
+
revision: -1,
|
|
10
|
+
branch: strand.branch,
|
|
11
|
+
documentId: strand.documentId ?? "",
|
|
12
|
+
driveId: strand.driveId,
|
|
13
|
+
scope: strand.scope,
|
|
14
|
+
status: result.status,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const revision = scopeOperations.slice().pop()?.index ?? -1;
|
|
18
|
+
return {
|
|
19
|
+
revision,
|
|
20
|
+
branch: strand.branch,
|
|
21
|
+
documentId: strand.documentId ?? "",
|
|
22
|
+
driveId: strand.driveId,
|
|
23
|
+
scope: strand.scope,
|
|
24
|
+
status: result.status,
|
|
25
|
+
error: result.error?.message || undefined,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
// processes an acknowledge request and returns a boolean
|
|
29
|
+
export const processAcknowledge = async (reactor, driveId, listenerId, revisions) => {
|
|
30
|
+
const transmitter = (await reactor.getTransmitter(driveId, listenerId));
|
|
31
|
+
return transmitter.processAcknowledge(driveId, listenerId, revisions);
|
|
32
|
+
};
|
|
33
|
+
// processes a get strands request and returns a list of strand updates
|
|
34
|
+
export const processGetStrands = async (reactor, driveId, listenerId, since) => {
|
|
35
|
+
const transmitter = (await reactor.getTransmitter(driveId, listenerId));
|
|
36
|
+
return transmitter.getStrands({ since });
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IDocumentDriveServer, IReceiver, Listener } from "document-drive";
|
|
2
|
+
import { Express } from "express";
|
|
3
|
+
import { IAnalyticsStore } from "./processors/analytics-processor.js";
|
|
4
|
+
import { ProcessorClass } from "./processors/processor.js";
|
|
5
|
+
import { SubgraphManager } from "./subgraphs/manager.js";
|
|
6
|
+
import { Db } from "./utils/db.js";
|
|
7
|
+
export type { Db } from "./utils/db.js";
|
|
8
|
+
export type IProcessorManager = {
|
|
9
|
+
registerProcessor(module: IProcessor | ProcessorClass): Promise<IProcessor>;
|
|
10
|
+
};
|
|
11
|
+
export type API = {
|
|
12
|
+
app: Express;
|
|
13
|
+
subgraphManager: SubgraphManager;
|
|
14
|
+
processorManager: IProcessorManager;
|
|
15
|
+
};
|
|
16
|
+
export type ProcessorType = "analytics" | "operational";
|
|
17
|
+
export type ProcessorSetupArgs = {
|
|
18
|
+
reactor: IDocumentDriveServer;
|
|
19
|
+
operationalStore: Db;
|
|
20
|
+
analyticsStore: IAnalyticsStore;
|
|
21
|
+
};
|
|
22
|
+
export type IProcessor = IReceiver & {
|
|
23
|
+
onSetup?: (args: ProcessorSetupArgs) => void;
|
|
24
|
+
getOptions: () => ProcessorOptions;
|
|
25
|
+
};
|
|
26
|
+
export type ProcessorOptions = Omit<Listener, "driveId" | "callInfo"> & {
|
|
27
|
+
label: string;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAEnC,YAAY,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7E,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,gBAAgB,EAAE,iBAAiB,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,aAAa,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gBAAgB,EAAE,EAAE,CAAC;IACrB,cAAc,EAAE,eAAe,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG;IACnC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,UAAU,EAAE,MAAM,gBAAgB,CAAC;CACpC,CAAC;AAQF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,GAAG,UAAU,CAAC,GAAG;IACtE,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +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";
|
|
5
|
+
export declare const createSchema: (documentDriveServer: IDocumentDriveServer, resolvers: GraphQLResolverMap<Context>, typeDefs: DocumentNode) => import("graphql").GraphQLSchema;
|
|
6
|
+
export declare const getDocumentModelTypeDefs: (documentDriveServer: IDocumentDriveServer, typeDefs: DocumentNode) => DocumentNode;
|
|
7
|
+
//# sourceMappingURL=create-schema.d.ts.map
|
|
@@ -0,0 +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;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AAGxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,eAAO,MAAM,YAAY,wBACF,oBAAoB,aAC9B,kBAAkB,CAAC,OAAO,CAAC,YAC5B,YAAY,oCAOpB,CAAC;AAEL,eAAO,MAAM,wBAAwB,wBACd,oBAAoB,YAC/B,YAAY,iBAwIvB,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
2
|
+
import { typeDefs as scalarsTypeDefs } from "@powerhousedao/scalars";
|
|
3
|
+
import { pascalCase } from "change-case";
|
|
4
|
+
import { gql } from "graphql-tag";
|
|
5
|
+
export const createSchema = (documentDriveServer, resolvers, typeDefs) => buildSubgraphSchema([
|
|
6
|
+
{
|
|
7
|
+
typeDefs: getDocumentModelTypeDefs(documentDriveServer, typeDefs),
|
|
8
|
+
resolvers,
|
|
9
|
+
},
|
|
10
|
+
]);
|
|
11
|
+
export const getDocumentModelTypeDefs = (documentDriveServer, typeDefs) => {
|
|
12
|
+
const documentModels = documentDriveServer.getDocumentModelModules();
|
|
13
|
+
let dmSchema = "";
|
|
14
|
+
documentModels.forEach(({ documentModel }) => {
|
|
15
|
+
const dmSchemaName = pascalCase(documentModel.name.replaceAll("/", " "));
|
|
16
|
+
let tmpDmSchema = `
|
|
17
|
+
${documentModel.specifications
|
|
18
|
+
.map((specification) => specification.state.global.schema
|
|
19
|
+
.replaceAll("scalar DateTime", "")
|
|
20
|
+
.replaceAll(/input (.*?) {[\s\S]*?}/g, ""))
|
|
21
|
+
.join("\n")};
|
|
22
|
+
|
|
23
|
+
${documentModel.specifications
|
|
24
|
+
.map((specification) => specification.state.local.schema
|
|
25
|
+
.replaceAll("scalar DateTime", "")
|
|
26
|
+
.replaceAll(/input (.*?) {[\s\S]*?}/g, "")
|
|
27
|
+
.replaceAll("type AccountSnapshotLocalState", "")
|
|
28
|
+
.replaceAll("type BudgetStatementLocalState", "")
|
|
29
|
+
.replaceAll("type ScopeFrameworkLocalState", ""))
|
|
30
|
+
.join("\n")};
|
|
31
|
+
|
|
32
|
+
\n`;
|
|
33
|
+
const found = tmpDmSchema.match(/(type|enum|union)\s+(\w+)\s/g);
|
|
34
|
+
const trimmedFound = found?.map((f) => f
|
|
35
|
+
.replaceAll("type ", "")
|
|
36
|
+
.replaceAll("enum ", "")
|
|
37
|
+
.replaceAll("union ", "")
|
|
38
|
+
.trim());
|
|
39
|
+
trimmedFound?.forEach((f) => {
|
|
40
|
+
// Create a regex that matches the type name with proper boundaries
|
|
41
|
+
const typeRegex = new RegExp(
|
|
42
|
+
// Match type references in various GraphQL contexts
|
|
43
|
+
`(?<![_A-Za-z0-9])(${f})(?![_A-Za-z0-9])|` + // Basic type references
|
|
44
|
+
`\\[(${f})\\]|` + // Array types without nullability
|
|
45
|
+
`\\[(${f})!\\]|` + // Array of non-null types
|
|
46
|
+
`\\[(${f})\\]!|` + // Non-null array of types
|
|
47
|
+
`\\[(${f})!\\]!`, // Non-null array of non-null types
|
|
48
|
+
"g");
|
|
49
|
+
tmpDmSchema = tmpDmSchema.replace(typeRegex, (match, p1, p2, p3, p4, p5) => {
|
|
50
|
+
// If it's an array type, preserve the brackets and ! while replacing the type name
|
|
51
|
+
if (match.startsWith("[")) {
|
|
52
|
+
return match.replace(p2 || p3 || p4 || p5, `${dmSchemaName}_${p2 || p3 || p4 || p5}`);
|
|
53
|
+
}
|
|
54
|
+
// Basic type reference
|
|
55
|
+
return `${dmSchemaName}_${p1}`;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
dmSchema += tmpDmSchema;
|
|
59
|
+
dmSchema += `
|
|
60
|
+
type ${dmSchemaName} implements IDocument {
|
|
61
|
+
id: String!
|
|
62
|
+
name: String!
|
|
63
|
+
documentType: String!
|
|
64
|
+
operations(skip: Int, first: Int): [Operation!]!
|
|
65
|
+
revision: Int!
|
|
66
|
+
created: DateTime!
|
|
67
|
+
lastModified: DateTime!
|
|
68
|
+
${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
69
|
+
${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
70
|
+
}\n`;
|
|
71
|
+
});
|
|
72
|
+
// add the mutation and query types
|
|
73
|
+
const schema = gql `
|
|
74
|
+
${scalarsTypeDefs.join("\n").replaceAll(";", "")}
|
|
75
|
+
|
|
76
|
+
type PHOperationContext {
|
|
77
|
+
signer: Signer
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type Signer {
|
|
81
|
+
user: SignerUser
|
|
82
|
+
app: SignerApp
|
|
83
|
+
signatures: [String!]!
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type SignerUser {
|
|
87
|
+
address: String!
|
|
88
|
+
networkId: String!
|
|
89
|
+
chainId: Int!
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type SignerApp {
|
|
93
|
+
name: String!
|
|
94
|
+
key: String!
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type Operation {
|
|
98
|
+
id: String!
|
|
99
|
+
type: String!
|
|
100
|
+
index: Int!
|
|
101
|
+
timestamp: DateTime!
|
|
102
|
+
hash: String!
|
|
103
|
+
skip: Int
|
|
104
|
+
inputText: String
|
|
105
|
+
error: String
|
|
106
|
+
context: PHOperationContext
|
|
107
|
+
}
|
|
108
|
+
interface IDocument {
|
|
109
|
+
id: String!
|
|
110
|
+
name: String!
|
|
111
|
+
documentType: String!
|
|
112
|
+
revision: Int!
|
|
113
|
+
created: DateTime!
|
|
114
|
+
lastModified: DateTime!
|
|
115
|
+
operations(first: Int, skip: Int): [Operation!]!
|
|
116
|
+
}
|
|
117
|
+
${dmSchema.replaceAll(";", "")}
|
|
118
|
+
|
|
119
|
+
${typeDefs}
|
|
120
|
+
`;
|
|
121
|
+
return schema;
|
|
122
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../../src/utils/db.ts"],"names":[],"mappings":"AACA,OAAa,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AAGvC,MAAM,MAAM,EAAE,GAAG,IAAI,CAAC;AAStB,wBAAgB,WAAW,CACzB,gBAAgB,GAAE,MAAM,GAAG,SAAqB,GAC/C,EAAE,CAUJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import knex from "knex";
|
|
3
|
+
import ClientPgLite from "knex-pglite";
|
|
4
|
+
function isPG(connectionString) {
|
|
5
|
+
if (connectionString.startsWith("postgres://")) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
export function getDbClient(connectionString = undefined) {
|
|
11
|
+
const isPg = connectionString && isPG(connectionString);
|
|
12
|
+
const client = isPg ? "pg" : ClientPgLite;
|
|
13
|
+
const connection = isPg
|
|
14
|
+
? { connectionString }
|
|
15
|
+
: { pglite: new PGlite(connectionString) };
|
|
16
|
+
return knex({
|
|
17
|
+
client,
|
|
18
|
+
connection,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
|