Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit a8598d0

Browse files
committed
#115 + lint fixes
1 parent 9dd7a74 commit a8598d0

20 files changed

Lines changed: 85 additions & 61 deletions

index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ import 'colors';
22

33
export * from './src/boot';
44
export * from './src/core';
5-

spec/helpers/_.0.reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {DisplayProcessor, SpecReporter} from 'jasmine-spec-reporter';
2-
import 'source-map-support/register';
2+
import 'source-map-support';
33
import SuiteInfo = jasmine.SuiteInfo;
44

55
class CustomProcessor extends DisplayProcessor {

spec/helpers/sakuraapi.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import {json} from 'body-parser';
2+
import * as helmet from 'helmet';
13
import * as path from 'path';
24
import {SakuraApi, SakuraApiPlugin} from '../../src/core/sakura-api';
3-
import bodyParser = require('body-parser');
4-
import helmet = require('helmet');
55

66
const baseUri = '/testApi';
77

@@ -28,6 +28,7 @@ process.on('unhandledRejection', (r) => {
2828
console.log('-'.repeat(process.stdout.columns).red);
2929
// tslint:enable:no-console
3030

31+
throw r;
3132
});
3233

3334
export function testSapi(options: ITestSapiOptions): SakuraApi {
@@ -42,7 +43,7 @@ export function testSapi(options: ITestSapiOptions): SakuraApi {
4243
});
4344

4445
sapi.addMiddleware(helmet(), 0);
45-
sapi.addMiddleware(bodyParser.json(), 0);
46+
sapi.addMiddleware(json(), 0);
4647

4748
if (process.env.TRACE_REQ) {
4849
sapi.addMiddleware((req, res, next) => {

src/boot/sakura-api-config.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as path from 'path';
12
import {testMongoDbUrl, testSapi} from '../../spec/helpers/sakuraapi';
23
import {SakuraMongoDbConnection} from '../core/sakura-mongo-db-connection';
34
import {SakuraApiConfig} from './sakura-api-config';
4-
import path = require('path');
55

66
describe('sakura-api-config', () => {
77

src/core/@injectable/injectable.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
ProvidersMustBeDecoratedWithInjectableError
1414
} from './injectable';
1515

16+
/* tslint:disable:no-shadowed-variable */
17+
1618
describe('@Injectable', () => {
1719

1820
describe('Error handling', () => {
@@ -403,3 +405,5 @@ describe('@Injectable', () => {
403405
});
404406
});
405407
});
408+
409+
/* tslint:enable:no-shadowed-variable */

src/core/@injectable/sapi-injectable-mixin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import {SakuraApi} from '../sakura-api';
1212
*
1313
* See [[SapiModelMixin]] for more information.
1414
*/
15-
export function SapiInjectableMixin<T extends Constructor<{}>>(Base?: T) {
16-
Base = Base || class {
15+
export function SapiInjectableMixin<T extends Constructor<{}>>(base?: T) {
16+
base = base || class {
1717
} as any;
1818

19-
return class extends Base {
20-
constructor(...args: any[]) {
21-
super(...args);
22-
}
23-
19+
return class extends base {
2420
static sapi: SakuraApi;
2521
static sapiConfig: any;
2622

2723
sapi: SakuraApi;
2824
sapiConfig: any;
25+
26+
constructor(...args: any[]) {
27+
super(...args);
28+
}
2929
};
3030
}

src/core/@model/json.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,18 +781,18 @@ describe('@Json', () => {
781781
describe('id behavior', () => {
782782

783783
@Model()
784-
class User extends SapiModelMixin() {
784+
class User1 extends SapiModelMixin() {
785785
}
786786

787787
it('unmarshalls id as an ObjectID when it is a valid ObjectID', () => {
788788
const data = {
789789
id: new ObjectID().toString()
790790
};
791791

792-
const user = User.fromJson(data);
792+
const user = User1.fromJson(data);
793793

794-
expect(new User().id).toBeDefined('nope');
795-
expect(user instanceof User).toBeTruthy('Should have gotten back an instance of User');
794+
expect(new User1().id).toBeDefined('nope');
795+
expect(user instanceof User1).toBeTruthy('Should have gotten back an instance of User');
796796
expect(user.id instanceof ObjectID).toBeTruthy();
797797
expect(user._id instanceof ObjectID).toBeTruthy();
798798
});

src/core/@model/model.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ describe('core/@Model', () => {
8787
db: 'test'
8888
}
8989
})
90-
class TestDbConfig {
90+
class TestDbConfig1 {
9191
}
9292

9393
expect(() => {
94-
new TestDbConfig(); // tslint:disable-line
94+
new TestDbConfig1(); // tslint:disable-line
9595
}).toThrow();
9696
});
9797
});

src/core/@model/model.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,10 @@ function toDb(changeSet?: any): object {
10101010

10111011
if (shouldRecurse(source[key])) {
10121012

1013-
const newKey = keyMapper(key, source[key], dbOptionsByPropertyName);
1014-
if (newKey !== undefined) {
1013+
const aNewKey = keyMapper(key, source[key], dbOptionsByPropertyName);
1014+
if (aNewKey !== undefined) {
10151015
const value = mapModelToDb(source[key], ++depth);
1016-
result[newKey] = value;
1016+
result[aNewKey] = value;
10171017
}
10181018

10191019
continue;
@@ -1129,11 +1129,11 @@ function toJson(): any {
11291129
}
11301130

11311131
if (shouldRecurse(source[key])) {
1132-
const newKey = keyMapper(key, source[key], jsonFieldNamesByProperty);
1132+
const aNewKey = keyMapper(key, source[key], jsonFieldNamesByProperty);
11331133

1134-
if (newKey !== undefined) {
1134+
if (aNewKey !== undefined) {
11351135
const value = mapModelToJson(source[key]);
1136-
result[newKey] = value;
1136+
result[aNewKey] = value;
11371137
}
11381138

11391139
continue;

src/core/@model/sapi-model-mixin.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable:max-line-length
12
import {
23
Collection, CollectionInsertOneOptions, CollectionOptions, Cursor, Db, DeleteWriteOpResultObject,
34
InsertOneWriteOpResult, ObjectID, ReplaceOneOptions, UpdateWriteOpResult
@@ -44,17 +45,15 @@ import {IDbGetParams, IFromDbOptions} from './';
4445
*
4546
* Just remember to stick to the interface in case SakuraAPI is calling the method being overriden internally.
4647
*/
47-
export function SapiModelMixin<T extends Constructor<{}>>(Base?: T) {
48-
Base = Base || class {
48+
49+
export function SapiModelMixin<C extends Constructor<{}>>(base?: C) {
50+
base = base || class {
4951
} as any;
5052

51-
return class extends Base {
52-
constructor(...args: any[]) {
53-
super(...args);
54-
}
53+
return class extends base {
5554

5655
static fromDb: <T>(this: { new(): T }, json: any, options?: IFromDbOptions) => T;
57-
static fromJson: <T>(this: { new(...any): T }, json: object) => T;
56+
static fromJson: <T>(this: { new(...params): T }, json: object) => T;
5857
static fromJsonToDb: (json: any) => any;
5958

6059
static fromDbArray: <T>(this: { new(): T }, jsons: object[], options?: IFromDbOptions) => T[];
@@ -90,5 +89,12 @@ export function SapiModelMixin<T extends Constructor<{}>>(Base?: T) {
9089
toDb: (changeSet?: object) => any;
9190
toJson: (projection?: any) => any;
9291
toJsonString: (replacer?: () => any | Array<string | number>, space?: string | number) => string;
92+
93+
constructor(...args: any[]) {
94+
super(...args);
95+
}
96+
9397
};
9498
}
99+
100+
// tslint:enable:max-line-length

0 commit comments

Comments
 (0)