@onyx.dev/onyx-database 1.0.2 → 1.1.0
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 +137 -2
- package/dist/aggregates-DodZNu9-.d.cts +1453 -0
- package/dist/aggregates-DodZNu9-.d.ts +1453 -0
- package/dist/edge.cjs +1976 -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 +1932 -0
- package/dist/edge.js.map +1 -0
- package/dist/gen/cli/generate.cjs +94 -41
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +100 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1407
- package/dist/index.d.ts +3 -1407
- package/dist/index.js +100 -41
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +94 -40
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +22 -5
package/README.md
CHANGED
|
@@ -13,6 +13,26 @@ 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
|
+
- [Full-text search](#full-text-search-lucene)
|
|
24
|
+
- [Examples](#usage-examples-with-user-role-permission)
|
|
25
|
+
- [Error handling](#error-handling)
|
|
26
|
+
- [HTTP retries](#http-retries)
|
|
27
|
+
- [Onyx CLI](#onyx-cli)
|
|
28
|
+
- [Runtime & bundlers](#runtime--bundlers)
|
|
29
|
+
- [Release workflow](#release-workflow)
|
|
30
|
+
- [Related links](#related-links)
|
|
31
|
+
- [Security](#security)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
16
36
|
## Getting started (Cloud ➜ keys ➜ connect)
|
|
17
37
|
|
|
18
38
|
1. **Sign up & create resources** at **<https://cloud.onyx.dev>**
|
|
@@ -116,6 +136,37 @@ Set `ONYX_CONFIG_PATH` to a JSON file containing your credentials. This file is
|
|
|
116
136
|
|
|
117
137
|
These files are ignored in non-Node runtimes like Cloudflare Workers.
|
|
118
138
|
|
|
139
|
+
### Edge / RSC usage (Next.js, Cloudflare Workers)
|
|
140
|
+
|
|
141
|
+
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.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { onyx } from '@onyx.dev/onyx-database/edge';
|
|
145
|
+
|
|
146
|
+
const db = onyx.init(); // uses env vars in edge runtimes
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
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.
|
|
150
|
+
|
|
151
|
+
**Cloudflare Worker example:**
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { onyx } from '@onyx.dev/onyx-database/edge';
|
|
155
|
+
|
|
156
|
+
export default {
|
|
157
|
+
async fetch(_request: Request, env: Record<string, string>) {
|
|
158
|
+
const db = onyx.init({
|
|
159
|
+
baseUrl: env.ONYX_DATABASE_BASE_URL,
|
|
160
|
+
databaseId: env.ONYX_DATABASE_ID,
|
|
161
|
+
apiKey: env.ONYX_DATABASE_API_KEY,
|
|
162
|
+
apiSecret: env.ONYX_DATABASE_API_SECRET,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return Response.json({ ok: true });
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
119
170
|
### Connection handling
|
|
120
171
|
|
|
121
172
|
Calling `onyx.init()` returns a lightweight client. Configuration is resolved once
|
|
@@ -360,7 +411,7 @@ import {
|
|
|
360
411
|
between,
|
|
361
412
|
gt, gte, lt, lte,
|
|
362
413
|
like, notLike, contains, notContains,
|
|
363
|
-
startsWith, notStartsWith, matches, notMatches,
|
|
414
|
+
startsWith, notStartsWith, matches, notMatches, search,
|
|
364
415
|
isNull, notNull,
|
|
365
416
|
asc, desc
|
|
366
417
|
} from '@onyx.dev/onyx-database';
|
|
@@ -368,6 +419,7 @@ import {
|
|
|
368
419
|
|
|
369
420
|
- Prefer `within`/`notWithin` for inclusion checks (supports arrays, comma-separated strings, or inner queries).
|
|
370
421
|
- `inOp`/`notIn` remain available for backward compatibility and are exact aliases.
|
|
422
|
+
- `search(text, minScore?)` builds a Lucene `MATCHES` predicate on `__full_text__` and always serializes `minScore` (null when omitted).
|
|
371
423
|
|
|
372
424
|
### Inner queries (IN/NOT IN with sub-selects)
|
|
373
425
|
|
|
@@ -403,6 +455,36 @@ const rolesMissingPermission = await db
|
|
|
403
455
|
|
|
404
456
|
---
|
|
405
457
|
|
|
458
|
+
## Full-text search (Lucene)
|
|
459
|
+
|
|
460
|
+
Use `.search(text, minScore?)` on a query builder for table-level full-text search, or call `db.search(...)` to target **all** tables (`table = "ALL"` in the request body). The search value always includes `minScore` and falls back to `null` when you omit it.
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
import { desc, eq, onyx, search, tables, type Schema } from '@onyx.dev/onyx-database';
|
|
464
|
+
|
|
465
|
+
const db = onyx.init<Schema>();
|
|
466
|
+
|
|
467
|
+
// Table-specific search with a minimum score
|
|
468
|
+
const recentUsers = await db
|
|
469
|
+
.from(tables.User)
|
|
470
|
+
.search('user bio text', 4.4)
|
|
471
|
+
.orderBy(desc('createdAt'))
|
|
472
|
+
.limit(5)
|
|
473
|
+
.list();
|
|
474
|
+
|
|
475
|
+
// Search across all tables (table: "ALL")
|
|
476
|
+
const acrossTables = await db.search('user bio text').list({ pageSize: 5 });
|
|
477
|
+
|
|
478
|
+
// Combine a search predicate with other filters
|
|
479
|
+
const activeMatch = await db
|
|
480
|
+
.from(tables.User)
|
|
481
|
+
.where(search('user bio text'))
|
|
482
|
+
.and(eq('isActive', true))
|
|
483
|
+
.firstOrNull();
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
406
488
|
## Usage examples with `User`, `Role`, `Permission`
|
|
407
489
|
|
|
408
490
|
> The examples assume your schema has tables named `User`, `Role`, and `Permission`.
|
|
@@ -665,7 +747,60 @@ try {
|
|
|
665
747
|
}
|
|
666
748
|
```
|
|
667
749
|
|
|
668
|
-
|
|
750
|
+
## HTTP retries
|
|
751
|
+
|
|
752
|
+
- GET requests retry automatically with Fibonacci backoff (300ms base) up to 3 times by default; mutations are never retried.
|
|
753
|
+
- Disable or tune via `retry` on `onyx.init`:
|
|
754
|
+
|
|
755
|
+
```ts
|
|
756
|
+
const db = onyx.init({
|
|
757
|
+
retry: {
|
|
758
|
+
enabled: true, // default
|
|
759
|
+
maxRetries: 2, // default 3
|
|
760
|
+
initialDelayMs: 500, // default 300
|
|
761
|
+
},
|
|
762
|
+
});
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
## Onyx CLI
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
```
|
|
769
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
770
|
+
| Command | Flags | Defaults / notes |
|
|
771
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
772
|
+
| onyx-gen | --source auto|api|file | Default: --source file; --schema ./onyx.schema.json; |
|
|
773
|
+
| | --schema <path> | --out ./onyx/types.ts (file or dir; repeatable; dir uses |
|
|
774
|
+
| | --out / --types-out / --types-file <dir|file> | --base onyx.schema); timestamps default: date; optional |
|
|
775
|
+
| | --base / --baseName <name> | strategy default: non-null; schema type name: OnyxSchema; |
|
|
776
|
+
| | --timestamps string|date|number | emit-json disabled by default; --overwrite enabled; quiet=false. |
|
|
777
|
+
| | --name / --schemaTypeName <T> | --api-path repeatable; --json-out derived from TS output. |
|
|
778
|
+
| | --prefix <Prefix> | |
|
|
779
|
+
| | --optional non-null|nullable|none | |
|
|
780
|
+
| | --emit-json / --no-emit-json | |
|
|
781
|
+
| | --json-out <dir> | |
|
|
782
|
+
| | --api-path <path> (repeatable) | |
|
|
783
|
+
| | --overwrite / --no-overwrite | |
|
|
784
|
+
| | -q / --quiet | |
|
|
785
|
+
| | -h / --help | |
|
|
786
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
787
|
+
| onyx-schema get | [file] (positional) | Default file: ./onyx.schema.json; writes file unless |
|
|
788
|
+
| | --tables a,b | --tables or --print (then prints to stdout). |
|
|
789
|
+
| | --print | |
|
|
790
|
+
| | -h / --help | |
|
|
791
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
792
|
+
| onyx-schema publish | [file] (positional) | Default file: ./onyx.schema.json; validates before publishing; |
|
|
793
|
+
| | -h / --help | uses onyx.init credential resolver. |
|
|
794
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
795
|
+
| onyx-schema validate | [file] (positional) | Default file: ./onyx.schema.json; exits non-zero on errors. |
|
|
796
|
+
| | -h / --help | |
|
|
797
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
798
|
+
| onyx-schema diff | [file] (positional) | Default file: ./onyx.schema.json; prints YAML diff vs API. |
|
|
799
|
+
| | -h / --help | |
|
|
800
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
801
|
+
| onyx-schema info | -h / --help | Shows resolved config sources, config path, connection check.|
|
|
802
|
+
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
803
|
+
```
|
|
669
804
|
|
|
670
805
|
## Runtime & bundlers
|
|
671
806
|
|