Options
All
  • Public
  • Public/Protected
  • All
Menu

Iridium

Index

Type aliases

BSONType

BSONType: undefined | null | number | string | symbol | BSONObject | BSONArray | ObjectID | boolean | Date | RegExp

Conditions

Conditions: FilterQuery<TDocument>

InsertionDocument

InsertionDocument: TDocument | object

Objects which are to be inserted into the DB can either be in the TDocument format used by the DB already, or have a toDB() method which returns such a document for insertion.

Functions

Binary

  • Binary<TInstance, K>(target: TInstance, name: K): 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.

    Type parameters

    • TInstance: Instance<any, TInstance>

    • K: keyof TInstance

    Parameters

    • target: TInstance
    • name: K

    Returns void

BuildUrl

Collection

  • Collection(name: string): (Anonymous function)
  • Specifies the name of the collection to which this instance's documents should be sent.

    Parameters

    • name: string

      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.

    Returns (Anonymous function)

DefaultValidators

  • DefaultValidators(): Validator[]

Delay

  • Delay(ms: number): Promise<void>
  • Delay<T>(ms: number, value: T): Promise<T>
  • Returns a promise which will be resolved with undefined after given ms milliseconds.

    Parameters

    • ms: number

      The amount of time, in milliseconds, to wait before resolving

    Returns Promise<void>

  • Returns a promise which will be resolved with value after given ms milliseconds. If value is a promise, the delay will start counting down when it is fulfilled with the fullfilment value of the value promise. If value is a rejected promise, the resulting promise will be immediately rejected.

    Type parameters

    • T

    Parameters

    • ms: number

      The amount of time, in milliseconds, to wait before resolving

    • value: T

    Returns Promise<T>

ExpressMiddlewareFactory

  • 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

    Parameters

    Returns ExpressMiddleware

Map

  • Map<T, S>(list: T[] | Promise<T[]>, map: Mapper<T, Promise<S> | S>): Promise<S[]>
  • A method which maps a promised list to another promised list using the provided mapping function.

    Type parameters

    • T

    • S

    Parameters

    • list: T[] | Promise<T[]>

      The promise that provides the list

    • map: Mapper<T, Promise<S> | S>

      The method which is used to map an input entry to an output entry

    Returns Promise<S[]>

MapReduce

  • MapReduce<Key, Value, TInstance, TDocument>(map: MapFunction<TDocument>, reduce: ReduceFunction<Key, Value>): (Anonymous function)
  • Specifies that the instance is a result of a mapReduce operation and functions of that operation.

    Type parameters

    • Key

      Type of the mapped keys

    • Value

      Type of the mapped values

    • TInstance: InstanceImplementation<TDocument, TInstance>

    • TDocument

      Interface of the document on which the operation will run

    Parameters

    • map: MapFunction<TDocument>

      A function which maps documents.

    • reduce: ReduceFunction<Key, Value>

      A function which reduces mapped pairs.

      This decorator replaces the use of the static mapReduce property on instance implementation classes. If your transpiler does not support decorators then you are free to make use of the property instead.

    Returns (Anonymous function)

ModelSpecificInstance

  • Creates a new subclass of the given instanceType which correctly performs property transforms and associates the instance with the correct model when instantiated.

    internal

    Type parameters

    • TDocument: object

      The interface representing the structure of the documents found in the database.

    • TInstance

      The interface or class representing the documents after they have been wrapped in an instance.

    Parameters

    • model: Model<TDocument, TInstance>

      The model which instances should be associated with when the resulting constructor is used.

    • instanceType: InstanceImplementation<TDocument, TInstance>

      The constructor used to create new instances of type TInstance.

    Returns ModelSpecificInstanceConstructor<TDocument, TInstance>

Nodeify

  • Nodeify<T>(promise: Promise<T>, callback?: Callback<T>): Promise<T>
  • Adds support for using callbacks with methods which commonly return promises.

    Type parameters

    • T

    Parameters

    • promise: Promise<T>

      The promise that is usually returned by the method.

    • Optional callback: Callback<T>

      The callback provided in lieu of using a promise.

    Returns Promise<T>

ObjectID

  • ObjectID<TInstance, K>(target: TInstance, name: K): 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.

    Type parameters

    • TInstance: Instance<any, TInstance>

    • K: keyof TInstance

    Parameters

    • target: TInstance
    • name: K

    Returns void

Rename

  • Rename<TInstance, K>(dbField: string): (Anonymous function)
  • Renames a code field to a new name when it is persisted in the database

    Type parameters

    Parameters

    • dbField: string

      the name of the field as it is stored in the DB

    Returns (Anonymous function)

