Skip to content

Commit

Permalink
Use ES6 module import format
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 11, 2015
1 parent b0bbad7 commit 6b0d5e5
Show file tree
Hide file tree
Showing 34 changed files with 210 additions and 256 deletions.
56 changes: 19 additions & 37 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
import _Core = require('./lib/Core');
import _Model = require('./lib/Model');
import _Instance = require('./lib/Instance');

import _Plugin = require('./lib/Plugins');
import _Schema = require('./lib/Schema');
import _Cache = require('./lib/Cache');
import _CacheDirector = require('./lib/CacheDirector');
import _ModelOptions = require('./lib/ModelOptions');
import _Configuration = require('./lib/Configuration');
import _Hooks = require('./lib/Hooks');

import _MemoryCache = require('./lib/caches/MemoryCache');
import _NoOpCache = require('./lib/caches/NoOpCache');

import _IDDirector = require('./lib/cacheControllers/IDDirector');

export = Iridium;

module Iridium {
export class Core extends _Core { }
export class Model<TDocument extends { _id?: any }, TInstance> extends _Model<TDocument, TInstance> { }
export class Instance<TDocument extends { _id?: any }, TInstance> extends _Instance<TDocument, TInstance> { }

export class NoOpCache extends _NoOpCache { }
export class MemoryCache extends _MemoryCache { }

export class CacheOnID extends _IDDirector { }

export interface Configuration extends _Configuration { }
export interface Hooks<TDocument, TInstance> extends _Hooks<TDocument, TInstance> { }
export interface Plugin extends _Plugin { }
export interface Schema extends _Schema { }
export interface Cache extends _Cache { }
export interface CacheDirector extends _CacheDirector { }
export interface ModelOptions<TDocument, TInstance> extends _ModelOptions.IModelOptions<TDocument, TInstance> { }
}
import Core from './lib/Core';
import Model from './lib/Model';
import Instance from './lib/Instance';
export {Core, Model, Instance};

export * from './lib/Plugins';
export * from './lib/Schema';
export * from './lib/Cache';
export * from './lib/CacheDirector';
export * from './lib/ModelOptions';
export * from './lib/Configuration';
export * from './lib/Hooks';

import MemoryCache from './lib/caches/MemoryCache';
import NoOpCache from './lib/caches/NoOpCache';
export {MemoryCache, NoOpCache};

import IDDirector from './lib/cacheControllers/IDDirector';
export {IDDirector as CacheOnID};
4 changes: 1 addition & 3 deletions lib/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/// <reference path="../_references.d.ts" />
import Bluebird = require('bluebird');

export = ICache;

