UNPKG

@rnaga/wp-node

Version:

👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**

101 lines (100 loc) • 3.86 kB
"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 __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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.postUpdate = exports.postInsert = exports.postUpsert = void 0; const zod_1 = require("zod"); const database = __importStar(require("../database")); const metaValue = zod_1.z.union([ zod_1.z.string(), zod_1.z.number(), zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()])), zod_1.z.record(zod_1.z.string(), zod_1.z.any()), ]); exports.postUpsert = database.wpPosts .merge(zod_1.z.object({ ID: zod_1.z.number().nonnegative().optional(), import_id: zod_1.z.number().nonnegative().optional().default(0), post_status: zod_1.z.string().default("draft"), post_categeory: zod_1.z.array(zod_1.z.number()).optional(), comment_status: zod_1.z.enum(["open", "closed"]).optional().default("open"), ping_status: zod_1.z.enum(["open", "closed"]).default("open"), tags_input: zod_1.z .union([ zod_1.z.array(zod_1.z.number()), zod_1.z.array(zod_1.z.string().trim()), zod_1.z.array(zod_1.z.union([zod_1.z.number(), zod_1.z.string().trim()])), ]) .optional() .default([]), tax_input: zod_1.z .record(zod_1.z.string(), zod_1.z.union([ zod_1.z.array(zod_1.z.string()), // For non-hierarchical taxonomy (names or slugs) zod_1.z.array(zod_1.z.number()), // For hierarchical taxonomy (term IDs) zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()])), //z.string(), // For non-hierarchical taxonomy (comma-separated string of names or slugs) //z.string(), // For hierarchical taxonomy (comma-separated string of IDs) ])) .optional(), meta_input: zod_1.z.record(zod_1.z.string(), metaValue).default({}).optional(), file: zod_1.z.string().optional().default(""), context: zod_1.z.string().optional().default(""), })) .required({ post_author: true, }); exports.postInsert = database.wpPosts.pick({ post_author: true, post_date: true, post_date_gmt: true, post_content: true, post_content_filtered: true, post_title: true, post_excerpt: true, post_status: true, post_type: true, comment_status: true, ping_status: true, post_password: true, post_name: true, to_ping: true, pinged: true, post_modified: true, post_modified_gmt: true, post_parent: true, menu_order: true, post_mime_type: true, guid: true, }); exports.postUpdate = exports.postInsert;