import { DEFAULT_WORKSPACE } from '../../constants' ; import { InstanceOptions , RequestTracingConfig } from '../../HttpClient' ; import { IOContext } from '../../service/worker/runtime/typings' ; import { InfraClient } from './InfraClient' ; const routes = { Account : ( account ) => `/${ account }` , Promote : ( account ) => `${ routes . Workspace ( account , DEFAULT_WORKSPACE ) }/_promote` , Workspace : ( account , workspace ) => `${ routes . Account ( account ) }/${ workspace }` , } ; export class Workspaces extends InfraClient { constructor ( context , options ? ) { super ( 'router' , context , options , true ) ; } public list = ( account , tracingConfig ? ) => { const metric = 'workspaces-list' ; return this . http . get < WorkspaceMetadata [ ] > ( routes . Account ( account ) , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public get = ( account , workspace , tracingConfig ? ) => { const metric = 'workspaces-get' ; return this . http . get < WorkspaceMetadata > ( routes . Workspace ( account , workspace ) , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public set = ( account , workspace , metadata , tracingConfig ? ) => { const metric = 'workspaces-set' ; return this . http . put ( routes . Workspace ( account , workspace ) , metadata , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public create = ( account , workspace , production , tracingConfig ? ) => { const metric = 'workspaces-create' ; return this . http . post ( routes . Account ( account ) , { name : workspace , production } , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public delete = ( account , workspace , tracingConfig ? ) => { const metric = 'workspaces-delete' ; return this . http . delete ( routes . Workspace ( account , workspace ) , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public reset = ( account , workspace , metadata = { } , tracingConfig ? ) => { const params = { reset : true } ; const metric = 'workspaces-reset' ; return this . http . put ( routes . Workspace ( account , workspace ) , metadata , { metric , params , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; public promote = ( account , workspace , tracingConfig ? ) => { const metric = 'workspaces-promote' ; return this . http . put ( routes . Promote ( account ) , { workspace } , { metric , tracing : { requestSpanNameSuffix : metric , ... tracingConfig ?. tracing , } } ) ; } ; } export interface WorkspaceMetadata { name : string ; weight : number ; production : boolean ; }