@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,9 @@
|
|
|
1
|
+
import { ProcessorOptions, ProcessorSetupArgs } from "#types.js";
|
|
2
|
+
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
3
|
+
import { Processor } from "./processor.js";
|
|
4
|
+
export * from "@powerhousedao/analytics-engine-core";
|
|
5
|
+
export declare abstract class AnalyticsProcessor extends Processor {
|
|
6
|
+
protected analyticsStore: IAnalyticsStore;
|
|
7
|
+
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=analytics-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-processor.d.ts","sourceRoot":"","sources":["../../../src/processors/analytics-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,cAAc,sCAAsC,CAAC;AAErD,8BAAsB,kBAAmB,SAAQ,SAAS;IACxD,SAAS,CAAC,cAAc,EAAE,eAAe,CAAC;gBAE9B,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,gBAAgB;CAIjE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Processor } from "./processor.js";
|
|
2
|
+
export * from "@powerhousedao/analytics-engine-core";
|
|
3
|
+
export class AnalyticsProcessor extends Processor {
|
|
4
|
+
analyticsStore;
|
|
5
|
+
constructor(args, options) {
|
|
6
|
+
super(args, options);
|
|
7
|
+
this.analyticsStore = args.analyticsStore;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/processors/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IDocumentDriveServer } from "document-drive";
|
|
2
|
+
import { IAnalyticsStore } from "#processors/analytics-processor.js";
|
|
3
|
+
import { ProcessorClass } from "#processors/processor.js";
|
|
4
|
+
import { Db, IProcessor, IProcessorManager } from "#types.js";
|
|
5
|
+
export declare class ProcessorManager implements IProcessorManager {
|
|
6
|
+
#private;
|
|
7
|
+
private operationalStore;
|
|
8
|
+
private analyticsStore;
|
|
9
|
+
private reactor;
|
|
10
|
+
private processors;
|
|
11
|
+
constructor(driveServer: IDocumentDriveServer, operationalStore: Db, analyticsStore: IAnalyticsStore);
|
|
12
|
+
registerProcessor(module: IProcessor | ProcessorClass): Promise<IProcessor>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/processors/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAoB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,EAAE,EACF,UAAU,EACV,iBAAiB,EAElB,MAAM,WAAW,CAAC;AAEnB,qBAAa,gBAAiB,YAAW,iBAAiB;;IAMtD,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,cAAc;IANxB,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,UAAU,CAAoB;gBAGpC,WAAW,EAAE,oBAAoB,EACzB,gBAAgB,EAAE,EAAE,EACpB,cAAc,EAAE,eAAe;IAyCnC,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc;CAc5D"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isProcessorClass } from "#processors/processor.js";
|
|
2
|
+
export class ProcessorManager {
|
|
3
|
+
operationalStore;
|
|
4
|
+
analyticsStore;
|
|
5
|
+
reactor;
|
|
6
|
+
processors = [];
|
|
7
|
+
constructor(driveServer, operationalStore, analyticsStore) {
|
|
8
|
+
this.operationalStore = operationalStore;
|
|
9
|
+
this.analyticsStore = analyticsStore;
|
|
10
|
+
this.reactor = driveServer;
|
|
11
|
+
driveServer.on("driveAdded", this.#onDriveAdded.bind(this));
|
|
12
|
+
}
|
|
13
|
+
async #onDriveAdded(drive) {
|
|
14
|
+
await Promise.all(this.processors.map((module) => this.reactor.addInternalListener(drive.state.global.id, {
|
|
15
|
+
onStrands: (strands) => module.onStrands(strands),
|
|
16
|
+
onDisconnect: () => module.onDisconnect(),
|
|
17
|
+
}, { ...module.getOptions() })));
|
|
18
|
+
}
|
|
19
|
+
async #onProcessorAdded(processor) {
|
|
20
|
+
const drives = await this.reactor.getDrives();
|
|
21
|
+
const options = processor.getOptions();
|
|
22
|
+
await Promise.all(drives.map((drive) => this.reactor.addInternalListener(drive, {
|
|
23
|
+
onStrands: (strands) => processor.onStrands(strands),
|
|
24
|
+
onDisconnect: () => processor.onDisconnect(),
|
|
25
|
+
}, options)));
|
|
26
|
+
console.log(`> Registered ${options.label} processor.`);
|
|
27
|
+
}
|
|
28
|
+
async registerProcessor(module) {
|
|
29
|
+
const args = {
|
|
30
|
+
reactor: this.reactor,
|
|
31
|
+
operationalStore: this.operationalStore,
|
|
32
|
+
analyticsStore: this.analyticsStore,
|
|
33
|
+
};
|
|
34
|
+
const processor = isProcessorClass(module) ? new module(args) : module;
|
|
35
|
+
processor.onSetup?.(args);
|
|
36
|
+
await this.#onProcessorAdded(processor);
|
|
37
|
+
this.processors.push(processor);
|
|
38
|
+
return processor;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Db, ProcessorOptions, ProcessorSetupArgs } from "#types.js";
|
|
2
|
+
import { Processor } from "./processor.js";
|
|
3
|
+
export declare abstract class OperationalProcessor extends Processor {
|
|
4
|
+
protected operationalStore: Db;
|
|
5
|
+
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions);
|
|
6
|
+
onSetup(args: ProcessorSetupArgs): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=operational-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operational-processor.d.ts","sourceRoot":"","sources":["../../../src/processors/operational-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,8BAAsB,oBAAqB,SAAQ,SAAS;IAC1D,SAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;gBAEnB,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAKhE,OAAO,CAAC,IAAI,EAAE,kBAAkB;CAIjC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Processor } from "./processor.js";
|
|
2
|
+
export class OperationalProcessor extends Processor {
|
|
3
|
+
operationalStore;
|
|
4
|
+
constructor(args, options) {
|
|
5
|
+
super(args, options);
|
|
6
|
+
this.operationalStore = args.operationalStore;
|
|
7
|
+
}
|
|
8
|
+
onSetup(args) {
|
|
9
|
+
super.onSetup(args);
|
|
10
|
+
this.operationalStore = args.operationalStore;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDocumentDriveServer, InternalTransmitterUpdate } from "document-drive";
|
|
2
|
+
import { PHDocument } from "document-model";
|
|
3
|
+
import { IProcessor, ProcessorOptions, ProcessorSetupArgs } from "../types.js";
|
|
4
|
+
export type ProcessorUpdate<TDocument extends PHDocument> = InternalTransmitterUpdate<TDocument>;
|
|
5
|
+
export declare abstract class Processor implements IProcessor {
|
|
6
|
+
protected reactor: IDocumentDriveServer;
|
|
7
|
+
protected processorOptions: ProcessorOptions;
|
|
8
|
+
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions);
|
|
9
|
+
onSetup(args: ProcessorSetupArgs): void;
|
|
10
|
+
abstract onStrands<TDocument extends PHDocument>(strands: ProcessorUpdate<TDocument>[]): Promise<void>;
|
|
11
|
+
abstract onDisconnect(): Promise<void>;
|
|
12
|
+
getOptions(): ProcessorOptions;
|
|
13
|
+
}
|
|
14
|
+
export declare class BaseProcessor extends Processor {
|
|
15
|
+
onStrands<TDocument extends PHDocument>(strands: ProcessorUpdate<TDocument>[]): Promise<void>;
|
|
16
|
+
onDisconnect(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export type ProcessorClass = typeof BaseProcessor;
|
|
19
|
+
export declare function isProcessorClass(candidate: unknown): candidate is ProcessorClass;
|
|
20
|
+
//# sourceMappingURL=processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../../../src/processors/processor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,UAAU,IACtD,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAEvC,8BAAsB,SAAU,YAAW,UAAU;IACnD,SAAS,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACxC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAW1C;gBAEU,IAAI,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAOhE,OAAO,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAIvC,QAAQ,CAAC,SAAS,CAAC,SAAS,SAAS,UAAU,EAC7C,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,GACpC,OAAO,CAAC,IAAI,CAAC;IAEhB,QAAQ,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAEtC,UAAU;CAGX;AAED,qBAAa,aAAc,SAAQ,SAAS;IACpC,SAAS,CAAC,SAAS,SAAS,UAAU,EAC1C,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,GACpC,OAAO,CAAC,IAAI,CAAC;IACV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CACpC;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,aAAa,CAAC;AAGlD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,OAAO,GACjB,SAAS,IAAI,cAAc,CAY7B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class Processor {
|
|
2
|
+
reactor;
|
|
3
|
+
processorOptions = {
|
|
4
|
+
listenerId: "processor",
|
|
5
|
+
filter: {
|
|
6
|
+
branch: ["main"],
|
|
7
|
+
documentId: ["*"],
|
|
8
|
+
documentType: ["*"],
|
|
9
|
+
scope: ["global"],
|
|
10
|
+
},
|
|
11
|
+
block: false,
|
|
12
|
+
label: "processor",
|
|
13
|
+
system: true,
|
|
14
|
+
};
|
|
15
|
+
constructor(args, options) {
|
|
16
|
+
this.reactor = args.reactor;
|
|
17
|
+
if (options) {
|
|
18
|
+
this.processorOptions = { ...this.processorOptions, ...options };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
onSetup(args) {
|
|
22
|
+
this.reactor = args.reactor;
|
|
23
|
+
}
|
|
24
|
+
getOptions() {
|
|
25
|
+
return this.processorOptions;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class BaseProcessor extends Processor {
|
|
29
|
+
async onStrands(strands) { }
|
|
30
|
+
async onDisconnect() { }
|
|
31
|
+
}
|
|
32
|
+
// checks if the provided candidate is a descendant of the Processor class.
|
|
33
|
+
export function isProcessorClass(candidate) {
|
|
34
|
+
if (typeof candidate !== "function")
|
|
35
|
+
return false;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
37
|
+
let proto = Object.getPrototypeOf(candidate);
|
|
38
|
+
while (proto) {
|
|
39
|
+
if (Object.prototype.isPrototypeOf.call(proto, Processor))
|
|
40
|
+
return true;
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
42
|
+
proto = Object.getPrototypeOf(proto);
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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";
|
|
6
|
+
type Options = {
|
|
7
|
+
express?: Express;
|
|
8
|
+
port?: number;
|
|
9
|
+
dbPath: string | undefined;
|
|
10
|
+
client?: PGlite | typeof Pool | undefined;
|
|
11
|
+
https?: {
|
|
12
|
+
keyPath: string;
|
|
13
|
+
certPath: string;
|
|
14
|
+
} | boolean | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare function startAPI(reactor: IDocumentDriveServer, options: Options): Promise<API>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAM9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAK3C,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAG1B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,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,CAkDd"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KnexAnalyticsStore, KnexQueryExecutor, } from "@powerhousedao/analytics-engine-knex";
|
|
2
|
+
import devcert from "devcert";
|
|
3
|
+
import express from "express";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import https from "node:https";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { ProcessorManager } from "#processors/index.js";
|
|
8
|
+
import { SubgraphManager } from "#subgraphs/manager.js";
|
|
9
|
+
import { getDbClient } from "./utils/db.js";
|
|
10
|
+
const DEFAULT_PORT = 4000;
|
|
11
|
+
export async function startAPI(reactor, options) {
|
|
12
|
+
const port = options.port ?? DEFAULT_PORT;
|
|
13
|
+
const app = options.express ?? express();
|
|
14
|
+
const db = getDbClient(options.dbPath);
|
|
15
|
+
const analyticsStore = new KnexAnalyticsStore({
|
|
16
|
+
executor: new KnexQueryExecutor(),
|
|
17
|
+
knex: db,
|
|
18
|
+
}); // TODO update @powerhousedao/analytics-engine-pg to use @powerhousedao/analytics-engine-core@0.3.2
|
|
19
|
+
const subgraphManager = new SubgraphManager("/", app, reactor, db, analyticsStore);
|
|
20
|
+
await subgraphManager.init();
|
|
21
|
+
const processorManager = new ProcessorManager(reactor, db, analyticsStore);
|
|
22
|
+
if (options.https) {
|
|
23
|
+
const currentDir = process.cwd();
|
|
24
|
+
let server;
|
|
25
|
+
if (typeof options.https === "object") {
|
|
26
|
+
server = https.createServer({
|
|
27
|
+
key: fs.readFileSync(path.join(currentDir, options.https.keyPath)),
|
|
28
|
+
cert: fs.readFileSync(path.join(currentDir, options.https.certPath)),
|
|
29
|
+
}, app);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
try {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
34
|
+
const { cert, key } = (await devcert.certificateFor("localhost"));
|
|
35
|
+
if (!cert || !key) {
|
|
36
|
+
throw new Error("Invalid certificate generated");
|
|
37
|
+
}
|
|
38
|
+
server = https.createServer({ cert, key }, app);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.error("Failed to get HTTPS certificate:", err);
|
|
42
|
+
throw new Error("Failed to start HTTPS server");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
server.listen(port);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
app.listen(port);
|
|
49
|
+
}
|
|
50
|
+
return { app, subgraphManager, processorManager };
|
|
51
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
2
|
+
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
3
|
+
import { AnalyticsModel } from "@powerhousedao/analytics-engine-graphql";
|
|
4
|
+
import { Subgraph } from "../base/index.js";
|
|
5
|
+
import { Context, SubgraphArgs } from "../index.js";
|
|
6
|
+
export declare class AnalyticsSubgraph extends Subgraph {
|
|
7
|
+
#private;
|
|
8
|
+
analyticsStore: IAnalyticsStore;
|
|
9
|
+
analyticsModel: AnalyticsModel;
|
|
10
|
+
name: string;
|
|
11
|
+
typeDefs: import("graphql").DocumentNode;
|
|
12
|
+
resolvers: GraphQLResolverMap<Context>;
|
|
13
|
+
constructor(args: SubgraphArgs);
|
|
14
|
+
onSetup(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/analytics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oDAAoD,CAAC;AACxF,OAAO,EAEL,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,cAAc,EAGf,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEpD,qBAAa,iBAAkB,SAAQ,QAAQ;;IAC7C,cAAc,EAAE,eAAe,CAAC;IAChC,cAAc,EAAE,cAAc,CAAC;IAE/B,IAAI,SAAe;IACnB,QAAQ,iCAEN;IAEF,SAAS,EAAyB,kBAAkB,CAAC,OAAO,CAAC,CAAC;gBAElD,IAAI,EAAE,YAAY;IAiBxB,OAAO;CA4Ed"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AnalyticsQueryEngine, } from "@powerhousedao/analytics-engine-core";
|
|
2
|
+
import { AnalyticsModel, AnalyticsResolvers, typedefs, } from "@powerhousedao/analytics-engine-graphql";
|
|
3
|
+
import { gql } from "graphql-tag";
|
|
4
|
+
import { Subgraph } from "../base/index.js";
|
|
5
|
+
export class AnalyticsSubgraph extends Subgraph {
|
|
6
|
+
analyticsStore;
|
|
7
|
+
analyticsModel;
|
|
8
|
+
name = "analytics";
|
|
9
|
+
typeDefs = gql `
|
|
10
|
+
${typedefs}
|
|
11
|
+
`;
|
|
12
|
+
resolvers = AnalyticsResolvers;
|
|
13
|
+
constructor(args) {
|
|
14
|
+
super(args);
|
|
15
|
+
this.analyticsStore = args.analyticsStore;
|
|
16
|
+
this.analyticsModel = new AnalyticsModel(new AnalyticsQueryEngine(this.analyticsStore));
|
|
17
|
+
args.subgraphManager.setAdditionalContextFields({
|
|
18
|
+
dataSources: {
|
|
19
|
+
db: {
|
|
20
|
+
Analytics: this.analyticsModel,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async onSetup() {
|
|
26
|
+
await this.#createTables();
|
|
27
|
+
}
|
|
28
|
+
async #createTables() {
|
|
29
|
+
if (!(await this.operationalStore.schema.hasTable("AnalyticsDimension"))) {
|
|
30
|
+
await this.operationalStore.schema.createTable("AnalyticsDimension", (table) => {
|
|
31
|
+
table.increments("id").primary();
|
|
32
|
+
table
|
|
33
|
+
.string("dimension")
|
|
34
|
+
.notNullable()
|
|
35
|
+
.index("analyticsdimension_dimension_index");
|
|
36
|
+
table
|
|
37
|
+
.string("path")
|
|
38
|
+
.notNullable()
|
|
39
|
+
.index("analyticsdimension_path_index");
|
|
40
|
+
table.string("label").nullable();
|
|
41
|
+
table.string("icon").nullable();
|
|
42
|
+
table.text("description").nullable();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!(await this.operationalStore.schema.hasTable("AnalyticsSeries"))) {
|
|
46
|
+
await this.operationalStore.schema.createTable("AnalyticsSeries", (table) => {
|
|
47
|
+
table.increments("id").primary();
|
|
48
|
+
table
|
|
49
|
+
.string("source")
|
|
50
|
+
.notNullable()
|
|
51
|
+
.index("analyticsseries_source_index");
|
|
52
|
+
table
|
|
53
|
+
.timestamp("start")
|
|
54
|
+
.notNullable()
|
|
55
|
+
.index("analyticsseries_start_index");
|
|
56
|
+
table.timestamp("end").nullable().index("analyticsseries_end_index");
|
|
57
|
+
table
|
|
58
|
+
.string("metric")
|
|
59
|
+
.notNullable()
|
|
60
|
+
.index("analyticsseries_metric_index");
|
|
61
|
+
table
|
|
62
|
+
.float("value")
|
|
63
|
+
.notNullable()
|
|
64
|
+
.index("analyticsseries_value_index");
|
|
65
|
+
table.string("unit").nullable().index("analyticsseries_unit_index");
|
|
66
|
+
table.string("fn").notNullable().index("analyticsseries_fn_index");
|
|
67
|
+
table.json("params").nullable();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (!(await this.operationalStore.schema.hasTable("AnalyticsSeries_AnalyticsDimension"))) {
|
|
71
|
+
await this.operationalStore.schema.createTable("AnalyticsSeries_AnalyticsDimension", (table) => {
|
|
72
|
+
table
|
|
73
|
+
.integer("seriesId")
|
|
74
|
+
.references("AnalyticsSeries.id")
|
|
75
|
+
.onDelete("CASCADE")
|
|
76
|
+
.index("analyticsseries_analyticsdimension_seriesid_index");
|
|
77
|
+
table
|
|
78
|
+
.integer("dimensionId")
|
|
79
|
+
.references("AnalyticsDimension.id")
|
|
80
|
+
.onDelete("CASCADE")
|
|
81
|
+
.index("analyticsseries_analyticsdimension_dimensionid_index");
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getters.d.ts","sourceRoot":"","sources":["../../../../../src/subgraphs/auth/env/getters.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,QAAO,MAO/B,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAO,MAkBzC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ms from "ms";
|
|
2
|
+
export const getJwtSecret = () => {
|
|
3
|
+
if (!process.env.JWT_SECRET) {
|
|
4
|
+
if (process.env.NODE_ENV === "production") {
|
|
5
|
+
throw new Error("JWT_SECRET is not defined");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return process.env.JWT_SECRET || "dev";
|
|
9
|
+
};
|
|
10
|
+
export const getJwtExpirationPeriod = () => {
|
|
11
|
+
if (!process.env.JWT_EXPIRATION_PERIOD) {
|
|
12
|
+
return "7d";
|
|
13
|
+
}
|
|
14
|
+
// check if number of seconds is provided
|
|
15
|
+
const expirationSeconds = Number(process.env.JWT_EXPIRATION_PERIOD);
|
|
16
|
+
if (!Number.isNaN(expirationSeconds)) {
|
|
17
|
+
// https://www.npmjs.com/package/jsonwebtoken for `expiresIn` format
|
|
18
|
+
return ms(expirationSeconds * 1000);
|
|
19
|
+
}
|
|
20
|
+
// check if a valid time string is provided
|
|
21
|
+
const expirationMs = ms(process.env.JWT_EXPIRATION_PERIOD);
|
|
22
|
+
if (!expirationMs) {
|
|
23
|
+
throw new Error("JWT_EXPIRATION_PERIOD must be a number of seconds or ms string");
|
|
24
|
+
}
|
|
25
|
+
return process.env.JWT_EXPIRATION_PERIOD;
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const JWT_SECRET: string;
|
|
2
|
+
export declare const PORT: string;
|
|
3
|
+
export declare const isDevelopment: boolean;
|
|
4
|
+
export declare const AUTH_SIGNUP_ENABLED: boolean;
|
|
5
|
+
export declare const JWT_EXPIRATION_PERIOD: string;
|
|
6
|
+
export declare const API_ORIGIN: string;
|
|
7
|
+
export declare const CORS_ORIGINS: string[];
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/subgraphs/auth/env/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,QAAiB,CAAC;AACzC,eAAO,MAAM,IAAI,QAA6B,CAAC;AAC/C,eAAO,MAAM,aAAa,SAAyC,CAAC;AACpE,eAAO,MAAM,mBAAmB,SAA2C,CAAC;AAC5E,eAAO,MAAM,qBAAqB,EAAE,MAAiC,CAAC;AACtE,eAAO,MAAM,UAAU,QAAuD,CAAC;AAC/E,eAAO,MAAM,YAAY,UAGxB,CAAC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
|
-
import { getJwtExpirationPeriod, getJwtSecret } from "./getters";
|
|
3
|
-
|
|
2
|
+
import { getJwtExpirationPeriod, getJwtSecret } from "./getters.js";
|
|
4
3
|
dotenv.config();
|
|
5
|
-
|
|
6
4
|
export const JWT_SECRET = getJwtSecret();
|
|
7
5
|
export const PORT = process.env.PORT ?? "3000";
|
|
8
6
|
export const isDevelopment = process.env.NODE_ENV === "development";
|
|
9
7
|
export const AUTH_SIGNUP_ENABLED = Boolean(process.env.AUTH_SIGNUP_ENABLED);
|
|
10
|
-
export const JWT_EXPIRATION_PERIOD
|
|
8
|
+
export const JWT_EXPIRATION_PERIOD = getJwtExpirationPeriod();
|
|
11
9
|
export const API_ORIGIN = process.env.API_ORIGIN || `http://localhost:${PORT}`;
|
|
12
10
|
export const CORS_ORIGINS = process.env.ORIGINS?.split(",") ?? [
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
"https://studio.apollographql.com",
|
|
12
|
+
"https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com",
|
|
15
13
|
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Subgraph } from "#subgraphs/index.js";
|
|
2
|
+
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper";
|
|
3
|
+
import { AuthContext } from "./types.js";
|
|
4
|
+
export declare class AuthSubgraph extends Subgraph {
|
|
5
|
+
#private;
|
|
6
|
+
name: string;
|
|
7
|
+
typeDefs: import("graphql").DocumentNode;
|
|
8
|
+
resolvers: GraphQLResolverMap<AuthContext>;
|
|
9
|
+
onSetup(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/subgraphs/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAMzE,OAAO,EAAE,WAAW,EAAoC,MAAM,YAAY,CAAC;AAS3E,qBAAa,YAAa,SAAQ,QAAQ;;IACxC,IAAI,SAAU;IACd,QAAQ,iCAkDN;IAEF,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC,CA8KxC;IAEI,OAAO;CAyEd"}
|