From 8c01e17f18671928b4719ecd52ec1e27a4ad70d5 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Thu, 18 May 2017 10:25:01 +0100 Subject: [PATCH] style: Tweak things to look like the rest of the Iridium codebase --- lib/Decorators.ts | 5 ++--- lib/Model.ts | 22 +++++++++++----------- test/MapReduce.ts | 23 ++++++++++++----------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/Decorators.ts b/lib/Decorators.ts index 8cf0d5b..766744f 100644 --- a/lib/Decorators.ts +++ b/lib/Decorators.ts @@ -7,7 +7,7 @@ import {Index, IndexSpecification} from "./Index"; import {Schema} from "./Schema"; import {InstanceImplementation} from "./InstanceInterface"; import {Transforms, DefaultTransforms} from "./Transforms"; -import * as MapReduceDef from './MapReduce'; +import * as MapReduceDef from "./MapReduce"; /** * Specifies the name of the collection to which this instance's documents should be sent. @@ -179,8 +179,7 @@ export function Binary(target: Instance, name: string) { * classes. If your transpiler does not support decorators then you are free to make use of the * property instead. */ -export function MapReduce(map: MapReduceDef.MapFunction, - reduce: MapReduceDef.ReduceFunction) { +export function MapReduce(map: MapReduceDef.MapFunction, reduce: MapReduceDef.ReduceFunction) { return function (target: InstanceImplementation) { target.mapReduceOptions = { map: map, reduce: reduce }; }; diff --git a/lib/Model.ts b/lib/Model.ts index 9889a21..c68fb21 100644 --- a/lib/Model.ts +++ b/lib/Model.ts @@ -716,27 +716,27 @@ export class Model { 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 } + 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 = , any> & { mapReduceOptions: MapReduceFunctions }>functions + let instanceType = , any> & { mapReduceOptions: MapReduceFunctions }>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 : {[op: string]: string} = {} - out[(options.out)] = instanceType.collection - opts.out = out + let opts = options; + let out : {[op: string]: string} = {}; + 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() - }) + if (err) return reject(err); + return resolve(); + }); }) } } diff --git a/test/MapReduce.ts b/test/MapReduce.ts index 8be565f..cbbf23d 100644 --- a/test/MapReduce.ts +++ b/test/MapReduce.ts @@ -36,11 +36,12 @@ class MapReducedInstance extends Iridium.Instance sum + val, 0) + return values.reduce((sum, val) => sum + val, 0); } } - _id: string - value: number + + _id: string; + value: number; } describe("Model", () => { @@ -64,7 +65,7 @@ describe("Model", () => { let reducedModel = new Iridium.Model, MapReducedInstance>(core, MapReducedInstance); let t = reducedModel.remove().then(() => model.mapReduce(MapReducedInstance, { out: "replace", query: { status: "A" } - }).then(() => reducedModel.find().toArray())) + }).then(() => reducedModel.find().toArray())); return chai.expect(t).to.eventually.exist.and.have.length(2); }); @@ -73,9 +74,9 @@ describe("Model", () => { map: function (this: TestDocument) { emit(this.cust_id, this.amount); }, reduce: function (k: string, v: number[]) { - return v.reduce((sum, val) => sum + val, 0) + return v.reduce((sum, val) => sum + val, 0); } - }, { query: { status: "A" } }) + }, { query: { status: "A" } }); return chai.expect(t).to.eventually.exist.and.have.length(2); }); @@ -84,17 +85,17 @@ describe("Model", () => { map: function (this: TestDocument) { emit(this.cust_id, this.amount); }, reduce: function (k: string, v: number[]) { - return v.reduce((sum, val) => sum + val, 0) + return v.reduce((sum, val) => sum + val, 0); } - }, { out: "replace", query: { status: "A" } }) - return chai.expect(t).to.eventually.be.rejected + }, { out: "replace", query: { status: "A" } }); + return chai.expect(t).to.eventually.be.rejected; }); it("should reject with wrong out option for model", () => { let t = model.mapReduce(MapReducedInstance, { out: "inline", query: { status: "A" } - }) - return chai.expect(t).to.eventually.be.rejected + }); + return chai.expect(t).to.eventually.be.rejected; }); }); }); \ No newline at end of file