Skip to content

Commit bd554cf

Browse files
committed
add eslint and prettier
1 parent e8300ef commit bd554cf

12 files changed

+774
-109
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jest.config.js

.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
'@typescript-eslint/no-empty-interface': 'off',
24+
'@typescript-eslint/no-non-null-assertion': 'off',
25+
},
26+
};

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export * from './type-dorm.module';
22
export * from './type-dorm.decorator';
33
export * from './type-dorm.interface';
44
export * from './type-dorm.util';
5-
export * from './type-dorm.service';
5+
export * from './type-dorm.service';

lib/type-dorm.const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const TYPE_DORM_MODULE_NAME = 'default';
22
export const TYPE_DORM_MODULE_TOKEN = 'TypeDormModuleToken';
3-
export const TYPE_DORM_MODULE_OPTION_TOKEN = 'TypeDormModuleOptionToken';
3+
export const TYPE_DORM_MODULE_OPTION_TOKEN = 'TypeDormModuleOptionToken';

lib/type-dorm.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { getTypeDormConnectionToken } from './type-dorm.util';
33

44
export const InjectTypeDorm = (name?: string) => {
55
return Inject(getTypeDormConnectionToken(name));
6-
};
6+
};

lib/type-dorm.interface.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { ModuleMetadata, Type } from "@nestjs/common";
2-
import { ConnectionOptions } from "@typedorm/core";
1+
import { ModuleMetadata, Type } from '@nestjs/common';
2+
import { ConnectionOptions } from '@typedorm/core';
33

44
export interface TypeDormModuleOption extends ConnectionOptions {}
55

66
export interface TypeDormModuleOptionFactory {
7-
createTypeDormConnectionOptions(): Promise<ConnectionOptions> | ConnectionOptions;
7+
createTypeDormConnectionOptions():
8+
| Promise<ConnectionOptions>
9+
| ConnectionOptions;
810
}
911

10-
export interface TypeDormModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
12+
export interface TypeDormModuleAsyncOptions
13+
extends Pick<ModuleMetadata, 'imports'> {
1114
name?: string;
1215
inject?: any[];
1316
useClass?: Type<TypeDormModuleOptionFactory>;
1417
useExisting?: Type<TypeDormModuleOptionFactory>;
15-
useFactory?: (...args: any[]) => Promise<ConnectionOptions> | ConnectionOptions;
16-
}
18+
useFactory?: (
19+
...args: any[]
20+
) => Promise<ConnectionOptions> | ConnectionOptions;
21+
}

lib/type-dorm.module.spec.ts

