@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
package/src/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
2
|
-
import { Document, OperationScope } from "document-model/document";
|
|
3
|
-
import { Processor } from "./processor";
|
|
4
|
-
import { ProcessorOptions, ProcessorSetupArgs } from "../types";
|
|
5
|
-
|
|
6
|
-
export * from "@powerhousedao/analytics-engine-core";
|
|
7
|
-
|
|
8
|
-
export abstract class AnalyticsProcessor<
|
|
9
|
-
D extends Document = Document,
|
|
10
|
-
S extends OperationScope = OperationScope,
|
|
11
|
-
> extends Processor<D, S> {
|
|
12
|
-
protected analyticsStore: IAnalyticsStore;
|
|
13
|
-
|
|
14
|
-
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions) {
|
|
15
|
-
super(args, options);
|
|
16
|
-
this.analyticsStore = args.analyticsStore;
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/processors/index.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
2
|
-
import { DocumentDriveDocument } from "document-model-libs/document-drive";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
Db,
|
|
6
|
-
IProcessor,
|
|
7
|
-
IProcessorManager,
|
|
8
|
-
ProcessorSetupArgs,
|
|
9
|
-
} from "../types";
|
|
10
|
-
import { IAnalyticsStore } from "./analytics-processor";
|
|
11
|
-
import { isProcessorClass, ProcessorClass } from "./processor";
|
|
12
|
-
|
|
13
|
-
export class ProcessorManager implements IProcessorManager {
|
|
14
|
-
private reactor: IDocumentDriveServer;
|
|
15
|
-
private processors: IProcessor[] = [];
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
driveServer: IDocumentDriveServer,
|
|
19
|
-
private operationalStore: Db,
|
|
20
|
-
private analyticsStore: IAnalyticsStore,
|
|
21
|
-
) {
|
|
22
|
-
this.reactor = driveServer;
|
|
23
|
-
driveServer.on("driveAdded", this.#onDriveAdded.bind(this));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async #onDriveAdded(drive: DocumentDriveDocument) {
|
|
27
|
-
await Promise.all(
|
|
28
|
-
this.processors.map((module) =>
|
|
29
|
-
this.reactor.addInternalListener(
|
|
30
|
-
drive.state.global.id,
|
|
31
|
-
{
|
|
32
|
-
onStrands: (strands) => module.onStrands(strands),
|
|
33
|
-
onDisconnect: () => module.onDisconnect(),
|
|
34
|
-
},
|
|
35
|
-
{ ...module.getOptions() },
|
|
36
|
-
),
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async #onProcessorAdded(processor: IProcessor) {
|
|
42
|
-
const drives = await this.reactor.getDrives();
|
|
43
|
-
|
|
44
|
-
const options = processor.getOptions();
|
|
45
|
-
await Promise.all(
|
|
46
|
-
drives.map((drive) =>
|
|
47
|
-
this.reactor.addInternalListener(
|
|
48
|
-
drive,
|
|
49
|
-
{
|
|
50
|
-
onStrands: (strands) => processor.onStrands(strands),
|
|
51
|
-
onDisconnect: () => processor.onDisconnect(),
|
|
52
|
-
},
|
|
53
|
-
options,
|
|
54
|
-
),
|
|
55
|
-
),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
console.log(`> Registered ${options.label} processor.`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async registerProcessor(module: IProcessor | ProcessorClass) {
|
|
62
|
-
const args: ProcessorSetupArgs = {
|
|
63
|
-
reactor: this.reactor,
|
|
64
|
-
operationalStore: this.operationalStore,
|
|
65
|
-
analyticsStore: this.analyticsStore,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const processor = isProcessorClass(module) ? new module(args) : module;
|
|
69
|
-
processor.onSetup?.(args);
|
|
70
|
-
|
|
71
|
-
await this.#onProcessorAdded(processor);
|
|
72
|
-
this.processors.push(processor);
|
|
73
|
-
return processor;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Document, OperationScope } from "document-model/document";
|
|
2
|
-
import { Db, ProcessorOptions, ProcessorSetupArgs } from "src/types";
|
|
3
|
-
import { Processor } from "./processor";
|
|
4
|
-
|
|
5
|
-
export abstract class OperationalProcessor<
|
|
6
|
-
D extends Document = Document,
|
|
7
|
-
S extends OperationScope = OperationScope,
|
|
8
|
-
> extends Processor<D, S> {
|
|
9
|
-
protected operationalStore: Db;
|
|
10
|
-
|
|
11
|
-
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions) {
|
|
12
|
-
super(args, options);
|
|
13
|
-
this.operationalStore = args.operationalStore;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
onSetup(args: ProcessorSetupArgs) {
|
|
17
|
-
super.onSetup(args);
|
|
18
|
-
this.operationalStore = args.operationalStore;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IDocumentDriveServer,
|
|
3
|
-
InternalTransmitterUpdate,
|
|
4
|
-
} from "document-drive";
|
|
5
|
-
import { Document, OperationScope } from "document-model/document";
|
|
6
|
-
import { IProcessor, ProcessorOptions, ProcessorSetupArgs } from "../types";
|
|
7
|
-
|
|
8
|
-
export type ProcessorUpdate<
|
|
9
|
-
D extends Document = Document,
|
|
10
|
-
S extends OperationScope = OperationScope,
|
|
11
|
-
> = InternalTransmitterUpdate<D, S>;
|
|
12
|
-
|
|
13
|
-
export abstract class Processor<
|
|
14
|
-
D extends Document = Document,
|
|
15
|
-
S extends OperationScope = OperationScope,
|
|
16
|
-
> implements IProcessor<D, S>
|
|
17
|
-
{
|
|
18
|
-
protected reactor: IDocumentDriveServer;
|
|
19
|
-
protected processorOptions: ProcessorOptions = {
|
|
20
|
-
listenerId: "processor",
|
|
21
|
-
filter: {
|
|
22
|
-
branch: ["main"],
|
|
23
|
-
documentId: ["*"],
|
|
24
|
-
documentType: ["*"],
|
|
25
|
-
scope: ["global"],
|
|
26
|
-
},
|
|
27
|
-
block: false,
|
|
28
|
-
label: "processor",
|
|
29
|
-
system: true,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions) {
|
|
33
|
-
this.reactor = args.reactor;
|
|
34
|
-
if (options) {
|
|
35
|
-
this.processorOptions = { ...this.processorOptions, ...options };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
onSetup(args: ProcessorSetupArgs): void {
|
|
40
|
-
this.reactor = args.reactor;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
abstract onStrands(strands: ProcessorUpdate<D, S>[]): Promise<void>;
|
|
44
|
-
|
|
45
|
-
abstract onDisconnect(): Promise<void>;
|
|
46
|
-
|
|
47
|
-
getOptions() {
|
|
48
|
-
return this.processorOptions;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class BaseProcessor extends Processor {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
-
async onStrands(strands: ProcessorUpdate[]): Promise<void> {}
|
|
55
|
-
async onDisconnect(): Promise<void> {}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type ProcessorClass = typeof BaseProcessor;
|
|
59
|
-
|
|
60
|
-
// checks if the provided candidate is a descendant of the Processor class.
|
|
61
|
-
export function isProcessorClass(
|
|
62
|
-
candidate: unknown,
|
|
63
|
-
): candidate is ProcessorClass {
|
|
64
|
-
if (typeof candidate !== "function") return false;
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
66
|
-
let proto = Object.getPrototypeOf(candidate);
|
|
67
|
-
|
|
68
|
-
while (proto) {
|
|
69
|
-
if (Object.prototype.isPrototypeOf.call(proto, Processor)) return true;
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
71
|
-
proto = Object.getPrototypeOf(proto);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return false;
|
|
75
|
-
}
|
package/src/server.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import {
|
|
3
|
-
KnexAnalyticsStore,
|
|
4
|
-
KnexQueryExecutor,
|
|
5
|
-
} from "@powerhousedao/analytics-engine-knex";
|
|
6
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
7
|
-
import express, { Express } from "express";
|
|
8
|
-
import fs from "node:fs";
|
|
9
|
-
import https from "node:https";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { Pool } from "pg";
|
|
12
|
-
import { IAnalyticsStore, ProcessorManager } from "./processors";
|
|
13
|
-
import { SubgraphManager } from "./subgraphs/manager";
|
|
14
|
-
import { API } from "./types";
|
|
15
|
-
import { getDbClient } from "./utils/db";
|
|
16
|
-
|
|
17
|
-
type Options = {
|
|
18
|
-
express?: Express;
|
|
19
|
-
port?: number;
|
|
20
|
-
dbPath: string | undefined;
|
|
21
|
-
client?: PGlite | typeof Pool | undefined;
|
|
22
|
-
https?: {
|
|
23
|
-
keyPath: string;
|
|
24
|
-
certPath: string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const DEFAULT_PORT = 4000;
|
|
29
|
-
|
|
30
|
-
export async function startAPI(
|
|
31
|
-
reactor: IDocumentDriveServer,
|
|
32
|
-
options: Options,
|
|
33
|
-
): Promise<API> {
|
|
34
|
-
const port = options.port ?? DEFAULT_PORT;
|
|
35
|
-
const app = options.express ?? express();
|
|
36
|
-
const db = getDbClient(options.dbPath);
|
|
37
|
-
const analyticsStore = new KnexAnalyticsStore({
|
|
38
|
-
executor: new KnexQueryExecutor(),
|
|
39
|
-
knex: db,
|
|
40
|
-
}) as unknown as IAnalyticsStore; // TODO update @powerhousedao/analytics-engine-pg to use @powerhousedao/analytics-engine-core@0.3.2
|
|
41
|
-
const subgraphManager = new SubgraphManager(
|
|
42
|
-
"/",
|
|
43
|
-
app,
|
|
44
|
-
reactor,
|
|
45
|
-
db,
|
|
46
|
-
analyticsStore,
|
|
47
|
-
);
|
|
48
|
-
await subgraphManager.init();
|
|
49
|
-
const processorManager = new ProcessorManager(reactor, db, analyticsStore);
|
|
50
|
-
|
|
51
|
-
if (options.https) {
|
|
52
|
-
const currentDir = process.cwd();
|
|
53
|
-
const server = https.createServer(
|
|
54
|
-
{
|
|
55
|
-
key: fs.readFileSync(path.join(currentDir, options.https.keyPath)),
|
|
56
|
-
cert: fs.readFileSync(path.join(currentDir, options.https.certPath)),
|
|
57
|
-
},
|
|
58
|
-
app,
|
|
59
|
-
);
|
|
60
|
-
server.listen(port);
|
|
61
|
-
} else {
|
|
62
|
-
app.listen(port);
|
|
63
|
-
}
|
|
64
|
-
return { app, subgraphManager, processorManager };
|
|
65
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnalyticsQueryEngine,
|
|
3
|
-
IAnalyticsStore,
|
|
4
|
-
} from "@powerhousedao/analytics-engine-core";
|
|
5
|
-
import {
|
|
6
|
-
AnalyticsModel,
|
|
7
|
-
typedefs,
|
|
8
|
-
AnalyticsResolvers,
|
|
9
|
-
} from "@powerhousedao/analytics-engine-graphql";
|
|
10
|
-
import gql from "graphql-tag";
|
|
11
|
-
import { Subgraph } from "../base/index.js";
|
|
12
|
-
import { Context, SubgraphArgs } from "../index.js";
|
|
13
|
-
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap.js";
|
|
14
|
-
|
|
15
|
-
export class AnalyticsSubgraph extends Subgraph {
|
|
16
|
-
analyticsStore: IAnalyticsStore;
|
|
17
|
-
analyticsModel: AnalyticsModel;
|
|
18
|
-
|
|
19
|
-
name = "analytics";
|
|
20
|
-
typeDefs = gql`
|
|
21
|
-
${typedefs}
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
resolvers = AnalyticsResolvers as GraphQLResolverMap<Context>;
|
|
25
|
-
|
|
26
|
-
constructor(args: SubgraphArgs) {
|
|
27
|
-
super(args);
|
|
28
|
-
this.analyticsStore = args.analyticsStore;
|
|
29
|
-
|
|
30
|
-
this.analyticsModel = new AnalyticsModel(
|
|
31
|
-
new AnalyticsQueryEngine(this.analyticsStore),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
args.subgraphManager.setAdditionalContextFields({
|
|
35
|
-
dataSources: {
|
|
36
|
-
db: {
|
|
37
|
-
Analytics: this.analyticsModel,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async onSetup() {
|
|
44
|
-
await this.#createTables();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async #createTables() {
|
|
48
|
-
if (!(await this.operationalStore.schema.hasTable("AnalyticsDimension"))) {
|
|
49
|
-
await this.operationalStore.schema.createTable(
|
|
50
|
-
"AnalyticsDimension",
|
|
51
|
-
(table) => {
|
|
52
|
-
table.increments("id").primary();
|
|
53
|
-
table
|
|
54
|
-
.string("dimension")
|
|
55
|
-
.notNullable()
|
|
56
|
-
.index("analyticsdimension_dimension_index");
|
|
57
|
-
table
|
|
58
|
-
.string("path")
|
|
59
|
-
.notNullable()
|
|
60
|
-
.index("analyticsdimension_path_index");
|
|
61
|
-
table.string("label").nullable();
|
|
62
|
-
table.string("icon").nullable();
|
|
63
|
-
table.text("description").nullable();
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!(await this.operationalStore.schema.hasTable("AnalyticsSeries"))) {
|
|
69
|
-
await this.operationalStore.schema.createTable(
|
|
70
|
-
"AnalyticsSeries",
|
|
71
|
-
(table) => {
|
|
72
|
-
table.increments("id").primary();
|
|
73
|
-
table
|
|
74
|
-
.string("source")
|
|
75
|
-
.notNullable()
|
|
76
|
-
.index("analyticsseries_source_index");
|
|
77
|
-
table
|
|
78
|
-
.timestamp("start")
|
|
79
|
-
.notNullable()
|
|
80
|
-
.index("analyticsseries_start_index");
|
|
81
|
-
table.timestamp("end").nullable().index("analyticsseries_end_index");
|
|
82
|
-
table
|
|
83
|
-
.string("metric")
|
|
84
|
-
.notNullable()
|
|
85
|
-
.index("analyticsseries_metric_index");
|
|
86
|
-
table
|
|
87
|
-
.float("value")
|
|
88
|
-
.notNullable()
|
|
89
|
-
.index("analyticsseries_value_index");
|
|
90
|
-
table.string("unit").nullable().index("analyticsseries_unit_index");
|
|
91
|
-
table.string("fn").notNullable().index("analyticsseries_fn_index");
|
|
92
|
-
table.json("params").nullable();
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
!(await this.operationalStore.schema.hasTable(
|
|
99
|
-
"AnalyticsSeries_AnalyticsDimension",
|
|
100
|
-
))
|
|
101
|
-
) {
|
|
102
|
-
await this.operationalStore.schema.createTable(
|
|
103
|
-
"AnalyticsSeries_AnalyticsDimension",
|
|
104
|
-
(table) => {
|
|
105
|
-
table
|
|
106
|
-
.integer("seriesId")
|
|
107
|
-
.references("AnalyticsSeries.id")
|
|
108
|
-
.onDelete("CASCADE")
|
|
109
|
-
.index("analyticsseries_analyticsdimension_seriesid_index");
|
|
110
|
-
table
|
|
111
|
-
.integer("dimensionId")
|
|
112
|
-
.references("AnalyticsDimension.id")
|
|
113
|
-
.onDelete("CASCADE")
|
|
114
|
-
.index("analyticsseries_analyticsdimension_dimensionid_index");
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import ms from "ms";
|
|
2
|
-
|
|
3
|
-
export const getJwtSecret = (): string => {
|
|
4
|
-
if (!process.env.JWT_SECRET) {
|
|
5
|
-
if (process.env.NODE_ENV === "production") {
|
|
6
|
-
throw new Error("JWT_SECRET is not defined");
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return process.env.JWT_SECRET || "dev";
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getJwtExpirationPeriod = (): string => {
|
|
13
|
-
if (!process.env.JWT_EXPIRATION_PERIOD) {
|
|
14
|
-
return "7d";
|
|
15
|
-
}
|
|
16
|
-
// check if number of seconds is provided
|
|
17
|
-
const expirationSeconds = Number(process.env.JWT_EXPIRATION_PERIOD);
|
|
18
|
-
if (!Number.isNaN(expirationSeconds)) {
|
|
19
|
-
// https://www.npmjs.com/package/jsonwebtoken for `expiresIn` format
|
|
20
|
-
return ms(expirationSeconds * 1000);
|
|
21
|
-
}
|
|
22
|
-
// check if a valid time string is provided
|
|
23
|
-
const expirationMs = ms(process.env.JWT_EXPIRATION_PERIOD);
|
|
24
|
-
if (!expirationMs) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
"JWT_EXPIRATION_PERIOD must be a number of seconds or ms string",
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return process.env.JWT_EXPIRATION_PERIOD;
|
|
30
|
-
};
|