@powerhousedao/reactor-local 1.2.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 +46 -0
- package/dist/chunk-VFTWNJCU.js +3935 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +30 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +1 -0
- package/drizzle.config.ts +11 -0
- package/package.json +52 -0
- package/src/cli.ts +56 -0
- package/src/server.ts +85 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +45 -0
- package/types.d.ts +5 -0
- package/types.ts +10 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { startServer } from './chunk-VFTWNJCU.js';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
|
|
5
|
+
var reactorLocalAction = (options) => {
|
|
6
|
+
if (options.port) {
|
|
7
|
+
process.env.PORT = options.port;
|
|
8
|
+
}
|
|
9
|
+
if (options.localEditors) {
|
|
10
|
+
process.env.LOCAL_DOCUMENT_EDITORS = options.localEditors;
|
|
11
|
+
}
|
|
12
|
+
if (options.localDocuments) {
|
|
13
|
+
process.env.LOCAL_DOCUMENT_MODELS = options.localDocuments;
|
|
14
|
+
}
|
|
15
|
+
startServer().catch((error) => {
|
|
16
|
+
throw error;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var program = new Command();
|
|
20
|
+
program.name("Reactor Local").description("Reactor Local CLI").option("-p, --port <port>", "Port to run the server on", "4001").option(
|
|
21
|
+
"-le, --local-editors <localEditors>",
|
|
22
|
+
"Link local document editors path"
|
|
23
|
+
).option(
|
|
24
|
+
"-ld, --local-documents <localDocuments>",
|
|
25
|
+
"Link local documents path"
|
|
26
|
+
).action(reactorLocalAction);
|
|
27
|
+
program.command("help").description("Display help information").action(() => {
|
|
28
|
+
program.help();
|
|
29
|
+
});
|
|
30
|
+
program.parse(process.argv);
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { startServer } from './chunk-VFTWNJCU.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit";
|
|
2
|
+
export default defineConfig({
|
|
3
|
+
driver: "pglite",
|
|
4
|
+
dialect: "postgresql",
|
|
5
|
+
schema: [
|
|
6
|
+
"node_modules/@powerhousedao/general-document-indexer/src/schema.ts",
|
|
7
|
+
],
|
|
8
|
+
dbCredentials: {
|
|
9
|
+
url: "./dev.db",
|
|
10
|
+
},
|
|
11
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@powerhousedao/reactor-local",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.0",
|
|
5
|
+
"main": "dist/server.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"reactor-local": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"description": "",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@apollo/subgraph": "^2.9.2",
|
|
17
|
+
"@electric-sql/pglite": "^0.2.12",
|
|
18
|
+
"@libsql/client": "^0.14.0",
|
|
19
|
+
"@powerhousedao/general-document-indexer": "1.2.0",
|
|
20
|
+
"@powerhousedao/reactor-api": "1.2.0",
|
|
21
|
+
"commander": "^12.1.0",
|
|
22
|
+
"document-drive": "1.2.0",
|
|
23
|
+
"dotenv": "^16.4.5",
|
|
24
|
+
"drizzle-kit": "^0.25.0",
|
|
25
|
+
"drizzle-orm": "^0.34.1",
|
|
26
|
+
"express": "^4.21.0",
|
|
27
|
+
"ms": "^2.1.3",
|
|
28
|
+
"pg": "^8.13.0",
|
|
29
|
+
"vite-node": "^2.1.2",
|
|
30
|
+
"document-model": "2.3.1",
|
|
31
|
+
"document-model-libs": "1.104.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/body-parser": "^1.19.5",
|
|
35
|
+
"@types/cors": "^2.8.17",
|
|
36
|
+
"@types/express": "^5.0.0",
|
|
37
|
+
"@types/ms": "^0.7.34",
|
|
38
|
+
"@types/node": "^22.7.5",
|
|
39
|
+
"@types/pg": "^8.11.10",
|
|
40
|
+
"postcss": "^8.4.47",
|
|
41
|
+
"tsup": "^8.3.0",
|
|
42
|
+
"typescript": "^5.6.2"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"start": "vite-node src/index.ts",
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"db:migrate": "drizzle-kit migrate",
|
|
48
|
+
"db:studio": "drizzle-kit studio",
|
|
49
|
+
"db:generate": "drizzle-kit generate",
|
|
50
|
+
"prestart": "pnpm db:migrate"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { startServer } from "./server";
|
|
4
|
+
|
|
5
|
+
type ReactorLocalOptions = {
|
|
6
|
+
port?: string;
|
|
7
|
+
host?: boolean;
|
|
8
|
+
configFile?: string;
|
|
9
|
+
localEditors?: string;
|
|
10
|
+
localDocuments?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ReactorLocalAction = (options: ReactorLocalOptions) => void;
|
|
14
|
+
|
|
15
|
+
const reactorLocalAction: ReactorLocalAction = (options) => {
|
|
16
|
+
if (options.port) {
|
|
17
|
+
process.env.PORT = options.port;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (options.localEditors) {
|
|
21
|
+
process.env.LOCAL_DOCUMENT_EDITORS = options.localEditors;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (options.localDocuments) {
|
|
25
|
+
process.env.LOCAL_DOCUMENT_MODELS = options.localDocuments;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
startServer().catch((error: unknown) => {
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const program = new Command();
|
|
34
|
+
|
|
35
|
+
program
|
|
36
|
+
.name("Reactor Local")
|
|
37
|
+
.description("Reactor Local CLI")
|
|
38
|
+
.option("-p, --port <port>", "Port to run the server on", "4001")
|
|
39
|
+
.option(
|
|
40
|
+
"-le, --local-editors <localEditors>",
|
|
41
|
+
"Link local document editors path",
|
|
42
|
+
)
|
|
43
|
+
.option(
|
|
44
|
+
"-ld, --local-documents <localDocuments>",
|
|
45
|
+
"Link local documents path",
|
|
46
|
+
)
|
|
47
|
+
.action(reactorLocalAction);
|
|
48
|
+
|
|
49
|
+
program
|
|
50
|
+
.command("help")
|
|
51
|
+
.description("Display help information")
|
|
52
|
+
.action(() => {
|
|
53
|
+
program.help();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
program.parse(process.argv);
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper";
|
|
2
|
+
import {
|
|
3
|
+
addSubgraph,
|
|
4
|
+
createSchema,
|
|
5
|
+
registerInternalListener,
|
|
6
|
+
setAdditionalContextFields,
|
|
7
|
+
startAPI,
|
|
8
|
+
} from "@powerhousedao/reactor-api";
|
|
9
|
+
import { DocumentDriveServer } from "document-drive";
|
|
10
|
+
import { FilesystemStorage } from "document-drive/storage/filesystem";
|
|
11
|
+
import * as DocumentModelsLibs from "document-model-libs/document-models";
|
|
12
|
+
import { DocumentModel } from "document-model/document";
|
|
13
|
+
import { module as DocumentModelLib } from "document-model/document-model";
|
|
14
|
+
import dotenv from "dotenv";
|
|
15
|
+
import { drizzle } from "drizzle-orm/connect";
|
|
16
|
+
import path from "path";
|
|
17
|
+
import * as searchListener from "@powerhousedao/general-document-indexer";
|
|
18
|
+
dotenv.config();
|
|
19
|
+
|
|
20
|
+
// start document drive server with all available document models & filesystem storage
|
|
21
|
+
const driveServer = new DocumentDriveServer(
|
|
22
|
+
[DocumentModelLib, ...Object.values(DocumentModelsLibs)] as DocumentModel[],
|
|
23
|
+
new FilesystemStorage(path.join(__dirname, "../file-storage")),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Start GraphQL API
|
|
27
|
+
const serverPort = process.env.PORT ? Number(process.env.PORT) : 4001;
|
|
28
|
+
|
|
29
|
+
const startServer = async () => {
|
|
30
|
+
const db = await drizzle("pglite", "./dev.db");
|
|
31
|
+
|
|
32
|
+
// init drive server
|
|
33
|
+
await driveServer.initialize();
|
|
34
|
+
try {
|
|
35
|
+
// add default drive
|
|
36
|
+
await driveServer.addDrive({
|
|
37
|
+
global: {
|
|
38
|
+
id: "powerhouse",
|
|
39
|
+
name: "Powerhouse",
|
|
40
|
+
icon: "powerhouse",
|
|
41
|
+
slug: "powerhouse",
|
|
42
|
+
},
|
|
43
|
+
local: {
|
|
44
|
+
availableOffline: true,
|
|
45
|
+
listeners: [],
|
|
46
|
+
sharingType: "public",
|
|
47
|
+
triggers: [],
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
} catch (e) {
|
|
51
|
+
// TODO check if error is because drive already exists
|
|
52
|
+
console.info("Default drive already exists. Skipping...");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// start api
|
|
57
|
+
await startAPI(driveServer, {
|
|
58
|
+
port: serverPort,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
setAdditionalContextFields({ db });
|
|
62
|
+
|
|
63
|
+
// register general document indexer listener
|
|
64
|
+
await registerInternalListener({
|
|
65
|
+
name: "search",
|
|
66
|
+
options: searchListener.options,
|
|
67
|
+
transmit: (strands) => searchListener.transmit(strands, db),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// add general document indexer subgraph
|
|
71
|
+
await addSubgraph({
|
|
72
|
+
getSchema: () =>
|
|
73
|
+
createSchema(
|
|
74
|
+
driveServer,
|
|
75
|
+
searchListener.resolvers as GraphQLResolverMap,
|
|
76
|
+
searchListener.typeDefs,
|
|
77
|
+
),
|
|
78
|
+
name: "search/:drive",
|
|
79
|
+
});
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error("App crashed", e);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { startServer };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"skipLibCheck": true,
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"moduleResolution": "Bundler",
|
|
16
|
+
"module": "ESNext",
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"lib": ["ESNext"],
|
|
19
|
+
"types": ["node", "./types.d.ts"]
|
|
20
|
+
},
|
|
21
|
+
"include": ["./"]
|
|
22
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { defineConfig } from "tsup";
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
|
|
8
|
+
function getDependencies(packageName: string) {
|
|
9
|
+
try {
|
|
10
|
+
const dependencyPath = require.resolve(packageName);
|
|
11
|
+
const packagePath = join(dependencyPath, "../../package.json");
|
|
12
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf8")) as {
|
|
13
|
+
dependencies?: Record<string, string>;
|
|
14
|
+
peerDependencies?: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
return Object.keys(packageJson.dependencies || {}).concat(
|
|
17
|
+
Object.keys(packageJson.peerDependencies || {}),
|
|
18
|
+
);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`Failed to load dependencies for ${packageName}:`, error);
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
entry: ["src/**/*.ts"],
|
|
27
|
+
splitting: true,
|
|
28
|
+
sourcemap: false,
|
|
29
|
+
clean: true,
|
|
30
|
+
format: "esm",
|
|
31
|
+
treeshake: true,
|
|
32
|
+
bundle: true,
|
|
33
|
+
platform: "node",
|
|
34
|
+
target: "node22",
|
|
35
|
+
noExternal: ["document-drive"],
|
|
36
|
+
external: getDependencies("document-drive"),
|
|
37
|
+
shims: true,
|
|
38
|
+
cjsInterop: true,
|
|
39
|
+
dts: {
|
|
40
|
+
entry: {
|
|
41
|
+
server: "src/server.ts",
|
|
42
|
+
cli: "src/cli.ts",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
package/types.d.ts
ADDED
package/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseDocumentDriveServer } from "document-drive";
|
|
2
|
+
import { DrizzleD1Database } from "drizzle-orm/d1";
|
|
3
|
+
import { IncomingHttpHeaders } from "http";
|
|
4
|
+
|
|
5
|
+
export type Context = {
|
|
6
|
+
driveServer: BaseDocumentDriveServer;
|
|
7
|
+
driveId?: string;
|
|
8
|
+
headers: IncomingHttpHeaders;
|
|
9
|
+
db: Omit<DrizzleD1Database, "run" | "batch" | "all" | "get" | "values">;
|
|
10
|
+
};
|