Socket
Socket
Sign inDemoInstall

iridium

Package Overview
Dependencies
26
Maintainers
1
Versions
157
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.1.6 to 7.2.0

dist/lib/MapReduce.d.ts

2

dist/example/ModelHookPlugin.d.ts
import Iridium = require("../iridium");
export = LowercaseCollectionsPlugin;
declare class LowercaseCollectionsPlugin implements Iridium.Plugin {
newModel(model: Iridium.Model<any, any>): void;
}
export = LowercaseCollectionsPlugin;

@@ -110,3 +110,3 @@ "use strict";

__decorate([
iridium_1.Property(String)
iridium_1.Property("password")
], User.prototype, "password", void 0);

@@ -162,3 +162,8 @@ __decorate([

iridium_1.Index({ sessions: 1 }, { sparse: true }),
iridium_1.Index({ "skill.xp": -1 }, { background: true })
iridium_1.Index({ "skill.xp": -1 }, { background: true }),
iridium_1.Validate("password", function (schema, data, path) {
// This should use something like zxcvbn to determine whether a password
// is strong enough for your use case.
return this.assert(typeof data === "string" && /^.{8,}$/.test(data), "Expected password to be at least 8 characters long.");
})
], User);

@@ -165,0 +170,0 @@ exports.User = User;

import Iridium = require("../iridium");
import Skmatc = require("skmatc");
export = StringCaseValidationPlugin;
declare class StringCaseValidationPlugin implements Iridium.Plugin {
validate: Skmatc.Validator[];
}
export = StringCaseValidationPlugin;

@@ -18,1 +18,2 @@ export * from "./lib/Core";

export * from "./lib/utils/ObjectID";
export * from "./lib/MapReduce";

@@ -7,2 +7,3 @@ import * as MongoDB from "mongodb";

import { InstanceImplementation } from "./InstanceInterface";
import * as MapReduceDef from "./MapReduce";
/**

@@ -37,2 +38,7 @@ * Specifies the name of the collection to which this instance's documents should be sent.

* property instead.
*
* @example
* @Iridium.Validate('everything', function(schema, data, path) {
* return this.assert(data == 42, "Expected the answer to life, the universe and everything.");
* })
*/

@@ -64,2 +70,6 @@ export declare function Validate(forType: any, validate: Skmatc.IValidationHandler): (target: InstanceImplementation<any, any>) => void;

*
* 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

@@ -93,1 +103,16 @@ * class, however only one transform can be applied to any property at a time.

export declare function Binary(target: Instance<any, any>, name: string): void;
/**
* Specifies that the instance is a result of a mapReduce operation and functions of that operation.
*
* @param TDocument Interface of the document on which the operation will run
* @param Key Type of the mapped keys
* @param Value Type of the mapped values
*
* @param {MapReduce.MapFunction<TDocument>} map A function which maps documents.
* @param {MapReduce.ReduceFunction<Key, Value>} reduce 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.
*/
export declare function MapReduce<TDocument, Key, Value>(map: MapReduceDef.MapFunction<TDocument>, reduce: MapReduceDef.ReduceFunction<Key, Value>): (target: InstanceImplementation<any, any>) => void;

@@ -47,2 +47,7 @@ "use strict";

* property instead.
*
* @example
* @Iridium.Validate('everything', function(schema, data, path) {
* return this.assert(data == 42, "Expected the answer to life, the universe and everything.");
* })
*/

