Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/component

Package Overview
Dependencies
Maintainers
4
Versions
2332
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/component - npm Package Compare versions

Comparing version 0.6.9-canary.beaa4dffb to 0.6.9-vertexai-preview.36cb0178c

285

dist/index.cjs.js

@@ -5,3 +5,2 @@ 'use strict';

var tslib = require('tslib');
var util = require('@firebase/util');

@@ -12,3 +11,3 @@

*/
var Component = /** @class */ (function () {
class Component {
/**

@@ -20,3 +19,3 @@ *

*/
function Component(name, instanceFactory, type) {
constructor(name, instanceFactory, type) {
this.name = name;

@@ -33,20 +32,19 @@ this.instanceFactory = instanceFactory;

}
Component.prototype.setInstantiationMode = function (mode) {
setInstantiationMode(mode) {
this.instantiationMode = mode;
return this;
};
Component.prototype.setMultipleInstances = function (multipleInstances) {
}
setMultipleInstances(multipleInstances) {
this.multipleInstances = multipleInstances;
return this;
};
Component.prototype.setServiceProps = function (props) {
}
setServiceProps(props) {
this.serviceProps = props;
return this;
};
Component.prototype.setInstanceCreatedCallback = function (callback) {
}
setInstanceCreatedCallback(callback) {
this.onInstanceCreated = callback;
return this;
};
return Component;
}());
}
}

@@ -69,3 +67,3 @@ /**

*/
var DEFAULT_ENTRY_NAME = '[DEFAULT]';
const DEFAULT_ENTRY_NAME = '[DEFAULT]';

@@ -92,4 +90,4 @@ /**

*/
var Provider = /** @class */ (function () {
function Provider(name, container) {
class Provider {
constructor(name, container) {
this.name = name;

@@ -107,7 +105,7 @@ this.container = container;

*/
Provider.prototype.get = function (identifier) {
get(identifier) {
// if multipleInstances is not supported, use the default name
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
if (!this.instancesDeferred.has(normalizedIdentifier)) {
var deferred = new util.Deferred();
const deferred = new util.Deferred();
this.instancesDeferred.set(normalizedIdentifier, deferred);

@@ -118,3 +116,3 @@ if (this.isInitialized(normalizedIdentifier) ||

try {
var instance = this.getOrInitializeService({
const instance = this.getOrInitializeService({
instanceIdentifier: normalizedIdentifier

@@ -133,8 +131,8 @@ });

return this.instancesDeferred.get(normalizedIdentifier).promise;
};
Provider.prototype.getImmediate = function (options) {
}
getImmediate(options) {
var _a;
// if multipleInstances is not supported, use the default name
var normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
var optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
const normalizedIdentifier = this.normalizeInstanceIdentifier(options === null || options === void 0 ? void 0 : options.identifier);
const optional = (_a = options === null || options === void 0 ? void 0 : options.optional) !== null && _a !== void 0 ? _a : false;
if (this.isInitialized(normalizedIdentifier) ||

@@ -162,16 +160,15 @@ this.shouldAutoInitialize()) {

else {
throw Error("Service ".concat(this.name, " is not available"));
throw Error(`Service ${this.name} is not available`);
}
}
};
Provider.prototype.getComponent = function () {
}
getComponent() {
return this.component;
};
Provider.prototype.setComponent = function (component) {
var e_1, _a;
}
setComponent(component) {
if (component.name !== this.name) {
throw Error("Mismatching Component ".concat(component.name, " for Provider ").concat(this.name, "."));
throw Error(`Mismatching Component ${component.name} for Provider ${this.name}.`);
}
if (this.component) {
throw Error("Component for ".concat(this.name, " has already been provided"));
throw Error(`Component for ${this.name} has already been provided`);
}

@@ -195,104 +192,71 @@ this.component = component;

}
try {
// Create service instances for the pending promises and resolve them
// NOTE: if this.multipleInstances is false, only the default instance will be created
// and all promises with resolve with it regardless of the identifier.
for (var _b = tslib.__values(this.instancesDeferred.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = tslib.__read(_c.value, 2), instanceIdentifier = _d[0], instanceDeferred = _d[1];
var normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
try {
// `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
var instance = this.getOrInitializeService({
instanceIdentifier: normalizedIdentifier
});
instanceDeferred.resolve(instance);
}
catch (e) {
// when the instance factory throws an exception, it should not cause
// a fatal error. We just leave the promise unresolved.
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
// Create service instances for the pending promises and resolve them
// NOTE: if this.multipleInstances is false, only the default instance will be created
// and all promises with resolve with it regardless of the identifier.
for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
const normalizedIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
// `getOrInitializeService()` should always return a valid instance since a component is guaranteed. use ! to make typescript happy.
const instance = this.getOrInitializeService({
instanceIdentifier: normalizedIdentifier
});
instanceDeferred.resolve(instance);
}
finally { if (e_1) throw e_1.error; }
catch (e) {
// when the instance factory throws an exception, it should not cause
// a fatal error. We just leave the promise unresolved.
}
}
};
Provider.prototype.clearInstance = function (identifier) {
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
}
clearInstance(identifier = DEFAULT_ENTRY_NAME) {
this.instancesDeferred.delete(identifier);
this.instancesOptions.delete(identifier);
this.instances.delete(identifier);
};
}
// app.delete() will call this method on every provider to delete the services
// TODO: should we mark the provider as deleted?
Provider.prototype.delete = function () {
return tslib.__awaiter(this, void 0, void 0, function () {
var services;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0:
services = Array.from(this.instances.values());
return [4 /*yield*/, Promise.all(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(services
.filter(function (service) { return 'INTERNAL' in service; }) // legacy services
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map(function (service) { return service.INTERNAL.delete(); })), false), tslib.__read(services
.filter(function (service) { return '_delete' in service; }) // modularized services
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map(function (service) { return service._delete(); })), false))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
Provider.prototype.isComponentSet = function () {
async delete() {
const services = Array.from(this.instances.values());
await Promise.all([
...services
.filter(service => 'INTERNAL' in service) // legacy services
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map(service => service.INTERNAL.delete()),
...services
.filter(service => '_delete' in service) // modularized services
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map(service => service._delete())
]);
}
isComponentSet() {
return this.component != null;
};
Provider.prototype.isInitialized = function (identifier) {
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
}
isInitialized(identifier = DEFAULT_ENTRY_NAME) {
return this.instances.has(identifier);
};
Provider.prototype.getOptions = function (identifier) {
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
}
getOptions(identifier = DEFAULT_ENTRY_NAME) {
return this.instancesOptions.get(identifier) || {};
};
Provider.prototype.initialize = function (opts) {
var e_2, _a;
if (opts === void 0) { opts = {}; }
var _b = opts.options, options = _b === void 0 ? {} : _b;
var normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
}
initialize(opts = {}) {
const { options = {} } = opts;
const normalizedIdentifier = this.normalizeInstanceIdentifier(opts.instanceIdentifier);
if (this.isInitialized(normalizedIdentifier)) {
throw Error("".concat(this.name, "(").concat(normalizedIdentifier, ") has already been initialized"));
throw Error(`${this.name}(${normalizedIdentifier}) has already been initialized`);
}
if (!this.isComponentSet()) {
throw Error("Component ".concat(this.name, " has not been registered yet"));
throw Error(`Component ${this.name} has not been registered yet`);
}
var instance = this.getOrInitializeService({
const instance = this.getOrInitializeService({
instanceIdentifier: normalizedIdentifier,
options: options
options
});
try {
// resolve any pending promise waiting for the service instance
for (var _c = tslib.__values(this.instancesDeferred.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = tslib.__read(_d.value, 2), instanceIdentifier = _e[0], instanceDeferred = _e[1];
var normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
if (normalizedIdentifier === normalizedDeferredIdentifier) {
instanceDeferred.resolve(instance);
}
// resolve any pending promise waiting for the service instance
for (const [instanceIdentifier, instanceDeferred] of this.instancesDeferred.entries()) {
const normalizedDeferredIdentifier = this.normalizeInstanceIdentifier(instanceIdentifier);
if (normalizedIdentifier === normalizedDeferredIdentifier) {
instanceDeferred.resolve(instance);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
return instance;
};
}
/**

@@ -306,16 +270,16 @@ *

*/
Provider.prototype.onInit = function (callback, identifier) {
onInit(callback, identifier) {
var _a;
var normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
var existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
const existingCallbacks = (_a = this.onInitCallbacks.get(normalizedIdentifier)) !== null && _a !== void 0 ? _a : new Set();
existingCallbacks.add(callback);
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
var existingInstance = this.instances.get(normalizedIdentifier);
const existingInstance = this.instances.get(normalizedIdentifier);
if (existingInstance) {
callback(existingInstance, normalizedIdentifier);
}
return function () {
return () => {
existingCallbacks.delete(callback);
};
};
}
/**

@@ -325,34 +289,22 @@ * Invoke onInit callbacks synchronously

*/
Provider.prototype.invokeOnInitCallbacks = function (instance, identifier) {
var e_3, _a;
var callbacks = this.onInitCallbacks.get(identifier);
invokeOnInitCallbacks(instance, identifier) {
const callbacks = this.onInitCallbacks.get(identifier);
if (!callbacks) {
return;
}
try {
for (var callbacks_1 = tslib.__values(callbacks), callbacks_1_1 = callbacks_1.next(); !callbacks_1_1.done; callbacks_1_1 = callbacks_1.next()) {
var callback = callbacks_1_1.value;
try {
callback(instance, identifier);
}
catch (_b) {
// ignore errors in the onInit callback
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
for (const callback of callbacks) {
try {
if (callbacks_1_1 && !callbacks_1_1.done && (_a = callbacks_1.return)) _a.call(callbacks_1);
callback(instance, identifier);
}
finally { if (e_3) throw e_3.error; }
catch (_a) {
// ignore errors in the onInit callback
}
}
};
Provider.prototype.getOrInitializeService = function (_a) {
var instanceIdentifier = _a.instanceIdentifier, _b = _a.options, options = _b === void 0 ? {} : _b;
var instance = this.instances.get(instanceIdentifier);
}
getOrInitializeService({ instanceIdentifier, options = {} }) {
let instance = this.instances.get(instanceIdentifier);
if (!instance && this.component) {
instance = this.component.instanceFactory(this.container, {
instanceIdentifier: normalizeIdentifierForFactory(instanceIdentifier),
options: options
options
});

@@ -376,3 +328,3 @@ this.instances.set(instanceIdentifier, instance);

}
catch (_c) {
catch (_a) {
// ignore errors in the onInstanceCreatedCallback

@@ -383,5 +335,4 @@ }

return instance || null;
};
Provider.prototype.normalizeInstanceIdentifier = function (identifier) {
if (identifier === void 0) { identifier = DEFAULT_ENTRY_NAME; }
}
normalizeInstanceIdentifier(identifier = DEFAULT_ENTRY_NAME) {
if (this.component) {

@@ -393,9 +344,8 @@ return this.component.multipleInstances ? identifier : DEFAULT_ENTRY_NAME;

}
};
Provider.prototype.shouldAutoInitialize = function () {
}
shouldAutoInitialize() {
return (!!this.component &&
this.component.instantiationMode !== "EXPLICIT" /* InstantiationMode.EXPLICIT */);
};
return Provider;
}());
}
}
// undefined should be passed to the service factory for the default instance

@@ -428,4 +378,4 @@ function normalizeIdentifierForFactory(identifier) {

*/
var ComponentContainer = /** @class */ (function () {
function ComponentContainer(name) {
class ComponentContainer {
constructor(name) {
this.name = name;

@@ -443,11 +393,11 @@ this.providers = new Map();

*/
ComponentContainer.prototype.addComponent = function (component) {
var provider = this.getProvider(component.name);
addComponent(component) {
const provider = this.getProvider(component.name);
if (provider.isComponentSet()) {
throw new Error("Component ".concat(component.name, " has already been registered with ").concat(this.name));
throw new Error(`Component ${component.name} has already been registered with ${this.name}`);
}
provider.setComponent(component);
};
ComponentContainer.prototype.addOrOverwriteComponent = function (component) {
var provider = this.getProvider(component.name);
}
addOrOverwriteComponent(component) {
const provider = this.getProvider(component.name);
if (provider.isComponentSet()) {

@@ -458,3 +408,3 @@ // delete the existing provider from the container, so we can register the new component

this.addComponent(component);
};
}
/**

@@ -467,3 +417,3 @@ * getProvider provides a type safe interface where it can only be called with a field name

*/
ComponentContainer.prototype.getProvider = function (name) {
getProvider(name) {
if (this.providers.has(name)) {

@@ -473,11 +423,10 @@ return this.providers.get(name);

// create a Provider for a service that hasn't registered with Firebase
var provider = new Provider(name, this);
const provider = new Provider(name, this);
this.providers.set(name, provider);
return provider;
};
ComponentContainer.prototype.getProviders = function () {
}
getProviders() {
return Array.from(this.providers.values());
};
return ComponentContainer;
}());
}
}

@@ -484,0 +433,0 @@ exports.Component = Component;

{
"name": "@firebase/component",
"version": "0.6.9-canary.beaa4dffb",
"version": "0.6.9-vertexai-preview.36cb0178c",
"description": "Firebase Component Platform",

@@ -9,3 +9,2 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"module": "dist/esm/index.esm2017.js",
"esm5": "dist/esm/index.esm5.js",
"exports": {

@@ -15,3 +14,2 @@ ".": {

"require": "./dist/index.cjs.js",
"esm5": "./dist/esm/index.esm5.js",
"default": "./dist/esm/index.esm2017.js"

@@ -38,3 +36,3 @@ },

"dependencies": {
"@firebase/util": "1.10.0-canary.beaa4dffb",
"@firebase/util": "1.10.0-vertexai-preview.36cb0178c",
"tslib": "^2.1.0"

@@ -62,3 +60,6 @@ },

"reportDir": "./coverage/node"
},
"engines": {
"node": ">=18.0.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc