Socket
Book a DemoInstallSign in
Socket

neon-sdk

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neon-sdk

TypeScript SDK for managing your Neon Serverless PostgreSQL projects

Source
npmnpm
Version
2.0.0-beta.9
Version published
Weekly downloads
244
29.1%
Maintainers
1
Weekly downloads
 
Created
Source

neon-sdk

CI NPM Version JSR Version

Fully-typed, zero-dependency Node.js and Deno SDK for managing your Neon Serverless Postgres projects.

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

Usage

Node.js

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

    npm i neon-sdk
    
  • Initialize the client with your Neon API token.

    import { NeonClient } from 'neon-sdk';
    
    const neonClient = new NeonClient({
        TOKEN: '<INSERT NEON API KEY HERE>',
    });
    
    (async () => {
        const projects = await neonClient.project.listProjects();
        console.log(projects);
    })()
    

Deno

  • Add the neon-sdk package from JSR.

    deno add @httgp/neon-sdk
    
  • Now import the module and initialize the client with your Neon API token.

    import { NeonClient } from "@httgp/neon-sdk";
    
    const neonClient = new NeonClient({
        TOKEN: "<INSERT NEON API KEY HERE>",
    });
    const projects = await neonClient.project.listProjects();
    console.log(projects);
    

    Make sure to allow net permissions to console.neon.tech for the code to run.

    deno run --allow-net=console.neon.tech neon.ts
    
  • Alternatively, the neon-sdk package is also available from npm, which can be used with the npm: specifier.

    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 –

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 using @hey-api/openapi-ts.

Keywords

neon

FAQs

Package last updated on 08 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts