Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 510x 510x 472x 472x 510x 472x 472x 472x 364x 364x 510x 510x 510x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 159x 159x 159x 159x 159x 159x 1x 1x 1x 1x 1x 1x 66x 66x 66x 66x 66x 66x 1x 66x 66x 66x 66x 66x 66x 66x 2x 2x 2x 2x 2x 66x 66x 66x 1x 312x 312x 312x 1x 66x 66x 66x 66x 66x 66x 66x 244x 244x 244x 244x 244x 244x 244x 244x 244x 271x 271x 271x 244x 244x 244x 66x 66x 66x 1x 515x 515x 515x 515x 515x 515x 515x 515x 515x 515x 515x 241x 241x 241x 1x 1x 1x 1x 1x 1x 66x 66x 66x 66x 66x 66x | import { getParameterNames } from "./get-param-names";
import { Service } from "./service";
import { IntrospectedEvent, IntrospectedMethod, SimpleIntrospectedType } from "./session";
export const OBJECT_ID = Symbol('OBJECT_ID');
export const REFERENCE_ID = Symbol('REFERENCE_ID');
export type Constructor<T = any> = (new (...args: any[]) => T);
export type AbstractConstructor<T = any> = (abstract new (...args: any[]) => T);
export type AnyConstructor<T = any> = Constructor<T> | AbstractConstructor<T>;
/**
* Get the RPC type assigned to the given target (or property of target).
* @internal
* @param target
* @param propertyKey
* @returns
*/
export function getRpcType(target: any, propertyKey?: string): 'service' | 'remotable' | 'event' | 'call' | undefined {
if (target.prototype instanceof Service)
return 'remotable';
if (!target)
throw new Error(`Cannot get RPC type for undefined/null target`);
try {
return Reflect.getMetadata('rpc:type', target, propertyKey)
?? Reflect.getMetadata('rpc:type', target.constructor.prototype, propertyKey)
?? 'none'
;
} catch (e) {
debugger;
throw e;
}
}
/**
* @internal
* @param target
* @returns
*/
export function getRpcUrl(target: any): string {
if (typeof Reflect === 'undefined')
return undefined;
return String(Reflect.getMetadata('rpc:url', target));
}
/**
* @internal
* @param target
* @returns
*/
export function getRpcServiceName(target: any): string {
if (typeof Reflect === 'undefined')
return undefined;
return String(Reflect.getMetadata('rpc:name', target));
}
/**
* @internal
* @param target
* @returns
*/
export function getRpcDiscoverable(target: any): boolean {
if (typeof Reflect === 'undefined')
return undefined;
return Boolean(Reflect.getMetadata('rpc:discoverable', target) ?? true);
}
export function getRpcEvents(target: any): IntrospectedEvent[] {
if (typeof Reflect === 'undefined')
return undefined;
let events: IntrospectedEvent[] = [];
for (let name of Reflect.getMetadata('rpc:events', target) ?? []) {
events.push({
name,
description: getRpcDescription(target.prototype, name)
})
}
return events;
}
export function getRpcDescription(target: any, propertyKey?: string) {
return Reflect.getMetadata('rpc:description', target, propertyKey);
}
export function getRpcMethods(target: any): IntrospectedMethod[] {
if (typeof Reflect === 'undefined')
return undefined;
let methods: IntrospectedMethod[] = [];
for (let name of Reflect.getMetadata('rpc:methods', target) ?? []) {
let paramTypes = Reflect.getMetadata('design:paramtypes', target.prototype, name);
let paramNames = getParameterNames(target.prototype[name]);
let paramDescriptions = Reflect.getMetadata('rpc:paramDescriptions', target.prototype, name) ?? [];
methods.push({
name,
description: getRpcDescription(target.prototype, name),
simpleReturnType: simplifyType(Reflect.getMetadata('design:returntype', target.prototype, name)),
parameters: paramNames.map((name, i) => ({
name,
simpleType: simplifyType(paramTypes[i]),
description: paramDescriptions[i]
}))
})
}
return methods;
}
function simplifyType(type: Function): SimpleIntrospectedType {
switch (type) {
case undefined: return 'void';
case null: return 'null';
case Number: return 'number';
case String: return 'string';
case Boolean: return 'boolean';
case BigInt: return 'bigint';
case Array: return 'array';
case Object: return 'object';
}
return 'unknown';
}
/**
* @internal
* @param target
* @returns
*/
export function getRpcIntrospectable(target: any): boolean {
if (typeof Reflect === 'undefined')
return undefined;
return Boolean(Reflect.getMetadata('rpc:introspectable', target) ?? true);
} |