@xylex-group/athena 2.6.0 → 2.8.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.
Files changed (44) hide show
  1. package/README.md +210 -17
  2. package/dist/browser.cjs +2102 -527
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.cts +8 -7
  5. package/dist/browser.d.ts +8 -7
  6. package/dist/browser.js +2096 -528
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +2116 -559
  9. package/dist/cli/index.cjs.map +1 -1
  10. package/dist/cli/index.d.cts +3 -3
  11. package/dist/cli/index.d.ts +3 -3
  12. package/dist/cli/index.js +2116 -559
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/cookies.cjs +10 -3
  15. package/dist/cookies.cjs.map +1 -1
  16. package/dist/cookies.js +10 -3
  17. package/dist/cookies.js.map +1 -1
  18. package/dist/index.cjs +2694 -748
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +8 -7
  21. package/dist/index.d.ts +8 -7
  22. package/dist/index.js +2688 -749
  23. package/dist/index.js.map +1 -1
  24. package/dist/model-form-DMed05gE.d.cts +3037 -0
  25. package/dist/model-form-DXPlOnlI.d.ts +3037 -0
  26. package/dist/{pipeline-Ce3pTw5h.d.ts → pipeline-CkMnhwPI.d.ts} +1 -1
  27. package/dist/{pipeline-D1ZYeoH7.d.cts → pipeline-D4sJRKqN.d.cts} +1 -1
  28. package/dist/react-email-DZhDDlEl.d.cts +417 -0
  29. package/dist/react-email-Lrz9A-BW.d.ts +417 -0
  30. package/dist/react.cjs +178 -71
  31. package/dist/react.cjs.map +1 -1
  32. package/dist/react.d.cts +22 -5
  33. package/dist/react.d.ts +22 -5
  34. package/dist/react.js +92 -5
  35. package/dist/react.js.map +1 -1
  36. package/dist/{types-CUuo4NDi.d.cts → types-BzY6fETM.d.ts} +47 -5
  37. package/dist/{types-DapchQY5.d.ts → types-CAtTGGoz.d.cts} +47 -5
  38. package/dist/{types-DSX6AT5B.d.cts → types-vikz9YIO.d.cts} +23 -1
  39. package/dist/{types-DSX6AT5B.d.ts → types-vikz9YIO.d.ts} +23 -1
  40. package/package.json +194 -193
  41. package/dist/model-form-BaHWi3gm.d.cts +0 -1383
  42. package/dist/model-form-Dh6gWjL0.d.ts +0 -1383
  43. package/dist/react-email-B8O1Jeff.d.cts +0 -1230
  44. package/dist/react-email-CDEF0jij.d.ts +0 -1230
package/dist/browser.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { z } from 'zod';
2
+
1
3
  // src/gateway/errors.ts
