@xylex-group/athena 2.7.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -18
- package/dist/browser.cjs +2173 -675
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +2167 -676
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +2068 -559
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +2068 -559
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +2815 -945
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +2809 -946
- package/dist/index.js.map +1 -1
- package/dist/{model-form-AKYrgede.d.ts → model-form-Cx3wtvi8.d.ts} +963 -93
- package/dist/{model-form-ehfqLuG7.d.cts → model-form-_ugfOXao.d.cts} +963 -93
- package/dist/{pipeline-BfCWSRYl.d.cts → pipeline-BtD-Uo5X.d.cts} +1 -1
- package/dist/{pipeline-BUsR9XlO.d.ts → pipeline-yCIZNJHE.d.ts} +1 -1
- package/dist/{react-email-BQzmXBDE.d.cts → react-email-CiiSVa9F.d.cts} +121 -10
- package/dist/{react-email-BrVRp80B.d.ts → react-email-WN8UU3AL.d.ts} +121 -10
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/{types-t_TVqnmp.d.ts → types-89EfjLjV.d.cts} +48 -5
- package/dist/{types-BSIsyss1.d.cts → types-C2kiTt6-.d.ts} +48 -5
- package/dist/{types-BsyRW49r.d.cts → types-g8G6J0xE.d.cts} +26 -1
- package/dist/{types-BsyRW49r.d.ts → types-g8G6J0xE.d.ts} +26 -1
- package/package.json +28 -57
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { existsSync, readFileSync } from 'fs';
|
|
2
3
|
import { resolve, dirname, posix } from 'path';
|
|
3
4
|
import { pathToFileURL } from 'url';
|
|
@@ -803,7 +804,7 @@ var getCookieCache = async (request, config) => {
|
|
|
803
804
|
|
|
804
805
|
// package.json
|
|
805
806
|
var package_default = {
|
|
806
|
-
version: "2.
|
|
807
|
+
version: "2.8.2"
|
|
807
808
|
};
|
|
808
809
|
|
|
809
810
|
// src/sdk-version.ts
|
|
@@ -3120,7 +3121,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
3120
3121
|
const details = resultOrError.errorDetails;
|
|
3121
3122
|
const message2 = messageFromUnknownError(resultOrError.error) ?? details?.message ?? `Athena ${context?.operation ?? operationFromDetails(details) ?? "request"} failed`;
|
|
3122
3123
|
const operation = context?.operation ?? operationFromDetails(details);
|
|
3123
|
-
const
|
|
3124
|
+
const table2 = context?.table ?? extractTable(message2);
|
|
3124
3125
|
const constraint = extractConstraint(message2);
|
|
3125
3126
|
const gatewayCode = details?.code ?? gatewayCodeFromUnknownError(resultOrError.error);
|
|
3126
3127
|
const kind2 = classifyKind(resultOrError.status, gatewayCode, message2);
|
|
@@ -3133,7 +3134,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
3133
3134
|
retryable: isRetryable(kind2, resultOrError.status),
|
|
3134
3135
|
status: resultOrError.status,
|
|
3135
3136
|
constraint,
|
|
3136
|
-
table,
|
|
3137
|
+
table: table2,
|
|
3137
3138
|
operation,
|
|
3138
3139
|
message: message2,
|
|
3139
3140
|
raw: resultOrError.raw
|
|
@@ -3142,7 +3143,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
3142
3143
|
if (isAthenaGatewayError(resultOrError)) {
|
|
3143
3144
|
const details = resultOrError.toDetails();
|
|
3144
3145
|
const operation = context?.operation ?? operationFromDetails(details);
|
|
3145
|
-
const
|
|
3146
|
+
const table2 = context?.table ?? extractTable(resultOrError.message);
|
|
3146
3147
|
const constraint = extractConstraint(resultOrError.message);
|
|
3147
3148
|
const kind2 = classifyKind(resultOrError.status, resultOrError.code, resultOrError.message);
|
|
3148
3149
|
const code = toAthenaErrorCode(kind2, resultOrError.status, resultOrError.code);
|
|
@@ -3154,7 +3155,7 @@ function normalizeAthenaError(resultOrError, context) {
|
|
|
3154
3155
|
retryable: isRetryable(kind2, resultOrError.status),
|
|
3155
3156
|
status: resultOrError.status,
|
|
3156
3157
|
constraint,
|
|
3157
|
-
table,
|
|
3158
|
+
table: table2,
|
|
3158
3159
|
operation,
|
|
3159
3160
|
message: resultOrError.message,
|
|
3160
3161
|
raw: resultOrError
|
|
@@ -3350,23 +3351,24 @@ async function withRetry(config, fn) {
|
|
|
3350
3351
|
// src/db/module.ts
|
|
3351
3352
|
function createDbModule(input) {
|
|
3352
3353
|
const db = {
|
|
3353
|
-
from
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3354
|
+
from: input.from,
|
|
3355
|
+
select(table2, first, second) {
|
|
3356
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
3357
|
+
return input.from(table2).select(void 0, first);
|
|
3358
|
+
}
|
|
3359
|
+
return input.from(table2).select(first, second);
|
|
3358
3360
|
},
|
|
3359
|
-
insert(
|
|
3360
|
-
return Array.isArray(values) ? input.from(
|
|
3361
|
+
insert(table2, values, options) {
|
|
3362
|
+
return Array.isArray(values) ? input.from(table2).insert(values, options) : input.from(table2).insert(values, options);
|
|
3361
3363
|
},
|
|
3362
|
-
upsert(
|
|
3363
|
-
return Array.isArray(values) ? input.from(
|
|
3364
|
+
upsert(table2, values, options) {
|
|
3365
|
+
return Array.isArray(values) ? input.from(table2).upsert(values, options) : input.from(table2).upsert(values, options);
|
|
3364
3366
|
},
|
|
3365
|
-
update(
|
|
3366
|
-
return input.from(
|
|
3367
|
+
update(table2, values, options) {
|
|
3368
|
+
return input.from(table2).update(values, options);
|
|
3367
3369
|
},
|
|
3368
|
-
delete(
|
|
3369
|
-
return input.from(
|
|
3370
|
+
delete(table2, options) {
|
|
3371
|
+
return input.from(table2).delete(options);
|
|
3370
3372
|
},
|
|
3371
3373
|
rpc(fn, args, options) {
|
|
3372
3374
|
return input.rpc(fn, args, options);
|
|
@@ -3398,7 +3400,12 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3398
3400
|
content_type: input.content_type ?? source.contentType,
|
|
3399
3401
|
size_bytes: source.sizeBytes,
|
|
3400
3402
|
public: input.public,
|
|
3401
|
-
metadata: input.metadata
|
|
3403
|
+
metadata: input.metadata,
|
|
3404
|
+
server_side_encryption: input.server_side_encryption,
|
|
3405
|
+
sse: input.sse,
|
|
3406
|
+
ssekms_key_id: input.ssekms_key_id,
|
|
3407
|
+
kms_key_id: input.kms_key_id,
|
|
3408
|
+
bucket_key_enabled: input.bucket_key_enabled
|
|
3402
3409
|
}
|
|
3403
3410
|
};
|
|
3404
3411
|
});
|
|
@@ -3409,10 +3416,17 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3409
3416
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
3410
3417
|
const request = uploadRequests[index];
|
|
3411
3418
|
const uploadUrl = uploadUrls[index];
|
|
3412
|
-
const response = await putUploadBody(
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3419
|
+
const response = await putUploadBody(
|
|
3420
|
+
uploadUrl.upload.url,
|
|
3421
|
+
uploadUrl.upload.headers ?? {},
|
|
3422
|
+
request.source,
|
|
3423
|
+
input,
|
|
3424
|
+
options,
|
|
3425
|
+
(progress) => {
|
|
3426
|
+
aggregateLoaded[index] = progress.loaded;
|
|
3427
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
3428
|
+
}
|
|
3429
|
+
);
|
|
3416
3430
|
uploaded.push({
|
|
3417
3431
|
file: uploadUrl.file,
|
|
3418
3432
|
upload: uploadUrl.upload,
|
|
@@ -3515,8 +3529,9 @@ function validateUploadConstraints(sources, input) {
|
|
|
3515
3529
|
}
|
|
3516
3530
|
}
|
|
3517
3531
|
}
|
|
3518
|
-
async function putUploadBody(url, source, input, options, onProgress) {
|
|
3519
|
-
const headers = new Headers(
|
|
3532
|
+
async function putUploadBody(url, uploadHeaders, source, input, options, onProgress) {
|
|
3533
|
+
const headers = new Headers(uploadHeaders);
|
|
3534
|
+
new Headers(input.uploadHeaders).forEach((value, key) => headers.set(key, value));
|
|
3520
3535
|
if (source.contentType && !headers.has("Content-Type")) {
|
|
3521
3536
|
headers.set("Content-Type", source.contentType);
|
|
3522
3537
|
}
|
|
@@ -3841,6 +3856,23 @@ var storageSdkManifest = {
|
|
|
3841
3856
|
responseEnvelope: "athena",
|
|
3842
3857
|
responseType: "StorageFileMutationResponse"
|
|
3843
3858
|
},
|
|
3859
|
+
{
|
|
3860
|
+
name: "postStorageFileVisibility",
|
|
3861
|
+
method: "POST",
|
|
3862
|
+
path: "/storage/files/{file_id}/visibility",
|
|
3863
|
+
pathParams: ["file_id"],
|
|
3864
|
+
requestType: "SetStorageFileVisibilityRequest",
|
|
3865
|
+
responseEnvelope: "athena",
|
|
3866
|
+
responseType: "StorageFileMutationResponse"
|
|
3867
|
+
},
|
|
3868
|
+
{
|
|
3869
|
+
name: "setManyStorageFileVisibility",
|
|
3870
|
+
method: "POST",
|
|
3871
|
+
path: "/storage/files/visibility-many",
|
|
3872
|
+
requestType: "SetManyStorageFileVisibilityRequest",
|
|
3873
|
+
responseEnvelope: "athena",
|
|
3874
|
+
responseType: "StorageFileMutationManyResponse"
|
|
3875
|
+
},
|
|
3844
3876
|
{
|
|
3845
3877
|
name: "deleteStorageFolder",
|
|
3846
3878
|
method: "POST",
|
|
@@ -3856,242 +3888,729 @@ var storageSdkManifest = {
|
|
|
3856
3888
|
requestType: "MoveStorageFolderRequest",
|
|
3857
3889
|
responseEnvelope: "athena",
|
|
3858
3890
|
responseType: "StorageFolderMutationResponse"
|
|
3859
|
-
}
|
|
3860
|
-
]
|
|
3861
|
-
};
|
|
3862
|
-
var AthenaStorageErrorCode = {
|
|
3863
|
-
InvalidUrl: "INVALID_URL",
|
|
3864
|
-
NetworkError: "NETWORK_ERROR",
|
|
3865
|
-
HttpError: "HTTP_ERROR",
|
|
3866
|
-
InvalidJson: "INVALID_JSON",
|
|
3867
|
-
InvalidAthenaEnvelope: "INVALID_ATHENA_ENVELOPE",
|
|
3868
|
-
UnknownError: "UNKNOWN_ERROR"
|
|
3869
|
-
};
|
|
3870
|
-
var AthenaStorageError = class extends Error {
|
|
3871
|
-
code;
|
|
3872
|
-
athenaCode;
|
|
3873
|
-
kind;
|
|
3874
|
-
category;
|
|
3875
|
-
retryable;
|
|
3876
|
-
status;
|
|
3877
|
-
endpoint;
|
|
3878
|
-
method;
|
|
3879
|
-
requestId;
|
|
3880
|
-
hint;
|
|
3881
|
-
causeDetail;
|
|
3882
|
-
raw;
|
|
3883
|
-
normalized;
|
|
3884
|
-
__athenaNormalizedError;
|
|
3885
|
-
constructor(input) {
|
|
3886
|
-
super(input.message, { cause: input.cause });
|
|
3887
|
-
this.name = "AthenaStorageError";
|
|
3888
|
-
this.code = input.code;
|
|
3889
|
-
this.status = input.status;
|
|
3890
|
-
this.endpoint = input.endpoint;
|
|
3891
|
-
this.method = input.method;
|
|
3892
|
-
this.requestId = input.requestId;
|
|
3893
|
-
this.hint = input.hint;
|
|
3894
|
-
this.causeDetail = causeToString(input.cause);
|
|
3895
|
-
this.raw = input.raw ?? null;
|
|
3896
|
-
this.normalized = normalizeStorageErrorInput(input);
|
|
3897
|
-
this.__athenaNormalizedError = this.normalized;
|
|
3898
|
-
this.athenaCode = this.normalized.code;
|
|
3899
|
-
this.kind = this.normalized.kind;
|
|
3900
|
-
this.category = this.normalized.category;
|
|
3901
|
-
this.retryable = this.normalized.retryable;
|
|
3902
|
-
Object.defineProperty(this, "__athenaNormalizedError", {
|
|
3903
|
-
value: this.normalized,
|
|
3904
|
-
enumerable: false,
|
|
3905
|
-
configurable: false,
|
|
3906
|
-
writable: false
|
|
3907
|
-
});
|
|
3908
|
-
}
|
|
3909
|
-
toDetails() {
|
|
3910
|
-
return {
|
|
3911
|
-
code: this.code,
|
|
3912
|
-
athenaCode: this.athenaCode,
|
|
3913
|
-
kind: this.kind,
|
|
3914
|
-
category: this.category,
|
|
3915
|
-
retryable: this.retryable,
|
|
3916
|
-
message: this.message,
|
|
3917
|
-
status: this.status,
|
|
3918
|
-
endpoint: this.endpoint,
|
|
3919
|
-
method: this.method,
|
|
3920
|
-
requestId: this.requestId,
|
|
3921
|
-
hint: this.hint,
|
|
3922
|
-
cause: this.causeDetail,
|
|
3923
|
-
raw: this.raw
|
|
3924
|
-
};
|
|
3925
|
-
}
|
|
3926
|
-
};
|
|
3927
|
-
function isRecord6(value) {
|
|
3928
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3929
|
-
}
|
|
3930
|
-
function causeToString(cause) {
|
|
3931
|
-
if (cause === void 0 || cause === null) return void 0;
|
|
3932
|
-
if (typeof cause === "string") return cause;
|
|
3933
|
-
if (cause instanceof Error && cause.message.trim()) return cause.message.trim();
|
|
3934
|
-
try {
|
|
3935
|
-
return JSON.stringify(cause);
|
|
3936
|
-
} catch {
|
|
3937
|
-
return String(cause);
|
|
3938
|
-
}
|
|
3939
|
-
}
|
|
3940
|
-
function storageGatewayCode(code) {
|
|
3941
|
-
if (code === "INVALID_URL") return "INVALID_URL";
|
|
3942
|
-
if (code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
3943
|
-
if (code === "INVALID_JSON" || code === "INVALID_ATHENA_ENVELOPE") return "INVALID_JSON";
|
|
3944
|
-
if (code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
3945
|
-
return "UNKNOWN_ERROR";
|
|
3946
|
-
}
|
|
3947
|
-
function headerValue(headers, names) {
|
|
3948
|
-
for (const name of names) {
|
|
3949
|
-
const value = headers.get(name);
|
|
3950
|
-
if (value?.trim()) return value.trim();
|
|
3951
|
-
}
|
|
3952
|
-
return void 0;
|
|
3953
|
-
}
|
|
3954
|
-
function storageOperationFromEndpoint(endpoint, method) {
|
|
3955
|
-
const endpointPath = String(endpoint).split("?")[0];
|
|
3956
|
-
for (const candidate of storageSdkManifest.methods) {
|
|
3957
|
-
if (candidate.method !== method) continue;
|
|
3958
|
-
const pattern = `^${candidate.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{[^/]+\\\}/g, "[^/]+")}$`;
|
|
3959
|
-
if (new RegExp(pattern).test(endpointPath)) {
|
|
3960
|
-
return candidate.name;
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
return `storage:${method.toLowerCase()}`;
|
|
3964
|
-
}
|
|
3965
|
-
function normalizeStorageErrorInput(input) {
|
|
3966
|
-
return normalizeAthenaError(
|
|
3891
|
+
},
|
|
3967
3892
|
{
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
},
|
|
3975
|
-
errorDetails: {
|
|
3976
|
-
code: storageGatewayCode(input.code),
|
|
3977
|
-
message: input.message,
|
|
3978
|
-
status: input.status,
|
|
3979
|
-
endpoint: input.endpoint,
|
|
3980
|
-
method: input.method,
|
|
3981
|
-
requestId: input.requestId,
|
|
3982
|
-
hint: input.hint,
|
|
3983
|
-
cause: causeToString(input.cause)
|
|
3984
|
-
},
|
|
3985
|
-
raw: input.raw ?? input.cause ?? null,
|
|
3986
|
-
status: input.status
|
|
3893
|
+
name: "searchStorageFiles",
|
|
3894
|
+
method: "POST",
|
|
3895
|
+
path: "/storage/files/search",
|
|
3896
|
+
requestType: "SearchStorageFilesRequest",
|
|
3897
|
+
responseEnvelope: "athena",
|
|
3898
|
+
responseType: "StorageListFilesResponse"
|
|
3987
3899
|
},
|
|
3988
|
-
{
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
}
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
}
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
}
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
},
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
3900
|
+
{
|
|
3901
|
+
name: "confirmStorageUpload",
|
|
3902
|
+
method: "POST",
|
|
3903
|
+
path: "/storage/files/{file_id}/confirm-upload",
|
|
3904
|
+
pathParams: ["file_id"],
|
|
3905
|
+
requestType: "ConfirmStorageUploadRequest",
|
|
3906
|
+
responseEnvelope: "athena",
|
|
3907
|
+
responseType: "StorageFileMutationResponse"
|
|
3908
|
+
},
|
|
3909
|
+
{
|
|
3910
|
+
name: "uploadStorageFileBinary",
|
|
3911
|
+
method: "PUT",
|
|
3912
|
+
path: "/storage/files/{file_id}/upload",
|
|
3913
|
+
pathParams: ["file_id"],
|
|
3914
|
+
responseEnvelope: "athena",
|
|
3915
|
+
responseType: "StorageFileMutationResponse",
|
|
3916
|
+
binary: true
|
|
3917
|
+
},
|
|
3918
|
+
{
|
|
3919
|
+
name: "copyStorageFile",
|
|
3920
|
+
method: "POST",
|
|
3921
|
+
path: "/storage/files/{file_id}/copy",
|
|
3922
|
+
pathParams: ["file_id"],
|
|
3923
|
+
requestType: "CopyStorageFileRequest",
|
|
3924
|
+
responseEnvelope: "athena",
|
|
3925
|
+
responseType: "StorageFileMutationResponse"
|
|
3926
|
+
},
|
|
3927
|
+
{
|
|
3928
|
+
name: "deleteManyStorageFiles",
|
|
3929
|
+
method: "POST",
|
|
3930
|
+
path: "/storage/files/delete-many",
|
|
3931
|
+
requestType: "DeleteManyStorageFilesRequest",
|
|
3932
|
+
responseEnvelope: "athena",
|
|
3933
|
+
responseType: "StorageFileMutationManyResponse"
|
|
3934
|
+
},
|
|
3935
|
+
{
|
|
3936
|
+
name: "updateManyStorageFiles",
|
|
3937
|
+
method: "POST",
|
|
3938
|
+
path: "/storage/files/update-many",
|
|
3939
|
+
requestType: "UpdateManyStorageFilesRequest",
|
|
3940
|
+
responseEnvelope: "athena",
|
|
3941
|
+
responseType: "StorageFileMutationManyResponse"
|
|
3942
|
+
},
|
|
3943
|
+
{
|
|
3944
|
+
name: "restoreStorageFile",
|
|
3945
|
+
method: "POST",
|
|
3946
|
+
path: "/storage/files/{file_id}/restore",
|
|
3947
|
+
pathParams: ["file_id"],
|
|
3948
|
+
responseEnvelope: "athena",
|
|
3949
|
+
responseType: "StorageFileMutationResponse"
|
|
3950
|
+
},
|
|
3951
|
+
{
|
|
3952
|
+
name: "purgeStorageFile",
|
|
3953
|
+
method: "DELETE",
|
|
3954
|
+
path: "/storage/files/{file_id}/purge",
|
|
3955
|
+
pathParams: ["file_id"],
|
|
3956
|
+
responseEnvelope: "athena",
|
|
3957
|
+
responseType: "StorageFileMutationResponse"
|
|
3958
|
+
},
|
|
3959
|
+
{
|
|
3960
|
+
name: "getStorageFilePublicUrl",
|
|
3961
|
+
method: "GET",
|
|
3962
|
+
path: "/storage/files/{file_id}/public-url",
|
|
3963
|
+
pathParams: ["file_id"],
|
|
3964
|
+
responseEnvelope: "athena",
|
|
3965
|
+
responseType: "Record<string, unknown>"
|
|
3966
|
+
},
|
|
3967
|
+
{
|
|
3968
|
+
name: "getStorageFileProxyUrl",
|
|
3969
|
+
method: "GET",
|
|
3970
|
+
path: "/storage/files/{file_id}/proxy-url",
|
|
3971
|
+
pathParams: ["file_id"],
|
|
3972
|
+
queryParams: ["purpose"],
|
|
3973
|
+
responseEnvelope: "athena",
|
|
3974
|
+
responseType: "Record<string, unknown>"
|
|
3975
|
+
},
|
|
3976
|
+
{
|
|
3977
|
+
name: "listStorageFileVersions",
|
|
3978
|
+
method: "GET",
|
|
3979
|
+
path: "/storage/files/{file_id}/versions",
|
|
3980
|
+
pathParams: ["file_id"],
|
|
3981
|
+
responseEnvelope: "athena",
|
|
3982
|
+
responseType: "Record<string, unknown>"
|
|
3983
|
+
},
|
|
3984
|
+
{
|
|
3985
|
+
name: "restoreStorageFileVersion",
|
|
3986
|
+
method: "POST",
|
|
3987
|
+
path: "/storage/files/{file_id}/versions/{version_id}/restore",
|
|
3988
|
+
pathParams: ["file_id", "version_id"],
|
|
3989
|
+
responseEnvelope: "athena",
|
|
3990
|
+
responseType: "Record<string, unknown>"
|
|
3991
|
+
},
|
|
3992
|
+
{
|
|
3993
|
+
name: "deleteStorageFileVersion",
|
|
3994
|
+
method: "DELETE",
|
|
3995
|
+
path: "/storage/files/{file_id}/versions/{version_id}",
|
|
3996
|
+
pathParams: ["file_id", "version_id"],
|
|
3997
|
+
responseEnvelope: "athena",
|
|
3998
|
+
responseType: "Record<string, unknown>"
|
|
3999
|
+
},
|
|
4000
|
+
{
|
|
4001
|
+
name: "getStorageFileRetention",
|
|
4002
|
+
method: "GET",
|
|
4003
|
+
path: "/storage/files/{file_id}/retention",
|
|
4004
|
+
pathParams: ["file_id"],
|
|
4005
|
+
queryParams: ["version_id"],
|
|
4006
|
+
responseEnvelope: "athena",
|
|
4007
|
+
responseType: "Record<string, unknown>"
|
|
4008
|
+
},
|
|
4009
|
+
{
|
|
4010
|
+
name: "setStorageFileRetention",
|
|
4011
|
+
method: "POST",
|
|
4012
|
+
path: "/storage/files/{file_id}/retention",
|
|
4013
|
+
pathParams: ["file_id"],
|
|
4014
|
+
requestType: "StorageFileRetentionRequest",
|
|
4015
|
+
responseEnvelope: "athena",
|
|
4016
|
+
responseType: "Record<string, unknown>"
|
|
4017
|
+
},
|
|
4018
|
+
{
|
|
4019
|
+
name: "listStorageFolders",
|
|
4020
|
+
method: "POST",
|
|
4021
|
+
path: "/storage/folders/list",
|
|
4022
|
+
requestType: "ListStorageFoldersRequest",
|
|
4023
|
+
responseEnvelope: "athena",
|
|
4024
|
+
responseType: "Record<string, unknown>"
|
|
4025
|
+
},
|
|
4026
|
+
{
|
|
4027
|
+
name: "treeStorageFolders",
|
|
4028
|
+
method: "POST",
|
|
4029
|
+
path: "/storage/folders/tree",
|
|
4030
|
+
requestType: "TreeStorageFoldersRequest",
|
|
4031
|
+
responseEnvelope: "athena",
|
|
4032
|
+
responseType: "Record<string, unknown>"
|
|
4033
|
+
},
|
|
4034
|
+
{
|
|
4035
|
+
name: "listStoragePermissions",
|
|
4036
|
+
method: "POST",
|
|
4037
|
+
path: "/storage/permissions/list",
|
|
4038
|
+
requestType: "StoragePermissionListRequest",
|
|
4039
|
+
responseEnvelope: "athena",
|
|
4040
|
+
responseType: "StoragePermissionListResponse"
|
|
4041
|
+
},
|
|
4042
|
+
{
|
|
4043
|
+
name: "grantStoragePermission",
|
|
4044
|
+
method: "POST",
|
|
4045
|
+
path: "/storage/permissions/grant",
|
|
4046
|
+
requestType: "StoragePermissionGrantRequest",
|
|
4047
|
+
responseEnvelope: "athena",
|
|
4048
|
+
responseType: "Record<string, unknown>"
|
|
4049
|
+
},
|
|
4050
|
+
{
|
|
4051
|
+
name: "revokeStoragePermission",
|
|
4052
|
+
method: "POST",
|
|
4053
|
+
path: "/storage/permissions/revoke",
|
|
4054
|
+
requestType: "StoragePermissionRevokeRequest",
|
|
4055
|
+
responseEnvelope: "athena",
|
|
4056
|
+
responseType: "Record<string, unknown>"
|
|
4057
|
+
},
|
|
4058
|
+
{
|
|
4059
|
+
name: "checkStoragePermission",
|
|
4060
|
+
method: "POST",
|
|
4061
|
+
path: "/storage/permissions/check",
|
|
4062
|
+
requestType: "StoragePermissionCheckRequest",
|
|
4063
|
+
responseEnvelope: "athena",
|
|
4064
|
+
responseType: "StoragePermissionCheckResponse"
|
|
4065
|
+
},
|
|
4066
|
+
{
|
|
4067
|
+
name: "listStorageObjects",
|
|
4068
|
+
method: "POST",
|
|
4069
|
+
path: "/storage/objects",
|
|
4070
|
+
requestType: "StorageListObjectsRequest",
|
|
4071
|
+
responseEnvelope: "athena",
|
|
4072
|
+
responseType: "Record<string, unknown>"
|
|
4073
|
+
},
|
|
4074
|
+
{
|
|
4075
|
+
name: "headStorageObject",
|
|
4076
|
+
method: "POST",
|
|
4077
|
+
path: "/storage/objects/head",
|
|
4078
|
+
requestType: "StorageObjectRequest",
|
|
4079
|
+
responseEnvelope: "athena",
|
|
4080
|
+
responseType: "Record<string, unknown>"
|
|
4081
|
+
},
|
|
4082
|
+
{
|
|
4083
|
+
name: "existsStorageObject",
|
|
4084
|
+
method: "POST",
|
|
4085
|
+
path: "/storage/objects/exists",
|
|
4086
|
+
requestType: "StorageObjectRequest",
|
|
4087
|
+
responseEnvelope: "athena",
|
|
4088
|
+
responseType: "Record<string, unknown>"
|
|
4089
|
+
},
|
|
4090
|
+
{
|
|
4091
|
+
name: "validateStorageObject",
|
|
4092
|
+
method: "POST",
|
|
4093
|
+
path: "/storage/objects/validate",
|
|
4094
|
+
requestType: "StorageObjectValidateRequest",
|
|
4095
|
+
responseEnvelope: "athena",
|
|
4096
|
+
responseType: "Record<string, unknown>"
|
|
4097
|
+
},
|
|
4098
|
+
{
|
|
4099
|
+
name: "updateStorageObject",
|
|
4100
|
+
method: "POST",
|
|
4101
|
+
path: "/storage/objects/update",
|
|
4102
|
+
requestType: "StorageUpdateObjectRequest",
|
|
4103
|
+
responseEnvelope: "athena",
|
|
4104
|
+
responseType: "Record<string, unknown>"
|
|
4105
|
+
},
|
|
4106
|
+
{
|
|
4107
|
+
name: "copyStorageObject",
|
|
4108
|
+
method: "POST",
|
|
4109
|
+
path: "/storage/objects/copy",
|
|
4110
|
+
requestType: "StorageObjectCopyRequest",
|
|
4111
|
+
responseEnvelope: "athena",
|
|
4112
|
+
responseType: "Record<string, unknown>"
|
|
4113
|
+
},
|
|
4114
|
+
{
|
|
4115
|
+
name: "getStorageObjectUrl",
|
|
4116
|
+
method: "POST",
|
|
4117
|
+
path: "/storage/objects/url",
|
|
4118
|
+
requestType: "StorageObjectRequest",
|
|
4119
|
+
responseEnvelope: "athena",
|
|
4120
|
+
responseType: "Record<string, unknown>"
|
|
4121
|
+
},
|
|
4122
|
+
{
|
|
4123
|
+
name: "getStorageObjectPublicUrl",
|
|
4124
|
+
method: "POST",
|
|
4125
|
+
path: "/storage/objects/public-url",
|
|
4126
|
+
requestType: "StorageObjectPublicUrlRequest",
|
|
4127
|
+
responseEnvelope: "athena",
|
|
4128
|
+
responseType: "Record<string, unknown>"
|
|
4129
|
+
},
|
|
4130
|
+
{
|
|
4131
|
+
name: "deleteStorageObject",
|
|
4132
|
+
method: "POST",
|
|
4133
|
+
path: "/storage/objects/delete",
|
|
4134
|
+
requestType: "StorageObjectRequest",
|
|
4135
|
+
responseEnvelope: "athena",
|
|
4136
|
+
responseType: "Record<string, unknown>"
|
|
4137
|
+
},
|
|
4138
|
+
{
|
|
4139
|
+
name: "createStorageObjectUploadUrl",
|
|
4140
|
+
method: "POST",
|
|
4141
|
+
path: "/storage/objects/upload-url",
|
|
4142
|
+
requestType: "StoragePresignUploadRequest",
|
|
4143
|
+
responseEnvelope: "athena",
|
|
4144
|
+
responseType: "Record<string, unknown>"
|
|
4145
|
+
},
|
|
4146
|
+
{
|
|
4147
|
+
name: "createStorageObjectPostPolicy",
|
|
4148
|
+
method: "POST",
|
|
4149
|
+
path: "/storage/objects/post-policy",
|
|
4150
|
+
requestType: "StorageSignedPostPolicyRequest",
|
|
4151
|
+
responseEnvelope: "athena",
|
|
4152
|
+
responseType: "Record<string, unknown>"
|
|
4153
|
+
},
|
|
4154
|
+
{
|
|
4155
|
+
name: "listStorageObjectVersions",
|
|
4156
|
+
method: "POST",
|
|
4157
|
+
path: "/storage/objects/versions",
|
|
4158
|
+
requestType: "StorageObjectVersionListRequest",
|
|
4159
|
+
responseEnvelope: "athena",
|
|
4160
|
+
responseType: "Record<string, unknown>"
|
|
4161
|
+
},
|
|
4162
|
+
{
|
|
4163
|
+
name: "restoreStorageObjectVersion",
|
|
4164
|
+
method: "POST",
|
|
4165
|
+
path: "/storage/objects/versions/restore",
|
|
4166
|
+
requestType: "StorageObjectVersionMutationRequest",
|
|
4167
|
+
responseEnvelope: "athena",
|
|
4168
|
+
responseType: "Record<string, unknown>"
|
|
4169
|
+
},
|
|
4170
|
+
{
|
|
4171
|
+
name: "deleteStorageObjectVersion",
|
|
4172
|
+
method: "POST",
|
|
4173
|
+
path: "/storage/objects/versions/delete",
|
|
4174
|
+
requestType: "StorageObjectVersionMutationRequest",
|
|
4175
|
+
responseEnvelope: "athena",
|
|
4176
|
+
responseType: "Record<string, unknown>"
|
|
4177
|
+
},
|
|
4178
|
+
{
|
|
4179
|
+
name: "createStorageObjectFolder",
|
|
4180
|
+
method: "POST",
|
|
4181
|
+
path: "/storage/objects/folder",
|
|
4182
|
+
requestType: "StorageObjectFolderCreateRequest",
|
|
4183
|
+
responseEnvelope: "athena",
|
|
4184
|
+
responseType: "Record<string, unknown>"
|
|
4185
|
+
},
|
|
4186
|
+
{
|
|
4187
|
+
name: "deleteStorageObjectFolder",
|
|
4188
|
+
method: "POST",
|
|
4189
|
+
path: "/storage/objects/folder/delete",
|
|
4190
|
+
requestType: "StorageObjectFolderDeleteRequest",
|
|
4191
|
+
responseEnvelope: "athena",
|
|
4192
|
+
responseType: "Record<string, unknown>"
|
|
4193
|
+
},
|
|
4194
|
+
{
|
|
4195
|
+
name: "renameStorageObjectFolder",
|
|
4196
|
+
method: "POST",
|
|
4197
|
+
path: "/storage/objects/folder/rename",
|
|
4198
|
+
requestType: "StorageObjectFolderRenameRequest",
|
|
4199
|
+
responseEnvelope: "athena",
|
|
4200
|
+
responseType: "Record<string, unknown>"
|
|
4201
|
+
},
|
|
4202
|
+
{
|
|
4203
|
+
name: "listStorageBuckets",
|
|
4204
|
+
method: "POST",
|
|
4205
|
+
path: "/storage/buckets/list",
|
|
4206
|
+
requestType: "Omit<StorageObjectBaseRequest, 'bucket'>",
|
|
4207
|
+
responseEnvelope: "athena",
|
|
4208
|
+
responseType: "Record<string, unknown>"
|
|
4209
|
+
},
|
|
4210
|
+
{
|
|
4211
|
+
name: "createStorageBucket",
|
|
4212
|
+
method: "POST",
|
|
4213
|
+
path: "/storage/buckets/create",
|
|
4214
|
+
requestType: "StorageObjectBaseRequest",
|
|
4215
|
+
responseEnvelope: "athena",
|
|
4216
|
+
responseType: "Record<string, unknown>"
|
|
4217
|
+
},
|
|
4218
|
+
{
|
|
4219
|
+
name: "deleteStorageBucket",
|
|
4220
|
+
method: "POST",
|
|
4221
|
+
path: "/storage/buckets/delete",
|
|
4222
|
+
requestType: "StorageObjectBaseRequest",
|
|
4223
|
+
responseEnvelope: "athena",
|
|
4224
|
+
responseType: "Record<string, unknown>"
|
|
4225
|
+
},
|
|
4226
|
+
{
|
|
4227
|
+
name: "getStorageBucketLifecycle",
|
|
4228
|
+
method: "POST",
|
|
4229
|
+
path: "/storage/buckets/lifecycle",
|
|
4230
|
+
requestType: "StorageBucketLifecycleRequest",
|
|
4231
|
+
responseEnvelope: "athena",
|
|
4232
|
+
responseType: "Record<string, unknown>"
|
|
4233
|
+
},
|
|
4234
|
+
{
|
|
4235
|
+
name: "setStorageBucketLifecycle",
|
|
4236
|
+
method: "POST",
|
|
4237
|
+
path: "/storage/buckets/lifecycle/set",
|
|
4238
|
+
requestType: "StorageSetBucketLifecycleRequest",
|
|
4239
|
+
responseEnvelope: "athena",
|
|
4240
|
+
responseType: "Record<string, unknown>"
|
|
4241
|
+
},
|
|
4242
|
+
{
|
|
4243
|
+
name: "deleteStorageBucketLifecycle",
|
|
4244
|
+
method: "POST",
|
|
4245
|
+
path: "/storage/buckets/lifecycle/delete",
|
|
4246
|
+
requestType: "StorageBucketLifecycleRequest",
|
|
4247
|
+
responseEnvelope: "athena",
|
|
4248
|
+
responseType: "Record<string, unknown>"
|
|
4249
|
+
},
|
|
4250
|
+
{
|
|
4251
|
+
name: "getStorageBucketPolicy",
|
|
4252
|
+
method: "POST",
|
|
4253
|
+
path: "/storage/buckets/policy",
|
|
4254
|
+
requestType: "StorageBucketPolicyRequest",
|
|
4255
|
+
responseEnvelope: "athena",
|
|
4256
|
+
responseType: "Record<string, unknown>"
|
|
4257
|
+
},
|
|
4258
|
+
{
|
|
4259
|
+
name: "setStorageBucketPolicy",
|
|
4260
|
+
method: "POST",
|
|
4261
|
+
path: "/storage/buckets/policy/set",
|
|
4262
|
+
requestType: "StorageSetBucketPolicyRequest",
|
|
4263
|
+
responseEnvelope: "athena",
|
|
4264
|
+
responseType: "Record<string, unknown>"
|
|
4265
|
+
},
|
|
4266
|
+
{
|
|
4267
|
+
name: "deleteStorageBucketPolicy",
|
|
4268
|
+
method: "POST",
|
|
4269
|
+
path: "/storage/buckets/policy/delete",
|
|
4270
|
+
requestType: "StorageBucketPolicyRequest",
|
|
4271
|
+
responseEnvelope: "athena",
|
|
4272
|
+
responseType: "Record<string, unknown>"
|
|
4273
|
+
},
|
|
4274
|
+
{
|
|
4275
|
+
name: "getStorageBucketPublicAccess",
|
|
4276
|
+
method: "POST",
|
|
4277
|
+
path: "/storage/buckets/public-access",
|
|
4278
|
+
requestType: "StoragePublicAccessBlockRequest",
|
|
4279
|
+
responseEnvelope: "athena",
|
|
4280
|
+
responseType: "Record<string, unknown>"
|
|
4281
|
+
},
|
|
4282
|
+
{
|
|
4283
|
+
name: "setStorageBucketPublicAccess",
|
|
4284
|
+
method: "POST",
|
|
4285
|
+
path: "/storage/buckets/public-access/set",
|
|
4286
|
+
requestType: "StorageSetPublicAccessBlockRequest",
|
|
4287
|
+
responseEnvelope: "athena",
|
|
4288
|
+
responseType: "Record<string, unknown>"
|
|
4289
|
+
},
|
|
4290
|
+
{
|
|
4291
|
+
name: "deleteStorageBucketPublicAccess",
|
|
4292
|
+
method: "POST",
|
|
4293
|
+
path: "/storage/buckets/public-access/delete",
|
|
4294
|
+
requestType: "StoragePublicAccessBlockRequest",
|
|
4295
|
+
responseEnvelope: "athena",
|
|
4296
|
+
responseType: "Record<string, unknown>"
|
|
4297
|
+
},
|
|
4298
|
+
{
|
|
4299
|
+
name: "getStorageBucketCors",
|
|
4300
|
+
method: "POST",
|
|
4301
|
+
path: "/storage/buckets/cors",
|
|
4302
|
+
requestType: "StorageBucketCorsRequest",
|
|
4303
|
+
responseEnvelope: "athena",
|
|
4304
|
+
responseType: "Record<string, unknown>"
|
|
4305
|
+
},
|
|
4306
|
+
{
|
|
4307
|
+
name: "setStorageBucketCors",
|
|
4308
|
+
method: "POST",
|
|
4309
|
+
path: "/storage/buckets/cors/set",
|
|
4310
|
+
requestType: "StorageSetBucketCorsRequest",
|
|
4311
|
+
responseEnvelope: "athena",
|
|
4312
|
+
responseType: "Record<string, unknown>"
|
|
4313
|
+
},
|
|
4314
|
+
{
|
|
4315
|
+
name: "deleteStorageBucketCors",
|
|
4316
|
+
method: "POST",
|
|
4317
|
+
path: "/storage/buckets/cors/delete",
|
|
4318
|
+
requestType: "StorageBucketCorsRequest",
|
|
4319
|
+
responseEnvelope: "athena",
|
|
4320
|
+
responseType: "Record<string, unknown>"
|
|
4321
|
+
},
|
|
4322
|
+
{
|
|
4323
|
+
name: "createStorageMultipartUpload",
|
|
4324
|
+
method: "POST",
|
|
4325
|
+
path: "/storage/multipart/create",
|
|
4326
|
+
requestType: "StorageMultipartCreateRequest",
|
|
4327
|
+
responseEnvelope: "athena",
|
|
4328
|
+
responseType: "Record<string, unknown>"
|
|
4329
|
+
},
|
|
4330
|
+
{
|
|
4331
|
+
name: "signStorageMultipartPart",
|
|
4332
|
+
method: "POST",
|
|
4333
|
+
path: "/storage/multipart/sign-part",
|
|
4334
|
+
requestType: "StorageMultipartSignPartRequest",
|
|
4335
|
+
responseEnvelope: "athena",
|
|
4336
|
+
responseType: "Record<string, unknown>"
|
|
4337
|
+
},
|
|
4338
|
+
{
|
|
4339
|
+
name: "completeStorageMultipartUpload",
|
|
4340
|
+
method: "POST",
|
|
4341
|
+
path: "/storage/multipart/complete",
|
|
4342
|
+
requestType: "StorageMultipartCompleteRequest",
|
|
4343
|
+
responseEnvelope: "athena",
|
|
4344
|
+
responseType: "StorageFileMutationResponse"
|
|
4345
|
+
},
|
|
4346
|
+
{
|
|
4347
|
+
name: "abortStorageMultipartUpload",
|
|
4348
|
+
method: "POST",
|
|
4349
|
+
path: "/storage/multipart/abort",
|
|
4350
|
+
requestType: "StorageMultipartAbortRequest",
|
|
4351
|
+
responseEnvelope: "athena",
|
|
4352
|
+
responseType: "Record<string, unknown>"
|
|
4353
|
+
},
|
|
4354
|
+
{
|
|
4355
|
+
name: "listStorageMultipartParts",
|
|
4356
|
+
method: "POST",
|
|
4357
|
+
path: "/storage/multipart/list-parts",
|
|
4358
|
+
requestType: "StorageMultipartListPartsRequest",
|
|
4359
|
+
responseEnvelope: "athena",
|
|
4360
|
+
responseType: "Record<string, unknown>"
|
|
4361
|
+
},
|
|
4362
|
+
{
|
|
4363
|
+
name: "listStorageAuditEvents",
|
|
4364
|
+
method: "POST",
|
|
4365
|
+
path: "/storage/audit/list",
|
|
4366
|
+
requestType: "StorageAuditQueryRequest",
|
|
4367
|
+
responseEnvelope: "athena",
|
|
4368
|
+
responseType: "StorageAuditListResponse"
|
|
4369
|
+
}
|
|
4370
|
+
]
|
|
4371
|
+
};
|
|
4372
|
+
var AthenaStorageErrorCode = {
|
|
4373
|
+
InvalidUrl: "INVALID_URL",
|
|
4374
|
+
NetworkError: "NETWORK_ERROR",
|
|
4375
|
+
HttpError: "HTTP_ERROR",
|
|
4376
|
+
InvalidJson: "INVALID_JSON",
|
|
4377
|
+
InvalidAthenaEnvelope: "INVALID_ATHENA_ENVELOPE",
|
|
4378
|
+
UnknownError: "UNKNOWN_ERROR"
|
|
4379
|
+
};
|
|
4380
|
+
var AthenaStorageError = class extends Error {
|
|
4381
|
+
code;
|
|
4382
|
+
athenaCode;
|
|
4383
|
+
kind;
|
|
4384
|
+
category;
|
|
4385
|
+
retryable;
|
|
4386
|
+
status;
|
|
4387
|
+
endpoint;
|
|
4388
|
+
method;
|
|
4389
|
+
requestId;
|
|
4390
|
+
hint;
|
|
4391
|
+
causeDetail;
|
|
4392
|
+
raw;
|
|
4393
|
+
normalized;
|
|
4394
|
+
__athenaNormalizedError;
|
|
4395
|
+
constructor(input) {
|
|
4396
|
+
super(input.message, { cause: input.cause });
|
|
4397
|
+
this.name = "AthenaStorageError";
|
|
4398
|
+
this.code = input.code;
|
|
4399
|
+
this.status = input.status;
|
|
4400
|
+
this.endpoint = input.endpoint;
|
|
4401
|
+
this.method = input.method;
|
|
4402
|
+
this.requestId = input.requestId;
|
|
4403
|
+
this.hint = input.hint;
|
|
4404
|
+
this.causeDetail = causeToString(input.cause);
|
|
4405
|
+
this.raw = input.raw ?? null;
|
|
4406
|
+
this.normalized = normalizeStorageErrorInput(input);
|
|
4407
|
+
this.__athenaNormalizedError = this.normalized;
|
|
4408
|
+
this.athenaCode = this.normalized.code;
|
|
4409
|
+
this.kind = this.normalized.kind;
|
|
4410
|
+
this.category = this.normalized.category;
|
|
4411
|
+
this.retryable = this.normalized.retryable;
|
|
4412
|
+
Object.defineProperty(this, "__athenaNormalizedError", {
|
|
4413
|
+
value: this.normalized,
|
|
4414
|
+
enumerable: false,
|
|
4415
|
+
configurable: false,
|
|
4416
|
+
writable: false
|
|
4417
|
+
});
|
|
4418
|
+
}
|
|
4419
|
+
toDetails() {
|
|
4420
|
+
return {
|
|
4421
|
+
code: this.code,
|
|
4422
|
+
athenaCode: this.athenaCode,
|
|
4423
|
+
kind: this.kind,
|
|
4424
|
+
category: this.category,
|
|
4425
|
+
retryable: this.retryable,
|
|
4426
|
+
message: this.message,
|
|
4427
|
+
status: this.status,
|
|
4428
|
+
endpoint: this.endpoint,
|
|
4429
|
+
method: this.method,
|
|
4430
|
+
requestId: this.requestId,
|
|
4431
|
+
hint: this.hint,
|
|
4432
|
+
cause: this.causeDetail,
|
|
4433
|
+
raw: this.raw
|
|
4434
|
+
};
|
|
4435
|
+
}
|
|
4436
|
+
};
|
|
4437
|
+
function isRecord6(value) {
|
|
4438
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4439
|
+
}
|
|
4440
|
+
function causeToString(cause) {
|
|
4441
|
+
if (cause === void 0 || cause === null) return void 0;
|
|
4442
|
+
if (typeof cause === "string") return cause;
|
|
4443
|
+
if (cause instanceof Error && cause.message.trim()) return cause.message.trim();
|
|
4444
|
+
try {
|
|
4445
|
+
return JSON.stringify(cause);
|
|
4446
|
+
} catch {
|
|
4447
|
+
return String(cause);
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
function storageGatewayCode(code) {
|
|
4451
|
+
if (code === "INVALID_URL") return "INVALID_URL";
|
|
4452
|
+
if (code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
4453
|
+
if (code === "INVALID_JSON" || code === "INVALID_ATHENA_ENVELOPE") return "INVALID_JSON";
|
|
4454
|
+
if (code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
4455
|
+
return "UNKNOWN_ERROR";
|
|
4456
|
+
}
|
|
4457
|
+
function headerValue(headers, names) {
|
|
4458
|
+
for (const name of names) {
|
|
4459
|
+
const value = headers.get(name);
|
|
4460
|
+
if (value?.trim()) return value.trim();
|
|
4461
|
+
}
|
|
4462
|
+
return void 0;
|
|
4463
|
+
}
|
|
4464
|
+
function storageOperationFromEndpoint(endpoint, method) {
|
|
4465
|
+
const endpointPath = String(endpoint).split("?")[0];
|
|
4466
|
+
for (const candidate of storageSdkManifest.methods) {
|
|
4467
|
+
if (candidate.method !== method) continue;
|
|
4468
|
+
const pattern = `^${candidate.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{[^/]+\\\}/g, "[^/]+")}$`;
|
|
4469
|
+
if (new RegExp(pattern).test(endpointPath)) {
|
|
4470
|
+
return candidate.name;
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
return `storage:${method.toLowerCase()}`;
|
|
4474
|
+
}
|
|
4475
|
+
function normalizeStorageErrorInput(input) {
|
|
4476
|
+
return normalizeAthenaError(
|
|
4477
|
+
{
|
|
4478
|
+
data: null,
|
|
4479
|
+
error: {
|
|
4480
|
+
message: input.message,
|
|
4481
|
+
gatewayCode: storageGatewayCode(input.code),
|
|
4482
|
+
status: input.status,
|
|
4483
|
+
raw: input.raw ?? input.cause ?? null
|
|
4484
|
+
},
|
|
4485
|
+
errorDetails: {
|
|
4486
|
+
code: storageGatewayCode(input.code),
|
|
4487
|
+
message: input.message,
|
|
4488
|
+
status: input.status,
|
|
4489
|
+
endpoint: input.endpoint,
|
|
4490
|
+
method: input.method,
|
|
4491
|
+
requestId: input.requestId,
|
|
4492
|
+
hint: input.hint,
|
|
4493
|
+
cause: causeToString(input.cause)
|
|
4494
|
+
},
|
|
4495
|
+
raw: input.raw ?? input.cause ?? null,
|
|
4496
|
+
status: input.status
|
|
4497
|
+
},
|
|
4498
|
+
{ operation: storageOperationFromEndpoint(input.endpoint, input.method) }
|
|
4499
|
+
);
|
|
4500
|
+
}
|
|
4501
|
+
function createAthenaStorageError(input) {
|
|
4502
|
+
return new AthenaStorageError(input);
|
|
4503
|
+
}
|
|
4504
|
+
async function notifyStorageError(error, options, runtimeOptions) {
|
|
4505
|
+
const handlers = [runtimeOptions?.onError, options?.onError].filter(
|
|
4506
|
+
(handler) => typeof handler === "function"
|
|
4507
|
+
);
|
|
4508
|
+
for (const handler of handlers) {
|
|
4509
|
+
try {
|
|
4510
|
+
await handler(error);
|
|
4511
|
+
} catch {
|
|
4512
|
+
}
|
|
4513
|
+
}
|
|
4514
|
+
}
|
|
4515
|
+
async function rejectStorageError(input, options, runtimeOptions) {
|
|
4516
|
+
const error = createAthenaStorageError(input);
|
|
4517
|
+
await notifyStorageError(error, options, runtimeOptions);
|
|
4518
|
+
throw error;
|
|
4519
|
+
}
|
|
4520
|
+
function parseResponseBody3(rawText, contentType) {
|
|
4521
|
+
if (!rawText) {
|
|
4522
|
+
return { parsed: null, parseFailed: false };
|
|
4523
|
+
}
|
|
4524
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
4525
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
4526
|
+
if (!looksJson) {
|
|
4527
|
+
return { parsed: rawText, parseFailed: false };
|
|
4528
|
+
}
|
|
4529
|
+
try {
|
|
4530
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
4531
|
+
} catch {
|
|
4532
|
+
return { parsed: rawText, parseFailed: true };
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
function appendQuery(path, query) {
|
|
4536
|
+
if (!query) return path;
|
|
4537
|
+
const params = new URLSearchParams();
|
|
4538
|
+
for (const [key, value] of Object.entries(query)) {
|
|
4539
|
+
if (value === void 0 || value === null) continue;
|
|
4540
|
+
params.set(key, String(value));
|
|
4541
|
+
}
|
|
4542
|
+
const queryText = params.toString();
|
|
4543
|
+
return queryText ? `${path}?${queryText}` : path;
|
|
4544
|
+
}
|
|
4545
|
+
function storagePath(path) {
|
|
4546
|
+
return path;
|
|
4547
|
+
}
|
|
4548
|
+
function resolveStorageEndpointPath(endpoint, runtimeOptions) {
|
|
4549
|
+
if (!runtimeOptions?.stripBasePath) {
|
|
4550
|
+
return endpoint;
|
|
4551
|
+
}
|
|
4552
|
+
const [pathname, queryText] = String(endpoint).split("?", 2);
|
|
4553
|
+
const trimmedPathname = pathname.startsWith("/storage/") ? pathname.slice("/storage".length) : pathname === "/storage" ? "/" : pathname;
|
|
4554
|
+
const resolvedPath = trimmedPathname.startsWith("/") ? trimmedPathname : `/${trimmedPathname}`;
|
|
4555
|
+
return storagePath(queryText ? `${resolvedPath}?${queryText}` : resolvedPath);
|
|
4556
|
+
}
|
|
4557
|
+
function withPathParam(path, name, value) {
|
|
4558
|
+
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
4559
|
+
}
|
|
4560
|
+
function resolveErrorMessage3(payload, fallback) {
|
|
4561
|
+
if (isRecord6(payload)) {
|
|
4562
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
4563
|
+
if (typeof message === "string" && message.trim()) {
|
|
4564
|
+
return message.trim();
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
if (typeof payload === "string" && payload.trim()) {
|
|
4568
|
+
return payload.trim();
|
|
4569
|
+
}
|
|
4570
|
+
return fallback;
|
|
4571
|
+
}
|
|
4572
|
+
function resolveErrorHint2(payload) {
|
|
4573
|
+
if (!isRecord6(payload)) return void 0;
|
|
4574
|
+
const hint = payload.hint ?? payload.suggestion;
|
|
4575
|
+
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
4576
|
+
}
|
|
4577
|
+
function resolveErrorCause(payload) {
|
|
4578
|
+
if (!isRecord6(payload)) return void 0;
|
|
4579
|
+
const cause = payload.cause ?? payload.reason;
|
|
4580
|
+
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
4581
|
+
}
|
|
4582
|
+
function storageCodeFromUnknown(error) {
|
|
4583
|
+
if (isAthenaGatewayError(error)) {
|
|
4584
|
+
if (error.code === "INVALID_URL") return "INVALID_URL";
|
|
4585
|
+
if (error.code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
4586
|
+
if (error.code === "INVALID_JSON") return "INVALID_JSON";
|
|
4587
|
+
if (error.code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
4588
|
+
}
|
|
4589
|
+
return "UNKNOWN_ERROR";
|
|
4590
|
+
}
|
|
4591
|
+
async function callStorageEndpoint(gateway, endpoint, method, envelope, payload, options, runtimeOptions) {
|
|
4592
|
+
let url;
|
|
4593
|
+
let headers;
|
|
4594
|
+
try {
|
|
4595
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
4596
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4597
|
+
headers = gateway.buildHeaders(options);
|
|
4598
|
+
} catch (error) {
|
|
4599
|
+
return rejectStorageError(
|
|
4600
|
+
{
|
|
4601
|
+
code: storageCodeFromUnknown(error),
|
|
4602
|
+
message: error instanceof Error ? error.message : `Athena storage ${method} ${endpoint} failed before sending the request`,
|
|
4603
|
+
status: isAthenaGatewayError(error) ? error.status : 0,
|
|
4604
|
+
endpoint,
|
|
4605
|
+
method,
|
|
4606
|
+
raw: error,
|
|
4607
|
+
requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
|
|
4608
|
+
hint: isAthenaGatewayError(error) ? error.hint : void 0,
|
|
4609
|
+
cause: error
|
|
4610
|
+
},
|
|
4611
|
+
options,
|
|
4612
|
+
runtimeOptions
|
|
4613
|
+
);
|
|
4095
4614
|
}
|
|
4096
4615
|
const requestInit = {
|
|
4097
4616
|
method,
|
|
@@ -4198,8 +4717,8 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
4198
4717
|
let url;
|
|
4199
4718
|
let headers;
|
|
4200
4719
|
try {
|
|
4201
|
-
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4202
|
-
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
4720
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
4721
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4203
4722
|
headers = gateway.buildHeaders(options);
|
|
4204
4723
|
} catch (error) {
|
|
4205
4724
|
return rejectStorageError(
|
|
@@ -4307,7 +4826,7 @@ async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
|
4307
4826
|
return fetch(uploadUrl, init);
|
|
4308
4827
|
}
|
|
4309
4828
|
function attachManagedUpload(upload) {
|
|
4310
|
-
const headers = {};
|
|
4829
|
+
const headers = { ...upload.headers ?? {} };
|
|
4311
4830
|
return {
|
|
4312
4831
|
...upload,
|
|
4313
4832
|
method: "PUT",
|
|
@@ -4353,15 +4872,20 @@ function normalizeUploadUrlRequest(input) {
|
|
|
4353
4872
|
file_id: input.file_id ?? input.fileId,
|
|
4354
4873
|
public: input.public,
|
|
4355
4874
|
visibility: input.visibility,
|
|
4356
|
-
metadata: input.metadata
|
|
4875
|
+
metadata: input.metadata,
|
|
4876
|
+
server_side_encryption: input.server_side_encryption,
|
|
4877
|
+
sse: input.sse,
|
|
4878
|
+
ssekms_key_id: input.ssekms_key_id,
|
|
4879
|
+
kms_key_id: input.kms_key_id,
|
|
4880
|
+
bucket_key_enabled: input.bucket_key_enabled
|
|
4357
4881
|
};
|
|
4358
4882
|
}
|
|
4359
4883
|
async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options, runtimeOptions) {
|
|
4360
4884
|
let url;
|
|
4361
4885
|
let headers;
|
|
4362
4886
|
try {
|
|
4363
|
-
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4364
|
-
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
4887
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
4888
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4365
4889
|
headers = gateway.buildHeaders(options);
|
|
4366
4890
|
} catch (error) {
|
|
4367
4891
|
return rejectStorageError(
|
|
@@ -4485,6 +5009,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4485
5009
|
return parsedBody.parsed.data;
|
|
4486
5010
|
}
|
|
4487
5011
|
function createStorageModule(gateway, runtimeOptions) {
|
|
5012
|
+
const resolvedRuntimeOptions = runtimeOptions;
|
|
4488
5013
|
const callRaw = (path, method, payload, options) => callStorageEndpoint(
|
|
4489
5014
|
gateway,
|
|
4490
5015
|
storagePath(path),
|
|
@@ -4492,7 +5017,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4492
5017
|
"raw",
|
|
4493
5018
|
payload,
|
|
4494
5019
|
options,
|
|
4495
|
-
|
|
5020
|
+
resolvedRuntimeOptions
|
|
4496
5021
|
);
|
|
4497
5022
|
const callAthena2 = (path, method, payload, options) => callStorageEndpoint(
|
|
4498
5023
|
gateway,
|
|
@@ -4501,7 +5026,13 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4501
5026
|
"athena",
|
|
4502
5027
|
payload,
|
|
4503
5028
|
options,
|
|
4504
|
-
|
|
5029
|
+
resolvedRuntimeOptions
|
|
5030
|
+
);
|
|
5031
|
+
const callStorageFileVisibility = (fileId, method, input, options) => callAthena2(
|
|
5032
|
+
withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId),
|
|
5033
|
+
method,
|
|
5034
|
+
input,
|
|
5035
|
+
options
|
|
4505
5036
|
);
|
|
4506
5037
|
const base = {
|
|
4507
5038
|
listStorageCatalogs(options) {
|
|
@@ -4543,7 +5074,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4543
5074
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
4544
5075
|
query
|
|
4545
5076
|
);
|
|
4546
|
-
return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options,
|
|
5077
|
+
return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, resolvedRuntimeOptions);
|
|
4547
5078
|
},
|
|
4548
5079
|
updateStorageFile(fileId, input, options) {
|
|
4549
5080
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "PATCH", input, options);
|
|
@@ -4552,7 +5083,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4552
5083
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "DELETE", void 0, options);
|
|
4553
5084
|
},
|
|
4554
5085
|
setStorageFileVisibility(fileId, input, options) {
|
|
4555
|
-
return
|
|
5086
|
+
return callStorageFileVisibility(fileId, "PATCH", input, options);
|
|
4556
5087
|
},
|
|
4557
5088
|
deleteStorageFolder(input, options) {
|
|
4558
5089
|
return callAthena2("/storage/folders/delete", "POST", input, options);
|
|
@@ -4590,7 +5121,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4590
5121
|
storagePath(withPathParam("/storage/files/{file_id}/upload", "file_id", fileId)),
|
|
4591
5122
|
body,
|
|
4592
5123
|
options,
|
|
4593
|
-
|
|
5124
|
+
resolvedRuntimeOptions
|
|
4594
5125
|
);
|
|
4595
5126
|
},
|
|
4596
5127
|
search(input, options) {
|
|
@@ -4624,13 +5155,62 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4624
5155
|
publicUrl(fileId, options) {
|
|
4625
5156
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
4626
5157
|
},
|
|
5158
|
+
proxyUrl(fileId, query, options) {
|
|
5159
|
+
const path = appendQuery(
|
|
5160
|
+
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
5161
|
+
query
|
|
5162
|
+
);
|
|
5163
|
+
return callAthena2(path, "GET", void 0, options);
|
|
5164
|
+
},
|
|
4627
5165
|
proxy(fileId, query, options) {
|
|
4628
5166
|
return base.getStorageFileProxy(fileId, query, options);
|
|
4629
5167
|
},
|
|
4630
|
-
|
|
5168
|
+
versions(fileId, options) {
|
|
5169
|
+
return callAthena2(withPathParam("/storage/files/{file_id}/versions", "file_id", fileId), "GET", void 0, options);
|
|
5170
|
+
},
|
|
5171
|
+
restoreVersion(fileId, versionId, options) {
|
|
5172
|
+
return callAthena2(
|
|
5173
|
+
withPathParam(
|
|
5174
|
+
withPathParam("/storage/files/{file_id}/versions/{version_id}/restore", "file_id", fileId),
|
|
5175
|
+
"version_id",
|
|
5176
|
+
versionId
|
|
5177
|
+
),
|
|
5178
|
+
"POST",
|
|
5179
|
+
{},
|
|
5180
|
+
options
|
|
5181
|
+
);
|
|
5182
|
+
},
|
|
5183
|
+
deleteVersion(fileId, versionId, options) {
|
|
5184
|
+
return callAthena2(
|
|
5185
|
+
withPathParam(
|
|
5186
|
+
withPathParam("/storage/files/{file_id}/versions/{version_id}", "file_id", fileId),
|
|
5187
|
+
"version_id",
|
|
5188
|
+
versionId
|
|
5189
|
+
),
|
|
5190
|
+
"DELETE",
|
|
5191
|
+
void 0,
|
|
5192
|
+
options
|
|
5193
|
+
);
|
|
5194
|
+
},
|
|
5195
|
+
retention: {
|
|
5196
|
+
get(fileId, query, options) {
|
|
5197
|
+
const path = appendQuery(
|
|
5198
|
+
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
5199
|
+
query
|
|
5200
|
+
);
|
|
5201
|
+
return callAthena2(path, "GET", void 0, options);
|
|
5202
|
+
},
|
|
4631
5203
|
set(fileId, input, options) {
|
|
5204
|
+
return callAthena2(withPathParam("/storage/files/{file_id}/retention", "file_id", fileId), "POST", input, options);
|
|
5205
|
+
}
|
|
5206
|
+
},
|
|
5207
|
+
visibility: {
|
|
5208
|
+
update(fileId, input, options) {
|
|
4632
5209
|
return base.setStorageFileVisibility(fileId, input, options);
|
|
4633
5210
|
},
|
|
5211
|
+
set(fileId, input, options) {
|
|
5212
|
+
return callStorageFileVisibility(fileId, "POST", input, options);
|
|
5213
|
+
},
|
|
4634
5214
|
setMany(input, options) {
|
|
4635
5215
|
return callAthena2("/storage/files/visibility-many", "POST", input, options);
|
|
4636
5216
|
}
|
|
@@ -4725,6 +5305,18 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4725
5305
|
uploadUrl(input, options) {
|
|
4726
5306
|
return callAthena2("/storage/objects/upload-url", "POST", input, options);
|
|
4727
5307
|
},
|
|
5308
|
+
versions(input, options) {
|
|
5309
|
+
return callAthena2("/storage/objects/versions", "POST", input, options);
|
|
5310
|
+
},
|
|
5311
|
+
restoreVersion(input, options) {
|
|
5312
|
+
return callAthena2("/storage/objects/versions/restore", "POST", input, options);
|
|
5313
|
+
},
|
|
5314
|
+
deleteVersion(input, options) {
|
|
5315
|
+
return callAthena2("/storage/objects/versions/delete", "POST", input, options);
|
|
5316
|
+
},
|
|
5317
|
+
postPolicy(input, options) {
|
|
5318
|
+
return callAthena2("/storage/objects/post-policy", "POST", input, options);
|
|
5319
|
+
},
|
|
4728
5320
|
folder: objectFolder
|
|
4729
5321
|
};
|
|
4730
5322
|
const bucket = {
|
|
@@ -4737,6 +5329,39 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4737
5329
|
delete(input, options) {
|
|
4738
5330
|
return callAthena2("/storage/buckets/delete", "POST", input, options);
|
|
4739
5331
|
},
|
|
5332
|
+
lifecycle: {
|
|
5333
|
+
get(input, options) {
|
|
5334
|
+
return callAthena2("/storage/buckets/lifecycle", "POST", input, options);
|
|
5335
|
+
},
|
|
5336
|
+
set(input, options) {
|
|
5337
|
+
return callAthena2("/storage/buckets/lifecycle/set", "POST", input, options);
|
|
5338
|
+
},
|
|
5339
|
+
delete(input, options) {
|
|
5340
|
+
return callAthena2("/storage/buckets/lifecycle/delete", "POST", input, options);
|
|
5341
|
+
}
|
|
5342
|
+
},
|
|
5343
|
+
policy: {
|
|
5344
|
+
get(input, options) {
|
|
5345
|
+
return callAthena2("/storage/buckets/policy", "POST", input, options);
|
|
5346
|
+
},
|
|
5347
|
+
set(input, options) {
|
|
5348
|
+
return callAthena2("/storage/buckets/policy/set", "POST", input, options);
|
|
5349
|
+
},
|
|
5350
|
+
delete(input, options) {
|
|
5351
|
+
return callAthena2("/storage/buckets/policy/delete", "POST", input, options);
|
|
5352
|
+
}
|
|
5353
|
+
},
|
|
5354
|
+
publicAccess: {
|
|
5355
|
+
get(input, options) {
|
|
5356
|
+
return callAthena2("/storage/buckets/public-access", "POST", input, options);
|
|
5357
|
+
},
|
|
5358
|
+
set(input, options) {
|
|
5359
|
+
return callAthena2("/storage/buckets/public-access/set", "POST", input, options);
|
|
5360
|
+
},
|
|
5361
|
+
delete(input, options) {
|
|
5362
|
+
return callAthena2("/storage/buckets/public-access/delete", "POST", input, options);
|
|
5363
|
+
}
|
|
5364
|
+
},
|
|
4740
5365
|
cors: {
|
|
4741
5366
|
get(input, options) {
|
|
4742
5367
|
return callAthena2("/storage/buckets/cors", "POST", input, options);
|
|
@@ -4748,42 +5373,212 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4748
5373
|
return callAthena2("/storage/buckets/cors/delete", "POST", input, options);
|
|
4749
5374
|
}
|
|
4750
5375
|
}
|
|
4751
|
-
};
|
|
4752
|
-
const multipart = {
|
|
4753
|
-
create(input, options) {
|
|
4754
|
-
return callAthena2("/storage/multipart/create", "POST", input, options);
|
|
4755
|
-
},
|
|
4756
|
-
signPart(input, options) {
|
|
4757
|
-
return callAthena2("/storage/multipart/sign-part", "POST", input, options);
|
|
4758
|
-
},
|
|
4759
|
-
complete(input, options) {
|
|
4760
|
-
return callAthena2("/storage/multipart/complete", "POST", input, options);
|
|
4761
|
-
},
|
|
4762
|
-
abort(input, options) {
|
|
4763
|
-
return callAthena2("/storage/multipart/abort", "POST", input, options);
|
|
4764
|
-
},
|
|
4765
|
-
listParts(input, options) {
|
|
4766
|
-
return callAthena2("/storage/multipart/list-parts", "POST", input, options);
|
|
5376
|
+
};
|
|
5377
|
+
const multipart = {
|
|
5378
|
+
create(input, options) {
|
|
5379
|
+
return callAthena2("/storage/multipart/create", "POST", input, options);
|
|
5380
|
+
},
|
|
5381
|
+
signPart(input, options) {
|
|
5382
|
+
return callAthena2("/storage/multipart/sign-part", "POST", input, options);
|
|
5383
|
+
},
|
|
5384
|
+
complete(input, options) {
|
|
5385
|
+
return callAthena2("/storage/multipart/complete", "POST", input, options);
|
|
5386
|
+
},
|
|
5387
|
+
abort(input, options) {
|
|
5388
|
+
return callAthena2("/storage/multipart/abort", "POST", input, options);
|
|
5389
|
+
},
|
|
5390
|
+
listParts(input, options) {
|
|
5391
|
+
return callAthena2("/storage/multipart/list-parts", "POST", input, options);
|
|
5392
|
+
}
|
|
5393
|
+
};
|
|
5394
|
+
const audit = {
|
|
5395
|
+
list(input, options) {
|
|
5396
|
+
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
5397
|
+
}
|
|
5398
|
+
};
|
|
5399
|
+
return {
|
|
5400
|
+
...base,
|
|
5401
|
+
credentials,
|
|
5402
|
+
catalog,
|
|
5403
|
+
file,
|
|
5404
|
+
folder,
|
|
5405
|
+
permission,
|
|
5406
|
+
object,
|
|
5407
|
+
bucket,
|
|
5408
|
+
multipart,
|
|
5409
|
+
audit,
|
|
5410
|
+
delete: file.delete
|
|
5411
|
+
};
|
|
5412
|
+
}
|
|
5413
|
+
|
|
5414
|
+
// src/client-builder.ts
|
|
5415
|
+
var DEFAULT_BACKEND = { type: "athena" };
|
|
5416
|
+
function toBackendConfig(value) {
|
|
5417
|
+
if (!value) return DEFAULT_BACKEND;
|
|
5418
|
+
return typeof value === "string" ? { type: value } : value;
|
|
5419
|
+
}
|
|
5420
|
+
function mergeHeaders(current, next) {
|
|
5421
|
+
return {
|
|
5422
|
+
...current ?? {},
|
|
5423
|
+
...next
|
|
5424
|
+
};
|
|
5425
|
+
}
|
|
5426
|
+
function mergeAuthClientConfig(current, next) {
|
|
5427
|
+
const merged = {
|
|
5428
|
+
...current ?? {},
|
|
5429
|
+
...next
|
|
5430
|
+
};
|
|
5431
|
+
if (current?.headers || next.headers) {
|
|
5432
|
+
merged.headers = mergeHeaders(current?.headers, next.headers ?? {});
|
|
5433
|
+
}
|
|
5434
|
+
return merged;
|
|
5435
|
+
}
|
|
5436
|
+
function mergeExperimentalOptions(current, next) {
|
|
5437
|
+
const merged = {
|
|
5438
|
+
...current ?? {},
|
|
5439
|
+
...next
|
|
5440
|
+
};
|
|
5441
|
+
if (current?.traceQueries && typeof current.traceQueries === "object" && next.traceQueries && typeof next.traceQueries === "object") {
|
|
5442
|
+
merged.traceQueries = {
|
|
5443
|
+
...current.traceQueries,
|
|
5444
|
+
...next.traceQueries
|
|
5445
|
+
};
|
|
5446
|
+
}
|
|
5447
|
+
if (current?.storage || next.storage) {
|
|
5448
|
+
merged.storage = {
|
|
5449
|
+
...current?.storage ?? {},
|
|
5450
|
+
...next.storage ?? {}
|
|
5451
|
+
};
|
|
5452
|
+
}
|
|
5453
|
+
return merged;
|
|
5454
|
+
}
|
|
5455
|
+
function resolveBuilderReturn(builder, storageEnabled, strictEnabled) {
|
|
5456
|
+
return builder;
|
|
5457
|
+
}
|
|
5458
|
+
var AthenaClientBuilderImpl = class {
|
|
5459
|
+
constructor(buildClient) {
|
|
5460
|
+
this.buildClient = buildClient;
|
|
5461
|
+
}
|
|
5462
|
+
rootUrl;
|
|
5463
|
+
apiKey;
|
|
5464
|
+
backendConfig = DEFAULT_BACKEND;
|
|
5465
|
+
clientName;
|
|
5466
|
+
defaultHeaders;
|
|
5467
|
+
authConfig;
|
|
5468
|
+
dbUrlOverride;
|
|
5469
|
+
gatewayUrlOverride;
|
|
5470
|
+
authUrlOverride;
|
|
5471
|
+
storageUrlOverride;
|
|
5472
|
+
experimentalOptions;
|
|
5473
|
+
url(url) {
|
|
5474
|
+
this.rootUrl = url;
|
|
5475
|
+
return this;
|
|
5476
|
+
}
|
|
5477
|
+
key(apiKey) {
|
|
5478
|
+
this.apiKey = apiKey;
|
|
5479
|
+
return this;
|
|
5480
|
+
}
|
|
5481
|
+
backend(backend) {
|
|
5482
|
+
this.backendConfig = toBackendConfig(backend);
|
|
5483
|
+
return this;
|
|
5484
|
+
}
|
|
5485
|
+
client(clientName) {
|
|
5486
|
+
this.clientName = clientName;
|
|
5487
|
+
return this;
|
|
5488
|
+
}
|
|
5489
|
+
headers(headers) {
|
|
5490
|
+
this.defaultHeaders = headers;
|
|
5491
|
+
return this;
|
|
5492
|
+
}
|
|
5493
|
+
auth(config) {
|
|
5494
|
+
this.authConfig = mergeAuthClientConfig(this.authConfig, config);
|
|
5495
|
+
return this;
|
|
5496
|
+
}
|
|
5497
|
+
experimental(options) {
|
|
5498
|
+
this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options);
|
|
5499
|
+
if (options.athenaStorageBackend && options.typecheckColumns) {
|
|
5500
|
+
return resolveBuilderReturn(this);
|
|
5501
|
+
}
|
|
5502
|
+
if (options.athenaStorageBackend) {
|
|
5503
|
+
return resolveBuilderReturn(this);
|
|
5504
|
+
}
|
|
5505
|
+
if (options.typecheckColumns) {
|
|
5506
|
+
return resolveBuilderReturn(this);
|
|
5507
|
+
}
|
|
5508
|
+
return this;
|
|
5509
|
+
}
|
|
5510
|
+
options(options) {
|
|
5511
|
+
if (options.client !== void 0) {
|
|
5512
|
+
this.clientName = options.client;
|
|
5513
|
+
}
|
|
5514
|
+
if (options.backend !== void 0) {
|
|
5515
|
+
this.backendConfig = toBackendConfig(options.backend);
|
|
5516
|
+
}
|
|
5517
|
+
if (options.headers !== void 0) {
|
|
5518
|
+
this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
|
|
5519
|
+
}
|
|
5520
|
+
if (options.auth !== void 0) {
|
|
5521
|
+
this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
|
|
4767
5522
|
}
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
list(input, options) {
|
|
4771
|
-
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
5523
|
+
if (options.db?.url !== void 0 && options.db.url !== null) {
|
|
5524
|
+
this.dbUrlOverride = options.db.url;
|
|
4772
5525
|
}
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
5526
|
+
if (options.gateway?.url !== void 0 && options.gateway.url !== null) {
|
|
5527
|
+
this.gatewayUrlOverride = options.gateway.url;
|
|
5528
|
+
}
|
|
5529
|
+
if (options.dbUrl !== void 0 && options.dbUrl !== null) {
|
|
5530
|
+
this.dbUrlOverride = options.dbUrl;
|
|
5531
|
+
}
|
|
5532
|
+
if (options.gatewayUrl !== void 0 && options.gatewayUrl !== null) {
|
|
5533
|
+
this.gatewayUrlOverride = options.gatewayUrl;
|
|
5534
|
+
}
|
|
5535
|
+
if (options.authUrl !== void 0 && options.authUrl !== null) {
|
|
5536
|
+
this.authUrlOverride = options.authUrl;
|
|
5537
|
+
}
|
|
5538
|
+
if (options.storage?.url !== void 0 && options.storage.url !== null) {
|
|
5539
|
+
this.storageUrlOverride = options.storage.url;
|
|
5540
|
+
}
|
|
5541
|
+
if (options.storageUrl !== void 0 && options.storageUrl !== null) {
|
|
5542
|
+
this.storageUrlOverride = options.storageUrl;
|
|
5543
|
+
}
|
|
5544
|
+
if (options.experimental !== void 0) {
|
|
5545
|
+
this.experimentalOptions = mergeExperimentalOptions(this.experimentalOptions, options.experimental);
|
|
5546
|
+
}
|
|
5547
|
+
if (options.experimental?.athenaStorageBackend && options.experimental.typecheckColumns) {
|
|
5548
|
+
return resolveBuilderReturn(this);
|
|
5549
|
+
}
|
|
5550
|
+
if (options.experimental?.athenaStorageBackend) {
|
|
5551
|
+
return resolveBuilderReturn(this);
|
|
5552
|
+
}
|
|
5553
|
+
if (options.experimental?.typecheckColumns) {
|
|
5554
|
+
return resolveBuilderReturn(this);
|
|
5555
|
+
}
|
|
5556
|
+
return this;
|
|
5557
|
+
}
|
|
5558
|
+
build() {
|
|
5559
|
+
if (!this.rootUrl && !this.dbUrlOverride && !this.gatewayUrlOverride || !this.apiKey) {
|
|
5560
|
+
throw new Error(
|
|
5561
|
+
"AthenaClient requires key plus either .url() or a db/gateway override before .build()"
|
|
5562
|
+
);
|
|
5563
|
+
}
|
|
5564
|
+
return this.buildClient({
|
|
5565
|
+
url: this.rootUrl,
|
|
5566
|
+
key: this.apiKey,
|
|
5567
|
+
client: this.clientName,
|
|
5568
|
+
backend: this.backendConfig,
|
|
5569
|
+
headers: this.defaultHeaders,
|
|
5570
|
+
db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
|
|
5571
|
+
gateway: this.gatewayUrlOverride ? { url: this.gatewayUrlOverride } : void 0,
|
|
5572
|
+
auth: this.authConfig,
|
|
5573
|
+
authUrl: this.authUrlOverride,
|
|
5574
|
+
storage: this.storageUrlOverride ? { url: this.storageUrlOverride } : void 0,
|
|
5575
|
+
storageUrl: this.storageUrlOverride,
|
|
5576
|
+
experimental: this.experimentalOptions
|
|
5577
|
+
});
|
|
5578
|
+
}
|
|
5579
|
+
};
|
|
5580
|
+
function createAthenaClientBuilder(buildClient) {
|
|
5581
|
+
return new AthenaClientBuilderImpl(buildClient);
|
|
4787
5582
|
}
|
|
4788
5583
|
|
|
4789
5584
|
// src/query-ast.ts
|
|
@@ -5396,32 +6191,455 @@ function createSelectTransportPlan(input) {
|
|
|
5396
6191
|
count: input.options?.count,
|
|
5397
6192
|
head: input.options?.head
|
|
5398
6193
|
},
|
|
5399
|
-
debug: {
|
|
5400
|
-
columns: input.columns,
|
|
5401
|
-
conditions,
|
|
5402
|
-
limit: input.state.limit,
|
|
5403
|
-
offset: input.state.offset,
|
|
5404
|
-
currentPage: input.state.currentPage,
|
|
5405
|
-
pageSize: input.state.pageSize,
|
|
5406
|
-
order: input.state.order
|
|
6194
|
+
debug: {
|
|
6195
|
+
columns: input.columns,
|
|
6196
|
+
conditions,
|
|
6197
|
+
limit: input.state.limit,
|
|
6198
|
+
offset: input.state.offset,
|
|
6199
|
+
currentPage: input.state.currentPage,
|
|
6200
|
+
pageSize: input.state.pageSize,
|
|
6201
|
+
order: input.state.order
|
|
6202
|
+
}
|
|
6203
|
+
};
|
|
6204
|
+
}
|
|
6205
|
+
|
|
6206
|
+
// src/query-debug-ast.ts
|
|
6207
|
+
var ATHENA_DEBUG_AST_KEY = "__athenaDebugAst";
|
|
6208
|
+
function cloneConditions(conditions) {
|
|
6209
|
+
return conditions.map((condition) => ({ ...condition }));
|
|
6210
|
+
}
|
|
6211
|
+
function cloneTableBuilderStateAst(state) {
|
|
6212
|
+
return {
|
|
6213
|
+
conditions: cloneConditions(state.conditions),
|
|
6214
|
+
limit: state.limit,
|
|
6215
|
+
offset: state.offset,
|
|
6216
|
+
order: state.order ? { ...state.order } : void 0,
|
|
6217
|
+
currentPage: state.currentPage,
|
|
6218
|
+
pageSize: state.pageSize,
|
|
6219
|
+
totalPages: state.totalPages
|
|
6220
|
+
};
|
|
6221
|
+
}
|
|
6222
|
+
function cloneRpcBuilderStateAst(state) {
|
|
6223
|
+
return {
|
|
6224
|
+
filters: state.filters.map((filter) => ({ ...filter })),
|
|
6225
|
+
limit: state.limit,
|
|
6226
|
+
offset: state.offset,
|
|
6227
|
+
order: state.order ? { ...state.order } : void 0
|
|
6228
|
+
};
|
|
6229
|
+
}
|
|
6230
|
+
function toSelectTransportAst(plan) {
|
|
6231
|
+
if (plan.kind === "query") {
|
|
6232
|
+
return {
|
|
6233
|
+
mode: "typed-query",
|
|
6234
|
+
endpoint: "/gateway/query",
|
|
6235
|
+
payload: plan.payload
|
|
6236
|
+
};
|
|
6237
|
+
}
|
|
6238
|
+
return {
|
|
6239
|
+
mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
|
|
6240
|
+
endpoint: "/gateway/fetch",
|
|
6241
|
+
payload: plan.payload
|
|
6242
|
+
};
|
|
6243
|
+
}
|
|
6244
|
+
function resolveDebugTableName(tableName) {
|
|
6245
|
+
return tableName ?? "__unknown_table__";
|
|
6246
|
+
}
|
|
6247
|
+
function buildSelectDebugAst(input) {
|
|
6248
|
+
return {
|
|
6249
|
+
version: 1,
|
|
6250
|
+
kind: "select",
|
|
6251
|
+
tableName: input.tableName,
|
|
6252
|
+
input: {
|
|
6253
|
+
columns: input.columns,
|
|
6254
|
+
state: cloneTableBuilderStateAst(input.state)
|
|
6255
|
+
},
|
|
6256
|
+
transport: toSelectTransportAst(input.plan)
|
|
6257
|
+
};
|
|
6258
|
+
}
|
|
6259
|
+
function buildFindManyCompiledDebugAst(input) {
|
|
6260
|
+
return {
|
|
6261
|
+
version: 1,
|
|
6262
|
+
kind: "findMany",
|
|
6263
|
+
tableName: input.tableName,
|
|
6264
|
+
input: {
|
|
6265
|
+
select: input.options.select,
|
|
6266
|
+
where: input.options.where,
|
|
6267
|
+
orderBy: input.options.orderBy,
|
|
6268
|
+
limit: input.options.limit
|
|
6269
|
+
},
|
|
6270
|
+
compiled: {
|
|
6271
|
+
columns: input.compiledColumns,
|
|
6272
|
+
baseState: cloneTableBuilderStateAst(input.baseState),
|
|
6273
|
+
executionState: cloneTableBuilderStateAst(input.executionState)
|
|
6274
|
+
},
|
|
6275
|
+
transport: planToFindManyTransport(input.plan)
|
|
6276
|
+
};
|
|
6277
|
+
}
|
|
6278
|
+
function buildFindManyDirectDebugAst(input) {
|
|
6279
|
+
return {
|
|
6280
|
+
version: 1,
|
|
6281
|
+
kind: "findMany",
|
|
6282
|
+
tableName: input.tableName,
|
|
6283
|
+
input: {
|
|
6284
|
+
select: input.options.select,
|
|
6285
|
+
where: input.options.where,
|
|
6286
|
+
orderBy: input.options.orderBy,
|
|
6287
|
+
limit: input.options.limit
|
|
6288
|
+
},
|
|
6289
|
+
compiled: {
|
|
6290
|
+
columns: input.compiledColumns,
|
|
6291
|
+
baseState: cloneTableBuilderStateAst(input.baseState),
|
|
6292
|
+
executionState: cloneTableBuilderStateAst(input.executionState)
|
|
6293
|
+
},
|
|
6294
|
+
transport: {
|
|
6295
|
+
mode: "direct-ast-fetch",
|
|
6296
|
+
endpoint: "/gateway/fetch",
|
|
6297
|
+
payload: input.payload
|
|
6298
|
+
}
|
|
6299
|
+
};
|
|
6300
|
+
}
|
|
6301
|
+
function planToFindManyTransport(plan) {
|
|
6302
|
+
if (plan.kind === "query") {
|
|
6303
|
+
return {
|
|
6304
|
+
mode: "compiled-query",
|
|
6305
|
+
endpoint: "/gateway/query",
|
|
6306
|
+
payload: plan.payload
|
|
6307
|
+
};
|
|
6308
|
+
}
|
|
6309
|
+
return {
|
|
6310
|
+
mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
|
|
6311
|
+
endpoint: "/gateway/fetch",
|
|
6312
|
+
payload: plan.payload
|
|
6313
|
+
};
|
|
6314
|
+
}
|
|
6315
|
+
function buildInsertDebugAst(payload) {
|
|
6316
|
+
return {
|
|
6317
|
+
version: 1,
|
|
6318
|
+
kind: "insert",
|
|
6319
|
+
tableName: payload.table_name,
|
|
6320
|
+
input: {
|
|
6321
|
+
values: payload.insert_body,
|
|
6322
|
+
returning: payload.columns,
|
|
6323
|
+
count: payload.count,
|
|
6324
|
+
head: payload.head,
|
|
6325
|
+
defaultToNull: payload.default_to_null
|
|
6326
|
+
},
|
|
6327
|
+
transport: {
|
|
6328
|
+
mode: "insert",
|
|
6329
|
+
endpoint: "/gateway/insert",
|
|
6330
|
+
payload
|
|
6331
|
+
}
|
|
6332
|
+
};
|
|
6333
|
+
}
|
|
6334
|
+
function buildUpsertDebugAst(payload) {
|
|
6335
|
+
return {
|
|
6336
|
+
version: 1,
|
|
6337
|
+
kind: "upsert",
|
|
6338
|
+
tableName: payload.table_name,
|
|
6339
|
+
input: {
|
|
6340
|
+
values: payload.insert_body,
|
|
6341
|
+
updateBody: payload.update_body,
|
|
6342
|
+
onConflict: payload.on_conflict,
|
|
6343
|
+
returning: payload.columns,
|
|
6344
|
+
count: payload.count,
|
|
6345
|
+
head: payload.head,
|
|
6346
|
+
defaultToNull: payload.default_to_null
|
|
6347
|
+
},
|
|
6348
|
+
transport: {
|
|
6349
|
+
mode: "upsert",
|
|
6350
|
+
endpoint: "/gateway/insert",
|
|
6351
|
+
payload
|
|
6352
|
+
}
|
|
6353
|
+
};
|
|
6354
|
+
}
|
|
6355
|
+
function buildUpdateDebugAst(input) {
|
|
6356
|
+
return {
|
|
6357
|
+
version: 1,
|
|
6358
|
+
kind: "update",
|
|
6359
|
+
tableName: resolveDebugTableName(input.payload.table_name),
|
|
6360
|
+
input: {
|
|
6361
|
+
values: input.payload.set,
|
|
6362
|
+
state: cloneTableBuilderStateAst(input.state),
|
|
6363
|
+
returning: input.payload.columns
|
|
6364
|
+
},
|
|
6365
|
+
transport: {
|
|
6366
|
+
mode: "update",
|
|
6367
|
+
endpoint: "/gateway/update",
|
|
6368
|
+
payload: input.payload
|
|
6369
|
+
}
|
|
6370
|
+
};
|
|
6371
|
+
}
|
|
6372
|
+
function buildDeleteDebugAst(input) {
|
|
6373
|
+
return {
|
|
6374
|
+
version: 1,
|
|
6375
|
+
kind: "delete",
|
|
6376
|
+
tableName: input.payload.table_name,
|
|
6377
|
+
input: {
|
|
6378
|
+
resourceId: input.payload.resource_id,
|
|
6379
|
+
state: cloneTableBuilderStateAst(input.state),
|
|
6380
|
+
returning: input.payload.columns
|
|
6381
|
+
},
|
|
6382
|
+
transport: {
|
|
6383
|
+
mode: "delete",
|
|
6384
|
+
endpoint: "/gateway/delete",
|
|
6385
|
+
payload: input.payload
|
|
6386
|
+
}
|
|
6387
|
+
};
|
|
6388
|
+
}
|
|
6389
|
+
function buildRpcDebugAst(input) {
|
|
6390
|
+
return {
|
|
6391
|
+
version: 1,
|
|
6392
|
+
kind: "rpc",
|
|
6393
|
+
functionName: input.functionName,
|
|
6394
|
+
input: {
|
|
6395
|
+
args: input.args,
|
|
6396
|
+
select: input.selectedColumns,
|
|
6397
|
+
state: cloneRpcBuilderStateAst(input.state)
|
|
6398
|
+
},
|
|
6399
|
+
transport: {
|
|
6400
|
+
mode: input.endpoint === "/gateway/rpc" ? "rpc-post" : "rpc-get",
|
|
6401
|
+
endpoint: input.endpoint,
|
|
6402
|
+
payload: input.payload
|
|
6403
|
+
}
|
|
6404
|
+
};
|
|
6405
|
+
}
|
|
6406
|
+
function buildRawQueryDebugAst(query) {
|
|
6407
|
+
return {
|
|
6408
|
+
version: 1,
|
|
6409
|
+
kind: "query",
|
|
6410
|
+
input: {
|
|
6411
|
+
query
|
|
6412
|
+
},
|
|
6413
|
+
transport: {
|
|
6414
|
+
mode: "raw-query",
|
|
6415
|
+
endpoint: "/gateway/query",
|
|
6416
|
+
payload: {
|
|
6417
|
+
query
|
|
6418
|
+
}
|
|
6419
|
+
}
|
|
6420
|
+
};
|
|
6421
|
+
}
|
|
6422
|
+
function attachAthenaDebugAst(target, ast) {
|
|
6423
|
+
if (!ast) {
|
|
6424
|
+
return;
|
|
6425
|
+
}
|
|
6426
|
+
if (!target || typeof target !== "object" && typeof target !== "function") {
|
|
6427
|
+
return;
|
|
6428
|
+
}
|
|
6429
|
+
Object.defineProperty(target, ATHENA_DEBUG_AST_KEY, {
|
|
6430
|
+
value: ast,
|
|
6431
|
+
enumerable: false,
|
|
6432
|
+
configurable: true,
|
|
6433
|
+
writable: false
|
|
6434
|
+
});
|
|
6435
|
+
}
|
|
6436
|
+
function getAthenaDebugAst(value) {
|
|
6437
|
+
if (!value || typeof value !== "object" && typeof value !== "function") {
|
|
6438
|
+
return null;
|
|
6439
|
+
}
|
|
6440
|
+
return value[ATHENA_DEBUG_AST_KEY] ?? null;
|
|
6441
|
+
}
|
|
6442
|
+
|
|
6443
|
+
// src/query-tracing.ts
|
|
6444
|
+
var QUERY_TRACE_STACK_SKIP_PATTERNS = [
|
|
6445
|
+
"src\\client.ts",
|
|
6446
|
+
"src/client.ts",
|
|
6447
|
+
"src\\query-tracing.ts",
|
|
6448
|
+
"src/query-tracing.ts",
|
|
6449
|
+
"dist\\client.",
|
|
6450
|
+
"dist/client.",
|
|
6451
|
+
"dist\\query-tracing.",
|
|
6452
|
+
"dist/query-tracing.",
|
|
6453
|
+
"node_modules\\@xylex-group\\athena",
|
|
6454
|
+
"node_modules/@xylex-group/athena",
|
|
6455
|
+
"node:internal",
|
|
6456
|
+
"internal/process"
|
|
6457
|
+
];
|
|
6458
|
+
function parseQueryTraceCallsiteFrame(frame) {
|
|
6459
|
+
const trimmed = frame.trim();
|
|
6460
|
+
if (!trimmed) {
|
|
6461
|
+
return null;
|
|
6462
|
+
}
|
|
6463
|
+
let body = trimmed.replace(/^at\s+/, "");
|
|
6464
|
+
if (body.startsWith("async ")) {
|
|
6465
|
+
body = body.slice(6);
|
|
6466
|
+
}
|
|
6467
|
+
let functionName;
|
|
6468
|
+
let location = body;
|
|
6469
|
+
const wrappedMatch = body.match(/^(.*?)\s+\((.*)\)$/);
|
|
6470
|
+
if (wrappedMatch) {
|
|
6471
|
+
functionName = wrappedMatch[1].trim() || void 0;
|
|
6472
|
+
location = wrappedMatch[2].trim();
|
|
6473
|
+
}
|
|
6474
|
+
const locationMatch = location.match(/^(.*):(\d+):(\d+)$/);
|
|
6475
|
+
if (!locationMatch) {
|
|
6476
|
+
return null;
|
|
6477
|
+
}
|
|
6478
|
+
const filePath = locationMatch[1].replace(/^file:\/\//, "");
|
|
6479
|
+
const line = Number(locationMatch[2]);
|
|
6480
|
+
const column = Number(locationMatch[3]);
|
|
6481
|
+
if (!Number.isFinite(line) || !Number.isFinite(column)) {
|
|
6482
|
+
return null;
|
|
6483
|
+
}
|
|
6484
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
6485
|
+
const fileName = normalizedPath.split("/").at(-1) ?? filePath;
|
|
6486
|
+
return {
|
|
6487
|
+
filePath,
|
|
6488
|
+
fileName,
|
|
6489
|
+
line,
|
|
6490
|
+
column,
|
|
6491
|
+
frame: trimmed,
|
|
6492
|
+
functionName
|
|
6493
|
+
};
|
|
6494
|
+
}
|
|
6495
|
+
function captureQueryTraceCallsite() {
|
|
6496
|
+
const stack = new Error().stack;
|
|
6497
|
+
if (!stack) return null;
|
|
6498
|
+
const frames = stack.split("\n").slice(2).map((frame) => frame.trim()).filter(Boolean);
|
|
6499
|
+
for (const frame of frames) {
|
|
6500
|
+
if (QUERY_TRACE_STACK_SKIP_PATTERNS.some((pattern) => frame.includes(pattern))) {
|
|
6501
|
+
continue;
|
|
6502
|
+
}
|
|
6503
|
+
const callsite = parseQueryTraceCallsiteFrame(frame);
|
|
6504
|
+
if (callsite) return callsite;
|
|
6505
|
+
}
|
|
6506
|
+
const fallback = frames.find((frame) => !frame.includes("captureQueryTraceCallsite"));
|
|
6507
|
+
return fallback ? parseQueryTraceCallsiteFrame(fallback) : null;
|
|
6508
|
+
}
|
|
6509
|
+
function defaultQueryTraceLogger(event) {
|
|
6510
|
+
const target = event.table ?? event.functionName ?? "gateway";
|
|
6511
|
+
const outcomeState = event.outcome?.error ? "error" : "ok";
|
|
6512
|
+
const banner = `[athena-js][trace] ${event.operation.toUpperCase()} ${event.endpoint} ${target} ${event.durationMs}ms ${outcomeState}`;
|
|
6513
|
+
console.info(banner, event);
|
|
6514
|
+
}
|
|
6515
|
+
function captureTraceCallsite(tracer) {
|
|
6516
|
+
return tracer?.captureCallsite() ?? null;
|
|
6517
|
+
}
|
|
6518
|
+
function createTraceCallsiteStore(tracer, initialCallsite) {
|
|
6519
|
+
let storedCallsite = initialCallsite ?? void 0;
|
|
6520
|
+
return {
|
|
6521
|
+
resolve(callsite) {
|
|
6522
|
+
if (callsite) {
|
|
6523
|
+
storedCallsite = callsite;
|
|
6524
|
+
return callsite;
|
|
6525
|
+
}
|
|
6526
|
+
if (storedCallsite !== void 0) {
|
|
6527
|
+
return storedCallsite;
|
|
6528
|
+
}
|
|
6529
|
+
const capturedCallsite = captureTraceCallsite(tracer);
|
|
6530
|
+
if (capturedCallsite) {
|
|
6531
|
+
storedCallsite = capturedCallsite;
|
|
6532
|
+
}
|
|
6533
|
+
return capturedCallsite;
|
|
6534
|
+
}
|
|
6535
|
+
};
|
|
6536
|
+
}
|
|
6537
|
+
function createQueryTracer(experimental) {
|
|
6538
|
+
const traceOption = experimental?.traceQueries;
|
|
6539
|
+
if (!traceOption) {
|
|
6540
|
+
return void 0;
|
|
6541
|
+
}
|
|
6542
|
+
const logger = typeof traceOption === "object" && traceOption.logger ? traceOption.logger : defaultQueryTraceLogger;
|
|
6543
|
+
const emit = (event) => {
|
|
6544
|
+
try {
|
|
6545
|
+
logger(event);
|
|
6546
|
+
} catch (error) {
|
|
6547
|
+
console.warn("[athena-js][trace] logger failed", error);
|
|
6548
|
+
}
|
|
6549
|
+
};
|
|
6550
|
+
return {
|
|
6551
|
+
captureCallsite: captureQueryTraceCallsite,
|
|
6552
|
+
publishSuccess(context, result, durationMs, callsite) {
|
|
6553
|
+
emit({
|
|
6554
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6555
|
+
durationMs,
|
|
6556
|
+
operation: context.operation,
|
|
6557
|
+
endpoint: context.endpoint,
|
|
6558
|
+
table: context.table,
|
|
6559
|
+
functionName: context.functionName,
|
|
6560
|
+
sql: context.sql,
|
|
6561
|
+
payload: context.payload,
|
|
6562
|
+
ast: context.ast,
|
|
6563
|
+
options: context.options,
|
|
6564
|
+
callsite,
|
|
6565
|
+
outcome: {
|
|
6566
|
+
status: result.status,
|
|
6567
|
+
error: result.error,
|
|
6568
|
+
errorDetails: result.errorDetails ?? null,
|
|
6569
|
+
count: result.count ?? null,
|
|
6570
|
+
data: result.data,
|
|
6571
|
+
raw: result.raw
|
|
6572
|
+
}
|
|
6573
|
+
});
|
|
6574
|
+
},
|
|
6575
|
+
publishFailure(context, error, durationMs, callsite) {
|
|
6576
|
+
emit({
|
|
6577
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6578
|
+
durationMs,
|
|
6579
|
+
operation: context.operation,
|
|
6580
|
+
endpoint: context.endpoint,
|
|
6581
|
+
table: context.table,
|
|
6582
|
+
functionName: context.functionName,
|
|
6583
|
+
sql: context.sql,
|
|
6584
|
+
payload: context.payload,
|
|
6585
|
+
ast: context.ast,
|
|
6586
|
+
options: context.options,
|
|
6587
|
+
callsite,
|
|
6588
|
+
thrownError: error
|
|
6589
|
+
});
|
|
5407
6590
|
}
|
|
5408
6591
|
};
|
|
5409
6592
|
}
|
|
6593
|
+
async function executeWithQueryTrace(tracer, context, runner, callsiteOverride) {
|
|
6594
|
+
const callsite = tracer ? callsiteOverride ?? tracer.captureCallsite() : null;
|
|
6595
|
+
const startedAt = tracer ? Date.now() : 0;
|
|
6596
|
+
try {
|
|
6597
|
+
const result = await runner();
|
|
6598
|
+
attachAthenaDebugAst(result, context.ast);
|
|
6599
|
+
if (tracer) {
|
|
6600
|
+
tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
|
|
6601
|
+
}
|
|
6602
|
+
return result;
|
|
6603
|
+
} catch (error) {
|
|
6604
|
+
attachAthenaDebugAst(error, context.ast);
|
|
6605
|
+
if (tracer) {
|
|
6606
|
+
tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
|
|
6607
|
+
}
|
|
6608
|
+
throw error;
|
|
6609
|
+
}
|
|
6610
|
+
}
|
|
6611
|
+
|
|
6612
|
+
// src/schema/model-target.ts
|
|
6613
|
+
function normalizeOptionalName(value) {
|
|
6614
|
+
const normalized = value?.trim();
|
|
6615
|
+
return normalized ? normalized : void 0;
|
|
6616
|
+
}
|
|
6617
|
+
function isAthenaModelTarget(value) {
|
|
6618
|
+
if (!value || typeof value !== "object") {
|
|
6619
|
+
return false;
|
|
6620
|
+
}
|
|
6621
|
+
const candidate = value;
|
|
6622
|
+
return Boolean(candidate.meta && Array.isArray(candidate.meta.primaryKey));
|
|
6623
|
+
}
|
|
6624
|
+
function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
6625
|
+
const explicitTableName = normalizeOptionalName(target.meta.tableName);
|
|
6626
|
+
if (explicitTableName) {
|
|
6627
|
+
return explicitTableName;
|
|
6628
|
+
}
|
|
6629
|
+
const schemaName = normalizeOptionalName(target.meta.schema ?? options.fallbackSchema);
|
|
6630
|
+
const modelName = normalizeOptionalName(target.meta.model ?? options.fallbackModel);
|
|
6631
|
+
if (!modelName) {
|
|
6632
|
+
throw new Error(
|
|
6633
|
+
"Athena model target is missing meta.model or meta.tableName. Provide one of those before calling from(model)."
|
|
6634
|
+
);
|
|
6635
|
+
}
|
|
6636
|
+
return schemaName ? `${schemaName}.${modelName}` : modelName;
|
|
6637
|
+
}
|
|
5410
6638
|
|
|
5411
6639
|
// src/client.ts
|
|
5412
6640
|
var DEFAULT_COLUMNS = "*";
|
|
5413
6641
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
5414
6642
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
5415
|
-
var QUERY_TRACE_STACK_SKIP_PATTERNS = [
|
|
5416
|
-
"src\\client.ts",
|
|
5417
|
-
"src/client.ts",
|
|
5418
|
-
"dist\\client.",
|
|
5419
|
-
"dist/client.",
|
|
5420
|
-
"node_modules\\@xylex-group\\athena",
|
|
5421
|
-
"node_modules/@xylex-group/athena",
|
|
5422
|
-
"node:internal",
|
|
5423
|
-
"internal/process"
|
|
5424
|
-
];
|
|
5425
6643
|
function formatResult(response) {
|
|
5426
6644
|
const result = {
|
|
5427
6645
|
data: response.data ?? null,
|
|
@@ -5563,154 +6781,6 @@ function createResultError(response, result, normalized) {
|
|
|
5563
6781
|
raw: result.raw
|
|
5564
6782
|
};
|
|
5565
6783
|
}
|
|
5566
|
-
function parseQueryTraceCallsiteFrame(frame) {
|
|
5567
|
-
const trimmed = frame.trim();
|
|
5568
|
-
if (!trimmed) {
|
|
5569
|
-
return null;
|
|
5570
|
-
}
|
|
5571
|
-
let body = trimmed.replace(/^at\s+/, "");
|
|
5572
|
-
if (body.startsWith("async ")) {
|
|
5573
|
-
body = body.slice(6);
|
|
5574
|
-
}
|
|
5575
|
-
let functionName;
|
|
5576
|
-
let location = body;
|
|
5577
|
-
const wrappedMatch = body.match(/^(.*?)\s+\((.*)\)$/);
|
|
5578
|
-
if (wrappedMatch) {
|
|
5579
|
-
functionName = wrappedMatch[1].trim() || void 0;
|
|
5580
|
-
location = wrappedMatch[2].trim();
|
|
5581
|
-
}
|
|
5582
|
-
const locationMatch = location.match(/^(.*):(\d+):(\d+)$/);
|
|
5583
|
-
if (!locationMatch) {
|
|
5584
|
-
return null;
|
|
5585
|
-
}
|
|
5586
|
-
const filePath = locationMatch[1].replace(/^file:\/\//, "");
|
|
5587
|
-
const line = Number(locationMatch[2]);
|
|
5588
|
-
const column = Number(locationMatch[3]);
|
|
5589
|
-
if (!Number.isFinite(line) || !Number.isFinite(column)) {
|
|
5590
|
-
return null;
|
|
5591
|
-
}
|
|
5592
|
-
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
5593
|
-
const fileName = normalizedPath.split("/").at(-1) ?? filePath;
|
|
5594
|
-
return {
|
|
5595
|
-
filePath,
|
|
5596
|
-
fileName,
|
|
5597
|
-
line,
|
|
5598
|
-
column,
|
|
5599
|
-
frame: trimmed,
|
|
5600
|
-
functionName
|
|
5601
|
-
};
|
|
5602
|
-
}
|
|
5603
|
-
function captureQueryTraceCallsite() {
|
|
5604
|
-
const stack = new Error().stack;
|
|
5605
|
-
if (!stack) return null;
|
|
5606
|
-
const frames = stack.split("\n").slice(2).map((frame) => frame.trim()).filter(Boolean);
|
|
5607
|
-
for (const frame of frames) {
|
|
5608
|
-
if (QUERY_TRACE_STACK_SKIP_PATTERNS.some((pattern) => frame.includes(pattern))) {
|
|
5609
|
-
continue;
|
|
5610
|
-
}
|
|
5611
|
-
const callsite = parseQueryTraceCallsiteFrame(frame);
|
|
5612
|
-
if (callsite) return callsite;
|
|
5613
|
-
}
|
|
5614
|
-
const fallback = frames.find((frame) => !frame.includes("captureQueryTraceCallsite"));
|
|
5615
|
-
return fallback ? parseQueryTraceCallsiteFrame(fallback) : null;
|
|
5616
|
-
}
|
|
5617
|
-
function defaultQueryTraceLogger(event) {
|
|
5618
|
-
const target = event.table ?? event.functionName ?? "gateway";
|
|
5619
|
-
const outcomeState = event.outcome?.error ? "error" : "ok";
|
|
5620
|
-
const banner = `[athena-js][trace] ${event.operation.toUpperCase()} ${event.endpoint} ${target} ${event.durationMs}ms ${outcomeState}`;
|
|
5621
|
-
console.info(banner, event);
|
|
5622
|
-
}
|
|
5623
|
-
function captureTraceCallsite(tracer) {
|
|
5624
|
-
return tracer?.captureCallsite() ?? null;
|
|
5625
|
-
}
|
|
5626
|
-
function createTraceCallsiteStore(tracer, initialCallsite) {
|
|
5627
|
-
let storedCallsite = initialCallsite ?? void 0;
|
|
5628
|
-
return {
|
|
5629
|
-
resolve(callsite) {
|
|
5630
|
-
if (callsite) {
|
|
5631
|
-
storedCallsite = callsite;
|
|
5632
|
-
return callsite;
|
|
5633
|
-
}
|
|
5634
|
-
if (storedCallsite !== void 0) {
|
|
5635
|
-
return storedCallsite;
|
|
5636
|
-
}
|
|
5637
|
-
const capturedCallsite = captureTraceCallsite(tracer);
|
|
5638
|
-
if (capturedCallsite) {
|
|
5639
|
-
storedCallsite = capturedCallsite;
|
|
5640
|
-
}
|
|
5641
|
-
return capturedCallsite;
|
|
5642
|
-
}
|
|
5643
|
-
};
|
|
5644
|
-
}
|
|
5645
|
-
function createQueryTracer(experimental) {
|
|
5646
|
-
const traceOption = experimental?.traceQueries;
|
|
5647
|
-
if (!traceOption) {
|
|
5648
|
-
return void 0;
|
|
5649
|
-
}
|
|
5650
|
-
const logger = typeof traceOption === "object" && traceOption.logger ? traceOption.logger : defaultQueryTraceLogger;
|
|
5651
|
-
const emit = (event) => {
|
|
5652
|
-
try {
|
|
5653
|
-
logger(event);
|
|
5654
|
-
} catch (error) {
|
|
5655
|
-
console.warn("[athena-js][trace] logger failed", error);
|
|
5656
|
-
}
|
|
5657
|
-
};
|
|
5658
|
-
return {
|
|
5659
|
-
captureCallsite: captureQueryTraceCallsite,
|
|
5660
|
-
publishSuccess(context, result, durationMs, callsite) {
|
|
5661
|
-
emit({
|
|
5662
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5663
|
-
durationMs,
|
|
5664
|
-
operation: context.operation,
|
|
5665
|
-
endpoint: context.endpoint,
|
|
5666
|
-
table: context.table,
|
|
5667
|
-
functionName: context.functionName,
|
|
5668
|
-
sql: context.sql,
|
|
5669
|
-
payload: context.payload,
|
|
5670
|
-
options: context.options,
|
|
5671
|
-
callsite,
|
|
5672
|
-
outcome: {
|
|
5673
|
-
status: result.status,
|
|
5674
|
-
error: result.error,
|
|
5675
|
-
errorDetails: result.errorDetails ?? null,
|
|
5676
|
-
count: result.count ?? null,
|
|
5677
|
-
data: result.data,
|
|
5678
|
-
raw: result.raw
|
|
5679
|
-
}
|
|
5680
|
-
});
|
|
5681
|
-
},
|
|
5682
|
-
publishFailure(context, error, durationMs, callsite) {
|
|
5683
|
-
emit({
|
|
5684
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5685
|
-
durationMs,
|
|
5686
|
-
operation: context.operation,
|
|
5687
|
-
endpoint: context.endpoint,
|
|
5688
|
-
table: context.table,
|
|
5689
|
-
functionName: context.functionName,
|
|
5690
|
-
sql: context.sql,
|
|
5691
|
-
payload: context.payload,
|
|
5692
|
-
options: context.options,
|
|
5693
|
-
callsite,
|
|
5694
|
-
thrownError: error
|
|
5695
|
-
});
|
|
5696
|
-
}
|
|
5697
|
-
};
|
|
5698
|
-
}
|
|
5699
|
-
async function executeWithQueryTrace(tracer, context, runner, callsiteOverride) {
|
|
5700
|
-
if (!tracer) {
|
|
5701
|
-
return runner();
|
|
5702
|
-
}
|
|
5703
|
-
const callsite = callsiteOverride ?? tracer.captureCallsite();
|
|
5704
|
-
const startedAt = Date.now();
|
|
5705
|
-
try {
|
|
5706
|
-
const result = await runner();
|
|
5707
|
-
tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
|
|
5708
|
-
return result;
|
|
5709
|
-
} catch (error) {
|
|
5710
|
-
tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
|
|
5711
|
-
throw error;
|
|
5712
|
-
}
|
|
5713
|
-
}
|
|
5714
6784
|
function toSingleResult(response) {
|
|
5715
6785
|
const payload = response.data;
|
|
5716
6786
|
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
@@ -5738,6 +6808,15 @@ function asAthenaJsonObject(value) {
|
|
|
5738
6808
|
function asAthenaJsonObjectArray(values) {
|
|
5739
6809
|
return values;
|
|
5740
6810
|
}
|
|
6811
|
+
function normalizeSelectColumnsInput(columns) {
|
|
6812
|
+
if (columns === void 0) {
|
|
6813
|
+
return void 0;
|
|
6814
|
+
}
|
|
6815
|
+
if (typeof columns === "string") {
|
|
6816
|
+
return columns;
|
|
6817
|
+
}
|
|
6818
|
+
return [...columns];
|
|
6819
|
+
}
|
|
5741
6820
|
function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer, initialCallsite) {
|
|
5742
6821
|
let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
|
|
5743
6822
|
let selectedOptions;
|
|
@@ -5747,25 +6826,29 @@ function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer,
|
|
|
5747
6826
|
const payloadColumns = columns ?? selectedColumns;
|
|
5748
6827
|
const payloadOptions = options ?? selectedOptions;
|
|
5749
6828
|
if (!promise) {
|
|
5750
|
-
promise = executor(
|
|
6829
|
+
promise = executor(
|
|
6830
|
+
normalizeSelectColumnsInput(payloadColumns),
|
|
6831
|
+
payloadOptions,
|
|
6832
|
+
callsiteStore.resolve(callsite)
|
|
6833
|
+
);
|
|
5751
6834
|
}
|
|
5752
6835
|
return promise;
|
|
5753
6836
|
};
|
|
5754
6837
|
const mutationQuery = {
|
|
5755
|
-
select(columns
|
|
6838
|
+
select(columns, options) {
|
|
5756
6839
|
selectedColumns = columns;
|
|
5757
6840
|
selectedOptions = options ?? selectedOptions;
|
|
5758
6841
|
return run(columns, options, captureTraceCallsite(tracer));
|
|
5759
6842
|
},
|
|
5760
|
-
returning(columns
|
|
6843
|
+
returning(columns, options) {
|
|
5761
6844
|
return mutationQuery.select(columns, options);
|
|
5762
6845
|
},
|
|
5763
|
-
single(columns
|
|
6846
|
+
single(columns, options) {
|
|
5764
6847
|
selectedColumns = columns;
|
|
5765
6848
|
selectedOptions = options ?? selectedOptions;
|
|
5766
6849
|
return run(columns, options, captureTraceCallsite(tracer)).then(toSingleResult);
|
|
5767
6850
|
},
|
|
5768
|
-
maybeSingle(columns
|
|
6851
|
+
maybeSingle(columns, options) {
|
|
5769
6852
|
return mutationQuery.single(columns, options);
|
|
5770
6853
|
},
|
|
5771
6854
|
then(onfulfilled, onrejected) {
|
|
@@ -6322,7 +7405,10 @@ function createFilterMethods(state, addCondition, self) {
|
|
|
6322
7405
|
}
|
|
6323
7406
|
function toRpcSelect(columns) {
|
|
6324
7407
|
if (!columns) return void 0;
|
|
6325
|
-
|
|
7408
|
+
if (typeof columns === "string") {
|
|
7409
|
+
return columns;
|
|
7410
|
+
}
|
|
7411
|
+
return columns.join(",");
|
|
6326
7412
|
}
|
|
6327
7413
|
function createRpcFilterMethods(filters, self) {
|
|
6328
7414
|
const addFilter = (operator, column, value) => {
|
|
@@ -6371,7 +7457,7 @@ function createRpcFilterMethods(filters, self) {
|
|
|
6371
7457
|
}
|
|
6372
7458
|
};
|
|
6373
7459
|
}
|
|
6374
|
-
function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite) {
|
|
7460
|
+
function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite, debugAstEnabled = false) {
|
|
6375
7461
|
const state = {
|
|
6376
7462
|
filters: []
|
|
6377
7463
|
};
|
|
@@ -6381,6 +7467,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6381
7467
|
const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
|
|
6382
7468
|
const executeRpc = async (columns, options, callsite) => {
|
|
6383
7469
|
const mergedOptions = mergeOptions(baseOptions, options);
|
|
7470
|
+
const normalizedSelectedColumns = normalizeSelectColumnsInput(columns);
|
|
6384
7471
|
const payload = {
|
|
6385
7472
|
function: functionName,
|
|
6386
7473
|
args,
|
|
@@ -6395,6 +7482,14 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6395
7482
|
};
|
|
6396
7483
|
const endpoint = mergedOptions?.get ? `/rpc/${functionName}` : "/gateway/rpc";
|
|
6397
7484
|
const sql = buildRpcDebugSql(payload);
|
|
7485
|
+
const debugAst = debugAstEnabled ? buildRpcDebugAst({
|
|
7486
|
+
functionName,
|
|
7487
|
+
args,
|
|
7488
|
+
selectedColumns: normalizedSelectedColumns,
|
|
7489
|
+
state,
|
|
7490
|
+
payload,
|
|
7491
|
+
endpoint
|
|
7492
|
+
}) : void 0;
|
|
6398
7493
|
return executeWithQueryTrace(
|
|
6399
7494
|
tracer,
|
|
6400
7495
|
{
|
|
@@ -6403,6 +7498,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6403
7498
|
functionName,
|
|
6404
7499
|
sql,
|
|
6405
7500
|
payload,
|
|
7501
|
+
ast: debugAst,
|
|
6406
7502
|
options: mergedOptions
|
|
6407
7503
|
},
|
|
6408
7504
|
async () => {
|
|
@@ -6423,7 +7519,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6423
7519
|
const builder = {};
|
|
6424
7520
|
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
6425
7521
|
Object.assign(builder, filterMethods, {
|
|
6426
|
-
select(columns
|
|
7522
|
+
select(columns, options) {
|
|
6427
7523
|
selectedColumns = columns;
|
|
6428
7524
|
selectedOptions = options ?? selectedOptions;
|
|
6429
7525
|
return run(columns, options, captureTraceCallsite(tracer));
|
|
@@ -6468,6 +7564,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6468
7564
|
const state = {
|
|
6469
7565
|
conditions: []
|
|
6470
7566
|
};
|
|
7567
|
+
const debugAstEnabled = Boolean(experimental?.debugAst);
|
|
6471
7568
|
const addCondition = (operator, column, value, hints) => {
|
|
6472
7569
|
const condition = { operator };
|
|
6473
7570
|
if (column) {
|
|
@@ -6511,15 +7608,27 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6511
7608
|
addCondition,
|
|
6512
7609
|
builder
|
|
6513
7610
|
);
|
|
6514
|
-
const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite) => {
|
|
7611
|
+
const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite, debugAstFactory) => {
|
|
7612
|
+
const runtimeColumns = normalizeSelectColumnsInput(columns) ?? DEFAULT_COLUMNS;
|
|
6515
7613
|
const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
|
|
6516
7614
|
const plan = createSelectTransportPlan({
|
|
6517
7615
|
tableName: resolvedTableName,
|
|
6518
|
-
columns,
|
|
7616
|
+
columns: runtimeColumns,
|
|
6519
7617
|
state: executionState,
|
|
6520
7618
|
options,
|
|
6521
7619
|
buildTypedSelectQuery
|
|
6522
7620
|
});
|
|
7621
|
+
const debugAst = debugAstEnabled ? debugAstFactory?.({
|
|
7622
|
+
tableName: resolvedTableName,
|
|
7623
|
+
columns: runtimeColumns,
|
|
7624
|
+
executionState,
|
|
7625
|
+
plan
|
|
7626
|
+
}) ?? buildSelectDebugAst({
|
|
7627
|
+
tableName: resolvedTableName,
|
|
7628
|
+
columns: runtimeColumns,
|
|
7629
|
+
state: executionState,
|
|
7630
|
+
plan
|
|
7631
|
+
}) : void 0;
|
|
6523
7632
|
if (plan.kind === "query") {
|
|
6524
7633
|
return executeExperimentalRead(
|
|
6525
7634
|
experimental,
|
|
@@ -6531,6 +7640,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6531
7640
|
table: resolvedTableName,
|
|
6532
7641
|
sql: plan.query,
|
|
6533
7642
|
payload: plan.payload,
|
|
7643
|
+
ast: debugAst,
|
|
6534
7644
|
options
|
|
6535
7645
|
},
|
|
6536
7646
|
async () => {
|
|
@@ -6555,6 +7665,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6555
7665
|
table: resolvedTableName,
|
|
6556
7666
|
sql,
|
|
6557
7667
|
payload: plan.payload,
|
|
7668
|
+
ast: debugAst,
|
|
6558
7669
|
options
|
|
6559
7670
|
},
|
|
6560
7671
|
async () => {
|
|
@@ -6568,7 +7679,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6568
7679
|
const createSelectChain = (columns, options, initialCallsite) => {
|
|
6569
7680
|
const chain = {};
|
|
6570
7681
|
const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
|
|
6571
|
-
const filterMethods2 = createFilterMethods(
|
|
7682
|
+
const filterMethods2 = createFilterMethods(
|
|
7683
|
+
state,
|
|
7684
|
+
addCondition,
|
|
7685
|
+
chain
|
|
7686
|
+
);
|
|
6572
7687
|
Object.assign(chain, filterMethods2, {
|
|
6573
7688
|
async single(cols, opts) {
|
|
6574
7689
|
const r = await runSelect(
|
|
@@ -6655,6 +7770,14 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6655
7770
|
limit: executionState.limit,
|
|
6656
7771
|
order: executionState.order
|
|
6657
7772
|
});
|
|
7773
|
+
const debugAst = debugAstEnabled ? buildFindManyDirectDebugAst({
|
|
7774
|
+
tableName: resolvedTableName,
|
|
7775
|
+
options,
|
|
7776
|
+
compiledColumns: columns,
|
|
7777
|
+
baseState,
|
|
7778
|
+
executionState,
|
|
7779
|
+
payload
|
|
7780
|
+
}) : void 0;
|
|
6658
7781
|
return executeExperimentalRead(
|
|
6659
7782
|
experimental,
|
|
6660
7783
|
() => executeWithQueryTrace(
|
|
@@ -6664,7 +7787,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6664
7787
|
endpoint: "/gateway/fetch",
|
|
6665
7788
|
table: resolvedTableName,
|
|
6666
7789
|
sql,
|
|
6667
|
-
payload
|
|
7790
|
+
payload,
|
|
7791
|
+
ast: debugAst
|
|
6668
7792
|
},
|
|
6669
7793
|
async () => {
|
|
6670
7794
|
const response = await client.fetchGateway(
|
|
@@ -6680,7 +7804,15 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6680
7804
|
columns,
|
|
6681
7805
|
void 0,
|
|
6682
7806
|
executionState,
|
|
6683
|
-
callsite
|
|
7807
|
+
callsite,
|
|
7808
|
+
debugAstEnabled ? ({ tableName: resolvedTableName, executionState: tracedState, plan }) => buildFindManyCompiledDebugAst({
|
|
7809
|
+
tableName: resolvedTableName,
|
|
7810
|
+
options,
|
|
7811
|
+
compiledColumns: columns,
|
|
7812
|
+
baseState,
|
|
7813
|
+
executionState: tracedState,
|
|
7814
|
+
plan
|
|
7815
|
+
}) : void 0
|
|
6684
7816
|
);
|
|
6685
7817
|
},
|
|
6686
7818
|
insert(values, options) {
|
|
@@ -6700,6 +7832,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6700
7832
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6701
7833
|
}
|
|
6702
7834
|
const sql = buildInsertDebugSql(payload);
|
|
7835
|
+
const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
|
|
6703
7836
|
return executeWithQueryTrace(
|
|
6704
7837
|
tracer,
|
|
6705
7838
|
{
|
|
@@ -6708,6 +7841,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6708
7841
|
table: resolvedTableName,
|
|
6709
7842
|
sql,
|
|
6710
7843
|
payload,
|
|
7844
|
+
ast: debugAst,
|
|
6711
7845
|
options: mergedOptions
|
|
6712
7846
|
},
|
|
6713
7847
|
async () => {
|
|
@@ -6733,6 +7867,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6733
7867
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6734
7868
|
}
|
|
6735
7869
|
const sql = buildInsertDebugSql(payload);
|
|
7870
|
+
const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
|
|
6736
7871
|
return executeWithQueryTrace(
|
|
6737
7872
|
tracer,
|
|
6738
7873
|
{
|
|
@@ -6741,6 +7876,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6741
7876
|
table: resolvedTableName,
|
|
6742
7877
|
sql,
|
|
6743
7878
|
payload,
|
|
7879
|
+
ast: debugAst,
|
|
6744
7880
|
options: mergedOptions
|
|
6745
7881
|
},
|
|
6746
7882
|
async () => {
|
|
@@ -6771,6 +7907,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6771
7907
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6772
7908
|
}
|
|
6773
7909
|
const sql = buildInsertDebugSql(payload);
|
|
7910
|
+
const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
|
|
6774
7911
|
return executeWithQueryTrace(
|
|
6775
7912
|
tracer,
|
|
6776
7913
|
{
|
|
@@ -6779,6 +7916,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6779
7916
|
table: resolvedTableName,
|
|
6780
7917
|
sql,
|
|
6781
7918
|
payload,
|
|
7919
|
+
ast: debugAst,
|
|
6782
7920
|
options: mergedOptions
|
|
6783
7921
|
},
|
|
6784
7922
|
async () => {
|
|
@@ -6806,6 +7944,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6806
7944
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6807
7945
|
}
|
|
6808
7946
|
const sql = buildInsertDebugSql(payload);
|
|
7947
|
+
const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
|
|
6809
7948
|
return executeWithQueryTrace(
|
|
6810
7949
|
tracer,
|
|
6811
7950
|
{
|
|
@@ -6814,6 +7953,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6814
7953
|
table: resolvedTableName,
|
|
6815
7954
|
sql,
|
|
6816
7955
|
payload,
|
|
7956
|
+
ast: debugAst,
|
|
6817
7957
|
options: mergedOptions
|
|
6818
7958
|
},
|
|
6819
7959
|
async () => {
|
|
@@ -6828,7 +7968,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6828
7968
|
update(values, options) {
|
|
6829
7969
|
const mutationCallsite = captureTraceCallsite(tracer);
|
|
6830
7970
|
const executeUpdate = async (columns, selectOptions, callsite) => {
|
|
6831
|
-
const
|
|
7971
|
+
const executionState = snapshotState();
|
|
7972
|
+
const filters = executionState.conditions.length ? [...executionState.conditions] : void 0;
|
|
6832
7973
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
6833
7974
|
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
6834
7975
|
const payload = {
|
|
@@ -6837,12 +7978,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6837
7978
|
conditions: filters,
|
|
6838
7979
|
strip_nulls: mergedOptions?.stripNulls ?? true
|
|
6839
7980
|
};
|
|
6840
|
-
if (
|
|
6841
|
-
if (
|
|
6842
|
-
if (
|
|
6843
|
-
if (
|
|
7981
|
+
if (executionState.order) payload.sort_by = executionState.order;
|
|
7982
|
+
if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
|
|
7983
|
+
if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
|
|
7984
|
+
if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
|
|
6844
7985
|
if (columns) payload.columns = columns;
|
|
6845
7986
|
const sql = buildUpdateDebugSql(payload);
|
|
7987
|
+
const debugAst = debugAstEnabled ? buildUpdateDebugAst({
|
|
7988
|
+
state: executionState,
|
|
7989
|
+
payload
|
|
7990
|
+
}) : void 0;
|
|
6846
7991
|
return executeWithQueryTrace(
|
|
6847
7992
|
tracer,
|
|
6848
7993
|
{
|
|
@@ -6851,6 +7996,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6851
7996
|
table: resolvedTableName,
|
|
6852
7997
|
sql,
|
|
6853
7998
|
payload,
|
|
7999
|
+
ast: debugAst,
|
|
6854
8000
|
options: mergedOptions
|
|
6855
8001
|
},
|
|
6856
8002
|
async () => {
|
|
@@ -6874,6 +8020,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6874
8020
|
}
|
|
6875
8021
|
const mutationCallsite = captureTraceCallsite(tracer);
|
|
6876
8022
|
const executeDelete = async (columns, selectOptions, callsite) => {
|
|
8023
|
+
const executionState = snapshotState();
|
|
8024
|
+
const debugState = {
|
|
8025
|
+
...executionState,
|
|
8026
|
+
conditions: filters ? filters.map((condition) => ({ ...condition })) : []
|
|
8027
|
+
};
|
|
6877
8028
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
6878
8029
|
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
6879
8030
|
const payload = {
|
|
@@ -6881,12 +8032,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6881
8032
|
resource_id: resourceId,
|
|
6882
8033
|
conditions: filters
|
|
6883
8034
|
};
|
|
6884
|
-
if (
|
|
6885
|
-
if (
|
|
6886
|
-
if (
|
|
6887
|
-
if (
|
|
8035
|
+
if (executionState.order) payload.sort_by = executionState.order;
|
|
8036
|
+
if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
|
|
8037
|
+
if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
|
|
8038
|
+
if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
|
|
6888
8039
|
if (columns) payload.columns = columns;
|
|
6889
8040
|
const sql = buildDeleteDebugSql(payload);
|
|
8041
|
+
const debugAst = debugAstEnabled ? buildDeleteDebugAst({
|
|
8042
|
+
state: debugState,
|
|
8043
|
+
payload
|
|
8044
|
+
}) : void 0;
|
|
6890
8045
|
return executeWithQueryTrace(
|
|
6891
8046
|
tracer,
|
|
6892
8047
|
{
|
|
@@ -6895,6 +8050,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6895
8050
|
table: resolvedTableName,
|
|
6896
8051
|
sql,
|
|
6897
8052
|
payload,
|
|
8053
|
+
ast: debugAst,
|
|
6898
8054
|
options: mergedOptions
|
|
6899
8055
|
},
|
|
6900
8056
|
async () => {
|
|
@@ -6922,6 +8078,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6922
8078
|
return builder;
|
|
6923
8079
|
}
|
|
6924
8080
|
function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
8081
|
+
const debugAstEnabled = Boolean(experimental?.debugAst);
|
|
6925
8082
|
return async function query(query, options) {
|
|
6926
8083
|
const normalizedQuery = query.trim();
|
|
6927
8084
|
if (!normalizedQuery) {
|
|
@@ -6938,6 +8095,7 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
6938
8095
|
endpoint: "/gateway/query",
|
|
6939
8096
|
sql: normalizedQuery,
|
|
6940
8097
|
payload,
|
|
8098
|
+
ast: debugAstEnabled ? buildRawQueryDebugAst(normalizedQuery) : void 0,
|
|
6941
8099
|
options
|
|
6942
8100
|
},
|
|
6943
8101
|
async () => {
|
|
@@ -6949,6 +8107,96 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
6949
8107
|
);
|
|
6950
8108
|
};
|
|
6951
8109
|
}
|
|
8110
|
+
function resolveClientServiceBaseUrl(value, label) {
|
|
8111
|
+
if (value === void 0 || value === null) {
|
|
8112
|
+
return void 0;
|
|
8113
|
+
}
|
|
8114
|
+
return normalizeAthenaGatewayBaseUrl(value, { label });
|
|
8115
|
+
}
|
|
8116
|
+
function appendServicePath(baseUrl, segment) {
|
|
8117
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8118
|
+
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8119
|
+
}
|
|
8120
|
+
function resolveServiceUrlOverride(value, label) {
|
|
8121
|
+
return resolveClientServiceBaseUrl(value, label);
|
|
8122
|
+
}
|
|
8123
|
+
function resolveServiceUrls(config) {
|
|
8124
|
+
const baseUrl = resolveClientServiceBaseUrl(config.url, "Athena public base URL");
|
|
8125
|
+
return {
|
|
8126
|
+
dbUrl: resolveServiceUrlOverride(config.db?.url, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gateway?.url, "Athena gateway base URL") ?? resolveServiceUrlOverride(config.dbUrl, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gatewayUrl, "Athena gateway base URL") ?? (baseUrl ? appendServicePath(baseUrl, "db") : void 0),
|
|
8127
|
+
authUrl: resolveServiceUrlOverride(config.auth?.url, "Athena auth base URL") ?? resolveServiceUrlOverride(config.auth?.baseUrl, "Athena auth base URL") ?? resolveServiceUrlOverride(config.authUrl, "Athena auth base URL") ?? (baseUrl ? appendServicePath(baseUrl, "auth") : void 0),
|
|
8128
|
+
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8129
|
+
};
|
|
8130
|
+
}
|
|
8131
|
+
function resolveOptionalClientName(value) {
|
|
8132
|
+
if (value === void 0 || value === null) {
|
|
8133
|
+
return void 0;
|
|
8134
|
+
}
|
|
8135
|
+
const normalizedValue = value.trim();
|
|
8136
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
8137
|
+
}
|
|
8138
|
+
function resolveRequiredClientApiKey(value) {
|
|
8139
|
+
if (value === void 0 || value === null) {
|
|
8140
|
+
throw new Error(
|
|
8141
|
+
"Athena API key is required. Pass createClient(url, key) with a real API key, or set key in the config object."
|
|
8142
|
+
);
|
|
8143
|
+
}
|
|
8144
|
+
const normalizedValue = value.trim();
|
|
8145
|
+
if (!normalizedValue) {
|
|
8146
|
+
throw new Error(
|
|
8147
|
+
"Athena API key is required. Pass createClient(url, key) with a real API key, or set key in the config object."
|
|
8148
|
+
);
|
|
8149
|
+
}
|
|
8150
|
+
return normalizedValue;
|
|
8151
|
+
}
|
|
8152
|
+
function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
8153
|
+
if (!auth && defaultBaseUrl === void 0) {
|
|
8154
|
+
return void 0;
|
|
8155
|
+
}
|
|
8156
|
+
const {
|
|
8157
|
+
url,
|
|
8158
|
+
baseUrl,
|
|
8159
|
+
apiKey,
|
|
8160
|
+
bearerToken,
|
|
8161
|
+
...rest
|
|
8162
|
+
} = auth ?? {};
|
|
8163
|
+
const normalized = {
|
|
8164
|
+
...rest
|
|
8165
|
+
};
|
|
8166
|
+
const resolvedBaseUrl = resolveClientServiceBaseUrl(
|
|
8167
|
+
url ?? baseUrl ?? defaultBaseUrl,
|
|
8168
|
+
"Athena auth base URL"
|
|
8169
|
+
);
|
|
8170
|
+
if (resolvedBaseUrl !== void 0) {
|
|
8171
|
+
normalized.baseUrl = resolvedBaseUrl;
|
|
8172
|
+
}
|
|
8173
|
+
if (typeof apiKey === "string") {
|
|
8174
|
+
normalized.apiKey = apiKey;
|
|
8175
|
+
}
|
|
8176
|
+
if (typeof bearerToken === "string") {
|
|
8177
|
+
normalized.bearerToken = bearerToken;
|
|
8178
|
+
}
|
|
8179
|
+
return normalized;
|
|
8180
|
+
}
|
|
8181
|
+
function resolveCreateClientConfig(config) {
|
|
8182
|
+
const resolvedUrls = resolveServiceUrls(config);
|
|
8183
|
+
if (!resolvedUrls.dbUrl) {
|
|
8184
|
+
throw new Error(
|
|
8185
|
+
"Athena DB base URL is required. Pass createClient(url, key) for a unified root, or set db.url / gateway.url / gatewayUrl explicitly."
|
|
8186
|
+
);
|
|
8187
|
+
}
|
|
8188
|
+
return {
|
|
8189
|
+
baseUrl: resolvedUrls.dbUrl,
|
|
8190
|
+
apiKey: resolveRequiredClientApiKey(config.key),
|
|
8191
|
+
client: resolveOptionalClientName(config.client),
|
|
8192
|
+
backend: toBackendConfig(config.backend),
|
|
8193
|
+
headers: config.headers,
|
|
8194
|
+
auth: config.auth,
|
|
8195
|
+
authUrl: resolvedUrls.authUrl,
|
|
8196
|
+
storageUrl: resolvedUrls.storageUrl,
|
|
8197
|
+
experimental: config.experimental
|
|
8198
|
+
};
|
|
8199
|
+
}
|
|
6952
8200
|
function createClientFromConfig(config) {
|
|
6953
8201
|
const gatewayHeaders = {
|
|
6954
8202
|
...config.headers ?? {}
|
|
@@ -6965,14 +8213,31 @@ function createClientFromConfig(config) {
|
|
|
6965
8213
|
});
|
|
6966
8214
|
const formatGatewayResult = createResultFormatter(config.experimental);
|
|
6967
8215
|
const queryTracer = createQueryTracer(config.experimental);
|
|
6968
|
-
const auth = createAuthClient(config.auth);
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
8216
|
+
const auth = createAuthClient(normalizeAuthClientConfig(config.auth, config.authUrl));
|
|
8217
|
+
function from(tableOrModel, options) {
|
|
8218
|
+
if (isAthenaModelTarget(tableOrModel)) {
|
|
8219
|
+
if (options?.schema !== void 0) {
|
|
8220
|
+
throw new Error(
|
|
8221
|
+
"from(model) does not accept a schema override because the model already defines its target."
|
|
8222
|
+
);
|
|
8223
|
+
}
|
|
8224
|
+
return createTableBuilder(
|
|
8225
|
+
resolveAthenaModelTargetTableName(tableOrModel),
|
|
8226
|
+
gateway,
|
|
8227
|
+
formatGatewayResult,
|
|
8228
|
+
queryTracer,
|
|
8229
|
+
config.experimental
|
|
8230
|
+
);
|
|
8231
|
+
}
|
|
8232
|
+
const resolvedTableName = resolveTableNameForCall(tableOrModel, options?.schema);
|
|
8233
|
+
return createTableBuilder(
|
|
8234
|
+
resolvedTableName,
|
|
8235
|
+
gateway,
|
|
8236
|
+
formatGatewayResult,
|
|
8237
|
+
queryTracer,
|
|
8238
|
+
config.experimental
|
|
8239
|
+
);
|
|
8240
|
+
}
|
|
6976
8241
|
const rpc = (fn, args, options) => {
|
|
6977
8242
|
const normalizedFn = fn.trim();
|
|
6978
8243
|
if (!normalizedFn) {
|
|
@@ -6985,10 +8250,16 @@ function createClientFromConfig(config) {
|
|
|
6985
8250
|
gateway,
|
|
6986
8251
|
formatGatewayResult,
|
|
6987
8252
|
queryTracer,
|
|
6988
|
-
captureTraceCallsite(queryTracer)
|
|
8253
|
+
captureTraceCallsite(queryTracer),
|
|
8254
|
+
Boolean(config.experimental?.debugAst)
|
|
6989
8255
|
);
|
|
6990
8256
|
};
|
|
6991
|
-
const query = createQueryBuilder(
|
|
8257
|
+
const query = createQueryBuilder(
|
|
8258
|
+
gateway,
|
|
8259
|
+
formatGatewayResult,
|
|
8260
|
+
config.experimental,
|
|
8261
|
+
queryTracer
|
|
8262
|
+
);
|
|
6992
8263
|
const db = createDbModule({ from, rpc, query });
|
|
6993
8264
|
const sdkClient = {
|
|
6994
8265
|
from,
|
|
@@ -7001,170 +8272,448 @@ function createClientFromConfig(config) {
|
|
|
7001
8272
|
if (config.experimental?.athenaStorageBackend) {
|
|
7002
8273
|
const storageClient = {
|
|
7003
8274
|
...sdkClient,
|
|
7004
|
-
storage: createStorageModule(gateway,
|
|
8275
|
+
storage: createStorageModule(gateway, {
|
|
8276
|
+
...config.experimental.storage,
|
|
8277
|
+
...config.storageUrl ? {
|
|
8278
|
+
baseUrl: config.storageUrl,
|
|
8279
|
+
stripBasePath: true
|
|
8280
|
+
} : {}
|
|
8281
|
+
})
|
|
7005
8282
|
};
|
|
7006
8283
|
return storageClient;
|
|
7007
8284
|
}
|
|
7008
8285
|
return sdkClient;
|
|
7009
8286
|
}
|
|
7010
|
-
var
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
}
|
|
7015
|
-
function mergeAuthClientConfig(current, next) {
|
|
7016
|
-
const merged = {
|
|
7017
|
-
...current ?? {},
|
|
7018
|
-
...next
|
|
7019
|
-
};
|
|
7020
|
-
if (current?.headers || next.headers) {
|
|
7021
|
-
merged.headers = {
|
|
7022
|
-
...current?.headers ?? {},
|
|
7023
|
-
...next.headers ?? {}
|
|
7024
|
-
};
|
|
8287
|
+
var AthenaClient = class {
|
|
8288
|
+
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8289
|
+
static builder() {
|
|
8290
|
+
return createAthenaClientBuilder((config) => createClientFromConfig(resolveCreateClientConfig(config)));
|
|
7025
8291
|
}
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
}
|
|
8292
|
+
/** Build a client from process environment variables. */
|
|
8293
|
+
static fromEnvironment() {
|
|
8294
|
+
const url = process.env.ATHENA_URL;
|
|
8295
|
+
const gatewayUrl = process.env.ATHENA_DB_URL ?? process.env.ATHENA_GATEWAY_URL;
|
|
8296
|
+
const authUrl = process.env.ATHENA_AUTH_URL;
|
|
8297
|
+
const storageUrl = process.env.ATHENA_STORAGE_URL;
|
|
8298
|
+
const key = process.env.ATHENA_API_KEY ?? process.env.ATHENA_GATEWAY_API_KEY;
|
|
8299
|
+
if (!url && !gatewayUrl || !key) {
|
|
8300
|
+
throw new Error(
|
|
8301
|
+
"ATHENA_API_KEY plus ATHENA_URL or ATHENA_GATEWAY_URL (optionally ATHENA_DB_URL, ATHENA_AUTH_URL, ATHENA_STORAGE_URL) are required"
|
|
8302
|
+
);
|
|
8303
|
+
}
|
|
8304
|
+
return createClient({
|
|
8305
|
+
url,
|
|
8306
|
+
gatewayUrl,
|
|
8307
|
+
authUrl,
|
|
8308
|
+
storageUrl,
|
|
8309
|
+
key
|
|
8310
|
+
});
|
|
7038
8311
|
}
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
8312
|
+
};
|
|
8313
|
+
function createClient(configOrUrl, apiKey, options) {
|
|
8314
|
+
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8315
|
+
return createClientFromConfig(resolveCreateClientConfig({
|
|
8316
|
+
url: configOrUrl,
|
|
8317
|
+
key: apiKey ?? "",
|
|
8318
|
+
...options
|
|
8319
|
+
}));
|
|
7044
8320
|
}
|
|
7045
|
-
return
|
|
8321
|
+
return createClientFromConfig(resolveCreateClientConfig(configOrUrl));
|
|
7046
8322
|
}
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
8323
|
+
|
|
8324
|
+
// src/gateway/types.ts
|
|
8325
|
+
var Backend = {
|
|
8326
|
+
Athena: { type: "athena" },
|
|
8327
|
+
Postgrest: { type: "postgrest" },
|
|
8328
|
+
PostgreSQL: { type: "postgresql" },
|
|
8329
|
+
ScyllaDB: { type: "scylladb" }
|
|
8330
|
+
};
|
|
8331
|
+
|
|
8332
|
+
// src/schema/definitions.ts
|
|
8333
|
+
function defineModel(input) {
|
|
8334
|
+
return input;
|
|
8335
|
+
}
|
|
8336
|
+
function defineSchema(models) {
|
|
8337
|
+
return { models };
|
|
8338
|
+
}
|
|
8339
|
+
function defineDatabase(schemas) {
|
|
8340
|
+
return { schemas };
|
|
8341
|
+
}
|
|
8342
|
+
function defineRegistry(databases) {
|
|
8343
|
+
return databases;
|
|
8344
|
+
}
|
|
8345
|
+
|
|
8346
|
+
// src/schema/model-form.ts
|
|
8347
|
+
function resolveNullishValue(mode) {
|
|
8348
|
+
if (mode === "undefined") return void 0;
|
|
8349
|
+
if (mode === "null") return null;
|
|
8350
|
+
return "";
|
|
8351
|
+
}
|
|
8352
|
+
function isRecord10(value) {
|
|
8353
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8354
|
+
}
|
|
8355
|
+
function isNullableColumn(model, key) {
|
|
8356
|
+
const nullable = model.meta.nullable;
|
|
8357
|
+
return nullable?.[key] === true;
|
|
8358
|
+
}
|
|
8359
|
+
function toModelFormDefaults(model, values, options) {
|
|
8360
|
+
const source = values;
|
|
8361
|
+
if (!isRecord10(source)) {
|
|
8362
|
+
return {};
|
|
7078
8363
|
}
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
8364
|
+
const mode = options?.nullishMode ?? "empty-string";
|
|
8365
|
+
const nullishValue = resolveNullishValue(mode);
|
|
8366
|
+
const result = {};
|
|
8367
|
+
for (const [key, value] of Object.entries(source)) {
|
|
8368
|
+
if (value === null && isNullableColumn(model, key)) {
|
|
8369
|
+
result[key] = nullishValue;
|
|
8370
|
+
continue;
|
|
8371
|
+
}
|
|
8372
|
+
result[key] = value;
|
|
7082
8373
|
}
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
8374
|
+
return result;
|
|
8375
|
+
}
|
|
8376
|
+
function toModelPayload(model, formValues, options) {
|
|
8377
|
+
const emptyStringAsNull = options?.emptyStringAsNull ?? true;
|
|
8378
|
+
const stripUndefined = options?.stripUndefined ?? true;
|
|
8379
|
+
const result = {};
|
|
8380
|
+
for (const [key, rawValue] of Object.entries(formValues)) {
|
|
8381
|
+
if (rawValue === void 0 && stripUndefined) {
|
|
8382
|
+
continue;
|
|
7086
8383
|
}
|
|
7087
|
-
if (
|
|
7088
|
-
|
|
8384
|
+
if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
|
|
8385
|
+
result[key] = null;
|
|
8386
|
+
continue;
|
|
7089
8387
|
}
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
8388
|
+
result[key] = rawValue;
|
|
8389
|
+
}
|
|
8390
|
+
return result;
|
|
8391
|
+
}
|
|
8392
|
+
function createModelFormAdapter(model) {
|
|
8393
|
+
return {
|
|
8394
|
+
model,
|
|
8395
|
+
toDefaults(values, options) {
|
|
8396
|
+
return toModelFormDefaults(model, values, options);
|
|
8397
|
+
},
|
|
8398
|
+
toInsert(values, options) {
|
|
8399
|
+
return toModelPayload(model, values, options);
|
|
8400
|
+
},
|
|
8401
|
+
toUpdate(values, options) {
|
|
8402
|
+
return toModelPayload(model, values, options);
|
|
7095
8403
|
}
|
|
7096
|
-
|
|
7097
|
-
|
|
8404
|
+
};
|
|
8405
|
+
}
|
|
8406
|
+
|
|
8407
|
+
// src/schema/table-columns.ts
|
|
8408
|
+
var COLUMN_CONFIG = /* @__PURE__ */ Symbol("athena.column.config");
|
|
8409
|
+
function createColumnBuilder(config) {
|
|
8410
|
+
return {
|
|
8411
|
+
[COLUMN_CONFIG]: config,
|
|
8412
|
+
optional() {
|
|
8413
|
+
return createColumnBuilder({
|
|
8414
|
+
...config,
|
|
8415
|
+
nullable: true
|
|
8416
|
+
});
|
|
8417
|
+
},
|
|
8418
|
+
from(columnName) {
|
|
8419
|
+
return createColumnBuilder({
|
|
8420
|
+
...config,
|
|
8421
|
+
columnName
|
|
8422
|
+
});
|
|
8423
|
+
},
|
|
8424
|
+
defaulted() {
|
|
8425
|
+
return createColumnBuilder({
|
|
8426
|
+
...config,
|
|
8427
|
+
hasDefault: true
|
|
8428
|
+
});
|
|
8429
|
+
},
|
|
8430
|
+
generated() {
|
|
8431
|
+
return createColumnBuilder({
|
|
8432
|
+
...config,
|
|
8433
|
+
isGenerated: true
|
|
8434
|
+
});
|
|
7098
8435
|
}
|
|
7099
|
-
|
|
7100
|
-
|
|
8436
|
+
};
|
|
8437
|
+
}
|
|
8438
|
+
function isColumnBuilder(value) {
|
|
8439
|
+
return value !== null && typeof value === "object" && COLUMN_CONFIG in value;
|
|
8440
|
+
}
|
|
8441
|
+
function getColumnConfig(column) {
|
|
8442
|
+
return column[COLUMN_CONFIG];
|
|
8443
|
+
}
|
|
8444
|
+
function string() {
|
|
8445
|
+
return createColumnBuilder({
|
|
8446
|
+
kind: "string",
|
|
8447
|
+
nullable: false,
|
|
8448
|
+
hasDefault: false,
|
|
8449
|
+
isGenerated: false
|
|
8450
|
+
});
|
|
8451
|
+
}
|
|
8452
|
+
function number() {
|
|
8453
|
+
return createColumnBuilder({
|
|
8454
|
+
kind: "number",
|
|
8455
|
+
nullable: false,
|
|
8456
|
+
hasDefault: false,
|
|
8457
|
+
isGenerated: false
|
|
8458
|
+
});
|
|
8459
|
+
}
|
|
8460
|
+
function boolean() {
|
|
8461
|
+
return createColumnBuilder({
|
|
8462
|
+
kind: "boolean",
|
|
8463
|
+
nullable: false,
|
|
8464
|
+
hasDefault: false,
|
|
8465
|
+
isGenerated: false
|
|
8466
|
+
});
|
|
8467
|
+
}
|
|
8468
|
+
function json(schema) {
|
|
8469
|
+
return createColumnBuilder({
|
|
8470
|
+
kind: "json",
|
|
8471
|
+
nullable: false,
|
|
8472
|
+
hasDefault: false,
|
|
8473
|
+
isGenerated: false,
|
|
8474
|
+
jsonSchema: schema
|
|
8475
|
+
});
|
|
8476
|
+
}
|
|
8477
|
+
function enumeration(values) {
|
|
8478
|
+
if (values.length === 0) {
|
|
8479
|
+
throw new Error("enumeration() requires at least one value");
|
|
8480
|
+
}
|
|
8481
|
+
return createColumnBuilder({
|
|
8482
|
+
kind: "enumeration",
|
|
8483
|
+
nullable: false,
|
|
8484
|
+
hasDefault: false,
|
|
8485
|
+
isGenerated: false,
|
|
8486
|
+
enumValues: values
|
|
8487
|
+
});
|
|
8488
|
+
}
|
|
8489
|
+
|
|
8490
|
+
// src/schema/table-schemas.ts
|
|
8491
|
+
function isScalarFormKind(kind) {
|
|
8492
|
+
return kind === "string" || kind === "number" || kind === "boolean" || kind === "enumeration";
|
|
8493
|
+
}
|
|
8494
|
+
function createBaseSchema(column) {
|
|
8495
|
+
const config = getColumnConfig(column);
|
|
8496
|
+
switch (config.kind) {
|
|
8497
|
+
case "boolean":
|
|
8498
|
+
return z.boolean();
|
|
8499
|
+
case "number":
|
|
8500
|
+
return z.number();
|
|
8501
|
+
case "json":
|
|
8502
|
+
return config.jsonSchema ?? z.unknown();
|
|
8503
|
+
case "enumeration":
|
|
8504
|
+
if (!config.enumValues || config.enumValues.length === 0) {
|
|
8505
|
+
return z.string();
|
|
8506
|
+
}
|
|
8507
|
+
return z.enum(config.enumValues);
|
|
8508
|
+
case "string":
|
|
8509
|
+
default:
|
|
8510
|
+
return z.string();
|
|
8511
|
+
}
|
|
8512
|
+
}
|
|
8513
|
+
function applyNullable(schema, column) {
|
|
8514
|
+
const config = getColumnConfig(column);
|
|
8515
|
+
return config.nullable ? schema.nullable() : schema;
|
|
8516
|
+
}
|
|
8517
|
+
function applyInsertOptional(schema, column) {
|
|
8518
|
+
const config = getColumnConfig(column);
|
|
8519
|
+
return config.nullable || config.hasDefault ? schema.optional() : schema;
|
|
8520
|
+
}
|
|
8521
|
+
function createFormFieldSchema(column) {
|
|
8522
|
+
const config = getColumnConfig(column);
|
|
8523
|
+
const base = createBaseSchema(column);
|
|
8524
|
+
let schema;
|
|
8525
|
+
if (config.nullable && isScalarFormKind(config.kind)) {
|
|
8526
|
+
schema = z.union([base, z.literal("")]).transform((value) => value === "" ? null : value);
|
|
8527
|
+
} else {
|
|
8528
|
+
schema = applyNullable(base, column);
|
|
8529
|
+
}
|
|
8530
|
+
if (config.nullable || config.hasDefault) {
|
|
8531
|
+
schema = schema.optional();
|
|
8532
|
+
}
|
|
8533
|
+
return schema;
|
|
8534
|
+
}
|
|
8535
|
+
function buildTableSchemaBundle(model, columns) {
|
|
8536
|
+
const rowShape = {};
|
|
8537
|
+
const insertShape = {};
|
|
8538
|
+
const updateShape = {};
|
|
8539
|
+
const formShape = {};
|
|
8540
|
+
for (const [columnName, column] of Object.entries(columns)) {
|
|
8541
|
+
const config = getColumnConfig(column);
|
|
8542
|
+
const base = createBaseSchema(column);
|
|
8543
|
+
rowShape[columnName] = applyNullable(base, column);
|
|
8544
|
+
if (config.isGenerated) {
|
|
8545
|
+
continue;
|
|
7101
8546
|
}
|
|
7102
|
-
|
|
8547
|
+
insertShape[columnName] = applyInsertOptional(applyNullable(base, column), column);
|
|
8548
|
+
updateShape[columnName] = applyNullable(base, column).optional();
|
|
8549
|
+
formShape[columnName] = createFormFieldSchema(column);
|
|
7103
8550
|
}
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
8551
|
+
const rowSchema = z.object(rowShape);
|
|
8552
|
+
const insertSchema = z.object(insertShape);
|
|
8553
|
+
const updateSchema = z.object(updateShape);
|
|
8554
|
+
const formSchema = z.object(formShape).transform((value) => toModelPayload(model, value));
|
|
8555
|
+
return {
|
|
8556
|
+
row: rowSchema,
|
|
8557
|
+
insert: insertSchema,
|
|
8558
|
+
update: updateSchema,
|
|
8559
|
+
form: formSchema
|
|
8560
|
+
};
|
|
8561
|
+
}
|
|
8562
|
+
|
|
8563
|
+
// src/schema/table-builder.ts
|
|
8564
|
+
function assertColumnRecord(columns) {
|
|
8565
|
+
for (const [columnName, column] of Object.entries(columns)) {
|
|
8566
|
+
if (!isColumnBuilder(column)) {
|
|
8567
|
+
throw new Error(`Invalid column definition for "${columnName}"`);
|
|
7107
8568
|
}
|
|
7108
|
-
return createClientFromConfig({
|
|
7109
|
-
baseUrl: this.baseUrl,
|
|
7110
|
-
apiKey: this.apiKey,
|
|
7111
|
-
client: this.clientName,
|
|
7112
|
-
backend: this.backendConfig,
|
|
7113
|
-
headers: this.defaultHeaders,
|
|
7114
|
-
auth: this.authConfig,
|
|
7115
|
-
experimental: this.experimentalOptions
|
|
7116
|
-
});
|
|
7117
8569
|
}
|
|
7118
|
-
}
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
8570
|
+
}
|
|
8571
|
+
function normalizeMappedNameInput(mappedName) {
|
|
8572
|
+
const normalized = mappedName.trim();
|
|
8573
|
+
if (!normalized) {
|
|
8574
|
+
throw new Error("table.from() requires a non-empty table name");
|
|
8575
|
+
}
|
|
8576
|
+
return normalized;
|
|
8577
|
+
}
|
|
8578
|
+
function normalizeSchemaNameInput(schemaName) {
|
|
8579
|
+
const normalized = schemaName.trim();
|
|
8580
|
+
if (!normalized) {
|
|
8581
|
+
throw new Error("table.schema() requires a non-empty schema name");
|
|
8582
|
+
}
|
|
8583
|
+
if (normalized.includes(".")) {
|
|
8584
|
+
throw new Error(
|
|
8585
|
+
'table.schema() expects a schema name without dots. Use .schema("schema").from("table") or .from("schema.table").'
|
|
8586
|
+
);
|
|
8587
|
+
}
|
|
8588
|
+
return normalized;
|
|
8589
|
+
}
|
|
8590
|
+
function resolveTableTarget(logicalName, mappedName, explicitSchemaName) {
|
|
8591
|
+
const physicalName = (mappedName ?? logicalName).trim();
|
|
8592
|
+
if (!physicalName) {
|
|
8593
|
+
throw new Error("table() requires a non-empty name");
|
|
7123
8594
|
}
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
const
|
|
7128
|
-
|
|
8595
|
+
const firstDot = physicalName.indexOf(".");
|
|
8596
|
+
const lastDot = physicalName.lastIndexOf(".");
|
|
8597
|
+
if (firstDot > 0 && firstDot === lastDot) {
|
|
8598
|
+
const inlineSchema = physicalName.slice(0, firstDot).trim();
|
|
8599
|
+
const inlineModel = physicalName.slice(firstDot + 1).trim();
|
|
8600
|
+
if (!inlineSchema || !inlineModel) {
|
|
8601
|
+
throw new Error('table.from() schema-qualified names must look like "schema.table"');
|
|
8602
|
+
}
|
|
8603
|
+
if (explicitSchemaName && explicitSchemaName !== inlineSchema) {
|
|
7129
8604
|
throw new Error(
|
|
7130
|
-
|
|
8605
|
+
`table schema "${explicitSchemaName}" conflicts with mapped table "${physicalName}"`
|
|
7131
8606
|
);
|
|
7132
8607
|
}
|
|
7133
|
-
return
|
|
8608
|
+
return {
|
|
8609
|
+
schema: explicitSchemaName ?? inlineSchema,
|
|
8610
|
+
model: inlineModel,
|
|
8611
|
+
qualifiedName: `${explicitSchemaName ?? inlineSchema}.${inlineModel}`
|
|
8612
|
+
};
|
|
7134
8613
|
}
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
}
|
|
8614
|
+
if (explicitSchemaName) {
|
|
8615
|
+
return {
|
|
8616
|
+
schema: explicitSchemaName,
|
|
8617
|
+
model: physicalName,
|
|
8618
|
+
qualifiedName: `${explicitSchemaName}.${physicalName}`
|
|
8619
|
+
};
|
|
8620
|
+
}
|
|
8621
|
+
return {
|
|
8622
|
+
model: physicalName,
|
|
8623
|
+
qualifiedName: physicalName
|
|
8624
|
+
};
|
|
7146
8625
|
}
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
function defineModel(input) {
|
|
7158
|
-
return input;
|
|
8626
|
+
function toColumnMetadata(column) {
|
|
8627
|
+
const config = getColumnConfig(column);
|
|
8628
|
+
return {
|
|
8629
|
+
kind: config.kind,
|
|
8630
|
+
columnName: config.columnName,
|
|
8631
|
+
nullable: config.nullable,
|
|
8632
|
+
hasDefault: config.hasDefault,
|
|
8633
|
+
isGenerated: config.isGenerated,
|
|
8634
|
+
enumValues: config.enumValues
|
|
8635
|
+
};
|
|
7159
8636
|
}
|
|
7160
|
-
function
|
|
7161
|
-
return
|
|
8637
|
+
function buildNullableMap(columns) {
|
|
8638
|
+
return Object.fromEntries(
|
|
8639
|
+
Object.entries(columns).map(([columnName, column]) => [columnName, getColumnConfig(column).nullable])
|
|
8640
|
+
);
|
|
7162
8641
|
}
|
|
7163
|
-
function
|
|
7164
|
-
return
|
|
8642
|
+
function buildColumnMetadataMap(columns) {
|
|
8643
|
+
return Object.fromEntries(
|
|
8644
|
+
Object.entries(columns).map(([columnName, column]) => [columnName, toColumnMetadata(column)])
|
|
8645
|
+
);
|
|
7165
8646
|
}
|
|
7166
|
-
function
|
|
7167
|
-
|
|
8647
|
+
function finalizeTable(name, mappedName, schemaName, columns, primaryKey) {
|
|
8648
|
+
const target = resolveTableTarget(name, mappedName, schemaName);
|
|
8649
|
+
const model = defineModel({
|
|
8650
|
+
meta: {
|
|
8651
|
+
schema: target.schema,
|
|
8652
|
+
model: target.model,
|
|
8653
|
+
primaryKey: [...primaryKey],
|
|
8654
|
+
nullable: buildNullableMap(columns),
|
|
8655
|
+
columns: buildColumnMetadataMap(columns)
|
|
8656
|
+
}
|
|
8657
|
+
});
|
|
8658
|
+
const schemas = buildTableSchemaBundle(model, columns);
|
|
8659
|
+
return Object.assign(model, {
|
|
8660
|
+
kind: "table",
|
|
8661
|
+
name,
|
|
8662
|
+
mappedName,
|
|
8663
|
+
schemaName: target.schema,
|
|
8664
|
+
tableName: target.model,
|
|
8665
|
+
qualifiedName: target.qualifiedName,
|
|
8666
|
+
columns,
|
|
8667
|
+
schemas
|
|
8668
|
+
});
|
|
8669
|
+
}
|
|
8670
|
+
function createColumnsBuilder(name, mappedName, schemaName, columns) {
|
|
8671
|
+
assertColumnRecord(columns);
|
|
8672
|
+
return {
|
|
8673
|
+
name,
|
|
8674
|
+
mappedName,
|
|
8675
|
+
schemaName,
|
|
8676
|
+
columns,
|
|
8677
|
+
from(tableName) {
|
|
8678
|
+
const normalizedTableName = normalizeMappedNameInput(tableName);
|
|
8679
|
+
resolveTableTarget(name, normalizedTableName, schemaName);
|
|
8680
|
+
return createColumnsBuilder(name, normalizedTableName, schemaName, columns);
|
|
8681
|
+
},
|
|
8682
|
+
schema(nextSchemaName) {
|
|
8683
|
+
const normalizedSchemaName = normalizeSchemaNameInput(nextSchemaName);
|
|
8684
|
+
resolveTableTarget(name, mappedName, normalizedSchemaName);
|
|
8685
|
+
return createColumnsBuilder(name, mappedName, normalizedSchemaName, columns);
|
|
8686
|
+
},
|
|
8687
|
+
primaryKey(...keys) {
|
|
8688
|
+
return finalizeTable(name, mappedName, schemaName, columns, keys);
|
|
8689
|
+
}
|
|
8690
|
+
};
|
|
8691
|
+
}
|
|
8692
|
+
function createTableBuilder2(name, mappedName, schemaName) {
|
|
8693
|
+
return {
|
|
8694
|
+
name,
|
|
8695
|
+
mappedName,
|
|
8696
|
+
schemaName,
|
|
8697
|
+
from(tableName) {
|
|
8698
|
+
const normalizedTableName = normalizeMappedNameInput(tableName);
|
|
8699
|
+
resolveTableTarget(name, normalizedTableName, schemaName);
|
|
8700
|
+
return createTableBuilder2(name, normalizedTableName, schemaName);
|
|
8701
|
+
},
|
|
8702
|
+
schema(nextSchemaName) {
|
|
8703
|
+
const normalizedSchemaName = normalizeSchemaNameInput(nextSchemaName);
|
|
8704
|
+
resolveTableTarget(name, mappedName, normalizedSchemaName);
|
|
8705
|
+
return createTableBuilder2(name, mappedName, normalizedSchemaName);
|
|
8706
|
+
},
|
|
8707
|
+
columns(columns) {
|
|
8708
|
+
return createColumnsBuilder(name, mappedName, schemaName, columns);
|
|
8709
|
+
}
|
|
8710
|
+
};
|
|
8711
|
+
}
|
|
8712
|
+
function table(name) {
|
|
8713
|
+
if (!name.trim()) {
|
|
8714
|
+
throw new Error("table() requires a non-empty name");
|
|
8715
|
+
}
|
|
8716
|
+
return createTableBuilder2(name, void 0, void 0);
|
|
7168
8717
|
}
|
|
7169
8718
|
|
|
7170
8719
|
// src/schema/typed-client.ts
|
|
@@ -7206,12 +8755,10 @@ var RegistryNavigator = class {
|
|
|
7206
8755
|
return modelDef;
|
|
7207
8756
|
}
|
|
7208
8757
|
resolveTableName(schema, model, modelDef) {
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
const modelName = modelDef.meta.model ?? model;
|
|
7214
|
-
return `${schemaName}.${modelName}`;
|
|
8758
|
+
return resolveAthenaModelTargetTableName(modelDef, {
|
|
8759
|
+
fallbackSchema: schema,
|
|
8760
|
+
fallbackModel: model
|
|
8761
|
+
});
|
|
7215
8762
|
}
|
|
7216
8763
|
};
|
|
7217
8764
|
var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
@@ -7238,17 +8785,20 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
7238
8785
|
this.clientOptions = {
|
|
7239
8786
|
backend: input.options?.backend,
|
|
7240
8787
|
client: input.options?.client,
|
|
7241
|
-
headers: input.options?.headers
|
|
8788
|
+
headers: input.options?.headers,
|
|
8789
|
+
experimental: input.options?.experimental
|
|
7242
8790
|
};
|
|
7243
8791
|
this.baseClient = createClient(this.url, this.apiKey, {
|
|
7244
8792
|
backend: this.clientOptions.backend,
|
|
7245
8793
|
client: this.clientOptions.client,
|
|
7246
|
-
headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext)
|
|
8794
|
+
headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext),
|
|
8795
|
+
experimental: this.clientOptions.experimental
|
|
7247
8796
|
});
|
|
7248
8797
|
this.db = this.baseClient.db;
|
|
7249
8798
|
}
|
|
7250
|
-
from(
|
|
7251
|
-
|
|
8799
|
+
from(tableOrModel, options) {
|
|
8800
|
+
const from = this.baseClient.from;
|
|
8801
|
+
return from(tableOrModel, options);
|
|
7252
8802
|
}
|
|
7253
8803
|
rpc(fn, args, options) {
|
|
7254
8804
|
return this.baseClient.rpc(fn, args, options);
|
|
@@ -7270,7 +8820,8 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
7270
8820
|
tenantContext: {
|
|
7271
8821
|
...this.tenantContext,
|
|
7272
8822
|
...context ?? {}
|
|
7273
|
-
}
|
|
8823
|
+
},
|
|
8824
|
+
experimental: this.clientOptions.experimental
|
|
7274
8825
|
}
|
|
7275
8826
|
});
|
|
7276
8827
|
}
|
|
@@ -7376,8 +8927,8 @@ var POSTGRES_CATALOG_SQL = {
|
|
|
7376
8927
|
ORDER BY sn.nspname, sc.relname, con.conname;
|
|
7377
8928
|
`
|
|
7378
8929
|
};
|
|
7379
|
-
function tableKey(schema,
|
|
7380
|
-
return `${schema}.${
|
|
8930
|
+
function tableKey(schema, table2) {
|
|
8931
|
+
return `${schema}.${table2}`;
|
|
7381
8932
|
}
|
|
7382
8933
|
function relationKey(...parts) {
|
|
7383
8934
|
const base = parts.join("_").replace(/[^A-Za-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
@@ -7488,8 +9039,8 @@ var PostgresCatalogSnapshotAssembler = class {
|
|
|
7488
9039
|
schemas = {};
|
|
7489
9040
|
addColumnRows(columnRows, enumMap) {
|
|
7490
9041
|
for (const row of columnRows) {
|
|
7491
|
-
const
|
|
7492
|
-
|
|
9042
|
+
const table2 = this.ensureTable(row.schema_name, row.table_name);
|
|
9043
|
+
table2.columns[row.column_name] = {
|
|
7493
9044
|
name: row.column_name,
|
|
7494
9045
|
dataType: row.data_type,
|
|
7495
9046
|
udtName: row.udt_name,
|
|
@@ -7505,12 +9056,12 @@ var PostgresCatalogSnapshotAssembler = class {
|
|
|
7505
9056
|
}
|
|
7506
9057
|
addPrimaryKeyRows(primaryKeyRows) {
|
|
7507
9058
|
for (const row of primaryKeyRows) {
|
|
7508
|
-
const
|
|
9059
|
+
const table2 = this.ensureTable(row.schema_name, row.table_name);
|
|
7509
9060
|
const primaryKeyColumns = coerceStringArray(row.columns);
|
|
7510
9061
|
row.columns = primaryKeyColumns;
|
|
7511
|
-
|
|
9062
|
+
table2.primaryKey = primaryKeyColumns;
|
|
7512
9063
|
for (const columnName of primaryKeyColumns) {
|
|
7513
|
-
const column =
|
|
9064
|
+
const column = table2.columns[columnName];
|
|
7514
9065
|
if (column) {
|
|
7515
9066
|
column.isPrimaryKey = true;
|
|
7516
9067
|
}
|
|
@@ -7626,14 +9177,14 @@ var PostgresCatalogSnapshotAssembler = class {
|
|
|
7626
9177
|
}
|
|
7627
9178
|
return schema.tables[tableName];
|
|
7628
9179
|
}
|
|
7629
|
-
upsertRelation(
|
|
9180
|
+
upsertRelation(table2, baseKey, relation) {
|
|
7630
9181
|
let key = baseKey;
|
|
7631
9182
|
let suffix = 2;
|
|
7632
|
-
while (
|
|
9183
|
+
while (table2.relations[key]) {
|
|
7633
9184
|
key = `${baseKey}_${suffix}`;
|
|
7634
9185
|
suffix += 1;
|
|
7635
9186
|
}
|
|
7636
|
-
|
|
9187
|
+
table2.relations[key] = relation;
|
|
7637
9188
|
}
|
|
7638
9189
|
};
|
|
7639
9190
|
|
|
@@ -7724,67 +9275,6 @@ function createPostgresIntrospectionProvider(options) {
|
|
|
7724
9275
|
return new PostgresIntrospectionProvider(options);
|
|
7725
9276
|
}
|
|
7726
9277
|
|
|
7727
|
-
// src/schema/model-form.ts
|
|
7728
|
-
function resolveNullishValue(mode) {
|
|
7729
|
-
if (mode === "undefined") return void 0;
|
|
7730
|
-
if (mode === "null") return null;
|
|
7731
|
-
return "";
|
|
7732
|
-
}
|
|
7733
|
-
function isRecord10(value) {
|
|
7734
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7735
|
-
}
|
|
7736
|
-
function isNullableColumn(model, key) {
|
|
7737
|
-
const nullable = model.meta.nullable;
|
|
7738
|
-
return nullable?.[key] === true;
|
|
7739
|
-
}
|
|
7740
|
-
function toModelFormDefaults(model, values, options) {
|
|
7741
|
-
const source = values;
|
|
7742
|
-
if (!isRecord10(source)) {
|
|
7743
|
-
return {};
|
|
7744
|
-
}
|
|
7745
|
-
const mode = options?.nullishMode ?? "empty-string";
|
|
7746
|
-
const nullishValue = resolveNullishValue(mode);
|
|
7747
|
-
const result = {};
|
|
7748
|
-
for (const [key, value] of Object.entries(source)) {
|
|
7749
|
-
if (value === null && isNullableColumn(model, key)) {
|
|
7750
|
-
result[key] = nullishValue;
|
|
7751
|
-
continue;
|
|
7752
|
-
}
|
|
7753
|
-
result[key] = value;
|
|
7754
|
-
}
|
|
7755
|
-
return result;
|
|
7756
|
-
}
|
|
7757
|
-
function toModelPayload(model, formValues, options) {
|
|
7758
|
-
const emptyStringAsNull = options?.emptyStringAsNull ?? true;
|
|
7759
|
-
const stripUndefined = options?.stripUndefined ?? true;
|
|
7760
|
-
const result = {};
|
|
7761
|
-
for (const [key, rawValue] of Object.entries(formValues)) {
|
|
7762
|
-
if (rawValue === void 0 && stripUndefined) {
|
|
7763
|
-
continue;
|
|
7764
|
-
}
|
|
7765
|
-
if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
|
|
7766
|
-
result[key] = null;
|
|
7767
|
-
continue;
|
|
7768
|
-
}
|
|
7769
|
-
result[key] = rawValue;
|
|
7770
|
-
}
|
|
7771
|
-
return result;
|
|
7772
|
-
}
|
|
7773
|
-
function createModelFormAdapter(model) {
|
|
7774
|
-
return {
|
|
7775
|
-
model,
|
|
7776
|
-
toDefaults(values, options) {
|
|
7777
|
-
return toModelFormDefaults(model, values, options);
|
|
7778
|
-
},
|
|
7779
|
-
toInsert(values, options) {
|
|
7780
|
-
return toModelPayload(model, values, options);
|
|
7781
|
-
},
|
|
7782
|
-
toUpdate(values, options) {
|
|
7783
|
-
return toModelPayload(model, values, options);
|
|
7784
|
-
}
|
|
7785
|
-
};
|
|
7786
|
-
}
|
|
7787
|
-
|
|
7788
9278
|
// src/generator/schema-selection.ts
|
|
7789
9279
|
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
7790
9280
|
function collectSchemaNames(input) {
|
|
@@ -7830,6 +9320,7 @@ var DEFAULT_TARGETS = {
|
|
|
7830
9320
|
database: "athena/relations.ts",
|
|
7831
9321
|
registry: "athena/config.ts"
|
|
7832
9322
|
};
|
|
9323
|
+
var DEFAULT_OUTPUT_FORMAT = "define-model";
|
|
7833
9324
|
var DEFAULT_NAMING = {
|
|
7834
9325
|
modelType: "pascal",
|
|
7835
9326
|
modelConst: "camel",
|
|
@@ -7845,6 +9336,9 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
7845
9336
|
postgresGatewayIntrospection: false,
|
|
7846
9337
|
scyllaProviderContracts: true
|
|
7847
9338
|
};
|
|
9339
|
+
var DEFAULT_INTERNAL_CONFIG = {
|
|
9340
|
+
schemaVersion: 1
|
|
9341
|
+
};
|
|
7848
9342
|
var PROJECT_ENV_FILENAMES = [".env", ".env.local"];
|
|
7849
9343
|
var DIRECT_CONNECTION_STRING_ENV_KEYS = [
|
|
7850
9344
|
"ATHENA_GENERATOR_PG_URL",
|
|
@@ -7861,6 +9355,27 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
7861
9355
|
"ATHENA_GATEWAY_API_KEY",
|
|
7862
9356
|
"ATHENA_GENERATOR_API_KEY"
|
|
7863
9357
|
];
|
|
9358
|
+
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
9359
|
+
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
9360
|
+
var MODEL_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TARGET"];
|
|
9361
|
+
var SCHEMA_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_TARGET"];
|
|
9362
|
+
var DATABASE_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_TARGET"];
|
|
9363
|
+
var REGISTRY_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_TARGET"];
|
|
9364
|
+
var PLACEHOLDER_MAP_ENV_KEYS = ["ATHENA_GENERATOR_PLACEHOLDER_MAP"];
|
|
9365
|
+
var MODEL_TYPE_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TYPE", "ATHENA_GENERATOR_MODEL_STYLE"];
|
|
9366
|
+
var MODEL_CONST_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_CONST"];
|
|
9367
|
+
var SCHEMA_CONST_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_CONST"];
|
|
9368
|
+
var DATABASE_CONST_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_CONST"];
|
|
9369
|
+
var REGISTRY_CONST_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_CONST"];
|
|
9370
|
+
var EMIT_RELATIONS_ENV_KEYS = ["ATHENA_GENERATOR_EMIT_RELATIONS"];
|
|
9371
|
+
var EMIT_REGISTRY_ENV_KEYS = ["ATHENA_GENERATOR_EMIT_REGISTRY"];
|
|
9372
|
+
var GATEWAY_BACKEND_ENV_KEYS = ["ATHENA_GENERATOR_BACKEND"];
|
|
9373
|
+
var GATEWAY_EXPERIMENTAL_ENV_KEYS = ["ATHENA_GENERATOR_GATEWAY_EXPERIMENTAL"];
|
|
9374
|
+
var SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS = ["ATHENA_GENERATOR_SCYLLA_PROVIDER_CONTRACTS"];
|
|
9375
|
+
var ENV_ONLY_CONFIG_PATH = "[environment defaults]";
|
|
9376
|
+
var NAMING_STYLE_VALUES = ["preserve", "camel", "pascal", "snake", "kebab"];
|
|
9377
|
+
var OUTPUT_FORMAT_VALUES = ["define-model", "table-builder"];
|
|
9378
|
+
var BACKEND_TYPE_VALUES = ["athena", "postgrest", "postgresql", "scylladb"];
|
|
7864
9379
|
function normalizeRawEnvValue(rawValue) {
|
|
7865
9380
|
if (rawValue.startsWith('"') && rawValue.endsWith('"') && rawValue.length >= 2) {
|
|
7866
9381
|
const inner = rawValue.slice(1, -1);
|
|
@@ -7952,6 +9467,50 @@ function resolveFallbackValue(fallbackKeys) {
|
|
|
7952
9467
|
}
|
|
7953
9468
|
return void 0;
|
|
7954
9469
|
}
|
|
9470
|
+
function normalizeOneOfValue(rawValue, allowedValues, envKeys) {
|
|
9471
|
+
if (!rawValue) {
|
|
9472
|
+
return void 0;
|
|
9473
|
+
}
|
|
9474
|
+
if (allowedValues.includes(rawValue)) {
|
|
9475
|
+
return rawValue;
|
|
9476
|
+
}
|
|
9477
|
+
throw new Error(
|
|
9478
|
+
`Generator config env vars ${envKeys.join(", ")} must resolve to one of: ${allowedValues.join(", ")}. Received: ${rawValue}.`
|
|
9479
|
+
);
|
|
9480
|
+
}
|
|
9481
|
+
function resolveOptionalOneOf(envKeys, allowedValues) {
|
|
9482
|
+
return normalizeOneOfValue(resolveFallbackValue(envKeys), allowedValues, envKeys);
|
|
9483
|
+
}
|
|
9484
|
+
function resolveOptionalBoolean(envKeys) {
|
|
9485
|
+
const rawValue = resolveFallbackValue(envKeys);
|
|
9486
|
+
return rawValue === void 0 ? void 0 : parseBooleanFlag2(rawValue, false);
|
|
9487
|
+
}
|
|
9488
|
+
function resolveOptionalJson(envKeys) {
|
|
9489
|
+
const rawValue = resolveFallbackValue(envKeys);
|
|
9490
|
+
if (rawValue === void 0) {
|
|
9491
|
+
return void 0;
|
|
9492
|
+
}
|
|
9493
|
+
try {
|
|
9494
|
+
return JSON.parse(rawValue);
|
|
9495
|
+
} catch (error) {
|
|
9496
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9497
|
+
throw new Error(
|
|
9498
|
+
`Generator config env vars ${envKeys.join(", ")} must contain valid JSON. ${message}`
|
|
9499
|
+
);
|
|
9500
|
+
}
|
|
9501
|
+
}
|
|
9502
|
+
function deriveDatabaseNameFromConnectionString(connectionString) {
|
|
9503
|
+
try {
|
|
9504
|
+
const parsedUrl = new URL(connectionString);
|
|
9505
|
+
if (!POSTGRES_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
9506
|
+
return void 0;
|
|
9507
|
+
}
|
|
9508
|
+
const pathname = parsedUrl.pathname.replace(/^\/+/, "").trim();
|
|
9509
|
+
return pathname.length > 0 ? decodeURIComponent(pathname) : void 0;
|
|
9510
|
+
} catch {
|
|
9511
|
+
return void 0;
|
|
9512
|
+
}
|
|
9513
|
+
}
|
|
7955
9514
|
function normalizeOptionalString(value, fallbackKeys) {
|
|
7956
9515
|
if (typeof value === "string") {
|
|
7957
9516
|
const trimmed = value.trim();
|
|
@@ -8025,12 +9584,13 @@ function normalizeExperimentalFlags(input) {
|
|
|
8025
9584
|
}
|
|
8026
9585
|
function normalizeOutputConfig(output) {
|
|
8027
9586
|
return {
|
|
9587
|
+
format: output?.format ?? DEFAULT_OUTPUT_FORMAT,
|
|
8028
9588
|
targets: {
|
|
8029
9589
|
...DEFAULT_TARGETS,
|
|
8030
|
-
...output
|
|
9590
|
+
...output?.targets ?? {}
|
|
8031
9591
|
},
|
|
8032
9592
|
placeholderMap: {
|
|
8033
|
-
...output
|
|
9593
|
+
...output?.placeholderMap ?? {}
|
|
8034
9594
|
}
|
|
8035
9595
|
};
|
|
8036
9596
|
}
|
|
@@ -8041,7 +9601,7 @@ function normalizeProviderConfig(provider) {
|
|
|
8041
9601
|
"provider.connectionString",
|
|
8042
9602
|
DIRECT_CONNECTION_STRING_ENV_KEYS
|
|
8043
9603
|
);
|
|
8044
|
-
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS);
|
|
9604
|
+
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? deriveDatabaseNameFromConnectionString(connectionString);
|
|
8045
9605
|
return {
|
|
8046
9606
|
...provider,
|
|
8047
9607
|
connectionString: applyPostgresPasswordFallback(connectionString),
|
|
@@ -8060,11 +9620,7 @@ function normalizeProviderConfig(provider) {
|
|
|
8060
9620
|
"provider.apiKey",
|
|
8061
9621
|
GATEWAY_API_KEY_ENV_KEYS
|
|
8062
9622
|
);
|
|
8063
|
-
const database =
|
|
8064
|
-
provider.database,
|
|
8065
|
-
"provider.database",
|
|
8066
|
-
POSTGRES_DATABASE_ENV_KEYS
|
|
8067
|
-
);
|
|
9623
|
+
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
8068
9624
|
return {
|
|
8069
9625
|
...provider,
|
|
8070
9626
|
gatewayUrl,
|
|
@@ -8073,6 +9629,26 @@ function normalizeProviderConfig(provider) {
|
|
|
8073
9629
|
schemas: normalizeSchemaSelection(provider.schemas)
|
|
8074
9630
|
};
|
|
8075
9631
|
}
|
|
9632
|
+
if (provider.kind === "scylla" && provider.mode === "direct") {
|
|
9633
|
+
if (!provider.contactPoints?.length) {
|
|
9634
|
+
throw new Error(
|
|
9635
|
+
"Generator config is missing provider.contactPoints for scylla direct mode."
|
|
9636
|
+
);
|
|
9637
|
+
}
|
|
9638
|
+
const keyspace = normalizeOptionalString(provider.keyspace, []);
|
|
9639
|
+
if (!keyspace) {
|
|
9640
|
+
throw new Error(
|
|
9641
|
+
"Generator config is missing provider.keyspace for scylla direct mode."
|
|
9642
|
+
);
|
|
9643
|
+
}
|
|
9644
|
+
return {
|
|
9645
|
+
kind: "scylla",
|
|
9646
|
+
mode: "direct",
|
|
9647
|
+
contactPoints: provider.contactPoints.slice(),
|
|
9648
|
+
keyspace,
|
|
9649
|
+
datacenter: normalizeOptionalString(provider.datacenter, [])
|
|
9650
|
+
};
|
|
9651
|
+
}
|
|
8076
9652
|
return provider;
|
|
8077
9653
|
}
|
|
8078
9654
|
function isAthenaGeneratorConfig(value) {
|
|
@@ -8080,7 +9656,7 @@ function isAthenaGeneratorConfig(value) {
|
|
|
8080
9656
|
return false;
|
|
8081
9657
|
}
|
|
8082
9658
|
const record = value;
|
|
8083
|
-
return Boolean(record.provider && typeof record.provider === "object") &&
|
|
9659
|
+
return Boolean(record.provider && typeof record.provider === "object") && (record.output === void 0 || typeof record.output === "object");
|
|
8084
9660
|
}
|
|
8085
9661
|
function normalizeGeneratorConfig(input) {
|
|
8086
9662
|
return {
|
|
@@ -8091,7 +9667,10 @@ function normalizeGeneratorConfig(input) {
|
|
|
8091
9667
|
...input.naming ?? {}
|
|
8092
9668
|
},
|
|
8093
9669
|
features: normalizeFeatureFlags(input.features),
|
|
8094
|
-
experimental: normalizeExperimentalFlags(input.experimental)
|
|
9670
|
+
experimental: normalizeExperimentalFlags(input.experimental),
|
|
9671
|
+
internal: {
|
|
9672
|
+
...DEFAULT_INTERNAL_CONFIG
|
|
9673
|
+
}
|
|
8095
9674
|
};
|
|
8096
9675
|
}
|
|
8097
9676
|
function defineGeneratorConfig(config) {
|
|
@@ -8148,16 +9727,123 @@ function importConfigModule(moduleSpecifier) {
|
|
|
8148
9727
|
);
|
|
8149
9728
|
return runtimeImport(moduleSpecifier);
|
|
8150
9729
|
}
|
|
9730
|
+
function buildEnvironmentOutputConfig() {
|
|
9731
|
+
const format = resolveOptionalOneOf(OUTPUT_FORMAT_ENV_KEYS, OUTPUT_FORMAT_VALUES);
|
|
9732
|
+
const modelTarget = resolveFallbackValue(MODEL_TARGET_ENV_KEYS);
|
|
9733
|
+
const schemaTarget = resolveFallbackValue(SCHEMA_TARGET_ENV_KEYS);
|
|
9734
|
+
const databaseTarget = resolveFallbackValue(DATABASE_TARGET_ENV_KEYS);
|
|
9735
|
+
const registryTarget = resolveFallbackValue(REGISTRY_TARGET_ENV_KEYS);
|
|
9736
|
+
const placeholderMap = resolveOptionalJson(PLACEHOLDER_MAP_ENV_KEYS);
|
|
9737
|
+
if (format === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
9738
|
+
return void 0;
|
|
9739
|
+
}
|
|
9740
|
+
return {
|
|
9741
|
+
format,
|
|
9742
|
+
targets: {
|
|
9743
|
+
...modelTarget ? { model: modelTarget } : {},
|
|
9744
|
+
...schemaTarget ? { schema: schemaTarget } : {},
|
|
9745
|
+
...databaseTarget ? { database: databaseTarget } : {},
|
|
9746
|
+
...registryTarget ? { registry: registryTarget } : {}
|
|
9747
|
+
},
|
|
9748
|
+
placeholderMap
|
|
9749
|
+
};
|
|
9750
|
+
}
|
|
9751
|
+
function buildEnvironmentNamingConfig() {
|
|
9752
|
+
const modelType = resolveOptionalOneOf(MODEL_TYPE_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9753
|
+
const modelConst = resolveOptionalOneOf(MODEL_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9754
|
+
const schemaConst = resolveOptionalOneOf(SCHEMA_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9755
|
+
const databaseConst = resolveOptionalOneOf(DATABASE_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9756
|
+
const registryConst = resolveOptionalOneOf(REGISTRY_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9757
|
+
if (modelType === void 0 && modelConst === void 0 && schemaConst === void 0 && databaseConst === void 0 && registryConst === void 0) {
|
|
9758
|
+
return void 0;
|
|
9759
|
+
}
|
|
9760
|
+
return {
|
|
9761
|
+
...modelType ? { modelType } : {},
|
|
9762
|
+
...modelConst ? { modelConst } : {},
|
|
9763
|
+
...schemaConst ? { schemaConst } : {},
|
|
9764
|
+
...databaseConst ? { databaseConst } : {},
|
|
9765
|
+
...registryConst ? { registryConst } : {}
|
|
9766
|
+
};
|
|
9767
|
+
}
|
|
9768
|
+
function buildEnvironmentFeatureFlags() {
|
|
9769
|
+
const emitRelations = resolveOptionalBoolean(EMIT_RELATIONS_ENV_KEYS);
|
|
9770
|
+
const emitRegistry = resolveOptionalBoolean(EMIT_REGISTRY_ENV_KEYS);
|
|
9771
|
+
if (emitRelations === void 0 && emitRegistry === void 0) {
|
|
9772
|
+
return void 0;
|
|
9773
|
+
}
|
|
9774
|
+
return {
|
|
9775
|
+
...emitRelations !== void 0 ? { emitRelations } : {},
|
|
9776
|
+
...emitRegistry !== void 0 ? { emitRegistry } : {}
|
|
9777
|
+
};
|
|
9778
|
+
}
|
|
9779
|
+
function buildEnvironmentExperimentalFlags() {
|
|
9780
|
+
const postgresGatewayIntrospection = resolveOptionalBoolean(GATEWAY_EXPERIMENTAL_ENV_KEYS);
|
|
9781
|
+
const scyllaProviderContracts = resolveOptionalBoolean(SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS);
|
|
9782
|
+
if (postgresGatewayIntrospection === void 0 && scyllaProviderContracts === void 0) {
|
|
9783
|
+
return void 0;
|
|
9784
|
+
}
|
|
9785
|
+
return {
|
|
9786
|
+
...postgresGatewayIntrospection !== void 0 ? { postgresGatewayIntrospection } : {},
|
|
9787
|
+
...scyllaProviderContracts !== void 0 ? { scyllaProviderContracts } : {}
|
|
9788
|
+
};
|
|
9789
|
+
}
|
|
9790
|
+
function buildEnvironmentProviderConfig() {
|
|
9791
|
+
const directConnectionString = resolveFallbackValue(DIRECT_CONNECTION_STRING_ENV_KEYS);
|
|
9792
|
+
if (directConnectionString) {
|
|
9793
|
+
return {
|
|
9794
|
+
kind: "postgres",
|
|
9795
|
+
mode: "direct",
|
|
9796
|
+
connectionString: directConnectionString,
|
|
9797
|
+
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9798
|
+
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS))
|
|
9799
|
+
};
|
|
9800
|
+
}
|
|
9801
|
+
const gatewayUrl = resolveFallbackValue(GATEWAY_URL_ENV_KEYS);
|
|
9802
|
+
const apiKey = resolveFallbackValue(GATEWAY_API_KEY_ENV_KEYS);
|
|
9803
|
+
if (gatewayUrl && apiKey) {
|
|
9804
|
+
const backend = resolveOptionalOneOf(GATEWAY_BACKEND_ENV_KEYS, BACKEND_TYPE_VALUES);
|
|
9805
|
+
return {
|
|
9806
|
+
kind: "postgres",
|
|
9807
|
+
mode: "gateway",
|
|
9808
|
+
gatewayUrl,
|
|
9809
|
+
apiKey,
|
|
9810
|
+
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9811
|
+
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
9812
|
+
backend
|
|
9813
|
+
};
|
|
9814
|
+
}
|
|
9815
|
+
return void 0;
|
|
9816
|
+
}
|
|
9817
|
+
function createEnvironmentGeneratorConfig() {
|
|
9818
|
+
const provider = buildEnvironmentProviderConfig();
|
|
9819
|
+
if (!provider) {
|
|
9820
|
+
return void 0;
|
|
9821
|
+
}
|
|
9822
|
+
return {
|
|
9823
|
+
provider,
|
|
9824
|
+
output: buildEnvironmentOutputConfig(),
|
|
9825
|
+
naming: buildEnvironmentNamingConfig(),
|
|
9826
|
+
features: buildEnvironmentFeatureFlags(),
|
|
9827
|
+
experimental: buildEnvironmentExperimentalFlags()
|
|
9828
|
+
};
|
|
9829
|
+
}
|
|
8151
9830
|
async function loadGeneratorConfig(options = {}) {
|
|
8152
9831
|
const cwd = options.cwd ?? process.cwd();
|
|
8153
9832
|
const restoreProjectEnv = applyProjectEnv(cwd);
|
|
8154
|
-
const resolvedPath = options.configPath ? resolve(cwd, options.configPath) : findGeneratorConfigPath(cwd);
|
|
8155
|
-
if (!resolvedPath) {
|
|
8156
|
-
throw new Error(
|
|
8157
|
-
`No generator config found in ${cwd}. Expected one of: ${DEFAULT_CONFIG_CANDIDATES.join(", ")}`
|
|
8158
|
-
);
|
|
8159
|
-
}
|
|
8160
9833
|
try {
|
|
9834
|
+
const resolvedPath = options.configPath ? resolve(cwd, options.configPath) : findGeneratorConfigPath(cwd);
|
|
9835
|
+
if (!resolvedPath) {
|
|
9836
|
+
const environmentConfig = createEnvironmentGeneratorConfig();
|
|
9837
|
+
if (environmentConfig) {
|
|
9838
|
+
return {
|
|
9839
|
+
configPath: ENV_ONLY_CONFIG_PATH,
|
|
9840
|
+
config: normalizeGeneratorConfig(environmentConfig)
|
|
9841
|
+
};
|
|
9842
|
+
}
|
|
9843
|
+
throw new Error(
|
|
9844
|
+
`No generator config found in ${cwd}. Expected one of: ${DEFAULT_CONFIG_CANDIDATES.join(", ")}. To run without a config file, set DATABASE_URL (direct mode) or ATHENA_URL + ATHENA_API_KEY (gateway mode).`
|
|
9845
|
+
);
|
|
9846
|
+
}
|
|
8161
9847
|
const moduleUrl = pathToFileURL(resolvedPath);
|
|
8162
9848
|
const module = await importConfigModule(`${moduleUrl.href}?cacheBust=${Date.now()}`);
|
|
8163
9849
|
const rawConfig = extractConfigExport(module);
|
|
@@ -8378,59 +10064,6 @@ function escapeStringLiteral(value) {
|
|
|
8378
10064
|
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
8379
10065
|
}
|
|
8380
10066
|
|
|
8381
|
-
// src/generator/placeholders.ts
|
|
8382
|
-
function createStyleTokens(prefix, value) {
|
|
8383
|
-
return {
|
|
8384
|
-
[prefix]: value,
|
|
8385
|
-
[`${prefix}_camel`]: applyNamingStyle(value, "camel"),
|
|
8386
|
-
[`${prefix}_pascal`]: applyNamingStyle(value, "pascal"),
|
|
8387
|
-
[`${prefix}_snake`]: applyNamingStyle(value, "snake"),
|
|
8388
|
-
[`${prefix}_kebab`]: applyNamingStyle(value, "kebab")
|
|
8389
|
-
};
|
|
8390
|
-
}
|
|
8391
|
-
function renderTemplate(template, tokenMap) {
|
|
8392
|
-
return template.replace(/\{([A-Za-z0-9_]+)\}/g, (_match, token) => {
|
|
8393
|
-
if (!(token in tokenMap)) {
|
|
8394
|
-
throw new Error(`Unknown placeholder token "${token}" in template "${template}"`);
|
|
8395
|
-
}
|
|
8396
|
-
return tokenMap[token];
|
|
8397
|
-
});
|
|
8398
|
-
}
|
|
8399
|
-
function resolvePlaceholderMap(baseTokens, outputConfig) {
|
|
8400
|
-
const resolved = {
|
|
8401
|
-
...baseTokens
|
|
8402
|
-
};
|
|
8403
|
-
const reservedTokenKeys = new Set(Object.keys(baseTokens));
|
|
8404
|
-
const entries = Object.entries(outputConfig.placeholderMap ?? {});
|
|
8405
|
-
for (let index = 0; index < entries.length; index += 1) {
|
|
8406
|
-
const [key, value] = entries[index];
|
|
8407
|
-
if (reservedTokenKeys.has(key)) {
|
|
8408
|
-
continue;
|
|
8409
|
-
}
|
|
8410
|
-
let current = value;
|
|
8411
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
8412
|
-
const next = renderTemplate(current, resolved);
|
|
8413
|
-
if (next === current) {
|
|
8414
|
-
break;
|
|
8415
|
-
}
|
|
8416
|
-
current = next;
|
|
8417
|
-
}
|
|
8418
|
-
resolved[key] = current;
|
|
8419
|
-
}
|
|
8420
|
-
return resolved;
|
|
8421
|
-
}
|
|
8422
|
-
function renderOutputPath(template, context, outputConfig) {
|
|
8423
|
-
const baseTokens = {
|
|
8424
|
-
provider: context.provider,
|
|
8425
|
-
kind: context.kind,
|
|
8426
|
-
...createStyleTokens("database", context.database),
|
|
8427
|
-
...createStyleTokens("schema", context.schema),
|
|
8428
|
-
...createStyleTokens("model", context.model)
|
|
8429
|
-
};
|
|
8430
|
-
const tokens = resolvePlaceholderMap(baseTokens, outputConfig);
|
|
8431
|
-
return renderTemplate(template, tokens);
|
|
8432
|
-
}
|
|
8433
|
-
|
|
8434
10067
|
// src/generator/postgres-type-mapping.ts
|
|
8435
10068
|
var NUMBER_TYPES = /* @__PURE__ */ new Set([
|
|
8436
10069
|
"int2",
|
|
@@ -8547,7 +10180,60 @@ function resolvePostgresColumnType(column) {
|
|
|
8547
10180
|
return wrapArrayType(baseType, column.arrayDimensions);
|
|
8548
10181
|
}
|
|
8549
10182
|
|
|
8550
|
-
// src/generator/
|
|
10183
|
+
// src/generator/placeholders.ts
|
|
10184
|
+
function createStyleTokens(prefix, value) {
|
|
10185
|
+
return {
|
|
10186
|
+
[prefix]: value,
|
|
10187
|
+
[`${prefix}_camel`]: applyNamingStyle(value, "camel"),
|
|
10188
|
+
[`${prefix}_pascal`]: applyNamingStyle(value, "pascal"),
|
|
10189
|
+
[`${prefix}_snake`]: applyNamingStyle(value, "snake"),
|
|
10190
|
+
[`${prefix}_kebab`]: applyNamingStyle(value, "kebab")
|
|
10191
|
+
};
|
|
10192
|
+
}
|
|
10193
|
+
function renderTemplate(template, tokenMap) {
|
|
10194
|
+
return template.replace(/\{([A-Za-z0-9_]+)\}/g, (_match, token) => {
|
|
10195
|
+
if (!(token in tokenMap)) {
|
|
10196
|
+
throw new Error(`Unknown placeholder token "${token}" in template "${template}"`);
|
|
10197
|
+
}
|
|
10198
|
+
return tokenMap[token];
|
|
10199
|
+
});
|
|
10200
|
+
}
|
|
10201
|
+
function resolvePlaceholderMap(baseTokens, outputConfig) {
|
|
10202
|
+
const resolved = {
|
|
10203
|
+
...baseTokens
|
|
10204
|
+
};
|
|
10205
|
+
const reservedTokenKeys = new Set(Object.keys(baseTokens));
|
|
10206
|
+
const entries = Object.entries(outputConfig.placeholderMap ?? {});
|
|
10207
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
10208
|
+
const [key, value] = entries[index];
|
|
10209
|
+
if (reservedTokenKeys.has(key)) {
|
|
10210
|
+
continue;
|
|
10211
|
+
}
|
|
10212
|
+
let current = value;
|
|
10213
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
10214
|
+
const next = renderTemplate(current, resolved);
|
|
10215
|
+
if (next === current) {
|
|
10216
|
+
break;
|
|
10217
|
+
}
|
|
10218
|
+
current = next;
|
|
10219
|
+
}
|
|
10220
|
+
resolved[key] = current;
|
|
10221
|
+
}
|
|
10222
|
+
return resolved;
|
|
10223
|
+
}
|
|
10224
|
+
function renderOutputPath(template, context, outputConfig) {
|
|
10225
|
+
const baseTokens = {
|
|
10226
|
+
provider: context.provider,
|
|
10227
|
+
kind: context.kind,
|
|
10228
|
+
...createStyleTokens("database", context.database),
|
|
10229
|
+
...createStyleTokens("schema", context.schema),
|
|
10230
|
+
...createStyleTokens("model", context.model)
|
|
10231
|
+
};
|
|
10232
|
+
const tokens = resolvePlaceholderMap(baseTokens, outputConfig);
|
|
10233
|
+
return renderTemplate(template, tokens);
|
|
10234
|
+
}
|
|
10235
|
+
|
|
10236
|
+
// src/generator/render-shared.ts
|
|
8551
10237
|
function normalizePath(pathValue) {
|
|
8552
10238
|
return pathValue.replace(/\\/g, "/");
|
|
8553
10239
|
}
|
|
@@ -8560,11 +10246,13 @@ function toModuleImportPath(fromFile, targetFile) {
|
|
|
8560
10246
|
);
|
|
8561
10247
|
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
8562
10248
|
}
|
|
10249
|
+
function resolveOutputPath(target, tokens, config) {
|
|
10250
|
+
return normalizePath(renderOutputPath(target, tokens, config.output));
|
|
10251
|
+
}
|
|
8563
10252
|
function renderObjectKey(key) {
|
|
8564
|
-
|
|
8565
|
-
return escaped.startsWith("'") ? escaped : escaped;
|
|
10253
|
+
return escapeTypePropertyName(key);
|
|
8566
10254
|
}
|
|
8567
|
-
function
|
|
10255
|
+
function renderRelationLiteral(relation) {
|
|
8568
10256
|
const through = relation.through ? `,
|
|
8569
10257
|
through: {
|
|
8570
10258
|
schema: ${escapeStringLiteral(relation.through.schema)},
|
|
@@ -8580,54 +10268,12 @@ function renderRelation(relation) {
|
|
|
8580
10268
|
targetColumns: [${relation.targetColumns.map((value) => escapeStringLiteral(value)).join(", ")}]${through}
|
|
8581
10269
|
}`;
|
|
8582
10270
|
}
|
|
8583
|
-
function renderModelArtifact(snapshot, descriptor, config) {
|
|
8584
|
-
const columnLines = Object.values(descriptor.table.columns).map((column) => {
|
|
8585
|
-
const propertyName = escapeTypePropertyName(column.name);
|
|
8586
|
-
const baseType = resolvePostgresColumnType(column);
|
|
8587
|
-
const isOptional = column.isNullable;
|
|
8588
|
-
const typeWithNullability = column.isNullable ? `${baseType} | null` : baseType;
|
|
8589
|
-
return ` ${propertyName}${isOptional ? "?" : ""}: ${typeWithNullability}`;
|
|
8590
|
-
}).join("\n");
|
|
8591
|
-
const nullableLines = Object.values(descriptor.table.columns).map((column) => ` ${renderObjectKey(column.name)}: ${column.isNullable ? "true" : "false"}`).join(",\n");
|
|
8592
|
-
const relationEntries = Object.entries(descriptor.table.relations);
|
|
8593
|
-
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
8594
|
-
relations: {
|
|
8595
|
-
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelation(relationValue)}`).join(",\n")}
|
|
8596
|
-
}` : "";
|
|
8597
|
-
const content = `import { defineModel } from '@xylex-group/athena'
|
|
8598
|
-
|
|
8599
|
-
export interface ${descriptor.rowTypeName} {
|
|
8600
|
-
${columnLines}
|
|
8601
|
-
}
|
|
8602
|
-
|
|
8603
|
-
export type ${descriptor.insertTypeName} = Partial<${descriptor.rowTypeName}>
|
|
8604
|
-
export type ${descriptor.updateTypeName} = Partial<${descriptor.insertTypeName}>
|
|
8605
|
-
|
|
8606
|
-
export const ${descriptor.modelConstName} = defineModel<${descriptor.rowTypeName}, ${descriptor.insertTypeName}, ${descriptor.updateTypeName}>({
|
|
8607
|
-
meta: {
|
|
8608
|
-
database: ${escapeStringLiteral(snapshot.database)},
|
|
8609
|
-
schema: ${escapeStringLiteral(descriptor.schemaName)},
|
|
8610
|
-
model: ${escapeStringLiteral(descriptor.tableName)},
|
|
8611
|
-
tableName: ${escapeStringLiteral(`${descriptor.schemaName}.${descriptor.tableName}`)},
|
|
8612
|
-
primaryKey: [${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")}],
|
|
8613
|
-
nullable: {
|
|
8614
|
-
${nullableLines}
|
|
8615
|
-
}${relationBlock}
|
|
8616
|
-
}
|
|
8617
|
-
})
|
|
8618
|
-
`;
|
|
8619
|
-
return {
|
|
8620
|
-
kind: "model",
|
|
8621
|
-
path: descriptor.filePath,
|
|
8622
|
-
content
|
|
8623
|
-
};
|
|
8624
|
-
}
|
|
8625
10271
|
function renderSchemaArtifact(descriptor) {
|
|
8626
10272
|
const importLines = descriptor.models.map((modelDescriptor) => {
|
|
8627
10273
|
const importPath = toModuleImportPath(descriptor.filePath, modelDescriptor.filePath);
|
|
8628
|
-
return `import { ${modelDescriptor.
|
|
10274
|
+
return `import { ${modelDescriptor.exportConstName} } from '${importPath}'`;
|
|
8629
10275
|
}).join("\n");
|
|
8630
|
-
const modelEntries = descriptor.models.map((modelDescriptor) => ` ${renderObjectKey(modelDescriptor.tableName)}: ${modelDescriptor.
|
|
10276
|
+
const modelEntries = descriptor.models.map((modelDescriptor) => ` ${renderObjectKey(modelDescriptor.tableName)}: ${modelDescriptor.exportConstName}`).join(",\n");
|
|
8631
10277
|
const content = `import { defineSchema } from '@xylex-group/athena'
|
|
8632
10278
|
${importLines ? `
|
|
8633
10279
|
${importLines}
|
|
@@ -8662,11 +10308,18 @@ ${schemaEntries}
|
|
|
8662
10308
|
content
|
|
8663
10309
|
};
|
|
8664
10310
|
}
|
|
8665
|
-
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName) {
|
|
10311
|
+
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputFormat, schemaVersion) {
|
|
8666
10312
|
const databaseImportPath = toModuleImportPath(registryPath, databasePath);
|
|
8667
10313
|
const content = `import { defineRegistry } from '@xylex-group/athena'
|
|
8668
10314
|
import { ${databaseConstName} } from '${databaseImportPath}'
|
|
8669
10315
|
|
|
10316
|
+
export const __athena_schema_meta = {
|
|
10317
|
+
schemaVersion: ${schemaVersion},
|
|
10318
|
+
generatedAt: ${escapeStringLiteral(generatedAt)},
|
|
10319
|
+
database: ${escapeStringLiteral(databaseName)},
|
|
10320
|
+
outputFormat: ${escapeStringLiteral(outputFormat)},
|
|
10321
|
+
} as const
|
|
10322
|
+
|
|
8670
10323
|
export const ${registryConstName} = defineRegistry({
|
|
8671
10324
|
${renderObjectKey(databaseName)}: ${databaseConstName}
|
|
8672
10325
|
})
|
|
@@ -8745,123 +10398,332 @@ function scopeDuplicateDescriptorPathsBySchema(descriptors) {
|
|
|
8745
10398
|
}
|
|
8746
10399
|
return nextDescriptors;
|
|
8747
10400
|
}
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
const
|
|
8755
|
-
const
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
const table = schema.tables[tableName];
|
|
8761
|
-
const rowTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Row`;
|
|
8762
|
-
const insertTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Insert`;
|
|
8763
|
-
const updateTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Update`;
|
|
8764
|
-
const modelConstName = `${toSafeIdentifier(`${schemaName} ${tableName} model`, this.config.naming.modelConst, "model")}`;
|
|
8765
|
-
const modelPath = normalizePath(
|
|
8766
|
-
renderOutputPath(this.config.output.targets.model, {
|
|
8767
|
-
provider: providerName,
|
|
8768
|
-
kind: "model",
|
|
8769
|
-
database: databaseName,
|
|
8770
|
-
schema: schemaName,
|
|
8771
|
-
model: tableName
|
|
8772
|
-
}, this.config.output)
|
|
8773
|
-
);
|
|
8774
|
-
modelDescriptors.push({
|
|
10401
|
+
function composeGeneratorArtifacts(input) {
|
|
10402
|
+
const { snapshot, config, createModelDescriptor, renderModelArtifact: renderModelArtifact3 } = input;
|
|
10403
|
+
const providerName = snapshot.backend;
|
|
10404
|
+
const databaseName = snapshot.database;
|
|
10405
|
+
const modelDescriptors = [];
|
|
10406
|
+
for (const schemaName of Object.keys(snapshot.schemas).sort()) {
|
|
10407
|
+
const schema = snapshot.schemas[schemaName];
|
|
10408
|
+
for (const tableName of Object.keys(schema.tables).sort()) {
|
|
10409
|
+
modelDescriptors.push(
|
|
10410
|
+
createModelDescriptor({
|
|
10411
|
+
providerName,
|
|
10412
|
+
databaseName,
|
|
8775
10413
|
schemaName,
|
|
8776
10414
|
tableName,
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
insertTypeName,
|
|
8780
|
-
updateTypeName,
|
|
8781
|
-
modelConstName,
|
|
8782
|
-
table
|
|
8783
|
-
});
|
|
8784
|
-
}
|
|
8785
|
-
}
|
|
8786
|
-
const scopedModelDescriptors = scopeDuplicateDescriptorPathsBySchema(modelDescriptors);
|
|
8787
|
-
let schemaDescriptors = Object.keys(this.snapshot.schemas).sort().map((schemaName) => {
|
|
8788
|
-
const schemaPath = normalizePath(
|
|
8789
|
-
renderOutputPath(this.config.output.targets.schema, {
|
|
8790
|
-
provider: providerName,
|
|
8791
|
-
kind: "schema",
|
|
8792
|
-
database: databaseName,
|
|
8793
|
-
schema: schemaName,
|
|
8794
|
-
model: "index"
|
|
8795
|
-
}, this.config.output)
|
|
10415
|
+
table: schema.tables[tableName]
|
|
10416
|
+
})
|
|
8796
10417
|
);
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
10418
|
+
}
|
|
10419
|
+
}
|
|
10420
|
+
const scopedModelDescriptors = scopeDuplicateDescriptorPathsBySchema(modelDescriptors);
|
|
10421
|
+
let schemaDescriptors = Object.keys(snapshot.schemas).sort().map((schemaName) => ({
|
|
10422
|
+
schemaName,
|
|
10423
|
+
filePath: resolveOutputPath(
|
|
10424
|
+
config.output.targets.schema,
|
|
10425
|
+
{
|
|
10426
|
+
provider: providerName,
|
|
10427
|
+
kind: "schema",
|
|
10428
|
+
database: databaseName,
|
|
10429
|
+
schema: schemaName,
|
|
10430
|
+
model: "index"
|
|
10431
|
+
},
|
|
10432
|
+
config
|
|
10433
|
+
),
|
|
10434
|
+
schemaConstName: toSafeIdentifier(
|
|
10435
|
+
`${schemaName} schema`,
|
|
10436
|
+
config.naming.schemaConst,
|
|
10437
|
+
"schema"
|
|
10438
|
+
),
|
|
10439
|
+
models: scopedModelDescriptors.filter((model) => model.schemaName === schemaName)
|
|
10440
|
+
}));
|
|
10441
|
+
schemaDescriptors = scopeDuplicateDescriptorPathsBySchema(schemaDescriptors);
|
|
10442
|
+
const databaseDescriptor = {
|
|
10443
|
+
filePath: resolveOutputPath(
|
|
10444
|
+
config.output.targets.database,
|
|
10445
|
+
{
|
|
8811
10446
|
provider: providerName,
|
|
8812
10447
|
kind: "database",
|
|
8813
10448
|
database: databaseName,
|
|
8814
10449
|
schema: "index",
|
|
8815
10450
|
model: "index"
|
|
8816
|
-
},
|
|
10451
|
+
},
|
|
10452
|
+
config
|
|
10453
|
+
),
|
|
10454
|
+
databaseConstName: toSafeIdentifier(
|
|
10455
|
+
`${databaseName} database`,
|
|
10456
|
+
config.naming.databaseConst,
|
|
10457
|
+
"database"
|
|
10458
|
+
),
|
|
10459
|
+
schemas: schemaDescriptors
|
|
10460
|
+
};
|
|
10461
|
+
const files = [];
|
|
10462
|
+
for (const modelDescriptor of scopedModelDescriptors) {
|
|
10463
|
+
files.push(renderModelArtifact3(modelDescriptor));
|
|
10464
|
+
}
|
|
10465
|
+
for (const schemaDescriptor of schemaDescriptors) {
|
|
10466
|
+
files.push(renderSchemaArtifact(schemaDescriptor));
|
|
10467
|
+
}
|
|
10468
|
+
files.push(renderDatabaseArtifact(databaseDescriptor));
|
|
10469
|
+
if (config.features.emitRegistry) {
|
|
10470
|
+
const registryPath = resolveOutputPath(
|
|
10471
|
+
config.output.targets.registry,
|
|
10472
|
+
{
|
|
10473
|
+
provider: providerName,
|
|
10474
|
+
kind: "registry",
|
|
10475
|
+
database: databaseName,
|
|
10476
|
+
schema: "index",
|
|
10477
|
+
model: "index"
|
|
10478
|
+
},
|
|
10479
|
+
config
|
|
10480
|
+
);
|
|
10481
|
+
files.push(
|
|
10482
|
+
renderRegistryArtifact(
|
|
10483
|
+
registryPath,
|
|
10484
|
+
databaseDescriptor.filePath,
|
|
10485
|
+
databaseDescriptor.databaseConstName,
|
|
10486
|
+
toSafeIdentifier("registry", config.naming.registryConst, "registry"),
|
|
10487
|
+
databaseName,
|
|
10488
|
+
snapshot.generatedAt,
|
|
10489
|
+
config.output.format,
|
|
10490
|
+
config.internal.schemaVersion
|
|
10491
|
+
)
|
|
8817
10492
|
);
|
|
8818
|
-
const databaseDescriptor = {
|
|
8819
|
-
filePath: databasePath,
|
|
8820
|
-
databaseConstName: toSafeIdentifier(
|
|
8821
|
-
`${databaseName} database`,
|
|
8822
|
-
this.config.naming.databaseConst,
|
|
8823
|
-
"database"
|
|
8824
|
-
),
|
|
8825
|
-
schemas: schemaDescriptors
|
|
8826
|
-
};
|
|
8827
|
-
const files = [];
|
|
8828
|
-
for (const modelDescriptor of scopedModelDescriptors) {
|
|
8829
|
-
files.push(renderModelArtifact(this.snapshot, modelDescriptor, this.config));
|
|
8830
|
-
}
|
|
8831
|
-
for (const schemaDescriptor of schemaDescriptors) {
|
|
8832
|
-
files.push(renderSchemaArtifact(schemaDescriptor));
|
|
8833
|
-
}
|
|
8834
|
-
files.push(renderDatabaseArtifact(databaseDescriptor));
|
|
8835
|
-
if (this.config.features.emitRegistry) {
|
|
8836
|
-
const registryPath = normalizePath(
|
|
8837
|
-
renderOutputPath(this.config.output.targets.registry, {
|
|
8838
|
-
provider: providerName,
|
|
8839
|
-
kind: "registry",
|
|
8840
|
-
database: databaseName,
|
|
8841
|
-
schema: "index",
|
|
8842
|
-
model: "index"
|
|
8843
|
-
}, this.config.output)
|
|
8844
|
-
);
|
|
8845
|
-
files.push(
|
|
8846
|
-
renderRegistryArtifact(
|
|
8847
|
-
registryPath,
|
|
8848
|
-
databaseDescriptor.filePath,
|
|
8849
|
-
databaseDescriptor.databaseConstName,
|
|
8850
|
-
toSafeIdentifier("registry", this.config.naming.registryConst, "registry"),
|
|
8851
|
-
databaseName
|
|
8852
|
-
)
|
|
8853
|
-
);
|
|
8854
|
-
}
|
|
8855
|
-
assertNoDuplicatePaths(files);
|
|
8856
|
-
return {
|
|
8857
|
-
snapshot: this.snapshot,
|
|
8858
|
-
files
|
|
8859
|
-
};
|
|
8860
10493
|
}
|
|
8861
|
-
|
|
10494
|
+
assertNoDuplicatePaths(files);
|
|
10495
|
+
return {
|
|
10496
|
+
snapshot,
|
|
10497
|
+
files
|
|
10498
|
+
};
|
|
10499
|
+
}
|
|
10500
|
+
|
|
10501
|
+
// src/generator/table-builder-renderer.ts
|
|
10502
|
+
var SAFE_NUMBER_TYPES = /* @__PURE__ */ new Set([
|
|
10503
|
+
"int2",
|
|
10504
|
+
"int4",
|
|
10505
|
+
"float4",
|
|
10506
|
+
"float8",
|
|
10507
|
+
"smallint",
|
|
10508
|
+
"integer",
|
|
10509
|
+
"real",
|
|
10510
|
+
"double precision"
|
|
10511
|
+
]);
|
|
10512
|
+
var JSON_TYPES = /* @__PURE__ */ new Set(["json", "jsonb"]);
|
|
10513
|
+
var BOOLEAN_TYPES = /* @__PURE__ */ new Set(["bool", "boolean"]);
|
|
10514
|
+
var STRING_TYPES = /* @__PURE__ */ new Set([
|
|
10515
|
+
"int8",
|
|
10516
|
+
"bigint",
|
|
10517
|
+
"serial8",
|
|
10518
|
+
"bigserial",
|
|
10519
|
+
"numeric",
|
|
10520
|
+
"decimal",
|
|
10521
|
+
"money",
|
|
10522
|
+
"bytea"
|
|
10523
|
+
]);
|
|
10524
|
+
function normalizeTypeLabel2(column) {
|
|
10525
|
+
const preferred = (column.udtName || column.dataType).toLowerCase().trim();
|
|
10526
|
+
if (column.arrayDimensions > 0 && preferred.startsWith("_")) {
|
|
10527
|
+
return preferred.slice(1);
|
|
10528
|
+
}
|
|
10529
|
+
return preferred;
|
|
10530
|
+
}
|
|
10531
|
+
function renderColumnBuilder(column) {
|
|
10532
|
+
const label = normalizeTypeLabel2(column);
|
|
10533
|
+
let helper;
|
|
10534
|
+
let expression;
|
|
10535
|
+
if (column.typeKind === "enum" && column.enumValues && column.enumValues.length > 0) {
|
|
10536
|
+
helper = "enumeration";
|
|
10537
|
+
expression = `enumeration([${column.enumValues.map((value) => escapeStringLiteral(value)).join(", ")}] as const)`;
|
|
10538
|
+
} else if (column.arrayDimensions > 0 || JSON_TYPES.has(label) || column.typeKind === "composite") {
|
|
10539
|
+
helper = "json";
|
|
10540
|
+
expression = `json<${resolvePostgresColumnType(column)}>()`;
|
|
10541
|
+
} else if (BOOLEAN_TYPES.has(label)) {
|
|
10542
|
+
helper = "boolean";
|
|
10543
|
+
expression = "boolean()";
|
|
10544
|
+
} else if (SAFE_NUMBER_TYPES.has(label)) {
|
|
10545
|
+
helper = "number";
|
|
10546
|
+
expression = "number()";
|
|
10547
|
+
} else if (STRING_TYPES.has(label)) {
|
|
10548
|
+
helper = "string";
|
|
10549
|
+
expression = "string()";
|
|
10550
|
+
} else {
|
|
10551
|
+
helper = "string";
|
|
10552
|
+
expression = "string()";
|
|
10553
|
+
}
|
|
10554
|
+
if (column.isNullable) {
|
|
10555
|
+
expression = `${expression}.optional()`;
|
|
10556
|
+
}
|
|
10557
|
+
if (column.hasDefault) {
|
|
10558
|
+
expression = `${expression}.defaulted()`;
|
|
10559
|
+
}
|
|
10560
|
+
if (column.isGenerated) {
|
|
10561
|
+
expression = `${expression}.generated()`;
|
|
10562
|
+
}
|
|
10563
|
+
return { helper, expression };
|
|
10564
|
+
}
|
|
10565
|
+
function renderModelArtifact(descriptor, config) {
|
|
10566
|
+
const helperImports = /* @__PURE__ */ new Set(["table"]);
|
|
10567
|
+
const columnLines = Object.entries(descriptor.table.columns).map(([columnName, column]) => {
|
|
10568
|
+
const propertyName = escapeTypePropertyName(columnName);
|
|
10569
|
+
const rendered = renderColumnBuilder(column);
|
|
10570
|
+
helperImports.add(rendered.helper);
|
|
10571
|
+
return ` ${propertyName}: ${rendered.expression}`;
|
|
10572
|
+
}).join(",\n");
|
|
10573
|
+
const helperImportLine = Array.from(helperImports).sort().join(", ");
|
|
10574
|
+
const rowSchemaConstName = `${descriptor.tableConstName}_row_schema`;
|
|
10575
|
+
const insertSchemaConstName = `${descriptor.tableConstName}_insert_schema`;
|
|
10576
|
+
const updateSchemaConstName = `${descriptor.tableConstName}_update_schema`;
|
|
10577
|
+
const formSchemaConstName = `${descriptor.tableConstName}_form_schema`;
|
|
10578
|
+
const relationEntries = Object.entries(descriptor.table.relations);
|
|
10579
|
+
const relationsAssignment = config.features.emitRelations && relationEntries.length > 0 ? `
|
|
10580
|
+
Object.assign(${descriptor.tableConstName}.meta, {
|
|
10581
|
+
relations: {
|
|
10582
|
+
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
10583
|
+
}
|
|
10584
|
+
})
|
|
10585
|
+
` : "";
|
|
10586
|
+
const content = `import { ${helperImportLine} } from '@xylex-group/athena'
|
|
10587
|
+
import type { FormValuesOf, InsertOf, RowOf, UpdateOf } from '@xylex-group/athena'
|
|
10588
|
+
|
|
10589
|
+
export const ${descriptor.tableConstName} = table(${escapeStringLiteral(descriptor.tableName)})
|
|
10590
|
+
.schema(${escapeStringLiteral(descriptor.schemaName)})
|
|
10591
|
+
.columns({
|
|
10592
|
+
${columnLines}
|
|
10593
|
+
})
|
|
10594
|
+
.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})
|
|
10595
|
+
${relationsAssignment ? `${relationsAssignment}` : ""}
|
|
10596
|
+
export type ${descriptor.rowTypeName} = RowOf<typeof ${descriptor.tableConstName}>
|
|
10597
|
+
export type ${descriptor.insertTypeName} = InsertOf<typeof ${descriptor.tableConstName}>
|
|
10598
|
+
export type ${descriptor.updateTypeName} = UpdateOf<typeof ${descriptor.tableConstName}>
|
|
10599
|
+
export type ${descriptor.formValuesTypeName} = FormValuesOf<typeof ${descriptor.tableConstName}>
|
|
10600
|
+
|
|
10601
|
+
export const ${rowSchemaConstName} = ${descriptor.tableConstName}.schemas.row
|
|
10602
|
+
export const ${insertSchemaConstName} = ${descriptor.tableConstName}.schemas.insert
|
|
10603
|
+
export const ${updateSchemaConstName} = ${descriptor.tableConstName}.schemas.update
|
|
10604
|
+
export const ${formSchemaConstName} = ${descriptor.tableConstName}.schemas.form
|
|
10605
|
+
`;
|
|
10606
|
+
return {
|
|
10607
|
+
kind: "model",
|
|
10608
|
+
path: descriptor.filePath,
|
|
10609
|
+
content
|
|
10610
|
+
};
|
|
10611
|
+
}
|
|
10612
|
+
function generateTableBuilderArtifactsFromSnapshot(snapshot, config) {
|
|
10613
|
+
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
10614
|
+
return composeGeneratorArtifacts({
|
|
10615
|
+
snapshot,
|
|
10616
|
+
config: normalizedConfig,
|
|
10617
|
+
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table: table2 }) {
|
|
10618
|
+
const tableConstName = toSafeIdentifier(tableName, "preserve", "table");
|
|
10619
|
+
return {
|
|
10620
|
+
schemaName,
|
|
10621
|
+
tableName,
|
|
10622
|
+
filePath: resolveOutputPath(
|
|
10623
|
+
normalizedConfig.output.targets.model,
|
|
10624
|
+
{
|
|
10625
|
+
provider: providerName,
|
|
10626
|
+
kind: "model",
|
|
10627
|
+
database: databaseName,
|
|
10628
|
+
schema: schemaName,
|
|
10629
|
+
model: tableName
|
|
10630
|
+
},
|
|
10631
|
+
normalizedConfig
|
|
10632
|
+
),
|
|
10633
|
+
rowTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Row`,
|
|
10634
|
+
insertTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Insert`,
|
|
10635
|
+
updateTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Update`,
|
|
10636
|
+
formValuesTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}FormValues`,
|
|
10637
|
+
tableConstName,
|
|
10638
|
+
exportConstName: tableConstName,
|
|
10639
|
+
table: table2
|
|
10640
|
+
};
|
|
10641
|
+
},
|
|
10642
|
+
renderModelArtifact: (descriptor) => renderModelArtifact(descriptor, normalizedConfig)
|
|
10643
|
+
});
|
|
10644
|
+
}
|
|
10645
|
+
|
|
10646
|
+
// src/generator/renderer.ts
|
|
10647
|
+
function renderModelArtifact2(databaseName, descriptor, config) {
|
|
10648
|
+
const columnLines = Object.values(descriptor.table.columns).map((column) => {
|
|
10649
|
+
const propertyName = escapeTypePropertyName(column.name);
|
|
10650
|
+
const baseType = resolvePostgresColumnType(column);
|
|
10651
|
+
const isOptional = column.isNullable;
|
|
10652
|
+
const typeWithNullability = column.isNullable ? `${baseType} | null` : baseType;
|
|
10653
|
+
return ` ${propertyName}${isOptional ? "?" : ""}: ${typeWithNullability}`;
|
|
10654
|
+
}).join("\n");
|
|
10655
|
+
const nullableLines = Object.values(descriptor.table.columns).map((column) => ` ${renderObjectKey(column.name)}: ${column.isNullable ? "true" : "false"}`).join(",\n");
|
|
10656
|
+
const relationEntries = Object.entries(descriptor.table.relations);
|
|
10657
|
+
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
10658
|
+
relations: {
|
|
10659
|
+
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
10660
|
+
}` : "";
|
|
10661
|
+
const content = `import { defineModel } from '@xylex-group/athena'
|
|
10662
|
+
|
|
10663
|
+
export interface ${descriptor.rowTypeName} {
|
|
10664
|
+
${columnLines}
|
|
10665
|
+
}
|
|
10666
|
+
|
|
10667
|
+
export type ${descriptor.insertTypeName} = Partial<${descriptor.rowTypeName}>
|
|
10668
|
+
export type ${descriptor.updateTypeName} = Partial<${descriptor.insertTypeName}>
|
|
10669
|
+
|
|
10670
|
+
export const ${descriptor.modelConstName} = defineModel<${descriptor.rowTypeName}, ${descriptor.insertTypeName}, ${descriptor.updateTypeName}>({
|
|
10671
|
+
meta: {
|
|
10672
|
+
database: ${escapeStringLiteral(databaseName)},
|
|
10673
|
+
schema: ${escapeStringLiteral(descriptor.schemaName)},
|
|
10674
|
+
model: ${escapeStringLiteral(descriptor.tableName)},
|
|
10675
|
+
tableName: ${escapeStringLiteral(`${descriptor.schemaName}.${descriptor.tableName}`)},
|
|
10676
|
+
primaryKey: [${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")}],
|
|
10677
|
+
nullable: {
|
|
10678
|
+
${nullableLines}
|
|
10679
|
+
}${relationBlock}
|
|
10680
|
+
}
|
|
10681
|
+
})
|
|
10682
|
+
`;
|
|
10683
|
+
return {
|
|
10684
|
+
kind: "model",
|
|
10685
|
+
path: descriptor.filePath,
|
|
10686
|
+
content
|
|
10687
|
+
};
|
|
10688
|
+
}
|
|
8862
10689
|
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
8863
|
-
const normalizedConfig = "
|
|
8864
|
-
|
|
10690
|
+
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
10691
|
+
if (normalizedConfig.output.format === "table-builder") {
|
|
10692
|
+
return generateTableBuilderArtifactsFromSnapshot(snapshot, normalizedConfig);
|
|
10693
|
+
}
|
|
10694
|
+
return composeGeneratorArtifacts({
|
|
10695
|
+
snapshot,
|
|
10696
|
+
config: normalizedConfig,
|
|
10697
|
+
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table: table2 }) {
|
|
10698
|
+
const modelConstName = toSafeIdentifier(
|
|
10699
|
+
`${schemaName} ${tableName} model`,
|
|
10700
|
+
normalizedConfig.naming.modelConst,
|
|
10701
|
+
"model"
|
|
10702
|
+
);
|
|
10703
|
+
return {
|
|
10704
|
+
schemaName,
|
|
10705
|
+
tableName,
|
|
10706
|
+
filePath: resolveOutputPath(
|
|
10707
|
+
normalizedConfig.output.targets.model,
|
|
10708
|
+
{
|
|
10709
|
+
provider: providerName,
|
|
10710
|
+
kind: "model",
|
|
10711
|
+
database: databaseName,
|
|
10712
|
+
schema: schemaName,
|
|
10713
|
+
model: tableName
|
|
10714
|
+
},
|
|
10715
|
+
normalizedConfig
|
|
10716
|
+
),
|
|
10717
|
+
rowTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Row`,
|
|
10718
|
+
insertTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Insert`,
|
|
10719
|
+
updateTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Update`,
|
|
10720
|
+
modelConstName,
|
|
10721
|
+
exportConstName: modelConstName,
|
|
10722
|
+
table: table2
|
|
10723
|
+
};
|
|
10724
|
+
},
|
|
10725
|
+
renderModelArtifact: (descriptor) => renderModelArtifact2(snapshot.database, descriptor, normalizedConfig)
|
|
10726
|
+
});
|
|
8865
10727
|
}
|
|
8866
10728
|
|
|
8867
10729
|
// src/generator/providers.ts
|
|
@@ -9007,6 +10869,7 @@ async function runSchemaGenerator(options = {}) {
|
|
|
9007
10869
|
return {
|
|
9008
10870
|
...generated,
|
|
9009
10871
|
configPath,
|
|
10872
|
+
config,
|
|
9010
10873
|
writtenFiles
|
|
9011
10874
|
};
|
|
9012
10875
|
}
|
|
@@ -9438,6 +11301,6 @@ function athenaAuth(config) {
|
|
|
9438
11301
|
return auth;
|
|
9439
11302
|
}
|
|
9440
11303
|
|
|
9441
|
-
export { ATHENA_AUTH_BASE_ERROR_CODES, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, identifier, isAthenaGatewayError, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
11304
|
+
export { ATHENA_AUTH_BASE_ERROR_CODES, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
9442
11305
|
//# sourceMappingURL=index.js.map
|
|
9443
11306
|
//# sourceMappingURL=index.js.map
|