abstracted-firebase
Advanced tools
Comparing version 0.27.0 to 0.27.1
@@ -5,3 +5,3 @@ import { IDictionary } from "common-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet } from "./types"; | ||
import { IFirebaseConfig, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet, IClientEmitter, IAdminEmitter } from "./types"; | ||
import { IFirebaseListener, IFirebaseConnectionCallback } from "."; | ||
@@ -15,2 +15,3 @@ declare type Mock = import("firemock").Mock; | ||
readonly isConnected: boolean; | ||
readonly config: IFirebaseConfig; | ||
static connect: (config: any) => Promise<any>; | ||
@@ -21,3 +22,3 @@ /** how many miliseconds before the attempt to connect to DB is timed out */ | ||
enableDatabaseLogging: (logger?: boolean | ((a: string) => any), persistent?: boolean) => any; | ||
protected abstract _eventManager: IEmitter; | ||
protected abstract _eventManager: IClientEmitter | IAdminEmitter; | ||
protected abstract _clientType: "client" | "admin"; | ||
@@ -40,2 +41,5 @@ protected _isConnected: boolean; | ||
constructor(config: IFirebaseConfig); | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config?: IFirebaseConfig): void; | ||
@@ -70,5 +74,15 @@ /** | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, ctx?: IDictionary): string; | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx?: IDictionary): string; | ||
/** | ||
* removes a callback notification previously registered | ||
@@ -75,0 +89,0 @@ */ |
@@ -55,2 +55,8 @@ "use strict"; | ||
} | ||
get config() { | ||
return this._config; | ||
} | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config = {}) { | ||
@@ -146,11 +152,18 @@ this._mocking = config.mocking ? true : false; | ||
} | ||
const connectionEvent = async () => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
return; | ||
} | ||
else { | ||
throw new AbstractedError_1.AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`); | ||
} | ||
}); | ||
const connectionEvent = () => { | ||
try { | ||
return new Promise((resolve, reject) => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
resolve(); | ||
} | ||
else { | ||
reject(new AbstractedError_1.AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`)); | ||
} | ||
}); | ||
}); | ||
} | ||
catch (e) { | ||
throw e; | ||
} | ||
}; | ||
@@ -161,3 +174,3 @@ const timeout = async () => { | ||
}; | ||
await Promise.race([connectionEvent, timeout]); | ||
await Promise.race([connectionEvent(), timeout()]); | ||
this._isConnected = true; | ||
@@ -172,4 +185,14 @@ return this; | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb, id, ctx) { | ||
notifyWhenConnected(cb, id, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx) { | ||
if (!id) { | ||
@@ -497,4 +520,6 @@ id = Math.random() | ||
if (this._isConnected) { | ||
// this._eventManager.connection(this._isConnected); | ||
this._onConnected.forEach(listener => listener.cb(this)); | ||
if (this._eventManager.connection) { | ||
this._eventManager.connection(this._isConnected); | ||
} | ||
this._onConnected.forEach(listener => listener.ctx ? listener.cb.bind(listener.ctx)(this) : listener.cb.bind(this)()); | ||
} | ||
@@ -501,0 +526,0 @@ else { |
@@ -19,2 +19,8 @@ import { DataSnapshot, OnDisconnect, Query, ThenableReference, EventType } from "@firebase/database-types"; | ||
} | ||
export interface IClientEmitter extends IEmitter { | ||
connection: (state: boolean) => void; | ||
} | ||
export interface IAdminEmitter extends IEmitter { | ||
connection: undefined; | ||
} | ||
export interface IPathSetter<T = any> { | ||
@@ -21,0 +27,0 @@ path: string; |
@@ -5,3 +5,3 @@ import { IDictionary } from "common-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet } from "./types"; | ||
import { IFirebaseConfig, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet, IClientEmitter, IAdminEmitter } from "./types"; | ||
import { IFirebaseListener, IFirebaseConnectionCallback } from "."; | ||
@@ -15,2 +15,3 @@ declare type Mock = import("firemock").Mock; | ||
readonly isConnected: boolean; | ||
readonly config: IFirebaseConfig; | ||
static connect: (config: any) => Promise<any>; | ||
@@ -21,3 +22,3 @@ /** how many miliseconds before the attempt to connect to DB is timed out */ | ||
enableDatabaseLogging: (logger?: boolean | ((a: string) => any), persistent?: boolean) => any; | ||
protected abstract _eventManager: IEmitter; | ||
protected abstract _eventManager: IClientEmitter | IAdminEmitter; | ||
protected abstract _clientType: "client" | "admin"; | ||
@@ -40,2 +41,5 @@ protected _isConnected: boolean; | ||
constructor(config: IFirebaseConfig); | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config?: IFirebaseConfig): void; | ||
@@ -70,5 +74,15 @@ /** | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, ctx?: IDictionary): string; | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx?: IDictionary): string; | ||
/** | ||
* removes a callback notification previously registered | ||
@@ -75,0 +89,0 @@ */ |
@@ -53,2 +53,8 @@ // tslint:disable:no-implicit-dependencies | ||
} | ||
get config() { | ||
return this._config; | ||
} | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config = {}) { | ||
@@ -144,11 +150,18 @@ this._mocking = config.mocking ? true : false; | ||
} | ||
const connectionEvent = async () => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
return; | ||
} | ||
else { | ||
throw new AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`); | ||
} | ||
}); | ||
const connectionEvent = () => { | ||
try { | ||
return new Promise((resolve, reject) => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
resolve(); | ||
} | ||
else { | ||
reject(new AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`)); | ||
} | ||
}); | ||
}); | ||
} | ||
catch (e) { | ||
throw e; | ||
} | ||
}; | ||
@@ -159,3 +172,3 @@ const timeout = async () => { | ||
}; | ||
await Promise.race([connectionEvent, timeout]); | ||
await Promise.race([connectionEvent(), timeout()]); | ||
this._isConnected = true; | ||
@@ -170,4 +183,14 @@ return this; | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb, id, ctx) { | ||
notifyWhenConnected(cb, id, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx) { | ||
if (!id) { | ||
@@ -495,4 +518,6 @@ id = Math.random() | ||
if (this._isConnected) { | ||
// this._eventManager.connection(this._isConnected); | ||
this._onConnected.forEach(listener => listener.cb(this)); | ||
if (this._eventManager.connection) { | ||
this._eventManager.connection(this._isConnected); | ||
} | ||
this._onConnected.forEach(listener => listener.ctx ? listener.cb.bind(listener.ctx)(this) : listener.cb.bind(this)()); | ||
} | ||
@@ -499,0 +524,0 @@ else { |
@@ -19,2 +19,8 @@ import { DataSnapshot, OnDisconnect, Query, ThenableReference, EventType } from "@firebase/database-types"; | ||
} | ||
export interface IClientEmitter extends IEmitter { | ||
connection: (state: boolean) => void; | ||
} | ||
export interface IAdminEmitter extends IEmitter { | ||
connection: undefined; | ||
} | ||
export interface IPathSetter<T = any> { | ||
@@ -21,0 +27,0 @@ path: string; |
@@ -5,3 +5,3 @@ import { IDictionary } from "common-types"; | ||
import { FirebaseDatabase, DataSnapshot, EventType, Reference } from "@firebase/database-types"; | ||
import { IFirebaseConfig, IEmitter, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet } from "./types"; | ||
import { IFirebaseConfig, IMockLoadingState, IFirebaseWatchHandler, IMultiPathSet, IClientEmitter, IAdminEmitter } from "./types"; | ||
import { IFirebaseListener, IFirebaseConnectionCallback } from "."; | ||
@@ -15,2 +15,3 @@ declare type Mock = import("firemock").Mock; | ||
readonly isConnected: boolean; | ||
readonly config: IFirebaseConfig; | ||
static connect: (config: any) => Promise<any>; | ||
@@ -21,3 +22,3 @@ /** how many miliseconds before the attempt to connect to DB is timed out */ | ||
enableDatabaseLogging: (logger?: boolean | ((a: string) => any), persistent?: boolean) => any; | ||
protected abstract _eventManager: IEmitter; | ||
protected abstract _eventManager: IClientEmitter | IAdminEmitter; | ||
protected abstract _clientType: "client" | "admin"; | ||
@@ -40,2 +41,5 @@ protected _isConnected: boolean; | ||
constructor(config: IFirebaseConfig); | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config?: IFirebaseConfig): void; | ||
@@ -70,5 +74,15 @@ /** | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, ctx?: IDictionary): string; | ||
notifyWhenConnected(cb: IFirebaseConnectionCallback, id?: string, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx?: IDictionary): string; | ||
/** | ||
* removes a callback notification previously registered | ||
@@ -75,0 +89,0 @@ */ |
@@ -65,2 +65,8 @@ (function (factory) { | ||
} | ||
get config() { | ||
return this._config; | ||
} | ||
/** | ||
* called by `client` and `admin` at end of constructor | ||
*/ | ||
initialize(config = {}) { | ||
@@ -156,11 +162,18 @@ this._mocking = config.mocking ? true : false; | ||
} | ||
const connectionEvent = async () => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
return; | ||
} | ||
else { | ||
throw new AbstractedError_1.AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`); | ||
} | ||
}); | ||
const connectionEvent = () => { | ||
try { | ||
return new Promise((resolve, reject) => { | ||
this._eventManager.once("connection", (state) => { | ||
if (state) { | ||
resolve(); | ||
} | ||
else { | ||
reject(new AbstractedError_1.AbstractedError(`While waiting for a connection received a disconnect message instead`, `no-connection`)); | ||
} | ||
}); | ||
}); | ||
} | ||
catch (e) { | ||
throw e; | ||
} | ||
}; | ||
@@ -171,3 +184,3 @@ const timeout = async () => { | ||
}; | ||
await Promise.race([connectionEvent, timeout]); | ||
await Promise.race([connectionEvent(), timeout()]); | ||
this._isConnected = true; | ||
@@ -182,4 +195,14 @@ return this; | ||
* state a unique id of your own. | ||
* | ||
* By default the callback will receive the database connection as it's | ||
* `this`/context. This means that any locally defined variables will be | ||
* dereferenced an unavailable. If you want to retain a connection to this | ||
* state you should include the optional _context_ parameter and your | ||
* callback will get a parameter passed back with this context available. | ||
*/ | ||
notifyWhenConnected(cb, id, ctx) { | ||
notifyWhenConnected(cb, id, | ||
/** | ||
* additional context/pointers for your callback to use when activated | ||
*/ | ||
ctx) { | ||
if (!id) { | ||
@@ -507,4 +530,6 @@ id = Math.random() | ||
if (this._isConnected) { | ||
// this._eventManager.connection(this._isConnected); | ||
this._onConnected.forEach(listener => listener.cb(this)); | ||
if (this._eventManager.connection) { | ||
this._eventManager.connection(this._isConnected); | ||
} | ||
this._onConnected.forEach(listener => listener.ctx ? listener.cb.bind(listener.ctx)(this) : listener.cb.bind(this)()); | ||
} | ||
@@ -511,0 +536,0 @@ else { |
@@ -19,2 +19,8 @@ import { DataSnapshot, OnDisconnect, Query, ThenableReference, EventType } from "@firebase/database-types"; | ||
} | ||
export interface IClientEmitter extends IEmitter { | ||
connection: (state: boolean) => void; | ||
} | ||
export interface IAdminEmitter extends IEmitter { | ||
connection: undefined; | ||
} | ||
export interface IPathSetter<T = any> { | ||
@@ -21,0 +27,0 @@ path: string; |
{ | ||
"name": "abstracted-firebase", | ||
"version": "0.27.0", | ||
"version": "0.27.1", | ||
"description": "Core functional library supporting 'abstracted-admin' and 'abstracted-client'", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144304
3470