UNPKG

@devgrid/netron

Version:
39 lines 1.75 kB
import { SERVICE_ANNOTATION } from './common'; export 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(SERVICE_ANNOTATION, metadata, target); }; export const Public = (options) => (target, propertyKey, descriptor) => { Reflect.defineMetadata('public', true, target, propertyKey); if (!descriptor) { Reflect.defineMetadata('readonly', options?.readonly, target, propertyKey); } }; //# sourceMappingURL=decorators.js.map