interface ICache {
export interface Cache {
set<T>(key: string, value: T): void;
get<T>(key: string): Bluebird<T>;
clear(key: string): void
Expand Down
4 changes: 1 addition & 3 deletions lib/CacheDirector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/// <reference path="../_references.d.ts" />
export = ICacheDirector;

interface ICacheDirector {
export interface CacheDirector {
valid<T>(object: T): boolean;
buildKey<T>(object: T): string;

Expand Down
4 changes: 1 addition & 3 deletions lib/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/// <reference path="../_references.d.ts" />
export = Configuration;

interface Configuration {
export interface Configuration {
host?: string;
port?: number;
hosts?: { address: string; port?: number }[];
Expand Down
41 changes: 20 additions & 21 deletions lib/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@ import _ = require('lodash');
import http = require('http');
import events = require('events');

import config = require('./Configuration');
import IPlugin = require('./Plugins');
import Model = require('./Model');
import Instance = require('./Instance');
import {Configuration} from './Configuration';
import {Plugin} from './Plugins';
import Model from './Model';
import Instance from './Instance';

import middleware = require('./Middleware');
import ExpressMiddleware = require('./middleware/Express');
import {MiddlewareFactory} from './Middleware';
import * as ExpressMiddleware from './middleware/Express';
import ExpressMiddlewareFactory from './middleware/Express';

import Cache = require('./Cache');
import NoOpCache = require('./caches/NoOpCache');
import MemoryCache = require('./caches/MemoryCache');
import {Cache} from './Cache';
import NoOpCache from './caches/NoOpCache';
import MemoryCache from './caches/MemoryCache';

var MongoConnectAsyc = Bluebird.promisify(MongoDB.MongoClient.connect);

export = Core;

class Core {
export default 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: config);
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?: config);
constructor(uri: string | config, config?: config) {
constructor(uri: string, config?: Configuration);
constructor(uri: string | Configuration, config?: Configuration) {

var args = Array.prototype.slice.call(arguments, 0);
uri = config = null;
Expand All @@ -52,17 +51,17 @@ class Core {
this._config = config;
}

private _plugins: IPlugin[] = [];
private _plugins: Plugin[] = [];
private _url: string;
private _config: config;
private _config: Configuration;
private _connection: MongoDB.Db;
private _cache: Cache = new NoOpCache();

/**
* Gets the plugins registered with this Iridium Core
* @returns {[Iridium.Plugin]}
*/
get plugins(): IPlugin[] {
get plugins(): Plugin[] {
return this._plugins;
}

Expand All @@ -71,7 +70,7 @@ class Core {
* Iridium Core.
* @returns {Iridium.Configuration}
*/
get settings(): config {
get settings(): Configuration {
return this._config;
}

Expand Down Expand Up @@ -146,7 +145,7 @@ class Core {
* @param {Iridium.Plugin} plugin The plugin to register with this Iridium Core
* @returns {Iridium.Core}
*/
register(plugin: IPlugin): Core {
register(plugin: Plugin): Core {
this.plugins.push(plugin);
return this;
}
Expand Down Expand Up @@ -188,6 +187,6 @@ class Core {
* @returns {Iridium.ExpressMiddleware}
*/
express(): ExpressMiddleware.ExpressMiddleware {
return ExpressMiddleware.ExpressMiddlewareFactory(this);
return ExpressMiddlewareFactory(this);
}
}
8 changes: 3 additions & 5 deletions lib/Cursor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/// <reference path="../_references.d.ts" />
import Model = require('./Model');
import Model from './Model';
import General = require('./General');
import MongoDB = require('mongodb');
import Bluebird = require('bluebird');
import Index = require('./Index');
import * as Index from './Index';

export = Cursor;

class Cursor<TDocument extends { _id?: any }, TInstance> {
export default class Cursor<TDocument extends { _id?: any }, TInstance> {
/**
* Creates a new Iridium cursor which wraps a MongoDB cursor object
* @param {Model} model The Iridium model that this cursor belongs to
Expand Down
4 changes: 1 addition & 3 deletions lib/Hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/// <reference path="../_references.d.ts" />
import instance = require('./Instance');

export = IHooks;

interface IHooks<TDocument, TInstance> {
export interface Hooks<TDocument, TInstance> {
onCreating? (document: TDocument): void;
onRetrieved? (document: TDocument): void;
onReady? (instance: TInstance): void;
Expand Down
46 changes: 22 additions & 24 deletions lib/Instance.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// <reference path="../_references.d.ts" />
import iridium = require('./Core');
import Model = require('./Model');
import IPlugin = require('./Plugins');
import Core from './Core';
import Model from './Model';
import {Plugin} from './Plugins';
import * as General from './General';

import _ = require('lodash');
import Bluebird = require('bluebird');

import general = require('./General');

class Instance<TDocument extends { _id?: any }, TInstance> {
export default class Instance<TDocument extends { _id?: any }, 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
Expand All @@ -28,7 +28,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
this._original = document;
this._modified = _.cloneDeep<TDocument>(document);

_.each(model.core.plugins,(plugin: IPlugin) => {
_.each(model.core.plugins,(plugin: Plugin) => {
if (plugin.newInstance) plugin.newInstance(this, model);
});
}
Expand All @@ -53,24 +53,24 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes
* @returns {Promise<TInstance>}
*/
save(callback?: general.Callback<TInstance>): Bluebird<TInstance>;
save(callback?: General.Callback<TInstance>): Bluebird<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>): Bluebird<TInstance>;
save(changes: Object, callback?: General.Callback<TInstance>): Bluebird<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>): Bluebird<TInstance>;
save(conditions: Object, changes: Object, callback?: General.Callback<TInstance>): Bluebird<TInstance>;
save(...args: any[]): Bluebird<TInstance> {
var callback: general.Callback<any> = null;
var callback: General.Callback<any> = null;
var changes: any = null;
var conditions: any = {};

Expand Down Expand Up @@ -145,7 +145,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error, IInstance)} callback A callback which is triggered when the update completes
* @returns {Promise<TInstance>}
*/
update(callback?: general.Callback<TInstance>): Bluebird<TInstance> {
update(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
return this.refresh(callback);
}

Expand All @@ -154,7 +154,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error, IInstance)} callback A callback which is triggered when the update completes
* @returns {Promise<TInstance>}
*/
refresh(callback?: general.Callback<TInstance>): Bluebird<TInstance> {
refresh(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
var conditions = { _id: this._original._id };

return Bluebird.resolve().then(() => {
Expand Down Expand Up @@ -188,7 +188,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes
* @returns {Promise<TInstance>}
*/
delete(callback?: general.Callback<TInstance>): Bluebird<TInstance> {
delete(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
return this.remove(callback);
}

Expand All @@ -197,7 +197,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes
* @returns {Promise<TInstance>}
*/
remove(callback?: general.Callback<TInstance>): Bluebird<TInstance> {
remove(callback?: General.Callback<TInstance>): Bluebird<TInstance> {
var conditions = { _id: this._original._id };

return Bluebird.resolve().then(() => {
Expand All @@ -223,15 +223,15 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @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;
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;
first<T>(collection: T[]| { [key: string]: T }, predicate: general.Predicate<T>): T {
first<T>(collection: { [key: string]: T }, predicate: General.Predicate<T>): T;
first<T>(collection: T[]| { [key: string]: T }, predicate: General.Predicate<T>): T {
var result = null;

_.each(collection,(value: T, key) => {
Expand All @@ -250,15 +250,15 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
* @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[];
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 };
select<T>(collection: T[]| { [key: string]: T }, predicate: general.Predicate<T>): any {
select<T>(collection: { [key: string]: T }, predicate: General.Predicate<T>): { [key: string]: T };
select<T>(collection: T[]| { [key: string]: T }, predicate: General.Predicate<T>): any {
var isArray = Array.isArray(collection);
var results: any = isArray ? [] : {};

Expand Down Expand Up @@ -287,6 +287,4 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
toString(): string {
return JSON.stringify(this.document, null, 2);
}
}

export = Instance;
}
5 changes: 2 additions & 3 deletions lib/Middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference path="../_references.d.ts" />
import Core = require('./Core');
import Core from './Core';

export = IMiddlewareFactory;
interface IMiddlewareFactory<T> {
export interface MiddlewareFactory<T> {
(core: Core): T;
}
Loading

0 comments on commit 6b0d5e5

Please sign in to comment.