ttc-origin-server 0.7.0 → 0.8.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/package.json +1 -2
- package/src/index.ts +0 -65
- package/src/test.ts +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttc-origin-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A lightweight server for TTC Origins - run RPC services with decorator-based endpoints",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"private": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
|
-
"src",
|
|
12
11
|
"README.md",
|
|
13
12
|
"LICENSE"
|
|
14
13
|
],
|
package/src/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { generateRPCMethodsInfo, ttc, type RPCMethodInfo } from 'ttc-rpc';
|
|
2
|
-
import express from 'express';
|
|
3
|
-
|
|
4
|
-
export { ttc, generateRPCMethodsInfo, type RPCMethodInfo } from 'ttc-rpc';
|
|
5
|
-
|
|
6
|
-
export const runServer = (config: {
|
|
7
|
-
name: string,
|
|
8
|
-
description?: string,
|
|
9
|
-
modules: any[],
|
|
10
|
-
port: number,
|
|
11
|
-
modulesRequiringAuth: any[],
|
|
12
|
-
modifyable?: boolean,
|
|
13
|
-
authCb: (req: any) => Promise<boolean>,
|
|
14
|
-
app?: express.Express
|
|
15
|
-
}) => {
|
|
16
|
-
const { modules, port, app } = config;
|
|
17
|
-
const appInstance = app || express();
|
|
18
|
-
|
|
19
|
-
config.name = config.name.replace(/\s+/g, '_').toLowerCase();
|
|
20
|
-
|
|
21
|
-
// authenticate to the ttc server
|
|
22
|
-
// the server will get the definition and Qualities and url etc
|
|
23
|
-
appInstance.get('/rpc/info', (req, res) => {
|
|
24
|
-
res.json({
|
|
25
|
-
name: config.name,
|
|
26
|
-
description: config.description || '',
|
|
27
|
-
modulesRequiringAuth: config.modulesRequiringAuth.map(module => module.name),
|
|
28
|
-
directory: config.modifyable ? process.cwd() : undefined
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
appInstance.get('/rpc/functions', (req, res) => {
|
|
33
|
-
const queryParams = req.query;
|
|
34
|
-
const assistant = queryParams.assistant as string | undefined;
|
|
35
|
-
console.log(`${assistant} is accessing the RPC definitions..`);
|
|
36
|
-
const info: Record<string, RPCMethodInfo[]> = generateRPCMethodsInfo();
|
|
37
|
-
const finalFunctions: RPCMethodInfo[] = [];
|
|
38
|
-
Object.keys(info).forEach((module: string) => {
|
|
39
|
-
const functions = info[module]?.map((func: RPCMethodInfo) => {
|
|
40
|
-
return {
|
|
41
|
-
...func,
|
|
42
|
-
name: `${config.name}.${module}.${func.name}`
|
|
43
|
-
}
|
|
44
|
-
}) || [];
|
|
45
|
-
finalFunctions.push(...functions);
|
|
46
|
-
});
|
|
47
|
-
console.log(JSON.stringify(finalFunctions, null, 2));
|
|
48
|
-
res.json({
|
|
49
|
-
functions: finalFunctions
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
ttc.init({
|
|
54
|
-
app: appInstance,
|
|
55
|
-
modules: modules,
|
|
56
|
-
generate_client: false,
|
|
57
|
-
authCb: async (req) => {
|
|
58
|
-
// authorization for fetching functions will come through here
|
|
59
|
-
if(config.authCb){
|
|
60
|
-
return await config.authCb(req);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
socketCb: async (socket) => { }
|
|
64
|
-
}).listen(port);
|
|
65
|
-
}
|
package/src/test.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ttc } from "ttc-rpc";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { runServer } from "./index";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class HelloWorldModule {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// @ttc.describe({
|
|
10
|
-
// doc: 'some info',
|
|
11
|
-
// inputSchema: z.object({
|
|
12
|
-
// name: z.string()
|
|
13
|
-
// }),
|
|
14
|
-
// outputSchema: z.string(),
|
|
15
|
-
// validate: true,
|
|
16
|
-
// auth: true
|
|
17
|
-
// })
|
|
18
|
-
hello(name: string): string {
|
|
19
|
-
return `Hello, ${name}!`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
runServer({
|
|
25
|
-
name: 'Test Server',
|
|
26
|
-
port: 3000,
|
|
27
|
-
modules: [HelloWorldModule],
|
|
28
|
-
modulesRequiringAuth: [HelloWorldModule],
|
|
29
|
-
authCb: async (req) => {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
})
|