-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,100 @@ | ||
# bun starter | ||
# UndbSDK | ||
|
||
## Getting Started | ||
UndbSDK is a TypeScript SDK for interacting with the Undb API. It provides authentication services, base services, and an OpenAPI client. | ||
|
||
Click the [Use this template](https://github.com/wobsoriano/bun-lib-starter/generate) button to create a new repository with the contents starter. | ||
## Installation | ||
|
||
OR | ||
Install UndbSDK using npm: | ||
|
||
Run `bun create wobsoriano/bun-lib-starter ./my-lib`. | ||
```bash | ||
npm install @undb/js-sdk | ||
# or | ||
yarn add @undb/js-sdk | ||
# or | ||
pnpm add @undb/js-sdk | ||
# or | ||
bun add @undb/js-sdk | ||
``` | ||
|
||
## Setup | ||
## Usage | ||
|
||
```bash | ||
# install dependencies | ||
bun install | ||
Import and use UndbSDK in your project: | ||
|
||
```typescript | ||
import { UndbSDK } from '@undb/js-sdk' | ||
|
||
const sdk = new UndbSDK({ | ||
baseURL: 'http://localhost:3721/openapi', // https://app.undb.io/openapi if you are using the hosted version | ||
fetch: fetch, // Optional, use a custom fetch function | ||
}) | ||
|
||
sdk.auth.setToken('secret') | ||
|
||
const client = sdk.getOpenapiClient<paths>() | ||
|
||
const res = await client.GET('/bases/templates/tables/templates/records') | ||
``` | ||
|
||
### Authentication | ||
|
||
Access the authentication service using the `auth` property: | ||
|
||
#### Set token | ||
|
||
```typescript | ||
sdk.auth.setToken('secret') | ||
``` | ||
|
||
### Usage with Base & Table names | ||
|
||
Get a `BaseService` instance using the `base` method: | ||
|
||
# test the app | ||
bun test | ||
```typescript | ||
const baseName = 'your-base-name' | ||
const baseService = sdk.base(baseName) | ||
// Access a specific table | ||
const tableService = baseService.table('your-table-name') | ||
|
||
# build the app, available under dist | ||
bun run build | ||
// Get records | ||
const records = await tableService.getRecords() | ||
// Create a record | ||
const newRecord = await tableService.createRecord({ values: { / your field values / } }) | ||
// Update a record | ||
const updatedRecord = await tableService.updateRecord('record-id', { values: { / updated field values / } }) | ||
// Delete a record | ||
await tableService.deleteRecord('record-id') | ||
``` | ||
|
||
#### Access a specific view | ||
|
||
```typescript | ||
const viewService = baseService.table('your-table-name', 'your-view-name') | ||
|
||
// Get records | ||
const records = await viewService.getRecords() | ||
``` | ||
|
||
### Usage with OpenAPI Client | ||
|
||
Get a `OpenApiClient` instance using the `getOpenapiClient` method: | ||
|
||
```typescript | ||
const client = sdk.getOpenapiClient<paths>() | ||
|
||
const res = await client.GET('/bases/templates/tables/templates/records') | ||
``` | ||
|
||
#### Generate OpenAPI types from undb | ||
|
||
TODO | ||
|
||
### Development | ||
|
||
```bash | ||
bun install | ||
bun run test:watch | ||
``` | ||
|
||
## License | ||
### License | ||
|
||
MIT | ||
[MIT](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters