Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(core): migrate to @hey-api/openapi-ts #63

Merged
merged 26 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9ac0f0a
core: migrate to @hey-api/openapi-ts
paambaati Apr 26, 2024
db4587a
chore: allow less scrict pnpm versions
paambaati Apr 26, 2024
0bfe8f9
Merge branch 'main' into gp/open-ts-migration
paambaati Apr 26, 2024
a4ee6aa
chore(docs): update generator package
paambaati May 7, 2024
4706718
chore: upgrade to latest package version
paambaati May 7, 2024
c029032
Merge branch 'main' into gp/open-ts-migration
paambaati May 7, 2024
fc9a4f3
chore(ci): upgrade pnpm/action-setup to v4.
paambaati May 7, 2024
f715e49
chore: upgrade package versions to latest
paambaati May 16, 2024
9e971f2
chore: regenerate types
paambaati May 16, 2024
f8fe840
chore: regenerate after package upgrade
paambaati May 21, 2024
fa24772
chore(fix): reorganize openapi-ts configuration and regenerate
paambaati May 23, 2024
e709690
chore: add some example code
paambaati May 23, 2024
8edaf93
fix: make sure NeonClient is generated
paambaati May 23, 2024
157b7b8
chore: package upgrade
paambaati May 23, 2024
b37442f
chore(ci): split codegen and build into 2 steps in CI
paambaati May 23, 2024
26baab2
fix: fix publint warning
paambaati May 24, 2024
b1789fa
ci: turn on strict mode for publint
paambaati May 24, 2024
4c9bddb
chore: upgrade packages
paambaati May 24, 2024
c00e273
chore: upgrade @hey-api/openapi-ts and regenerate
paambaati May 28, 2024
5ad7e51
chore: routine dep upgrades
paambaati Jun 3, 2024
324eaaf
Merge remote-tracking branch 'origin/main' into gp/open-ts-migration
paambaati Jun 3, 2024
53b05ba
chore(deps): routine upgrade
paambaati Jun 6, 2024
5d8b663
chore: upgrade to pnpm 9.3.x
paambaati Jun 13, 2024
f5d0d58
chore(ci): support beta releases
paambaati Jun 13, 2024
f1f8ed9
chore(ci): allow release workflows for beta branch
paambaati Jun 13, 2024
c5cbdae
chore: regenerate bindings
paambaati Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_PERSONAL_TOKEN }}

- name: setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
uses: pnpm/action-setup@v4

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -32,16 +30,14 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Check lock file for untrusted packages
run: pnpm dlx lockfile-lint --path package-lock.json --allowed-hosts npm --validate-https
- name: Generate OpenAPI bindings
run: pnpm run generate

- name: Generate OpenAPI bindings and build package
run: |
pnpm run generate
pnpm run build
- name: Type-check and build package
run: pnpm run build

- name: Check package for packaging errors
run: pnpm dlx publint run
run: pnpm dlx publint run --strict

- name: Check for uncommitted changes
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/refresh-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
fetch-depth: 0

- name: setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
uses: pnpm/action-setup@v4

- name: Set up Node.js
uses: actions/setup-node@v4
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/release+publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- beta
tags:
- '!*'

Expand All @@ -22,9 +23,7 @@ jobs:
token: ${{ secrets.CUSTOM_GITHUB_PERSONAL_TOKEN }}

- name: setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
uses: pnpm/action-setup@v4

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -36,9 +35,6 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Check lock file for untrusted packages
run: pnpm dlx lockfile-lint --path package-lock.json --allowed-hosts npm --validate-https

