@xylex-group/athena 1.9.0 → 2.1.2

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.
Files changed (45) hide show
  1. package/README.md +86 -68
  2. package/bin/athena-js.js +0 -0
  3. package/dist/browser.cjs +3319 -0
  4. package/dist/browser.cjs.map +1 -0
  5. package/dist/browser.d.cts +25 -0
  6. package/dist/browser.d.ts +25 -0
  7. package/dist/browser.js +3276 -0
  8. package/dist/browser.js.map +1 -0
  9. package/dist/cli/index.cjs +1839 -275
  10. package/dist/cli/index.cjs.map +1 -1
  11. package/dist/cli/index.d.cts +3 -2
  12. package/dist/cli/index.d.ts +3 -2
  13. package/dist/cli/index.js +1840 -276
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/client-BX0NQqOn.d.ts +435 -0
  16. package/dist/client-dpAp-NZK.d.cts +435 -0
  17. package/dist/cookies.cjs +890 -0
  18. package/dist/cookies.cjs.map +1 -0
  19. package/dist/cookies.d.cts +174 -0
  20. package/dist/cookies.d.ts +174 -0
  21. package/dist/cookies.js +869 -0
  22. package/dist/cookies.js.map +1 -0
  23. package/dist/index.cjs +2724 -1777
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +8 -641
  26. package/dist/index.d.ts +8 -641
  27. package/dist/index.js +2725 -1779
  28. package/dist/index.js.map +1 -1
  29. package/dist/model-form-2hqmoOUX.d.ts +1284 -0
  30. package/dist/model-form-Cy-zaO0u.d.cts +1284 -0
  31. package/dist/pipeline-BOPszLsL.d.ts +8 -0
  32. package/dist/pipeline-E3FDbs4W.d.cts +8 -0
  33. package/dist/react.cjs +93 -0
  34. package/dist/react.cjs.map +1 -1
  35. package/dist/react.d.cts +38 -4
  36. package/dist/react.d.ts +38 -4
  37. package/dist/react.js +93 -1
  38. package/dist/react.js.map +1 -1
  39. package/dist/{types-BnzoaNRC.d.cts → types-BaBzjwXr.d.cts} +1 -1
  40. package/dist/{types-BnzoaNRC.d.ts → types-BaBzjwXr.d.ts} +1 -1
  41. package/dist/{pipeline-CQgV-Yfo.d.ts → types-CeBPrnGj.d.ts} +2 -7
  42. package/dist/{pipeline-C-cN0ACi.d.cts → types-CpqL-pZx.d.cts} +2 -7
  43. package/package.json +36 -17
  44. package/dist/model-form-Bm_kqCn2.d.ts +0 -92
  45. package/dist/model-form-DkS48fsh.d.cts +0 -92
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # athena-js
2
2
 
