diff --git a/src/api-promise.ts b/src/api-promise.ts index a7416b0..8c775ee 100644 --- a/src/api-promise.ts +++ b/src/api-promise.ts @@ -1,92 +1,2 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import { type Gitpod } from './client'; - -import { type PromiseOrValue } from './internal/types'; -import { APIResponseProps, defaultParseResponse } from './internal/parse'; - -/** - * A subclass of `Promise` providing additional helper methods - * for interacting with the SDK. - */ -export class APIPromise extends Promise { - private parsedPromise: Promise | undefined; - #client: Gitpod; - - constructor( - client: Gitpod, - private responsePromise: Promise, - private parseResponse: ( - client: Gitpod, - props: APIResponseProps, - ) => PromiseOrValue = defaultParseResponse, - ) { - super((resolve) => { - // this is maybe a bit weird but this has to be a no-op to not implicitly - // parse the response body; instead .then, .catch, .finally are overridden - // to parse the response - resolve(null as any); - }); - this.#client = client; - } - - _thenUnwrap(transform: (data: T, props: APIResponseProps) => U): APIPromise { - return new APIPromise(this.#client, this.responsePromise, async (client, props) => - transform(await this.parseResponse(client, props), props), - ); - } - - /** - * Gets the raw `Response` instance instead of parsing the response - * data. - * - * If you want to parse the response body but still get the `Response` - * instance, you can use {@link withResponse()}. - * - * 👋 Getting the wrong TypeScript type for `Response`? - * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]` - * to your `tsconfig.json`. - */ - asResponse(): Promise { - return this.responsePromise.then((p) => p.response); - } - - /** - * Gets the parsed response data and the raw `Response` instance. - * - * If you just want to get the raw `Response` instance without parsing it, - * you can use {@link asResponse()}. - * - * 👋 Getting the wrong TypeScript type for `Response`? - * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]` - * to your `tsconfig.json`. - */ - async withResponse(): Promise<{ data: T; response: Response }> { - const [data, response] = await Promise.all([this.parse(), this.asResponse()]); - return { data, response }; - } - - private parse(): Promise { - if (!this.parsedPromise) { - this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(this.#client, data)); - } - return this.parsedPromise; - } - - override then( - onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, - onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null, - ): Promise { - return this.parse().then(onfulfilled, onrejected); - } - - override catch( - onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null, - ): Promise { - return this.parse().catch(onrejected); - } - - override finally(onfinally?: (() => void) | undefined | null): Promise { - return this.parse().finally(onfinally); - } -} +/** @deprecated Import from ./core/api-promise instead */ +export * from './core/api-promise'; diff --git a/src/client.ts b/src/client.ts index 4371dfa..ef0b007 100644 --- a/src/client.ts +++ b/src/client.ts @@ -13,8 +13,8 @@ import { getPlatformHeaders } from './internal/detect-platform'; import * as Shims from './internal/shims'; import * as Opts from './internal/request-options'; import { VERSION } from './version'; -import * as Errors from './error'; -import * as Pagination from './pagination'; +import * as Errors from './core/error'; +import * as Pagination from './core/pagination'; import { AbstractPage, type DomainVerificationsPageParams, @@ -57,10 +57,10 @@ import { TasksPageResponse, type TokensPageParams, TokensPageResponse, -} from './pagination'; -import * as Uploads from './uploads'; +} from './core/pagination'; +import * as Uploads from './core/uploads'; import * as API from './resources/index'; -import { APIPromise } from './api-promise'; +import { APIPromise } from './core/api-promise'; import { type Fetch } from './internal/builtin-types'; import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers'; import { FinalRequestOptions, RequestOptions } from './internal/request-options'; diff --git a/src/core/README.md b/src/core/README.md new file mode 100644 index 0000000..485fce8 --- /dev/null +++ b/src/core/README.md @@ -0,0 +1,3 @@ +# `core` + +This directory holds public modules implementing non-resource-specific SDK functionality. diff --git a/src/core/api-promise.ts b/src/core/api-promise.ts new file mode 100644 index 0000000..639a545 --- /dev/null +++ b/src/core/api-promise.ts @@ -0,0 +1,92 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { type Gitpod } from '../client'; + +import { type PromiseOrValue } from '../internal/types'; +import { APIResponseProps, defaultParseResponse } from '../internal/parse'; + +/** + * A subclass of `Promise` providing additional helper methods + * for interacting with the SDK. + */ +export class APIPromise extends Promise { + private parsedPromise: Promise | undefined; + #client: Gitpod; + + constructor( + client: Gitpod, + private responsePromise: Promise, + private parseResponse: ( + client: Gitpod, + props: APIResponseProps, + ) => PromiseOrValue = defaultParseResponse, + ) { + super((resolve) => { + // this is maybe a bit weird but this has to be a no-op to not implicitly + // parse the response body; instead .then, .catch, .finally are overridden + // to parse the response + resolve(null as any); + }); + this.#client = client; + } + + _thenUnwrap(transform: (data: T, props: APIResponseProps) => U): APIPromise { + return new APIPromise(this.#client, this.responsePromise, async (client, props) => + transform(await this.parseResponse(client, props), props), + ); + } + + /** + * Gets the raw `Response` instance instead of parsing the response + * data. + * + * If you want to parse the response body but still get the `Response` + * instance, you can use {@link withResponse()}. + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]` + * to your `tsconfig.json`. + */ + asResponse(): Promise { + return this.responsePromise.then((p) => p.response); + } + + /** + * Gets the parsed response data and the raw `Response` instance. + * + * If you just want to get the raw `Response` instance without parsing it, + * you can use {@link asResponse()}. + * + * 👋 Getting the wrong TypeScript type for `Response`? + * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]` + * to your `tsconfig.json`. + */ + async withResponse(): Promise<{ data: T; response: Response }> { + const [data, response] = await Promise.all([this.parse(), this.asResponse()]); + return { data, response }; + } + + private parse(): Promise { + if (!this.parsedPromise) { + this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(this.#client, data)); + } + return this.parsedPromise; + } + + override then( + onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, + onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null, + ): Promise { + return this.parse().then(onfulfilled, onrejected); + } + + override catch( + onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null, + ): Promise { + return this.parse().catch(onrejected); + } + + override finally(onfinally?: (() => void) | undefined | null): Promise { + return this.parse().finally(onfinally); + } +} diff --git a/src/core/error.ts b/src/core/error.ts new file mode 100644 index 0000000..1b22334 --- /dev/null +++ b/src/core/error.ts @@ -0,0 +1,140 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { castToError } from '../internal/errors'; +import * as Shared from '../resources/shared'; + +export class GitpodError extends Error {} + +export class APIError< + TStatus extends number | undefined = number | undefined, + THeaders extends Headers | undefined = Headers | undefined, + TError extends Object | undefined = Object | undefined, +> extends GitpodError { + /** HTTP status for the response that caused the error */ + readonly status: TStatus; + /** HTTP headers for the response that caused the error */ + readonly headers: THeaders; + /** JSON body of the response that caused the error */ + readonly error: TError; + + /** + * The status code, which should be an enum value of + * [google.rpc.Code][google.rpc.Code]. + */ + readonly code?: Shared.ErrorCode | undefined; + + constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) { + super(`${APIError.makeMessage(status, error, message)}`); + this.status = status; + this.headers = headers; + this.error = error; + + const data = error as Record; + this.code = data?.['code']; + } + + private static makeMessage(status: number | undefined, error: any, message: string | undefined) { + const msg = + error?.message ? + typeof error.message === 'string' ? + error.message + : JSON.stringify(error.message) + : error ? JSON.stringify(error) + : message; + + if (status && msg) { + return `${status} ${msg}`; + } + if (status) { + return `${status} status code (no body)`; + } + if (msg) { + return msg; + } + return '(no status code or body)'; + } + + static generate( + status: number | undefined, + errorResponse: Object | undefined, + message: string | undefined, + headers: Headers | undefined, + ): APIError { + if (!status || !headers) { + return new APIConnectionError({ message, cause: castToError(errorResponse) }); + } + + const error = errorResponse as Record; + + if (status === 400) { + return new BadRequestError(status, error, message, headers); + } + + if (status === 401) { + return new AuthenticationError(status, error, message, headers); + } + + if (status === 403) { + return new PermissionDeniedError(status, error, message, headers); + } + + if (status === 404) { + return new NotFoundError(status, error, message, headers); + } + + if (status === 409) { + return new ConflictError(status, error, message, headers); + } + + if (status === 422) { + return new UnprocessableEntityError(status, error, message, headers); + } + + if (status === 429) { + return new RateLimitError(status, error, message, headers); + } + + if (status >= 500) { + return new InternalServerError(status, error, message, headers); + } + + return new APIError(status, error, message, headers); + } +} + +export class APIUserAbortError extends APIError { + constructor({ message }: { message?: string } = {}) { + super(undefined, undefined, message || 'Request was aborted.', undefined); + } +} + +export class APIConnectionError extends APIError { + constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) { + super(undefined, undefined, message || 'Connection error.', undefined); + // in some environments the 'cause' property is already declared + // @ts-ignore + if (cause) this.cause = cause; + } +} + +export class APIConnectionTimeoutError extends APIConnectionError { + constructor({ message }: { message?: string } = {}) { + super({ message: message ?? 'Request timed out.' }); + } +} + +export class BadRequestError extends APIError<400, Headers> {} + +export class AuthenticationError extends APIError<401, Headers> {} + +export class PermissionDeniedError extends APIError<403, Headers> {} + +export class NotFoundError extends APIError<404, Headers> {} + +export class ConflictError extends APIError<409, Headers> {} + +export class UnprocessableEntityError extends APIError<422, Headers> {} + +export class RateLimitError extends APIError<429, Headers> {} + +export class InternalServerError extends APIError {} diff --git a/src/core/pagination.ts b/src/core/pagination.ts new file mode 100644 index 0000000..5ae7b97 --- /dev/null +++ b/src/core/pagination.ts @@ -0,0 +1,1220 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { GitpodError } from './error'; +import { FinalRequestOptions } from '../internal/request-options'; +import { defaultParseResponse } from '../internal/parse'; +import { type Gitpod } from '../client'; +import { APIPromise } from './api-promise'; +import { type APIResponseProps } from '../internal/parse'; +import { maybeObj } from '../internal/utils/values'; + +export type PageRequestOptions = Pick; + +export abstract class AbstractPage implements AsyncIterable { + #client: Gitpod; + protected options: FinalRequestOptions; + + protected response: Response; + protected body: unknown; + + constructor(client: Gitpod, response: Response, body: unknown, options: FinalRequestOptions) { + this.#client = client; + this.options = options; + this.response = response; + this.body = body; + } + + abstract nextPageRequestOptions(): PageRequestOptions | null; + + abstract getPaginatedItems(): Item[]; + + hasNextPage(): boolean { + const items = this.getPaginatedItems(); + if (!items.length) return false; + return this.nextPageRequestOptions() != null; + } + + async getNextPage(): Promise { + const nextOptions = this.nextPageRequestOptions(); + if (!nextOptions) { + throw new GitpodError( + 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.', + ); + } + + return await this.#client.requestAPIList(this.constructor as any, nextOptions); + } + + async *iterPages(): AsyncGenerator { + let page: this = this; + yield page; + while (page.hasNextPage()) { + page = await page.getNextPage(); + yield page; + } + } + + async *[Symbol.asyncIterator](): AsyncGenerator { + for await (const page of this.iterPages()) { + for (const item of page.getPaginatedItems()) { + yield item; + } + } + } +} + +/** + * This subclass of Promise will resolve to an instantiated Page once the request completes. + * + * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg: + * + * for await (const item of client.items.list()) { + * console.log(item) + * } + */ +export class PagePromise< + PageClass extends AbstractPage, + Item = ReturnType[number], + > + extends APIPromise + implements AsyncIterable +{ + constructor( + client: Gitpod, + request: Promise, + Page: new (...args: ConstructorParameters) => PageClass, + ) { + super( + client, + request, + async (client, props) => + new Page(client, props.response, await defaultParseResponse(client, props), props.options), + ); + } + + /** + * Allow auto-paginating iteration on an unawaited list call, eg: + * + * for await (const item of client.items.list()) { + * console.log(item) + * } + */ + async *[Symbol.asyncIterator]() { + const page = await this; + for await (const item of page) { + yield item; + } + } +} + +export interface DomainVerificationsPageResponse { + domainVerifications: Array; + + pagination: DomainVerificationsPageResponse.Pagination; +} + +export namespace DomainVerificationsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface DomainVerificationsPageParams { + pageSize?: number; + + token?: string; +} + +export class DomainVerificationsPage + extends AbstractPage + implements DomainVerificationsPageResponse +{ + domainVerifications: Array; + + pagination: DomainVerificationsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: DomainVerificationsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.domainVerifications = body.domainVerifications || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.domainVerifications ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface EditorsPageResponse { + editors: Array; + + pagination: EditorsPageResponse.Pagination; +} + +export namespace EditorsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface EditorsPageParams { + pageSize?: number; + + token?: string; +} + +export class EditorsPage extends AbstractPage implements EditorsPageResponse { + editors: Array; + + pagination: EditorsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: EditorsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.editors = body.editors || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.editors ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface EntriesPageResponse { + entries: Array; + + pagination: EntriesPageResponse.Pagination; +} + +export namespace EntriesPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface EntriesPageParams { + pageSize?: number; + + token?: string; +} + +export class EntriesPage extends AbstractPage implements EntriesPageResponse { + entries: Array; + + pagination: EntriesPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: EntriesPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.entries = body.entries || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.entries ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface EnvironmentClassesPageResponse { + environmentClasses: Array; + + pagination: EnvironmentClassesPageResponse.Pagination; +} + +export namespace EnvironmentClassesPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface EnvironmentClassesPageParams { + pageSize?: number; + + token?: string; +} + +export class EnvironmentClassesPage + extends AbstractPage + implements EnvironmentClassesPageResponse +{ + environmentClasses: Array; + + pagination: EnvironmentClassesPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: EnvironmentClassesPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.environmentClasses = body.environmentClasses || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.environmentClasses ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface EnvironmentsPageResponse { + environments: Array; + + pagination: EnvironmentsPageResponse.Pagination; +} + +export namespace EnvironmentsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface EnvironmentsPageParams { + pageSize?: number; + + token?: string; +} + +export class EnvironmentsPage extends AbstractPage implements EnvironmentsPageResponse { + environments: Array; + + pagination: EnvironmentsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: EnvironmentsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.environments = body.environments || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.environments ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface GroupsPageResponse { + groups: Array; + + pagination: GroupsPageResponse.Pagination; +} + +export namespace GroupsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface GroupsPageParams { + pageSize?: number; + + token?: string; +} + +export class GroupsPage extends AbstractPage implements GroupsPageResponse { + groups: Array; + + pagination: GroupsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: GroupsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.groups = body.groups || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.groups ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface IntegrationsPageResponse { + integrations: Array; + + pagination: IntegrationsPageResponse.Pagination; +} + +export namespace IntegrationsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface IntegrationsPageParams { + pageSize?: number; + + token?: string; +} + +export class IntegrationsPage extends AbstractPage implements IntegrationsPageResponse { + integrations: Array; + + pagination: IntegrationsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: IntegrationsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.integrations = body.integrations || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.integrations ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface LoginProvidersPageResponse { + loginProviders: Array; + + pagination: LoginProvidersPageResponse.Pagination; +} + +export namespace LoginProvidersPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface LoginProvidersPageParams { + pageSize?: number; + + token?: string; +} + +export class LoginProvidersPage extends AbstractPage implements LoginProvidersPageResponse { + loginProviders: Array; + + pagination: LoginProvidersPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: LoginProvidersPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.loginProviders = body.loginProviders || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.loginProviders ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface MembersPageResponse { + members: Array; + + pagination: MembersPageResponse.Pagination; +} + +export namespace MembersPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface MembersPageParams { + pageSize?: number; + + token?: string; +} + +export class MembersPage extends AbstractPage implements MembersPageResponse { + members: Array; + + pagination: MembersPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: MembersPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.members = body.members || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.members ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface OrganizationsPageResponse { + organizations: Array; + + pagination: OrganizationsPageResponse.Pagination; +} + +export namespace OrganizationsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface OrganizationsPageParams { + pageSize?: number; + + token?: string; +} + +export class OrganizationsPage extends AbstractPage implements OrganizationsPageResponse { + organizations: Array; + + pagination: OrganizationsPageResponse.Pagination; + + constructor( + client: Gitpod, + response: Response, + body: OrganizationsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.organizations = body.organizations || []; + this.pagination = body.pagination || {}; + } + + getPaginatedItems(): Item[] { + return this.organizations ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface PersonalAccessTokensPageResponse { + pagination: PersonalAccessTokensPageResponse.Pagination; + + personalAccessTokens: Array; +} + +export namespace PersonalAccessTokensPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface PersonalAccessTokensPageParams { + pageSize?: number; + + token?: string; +} + +export class PersonalAccessTokensPage + extends AbstractPage + implements PersonalAccessTokensPageResponse +{ + pagination: PersonalAccessTokensPageResponse.Pagination; + + personalAccessTokens: Array; + + constructor( + client: Gitpod, + response: Response, + body: PersonalAccessTokensPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.personalAccessTokens = body.personalAccessTokens || []; + } + + getPaginatedItems(): Item[] { + return this.personalAccessTokens ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface PoliciesPageResponse { + pagination: PoliciesPageResponse.Pagination; + + policies: Array; +} + +export namespace PoliciesPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface PoliciesPageParams { + pageSize?: number; + + token?: string; +} + +export class PoliciesPage extends AbstractPage implements PoliciesPageResponse { + pagination: PoliciesPageResponse.Pagination; + + policies: Array; + + constructor( + client: Gitpod, + response: Response, + body: PoliciesPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.policies = body.policies || []; + } + + getPaginatedItems(): Item[] { + return this.policies ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface ProjectsPageResponse { + pagination: ProjectsPageResponse.Pagination; + + projects: Array; +} + +export namespace ProjectsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface ProjectsPageParams { + pageSize?: number; + + token?: string; +} + +export class ProjectsPage extends AbstractPage implements ProjectsPageResponse { + pagination: ProjectsPageResponse.Pagination; + + projects: Array; + + constructor( + client: Gitpod, + response: Response, + body: ProjectsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.projects = body.projects || []; + } + + getPaginatedItems(): Item[] { + return this.projects ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface RunnersPageResponse { + pagination: RunnersPageResponse.Pagination; + + runners: Array; +} + +export namespace RunnersPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface RunnersPageParams { + pageSize?: number; + + token?: string; +} + +export class RunnersPage extends AbstractPage implements RunnersPageResponse { + pagination: RunnersPageResponse.Pagination; + + runners: Array; + + constructor( + client: Gitpod, + response: Response, + body: RunnersPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.runners = body.runners || []; + } + + getPaginatedItems(): Item[] { + return this.runners ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface SecretsPageResponse { + pagination: SecretsPageResponse.Pagination; + + secrets: Array; +} + +export namespace SecretsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface SecretsPageParams { + pageSize?: number; + + token?: string; +} + +export class SecretsPage extends AbstractPage implements SecretsPageResponse { + pagination: SecretsPageResponse.Pagination; + + secrets: Array; + + constructor( + client: Gitpod, + response: Response, + body: SecretsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.secrets = body.secrets || []; + } + + getPaginatedItems(): Item[] { + return this.secrets ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface ServicesPageResponse { + pagination: ServicesPageResponse.Pagination; + + services: Array; +} + +export namespace ServicesPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface ServicesPageParams { + pageSize?: number; + + token?: string; +} + +export class ServicesPage extends AbstractPage implements ServicesPageResponse { + pagination: ServicesPageResponse.Pagination; + + services: Array; + + constructor( + client: Gitpod, + response: Response, + body: ServicesPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.services = body.services || []; + } + + getPaginatedItems(): Item[] { + return this.services ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface SSOConfigurationsPageResponse { + pagination: SSOConfigurationsPageResponse.Pagination; + + ssoConfigurations: Array; +} + +export namespace SSOConfigurationsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface SSOConfigurationsPageParams { + pageSize?: number; + + token?: string; +} + +export class SSOConfigurationsPage + extends AbstractPage + implements SSOConfigurationsPageResponse +{ + pagination: SSOConfigurationsPageResponse.Pagination; + + ssoConfigurations: Array; + + constructor( + client: Gitpod, + response: Response, + body: SSOConfigurationsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.ssoConfigurations = body.ssoConfigurations || []; + } + + getPaginatedItems(): Item[] { + return this.ssoConfigurations ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface TaskExecutionsPageResponse { + pagination: TaskExecutionsPageResponse.Pagination; + + taskExecutions: Array; +} + +export namespace TaskExecutionsPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface TaskExecutionsPageParams { + pageSize?: number; + + token?: string; +} + +export class TaskExecutionsPage extends AbstractPage implements TaskExecutionsPageResponse { + pagination: TaskExecutionsPageResponse.Pagination; + + taskExecutions: Array; + + constructor( + client: Gitpod, + response: Response, + body: TaskExecutionsPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.taskExecutions = body.taskExecutions || []; + } + + getPaginatedItems(): Item[] { + return this.taskExecutions ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface TasksPageResponse { + pagination: TasksPageResponse.Pagination; + + tasks: Array; +} + +export namespace TasksPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface TasksPageParams { + pageSize?: number; + + token?: string; +} + +export class TasksPage extends AbstractPage implements TasksPageResponse { + pagination: TasksPageResponse.Pagination; + + tasks: Array; + + constructor( + client: Gitpod, + response: Response, + body: TasksPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.tasks = body.tasks || []; + } + + getPaginatedItems(): Item[] { + return this.tasks ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} + +export interface TokensPageResponse { + pagination: TokensPageResponse.Pagination; + + tokens: Array; +} + +export namespace TokensPageResponse { + export interface Pagination { + nextToken?: string; + } +} + +export interface TokensPageParams { + pageSize?: number; + + token?: string; +} + +export class TokensPage extends AbstractPage implements TokensPageResponse { + pagination: TokensPageResponse.Pagination; + + tokens: Array; + + constructor( + client: Gitpod, + response: Response, + body: TokensPageResponse, + options: FinalRequestOptions, + ) { + super(client, response, body, options); + + this.pagination = body.pagination || {}; + this.tokens = body.tokens || []; + } + + getPaginatedItems(): Item[] { + return this.tokens ?? []; + } + + nextPageRequestOptions(): PageRequestOptions | null { + const cursor = this.pagination?.nextToken; + if (!cursor) { + return null; + } + + return { + ...this.options, + query: { + ...maybeObj(this.options.query), + token: cursor, + }, + }; + } +} diff --git a/src/core/resource.ts b/src/core/resource.ts new file mode 100644 index 0000000..c73b82d --- /dev/null +++ b/src/core/resource.ts @@ -0,0 +1,11 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import type { Gitpod } from '../client'; + +export class APIResource { + protected _client: Gitpod; + + constructor(client: Gitpod) { + this._client = client; + } +} diff --git a/src/core/uploads.ts b/src/core/uploads.ts new file mode 100644 index 0000000..2882ca6 --- /dev/null +++ b/src/core/uploads.ts @@ -0,0 +1,2 @@ +export { type Uploadable } from '../internal/uploads'; +export { toFile, type ToFileInput } from '../internal/to-file'; diff --git a/src/error.ts b/src/error.ts index 67145c6..fc55f46 100644 --- a/src/error.ts +++ b/src/error.ts @@ -1,140 +1,2 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import { castToError } from './internal/errors'; -import * as Shared from './resources/shared'; - -export class GitpodError extends Error {} - -export class APIError< - TStatus extends number | undefined = number | undefined, - THeaders extends Headers | undefined = Headers | undefined, - TError extends Object | undefined = Object | undefined, -> extends GitpodError { - /** HTTP status for the response that caused the error */ - readonly status: TStatus; - /** HTTP headers for the response that caused the error */ - readonly headers: THeaders; - /** JSON body of the response that caused the error */ - readonly error: TError; - - /** - * The status code, which should be an enum value of - * [google.rpc.Code][google.rpc.Code]. - */ - readonly code?: Shared.ErrorCode | undefined; - - constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) { - super(`${APIError.makeMessage(status, error, message)}`); - this.status = status; - this.headers = headers; - this.error = error; - - const data = error as Record; - this.code = data?.['code']; - } - - private static makeMessage(status: number | undefined, error: any, message: string | undefined) { - const msg = - error?.message ? - typeof error.message === 'string' ? - error.message - : JSON.stringify(error.message) - : error ? JSON.stringify(error) - : message; - - if (status && msg) { - return `${status} ${msg}`; - } - if (status) { - return `${status} status code (no body)`; - } - if (msg) { - return msg; - } - return '(no status code or body)'; - } - - static generate( - status: number | undefined, - errorResponse: Object | undefined, - message: string | undefined, - headers: Headers | undefined, - ): APIError { - if (!status || !headers) { - return new APIConnectionError({ message, cause: castToError(errorResponse) }); - } - - const error = errorResponse as Record; - - if (status === 400) { - return new BadRequestError(status, error, message, headers); - } - - if (status === 401) { - return new AuthenticationError(status, error, message, headers); - } - - if (status === 403) { - return new PermissionDeniedError(status, error, message, headers); - } - - if (status === 404) { - return new NotFoundError(status, error, message, headers); - } - - if (status === 409) { - return new ConflictError(status, error, message, headers); - } - - if (status === 422) { - return new UnprocessableEntityError(status, error, message, headers); - } - - if (status === 429) { - return new RateLimitError(status, error, message, headers); - } - - if (status >= 500) { - return new InternalServerError(status, error, message, headers); - } - - return new APIError(status, error, message, headers); - } -} - -export class APIUserAbortError extends APIError { - constructor({ message }: { message?: string } = {}) { - super(undefined, undefined, message || 'Request was aborted.', undefined); - } -} - -export class APIConnectionError extends APIError { - constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) { - super(undefined, undefined, message || 'Connection error.', undefined); - // in some environments the 'cause' property is already declared - // @ts-ignore - if (cause) this.cause = cause; - } -} - -export class APIConnectionTimeoutError extends APIConnectionError { - constructor({ message }: { message?: string } = {}) { - super({ message: message ?? 'Request timed out.' }); - } -} - -export class BadRequestError extends APIError<400, Headers> {} - -export class AuthenticationError extends APIError<401, Headers> {} - -export class PermissionDeniedError extends APIError<403, Headers> {} - -export class NotFoundError extends APIError<404, Headers> {} - -export class ConflictError extends APIError<409, Headers> {} - -export class UnprocessableEntityError extends APIError<422, Headers> {} - -export class RateLimitError extends APIError<429, Headers> {} - -export class InternalServerError extends APIError {} +/** @deprecated Import from ./core/error instead */ +export * from './core/error'; diff --git a/src/index.ts b/src/index.ts index 2b3917a..0eaf4c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,10 +2,10 @@ export { Gitpod as default } from './client'; -export { type Uploadable, toFile } from './uploads'; -export { APIPromise } from './api-promise'; +export { type Uploadable, toFile } from './core/uploads'; +export { APIPromise } from './core/api-promise'; export { Gitpod, type ClientOptions } from './client'; -export { PagePromise } from './pagination'; +export { PagePromise } from './core/pagination'; export { GitpodError, APIError, @@ -20,4 +20,4 @@ export { InternalServerError, PermissionDeniedError, UnprocessableEntityError, -} from './error'; +} from './core/error'; diff --git a/src/internal/README.md b/src/internal/README.md new file mode 100644 index 0000000..3ef5a25 --- /dev/null +++ b/src/internal/README.md @@ -0,0 +1,3 @@ +# `internal` + +The modules in this directory are not importable outside this package and will change between releases. diff --git a/src/internal/decoders/jsonl.ts b/src/internal/decoders/jsonl.ts index cb40d92..79ec5f8 100644 --- a/src/internal/decoders/jsonl.ts +++ b/src/internal/decoders/jsonl.ts @@ -1,4 +1,4 @@ -import { GitpodError } from '../../error'; +import { GitpodError } from '../../core/error'; import { ReadableStreamToAsyncIterable } from '../shims'; import { LineDecoder, type Bytes } from './line'; diff --git a/src/internal/decoders/line.ts b/src/internal/decoders/line.ts index 0295286..a4c237f 100644 --- a/src/internal/decoders/line.ts +++ b/src/internal/decoders/line.ts @@ -1,4 +1,4 @@ -import { GitpodError } from '../../error'; +import { GitpodError } from '../../core/error'; export type Bytes = string | ArrayBuffer | Uint8Array | null | undefined; diff --git a/src/internal/utils/base64.ts b/src/internal/utils/base64.ts index 3b077b3..50d616c 100644 --- a/src/internal/utils/base64.ts +++ b/src/internal/utils/base64.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { GitpodError } from '../../error'; +import { GitpodError } from '../../core/error'; export const toBase64 = (data: string | Uint8Array | null | undefined): string => { if (!data) return ''; diff --git a/src/internal/utils/path.ts b/src/internal/utils/path.ts index 0115b07..56154a2 100644 --- a/src/internal/utils/path.ts +++ b/src/internal/utils/path.ts @@ -1,4 +1,4 @@ -import { GitpodError } from '../../error'; +import { GitpodError } from '../../core/error'; /** * Percent-encode everything that isn't safe to have in a path without encoding safe chars. diff --git a/src/internal/utils/values.ts b/src/internal/utils/values.ts index 43b0e39..d0e9c61 100644 --- a/src/internal/utils/values.ts +++ b/src/internal/utils/values.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { GitpodError } from '../../error'; +import { GitpodError } from '../../core/error'; // https://url.spec.whatwg.org/#url-scheme-string const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i; diff --git a/src/pagination.ts b/src/pagination.ts index 7bacc0a..90bf015 100644 --- a/src/pagination.ts +++ b/src/pagination.ts @@ -1,1220 +1,2 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import { GitpodError } from './error'; -import { FinalRequestOptions } from './internal/request-options'; -import { defaultParseResponse } from './internal/parse'; -import { APIPromise } from './api-promise'; -import { type Gitpod } from './client'; -import { type APIResponseProps } from './internal/parse'; -import { maybeObj } from './internal/utils/values'; - -export type PageRequestOptions = Pick; - -export abstract class AbstractPage implements AsyncIterable { - #client: Gitpod; - protected options: FinalRequestOptions; - - protected response: Response; - protected body: unknown; - - constructor(client: Gitpod, response: Response, body: unknown, options: FinalRequestOptions) { - this.#client = client; - this.options = options; - this.response = response; - this.body = body; - } - - abstract nextPageRequestOptions(): PageRequestOptions | null; - - abstract getPaginatedItems(): Item[]; - - hasNextPage(): boolean { - const items = this.getPaginatedItems(); - if (!items.length) return false; - return this.nextPageRequestOptions() != null; - } - - async getNextPage(): Promise { - const nextOptions = this.nextPageRequestOptions(); - if (!nextOptions) { - throw new GitpodError( - 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.', - ); - } - - return await this.#client.requestAPIList(this.constructor as any, nextOptions); - } - - async *iterPages(): AsyncGenerator { - let page: this = this; - yield page; - while (page.hasNextPage()) { - page = await page.getNextPage(); - yield page; - } - } - - async *[Symbol.asyncIterator](): AsyncGenerator { - for await (const page of this.iterPages()) { - for (const item of page.getPaginatedItems()) { - yield item; - } - } - } -} - -/** - * This subclass of Promise will resolve to an instantiated Page once the request completes. - * - * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg: - * - * for await (const item of client.items.list()) { - * console.log(item) - * } - */ -export class PagePromise< - PageClass extends AbstractPage, - Item = ReturnType[number], - > - extends APIPromise - implements AsyncIterable -{ - constructor( - client: Gitpod, - request: Promise, - Page: new (...args: ConstructorParameters) => PageClass, - ) { - super( - client, - request, - async (client, props) => - new Page(client, props.response, await defaultParseResponse(client, props), props.options), - ); - } - - /** - * Allow auto-paginating iteration on an unawaited list call, eg: - * - * for await (const item of client.items.list()) { - * console.log(item) - * } - */ - async *[Symbol.asyncIterator]() { - const page = await this; - for await (const item of page) { - yield item; - } - } -} - -export interface DomainVerificationsPageResponse { - domainVerifications: Array; - - pagination: DomainVerificationsPageResponse.Pagination; -} - -export namespace DomainVerificationsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface DomainVerificationsPageParams { - pageSize?: number; - - token?: string; -} - -export class DomainVerificationsPage - extends AbstractPage - implements DomainVerificationsPageResponse -{ - domainVerifications: Array; - - pagination: DomainVerificationsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: DomainVerificationsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.domainVerifications = body.domainVerifications || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.domainVerifications ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface EditorsPageResponse { - editors: Array; - - pagination: EditorsPageResponse.Pagination; -} - -export namespace EditorsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface EditorsPageParams { - pageSize?: number; - - token?: string; -} - -export class EditorsPage extends AbstractPage implements EditorsPageResponse { - editors: Array; - - pagination: EditorsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: EditorsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.editors = body.editors || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.editors ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface EntriesPageResponse { - entries: Array; - - pagination: EntriesPageResponse.Pagination; -} - -export namespace EntriesPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface EntriesPageParams { - pageSize?: number; - - token?: string; -} - -export class EntriesPage extends AbstractPage implements EntriesPageResponse { - entries: Array; - - pagination: EntriesPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: EntriesPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.entries = body.entries || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.entries ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface EnvironmentClassesPageResponse { - environmentClasses: Array; - - pagination: EnvironmentClassesPageResponse.Pagination; -} - -export namespace EnvironmentClassesPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface EnvironmentClassesPageParams { - pageSize?: number; - - token?: string; -} - -export class EnvironmentClassesPage - extends AbstractPage - implements EnvironmentClassesPageResponse -{ - environmentClasses: Array; - - pagination: EnvironmentClassesPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: EnvironmentClassesPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.environmentClasses = body.environmentClasses || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.environmentClasses ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface EnvironmentsPageResponse { - environments: Array; - - pagination: EnvironmentsPageResponse.Pagination; -} - -export namespace EnvironmentsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface EnvironmentsPageParams { - pageSize?: number; - - token?: string; -} - -export class EnvironmentsPage extends AbstractPage implements EnvironmentsPageResponse { - environments: Array; - - pagination: EnvironmentsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: EnvironmentsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.environments = body.environments || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.environments ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface GroupsPageResponse { - groups: Array; - - pagination: GroupsPageResponse.Pagination; -} - -export namespace GroupsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface GroupsPageParams { - pageSize?: number; - - token?: string; -} - -export class GroupsPage extends AbstractPage implements GroupsPageResponse { - groups: Array; - - pagination: GroupsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: GroupsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.groups = body.groups || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.groups ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface IntegrationsPageResponse { - integrations: Array; - - pagination: IntegrationsPageResponse.Pagination; -} - -export namespace IntegrationsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface IntegrationsPageParams { - pageSize?: number; - - token?: string; -} - -export class IntegrationsPage extends AbstractPage implements IntegrationsPageResponse { - integrations: Array; - - pagination: IntegrationsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: IntegrationsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.integrations = body.integrations || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.integrations ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface LoginProvidersPageResponse { - loginProviders: Array; - - pagination: LoginProvidersPageResponse.Pagination; -} - -export namespace LoginProvidersPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface LoginProvidersPageParams { - pageSize?: number; - - token?: string; -} - -export class LoginProvidersPage extends AbstractPage implements LoginProvidersPageResponse { - loginProviders: Array; - - pagination: LoginProvidersPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: LoginProvidersPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.loginProviders = body.loginProviders || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.loginProviders ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface MembersPageResponse { - members: Array; - - pagination: MembersPageResponse.Pagination; -} - -export namespace MembersPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface MembersPageParams { - pageSize?: number; - - token?: string; -} - -export class MembersPage extends AbstractPage implements MembersPageResponse { - members: Array; - - pagination: MembersPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: MembersPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.members = body.members || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.members ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface OrganizationsPageResponse { - organizations: Array; - - pagination: OrganizationsPageResponse.Pagination; -} - -export namespace OrganizationsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface OrganizationsPageParams { - pageSize?: number; - - token?: string; -} - -export class OrganizationsPage extends AbstractPage implements OrganizationsPageResponse { - organizations: Array; - - pagination: OrganizationsPageResponse.Pagination; - - constructor( - client: Gitpod, - response: Response, - body: OrganizationsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.organizations = body.organizations || []; - this.pagination = body.pagination || {}; - } - - getPaginatedItems(): Item[] { - return this.organizations ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface PersonalAccessTokensPageResponse { - pagination: PersonalAccessTokensPageResponse.Pagination; - - personalAccessTokens: Array; -} - -export namespace PersonalAccessTokensPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface PersonalAccessTokensPageParams { - pageSize?: number; - - token?: string; -} - -export class PersonalAccessTokensPage - extends AbstractPage - implements PersonalAccessTokensPageResponse -{ - pagination: PersonalAccessTokensPageResponse.Pagination; - - personalAccessTokens: Array; - - constructor( - client: Gitpod, - response: Response, - body: PersonalAccessTokensPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.personalAccessTokens = body.personalAccessTokens || []; - } - - getPaginatedItems(): Item[] { - return this.personalAccessTokens ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface PoliciesPageResponse { - pagination: PoliciesPageResponse.Pagination; - - policies: Array; -} - -export namespace PoliciesPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface PoliciesPageParams { - pageSize?: number; - - token?: string; -} - -export class PoliciesPage extends AbstractPage implements PoliciesPageResponse { - pagination: PoliciesPageResponse.Pagination; - - policies: Array; - - constructor( - client: Gitpod, - response: Response, - body: PoliciesPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.policies = body.policies || []; - } - - getPaginatedItems(): Item[] { - return this.policies ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface ProjectsPageResponse { - pagination: ProjectsPageResponse.Pagination; - - projects: Array; -} - -export namespace ProjectsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface ProjectsPageParams { - pageSize?: number; - - token?: string; -} - -export class ProjectsPage extends AbstractPage implements ProjectsPageResponse { - pagination: ProjectsPageResponse.Pagination; - - projects: Array; - - constructor( - client: Gitpod, - response: Response, - body: ProjectsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.projects = body.projects || []; - } - - getPaginatedItems(): Item[] { - return this.projects ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface RunnersPageResponse { - pagination: RunnersPageResponse.Pagination; - - runners: Array; -} - -export namespace RunnersPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface RunnersPageParams { - pageSize?: number; - - token?: string; -} - -export class RunnersPage extends AbstractPage implements RunnersPageResponse { - pagination: RunnersPageResponse.Pagination; - - runners: Array; - - constructor( - client: Gitpod, - response: Response, - body: RunnersPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.runners = body.runners || []; - } - - getPaginatedItems(): Item[] { - return this.runners ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface SecretsPageResponse { - pagination: SecretsPageResponse.Pagination; - - secrets: Array; -} - -export namespace SecretsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface SecretsPageParams { - pageSize?: number; - - token?: string; -} - -export class SecretsPage extends AbstractPage implements SecretsPageResponse { - pagination: SecretsPageResponse.Pagination; - - secrets: Array; - - constructor( - client: Gitpod, - response: Response, - body: SecretsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.secrets = body.secrets || []; - } - - getPaginatedItems(): Item[] { - return this.secrets ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface ServicesPageResponse { - pagination: ServicesPageResponse.Pagination; - - services: Array; -} - -export namespace ServicesPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface ServicesPageParams { - pageSize?: number; - - token?: string; -} - -export class ServicesPage extends AbstractPage implements ServicesPageResponse { - pagination: ServicesPageResponse.Pagination; - - services: Array; - - constructor( - client: Gitpod, - response: Response, - body: ServicesPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.services = body.services || []; - } - - getPaginatedItems(): Item[] { - return this.services ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface SSOConfigurationsPageResponse { - pagination: SSOConfigurationsPageResponse.Pagination; - - ssoConfigurations: Array; -} - -export namespace SSOConfigurationsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface SSOConfigurationsPageParams { - pageSize?: number; - - token?: string; -} - -export class SSOConfigurationsPage - extends AbstractPage - implements SSOConfigurationsPageResponse -{ - pagination: SSOConfigurationsPageResponse.Pagination; - - ssoConfigurations: Array; - - constructor( - client: Gitpod, - response: Response, - body: SSOConfigurationsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.ssoConfigurations = body.ssoConfigurations || []; - } - - getPaginatedItems(): Item[] { - return this.ssoConfigurations ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface TaskExecutionsPageResponse { - pagination: TaskExecutionsPageResponse.Pagination; - - taskExecutions: Array; -} - -export namespace TaskExecutionsPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface TaskExecutionsPageParams { - pageSize?: number; - - token?: string; -} - -export class TaskExecutionsPage extends AbstractPage implements TaskExecutionsPageResponse { - pagination: TaskExecutionsPageResponse.Pagination; - - taskExecutions: Array; - - constructor( - client: Gitpod, - response: Response, - body: TaskExecutionsPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.taskExecutions = body.taskExecutions || []; - } - - getPaginatedItems(): Item[] { - return this.taskExecutions ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface TasksPageResponse { - pagination: TasksPageResponse.Pagination; - - tasks: Array; -} - -export namespace TasksPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface TasksPageParams { - pageSize?: number; - - token?: string; -} - -export class TasksPage extends AbstractPage implements TasksPageResponse { - pagination: TasksPageResponse.Pagination; - - tasks: Array; - - constructor( - client: Gitpod, - response: Response, - body: TasksPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.tasks = body.tasks || []; - } - - getPaginatedItems(): Item[] { - return this.tasks ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} - -export interface TokensPageResponse { - pagination: TokensPageResponse.Pagination; - - tokens: Array; -} - -export namespace TokensPageResponse { - export interface Pagination { - nextToken?: string; - } -} - -export interface TokensPageParams { - pageSize?: number; - - token?: string; -} - -export class TokensPage extends AbstractPage implements TokensPageResponse { - pagination: TokensPageResponse.Pagination; - - tokens: Array; - - constructor( - client: Gitpod, - response: Response, - body: TokensPageResponse, - options: FinalRequestOptions, - ) { - super(client, response, body, options); - - this.pagination = body.pagination || {}; - this.tokens = body.tokens || []; - } - - getPaginatedItems(): Item[] { - return this.tokens ?? []; - } - - nextPageRequestOptions(): PageRequestOptions | null { - const cursor = this.pagination?.nextToken; - if (!cursor) { - return null; - } - - return { - ...this.options, - query: { - ...maybeObj(this.options.query), - token: cursor, - }, - }; - } -} +/** @deprecated Import from ./core/pagination instead */ +export * from './core/pagination'; diff --git a/src/resource.ts b/src/resource.ts index ce38897..363e351 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -1,11 +1,2 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import type { Gitpod } from './client'; - -export class APIResource { - protected _client: Gitpod; - - constructor(client: Gitpod) { - this._client = client; - } -} +/** @deprecated Import from ./core/resource instead */ +export * from './core/resource'; diff --git a/src/resources/accounts.ts b/src/resources/accounts.ts index 6704ddc..b341c47 100644 --- a/src/resources/accounts.ts +++ b/src/resources/accounts.ts @@ -1,9 +1,9 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; +import { APIResource } from '../core/resource'; import * as Shared from './shared'; -import { APIPromise } from '../api-promise'; -import { LoginProvidersPage, type LoginProvidersPageParams, PagePromise } from '../pagination'; +import { APIPromise } from '../core/api-promise'; +import { LoginProvidersPage, type LoginProvidersPageParams, PagePromise } from '../core/pagination'; import { RequestOptions } from '../internal/request-options'; export class Accounts extends APIResource { diff --git a/src/resources/editors.ts b/src/resources/editors.ts index 11232fc..28832f9 100644 --- a/src/resources/editors.ts +++ b/src/resources/editors.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; -import { APIPromise } from '../api-promise'; -import { EditorsPage, type EditorsPageParams, PagePromise } from '../pagination'; +import { APIResource } from '../core/resource'; +import { APIPromise } from '../core/api-promise'; +import { EditorsPage, type EditorsPageParams, PagePromise } from '../core/pagination'; import { RequestOptions } from '../internal/request-options'; export class Editors extends APIResource { diff --git a/src/resources/environments/automations/automations.ts b/src/resources/environments/automations/automations.ts index 9659f33..a369c3c 100644 --- a/src/resources/environments/automations/automations.ts +++ b/src/resources/environments/automations/automations.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; +import { APIResource } from '../../../core/resource'; import * as Shared from '../../shared'; import * as ServicesAPI from './services'; import { @@ -40,7 +40,7 @@ import { TaskUpdateResponse, Tasks as TasksAPITasks, } from './tasks/tasks'; -import { APIPromise } from '../../../api-promise'; +import { APIPromise } from '../../../core/api-promise'; import { RequestOptions } from '../../../internal/request-options'; export class Automations extends APIResource { diff --git a/src/resources/environments/automations/services.ts b/src/resources/environments/automations/services.ts index 4089844..6941f18 100644 --- a/src/resources/environments/automations/services.ts +++ b/src/resources/environments/automations/services.ts @@ -1,10 +1,10 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; +import { APIResource } from '../../../core/resource'; import * as ServicesAPI from './services'; import * as Shared from '../../shared'; -import { APIPromise } from '../../../api-promise'; -import { PagePromise, ServicesPage, type ServicesPageParams } from '../../../pagination'; +import { APIPromise } from '../../../core/api-promise'; +import { PagePromise, ServicesPage, type ServicesPageParams } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; export class Services extends APIResource { diff --git a/src/resources/environments/automations/tasks/executions.ts b/src/resources/environments/automations/tasks/executions.ts index d8bc0cf..47410d8 100644 --- a/src/resources/environments/automations/tasks/executions.ts +++ b/src/resources/environments/automations/tasks/executions.ts @@ -1,10 +1,10 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../../resource'; +import { APIResource } from '../../../../core/resource'; import * as Shared from '../../../shared'; import { TaskExecutionsTaskExecutionsPage } from '../../../shared'; -import { APIPromise } from '../../../../api-promise'; -import { PagePromise, TaskExecutionsPage, type TaskExecutionsPageParams } from '../../../../pagination'; +import { APIPromise } from '../../../../core/api-promise'; +import { PagePromise, TaskExecutionsPage, type TaskExecutionsPageParams } from '../../../../core/pagination'; import { RequestOptions } from '../../../../internal/request-options'; export class Executions extends APIResource { diff --git a/src/resources/environments/automations/tasks/tasks.ts b/src/resources/environments/automations/tasks/tasks.ts index a1e1b97..6a85c1f 100644 --- a/src/resources/environments/automations/tasks/tasks.ts +++ b/src/resources/environments/automations/tasks/tasks.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../../resource'; +import { APIResource } from '../../../../core/resource'; import * as Shared from '../../../shared'; import { TasksTasksPage } from '../../../shared'; import * as ExecutionsAPI from './executions'; @@ -12,8 +12,8 @@ import { ExecutionStopResponse, Executions, } from './executions'; -import { APIPromise } from '../../../../api-promise'; -import { PagePromise, TasksPage, type TasksPageParams } from '../../../../pagination'; +import { APIPromise } from '../../../../core/api-promise'; +import { PagePromise, TasksPage, type TasksPageParams } from '../../../../core/pagination'; import { RequestOptions } from '../../../../internal/request-options'; export class Tasks extends APIResource { diff --git a/src/resources/environments/classes.ts b/src/resources/environments/classes.ts index d1a03ee..709e8bc 100644 --- a/src/resources/environments/classes.ts +++ b/src/resources/environments/classes.ts @@ -1,10 +1,14 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as Shared from '../shared'; import { EnvironmentClassesEnvironmentClassesPage } from '../shared'; import * as RunnersAPI from '../runners/runners'; -import { EnvironmentClassesPage, type EnvironmentClassesPageParams, PagePromise } from '../../pagination'; +import { + EnvironmentClassesPage, + type EnvironmentClassesPageParams, + PagePromise, +} from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Classes extends APIResource { diff --git a/src/resources/environments/environments.ts b/src/resources/environments/environments.ts index ee1390b..2534b7f 100644 --- a/src/resources/environments/environments.ts +++ b/src/resources/environments/environments.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as EnvironmentsAPI from './environments'; import * as Shared from '../shared'; import * as ClassesAPI from './classes'; @@ -14,8 +14,8 @@ import { Automations, AutomationsFile as AutomationsAPIAutomationsFile, } from './automations/automations'; -import { APIPromise } from '../../api-promise'; -import { EnvironmentsPage, type EnvironmentsPageParams, PagePromise } from '../../pagination'; +import { APIPromise } from '../../core/api-promise'; +import { EnvironmentsPage, type EnvironmentsPageParams, PagePromise } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Environments extends APIResource { diff --git a/src/resources/events.ts b/src/resources/events.ts index 927e568..68a011a 100644 --- a/src/resources/events.ts +++ b/src/resources/events.ts @@ -1,10 +1,10 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; +import { APIResource } from '../core/resource'; import * as EventsAPI from './events'; import * as Shared from './shared'; -import { APIPromise } from '../api-promise'; -import { EntriesPage, type EntriesPageParams, PagePromise } from '../pagination'; +import { APIPromise } from '../core/api-promise'; +import { EntriesPage, type EntriesPageParams, PagePromise } from '../core/pagination'; import { buildHeaders } from '../internal/headers'; import { RequestOptions } from '../internal/request-options'; import { JSONLDecoder } from '../internal/decoders/jsonl'; diff --git a/src/resources/groups.ts b/src/resources/groups.ts index b67b15c..56384a4 100644 --- a/src/resources/groups.ts +++ b/src/resources/groups.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; -import { GroupsPage, type GroupsPageParams, PagePromise } from '../pagination'; +import { APIResource } from '../core/resource'; +import { GroupsPage, type GroupsPageParams, PagePromise } from '../core/pagination'; import { RequestOptions } from '../internal/request-options'; export class Groups extends APIResource { diff --git a/src/resources/identity.ts b/src/resources/identity.ts index 9bfb3fd..e351965 100644 --- a/src/resources/identity.ts +++ b/src/resources/identity.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; +import { APIResource } from '../core/resource'; import * as Shared from './shared'; -import { APIPromise } from '../api-promise'; +import { APIPromise } from '../core/api-promise'; import { RequestOptions } from '../internal/request-options'; export class Identity extends APIResource { diff --git a/src/resources/organizations/domain-verifications.ts b/src/resources/organizations/domain-verifications.ts index 8fcb6a9..51e3a9e 100644 --- a/src/resources/organizations/domain-verifications.ts +++ b/src/resources/organizations/domain-verifications.ts @@ -1,8 +1,12 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; -import { APIPromise } from '../../api-promise'; -import { DomainVerificationsPage, type DomainVerificationsPageParams, PagePromise } from '../../pagination'; +import { APIResource } from '../../core/resource'; +import { APIPromise } from '../../core/api-promise'; +import { + DomainVerificationsPage, + type DomainVerificationsPageParams, + PagePromise, +} from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class DomainVerifications extends APIResource { diff --git a/src/resources/organizations/invites.ts b/src/resources/organizations/invites.ts index b8f3540..5dded81 100644 --- a/src/resources/organizations/invites.ts +++ b/src/resources/organizations/invites.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; -import { APIPromise } from '../../api-promise'; +import { APIResource } from '../../core/resource'; +import { APIPromise } from '../../core/api-promise'; import { RequestOptions } from '../../internal/request-options'; export class Invites extends APIResource { diff --git a/src/resources/organizations/organizations.ts b/src/resources/organizations/organizations.ts index bdba148..b0b452d 100644 --- a/src/resources/organizations/organizations.ts +++ b/src/resources/organizations/organizations.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as Shared from '../shared'; import * as DomainVerificationsAPI from './domain-verifications'; import { @@ -46,14 +46,14 @@ import { SSOConfigurations, SSOConfigurationsSSOConfigurationsPage, } from './sso-configurations'; -import { APIPromise } from '../../api-promise'; +import { APIPromise } from '../../core/api-promise'; import { MembersPage, type MembersPageParams, OrganizationsPage, type OrganizationsPageParams, PagePromise, -} from '../../pagination'; +} from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Organizations extends APIResource { diff --git a/src/resources/organizations/sso-configurations.ts b/src/resources/organizations/sso-configurations.ts index 83e5205..a447375 100644 --- a/src/resources/organizations/sso-configurations.ts +++ b/src/resources/organizations/sso-configurations.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, SSOConfigurationsPage, type SSOConfigurationsPageParams } from '../../pagination'; +import { APIResource } from '../../core/resource'; +import { APIPromise } from '../../core/api-promise'; +import { PagePromise, SSOConfigurationsPage, type SSOConfigurationsPageParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class SSOConfigurations extends APIResource { diff --git a/src/resources/projects/policies.ts b/src/resources/projects/policies.ts index 07d3d09..ea39ec5 100644 --- a/src/resources/projects/policies.ts +++ b/src/resources/projects/policies.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, PoliciesPage, type PoliciesPageParams } from '../../pagination'; +import { APIResource } from '../../core/resource'; +import { APIPromise } from '../../core/api-promise'; +import { PagePromise, PoliciesPage, type PoliciesPageParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Policies extends APIResource { diff --git a/src/resources/projects/projects.ts b/src/resources/projects/projects.ts index 7ca91c8..3f3967a 100644 --- a/src/resources/projects/projects.ts +++ b/src/resources/projects/projects.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as Shared from '../shared'; import * as PoliciesAPI from './policies'; import { @@ -16,8 +16,8 @@ import { ProjectPolicy, ProjectRole, } from './policies'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, ProjectsPage, type ProjectsPageParams } from '../../pagination'; +import { APIPromise } from '../../core/api-promise'; +import { PagePromise, ProjectsPage, type ProjectsPageParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Projects extends APIResource { diff --git a/src/resources/runners/configurations/configurations.ts b/src/resources/runners/configurations/configurations.ts index 0213678..db30ece 100644 --- a/src/resources/runners/configurations/configurations.ts +++ b/src/resources/runners/configurations/configurations.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; +import { APIResource } from '../../../core/resource'; import * as Shared from '../../shared'; import * as EnvironmentClassesAPI from './environment-classes'; import { @@ -47,7 +47,7 @@ import { ScmIntegrations, ScmIntegrationsIntegrationsPage, } from './scm-integrations'; -import { APIPromise } from '../../../api-promise'; +import { APIPromise } from '../../../core/api-promise'; import { RequestOptions } from '../../../internal/request-options'; export class Configurations extends APIResource { diff --git a/src/resources/runners/configurations/environment-classes.ts b/src/resources/runners/configurations/environment-classes.ts index 9e70d73..1db7137 100644 --- a/src/resources/runners/configurations/environment-classes.ts +++ b/src/resources/runners/configurations/environment-classes.ts @@ -1,11 +1,15 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; +import { APIResource } from '../../../core/resource'; import * as Shared from '../../shared'; import { EnvironmentClassesEnvironmentClassesPage } from '../../shared'; import * as RunnersAPI from '../runners'; -import { APIPromise } from '../../../api-promise'; -import { EnvironmentClassesPage, type EnvironmentClassesPageParams, PagePromise } from '../../../pagination'; +import { APIPromise } from '../../../core/api-promise'; +import { + EnvironmentClassesPage, + type EnvironmentClassesPageParams, + PagePromise, +} from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; export class EnvironmentClasses extends APIResource { diff --git a/src/resources/runners/configurations/host-authentication-tokens.ts b/src/resources/runners/configurations/host-authentication-tokens.ts index 0b7240e..8196628 100644 --- a/src/resources/runners/configurations/host-authentication-tokens.ts +++ b/src/resources/runners/configurations/host-authentication-tokens.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; -import { APIPromise } from '../../../api-promise'; -import { PagePromise, TokensPage, type TokensPageParams } from '../../../pagination'; +import { APIResource } from '../../../core/resource'; +import { APIPromise } from '../../../core/api-promise'; +import { PagePromise, TokensPage, type TokensPageParams } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; export class HostAuthenticationTokens extends APIResource { diff --git a/src/resources/runners/configurations/schema.ts b/src/resources/runners/configurations/schema.ts index 137908c..a7885dd 100644 --- a/src/resources/runners/configurations/schema.ts +++ b/src/resources/runners/configurations/schema.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; -import { APIPromise } from '../../../api-promise'; +import { APIResource } from '../../../core/resource'; +import { APIPromise } from '../../../core/api-promise'; import { RequestOptions } from '../../../internal/request-options'; export class Schema extends APIResource { diff --git a/src/resources/runners/configurations/scm-integrations.ts b/src/resources/runners/configurations/scm-integrations.ts index d6dcc3f..ebdc52b 100644 --- a/src/resources/runners/configurations/scm-integrations.ts +++ b/src/resources/runners/configurations/scm-integrations.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../../resource'; -import { APIPromise } from '../../../api-promise'; -import { IntegrationsPage, type IntegrationsPageParams, PagePromise } from '../../../pagination'; +import { APIResource } from '../../../core/resource'; +import { APIPromise } from '../../../core/api-promise'; +import { IntegrationsPage, type IntegrationsPageParams, PagePromise } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; export class ScmIntegrations extends APIResource { diff --git a/src/resources/runners/policies.ts b/src/resources/runners/policies.ts index 4b71a77..0cdd4c1 100644 --- a/src/resources/runners/policies.ts +++ b/src/resources/runners/policies.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, PoliciesPage, type PoliciesPageParams } from '../../pagination'; +import { APIResource } from '../../core/resource'; +import { APIPromise } from '../../core/api-promise'; +import { PagePromise, PoliciesPage, type PoliciesPageParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Policies extends APIResource { diff --git a/src/resources/runners/runners.ts b/src/resources/runners/runners.ts index 4efa8a4..0925d50 100644 --- a/src/resources/runners/runners.ts +++ b/src/resources/runners/runners.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as RunnersAPI from './runners'; import * as Shared from '../shared'; import * as PoliciesAPI from './policies'; @@ -26,8 +26,8 @@ import { FieldValidationError, ScmIntegrationValidationResult, } from './configurations/configurations'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, RunnersPage, type RunnersPageParams } from '../../pagination'; +import { APIPromise } from '../../core/api-promise'; +import { PagePromise, RunnersPage, type RunnersPageParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Runners extends APIResource { diff --git a/src/resources/secrets.ts b/src/resources/secrets.ts index 845d02e..62ceb78 100644 --- a/src/resources/secrets.ts +++ b/src/resources/secrets.ts @@ -1,9 +1,9 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; +import { APIResource } from '../core/resource'; import * as Shared from './shared'; -import { APIPromise } from '../api-promise'; -import { PagePromise, SecretsPage, type SecretsPageParams } from '../pagination'; +import { APIPromise } from '../core/api-promise'; +import { PagePromise, SecretsPage, type SecretsPageParams } from '../core/pagination'; import { RequestOptions } from '../internal/request-options'; export class Secrets extends APIResource { diff --git a/src/resources/shared.ts b/src/resources/shared.ts index e6c63f1..b771f1d 100644 --- a/src/resources/shared.ts +++ b/src/resources/shared.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import * as Shared from './shared'; -import { EnvironmentClassesPage, TaskExecutionsPage, TasksPage } from '../pagination'; +import { EnvironmentClassesPage, TaskExecutionsPage, TasksPage } from '../core/pagination'; /** * An AutomationTrigger represents a trigger for an automation action. The diff --git a/src/resources/users/pats.ts b/src/resources/users/pats.ts index d8037ac..6827d68 100644 --- a/src/resources/users/pats.ts +++ b/src/resources/users/pats.ts @@ -1,9 +1,13 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as Shared from '../shared'; -import { APIPromise } from '../../api-promise'; -import { PagePromise, PersonalAccessTokensPage, type PersonalAccessTokensPageParams } from '../../pagination'; +import { APIPromise } from '../../core/api-promise'; +import { + PagePromise, + PersonalAccessTokensPage, + type PersonalAccessTokensPageParams, +} from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; export class Pats extends APIResource { diff --git a/src/resources/users/users.ts b/src/resources/users/users.ts index 63c3f75..4fb4bad 100644 --- a/src/resources/users/users.ts +++ b/src/resources/users/users.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../../resource'; +import { APIResource } from '../../core/resource'; import * as Shared from '../shared'; import * as PatsAPI from './pats'; import { @@ -13,7 +13,7 @@ import { PersonalAccessToken, PersonalAccessTokensPersonalAccessTokensPage, } from './pats'; -import { APIPromise } from '../../api-promise'; +import { APIPromise } from '../../core/api-promise'; import { RequestOptions } from '../../internal/request-options'; export class Users extends APIResource { diff --git a/src/uploads.ts b/src/uploads.ts index 79d3073..b2ef647 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -1,2 +1,2 @@ -export { type Uploadable } from './internal/uploads'; -export { toFile, type ToFileInput } from './internal/to-file'; +/** @deprecated Import from ./core/uploads instead */ +export * from './core/uploads'; diff --git a/tests/form.test.ts b/tests/form.test.ts index 1dd9656..cb575ba 100644 --- a/tests/form.test.ts +++ b/tests/form.test.ts @@ -1,5 +1,5 @@ import { multipartFormRequestOptions, createForm } from '@gitpod/sdk/internal/uploads'; -import { toFile } from '@gitpod/sdk/uploads'; +import { toFile } from '@gitpod/sdk/core/uploads'; describe('form data validation', () => { test('valid values do not error', async () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 24fd099..afe3fed 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,6 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIPromise } from '@gitpod/sdk/api-promise'; +import { APIPromise } from '@gitpod/sdk/core/api-promise'; import util from 'node:util'; import Gitpod from '@gitpod/sdk'; diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index 7b28bb5..d18eb6c 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -1,6 +1,6 @@ import fs from 'fs'; import type { ResponseLike } from '@gitpod/sdk/internal/to-file'; -import { toFile } from '@gitpod/sdk/uploads'; +import { toFile } from '@gitpod/sdk/core/uploads'; import { File } from 'node:buffer'; class MyClass { @@ -97,7 +97,7 @@ describe('missing File error message', () => { }); test('is thrown', async () => { - const uploads = await import('@gitpod/sdk/uploads'); + const uploads = await import('@gitpod/sdk/core/uploads'); await expect( uploads.toFile(mockResponse({ url: 'https://example.com/my/audio.mp3' })), ).rejects.toMatchInlineSnapshot(