wechaty-puppet
Version:
Abstract Puppet for Wechaty
62 lines • 2.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.postMixin = void 0;
const config_js_1 = require("../config.js");
const dirty_js_1 = require("../schemas/dirty.js");
const postMixin = (baseMixin) => {
class PostMixin extends baseMixin {
constructor(...args) {
super(...args);
config_js_1.log.verbose('PuppetPostMixin', 'constructor()');
}
postPayloadCache(postId) {
// log.silly('PuppetPostMixin', 'postPayloadCache(id=%s) @ %s', postId, this)
if (!postId) {
throw new Error('no id');
}
const cachedPayload = this.cache.post.get(postId);
if (cachedPayload) {
// log.silly('PuppetPostMixin', 'postPayloadCache(%s) cache HIT', postId)
}
else {
config_js_1.log.silly('PuppetPostMixin', 'postPayloadCache(%s) cache MISS', postId);
}
return cachedPayload;
}
async postPayload(postId) {
config_js_1.log.verbose('PuppetPostMixin', 'postPayload(%s)', postId);
if (!postId) {
throw new Error('no id');
}
/**
* 1. Try to get from cache first
*/
const cachedPayload = this.postPayloadCache(postId);
if (cachedPayload) {
return cachedPayload;
}
/**
* 2. Cache not found
*/
const rawPayload = await this.postRawPayload(postId);
const payload = await this.postRawPayloadParser(rawPayload);
this.cache.post.set(postId, payload);
config_js_1.log.silly('PuppetPostMixin', 'postPayload(%s) cache SET', postId);
return payload;
}
/**
* List from the local, will return all ids from cache
*/
postList() {
config_js_1.log.verbose('PuppetPostMixin', 'postList()');
return [...this.cache.post.keys()];
}
async postPayloadDirty(id) {
config_js_1.log.verbose('PuppetPostMixin', 'postPayloadDirty(%s)', id);
await this.__dirtyPayloadAwait(dirty_js_1.DirtyType.Post, id);
}
}
return PostMixin;
};
exports.postMixin = postMixin;
//# sourceMappingURL=post-mixin.js.map
;