Lines changed: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { Table } from '@typedorm/common';
3-
import {DocumentClientV3} from '@typedorm/document-client';
4-
import {DynamoDBClient} from '@aws-sdk/client-dynamodb';
3+
import { DocumentClientV3 } from '@typedorm/document-client';
4+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
55
import { TypeDormModule } from './type-dorm.module';
66
import { getTypeDormConnectionToken } from './type-dorm.util';
77
import { Connection, getEntityManager } from '@typedorm/core';
@@ -20,74 +20,83 @@ describe('TypeDormModule', () => {
2020
it('Instance typeDorm', async () => {
2121
const instanceName = 'dummy';
2222
const module: TestingModule = await Test.createTestingModule({
23-
imports: [TypeDormModule.forRoot({
24-
table,
25-
entities: [],
26-
documentClient: new DocumentClientV3(new DynamoDBClient({})),
27-
name: instanceName
28-
})],
23+
imports: [
24+
TypeDormModule.forRoot({
25+
table,
26+
entities: [],
27+
documentClient: new DocumentClientV3(new DynamoDBClient({})),
28+
name: instanceName,
29+
}),
30+
],
2931
}).compile();
3032

3133
const typeDormModule = module.get(TypeDormModule);
3234
expect(typeDormModule).toBeInstanceOf(TypeDormModule);
3335

34-
const typeDormConnection: Connection = module.get(getTypeDormConnectionToken(instanceName));
36+
const typeDormConnection: Connection = module.get(
37+
getTypeDormConnectionToken(instanceName),
38+
);
3539
expect(typeDormConnection).toBeInstanceOf(Connection);
3640

37-
const entityManager = getEntityManager(instanceName)
38-
expect(entityManager).toStrictEqual(typeDormConnection.entityManager)
41+
const entityManager = getEntityManager(instanceName);
42+
expect(entityManager).toStrictEqual(typeDormConnection.entityManager);
3943
});
4044

4145
it('inject redis connection', async () => {
42-
4346
@Injectable()
4447
class TestProvider {
45-
constructor(@InjectTypeDorm() private readonly connection: TypeDormConnection) {}
48+
constructor(
49+
@InjectTypeDorm() private readonly connection: TypeDormConnection,
50+
) {}
4651

4752
getConnection() {
4853
return this.connection;
4954
}
5055
}
5156

5257
const module: TestingModule = await Test.createTestingModule({
53-
imports: [TypeDormModule.forRoot({
54-
table,
55-
entities: [],
56-
documentClient: new DocumentClientV3(new DynamoDBClient({})),
57-
})],
58+
imports: [
59+
TypeDormModule.forRoot({
60+
table,
61+
entities: [],
62+
documentClient: new DocumentClientV3(new DynamoDBClient({})),
63+
}),
64+
],
5865
providers: [TestProvider],
5966
}).compile();
6067

61-
6268
const provider = module.get(TestProvider);
6369
expect(provider.getConnection()).toBeInstanceOf(Connection);
64-
6570
});
6671

6772
it('Instance async typeDorm', async () => {
6873
const instanceName = 'dummy2';
6974
const module: TestingModule = await Test.createTestingModule({
70-
imports: [TypeDormModule.forRootAsync({
71-
name: instanceName,
72-
useFactory: async () => {
73-
return {
74-
table,
75-
entities: [],
76-
documentClient: new DocumentClientV3(new DynamoDBClient({})),
77-
name: instanceName
78-
}
79-
},
80-
})],
75+
imports: [
76+
TypeDormModule.forRootAsync({
77+
name: instanceName,
78+
useFactory: async () => {
79+
return {
80+
table,
81+
entities: [],
82+
documentClient: new DocumentClientV3(new DynamoDBClient({})),
83+
name: instanceName,
84+
};
85+
},
86+
}),
87+
],
8188
}).compile();
8289

8390
const typeDormModule = module.get(TypeDormModule);
8491
expect(typeDormModule).toBeInstanceOf(TypeDormModule);
8592

86-
const typeDormConnection: Connection = module.get(getTypeDormConnectionToken(instanceName));
93+
const typeDormConnection: Connection = module.get(
94+
getTypeDormConnectionToken(instanceName),
95+
);
8796
expect(typeDormConnection).toBeInstanceOf(Connection);
8897

89-
const entityManager = getEntityManager(instanceName)
90-
expect(entityManager).toStrictEqual(typeDormConnection.entityManager)
98+
const entityManager = getEntityManager(instanceName);
99+
expect(entityManager).toStrictEqual(typeDormConnection.entityManager);
91100
});
92101

93102
it('Instance async typeDorm use class', async () => {
@@ -97,38 +106,44 @@ describe('TypeDormModule', () => {
97106
table,
98107
entities: [],
99108
documentClient: new DocumentClientV3(new DynamoDBClient({})),
100-
name: instanceName
101-
}
109+
name: instanceName,
110+
};
102111
}
103112
}
104113

105114
const instanceName = 'dummy3';
106115
const module: TestingModule = await Test.createTestingModule({
107-
imports: [TypeDormModule.forRootAsync({
108-
name: instanceName,
109-
useClass: Factory,
110-
})],
116+
imports: [
117+
TypeDormModule.forRootAsync({
118+
name: instanceName,
119+
useClass: Factory,
120+
}),
121+
],
111122
}).compile();
112123

113124
const typeDormModule = module.get(TypeDormModule);
114125
expect(typeDormModule).toBeInstanceOf(TypeDormModule);
115126

116-
const typeDormConnection: Connection = module.get(getTypeDormConnectionToken(instanceName));
127+
const typeDormConnection: Connection = module.get(
128+
getTypeDormConnectionToken(instanceName),
129+
);
117130
expect(typeDormConnection).toBeInstanceOf(Connection);
118131

119-
const entityManager = getEntityManager(instanceName)
120-
expect(entityManager).toStrictEqual(typeDormConnection.entityManager)
132+
const entityManager = getEntityManager(instanceName);
133+
expect(entityManager).toStrictEqual(typeDormConnection.entityManager);
121134
});
122135

123136
it('Instance typeDorm without injection', async () => {
124137
const instanceName = 'dummy5';
125138
const module: TestingModule = await Test.createTestingModule({
126-
imports: [TypeDormModule.forRootNonInjection({
127-
table,
128-
entities: [],
129-
documentClient: new DocumentClientV3(new DynamoDBClient({})),
130-
name: instanceName
131-
})],
139+
imports: [
140+
TypeDormModule.forRootNonInjection({
141+
table,
142+
entities: [],
143+
documentClient: new DocumentClientV3(new DynamoDBClient({})),
144+
name: instanceName,
145+
}),
146+
],
132147
}).compile();
133148

134149
const typeDormModule = module.get(TypeDormModule);
@@ -137,16 +152,22 @@ describe('TypeDormModule', () => {
137152
const typeDormConnection = module.get(TypeDormConnection);
138153
expect(typeDormConnection).toBeInstanceOf(Connection);
139154

140-
const entityManager = getEntityManager(instanceName)
141-
expect(entityManager).toStrictEqual(typeDormConnection.entityManager)
155+
const entityManager = getEntityManager(instanceName);
156+
expect(entityManager).toStrictEqual(typeDormConnection.entityManager);
142157
});
143158

144159
it('Throw error if pass invalid configuration', async () => {
145160
const instanceName = 'dummy6';
146-
expect(() => Test.createTestingModule({
147-
imports: [TypeDormModule.forRootAsync({
148-
name: instanceName,
149-
})],
150-
}).compile()).toThrow('Invalid configuration. Must provide useFactory, useClass or useExisting');
161+
expect(() =>
162+
Test.createTestingModule({
163+
imports: [
164+
TypeDormModule.forRootAsync({
165+
name: instanceName,
166+
}),
167+
],
168+
}).compile(),
169+
).toThrow(
170+
'Invalid configuration. Must provide useFactory, useClass or useExisting',
171+
);
151172
});
152-
});
173+
});

0 commit comments

Comments
 (0)