quantum-flow 1.7.0 → 1.8.1
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/README.md +4 -15
- package/dist/app/http/Application.d.ts +1 -0
- package/dist/app/http/Application.js +12 -3
- package/dist/app/http/decorators.js +0 -3
- package/dist/app/http/websocket/WebsocketServer.d.ts +3 -2
- package/dist/app/http/websocket/WebsocketServer.js +39 -27
- package/dist/constants.d.ts +1 -2
- package/dist/constants.js +2 -3
- package/dist/core/Controller.d.ts +12 -0
- package/dist/core/Controller.js +28 -0
- package/dist/core/{utils/extractors.js → decorators.js} +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/types/websocket.d.ts +0 -6
- package/dist/utils/server.js +1 -2
- package/dist/{core/utils/websocket.d.ts → ws/decorators.d.ts} +1 -1
- package/dist/{core/utils/websocket.js → ws/decorators.js} +3 -3
- package/dist/ws/index.d.ts +2 -0
- package/dist/{examples/controllers → ws}/index.js +1 -2
- package/package.json +7 -2
- package/dist/core/utils/index.d.ts +0 -2
- package/dist/core/utils/index.js +0 -18
- package/dist/examples/app.d.ts +0 -4
- package/dist/examples/app.js +0 -99
- package/dist/examples/controllers/index.d.ts +0 -2
- package/dist/examples/controllers/socket.d.ts +0 -8
- package/dist/examples/controllers/socket.js +0 -66
- package/dist/examples/controllers/user.d.ts +0 -15
- package/dist/examples/controllers/user.js +0 -107
- package/dist/examples/controllers/userMetadata.d.ts +0 -7
- package/dist/examples/controllers/userMetadata.js +0 -102
- package/dist/examples/lambda.d.ts +0 -1
- package/dist/examples/lambda.js +0 -6
- package/dist/examples/mock/context.d.ts +0 -14
- package/dist/examples/mock/context.js +0 -17
- package/dist/examples/server.d.ts +0 -1
- package/dist/examples/server.js +0 -6
- /package/dist/core/{utils/extractors.d.ts → decorators.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ You can use controllers and server functionality by importing controllers and cr
|
|
|
21
21
|
- `quantum-flow/aws` - Main application source code AWS Lambda.
|
|
22
22
|
- `quantum-flow/core` - Core framework components like Controller and Endpoint.
|
|
23
23
|
- `quantum-flow/middlewares` - Core middlewares to use within the application.
|
|
24
|
+
- `quantum-flow/ws` - Websocket decorators.
|
|
24
25
|
|
|
25
26
|
---
|
|
26
27
|
|
|
@@ -33,7 +34,6 @@ import {
|
|
|
33
34
|
Body,
|
|
34
35
|
Controller,
|
|
35
36
|
Headers,
|
|
36
|
-
InjectWS,
|
|
37
37
|
IWebSocketService,
|
|
38
38
|
Params,
|
|
39
39
|
PUT,
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
} from 'quantum-flow/core';
|
|
46
46
|
import {IsString} from 'class-validator'
|
|
47
47
|
import { Catch, Cors, Sanitize, Use } from 'quantum-flow/middlewares';
|
|
48
|
+
import { InjectWS } from 'quantum-flow/ws';
|
|
48
49
|
|
|
49
50
|
class UserDto {
|
|
50
51
|
constructor() {}
|
|
@@ -168,17 +169,13 @@ export const handler = LambdaAdapter.createHandler(RootController);
|
|
|
168
169
|
Enable WebSocket in the server configuration and register WebSocket controllers.
|
|
169
170
|
|
|
170
171
|
```typescript
|
|
172
|
+
import { OnConnection, Subscribe, OnMessage } from 'quantum-flow/ws';
|
|
171
173
|
@Controller('socket')
|
|
172
174
|
export class Socket {
|
|
173
175
|
@OnConnection()
|
|
174
176
|
onConnection(event: WebSocketEvent) {
|
|
175
177
|
// Send greeting ONLY to this client
|
|
176
|
-
event.client.socket.send(
|
|
177
|
-
JSON.stringify({
|
|
178
|
-
type: 'welcome',
|
|
179
|
-
data: { message: 'Welcome!' },
|
|
180
|
-
}),
|
|
181
|
-
);
|
|
178
|
+
event.client.socket.send(JSON.stringify({ type: 'welcome', data: { message: 'Welcome!' } }));
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
/**
|
|
@@ -200,14 +197,6 @@ export class Socket {
|
|
|
200
197
|
// That's it, the message will be sent to subscribers automatically!
|
|
201
198
|
}
|
|
202
199
|
|
|
203
|
-
/**
|
|
204
|
-
* 3. @Subscribe for another room
|
|
205
|
-
*/
|
|
206
|
-
@Subscribe('news')
|
|
207
|
-
onNewsMessage(event: WebSocketEvent) {
|
|
208
|
-
// Automatic broadcast to all subscribed to 'news'
|
|
209
|
-
}
|
|
210
|
-
|
|
211
200
|
/**
|
|
212
201
|
* 4. @OnMessage for commands (without WebSocketService)
|
|
213
202
|
*/
|
|
@@ -8,6 +8,7 @@ export declare class HttpServer extends Socket {
|
|
|
8
8
|
constructor(configOrClass: new (...args: any[]) => any);
|
|
9
9
|
private logConfig;
|
|
10
10
|
listen(port?: number, host?: string): Promise<http.Server>;
|
|
11
|
+
private getAllControllers;
|
|
11
12
|
close(): Promise<void>;
|
|
12
13
|
status(): {
|
|
13
14
|
running: boolean;
|
|
@@ -19,9 +19,8 @@ class HttpServer extends Socket_1.Socket {
|
|
|
19
19
|
this.config = (0, _utils_1.resolveConfig)(configOrClass);
|
|
20
20
|
const app = http_1.default.createServer(this.requestHandler.bind(this));
|
|
21
21
|
if (this.config.websocket?.enabled) {
|
|
22
|
-
this.wss = new WebsocketServer_1.WebSocketServer(app, {
|
|
23
|
-
|
|
24
|
-
});
|
|
22
|
+
this.wss = new WebsocketServer_1.WebSocketServer(app, { path: this.config.websocket.path });
|
|
23
|
+
this.wss.registerControllers(this.getAllControllers(this.config.controllers));
|
|
25
24
|
WebsocketService_1.WebSocketService.getInstance().initialize(this.wss);
|
|
26
25
|
}
|
|
27
26
|
this.app = app;
|
|
@@ -73,6 +72,16 @@ class HttpServer extends Socket_1.Socket {
|
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
}
|
|
75
|
+
getAllControllers(controllers = []) {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const ControllerClass of controllers || []) {
|
|
78
|
+
const instance = new ControllerClass();
|
|
79
|
+
result.push(instance);
|
|
80
|
+
const subControllers = Reflect.getMetadata(_constants_1.CONTROLLERS, ControllerClass.prototype) || [];
|
|
81
|
+
result.push(...this.getAllControllers(subControllers));
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
76
85
|
async close() {
|
|
77
86
|
return new Promise((resolve, reject) => {
|
|
78
87
|
if (!this.isRunning) {
|
|
@@ -16,9 +16,6 @@ function Server(config = {}) {
|
|
|
16
16
|
interceptors: existingConfig.interceptor ?? config.interceptor,
|
|
17
17
|
};
|
|
18
18
|
Reflect.defineMetadata(_constants_1.SERVER_CONFIG_KEY, mergedConfig, target);
|
|
19
|
-
if (config.controllers) {
|
|
20
|
-
Reflect.defineMetadata(_constants_1.SERVER_MODULES_KEY, config.controllers, target);
|
|
21
|
-
}
|
|
22
19
|
return target;
|
|
23
20
|
};
|
|
24
21
|
}
|
|
@@ -6,9 +6,10 @@ export declare class WebSocketServer {
|
|
|
6
6
|
private topics;
|
|
7
7
|
private controllers;
|
|
8
8
|
private options;
|
|
9
|
-
constructor(server: http.Server, options?:
|
|
9
|
+
constructor(server: http.Server, options?: {
|
|
10
|
+
path?: string;
|
|
11
|
+
});
|
|
10
12
|
private shouldHandleWebSocket;
|
|
11
|
-
private ensureServer;
|
|
12
13
|
private handleConnection;
|
|
13
14
|
private handleMessage;
|
|
14
15
|
private handleClose;
|
|
@@ -7,18 +7,28 @@ exports.WebSocketServer = void 0;
|
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
8
8
|
const ws_1 = __importDefault(require("ws"));
|
|
9
9
|
class WebSocketServer {
|
|
10
|
-
wss
|
|
10
|
+
wss;
|
|
11
11
|
clients = new Map();
|
|
12
12
|
topics = new Map();
|
|
13
13
|
controllers = [];
|
|
14
14
|
options;
|
|
15
15
|
constructor(server, options) {
|
|
16
16
|
this.options = options;
|
|
17
|
+
this.wss = new ws_1.default.Server({
|
|
18
|
+
noServer: true,
|
|
19
|
+
path: this.options?.path || '/',
|
|
20
|
+
});
|
|
21
|
+
this.wss.on('connection', (socket, request) => {
|
|
22
|
+
this.handleConnection(socket);
|
|
23
|
+
});
|
|
17
24
|
server.on('upgrade', (request, socket, head) => {
|
|
25
|
+
if (socket.__wsHandled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
socket.__wsHandled = true;
|
|
18
29
|
if (this.shouldHandleWebSocket(request.url)) {
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
this.wss?.emit('connection', ws, request);
|
|
30
|
+
this.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
31
|
+
this.wss.emit('connection', ws, request);
|
|
22
32
|
});
|
|
23
33
|
}
|
|
24
34
|
else {
|
|
@@ -30,19 +40,7 @@ class WebSocketServer {
|
|
|
30
40
|
const path = this.options?.path || '/ws';
|
|
31
41
|
return url.startsWith(path);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
if (!this.wss) {
|
|
35
|
-
this.wss = new ws_1.default.Server({
|
|
36
|
-
server,
|
|
37
|
-
path: this.options?.path || '/ws',
|
|
38
|
-
noServer: true,
|
|
39
|
-
});
|
|
40
|
-
this.wss.on('connection', (socket, request) => {
|
|
41
|
-
this.handleConnection(socket, request);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async handleConnection(socket, request) {
|
|
43
|
+
async handleConnection(socket) {
|
|
46
44
|
const clientId = (0, uuid_1.v4)();
|
|
47
45
|
const client = {
|
|
48
46
|
id: clientId,
|
|
@@ -66,8 +64,9 @@ class WebSocketServer {
|
|
|
66
64
|
async handleMessage(client, data) {
|
|
67
65
|
try {
|
|
68
66
|
const message = JSON.parse(data.toString());
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const topic = message.topic ?? message.data?.topic;
|
|
68
|
+
if (message.type === 'subscribe' && topic) {
|
|
69
|
+
this.subscribeToTopic(client, topic);
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
if (message.type === 'unsubscribe' && message.topic) {
|
|
@@ -121,22 +120,27 @@ class WebSocketServer {
|
|
|
121
120
|
}
|
|
122
121
|
async triggerHandlers(eventType, event, topic) {
|
|
123
122
|
for (const controller of this.controllers) {
|
|
124
|
-
const
|
|
125
|
-
const matchingHandlers =
|
|
123
|
+
const controllerHandlers = controller.handlers?.[eventType] ?? [];
|
|
124
|
+
const matchingHandlers = controllerHandlers.filter((h) => {
|
|
125
|
+
if (h.type !== eventType)
|
|
126
|
+
return false;
|
|
127
|
+
if (!topic)
|
|
128
|
+
return !h.topic;
|
|
129
|
+
return !h.topic || h.topic === topic;
|
|
130
|
+
});
|
|
126
131
|
for (const handler of matchingHandlers) {
|
|
127
132
|
try {
|
|
128
|
-
await
|
|
133
|
+
await handler.fn(event);
|
|
129
134
|
}
|
|
130
135
|
catch (error) {
|
|
131
136
|
console.error(`Error in WebSocket handler ${handler.method}:`, error);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
|
-
const subscriptions = Reflect.getMetadata('websocket:topic', controller.constructor) || [];
|
|
135
139
|
if (eventType === 'message' && topic) {
|
|
136
|
-
const matchingSubs =
|
|
140
|
+
const matchingSubs = controller.topics.filter((s) => s.topic === topic);
|
|
137
141
|
for (const sub of matchingSubs) {
|
|
138
142
|
try {
|
|
139
|
-
await
|
|
143
|
+
await sub.fn(event);
|
|
140
144
|
}
|
|
141
145
|
catch (error) {
|
|
142
146
|
console.error(`Error in subscription ${sub.method}:`, error);
|
|
@@ -146,7 +150,12 @@ class WebSocketServer {
|
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
152
|
registerControllers(controllers) {
|
|
149
|
-
this.controllers = controllers
|
|
153
|
+
this.controllers = controllers.map((controller) => {
|
|
154
|
+
if (controller.getWebSocketController) {
|
|
155
|
+
return controller.getWebSocketController();
|
|
156
|
+
}
|
|
157
|
+
return controller;
|
|
158
|
+
});
|
|
150
159
|
}
|
|
151
160
|
subscribeToTopic(client, topic) {
|
|
152
161
|
if (!this.topics.has(topic)) {
|
|
@@ -186,8 +195,11 @@ class WebSocketServer {
|
|
|
186
195
|
timestamp: new Date().toISOString(),
|
|
187
196
|
});
|
|
188
197
|
topicClients.forEach((clientId) => {
|
|
198
|
+
if (exclude && exclude.includes(clientId)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
189
201
|
const client = this.clients.get(clientId);
|
|
190
|
-
if (client
|
|
202
|
+
if (client) {
|
|
191
203
|
client.socket.send(message);
|
|
192
204
|
}
|
|
193
205
|
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -8,9 +8,8 @@ export declare const INTERCEPTOR = "app:interceptors";
|
|
|
8
8
|
export declare const ENDPOINT = "route:endpoints";
|
|
9
9
|
export declare const OK_METADATA_KEY = "custom:ok";
|
|
10
10
|
export declare const SERVER_CONFIG_KEY = "server:config";
|
|
11
|
-
export declare const SERVER_MODULES_KEY = "server:modules";
|
|
12
11
|
export declare const USE_MIDDLEWARE = "controller:usemiddleware";
|
|
13
|
-
export declare const
|
|
12
|
+
export declare const WS_HANDLER = "websocket:handler";
|
|
14
13
|
export declare const WS_TOPIC_KEY = "websocket:topic";
|
|
15
14
|
export declare const WS_SERVICE_KEY = "websocket:service";
|
|
16
15
|
export declare const INTECEPT = "server:intercept";
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CORS_METADATA = exports.INCREMENT_STATISTIC = exports.STATISTIC = exports.TO_VALIDATE = exports.OK_STATUSES = exports.STOPPED = exports.SANITIZE = exports.CATCH = exports.INTECEPT = exports.WS_SERVICE_KEY = exports.WS_TOPIC_KEY = exports.
|
|
3
|
+
exports.CORS_METADATA = exports.INCREMENT_STATISTIC = exports.STATISTIC = exports.TO_VALIDATE = exports.OK_STATUSES = exports.STOPPED = exports.SANITIZE = exports.CATCH = exports.INTECEPT = exports.WS_SERVICE_KEY = exports.WS_TOPIC_KEY = exports.WS_HANDLER = exports.USE_MIDDLEWARE = exports.SERVER_CONFIG_KEY = exports.OK_METADATA_KEY = exports.ENDPOINT = exports.INTERCEPTOR = exports.CONTROLLERS = exports.MIDDLEWARES = exports.ROUTE_MIDDLEWARES = exports.ROUTE_PREFIX = exports.APP_METADATA_KEY = exports.PARAM_METADATA_KEY = void 0;
|
|
4
4
|
exports.PARAM_METADATA_KEY = 'design:parameters';
|
|
5
5
|
exports.APP_METADATA_KEY = 'app:configuration';
|
|
6
6
|
exports.ROUTE_PREFIX = 'route:prefix';
|
|
@@ -11,9 +11,8 @@ exports.INTERCEPTOR = 'app:interceptors';
|
|
|
11
11
|
exports.ENDPOINT = 'route:endpoints';
|
|
12
12
|
exports.OK_METADATA_KEY = 'custom:ok';
|
|
13
13
|
exports.SERVER_CONFIG_KEY = 'server:config';
|
|
14
|
-
exports.SERVER_MODULES_KEY = 'server:modules';
|
|
15
14
|
exports.USE_MIDDLEWARE = 'controller:usemiddleware';
|
|
16
|
-
exports.
|
|
15
|
+
exports.WS_HANDLER = 'websocket:handler';
|
|
17
16
|
exports.WS_TOPIC_KEY = 'websocket:topic';
|
|
18
17
|
exports.WS_SERVICE_KEY = 'websocket:service';
|
|
19
18
|
exports.INTECEPT = 'server:intercept';
|
|
@@ -29,5 +29,17 @@ export declare function Controller(config: string | ControllerConfig, middleware
|
|
|
29
29
|
getControllerMethods: (controller: import("../types/index.js").ControllerInstance) => import("../types/index.js").ControllerMethods;
|
|
30
30
|
handleRequest: (request: AppRequest, response: ServerResponse) => Promise<any>;
|
|
31
31
|
routeWalker(context: RouteContext, request: AppRequest, response: ServerResponse): Promise<any>;
|
|
32
|
+
getWebSocketController(): {
|
|
33
|
+
instance: /*elided*/ any;
|
|
34
|
+
handlers: {
|
|
35
|
+
connection: any;
|
|
36
|
+
message: any;
|
|
37
|
+
close: any;
|
|
38
|
+
error: any;
|
|
39
|
+
};
|
|
40
|
+
topics: any;
|
|
41
|
+
};
|
|
42
|
+
getWSHandlers(type: string): any;
|
|
43
|
+
getWSTopics(): any;
|
|
32
44
|
};
|
|
33
45
|
} & T;
|
package/dist/core/Controller.js
CHANGED
|
@@ -200,6 +200,34 @@ function Controller(config, middlewares = []) {
|
|
|
200
200
|
}
|
|
201
201
|
return null;
|
|
202
202
|
}
|
|
203
|
+
getWebSocketController() {
|
|
204
|
+
return {
|
|
205
|
+
instance: this,
|
|
206
|
+
handlers: {
|
|
207
|
+
connection: this.getWSHandlers('connection'),
|
|
208
|
+
message: this.getWSHandlers('message'),
|
|
209
|
+
close: this.getWSHandlers('close'),
|
|
210
|
+
error: this.getWSHandlers('error'),
|
|
211
|
+
},
|
|
212
|
+
topics: this.getWSTopics(),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
getWSHandlers(type) {
|
|
216
|
+
const handlers = Reflect.getMetadata(_constants_1.WS_HANDLER, this.constructor) || [];
|
|
217
|
+
return handlers
|
|
218
|
+
.filter((h) => h.type === type)
|
|
219
|
+
.map((h) => ({
|
|
220
|
+
...h,
|
|
221
|
+
fn: this[h.method].bind(this),
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
getWSTopics() {
|
|
225
|
+
const topics = Reflect.getMetadata(_constants_1.WS_TOPIC_KEY, this.constructor) || [];
|
|
226
|
+
return topics.map((t) => ({
|
|
227
|
+
...t,
|
|
228
|
+
fn: this[t.method].bind(this),
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
203
231
|
};
|
|
204
232
|
};
|
|
205
233
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Response = exports.Multipart = exports.Cookies = exports.Headers = exports.Request = exports.Query = exports.Params = exports.Body = void 0;
|
|
4
|
-
const _utils_1 = require("
|
|
4
|
+
const _utils_1 = require("../utils/index.js");
|
|
5
5
|
/**
|
|
6
6
|
* Parameter decorator to extract and validate the request body.
|
|
7
7
|
* @param dto Optional DTO class for validation and transformation.
|
package/dist/core/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { AppRequest, CORSConfig, EndpointResponse, ErrorCB, HttpError, IController, InterceptorCB, IWebSocketService, MiddlewareCB, MultipartFile, ResponseWithStatus, WebSocketClient, WebSocketEvent, WebSocketMessage, } from '../types/index.js';
|
|
8
8
|
export * from './Controller';
|
|
9
|
+
export * from './decorators';
|
|
9
10
|
export * from './Endpoint';
|
|
10
|
-
export * from './utils';
|
package/dist/core/index.js
CHANGED
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Controller"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
18
19
|
__exportStar(require("./Endpoint"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
2
|
export type WebSocketHandlerType = 'connection' | 'message' | 'close' | 'error';
|
|
3
|
-
export interface WebSocketMessage {
|
|
4
|
-
type: string;
|
|
5
|
-
topic?: string;
|
|
6
|
-
data: any;
|
|
7
|
-
clientId?: string;
|
|
8
|
-
}
|
|
9
3
|
export interface WebSocketEvent {
|
|
10
4
|
type: WebSocketHandlerType;
|
|
11
5
|
client: WebSocketClient;
|
package/dist/utils/server.js
CHANGED
|
@@ -6,7 +6,6 @@ const resolveConfig = (configOrClass) => {
|
|
|
6
6
|
let config = {};
|
|
7
7
|
if (configOrClass && typeof configOrClass === 'function') {
|
|
8
8
|
const decoratorConfig = Reflect.getMetadata(_constants_1.SERVER_CONFIG_KEY, configOrClass) || {};
|
|
9
|
-
const controllers = Reflect.getMetadata(_constants_1.SERVER_MODULES_KEY, configOrClass) || [];
|
|
10
9
|
const errorHandler = Reflect.getMetadata(_constants_1.CATCH, configOrClass);
|
|
11
10
|
const interceptors = Reflect.getMetadata(_constants_1.INTECEPT, configOrClass);
|
|
12
11
|
const middlewares = Reflect.getMetadata(_constants_1.USE_MIDDLEWARE, configOrClass);
|
|
@@ -19,7 +18,7 @@ const resolveConfig = (configOrClass) => {
|
|
|
19
18
|
interceptors,
|
|
20
19
|
middlewares: decoratorConfig.middlewares.concat(middlewares),
|
|
21
20
|
cors: decoratorConfig.cors,
|
|
22
|
-
controllers:
|
|
21
|
+
controllers: decoratorConfig.controllers || [],
|
|
23
22
|
sanitizers,
|
|
24
23
|
};
|
|
25
24
|
}
|
|
@@ -7,7 +7,7 @@ exports.OnClose = OnClose;
|
|
|
7
7
|
exports.OnError = OnError;
|
|
8
8
|
exports.Subscribe = Subscribe;
|
|
9
9
|
exports.InjectWS = InjectWS;
|
|
10
|
-
const _constants_1 = require("
|
|
10
|
+
const _constants_1 = require("../constants.js");
|
|
11
11
|
/**
|
|
12
12
|
* Method decorator to handle WebSocket events.
|
|
13
13
|
* @param type Type of WebSocket event (connection, message, close, error).
|
|
@@ -15,9 +15,9 @@ const _constants_1 = require("../../constants.js");
|
|
|
15
15
|
*/
|
|
16
16
|
function OnWS(type, topic) {
|
|
17
17
|
return function (target, propertyKey, descriptor) {
|
|
18
|
-
const handlers = Reflect.getMetadata(_constants_1.
|
|
18
|
+
const handlers = Reflect.getMetadata(_constants_1.WS_HANDLER, target.constructor) || [];
|
|
19
19
|
handlers.push({ type, topic, method: propertyKey });
|
|
20
|
-
Reflect.defineMetadata(_constants_1.
|
|
20
|
+
Reflect.defineMetadata(_constants_1.WS_HANDLER, handlers, target.constructor);
|
|
21
21
|
return descriptor;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./user"), exports);
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quantum-flow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Decorator-based API framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "rm -rf dist",
|
|
9
|
-
"build": "yarn clean && tsc && resolve-tspaths",
|
|
9
|
+
"build": "yarn clean && tsc -p tsconfig.build.json && resolve-tspaths",
|
|
10
10
|
"prepublishOnly": "yarn build",
|
|
11
11
|
"dev": "nodemon --config ./nodemon.json",
|
|
12
12
|
"link": "yarn link && cd ./examples && yarn link quantum-flow",
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"import": "./dist/middlewares/index.js",
|
|
36
36
|
"require": "./dist/middlewares/index.js",
|
|
37
37
|
"types": "./dist/middlewares/index.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./ws": {
|
|
40
|
+
"import": "./dist/ws/index.js",
|
|
41
|
+
"require": "./dist/ws/index.js",
|
|
42
|
+
"types": "./dist/ws/index.d.ts"
|
|
38
43
|
}
|
|
39
44
|
},
|
|
40
45
|
"repository": {
|
package/dist/core/utils/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./extractors"), exports);
|
|
18
|
-
__exportStar(require("./websocket"), exports);
|
package/dist/examples/app.d.ts
DELETED
package/dist/examples/app.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.App = exports.Root = void 0;
|
|
43
|
-
const Joi = __importStar(require("joi"));
|
|
44
|
-
const core_1 = require("quantum-flow/core");
|
|
45
|
-
const http_1 = require("quantum-flow/http");
|
|
46
|
-
const middlewares_1 = require("quantum-flow/middlewares");
|
|
47
|
-
const user_1 = require("./controllers/user");
|
|
48
|
-
let Root = class Root {
|
|
49
|
-
};
|
|
50
|
-
exports.Root = Root;
|
|
51
|
-
exports.Root = Root = __decorate([
|
|
52
|
-
(0, core_1.Controller)({
|
|
53
|
-
prefix: 'api',
|
|
54
|
-
controllers: [user_1.User],
|
|
55
|
-
middlewares: [function Global(req, res, next) { }],
|
|
56
|
-
}),
|
|
57
|
-
(0, middlewares_1.Cors)({ origin: '*' }),
|
|
58
|
-
(0, middlewares_1.Use)(function Global1(req, res, next) {
|
|
59
|
-
return next();
|
|
60
|
-
}),
|
|
61
|
-
(0, middlewares_1.Catch)(function GLOBALCATCH(err) {
|
|
62
|
-
return { status: 400 };
|
|
63
|
-
}),
|
|
64
|
-
(0, middlewares_1.Sanitize)({
|
|
65
|
-
schema: Joi.object({
|
|
66
|
-
name: Joi.string().trim().min(2).max(50).required(),
|
|
67
|
-
}),
|
|
68
|
-
action: 'both',
|
|
69
|
-
options: { abortEarly: false },
|
|
70
|
-
stripUnknown: true,
|
|
71
|
-
type: 'body',
|
|
72
|
-
})
|
|
73
|
-
], Root);
|
|
74
|
-
let App = class App {
|
|
75
|
-
};
|
|
76
|
-
exports.App = App;
|
|
77
|
-
exports.App = App = __decorate([
|
|
78
|
-
(0, http_1.Server)({
|
|
79
|
-
controllers: [Root],
|
|
80
|
-
websocket: { enabled: true },
|
|
81
|
-
interceptor: (data) => data,
|
|
82
|
-
errorHandler: (err) => err,
|
|
83
|
-
cors: { origin: '*' },
|
|
84
|
-
middlewares: [() => { }, () => { }],
|
|
85
|
-
}),
|
|
86
|
-
(0, http_1.Port)(3000),
|
|
87
|
-
(0, middlewares_1.Use)(() => { }),
|
|
88
|
-
(0, middlewares_1.Use)([() => { }, () => { }]),
|
|
89
|
-
(0, middlewares_1.Catch)((err) => err),
|
|
90
|
-
(0, middlewares_1.Sanitize)({
|
|
91
|
-
schema: Joi.object({
|
|
92
|
-
name: Joi.string().trim().min(2).max(50).required(),
|
|
93
|
-
}),
|
|
94
|
-
action: 'both',
|
|
95
|
-
options: { abortEarly: false },
|
|
96
|
-
stripUnknown: true,
|
|
97
|
-
type: 'headers',
|
|
98
|
-
})
|
|
99
|
-
], App);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { WebSocketEvent } from 'quantum-flow/core';
|
|
2
|
-
export declare class Socket {
|
|
3
|
-
onConnection(event: WebSocketEvent): void;
|
|
4
|
-
onChatMessage(event: WebSocketEvent): void;
|
|
5
|
-
onNewsMessage(event: WebSocketEvent): void;
|
|
6
|
-
onPing(event: WebSocketEvent): void;
|
|
7
|
-
onSubscribe(event: WebSocketEvent): void;
|
|
8
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Socket = void 0;
|
|
13
|
-
const core_1 = require("quantum-flow/core");
|
|
14
|
-
let Socket = class Socket {
|
|
15
|
-
onConnection(event) {
|
|
16
|
-
event.client.socket.send(JSON.stringify({ type: 'welcome', data: { message: 'welcome' } }));
|
|
17
|
-
}
|
|
18
|
-
onChatMessage(event) {
|
|
19
|
-
const msg = event.message?.data;
|
|
20
|
-
if (msg?.text.includes('bad')) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
onNewsMessage(event) { }
|
|
25
|
-
onPing(event) {
|
|
26
|
-
event.client.socket.send(JSON.stringify({ type: 'pong', data: { time: Date.now() } }));
|
|
27
|
-
}
|
|
28
|
-
onSubscribe(event) {
|
|
29
|
-
const topic = event.message?.data.topic;
|
|
30
|
-
event.client.socket.send(JSON.stringify({ type: 'subscribed', topic, data: { success: true } }));
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.Socket = Socket;
|
|
34
|
-
__decorate([
|
|
35
|
-
(0, core_1.OnConnection)(),
|
|
36
|
-
__metadata("design:type", Function),
|
|
37
|
-
__metadata("design:paramtypes", [Object]),
|
|
38
|
-
__metadata("design:returntype", void 0)
|
|
39
|
-
], Socket.prototype, "onConnection", null);
|
|
40
|
-
__decorate([
|
|
41
|
-
(0, core_1.Subscribe)('chat'),
|
|
42
|
-
__metadata("design:type", Function),
|
|
43
|
-
__metadata("design:paramtypes", [Object]),
|
|
44
|
-
__metadata("design:returntype", void 0)
|
|
45
|
-
], Socket.prototype, "onChatMessage", null);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, core_1.Subscribe)('news'),
|
|
48
|
-
__metadata("design:type", Function),
|
|
49
|
-
__metadata("design:paramtypes", [Object]),
|
|
50
|
-
__metadata("design:returntype", void 0)
|
|
51
|
-
], Socket.prototype, "onNewsMessage", null);
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, core_1.OnMessage)('ping'),
|
|
54
|
-
__metadata("design:type", Function),
|
|
55
|
-
__metadata("design:paramtypes", [Object]),
|
|
56
|
-
__metadata("design:returntype", void 0)
|
|
57
|
-
], Socket.prototype, "onPing", null);
|
|
58
|
-
__decorate([
|
|
59
|
-
(0, core_1.OnMessage)('subscribe'),
|
|
60
|
-
__metadata("design:type", Function),
|
|
61
|
-
__metadata("design:paramtypes", [Object]),
|
|
62
|
-
__metadata("design:returntype", void 0)
|
|
63
|
-
], Socket.prototype, "onSubscribe", null);
|
|
64
|
-
exports.Socket = Socket = __decorate([
|
|
65
|
-
(0, core_1.Controller)('socket')
|
|
66
|
-
], Socket);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IWebSocketService } from 'quantum-flow/core';
|
|
2
|
-
declare class DTO {
|
|
3
|
-
constructor();
|
|
4
|
-
name: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class User {
|
|
7
|
-
createUser(body: DTO, query: any, headers: any, ws: IWebSocketService, req: any, params: any, resp: any): Promise<{
|
|
8
|
-
body: DTO;
|
|
9
|
-
query: any;
|
|
10
|
-
headers: any;
|
|
11
|
-
params: any;
|
|
12
|
-
}>;
|
|
13
|
-
any(resp: any): Promise<string>;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
-
};
|
|
44
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.User = void 0;
|
|
49
|
-
const class_validator_1 = require("class-validator");
|
|
50
|
-
const core_1 = require("quantum-flow/core");
|
|
51
|
-
const middlewares_1 = require("quantum-flow/middlewares");
|
|
52
|
-
const Joi = __importStar(require("joi"));
|
|
53
|
-
const userMetadata_1 = require("./userMetadata");
|
|
54
|
-
const params = Joi.object({
|
|
55
|
-
meta: Joi.string().trim().min(2).max(50).required(),
|
|
56
|
-
});
|
|
57
|
-
class DTO {
|
|
58
|
-
constructor() { }
|
|
59
|
-
name;
|
|
60
|
-
}
|
|
61
|
-
__decorate([
|
|
62
|
-
(0, class_validator_1.IsString)(),
|
|
63
|
-
__metadata("design:type", String)
|
|
64
|
-
], DTO.prototype, "name", void 0);
|
|
65
|
-
let User = class User {
|
|
66
|
-
async createUser(body, query, headers, ws, req, params, resp) {
|
|
67
|
-
return { body, query, headers, params };
|
|
68
|
-
}
|
|
69
|
-
async any(resp) {
|
|
70
|
-
return 'done';
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
exports.User = User;
|
|
74
|
-
__decorate([
|
|
75
|
-
(0, middlewares_1.Status)(201),
|
|
76
|
-
(0, core_1.PUT)(':id'),
|
|
77
|
-
__param(0, (0, core_1.Body)(DTO)),
|
|
78
|
-
__param(1, (0, core_1.Query)()),
|
|
79
|
-
__param(2, (0, core_1.Headers)()),
|
|
80
|
-
__param(3, (0, core_1.InjectWS)()),
|
|
81
|
-
__param(4, (0, core_1.Request)()),
|
|
82
|
-
__param(5, (0, core_1.Params)()),
|
|
83
|
-
__param(6, (0, core_1.Response)()),
|
|
84
|
-
__metadata("design:type", Function),
|
|
85
|
-
__metadata("design:paramtypes", [DTO, Object, Object, Object, Object, Object, Object]),
|
|
86
|
-
__metadata("design:returntype", Promise)
|
|
87
|
-
], User.prototype, "createUser", null);
|
|
88
|
-
__decorate([
|
|
89
|
-
(0, middlewares_1.Status)(300),
|
|
90
|
-
(0, core_1.USE)(),
|
|
91
|
-
__param(0, (0, core_1.Response)()),
|
|
92
|
-
__metadata("design:type", Function),
|
|
93
|
-
__metadata("design:paramtypes", [Object]),
|
|
94
|
-
__metadata("design:returntype", Promise)
|
|
95
|
-
], User.prototype, "any", null);
|
|
96
|
-
exports.User = User = __decorate([
|
|
97
|
-
(0, core_1.Controller)({
|
|
98
|
-
prefix: 'user',
|
|
99
|
-
controllers: [userMetadata_1.UserMetadata],
|
|
100
|
-
middlewares: [function UserGlobalUse() { }],
|
|
101
|
-
interceptor: (data, req, res) => {
|
|
102
|
-
return { data, intercepted: true };
|
|
103
|
-
},
|
|
104
|
-
}),
|
|
105
|
-
(0, middlewares_1.Cors)({ origin: '*' }),
|
|
106
|
-
(0, middlewares_1.Use)(function s1() { })
|
|
107
|
-
], User);
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
-
};
|
|
44
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.UserMetadata = void 0;
|
|
49
|
-
const class_validator_1 = require("class-validator");
|
|
50
|
-
const Joi = __importStar(require("joi"));
|
|
51
|
-
const core_1 = require("quantum-flow/core");
|
|
52
|
-
const middlewares_1 = require("quantum-flow/middlewares");
|
|
53
|
-
class DTO {
|
|
54
|
-
name;
|
|
55
|
-
}
|
|
56
|
-
__decorate([
|
|
57
|
-
(0, class_validator_1.IsString)(),
|
|
58
|
-
__metadata("design:type", String)
|
|
59
|
-
], DTO.prototype, "name", void 0);
|
|
60
|
-
const userSchema = Joi.object({
|
|
61
|
-
name: Joi.string().trim().min(2).max(50).required(),
|
|
62
|
-
});
|
|
63
|
-
let UserMetadata = class UserMetadata {
|
|
64
|
-
async getUserMetadata(params) {
|
|
65
|
-
return params;
|
|
66
|
-
}
|
|
67
|
-
async createMeta(mult, body, params) {
|
|
68
|
-
return { body, params };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
exports.UserMetadata = UserMetadata;
|
|
72
|
-
__decorate([
|
|
73
|
-
(0, core_1.GET)('/:meta'),
|
|
74
|
-
__param(0, (0, core_1.Params)(DTO, 'meta')),
|
|
75
|
-
__metadata("design:type", Function),
|
|
76
|
-
__metadata("design:paramtypes", [Object]),
|
|
77
|
-
__metadata("design:returntype", Promise)
|
|
78
|
-
], UserMetadata.prototype, "getUserMetadata", null);
|
|
79
|
-
__decorate([
|
|
80
|
-
(0, core_1.POST)('/:meta', [function s4() { }]),
|
|
81
|
-
(0, middlewares_1.Sanitize)({
|
|
82
|
-
schema: userSchema,
|
|
83
|
-
action: 'both',
|
|
84
|
-
options: { abortEarly: false },
|
|
85
|
-
stripUnknown: true,
|
|
86
|
-
type: 'body',
|
|
87
|
-
}),
|
|
88
|
-
__param(0, (0, core_1.Multipart)()),
|
|
89
|
-
__param(1, (0, core_1.Body)(DTO)),
|
|
90
|
-
__param(2, (0, core_1.Params)('meta')),
|
|
91
|
-
__metadata("design:type", Function),
|
|
92
|
-
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
93
|
-
__metadata("design:returntype", Promise)
|
|
94
|
-
], UserMetadata.prototype, "createMeta", null);
|
|
95
|
-
exports.UserMetadata = UserMetadata = __decorate([
|
|
96
|
-
(0, core_1.Controller)({
|
|
97
|
-
prefix: 'metadata',
|
|
98
|
-
middlewares: [function s2() { }],
|
|
99
|
-
}),
|
|
100
|
-
(0, middlewares_1.Use)([function s3() { }]),
|
|
101
|
-
(0, middlewares_1.Cors)({ origin: '*' })
|
|
102
|
-
], UserMetadata);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const handler: import("aws-lambda").Handler;
|
package/dist/examples/lambda.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const mockContext: {
|
|
2
|
-
awsRequestId: string;
|
|
3
|
-
functionName: string;
|
|
4
|
-
functionVersion: string;
|
|
5
|
-
invokedFunctionArn: string;
|
|
6
|
-
memoryLimitInMB: string;
|
|
7
|
-
logGroupName: string;
|
|
8
|
-
logStreamName: string;
|
|
9
|
-
getRemainingTimeInMillis: () => number;
|
|
10
|
-
callbackWaitsForEmptyEventLoop: boolean;
|
|
11
|
-
done: () => void;
|
|
12
|
-
fail: () => void;
|
|
13
|
-
succeed: () => void;
|
|
14
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockContext = void 0;
|
|
4
|
-
exports.mockContext = {
|
|
5
|
-
awsRequestId: 'local-req-id-123456',
|
|
6
|
-
functionName: 'localFunction',
|
|
7
|
-
functionVersion: '$LATEST',
|
|
8
|
-
invokedFunctionArn: 'arn:aws:lambda:local:123456789012:function:localFunction',
|
|
9
|
-
memoryLimitInMB: '128',
|
|
10
|
-
logGroupName: '/aws/lambda/localFunction',
|
|
11
|
-
logStreamName: '2023/01/01/[$LATEST]abcdefghijk',
|
|
12
|
-
getRemainingTimeInMillis: () => 30000,
|
|
13
|
-
callbackWaitsForEmptyEventLoop: true,
|
|
14
|
-
done: () => { },
|
|
15
|
-
fail: () => { },
|
|
16
|
-
succeed: () => { },
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/examples/server.js
DELETED
|
File without changes
|