@hazae41/turbine 0.1.1 → 0.1.2
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference lib="deno.ns" />
|
|
2
2
|
import { Server } from "./mod.js";
|
|
3
|
+
import { RpcWorkerClient } from "@hazae41/bobine";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
export async function main(args) {
|
|
5
6
|
const options = {};
|
|
@@ -28,7 +29,9 @@ export async function main(args) {
|
|
|
28
29
|
throw new Error(`Unknown argument: ${arg}`);
|
|
29
30
|
}
|
|
30
31
|
const { uuid = process.env.UUID || "98e31aaf-c518-430b-8863-eed26c44d91f", path = process.env.DATA || "./data", port = Number(process.env.PORT) || 8080 } = options;
|
|
31
|
-
|
|
32
|
+
console.log("Starting...");
|
|
33
|
+
const worker = await RpcWorkerClient.spawn(uuid, path);
|
|
34
|
+
const server = new Server(worker);
|
|
32
35
|
await server.setup();
|
|
33
36
|
Deno.serve({ hostname: "0.0.0.0", port }, (request) => server.respond(request));
|
|
34
37
|
}
|
|
@@ -6,10 +6,9 @@ import { Mutex } from "@hazae41/mutex";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class Server {
|
|
8
8
|
#private;
|
|
9
|
-
readonly
|
|
10
|
-
readonly path: string;
|
|
9
|
+
readonly worker: RpcWorkerClient;
|
|
11
10
|
readonly subserver: RpcServer;
|
|
12
|
-
constructor(
|
|
11
|
+
constructor(worker: RpcWorkerClient);
|
|
13
12
|
setup(): Promise<void>;
|
|
14
13
|
respond(request: Request): Promise<any>;
|
|
15
14
|
}
|
|
@@ -18,12 +17,10 @@ export declare class Server {
|
|
|
18
17
|
*/
|
|
19
18
|
export declare class RpcServer {
|
|
20
19
|
#private;
|
|
21
|
-
readonly uuid: string;
|
|
22
|
-
readonly path: string;
|
|
23
20
|
readonly worker: RpcWorkerClient;
|
|
24
21
|
readonly seens: Set<string>;
|
|
25
22
|
readonly mutex: Mutex<undefined>;
|
|
26
|
-
constructor(
|
|
23
|
+
constructor(worker: RpcWorkerClient);
|
|
27
24
|
setup(): Promise<void>;
|
|
28
25
|
respond(request: RpcRequestInit): Promise<RpcErr | RpcOk<string>>;
|
|
29
26
|
}
|
|
@@ -50,20 +50,18 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
-
import { RpcPaymentError
|
|
53
|
+
import { RpcPaymentError } from "@hazae41/bobine";
|
|
54
54
|
import { RpcErr, RpcError, RpcInvalidParamsError, RpcMethodNotFoundError, RpcOk } from "@hazae41/jsonrpc";
|
|
55
55
|
import { Mutex } from "@hazae41/mutex";
|
|
56
56
|
/**
|
|
57
57
|
* Translates HTTP or WebSocket into JSON-RPC
|
|
58
58
|
*/
|
|
59
59
|
export class Server {
|
|
60
|
-
|
|
61
|
-
path;
|
|
60
|
+
worker;
|
|
62
61
|
subserver;
|
|
63
|
-
constructor(
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.subserver = new RpcServer(uuid, path);
|
|
62
|
+
constructor(worker) {
|
|
63
|
+
this.worker = worker;
|
|
64
|
+
this.subserver = new RpcServer(worker);
|
|
67
65
|
}
|
|
68
66
|
async setup() {
|
|
69
67
|
await this.subserver.setup();
|
|
@@ -96,15 +94,11 @@ export class Server {
|
|
|
96
94
|
* Converts hex to raw and checks efforts
|
|
97
95
|
*/
|
|
98
96
|
export class RpcServer {
|
|
99
|
-
uuid;
|
|
100
|
-
path;
|
|
101
97
|
worker;
|
|
102
98
|
seens = new Set();
|
|
103
99
|
mutex = new Mutex(undefined);
|
|
104
|
-
constructor(
|
|
105
|
-
this.
|
|
106
|
-
this.path = path;
|
|
107
|
-
this.worker = RpcWorkerClient.spawn(uuid, path);
|
|
100
|
+
constructor(worker) {
|
|
101
|
+
this.worker = worker;
|
|
108
102
|
}
|
|
109
103
|
async setup() {
|
|
110
104
|
await this.worker.setup();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@hazae41/turbine",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Bobine over HTTP and WebSocket",
|
|
6
6
|
"repository": "github:hazae41/turbine",
|
|
7
7
|
"author": "hazae41",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@hazae41/bobine": "^0.1.
|
|
25
|
+
"@hazae41/bobine": "^0.1.2",
|
|
26
26
|
"@hazae41/jsonrpc": "^1.2.1",
|
|
27
27
|
"@hazae41/mutex": "^3.0.1"
|
|
28
28
|
},
|