1 | "use strict";
|
2 | var __read = (this && this.__read) || function (o, n) {
|
3 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
4 | if (!m) return o;
|
5 | var i = m.call(o), r, ar = [], e;
|
6 | try {
|
7 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
8 | }
|
9 | catch (error) { e = { error: error }; }
|
10 | finally {
|
11 | try {
|
12 | if (r && !r.done && (m = i["return"])) m.call(i);
|
13 | }
|
14 | finally { if (e) throw e.error; }
|
15 | }
|
16 | return ar;
|
17 | };
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.Amplify = exports.AmplifyClass = void 0;
|
20 |
|
21 |
|
22 | var Logger_1 = require("./Logger");
|
23 | var logger = new Logger_1.ConsoleLogger('Amplify');
|
24 | var AmplifyClass = (function () {
|
25 | function AmplifyClass() {
|
26 |
|
27 | this._components = [];
|
28 | this._config = {};
|
29 |
|
30 | this._modules = {};
|
31 |
|
32 |
|
33 | this.Auth = null;
|
34 | this.Analytics = null;
|
35 | this.API = null;
|
36 | this.Credentials = null;
|
37 | this.Storage = null;
|
38 | this.I18n = null;
|
39 | this.Cache = null;
|
40 | this.PubSub = null;
|
41 | this.Interactions = null;
|
42 | this.Pushnotification = null;
|
43 | this.UI = null;
|
44 | this.XR = null;
|
45 | this.Predictions = null;
|
46 | this.DataStore = null;
|
47 | this.Geo = null;
|
48 | this.Notifications = null;
|
49 | this.Logger = Logger_1.ConsoleLogger;
|
50 | this.ServiceWorker = null;
|
51 | }
|
52 | AmplifyClass.prototype.register = function (comp) {
|
53 | logger.debug('component registered in amplify', comp);
|
54 | this._components.push(comp);
|
55 | if (typeof comp.getModuleName === 'function') {
|
56 | this._modules[comp.getModuleName()] = comp;
|
57 | this[comp.getModuleName()] = comp;
|
58 | }
|
59 | else {
|
60 | logger.debug('no getModuleName method for component', comp);
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | comp.configure(this._config);
|
69 | };
|
70 | AmplifyClass.prototype.configure = function (config) {
|
71 | var _this = this;
|
72 | if (!config)
|
73 | return this._config;
|
74 | this._config = Object.assign(this._config, config);
|
75 | logger.debug('amplify config', this._config);
|
76 |
|
77 |
|
78 |
|
79 | Object.entries(this._modules).forEach(function (_a) {
|
80 | var _b = __read(_a, 2), Name = _b[0], comp = _b[1];
|
81 |
|
82 | Object.keys(comp).forEach(function (property) {
|
83 |
|
84 | if (_this._modules[property]) {
|
85 | comp[property] = _this._modules[property];
|
86 | }
|
87 | });
|
88 | });
|
89 | this._components.map(function (comp) {
|
90 | comp.configure(_this._config);
|
91 | });
|
92 | return this._config;
|
93 | };
|
94 | AmplifyClass.prototype.addPluggable = function (pluggable) {
|
95 | if (pluggable &&
|
96 | pluggable['getCategory'] &&
|
97 | typeof pluggable['getCategory'] === 'function') {
|
98 | this._components.map(function (comp) {
|
99 | if (comp['addPluggable'] &&
|
100 | typeof comp['addPluggable'] === 'function') {
|
101 | comp.addPluggable(pluggable);
|
102 | }
|
103 | });
|
104 | }
|
105 | };
|
106 | return AmplifyClass;
|
107 | }());
|
108 | exports.AmplifyClass = AmplifyClass;
|
109 | exports.Amplify = new AmplifyClass();
|