Skip to content

Commit 845e66c

Browse files
easyCZroboquat
authored andcommitted
Format components/gitpod-db with prettier
1 parent 2f0b946 commit 845e66c

File tree

162 files changed

+2824
-2126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+2824
-2126
lines changed

components/gitpod-db/src/accounting-db.spec.db.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
* See License.enterprise.txt in the project root folder.
55
*/
66

7-
import { Subscription } from '@gitpod/gitpod-protocol/lib/accounting-protocol';
8-
import * as chai from 'chai';
9-
import { suite, test, timeout } from 'mocha-typescript';
10-
import { QueryRunner } from 'typeorm';
11-
import { AccountingDB } from './accounting-db';
12-
import { oneMonthLater, rightAfter, rightBefore } from '@gitpod/gitpod-protocol/lib/util/timeutil';
13-
import { DBAccountEntry } from './typeorm/entity/db-account-entry';
14-
import { TransactionalAccountingDBImpl } from './typeorm/accounting-db-impl';
15-
import { DBWorkspace } from './typeorm/entity/db-workspace';
16-
import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
17-
import { DBSubscription } from './typeorm/entity/db-subscription';
18-
import { testContainer } from './test-container';
19-
import { TypeORM } from './typeorm/typeorm';
7+
import { Subscription } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
8+
import * as chai from "chai";
9+
import { suite, test, timeout } from "mocha-typescript";
10+
import { QueryRunner } from "typeorm";
11+
import { AccountingDB } from "./accounting-db";
12+
import { oneMonthLater, rightAfter, rightBefore } from "@gitpod/gitpod-protocol/lib/util/timeutil";
13+
import { DBAccountEntry } from "./typeorm/entity/db-account-entry";
14+
import { TransactionalAccountingDBImpl } from "./typeorm/accounting-db-impl";
15+
import { DBWorkspace } from "./typeorm/entity/db-workspace";
16+
import { DBWorkspaceInstance } from "./typeorm/entity/db-workspace-instance";
17+
import { DBSubscription } from "./typeorm/entity/db-subscription";
18+
import { testContainer } from "./test-container";
19+
import { TypeORM } from "./typeorm/typeorm";
2020
const expect = chai.expect;
2121

22-
@suite @timeout(5000)
22+
@suite
23+
@timeout(5000)
2324
export class AccountingDBSpec {
24-
2525
typeORM = testContainer.get<TypeORM>(TypeORM);
2626
db: AccountingDB;
2727
queryRunner: QueryRunner;
@@ -37,7 +37,7 @@ export class AccountingDBSpec {
3737
this.queryRunner = connection.createQueryRunner();
3838
await this.queryRunner.connect();
3939
await this.queryRunner.startTransaction();
40-
this.db = new TransactionalAccountingDBImpl(this.queryRunner.manager)
40+
this.db = new TransactionalAccountingDBImpl(this.queryRunner.manager);
4141
}
4242

4343
async after() {
@@ -54,7 +54,7 @@ export class AccountingDBSpec {
5454
startDate: now,
5555
endDate: later,
5656
amount: 1.01,
57-
planId: 'test'
57+
planId: "test",
5858
};
5959
await this.db.newSubscription(subscription);
6060

@@ -80,7 +80,7 @@ export class AccountingDBSpec {
8080
startDate: now,
8181
endDate: undefined, // open ended
8282
amount: 1.01,
83-
planId: 'test'
83+
planId: "test",
8484
};
8585
await this.db.newSubscription(subscription);
8686

@@ -104,43 +104,47 @@ export class AccountingDBSpec {
104104
startDate: now,
105105
endDate: undefined, // open ended
106106
amount: 1.01,
107-
planId: 'test'
107+
planId: "test",
108108
};
109109
const dbSubscription = await this.db.newSubscription(subscription);
110110
expectExactlyOne(await this.db.findActiveSubscriptions(now, rightAfter(later)), subscription);
111111
expect(await this.db.findActiveSubscriptions(rightBefore(now), rightBefore(now))).to.be.empty;
112112
Subscription.cancelSubscription(dbSubscription, later);
113-
await this.db.storeSubscription(dbSubscription)
113+
await this.db.storeSubscription(dbSubscription);
114114
expect(await this.db.findActiveSubscriptions(rightAfter(later), rightAfter(later))).to.be.empty;
115-
await this.db.storeSubscription(dbSubscription)
115+
await this.db.storeSubscription(dbSubscription);
116116
expect(await this.db.findActiveSubscriptions(rightAfter(later), rightAfter(later))).to.be.empty;
117117
}
118118

119119
@test public async subscriptionsForUser() {
120120
const now = new Date().toISOString();
121-
const later = oneMonthLater(now, 31)
121+
const later = oneMonthLater(now, 31);
122122
const subscription = <Subscription>{
123123
userId: "Open ended",
124124
startDate: now,
125125
endDate: undefined, // open ended
126126
amount: 1.01,
127-
planId: 'test'
127+
planId: "test",
128128
};
129129
let dbSubscription = await this.db.newSubscription(subscription);
130130
expectExactlyOne(await this.db.findActiveSubscriptionsForUser(subscription.userId, now), subscription);
131-
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(now))).to.be.an('array').and.empty;
131+
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(now))).to.be.an("array")
132+
.and.empty;
132133
expectExactlyOne(await this.db.findActiveSubscriptionsForUser(subscription.userId, later), subscription);
133134
Subscription.cancelSubscription(dbSubscription, later);
134135
await this.db.storeSubscription(dbSubscription);
135136

