@xylex-group/athena 2.12.1 → 2.14.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/LICENSE +21 -21
- package/README.md +1190 -1184
- package/bin/athena-js.js +104 -76
- package/dist/admin.cjs +45 -0
- package/dist/admin.cjs.map +1 -0
- package/dist/admin.d.cts +64 -0
- package/dist/admin.d.ts +64 -0
- package/dist/admin.js +41 -0
- package/dist/admin.js.map +1 -0
- package/dist/athena-auth-url-oLux_57a.d.cts +377 -0
- package/dist/athena-auth-url-oLux_57a.d.ts +377 -0
- package/dist/browser.cjs +580 -96
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +12 -10
- package/dist/browser.d.ts +12 -10
- package/dist/browser.js +580 -96
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +690 -91
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +14 -5
- package/dist/cli/index.d.ts +14 -5
- package/dist/cli/index.js +690 -92
- package/dist/cli/index.js.map +1 -1
- package/dist/{client-CMtx5P4D.d.cts → client-uthENhaf.d.ts} +346 -1488
- package/dist/{client-Dre8H24u.d.ts → client-wU2J9yqb.d.cts} +346 -1488
- package/dist/cookies.cjs +18 -0
- package/dist/cookies.cjs.map +1 -1
- package/dist/cookies.d.cts +2 -1
- package/dist/cookies.d.ts +2 -1
- package/dist/cookies.js +17 -1
- package/dist/cookies.js.map +1 -1
- package/dist/{index-CVcQCGyG.d.ts → index-CFL9xbFR.d.cts} +2 -0
- package/dist/{index-CVcQCGyG.d.cts → index-UKJpunc6.d.ts} +2 -0
- package/dist/index.cjs +648 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +648 -97
- package/dist/index.js.map +1 -1
- package/dist/{model-form-DfTi8-D1.d.cts → model-form-BE1_Bmdd.d.cts} +2 -2
- package/dist/{model-form-CU0mWrF9.d.ts → model-form-DcH3R7WD.d.ts} +2 -2
- package/dist/{module-DBGmbIuh.d.ts → module-Ca3_OQqR.d.ts} +12 -9
- package/dist/{module-GoijrBXV.d.cts → module-DFGZXCtt.d.cts} +12 -9
- package/dist/next/client.cjs +992 -89
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +7 -4
- package/dist/next/client.d.ts +7 -4
- package/dist/next/client.js +970 -90
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +832 -89
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +81 -5
- package/dist/next/server.d.ts +81 -5
- package/dist/next/server.js +820 -90
- package/dist/next/server.js.map +1 -1
- package/dist/organization.cjs +72 -0
- package/dist/organization.cjs.map +1 -0
- package/dist/organization.d.cts +43 -0
- package/dist/organization.d.ts +43 -0
- package/dist/organization.js +70 -0
- package/dist/organization.js.map +1 -0
- package/dist/payload-BbSCmILD.d.ts +219 -0
- package/dist/payload-zXIwKTQf.d.cts +219 -0
- package/dist/{pipeline-c7Gdm0qv.d.cts → pipeline-CwQoD5G9.d.cts} +1 -1
- package/dist/{pipeline-DrjU2vNA.d.ts → pipeline-DqwehoQV.d.ts} +1 -1
- package/dist/react.cjs +2 -13
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +26 -7
- package/dist/react.d.ts +26 -7
- package/dist/react.js +2 -13
- package/dist/react.js.map +1 -1
- package/dist/session-cookie-detection-BqOp9mO6.d.cts +46 -0
- package/dist/session-cookie-detection-BqOp9mO6.d.ts +46 -0
- package/dist/social-providers.cjs +4198 -0
- package/dist/social-providers.cjs.map +1 -0
- package/dist/social-providers.d.cts +4948 -0
- package/dist/social-providers.d.ts +4948 -0
- package/dist/social-providers.js +4126 -0
- package/dist/social-providers.js.map +1 -0
- package/dist/{types-kPaHUqUa.d.ts → types-6H575ITc.d.cts} +50 -2
- package/dist/{types-DRRb0Fd0.d.ts → types-C1swabT5.d.ts} +3 -3
- package/dist/{types-Bez4HSbI.d.cts → types-CD6K05JQ.d.ts} +50 -2
- package/dist/{types-BRUHGXo2.d.ts → types-YQUR7wu0.d.cts} +3 -3
- package/dist/{types-BRUHGXo2.d.cts → types-YQUR7wu0.d.ts} +3 -3
- package/dist/{types-BLizCLd1.d.cts → types-dHnjluBC.d.cts} +3 -3
- package/dist/types-eAKAh71s.d.cts +1476 -0
- package/dist/types-eAKAh71s.d.ts +1476 -0
- package/dist/utils.cjs +438 -15
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +76 -11
- package/dist/utils.d.ts +76 -11
- package/dist/utils.js +390 -16
- package/dist/utils.js.map +1 -1
- package/package.json +29 -1
- package/dist/shared-DZSGAmXs.d.cts +0 -35
- package/dist/shared-MMnVBBfy.d.ts +0 -35
package/dist/cli/index.cjs
CHANGED
|
@@ -2004,7 +2004,7 @@ var getSessionCookie = (request2, config) => {
|
|
|
2004
2004
|
|
|
2005
2005
|
// src/utils/athena-request-headers.ts
|
|
2006
2006
|
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
2007
|
-
var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
|
|
2007
|
+
var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
|
|
2008
2008
|
var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
|
|
2009
2009
|
var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
|
|
2010
2010
|
var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
|
|
@@ -2106,17 +2106,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
|
|
|
2106
2106
|
});
|
|
2107
2107
|
}
|
|
2108
2108
|
function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
|
|
2109
|
-
if (apiKey) {
|
|
2110
|
-
if (!hasHeaderIgnoreCase(headers, "apikey")) {
|
|
2111
|
-
headers.apikey = apiKey;
|
|
2112
|
-
}
|
|
2113
|
-
if (!Object.hasOwn(headers, "x-api-key")) {
|
|
2114
|
-
headers["x-api-key"] = apiKey;
|
|
2115
|
-
}
|
|
2116
|
-
if (!Object.hasOwn(headers, "X-Api-Key")) {
|
|
2117
|
-
headers["X-Api-Key"] = apiKey;
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
2109
|
const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
|
|
2121
2110
|
if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
|
|
2122
2111
|
headers["X-Athena-Key"] = resolvedAthenaKey;
|
|
@@ -2242,7 +2231,7 @@ function buildAthenaRequestHeaders(input) {
|
|
|
2242
2231
|
|
|
2243
2232
|
// package.json
|
|
2244
2233
|
var package_default = {
|
|
2245
|
-
version: "2.
|
|
2234
|
+
version: "2.14.0"
|
|
2246
2235
|
};
|
|
2247
2236
|
|
|
2248
2237
|
// src/sdk-version.ts
|
|
@@ -4335,39 +4324,224 @@ function createAuthClient(config = {}) {
|
|
|
4335
4324
|
};
|
|
4336
4325
|
}
|
|
4337
4326
|
|
|
4338
|
-
// src/
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4327
|
+
// src/storage/direct-upload.ts
|
|
4328
|
+
var SERVICE = "s3";
|
|
4329
|
+
var TERMINATOR = "aws4_request";
|
|
4330
|
+
async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
|
|
4331
|
+
if (config.bucket && bucket && config.bucket !== bucket) {
|
|
4332
|
+
throw new Error(
|
|
4333
|
+
`athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
|
|
4334
|
+
);
|
|
4335
|
+
}
|
|
4336
|
+
const target = createDirectUploadTarget(config, bucket, storageKey);
|
|
4337
|
+
const bytes = await bodyToArrayBuffer(body);
|
|
4338
|
+
const payloadHash = await sha256Hex(bytes);
|
|
4339
|
+
const headers = new Headers(uploadHeaders);
|
|
4340
|
+
if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
|
|
4341
|
+
headers.set("Content-Type", body.type);
|
|
4342
|
+
}
|
|
4343
|
+
const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
|
|
4344
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
4345
|
+
return putWithXhr(target.toString(), signed, body, signal, onProgress);
|
|
4346
|
+
}
|
|
4347
|
+
onProgress({ loaded: 0 });
|
|
4348
|
+
const response = await fetch(target, {
|
|
4349
|
+
method: "PUT",
|
|
4350
|
+
headers: signed.requestHeaders,
|
|
4351
|
+
body,
|
|
4352
|
+
signal
|
|
4353
|
+
});
|
|
4354
|
+
if (!response.ok) {
|
|
4355
|
+
throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
|
|
4356
|
+
}
|
|
4357
|
+
onProgress({ loaded: bytes.byteLength });
|
|
4358
|
+
return response;
|
|
4359
|
+
}
|
|
4360
|
+
function createDirectUploadTarget(config, bucket, storageKey) {
|
|
4361
|
+
const resolvedBucket = config.bucket ?? bucket;
|
|
4362
|
+
if (!resolvedBucket?.trim()) {
|
|
4363
|
+
throw new Error(
|
|
4364
|
+
"athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
|
|
4365
|
+
);
|
|
4366
|
+
}
|
|
4367
|
+
if (!storageKey.trim()) {
|
|
4368
|
+
throw new Error("athena.storage.file.upload direct mode requires a storage key");
|
|
4369
|
+
}
|
|
4370
|
+
let endpoint;
|
|
4371
|
+
try {
|
|
4372
|
+
endpoint = new URL(config.endpoint);
|
|
4373
|
+
} catch (error) {
|
|
4374
|
+
throw new Error(
|
|
4375
|
+
`athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
|
|
4376
|
+
);
|
|
4377
|
+
}
|
|
4378
|
+
if (endpoint.search || endpoint.hash) {
|
|
4379
|
+
throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
|
|
4380
|
+
}
|
|
4381
|
+
const endpointPath = endpoint.pathname.replace(/\/+$/, "");
|
|
4382
|
+
const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
|
|
4383
|
+
if (config.forcePathStyle === false) {
|
|
4384
|
+
endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
|
|
4385
|
+
}
|
|
4386
|
+
endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
|
|
4387
|
+
return endpoint;
|
|
4388
|
+
}
|
|
4389
|
+
async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
|
|
4390
|
+
const accessKeyId = config.accessKeyId.trim();
|
|
4391
|
+
const secretAccessKey = config.secretAccessKey.trim();
|
|
4392
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
4393
|
+
throw new Error(
|
|
4394
|
+
"athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
|
|
4395
|
+
);
|
|
4396
|
+
}
|
|
4397
|
+
const now = /* @__PURE__ */ new Date();
|
|
4398
|
+
const amzDate = formatAmzDate(now);
|
|
4399
|
+
const shortDate = amzDate.slice(0, 8);
|
|
4400
|
+
const region = config.region?.trim() || "auto";
|
|
4401
|
+
const headers = {};
|
|
4402
|
+
inputHeaders.forEach((value, key) => {
|
|
4403
|
+
if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
|
|
4404
|
+
headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
|
|
4405
|
+
}
|
|
4406
|
+
});
|
|
4407
|
+
headers["x-amz-content-sha256"] = payloadHash;
|
|
4408
|
+
headers["x-amz-date"] = amzDate;
|
|
4409
|
+
if (config.sessionToken?.trim()) {
|
|
4410
|
+
headers["x-amz-security-token"] = config.sessionToken.trim();
|
|
4411
|
+
}
|
|
4412
|
+
const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
|
|
4413
|
+
`).join("");
|
|
4414
|
+
const signedHeaders = Object.keys(headers).sort().join(";");
|
|
4415
|
+
const canonicalRequest = [
|
|
4416
|
+
"PUT",
|
|
4417
|
+
target.pathname,
|
|
4418
|
+
"",
|
|
4419
|
+
`host:${target.host}
|
|
4420
|
+
${canonicalHeaders}`,
|
|
4421
|
+
`host;${signedHeaders}`,
|
|
4422
|
+
payloadHash
|
|
4423
|
+
].join("\n");
|
|
4424
|
+
const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
|
|
4425
|
+
const stringToSign = [
|
|
4426
|
+
"AWS4-HMAC-SHA256",
|
|
4427
|
+
amzDate,
|
|
4428
|
+
credentialScope,
|
|
4429
|
+
await sha256Hex(canonicalRequest)
|
|
4430
|
+
].join("\n");
|
|
4431
|
+
const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
|
|
4432
|
+
const regionKey = await hmac(dateKey, region);
|
|
4433
|
+
const serviceKey = await hmac(regionKey, SERVICE);
|
|
4434
|
+
const signingKey = await hmac(serviceKey, TERMINATOR);
|
|
4435
|
+
const signature = await hmacHex(signingKey, stringToSign);
|
|
4436
|
+
headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
|
|
4437
|
+
return { requestHeaders: headers };
|
|
4438
|
+
}
|
|
4439
|
+
async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
4440
|
+
const Xhr = XMLHttpRequest;
|
|
4441
|
+
if (Xhr === void 0) {
|
|
4442
|
+
return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
|
|
4443
|
+
}
|
|
4444
|
+
return new Promise((resolve3, reject) => {
|
|
4445
|
+
const xhr = new Xhr();
|
|
4446
|
+
const abort = () => xhr.abort();
|
|
4447
|
+
xhr.open("PUT", url);
|
|
4448
|
+
Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
|
|
4449
|
+
xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
|
|
4450
|
+
xhr.onload = () => {
|
|
4451
|
+
signal?.removeEventListener("abort", abort);
|
|
4452
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
4453
|
+
reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
|
|
4454
|
+
return;
|
|
4345
4455
|
}
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4456
|
+
onProgress({ loaded: bodySize(body) });
|
|
4457
|
+
resolve3(new Response(xhr.response, {
|
|
4458
|
+
status: xhr.status,
|
|
4459
|
+
statusText: xhr.statusText,
|
|
4460
|
+
headers: parseXhrHeaders(xhr.getAllResponseHeaders())
|
|
4461
|
+
}));
|
|
4462
|
+
};
|
|
4463
|
+
xhr.onerror = () => {
|
|
4464
|
+
signal?.removeEventListener("abort", abort);
|
|
4465
|
+
reject(new Error("athena.storage.file.upload failed with a network error"));
|
|
4466
|
+
};
|
|
4467
|
+
xhr.onabort = () => {
|
|
4468
|
+
signal?.removeEventListener("abort", abort);
|
|
4469
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
4470
|
+
};
|
|
4471
|
+
if (signal) {
|
|
4472
|
+
if (signal.aborted) {
|
|
4473
|
+
abort();
|
|
4474
|
+
return;
|
|
4475
|
+
}
|
|
4476
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
4365
4477
|
}
|
|
4366
|
-
|
|
4367
|
-
|
|
4478
|
+
xhr.send(body);
|
|
4479
|
+
});
|
|
4480
|
+
}
|
|
4481
|
+
function isBlobBody(body) {
|
|
4482
|
+
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
4483
|
+
}
|
|
4484
|
+
async function bodyToArrayBuffer(body) {
|
|
4485
|
+
if (isBlobBody(body)) return body.arrayBuffer();
|
|
4486
|
+
if (body instanceof ArrayBuffer) return body;
|
|
4487
|
+
if (ArrayBuffer.isView(body)) {
|
|
4488
|
+
return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
|
|
4489
|
+
}
|
|
4490
|
+
throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
|
|
4491
|
+
}
|
|
4492
|
+
function bodySize(body) {
|
|
4493
|
+
if (isBlobBody(body)) return body.size;
|
|
4494
|
+
if (body instanceof ArrayBuffer) return body.byteLength;
|
|
4495
|
+
if (ArrayBuffer.isView(body)) return body.byteLength;
|
|
4496
|
+
return 0;
|
|
4497
|
+
}
|
|
4498
|
+
function awsEncode(value) {
|
|
4499
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
4500
|
+
}
|
|
4501
|
+
function formatAmzDate(date) {
|
|
4502
|
+
return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
4503
|
+
}
|
|
4504
|
+
async function sha256Hex(value) {
|
|
4505
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
|
|
4506
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
4507
|
+
return toHex(new Uint8Array(digest));
|
|
4508
|
+
}
|
|
4509
|
+
async function hmac(key, value) {
|
|
4510
|
+
const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
4511
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
4512
|
+
"raw",
|
|
4513
|
+
keyBytes,
|
|
4514
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
4515
|
+
false,
|
|
4516
|
+
["sign"]
|
|
4517
|
+
);
|
|
4518
|
+
return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
|
|
4519
|
+
}
|
|
4520
|
+
async function hmacHex(key, value) {
|
|
4521
|
+
return toHex(new Uint8Array(await hmac(key, value)));
|
|
4522
|
+
}
|
|
4523
|
+
function toHex(bytes) {
|
|
4524
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
4525
|
+
}
|
|
4526
|
+
function parseXhrHeaders(rawHeaders) {
|
|
4527
|
+
const headers = new Headers();
|
|
4528
|
+
rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
|
|
4529
|
+
const separator = line.indexOf(":");
|
|
4530
|
+
if (separator > 0) {
|
|
4531
|
+
headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
4532
|
+
}
|
|
4533
|
+
});
|
|
4534
|
+
return headers;
|
|
4368
4535
|
}
|
|
4369
4536
|
|
|
4370
4537
|
// src/storage/file.ts
|
|
4538
|
+
function mergeUploadHeaders(serverHeaders, inputHeaders) {
|
|
4539
|
+
const headers = { ...serverHeaders };
|
|
4540
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
4541
|
+
headers[key] = value;
|
|
4542
|
+
});
|
|
4543
|
+
return headers;
|
|
4544
|
+
}
|
|
4371
4545
|
function createStorageFileModule(base, config = {}) {
|
|
4372
4546
|
const upload = async (input, options) => {
|
|
4373
4547
|
const sources = normalizeUploadSources(input);
|
|
@@ -4403,16 +4577,25 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4403
4577
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
4404
4578
|
const request2 = uploadRequests[index];
|
|
4405
4579
|
const uploadUrl = uploadUrls[index];
|
|
4406
|
-
const
|
|
4580
|
+
const aggregateProgress = (progress) => {
|
|
4581
|
+
aggregateLoaded[index] = progress.loaded;
|
|
4582
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
4583
|
+
};
|
|
4584
|
+
const response = config.directUpload ? await putDirectStorageUploadBody(
|
|
4585
|
+
config.directUpload,
|
|
4586
|
+
uploadUrl.upload.bucket,
|
|
4587
|
+
uploadUrl.upload.storage_key,
|
|
4588
|
+
request2.source.source,
|
|
4589
|
+
mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
|
|
4590
|
+
options?.signal,
|
|
4591
|
+
aggregateProgress
|
|
4592
|
+
) : await putUploadBody(
|
|
4407
4593
|
uploadUrl.upload.url,
|
|
4408
4594
|
uploadUrl.upload.headers ?? {},
|
|
4409
4595
|
request2.source,
|
|
4410
4596
|
input,
|
|
4411
4597
|
options,
|
|
4412
|
-
|
|
4413
|
-
aggregateLoaded[index] = progress.loaded;
|
|
4414
|
-
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
4415
|
-
}
|
|
4598
|
+
aggregateProgress
|
|
4416
4599
|
);
|
|
4417
4600
|
uploaded.push({
|
|
4418
4601
|
file: uploadUrl.file,
|
|
@@ -4563,7 +4746,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
4563
4746
|
resolve3(new Response(xhr.response, {
|
|
4564
4747
|
status: xhr.status,
|
|
4565
4748
|
statusText: xhr.statusText,
|
|
4566
|
-
headers:
|
|
4749
|
+
headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
|
|
4567
4750
|
}));
|
|
4568
4751
|
};
|
|
4569
4752
|
xhr.onerror = () => {
|
|
@@ -4701,7 +4884,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
|
|
|
4701
4884
|
function sum(values) {
|
|
4702
4885
|
return values.reduce((total, value) => total + value, 0);
|
|
4703
4886
|
}
|
|
4704
|
-
function
|
|
4887
|
+
function parseXhrHeaders2(raw) {
|
|
4705
4888
|
const headers = new Headers();
|
|
4706
4889
|
for (const line of raw.trim().split(/[\r\n]+/)) {
|
|
4707
4890
|
const index = line.indexOf(":");
|
|
@@ -4718,6 +4901,230 @@ function isRecord5(value) {
|
|
|
4718
4901
|
return Boolean(value) && typeof value === "object";
|
|
4719
4902
|
}
|
|
4720
4903
|
|
|
4904
|
+
// src/storage/backup.ts
|
|
4905
|
+
function backupError(message, status, endpoint, method, cause, raw) {
|
|
4906
|
+
const error = new Error(message);
|
|
4907
|
+
error.name = "AthenaStorageError";
|
|
4908
|
+
error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
|
|
4909
|
+
error.status = status;
|
|
4910
|
+
error.endpoint = endpoint;
|
|
4911
|
+
error.method = method;
|
|
4912
|
+
error.cause = cause;
|
|
4913
|
+
error.raw = raw;
|
|
4914
|
+
throw error;
|
|
4915
|
+
}
|
|
4916
|
+
function isRecord6(value) {
|
|
4917
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4918
|
+
}
|
|
4919
|
+
function asPath(path) {
|
|
4920
|
+
return path;
|
|
4921
|
+
}
|
|
4922
|
+
function appendQuery(path, query) {
|
|
4923
|
+
if (!query) return path;
|
|
4924
|
+
const params = new URLSearchParams();
|
|
4925
|
+
for (const [key, value] of Object.entries(query)) {
|
|
4926
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
4927
|
+
params.set(key, String(value));
|
|
4928
|
+
}
|
|
4929
|
+
const text = params.toString();
|
|
4930
|
+
return text ? `${path}?${text}` : path;
|
|
4931
|
+
}
|
|
4932
|
+
function unwrapAthenaData(payload) {
|
|
4933
|
+
if (isRecord6(payload) && "data" in payload) {
|
|
4934
|
+
return payload.data;
|
|
4935
|
+
}
|
|
4936
|
+
return payload;
|
|
4937
|
+
}
|
|
4938
|
+
function requireKey(key) {
|
|
4939
|
+
const trimmed = key.trim();
|
|
4940
|
+
if (!trimmed || trimmed === "undefined" || trimmed === "null") {
|
|
4941
|
+
backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
|
|
4942
|
+
}
|
|
4943
|
+
return trimmed;
|
|
4944
|
+
}
|
|
4945
|
+
function resolveMessage(payload, fallback) {
|
|
4946
|
+
if (isRecord6(payload)) {
|
|
4947
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
4948
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
4949
|
+
}
|
|
4950
|
+
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
4951
|
+
return fallback;
|
|
4952
|
+
}
|
|
4953
|
+
async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
|
|
4954
|
+
const endpoint = asPath(path);
|
|
4955
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4956
|
+
const url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
4957
|
+
const headers = gateway.buildHeaders(options);
|
|
4958
|
+
const init = {
|
|
4959
|
+
method,
|
|
4960
|
+
headers,
|
|
4961
|
+
signal: options?.signal
|
|
4962
|
+
};
|
|
4963
|
+
if (payload !== void 0 && method !== "GET") {
|
|
4964
|
+
init.body = JSON.stringify(payload);
|
|
4965
|
+
}
|
|
4966
|
+
let response;
|
|
4967
|
+
try {
|
|
4968
|
+
response = await fetch(url, init);
|
|
4969
|
+
} catch (error) {
|
|
4970
|
+
backupError(
|
|
4971
|
+
error instanceof Error ? error.message : "Backup network error",
|
|
4972
|
+
0,
|
|
4973
|
+
path,
|
|
4974
|
+
method,
|
|
4975
|
+
error
|
|
4976
|
+
);
|
|
4977
|
+
}
|
|
4978
|
+
const rawText = await response.text();
|
|
4979
|
+
let parsed = null;
|
|
4980
|
+
if (rawText) {
|
|
4981
|
+
try {
|
|
4982
|
+
parsed = JSON.parse(rawText);
|
|
4983
|
+
} catch {
|
|
4984
|
+
parsed = rawText;
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
if (!response.ok) {
|
|
4988
|
+
backupError(
|
|
4989
|
+
resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
|
|
4990
|
+
response.status,
|
|
4991
|
+
path,
|
|
4992
|
+
method,
|
|
4993
|
+
void 0,
|
|
4994
|
+
parsed
|
|
4995
|
+
);
|
|
4996
|
+
}
|
|
4997
|
+
return unwrapAthenaData(parsed);
|
|
4998
|
+
}
|
|
4999
|
+
function createStorageBackupModule(gateway, runtimeOptions) {
|
|
5000
|
+
const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
|
|
5001
|
+
return {
|
|
5002
|
+
async list(query, options) {
|
|
5003
|
+
const path = appendQuery("/admin/backups", {
|
|
5004
|
+
limit: query?.limit ?? 10,
|
|
5005
|
+
client_name: query?.client_name,
|
|
5006
|
+
cursor: query?.cursor ?? void 0
|
|
5007
|
+
});
|
|
5008
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
5009
|
+
const backups = (data?.backups ?? []).map((row) => ({
|
|
5010
|
+
...row,
|
|
5011
|
+
key: row.key ?? row.s3_key
|
|
5012
|
+
}));
|
|
5013
|
+
return {
|
|
5014
|
+
backups,
|
|
5015
|
+
next_cursor: data?.next_cursor ?? null
|
|
5016
|
+
};
|
|
5017
|
+
},
|
|
5018
|
+
async create(input, options) {
|
|
5019
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
|
|
5020
|
+
return {
|
|
5021
|
+
job_id: Number(data?.job_id ?? 0),
|
|
5022
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
5023
|
+
status: String(data?.status ?? "pending")
|
|
5024
|
+
};
|
|
5025
|
+
},
|
|
5026
|
+
async restore(key, input, options) {
|
|
5027
|
+
const backupKey = requireKey(key);
|
|
5028
|
+
const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
|
|
5029
|
+
const data = await callBackupEndpoint(gateway, path, "POST", input, options);
|
|
5030
|
+
return {
|
|
5031
|
+
job_id: Number(data?.job_id ?? 0),
|
|
5032
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
5033
|
+
status: String(data?.status ?? "pending"),
|
|
5034
|
+
key: String(data?.key ?? backupKey)
|
|
5035
|
+
};
|
|
5036
|
+
},
|
|
5037
|
+
async delete(key, options) {
|
|
5038
|
+
const backupKey = requireKey(key);
|
|
5039
|
+
await callBackupEndpoint(
|
|
5040
|
+
gateway,
|
|
5041
|
+
`/admin/backups/${encodeURIComponent(backupKey)}`,
|
|
5042
|
+
"DELETE",
|
|
5043
|
+
void 0,
|
|
5044
|
+
options);
|
|
5045
|
+
},
|
|
5046
|
+
downloadUrl(key, options) {
|
|
5047
|
+
const backupKey = requireKey(key);
|
|
5048
|
+
const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
|
|
5049
|
+
return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
|
|
5050
|
+
},
|
|
5051
|
+
jobs: {
|
|
5052
|
+
async list(query, options) {
|
|
5053
|
+
const path = appendQuery("/admin/backups/jobs", query ?? {});
|
|
5054
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
5055
|
+
if (Array.isArray(data)) return data;
|
|
5056
|
+
if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
|
|
5057
|
+
return [];
|
|
5058
|
+
},
|
|
5059
|
+
async get(jobId, options) {
|
|
5060
|
+
return callBackupEndpoint(
|
|
5061
|
+
gateway,
|
|
5062
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
5063
|
+
"GET",
|
|
5064
|
+
void 0,
|
|
5065
|
+
options);
|
|
5066
|
+
},
|
|
5067
|
+
async cancel(jobId, options) {
|
|
5068
|
+
return callBackupEndpoint(
|
|
5069
|
+
gateway,
|
|
5070
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
|
|
5071
|
+
"POST",
|
|
5072
|
+
{},
|
|
5073
|
+
options);
|
|
5074
|
+
},
|
|
5075
|
+
async delete(jobId, options) {
|
|
5076
|
+
await callBackupEndpoint(
|
|
5077
|
+
gateway,
|
|
5078
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
5079
|
+
"DELETE",
|
|
5080
|
+
void 0,
|
|
5081
|
+
options);
|
|
5082
|
+
},
|
|
5083
|
+
async openObjectUrl(jobId, options) {
|
|
5084
|
+
const data = await callBackupEndpoint(
|
|
5085
|
+
gateway,
|
|
5086
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
|
|
5087
|
+
"GET",
|
|
5088
|
+
void 0,
|
|
5089
|
+
options);
|
|
5090
|
+
return String(data?.url ?? "");
|
|
5091
|
+
}
|
|
5092
|
+
},
|
|
5093
|
+
schedules: {
|
|
5094
|
+
async list(options) {
|
|
5095
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
|
|
5096
|
+
if (Array.isArray(data)) return data;
|
|
5097
|
+
if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
|
|
5098
|
+
return [];
|
|
5099
|
+
},
|
|
5100
|
+
async create(input, options) {
|
|
5101
|
+
return callBackupEndpoint(
|
|
5102
|
+
gateway,
|
|
5103
|
+
"/admin/backups/schedules",
|
|
5104
|
+
"POST",
|
|
5105
|
+
input,
|
|
5106
|
+
options);
|
|
5107
|
+
},
|
|
5108
|
+
async update(id, input, options) {
|
|
5109
|
+
return callBackupEndpoint(
|
|
5110
|
+
gateway,
|
|
5111
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
5112
|
+
"PATCH",
|
|
5113
|
+
input,
|
|
5114
|
+
options);
|
|
5115
|
+
},
|
|
5116
|
+
async delete(id, options) {
|
|
5117
|
+
await callBackupEndpoint(
|
|
5118
|
+
gateway,
|
|
5119
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
5120
|
+
"DELETE",
|
|
5121
|
+
void 0,
|
|
5122
|
+
options);
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
|
|
4721
5128
|
// src/storage/module.ts
|
|
4722
5129
|
var storageSdkManifest = {
|
|
4723
5130
|
methods: [
|
|
@@ -4760,6 +5167,53 @@ var storageSdkManifest = {
|
|
|
4760
5167
|
responseEnvelope: "raw",
|
|
4761
5168
|
responseType: "{ data: S3CredentialListItem[] }"
|
|
4762
5169
|
},
|
|
5170
|
+
{
|
|
5171
|
+
name: "backup.list",
|
|
5172
|
+
method: "GET",
|
|
5173
|
+
path: "/admin/backups",
|
|
5174
|
+
responseEnvelope: "athena",
|
|
5175
|
+
responseType: "StorageBackupListPage",
|
|
5176
|
+
note: "Admin backup archives on server S3/R2 profile"
|
|
5177
|
+
},
|
|
5178
|
+
{
|
|
5179
|
+
name: "backup.create",
|
|
5180
|
+
method: "POST",
|
|
5181
|
+
path: "/admin/backups",
|
|
5182
|
+
requestType: "StorageBackupCreateRequest",
|
|
5183
|
+
responseEnvelope: "athena",
|
|
5184
|
+
responseType: "StorageBackupQueuedJob"
|
|
5185
|
+
},
|
|
5186
|
+
{
|
|
5187
|
+
name: "backup.restore",
|
|
5188
|
+
method: "POST",
|
|
5189
|
+
path: "/admin/backups/{key}/restore",
|
|
5190
|
+
pathParams: ["key"],
|
|
5191
|
+
requestType: "StorageBackupRestoreRequest",
|
|
5192
|
+
responseEnvelope: "athena",
|
|
5193
|
+
responseType: "StorageBackupQueuedJob"
|
|
5194
|
+
},
|
|
5195
|
+
{
|
|
5196
|
+
name: "backup.delete",
|
|
5197
|
+
method: "DELETE",
|
|
5198
|
+
path: "/admin/backups/{key}",
|
|
5199
|
+
pathParams: ["key"],
|
|
5200
|
+
responseEnvelope: "athena",
|
|
5201
|
+
responseType: "void"
|
|
5202
|
+
},
|
|
5203
|
+
{
|
|
5204
|
+
name: "backup.jobs.list",
|
|
5205
|
+
method: "GET",
|
|
5206
|
+
path: "/admin/backups/jobs",
|
|
5207
|
+
responseEnvelope: "athena",
|
|
5208
|
+
responseType: "StorageBackupJob[]"
|
|
5209
|
+
},
|
|
5210
|
+
{
|
|
5211
|
+
name: "backup.schedules.list",
|
|
5212
|
+
method: "GET",
|
|
5213
|
+
path: "/admin/backups/schedules",
|
|
5214
|
+
responseEnvelope: "athena",
|
|
5215
|
+
responseType: "StorageBackupSchedule[]"
|
|
5216
|
+
},
|
|
4763
5217
|
{
|
|
4764
5218
|
name: "createStorageUploadUrl",
|
|
4765
5219
|
method: "POST",
|
|
@@ -5407,7 +5861,7 @@ var AthenaStorageError = class extends Error {
|
|
|
5407
5861
|
};
|
|
5408
5862
|
}
|
|
5409
5863
|
};
|
|
5410
|
-
function
|
|
5864
|
+
function isRecord7(value) {
|
|
5411
5865
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5412
5866
|
}
|
|
5413
5867
|
function causeToString(cause) {
|
|
@@ -5505,7 +5959,7 @@ function parseResponseBody3(rawText, contentType) {
|
|
|
5505
5959
|
return { parsed: rawText, parseFailed: true };
|
|
5506
5960
|
}
|
|
5507
5961
|
}
|
|
5508
|
-
function
|
|
5962
|
+
function appendQuery2(path, query) {
|
|
5509
5963
|
if (!query) return path;
|
|
5510
5964
|
const params = new URLSearchParams();
|
|
5511
5965
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -5531,7 +5985,7 @@ function withPathParam(path, name, value) {
|
|
|
5531
5985
|
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
5532
5986
|
}
|
|
5533
5987
|
function resolveErrorMessage3(payload, fallback) {
|
|
5534
|
-
if (
|
|
5988
|
+
if (isRecord7(payload)) {
|
|
5535
5989
|
const message = payload.message ?? payload.error ?? payload.details;
|
|
5536
5990
|
if (typeof message === "string" && message.trim()) {
|
|
5537
5991
|
return message.trim();
|
|
@@ -5543,12 +5997,12 @@ function resolveErrorMessage3(payload, fallback) {
|
|
|
5543
5997
|
return fallback;
|
|
5544
5998
|
}
|
|
5545
5999
|
function resolveErrorHint2(payload) {
|
|
5546
|
-
if (!
|
|
6000
|
+
if (!isRecord7(payload)) return void 0;
|
|
5547
6001
|
const hint = payload.hint ?? payload.suggestion;
|
|
5548
6002
|
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
5549
6003
|
}
|
|
5550
6004
|
function resolveErrorCause(payload) {
|
|
5551
|
-
if (!
|
|
6005
|
+
if (!isRecord7(payload)) return void 0;
|
|
5552
6006
|
const cause = payload.cause ?? payload.reason;
|
|
5553
6007
|
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
5554
6008
|
}
|
|
@@ -5667,7 +6121,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
|
|
|
5667
6121
|
);
|
|
5668
6122
|
}
|
|
5669
6123
|
if (envelope === "athena") {
|
|
5670
|
-
if (!
|
|
6124
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
5671
6125
|
return rejectStorageError(
|
|
5672
6126
|
{
|
|
5673
6127
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -5775,7 +6229,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
5775
6229
|
runtimeOptions
|
|
5776
6230
|
);
|
|
5777
6231
|
}
|
|
5778
|
-
function
|
|
6232
|
+
function isBlobBody2(body) {
|
|
5779
6233
|
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
5780
6234
|
}
|
|
5781
6235
|
function isReadableStreamBody(body) {
|
|
@@ -5784,7 +6238,7 @@ function isReadableStreamBody(body) {
|
|
|
5784
6238
|
async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
5785
6239
|
const headers = new Headers(uploadHeaders);
|
|
5786
6240
|
Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
|
|
5787
|
-
if (!headers.has("Content-Type") &&
|
|
6241
|
+
if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
|
|
5788
6242
|
headers.set("Content-Type", body.type);
|
|
5789
6243
|
}
|
|
5790
6244
|
const init = {
|
|
@@ -5879,7 +6333,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
5879
6333
|
}
|
|
5880
6334
|
delete headers["Content-Type"];
|
|
5881
6335
|
delete headers["content-type"];
|
|
5882
|
-
if (
|
|
6336
|
+
if (isBlobBody2(body) && body.type) {
|
|
5883
6337
|
headers["Content-Type"] = body.type;
|
|
5884
6338
|
}
|
|
5885
6339
|
const requestInit = {
|
|
@@ -5964,7 +6418,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
5964
6418
|
runtimeOptions
|
|
5965
6419
|
);
|
|
5966
6420
|
}
|
|
5967
|
-
if (!
|
|
6421
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
5968
6422
|
return rejectStorageError(
|
|
5969
6423
|
{
|
|
5970
6424
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -6036,14 +6490,14 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6036
6490
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
|
|
6037
6491
|
},
|
|
6038
6492
|
getStorageFileUrl(fileId, query, options) {
|
|
6039
|
-
const path =
|
|
6493
|
+
const path = appendQuery2(
|
|
6040
6494
|
withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
|
|
6041
6495
|
query
|
|
6042
6496
|
);
|
|
6043
6497
|
return callAthena2(path, "GET", void 0, options);
|
|
6044
6498
|
},
|
|
6045
6499
|
getStorageFileProxy(fileId, query, options) {
|
|
6046
|
-
const path =
|
|
6500
|
+
const path = appendQuery2(
|
|
6047
6501
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
6048
6502
|
query
|
|
6049
6503
|
);
|
|
@@ -6067,7 +6521,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6067
6521
|
};
|
|
6068
6522
|
const fileFacade = createStorageFileModule(base, runtimeOptions);
|
|
6069
6523
|
const fileUpload = ((input, options) => {
|
|
6070
|
-
if (
|
|
6524
|
+
if (isRecord7(input) && "files" in input) {
|
|
6071
6525
|
return fileFacade.upload(input, options);
|
|
6072
6526
|
}
|
|
6073
6527
|
return base.createStorageUploadUrl(
|
|
@@ -6129,7 +6583,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6129
6583
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
6130
6584
|
},
|
|
6131
6585
|
proxyUrl(fileId, query, options) {
|
|
6132
|
-
const path =
|
|
6586
|
+
const path = appendQuery2(
|
|
6133
6587
|
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
6134
6588
|
query
|
|
6135
6589
|
);
|
|
@@ -6167,7 +6621,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6167
6621
|
},
|
|
6168
6622
|
retention: {
|
|
6169
6623
|
get(fileId, query, options) {
|
|
6170
|
-
const path =
|
|
6624
|
+
const path = appendQuery2(
|
|
6171
6625
|
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
6172
6626
|
query
|
|
6173
6627
|
);
|
|
@@ -6369,6 +6823,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6369
6823
|
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
6370
6824
|
}
|
|
6371
6825
|
};
|
|
6826
|
+
const backup = createStorageBackupModule(gateway);
|
|
6372
6827
|
return {
|
|
6373
6828
|
...base,
|
|
6374
6829
|
credentials,
|
|
@@ -6380,6 +6835,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6380
6835
|
bucket,
|
|
6381
6836
|
multipart,
|
|
6382
6837
|
audit,
|
|
6838
|
+
backup,
|
|
6383
6839
|
delete: file.delete
|
|
6384
6840
|
};
|
|
6385
6841
|
}
|
|
@@ -6429,7 +6885,7 @@ function normalizeWsUrl(value, label) {
|
|
|
6429
6885
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
6430
6886
|
return parsed.toString().replace(/\/$/, "");
|
|
6431
6887
|
}
|
|
6432
|
-
function
|
|
6888
|
+
function isRecord8(value) {
|
|
6433
6889
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6434
6890
|
}
|
|
6435
6891
|
function parseResponseBody4(rawText, contentType) {
|
|
@@ -6451,7 +6907,7 @@ function resolveRequestId3(headers) {
|
|
|
6451
6907
|
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
6452
6908
|
}
|
|
6453
6909
|
function resolveErrorMessage4(payload, fallback) {
|
|
6454
|
-
if (
|
|
6910
|
+
if (isRecord8(payload)) {
|
|
6455
6911
|
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
6456
6912
|
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
6457
6913
|
return candidate.trim();
|
|
@@ -6860,7 +7316,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
6860
7316
|
"ilike",
|
|
6861
7317
|
"is"
|
|
6862
7318
|
]);
|
|
6863
|
-
function
|
|
7319
|
+
function isRecord9(value) {
|
|
6864
7320
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6865
7321
|
}
|
|
6866
7322
|
function isUuidString(value) {
|
|
@@ -6873,7 +7329,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
6873
7329
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
6874
7330
|
}
|
|
6875
7331
|
function isRelationSelectNode(value) {
|
|
6876
|
-
return
|
|
7332
|
+
return isRecord9(value) && isRecord9(value.select);
|
|
6877
7333
|
}
|
|
6878
7334
|
function normalizeIdentifier(value, label) {
|
|
6879
7335
|
const normalized = value.trim();
|
|
@@ -6929,7 +7385,7 @@ function compileRelationToken(key, node) {
|
|
|
6929
7385
|
return `${prefix}${relationToken}(${nested})`;
|
|
6930
7386
|
}
|
|
6931
7387
|
function compileSelectShape(select) {
|
|
6932
|
-
if (!
|
|
7388
|
+
if (!isRecord9(select)) {
|
|
6933
7389
|
throw new Error("findMany select must be an object");
|
|
6934
7390
|
}
|
|
6935
7391
|
const tokens = [];
|
|
@@ -6953,7 +7409,7 @@ function compileSelectShape(select) {
|
|
|
6953
7409
|
return tokens.join(",");
|
|
6954
7410
|
}
|
|
6955
7411
|
function selectShapeUsesRelationSchema(select) {
|
|
6956
|
-
if (!
|
|
7412
|
+
if (!isRecord9(select)) {
|
|
6957
7413
|
return false;
|
|
6958
7414
|
}
|
|
6959
7415
|
for (const rawValue of Object.values(select)) {
|
|
@@ -6971,7 +7427,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
6971
7427
|
}
|
|
6972
7428
|
function compileColumnWhere(column, input) {
|
|
6973
7429
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
6974
|
-
if (!
|
|
7430
|
+
if (!isRecord9(input)) {
|
|
6975
7431
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
6976
7432
|
}
|
|
6977
7433
|
const conditions = [];
|
|
@@ -6999,7 +7455,7 @@ function compileColumnWhere(column, input) {
|
|
|
6999
7455
|
return conditions;
|
|
7000
7456
|
}
|
|
7001
7457
|
function compileBooleanExpressionTerms(clause, label) {
|
|
7002
|
-
if (!
|
|
7458
|
+
if (!isRecord9(clause)) {
|
|
7003
7459
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
7004
7460
|
}
|
|
7005
7461
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -7008,7 +7464,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
7008
7464
|
}
|
|
7009
7465
|
const [rawColumn, rawValue] = entries[0];
|
|
7010
7466
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
7011
|
-
if (!
|
|
7467
|
+
if (!isRecord9(rawValue)) {
|
|
7012
7468
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
7013
7469
|
}
|
|
7014
7470
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -7032,7 +7488,7 @@ function compileWhere(where) {
|
|
|
7032
7488
|
if (where === void 0) {
|
|
7033
7489
|
return void 0;
|
|
7034
7490
|
}
|
|
7035
|
-
if (!
|
|
7491
|
+
if (!isRecord9(where)) {
|
|
7036
7492
|
throw new Error("findMany where must be an object");
|
|
7037
7493
|
}
|
|
7038
7494
|
const conditions = [];
|
|
@@ -7082,7 +7538,7 @@ function compileOrderBy(orderBy) {
|
|
|
7082
7538
|
if (orderBy === void 0) {
|
|
7083
7539
|
return void 0;
|
|
7084
7540
|
}
|
|
7085
|
-
if (!
|
|
7541
|
+
if (!isRecord9(orderBy)) {
|
|
7086
7542
|
throw new Error("findMany orderBy must be an object");
|
|
7087
7543
|
}
|
|
7088
7544
|
if ("column" in orderBy) {
|
|
@@ -7257,11 +7713,11 @@ function toFindManyAstOrder(order) {
|
|
|
7257
7713
|
ascending: order.direction !== "descending"
|
|
7258
7714
|
};
|
|
7259
7715
|
}
|
|
7260
|
-
function
|
|
7716
|
+
function isRecord10(value) {
|
|
7261
7717
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7262
7718
|
}
|
|
7263
7719
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
7264
|
-
if (!
|
|
7720
|
+
if (!isRecord10(value)) {
|
|
7265
7721
|
return {
|
|
7266
7722
|
eq: value
|
|
7267
7723
|
};
|
|
@@ -7285,7 +7741,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
7285
7741
|
return normalized;
|
|
7286
7742
|
}
|
|
7287
7743
|
function normalizeFindManyAstWhere(where) {
|
|
7288
|
-
if (!where || !
|
|
7744
|
+
if (!where || !isRecord10(where)) {
|
|
7289
7745
|
return where;
|
|
7290
7746
|
}
|
|
7291
7747
|
const normalized = {};
|
|
@@ -7299,7 +7755,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
7299
7755
|
);
|
|
7300
7756
|
continue;
|
|
7301
7757
|
}
|
|
7302
|
-
if (key === "not" &&
|
|
7758
|
+
if (key === "not" && isRecord10(value)) {
|
|
7303
7759
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
7304
7760
|
value
|
|
7305
7761
|
);
|
|
@@ -7310,7 +7766,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
7310
7766
|
return normalized;
|
|
7311
7767
|
}
|
|
7312
7768
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
7313
|
-
if (!
|
|
7769
|
+
if (!isRecord10(value)) {
|
|
7314
7770
|
return shouldUseUuidTextComparison(column, value);
|
|
7315
7771
|
}
|
|
7316
7772
|
const eqValue = value.eq;
|
|
@@ -7328,7 +7784,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
7328
7784
|
return false;
|
|
7329
7785
|
}
|
|
7330
7786
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
7331
|
-
if (!where || !
|
|
7787
|
+
if (!where || !isRecord10(where)) {
|
|
7332
7788
|
return false;
|
|
7333
7789
|
}
|
|
7334
7790
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -7343,7 +7799,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
7343
7799
|
}
|
|
7344
7800
|
continue;
|
|
7345
7801
|
}
|
|
7346
|
-
if (key === "not" &&
|
|
7802
|
+
if (key === "not" && isRecord10(value)) {
|
|
7347
7803
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
7348
7804
|
return true;
|
|
7349
7805
|
}
|
|
@@ -7963,7 +8419,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
7963
8419
|
throw error;
|
|
7964
8420
|
}
|
|
7965
8421
|
}
|
|
7966
|
-
function
|
|
8422
|
+
function isRecord11(value) {
|
|
7967
8423
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7968
8424
|
}
|
|
7969
8425
|
function firstNonEmptyString2(...values) {
|
|
@@ -7975,8 +8431,8 @@ function firstNonEmptyString2(...values) {
|
|
|
7975
8431
|
return void 0;
|
|
7976
8432
|
}
|
|
7977
8433
|
function resolveStructuredErrorPayload2(raw) {
|
|
7978
|
-
if (!
|
|
7979
|
-
return
|
|
8434
|
+
if (!isRecord11(raw)) return null;
|
|
8435
|
+
return isRecord11(raw.error) ? raw.error : raw;
|
|
7980
8436
|
}
|
|
7981
8437
|
function resolveStructuredErrorDetails(payload, message) {
|
|
7982
8438
|
if (!payload || !("details" in payload)) {
|
|
@@ -7992,7 +8448,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
7992
8448
|
return details;
|
|
7993
8449
|
}
|
|
7994
8450
|
function createResultError(response, result, normalized) {
|
|
7995
|
-
const rawRecord =
|
|
8451
|
+
const rawRecord = isRecord11(response.raw) ? response.raw : null;
|
|
7996
8452
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
7997
8453
|
const message = firstNonEmptyString2(
|
|
7998
8454
|
response.error,
|
|
@@ -9714,7 +10170,30 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9714
10170
|
config.experimental,
|
|
9715
10171
|
queryTracer
|
|
9716
10172
|
);
|
|
9717
|
-
const
|
|
10173
|
+
const untypedDbFrom = from;
|
|
10174
|
+
const db = {
|
|
10175
|
+
from,
|
|
10176
|
+
select(table, first, second) {
|
|
10177
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
10178
|
+
return untypedDbFrom(table).select(void 0, first);
|
|
10179
|
+
}
|
|
10180
|
+
return untypedDbFrom(table).select(first, second);
|
|
10181
|
+
},
|
|
10182
|
+
insert(table, values, options) {
|
|
10183
|
+
return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
|
|
10184
|
+
},
|
|
10185
|
+
upsert(table, values, options) {
|
|
10186
|
+
return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
|
|
10187
|
+
},
|
|
10188
|
+
update(table, values, options) {
|
|
10189
|
+
return untypedDbFrom(table).update(values, options);
|
|
10190
|
+
},
|
|
10191
|
+
delete(table, options) {
|
|
10192
|
+
return untypedDbFrom(table).delete(options);
|
|
10193
|
+
},
|
|
10194
|
+
rpc,
|
|
10195
|
+
query
|
|
10196
|
+
};
|
|
9718
10197
|
const chat = createChatModule({
|
|
9719
10198
|
baseUrl: config.chatUrl,
|
|
9720
10199
|
apiKey: config.apiKey,
|
|
@@ -9852,6 +10331,7 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9852
10331
|
withOptions: storageWithOptions,
|
|
9853
10332
|
storage: createStorageModule(gateway, {
|
|
9854
10333
|
...config.experimental.storage,
|
|
10334
|
+
...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
|
|
9855
10335
|
...config.storageUrl ? {
|
|
9856
10336
|
baseUrl: config.storageUrl,
|
|
9857
10337
|
stripBasePath: true
|
|
@@ -9862,7 +10342,8 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9862
10342
|
}
|
|
9863
10343
|
return sdkClient;
|
|
9864
10344
|
}
|
|
9865
|
-
function createClient(
|
|
10345
|
+
function createClient(...args) {
|
|
10346
|
+
const [configOrUrl, apiKey, options] = args;
|
|
9866
10347
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
9867
10348
|
return createClientFromInput({
|
|
9868
10349
|
url: configOrUrl,
|
|
@@ -10469,6 +10950,10 @@ async function runSchemaGenerator(options = {}) {
|
|
|
10469
10950
|
}
|
|
10470
10951
|
|
|
10471
10952
|
// src/cli/index.ts
|
|
10953
|
+
function isDebugEnabled() {
|
|
10954
|
+
const value = globalThis.process?.env?.ATHENA_JS_DEBUG;
|
|
10955
|
+
return value === "1" || value === "true";
|
|
10956
|
+
}
|
|
10472
10957
|
function rootUsage() {
|
|
10473
10958
|
return [
|
|
10474
10959
|
"athena-js CLI",
|
|
@@ -10632,7 +11117,61 @@ function extractMissingDatabaseName(message) {
|
|
|
10632
11117
|
function isErrorWithCode(error) {
|
|
10633
11118
|
return typeof error === "object" && error !== null && "code" in error;
|
|
10634
11119
|
}
|
|
11120
|
+
function isNetworkConnectionError(error) {
|
|
11121
|
+
if (!isErrorWithCode(error)) {
|
|
11122
|
+
return false;
|
|
11123
|
+
}
|
|
11124
|
+
const code = typeof error.code === "string" ? error.code : "";
|
|
11125
|
+
if (code === "ECONNRESET" || code === "ECONNREFUSED" || code === "ETIMEDOUT" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "EPIPE" || code === "EHOSTUNREACH" || code === "ENETUNREACH") {
|
|
11126
|
+
return true;
|
|
11127
|
+
}
|
|
11128
|
+
const message = normalizeErrorMessage(error).toLowerCase();
|
|
11129
|
+
return message.includes("econnreset") || message.includes("econnrefused") || message.includes("etimedout") || message.includes("connection terminated") || message.includes("connection refused") || message.includes("timeout expired");
|
|
11130
|
+
}
|
|
11131
|
+
function collectErrorDiagnostics(error) {
|
|
11132
|
+
const lines = [];
|
|
11133
|
+
if (!isErrorWithCode(error) && !(error instanceof Error)) {
|
|
11134
|
+
return lines;
|
|
11135
|
+
}
|
|
11136
|
+
const code = isErrorWithCode(error) && error.code !== void 0 ? String(error.code) : void 0;
|
|
11137
|
+
if (code) {
|
|
11138
|
+
lines.push(` code: ${code}`);
|
|
11139
|
+
}
|
|
11140
|
+
const errno = isErrorWithCode(error) && error.errno !== void 0 ? String(error.errno) : void 0;
|
|
11141
|
+
if (errno) {
|
|
11142
|
+
lines.push(` errno: ${errno}`);
|
|
11143
|
+
}
|
|
11144
|
+
const syscall = isErrorWithCode(error) && typeof error.syscall === "string" ? error.syscall : void 0;
|
|
11145
|
+
if (syscall) {
|
|
11146
|
+
lines.push(` syscall: ${syscall}`);
|
|
11147
|
+
}
|
|
11148
|
+
const address = isErrorWithCode(error) && typeof error.address === "string" ? error.address : void 0;
|
|
11149
|
+
const port = isErrorWithCode(error) && error.port !== void 0 ? String(error.port) : void 0;
|
|
11150
|
+
if (address || port) {
|
|
11151
|
+
lines.push(
|
|
11152
|
+
` remote: ${address ?? "?"}${port ? `:${port}` : ""}`
|
|
11153
|
+
);
|
|
11154
|
+
}
|
|
11155
|
+
const hostname = isErrorWithCode(error) && typeof error.hostname === "string" ? error.hostname : void 0;
|
|
11156
|
+
if (hostname) {
|
|
11157
|
+
lines.push(` hostname: ${hostname}`);
|
|
11158
|
+
}
|
|
11159
|
+
let cause = error instanceof Error ? error.cause : isErrorWithCode(error) ? error.cause : void 0;
|
|
11160
|
+
let depth = 0;
|
|
11161
|
+
while (cause && depth < 4) {
|
|
11162
|
+
const causeMessage = normalizeErrorMessage(cause);
|
|
11163
|
+
const causeCode = isErrorWithCode(cause) && cause.code !== void 0 ? String(cause.code) : void 0;
|
|
11164
|
+
lines.push(
|
|
11165
|
+
` cause[${depth}]: ${causeCode ? `${causeCode} \u2014 ` : ""}${causeMessage}`
|
|
11166
|
+
);
|
|
11167
|
+
cause = cause instanceof Error ? cause.cause : isErrorWithCode(cause) ? cause.cause : void 0;
|
|
11168
|
+
depth += 1;
|
|
11169
|
+
}
|
|
11170
|
+
return lines;
|
|
11171
|
+
}
|
|
10635
11172
|
function formatGeneratorError(error, configPath) {
|
|
11173
|
+
const diagnostics = collectErrorDiagnostics(error);
|
|
11174
|
+
const diagnosticsBlock = diagnostics.length > 0 ? ["", "Diagnostics:", ...diagnostics] : [];
|
|
10636
11175
|
if (isErrorWithCode(error) && error.code === "3D000") {
|
|
10637
11176
|
const message = normalizeErrorMessage(error);
|
|
10638
11177
|
const databaseName = extractMissingDatabaseName(message);
|
|
@@ -10641,15 +11180,58 @@ function formatGeneratorError(error, configPath) {
|
|
|
10641
11180
|
return new Error(
|
|
10642
11181
|
[
|
|
10643
11182
|
`${databaseLabel} (code 3D000).`,
|
|
10644
|
-
`Update provider.connectionString (and provider.database, if set) in ${configLabel}, or create that database before running generate
|
|
11183
|
+
`Update provider.connectionString (and provider.database, if set) in ${configLabel}, or create that database before running generate.`,
|
|
11184
|
+
...diagnosticsBlock,
|
|
11185
|
+
"",
|
|
11186
|
+
"Hint: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"
|
|
11187
|
+
].join("\n")
|
|
11188
|
+
);
|
|
11189
|
+
}
|
|
11190
|
+
if (isNetworkConnectionError(error)) {
|
|
11191
|
+
const message = normalizeErrorMessage(error);
|
|
11192
|
+
const configLabel = configPath ? `config "${configPath}"` : "the resolved athena config";
|
|
11193
|
+
const code = isErrorWithCode(error) && typeof error.code === "string" ? error.code : "network";
|
|
11194
|
+
return new Error(
|
|
11195
|
+
[
|
|
11196
|
+
`Schema introspection failed: database connection was reset or unreachable (${code}: ${message}).`,
|
|
11197
|
+
`The CLI started correctly; generate could not finish talking to Postgres for ${configLabel}.`,
|
|
11198
|
+
...diagnosticsBlock,
|
|
11199
|
+
"",
|
|
11200
|
+
"Check:",
|
|
11201
|
+
" 1. DATABASE_URL / provider.connectionString is reachable from this machine (VPN, Railway proxy, firewall).",
|
|
11202
|
+
' 2. The database is running and accepts connections (try `psql "$DATABASE_URL" -c "select 1"`).',
|
|
11203
|
+
" 3. SSL settings match the host (Railway/public proxy often needs `?sslmode=require`).",
|
|
11204
|
+
" 4. Retry once \u2014 ECONNRESET is often a transient proxy drop mid-introspection.",
|
|
11205
|
+
"",
|
|
11206
|
+
"For a full stack: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"
|
|
10645
11207
|
].join("\n")
|
|
10646
11208
|
);
|
|
10647
11209
|
}
|
|
10648
11210
|
if (error instanceof Error) {
|
|
10649
|
-
|
|
11211
|
+
if (diagnostics.length === 0 && !isDebugEnabled()) {
|
|
11212
|
+
return error;
|
|
11213
|
+
}
|
|
11214
|
+
const base = error.message || normalizeErrorMessage(error);
|
|
11215
|
+
return new Error(
|
|
11216
|
+
[
|
|
11217
|
+
base,
|
|
11218
|
+
...diagnosticsBlock,
|
|
11219
|
+
...isDebugEnabled() && error.stack ? ["", "Stack:", error.stack] : ["", "Hint: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"]
|
|
11220
|
+
].join("\n")
|
|
11221
|
+
);
|
|
10650
11222
|
}
|
|
10651
11223
|
return new Error(normalizeErrorMessage(error));
|
|
10652
11224
|
}
|
|
11225
|
+
function logCliError(error, errorLog = console.error) {
|
|
11226
|
+
const message = error instanceof Error ? error.message : normalizeErrorMessage(error);
|
|
11227
|
+
errorLog(message);
|
|
11228
|
+
if (isDebugEnabled() && error instanceof Error && error.stack) {
|
|
11229
|
+
const stackOnly = error.stack.startsWith(error.message) ? error.stack.slice(error.message.length).replace(/^\n/, "") : error.stack;
|
|
11230
|
+
if (stackOnly) {
|
|
11231
|
+
errorLog(stackOnly);
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11234
|
+
}
|
|
10653
11235
|
function formatSkippedArtifactLine(artifact) {
|
|
10654
11236
|
if (artifact.reason === "protected-existing-file") {
|
|
10655
11237
|
return ` [skip] ${artifact.path} (existing ${artifact.kind} artifacts are protected from overwrite; delete or retarget the file to regenerate it)`;
|
|
@@ -10658,20 +11240,36 @@ function formatSkippedArtifactLine(artifact) {
|
|
|
10658
11240
|
}
|
|
10659
11241
|
async function runCLI(argv, runtime = {}) {
|
|
10660
11242
|
const log = runtime.log ?? console.log;
|
|
11243
|
+
const errorLog = runtime.errorLog ?? console.error;
|
|
10661
11244
|
const runGenerator = runtime.runGenerator ?? runSchemaGenerator;
|
|
10662
|
-
|
|
11245
|
+
let parsed;
|
|
11246
|
+
try {
|
|
11247
|
+
parsed = parseCommand(argv);
|
|
11248
|
+
} catch (error) {
|
|
11249
|
+
logCliError(formatGeneratorError(error), errorLog);
|
|
11250
|
+
process.exitCode = 1;
|
|
11251
|
+
return;
|
|
11252
|
+
}
|
|
10663
11253
|
if (parsed.command === "help") {
|
|
10664
11254
|
log(usage(parsed.topic));
|
|
10665
11255
|
return;
|
|
10666
11256
|
}
|
|
10667
11257
|
let result;
|
|
10668
11258
|
try {
|
|
11259
|
+
if (isDebugEnabled()) {
|
|
11260
|
+
errorLog(
|
|
11261
|
+
`[athena-js] generate starting (dryRun=${parsed.dryRun}${parsed.configPath ? ` config=${parsed.configPath}` : ""})`
|
|
11262
|
+
);
|
|
11263
|
+
}
|
|
10669
11264
|
result = await runGenerator({
|
|
10670
11265
|
configPath: parsed.configPath,
|
|
10671
11266
|
dryRun: parsed.dryRun
|
|
10672
11267
|
});
|
|
10673
11268
|
} catch (error) {
|
|
10674
|
-
|
|
11269
|
+
const formatted = formatGeneratorError(error, parsed.configPath);
|
|
11270
|
+
logCliError(formatted, errorLog);
|
|
11271
|
+
process.exitCode = 1;
|
|
11272
|
+
return;
|
|
10675
11273
|
}
|
|
10676
11274
|
if (parsed.dryRun) {
|
|
10677
11275
|
log(`[dry-run] Generated ${result.files.length} files from ${result.configPath}`);
|
|
@@ -10695,6 +11293,7 @@ async function runCLI(argv, runtime = {}) {
|
|
|
10695
11293
|
}
|
|
10696
11294
|
}
|
|
10697
11295
|
|
|
11296
|
+
exports.logCliError = logCliError;
|
|
10698
11297
|
exports.parseCommand = parseCommand;
|
|
10699
11298
|
exports.runCLI = runCLI;
|
|
10700
11299
|
exports.usage = usage;
|