Socket
Socket
Sign inDemoInstall

@andrewscwei/mongodb-odm

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@andrewscwei/mongodb-odm - npm Package Compare versions

Comparing version 0.66.0 to 0.67.0

9

build/core/Aggregation.d.ts
/**
* @file Static utility class with helper functions for MongoDB's aggregation
* framework.
* @file Static utility class with helper functions for MongoDB's aggregation framework.
*/

@@ -47,4 +46,3 @@ import { AggregationPipeline, GroupStageFactorySpec, LookupStageFactoryOptions, LookupStageFactorySpec, MatchStageFactoryOptions, MatchStageFactorySpec, PipelineFactoryOperators, PipelineFactoryOptions, ProjectStageFactoryOptions, Schema, SortStageFactorySpec } from '../types';

* @param schema - The schema of the database collection.
* @param spec - Spec that defines the $lookup stage, supports looking up
* nested foreign keys.
* @param spec - Spec that defines the $lookup stage, supports looking up nested foreign keys.
* @param options - Additional options.

@@ -73,3 +71,4 @@ *

*
* @see {@link https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/}
* @see
* {@link https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/}
*

@@ -76,0 +75,0 @@ * @throws {TypeError} Invalid params or options provided.

"use strict";
/**
* @file Static utility class with helper functions for MongoDB's aggregation
* framework.
* @file Static utility class with helper functions for MongoDB's aggregation framework.
*/

@@ -99,4 +98,3 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

* @param schema - The schema of the database collection.
* @param spec - Spec that defines the $lookup stage, supports looking up
* nested foreign keys.
* @param spec - Spec that defines the $lookup stage, supports looking up nested foreign keys.
* @param options - Additional options.

@@ -125,3 +123,4 @@ *

*
* @see {@link https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/}
* @see
* {@link https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/}
*

@@ -128,0 +127,0 @@ * @throws {TypeError} Invalid params or options provided.

/**
* @file This is a static, abstract model that provides ORM for a single MongoDB
* collection. Every other model must inherit this class. It sets up the
* ground work for basic CRUD operations, event triggers, query
* validations, etc. All returned documents are native JSON objects.
* @file This is a static, abstract model that provides ORM for a single MongoDB collection. Every other model must
* inherit this class. It sets up the ground work for basic CRUD operations, event triggers, query validations,
* etc. All returned documents are native JSON objects.
*/

@@ -13,4 +12,3 @@ import { Collection, FilterQuery, ObjectID, UpdateQuery } from 'mongodb';

/**
* Schema of this model. This property must be overridden in the derived
* class.
* Schema of this model. This property must be overridden in the derived class.
*/

@@ -45,9 +43,7 @@ readonly schema: db.Schema<T>;

/**
* Generates random fields for this model. By default, only fields that are
* marked as required and has a random() function defined will have random
* values generated. Specify `includeOptionals` to generate unrequired
* fields as well.
* Generates random fields for this model. By default, only fields that are marked as required and has a random()
* function defined will have random values generated. Specify `includeOptionals` to generate unrequired fields as
* well.
*
* @param fixedFields - A collection of fields that must be present in the
* output.
* @param fixedFields - A collection of fields that must be present in the output.
* @param options - See `ModelRandomFieldsOptions`.

@@ -61,7 +57,6 @@ *

/**
* Generates an aggregation pipeline specifically for the schema associated
* with this schema.
* Generates an aggregation pipeline specifically for the schema associated with this schema.
*
* @param queryOrOperators - This is either a query for the $match stage or
* operators for the aggregation factory function.
* @param queryOrOperators - This is either a query for the $match stage or operators for the aggregation factory
* function.
* @param options - See `PipelineFactoryOptions`.

@@ -80,7 +75,6 @@ *

/**
* Identifies the ObjectID of exactly one document matching the given query.
* Error is thrown if the document cannot be identified.
* Identifies the ObjectID of exactly one document matching the given query. Error is thrown if the document cannot
* be identified.
*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
*

@@ -94,7 +88,6 @@ * @returns The matching ObjectID.

/**
* Same as the strict identify one operation but this method swallows all
* errors and returns `undefined` if document canot be identified.
* Same as the strict identify one operation but this method swallows all errors and returns `undefined` if document
* canot be identified.
*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
*

@@ -120,7 +113,6 @@ * @returns The matching ObjectID.

/**
* Finds one document from this collection using the aggregation framework.
* If no query is specified, a random document will be fetched.
* Finds one document from this collection using the aggregation framework. If no query is specified, a random
* document will be fetched.
*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
* @param options - See `module:mongodb.Collection#aggregate`.

@@ -140,7 +132,6 @@ *

/**
* Same as the strict find one operation but this method swallows all errors
* and returns `undefined` when no document is found.
* Same as the strict find one operation but this method swallows all errors and returns `undefined` when no
* document is found.
*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
* @param options - See `module:mongodb.Collection#aggregate`.

@@ -159,7 +150,6 @@ *

/**
* Finds multiple documents of this collection using the aggregation
* framework. If no query is specified, all documents are fetched.
* Finds multiple documents of this collection using the aggregation framework. If no query is specified, all
* documents are fetched.
*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
* @param options - See `module:mongodb.Collection#aggregate`.

@@ -176,4 +166,3 @@ *

/**
* Inserts one document into this model's collection. If `doc` is not
* specified, random fields will be generated.
* Inserts one document into this model's collection. If `doc` is not specified, random fields will be generated.
*

@@ -188,4 +177,3 @@ * @param doc - Document to be inserted. See `module:mongodb.Collection#insertOne`.

*
* @throws {Error} This method is called even though insertions are disabled
* in the schema.
* @throws {Error} This method is called even though insertions are disabled in the schema.
* @throws {MongoError} collection#insertOne failed.

@@ -195,4 +183,4 @@ */

