@powerhousedao/reactor-api 1.9.4 → 1.10.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/CHANGELOG.md +18 -3
- package/dist/index.d.ts +86 -60
- package/dist/index.js +8107 -1402
- package/dist/index.js.map +1 -1
- package/package.json +10 -5
- package/src/index.ts +2 -0
- package/src/processor-manager.ts +67 -0
- package/src/processors/analytics-processor.ts +21 -0
- package/src/processors/index.ts +3 -0
- package/src/processors/processor.ts +75 -0
- package/src/router.ts +22 -66
- package/src/server.ts +31 -12
- package/src/subgraphs/analytics/db.ts +55 -0
- package/src/subgraphs/analytics/index.ts +12 -0
- package/src/subgraphs/drive/resolvers.ts +26 -14
- package/src/subgraphs/index.ts +1 -0
- package/src/types.ts +46 -4
- package/src/utils/create-schema.ts +16 -7
- package/src/utils/get-knex-client.ts +23 -0
- package/test/router.test.ts +27 -31
- package/src/internal-listener-manager.ts +0 -108
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
## 1.
|
|
1
|
+
## 1.10.0 (2024-12-11)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- **reactor-api:** Added support for processors ([#655](https://github.com/powerhouse-inc/powerhouse/pull/655))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **monorepo:** remove nx cloud id ([45da8784](https://github.com/powerhouse-inc/powerhouse/commit/45da8784))
|
|
2
10
|
|
|
3
11
|
### 🧱 Updated Dependencies
|
|
4
12
|
|
|
5
|
-
- Updated document-model-libs to 1.
|
|
6
|
-
- Updated document-drive to 1.
|
|
13
|
+
- Updated document-model-libs to 1.121.0
|
|
14
|
+
- Updated document-drive to 1.9.0
|
|
15
|
+
- Updated document-model to 2.11.0
|
|
16
|
+
- Updated @powerhousedao/scalars to 1.13.0
|
|
17
|
+
|
|
18
|
+
### ❤️ Thank You
|
|
19
|
+
|
|
20
|
+
- acaldas
|
|
21
|
+
- ryanwolhuter @ryanwolhuter
|
|
7
22
|
|
|
8
23
|
## 1.2.0 (2024-10-29)
|
|
9
24
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PGlite } from '@electric-sql/pglite';
|
|
2
|
-
import { Trigger, PullResponderTriggerData, DocumentDriveDocument, ListenerFilter,
|
|
3
|
-
import {
|
|
2
|
+
import { Trigger, PullResponderTriggerData, DocumentDriveDocument, ListenerFilter, ListenerCallInfo, DocumentDriveLocalState, DocumentDriveAction, DocumentDriveState } from 'document-model-libs/document-drive';
|
|
3
|
+
import { Operation, Document, DocumentModel, Action, OperationScope, BaseAction, State, CreateChildDocumentInput, ActionContext, ReducerOptions, Signal } from 'document-model/document';
|
|
4
4
|
import { Unsubscribe } from 'nanoevents';
|
|
5
5
|
import express, { Express } from 'express';
|
|
6
|
-
import
|
|
7
|
-
import { PgDatabase } from 'drizzle-orm/pg-core';
|
|
6
|
+
import { Pool } from 'pg';
|
|
8
7
|
import { IncomingHttpHeaders } from 'http';
|
|
8
|
+
import { IAnalyticsStore } from '@powerhousedao/analytics-engine-core';
|
|
9
9
|
import * as graphql from 'graphql';
|
|
10
10
|
import { GraphQLResolverMap } from '@apollo/subgraph/dist/schema-helper';
|
|
11
11
|
|
|
@@ -24,22 +24,6 @@ type PullResponderTrigger = Omit<Trigger, "data" | "type"> & {
|
|
|
24
24
|
type: "PullResponder";
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
interface IReceiver {
|
|
28
|
-
transmit: (strands: InternalTransmitterUpdate[]) => Promise<void>;
|
|
29
|
-
disconnect: () => Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
type InternalTransmitterUpdate<T extends Document = Document, S extends OperationScope = OperationScope> = {
|
|
32
|
-
driveId: string;
|
|
33
|
-
documentId: string;
|
|
34
|
-
scope: S;
|
|
35
|
-
branch: string;
|
|
36
|
-
operations: OperationUpdate[];
|
|
37
|
-
state: T["state"][S];
|
|
38
|
-
};
|
|
39
|
-
interface IInternalTransmitter extends ITransmitter {
|
|
40
|
-
setReceiver(receiver: IReceiver): void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
27
|
declare class DocumentModelNotFoundError extends Error {
|
|
44
28
|
id: string;
|
|
45
29
|
constructor(id: string, cause?: unknown);
|
|
@@ -103,6 +87,26 @@ interface IReadModeDriveService {
|
|
|
103
87
|
deleteReadDrive(id: string): Promise<ReadDriveNotFoundError | undefined>;
|
|
104
88
|
}
|
|
105
89
|
|
|
90
|
+
interface IReceiver<T extends Document = Document, S extends OperationScope = OperationScope> {
|
|
91
|
+
onStrands: (strands: InternalTransmitterUpdate<T, S>[]) => Promise<void>;
|
|
92
|
+
onDisconnect: () => Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
type InternalOperationUpdate<D extends Document = Document, S extends OperationScope = OperationScope> = Omit<Operation<InferDocumentOperation<D>>, "scope"> & {
|
|
95
|
+
state: D["state"][S];
|
|
96
|
+
previousState: D["state"][S];
|
|
97
|
+
};
|
|
98
|
+
type InternalTransmitterUpdate<D extends Document = Document, S extends OperationScope = OperationScope> = {
|
|
99
|
+
driveId: string;
|
|
100
|
+
documentId: string;
|
|
101
|
+
scope: S;
|
|
102
|
+
branch: string;
|
|
103
|
+
operations: InternalOperationUpdate<D, S>[];
|
|
104
|
+
state: D["state"][S];
|
|
105
|
+
};
|
|
106
|
+
interface IInternalTransmitter extends ITransmitter {
|
|
107
|
+
setReceiver(receiver: IReceiver): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
interface IDefaultDrivesManager {
|
|
107
111
|
initializeDefaultRemoteDrives(): Promise<void>;
|
|
108
112
|
getDefaultRemoteDrives(): Map<string, DefaultRemoteDriveInfo>;
|
|
@@ -283,67 +287,89 @@ type PublicPart<T> = Pick<T, PublicKeys<T>>;
|
|
|
283
287
|
type IBaseDocumentDriveServer = PublicPart<AbstractDocumentDriveServer>;
|
|
284
288
|
type IDocumentDriveServer = IBaseDocumentDriveServer & IDefaultDrivesManager & IReadModeDriveServer;
|
|
285
289
|
|
|
286
|
-
|
|
287
|
-
name: string;
|
|
288
|
-
options: Omit<Listener, "driveId">;
|
|
289
|
-
transmit: (strands: InternalTransmitterUpdate[]) => Promise<void>;
|
|
290
|
-
};
|
|
291
|
-
declare class InternalListenerManager {
|
|
290
|
+
declare class ReactorRouterManager {
|
|
292
291
|
#private;
|
|
293
|
-
private
|
|
294
|
-
private
|
|
295
|
-
|
|
292
|
+
private readonly path;
|
|
293
|
+
private readonly app;
|
|
294
|
+
private readonly reactor;
|
|
295
|
+
private reactorRouter;
|
|
296
|
+
private contextFields;
|
|
297
|
+
private subgraphs;
|
|
298
|
+
constructor(path: string, app: express.Express, reactor: IDocumentDriveServer);
|
|
296
299
|
init(): Promise<void>;
|
|
297
|
-
|
|
300
|
+
updateRouter(): Promise<void>;
|
|
301
|
+
registerSubgraph(subgraph: Subgraph): Promise<void>;
|
|
302
|
+
getAdditionalContextFields: () => Record<string, any>;
|
|
303
|
+
setAdditionalContextFields(fields: Record<string, any>): void;
|
|
298
304
|
}
|
|
299
305
|
|
|
306
|
+
type ProcessorUpdate<D extends Document = Document, S extends OperationScope = OperationScope> = InternalTransmitterUpdate<D, S>;
|
|
307
|
+
declare abstract class Processor<D extends Document = Document, S extends OperationScope = OperationScope> implements IProcessor<D, S> {
|
|
308
|
+
protected reactor: IDocumentDriveServer;
|
|
309
|
+
protected processorOptions: ProcessorOptions;
|
|
310
|
+
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions);
|
|
311
|
+
onSetup(args: ProcessorSetupArgs): void;
|
|
312
|
+
abstract onStrands(strands: ProcessorUpdate<D, S>[]): Promise<void>;
|
|
313
|
+
abstract onDisconnect(): Promise<void>;
|
|
314
|
+
getOptions(): ProcessorOptions;
|
|
315
|
+
}
|
|
316
|
+
declare class BaseProcessor extends Processor {
|
|
317
|
+
onStrands(strands: ProcessorUpdate[]): Promise<void>;
|
|
318
|
+
onDisconnect(): Promise<void>;
|
|
319
|
+
}
|
|
320
|
+
type ProcessorClass = typeof BaseProcessor;
|
|
321
|
+
declare function isProcessorClass(candidate: unknown): candidate is ProcessorClass;
|
|
322
|
+
|
|
323
|
+
type IProcessorManager = {
|
|
324
|
+
registerProcessor(module: IProcessor | ProcessorClass): Promise<IProcessor>;
|
|
325
|
+
};
|
|
326
|
+
type API = {
|
|
327
|
+
app: Express;
|
|
328
|
+
reactorRouterManager: ReactorRouterManager;
|
|
329
|
+
processorManager: IProcessorManager;
|
|
330
|
+
};
|
|
300
331
|
interface Context {
|
|
301
332
|
headers: IncomingHttpHeaders;
|
|
302
333
|
driveId: string | undefined;
|
|
303
334
|
driveServer: IDocumentDriveServer;
|
|
304
|
-
db: PgDatabase<any, any, any>;
|
|
305
335
|
}
|
|
306
|
-
type
|
|
336
|
+
type Subgraph = {
|
|
307
337
|
name: string;
|
|
308
338
|
resolvers: any;
|
|
309
339
|
typeDefs: string;
|
|
310
340
|
options?: Omit<Listener, "driveId">;
|
|
311
|
-
transmit?: (strands: InternalTransmitterUpdate[]) => Promise<
|
|
341
|
+
transmit?: (strands: InternalTransmitterUpdate[]) => Promise<ListenerRevision[]>;
|
|
342
|
+
};
|
|
343
|
+
type ProcessorType = "analytics" | "operational";
|
|
344
|
+
type ProcessorSetupArgs = {
|
|
345
|
+
reactor: IDocumentDriveServer;
|
|
346
|
+
dataSources: {
|
|
347
|
+
analyticsStore: IAnalyticsStore;
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
type IProcessor<D extends Document = Document, S extends OperationScope = OperationScope> = IReceiver<D, S> & {
|
|
351
|
+
onSetup?: (args: ProcessorSetupArgs) => void;
|
|
352
|
+
getOptions: () => ProcessorOptions;
|
|
353
|
+
};
|
|
354
|
+
type ProcessorOptions = Omit<Listener, "driveId"> & {
|
|
355
|
+
label: string;
|
|
312
356
|
};
|
|
313
|
-
|
|
314
|
-
declare const Pool$1: typeof pg.Pool;
|
|
315
|
-
declare class ReactorRouterManager {
|
|
316
|
-
#private;
|
|
317
|
-
private readonly path;
|
|
318
|
-
private readonly app;
|
|
319
|
-
private readonly driveServer;
|
|
320
|
-
private readonly client;
|
|
321
|
-
private listenerManager;
|
|
322
|
-
private database;
|
|
323
|
-
private reactorRouter;
|
|
324
|
-
private contextFields;
|
|
325
|
-
private registry;
|
|
326
|
-
constructor(path: string, app: express.Express, driveServer: IDocumentDriveServer, client?: PGlite | typeof Pool$1, listenerManager?: InternalListenerManager);
|
|
327
|
-
init(): Promise<void>;
|
|
328
|
-
updateRouter(): Promise<void>;
|
|
329
|
-
registerProcessor(processor: Processor): Promise<void>;
|
|
330
|
-
getAdditionalContextFields: () => Record<string, any>;
|
|
331
|
-
setAdditionalContextFields(fields: Record<string, any>): void;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
declare const Pool: typeof pg.Pool;
|
|
335
357
|
|
|
336
358
|
type Options = {
|
|
337
359
|
express?: Express;
|
|
338
360
|
port?: number;
|
|
361
|
+
dbConnection: string | undefined;
|
|
339
362
|
client?: PGlite | typeof Pool | undefined;
|
|
340
363
|
};
|
|
341
|
-
declare function startAPI(reactor: IDocumentDriveServer, options: Options): Promise<
|
|
342
|
-
app: express.Express;
|
|
343
|
-
reactorRouterManager: ReactorRouterManager;
|
|
344
|
-
}>;
|
|
364
|
+
declare function startAPI(reactor: IDocumentDriveServer, options: Options): Promise<API>;
|
|
345
365
|
|
|
346
366
|
declare const createSchema: (documentDriveServer: IDocumentDriveServer, resolvers: GraphQLResolverMap<Context>, typeDefs: string) => graphql.GraphQLSchema;
|
|
347
367
|
declare const getDocumentModelTypeDefs: (documentDriveServer: IDocumentDriveServer, typeDefs: string) => graphql.DocumentNode;
|
|
348
368
|
|
|
349
|
-
|
|
369
|
+
declare abstract class AnalyticsProcessor<D extends Document = Document, S extends OperationScope = OperationScope> extends Processor<D, S> {
|
|
370
|
+
protected analyticsStore: IAnalyticsStore;
|
|
371
|
+
constructor(args: ProcessorSetupArgs, options?: ProcessorOptions);
|
|
372
|
+
onSetup(args: ProcessorSetupArgs): void;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export { type API, AnalyticsProcessor, BaseProcessor, type Context, type IProcessor, type IProcessorManager, Processor, type ProcessorClass, type ProcessorOptions, type ProcessorSetupArgs, type ProcessorType, type ProcessorUpdate, ReactorRouterManager, type Subgraph, createSchema, getDocumentModelTypeDefs, isProcessorClass, startAPI };
|