Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolveControllerSpec(constructor: Function): ControllerSpec {
debug(`Retrieving OpenAPI specification for controller ${constructor.name}`);
let spec = MetadataInspector.getClassMetadata(
OAI2Keys.CLASS_KEY,
constructor,
);
if (spec) {
debug(' using class-level spec defined via @api()', spec);
spec = DecoratorFactory.cloneDeep(spec);
} else {
spec = {paths: {}};
}
let endpoints =
MetadataInspector.getAllMethodMetadata(
OAI2Keys.METHODS_KEY,
constructor.prototype,
) || {};
endpoints = DecoratorFactory.cloneDeep(endpoints);
for (const op in endpoints) {
debug(' processing method %s', op);
const endpoint = endpoints[op];
const verb = endpoint.verb!;
const path = endpoint.path!;
let endpointName = '';
/* istanbul ignore if */
if (debug.enabled) {
const className = constructor.name || '';
registerSubscribeMethods(socket: Socket) {
const regexpEventHandlers = new Map<
RegExp[],
(...args: unknown[]) => Promise
>();
const subscribeMethods =
MetadataInspector.getAllMethodMetadata<(string | RegExp)[]>(
'websocket:subscribe',
this.controllerClass.prototype,
) || {};
for (const m in subscribeMethods) {
for (const t of subscribeMethods[m]) {
const regexps: RegExp[] = [];
if (typeof t === 'string') {
socket.on(t, async (...args: unknown[]) => {
await invokeMethod(this.controller, m, this.ctx, args);
});
} else if (t instanceof RegExp) {
regexps.push(t);
}
if (regexps.length) {
// Build a map of regexp based message handlers
regexpEventHandlers.set(regexps, async (...args: unknown[]) => {
async connect(socket: Socket) {
const connectMethods =
MetadataInspector.getAllMethodMetadata(
'websocket:connect',
this.controllerClass.prototype,
) || {};
for (const m in connectMethods) {
await invokeMethod(this.controller, m, this.ctx, [socket]);
}
}