136-
expectExactlyOne(await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(later)), dbSubscription);
137-
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, later)).to.be.an('array').and.empty;
137+
expectExactlyOne(
138+
await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(later)),
139+
dbSubscription,
140+
);
141+
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, later)).to.be.an("array").and.empty;
138142
}
139143
}
140144

141145
const expectExactlyOne = <T>(result: T[], expectation: T) => {
142146
expect(result.length).to.be.equal(1);
143147
expect(result[0]).to.deep.include(expectation);
144-
}
148+
};
145149

146-
module.exports = new AccountingDBSpec
150+
module.exports = new AccountingDBSpec();

components/gitpod-db/src/accounting-db.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,38 @@
44
* See License.enterprise.txt in the project root folder.
55
*/
66

7-
import { AccountEntry, Subscription, SubscriptionAndUser, Credit } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
7+
import {
8+
AccountEntry,
9+
Subscription,
10+
SubscriptionAndUser,
11+
Credit,
12+
} from "@gitpod/gitpod-protocol/lib/accounting-protocol";
813
import { DBSubscriptionAdditionalData } from "./typeorm/entity/db-subscription";
914
import { EntityManager } from "typeorm";
1015

11-
export const TransactionalAccountingDBFactory = Symbol('TransactionalAccountingDBFactory');
16+
export const TransactionalAccountingDBFactory = Symbol("TransactionalAccountingDBFactory");
1217
export interface TransactionalAccountingDBFactory {
1318
(manager: EntityManager): AccountingDB;
1419
}
1520

16-
export const AccountingDB = Symbol('AccountingDB');
21+
export const AccountingDB = Symbol("AccountingDB");
1722

