@spider-mesh/core 1.0.5 → 1.0.7
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/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/src/BuiltinTransporter.d.ts +14 -0
- package/build/src/BuiltinTransporter.js +224 -0
- package/build/src/BuiltinTransporter.js.map +1 -0
- package/build/src/DeepProxy.d.ts +7 -0
- package/build/src/DeepProxy.js +28 -0
- package/build/src/DeepProxy.js.map +1 -0
- package/build/src/RPCOptions.d.ts +15 -0
- package/build/src/RPCOptions.js +2 -0
- package/build/src/RPCOptions.js.map +1 -0
- package/build/src/RemoteService.d.ts +6 -0
- package/build/src/RemoteService.js +2 -0
- package/build/src/RemoteService.js.map +1 -0
- package/build/src/SpiderMesh.d.ts +22 -0
- package/build/src/SpiderMesh.js +203 -0
- package/build/src/SpiderMesh.js.map +1 -0
- package/build/src/SpiderMeshNestJSProvider.d.ts +7 -0
- package/build/src/SpiderMeshNestJSProvider.js +35 -0
- package/build/src/SpiderMeshNestJSProvider.js.map +1 -0
- package/build/src/SpiderMeshNode.d.ts +14 -0
- package/build/src/SpiderMeshNode.js +2 -0
- package/build/src/SpiderMeshNode.js.map +1 -0
- package/build/src/SpiderMeshTransporter.d.ts +9 -0
- package/build/src/SpiderMeshTransporter.js +2 -0
- package/build/src/SpiderMeshTransporter.js.map +1 -0
- package/build/src/decorators/OnMicroserviceReady.d.ts +3 -0
- package/build/src/decorators/OnMicroserviceReady.js +14 -0
- package/build/src/decorators/OnMicroserviceReady.js.map +1 -0
- package/build/src/decorators/SpiderMeshMicroservice.d.ts +9 -0
- package/build/src/decorators/SpiderMeshMicroservice.js +24 -0
- package/build/src/decorators/SpiderMeshMicroservice.js.map +1 -0
- package/build/src/decorators/createMicroserviceEvent.d.ts +14 -0
- package/build/src/decorators/createMicroserviceEvent.js +32 -0
- package/build/src/decorators/createMicroserviceEvent.js.map +1 -0
- package/package.json +8 -2
- package/.vscode/settings.json +0 -3
- package/index.ts +0 -8
package/build/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export { SpiderMeshNode, SpiderMeshNodeMetadata } from './src/SpiderMeshNode';
|
|
|
4
4
|
export { SpiderMeshTransporter } from './src/SpiderMeshTransporter';
|
|
5
5
|
export { RemoteService } from './src/RemoteService';
|
|
6
6
|
export { RPCOptions, RPCOptionsList } from './src/RPCOptions';
|
|
7
|
-
export { SpiderMeshMicroservice } from './src/SpiderMeshMicroservice';
|
|
7
|
+
export { SpiderMeshMicroservice } from './src/decorators/SpiderMeshMicroservice';
|
|
8
8
|
export { SpiderMeshNestJSProvider } from './src/SpiderMeshNestJSProvider';
|
|
9
|
+
export { OnMicroserviceReady } from './src/decorators/OnMicroserviceReady';
|
|
10
|
+
export { createMicroserviceEvent } from './src/decorators/createMicroserviceEvent';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { BuiltinTransporter } from './src/BuiltinTransporter';
|
|
2
2
|
export { SpiderMesh } from './src/SpiderMesh';
|
|
3
3
|
export { RPCOptionsList } from './src/RPCOptions';
|
|
4
|
-
export { SpiderMeshMicroservice } from './src/SpiderMeshMicroservice';
|
|
4
|
+
export { SpiderMeshMicroservice } from './src/decorators/SpiderMeshMicroservice';
|
|
5
5
|
export { SpiderMeshNestJSProvider } from './src/SpiderMeshNestJSProvider';
|
|
6
|
+
export { OnMicroserviceReady } from './src/decorators/OnMicroserviceReady';
|
|
7
|
+
export { createMicroserviceEvent } from './src/decorators/createMicroserviceEvent';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAI7C,OAAO,EAAc,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAI7C,OAAO,EAAc,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAA;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SpiderMeshTransporter } from "./SpiderMeshTransporter";
|
|
2
|
+
export declare class BuiltinTransporter implements SpiderMeshTransporter {
|
|
3
|
+
#private;
|
|
4
|
+
readonly node_id: string;
|
|
5
|
+
readonly namespace: string;
|
|
6
|
+
constructor(node_id: string, namespace: string);
|
|
7
|
+
on_node_offline(cb: (node_id: string) => any): {
|
|
8
|
+
unsubscribe: () => boolean;
|
|
9
|
+
};
|
|
10
|
+
listen<T = any>(topic: string, cb: (node_id: string, data: T) => any): {
|
|
11
|
+
unsubscribe: () => void;
|
|
12
|
+
};
|
|
13
|
+
publish<T = any>(event: string, node_id: string | null, data: T, queue?: boolean): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
import dgram from 'dgram';
|
|
3
|
+
import { createConnection, createServer } from "net";
|
|
4
|
+
import { networkInterfaces } from 'os';
|
|
5
|
+
import { PassThrough } from "stream";
|
|
6
|
+
async function tryCatch(fn) {
|
|
7
|
+
try {
|
|
8
|
+
return [null, typeof fn == 'function' ? await fn() : await fn];
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return [e, null];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const UDP_MULTICAST_PORT = Number(process.env.UDP_MULTICAST_PORT || 10001);
|
|
15
|
+
const MULTICAST_IP = process.env.MULTICAST_IP || '239.255.255.250';
|
|
16
|
+
const PRIVATE_SUBNET = process.env.PRIVATE_SUBNET;
|
|
17
|
+
const SEEDING_IP = process.env.SEEDING_IP;
|
|
18
|
+
const initAutoReconnectConnection = ({ reconnect_intervel = 10, ...options }) => {
|
|
19
|
+
return new Promise(async (s) => {
|
|
20
|
+
const $ = new PassThrough();
|
|
21
|
+
for (let i = 1; i <= reconnect_intervel; i++) {
|
|
22
|
+
const socket = await new Promise(s => {
|
|
23
|
+
const socket = createConnection(options);
|
|
24
|
+
socket.on('connect', () => s(socket));
|
|
25
|
+
socket.on('error', () => s(null));
|
|
26
|
+
socket.on('timeout', () => s(null));
|
|
27
|
+
});
|
|
28
|
+
if (socket) {
|
|
29
|
+
s($);
|
|
30
|
+
$.pipe(socket);
|
|
31
|
+
socket.on('data', data => $.emit('data', data));
|
|
32
|
+
socket.on('close', () => $.emit('close'));
|
|
33
|
+
i = 1;
|
|
34
|
+
await new Promise(s => socket.on('error', s));
|
|
35
|
+
await new Promise(s => setTimeout(s, 500));
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
return s(null);
|
|
39
|
+
}
|
|
40
|
+
$.emit('error');
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export class BuiltinTransporter {
|
|
44
|
+
node_id;
|
|
45
|
+
namespace;
|
|
46
|
+
#node_offline_callbacks = new Map;
|
|
47
|
+
#listeners = new Map;
|
|
48
|
+
#nodes_map = new Map;
|
|
49
|
+
#events_map = new Map();
|
|
50
|
+
#initing;
|
|
51
|
+
constructor(node_id, namespace) {
|
|
52
|
+
this.node_id = node_id;
|
|
53
|
+
this.namespace = namespace;
|
|
54
|
+
setTimeout(async () => {
|
|
55
|
+
while (true) {
|
|
56
|
+
this.#initing = this.#init();
|
|
57
|
+
const task = await this.#initing;
|
|
58
|
+
await task.next();
|
|
59
|
+
await task.wait_error();
|
|
60
|
+
await task.flush();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async #init() {
|
|
65
|
+
// Create UDP
|
|
66
|
+
const udp = dgram.createSocket({ type: 'udp4', reuseAddr: true });
|
|
67
|
+
udp.bind(UDP_MULTICAST_PORT, () => udp.addMembership(MULTICAST_IP));
|
|
68
|
+
udp.on('message', (raw, rinfo) => {
|
|
69
|
+
this.#on_message(rinfo.address, raw);
|
|
70
|
+
});
|
|
71
|
+
// Find free port
|
|
72
|
+
const { tcp_port, server } = await new Promise(async (s) => {
|
|
73
|
+
for (let tcp_port = 10000; true; tcp_port++) {
|
|
74
|
+
const server = createServer();
|
|
75
|
+
server.listen(tcp_port);
|
|
76
|
+
const success = await new Promise(s => {
|
|
77
|
+
server.on('listening', () => s(true));
|
|
78
|
+
server.on('error', () => s(false));
|
|
79
|
+
});
|
|
80
|
+
if (success)
|
|
81
|
+
return s({ tcp_port, server });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
server.on('connection', socket => {
|
|
85
|
+
const remote_host = socket.remoteAddress?.split(':')?.pop();
|
|
86
|
+
remote_host && socket.on('data', data => this.#on_message(remote_host, data, socket));
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
udp,
|
|
90
|
+
tcp_port,
|
|
91
|
+
next: async () => {
|
|
92
|
+
const broadcast_ips = [];
|
|
93
|
+
// Add multicast IP
|
|
94
|
+
MULTICAST_IP && broadcast_ips.push(MULTICAST_IP);
|
|
95
|
+
// Scan subnet IP
|
|
96
|
+
if (PRIVATE_SUBNET) {
|
|
97
|
+
const current_ips = Object.values(networkInterfaces()).map(c => c?.map(f => f.address) || []).flat(2);
|
|
98
|
+
for (let i = 1; i <= 255; i++) {
|
|
99
|
+
const host = `${PRIVATE_SUBNET}.${i}`;
|
|
100
|
+
!current_ips.includes(host) && broadcast_ips.push(host);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Hello via UDP
|
|
104
|
+
broadcast_ips.forEach(host => this.#hello(undefined, { host, socket: udp }));
|
|
105
|
+
// Scan remote node ( <= internet)
|
|
106
|
+
if (SEEDING_IP) {
|
|
107
|
+
const ips = SEEDING_IP.split(',').map(c => c.trim().split(':'));
|
|
108
|
+
for (const [host, port] of ips) {
|
|
109
|
+
const socket = await initAutoReconnectConnection({ host, port: Number(port), timeout: 2500, });
|
|
110
|
+
socket?.on('data', data => this.#on_message(host, data, socket));
|
|
111
|
+
socket && this.#hello(socket);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
wait_error: () => new Promise(async (s) => {
|
|
116
|
+
await new Promise(s => {
|
|
117
|
+
udp.on('close', s);
|
|
118
|
+
udp.on('error', s);
|
|
119
|
+
server.on('error', s);
|
|
120
|
+
server.on('drop', s);
|
|
121
|
+
server.on('close', s);
|
|
122
|
+
});
|
|
123
|
+
}),
|
|
124
|
+
flush: () => {
|
|
125
|
+
udp.close();
|
|
126
|
+
server.close();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async #hello(socket, udp_socket) {
|
|
131
|
+
const { tcp_port } = await this.#initing;
|
|
132
|
+
const msg = {
|
|
133
|
+
data: {
|
|
134
|
+
node_id: this.node_id,
|
|
135
|
+
port: tcp_port,
|
|
136
|
+
listening_events: ['#hello', ...this.#listeners.keys()],
|
|
137
|
+
peers: [...this.#nodes_map.values()].map(({ host, listening_events, node_id, port }) => ({ listening_events, node_id, port, host }))
|
|
138
|
+
},
|
|
139
|
+
namespace: this.namespace,
|
|
140
|
+
sender_node_id: this.node_id,
|
|
141
|
+
topic: '#hello'
|
|
142
|
+
};
|
|
143
|
+
const buffer = Buffer.from(JSON.stringify(msg), 'utf8');
|
|
144
|
+
socket?.write(buffer);
|
|
145
|
+
udp_socket?.socket.send(buffer, UDP_MULTICAST_PORT, udp_socket.host);
|
|
146
|
+
}
|
|
147
|
+
async #on_message(remote_address, data, tcp_socket) {
|
|
148
|
+
if (!remote_address)
|
|
149
|
+
return;
|
|
150
|
+
const [_, msg] = await tryCatch(() => JSON.parse(data.toString('utf8')));
|
|
151
|
+
if (!msg)
|
|
152
|
+
return;
|
|
153
|
+
if (msg.sender_node_id == this.node_id)
|
|
154
|
+
return;
|
|
155
|
+
// New node
|
|
156
|
+
if (msg.topic == `#hello` && msg.namespace == this.namespace) {
|
|
157
|
+
return this.#add_node(remote_address, msg.data, tcp_socket);
|
|
158
|
+
}
|
|
159
|
+
this.#listeners.get(msg.topic)?.forEach(cb => cb(msg.sender_node_id, msg.data));
|
|
160
|
+
}
|
|
161
|
+
async #add_node(host, new_node, tcp_socket) {
|
|
162
|
+
process.env.SPIDERMESH_TCP_DEBUG && console.log(`[${new Date().toLocaleTimeString()}] New node [${host}]`, new_node);
|
|
163
|
+
if (!this.#nodes_map.get(new_node.node_id)?.socket) {
|
|
164
|
+
const socket = await initAutoReconnectConnection({ host, port: new_node.port, timeout: 2500 }) || tcp_socket;
|
|
165
|
+
if (!socket)
|
|
166
|
+
return;
|
|
167
|
+
const on_offline = (e) => {
|
|
168
|
+
process.env.SPIDERMESH_TCP_DEBUG && console.log(`Node offline: ${new_node.node_id}`);
|
|
169
|
+
this.#node_offline_callbacks?.forEach(cb => cb(new_node.node_id));
|
|
170
|
+
this.#nodes_map.delete(new_node.node_id);
|
|
171
|
+
};
|
|
172
|
+
socket.on('error', on_offline);
|
|
173
|
+
socket.on('close', on_offline);
|
|
174
|
+
this.#nodes_map.set(new_node.node_id, { ...new_node, host, socket });
|
|
175
|
+
new_node.peers.every(p => p.node_id != this.node_id) && await this.#hello(socket);
|
|
176
|
+
}
|
|
177
|
+
for (const event of new_node.listening_events) {
|
|
178
|
+
!this.#events_map.has(event) && this.#events_map.set(event, new Set());
|
|
179
|
+
this.#events_map.get(event)?.add(new_node.node_id);
|
|
180
|
+
}
|
|
181
|
+
new_node.peers.filter(peer => peer.node_id != this.node_id && !this.#nodes_map.has(peer.node_id)).forEach(peer => this.#add_node(host, { ...peer, peers: [] }));
|
|
182
|
+
}
|
|
183
|
+
on_node_offline(cb) {
|
|
184
|
+
const id = randomUUID();
|
|
185
|
+
this.#node_offline_callbacks.set(id, cb);
|
|
186
|
+
return { unsubscribe: () => this.#node_offline_callbacks.delete(id) };
|
|
187
|
+
}
|
|
188
|
+
#broadcast_listen;
|
|
189
|
+
listen(topic, cb) {
|
|
190
|
+
this.#broadcast_listen && clearTimeout(this.#broadcast_listen);
|
|
191
|
+
this.#broadcast_listen = setTimeout(() => {
|
|
192
|
+
// Notify about update
|
|
193
|
+
this.#nodes_map.forEach(node => this.#hello(node.socket));
|
|
194
|
+
}, 1000);
|
|
195
|
+
!this.#listeners.has(topic) && this.#listeners.set(topic, new Map());
|
|
196
|
+
const id = randomUUID();
|
|
197
|
+
this.#listeners.get(topic)?.set(id, cb);
|
|
198
|
+
return {
|
|
199
|
+
unsubscribe: () => {
|
|
200
|
+
this.#listeners.get(topic)?.delete(id);
|
|
201
|
+
this.#listeners.get(topic)?.size == 0 && this.#listeners.delete(topic);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async publish(event, node_id, data, queue) {
|
|
206
|
+
const msg = {
|
|
207
|
+
data,
|
|
208
|
+
namespace: this.namespace,
|
|
209
|
+
sender_node_id: this.node_id,
|
|
210
|
+
topic: event || node_id || '#'
|
|
211
|
+
};
|
|
212
|
+
const buffer = Buffer.from(JSON.stringify(msg), 'utf8');
|
|
213
|
+
if (node_id) {
|
|
214
|
+
const node = this.#nodes_map.get(node_id);
|
|
215
|
+
node?.socket?.write(buffer);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
for (const node_id of this.#events_map.get(event) || []) {
|
|
219
|
+
const node = this.#nodes_map.get(node_id);
|
|
220
|
+
node?.socket?.write(buffer);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=BuiltinTransporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuiltinTransporter.js","sourceRoot":"","sources":["../../src/BuiltinTransporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAA0B,MAAM,KAAK,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAA;AACtC,OAAO,EAAU,WAAW,EAAE,MAAM,QAAQ,CAAC;AAI7C,KAAK,UAAU,QAAQ,CAAI,EAAmD;IAC1E,IAAI;QACA,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAa,CAAA;KAC7E;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,CAAC,EAAE,IAAI,CAAa,CAAA;KAC/B;AACL,CAAC;AAsBD,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,KAAK,CAAC,CAAA;AAC1E,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,iBAAiB,CAAA;AAClE,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAA;AACjD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAA;AAGzC,MAAM,2BAA2B,GAAG,CAAC,EAAE,kBAAkB,GAAG,EAAE,EAAE,GAAG,OAAO,EAAuD,EAAE,EAAE;IAEjI,OAAO,IAAI,OAAO,CAAgB,KAAK,EAAC,CAAC,EAAC,EAAE;QAExC,MAAM,CAAC,GAAG,IAAI,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AAK,CAAC,IAAI,EAAE,EAAE;YACrD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACzC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;SAC9B;IAGL,CAAC;CAEJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class DeepProxy {
|
|
2
|
+
options_list;
|
|
3
|
+
handler;
|
|
4
|
+
#options = {};
|
|
5
|
+
constructor(options_list, handler) {
|
|
6
|
+
this.options_list = options_list;
|
|
7
|
+
this.handler = handler;
|
|
8
|
+
}
|
|
9
|
+
nest() {
|
|
10
|
+
return new Proxy(this, {
|
|
11
|
+
get: (_, method) => {
|
|
12
|
+
if (method == 'then')
|
|
13
|
+
return null;
|
|
14
|
+
if (method.startsWith('set_')) {
|
|
15
|
+
const m = method.split('set_')[1];
|
|
16
|
+
if (this.options_list.includes(m)) {
|
|
17
|
+
return value => {
|
|
18
|
+
this.#options[m] = value;
|
|
19
|
+
return this.nest();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return this.handler(method, this.#options);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=DeepProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeepProxy.js","sourceRoot":"","sources":["../../src/DeepProxy.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,SAAS;IAKN;IACA;IAJZ,QAAQ,GAA2B,EAAE,CAAA;IAErC,YACY,YAAsB,EACtB,OAAyC;QADzC,iBAAY,GAAZ,YAAY,CAAU;QACtB,YAAO,GAAP,OAAO,CAAkC;IACjD,CAAC;IAGL,IAAI;QACA,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;YACnB,GAAG,EAAE,CAAC,CAAC,EAAE,MAAc,EAAE,EAAE;gBAEvB,IAAI,MAAM,IAAI,MAAM;oBAAE,OAAO,IAAI,CAAA;gBAEjC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;oBAC3B,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;oBACjC,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;wBAC/B,OAAO,KAAK,CAAC,EAAE;4BACX,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;4BACxB,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;wBACtB,CAAC,CAAA;qBACJ;iBACJ;gBACD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC9C,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type RPCOptions<T = any> = {
|
|
2
|
+
node_id: string;
|
|
3
|
+
ip: string;
|
|
4
|
+
load_balance_mode: 'round-robin' | 'least-connections' | 'weight';
|
|
5
|
+
offline_cut: boolean;
|
|
6
|
+
timeout: number;
|
|
7
|
+
nevermind: boolean;
|
|
8
|
+
fallback: T;
|
|
9
|
+
retry: number;
|
|
10
|
+
retry_delay: number;
|
|
11
|
+
require_ack: boolean;
|
|
12
|
+
ack_timeout: number;
|
|
13
|
+
queue: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const RPCOptionsList: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RPCOptions.js","sourceRoot":"","sources":["../../src/RPCOptions.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,mBAAmB,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RPCOptions } from "./RPCOptions";
|
|
2
|
+
export type RemoteService<T> = ({
|
|
3
|
+
[K in keyof T as (T[K] extends (...args: any) => any ? K : '')]: T[K] extends (...args: any) => any ? ((...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>>) : null;
|
|
4
|
+
} & {
|
|
5
|
+
[key in keyof RPCOptions as `set_${key}`]: (value: RPCOptions[key]) => RemoteService<T>;
|
|
6
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteService.js","sourceRoot":"","sources":["../../src/RemoteService.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SpiderMeshNodeMetadata } from './SpiderMeshNode';
|
|
2
|
+
import { SpiderMeshTransporter } from './SpiderMeshTransporter';
|
|
3
|
+
import { RPCOptions } from './RPCOptions';
|
|
4
|
+
import { RemoteService } from './RemoteService';
|
|
5
|
+
export declare class SpiderMesh {
|
|
6
|
+
#private;
|
|
7
|
+
readonly node_id: `${string}-${string}-${string}-${string}-${string}`;
|
|
8
|
+
readonly namespace: any;
|
|
9
|
+
$metadata(): Promise<SpiderMeshNodeMetadata>;
|
|
10
|
+
add_transporter(factory: {
|
|
11
|
+
new (...args: any[]): SpiderMeshTransporter;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
rpc(service: string, method: string, args: any, options: RPCOptions): Promise<any>;
|
|
14
|
+
active_local_service(name: string, instance: any): Promise<void>;
|
|
15
|
+
link_remote_service<T>(factory: {
|
|
16
|
+
new (...args: any[]): T;
|
|
17
|
+
}): RemoteService<T>;
|
|
18
|
+
publish<T = any>(topic: string, data: T): Promise<void>;
|
|
19
|
+
subscribe<T = any>(topic: string, cb: (from_node_id: string, data: T) => any): Promise<{
|
|
20
|
+
unsubscribe: () => void;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { get } from 'http';
|
|
3
|
+
import { readFileSync, existsSync } from 'fs';
|
|
4
|
+
import { networkInterfaces } from 'os';
|
|
5
|
+
import { DeepProxy } from './DeepProxy';
|
|
6
|
+
import { RPCOptionsList } from './RPCOptions';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
export class SpiderMesh {
|
|
9
|
+
#package_json = existsSync(`package.json`) ? JSON.parse(readFileSync(`package.json`, 'utf8')) || {} : {};
|
|
10
|
+
node_id = randomUUID();
|
|
11
|
+
namespace = process.env.NAMESPACE || this.#package_json.name || 'default';
|
|
12
|
+
#services = new Map;
|
|
13
|
+
#nodes = new Map;
|
|
14
|
+
#transporters = new Map;
|
|
15
|
+
#rpc_queue = new Map;
|
|
16
|
+
#public_ip = new Promise(s => {
|
|
17
|
+
get('http://api.ipify.org', (res) => {
|
|
18
|
+
res.setEncoding('utf8');
|
|
19
|
+
let rawData = '';
|
|
20
|
+
res.on('data', (chunk) => { rawData += chunk; });
|
|
21
|
+
res.on('end', () => s(rawData));
|
|
22
|
+
}).on('error', () => s(null));
|
|
23
|
+
});
|
|
24
|
+
async $metadata() {
|
|
25
|
+
const ips = Object.values(networkInterfaces()).map(itf => itf?.map(ip => ip.address) || []).flat(2);
|
|
26
|
+
const { name, version } = this.#package_json;
|
|
27
|
+
return {
|
|
28
|
+
id: this.node_id,
|
|
29
|
+
name,
|
|
30
|
+
version,
|
|
31
|
+
path: process.cwd(),
|
|
32
|
+
argv: process.argv,
|
|
33
|
+
uptime: process.uptime(),
|
|
34
|
+
hostname: os.hostname(),
|
|
35
|
+
plaform: os.platform(),
|
|
36
|
+
node_version: process.version,
|
|
37
|
+
public_ip: await this.#public_ip,
|
|
38
|
+
ip_addresses: ips,
|
|
39
|
+
last_online: Date.now(),
|
|
40
|
+
active: true,
|
|
41
|
+
offline: false,
|
|
42
|
+
services: [...this.#services.keys()],
|
|
43
|
+
namespace: this.namespace,
|
|
44
|
+
linked: [...this.#nodes.keys()],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async add_transporter(factory) {
|
|
48
|
+
const transporter = new factory(this.node_id, this.namespace);
|
|
49
|
+
this.#transporters.set(factory.name, transporter);
|
|
50
|
+
transporter.on_node_offline(id => {
|
|
51
|
+
const node = this.#nodes.get(id);
|
|
52
|
+
if (!node)
|
|
53
|
+
return;
|
|
54
|
+
process.env.SPIDERMESH_DEBUG && console.log(`Node ${id} offline`);
|
|
55
|
+
node.transporters?.delete(factory.name);
|
|
56
|
+
node.transporters?.size == 0 && this.#nodes.delete(id);
|
|
57
|
+
this.#services.forEach(service => service.nodes = service.nodes?.filter(node => node.id != id));
|
|
58
|
+
[...this.#rpc_queue.entries()].forEach(([rid, { reject }]) => {
|
|
59
|
+
reject(new Error('SERVICE_OFFLINE'));
|
|
60
|
+
this.#rpc_queue.delete(rid);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
transporter.listen(this.node_id, async (sender_node_id, msg) => {
|
|
64
|
+
if (msg.type == 'rpc') {
|
|
65
|
+
const instance = this.#services.get(msg.service);
|
|
66
|
+
const args = msg.args.map(arg => arg != '__FUNCTION__' ? arg : (...args) => {
|
|
67
|
+
sender_node_id && transporter.publish(sender_node_id, sender_node_id, { id: msg.id, type: 'callback', args });
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
const response = await instance?.[msg.method]?.(...args);
|
|
71
|
+
sender_node_id && transporter.publish(sender_node_id, sender_node_id, { id: msg.id, type: 'response', response });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
sender_node_id && transporter.publish(sender_node_id, sender_node_id, { id: msg.id, type: 'error', error });
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const request = this.#rpc_queue.get(msg.id);
|
|
79
|
+
if (!request)
|
|
80
|
+
return;
|
|
81
|
+
if (msg.type == 'callback') {
|
|
82
|
+
request.args?.[msg.index]?.();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (msg.type == 'ack') {
|
|
86
|
+
request.last_ping = Date.now();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (msg.type == 'error') {
|
|
90
|
+
request.reject(msg.error);
|
|
91
|
+
this.#rpc_queue.delete(msg.id);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (msg.type == 'response') {
|
|
95
|
+
request.success(msg.response);
|
|
96
|
+
this.#rpc_queue.delete(msg.id);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
transporter.listen('#join', (sender_node_id, node) => this.#on_node_discovered(node, transporter));
|
|
101
|
+
const me = await this.$metadata();
|
|
102
|
+
await transporter.publish('#join', null, me);
|
|
103
|
+
}
|
|
104
|
+
async #on_node_discovered(node, transporter) {
|
|
105
|
+
if (node.id == this.node_id)
|
|
106
|
+
return;
|
|
107
|
+
process.env.SPIDERMESH_DEBUG && console.log(`New node `, node);
|
|
108
|
+
const discovered = this.#nodes.get(node.id);
|
|
109
|
+
const new_node = {
|
|
110
|
+
...discovered,
|
|
111
|
+
...node,
|
|
112
|
+
transporters: discovered?.transporters || new Map(),
|
|
113
|
+
offline: false
|
|
114
|
+
};
|
|
115
|
+
this.#nodes.set(node.id, new_node);
|
|
116
|
+
const transporter_name = Object.getPrototypeOf(transporter).constructor.name;
|
|
117
|
+
this.#nodes.get(node.id)?.transporters?.set(transporter_name, transporter);
|
|
118
|
+
node.services.forEach(service => {
|
|
119
|
+
const $service = this.#services.get(service);
|
|
120
|
+
if (!$service) {
|
|
121
|
+
this.#services.set(service, {
|
|
122
|
+
last_call_index: -1,
|
|
123
|
+
nodes: [node]
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if ($service.nodes) {
|
|
128
|
+
const index = $service.nodes.findIndex(n => n.id == new_node.id);
|
|
129
|
+
index >= 0 ? ($service.nodes[index] = new_node) : $service.nodes.push(new_node);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
$service.nodes = [new_node];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
!node.linked.includes(this.node_id) && await transporter.publish('#join', null, await this.$metadata());
|
|
136
|
+
}
|
|
137
|
+
async #caculate_request_node_id(service, options) {
|
|
138
|
+
const $ = this.#services.get(service);
|
|
139
|
+
if (!$ || $.nodes.length == 0)
|
|
140
|
+
return null;
|
|
141
|
+
$.last_call_index = ($.last_call_index + 1) % $.nodes.length;
|
|
142
|
+
return $.nodes[$.last_call_index].id;
|
|
143
|
+
}
|
|
144
|
+
async rpc(service, method, args, options) {
|
|
145
|
+
return await new Promise(async (success, r) => {
|
|
146
|
+
const reject = (err) => (options.fallback !== undefined) ? success(options.fallback) : r(err);
|
|
147
|
+
const node_id = options.node_id || await this.#caculate_request_node_id(service, options);
|
|
148
|
+
if (!node_id)
|
|
149
|
+
return reject(new Error('SERVICE_OFFLINE'));
|
|
150
|
+
const rid = randomUUID();
|
|
151
|
+
(!options.timeout || options.timeout > 0) && setTimeout(() => {
|
|
152
|
+
reject(new Error('TIMEOUT'));
|
|
153
|
+
this.#rpc_queue.delete(rid);
|
|
154
|
+
}, options.timeout || 10000);
|
|
155
|
+
!options.nevermind && this.#rpc_queue.set(rid, {
|
|
156
|
+
args,
|
|
157
|
+
last_ping: 0,
|
|
158
|
+
reject,
|
|
159
|
+
request_time: Date.now(),
|
|
160
|
+
success,
|
|
161
|
+
timeout: options.timeout,
|
|
162
|
+
target_node_id: node_id
|
|
163
|
+
});
|
|
164
|
+
const retry_count = options.retry || 1;
|
|
165
|
+
for (let i = retry_count; i > 0; i--) {
|
|
166
|
+
for (const [__, transporter] of this.#nodes.get(node_id)?.transporters || []) {
|
|
167
|
+
try {
|
|
168
|
+
await transporter.publish(node_id, node_id, { type: 'rpc', id: rid, args, method, service });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
i > 1 && await new Promise(s => setTimeout(s, options.retry_delay || 1000));
|
|
175
|
+
}
|
|
176
|
+
if (options.fallback)
|
|
177
|
+
return success(options.fallback);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
#pending_join_mesh;
|
|
181
|
+
async active_local_service(name, instance) {
|
|
182
|
+
this.#services.set(name, instance);
|
|
183
|
+
this.#pending_join_mesh && clearTimeout(this.#pending_join_mesh);
|
|
184
|
+
this.#pending_join_mesh = setTimeout(async () => {
|
|
185
|
+
const me = await this.$metadata();
|
|
186
|
+
this.#transporters.forEach(t => t.publish('#join', null, me));
|
|
187
|
+
}, 1000);
|
|
188
|
+
}
|
|
189
|
+
link_remote_service(factory) {
|
|
190
|
+
const service_name = factory.name;
|
|
191
|
+
return new Proxy({}, {
|
|
192
|
+
get: (_, method) => new DeepProxy(RPCOptionsList, (method, options) => (...args) => this.rpc(service_name, method, args, options)).nest()[method]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async publish(topic, data) {
|
|
196
|
+
this.#transporters.forEach(t => t.publish(topic, null, data));
|
|
197
|
+
}
|
|
198
|
+
async subscribe(topic, cb) {
|
|
199
|
+
const subscriptions = [...this.#transporters.values()].map(t => t.listen(topic, cb));
|
|
200
|
+
return { unsubscribe: () => subscriptions.forEach(s => s.unsubscribe()) };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=SpiderMesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpiderMesh.js","sourceRoot":"","sources":["../../src/SpiderMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MA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AAE,WAAW,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,CAAA;IAC7E,CAAC;CAEJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SpiderMeshTransporter } from './SpiderMeshTransporter';
|
|
2
|
+
import { SpiderMesh } from './SpiderMesh';
|
|
3
|
+
export declare const SpiderMeshNestJSProvider: (transporters?: (new (...arsg: any) => SpiderMeshTransporter)[]) => {
|
|
4
|
+
provide: never[];
|
|
5
|
+
useFactory: (ms: SpiderMesh) => Promise<void>;
|
|
6
|
+
inject: (typeof SpiderMesh)[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SpiderMesh } from './SpiderMesh';
|
|
2
|
+
import { ServiceInstanceList } from './decorators/SpiderMeshMicroservice';
|
|
3
|
+
import { BuiltinTransporter } from './BuiltinTransporter';
|
|
4
|
+
export const SpiderMeshNestJSProvider = (transporters = [BuiltinTransporter]) => ({
|
|
5
|
+
provide: [],
|
|
6
|
+
useFactory: async (ms) => {
|
|
7
|
+
for (const transporter of transporters) {
|
|
8
|
+
await ms.add_transporter(transporter);
|
|
9
|
+
}
|
|
10
|
+
// Active event requester
|
|
11
|
+
for (const { instance, event_subscribers } of ServiceInstanceList) {
|
|
12
|
+
for (const { event, method, requests } of event_subscribers) {
|
|
13
|
+
requests.on('data', data => ms.publish(event, data));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Active local services
|
|
17
|
+
for (const { name, instance } of ServiceInstanceList) {
|
|
18
|
+
await ms.active_local_service(name, instance);
|
|
19
|
+
}
|
|
20
|
+
// Active event subscribers
|
|
21
|
+
for (const { instance, event_subscribers } of ServiceInstanceList) {
|
|
22
|
+
for (const { event, method, requests } of event_subscribers) {
|
|
23
|
+
ms.subscribe(event, (_, data) => instance[method]?.(data));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// Active ready hook
|
|
27
|
+
for (const { instance, ready_hook_methods } of ServiceInstanceList) {
|
|
28
|
+
for (const method of ready_hook_methods) {
|
|
29
|
+
await instance[method]?.();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
inject: [SpiderMesh]
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=SpiderMeshNestJSProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpiderMeshNestJSProvider.js","sourceRoot":"","sources":["../../src/SpiderMeshNestJSProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACpC,eAAoE,CAAC,kBAAkB,CAAC,EAC1F,EAAE,CAAC,CAAC;IACF,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,KAAK,EAAE,EAAc,EAAE,EAAE;QACjC,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;YACpC,MAAM,EAAE,CAAC,eAAe,CAAC,WAAW,CAAC,CAAA;SACxC;QAED,yBAAyB;QACzB,KAAK,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,mBAAmB,EAAE;YAC/D,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,iBAAiB,EAAE;gBACzD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;aACvD;SACJ;QAED,wBAAwB;QACxB,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,mBAAmB,EAAE;YAClD,MAAM,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;SAChD;QAED,2BAA2B;QAC3B,KAAK,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,mBAAmB,EAAE;YAC/D,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,iBAAiB,EAAE;gBACzD,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;aAC7D;SACJ;QAED,oBAAoB;QACpB,KAAK,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,mBAAmB,EAAE;YAChE,KAAK,MAAM,MAAM,IAAI,kBAAkB,EAAE;gBACrC,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;aAC7B;SACJ;IACL,CAAC;IACD,MAAM,EAAE,CAAC,UAAU,CAAC;CACvB,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SpiderMeshTransporter } from "./SpiderMeshTransporter";
|
|
2
|
+
export type SpiderMeshNodeMetadata = {
|
|
3
|
+
id: string;
|
|
4
|
+
namespace: string;
|
|
5
|
+
ip_addresses: string[];
|
|
6
|
+
last_online: number;
|
|
7
|
+
active: boolean;
|
|
8
|
+
offline: boolean;
|
|
9
|
+
services: string[];
|
|
10
|
+
linked: string[];
|
|
11
|
+
};
|
|
12
|
+
export type SpiderMeshNode = SpiderMeshNodeMetadata & {
|
|
13
|
+
transporters?: Map<string, SpiderMeshTransporter>;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpiderMeshNode.js","sourceRoot":"","sources":["../../src/SpiderMeshNode.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type SpiderMeshTransporter = {
|
|
2
|
+
node_id: string;
|
|
3
|
+
namespace: string;
|
|
4
|
+
on_node_offline: (cb: (node_id: string) => any) => void;
|
|
5
|
+
listen: <T = any>(topic: string, cb: (node_id: string, data: T) => any) => {
|
|
6
|
+
unsubscribe: Function;
|
|
7
|
+
};
|
|
8
|
+
publish<T = any>(event: string, node_id: string | null, data: T, queue?: boolean): Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpiderMeshTransporter.js","sourceRoot":"","sources":["../../src/SpiderMeshTransporter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const OnMicroserviceReadyHook = Symbol.for('OnMicroserviceReadyHook');
|
|
2
|
+
export const OnMicroserviceReady = () => (target, propertyKey, descriptor) => {
|
|
3
|
+
Object.defineProperty(descriptor.value, OnMicroserviceReadyHook, { value: true });
|
|
4
|
+
};
|
|
5
|
+
export const listReadyHookMethods = (target) => {
|
|
6
|
+
const methods = [];
|
|
7
|
+
for (let f = target; f != null; f = Object.getPrototypeOf(f)) {
|
|
8
|
+
for (const method of Object.getOwnPropertyNames(f)) {
|
|
9
|
+
f[method]?.[OnMicroserviceReadyHook] && methods.push(method);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return methods;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=OnMicroserviceReady.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnMicroserviceReady.js","sourceRoot":"","sources":["../../../src/decorators/OnMicroserviceReady.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAA;AAE5E,MAAM,CAAC,MAAM,mBAAmB,GAA0B,GAAG,EAAE,CAAC,CAAI,MAAc,EAAE,WAA4B,EAAE,UAAsC,EAAE,EAAE;IACxJ,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,uBAAuB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AACrF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,EAAc,CAAA;IAC9B,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;QAC1D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE;YAChD,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SAC/D;KACJ;IACD,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventSubscriberMetadata } from "./createMicroserviceEvent";
|
|
2
|
+
export declare const ServiceInstanceList: {
|
|
3
|
+
factory: any;
|
|
4
|
+
name: string;
|
|
5
|
+
instance: any;
|
|
6
|
+
ready_hook_methods: string[];
|
|
7
|
+
event_subscribers: EventSubscriberMetadata[];
|
|
8
|
+
}[];
|
|
9
|
+
export declare const SpiderMeshMicroservice: () => (factory: new (...args: any[]) => any) => any;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { listReadyHookMethods } from "./OnMicroserviceReady";
|
|
2
|
+
import { listEventSubscribers } from "./createMicroserviceEvent";
|
|
3
|
+
export const ServiceInstanceList = new Array();
|
|
4
|
+
export const SpiderMeshMicroservice = () => (factory) => {
|
|
5
|
+
const C = class extends factory {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
super(...args);
|
|
8
|
+
const ready_hook_methods = listReadyHookMethods(factory.prototype);
|
|
9
|
+
const event_subscribers = listEventSubscribers(factory.prototype);
|
|
10
|
+
ServiceInstanceList.push({
|
|
11
|
+
factory,
|
|
12
|
+
name: factory.name,
|
|
13
|
+
instance: this,
|
|
14
|
+
ready_hook_methods,
|
|
15
|
+
event_subscribers
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(C, 'name', {
|
|
20
|
+
value: factory.name
|
|
21
|
+
});
|
|
22
|
+
return C;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=SpiderMeshMicroservice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpiderMeshMicroservice.js","sourceRoot":"","sources":["../../../src/decorators/SpiderMeshMicroservice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAA2B,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAEzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,KAAK,EAMxC,CAAA;AAEJ,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,CAAC,OAAqC,EAAE,EAAE;IAElF,MAAM,CAAC,GAAG,KAAM,SAAQ,OAAO;QAC3B,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;YACd,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YAClE,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YACjE,mBAAmB,CAAC,IAAI,CAAC;gBACrB,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,QAAQ,EAAE,IAAI;gBACd,kBAAkB;gBAClB,iBAAiB;aACpB,CAAC,CAAA;QACN,CAAC;KACJ,CAAA;IACD,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE;QAC7B,KAAK,EAAE,OAAO,CAAC,IAAI;KACtB,CAAC,CAAA;IACF,OAAO,CAAQ,CAAA;AACnB,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Duplex } from "stream";
|
|
3
|
+
export declare const EventSubscriberHook: unique symbol;
|
|
4
|
+
export type EventSubscriberMetadata = {
|
|
5
|
+
method: string;
|
|
6
|
+
event: string;
|
|
7
|
+
requests: Duplex;
|
|
8
|
+
};
|
|
9
|
+
export declare const createMicroserviceEvent: <T>(event: string) => [{
|
|
10
|
+
new (): {
|
|
11
|
+
publish(data: T): void;
|
|
12
|
+
};
|
|
13
|
+
}, () => MethodDecorator];
|
|
14
|
+
export declare const listEventSubscribers: (target: any) => EventSubscriberMetadata[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Duplex } from "stream";
|
|
2
|
+
export const EventSubscriberHook = Symbol.for('SubscribeEventHook');
|
|
3
|
+
export const createMicroserviceEvent = (event) => {
|
|
4
|
+
const requests = new Duplex();
|
|
5
|
+
const subscribe_event_decorator = () => (target, method, descriptor) => {
|
|
6
|
+
if (typeof method == 'string') {
|
|
7
|
+
const value = {
|
|
8
|
+
method,
|
|
9
|
+
event,
|
|
10
|
+
requests
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(descriptor.value, EventSubscriberHook, { value });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
class Publisher {
|
|
16
|
+
publish(data) {
|
|
17
|
+
requests.emit('data', data);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [Publisher, subscribe_event_decorator];
|
|
21
|
+
};
|
|
22
|
+
export const listEventSubscribers = (target) => {
|
|
23
|
+
const list = new Array();
|
|
24
|
+
for (let f = target; f != null; f = Object.getPrototypeOf(f)) {
|
|
25
|
+
for (const method of Object.getOwnPropertyNames(f)) {
|
|
26
|
+
const metadata = f[method]?.[EventSubscriberHook];
|
|
27
|
+
metadata && list.push(metadata);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return list;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=createMicroserviceEvent.js.map
|
|
@@ -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AAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAA;YAC1E,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAClC;KACJ;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spider-mesh/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"description": "Lightweight microservice framework for typescript, auto discovery, load-balancing, fault-torrent, multiple transporters",
|
|
6
6
|
"main": "build/index.js",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"build/**/*",
|
|
10
|
+
"tsconfig.json",
|
|
11
|
+
"yarn.lock"
|
|
12
|
+
],
|
|
7
13
|
"devDependencies": {
|
|
8
14
|
"@types/node": "^18.16.0",
|
|
9
15
|
"ts-node": "^10.9.1",
|
|
@@ -14,5 +20,5 @@
|
|
|
14
20
|
"build": "tsc -v; rm -rf build && tsc -b tsconfig.json"
|
|
15
21
|
},
|
|
16
22
|
"author": "Duong Van Ba",
|
|
17
|
-
"license": "ISC"
|
|
23
|
+
"license": "ISC"
|
|
18
24
|
}
|
package/.vscode/settings.json
DELETED
package/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { BuiltinTransporter } from './src/BuiltinTransporter'
|
|
2
|
-
export { SpiderMesh } from './src/SpiderMesh'
|
|
3
|
-
export { SpiderMeshNode, SpiderMeshNodeMetadata } from './src/SpiderMeshNode'
|
|
4
|
-
export { SpiderMeshTransporter } from './src/SpiderMeshTransporter'
|
|
5
|
-
export { RemoteService } from './src/RemoteService'
|
|
6
|
-
export { RPCOptions, RPCOptionsList } from './src/RPCOptions'
|
|
7
|
-
export { SpiderMeshMicroservice } from './src/SpiderMeshMicroservice'
|
|
8
|
-
export { SpiderMeshNestJSProvider } from './src/SpiderMeshNestJSProvider'
|