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