@nextgis/ngw-connector 1.19.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/index.d.ts +1100 -1192
- package/lib/ngw-connector.cjs.js +937 -939
- package/lib/ngw-connector.cjs.js.map +1 -1
- package/lib/ngw-connector.cjs.prod.js +1 -1
- package/lib/ngw-connector.cjs.prod.js.map +1 -1
- package/lib/ngw-connector.esm-browser.js +1634 -1709
- package/lib/ngw-connector.esm-browser.js.map +1 -1
- package/lib/ngw-connector.esm-browser.prod.js +1 -1
- package/lib/ngw-connector.esm-browser.prod.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.js +936 -904
- package/lib/ngw-connector.esm-bundler.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js.map +1 -1
- package/lib/ngw-connector.global.js +1845 -2096
- package/lib/ngw-connector.global.js.map +1 -1
- package/lib/ngw-connector.global.prod.js +1 -1
- package/lib/ngw-connector.global.prod.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,2262 +1,2011 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version:
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 2.0.0-alpha.1; author: NextGIS */
|
|
2
2
|
var NgwConnector = (function () {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/******************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
|
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
20
|
-
|
|
21
|
-
var extendStatics = function(d, b) {
|
|
22
|
-
extendStatics = Object.setPrototypeOf ||
|
|
23
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
25
|
-
return extendStatics(d, b);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function __extends(d, b) {
|
|
29
|
-
if (typeof b !== "function" && b !== null)
|
|
30
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
-
extendStatics(d, b);
|
|
32
|
-
function __() { this.constructor = d; }
|
|
33
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var __assign = function() {
|
|
37
|
-
__assign = Object.assign || function __assign(t) {
|
|
38
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
-
s = arguments[i];
|
|
40
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
-
}
|
|
42
|
-
return t;
|
|
43
|
-
};
|
|
44
|
-
return __assign.apply(this, arguments);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
48
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
49
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
50
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
51
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
52
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
53
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function __generator(thisArg, body) {
|
|
58
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
59
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
60
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
61
|
-
function step(op) {
|
|
62
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
63
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
64
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
65
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
66
|
-
switch (op[0]) {
|
|
67
|
-
case 0: case 1: t = op; break;
|
|
68
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
69
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
70
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
71
|
-
default:
|
|
72
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
73
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
74
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
75
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
76
|
-
if (t[2]) _.ops.pop();
|
|
77
|
-
_.trys.pop(); continue;
|
|
78
|
-
}
|
|
79
|
-
op = body.call(thisArg, _);
|
|
80
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
81
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function __spreadArray(to, from, pack) {
|
|
86
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
87
|
-
if (ar || !(i in from)) {
|
|
88
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
89
|
-
ar[i] = from[i];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
96
|
-
var e = new Error(message);
|
|
97
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
var events = {exports: {}};
|
|
101
|
-
|
|
102
|
-
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
103
|
-
var ReflectApply = R && typeof R.apply === 'function'
|
|
104
|
-
? R.apply
|
|
105
|
-
: function ReflectApply(target, receiver, args) {
|
|
106
|
-
return Function.prototype.apply.call(target, receiver, args);
|
|
107
|
-
};
|
|
3
|
+
'use strict';
|
|
108
4
|
|
|
109
|
-
|
|
110
|
-
if (R && typeof R.ownKeys === 'function') {
|
|
111
|
-
ReflectOwnKeys = R.ownKeys;
|
|
112
|
-
} else if (Object.getOwnPropertySymbols) {
|
|
113
|
-
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
114
|
-
return Object.getOwnPropertyNames(target)
|
|
115
|
-
.concat(Object.getOwnPropertySymbols(target));
|
|
116
|
-
};
|
|
117
|
-
} else {
|
|
118
|
-
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
|
119
|
-
return Object.getOwnPropertyNames(target);
|
|
120
|
-
};
|
|
121
|
-
}
|
|
5
|
+
var domain;
|
|
122
6
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
7
|
+
// This constructor is used to store event handlers. Instantiating this is
|
|
8
|
+
// faster than explicitly calling `Object.create(null)` to get a "clean" empty
|
|
9
|
+
// object (tested with v8 v4.9).
|
|
10
|
+
function EventHandlers() {}
|
|
11
|
+
EventHandlers.prototype = Object.create(null);
|
|
126
12
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
13
|
+
function EventEmitter() {
|
|
14
|
+
EventEmitter.init.call(this);
|
|
15
|
+
}
|
|
130
16
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
events.exports = EventEmitter;
|
|
135
|
-
events.exports.once = once;
|
|
17
|
+
// nodejs oddity
|
|
18
|
+
// require('events') === require('events').EventEmitter
|
|
19
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
136
20
|
|
|
137
|
-
|
|
138
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
21
|
+
EventEmitter.usingDomains = false;
|
|
139
22
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
23
|
+
EventEmitter.prototype.domain = undefined;
|
|
24
|
+
EventEmitter.prototype._events = undefined;
|
|
25
|
+
EventEmitter.prototype._maxListeners = undefined;
|
|
143
26
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
27
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
28
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
29
|
+
EventEmitter.defaultMaxListeners = 10;
|
|
147
30
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
31
|
+
EventEmitter.init = function() {
|
|
32
|
+
this.domain = null;
|
|
33
|
+
if (EventEmitter.usingDomains) {
|
|
34
|
+
// if there is an active domain, then attach to it.
|
|
35
|
+
if (domain.active ) ;
|
|
152
36
|
}
|
|
153
37
|
|
|
154
|
-
Object.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return defaultMaxListeners;
|
|
158
|
-
},
|
|
159
|
-
set: function(arg) {
|
|
160
|
-
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
|
161
|
-
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
|
162
|
-
}
|
|
163
|
-
defaultMaxListeners = arg;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
EventEmitter.init = function() {
|
|
168
|
-
|
|
169
|
-
if (this._events === undefined ||
|
|
170
|
-
this._events === Object.getPrototypeOf(this)._events) {
|
|
171
|
-
this._events = Object.create(null);
|
|
172
|
-
this._eventsCount = 0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
this._maxListeners = this._maxListeners || undefined;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Obviously not all Emitters should be limited to 10. This function allows
|
|
179
|
-
// that to be increased. Set to zero for unlimited.
|
|
180
|
-
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
181
|
-
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
|
182
|
-
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
|
183
|
-
}
|
|
184
|
-
this._maxListeners = n;
|
|
185
|
-
return this;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function _getMaxListeners(that) {
|
|
189
|
-
if (that._maxListeners === undefined)
|
|
190
|
-
return EventEmitter.defaultMaxListeners;
|
|
191
|
-
return that._maxListeners;
|
|
38
|
+
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
|
|
39
|
+
this._events = new EventHandlers();
|
|
40
|
+
this._eventsCount = 0;
|
|
192
41
|
}
|
|
193
42
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
43
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Obviously not all Emitters should be limited to 10. This function allows
|
|
47
|
+
// that to be increased. Set to zero for unlimited.
|
|
48
|
+
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
|
49
|
+
if (typeof n !== 'number' || n < 0 || isNaN(n))
|
|
50
|
+
throw new TypeError('"n" argument must be a positive number');
|
|
51
|
+
this._maxListeners = n;
|
|
52
|
+
return this;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function $getMaxListeners(that) {
|
|
56
|
+
if (that._maxListeners === undefined)
|
|
57
|
+
return EventEmitter.defaultMaxListeners;
|
|
58
|
+
return that._maxListeners;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
|
62
|
+
return $getMaxListeners(this);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// These standalone emit* functions are used to optimize calling of event
|
|
66
|
+
// handlers for fast cases because emit() itself often has a variable number of
|
|
67
|
+
// arguments and can be deoptimized because of that. These functions always have
|
|
68
|
+
// the same number of arguments and thus do not get deoptimized, so the code
|
|
69
|
+
// inside them can execute faster.
|
|
70
|
+
function emitNone(handler, isFn, self) {
|
|
71
|
+
if (isFn)
|
|
72
|
+
handler.call(self);
|
|
73
|
+
else {
|
|
74
|
+
var len = handler.length;
|
|
75
|
+
var listeners = arrayClone(handler, len);
|
|
76
|
+
for (var i = 0; i < len; ++i)
|
|
77
|
+
listeners[i].call(self);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function emitOne(handler, isFn, self, arg1) {
|
|
81
|
+
if (isFn)
|
|
82
|
+
handler.call(self, arg1);
|
|
83
|
+
else {
|
|
84
|
+
var len = handler.length;
|
|
85
|
+
var listeners = arrayClone(handler, len);
|
|
86
|
+
for (var i = 0; i < len; ++i)
|
|
87
|
+
listeners[i].call(self, arg1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function emitTwo(handler, isFn, self, arg1, arg2) {
|
|
91
|
+
if (isFn)
|
|
92
|
+
handler.call(self, arg1, arg2);
|
|
93
|
+
else {
|
|
94
|
+
var len = handler.length;
|
|
95
|
+
var listeners = arrayClone(handler, len);
|
|
96
|
+
for (var i = 0; i < len; ++i)
|
|
97
|
+
listeners[i].call(self, arg1, arg2);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function emitThree(handler, isFn, self, arg1, arg2, arg3) {
|
|
101
|
+
if (isFn)
|
|
102
|
+
handler.call(self, arg1, arg2, arg3);
|
|
103
|
+
else {
|
|
104
|
+
var len = handler.length;
|
|
105
|
+
var listeners = arrayClone(handler, len);
|
|
106
|
+
for (var i = 0; i < len; ++i)
|
|
107
|
+
listeners[i].call(self, arg1, arg2, arg3);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function emitMany(handler, isFn, self, args) {
|
|
112
|
+
if (isFn)
|
|
113
|
+
handler.apply(self, args);
|
|
114
|
+
else {
|
|
115
|
+
var len = handler.length;
|
|
116
|
+
var listeners = arrayClone(handler, len);
|
|
117
|
+
for (var i = 0; i < len; ++i)
|
|
118
|
+
listeners[i].apply(self, args);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
EventEmitter.prototype.emit = function emit(type) {
|
|
123
|
+
var er, handler, len, args, i, events, domain;
|
|
124
|
+
var doError = (type === 'error');
|
|
125
|
+
|
|
126
|
+
events = this._events;
|
|
127
|
+
if (events)
|
|
128
|
+
doError = (doError && events.error == null);
|
|
129
|
+
else if (!doError)
|
|
130
|
+
return false;
|
|
131
|
+
|
|
132
|
+
domain = this.domain;
|
|
133
|
+
|
|
134
|
+
// If there is no 'error' event listener then throw.
|
|
135
|
+
if (doError) {
|
|
136
|
+
er = arguments[1];
|
|
137
|
+
if (domain) {
|
|
138
|
+
if (!er)
|
|
139
|
+
er = new Error('Uncaught, unspecified "error" event');
|
|
140
|
+
er.domainEmitter = this;
|
|
141
|
+
er.domain = domain;
|
|
142
|
+
er.domainThrown = false;
|
|
143
|
+
domain.emit('error', er);
|
|
144
|
+
} else if (er instanceof Error) {
|
|
145
|
+
throw er; // Unhandled 'error' event
|
|
146
|
+
} else {
|
|
219
147
|
// At least give some kind of context to the user
|
|
220
|
-
var err = new Error('
|
|
148
|
+
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
|
|
221
149
|
err.context = er;
|
|
222
|
-
throw err;
|
|
150
|
+
throw err;
|
|
223
151
|
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
224
154
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
155
|
+
handler = events[type];
|
|
156
|
+
|
|
157
|
+
if (!handler)
|
|
158
|
+
return false;
|
|
159
|
+
|
|
160
|
+
var isFn = typeof handler === 'function';
|
|
161
|
+
len = arguments.length;
|
|
162
|
+
switch (len) {
|
|
163
|
+
// fast cases
|
|
164
|
+
case 1:
|
|
165
|
+
emitNone(handler, isFn, this);
|
|
166
|
+
break;
|
|
167
|
+
case 2:
|
|
168
|
+
emitOne(handler, isFn, this, arguments[1]);
|
|
169
|
+
break;
|
|
170
|
+
case 3:
|
|
171
|
+
emitTwo(handler, isFn, this, arguments[1], arguments[2]);
|
|
172
|
+
break;
|
|
173
|
+
case 4:
|
|
174
|
+
emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
|
|
175
|
+
break;
|
|
176
|
+
// slower
|
|
177
|
+
default:
|
|
178
|
+
args = new Array(len - 1);
|
|
179
|
+
for (i = 1; i < len; i++)
|
|
180
|
+
args[i - 1] = arguments[i];
|
|
181
|
+
emitMany(handler, isFn, this, args);
|
|
182
|
+
}
|
|
238
183
|
|
|
239
|
-
|
|
240
|
-
|
|
184
|
+
return true;
|
|
185
|
+
};
|
|
241
186
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
187
|
+
function _addListener(target, type, listener, prepend) {
|
|
188
|
+
var m;
|
|
189
|
+
var events;
|
|
190
|
+
var existing;
|
|
246
191
|
|
|
247
|
-
|
|
192
|
+
if (typeof listener !== 'function')
|
|
193
|
+
throw new TypeError('"listener" argument must be a function');
|
|
248
194
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
existing = events[type];
|
|
195
|
+
events = target._events;
|
|
196
|
+
if (!events) {
|
|
197
|
+
events = target._events = new EventHandlers();
|
|
198
|
+
target._eventsCount = 0;
|
|
199
|
+
} else {
|
|
200
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
201
|
+
// adding it to the listeners, first emit "newListener".
|
|
202
|
+
if (events.newListener) {
|
|
203
|
+
target.emit('newListener', type,
|
|
204
|
+
listener.listener ? listener.listener : listener);
|
|
205
|
+
|
|
206
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
207
|
+
// this._events to be assigned to a new object
|
|
208
|
+
events = target._events;
|
|
265
209
|
}
|
|
210
|
+
existing = events[type];
|
|
211
|
+
}
|
|
266
212
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
213
|
+
if (!existing) {
|
|
214
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
215
|
+
existing = events[type] = listener;
|
|
216
|
+
++target._eventsCount;
|
|
217
|
+
} else {
|
|
218
|
+
if (typeof existing === 'function') {
|
|
219
|
+
// Adding the second element, need to change to array.
|
|
220
|
+
existing = events[type] = prepend ? [listener, existing] :
|
|
221
|
+
[existing, listener];
|
|
271
222
|
} else {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
existing = events[type] =
|
|
275
|
-
prepend ? [listener, existing] : [existing, listener];
|
|
276
|
-
// If we've already got an array, just append.
|
|
277
|
-
} else if (prepend) {
|
|
223
|
+
// If we've already got an array, just append.
|
|
224
|
+
if (prepend) {
|
|
278
225
|
existing.unshift(listener);
|
|
279
226
|
} else {
|
|
280
227
|
existing.push(listener);
|
|
281
228
|
}
|
|
229
|
+
}
|
|
282
230
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
231
|
+
// Check for listener leak
|
|
232
|
+
if (!existing.warned) {
|
|
233
|
+
m = $getMaxListeners(target);
|
|
234
|
+
if (m && m > 0 && existing.length > m) {
|
|
286
235
|
existing.warned = true;
|
|
287
|
-
// No error code for this since it is a Warning
|
|
288
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
289
236
|
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
|
290
|
-
existing.length + ' ' +
|
|
291
|
-
'
|
|
292
|
-
'increase limit');
|
|
237
|
+
existing.length + ' ' + type + ' listeners added. ' +
|
|
238
|
+
'Use emitter.setMaxListeners() to increase limit');
|
|
293
239
|
w.name = 'MaxListenersExceededWarning';
|
|
294
240
|
w.emitter = target;
|
|
295
241
|
w.type = type;
|
|
296
242
|
w.count = existing.length;
|
|
297
|
-
|
|
243
|
+
emitWarning(w);
|
|
298
244
|
}
|
|
299
245
|
}
|
|
300
|
-
|
|
301
|
-
return target;
|
|
302
246
|
}
|
|
303
247
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
248
|
+
return target;
|
|
249
|
+
}
|
|
250
|
+
function emitWarning(e) {
|
|
251
|
+
typeof console.warn === 'function' ? console.warn(e) : console.log(e);
|
|
252
|
+
}
|
|
253
|
+
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
|
254
|
+
return _addListener(this, type, listener, false);
|
|
255
|
+
};
|
|
307
256
|
|
|
308
|
-
|
|
257
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
309
258
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
259
|
+
EventEmitter.prototype.prependListener =
|
|
260
|
+
function prependListener(type, listener) {
|
|
261
|
+
return _addListener(this, type, listener, true);
|
|
262
|
+
};
|
|
314
263
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
264
|
+
function _onceWrap(target, type, listener) {
|
|
265
|
+
var fired = false;
|
|
266
|
+
function g() {
|
|
267
|
+
target.removeListener(type, g);
|
|
268
|
+
if (!fired) {
|
|
269
|
+
fired = true;
|
|
270
|
+
listener.apply(target, arguments);
|
|
322
271
|
}
|
|
323
272
|
}
|
|
273
|
+
g.listener = listener;
|
|
274
|
+
return g;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
EventEmitter.prototype.once = function once(type, listener) {
|
|
278
|
+
if (typeof listener !== 'function')
|
|
279
|
+
throw new TypeError('"listener" argument must be a function');
|
|
280
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
281
|
+
return this;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
EventEmitter.prototype.prependOnceListener =
|
|
285
|
+
function prependOnceListener(type, listener) {
|
|
286
|
+
if (typeof listener !== 'function')
|
|
287
|
+
throw new TypeError('"listener" argument must be a function');
|
|
288
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
289
|
+
return this;
|
|
290
|
+
};
|
|
324
291
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
state.wrapFn = wrapped;
|
|
330
|
-
return wrapped;
|
|
331
|
-
}
|
|
292
|
+
// emits a 'removeListener' event iff the listener was removed
|
|
293
|
+
EventEmitter.prototype.removeListener =
|
|
294
|
+
function removeListener(type, listener) {
|
|
295
|
+
var list, events, position, i, originalListener;
|
|
332
296
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this.on(type, _onceWrap(this, type, listener));
|
|
336
|
-
return this;
|
|
337
|
-
};
|
|
297
|
+
if (typeof listener !== 'function')
|
|
298
|
+
throw new TypeError('"listener" argument must be a function');
|
|
338
299
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
checkListener(listener);
|
|
342
|
-
this.prependListener(type, _onceWrap(this, type, listener));
|
|
300
|
+
events = this._events;
|
|
301
|
+
if (!events)
|
|
343
302
|
return this;
|
|
344
|
-
};
|
|
345
303
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var list, events, position, i, originalListener;
|
|
304
|
+
list = events[type];
|
|
305
|
+
if (!list)
|
|
306
|
+
return this;
|
|
350
307
|
|
|
351
|
-
|
|
308
|
+
if (list === listener || (list.listener && list.listener === listener)) {
|
|
309
|
+
if (--this._eventsCount === 0)
|
|
310
|
+
this._events = new EventHandlers();
|
|
311
|
+
else {
|
|
312
|
+
delete events[type];
|
|
313
|
+
if (events.removeListener)
|
|
314
|
+
this.emit('removeListener', type, list.listener || listener);
|
|
315
|
+
}
|
|
316
|
+
} else if (typeof list !== 'function') {
|
|
317
|
+
position = -1;
|
|
352
318
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
319
|
+
for (i = list.length; i-- > 0;) {
|
|
320
|
+
if (list[i] === listener ||
|
|
321
|
+
(list[i].listener && list[i].listener === listener)) {
|
|
322
|
+
originalListener = list[i].listener;
|
|
323
|
+
position = i;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
356
327
|
|
|
357
|
-
|
|
358
|
-
if (list === undefined)
|
|
328
|
+
if (position < 0)
|
|
359
329
|
return this;
|
|
360
330
|
|
|
361
|
-
if (list
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
delete events[type];
|
|
366
|
-
if (events.removeListener)
|
|
367
|
-
this.emit('removeListener', type, list.listener || listener);
|
|
368
|
-
}
|
|
369
|
-
} else if (typeof list !== 'function') {
|
|
370
|
-
position = -1;
|
|
371
|
-
|
|
372
|
-
for (i = list.length - 1; i >= 0; i--) {
|
|
373
|
-
if (list[i] === listener || list[i].listener === listener) {
|
|
374
|
-
originalListener = list[i].listener;
|
|
375
|
-
position = i;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (position < 0)
|
|
331
|
+
if (list.length === 1) {
|
|
332
|
+
list[0] = undefined;
|
|
333
|
+
if (--this._eventsCount === 0) {
|
|
334
|
+
this._events = new EventHandlers();
|
|
381
335
|
return this;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
list.shift();
|
|
385
|
-
else {
|
|
386
|
-
spliceOne(list, position);
|
|
336
|
+
} else {
|
|
337
|
+
delete events[type];
|
|
387
338
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
events[type] = list[0];
|
|
391
|
-
|
|
392
|
-
if (events.removeListener !== undefined)
|
|
393
|
-
this.emit('removeListener', type, originalListener || listener);
|
|
339
|
+
} else {
|
|
340
|
+
spliceOne(list, position);
|
|
394
341
|
}
|
|
395
342
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
400
|
-
|
|
401
|
-
EventEmitter.prototype.removeAllListeners =
|
|
402
|
-
function removeAllListeners(type) {
|
|
403
|
-
var listeners, events, i;
|
|
404
|
-
|
|
405
|
-
events = this._events;
|
|
406
|
-
if (events === undefined)
|
|
407
|
-
return this;
|
|
343
|
+
if (events.removeListener)
|
|
344
|
+
this.emit('removeListener', type, originalListener || listener);
|
|
345
|
+
}
|
|
408
346
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
347
|
+
return this;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Alias for removeListener added in NodeJS 10.0
|
|
351
|
+
// https://nodejs.org/api/events.html#events_emitter_off_eventname_listener
|
|
352
|
+
EventEmitter.prototype.off = function(type, listener){
|
|
353
|
+
return this.removeListener(type, listener);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
EventEmitter.prototype.removeAllListeners =
|
|
357
|
+
function removeAllListeners(type) {
|
|
358
|
+
var listeners, events;
|
|
359
|
+
|
|
360
|
+
events = this._events;
|
|
361
|
+
if (!events)
|
|
362
|
+
return this;
|
|
422
363
|
|
|
423
|
-
|
|
364
|
+
// not listening for removeListener, no need to emit
|
|
365
|
+
if (!events.removeListener) {
|
|
424
366
|
if (arguments.length === 0) {
|
|
425
|
-
|
|
426
|
-
var key;
|
|
427
|
-
for (i = 0; i < keys.length; ++i) {
|
|
428
|
-
key = keys[i];
|
|
429
|
-
if (key === 'removeListener') continue;
|
|
430
|
-
this.removeAllListeners(key);
|
|
431
|
-
}
|
|
432
|
-
this.removeAllListeners('removeListener');
|
|
433
|
-
this._events = Object.create(null);
|
|
367
|
+
this._events = new EventHandlers();
|
|
434
368
|
this._eventsCount = 0;
|
|
435
|
-
|
|
369
|
+
} else if (events[type]) {
|
|
370
|
+
if (--this._eventsCount === 0)
|
|
371
|
+
this._events = new EventHandlers();
|
|
372
|
+
else
|
|
373
|
+
delete events[type];
|
|
436
374
|
}
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
437
377
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
this.removeListener(type, listeners[i]);
|
|
446
|
-
}
|
|
378
|
+
// emit removeListener for all listeners on all events
|
|
379
|
+
if (arguments.length === 0) {
|
|
380
|
+
var keys = Object.keys(events);
|
|
381
|
+
for (var i = 0, key; i < keys.length; ++i) {
|
|
382
|
+
key = keys[i];
|
|
383
|
+
if (key === 'removeListener') continue;
|
|
384
|
+
this.removeAllListeners(key);
|
|
447
385
|
}
|
|
448
|
-
|
|
386
|
+
this.removeAllListeners('removeListener');
|
|
387
|
+
this._events = new EventHandlers();
|
|
388
|
+
this._eventsCount = 0;
|
|
449
389
|
return this;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function _listeners(target, type, unwrap) {
|
|
453
|
-
var events = target._events;
|
|
390
|
+
}
|
|
454
391
|
|
|
455
|
-
|
|
456
|
-
return [];
|
|
392
|
+
listeners = events[type];
|
|
457
393
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
394
|
+
if (typeof listeners === 'function') {
|
|
395
|
+
this.removeListener(type, listeners);
|
|
396
|
+
} else if (listeners) {
|
|
397
|
+
// LIFO order
|
|
398
|
+
do {
|
|
399
|
+
this.removeListener(type, listeners[listeners.length - 1]);
|
|
400
|
+
} while (listeners[0]);
|
|
401
|
+
}
|
|
461
402
|
|
|
462
|
-
|
|
463
|
-
|
|
403
|
+
return this;
|
|
404
|
+
};
|
|
464
405
|
|
|
465
|
-
|
|
466
|
-
|
|
406
|
+
EventEmitter.prototype.listeners = function listeners(type) {
|
|
407
|
+
var evlistener;
|
|
408
|
+
var ret;
|
|
409
|
+
var events = this._events;
|
|
410
|
+
|
|
411
|
+
if (!events)
|
|
412
|
+
ret = [];
|
|
413
|
+
else {
|
|
414
|
+
evlistener = events[type];
|
|
415
|
+
if (!evlistener)
|
|
416
|
+
ret = [];
|
|
417
|
+
else if (typeof evlistener === 'function')
|
|
418
|
+
ret = [evlistener.listener || evlistener];
|
|
419
|
+
else
|
|
420
|
+
ret = unwrapListeners(evlistener);
|
|
467
421
|
}
|
|
468
422
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
|
474
|
-
return _listeners(this, type, false);
|
|
475
|
-
};
|
|
423
|
+
return ret;
|
|
424
|
+
};
|
|
476
425
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
426
|
+
EventEmitter.listenerCount = function(emitter, type) {
|
|
427
|
+
if (typeof emitter.listenerCount === 'function') {
|
|
428
|
+
return emitter.listenerCount(type);
|
|
429
|
+
} else {
|
|
430
|
+
return listenerCount.call(emitter, type);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
484
433
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
434
|
+
EventEmitter.prototype.listenerCount = listenerCount;
|
|
435
|
+
function listenerCount(type) {
|
|
436
|
+
var events = this._events;
|
|
488
437
|
|
|
489
|
-
|
|
490
|
-
|
|
438
|
+
if (events) {
|
|
439
|
+
var evlistener = events[type];
|
|
491
440
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
441
|
+
if (typeof evlistener === 'function') {
|
|
442
|
+
return 1;
|
|
443
|
+
} else if (evlistener) {
|
|
444
|
+
return evlistener.length;
|
|
497
445
|
}
|
|
498
|
-
|
|
499
|
-
return 0;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
503
|
-
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
function arrayClone(arr, n) {
|
|
507
|
-
var copy = new Array(n);
|
|
508
|
-
for (var i = 0; i < n; ++i)
|
|
509
|
-
copy[i] = arr[i];
|
|
510
|
-
return copy;
|
|
511
446
|
}
|
|
512
447
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
448
|
+
return 0;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
452
|
+
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// About 1.5x faster than the two-arg version of Array#splice().
|
|
456
|
+
function spliceOne(list, index) {
|
|
457
|
+
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
|
|
458
|
+
list[i] = list[k];
|
|
459
|
+
list.pop();
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function arrayClone(arr, i) {
|
|
463
|
+
var copy = new Array(i);
|
|
464
|
+
while (i--)
|
|
465
|
+
copy[i] = arr[i];
|
|
466
|
+
return copy;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function unwrapListeners(arr) {
|
|
470
|
+
var ret = new Array(arr.length);
|
|
471
|
+
for (var i = 0; i < ret.length; ++i) {
|
|
472
|
+
ret[i] = arr[i].listener || arr[i];
|
|
517
473
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
474
|
+
return ret;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function defined(val) {
|
|
478
|
+
return val !== void 0 && val !== null;
|
|
479
|
+
}
|
|
480
|
+
function full(val) {
|
|
481
|
+
return typeof val === "string" ? !!val : defined(val);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function isEqual(a, b, o, p) {
|
|
485
|
+
if (a instanceof Array) {
|
|
486
|
+
if (!(b instanceof Array))
|
|
487
|
+
return false;
|
|
488
|
+
return b.sort().join("") === a.sort().join("");
|
|
489
|
+
} else if (a instanceof Date) {
|
|
490
|
+
if (!(b instanceof Date))
|
|
491
|
+
return false;
|
|
492
|
+
return "" + a === "" + b;
|
|
493
|
+
} else if (a instanceof Function) {
|
|
494
|
+
if (!(b instanceof Function))
|
|
495
|
+
return false;
|
|
496
|
+
} else if (a instanceof Object) {
|
|
497
|
+
if (!(b instanceof Object))
|
|
498
|
+
return false;
|
|
499
|
+
if (a === o) {
|
|
500
|
+
return b === p;
|
|
501
|
+
} else {
|
|
502
|
+
return objectDeepEqual(a, b);
|
|
523
503
|
}
|
|
524
|
-
return ret;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
function once(emitter, name) {
|
|
528
|
-
return new Promise(function (resolve, reject) {
|
|
529
|
-
function errorListener(err) {
|
|
530
|
-
emitter.removeListener(name, resolver);
|
|
531
|
-
reject(err);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
function resolver() {
|
|
535
|
-
if (typeof emitter.removeListener === 'function') {
|
|
536
|
-
emitter.removeListener('error', errorListener);
|
|
537
|
-
}
|
|
538
|
-
resolve([].slice.call(arguments));
|
|
539
|
-
}
|
|
540
|
-
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
541
|
-
if (name !== 'error') {
|
|
542
|
-
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
504
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
505
|
+
return a === b;
|
|
506
|
+
}
|
|
507
|
+
function objectDeepEqual(o, p) {
|
|
508
|
+
const keysO = Object.keys(o).sort();
|
|
509
|
+
const keysP = Object.keys(p).sort();
|
|
510
|
+
if (keysO.length !== keysP.length)
|
|
511
|
+
return false;
|
|
512
|
+
if (keysO.join("") !== keysP.join(""))
|
|
513
|
+
return false;
|
|
514
|
+
for (let i = 0; i < keysO.length; i++) {
|
|
515
|
+
const oVal = o[keysO[i]];
|
|
516
|
+
const pVal = p[keysP[i]];
|
|
517
|
+
if (!isEqual(oVal, pVal, o, p)) {
|
|
518
|
+
return false;
|
|
550
519
|
}
|
|
551
520
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
} else if (
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function objectRemoveEmpty(obj) {
|
|
525
|
+
const newObj = {};
|
|
526
|
+
Object.keys(obj).forEach((key) => {
|
|
527
|
+
if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
|
|
528
|
+
newObj[key] = objectRemoveEmpty(obj[key]);
|
|
529
|
+
} else if (obj[key] !== void 0) {
|
|
530
|
+
newObj[key] = obj[key];
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
return newObj;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function fixUrlStr(url) {
|
|
537
|
+
return url.replace(/([^:]\/)\/+/g, "$1");
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
var __defProp$a = Object.defineProperty;
|
|
541
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
542
|
+
var __publicField$a = (obj, key, value) => {
|
|
543
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
544
|
+
return value;
|
|
545
|
+
};
|
|
546
|
+
const _Cache = class _Cache {
|
|
547
|
+
constructor(options = {}) {
|
|
548
|
+
__publicField$a(this, "cache", []);
|
|
549
|
+
var _a;
|
|
550
|
+
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
551
|
+
if (_Cache.instance[namespace]) {
|
|
552
|
+
return _Cache.instance[namespace];
|
|
573
553
|
}
|
|
554
|
+
_Cache.instance[namespace] = this;
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
clean() {
|
|
558
|
+
this.cache.length = 0;
|
|
559
|
+
}
|
|
560
|
+
all() {
|
|
561
|
+
return this.cache;
|
|
574
562
|
}
|
|
575
|
-
|
|
576
563
|
/**
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* @param val - The object.
|
|
580
|
-
* @returns Returns true if the object is defined, returns false otherwise.
|
|
564
|
+
* Caching only a non-empty value.
|
|
581
565
|
*
|
|
566
|
+
* Useful for get or create strategy
|
|
582
567
|
* @example
|
|
583
568
|
* ```javascript
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
569
|
+
* const cache = new Cache();
|
|
570
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
571
|
+
* return data.json(); // undefined
|
|
572
|
+
* });
|
|
573
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
574
|
+
* if (!item) {
|
|
575
|
+
* await createItem(); // 'New item'
|
|
588
576
|
* }
|
|
589
|
-
* ```
|
|
590
|
-
*/
|
|
591
|
-
function defined(val) {
|
|
592
|
-
return val !== undefined && val !== null;
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* from https://github.com/CesiumGS/cesium/blob/master/Source/Core/defined.js
|
|
596
577
|
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
578
|
+
* // somewhere else in the code
|
|
579
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
580
|
+
* console.log(resp); // 'New item'
|
|
581
|
+
* })
|
|
599
582
|
*
|
|
600
|
-
* @example
|
|
601
|
-
* ```javascript
|
|
602
|
-
* full('foo') // true
|
|
603
|
-
* full('') // false
|
|
604
|
-
* full(undefined) // false
|
|
605
|
-
* full(0) // true
|
|
606
583
|
* ```
|
|
607
584
|
*/
|
|
608
|
-
|
|
609
|
-
|
|
585
|
+
addFull(key, valueToSet, props) {
|
|
586
|
+
return this.add(key, valueToSet, props, true);
|
|
610
587
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
else if (a instanceof Date) {
|
|
621
|
-
if (!(b instanceof Date))
|
|
622
|
-
return false;
|
|
623
|
-
return '' + a === '' + b;
|
|
588
|
+
add(key, valueToSet, props, onlyFull) {
|
|
589
|
+
const exist = this._find(key, props);
|
|
590
|
+
if (!exist) {
|
|
591
|
+
let value;
|
|
592
|
+
if (valueToSet instanceof Function) {
|
|
593
|
+
value = valueToSet();
|
|
594
|
+
} else {
|
|
595
|
+
value = valueToSet;
|
|
624
596
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
597
|
+
const props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
598
|
+
const cacheItem = {
|
|
599
|
+
key,
|
|
600
|
+
value,
|
|
601
|
+
props: props_,
|
|
602
|
+
// TODO: remove backward compatibility use only props
|
|
603
|
+
options: props_
|
|
604
|
+
};
|
|
605
|
+
if (onlyFull && !full(value)) {
|
|
606
|
+
return value;
|
|
629
607
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
608
|
+
this.cache.push(cacheItem);
|
|
609
|
+
if (value instanceof Promise) {
|
|
610
|
+
value.catch((er) => {
|
|
611
|
+
this.delete(key, props);
|
|
612
|
+
throw er;
|
|
613
|
+
});
|
|
614
|
+
if (onlyFull) {
|
|
615
|
+
value.then((x) => {
|
|
616
|
+
if (!full(x)) {
|
|
617
|
+
this.delete(key, props);
|
|
618
|
+
}
|
|
619
|
+
return x;
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
return value;
|
|
639
623
|
}
|
|
640
|
-
return
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
624
|
+
return value;
|
|
625
|
+
} else {
|
|
626
|
+
return exist.value;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
match(key, props) {
|
|
630
|
+
const cacheRecord = this._find(key, props);
|
|
631
|
+
if (cacheRecord) {
|
|
632
|
+
return cacheRecord.value;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
matchAll(key, props) {
|
|
636
|
+
if (key) {
|
|
637
|
+
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
638
|
+
}
|
|
639
|
+
return this.cache.map((x) => x.value);
|
|
640
|
+
}
|
|
641
|
+
delete(keyOrItem, props) {
|
|
642
|
+
let exist = [];
|
|
643
|
+
if (typeof keyOrItem === "string") {
|
|
644
|
+
exist = this.cache.filter((x) => this._filter(x, keyOrItem, props));
|
|
645
|
+
} else {
|
|
646
|
+
exist.push(keyOrItem);
|
|
647
|
+
}
|
|
648
|
+
for (const e of exist) {
|
|
649
|
+
const index = this.cache.indexOf(e);
|
|
650
|
+
this.cache.splice(index, 1);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
_find(key, props) {
|
|
654
|
+
return this.cache.find((x) => this._filter(x, key, props));
|
|
655
|
+
}
|
|
656
|
+
_filter(item, key, props) {
|
|
657
|
+
if (item.key === key) {
|
|
658
|
+
if (props) {
|
|
659
|
+
const itemProps = item.props || item.options;
|
|
660
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
656
661
|
}
|
|
657
662
|
return true;
|
|
663
|
+
}
|
|
664
|
+
return false;
|
|
658
665
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
666
|
+
};
|
|
667
|
+
__publicField$a(_Cache, "instance", {});
|
|
668
|
+
let Cache = _Cache;
|
|
669
|
+
|
|
670
|
+
var __defProp$9 = Object.defineProperty;
|
|
671
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
672
|
+
var __publicField$9 = (obj, key, value) => {
|
|
673
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
674
|
+
return value;
|
|
675
|
+
};
|
|
676
|
+
class CancelError extends Error {
|
|
677
|
+
constructor() {
|
|
678
|
+
super();
|
|
679
|
+
__publicField$9(this, "name", "CancelError");
|
|
680
|
+
Object.setPrototypeOf(this, CancelError.prototype);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
var __defProp$8 = Object.defineProperty;
|
|
685
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
686
|
+
var __publicField$8 = (obj, key, value) => {
|
|
687
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
688
|
+
return value;
|
|
689
|
+
};
|
|
690
|
+
class PromiseControl {
|
|
691
|
+
constructor(options = {}) {
|
|
692
|
+
this.options = options;
|
|
693
|
+
__publicField$8(this, "_promises", /* @__PURE__ */ new Map());
|
|
694
|
+
}
|
|
695
|
+
get isLoaded() {
|
|
696
|
+
return this._promises.size > 0;
|
|
697
|
+
}
|
|
698
|
+
remove(promise) {
|
|
699
|
+
if (this._promises.has(promise)) {
|
|
700
|
+
this._promises.delete(promise);
|
|
701
|
+
this._onStop();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
get(promise) {
|
|
705
|
+
return this._promises.get(promise);
|
|
706
|
+
}
|
|
707
|
+
add(promise, name) {
|
|
708
|
+
const key = name ? name : promise;
|
|
709
|
+
const exist = this._promises.get(key);
|
|
710
|
+
if (this.options.onStart && !this.isLoaded) {
|
|
711
|
+
this.options.onStart();
|
|
712
|
+
}
|
|
713
|
+
if (exist) {
|
|
714
|
+
return exist;
|
|
715
|
+
}
|
|
716
|
+
this._promises.set(key, promise);
|
|
717
|
+
promise.finally(() => {
|
|
718
|
+
this.remove(key);
|
|
719
|
+
});
|
|
720
|
+
return promise;
|
|
721
|
+
}
|
|
722
|
+
abort() {
|
|
723
|
+
if (this.isLoaded) {
|
|
724
|
+
this._promises.forEach((x) => {
|
|
725
|
+
if (x.cancel) {
|
|
726
|
+
x.cancel();
|
|
727
|
+
}
|
|
669
728
|
});
|
|
670
|
-
|
|
729
|
+
this._promises.clear();
|
|
730
|
+
this._onStop();
|
|
731
|
+
}
|
|
671
732
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
733
|
+
waitFunc(func, name = "") {
|
|
734
|
+
name = name || func.name;
|
|
735
|
+
const exist = this.get(name);
|
|
736
|
+
if (exist) {
|
|
737
|
+
return exist;
|
|
738
|
+
}
|
|
739
|
+
return this.add(func(), name);
|
|
676
740
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
*
|
|
691
|
-
* @example
|
|
692
|
-
* ```javascript
|
|
693
|
-
* let COUNTER = 0;
|
|
694
|
-
* const createPromise = () => new Promise((res) => {
|
|
695
|
-
* COUNTER++
|
|
696
|
-
* setTimeout(() => res('Ok'), 300)
|
|
697
|
-
* });
|
|
698
|
-
*
|
|
699
|
-
* const cache = new Cache();
|
|
700
|
-
* for (let i = 0; i < 10; i++) {
|
|
701
|
-
* cache.add('foo', createPromise).then((data) => {
|
|
702
|
-
* console.log(data); // 'Ok'
|
|
703
|
-
* });
|
|
704
|
-
* }
|
|
705
|
-
* console.log(COUNTER); // 1
|
|
706
|
-
* ```
|
|
707
|
-
*/
|
|
708
|
-
var Cache$1 = /** @class */ (function () {
|
|
709
|
-
function Cache(options) {
|
|
710
|
-
if (options === void 0) { options = {}; }
|
|
711
|
-
var _a;
|
|
712
|
-
this.cache = [];
|
|
713
|
-
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
714
|
-
if (Cache.instance[namespace]) {
|
|
715
|
-
return Cache.instance[namespace];
|
|
716
|
-
}
|
|
717
|
-
Cache.instance[namespace] = this;
|
|
718
|
-
return this;
|
|
719
|
-
}
|
|
720
|
-
Cache.prototype.clean = function () {
|
|
721
|
-
this.cache.length = 0;
|
|
722
|
-
};
|
|
723
|
-
Cache.prototype.all = function () {
|
|
724
|
-
return this.cache;
|
|
725
|
-
};
|
|
726
|
-
/**
|
|
727
|
-
* Caching only a non-empty value.
|
|
728
|
-
*
|
|
729
|
-
* Useful for get or create strategy
|
|
730
|
-
* @example
|
|
731
|
-
* ```javascript
|
|
732
|
-
* const cache = new Cache();
|
|
733
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
734
|
-
* return data.json(); // undefined
|
|
735
|
-
* });
|
|
736
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
737
|
-
* if (!item) {
|
|
738
|
-
* await createItem(); // 'New item'
|
|
739
|
-
* }
|
|
740
|
-
*
|
|
741
|
-
* // somewhere else in the code
|
|
742
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
743
|
-
* console.log(resp); // 'New item'
|
|
744
|
-
* })
|
|
745
|
-
*
|
|
746
|
-
* ```
|
|
747
|
-
*/
|
|
748
|
-
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
749
|
-
return this.add(key, valueToSet, props, true);
|
|
741
|
+
WaitForMe(name = "") {
|
|
742
|
+
const get = this.get.bind(this);
|
|
743
|
+
const add = this.add.bind(this);
|
|
744
|
+
return function(target, key, descriptor) {
|
|
745
|
+
const originalMethod = descriptor.value;
|
|
746
|
+
name = name || key;
|
|
747
|
+
descriptor.value = function(...args) {
|
|
748
|
+
const exist = get(name);
|
|
749
|
+
if (exist) {
|
|
750
|
+
return exist;
|
|
751
|
+
}
|
|
752
|
+
const result = add(originalMethod.apply(this, args), name);
|
|
753
|
+
return result;
|
|
750
754
|
};
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
755
|
+
return descriptor;
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
759
|
+
GetOrCreateDecorator(name = "") {
|
|
760
|
+
return this.WaitForMe(name);
|
|
761
|
+
}
|
|
762
|
+
_onStop() {
|
|
763
|
+
if (this.options.onStop && !this.isLoaded) {
|
|
764
|
+
this.options.onStop();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
var __defProp$7 = Object.defineProperty;
|
|
770
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
771
|
+
var __publicField$7 = (obj, key, value) => {
|
|
772
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
773
|
+
return value;
|
|
774
|
+
};
|
|
775
|
+
class TimeoutError extends Error {
|
|
776
|
+
constructor() {
|
|
777
|
+
super();
|
|
778
|
+
__publicField$7(this, "name", "TimeoutError");
|
|
779
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
var __defProp$6 = Object.defineProperty;
|
|
784
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
785
|
+
var __publicField$6 = (obj, key, value) => {
|
|
786
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
787
|
+
return value;
|
|
788
|
+
};
|
|
789
|
+
var _a;
|
|
790
|
+
const handleCallback = (resolve, reject, callback, r) => {
|
|
791
|
+
try {
|
|
792
|
+
resolve(callback(r));
|
|
793
|
+
} catch (e) {
|
|
794
|
+
reject(e);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
let ID$1 = 0;
|
|
798
|
+
const _CancelablePromise = class _CancelablePromise {
|
|
799
|
+
constructor(executor, timeout) {
|
|
800
|
+
// @ts-ignore
|
|
801
|
+
__publicField$6(this, _a);
|
|
802
|
+
__publicField$6(this, "id", ID$1++);
|
|
803
|
+
__publicField$6(this, "_isCanceled", false);
|
|
804
|
+
__publicField$6(this, "_isPending", true);
|
|
805
|
+
__publicField$6(this, "_promise");
|
|
806
|
+
__publicField$6(this, "_cancelPromise");
|
|
807
|
+
__publicField$6(this, "_cancelHandlers", []);
|
|
808
|
+
__publicField$6(this, "_setCanceledCallback");
|
|
809
|
+
__publicField$6(this, "_parentPromise");
|
|
810
|
+
__publicField$6(this, "_children", []);
|
|
811
|
+
this._cancelPromise = new Promise((resolve_, reject_) => {
|
|
812
|
+
this._setCanceledCallback = (er) => resolve_(er || new CancelError());
|
|
813
|
+
});
|
|
814
|
+
const promises = [
|
|
815
|
+
this._cancelPromise,
|
|
816
|
+
new Promise((resolve, reject) => {
|
|
817
|
+
const onResolve = (value) => {
|
|
818
|
+
if (value instanceof _CancelablePromise) {
|
|
819
|
+
this.attach(value);
|
|
820
|
+
} else {
|
|
821
|
+
this._isPending = false;
|
|
822
|
+
}
|
|
823
|
+
resolve(value);
|
|
824
|
+
};
|
|
825
|
+
const onReject = (error) => {
|
|
826
|
+
this._isPending = false;
|
|
827
|
+
reject(error);
|
|
828
|
+
};
|
|
829
|
+
const onCancel = (handler) => {
|
|
830
|
+
if (!this._isPending) {
|
|
831
|
+
throw new Error(
|
|
832
|
+
"The `onCancel` handler was attached after the promise settled."
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
this._cancelHandlers.push(handler);
|
|
836
|
+
};
|
|
837
|
+
return executor(onResolve, onReject, onCancel);
|
|
838
|
+
})
|
|
839
|
+
];
|
|
840
|
+
if (timeout) {
|
|
841
|
+
promises.push(
|
|
842
|
+
new Promise((resolve, reject) => {
|
|
843
|
+
setTimeout(() => {
|
|
844
|
+
if (this._isPending) {
|
|
845
|
+
try {
|
|
846
|
+
this.cancel();
|
|
847
|
+
} finally {
|
|
848
|
+
reject(new TimeoutError());
|
|
788
849
|
}
|
|
789
|
-
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
|
|
850
|
+
}
|
|
851
|
+
}, timeout);
|
|
852
|
+
})
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
this._promise = Promise.race(promises);
|
|
856
|
+
}
|
|
857
|
+
static createControl(opt) {
|
|
858
|
+
return new PromiseControl(opt);
|
|
859
|
+
}
|
|
860
|
+
static resolve(value) {
|
|
861
|
+
return new _CancelablePromise((resolve) => resolve(value));
|
|
862
|
+
}
|
|
863
|
+
static reject(value) {
|
|
864
|
+
return new _CancelablePromise((resolve, reject) => reject(value));
|
|
865
|
+
}
|
|
866
|
+
static all(values) {
|
|
867
|
+
return new _CancelablePromise((resolve, reject) => {
|
|
868
|
+
Promise.all(values).then(resolve).catch(reject);
|
|
869
|
+
}).catch((er) => {
|
|
870
|
+
if (er instanceof this.CancelError) {
|
|
871
|
+
for (const v of values) {
|
|
872
|
+
const v_ = v;
|
|
873
|
+
if ("cancel" in v_) {
|
|
874
|
+
v_.cancel();
|
|
793
875
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
throw er;
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
attach(p) {
|
|
882
|
+
if (this._isCanceled) {
|
|
883
|
+
p.cancel();
|
|
884
|
+
} else {
|
|
885
|
+
this._children.push(p);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
then(onfulfilled, onrejected) {
|
|
889
|
+
const p = new _CancelablePromise((resolve, reject) => {
|
|
890
|
+
if (this._promise) {
|
|
891
|
+
const reject_ = (r) => {
|
|
892
|
+
if (onrejected) {
|
|
893
|
+
handleCallback(resolve, reject, onrejected, r);
|
|
894
|
+
} else {
|
|
895
|
+
reject(r);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
this._promise.then((r) => {
|
|
899
|
+
if (this._isCanceled) {
|
|
900
|
+
reject_(r);
|
|
901
|
+
} else {
|
|
902
|
+
if (onfulfilled) {
|
|
903
|
+
handleCallback(resolve, reject, onfulfilled, r);
|
|
904
|
+
} else {
|
|
905
|
+
resolve(r);
|
|
906
|
+
}
|
|
799
907
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
908
|
+
}, reject_);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
p._parentPromise = this;
|
|
912
|
+
this._children.push(p);
|
|
913
|
+
return p;
|
|
914
|
+
}
|
|
915
|
+
catch(onrejected) {
|
|
916
|
+
if (this._isCanceled && onrejected) {
|
|
917
|
+
onrejected(new CancelError());
|
|
918
|
+
}
|
|
919
|
+
return this.then(void 0, onrejected);
|
|
920
|
+
}
|
|
921
|
+
finally(onfinally) {
|
|
922
|
+
if (this._promise) {
|
|
923
|
+
return this._promise.finally(onfinally);
|
|
924
|
+
}
|
|
925
|
+
if (this._isCanceled) {
|
|
926
|
+
return Promise.reject(new CancelError());
|
|
927
|
+
}
|
|
928
|
+
return Promise.reject(onfinally);
|
|
929
|
+
}
|
|
930
|
+
cancel() {
|
|
931
|
+
if (this._isCanceled || !this._isPending) {
|
|
932
|
+
return this;
|
|
933
|
+
}
|
|
934
|
+
this._isCanceled = true;
|
|
935
|
+
const parent = this._getTopParent();
|
|
936
|
+
if (parent) {
|
|
937
|
+
parent.cancel();
|
|
938
|
+
}
|
|
939
|
+
if (this._children) {
|
|
940
|
+
this._children.forEach((x) => x.cancel());
|
|
941
|
+
}
|
|
942
|
+
if (this._isPending) {
|
|
943
|
+
if (this._cancelHandlers.length) {
|
|
944
|
+
try {
|
|
945
|
+
for (const handler of this._cancelHandlers) {
|
|
946
|
+
handler();
|
|
807
947
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
948
|
+
} catch (error) {
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
if (this._setCanceledCallback) {
|
|
952
|
+
this._setCanceledCallback();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
this._destroy();
|
|
956
|
+
return this;
|
|
957
|
+
}
|
|
958
|
+
_getTopParent() {
|
|
959
|
+
let parent = this._parentPromise;
|
|
960
|
+
let hasParent = !!parent;
|
|
961
|
+
while (hasParent) {
|
|
962
|
+
if (parent && parent._parentPromise) {
|
|
963
|
+
parent = parent._parentPromise;
|
|
964
|
+
hasParent = !!parent;
|
|
965
|
+
} else {
|
|
966
|
+
hasParent = false;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return parent;
|
|
970
|
+
}
|
|
971
|
+
_destroy() {
|
|
972
|
+
this._setCanceledCallback = void 0;
|
|
973
|
+
this._cancelPromise = void 0;
|
|
974
|
+
this._promise = void 0;
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
_a = Symbol.toStringTag;
|
|
978
|
+
__publicField$6(_CancelablePromise, "CancelError", CancelError);
|
|
979
|
+
__publicField$6(_CancelablePromise, "TimeoutError", TimeoutError);
|
|
980
|
+
__publicField$6(_CancelablePromise, "PromiseControl", PromiseControl);
|
|
981
|
+
let CancelablePromise = _CancelablePromise;
|
|
982
|
+
Object.setPrototypeOf(CancelablePromise.prototype, Promise.prototype);
|
|
983
|
+
|
|
984
|
+
var __defProp$5 = Object.defineProperty;
|
|
985
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
986
|
+
var __publicField$5 = (obj, key, value) => {
|
|
987
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
988
|
+
return value;
|
|
989
|
+
};
|
|
990
|
+
class NgwError extends Error {
|
|
991
|
+
constructor(er) {
|
|
992
|
+
super();
|
|
993
|
+
__publicField$5(this, "name", "NgwError");
|
|
994
|
+
__publicField$5(this, "title");
|
|
995
|
+
__publicField$5(this, "message");
|
|
996
|
+
__publicField$5(this, "detail");
|
|
997
|
+
__publicField$5(this, "exception");
|
|
998
|
+
__publicField$5(this, "status_code");
|
|
999
|
+
__publicField$5(this, "data");
|
|
1000
|
+
__publicField$5(this, "guru_meditation");
|
|
1001
|
+
Object.assign(this, er);
|
|
1002
|
+
Object.setPrototypeOf(this, NgwError.prototype);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
var __defProp$4 = Object.defineProperty;
|
|
1007
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1008
|
+
var __publicField$4 = (obj, key, value) => {
|
|
1009
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1010
|
+
return value;
|
|
1011
|
+
};
|
|
1012
|
+
class ResourceNotFoundError extends NgwError {
|
|
1013
|
+
constructor(obj) {
|
|
1014
|
+
super(obj);
|
|
1015
|
+
__publicField$4(this, "name", "ResourceNotFoundError");
|
|
1016
|
+
__publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
|
|
1017
|
+
Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function isObject(val) {
|
|
1022
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function resourceCompare(res1, res2) {
|
|
1026
|
+
return objectDeepEqual(res1, res2);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
const exclude = ["description"];
|
|
1030
|
+
function resourceToQuery(resource, prefix = "") {
|
|
1031
|
+
prefix = prefix ? prefix + "__" : "";
|
|
1032
|
+
const query = {};
|
|
1033
|
+
for (const [key, value] of Object.entries(resource)) {
|
|
1034
|
+
if (exclude.indexOf(key) === -1) {
|
|
1035
|
+
if (isObject(value)) {
|
|
1036
|
+
if (key === "owner_user") {
|
|
1037
|
+
const children = resourceToQuery(value, key);
|
|
1038
|
+
Object.assign(query, children);
|
|
1039
|
+
} else if (key === "parent" && "id" in value) {
|
|
1040
|
+
query.parent_id = value.id;
|
|
1041
|
+
}
|
|
1042
|
+
} else if (defined(value)) {
|
|
1043
|
+
query[prefix + key] = value;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return query;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
var __defProp$3 = Object.defineProperty;
|
|
1051
|
+
var __defProps = Object.defineProperties;
|
|
1052
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1053
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1054
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1055
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1056
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1057
|
+
var __spreadValues$1 = (a, b) => {
|
|
1058
|
+
for (var prop in b || (b = {}))
|
|
1059
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1060
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1061
|
+
if (__getOwnPropSymbols$1)
|
|
1062
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1063
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1064
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1065
|
+
}
|
|
1066
|
+
return a;
|
|
1067
|
+
};
|
|
1068
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1069
|
+
var __publicField$3 = (obj, key, value) => {
|
|
1070
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1071
|
+
return value;
|
|
1072
|
+
};
|
|
1073
|
+
var __async = (__this, __arguments, generator) => {
|
|
1074
|
+
return new Promise((resolve, reject) => {
|
|
1075
|
+
var fulfilled = (value) => {
|
|
1076
|
+
try {
|
|
1077
|
+
step(generator.next(value));
|
|
1078
|
+
} catch (e) {
|
|
1079
|
+
reject(e);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
var rejected = (value) => {
|
|
1083
|
+
try {
|
|
1084
|
+
step(generator.throw(value));
|
|
1085
|
+
} catch (e) {
|
|
1086
|
+
reject(e);
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1090
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1091
|
+
});
|
|
1092
|
+
};
|
|
1093
|
+
class ResourcesControl {
|
|
1094
|
+
constructor(connector) {
|
|
1095
|
+
this.connector = connector;
|
|
1096
|
+
__publicField$3(this, "cache", new Cache());
|
|
1097
|
+
}
|
|
1098
|
+
// -------------------------------------------------------------------------
|
|
1099
|
+
// Resource Methods
|
|
1100
|
+
// -------------------------------------------------------------------------
|
|
844
1101
|
/**
|
|
845
|
-
*
|
|
1102
|
+
* Receive resource from NGW by id, keyname or search-object parameter.
|
|
1103
|
+
* @param resource - Resource id, keyname or search-object
|
|
846
1104
|
*
|
|
847
|
-
* @
|
|
848
|
-
*
|
|
1105
|
+
* @remarks
|
|
1106
|
+
* Fetching resource would be cached to speed up next call
|
|
849
1107
|
*/
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1108
|
+
getOne(resource, requestOptions) {
|
|
1109
|
+
const cache = new Cache();
|
|
1110
|
+
const forCache = {};
|
|
1111
|
+
const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
|
|
1112
|
+
if (typeof resource === "string") {
|
|
1113
|
+
forCache.keyname = resource;
|
|
1114
|
+
} else if (typeof resource === "number") {
|
|
1115
|
+
forCache.id = resource;
|
|
1116
|
+
} else if (isObject(resource)) {
|
|
1117
|
+
if (resource.id !== void 0) {
|
|
1118
|
+
forCache.id = resource.id;
|
|
1119
|
+
} else {
|
|
1120
|
+
if (resource.keyname) {
|
|
1121
|
+
forCache.keyname = resource.keyname;
|
|
1122
|
+
}
|
|
1123
|
+
if (resource.display_name) {
|
|
1124
|
+
forCache.display_name = resource.display_name;
|
|
1125
|
+
}
|
|
859
1126
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1127
|
+
}
|
|
1128
|
+
const makeRequest = () => {
|
|
1129
|
+
if (typeof resource === "string") {
|
|
1130
|
+
return this._fetchResourceBy({ keyname: resource }, opt);
|
|
1131
|
+
} else if (typeof resource === "number") {
|
|
1132
|
+
return this._fetchResourceById(resource, opt);
|
|
1133
|
+
} else if (isObject(resource)) {
|
|
1134
|
+
return this._fetchResourceBy(resource, opt);
|
|
1135
|
+
}
|
|
1136
|
+
return CancelablePromise.resolve(void 0);
|
|
1137
|
+
};
|
|
1138
|
+
return cache.addFull("resource", makeRequest, forCache);
|
|
1139
|
+
}
|
|
1140
|
+
getOneOrFail(resource, requestOptions) {
|
|
1141
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
1142
|
+
if (res) {
|
|
1143
|
+
return res;
|
|
868
1144
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1145
|
+
throw new ResourceNotFoundError();
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
1150
|
+
* @param resource - Any available resource definition
|
|
1151
|
+
*
|
|
1152
|
+
* @remarks
|
|
1153
|
+
* There are situations when exactly the resource id is needed
|
|
1154
|
+
* (for example, to compose the correct request to the api)
|
|
1155
|
+
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1156
|
+
* if the resource is specified through a keyname or other parameters.
|
|
1157
|
+
*/
|
|
1158
|
+
getId(resource, requestOptions) {
|
|
1159
|
+
if (typeof resource === "number") {
|
|
1160
|
+
return CancelablePromise.resolve(resource);
|
|
1161
|
+
} else if (typeof resource === "string" || isObject(resource)) {
|
|
1162
|
+
return this.getOne(resource, requestOptions).then((res) => {
|
|
1163
|
+
if (res) {
|
|
1164
|
+
return res.resource.id;
|
|
1165
|
+
}
|
|
875
1166
|
});
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1167
|
+
}
|
|
1168
|
+
return CancelablePromise.resolve(void 0);
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* A fast way to retrieve resource ID for any resource definition.
|
|
1172
|
+
* @param resource - Any available resource definition
|
|
1173
|
+
*
|
|
1174
|
+
* @remarks
|
|
1175
|
+
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1176
|
+
* To not make one more checks if the resource is definitely exists
|
|
1177
|
+
*/
|
|
1178
|
+
getIdOrFail(resource, requestOptions) {
|
|
1179
|
+
return this.getId(resource, requestOptions).then((resp) => {
|
|
1180
|
+
if (resp === void 0) {
|
|
1181
|
+
throw new Error();
|
|
1182
|
+
}
|
|
1183
|
+
return resp;
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
getMany(resource, requestOptions) {
|
|
1187
|
+
return this._resourceCacheFilter(resource).then((items) => {
|
|
1188
|
+
if (!items.length) {
|
|
1189
|
+
const query = {};
|
|
1190
|
+
if (resource.keyname) {
|
|
1191
|
+
query.keyname = resource.keyname;
|
|
1192
|
+
} else {
|
|
1193
|
+
Object.assign(query, resourceToQuery(resource));
|
|
1194
|
+
}
|
|
1195
|
+
return this.connector.get("resource.search", requestOptions, __spreadValues$1({
|
|
1196
|
+
serialization: "full"
|
|
1197
|
+
}, query)).then((resources) => {
|
|
1198
|
+
if (resources) {
|
|
1199
|
+
for (const x of resources) {
|
|
1200
|
+
this.cache.add("resource.item", CancelablePromise.resolve(x), {
|
|
1201
|
+
id: x.resource.id
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
880
1204
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1205
|
+
return resources;
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
return items;
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
getParent(resource, requestOptions) {
|
|
1212
|
+
return this.getOne(resource, requestOptions).then((child) => {
|
|
1213
|
+
if (child) {
|
|
1214
|
+
return this.getOne(child.resource.parent.id, requestOptions);
|
|
1215
|
+
}
|
|
1216
|
+
return CancelablePromise.resolve(void 0);
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
getChildrenOf(resource, requestOptions) {
|
|
1220
|
+
return this.getIdOrFail(resource).then(
|
|
1221
|
+
(parent) => this._getChildrenOf(parent, requestOptions)
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
update(resource, data) {
|
|
1225
|
+
return this.getId(resource).then((id) => {
|
|
1226
|
+
if (id !== void 0) {
|
|
1227
|
+
return this.connector.put("resource.item", { data }, { id });
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Fast way to delete resource from NGW and clean cache.
|
|
1233
|
+
* @param resource - Resource definition
|
|
1234
|
+
*/
|
|
1235
|
+
delete(resource) {
|
|
1236
|
+
return this.getId(resource).then((id) => {
|
|
1237
|
+
if (id !== void 0) {
|
|
1238
|
+
return this.connector.delete("resource.item", null, { id }).then(() => {
|
|
1239
|
+
this._cleanResourceItemCache(id);
|
|
1240
|
+
return void 0;
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
_getChildrenOf(parent, requestOptions, _items = []) {
|
|
1246
|
+
return this.connector.get(
|
|
1247
|
+
"resource.collection",
|
|
1248
|
+
__spreadValues$1({ cache: true }, requestOptions),
|
|
1249
|
+
{
|
|
1250
|
+
parent
|
|
1251
|
+
}
|
|
1252
|
+
).then((items) => {
|
|
1253
|
+
const recursivePromises = [];
|
|
1254
|
+
for (const item of items) {
|
|
1255
|
+
this.cache.add("resource.item", CancelablePromise.resolve(item), {
|
|
1256
|
+
id: item.resource.id
|
|
1257
|
+
});
|
|
1258
|
+
_items.push(item);
|
|
1259
|
+
if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1260
|
+
recursivePromises.push(
|
|
1261
|
+
this._getChildrenOf(item.resource.id, requestOptions, _items)
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
if (recursivePromises.length) {
|
|
1266
|
+
return CancelablePromise.all(recursivePromises).then(() => {
|
|
1267
|
+
return _items;
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
return _items;
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
_cleanResourceItemCache(id) {
|
|
1274
|
+
return __async(this, null, function* () {
|
|
1275
|
+
const all = this.cache.all();
|
|
1276
|
+
const toDelete = [];
|
|
1277
|
+
for (const c of all) {
|
|
1278
|
+
const cid = c.options && c.options.id;
|
|
1279
|
+
if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
|
|
1280
|
+
if (typeof cid === "number") {
|
|
1281
|
+
if (cid === id) {
|
|
1282
|
+
toDelete.push(c);
|
|
1283
|
+
}
|
|
1284
|
+
} else {
|
|
1285
|
+
const rid = yield this.getId(cid);
|
|
1286
|
+
if (rid === id) {
|
|
1287
|
+
toDelete.push(c);
|
|
1288
|
+
}
|
|
891
1289
|
}
|
|
892
|
-
|
|
893
|
-
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
for (const d of toDelete) {
|
|
1293
|
+
this.cache.delete(d);
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
_fetchResourceById(id, requestOptions) {
|
|
1298
|
+
const promise = () => this.connector.get("resource.item", requestOptions, { id });
|
|
1299
|
+
return this.cache.add("resource.item", promise, {
|
|
1300
|
+
id
|
|
1301
|
+
}).catch((er) => {
|
|
1302
|
+
if (!(er instanceof ResourceNotFoundError)) {
|
|
1303
|
+
throw er;
|
|
1304
|
+
}
|
|
1305
|
+
return void 0;
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
_fetchResourceBy(resource, requestOptions) {
|
|
1309
|
+
return this.getMany(resource, requestOptions).then((resources) => {
|
|
1310
|
+
return resources[0];
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
_resourceCacheFilter(resource) {
|
|
1314
|
+
return CancelablePromise.all(this.cache.matchAll("resource.item")).then(
|
|
1315
|
+
(resources) => {
|
|
1316
|
+
const items = [];
|
|
1317
|
+
resources.filter((x) => {
|
|
1318
|
+
if (x) {
|
|
1319
|
+
if (resource.keyname && x.resource.keyname) {
|
|
1320
|
+
return resource.keyname === x.resource.keyname;
|
|
1321
|
+
}
|
|
1322
|
+
if (defined(resource.id) && defined(x.resource.id)) {
|
|
1323
|
+
return resource.id === x.resource.id;
|
|
1324
|
+
}
|
|
1325
|
+
return resourceCompare(resource, x.resource);
|
|
894
1326
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1327
|
+
});
|
|
1328
|
+
return items;
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const CONNECTORS = [];
|
|
1335
|
+
function addConnector(connector) {
|
|
1336
|
+
CONNECTORS.push(connector);
|
|
1337
|
+
}
|
|
1338
|
+
function findConnector(options) {
|
|
1339
|
+
return CONNECTORS.find((x) => {
|
|
1340
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1341
|
+
if (options.auth) {
|
|
1342
|
+
if (x.options.auth) {
|
|
1343
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1344
|
+
}
|
|
1345
|
+
} else {
|
|
1346
|
+
return true;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
function removeConnector(connector) {
|
|
1352
|
+
const index = CONNECTORS.indexOf(connector);
|
|
1353
|
+
if (index !== -1) {
|
|
1354
|
+
CONNECTORS.splice(index, 1);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
var __defProp$2 = Object.defineProperty;
|
|
1359
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1360
|
+
var __publicField$2 = (obj, key, value) => {
|
|
1361
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1362
|
+
return value;
|
|
1363
|
+
};
|
|
1364
|
+
class InsufficientPermissionsError extends NgwError {
|
|
1365
|
+
constructor(obj) {
|
|
1366
|
+
super(obj);
|
|
1367
|
+
__publicField$2(this, "name", "InsufficientPermissionsError");
|
|
1368
|
+
__publicField$2(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
1369
|
+
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1374
|
+
function template(str, data) {
|
|
1375
|
+
return str.replace(templateRe, (s, key) => {
|
|
1376
|
+
let value = data[key];
|
|
1377
|
+
if (value === void 0) {
|
|
1378
|
+
throw new Error("No value provided for letiable " + s);
|
|
1379
|
+
} else if (typeof value === "function") {
|
|
1380
|
+
value = value(data);
|
|
1381
|
+
}
|
|
1382
|
+
return value;
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
function apiRequest(opt) {
|
|
1387
|
+
const params = opt.params;
|
|
1388
|
+
return new CancelablePromise((resolve, reject) => {
|
|
1389
|
+
opt.connector.connect().then((apiItems) => {
|
|
1390
|
+
let apiItem = apiItems && apiItems[opt.name];
|
|
1391
|
+
if (apiItem) {
|
|
1392
|
+
apiItem = [...apiItem];
|
|
1393
|
+
let url = apiItem.shift();
|
|
1394
|
+
if (apiItem.length) {
|
|
1395
|
+
const replaceParams = {};
|
|
1396
|
+
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
1397
|
+
const arg = apiItem[fry];
|
|
1398
|
+
replaceParams[fry] = "{" + arg + "}";
|
|
1399
|
+
if (params[arg] === void 0) {
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
"`" + arg + "` url api argument is not specified"
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
910
1404
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
if (name === void 0) { name = ''; }
|
|
914
|
-
name = name || func.name;
|
|
915
|
-
var exist = this.get(name);
|
|
916
|
-
if (exist) {
|
|
917
|
-
return exist;
|
|
1405
|
+
if (url) {
|
|
1406
|
+
url = template(url, replaceParams);
|
|
918
1407
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
var exist = get(name);
|
|
934
|
-
if (exist) {
|
|
935
|
-
return exist;
|
|
936
|
-
}
|
|
937
|
-
var result = add(originalMethod.apply(this, args), name);
|
|
938
|
-
return result;
|
|
939
|
-
};
|
|
940
|
-
return descriptor;
|
|
941
|
-
};
|
|
942
|
-
};
|
|
943
|
-
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
944
|
-
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
945
|
-
if (name === void 0) { name = ''; }
|
|
946
|
-
return this.WaitForMe(name);
|
|
947
|
-
};
|
|
948
|
-
PromiseControl.prototype._onStop = function () {
|
|
949
|
-
if (this.options.onStop && !this.isLoaded) {
|
|
950
|
-
this.options.onStop();
|
|
1408
|
+
}
|
|
1409
|
+
if (params) {
|
|
1410
|
+
const paramArray = [];
|
|
1411
|
+
const paramList = params.paramList;
|
|
1412
|
+
if (Array.isArray(paramList)) {
|
|
1413
|
+
delete params.paramList;
|
|
1414
|
+
paramList.forEach((x) => {
|
|
1415
|
+
paramArray.push(`${x[0]}=${x[1]}`);
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
for (const p in params) {
|
|
1419
|
+
if (apiItem.indexOf(p) === -1) {
|
|
1420
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
1421
|
+
}
|
|
951
1422
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1423
|
+
if (paramArray.length) {
|
|
1424
|
+
url = url + "?" + paramArray.join("&");
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (url) {
|
|
1428
|
+
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1429
|
+
} else {
|
|
1430
|
+
reject(new Error("request url is not set"));
|
|
1431
|
+
}
|
|
1432
|
+
} else {
|
|
1433
|
+
resolve(void 0);
|
|
963
1434
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1435
|
+
}).catch((er) => {
|
|
1436
|
+
reject(er);
|
|
1437
|
+
});
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
var __defProp$1 = Object.defineProperty;
|
|
1442
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1443
|
+
var __publicField$1 = (obj, key, value) => {
|
|
1444
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1445
|
+
return value;
|
|
1446
|
+
};
|
|
1447
|
+
class NetworkError extends Error {
|
|
1448
|
+
constructor(url) {
|
|
1449
|
+
super();
|
|
1450
|
+
__publicField$1(this, "name", "NetworkError");
|
|
1451
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
1452
|
+
this.message = `Unable to request ${url}.
|
|
1453
|
+
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
let loadData;
|
|
1458
|
+
{
|
|
1459
|
+
loadData = (url, callback, options = {}, error, onCancel) => {
|
|
1460
|
+
options.method = options.method || "GET";
|
|
1461
|
+
const xhr = new XMLHttpRequest();
|
|
1462
|
+
xhr.open(options.method || "GET", url, true);
|
|
1463
|
+
if (options.responseType === "blob") {
|
|
1464
|
+
xhr.responseType = options.responseType;
|
|
1465
|
+
}
|
|
1466
|
+
const getResponseText = () => {
|
|
968
1467
|
try {
|
|
969
|
-
|
|
1468
|
+
return JSON.parse(xhr.responseText);
|
|
1469
|
+
} catch (er) {
|
|
1470
|
+
return xhr.responseText;
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
const processingResponse = (forError = false) => {
|
|
1474
|
+
const cb = forError ? error : callback;
|
|
1475
|
+
if (options.responseType === "blob") {
|
|
1476
|
+
cb(xhr.response);
|
|
1477
|
+
} else {
|
|
1478
|
+
if (xhr.responseText) {
|
|
1479
|
+
cb(getResponseText());
|
|
1480
|
+
} else {
|
|
1481
|
+
error({ message: "" });
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
xhr.onload = () => {
|
|
1486
|
+
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1487
|
+
error(new NgwError(getResponseText()));
|
|
1488
|
+
}
|
|
1489
|
+
processingResponse();
|
|
1490
|
+
};
|
|
1491
|
+
xhr.onerror = (er) => {
|
|
1492
|
+
if (xhr.status === 0) {
|
|
1493
|
+
error(new NetworkError(url));
|
|
1494
|
+
} else {
|
|
1495
|
+
error(er);
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
xhr.upload.onprogress = function(e) {
|
|
1499
|
+
if (e.lengthComputable) {
|
|
1500
|
+
const percentComplete = e.loaded / e.total * 100;
|
|
1501
|
+
if (options.onProgress) {
|
|
1502
|
+
options.onProgress(percentComplete, e);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
const headers = options.headers;
|
|
1507
|
+
if (headers) {
|
|
1508
|
+
for (const h in headers) {
|
|
1509
|
+
const header = headers[h];
|
|
1510
|
+
if (typeof header === "string") {
|
|
1511
|
+
xhr.setRequestHeader(h, header);
|
|
1512
|
+
}
|
|
970
1513
|
}
|
|
971
|
-
|
|
972
|
-
|
|
1514
|
+
}
|
|
1515
|
+
if (options.withCredentials !== void 0) {
|
|
1516
|
+
xhr.withCredentials = options.withCredentials;
|
|
1517
|
+
}
|
|
1518
|
+
let data;
|
|
1519
|
+
if (options.file) {
|
|
1520
|
+
data = new FormData();
|
|
1521
|
+
data.append("file", options.file);
|
|
1522
|
+
if (options.data) {
|
|
1523
|
+
for (const d in options.data) {
|
|
1524
|
+
data.append(d, data[d]);
|
|
1525
|
+
}
|
|
973
1526
|
}
|
|
1527
|
+
} else {
|
|
1528
|
+
data = options.data ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : null;
|
|
1529
|
+
}
|
|
1530
|
+
if (onCancel) {
|
|
1531
|
+
onCancel(() => {
|
|
1532
|
+
xhr.abort();
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
xhr.send(data);
|
|
974
1536
|
};
|
|
975
|
-
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
var __defProp = Object.defineProperty;
|
|
1540
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1541
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1542
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1543
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1544
|
+
var __spreadValues = (a, b) => {
|
|
1545
|
+
for (var prop in b || (b = {}))
|
|
1546
|
+
if (__hasOwnProp.call(b, prop))
|
|
1547
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1548
|
+
if (__getOwnPropSymbols)
|
|
1549
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
1550
|
+
if (__propIsEnum.call(b, prop))
|
|
1551
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1552
|
+
}
|
|
1553
|
+
return a;
|
|
1554
|
+
};
|
|
1555
|
+
var __publicField = (obj, key, value) => {
|
|
1556
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1557
|
+
return value;
|
|
1558
|
+
};
|
|
1559
|
+
let ID = 0;
|
|
1560
|
+
class NgwConnector {
|
|
1561
|
+
constructor(options) {
|
|
1562
|
+
this.options = options;
|
|
1563
|
+
__publicField(this, "id", ID++);
|
|
1564
|
+
__publicField(this, "emitter", new EventEmitter());
|
|
1565
|
+
__publicField(this, "user");
|
|
1566
|
+
__publicField(this, "resources");
|
|
1567
|
+
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
1568
|
+
__publicField(this, "activeRequests", []);
|
|
1569
|
+
__publicField(this, "requestTransform");
|
|
1570
|
+
const exist = findConnector(options);
|
|
1571
|
+
if (exist) {
|
|
1572
|
+
return exist;
|
|
1573
|
+
} else {
|
|
1574
|
+
if (this.options.route) {
|
|
1575
|
+
this.routeStr = this.options.route;
|
|
1576
|
+
}
|
|
1577
|
+
if (this.options.requestTransform) {
|
|
1578
|
+
this.requestTransform = this.options.requestTransform;
|
|
1579
|
+
}
|
|
1580
|
+
this.resources = new ResourcesControl(this);
|
|
1581
|
+
addConnector(this);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
static create(options) {
|
|
1585
|
+
return new this(options);
|
|
1586
|
+
}
|
|
1587
|
+
setRequestTransform(requestTransform) {
|
|
1588
|
+
this.requestTransform = requestTransform;
|
|
1589
|
+
}
|
|
976
1590
|
/**
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1591
|
+
* Fast way to specify the connection address to NextGIS Web.
|
|
1592
|
+
* The current connection will be severed.
|
|
1593
|
+
* @param baseUrl - NGW url
|
|
1594
|
+
*/
|
|
1595
|
+
setNgw(baseUrl) {
|
|
1596
|
+
this.logout();
|
|
1597
|
+
this.options.baseUrl = baseUrl;
|
|
1598
|
+
addConnector(this);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1602
|
+
* @remarks
|
|
1603
|
+
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
1604
|
+
* Can be used to check connection.
|
|
979
1605
|
* @example
|
|
980
|
-
* Catch `CancelError`
|
|
981
1606
|
* ```javascript
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
* }).catch((er) => {
|
|
987
|
-
* if (er.name === "CancelError") {
|
|
988
|
-
* // handle cancel error
|
|
989
|
-
* }
|
|
990
|
-
* throw er;
|
|
991
|
-
* });
|
|
992
|
-
*
|
|
993
|
-
* promise.cancel();
|
|
1607
|
+
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
1608
|
+
* connector.connect()
|
|
1609
|
+
* .then(() => console.log('Ok'))
|
|
1610
|
+
* .catch((er) => console.log('Connection problem', er));
|
|
994
1611
|
* ```
|
|
1612
|
+
*/
|
|
1613
|
+
connect() {
|
|
1614
|
+
const cache = new Cache();
|
|
1615
|
+
const auth = this.options.auth;
|
|
1616
|
+
const makeConnect = () => new CancelablePromise((resolve, reject) => {
|
|
1617
|
+
const makeQuery = () => {
|
|
1618
|
+
return this.makeQuery(this.routeStr, {}, {}).then((route) => {
|
|
1619
|
+
resolve(route);
|
|
1620
|
+
}).catch((er) => {
|
|
1621
|
+
reject(er);
|
|
1622
|
+
});
|
|
1623
|
+
};
|
|
1624
|
+
if (auth) {
|
|
1625
|
+
const { login, password } = auth;
|
|
1626
|
+
if (login && password) {
|
|
1627
|
+
return this._login({ login, password }).then(() => {
|
|
1628
|
+
return makeQuery();
|
|
1629
|
+
}).catch((er) => reject(er));
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
return makeQuery();
|
|
1633
|
+
});
|
|
1634
|
+
return cache.add("route", makeConnect, {
|
|
1635
|
+
id: this.id,
|
|
1636
|
+
auth,
|
|
1637
|
+
baseUrl: this.options.baseUrl
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Quick way to change NextGIS Web user.
|
|
1642
|
+
* @param credentials - New user credentials
|
|
1643
|
+
*/
|
|
1644
|
+
login(credentials, options) {
|
|
1645
|
+
this.logout();
|
|
1646
|
+
addConnector(this);
|
|
1647
|
+
return this._login(credentials, options);
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Disconnecting a user. Aborting all current requests
|
|
1651
|
+
*/
|
|
1652
|
+
logout() {
|
|
1653
|
+
this.abort();
|
|
1654
|
+
removeConnector(this);
|
|
1655
|
+
this.options.auth = void 0;
|
|
1656
|
+
this.user = void 0;
|
|
1657
|
+
this.emitter.emit("logout");
|
|
1658
|
+
this.resources.cache.clean();
|
|
1659
|
+
}
|
|
1660
|
+
getUserInfo(credentials, options) {
|
|
1661
|
+
if (this.user && this.user.id) {
|
|
1662
|
+
return CancelablePromise.resolve(this.user);
|
|
1663
|
+
}
|
|
1664
|
+
if (credentials) {
|
|
1665
|
+
this.options.auth = credentials;
|
|
1666
|
+
}
|
|
1667
|
+
const options_ = __spreadValues({
|
|
1668
|
+
headers: this.getAuthorizationHeaders(credentials)
|
|
1669
|
+
}, options);
|
|
1670
|
+
return this.makeQuery(
|
|
1671
|
+
"/api/component/auth/current_user",
|
|
1672
|
+
{},
|
|
1673
|
+
options_
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1678
|
+
*/
|
|
1679
|
+
getAuthorizationHeaders(credentials) {
|
|
1680
|
+
const client = this.makeClientId(credentials);
|
|
1681
|
+
if (client) {
|
|
1682
|
+
return {
|
|
1683
|
+
Authorization: "Basic " + client
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
makeClientId(credentials) {
|
|
1688
|
+
credentials = credentials || this.options.auth;
|
|
1689
|
+
if (credentials) {
|
|
1690
|
+
const { login, password } = credentials;
|
|
1691
|
+
const str = unescape(encodeURIComponent(`${login}:${password}`));
|
|
1692
|
+
{
|
|
1693
|
+
return window.btoa(str);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
/** Stop all api requests */
|
|
1698
|
+
abort() {
|
|
1699
|
+
for (const req of this.activeRequests) {
|
|
1700
|
+
req.cancel();
|
|
1701
|
+
}
|
|
1702
|
+
this.activeRequests = [];
|
|
1703
|
+
}
|
|
1704
|
+
getActiveApiRequests() {
|
|
1705
|
+
return [...this.activeRequests];
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Send request to NGW api router.
|
|
1709
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1710
|
+
* @param params - Request item params or query params
|
|
1711
|
+
* @param requestOptions - Request options
|
|
1712
|
+
*
|
|
995
1713
|
* @example
|
|
996
|
-
* Handle `onCancel` callback
|
|
997
1714
|
* ```javascript
|
|
998
|
-
* import CancelablePromise from "@nextgis/cancelable-promise";
|
|
999
1715
|
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1006
|
-
* xhr.onerror = (er) => {
|
|
1007
|
-
* reject(er);
|
|
1008
|
-
* };
|
|
1716
|
+
* // there is such an NGW route item
|
|
1717
|
+
* // "feature_layer.feature.item": [
|
|
1718
|
+
* // "/api/resource/{0}/feature/{1}",
|
|
1719
|
+
* // "id",
|
|
1720
|
+
* // "fid"
|
|
1721
|
+
* // ],
|
|
1009
1722
|
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
* }
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1723
|
+
* const connector = new NgwConnector({ baseUrl: 'https://example.nextgis.com' });
|
|
1724
|
+
* connector.apiRequest('feature_layer.feature.item', {
|
|
1725
|
+
* // request params for {0} and {1}
|
|
1726
|
+
* 'id': 2011,
|
|
1727
|
+
* 'fid': 101,
|
|
1728
|
+
* // query params
|
|
1729
|
+
* 'srs': 4326,
|
|
1730
|
+
* 'geom_format': 'geojson',
|
|
1731
|
+
* }, { method: 'GET' });
|
|
1732
|
+
* // send get-request to 'https://example.nextgis.com/api/resource/2011/feature/101?srs=4326&geom_format=geojson'
|
|
1016
1733
|
*
|
|
1017
|
-
* promise.cancel();
|
|
1018
1734
|
* ```
|
|
1019
1735
|
*/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
1042
|
-
resolve(value);
|
|
1043
|
-
};
|
|
1044
|
-
var onReject = function (error) {
|
|
1045
|
-
_this._isPending = false;
|
|
1046
|
-
reject(error);
|
|
1047
|
-
};
|
|
1048
|
-
var onCancel = function (handler) {
|
|
1049
|
-
if (!_this._isPending) {
|
|
1050
|
-
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
1051
|
-
}
|
|
1052
|
-
_this._cancelHandlers.push(handler);
|
|
1053
|
-
};
|
|
1054
|
-
return executor(onResolve, onReject, onCancel);
|
|
1055
|
-
}),
|
|
1056
|
-
];
|
|
1057
|
-
if (timeout) {
|
|
1058
|
-
promises.push(new Promise(function (resolve, reject) {
|
|
1059
|
-
setTimeout(function () {
|
|
1060
|
-
if (_this._isPending) {
|
|
1061
|
-
try {
|
|
1062
|
-
_this.cancel();
|
|
1063
|
-
}
|
|
1064
|
-
finally {
|
|
1065
|
-
reject(new TimeoutError());
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}, timeout);
|
|
1069
|
-
}));
|
|
1070
|
-
}
|
|
1071
|
-
this._promise = Promise.race(promises);
|
|
1072
|
-
}
|
|
1073
|
-
CancelablePromise.createControl = function (opt) {
|
|
1074
|
-
return new PromiseControl(opt);
|
|
1075
|
-
};
|
|
1076
|
-
CancelablePromise.resolve = function (value) {
|
|
1077
|
-
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
1078
|
-
};
|
|
1079
|
-
CancelablePromise.reject = function (value) {
|
|
1080
|
-
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
1081
|
-
};
|
|
1082
|
-
CancelablePromise.all = function (values) {
|
|
1083
|
-
var _this = this;
|
|
1084
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
1085
|
-
Promise.all(values).then(resolve).catch(reject);
|
|
1086
|
-
}).catch(function (er) {
|
|
1087
|
-
if (er instanceof _this.CancelError) {
|
|
1088
|
-
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
1089
|
-
var v = values_1[_i];
|
|
1090
|
-
var v_ = v;
|
|
1091
|
-
if ('cancel' in v_) {
|
|
1092
|
-
v_.cancel();
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
throw er;
|
|
1097
|
-
});
|
|
1098
|
-
};
|
|
1099
|
-
CancelablePromise.prototype.attach = function (p) {
|
|
1100
|
-
if (this._isCanceled) {
|
|
1101
|
-
p.cancel();
|
|
1102
|
-
}
|
|
1103
|
-
else {
|
|
1104
|
-
this._children.push(p);
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
1108
|
-
var _this = this;
|
|
1109
|
-
var p = new CancelablePromise(function (resolve, reject) {
|
|
1110
|
-
if (_this._promise) {
|
|
1111
|
-
var reject_1 = function (r) {
|
|
1112
|
-
if (onrejected) {
|
|
1113
|
-
handleCallback(resolve, reject, onrejected, r);
|
|
1114
|
-
}
|
|
1115
|
-
else {
|
|
1116
|
-
reject(r);
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
|
-
_this._promise.then(function (r) {
|
|
1120
|
-
if (_this._isCanceled) {
|
|
1121
|
-
reject_1(r);
|
|
1122
|
-
}
|
|
1123
|
-
else {
|
|
1124
|
-
if (onfulfilled) {
|
|
1125
|
-
handleCallback(resolve, reject, onfulfilled, r);
|
|
1126
|
-
}
|
|
1127
|
-
else {
|
|
1128
|
-
resolve(r);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
}, reject_1);
|
|
1132
|
-
}
|
|
1133
|
-
});
|
|
1134
|
-
p._parentPromise = this;
|
|
1135
|
-
this._children.push(p);
|
|
1136
|
-
return p;
|
|
1137
|
-
};
|
|
1138
|
-
CancelablePromise.prototype.catch = function (onrejected) {
|
|
1139
|
-
if (this._isCanceled && onrejected) {
|
|
1140
|
-
onrejected(new CancelError());
|
|
1141
|
-
}
|
|
1142
|
-
return this.then(undefined, onrejected);
|
|
1143
|
-
};
|
|
1144
|
-
CancelablePromise.prototype.finally = function (onfinally) {
|
|
1145
|
-
if (this._promise) {
|
|
1146
|
-
return this._promise.finally(onfinally);
|
|
1147
|
-
}
|
|
1148
|
-
if (this._isCanceled) {
|
|
1149
|
-
return Promise.reject(new CancelError());
|
|
1150
|
-
}
|
|
1151
|
-
return Promise.reject(onfinally);
|
|
1152
|
-
};
|
|
1153
|
-
CancelablePromise.prototype.cancel = function () {
|
|
1154
|
-
// No reason to run cancel action if promise is already complete
|
|
1155
|
-
if (this._isCanceled || !this._isPending) {
|
|
1156
|
-
return this;
|
|
1157
|
-
}
|
|
1158
|
-
this._isCanceled = true;
|
|
1159
|
-
var parent = this._getTopParent();
|
|
1160
|
-
if (parent) {
|
|
1161
|
-
parent.cancel();
|
|
1162
|
-
}
|
|
1163
|
-
if (this._children) {
|
|
1164
|
-
this._children.forEach(function (x) { return x.cancel(); });
|
|
1165
|
-
}
|
|
1166
|
-
if (this._isPending) {
|
|
1167
|
-
if (this._cancelHandlers.length) {
|
|
1168
|
-
try {
|
|
1169
|
-
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
1170
|
-
var handler = _a[_i];
|
|
1171
|
-
handler();
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
catch (error) {
|
|
1175
|
-
// this._setCanceledCallback(error);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
if (this._setCanceledCallback) {
|
|
1179
|
-
this._setCanceledCallback();
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
this._destroy();
|
|
1183
|
-
return this;
|
|
1184
|
-
};
|
|
1185
|
-
CancelablePromise.prototype._getTopParent = function () {
|
|
1186
|
-
var parent = this._parentPromise;
|
|
1187
|
-
var hasParent = !!parent;
|
|
1188
|
-
while (hasParent) {
|
|
1189
|
-
if (parent && parent._parentPromise) {
|
|
1190
|
-
parent = parent._parentPromise;
|
|
1191
|
-
hasParent = !!parent;
|
|
1192
|
-
}
|
|
1193
|
-
else {
|
|
1194
|
-
hasParent = false;
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
return parent;
|
|
1198
|
-
};
|
|
1199
|
-
CancelablePromise.prototype._destroy = function () {
|
|
1200
|
-
this._setCanceledCallback = undefined;
|
|
1201
|
-
this._cancelPromise = undefined;
|
|
1202
|
-
this._promise = undefined;
|
|
1203
|
-
};
|
|
1204
|
-
CancelablePromise.CancelError = CancelError;
|
|
1205
|
-
CancelablePromise.TimeoutError = TimeoutError;
|
|
1206
|
-
CancelablePromise.PromiseControl = PromiseControl;
|
|
1207
|
-
return CancelablePromise;
|
|
1208
|
-
}());
|
|
1209
|
-
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
1210
|
-
|
|
1736
|
+
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
1737
|
+
var _a, _b;
|
|
1738
|
+
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
1739
|
+
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
1740
|
+
const params = objectRemoveEmpty(params_);
|
|
1741
|
+
const makeApiRequest = () => apiRequest({ name, params, requestOptions, connector: this });
|
|
1742
|
+
if (requestOptions.cache && method === "GET") {
|
|
1743
|
+
const cache = new Cache();
|
|
1744
|
+
return cache.add(name, makeApiRequest, __spreadValues({
|
|
1745
|
+
params
|
|
1746
|
+
}, objectRemoveEmpty({
|
|
1747
|
+
headers,
|
|
1748
|
+
withCredentials,
|
|
1749
|
+
responseType,
|
|
1750
|
+
baseUrl: this.options.baseUrl,
|
|
1751
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
1752
|
+
})));
|
|
1753
|
+
}
|
|
1754
|
+
return makeApiRequest();
|
|
1755
|
+
}
|
|
1211
1756
|
/**
|
|
1212
|
-
*
|
|
1757
|
+
* Shortcut method for send POST request to NGW.
|
|
1758
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1759
|
+
* @param options - Request options
|
|
1760
|
+
* @param params - Request item params or query params
|
|
1213
1761
|
*
|
|
1214
|
-
* @
|
|
1215
|
-
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* ```javascript
|
|
1764
|
+
* connector.post('resource.collection', { data: POST_PAYLOAD })
|
|
1765
|
+
* .then((newResource) => console.log(newResource))
|
|
1766
|
+
* .catch((error) => console.warn(error));
|
|
1767
|
+
* ```
|
|
1216
1768
|
*/
|
|
1217
|
-
|
|
1218
|
-
|
|
1769
|
+
post(name, options, params) {
|
|
1770
|
+
options = options || {};
|
|
1771
|
+
options.method = "POST";
|
|
1772
|
+
return this.apiRequest(
|
|
1773
|
+
name,
|
|
1774
|
+
params,
|
|
1775
|
+
options
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1219
1778
|
/**
|
|
1220
|
-
*
|
|
1779
|
+
* Shortcut method for send GET request to NGW.
|
|
1780
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1781
|
+
* @param options - Request options
|
|
1782
|
+
* @param params - Request item params or query params
|
|
1221
1783
|
*/
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
return NgwError;
|
|
1232
|
-
}(Error));
|
|
1233
|
-
|
|
1784
|
+
get(name, options, params) {
|
|
1785
|
+
options = options || {};
|
|
1786
|
+
options.method = "GET";
|
|
1787
|
+
return this.apiRequest(
|
|
1788
|
+
name,
|
|
1789
|
+
params,
|
|
1790
|
+
options
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1234
1793
|
/**
|
|
1235
|
-
*
|
|
1794
|
+
* Shortcut method for send PATCH request to NGW.
|
|
1795
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1796
|
+
* @param options - Request options
|
|
1797
|
+
* @param params - Request item params or query params
|
|
1236
1798
|
*/
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
return ResourceNotFoundError;
|
|
1247
|
-
}(NgwError));
|
|
1248
|
-
|
|
1249
|
-
function isObject(val) {
|
|
1250
|
-
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1799
|
+
patch(name, options, params) {
|
|
1800
|
+
options = options || {};
|
|
1801
|
+
options.method = "PATCH";
|
|
1802
|
+
return this.apiRequest(
|
|
1803
|
+
name,
|
|
1804
|
+
params,
|
|
1805
|
+
options
|
|
1806
|
+
);
|
|
1251
1807
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1808
|
+
/**
|
|
1809
|
+
* Shortcut method for send PUT request to NGW.
|
|
1810
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1811
|
+
* @param options - Request options
|
|
1812
|
+
* @param params - Request item params or query params
|
|
1813
|
+
*/
|
|
1814
|
+
put(name, options, params) {
|
|
1815
|
+
options = options || {};
|
|
1816
|
+
options.method = "PUT";
|
|
1817
|
+
return this.apiRequest(
|
|
1818
|
+
name,
|
|
1819
|
+
params,
|
|
1820
|
+
options
|
|
1821
|
+
);
|
|
1255
1822
|
}
|
|
1256
|
-
|
|
1257
|
-
var exclude = ['description'];
|
|
1258
1823
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
* https://docs.nextgis.
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
* { keyname, owner_user: { id }} > { keyname, owner_user__id }
|
|
1264
|
-
* ```
|
|
1265
|
-
*
|
|
1266
|
-
* @param resource - Any property from NGW resource item
|
|
1824
|
+
* Shortcut method for send DELETE request to NGW.
|
|
1825
|
+
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1826
|
+
* @param options - Request options
|
|
1827
|
+
* @param params - Request item params or query params
|
|
1267
1828
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
if (key === 'owner_user') {
|
|
1277
|
-
var children = resourceToQuery(value, key);
|
|
1278
|
-
Object.assign(query, children);
|
|
1279
|
-
}
|
|
1280
|
-
else if (key === 'parent' && 'id' in value) {
|
|
1281
|
-
query.parent_id = value.id;
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
else if (defined(value)) {
|
|
1285
|
-
query[prefix + key] = value;
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
return query;
|
|
1829
|
+
delete(name, options, params) {
|
|
1830
|
+
options = options || {};
|
|
1831
|
+
options.method = "DELETE";
|
|
1832
|
+
return this.apiRequest(
|
|
1833
|
+
name,
|
|
1834
|
+
params,
|
|
1835
|
+
options
|
|
1836
|
+
);
|
|
1290
1837
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1838
|
+
/**
|
|
1839
|
+
* Send request to NGW.
|
|
1840
|
+
* @param url - URL address to NGW
|
|
1841
|
+
* @param params - Query params
|
|
1842
|
+
* @param options - Request options
|
|
1843
|
+
*/
|
|
1844
|
+
makeQuery(url, params, options = {}) {
|
|
1845
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1846
|
+
if (url) {
|
|
1847
|
+
if (params) {
|
|
1848
|
+
url = template(url, params);
|
|
1296
1849
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
* @param resource - Resource id, keyname or search-object
|
|
1303
|
-
*
|
|
1304
|
-
* @remarks
|
|
1305
|
-
* Fetching resource would be cached to speed up next call
|
|
1306
|
-
*/
|
|
1307
|
-
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
1308
|
-
var _this = this;
|
|
1309
|
-
var cache = new Cache();
|
|
1310
|
-
var forCache = {};
|
|
1311
|
-
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
1312
|
-
if (typeof resource === 'string') {
|
|
1313
|
-
forCache.keyname = resource;
|
|
1314
|
-
}
|
|
1315
|
-
else if (typeof resource === 'number') {
|
|
1316
|
-
forCache.id = resource;
|
|
1317
|
-
}
|
|
1318
|
-
else if (isObject(resource)) {
|
|
1319
|
-
if (resource.id !== undefined) {
|
|
1320
|
-
forCache.id = resource.id;
|
|
1321
|
-
}
|
|
1322
|
-
else if (resource.keyname) {
|
|
1323
|
-
forCache.keyname = resource.keyname;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
var makeRequest = function () {
|
|
1327
|
-
if (typeof resource === 'string') {
|
|
1328
|
-
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
1329
|
-
}
|
|
1330
|
-
else if (typeof resource === 'number') {
|
|
1331
|
-
return _this._fetchResourceById(resource, opt);
|
|
1332
|
-
}
|
|
1333
|
-
else if (isObject(resource)) {
|
|
1334
|
-
return _this._fetchResourceBy(resource, opt);
|
|
1335
|
-
}
|
|
1336
|
-
return CancelablePromise.resolve(undefined);
|
|
1337
|
-
};
|
|
1338
|
-
return cache.addFull('resource', makeRequest, forCache);
|
|
1339
|
-
};
|
|
1340
|
-
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
1341
|
-
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1342
|
-
if (res) {
|
|
1343
|
-
return res;
|
|
1344
|
-
}
|
|
1345
|
-
throw new ResourceNotFoundError();
|
|
1346
|
-
});
|
|
1347
|
-
};
|
|
1348
|
-
/**
|
|
1349
|
-
* A fast way to retrieve resource ID for any resource definition.
|
|
1350
|
-
* @param resource - Any available resource definition
|
|
1351
|
-
*
|
|
1352
|
-
* @remarks
|
|
1353
|
-
* There are situations when exactly the resource id is needed
|
|
1354
|
-
* (for example, to compose the correct request to the api)
|
|
1355
|
-
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1356
|
-
* if the resource is specified through a keyname or other parameters.
|
|
1357
|
-
*/
|
|
1358
|
-
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
1359
|
-
if (typeof resource === 'number') {
|
|
1360
|
-
return CancelablePromise.resolve(resource);
|
|
1361
|
-
}
|
|
1362
|
-
else if (typeof resource === 'string' || isObject(resource)) {
|
|
1363
|
-
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1364
|
-
if (res) {
|
|
1365
|
-
return res.resource.id;
|
|
1366
|
-
}
|
|
1367
|
-
});
|
|
1368
|
-
}
|
|
1369
|
-
return CancelablePromise.resolve(undefined);
|
|
1370
|
-
};
|
|
1371
|
-
/**
|
|
1372
|
-
* A fast way to retrieve resource ID for any resource definition.
|
|
1373
|
-
* @param resource - Any available resource definition
|
|
1374
|
-
*
|
|
1375
|
-
* @remarks
|
|
1376
|
-
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1377
|
-
* To not make one more checks if the resource is definitely exists
|
|
1378
|
-
*/
|
|
1379
|
-
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
1380
|
-
return this.getId(resource, requestOptions).then(function (resp) {
|
|
1381
|
-
if (resp === undefined) {
|
|
1382
|
-
throw new Error();
|
|
1383
|
-
}
|
|
1384
|
-
return resp;
|
|
1385
|
-
});
|
|
1386
|
-
};
|
|
1387
|
-
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
1388
|
-
var _this = this;
|
|
1389
|
-
return this._resourceCacheFilter(resource).then(function (items) {
|
|
1390
|
-
if (!items.length) {
|
|
1391
|
-
var query = {};
|
|
1392
|
-
if (resource.keyname) {
|
|
1393
|
-
query.keyname = resource.keyname;
|
|
1394
|
-
}
|
|
1395
|
-
else {
|
|
1396
|
-
Object.assign(query, resourceToQuery(resource));
|
|
1397
|
-
}
|
|
1398
|
-
return _this.connector
|
|
1399
|
-
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
1400
|
-
.then(function (resources) {
|
|
1401
|
-
if (resources) {
|
|
1402
|
-
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
1403
|
-
var x = resources_1[_i];
|
|
1404
|
-
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
1405
|
-
id: x.resource.id,
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
return resources;
|
|
1410
|
-
});
|
|
1411
|
-
}
|
|
1412
|
-
return items;
|
|
1413
|
-
});
|
|
1414
|
-
};
|
|
1415
|
-
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
1416
|
-
var _this = this;
|
|
1417
|
-
return this.getOne(resource, requestOptions).then(function (child) {
|
|
1418
|
-
if (child) {
|
|
1419
|
-
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
1420
|
-
}
|
|
1421
|
-
return CancelablePromise.resolve(undefined);
|
|
1422
|
-
});
|
|
1423
|
-
};
|
|
1424
|
-
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
1425
|
-
var _this = this;
|
|
1426
|
-
return this.getIdOrFail(resource).then(function (parent) {
|
|
1427
|
-
return _this._getChildrenOf(parent, requestOptions);
|
|
1428
|
-
});
|
|
1429
|
-
};
|
|
1430
|
-
ResourcesControl.prototype.update = function (resource, data) {
|
|
1431
|
-
var _this = this;
|
|
1432
|
-
return this.getId(resource).then(function (id) {
|
|
1433
|
-
if (id !== undefined) {
|
|
1434
|
-
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
1435
|
-
}
|
|
1436
|
-
});
|
|
1437
|
-
};
|
|
1438
|
-
/**
|
|
1439
|
-
* Fast way to delete resource from NGW and clean cache.
|
|
1440
|
-
* @param resource - Resource definition
|
|
1441
|
-
*/
|
|
1442
|
-
ResourcesControl.prototype.delete = function (resource) {
|
|
1443
|
-
var _this = this;
|
|
1444
|
-
return this.getId(resource).then(function (id) {
|
|
1445
|
-
if (id !== undefined) {
|
|
1446
|
-
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
1447
|
-
_this._cleanResourceItemCache(id);
|
|
1448
|
-
return undefined;
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
});
|
|
1452
|
-
};
|
|
1453
|
-
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
1454
|
-
var _this = this;
|
|
1455
|
-
if (_items === void 0) { _items = []; }
|
|
1456
|
-
return this.connector
|
|
1457
|
-
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
1458
|
-
parent: parent,
|
|
1459
|
-
})
|
|
1460
|
-
.then(function (items) {
|
|
1461
|
-
var recursivePromises = [];
|
|
1462
|
-
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
1463
|
-
var item = items_1[_i];
|
|
1464
|
-
_this.cache.add('resource.item', CancelablePromise.resolve(item), {
|
|
1465
|
-
id: item.resource.id,
|
|
1466
|
-
});
|
|
1467
|
-
_items.push(item);
|
|
1468
|
-
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1469
|
-
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
if (recursivePromises.length) {
|
|
1473
|
-
return CancelablePromise.all(recursivePromises).then(function () {
|
|
1474
|
-
return _items;
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
return _items;
|
|
1478
|
-
});
|
|
1479
|
-
};
|
|
1480
|
-
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
1481
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1482
|
-
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
1483
|
-
return __generator(this, function (_b) {
|
|
1484
|
-
switch (_b.label) {
|
|
1485
|
-
case 0:
|
|
1486
|
-
all = this.cache.all();
|
|
1487
|
-
toDelete = [];
|
|
1488
|
-
_i = 0, all_1 = all;
|
|
1489
|
-
_b.label = 1;
|
|
1490
|
-
case 1:
|
|
1491
|
-
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
1492
|
-
c = all_1[_i];
|
|
1493
|
-
cid = c.options && c.options.id;
|
|
1494
|
-
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
1495
|
-
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
1496
|
-
if (cid === id) {
|
|
1497
|
-
toDelete.push(c);
|
|
1498
|
-
}
|
|
1499
|
-
return [3 /*break*/, 4];
|
|
1500
|
-
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
1501
|
-
case 3:
|
|
1502
|
-
rid = _b.sent();
|
|
1503
|
-
if (rid === id) {
|
|
1504
|
-
toDelete.push(c);
|
|
1505
|
-
}
|
|
1506
|
-
_b.label = 4;
|
|
1507
|
-
case 4:
|
|
1508
|
-
_i++;
|
|
1509
|
-
return [3 /*break*/, 1];
|
|
1510
|
-
case 5:
|
|
1511
|
-
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
1512
|
-
d = toDelete_1[_a];
|
|
1513
|
-
this.cache.delete(d);
|
|
1514
|
-
}
|
|
1515
|
-
return [2 /*return*/];
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
});
|
|
1519
|
-
};
|
|
1520
|
-
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
1521
|
-
var _this = this;
|
|
1522
|
-
var promise = function () {
|
|
1523
|
-
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
1524
|
-
};
|
|
1525
|
-
return this.cache
|
|
1526
|
-
.add('resource.item', promise, {
|
|
1527
|
-
id: id,
|
|
1528
|
-
})
|
|
1529
|
-
.catch(function (er) {
|
|
1530
|
-
if (!(er instanceof ResourceNotFoundError)) {
|
|
1531
|
-
throw er;
|
|
1532
|
-
}
|
|
1533
|
-
return undefined;
|
|
1534
|
-
});
|
|
1535
|
-
};
|
|
1536
|
-
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
1537
|
-
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
1538
|
-
return resources[0];
|
|
1539
|
-
});
|
|
1540
|
-
};
|
|
1541
|
-
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
1542
|
-
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
1543
|
-
var items = [];
|
|
1544
|
-
resources.filter(function (x) {
|
|
1545
|
-
if (x) {
|
|
1546
|
-
// identical by uniq props
|
|
1547
|
-
if (resource.keyname && x.resource.keyname) {
|
|
1548
|
-
return resource.keyname === x.resource.keyname;
|
|
1549
|
-
}
|
|
1550
|
-
if (defined(resource.id) && defined(x.resource.id)) {
|
|
1551
|
-
return resource.id === x.resource.id;
|
|
1552
|
-
}
|
|
1553
|
-
return resourceCompare(resource, x.resource);
|
|
1554
|
-
}
|
|
1555
|
-
});
|
|
1556
|
-
return items;
|
|
1557
|
-
});
|
|
1558
|
-
};
|
|
1559
|
-
return ResourcesControl;
|
|
1560
|
-
}());
|
|
1561
|
-
|
|
1562
|
-
var CONNECTORS = [];
|
|
1563
|
-
function addConnector(connector) {
|
|
1564
|
-
CONNECTORS.push(connector);
|
|
1565
|
-
}
|
|
1566
|
-
function findConnector(options) {
|
|
1567
|
-
return CONNECTORS.find(function (x) {
|
|
1568
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
1569
|
-
if (options.auth) {
|
|
1570
|
-
if (x.options.auth) {
|
|
1571
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1575
|
-
// if auth not in find options; use first connector with same url
|
|
1576
|
-
return true;
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
});
|
|
1850
|
+
url = encodeURI(fixUrlStr(url));
|
|
1851
|
+
return this._loadData(url, options);
|
|
1852
|
+
} else {
|
|
1853
|
+
throw new Error("Empty `url` not allowed");
|
|
1854
|
+
}
|
|
1580
1855
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1856
|
+
// -------------------------------------------------------------------------
|
|
1857
|
+
// Resource Methods
|
|
1858
|
+
// -------------------------------------------------------------------------
|
|
1859
|
+
/**
|
|
1860
|
+
* {@link ResourcesControl.getOne}
|
|
1861
|
+
*/
|
|
1862
|
+
getResource(resource, requestOptions) {
|
|
1863
|
+
return this.resources.getOne(resource, requestOptions);
|
|
1586
1864
|
}
|
|
1587
|
-
|
|
1588
1865
|
/**
|
|
1589
|
-
*
|
|
1866
|
+
* {@link ResourcesControl.getOneOrFail}
|
|
1590
1867
|
*/
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
function InsufficientPermissionsError(obj) {
|
|
1594
|
-
var _this = _super.call(this, obj) || this;
|
|
1595
|
-
_this.name = 'InsufficientPermissionsError';
|
|
1596
|
-
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1597
|
-
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1598
|
-
return _this;
|
|
1599
|
-
}
|
|
1600
|
-
return InsufficientPermissionsError;
|
|
1601
|
-
}(NgwError));
|
|
1602
|
-
|
|
1603
|
-
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1604
|
-
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1605
|
-
function template(str, data) {
|
|
1606
|
-
return str.replace(templateRe, function (s, key) {
|
|
1607
|
-
var value = data[key];
|
|
1608
|
-
if (value === undefined) {
|
|
1609
|
-
throw new Error('No value provided for letiable ' + s);
|
|
1610
|
-
}
|
|
1611
|
-
else if (typeof value === 'function') {
|
|
1612
|
-
value = value(data);
|
|
1613
|
-
}
|
|
1614
|
-
return value;
|
|
1615
|
-
});
|
|
1868
|
+
getResourceOrFail(resource, requestOptions) {
|
|
1869
|
+
return this.resources.getOneOrFail(resource, requestOptions);
|
|
1616
1870
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
.connect()
|
|
1623
|
-
.then(function (apiItems) {
|
|
1624
|
-
var apiItem = apiItems && apiItems[opt.name];
|
|
1625
|
-
if (apiItem) {
|
|
1626
|
-
apiItem = __spreadArray([], apiItem, true);
|
|
1627
|
-
var url = apiItem.shift();
|
|
1628
|
-
if (apiItem.length) {
|
|
1629
|
-
var replaceParams = {};
|
|
1630
|
-
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1631
|
-
var arg = apiItem[fry];
|
|
1632
|
-
replaceParams[fry] = '{' + arg + '}';
|
|
1633
|
-
if (params[arg] === undefined) {
|
|
1634
|
-
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
if (url) {
|
|
1638
|
-
url = template(url, replaceParams);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
// Transfer part of the parameters from `params` to the URL string
|
|
1642
|
-
if (params) {
|
|
1643
|
-
var paramArray_1 = [];
|
|
1644
|
-
var paramList = params.paramList;
|
|
1645
|
-
if (Array.isArray(paramList)) {
|
|
1646
|
-
delete params.paramList;
|
|
1647
|
-
paramList.forEach(function (x) {
|
|
1648
|
-
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1649
|
-
});
|
|
1650
|
-
}
|
|
1651
|
-
for (var p in params) {
|
|
1652
|
-
if (apiItem.indexOf(p) === -1) {
|
|
1653
|
-
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
if (paramArray_1.length) {
|
|
1657
|
-
url = url + '?' + paramArray_1.join('&');
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
if (url) {
|
|
1661
|
-
resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
|
|
1662
|
-
}
|
|
1663
|
-
else {
|
|
1664
|
-
reject(new Error('request url is not set'));
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
else {
|
|
1668
|
-
resolve(undefined);
|
|
1669
|
-
}
|
|
1670
|
-
})
|
|
1671
|
-
.catch(function (er) {
|
|
1672
|
-
reject(er);
|
|
1673
|
-
});
|
|
1674
|
-
});
|
|
1871
|
+
/**
|
|
1872
|
+
* @deprecated - use {@link getResource}
|
|
1873
|
+
*/
|
|
1874
|
+
getResourceBy(resource) {
|
|
1875
|
+
return this.resources.getOne(resource);
|
|
1675
1876
|
}
|
|
1676
|
-
|
|
1677
1877
|
/**
|
|
1678
|
-
*
|
|
1878
|
+
* @deprecated - use {@link getResource}
|
|
1679
1879
|
*/
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
function NetworkError(url) {
|
|
1683
|
-
var _this = _super.call(this) || this;
|
|
1684
|
-
_this.name = 'NetworkError';
|
|
1685
|
-
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1686
|
-
_this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
|
|
1687
|
-
return _this;
|
|
1688
|
-
}
|
|
1689
|
-
return NetworkError;
|
|
1690
|
-
}(Error));
|
|
1691
|
-
|
|
1692
|
-
var loadData;
|
|
1693
|
-
// @ts-ignore
|
|
1694
|
-
{
|
|
1695
|
-
loadData = function (url, callback, options, error, onCancel) {
|
|
1696
|
-
if (options === void 0) { options = {}; }
|
|
1697
|
-
options.method = options.method || 'GET';
|
|
1698
|
-
var xhr = new XMLHttpRequest();
|
|
1699
|
-
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1700
|
-
if (options.responseType === 'blob') {
|
|
1701
|
-
xhr.responseType = options.responseType;
|
|
1702
|
-
}
|
|
1703
|
-
var getResponseText = function () {
|
|
1704
|
-
try {
|
|
1705
|
-
return JSON.parse(xhr.responseText);
|
|
1706
|
-
}
|
|
1707
|
-
catch (er) {
|
|
1708
|
-
return xhr.responseText;
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
var processingResponse = function (forError) {
|
|
1712
|
-
if (forError === void 0) { forError = false; }
|
|
1713
|
-
var cb = forError ? error : callback;
|
|
1714
|
-
if (options.responseType === 'blob') {
|
|
1715
|
-
cb(xhr.response);
|
|
1716
|
-
}
|
|
1717
|
-
else {
|
|
1718
|
-
if (xhr.responseText) {
|
|
1719
|
-
cb(getResponseText());
|
|
1720
|
-
}
|
|
1721
|
-
else {
|
|
1722
|
-
error({ message: '' });
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
};
|
|
1726
|
-
xhr.onload = function () {
|
|
1727
|
-
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1728
|
-
error(new NgwError(getResponseText()));
|
|
1729
|
-
}
|
|
1730
|
-
processingResponse();
|
|
1731
|
-
};
|
|
1732
|
-
// xhr.onreadystatechange = () => {
|
|
1733
|
-
// if (
|
|
1734
|
-
// (xhr.readyState === 4 && xhr.status === 200) ||
|
|
1735
|
-
// (xhr.readyState === 3 && xhr.status === 201)
|
|
1736
|
-
// ) {
|
|
1737
|
-
// processingResponse();
|
|
1738
|
-
// } else if (xhr.readyState === 3 && xhr.status === 400) {
|
|
1739
|
-
// processingResponse();
|
|
1740
|
-
// } else if (xhr.readyState === 4 && xhr.status === 500) {
|
|
1741
|
-
// processingResponse();
|
|
1742
|
-
// } else if (xhr.readyState === 4 && xhr.status === 401) {
|
|
1743
|
-
// error(xhr.statusText);
|
|
1744
|
-
// } else if (xhr.readyState === 4) {
|
|
1745
|
-
// error('request error');
|
|
1746
|
-
// }
|
|
1747
|
-
// };
|
|
1748
|
-
xhr.onerror = function (er) {
|
|
1749
|
-
if (xhr.status === 0) {
|
|
1750
|
-
error(new NetworkError(url));
|
|
1751
|
-
}
|
|
1752
|
-
else {
|
|
1753
|
-
error(er);
|
|
1754
|
-
}
|
|
1755
|
-
};
|
|
1756
|
-
xhr.upload.onprogress = function (e) {
|
|
1757
|
-
if (e.lengthComputable) {
|
|
1758
|
-
var percentComplete = (e.loaded / e.total) * 100;
|
|
1759
|
-
if (options.onProgress) {
|
|
1760
|
-
options.onProgress(percentComplete, e);
|
|
1761
|
-
}
|
|
1762
|
-
// console.log(percentComplete + '% uploaded');
|
|
1763
|
-
}
|
|
1764
|
-
};
|
|
1765
|
-
var headers = options.headers;
|
|
1766
|
-
if (headers) {
|
|
1767
|
-
for (var h in headers) {
|
|
1768
|
-
var header = headers[h];
|
|
1769
|
-
if (typeof header === 'string') {
|
|
1770
|
-
xhr.setRequestHeader(h, header);
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
if (options.withCredentials !== undefined) {
|
|
1775
|
-
xhr.withCredentials = options.withCredentials;
|
|
1776
|
-
}
|
|
1777
|
-
var data;
|
|
1778
|
-
if (options.file) {
|
|
1779
|
-
data = new FormData();
|
|
1780
|
-
data.append('file', options.file);
|
|
1781
|
-
if (options.data) {
|
|
1782
|
-
for (var d in options.data) {
|
|
1783
|
-
data.append(d, data[d]);
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
else {
|
|
1788
|
-
data = options.data
|
|
1789
|
-
? typeof options.data === 'string'
|
|
1790
|
-
? options.data
|
|
1791
|
-
: JSON.stringify(options.data)
|
|
1792
|
-
: null;
|
|
1793
|
-
}
|
|
1794
|
-
if (onCancel) {
|
|
1795
|
-
onCancel(function () {
|
|
1796
|
-
xhr.abort();
|
|
1797
|
-
});
|
|
1798
|
-
}
|
|
1799
|
-
xhr.send(data);
|
|
1800
|
-
};
|
|
1880
|
+
getResourceByKeyname(keyname) {
|
|
1881
|
+
return this.resources.getOne(keyname);
|
|
1801
1882
|
}
|
|
1802
|
-
|
|
1803
|
-
var ID = 0;
|
|
1804
|
-
var NgwConnector$1 = /** @class */ (function () {
|
|
1805
|
-
function NgwConnector(options) {
|
|
1806
|
-
this.options = options;
|
|
1807
|
-
this.id = ID++;
|
|
1808
|
-
this.emitter = new events.exports.EventEmitter();
|
|
1809
|
-
this.routeStr = '/api/component/pyramid/route';
|
|
1810
|
-
this.activeRequests = [];
|
|
1811
|
-
var exist = findConnector(options);
|
|
1812
|
-
if (exist) {
|
|
1813
|
-
return exist;
|
|
1814
|
-
}
|
|
1815
|
-
else {
|
|
1816
|
-
if (this.options.route) {
|
|
1817
|
-
this.routeStr = this.options.route;
|
|
1818
|
-
}
|
|
1819
|
-
if (this.options.requestTransform) {
|
|
1820
|
-
this.requestTransform = this.options.requestTransform;
|
|
1821
|
-
}
|
|
1822
|
-
this.resources = new ResourcesControl(this);
|
|
1823
|
-
addConnector(this);
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
NgwConnector.create = function (options) {
|
|
1827
|
-
return new this(options);
|
|
1828
|
-
};
|
|
1829
|
-
NgwConnector.prototype.setRequestTransform = function (requestTransform) {
|
|
1830
|
-
this.requestTransform = requestTransform;
|
|
1831
|
-
};
|
|
1832
|
-
/**
|
|
1833
|
-
* Fast way to specify the connection address to NextGIS Web.
|
|
1834
|
-
* The current connection will be severed.
|
|
1835
|
-
* @param baseUrl - NGW url
|
|
1836
|
-
*/
|
|
1837
|
-
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
1838
|
-
this.logout();
|
|
1839
|
-
this.options.baseUrl = baseUrl;
|
|
1840
|
-
addConnector(this);
|
|
1841
|
-
};
|
|
1842
|
-
/**
|
|
1843
|
-
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1844
|
-
* @remarks
|
|
1845
|
-
* This method need not be called manually as it is used when forming a request in {@link apiRequest | apiRequest}.
|
|
1846
|
-
* Can be used to check connection.
|
|
1847
|
-
* @example
|
|
1848
|
-
* ```javascript
|
|
1849
|
-
* const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
|
|
1850
|
-
* connector.connect()
|
|
1851
|
-
* .then(() => console.log('Ok'))
|
|
1852
|
-
* .catch((er) => console.log('Connection problem', er));
|
|
1853
|
-
* ```
|
|
1854
|
-
*/
|
|
1855
|
-
NgwConnector.prototype.connect = function () {
|
|
1856
|
-
var _this = this;
|
|
1857
|
-
var cache = new Cache();
|
|
1858
|
-
var auth = this.options.auth;
|
|
1859
|
-
var makeConnect = function () {
|
|
1860
|
-
return new CancelablePromise(function (resolve, reject) {
|
|
1861
|
-
var makeQuery = function () {
|
|
1862
|
-
return _this.makeQuery(_this.routeStr, {}, {})
|
|
1863
|
-
.then(function (route) {
|
|
1864
|
-
resolve(route);
|
|
1865
|
-
})
|
|
1866
|
-
.catch(function (er) {
|
|
1867
|
-
reject(er);
|
|
1868
|
-
});
|
|
1869
|
-
};
|
|
1870
|
-
if (auth) {
|
|
1871
|
-
var login = auth.login, password = auth.password;
|
|
1872
|
-
if (login && password) {
|
|
1873
|
-
return _this._login({ login: login, password: password })
|
|
1874
|
-
.then(function () {
|
|
1875
|
-
return makeQuery();
|
|
1876
|
-
})
|
|
1877
|
-
.catch(function (er) { return reject(er); });
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
return makeQuery();
|
|
1881
|
-
});
|
|
1882
|
-
};
|
|
1883
|
-
return cache.add('route', makeConnect, {
|
|
1884
|
-
id: this.id,
|
|
1885
|
-
auth: auth,
|
|
1886
|
-
baseUrl: this.options.baseUrl,
|
|
1887
|
-
});
|
|
1888
|
-
};
|
|
1889
|
-
/**
|
|
1890
|
-
* Quick way to change NextGIS Web user.
|
|
1891
|
-
* @param credentials - New user credentials
|
|
1892
|
-
*/
|
|
1893
|
-
NgwConnector.prototype.login = function (credentials, options) {
|
|
1894
|
-
this.logout();
|
|
1895
|
-
addConnector(this);
|
|
1896
|
-
return this._login(credentials, options);
|
|
1897
|
-
};
|
|
1898
|
-
/**
|
|
1899
|
-
* Disconnecting a user. Aborting all current requests
|
|
1900
|
-
*/
|
|
1901
|
-
NgwConnector.prototype.logout = function () {
|
|
1902
|
-
this.abort();
|
|
1903
|
-
removeConnector(this);
|
|
1904
|
-
this.options.auth = undefined;
|
|
1905
|
-
this.user = undefined;
|
|
1906
|
-
this.emitter.emit('logout');
|
|
1907
|
-
this.resources.cache.clean();
|
|
1908
|
-
};
|
|
1909
|
-
NgwConnector.prototype.getUserInfo = function (credentials, options) {
|
|
1910
|
-
if (this.user && this.user.id) {
|
|
1911
|
-
return CancelablePromise.resolve(this.user);
|
|
1912
|
-
}
|
|
1913
|
-
if (credentials) {
|
|
1914
|
-
this.options.auth = credentials;
|
|
1915
|
-
}
|
|
1916
|
-
var options_ = __assign({ headers: this.getAuthorizationHeaders(credentials) }, options);
|
|
1917
|
-
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
1918
|
-
return this.makeQuery('/api/component/auth/current_user', {}, options_);
|
|
1919
|
-
};
|
|
1920
|
-
/**
|
|
1921
|
-
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1922
|
-
*/
|
|
1923
|
-
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
1924
|
-
var client = this.makeClientId(credentials);
|
|
1925
|
-
if (client) {
|
|
1926
|
-
return {
|
|
1927
|
-
Authorization: 'Basic ' + client,
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
};
|
|
1931
|
-
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
1932
|
-
credentials = credentials || this.options.auth;
|
|
1933
|
-
if (credentials) {
|
|
1934
|
-
var login = credentials.login, password = credentials.password;
|
|
1935
|
-
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
1936
|
-
// @ts-ignore
|
|
1937
|
-
{
|
|
1938
|
-
return window.btoa(str);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
};
|
|
1942
|
-
/** Stop all api requests */
|
|
1943
|
-
NgwConnector.prototype.abort = function () {
|
|
1944
|
-
for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
|
|
1945
|
-
var req = _a[_i];
|
|
1946
|
-
req.cancel();
|
|
1947
|
-
}
|
|
1948
|
-
this.activeRequests = [];
|
|
1949
|
-
};
|
|
1950
|
-
NgwConnector.prototype.getActiveApiRequests = function () {
|
|
1951
|
-
return __spreadArray([], this.activeRequests, true);
|
|
1952
|
-
};
|
|
1953
|
-
/**
|
|
1954
|
-
* Send request to NGW api router.
|
|
1955
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1956
|
-
* @param params - Request item params or query params
|
|
1957
|
-
* @param requestOptions - Request options
|
|
1958
|
-
*
|
|
1959
|
-
* @example
|
|
1960
|
-
* ```javascript
|
|
1961
|
-
*
|
|
1962
|
-
* // there is such an NGW route item
|
|
1963
|
-
* // "feature_layer.feature.item": [
|
|
1964
|
-
* // "/api/resource/{0}/feature/{1}",
|
|
1965
|
-
* // "id",
|
|
1966
|
-
* // "fid"
|
|
1967
|
-
* // ],
|
|
1968
|
-
*
|
|
1969
|
-
* const connector = new NgwConnector({ baseUrl: 'https://example.nextgis.com' });
|
|
1970
|
-
* connector.apiRequest('feature_layer.feature.item', {
|
|
1971
|
-
* // request params for {0} and {1}
|
|
1972
|
-
* 'id': 2011,
|
|
1973
|
-
* 'fid': 101,
|
|
1974
|
-
* // query params
|
|
1975
|
-
* 'srs': 4326,
|
|
1976
|
-
* 'geom_format': 'geojson',
|
|
1977
|
-
* }, { method: 'GET' });
|
|
1978
|
-
* // send get-request to 'https://example.nextgis.com/api/resource/2011/feature/101?srs=4326&geom_format=geojson'
|
|
1979
|
-
*
|
|
1980
|
-
* ```
|
|
1981
|
-
*/
|
|
1982
|
-
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
1983
|
-
var _this = this;
|
|
1984
|
-
var _a, _b;
|
|
1985
|
-
if (params_ === void 0) { params_ = {}; }
|
|
1986
|
-
if (requestOptions === void 0) { requestOptions = {}; }
|
|
1987
|
-
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
1988
|
-
params_ = (_a = requestOptions.params) !== null && _a !== void 0 ? _a : params_;
|
|
1989
|
-
var params = objectRemoveEmpty(params_);
|
|
1990
|
-
var makeApiRequest = function () {
|
|
1991
|
-
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
1992
|
-
};
|
|
1993
|
-
if (requestOptions.cache && method === 'GET') {
|
|
1994
|
-
var cache = new Cache();
|
|
1995
|
-
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
1996
|
-
headers: headers,
|
|
1997
|
-
withCredentials: withCredentials,
|
|
1998
|
-
responseType: responseType,
|
|
1999
|
-
baseUrl: this.options.baseUrl,
|
|
2000
|
-
userId: (_b = this.user) === null || _b === void 0 ? void 0 : _b.id,
|
|
2001
|
-
})));
|
|
2002
|
-
}
|
|
2003
|
-
return makeApiRequest();
|
|
2004
|
-
};
|
|
2005
|
-
/**
|
|
2006
|
-
* Shortcut method for send POST request to NGW.
|
|
2007
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2008
|
-
* @param options - Request options
|
|
2009
|
-
* @param params - Request item params or query params
|
|
2010
|
-
*
|
|
2011
|
-
* @example
|
|
2012
|
-
* ```javascript
|
|
2013
|
-
* connector.post('resource.collection', { data: POST_PAYLOAD })
|
|
2014
|
-
* .then((newResource) => console.log(newResource))
|
|
2015
|
-
* .catch((error) => console.warn(error));
|
|
2016
|
-
* ```
|
|
2017
|
-
*/
|
|
2018
|
-
NgwConnector.prototype.post = function (name, options, params) {
|
|
2019
|
-
options = options || {};
|
|
2020
|
-
options.method = 'POST';
|
|
2021
|
-
return this.apiRequest(name, params, options);
|
|
2022
|
-
};
|
|
2023
|
-
/**
|
|
2024
|
-
* Shortcut method for send GET request to NGW.
|
|
2025
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2026
|
-
* @param options - Request options
|
|
2027
|
-
* @param params - Request item params or query params
|
|
2028
|
-
*/
|
|
2029
|
-
NgwConnector.prototype.get = function (name, options, params) {
|
|
2030
|
-
options = options || {};
|
|
2031
|
-
options.method = 'GET';
|
|
2032
|
-
return this.apiRequest(name, params, options);
|
|
2033
|
-
};
|
|
2034
|
-
/**
|
|
2035
|
-
* Shortcut method for send PATCH request to NGW.
|
|
2036
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2037
|
-
* @param options - Request options
|
|
2038
|
-
* @param params - Request item params or query params
|
|
2039
|
-
*/
|
|
2040
|
-
NgwConnector.prototype.patch = function (name, options, params) {
|
|
2041
|
-
options = options || {};
|
|
2042
|
-
options.method = 'PATCH';
|
|
2043
|
-
return this.apiRequest(name, params, options);
|
|
2044
|
-
};
|
|
2045
|
-
/**
|
|
2046
|
-
* Shortcut method for send PUT request to NGW.
|
|
2047
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2048
|
-
* @param options - Request options
|
|
2049
|
-
* @param params - Request item params or query params
|
|
2050
|
-
*/
|
|
2051
|
-
NgwConnector.prototype.put = function (name, options, params) {
|
|
2052
|
-
options = options || {};
|
|
2053
|
-
options.method = 'PUT';
|
|
2054
|
-
return this.apiRequest(name, params, options);
|
|
2055
|
-
};
|
|
2056
|
-
/**
|
|
2057
|
-
* Shortcut method for send DELETE request to NGW.
|
|
2058
|
-
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
2059
|
-
* @param options - Request options
|
|
2060
|
-
* @param params - Request item params or query params
|
|
2061
|
-
*/
|
|
2062
|
-
NgwConnector.prototype.delete = function (name, options, params) {
|
|
2063
|
-
options = options || {};
|
|
2064
|
-
options.method = 'DELETE';
|
|
2065
|
-
return this.apiRequest(name, params, options);
|
|
2066
|
-
};
|
|
2067
|
-
/**
|
|
2068
|
-
* Send request to NGW.
|
|
2069
|
-
* @param url - URL address to NGW
|
|
2070
|
-
* @param params - Query params
|
|
2071
|
-
* @param options - Request options
|
|
2072
|
-
*/
|
|
2073
|
-
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
2074
|
-
if (options === void 0) { options = {}; }
|
|
2075
|
-
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
2076
|
-
if (url) {
|
|
2077
|
-
if (params) {
|
|
2078
|
-
url = template(url, params);
|
|
2079
|
-
}
|
|
2080
|
-
url = encodeURI(fixUrlStr(url));
|
|
2081
|
-
return this._loadData(url, options);
|
|
2082
|
-
}
|
|
2083
|
-
else {
|
|
2084
|
-
throw new Error('Empty `url` not allowed');
|
|
2085
|
-
}
|
|
2086
|
-
};
|
|
2087
|
-
// -------------------------------------------------------------------------
|
|
2088
|
-
// Resource Methods
|
|
2089
|
-
// -------------------------------------------------------------------------
|
|
2090
|
-
/**
|
|
2091
|
-
* {@link ResourcesControl.getOne}
|
|
2092
|
-
*/
|
|
2093
|
-
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
2094
|
-
return this.resources.getOne(resource, requestOptions);
|
|
2095
|
-
};
|
|
2096
|
-
/**
|
|
2097
|
-
* {@link ResourcesControl.getOneOrFail}
|
|
2098
|
-
*/
|
|
2099
|
-
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
2100
|
-
return this.resources.getOneOrFail(resource, requestOptions);
|
|
2101
|
-
};
|
|
2102
|
-
/**
|
|
2103
|
-
* @deprecated - use {@link getResource}
|
|
2104
|
-
*/
|
|
2105
|
-
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
2106
|
-
return this.resources.getOne(resource);
|
|
2107
|
-
};
|
|
2108
|
-
/**
|
|
2109
|
-
* @deprecated - use {@link getResource}
|
|
2110
|
-
*/
|
|
2111
|
-
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
2112
|
-
return this.resources.getOne(keyname);
|
|
2113
|
-
};
|
|
2114
|
-
/**
|
|
2115
|
-
* @deprecated - use {@link getResource}
|
|
2116
|
-
*/
|
|
2117
|
-
NgwConnector.prototype.getResourceById = function (id) {
|
|
2118
|
-
return this.resources.getOne(id);
|
|
2119
|
-
};
|
|
2120
|
-
/**
|
|
2121
|
-
* {@link ResourcesControl.getId}
|
|
2122
|
-
*/
|
|
2123
|
-
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
2124
|
-
return this.resources.getId(resource, requestOptions);
|
|
2125
|
-
};
|
|
2126
|
-
/**
|
|
2127
|
-
* {@link ResourcesControl.getIdOrFail}
|
|
2128
|
-
*/
|
|
2129
|
-
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
2130
|
-
return this.resources.getIdOrFail(resource, requestOptions);
|
|
2131
|
-
};
|
|
2132
|
-
/**
|
|
2133
|
-
* {@link ResourcesControl.getMany}
|
|
2134
|
-
*/
|
|
2135
|
-
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
2136
|
-
return this.resources.getMany(resource, requestOptions);
|
|
2137
|
-
};
|
|
2138
|
-
/**
|
|
2139
|
-
* {@link ResourcesControl.getParent}
|
|
2140
|
-
*/
|
|
2141
|
-
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
2142
|
-
return this.resources.getParent(resource, requestOptions);
|
|
2143
|
-
};
|
|
2144
|
-
/**
|
|
2145
|
-
* {@link ResourcesControl.getChildrenOf}
|
|
2146
|
-
*/
|
|
2147
|
-
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
2148
|
-
return this.resources.getChildrenOf(resource, requestOptions);
|
|
2149
|
-
};
|
|
2150
|
-
/**
|
|
2151
|
-
* {@link ResourcesControl.update}
|
|
2152
|
-
*/
|
|
2153
|
-
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
2154
|
-
return this.resources.update(resource, data);
|
|
2155
|
-
};
|
|
2156
|
-
/**
|
|
2157
|
-
* {@link ResourcesControl.delete}
|
|
2158
|
-
*/
|
|
2159
|
-
NgwConnector.prototype.deleteResource = function (resource) {
|
|
2160
|
-
return this.resources.delete(resource);
|
|
2161
|
-
};
|
|
2162
|
-
/**
|
|
2163
|
-
* @internal
|
|
2164
|
-
*/
|
|
2165
|
-
NgwConnector.prototype._loadData = function (url, options) {
|
|
2166
|
-
var _this = this;
|
|
2167
|
-
options.responseType = options.responseType || 'json';
|
|
2168
|
-
var request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2169
|
-
if (_this.user) {
|
|
2170
|
-
options = options || {};
|
|
2171
|
-
// options.withCredentials = true;
|
|
2172
|
-
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
2173
|
-
}
|
|
2174
|
-
if (_this.requestTransform) {
|
|
2175
|
-
var _a = _this.requestTransform(url, options), transUrl = _a[0], transOptions = _a[1];
|
|
2176
|
-
url = transUrl;
|
|
2177
|
-
options = transOptions;
|
|
2178
|
-
}
|
|
2179
|
-
loadData(url, resolve, options, reject, onCancel);
|
|
2180
|
-
})
|
|
2181
|
-
.then(function (resp) {
|
|
2182
|
-
_this._cleanActiveRequests(request);
|
|
2183
|
-
return resp;
|
|
2184
|
-
})
|
|
2185
|
-
.catch(function (httpError) {
|
|
2186
|
-
_this._cleanActiveRequests(request);
|
|
2187
|
-
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
2188
|
-
else {
|
|
2189
|
-
// @ts-ignore
|
|
2190
|
-
{
|
|
2191
|
-
console.warn('DEV WARN', httpError);
|
|
2192
|
-
}
|
|
2193
|
-
var er = _this._handleHttpError(httpError);
|
|
2194
|
-
if (er) {
|
|
2195
|
-
throw er;
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
});
|
|
2199
|
-
if (options.signal &&
|
|
2200
|
-
typeof options.signal.addEventListener === 'function') {
|
|
2201
|
-
options.signal.addEventListener('abort', function () {
|
|
2202
|
-
request.cancel();
|
|
2203
|
-
_this._cleanActiveRequests(request);
|
|
2204
|
-
});
|
|
2205
|
-
}
|
|
2206
|
-
this.activeRequests.push(request);
|
|
2207
|
-
return request;
|
|
2208
|
-
};
|
|
2209
|
-
NgwConnector.prototype._login = function (credentials, options) {
|
|
2210
|
-
var _this = this;
|
|
2211
|
-
return this.getUserInfo(credentials, options)
|
|
2212
|
-
.then(function (data) {
|
|
2213
|
-
_this.user = data;
|
|
2214
|
-
_this.emitter.emit('login', data);
|
|
2215
|
-
return data;
|
|
2216
|
-
})
|
|
2217
|
-
.catch(function (er) {
|
|
2218
|
-
_this.emitter.emit('login:error', er);
|
|
2219
|
-
throw er;
|
|
2220
|
-
});
|
|
2221
|
-
};
|
|
2222
|
-
NgwConnector.prototype._cleanActiveRequests = function (request) {
|
|
2223
|
-
var activeRequestIndex = this.activeRequests.indexOf(request);
|
|
2224
|
-
if (activeRequestIndex !== -1) {
|
|
2225
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
2226
|
-
}
|
|
2227
|
-
};
|
|
2228
|
-
NgwConnector.prototype._handleHttpError = function (er) {
|
|
2229
|
-
if (er) {
|
|
2230
|
-
if (er instanceof NgwError) {
|
|
2231
|
-
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
2232
|
-
throw new ResourceNotFoundError(er);
|
|
2233
|
-
}
|
|
2234
|
-
else if (er.exception === 'nextgisweb.core.exception.InsufficientPermissions') {
|
|
2235
|
-
throw new InsufficientPermissionsError(er);
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
return er;
|
|
2240
|
-
};
|
|
2241
|
-
NgwConnector.errors = {
|
|
2242
|
-
NgwError: NgwError,
|
|
2243
|
-
ResourceNotFoundError: ResourceNotFoundError,
|
|
2244
|
-
};
|
|
2245
|
-
return NgwConnector;
|
|
2246
|
-
}());
|
|
2247
|
-
|
|
2248
1883
|
/**
|
|
2249
|
-
*
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
* @
|
|
1884
|
+
* @deprecated - use {@link getResource}
|
|
1885
|
+
*/
|
|
1886
|
+
getResourceById(id) {
|
|
1887
|
+
return this.resources.getOne(id);
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* {@link ResourcesControl.getId}
|
|
1891
|
+
*/
|
|
1892
|
+
getResourceId(resource, requestOptions) {
|
|
1893
|
+
return this.resources.getId(resource, requestOptions);
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* {@link ResourcesControl.getIdOrFail}
|
|
1897
|
+
*/
|
|
1898
|
+
getResourceIdOrFail(resource, requestOptions) {
|
|
1899
|
+
return this.resources.getIdOrFail(resource, requestOptions);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* {@link ResourcesControl.getMany}
|
|
1903
|
+
*/
|
|
1904
|
+
getResourcesBy(resource, requestOptions) {
|
|
1905
|
+
return this.resources.getMany(resource, requestOptions);
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* {@link ResourcesControl.getParent}
|
|
1909
|
+
*/
|
|
1910
|
+
getResourceParent(resource, requestOptions) {
|
|
1911
|
+
return this.resources.getParent(resource, requestOptions);
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* {@link ResourcesControl.getChildrenOf}
|
|
1915
|
+
*/
|
|
1916
|
+
getResourceChildren(resource, requestOptions) {
|
|
1917
|
+
return this.resources.getChildrenOf(resource, requestOptions);
|
|
1918
|
+
}
|
|
1919
|
+
/**
|
|
1920
|
+
* {@link ResourcesControl.update}
|
|
1921
|
+
*/
|
|
1922
|
+
updateResource(resource, data) {
|
|
1923
|
+
return this.resources.update(resource, data);
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* {@link ResourcesControl.delete}
|
|
2256
1927
|
*/
|
|
2257
|
-
|
|
1928
|
+
deleteResource(resource) {
|
|
1929
|
+
return this.resources.delete(resource);
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* @internal
|
|
1933
|
+
*/
|
|
1934
|
+
_loadData(url, options) {
|
|
1935
|
+
options.responseType = options.responseType || "json";
|
|
1936
|
+
if (options.signal && options.signal.aborted) {
|
|
1937
|
+
return CancelablePromise.reject(new CancelablePromise.CancelError());
|
|
1938
|
+
}
|
|
1939
|
+
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1940
|
+
if (this.user) {
|
|
1941
|
+
options = options || {};
|
|
1942
|
+
options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
|
|
1943
|
+
}
|
|
1944
|
+
if (this.requestTransform) {
|
|
1945
|
+
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
1946
|
+
url = transUrl;
|
|
1947
|
+
options = transOptions;
|
|
1948
|
+
}
|
|
1949
|
+
loadData(url, resolve, options, reject, onCancel);
|
|
1950
|
+
}).then((resp) => {
|
|
1951
|
+
this._cleanActiveRequests(request);
|
|
1952
|
+
return resp;
|
|
1953
|
+
}).catch((httpError) => {
|
|
1954
|
+
this._cleanActiveRequests(request);
|
|
1955
|
+
if (httpError instanceof CancelablePromise.CancelError) ; else {
|
|
1956
|
+
{
|
|
1957
|
+
console.warn("DEV WARN", httpError);
|
|
1958
|
+
}
|
|
1959
|
+
const er = this._handleHttpError(httpError);
|
|
1960
|
+
if (er) {
|
|
1961
|
+
throw er;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
if (options.signal && typeof options.signal.addEventListener === "function") {
|
|
1966
|
+
options.signal.addEventListener("abort", () => {
|
|
1967
|
+
request.cancel();
|
|
1968
|
+
this._cleanActiveRequests(request);
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
this.activeRequests.push(request);
|
|
1972
|
+
return request;
|
|
1973
|
+
}
|
|
1974
|
+
_login(credentials, options) {
|
|
1975
|
+
return this.getUserInfo(credentials, options).then((data) => {
|
|
1976
|
+
this.user = data;
|
|
1977
|
+
this.emitter.emit("login", data);
|
|
1978
|
+
return data;
|
|
1979
|
+
}).catch((er) => {
|
|
1980
|
+
this.emitter.emit("login:error", er);
|
|
1981
|
+
throw er;
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
_cleanActiveRequests(request) {
|
|
1985
|
+
const activeRequestIndex = this.activeRequests.indexOf(request);
|
|
1986
|
+
if (activeRequestIndex !== -1) {
|
|
1987
|
+
this.activeRequests.splice(activeRequestIndex, 1);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
_handleHttpError(er) {
|
|
1991
|
+
if (er) {
|
|
1992
|
+
if (er instanceof NgwError) {
|
|
1993
|
+
if (er.exception === "nextgisweb.resource.exception.ResourceNotFound") {
|
|
1994
|
+
throw new ResourceNotFoundError(er);
|
|
1995
|
+
} else if (er.exception === "nextgisweb.core.exception.InsufficientPermissions") {
|
|
1996
|
+
throw new InsufficientPermissionsError(er);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
return er;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
__publicField(NgwConnector, "errors", {
|
|
2004
|
+
NgwError,
|
|
2005
|
+
ResourceNotFoundError
|
|
2006
|
+
});
|
|
2258
2007
|
|
|
2259
|
-
|
|
2008
|
+
return NgwConnector;
|
|
2260
2009
|
|
|
2261
2010
|
})();
|
|
2262
2011
|
//# sourceMappingURL=ngw-connector.global.js.map
|