Skip to content

decouple gitpod-protocol from public-api #19151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist/
components/*/lib/
components/ee/*/lib/
components/*/typescript/lib/
components/*/typescript-*/lib/
components/local-app-api/*/lib/
components/supervisor/frontend/lib/
src-gen/
Expand Down
1 change: 1 addition & 0 deletions components/dashboard/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ packages:
deps:
- components/gitpod-protocol:lib
- components/public-api/typescript:lib
- components/public-api/typescript-common:lib
config:
commands:
build:
Expand Down
1 change: 1 addition & 0 deletions components/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@connectrpc/connect-web": "1.1.2",
"@gitpod/gitpod-protocol": "0.1.5",
"@gitpod/public-api": "0.1.5",
"@gitpod/public-api-common": "0.1.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getGitpodService } from "./service";
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";
import { generateAsyncGenerator } from "@gitpod/gitpod-protocol/lib/generate-async-generator";
import { WorkspaceInstance } from "@gitpod/gitpod-protocol";
import { parsePagination } from "@gitpod/gitpod-protocol/lib/public-api-pagination";
import { parsePagination } from "@gitpod/public-api-common/lib/public-api-pagination";
import { validate as uuidValidate } from "uuid";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";

Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/src/service/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { MetricsReporter } from "@gitpod/public-api/lib/metrics";
import { MetricsReporter } from "@gitpod/gitpod-protocol/lib/metrics";
import { getExperimentsClient } from "../experiments/client";
import { v4 } from "uuid";
const commit = require("./config.json").commit;
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/src/service/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MethodKind, ServiceType } from "@bufbuild/protobuf";
import { CallOptions, Code, ConnectError, PromiseClient, createPromiseClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { Disposable, User } from "@gitpod/gitpod-protocol";
import { PublicAPIConverter } from "@gitpod/gitpod-protocol/lib/public-api-converter";
import { PublicAPIConverter } from "@gitpod/public-api-common/lib/public-api-converter";
import { Project as ProtocolProject } from "@gitpod/gitpod-protocol/lib/teams-projects-protocol";
import { HelloService } from "@gitpod/public-api/lib/gitpod/experimental/v1/dummy_connect";
import { OIDCService } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_connect";
Expand All @@ -21,7 +21,7 @@ import { OrganizationService } from "@gitpod/public-api/lib/gitpod/v1/organizati
import { WorkspaceService } from "@gitpod/public-api/lib/gitpod/v1/workspace_connect";
import { ConfigurationService } from "@gitpod/public-api/lib/gitpod/v1/configuration_connect";
import { PrebuildService } from "@gitpod/public-api/lib/gitpod/v1/prebuild_connect";
import { getMetricsInterceptor } from "@gitpod/public-api/lib/metrics";
import { getMetricsInterceptor } from "@gitpod/gitpod-protocol/lib/metrics";
import { getExperimentsClient } from "../experiments/client";
import { JsonRpcOrganizationClient } from "./json-rpc-organization-client";
import { JsonRpcWorkspaceClient } from "./json-rpc-workspace-client";
Expand Down
3 changes: 2 additions & 1 deletion components/dashboard/src/user-settings/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* See License.AGPL.txt in the project root for license information.
*/

import { User, getScopesForAuthProviderType } from "@gitpod/gitpod-protocol";
import { User } from "@gitpod/gitpod-protocol";
import { getScopesForAuthProviderType } from "@gitpod/public-api-common/lib/auth-providers";
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
import { useQuery } from "@tanstack/react-query";
import React, { useCallback, useContext, useEffect, useMemo, useState } from "react";
Expand Down
2 changes: 0 additions & 2 deletions components/gitpod-protocol/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ packages:
- .eslintrc
- mocha.opts
- package.json
deps:
- components/public-api/typescript:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"exit": true
},
"dependencies": {
"@bufbuild/protobuf": "^1.3.3",
"@connectrpc/connect": "1.1.2",
"@gitpod/public-api": "0.1.5",
"@types/react": "17.0.32",
"abort-controller-x": "^0.4.0",
"ajv": "^6.5.4",
Expand Down
1 change: 0 additions & 1 deletion components/gitpod-protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ export * from "./teams-projects-protocol";
export * from "./snapshot-url";
export * from "./webhook-event";
export * from "./redis";
export * from "./auth-providers";
25 changes: 0 additions & 25 deletions components/gitpod-protocol/src/messaging/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
*/

import { scrubber } from "../util/scrubbing";
import { PlainMessage } from "@bufbuild/protobuf";
import {
InvalidGitpodYMLError as InvalidGitpodYMLErrorData,
RepositoryNotFoundError as RepositoryNotFoundErrorData,
RepositoryUnauthorizedError as RepositoryUnauthorizedErrorData,
} from "@gitpod/public-api/lib/gitpod/v1/error_pb";

export class ApplicationError extends Error {
constructor(readonly code: ErrorCode, readonly message: string, readonly data?: any) {
Expand All @@ -27,25 +21,6 @@ export class ApplicationError extends Error {
}
}

export class RepositoryNotFoundError extends ApplicationError {
constructor(readonly info: PlainMessage<RepositoryNotFoundErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.NOT_FOUND, "Repository not found.", info);
}
}
export class UnauthorizedRepositoryAccessError extends ApplicationError {
constructor(readonly info: PlainMessage<RepositoryUnauthorizedErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.NOT_AUTHENTICATED, "Repository unauthorized.", info);
}
}
export class InvalidGitpodYMLError extends ApplicationError {
constructor(readonly info: PlainMessage<InvalidGitpodYMLErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.INVALID_GITPOD_YML, "Invalid gitpod.yml: " + info.violations.join(","), info);
}
}

