Skip to content

Commit

Permalink
feat(internal): JSR support ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
paambaati authored Jul 23, 2024
2 parents 12f4d63 + 8c1ba1b commit 8744bec
Show file tree
Hide file tree
Showing 12 changed files with 1,398 additions and 509 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ jobs:
- name: Generate OpenAPI bindings
run: pnpm run generate

- name: Run JSR fixes
run: pnpm run jsr:fix

- name: Type-check and build package
run: pnpm run build

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

- name: Check JSR package for packaging/publishing errors
run: pnpm dlx jsr publish --dry-run --allow-dirty

- name: Check for uncommitted changes
# NOTE: Do not run this step for Dependabot PRs, because `pnpm run generate` might generate newer bindings (in case Neon's OpenAPI spec has had updates)
# which in turn will flag a "found changed files after build" error, which turns CI red.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependencies') }}
if: "!contains(github.event.pull_request.labels.*.name, 'dependencies')"
# NOTE: Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
run: |
git diff --exit-code --stat -- . ':!node_modules' ':!dist' \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/refresh-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- name: Generate OpenAPI bindings
run: |
pnpm run generate
pnpm run jsr:fix
- name: Create pull request with changes
uses: peter-evans/create-pull-request@v5
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release+publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ jobs:
- name: Build package
run: pnpm run build

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

- name: Make a release on NPM and GitHub
- name: Check JSR package for packaging/publishing errors
run: pnpm dlx jsr publish --dry-run

- name: Make a release on npm, JSR and GitHub
run: pnpm dlx semantic-release
env:
NPM_CONFIG_USERCONFIG: '/dev/null' # Ignore local .npmrc as semantic-release will use ONLY THAT if it finds one, leading to npm auth not working.
Expand Down
1 change: 1 addition & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"changelogFile": "CHANGELOG.md"
}
],
"@sebbo2002/semantic-release-jsr",
"@semantic-release/npm",
[
"@semantic-release/git",
Expand Down
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

![CI](https://github.com/paambaati/neon-js-sdk/actions/workflows/ci.yml/badge.svg)
[![NPM Version](https://img.shields.io/npm/v/neon-sdk.svg?logo=npm)](https://www.npmjs.com/package/neon-sdk)
![JSR Version](https://img.shields.io/jsr/v/%40httgp/neon-sdk)

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.22.1/README.md#usage).
## Usage

**Node.js**
### Node.js

1. Install `neon-sdk` as a dependency using the package manager of your choice.

Expand All @@ -38,13 +37,18 @@ Fully-typed, zero-dependency Node.js and Deno SDK for managing your [Neon](https
})()
```
**Deno (>= v1.28.x)**
### Deno
1. Add the `neon-sdk` package from JSR.
1. Simply import the `neon-sdk` from npm using the [`npm:` specifier](https://deno.land/[email protected]/node/npm_specifiers) and initialize the client with your [Neon API token](https://neon.tech/docs/manage/api-keys#manage-api-keys-with-the-neon-api).
```bash
deno add @httgp/neon-sdk
```
2. Now import the module and initialize the client with your [Neon API token](https://neon.tech/docs/manage/api-keys#manage-api-keys-with-the-neon-api).
```typescript
// neon.ts
import { NeonClient } from "npm:neon-sdk";
import { NeonClient } from "@httgp/neon-sdk";
const neonClient = new NeonClient({
TOKEN: "<INSERT NEON API KEY HERE>",
Expand All @@ -59,6 +63,18 @@ Fully-typed, zero-dependency Node.js and Deno SDK for managing your [Neon](https
deno run --allow-net=console.neon.tech neon.ts
```
2. Alternatively, the `neon-sdk` package is also available from npm, which can be used with the [`npm:` specifier](https://deno.land/[email protected]/node/npm_specifiers).
```typescript
import { NeonClient } from "npm:neon-sdk";
const neonClient = new NeonClient({
TOKEN: "<INSERT NEON API KEY HERE>",
});
const projects = await neonClient.project.listProjects();
console.log(projects);
```
## Recipes
All API responses are typed as a union of the specific API's successful response and `GeneralError`. To narrow this type down –
Expand All @@ -76,7 +92,7 @@ function isNeonError(neonResponse: unknown): neonResponse is GeneralError {
}
const neonClient = new NeonClient({
TOKEN: "<INSERT NEON API KEY HERE>",
TOKEN: '<INSERT NEON API KEY HERE>',
});
const response = await neonClient.project.listProjects();
Expand Down
7 changes: 5 additions & 2 deletions generated/core/CancelablePromise.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* This file was modified by a custom transform to make it ready to publish to JSR - see https://github.com/paambaati/neon-js-sdk/blob/main/scripts/transformers/jsr-fixes.ts
*/
export class CancelError extends Error {
constructor(message: string) {
super(message);
Expand Down Expand Up @@ -80,7 +83,7 @@ export class CancelablePromise<T> implements Promise<T> {
});
}

get [Symbol.toStringTag]() {
get [Symbol.toStringTag](): string {
return "Cancellable Promise";
}

Expand Down Expand Up @@ -123,4 +126,4 @@ export class CancelablePromise<T> implements Promise<T> {
public get isCancelled(): boolean {
return this._isCancelled;
}
}
}
Loading

0 comments on commit 8744bec

Please sign in to comment.