@rnaga/wp-node
Version:
👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**
124 lines (123 loc) • 4.88 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Meta = void 0;
const zod_1 = require("zod");
const formatting_1 = require("../common/formatting");
const constants_1 = require("../constants");
const component_1 = require("../decorators/component");
const val = __importStar(require("../validators"));
const query_util_1 = require("./utils/query.util");
let Meta = class Meta {
queryUtil;
table;
id;
_props;
constructor(queryUtil, table, id, _props) {
this.queryUtil = queryUtil;
this.table = table;
this.id = id;
this._props = _props;
this._props = {};
}
set(table, id) {
this.table = table;
this.id = id;
return this;
}
setProps(props) {
this._props = props;
}
async get(key) {
if (!this._props[key]) {
this._props = await this.props();
}
return this._props[key];
}
async post() {
return ((await this.queryUtil.posts((query) => {
query.withMeta("inner").where("ID", this.id);
}, zod_1.z.array(val.database.wpPostMeta))) ?? []);
}
async comment() {
return ((await this.queryUtil.comments((query) => {
query.withMeta("inner").where("ID", this.id);
}, zod_1.z.array(val.database.wpCommentMeta))) ?? []);
}
async site() {
return ((await this.queryUtil.sites((query) => {
query.withMeta("inner").where("id", this.id);
}, zod_1.z.array(val.database.wpSiteMeta))) ?? []);
}
async blog() {
return ((await this.queryUtil.blogs((query) => {
query.withMeta("inner").where("blog_id", this.id);
}, zod_1.z.array(val.database.wpBlogMeta))) ?? []);
}
async term() {
return ((await this.queryUtil.terms((query) => {
query.withMeta("inner").where("term_id", this.id);
}, zod_1.z.array(val.database.wpTermMeta))) ?? []);
}
async user() {
return ((await this.queryUtil.users((query) => {
query.withMeta("inner").where("ID", this.id);
}, zod_1.z.array(val.database.wpUserMeta))) ?? []);
}
async props() {
const result = await this[this.table]();
result.forEach((meta) => {
if (typeof meta.meta_key !== "string" || 0 >= meta.meta_key.length) {
return;
}
this._props[meta.meta_key] = formatting_1.formatting.primitive(meta.meta_value);
});
return this._props;
}
};
exports.Meta = Meta;
exports.Meta = Meta = __decorate([
(0, component_1.component)({ scope: constants_1.Scope.Transient }),
__metadata("design:paramtypes", [query_util_1.QueryUtil, String, Number, Object])
], Meta);