@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/subgraphs/types.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders } from "http";
|
|
2
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
3
|
-
import { DocumentNode } from "graphql";
|
|
4
|
-
import { SubgraphManager } from "./manager";
|
|
5
|
-
import { Db } from "src/types";
|
|
6
|
-
import { IAnalyticsStore } from "@powerhousedao/analytics-engine-core";
|
|
7
|
-
|
|
8
|
-
export type Context = {
|
|
9
|
-
driveServer: IDocumentDriveServer;
|
|
10
|
-
driveId?: string;
|
|
11
|
-
headers: IncomingHttpHeaders;
|
|
12
|
-
db: unknown;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type ISubgraph = {
|
|
16
|
-
name: string;
|
|
17
|
-
resolvers: Record<string, any>;
|
|
18
|
-
typeDefs: DocumentNode;
|
|
19
|
-
reactor: IDocumentDriveServer;
|
|
20
|
-
operationalStore: Db;
|
|
21
|
-
onSetup?: () => Promise<void>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type SubgraphArgs = {
|
|
25
|
-
reactor: IDocumentDriveServer;
|
|
26
|
-
operationalStore: Db;
|
|
27
|
-
analyticsStore: IAnalyticsStore;
|
|
28
|
-
subgraphManager: SubgraphManager;
|
|
29
|
-
};
|
package/src/sync/utils.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IDocumentDriveServer,
|
|
3
|
-
ListenerRevision,
|
|
4
|
-
PullResponderTransmitter,
|
|
5
|
-
StrandUpdate,
|
|
6
|
-
} from "document-drive";
|
|
7
|
-
import { DocumentDriveAction } from "document-model-libs/document-drive";
|
|
8
|
-
import { BaseAction, Operation, OperationScope } from "document-model/document";
|
|
9
|
-
|
|
10
|
-
// define types
|
|
11
|
-
export type InternalStrandUpdate = {
|
|
12
|
-
operations: Operation[];
|
|
13
|
-
documentId: string;
|
|
14
|
-
driveId: string;
|
|
15
|
-
scope: OperationScope;
|
|
16
|
-
branch: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// processes a strand update and returns a listener revision
|
|
20
|
-
export const processPushUpdate = async (
|
|
21
|
-
reactor: IDocumentDriveServer,
|
|
22
|
-
strand: InternalStrandUpdate
|
|
23
|
-
): Promise<ListenerRevision> => {
|
|
24
|
-
const result = await (strand.documentId !== undefined
|
|
25
|
-
? reactor.queueOperations(
|
|
26
|
-
strand.driveId,
|
|
27
|
-
strand.documentId,
|
|
28
|
-
strand.operations
|
|
29
|
-
)
|
|
30
|
-
: reactor.queueDriveOperations(
|
|
31
|
-
strand.driveId,
|
|
32
|
-
strand.operations as Operation<DocumentDriveAction | BaseAction>[]
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
const scopeOperations = result.document?.operations[strand.scope] ?? [];
|
|
36
|
-
if (scopeOperations.length === 0) {
|
|
37
|
-
return {
|
|
38
|
-
revision: -1,
|
|
39
|
-
branch: strand.branch,
|
|
40
|
-
documentId: strand.documentId ?? "",
|
|
41
|
-
driveId: strand.driveId,
|
|
42
|
-
scope: strand.scope,
|
|
43
|
-
status: result.status,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const revision = scopeOperations.slice().pop()?.index ?? -1;
|
|
48
|
-
return {
|
|
49
|
-
revision,
|
|
50
|
-
branch: strand.branch,
|
|
51
|
-
documentId: strand.documentId ?? "",
|
|
52
|
-
driveId: strand.driveId,
|
|
53
|
-
scope: strand.scope,
|
|
54
|
-
status: result.status,
|
|
55
|
-
error: result.error?.message || undefined,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// processes an acknowledge request and returns a boolean
|
|
60
|
-
export const processAcknowledge = async (
|
|
61
|
-
reactor: IDocumentDriveServer,
|
|
62
|
-
driveId: string,
|
|
63
|
-
listenerId: string,
|
|
64
|
-
revisions: ListenerRevision[]
|
|
65
|
-
): Promise<boolean> => {
|
|
66
|
-
const transmitter = (await reactor.getTransmitter(
|
|
67
|
-
driveId,
|
|
68
|
-
listenerId
|
|
69
|
-
)) as PullResponderTransmitter;
|
|
70
|
-
return transmitter.processAcknowledge(driveId, listenerId, revisions);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// processes a get strands request and returns a list of strand updates
|
|
74
|
-
export const processGetStrands = async (
|
|
75
|
-
reactor: IDocumentDriveServer,
|
|
76
|
-
driveId: string,
|
|
77
|
-
listenerId: string,
|
|
78
|
-
since: string | undefined
|
|
79
|
-
): Promise<StrandUpdate[]> => {
|
|
80
|
-
const transmitter = (await reactor.getTransmitter(
|
|
81
|
-
driveId,
|
|
82
|
-
listenerId
|
|
83
|
-
)) as PullResponderTransmitter;
|
|
84
|
-
return transmitter.getStrands({ since });
|
|
85
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IDocumentDriveServer, IReceiver, Listener } from "document-drive";
|
|
2
|
-
import { Document, OperationScope } from "document-model/document";
|
|
3
|
-
import { Express } from "express";
|
|
4
|
-
import { ProcessorClass } from "./processors/processor";
|
|
5
|
-
import { SubgraphManager } from "./subgraphs/manager";
|
|
6
|
-
import { Db } from "./utils/db";
|
|
7
|
-
import { IAnalyticsStore } from "./processors/analytics-processor";
|
|
8
|
-
|
|
9
|
-
export type { Db } from "./utils/db";
|
|
10
|
-
|
|
11
|
-
export type IProcessorManager = {
|
|
12
|
-
registerProcessor(module: IProcessor | ProcessorClass): Promise<IProcessor>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type API = {
|
|
16
|
-
app: Express;
|
|
17
|
-
subgraphManager: SubgraphManager;
|
|
18
|
-
processorManager: IProcessorManager;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type ProcessorType = "analytics" | "operational";
|
|
22
|
-
|
|
23
|
-
export type ProcessorSetupArgs = {
|
|
24
|
-
reactor: IDocumentDriveServer;
|
|
25
|
-
operationalStore: Db;
|
|
26
|
-
analyticsStore: IAnalyticsStore;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type IProcessor<
|
|
30
|
-
D extends Document = Document,
|
|
31
|
-
S extends OperationScope = OperationScope,
|
|
32
|
-
> = IReceiver<D, S> & {
|
|
33
|
-
onSetup?: (args: ProcessorSetupArgs) => void;
|
|
34
|
-
getOptions: () => ProcessorOptions;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// export interface ProcessorType<T> extends Function {
|
|
38
|
-
// new (...args: any[]): T;
|
|
39
|
-
// TYPE: string;
|
|
40
|
-
// OPTIONS: ProcessorOptions;
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
export type ProcessorOptions = Omit<Listener, "driveId"> & { label: string };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
2
|
-
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper";
|
|
3
|
-
import { typeDefs as scalarsTypeDefs } from "@powerhousedao/scalars";
|
|
4
|
-
import { pascalCase } from "change-case";
|
|
5
|
-
import { IDocumentDriveServer } from "document-drive";
|
|
6
|
-
import { DocumentNode } from "graphql";
|
|
7
|
-
import gql from "graphql-tag";
|
|
8
|
-
import { Context } from "src/subgraphs";
|
|
9
|
-
|
|
10
|
-
export const createSchema = (
|
|
11
|
-
documentDriveServer: IDocumentDriveServer,
|
|
12
|
-
resolvers: GraphQLResolverMap<Context>,
|
|
13
|
-
typeDefs: DocumentNode,
|
|
14
|
-
) =>
|
|
15
|
-
buildSubgraphSchema([
|
|
16
|
-
{
|
|
17
|
-
typeDefs: getDocumentModelTypeDefs(documentDriveServer, typeDefs),
|
|
18
|
-
resolvers,
|
|
19
|
-
},
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
export const getDocumentModelTypeDefs = (
|
|
23
|
-
documentDriveServer: IDocumentDriveServer,
|
|
24
|
-
typeDefs: DocumentNode,
|
|
25
|
-
) => {
|
|
26
|
-
const documentModels = documentDriveServer.getDocumentModels();
|
|
27
|
-
let dmSchema = "";
|
|
28
|
-
documentModels.forEach(({ documentModel }) => {
|
|
29
|
-
const dmSchemaName = pascalCase(documentModel.name.replaceAll("/", " "));
|
|
30
|
-
let tmpDmSchema = `
|
|
31
|
-
${documentModel.specifications
|
|
32
|
-
.map((specification) =>
|
|
33
|
-
specification.state.global.schema
|
|
34
|
-
.replaceAll("scalar DateTime", "")
|
|
35
|
-
.replaceAll(/input (.*?) {[\s\S]*?}/g, ""),
|
|
36
|
-
)
|
|
37
|
-
.join("\n")};
|
|
38
|
-
|
|
39
|
-
${documentModel.specifications
|
|
40
|
-
.map((specification) =>
|
|
41
|
-
specification.state.local.schema
|
|
42
|
-
.replaceAll("scalar DateTime", "")
|
|
43
|
-
.replaceAll(/input (.*?) {[\s\S]*?}/g, "")
|
|
44
|
-
.replaceAll("type AccountSnapshotLocalState", "")
|
|
45
|
-
.replaceAll("type BudgetStatementLocalState", "")
|
|
46
|
-
.replaceAll("type ScopeFrameworkLocalState", ""),
|
|
47
|
-
)
|
|
48
|
-
.join("\n")};
|
|
49
|
-
|
|
50
|
-
\n`;
|
|
51
|
-
|
|
52
|
-
const found = tmpDmSchema.match(/(type|enum|union)\s+(\w+)\s/g);
|
|
53
|
-
const trimmedFound = found?.map((f) =>
|
|
54
|
-
f
|
|
55
|
-
.replaceAll("type ", "")
|
|
56
|
-
.replaceAll("enum ", "")
|
|
57
|
-
.replaceAll("union ", "")
|
|
58
|
-
.trim(),
|
|
59
|
-
);
|
|
60
|
-
trimmedFound?.forEach((f) => {
|
|
61
|
-
// Create a regex that matches the type name with proper boundaries
|
|
62
|
-
const typeRegex = new RegExp(
|
|
63
|
-
// Match type references in various GraphQL contexts
|
|
64
|
-
`(?<![_A-Za-z0-9])(${f})(?![_A-Za-z0-9])|` + // Basic type references
|
|
65
|
-
`\\[(${f})\\]|` + // Array types without nullability
|
|
66
|
-
`\\[(${f})!\\]|` + // Array of non-null types
|
|
67
|
-
`\\[(${f})\\]!|` + // Non-null array of types
|
|
68
|
-
`\\[(${f})!\\]!`, // Non-null array of non-null types
|
|
69
|
-
"g",
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
tmpDmSchema = tmpDmSchema.replace(
|
|
73
|
-
typeRegex,
|
|
74
|
-
(
|
|
75
|
-
match: string,
|
|
76
|
-
p1: string,
|
|
77
|
-
p2: string,
|
|
78
|
-
p3: string,
|
|
79
|
-
p4: string,
|
|
80
|
-
p5: string,
|
|
81
|
-
) => {
|
|
82
|
-
// If it's an array type, preserve the brackets and ! while replacing the type name
|
|
83
|
-
if (match.startsWith("[")) {
|
|
84
|
-
return match.replace(
|
|
85
|
-
p2 || p3 || p4 || p5,
|
|
86
|
-
`${dmSchemaName}_${p2 || p3 || p4 || p5}`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
// Basic type reference
|
|
90
|
-
return `${dmSchemaName}_${p1}`;
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
dmSchema += tmpDmSchema;
|
|
95
|
-
dmSchema += `
|
|
96
|
-
type ${dmSchemaName} implements IDocument {
|
|
97
|
-
id: String!
|
|
98
|
-
name: String!
|
|
99
|
-
documentType: String!
|
|
100
|
-
operations(skip: Int, first: Int): [Operation!]!
|
|
101
|
-
revision: Int!
|
|
102
|
-
created: DateTime!
|
|
103
|
-
lastModified: DateTime!
|
|
104
|
-
${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
105
|
-
${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
106
|
-
}\n`;
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// add the mutation and query types
|
|
110
|
-
const schema = gql`
|
|
111
|
-
${scalarsTypeDefs.join("\n").replaceAll(";", "")}
|
|
112
|
-
|
|
113
|
-
type PHOperationContext {
|
|
114
|
-
signer: Signer
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
type Signer {
|
|
118
|
-
user: SignerUser
|
|
119
|
-
app: SignerApp
|
|
120
|
-
signatures: [String!]!
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
type SignerUser {
|
|
124
|
-
address: String!
|
|
125
|
-
networkId: String!
|
|
126
|
-
chainId: Int!
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
type SignerApp {
|
|
130
|
-
name: String!
|
|
131
|
-
key: String!
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
type Operation {
|
|
135
|
-
id: String!
|
|
136
|
-
type: String!
|
|
137
|
-
index: Int!
|
|
138
|
-
timestamp: DateTime!
|
|
139
|
-
hash: String!
|
|
140
|
-
skip: Int
|
|
141
|
-
inputText: String
|
|
142
|
-
error: String
|
|
143
|
-
context: PHOperationContext
|
|
144
|
-
}
|
|
145
|
-
interface IDocument {
|
|
146
|
-
id: String!
|
|
147
|
-
name: String!
|
|
148
|
-
documentType: String!
|
|
149
|
-
revision: Int!
|
|
150
|
-
created: DateTime!
|
|
151
|
-
lastModified: DateTime!
|
|
152
|
-
operations(first: Int, skip: Int): [Operation!]!
|
|
153
|
-
}
|
|
154
|
-
${dmSchema.replaceAll(";", "")}
|
|
155
|
-
|
|
156
|
-
${typeDefs}
|
|
157
|
-
`;
|
|
158
|
-
|
|
159
|
-
return schema;
|
|
160
|
-
};
|
package/src/utils/db.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import knex, { type Knex } from "knex";
|
|
3
|
-
import ClientPgLite from "knex-pglite";
|
|
4
|
-
|
|
5
|
-
export type Db = Knex;
|
|
6
|
-
|
|
7
|
-
function isPG(connectionString: string) {
|
|
8
|
-
if (connectionString.startsWith("postgres://")) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getDbClient(
|
|
15
|
-
connectionString: string | undefined = undefined,
|
|
16
|
-
): Db {
|
|
17
|
-
const isPg = connectionString && isPG(connectionString);
|
|
18
|
-
const client = isPg ? "pg" : (ClientPgLite as typeof knex.Client);
|
|
19
|
-
const connection = isPg
|
|
20
|
-
? { connectionString }
|
|
21
|
-
: { pglite: new PGlite(connectionString) };
|
|
22
|
-
return knex({
|
|
23
|
-
client,
|
|
24
|
-
connection,
|
|
25
|
-
});
|
|
26
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { RealWorldAssets } from "@sky-ph/atlas/document-models";
|
|
2
|
-
import { DocumentDriveServer, generateUUID } from "document-drive";
|
|
3
|
-
import { MemoryStorage } from "document-drive/storage/memory";
|
|
4
|
-
import {
|
|
5
|
-
module as DocumentDrive,
|
|
6
|
-
generateAddNodeAction,
|
|
7
|
-
} from "document-model-libs/document-drive";
|
|
8
|
-
import { DocumentModel } from "document-model/document";
|
|
9
|
-
|
|
10
|
-
import { bench, describe } from "vitest";
|
|
11
|
-
|
|
12
|
-
describe("Document Drive", async () => {
|
|
13
|
-
const documentModels = [DocumentDrive, RealWorldAssets] as DocumentModel[];
|
|
14
|
-
const document = await RealWorldAssets.utils.loadFromFile(
|
|
15
|
-
"test/data/BlocktowerAndromeda.zip",
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
bench(
|
|
19
|
-
"Load PHDM into Document Drive",
|
|
20
|
-
async () => {
|
|
21
|
-
const server = new DocumentDriveServer(
|
|
22
|
-
documentModels,
|
|
23
|
-
new MemoryStorage(),
|
|
24
|
-
);
|
|
25
|
-
await server.initialize();
|
|
26
|
-
|
|
27
|
-
const driveId = generateUUID();
|
|
28
|
-
const documentId = generateUUID();
|
|
29
|
-
|
|
30
|
-
const drive = await server.addDrive({
|
|
31
|
-
global: {
|
|
32
|
-
id: driveId,
|
|
33
|
-
name: "Test Drive",
|
|
34
|
-
icon: null,
|
|
35
|
-
slug: null,
|
|
36
|
-
},
|
|
37
|
-
local: {
|
|
38
|
-
availableOffline: false,
|
|
39
|
-
sharingType: "PRIVATE",
|
|
40
|
-
listeners: [],
|
|
41
|
-
triggers: [],
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// adds file node for document
|
|
46
|
-
const addFileAction = generateAddNodeAction(
|
|
47
|
-
drive.state.global,
|
|
48
|
-
{
|
|
49
|
-
documentType: document.documentType,
|
|
50
|
-
id: documentId,
|
|
51
|
-
name: "BlocktowerAndromeda",
|
|
52
|
-
},
|
|
53
|
-
["global"],
|
|
54
|
-
);
|
|
55
|
-
await server.addDriveAction(driveId, addFileAction);
|
|
56
|
-
|
|
57
|
-
// adds document operations
|
|
58
|
-
const result = await server.addOperations(
|
|
59
|
-
driveId,
|
|
60
|
-
documentId,
|
|
61
|
-
document.operations.global,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (result.error) {
|
|
65
|
-
throw result.error;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const lastOperation = document.operations.global.at(-1);
|
|
69
|
-
const lastLoadedOperation = result.operations.at(-1);
|
|
70
|
-
if (
|
|
71
|
-
JSON.stringify(lastOperation) !== JSON.stringify(lastLoadedOperation)
|
|
72
|
-
) {
|
|
73
|
-
throw new Error("Document operations mismatch");
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
{ throws: true },
|
|
77
|
-
);
|
|
78
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { RealWorldAssets } from "@sky-ph/atlas/document-models";
|
|
2
|
-
import {
|
|
3
|
-
DocumentDriveServer,
|
|
4
|
-
generateUUID,
|
|
5
|
-
InternalTransmitterUpdate,
|
|
6
|
-
IReceiver,
|
|
7
|
-
} from "document-drive";
|
|
8
|
-
import { MemoryStorage } from "document-drive/storage/memory";
|
|
9
|
-
import {
|
|
10
|
-
module as DocumentDrive,
|
|
11
|
-
generateAddNodeAction,
|
|
12
|
-
ListenerFilter,
|
|
13
|
-
} from "document-model-libs/document-drive";
|
|
14
|
-
import {
|
|
15
|
-
Document,
|
|
16
|
-
DocumentModel,
|
|
17
|
-
OperationScope,
|
|
18
|
-
} from "document-model/document";
|
|
19
|
-
|
|
20
|
-
import { beforeAll, bench, describe } from "vitest";
|
|
21
|
-
|
|
22
|
-
class TestReceiver<
|
|
23
|
-
T extends Document = Document,
|
|
24
|
-
S extends OperationScope = OperationScope,
|
|
25
|
-
> implements IReceiver<T, S>
|
|
26
|
-
{
|
|
27
|
-
async onStrands(strands: InternalTransmitterUpdate<T, S>[]) {
|
|
28
|
-
return Promise.resolve();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async onDisconnect() {
|
|
32
|
-
return Promise.resolve();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
beforeAll(async () => {});
|
|
37
|
-
|
|
38
|
-
describe("Document Drive", async () => {
|
|
39
|
-
const documentModels = Object.values([
|
|
40
|
-
DocumentDrive,
|
|
41
|
-
RealWorldAssets,
|
|
42
|
-
]) as DocumentModel[];
|
|
43
|
-
const document = await RealWorldAssets.utils.loadFromFile(
|
|
44
|
-
"test/data/BlocktowerAndromeda.zip",
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
bench(
|
|
48
|
-
"Load PHDM into Document Drive",
|
|
49
|
-
async () => {
|
|
50
|
-
const serverA = new DocumentDriveServer(
|
|
51
|
-
documentModels,
|
|
52
|
-
new MemoryStorage(),
|
|
53
|
-
);
|
|
54
|
-
await serverA.initialize();
|
|
55
|
-
|
|
56
|
-
const serverB = new DocumentDriveServer(
|
|
57
|
-
documentModels,
|
|
58
|
-
new MemoryStorage(),
|
|
59
|
-
);
|
|
60
|
-
await serverB.initialize();
|
|
61
|
-
|
|
62
|
-
const driveAId = generateUUID();
|
|
63
|
-
const documentId = generateUUID();
|
|
64
|
-
|
|
65
|
-
const driveA = await serverA.addDrive({
|
|
66
|
-
global: {
|
|
67
|
-
id: driveAId,
|
|
68
|
-
name: "Test Drive",
|
|
69
|
-
icon: null,
|
|
70
|
-
slug: null,
|
|
71
|
-
},
|
|
72
|
-
local: {
|
|
73
|
-
availableOffline: false,
|
|
74
|
-
sharingType: "PRIVATE",
|
|
75
|
-
listeners: [],
|
|
76
|
-
triggers: [],
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const driveBId = generateUUID();
|
|
81
|
-
const driveB = await serverB.addDrive({
|
|
82
|
-
global: {
|
|
83
|
-
id: driveBId,
|
|
84
|
-
name: "Test Drive",
|
|
85
|
-
icon: null,
|
|
86
|
-
slug: null,
|
|
87
|
-
},
|
|
88
|
-
local: {
|
|
89
|
-
availableOffline: false,
|
|
90
|
-
sharingType: "PRIVATE",
|
|
91
|
-
listeners: [],
|
|
92
|
-
triggers: [],
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// listener!
|
|
97
|
-
const filter: ListenerFilter = {
|
|
98
|
-
branch: ["*"],
|
|
99
|
-
documentId: ["*"],
|
|
100
|
-
documentType: ["*"],
|
|
101
|
-
scope: ["*"],
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const receiver = new TestReceiver();
|
|
105
|
-
await serverA.addInternalListener(driveAId, receiver, {
|
|
106
|
-
listenerId: generateUUID(),
|
|
107
|
-
label: "Test Listener",
|
|
108
|
-
block: false,
|
|
109
|
-
filter,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
await serverB.addInternalListener(driveBId, receiver, {
|
|
113
|
-
listenerId: generateUUID(),
|
|
114
|
-
label: "Test Listener",
|
|
115
|
-
block: false,
|
|
116
|
-
filter,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// loads document in drive A
|
|
120
|
-
const addFileAction = generateAddNodeAction(
|
|
121
|
-
driveA.state.global,
|
|
122
|
-
{
|
|
123
|
-
documentType: document.documentType,
|
|
124
|
-
id: documentId,
|
|
125
|
-
name: "BlocktowerAndromeda",
|
|
126
|
-
},
|
|
127
|
-
["global"],
|
|
128
|
-
);
|
|
129
|
-
await serverA.addDriveAction(driveAId, addFileAction);
|
|
130
|
-
|
|
131
|
-
const result = await serverA.addOperations(
|
|
132
|
-
driveAId,
|
|
133
|
-
documentId,
|
|
134
|
-
document.operations.global,
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
if (result.error) {
|
|
138
|
-
throw result.error;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const lastOperation = document.operations.global.at(-1);
|
|
142
|
-
const lastLoadedOperation = result.operations.at(-1);
|
|
143
|
-
if (
|
|
144
|
-
JSON.stringify(lastOperation) !== JSON.stringify(lastLoadedOperation)
|
|
145
|
-
) {
|
|
146
|
-
throw new Error("Document operations mismatch");
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
{ throws: true },
|
|
150
|
-
);
|
|
151
|
-
});
|
|
Binary file
|
package/test/router.test.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { DocumentDriveServer } from "document-drive";
|
|
2
|
-
import * as DocumentModelsLibs from "document-model-libs/document-models";
|
|
3
|
-
import { DocumentModel } from "document-model/document";
|
|
4
|
-
import { module as DocumentModelLib } from "document-model/document-model";
|
|
5
|
-
import express from "express";
|
|
6
|
-
import { SubgraphManager } from "src";
|
|
7
|
-
import { getDbClient } from "src/utils/db";
|
|
8
|
-
import { describe, expect, it } from "vitest";
|
|
9
|
-
|
|
10
|
-
const documentModels = [
|
|
11
|
-
DocumentModelLib,
|
|
12
|
-
...Object.values(DocumentModelsLibs),
|
|
13
|
-
] as DocumentModel[];
|
|
14
|
-
|
|
15
|
-
describe("Reactor Router", () => {
|
|
16
|
-
it("should be initialized", () => {
|
|
17
|
-
// const app = express();
|
|
18
|
-
// const knex = getDbClient();
|
|
19
|
-
// const reactor = new DocumentDriveServer(documentModels);
|
|
20
|
-
// const reactorRouter = new SubgraphManager("/", app, reactor, knex);
|
|
21
|
-
expect(true).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// it("should be able to add a new subgraph", async () => {
|
|
25
|
-
// const driveServer = new DocumentDriveServer(documentModels);
|
|
26
|
-
// await driveServer.initialize();
|
|
27
|
-
// const newSubgraph = {
|
|
28
|
-
// name: "newSubgraph",
|
|
29
|
-
// getSchema: (documentDriveServer: IDocumentDriveServer) =>
|
|
30
|
-
// buildSubgraphSchema([
|
|
31
|
-
// {
|
|
32
|
-
// typeDefs: getDocumentModelTypeDefs(
|
|
33
|
-
// documentDriveServer,
|
|
34
|
-
// `
|
|
35
|
-
// type Query {
|
|
36
|
-
// hello: String
|
|
37
|
-
// }
|
|
38
|
-
// `,
|
|
39
|
-
// ),
|
|
40
|
-
// resolvers: { Query: { hello: () => "world" } },
|
|
41
|
-
// },
|
|
42
|
-
// ]),
|
|
43
|
-
// };
|
|
44
|
-
|
|
45
|
-
// await addSubgraph(newSubgraph);
|
|
46
|
-
// expect(reactorRouter.stack.length).gte(3);
|
|
47
|
-
// });
|
|
48
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "ESNext",
|
|
4
|
-
"moduleResolution": "Bundler",
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"types": ["@types/node", "./types.d.ts"],
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"strict": true,
|
|
12
|
-
"noImplicitAny": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"emitDeclarationOnly": true,
|
|
15
|
-
"baseUrl": ".",
|
|
16
|
-
"paths": {
|
|
17
|
-
"document-drive": ["../document-drive/src/index.ts"]
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"include": ["src/**/*.ts", "test/**/*.ts", "*.config.ts"]
|
|
21
|
-
}
|
package/tsdoc.json
DELETED
package/tsup.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ["src/index.ts"],
|
|
5
|
-
splitting: true,
|
|
6
|
-
sourcemap: true,
|
|
7
|
-
clean: true,
|
|
8
|
-
format: "esm",
|
|
9
|
-
treeshake: true,
|
|
10
|
-
noExternal: ["document-drive"],
|
|
11
|
-
platform: "node",
|
|
12
|
-
target: "node20",
|
|
13
|
-
loader: {
|
|
14
|
-
".graphql": "file",
|
|
15
|
-
},
|
|
16
|
-
dts: true,
|
|
17
|
-
});
|