@onyx.dev/onyx-database 2.0.0 → 2.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 +100 -57
- package/dist/{aggregates-BJT5DGGX.d.cts → aggregates-DREvey7b.d.cts} +5 -1
- package/dist/{aggregates-BJT5DGGX.d.ts → aggregates-DREvey7b.d.ts} +5 -1
- package/dist/edge.cjs +65 -45
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +3 -6
- package/dist/edge.d.ts +3 -6
- package/dist/edge.js +63 -44
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +24 -6
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +65 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +63 -44
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +24 -6
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,20 +63,16 @@ npm i @onyx.dev/onyx-database
|
|
|
63
63
|
|
|
64
64
|
The package is dual-module (ESM + CJS) and has **no runtime or peer dependencies**.
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
CLI tooling and schema codegen now live in the dedicated **Onyx CLI** repo:
|
|
67
|
+
<https://github.com/OnyxDevTools/onyx-cli>. Install it via the official install
|
|
68
|
+
script or Homebrew (macOS):
|
|
67
69
|
|
|
68
70
|
```bash
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
To install the CLI globally from this repo checkout (useful for local development and testing):
|
|
71
|
+
curl -fsSL https://raw.githubusercontent.com/OnyxDevTools/onyx-cli/main/scripts/install.sh | bash
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
npm run build
|
|
78
|
-
npm uninstall -g @onyx.dev/onyx-database # optional: clear older global versions
|
|
79
|
-
npm install -g . # installs the built onyx-schema and onyx-gen
|
|
73
|
+
# macOS (Homebrew)
|
|
74
|
+
brew tap OnyxDevTools/onyx-cli
|
|
75
|
+
brew install onyx-cli
|
|
80
76
|
```
|
|
81
77
|
|
|
82
78
|
---
|
|
@@ -85,16 +81,25 @@ npm install -g . # installs the built onyx-schema and on
|
|
|
85
81
|
|
|
86
82
|
This SDK resolves credentials automatically using the chain **explicit config ➜ environment variables ➜ `ONYX_CONFIG_PATH` file ➜ project config file ➜ home profile** _(Node.js only for file-based sources)_. Call `onyx.init({ databaseId: 'database-id' })` to target a specific database, or omit the `databaseId` to use the default. You can also pass credentials directly via config.
|
|
87
83
|
|
|
84
|
+
**Reliability defaults (read this):**
|
|
85
|
+
- **Retries:** GET/query calls auto-retry up to 3 times with Fibonacci backoff starting at 300ms (honors `Retry-After`); writes never retry.
|
|
86
|
+
- **Config cache:** Resolved config is cached per `${databaseId}-${apiKey}` for 5 minutes; tune with `ttl`, clear via `onyx.clearCacheConfig()`.
|
|
87
|
+
|
|
88
88
|
### Option A) Environment variables (recommended for production)
|
|
89
89
|
|
|
90
|
-
Set
|
|
90
|
+
Set these environment variables for your database:
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
| Variable | Purpose | Default when unset |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| `ONYX_DATABASE_ID` | Target database ID | required |
|
|
95
|
+
| `ONYX_DATABASE_BASE_URL` | Base URL for DB API | `https://api.onyx.dev` |
|
|
96
|
+
| `ONYX_DATABASE_API_KEY` | API key | required |
|
|
97
|
+
| `ONYX_DATABASE_API_SECRET` | API secret | required |
|
|
98
|
+
| `ONYX_AI_BASE_URL` | Base URL for AI endpoints | `https://ai.onyx.dev` |
|
|
99
|
+
| `ONYX_DEFAULT_MODEL` | Model used by `db.chat()` shorthand | `onyx` |
|
|
100
|
+
| `ONYX_CONFIG_PATH` | Path to JSON credentials file (Node only; ignored on edge) | unset (falls back to env ➜ project file ➜ home profile) |
|
|
101
|
+
| `ONYX_DEBUG` | Enable HTTP + config debug logging | off |
|
|
102
|
+
| `ONYX_STREAM_DEBUG` | Enable streaming debug logs | off |
|
|
98
103
|
|
|
99
104
|
```ts
|
|
100
105
|
import { onyx } from '@onyx.dev/onyx-database';
|
|
@@ -172,15 +177,34 @@ export default {
|
|
|
172
177
|
};
|
|
173
178
|
```
|
|
174
179
|
|
|
175
|
-
### Connection
|
|
180
|
+
### Connection & config caching
|
|
176
181
|
|
|
177
182
|
Calling `onyx.init()` returns a lightweight client. Configuration is resolved once
|
|
178
|
-
and cached for 5 minutes to avoid repeated
|
|
179
|
-
`ttl` or reset via `onyx.clearCacheConfig()`).
|
|
180
|
-
single internal `HttpClient`. Requests use the
|
|
181
|
-
already reuses connections and pools them for
|
|
182
|
-
`db` for multiple operations; extra SDK‑level
|
|
183
|
-
necessary unless you create many short‑lived
|
|
183
|
+
and cached **per `${databaseId}-${apiKey}` pair** for 5 minutes to avoid repeated
|
|
184
|
+
env/file lookups (override with `ttl` or reset via `onyx.clearCacheConfig()`).
|
|
185
|
+
Each database instance keeps a single internal `HttpClient`. Requests use the
|
|
186
|
+
runtime's global `fetch`, which already reuses connections and pools them for
|
|
187
|
+
keep‑alive. Reuse the returned `db` for multiple operations; extra SDK‑level
|
|
188
|
+
connection pooling generally isn't necessary unless you create many short‑lived
|
|
189
|
+
clients.
|
|
190
|
+
|
|
191
|
+
### Typed vs untyped init
|
|
192
|
+
|
|
193
|
+
`onyx.init()` is generic. Omit the type for quick scripts; add your generated schema type for full safety.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
// Untyped: flexible, no compile-time field checks
|
|
197
|
+
const db = onyx.init();
|
|
198
|
+
const user = await db.from('User').findById('abc'); // inferred as any/unknown
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
// Typed: import generated schema to get autocomplete and validation
|
|
203
|
+
import type { OnyxSchema as Schema } from './onyx/types';
|
|
204
|
+
const db = onyx.init<Schema>();
|
|
205
|
+
const user = await db.from('User').findById('abc'); // inferred as Schema['User']
|
|
206
|
+
// user.emali -> TypeScript error
|
|
207
|
+
```
|
|
184
208
|
|
|
185
209
|
---
|
|
186
210
|
|
|
@@ -295,15 +319,19 @@ if (approval.requiresApproval) {
|
|
|
295
319
|
|
|
296
320
|
## Optional: generate TypeScript types from your schema
|
|
297
321
|
|
|
298
|
-
|
|
322
|
+
Use the **Onyx CLI** (`onyx`) from <https://github.com/OnyxDevTools/onyx-cli> to
|
|
323
|
+
emit per-table interfaces, a `tables` enum, and a `Schema` mapping for
|
|
324
|
+
compile-time safety and IntelliSense. Each generated interface also includes an
|
|
325
|
+
index signature so extra properties (for graph attachments in cascade saves)
|
|
326
|
+
don't trigger type errors.
|
|
299
327
|
|
|
300
328
|
Generate directly from the API (using the same credential resolver as `init()`):
|
|
301
329
|
|
|
302
330
|
```bash
|
|
303
|
-
|
|
331
|
+
onyx gen --ts --source api --out ./src/onyx/types.ts --name OnyxSchema
|
|
304
332
|
```
|
|
305
333
|
|
|
306
|
-
With `--source api`, `onyx
|
|
334
|
+
With `--source api`, `onyx gen` calls the Schema API (same as `onyx schema get`) using the
|
|
307
335
|
standard config chain (env, project file, home profile).
|
|
308
336
|
|
|
309
337
|
Timestamp attributes are emitted as `Date` fields by default. When saving,
|
|
@@ -313,30 +341,30 @@ Timestamp attributes are emitted as `Date` fields by default. When saving,
|
|
|
313
341
|
Or from a local schema file you export from the console:
|
|
314
342
|
|
|
315
343
|
```bash
|
|
316
|
-
|
|
344
|
+
onyx gen --ts --source file --schema ./onyx.schema.json --out ./src/onyx/types.ts --name OnyxSchema
|
|
317
345
|
```
|
|
318
346
|
|
|
319
|
-
Run it with no flags to use the defaults: `onyx
|
|
347
|
+
Run it with no flags to use the defaults: `onyx gen` reads `./onyx.schema.json` and writes to `./onyx/types.ts`.
|
|
320
348
|
|
|
321
349
|
### Manage schemas from the CLI
|
|
322
350
|
|
|
323
|
-
Publish or download schema JSON directly via API using the `onyx
|
|
351
|
+
Publish or download schema JSON directly via API using the `onyx schema` helper:
|
|
324
352
|
|
|
325
353
|
```bash
|
|
326
354
|
# Publish ./onyx.schema.json with publish=true by default
|
|
327
|
-
onyx
|
|
355
|
+
onyx schema publish
|
|
328
356
|
|
|
329
357
|
# Overwrite ./onyx.schema.json with the remote schema
|
|
330
|
-
onyx
|
|
358
|
+
onyx schema get
|
|
331
359
|
|
|
332
360
|
# Print the remote schema without writing a file
|
|
333
|
-
onyx
|
|
361
|
+
onyx schema get --print
|
|
334
362
|
|
|
335
363
|
# Fetch only selected tables (prints to stdout; does not overwrite files)
|
|
336
|
-
onyx
|
|
364
|
+
onyx schema get --tables=User,Profile
|
|
337
365
|
|
|
338
366
|
# Example subset output
|
|
339
|
-
onyx
|
|
367
|
+
onyx schema get --tables=User,Profile
|
|
340
368
|
# {
|
|
341
369
|
# "tables": [
|
|
342
370
|
# {
|
|
@@ -357,10 +385,10 @@ onyx-schema get --tables=User,Profile
|
|
|
357
385
|
# }
|
|
358
386
|
|
|
359
387
|
# Validate a schema file without publishing
|
|
360
|
-
onyx
|
|
388
|
+
onyx schema validate ./onyx.schema.json
|
|
361
389
|
|
|
362
390
|
# Diff local schema vs API
|
|
363
|
-
onyx
|
|
391
|
+
onyx schema diff ./onyx.schema.json
|
|
364
392
|
# Prints YAML with added/removed/changed tables and attribute differences between the API schema and your local file.
|
|
365
393
|
```
|
|
366
394
|
|
|
@@ -391,7 +419,7 @@ console.log(diff.changedTables);
|
|
|
391
419
|
You can also emit to multiple paths in one run (comma-separated or by repeating `--out`):
|
|
392
420
|
|
|
393
421
|
```bash
|
|
394
|
-
onyx
|
|
422
|
+
onyx gen --ts --out ./src/onyx/types.ts,./apps/admin/src/onyx/types.ts
|
|
395
423
|
```
|
|
396
424
|
|
|
397
425
|
Use in code:
|
|
@@ -411,12 +439,12 @@ const User = await db
|
|
|
411
439
|
```
|
|
412
440
|
|
|
413
441
|
For a schema with `User`, `UserProfile`, `Role`, and `Permission` tables,
|
|
414
|
-
`onyx
|
|
442
|
+
`onyx gen` emits plain interfaces keyed by IDs. Each interface includes an
|
|
415
443
|
index signature so resolver-attached fields or embedded objects remain
|
|
416
444
|
type-safe:
|
|
417
445
|
|
|
418
446
|
```ts
|
|
419
|
-
// AUTO-GENERATED BY onyx
|
|
447
|
+
// AUTO-GENERATED BY onyx gen. DO NOT EDIT.
|
|
420
448
|
export interface User {
|
|
421
449
|
id?: string;
|
|
422
450
|
name: string;
|
|
@@ -535,6 +563,26 @@ import {
|
|
|
535
563
|
- `inOp`/`notIn` remain available for backward compatibility and are exact aliases.
|
|
536
564
|
- `search(text, minScore?)` builds a Lucene `MATCHES` predicate on `__full_text__` and always serializes `minScore` (null when omitted).
|
|
537
565
|
|
|
566
|
+
### Aggregate helpers
|
|
567
|
+
|
|
568
|
+
```ts
|
|
569
|
+
import {
|
|
570
|
+
avg, sum, count, min, max,
|
|
571
|
+
std, variance, median,
|
|
572
|
+
upper, lower,
|
|
573
|
+
substring, replace, percentile,
|
|
574
|
+
format
|
|
575
|
+
} from '@onyx.dev/onyx-database';
|
|
576
|
+
|
|
577
|
+
const rows = await db
|
|
578
|
+
.select(format('createdAt', 'yyyy-MM-dd'))
|
|
579
|
+
.from('User')
|
|
580
|
+
.list();
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
- `format(field, formatter)` uses Java-style format strings for dates and numbers.
|
|
584
|
+
- Example: `examples/query/format.ts`
|
|
585
|
+
|
|
538
586
|
### Inner queries (IN/NOT IN with sub-selects)
|
|
539
587
|
|
|
540
588
|
You can pass another query builder to `within` or `notWithin` to create nested filters. The SDK serializes the inner query (including its table) before sending the request.
|
|
@@ -889,36 +937,31 @@ const db = onyx.init({
|
|
|
889
937
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
890
938
|
| Command | Flags | Defaults / notes |
|
|
891
939
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
892
|
-
| onyx
|
|
893
|
-
| | --
|
|
894
|
-
| | --
|
|
895
|
-
| | --
|
|
896
|
-
| | --
|
|
897
|
-
| | --
|
|
898
|
-
| | --prefix <Prefix> | |
|
|
899
|
-
| | --optional non-null|nullable|none | |
|
|
900
|
-
| | --emit-json / --no-emit-json | |
|
|
901
|
-
| | --json-out <dir> | |
|
|
902
|
-
| | --api-path <path> (repeatable) | |
|
|
940
|
+
| onyx gen | --ts/--typescript | Default: --source file; --schema ./onyx.schema.json; |
|
|
941
|
+
| | --source auto|api|file | --out ./onyx/types.ts (file or dir; repeatable); |
|
|
942
|
+
| | --schema <path> | schema type name: OnyxSchema; timestamps default: date. |
|
|
943
|
+
| | --out <dir|file> | Use --overwrite to force output; quiet=false. |
|
|
944
|
+
| | --name <T> | |
|
|
945
|
+
| | --timestamps string|date|number | |
|
|
903
946
|
| | --overwrite / --no-overwrite | |
|
|
904
947
|
| | -q / --quiet | |
|
|
905
948
|
| | -h / --help | |
|
|
906
949
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
907
|
-
| onyx
|
|
950
|
+
| onyx schema get | [file] (positional) | Default file: ./onyx.schema.json; writes file unless |
|
|
908
951
|
| | --tables a,b | --tables or --print (then prints to stdout). |
|
|
909
952
|
| | --print | |
|
|
910
953
|
| | -h / --help | |
|
|
911
954
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
912
|
-
| onyx
|
|
955
|
+
| onyx schema publish | [file] (positional) | Default file: ./onyx.schema.json; validates before publishing; |
|
|
913
956
|
| | -h / --help | uses onyx.init credential resolver. |
|
|
914
957
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
915
|
-
| onyx
|
|
958
|
+
| onyx schema validate | [file] (positional) | Default file: ./onyx.schema.json; exits non-zero on errors. |
|
|
916
959
|
| | -h / --help | |
|
|
917
960
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
918
|
-
| onyx
|
|
961
|
+
| onyx schema diff | [file] (positional) | Default file: ./onyx.schema.json; prints YAML diff vs API. |
|
|
919
962
|
| | -h / --help | |
|
|
920
963
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
921
|
-
| onyx
|
|
964
|
+
| onyx schema info | -h / --help | Shows resolved config sources, config path, connection check.|
|
|
922
965
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
923
966
|
```
|
|
924
967
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var name = "@onyx.dev/onyx-database";
|
|
2
|
+
var version = "2.1.0";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Supported operators for building query criteria.
|
|
3
6
|
*
|
|
@@ -1755,6 +1758,7 @@ declare const upper: (attribute: string) => string;
|
|
|
1755
1758
|
declare const lower: (attribute: string) => string;
|
|
1756
1759
|
declare const substring: (attribute: string, from: number, length: number) => string;
|
|
1757
1760
|
declare const replace: (attribute: string, pattern: string, repl: string) => string;
|
|
1761
|
+
declare const format: (attribute: string, formatter: string) => string;
|
|
1758
1762
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1759
1763
|
|
|
1760
|
-
export { type
|
|
1764
|
+
export { type SchemaIndexChange as $, type AiRequestOptions as A, type AiClient as B, type SecretRecord as C, type SecretsListResponse as D, type SecretSaveRequest as E, type FullTextQuery as F, type SchemaDataType as G, type SchemaIdentifierGenerator as H, type IOnyxDatabase as I, type SchemaIdentifier as J, type SchemaAttribute as K, type SchemaIndexType as L, type SchemaIndex as M, type SchemaResolver as N, type OnyxFacade as O, type SchemaTriggerEvent as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type SchemaTrigger as T, type SchemaEntity as U, type SchemaRevisionMetadata as V, type SchemaRevision as W, type SchemaHistoryEntry as X, type SchemaUpsertRequest as Y, type SchemaValidationResult as Z, type SchemaAttributeChange as _, type QueryResultsPromise as a, type SchemaResolverChange as a0, type SchemaTriggerChange as a1, type SchemaTableDiff as a2, type SchemaDiff as a3, type QueryCriteriaOperator as a4, type LogicalOperator as a5, type Sort as a6, type StreamAction as a7, type OnyxDocument as a8, type FetchResponse as a9, notMatches as aA, like as aB, notLike as aC, contains as aD, containsIgnoreCase as aE, notContains as aF, notContainsIgnoreCase as aG, startsWith as aH, notStartsWith as aI, isNull as aJ, notNull as aK, avg as aL, sum as aM, count as aN, min as aO, max as aP, std as aQ, variance as aR, median as aS, upper as aT, lower as aU, substring as aV, replace as aW, format as aX, percentile as aY, type FetchImpl as aa, type QueryCriteria as ab, type QueryCondition as ac, type SelectQuery as ad, type UpdateQuery as ae, type QueryPage as af, type IConditionBuilder as ag, type IQueryBuilder as ah, type ISaveBuilder as ai, type ICascadeBuilder as aj, type ICascadeRelationshipBuilder as ak, asc as al, desc as am, eq as an, neq as ao, inOp as ap, within as aq, notIn as ar, notWithin as as, between as at, gt as au, gte as av, lt as aw, lte as ax, matches as ay, search as az, type OnyxConfig as b, type AiChatRole as c, type AiToolCallFunction as d, type AiToolCall as e, type AiChatMessage as f, type AiToolFunction as g, type AiTool as h, type AiToolChoice as i, type AiChatCompletionRequest as j, type AiChatCompletionUsage as k, type AiChatCompletionChoice as l, type AiChatCompletionResponse as m, name as n, type AiChatCompletionChunkDelta as o, type AiChatCompletionChunkChoice as p, type AiChatCompletionChunk as q, type AiChatCompletionStream as r, type AiChatOptions as s, type AiChatClient as t, type AiScriptApprovalRequest as u, version as v, type AiScriptApprovalResponse as w, type AiModelsResponse as x, type AiModel as y, type AiErrorResponse as z };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var name = "@onyx.dev/onyx-database";
|
|
2
|
+
var version = "2.1.0";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Supported operators for building query criteria.
|
|
3
6
|
*
|
|
@@ -1755,6 +1758,7 @@ declare const upper: (attribute: string) => string;
|
|
|
1755
1758
|
declare const lower: (attribute: string) => string;
|
|
1756
1759
|
declare const substring: (attribute: string, from: number, length: number) => string;
|
|
1757
1760
|
declare const replace: (attribute: string, pattern: string, repl: string) => string;
|
|
1761
|
+
declare const format: (attribute: string, formatter: string) => string;
|
|
1758
1762
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1759
1763
|
|
|
1760
|
-
export { type
|
|
1764
|
+
export { type SchemaIndexChange as $, type AiRequestOptions as A, type AiClient as B, type SecretRecord as C, type SecretsListResponse as D, type SecretSaveRequest as E, type FullTextQuery as F, type SchemaDataType as G, type SchemaIdentifierGenerator as H, type IOnyxDatabase as I, type SchemaIdentifier as J, type SchemaAttribute as K, type SchemaIndexType as L, type SchemaIndex as M, type SchemaResolver as N, type OnyxFacade as O, type SchemaTriggerEvent as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type SchemaTrigger as T, type SchemaEntity as U, type SchemaRevisionMetadata as V, type SchemaRevision as W, type SchemaHistoryEntry as X, type SchemaUpsertRequest as Y, type SchemaValidationResult as Z, type SchemaAttributeChange as _, type QueryResultsPromise as a, type SchemaResolverChange as a0, type SchemaTriggerChange as a1, type SchemaTableDiff as a2, type SchemaDiff as a3, type QueryCriteriaOperator as a4, type LogicalOperator as a5, type Sort as a6, type StreamAction as a7, type OnyxDocument as a8, type FetchResponse as a9, notMatches as aA, like as aB, notLike as aC, contains as aD, containsIgnoreCase as aE, notContains as aF, notContainsIgnoreCase as aG, startsWith as aH, notStartsWith as aI, isNull as aJ, notNull as aK, avg as aL, sum as aM, count as aN, min as aO, max as aP, std as aQ, variance as aR, median as aS, upper as aT, lower as aU, substring as aV, replace as aW, format as aX, percentile as aY, type FetchImpl as aa, type QueryCriteria as ab, type QueryCondition as ac, type SelectQuery as ad, type UpdateQuery as ae, type QueryPage as af, type IConditionBuilder as ag, type IQueryBuilder as ah, type ISaveBuilder as ai, type ICascadeBuilder as aj, type ICascadeRelationshipBuilder as ak, asc as al, desc as am, eq as an, neq as ao, inOp as ap, within as aq, notIn as ar, notWithin as as, between as at, gt as au, gte as av, lt as aw, lte as ax, matches as ay, search as az, type OnyxConfig as b, type AiChatRole as c, type AiToolCallFunction as d, type AiToolCall as e, type AiChatMessage as f, type AiToolFunction as g, type AiTool as h, type AiToolChoice as i, type AiChatCompletionRequest as j, type AiChatCompletionUsage as k, type AiChatCompletionChoice as l, type AiChatCompletionResponse as m, name as n, type AiChatCompletionChunkDelta as o, type AiChatCompletionChunkChoice as p, type AiChatCompletionChunk as q, type AiChatCompletionStream as r, type AiChatOptions as s, type AiChatClient as t, type AiScriptApprovalRequest as u, version as v, type AiScriptApprovalResponse as w, type AiModelsResponse as x, type AiModel as y, type AiErrorResponse as z };
|
package/dist/edge.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// package.json
|
|
4
|
+
var name = "@onyx.dev/onyx-database";
|
|
5
|
+
var version = "2.1.0";
|
|
6
|
+
|
|
3
7
|
// src/config/defaults.ts
|
|
4
8
|
var DEFAULT_BASE_URL = "https://api.onyx.dev";
|
|
5
9
|
var DEFAULT_AI_BASE_URL = "https://ai.onyx.dev";
|
|
@@ -803,8 +807,8 @@ var CascadeRelationshipBuilder = class {
|
|
|
803
807
|
* builder.graph('programs');
|
|
804
808
|
* ```
|
|
805
809
|
*/
|
|
806
|
-
graph(
|
|
807
|
-
this.graphName =
|
|
810
|
+
graph(name2) {
|
|
811
|
+
this.graphName = name2;
|
|
808
812
|
return this;
|
|
809
813
|
}
|
|
810
814
|
/**
|
|
@@ -891,24 +895,24 @@ function diffAttributes(apiAttrs, localAttrs) {
|
|
|
891
895
|
const added = [];
|
|
892
896
|
const removed = [];
|
|
893
897
|
const changed = [];
|
|
894
|
-
for (const [
|
|
895
|
-
if (!apiMap.has(
|
|
898
|
+
for (const [name2, local] of localMap.entries()) {
|
|
899
|
+
if (!apiMap.has(name2)) {
|
|
896
900
|
added.push(local);
|
|
897
901
|
continue;
|
|
898
902
|
}
|
|
899
|
-
const api = apiMap.get(
|
|
903
|
+
const api = apiMap.get(name2);
|
|
900
904
|
const apiNull = Boolean(api.isNullable);
|
|
901
905
|
const localNull = Boolean(local.isNullable);
|
|
902
906
|
if (api.type !== local.type || apiNull !== localNull) {
|
|
903
907
|
changed.push({
|
|
904
|
-
name,
|
|
908
|
+
name: name2,
|
|
905
909
|
from: { type: api.type, isNullable: apiNull },
|
|
906
910
|
to: { type: local.type, isNullable: localNull }
|
|
907
911
|
});
|
|
908
912
|
}
|
|
909
913
|
}
|
|
910
|
-
for (const
|
|
911
|
-
if (!localMap.has(
|
|
914
|
+
for (const name2 of apiMap.keys()) {
|
|
915
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
912
916
|
}
|
|
913
917
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
914
918
|
removed.sort();
|
|
@@ -922,22 +926,22 @@ function diffIndexes(apiIndexes, localIndexes) {
|
|
|
922
926
|
const added = [];
|
|
923
927
|
const removed = [];
|
|
924
928
|
const changed = [];
|
|
925
|
-
for (const [
|
|
926
|
-
if (!apiMap.has(
|
|
929
|
+
for (const [name2, local] of localMap.entries()) {
|
|
930
|
+
if (!apiMap.has(name2)) {
|
|
927
931
|
added.push(local);
|
|
928
932
|
continue;
|
|
929
933
|
}
|
|
930
|
-
const api = apiMap.get(
|
|
934
|
+
const api = apiMap.get(name2);
|
|
931
935
|
const apiType = api.type ?? "DEFAULT";
|
|
932
936
|
const localType = local.type ?? "DEFAULT";
|
|
933
937
|
const apiScore = api.minimumScore;
|
|
934
938
|
const localScore = local.minimumScore;
|
|
935
939
|
if (apiType !== localType || apiScore !== localScore) {
|
|
936
|
-
changed.push({ name, from: api, to: local });
|
|
940
|
+
changed.push({ name: name2, from: api, to: local });
|
|
937
941
|
}
|
|
938
942
|
}
|
|
939
|
-
for (const
|
|
940
|
-
if (!localMap.has(
|
|
943
|
+
for (const name2 of apiMap.keys()) {
|
|
944
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
941
945
|
}
|
|
942
946
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
943
947
|
removed.sort();
|
|
@@ -951,18 +955,18 @@ function diffResolvers(apiResolvers, localResolvers) {
|
|
|
951
955
|
const added = [];
|
|
952
956
|
const removed = [];
|
|
953
957
|
const changed = [];
|
|
954
|
-
for (const [
|
|
955
|
-
if (!apiMap.has(
|
|
958
|
+
for (const [name2, local] of localMap.entries()) {
|
|
959
|
+
if (!apiMap.has(name2)) {
|
|
956
960
|
added.push(local);
|
|
957
961
|
continue;
|
|
958
962
|
}
|
|
959
|
-
const api = apiMap.get(
|
|
963
|
+
const api = apiMap.get(name2);
|
|
960
964
|
if (api.resolver !== local.resolver) {
|
|
961
|
-
changed.push({ name, from: api, to: local });
|
|
965
|
+
changed.push({ name: name2, from: api, to: local });
|
|
962
966
|
}
|
|
963
967
|
}
|
|
964
|
-
for (const
|
|
965
|
-
if (!localMap.has(
|
|
968
|
+
for (const name2 of apiMap.keys()) {
|
|
969
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
966
970
|
}
|
|
967
971
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
968
972
|
removed.sort();
|
|
@@ -976,18 +980,18 @@ function diffTriggers(apiTriggers, localTriggers) {
|
|
|
976
980
|
const added = [];
|
|
977
981
|
const removed = [];
|
|
978
982
|
const changed = [];
|
|
979
|
-
for (const [
|
|
980
|
-
if (!apiMap.has(
|
|
983
|
+
for (const [name2, local] of localMap.entries()) {
|
|
984
|
+
if (!apiMap.has(name2)) {
|
|
981
985
|
added.push(local);
|
|
982
986
|
continue;
|
|
983
987
|
}
|
|
984
|
-
const api = apiMap.get(
|
|
988
|
+
const api = apiMap.get(name2);
|
|
985
989
|
if (api.event !== local.event || api.trigger !== local.trigger) {
|
|
986
|
-
changed.push({ name, from: api, to: local });
|
|
990
|
+
changed.push({ name: name2, from: api, to: local });
|
|
987
991
|
}
|
|
988
992
|
}
|
|
989
|
-
for (const
|
|
990
|
-
if (!localMap.has(
|
|
993
|
+
for (const name2 of apiMap.keys()) {
|
|
994
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
991
995
|
}
|
|
992
996
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
993
997
|
removed.sort();
|
|
@@ -1003,13 +1007,13 @@ function computeSchemaDiff(apiSchema, localSchema) {
|
|
|
1003
1007
|
const newTables = [];
|
|
1004
1008
|
const removedTables = [];
|
|
1005
1009
|
const changedTables = [];
|
|
1006
|
-
for (const [
|
|
1007
|
-
if (!apiMap.has(
|
|
1008
|
-
newTables.push(
|
|
1010
|
+
for (const [name2, localEntity] of localMap.entries()) {
|
|
1011
|
+
if (!apiMap.has(name2)) {
|
|
1012
|
+
newTables.push(name2);
|
|
1009
1013
|
continue;
|
|
1010
1014
|
}
|
|
1011
|
-
const apiEntity = apiMap.get(
|
|
1012
|
-
const tableDiff = { name };
|
|
1015
|
+
const apiEntity = apiMap.get(name2);
|
|
1016
|
+
const tableDiff = { name: name2 };
|
|
1013
1017
|
const partitionFrom = normalizePartition(apiEntity.partition);
|
|
1014
1018
|
const partitionTo = normalizePartition(localEntity.partition);
|
|
1015
1019
|
if (partitionFrom !== partitionTo) {
|
|
@@ -1034,8 +1038,8 @@ function computeSchemaDiff(apiSchema, localSchema) {
|
|
|
1034
1038
|
changedTables.push(tableDiff);
|
|
1035
1039
|
}
|
|
1036
1040
|
}
|
|
1037
|
-
for (const
|
|
1038
|
-
if (!localMap.has(
|
|
1041
|
+
for (const name2 of apiMap.keys()) {
|
|
1042
|
+
if (!localMap.has(name2)) removedTables.push(name2);
|
|
1039
1043
|
}
|
|
1040
1044
|
newTables.sort();
|
|
1041
1045
|
removedTables.sort();
|
|
@@ -1973,20 +1977,38 @@ var AiChatClientImpl = class {
|
|
|
1973
1977
|
}
|
|
1974
1978
|
};
|
|
1975
1979
|
function createOnyxFacade(resolveConfig2) {
|
|
1976
|
-
|
|
1980
|
+
const cachedCfgs = /* @__PURE__ */ new Map();
|
|
1981
|
+
const cacheKey = (databaseId, apiKey) => {
|
|
1982
|
+
const id = typeof databaseId === "string" && databaseId.trim() !== "" ? databaseId.trim() : null;
|
|
1983
|
+
const key = typeof apiKey === "string" && apiKey.trim() !== "" ? apiKey.trim() : null;
|
|
1984
|
+
return id && key ? `${id}-${key}` : null;
|
|
1985
|
+
};
|
|
1977
1986
|
function resolveConfigWithCache(config) {
|
|
1978
1987
|
const ttl = config?.ttl ?? DEFAULT_CACHE_TTL;
|
|
1979
1988
|
const now = Date.now();
|
|
1980
|
-
|
|
1981
|
-
|
|
1989
|
+
const hintKey = cacheKey(config?.databaseId, config?.apiKey) ?? "__default__";
|
|
1990
|
+
const existing = cachedCfgs.get(hintKey);
|
|
1991
|
+
if (existing && existing.expires > now) {
|
|
1992
|
+
return existing.promise;
|
|
1982
1993
|
}
|
|
1994
|
+
if (existing) cachedCfgs.delete(hintKey);
|
|
1983
1995
|
const { ttl: _ttl, requestLoggingEnabled: _reqLog, responseLoggingEnabled: _resLog, ...rest } = config ?? {};
|
|
1984
|
-
const
|
|
1985
|
-
|
|
1996
|
+
const expires = now + ttl;
|
|
1997
|
+
const promise = resolveConfig2(rest).then((resolved) => {
|
|
1998
|
+
const resolvedKey = cacheKey(resolved.databaseId, resolved.apiKey) ?? hintKey;
|
|
1999
|
+
const nextExpires = Date.now() + ttl;
|
|
2000
|
+
cachedCfgs.set(resolvedKey, { promise, expires: nextExpires });
|
|
2001
|
+
if (resolvedKey !== hintKey) {
|
|
2002
|
+
const stale = cachedCfgs.get(hintKey);
|
|
2003
|
+
if (stale && stale.promise === promise) cachedCfgs.delete(hintKey);
|
|
2004
|
+
}
|
|
2005
|
+
return resolved;
|
|
2006
|
+
});
|
|
2007
|
+
cachedCfgs.set(hintKey, { promise, expires });
|
|
1986
2008
|
return promise;
|
|
1987
2009
|
}
|
|
1988
2010
|
function clearCacheConfig() {
|
|
1989
|
-
|
|
2011
|
+
cachedCfgs.clear();
|
|
1990
2012
|
}
|
|
1991
2013
|
return {
|
|
1992
2014
|
init(config) {
|
|
@@ -2179,12 +2201,9 @@ var upper = (attribute) => `upper(${attribute})`;
|
|
|
2179
2201
|
var lower = (attribute) => `lower(${attribute})`;
|
|
2180
2202
|
var substring = (attribute, from, length) => `substring(${attribute},${from},${length})`;
|
|
2181
2203
|
var replace = (attribute, pattern, repl) => `replace(${attribute}, '${pattern.replace(/'/g, "\\'")}', '${repl.replace(/'/g, "\\'")}')`;
|
|
2204
|
+
var format = (attribute, formatter) => `format(${attribute}, '${formatter.replace(/'/g, "\\'")}')`;
|
|
2182
2205
|
var percentile = (attribute, p) => `percentile(${attribute}, ${p})`;
|
|
2183
2206
|
|
|
2184
|
-
// src/edge.ts
|
|
2185
|
-
var sdkName = "@onyx.dev/onyx-database";
|
|
2186
|
-
var sdkVersion = "0.1.0";
|
|
2187
|
-
|
|
2188
2207
|
exports.QueryResults = QueryResults;
|
|
2189
2208
|
exports.asc = asc;
|
|
2190
2209
|
exports.avg = avg;
|
|
@@ -2194,6 +2213,7 @@ exports.containsIgnoreCase = containsIgnoreCase;
|
|
|
2194
2213
|
exports.count = count;
|
|
2195
2214
|
exports.desc = desc;
|
|
2196
2215
|
exports.eq = eq;
|
|
2216
|
+
exports.format = format;
|
|
2197
2217
|
exports.gt = gt;
|
|
2198
2218
|
exports.gte = gte;
|
|
2199
2219
|
exports.inOp = inOp;
|
|
@@ -2218,8 +2238,8 @@ exports.notWithin = notWithin;
|
|
|
2218
2238
|
exports.onyx = onyx;
|
|
2219
2239
|
exports.percentile = percentile;
|
|
2220
2240
|
exports.replace = replace;
|
|
2221
|
-
exports.sdkName =
|
|
2222
|
-
exports.sdkVersion =
|
|
2241
|
+
exports.sdkName = name;
|
|
2242
|
+
exports.sdkVersion = version;
|
|
2223
2243
|
exports.search = search;
|
|
2224
2244
|
exports.startsWith = startsWith;
|
|
2225
2245
|
exports.std = std;
|