1823
export interface AccountingDB {
19-
newAccountEntry(entry: Omit<AccountEntry, 'uid'>): Promise<AccountEntry>;
24+
newAccountEntry(entry: Omit<AccountEntry, "uid">): Promise<AccountEntry>;
2025
storeAccountEntry(AccountEntry: AccountEntry): void;
2126
findAccountEntriesFor(userId: string, fromDate: string, toDate: string): Promise<AccountEntry[]>;
2227
findOpenCredits(userId: string, date: string): Promise<Credit[]>;
2328

24-
newSubscription(subscription: Omit<Subscription, 'uid'>): Promise<Subscription>;
29+
newSubscription(subscription: Omit<Subscription, "uid">): Promise<Subscription>;
2530
storeSubscription(subscription: Subscription): Promise<Subscription>;
2631
findSubscriptionById(id: string): Promise<Subscription | undefined>;
27-
deleteSubscription(subscription: Subscription): Promise<void>
32+
deleteSubscription(subscription: Subscription): Promise<void>;
2833
findActiveSubscriptions(fromDate: string, toDate: string): Promise<Subscription[]>;
2934
findActiveSubscriptionsForUser(userId: string, fromDate: string): Promise<Subscription[]>;
30-
findActiveSubscriptionsByIdentity(authId: string[], authProvider: string): Promise<{ [authId:string]:SubscriptionAndUser[] }>;
35+
findActiveSubscriptionsByIdentity(
36+
authId: string[],
37+
authProvider: string,
38+
): Promise<{ [authId: string]: SubscriptionAndUser[] }>;
3139
findActiveSubscriptionByPlanID(planID: string, date: string): Promise<Subscription[]>;
3240
findAllSubscriptionsForUser(userId: string): Promise<Subscription[]>;
3341
findSubscriptionsForUserInPeriod(userId: string, fromDate: string, toDate: string): Promise<Subscription[]>;
@@ -38,7 +46,12 @@ export interface AccountingDB {
3846
hadSubscriptionCreatedWithCoupon(userId: string, coupon: string): Promise<boolean>;
3947
findSubscriptionAdditionalData(paymentReference: string): Promise<DBSubscriptionAdditionalData | undefined>;
4048

41-
transaction<T>(closure: (db: AccountingDB)=>Promise<T>, closures?: ((manager: EntityManager) => Promise<any>)[]): Promise<T>;
49+
transaction<T>(
50+
closure: (db: AccountingDB) => Promise<T>,
51+
closures?: ((manager: EntityManager) => Promise<any>)[],
52+
): Promise<T>;
4253

43-
storeSubscriptionAdditionalData(subscriptionData: DBSubscriptionAdditionalData): Promise<DBSubscriptionAdditionalData>;
54+
storeSubscriptionAdditionalData(
55+
subscriptionData: DBSubscriptionAdditionalData,
56+
): Promise<DBSubscriptionAdditionalData>;
4457
}

components/gitpod-db/src/app-installation-db.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66

77
import { AppInstallation, AppInstallationPlatform } from "@gitpod/gitpod-protocol";
88

9-
export const AppInstallationDB = Symbol('AppInstallationDB');
9+
export const AppInstallationDB = Symbol("AppInstallationDB");
1010

1111
export interface AppInstallationDB {
12-
13-
recordNewInstallation(platform: AppInstallationPlatform, source: 'user' | 'platform', installationID: string, ownerUserID?: string, platformUserID?: string): Promise<void>;
14-
recordUninstallation(platform: AppInstallationPlatform, source: 'user' | 'platform', installationID: string): Promise<void>;
12+
recordNewInstallation(
13+
platform: AppInstallationPlatform,
14+
source: "user" | "platform",
15+
installationID: string,
16+
ownerUserID?: string,
17+
platformUserID?: string,
18+
): Promise<void>;
19+
recordUninstallation(
20+
platform: AppInstallationPlatform,
21+
source: "user" | "platform",
22+
installationID: string,
23+
): Promise<void>;
1524

1625
findInstallation(platform: AppInstallationPlatform, installationID: string): Promise<AppInstallation | undefined>;
17-
18-
}
26+
}

components/gitpod-db/src/auth-provider-entry-db.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { AuthProviderEntry as AuthProviderEntry } from "@gitpod/gitpod-protocol";
88
import { createHash } from "crypto";
99

10-
export const AuthProviderEntryDB = Symbol('AuthProviderEntryDB');
10+
export const AuthProviderEntryDB = Symbol("AuthProviderEntryDB");
1111

1212
export interface AuthProviderEntryDB {
1313
storeAuthProvider(ap: AuthProviderEntry, updateOAuthRevision: boolean): Promise<AuthProviderEntry>;
@@ -21,5 +21,5 @@ export interface AuthProviderEntryDB {
2121
}
2222

2323
export function hashOAuth(oauth: AuthProviderEntry["oauth"]): string {
24-
return createHash('sha256').update(JSON.stringify(oauth)).digest('hex');
25-
}
24+
return createHash("sha256").update(JSON.stringify(oauth)).digest("hex");
25+
}

components/gitpod-db/src/auth-provider-entry.spec.db.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
* See License.enterprise.txt in the project root folder.
55
*/
66

7-
import * as chai from 'chai';
8-
import { suite, test, timeout } from 'mocha-typescript';
9-
import { testContainer } from './test-container';
10-
import { TypeORM } from './typeorm/typeorm';
11-
import { AuthProviderEntryDB } from '.';
12-
import { DBAuthProviderEntry } from './typeorm/entity/db-auth-provider-entry';
13-
import { DeepPartial } from '@gitpod/gitpod-protocol/lib/util/deep-partial';
7+
import * as chai from "chai";
8+
import { suite, test, timeout } from "mocha-typescript";
9+
import { testContainer } from "./test-container";
10+
import { TypeORM } from "./typeorm/typeorm";
11+
import { AuthProviderEntryDB } from ".";
12+
import { DBAuthProviderEntry } from "./typeorm/entity/db-auth-provider-entry";
13+
import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";
1414
const expect = chai.expect;
1515

