/** * 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 } from '@gitpod/gitpod-protocol'; export type MaybeWorkspace = Workspace | undefined; export type MaybeWorkspaceInstance = WorkspaceInstance | undefined; export interface FindWorkspacesOptions { userId: string projectId?: string limit?: number searchString?: string includeHeadless?: boolean pinnedOnly?: boolean } export interface PrebuiltUpdatableAndWorkspace extends PrebuiltWorkspaceUpdatable { prebuild: PrebuiltWorkspace workspace: Workspace instance: WorkspaceInstance } export type WorkspaceAuthData = Pick; export type WorkspaceInstancePortsAuthData = Pick; export interface WorkspacePortsAuthData { instance: WorkspaceInstancePortsAuthData; workspace: WorkspaceAuthData; } export type WorkspaceInstanceSession = Pick; export type WorkspaceSessionData = Pick; export interface WorkspaceInstanceSessionWithWorkspace { instance: WorkspaceInstanceSession; workspace: WorkspaceSessionData; } export interface PrebuildWithWorkspace { prebuild: PrebuiltWorkspace; workspace: Workspace; } export type WorkspaceAndOwner = Pick; export type WorkspaceOwnerAndSoftDeleted = Pick; export const WorkspaceDB = Symbol('WorkspaceDB'); export interface WorkspaceDB { connect(maxTries: number, timeout: number): Promise; transaction(code: (db: WorkspaceDB) => Promise): Promise; store(workspace: Workspace): Promise; updatePartial(workspaceId: string, partial: DeepPartial): Promise; findById(id: string): Promise; findByInstanceId(id: string): Promise; find(options: FindWorkspacesOptions): Promise; findWorkspacePortsAuthDataById(workspaceId: string): Promise; storeInstance(instance: WorkspaceInstance): Promise; // Partial update: unconditional, single field updates. Enclose in a transaction if necessary updateLastHeartbeat(instanceId: string, userId: string, newHeartbeat: Date, wasClosed?: boolean): Promise; getLastOwnerHeartbeatFor(instance: WorkspaceInstance): Promise<{ lastSeen:Date, wasClosed?: boolean} | undefined>; getWorkspaceUsers(workspaceId: string, minLastSeen: number): Promise; updateInstancePartial(instanceId: string, partial: DeepPartial): Promise; findInstanceById(workspaceInstanceId: string): Promise; findInstances(workspaceId: string): Promise; findWorkspacesByUser(userId: string): Promise; findCurrentInstance(workspaceId: string): Promise; findRunningInstance(workspaceId: string): Promise; findSessionsInPeriod(userId: string, periodStart: string, periodEnd: string): Promise; findWorkspacesForGarbageCollection(minAgeInDays: number, limit: number): Promise; findWorkspacesForContentDeletion(minSoftDeletedTimeInDays: number, limit: number): Promise; findPrebuiltWorkspacesForGC(daysUnused: number, limit: number): Promise; 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", ownerId?: string, searchTerm?: string): Promise<{ total: number, rows: WorkspaceAndInstance[] }>; findWorkspaceAndInstance(id: string): Promise; 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; findRunningInstancesWithWorkspaces(installation?: string, userId?: string, includeStopping?: boolean): Promise; isWhitelisted(repositoryUrl : string): Promise; getFeaturedRepositories(): Promise[]>; findSnapshotById(snapshotId: string): Promise; findSnapshotsByWorkspaceId(workspaceId: string): Promise; storeSnapshot(snapshot: Snapshot): Promise; getTotalPrebuildUseSeconds(forDays: number): Promise; storePrebuiltWorkspace(pws: PrebuiltWorkspace): Promise; findPrebuiltWorkspaceByCommit(cloneURL: string, commit: string): Promise; findPrebuildsWithWorkpace(cloneURL: string): Promise; findPrebuildByWorkspaceID(wsid: string): Promise; findPrebuildByID(pwsid: string): Promise; countRunningPrebuilds(cloneURL: string): Promise; findQueuedPrebuilds(cloneURL?: string): Promise; attachUpdatableToPrebuild(pwsid: string, update: PrebuiltWorkspaceUpdatable): Promise; findUpdatablesForPrebuild(pwsid: string): Promise; markUpdatableResolved(updatableId: string): Promise; getUnresolvedUpdatables(): Promise; findLayoutDataByWorkspaceId(workspaceId: string): Promise; storeLayoutData(layoutData: LayoutData): Promise; hardDeleteWorkspace(workspaceID: string): Promise; findPrebuiltWorkspacesByProject(projectId: string, branch?: string, limit?: number): Promise; findPrebuiltWorkspaceById(prebuildId: string): Promise; storePrebuildInfo(prebuildInfo: PrebuildInfo): Promise; findPrebuildInfos(prebuildIds: string[]): Promise; }