@xylex-group/athena 2.4.0 → 2.6.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 +124 -2
- package/bin/athena-js.js +0 -0
- package/dist/browser.cjs +2245 -151
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +2238 -152
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +1073 -102
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +1073 -102
- package/dist/cli/index.js.map +1 -1
- package/dist/cookies.d.cts +1 -174
- package/dist/cookies.d.ts +1 -174
- package/dist/index-CVcQCGyG.d.cts +174 -0
- package/dist/index-CVcQCGyG.d.ts +174 -0
- package/dist/index.cjs +2246 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +2239 -153
- package/dist/index.js.map +1 -1
- package/dist/{model-form-GzTqhEzM.d.cts → model-form-BaHWi3gm.d.cts} +9 -5
- package/dist/{model-form-C0FAbOaf.d.ts → model-form-Dh6gWjL0.d.ts} +9 -5
- package/dist/{pipeline-CR4V15jF.d.ts → pipeline-Ce3pTw5h.d.ts} +1 -1
- package/dist/{pipeline-DZeExYMA.d.cts → pipeline-D1ZYeoH7.d.cts} +1 -1
- package/dist/{react-email-CQJq92zQ.d.cts → react-email-B8O1Jeff.d.cts} +637 -30
- package/dist/{react-email-BuApZuyG.d.ts → react-email-CDEF0jij.d.ts} +637 -30
- package/dist/react.cjs +84 -4
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +84 -4
- package/dist/react.js.map +1 -1
- package/dist/{types-D1JvL21V.d.cts → types-CUuo4NDi.d.cts} +1 -1
- package/dist/{types-09Q4D86N.d.cts → types-DSX6AT5B.d.cts} +3 -3
- package/dist/{types-09Q4D86N.d.ts → types-DSX6AT5B.d.ts} +3 -3
- package/dist/{types-DU3gNdFv.d.ts → types-DapchQY5.d.ts} +1 -1
- package/dist/utils.cjs +131 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +42 -1
- package/dist/utils.d.ts +42 -1
- package/dist/utils.js +117 -1
- package/dist/utils.js.map +1 -1
- package/package.json +193 -192
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# athena-js
|
|
2
2
|
|
|
3
|
-
current version: `2.
|
|
3
|
+
current version: `2.6.0`
|
|
4
4
|
`@xylex-group/athena` is a database driver and API gateway SDK that lets you interact with SQL backends over HTTP through a fluent builder API. It ships a typed query builder for Node.js / server environments plus Athena-native React hooks for client-side use.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
@@ -54,6 +54,31 @@ The existing string-based `.select(...)` chain remains fully supported for compa
|
|
|
54
54
|
including alias/FK patterns like `from:sender_id(name)`.
|
|
55
55
|
For the full AST model, route contract, error behavior, and Athena server implications,
|
|
56
56
|
see [`docs/findmany-ast-and-server-contract.md`](docs/findmany-ast-and-server-contract.md).
|
|
57
|
+
For method-by-method runtime AST/state/payload models across `select(...)`, mutations,
|
|
58
|
+
`rpc(...)`, `query(...)`, and fluent builder filters, see
|
|
59
|
+
[`docs/runtime-method-ast-models.md`](docs/runtime-method-ast-models.md).
|
|
60
|
+
|
|
61
|
+
### Gateway auth-session forwarding
|
|
62
|
+
|
|
63
|
+
If you need Athena server-side auth rollout to inspect auth context on normal query requests, the SDK now mirrors available auth state into gateway headers while still forwarding the original headers too.
|
|
64
|
+
|
|
65
|
+
Current behavior:
|
|
66
|
+
|
|
67
|
+
- `headers.Cookie` containing an Athena auth session cookie keeps `Cookie` and also adds `X-Athena-Auth-Session-Token`
|
|
68
|
+
- `headers.Authorization: Bearer ...` keeps `Authorization` and also adds `X-Athena-Auth-Bearer-Token`
|
|
69
|
+
- `createClient(..., { auth: { bearerToken } })` mirrors that token onto gateway/query requests as `X-Athena-Auth-Bearer-Token`
|
|
70
|
+
|
|
71
|
+
Server-side cookie forwarding example:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
|
|
75
|
+
headers: {
|
|
76
|
+
Cookie: request.headers.get("cookie") ?? "",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For the full contract, precedence rules, browser/server caveats, and rollout guidance, see [`docs/auth-session-forwarding.md`](docs/auth-session-forwarding.md).
|
|
57
82
|
|
|
58
83
|
### Auth client (Athena Auth server)
|
|
59
84
|
|
|
@@ -163,6 +188,56 @@ pnpm add @react-email/components @react-email/render
|
|
|
163
188
|
|
|
164
189
|
Auth responses follow the same envelope style: `{ ok, status, data, error, errorDetails, raw }`.
|
|
165
190
|
|
|
191
|
+
#### Native auth bootstrap helpers
|
|
192
|
+
|
|
193
|
+
If you want to remove `better-auth` from an app that is already aligned to
|
|
194
|
+
Athena Auth session semantics, the SDK now ships a native bootstrap layer with
|
|
195
|
+
an Athena-native `athenaAuth({...})` export that matches the Better Auth
|
|
196
|
+
top-level contract:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { athenaAuth } from "@xylex-group/athena";
|
|
200
|
+
|
|
201
|
+
export function getAuth(env: {
|
|
202
|
+
DB: unknown;
|
|
203
|
+
ATHENA_AUTH_URL: string;
|
|
204
|
+
ATHENA_AUTH_SECRET: string;
|
|
205
|
+
GITHUB_CLIENT_ID: string;
|
|
206
|
+
GITHUB_CLIENT_SECRET: string;
|
|
207
|
+
}) {
|
|
208
|
+
return athenaAuth({
|
|
209
|
+
baseURL: env.ATHENA_AUTH_URL,
|
|
210
|
+
secret: env.ATHENA_AUTH_SECRET,
|
|
211
|
+
database: env.DB,
|
|
212
|
+
socialProviders: {
|
|
213
|
+
github: {
|
|
214
|
+
clientId: env.GITHUB_CLIENT_ID,
|
|
215
|
+
clientSecret: env.GITHUB_CLIENT_SECRET,
|
|
216
|
+
scope: ["repo", "read:org", "user:email"],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
The returned auth object now carries the Better Auth-style top-level contract:
|
|
224
|
+
|
|
225
|
+
- `handler(request)`
|
|
226
|
+
- `api`
|
|
227
|
+
- `options`
|
|
228
|
+
- `$context`
|
|
229
|
+
- `$ERROR_CODES`
|
|
230
|
+
|
|
231
|
+
This native layer currently covers:
|
|
232
|
+
|
|
233
|
+
- typed auth bootstrap config
|
|
234
|
+
- session cookie set/clear helpers via the SDK cookie primitives
|
|
235
|
+
|
|
236
|
+
It also supports dynamic `baseURL` host resolution plus static/dynamic
|
|
237
|
+
`trustedOrigins` and `trustedProviders` on the native server bootstrap.
|
|
238
|
+
|
|
239
|
+
For the full details and current scope, see [`docs/auth/server-bootstrap.mdx`](docs/auth/server-bootstrap.mdx).
|
|
240
|
+
|
|
166
241
|
### Typed schema registry (model-first)
|
|
167
242
|
|
|
168
243
|
You can keep `createClient(...).from<T>(...)` as-is, or opt into a typed registry:
|
|
@@ -226,6 +301,7 @@ Generator supports:
|
|
|
226
301
|
- Multiple schema syncs such as `public` plus `athena`, with schema-safe default output paths
|
|
227
302
|
- Placeholder-driven output paths
|
|
228
303
|
- Feature flags (`features.emitRegistry`, `features.emitRelations`)
|
|
304
|
+
- Typed env-backed config fields via `generatorEnv(...)` for connection strings, schema lists, naming styles, flags, and placeholder maps
|
|
229
305
|
|
|
230
306
|
For full generator configuration and troubleshooting, see [`docs/generator-config.md`](./docs/generator-config.md).
|
|
231
307
|
For full CLI commands, help behavior, and troubleshooting, see [`docs/cli-command-reference.md`](./docs/cli-command-reference.md).
|
|
@@ -350,6 +426,22 @@ const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
|
|
|
350
426
|
});
|
|
351
427
|
```
|
|
352
428
|
|
|
429
|
+
### Read retries (experimental)
|
|
430
|
+
|
|
431
|
+
```ts
|
|
432
|
+
const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
|
|
433
|
+
experimental: {
|
|
434
|
+
retryReads: true,
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
With `retryReads: true`, the SDK automatically retries retryable read failures for `select`, `findMany(...)`, and `query(...)`.
|
|
440
|
+
|
|
441
|
+
- two additional attempts are applied internally
|
|
442
|
+
- retry classification follows the SDK's normalized `retryable` signal
|
|
443
|
+
- writes (`insert`, `upsert`, `update`, `delete`) are not retried by this flag
|
|
444
|
+
|
|
353
445
|
### findMany AST transport (experimental)
|
|
354
446
|
|
|
355
447
|
```ts
|
|
@@ -360,10 +452,13 @@ const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
|
|
|
360
452
|
});
|
|
361
453
|
```
|
|
362
454
|
|
|
363
|
-
With `findManyAst: true`, clean `findMany(...)` calls send
|
|
455
|
+
With `findManyAst: true`, clean `findMany(...)` calls can send an AST-style body to `/gateway/fetch` instead of compiling the select tree down to `columns` and `conditions` first.
|
|
364
456
|
|
|
365
457
|
- this is opt-in and meant for gateways that explicitly support direct AST bodies
|
|
366
458
|
- existing compiled `findMany(...)` transport remains the default
|
|
459
|
+
- shorthand `where` filters are normalized to explicit operator objects before the AST body is sent
|
|
460
|
+
- UUID-like equality filters that need the SDK's `::text` comparison still fall back to the legacy query/compiled path
|
|
461
|
+
- nested relation select strings stay off the SQL query fallback path and continue through `/gateway/fetch`
|
|
367
462
|
- chained builder filters or pagination state that the AST body cannot represent losslessly yet continue to use the legacy compiled path
|
|
368
463
|
- trace output still includes synthesized SQL so diagnostics stay readable
|
|
369
464
|
|
|
@@ -384,12 +479,27 @@ Utilities that are intentionally not exported from the root package are availabl
|
|
|
384
479
|
|
|
385
480
|
```ts
|
|
386
481
|
import {
|
|
482
|
+
asString,
|
|
483
|
+
asBoolean,
|
|
484
|
+
asBooleanOrNull,
|
|
485
|
+
asRecord,
|
|
486
|
+
asIdentifier,
|
|
487
|
+
firstString,
|
|
488
|
+
readTrimmedString,
|
|
489
|
+
asNumber,
|
|
490
|
+
asStringArray,
|
|
387
491
|
slugify,
|
|
388
492
|
trimTrailingSlashes,
|
|
389
493
|
parseBooleanFlag,
|
|
390
494
|
isLocalHostname,
|
|
391
495
|
clearAuthCookies,
|
|
392
496
|
proxyRequestHeaders,
|
|
497
|
+
sqlText,
|
|
498
|
+
escapeLikePatternValue,
|
|
499
|
+
quoteSqlStringLiteral,
|
|
500
|
+
sqlNullableText,
|
|
501
|
+
sqlJsonbLiteral,
|
|
502
|
+
sqlBigInt,
|
|
393
503
|
} from "@xylex-group/athena/utils";
|
|
394
504
|
```
|
|
395
505
|
|
|
@@ -400,15 +510,27 @@ const slug = slugify("Customer Success / Q4 Report"); // customer-success-q4-rep
|
|
|
400
510
|
const local = isLocalHostname("api.localhost"); // true
|
|
401
511
|
const normalized = trimTrailingSlashes("https://example.com///"); // https://example.com
|
|
402
512
|
const enabled = parseBooleanFlag(process.env.FEATURE_FLAG, false);
|
|
513
|
+
const count = asNumber("42"); // 42
|
|
514
|
+
const label = asString(" ready "); // ready
|
|
515
|
+
const active = asBooleanOrNull("yes"); // true
|
|
516
|
+
const tags = asStringArray([" alpha ", "", "beta"]); // ["alpha", "beta"]
|
|
517
|
+
const likePattern = escapeLikePatternValue("%admin_"); // \%admin\_
|
|
403
518
|
|
|
404
519
|
// Browser-only helper (safe no-op on server runtimes)
|
|
405
520
|
clearAuthCookies();
|
|
406
521
|
|
|
407
522
|
// Preserve forwarded headers when proxying auth requests
|
|
408
523
|
const upstreamHeaders = proxyRequestHeaders(request);
|
|
524
|
+
|
|
525
|
+
// Safely embed raw SQL values when using athena.query(...)
|
|
526
|
+
const emailLiteral = sqlText("floris@example.com");
|
|
527
|
+
const metadataLiteral = sqlJsonbLiteral({ role: "admin" });
|
|
528
|
+
const actorIdLiteral = sqlBigInt(42);
|
|
529
|
+
const exactLiteral = quoteSqlStringLiteral("Athena's SDK");
|
|
409
530
|
```
|
|
410
531
|
|
|
411
532
|
`clearAuthCookies()` clears cookies matching Athena/Better Auth prefixes (`athena-auth`, `__Secure-athena-auth`, `better-auth`, `__Secure-better-auth`) and also attempts parent-domain cleanup for subdomain deployments.
|
|
533
|
+
For SQL identifiers, keep using `identifier(...)`; `sqlText(...)`-style helpers are for literal values only.
|
|
412
534
|
|
|
413
535
|
### Retry helper
|
|
414
536
|
|
package/bin/athena-js.js
CHANGED
|
File without changes
|