Skip to content

Commit

Permalink
Separated Model into a number of smaller files to make it more manage…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
notheotherben committed Apr 24, 2015
1 parent fb6f69a commit aad75e8
Show file tree
Hide file tree
Showing 38 changed files with 612 additions and 522 deletions.
7 changes: 7 additions & 0 deletions Iridium.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@
<TypeScriptCompile Include="lib\Cursor.ts" />
<TypeScriptCompile Include="lib\General.ts" />
<TypeScriptCompile Include="lib\Hooks.ts" />
<TypeScriptCompile Include="lib\Index.ts" />
<TypeScriptCompile Include="lib\Instance.ts" />
<TypeScriptCompile Include="lib\Middleware.ts" />
<TypeScriptCompile Include="lib\Model.ts" />
<TypeScriptCompile Include="lib\ModelCache.ts" />
<TypeScriptCompile Include="lib\ModelHandlers.ts" />
<TypeScriptCompile Include="lib\ModelHelpers.ts" />
<TypeScriptCompile Include="lib\ModelInterfaces.ts" />
<TypeScriptCompile Include="lib\ModelOptions.ts" />
<TypeScriptCompile Include="lib\ModelSpecificInstance.ts" />
<TypeScriptCompile Include="lib\Plugins.ts" />
<TypeScriptCompile Include="lib\Schema.ts" />
<Content Include="test\mocha.opts" />
Expand Down
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export = Iridium;

module Iridium {
export class Core extends _Core { };
export class Model<TDocument, TInstance> extends _Model.Model<TDocument, TInstance> { };
export class Model<TDocument, TInstance> extends _Model<TDocument, TInstance> { };
export class Instance<TDocument, TInstance> extends _Instance<TDocument, TInstance> { };

export class NoOpCache extends _NoOpCache { };
Expand Down
2 changes: 1 addition & 1 deletion lib/Cursor.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions lib/Cursor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// <reference path="../_references.d.ts" />
import model = require('./Model');
import general = require('./General');
import Model = require('./Model');
import General = require('./General');
import MongoDB = require('mongodb');
import Promise = require('bluebird');
import Index = require('./Index');

export = Cursor;

Expand All @@ -14,7 +15,7 @@ class Cursor<TDocument, TInstance> {
* @param {MongoDB.Cursor} cursor The MongoDB native cursor object to be wrapped
* @constructor
*/
constructor(private model: model.Model<TDocument, TInstance>, private conditions: any, public cursor: MongoDB.Cursor) {
constructor(private model: Model<TDocument, TInstance>, private conditions: any, public cursor: MongoDB.Cursor) {

}

Expand All @@ -23,7 +24,7 @@ class Cursor<TDocument, TInstance> {
* @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>): Promise<number> {
count(callback?: General.Callback<number>): Promise<number> {
return new Promise<number>((resolve, reject) => {
this.cursor.count(true,(err, count) => {
if (err) return reject(err);
Expand All @@ -38,7 +39,7 @@ class Cursor<TDocument, TInstance> {
* @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
*/
each(handler: (instance: TInstance) => void, callback?: general.Callback<void>): Promise<void> {
each(handler: (instance: TInstance) => void, callback?: General.Callback<void>): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.cursor.each((err, item: TDocument) => {
if (err) return reject(err);
Expand All @@ -54,7 +55,7 @@ class Cursor<TDocument, TInstance> {
* @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 | Promise<TResult>, callback?: general.Callback<TResult[]>): Promise<TResult[]> {
map<TResult>(transform: (instance: TInstance) => TResult | Promise<TResult>, callback?: General.Callback<TResult[]>): Promise<TResult[]> {
return new Promise<TResult[]>((resolve, reject) => {
var promises: Promise<TResult>[] = [];
this.cursor.each((err, item: TDocument) => {
Expand All @@ -71,7 +72,7 @@ class Cursor<TDocument, TInstance> {
* @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[]>): Promise<TInstance[]> {
toArray(callback?: General.Callback<TInstance[]>): Promise<TInstance[]> {
return new Promise<TDocument[]>((resolve, reject) => {
this.cursor.toArray((err, results: any[]) => {
if (err) return reject(err);
Expand All @@ -87,7 +88,7 @@ class Cursor<TDocument, TInstance> {
* @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>): Promise<TInstance> {
next(callback?: General.Callback<TInstance>): Promise<TInstance> {
return new Promise<TDocument>((resolve, reject) => {
this.cursor.nextObject((err, result: any) => {
if (err) return reject(err);
Expand All @@ -111,7 +112,7 @@ class Cursor<TDocument, TInstance> {
* @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: model.IndexSpecification): Cursor<TDocument, TInstance> {
sort(sortExpression: Index.IndexSpecification): Cursor<TDocument, TInstance> {
return new Cursor(this.model, this.conditions, this.cursor.sort(sortExpression));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Hooks.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/Hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference path="../_references.d.ts" />
import instance = require('./Instance');

export interface IHooks<TDocument, TInstance> {
export = IHooks;

interface IHooks<TDocument, TInstance> {
creating? (document: TDocument);
retrieved? (document: TDocument);
ready? (instance: TInstance);
Expand Down
1 change: 1 addition & 0 deletions lib/Index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/Index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aad75e8

Please sign in to comment.