@devgrid/netron
Version:
Event bus, streams and remote object invocation.
44 lines • 1.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Public = exports.Service = void 0;
const common_1 = require("./common");
const Service = (name) => (target) => {
const metadata = { name, properties: {}, methods: {} };
for (const key of Object.getOwnPropertyNames(target.prototype)) {
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
if (!descriptor)
continue;
const isPublic = Reflect.getMetadata('public', target.prototype, key);
if (!isPublic)
continue;
if (typeof descriptor.value === 'function') {
const paramTypes = Reflect.getMetadata('design:paramtypes', target.prototype, key) || [];
const returnType = Reflect.getMetadata('design:returntype', target.prototype, key)?.name || 'void';
metadata.methods[key] = {
type: returnType,
arguments: paramTypes.map((type) => type?.name || 'unknown'),
};
}
}
for (const key of Object.keys(new target())) {
const isPublic = Reflect.getMetadata('public', target.prototype, key);
if (!isPublic)
continue;
const type = Reflect.getMetadata('design:type', target.prototype, key)?.name || 'unknown';
const isReadonly = Reflect.getMetadata('readonly', target.prototype, key);
metadata.properties[key] = {
type,
readonly: !!isReadonly,
};
}
Reflect.defineMetadata(common_1.SERVICE_ANNOTATION, metadata, target);
};
exports.Service = Service;
const Public = (options) => (target, propertyKey, descriptor) => {
Reflect.defineMetadata('public', true, target, propertyKey);
if (!descriptor) {
Reflect.defineMetadata('readonly', options?.readonly, target, propertyKey);
}
};
exports.Public = Public;
//# sourceMappingURL=decorators.js.map
;