/**
* Same as the strict insert one operation except this method swallows all
* errors and returns `undefined` if the document cannot be inserted.
* Same as the strict insert one operation except this method swallows all errors and returns `undefined` if the
* document cannot be inserted.
*

@@ -226,14 +214,11 @@ * @param doc - Document to be inserted. See `module:mongodb.Collection#insertOne`.

/**
* Updates one document matched by `query` with `update` object. Note that
* if upserting, all *required* fields must be in the `query` param instead
* of the `update` param.
* Updates one document matched by `query` with `update` object. Note that if upserting, all *required* fields must
* be in the `query` param instead of the `update` param.
*
* @param query - Query for the document to update.
* @param update - Either an object whose key/value pair represent the
* fields belonging to this model to update to, or an update
* query.
* @param update - Either an object whose key/value pair represent the fields belonging to this model to update to,
* or an update query.
* @param options - See `ModelUpdateOneOptions`.
*
* @returns The updated doc if `returnDoc` is set to `true`, else there is
* no fulfillment value.
* @returns The updated doc if `returnDoc` is set to `true`, else there is no fulfillment value.
*

@@ -245,6 +230,4 @@ * @see {@link https://docs.mongodb.com/manual/reference/operator/update-field/}

*
* @throws {Error} This method is called even though updates are disabled in
* the schema.
* @throws {Error} Query is invalid probably because it is not santized due
* to hooks being skipped.
* @throws {Error} This method is called even though updates are disabled in the schema.
* @throws {Error} Query is invalid probably because it is not santized due to hooks being skipped.
* @throws {Error} A doc is updated but it cannot be found.

@@ -254,15 +237,12 @@ */

/**
* Same as the strict update one operation except this method swallows all
* errors and returns `undefined` if no document was updated (and that
* `returnDoc` is `true`) or `true`/`false` (if `returnDoc` is `false`).
* Same as the strict update one operation except this method swallows all errors and returns `undefined` if no
* document was updated (and that `returnDoc` is `true`) or `true`/`false` (if `returnDoc` is `false`).
*
* @param query - Query for the document to update.
* @param update - Either an object whose key/value pair represent the
* fields belonging to this model to update to, or an update
* query.
* @param update - Either an object whose key/value pair represent the fields belonging to this model to update to,
* or an update query.
* @param options - See `ModelUpdateOneOptions`.
*
* @returns The updated doc if `returnDoc` is set to `true`, else either
* `true` or `false` depending on whether the operation was
* successful.
* @returns The updated doc if `returnDoc` is set to `true`, else either `true` or `false` depending on whether the
* operation was successful.
*

@@ -276,10 +256,8 @@ * @see Model.updateOneStrict

* @param query - Query for document to update.
* @param update - Either an object whose key/value pair represent the
* fields belonging to this model to update to, or an update
* query.
* @param update - Either an object whose key/value pair represent the fields belonging to this model to update to,
* or an update query.
* @param options - See `ModelUpdateManyOptions`.
*
* @returns The updated docs if `returnDocs` is set to `true`, else `true`
* or `false` depending on whether or not the operation was
* successful.
* @returns The updated docs if `returnDocs` is set to `true`, else `true` or `false` depending on whether or not
* the operation was successful.
*

@@ -291,4 +269,3 @@ * @see {@link https://docs.mongodb.com/manual/reference/operator/update-field/}

*
* @throws {Error} This method is called even though updates or multiple
* updates are disabled in the schema.
* @throws {Error} This method is called even though updates or multiple updates are disabled in the schema.
* @throws {Error} One of the updated docs are not returned.

@@ -309,6 +286,4 @@ */

*
* @throws {Error} This method is called even though deletions are disabled
* in the schema.
* @throws {Error} Unable to return the deleted document when `returnDoc` is
* `true`.
* @throws {Error} This method is called even though deletions are disabled in the schema.
* @throws {Error} Unable to return the deleted document when `returnDoc` is `true`.
* @throws {Error} Unable to delete document.

@@ -318,4 +293,3 @@ */