Transform

  • Transform<TInstance, K, V>(fromDB: function, toDB: function): (Anonymous function)
  • Specifies a custom transform to be applied to the property this decorator is applied to.

    Type parameters

    Parameters

    • fromDB: function

      The function used to convert values from the database for the application.

        • (value: any, property: K, model: Model<any, TInstance>): V
        • Parameters

          • value: any
          • property: K
          • model: Model<any, TInstance>

          Returns V

    • toDB: function

      The function used to convert values from the application to the form used in the database.

      Property transforms are lazily evaluated when their fields are accessed for performance reasons. Modifying the values of an array or object will not trigger its transform function unless the document level property is re-assigned.

      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.

        • (value: V, property: string, model: Model<any, TInstance>): any
        • Parameters

          • value: V
          • property: string
          • model: Model<any, TInstance>

          Returns any

    Returns (Anonymous function)

TransformClass

  • TransformClass<TInstance, K, TField, TDocument>(transformType: TransformClassType<TField, TDocument>): (Anonymous function)
  • Provides an easy to use decorator which allows you to use a compatible class as a transform type for this field.

    Type parameters

    Parameters

    • transformType: TransformClassType<TField, TDocument>

      A class whose constructor accepts the DB object and which implements a toDB() method to convert back to a DB object

    Returns (Anonymous function)

TransformClassList

  • TransformClassList<TInstance, K, TField, TElement, TDocument>(transformType: TransformClassType<TElement, TDocument>): (Anonymous function)
  • Provides an easy to use decorator which allows you to use a compatible class as a transform type for this field.

    Type parameters

    • TInstance: Instance<any, TInstance>

    • K: keyof TInstance

    • TField: TInstance[K] & ArrayLike<TElement>

    • TElement: TransformClassInstance<TDocument>

    • TDocument

    Parameters

    • transformType: TransformClassType<TElement, TDocument>

      A class whose constructor accepts the DB object and which implements a toDB() method to convert back to a DB object

    Returns (Anonymous function)

Validate

  • Validate(forType: any, validate: Skmatc.IValidationHandler): (Anonymous function)
  • 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.

    example
    iridium.validate('everything',

    function(schema, data, path) { return this.assert(data == 42, "Expected the answer to life, the universe and everything."); })

    Parameters

    • forType: any

      The value in the schema which will be delegated to this function for validation.

    • validate: Skmatc.IValidationHandler

      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.

    Returns (Anonymous function)

buildHostList

hasObjectID

  • hasObjectID(object: any): boolean
  • Type guard method which determines whether an object has an _id field present.

    Parameters

    • object: any

      The object to test for a _id field.

    Returns boolean

    Boolean indicating whether the object has an _id field present.

hasValidObjectID

  • hasValidObjectID(object: any): boolean
  • Type guard method which determines whether an object has an _id field present and populated.

    Parameters

    • object: any

      The object to test for a _id field.

    Returns boolean

    Boolean indicating whether the object has an _id field present.

toBinary

  • toBinary(value: Buffer): Binary
  • Converts a Node.js Buffer into a MongoDB Binary object. This is a shortcut for new require("mongodb").Binary(buffer).

    Parameters

    • value: Buffer

      The Buffer which you would like to convert into a Binary object

    Returns Binary

toDecimal128

  • toDecimal128(value: string): Decimal128
  • Converts a string into a Decimal128 instance - a shortcut for require("mongodb").Decimal128.fromString(value).

    Parameters

    • value: string

      The string representation of a decimal number

    Returns Decimal128

    A MongoDB Decimal128 instance equivalent to the string you provided.

toLong

  • toLong(value: string | number): Long
  • Converts a string into a Long instance - a shortcut for require("mongodb").Long.fromString(value).

    Parameters

    • value: string | number

      The string representation of a decimal number

    Returns Long

    A MongoDB Long instance equivalent to the string you provided.

toObjectID

  • toObjectID(value: string): ObjectID
  • Converts a string to an ObjectID instance - a shortcut for require("mongodb").ObjectID.createFromHexString

    Parameters

    • value: string

      The string representation of the ObjectID you wish to create.

    Returns ObjectID

    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).

Object literals

Const DefaultTransforms

DefaultTransforms: object

Binary

Binary: PropertyTransform<Binary> = <PropertyTransform<Binary>>{fromDB: value => {if(!value) return null;if(value instanceof Binary) return (<any>value).buffer;return value;},toDB: value => {if(Buffer.isBuffer(value)) return new Binary(value);if(Array.isArray(value)) return new Binary(new Buffer(value));return null;}}

ObjectID

ObjectID: PropertyTransform<ObjectID> = <PropertyTransform<ObjectID>>{fromDB: value => value instanceof ObjectID ? value.toHexString() : value,toDB: value => typeof value === "string" ? new ObjectID(value) : value}

Generated using TypeDoc