export namespace ApplicationError {
export function hasErrorCode(e: any): e is Error & { code: ErrorCode; data?: any } {
return ErrorCode.is(e["code"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export class MetricsReporter {
while (this.pendingRequests.length) {
const request = this.pendingRequests.shift();
if (request) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.send(request);
}
}
Expand Down Expand Up @@ -393,6 +394,7 @@ export class MetricsReporter {
[key: string]: string | undefined;
},
): void {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.asyncReportError(error, data);
}

Expand Down
17 changes: 17 additions & 0 deletions components/public-api/typescript-common/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
packages:
- name: lib
type: yarn
srcs:
- src/**
- package.json
- tsconfig.json
deps:
- components/gitpod-protocol:lib
- components/public-api/typescript:lib
config:
packaging: library
commands:
# leeway executes the build and test step in the wrong order, so we need to call a special script that builds before testing
test: ["yarn", "test:leeway"]
yarnLock: ${coreYarnLockBase}/../yarn.lock
tsconfig: tsconfig.json
36 changes: 36 additions & 0 deletions components/public-api/typescript-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@gitpod/public-api-common",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosyakov Personally I would love to see a README.md next to this file, which explains the "WHY does this package exist, how it compares to gitpod-protocol, and "which package to choose for what"".

Can be a follow-up 👍

"version": "0.1.5",
"license": "AGPL-3.0",
"files": [
"lib"
],
"exports": {
"./lib/*": {
"types": "./lib/*.d.ts",
"import": "./lib/esm/*.js",
"require": "./lib/*.js"
}
},
"scripts": {
"build": "yarn run build:cjs && yarn run build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module es2015 --outDir ./lib/esm",
"test": "mocha './**/*.spec.js' --exclude './node_modules/**' --exclude './lib/esm/**' --exit",
"test:leeway": "yarn build && yarn test"
},
"dependencies": {
"@gitpod/gitpod-protocol": "0.1.5",
"@gitpod/public-api": "0.1.5",
"@connectrpc/connect": "1.1.2",
"@bufbuild/protobuf": "^1.3.3"
},
"devDependencies": {
"@types/chai-subset": "^1.3.3",
"@types/mocha": "^10.0.1",
"@types/node": "^16.11.6",
"chai": "^4.3.4",
"mocha": "^10.2.0",
"typescript": "~4.4.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
import { expect } from "chai";
import { PartialConfiguration, PublicAPIConverter } from "./public-api-converter";
import { OrgMemberInfo, Project, PrebuildSettings as PrebuildSettingsProtocol } from "./teams-projects-protocol";
import {
OrgMemberInfo,
Project,
PrebuildSettings as PrebuildSettingsProtocol,
} from "@gitpod/gitpod-protocol/lib/teams-projects-protocol";
import { OrganizationRole } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
import {
BranchMatchingStrategy,
Expand All @@ -31,7 +35,7 @@ import {
UserEnvVarValue,
UserSSHPublicKey,
WithEnvvarsContext,
} from "./protocol";
} from "@gitpod/gitpod-protocol/lib/protocol";
import {
AuthProvider,
AuthProviderDescription,
Expand All @@ -42,13 +46,8 @@ import {
EnvironmentVariableAdmission,
UserEnvironmentVariable,
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb";
import {
ApplicationError,
ErrorCodes,
InvalidGitpodYMLError,
RepositoryNotFoundError,
UnauthorizedRepositoryAccessError,
} from "./messaging/error";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { InvalidGitpodYMLError, RepositoryNotFoundError, UnauthorizedRepositoryAccessError } from "./public-api-errors";
import { Code, ConnectError } from "@connectrpc/connect";
import {
FailedPreconditionDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,15 @@ import {
UserEnvironmentVariable,
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb";
import { SCMToken, SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
import { ContextURL } from "./context-url";
import { ContextURL } from "@gitpod/gitpod-protocol/lib/context-url";
import {
Prebuild,
PrebuildStatus,
PrebuildPhase,
PrebuildPhase_Phase,
} from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb";
import {
ApplicationError,
ErrorCodes,
InvalidGitpodYMLError,
RepositoryNotFoundError,
UnauthorizedRepositoryAccessError,
} from "./messaging/error";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { InvalidGitpodYMLError, RepositoryNotFoundError, UnauthorizedRepositoryAccessError } from "./public-api-errors";
import {
AuthProviderEntry as AuthProviderProtocol,
AuthProviderInfo,
Expand All @@ -89,7 +84,7 @@ import {
Token,
SuggestedRepository as SuggestedRepositoryProtocol,
UserSSHPublicKeyValue,
} from "./protocol";
} from "@gitpod/gitpod-protocol/lib//protocol";
import {
OrgMemberInfo,
OrgMemberRole,
Expand All @@ -99,16 +94,16 @@ import {
PrebuildWithStatus,
Project,
Organization as ProtocolOrganization,
} from "./teams-projects-protocol";
} from "@gitpod/gitpod-protocol/lib//teams-projects-protocol";
import {
ConfigurationIdeConfig,
PortProtocol,
WorkspaceInstance,
WorkspaceInstanceConditions,
WorkspaceInstancePort,
} from "./workspace-instance";
} from "@gitpod/gitpod-protocol/lib//workspace-instance";
import { Author, Commit } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
import type { DeepPartial } from "./util/deep-partial";
import type { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";

export type PartialConfiguration = DeepPartial<Configuration> & Pick<Configuration, "id">;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2023 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 { PlainMessage } from "@bufbuild/protobuf";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import {
InvalidGitpodYMLError as InvalidGitpodYMLErrorData,
RepositoryNotFoundError as RepositoryNotFoundErrorData,
RepositoryUnauthorizedError as RepositoryUnauthorizedErrorData,
} from "@gitpod/public-api/lib/gitpod/v1/error_pb";

export class RepositoryNotFoundError extends ApplicationError {
constructor(readonly info: PlainMessage<RepositoryNotFoundErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.NOT_FOUND, "Repository not found.", info);
}
}
export class UnauthorizedRepositoryAccessError extends ApplicationError {
constructor(readonly info: PlainMessage<RepositoryUnauthorizedErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.NOT_AUTHENTICATED, "Repository unauthorized.", info);
}
}
export class InvalidGitpodYMLError extends ApplicationError {
constructor(readonly info: PlainMessage<InvalidGitpodYMLErrorData>) {
// on gRPC we remap to PRECONDITION_FAILED, all error code for backwards compatibility with the dashboard
super(ErrorCodes.INVALID_GITPOD_YML, "Invalid gitpod.yml: " + info.violations.join(","), info);
}
}
31 changes: 31 additions & 0 deletions components/public-api/typescript-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"rootDir": "src",
"experimentalDecorators": true,
"outDir": "lib",
"declarationDir": "lib",
"lib": [
"es6",
"esnext.asynciterable",
"DOM"
],
"strict": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"downlevelIteration": true,
"module": "CommonJS",
"moduleResolution": "node",
"target": "es6",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false
},
"include": [
"src"
]
}
22 changes: 2 additions & 20 deletions components/public-api/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,16 @@
"scripts": {
"build": "yarn run build:cjs && yarn run build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module es2015 --outDir ./lib/esm",
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput",
"test": "mocha './**/*.spec.ts' --exclude './node_modules/**' --exit",
"test:brk": "yarn test --inspect-brk"
},
"mocha": {
"require": [
"ts-node/register",
"reflect-metadata/Reflect",
"source-map-support/register"
],
"extensions": [
"ts"
],
"exit": true
"build:esm": "tsc --module es2015 --outDir ./lib/esm"
},
"dependencies": {
"@connectrpc/connect-node": "1.1.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is unrelated, but these dependencies are not strictly required, and not necessary in case of browser for instance

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling we are better to remove it and let a client to decide which version to use in their context.

"@connectrpc/connect": "1.1.2",
"@bufbuild/protobuf": "^1.3.3",
"prom-client": "^14.2.0"
"@bufbuild/protobuf": "^1.3.3"
},
"devDependencies": {
"@connectrpc/protoc-gen-connect-es": "1.1.2",
"@bufbuild/protoc-gen-es": "1.3.3",
"@testdeck/mocha": "0.1.2",
"@types/chai": "^4.1.2",
"@types/node": "^16.11.0",
"typescript": "~4.4.2"
}
}
Loading