@@ -82,2 +87,6 @@ function Validate(forType, validate) {

*
* 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

@@ -129,2 +138,22 @@ * class, however only one transform can be applied to any property at a time.

exports.Binary = Binary;
/**
* Specifies that the instance is a result of a mapReduce operation and functions of that operation.
*
* @param TDocument Interface of the document on which the operation will run
* @param Key Type of the mapped keys
* @param Value Type of the mapped values
*
* @param {MapReduce.MapFunction<TDocument>} map A function which maps documents.
* @param {MapReduce.ReduceFunction<Key, Value>} reduce 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.
*/
function MapReduce(map, reduce) {
return function (target) {
target.mapReduceOptions = { map: map, reduce: reduce };
};
}
exports.MapReduce = MapReduce;
//# sourceMappingURL=Decorators.js.map

@@ -10,2 +10,3 @@ /// <reference types="bluebird" />

import { Changes } from "./Changes";
import * as MapReduce from "./MapReduce";
import * as Bluebird from "bluebird";

@@ -110,2 +111,6 @@ import * as Skmatc from "skmatc";

/**
* mapReduce Options
*/
static mapReduceOptions?: MapReduce.MapReduceFunctions<any, any, any>;
/**
* Saves any changes to this instance, using the built in diff algorithm to write the update query.

@@ -112,0 +117,0 @@ * @param {function} callback A callback which is triggered when the save operation completes

@@ -8,2 +8,3 @@ import * as Skmatc from "skmatc";

import { Changes } from "./Changes";
import { MapReduceFunctions } from "./MapReduce";
/**

@@ -52,2 +53,6 @@ * This interface dictates the format of an instance class which wraps documents received

/**
* mapReduce Options
*/
mapReduceOptions?: MapReduceFunctions<any, any, any>;
/**
* An optional method which will be called whenever a document is about to be inserted into the database,

@@ -54,0 +59,0 @@ * allowing you to set default values and do any preprocessing you wish prior to the document being inserted.

@@ -22,2 +22,3 @@ /// <reference types="bluebird" />

import * as AggregationPipeline from "./Aggregate";
import { MapReducedDocument, MapReduceFunctions, MapReduceOptions } from "./MapReduce";
/**

@@ -379,2 +380,18 @@ * An Iridium Model which represents a structured MongoDB collection.

/**
* Runs a mapReduce operation in MongoDB and returns the contents of the resulting collection.
* @param functions The mapReduce functions which will be passed to MongoDB to complete the operation.
* @param options Options used to configure how MongoDB runs the mapReduce operation on your collection.
* @return A promise which completes when the mapReduce operation has written its results to the provided collection.
*/
mapReduce<Key, Value>(functions: MapReduceFunctions<TDocument, Key, Value>, options: MapReduceOptions): Bluebird<MapReducedDocument<Key, Value>[]>;
/**
* Runs a mapReduce operation in MongoDB and writes the results to a collection.
* @param instanceType An Iridium.Instance type whichThe mapReduce functions which will be passed to MongoDB to complete the operation.
* @param options Options used to configure how MongoDB runs the mapReduce operation on your collection.
* @return A promise which completes when the mapReduce operation has written its results to the provided collection.
*/
mapReduce<Key, Value>(instanceType: InstanceImplementation<MapReducedDocument<Key, Value>, any> & {
mapReduceOptions: MapReduceFunctions<TDocument, Key, Value>;
}, options: MapReduceOptions): Bluebird<void>;
/**
* Ensures that the given index is created for the collection

@@ -381,0 +398,0 @@ * @param {Object} specification The index specification object used by MongoDB

@@ -420,2 +420,33 @@ "use strict";

}
mapReduce(functions, options) {
if (functions.map) {
return new Bluebird((resolve, reject) => {
if (options.out && options.out != "inline")
return reject(new Error("Expected inline mapReduce output mode for this method signature"));
let opts = options;
opts.out = { inline: 1 };
this.collection.mapReduce(functions.map, functions.reduce, opts, function (err, data) {
if (err)
return reject(err);
return resolve(data);
});
});
}
else {
let instanceType = functions;
return new Bluebird((resolve, reject) => {
if (options.out && options.out == "inline")
return reject(new Error("Expected a non-inline mapReduce output mode for this method signature"));
let opts = options;
let out = {};
out[options.out] = instanceType.collection;
opts.out = out;
this.collection.mapReduce(instanceType.mapReduceOptions.map, instanceType.mapReduceOptions.reduce, opts, (err, data) => {
if (err)
return reject(err);
return resolve();
});
});
}
}
ensureIndex(specification, options, callback) {

@@ -422,0 +453,0 @@ if (typeof options === "function") {

{
"name": "iridium",
"version": "7.1.6",
"version": "7.2.0",
"author": "Benjamin Pannell <admin@sierrasoftworks.com>",

@@ -37,6 +37,6 @@ "description": "A custom lightweight ORM for MongoDB designed for power-users",

"predoc:build": "cd ./doc && git checkout gh-pages",
"doc:build": "typedoc --out ./doc --mode file --name Iridium iridium.ts",
"doc:build": "typedoc --out ./doc --mode file --name Iridium --tsconfig tsconfig.doc.json iridium.ts",
"postdoc:build": "echo gitdir: ../.git/modules/doc> ./doc/.git",
"doc:stage": "cd ./doc && git add -A",
"doc:commit": "cd ./doc && git diff --cached --exit-code && git commit -m \"doc: Update documentation\" || true",
"doc:commit": "cd ./doc && git diff-index --cached --quiet HEAD -- && git commit -m \"doc: Update documentation\" || true",
"doc:push": "cd ./doc && git push",

@@ -54,34 +54,34 @@ "doc:publish": "npm run doc:stage && npm run doc:commit && npm run doc:push",

"dependencies": {
"@types/bluebird": "^3.5.2",
"@types/lodash": "^4.14.58",
"@types/mongodb": "^2.1.41",
"@types/chai": "^3.4.35",
"@types/bluebird": "^3.5.4",
"@types/lodash": "^4.14.64",
"@types/mongodb": "^2.2.2",
"@types/chai": "^3.5.2",
"bluebird": "^3.5.0",
"lodash": "^4.17.4",
"mongodb": "^2.2.25",
"mongodb": "^2.2.26",
"skmatc": "~1.2.2"
},
"peerDependencies": {
"@types/bluebird": "^3.5.2",
"@types/lodash": "^4.14.58",
"@types/mongodb": "^2.1.41",
"@types/chai": "^3.4.35"
"@types/bluebird": "^3.5.4",
"@types/lodash": "^4.14.64",
"@types/mongodb": "^2.2.2",
"@types/chai": "^3.5.2"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/chai-as-promised": "^0.0.29",
"@types/mocha": "^2.2.39",
"@types/chai": "^3.5.2",
"@types/chai-as-promised": "^0.0.30",
"@types/mocha": "^2.2.41",
"@types/source-map-support": "^0.2.28",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"chai-as-promised": "^6.0.0",
"chalk": "^1.1.3",
"concurrently": "^2.1.0",
"coveralls": "^2.11.14",
"concurrently": "^3.4.0",
"coveralls": "^2.13.1",
"istanbul": "~0.4.5",
"mocha": "^3.2.0",
"remap-istanbul": "^0.7.0",
"source-map-support": "^0.4.2",
"tslint": "^4.1.0",
"typedoc": "~0.5.1",
"typescript": "~2.2.1"
"mocha": "^3.4.1",
"remap-istanbul": "^0.9.5",
"source-map-support": "^0.4.15",
"tslint": "^5.2.0",
"typedoc": "~0.7.0",
"typescript": "~2.3.2"
},

@@ -88,0 +88,0 @@ "keywords": [

@@ -301,3 +301,5 @@ # Iridium

```typescript
@Iridium.Validate('myValidator', x => x === 42)
@Iridium.Validate('myValidator', function(schema, data, path) {
return this.assert(data == 42)
})
export class InstanceType extends Iridium.Instance<any, InstanceType> {

@@ -385,2 +387,41 @@ @Iridium.Property('myValidator')

#### Transform Gotchas
It is important to note that property transforms are lazily evaluated on field access, rather than when the document is retrieved from the database.
This is done for performance reasons, but has the side effect that complex objects which are the targets of property transforms must be re-assigned to the field
if you wish to trigger the `toDB` transform function.
Let's take the following model definition for our example, here we have a GeoJSON representation of a location but we want our application to use the data
in a `{lat,lng}` style object. In this case we can use a transform which translates from one form to another to accomplish our task.
```typescript
import {inspect} from "util";
export class InstanceType extends Iridium.Instance<any, InstanceType> {
// Converts a GeoJSON object into a simple {lat, lng} object and back.
@Iridium.Transform(
data => { lat: data.coordinates[1], lng: data.coordinates[0] },
data => { type: "Point", coordinates: [data.lng, data.lat] }
)
position: {
lat: number;
lng: number;
};
}
db.Model.findOne().then(instance => {
console.log(util.inspect(instance.position)); // { lat: 1, lng: 2 }
console.log(util.inspect(instance.document.position)); // { type: "Point", coordinates: [2, 1] }
let pos = instance.pos;
pos.lat = 3;
console.log(util.inspect(pos)); // { lat: 3, lng: 2 }
console.log(util.inspect(instance.position)); // { lat: 1, lng: 2 }
console.log(util.inspect(instance.document.position)); // { type: "Point", coordinates: [2, 1] }
instance.position = pos
console.log(util.inspect(instance.position)); // { lat: 3, lng: 2 }
console.log(util.inspect(instance.document.position)); // { type: "Point", coordinates: [2, 3] }
});
```
#### Useful Transform Tricks

@@ -387,0 +428,0 @@ There are a couple of clever tricks you can do using transforms to enable additional functionality within Iridium. An example would be cleaning your documents of properties

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc