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