2
4
  var AthenaGatewayError = class _AthenaGatewayError extends Error {
3
5
  code;
@@ -666,9 +668,16 @@ var getSessionCookie = (request, config) => {
666
668
  const { cookieName = "session_token", cookiePrefix = "athena-auth" } = config || {};
667
669
  const parsedCookie = parseCookies(cookies);
668
670
  const getCookie = (name) => parsedCookie.get(name) || parsedCookie.get(`${SECURE_COOKIE_PREFIX}${name}`);
669
- const sessionToken = getCookie(`${cookiePrefix}.${cookieName}`) || getCookie(`${cookiePrefix}-${cookieName}`);
670
- if (sessionToken) {
671
- return sessionToken;
671
+ const candidateCookieNames = Array.from(/* @__PURE__ */ new Set([
672
+ cookieName,
673
+ cookieName.replace(/_/g, "-"),
674
+ cookieName.replace(/-/g, "_")
675
+ ])).filter(Boolean);
676
+ for (const candidateName of candidateCookieNames) {
677
+ const sessionToken = getCookie(`${cookiePrefix}.${candidateName}`) || getCookie(`${cookiePrefix}-${candidateName}`);
678
+ if (sessionToken) {
679
+ return sessionToken;
680
+ }
672
681
  }
673
682
  return null;
674
683
  };
@@ -791,7 +800,7 @@ var getCookieCache = async (request, config) => {
791
800
 
792
801
  // package.json
793
802
  var package_default = {
794
- version: "2.6.0"
803
+ version: "2.8.0"
795
804
  };
796
805
 
797
806
  // src/sdk-version.ts
@@ -3108,7 +3117,7 @@ function normalizeAthenaError(resultOrError, context) {
3108
3117
  const details = resultOrError.errorDetails;
3109
3118
  const message2 = messageFromUnknownError(resultOrError.error) ?? details?.message ?? `Athena ${context?.operation ?? operationFromDetails(details) ?? "request"} failed`;
3110
3119
  const operation = context?.operation ?? operationFromDetails(details);
3111
- const table = context?.table ?? extractTable(message2);
3120
+ const table2 = context?.table ?? extractTable(message2);
3112
3121
  const constraint = extractConstraint(message2);
3113
3122
  const gatewayCode = details?.code ?? gatewayCodeFromUnknownError(resultOrError.error);
3114
3123
  const kind2 = classifyKind(resultOrError.status, gatewayCode, message2);
@@ -3121,7 +3130,7 @@ function normalizeAthenaError(resultOrError, context) {
3121
3130
  retryable: isRetryable(kind2, resultOrError.status),
3122
3131
  status: resultOrError.status,
3123
3132
  constraint,
3124
- table,
3133
+ table: table2,
3125
3134
  operation,
3126
3135
  message: message2,
3127
3136
  raw: resultOrError.raw
@@ -3130,7 +3139,7 @@ function normalizeAthenaError(resultOrError, context) {
3130
3139
  if (isAthenaGatewayError(resultOrError)) {
3131
3140
  const details = resultOrError.toDetails();
3132
3141
  const operation = context?.operation ?? operationFromDetails(details);
3133
- const table = context?.table ?? extractTable(resultOrError.message);
3142
+ const table2 = context?.table ?? extractTable(resultOrError.message);
3134
3143
  const constraint = extractConstraint(resultOrError.message);
3135
3144
  const kind2 = classifyKind(resultOrError.status, resultOrError.code, resultOrError.message);
3136
3145
  const code = toAthenaErrorCode(kind2, resultOrError.status, resultOrError.code);
@@ -3142,7 +3151,7 @@ function normalizeAthenaError(resultOrError, context) {
3142
3151
  retryable: isRetryable(kind2, resultOrError.status),
3143
3152
  status: resultOrError.status,
3144
3153
  constraint,
3145
- table,
3154
+ table: table2,
3146
3155
  operation,
3147
3156
  message: resultOrError.message,
3148
3157
  raw: resultOrError
@@ -3338,23 +3347,24 @@ async function withRetry(config, fn) {
3338
3347
  // src/db/module.ts
3339
3348
  function createDbModule(input) {
3340
3349
  const db = {
3341
- from(table, options) {
3342
- return input.from(table, options);
3343
- },
3344
- select(table, columns, options) {
3345
- return input.from(table).select(columns, options);
3350
+ from: input.from,
3351
+ select(table2, first, second) {
3352
+ if (first && typeof first === "object" && !Array.isArray(first)) {
3353
+ return input.from(table2).select(void 0, first);
3354
+ }
3355
+ return input.from(table2).select(first, second);
3346
3356
  },
3347
- insert(table, values, options) {
3348
- return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
3357
+ insert(table2, values, options) {
3358
+ return Array.isArray(values) ? input.from(table2).insert(values, options) : input.from(table2).insert(values, options);
3349
3359
  },
3350
- upsert(table, values, options) {
3351
- return Array.isArray(values) ? input.from(table).upsert(values, options) : input.from(table).upsert(values, options);
3360
+ upsert(table2, values, options) {
3361
+ return Array.isArray(values) ? input.from(table2).upsert(values, options) : input.from(table2).upsert(values, options);
3352
3362
  },
3353
- update(table, values, options) {
3354
- return input.from(table).update(values, options);
3363
+ update(table2, values, options) {
3364
+ return input.from(table2).update(values, options);
3355
3365
  },
3356
- delete(table, options) {
3357
- return input.from(table).delete(options);
3366
+ delete(table2, options) {
3367
+ return input.from(table2).delete(options);
3358
3368
  },
3359
3369
  rpc(fn, args, options) {
3360
3370
  return input.rpc(fn, args, options);
@@ -3366,6 +3376,344 @@ function createDbModule(input) {
3366
3376
  return db;
3367
3377
  }
3368
3378
 
3379
+ // src/storage/file.ts
3380
+ function createStorageFileModule(base, config = {}) {
3381
+ const upload = async (input, options) => {
3382
+ const sources = normalizeUploadSources(input);
3383
+ validateUploadConstraints(sources, input);
3384
+ const uploadRequests = sources.map((source, index) => {
3385
+ const storageKey = resolveUploadStorageKey(input, source, index, options, config);
3386
+ return {
3387
+ source,
3388
+ uploadRequest: {
3389
+ s3_id: input.s3_id,
3390
+ bucket: input.bucket,
3391
+ storage_key: storageKey,
3392
+ name: input.name ?? source.fileName,
3393
+ original_name: input.original_name ?? source.fileName,
3394
+ resource_id: input.resource_id ?? input.resourceId,
3395
+ mime_type: input.mime_type ?? source.contentType,
3396
+ content_type: input.content_type ?? source.contentType,
3397
+ size_bytes: source.sizeBytes,
3398
+ public: input.public,
3399
+ metadata: input.metadata
3400
+ }
3401
+ };
3402
+ });
3403
+ input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
3404
+ const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request) => request.uploadRequest) }, options)).files;
3405
+ const aggregateLoaded = new Array(uploadRequests.length).fill(0);
3406
+ const uploaded = [];
3407
+ for (let index = 0; index < uploadRequests.length; index += 1) {
3408
+ const request = uploadRequests[index];
3409
+ const uploadUrl = uploadUrls[index];
3410
+ const response = await putUploadBody(uploadUrl.upload.url, request.source, input, options, (progress) => {
3411
+ aggregateLoaded[index] = progress.loaded;
3412
+ input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3413
+ });
3414
+ uploaded.push({
3415
+ file: uploadUrl.file,
3416
+ upload: uploadUrl.upload,
3417
+ source: request.source.source,
3418
+ fileName: request.source.fileName,
3419
+ storage_key: request.uploadRequest.storage_key,
3420
+ response
3421
+ });
3422
+ aggregateLoaded[index] = request.source.sizeBytes;
3423
+ input.onProgress?.(createProgressSnapshot("complete", sources, index, request.source.sizeBytes, sum(aggregateLoaded)));
3424
+ }
3425
+ return {
3426
+ files: uploaded,
3427
+ count: uploaded.length
3428
+ };
3429
+ };
3430
+ const download = ((input, queryOrOptions, maybeOptions) => {
3431
+ const { fileIds, query, options } = normalizeDownloadArgs(input, queryOrOptions, maybeOptions);
3432
+ const downloads = fileIds.map((fileId) => base.getStorageFileProxy(fileId, query, options));
3433
+ return Array.isArray(input) || isRecord5(input) && Array.isArray(input.fileIds) ? Promise.all(downloads) : downloads[0];
3434
+ });
3435
+ const deleteFile = ((input, options) => {
3436
+ if (Array.isArray(input)) {
3437
+ return Promise.all(input.map((fileId) => base.deleteStorageFile(fileId, options)));
3438
+ }
3439
+ return base.deleteStorageFile(input, options);
3440
+ });
3441
+ return {
3442
+ upload,
3443
+ download,
3444
+ list(input, options) {
3445
+ const prefix = resolveStoragePath(input.prefix ?? "", input, options, config);
3446
+ return base.listStorageFiles(
3447
+ {
3448
+ s3_id: input.s3_id,
3449
+ prefix
3450
+ },
3451
+ options
3452
+ );
3453
+ },
3454
+ delete: deleteFile
3455
+ };
3456
+ }
3457
+ function resolveStoragePath(path, input, options, config = {}) {
3458
+ const context = createPathContext(input, options, config);
3459
+ const prefixPath = input.prefixPath ?? config.prefixPath;
3460
+ const prefix = typeof prefixPath === "function" ? prefixPath(context) : prefixPath;
3461
+ return joinStoragePath(renderStorageTemplate(prefix ?? "", context), renderStorageTemplate(path, context));
3462
+ }
3463
+ function resolveUploadStorageKey(input, source, index, options, config) {
3464
+ const explicitKey = input.storage_key ?? input.storageKey;
3465
+ const keyTemplate = input.storageKeyTemplate;
3466
+ const fallbackName = source.fileName;
3467
+ const context = createPathContext(input, options, config);
3468
+ const key = keyTemplate ? renderStorageTemplate(keyTemplate, {
3469
+ ...context,
3470
+ vars: {
3471
+ ...context.vars,
3472
+ index,
3473
+ fileName: source.fileName,
3474
+ name: source.fileName
3475
+ }
3476
+ }) : explicitKey ?? fallbackName;
3477
+ return resolveStoragePath(key, input, options, config);
3478
+ }
3479
+ function normalizeUploadSources(input) {
3480
+ const files = toArray(input.files);
3481
+ if (files.length === 0) {
3482
+ throw new Error("athena.storage.file.upload requires at least one file");
3483
+ }
3484
+ return files.map((source, index) => {
3485
+ const fileName = input.fileName ?? sourceName(source) ?? `file-${index + 1}`;
3486
+ const sizeBytes = sourceSize(source);
3487
+ const contentType = input.content_type ?? input.mime_type ?? sourceContentType(source);
3488
+ return {
3489
+ source,
3490
+ fileName,
3491
+ sizeBytes,
3492
+ contentType
3493
+ };
3494
+ });
3495
+ }
3496
+ function validateUploadConstraints(sources, input) {
3497
+ const maxFiles = input.maxFiles ?? 1;
3498
+ if (sources.length > maxFiles) {
3499
+ throw new Error(`athena.storage.file.upload accepts at most ${maxFiles} file${maxFiles === 1 ? "" : "s"} for this call`);
3500
+ }
3501
+ const maxFileSizeBytes = input.maxFileSizeBytes ?? (input.maxFileSizeMb === void 0 ? void 0 : Math.floor(input.maxFileSizeMb * 1024 * 1024));
3502
+ if (maxFileSizeBytes !== void 0) {
3503
+ const tooLarge = sources.find((source) => source.sizeBytes > maxFileSizeBytes);
3504
+ if (tooLarge) {
3505
+ throw new Error(`athena.storage.file.upload rejected ${tooLarge.fileName}: file exceeds ${maxFileSizeBytes} bytes`);
3506
+ }
3507
+ }
3508
+ const allowedExtensions = normalizeExtensions(input.allowedExtensions ?? input.extensions);
3509
+ if (allowedExtensions.size > 0) {
3510
+ const invalid = sources.find((source) => !allowedExtensions.has(fileExtension(source.fileName)));
3511
+ if (invalid) {
3512
+ throw new Error(`athena.storage.file.upload rejected ${invalid.fileName}: extension is not allowed`);
3513
+ }
3514
+ }
3515
+ }
3516
+ async function putUploadBody(url, source, input, options, onProgress) {
3517
+ const headers = new Headers(input.uploadHeaders);
3518
+ if (source.contentType && !headers.has("Content-Type")) {
3519
+ headers.set("Content-Type", source.contentType);
3520
+ }
3521
+ if (typeof XMLHttpRequest !== "undefined") {
3522
+ return putUploadBodyWithXhr(url, source, headers, options, onProgress);
3523
+ }
3524
+ onProgress({ loaded: 0 });
3525
+ const response = await fetch(url, {
3526
+ method: "PUT",
3527
+ headers,
3528
+ body: source.source,
3529
+ signal: options?.signal
3530
+ });
3531
+ if (!response.ok) {
3532
+ throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
3533
+ }
3534
+ onProgress({ loaded: source.sizeBytes });
3535
+ return response;
3536
+ }
3537
+ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3538
+ const Xhr = XMLHttpRequest;
3539
+ if (Xhr === void 0) {
3540
+ return Promise.reject(new Error("athena.storage.file.upload requires XMLHttpRequest in this runtime"));
3541
+ }
3542
+ return new Promise((resolve, reject) => {
3543
+ const xhr = new Xhr();
3544
+ const abort = () => xhr.abort();
3545
+ xhr.open("PUT", url);
3546
+ headers.forEach((value, key) => xhr.setRequestHeader(key, value));
3547
+ xhr.upload.onprogress = (event) => {
3548
+ onProgress({ loaded: event.loaded });
3549
+ };
3550
+ xhr.onload = () => {
3551
+ if (options?.signal) {
3552
+ options.signal.removeEventListener("abort", abort);
3553
+ }
3554
+ if (xhr.status < 200 || xhr.status >= 300) {
3555
+ reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
3556
+ return;
3557
+ }
3558
+ onProgress({ loaded: source.sizeBytes });
3559
+ resolve(new Response(xhr.response, {
3560
+ status: xhr.status,
3561
+ statusText: xhr.statusText,
3562
+ headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3563
+ }));
3564
+ };
3565
+ xhr.onerror = () => {
3566
+ if (options?.signal) {
3567
+ options.signal.removeEventListener("abort", abort);
3568
+ }
3569
+ reject(new Error("athena.storage.file.upload failed with a network error"));
3570
+ };
3571
+ xhr.onabort = () => {
3572
+ if (options?.signal) {
3573
+ options.signal.removeEventListener("abort", abort);
3574
+ }
3575
+ reject(new DOMException("Upload aborted", "AbortError"));
3576
+ };
3577
+ if (options?.signal) {
3578
+ if (options.signal.aborted) {
3579
+ abort();
3580
+ return;
3581
+ }
3582
+ options.signal.addEventListener("abort", abort, { once: true });
3583
+ }
3584
+ xhr.send(source.source);
3585
+ });
3586
+ }
3587
+ function normalizeDownloadArgs(input, queryOrOptions, maybeOptions) {
3588
+ if (typeof input === "string") {
3589
+ return { fileIds: [input], query: queryOrOptions, options: maybeOptions };
3590
+ }
3591
+ if (Array.isArray(input)) {
3592
+ return { fileIds: [...input], query: queryOrOptions, options: maybeOptions };
3593
+ }
3594
+ const downloadInput = input;
3595
+ const { fileId, fileIds, ...query } = downloadInput;
3596
+ return {
3597
+ fileIds: fileIds ? [...fileIds] : fileId ? [fileId] : [],
3598
+ query,
3599
+ options: queryOrOptions
3600
+ };
3601
+ }
3602
+ function createPathContext(input, options, config) {
3603
+ const organizationId = input.organizationId ?? input.organization_id ?? options?.organizationId ?? void 0;
3604
+ const userId = input.userId ?? input.user_id ?? options?.userId ?? void 0;
3605
+ const resourceId = input.resourceId ?? input.resource_id ?? void 0;
3606
+ const vars = {
3607
+ ...config.vars ?? {},
3608
+ ...input.vars ?? {}
3609
+ };
3610
+ if (organizationId !== void 0) {
3611
+ vars.organizationId = organizationId;
3612
+ vars.organization_id = organizationId;
3613
+ }
3614
+ if (userId !== void 0) {
3615
+ vars.userId = userId;
3616
+ vars.user_id = userId;
3617
+ }
3618
+ if (resourceId !== void 0) {
3619
+ vars.resourceId = resourceId;
3620
+ vars.resource_id = resourceId;
3621
+ }
3622
+ return {
3623
+ vars,
3624
+ env: {
3625
+ ...readProcessEnv(),
3626
+ ...config.env ?? {},
3627
+ ...input.env ?? {}
3628
+ },
3629
+ organizationId,
3630
+ organization_id: organizationId,
3631
+ userId,
3632
+ user_id: userId,
3633
+ resourceId,
3634
+ resource_id: resourceId
3635
+ };
3636
+ }
3637
+ function renderStorageTemplate(template, context) {
3638
+ return template.replace(/\$\{([^}]+)\}|\{([^}]+)\}/g, (_match, shellToken, braceToken) => {
3639
+ const token = (shellToken ?? braceToken ?? "").trim();
3640
+ if (!token) return "";
3641
+ const value = resolveTemplateToken(token, context);
3642
+ return value === void 0 || value === null ? "" : String(value);
3643
+ });
3644
+ }
3645
+ function resolveTemplateToken(token, context) {
3646
+ if (token.startsWith("env.")) {
3647
+ return context.env[token.slice(4)];
3648
+ }
3649
+ if (token in context.vars) {
3650
+ return context.vars[token];
3651
+ }
3652
+ return context.env[token];
3653
+ }
3654
+ function joinStoragePath(...parts) {
3655
+ return parts.map((part) => part.trim().replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
3656
+ }
3657
+ function toArray(files) {
3658
+ if (isUploadSource(files)) return [files];
3659
+ return Array.from(files);
3660
+ }
3661
+ function isUploadSource(value) {
3662
+ return value instanceof Blob || value instanceof ArrayBuffer || value instanceof Uint8Array;
3663
+ }
3664
+ function sourceName(source) {
3665
+ return isRecord5(source) && typeof source.name === "string" && source.name.trim() ? source.name.trim() : void 0;
3666
+ }
3667
+ function sourceSize(source) {
3668
+ if (source instanceof Blob) return source.size;
3669
+ return source.byteLength;
3670
+ }
3671
+ function sourceContentType(source) {
3672
+ return source instanceof Blob && source.type.trim() ? source.type.trim() : void 0;
3673
+ }
3674
+ function normalizeExtensions(extensions) {
3675
+ return new Set((extensions ?? []).map((extension) => extension.replace(/^\./, "").toLowerCase()).filter(Boolean));
3676
+ }
3677
+ function fileExtension(fileName) {
3678
+ const lastDot = fileName.lastIndexOf(".");
3679
+ return lastDot === -1 ? "" : fileName.slice(lastDot + 1).toLowerCase();
3680
+ }
3681
+ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoaded) {
3682
+ const total = sources[fileIndex]?.sizeBytes ?? 0;
3683
+ const aggregateTotal = sources.reduce((totalBytes, source) => totalBytes + source.sizeBytes, 0);
3684
+ return {
3685
+ phase,
3686
+ fileIndex,
3687
+ fileCount: sources.length,
3688
+ fileName: sources[fileIndex]?.fileName ?? "",
3689
+ loaded,
3690
+ total,
3691
+ percent: total > 0 ? Math.round(loaded / total * 100) : 100,
3692
+ aggregateLoaded,
3693
+ aggregateTotal,
3694
+ aggregatePercent: aggregateTotal > 0 ? Math.round(aggregateLoaded / aggregateTotal * 100) : 100
3695
+ };
3696
+ }
3697
+ function sum(values) {
3698
+ return values.reduce((total, value) => total + value, 0);
3699
+ }
3700
+ function parseXhrHeaders(raw) {
3701
+ const headers = new Headers();
3702
+ for (const line of raw.trim().split(/[\r\n]+/)) {
3703
+ const index = line.indexOf(":");
3704
+ if (index === -1) continue;
3705
+ headers.set(line.slice(0, index).trim(), line.slice(index + 1).trim());
3706
+ }
3707
+ return headers;
3708
+ }
3709
+ function readProcessEnv() {
3710
+ const processLike = globalThis.process;
3711
+ return processLike?.env ?? {};
3712
+ }
3713
+ function isRecord5(value) {
3714
+ return Boolean(value) && typeof value === "object";
3715
+ }
3716
+
3369
3717
  // src/storage/module.ts
3370
3718
  var storageSdkManifest = {
3371
3719
  namespace: "storage",
@@ -3574,7 +3922,7 @@ var AthenaStorageError = class extends Error {
3574
3922
  };
3575
3923
  }
3576
3924
  };
3577
- function isRecord5(value) {
3925
+ function isRecord6(value) {
3578
3926
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3579
3927
  }
3580
3928
  function causeToString(cause) {
@@ -3685,11 +4033,20 @@ function appendQuery(path, query) {
3685
4033
  function storagePath(path) {
3686
4034
  return path;
3687
4035
  }
4036
+ function resolveStorageEndpointPath(endpoint, runtimeOptions) {
4037
+ if (!runtimeOptions?.stripBasePath) {
4038
+ return endpoint;
4039
+ }
4040
+ const [pathname, queryText] = String(endpoint).split("?", 2);
4041
+ const trimmedPathname = pathname.startsWith("/storage/") ? pathname.slice("/storage".length) : pathname === "/storage" ? "/" : pathname;
4042
+ const resolvedPath = trimmedPathname.startsWith("/") ? trimmedPathname : `/${trimmedPathname}`;
4043
+ return storagePath(queryText ? `${resolvedPath}?${queryText}` : resolvedPath);
4044
+ }
3688
4045
  function withPathParam(path, name, value) {
3689
4046
  return path.replace(`{${name}}`, encodeURIComponent(value));
3690
4047
  }
3691
4048
  function resolveErrorMessage3(payload, fallback) {
3692
- if (isRecord5(payload)) {
4049
+ if (isRecord6(payload)) {
3693
4050
  const message = payload.message ?? payload.error ?? payload.details;
3694
4051
  if (typeof message === "string" && message.trim()) {
3695
4052
  return message.trim();
@@ -3701,12 +4058,12 @@ function resolveErrorMessage3(payload, fallback) {
3701
4058
  return fallback;
3702
4059
  }
3703
4060
  function resolveErrorHint2(payload) {
3704
- if (!isRecord5(payload)) return void 0;
4061
+ if (!isRecord6(payload)) return void 0;
3705
4062
  const hint = payload.hint ?? payload.suggestion;
3706
4063
  return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
3707
4064
  }
3708
4065
  function resolveErrorCause(payload) {
3709
- if (!isRecord5(payload)) return void 0;
4066
+ if (!isRecord6(payload)) return void 0;
3710
4067
  const cause = payload.cause ?? payload.reason;
3711
4068
  return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
3712
4069
  }
@@ -3723,8 +4080,8 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
3723
4080
  let url;
3724
4081
  let headers;
3725
4082
  try {
3726
- const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
3727
- url = buildAthenaGatewayUrl(baseUrl, endpoint);
4083
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
4084
+ url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
3728
4085
  headers = gateway.buildHeaders(options);
3729
4086
  } catch (error) {
3730
4087
  return rejectStorageError(
@@ -3825,7 +4182,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
3825
4182
  );
3826
4183
  }
3827
4184
  if (envelope === "athena") {
3828
- if (!isRecord5(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4185
+ if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
3829
4186
  return rejectStorageError(
3830
4187
  {
3831
4188
  code: "INVALID_ATHENA_ENVELOPE",
@@ -3848,8 +4205,8 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
3848
4205
  let url;
3849
4206
  let headers;
3850
4207
  try {
3851
- const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
3852
- url = buildAthenaGatewayUrl(baseUrl, endpoint);
4208
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
4209
+ url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
3853
4210
  headers = gateway.buildHeaders(options);
3854
4211
  } catch (error) {
3855
4212
  return rejectStorageError(
@@ -3933,129 +4290,678 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
3933
4290
  runtimeOptions
3934
4291
  );
3935
4292
  }
3936
- function createStorageModule(gateway, runtimeOptions) {
4293
+ function isBlobBody(body) {
4294
+ return typeof Blob !== "undefined" && body instanceof Blob;
4295
+ }
4296
+ function isReadableStreamBody(body) {
4297
+ return typeof ReadableStream !== "undefined" && body instanceof ReadableStream;
4298
+ }
4299
+ async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
4300
+ const headers = new Headers(uploadHeaders);
4301
+ Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
4302
+ if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
4303
+ headers.set("Content-Type", body.type);
4304
+ }
4305
+ const init = {
4306
+ method: "PUT",
4307
+ headers,
4308
+ body,
4309
+ signal: options?.signal
4310
+ };
4311
+ if (isReadableStreamBody(body)) {
4312
+ init.duplex = "half";
4313
+ }
4314
+ return fetch(uploadUrl, init);
4315
+ }
4316
+ function attachManagedUpload(upload) {
4317
+ const headers = {};
4318
+ return {
4319
+ ...upload,
4320
+ method: "PUT",
4321
+ headers,
4322
+ expiresAt: upload.expires_at,
4323
+ put(body, options) {
4324
+ return putPresignedUploadBody(upload.url, headers, body, options);
4325
+ }
4326
+ };
4327
+ }
4328
+ function attachUploadHelper(response) {
4329
+ return {
4330
+ ...response,
4331
+ upload: attachManagedUpload(response.upload)
4332
+ };
4333
+ }
4334
+ function attachUploadHelpers(response) {
4335
+ return {
4336
+ files: response.files.map(attachUploadHelper)
4337
+ };
4338
+ }
4339
+ function normalizeUploadUrlRequest(input) {
4340
+ const s3_id = input.s3_id ?? input.s3Id;
4341
+ const storage_key = input.storage_key ?? input.storageKey;
4342
+ if (!s3_id?.trim()) {
4343
+ throw new Error("athena.storage.file.upload requires s3_id or s3Id");
4344
+ }
4345
+ if (!storage_key?.trim()) {
4346
+ throw new Error("athena.storage.file.upload requires storage_key or storageKey");
4347
+ }
4348
+ const fileName = input.fileName?.trim();
4349
+ const originalName = input.originalName?.trim();
3937
4350
  return {
4351
+ s3_id,
4352
+ bucket: input.bucket,
4353
+ storage_key,
4354
+ name: input.name ?? fileName,
4355
+ original_name: input.original_name ?? originalName ?? fileName,
4356
+ resource_id: input.resource_id ?? input.resourceId,
4357
+ mime_type: input.mime_type ?? input.mimeType,
4358
+ content_type: input.content_type ?? input.contentType,
4359
+ size_bytes: input.size_bytes ?? input.sizeBytes,
4360
+ file_id: input.file_id ?? input.fileId,
4361
+ public: input.public,
4362
+ visibility: input.visibility,
4363
+ metadata: input.metadata
4364
+ };
4365
+ }
4366
+ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options, runtimeOptions) {
4367
+ let url;
4368
+ let headers;
4369
+ try {
4370
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
4371
+ url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
4372
+ headers = gateway.buildHeaders(options);
4373
+ } catch (error) {
4374
+ return rejectStorageError(
4375
+ {
4376
+ code: storageCodeFromUnknown(error),
4377
+ message: error instanceof Error ? error.message : `Athena storage PUT ${endpoint} failed before sending the request`,
4378
+ status: isAthenaGatewayError(error) ? error.status : 0,
4379
+ endpoint,
4380
+ method: "PUT",
4381
+ raw: error,
4382
+ requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
4383
+ hint: isAthenaGatewayError(error) ? error.hint : void 0,
4384
+ cause: error
4385
+ },
4386
+ options,
4387
+ runtimeOptions
4388
+ );
4389
+ }
4390
+ delete headers["Content-Type"];
4391
+ delete headers["content-type"];
4392
+ if (isBlobBody(body) && body.type) {
4393
+ headers["Content-Type"] = body.type;
4394
+ }
4395
+ const requestInit = {
4396
+ method: "PUT",
4397
+ headers,
4398
+ body,
4399
+ signal: options?.signal
4400
+ };
4401
+ if (isReadableStreamBody(body)) {
4402
+ requestInit.duplex = "half";
4403
+ }
4404
+ let response;
4405
+ try {
4406
+ response = await fetch(url, requestInit);
4407
+ } catch (error) {
4408
+ const message = error instanceof Error ? error.message : String(error);
4409
+ return rejectStorageError(
4410
+ {
4411
+ code: "NETWORK_ERROR",
4412
+ message: `Network error while calling Athena storage PUT ${endpoint}: ${message}`,
4413
+ status: 0,
4414
+ endpoint,
4415
+ method: "PUT",
4416
+ cause: error
4417
+ },
4418
+ options,
4419
+ runtimeOptions
4420
+ );
4421
+ }
4422
+ let rawText;
4423
+ try {
4424
+ rawText = await response.text();
4425
+ } catch (error) {
4426
+ return rejectStorageError(
4427
+ {
4428
+ code: "NETWORK_ERROR",
4429
+ message: `Athena storage PUT ${endpoint} response body could not be read`,
4430
+ status: response.status,
4431
+ endpoint,
4432
+ method: "PUT",
4433
+ requestId: headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]),
4434
+ cause: error
4435
+ },
4436
+ options,
4437
+ runtimeOptions
4438
+ );
4439
+ }
4440
+ const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
4441
+ const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
4442
+ if (parsedBody.parseFailed) {
4443
+ return rejectStorageError(
4444
+ {
4445
+ code: "INVALID_JSON",
4446
+ message: `Athena storage PUT ${endpoint} returned malformed JSON`,
4447
+ status: response.status,
4448
+ endpoint,
4449
+ method: "PUT",
4450
+ requestId,
4451
+ raw: parsedBody.parsed
4452
+ },
4453
+ options,
4454
+ runtimeOptions
4455
+ );
4456
+ }
4457
+ if (!response.ok) {
4458
+ return rejectStorageError(
4459
+ {
4460
+ code: "HTTP_ERROR",
4461
+ message: resolveErrorMessage3(
4462
+ parsedBody.parsed,
4463
+ `Athena storage PUT ${endpoint} failed with status ${response.status}`
4464
+ ),
4465
+ status: response.status,
4466
+ endpoint,
4467
+ method: "PUT",
4468
+ requestId,
4469
+ hint: resolveErrorHint2(parsedBody.parsed),
4470
+ cause: resolveErrorCause(parsedBody.parsed),
4471
+ raw: parsedBody.parsed
4472
+ },
4473
+ options,
4474
+ runtimeOptions
4475
+ );
4476
+ }
4477
+ if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4478
+ return rejectStorageError(
4479
+ {
4480
+ code: "INVALID_ATHENA_ENVELOPE",
4481
+ message: `Athena storage PUT ${endpoint} returned an invalid Athena envelope`,
4482
+ status: response.status,
4483
+ endpoint,
4484
+ method: "PUT",
4485
+ requestId,
4486
+ raw: parsedBody.parsed
4487
+ },
4488
+ options,
4489
+ runtimeOptions
4490
+ );
4491
+ }
4492
+ return parsedBody.parsed.data;
4493
+ }
4494
+ function createStorageModule(gateway, runtimeOptions) {
4495
+ const resolvedRuntimeOptions = runtimeOptions;
4496
+ const callRaw = (path, method, payload, options) => callStorageEndpoint(
4497
+ gateway,
4498
+ storagePath(path),
4499
+ method,
4500
+ "raw",
4501
+ payload,
4502
+ options,
4503
+ resolvedRuntimeOptions
4504
+ );
4505
+ const callAthena2 = (path, method, payload, options) => callStorageEndpoint(
4506
+ gateway,
4507
+ storagePath(path),
4508
+ method,
4509
+ "athena",
4510
+ payload,
4511
+ options,
4512
+ resolvedRuntimeOptions
4513
+ );
4514
+ const base = {
3938
4515
  listStorageCatalogs(options) {
3939
- return callStorageEndpoint(gateway, storagePath("/storage/catalogs"), "GET", "raw", void 0, options, runtimeOptions);
4516
+ return callRaw("/storage/catalogs", "GET", void 0, options);
3940
4517
  },
3941
4518
  createStorageCatalog(input, options) {
3942
- return callStorageEndpoint(gateway, storagePath("/storage/catalogs"), "POST", "raw", input, options, runtimeOptions);
4519
+ return callRaw("/storage/catalogs", "POST", input, options);
3943
4520
  },
3944
4521
  updateStorageCatalog(id, input, options) {
3945
- return callStorageEndpoint(
3946
- gateway,
3947
- storagePath(withPathParam("/storage/catalogs/{id}", "id", id)),
3948
- "PATCH",
3949
- "raw",
3950
- input,
3951
- options,
3952
- runtimeOptions
3953
- );
4522
+ return callRaw(withPathParam("/storage/catalogs/{id}", "id", id), "PATCH", input, options);
3954
4523
  },
3955
4524
  deleteStorageCatalog(id, options) {
3956
- return callStorageEndpoint(
3957
- gateway,
3958
- storagePath(withPathParam("/storage/catalogs/{id}", "id", id)),
3959
- "DELETE",
3960
- "raw",
3961
- void 0,
3962
- options,
3963
- runtimeOptions
3964
- );
4525
+ return callRaw(withPathParam("/storage/catalogs/{id}", "id", id), "DELETE", void 0, options);
3965
4526
  },
3966
4527
  listStorageCredentials(options) {
3967
- return callStorageEndpoint(gateway, storagePath("/storage/credentials"), "GET", "raw", void 0, options, runtimeOptions);
4528
+ return callRaw("/storage/credentials", "GET", void 0, options);
3968
4529
  },
3969
4530
  createStorageUploadUrl(input, options) {
3970
- return callStorageEndpoint(
3971
- gateway,
3972
- storagePath("/storage/files/upload-url"),
3973
- "POST",
3974
- "athena",
3975
- input,
3976
- options,
3977
- runtimeOptions
3978
- );
4531
+ return callAthena2("/storage/files/upload-url", "POST", input, options);
3979
4532
  },
3980
4533
  createStorageUploadUrls(input, options) {
3981
- return callStorageEndpoint(
3982
- gateway,
3983
- storagePath("/storage/files/upload-urls"),
3984
- "POST",
3985
- "athena",
3986
- input,
3987
- options,
3988
- runtimeOptions
3989
- );
4534
+ return callAthena2("/storage/files/upload-urls", "POST", input, options);
3990
4535
  },
3991
4536
  listStorageFiles(input, options) {
3992
- return callStorageEndpoint(gateway, storagePath("/storage/files/list"), "POST", "athena", input, options, runtimeOptions);
4537
+ return callAthena2("/storage/files/list", "POST", input, options);
3993
4538
  },
3994
4539
  getStorageFile(fileId, options) {
3995
- return callStorageEndpoint(
3996
- gateway,
3997
- storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
3998
- "GET",
3999
- "athena",
4000
- void 0,
4001
- options,
4002
- runtimeOptions
4003
- );
4540
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
4004
4541
  },
4005
4542
  getStorageFileUrl(fileId, query, options) {
4006
4543
  const path = appendQuery(
4007
4544
  withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
4008
4545
  query
4009
4546
  );
4010
- return callStorageEndpoint(gateway, storagePath(path), "GET", "athena", void 0, options, runtimeOptions);
4547
+ return callAthena2(path, "GET", void 0, options);
4011
4548
  },
4012
4549
  getStorageFileProxy(fileId, query, options) {
4013
4550
  const path = appendQuery(
4014
4551
  withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
4015
4552
  query
4016
4553
  );
4017
- return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, runtimeOptions);
4554
+ return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, resolvedRuntimeOptions);
4018
4555
  },
4019
4556
  updateStorageFile(fileId, input, options) {
4020
- return callStorageEndpoint(
4021
- gateway,
4022
- storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
4023
- "PATCH",
4024
- "athena",
4025
- input,
4026
- options,
4027
- runtimeOptions
4028
- );
4557
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "PATCH", input, options);
4029
4558
  },
4030
4559
  deleteStorageFile(fileId, options) {
4031
- return callStorageEndpoint(
4032
- gateway,
4033
- storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
4034
- "DELETE",
4035
- "athena",
4036
- void 0,
4037
- options,
4038
- runtimeOptions
4039
- );
4560
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "DELETE", void 0, options);
4040
4561
  },
4041
4562
  setStorageFileVisibility(fileId, input, options) {
4042
- return callStorageEndpoint(
4563
+ return callAthena2(withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId), "PATCH", input, options);
4564
+ },
4565
+ deleteStorageFolder(input, options) {
4566
+ return callAthena2("/storage/folders/delete", "POST", input, options);
4567
+ },
4568
+ moveStorageFolder(input, options) {
4569
+ return callAthena2("/storage/folders/move", "POST", input, options);
4570
+ }
4571
+ };
4572
+ const fileFacade = createStorageFileModule(base, runtimeOptions);
4573
+ const fileUpload = ((input, options) => {
4574
+ if (isRecord6(input) && "files" in input) {
4575
+ return fileFacade.upload(input, options);
4576
+ }
4577
+ return base.createStorageUploadUrl(
4578
+ normalizeUploadUrlRequest(input),
4579
+ options
4580
+ ).then(attachUploadHelper);
4581
+ });
4582
+ const fileDelete = ((input, options) => fileFacade.delete(input, options));
4583
+ const file = {
4584
+ ...fileFacade,
4585
+ upload: fileUpload,
4586
+ uploadMany(input, options) {
4587
+ return base.createStorageUploadUrls(
4588
+ { files: input.files.map(normalizeUploadUrlRequest) },
4589
+ options
4590
+ ).then(attachUploadHelpers);
4591
+ },
4592
+ confirmUpload(fileId, input, options) {
4593
+ return callAthena2(withPathParam("/storage/files/{file_id}/confirm-upload", "file_id", fileId), "POST", input ?? {}, options);
4594
+ },
4595
+ uploadBinary(fileId, body, options) {
4596
+ return callStorageUploadBinaryEndpoint(
4043
4597
  gateway,
4044
- storagePath(withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId)),
4045
- "PATCH",
4046
- "athena",
4047
- input,
4598
+ storagePath(withPathParam("/storage/files/{file_id}/upload", "file_id", fileId)),
4599
+ body,
4048
4600
  options,
4049
- runtimeOptions
4601
+ resolvedRuntimeOptions
4050
4602
  );
4051
4603
  },
4052
- deleteStorageFolder(input, options) {
4053
- return callStorageEndpoint(gateway, storagePath("/storage/folders/delete"), "POST", "athena", input, options, runtimeOptions);
4604
+ search(input, options) {
4605
+ return callAthena2("/storage/files/search", "POST", input, options);
4054
4606
  },
4055
- moveStorageFolder(input, options) {
4056
- return callStorageEndpoint(gateway, storagePath("/storage/folders/move"), "POST", "athena", input, options, runtimeOptions);
4607
+ get(fileId, options) {
4608
+ return base.getStorageFile(fileId, options);
4609
+ },
4610
+ update(fileId, input, options) {
4611
+ return base.updateStorageFile(fileId, input, options);
4612
+ },
4613
+ delete: fileDelete,
4614
+ deleteMany(input, options) {
4615
+ return callAthena2("/storage/files/delete-many", "POST", input, options);
4616
+ },
4617
+ updateMany(input, options) {
4618
+ return callAthena2("/storage/files/update-many", "POST", input, options);
4619
+ },
4620
+ restore(fileId, options) {
4621
+ return callAthena2(withPathParam("/storage/files/{file_id}/restore", "file_id", fileId), "POST", {}, options);
4622
+ },
4623
+ purge(fileId, options) {
4624
+ return callAthena2(withPathParam("/storage/files/{file_id}/purge", "file_id", fileId), "DELETE", void 0, options);
4625
+ },
4626
+ copy(fileId, input, options) {
4627
+ return callAthena2(withPathParam("/storage/files/{file_id}/copy", "file_id", fileId), "POST", input, options);
4628
+ },
4629
+ url(fileId, query, options) {
4630
+ return base.getStorageFileUrl(fileId, query, options);
4631
+ },
4632
+ publicUrl(fileId, options) {
4633
+ return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
4634
+ },
4635
+ proxy(fileId, query, options) {
4636
+ return base.getStorageFileProxy(fileId, query, options);
4637
+ },
4638
+ visibility: {
4639
+ set(fileId, input, options) {
4640
+ return base.setStorageFileVisibility(fileId, input, options);
4641
+ },
4642
+ setMany(input, options) {
4643
+ return callAthena2("/storage/files/visibility-many", "POST", input, options);
4644
+ }
4645
+ }
4646
+ };
4647
+ const credentials = {
4648
+ list(options) {
4649
+ return base.listStorageCredentials(options);
4650
+ }
4651
+ };
4652
+ const catalog = {
4653
+ list(options) {
4654
+ return base.listStorageCatalogs(options);
4655
+ },
4656
+ create(input, options) {
4657
+ return base.createStorageCatalog(input, options);
4658
+ },
4659
+ update(id, input, options) {
4660
+ return base.updateStorageCatalog(id, input, options);
4661
+ },
4662
+ delete(id, options) {
4663
+ return base.deleteStorageCatalog(id, options);
4664
+ }
4665
+ };
4666
+ const folder = {
4667
+ list(input, options) {
4668
+ return callAthena2("/storage/folders/list", "POST", input, options);
4669
+ },
4670
+ tree(input, options) {
4671
+ return callAthena2("/storage/folders/tree", "POST", input, options);
4672
+ },
4673
+ delete(input, options) {
4674
+ return base.deleteStorageFolder(input, options);
4675
+ },
4676
+ move(input, options) {
4677
+ return base.moveStorageFolder(input, options);
4678
+ }
4679
+ };
4680
+ const permission = {
4681
+ list(input, options) {
4682
+ return callAthena2("/storage/permissions/list", "POST", input, options);
4683
+ },
4684
+ grant(input, options) {
4685
+ return callAthena2("/storage/permissions/grant", "POST", input, options);
4686
+ },
4687
+ revoke(input, options) {
4688
+ return callAthena2("/storage/permissions/revoke", "POST", input, options);
4689
+ },
4690
+ check(input, options) {
4691
+ return callAthena2("/storage/permissions/check", "POST", input, options);
4692
+ }
4693
+ };
4694
+ const objectFolder = {
4695
+ create(input, options) {
4696
+ return callAthena2("/storage/objects/folder", "POST", input, options);
4697
+ },
4698
+ delete(input, options) {
4699
+ return callAthena2("/storage/objects/folder/delete", "POST", input, options);
4700
+ },
4701
+ rename(input, options) {
4702
+ return callAthena2("/storage/objects/folder/rename", "POST", input, options);
4703
+ }
4704
+ };
4705
+ const object = {
4706
+ list(input, options) {
4707
+ return callAthena2("/storage/objects", "POST", input, options);
4708
+ },
4709
+ head(input, options) {
4710
+ return callAthena2("/storage/objects/head", "POST", input, options);
4711
+ },
4712
+ exists(input, options) {
4713
+ return callAthena2("/storage/objects/exists", "POST", input, options);
4714
+ },
4715
+ validate(input, options) {
4716
+ return callAthena2("/storage/objects/validate", "POST", input, options);
4717
+ },
4718
+ update(input, options) {
4719
+ return callAthena2("/storage/objects/update", "POST", input, options);
4720
+ },
4721
+ copy(input, options) {
4722
+ return callAthena2("/storage/objects/copy", "POST", input, options);
4723
+ },
4724
+ url(input, options) {
4725
+ return callAthena2("/storage/objects/url", "POST", input, options);
4726
+ },
4727
+ publicUrl(input, options) {
4728
+ return callAthena2("/storage/objects/public-url", "POST", input, options);
4729
+ },
4730
+ delete(input, options) {
4731
+ return callAthena2("/storage/objects/delete", "POST", input, options);
4732
+ },
4733
+ uploadUrl(input, options) {
4734
+ return callAthena2("/storage/objects/upload-url", "POST", input, options);
4735
+ },
4736
+ folder: objectFolder
4737
+ };
4738
+ const bucket = {
4739
+ list(input, options) {
4740
+ return callAthena2("/storage/buckets/list", "POST", input, options);
4741
+ },
4742
+ create(input, options) {
4743
+ return callAthena2("/storage/buckets/create", "POST", input, options);
4744
+ },
4745
+ delete(input, options) {
4746
+ return callAthena2("/storage/buckets/delete", "POST", input, options);
4747
+ },
4748
+ cors: {
4749
+ get(input, options) {
4750
+ return callAthena2("/storage/buckets/cors", "POST", input, options);
4751
+ },
4752
+ set(input, options) {
4753
+ return callAthena2("/storage/buckets/cors/set", "POST", input, options);
4754
+ },
4755
+ delete(input, options) {
4756
+ return callAthena2("/storage/buckets/cors/delete", "POST", input, options);
4757
+ }
4758
+ }
4759
+ };
4760
+ const multipart = {
4761
+ create(input, options) {
4762
+ return callAthena2("/storage/multipart/create", "POST", input, options);
4763
+ },
4764
+ signPart(input, options) {
4765
+ return callAthena2("/storage/multipart/sign-part", "POST", input, options);
4766
+ },
4767
+ complete(input, options) {
4768
+ return callAthena2("/storage/multipart/complete", "POST", input, options);
4769
+ },
4770
+ abort(input, options) {
4771
+ return callAthena2("/storage/multipart/abort", "POST", input, options);
4772
+ },
4773
+ listParts(input, options) {
4774
+ return callAthena2("/storage/multipart/list-parts", "POST", input, options);
4775
+ }
4776
+ };
4777
+ const audit = {
4778
+ list(input, options) {
4779
+ return callAthena2("/storage/audit/list", "POST", input, options);
4057
4780
  }
4058
4781
  };
4782
+ return {
4783
+ ...base,
4784
+ credentials,
4785
+ catalog,
4786
+ file,
4787
+ folder,
4788
+ permission,
4789
+ object,
4790
+ bucket,
4791
+ multipart,
4792
+ audit,
4793
+ delete: file.delete
4794
+ };
4795
+ }
4796
+
4797
+ // src/client-builder.ts
4798
+ var DEFAULT_BACKEND = { type: "athena" };
4799
+ function toBackendConfig(value) {
4800
+ if (!value) return DEFAULT_BACKEND;
4801
+ return typeof value === "string" ? { type: value } : value;
4802
+ }
4803
+ function mergeHeaders(current, next) {
4804
+ return {
4805
+ ...current ?? {},
4806
+ ...next
4807
+ };
4808
+ }
4809
+ function mergeAuthClientConfig(current, next) {
4810
+ const merged = {
4811
+ ...current ?? {},
4812
+ ...next
4813
+ };
4814
+ if (current?.headers || next.headers) {
4815
+ merged.headers = mergeHeaders(current?.headers, next.headers ?? {});
4816
+ }
4817
+ return merged;
4818
+ }
4819
+ function mergeExperimentalOptions(current, next) {
4820
+ const merged = {
4821
+ ...current ?? {},
4822
+ ...next
4823
+ };
4824
+ if (current?.traceQueries && typeof current.traceQueries === "object" && next.traceQueries && typeof next.traceQueries === "object") {
4825
+ merged.traceQueries = {
4826
+ ...current.traceQueries,
4827
+ ...next.traceQueries
4828
+ };
4829
+ }
4830
+ if (current?.storage || next.storage) {
4831
+ merged.storage = {
4832
+ ...current?.storage ?? {},
4833
+ ...next.storage ?? {}
4834
+ };
4835
+ }
4836
+ return merged;
4837
+ }
4838
+ function resolveBuilderReturn(builder, storageEnabled, strictEnabled) {
4839
+ return builder;
4840
+ }
4841
+ var AthenaClientBuilderImpl = class {
4842
+ constructor(buildClient) {
4843
+ this.buildClient = buildClient;
4844
+ }
4845
+ rootUrl;
4846
+ apiKey;
4847
+ backendConfig = DEFAULT_BACKEND;
4848
+ clientName;
4849
+ defaultHeaders;
4850
+ authConfig;
4851
+ dbUrlOverride;
4852
+ gatewayUrlOverride;
4853
+ authUrlOverride;
4854
+ storageUrlOverride;
4855
+ experimentalOptions;
4856
+ url(url) {
4857
+ this.rootUrl = url;
4858
+ return this;
4859
+ }
4860
+ key(apiKey) {
4861
+ this.apiKey = apiKey;
4862
+ return this;
4863
+ }
4864
+ backend(backend) {
4865
+ this.backendConfig = toBackendConfig(backend);
4866
+ return this;
4867
+ }
4868
+ client(clientName) {
4869
+ this.clientName = clientName;
4870
+ return this;
4871
+ }
4872
+ headers(headers) {
4873
+ this.defaultHeaders = headers;
4874
+ return this;
4875
+ }
4876
+ auth(config) {
4877
+ this.authConfig = mergeAuthClientConfig(this.authConfig, config);
4878
+ return this;
4879
+ }
4880
+ experimental(options) {
4881
+ this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options);
4882
+ if (options.athenaStorageBackend && options.typecheckColumns) {
4883
+ return resolveBuilderReturn(this);
4884
+ }
4885
+ if (options.athenaStorageBackend) {
4886
+ return resolveBuilderReturn(this);
4887
+ }
4888
+ if (options.typecheckColumns) {
4889
+ return resolveBuilderReturn(this);
4890
+ }
4891
+ return this;
4892
+ }
4893
+ options(options) {
4894
+ if (options.client !== void 0) {
4895
+ this.clientName = options.client;
4896
+ }
4897
+ if (options.backend !== void 0) {
4898
+ this.backendConfig = toBackendConfig(options.backend);
4899
+ }
4900
+ if (options.headers !== void 0) {
4901
+ this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
4902
+ }
4903
+ if (options.auth !== void 0) {
4904
+ this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
4905
+ }
4906
+ if (options.db?.url !== void 0 && options.db.url !== null) {
4907
+ this.dbUrlOverride = options.db.url;
4908
+ }
4909
+ if (options.gateway?.url !== void 0 && options.gateway.url !== null) {
4910
+ this.gatewayUrlOverride = options.gateway.url;
4911
+ }
4912
+ if (options.dbUrl !== void 0 && options.dbUrl !== null) {
4913
+ this.dbUrlOverride = options.dbUrl;
4914
+ }
4915
+ if (options.gatewayUrl !== void 0 && options.gatewayUrl !== null) {
4916
+ this.gatewayUrlOverride = options.gatewayUrl;
4917
+ }
4918
+ if (options.authUrl !== void 0 && options.authUrl !== null) {
4919
+ this.authUrlOverride = options.authUrl;
4920
+ }
4921
+ if (options.storage?.url !== void 0 && options.storage.url !== null) {
4922
+ this.storageUrlOverride = options.storage.url;
4923
+ }
4924
+ if (options.storageUrl !== void 0 && options.storageUrl !== null) {
4925
+ this.storageUrlOverride = options.storageUrl;
4926
+ }
4927
+ if (options.experimental !== void 0) {
4928
+ this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options.experimental);
4929
+ }
4930
+ if (options.experimental?.athenaStorageBackend && options.experimental.typecheckColumns) {
4931
+ return resolveBuilderReturn(this);
4932
+ }
4933
+ if (options.experimental?.athenaStorageBackend) {
4934
+ return resolveBuilderReturn(this);
4935
+ }
4936
+ if (options.experimental?.typecheckColumns) {
4937
+ return resolveBuilderReturn(this);
4938
+ }
4939
+ return this;
4940
+ }
4941
+ build() {
4942
+ if (!this.rootUrl && !this.dbUrlOverride && !this.gatewayUrlOverride || !this.apiKey) {
4943
+ throw new Error(
4944
+ "AthenaClient requires key plus either .url() or a db/gateway override before .build()"
4945
+ );
4946
+ }
4947
+ return this.buildClient({
4948
+ url: this.rootUrl,
4949
+ key: this.apiKey,
4950
+ client: this.clientName,
4951
+ backend: this.backendConfig,
4952
+ headers: this.defaultHeaders,
4953
+ db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
4954
+ gateway: this.gatewayUrlOverride ? { url: this.gatewayUrlOverride } : void 0,
4955
+ auth: this.authConfig,
4956
+ authUrl: this.authUrlOverride,
4957
+ storage: this.storageUrlOverride ? { url: this.storageUrlOverride } : void 0,
4958
+ storageUrl: this.storageUrlOverride,
4959
+ experimental: this.experimentalOptions
4960
+ });
4961
+ }
4962
+ };
4963
+ function createAthenaClientBuilder(buildClient) {
4964
+ return new AthenaClientBuilderImpl(buildClient);
4059
4965
  }
4060
4966
 
4061
4967
  // src/query-ast.ts
@@ -4085,7 +4991,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
4085
4991
  "ilike",
4086
4992
  "is"
4087
4993
  ]);
4088
- function isRecord6(value) {
4994
+ function isRecord7(value) {
4089
4995
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4090
4996
  }
4091
4997
  function isUuidString(value) {
@@ -4098,7 +5004,7 @@ function shouldUseUuidTextComparison(column, value) {
4098
5004
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
4099
5005
  }
4100
5006
  function isRelationSelectNode(value) {
4101
- return isRecord6(value) && isRecord6(value.select);
5007
+ return isRecord7(value) && isRecord7(value.select);
4102
5008
  }
4103
5009
  function normalizeIdentifier(value, label) {
4104
5010
  const normalized = value.trim();
@@ -4154,7 +5060,7 @@ function compileRelationToken(key, node) {
4154
5060
  return `${prefix}${relationToken}(${nested})`;
4155
5061
  }
4156
5062
  function compileSelectShape(select) {
4157
- if (!isRecord6(select)) {
5063
+ if (!isRecord7(select)) {
4158
5064
  throw new Error("findMany select must be an object");
4159
5065
  }
4160
5066
  const tokens = [];
@@ -4178,7 +5084,7 @@ function compileSelectShape(select) {
4178
5084
  return tokens.join(",");
4179
5085
  }
4180
5086
  function selectShapeUsesRelationSchema(select) {
4181
- if (!isRecord6(select)) {
5087
+ if (!isRecord7(select)) {
4182
5088
  return false;
4183
5089
  }
4184
5090
  for (const rawValue of Object.values(select)) {
@@ -4196,7 +5102,7 @@ function selectShapeUsesRelationSchema(select) {
4196
5102
  }
4197
5103
  function compileColumnWhere(column, input) {
4198
5104
  const normalizedColumn = normalizeIdentifier(column, "where column");
4199
- if (!isRecord6(input)) {
5105
+ if (!isRecord7(input)) {
4200
5106
  return [buildGatewayCondition("eq", normalizedColumn, input)];
4201
5107
  }
4202
5108
  const conditions = [];
@@ -4224,7 +5130,7 @@ function compileColumnWhere(column, input) {
4224
5130
  return conditions;
4225
5131
  }
4226
5132
  function compileBooleanExpressionTerms(clause, label) {
4227
- if (!isRecord6(clause)) {
5133
+ if (!isRecord7(clause)) {
4228
5134
  throw new Error(`findMany where.${label} clauses must be objects`);
4229
5135
  }
4230
5136
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -4233,7 +5139,7 @@ function compileBooleanExpressionTerms(clause, label) {
4233
5139
  }
4234
5140
  const [rawColumn, rawValue] = entries[0];
4235
5141
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
4236
- if (!isRecord6(rawValue)) {
5142
+ if (!isRecord7(rawValue)) {
4237
5143
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
4238
5144
  }
4239
5145
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -4257,7 +5163,7 @@ function compileWhere(where) {
4257
5163
  if (where === void 0) {
4258
5164
  return void 0;
4259
5165
  }
4260
- if (!isRecord6(where)) {
5166
+ if (!isRecord7(where)) {
4261
5167
  throw new Error("findMany where must be an object");
4262
5168
  }
4263
5169
  const conditions = [];
@@ -4307,7 +5213,7 @@ function compileOrderBy(orderBy) {
4307
5213
  if (orderBy === void 0) {
4308
5214
  return void 0;
4309
5215
  }
4310
- if (!isRecord6(orderBy)) {
5216
+ if (!isRecord7(orderBy)) {
4311
5217
  throw new Error("findMany orderBy must be an object");
4312
5218
  }
4313
5219
  if ("column" in orderBy) {
@@ -4482,11 +5388,11 @@ function toFindManyAstOrder(order) {
4482
5388
  ascending: order.direction !== "descending"
4483
5389
  };
4484
5390
  }
4485
- function isRecord7(value) {
5391
+ function isRecord8(value) {
4486
5392
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4487
5393
  }
4488
5394
  function normalizeFindManyAstColumnPredicate(value) {
4489
- if (!isRecord7(value)) {
5395
+ if (!isRecord8(value)) {
4490
5396
  return {
4491
5397
  eq: value
4492
5398
  };
@@ -4510,7 +5416,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
4510
5416
  return normalized;
4511
5417
  }
4512
5418
  function normalizeFindManyAstWhere(where) {
4513
- if (!where || !isRecord7(where)) {
5419
+ if (!where || !isRecord8(where)) {
4514
5420
  return where;
4515
5421
  }
4516
5422
  const normalized = {};
@@ -4524,7 +5430,7 @@ function normalizeFindManyAstWhere(where) {
4524
5430
  );
4525
5431
  continue;
4526
5432
  }
4527
- if (key === "not" && isRecord7(value)) {
5433
+ if (key === "not" && isRecord8(value)) {
4528
5434
  normalized.not = normalizeFindManyAstBooleanOperand(
4529
5435
  value
4530
5436
  );
@@ -4535,7 +5441,7 @@ function normalizeFindManyAstWhere(where) {
4535
5441
  return normalized;
4536
5442
  }
4537
5443
  function predicateRequiresUuidQueryFallback(column, value) {
4538
- if (!isRecord7(value)) {
5444
+ if (!isRecord8(value)) {
4539
5445
  return shouldUseUuidTextComparison(column, value);
4540
5446
  }
4541
5447
  const eqValue = value.eq;
@@ -4553,7 +5459,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
4553
5459
  return false;
4554
5460
  }
4555
5461
  function findManyAstWhereRequiresLegacyTransport(where) {
4556
- if (!where || !isRecord7(where)) {
5462
+ if (!where || !isRecord8(where)) {
4557
5463
  return false;
4558
5464
  }
4559
5465
  for (const [key, value] of Object.entries(where)) {
@@ -4568,7 +5474,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
4568
5474
  }
4569
5475
  continue;
4570
5476
  }
4571
- if (key === "not" && isRecord7(value)) {
5477
+ if (key === "not" && isRecord8(value)) {
4572
5478
  if (booleanOperandRequiresUuidQueryFallback(value)) {
4573
5479
  return true;
4574
5480
  }
@@ -4680,161 +5586,258 @@ function createSelectTransportPlan(input) {
4680
5586
  };
4681
5587
  }
4682
5588
 
4683
- // src/client.ts
4684
- var DEFAULT_COLUMNS = "*";
4685
- var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
4686
- var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
4687
- var QUERY_TRACE_STACK_SKIP_PATTERNS = [
4688
- "src\\client.ts",
4689
- "src/client.ts",
4690
- "dist\\client.",
4691
- "dist/client.",
4692
- "node_modules\\@xylex-group\\athena",
4693
- "node_modules/@xylex-group/athena",
4694
- "node:internal",
4695
- "internal/process"
4696
- ];
4697
- function formatResult(response) {
4698
- const result = {
4699
- data: response.data ?? null,
4700
- error: null,
4701
- errorDetails: response.errorDetails ?? null,
4702
- status: response.status,
4703
- statusText: response.statusText ?? null,
4704
- raw: response.raw
5589
+ // src/query-debug-ast.ts
5590
+ var ATHENA_DEBUG_AST_KEY = "__athenaDebugAst";
5591
+ function cloneConditions(conditions) {
5592
+ return conditions.map((condition) => ({ ...condition }));
5593
+ }
5594
+ function cloneTableBuilderStateAst(state) {
5595
+ return {
5596
+ conditions: cloneConditions(state.conditions),
5597
+ limit: state.limit,
5598
+ offset: state.offset,
5599
+ order: state.order ? { ...state.order } : void 0,
5600
+ currentPage: state.currentPage,
5601
+ pageSize: state.pageSize,
5602
+ totalPages: state.totalPages
4705
5603
  };
4706
- if (response.count !== void 0) {
4707
- result.count = response.count;
5604
+ }
5605
+ function cloneRpcBuilderStateAst(state) {
5606
+ return {
5607
+ filters: state.filters.map((filter) => ({ ...filter })),
5608
+ limit: state.limit,
5609
+ offset: state.offset,
5610
+ order: state.order ? { ...state.order } : void 0
5611
+ };
5612
+ }
5613
+ function toSelectTransportAst(plan) {
5614
+ if (plan.kind === "query") {
5615
+ return {
5616
+ mode: "typed-query",
5617
+ endpoint: "/gateway/query",
5618
+ payload: plan.payload
5619
+ };
4708
5620
  }
4709
- return result;
5621
+ return {
5622
+ mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
5623
+ endpoint: "/gateway/fetch",
5624
+ payload: plan.payload
5625
+ };
4710
5626
  }
4711
- var EXPERIMENTAL_READ_RETRY_CONFIG = {
4712
- retries: 2,
4713
- baseDelayMs: 100,
4714
- maxDelayMs: 1e3,
4715
- backoff: "exponential",
4716
- jitter: true
4717
- };
4718
- function attachNormalizedError(result, normalizedError) {
4719
- Object.defineProperty(result, ATHENA_NORMALIZED_ERROR_KEY, {
4720
- value: normalizedError,
4721
- enumerable: false,
4722
- configurable: true,
4723
- writable: false
4724
- });
5627
+ function resolveDebugTableName(tableName) {
5628
+ return tableName ?? "__unknown_table__";
4725
5629
  }
4726
- function createResultFormatter(experimental) {
4727
- return (response, context) => {
4728
- const result = formatResult(response);
4729
- if (response.error == null && response.errorDetails == null) {
4730
- return result;
5630
+ function buildSelectDebugAst(input) {
5631
+ return {
5632
+ version: 1,
5633
+ kind: "select",
5634
+ tableName: input.tableName,
5635
+ input: {
5636
+ columns: input.columns,
5637
+ state: cloneTableBuilderStateAst(input.state)
5638
+ },
5639
+ transport: toSelectTransportAst(input.plan)
5640
+ };
5641
+ }
5642
+ function buildFindManyCompiledDebugAst(input) {
5643
+ return {
5644
+ version: 1,
5645
+ kind: "findMany",
5646
+ tableName: input.tableName,
5647
+ input: {
5648
+ select: input.options.select,
5649
+ where: input.options.where,
5650
+ orderBy: input.options.orderBy,
5651
+ limit: input.options.limit
5652
+ },
5653
+ compiled: {
5654
+ columns: input.compiledColumns,
5655
+ baseState: cloneTableBuilderStateAst(input.baseState),
5656
+ executionState: cloneTableBuilderStateAst(input.executionState)
5657
+ },
5658
+ transport: planToFindManyTransport(input.plan)
5659
+ };
5660
+ }
5661
+ function buildFindManyDirectDebugAst(input) {
5662
+ return {
5663
+ version: 1,
5664
+ kind: "findMany",
5665
+ tableName: input.tableName,
5666
+ input: {
5667
+ select: input.options.select,
5668
+ where: input.options.where,
5669
+ orderBy: input.options.orderBy,
5670
+ limit: input.options.limit
5671
+ },
5672
+ compiled: {
5673
+ columns: input.compiledColumns,
5674
+ baseState: cloneTableBuilderStateAst(input.baseState),
5675
+ executionState: cloneTableBuilderStateAst(input.executionState)
5676
+ },
5677
+ transport: {
5678
+ mode: "direct-ast-fetch",
5679
+ endpoint: "/gateway/fetch",
5680
+ payload: input.payload
4731
5681
  }
4732
- const normalizedError = normalizeAthenaError(
4733
- {
4734
- ...result,
4735
- error: response.error ?? response.errorDetails?.message ?? null
4736
- },
4737
- context
4738
- );
4739
- result.error = createResultError(response, result, normalizedError);
4740
- attachNormalizedError(result, normalizedError);
4741
- return result;
4742
5682
  };
4743
5683
  }
4744
- async function executeExperimentalRead(experimental, runner) {
4745
- if (!experimental?.retryReads) {
4746
- return runner();
5684
+ function planToFindManyTransport(plan) {
5685
+ if (plan.kind === "query") {
5686
+ return {
5687
+ mode: "compiled-query",
5688
+ endpoint: "/gateway/query",
5689
+ payload: plan.payload
5690
+ };
4747
5691
  }
4748
- let lastRetryableResult;
4749
- let lastRetrySignal = null;
4750
- try {
4751
- return await withRetry(
4752
- {
4753
- ...EXPERIMENTAL_READ_RETRY_CONFIG,
4754
- shouldRetry: (error) => error === lastRetrySignal || normalizeAthenaError(error).retryable
4755
- },
4756
- async () => {
4757
- const result = await runner();
4758
- if (result.error?.retryable) {
4759
- lastRetryableResult = result;
4760
- lastRetrySignal = result.error;
4761
- throw lastRetrySignal;
4762
- }
4763
- return result;
4764
- }
4765
- );
4766
- } catch (error) {
4767
- if (lastRetryableResult && error === lastRetrySignal) {
4768
- return lastRetryableResult;
5692
+ return {
5693
+ mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
5694
+ endpoint: "/gateway/fetch",
5695
+ payload: plan.payload
5696
+ };
5697
+ }
5698
+ function buildInsertDebugAst(payload) {
5699
+ return {
5700
+ version: 1,
5701
+ kind: "insert",
5702
+ tableName: payload.table_name,
5703
+ input: {
5704
+ values: payload.insert_body,
5705
+ returning: payload.columns,
5706
+ count: payload.count,
5707
+ head: payload.head,
5708
+ defaultToNull: payload.default_to_null
5709
+ },
5710
+ transport: {
5711
+ mode: "insert",
5712
+ endpoint: "/gateway/insert",
5713
+ payload
4769
5714
  }
4770
- throw error;
4771
- }
5715
+ };
4772
5716
  }
4773
- function isRecord8(value) {
4774
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5717
+ function buildUpsertDebugAst(payload) {
5718
+ return {
5719
+ version: 1,
5720
+ kind: "upsert",
5721
+ tableName: payload.table_name,
5722
+ input: {
5723
+ values: payload.insert_body,
5724
+ updateBody: payload.update_body,
5725
+ onConflict: payload.on_conflict,
5726
+ returning: payload.columns,
5727
+ count: payload.count,
5728
+ head: payload.head,
5729
+ defaultToNull: payload.default_to_null
5730
+ },
5731
+ transport: {
5732
+ mode: "upsert",
5733
+ endpoint: "/gateway/insert",
5734
+ payload
5735
+ }
5736
+ };
4775
5737
  }
4776
- function firstNonEmptyString2(...values) {
4777
- for (const value of values) {
4778
- if (typeof value === "string" && value.trim().length > 0) {
4779
- return value.trim();
5738
+ function buildUpdateDebugAst(input) {
5739
+ return {
5740
+ version: 1,
5741
+ kind: "update",
5742
+ tableName: resolveDebugTableName(input.payload.table_name),
5743
+ input: {
5744
+ values: input.payload.set,
5745
+ state: cloneTableBuilderStateAst(input.state),
5746
+ returning: input.payload.columns
5747
+ },
5748
+ transport: {
5749
+ mode: "update",
5750
+ endpoint: "/gateway/update",
5751
+ payload: input.payload
4780
5752
  }
4781
- }
4782
- return void 0;
5753
+ };
4783
5754
  }
4784
- function resolveStructuredErrorPayload2(raw) {
4785
- if (!isRecord8(raw)) return null;
4786
- return isRecord8(raw.error) ? raw.error : raw;
5755
+ function buildDeleteDebugAst(input) {
5756
+ return {
5757
+ version: 1,
5758
+ kind: "delete",
5759
+ tableName: input.payload.table_name,
5760
+ input: {
5761
+ resourceId: input.payload.resource_id,
5762
+ state: cloneTableBuilderStateAst(input.state),
5763
+ returning: input.payload.columns
5764
+ },
5765
+ transport: {
5766
+ mode: "delete",
5767
+ endpoint: "/gateway/delete",
5768
+ payload: input.payload
5769
+ }
5770
+ };
4787
5771
  }
4788
- function resolveStructuredErrorDetails(payload, message) {
4789
- if (!payload || !("details" in payload)) {
4790
- return null;
5772
+ function buildRpcDebugAst(input) {
5773
+ return {
5774
+ version: 1,
5775
+ kind: "rpc",
5776
+ functionName: input.functionName,
5777
+ input: {
5778
+ args: input.args,
5779
+ select: input.selectedColumns,
5780
+ state: cloneRpcBuilderStateAst(input.state)
5781
+ },
5782
+ transport: {
5783
+ mode: input.endpoint === "/gateway/rpc" ? "rpc-post" : "rpc-get",
5784
+ endpoint: input.endpoint,
5785
+ payload: input.payload
5786
+ }
5787
+ };
5788
+ }
5789
+ function buildRawQueryDebugAst(query) {
5790
+ return {
5791
+ version: 1,
5792
+ kind: "query",
5793
+ input: {
5794
+ query
5795
+ },
5796
+ transport: {
5797
+ mode: "raw-query",
5798
+ endpoint: "/gateway/query",
5799
+ payload: {
5800
+ query
5801
+ }
5802
+ }
5803
+ };
5804
+ }
5805
+ function attachAthenaDebugAst(target, ast) {
5806
+ if (!ast) {
5807
+ return;
4791
5808
  }
4792
- const details = payload.details;
4793
- if (details == null) {
4794
- return null;
5809
+ if (!target || typeof target !== "object" && typeof target !== "function") {
5810
+ return;
4795
5811
  }
4796
- if (typeof details === "string" && details.trim() === message.trim()) {
5812
+ Object.defineProperty(target, ATHENA_DEBUG_AST_KEY, {
5813
+ value: ast,
5814
+ enumerable: false,
5815
+ configurable: true,
5816
+ writable: false
5817
+ });
5818
+ }
5819
+ function getAthenaDebugAst(value) {
5820
+ if (!value || typeof value !== "object" && typeof value !== "function") {
4797
5821
  return null;
4798
5822
  }
4799
- return details;
4800
- }
4801
- function createResultError(response, result, normalized) {
4802
- const rawRecord = isRecord8(response.raw) ? response.raw : null;
4803
- const payload = resolveStructuredErrorPayload2(response.raw);
4804
- const message = firstNonEmptyString2(
4805
- response.error,
4806
- payload?.message,
4807
- payload?.error,
4808
- payload?.details,
4809
- response.errorDetails?.message,
4810
- normalized.message
4811
- ) ?? normalized.message;
4812
- const statusText = firstNonEmptyString2(response.statusText, rawRecord?.statusText) ?? null;
4813
- const hint = firstNonEmptyString2(payload?.hint, response.errorDetails?.hint) ?? null;
4814
- const code = firstNonEmptyString2(payload?.code) ?? normalized.code;
4815
- const details = resolveStructuredErrorDetails(payload, message) ?? response.errorDetails?.cause ?? null;
4816
- return {
4817
- message,
4818
- code,
4819
- athenaCode: normalized.code,
4820
- gatewayCode: response.errorDetails?.code ?? null,
4821
- kind: normalized.kind,
4822
- category: normalized.category,
4823
- retryable: normalized.retryable,
4824
- details,
4825
- hint,
4826
- status: result.status,
4827
- statusText,
4828
- constraint: normalized.constraint,
4829
- table: normalized.table,
4830
- operation: normalized.operation,
4831
- endpoint: response.errorDetails?.endpoint,
4832
- method: response.errorDetails?.method,
4833
- requestId: response.errorDetails?.requestId,
4834
- cause: response.errorDetails?.cause,
4835
- raw: result.raw
4836
- };
5823
+ return value[ATHENA_DEBUG_AST_KEY] ?? null;
4837
5824
  }
5825
+
5826
+ // src/query-tracing.ts
5827
+ var QUERY_TRACE_STACK_SKIP_PATTERNS = [
5828
+ "src\\client.ts",
5829
+ "src/client.ts",
5830
+ "src\\query-tracing.ts",
5831
+ "src/query-tracing.ts",
5832
+ "dist\\client.",
5833
+ "dist/client.",
5834
+ "dist\\query-tracing.",
5835
+ "dist/query-tracing.",
5836
+ "node_modules\\@xylex-group\\athena",
5837
+ "node_modules/@xylex-group/athena",
5838
+ "node:internal",
5839
+ "internal/process"
5840
+ ];
4838
5841
  function parseQueryTraceCallsiteFrame(frame) {
4839
5842
  const trimmed = frame.trim();
4840
5843
  if (!trimmed) {
@@ -4939,6 +5942,7 @@ function createQueryTracer(experimental) {
4939
5942
  functionName: context.functionName,
4940
5943
  sql: context.sql,
4941
5944
  payload: context.payload,
5945
+ ast: context.ast,
4942
5946
  options: context.options,
4943
5947
  callsite,
4944
5948
  outcome: {
@@ -4961,6 +5965,7 @@ function createQueryTracer(experimental) {
4961
5965
  functionName: context.functionName,
4962
5966
  sql: context.sql,
4963
5967
  payload: context.payload,
5968
+ ast: context.ast,
4964
5969
  options: context.options,
4965
5970
  callsite,
4966
5971
  thrownError: error
@@ -4969,20 +5974,196 @@ function createQueryTracer(experimental) {
4969
5974
  };
4970
5975
  }
4971
5976
  async function executeWithQueryTrace(tracer, context, runner, callsiteOverride) {
4972
- if (!tracer) {
4973
- return runner();
4974
- }
4975
- const callsite = callsiteOverride ?? tracer.captureCallsite();
4976
- const startedAt = Date.now();
5977
+ const callsite = tracer ? callsiteOverride ?? tracer.captureCallsite() : null;
5978
+ const startedAt = tracer ? Date.now() : 0;
4977
5979
  try {
4978
5980
  const result = await runner();
4979
- tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
5981
+ attachAthenaDebugAst(result, context.ast);
5982
+ if (tracer) {
5983
+ tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
5984
+ }
4980
5985
  return result;
4981
5986
  } catch (error) {
4982
- tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
5987
+ attachAthenaDebugAst(error, context.ast);
5988
+ if (tracer) {
5989
+ tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
5990
+ }
5991
+ throw error;
5992
+ }
5993
+ }
5994
+
5995
+ // src/schema/model-target.ts
5996
+ function normalizeOptionalName(value) {
5997
+ const normalized = value?.trim();
5998
+ return normalized ? normalized : void 0;
5999
+ }
6000
+ function isAthenaModelTarget(value) {
6001
+ if (!value || typeof value !== "object") {
6002
+ return false;
6003
+ }
6004
+ const candidate = value;
6005
+ return Boolean(candidate.meta && Array.isArray(candidate.meta.primaryKey));
6006
+ }
6007
+ function resolveAthenaModelTargetTableName(target, options = {}) {
6008
+ const explicitTableName = normalizeOptionalName(target.meta.tableName);
6009
+ if (explicitTableName) {
6010
+ return explicitTableName;
6011
+ }
6012
+ const schemaName = normalizeOptionalName(target.meta.schema ?? options.fallbackSchema);
6013
+ const modelName = normalizeOptionalName(target.meta.model ?? options.fallbackModel);
6014
+ if (!modelName) {
6015
+ throw new Error(
6016
+ "Athena model target is missing meta.model or meta.tableName. Provide one of those before calling from(model)."
6017
+ );
6018
+ }
6019
+ return schemaName ? `${schemaName}.${modelName}` : modelName;
6020
+ }
6021
+
6022
+ // src/client.ts
6023
+ var DEFAULT_COLUMNS = "*";
6024
+ var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
6025
+ var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
6026
+ function formatResult(response) {
6027
+ const result = {
6028
+ data: response.data ?? null,
6029
+ error: null,
6030
+ errorDetails: response.errorDetails ?? null,
6031
+ status: response.status,
6032
+ statusText: response.statusText ?? null,
6033
+ raw: response.raw
6034
+ };
6035
+ if (response.count !== void 0) {
6036
+ result.count = response.count;
6037
+ }
6038
+ return result;
6039
+ }
6040
+ var EXPERIMENTAL_READ_RETRY_CONFIG = {
6041
+ retries: 2,
6042
+ baseDelayMs: 100,
6043
+ maxDelayMs: 1e3,
6044
+ backoff: "exponential",
6045
+ jitter: true
6046
+ };
6047
+ function attachNormalizedError(result, normalizedError) {
6048
+ Object.defineProperty(result, ATHENA_NORMALIZED_ERROR_KEY, {
6049
+ value: normalizedError,
6050
+ enumerable: false,
6051
+ configurable: true,
6052
+ writable: false
6053
+ });
6054
+ }
6055
+ function createResultFormatter(experimental) {
6056
+ return (response, context) => {
6057
+ const result = formatResult(response);
6058
+ if (response.error == null && response.errorDetails == null) {
6059
+ return result;
6060
+ }
6061
+ const normalizedError = normalizeAthenaError(
6062
+ {
6063
+ ...result,
6064
+ error: response.error ?? response.errorDetails?.message ?? null
6065
+ },
6066
+ context
6067
+ );
6068
+ result.error = createResultError(response, result, normalizedError);
6069
+ attachNormalizedError(result, normalizedError);
6070
+ return result;
6071
+ };
6072
+ }
6073
+ async function executeExperimentalRead(experimental, runner) {
6074
+ if (!experimental?.retryReads) {
6075
+ return runner();
6076
+ }
6077
+ let lastRetryableResult;
6078
+ let lastRetrySignal = null;
6079
+ try {
6080
+ return await withRetry(
6081
+ {
6082
+ ...EXPERIMENTAL_READ_RETRY_CONFIG,
6083
+ shouldRetry: (error) => error === lastRetrySignal || normalizeAthenaError(error).retryable
6084
+ },
6085
+ async () => {
6086
+ const result = await runner();
6087
+ if (result.error?.retryable) {
6088
+ lastRetryableResult = result;
6089
+ lastRetrySignal = result.error;
6090
+ throw lastRetrySignal;
6091
+ }
6092
+ return result;
6093
+ }
6094
+ );
6095
+ } catch (error) {
6096
+ if (lastRetryableResult && error === lastRetrySignal) {
6097
+ return lastRetryableResult;
6098
+ }
4983
6099
  throw error;
4984
6100
  }
4985
6101
  }
6102
+ function isRecord9(value) {
6103
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6104
+ }
6105
+ function firstNonEmptyString2(...values) {
6106
+ for (const value of values) {
6107
+ if (typeof value === "string" && value.trim().length > 0) {
6108
+ return value.trim();
6109
+ }
6110
+ }
6111
+ return void 0;
6112
+ }
6113
+ function resolveStructuredErrorPayload2(raw) {
6114
+ if (!isRecord9(raw)) return null;
6115
+ return isRecord9(raw.error) ? raw.error : raw;
6116
+ }
6117
+ function resolveStructuredErrorDetails(payload, message) {
6118
+ if (!payload || !("details" in payload)) {
6119
+ return null;
6120
+ }
6121
+ const details = payload.details;
6122
+ if (details == null) {
6123
+ return null;
6124
+ }
6125
+ if (typeof details === "string" && details.trim() === message.trim()) {
6126
+ return null;
6127
+ }
6128
+ return details;
6129
+ }
6130
+ function createResultError(response, result, normalized) {
6131
+ const rawRecord = isRecord9(response.raw) ? response.raw : null;
6132
+ const payload = resolveStructuredErrorPayload2(response.raw);
6133
+ const message = firstNonEmptyString2(
6134
+ response.error,
6135
+ payload?.message,
6136
+ payload?.error,
6137
+ payload?.details,
6138
+ response.errorDetails?.message,
6139
+ normalized.message
6140
+ ) ?? normalized.message;
6141
+ const statusText = firstNonEmptyString2(response.statusText, rawRecord?.statusText) ?? null;
6142
+ const hint = firstNonEmptyString2(payload?.hint, response.errorDetails?.hint) ?? null;
6143
+ const code = firstNonEmptyString2(payload?.code) ?? normalized.code;
6144
+ const details = resolveStructuredErrorDetails(payload, message) ?? response.errorDetails?.cause ?? null;
6145
+ return {
6146
+ message,
6147
+ code,
6148
+ athenaCode: normalized.code,
6149
+ gatewayCode: response.errorDetails?.code ?? null,
6150
+ kind: normalized.kind,
6151
+ category: normalized.category,
6152
+ retryable: normalized.retryable,
6153
+ details,
6154
+ hint,
6155
+ status: result.status,
6156
+ statusText,
6157
+ constraint: normalized.constraint,
6158
+ table: normalized.table,
6159
+ operation: normalized.operation,
6160
+ endpoint: response.errorDetails?.endpoint,
6161
+ method: response.errorDetails?.method,
6162
+ requestId: response.errorDetails?.requestId,
6163
+ cause: response.errorDetails?.cause,
6164
+ raw: result.raw
6165
+ };
6166
+ }
4986
6167
  function toSingleResult(response) {
4987
6168
  const payload = response.data;
4988
6169
  const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
@@ -5010,6 +6191,15 @@ function asAthenaJsonObject(value) {
5010
6191
  function asAthenaJsonObjectArray(values) {
5011
6192
  return values;
5012
6193
  }
6194
+ function normalizeSelectColumnsInput(columns) {
6195
+ if (columns === void 0) {
6196
+ return void 0;
6197
+ }
6198
+ if (typeof columns === "string") {
6199
+ return columns;
6200
+ }
6201
+ return [...columns];
6202
+ }
5013
6203
  function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer, initialCallsite) {
5014
6204
  let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
5015
6205
  let selectedOptions;
@@ -5019,25 +6209,29 @@ function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer,
5019
6209
  const payloadColumns = columns ?? selectedColumns;
5020
6210
  const payloadOptions = options ?? selectedOptions;
5021
6211
  if (!promise) {
5022
- promise = executor(payloadColumns, payloadOptions, callsiteStore.resolve(callsite));
6212
+ promise = executor(
6213
+ normalizeSelectColumnsInput(payloadColumns),
6214
+ payloadOptions,
6215
+ callsiteStore.resolve(callsite)
6216
+ );
5023
6217
  }
5024
6218
  return promise;
5025
6219
  };
5026
6220
  const mutationQuery = {
5027
- select(columns = selectedColumns, options) {
6221
+ select(columns, options) {
5028
6222
  selectedColumns = columns;
5029
6223
  selectedOptions = options ?? selectedOptions;
5030
6224
  return run(columns, options, captureTraceCallsite(tracer));
5031
6225
  },
5032
- returning(columns = selectedColumns, options) {
6226
+ returning(columns, options) {
5033
6227
  return mutationQuery.select(columns, options);
5034
6228
  },
5035
- single(columns = selectedColumns, options) {
6229
+ single(columns, options) {
5036
6230
  selectedColumns = columns;
5037
6231
  selectedOptions = options ?? selectedOptions;
5038
6232
  return run(columns, options, captureTraceCallsite(tracer)).then(toSingleResult);
5039
6233
  },
5040
- maybeSingle(columns = selectedColumns, options) {
6234
+ maybeSingle(columns, options) {
5041
6235
  return mutationQuery.single(columns, options);
5042
6236
  },
5043
6237
  then(onfulfilled, onrejected) {
@@ -5594,7 +6788,10 @@ function createFilterMethods(state, addCondition, self) {
5594
6788
  }
5595
6789
  function toRpcSelect(columns) {
5596
6790
  if (!columns) return void 0;
5597
- return Array.isArray(columns) ? columns.join(",") : columns;
6791
+ if (typeof columns === "string") {
6792
+ return columns;
6793
+ }
6794
+ return columns.join(",");
5598
6795
  }
5599
6796
  function createRpcFilterMethods(filters, self) {
5600
6797
  const addFilter = (operator, column, value) => {
@@ -5643,7 +6840,7 @@ function createRpcFilterMethods(filters, self) {
5643
6840
  }
5644
6841
  };
5645
6842
  }
5646
- function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite) {
6843
+ function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite, debugAstEnabled = false) {
5647
6844
  const state = {
5648
6845
  filters: []
5649
6846
  };
@@ -5653,6 +6850,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
5653
6850
  const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
5654
6851
  const executeRpc = async (columns, options, callsite) => {
5655
6852
  const mergedOptions = mergeOptions(baseOptions, options);
6853
+ const normalizedSelectedColumns = normalizeSelectColumnsInput(columns);
5656
6854
  const payload = {
5657
6855
  function: functionName,
5658
6856
  args,
@@ -5667,6 +6865,14 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
5667
6865
  };
5668
6866
  const endpoint = mergedOptions?.get ? `/rpc/${functionName}` : "/gateway/rpc";
5669
6867
  const sql = buildRpcDebugSql(payload);
6868
+ const debugAst = debugAstEnabled ? buildRpcDebugAst({
6869
+ functionName,
6870
+ args,
6871
+ selectedColumns: normalizedSelectedColumns,
6872
+ state,
6873
+ payload,
6874
+ endpoint
6875
+ }) : void 0;
5670
6876
  return executeWithQueryTrace(
5671
6877
  tracer,
5672
6878
  {
@@ -5675,6 +6881,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
5675
6881
  functionName,
5676
6882
  sql,
5677
6883
  payload,
6884
+ ast: debugAst,
5678
6885
  options: mergedOptions
5679
6886
  },
5680
6887
  async () => {
@@ -5695,7 +6902,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
5695
6902
  const builder = {};
5696
6903
  const filterMethods = createRpcFilterMethods(state.filters, builder);
5697
6904
  Object.assign(builder, filterMethods, {
5698
- select(columns = selectedColumns, options) {
6905
+ select(columns, options) {
5699
6906
  selectedColumns = columns;
5700
6907
  selectedOptions = options ?? selectedOptions;
5701
6908
  return run(columns, options, captureTraceCallsite(tracer));
@@ -5740,6 +6947,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5740
6947
  const state = {
5741
6948
  conditions: []
5742
6949
  };
6950
+ const debugAstEnabled = Boolean(experimental?.debugAst);
5743
6951
  const addCondition = (operator, column, value, hints) => {
5744
6952
  const condition = { operator };
5745
6953
  if (column) {
@@ -5783,15 +6991,27 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5783
6991
  addCondition,
5784
6992
  builder
5785
6993
  );
5786
- const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite) => {
6994
+ const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite, debugAstFactory) => {
6995
+ const runtimeColumns = normalizeSelectColumnsInput(columns) ?? DEFAULT_COLUMNS;
5787
6996
  const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
5788
6997
  const plan = createSelectTransportPlan({
5789
6998
  tableName: resolvedTableName,
5790
- columns,
6999
+ columns: runtimeColumns,
5791
7000
  state: executionState,
5792
7001
  options,
5793
7002
  buildTypedSelectQuery
5794
7003
  });
7004
+ const debugAst = debugAstEnabled ? debugAstFactory?.({
7005
+ tableName: resolvedTableName,
7006
+ columns: runtimeColumns,
7007
+ executionState,
7008
+ plan
7009
+ }) ?? buildSelectDebugAst({
7010
+ tableName: resolvedTableName,
7011
+ columns: runtimeColumns,
7012
+ state: executionState,
7013
+ plan
7014
+ }) : void 0;
5795
7015
  if (plan.kind === "query") {
5796
7016
  return executeExperimentalRead(
5797
7017
  experimental,
@@ -5803,6 +7023,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5803
7023
  table: resolvedTableName,
5804
7024
  sql: plan.query,
5805
7025
  payload: plan.payload,
7026
+ ast: debugAst,
5806
7027
  options
5807
7028
  },
5808
7029
  async () => {
@@ -5827,6 +7048,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5827
7048
  table: resolvedTableName,
5828
7049
  sql,
5829
7050
  payload: plan.payload,
7051
+ ast: debugAst,
5830
7052
  options
5831
7053
  },
5832
7054
  async () => {
@@ -5840,7 +7062,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5840
7062
  const createSelectChain = (columns, options, initialCallsite) => {
5841
7063
  const chain = {};
5842
7064
  const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
5843
- const filterMethods2 = createFilterMethods(state, addCondition, chain);
7065
+ const filterMethods2 = createFilterMethods(
7066
+ state,
7067
+ addCondition,
7068
+ chain
7069
+ );
5844
7070
  Object.assign(chain, filterMethods2, {
5845
7071
  async single(cols, opts) {
5846
7072
  const r = await runSelect(
@@ -5927,6 +7153,14 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5927
7153
  limit: executionState.limit,
5928
7154
  order: executionState.order
5929
7155
  });
7156
+ const debugAst = debugAstEnabled ? buildFindManyDirectDebugAst({
7157
+ tableName: resolvedTableName,
7158
+ options,
7159
+ compiledColumns: columns,
7160
+ baseState,
7161
+ executionState,
7162
+ payload
7163
+ }) : void 0;
5930
7164
  return executeExperimentalRead(
5931
7165
  experimental,
5932
7166
  () => executeWithQueryTrace(
@@ -5936,7 +7170,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5936
7170
  endpoint: "/gateway/fetch",
5937
7171
  table: resolvedTableName,
5938
7172
  sql,
5939
- payload
7173
+ payload,
7174
+ ast: debugAst
5940
7175
  },
5941
7176
  async () => {
5942
7177
  const response = await client.fetchGateway(
@@ -5952,7 +7187,15 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5952
7187
  columns,
5953
7188
  void 0,
5954
7189
  executionState,
5955
- callsite
7190
+ callsite,
7191
+ debugAstEnabled ? ({ tableName: resolvedTableName, executionState: tracedState, plan }) => buildFindManyCompiledDebugAst({
7192
+ tableName: resolvedTableName,
7193
+ options,
7194
+ compiledColumns: columns,
7195
+ baseState,
7196
+ executionState: tracedState,
7197
+ plan
7198
+ }) : void 0
5956
7199
  );
5957
7200
  },
5958
7201
  insert(values, options) {
@@ -5972,6 +7215,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5972
7215
  payload.default_to_null = mergedOptions.defaultToNull;
5973
7216
  }
5974
7217
  const sql = buildInsertDebugSql(payload);
7218
+ const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
5975
7219
  return executeWithQueryTrace(
5976
7220
  tracer,
5977
7221
  {
@@ -5980,6 +7224,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
5980
7224
  table: resolvedTableName,
5981
7225
  sql,
5982
7226
  payload,
7227
+ ast: debugAst,
5983
7228
  options: mergedOptions
5984
7229
  },
5985
7230
  async () => {
@@ -6005,6 +7250,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6005
7250
  payload.default_to_null = mergedOptions.defaultToNull;
6006
7251
  }
6007
7252
  const sql = buildInsertDebugSql(payload);
7253
+ const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
6008
7254
  return executeWithQueryTrace(
6009
7255
  tracer,
6010
7256
  {
@@ -6013,6 +7259,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6013
7259
  table: resolvedTableName,
6014
7260
  sql,
6015
7261
  payload,
7262
+ ast: debugAst,
6016
7263
  options: mergedOptions
6017
7264
  },
6018
7265
  async () => {
@@ -6043,6 +7290,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6043
7290
  payload.default_to_null = mergedOptions.defaultToNull;
6044
7291
  }
6045
7292
  const sql = buildInsertDebugSql(payload);
7293
+ const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
6046
7294
  return executeWithQueryTrace(
6047
7295
  tracer,
6048
7296
  {
@@ -6051,6 +7299,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6051
7299
  table: resolvedTableName,
6052
7300
  sql,
6053
7301
  payload,
7302
+ ast: debugAst,
6054
7303
  options: mergedOptions
6055
7304
  },
6056
7305
  async () => {
@@ -6078,6 +7327,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6078
7327
  payload.default_to_null = mergedOptions.defaultToNull;
6079
7328
  }
6080
7329
  const sql = buildInsertDebugSql(payload);
7330
+ const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
6081
7331
  return executeWithQueryTrace(
6082
7332
  tracer,
6083
7333
  {
@@ -6086,6 +7336,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6086
7336
  table: resolvedTableName,
6087
7337
  sql,
6088
7338
  payload,
7339
+ ast: debugAst,
6089
7340
  options: mergedOptions
6090
7341
  },
6091
7342
  async () => {
@@ -6100,7 +7351,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6100
7351
  update(values, options) {
6101
7352
  const mutationCallsite = captureTraceCallsite(tracer);
6102
7353
  const executeUpdate = async (columns, selectOptions, callsite) => {
6103
- const filters = state.conditions.length ? [...state.conditions] : void 0;
7354
+ const executionState = snapshotState();
7355
+ const filters = executionState.conditions.length ? [...executionState.conditions] : void 0;
6104
7356
  const mergedOptions = mergeOptions(options, selectOptions);
6105
7357
  const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
6106
7358
  const payload = {
@@ -6109,12 +7361,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6109
7361
  conditions: filters,
6110
7362
  strip_nulls: mergedOptions?.stripNulls ?? true
6111
7363
  };
6112
- if (state.order) payload.sort_by = state.order;
6113
- if (state.currentPage !== void 0) payload.current_page = state.currentPage;
6114
- if (state.pageSize !== void 0) payload.page_size = state.pageSize;
6115
- if (state.totalPages !== void 0) payload.total_pages = state.totalPages;
7364
+ if (executionState.order) payload.sort_by = executionState.order;
7365
+ if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
7366
+ if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
7367
+ if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
6116
7368
  if (columns) payload.columns = columns;
6117
7369
  const sql = buildUpdateDebugSql(payload);
7370
+ const debugAst = debugAstEnabled ? buildUpdateDebugAst({
7371
+ state: executionState,
7372
+ payload
7373
+ }) : void 0;
6118
7374
  return executeWithQueryTrace(
6119
7375
  tracer,
6120
7376
  {
@@ -6123,6 +7379,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6123
7379
  table: resolvedTableName,
6124
7380
  sql,
6125
7381
  payload,
7382
+ ast: debugAst,
6126
7383
  options: mergedOptions
6127
7384
  },
6128
7385
  async () => {
@@ -6146,6 +7403,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6146
7403
  }
6147
7404
  const mutationCallsite = captureTraceCallsite(tracer);
6148
7405
  const executeDelete = async (columns, selectOptions, callsite) => {
7406
+ const executionState = snapshotState();
7407
+ const debugState = {
7408
+ ...executionState,
7409
+ conditions: filters ? filters.map((condition) => ({ ...condition })) : []
7410
+ };
6149
7411
  const mergedOptions = mergeOptions(options, selectOptions);
6150
7412
  const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
6151
7413
  const payload = {
@@ -6153,12 +7415,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6153
7415
  resource_id: resourceId,
6154
7416
  conditions: filters
6155
7417
  };
6156
- if (state.order) payload.sort_by = state.order;
6157
- if (state.currentPage !== void 0) payload.current_page = state.currentPage;
6158
- if (state.pageSize !== void 0) payload.page_size = state.pageSize;
6159
- if (state.totalPages !== void 0) payload.total_pages = state.totalPages;
7418
+ if (executionState.order) payload.sort_by = executionState.order;
7419
+ if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
7420
+ if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
7421
+ if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
6160
7422
  if (columns) payload.columns = columns;
6161
7423
  const sql = buildDeleteDebugSql(payload);
7424
+ const debugAst = debugAstEnabled ? buildDeleteDebugAst({
7425
+ state: debugState,
7426
+ payload
7427
+ }) : void 0;
6162
7428
  return executeWithQueryTrace(
6163
7429
  tracer,
6164
7430
  {
@@ -6167,6 +7433,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6167
7433
  table: resolvedTableName,
6168
7434
  sql,
6169
7435
  payload,
7436
+ ast: debugAst,
6170
7437
  options: mergedOptions
6171
7438
  },
6172
7439
  async () => {
@@ -6194,6 +7461,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
6194
7461
  return builder;
6195
7462
  }
6196
7463
  function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
7464
+ const debugAstEnabled = Boolean(experimental?.debugAst);
6197
7465
  return async function query(query, options) {
6198
7466
  const normalizedQuery = query.trim();
6199
7467
  if (!normalizedQuery) {
@@ -6210,6 +7478,7 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
6210
7478
  endpoint: "/gateway/query",
6211
7479
  sql: normalizedQuery,
6212
7480
  payload,
7481
+ ast: debugAstEnabled ? buildRawQueryDebugAst(normalizedQuery) : void 0,
6213
7482
  options
6214
7483
  },
6215
7484
  async () => {
@@ -6221,6 +7490,63 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
6221
7490
  );
6222
7491
  };
6223
7492
  }
7493
+ function resolveClientServiceBaseUrl(value, label) {
7494
+ if (value === void 0 || value === null) {
7495
+ return void 0;
7496
+ }
7497
+ return normalizeAthenaGatewayBaseUrl(value, { label });
7498
+ }
7499
+ function appendServicePath(baseUrl, segment) {
7500
+ const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
7501
+ return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
7502
+ }
7503
+ function resolveServiceUrlOverride(value, label) {
7504
+ return resolveClientServiceBaseUrl(value, label);
7505
+ }
7506
+ function resolveServiceUrls(config) {
7507
+ const baseUrl = resolveClientServiceBaseUrl(config.url, "Athena public base URL");
7508
+ return {
7509
+ dbUrl: resolveServiceUrlOverride(config.db?.url, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gateway?.url, "Athena gateway base URL") ?? resolveServiceUrlOverride(config.dbUrl, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gatewayUrl, "Athena gateway base URL") ?? (baseUrl ? appendServicePath(baseUrl, "db") : void 0),
7510
+ authUrl: resolveServiceUrlOverride(config.auth?.url, "Athena auth base URL") ?? resolveServiceUrlOverride(config.auth?.baseUrl, "Athena auth base URL") ?? resolveServiceUrlOverride(config.authUrl, "Athena auth base URL") ?? (baseUrl ? appendServicePath(baseUrl, "auth") : void 0),
7511
+ storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
7512
+ };
7513
+ }
7514
+ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
7515
+ if (!auth && defaultBaseUrl === void 0) {
7516
+ return void 0;
7517
+ }
7518
+ const { url, ...rest } = auth ?? {};
7519
+ const normalized = {
7520
+ ...rest
7521
+ };
7522
+ const resolvedBaseUrl = resolveClientServiceBaseUrl(
7523
+ url ?? rest.baseUrl ?? defaultBaseUrl,
7524
+ "Athena auth base URL"
7525
+ );
7526
+ if (resolvedBaseUrl !== void 0) {
7527
+ normalized.baseUrl = resolvedBaseUrl;
7528
+ }
7529
+ return normalized;
7530
+ }
7531
+ function resolveCreateClientConfig(config) {
7532
+ const resolvedUrls = resolveServiceUrls(config);
7533
+ if (!resolvedUrls.dbUrl) {
7534
+ throw new Error(
7535
+ "Athena DB base URL is required. Pass createClient(url, key) for a unified root, or set db.url / gateway.url / gatewayUrl explicitly."
7536
+ );
7537
+ }
7538
+ return {
7539
+ baseUrl: resolvedUrls.dbUrl,
7540
+ apiKey: config.key,
7541
+ client: config.client,
7542
+ backend: toBackendConfig(config.backend),
7543
+ headers: config.headers,
7544
+ auth: config.auth,
7545
+ authUrl: resolvedUrls.authUrl,
7546
+ storageUrl: resolvedUrls.storageUrl,
7547
+ experimental: config.experimental
7548
+ };
7549
+ }
6224
7550
  function createClientFromConfig(config) {
6225
7551
  const gatewayHeaders = {
6226
7552
  ...config.headers ?? {}
@@ -6237,184 +7563,112 @@ function createClientFromConfig(config) {
6237
7563
  });
6238
7564
  const formatGatewayResult = createResultFormatter(config.experimental);
6239
7565
  const queryTracer = createQueryTracer(config.experimental);
6240
- const auth = createAuthClient(config.auth);
6241
- const from = (table, options) => createTableBuilder(
6242
- resolveTableNameForCall(table, options?.schema),
6243
- gateway,
6244
- formatGatewayResult,
6245
- queryTracer,
6246
- config.experimental
6247
- );
6248
- const rpc = (fn, args, options) => {
6249
- const normalizedFn = fn.trim();
6250
- if (!normalizedFn) {
6251
- throw new Error("rpc requires a function name");
7566
+ const auth = createAuthClient(normalizeAuthClientConfig(config.auth, config.authUrl));
7567
+ function from(tableOrModel, options) {
7568
+ if (isAthenaModelTarget(tableOrModel)) {
7569
+ if (options?.schema !== void 0) {
7570
+ throw new Error(
7571
+ "from(model) does not accept a schema override because the model already defines its target."
7572
+ );
7573
+ }
7574
+ return createTableBuilder(
7575
+ resolveAthenaModelTargetTableName(tableOrModel),
7576
+ gateway,
7577
+ formatGatewayResult,
7578
+ queryTracer,
7579
+ config.experimental
7580
+ );
6252
7581
  }
6253
- return createRpcBuilder(
6254
- normalizedFn,
6255
- args,
6256
- options,
7582
+ const resolvedTableName = resolveTableNameForCall(tableOrModel, options?.schema);
7583
+ return createTableBuilder(
7584
+ resolvedTableName,
6257
7585
  gateway,
6258
7586
  formatGatewayResult,
6259
7587
  queryTracer,
6260
- captureTraceCallsite(queryTracer)
7588
+ config.experimental
6261
7589
  );
6262
- };
6263
- const query = createQueryBuilder(gateway, formatGatewayResult, config.experimental, queryTracer);
6264
- const db = createDbModule({ from, rpc, query });
6265
- const sdkClient = {
6266
- from,
6267
- db,
6268
- rpc,
6269
- query,
6270
- verifyConnection: gateway.verifyConnection,
6271
- auth: auth.auth
6272
- };
6273
- if (config.experimental?.athenaStorageBackend) {
6274
- const storageClient = {
6275
- ...sdkClient,
6276
- storage: createStorageModule(gateway, config.experimental.storage)
6277
- };
6278
- return storageClient;
6279
- }
6280
- return sdkClient;
6281
- }
6282
- var DEFAULT_BACKEND = { type: "athena" };
6283
- function toBackendConfig(b) {
6284
- if (!b) return DEFAULT_BACKEND;
6285
- return typeof b === "string" ? { type: b } : b;
6286
- }
6287
- function mergeAuthClientConfig(current, next) {
6288
- const merged = {
6289
- ...current ?? {},
6290
- ...next
6291
- };
6292
- if (current?.headers || next.headers) {
6293
- merged.headers = {
6294
- ...current?.headers ?? {},
6295
- ...next.headers ?? {}
6296
- };
6297
- }
6298
- return merged;
6299
- }
6300
- function mergeExperimentalOptions(current, next) {
6301
- const merged = {
6302
- ...current ?? {},
6303
- ...next
6304
- };
6305
- if (current?.traceQueries && typeof current.traceQueries === "object" && next.traceQueries && typeof next.traceQueries === "object") {
6306
- merged.traceQueries = {
6307
- ...current.traceQueries,
6308
- ...next.traceQueries
6309
- };
6310
7590
  }
6311
- if (current?.storage || next.storage) {
6312
- merged.storage = {
6313
- ...current?.storage ?? {},
6314
- ...next.storage ?? {}
6315
- };
6316
- }
6317
- return merged;
6318
- }
6319
- var AthenaClientBuilderImpl = class {
6320
- baseUrl;
6321
- apiKey;
6322
- backendConfig = DEFAULT_BACKEND;
6323
- clientName;
6324
- defaultHeaders;
6325
- authConfig;
6326
- experimentalOptions;
6327
- url(url) {
6328
- this.baseUrl = url;
6329
- return this;
6330
- }
6331
- key(apiKey) {
6332
- this.apiKey = apiKey;
6333
- return this;
6334
- }
6335
- backend(backend) {
6336
- this.backendConfig = toBackendConfig(backend);
6337
- return this;
6338
- }
6339
- client(clientName) {
6340
- this.clientName = clientName;
6341
- return this;
6342
- }
6343
- headers(headers) {
6344
- this.defaultHeaders = headers;
6345
- return this;
6346
- }
6347
- auth(config) {
6348
- this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6349
- return this;
6350
- }
6351
- experimental(options) {
6352
- this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options);
6353
- return options.athenaStorageBackend ? this : this;
6354
- }
6355
- options(options) {
6356
- if (options.client !== void 0) {
6357
- this.clientName = options.client;
6358
- }
6359
- if (options.backend !== void 0) {
6360
- this.backendConfig = toBackendConfig(options.backend);
6361
- }
6362
- if (options.headers !== void 0) {
6363
- this.defaultHeaders = {
6364
- ...this.defaultHeaders ?? {},
6365
- ...options.headers
6366
- };
6367
- }
6368
- if (options.auth !== void 0) {
6369
- this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6370
- }
6371
- if (options.experimental !== void 0) {
6372
- this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options.experimental);
6373
- }
6374
- return options.experimental?.athenaStorageBackend ? this : this;
6375
- }
6376
- build() {
6377
- if (!this.baseUrl || !this.apiKey) {
6378
- throw new Error("AthenaClient requires url and key; call .url() and .key() before .build()");
7591
+ const rpc = (fn, args, options) => {
7592
+ const normalizedFn = fn.trim();
7593
+ if (!normalizedFn) {
7594
+ throw new Error("rpc requires a function name");
6379
7595
  }
6380
- return createClientFromConfig({
6381
- baseUrl: this.baseUrl,
6382
- apiKey: this.apiKey,
6383
- client: this.clientName,
6384
- backend: this.backendConfig,
6385
- headers: this.defaultHeaders,
6386
- auth: this.authConfig,
6387
- experimental: this.experimentalOptions
6388
- });
7596
+ return createRpcBuilder(
7597
+ normalizedFn,
7598
+ args,
7599
+ options,
7600
+ gateway,
7601
+ formatGatewayResult,
7602
+ queryTracer,
7603
+ captureTraceCallsite(queryTracer),
7604
+ Boolean(config.experimental?.debugAst)
7605
+ );
7606
+ };
7607
+ const query = createQueryBuilder(
7608
+ gateway,
7609
+ formatGatewayResult,
7610
+ config.experimental,
7611
+ queryTracer
7612
+ );
7613
+ const db = createDbModule({ from, rpc, query });
7614
+ const sdkClient = {
7615
+ from,
7616
+ db,
7617
+ rpc,
7618
+ query,
7619
+ verifyConnection: gateway.verifyConnection,
7620
+ auth: auth.auth
7621
+ };
7622
+ if (config.experimental?.athenaStorageBackend) {
7623
+ const storageClient = {
7624
+ ...sdkClient,
7625
+ storage: createStorageModule(gateway, {
7626
+ ...config.experimental.storage,
7627
+ ...config.storageUrl ? {
7628
+ baseUrl: config.storageUrl,
7629
+ stripBasePath: true
7630
+ } : {}
7631
+ })
7632
+ };
7633
+ return storageClient;
6389
7634
  }
6390
- };
6391
- var AthenaClient = class _AthenaClient {
7635
+ return sdkClient;
7636
+ }
7637
+ var AthenaClient = class {
6392
7638
  /** Create a fluent builder for a strongly-typed Athena SDK client. */
6393
7639
  static builder() {
6394
- return new AthenaClientBuilderImpl();
7640
+ return createAthenaClientBuilder((config) => createClientFromConfig(resolveCreateClientConfig(config)));
6395
7641
  }
6396
7642
  /** Build a client from process environment variables. */
6397
7643
  static fromEnvironment() {
6398
- const url = process.env.ATHENA_URL ?? process.env.ATHENA_GATEWAY_URL;
7644
+ const url = process.env.ATHENA_URL;
7645
+ const gatewayUrl = process.env.ATHENA_DB_URL ?? process.env.ATHENA_GATEWAY_URL;
7646
+ const authUrl = process.env.ATHENA_AUTH_URL;
7647
+ const storageUrl = process.env.ATHENA_STORAGE_URL;
6399
7648
  const key = process.env.ATHENA_API_KEY ?? process.env.ATHENA_GATEWAY_API_KEY;
6400
- if (!url || !key) {
7649
+ if (!url && !gatewayUrl || !key) {
6401
7650
  throw new Error(
6402
- "ATHENA_URL and ATHENA_API_KEY (or ATHENA_GATEWAY_URL and ATHENA_GATEWAY_API_KEY) are required"
7651
+ "ATHENA_API_KEY plus ATHENA_URL or ATHENA_GATEWAY_URL (optionally ATHENA_DB_URL, ATHENA_AUTH_URL, ATHENA_STORAGE_URL) are required"
6403
7652
  );
6404
7653
  }
6405
- return _AthenaClient.builder().url(url).key(key).build();
7654
+ return createClient({
7655
+ url,
7656
+ gatewayUrl,
7657
+ authUrl,
7658
+ storageUrl,
7659
+ key
7660
+ });
6406
7661
  }
6407
7662
  };
6408
- function createClient(url, apiKey, options) {
6409
- return createClientFromConfig({
6410
- baseUrl: url,
6411
- apiKey,
6412
- client: options?.client,
6413
- backend: toBackendConfig(options?.backend),
6414
- headers: options?.headers,
6415
- auth: options?.auth,
6416
- experimental: options?.experimental
6417
- });
7663
+ function createClient(configOrUrl, apiKey, options) {
7664
+ if (typeof configOrUrl === "string") {
7665
+ return createClientFromConfig(resolveCreateClientConfig({
7666
+ url: configOrUrl,
7667
+ key: apiKey ?? "",
7668
+ ...options
7669
+ }));
7670
+ }
7671
+ return createClientFromConfig(resolveCreateClientConfig(configOrUrl));
6418
7672
  }
6419
7673
 
6420
7674
  // src/gateway/types.ts
@@ -6439,6 +7693,379 @@ function defineRegistry(databases) {
6439
7693
  return databases;
6440
7694
  }
6441
7695
 
7696
+ // src/schema/model-form.ts
7697
+ function resolveNullishValue(mode) {
7698
+ if (mode === "undefined") return void 0;
7699
+ if (mode === "null") return null;
7700
+ return "";
7701
+ }
7702
+ function isRecord10(value) {
7703
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
7704
+ }
7705
+ function isNullableColumn(model, key) {
7706
+ const nullable = model.meta.nullable;
7707
+ return nullable?.[key] === true;
7708
+ }
7709
+ function toModelFormDefaults(model, values, options) {
7710
+ const source = values;
7711
+ if (!isRecord10(source)) {
7712
+ return {};
7713
+ }
7714
+ const mode = options?.nullishMode ?? "empty-string";
7715
+ const nullishValue = resolveNullishValue(mode);
7716
+ const result = {};
7717
+ for (const [key, value] of Object.entries(source)) {
7718
+ if (value === null && isNullableColumn(model, key)) {
7719
+ result[key] = nullishValue;
7720
+ continue;
7721
+ }
7722
+ result[key] = value;
7723
+ }
7724
+ return result;
7725
+ }
7726
+ function toModelPayload(model, formValues, options) {
7727
+ const emptyStringAsNull = options?.emptyStringAsNull ?? true;
7728
+ const stripUndefined = options?.stripUndefined ?? true;
7729
+ const result = {};
7730
+ for (const [key, rawValue] of Object.entries(formValues)) {
7731
+ if (rawValue === void 0 && stripUndefined) {
7732
+ continue;
7733
+ }
7734
+ if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
7735
+ result[key] = null;
7736
+ continue;
7737
+ }
7738
+ result[key] = rawValue;
7739
+ }
7740
+ return result;
7741
+ }
7742
+ function createModelFormAdapter(model) {
7743
+ return {
7744
+ model,
7745
+ toDefaults(values, options) {
7746
+ return toModelFormDefaults(model, values, options);
7747
+ },
7748
+ toInsert(values, options) {
7749
+ return toModelPayload(model, values, options);
7750
+ },
7751
+ toUpdate(values, options) {
7752
+ return toModelPayload(model, values, options);
7753
+ }
7754
+ };
7755
+ }
7756
+
7757
+ // src/schema/table-columns.ts
7758
+ var COLUMN_CONFIG = /* @__PURE__ */ Symbol("athena.column.config");
7759
+ function createColumnBuilder(config) {
7760
+ return {
7761
+ [COLUMN_CONFIG]: config,
7762
+ optional() {
7763
+ return createColumnBuilder({
7764
+ ...config,
7765
+ nullable: true
7766
+ });
7767
+ },
7768
+ from(columnName) {
7769
+ return createColumnBuilder({
7770
+ ...config,
7771
+ columnName
7772
+ });
7773
+ },
7774
+ defaulted() {
7775
+ return createColumnBuilder({
7776
+ ...config,
7777
+ hasDefault: true
7778
+ });
7779
+ },
7780
+ generated() {
7781
+ return createColumnBuilder({
7782
+ ...config,
7783
+ isGenerated: true
7784
+ });
7785
+ }
7786
+ };
7787
+ }
7788
+ function isColumnBuilder(value) {
7789
+ return value !== null && typeof value === "object" && COLUMN_CONFIG in value;
7790
+ }
7791
+ function getColumnConfig(column) {
7792
+ return column[COLUMN_CONFIG];
7793
+ }
7794
+ function string() {
7795
+ return createColumnBuilder({
7796
+ kind: "string",
7797
+ nullable: false,
7798
+ hasDefault: false,
7799
+ isGenerated: false
7800
+ });
7801
+ }
7802
+ function number() {
7803
+ return createColumnBuilder({
7804
+ kind: "number",
7805
+ nullable: false,
7806
+ hasDefault: false,
7807
+ isGenerated: false
7808
+ });
7809
+ }
7810
+ function boolean() {
7811
+ return createColumnBuilder({
7812
+ kind: "boolean",
7813
+ nullable: false,
7814
+ hasDefault: false,
7815
+ isGenerated: false
7816
+ });
7817
+ }
7818
+ function json(schema) {
7819
+ return createColumnBuilder({
7820
+ kind: "json",
7821
+ nullable: false,
7822
+ hasDefault: false,
7823
+ isGenerated: false,
7824
+ jsonSchema: schema
7825
+ });
7826
+ }
7827
+ function enumeration(values) {
7828
+ if (values.length === 0) {
7829
+ throw new Error("enumeration() requires at least one value");
7830
+ }
7831
+ return createColumnBuilder({
7832
+ kind: "enumeration",
7833
+ nullable: false,
7834
+ hasDefault: false,
7835
+ isGenerated: false,
7836
+ enumValues: values
7837
+ });
7838
+ }
7839
+
7840
+ // src/schema/table-schemas.ts
7841
+ function isScalarFormKind(kind) {
7842
+ return kind === "string" || kind === "number" || kind === "boolean" || kind === "enumeration";
7843
+ }
7844
+ function createBaseSchema(column) {
7845
+ const config = getColumnConfig(column);
7846
+ switch (config.kind) {
7847
+ case "boolean":
7848
+ return z.boolean();
7849
+ case "number":
7850
+ return z.number();
7851
+ case "json":
7852
+ return config.jsonSchema ?? z.unknown();
7853
+ case "enumeration":
7854
+ if (!config.enumValues || config.enumValues.length === 0) {
7855
+ return z.string();
7856
+ }
7857
+ return z.enum(config.enumValues);
7858
+ case "string":
7859
+ default:
7860
+ return z.string();
7861
+ }
7862
+ }
7863
+ function applyNullable(schema, column) {
7864
+ const config = getColumnConfig(column);
7865
+ return config.nullable ? schema.nullable() : schema;
7866
+ }
7867
+ function applyInsertOptional(schema, column) {
7868
+ const config = getColumnConfig(column);
7869
+ return config.nullable || config.hasDefault ? schema.optional() : schema;
7870
+ }
7871
+ function createFormFieldSchema(column) {
7872
+ const config = getColumnConfig(column);
7873
+ const base = createBaseSchema(column);
7874
+ let schema;
7875
+ if (config.nullable && isScalarFormKind(config.kind)) {
7876
+ schema = z.union([base, z.literal("")]).transform((value) => value === "" ? null : value);
7877
+ } else {
7878
+ schema = applyNullable(base, column);
7879
+ }
7880
+ if (config.nullable || config.hasDefault) {
7881
+ schema = schema.optional();
7882
+ }
7883
+ return schema;
7884
+ }
7885
+ function buildTableSchemaBundle(model, columns) {
7886
+ const rowShape = {};
7887
+ const insertShape = {};
7888
+ const updateShape = {};
7889
+ const formShape = {};
7890
+ for (const [columnName, column] of Object.entries(columns)) {
7891
+ const config = getColumnConfig(column);
7892
+ const base = createBaseSchema(column);
7893
+ rowShape[columnName] = applyNullable(base, column);
7894
+ if (config.isGenerated) {
7895
+ continue;
7896
+ }
7897
+ insertShape[columnName] = applyInsertOptional(applyNullable(base, column), column);
7898
+ updateShape[columnName] = applyNullable(base, column).optional();
7899
+ formShape[columnName] = createFormFieldSchema(column);
7900
+ }
7901
+ const rowSchema = z.object(rowShape);
7902
+ const insertSchema = z.object(insertShape);
7903
+ const updateSchema = z.object(updateShape);
7904
+ const formSchema = z.object(formShape).transform((value) => toModelPayload(model, value));
7905
+ return {
7906
+ row: rowSchema,
7907
+ insert: insertSchema,
7908
+ update: updateSchema,
7909
+ form: formSchema
7910
+ };
7911
+ }
7912
+
7913
+ // src/schema/table-builder.ts
7914
+ function assertColumnRecord(columns) {
7915
+ for (const [columnName, column] of Object.entries(columns)) {
7916
+ if (!isColumnBuilder(column)) {
7917
+ throw new Error(`Invalid column definition for "${columnName}"`);
7918
+ }
7919
+ }
7920
+ }
7921
+ function normalizeMappedNameInput(mappedName) {
7922
+ const normalized = mappedName.trim();
7923
+ if (!normalized) {
7924
+ throw new Error("table.from() requires a non-empty table name");
7925
+ }
7926
+ return normalized;
7927
+ }
7928
+ function normalizeSchemaNameInput(schemaName) {
7929
+ const normalized = schemaName.trim();
7930
+ if (!normalized) {
7931
+ throw new Error("table.schema() requires a non-empty schema name");
7932
+ }
7933
+ if (normalized.includes(".")) {
7934
+ throw new Error(
7935
+ 'table.schema() expects a schema name without dots. Use .schema("schema").from("table") or .from("schema.table").'
7936
+ );
7937
+ }
7938
+ return normalized;
7939
+ }
7940
+ function resolveTableTarget(logicalName, mappedName, explicitSchemaName) {
7941
+ const physicalName = (mappedName ?? logicalName).trim();
7942
+ if (!physicalName) {
7943
+ throw new Error("table() requires a non-empty name");
7944
+ }
7945
+ const firstDot = physicalName.indexOf(".");
7946
+ const lastDot = physicalName.lastIndexOf(".");
7947
+ if (firstDot > 0 && firstDot === lastDot) {
7948
+ const inlineSchema = physicalName.slice(0, firstDot).trim();
7949
+ const inlineModel = physicalName.slice(firstDot + 1).trim();
7950
+ if (!inlineSchema || !inlineModel) {
7951
+ throw new Error('table.from() schema-qualified names must look like "schema.table"');
7952
+ }
7953
+ if (explicitSchemaName && explicitSchemaName !== inlineSchema) {
7954
+ throw new Error(
7955
+ `table schema "${explicitSchemaName}" conflicts with mapped table "${physicalName}"`
7956
+ );
7957
+ }
7958
+ return {
7959
+ schema: explicitSchemaName ?? inlineSchema,
7960
+ model: inlineModel,
7961
+ qualifiedName: `${explicitSchemaName ?? inlineSchema}.${inlineModel}`
7962
+ };
7963
+ }
7964
+ if (explicitSchemaName) {
7965
+ return {
7966
+ schema: explicitSchemaName,
7967
+ model: physicalName,
7968
+ qualifiedName: `${explicitSchemaName}.${physicalName}`
7969
+ };
7970
+ }
7971
+ return {
7972
+ model: physicalName,
7973
+ qualifiedName: physicalName
7974
+ };
7975
+ }
7976
+ function toColumnMetadata(column) {
7977
+ const config = getColumnConfig(column);
7978
+ return {
7979
+ kind: config.kind,
7980
+ columnName: config.columnName,
7981
+ nullable: config.nullable,
7982
+ hasDefault: config.hasDefault,
7983
+ isGenerated: config.isGenerated,
7984
+ enumValues: config.enumValues
7985
+ };
7986
+ }
7987
+ function buildNullableMap(columns) {
7988
+ return Object.fromEntries(
7989
+ Object.entries(columns).map(([columnName, column]) => [columnName, getColumnConfig(column).nullable])
7990
+ );
7991
+ }
7992
+ function buildColumnMetadataMap(columns) {
7993
+ return Object.fromEntries(
7994
+ Object.entries(columns).map(([columnName, column]) => [columnName, toColumnMetadata(column)])
7995
+ );
7996
+ }
7997
+ function finalizeTable(name, mappedName, schemaName, columns, primaryKey) {
7998
+ const target = resolveTableTarget(name, mappedName, schemaName);
7999
+ const model = defineModel({
8000
+ meta: {
8001
+ schema: target.schema,
8002
+ model: target.model,
8003
+ primaryKey: [...primaryKey],
8004
+ nullable: buildNullableMap(columns),
8005
+ columns: buildColumnMetadataMap(columns)
8006
+ }
8007
+ });
8008
+ const schemas = buildTableSchemaBundle(model, columns);
8009
+ return Object.assign(model, {
8010
+ kind: "table",
8011
+ name,
8012
+ mappedName,
8013
+ schemaName: target.schema,
8014
+ tableName: target.model,
8015
+ qualifiedName: target.qualifiedName,
8016
+ columns,
8017
+ schemas
8018
+ });
8019
+ }
8020
+ function createColumnsBuilder(name, mappedName, schemaName, columns) {
8021
+ assertColumnRecord(columns);
8022
+ return {
8023
+ name,
8024
+ mappedName,
8025
+ schemaName,
8026
+ columns,
8027
+ from(tableName) {
8028
+ const normalizedTableName = normalizeMappedNameInput(tableName);
8029
+ resolveTableTarget(name, normalizedTableName, schemaName);
8030
+ return createColumnsBuilder(name, normalizedTableName, schemaName, columns);
8031
+ },
8032
+ schema(nextSchemaName) {
8033
+ const normalizedSchemaName = normalizeSchemaNameInput(nextSchemaName);
8034
+ resolveTableTarget(name, mappedName, normalizedSchemaName);
8035
+ return createColumnsBuilder(name, mappedName, normalizedSchemaName, columns);
8036
+ },
8037
+ primaryKey(...keys) {
8038
+ return finalizeTable(name, mappedName, schemaName, columns, keys);
8039
+ }
8040
+ };
8041
+ }
8042
+ function createTableBuilder2(name, mappedName, schemaName) {
8043
+ return {
8044
+ name,
8045
+ mappedName,
8046
+ schemaName,
8047
+ from(tableName) {
8048
+ const normalizedTableName = normalizeMappedNameInput(tableName);
8049
+ resolveTableTarget(name, normalizedTableName, schemaName);
8050
+ return createTableBuilder2(name, normalizedTableName, schemaName);
8051
+ },
8052
+ schema(nextSchemaName) {
8053
+ const normalizedSchemaName = normalizeSchemaNameInput(nextSchemaName);
8054
+ resolveTableTarget(name, mappedName, normalizedSchemaName);
8055
+ return createTableBuilder2(name, mappedName, normalizedSchemaName);
8056
+ },
8057
+ columns(columns) {
8058
+ return createColumnsBuilder(name, mappedName, schemaName, columns);
8059
+ }
8060
+ };
8061
+ }
8062
+ function table(name) {
8063
+ if (!name.trim()) {
8064
+ throw new Error("table() requires a non-empty name");
8065
+ }
8066
+ return createTableBuilder2(name, void 0, void 0);
8067
+ }
8068
+
6442
8069
  // src/schema/typed-client.ts
6443
8070
  var TenantHeaderMapper = class {
6444
8071
  constructor(tenantKeyMap) {
@@ -6478,12 +8105,10 @@ var RegistryNavigator = class {
6478
8105
  return modelDef;
6479
8106
  }
6480
8107
  resolveTableName(schema, model, modelDef) {
6481
- if (modelDef.meta.tableName) {
6482
- return modelDef.meta.tableName;
6483
- }
6484
- const schemaName = modelDef.meta.schema ?? schema;
6485
- const modelName = modelDef.meta.model ?? model;
6486
- return `${schemaName}.${modelName}`;
8108
+ return resolveAthenaModelTargetTableName(modelDef, {
8109
+ fallbackSchema: schema,
8110
+ fallbackModel: model
8111
+ });
6487
8112
  }
6488
8113
  };
6489
8114
  var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
@@ -6510,17 +8135,20 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
6510
8135
  this.clientOptions = {
6511
8136
  backend: input.options?.backend,
6512
8137
  client: input.options?.client,
6513
- headers: input.options?.headers
8138
+ headers: input.options?.headers,
8139
+ experimental: input.options?.experimental
6514
8140
  };
6515
8141
  this.baseClient = createClient(this.url, this.apiKey, {
6516
8142
  backend: this.clientOptions.backend,
6517
8143
  client: this.clientOptions.client,
6518
- headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext)
8144
+ headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext),
8145
+ experimental: this.clientOptions.experimental
6519
8146
  });
6520
8147
  this.db = this.baseClient.db;
6521
8148
  }
6522
- from(table, options) {
6523
- return this.baseClient.from(table, options);
8149
+ from(tableOrModel, options) {
8150
+ const from = this.baseClient.from;
8151
+ return from(tableOrModel, options);
6524
8152
  }
6525
8153
  rpc(fn, args, options) {
6526
8154
  return this.baseClient.rpc(fn, args, options);
@@ -6542,7 +8170,8 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
6542
8170
  tenantContext: {
6543
8171
  ...this.tenantContext,
6544
8172
  ...context ?? {}
6545
- }
8173
+ },
8174
+ experimental: this.clientOptions.experimental
6546
8175
  }
6547
8176
  });
6548
8177
  }
@@ -6561,67 +8190,6 @@ function createTypedClient(registry, url, apiKey, options) {
6561
8190
  });
6562
8191
  }
6563
8192
 
6564
- // src/schema/model-form.ts
6565
- function resolveNullishValue(mode) {
6566
- if (mode === "undefined") return void 0;
6567
- if (mode === "null") return null;
6568
- return "";
6569
- }
6570
- function isRecord9(value) {
6571
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6572
- }
6573
- function isNullableColumn(model, key) {
6574
- const nullable = model.meta.nullable;
6575
- return nullable?.[key] === true;
6576
- }
6577
- function toModelFormDefaults(model, values, options) {
6578
- const source = values;
6579
- if (!isRecord9(source)) {
6580
- return {};
6581
- }
6582
- const mode = options?.nullishMode ?? "empty-string";
6583
- const nullishValue = resolveNullishValue(mode);
6584
- const result = {};
6585
- for (const [key, value] of Object.entries(source)) {
6586
- if (value === null && isNullableColumn(model, key)) {
6587
- result[key] = nullishValue;
6588
- continue;
6589
- }
6590
- result[key] = value;
6591
- }
6592
- return result;
6593
- }
6594
- function toModelPayload(model, formValues, options) {
6595
- const emptyStringAsNull = options?.emptyStringAsNull ?? true;
6596
- const stripUndefined = options?.stripUndefined ?? true;
6597
- const result = {};
6598
- for (const [key, rawValue] of Object.entries(formValues)) {
6599
- if (rawValue === void 0 && stripUndefined) {
6600
- continue;
6601
- }
6602
- if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
6603
- result[key] = null;
6604
- continue;
6605
- }
6606
- result[key] = rawValue;
6607
- }
6608
- return result;
6609
- }
6610
- function createModelFormAdapter(model) {
6611
- return {
6612
- model,
6613
- toDefaults(values, options) {
6614
- return toModelFormDefaults(model, values, options);
6615
- },
6616
- toInsert(values, options) {
6617
- return toModelPayload(model, values, options);
6618
- },
6619
- toUpdate(values, options) {
6620
- return toModelPayload(model, values, options);
6621
- }
6622
- };
6623
- }
6624
-
6625
8193
  // src/generator/schema-selection.ts
6626
8194
  var DEFAULT_POSTGRES_SCHEMAS = ["public"];
6627
8195
  function collectSchemaNames(input) {
@@ -6916,15 +8484,15 @@ function readCookieFromHeaders(headers, name) {
6916
8484
  }
6917
8485
  return parseCookies(cookieHeader).get(name);
6918
8486
  }
6919
- function isRecord10(value) {
8487
+ function isRecord11(value) {
6920
8488
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6921
8489
  }
6922
8490
  function resolveSessionCandidate(value) {
6923
- if (!isRecord10(value)) {
8491
+ if (!isRecord11(value)) {
6924
8492
  return null;
6925
8493
  }
6926
- const session = isRecord10(value.session) ? value.session : void 0;
6927
- const user = isRecord10(value.user) ? value.user : void 0;
8494
+ const session = isRecord11(value.session) ? value.session : void 0;
8495
+ const user = isRecord11(value.user) ? value.user : void 0;
6928
8496
  if (session && typeof session.token === "string" && session.token.length > 0 && user) {
6929
8497
  return {
6930
8498
  session,
@@ -6934,7 +8502,7 @@ function resolveSessionCandidate(value) {
6934
8502
  return null;
6935
8503
  }
6936
8504
  function inferSessionPair(returned) {
6937
- return resolveSessionCandidate(returned) ?? (isRecord10(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord10(returned) ? resolveSessionCandidate(returned.session) : null);
8505
+ return resolveSessionCandidate(returned) ?? (isRecord11(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord11(returned) ? resolveSessionCandidate(returned.session) : null);
6938
8506
  }
6939
8507
  function resolveResponseHeaders(ctx) {
6940
8508
  if (ctx.context.responseHeaders instanceof Headers) {
@@ -7309,6 +8877,6 @@ async function runSchemaGenerator(options = {}) {
7309
8877
  return throwBrowserUnsupported("runSchemaGenerator");
7310
8878
  }
7311
8879
 
7312
- export { ATHENA_AUTH_BASE_ERROR_CODES, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, identifier, isAthenaGatewayError, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
8880
+ export { ATHENA_AUTH_BASE_ERROR_CODES, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
7313
8881
  //# sourceMappingURL=browser.js.map
7314
8882
  //# sourceMappingURL=browser.js.map