@cripty2001/utils 0.0.58 → 0.0.59
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/dist/Appserver/server.d.ts +22 -0
- package/dist/Appserver/server.js +22 -0
- package/package.json +1 -1
|
@@ -16,6 +16,21 @@ export declare class AppserverAuthError extends AppserverError {
|
|
|
16
16
|
export declare class AppserverHandledError extends AppserverError {
|
|
17
17
|
constructor(code: string, message: string, payload?: AppserverData);
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Lightweight typed RPC runner that exposes POST `/exec/:action` endpoints using msgpack payloads
|
|
21
|
+
* and a GET `/metrics` endpoint for Prometheus gauges.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
* const app = new Appserver(8080, parseToken, collectMetrics);
|
|
25
|
+
* app.register('sum', SumSchema, true, async (input, user) => ({ total: input.a + input.b }));
|
|
26
|
+
*
|
|
27
|
+
* Request requirements:
|
|
28
|
+
* - `Content-Type: application/vnd.msgpack`
|
|
29
|
+
* - Body is msgpack-encoded object matching the provided schema.
|
|
30
|
+
* - Optional `Authorization: Bearer <token>` header is decoded via the provided parseUser function.
|
|
31
|
+
*
|
|
32
|
+
* Responses are msgpack encoded objects with either handler data or `{ error, code, payload }` for handled errors.
|
|
33
|
+
*/
|
|
19
34
|
export declare class Appserver<U extends AppserverData> {
|
|
20
35
|
private app;
|
|
21
36
|
private parseUser;
|
|
@@ -24,5 +39,12 @@ export declare class Appserver<U extends AppserverData> {
|
|
|
24
39
|
constructor(port: number, parseUser: AppserverUsergetter<U>, getMetrics: () => Record<string, number>);
|
|
25
40
|
private handleMetricsRequest;
|
|
26
41
|
private parseInput;
|
|
42
|
+
/**
|
|
43
|
+
* Registers a msgpack RPC endpoint under `/exec/${action}`.
|
|
44
|
+
* @param action unique action name (duplicates throw)
|
|
45
|
+
* @param inputSchema typebox schema used for runtime validation
|
|
46
|
+
* @param auth when true rejects requests without a valid user
|
|
47
|
+
* @param handler business logic returning serializable data
|
|
48
|
+
*/
|
|
27
49
|
register<ISchema extends TSchema, O extends AppserverData, I extends Static<ISchema> & AppserverData = Static<ISchema> & AppserverData>(action: string, inputSchema: ISchema, auth: boolean, handler: AppserverHandler<I, U, O>): void;
|
|
28
50
|
}
|
package/dist/Appserver/server.js
CHANGED
|
@@ -36,6 +36,21 @@ class AppserverHandledError extends AppserverError {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.AppserverHandledError = AppserverHandledError;
|
|
39
|
+
/**
|
|
40
|
+
* Lightweight typed RPC runner that exposes POST `/exec/:action` endpoints using msgpack payloads
|
|
41
|
+
* and a GET `/metrics` endpoint for Prometheus gauges.
|
|
42
|
+
*
|
|
43
|
+
* Usage:
|
|
44
|
+
* const app = new Appserver(8080, parseToken, collectMetrics);
|
|
45
|
+
* app.register('sum', SumSchema, true, async (input, user) => ({ total: input.a + input.b }));
|
|
46
|
+
*
|
|
47
|
+
* Request requirements:
|
|
48
|
+
* - `Content-Type: application/vnd.msgpack`
|
|
49
|
+
* - Body is msgpack-encoded object matching the provided schema.
|
|
50
|
+
* - Optional `Authorization: Bearer <token>` header is decoded via the provided parseUser function.
|
|
51
|
+
*
|
|
52
|
+
* Responses are msgpack encoded objects with either handler data or `{ error, code, payload }` for handled errors.
|
|
53
|
+
*/
|
|
39
54
|
class Appserver {
|
|
40
55
|
app;
|
|
41
56
|
parseUser;
|
|
@@ -96,6 +111,13 @@ class Appserver {
|
|
|
96
111
|
user: token ? await this.parseUser(token) : null
|
|
97
112
|
};
|
|
98
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Registers a msgpack RPC endpoint under `/exec/${action}`.
|
|
116
|
+
* @param action unique action name (duplicates throw)
|
|
117
|
+
* @param inputSchema typebox schema used for runtime validation
|
|
118
|
+
* @param auth when true rejects requests without a valid user
|
|
119
|
+
* @param handler business logic returning serializable data
|
|
120
|
+
*/
|
|
99
121
|
register(action, inputSchema, auth, handler) {
|
|
100
122
|
if (this.registered.has(action))
|
|
101
123
|
throw new Error(`Action ${action} is already registered`);
|
package/package.json
CHANGED