1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | 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;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
12 | return new (P || (P = Promise))(function (resolve, reject) {
|
13 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
16 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17 | });
|
18 | };
|
19 | Object.defineProperty(exports, "__esModule", { value: true });
|
20 | const _ = require("lodash");
|
21 | const Storage_1 = require("../libs/storage/Storage");
|
22 | const Log_1 = require("../libs/logging/Log");
|
23 | const typedi_1 = require("typedi");
|
24 | const System_1 = require("../libs/system/System");
|
25 | class StorageCommand {
|
26 | constructor() {
|
27 | this.command = 'storage';
|
28 | this.aliases = 'st';
|
29 | this.describe = 'Storages';
|
30 | }
|
31 | beforeStartup() {
|
32 | System_1.System.enableDistribution(false);
|
33 | }
|
34 | builder(yargs) {
|
35 | return yargs;
|
36 | }
|
37 | handler(argv) {
|
38 | return __awaiter(this, void 0, void 0, function* () {
|
39 | let parts = _.clone(argv._);
|
40 | if (!parts) {
|
41 | parts = [];
|
42 | }
|
43 | let subcommand = parts.shift();
|
44 | subcommand = parts.shift();
|
45 | if (!subcommand) {
|
46 | Log_1.Log.info('No storage command to execute.');
|
47 | return;
|
48 | }
|
49 | if (!this[subcommand]) {
|
50 | return Log_1.Log.info('No subcommand method to execute found for ' + subcommand + '.');
|
51 | }
|
52 | const storageName = parts.shift();
|
53 | return yield this[subcommand](storageName, parts, argv);
|
54 | });
|
55 | }
|
56 | dump(storageName, parts, argv) {
|
57 | return __awaiter(this, void 0, void 0, function* () {
|
58 | if (!storageName) {
|
59 | Log_1.Log.info('No storage for dump defined.');
|
60 | return;
|
61 | }
|
62 | const storageRef = this.storage.get(storageName);
|
63 | if (!storageRef) {
|
64 | Log_1.Log.info('No storage ref for "' + storageName + '" defined.');
|
65 | return;
|
66 | }
|
67 | if (parts.length === 0) {
|
68 | parts = yield storageRef.getSchemaHandler().getCollectionNames();
|
69 | }
|
70 | const c = yield storageRef.connect();
|
71 | const data = yield c.manager.connection.createQueryRunner().getTables(parts);
|
72 | yield c.close();
|
73 | console.log(JSON.stringify(data, null, 2));
|
74 | });
|
75 | }
|
76 | config(storageName, parts, argv) {
|
77 | return __awaiter(this, void 0, void 0, function* () {
|
78 | if (!storageName) {
|
79 | console.log(JSON.stringify(this.storage.getAllOptions(), null, 2));
|
80 | return;
|
81 | }
|
82 | const storageRef = this.storage.get(storageName);
|
83 | if (!storageRef) {
|
84 | Log_1.Log.info('No storage ref for "' + storageName + '" defined.');
|
85 | return;
|
86 | }
|
87 | console.log(JSON.stringify(storageRef.getOptions(), null, 2));
|
88 | });
|
89 | }
|
90 | }
|
91 | __decorate([
|
92 | typedi_1.Inject(Storage_1.Storage.NAME),
|
93 | __metadata("design:type", Storage_1.Storage)
|
94 | ], StorageCommand.prototype, "storage", void 0);
|
95 | exports.StorageCommand = StorageCommand;
|
96 |
|
97 |
|