@adminide-stack/core 7.0.3-alpha.21 → 7.0.3-alpha.25

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.
Files changed (79) hide show
  1. package/lib/constants/types.js +13 -13
  2. package/lib/constants/types.js.map +1 -1
  3. package/lib/constants/urls.js +3 -3
  4. package/lib/constants/urls.js.map +1 -1
  5. package/lib/core/configurations/configuration.js +444 -546
  6. package/lib/core/configurations/configuration.js.map +1 -1
  7. package/lib/core/configurations/events/ConfigurationChangeEvent.js +49 -52
  8. package/lib/core/configurations/events/ConfigurationChangeEvent.js.map +1 -1
  9. package/lib/core/configurations/helpers/configuration.js +149 -138
  10. package/lib/core/configurations/helpers/configuration.js.map +1 -1
  11. package/lib/core/configurations/models/ConfigurationModel.js +190 -186
  12. package/lib/core/configurations/models/ConfigurationModel.js.map +1 -1
  13. package/lib/core/disposable.js +67 -66
  14. package/lib/core/disposable.js.map +1 -1
  15. package/lib/core/event.js +235 -239
  16. package/lib/core/event.js.map +1 -1
  17. package/lib/core/organization/configuration.js +15 -15
  18. package/lib/core/organization/configuration.js.map +1 -1
  19. package/lib/core/organization/helpers/organization-helpers.js +14 -7
  20. package/lib/core/organization/helpers/organization-helpers.js.map +1 -1
  21. package/lib/core/organization/organization.js +113 -132
  22. package/lib/core/organization/organization.js.map +1 -1
  23. package/lib/core/path.js +158 -154
  24. package/lib/core/path.js.map +1 -1
  25. package/lib/enums/connection-status.js +4 -4
  26. package/lib/enums/connection-status.js.map +1 -1
  27. package/lib/enums/integration-configuration-status.js +3 -3
  28. package/lib/enums/integration-configuration-status.js.map +1 -1
  29. package/lib/enums/integrations-configuration-steps.js +6 -6
  30. package/lib/enums/integrations-configuration-steps.js.map +1 -1
  31. package/lib/enums/integrations-connection-names.js +10 -10
  32. package/lib/enums/integrations-connection-names.js.map +1 -1
  33. package/lib/enums/integrations.js +8 -8
  34. package/lib/enums/integrations.js.map +1 -1
  35. package/lib/enums/permissions.js +5 -5
  36. package/lib/enums/permissions.js.map +1 -1
  37. package/lib/enums/team-member-status.js +2 -2
  38. package/lib/enums/team-member-status.js.map +1 -1
  39. package/lib/errors/auth-error-messages.js +22 -22
  40. package/lib/errors/auth-error-messages.js.map +1 -1
  41. package/lib/errors/auth-error.js +5 -9
  42. package/lib/errors/auth-error.js.map +1 -1
  43. package/lib/interfaces/configuration/configuration.js +30 -30
  44. package/lib/interfaces/configuration/configuration.js.map +1 -1
  45. package/lib/interfaces/generated/generated-models.js +919 -15741
  46. package/lib/interfaces/generated/generated-models.js.map +1 -1
  47. package/lib/interfaces/organization/organization-context.js +17 -12
  48. package/lib/interfaces/organization/organization-context.js.map +1 -1
  49. package/lib/modules/account-api/enums/index.js +64 -64
  50. package/lib/modules/account-api/enums/index.js.map +1 -1
  51. package/lib/modules/billing-api/enums/index.js +18 -18
  52. package/lib/modules/billing-api/enums/index.js.map +1 -1
  53. package/lib/modules/inbox/enums/index.js +23 -23
  54. package/lib/modules/inbox/enums/index.js.map +1 -1
  55. package/lib/services/abstract-configuration.js +116 -113
  56. package/lib/services/abstract-configuration.js.map +1 -1
  57. package/lib/services/abstract-organization-context-service.js +93 -97
  58. package/lib/services/abstract-organization-context-service.js.map +1 -1
  59. package/lib/utils/configuration-utils.js +8 -8
  60. package/lib/utils/configuration-utils.js.map +1 -1
  61. package/lib/utils/date-utils.js +2 -2
  62. package/lib/utils/date-utils.js.map +1 -1
  63. package/lib/utils/flatten-utils.js +39 -35
  64. package/lib/utils/flatten-utils.js.map +1 -1
  65. package/lib/utils/generate-uri.js +15 -25
  66. package/lib/utils/generate-uri.js.map +1 -1
  67. package/lib/utils/generated-settings-id.js +4 -4
  68. package/lib/utils/generated-settings-id.js.map +1 -1
  69. package/lib/utils/omit-deep.js +7 -7
  70. package/lib/utils/omit-deep.js.map +1 -1
  71. package/lib/utils/roles-utils.js +2 -6
  72. package/lib/utils/roles-utils.js.map +1 -1
  73. package/lib/utils/uri.js +12 -10
  74. package/lib/utils/uri.js.map +1 -1
  75. package/lib/utils/utils.js +14 -19
  76. package/lib/utils/utils.js.map +1 -1
  77. package/lib/utils/validations.js +2 -2
  78. package/lib/utils/validations.js.map +1 -1
  79. package/package.json +2 -2