3
- current version: `1.9.0`
3
+ current version: `2.1.2`
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
@@ -45,48 +45,45 @@ if (error) {
45
45
 
46
46
  ### Auth client (Athena Auth server)
47
47
 
48
- If your auth backend is now Athena Auth, you can keep core login/session flows in this SDK:
49
-
50
- ```ts
51
- import { createAuthClient } from "@xylex-group/athena";
52
-
53
- const auth = createAuthClient({
54
- baseUrl: "http://localhost:3001/api/auth",
55
- // optional: bearer token if you are not using cookie-based sessions
56
- bearerToken: process.env.AUTH_BEARER_TOKEN,
57
- });
58
-
59
- const login = await auth.signIn.email({
60
- email: "demo@example.com",
61
- password: "super-secret",
62
- rememberMe: true,
63
- });
64
-
65
- const session = await auth.getSession();
66
- const sessions = await auth.listSessions();
67
-
68
- // clear one session
69
- await auth.revokeSession({ token: "session_token_here" });
70
- // or clear all sessions
71
- await auth.revokeSessions();
72
-
73
- await auth.signOut();
74
-
75
- // additional core flows
76
- await auth.forgetPassword({ email: "demo@example.com", redirectTo: "https://app/reset-password" });
77
- await auth.resetPassword({ newPassword: "new-secret", token: "reset_token" });
78
- await auth.verifyEmail({ token: "verify_token", callbackURL: "https://app/verified" });
79
- await auth.changePassword({ currentPassword: "old-secret", newPassword: "new-secret" });
80
- await auth.updateUser({ name: "Demo User" });
81
-
82
- // escape hatch for any endpoint on your Athena Auth instance
83
- await auth.request({
84
- endpoint: "/ok",
85
- query: { ping: "pong" },
86
- });
87
- ```
88
-
89
- Auth responses follow the same envelope style: `{ ok, status, data, error, errorDetails, raw }`.
48
+ If your auth backend is now Athena Auth, you can keep core login/session flows in this SDK:
49
+
50
+ ```ts
51
+ import { createClient } from "@xylex-group/athena";
52
+
53
+ const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
54
+ client: "CLIENT_NAME",
55
+ auth: {
56
+ baseUrl: "http://localhost:3001/api/auth",
57
+ // optional: bearer token if you are not using cookie-based sessions
58
+ bearerToken: process.env.AUTH_BEARER_TOKEN,
59
+ },
60
+ });
61
+
62
+ const login = await athena.auth.signIn.email({
63
+ email: "demo@example.com",
64
+ password: "super-secret",
65
+ rememberMe: true,
66
+ });
67
+
68
+ const session = await athena.auth.getSession();
69
+ const sessions = await athena.auth.session.list();
70
+
71
+ // clear one session
72
+ await athena.auth.session.revoke({ token: "session_token_here" });
73
+ // or clear all sessions
74
+ await athena.auth.session.revoke([{ token: "session_token_here" }, { token: "session_token_2" }]);
75
+
76
+ await athena.auth.signOut();
77
+
78
+ // additional core flows
79
+ await athena.auth.forgetPassword({ email: "demo@example.com", redirectTo: "https://app/reset-password" });
80
+ await athena.auth.resetPassword({ newPassword: "new-secret", token: "reset_token" });
81
+ await athena.auth.verifyEmail({ token: "verify_token", callbackURL: "https://app/verified" });
82
+ await athena.auth.changePassword({ currentPassword: "old-secret", newPassword: "new-secret" });
83
+ await athena.auth.user.update({ name: "Demo User" });
84
+ ```
85
+
86
+ Auth responses follow the same envelope style: `{ ok, status, data, error, errorDetails, raw }`.
90
87
 
91
88
  ### Typed schema registry (model-first)
92
89
 
@@ -209,24 +206,27 @@ requireAffected(inserted, { min: 1 }, { table: "users", operation: "insert" });
209
206
 
210
207
  `requireAffected` uses `result.count`; request it on writes with `{ count: "exact" }` when you need enforced postconditions.
211
208
 
212
- ### Error normalization
213
-
214
- ```ts
215
- import { normalizeAthenaError } from "@xylex-group/athena";
216
-
217
- const result = await athena.from("users").insert({ id: 1 }).select();
218
- if (result.error) {
219
- const err = normalizeAthenaError(result, {
220
- table: "users",
221
- operation: "insert",
222
- });
223
- if (err.kind === "unique_violation") {
224
- // deterministic conflict handling
225
- }
226
- }
227
- ```
228
-
229
- Normalized errors expose stable `kind` values (`unique_violation`, `validation`, `auth`, `rate_limit`, `transient`, etc.) plus operation metadata.
209
+ ### Error normalization
210
+
211
+ ```ts
212
+ import { createClient, normalizeAthenaError } from "@xylex-group/athena";
213
+
214
+ const athena = createClient(ATHENA_URL, ATHENA_API_KEY, {
215
+ experimental: { enableErrorNormalization: true },
216
+ });
217
+
218
+ const result = await athena.from("users").insert({ id: 1 }).select();
219
+ if (result.error) {
220
+ const err = normalizeAthenaError(result);
221
+ if (err.kind === "unique_violation") {
222
+ // deterministic conflict handling
223
+ }
224
+ }
225
+ ```
226
+
227
+ Normalized errors expose stable `kind` values (`unique_violation`, `validation`, `auth`, `rate_limit`, `transient`, etc.) plus operation metadata.
228
+
229
+ `experimental.enableErrorNormalization` keeps the existing `AthenaResult<T>` shape intact and pre-attaches context-aware metadata so `normalizeAthenaError(result)` can resolve table/operation without extra per-call context objects.
230
230
 
231
231
  ### Numeric coercion
232
232
 
@@ -257,13 +257,31 @@ const result = await withRetry(
257
257
 
258
258
  By default, retries target transient/rate-limit failures; use `shouldRetry` for custom policies.
259
259
 
260
- ## Query builder
261
-
262
- ### Reading rows
263
-
264
- ```ts
265
- // select all columns
266
- const { data } = await athena.from("users").select();
260
+ ## Query builder
261
+
262
+ ### DB module namespace
263
+
264
+ `createClient()` keeps root methods (`from`, `rpc`, `query`) and now also exposes `db` as an additive namespace.
265
+
266
+ ```ts
267
+ const athena = createClient(ATHENA_URL, ATHENA_API_KEY);
268
+
269
+ await athena.db.from("users").select("id,name").eq("active", true).limit(20);
270
+
271
+ await athena.db.select("users", "id,name").eq("id", 1).single();
272
+
273
+ await athena.db.insert("users", { id: 1, name: "Alice" }).select("id");
274
+ await athena.db.update("users", { name: "Updated" }).eq("id", 1).select("id,name");
275
+ await athena.db.delete("users", { resourceId: "r-1" }).select("id");
276
+ ```
277
+
278
+ `db` mirrors the existing query builder semantics while providing a module seam for future database-surface expansion.
279
+
280
+ ### Reading rows
281
+
282
+ ```ts
283
+ // select all columns
284
+ const { data } = await athena.from("users").select();
267
285
 
268
286
  // select specific columns
269
287
  const { data } = await athena.from("users").select("id, name, email");
package/bin/athena-js.js CHANGED
File without changes