UNPKG

@rnaga/wp-node

Version:

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

84 lines (83 loc) • 3.42 kB
"use strict"; 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 __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.Schema = void 0; const config_1 = require("../config"); const constants_1 = require("../constants"); const component_1 = require("../decorators/component"); const schema_builder_1 = require("../schema-builder/schema-builder"); let Schema = class Schema { schemaBuilder; config; constructor(schemaBuilder, config) { this.schemaBuilder = schemaBuilder; this.config = config; } usingBlog(id) { this.schemaBuilder.tables.index = id; return this; } // dbDelta / make_db_current_silent / wp_get_db_schema async build(scope = "all") { let tableNames = []; switch (scope) { case "blog": tableNames = constants_1.DEFAULT_DATABASE_TABLES.blog; break; case "global": tableNames = [ ...constants_1.DEFAULT_DATABASE_TABLES.global, ...(this.config.isMultiSite() ? constants_1.DEFAULT_DATABASE_TABLES.ms_global : []), ]; break; case "ms_global": tableNames = constants_1.DEFAULT_DATABASE_TABLES.ms_global; break; case "all": default: tableNames = [ ...constants_1.DEFAULT_DATABASE_TABLES.global, ...constants_1.DEFAULT_DATABASE_TABLES.blog, ...(this.config.isMultiSite() ? constants_1.DEFAULT_DATABASE_TABLES.ms_global : []), ]; break; } for (const tableName of tableNames) { const builderList = await this.schemaBuilder.get(tableName); for (const builder of builderList) { await builder; } } } // Part of wp_uninitialize_site async dropBlog(blogId) { const currentBlogId = this.schemaBuilder.tables.index; if (blogId !== currentBlogId) { this.usingBlog(blogId); } const tableNames = constants_1.DEFAULT_DATABASE_TABLES.blog; for (const tableName of tableNames) { await this.schemaBuilder.drop(tableName); } if (blogId !== currentBlogId) { this.usingBlog(currentBlogId); } } }; exports.Schema = Schema; exports.Schema = Schema = __decorate([ (0, component_1.component)({ scope: constants_1.Scope.Transient }), __metadata("design:paramtypes", [schema_builder_1.SchemaBuilder, config_1.Config]) ], Schema);