@@ -1,75 +1,76 @@
1
1
  import {Emitter}from'./event.js';/* tslint:disable */
2
2
  var Disposable;
3
3
  (function (Disposable) {
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- function is(arg) {
6
- return !!arg && typeof arg === 'object' && 'dispose' in arg && typeof arg['dispose'] === 'function';
7
- }
8
- Disposable.is = is;
9
- function create(func) {
10
- return {
11
- dispose: func
12
- };
13
- }
14
- Disposable.create = create;
15
- Disposable.NULL = create(() => {});
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ function is(arg) {
6
+ return !!arg && typeof arg === 'object' && 'dispose' in arg && typeof arg['dispose'] === 'function';
7
+ }
8
+ Disposable.is = is;
9
+ function create(func) {
10
+ return {
11
+ dispose: func
12
+ };
13
+ }
14
+ Disposable.create = create;
15
+ Disposable.NULL = create(() => { });
16
16
  })(Disposable || (Disposable = {}));
17
17
  class DisposableCollection {
18
- disposables = [];
19
- onDisposeEmitter = new Emitter();
20
- constructor(...toDispose) {
21
- toDispose.forEach(d => this.push(d));
22
- }
23
- /**
24
- * This event is fired only once
25
- * on first dispose of not empty collection.
26
- */
27
- get onDispose() {
28
- return this.onDisposeEmitter.event;
29
- }
30
- checkDisposed() {
31
- if (this.disposed && !this.disposingElements) {
32
- this.onDisposeEmitter.fire(undefined);
33
- this.onDisposeEmitter.dispose();
18
+ disposables = [];
19
+ onDisposeEmitter = new Emitter();
20
+ constructor(...toDispose) {
21
+ toDispose.forEach(d => this.push(d));
22
+ }
23
+ /**
24
+ * This event is fired only once
25
+ * on first dispose of not empty collection.
26
+ */
27
+ get onDispose() {
28
+ return this.onDisposeEmitter.event;
29
+ }
30
+ checkDisposed() {
31
+ if (this.disposed && !this.disposingElements) {
32
+ this.onDisposeEmitter.fire(undefined);
33
+ this.onDisposeEmitter.dispose();
34
+ }
35
+ }
36
+ get disposed() {
37
+ return this.disposables.length === 0;
38
+ }
39
+ disposingElements = false;
40
+ dispose() {
41
+ if (this.disposed || this.disposingElements) {
42
+ return;
43
+ }
44
+ this.disposingElements = true;
45
+ while (!this.disposed) {
46
+ try {
47
+ this.disposables.pop().dispose();
48
+ }
49
+ catch (e) {
50
+ console.error(e);
51
+ }
52
+ }
53
+ this.disposingElements = false;
54
+ this.checkDisposed();
34
55
  }
35
- }
36
- get disposed() {
37
- return this.disposables.length === 0;
38
- }
39
- disposingElements = false;
40
- dispose() {
41
- if (this.disposed || this.disposingElements) {
42
- return;
56
+ push(disposable) {
57
+ const disposables = this.disposables;
58
+ disposables.push(disposable);
59
+ const originalDispose = disposable.dispose.bind(disposable);
60
+ const toRemove = Disposable.create(() => {
61
+ const index = disposables.indexOf(disposable);
62
+ if (index !== -1) {
63
+ disposables.splice(index, 1);
64
+ }
65
+ this.checkDisposed();
66
+ });
67
+ disposable.dispose = () => {
68
+ toRemove.dispose();
69
+ originalDispose();
70
+ };
71
+ return toRemove;
43
72
  }
44
- this.disposingElements = true;
45
- while (!this.disposed) {
46
- try {
47
- this.disposables.pop().dispose();
48
- } catch (e) {
49
- console.error(e);
50
- }
73
+ pushAll(disposables) {
74
+ return disposables.map(disposable => this.push(disposable));
51
75
  }
52
- this.disposingElements = false;
53
- this.checkDisposed();
54
- }
55
- push(disposable) {
56
- const disposables = this.disposables;
57
- disposables.push(disposable);
58
- const originalDispose = disposable.dispose.bind(disposable);
59
- const toRemove = Disposable.create(() => {
60
- const index = disposables.indexOf(disposable);
61
- if (index !== -1) {
62
- disposables.splice(index, 1);
63
- }
64
- this.checkDisposed();
65
- });
66
- disposable.dispose = () => {
67
- toRemove.dispose();
68
- originalDispose();
69
- };
70
- return toRemove;
71
- }
72
- pushAll(disposables) {
73
- return disposables.map(disposable => this.push(disposable));
74
- }
75
76
  }export{Disposable,DisposableCollection};//# sourceMappingURL=disposable.js.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U,IAC7B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CACxB,CAAC;KACL;AAEJ"}
package/lib/core/event.js CHANGED
@@ -1,254 +1,250 @@
1
1
  /* tslint:disable */
2
2
  var Event;
3
3
  (function (Event) {
4
- const _disposable = {
5
- dispose() {}
6
- };
7
- Event.None = Object.assign(function () {
8
- return _disposable;
9
- }, {
10
- get maxListeners() {
11
- return 0;
12
- },
13
- set maxListeners(maxListeners) {}
14
- });
15
- /**
16
- * Given an event and a `map` function, returns another event which maps each element
17
- * through the mapping function.
18
- */
19
- function map(event, mapFunc) {
20
- return Object.assign((listener, thisArgs, disposables) => event(i => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
21
- maxListeners: 0
4
+ const _disposable = { dispose() { } };
5
+ Event.None = Object.assign(function () { return _disposable; }, {
6
+ get maxListeners() { return 0; },
7
+ set maxListeners(maxListeners) { }
22
8
  });
23
- }
24
- Event.map = map;
9
+ /**
10
+ * Given an event and a `map` function, returns another event which maps each element
11
+ * through the mapping function.
12
+ */
13
+ function map(event, mapFunc) {
14
+ return Object.assign((listener, thisArgs, disposables) => event(i => listener.call(thisArgs, mapFunc(i)), undefined, disposables), {
15
+ maxListeners: 0,
16
+ });
17
+ }
18
+ Event.map = map;
25
19
  })(Event || (Event = {}));
26
20
  class CallbackList {
27
- _callbacks;
28
- _contexts;
29
- get length() {
30
- return this._callbacks && this._callbacks.length || 0;
31
- }
32
- add(callback, context = undefined, bucket) {
33
- if (!this._callbacks) {
34
- this._callbacks = [];
35
- this._contexts = [];
36
- }
37
- this._callbacks.push(callback);
38
- this._contexts.push(context);
39
- if (Array.isArray(bucket)) {
40
- bucket.push({
41
- dispose: () => this.remove(callback, context)
42
- });
43
- }
44
- }
45
- remove(callback, context = undefined) {
46
- if (!this._callbacks) {
47
- return;
48
- }
49
- let foundCallbackWithDifferentContext = false;
50
- for (let i = 0; i < this._callbacks.length; i++) {
51
- if (this._callbacks[i] === callback) {
52
- if (this._contexts[i] === context) {
53
- // callback & context match => remove it
54
- this._callbacks.splice(i, 1);
55
- this._contexts.splice(i, 1);
56
- return;
57
- } else {
58
- foundCallbackWithDifferentContext = true;
59
- }
60
- }
61
- }
62
- if (foundCallbackWithDifferentContext) {
63
- throw new Error('When adding a listener with a context, you should remove it with the same context');
64
- }
65
- }
66
- // tslint:disable-next-line:typedef
67
- [Symbol.iterator]() {
68
- if (!this._callbacks) {
69
- return [][Symbol.iterator]();
70
- }
71
- const callbacks = this._callbacks.slice(0);
72
- const contexts = this._contexts.slice(0);
73
- return callbacks.map((callback, i) => (...args) => callback.apply(contexts[i], args))[Symbol.iterator]();
74
- }
75
- invoke(...args) {
76
- const ret = [];
77
- for (const callback of this) {
78
- try {
79
- ret.push(callback(...args));
80
- } catch (e) {
81
- console.error(e);
82
- }
83
- }
84
- return ret;
85
- }
86
- isEmpty() {
87
- return !this._callbacks || this._callbacks.length === 0;
88
- }
89
- dispose() {
90
- this._callbacks = undefined;
91
- this._contexts = undefined;
92
- }
93
- }
94
- class Emitter {
95
- _options;
96
- static LEAK_WARNING_THRESHHOLD = 175;
97
- static _noop = function () {};
98
- _event;
99
- _callbacks;
100
- _disposed = false;
101
- _leakingStacks;
102
- _leakWarnCountdown = 0;
103
- constructor(_options) {
104
- this._options = _options;
105
- }
106
- /**
107
- * For the public to allow to subscribe
108
- * to events from this Emitter
109
- */
110
- get event() {
111
- if (!this._event) {
112
- this._event = Object.assign((listener, thisArgs, disposables) => {
21
+ _callbacks;
22
+ _contexts;
23
+ get length() {
24
+ return this._callbacks && this._callbacks.length || 0;
25
+ }
26
+ add(callback, context = undefined, bucket) {
113
27
  if (!this._callbacks) {
114
- this._callbacks = new CallbackList();
28
+ this._callbacks = [];
29
+ this._contexts = [];
115
30
  }
116
- if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
117
- this._options.onFirstListenerAdd(this);
31
+ this._callbacks.push(callback);
32
+ this._contexts.push(context);
33
+ if (Array.isArray(bucket)) {
34
+ bucket.push({ dispose: () => this.remove(callback, context) });
35
+ }
36
+ }
37
+ remove(callback, context = undefined) {
38
+ if (!this._callbacks) {
39
+ return;
118
40
  }
119
- this._callbacks.add(listener, thisArgs);
120
- const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
121
- const result = {
122
- dispose: () => {
123
- if (removeMaxListenersCheck) {
124
- removeMaxListenersCheck();
41
+ let foundCallbackWithDifferentContext = false;
42
+ for (let i = 0; i < this._callbacks.length; i++) {
43
+ if (this._callbacks[i] === callback) {
44
+ if (this._contexts[i] === context) {
45
+ // callback & context match => remove it
46
+ this._callbacks.splice(i, 1);
47
+ this._contexts.splice(i, 1);
48
+ return;
49
+ }
50
+ else {
51
+ foundCallbackWithDifferentContext = true;
52
+ }
125
53
  }
126
- result.dispose = Emitter._noop;
127
- if (!this._disposed) {
128
- this._callbacks.remove(listener, thisArgs);
129
- result.dispose = Emitter._noop;
130
- if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
131
- this._options.onLastListenerRemove(this);
132
- }
54
+ }
55
+ if (foundCallbackWithDifferentContext) {
56
+ throw new Error('When adding a listener with a context, you should remove it with the same context');
57
+ }
58
+ }
59
+ // tslint:disable-next-line:typedef
60
+ [Symbol.iterator]() {
61
+ if (!this._callbacks) {
62
+ return [][Symbol.iterator]();
63
+ }
64
+ const callbacks = this._callbacks.slice(0);
65
+ const contexts = this._contexts.slice(0);
66
+ return callbacks.map((callback, i) => (...args) => callback.apply(contexts[i], args))[Symbol.iterator]();
67
+ }
68
+ invoke(...args) {
69
+ const ret = [];
70
+ for (const callback of this) {
71
+ try {
72
+ ret.push(callback(...args));
73
+ }
74
+ catch (e) {
75
+ console.error(e);
76
+ }
77
+ }
78
+ return ret;
79
+ }
80
+ isEmpty() {
81
+ return !this._callbacks || this._callbacks.length === 0;
82
+ }
83
+ dispose() {
84
+ this._callbacks = undefined;
85
+ this._contexts = undefined;
86
+ }
87
+ }
88
+ class Emitter {
89
+ _options;
90
+ static LEAK_WARNING_THRESHHOLD = 175;
91
+ static _noop = function () { };
92
+ _event;
93
+ _callbacks;
94
+ _disposed = false;
95
+ _leakingStacks;
96
+ _leakWarnCountdown = 0;
97
+ constructor(_options) {
98
+ this._options = _options;
99
+ }
100
+ /**
101
+ * For the public to allow to subscribe
102
+ * to events from this Emitter
103
+ */
104
+ get event() {
105
+ if (!this._event) {
106
+ this._event = Object.assign((listener, thisArgs, disposables) => {
107
+ if (!this._callbacks) {
108
+ this._callbacks = new CallbackList();
109
+ }
110
+ if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
111
+ this._options.onFirstListenerAdd(this);
112
+ }
113
+ this._callbacks.add(listener, thisArgs);
114
+ const removeMaxListenersCheck = this.checkMaxListeners(this._event.maxListeners);
115
+ const result = {
116
+ dispose: () => {
117
+ if (removeMaxListenersCheck) {
118
+ removeMaxListenersCheck();
119
+ }
120
+ result.dispose = Emitter._noop;
121
+ if (!this._disposed) {
122
+ this._callbacks.remove(listener, thisArgs);
123
+ result.dispose = Emitter._noop;
124
+ if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
125
+ this._options.onLastListenerRemove(this);
126
+ }
127
+ }
128
+ }
129
+ };
130
+ if (Array.isArray(disposables)) {
131
+ disposables.push(result);
132
+ }
133
+ return result;
134
+ }, {
135
+ maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
136
+ });
137
+ }
138
+ return this._event;
139
+ }
140
+ checkMaxListeners(maxListeners) {
141
+ if (maxListeners === 0 || !this._callbacks) {
142
+ return undefined;
143
+ }
144
+ const listenerCount = this._callbacks.length;
145
+ if (listenerCount <= maxListeners) {
146
+ return undefined;
147
+ }
148
+ const popStack = this.pushLeakingStack();
149
+ this._leakWarnCountdown -= 1;
150
+ if (this._leakWarnCountdown <= 0) {
151
+ // only warn on first exceed and then every time the limit
152
+ // is exceeded by 50% again
153
+ this._leakWarnCountdown = maxListeners * 0.5;
154
+ let topStack;
155
+ let topCount = 0;
156
+ this._leakingStacks.forEach((stackCount, stack) => {
157
+ if (!topStack || topCount < stackCount) {
158
+ topStack = stack;
159
+ topCount = stackCount;
160
+ }
161
+ });
162
+ // eslint-disable-next-line max-len
163
+ console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
164
+ console.warn(topStack);
165
+ }
166
+ return popStack;
167
+ }
168
+ pushLeakingStack() {
169
+ if (!this._leakingStacks) {
170
+ this._leakingStacks = new Map();
171
+ }
172
+ const stack = new Error().stack.split('\n').slice(3).join('\n');
173
+ const count = (this._leakingStacks.get(stack) || 0);
174
+ this._leakingStacks.set(stack, count + 1);
175
+ return () => this.popLeakingStack(stack);
176
+ }
177
+ popLeakingStack(stack) {
178
+ if (!this._leakingStacks) {
179
+ return;
180
+ }
181
+ const count = (this._leakingStacks.get(stack) || 0);
182
+ this._leakingStacks.set(stack, count - 1);
183
+ }
184
+ /**
185
+ * To be kept private to fire an event to
186
+ * subscribers
187
+ */
188
+ fire(event) {
189
+ if (this._callbacks) {
190
+ this._callbacks.invoke(event);
191
+ }
192
+ }
193
+ /**
194
+ * Process each listener one by one.
195
+ * Return `false` to stop iterating over the listeners, `true` to continue.
196
+ */
197
+ async sequence(processor) {
198
+ if (this._callbacks) {
199
+ for (const listener of this._callbacks) {
200
+ if (!await processor(listener)) {
201
+ break;
202
+ }
133
203
  }
134
- }
135
- };
136
- if (Array.isArray(disposables)) {
137
- disposables.push(result);
138
- }
139
- return result;
140
- }, {
141
- maxListeners: Emitter.LEAK_WARNING_THRESHHOLD
142
- });
143
- }
144
- return this._event;
145
- }
146
- checkMaxListeners(maxListeners) {
147
- if (maxListeners === 0 || !this._callbacks) {
148
- return undefined;
149
- }
150
- const listenerCount = this._callbacks.length;
151
- if (listenerCount <= maxListeners) {
152
- return undefined;
153
- }
154
- const popStack = this.pushLeakingStack();
155
- this._leakWarnCountdown -= 1;
156
- if (this._leakWarnCountdown <= 0) {
157
- // only warn on first exceed and then every time the limit
158
- // is exceeded by 50% again
159
- this._leakWarnCountdown = maxListeners * 0.5;
160
- let topStack;
161
- let topCount = 0;
162
- this._leakingStacks.forEach((stackCount, stack) => {
163
- if (!topStack || topCount < stackCount) {
164
- topStack = stack;
165
- topCount = stackCount;
166
- }
167
- });
168
- // eslint-disable-next-line max-len
169
- console.warn(`Possible Emitter memory leak detected. ${listenerCount} listeners added. Use event.maxListeners to increase the limit (${maxListeners}). MOST frequent listener (${topCount}):`);
170
- console.warn(topStack);
171
- }
172
- return popStack;
173
- }
174
- pushLeakingStack() {
175
- if (!this._leakingStacks) {
176
- this._leakingStacks = new Map();
177
- }
178
- const stack = new Error().stack.split('\n').slice(3).join('\n');
179
- const count = this._leakingStacks.get(stack) || 0;
180
- this._leakingStacks.set(stack, count + 1);
181
- return () => this.popLeakingStack(stack);
182
- }
183
- popLeakingStack(stack) {
184
- if (!this._leakingStacks) {
185
- return;
186
- }
187
- const count = this._leakingStacks.get(stack) || 0;
188
- this._leakingStacks.set(stack, count - 1);
189
- }
190
- /**
191
- * To be kept private to fire an event to
192
- * subscribers
193
- */
194
- fire(event) {
195
- if (this._callbacks) {
196
- this._callbacks.invoke(event);
197
- }
198
- }
199
- /**
200
- * Process each listener one by one.
201
- * Return `false` to stop iterating over the listeners, `true` to continue.
202
- */
203
- async sequence(processor) {
204
- if (this._callbacks) {
205
- for (const listener of this._callbacks) {
206
- if (!(await processor(listener))) {
207
- break;
208
- }
209
- }
210
- }
211
- }
212
- dispose() {
213
- if (this._leakingStacks) {
214
- this._leakingStacks.clear();
215
- this._leakingStacks = undefined;
216
- }
217
- if (this._callbacks) {
218
- this._callbacks.dispose();
219
- this._callbacks = undefined;
220
- }
221
- this._disposed = true;
222
- }
204
+ }
205
+ }
206
+ dispose() {
207
+ if (this._leakingStacks) {
208
+ this._leakingStacks.clear();
209
+ this._leakingStacks = undefined;
210
+ }
211
+ if (this._callbacks) {
212
+ this._callbacks.dispose();
213
+ this._callbacks = undefined;
214
+ }
215
+ this._disposed = true;
216
+ }
223
217
  }
224
218
  var WaitUntilEvent;
225
219
  (function (WaitUntilEvent) {
226
- async function fire(emitter, event, timeout = undefined) {
227
- const waitables = [];
228
- const asyncEvent = Object.assign(event, {
229
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- waitUntil: thenable => {
231
- if (Object.isFrozen(waitables)) {
232
- throw new Error('waitUntil cannot be called asynchronously.');
233
- }
234
- waitables.push(thenable);
235
- }
236
- });
237
- try {
238
- emitter.fire(asyncEvent);
239
- // Asynchronous calls to `waitUntil` should fail.
240
- Object.freeze(waitables);
241
- } finally {
242
- delete asyncEvent['waitUntil'];
243
- }
244
- if (!waitables.length) {
245
- return;
246
- }
247
- if (timeout !== undefined) {
248
- await Promise.race([Promise.all(waitables), new Promise(resolve => setTimeout(resolve, timeout))]);
249
- } else {
250
- await Promise.all(waitables);
251
- }
252
- }
253
- WaitUntilEvent.fire = fire;
220
+ async function fire(emitter, event, timeout = undefined) {
221
+ const waitables = [];
222
+ const asyncEvent = Object.assign(event, {
223
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
+ waitUntil: (thenable) => {
225
+ if (Object.isFrozen(waitables)) {
226
+ throw new Error('waitUntil cannot be called asynchronously.');
227
+ }
228
+ waitables.push(thenable);
229
+ }
230
+ });
231
+ try {
232
+ emitter.fire(asyncEvent);
233
+ // Asynchronous calls to `waitUntil` should fail.
234
+ Object.freeze(waitables);
235
+ }
236
+ finally {
237
+ delete asyncEvent['waitUntil'];
238
+ }
239
+ if (!waitables.length) {
240
+ return;
241
+ }
242
+ if (timeout !== undefined) {
243
+ await Promise.race([Promise.all(waitables), new Promise(resolve => setTimeout(resolve, timeout))]);
244
+ }
245
+ else {
246
+ await Promise.all(waitables);
247
+ }
248
+ }
249
+ WaitUntilEvent.fire = fire;
254
250
  })(WaitUntilEvent || (WaitUntilEvent = {}));export{Emitter,Event,WaitUntilEvent};//# sourceMappingURL=event.js.map