- name: Build package
run: pnpm run build

Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
save-exact=true
fund=false
package-manager-strict=false
6 changes: 5 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"branches": [
"main"
"main",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

Fully-typed, zero-dependency Node.js and Deno SDK for managing your [Neon](https://neon.tech/) Serverless Postgres projects.

> **Note**

> [!NOTE]
> Neon is a fully managed serverless PostgreSQL with a generous free tier. Neon separates storage and compute and offers modern developer features such as serverless, branching, bottomless storage, and more. Neon is open source and written in Rust.
>
> [Learn more about Neon](https://neon.tech/docs/introduction/about)

> [!IMPORTANT]
> Note that you're reading the documentation for v2.x of this package. If you're still using the legacy v1.x version, see the [v1.x documentation](https://github.com/paambaati/neon-js-sdk/blob/v1.21.0/README.md#usage).

## Usage

**Node.js (>= v18.x)**
Expand Down Expand Up @@ -68,6 +70,32 @@ node --experimental-fetch app.js
deno run --allow-net=console.neon.tech neon.ts
```

## Recipes

All API responses are typed as a union of the specific API's successful response and `GeneralError`. To narrow this type down –

```typescript
import { NeonClient, type GeneralError } from 'neon-sdk';

function isNeonError(neonResponse: unknown): neonResponse is GeneralError {
const allowedKeys = ['code', 'message'].sort();
const foundKeys = Object.getOwnPropertyNames(neonResponse || {}).sort();
return foundKeys.length === allowedKeys.length
&& foundKeys.every((value, index) => value === allowedKeys[index])
&& (neonResponse as GeneralError).code !== undefined
&& (neonResponse as GeneralError).message !== undefined;
}

const neonClient = new NeonClient({
TOKEN: "<INSERT NEON API KEY HERE>",
});
const response = await neonClient.project.listProjects();

if (!isNeonError(response)) {
// Correctly typed as `ProjectsResponse`
response
}
```
## Developer Notes

This package is auto-generated from [Neon's OpenAPI reference](https://neon.tech/api-reference/v2/) using [`openapi-typescript-codegen`](https://www.npmjs.com/package/openapi-typescript-codegen).
This package is auto-generated from [Neon's OpenAPI reference](https://neon.tech/api-reference/v2/) using [`@hey-api/openapi-ts`](https://github.com/hey-api/openapi-ts).
90 changes: 50 additions & 40 deletions generated/NeonClient.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { BaseHttpRequest } from './core/BaseHttpRequest';
import type { OpenAPIConfig } from './core/OpenAPI';
import { Interceptors } from './core/OpenAPI';
import { FetchHttpRequest } from './core/FetchHttpRequest';
import { ApiKeyService } from './services/ApiKeyService';
import { BranchService } from './services/BranchService';
import { ConsumptionService } from './services/ConsumptionService';
import { EndpointService } from './services/EndpointService';
import { OperationService } from './services/OperationService';
import { ProjectService } from './services/ProjectService';
import { UsersService } from './services/UsersService';

import { ApiKeyService } from './services.gen';
import { BranchService } from './services.gen';
import { ConsumptionService } from './services.gen';
import { DefaultService } from './services.gen';
import { EndpointService } from './services.gen';
import { OperationService } from './services.gen';
import { ProjectService } from './services.gen';
import { UsersService } from './services.gen';

type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;

export class NeonClient {
public readonly apiKey: ApiKeyService;
public readonly branch: BranchService;
public readonly consumption: ConsumptionService;
public readonly endpoint: EndpointService;
public readonly operation: OperationService;
public readonly project: ProjectService;
public readonly users: UsersService;
public readonly request: BaseHttpRequest;
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
this.request = new HttpRequest({
BASE: config?.BASE ?? 'https://console.neon.tech/api/v2',
VERSION: config?.VERSION ?? '2',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
});
this.apiKey = new ApiKeyService(this.request);
this.branch = new BranchService(this.request);
this.consumption = new ConsumptionService(this.request);
this.endpoint = new EndpointService(this.request);
this.operation = new OperationService(this.request);
this.project = new ProjectService(this.request);
this.users = new UsersService(this.request);
}
}

public readonly apiKey: ApiKeyService;
public readonly branch: BranchService;
public readonly consumption: ConsumptionService;
public readonly default: DefaultService;
public readonly endpoint: EndpointService;
public readonly operation: OperationService;
public readonly project: ProjectService;
public readonly users: UsersService;

public readonly request: BaseHttpRequest;

constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
this.request = new HttpRequest({
BASE: config?.BASE ?? 'https://console.neon.tech/api/v2',
VERSION: config?.VERSION ?? '2',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
interceptors: {
request: config?.interceptors?.request ?? new Interceptors(),
response: config?.interceptors?.response ?? new Interceptors(),
},
});

this.apiKey = new ApiKeyService(this.request);
this.branch = new BranchService(this.request);
this.consumption = new ConsumptionService(this.request);
this.default = new DefaultService(this.request);
this.endpoint = new EndpointService(this.request);
this.operation = new OperationService(this.request);
this.project = new ProjectService(this.request);
this.users = new UsersService(this.request);
}
}
34 changes: 15 additions & 19 deletions generated/core/ApiError.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { ApiResult } from './ApiResult';

export class ApiError extends Error {
public readonly url: string;
public readonly status: number;
public readonly statusText: string;
public readonly body: any;
public readonly request: ApiRequestOptions;
public readonly url: string;
public readonly status: number;
public readonly statusText: string;
public readonly body: unknown;
public readonly request: ApiRequestOptions;

constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
super(message);
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
super(message);

this.name = 'ApiError';
this.url = response.url;
this.status = response.status;
this.statusText = response.statusText;
this.body = response.body;
this.request = request;
}
}
this.name = 'ApiError';
this.url = response.url;
this.status = response.status;
this.statusText = response.statusText;
this.body = response.body;
this.request = request;
}
}
28 changes: 12 additions & 16 deletions generated/core/ApiRequestOptions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiRequestOptions = {
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
readonly url: string;
readonly path?: Record<string, any>;
readonly cookies?: Record<string, any>;
readonly headers?: Record<string, any>;
readonly query?: Record<string, any>;
readonly formData?: Record<string, any>;
readonly body?: any;
readonly mediaType?: string;
readonly responseHeader?: string;
readonly errors?: Record<number, string>;
};
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
readonly url: string;
readonly path?: Record<string, unknown>;
readonly cookies?: Record<string, unknown>;
readonly headers?: Record<string, unknown>;
readonly query?: Record<string, unknown>;
readonly formData?: Record<string, unknown>;
readonly body?: any;
readonly mediaType?: string;
readonly responseHeader?: string;
readonly errors?: Record<number | string, string>;
};
18 changes: 7 additions & 11 deletions generated/core/ApiResult.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type ApiResult = {
readonly url: string;
readonly ok: boolean;
readonly status: number;
readonly statusText: string;
readonly body: any;
};
export type ApiResult<TData = any> = {
readonly body: TData;
readonly ok: boolean;
readonly status: number;
readonly statusText: string;
readonly url: string;
};
10 changes: 3 additions & 7 deletions generated/core/BaseHttpRequest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ApiRequestOptions } from './ApiRequestOptions';
import type { CancelablePromise } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';

export abstract class BaseHttpRequest {

constructor(public readonly config: OpenAPIConfig) {}
constructor(public readonly config: OpenAPIConfig) {}

public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
}
public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
}
Loading