From acb776e17040d74b75bdd378ee26ed78eb0a41ad Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Tue, 12 Apr 2016 21:46:52 +0200 Subject: [PATCH] repo: Remove a number of unnecessary definition and map files from the repo This will become redundant once we start bundling our definition files into a module. --- dist/.gitignore | 4 +- dist/iridium.d.ts | 16 - dist/lib/Aggregate.d.ts | 2 - dist/lib/BSON.d.ts | 1 - dist/lib/CacheDirector.d.ts | 6 - dist/lib/Configuration.d.ts | 104 ------ dist/lib/Core.d.ts | 105 ------ dist/lib/Cursor.d.ts | 95 ----- dist/lib/Decorators.d.ts | 89 ----- dist/lib/General.d.ts | 60 --- dist/lib/Hooks.d.ts | 6 - dist/lib/Index.d.ts | 8 - dist/lib/Instance.d.ts | 194 ---------- dist/lib/InstanceInterface.d.ts | 119 ------ dist/lib/Middleware.d.ts | 8 - dist/lib/Model.d.ts | 426 ---------------------- dist/lib/ModelCache.d.ts | 14 - dist/lib/ModelHandlers.d.ts | 20 - dist/lib/ModelHelpers.d.ts | 81 ---- dist/lib/ModelInterfaces.d.ts | 17 - dist/lib/ModelOptions.d.ts | 120 ------ dist/lib/ModelSpecificInstance.d.ts | 18 - dist/lib/Plugins.d.ts | 7 - dist/lib/Schema.d.ts | 4 - dist/lib/Transforms.d.ts | 37 -- dist/lib/Validators.d.ts | 2 - dist/lib/cacheControllers/IDDirector.d.ts | 17 - dist/lib/caches/MemoryCache.d.ts | 14 - dist/lib/caches/NoOpCache.d.ts | 14 - dist/lib/middleware/Express.d.ts | 17 - dist/lib/utils/ObjectID.d.ts | 15 - dist/lib/utils/Omnom.d.ts | 50 --- 32 files changed, 3 insertions(+), 1687 deletions(-) delete mode 100644 dist/iridium.d.ts delete mode 100644 dist/lib/Aggregate.d.ts delete mode 100644 dist/lib/BSON.d.ts delete mode 100644 dist/lib/CacheDirector.d.ts delete mode 100644 dist/lib/Configuration.d.ts delete mode 100644 dist/lib/Core.d.ts delete mode 100644 dist/lib/Cursor.d.ts delete mode 100644 dist/lib/Decorators.d.ts delete mode 100644 dist/lib/General.d.ts delete mode 100644 dist/lib/Hooks.d.ts delete mode 100644 dist/lib/Index.d.ts delete mode 100644 dist/lib/Instance.d.ts delete mode 100644 dist/lib/InstanceInterface.d.ts delete mode 100644 dist/lib/Middleware.d.ts delete mode 100644 dist/lib/Model.d.ts delete mode 100644 dist/lib/ModelCache.d.ts delete mode 100644 dist/lib/ModelHandlers.d.ts delete mode 100644 dist/lib/ModelHelpers.d.ts delete mode 100644 dist/lib/ModelInterfaces.d.ts delete mode 100644 dist/lib/ModelOptions.d.ts delete mode 100644 dist/lib/ModelSpecificInstance.d.ts delete mode 100644 dist/lib/Plugins.d.ts delete mode 100644 dist/lib/Schema.d.ts delete mode 100644 dist/lib/Transforms.d.ts delete mode 100644 dist/lib/Validators.d.ts delete mode 100644 dist/lib/cacheControllers/IDDirector.d.ts delete mode 100644 dist/lib/caches/MemoryCache.d.ts delete mode 100644 dist/lib/caches/NoOpCache.d.ts delete mode 100644 dist/lib/middleware/Express.d.ts delete mode 100644 dist/lib/utils/ObjectID.d.ts delete mode 100644 dist/lib/utils/Omnom.d.ts diff --git a/dist/.gitignore b/dist/.gitignore index 468282e..acdb84d 100644 --- a/dist/.gitignore +++ b/dist/.gitignore @@ -1,3 +1,5 @@ benchmarks example -test \ No newline at end of file +test +*.d.ts +*.map \ No newline at end of file diff --git a/dist/iridium.d.ts b/dist/iridium.d.ts deleted file mode 100644 index 1c0ce3e..0000000 --- a/dist/iridium.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -export * from "./lib/Core"; -export * from "./lib/Model"; -export * from "./lib/Instance"; -export * from "./lib/Decorators"; -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"; -export * from "./lib/Transforms"; -export * from "./lib/caches/MemoryCache"; -export * from "./lib/caches/NoOpCache"; -export * from "./lib/cacheControllers/IDDirector"; -export * from "./lib/utils/ObjectID"; diff --git a/dist/lib/Aggregate.d.ts b/dist/lib/Aggregate.d.ts deleted file mode 100644 index d830fc6..0000000 --- a/dist/lib/Aggregate.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export interface Stage { -} diff --git a/dist/lib/BSON.d.ts b/dist/lib/BSON.d.ts deleted file mode 100644 index 299986c..0000000 --- a/dist/lib/BSON.d.ts +++ /dev/null @@ -1 +0,0 @@ -export { ObjectID, Binary } from "mongodb"; diff --git a/dist/lib/CacheDirector.d.ts b/dist/lib/CacheDirector.d.ts deleted file mode 100644 index b83cefc..0000000 --- a/dist/lib/CacheDirector.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface CacheDirector { - valid(object: T): boolean; - buildKey(object: T): string; - validQuery(conditions: any): boolean; - buildQueryKey(conditions: any): string; -} diff --git a/dist/lib/Configuration.d.ts b/dist/lib/Configuration.d.ts deleted file mode 100644 index c25c3f3..0000000 --- a/dist/lib/Configuration.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -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; - }; -} diff --git a/dist/lib/Core.d.ts b/dist/lib/Core.d.ts deleted file mode 100644 index 5da4aa3..0000000 --- a/dist/lib/Core.d.ts +++ /dev/null @@ -1,105 +0,0 @@ -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; - /** - * Closes the active database connection - * @type {Promise} - */ - close(): Bluebird; - /** - * 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; - /** - * 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; -} diff --git a/dist/lib/Cursor.d.ts b/dist/lib/Cursor.d.ts deleted file mode 100644 index 54fb81f..0000000 --- a/dist/lib/Cursor.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -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 { - 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, 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} A promise which will resolve with the number of documents matched by this cursor - */ - count(callback?: General.Callback): Bluebird; - /** - * 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): Bluebird; - /** - * 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} A promise which is fulfilled with the results of the transformations - */ - map(transform: (instance: TInstance) => TResult | Bluebird, callback?: General.Callback): Bluebird; - /** - * 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} A promise which resolves with the instances returned by the query - */ - toArray(callback?: General.Callback): Bluebird; - /** - * 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} A promise which is resolved with the next item - */ - next(callback?: General.Callback): Bluebird; - /** - * 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} A promise which is resolved once the item becomes available and the cursor has been closed. - */ - one(callback?: General.Callback): Bluebird; - /** - * 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; - /** - * 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; - /** - * 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; - /** - * 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; - /** - * 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; -} diff --git a/dist/lib/Decorators.d.ts b/dist/lib/Decorators.d.ts deleted file mode 100644 index d59ae9c..0000000 --- a/dist/lib/Decorators.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -import * as MongoDB from "mongodb"; -import Skmatc = require("skmatc"); -import { Instance } from "./Instance"; -import { Model } from "./Model"; -import { IndexSpecification } from "./Index"; -import { InstanceImplementation } from "./InstanceInterface"; -/** - * Specifies the name of the collection to which this instance's documents should be sent. - * @param name The name of the MongoDB collection to store the documents in. - * - * This decorator replaces the use of the static collection property on instance implementation - * classes. If your transpiler does not support decorators then you are free to make use of the - * property instead. - */ -export declare function Collection(name: string): (target: InstanceImplementation) => void; -/** - * Specifies a MongoDB collection level index to be managed by Iridium for this instance type. - * More than one instance of this decorator may be used if you wish to specify multiple indexes. - * @param spec The formal index specification which defines the properties and ordering used in the index. - * @param options The options dictating the way in which the index behaves. - * - * This decorator replaces the use of the static indexes property on instance implementation - * classes. If your transpiler does not support decorators then you are free to make use of the - * property instead. - */ -export declare function Index(spec: IndexSpecification, options?: MongoDB.IndexOptions): (target: InstanceImplementation) => void; -/** - * Specifies a custom validator to be made available for this collection's schema. - * More than one instance of this decorator may be used if you wish to specify multiple validators. - * @param forType The value in the schema which will be delegated to this function for validation. - * @param validate A function which calls this.assert(condition) to determine whether a schema node is valid or not. - * - * This decorator replaces the use of the static validators property on instance implementation - * classes. If your transpiler does not support decorators then you are free to make use of the - * property instead. - */ -export declare function Validate(forType: any, validate: (schema: any, data: any, path: string) => Skmatc.Result): (target: InstanceImplementation) => void; -/** - * Specifies the schema type for the property this decorator is applied to. This can be used to replace the - * static schema property on your instance. Multiple instances of this decorator can be applied, but no more - * than one per property. - * - * @param asType The schema validation type to make use of for this property - * @param required Whether this property is required to have a value or not, defaults to true. - */ -export declare function Property(asType: any, required?: boolean): (target: Instance, name: string) => void; -/** - * Specifies the schema type for a property with the given name on the class this decorator is applied to. This - * can either compliment or replace the static schema property on your instance class. - * - * @param name The name of the property that is being targetted - * @param asType The schema validation type to make use of for this property - * @param required Whether this property is required to have a value or not, defaults to true. - */ -export declare function Property(name: string, asType: any, required?: boolean): (target: InstanceImplementation) => void; -/** - * Specifies a custom transform to be applied to the property this decorator is applied to. - * - * @param fromDB The function used to convert values from the database for the application. - * @param toDB The function used to convert values from the application to the form used in the database. - * - * This decorator can either compliment or replace the static transforms property on your instance - * class, however only one transform can be applied to any property at a time. - * If your transpiler does not support decorators then you are free to make use of the - * property instead. - * - * If this decorator is applied to the instance class itself, as opposed to a property, then - * it will be treated as a $document transformer - and will receive the full document as opposed - * to individual property values. Similarly, it is expected to return a full document when either - * fromDB or toDB is called. - */ -export declare function Transform(fromDB: (value: any, property: string, model: Model) => any, toDB: (value: any, property: string, model: Model) => any): (target: Instance, property?: string) => void; -/** - * Specifies that this property should be treated as an ObjectID, with the requisite validator and transforms. - * - * This decorator applies an ObjectID validator to the property, which ensures that values sent to the database - * are instances of the MongoDB ObjectID type, as well as applying a transform operation which converts ObjectIDs - * to strings for your application, and then converts strings back to ObjectIDs for the database. - */ -export declare function ObjectID(target: Instance, name: string): void; -/** - * Specifies that this property should be stored using the MongoDB binary type and represented as a Buffer. - * - * This decorator applies a Buffer validator to the property, which ensures that values you send to the database - * are well formatted Buffer objects represented using the BSON Binary datatype. In addition to this, it will - * apply a transform which ensures you only work with Buffer objects and that data is always stored in Binary - * format. - */ -export declare function Binary(target: Instance, name: string): void; diff --git a/dist/lib/General.d.ts b/dist/lib/General.d.ts deleted file mode 100644 index 4b33f67..0000000 --- a/dist/lib/General.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * A method which is called once an asynchronous operation has completed, an alternative - * to using Promises. - * @param T The type of object returned by the asynchronous operation. - */ -export interface Callback { - /** - * @param err The error object, if one occurred, otherwise null if the operation completed successfully. - * @param object The result of the asynchronous operation if it completed successfully. If err is defined, the presence of this value is unknown. - */ - (err: Error, object?: T): void; -} -/** - * A method which is used to determine whether a value within a collection meets a set of criteria. - * @param T The type of item in the collection. - */ -export interface Predicate { - /** - * @param object The value of the item in the collection - * @param key The key, if one is available, under which the item appeared within the collection - * @returns A true-y value if the item met the predicate conditions, false-y values if it did not. - */ - (object: T, key?: string): boolean; -} -/** - * A method which is called to retrieve a value of the given type. - * @param T The type of value to be retrieved. - */ -export interface PropertyGetter { - /** - * Gets the current value of the property - * @returns The current value - */ - (): T; -} -/** - * A method which is called to set a value of the given type. - * @param T The type of value to set - */ -export interface PropertySetter { - /** - * Sets the value to the provided one - * @param value The new value to set - */ - (value: T): void; -} -/** - * A compound property which provides either a getter, setter or both. - * @param T The type of objects stored in the property - */ -export interface Property { - /** - * An optional getter which can be used to retrieve the property's value - */ - get?: PropertyGetter; - /** - * An optional setter which can be used to set the property's value - */ - set?: PropertySetter; -} diff --git a/dist/lib/Hooks.d.ts b/dist/lib/Hooks.d.ts deleted file mode 100644 index f929ca0..0000000 --- a/dist/lib/Hooks.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Hooks { - onCreating?(document: TDocument): Promise | void; - onRetrieved?(document: TDocument): Promise | void; - onReady?(instance: TInstance): Promise | void; - onSaving?(instance: TInstance, changes: any): Promise | void; -} diff --git a/dist/lib/Index.d.ts b/dist/lib/Index.d.ts deleted file mode 100644 index 6eb5446..0000000 --- a/dist/lib/Index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as MongoDB from "mongodb"; -export interface Index { - spec: IndexSpecification; - options?: MongoDB.IndexOptions; -} -export interface IndexSpecification { - [key: string]: number | string; -} diff --git a/dist/lib/Instance.d.ts b/dist/lib/Instance.d.ts deleted file mode 100644 index 2d1ca87..0000000 --- a/dist/lib/Instance.d.ts +++ /dev/null @@ -1,194 +0,0 @@ -import { Model } from "./Model"; -import { CacheDirector } from "./CacheDirector"; -import * as General from "./General"; -import * as Index from "./Index"; -import { Schema } from "./Schema"; -import { Transforms } from "./Transforms"; -import * as Bluebird from "bluebird"; -import * as Skmatc from "skmatc"; -/** - * The default Iridium Instance implementation which provides methods for saving, refreshing and - * removing the wrapped document from the collection, as well as integrating with Omnom, our - * built in document diff processor which allows clean, atomic, document updates to be performed - * without needing to write the update queries yourself. - * - * @param TDocument The interface representing the structure of the documents in the collection. - * @param TInstance The type of instance which wraps the documents, generally the subclass of this class. - * - * 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. - */ -export declare class Instance { - /** - * Creates a new instance which represents the given document as a type of model - * @param model The model that dictates the collection the document originated from as well as how validations are performed. - * @param document The document which should be wrapped by this instance - * @param isNew Whether the document is new (doesn't exist in the database) or not - * @param isPartial Whether the document has only a subset of its fields populated - * - */ - constructor(model: Model, 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; - /** - * A function which is called whenever a new document is in the process of being inserted into the database. - * @param document The document which will be inserted into the database. - */ - static onCreating: (document: { - _id?: any; - }) => Promise | void; - /** - * A function which is called whenever a document of this type is received from the database, prior to it being - * wrapped by an Instance object. - * @param document The document that was retrieved from the database. - */ - static onRetrieved: (document: { - _id?: any; - }) => Promise | void; - /** - * A function which is called whenever a new instance has been created to wrap a document. - * @param instance The instance which has been created. - */ - static onReady: (instance: Instance<{ - _id?: any; - }, Instance<{ - _id?: any; - }, any>>) => Promise | void; - /** - * A function which is called whenever an instance's save() method is called to allow you to interrogate and/or manipulate - * the changes which are being made. - * - * @param instance The instance to which the changes are being made - * @param changes The MongoDB change object describing the changes being made to the document. - */ - static onSaving: (instance: Instance<{ - _id?: any; - }, Instance<{ - _id?: any; - }, any>>, changes: any) => Promise | void; - /** - * The name of the collection into which documents of this type are stored. - */ - static collection: string; - /** - * The schema used to validate documents of this type before being stored in the database. - */ - static schema: Schema; - /** - * Additional which should be made available for use in the schema definition for this instance. - */ - static validators: Skmatc.Validator[]; - /** - * The transformations which should be applied to properties of documents of this type. - */ - static transforms: Transforms; - /** - * The cache director used to derive unique cache keys for documents of this type. - */ - static cache: CacheDirector; - /** - * The indexes which should be managed by Iridium for the collection used by this type. - */ - static indexes: (Index.Index | Index.IndexSpecification)[]; - /** - * 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} - */ - save(callback?: General.Callback): Bluebird; - /** - * 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} - */ - save(changes: Object, callback?: General.Callback): Bluebird; - /** - * 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} - */ - save(conditions: Object, changes: Object, callback?: General.Callback): Bluebird; - /** - * 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} - */ - update(callback?: General.Callback): Bluebird; - /** - * 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} - */ - refresh(callback?: General.Callback): Bluebird; - /** - * 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} - */ - delete(callback?: General.Callback): Bluebird; - /** - * 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} - */ - remove(callback?: General.Callback): Bluebird; - /** - * Retrieves the first element in an enumerable collection which matches the predicate - * @param collection The collection from which to retrieve the element - * @param predicate The function which determines whether to select an element - * @returns The first element in the array which matched the predicate. - */ - first(collection: T[], predicate: General.Predicate): T; - /** - * Retrieves the first element in an enumerable collection which matches the predicate - * @param collection The collection from which to retrieve the element - * @param predicate The function which determines whether to select an element - * @returns The first element in the object which matched the predicate. - */ - first(collection: { - [key: string]: T; - }, predicate: General.Predicate): T; - /** - * Retrieves a number of elements from an enumerable collection which match the predicate - * @param collection The collection from which elements will be plucked - * @param predicate The function which determines the elements to be plucked - * @returns A new array containing the elements in the array which matched the predicate. - */ - select(collection: T[], predicate: General.Predicate): T[]; - /** - * Retrieves a number of elements from an enumerable collection which match the predicate - * @param collection The collection from which elements will be plucked - * @param predicate The function which determines the elements to be plucked - * @returns An object with the properties from the collection which matched the predicate. - */ - select(collection: { - [key: string]: T; - }, predicate: General.Predicate): { - [key: string]: T; - }; - /** - * Gets the JSON representation of this instance - * @returns {TDocument} - */ - toJSON(): any; - /** - * Gets a string representation of this instance - * @returns {String} - */ - toString(): string; -} diff --git a/dist/lib/InstanceInterface.d.ts b/dist/lib/InstanceInterface.d.ts deleted file mode 100644 index 3006b96..0000000 --- a/dist/lib/InstanceInterface.d.ts +++ /dev/null @@ -1,119 +0,0 @@ -import * as Skmatc from "skmatc"; -import { Schema } from "./Schema"; -import { Model } from "./Model"; -import * as Index from "./Index"; -import { CacheDirector } from "./CacheDirector"; -import { Transforms } from "./Transforms"; -/** - * This interface dictates the format of an instance class which wraps documents received - * from the database for a specific Iridium model. - * - * @param TDocument The interface representing the documents stored in the database, after being passed through the transforms pipeline. - * @param TInstance The type of object which is instantiated when calling this implementation's constructor. - * - * It is important to note that, when implementing this interface, each of the properties and methods - * should be exposed statically. That is, you would expose the collection property as a static variable - * on the instance implementation, since prototype methods and variables become available to consumers of the - * instance itself. - */ -export interface InstanceImplementation { - /** - * A constructor which creates a new instance tied to the given model and representing the given document. - * @param model The Iridium Model which this instance should be tied to, gives the instance access to the database collection and any other context it requires. - * @param doc The document this instance should wrap from the database. This provides the data context for the instance. - * @param isNew Whether this document is known to exist in the database or not, for example, if the instance was generated from user input and hasn't been saved yet. - * @param isPartial Whether the document which has been given to this instance had any field restrictions imposed on it during the query, and may therefore only contain partial data. - */ - new (model: Model, doc: TDocument, isNew?: boolean, isPartial?: boolean): TInstance; - /** - * The name of the database collection from which documents are retrieved, and to which they are stored. - */ - collection: string; - /** - * The database schematic used for validation of instances prior to storing them in the database. - * This schematic should follow the guides set out in skmatc's documentation, and is used whenever - * you insert a new document into the collection or save an instance using the default instance type. - * Operations like update() (and by extension, save() when using the update operations) cannot be checked - * by skmatc for consistency and as a result will not have their data validated - be careful when making - * use of them as a result. - */ - schema: Schema; - /** - * Any additional indexes on the collection which should be managed by Iridium. - * This field is optional, but if provided allows you to make use of the model's ensureIndexes() method - * to automatically generate all specified indexes. - */ - indexes?: (Index.Index | Index.IndexSpecification)[]; - /** - * An optional method which will be called whenever a document is about to be inserted into the database, - * allowing you to set default values and do any preprocessing you wish prior to the document being inserted. - * - * @param document The document which will be inserted into the database. - * - * This method is executed synchronously, however you can perform asynchronous operations by returning a - * promise which resolves once your task has completed. Be aware that this method is executed for every - * document inserted into the database. As a result, long running tasks will have a significant impact - * on the performance of your inserts. - */ - onCreating?(document: TDocument): Promise | void; - /** - * An optional method which is called whenever a new document is received from the model's collection and - * prior to the document being wrapped, can be used to perform preprocessing if necessary - however we recommend - * you rather make use of transforms for that task. - * - * @param document The document that was retrieved from the database. - * - * This method is executed synchronously, however you can perform asynchronous operations by returning a - * promise which resolves once your task has completed. Be aware that this method is executed for every - * document retrieved from the database. As a result, long running tasks will have a significant impact - * on the performance of your queries. - */ - onRetrieved?(document: TDocument): Promise | void; - /** - * An optional method which is called whenever a new document for this model has been wrapped in an instance. - * - * @param instance The instance which has been created. - * - * This method is executed synchronously, however you can perform asynchronous operations by returning a - * promise which resolves once your task has completed. Be aware that this method is executed for every - * document retrieved from the database. As a result, long running tasks will have a significant impact - * on the performance of your queries. - */ - onReady?(instance: TInstance): Promise | void; - /** - * An optional method which is called prior to saving an instance, it is provided with the instance itself as - * well as the proposed changes to the instance. This allows you to make additional changes, such as updating - * a lastChanged property on the document, or abort changes by throwing an error. - * - * @param instance The instance to which the changes are being made - * @param changes The MongoDB change object describing the changes being made to the document. - * - * This method is executed synchronously, however you can perform asynchronous operations by returning a - * promise which resolves once your task has completed. Be aware that this method is executed for every - * call to save. As a result, long running tasks will have a significant impact on how quickly your save - * operations are dispatched. - */ - onSaving?(instance: TInstance, changes: any): Promise | void; - /** - * The cache controller used to determine whether a document may be cached, as well as deriving a unique cache - * key for the document and similarly, for a query. This works in concert with the cache implementation itself - * to ensure that documents are cached in an intelligent manner. By default this will simply make use of the - * document's _id field as the cache key - however that behaviour may be modified if you wish to query on other - * properties instead. - */ - cache?: CacheDirector; - /** - * Any additional validation types you wish to make available for use within this model's database schema. This - * allows you to validate using conditions otherwise not available within skmatc itself. For more information - * on implementing a validator, take a look at the skmatc documentation on GitHub. - */ - validators?: Skmatc.Validator[]; - /** - * Any transform operations you would like to perform on documents received from the database, or prior to being - * sent to the database. These may include things such as converting ObjectIDs to strings for the application, and - * then back to ObjectIDs once they return to the database. - */ - transforms?: Transforms; -} diff --git a/dist/lib/Middleware.d.ts b/dist/lib/Middleware.d.ts deleted file mode 100644 index 16bf1d7..0000000 --- a/dist/lib/Middleware.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Core } from "./Core"; -/** - * Middlewares provided by Iridium, such as the Express one, derive from this interface. - * @internal - */ -export interface MiddlewareFactory { - (core: Core): T; -} diff --git a/dist/lib/Model.d.ts b/dist/lib/Model.d.ts deleted file mode 100644 index 8adb96a..0000000 --- a/dist/lib/Model.d.ts +++ /dev/null @@ -1,426 +0,0 @@ -import * as MongoDB from "mongodb"; -import * as Bluebird from "bluebird"; -import * as Skmatc from "skmatc"; -import { Core } from "./Core"; -import { Schema } from "./Schema"; -import { Hooks } from "./Hooks"; -import { CacheDirector } from "./CacheDirector"; -import * as General from "./General"; -import { Cursor } from "./Cursor"; -import * as Index from "./Index"; -import * as ModelOptions from "./ModelOptions"; -import { ModelCache } from "./ModelCache"; -import { ModelHelpers } from "./ModelHelpers"; -import { ModelHandlers } from "./ModelHandlers"; -import * as ModelInterfaces from "./ModelInterfaces"; -import { InstanceImplementation } from "./InstanceInterface"; -import { Transforms } from "./Transforms"; -import * as AggregationPipeline from "./Aggregate"; -/** - * An Iridium Model which represents a structured MongoDB collection. - * Models expose the methods you will generally use to query those collections, and ensure that - * the results of those queries are returned as {TInstance} instances. - * - * @param TDocument The interface used to determine the schema of documents in the collection. - * @param TInstance The interface or class used to represent collection documents in the JS world. - * - * @class - */ -export declare class Model { - /** - * Creates a new Iridium model representing a given ISchema and backed by a collection whose name is specified - * @param core The Iridium core that this model should use for database access - * @param instanceType The class which will be instantiated for each document retrieved from the database - * @constructor - */ - constructor(core: Core, instanceType: InstanceImplementation); - /** - * Loads any externally available properties (generally accessed using public getters/setters). - */ - private loadExternal(instanceType); - /** - * Loads any internally (protected/private) properties and helpers only used within Iridium itself. - */ - private loadInternal(); - /** - * Process any callbacks and plugin delegation for the creation of this model. - * It will generally be called whenever a new Iridium Core is created, however is - * more specifically tied to the lifespan of the models themselves. - */ - private onNewModel(); - private _helpers; - /** - * Provides helper methods used by Iridium for common tasks - * @returns A set of helper methods which are used within Iridium for common tasks - */ - helpers: ModelHelpers; - private _handlers; - /** - * Provides helper methods used by Iridium for hook delegation and common processes - * @returns A set of helper methods which perform common event and response handling tasks within Iridium. - */ - handlers: ModelHandlers; - private _hooks; - /** - * Gets the even hooks subscribed on this model for a number of different state changes. - * These hooks are primarily intended to allow lifecycle manipulation logic to be added - * in the user's model definition, allowing tasks such as the setting of default values - * or automatic client-side joins to take place. - */ - hooks: Hooks; - private _schema; - /** - * Gets the schema dictating the data structure represented by this model. - * The schema is used by skmatc to validate documents before saving to the database, however - * until MongoDB 3.1 becomes widely available (with server side validation support) we are - * limited in our ability to validate certain types of updates. As such, these validations - * act more as a data-integrity check than anything else, unless you purely make use of Omnom - * updates within instances. - * @public - * @returns The defined validation schema for this model - */ - schema: Schema; - private _core; - /** - * Gets the Iridium core that this model is associated with. - * @public - * @returns The Iridium core that this model is bound to - */ - core: Core; - private _collection; - /** - * Gets the underlying MongoDB collection from which this model's documents are retrieved. - * You can make use of this object if you require any low level access to the MongoDB collection, - * however we recommend you make use of the Iridium methods whereever possible, as we cannot - * guarantee the accuracy of the type definitions for the underlying MongoDB driver. - * @public - * @returns {Collection} - */ - collection: MongoDB.Collection; - /** - * Gets the name of the underlying MongoDB collection from which this model's documents are retrieved - * @public - */ - /** - * Sets the name of the underlying MongoDB collection from which this model's documents are retrieved - * @public - */ - collectionName: string; - private _cacheDirector; - /** - * Gets the cache controller which dictates which queries will be cached, and under which key - * @public - * @returns {CacheDirector} - */ - cacheDirector: CacheDirector; - private _cache; - /** - * Gets the cache responsible for storing objects for quick retrieval under certain conditions - * @public - * @returns {ModelCache} - */ - cache: ModelCache; - private _Instance; - /** - * Gets the constructor responsible for creating instances for this model - */ - Instance: ModelInterfaces.ModelSpecificInstanceConstructor; - private _transforms; - /** - * Gets the transforms which are applied whenever a document is received from the database, or - * prior to storing a document in the database. Tasks such as converting an ObjectID to a string - * and vice versa are all listed in this object. - */ - transforms: Transforms; - private _validators; - /** - * Gets the custom validation types available for this model. These validators are added to the - * default skmatc validators, as well as those available through plugins, for use when checking - * your instances. - */ - validators: Skmatc.Validator[]; - private _indexes; - /** - * Gets the indexes which Iridium will manage on this model's database collection. - */ - indexes: (Index.Index | Index.IndexSpecification)[]; - /** - * Retrieves all documents in the collection and wraps them as instances - * @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available - * @returns {Promise} - */ - find(): Cursor; - /** - * Returns all documents in the collection which match the conditions and wraps them as instances - * @param {Object} conditions The MongoDB query dictating which documents to return - * @returns {Promise} - */ - find(conditions: { - _id?: any; - [key: string]: any; - } | any): Cursor; - /** - * Returns all documents in the collection which match the conditions - * @param {Object} conditions The MongoDB query dictating which documents to return - * @param {Object} fields The fields to include or exclude from the document - * @returns {Promise} - */ - find(conditions: { - _id?: any; - [key: string]: any; - } | any, fields: { - [name: string]: number; - }): Cursor; - /** - * Retrieves a single document from the collection and wraps it as an instance - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - get(callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection with the given ID and wraps it as an instance - * @param {any} id The document's unique _id field value in downstream format - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - get(id: any, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection which matches the conditions - * @param {Object} conditions The MongoDB query dictating which document to return - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - get(conditions: { - _id?: any; - [key: string]: any; - }, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection with the given ID and wraps it as an instance - * @param {any} id The document's unique _id field value in downstream format - * @param {QueryOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - get(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection which matches the conditions - * @param {Object} conditions The MongoDB query dictating which document to return - * @param {QueryOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - get(conditions: { - _id?: any; - [key: string]: any; - }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection and wraps it as an instance - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - findOne(callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection with the given ID and wraps it as an instance - * @param {any} id The document's unique _id field value in downstream format - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - findOne(id: any, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection which matches the conditions - * @param {Object} conditions The MongoDB query dictating which document to return - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - findOne(conditions: { - _id?: any; - [key: string]: any; - }, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection with the given ID and wraps it as an instance - * @param {any} id The document's unique _id field value in downstream format - * @param {QueryOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - findOne(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird; - /** - * Retrieves a single document from the collection which matches the conditions - * @param {Object} conditions The MongoDB query dictating which document to return - * @param {QueryOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available - * @returns {Promise} - */ - findOne(conditions: { - _id?: any; - [key: string]: any; - }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird; - /** - * Inserts an object into the collection after validating it against this model's schema - * @param {Object} object The object to insert into the collection - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - create(objects: TDocument, callback?: General.Callback): Bluebird; - /** - * Inserts an object into the collection after validating it against this model's schema - * @param {Object} object The object to insert into the collection - * @param {CreateOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - create(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird; - /** - * Inserts the objects into the collection after validating them against this model's schema - * @param {Object[]} objects The objects to insert into the collection - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - create(objects: TDocument[], callback?: General.Callback): Bluebird; - /** - * Inserts the objects into the collection after validating them against this model's schema - * @param {Object[]} objects The objects to insert into the collection - * @param {CreateOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - create(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird; - /** - * Inserts an object into the collection after validating it against this model's schema - * @param {Object} object The object to insert into the collection - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - insert(objects: TDocument, callback?: General.Callback): Bluebird; - /** - * Inserts an object into the collection after validating it against this model's schema - * @param {Object} object The object to insert into the collection - * @param {CreateOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - insert(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird; - /** - * Inserts the objects into the collection after validating them against this model's schema - * @param {Object[]} objects The objects to insert into the collection - * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - insert(objects: TDocument[], callback?: General.Callback): Bluebird; - /** - * Inserts the objects into the collection after validating them against this model's schema - * @param {Object[]} objects The objects to insert into the collection - * @param {CreateOptions} options The options dictating how this function behaves - * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - insert(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird; - /** - * Updates the documents in the backing collection which match the conditions using the given update instructions - * @param {Object} conditions The conditions which determine which documents will be updated - * @param {Object} changes The changes to make to the documents - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - */ - update(conditions: { - _id?: any; - [key: string]: any; - } | any, changes: any, callback?: General.Callback): Bluebird; - /** - * Updates the documents in the backing collection which match the conditions using the given update instructions - * @param {Object} conditions The conditions which determine which documents will be updated - * @param {Object} changes The changes to make to the documents - * @param {UpdateOptions} options The options which dictate how this function behaves - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - */ - update(conditions: { - _id?: any; - [key: string]: any; - } | any, changes: any, options: ModelOptions.UpdateOptions, callback?: General.Callback): Bluebird; - /** - * Counts the number of documents in the collection - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - count(callback?: General.Callback): Bluebird; - /** - * Counts the number of documents in the collection which match the conditions provided - * @param {Object} conditions The conditions which determine whether an object is counted or not - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - count(conditions: { - _id?: any; - [key: string]: any; - } | any, callback?: General.Callback): Bluebird; - /** - * Removes all documents from the collection - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - remove(callback?: General.Callback): Bluebird; - /** - * Removes all documents from the collection which match the conditions - * @param {Object} conditions The conditions determining whether an object is removed or not - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - remove(conditions: { - _id?: any; - [key: string]: any; - } | any, callback?: General.Callback): Bluebird; - /** - * Removes all documents from the collection which match the conditions - * @param {Object} conditions The conditions determining whether an object is removed or not - * @param {Object} options The options controlling the way in which the function behaves - * @param {function(Error, Number)} callback A callback which is triggered when the operation completes - * @returns {Promise} - */ - remove(conditions: { - _id?: any; - [key: string]: any; - }, options: ModelOptions.RemoveOptions, callback?: General.Callback): Bluebird; - aggregate(pipeline: AggregationPipeline.Stage[]): Bluebird; - /** - * Ensures that the given index is created for the collection - * @param {Object} specification The index specification object used by MongoDB - * @param {function(Error, String)} callback A callback which is triggered when the operation completes - * @returns {Promise} The name of the index - */ - ensureIndex(specification: Index.IndexSpecification, callback?: General.Callback): Bluebird; - /** - * Ensures that the given index is created for the collection - * @param {Object} specification The index specification object used by MongoDB - * @param {MongoDB.IndexOptions} options The options dictating how the index is created and behaves - * @param {function(Error, String)} callback A callback which is triggered when the operation completes - * @returns {Promise} The name of the index - */ - ensureIndex(specification: Index.IndexSpecification, options: MongoDB.IndexOptions, callback?: General.Callback): Bluebird; - /** - * Ensures that all indexes defined in the model's options are created - * @param {function(Error, String[])} callback A callback which is triggered when the operation completes - * @returns {Promise} The names of the indexes - */ - ensureIndexes(callback?: General.Callback): Bluebird; - /** - * Drops the index with the specified name if it exists in the collection - * @param {String} name The name of the index to remove - * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes - * @returns {Promise} Whether the index was dropped - */ - dropIndex(name: string, callback?: General.Callback): Bluebird; - /** - * Drops the index if it exists in the collection - * @param {IndexSpecification} index The index to remove - * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes - * @returns {Promise} Whether the index was dropped - */ - dropIndex(index: Index.IndexSpecification, callback?: General.Callback): Bluebird; - /** - * Removes all indexes (except for _id) from the collection - * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes - * @returns {Promise} Whether the indexes were dropped - */ - dropIndexes(callback?: General.Callback): Bluebird; -} diff --git a/dist/lib/ModelCache.d.ts b/dist/lib/ModelCache.d.ts deleted file mode 100644 index f6311bd..0000000 --- a/dist/lib/ModelCache.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Model } from "./Model"; -import * as Bluebird from "bluebird"; -/** - * A centralized class which ties the cache and cache directors together in a cohesive way - * for use by Iridium. - * @internal - */ -export declare class ModelCache { - model: Model; - constructor(model: Model); - set(value: T): void; - get(conditions: any): Bluebird; - clear(conditions: any): void; -} diff --git a/dist/lib/ModelHandlers.d.ts b/dist/lib/ModelHandlers.d.ts deleted file mode 100644 index 4d03934..0000000 --- a/dist/lib/ModelHandlers.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Model } from "./Model"; -import * as ModelOptions from "./ModelOptions"; -import * as Bluebird from "bluebird"; -/** - * Provides a number of methods which are used to handle events that occur within - * the Iridium workflow - such as what happens when a document is received from - * the database, or how to handle the creation of new documents and saving of instances. - * - * Mostly this is for cache support, wrapping and hook triggering. - * @internal - */ -export declare class ModelHandlers { - model: Model; - constructor(model: Model); - documentReceived(conditions: any, result: TDocument, wrapper: (document: TDocument, isNew?: boolean, isPartial?: boolean) => TResult, options?: ModelOptions.QueryOptions): Bluebird; - creatingDocuments(documents: TDocument[]): Bluebird; - savingDocument(instance: TInstance, changes: any): Bluebird; -} diff --git a/dist/lib/ModelHelpers.d.ts b/dist/lib/ModelHelpers.d.ts deleted file mode 100644 index af49758..0000000 --- a/dist/lib/ModelHelpers.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Model } from "./Model"; -import * as Skmatc from "skmatc"; -/** - * A number of helper methods used commonly within Iridium, they provide a means to transform, - * validate, wrap and diff instances and documents. By keeping these methods in one place we - * help to improve testability and reduce code duplication (mouse abuse) throughout the codebase. - * @internal - */ -export declare class ModelHelpers { - model: Model; - constructor(model: Model); - private _validator; - /** - * Validates a document to ensure that it matches the model's ISchema requirements - * @param {any} document The document to validate against the ISchema - * @returns {SkmatcCore.IResult} The result of the validation - */ - validate(document: TDocument): Skmatc.Result; - /** - * Wraps the given document in an instance wrapper for use throughout the application - * @param {any} document The document to be wrapped as an instance - * @param {Boolean} isNew Whether the instance originated from the database or was created by the application - * @param {Boolean} isPartial Whether the document supplied contains all information present in the database - * @returns {any} An instance which wraps this document - */ - wrapDocument(document: TDocument, isNew?: boolean, isPartial?: boolean): TInstance; - /** - * Converts the given document to its database form into a form - * using the transforms defined on the model. - * @param {any} document The document to be converted - * @returns {any} The result of having transformed the document. - * @remarks This is only really called from insert/create - as - */ - transformToDB(document: T, options?: TransformOptions): T; - /** - * Converts the given document from its database form using the - * transforms defined on the model. - * @param document The document to be converted. - * @returns The result of having transformed the document. - * @remarks Unlike the transformToDB function - this method only applies - * document level transforms, as property level transforms are applied in - * their relevant instance setters. - */ - transformFromDB(document: TDocument, options?: TransformOptions): TDocument; - /** - * Converts the given document to its database form into a form - * using the transforms defined on the model. - * @param document The document to be converted - * @param processProperties Whether or not to process properties in addition - * document level transforms. - * @returns {any} A new document cloned from the original and transformed - */ - convertToDB(document: T, options?: TransformOptions): T; - /** - * Performs a diff operation between two documents and creates a MongoDB changes object to represent the differences - * @param {any} original The original document prior to changes being made - * @param {any} modified The document after changes were made - */ - diff(original: TDocument, modified: TDocument): any; - /** - * Clones the given document recursively, taking into account complex types like - * Buffers correctly. - * - * @param {any} The document you wish to clone deeply. - */ - cloneDocument(original: T): T; - /** - * Clones the given document recursively, taking into account complex types like - * Buffers correctly. Optimized for working with query documents instead of true - * documents. - * - * @param {any} The document you wish to clone deeply. - */ - cloneConditions(original: T): T; -} -export interface TransformOptions { - properties?: boolean; - document?: boolean; -} diff --git a/dist/lib/ModelInterfaces.d.ts b/dist/lib/ModelInterfaces.d.ts deleted file mode 100644 index 8de6b35..0000000 --- a/dist/lib/ModelInterfaces.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * The interface to which a prepared instance constructor should conform. When called with a document - * object, it should instantiate a new instance of type TInstance which is associated with its parent - * model. - * - * This is primarily used internally for prepared model instance constructors. - * - * @param TDocument The interface used to describe the structure of the documents found in the database collection. - * @param TInstance The interface or class used to wrap the documents returned from the database. - * - * @internal - */ -export interface ModelSpecificInstanceConstructor { - new (doc: TDocument, isNew?: boolean, isPartial?: boolean): TInstance; -} diff --git a/dist/lib/ModelOptions.d.ts b/dist/lib/ModelOptions.d.ts deleted file mode 100644 index 84939b0..0000000 --- a/dist/lib/ModelOptions.d.ts +++ /dev/null @@ -1,120 +0,0 @@ -import * as Index from "./Index"; -/** - * Options which can be used to control the way in which a query is executed - * against the MongoDB database. - */ -export interface QueryOptions { - cache?: boolean; - fields?: { - [name: string]: number; - }; - limit?: number; - skip?: number; - sort?: Index.IndexSpecification; -} -/** - * Options which can be used to control the way in which a document is created - * on the MongoDB server. - */ -export interface CreateOptions { - /** - * The write concern, can either be a number from 0 to the number of nodes within - * the cluster, or "majority" if you would like to wait for the majority of nodes - * within the cluster to confirm the write before returning. - * - * It is recommended that you set this to "majority", however in all situations - * where you mind if data is lost, you should set it to at least 1. - */ - w?: string | number; - /** - * The timeout in milliseconds before the write will be aborted by the MongoDB server - * and an error response (if the write concern is non-zero) is returned to the client. - */ - wtimeout?: number; - /** - * Whether to wait for the write to be commited to the server's journal (flushed to disk) - * or not. By specifying 1 here, you imply w:1 - howver this can be combined with w:"majority" - * to give excellent write reliability within a cluster, even across failures. - */ - j?: number; - /** - * Whether or not to serialize JavaScript functions which are provided as values. For security - * reasons it is probably best to set this to false, however it may come in handy under certain - * circumstances. - */ - serializeFunctions?: boolean; - /** - * Whether to generate document ObjectIDs within the client library or on the server, it is recommended - * that you leave this to default (false) unless you are making thousands of inserts per second from - * a single node and experiencing _id collisions. - */ - forceServerObjectId?: boolean; - /** - * Whether to perform an upsert operation if the document already exists. - */ - upsert?: boolean; - /** - * Whether to store the resulting document in the Iridium document cache to boost later retrieval times. - */ - cache?: boolean; -} -export interface UpdateOptions { - /** - * The write concern, can either be a number from 0 to the number of nodes within - * the cluster, or "majority" if you would like to wait for the majority of nodes - * within the cluster to confirm the write before returning. - * - * It is recommended that you set this to "majority", however in all situations - * where you mind if data is lost, you should set it to at least 1. - */ - w?: string | number; - /** - * The timeout in milliseconds before the write will be aborted by the MongoDB server - * and an error response (if the write concern is non-zero) is returned to the client. - */ - wtimeout?: number; - /** - * Whether to wait for the write to be commited to the server's journal (flushed to disk) - * or not. By specifying 1 here, you imply w:1 - howver this can be combined with w:"majority" - * to give excellent write reliability within a cluster, even across failures. - */ - j?: boolean; - /** - * Whether to perform an upsert operation if the document already exists. This can be combined - * with $setOnInsert to automatically create documents which do not exist in the database prior - * to making changes - and can be very handy for high-throughput systems. - */ - upsert?: boolean; - /** - * Whether to update multiple documents at once, defaults to false unless run using a method - * which explcitly sets it to true. - */ - multi?: boolean; -} -export interface RemoveOptions { - /** - * The write concern, can either be a number from 0 to the number of nodes within - * the cluster, or "majority" if you would like to wait for the majority of nodes - * within the cluster to confirm the write before returning. - * - * It is recommended that you set this to "majority", however in all situations - * where you mind if data is lost, you should set it to at least 1. - */ - w?: string | number; - /** - * The timeout in milliseconds before the write will be aborted by the MongoDB server - * and an error response (if the write concern is non-zero) is returned to the client. - */ - wtimeout?: number; - /** - * Whether to wait for the write to be commited to the server's journal (flushed to disk) - * or not. By specifying 1 here, you imply w:1 - howver this can be combined with w:"majority" - * to give excellent write reliability within a cluster, even across failures. - */ - j?: boolean; - /** - * Whether to only remove the first document in the collection or not, by default this is false - * and any document matching the conditions will be removed. - */ - single?: boolean; -} diff --git a/dist/lib/ModelSpecificInstance.d.ts b/dist/lib/ModelSpecificInstance.d.ts deleted file mode 100644 index 87fec99..0000000 --- a/dist/lib/ModelSpecificInstance.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Model } from "./Model"; -import { InstanceImplementation } from "./InstanceInterface"; -import { ModelSpecificInstanceConstructor } from "./ModelInterfaces"; -/** - * Creates a new subclass of the given instanceType which correctly performs property transforms - * and associates the instance with the correct model when instantiated. - * - * @param TDocument The interface representing the structure of the documents found in the database. - * @param TInstance The interface or class representing the documents after they have been wrapped in an instance. - * - * @param model The model which instances should be associated with when the resulting constructor is used. - * @param instanceType The constructor used to create new instances of type TInstance. - * - * @internal - */ -export declare function ModelSpecificInstance(model: Model, instanceType: InstanceImplementation): ModelSpecificInstanceConstructor; diff --git a/dist/lib/Plugins.d.ts b/dist/lib/Plugins.d.ts deleted file mode 100644 index ff8384f..0000000 --- a/dist/lib/Plugins.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Model } from "./Model"; -import Skmatc = require("skmatc"); -export interface Plugin { - newModel?(model: Model): any; - newInstance?(instance: any, model: Model): any; - validate?: Skmatc.Validator | Skmatc.Validator[]; -} diff --git a/dist/lib/Schema.d.ts b/dist/lib/Schema.d.ts deleted file mode 100644 index 994c43a..0000000 --- a/dist/lib/Schema.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Schema { - _id: boolean | any; - [key: string]: any; -} diff --git a/dist/lib/Transforms.d.ts b/dist/lib/Transforms.d.ts deleted file mode 100644 index 8fb8bd4..0000000 --- a/dist/lib/Transforms.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ObjectID, Binary } from "./BSON"; -import { Model } from "./Model"; -export interface Transforms { - /** - * A transform which is applied to the entire document. - */ - $document?: PropertyTransform; - _id?: PropertyTransform; - [property: string]: PropertyTransform; -} -/** - * Converts the value of a property to and from its database representation. - */ -export interface PropertyTransform { - /** - * Converts a property's value from its database representation into one - * suitable for the application. - * @param value The value stored in the MongoDB database document. - * @param property The name of the document property to which this transform is being applied. - * @param model The Iridium Model on which this transform is being applied - * @returns A derived value which is more useful to the application. - */ - fromDB(value: T, property: string, model: Model): any; - /** - * Converts a property's value into a representation more suitable for - * the database. - * @param value The value used by the application. - * @param property The name of the document property to which this transform is being applied. - * @param model The Iridium Model on which this transform is being applied - * @returns The database optimized representation of the value. - */ - toDB(value: any, property: string, model: Model): T; -} -export declare const DefaultTransforms: { - ObjectID: PropertyTransform; - Binary: PropertyTransform; -}; diff --git a/dist/lib/Validators.d.ts b/dist/lib/Validators.d.ts deleted file mode 100644 index 3aff0e8..0000000 --- a/dist/lib/Validators.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import * as Skmatc from "skmatc"; -export declare function DefaultValidators(): Skmatc.Validator[]; diff --git a/dist/lib/cacheControllers/IDDirector.d.ts b/dist/lib/cacheControllers/IDDirector.d.ts deleted file mode 100644 index 394a0d4..0000000 --- a/dist/lib/cacheControllers/IDDirector.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { CacheDirector } from "../CacheDirector"; -/** - * Caches documents using their _id field as the unique cache key. This - * is useful if you primarily query your documents using their _id field, - * however can be suboptimal (or even a complete waste) if you use different - * types of queries. - */ -export declare class CacheOnID implements CacheDirector { - valid(object: { - _id: any; - }): boolean; - buildKey(object: { - _id: any; - }): any; - validQuery(conditions: any): boolean; - buildQueryKey(conditions: any): any; -} diff --git a/dist/lib/caches/MemoryCache.d.ts b/dist/lib/caches/MemoryCache.d.ts deleted file mode 100644 index 1e2035d..0000000 --- a/dist/lib/caches/MemoryCache.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import * as Bluebird from "bluebird"; -import { Cache } from "../Cache"; -/** - * A cache implementation which stores documents in an in-memory cache. - * - * Be aware that this is an incredibly simplistic implementation which doesn't manage - * memory usage at all and is very likely NOT suitable for production use. - */ -export declare class MemoryCache implements Cache { - private cache; - set(key: string, value: T): Bluebird; - get(key: string): Bluebird; - clear(key: string): Bluebird; -} diff --git a/dist/lib/caches/NoOpCache.d.ts b/dist/lib/caches/NoOpCache.d.ts deleted file mode 100644 index 39b6a94..0000000 --- a/dist/lib/caches/NoOpCache.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Cache } from "../Cache"; -import Bluebird = require("bluebird"); -/** - * A cache implementation which does not cache any received documents - * and returns nothing when requested - mimicking an empty cache. - * - * This is the default cache used if one is not supplied and should - * not impose any significant performance overhead. - */ -export declare class NoOpCache implements Cache { - set(key: string, object: T): Bluebird; - get(key: string): Bluebird; - clear(key: string): Bluebird; -} diff --git a/dist/lib/middleware/Express.d.ts b/dist/lib/middleware/Express.d.ts deleted file mode 100644 index 9cd6c1a..0000000 --- a/dist/lib/middleware/Express.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as http from "http"; -import { Core } from "../Core"; -/** - * A factory method which creates Express/Connect compatible middleware functions to inject - * a "db" field on your request objects as well as ensuring that the Iridium Core is connected - * to a MongoDB database before handling any requests. - * - * @internal - */ -export declare function ExpressMiddlewareFactory(core: Core): ExpressMiddleware; -/** - * An Express/Connect compatible middleware function which injects req.db and ensures that the Iridium Core - * has an active database connection before continuing the request handling process. - */ -export interface ExpressMiddleware { - (req: http.ServerRequest, res: http.ServerResponse, next: (err?: Error, route?: String) => void): any; -} diff --git a/dist/lib/utils/ObjectID.d.ts b/dist/lib/utils/ObjectID.d.ts deleted file mode 100644 index 2ae9578..0000000 --- a/dist/lib/utils/ObjectID.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as MongoDB from "mongodb"; -/** - * Converts a string to an ObjectID instance - a shortcut for require("mongodb").ObjectID.createFromHexString - * - * @param value The string representation of the ObjectID you wish to create. - * @returns A MongoDB ObjectID instance equivalent to the string you provided. - * - * You should be aware that this method performs no validation on the received string, MongoDB's ObjectID requires - * that it either be a 12 byte UTF8 string, or a 24 byte hexadecimal string in order to be converted correctly. - * - * This method removes the need for your application to directly depend on MongoDB's Node.js client library, - * which helps clean up your code a bit and reduces the headache of maintaining two different versions of the - * library (since Iridium also has one). - */ -export declare function toObjectID(value: string): MongoDB.ObjectID; diff --git a/dist/lib/utils/Omnom.d.ts b/dist/lib/utils/Omnom.d.ts deleted file mode 100644 index b02a496..0000000 --- a/dist/lib/utils/Omnom.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as MongoDB from "mongodb"; -export 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, options?: { - atomicNumbers?: boolean; - }): any; - static diff(original: [any], modified: any[], options?: { - atomicNumbers?: boolean; - }): any; - static diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID, options?: { - atomicNumbers?: boolean; - }): any; - static diff(original: Object, modified: Object, options?: { - atomicNumbers?: boolean; - }): 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 onSmallerArray(original, modified, changePath); - private onLargerArray(original, modified, changePath); - private onSimilarArray(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); -}