-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathworkspace-db.ts
128 lines (102 loc) · 7.29 KB
/
workspace-db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/
import { DeepPartial } from 'typeorm';
import { Workspace, WorkspaceInfo, WorkspaceInstance, WorkspaceInstanceUser, WhitelistedRepository, Snapshot, LayoutData, PrebuiltWorkspace, PrebuiltWorkspaceUpdatable, RunningWorkspaceInfo, WorkspaceAndInstance, WorkspaceType, PrebuildInfo, AdminGetWorkspacesQuery, SnapshotState } from '@gitpod/gitpod-protocol';
export type MaybeWorkspace = Workspace | undefined;
export type MaybeWorkspaceInstance = WorkspaceInstance | undefined;
export interface FindWorkspacesOptions {
userId: string
projectId?: string | string[]
includeWithoutProject?: boolean;
limit?: number
searchString?: string
includeHeadless?: boolean
pinnedOnly?: boolean
}
export interface PrebuiltUpdatableAndWorkspace extends PrebuiltWorkspaceUpdatable {
prebuild: PrebuiltWorkspace
workspace: Workspace
instance: WorkspaceInstance
}
export type WorkspaceAuthData = Pick<Workspace, "id" | "ownerId" | "shareable">;
export type WorkspaceInstancePortsAuthData = Pick<WorkspaceInstance, "id" | "region">;
export interface WorkspacePortsAuthData {
instance: WorkspaceInstancePortsAuthData;
workspace: WorkspaceAuthData;
}
export type WorkspaceInstanceSession = Pick<WorkspaceInstance, "id" | "startedTime" | "stoppingTime" | "stoppedTime">;
export type WorkspaceSessionData = Pick<Workspace, "id" | "contextURL" | "context" | "type">;
export interface WorkspaceInstanceSessionWithWorkspace {
instance: WorkspaceInstanceSession;
workspace: WorkspaceSessionData;
}
export interface PrebuildWithWorkspace {
prebuild: PrebuiltWorkspace;
workspace: Workspace;
}
export type WorkspaceAndOwner = Pick<Workspace, "id" | "ownerId">;
export type WorkspaceOwnerAndSoftDeleted = Pick<Workspace, "id" | "ownerId" | "softDeleted">;
export const WorkspaceDB = Symbol('WorkspaceDB');
export interface WorkspaceDB {
connect(maxTries: number, timeout: number): Promise<void>;
transaction<T>(code: (db: WorkspaceDB) => Promise<T>): Promise<T>;
store(workspace: Workspace): Promise<Workspace>;
updatePartial(workspaceId: string, partial: DeepPartial<Workspace>): Promise<void>;
findById(id: string): Promise<MaybeWorkspace>;
findByInstanceId(id: string): Promise<MaybeWorkspace>;
find(options: FindWorkspacesOptions): Promise<WorkspaceInfo[]>;
findWorkspacePortsAuthDataById(workspaceId: string): Promise<WorkspacePortsAuthData | undefined>;
storeInstance(instance: WorkspaceInstance): Promise<WorkspaceInstance>;
// Partial update: unconditional, single field updates. Enclose in a transaction if necessary
updateLastHeartbeat(instanceId: string, userId: string, newHeartbeat: Date, wasClosed?: boolean): Promise<void>;
getLastOwnerHeartbeatFor(instance: WorkspaceInstance): Promise<{ lastSeen: Date, wasClosed?: boolean } | undefined>;
getWorkspaceUsers(workspaceId: string, minLastSeen: number): Promise<WorkspaceInstanceUser[]>;
updateInstancePartial(instanceId: string, partial: DeepPartial<WorkspaceInstance>): Promise<WorkspaceInstance>;
findInstanceById(workspaceInstanceId: string): Promise<MaybeWorkspaceInstance>;
findInstances(workspaceId: string): Promise<WorkspaceInstance[]>;
findWorkspacesByUser(userId: string): Promise<Workspace[]>;
findCurrentInstance(workspaceId: string): Promise<MaybeWorkspaceInstance>;
findRunningInstance(workspaceId: string): Promise<MaybeWorkspaceInstance>;
findSessionsInPeriod(userId: string, periodStart: string, periodEnd: string): Promise<WorkspaceInstanceSessionWithWorkspace[]>;
findWorkspacesForGarbageCollection(minAgeInDays: number, limit: number): Promise<WorkspaceAndOwner[]>;
findWorkspacesForContentDeletion(minSoftDeletedTimeInDays: number, limit: number): Promise<WorkspaceOwnerAndSoftDeleted[]>;
findPrebuiltWorkspacesForGC(daysUnused: number, limit: number): Promise<WorkspaceAndOwner[]>;
findAllWorkspaces(offset: number, limit: number, orderBy: keyof Workspace, orderDir: "ASC" | "DESC", ownerId?: string, searchTerm?: string, minCreationTime?: Date, maxCreationDateTime?: Date, type?: WorkspaceType): Promise<{ total: number, rows: Workspace[] }>;
findAllWorkspaceAndInstances(offset: number, limit: number, orderBy: keyof WorkspaceAndInstance, orderDir: "ASC" | "DESC", query?: AdminGetWorkspacesQuery): Promise<{ total: number, rows: WorkspaceAndInstance[] }>;
findWorkspaceAndInstance(id: string): Promise<WorkspaceAndInstance | undefined>;
findInstancesByPhaseAndRegion(phase: string, region: string): Promise<WorkspaceInstance[]>;
getWorkspaceCount(type?: String): Promise<Number>;
getInstanceCount(type?: string): Promise<number>
findAllWorkspaceInstances(offset: number, limit: number, orderBy: keyof WorkspaceInstance, orderDir: "ASC" | "DESC", ownerId?: string, minCreationTime?: Date, maxCreationTime?: Date, onlyRunning?: boolean, type?: WorkspaceType): Promise<{ total: number, rows: WorkspaceInstance[] }>;
findRegularRunningInstances(userId?: string): Promise<WorkspaceInstance[]>;
findRunningInstancesWithWorkspaces(installation?: string, userId?: string, includeStopping?: boolean): Promise<RunningWorkspaceInfo[]>;
isWhitelisted(repositoryUrl: string): Promise<boolean>;
getFeaturedRepositories(): Promise<Partial<WhitelistedRepository>[]>;
findSnapshotById(snapshotId: string): Promise<Snapshot | undefined>;
findSnapshotsWithState(state: SnapshotState, offset: number, limit: number): Promise<{ snapshots: Snapshot[], total: number }>;
findSnapshotsByWorkspaceId(workspaceId: string): Promise<Snapshot[]>;
storeSnapshot(snapshot: Snapshot): Promise<Snapshot>;
deleteSnapshot(snapshotId: string): Promise<void>;
updateSnapshot(snapshot: DeepPartial<Snapshot> & Pick<Snapshot, 'id'>): Promise<void>;
storePrebuiltWorkspace(pws: PrebuiltWorkspace): Promise<PrebuiltWorkspace>;
findPrebuiltWorkspaceByCommit(cloneURL: string, commit: string): Promise<PrebuiltWorkspace | undefined>;
findPrebuildsWithWorkpace(cloneURL: string): Promise<PrebuildWithWorkspace[]>;
findPrebuildByWorkspaceID(wsid: string): Promise<PrebuiltWorkspace | undefined>;
findPrebuildByID(pwsid: string): Promise<PrebuiltWorkspace | undefined>;
countRunningPrebuilds(cloneURL: string): Promise<number>;
findQueuedPrebuilds(cloneURL?: string): Promise<PrebuildWithWorkspace[]>;
attachUpdatableToPrebuild(pwsid: string, update: PrebuiltWorkspaceUpdatable): Promise<void>;
findUpdatablesForPrebuild(pwsid: string): Promise<PrebuiltWorkspaceUpdatable[]>;
markUpdatableResolved(updatableId: string): Promise<void>;
getUnresolvedUpdatables(): Promise<PrebuiltUpdatableAndWorkspace[]>;
findLayoutDataByWorkspaceId(workspaceId: string): Promise<LayoutData | undefined>;
storeLayoutData(layoutData: LayoutData): Promise<LayoutData>;
hardDeleteWorkspace(workspaceID: string): Promise<void>;
findPrebuiltWorkspacesByProject(projectId: string, branch?: string, limit?: number): Promise<PrebuiltWorkspace[]>;
findPrebuiltWorkspaceById(prebuildId: string): Promise<PrebuiltWorkspace | undefined>;
storePrebuildInfo(prebuildInfo: PrebuildInfo): Promise<void>;
findPrebuildInfos(prebuildIds: string[]): Promise<PrebuildInfo[]>;
}