/**
* Same as the strict delete one operation except this method swallows all
* errors.
* Same as the strict delete one operation except this method swallows all errors.
*

@@ -325,4 +299,4 @@ * @param query - Query for document to delete.

*
* @returns The deleted doc if `returnDoc` is set to `true`, else `true` or
* `false` depending on whether or not the operation was successful.
* @returns The deleted doc if `returnDoc` is set to `true`, else `true` or `false` depending on whether or not the
* operation was successful.
*

@@ -338,5 +312,4 @@ * @see Model.deleteOneStrict

*
* @returns The deleted docs if `returnDocs` is set to `true`, else `true`
* or `false` depending on whether or not the operation was
* successful.
* @returns The deleted docs if `returnDocs` is set to `true`, else `true` or `false` depending on whether or not
* the operation was successful.
*

@@ -347,9 +320,7 @@ * @see {@link http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#deleteMany}

*
* @throws {Error} This method is called even though deletions or multiple
* deletions are disabled in the schema.
* @throws {Error} This method is called even though deletions or multiple deletions are disabled in the schema.
*/
deleteMany(query: db.Query<T>, options?: ModelDeleteManyOptions): Promise<boolean | db.Document<T>[]>;
/**
* Replaces one document with another. If `replacement` is not specified,
* one with random info will be generated.
* Replaces one document with another. If `replacement` is not specified, one with random info will be generated.
*

@@ -360,4 +331,3 @@ * @param query - Query for document to replace.

*
* @returns The replaced document (by default) or the new document
* (depending on the `returnOriginal` option).
* @returns The replaced document (by default) or the new document (depending on the `returnOriginal` option).
*

@@ -372,4 +342,3 @@ * @see {@link http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#findOneAndReplace}

/**
* Same as the strict find and replace one operation except this method
* swallows all errors.
* Same as the strict find and replace one operation except this method swallows all errors.
*

@@ -380,5 +349,4 @@ * @param query - Query for document to replace.

*
* @returns The replaced document (by default) or the new document
* (depending on the `returnOriginal` option) if available,
* `undefined` otherwise.
* @returns The replaced document (by default) or the new document (depending on the `returnOriginal` option) if
* available, `undefined` otherwise.
*

@@ -399,4 +367,3 @@ * @see Model.findAndReplaceOneStrict

*
* @param query - Query used for the $match stage of the aggregation
* pipeline.
* @param query - Query used for the $match stage of the aggregation pipeline.
*

@@ -407,5 +374,4 @@ * @returns The total number of documents found. The minimum is 0.

/**
* Returns a document whose values are formatted according to the format
* functions defined in the schema. If the field is marked as encrypted in
* the schema, this process takes care of that too.
* Returns a document whose values are formatted according to the format functions defined in the schema. If the
* field is marked as encrypted in the schema, this process takes care of that too.
*

@@ -416,14 +382,11 @@ * @param doc - Document to format.

*
* @throws {Error} A field in the document to format is not defined in the
* schema.
* @throws {Error} A field in the document to format is not defined in the schema.
*/
formatDocument(doc: Partial<db.Document<T>>): Promise<Partial<db.Document<T>>>;
/**
* Validates a document of this collection and throws an error if validation
* fails. This method does not modify the document in any way. It checks for
* the following in order:
* Validates a document of this collection and throws an error if validation fails. This method does not modify the
* document in any way. It checks for the following in order:
* 1. Each field is defined in the schema.
* 2. Each field value conforms to the defined field spec.
* 3. Unique indexes are enforced (only if `ignoreUniqueIndex` is
* disabled).
* 3. Unique indexes are enforced (only if `ignoreUniqueIndex` is disabled).
* 4. No required fields are missing (only if `strict` is enabled).

@@ -436,9 +399,6 @@ *

* @throws {Error} Document is empty.
* @throws {Error} One of the fields in the document is not defined in the
* schema.
* @throws {Error} One of the fields in the document does not pass the
* validation test.
* @throws {Error} One of the fields has a duplicated value as another
* document in the collection (only if unique indexes are
* defined in the schema).
* @throws {Error} One of the fields in the document is not defined in the schema.
* @throws {Error} One of the fields in the document does not pass the validation test.
* @throws {Error} One of the fields has a duplicated value as another document in the collection (only if unique
* indexes are defined in the schema).
* @throws {Error} Some required fields in the document are missing.

@@ -448,6 +408,5 @@ */

/**
* Handler called before an attempt to insert document into the database.
* This is a good place to apply any custom pre-processing to the document
* before it is inserted into the document. This method must return the
* document to be inserted.
* Handler called before an attempt to insert document into the database. This is a good place to apply any custom
* pre-processing to the document before it is inserted into the document. This method must return the document to
* be inserted.
*

@@ -467,4 +426,4 @@ * @param doc - The document to be inserted.

/**
* Handler called before an attempted update operation. This method must
* return the query and update descriptor for the update operation.
* Handler called before an attempted update operation. This method must return the query and update descriptor for
* the update operation.
*

@@ -478,10 +437,7 @@ * @param query - The query for document(s) to update.

/**
* Handler called after a document or a set of documents have been
* successfully updated.
* Handler called after a document or a set of documents have been successfully updated.
*
* @param prevDoc - The document before it is updated. This is only
* available if `returnDoc` was enabled, and only for
* updateOne().
* @param newDocs - The updated document(s). This is only available if
* `returnDoc` or `returnDocs` was enabled.
* @param prevDoc - The document before it is updated. This is only available if `returnDoc` was enabled, and only
* for updateOne().
* @param newDocs - The updated document(s). This is only available if `returnDoc` or `returnDocs` was enabled.
*/