16-
@suite @timeout(5000)
16+
@suite
17+
@timeout(5000)
1718
export class AuthProviderEntryDBSpec {
18-
1919
typeORM = testContainer.get<TypeORM>(TypeORM);
2020
db = testContainer.get<AuthProviderEntryDB>(AuthProviderEntryDB);
2121

@@ -40,7 +40,7 @@ export class AuthProviderEntryDBSpec {
4040
id: "0049b9d2-005f-43c2-a0ae-76377805d8b8",
4141
host,
4242
ownerId,
43-
status: 'verified',
43+
status: "verified",
4444
type: "GitHub",
4545
oauthRevision: undefined,
4646
deleted: false,
@@ -87,8 +87,10 @@ export class AuthProviderEntryDBSpec {
8787

8888
const loadedAp = await this.db.findByHost(ap.host);
8989
expect(loadedAp, "findByHost()").to.deep.equal(ap);
90-
expect(loadedAp?.oauthRevision, "findByHost()").to.equal("e05ea6fab8efcaba4b3246c2b2d3931af897c3bc2c1cf075c31614f0954f9840");
90+
expect(loadedAp?.oauthRevision, "findByHost()").to.equal(
91+
"e05ea6fab8efcaba4b3246c2b2d3931af897c3bc2c1cf075c31614f0954f9840",
92+
);
9193
}
9294
}
9395

94-
module.exports = AuthProviderEntryDBSpec
96+
module.exports = AuthProviderEntryDBSpec;

components/gitpod-db/src/config.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { injectable } from 'inversify';
8-
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
9-
import { getEnvVarParsed, getEnvVar } from '@gitpod/gitpod-protocol/lib/env';
10-
import { ConnectionConfig } from 'mysql';
7+
import { injectable } from "inversify";
8+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
9+
import { getEnvVarParsed, getEnvVar } from "@gitpod/gitpod-protocol/lib/env";
10+
import { ConnectionConfig } from "mysql";
1111

1212
@injectable()
1313
export class Config {
1414
get dbConfig(): DatabaseConfig {
1515
// defaults to be used only in tests
1616
const dbSetup = {
17-
host: process.env.DB_HOST || 'localhost',
18-
port: getEnvVarParsed('DB_PORT', Number.parseInt, '3306'),
19-
username: process.env.DB_USERNAME || 'gitpod',
20-
password: process.env.DB_PASSWORD || 'test',
21-
database: process.env.DB_NAME || 'gitpod'
17+
host: process.env.DB_HOST || "localhost",
18+
port: getEnvVarParsed("DB_PORT", Number.parseInt, "3306"),
19+
username: process.env.DB_USERNAME || "gitpod",
20+
password: process.env.DB_PASSWORD || "test",
21+
database: process.env.DB_NAME || "gitpod",
2222
};
2323

2424
log.info(`Using DB: ${dbSetup.host}:${dbSetup.port}/${dbSetup.database}`);
@@ -33,17 +33,17 @@ export class Config {
3333
port: dbConfig.port,
3434
user: dbConfig.username,
3535
password: dbConfig.password,
36-
database: dbConfig.database
36+
database: dbConfig.database,
3737
};
3838
}
3939

4040
get dbEncryptionKeys(): string {
41-
return getEnvVar('DB_ENCRYPTION_KEYS');
41+
return getEnvVar("DB_ENCRYPTION_KEYS");
4242
}
4343

4444
get deletedEntryGCConfig(): DeletedEntryGCConfig {
45-
const enabled = getEnvVar('DB_DELETED_ENTRIES_GC_ENABLED', 'true') === 'true';
46-
const intervalMS = parseInt(getEnvVar('DB_DELETED_ENTRIES_GC_INTERVAL', (10 * 60 * 1000).toString()));
45+
const enabled = getEnvVar("DB_DELETED_ENTRIES_GC_ENABLED", "true") === "true";
46+
const intervalMS = parseInt(getEnvVar("DB_DELETED_ENTRIES_GC_INTERVAL", (10 * 60 * 1000).toString()));
4747
return { enabled, intervalMS };
4848
}
4949
}
@@ -59,4 +59,4 @@ export interface DatabaseConfig {
5959
export interface DeletedEntryGCConfig {
6060
enabled: boolean;
6161
intervalMS: number;
62-
}
62+
}

0 commit comments

Comments
 (0)