@onyx.dev/onyx-database 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -2
- package/dist/aggregates-BGXzij4U.d.cts +1424 -0
- package/dist/aggregates-BGXzij4U.d.ts +1424 -0
- package/dist/edge.cjs +1954 -0
- package/dist/edge.cjs.map +1 -0
- package/dist/edge.d.cts +9 -0
- package/dist/edge.d.ts +9 -0
- package/dist/edge.js +1911 -0
- package/dist/edge.js.map +1 -0
- package/dist/gen/cli/generate.cjs +303 -56
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +303 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1325
- package/dist/index.d.ts +3 -1325
- package/dist/index.js +303 -55
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +473 -267
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +22 -5
package/README.md
CHANGED
|
@@ -13,6 +13,25 @@ TypeScript client SDK for **Onyx Cloud Database** — a zero-dependency, strict-
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
+
## Table of contents
|
|
17
|
+
|
|
18
|
+
- [Getting started](#getting-started-cloud--keys--connect)
|
|
19
|
+
- [Install](#install)
|
|
20
|
+
- [Initialize the client](#initialize-the-client)
|
|
21
|
+
- [Generate schema types](#optional-generate-typescript-types-from-your-schema)
|
|
22
|
+
- [Query helpers](#query-helpers-at-a-glance)
|
|
23
|
+
- [Examples](#usage-examples-with-user-role-permission)
|
|
24
|
+
- [Error handling](#error-handling)
|
|
25
|
+
- [HTTP retries](#http-retries)
|
|
26
|
+
- [Onyx CLI](#onyx-cli)
|
|
27
|
+
- [Runtime & bundlers](#runtime--bundlers)
|
|
28
|
+
- [Release workflow](#release-workflow)
|
|
29
|
+
- [Related links](#related-links)
|
|
30
|
+
- [Security](#security)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
16
35
|
## Getting started (Cloud ➜ keys ➜ connect)
|
|
17
36
|
|
|
18
37
|
1. **Sign up & create resources** at **<https://cloud.onyx.dev>**
|
|
@@ -42,6 +61,22 @@ npm i @onyx.dev/onyx-database
|
|
|
42
61
|
|
|
43
62
|
The package is dual-module (ESM + CJS) and has **no runtime or peer dependencies**.
|
|
44
63
|
|
|
64
|
+
To use the bundled CLIs (`onyx-gen` and `onyx-schema`) globally:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install -g @onyx.dev/onyx-database
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
To install the CLI globally from this repo checkout (useful for local development and testing):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# run from the repo root
|
|
74
|
+
npm install
|
|
75
|
+
npm run build
|
|
76
|
+
npm uninstall -g @onyx.dev/onyx-database # optional: clear older global versions
|
|
77
|
+
npm install -g . # installs the built onyx-schema and onyx-gen
|
|
78
|
+
```
|
|
79
|
+
|
|
45
80
|
---
|
|
46
81
|
|
|
47
82
|
## Initialize the client
|
|
@@ -100,6 +135,37 @@ Set `ONYX_CONFIG_PATH` to a JSON file containing your credentials. This file is
|
|
|
100
135
|
|
|
101
136
|
These files are ignored in non-Node runtimes like Cloudflare Workers.
|
|
102
137
|
|
|
138
|
+
### Edge / RSC usage (Next.js, Cloudflare Workers)
|
|
139
|
+
|
|
140
|
+
For edge runtimes (Next.js Edge/RSC, Cloudflare Workers), import the edge entry. It avoids Node-only imports and only resolves credentials from environment variables or explicit config.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { onyx } from '@onyx.dev/onyx-database/edge';
|
|
144
|
+
|
|
145
|
+
const db = onyx.init(); // uses env vars in edge runtimes
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
File-based config (`ONYX_CONFIG_PATH`, project files, home profiles) is not available in edge runtimes. If you need file-based config, use the Node entry instead.
|
|
149
|
+
|
|
150
|
+
**Cloudflare Worker example:**
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { onyx } from '@onyx.dev/onyx-database/edge';
|
|
154
|
+
|
|
155
|
+
export default {
|
|
156
|
+
async fetch(_request: Request, env: Record<string, string>) {
|
|
157
|
+
const db = onyx.init({
|
|
158
|
+
baseUrl: env.ONYX_DATABASE_BASE_URL,
|
|
159
|
+
databaseId: env.ONYX_DATABASE_ID,
|
|
160
|
+
apiKey: env.ONYX_DATABASE_API_KEY,
|
|
161
|
+
apiSecret: env.ONYX_DATABASE_API_SECRET,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return Response.json({ ok: true });
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
103
169
|
### Connection handling
|
|
104
170
|
|
|
105
171
|
Calling `onyx.init()` returns a lightweight client. Configuration is resolved once
|
|
@@ -148,6 +214,9 @@ onyx-schema publish
|
|
|
148
214
|
# Overwrite ./onyx.schema.json with the remote schema
|
|
149
215
|
onyx-schema get
|
|
150
216
|
|
|
217
|
+
# Print the remote schema without writing a file
|
|
218
|
+
onyx-schema get --print
|
|
219
|
+
|
|
151
220
|
# Fetch only selected tables (prints to stdout; does not overwrite files)
|
|
152
221
|
onyx-schema get --tables=User,Profile
|
|
153
222
|
|
|
@@ -177,7 +246,7 @@ onyx-schema validate ./onyx.schema.json
|
|
|
177
246
|
|
|
178
247
|
# Diff local schema vs API
|
|
179
248
|
onyx-schema diff ./onyx.schema.json
|
|
180
|
-
# Prints added/removed/changed tables and attribute differences between the API schema and your local file.
|
|
249
|
+
# Prints YAML with added/removed/changed tables and attribute differences between the API schema and your local file.
|
|
181
250
|
```
|
|
182
251
|
|
|
183
252
|
When `--tables` is provided, the subset is printed to stdout instead of writing a
|
|
@@ -194,6 +263,16 @@ npm run schema:publish # validate then publish the local schema
|
|
|
194
263
|
The CLI reuses the same configuration resolution as `onyx.init()` (env vars,
|
|
195
264
|
project config, and home profile files).
|
|
196
265
|
|
|
266
|
+
Programmatic diffing is also available:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { onyx } from '@onyx.dev/onyx-database';
|
|
270
|
+
|
|
271
|
+
const db = onyx.init();
|
|
272
|
+
const diff = await db.diffSchema(localSchema); // SchemaUpsertRequest
|
|
273
|
+
console.log(diff.changedTables);
|
|
274
|
+
```
|
|
275
|
+
|
|
197
276
|
You can also emit to multiple paths in one run (comma-separated or by repeating `--out`):
|
|
198
277
|
|
|
199
278
|
```bash
|
|
@@ -636,7 +715,60 @@ try {
|
|
|
636
715
|
}
|
|
637
716
|
```
|
|
638
717
|
|
|
639
|
-
|
|
718
|
+
## HTTP retries
|
|
719
|
+
|
|
720
|
+
- GET requests retry automatically with Fibonacci backoff (300ms base) up to 3 times by default; mutations are never retried.
|
|
721
|
+
- Disable or tune via `retry` on `onyx.init`:
|
|
722
|
+
|
|
723
|
+
```ts
|
|
724
|
+
const db = onyx.init({
|
|
725
|
+
retry: {
|
|
726
|
+
enabled: true, // default
|
|
727
|
+
maxRetries: 2, // default 3
|
|
728
|
+
initialDelayMs: 500, // default 300
|
|
729
|
+
},
|
|
730
|
+
});
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
## Onyx CLI
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
```
|
|
737
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
738
|
+
| Command | Flags | Defaults / notes |
|
|
739
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
740
|
+
| onyx-gen | --source auto|api|file | Default: --source file; --schema ./onyx.schema.json; |
|
|
741
|
+
| | --schema <path> | --out ./onyx/types.ts (file or dir; repeatable; dir uses |
|
|
742
|
+
| | --out / --types-out / --types-file <dir|file> | --base onyx.schema); timestamps default: date; optional |
|
|
743
|
+
| | --base / --baseName <name> | strategy default: non-null; schema type name: OnyxSchema; |
|
|
744
|
+
| | --timestamps string|date|number | emit-json disabled by default; --overwrite enabled; quiet=false. |
|
|
745
|
+
| | --name / --schemaTypeName <T> | --api-path repeatable; --json-out derived from TS output. |
|
|
746
|
+
| | --prefix <Prefix> | |
|
|
747
|
+
| | --optional non-null|nullable|none | |
|
|
748
|
+
| | --emit-json / --no-emit-json | |
|
|
749
|
+
| | --json-out <dir> | |
|
|
750
|
+
| | --api-path <path> (repeatable) | |
|
|
751
|
+
| | --overwrite / --no-overwrite | |
|
|
752
|
+
| | -q / --quiet | |
|
|
753
|
+
| | -h / --help | |
|
|
754
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
755
|
+
| onyx-schema get | [file] (positional) | Default file: ./onyx.schema.json; writes file unless |
|
|
756
|
+
| | --tables a,b | --tables or --print (then prints to stdout). |
|
|
757
|
+
| | --print | |
|
|
758
|
+
| | -h / --help | |
|
|
759
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
760
|
+
| onyx-schema publish | [file] (positional) | Default file: ./onyx.schema.json; validates before publishing; |
|
|
761
|
+
| | -h / --help | uses onyx.init credential resolver. |
|
|
762
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
763
|
+
| onyx-schema validate | [file] (positional) | Default file: ./onyx.schema.json; exits non-zero on errors. |
|
|
764
|
+
| | -h / --help | |
|
|
765
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
766
|
+
| onyx-schema diff | [file] (positional) | Default file: ./onyx.schema.json; prints YAML diff vs API. |
|
|
767
|
+
| | -h / --help | |
|
|
768
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
769
|
+
| onyx-schema info | -h / --help | Shows resolved config sources, config path, connection check.|
|
|
770
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
771
|
+
```
|
|
640
772
|
|
|
641
773
|
## Runtime & bundlers
|
|
642
774
|
|