Skip to content

Commit

Permalink
Added a number of definition files
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 23, 2015
1 parent 4823afb commit 860a824
Show file tree
Hide file tree
Showing 22 changed files with 351 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Cache.d.ts
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>;
}
6 changes: 6 additions & 0 deletions lib/CacheDirector.d.ts
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;
}
10 changes: 10 additions & 0 deletions lib/Configuration.d.ts
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;
}
78 changes: 78 additions & 0 deletions lib/Core.d.ts
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;
}
17 changes: 17 additions & 0 deletions lib/General.d.ts
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>;
}
8 changes: 8 additions & 0 deletions lib/Hooks.d.ts
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;
}
119 changes: 119 additions & 0 deletions lib/Instance.d.ts
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;
6 changes: 6 additions & 0 deletions lib/Middleware.d.ts
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;
}
8 changes: 8 additions & 0 deletions lib/Plugins.d.ts
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[];
}
5 changes: 5 additions & 0 deletions lib/Schema.d.ts
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;
}
11 changes: 11 additions & 0 deletions lib/cacheControllers/IDDirector.d.ts
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;
}
10 changes: 10 additions & 0 deletions lib/caches/MemoryCache.d.ts
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>;
}
9 changes: 9 additions & 0 deletions lib/caches/NoOpCache.d.ts
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>;
}
7 changes: 7 additions & 0 deletions lib/middleware/Express.d.ts
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;
}
41 changes: 41 additions & 0 deletions lib/utils/Omnom.d.ts
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);
}
1 change: 1 addition & 0 deletions test/Core.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../_references.d.ts" />
1 change: 1 addition & 0 deletions test/Instance.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../_references.d.ts" />
1 change: 1 addition & 0 deletions test/Model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../_references.d.ts" />
1 change: 1 addition & 0 deletions test/Omnom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../_references.d.ts" />
1 change: 1 addition & 0 deletions test/iridium.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../_references.d.ts" />
1 change: 1 addition & 0 deletions test/support/chai.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../_references.d.ts" />
2 changes: 2 additions & 0 deletions test/support/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../../_references.d.ts" />
declare var config: any;

0 comments on commit 860a824

Please sign in to comment.