schangxiang@126.com
2025-09-18 49a51c068d62084bc4c3e77c4be94a20de556c4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as tslib_1 from "tslib";
import { PlatformTools } from "../../platform/PlatformTools";
/**
 * Reads connection options defined in the xml file.
 */
var ConnectionOptionsXmlReader = /** @class */ (function () {
    function ConnectionOptionsXmlReader() {
    }
    // -------------------------------------------------------------------------
    // Public Methods
    // -------------------------------------------------------------------------
    /**
     * Reads connection options from given xml file.
     */
    ConnectionOptionsXmlReader.prototype.read = function (path) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var xml;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.readXml(path)];
                    case 1:
                        xml = _a.sent();
                        return [2 /*return*/, xml.connection.map(function (connection) {
                                return {
                                    name: connection.$.name,
                                    type: connection.$.type,
                                    url: connection.url ? connection.url[0] : undefined,
                                    host: connection.host ? connection.host[0] : undefined,
                                    port: connection.port && connection.port[0] ? parseInt(connection.port[0]) : undefined,
                                    username: connection.username ? connection.username[0] : undefined,
                                    password: connection.password ? connection.password[0] : undefined,
                                    database: connection.database ? connection.database[0] : undefined,
                                    sid: connection.sid ? connection.sid[0] : undefined,
                                    extra: connection.extra ? connection.extra[0] : undefined,
                                    synchronize: connection.synchronize ? connection.synchronize[0] : undefined,
                                    entities: connection.entities ? connection.entities[0].entity : [],
                                    subscribers: connection.subscribers ? connection.subscribers[0].entity : [],
                                    logging: connection.logging[0] ? connection.logging[0].split(",") : undefined,
                                };
                            })];
                }
            });
        });
    };
    // -------------------------------------------------------------------------
    // Protected Methods
    // -------------------------------------------------------------------------
    /**
     * Reads xml file contents and returns them in a promise.
     */
    ConnectionOptionsXmlReader.prototype.readXml = function (path) {
        var xmlParser = PlatformTools.load("xml2js").parseString;
        var xmlOptions = { trim: true, explicitRoot: false };
        return new Promise(function (ok, fail) {
            xmlParser(PlatformTools.readFileSync(path), xmlOptions, function (err, result) { return err ? fail(err) : ok(result); });
        });
    };
    return ConnectionOptionsXmlReader;
}());
export { ConnectionOptionsXmlReader };
 
//# sourceMappingURL=ConnectionOptionsXmlReader.js.map