-
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.
- Loading branch information
1 parent
4823afb
commit 860a824
Showing
22 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
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,8 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import Promise = require('bluebird'); | ||
export = ICache; | ||
interface ICache { | ||
set<T>(key: string, value: T): Promise<T>; | ||
get<T>(key: string): Promise<T>; | ||
clear(key: string): Promise<boolean>; | ||
} |
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 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
export = ICacheDirector; | ||
interface ICacheDirector { | ||
valid<T>(object: T): boolean; | ||
buildKey<T>(object: T): 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,10 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
export = Configuration; | ||
interface Configuration { | ||
host?: string; | ||
port?: number; | ||
database?: string; | ||
username?: string; | ||
password?: string; | ||
[key: string]: any; | ||
} |
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,78 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import Promise = require('bluebird'); | ||
import MongoDB = require('mongodb'); | ||
import config = require('./Configuration'); | ||
import IPlugin = require('./Plugins'); | ||
import expressMiddleware = require('./middleware/Express'); | ||
import cache = require('./Cache'); | ||
export = Core; | ||
declare class Core { | ||
private _plugins; | ||
private _url; | ||
private _config; | ||
private _connection; | ||
private _cache; | ||
/** | ||
* Gets the plugins registered with this Iridium Core | ||
* @returns {[Iridium.Plugin]} | ||
*/ | ||
plugins: IPlugin[]; | ||
/** | ||
* Gets the configuration specified in the construction of this | ||
* Iridium Core. | ||
* @returns {Iridium.Configuration} | ||
*/ | ||
settings: config; | ||
/** | ||
* 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; | ||
/** | ||
* 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: config); | ||
/** | ||
* 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?: config); | ||
/** | ||
* 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: IPlugin): 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): Promise<Core>; | ||
/** | ||
* Closes the active database connection | ||
* @type {Promise} | ||
*/ | ||
close(): Promise<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; | ||
} |
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,17 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
export interface Callback<T> { | ||
(err: Error, object: T): void; | ||
} | ||
export interface Predicate<T> { | ||
(object: T, key?: string): boolean; | ||
} | ||
export interface PropertyGetter<T> { | ||
(): T; | ||
} | ||
export interface PropertySetter<T> { | ||
(value: T): void; | ||
} | ||
export interface Property<T> { | ||
get?: PropertyGetter<T>; | ||
set?: PropertySetter<T>; | ||
} |
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,8 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
export interface IHooks<TDocument, TInstance> { | ||
creating?(document: TDocument): any; | ||
retrieved?(document: TDocument): any; | ||
ready?(instance: TInstance): any; | ||
beforeSave?(instance: TInstance): any; | ||
saving?(instance: TInstance, changes: any): any; | ||
} |
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,119 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import model = require('./Model'); | ||
import Promise = require('bluebird'); | ||
import general = require('./General'); | ||
declare class Instance<TDocument, TInstance> { | ||
/** | ||
* Creates a new instance which represents the given document as a type of model | ||
* @param {model.Model} model The model that the document represents | ||
* @param {TSchema} document The document which should be wrapped by this instance | ||
* @param {Boolean} isNew Whether the document is new (doesn't exist in the database) or not | ||
* @param {Boolean} isPartial Whether the document has only a subset of its fields populated | ||
* @description | ||
* This class will be subclassed automatically by Iridium to create a model specific instance | ||
* which takes advantage of some of v8's optimizations to boost performance significantly. | ||
* The instance returned by the model, and all of this instance's methods, will be of type | ||
* TInstance - which should represent the merger of TSchema and IInstance for best results. | ||
*/ | ||
constructor(model: model.Model<TDocument, TInstance>, document: TDocument, isNew?: boolean, isPartial?: boolean); | ||
private _isNew; | ||
private _isPartial; | ||
private _model; | ||
private _original; | ||
private _modified; | ||
/** | ||
* Gets the underlying document representation of this instance | ||
*/ | ||
document: TDocument; | ||
[name: string]: any; | ||
/** | ||
* Saves any changes to this instance, using the built in diff algorithm to write the update query. | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
save(callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Saves the given changes to this instance and updates the instance to match the latest database document. | ||
* @param {Object} changes The MongoDB changes object to be used when updating this instance | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
save(changes: Object, callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Saves the given changes to this instance and updates the instance to match the latest database document. | ||
* @param {Object} conditions The conditions under which the update will take place - these will be merged with an _id query | ||
* @param {Object} changes The MongoDB changes object to be used when updating this instance | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
save(conditions: Object, changes: Object, callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Updates this instance to match the latest document available in the backing collection | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the update completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
update(callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Updates this instance to match the latest document available in the backing collection | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the update completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
refresh(callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Removes this instance's document from the backing collection | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
delete(callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Removes this instance's document from the backing collection | ||
* @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes | ||
* @returns {Promise<TInstance>} | ||
*/ | ||
remove(callback?: general.Callback<TInstance>): Promise<TInstance>; | ||
/** | ||
* Retrieves the first element in an enumerable collection which matches the predicate | ||
* @param {any[]} collection The collection from which to retrieve the element | ||
* @param {function(any, Number): Boolean} predicate The function which determines whether to select an element | ||
* @returns {any} | ||
*/ | ||
first<T>(collection: T[], predicate: general.Predicate<T>): T; | ||
/** | ||
* Retrieves the first element in an enumerable collection which matches the predicate | ||
* @param {Object} collection The collection from which to retrieve the element | ||
* @param {function(any, String): Boolean} predicate The function which determines whether to select an element | ||
* @returns {any} | ||
*/ | ||
first<T>(collection: { | ||
[key: string]: T; | ||
}, predicate: general.Predicate<T>): T; | ||
/** | ||
* Retrieves a number of elements from an enumerable collection which match the predicate | ||
* @param {any[]} collection The collection from which elements will be plucked | ||
* @param {function(any, Number): Boolean} predicate The function which determines the elements to be plucked | ||
* @returns {any[]} | ||
*/ | ||
select<T>(collection: T[], predicate: general.Predicate<T>): T[]; | ||
/** | ||
* Retrieves a number of elements from an enumerable collection which match the predicate | ||
* @param {Object} collection The collection from which elements will be plucked | ||
* @param {function(any, String): Boolean} predicate The function which determines the elements to be plucked | ||
* @returns {Object} | ||
*/ | ||
select<T>(collection: { | ||
[key: string]: T; | ||
}, predicate: general.Predicate<T>): { | ||
[key: string]: T; | ||
}; | ||
/** | ||
* Gets the JSON representation of this instance | ||
* @returns {TDocument} | ||
*/ | ||
toJSON(): TDocument; | ||
/** | ||
* Gets a string representation of this instance | ||
* @returns {String} | ||
*/ | ||
toString(): string; | ||
} | ||
export = Instance; |
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 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import Core = require('./Core'); | ||
export = IMiddlewareFactory; | ||
interface IMiddlewareFactory<T> { | ||
(core: Core): T; | ||
} |
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,8 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import model = require('./Model'); | ||
export = IPlugin; | ||
interface IPlugin { | ||
newModel?(model: model.IModel<any, any>): any; | ||
newInstance?(instance: any, model: model.IModelBase): any; | ||
validate?: SkmatcCore.IValidator | SkmatcCore.IValidator[]; | ||
} |
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 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
export = ISchema; | ||
interface ISchema { | ||
[key: string]: any; | ||
} |
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,11 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
import cacheDirector = require('../CacheDirector'); | ||
export = IDCacheDirector; | ||
declare class IDCacheDirector implements cacheDirector { | ||
valid(object: { | ||
_id: any; | ||
}): any; | ||
buildKey(object: { | ||
_id: 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,10 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
import Promise = require('bluebird'); | ||
import cache = require('../Cache'); | ||
export = MemoryCache; | ||
declare class MemoryCache implements cache { | ||
private cache; | ||
set<T>(key: string, value: T): Promise<T>; | ||
get<T>(key: string): Promise<T>; | ||
clear(key: string): Promise<boolean>; | ||
} |
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,9 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
import cache = require('../Cache'); | ||
import Promise = require('bluebird'); | ||
export = NoOpCache; | ||
declare class NoOpCache implements cache { | ||
set<T>(key: string, object: T): Promise<T>; | ||
get<T>(key: string): Promise<void>; | ||
clear(key: string): Promise<boolean>; | ||
} |
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,7 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
import http = require('http'); | ||
import Core = require('../Core'); | ||
export declare function ExpressMiddlewareFactory(core: Core): ExpressMiddleware; | ||
export interface ExpressMiddleware { | ||
(req: http.ServerRequest, res: http.ServerResponse, next: (err?: Error, route?: String) => void): any; | ||
} |
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,41 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
import MongoDB = require('mongodb'); | ||
export = Omnom; | ||
declare class Omnom { | ||
options: { | ||
atomicNumbers?: boolean; | ||
}; | ||
constructor(options?: { | ||
atomicNumbers?: boolean; | ||
}); | ||
private _changes; | ||
changes: { | ||
$set?: any; | ||
$unset?: any; | ||
$inc?: any; | ||
$push?: any; | ||
$pull?: any; | ||
$pullAll?: any; | ||
}; | ||
diff(original: number, modified: number): Omnom; | ||
diff(original: [any], modified: any[]): Omnom; | ||
diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID): Omnom; | ||
diff(original: Object, modified: Object): Omnom; | ||
static diff(original: number, modified: number): any; | ||
static diff(original: [any], modified: any[]): any; | ||
static diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID): any; | ||
static diff(original: Object, modified: Object): any; | ||
private onObject(original, modified, changePath?); | ||
private onObject(original, modified, changePath?); | ||
private onObject(original, modified, changePath?); | ||
private onObject(original, modified, changePath?); | ||
private onArray(original, modified, changePath); | ||
private set(path, value); | ||
private unset(path); | ||
private inc(path, value); | ||
private push(path, value); | ||
private pull(path, value); | ||
private pullAll(path, values); | ||
private resolve(...args); | ||
private almostEqual(o1, o2); | ||
} |
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 @@ | ||
/// <reference path="../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../../_references.d.ts" /> |
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 @@ | ||
/// <reference path="../../_references.d.ts" /> | ||
declare var config: any; |