UNPKG

@juzi/wechaty

Version:

Wechaty is a RPA SDK for Chatbot Makers.

47 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wechatifyUserModule = exports.wechatifyMixinBase = exports.wechatifyMixin = exports.isWechatified = void 0; const wechaty_puppet_1 = require("@juzi/wechaty-puppet"); const WECHATIFIED_PREFIX = 'Wechatified'; const wechatifyUserModule = (UserClass) => { wechaty_puppet_1.log.verbose('WechatifyMixin', 'wechatifyUserModule(%s)', UserClass.name); return (wechaty) => { wechaty_puppet_1.log.verbose('WechatifyMixin', 'wechatifyUserModule(%s)(%s)', UserClass.name, wechaty); class WechatifiedUserClass extends UserClass { static get wechaty() { return wechaty; } get wechaty() { return wechaty; } } Reflect.defineProperty(WechatifiedUserClass, 'name', { value: WECHATIFIED_PREFIX + UserClass.name, }); return WechatifiedUserClass; }; }; exports.wechatifyUserModule = wechatifyUserModule; const throwWechatifyError = (WechatyUserClass) => { throw new Error([ `${WechatyUserClass.name}: Wechaty User Class (WUC) can not be instantiated directly!`, 'See: https://github.com/wechaty/wechaty/issues/1217', ].join('\n')); }; const isWechatified = (klass) => klass.name.startsWith(WECHATIFIED_PREFIX); exports.isWechatified = isWechatified; const wechatifyMixin = (Base) => { wechaty_puppet_1.log.verbose('WechatifyMixin', 'wechatifyMixin(%s)', Base.name || ''); class AbstractWechatifyMixin extends Base { static get wechaty() { return throwWechatifyError(this); } get wechaty() { return throwWechatifyError(this.constructor); } constructor(...args) { super(...args); if (!isWechatified(this.constructor)) { throwWechatifyError(this.constructor); } } } return AbstractWechatifyMixin; }; exports.wechatifyMixin = wechatifyMixin; const wechatifyMixinBase = () => wechatifyMixin(class EmptyBase { }); exports.wechatifyMixinBase = wechatifyMixinBase; //# sourceMappingURL=wechatify.js.map