@firebase/component 0.6.9 → 0.6.10-canary.a97ac88db

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/dist/index.cjs.js CHANGED
@@ -2,20 +2,19 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib = require('tslib');
6
5
  var util = require('@firebase/util');
7
6
 
8
7
  /**
9
8
  * Component for service name T, e.g. `auth`, `auth-internal`
10
9
  */
11
- var Component = /** @class */ (function () {
10
+ class Component {
12
11
  /**
13
12
  *
14
13
  * @param name The public service name, e.g. app, auth, firestore, database
15
14
  * @param instanceFactory Service factory responsible for creating the public interface
16
15
  * @param type whether the service provided by the component is public or private
17
16
  */
18
- function Component(name, instanceFactory, type) {
17
+ constructor(name, instanceFactory, type) {
19
18
  this.name = name;
20
19
  this.instanceFactory = instanceFactory;
21
20
  this.type = type;
@@ -27,24 +26,23 @@ var Component = /** @class */ (function () {
27
26
  this.instantiationMode = "LAZY" /* InstantiationMode.LAZY */;
28
27
  this.onInstanceCreated = null;
29
28
  }
30
- Component.prototype.setInstantiationMode = function (mode) {
29
+ setInstantiationMode(mode) {
31
30
  this.instantiationMode = mode;
32
31
  return this;
33
- };
34
- Component.prototype.setMultipleInstances = function (multipleInstances) {
32
+ }
33
+ setMultipleInstances(multipleInstances) {
35
34
  this.multipleInstances = multipleInstances;
36
35
  return this;
37
- };
38
- Component.prototype.setServiceProps = function (props) {
36
+ }
37
+ setServiceProps(props) {
39
38
  this.serviceProps = props;
40
39
  return this;
41
- };
42
- Component.prototype.setInstanceCreatedCallback = function (callback) {
40
+ }
41
+ setInstanceCreatedCallback(callback) {
43
42
  this.onInstanceCreated = callback;
44
43
  return this;
45
- };
46
- return Component;
47
- }());
44
+ }
45
+ }
48
46
 
49
47
  /**
50
48
  * @license
@@ -62,7 +60,7 @@ var Component = /** @class */ (function () {
62
60
  * See the License for the specific language governing permissions and
63
61
  * limitations under the License.
64
62
  */
65
- var DEFAULT_ENTRY_NAME = '[DEFAULT]';
63
+ const DEFAULT_ENTRY_NAME = '[DEFAULT]';
66
64
 
67
65
  /**
68
66
  * @license
@@ -84,8 +82,8 @@ var DEFAULT_ENTRY_NAME = '[DEFAULT]';
84
82
  * Provider for instance for service name T, e.g. 'auth', 'auth-internal'
85
83
  * NameServiceMapping[T] is an alias for the type of the instance
86
84
  */
87
- var Provider = /** @class */ (function () {
88
- function Provider(name, container) {
85
+ class Provider {
86
+ constructor(name, container) {
89
87
  this.name = name;
90
88
  this.container = container;
91
89
  this.component = null;
@@ -98,17 +96,17 @@ var Provider = /** @class */ (function () {
98
96
  * @param identifier A provider can provide multiple instances of a service
99
97
  * if this.component.multipleInstances is true.
100
98
  */
101
- Provider.prototype.get = function (identifier) {
99
+ get(identifier) {
102
100
  // if multipleInstances is not supported, use the default name
103
- var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
101
+ const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
104
102
  if (!this.instancesDeferred.has(normalizedIdentifier)) {
105
- var deferred = new util.Deferred();
103
+ const deferred = new util.Deferred();
106
104
  this.instancesDeferred.set(normalizedIdentifier, deferred);
107
105
  if (this.isInitialized(normalizedIdentifier) ||
108
106
  this.shouldAutoInitialize()) {
109
107
  // initialize the service if it can be auto-initialized
110
108
  try {
111
- var instance = this.getOrInitializeService({
109
+ const instance = this.getOrInitializeService({
112
110
  instanceIdentifier: normalizedIdentifier
113
111
  });
114
112
  if (instance) {
@@ -122,12 +120,12 @@ var Provider = /** @class */ (function () {
122
120
  }
123
121
  }
124
122
  return this.instancesDeferred.get(normalizedIdentifier).promise;
125
- };
126
- Provider.prototype.getImmediate = function (options) {
123
+ }
124
+ getImmediate(options) {
127
125
  var _a;
128
126
  // if multipleInstances is not supported, use the default name
129
- var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
130
- var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
127
+ const normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
128
+ const optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
131
129
  if (this.isInitialized(normalizedIdentifier) ||
132
130
  this.shouldAutoInitialize()) {
133
131
  try {
@@ -150,20 +148,19 @@ var Provider = /** @class */ (function () {
150
148
  return null;
151
149
  }
152
150
  else {
153
- throw Error("Service ".concat(this.name, " is not available"));
151
+ throw Error(`Service ${this.name} is not available`);
154
152
  }
155
153
  }
156
- };
157
- Provider.prototype.getComponent = function () {
154
+ }
155
+ getComponent() {
158
156
  return this.component;
159
- };
160
- Provider.prototype.setComponent = function (component) {
161
- var e_1, _a;
157
+ }
158
+ setComponent(component) {
162
159
  if (component.name !== this.name) {
163
- throw Error("Mismatching Component ".concat(component.name, " for Provider ").concat(this.name, "."));
160
+ throw Error(`Mismatching Component ${component.name} for Provider ${this.name}.`);
164
161
  }
165
162
  if (this.component) {
166
- throw Error("Component for ".concat(this.name, " has already been provided"));
163
+ throw Error(`Component for ${this.name} has already been provided`);
167
164
  }
168
165
  this.component = component;
169
166
  // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)
@@ -182,108 +179,75 @@ var Provider = /** @class */ (function () {
182
179
  // a fatal error in this case?
183
180
  }
184
181
  }
185
- try {
186
- // Create service instances for the pending promises and resolve them
187
- // NOTE: if this.multipleInstances is false, only the default instance will be created
188
- // and all promises with resolve with it regardless of the identifier.
189
- for (var _b = tslib.__values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
190
- var _d = tslib.__read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];
191
- var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
192
- try {
193
- // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
194
- var instance = this.getOrInitializeService({
195
- instanceIdentifier: normalizedIdentifier
196
- });
197
- instanceDeferred.resolve(instance);
198
- }
199
- catch (e) {
200
- // when the instance factory throws an exception, it should not cause
201
- // a fatal error. We just leave the promise unresolved.
202
- }
203
- }
204
- }
205
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
206
- finally {
182
+ // Create service instances for the pending promises and resolve them
183
+ // NOTE: if this.multipleInstances is false, only the default instance will be created
184
+ // and all promises with resolve with it regardless of the identifier.
185
+ for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
186
+ const normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
207
187
  try {
208
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
188
+ // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
189
+ const instance = this.getOrInitializeService({
190
+ instanceIdentifier: normalizedIdentifier
191
+ });
192
+ instanceDeferred.resolve(instance);
193
+ }
194
+ catch (e) {
195
+ // when the instance factory throws an exception, it should not cause
196
+ // a fatal error. We just leave the promise unresolved.
209
197
  }
210
- finally { if (e_1) throw e_1.error; }
211
198
  }
212
- };
213
- Provider.prototype.clearInstance = function (identifier) {
214
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
199
+ }
200
+ clearInstance(identifier = DEFAULT_ENTRY_NAME) {
215
201
  this.instancesDeferred.delete(identifier);
216
202
  this.instancesOptions.delete(identifier);
217
203
  this.instances.delete(identifier);
218
- };
204
+ }
219
205
  // app.delete() will call this method on every provider to delete the services
220
206
  // TODO: should we mark the provider as deleted?
221
- Provider.prototype.delete = function () {
222
- return tslib.__awaiter(this, void 0, void 0, function () {
223
- var services;
224
- return tslib.__generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0:
227
- services = Array.from(this.instances.values());
228
- return [4 /*yield*/, Promise.all(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(services
229
- .filter(function (service) { return 'INTERNAL' in service; }) // legacy services
230
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
- .map(function (service) { return service.INTERNAL.delete(); })), false), tslib.__read(services
232
- .filter(function (service) { return '_delete' in service; }) // modularized services
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
- .map(function (service) { return service._delete(); })), false))];
235
- case 1:
236
- _a.sent();
237
- return [2 /*return*/];
238
- }
239
- });
240
- });
241
- };
242
- Provider.prototype.isComponentSet = function () {
207
+ async delete() {
208
+ const services = Array.from(this.instances.values());
209
+ await Promise.all([
210
+ ...services
211
+ .filter(service => 'INTERNAL' in service) // legacy services
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ .map(service => service.INTERNAL.delete()),
214
+ ...services
215
+ .filter(service => '_delete' in service) // modularized services
216
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
217
+ .map(service => service._delete())
218
+ ]);
219
+ }
220
+ isComponentSet() {
243
221
  return this.component != null;
244
- };
245
- Provider.prototype.isInitialized = function (identifier) {
246
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
222
+ }
223
+ isInitialized(identifier = DEFAULT_ENTRY_NAME) {
247
224
  return this.instances.has(identifier);
248
- };
249
- Provider.prototype.getOptions = function (identifier) {
250
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
225
+ }
226
+ getOptions(identifier = DEFAULT_ENTRY_NAME) {
251
227
  return this.instancesOptions.get(identifier) || {};
252
- };
253
- Provider.prototype.initialize = function (opts) {
254
- var e_2, _a;
255
- if (opts === void 0) { opts = {}; }
256
- var _b = opts.options, options = _b === void 0 ? {} : _b;
257
- var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
228
+ }
229
+ initialize(opts = {}) {
230
+ const { options = {} } = opts;
231
+ const normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
258
232
  if (this.isInitialized(normalizedIdentifier)) {
259
- throw Error("".concat(this.name, "(").concat(normalizedIdentifier, ") has already been initialized"));
233
+ throw Error(`${this.name}(${normalizedIdentifier}) has already been initialized`);
260
234
  }
261
235
  if (!this.isComponentSet()) {
262
- throw Error("Component ".concat(this.name, " has not been registered yet"));
236
+ throw Error(`Component ${this.name} has not been registered yet`);
263
237
  }
264
- var instance = this.getOrInitializeService({
238
+ const instance = this.getOrInitializeService({
265
239
  instanceIdentifier: normalizedIdentifier,
266
- options: options
240
+ options
267
241
  });
268
- try {
269
- // resolve any pending promise waiting for the service instance
270
- for (var _c = tslib.__values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
271
- var _e = tslib.__read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];
272
- var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
273
- if (normalizedIdentifier === normalizedDeferredIdentifier) {
274
- instanceDeferred.resolve(instance);
275
- }
276
- }
277
- }
278
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
279
- finally {
280
- try {
281
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
242
+ // resolve any pending promise waiting for the service instance
243
+ for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
244
+ const normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
245
+ if (normalizedIdentifier === normalizedDeferredIdentifier) {
246
+ instanceDeferred.resolve(instance);
282
247
  }
283
- finally { if (e_2) throw e_2.error; }
284
248
  }
285
249
  return instance;
286
- };
250
+ }
287
251
  /**
288
252
  *
289
253
  * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
@@ -292,56 +256,44 @@ var Provider = /** @class */ (function () {
292
256
  * @param identifier An optional instance identifier
293
257
  * @returns a function to unregister the callback
294
258
  */
295
- Provider.prototype.onInit = function (callback, identifier) {
259
+ onInit(callback, identifier) {
296
260
  var _a;
297
- var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
298
- var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
261
+ const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
262
+ const existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
299
263
  existingCallbacks.add(callback);
300
264
  this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
301
- var existingInstance = this.instances.get(normalizedIdentifier);
265
+ const existingInstance = this.instances.get(normalizedIdentifier);
302
266
  if (existingInstance) {
303
267
  callback(existingInstance, normalizedIdentifier);
304
268
  }
305
- return function () {
269
+ return () => {
306
270
  existingCallbacks.delete(callback);
307
271
  };
308
- };
272
+ }
309
273
  /**
310
274
  * Invoke onInit callbacks synchronously
311
275
  * @param instance the service instance`
312
276
  */
313
- Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {
314
- var e_3, _a;
315
- var callbacks = this.onInitCallbacks.get(identifier);
277
+ invokeOnInitCallbacks(instance, identifier) {
278
+ const callbacks = this.onInitCallbacks.get(identifier);
316
279
  if (!callbacks) {
317
280
  return;
318
281
  }
319
- try {
320
- for (var callbacks_1 = tslib.__values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
321
- var callback = callbacks_1_1.value;
322
- try {
323
- callback(instance, identifier);
324
- }
325
- catch (_b) {
326
- // ignore errors in the onInit callback
327
- }
328
- }
329
- }
330
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
331
- finally {
282
+ for (const callback of callbacks) {
332
283
  try {
333
- if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
284
+ callback(instance, identifier);
285
+ }
286
+ catch (_a) {
287
+ // ignore errors in the onInit callback
334
288
  }
335
- finally { if (e_3) throw e_3.error; }
336
289
  }
337
- };
338
- Provider.prototype.getOrInitializeService = function (_a) {
339
- var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;
340
- var instance = this.instances.get(instanceIdentifier);
290
+ }
291
+ getOrInitializeService({ instanceIdentifier, options = {} }) {
292
+ let instance = this.instances.get(instanceIdentifier);
341
293
  if (!instance && this.component) {
342
294
  instance = this.component.instanceFactory(this.container, {
343
295
  instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
344
- options: options
296
+ options
345
297
  });
346
298
  this.instances.set(instanceIdentifier, instance);
347
299
  this.instancesOptions.set(instanceIdentifier, options);
@@ -360,28 +312,26 @@ var Provider = /** @class */ (function () {
360
312
  try {
361
313
  this.component.onInstanceCreated(this.container, instanceIdentifier, instance);
362
314
  }
363
- catch (_c) {
315
+ catch (_a) {
364
316
  // ignore errors in the onInstanceCreatedCallback
365
317
  }
366
318
  }
367
319
  }
368
320
  return instance || null;
369
- };
370
- Provider.prototype.normalizeInstanceIdentifier = function (identifier) {
371
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
321
+ }
322
+ normalizeInstanceIdentifier(identifier = DEFAULT_ENTRY_NAME) {
372
323
  if (this.component) {
373
324
  return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;
374
325
  }
375
326
  else {
376
327
  return identifier; // assume multiple instances are supported before the component is provided.
377
328
  }
378
- };
379
- Provider.prototype.shouldAutoInitialize = function () {
329
+ }
330
+ shouldAutoInitialize() {
380
331
  return (!!this.component &&
381
332
  this.component.instantiationMode !== "EXPLICIT" /* InstantiationMode.EXPLICIT */);
382
- };
383
- return Provider;
384
- }());
333
+ }
334
+ }
385
335
  // undefined should be passed to the service factory for the default instance
386
336
  function normalizeIdentifierForFactory(identifier) {
387
337
  return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;
@@ -409,8 +359,8 @@ function isComponentEager(component) {
409
359
  /**
410
360
  * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
411
361
  */
412
- var ComponentContainer = /** @class */ (function () {
413
- function ComponentContainer(name) {
362
+ class ComponentContainer {
363
+ constructor(name) {
414
364
  this.name = name;
415
365
  this.providers = new Map();
416
366
  }
@@ -423,21 +373,21 @@ var ComponentContainer = /** @class */ (function () {
423
373
  * for different tests.
424
374
  * if overwrite is false: throw an exception
425
375
  */
426
- ComponentContainer.prototype.addComponent = function (component) {
427
- var provider = this.getProvider(component.name);
376
+ addComponent(component) {
377
+ const provider = this.getProvider(component.name);
428
378
  if (provider.isComponentSet()) {
429
- throw new Error("Component ".concat(component.name, " has already been registered with ").concat(this.name));
379
+ throw new Error(`Component ${component.name} has already been registered with ${this.name}`);
430
380
  }
431
381
  provider.setComponent(component);
432
- };
433
- ComponentContainer.prototype.addOrOverwriteComponent = function (component) {
434
- var provider = this.getProvider(component.name);
382
+ }
383
+ addOrOverwriteComponent(component) {
384
+ const provider = this.getProvider(component.name);
435
385
  if (provider.isComponentSet()) {
436
386
  // delete the existing provider from the container, so we can register the new component
437
387
  this.providers.delete(component.name);
438
388
  }
439
389
  this.addComponent(component);
440
- };
390
+ }
441
391
  /**
442
392
  * getProvider provides a type safe interface where it can only be called with a field name
443
393
  * present in NameServiceMapping interface.
@@ -445,20 +395,19 @@ var ComponentContainer = /** @class */ (function () {
445
395
  * Firebase SDKs providing services should extend NameServiceMapping interface to register
446
396
  * themselves.
447
397
  */
448
- ComponentContainer.prototype.getProvider = function (name) {
398
+ getProvider(name) {
449
399
  if (this.providers.has(name)) {
450
400
  return this.providers.get(name);
451
401
  }
452
402
  // create a Provider for a service that hasn't registered with Firebase
453
- var provider = new Provider(name, this);
403
+ const provider = new Provider(name, this);
454
404
  this.providers.set(name, provider);
455
405
  return provider;
456
- };
457
- ComponentContainer.prototype.getProviders = function () {
406
+ }
407
+ getProviders() {
458
408
  return Array.from(this.providers.values());
459
- };
460
- return ComponentContainer;
461
- }());
409
+ }
410
+ }
462
411
 
463
412
  exports.Component = Component;
464
413
  exports.ComponentContainer = ComponentContainer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/component.ts","../src/constants.ts","../src/provider.ts","../src/component_container.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n InstantiationMode,\n InstanceFactory,\n ComponentType,\n Dictionary,\n Name,\n onInstanceCreatedCallback\n} from './types';\n\n/**\n * Component for service name T, e.g. `auth`, `auth-internal`\n */\nexport class Component<T extends Name = Name> {\n multipleInstances = false;\n /**\n * Properties to be added to the service namespace\n */\n serviceProps: Dictionary = {};\n\n instantiationMode = InstantiationMode.LAZY;\n\n onInstanceCreated: onInstanceCreatedCallback<T> | null = null;\n\n /**\n *\n * @param name The public service name, e.g. app, auth, firestore, database\n * @param instanceFactory Service factory responsible for creating the public interface\n * @param type whether the service provided by the component is public or private\n */\n constructor(\n readonly name: T,\n readonly instanceFactory: InstanceFactory<T>,\n readonly type: ComponentType\n ) {}\n\n setInstantiationMode(mode: InstantiationMode): this {\n this.instantiationMode = mode;\n return this;\n }\n\n setMultipleInstances(multipleInstances: boolean): this {\n this.multipleInstances = multipleInstances;\n return this;\n }\n\n setServiceProps(props: Dictionary): this {\n this.serviceProps = props;\n return this;\n }\n\n setInstanceCreatedCallback(callback: onInstanceCreatedCallback<T>): this {\n this.onInstanceCreated = callback;\n return this;\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const DEFAULT_ENTRY_NAME = '[DEFAULT]';\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Deferred } from '@firebase/util';\nimport { ComponentContainer } from './component_container';\nimport { DEFAULT_ENTRY_NAME } from './constants';\nimport {\n InitializeOptions,\n InstantiationMode,\n Name,\n NameServiceMapping,\n OnInitCallBack\n} from './types';\nimport { Component } from './component';\n\n/**\n * Provider for instance for service name T, e.g. 'auth', 'auth-internal'\n * NameServiceMapping[T] is an alias for the type of the instance\n */\nexport class Provider<T extends Name> {\n private component: Component<T> | null = null;\n private readonly instances: Map<string, NameServiceMapping[T]> = new Map();\n private readonly instancesDeferred: Map<\n string,\n Deferred<NameServiceMapping[T]>\n > = new Map();\n private readonly instancesOptions: Map<string, Record<string, unknown>> =\n new Map();\n private onInitCallbacks: Map<string, Set<OnInitCallBack<T>>> = new Map();\n\n constructor(\n private readonly name: T,\n private readonly container: ComponentContainer\n ) {}\n\n /**\n * @param identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n */\n get(identifier?: string): Promise<NameServiceMapping[T]> {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n\n if (!this.instancesDeferred.has(normalizedIdentifier)) {\n const deferred = new Deferred<NameServiceMapping[T]>();\n this.instancesDeferred.set(normalizedIdentifier, deferred);\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n // initialize the service if it can be auto-initialized\n try {\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n if (instance) {\n deferred.resolve(instance);\n }\n } catch (e) {\n // when the instance factory throws an exception during get(), it should not cause\n // a fatal error. We just return the unresolved promise in this case.\n }\n }\n }\n\n return this.instancesDeferred.get(normalizedIdentifier)!.promise;\n }\n\n /**\n *\n * @param options.identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n * @param options.optional If optional is false or not provided, the method throws an error when\n * the service is not immediately available.\n * If optional is true, the method returns null if the service is not immediately available.\n */\n getImmediate(options: {\n identifier?: string;\n optional: true;\n }): NameServiceMapping[T] | null;\n getImmediate(options?: {\n identifier?: string;\n optional?: false;\n }): NameServiceMapping[T];\n getImmediate(options?: {\n identifier?: string;\n optional?: boolean;\n }): NameServiceMapping[T] | null {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n options?.identifier\n );\n const optional = options?.optional ?? false;\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n try {\n return this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n } catch (e) {\n if (optional) {\n return null;\n } else {\n throw e;\n }\n }\n } else {\n // In case a component is not initialized and should/cannot be auto-initialized at the moment, return null if the optional flag is set, or throw\n if (optional) {\n return null;\n } else {\n throw Error(`Service ${this.name} is not available`);\n }\n }\n }\n\n getComponent(): Component<T> | null {\n return this.component;\n }\n\n setComponent(component: Component<T>): void {\n if (component.name !== this.name) {\n throw Error(\n `Mismatching Component ${component.name} for Provider ${this.name}.`\n );\n }\n\n if (this.component) {\n throw Error(`Component for ${this.name} has already been provided`);\n }\n\n this.component = component;\n\n // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)\n if (!this.shouldAutoInitialize()) {\n return;\n }\n\n // if the service is eager, initialize the default instance\n if (isComponentEager(component)) {\n try {\n this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });\n } catch (e) {\n // when the instance factory for an eager Component throws an exception during the eager\n // initialization, it should not cause a fatal error.\n // TODO: Investigate if we need to make it configurable, because some component may want to cause\n // a fatal error in this case?\n }\n }\n\n // Create service instances for the pending promises and resolve them\n // NOTE: if this.multipleInstances is false, only the default instance will be created\n // and all promises with resolve with it regardless of the identifier.\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n\n try {\n // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n })!;\n instanceDeferred.resolve(instance);\n } catch (e) {\n // when the instance factory throws an exception, it should not cause\n // a fatal error. We just leave the promise unresolved.\n }\n }\n }\n\n clearInstance(identifier: string = DEFAULT_ENTRY_NAME): void {\n this.instancesDeferred.delete(identifier);\n this.instancesOptions.delete(identifier);\n this.instances.delete(identifier);\n }\n\n // app.delete() will call this method on every provider to delete the services\n // TODO: should we mark the provider as deleted?\n async delete(): Promise<void> {\n const services = Array.from(this.instances.values());\n\n await Promise.all([\n ...services\n .filter(service => 'INTERNAL' in service) // legacy services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any).INTERNAL!.delete()),\n ...services\n .filter(service => '_delete' in service) // modularized services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any)._delete())\n ]);\n }\n\n isComponentSet(): boolean {\n return this.component != null;\n }\n\n isInitialized(identifier: string = DEFAULT_ENTRY_NAME): boolean {\n return this.instances.has(identifier);\n }\n\n getOptions(identifier: string = DEFAULT_ENTRY_NAME): Record<string, unknown> {\n return this.instancesOptions.get(identifier) || {};\n }\n\n initialize(opts: InitializeOptions = {}): NameServiceMapping[T] {\n const { options = {} } = opts;\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n opts.instanceIdentifier\n );\n if (this.isInitialized(normalizedIdentifier)) {\n throw Error(\n `${this.name}(${normalizedIdentifier}) has already been initialized`\n );\n }\n\n if (!this.isComponentSet()) {\n throw Error(`Component ${this.name} has not been registered yet`);\n }\n\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier,\n options\n })!;\n\n // resolve any pending promise waiting for the service instance\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedDeferredIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n if (normalizedIdentifier === normalizedDeferredIdentifier) {\n instanceDeferred.resolve(instance);\n }\n }\n\n return instance;\n }\n\n /**\n *\n * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().\n * The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.\n *\n * @param identifier An optional instance identifier\n * @returns a function to unregister the callback\n */\n onInit(callback: OnInitCallBack<T>, identifier?: string): () => void {\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n const existingCallbacks =\n this.onInitCallbacks.get(normalizedIdentifier) ??\n new Set<OnInitCallBack<T>>();\n existingCallbacks.add(callback);\n this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);\n\n const existingInstance = this.instances.get(normalizedIdentifier);\n if (existingInstance) {\n callback(existingInstance, normalizedIdentifier);\n }\n\n return () => {\n existingCallbacks.delete(callback);\n };\n }\n\n /**\n * Invoke onInit callbacks synchronously\n * @param instance the service instance`\n */\n private invokeOnInitCallbacks(\n instance: NameServiceMapping[T],\n identifier: string\n ): void {\n const callbacks = this.onInitCallbacks.get(identifier);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n try {\n callback(instance, identifier);\n } catch {\n // ignore errors in the onInit callback\n }\n }\n }\n\n private getOrInitializeService({\n instanceIdentifier,\n options = {}\n }: {\n instanceIdentifier: string;\n options?: Record<string, unknown>;\n }): NameServiceMapping[T] | null {\n let instance = this.instances.get(instanceIdentifier);\n if (!instance && this.component) {\n instance = this.component.instanceFactory(this.container, {\n instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),\n options\n });\n this.instances.set(instanceIdentifier, instance);\n this.instancesOptions.set(instanceIdentifier, options);\n\n /**\n * Invoke onInit listeners.\n * Note this.component.onInstanceCreated is different, which is used by the component creator,\n * while onInit listeners are registered by consumers of the provider.\n */\n this.invokeOnInitCallbacks(instance, instanceIdentifier);\n\n /**\n * Order is important\n * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which\n * makes `isInitialized()` return true.\n */\n if (this.component.onInstanceCreated) {\n try {\n this.component.onInstanceCreated(\n this.container,\n instanceIdentifier,\n instance\n );\n } catch {\n // ignore errors in the onInstanceCreatedCallback\n }\n }\n }\n\n return instance || null;\n }\n\n private normalizeInstanceIdentifier(\n identifier: string = DEFAULT_ENTRY_NAME\n ): string {\n if (this.component) {\n return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;\n } else {\n return identifier; // assume multiple instances are supported before the component is provided.\n }\n }\n\n private shouldAutoInitialize(): boolean {\n return (\n !!this.component &&\n this.component.instantiationMode !== InstantiationMode.EXPLICIT\n );\n }\n}\n\n// undefined should be passed to the service factory for the default instance\nfunction normalizeIdentifierForFactory(identifier: string): string | undefined {\n return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;\n}\n\nfunction isComponentEager<T extends Name>(component: Component<T>): boolean {\n return component.instantiationMode === InstantiationMode.EAGER;\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Provider } from './provider';\nimport { Component } from './component';\nimport { Name } from './types';\n\n/**\n * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`\n */\nexport class ComponentContainer {\n private readonly providers = new Map<string, Provider<Name>>();\n\n constructor(private readonly name: string) {}\n\n /**\n *\n * @param component Component being added\n * @param overwrite When a component with the same name has already been registered,\n * if overwrite is true: overwrite the existing component with the new component and create a new\n * provider with the new component. It can be useful in tests where you want to use different mocks\n * for different tests.\n * if overwrite is false: throw an exception\n */\n addComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n throw new Error(\n `Component ${component.name} has already been registered with ${this.name}`\n );\n }\n\n provider.setComponent(component);\n }\n\n addOrOverwriteComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n // delete the existing provider from the container, so we can register the new component\n this.providers.delete(component.name);\n }\n\n this.addComponent(component);\n }\n\n /**\n * getProvider provides a type safe interface where it can only be called with a field name\n * present in NameServiceMapping interface.\n *\n * Firebase SDKs providing services should extend NameServiceMapping interface to register\n * themselves.\n */\n getProvider<T extends Name>(name: T): Provider<T> {\n if (this.providers.has(name)) {\n return this.providers.get(name) as unknown as Provider<T>;\n }\n\n // create a Provider for a service that hasn't registered with Firebase\n const provider = new Provider<T>(name, this);\n this.providers.set(name, provider as unknown as Provider<Name>);\n\n return provider as Provider<T>;\n }\n\n getProviders(): Array<Provider<Name>> {\n return Array.from(this.providers.values());\n }\n}\n"],"names":["Deferred","__values","__read","__spreadArray"],"mappings":";;;;;;;AAyBA;;AAEG;AACH,IAAA,SAAA,kBAAA,YAAA;AAWE;;;;;AAKG;AACH,IAAA,SAAA,SAAA,CACW,IAAO,EACP,eAAmC,EACnC,IAAmB,EAAA;QAFnB,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAG;QACP,IAAe,CAAA,eAAA,GAAf,eAAe,CAAoB;QACnC,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAe;QAnB9B,IAAiB,CAAA,iBAAA,GAAG,KAAK,CAAC;AAC1B;;AAEG;QACH,IAAY,CAAA,YAAA,GAAe,EAAE,CAAC;AAE9B,QAAA,IAAA,CAAA,iBAAiB,GAA0B,MAAA,8BAAA;QAE3C,IAAiB,CAAA,iBAAA,G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;AAED,QAAA,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KAC9B,CAAA;AAED;;;;;;AAMG;IACH,kBAAW,CAAA,SAAA,CAAA,WAAA,GAAX,UAA4B,IAAO,EAAA;QACjC,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAA2B,CAAC;AAC3D,SAAA;;QAGD,IAAM,QAAQ,GAAG,IAAI,QAAQ,CAAI,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAqC,CAAC,CAAC;AAEhE,QAAA,OAAO,QAAuB,CAAC;KAChC,CAAA;AAED,IAAA,kBAAA,CAAA,SAAA,CAAA,YAAY,GAAZ,YAAA;QACE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5C,CAAA;IACH,OAAC,kBAAA,CAAA;AAAD,CAAC,EAAA;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/component.ts","../src/constants.ts","../src/provider.ts","../src/component_container.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n InstantiationMode,\n InstanceFactory,\n ComponentType,\n Dictionary,\n Name,\n onInstanceCreatedCallback\n} from './types';\n\n/**\n * Component for service name T, e.g. `auth`, `auth-internal`\n */\nexport class Component<T extends Name = Name> {\n multipleInstances = false;\n /**\n * Properties to be added to the service namespace\n */\n serviceProps: Dictionary = {};\n\n instantiationMode = InstantiationMode.LAZY;\n\n onInstanceCreated: onInstanceCreatedCallback<T> | null = null;\n\n /**\n *\n * @param name The public service name, e.g. app, auth, firestore, database\n * @param instanceFactory Service factory responsible for creating the public interface\n * @param type whether the service provided by the component is public or private\n */\n constructor(\n readonly name: T,\n readonly instanceFactory: InstanceFactory<T>,\n readonly type: ComponentType\n ) {}\n\n setInstantiationMode(mode: InstantiationMode): this {\n this.instantiationMode = mode;\n return this;\n }\n\n setMultipleInstances(multipleInstances: boolean): this {\n this.multipleInstances = multipleInstances;\n return this;\n }\n\n setServiceProps(props: Dictionary): this {\n this.serviceProps = props;\n return this;\n }\n\n setInstanceCreatedCallback(callback: onInstanceCreatedCallback<T>): this {\n this.onInstanceCreated = callback;\n return this;\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const DEFAULT_ENTRY_NAME = '[DEFAULT]';\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Deferred } from '@firebase/util';\nimport { ComponentContainer } from './component_container';\nimport { DEFAULT_ENTRY_NAME } from './constants';\nimport {\n InitializeOptions,\n InstantiationMode,\n Name,\n NameServiceMapping,\n OnInitCallBack\n} from './types';\nimport { Component } from './component';\n\n/**\n * Provider for instance for service name T, e.g. 'auth', 'auth-internal'\n * NameServiceMapping[T] is an alias for the type of the instance\n */\nexport class Provider<T extends Name> {\n private component: Component<T> | null = null;\n private readonly instances: Map<string, NameServiceMapping[T]> = new Map();\n private readonly instancesDeferred: Map<\n string,\n Deferred<NameServiceMapping[T]>\n > = new Map();\n private readonly instancesOptions: Map<string, Record<string, unknown>> =\n new Map();\n private onInitCallbacks: Map<string, Set<OnInitCallBack<T>>> = new Map();\n\n constructor(\n private readonly name: T,\n private readonly container: ComponentContainer\n ) {}\n\n /**\n * @param identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n */\n get(identifier?: string): Promise<NameServiceMapping[T]> {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n\n if (!this.instancesDeferred.has(normalizedIdentifier)) {\n const deferred = new Deferred<NameServiceMapping[T]>();\n this.instancesDeferred.set(normalizedIdentifier, deferred);\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n // initialize the service if it can be auto-initialized\n try {\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n if (instance) {\n deferred.resolve(instance);\n }\n } catch (e) {\n // when the instance factory throws an exception during get(), it should not cause\n // a fatal error. We just return the unresolved promise in this case.\n }\n }\n }\n\n return this.instancesDeferred.get(normalizedIdentifier)!.promise;\n }\n\n /**\n *\n * @param options.identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n * @param options.optional If optional is false or not provided, the method throws an error when\n * the service is not immediately available.\n * If optional is true, the method returns null if the service is not immediately available.\n */\n getImmediate(options: {\n identifier?: string;\n optional: true;\n }): NameServiceMapping[T] | null;\n getImmediate(options?: {\n identifier?: string;\n optional?: false;\n }): NameServiceMapping[T];\n getImmediate(options?: {\n identifier?: string;\n optional?: boolean;\n }): NameServiceMapping[T] | null {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n options?.identifier\n );\n const optional = options?.optional ?? false;\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n try {\n return this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n } catch (e) {\n if (optional) {\n return null;\n } else {\n throw e;\n }\n }\n } else {\n // In case a component is not initialized and should/cannot be auto-initialized at the moment, return null if the optional flag is set, or throw\n if (optional) {\n return null;\n } else {\n throw Error(`Service ${this.name} is not available`);\n }\n }\n }\n\n getComponent(): Component<T> | null {\n return this.component;\n }\n\n setComponent(component: Component<T>): void {\n if (component.name !== this.name) {\n throw Error(\n `Mismatching Component ${component.name} for Provider ${this.name}.`\n );\n }\n\n if (this.component) {\n throw Error(`Component for ${this.name} has already been provided`);\n }\n\n this.component = component;\n\n // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)\n if (!this.shouldAutoInitialize()) {\n return;\n }\n\n // if the service is eager, initialize the default instance\n if (isComponentEager(component)) {\n try {\n this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });\n } catch (e) {\n // when the instance factory for an eager Component throws an exception during the eager\n // initialization, it should not cause a fatal error.\n // TODO: Investigate if we need to make it configurable, because some component may want to cause\n // a fatal error in this case?\n }\n }\n\n // Create service instances for the pending promises and resolve them\n // NOTE: if this.multipleInstances is false, only the default instance will be created\n // and all promises with resolve with it regardless of the identifier.\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n\n try {\n // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n })!;\n instanceDeferred.resolve(instance);\n } catch (e) {\n // when the instance factory throws an exception, it should not cause\n // a fatal error. We just leave the promise unresolved.\n }\n }\n }\n\n clearInstance(identifier: string = DEFAULT_ENTRY_NAME): void {\n this.instancesDeferred.delete(identifier);\n this.instancesOptions.delete(identifier);\n this.instances.delete(identifier);\n }\n\n // app.delete() will call this method on every provider to delete the services\n // TODO: should we mark the provider as deleted?\n async delete(): Promise<void> {\n const services = Array.from(this.instances.values());\n\n await Promise.all([\n ...services\n .filter(service => 'INTERNAL' in service) // legacy services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any).INTERNAL!.delete()),\n ...services\n .filter(service => '_delete' in service) // modularized services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any)._delete())\n ]);\n }\n\n isComponentSet(): boolean {\n return this.component != null;\n }\n\n isInitialized(identifier: string = DEFAULT_ENTRY_NAME): boolean {\n return this.instances.has(identifier);\n }\n\n getOptions(identifier: string = DEFAULT_ENTRY_NAME): Record<string, unknown> {\n return this.instancesOptions.get(identifier) || {};\n }\n\n initialize(opts: InitializeOptions = {}): NameServiceMapping[T] {\n const { options = {} } = opts;\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n opts.instanceIdentifier\n );\n if (this.isInitialized(normalizedIdentifier)) {\n throw Error(\n `${this.name}(${normalizedIdentifier}) has already been initialized`\n );\n }\n\n if (!this.isComponentSet()) {\n throw Error(`Component ${this.name} has not been registered yet`);\n }\n\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier,\n options\n })!;\n\n // resolve any pending promise waiting for the service instance\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedDeferredIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n if (normalizedIdentifier === normalizedDeferredIdentifier) {\n instanceDeferred.resolve(instance);\n }\n }\n\n return instance;\n }\n\n /**\n *\n * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().\n * The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.\n *\n * @param identifier An optional instance identifier\n * @returns a function to unregister the callback\n */\n onInit(callback: OnInitCallBack<T>, identifier?: string): () => void {\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n const existingCallbacks =\n this.onInitCallbacks.get(normalizedIdentifier) ??\n new Set<OnInitCallBack<T>>();\n existingCallbacks.add(callback);\n this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);\n\n const existingInstance = this.instances.get(normalizedIdentifier);\n if (existingInstance) {\n callback(existingInstance, normalizedIdentifier);\n }\n\n return () => {\n existingCallbacks.delete(callback);\n };\n }\n\n /**\n * Invoke onInit callbacks synchronously\n * @param instance the service instance`\n */\n private invokeOnInitCallbacks(\n instance: NameServiceMapping[T],\n identifier: string\n ): void {\n const callbacks = this.onInitCallbacks.get(identifier);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n try {\n callback(instance, identifier);\n } catch {\n // ignore errors in the onInit callback\n }\n }\n }\n\n private getOrInitializeService({\n instanceIdentifier,\n options = {}\n }: {\n instanceIdentifier: string;\n options?: Record<string, unknown>;\n }): NameServiceMapping[T] | null {\n let instance = this.instances.get(instanceIdentifier);\n if (!instance && this.component) {\n instance = this.component.instanceFactory(this.container, {\n instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),\n options\n });\n this.instances.set(instanceIdentifier, instance);\n this.instancesOptions.set(instanceIdentifier, options);\n\n /**\n * Invoke onInit listeners.\n * Note this.component.onInstanceCreated is different, which is used by the component creator,\n * while onInit listeners are registered by consumers of the provider.\n */\n this.invokeOnInitCallbacks(instance, instanceIdentifier);\n\n /**\n * Order is important\n * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which\n * makes `isInitialized()` return true.\n */\n if (this.component.onInstanceCreated) {\n try {\n this.component.onInstanceCreated(\n this.container,\n instanceIdentifier,\n instance\n );\n } catch {\n // ignore errors in the onInstanceCreatedCallback\n }\n }\n }\n\n return instance || null;\n }\n\n private normalizeInstanceIdentifier(\n identifier: string = DEFAULT_ENTRY_NAME\n ): string {\n if (this.component) {\n return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;\n } else {\n return identifier; // assume multiple instances are supported before the component is provided.\n }\n }\n\n private shouldAutoInitialize(): boolean {\n return (\n !!this.component &&\n this.component.instantiationMode !== InstantiationMode.EXPLICIT\n );\n }\n}\n\n// undefined should be passed to the service factory for the default instance\nfunction normalizeIdentifierForFactory(identifier: string): string | undefined {\n return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;\n}\n\nfunction isComponentEager<T extends Name>(component: Component<T>): boolean {\n return component.instantiationMode === InstantiationMode.EAGER;\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Provider } from './provider';\nimport { Component } from './component';\nimport { Name } from './types';\n\n/**\n * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`\n */\nexport class ComponentContainer {\n private readonly providers = new Map<string, Provider<Name>>();\n\n constructor(private readonly name: string) {}\n\n /**\n *\n * @param component Component being added\n * @param overwrite When a component with the same name has already been registered,\n * if overwrite is true: overwrite the existing component with the new component and create a new\n * provider with the new component. It can be useful in tests where you want to use different mocks\n * for different tests.\n * if overwrite is false: throw an exception\n */\n addComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n throw new Error(\n `Component ${component.name} has already been registered with ${this.name}`\n );\n }\n\n provider.setComponent(component);\n }\n\n addOrOverwriteComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n // delete the existing provider from the container, so we can register the new component\n this.providers.delete(component.name);\n }\n\n this.addComponent(component);\n }\n\n /**\n * getProvider provides a type safe interface where it can only be called with a field name\n * present in NameServiceMapping interface.\n *\n * Firebase SDKs providing services should extend NameServiceMapping interface to register\n * themselves.\n */\n getProvider<T extends Name>(name: T): Provider<T> {\n if (this.providers.has(name)) {\n return this.providers.get(name) as unknown as Provider<T>;\n }\n\n // create a Provider for a service that hasn't registered with Firebase\n const provider = new Provider<T>(name, this);\n this.providers.set(name, provider as unknown as Provider<Name>);\n\n return provider as Provider<T>;\n }\n\n getProviders(): Array<Provider<Name>> {\n return Array.from(this.providers.values());\n }\n}\n"],"names":["Deferred"],"mappings":";;;;;;AAyBA;;AAEG;MACU,SAAS,CAAA;AAWpB;;;;;AAKG;AACH,IAAA,WAAA,CACW,IAAO,EACP,eAAmC,EACnC,IAAmB,EAAA;QAFnB,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAG;QACP,IAAe,CAAA,eAAA,GAAf,eAAe,CAAoB;QACnC,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAe;QAnB9B,IAAiB,CAAA,iBAAA,GAAG,KAAK,CAAC;AAC1B;;AAEG;QACH,IAAY,CAAA,YAAA,GAAe,EAAE,CAAC;AAE9B,QAAA,IAAA,CAAA,iBAAiB,GAA0B,MAAA,8BAAA;QAE3C,IAAiB,CAAA,iBAAA,GAAwC,IAAI,CAAC;KAY1D;AAEJ,IAAA,oBAAoB,CAAC,IAAuB,EAAA;AAC1C,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;AAC9B,QAAA,OAAO,IAAI,CAAC;KACb;AAED,IAAA,oBAAoB,CAAC,iBAA0B,EAAA;AAC7C,QAAA,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;AAC3C,QAAA,OAAO,IAAI,CAAC;KACb;AAED,IAAA,eAAe,CAAC,KAAiB,EAAA;AAC/B,QAAA,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;AAC1B,QAAA,OAAO,IAAI,CAAC;KACb;AAED,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,YAAY,GAAA;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5C;AACF;;;;;;"}
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "@firebase/component",
3
- "version": "0.6.9",
3
+ "version": "0.6.10-canary.a97ac88db",
4
4
  "description": "Firebase Component Platform",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.cjs.js",
7
7
  "browser": "dist/esm/index.esm2017.js",
8
8
  "module": "dist/esm/index.esm2017.js",
9
- "esm5": "dist/esm/index.esm5.js",
10
9
  "exports": {
11
10
  ".": {
12
11
  "types": "./dist/index.d.ts",
13
12
  "require": "./dist/index.cjs.js",
14
- "esm5": "./dist/esm/index.esm5.js",
15
13
  "default": "./dist/esm/index.esm2017.js"
16
14
  },
17
15
  "./package.json": "./package.json"
@@ -33,7 +31,7 @@
33
31
  "trusted-type-check": "tsec -p tsconfig.json --noEmit"
34
32
  },
35
33
  "dependencies": {
36
- "@firebase/util": "1.10.0",
34
+ "@firebase/util": "1.10.1-canary.a97ac88db",
37
35
  "tslib": "^2.1.0"
38
36
  },
39
37
  "license": "Apache-2.0",
@@ -56,5 +54,8 @@
56
54
  ".ts"
57
55
  ],
58
56
  "reportDir": "./coverage/node"
57
+ },
58
+ "engines": {
59
+ "node": ">=18.0.0"
59
60
  }
60
61
  }
@@ -1,460 +0,0 @@
1
- import { __values, __read, __awaiter, __generator, __spreadArray } from 'tslib';
2
- import { Deferred } from '@firebase/util';
3
-
4
- /**
5
- * Component for service name T, e.g. `auth`, `auth-internal`
6
- */
7
- var Component = /** @class */ (function () {
8
- /**
9
- *
10
- * @param name The public service name, e.g. app, auth, firestore, database
11
- * @param instanceFactory Service factory responsible for creating the public interface
12
- * @param type whether the service provided by the component is public or private
13
- */
14
- function Component(name, instanceFactory, type) {
15
- this.name = name;
16
- this.instanceFactory = instanceFactory;
17
- this.type = type;
18
- this.multipleInstances = false;
19
- /**
20
- * Properties to be added to the service namespace
21
- */
22
- this.serviceProps = {};
23
- this.instantiationMode = "LAZY" /* InstantiationMode.LAZY */;
24
- this.onInstanceCreated = null;
25
- }
26
- Component.prototype.setInstantiationMode = function (mode) {
27
- this.instantiationMode = mode;
28
- return this;
29
- };
30
- Component.prototype.setMultipleInstances = function (multipleInstances) {
31
- this.multipleInstances = multipleInstances;
32
- return this;
33
- };
34
- Component.prototype.setServiceProps = function (props) {
35
- this.serviceProps = props;
36
- return this;
37
- };
38
- Component.prototype.setInstanceCreatedCallback = function (callback) {
39
- this.onInstanceCreated = callback;
40
- return this;
41
- };
42
- return Component;
43
- }());
44
-
45
- /**
46
- * @license
47
- * Copyright 2019 Google LLC
48
- *
49
- * Licensed under the Apache License, Version 2.0 (the "License");
50
- * you may not use this file except in compliance with the License.
51
- * You may obtain a copy of the License at
52
- *
53
- * http://www.apache.org/licenses/LICENSE-2.0
54
- *
55
- * Unless required by applicable law or agreed to in writing, software
56
- * distributed under the License is distributed on an "AS IS" BASIS,
57
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58
- * See the License for the specific language governing permissions and
59
- * limitations under the License.
60
- */
61
- var DEFAULT_ENTRY_NAME = '[DEFAULT]';
62
-
63
- /**
64
- * @license
65
- * Copyright 2019 Google LLC
66
- *
67
- * Licensed under the Apache License, Version 2.0 (the "License");
68
- * you may not use this file except in compliance with the License.
69
- * You may obtain a copy of the License at
70
- *
71
- * http://www.apache.org/licenses/LICENSE-2.0
72
- *
73
- * Unless required by applicable law or agreed to in writing, software
74
- * distributed under the License is distributed on an "AS IS" BASIS,
75
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76
- * See the License for the specific language governing permissions and
77
- * limitations under the License.
78
- */
79
- /**
80
- * Provider for instance for service name T, e.g. 'auth', 'auth-internal'
81
- * NameServiceMapping[T] is an alias for the type of the instance
82
- */
83
- var Provider = /** @class */ (function () {
84
- function Provider(name, container) {
85
- this.name = name;
86
- this.container = container;
87
- this.component = null;
88
- this.instances = new Map();
89
- this.instancesDeferred = new Map();
90
- this.instancesOptions = new Map();
91
- this.onInitCallbacks = new Map();
92
- }
93
- /**
94
- * @param identifier A provider can provide multiple instances of a service
95
- * if this.component.multipleInstances is true.
96
- */
97
- Provider.prototype.get = function (identifier) {
98
- // if multipleInstances is not supported, use the default name
99
- var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
100
- if (!this.instancesDeferred.has(normalizedIdentifier)) {
101
- var deferred = new Deferred();
102
- this.instancesDeferred.set(normalizedIdentifier, deferred);
103
- if (this.isInitialized(normalizedIdentifier) ||
104
- this.shouldAutoInitialize()) {
105
- // initialize the service if it can be auto-initialized
106
- try {
107
- var instance = this.getOrInitializeService({
108
- instanceIdentifier: normalizedIdentifier
109
- });
110
- if (instance) {
111
- deferred.resolve(instance);
112
- }
113
- }
114
- catch (e) {
115
- // when the instance factory throws an exception during get(), it should not cause
116
- // a fatal error. We just return the unresolved promise in this case.
117
- }
118
- }
119
- }
120
- return this.instancesDeferred.get(normalizedIdentifier).promise;
121
- };
122
- Provider.prototype.getImmediate = function (options) {
123
- var _a;
124
- // if multipleInstances is not supported, use the default name
125
- var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
126
- var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
127
- if (this.isInitialized(normalizedIdentifier) ||
128
- this.shouldAutoInitialize()) {
129
- try {
130
- return this.getOrInitializeService({
131
- instanceIdentifier: normalizedIdentifier
132
- });
133
- }
134
- catch (e) {
135
- if (optional) {
136
- return null;
137
- }
138
- else {
139
- throw e;
140
- }
141
- }
142
- }
143
- else {
144
- // In case a component is not initialized and should/cannot be auto-initialized at the moment, return null if the optional flag is set, or throw
145
- if (optional) {
146
- return null;
147
- }
148
- else {
149
- throw Error("Service ".concat(this.name, " is not available"));
150
- }
151
- }
152
- };
153
- Provider.prototype.getComponent = function () {
154
- return this.component;
155
- };
156
- Provider.prototype.setComponent = function (component) {
157
- var e_1, _a;
158
- if (component.name !== this.name) {
159
- throw Error("Mismatching Component ".concat(component.name, " for Provider ").concat(this.name, "."));
160
- }
161
- if (this.component) {
162
- throw Error("Component for ".concat(this.name, " has already been provided"));
163
- }
164
- this.component = component;
165
- // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)
166
- if (!this.shouldAutoInitialize()) {
167
- return;
168
- }
169
- // if the service is eager, initialize the default instance
170
- if (isComponentEager(component)) {
171
- try {
172
- this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });
173
- }
174
- catch (e) {
175
- // when the instance factory for an eager Component throws an exception during the eager
176
- // initialization, it should not cause a fatal error.
177
- // TODO: Investigate if we need to make it configurable, because some component may want to cause
178
- // a fatal error in this case?
179
- }
180
- }
181
- try {
182
- // Create service instances for the pending promises and resolve them
183
- // NOTE: if this.multipleInstances is false, only the default instance will be created
184
- // and all promises with resolve with it regardless of the identifier.
185
- for (var _b = __values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
186
- var _d = __read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];
187
- var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
188
- try {
189
- // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
190
- var instance = this.getOrInitializeService({
191
- instanceIdentifier: normalizedIdentifier
192
- });
193
- instanceDeferred.resolve(instance);
194
- }
195
- catch (e) {
196
- // when the instance factory throws an exception, it should not cause
197
- // a fatal error. We just leave the promise unresolved.
198
- }
199
- }
200
- }
201
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
202
- finally {
203
- try {
204
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
205
- }
206
- finally { if (e_1) throw e_1.error; }
207
- }
208
- };
209
- Provider.prototype.clearInstance = function (identifier) {
210
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
211
- this.instancesDeferred.delete(identifier);
212
- this.instancesOptions.delete(identifier);
213
- this.instances.delete(identifier);
214
- };
215
- // app.delete() will call this method on every provider to delete the services
216
- // TODO: should we mark the provider as deleted?
217
- Provider.prototype.delete = function () {
218
- return __awaiter(this, void 0, void 0, function () {
219
- var services;
220
- return __generator(this, function (_a) {
221
- switch (_a.label) {
222
- case 0:
223
- services = Array.from(this.instances.values());
224
- return [4 /*yield*/, Promise.all(__spreadArray(__spreadArray([], __read(services
225
- .filter(function (service) { return 'INTERNAL' in service; }) // legacy services
226
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
- .map(function (service) { return service.INTERNAL.delete(); })), false), __read(services
228
- .filter(function (service) { return '_delete' in service; }) // modularized services
229
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- .map(function (service) { return service._delete(); })), false))];
231
- case 1:
232
- _a.sent();
233
- return [2 /*return*/];
234
- }
235
- });
236
- });
237
- };
238
- Provider.prototype.isComponentSet = function () {
239
- return this.component != null;
240
- };
241
- Provider.prototype.isInitialized = function (identifier) {
242
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
243
- return this.instances.has(identifier);
244
- };
245
- Provider.prototype.getOptions = function (identifier) {
246
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
247
- return this.instancesOptions.get(identifier) || {};
248
- };
249
- Provider.prototype.initialize = function (opts) {
250
- var e_2, _a;
251
- if (opts === void 0) { opts = {}; }
252
- var _b = opts.options, options = _b === void 0 ? {} : _b;
253
- var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
254
- if (this.isInitialized(normalizedIdentifier)) {
255
- throw Error("".concat(this.name, "(").concat(normalizedIdentifier, ") has already been initialized"));
256
- }
257
- if (!this.isComponentSet()) {
258
- throw Error("Component ".concat(this.name, " has not been registered yet"));
259
- }
260
- var instance = this.getOrInitializeService({
261
- instanceIdentifier: normalizedIdentifier,
262
- options: options
263
- });
264
- try {
265
- // resolve any pending promise waiting for the service instance
266
- for (var _c = __values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
267
- var _e = __read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];
268
- var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
269
- if (normalizedIdentifier === normalizedDeferredIdentifier) {
270
- instanceDeferred.resolve(instance);
271
- }
272
- }
273
- }
274
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
275
- finally {
276
- try {
277
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
278
- }
279
- finally { if (e_2) throw e_2.error; }
280
- }
281
- return instance;
282
- };
283
- /**
284
- *
285
- * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().
286
- * The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.
287
- *
288
- * @param identifier An optional instance identifier
289
- * @returns a function to unregister the callback
290
- */
291
- Provider.prototype.onInit = function (callback, identifier) {
292
- var _a;
293
- var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
294
- var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
295
- existingCallbacks.add(callback);
296
- this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
297
- var existingInstance = this.instances.get(normalizedIdentifier);
298
- if (existingInstance) {
299
- callback(existingInstance, normalizedIdentifier);
300
- }
301
- return function () {
302
- existingCallbacks.delete(callback);
303
- };
304
- };
305
- /**
306
- * Invoke onInit callbacks synchronously
307
- * @param instance the service instance`
308
- */
309
- Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {
310
- var e_3, _a;
311
- var callbacks = this.onInitCallbacks.get(identifier);
312
- if (!callbacks) {
313
- return;
314
- }
315
- try {
316
- for (var callbacks_1 = __values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
317
- var callback = callbacks_1_1.value;
318
- try {
319
- callback(instance, identifier);
320
- }
321
- catch (_b) {
322
- // ignore errors in the onInit callback
323
- }
324
- }
325
- }
326
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
327
- finally {
328
- try {
329
- if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
330
- }
331
- finally { if (e_3) throw e_3.error; }
332
- }
333
- };
334
- Provider.prototype.getOrInitializeService = function (_a) {
335
- var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;
336
- var instance = this.instances.get(instanceIdentifier);
337
- if (!instance && this.component) {
338
- instance = this.component.instanceFactory(this.container, {
339
- instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
340
- options: options
341
- });
342
- this.instances.set(instanceIdentifier, instance);
343
- this.instancesOptions.set(instanceIdentifier, options);
344
- /**
345
- * Invoke onInit listeners.
346
- * Note this.component.onInstanceCreated is different, which is used by the component creator,
347
- * while onInit listeners are registered by consumers of the provider.
348
- */
349
- this.invokeOnInitCallbacks(instance, instanceIdentifier);
350
- /**
351
- * Order is important
352
- * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which
353
- * makes `isInitialized()` return true.
354
- */
355
- if (this.component.onInstanceCreated) {
356
- try {
357
- this.component.onInstanceCreated(this.container, instanceIdentifier, instance);
358
- }
359
- catch (_c) {
360
- // ignore errors in the onInstanceCreatedCallback
361
- }
362
- }
363
- }
364
- return instance || null;
365
- };
366
- Provider.prototype.normalizeInstanceIdentifier = function (identifier) {
367
- if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
368
- if (this.component) {
369
- return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;
370
- }
371
- else {
372
- return identifier; // assume multiple instances are supported before the component is provided.
373
- }
374
- };
375
- Provider.prototype.shouldAutoInitialize = function () {
376
- return (!!this.component &&
377
- this.component.instantiationMode !== "EXPLICIT" /* InstantiationMode.EXPLICIT */);
378
- };
379
- return Provider;
380
- }());
381
- // undefined should be passed to the service factory for the default instance
382
- function normalizeIdentifierForFactory(identifier) {
383
- return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;
384
- }
385
- function isComponentEager(component) {
386
- return component.instantiationMode === "EAGER" /* InstantiationMode.EAGER */;
387
- }
388
-
389
- /**
390
- * @license
391
- * Copyright 2019 Google LLC
392
- *
393
- * Licensed under the Apache License, Version 2.0 (the "License");
394
- * you may not use this file except in compliance with the License.
395
- * You may obtain a copy of the License at
396
- *
397
- * http://www.apache.org/licenses/LICENSE-2.0
398
- *
399
- * Unless required by applicable law or agreed to in writing, software
400
- * distributed under the License is distributed on an "AS IS" BASIS,
401
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
402
- * See the License for the specific language governing permissions and
403
- * limitations under the License.
404
- */
405
- /**
406
- * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`
407
- */
408
- var ComponentContainer = /** @class */ (function () {
409
- function ComponentContainer(name) {
410
- this.name = name;
411
- this.providers = new Map();
412
- }
413
- /**
414
- *
415
- * @param component Component being added
416
- * @param overwrite When a component with the same name has already been registered,
417
- * if overwrite is true: overwrite the existing component with the new component and create a new
418
- * provider with the new component. It can be useful in tests where you want to use different mocks
419
- * for different tests.
420
- * if overwrite is false: throw an exception
421
- */
422
- ComponentContainer.prototype.addComponent = function (component) {
423
- var provider = this.getProvider(component.name);
424
- if (provider.isComponentSet()) {
425
- throw new Error("Component ".concat(component.name, " has already been registered with ").concat(this.name));
426
- }
427
- provider.setComponent(component);
428
- };
429
- ComponentContainer.prototype.addOrOverwriteComponent = function (component) {
430
- var provider = this.getProvider(component.name);
431
- if (provider.isComponentSet()) {
432
- // delete the existing provider from the container, so we can register the new component
433
- this.providers.delete(component.name);
434
- }
435
- this.addComponent(component);
436
- };
437
- /**
438
- * getProvider provides a type safe interface where it can only be called with a field name
439
- * present in NameServiceMapping interface.
440
- *
441
- * Firebase SDKs providing services should extend NameServiceMapping interface to register
442
- * themselves.
443
- */
444
- ComponentContainer.prototype.getProvider = function (name) {
445
- if (this.providers.has(name)) {
446
- return this.providers.get(name);
447
- }
448
- // create a Provider for a service that hasn't registered with Firebase
449
- var provider = new Provider(name, this);
450
- this.providers.set(name, provider);
451
- return provider;
452
- };
453
- ComponentContainer.prototype.getProviders = function () {
454
- return Array.from(this.providers.values());
455
- };
456
- return ComponentContainer;
457
- }());
458
-
459
- export { Component, ComponentContainer, Provider };
460
- //# sourceMappingURL=index.esm5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm5.js","sources":["../../src/component.ts","../../src/constants.ts","../../src/provider.ts","../../src/component_container.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n InstantiationMode,\n InstanceFactory,\n ComponentType,\n Dictionary,\n Name,\n onInstanceCreatedCallback\n} from './types';\n\n/**\n * Component for service name T, e.g. `auth`, `auth-internal`\n */\nexport class Component<T extends Name = Name> {\n multipleInstances = false;\n /**\n * Properties to be added to the service namespace\n */\n serviceProps: Dictionary = {};\n\n instantiationMode = InstantiationMode.LAZY;\n\n onInstanceCreated: onInstanceCreatedCallback<T> | null = null;\n\n /**\n *\n * @param name The public service name, e.g. app, auth, firestore, database\n * @param instanceFactory Service factory responsible for creating the public interface\n * @param type whether the service provided by the component is public or private\n */\n constructor(\n readonly name: T,\n readonly instanceFactory: InstanceFactory<T>,\n readonly type: ComponentType\n ) {}\n\n setInstantiationMode(mode: InstantiationMode): this {\n this.instantiationMode = mode;\n return this;\n }\n\n setMultipleInstances(multipleInstances: boolean): this {\n this.multipleInstances = multipleInstances;\n return this;\n }\n\n setServiceProps(props: Dictionary): this {\n this.serviceProps = props;\n return this;\n }\n\n setInstanceCreatedCallback(callback: onInstanceCreatedCallback<T>): this {\n this.onInstanceCreated = callback;\n return this;\n }\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const DEFAULT_ENTRY_NAME = '[DEFAULT]';\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Deferred } from '@firebase/util';\nimport { ComponentContainer } from './component_container';\nimport { DEFAULT_ENTRY_NAME } from './constants';\nimport {\n InitializeOptions,\n InstantiationMode,\n Name,\n NameServiceMapping,\n OnInitCallBack\n} from './types';\nimport { Component } from './component';\n\n/**\n * Provider for instance for service name T, e.g. 'auth', 'auth-internal'\n * NameServiceMapping[T] is an alias for the type of the instance\n */\nexport class Provider<T extends Name> {\n private component: Component<T> | null = null;\n private readonly instances: Map<string, NameServiceMapping[T]> = new Map();\n private readonly instancesDeferred: Map<\n string,\n Deferred<NameServiceMapping[T]>\n > = new Map();\n private readonly instancesOptions: Map<string, Record<string, unknown>> =\n new Map();\n private onInitCallbacks: Map<string, Set<OnInitCallBack<T>>> = new Map();\n\n constructor(\n private readonly name: T,\n private readonly container: ComponentContainer\n ) {}\n\n /**\n * @param identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n */\n get(identifier?: string): Promise<NameServiceMapping[T]> {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n\n if (!this.instancesDeferred.has(normalizedIdentifier)) {\n const deferred = new Deferred<NameServiceMapping[T]>();\n this.instancesDeferred.set(normalizedIdentifier, deferred);\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n // initialize the service if it can be auto-initialized\n try {\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n if (instance) {\n deferred.resolve(instance);\n }\n } catch (e) {\n // when the instance factory throws an exception during get(), it should not cause\n // a fatal error. We just return the unresolved promise in this case.\n }\n }\n }\n\n return this.instancesDeferred.get(normalizedIdentifier)!.promise;\n }\n\n /**\n *\n * @param options.identifier A provider can provide multiple instances of a service\n * if this.component.multipleInstances is true.\n * @param options.optional If optional is false or not provided, the method throws an error when\n * the service is not immediately available.\n * If optional is true, the method returns null if the service is not immediately available.\n */\n getImmediate(options: {\n identifier?: string;\n optional: true;\n }): NameServiceMapping[T] | null;\n getImmediate(options?: {\n identifier?: string;\n optional?: false;\n }): NameServiceMapping[T];\n getImmediate(options?: {\n identifier?: string;\n optional?: boolean;\n }): NameServiceMapping[T] | null {\n // if multipleInstances is not supported, use the default name\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n options?.identifier\n );\n const optional = options?.optional ?? false;\n\n if (\n this.isInitialized(normalizedIdentifier) ||\n this.shouldAutoInitialize()\n ) {\n try {\n return this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n });\n } catch (e) {\n if (optional) {\n return null;\n } else {\n throw e;\n }\n }\n } else {\n // In case a component is not initialized and should/cannot be auto-initialized at the moment, return null if the optional flag is set, or throw\n if (optional) {\n return null;\n } else {\n throw Error(`Service ${this.name} is not available`);\n }\n }\n }\n\n getComponent(): Component<T> | null {\n return this.component;\n }\n\n setComponent(component: Component<T>): void {\n if (component.name !== this.name) {\n throw Error(\n `Mismatching Component ${component.name} for Provider ${this.name}.`\n );\n }\n\n if (this.component) {\n throw Error(`Component for ${this.name} has already been provided`);\n }\n\n this.component = component;\n\n // return early without attempting to initialize the component if the component requires explicit initialization (calling `Provider.initialize()`)\n if (!this.shouldAutoInitialize()) {\n return;\n }\n\n // if the service is eager, initialize the default instance\n if (isComponentEager(component)) {\n try {\n this.getOrInitializeService({ instanceIdentifier: DEFAULT_ENTRY_NAME });\n } catch (e) {\n // when the instance factory for an eager Component throws an exception during the eager\n // initialization, it should not cause a fatal error.\n // TODO: Investigate if we need to make it configurable, because some component may want to cause\n // a fatal error in this case?\n }\n }\n\n // Create service instances for the pending promises and resolve them\n // NOTE: if this.multipleInstances is false, only the default instance will be created\n // and all promises with resolve with it regardless of the identifier.\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n\n try {\n // `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier\n })!;\n instanceDeferred.resolve(instance);\n } catch (e) {\n // when the instance factory throws an exception, it should not cause\n // a fatal error. We just leave the promise unresolved.\n }\n }\n }\n\n clearInstance(identifier: string = DEFAULT_ENTRY_NAME): void {\n this.instancesDeferred.delete(identifier);\n this.instancesOptions.delete(identifier);\n this.instances.delete(identifier);\n }\n\n // app.delete() will call this method on every provider to delete the services\n // TODO: should we mark the provider as deleted?\n async delete(): Promise<void> {\n const services = Array.from(this.instances.values());\n\n await Promise.all([\n ...services\n .filter(service => 'INTERNAL' in service) // legacy services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any).INTERNAL!.delete()),\n ...services\n .filter(service => '_delete' in service) // modularized services\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(service => (service as any)._delete())\n ]);\n }\n\n isComponentSet(): boolean {\n return this.component != null;\n }\n\n isInitialized(identifier: string = DEFAULT_ENTRY_NAME): boolean {\n return this.instances.has(identifier);\n }\n\n getOptions(identifier: string = DEFAULT_ENTRY_NAME): Record<string, unknown> {\n return this.instancesOptions.get(identifier) || {};\n }\n\n initialize(opts: InitializeOptions = {}): NameServiceMapping[T] {\n const { options = {} } = opts;\n const normalizedIdentifier = this.normalizeInstanceIdentifier(\n opts.instanceIdentifier\n );\n if (this.isInitialized(normalizedIdentifier)) {\n throw Error(\n `${this.name}(${normalizedIdentifier}) has already been initialized`\n );\n }\n\n if (!this.isComponentSet()) {\n throw Error(`Component ${this.name} has not been registered yet`);\n }\n\n const instance = this.getOrInitializeService({\n instanceIdentifier: normalizedIdentifier,\n options\n })!;\n\n // resolve any pending promise waiting for the service instance\n for (const [\n instanceIdentifier,\n instanceDeferred\n ] of this.instancesDeferred.entries()) {\n const normalizedDeferredIdentifier =\n this.normalizeInstanceIdentifier(instanceIdentifier);\n if (normalizedIdentifier === normalizedDeferredIdentifier) {\n instanceDeferred.resolve(instance);\n }\n }\n\n return instance;\n }\n\n /**\n *\n * @param callback - a function that will be invoked after the provider has been initialized by calling provider.initialize().\n * The function is invoked SYNCHRONOUSLY, so it should not execute any longrunning tasks in order to not block the program.\n *\n * @param identifier An optional instance identifier\n * @returns a function to unregister the callback\n */\n onInit(callback: OnInitCallBack<T>, identifier?: string): () => void {\n const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);\n const existingCallbacks =\n this.onInitCallbacks.get(normalizedIdentifier) ??\n new Set<OnInitCallBack<T>>();\n existingCallbacks.add(callback);\n this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);\n\n const existingInstance = this.instances.get(normalizedIdentifier);\n if (existingInstance) {\n callback(existingInstance, normalizedIdentifier);\n }\n\n return () => {\n existingCallbacks.delete(callback);\n };\n }\n\n /**\n * Invoke onInit callbacks synchronously\n * @param instance the service instance`\n */\n private invokeOnInitCallbacks(\n instance: NameServiceMapping[T],\n identifier: string\n ): void {\n const callbacks = this.onInitCallbacks.get(identifier);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n try {\n callback(instance, identifier);\n } catch {\n // ignore errors in the onInit callback\n }\n }\n }\n\n private getOrInitializeService({\n instanceIdentifier,\n options = {}\n }: {\n instanceIdentifier: string;\n options?: Record<string, unknown>;\n }): NameServiceMapping[T] | null {\n let instance = this.instances.get(instanceIdentifier);\n if (!instance && this.component) {\n instance = this.component.instanceFactory(this.container, {\n instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),\n options\n });\n this.instances.set(instanceIdentifier, instance);\n this.instancesOptions.set(instanceIdentifier, options);\n\n /**\n * Invoke onInit listeners.\n * Note this.component.onInstanceCreated is different, which is used by the component creator,\n * while onInit listeners are registered by consumers of the provider.\n */\n this.invokeOnInitCallbacks(instance, instanceIdentifier);\n\n /**\n * Order is important\n * onInstanceCreated() should be called after this.instances.set(instanceIdentifier, instance); which\n * makes `isInitialized()` return true.\n */\n if (this.component.onInstanceCreated) {\n try {\n this.component.onInstanceCreated(\n this.container,\n instanceIdentifier,\n instance\n );\n } catch {\n // ignore errors in the onInstanceCreatedCallback\n }\n }\n }\n\n return instance || null;\n }\n\n private normalizeInstanceIdentifier(\n identifier: string = DEFAULT_ENTRY_NAME\n ): string {\n if (this.component) {\n return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;\n } else {\n return identifier; // assume multiple instances are supported before the component is provided.\n }\n }\n\n private shouldAutoInitialize(): boolean {\n return (\n !!this.component &&\n this.component.instantiationMode !== InstantiationMode.EXPLICIT\n );\n }\n}\n\n// undefined should be passed to the service factory for the default instance\nfunction normalizeIdentifierForFactory(identifier: string): string | undefined {\n return identifier === DEFAULT_ENTRY_NAME ? undefined : identifier;\n}\n\nfunction isComponentEager<T extends Name>(component: Component<T>): boolean {\n return component.instantiationMode === InstantiationMode.EAGER;\n}\n","/**\n * @license\n * Copyright 2019 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Provider } from './provider';\nimport { Component } from './component';\nimport { Name } from './types';\n\n/**\n * ComponentContainer that provides Providers for service name T, e.g. `auth`, `auth-internal`\n */\nexport class ComponentContainer {\n private readonly providers = new Map<string, Provider<Name>>();\n\n constructor(private readonly name: string) {}\n\n /**\n *\n * @param component Component being added\n * @param overwrite When a component with the same name has already been registered,\n * if overwrite is true: overwrite the existing component with the new component and create a new\n * provider with the new component. It can be useful in tests where you want to use different mocks\n * for different tests.\n * if overwrite is false: throw an exception\n */\n addComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n throw new Error(\n `Component ${component.name} has already been registered with ${this.name}`\n );\n }\n\n provider.setComponent(component);\n }\n\n addOrOverwriteComponent<T extends Name>(component: Component<T>): void {\n const provider = this.getProvider(component.name);\n if (provider.isComponentSet()) {\n // delete the existing provider from the container, so we can register the new component\n this.providers.delete(component.name);\n }\n\n this.addComponent(component);\n }\n\n /**\n * getProvider provides a type safe interface where it can only be called with a field name\n * present in NameServiceMapping interface.\n *\n * Firebase SDKs providing services should extend NameServiceMapping interface to register\n * themselves.\n */\n getProvider<T extends Name>(name: T): Provider<T> {\n if (this.providers.has(name)) {\n return this.providers.get(name) as unknown as Provider<T>;\n }\n\n // create a Provider for a service that hasn't registered with Firebase\n const provider = new Provider<T>(name, this);\n this.providers.set(name, provider as unknown as Provider<Name>);\n\n return provider as Provider<T>;\n }\n\n getProviders(): Array<Provider<Name>> {\n return Array.from(this.provid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