@@ -498,4 +454,3 @@ didUpdateDocument(prevDoc?: db.Document<T> | undefined, newDocs?: db.Document<T> | db.Document<T>[] | undefined): Promise<void>;

/**
* Handler called after a document or a set of documents are successfully
* deleted.
* Handler called after a document or a set of documents are successfully deleted.
*

@@ -506,4 +461,3 @@ * @param docs - The deleted document(s) if available.

/**
* Processes a document before it is inserted. This is also used during an
* upsert operation.
* Processes a document before it is inserted. This is also used during an upsert operation.
*

@@ -523,4 +477,3 @@ * @param doc - The document to be inserted/upserted.

/**
* Handler invoked right before an update. This is NOT invoked on an
* insertion.
* Handler invoked right before an update. This is NOT invoked on an insertion.
*

@@ -533,4 +486,3 @@ * @param query - Query for document to update.

*
* @throws {Error} Attempting to upsert even though upserts are disabled in
* the schema.
* @throws {Error} Attempting to upsert even though upserts are disabled in the schema.
*

@@ -541,4 +493,3 @@ * @todo Handle remaining update operators.

/**
* Handler invoked right after an update. This does not account for
* insertions.
* Handler invoked right after an update. This does not account for insertions.
*

@@ -567,7 +518,5 @@ * @param oldDoc - The original document.

/**
* Deletes documents from other collections that have a foreign key to this
* collection, as specified in the schema.
* Deletes documents from other collections that have a foreign key to this collection, as specified in the schema.
*
* @param docId - The ID of the document in this collection in which other
* collections are pointing to.
* @param docId - The ID of the document in this collection in which other collections are pointing to.
*

@@ -579,4 +528,4 @@ * @throws {Error} Cascade deletion is incorrectly defined in the schema.

/**
* Validates a doc of this model to see if the required fields are in place.
* This process handles spec defined for embedded docs as well.
* Validates a doc of this model to see if the required fields are in place. This process handles spec defined for
* embedded docs as well.
*

@@ -583,0 +532,0 @@ * @param doc - The doc to validate.

/**
* @file Database configuration file. This file exports methods to interact with
* the MongoClient instance.
* @file Database configuration file. This file exports methods to interact with the MongoClient instance.
*/

@@ -18,4 +17,4 @@ import { Collection, Db, ObjectID } from 'mongodb';

/**
* Establishes a new connection to the database based on the initialized
* configuration. If there already exists one, this method does nothing.
* Establishes a new connection to the database based on the initialized configuration. If there already exists one,
* this method does nothing.
*

@@ -59,4 +58,3 @@ * @throws {Error} ODM is not configured.

/**
* Gets the MongoDB collection associated with a model or collection name and
* ensures the indexes defined in its schema.
* Gets the MongoDB collection associated with a model or collection name and ensures the indexes defined in its schema.
*

@@ -70,4 +68,3 @@ * @param modelOrCollectionName - The model or collection name.

* @throws {Error} There are no models registered.
* @throws {Error} Unable to find the model associated with the model or
* collection name.
* @throws {Error} Unable to find the model associated with the model or collection name.
*/

@@ -74,0 +71,0 @@ export declare function getCollection(modelOrCollectionName: string): Promise<Collection>;

"use strict";
/**
* @file Database configuration file. This file exports methods to interact with
* the MongoClient instance.
* @file Database configuration file. This file exports methods to interact with the MongoClient instance.
*/

@@ -56,4 +55,4 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

/**
* Establishes a new connection to the database based on the initialized
* configuration. If there already exists one, this method does nothing.
* Establishes a new connection to the database based on the initialized configuration. If there already exists one,
* this method does nothing.
*

@@ -179,4 +178,3 @@ * @throws {Error} ODM is not configured.

/**
* Gets the MongoDB collection associated with a model or collection name and
* ensures the indexes defined in its schema.
* Gets the MongoDB collection associated with a model or collection name and ensures the indexes defined in its schema.
*

@@ -190,4 +188,3 @@ * @param modelOrCollectionName - The model or collection name.

* @throws {Error} There are no models registered.
* @throws {Error} Unable to find the model associated with the model or
* collection name.
* @throws {Error} Unable to find the model associated with the model or collection name.
*/

