@xylex-group/athena 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -2
- package/bin/athena-js.js +0 -0
- package/dist/browser.cjs +2245 -151
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +2238 -152
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +1073 -102
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +1073 -102
- package/dist/cli/index.js.map +1 -1
- package/dist/cookies.d.cts +1 -174
- package/dist/cookies.d.ts +1 -174
- package/dist/index-CVcQCGyG.d.cts +174 -0
- package/dist/index-CVcQCGyG.d.ts +174 -0
- package/dist/index.cjs +2246 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +2239 -153
- package/dist/index.js.map +1 -1
- package/dist/{model-form-GzTqhEzM.d.cts → model-form-BaHWi3gm.d.cts} +9 -5
- package/dist/{model-form-C0FAbOaf.d.ts → model-form-Dh6gWjL0.d.ts} +9 -5
- package/dist/{pipeline-CR4V15jF.d.ts → pipeline-Ce3pTw5h.d.ts} +1 -1
- package/dist/{pipeline-DZeExYMA.d.cts → pipeline-D1ZYeoH7.d.cts} +1 -1
- package/dist/{react-email-CQJq92zQ.d.cts → react-email-B8O1Jeff.d.cts} +637 -30
- package/dist/{react-email-BuApZuyG.d.ts → react-email-CDEF0jij.d.ts} +637 -30
- package/dist/react.cjs +84 -4
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +84 -4
- package/dist/react.js.map +1 -1
- package/dist/{types-D1JvL21V.d.cts → types-CUuo4NDi.d.cts} +1 -1
- package/dist/{types-09Q4D86N.d.cts → types-DSX6AT5B.d.cts} +3 -3
- package/dist/{types-09Q4D86N.d.ts → types-DSX6AT5B.d.ts} +3 -3
- package/dist/{types-DU3gNdFv.d.ts → types-DapchQY5.d.ts} +1 -1
- package/dist/utils.cjs +131 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +42 -1
- package/dist/utils.d.ts +42 -1
- package/dist/utils.js +117 -1
- package/dist/utils.js.map +1 -1
- package/package.json +193 -192
package/dist/cli/index.js
CHANGED
|
@@ -661,6 +661,54 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
661
661
|
raw: resultOrError
|
|
662
662
|
};
|
|
663
663
|
}
|
|
664
|
+
function defaultShouldRetry(error) {
|
|
665
|
+
const normalized = normalizeAthenaError(error);
|
|
666
|
+
return normalized.kind === "transient" || normalized.kind === "rate_limit";
|
|
667
|
+
}
|
|
668
|
+
function computeDelayMs(attempt, error, config) {
|
|
669
|
+
const baseDelay = config.baseDelayMs;
|
|
670
|
+
const rawDelay = typeof config.backoff === "function" ? config.backoff(attempt, error) : config.backoff === "linear" ? baseDelay * attempt : baseDelay * Math.pow(2, attempt - 1);
|
|
671
|
+
const safeDelay = Number.isFinite(rawDelay) ? Math.max(0, rawDelay) : 0;
|
|
672
|
+
const clamped = Math.min(config.maxDelayMs, safeDelay);
|
|
673
|
+
const jitterFactor = typeof config.jitter === "number" ? Math.max(0, Math.min(1, config.jitter)) : config.jitter ? 0.2 : 0;
|
|
674
|
+
if (!jitterFactor) return clamped;
|
|
675
|
+
const deviation = clamped * jitterFactor;
|
|
676
|
+
const offset = (Math.random() * 2 - 1) * deviation;
|
|
677
|
+
return Math.max(0, clamped + offset);
|
|
678
|
+
}
|
|
679
|
+
function sleep(ms) {
|
|
680
|
+
if (ms <= 0) return Promise.resolve();
|
|
681
|
+
return new Promise((resolve3) => {
|
|
682
|
+
setTimeout(resolve3, ms);
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
async function withRetry(config, fn) {
|
|
686
|
+
const retries = Math.max(0, Math.trunc(config.retries));
|
|
687
|
+
const shouldRetry = config.shouldRetry ?? defaultShouldRetry;
|
|
688
|
+
const resolvedConfig = {
|
|
689
|
+
baseDelayMs: config.baseDelayMs ?? 100,
|
|
690
|
+
maxDelayMs: config.maxDelayMs ?? 1e4,
|
|
691
|
+
backoff: config.backoff ?? "exponential",
|
|
692
|
+
jitter: config.jitter ?? false
|
|
693
|
+
};
|
|
694
|
+
for (let attempts = 0; attempts <= retries; attempts += 1) {
|
|
695
|
+
try {
|
|
696
|
+
return await fn();
|
|
697
|
+
} catch (error) {
|
|
698
|
+
if (attempts >= retries) {
|
|
699
|
+
throw error;
|
|
700
|
+
}
|
|
701
|
+
const currentAttempt = attempts + 1;
|
|
702
|
+
const retry = await shouldRetry(error, currentAttempt);
|
|
703
|
+
if (!retry) {
|
|
704
|
+
throw error;
|
|
705
|
+
}
|
|
706
|
+
const delay = computeDelayMs(currentAttempt, error, resolvedConfig);
|
|
707
|
+
await sleep(delay);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
throw new Error("withRetry reached an unexpected state");
|
|
711
|
+
}
|
|
664
712
|
|
|
665
713
|
// src/generator/schema-selection.ts
|
|
666
714
|
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
@@ -1428,12 +1476,47 @@ function buildAthenaGatewayUrl(baseUrl, path) {
|
|
|
1428
1476
|
return `${baseUrl}${path}`;
|
|
1429
1477
|
}
|
|
1430
1478
|
|
|
1479
|
+
// src/cookies/cookie-utils.ts
|
|
1480
|
+
var SECURE_COOKIE_PREFIX = "__Secure-";
|
|
1481
|
+
function parseCookies(cookieHeader) {
|
|
1482
|
+
const cookies = cookieHeader.split("; ");
|
|
1483
|
+
const cookieMap = /* @__PURE__ */ new Map();
|
|
1484
|
+
cookies.forEach((cookie) => {
|
|
1485
|
+
const [name, value] = cookie.split(/=(.*)/s);
|
|
1486
|
+
cookieMap.set(name, value);
|
|
1487
|
+
});
|
|
1488
|
+
return cookieMap;
|
|
1489
|
+
}
|
|
1490
|
+
var getSessionCookie = (request, config) => {
|
|
1491
|
+
const cookies = (request instanceof Headers || !("headers" in request) ? request : request.headers).get("cookie");
|
|
1492
|
+
if (!cookies) {
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
const { cookieName = "session_token", cookiePrefix = "athena-auth" } = {};
|
|
1496
|
+
const parsedCookie = parseCookies(cookies);
|
|
1497
|
+
const getCookie = (name) => parsedCookie.get(name) || parsedCookie.get(`${SECURE_COOKIE_PREFIX}${name}`);
|
|
1498
|
+
const sessionToken = getCookie(`${cookiePrefix}.${cookieName}`) || getCookie(`${cookiePrefix}-${cookieName}`);
|
|
1499
|
+
if (sessionToken) {
|
|
1500
|
+
return sessionToken;
|
|
1501
|
+
}
|
|
1502
|
+
return null;
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
// package.json
|
|
1506
|
+
var package_default = {
|
|
1507
|
+
version: "2.6.0"
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
// src/sdk-version.ts
|
|
1511
|
+
var PACKAGE_VERSION = package_default.version;
|
|
1512
|
+
function buildSdkHeaderValue(sdkName) {
|
|
1513
|
+
return `${sdkName} ${PACKAGE_VERSION}`;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1431
1516
|
// src/gateway/client.ts
|
|
1432
1517
|
var DEFAULT_CLIENT = "railway_direct";
|
|
1433
|
-
var FALLBACK_SDK_VERSION = "1.3.0";
|
|
1434
1518
|
var SDK_NAME = "xylex-group/athena";
|
|
1435
|
-
var
|
|
1436
|
-
var SDK_HEADER_VALUE = `${SDK_NAME} ${SDK_VERSION}`;
|
|
1519
|
+
var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
|
|
1437
1520
|
function parseResponseBody(rawText, contentType) {
|
|
1438
1521
|
if (!rawText) {
|
|
1439
1522
|
return { parsed: null, parseFailed: false };
|
|
@@ -1452,6 +1535,37 @@ function parseResponseBody(rawText, contentType) {
|
|
|
1452
1535
|
function normalizeHeaderValue(value) {
|
|
1453
1536
|
return value ? value : void 0;
|
|
1454
1537
|
}
|
|
1538
|
+
function resolveHeaderValue(headers, candidates) {
|
|
1539
|
+
for (const candidate of candidates) {
|
|
1540
|
+
const direct = normalizeHeaderValue(headers[candidate]);
|
|
1541
|
+
if (direct) return direct;
|
|
1542
|
+
}
|
|
1543
|
+
const loweredCandidates = new Set(candidates.map((candidate) => candidate.toLowerCase()));
|
|
1544
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1545
|
+
if (!loweredCandidates.has(key.toLowerCase())) {
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
const normalized = normalizeHeaderValue(value);
|
|
1549
|
+
if (normalized) return normalized;
|
|
1550
|
+
}
|
|
1551
|
+
return void 0;
|
|
1552
|
+
}
|
|
1553
|
+
function resolveBearerTokenFromAuthorizationHeader(headers) {
|
|
1554
|
+
const authorization = resolveHeaderValue(headers, ["Authorization"]);
|
|
1555
|
+
if (!authorization) {
|
|
1556
|
+
return void 0;
|
|
1557
|
+
}
|
|
1558
|
+
const match = authorization.match(/^Bearer\s+(.+)$/i);
|
|
1559
|
+
const token = match?.[1]?.trim();
|
|
1560
|
+
return token ? token : void 0;
|
|
1561
|
+
}
|
|
1562
|
+
function resolveSessionTokenFromCookieHeader(headers) {
|
|
1563
|
+
const cookie = resolveHeaderValue(headers, ["Cookie"]);
|
|
1564
|
+
if (!cookie) {
|
|
1565
|
+
return void 0;
|
|
1566
|
+
}
|
|
1567
|
+
return getSessionCookie(new Headers({ cookie })) ?? void 0;
|
|
1568
|
+
}
|
|
1455
1569
|
function isRecord2(value) {
|
|
1456
1570
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1457
1571
|
}
|
|
@@ -1569,7 +1683,7 @@ function buildRpcGetEndpoint(payload) {
|
|
|
1569
1683
|
status: 0
|
|
1570
1684
|
});
|
|
1571
1685
|
}
|
|
1572
|
-
query.
|
|
1686
|
+
query.append(filter.column, toRpcFilterQueryValue(filter));
|
|
1573
1687
|
}
|
|
1574
1688
|
}
|
|
1575
1689
|
const endpoint = `/rpc/${encodeURIComponent(functionName)}`;
|
|
@@ -1615,6 +1729,20 @@ function buildHeaders(config, options) {
|
|
|
1615
1729
|
headers["apikey"] = finalApiKey;
|
|
1616
1730
|
headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
|
|
1617
1731
|
}
|
|
1732
|
+
const explicitSessionToken = resolveHeaderValue(extraHeaders, [
|
|
1733
|
+
"X-Athena-Auth-Session-Token"
|
|
1734
|
+
]);
|
|
1735
|
+
const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
|
|
1736
|
+
if (derivedSessionToken) {
|
|
1737
|
+
headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
|
|
1738
|
+
}
|
|
1739
|
+
const explicitBearerToken = resolveHeaderValue(extraHeaders, [
|
|
1740
|
+
"X-Athena-Auth-Bearer-Token"
|
|
1741
|
+
]);
|
|
1742
|
+
const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
|
|
1743
|
+
if (derivedBearerToken) {
|
|
1744
|
+
headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
|
|
1745
|
+
}
|
|
1618
1746
|
const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
|
|
1619
1747
|
Object.entries(extraHeaders).forEach(([key, value]) => {
|
|
1620
1748
|
if (athenaClientKeys.includes(key)) return;
|
|
@@ -2249,10 +2377,8 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
|
|
|
2249
2377
|
|
|
2250
2378
|
// src/auth/client.ts
|
|
2251
2379
|
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
2252
|
-
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
2253
2380
|
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
2254
|
-
var
|
|
2255
|
-
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
2381
|
+
var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
|
|
2256
2382
|
function normalizeBaseUrl(baseUrl) {
|
|
2257
2383
|
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
2258
2384
|
}
|
|
@@ -3353,6 +3479,684 @@ function createDbModule(input) {
|
|
|
3353
3479
|
return db;
|
|
3354
3480
|
}
|
|
3355
3481
|
|
|
3482
|
+
// src/storage/module.ts
|
|
3483
|
+
var storageSdkManifest = {
|
|
3484
|
+
methods: [
|
|
3485
|
+
{
|
|
3486
|
+
name: "listStorageCatalogs",
|
|
3487
|
+
method: "GET",
|
|
3488
|
+
path: "/storage/catalogs",
|
|
3489
|
+
responseEnvelope: "raw",
|
|
3490
|
+
responseType: "{ data: S3CatalogItem[] }"
|
|
3491
|
+
},
|
|
3492
|
+
{
|
|
3493
|
+
name: "createStorageCatalog",
|
|
3494
|
+
method: "POST",
|
|
3495
|
+
path: "/storage/catalogs",
|
|
3496
|
+
requestType: "CreateStorageCatalogRequest",
|
|
3497
|
+
responseEnvelope: "raw",
|
|
3498
|
+
responseType: "S3CatalogItem"
|
|
3499
|
+
},
|
|
3500
|
+
{
|
|
3501
|
+
name: "updateStorageCatalog",
|
|
3502
|
+
method: "PATCH",
|
|
3503
|
+
path: "/storage/catalogs/{id}",
|
|
3504
|
+
pathParams: ["id"],
|
|
3505
|
+
requestType: "UpdateStorageCatalogRequest",
|
|
3506
|
+
responseEnvelope: "raw",
|
|
3507
|
+
responseType: "S3CatalogItem"
|
|
3508
|
+
},
|
|
3509
|
+
{
|
|
3510
|
+
name: "deleteStorageCatalog",
|
|
3511
|
+
method: "DELETE",
|
|
3512
|
+
path: "/storage/catalogs/{id}",
|
|
3513
|
+
pathParams: ["id"],
|
|
3514
|
+
responseEnvelope: "raw",
|
|
3515
|
+
responseType: "{ id: string; deleted: boolean }"
|
|
3516
|
+
},
|
|
3517
|
+
{
|
|
3518
|
+
name: "listStorageCredentials",
|
|
3519
|
+
method: "GET",
|
|
3520
|
+
path: "/storage/credentials",
|
|
3521
|
+
responseEnvelope: "raw",
|
|
3522
|
+
responseType: "{ data: S3CredentialListItem[] }"
|
|
3523
|
+
},
|
|
3524
|
+
{
|
|
3525
|
+
name: "createStorageUploadUrl",
|
|
3526
|
+
method: "POST",
|
|
3527
|
+
path: "/storage/files/upload-url",
|
|
3528
|
+
requestType: "CreateStorageUploadUrlRequest",
|
|
3529
|
+
responseEnvelope: "athena",
|
|
3530
|
+
responseType: "StorageUploadUrlResponse"
|
|
3531
|
+
},
|
|
3532
|
+
{
|
|
3533
|
+
name: "createStorageUploadUrls",
|
|
3534
|
+
method: "POST",
|
|
3535
|
+
path: "/storage/files/upload-urls",
|
|
3536
|
+
requestType: "CreateStorageUploadUrlsRequest",
|
|
3537
|
+
responseEnvelope: "athena",
|
|
3538
|
+
responseType: "StorageBatchUploadUrlResponse"
|
|
3539
|
+
},
|
|
3540
|
+
{
|
|
3541
|
+
name: "listStorageFiles",
|
|
3542
|
+
method: "POST",
|
|
3543
|
+
path: "/storage/files/list",
|
|
3544
|
+
requestType: "ListStorageFilesRequest",
|
|
3545
|
+
responseEnvelope: "athena",
|
|
3546
|
+
responseType: "StorageListFilesResponse"
|
|
3547
|
+
},
|
|
3548
|
+
{
|
|
3549
|
+
name: "getStorageFile",
|
|
3550
|
+
method: "GET",
|
|
3551
|
+
path: "/storage/files/{file_id}",
|
|
3552
|
+
pathParams: ["file_id"],
|
|
3553
|
+
responseEnvelope: "athena",
|
|
3554
|
+
responseType: "StorageFileMutationResponse"
|
|
3555
|
+
},
|
|
3556
|
+
{
|
|
3557
|
+
name: "getStorageFileUrl",
|
|
3558
|
+
method: "GET",
|
|
3559
|
+
path: "/storage/files/{file_id}/url",
|
|
3560
|
+
pathParams: ["file_id"],
|
|
3561
|
+
queryParams: ["purpose"],
|
|
3562
|
+
responseEnvelope: "athena",
|
|
3563
|
+
responseType: "PresignedFileUrlResponse"
|
|
3564
|
+
},
|
|
3565
|
+
{
|
|
3566
|
+
name: "getStorageFileProxy",
|
|
3567
|
+
method: "GET",
|
|
3568
|
+
path: "/storage/files/{file_id}/proxy",
|
|
3569
|
+
pathParams: ["file_id"],
|
|
3570
|
+
queryParams: ["purpose"],
|
|
3571
|
+
responseEnvelope: "raw",
|
|
3572
|
+
responseType: "Response",
|
|
3573
|
+
binary: true
|
|
3574
|
+
},
|
|
3575
|
+
{
|
|
3576
|
+
name: "updateStorageFile",
|
|
3577
|
+
method: "PATCH",
|
|
3578
|
+
path: "/storage/files/{file_id}",
|
|
3579
|
+
pathParams: ["file_id"],
|
|
3580
|
+
requestType: "UpdateStorageFileRequest",
|
|
3581
|
+
responseEnvelope: "athena",
|
|
3582
|
+
responseType: "StorageFileMutationResponse"
|
|
3583
|
+
},
|
|
3584
|
+
{
|
|
3585
|
+
name: "deleteStorageFile",
|
|
3586
|
+
method: "DELETE",
|
|
3587
|
+
path: "/storage/files/{file_id}",
|
|
3588
|
+
pathParams: ["file_id"],
|
|
3589
|
+
responseEnvelope: "athena",
|
|
3590
|
+
responseType: "StorageFileMutationResponse"
|
|
3591
|
+
},
|
|
3592
|
+
{
|
|
3593
|
+
name: "setStorageFileVisibility",
|
|
3594
|
+
method: "PATCH",
|
|
3595
|
+
path: "/storage/files/{file_id}/visibility",
|
|
3596
|
+
pathParams: ["file_id"],
|
|
3597
|
+
requestType: "SetStorageFileVisibilityRequest",
|
|
3598
|
+
responseEnvelope: "athena",
|
|
3599
|
+
responseType: "StorageFileMutationResponse"
|
|
3600
|
+
},
|
|
3601
|
+
{
|
|
3602
|
+
name: "deleteStorageFolder",
|
|
3603
|
+
method: "POST",
|
|
3604
|
+
path: "/storage/folders/delete",
|
|
3605
|
+
requestType: "DeleteStorageFolderRequest",
|
|
3606
|
+
responseEnvelope: "athena",
|
|
3607
|
+
responseType: "StorageFolderMutationResponse"
|
|
3608
|
+
},
|
|
3609
|
+
{
|
|
3610
|
+
name: "moveStorageFolder",
|
|
3611
|
+
method: "POST",
|
|
3612
|
+
path: "/storage/folders/move",
|
|
3613
|
+
requestType: "MoveStorageFolderRequest",
|
|
3614
|
+
responseEnvelope: "athena",
|
|
3615
|
+
responseType: "StorageFolderMutationResponse"
|
|
3616
|
+
}
|
|
3617
|
+
]
|
|
3618
|
+
};
|
|
3619
|
+
var AthenaStorageError = class extends Error {
|
|
3620
|
+
code;
|
|
3621
|
+
athenaCode;
|
|
3622
|
+
kind;
|
|
3623
|
+
category;
|
|
3624
|
+
retryable;
|
|
3625
|
+
status;
|
|
3626
|
+
endpoint;
|
|
3627
|
+
method;
|
|
3628
|
+
requestId;
|
|
3629
|
+
hint;
|
|
3630
|
+
causeDetail;
|
|
3631
|
+
raw;
|
|
3632
|
+
normalized;
|
|
3633
|
+
__athenaNormalizedError;
|
|
3634
|
+
constructor(input) {
|
|
3635
|
+
super(input.message, { cause: input.cause });
|
|
3636
|
+
this.name = "AthenaStorageError";
|
|
3637
|
+
this.code = input.code;
|
|
3638
|
+
this.status = input.status;
|
|
3639
|
+
this.endpoint = input.endpoint;
|
|
3640
|
+
this.method = input.method;
|
|
3641
|
+
this.requestId = input.requestId;
|
|
3642
|
+
this.hint = input.hint;
|
|
3643
|
+
this.causeDetail = causeToString(input.cause);
|
|
3644
|
+
this.raw = input.raw ?? null;
|
|
3645
|
+
this.normalized = normalizeStorageErrorInput(input);
|
|
3646
|
+
this.__athenaNormalizedError = this.normalized;
|
|
3647
|
+
this.athenaCode = this.normalized.code;
|
|
3648
|
+
this.kind = this.normalized.kind;
|
|
3649
|
+
this.category = this.normalized.category;
|
|
3650
|
+
this.retryable = this.normalized.retryable;
|
|
3651
|
+
Object.defineProperty(this, "__athenaNormalizedError", {
|
|
3652
|
+
value: this.normalized,
|
|
3653
|
+
enumerable: false,
|
|
3654
|
+
configurable: false,
|
|
3655
|
+
writable: false
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
toDetails() {
|
|
3659
|
+
return {
|
|
3660
|
+
code: this.code,
|
|
3661
|
+
athenaCode: this.athenaCode,
|
|
3662
|
+
kind: this.kind,
|
|
3663
|
+
category: this.category,
|
|
3664
|
+
retryable: this.retryable,
|
|
3665
|
+
message: this.message,
|
|
3666
|
+
status: this.status,
|
|
3667
|
+
endpoint: this.endpoint,
|
|
3668
|
+
method: this.method,
|
|
3669
|
+
requestId: this.requestId,
|
|
3670
|
+
hint: this.hint,
|
|
3671
|
+
cause: this.causeDetail,
|
|
3672
|
+
raw: this.raw
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3675
|
+
};
|
|
3676
|
+
function isRecord5(value) {
|
|
3677
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3678
|
+
}
|
|
3679
|
+
function causeToString(cause) {
|
|
3680
|
+
if (cause === void 0 || cause === null) return void 0;
|
|
3681
|
+
if (typeof cause === "string") return cause;
|
|
3682
|
+
if (cause instanceof Error && cause.message.trim()) return cause.message.trim();
|
|
3683
|
+
try {
|
|
3684
|
+
return JSON.stringify(cause);
|
|
3685
|
+
} catch {
|
|
3686
|
+
return String(cause);
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
function storageGatewayCode(code) {
|
|
3690
|
+
if (code === "INVALID_URL") return "INVALID_URL";
|
|
3691
|
+
if (code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
3692
|
+
if (code === "INVALID_JSON" || code === "INVALID_ATHENA_ENVELOPE") return "INVALID_JSON";
|
|
3693
|
+
if (code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
3694
|
+
return "UNKNOWN_ERROR";
|
|
3695
|
+
}
|
|
3696
|
+
function headerValue(headers, names) {
|
|
3697
|
+
for (const name of names) {
|
|
3698
|
+
const value = headers.get(name);
|
|
3699
|
+
if (value?.trim()) return value.trim();
|
|
3700
|
+
}
|
|
3701
|
+
return void 0;
|
|
3702
|
+
}
|
|
3703
|
+
function storageOperationFromEndpoint(endpoint, method) {
|
|
3704
|
+
const endpointPath = String(endpoint).split("?")[0];
|
|
3705
|
+
for (const candidate of storageSdkManifest.methods) {
|
|
3706
|
+
if (candidate.method !== method) continue;
|
|
3707
|
+
const pattern = `^${candidate.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{[^/]+\\\}/g, "[^/]+")}$`;
|
|
3708
|
+
if (new RegExp(pattern).test(endpointPath)) {
|
|
3709
|
+
return candidate.name;
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
return `storage:${method.toLowerCase()}`;
|
|
3713
|
+
}
|
|
3714
|
+
function normalizeStorageErrorInput(input) {
|
|
3715
|
+
return normalizeAthenaError(
|
|
3716
|
+
{
|
|
3717
|
+
data: null,
|
|
3718
|
+
error: {
|
|
3719
|
+
message: input.message,
|
|
3720
|
+
gatewayCode: storageGatewayCode(input.code),
|
|
3721
|
+
status: input.status,
|
|
3722
|
+
raw: input.raw ?? input.cause ?? null
|
|
3723
|
+
},
|
|
3724
|
+
errorDetails: {
|
|
3725
|
+
code: storageGatewayCode(input.code),
|
|
3726
|
+
message: input.message,
|
|
3727
|
+
status: input.status,
|
|
3728
|
+
endpoint: input.endpoint,
|
|
3729
|
+
method: input.method,
|
|
3730
|
+
requestId: input.requestId,
|
|
3731
|
+
hint: input.hint,
|
|
3732
|
+
cause: causeToString(input.cause)
|
|
3733
|
+
},
|
|
3734
|
+
raw: input.raw ?? input.cause ?? null,
|
|
3735
|
+
status: input.status
|
|
3736
|
+
},
|
|
3737
|
+
{ operation: storageOperationFromEndpoint(input.endpoint, input.method) }
|
|
3738
|
+
);
|
|
3739
|
+
}
|
|
3740
|
+
function createAthenaStorageError(input) {
|
|
3741
|
+
return new AthenaStorageError(input);
|
|
3742
|
+
}
|
|
3743
|
+
async function notifyStorageError(error, options, runtimeOptions) {
|
|
3744
|
+
const handlers = [runtimeOptions?.onError, options?.onError].filter(
|
|
3745
|
+
(handler) => typeof handler === "function"
|
|
3746
|
+
);
|
|
3747
|
+
for (const handler of handlers) {
|
|
3748
|
+
try {
|
|
3749
|
+
await handler(error);
|
|
3750
|
+
} catch {
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
async function rejectStorageError(input, options, runtimeOptions) {
|
|
3755
|
+
const error = createAthenaStorageError(input);
|
|
3756
|
+
await notifyStorageError(error, options, runtimeOptions);
|
|
3757
|
+
throw error;
|
|
3758
|
+
}
|
|
3759
|
+
function parseResponseBody3(rawText, contentType) {
|
|
3760
|
+
if (!rawText) {
|
|
3761
|
+
return { parsed: null, parseFailed: false };
|
|
3762
|
+
}
|
|
3763
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
3764
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
3765
|
+
if (!looksJson) {
|
|
3766
|
+
return { parsed: rawText, parseFailed: false };
|
|
3767
|
+
}
|
|
3768
|
+
try {
|
|
3769
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
3770
|
+
} catch {
|
|
3771
|
+
return { parsed: rawText, parseFailed: true };
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
function appendQuery(path, query) {
|
|
3775
|
+
if (!query) return path;
|
|
3776
|
+
const params = new URLSearchParams();
|
|
3777
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3778
|
+
if (value === void 0 || value === null) continue;
|
|
3779
|
+
params.set(key, String(value));
|
|
3780
|
+
}
|
|
3781
|
+
const queryText = params.toString();
|
|
3782
|
+
return queryText ? `${path}?${queryText}` : path;
|
|
3783
|
+
}
|
|
3784
|
+
function storagePath(path) {
|
|
3785
|
+
return path;
|
|
3786
|
+
}
|
|
3787
|
+
function withPathParam(path, name, value) {
|
|
3788
|
+
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
3789
|
+
}
|
|
3790
|
+
function resolveErrorMessage3(payload, fallback) {
|
|
3791
|
+
if (isRecord5(payload)) {
|
|
3792
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
3793
|
+
if (typeof message === "string" && message.trim()) {
|
|
3794
|
+
return message.trim();
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
if (typeof payload === "string" && payload.trim()) {
|
|
3798
|
+
return payload.trim();
|
|
3799
|
+
}
|
|
3800
|
+
return fallback;
|
|
3801
|
+
}
|
|
3802
|
+
function resolveErrorHint2(payload) {
|
|
3803
|
+
if (!isRecord5(payload)) return void 0;
|
|
3804
|
+
const hint = payload.hint ?? payload.suggestion;
|
|
3805
|
+
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
3806
|
+
}
|
|
3807
|
+
function resolveErrorCause(payload) {
|
|
3808
|
+
if (!isRecord5(payload)) return void 0;
|
|
3809
|
+
const cause = payload.cause ?? payload.reason;
|
|
3810
|
+
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
3811
|
+
}
|
|
3812
|
+
function storageCodeFromUnknown(error) {
|
|
3813
|
+
if (isAthenaGatewayError(error)) {
|
|
3814
|
+
if (error.code === "INVALID_URL") return "INVALID_URL";
|
|
3815
|
+
if (error.code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
3816
|
+
if (error.code === "INVALID_JSON") return "INVALID_JSON";
|
|
3817
|
+
if (error.code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
3818
|
+
}
|
|
3819
|
+
return "UNKNOWN_ERROR";
|
|
3820
|
+
}
|
|
3821
|
+
async function callStorageEndpoint(gateway, endpoint, method, envelope, payload, options, runtimeOptions) {
|
|
3822
|
+
let url;
|
|
3823
|
+
let headers;
|
|
3824
|
+
try {
|
|
3825
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
3826
|
+
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
3827
|
+
headers = gateway.buildHeaders(options);
|
|
3828
|
+
} catch (error) {
|
|
3829
|
+
return rejectStorageError(
|
|
3830
|
+
{
|
|
3831
|
+
code: storageCodeFromUnknown(error),
|
|
3832
|
+
message: error instanceof Error ? error.message : `Athena storage ${method} ${endpoint} failed before sending the request`,
|
|
3833
|
+
status: isAthenaGatewayError(error) ? error.status : 0,
|
|
3834
|
+
endpoint,
|
|
3835
|
+
method,
|
|
3836
|
+
raw: error,
|
|
3837
|
+
requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
|
|
3838
|
+
hint: isAthenaGatewayError(error) ? error.hint : void 0,
|
|
3839
|
+
cause: error
|
|
3840
|
+
},
|
|
3841
|
+
options,
|
|
3842
|
+
runtimeOptions
|
|
3843
|
+
);
|
|
3844
|
+
}
|
|
3845
|
+
const requestInit = {
|
|
3846
|
+
method,
|
|
3847
|
+
headers,
|
|
3848
|
+
signal: options?.signal
|
|
3849
|
+
};
|
|
3850
|
+
if (payload !== void 0 && method !== "GET") {
|
|
3851
|
+
requestInit.body = JSON.stringify(payload);
|
|
3852
|
+
}
|
|
3853
|
+
let response;
|
|
3854
|
+
try {
|
|
3855
|
+
response = await fetch(url, requestInit);
|
|
3856
|
+
} catch (error) {
|
|
3857
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3858
|
+
return rejectStorageError(
|
|
3859
|
+
{
|
|
3860
|
+
code: "NETWORK_ERROR",
|
|
3861
|
+
message: `Network error while calling Athena storage ${method} ${endpoint}: ${message}`,
|
|
3862
|
+
status: 0,
|
|
3863
|
+
endpoint,
|
|
3864
|
+
method,
|
|
3865
|
+
cause: error
|
|
3866
|
+
},
|
|
3867
|
+
options,
|
|
3868
|
+
runtimeOptions
|
|
3869
|
+
);
|
|
3870
|
+
}
|
|
3871
|
+
let rawText;
|
|
3872
|
+
try {
|
|
3873
|
+
rawText = await response.text();
|
|
3874
|
+
} catch (error) {
|
|
3875
|
+
return rejectStorageError(
|
|
3876
|
+
{
|
|
3877
|
+
code: "NETWORK_ERROR",
|
|
3878
|
+
message: `Athena storage ${method} ${endpoint} response body could not be read`,
|
|
3879
|
+
status: response.status,
|
|
3880
|
+
endpoint,
|
|
3881
|
+
method,
|
|
3882
|
+
requestId: headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]),
|
|
3883
|
+
cause: error
|
|
3884
|
+
},
|
|
3885
|
+
options,
|
|
3886
|
+
runtimeOptions
|
|
3887
|
+
);
|
|
3888
|
+
}
|
|
3889
|
+
const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
|
|
3890
|
+
const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
|
|
3891
|
+
if (parsedBody.parseFailed) {
|
|
3892
|
+
return rejectStorageError(
|
|
3893
|
+
{
|
|
3894
|
+
code: "INVALID_JSON",
|
|
3895
|
+
message: `Athena storage ${method} ${endpoint} returned malformed JSON`,
|
|
3896
|
+
status: response.status,
|
|
3897
|
+
endpoint,
|
|
3898
|
+
method,
|
|
3899
|
+
requestId,
|
|
3900
|
+
raw: parsedBody.parsed
|
|
3901
|
+
},
|
|
3902
|
+
options,
|
|
3903
|
+
runtimeOptions
|
|
3904
|
+
);
|
|
3905
|
+
}
|
|
3906
|
+
if (!response.ok) {
|
|
3907
|
+
return rejectStorageError(
|
|
3908
|
+
{
|
|
3909
|
+
code: "HTTP_ERROR",
|
|
3910
|
+
message: resolveErrorMessage3(
|
|
3911
|
+
parsedBody.parsed,
|
|
3912
|
+
`Athena storage ${method} ${endpoint} failed with status ${response.status}`
|
|
3913
|
+
),
|
|
3914
|
+
status: response.status,
|
|
3915
|
+
endpoint,
|
|
3916
|
+
method,
|
|
3917
|
+
requestId,
|
|
3918
|
+
hint: resolveErrorHint2(parsedBody.parsed),
|
|
3919
|
+
cause: resolveErrorCause(parsedBody.parsed),
|
|
3920
|
+
raw: parsedBody.parsed
|
|
3921
|
+
},
|
|
3922
|
+
options,
|
|
3923
|
+
runtimeOptions
|
|
3924
|
+
);
|
|
3925
|
+
}
|
|
3926
|
+
if (envelope === "athena") {
|
|
3927
|
+
if (!isRecord5(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
3928
|
+
return rejectStorageError(
|
|
3929
|
+
{
|
|
3930
|
+
code: "INVALID_ATHENA_ENVELOPE",
|
|
3931
|
+
message: `Athena storage ${method} ${endpoint} returned an invalid Athena envelope`,
|
|
3932
|
+
status: response.status,
|
|
3933
|
+
endpoint,
|
|
3934
|
+
method,
|
|
3935
|
+
requestId,
|
|
3936
|
+
raw: parsedBody.parsed
|
|
3937
|
+
},
|
|
3938
|
+
options,
|
|
3939
|
+
runtimeOptions
|
|
3940
|
+
);
|
|
3941
|
+
}
|
|
3942
|
+
return parsedBody.parsed.data;
|
|
3943
|
+
}
|
|
3944
|
+
return parsedBody.parsed;
|
|
3945
|
+
}
|
|
3946
|
+
async function callStorageBinaryEndpoint(gateway, endpoint, method, options, runtimeOptions) {
|
|
3947
|
+
let url;
|
|
3948
|
+
let headers;
|
|
3949
|
+
try {
|
|
3950
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
3951
|
+
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
3952
|
+
headers = gateway.buildHeaders(options);
|
|
3953
|
+
} catch (error) {
|
|
3954
|
+
return rejectStorageError(
|
|
3955
|
+
{
|
|
3956
|
+
code: storageCodeFromUnknown(error),
|
|
3957
|
+
message: error instanceof Error ? error.message : `Athena storage ${method} ${endpoint} failed before sending the request`,
|
|
3958
|
+
status: isAthenaGatewayError(error) ? error.status : 0,
|
|
3959
|
+
endpoint,
|
|
3960
|
+
method,
|
|
3961
|
+
raw: error,
|
|
3962
|
+
requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
|
|
3963
|
+
hint: isAthenaGatewayError(error) ? error.hint : void 0,
|
|
3964
|
+
cause: error
|
|
3965
|
+
},
|
|
3966
|
+
options,
|
|
3967
|
+
runtimeOptions
|
|
3968
|
+
);
|
|
3969
|
+
}
|
|
3970
|
+
let response;
|
|
3971
|
+
try {
|
|
3972
|
+
response = await fetch(url, {
|
|
3973
|
+
method,
|
|
3974
|
+
headers,
|
|
3975
|
+
signal: options?.signal
|
|
3976
|
+
});
|
|
3977
|
+
} catch (error) {
|
|
3978
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3979
|
+
return rejectStorageError(
|
|
3980
|
+
{
|
|
3981
|
+
code: "NETWORK_ERROR",
|
|
3982
|
+
message: `Network error while calling Athena storage ${method} ${endpoint}: ${message}`,
|
|
3983
|
+
status: 0,
|
|
3984
|
+
endpoint,
|
|
3985
|
+
method,
|
|
3986
|
+
cause: error
|
|
3987
|
+
},
|
|
3988
|
+
options,
|
|
3989
|
+
runtimeOptions
|
|
3990
|
+
);
|
|
3991
|
+
}
|
|
3992
|
+
if (response.ok) {
|
|
3993
|
+
return response;
|
|
3994
|
+
}
|
|
3995
|
+
const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
|
|
3996
|
+
let rawErrorBody = null;
|
|
3997
|
+
try {
|
|
3998
|
+
const rawText = await response.text();
|
|
3999
|
+
const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
|
|
4000
|
+
rawErrorBody = parsedBody.parsed;
|
|
4001
|
+
} catch (error) {
|
|
4002
|
+
return rejectStorageError(
|
|
4003
|
+
{
|
|
4004
|
+
code: "NETWORK_ERROR",
|
|
4005
|
+
message: `Athena storage ${method} ${endpoint} error response body could not be read`,
|
|
4006
|
+
status: response.status,
|
|
4007
|
+
endpoint,
|
|
4008
|
+
method,
|
|
4009
|
+
requestId,
|
|
4010
|
+
cause: error
|
|
4011
|
+
},
|
|
4012
|
+
options,
|
|
4013
|
+
runtimeOptions
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
4016
|
+
return rejectStorageError(
|
|
4017
|
+
{
|
|
4018
|
+
code: "HTTP_ERROR",
|
|
4019
|
+
message: resolveErrorMessage3(
|
|
4020
|
+
rawErrorBody,
|
|
4021
|
+
`Athena storage ${method} ${endpoint} failed with status ${response.status}`
|
|
4022
|
+
),
|
|
4023
|
+
status: response.status,
|
|
4024
|
+
endpoint,
|
|
4025
|
+
method,
|
|
4026
|
+
requestId,
|
|
4027
|
+
hint: resolveErrorHint2(rawErrorBody),
|
|
4028
|
+
cause: resolveErrorCause(rawErrorBody),
|
|
4029
|
+
raw: rawErrorBody
|
|
4030
|
+
},
|
|
4031
|
+
options,
|
|
4032
|
+
runtimeOptions
|
|
4033
|
+
);
|
|
4034
|
+
}
|
|
4035
|
+
function createStorageModule(gateway, runtimeOptions) {
|
|
4036
|
+
return {
|
|
4037
|
+
listStorageCatalogs(options) {
|
|
4038
|
+
return callStorageEndpoint(gateway, storagePath("/storage/catalogs"), "GET", "raw", void 0, options, runtimeOptions);
|
|
4039
|
+
},
|
|
4040
|
+
createStorageCatalog(input, options) {
|
|
4041
|
+
return callStorageEndpoint(gateway, storagePath("/storage/catalogs"), "POST", "raw", input, options, runtimeOptions);
|
|
4042
|
+
},
|
|
4043
|
+
updateStorageCatalog(id, input, options) {
|
|
4044
|
+
return callStorageEndpoint(
|
|
4045
|
+
gateway,
|
|
4046
|
+
storagePath(withPathParam("/storage/catalogs/{id}", "id", id)),
|
|
4047
|
+
"PATCH",
|
|
4048
|
+
"raw",
|
|
4049
|
+
input,
|
|
4050
|
+
options,
|
|
4051
|
+
runtimeOptions
|
|
4052
|
+
);
|
|
4053
|
+
},
|
|
4054
|
+
deleteStorageCatalog(id, options) {
|
|
4055
|
+
return callStorageEndpoint(
|
|
4056
|
+
gateway,
|
|
4057
|
+
storagePath(withPathParam("/storage/catalogs/{id}", "id", id)),
|
|
4058
|
+
"DELETE",
|
|
4059
|
+
"raw",
|
|
4060
|
+
void 0,
|
|
4061
|
+
options,
|
|
4062
|
+
runtimeOptions
|
|
4063
|
+
);
|
|
4064
|
+
},
|
|
4065
|
+
listStorageCredentials(options) {
|
|
4066
|
+
return callStorageEndpoint(gateway, storagePath("/storage/credentials"), "GET", "raw", void 0, options, runtimeOptions);
|
|
4067
|
+
},
|
|
4068
|
+
createStorageUploadUrl(input, options) {
|
|
4069
|
+
return callStorageEndpoint(
|
|
4070
|
+
gateway,
|
|
4071
|
+
storagePath("/storage/files/upload-url"),
|
|
4072
|
+
"POST",
|
|
4073
|
+
"athena",
|
|
4074
|
+
input,
|
|
4075
|
+
options,
|
|
4076
|
+
runtimeOptions
|
|
4077
|
+
);
|
|
4078
|
+
},
|
|
4079
|
+
createStorageUploadUrls(input, options) {
|
|
4080
|
+
return callStorageEndpoint(
|
|
4081
|
+
gateway,
|
|
4082
|
+
storagePath("/storage/files/upload-urls"),
|
|
4083
|
+
"POST",
|
|
4084
|
+
"athena",
|
|
4085
|
+
input,
|
|
4086
|
+
options,
|
|
4087
|
+
runtimeOptions
|
|
4088
|
+
);
|
|
4089
|
+
},
|
|
4090
|
+
listStorageFiles(input, options) {
|
|
4091
|
+
return callStorageEndpoint(gateway, storagePath("/storage/files/list"), "POST", "athena", input, options, runtimeOptions);
|
|
4092
|
+
},
|
|
4093
|
+
getStorageFile(fileId, options) {
|
|
4094
|
+
return callStorageEndpoint(
|
|
4095
|
+
gateway,
|
|
4096
|
+
storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
|
|
4097
|
+
"GET",
|
|
4098
|
+
"athena",
|
|
4099
|
+
void 0,
|
|
4100
|
+
options,
|
|
4101
|
+
runtimeOptions
|
|
4102
|
+
);
|
|
4103
|
+
},
|
|
4104
|
+
getStorageFileUrl(fileId, query, options) {
|
|
4105
|
+
const path = appendQuery(
|
|
4106
|
+
withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
|
|
4107
|
+
query
|
|
4108
|
+
);
|
|
4109
|
+
return callStorageEndpoint(gateway, storagePath(path), "GET", "athena", void 0, options, runtimeOptions);
|
|
4110
|
+
},
|
|
4111
|
+
getStorageFileProxy(fileId, query, options) {
|
|
4112
|
+
const path = appendQuery(
|
|
4113
|
+
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
4114
|
+
query
|
|
4115
|
+
);
|
|
4116
|
+
return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, runtimeOptions);
|
|
4117
|
+
},
|
|
4118
|
+
updateStorageFile(fileId, input, options) {
|
|
4119
|
+
return callStorageEndpoint(
|
|
4120
|
+
gateway,
|
|
4121
|
+
storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
|
|
4122
|
+
"PATCH",
|
|
4123
|
+
"athena",
|
|
4124
|
+
input,
|
|
4125
|
+
options,
|
|
4126
|
+
runtimeOptions
|
|
4127
|
+
);
|
|
4128
|
+
},
|
|
4129
|
+
deleteStorageFile(fileId, options) {
|
|
4130
|
+
return callStorageEndpoint(
|
|
4131
|
+
gateway,
|
|
4132
|
+
storagePath(withPathParam("/storage/files/{file_id}", "file_id", fileId)),
|
|
4133
|
+
"DELETE",
|
|
4134
|
+
"athena",
|
|
4135
|
+
void 0,
|
|
4136
|
+
options,
|
|
4137
|
+
runtimeOptions
|
|
4138
|
+
);
|
|
4139
|
+
},
|
|
4140
|
+
setStorageFileVisibility(fileId, input, options) {
|
|
4141
|
+
return callStorageEndpoint(
|
|
4142
|
+
gateway,
|
|
4143
|
+
storagePath(withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId)),
|
|
4144
|
+
"PATCH",
|
|
4145
|
+
"athena",
|
|
4146
|
+
input,
|
|
4147
|
+
options,
|
|
4148
|
+
runtimeOptions
|
|
4149
|
+
);
|
|
4150
|
+
},
|
|
4151
|
+
deleteStorageFolder(input, options) {
|
|
4152
|
+
return callStorageEndpoint(gateway, storagePath("/storage/folders/delete"), "POST", "athena", input, options, runtimeOptions);
|
|
4153
|
+
},
|
|
4154
|
+
moveStorageFolder(input, options) {
|
|
4155
|
+
return callStorageEndpoint(gateway, storagePath("/storage/folders/move"), "POST", "athena", input, options, runtimeOptions);
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
|
|
3356
4160
|
// src/query-ast.ts
|
|
3357
4161
|
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
3358
4162
|
var FILTER_OPERATORS = /* @__PURE__ */ new Set([
|
|
@@ -3380,7 +4184,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
3380
4184
|
"ilike",
|
|
3381
4185
|
"is"
|
|
3382
4186
|
]);
|
|
3383
|
-
function
|
|
4187
|
+
function isRecord6(value) {
|
|
3384
4188
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3385
4189
|
}
|
|
3386
4190
|
function isUuidString(value) {
|
|
@@ -3393,7 +4197,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
3393
4197
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
3394
4198
|
}
|
|
3395
4199
|
function isRelationSelectNode(value) {
|
|
3396
|
-
return
|
|
4200
|
+
return isRecord6(value) && isRecord6(value.select);
|
|
3397
4201
|
}
|
|
3398
4202
|
function normalizeIdentifier(value, label) {
|
|
3399
4203
|
const normalized = value.trim();
|
|
@@ -3449,7 +4253,7 @@ function compileRelationToken(key, node) {
|
|
|
3449
4253
|
return `${prefix}${relationToken}(${nested})`;
|
|
3450
4254
|
}
|
|
3451
4255
|
function compileSelectShape(select) {
|
|
3452
|
-
if (!
|
|
4256
|
+
if (!isRecord6(select)) {
|
|
3453
4257
|
throw new Error("findMany select must be an object");
|
|
3454
4258
|
}
|
|
3455
4259
|
const tokens = [];
|
|
@@ -3473,7 +4277,7 @@ function compileSelectShape(select) {
|
|
|
3473
4277
|
return tokens.join(",");
|
|
3474
4278
|
}
|
|
3475
4279
|
function selectShapeUsesRelationSchema(select) {
|
|
3476
|
-
if (!
|
|
4280
|
+
if (!isRecord6(select)) {
|
|
3477
4281
|
return false;
|
|
3478
4282
|
}
|
|
3479
4283
|
for (const rawValue of Object.values(select)) {
|
|
@@ -3491,7 +4295,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
3491
4295
|
}
|
|
3492
4296
|
function compileColumnWhere(column, input) {
|
|
3493
4297
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
3494
|
-
if (!
|
|
4298
|
+
if (!isRecord6(input)) {
|
|
3495
4299
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
3496
4300
|
}
|
|
3497
4301
|
const conditions = [];
|
|
@@ -3519,7 +4323,7 @@ function compileColumnWhere(column, input) {
|
|
|
3519
4323
|
return conditions;
|
|
3520
4324
|
}
|
|
3521
4325
|
function compileBooleanExpressionTerms(clause, label) {
|
|
3522
|
-
if (!
|
|
4326
|
+
if (!isRecord6(clause)) {
|
|
3523
4327
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
3524
4328
|
}
|
|
3525
4329
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -3528,7 +4332,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
3528
4332
|
}
|
|
3529
4333
|
const [rawColumn, rawValue] = entries[0];
|
|
3530
4334
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
3531
|
-
if (!
|
|
4335
|
+
if (!isRecord6(rawValue)) {
|
|
3532
4336
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
3533
4337
|
}
|
|
3534
4338
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -3552,7 +4356,7 @@ function compileWhere(where) {
|
|
|
3552
4356
|
if (where === void 0) {
|
|
3553
4357
|
return void 0;
|
|
3554
4358
|
}
|
|
3555
|
-
if (!
|
|
4359
|
+
if (!isRecord6(where)) {
|
|
3556
4360
|
throw new Error("findMany where must be an object");
|
|
3557
4361
|
}
|
|
3558
4362
|
const conditions = [];
|
|
@@ -3602,7 +4406,7 @@ function compileOrderBy(orderBy) {
|
|
|
3602
4406
|
if (orderBy === void 0) {
|
|
3603
4407
|
return void 0;
|
|
3604
4408
|
}
|
|
3605
|
-
if (!
|
|
4409
|
+
if (!isRecord6(orderBy)) {
|
|
3606
4410
|
throw new Error("findMany orderBy must be an object");
|
|
3607
4411
|
}
|
|
3608
4412
|
if ("column" in orderBy) {
|
|
@@ -3698,7 +4502,7 @@ function buildStructuredWhere(conditions) {
|
|
|
3698
4502
|
if (!condition.column) {
|
|
3699
4503
|
return null;
|
|
3700
4504
|
}
|
|
3701
|
-
if (condition.
|
|
4505
|
+
if (condition.value_cast !== void 0) {
|
|
3702
4506
|
return null;
|
|
3703
4507
|
}
|
|
3704
4508
|
const operand = condition.value;
|
|
@@ -3777,6 +4581,104 @@ function toFindManyAstOrder(order) {
|
|
|
3777
4581
|
ascending: order.direction !== "descending"
|
|
3778
4582
|
};
|
|
3779
4583
|
}
|
|
4584
|
+
function isRecord7(value) {
|
|
4585
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4586
|
+
}
|
|
4587
|
+
function normalizeFindManyAstColumnPredicate(value) {
|
|
4588
|
+
if (!isRecord7(value)) {
|
|
4589
|
+
return {
|
|
4590
|
+
eq: value
|
|
4591
|
+
};
|
|
4592
|
+
}
|
|
4593
|
+
const normalized = {};
|
|
4594
|
+
for (const [key, operand] of Object.entries(value)) {
|
|
4595
|
+
if (operand !== void 0) {
|
|
4596
|
+
normalized[key] = operand;
|
|
4597
|
+
}
|
|
4598
|
+
}
|
|
4599
|
+
return normalized;
|
|
4600
|
+
}
|
|
4601
|
+
function normalizeFindManyAstBooleanOperand(clause) {
|
|
4602
|
+
const normalized = {};
|
|
4603
|
+
for (const [column, value] of Object.entries(clause)) {
|
|
4604
|
+
if (value === void 0) {
|
|
4605
|
+
continue;
|
|
4606
|
+
}
|
|
4607
|
+
normalized[column] = normalizeFindManyAstColumnPredicate(value);
|
|
4608
|
+
}
|
|
4609
|
+
return normalized;
|
|
4610
|
+
}
|
|
4611
|
+
function normalizeFindManyAstWhere(where) {
|
|
4612
|
+
if (!where || !isRecord7(where)) {
|
|
4613
|
+
return where;
|
|
4614
|
+
}
|
|
4615
|
+
const normalized = {};
|
|
4616
|
+
for (const [key, value] of Object.entries(where)) {
|
|
4617
|
+
if (value === void 0) {
|
|
4618
|
+
continue;
|
|
4619
|
+
}
|
|
4620
|
+
if (key === "or" && Array.isArray(value)) {
|
|
4621
|
+
normalized.or = value.map(
|
|
4622
|
+
(clause) => normalizeFindManyAstBooleanOperand(clause)
|
|
4623
|
+
);
|
|
4624
|
+
continue;
|
|
4625
|
+
}
|
|
4626
|
+
if (key === "not" && isRecord7(value)) {
|
|
4627
|
+
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
4628
|
+
value
|
|
4629
|
+
);
|
|
4630
|
+
continue;
|
|
4631
|
+
}
|
|
4632
|
+
normalized[key] = normalizeFindManyAstColumnPredicate(value);
|
|
4633
|
+
}
|
|
4634
|
+
return normalized;
|
|
4635
|
+
}
|
|
4636
|
+
function predicateRequiresUuidQueryFallback(column, value) {
|
|
4637
|
+
if (!isRecord7(value)) {
|
|
4638
|
+
return shouldUseUuidTextComparison(column, value);
|
|
4639
|
+
}
|
|
4640
|
+
const eqValue = value.eq;
|
|
4641
|
+
return eqValue !== void 0 && shouldUseUuidTextComparison(column, eqValue);
|
|
4642
|
+
}
|
|
4643
|
+
function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
4644
|
+
for (const [column, value] of Object.entries(clause)) {
|
|
4645
|
+
if (value === void 0) {
|
|
4646
|
+
continue;
|
|
4647
|
+
}
|
|
4648
|
+
if (predicateRequiresUuidQueryFallback(column, value)) {
|
|
4649
|
+
return true;
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
return false;
|
|
4653
|
+
}
|
|
4654
|
+
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
4655
|
+
if (!where || !isRecord7(where)) {
|
|
4656
|
+
return false;
|
|
4657
|
+
}
|
|
4658
|
+
for (const [key, value] of Object.entries(where)) {
|
|
4659
|
+
if (value === void 0) {
|
|
4660
|
+
continue;
|
|
4661
|
+
}
|
|
4662
|
+
if (key === "or" && Array.isArray(value)) {
|
|
4663
|
+
if (value.some(
|
|
4664
|
+
(clause) => booleanOperandRequiresUuidQueryFallback(clause)
|
|
4665
|
+
)) {
|
|
4666
|
+
return true;
|
|
4667
|
+
}
|
|
4668
|
+
continue;
|
|
4669
|
+
}
|
|
4670
|
+
if (key === "not" && isRecord7(value)) {
|
|
4671
|
+
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
4672
|
+
return true;
|
|
4673
|
+
}
|
|
4674
|
+
continue;
|
|
4675
|
+
}
|
|
4676
|
+
if (predicateRequiresUuidQueryFallback(key, value)) {
|
|
4677
|
+
return true;
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
return false;
|
|
4681
|
+
}
|
|
3780
4682
|
function resolvePagination(input) {
|
|
3781
4683
|
let limit = input.limit;
|
|
3782
4684
|
let offset = input.offset;
|
|
@@ -3795,25 +4697,6 @@ function hasTypedEqualityComparison(conditions) {
|
|
|
3795
4697
|
}
|
|
3796
4698
|
function createSelectTransportPlan(input) {
|
|
3797
4699
|
const conditions = input.state.conditions.length ? input.state.conditions.map((condition) => ({ ...condition })) : void 0;
|
|
3798
|
-
if (hasTypedEqualityComparison(conditions) && !input.options?.head && !input.options?.count && conditions) {
|
|
3799
|
-
const query = input.buildTypedSelectQuery({
|
|
3800
|
-
tableName: input.tableName,
|
|
3801
|
-
columns: input.columns,
|
|
3802
|
-
conditions,
|
|
3803
|
-
limit: input.state.limit,
|
|
3804
|
-
offset: input.state.offset,
|
|
3805
|
-
currentPage: input.state.currentPage,
|
|
3806
|
-
pageSize: input.state.pageSize,
|
|
3807
|
-
order: input.state.order
|
|
3808
|
-
});
|
|
3809
|
-
if (query) {
|
|
3810
|
-
return {
|
|
3811
|
-
kind: "query",
|
|
3812
|
-
query,
|
|
3813
|
-
payload: { query }
|
|
3814
|
-
};
|
|
3815
|
-
}
|
|
3816
|
-
}
|
|
3817
4700
|
const pagination = resolvePagination({
|
|
3818
4701
|
limit: input.state.limit,
|
|
3819
4702
|
offset: input.state.offset,
|
|
@@ -3849,6 +4732,25 @@ function createSelectTransportPlan(input) {
|
|
|
3849
4732
|
}
|
|
3850
4733
|
};
|
|
3851
4734
|
}
|
|
4735
|
+
if (hasTypedEqualityComparison(conditions) && !input.options?.head && !input.options?.count && conditions) {
|
|
4736
|
+
const query = input.buildTypedSelectQuery({
|
|
4737
|
+
tableName: input.tableName,
|
|
4738
|
+
columns: input.columns,
|
|
4739
|
+
conditions,
|
|
4740
|
+
limit: input.state.limit,
|
|
4741
|
+
offset: input.state.offset,
|
|
4742
|
+
currentPage: input.state.currentPage,
|
|
4743
|
+
pageSize: input.state.pageSize,
|
|
4744
|
+
order: input.state.order
|
|
4745
|
+
});
|
|
4746
|
+
if (query) {
|
|
4747
|
+
return {
|
|
4748
|
+
kind: "query",
|
|
4749
|
+
query,
|
|
4750
|
+
payload: { query }
|
|
4751
|
+
};
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
3852
4754
|
return {
|
|
3853
4755
|
kind: "fetch",
|
|
3854
4756
|
payload: {
|
|
@@ -3905,6 +4807,13 @@ function formatResult(response) {
|
|
|
3905
4807
|
}
|
|
3906
4808
|
return result;
|
|
3907
4809
|
}
|
|
4810
|
+
var EXPERIMENTAL_READ_RETRY_CONFIG = {
|
|
4811
|
+
retries: 2,
|
|
4812
|
+
baseDelayMs: 100,
|
|
4813
|
+
maxDelayMs: 1e3,
|
|
4814
|
+
backoff: "exponential",
|
|
4815
|
+
jitter: true
|
|
4816
|
+
};
|
|
3908
4817
|
function attachNormalizedError(result, normalizedError) {
|
|
3909
4818
|
Object.defineProperty(result, ATHENA_NORMALIZED_ERROR_KEY, {
|
|
3910
4819
|
value: normalizedError,
|
|
@@ -3931,7 +4840,36 @@ function createResultFormatter(experimental) {
|
|
|
3931
4840
|
return result;
|
|
3932
4841
|
};
|
|
3933
4842
|
}
|
|
3934
|
-
function
|
|
4843
|
+
async function executeExperimentalRead(experimental, runner) {
|
|
4844
|
+
if (!experimental?.retryReads) {
|
|
4845
|
+
return runner();
|
|
4846
|
+
}
|
|
4847
|
+
let lastRetryableResult;
|
|
4848
|
+
let lastRetrySignal = null;
|
|
4849
|
+
try {
|
|
4850
|
+
return await withRetry(
|
|
4851
|
+
{
|
|
4852
|
+
...EXPERIMENTAL_READ_RETRY_CONFIG,
|
|
4853
|
+
shouldRetry: (error) => error === lastRetrySignal || normalizeAthenaError(error).retryable
|
|
4854
|
+
},
|
|
4855
|
+
async () => {
|
|
4856
|
+
const result = await runner();
|
|
4857
|
+
if (result.error?.retryable) {
|
|
4858
|
+
lastRetryableResult = result;
|
|
4859
|
+
lastRetrySignal = result.error;
|
|
4860
|
+
throw lastRetrySignal;
|
|
4861
|
+
}
|
|
4862
|
+
return result;
|
|
4863
|
+
}
|
|
4864
|
+
);
|
|
4865
|
+
} catch (error) {
|
|
4866
|
+
if (lastRetryableResult && error === lastRetrySignal) {
|
|
4867
|
+
return lastRetryableResult;
|
|
4868
|
+
}
|
|
4869
|
+
throw error;
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
function isRecord8(value) {
|
|
3935
4873
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3936
4874
|
}
|
|
3937
4875
|
function firstNonEmptyString2(...values) {
|
|
@@ -3943,8 +4881,8 @@ function firstNonEmptyString2(...values) {
|
|
|
3943
4881
|
return void 0;
|
|
3944
4882
|
}
|
|
3945
4883
|
function resolveStructuredErrorPayload2(raw) {
|
|
3946
|
-
if (!
|
|
3947
|
-
return
|
|
4884
|
+
if (!isRecord8(raw)) return null;
|
|
4885
|
+
return isRecord8(raw.error) ? raw.error : raw;
|
|
3948
4886
|
}
|
|
3949
4887
|
function resolveStructuredErrorDetails(payload, message) {
|
|
3950
4888
|
if (!payload || !("details" in payload)) {
|
|
@@ -3960,7 +4898,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
3960
4898
|
return details;
|
|
3961
4899
|
}
|
|
3962
4900
|
function createResultError(response, result, normalized) {
|
|
3963
|
-
const rawRecord =
|
|
4901
|
+
const rawRecord = isRecord8(response.raw) ? response.raw : null;
|
|
3964
4902
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
3965
4903
|
const message = firstNonEmptyString2(
|
|
3966
4904
|
response.error,
|
|
@@ -4155,7 +5093,14 @@ function toSingleResult(response) {
|
|
|
4155
5093
|
function mergeOptions(...options) {
|
|
4156
5094
|
return options.reduce((acc, next) => {
|
|
4157
5095
|
if (!next) return acc;
|
|
4158
|
-
|
|
5096
|
+
const merged = { ...acc ?? {}, ...next };
|
|
5097
|
+
if (acc?.headers || next.headers) {
|
|
5098
|
+
merged.headers = {
|
|
5099
|
+
...acc?.headers ?? {},
|
|
5100
|
+
...next.headers ?? {}
|
|
5101
|
+
};
|
|
5102
|
+
}
|
|
5103
|
+
return merged;
|
|
4159
5104
|
}, void 0);
|
|
4160
5105
|
}
|
|
4161
5106
|
function asAthenaJsonObject(value) {
|
|
@@ -4947,42 +5892,48 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
4947
5892
|
buildTypedSelectQuery
|
|
4948
5893
|
});
|
|
4949
5894
|
if (plan.kind === "query") {
|
|
4950
|
-
return
|
|
5895
|
+
return executeExperimentalRead(
|
|
5896
|
+
experimental,
|
|
5897
|
+
() => executeWithQueryTrace(
|
|
5898
|
+
tracer,
|
|
5899
|
+
{
|
|
5900
|
+
operation: "select",
|
|
5901
|
+
endpoint: "/gateway/query",
|
|
5902
|
+
table: resolvedTableName,
|
|
5903
|
+
sql: plan.query,
|
|
5904
|
+
payload: plan.payload,
|
|
5905
|
+
options
|
|
5906
|
+
},
|
|
5907
|
+
async () => {
|
|
5908
|
+
const queryResponse = await client.queryGateway(plan.payload, options);
|
|
5909
|
+
return formatGatewayResult(queryResponse, { table: resolvedTableName, operation: "select" });
|
|
5910
|
+
},
|
|
5911
|
+
callsite
|
|
5912
|
+
)
|
|
5913
|
+
);
|
|
5914
|
+
}
|
|
5915
|
+
const sql = buildDebugSelectQuery({
|
|
5916
|
+
tableName: resolvedTableName,
|
|
5917
|
+
...plan.debug
|
|
5918
|
+
});
|
|
5919
|
+
return executeExperimentalRead(
|
|
5920
|
+
experimental,
|
|
5921
|
+
() => executeWithQueryTrace(
|
|
4951
5922
|
tracer,
|
|
4952
5923
|
{
|
|
4953
5924
|
operation: "select",
|
|
4954
|
-
endpoint: "/gateway/
|
|
5925
|
+
endpoint: "/gateway/fetch",
|
|
4955
5926
|
table: resolvedTableName,
|
|
4956
|
-
sql
|
|
5927
|
+
sql,
|
|
4957
5928
|
payload: plan.payload,
|
|
4958
5929
|
options
|
|
4959
5930
|
},
|
|
4960
5931
|
async () => {
|
|
4961
|
-
const
|
|
4962
|
-
return formatGatewayResult(
|
|
5932
|
+
const response = await client.fetchGateway(plan.payload, options);
|
|
5933
|
+
return formatGatewayResult(response, { table: resolvedTableName, operation: "select" });
|
|
4963
5934
|
},
|
|
4964
5935
|
callsite
|
|
4965
|
-
)
|
|
4966
|
-
}
|
|
4967
|
-
const sql = buildDebugSelectQuery({
|
|
4968
|
-
tableName: resolvedTableName,
|
|
4969
|
-
...plan.debug
|
|
4970
|
-
});
|
|
4971
|
-
return executeWithQueryTrace(
|
|
4972
|
-
tracer,
|
|
4973
|
-
{
|
|
4974
|
-
operation: "select",
|
|
4975
|
-
endpoint: "/gateway/fetch",
|
|
4976
|
-
table: resolvedTableName,
|
|
4977
|
-
sql,
|
|
4978
|
-
payload: plan.payload,
|
|
4979
|
-
options
|
|
4980
|
-
},
|
|
4981
|
-
async () => {
|
|
4982
|
-
const response = await client.fetchGateway(plan.payload, options);
|
|
4983
|
-
return formatGatewayResult(response, { table: resolvedTableName, operation: "select" });
|
|
4984
|
-
},
|
|
4985
|
-
callsite
|
|
5936
|
+
)
|
|
4986
5937
|
);
|
|
4987
5938
|
};
|
|
4988
5939
|
const createSelectChain = (columns, options, initialCallsite) => {
|
|
@@ -5052,14 +6003,14 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
5052
6003
|
if (options.limit !== void 0) {
|
|
5053
6004
|
executionState.limit = options.limit;
|
|
5054
6005
|
}
|
|
5055
|
-
if (experimental?.findManyAst && canUseFindManyAstTransport(baseState) && !selectShapeUsesRelationSchema(options.select)) {
|
|
6006
|
+
if (experimental?.findManyAst && canUseFindManyAstTransport(baseState) && !selectShapeUsesRelationSchema(options.select) && !findManyAstWhereRequiresLegacyTransport(options.where)) {
|
|
5056
6007
|
const resolvedTableName = resolveTableNameForCall(tableName, void 0);
|
|
5057
6008
|
const payload = {
|
|
5058
6009
|
table_name: resolvedTableName,
|
|
5059
6010
|
select: options.select
|
|
5060
6011
|
};
|
|
5061
6012
|
if (options.where !== void 0) {
|
|
5062
|
-
payload.where = options.where;
|
|
6013
|
+
payload.where = normalizeFindManyAstWhere(options.where);
|
|
5063
6014
|
}
|
|
5064
6015
|
const astOrder = toFindManyAstOrder(executionState.order);
|
|
5065
6016
|
if (astOrder !== void 0) {
|
|
@@ -5075,22 +6026,25 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
5075
6026
|
limit: executionState.limit,
|
|
5076
6027
|
order: executionState.order
|
|
5077
6028
|
});
|
|
5078
|
-
return
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
async () => {
|
|
5088
|
-
const response = await client.fetchGateway(
|
|
6029
|
+
return executeExperimentalRead(
|
|
6030
|
+
experimental,
|
|
6031
|
+
() => executeWithQueryTrace(
|
|
6032
|
+
tracer,
|
|
6033
|
+
{
|
|
6034
|
+
operation: "select",
|
|
6035
|
+
endpoint: "/gateway/fetch",
|
|
6036
|
+
table: resolvedTableName,
|
|
6037
|
+
sql,
|
|
5089
6038
|
payload
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
6039
|
+
},
|
|
6040
|
+
async () => {
|
|
6041
|
+
const response = await client.fetchGateway(
|
|
6042
|
+
payload
|
|
6043
|
+
);
|
|
6044
|
+
return formatGatewayResult(response, { table: resolvedTableName, operation: "select" });
|
|
6045
|
+
},
|
|
6046
|
+
callsite
|
|
6047
|
+
)
|
|
5094
6048
|
);
|
|
5095
6049
|
}
|
|
5096
6050
|
return runSelect(
|
|
@@ -5338,7 +6292,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
5338
6292
|
});
|
|
5339
6293
|
return builder;
|
|
5340
6294
|
}
|
|
5341
|
-
function createQueryBuilder(client, formatGatewayResult, tracer) {
|
|
6295
|
+
function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
5342
6296
|
return async function query(query, options) {
|
|
5343
6297
|
const normalizedQuery = query.trim();
|
|
5344
6298
|
if (!normalizedQuery) {
|
|
@@ -5346,30 +6300,39 @@ function createQueryBuilder(client, formatGatewayResult, tracer) {
|
|
|
5346
6300
|
}
|
|
5347
6301
|
const payload = { query: normalizedQuery };
|
|
5348
6302
|
const callsite = captureTraceCallsite(tracer);
|
|
5349
|
-
return
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
6303
|
+
return executeExperimentalRead(
|
|
6304
|
+
experimental,
|
|
6305
|
+
() => executeWithQueryTrace(
|
|
6306
|
+
tracer,
|
|
6307
|
+
{
|
|
6308
|
+
operation: "query",
|
|
6309
|
+
endpoint: "/gateway/query",
|
|
6310
|
+
sql: normalizedQuery,
|
|
6311
|
+
payload,
|
|
6312
|
+
options
|
|
6313
|
+
},
|
|
6314
|
+
async () => {
|
|
6315
|
+
const response = await client.queryGateway(payload, options);
|
|
6316
|
+
return formatGatewayResult(response, { operation: "query" });
|
|
6317
|
+
},
|
|
6318
|
+
callsite
|
|
6319
|
+
)
|
|
5363
6320
|
);
|
|
5364
6321
|
};
|
|
5365
6322
|
}
|
|
5366
6323
|
function createClientFromConfig(config) {
|
|
6324
|
+
const gatewayHeaders = {
|
|
6325
|
+
...config.headers ?? {}
|
|
6326
|
+
};
|
|
6327
|
+
if (config.auth?.bearerToken && gatewayHeaders["X-Athena-Auth-Bearer-Token"] === void 0 && gatewayHeaders["x-athena-auth-bearer-token"] === void 0) {
|
|
6328
|
+
gatewayHeaders["X-Athena-Auth-Bearer-Token"] = config.auth.bearerToken;
|
|
6329
|
+
}
|
|
5367
6330
|
const gateway = createAthenaGatewayClient({
|
|
5368
6331
|
baseUrl: config.baseUrl,
|
|
5369
6332
|
apiKey: config.apiKey,
|
|
5370
6333
|
client: config.client,
|
|
5371
6334
|
backend: config.backend,
|
|
5372
|
-
headers:
|
|
6335
|
+
headers: gatewayHeaders
|
|
5373
6336
|
});
|
|
5374
6337
|
const formatGatewayResult = createResultFormatter();
|
|
5375
6338
|
const queryTracer = createQueryTracer(config.experimental);
|
|
@@ -5396,9 +6359,9 @@ function createClientFromConfig(config) {
|
|
|
5396
6359
|
captureTraceCallsite(queryTracer)
|
|
5397
6360
|
);
|
|
5398
6361
|
};
|
|
5399
|
-
const query = createQueryBuilder(gateway, formatGatewayResult, queryTracer);
|
|
6362
|
+
const query = createQueryBuilder(gateway, formatGatewayResult, config.experimental, queryTracer);
|
|
5400
6363
|
const db = createDbModule({ from, rpc, query });
|
|
5401
|
-
|
|
6364
|
+
const sdkClient = {
|
|
5402
6365
|
from,
|
|
5403
6366
|
db,
|
|
5404
6367
|
rpc,
|
|
@@ -5406,6 +6369,14 @@ function createClientFromConfig(config) {
|
|
|
5406
6369
|
verifyConnection: gateway.verifyConnection,
|
|
5407
6370
|
auth: auth.auth
|
|
5408
6371
|
};
|
|
6372
|
+
if (config.experimental?.athenaStorageBackend) {
|
|
6373
|
+
const storageClient = {
|
|
6374
|
+
...sdkClient,
|
|
6375
|
+
storage: createStorageModule(gateway, config.experimental.storage)
|
|
6376
|
+
};
|
|
6377
|
+
return storageClient;
|
|
6378
|
+
}
|
|
6379
|
+
return sdkClient;
|
|
5409
6380
|
}
|
|
5410
6381
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
5411
6382
|
function toBackendConfig(b) {
|