hypha-rpc 0.1.0-post5
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/.eslintrc +4 -0
- package/.prettierignore +3 -0
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/hypha-rpc-websocket.js +4688 -0
- package/dist/hypha-rpc-websocket.js.map +1 -0
- package/dist/hypha-rpc-websocket.min.js +2 -0
- package/dist/hypha-rpc-websocket.min.js.map +1 -0
- package/index.d.ts +96 -0
- package/index.js +1 -0
- package/karma.conf.js +114 -0
- package/package.json +65 -0
- package/report.html +39 -0
- package/src/rpc.js +1555 -0
- package/src/utils.js +331 -0
- package/src/webrtc-client.js +201 -0
- package/src/websocket-client.js +558 -0
- package/tests/.eslintrc.js +8 -0
- package/tests/websocket_client_test.js +203 -0
- package/webpack.config.js +44 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
interface MessageEmitter {
|
|
2
|
+
emit: (event: any) => void;
|
|
3
|
+
on(event: string, handler: Function): void;
|
|
4
|
+
once(event: string, handler: Function): void;
|
|
5
|
+
off(event: string, handler?: Function): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface RPC extends MessageEmitter {
|
|
9
|
+
init(): void;
|
|
10
|
+
setConfig(config: any): void;
|
|
11
|
+
getRemoteCallStack(): any;
|
|
12
|
+
getRemote(): any;
|
|
13
|
+
setInterface(_interface: any, config?: any): Promise<void>;
|
|
14
|
+
sendInterface(): void;
|
|
15
|
+
disposeObject(obj: any): Promise<void>;
|
|
16
|
+
requestRemote(): void;
|
|
17
|
+
reset(): void;
|
|
18
|
+
disconnect(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface hRPC extends MessageEmitter {
|
|
22
|
+
register_codec(config: any): void;
|
|
23
|
+
ping(client_id: any, timeout: any): Promise<any>;
|
|
24
|
+
reset(): void;
|
|
25
|
+
disconnect(): Promise<void>;
|
|
26
|
+
get_manager_service(timeout?: any): Promise<void>;
|
|
27
|
+
get_all_local_services(): any;
|
|
28
|
+
get_local_service(service_id: any, context: any): any;
|
|
29
|
+
get_remote_service(service_uri: any, timeout?: any): Promise<any>;
|
|
30
|
+
add_service(api: any, overwrite?: any): any;
|
|
31
|
+
register_service(
|
|
32
|
+
api: any,
|
|
33
|
+
overwrite?: any,
|
|
34
|
+
notify?: any,
|
|
35
|
+
context?: any
|
|
36
|
+
): Promise<any>;
|
|
37
|
+
unregister_service(service: any, notify?: any): Promise<void>;
|
|
38
|
+
get_client_info(): any;
|
|
39
|
+
encode(aObject: any, session_id: any): any;
|
|
40
|
+
decode(aObject: any): Promise<any>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface HyphaServer {
|
|
44
|
+
url: string;
|
|
45
|
+
WebSocketClass: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ServerConfig {
|
|
49
|
+
server?: HyphaServer;
|
|
50
|
+
server_url?: string;
|
|
51
|
+
client_id?: string;
|
|
52
|
+
workspace?: string;
|
|
53
|
+
token?: string;
|
|
54
|
+
method_timeout?: number;
|
|
55
|
+
name?: string;
|
|
56
|
+
WebSocketClass?: any;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface LoginConfig {
|
|
60
|
+
server_url: string;
|
|
61
|
+
login_service_id?: string;
|
|
62
|
+
login_timeout?: string;
|
|
63
|
+
login_callback?: Function;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface API {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare module "hypha-rpc" {
|
|
72
|
+
const hyphaRPCModule: {
|
|
73
|
+
hyphaWebsocketClient: {
|
|
74
|
+
RPC: hRPC;
|
|
75
|
+
API_VERSION: string;
|
|
76
|
+
VERSION: string;
|
|
77
|
+
loadRequirements: (config: any) => Promise<any>;
|
|
78
|
+
login: (config: LoginConfig) => Promise<any>;
|
|
79
|
+
connectToServer: (config: ServerConfig) => Promise<any>;
|
|
80
|
+
registerRTCService: (server: any, service_id: string, config?: any) => Promise<any>;
|
|
81
|
+
getRTCService: (server: any, service_id: string, config?: any) => Promise<any>;
|
|
82
|
+
};
|
|
83
|
+
hyphaSSEClient: {
|
|
84
|
+
RPC: hRPC;
|
|
85
|
+
API_VERSION: string;
|
|
86
|
+
VERSION: string;
|
|
87
|
+
loadRequirements: (config: any) => Promise<any>;
|
|
88
|
+
login: (config: LoginConfig) => Promise<any>;
|
|
89
|
+
connectToServer: (config: ServerConfig) => Promise<any>;
|
|
90
|
+
registerRTCService: (server: any, service_id: string, config?: any) => Promise<any>;
|
|
91
|
+
getRTCService: (server: any, service_id: string, config?: any) => Promise<any>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export = hyphaRPCModule;
|
|
96
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { hyphaWebsocketClient: require("./dist/hypha-rpc-websocket.js"), hyphaSSEClient: require("./dist/hypha-rpc-sse.js") };
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Karma configuration
|
|
2
|
+
// Generated on Sun Mar 08 2020 02:01:17 GMT+0100 (GMT+01:00)
|
|
3
|
+
var webpackConfig = require('./webpack.config.js');
|
|
4
|
+
|
|
5
|
+
module.exports = function (config) {
|
|
6
|
+
config.set({
|
|
7
|
+
|
|
8
|
+
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|
9
|
+
basePath: '',
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// frameworks to use
|
|
13
|
+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|
14
|
+
frameworks: ['mocha'],
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// list of files / patterns to load in the browser
|
|
18
|
+
files: [
|
|
19
|
+
// only specify one entry point
|
|
20
|
+
// and require all tests in there
|
|
21
|
+
'tests/*_test.js',
|
|
22
|
+
{
|
|
23
|
+
pattern: 'src/*.js',
|
|
24
|
+
watched: false,
|
|
25
|
+
included: false,
|
|
26
|
+
served: true,
|
|
27
|
+
nocache: false
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
proxies: {
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// list of files / patterns to exclude
|
|
36
|
+
exclude: [],
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// preprocess matching files before serving them to the browser
|
|
40
|
+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|
41
|
+
preprocessors: {
|
|
42
|
+
// add webpack as preprocessor
|
|
43
|
+
'tests/*_test.js': ['webpack', 'sourcemap'],
|
|
44
|
+
'src/*.js': ['webpack', 'sourcemap' ]
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
webpack: webpackConfig,
|
|
48
|
+
|
|
49
|
+
webpackMiddleware: {
|
|
50
|
+
// webpack-dev-middleware configuration
|
|
51
|
+
// i. e.
|
|
52
|
+
stats: 'errors-only',
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// test results reporter to use
|
|
57
|
+
// possible values: 'dots', 'progress'
|
|
58
|
+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|
59
|
+
reporters: ["spec"],
|
|
60
|
+
specReporter: {
|
|
61
|
+
maxLogLines: 5, // limit number of lines logged per test
|
|
62
|
+
suppressErrorSummary: true, // do not print error summary
|
|
63
|
+
suppressFailed: false, // do not print information about failed tests
|
|
64
|
+
suppressPassed: false, // do not print information about passed tests
|
|
65
|
+
suppressSkipped: true, // do not print information about skipped tests
|
|
66
|
+
showSpecTiming: false // print the time elapsed for each spec
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// web server port
|
|
71
|
+
port: 9876,
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// enable / disable colors in the output (reporters and logs)
|
|
75
|
+
colors: true,
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// level of logging
|
|
79
|
+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|
80
|
+
logLevel: config.LOG_INFO,
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
// enable / disable watching file and executing tests whenever any file changes
|
|
84
|
+
autoWatch: true,
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// start these browsers
|
|
88
|
+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|
89
|
+
browsers: ['ChromeHeadlessNoSandbox', 'FirefoxHeadless', 'ChromeDebugging'],
|
|
90
|
+
|
|
91
|
+
customLaunchers: {
|
|
92
|
+
ChromeHeadlessNoSandbox: {
|
|
93
|
+
base: 'ChromeHeadless',
|
|
94
|
+
flags: ["--no-sandbox"]
|
|
95
|
+
},
|
|
96
|
+
ChromeDebugging: {
|
|
97
|
+
base: 'Chrome',
|
|
98
|
+
flags: [ '--remote-debugging-port=9333' ]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
// Continuous Integration mode
|
|
103
|
+
// if true, Karma captures browsers, runs the tests and exits
|
|
104
|
+
singleRun: false,
|
|
105
|
+
|
|
106
|
+
// Concurrency level
|
|
107
|
+
// how many browser should be started simultaneous
|
|
108
|
+
concurrency: Infinity,
|
|
109
|
+
captureTimeout: 12000,
|
|
110
|
+
browserDisconnectTolerance: 2,
|
|
111
|
+
browserDisconnectTimeout: 40000,
|
|
112
|
+
browserNoActivityTimeout: 40000,
|
|
113
|
+
})
|
|
114
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hypha-rpc",
|
|
3
|
+
"version": "0.1.0-post5",
|
|
4
|
+
"description": "Hypha RPC client for connecting to Hypha server for data management and AI model serving.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rm -rf dist && npm run build-umd",
|
|
9
|
+
"build-umd": "webpack --config webpack.config.js --mode development && NODE_ENV=production webpack --config webpack.config.js --mode production --devtool source-map",
|
|
10
|
+
"watch": "NODE_ENV=production webpack --watch --progress --config webpack.config.js --mode production --devtool source-map",
|
|
11
|
+
"publish-npm": "npm install && npm run build && npm publish",
|
|
12
|
+
"serve": "webpack serve",
|
|
13
|
+
"stats": "webpack --profile --json > stats.json",
|
|
14
|
+
"stats-prod": "webpack --profile --json --mode production > stats-prod.json",
|
|
15
|
+
"clean": "rimraf dist/*",
|
|
16
|
+
"format": "prettier --write \"{src,tests}/**/**\"",
|
|
17
|
+
"check-format": "prettier --check \"{src,tests}/**/**\"",
|
|
18
|
+
"test": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.conf.js",
|
|
19
|
+
"test-watch": "karma start --auto-watch --browsers ChromeDebugging karma.conf.js --debug"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/oeway/hypha-rpc.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"hypha",
|
|
27
|
+
"rpc"
|
|
28
|
+
],
|
|
29
|
+
"author": "Wei Ouyang",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/oeway/hypha-rpc/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/oeway/hypha-rpc",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=19.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@msgpack/msgpack": "^2.7.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@babel/core": "^7.24.9",
|
|
43
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
44
|
+
"@babel/preset-env": "^7.24.8",
|
|
45
|
+
"babel-loader": "^9.1.3",
|
|
46
|
+
"chai": "^5.1.1",
|
|
47
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
48
|
+
"copy-webpack-plugin": "^12.0.2",
|
|
49
|
+
"eslint": "^7.32.0",
|
|
50
|
+
"eslint-config-prettier": "^9.1.0",
|
|
51
|
+
"eslint-loader": "^4.0.2",
|
|
52
|
+
"karma": "^6.4.3",
|
|
53
|
+
"karma-chrome-launcher": "^3.2.0",
|
|
54
|
+
"karma-firefox-launcher": "^2.1.3",
|
|
55
|
+
"karma-mocha": "^2.0.1",
|
|
56
|
+
"karma-sourcemap-loader": "^0.4.0",
|
|
57
|
+
"karma-spec-reporter": "^0.0.36",
|
|
58
|
+
"karma-webpack": "^5.0.1",
|
|
59
|
+
"mocha": "^10.6.0",
|
|
60
|
+
"prettier": "^3.3.3",
|
|
61
|
+
"webpack": "^5.93.0",
|
|
62
|
+
"webpack-cli": "^5.1.4",
|
|
63
|
+
"webpack-dev-server": "^5.0.4"
|
|
64
|
+
}
|
|
65
|
+
}
|