@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.js
CHANGED
|
@@ -2002,7 +2002,7 @@ var getSessionCookie = (request2, config) => {
|
|
|
2002
2002
|
|
|
2003
2003
|
// src/utils/athena-request-headers.ts
|
|
2004
2004
|
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
2005
|
-
var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
|
|
2005
|
+
var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
|
|
2006
2006
|
var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
|
|
2007
2007
|
var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
|
|
2008
2008
|
var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
|
|
@@ -2104,17 +2104,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
|
|
|
2104
2104
|
});
|
|
2105
2105
|
}
|
|
2106
2106
|
function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
|
|
2107
|
-
if (apiKey) {
|
|
2108
|
-
if (!hasHeaderIgnoreCase(headers, "apikey")) {
|
|
2109
|
-
headers.apikey = apiKey;
|
|
2110
|
-
}
|
|
2111
|
-
if (!Object.hasOwn(headers, "x-api-key")) {
|
|
2112
|
-
headers["x-api-key"] = apiKey;
|
|
2113
|
-
}
|
|
2114
|
-
if (!Object.hasOwn(headers, "X-Api-Key")) {
|
|
2115
|
-
headers["X-Api-Key"] = apiKey;
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
2107
|
const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
|
|
2119
2108
|
if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
|
|
2120
2109
|
headers["X-Athena-Key"] = resolvedAthenaKey;
|
|
@@ -2240,7 +2229,7 @@ function buildAthenaRequestHeaders(input) {
|
|
|
2240
2229
|
|
|
2241
2230
|
// package.json
|
|
2242
2231
|
var package_default = {
|
|
2243
|
-
version: "2.
|
|
2232
|
+
version: "2.14.0"
|
|
2244
2233
|
};
|
|
2245
2234
|
|
|
2246
2235
|
// src/sdk-version.ts
|
|
@@ -4333,39 +4322,224 @@ function createAuthClient(config = {}) {
|
|
|
4333
4322
|
};
|
|
4334
4323
|
}
|
|
4335
4324
|
|
|
4336
|
-
// src/
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4325
|
+
// src/storage/direct-upload.ts
|
|
4326
|
+
var SERVICE = "s3";
|
|
4327
|
+
var TERMINATOR = "aws4_request";
|
|
4328
|
+
async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
|
|
4329
|
+
if (config.bucket && bucket && config.bucket !== bucket) {
|
|
4330
|
+
throw new Error(
|
|
4331
|
+
`athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
|
|
4332
|
+
);
|
|
4333
|
+
}
|
|
4334
|
+
const target = createDirectUploadTarget(config, bucket, storageKey);
|
|
4335
|
+
const bytes = await bodyToArrayBuffer(body);
|
|
4336
|
+
const payloadHash = await sha256Hex(bytes);
|
|
4337
|
+
const headers = new Headers(uploadHeaders);
|
|
4338
|
+
if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
|
|
4339
|
+
headers.set("Content-Type", body.type);
|
|
4340
|
+
}
|
|
4341
|
+
const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
|
|
4342
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
4343
|
+
return putWithXhr(target.toString(), signed, body, signal, onProgress);
|
|
4344
|
+
}
|
|
4345
|
+
onProgress({ loaded: 0 });
|
|
4346
|
+
const response = await fetch(target, {
|
|
4347
|
+
method: "PUT",
|
|
4348
|
+
headers: signed.requestHeaders,
|
|
4349
|
+
body,
|
|
4350
|
+
signal
|
|
4351
|
+
});
|
|
4352
|
+
if (!response.ok) {
|
|
4353
|
+
throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
|
|
4354
|
+
}
|
|
4355
|
+
onProgress({ loaded: bytes.byteLength });
|
|
4356
|
+
return response;
|
|
4357
|
+
}
|
|
4358
|
+
function createDirectUploadTarget(config, bucket, storageKey) {
|
|
4359
|
+
const resolvedBucket = config.bucket ?? bucket;
|
|
4360
|
+
if (!resolvedBucket?.trim()) {
|
|
4361
|
+
throw new Error(
|
|
4362
|
+
"athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
|
|
4363
|
+
);
|
|
4364
|
+
}
|
|
4365
|
+
if (!storageKey.trim()) {
|
|
4366
|
+
throw new Error("athena.storage.file.upload direct mode requires a storage key");
|
|
4367
|
+
}
|
|
4368
|
+
let endpoint;
|
|
4369
|
+
try {
|
|
4370
|
+
endpoint = new URL(config.endpoint);
|
|
4371
|
+
} catch (error) {
|
|
4372
|
+
throw new Error(
|
|
4373
|
+
`athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4376
|
+
if (endpoint.search || endpoint.hash) {
|
|
4377
|
+
throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
|
|
4378
|
+
}
|
|
4379
|
+
const endpointPath = endpoint.pathname.replace(/\/+$/, "");
|
|
4380
|
+
const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
|
|
4381
|
+
if (config.forcePathStyle === false) {
|
|
4382
|
+
endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
|
|
4383
|
+
}
|
|
4384
|
+
endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
|
|
4385
|
+
return endpoint;
|
|
4386
|
+
}
|
|
4387
|
+
async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
|
|
4388
|
+
const accessKeyId = config.accessKeyId.trim();
|
|
4389
|
+
const secretAccessKey = config.secretAccessKey.trim();
|
|
4390
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
4391
|
+
throw new Error(
|
|
4392
|
+
"athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
|
|
4393
|
+
);
|
|
4394
|
+
}
|
|
4395
|
+
const now = /* @__PURE__ */ new Date();
|
|
4396
|
+
const amzDate = formatAmzDate(now);
|
|
4397
|
+
const shortDate = amzDate.slice(0, 8);
|
|
4398
|
+
const region = config.region?.trim() || "auto";
|
|
4399
|
+
const headers = {};
|
|
4400
|
+
inputHeaders.forEach((value, key) => {
|
|
4401
|
+
if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
|
|
4402
|
+
headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
|
|
4403
|
+
}
|
|
4404
|
+
});
|
|
4405
|
+
headers["x-amz-content-sha256"] = payloadHash;
|
|
4406
|
+
headers["x-amz-date"] = amzDate;
|
|
4407
|
+
if (config.sessionToken?.trim()) {
|
|
4408
|
+
headers["x-amz-security-token"] = config.sessionToken.trim();
|
|
4409
|
+
}
|
|
4410
|
+
const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
|
|
4411
|
+
`).join("");
|
|
4412
|
+
const signedHeaders = Object.keys(headers).sort().join(";");
|
|
4413
|
+
const canonicalRequest = [
|
|
4414
|
+
"PUT",
|
|
4415
|
+
target.pathname,
|
|
4416
|
+
"",
|
|
4417
|
+
`host:${target.host}
|
|
4418
|
+
${canonicalHeaders}`,
|
|
4419
|
+
`host;${signedHeaders}`,
|
|
4420
|
+
payloadHash
|
|
4421
|
+
].join("\n");
|
|
4422
|
+
const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
|
|
4423
|
+
const stringToSign = [
|
|
4424
|
+
"AWS4-HMAC-SHA256",
|
|
4425
|
+
amzDate,
|
|
4426
|
+
credentialScope,
|
|
4427
|
+
await sha256Hex(canonicalRequest)
|
|
4428
|
+
].join("\n");
|
|
4429
|
+
const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
|
|
4430
|
+
const regionKey = await hmac(dateKey, region);
|
|
4431
|
+
const serviceKey = await hmac(regionKey, SERVICE);
|
|
4432
|
+
const signingKey = await hmac(serviceKey, TERMINATOR);
|
|
4433
|
+
const signature = await hmacHex(signingKey, stringToSign);
|
|
4434
|
+
headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
|
|
4435
|
+
return { requestHeaders: headers };
|
|
4436
|
+
}
|
|
4437
|
+
async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
4438
|
+
const Xhr = XMLHttpRequest;
|
|
4439
|
+
if (Xhr === void 0) {
|
|
4440
|
+
return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
|
|
4441
|
+
}
|
|
4442
|
+
return new Promise((resolve3, reject) => {
|
|
4443
|
+
const xhr = new Xhr();
|
|
4444
|
+
const abort = () => xhr.abort();
|
|
4445
|
+
xhr.open("PUT", url);
|
|
4446
|
+
Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
|
|
4447
|
+
xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
|
|
4448
|
+
xhr.onload = () => {
|
|
4449
|
+
signal?.removeEventListener("abort", abort);
|
|
4450
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
4451
|
+
reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
|
|
4452
|
+
return;
|
|
4343
4453
|
}
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
}
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4454
|
+
onProgress({ loaded: bodySize(body) });
|
|
4455
|
+
resolve3(new Response(xhr.response, {
|
|
4456
|
+
status: xhr.status,
|
|
4457
|
+
statusText: xhr.statusText,
|
|
4458
|
+
headers: parseXhrHeaders(xhr.getAllResponseHeaders())
|
|
4459
|
+
}));
|
|
4460
|
+
};
|
|
4461
|
+
xhr.onerror = () => {
|
|
4462
|
+
signal?.removeEventListener("abort", abort);
|
|
4463
|
+
reject(new Error("athena.storage.file.upload failed with a network error"));
|
|
4464
|
+
};
|
|
4465
|
+
xhr.onabort = () => {
|
|
4466
|
+
signal?.removeEventListener("abort", abort);
|
|
4467
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
4468
|
+
};
|
|
4469
|
+
if (signal) {
|
|
4470
|
+
if (signal.aborted) {
|
|
4471
|
+
abort();
|
|
4472
|
+
return;
|
|
4473
|
+
}
|
|
4474
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
4363
4475
|
}
|
|
4364
|
-
|
|
4365
|
-
|
|
4476
|
+
xhr.send(body);
|
|
4477
|
+
});
|
|
4478
|
+
}
|
|
4479
|
+
function isBlobBody(body) {
|
|
4480
|
+
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
4481
|
+
}
|
|
4482
|
+
async function bodyToArrayBuffer(body) {
|
|
4483
|
+
if (isBlobBody(body)) return body.arrayBuffer();
|
|
4484
|
+
if (body instanceof ArrayBuffer) return body;
|
|
4485
|
+
if (ArrayBuffer.isView(body)) {
|
|
4486
|
+
return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
|
|
4487
|
+
}
|
|
4488
|
+
throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
|
|
4489
|
+
}
|
|
4490
|
+
function bodySize(body) {
|
|
4491
|
+
if (isBlobBody(body)) return body.size;
|
|
4492
|
+
if (body instanceof ArrayBuffer) return body.byteLength;
|
|
4493
|
+
if (ArrayBuffer.isView(body)) return body.byteLength;
|
|
4494
|
+
return 0;
|
|
4495
|
+
}
|
|
4496
|
+
function awsEncode(value) {
|
|
4497
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
4498
|
+
}
|
|
4499
|
+
function formatAmzDate(date) {
|
|
4500
|
+
return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
4501
|
+
}
|
|
4502
|
+
async function sha256Hex(value) {
|
|
4503
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
|
|
4504
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
4505
|
+
return toHex(new Uint8Array(digest));
|
|
4506
|
+
}
|
|
4507
|
+
async function hmac(key, value) {
|
|
4508
|
+
const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
4509
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
4510
|
+
"raw",
|
|
4511
|
+
keyBytes,
|
|
4512
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
4513
|
+
false,
|
|
4514
|
+
["sign"]
|
|
4515
|
+
);
|
|
4516
|
+
return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
|
|
4517
|
+
}
|
|
4518
|
+
async function hmacHex(key, value) {
|
|
4519
|
+
return toHex(new Uint8Array(await hmac(key, value)));
|
|
4520
|
+
}
|
|
4521
|
+
function toHex(bytes) {
|
|
4522
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
4523
|
+
}
|
|
4524
|
+
function parseXhrHeaders(rawHeaders) {
|
|
4525
|
+
const headers = new Headers();
|
|
4526
|
+
rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
|
|
4527
|
+
const separator = line.indexOf(":");
|
|
4528
|
+
if (separator > 0) {
|
|
4529
|
+
headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
4530
|
+
}
|
|
4531
|
+
});
|
|
4532
|
+
return headers;
|
|
4366
4533
|
}
|
|
4367
4534
|
|
|
4368
4535
|
// src/storage/file.ts
|
|
4536
|
+
function mergeUploadHeaders(serverHeaders, inputHeaders) {
|
|
4537
|
+
const headers = { ...serverHeaders };
|
|
4538
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
4539
|
+
headers[key] = value;
|
|
4540
|
+
});
|
|
4541
|
+
return headers;
|
|
4542
|
+
}
|
|
4369
4543
|
function createStorageFileModule(base, config = {}) {
|
|
4370
4544
|
const upload = async (input, options) => {
|
|
4371
4545
|
const sources = normalizeUploadSources(input);
|
|
@@ -4401,16 +4575,25 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4401
4575
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
4402
4576
|
const request2 = uploadRequests[index];
|
|
4403
4577
|
const uploadUrl = uploadUrls[index];
|
|
4404
|
-
const
|
|
4578
|
+
const aggregateProgress = (progress) => {
|
|
4579
|
+
aggregateLoaded[index] = progress.loaded;
|
|
4580
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
4581
|
+
};
|
|
4582
|
+
const response = config.directUpload ? await putDirectStorageUploadBody(
|
|
4583
|
+
config.directUpload,
|
|
4584
|
+
uploadUrl.upload.bucket,
|
|
4585
|
+
uploadUrl.upload.storage_key,
|
|
4586
|
+
request2.source.source,
|
|
4587
|
+
mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
|
|
4588
|
+
options?.signal,
|
|
4589
|
+
aggregateProgress
|
|
4590
|
+
) : await putUploadBody(
|
|
4405
4591
|
uploadUrl.upload.url,
|
|
4406
4592
|
uploadUrl.upload.headers ?? {},
|
|
4407
4593
|
request2.source,
|
|
4408
4594
|
input,
|
|
4409
4595
|
options,
|
|
4410
|
-
|
|
4411
|
-
aggregateLoaded[index] = progress.loaded;
|
|
4412
|
-
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
4413
|
-
}
|
|
4596
|
+
aggregateProgress
|
|
4414
4597
|
);
|
|
4415
4598
|
uploaded.push({
|
|
4416
4599
|
file: uploadUrl.file,
|
|
@@ -4561,7 +4744,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
4561
4744
|
resolve3(new Response(xhr.response, {
|
|
4562
4745
|
status: xhr.status,
|
|
4563
4746
|
statusText: xhr.statusText,
|
|
4564
|
-
headers:
|
|
4747
|
+
headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
|
|
4565
4748
|
}));
|
|
4566
4749
|
};
|
|
4567
4750
|
xhr.onerror = () => {
|
|
@@ -4699,7 +4882,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
|
|
|
4699
4882
|
function sum(values) {
|
|
4700
4883
|
return values.reduce((total, value) => total + value, 0);
|
|
4701
4884
|
}
|
|
4702
|
-
function
|
|
4885
|
+
function parseXhrHeaders2(raw) {
|
|
4703
4886
|
const headers = new Headers();
|
|
4704
4887
|
for (const line of raw.trim().split(/[\r\n]+/)) {
|
|
4705
4888
|
const index = line.indexOf(":");
|
|
@@ -4716,6 +4899,230 @@ function isRecord5(value) {
|
|
|
4716
4899
|
return Boolean(value) && typeof value === "object";
|
|
4717
4900
|
}
|
|
4718
4901
|
|
|
4902
|
+
// src/storage/backup.ts
|
|
4903
|
+
function backupError(message, status, endpoint, method, cause, raw) {
|
|
4904
|
+
const error = new Error(message);
|
|
4905
|
+
error.name = "AthenaStorageError";
|
|
4906
|
+
error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
|
|
4907
|
+
error.status = status;
|
|
4908
|
+
error.endpoint = endpoint;
|
|
4909
|
+
error.method = method;
|
|
4910
|
+
error.cause = cause;
|
|
4911
|
+
error.raw = raw;
|
|
4912
|
+
throw error;
|
|
4913
|
+
}
|
|
4914
|
+
function isRecord6(value) {
|
|
4915
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4916
|
+
}
|
|
4917
|
+
function asPath(path) {
|
|
4918
|
+
return path;
|
|
4919
|
+
}
|
|
4920
|
+
function appendQuery(path, query) {
|
|
4921
|
+
if (!query) return path;
|
|
4922
|
+
const params = new URLSearchParams();
|
|
4923
|
+
for (const [key, value] of Object.entries(query)) {
|
|
4924
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
4925
|
+
params.set(key, String(value));
|
|
4926
|
+
}
|
|
4927
|
+
const text = params.toString();
|
|
4928
|
+
return text ? `${path}?${text}` : path;
|
|
4929
|
+
}
|
|
4930
|
+
function unwrapAthenaData(payload) {
|
|
4931
|
+
if (isRecord6(payload) && "data" in payload) {
|
|
4932
|
+
return payload.data;
|
|
4933
|
+
}
|
|
4934
|
+
return payload;
|
|
4935
|
+
}
|
|
4936
|
+
function requireKey(key) {
|
|
4937
|
+
const trimmed = key.trim();
|
|
4938
|
+
if (!trimmed || trimmed === "undefined" || trimmed === "null") {
|
|
4939
|
+
backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
|
|
4940
|
+
}
|
|
4941
|
+
return trimmed;
|
|
4942
|
+
}
|
|
4943
|
+
function resolveMessage(payload, fallback) {
|
|
4944
|
+
if (isRecord6(payload)) {
|
|
4945
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
4946
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
4947
|
+
}
|
|
4948
|
+
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
4949
|
+
return fallback;
|
|
4950
|
+
}
|
|
4951
|
+
async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
|
|
4952
|
+
const endpoint = asPath(path);
|
|
4953
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4954
|
+
const url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
4955
|
+
const headers = gateway.buildHeaders(options);
|
|
4956
|
+
const init = {
|
|
4957
|
+
method,
|
|
4958
|
+
headers,
|
|
4959
|
+
signal: options?.signal
|
|
4960
|
+
};
|
|
4961
|
+
if (payload !== void 0 && method !== "GET") {
|
|
4962
|
+
init.body = JSON.stringify(payload);
|
|
4963
|
+
}
|
|
4964
|
+
let response;
|
|
4965
|
+
try {
|
|
4966
|
+
response = await fetch(url, init);
|
|
4967
|
+
} catch (error) {
|
|
4968
|
+
backupError(
|
|
4969
|
+
error instanceof Error ? error.message : "Backup network error",
|
|
4970
|
+
0,
|
|
4971
|
+
path,
|
|
4972
|
+
method,
|
|
4973
|
+
error
|
|
4974
|
+
);
|
|
4975
|
+
}
|
|
4976
|
+
const rawText = await response.text();
|
|
4977
|
+
let parsed = null;
|
|
4978
|
+
if (rawText) {
|
|
4979
|
+
try {
|
|
4980
|
+
parsed = JSON.parse(rawText);
|
|
4981
|
+
} catch {
|
|
4982
|
+
parsed = rawText;
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
if (!response.ok) {
|
|
4986
|
+
backupError(
|
|
4987
|
+
resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
|
|
4988
|
+
response.status,
|
|
4989
|
+
path,
|
|
4990
|
+
method,
|
|
4991
|
+
void 0,
|
|
4992
|
+
parsed
|
|
4993
|
+
);
|
|
4994
|
+
}
|
|
4995
|
+
return unwrapAthenaData(parsed);
|
|
4996
|
+
}
|
|
4997
|
+
function createStorageBackupModule(gateway, runtimeOptions) {
|
|
4998
|
+
const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
|
|
4999
|
+
return {
|
|
5000
|
+
async list(query, options) {
|
|
5001
|
+
const path = appendQuery("/admin/backups", {
|
|
5002
|
+
limit: query?.limit ?? 10,
|
|
5003
|
+
client_name: query?.client_name,
|
|
5004
|
+
cursor: query?.cursor ?? void 0
|
|
5005
|
+
});
|
|
5006
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
5007
|
+
const backups = (data?.backups ?? []).map((row) => ({
|
|
5008
|
+
...row,
|
|
5009
|
+
key: row.key ?? row.s3_key
|
|
5010
|
+
}));
|
|
5011
|
+
return {
|
|
5012
|
+
backups,
|
|
5013
|
+
next_cursor: data?.next_cursor ?? null
|
|
5014
|
+
};
|
|
5015
|
+
},
|
|
5016
|
+
async create(input, options) {
|
|
5017
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
|
|
5018
|
+
return {
|
|
5019
|
+
job_id: Number(data?.job_id ?? 0),
|
|
5020
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
5021
|
+
status: String(data?.status ?? "pending")
|
|
5022
|
+
};
|
|
5023
|
+
},
|
|
5024
|
+
async restore(key, input, options) {
|
|
5025
|
+
const backupKey = requireKey(key);
|
|
5026
|
+
const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
|
|
5027
|
+
const data = await callBackupEndpoint(gateway, path, "POST", input, options);
|
|
5028
|
+
return {
|
|
5029
|
+
job_id: Number(data?.job_id ?? 0),
|
|
5030
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
5031
|
+
status: String(data?.status ?? "pending"),
|
|
5032
|
+
key: String(data?.key ?? backupKey)
|
|
5033
|
+
};
|
|
5034
|
+
},
|
|
5035
|
+
async delete(key, options) {
|
|
5036
|
+
const backupKey = requireKey(key);
|
|
5037
|
+
await callBackupEndpoint(
|
|
5038
|
+
gateway,
|
|
5039
|
+
`/admin/backups/${encodeURIComponent(backupKey)}`,
|
|
5040
|
+
"DELETE",
|
|
5041
|
+
void 0,
|
|
5042
|
+
options);
|
|
5043
|
+
},
|
|
5044
|
+
downloadUrl(key, options) {
|
|
5045
|
+
const backupKey = requireKey(key);
|
|
5046
|
+
const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
|
|
5047
|
+
return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
|
|
5048
|
+
},
|
|
5049
|
+
jobs: {
|
|
5050
|
+
async list(query, options) {
|
|
5051
|
+
const path = appendQuery("/admin/backups/jobs", query ?? {});
|
|
5052
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
5053
|
+
if (Array.isArray(data)) return data;
|
|
5054
|
+
if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
|
|
5055
|
+
return [];
|
|
5056
|
+
},
|
|
5057
|
+
async get(jobId, options) {
|
|
5058
|
+
return callBackupEndpoint(
|
|
5059
|
+
gateway,
|
|
5060
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
5061
|
+
"GET",
|
|
5062
|
+
void 0,
|
|
5063
|
+
options);
|
|
5064
|
+
},
|
|
5065
|
+
async cancel(jobId, options) {
|
|
5066
|
+
return callBackupEndpoint(
|
|
5067
|
+
gateway,
|
|
5068
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
|
|
5069
|
+
"POST",
|
|
5070
|
+
{},
|
|
5071
|
+
options);
|
|
5072
|
+
},
|
|
5073
|
+
async delete(jobId, options) {
|
|
5074
|
+
await callBackupEndpoint(
|
|
5075
|
+
gateway,
|
|
5076
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
5077
|
+
"DELETE",
|
|
5078
|
+
void 0,
|
|
5079
|
+
options);
|
|
5080
|
+
},
|
|
5081
|
+
async openObjectUrl(jobId, options) {
|
|
5082
|
+
const data = await callBackupEndpoint(
|
|
5083
|
+
gateway,
|
|
5084
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
|
|
5085
|
+
"GET",
|
|
5086
|
+
void 0,
|
|
5087
|
+
options);
|
|
5088
|
+
return String(data?.url ?? "");
|
|
5089
|
+
}
|
|
5090
|
+
},
|
|
5091
|
+
schedules: {
|
|
5092
|
+
async list(options) {
|
|
5093
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
|
|
5094
|
+
if (Array.isArray(data)) return data;
|
|
5095
|
+
if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
|
|
5096
|
+
return [];
|
|
5097
|
+
},
|
|
5098
|
+
async create(input, options) {
|
|
5099
|
+
return callBackupEndpoint(
|
|
5100
|
+
gateway,
|
|
5101
|
+
"/admin/backups/schedules",
|
|
5102
|
+
"POST",
|
|
5103
|
+
input,
|
|
5104
|
+
options);
|
|
5105
|
+
},
|
|
5106
|
+
async update(id, input, options) {
|
|
5107
|
+
return callBackupEndpoint(
|
|
5108
|
+
gateway,
|
|
5109
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
5110
|
+
"PATCH",
|
|
5111
|
+
input,
|
|
5112
|
+
options);
|
|
5113
|
+
},
|
|
5114
|
+
async delete(id, options) {
|
|
5115
|
+
await callBackupEndpoint(
|
|
5116
|
+
gateway,
|
|
5117
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
5118
|
+
"DELETE",
|
|
5119
|
+
void 0,
|
|
5120
|
+
options);
|
|
5121
|
+
}
|
|
5122
|
+
}
|
|
5123
|
+
};
|
|
5124
|
+
}
|
|
5125
|
+
|
|
4719
5126
|
// src/storage/module.ts
|
|
4720
5127
|
var storageSdkManifest = {
|
|
4721
5128
|
methods: [
|
|
@@ -4758,6 +5165,53 @@ var storageSdkManifest = {
|
|
|
4758
5165
|
responseEnvelope: "raw",
|
|
4759
5166
|
responseType: "{ data: S3CredentialListItem[] }"
|
|
4760
5167
|
},
|
|
5168
|
+
{
|
|
5169
|
+
name: "backup.list",
|
|
5170
|
+
method: "GET",
|
|
5171
|
+
path: "/admin/backups",
|
|
5172
|
+
responseEnvelope: "athena",
|
|
5173
|
+
responseType: "StorageBackupListPage",
|
|
5174
|
+
note: "Admin backup archives on server S3/R2 profile"
|
|
5175
|
+
},
|
|
5176
|
+
{
|
|
5177
|
+
name: "backup.create",
|
|
5178
|
+
method: "POST",
|
|
5179
|
+
path: "/admin/backups",
|
|
5180
|
+
requestType: "StorageBackupCreateRequest",
|
|
5181
|
+
responseEnvelope: "athena",
|
|
5182
|
+
responseType: "StorageBackupQueuedJob"
|
|
5183
|
+
},
|
|
5184
|
+
{
|
|
5185
|
+
name: "backup.restore",
|
|
5186
|
+
method: "POST",
|
|
5187
|
+
path: "/admin/backups/{key}/restore",
|
|
5188
|
+
pathParams: ["key"],
|
|
5189
|
+
requestType: "StorageBackupRestoreRequest",
|
|
5190
|
+
responseEnvelope: "athena",
|
|
5191
|
+
responseType: "StorageBackupQueuedJob"
|
|
5192
|
+
},
|
|
5193
|
+
{
|
|
5194
|
+
name: "backup.delete",
|
|
5195
|
+
method: "DELETE",
|
|
5196
|
+
path: "/admin/backups/{key}",
|
|
5197
|
+
pathParams: ["key"],
|
|
5198
|
+
responseEnvelope: "athena",
|
|
5199
|
+
responseType: "void"
|
|
5200
|
+
},
|
|
5201
|
+
{
|
|
5202
|
+
name: "backup.jobs.list",
|
|
5203
|
+
method: "GET",
|
|
5204
|
+
path: "/admin/backups/jobs",
|
|
5205
|
+
responseEnvelope: "athena",
|
|
5206
|
+
responseType: "StorageBackupJob[]"
|
|
5207
|
+
},
|
|
5208
|
+
{
|
|
5209
|
+
name: "backup.schedules.list",
|
|
5210
|
+
method: "GET",
|
|
5211
|
+
path: "/admin/backups/schedules",
|
|
5212
|
+
responseEnvelope: "athena",
|
|
5213
|
+
responseType: "StorageBackupSchedule[]"
|
|
5214
|
+
},
|
|
4761
5215
|
{
|
|
4762
5216
|
name: "createStorageUploadUrl",
|
|
4763
5217
|
method: "POST",
|
|
@@ -5405,7 +5859,7 @@ var AthenaStorageError = class extends Error {
|
|
|
5405
5859
|
};
|
|
5406
5860
|
}
|
|
5407
5861
|
};
|
|
5408
|
-
function
|
|
5862
|
+
function isRecord7(value) {
|
|
5409
5863
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5410
5864
|
}
|
|
5411
5865
|
function causeToString(cause) {
|
|
@@ -5503,7 +5957,7 @@ function parseResponseBody3(rawText, contentType) {
|
|
|
5503
5957
|
return { parsed: rawText, parseFailed: true };
|
|
5504
5958
|
}
|
|
5505
5959
|
}
|
|
5506
|
-
function
|
|
5960
|
+
function appendQuery2(path, query) {
|
|
5507
5961
|
if (!query) return path;
|
|
5508
5962
|
const params = new URLSearchParams();
|
|
5509
5963
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -5529,7 +5983,7 @@ function withPathParam(path, name, value) {
|
|
|
5529
5983
|
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
5530
5984
|
}
|
|
5531
5985
|
function resolveErrorMessage3(payload, fallback) {
|
|
5532
|
-
if (
|
|
5986
|
+
if (isRecord7(payload)) {
|
|
5533
5987
|
const message = payload.message ?? payload.error ?? payload.details;
|
|
5534
5988
|
if (typeof message === "string" && message.trim()) {
|
|
5535
5989
|
return message.trim();
|
|
@@ -5541,12 +5995,12 @@ function resolveErrorMessage3(payload, fallback) {
|
|
|
5541
5995
|
return fallback;
|
|
5542
5996
|
}
|
|
5543
5997
|
function resolveErrorHint2(payload) {
|
|
5544
|
-
if (!
|
|
5998
|
+
if (!isRecord7(payload)) return void 0;
|
|
5545
5999
|
const hint = payload.hint ?? payload.suggestion;
|
|
5546
6000
|
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
5547
6001
|
}
|
|
5548
6002
|
function resolveErrorCause(payload) {
|
|
5549
|
-
if (!
|
|
6003
|
+
if (!isRecord7(payload)) return void 0;
|
|
5550
6004
|
const cause = payload.cause ?? payload.reason;
|
|
5551
6005
|
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
5552
6006
|
}
|
|
@@ -5665,7 +6119,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
|
|
|
5665
6119
|
);
|
|
5666
6120
|
}
|
|
5667
6121
|
if (envelope === "athena") {
|
|
5668
|
-
if (!
|
|
6122
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
5669
6123
|
return rejectStorageError(
|
|
5670
6124
|
{
|
|
5671
6125
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -5773,7 +6227,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
5773
6227
|
runtimeOptions
|
|
5774
6228
|
);
|
|
5775
6229
|
}
|
|
5776
|
-
function
|
|
6230
|
+
function isBlobBody2(body) {
|
|
5777
6231
|
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
5778
6232
|
}
|
|
5779
6233
|
function isReadableStreamBody(body) {
|
|
@@ -5782,7 +6236,7 @@ function isReadableStreamBody(body) {
|
|
|
5782
6236
|
async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
5783
6237
|
const headers = new Headers(uploadHeaders);
|
|
5784
6238
|
Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
|
|
5785
|
-
if (!headers.has("Content-Type") &&
|
|
6239
|
+
if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
|
|
5786
6240
|
headers.set("Content-Type", body.type);
|
|
5787
6241
|
}
|
|
5788
6242
|
const init = {
|
|
@@ -5877,7 +6331,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
5877
6331
|
}
|
|
5878
6332
|
delete headers["Content-Type"];
|
|
5879
6333
|
delete headers["content-type"];
|
|
5880
|
-
if (
|
|
6334
|
+
if (isBlobBody2(body) && body.type) {
|
|
5881
6335
|
headers["Content-Type"] = body.type;
|
|
5882
6336
|
}
|
|
5883
6337
|
const requestInit = {
|
|
@@ -5962,7 +6416,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
5962
6416
|
runtimeOptions
|
|
5963
6417
|
);
|
|
5964
6418
|
}
|
|
5965
|
-
if (!
|
|
6419
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
5966
6420
|
return rejectStorageError(
|
|
5967
6421
|
{
|
|
5968
6422
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -6034,14 +6488,14 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6034
6488
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
|
|
6035
6489
|
},
|
|
6036
6490
|
getStorageFileUrl(fileId, query, options) {
|
|
6037
|
-
const path =
|
|
6491
|
+
const path = appendQuery2(
|
|
6038
6492
|
withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
|
|
6039
6493
|
query
|
|
6040
6494
|
);
|
|
6041
6495
|
return callAthena2(path, "GET", void 0, options);
|
|
6042
6496
|
},
|
|
6043
6497
|
getStorageFileProxy(fileId, query, options) {
|
|
6044
|
-
const path =
|
|
6498
|
+
const path = appendQuery2(
|
|
6045
6499
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
6046
6500
|
query
|
|
6047
6501
|
);
|
|
@@ -6065,7 +6519,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6065
6519
|
};
|
|
6066
6520
|
const fileFacade = createStorageFileModule(base, runtimeOptions);
|
|
6067
6521
|
const fileUpload = ((input, options) => {
|
|
6068
|
-
if (
|
|
6522
|
+
if (isRecord7(input) && "files" in input) {
|
|
6069
6523
|
return fileFacade.upload(input, options);
|
|
6070
6524
|
}
|
|
6071
6525
|
return base.createStorageUploadUrl(
|
|
@@ -6127,7 +6581,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6127
6581
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
6128
6582
|
},
|
|
6129
6583
|
proxyUrl(fileId, query, options) {
|
|
6130
|
-
const path =
|
|
6584
|
+
const path = appendQuery2(
|
|
6131
6585
|
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
6132
6586
|
query
|
|
6133
6587
|
);
|
|
@@ -6165,7 +6619,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6165
6619
|
},
|
|
6166
6620
|
retention: {
|
|
6167
6621
|
get(fileId, query, options) {
|
|
6168
|
-
const path =
|
|
6622
|
+
const path = appendQuery2(
|
|
6169
6623
|
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
6170
6624
|
query
|
|
6171
6625
|
);
|
|
@@ -6367,6 +6821,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6367
6821
|
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
6368
6822
|
}
|
|
6369
6823
|
};
|
|
6824
|
+
const backup = createStorageBackupModule(gateway);
|
|
6370
6825
|
return {
|
|
6371
6826
|
...base,
|
|
6372
6827
|
credentials,
|
|
@@ -6378,6 +6833,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6378
6833
|
bucket,
|
|
6379
6834
|
multipart,
|
|
6380
6835
|
audit,
|
|
6836
|
+
backup,
|
|
6381
6837
|
delete: file.delete
|
|
6382
6838
|
};
|
|
6383
6839
|
}
|
|
@@ -6427,7 +6883,7 @@ function normalizeWsUrl(value, label) {
|
|
|
6427
6883
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
6428
6884
|
return parsed.toString().replace(/\/$/, "");
|
|
6429
6885
|
}
|
|
6430
|
-
function
|
|
6886
|
+
function isRecord8(value) {
|
|
6431
6887
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6432
6888
|
}
|
|
6433
6889
|
function parseResponseBody4(rawText, contentType) {
|
|
@@ -6449,7 +6905,7 @@ function resolveRequestId3(headers) {
|
|
|
6449
6905
|
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
6450
6906
|
}
|
|
6451
6907
|
function resolveErrorMessage4(payload, fallback) {
|
|
6452
|
-
if (
|
|
6908
|
+
if (isRecord8(payload)) {
|
|
6453
6909
|
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
6454
6910
|
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
6455
6911
|
return candidate.trim();
|
|
@@ -6858,7 +7314,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
6858
7314
|
"ilike",
|
|
6859
7315
|
"is"
|
|
6860
7316
|
]);
|
|
6861
|
-
function
|
|
7317
|
+
function isRecord9(value) {
|
|
6862
7318
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6863
7319
|
}
|
|
6864
7320
|
function isUuidString(value) {
|
|
@@ -6871,7 +7327,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
6871
7327
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
6872
7328
|
}
|
|
6873
7329
|
function isRelationSelectNode(value) {
|
|
6874
|
-
return
|
|
7330
|
+
return isRecord9(value) && isRecord9(value.select);
|
|
6875
7331
|
}
|
|
6876
7332
|
function normalizeIdentifier(value, label) {
|
|
6877
7333
|
const normalized = value.trim();
|
|
@@ -6927,7 +7383,7 @@ function compileRelationToken(key, node) {
|
|
|
6927
7383
|
return `${prefix}${relationToken}(${nested})`;
|
|
6928
7384
|
}
|
|
6929
7385
|
function compileSelectShape(select) {
|
|
6930
|
-
if (!
|
|
7386
|
+
if (!isRecord9(select)) {
|
|
6931
7387
|
throw new Error("findMany select must be an object");
|
|
6932
7388
|
}
|
|
6933
7389
|
const tokens = [];
|
|
@@ -6951,7 +7407,7 @@ function compileSelectShape(select) {
|
|
|
6951
7407
|
return tokens.join(",");
|
|
6952
7408
|
}
|
|
6953
7409
|
function selectShapeUsesRelationSchema(select) {
|
|
6954
|
-
if (!
|
|
7410
|
+
if (!isRecord9(select)) {
|
|
6955
7411
|
return false;
|
|
6956
7412
|
}
|
|
6957
7413
|
for (const rawValue of Object.values(select)) {
|
|
@@ -6969,7 +7425,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
6969
7425
|
}
|
|
6970
7426
|
function compileColumnWhere(column, input) {
|
|
6971
7427
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
6972
|
-
if (!
|
|
7428
|
+
if (!isRecord9(input)) {
|
|
6973
7429
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
6974
7430
|
}
|
|
6975
7431
|
const conditions = [];
|
|
@@ -6997,7 +7453,7 @@ function compileColumnWhere(column, input) {
|
|
|
6997
7453
|
return conditions;
|
|
6998
7454
|
}
|
|
6999
7455
|
function compileBooleanExpressionTerms(clause, label) {
|
|
7000
|
-
if (!
|
|
7456
|
+
if (!isRecord9(clause)) {
|
|
7001
7457
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
7002
7458
|
}
|
|
7003
7459
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -7006,7 +7462,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
7006
7462
|
}
|
|
7007
7463
|
const [rawColumn, rawValue] = entries[0];
|
|
7008
7464
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
7009
|
-
if (!
|
|
7465
|
+
if (!isRecord9(rawValue)) {
|
|
7010
7466
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
7011
7467
|
}
|
|
7012
7468
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -7030,7 +7486,7 @@ function compileWhere(where) {
|
|
|
7030
7486
|
if (where === void 0) {
|
|
7031
7487
|
return void 0;
|
|
7032
7488
|
}
|
|
7033
|
-
if (!
|
|
7489
|
+
if (!isRecord9(where)) {
|
|
7034
7490
|
throw new Error("findMany where must be an object");
|
|
7035
7491
|
}
|
|
7036
7492
|
const conditions = [];
|
|
@@ -7080,7 +7536,7 @@ function compileOrderBy(orderBy) {
|
|
|
7080
7536
|
if (orderBy === void 0) {
|
|
7081
7537
|
return void 0;
|
|
7082
7538
|
}
|
|
7083
|
-
if (!
|
|
7539
|
+
if (!isRecord9(orderBy)) {
|
|
7084
7540
|
throw new Error("findMany orderBy must be an object");
|
|
7085
7541
|
}
|
|
7086
7542
|
if ("column" in orderBy) {
|
|
@@ -7255,11 +7711,11 @@ function toFindManyAstOrder(order) {
|
|
|
7255
7711
|
ascending: order.direction !== "descending"
|
|
7256
7712
|
};
|
|
7257
7713
|
}
|
|
7258
|
-
function
|
|
7714
|
+
function isRecord10(value) {
|
|
7259
7715
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7260
7716
|
}
|
|
7261
7717
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
7262
|
-
if (!
|
|
7718
|
+
if (!isRecord10(value)) {
|
|
7263
7719
|
return {
|
|
7264
7720
|
eq: value
|
|
7265
7721
|
};
|
|
@@ -7283,7 +7739,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
7283
7739
|
return normalized;
|
|
7284
7740
|
}
|
|
7285
7741
|
function normalizeFindManyAstWhere(where) {
|
|
7286
|
-
if (!where || !
|
|
7742
|
+
if (!where || !isRecord10(where)) {
|
|
7287
7743
|
return where;
|
|
7288
7744
|
}
|
|
7289
7745
|
const normalized = {};
|
|
@@ -7297,7 +7753,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
7297
7753
|
);
|
|
7298
7754
|
continue;
|
|
7299
7755
|
}
|
|
7300
|
-
if (key === "not" &&
|
|
7756
|
+
if (key === "not" && isRecord10(value)) {
|
|
7301
7757
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
7302
7758
|
value
|
|
7303
7759
|
);
|
|
@@ -7308,7 +7764,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
7308
7764
|
return normalized;
|
|
7309
7765
|
}
|
|
7310
7766
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
7311
|
-
if (!
|
|
7767
|
+
if (!isRecord10(value)) {
|
|
7312
7768
|
return shouldUseUuidTextComparison(column, value);
|
|
7313
7769
|
}
|
|
7314
7770
|
const eqValue = value.eq;
|
|
@@ -7326,7 +7782,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
7326
7782
|
return false;
|
|
7327
7783
|
}
|
|
7328
7784
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
7329
|
-
if (!where || !
|
|
7785
|
+
if (!where || !isRecord10(where)) {
|
|
7330
7786
|
return false;
|
|
7331
7787
|
}
|
|
7332
7788
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -7341,7 +7797,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
7341
7797
|
}
|
|
7342
7798
|
continue;
|
|
7343
7799
|
}
|
|
7344
|
-
if (key === "not" &&
|
|
7800
|
+
if (key === "not" && isRecord10(value)) {
|
|
7345
7801
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
7346
7802
|
return true;
|
|
7347
7803
|
}
|
|
@@ -7961,7 +8417,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
7961
8417
|
throw error;
|
|
7962
8418
|
}
|
|
7963
8419
|
}
|
|
7964
|
-
function
|
|
8420
|
+
function isRecord11(value) {
|
|
7965
8421
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7966
8422
|
}
|
|
7967
8423
|
function firstNonEmptyString2(...values) {
|
|
@@ -7973,8 +8429,8 @@ function firstNonEmptyString2(...values) {
|
|
|
7973
8429
|
return void 0;
|
|
7974
8430
|
}
|
|
7975
8431
|
function resolveStructuredErrorPayload2(raw) {
|
|
7976
|
-
if (!
|
|
7977
|
-
return
|
|
8432
|
+
if (!isRecord11(raw)) return null;
|
|
8433
|
+
return isRecord11(raw.error) ? raw.error : raw;
|
|
7978
8434
|
}
|
|
7979
8435
|
function resolveStructuredErrorDetails(payload, message) {
|
|
7980
8436
|
if (!payload || !("details" in payload)) {
|
|
@@ -7990,7 +8446,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
7990
8446
|
return details;
|
|
7991
8447
|
}
|
|
7992
8448
|
function createResultError(response, result, normalized) {
|
|
7993
|
-
const rawRecord =
|
|
8449
|
+
const rawRecord = isRecord11(response.raw) ? response.raw : null;
|
|
7994
8450
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
7995
8451
|
const message = firstNonEmptyString2(
|
|
7996
8452
|
response.error,
|
|
@@ -9712,7 +10168,30 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9712
10168
|
config.experimental,
|
|
9713
10169
|
queryTracer
|
|
9714
10170
|
);
|
|
9715
|
-
const
|
|
10171
|
+
const untypedDbFrom = from;
|
|
10172
|
+
const db = {
|
|
10173
|
+
from,
|
|
10174
|
+
select(table, first, second) {
|
|
10175
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
10176
|
+
return untypedDbFrom(table).select(void 0, first);
|
|
10177
|
+
}
|
|
10178
|
+
return untypedDbFrom(table).select(first, second);
|
|
10179
|
+
},
|
|
10180
|
+
insert(table, values, options) {
|
|
10181
|
+
return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
|
|
10182
|
+
},
|
|
10183
|
+
upsert(table, values, options) {
|
|
10184
|
+
return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
|
|
10185
|
+
},
|
|
10186
|
+
update(table, values, options) {
|
|
10187
|
+
return untypedDbFrom(table).update(values, options);
|
|
10188
|
+
},
|
|
10189
|
+
delete(table, options) {
|
|
10190
|
+
return untypedDbFrom(table).delete(options);
|
|
10191
|
+
},
|
|
10192
|
+
rpc,
|
|
10193
|
+
query
|
|
10194
|
+
};
|
|
9716
10195
|
const chat = createChatModule({
|
|
9717
10196
|
baseUrl: config.chatUrl,
|
|
9718
10197
|
apiKey: config.apiKey,
|
|
@@ -9850,6 +10329,7 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9850
10329
|
withOptions: storageWithOptions,
|
|
9851
10330
|
storage: createStorageModule(gateway, {
|
|
9852
10331
|
...config.experimental.storage,
|
|
10332
|
+
...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
|
|
9853
10333
|
...config.storageUrl ? {
|
|
9854
10334
|
baseUrl: config.storageUrl,
|
|
9855
10335
|
stripBasePath: true
|
|
@@ -9860,7 +10340,8 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9860
10340
|
}
|
|
9861
10341
|
return sdkClient;
|
|
9862
10342
|
}
|
|
9863
|
-
function createClient(
|
|
10343
|
+
function createClient(...args) {
|
|
10344
|
+
const [configOrUrl, apiKey, options] = args;
|
|
9864
10345
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
9865
10346
|
return createClientFromInput({
|
|
9866
10347
|
url: configOrUrl,
|
|
@@ -10467,6 +10948,10 @@ async function runSchemaGenerator(options = {}) {
|
|
|
10467
10948
|
}
|
|
10468
10949
|
|
|
10469
10950
|
// src/cli/index.ts
|
|
10951
|
+
function isDebugEnabled() {
|
|
10952
|
+
const value = globalThis.process?.env?.ATHENA_JS_DEBUG;
|
|
10953
|
+
return value === "1" || value === "true";
|
|
10954
|
+
}
|
|
10470
10955
|
function rootUsage() {
|
|
10471
10956
|
return [
|
|
10472
10957
|
"athena-js CLI",
|
|
@@ -10630,7 +11115,61 @@ function extractMissingDatabaseName(message) {
|
|
|
10630
11115
|
function isErrorWithCode(error) {
|
|
10631
11116
|
return typeof error === "object" && error !== null && "code" in error;
|
|
10632
11117
|
}
|
|
11118
|
+
function isNetworkConnectionError(error) {
|
|
11119
|
+
if (!isErrorWithCode(error)) {
|
|
11120
|
+
return false;
|
|
11121
|
+
}
|
|
11122
|
+
const code = typeof error.code === "string" ? error.code : "";
|
|
11123
|
+
if (code === "ECONNRESET" || code === "ECONNREFUSED" || code === "ETIMEDOUT" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "EPIPE" || code === "EHOSTUNREACH" || code === "ENETUNREACH") {
|
|
11124
|
+
return true;
|
|
11125
|
+
}
|
|
11126
|
+
const message = normalizeErrorMessage(error).toLowerCase();
|
|
11127
|
+
return message.includes("econnreset") || message.includes("econnrefused") || message.includes("etimedout") || message.includes("connection terminated") || message.includes("connection refused") || message.includes("timeout expired");
|
|
11128
|
+
}
|
|
11129
|
+
function collectErrorDiagnostics(error) {
|
|
11130
|
+
const lines = [];
|
|
11131
|
+
if (!isErrorWithCode(error) && !(error instanceof Error)) {
|
|
11132
|
+
return lines;
|
|
11133
|
+
}
|
|
11134
|
+
const code = isErrorWithCode(error) && error.code !== void 0 ? String(error.code) : void 0;
|
|
11135
|
+
if (code) {
|
|
11136
|
+
lines.push(` code: ${code}`);
|
|
11137
|
+
}
|
|
11138
|
+
const errno = isErrorWithCode(error) && error.errno !== void 0 ? String(error.errno) : void 0;
|
|
11139
|
+
if (errno) {
|
|
11140
|
+
lines.push(` errno: ${errno}`);
|
|
11141
|
+
}
|
|
11142
|
+
const syscall = isErrorWithCode(error) && typeof error.syscall === "string" ? error.syscall : void 0;
|
|
11143
|
+
if (syscall) {
|
|
11144
|
+
lines.push(` syscall: ${syscall}`);
|
|
11145
|
+
}
|
|
11146
|
+
const address = isErrorWithCode(error) && typeof error.address === "string" ? error.address : void 0;
|
|
11147
|
+
const port = isErrorWithCode(error) && error.port !== void 0 ? String(error.port) : void 0;
|
|
11148
|
+
if (address || port) {
|
|
11149
|
+
lines.push(
|
|
11150
|
+
` remote: ${address ?? "?"}${port ? `:${port}` : ""}`
|
|
11151
|
+
);
|
|
11152
|
+
}
|
|
11153
|
+
const hostname = isErrorWithCode(error) && typeof error.hostname === "string" ? error.hostname : void 0;
|
|
11154
|
+
if (hostname) {
|
|
11155
|
+
lines.push(` hostname: ${hostname}`);
|
|
11156
|
+
}
|
|
11157
|
+
let cause = error instanceof Error ? error.cause : isErrorWithCode(error) ? error.cause : void 0;
|
|
11158
|
+
let depth = 0;
|
|
11159
|
+
while (cause && depth < 4) {
|
|
11160
|
+
const causeMessage = normalizeErrorMessage(cause);
|
|
11161
|
+
const causeCode = isErrorWithCode(cause) && cause.code !== void 0 ? String(cause.code) : void 0;
|
|
11162
|
+
lines.push(
|
|
11163
|
+
` cause[${depth}]: ${causeCode ? `${causeCode} \u2014 ` : ""}${causeMessage}`
|
|
11164
|
+
);
|
|
11165
|
+
cause = cause instanceof Error ? cause.cause : isErrorWithCode(cause) ? cause.cause : void 0;
|
|
11166
|
+
depth += 1;
|
|
11167
|
+
}
|
|
11168
|
+
return lines;
|
|
11169
|
+
}
|
|
10633
11170
|
function formatGeneratorError(error, configPath) {
|
|
11171
|
+
const diagnostics = collectErrorDiagnostics(error);
|
|
11172
|
+
const diagnosticsBlock = diagnostics.length > 0 ? ["", "Diagnostics:", ...diagnostics] : [];
|
|
10634
11173
|
if (isErrorWithCode(error) && error.code === "3D000") {
|
|
10635
11174
|
const message = normalizeErrorMessage(error);
|
|
10636
11175
|
const databaseName = extractMissingDatabaseName(message);
|
|
@@ -10639,15 +11178,58 @@ function formatGeneratorError(error, configPath) {
|
|
|
10639
11178
|
return new Error(
|
|
10640
11179
|
[
|
|
10641
11180
|
`${databaseLabel} (code 3D000).`,
|
|
10642
|
-
`Update provider.connectionString (and provider.database, if set) in ${configLabel}, or create that database before running generate
|
|
11181
|
+
`Update provider.connectionString (and provider.database, if set) in ${configLabel}, or create that database before running generate.`,
|
|
11182
|
+
...diagnosticsBlock,
|
|
11183
|
+
"",
|
|
11184
|
+
"Hint: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"
|
|
11185
|
+
].join("\n")
|
|
11186
|
+
);
|
|
11187
|
+
}
|
|
11188
|
+
if (isNetworkConnectionError(error)) {
|
|
11189
|
+
const message = normalizeErrorMessage(error);
|
|
11190
|
+
const configLabel = configPath ? `config "${configPath}"` : "the resolved athena config";
|
|
11191
|
+
const code = isErrorWithCode(error) && typeof error.code === "string" ? error.code : "network";
|
|
11192
|
+
return new Error(
|
|
11193
|
+
[
|
|
11194
|
+
`Schema introspection failed: database connection was reset or unreachable (${code}: ${message}).`,
|
|
11195
|
+
`The CLI started correctly; generate could not finish talking to Postgres for ${configLabel}.`,
|
|
11196
|
+
...diagnosticsBlock,
|
|
11197
|
+
"",
|
|
11198
|
+
"Check:",
|
|
11199
|
+
" 1. DATABASE_URL / provider.connectionString is reachable from this machine (VPN, Railway proxy, firewall).",
|
|
11200
|
+
' 2. The database is running and accepts connections (try `psql "$DATABASE_URL" -c "select 1"`).',
|
|
11201
|
+
" 3. SSL settings match the host (Railway/public proxy often needs `?sslmode=require`).",
|
|
11202
|
+
" 4. Retry once \u2014 ECONNRESET is often a transient proxy drop mid-introspection.",
|
|
11203
|
+
"",
|
|
11204
|
+
"For a full stack: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"
|
|
10643
11205
|
].join("\n")
|
|
10644
11206
|
);
|
|
10645
11207
|
}
|
|
10646
11208
|
if (error instanceof Error) {
|
|
10647
|
-
|
|
11209
|
+
if (diagnostics.length === 0 && !isDebugEnabled()) {
|
|
11210
|
+
return error;
|
|
11211
|
+
}
|
|
11212
|
+
const base = error.message || normalizeErrorMessage(error);
|
|
11213
|
+
return new Error(
|
|
11214
|
+
[
|
|
11215
|
+
base,
|
|
11216
|
+
...diagnosticsBlock,
|
|
11217
|
+
...isDebugEnabled() && error.stack ? ["", "Stack:", error.stack] : ["", "Hint: ATHENA_JS_DEBUG=1 pnpm exec athena-js generate"]
|
|
11218
|
+
].join("\n")
|
|
11219
|
+
);
|
|
10648
11220
|
}
|
|
10649
11221
|
return new Error(normalizeErrorMessage(error));
|
|
10650
11222
|
}
|
|
11223
|
+
function logCliError(error, errorLog = console.error) {
|
|
11224
|
+
const message = error instanceof Error ? error.message : normalizeErrorMessage(error);
|
|
11225
|
+
errorLog(message);
|
|
11226
|
+
if (isDebugEnabled() && error instanceof Error && error.stack) {
|
|
11227
|
+
const stackOnly = error.stack.startsWith(error.message) ? error.stack.slice(error.message.length).replace(/^\n/, "") : error.stack;
|
|
11228
|
+
if (stackOnly) {
|
|
11229
|
+
errorLog(stackOnly);
|
|
11230
|
+
}
|
|
11231
|
+
}
|
|
11232
|
+
}
|
|
10651
11233
|
function formatSkippedArtifactLine(artifact) {
|
|
10652
11234
|
if (artifact.reason === "protected-existing-file") {
|
|
10653
11235
|
return ` [skip] ${artifact.path} (existing ${artifact.kind} artifacts are protected from overwrite; delete or retarget the file to regenerate it)`;
|
|
@@ -10656,20 +11238,36 @@ function formatSkippedArtifactLine(artifact) {
|
|
|
10656
11238
|
}
|
|
10657
11239
|
async function runCLI(argv, runtime = {}) {
|
|
10658
11240
|
const log = runtime.log ?? console.log;
|
|
11241
|
+
const errorLog = runtime.errorLog ?? console.error;
|
|
10659
11242
|
const runGenerator = runtime.runGenerator ?? runSchemaGenerator;
|
|
10660
|
-
|
|
11243
|
+
let parsed;
|
|
11244
|
+
try {
|
|
11245
|
+
parsed = parseCommand(argv);
|
|
11246
|
+
} catch (error) {
|
|
11247
|
+
logCliError(formatGeneratorError(error), errorLog);
|
|
11248
|
+
process.exitCode = 1;
|
|
11249
|
+
return;
|
|
11250
|
+
}
|
|
10661
11251
|
if (parsed.command === "help") {
|
|
10662
11252
|
log(usage(parsed.topic));
|
|
10663
11253
|
return;
|
|
10664
11254
|
}
|
|
10665
11255
|
let result;
|
|
10666
11256
|
try {
|
|
11257
|
+
if (isDebugEnabled()) {
|
|
11258
|
+
errorLog(
|
|
11259
|
+
`[athena-js] generate starting (dryRun=${parsed.dryRun}${parsed.configPath ? ` config=${parsed.configPath}` : ""})`
|
|
11260
|
+
);
|
|
11261
|
+
}
|
|
10667
11262
|
result = await runGenerator({
|
|
10668
11263
|
configPath: parsed.configPath,
|
|
10669
11264
|
dryRun: parsed.dryRun
|
|
10670
11265
|
});
|
|
10671
11266
|
} catch (error) {
|
|
10672
|
-
|
|
11267
|
+
const formatted = formatGeneratorError(error, parsed.configPath);
|
|
11268
|
+
logCliError(formatted, errorLog);
|
|
11269
|
+
process.exitCode = 1;
|
|
11270
|
+
return;
|
|
10673
11271
|
}
|
|
10674
11272
|
if (parsed.dryRun) {
|
|
10675
11273
|
log(`[dry-run] Generated ${result.files.length} files from ${result.configPath}`);
|
|
@@ -10693,6 +11291,6 @@ async function runCLI(argv, runtime = {}) {
|
|
|
10693
11291
|
}
|
|
10694
11292
|
}
|
|
10695
11293
|
|
|
10696
|
-
export { parseCommand, runCLI, usage };
|
|
11294
|
+
export { logCliError, parseCommand, runCLI, usage };
|
|
10697
11295
|
//# sourceMappingURL=index.js.map
|
|
10698
11296
|
//# sourceMappingURL=index.js.map
|