-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate definition files for distribution
- Loading branch information
1 parent
ca6bbff
commit ac3505e
Showing
34 changed files
with
1,692 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export interface Stage { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ObjectID, Binary } from "mongodb"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Cache { | ||
set<T>(key: string, value: T): void; | ||
get<T>(key: string): Promise<T>; | ||
clear(key: string): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface CacheDirector { | ||
valid<T>(object: T): boolean; | ||
buildKey<T>(object: T): string; | ||
validQuery(conditions: any): boolean; | ||
buildQueryKey(conditions: any): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
export interface Configuration { | ||
host?: string; | ||
port?: number; | ||
hosts?: { | ||
address: string; | ||
port?: number; | ||
}[]; | ||
database?: string; | ||
username?: string; | ||
password?: string; | ||
options?: ConnectionOptions; | ||
[key: string]: any; | ||
} | ||
export interface ConnectionOptions { | ||
db?: DatabaseLevelConnectionOptions; | ||
server?: ServerLevelConnectionOptions; | ||
replset?: ReplicasetLevelConnectionOptions; | ||
mongos?: MongosLevelConnectionOptions; | ||
} | ||
export interface DatabaseLevelConnectionOptions { | ||
/** | ||
* The write concern for the operation where < 1 is no acknowledgment of write and w >= 1 or w = ‘majority’ acknowledges the write | ||
*/ | ||
w?: string | number; | ||
/** | ||
* Set the timeout for waiting for write concern to finish (combines with w option) | ||
*/ | ||
wtimeout?: number; | ||
/** | ||
* Write waits for fsync before returning | ||
*/ | ||
fsync?: boolean; | ||
/** | ||
* Write waits for journal sync before returning | ||
*/ | ||
j?: boolean; | ||
/** | ||
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). | ||
*/ | ||
readPreference?: string; | ||
/** | ||
* The tags object {‘loc’:‘ny’} used with the readPreference. | ||
*/ | ||
readPreferenceTags?: any; | ||
/** | ||
* Use c++ bson parser. | ||
*/ | ||
native_parser?: boolean; | ||
/** | ||
* Force server to create _id fields instead of client. | ||
*/ | ||
forceServerObjectId?: boolean; | ||
/** | ||
* Object overriding the basic ObjectID primary key generation. | ||
*/ | ||
pkFactory?: any; | ||
/** | ||
* Serialize functions. | ||
*/ | ||
serializeFunctions?: boolean; | ||
/** | ||
* Perform operations using raw bson buffers. | ||
*/ | ||
raw?: boolean; | ||
/** | ||
* Number of milliseconds between retries. | ||
*/ | ||
retryMiliseconds?: number; | ||
/** | ||
* Number of retries off connection. | ||
*/ | ||
numberOfRetries?: number; | ||
/** | ||
* Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited. | ||
*/ | ||
bufferMaxEntries?: number; | ||
} | ||
export interface ServerLevelConnectionOptions extends BasicConnectionOptions { | ||
autoReconnect?: boolean; | ||
} | ||
export interface ReplicasetLevelConnectionOptions extends MongosLevelConnectionOptions { | ||
replicaSet?: string; | ||
connectWithNoPrimary?: boolean; | ||
} | ||
export interface MongosLevelConnectionOptions extends BasicConnectionOptions { | ||
ha?: boolean; | ||
haInterval?: number; | ||
secondaryAcceptableLatencyMS?: number; | ||
} | ||
export interface BasicConnectionOptions { | ||
poolSize?: number; | ||
ssl?: boolean; | ||
sslValidate?: boolean; | ||
sslCA?: Buffer[] | string[]; | ||
sslCert?: Buffer | string; | ||
sslKey?: Buffer | string; | ||
sslPass?: Buffer | string; | ||
socketOptions?: { | ||
noDelay?: boolean; | ||
keepAlive?: number; | ||
connectTimeoutMS?: number; | ||
socketTimeoutMS?: number; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import * as Bluebird from "bluebird"; | ||
import * as MongoDB from "mongodb"; | ||
import { Configuration } from "./Configuration"; | ||
import { Plugin } from "./Plugins"; | ||
import * as ExpressMiddleware from "./middleware/Express"; | ||
import { Cache } from "./Cache"; | ||
/** | ||
* The Iridium Core, responsible for managing the connection to the database as well | ||
* as any plugins you are making use of. | ||
* | ||
* Generally you will subclass this to provide your own custom core with the models you | ||
* make use of within your application. | ||
*/ | ||
export declare class Core { | ||
/** | ||
* Creates a new Iridium Core instance connected to the specified MongoDB instance | ||
* @param {Iridium.IridiumConfiguration} config The config object defining the database to connect to | ||
* @constructs Core | ||
*/ | ||
constructor(config: Configuration); | ||
/** | ||
* Creates a new Iridium Core instance connected to the specified MongoDB instance | ||
* @param {String} url The URL of the MongoDB instance to connect to | ||
* @param {Iridium.IridiumConfiguration} config The config object made available as settings | ||
* @constructs Core | ||
*/ | ||
constructor(uri: string, config?: Configuration); | ||
private mongoConnectAsyc; | ||
private _plugins; | ||
private _url; | ||
private _config; | ||
private _connection; | ||
private _cache; | ||
private _connectPromise; | ||
/** | ||
* Gets the plugins registered with this Iridium Core | ||
* @returns {[Iridium.Plugin]} | ||
*/ | ||
plugins: Plugin[]; | ||
/** | ||
* Gets the configuration specified in the construction of this | ||
* Iridium Core. | ||
* @returns {Iridium.Configuration} | ||
*/ | ||
settings: Configuration; | ||
/** | ||
* Gets the currently active database connection for this Iridium | ||
* Core. | ||
* @returns {MongoDB.Db} | ||
*/ | ||
connection: MongoDB.Db; | ||
/** | ||
* Gets the URL used to connect to MongoDB | ||
* @returns {String} | ||
*/ | ||
url: string; | ||
/** | ||
* Gets the cache used to store objects retrieved from the database for performance reasons | ||
* @returns {cache} | ||
*/ | ||
cache: Cache; | ||
/** | ||
* Registers a new plugin with this Iridium Core | ||
* @param {Iridium.Plugin} plugin The plugin to register with this Iridium Core | ||
* @returns {Iridium.Core} | ||
*/ | ||
register(plugin: Plugin): Core; | ||
/** | ||
* Connects to the database server specified in the provided configuration | ||
* @param {function(Error, Iridium.Core)} [callback] A callback to be triggered once the connection is established. | ||
* @returns {Promise} | ||
*/ | ||
connect(callback?: (err: Error, core: Core) => any): Bluebird<Core>; | ||
/** | ||
* Closes the active database connection | ||
* @type {Promise} | ||
*/ | ||
close(): Bluebird<Core>; | ||
/** | ||
* Provides an express middleware which can be used to set the req.db property | ||
* to the current Iridium instance. | ||
* @returns {Iridium.ExpressMiddleware} | ||
*/ | ||
express(): ExpressMiddleware.ExpressMiddleware; | ||
/** | ||
* A method which is called whenever a new connection is made to the database. | ||
* | ||
* @param connection The underlying MongoDB connection which was created, you can modify or replace this if you wish. | ||
* @returns A promise for the connection, allowing you to perform any asynchronous initialization required by your application. | ||
* | ||
* In subclassed Iridium Cores this method can be overridden to manipulate the properties | ||
* of the underlying MongoDB connection object, such as authenticating. Until this method | ||
* resolves a connection object, Iridium will be unable to execute any queries. If you wish | ||
* to run Iridium queries then look at the onConnected method. | ||
*/ | ||
protected onConnecting(connection: MongoDB.Db): Bluebird<MongoDB.Db>; | ||
/** | ||
* A method which is called once a database connection has been established and accepted by Iridium | ||
* | ||
* In subclassed Iridium cores this method can be overridden to perform tasks whenever a | ||
* connection to the database has been established - such as setting up indexes for your | ||
* collections or seeding the database. | ||
*/ | ||
protected onConnected(): Bluebird<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Model } from "./Model"; | ||
import * as General from "./General"; | ||
import * as MongoDB from "mongodb"; | ||
import * as Bluebird from "bluebird"; | ||
import * as Index from "./Index"; | ||
/** | ||
* An Iridium collection cursor which allows the itteration through documents | ||
* in the collection, automatically wrapping them in the correct instance type. | ||
* | ||
* @param TDocument The interface representing the collection's documents | ||
* @param TInstance The interface or class used to represent the wrapped documents. | ||
*/ | ||
export declare class Cursor<TDocument extends { | ||
_id?: any; | ||
}, TInstance> { | ||
private model; | ||
private conditions; | ||
cursor: MongoDB.Cursor; | ||
/** | ||
* Creates a new Iridium cursor which wraps a MongoDB cursor object | ||
* @param {Model} model The Iridium model that this cursor belongs to | ||
* @param {Object} conditions The conditions that resulte in this cursor being created | ||
* @param {MongoDB.Cursor} cursor The MongoDB native cursor object to be wrapped | ||
* @constructor | ||
*/ | ||
constructor(model: Model<TDocument, TInstance>, conditions: any, cursor: MongoDB.Cursor); | ||
/** | ||
* Counts the number of documents which are matched by this cursor | ||
* @param {function(Error, Number)} callback A callback which is triggered when the result is available | ||
* @return {Promise<number>} A promise which will resolve with the number of documents matched by this cursor | ||
*/ | ||
count(callback?: General.Callback<number>): Bluebird<number>; | ||
/** | ||
* Runs the specified handler over each instance in the query results | ||
* @param {function(Instance)} handler The handler which is triggered for each element in the query | ||
* @param {function(Error)} callback A callback which is triggered when all operations have been dispatched | ||
* @return {Promise} A promise which is resolved when all operations have been dispatched | ||
*/ | ||
forEach(handler: (instance: TInstance) => void, callback?: General.Callback<void>): Bluebird<void>; | ||
/** | ||
* Runs the specified transform over each instance in the query results and returns the resulting transformed objects | ||
* @param {function(Instance): TResult} transform A handler which is used to transform the result objects | ||
* @param {function(Error, TResult[])} callback A callback which is triggered when the transformations are completed | ||
* @return {Promise<TResult[]>} A promise which is fulfilled with the results of the transformations | ||
*/ | ||
map<TResult>(transform: (instance: TInstance) => TResult | Bluebird<TResult>, callback?: General.Callback<TResult[]>): Bluebird<TResult[]>; | ||
/** | ||
* Retrieves all matching instances and returns them in an array | ||
* @param {function(Error, TInstance[])} callback A callback which is triggered with the resulting instances | ||
* @return {Promise<TInstance[]>} A promise which resolves with the instances returned by the query | ||
*/ | ||
toArray(callback?: General.Callback<TInstance[]>): Bluebird<TInstance[]>; | ||
/** | ||
* Retrieves the next item in the results list | ||
* @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available | ||
* @return {Promise<TInstance>} A promise which is resolved with the next item | ||
*/ | ||
next(callback?: General.Callback<TInstance>): Bluebird<TInstance>; | ||
/** | ||
* Retrieves the next item in the result list and then closes the cursor | ||
* @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available | ||
* @return {Promise<TInstance>} A promise which is resolved once the item becomes available and the cursor has been closed. | ||
*/ | ||
one(callback?: General.Callback<TInstance>): Bluebird<TInstance>; | ||
/** | ||
* Returns a new cursor which behaves the same as this one did before any results were retrieved | ||
* @return {Cursor} The new cursor which starts at the beginning of the results | ||
*/ | ||
rewind(): Cursor<TDocument, TInstance>; | ||
/** | ||
* Returns a new cursor which sorts its results by the given index expression | ||
* @param {model.IndexSpecification} sortExpression The index expression dictating the sort order and direction to use | ||
* @return {Cursor} The new cursor which sorts its results by the sortExpression | ||
*/ | ||
sort(sortExpression: Index.IndexSpecification): Cursor<TDocument, TInstance>; | ||
/** | ||
* Returns a new cursor which limits the number of returned results | ||
* @param {Number} limit The maximum number of results to return | ||
* @return {Cursor} The new cursor which will return a maximum number of results | ||
*/ | ||
limit(limit: number): Cursor<TDocument, TInstance>; | ||
/** | ||
* Returns a new cursor which skips a number of results before it begins | ||
* returning any. | ||
* @param {Number} skip The number of results to skip before the cursor beings returning | ||
* @return {Cursor} The new cursor which skips a number of results | ||
*/ | ||
skip(skip: number): Cursor<TDocument, TInstance>; | ||
/** | ||
* Returns a new cursor which will read from the specified node type. | ||
* @param {String} type The type of node to read from - see https://docs.mongodb.org/manual/core/read-preference/ | ||
* @return {Cursor} The new cursor which reads from the specified node type | ||
*/ | ||
readFrom(type: string): Cursor<TDocument, TInstance>; | ||
} |
Oops, something went wrong.