@@ -194,0 +191,0 @@ function getCollection(modelOrCollectionName) {

@@ -72,10 +72,8 @@ import { CollectionAggregationOptions, CollectionInsertManyOptions, CollectionInsertOneOptions, CommonOptions, FilterQuery, FindOneAndReplaceOption, IndexOptions, ObjectID, ReplaceOneOptions, UpdateQuery } from 'mongodb';

/**
* Name of the collection in the MongoDB. Should be in lower camel-case and
* pluralized, i.e. `models`.
* Name of the collection in the MongoDB. Should be in lower camel-case and pluralized, i.e. `models`.
*/
collection: string;
/**
* Specifies whether timestamp fields will be automatically generated and
* tracked per CRUD operation. The genrated fields are `updatedAt` and
* `createdAt`, which are both `Date` values.
* Specifies whether timestamp fields will be automatically generated and tracked per CRUD operation. The genrated
* fields are `updatedAt` and `createdAt`, which are both `Date` values.
*/

@@ -112,7 +110,5 @@ timestamps?: boolean;

/**
* Indicates whether cascade deletion should occur if a document of this
* collection is deleted. This array should contain a list of model names
* indicating that once a document in this collection is deleted, other
* documents in the models listed in this array should also be deleted if
* it has a foreign key to the deleted document.
* Indicates whether cascade deletion should occur if a document of this collection is deleted. This array should
* contain a list of model names indicating that once a document in this collection is deleted, other documents in the
* models listed in this array should also be deleted if it has a foreign key to the deleted document.
*/

@@ -147,17 +143,14 @@ cascade?: string[];

/**
* Tells the validation process to account for required fields. That is, if
* this is `true` and some required fields are missing in the document to be
* validated, validation fails.
* Tells the validation process to account for required fields. That is, if this is `true` and some required fields
* are missing in the document to be validated, validation fails.
*/
strict?: boolean;
/**
* Tells the validation process to account for unique indexes. That is, if
* this is `false` and one or more field values are not unique when it
* supposedly has a unique index, validation fails.
* Tells the validation process to account for unique indexes. That is, if this is `false` and one or more field
* values are not unique when it supposedly has a unique index, validation fails.
*/
ignoreUniqueIndex?: boolean;
/**
* Tells the validation process that the document contains dot notations to
* in its keys. Dot notations are usually used by udate queries to update
* fields in an embedded doc as opposed to a top-level field.
* Tells the validation process that the document contains dot notations to in its keys. Dot notations are usually
* used by udate queries to update fields in an embedded doc as opposed to a top-level field.
*/

@@ -172,4 +165,3 @@ accountForDotNotation?: boolean;

/**
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are
* automatically generated before insertion.
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are automatically generated before insertion.
*/

@@ -180,4 +172,3 @@ ignoreTimestamps?: boolean;

/**
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are
* automatically generated before insertion.
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are automatically generated before insertion.
*/

@@ -192,4 +183,3 @@ ignoreTimestamps?: boolean;

/**
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are
* automatically generated before insertion.
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are automatically generated before insertion.
*/

@@ -208,4 +198,3 @@ ignoreTimestamps?: boolean;

/**
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are
* automatically generated before insertion.
* Specifies whether timestamp fields (i.e. `createdAt` and `updatedAt`) are automatically generated before insertion.
*/

@@ -267,10 +256,7 @@ ignoreTimestamps?: boolean;

/**
* Defines fields to perform lookup on used by #lookupStageFactory(). These
* fields must be references (i.e. model name as foreign keys) to another model.
* The fields are represented by the keys in this object. The accepted values of
* the keys are `true` or another object for recursive lookup of the reference
* model's foreign keys. If the value is simply `true`, lookup will only be
* performed on the immediate foreign key, all of its subsequent foreign keys
* will be ignored. Spec can be nested objects. `$unwind` is immediately
* followed after the generated `$lookup`.
* Defines fields to perform lookup on used by #lookupStageFactory(). These fields must be references (i.e. model name
* as foreign keys) to another model. The fields are represented by the keys in this object. The accepted values of the
* keys are `true` or another object for recursive lookup of the reference model's foreign keys. If the value is simply
* `true`, lookup will only be performed on the immediate foreign key, all of its subsequent foreign keys will be
* ignored. Spec can be nested objects. `$unwind` is immediately followed after the generated `$lookup`.
*/

@@ -291,4 +277,4 @@ export interface LookupStageFactorySpec {

/**
* Spec that define the $group stage. If this is a string, a simple $group
* stage will be generated with `_id` equal this string.
* Spec that define the $group stage. If this is a string, a simple $group stage will be generated with `_id` equal this
* string.
*/

@@ -311,7 +297,6 @@ export declare type GroupStageFactorySpec = string | {

/**
* An object containing key/value pairs representing a field belonging to this
* model that is a reference (aka foreign key) pointing to another model. The
* keys equate the name of the field while the values equate the `options`
* parameter for the reference models `project()` method. The values can also
* just be `true` to omit passing an `options` parameter.
* An object containing key/value pairs representing a field belonging to this model that is a reference (aka foreign
* key) pointing to another model. The keys equate the name of the field while the values equate the `options`
* parameter for the reference models `project()` method. The values can also just be `true` to omit passing an
* `options` parameter.
*/

@@ -336,16 +321,13 @@ populate?: ProjectStageFactoryOptionsPopulate;

/**
* Function for formatting field values, in which the value to be formatted will
* be passed into this function as its only paramenter.
* Function for formatting field values, in which the value to be formatted will be passed into this function as its
* only paramenter.
*/
export declare type FieldFormatFunction<T = FieldValue> = (value: T) => T;
/**
* The validation strategy can be one of several types. The behavior per type is
* as follows:
* The validation strategy can be one of several types. The behavior per type is as follows:
* 1. RegExp: The value to be validated must pass for RegExp.test().
* 2. number: The value to be validated must be <= this number. If the value
* is a string, its length must be <= this number.
* 3. any[]: The value to be validated must be one of the elements of this
* array.
* 4. Function: The value to be validated will be passed into this function
* and it must return `true`.
* 2. number: The value to be validated must be <= this number. If the value is a string, its length must be <= this
* number.
* 3. any[]: The value to be validated must be one of the elements of this array.
* 4. Function: The value to be validated will be passed into this function and it must return `true`.
*/

@@ -426,10 +408,8 @@ export declare type FieldValidationStrategy<T = FieldValue> = RegExp | number | T[] | FieldValidationFunction<T>;

*
* @returns If successful, a new ObjectID instance will be returned. If not,
* `undefined` will be returned.
* @returns If successful, a new ObjectID instance will be returned. If not, `undefined` will be returned.
*/
export declare function ObjectIDMake(value: any): ObjectID | undefined;
/**
* Checks to see if a value is a valid ObjectID and returns it if it is. If not,
* this method will check if the value is an identifiable document, and if it is
* it will return the `_id` of the document.
* Checks to see if a value is a valid ObjectID and returns it if it is. If not, this method will check if the value is
* an identifiable document, and if it is it will return the `_id` of the document.
*

@@ -436,0 +416,0 @@ * @param value - Value to check.

@@ -74,4 +74,3 @@ "use strict";

*
* @returns If successful, a new ObjectID instance will be returned. If not,
* `undefined` will be returned.
* @returns If successful, a new ObjectID instance will be returned. If not, `undefined` will be returned.
*/

@@ -85,5 +84,4 @@ function ObjectIDMake(value) {

/**
* Checks to see if a value is a valid ObjectID and returns it if it is. If not,
* this method will check if the value is an identifiable document, and if it is
* it will return the `_id` of the document.
* Checks to see if a value is a valid ObjectID and returns it if it is. If not, this method will check if the value is
* an identifiable document, and if it is it will return the `_id` of the document.
*

@@ -90,0 +88,0 @@ * @param value - Value to check.

import { FieldSpec } from '../types';
/**
* Finds and returns the spec of a field in the provided schema by its key.
* This key can be in dot notation to seek fields in embedded docs.
* Finds and returns the spec of a field in the provided schema by its key. This key can be in dot notation to seek
* fields in embedded docs.
*

@@ -6,0 +6,0 @@ * @returns The field spec.

@@ -5,4 +5,4 @@ "use strict";

/**
* Finds and returns the spec of a field in the provided schema by its key.
* This key can be in dot notation to seek fields in embedded docs.
* Finds and returns the spec of a field in the provided schema by its key. This key can be in dot notation to seek
* fields in embedded docs.
*

@@ -9,0 +9,0 @@ * @returns The field spec.

import { DocumentFragment, Schema } from '../types';
interface SanitizeDocumentOptions {
/**
* If set to `true`, fields in dot notated format will be further investigated
* to account for fields in embedded docs.
* If set to `true`, fields in dot notated format will be further investigated to account for fields in embedded docs.
*/

@@ -10,4 +9,3 @@ accountForDotNotation?: boolean;

/**
* Sanitizes a partial document by removing all extraneous fields from it
* according to the provided schema.
* Sanitizes a partial document by removing all extraneous fields from it according to the provided schema.
*

@@ -14,0 +12,0 @@ * @param schema - The collection schema.

@@ -9,4 +9,3 @@ "use strict";

/**
* Sanitizes a partial document by removing all extraneous fields from it
* according to the provided schema.
* Sanitizes a partial document by removing all extraneous fields from it according to the provided schema.
*

@@ -31,4 +30,3 @@ * @param schema - The collection schema.

continue;
// Ignore fields that don't exist in the schema with/without dot notation
// enabled.
// Ignore fields that don't exist in the schema with/without dot notation enabled.
if ((key !== '_id') && !accountForDotNotation && !schema.fields.hasOwnProperty(key))

@@ -35,0 +33,0 @@ continue;

import { Query, Schema } from '../types';
interface SanitizeQueryOptions {
/**
* If set to `true`, fields that are not specified in the schema will be
* deleted as part of the sanitizing process.
* If set to `true`, fields that are not specified in the schema will be deleted as part of the sanitizing process.
*/

@@ -10,9 +9,7 @@ strict?: boolean;

/**
* Magically transforms any supported value into a valid input for querying db
* collections. Note that this process does not perform any data validation. The
* transformation process includes the following:
* 1. Wraps an ObjectID instance or string representing an ObjectID into a
* proper query.
* 2. If strict mode is enabled, the provided schema will be used to strip out
* all extraneous fields from the input. @see sanitizeDocument
* Magically transforms any supported value into a valid input for querying db collections. Note that this process does
* not perform any data validation. The transformation process includes the following:
* 1. Wraps an ObjectID instance or string representing an ObjectID into a proper query.
* 2. If strict mode is enabled, the provided schema will be used to strip out all extraneous fields from the input.
* @see sanitizeDocument
*

@@ -19,0 +16,0 @@ * @param schema - The collection schema.

@@ -11,9 +11,7 @@ "use strict";

/**
* Magically transforms any supported value into a valid input for querying db
* collections. Note that this process does not perform any data validation. The
* transformation process includes the following:
* 1. Wraps an ObjectID instance or string representing an ObjectID into a
* proper query.
* 2. If strict mode is enabled, the provided schema will be used to strip out
* all extraneous fields from the input. @see sanitizeDocument
* Magically transforms any supported value into a valid input for querying db collections. Note that this process does
* not perform any data validation. The transformation process includes the following:
* 1. Wraps an ObjectID instance or string representing an ObjectID into a proper query.
* 2. If strict mode is enabled, the provided schema will be used to strip out all extraneous fields from the input.
* @see sanitizeDocument
*

@@ -20,0 +18,0 @@ * @param schema - The collection schema.

@@ -9,62 +9,37 @@ import { FieldSpec, FieldValidationStrategy, FieldValue } from '../types';

*
* @throws {TypeError} Value is marked as required in the spec but it is null
* or undefined.
* @throws {TypeError} Value is marked as required in the spec but it is null or undefined.
* @throws {TypeError} Value is supposed to be a string but it is not.
* @throws {TypeError} String value does not conform to the RegExp validator
* (only if validator is a RegExp).
* @throws {TypeError} Length of string value exceeds the limit (only if
* validator is a number).
* @throws {TypeError} String value is not an element of a set of strings (only
* if validator is an array).
* @throws {TypeError} String value does not conform to the RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Length of string value exceeds the limit (only if validator is a number).
* @throws {TypeError} String value is not an element of a set of strings (only if validator is an array).
* @throws {TypeError} Value is supposed to be a number but it is not.
* @throws {TypeError} Number value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Number value exceeds the maximum (only if validator is a
* number).
* @throws {TypeError} Number value is not an element of a set of numbers (only
* if validator is an array).
* @throws {TypeError} Number value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Number value exceeds the maximum (only if validator is a number).
* @throws {TypeError} Number value is not an element of a set of numbers (only if validator is an array).
* @throws {TypeError} Value is supposed to be a boolean but it is not.
* @throws {TypeError} Boolean value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Boolean value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Boolean value is not an element of a set of booleans
* (only if validator is an array).
* @throws {TypeError} Boolean value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Boolean value should not have a number validator (only if validator is a number).
* @throws {TypeError} Boolean value is not an element of a set of booleans (only if validator is an array).
* @throws {TypeError} Value is supposed to be a date but it is not.
* @throws {TypeError} Date value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Date value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Date value should not have an array validator (only if
* validator is an array).
* @throws {TypeError} Date value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Date value should not have a number validator (only if validator is a number).
* @throws {TypeError} Date value should not have an array validator (only if validator is an array).
* @throws {TypeError} Value is supposed to be an array but it is not.
* @throws {TypeError} Array value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Array value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Array value should not have an array validator (only if
* validator is an array).
* @throws {TypeError} Array value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Array value should not have a number validator (only if validator is a number).
* @throws {TypeError} Array value should not have an array validator (only if validator is an array).
* @throws {TypeError} Value is supposed to be an ObjectID but it is not.
* @throws {TypeError} ObjectID value should not have a RegExp validator (only
* if validator is a RegExp).
* @throws {TypeError} ObjectID value should not have a number validator (only
* if validator is a number).
* @throws {TypeError} ObjectID value should not have an array validator (only
* if validator is an array).
* @throws {TypeError} ObjectID value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} ObjectID value should not have a number validator (only if validator is a number).
* @throws {TypeError} ObjectID value should not have an array validator (only if validator is an array).
* @throws {TypeError} Incorrect definition of a typed array type in the spec.
* @throws {TypeError} Value is supposed to be a typed array but it is not even
* an array.
* @throws {TypeError} One or more values in the typed array is not of the
* correct type.
* @throws {TypeError} Value is supposed to be a typed array but it is not even an array.
* @throws {TypeError} One or more values in the typed array is not of the correct type.
* @throws {TypeError} Value is supposed to be an object but it is not.
* @throws {TypeError} Object value should not have a RegExp validator (only
* if validator is a RegExp).
* @throws {TypeError} Object value should not have a number validator (only
* if validator is a number).
* @throws {TypeError} Object value should not have an array validator (only
* if validator is an array).
* @throws {TypeError} Object value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Object value should not have a number validator (only if validator is a number).
* @throws {TypeError} Object value should not have an array validator (only if validator is an array).
* @throws {TypeError} One or more sub-fields of an object value is not valid.
* @throws {TypeError} Value fails custom validation function (only if validator
* is a function).
* @throws {TypeError} Value fails custom validation function (only if validator is a function).
*/
export default function validateFieldValue<T = FieldValue>(value: T, spec: FieldSpec, strategy?: FieldValidationStrategy<T>): true | undefined;

@@ -16,61 +16,36 @@ "use strict";

*
* @throws {TypeError} Value is marked as required in the spec but it is null
* or undefined.
* @throws {TypeError} Value is marked as required in the spec but it is null or undefined.
* @throws {TypeError} Value is supposed to be a string but it is not.
* @throws {TypeError} String value does not conform to the RegExp validator
* (only if validator is a RegExp).
* @throws {TypeError} Length of string value exceeds the limit (only if
* validator is a number).
* @throws {TypeError} String value is not an element of a set of strings (only
* if validator is an array).
* @throws {TypeError} String value does not conform to the RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Length of string value exceeds the limit (only if validator is a number).
* @throws {TypeError} String value is not an element of a set of strings (only if validator is an array).
* @throws {TypeError} Value is supposed to be a number but it is not.
* @throws {TypeError} Number value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Number value exceeds the maximum (only if validator is a
* number).
* @throws {TypeError} Number value is not an element of a set of numbers (only
* if validator is an array).
* @throws {TypeError} Number value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Number value exceeds the maximum (only if validator is a number).
* @throws {TypeError} Number value is not an element of a set of numbers (only if validator is an array).
* @throws {TypeError} Value is supposed to be a boolean but it is not.
* @throws {TypeError} Boolean value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Boolean value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Boolean value is not an element of a set of booleans
* (only if validator is an array).
* @throws {TypeError} Boolean value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Boolean value should not have a number validator (only if validator is a number).
* @throws {TypeError} Boolean value is not an element of a set of booleans (only if validator is an array).
* @throws {TypeError} Value is supposed to be a date but it is not.
* @throws {TypeError} Date value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Date value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Date value should not have an array validator (only if
* validator is an array).
* @throws {TypeError} Date value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Date value should not have a number validator (only if validator is a number).
* @throws {TypeError} Date value should not have an array validator (only if validator is an array).
* @throws {TypeError} Value is supposed to be an array but it is not.
* @throws {TypeError} Array value should not have a RegExp validator (only if
* validator is a RegExp).
* @throws {TypeError} Array value should not have a number validator (only if
* validator is a number).
* @throws {TypeError} Array value should not have an array validator (only if
* validator is an array).
* @throws {TypeError} Array value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Array value should not have a number validator (only if validator is a number).
* @throws {TypeError} Array value should not have an array validator (only if validator is an array).
* @throws {TypeError} Value is supposed to be an ObjectID but it is not.
* @throws {TypeError} ObjectID value should not have a RegExp validator (only
* if validator is a RegExp).
* @throws {TypeError} ObjectID value should not have a number validator (only
* if validator is a number).
* @throws {TypeError} ObjectID value should not have an array validator (only
* if validator is an array).
* @throws {TypeError} ObjectID value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} ObjectID value should not have a number validator (only if validator is a number).
* @throws {TypeError} ObjectID value should not have an array validator (only if validator is an array).
* @throws {TypeError} Incorrect definition of a typed array type in the spec.
* @throws {TypeError} Value is supposed to be a typed array but it is not even
* an array.
* @throws {TypeError} One or more values in the typed array is not of the
* correct type.
* @throws {TypeError} Value is supposed to be a typed array but it is not even an array.
* @throws {TypeError} One or more values in the typed array is not of the correct type.
* @throws {TypeError} Value is supposed to be an object but it is not.
* @throws {TypeError} Object value should not have a RegExp validator (only
* if validator is a RegExp).
* @throws {TypeError} Object value should not have a number validator (only
* if validator is a number).
* @throws {TypeError} Object value should not have an array validator (only
* if validator is an array).
* @throws {TypeError} Object value should not have a RegExp validator (only if validator is a RegExp).
* @throws {TypeError} Object value should not have a number validator (only if validator is a number).
* @throws {TypeError} Object value should not have an array validator (only if validator is an array).
* @throws {TypeError} One or more sub-fields of an object value is not valid.
* @throws {TypeError} Value fails custom validation function (only if validator
* is a function).
* @throws {TypeError} Value fails custom validation function (only if validator is a function).
*/

@@ -77,0 +52,0 @@ function validateFieldValue(value, spec, strategy) {

{
"name": "@andrewscwei/mongodb-odm",
"version": "0.66.0",
"version": "0.67.0",
"description": "ODM for MongoDB",

@@ -13,3 +13,3 @@ "main": "build/index.js",

"db:stop": "docker stop node-mongodb-odm-db",
"lint": "eslint --ext .ts --ignore-pattern *.spec.ts src",
"lint": "eslint --ext .ts src",
"lint:fix": "npm run lint -- --fix"

@@ -36,23 +36,23 @@ },

"dependencies": {
"@types/mongodb": "^3.5.31",
"bcrypt": "^5.0.0",
"debug": "^4.2.0",
"lodash": "^4.17.20",
"mongodb": "^3.6.2"
"@types/mongodb": "^3.6.19",
"bcrypt": "^5.0.1",
"debug": "^4.3.2",
"lodash": "^4.17.21",
"mongodb": "^3.6.9"
},
"devDependencies": {
"@types/bcrypt": "^3.0.0",
"@types/debug": "^4.1.5",
"@types/bcrypt": "^5.0.0",
"@types/debug": "^4.1.6",
"@types/dotenv": "^8.2.0",
"@types/faker": "^5.1.3",
"@types/lodash": "^4.14.162",
"@types/mocha": "^8.0.3",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"dotenv": "^8.2.0",
"eslint": "^7.11.0",
"faker": "^5.1.0",
"mocha": "^8.2.0",
"@types/faker": "^5.5.6",
"@types/lodash": "^4.14.170",
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"dotenv": "^10.0.0",
"eslint": "^7.30.0",
"faker": "^5.5.3",
"mocha": "^9.0.2",
"rimraf": "^3.0.2",
"ts-node": "^9.0.0",
"ts-node": "^10.0.0",
"typescript": "4.0.3"

@@ -59,0 +59,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc