@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/cli/index.js
CHANGED
|
@@ -129,59 +129,6 @@ function escapeStringLiteral(value) {
|
|
|
129
129
|
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
// src/generator/placeholders.ts
|
|
133
|
-
function createStyleTokens(prefix, value) {
|
|
134
|
-
return {
|
|
135
|
-
[prefix]: value,
|
|
136
|
-
[`${prefix}_camel`]: applyNamingStyle(value, "camel"),
|
|
137
|
-
[`${prefix}_pascal`]: applyNamingStyle(value, "pascal"),
|
|
138
|
-
[`${prefix}_snake`]: applyNamingStyle(value, "snake"),
|
|
139
|
-
[`${prefix}_kebab`]: applyNamingStyle(value, "kebab")
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function renderTemplate(template, tokenMap) {
|
|
143
|
-
return template.replace(/\{([A-Za-z0-9_]+)\}/g, (_match, token) => {
|
|
144
|
-
if (!(token in tokenMap)) {
|
|
145
|
-
throw new Error(`Unknown placeholder token "${token}" in template "${template}"`);
|
|
146
|
-
}
|
|
147
|
-
return tokenMap[token];
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function resolvePlaceholderMap(baseTokens, outputConfig) {
|
|
151
|
-
const resolved = {
|
|
152
|
-
...baseTokens
|
|
153
|
-
};
|
|
154
|
-
const reservedTokenKeys = new Set(Object.keys(baseTokens));
|
|
155
|
-
const entries = Object.entries(outputConfig.placeholderMap ?? {});
|
|
156
|
-
for (let index = 0; index < entries.length; index += 1) {
|
|
157
|
-
const [key, value] = entries[index];
|
|
158
|
-
if (reservedTokenKeys.has(key)) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
let current = value;
|
|
162
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
163
|
-
const next = renderTemplate(current, resolved);
|
|
164
|
-
if (next === current) {
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
current = next;
|
|
168
|
-
}
|
|
169
|
-
resolved[key] = current;
|
|
170
|
-
}
|
|
171
|
-
return resolved;
|
|
172
|
-
}
|
|
173
|
-
function renderOutputPath(template, context, outputConfig) {
|
|
174
|
-
const baseTokens = {
|
|
175
|
-
provider: context.provider,
|
|
176
|
-
kind: context.kind,
|
|
177
|
-
...createStyleTokens("database", context.database),
|
|
178
|
-
...createStyleTokens("schema", context.schema),
|
|
179
|
-
...createStyleTokens("model", context.model)
|
|
180
|
-
};
|
|
181
|
-
const tokens = resolvePlaceholderMap(baseTokens, outputConfig);
|
|
182
|
-
return renderTemplate(template, tokens);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
132
|
// src/generator/postgres-type-mapping.ts
|
|
186
133
|
var NUMBER_TYPES = /* @__PURE__ */ new Set([
|
|
187
134
|
"int2",
|
|
@@ -755,6 +702,7 @@ var DEFAULT_TARGETS = {
|
|
|
755
702
|
database: "athena/relations.ts",
|
|
756
703
|
registry: "athena/config.ts"
|
|
757
704
|
};
|
|
705
|
+
var DEFAULT_OUTPUT_FORMAT = "define-model";
|
|
758
706
|
var DEFAULT_NAMING = {
|
|
759
707
|
modelType: "pascal",
|
|
760
708
|
modelConst: "camel",
|
|
@@ -770,6 +718,9 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
770
718
|
postgresGatewayIntrospection: false,
|
|
771
719
|
scyllaProviderContracts: true
|
|
772
720
|
};
|
|
721
|
+
var DEFAULT_INTERNAL_CONFIG = {
|
|
722
|
+
schemaVersion: 1
|
|
723
|
+
};
|
|
773
724
|
var PROJECT_ENV_FILENAMES = [".env", ".env.local"];
|
|
774
725
|
var DIRECT_CONNECTION_STRING_ENV_KEYS = [
|
|
775
726
|
"ATHENA_GENERATOR_PG_URL",
|
|
@@ -786,6 +737,27 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
786
737
|
"ATHENA_GATEWAY_API_KEY",
|
|
787
738
|
"ATHENA_GENERATOR_API_KEY"
|
|
788
739
|
];
|
|
740
|
+
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
741
|
+
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
742
|
+
var MODEL_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TARGET"];
|
|
743
|
+
var SCHEMA_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_TARGET"];
|
|
744
|
+
var DATABASE_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_TARGET"];
|
|
745
|
+
var REGISTRY_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_TARGET"];
|
|
746
|
+
var PLACEHOLDER_MAP_ENV_KEYS = ["ATHENA_GENERATOR_PLACEHOLDER_MAP"];
|
|
747
|
+
var MODEL_TYPE_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TYPE", "ATHENA_GENERATOR_MODEL_STYLE"];
|
|
748
|
+
var MODEL_CONST_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_CONST"];
|
|
749
|
+
var SCHEMA_CONST_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_CONST"];
|
|
750
|
+
var DATABASE_CONST_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_CONST"];
|
|
751
|
+
var REGISTRY_CONST_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_CONST"];
|
|
752
|
+
var EMIT_RELATIONS_ENV_KEYS = ["ATHENA_GENERATOR_EMIT_RELATIONS"];
|
|
753
|
+
var EMIT_REGISTRY_ENV_KEYS = ["ATHENA_GENERATOR_EMIT_REGISTRY"];
|
|
754
|
+
var GATEWAY_BACKEND_ENV_KEYS = ["ATHENA_GENERATOR_BACKEND"];
|
|
755
|
+
var GATEWAY_EXPERIMENTAL_ENV_KEYS = ["ATHENA_GENERATOR_GATEWAY_EXPERIMENTAL"];
|
|
756
|
+
var SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS = ["ATHENA_GENERATOR_SCYLLA_PROVIDER_CONTRACTS"];
|
|
757
|
+
var ENV_ONLY_CONFIG_PATH = "[environment defaults]";
|
|
758
|
+
var NAMING_STYLE_VALUES = ["preserve", "camel", "pascal", "snake", "kebab"];
|
|
759
|
+
var OUTPUT_FORMAT_VALUES = ["define-model", "table-builder"];
|
|
760
|
+
var BACKEND_TYPE_VALUES = ["athena", "postgrest", "postgresql", "scylladb"];
|
|
789
761
|
function normalizeRawEnvValue(rawValue) {
|
|
790
762
|
if (rawValue.startsWith('"') && rawValue.endsWith('"') && rawValue.length >= 2) {
|
|
791
763
|
const inner = rawValue.slice(1, -1);
|
|
@@ -877,6 +849,50 @@ function resolveFallbackValue(fallbackKeys) {
|
|
|
877
849
|
}
|
|
878
850
|
return void 0;
|
|
879
851
|
}
|
|
852
|
+
function normalizeOneOfValue(rawValue, allowedValues, envKeys) {
|
|
853
|
+
if (!rawValue) {
|
|
854
|
+
return void 0;
|
|
855
|
+
}
|
|
856
|
+
if (allowedValues.includes(rawValue)) {
|
|
857
|
+
return rawValue;
|
|
858
|
+
}
|
|
859
|
+
throw new Error(
|
|
860
|
+
`Generator config env vars ${envKeys.join(", ")} must resolve to one of: ${allowedValues.join(", ")}. Received: ${rawValue}.`
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
function resolveOptionalOneOf(envKeys, allowedValues) {
|
|
864
|
+
return normalizeOneOfValue(resolveFallbackValue(envKeys), allowedValues, envKeys);
|
|
865
|
+
}
|
|
866
|
+
function resolveOptionalBoolean(envKeys) {
|
|
867
|
+
const rawValue = resolveFallbackValue(envKeys);
|
|
868
|
+
return rawValue === void 0 ? void 0 : parseBooleanFlag2(rawValue, false);
|
|
869
|
+
}
|
|
870
|
+
function resolveOptionalJson(envKeys) {
|
|
871
|
+
const rawValue = resolveFallbackValue(envKeys);
|
|
872
|
+
if (rawValue === void 0) {
|
|
873
|
+
return void 0;
|
|
874
|
+
}
|
|
875
|
+
try {
|
|
876
|
+
return JSON.parse(rawValue);
|
|
877
|
+
} catch (error) {
|
|
878
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
879
|
+
throw new Error(
|
|
880
|
+
`Generator config env vars ${envKeys.join(", ")} must contain valid JSON. ${message}`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function deriveDatabaseNameFromConnectionString(connectionString) {
|
|
885
|
+
try {
|
|
886
|
+
const parsedUrl = new URL(connectionString);
|
|
887
|
+
if (!POSTGRES_PROTOCOLS.has(parsedUrl.protocol)) {
|
|
888
|
+
return void 0;
|
|
889
|
+
}
|
|
890
|
+
const pathname = parsedUrl.pathname.replace(/^\/+/, "").trim();
|
|
891
|
+
return pathname.length > 0 ? decodeURIComponent(pathname) : void 0;
|
|
892
|
+
} catch {
|
|
893
|
+
return void 0;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
880
896
|
function normalizeOptionalString(value, fallbackKeys) {
|
|
881
897
|
if (typeof value === "string") {
|
|
882
898
|
const trimmed = value.trim();
|
|
@@ -950,12 +966,13 @@ function normalizeExperimentalFlags(input) {
|
|
|
950
966
|
}
|
|
951
967
|
function normalizeOutputConfig(output) {
|
|
952
968
|
return {
|
|
969
|
+
format: output?.format ?? DEFAULT_OUTPUT_FORMAT,
|
|
953
970
|
targets: {
|
|
954
971
|
...DEFAULT_TARGETS,
|
|
955
|
-
...output
|
|
972
|
+
...output?.targets ?? {}
|
|
956
973
|
},
|
|
957
974
|
placeholderMap: {
|
|
958
|
-
...output
|
|
975
|
+
...output?.placeholderMap ?? {}
|
|
959
976
|
}
|
|
960
977
|
};
|
|
961
978
|
}
|
|
@@ -966,7 +983,7 @@ function normalizeProviderConfig(provider) {
|
|
|
966
983
|
"provider.connectionString",
|
|
967
984
|
DIRECT_CONNECTION_STRING_ENV_KEYS
|
|
968
985
|
);
|
|
969
|
-
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS);
|
|
986
|
+
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? deriveDatabaseNameFromConnectionString(connectionString);
|
|
970
987
|
return {
|
|
971
988
|
...provider,
|
|
972
989
|
connectionString: applyPostgresPasswordFallback(connectionString),
|
|
@@ -985,11 +1002,7 @@ function normalizeProviderConfig(provider) {
|
|
|
985
1002
|
"provider.apiKey",
|
|
986
1003
|
GATEWAY_API_KEY_ENV_KEYS
|
|
987
1004
|
);
|
|
988
|
-
const database =
|
|
989
|
-
provider.database,
|
|
990
|
-
"provider.database",
|
|
991
|
-
POSTGRES_DATABASE_ENV_KEYS
|
|
992
|
-
);
|
|
1005
|
+
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
993
1006
|
return {
|
|
994
1007
|
...provider,
|
|
995
1008
|
gatewayUrl,
|
|
@@ -998,6 +1011,26 @@ function normalizeProviderConfig(provider) {
|
|
|
998
1011
|
schemas: normalizeSchemaSelection(provider.schemas)
|
|
999
1012
|
};
|
|
1000
1013
|
}
|
|
1014
|
+
if (provider.kind === "scylla" && provider.mode === "direct") {
|
|
1015
|
+
if (!provider.contactPoints?.length) {
|
|
1016
|
+
throw new Error(
|
|
1017
|
+
"Generator config is missing provider.contactPoints for scylla direct mode."
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
const keyspace = normalizeOptionalString(provider.keyspace, []);
|
|
1021
|
+
if (!keyspace) {
|
|
1022
|
+
throw new Error(
|
|
1023
|
+
"Generator config is missing provider.keyspace for scylla direct mode."
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
return {
|
|
1027
|
+
kind: "scylla",
|
|
1028
|
+
mode: "direct",
|
|
1029
|
+
contactPoints: provider.contactPoints.slice(),
|
|
1030
|
+
keyspace,
|
|
1031
|
+
datacenter: normalizeOptionalString(provider.datacenter, [])
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1001
1034
|
return provider;
|
|
1002
1035
|
}
|
|
1003
1036
|
function isAthenaGeneratorConfig(value) {
|
|
@@ -1005,7 +1038,7 @@ function isAthenaGeneratorConfig(value) {
|
|
|
1005
1038
|
return false;
|
|
1006
1039
|
}
|
|
1007
1040
|
const record = value;
|
|
1008
|
-
return Boolean(record.provider && typeof record.provider === "object") &&
|
|
1041
|
+
return Boolean(record.provider && typeof record.provider === "object") && (record.output === void 0 || typeof record.output === "object");
|
|
1009
1042
|
}
|
|
1010
1043
|
function normalizeGeneratorConfig(input) {
|
|
1011
1044
|
return {
|
|
@@ -1016,7 +1049,10 @@ function normalizeGeneratorConfig(input) {
|
|
|
1016
1049
|
...input.naming ?? {}
|
|
1017
1050
|
},
|
|
1018
1051
|
features: normalizeFeatureFlags(input.features),
|
|
1019
|
-
experimental: normalizeExperimentalFlags(input.experimental)
|
|
1052
|
+
experimental: normalizeExperimentalFlags(input.experimental),
|
|
1053
|
+
internal: {
|
|
1054
|
+
...DEFAULT_INTERNAL_CONFIG
|
|
1055
|
+
}
|
|
1020
1056
|
};
|
|
1021
1057
|
}
|
|
1022
1058
|
function findGeneratorConfigPath(cwd = process.cwd()) {
|
|
@@ -1070,16 +1106,123 @@ function importConfigModule(moduleSpecifier) {
|
|
|
1070
1106
|
);
|
|
1071
1107
|
return runtimeImport(moduleSpecifier);
|
|
1072
1108
|
}
|
|
1109
|
+
function buildEnvironmentOutputConfig() {
|
|
1110
|
+
const format = resolveOptionalOneOf(OUTPUT_FORMAT_ENV_KEYS, OUTPUT_FORMAT_VALUES);
|
|
1111
|
+
const modelTarget = resolveFallbackValue(MODEL_TARGET_ENV_KEYS);
|
|
1112
|
+
const schemaTarget = resolveFallbackValue(SCHEMA_TARGET_ENV_KEYS);
|
|
1113
|
+
const databaseTarget = resolveFallbackValue(DATABASE_TARGET_ENV_KEYS);
|
|
1114
|
+
const registryTarget = resolveFallbackValue(REGISTRY_TARGET_ENV_KEYS);
|
|
1115
|
+
const placeholderMap = resolveOptionalJson(PLACEHOLDER_MAP_ENV_KEYS);
|
|
1116
|
+
if (format === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
1117
|
+
return void 0;
|
|
1118
|
+
}
|
|
1119
|
+
return {
|
|
1120
|
+
format,
|
|
1121
|
+
targets: {
|
|
1122
|
+
...modelTarget ? { model: modelTarget } : {},
|
|
1123
|
+
...schemaTarget ? { schema: schemaTarget } : {},
|
|
1124
|
+
...databaseTarget ? { database: databaseTarget } : {},
|
|
1125
|
+
...registryTarget ? { registry: registryTarget } : {}
|
|
1126
|
+
},
|
|
1127
|
+
placeholderMap
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
function buildEnvironmentNamingConfig() {
|
|
1131
|
+
const modelType = resolveOptionalOneOf(MODEL_TYPE_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
1132
|
+
const modelConst = resolveOptionalOneOf(MODEL_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
1133
|
+
const schemaConst = resolveOptionalOneOf(SCHEMA_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
1134
|
+
const databaseConst = resolveOptionalOneOf(DATABASE_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
1135
|
+
const registryConst = resolveOptionalOneOf(REGISTRY_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
1136
|
+
if (modelType === void 0 && modelConst === void 0 && schemaConst === void 0 && databaseConst === void 0 && registryConst === void 0) {
|
|
1137
|
+
return void 0;
|
|
1138
|
+
}
|
|
1139
|
+
return {
|
|
1140
|
+
...modelType ? { modelType } : {},
|
|
1141
|
+
...modelConst ? { modelConst } : {},
|
|
1142
|
+
...schemaConst ? { schemaConst } : {},
|
|
1143
|
+
...databaseConst ? { databaseConst } : {},
|
|
1144
|
+
...registryConst ? { registryConst } : {}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
function buildEnvironmentFeatureFlags() {
|
|
1148
|
+
const emitRelations = resolveOptionalBoolean(EMIT_RELATIONS_ENV_KEYS);
|
|
1149
|
+
const emitRegistry = resolveOptionalBoolean(EMIT_REGISTRY_ENV_KEYS);
|
|
1150
|
+
if (emitRelations === void 0 && emitRegistry === void 0) {
|
|
1151
|
+
return void 0;
|
|
1152
|
+
}
|
|
1153
|
+
return {
|
|
1154
|
+
...emitRelations !== void 0 ? { emitRelations } : {},
|
|
1155
|
+
...emitRegistry !== void 0 ? { emitRegistry } : {}
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
function buildEnvironmentExperimentalFlags() {
|
|
1159
|
+
const postgresGatewayIntrospection = resolveOptionalBoolean(GATEWAY_EXPERIMENTAL_ENV_KEYS);
|
|
1160
|
+
const scyllaProviderContracts = resolveOptionalBoolean(SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS);
|
|
1161
|
+
if (postgresGatewayIntrospection === void 0 && scyllaProviderContracts === void 0) {
|
|
1162
|
+
return void 0;
|
|
1163
|
+
}
|
|
1164
|
+
return {
|
|
1165
|
+
...postgresGatewayIntrospection !== void 0 ? { postgresGatewayIntrospection } : {},
|
|
1166
|
+
...scyllaProviderContracts !== void 0 ? { scyllaProviderContracts } : {}
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function buildEnvironmentProviderConfig() {
|
|
1170
|
+
const directConnectionString = resolveFallbackValue(DIRECT_CONNECTION_STRING_ENV_KEYS);
|
|
1171
|
+
if (directConnectionString) {
|
|
1172
|
+
return {
|
|
1173
|
+
kind: "postgres",
|
|
1174
|
+
mode: "direct",
|
|
1175
|
+
connectionString: directConnectionString,
|
|
1176
|
+
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
1177
|
+
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS))
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
const gatewayUrl = resolveFallbackValue(GATEWAY_URL_ENV_KEYS);
|
|
1181
|
+
const apiKey = resolveFallbackValue(GATEWAY_API_KEY_ENV_KEYS);
|
|
1182
|
+
if (gatewayUrl && apiKey) {
|
|
1183
|
+
const backend = resolveOptionalOneOf(GATEWAY_BACKEND_ENV_KEYS, BACKEND_TYPE_VALUES);
|
|
1184
|
+
return {
|
|
1185
|
+
kind: "postgres",
|
|
1186
|
+
mode: "gateway",
|
|
1187
|
+
gatewayUrl,
|
|
1188
|
+
apiKey,
|
|
1189
|
+
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
1190
|
+
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
1191
|
+
backend
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
return void 0;
|
|
1195
|
+
}
|
|
1196
|
+
function createEnvironmentGeneratorConfig() {
|
|
1197
|
+
const provider = buildEnvironmentProviderConfig();
|
|
1198
|
+
if (!provider) {
|
|
1199
|
+
return void 0;
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
provider,
|
|
1203
|
+
output: buildEnvironmentOutputConfig(),
|
|
1204
|
+
naming: buildEnvironmentNamingConfig(),
|
|
1205
|
+
features: buildEnvironmentFeatureFlags(),
|
|
1206
|
+
experimental: buildEnvironmentExperimentalFlags()
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1073
1209
|
async function loadGeneratorConfig(options = {}) {
|
|
1074
1210
|
const cwd = options.cwd ?? process.cwd();
|
|
1075
1211
|
const restoreProjectEnv = applyProjectEnv(cwd);
|
|
1076
|
-
const resolvedPath = options.configPath ? resolve(cwd, options.configPath) : findGeneratorConfigPath(cwd);
|
|
1077
|
-
if (!resolvedPath) {
|
|
1078
|
-
throw new Error(
|
|
1079
|
-
`No generator config found in ${cwd}. Expected one of: ${DEFAULT_CONFIG_CANDIDATES.join(", ")}`
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
1212
|
try {
|
|
1213
|
+
const resolvedPath = options.configPath ? resolve(cwd, options.configPath) : findGeneratorConfigPath(cwd);
|
|
1214
|
+
if (!resolvedPath) {
|
|
1215
|
+
const environmentConfig = createEnvironmentGeneratorConfig();
|
|
1216
|
+
if (environmentConfig) {
|
|
1217
|
+
return {
|
|
1218
|
+
configPath: ENV_ONLY_CONFIG_PATH,
|
|
1219
|
+
config: normalizeGeneratorConfig(environmentConfig)
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
throw new Error(
|
|
1223
|
+
`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).`
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1083
1226
|
const moduleUrl = pathToFileURL(resolvedPath);
|
|
1084
1227
|
const module = await importConfigModule(`${moduleUrl.href}?cacheBust=${Date.now()}`);
|
|
1085
1228
|
const rawConfig = extractConfigExport(module);
|
|
@@ -1092,7 +1235,60 @@ async function loadGeneratorConfig(options = {}) {
|
|
|
1092
1235
|
}
|
|
1093
1236
|
}
|
|
1094
1237
|
|
|
1095
|
-
// src/generator/
|
|
1238
|
+
// src/generator/placeholders.ts
|
|
1239
|
+
function createStyleTokens(prefix, value) {
|
|
1240
|
+
return {
|
|
1241
|
+
[prefix]: value,
|
|
1242
|
+
[`${prefix}_camel`]: applyNamingStyle(value, "camel"),
|
|
1243
|
+
[`${prefix}_pascal`]: applyNamingStyle(value, "pascal"),
|
|
1244
|
+
[`${prefix}_snake`]: applyNamingStyle(value, "snake"),
|
|
1245
|
+
[`${prefix}_kebab`]: applyNamingStyle(value, "kebab")
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
function renderTemplate(template, tokenMap) {
|
|
1249
|
+
return template.replace(/\{([A-Za-z0-9_]+)\}/g, (_match, token) => {
|
|
1250
|
+
if (!(token in tokenMap)) {
|
|
1251
|
+
throw new Error(`Unknown placeholder token "${token}" in template "${template}"`);
|
|
1252
|
+
}
|
|
1253
|
+
return tokenMap[token];
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
function resolvePlaceholderMap(baseTokens, outputConfig) {
|
|
1257
|
+
const resolved = {
|
|
1258
|
+
...baseTokens
|
|
1259
|
+
};
|
|
1260
|
+
const reservedTokenKeys = new Set(Object.keys(baseTokens));
|
|
1261
|
+
const entries = Object.entries(outputConfig.placeholderMap ?? {});
|
|
1262
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
1263
|
+
const [key, value] = entries[index];
|
|
1264
|
+
if (reservedTokenKeys.has(key)) {
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
let current = value;
|
|
1268
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
1269
|
+
const next = renderTemplate(current, resolved);
|
|
1270
|
+
if (next === current) {
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
current = next;
|
|
1274
|
+
}
|
|
1275
|
+
resolved[key] = current;
|
|
1276
|
+
}
|
|
1277
|
+
return resolved;
|
|
1278
|
+
}
|
|
1279
|
+
function renderOutputPath(template, context, outputConfig) {
|
|
1280
|
+
const baseTokens = {
|
|
1281
|
+
provider: context.provider,
|
|
1282
|
+
kind: context.kind,
|
|
1283
|
+
...createStyleTokens("database", context.database),
|
|
1284
|
+
...createStyleTokens("schema", context.schema),
|
|
1285
|
+
...createStyleTokens("model", context.model)
|
|
1286
|
+
};
|
|
1287
|
+
const tokens = resolvePlaceholderMap(baseTokens, outputConfig);
|
|
1288
|
+
return renderTemplate(template, tokens);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
// src/generator/render-shared.ts
|
|
1096
1292
|
function normalizePath(pathValue) {
|
|
1097
1293
|
return pathValue.replace(/\\/g, "/");
|
|
1098
1294
|
}
|
|
@@ -1105,11 +1301,13 @@ function toModuleImportPath(fromFile, targetFile) {
|
|
|
1105
1301
|
);
|
|
1106
1302
|
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
1107
1303
|
}
|
|
1304
|
+
function resolveOutputPath(target, tokens, config) {
|
|
1305
|
+
return normalizePath(renderOutputPath(target, tokens, config.output));
|
|
1306
|
+
}
|
|
1108
1307
|
function renderObjectKey(key) {
|
|
1109
|
-
|
|
1110
|
-
return escaped.startsWith("'") ? escaped : escaped;
|
|
1308
|
+
return escapeTypePropertyName(key);
|
|
1111
1309
|
}
|
|
1112
|
-
function
|
|
1310
|
+
function renderRelationLiteral(relation) {
|
|
1113
1311
|
const through = relation.through ? `,
|
|
1114
1312
|
through: {
|
|
1115
1313
|
schema: ${escapeStringLiteral(relation.through.schema)},
|
|
@@ -1125,54 +1323,12 @@ function renderRelation(relation) {
|
|
|
1125
1323
|
targetColumns: [${relation.targetColumns.map((value) => escapeStringLiteral(value)).join(", ")}]${through}
|
|
1126
1324
|
}`;
|
|
1127
1325
|
}
|
|
1128
|
-
function renderModelArtifact(snapshot, descriptor, config) {
|
|
1129
|
-
const columnLines = Object.values(descriptor.table.columns).map((column) => {
|
|
1130
|
-
const propertyName = escapeTypePropertyName(column.name);
|
|
1131
|
-
const baseType = resolvePostgresColumnType(column);
|
|
1132
|
-
const isOptional = column.isNullable;
|
|
1133
|
-
const typeWithNullability = column.isNullable ? `${baseType} | null` : baseType;
|
|
1134
|
-
return ` ${propertyName}${isOptional ? "?" : ""}: ${typeWithNullability}`;
|
|
1135
|
-
}).join("\n");
|
|
1136
|
-
const nullableLines = Object.values(descriptor.table.columns).map((column) => ` ${renderObjectKey(column.name)}: ${column.isNullable ? "true" : "false"}`).join(",\n");
|
|
1137
|
-
const relationEntries = Object.entries(descriptor.table.relations);
|
|
1138
|
-
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
1139
|
-
relations: {
|
|
1140
|
-
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelation(relationValue)}`).join(",\n")}
|
|
1141
|
-
}` : "";
|
|
1142
|
-
const content = `import { defineModel } from '@xylex-group/athena'
|
|
1143
|
-
|
|
1144
|
-
export interface ${descriptor.rowTypeName} {
|
|
1145
|
-
${columnLines}
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
export type ${descriptor.insertTypeName} = Partial<${descriptor.rowTypeName}>
|
|
1149
|
-
export type ${descriptor.updateTypeName} = Partial<${descriptor.insertTypeName}>
|
|
1150
|
-
|
|
1151
|
-
export const ${descriptor.modelConstName} = defineModel<${descriptor.rowTypeName}, ${descriptor.insertTypeName}, ${descriptor.updateTypeName}>({
|
|
1152
|
-
meta: {
|
|
1153
|
-
database: ${escapeStringLiteral(snapshot.database)},
|
|
1154
|
-
schema: ${escapeStringLiteral(descriptor.schemaName)},
|
|
1155
|
-
model: ${escapeStringLiteral(descriptor.tableName)},
|
|
1156
|
-
tableName: ${escapeStringLiteral(`${descriptor.schemaName}.${descriptor.tableName}`)},
|
|
1157
|
-
primaryKey: [${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")}],
|
|
1158
|
-
nullable: {
|
|
1159
|
-
${nullableLines}
|
|
1160
|
-
}${relationBlock}
|
|
1161
|
-
}
|
|
1162
|
-
})
|
|
1163
|
-
`;
|
|
1164
|
-
return {
|
|
1165
|
-
kind: "model",
|
|
1166
|
-
path: descriptor.filePath,
|
|
1167
|
-
content
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
1326
|
function renderSchemaArtifact(descriptor) {
|
|
1171
1327
|
const importLines = descriptor.models.map((modelDescriptor) => {
|
|
1172
1328
|
const importPath = toModuleImportPath(descriptor.filePath, modelDescriptor.filePath);
|
|
1173
|
-
return `import { ${modelDescriptor.
|
|
1329
|
+
return `import { ${modelDescriptor.exportConstName} } from '${importPath}'`;
|
|
1174
1330
|
}).join("\n");
|
|
1175
|
-
const modelEntries = descriptor.models.map((modelDescriptor) => ` ${renderObjectKey(modelDescriptor.tableName)}: ${modelDescriptor.
|
|
1331
|
+
const modelEntries = descriptor.models.map((modelDescriptor) => ` ${renderObjectKey(modelDescriptor.tableName)}: ${modelDescriptor.exportConstName}`).join(",\n");
|
|
1176
1332
|
const content = `import { defineSchema } from '@xylex-group/athena'
|
|
1177
1333
|
${importLines ? `
|
|
1178
1334
|
${importLines}
|
|
@@ -1207,11 +1363,18 @@ ${schemaEntries}
|
|
|
1207
1363
|
content
|
|
1208
1364
|
};
|
|
1209
1365
|
}
|
|
1210
|
-
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName) {
|
|
1366
|
+
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputFormat, schemaVersion) {
|
|
1211
1367
|
const databaseImportPath = toModuleImportPath(registryPath, databasePath);
|
|
1212
1368
|
const content = `import { defineRegistry } from '@xylex-group/athena'
|
|
1213
1369
|
import { ${databaseConstName} } from '${databaseImportPath}'
|
|
1214
1370
|
|
|
1371
|
+
export const __athena_schema_meta = {
|
|
1372
|
+
schemaVersion: ${schemaVersion},
|
|
1373
|
+
generatedAt: ${escapeStringLiteral(generatedAt)},
|
|
1374
|
+
database: ${escapeStringLiteral(databaseName)},
|
|
1375
|
+
outputFormat: ${escapeStringLiteral(outputFormat)},
|
|
1376
|
+
} as const
|
|
1377
|
+
|
|
1215
1378
|
export const ${registryConstName} = defineRegistry({
|
|
1216
1379
|
${renderObjectKey(databaseName)}: ${databaseConstName}
|
|
1217
1380
|
})
|
|
@@ -1290,123 +1453,332 @@ function scopeDuplicateDescriptorPathsBySchema(descriptors) {
|
|
|
1290
1453
|
}
|
|
1291
1454
|
return nextDescriptors;
|
|
1292
1455
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
const
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
const table = schema.tables[tableName];
|
|
1306
|
-
const rowTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Row`;
|
|
1307
|
-
const insertTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Insert`;
|
|
1308
|
-
const updateTypeName = `${toSafeIdentifier(`${schemaName} ${tableName}`, this.config.naming.modelType, "Model")}Update`;
|
|
1309
|
-
const modelConstName = `${toSafeIdentifier(`${schemaName} ${tableName} model`, this.config.naming.modelConst, "model")}`;
|
|
1310
|
-
const modelPath = normalizePath(
|
|
1311
|
-
renderOutputPath(this.config.output.targets.model, {
|
|
1312
|
-
provider: providerName,
|
|
1313
|
-
kind: "model",
|
|
1314
|
-
database: databaseName,
|
|
1315
|
-
schema: schemaName,
|
|
1316
|
-
model: tableName
|
|
1317
|
-
}, this.config.output)
|
|
1318
|
-
);
|
|
1319
|
-
modelDescriptors.push({
|
|
1456
|
+
function composeGeneratorArtifacts(input) {
|
|
1457
|
+
const { snapshot, config, createModelDescriptor, renderModelArtifact: renderModelArtifact3 } = input;
|
|
1458
|
+
const providerName = snapshot.backend;
|
|
1459
|
+
const databaseName = snapshot.database;
|
|
1460
|
+
const modelDescriptors = [];
|
|
1461
|
+
for (const schemaName of Object.keys(snapshot.schemas).sort()) {
|
|
1462
|
+
const schema = snapshot.schemas[schemaName];
|
|
1463
|
+
for (const tableName of Object.keys(schema.tables).sort()) {
|
|
1464
|
+
modelDescriptors.push(
|
|
1465
|
+
createModelDescriptor({
|
|
1466
|
+
providerName,
|
|
1467
|
+
databaseName,
|
|
1320
1468
|
schemaName,
|
|
1321
1469
|
tableName,
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
insertTypeName,
|
|
1325
|
-
updateTypeName,
|
|
1326
|
-
modelConstName,
|
|
1327
|
-
table
|
|
1328
|
-
});
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
const scopedModelDescriptors = scopeDuplicateDescriptorPathsBySchema(modelDescriptors);
|
|
1332
|
-
let schemaDescriptors = Object.keys(this.snapshot.schemas).sort().map((schemaName) => {
|
|
1333
|
-
const schemaPath = normalizePath(
|
|
1334
|
-
renderOutputPath(this.config.output.targets.schema, {
|
|
1335
|
-
provider: providerName,
|
|
1336
|
-
kind: "schema",
|
|
1337
|
-
database: databaseName,
|
|
1338
|
-
schema: schemaName,
|
|
1339
|
-
model: "index"
|
|
1340
|
-
}, this.config.output)
|
|
1470
|
+
table: schema.tables[tableName]
|
|
1471
|
+
})
|
|
1341
1472
|
);
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
models: scopedModelDescriptors.filter((model) => model.schemaName === schemaName)
|
|
1351
|
-
};
|
|
1352
|
-
});
|
|
1353
|
-
schemaDescriptors = scopeDuplicateDescriptorPathsBySchema(schemaDescriptors);
|
|
1354
|
-
const databasePath = normalizePath(
|
|
1355
|
-
renderOutputPath(this.config.output.targets.database, {
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
const scopedModelDescriptors = scopeDuplicateDescriptorPathsBySchema(modelDescriptors);
|
|
1476
|
+
let schemaDescriptors = Object.keys(snapshot.schemas).sort().map((schemaName) => ({
|
|
1477
|
+
schemaName,
|
|
1478
|
+
filePath: resolveOutputPath(
|
|
1479
|
+
config.output.targets.schema,
|
|
1480
|
+
{
|
|
1356
1481
|
provider: providerName,
|
|
1357
|
-
kind: "
|
|
1482
|
+
kind: "schema",
|
|
1358
1483
|
database: databaseName,
|
|
1359
|
-
schema:
|
|
1484
|
+
schema: schemaName,
|
|
1360
1485
|
model: "index"
|
|
1361
|
-
},
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
databaseDescriptor.databaseConstName,
|
|
1395
|
-
toSafeIdentifier("registry", this.config.naming.registryConst, "registry"),
|
|
1396
|
-
databaseName
|
|
1397
|
-
)
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
assertNoDuplicatePaths(files);
|
|
1401
|
-
return {
|
|
1402
|
-
snapshot: this.snapshot,
|
|
1403
|
-
files
|
|
1404
|
-
};
|
|
1486
|
+
},
|
|
1487
|
+
config
|
|
1488
|
+
),
|
|
1489
|
+
schemaConstName: toSafeIdentifier(
|
|
1490
|
+
`${schemaName} schema`,
|
|
1491
|
+
config.naming.schemaConst,
|
|
1492
|
+
"schema"
|
|
1493
|
+
),
|
|
1494
|
+
models: scopedModelDescriptors.filter((model) => model.schemaName === schemaName)
|
|
1495
|
+
}));
|
|
1496
|
+
schemaDescriptors = scopeDuplicateDescriptorPathsBySchema(schemaDescriptors);
|
|
1497
|
+
const databaseDescriptor = {
|
|
1498
|
+
filePath: resolveOutputPath(
|
|
1499
|
+
config.output.targets.database,
|
|
1500
|
+
{
|
|
1501
|
+
provider: providerName,
|
|
1502
|
+
kind: "database",
|
|
1503
|
+
database: databaseName,
|
|
1504
|
+
schema: "index",
|
|
1505
|
+
model: "index"
|
|
1506
|
+
},
|
|
1507
|
+
config
|
|
1508
|
+
),
|
|
1509
|
+
databaseConstName: toSafeIdentifier(
|
|
1510
|
+
`${databaseName} database`,
|
|
1511
|
+
config.naming.databaseConst,
|
|
1512
|
+
"database"
|
|
1513
|
+
),
|
|
1514
|
+
schemas: schemaDescriptors
|
|
1515
|
+
};
|
|
1516
|
+
const files = [];
|
|
1517
|
+
for (const modelDescriptor of scopedModelDescriptors) {
|
|
1518
|
+
files.push(renderModelArtifact3(modelDescriptor));
|
|
1405
1519
|
}
|
|
1406
|
-
|
|
1520
|
+
for (const schemaDescriptor of schemaDescriptors) {
|
|
1521
|
+
files.push(renderSchemaArtifact(schemaDescriptor));
|
|
1522
|
+
}
|
|
1523
|
+
files.push(renderDatabaseArtifact(databaseDescriptor));
|
|
1524
|
+
if (config.features.emitRegistry) {
|
|
1525
|
+
const registryPath = resolveOutputPath(
|
|
1526
|
+
config.output.targets.registry,
|
|
1527
|
+
{
|
|
1528
|
+
provider: providerName,
|
|
1529
|
+
kind: "registry",
|
|
1530
|
+
database: databaseName,
|
|
1531
|
+
schema: "index",
|
|
1532
|
+
model: "index"
|
|
1533
|
+
},
|
|
1534
|
+
config
|
|
1535
|
+
);
|
|
1536
|
+
files.push(
|
|
1537
|
+
renderRegistryArtifact(
|
|
1538
|
+
registryPath,
|
|
1539
|
+
databaseDescriptor.filePath,
|
|
1540
|
+
databaseDescriptor.databaseConstName,
|
|
1541
|
+
toSafeIdentifier("registry", config.naming.registryConst, "registry"),
|
|
1542
|
+
databaseName,
|
|
1543
|
+
snapshot.generatedAt,
|
|
1544
|
+
config.output.format,
|
|
1545
|
+
config.internal.schemaVersion
|
|
1546
|
+
)
|
|
1547
|
+
);
|
|
1548
|
+
}
|
|
1549
|
+
assertNoDuplicatePaths(files);
|
|
1550
|
+
return {
|
|
1551
|
+
snapshot,
|
|
1552
|
+
files
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// src/generator/table-builder-renderer.ts
|
|
1557
|
+
var SAFE_NUMBER_TYPES = /* @__PURE__ */ new Set([
|
|
1558
|
+
"int2",
|
|
1559
|
+
"int4",
|
|
1560
|
+
"float4",
|
|
1561
|
+
"float8",
|
|
1562
|
+
"smallint",
|
|
1563
|
+
"integer",
|
|
1564
|
+
"real",
|
|
1565
|
+
"double precision"
|
|
1566
|
+
]);
|
|
1567
|
+
var JSON_TYPES = /* @__PURE__ */ new Set(["json", "jsonb"]);
|
|
1568
|
+
var BOOLEAN_TYPES = /* @__PURE__ */ new Set(["bool", "boolean"]);
|
|
1569
|
+
var STRING_TYPES = /* @__PURE__ */ new Set([
|
|
1570
|
+
"int8",
|
|
1571
|
+
"bigint",
|
|
1572
|
+
"serial8",
|
|
1573
|
+
"bigserial",
|
|
1574
|
+
"numeric",
|
|
1575
|
+
"decimal",
|
|
1576
|
+
"money",
|
|
1577
|
+
"bytea"
|
|
1578
|
+
]);
|
|
1579
|
+
function normalizeTypeLabel2(column) {
|
|
1580
|
+
const preferred = (column.udtName || column.dataType).toLowerCase().trim();
|
|
1581
|
+
if (column.arrayDimensions > 0 && preferred.startsWith("_")) {
|
|
1582
|
+
return preferred.slice(1);
|
|
1583
|
+
}
|
|
1584
|
+
return preferred;
|
|
1585
|
+
}
|
|
1586
|
+
function renderColumnBuilder(column) {
|
|
1587
|
+
const label = normalizeTypeLabel2(column);
|
|
1588
|
+
let helper;
|
|
1589
|
+
let expression;
|
|
1590
|
+
if (column.typeKind === "enum" && column.enumValues && column.enumValues.length > 0) {
|
|
1591
|
+
helper = "enumeration";
|
|
1592
|
+
expression = `enumeration([${column.enumValues.map((value) => escapeStringLiteral(value)).join(", ")}] as const)`;
|
|
1593
|
+
} else if (column.arrayDimensions > 0 || JSON_TYPES.has(label) || column.typeKind === "composite") {
|
|
1594
|
+
helper = "json";
|
|
1595
|
+
expression = `json<${resolvePostgresColumnType(column)}>()`;
|
|
1596
|
+
} else if (BOOLEAN_TYPES.has(label)) {
|
|
1597
|
+
helper = "boolean";
|
|
1598
|
+
expression = "boolean()";
|
|
1599
|
+
} else if (SAFE_NUMBER_TYPES.has(label)) {
|
|
1600
|
+
helper = "number";
|
|
1601
|
+
expression = "number()";
|
|
1602
|
+
} else if (STRING_TYPES.has(label)) {
|
|
1603
|
+
helper = "string";
|
|
1604
|
+
expression = "string()";
|
|
1605
|
+
} else {
|
|
1606
|
+
helper = "string";
|
|
1607
|
+
expression = "string()";
|
|
1608
|
+
}
|
|
1609
|
+
if (column.isNullable) {
|
|
1610
|
+
expression = `${expression}.optional()`;
|
|
1611
|
+
}
|
|
1612
|
+
if (column.hasDefault) {
|
|
1613
|
+
expression = `${expression}.defaulted()`;
|
|
1614
|
+
}
|
|
1615
|
+
if (column.isGenerated) {
|
|
1616
|
+
expression = `${expression}.generated()`;
|
|
1617
|
+
}
|
|
1618
|
+
return { helper, expression };
|
|
1619
|
+
}
|
|
1620
|
+
function renderModelArtifact(descriptor, config) {
|
|
1621
|
+
const helperImports = /* @__PURE__ */ new Set(["table"]);
|
|
1622
|
+
const columnLines = Object.entries(descriptor.table.columns).map(([columnName, column]) => {
|
|
1623
|
+
const propertyName = escapeTypePropertyName(columnName);
|
|
1624
|
+
const rendered = renderColumnBuilder(column);
|
|
1625
|
+
helperImports.add(rendered.helper);
|
|
1626
|
+
return ` ${propertyName}: ${rendered.expression}`;
|
|
1627
|
+
}).join(",\n");
|
|
1628
|
+
const helperImportLine = Array.from(helperImports).sort().join(", ");
|
|
1629
|
+
const rowSchemaConstName = `${descriptor.tableConstName}_row_schema`;
|
|
1630
|
+
const insertSchemaConstName = `${descriptor.tableConstName}_insert_schema`;
|
|
1631
|
+
const updateSchemaConstName = `${descriptor.tableConstName}_update_schema`;
|
|
1632
|
+
const formSchemaConstName = `${descriptor.tableConstName}_form_schema`;
|
|
1633
|
+
const relationEntries = Object.entries(descriptor.table.relations);
|
|
1634
|
+
const relationsAssignment = config.features.emitRelations && relationEntries.length > 0 ? `
|
|
1635
|
+
Object.assign(${descriptor.tableConstName}.meta, {
|
|
1636
|
+
relations: {
|
|
1637
|
+
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
1638
|
+
}
|
|
1639
|
+
})
|
|
1640
|
+
` : "";
|
|
1641
|
+
const content = `import { ${helperImportLine} } from '@xylex-group/athena'
|
|
1642
|
+
import type { FormValuesOf, InsertOf, RowOf, UpdateOf } from '@xylex-group/athena'
|
|
1643
|
+
|
|
1644
|
+
export const ${descriptor.tableConstName} = table(${escapeStringLiteral(descriptor.tableName)})
|
|
1645
|
+
.schema(${escapeStringLiteral(descriptor.schemaName)})
|
|
1646
|
+
.columns({
|
|
1647
|
+
${columnLines}
|
|
1648
|
+
})
|
|
1649
|
+
.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})
|
|
1650
|
+
${relationsAssignment ? `${relationsAssignment}` : ""}
|
|
1651
|
+
export type ${descriptor.rowTypeName} = RowOf<typeof ${descriptor.tableConstName}>
|
|
1652
|
+
export type ${descriptor.insertTypeName} = InsertOf<typeof ${descriptor.tableConstName}>
|
|
1653
|
+
export type ${descriptor.updateTypeName} = UpdateOf<typeof ${descriptor.tableConstName}>
|
|
1654
|
+
export type ${descriptor.formValuesTypeName} = FormValuesOf<typeof ${descriptor.tableConstName}>
|
|
1655
|
+
|
|
1656
|
+
export const ${rowSchemaConstName} = ${descriptor.tableConstName}.schemas.row
|
|
1657
|
+
export const ${insertSchemaConstName} = ${descriptor.tableConstName}.schemas.insert
|
|
1658
|
+
export const ${updateSchemaConstName} = ${descriptor.tableConstName}.schemas.update
|
|
1659
|
+
export const ${formSchemaConstName} = ${descriptor.tableConstName}.schemas.form
|
|
1660
|
+
`;
|
|
1661
|
+
return {
|
|
1662
|
+
kind: "model",
|
|
1663
|
+
path: descriptor.filePath,
|
|
1664
|
+
content
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
function generateTableBuilderArtifactsFromSnapshot(snapshot, config) {
|
|
1668
|
+
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
1669
|
+
return composeGeneratorArtifacts({
|
|
1670
|
+
snapshot,
|
|
1671
|
+
config: normalizedConfig,
|
|
1672
|
+
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table }) {
|
|
1673
|
+
const tableConstName = toSafeIdentifier(tableName, "preserve", "table");
|
|
1674
|
+
return {
|
|
1675
|
+
schemaName,
|
|
1676
|
+
tableName,
|
|
1677
|
+
filePath: resolveOutputPath(
|
|
1678
|
+
normalizedConfig.output.targets.model,
|
|
1679
|
+
{
|
|
1680
|
+
provider: providerName,
|
|
1681
|
+
kind: "model",
|
|
1682
|
+
database: databaseName,
|
|
1683
|
+
schema: schemaName,
|
|
1684
|
+
model: tableName
|
|
1685
|
+
},
|
|
1686
|
+
normalizedConfig
|
|
1687
|
+
),
|
|
1688
|
+
rowTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Row`,
|
|
1689
|
+
insertTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Insert`,
|
|
1690
|
+
updateTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Update`,
|
|
1691
|
+
formValuesTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}FormValues`,
|
|
1692
|
+
tableConstName,
|
|
1693
|
+
exportConstName: tableConstName,
|
|
1694
|
+
table
|
|
1695
|
+
};
|
|
1696
|
+
},
|
|
1697
|
+
renderModelArtifact: (descriptor) => renderModelArtifact(descriptor, normalizedConfig)
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
// src/generator/renderer.ts
|
|
1702
|
+
function renderModelArtifact2(databaseName, descriptor, config) {
|
|
1703
|
+
const columnLines = Object.values(descriptor.table.columns).map((column) => {
|
|
1704
|
+
const propertyName = escapeTypePropertyName(column.name);
|
|
1705
|
+
const baseType = resolvePostgresColumnType(column);
|
|
1706
|
+
const isOptional = column.isNullable;
|
|
1707
|
+
const typeWithNullability = column.isNullable ? `${baseType} | null` : baseType;
|
|
1708
|
+
return ` ${propertyName}${isOptional ? "?" : ""}: ${typeWithNullability}`;
|
|
1709
|
+
}).join("\n");
|
|
1710
|
+
const nullableLines = Object.values(descriptor.table.columns).map((column) => ` ${renderObjectKey(column.name)}: ${column.isNullable ? "true" : "false"}`).join(",\n");
|
|
1711
|
+
const relationEntries = Object.entries(descriptor.table.relations);
|
|
1712
|
+
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
1713
|
+
relations: {
|
|
1714
|
+
${relationEntries.map(([relationKey2, relationValue]) => ` ${renderObjectKey(relationKey2)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
1715
|
+
}` : "";
|
|
1716
|
+
const content = `import { defineModel } from '@xylex-group/athena'
|
|
1717
|
+
|
|
1718
|
+
export interface ${descriptor.rowTypeName} {
|
|
1719
|
+
${columnLines}
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
export type ${descriptor.insertTypeName} = Partial<${descriptor.rowTypeName}>
|
|
1723
|
+
export type ${descriptor.updateTypeName} = Partial<${descriptor.insertTypeName}>
|
|
1724
|
+
|
|
1725
|
+
export const ${descriptor.modelConstName} = defineModel<${descriptor.rowTypeName}, ${descriptor.insertTypeName}, ${descriptor.updateTypeName}>({
|
|
1726
|
+
meta: {
|
|
1727
|
+
database: ${escapeStringLiteral(databaseName)},
|
|
1728
|
+
schema: ${escapeStringLiteral(descriptor.schemaName)},
|
|
1729
|
+
model: ${escapeStringLiteral(descriptor.tableName)},
|
|
1730
|
+
tableName: ${escapeStringLiteral(`${descriptor.schemaName}.${descriptor.tableName}`)},
|
|
1731
|
+
primaryKey: [${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")}],
|
|
1732
|
+
nullable: {
|
|
1733
|
+
${nullableLines}
|
|
1734
|
+
}${relationBlock}
|
|
1735
|
+
}
|
|
1736
|
+
})
|
|
1737
|
+
`;
|
|
1738
|
+
return {
|
|
1739
|
+
kind: "model",
|
|
1740
|
+
path: descriptor.filePath,
|
|
1741
|
+
content
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1407
1744
|
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
1408
|
-
const normalizedConfig = "
|
|
1409
|
-
|
|
1745
|
+
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
1746
|
+
if (normalizedConfig.output.format === "table-builder") {
|
|
1747
|
+
return generateTableBuilderArtifactsFromSnapshot(snapshot, normalizedConfig);
|
|
1748
|
+
}
|
|
1749
|
+
return composeGeneratorArtifacts({
|
|
1750
|
+
snapshot,
|
|
1751
|
+
config: normalizedConfig,
|
|
1752
|
+
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table }) {
|
|
1753
|
+
const modelConstName = toSafeIdentifier(
|
|
1754
|
+
`${schemaName} ${tableName} model`,
|
|
1755
|
+
normalizedConfig.naming.modelConst,
|
|
1756
|
+
"model"
|
|
1757
|
+
);
|
|
1758
|
+
return {
|
|
1759
|
+
schemaName,
|
|
1760
|
+
tableName,
|
|
1761
|
+
filePath: resolveOutputPath(
|
|
1762
|
+
normalizedConfig.output.targets.model,
|
|
1763
|
+
{
|
|
1764
|
+
provider: providerName,
|
|
1765
|
+
kind: "model",
|
|
1766
|
+
database: databaseName,
|
|
1767
|
+
schema: schemaName,
|
|
1768
|
+
model: tableName
|
|
1769
|
+
},
|
|
1770
|
+
normalizedConfig
|
|
1771
|
+
),
|
|
1772
|
+
rowTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Row`,
|
|
1773
|
+
insertTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Insert`,
|
|
1774
|
+
updateTypeName: `${toSafeIdentifier(`${schemaName} ${tableName}`, normalizedConfig.naming.modelType, "Model")}Update`,
|
|
1775
|
+
modelConstName,
|
|
1776
|
+
exportConstName: modelConstName,
|
|
1777
|
+
table
|
|
1778
|
+
};
|
|
1779
|
+
},
|
|
1780
|
+
renderModelArtifact: (descriptor) => renderModelArtifact2(snapshot.database, descriptor, normalizedConfig)
|
|
1781
|
+
});
|
|
1410
1782
|
}
|
|
1411
1783
|
|
|
1412
1784
|
// src/gateway/url.ts
|
|
@@ -1511,7 +1883,7 @@ var getSessionCookie = (request, config) => {
|
|
|
1511
1883
|
|
|
1512
1884
|
// package.json
|
|
1513
1885
|
var package_default = {
|
|
1514
|
-
version: "2.
|
|
1886
|
+
version: "2.8.2"
|
|
1515
1887
|
};
|
|
1516
1888
|
|
|
1517
1889
|
// src/sdk-version.ts
|
|
@@ -3458,11 +3830,12 @@ function createAuthClient(config = {}) {
|
|
|
3458
3830
|
// src/db/module.ts
|
|
3459
3831
|
function createDbModule(input) {
|
|
3460
3832
|
const db = {
|
|
3461
|
-
from
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3833
|
+
from: input.from,
|
|
3834
|
+
select(table, first, second) {
|
|
3835
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
3836
|
+
return input.from(table).select(void 0, first);
|
|
3837
|
+
}
|
|
3838
|
+
return input.from(table).select(first, second);
|
|
3466
3839
|
},
|
|
3467
3840
|
insert(table, values, options) {
|
|
3468
3841
|
return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
|
|
@@ -3506,7 +3879,12 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3506
3879
|
content_type: input.content_type ?? source.contentType,
|
|
3507
3880
|
size_bytes: source.sizeBytes,
|
|
3508
3881
|
public: input.public,
|
|
3509
|
-
metadata: input.metadata
|
|
3882
|
+
metadata: input.metadata,
|
|
3883
|
+
server_side_encryption: input.server_side_encryption,
|
|
3884
|
+
sse: input.sse,
|
|
3885
|
+
ssekms_key_id: input.ssekms_key_id,
|
|
3886
|
+
kms_key_id: input.kms_key_id,
|
|
3887
|
+
bucket_key_enabled: input.bucket_key_enabled
|
|
3510
3888
|
}
|
|
3511
3889
|
};
|
|
3512
3890
|
});
|
|
@@ -3517,10 +3895,17 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3517
3895
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
3518
3896
|
const request = uploadRequests[index];
|
|
3519
3897
|
const uploadUrl = uploadUrls[index];
|
|
3520
|
-
const response = await putUploadBody(
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3898
|
+
const response = await putUploadBody(
|
|
3899
|
+
uploadUrl.upload.url,
|
|
3900
|
+
uploadUrl.upload.headers ?? {},
|
|
3901
|
+
request.source,
|
|
3902
|
+
input,
|
|
3903
|
+
options,
|
|
3904
|
+
(progress) => {
|
|
3905
|
+
aggregateLoaded[index] = progress.loaded;
|
|
3906
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
3907
|
+
}
|
|
3908
|
+
);
|
|
3524
3909
|
uploaded.push({
|
|
3525
3910
|
file: uploadUrl.file,
|
|
3526
3911
|
upload: uploadUrl.upload,
|
|
@@ -3623,8 +4008,9 @@ function validateUploadConstraints(sources, input) {
|
|
|
3623
4008
|
}
|
|
3624
4009
|
}
|
|
3625
4010
|
}
|
|
3626
|
-
async function putUploadBody(url, source, input, options, onProgress) {
|
|
3627
|
-
const headers = new Headers(
|
|
4011
|
+
async function putUploadBody(url, uploadHeaders, source, input, options, onProgress) {
|
|
4012
|
+
const headers = new Headers(uploadHeaders);
|
|
4013
|
+
new Headers(input.uploadHeaders).forEach((value, key) => headers.set(key, value));
|
|
3628
4014
|
if (source.contentType && !headers.has("Content-Type")) {
|
|
3629
4015
|
headers.set("Content-Type", source.contentType);
|
|
3630
4016
|
}
|
|
@@ -3943,6 +4329,23 @@ var storageSdkManifest = {
|
|
|
3943
4329
|
responseEnvelope: "athena",
|
|
3944
4330
|
responseType: "StorageFileMutationResponse"
|
|
3945
4331
|
},
|
|
4332
|
+
{
|
|
4333
|
+
name: "postStorageFileVisibility",
|
|
4334
|
+
method: "POST",
|
|
4335
|
+
path: "/storage/files/{file_id}/visibility",
|
|
4336
|
+
pathParams: ["file_id"],
|
|
4337
|
+
requestType: "SetStorageFileVisibilityRequest",
|
|
4338
|
+
responseEnvelope: "athena",
|
|
4339
|
+
responseType: "StorageFileMutationResponse"
|
|
4340
|
+
},
|
|
4341
|
+
{
|
|
4342
|
+
name: "setManyStorageFileVisibility",
|
|
4343
|
+
method: "POST",
|
|
4344
|
+
path: "/storage/files/visibility-many",
|
|
4345
|
+
requestType: "SetManyStorageFileVisibilityRequest",
|
|
4346
|
+
responseEnvelope: "athena",
|
|
4347
|
+
responseType: "StorageFileMutationManyResponse"
|
|
4348
|
+
},
|
|
3946
4349
|
{
|
|
3947
4350
|
name: "deleteStorageFolder",
|
|
3948
4351
|
method: "POST",
|
|
@@ -3958,103 +4361,581 @@ var storageSdkManifest = {
|
|
|
3958
4361
|
requestType: "MoveStorageFolderRequest",
|
|
3959
4362
|
responseEnvelope: "athena",
|
|
3960
4363
|
responseType: "StorageFolderMutationResponse"
|
|
3961
|
-
}
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
}
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4364
|
+
},
|
|
4365
|
+
{
|
|
4366
|
+
name: "searchStorageFiles",
|
|
4367
|
+
method: "POST",
|
|
4368
|
+
path: "/storage/files/search",
|
|
4369
|
+
requestType: "SearchStorageFilesRequest",
|
|
4370
|
+
responseEnvelope: "athena",
|
|
4371
|
+
responseType: "StorageListFilesResponse"
|
|
4372
|
+
},
|
|
4373
|
+
{
|
|
4374
|
+
name: "confirmStorageUpload",
|
|
4375
|
+
method: "POST",
|
|
4376
|
+
path: "/storage/files/{file_id}/confirm-upload",
|
|
4377
|
+
pathParams: ["file_id"],
|
|
4378
|
+
requestType: "ConfirmStorageUploadRequest",
|
|
4379
|
+
responseEnvelope: "athena",
|
|
4380
|
+
responseType: "StorageFileMutationResponse"
|
|
4381
|
+
},
|
|
4382
|
+
{
|
|
4383
|
+
name: "uploadStorageFileBinary",
|
|
4384
|
+
method: "PUT",
|
|
4385
|
+
path: "/storage/files/{file_id}/upload",
|
|
4386
|
+
pathParams: ["file_id"],
|
|
4387
|
+
responseEnvelope: "athena",
|
|
4388
|
+
responseType: "StorageFileMutationResponse",
|
|
4389
|
+
binary: true
|
|
4390
|
+
},
|
|
4391
|
+
{
|
|
4392
|
+
name: "copyStorageFile",
|
|
4393
|
+
method: "POST",
|
|
4394
|
+
path: "/storage/files/{file_id}/copy",
|
|
4395
|
+
pathParams: ["file_id"],
|
|
4396
|
+
requestType: "CopyStorageFileRequest",
|
|
4397
|
+
responseEnvelope: "athena",
|
|
4398
|
+
responseType: "StorageFileMutationResponse"
|
|
4399
|
+
},
|
|
4400
|
+
{
|
|
4401
|
+
name: "deleteManyStorageFiles",
|
|
4402
|
+
method: "POST",
|
|
4403
|
+
path: "/storage/files/delete-many",
|
|
4404
|
+
requestType: "DeleteManyStorageFilesRequest",
|
|
4405
|
+
responseEnvelope: "athena",
|
|
4406
|
+
responseType: "StorageFileMutationManyResponse"
|
|
4407
|
+
},
|
|
4408
|
+
{
|
|
4409
|
+
name: "updateManyStorageFiles",
|
|
4410
|
+
method: "POST",
|
|
4411
|
+
path: "/storage/files/update-many",
|
|
4412
|
+
requestType: "UpdateManyStorageFilesRequest",
|
|
4413
|
+
responseEnvelope: "athena",
|
|
4414
|
+
responseType: "StorageFileMutationManyResponse"
|
|
4415
|
+
},
|
|
4416
|
+
{
|
|
4417
|
+
name: "restoreStorageFile",
|
|
4418
|
+
method: "POST",
|
|
4419
|
+
path: "/storage/files/{file_id}/restore",
|
|
4420
|
+
pathParams: ["file_id"],
|
|
4421
|
+
responseEnvelope: "athena",
|
|
4422
|
+
responseType: "StorageFileMutationResponse"
|
|
4423
|
+
},
|
|
4424
|
+
{
|
|
4425
|
+
name: "purgeStorageFile",
|
|
4426
|
+
method: "DELETE",
|
|
4427
|
+
path: "/storage/files/{file_id}/purge",
|
|
4428
|
+
pathParams: ["file_id"],
|
|
4429
|
+
responseEnvelope: "athena",
|
|
4430
|
+
responseType: "StorageFileMutationResponse"
|
|
4431
|
+
},
|
|
4432
|
+
{
|
|
4433
|
+
name: "getStorageFilePublicUrl",
|
|
4434
|
+
method: "GET",
|
|
4435
|
+
path: "/storage/files/{file_id}/public-url",
|
|
4436
|
+
pathParams: ["file_id"],
|
|
4437
|
+
responseEnvelope: "athena",
|
|
4438
|
+
responseType: "Record<string, unknown>"
|
|
4439
|
+
},
|
|
4440
|
+
{
|
|
4441
|
+
name: "getStorageFileProxyUrl",
|
|
4442
|
+
method: "GET",
|
|
4443
|
+
path: "/storage/files/{file_id}/proxy-url",
|
|
4444
|
+
pathParams: ["file_id"],
|
|
4445
|
+
queryParams: ["purpose"],
|
|
4446
|
+
responseEnvelope: "athena",
|
|
4447
|
+
responseType: "Record<string, unknown>"
|
|
4448
|
+
},
|
|
4449
|
+
{
|
|
4450
|
+
name: "listStorageFileVersions",
|
|
4451
|
+
method: "GET",
|
|
4452
|
+
path: "/storage/files/{file_id}/versions",
|
|
4453
|
+
pathParams: ["file_id"],
|
|
4454
|
+
responseEnvelope: "athena",
|
|
4455
|
+
responseType: "Record<string, unknown>"
|
|
4456
|
+
},
|
|
4457
|
+
{
|
|
4458
|
+
name: "restoreStorageFileVersion",
|
|
4459
|
+
method: "POST",
|
|
4460
|
+
path: "/storage/files/{file_id}/versions/{version_id}/restore",
|
|
4461
|
+
pathParams: ["file_id", "version_id"],
|
|
4462
|
+
responseEnvelope: "athena",
|
|
4463
|
+
responseType: "Record<string, unknown>"
|
|
4464
|
+
},
|
|
4465
|
+
{
|
|
4466
|
+
name: "deleteStorageFileVersion",
|
|
4467
|
+
method: "DELETE",
|
|
4468
|
+
path: "/storage/files/{file_id}/versions/{version_id}",
|
|
4469
|
+
pathParams: ["file_id", "version_id"],
|
|
4470
|
+
responseEnvelope: "athena",
|
|
4471
|
+
responseType: "Record<string, unknown>"
|
|
4472
|
+
},
|
|
4473
|
+
{
|
|
4474
|
+
name: "getStorageFileRetention",
|
|
4475
|
+
method: "GET",
|
|
4476
|
+
path: "/storage/files/{file_id}/retention",
|
|
4477
|
+
pathParams: ["file_id"],
|
|
4478
|
+
queryParams: ["version_id"],
|
|
4479
|
+
responseEnvelope: "athena",
|
|
4480
|
+
responseType: "Record<string, unknown>"
|
|
4481
|
+
},
|
|
4482
|
+
{
|
|
4483
|
+
name: "setStorageFileRetention",
|
|
4484
|
+
method: "POST",
|
|
4485
|
+
path: "/storage/files/{file_id}/retention",
|
|
4486
|
+
pathParams: ["file_id"],
|
|
4487
|
+
requestType: "StorageFileRetentionRequest",
|
|
4488
|
+
responseEnvelope: "athena",
|
|
4489
|
+
responseType: "Record<string, unknown>"
|
|
4490
|
+
},
|
|
4491
|
+
{
|
|
4492
|
+
name: "listStorageFolders",
|
|
4493
|
+
method: "POST",
|
|
4494
|
+
path: "/storage/folders/list",
|
|
4495
|
+
requestType: "ListStorageFoldersRequest",
|
|
4496
|
+
responseEnvelope: "athena",
|
|
4497
|
+
responseType: "Record<string, unknown>"
|
|
4498
|
+
},
|
|
4499
|
+
{
|
|
4500
|
+
name: "treeStorageFolders",
|
|
4501
|
+
method: "POST",
|
|
4502
|
+
path: "/storage/folders/tree",
|
|
4503
|
+
requestType: "TreeStorageFoldersRequest",
|
|
4504
|
+
responseEnvelope: "athena",
|
|
4505
|
+
responseType: "Record<string, unknown>"
|
|
4506
|
+
},
|
|
4507
|
+
{
|
|
4508
|
+
name: "listStoragePermissions",
|
|
4509
|
+
method: "POST",
|
|
4510
|
+
path: "/storage/permissions/list",
|
|
4511
|
+
requestType: "StoragePermissionListRequest",
|
|
4512
|
+
responseEnvelope: "athena",
|
|
4513
|
+
responseType: "StoragePermissionListResponse"
|
|
4514
|
+
},
|
|
4515
|
+
{
|
|
4516
|
+
name: "grantStoragePermission",
|
|
4517
|
+
method: "POST",
|
|
4518
|
+
path: "/storage/permissions/grant",
|
|
4519
|
+
requestType: "StoragePermissionGrantRequest",
|
|
4520
|
+
responseEnvelope: "athena",
|
|
4521
|
+
responseType: "Record<string, unknown>"
|
|
4522
|
+
},
|
|
4523
|
+
{
|
|
4524
|
+
name: "revokeStoragePermission",
|
|
4525
|
+
method: "POST",
|
|
4526
|
+
path: "/storage/permissions/revoke",
|
|
4527
|
+
requestType: "StoragePermissionRevokeRequest",
|
|
4528
|
+
responseEnvelope: "athena",
|
|
4529
|
+
responseType: "Record<string, unknown>"
|
|
4530
|
+
},
|
|
4531
|
+
{
|
|
4532
|
+
name: "checkStoragePermission",
|
|
4533
|
+
method: "POST",
|
|
4534
|
+
path: "/storage/permissions/check",
|
|
4535
|
+
requestType: "StoragePermissionCheckRequest",
|
|
4536
|
+
responseEnvelope: "athena",
|
|
4537
|
+
responseType: "StoragePermissionCheckResponse"
|
|
4538
|
+
},
|
|
4539
|
+
{
|
|
4540
|
+
name: "listStorageObjects",
|
|
4541
|
+
method: "POST",
|
|
4542
|
+
path: "/storage/objects",
|
|
4543
|
+
requestType: "StorageListObjectsRequest",
|
|
4544
|
+
responseEnvelope: "athena",
|
|
4545
|
+
responseType: "Record<string, unknown>"
|
|
4546
|
+
},
|
|
4547
|
+
{
|
|
4548
|
+
name: "headStorageObject",
|
|
4549
|
+
method: "POST",
|
|
4550
|
+
path: "/storage/objects/head",
|
|
4551
|
+
requestType: "StorageObjectRequest",
|
|
4552
|
+
responseEnvelope: "athena",
|
|
4553
|
+
responseType: "Record<string, unknown>"
|
|
4554
|
+
},
|
|
4555
|
+
{
|
|
4556
|
+
name: "existsStorageObject",
|
|
4557
|
+
method: "POST",
|
|
4558
|
+
path: "/storage/objects/exists",
|
|
4559
|
+
requestType: "StorageObjectRequest",
|
|
4560
|
+
responseEnvelope: "athena",
|
|
4561
|
+
responseType: "Record<string, unknown>"
|
|
4562
|
+
},
|
|
4563
|
+
{
|
|
4564
|
+
name: "validateStorageObject",
|
|
4565
|
+
method: "POST",
|
|
4566
|
+
path: "/storage/objects/validate",
|
|
4567
|
+
requestType: "StorageObjectValidateRequest",
|
|
4568
|
+
responseEnvelope: "athena",
|
|
4569
|
+
responseType: "Record<string, unknown>"
|
|
4570
|
+
},
|
|
4571
|
+
{
|
|
4572
|
+
name: "updateStorageObject",
|
|
4573
|
+
method: "POST",
|
|
4574
|
+
path: "/storage/objects/update",
|
|
4575
|
+
requestType: "StorageUpdateObjectRequest",
|
|
4576
|
+
responseEnvelope: "athena",
|
|
4577
|
+
responseType: "Record<string, unknown>"
|
|
4578
|
+
},
|
|
4579
|
+
{
|
|
4580
|
+
name: "copyStorageObject",
|
|
4581
|
+
method: "POST",
|
|
4582
|
+
path: "/storage/objects/copy",
|
|
4583
|
+
requestType: "StorageObjectCopyRequest",
|
|
4584
|
+
responseEnvelope: "athena",
|
|
4585
|
+
responseType: "Record<string, unknown>"
|
|
4586
|
+
},
|
|
4587
|
+
{
|
|
4588
|
+
name: "getStorageObjectUrl",
|
|
4589
|
+
method: "POST",
|
|
4590
|
+
path: "/storage/objects/url",
|
|
4591
|
+
requestType: "StorageObjectRequest",
|
|
4592
|
+
responseEnvelope: "athena",
|
|
4593
|
+
responseType: "Record<string, unknown>"
|
|
4594
|
+
},
|
|
4595
|
+
{
|
|
4596
|
+
name: "getStorageObjectPublicUrl",
|
|
4597
|
+
method: "POST",
|
|
4598
|
+
path: "/storage/objects/public-url",
|
|
4599
|
+
requestType: "StorageObjectPublicUrlRequest",
|
|
4600
|
+
responseEnvelope: "athena",
|
|
4601
|
+
responseType: "Record<string, unknown>"
|
|
4602
|
+
},
|
|
4603
|
+
{
|
|
4604
|
+
name: "deleteStorageObject",
|
|
4605
|
+
method: "POST",
|
|
4606
|
+
path: "/storage/objects/delete",
|
|
4607
|
+
requestType: "StorageObjectRequest",
|
|
4608
|
+
responseEnvelope: "athena",
|
|
4609
|
+
responseType: "Record<string, unknown>"
|
|
4610
|
+
},
|
|
4611
|
+
{
|
|
4612
|
+
name: "createStorageObjectUploadUrl",
|
|
4613
|
+
method: "POST",
|
|
4614
|
+
path: "/storage/objects/upload-url",
|
|
4615
|
+
requestType: "StoragePresignUploadRequest",
|
|
4616
|
+
responseEnvelope: "athena",
|
|
4617
|
+
responseType: "Record<string, unknown>"
|
|
4618
|
+
},
|
|
4619
|
+
{
|
|
4620
|
+
name: "createStorageObjectPostPolicy",
|
|
4621
|
+
method: "POST",
|
|
4622
|
+
path: "/storage/objects/post-policy",
|
|
4623
|
+
requestType: "StorageSignedPostPolicyRequest",
|
|
4624
|
+
responseEnvelope: "athena",
|
|
4625
|
+
responseType: "Record<string, unknown>"
|
|
4626
|
+
},
|
|
4627
|
+
{
|
|
4628
|
+
name: "listStorageObjectVersions",
|
|
4629
|
+
method: "POST",
|
|
4630
|
+
path: "/storage/objects/versions",
|
|
4631
|
+
requestType: "StorageObjectVersionListRequest",
|
|
4632
|
+
responseEnvelope: "athena",
|
|
4633
|
+
responseType: "Record<string, unknown>"
|
|
4634
|
+
},
|
|
4635
|
+
{
|
|
4636
|
+
name: "restoreStorageObjectVersion",
|
|
4637
|
+
method: "POST",
|
|
4638
|
+
path: "/storage/objects/versions/restore",
|
|
4639
|
+
requestType: "StorageObjectVersionMutationRequest",
|
|
4640
|
+
responseEnvelope: "athena",
|
|
4641
|
+
responseType: "Record<string, unknown>"
|
|
4642
|
+
},
|
|
4643
|
+
{
|
|
4644
|
+
name: "deleteStorageObjectVersion",
|
|
4645
|
+
method: "POST",
|
|
4646
|
+
path: "/storage/objects/versions/delete",
|
|
4647
|
+
requestType: "StorageObjectVersionMutationRequest",
|
|
4648
|
+
responseEnvelope: "athena",
|
|
4649
|
+
responseType: "Record<string, unknown>"
|
|
4650
|
+
},
|
|
4651
|
+
{
|
|
4652
|
+
name: "createStorageObjectFolder",
|
|
4653
|
+
method: "POST",
|
|
4654
|
+
path: "/storage/objects/folder",
|
|
4655
|
+
requestType: "StorageObjectFolderCreateRequest",
|
|
4656
|
+
responseEnvelope: "athena",
|
|
4657
|
+
responseType: "Record<string, unknown>"
|
|
4658
|
+
},
|
|
4659
|
+
{
|
|
4660
|
+
name: "deleteStorageObjectFolder",
|
|
4661
|
+
method: "POST",
|
|
4662
|
+
path: "/storage/objects/folder/delete",
|
|
4663
|
+
requestType: "StorageObjectFolderDeleteRequest",
|
|
4664
|
+
responseEnvelope: "athena",
|
|
4665
|
+
responseType: "Record<string, unknown>"
|
|
4666
|
+
},
|
|
4667
|
+
{
|
|
4668
|
+
name: "renameStorageObjectFolder",
|
|
4669
|
+
method: "POST",
|
|
4670
|
+
path: "/storage/objects/folder/rename",
|
|
4671
|
+
requestType: "StorageObjectFolderRenameRequest",
|
|
4672
|
+
responseEnvelope: "athena",
|
|
4673
|
+
responseType: "Record<string, unknown>"
|
|
4674
|
+
},
|
|
4675
|
+
{
|
|
4676
|
+
name: "listStorageBuckets",
|
|
4677
|
+
method: "POST",
|
|
4678
|
+
path: "/storage/buckets/list",
|
|
4679
|
+
requestType: "Omit<StorageObjectBaseRequest, 'bucket'>",
|
|
4680
|
+
responseEnvelope: "athena",
|
|
4681
|
+
responseType: "Record<string, unknown>"
|
|
4682
|
+
},
|
|
4683
|
+
{
|
|
4684
|
+
name: "createStorageBucket",
|
|
4685
|
+
method: "POST",
|
|
4686
|
+
path: "/storage/buckets/create",
|
|
4687
|
+
requestType: "StorageObjectBaseRequest",
|
|
4688
|
+
responseEnvelope: "athena",
|
|
4689
|
+
responseType: "Record<string, unknown>"
|
|
4690
|
+
},
|
|
4691
|
+
{
|
|
4692
|
+
name: "deleteStorageBucket",
|
|
4693
|
+
method: "POST",
|
|
4694
|
+
path: "/storage/buckets/delete",
|
|
4695
|
+
requestType: "StorageObjectBaseRequest",
|
|
4696
|
+
responseEnvelope: "athena",
|
|
4697
|
+
responseType: "Record<string, unknown>"
|
|
4698
|
+
},
|
|
4699
|
+
{
|
|
4700
|
+
name: "getStorageBucketLifecycle",
|
|
4701
|
+
method: "POST",
|
|
4702
|
+
path: "/storage/buckets/lifecycle",
|
|
4703
|
+
requestType: "StorageBucketLifecycleRequest",
|
|
4704
|
+
responseEnvelope: "athena",
|
|
4705
|
+
responseType: "Record<string, unknown>"
|
|
4706
|
+
},
|
|
4707
|
+
{
|
|
4708
|
+
name: "setStorageBucketLifecycle",
|
|
4709
|
+
method: "POST",
|
|
4710
|
+
path: "/storage/buckets/lifecycle/set",
|
|
4711
|
+
requestType: "StorageSetBucketLifecycleRequest",
|
|
4712
|
+
responseEnvelope: "athena",
|
|
4713
|
+
responseType: "Record<string, unknown>"
|
|
4714
|
+
},
|
|
4715
|
+
{
|
|
4716
|
+
name: "deleteStorageBucketLifecycle",
|
|
4717
|
+
method: "POST",
|
|
4718
|
+
path: "/storage/buckets/lifecycle/delete",
|
|
4719
|
+
requestType: "StorageBucketLifecycleRequest",
|
|
4720
|
+
responseEnvelope: "athena",
|
|
4721
|
+
responseType: "Record<string, unknown>"
|
|
4722
|
+
},
|
|
4723
|
+
{
|
|
4724
|
+
name: "getStorageBucketPolicy",
|
|
4725
|
+
method: "POST",
|
|
4726
|
+
path: "/storage/buckets/policy",
|
|
4727
|
+
requestType: "StorageBucketPolicyRequest",
|
|
4728
|
+
responseEnvelope: "athena",
|
|
4729
|
+
responseType: "Record<string, unknown>"
|
|
4730
|
+
},
|
|
4731
|
+
{
|
|
4732
|
+
name: "setStorageBucketPolicy",
|
|
4733
|
+
method: "POST",
|
|
4734
|
+
path: "/storage/buckets/policy/set",
|
|
4735
|
+
requestType: "StorageSetBucketPolicyRequest",
|
|
4736
|
+
responseEnvelope: "athena",
|
|
4737
|
+
responseType: "Record<string, unknown>"
|
|
4738
|
+
},
|
|
4739
|
+
{
|
|
4740
|
+
name: "deleteStorageBucketPolicy",
|
|
4741
|
+
method: "POST",
|
|
4742
|
+
path: "/storage/buckets/policy/delete",
|
|
4743
|
+
requestType: "StorageBucketPolicyRequest",
|
|
4744
|
+
responseEnvelope: "athena",
|
|
4745
|
+
responseType: "Record<string, unknown>"
|
|
4746
|
+
},
|
|
4747
|
+
{
|
|
4748
|
+
name: "getStorageBucketPublicAccess",
|
|
4749
|
+
method: "POST",
|
|
4750
|
+
path: "/storage/buckets/public-access",
|
|
4751
|
+
requestType: "StoragePublicAccessBlockRequest",
|
|
4752
|
+
responseEnvelope: "athena",
|
|
4753
|
+
responseType: "Record<string, unknown>"
|
|
4754
|
+
},
|
|
4755
|
+
{
|
|
4756
|
+
name: "setStorageBucketPublicAccess",
|
|
4757
|
+
method: "POST",
|
|
4758
|
+
path: "/storage/buckets/public-access/set",
|
|
4759
|
+
requestType: "StorageSetPublicAccessBlockRequest",
|
|
4760
|
+
responseEnvelope: "athena",
|
|
4761
|
+
responseType: "Record<string, unknown>"
|
|
4762
|
+
},
|
|
4763
|
+
{
|
|
4764
|
+
name: "deleteStorageBucketPublicAccess",
|
|
4765
|
+
method: "POST",
|
|
4766
|
+
path: "/storage/buckets/public-access/delete",
|
|
4767
|
+
requestType: "StoragePublicAccessBlockRequest",
|
|
4768
|
+
responseEnvelope: "athena",
|
|
4769
|
+
responseType: "Record<string, unknown>"
|
|
4770
|
+
},
|
|
4771
|
+
{
|
|
4772
|
+
name: "getStorageBucketCors",
|
|
4773
|
+
method: "POST",
|
|
4774
|
+
path: "/storage/buckets/cors",
|
|
4775
|
+
requestType: "StorageBucketCorsRequest",
|
|
4776
|
+
responseEnvelope: "athena",
|
|
4777
|
+
responseType: "Record<string, unknown>"
|
|
4778
|
+
},
|
|
4779
|
+
{
|
|
4780
|
+
name: "setStorageBucketCors",
|
|
4781
|
+
method: "POST",
|
|
4782
|
+
path: "/storage/buckets/cors/set",
|
|
4783
|
+
requestType: "StorageSetBucketCorsRequest",
|
|
4784
|
+
responseEnvelope: "athena",
|
|
4785
|
+
responseType: "Record<string, unknown>"
|
|
4786
|
+
},
|
|
4787
|
+
{
|
|
4788
|
+
name: "deleteStorageBucketCors",
|
|
4789
|
+
method: "POST",
|
|
4790
|
+
path: "/storage/buckets/cors/delete",
|
|
4791
|
+
requestType: "StorageBucketCorsRequest",
|
|
4792
|
+
responseEnvelope: "athena",
|
|
4793
|
+
responseType: "Record<string, unknown>"
|
|
4794
|
+
},
|
|
4795
|
+
{
|
|
4796
|
+
name: "createStorageMultipartUpload",
|
|
4797
|
+
method: "POST",
|
|
4798
|
+
path: "/storage/multipart/create",
|
|
4799
|
+
requestType: "StorageMultipartCreateRequest",
|
|
4800
|
+
responseEnvelope: "athena",
|
|
4801
|
+
responseType: "Record<string, unknown>"
|
|
4802
|
+
},
|
|
4803
|
+
{
|
|
4804
|
+
name: "signStorageMultipartPart",
|
|
4805
|
+
method: "POST",
|
|
4806
|
+
path: "/storage/multipart/sign-part",
|
|
4807
|
+
requestType: "StorageMultipartSignPartRequest",
|
|
4808
|
+
responseEnvelope: "athena",
|
|
4809
|
+
responseType: "Record<string, unknown>"
|
|
4810
|
+
},
|
|
4811
|
+
{
|
|
4812
|
+
name: "completeStorageMultipartUpload",
|
|
4813
|
+
method: "POST",
|
|
4814
|
+
path: "/storage/multipart/complete",
|
|
4815
|
+
requestType: "StorageMultipartCompleteRequest",
|
|
4816
|
+
responseEnvelope: "athena",
|
|
4817
|
+
responseType: "StorageFileMutationResponse"
|
|
4818
|
+
},
|
|
4819
|
+
{
|
|
4820
|
+
name: "abortStorageMultipartUpload",
|
|
4821
|
+
method: "POST",
|
|
4822
|
+
path: "/storage/multipart/abort",
|
|
4823
|
+
requestType: "StorageMultipartAbortRequest",
|
|
4824
|
+
responseEnvelope: "athena",
|
|
4825
|
+
responseType: "Record<string, unknown>"
|
|
4826
|
+
},
|
|
4827
|
+
{
|
|
4828
|
+
name: "listStorageMultipartParts",
|
|
4829
|
+
method: "POST",
|
|
4830
|
+
path: "/storage/multipart/list-parts",
|
|
4831
|
+
requestType: "StorageMultipartListPartsRequest",
|
|
4832
|
+
responseEnvelope: "athena",
|
|
4833
|
+
responseType: "Record<string, unknown>"
|
|
4834
|
+
},
|
|
4835
|
+
{
|
|
4836
|
+
name: "listStorageAuditEvents",
|
|
4837
|
+
method: "POST",
|
|
4838
|
+
path: "/storage/audit/list",
|
|
4839
|
+
requestType: "StorageAuditQueryRequest",
|
|
4840
|
+
responseEnvelope: "athena",
|
|
4841
|
+
responseType: "StorageAuditListResponse"
|
|
4842
|
+
}
|
|
4843
|
+
]
|
|
4844
|
+
};
|
|
4845
|
+
var AthenaStorageError = class extends Error {
|
|
4846
|
+
code;
|
|
4847
|
+
athenaCode;
|
|
4848
|
+
kind;
|
|
4849
|
+
category;
|
|
4850
|
+
retryable;
|
|
4851
|
+
status;
|
|
4852
|
+
endpoint;
|
|
4853
|
+
method;
|
|
4854
|
+
requestId;
|
|
4855
|
+
hint;
|
|
4856
|
+
causeDetail;
|
|
4857
|
+
raw;
|
|
4858
|
+
normalized;
|
|
4859
|
+
__athenaNormalizedError;
|
|
4860
|
+
constructor(input) {
|
|
4861
|
+
super(input.message, { cause: input.cause });
|
|
4862
|
+
this.name = "AthenaStorageError";
|
|
4863
|
+
this.code = input.code;
|
|
4864
|
+
this.status = input.status;
|
|
4865
|
+
this.endpoint = input.endpoint;
|
|
4866
|
+
this.method = input.method;
|
|
4867
|
+
this.requestId = input.requestId;
|
|
4868
|
+
this.hint = input.hint;
|
|
4869
|
+
this.causeDetail = causeToString(input.cause);
|
|
4870
|
+
this.raw = input.raw ?? null;
|
|
4871
|
+
this.normalized = normalizeStorageErrorInput(input);
|
|
4872
|
+
this.__athenaNormalizedError = this.normalized;
|
|
4873
|
+
this.athenaCode = this.normalized.code;
|
|
4874
|
+
this.kind = this.normalized.kind;
|
|
4875
|
+
this.category = this.normalized.category;
|
|
4876
|
+
this.retryable = this.normalized.retryable;
|
|
4877
|
+
Object.defineProperty(this, "__athenaNormalizedError", {
|
|
4878
|
+
value: this.normalized,
|
|
4879
|
+
enumerable: false,
|
|
4880
|
+
configurable: false,
|
|
4881
|
+
writable: false
|
|
4882
|
+
});
|
|
4883
|
+
}
|
|
4884
|
+
toDetails() {
|
|
4885
|
+
return {
|
|
4886
|
+
code: this.code,
|
|
4887
|
+
athenaCode: this.athenaCode,
|
|
4888
|
+
kind: this.kind,
|
|
4889
|
+
category: this.category,
|
|
4890
|
+
retryable: this.retryable,
|
|
4891
|
+
message: this.message,
|
|
4892
|
+
status: this.status,
|
|
4893
|
+
endpoint: this.endpoint,
|
|
4894
|
+
method: this.method,
|
|
4895
|
+
requestId: this.requestId,
|
|
4896
|
+
hint: this.hint,
|
|
4897
|
+
cause: this.causeDetail,
|
|
4898
|
+
raw: this.raw
|
|
4899
|
+
};
|
|
4900
|
+
}
|
|
4901
|
+
};
|
|
4902
|
+
function isRecord6(value) {
|
|
4903
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4904
|
+
}
|
|
4905
|
+
function causeToString(cause) {
|
|
4906
|
+
if (cause === void 0 || cause === null) return void 0;
|
|
4907
|
+
if (typeof cause === "string") return cause;
|
|
4908
|
+
if (cause instanceof Error && cause.message.trim()) return cause.message.trim();
|
|
4909
|
+
try {
|
|
4910
|
+
return JSON.stringify(cause);
|
|
4911
|
+
} catch {
|
|
4912
|
+
return String(cause);
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
function storageGatewayCode(code) {
|
|
4916
|
+
if (code === "INVALID_URL") return "INVALID_URL";
|
|
4917
|
+
if (code === "NETWORK_ERROR") return "NETWORK_ERROR";
|
|
4918
|
+
if (code === "INVALID_JSON" || code === "INVALID_ATHENA_ENVELOPE") return "INVALID_JSON";
|
|
4919
|
+
if (code === "HTTP_ERROR") return "HTTP_ERROR";
|
|
4920
|
+
return "UNKNOWN_ERROR";
|
|
4921
|
+
}
|
|
4922
|
+
function headerValue(headers, names) {
|
|
4923
|
+
for (const name of names) {
|
|
4924
|
+
const value = headers.get(name);
|
|
4925
|
+
if (value?.trim()) return value.trim();
|
|
4926
|
+
}
|
|
4927
|
+
return void 0;
|
|
4928
|
+
}
|
|
4929
|
+
function storageOperationFromEndpoint(endpoint, method) {
|
|
4930
|
+
const endpointPath = String(endpoint).split("?")[0];
|
|
4931
|
+
for (const candidate of storageSdkManifest.methods) {
|
|
4932
|
+
if (candidate.method !== method) continue;
|
|
4933
|
+
const pattern = `^${candidate.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{[^/]+\\\}/g, "[^/]+")}$`;
|
|
4934
|
+
if (new RegExp(pattern).test(endpointPath)) {
|
|
4935
|
+
return candidate.name;
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
4938
|
+
return `storage:${method.toLowerCase()}`;
|
|
4058
4939
|
}
|
|
4059
4940
|
function normalizeStorageErrorInput(input) {
|
|
4060
4941
|
return normalizeAthenaError(
|
|
@@ -4129,6 +5010,15 @@ function appendQuery(path, query) {
|
|
|
4129
5010
|
function storagePath(path) {
|
|
4130
5011
|
return path;
|
|
4131
5012
|
}
|
|
5013
|
+
function resolveStorageEndpointPath(endpoint, runtimeOptions) {
|
|
5014
|
+
if (!runtimeOptions?.stripBasePath) {
|
|
5015
|
+
return endpoint;
|
|
5016
|
+
}
|
|
5017
|
+
const [pathname, queryText] = String(endpoint).split("?", 2);
|
|
5018
|
+
const trimmedPathname = pathname.startsWith("/storage/") ? pathname.slice("/storage".length) : pathname === "/storage" ? "/" : pathname;
|
|
5019
|
+
const resolvedPath = trimmedPathname.startsWith("/") ? trimmedPathname : `/${trimmedPathname}`;
|
|
5020
|
+
return storagePath(queryText ? `${resolvedPath}?${queryText}` : resolvedPath);
|
|
5021
|
+
}
|
|
4132
5022
|
function withPathParam(path, name, value) {
|
|
4133
5023
|
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
4134
5024
|
}
|
|
@@ -4167,8 +5057,8 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
|
|
|
4167
5057
|
let url;
|
|
4168
5058
|
let headers;
|
|
4169
5059
|
try {
|
|
4170
|
-
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4171
|
-
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
5060
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
5061
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4172
5062
|
headers = gateway.buildHeaders(options);
|
|
4173
5063
|
} catch (error) {
|
|
4174
5064
|
return rejectStorageError(
|
|
@@ -4292,8 +5182,8 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
4292
5182
|
let url;
|
|
4293
5183
|
let headers;
|
|
4294
5184
|
try {
|
|
4295
|
-
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4296
|
-
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
5185
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
5186
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4297
5187
|
headers = gateway.buildHeaders(options);
|
|
4298
5188
|
} catch (error) {
|
|
4299
5189
|
return rejectStorageError(
|
|
@@ -4401,7 +5291,7 @@ async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
|
4401
5291
|
return fetch(uploadUrl, init);
|
|
4402
5292
|
}
|
|
4403
5293
|
function attachManagedUpload(upload) {
|
|
4404
|
-
const headers = {};
|
|
5294
|
+
const headers = { ...upload.headers ?? {} };
|
|
4405
5295
|
return {
|
|
4406
5296
|
...upload,
|
|
4407
5297
|
method: "PUT",
|
|
@@ -4447,15 +5337,20 @@ function normalizeUploadUrlRequest(input) {
|
|
|
4447
5337
|
file_id: input.file_id ?? input.fileId,
|
|
4448
5338
|
public: input.public,
|
|
4449
5339
|
visibility: input.visibility,
|
|
4450
|
-
metadata: input.metadata
|
|
5340
|
+
metadata: input.metadata,
|
|
5341
|
+
server_side_encryption: input.server_side_encryption,
|
|
5342
|
+
sse: input.sse,
|
|
5343
|
+
ssekms_key_id: input.ssekms_key_id,
|
|
5344
|
+
kms_key_id: input.kms_key_id,
|
|
5345
|
+
bucket_key_enabled: input.bucket_key_enabled
|
|
4451
5346
|
};
|
|
4452
5347
|
}
|
|
4453
5348
|
async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options, runtimeOptions) {
|
|
4454
5349
|
let url;
|
|
4455
5350
|
let headers;
|
|
4456
5351
|
try {
|
|
4457
|
-
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
4458
|
-
url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
5352
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : runtimeOptions?.baseUrl ? normalizeAthenaGatewayBaseUrl(runtimeOptions.baseUrl) : gateway.baseUrl;
|
|
5353
|
+
url = buildAthenaGatewayUrl(baseUrl, resolveStorageEndpointPath(endpoint, runtimeOptions));
|
|
4459
5354
|
headers = gateway.buildHeaders(options);
|
|
4460
5355
|
} catch (error) {
|
|
4461
5356
|
return rejectStorageError(
|
|
@@ -4579,6 +5474,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4579
5474
|
return parsedBody.parsed.data;
|
|
4580
5475
|
}
|
|
4581
5476
|
function createStorageModule(gateway, runtimeOptions) {
|
|
5477
|
+
const resolvedRuntimeOptions = runtimeOptions;
|
|
4582
5478
|
const callRaw = (path, method, payload, options) => callStorageEndpoint(
|
|
4583
5479
|
gateway,
|
|
4584
5480
|
storagePath(path),
|
|
@@ -4586,7 +5482,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4586
5482
|
"raw",
|
|
4587
5483
|
payload,
|
|
4588
5484
|
options,
|
|
4589
|
-
|
|
5485
|
+
resolvedRuntimeOptions
|
|
4590
5486
|
);
|
|
4591
5487
|
const callAthena2 = (path, method, payload, options) => callStorageEndpoint(
|
|
4592
5488
|
gateway,
|
|
@@ -4595,7 +5491,13 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4595
5491
|
"athena",
|
|
4596
5492
|
payload,
|
|
4597
5493
|
options,
|
|
4598
|
-
|
|
5494
|
+
resolvedRuntimeOptions
|
|
5495
|
+
);
|
|
5496
|
+
const callStorageFileVisibility = (fileId, method, input, options) => callAthena2(
|
|
5497
|
+
withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId),
|
|
5498
|
+
method,
|
|
5499
|
+
input,
|
|
5500
|
+
options
|
|
4599
5501
|
);
|
|
4600
5502
|
const base = {
|
|
4601
5503
|
listStorageCatalogs(options) {
|
|
@@ -4637,7 +5539,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4637
5539
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
4638
5540
|
query
|
|
4639
5541
|
);
|
|
4640
|
-
return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options,
|
|
5542
|
+
return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, resolvedRuntimeOptions);
|
|
4641
5543
|
},
|
|
4642
5544
|
updateStorageFile(fileId, input, options) {
|
|
4643
5545
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "PATCH", input, options);
|
|
@@ -4646,7 +5548,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4646
5548
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "DELETE", void 0, options);
|
|
4647
5549
|
},
|
|
4648
5550
|
setStorageFileVisibility(fileId, input, options) {
|
|
4649
|
-
return
|
|
5551
|
+
return callStorageFileVisibility(fileId, "PATCH", input, options);
|
|
4650
5552
|
},
|
|
4651
5553
|
deleteStorageFolder(input, options) {
|
|
4652
5554
|
return callAthena2("/storage/folders/delete", "POST", input, options);
|
|
@@ -4684,7 +5586,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4684
5586
|
storagePath(withPathParam("/storage/files/{file_id}/upload", "file_id", fileId)),
|
|
4685
5587
|
body,
|
|
4686
5588
|
options,
|
|
4687
|
-
|
|
5589
|
+
resolvedRuntimeOptions
|
|
4688
5590
|
);
|
|
4689
5591
|
},
|
|
4690
5592
|
search(input, options) {
|
|
@@ -4718,13 +5620,62 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4718
5620
|
publicUrl(fileId, options) {
|
|
4719
5621
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
4720
5622
|
},
|
|
5623
|
+
proxyUrl(fileId, query, options) {
|
|
5624
|
+
const path = appendQuery(
|
|
5625
|
+
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
5626
|
+
query
|
|
5627
|
+
);
|
|
5628
|
+
return callAthena2(path, "GET", void 0, options);
|
|
5629
|
+
},
|
|
4721
5630
|
proxy(fileId, query, options) {
|
|
4722
5631
|
return base.getStorageFileProxy(fileId, query, options);
|
|
4723
5632
|
},
|
|
4724
|
-
|
|
5633
|
+
versions(fileId, options) {
|
|
5634
|
+
return callAthena2(withPathParam("/storage/files/{file_id}/versions", "file_id", fileId), "GET", void 0, options);
|
|
5635
|
+
},
|
|
5636
|
+
restoreVersion(fileId, versionId, options) {
|
|
5637
|
+
return callAthena2(
|
|
5638
|
+
withPathParam(
|
|
5639
|
+
withPathParam("/storage/files/{file_id}/versions/{version_id}/restore", "file_id", fileId),
|
|
5640
|
+
"version_id",
|
|
5641
|
+
versionId
|
|
5642
|
+
),
|
|
5643
|
+
"POST",
|
|
5644
|
+
{},
|
|
5645
|
+
options
|
|
5646
|
+
);
|
|
5647
|
+
},
|
|
5648
|
+
deleteVersion(fileId, versionId, options) {
|
|
5649
|
+
return callAthena2(
|
|
5650
|
+
withPathParam(
|
|
5651
|
+
withPathParam("/storage/files/{file_id}/versions/{version_id}", "file_id", fileId),
|
|
5652
|
+
"version_id",
|
|
5653
|
+
versionId
|
|
5654
|
+
),
|
|
5655
|
+
"DELETE",
|
|
5656
|
+
void 0,
|
|
5657
|
+
options
|
|
5658
|
+
);
|
|
5659
|
+
},
|
|
5660
|
+
retention: {
|
|
5661
|
+
get(fileId, query, options) {
|
|
5662
|
+
const path = appendQuery(
|
|
5663
|
+
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
5664
|
+
query
|
|
5665
|
+
);
|
|
5666
|
+
return callAthena2(path, "GET", void 0, options);
|
|
5667
|
+
},
|
|
4725
5668
|
set(fileId, input, options) {
|
|
5669
|
+
return callAthena2(withPathParam("/storage/files/{file_id}/retention", "file_id", fileId), "POST", input, options);
|
|
5670
|
+
}
|
|
5671
|
+
},
|
|
5672
|
+
visibility: {
|
|
5673
|
+
update(fileId, input, options) {
|
|
4726
5674
|
return base.setStorageFileVisibility(fileId, input, options);
|
|
4727
5675
|
},
|
|
5676
|
+
set(fileId, input, options) {
|
|
5677
|
+
return callStorageFileVisibility(fileId, "POST", input, options);
|
|
5678
|
+
},
|
|
4728
5679
|
setMany(input, options) {
|
|
4729
5680
|
return callAthena2("/storage/files/visibility-many", "POST", input, options);
|
|
4730
5681
|
}
|
|
@@ -4819,6 +5770,18 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4819
5770
|
uploadUrl(input, options) {
|
|
4820
5771
|
return callAthena2("/storage/objects/upload-url", "POST", input, options);
|
|
4821
5772
|
},
|
|
5773
|
+
versions(input, options) {
|
|
5774
|
+
return callAthena2("/storage/objects/versions", "POST", input, options);
|
|
5775
|
+
},
|
|
5776
|
+
restoreVersion(input, options) {
|
|
5777
|
+
return callAthena2("/storage/objects/versions/restore", "POST", input, options);
|
|
5778
|
+
},
|
|
5779
|
+
deleteVersion(input, options) {
|
|
5780
|
+
return callAthena2("/storage/objects/versions/delete", "POST", input, options);
|
|
5781
|
+
},
|
|
5782
|
+
postPolicy(input, options) {
|
|
5783
|
+
return callAthena2("/storage/objects/post-policy", "POST", input, options);
|
|
5784
|
+
},
|
|
4822
5785
|
folder: objectFolder
|
|
4823
5786
|
};
|
|
4824
5787
|
const bucket = {
|
|
@@ -4831,6 +5794,39 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4831
5794
|
delete(input, options) {
|
|
4832
5795
|
return callAthena2("/storage/buckets/delete", "POST", input, options);
|
|
4833
5796
|
},
|
|
5797
|
+
lifecycle: {
|
|
5798
|
+
get(input, options) {
|
|
5799
|
+
return callAthena2("/storage/buckets/lifecycle", "POST", input, options);
|
|
5800
|
+
},
|
|
5801
|
+
set(input, options) {
|
|
5802
|
+
return callAthena2("/storage/buckets/lifecycle/set", "POST", input, options);
|
|
5803
|
+
},
|
|
5804
|
+
delete(input, options) {
|
|
5805
|
+
return callAthena2("/storage/buckets/lifecycle/delete", "POST", input, options);
|
|
5806
|
+
}
|
|
5807
|
+
},
|
|
5808
|
+
policy: {
|
|
5809
|
+
get(input, options) {
|
|
5810
|
+
return callAthena2("/storage/buckets/policy", "POST", input, options);
|
|
5811
|
+
},
|
|
5812
|
+
set(input, options) {
|
|
5813
|
+
return callAthena2("/storage/buckets/policy/set", "POST", input, options);
|
|
5814
|
+
},
|
|
5815
|
+
delete(input, options) {
|
|
5816
|
+
return callAthena2("/storage/buckets/policy/delete", "POST", input, options);
|
|
5817
|
+
}
|
|
5818
|
+
},
|
|
5819
|
+
publicAccess: {
|
|
5820
|
+
get(input, options) {
|
|
5821
|
+
return callAthena2("/storage/buckets/public-access", "POST", input, options);
|
|
5822
|
+
},
|
|
5823
|
+
set(input, options) {
|
|
5824
|
+
return callAthena2("/storage/buckets/public-access/set", "POST", input, options);
|
|
5825
|
+
},
|
|
5826
|
+
delete(input, options) {
|
|
5827
|
+
return callAthena2("/storage/buckets/public-access/delete", "POST", input, options);
|
|
5828
|
+
}
|
|
5829
|
+
},
|
|
4834
5830
|
cors: {
|
|
4835
5831
|
get(input, options) {
|
|
4836
5832
|
return callAthena2("/storage/buckets/cors", "POST", input, options);
|
|
@@ -4880,6 +5876,13 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4880
5876
|
};
|
|
4881
5877
|
}
|
|
4882
5878
|
|
|
5879
|
+
// src/client-builder.ts
|
|
5880
|
+
var DEFAULT_BACKEND = { type: "athena" };
|
|
5881
|
+
function toBackendConfig(value) {
|
|
5882
|
+
if (!value) return DEFAULT_BACKEND;
|
|
5883
|
+
return typeof value === "string" ? { type: value } : value;
|
|
5884
|
+
}
|
|
5885
|
+
|
|
4883
5886
|
// src/query-ast.ts
|
|
4884
5887
|
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
4885
5888
|
var FILTER_OPERATORS = /* @__PURE__ */ new Set([
|
|
@@ -5502,20 +6505,437 @@ function createSelectTransportPlan(input) {
|
|
|
5502
6505
|
};
|
|
5503
6506
|
}
|
|
5504
6507
|
|
|
6508
|
+
// src/query-debug-ast.ts
|
|
6509
|
+
var ATHENA_DEBUG_AST_KEY = "__athenaDebugAst";
|
|
6510
|
+
function cloneConditions(conditions) {
|
|
6511
|
+
return conditions.map((condition) => ({ ...condition }));
|
|
6512
|
+
}
|
|
6513
|
+
function cloneTableBuilderStateAst(state) {
|
|
6514
|
+
return {
|
|
6515
|
+
conditions: cloneConditions(state.conditions),
|
|
6516
|
+
limit: state.limit,
|
|
6517
|
+
offset: state.offset,
|
|
6518
|
+
order: state.order ? { ...state.order } : void 0,
|
|
6519
|
+
currentPage: state.currentPage,
|
|
6520
|
+
pageSize: state.pageSize,
|
|
6521
|
+
totalPages: state.totalPages
|
|
6522
|
+
};
|
|
6523
|
+
}
|
|
6524
|
+
function cloneRpcBuilderStateAst(state) {
|
|
6525
|
+
return {
|
|
6526
|
+
filters: state.filters.map((filter) => ({ ...filter })),
|
|
6527
|
+
limit: state.limit,
|
|
6528
|
+
offset: state.offset,
|
|
6529
|
+
order: state.order ? { ...state.order } : void 0
|
|
6530
|
+
};
|
|
6531
|
+
}
|
|
6532
|
+
function toSelectTransportAst(plan) {
|
|
6533
|
+
if (plan.kind === "query") {
|
|
6534
|
+
return {
|
|
6535
|
+
mode: "typed-query",
|
|
6536
|
+
endpoint: "/gateway/query",
|
|
6537
|
+
payload: plan.payload
|
|
6538
|
+
};
|
|
6539
|
+
}
|
|
6540
|
+
return {
|
|
6541
|
+
mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
|
|
6542
|
+
endpoint: "/gateway/fetch",
|
|
6543
|
+
payload: plan.payload
|
|
6544
|
+
};
|
|
6545
|
+
}
|
|
6546
|
+
function resolveDebugTableName(tableName) {
|
|
6547
|
+
return tableName ?? "__unknown_table__";
|
|
6548
|
+
}
|
|
6549
|
+
function buildSelectDebugAst(input) {
|
|
6550
|
+
return {
|
|
6551
|
+
version: 1,
|
|
6552
|
+
kind: "select",
|
|
6553
|
+
tableName: input.tableName,
|
|
6554
|
+
input: {
|
|
6555
|
+
columns: input.columns,
|
|
6556
|
+
state: cloneTableBuilderStateAst(input.state)
|
|
6557
|
+
},
|
|
6558
|
+
transport: toSelectTransportAst(input.plan)
|
|
6559
|
+
};
|
|
6560
|
+
}
|
|
6561
|
+
function buildFindManyCompiledDebugAst(input) {
|
|
6562
|
+
return {
|
|
6563
|
+
version: 1,
|
|
6564
|
+
kind: "findMany",
|
|
6565
|
+
tableName: input.tableName,
|
|
6566
|
+
input: {
|
|
6567
|
+
select: input.options.select,
|
|
6568
|
+
where: input.options.where,
|
|
6569
|
+
orderBy: input.options.orderBy,
|
|
6570
|
+
limit: input.options.limit
|
|
6571
|
+
},
|
|
6572
|
+
compiled: {
|
|
6573
|
+
columns: input.compiledColumns,
|
|
6574
|
+
baseState: cloneTableBuilderStateAst(input.baseState),
|
|
6575
|
+
executionState: cloneTableBuilderStateAst(input.executionState)
|
|
6576
|
+
},
|
|
6577
|
+
transport: planToFindManyTransport(input.plan)
|
|
6578
|
+
};
|
|
6579
|
+
}
|
|
6580
|
+
function buildFindManyDirectDebugAst(input) {
|
|
6581
|
+
return {
|
|
6582
|
+
version: 1,
|
|
6583
|
+
kind: "findMany",
|
|
6584
|
+
tableName: input.tableName,
|
|
6585
|
+
input: {
|
|
6586
|
+
select: input.options.select,
|
|
6587
|
+
where: input.options.where,
|
|
6588
|
+
orderBy: input.options.orderBy,
|
|
6589
|
+
limit: input.options.limit
|
|
6590
|
+
},
|
|
6591
|
+
compiled: {
|
|
6592
|
+
columns: input.compiledColumns,
|
|
6593
|
+
baseState: cloneTableBuilderStateAst(input.baseState),
|
|
6594
|
+
executionState: cloneTableBuilderStateAst(input.executionState)
|
|
6595
|
+
},
|
|
6596
|
+
transport: {
|
|
6597
|
+
mode: "direct-ast-fetch",
|
|
6598
|
+
endpoint: "/gateway/fetch",
|
|
6599
|
+
payload: input.payload
|
|
6600
|
+
}
|
|
6601
|
+
};
|
|
6602
|
+
}
|
|
6603
|
+
function planToFindManyTransport(plan) {
|
|
6604
|
+
if (plan.kind === "query") {
|
|
6605
|
+
return {
|
|
6606
|
+
mode: "compiled-query",
|
|
6607
|
+
endpoint: "/gateway/query",
|
|
6608
|
+
payload: plan.payload
|
|
6609
|
+
};
|
|
6610
|
+
}
|
|
6611
|
+
return {
|
|
6612
|
+
mode: plan.payload.select !== void 0 ? "structured-fetch" : "compiled-fetch",
|
|
6613
|
+
endpoint: "/gateway/fetch",
|
|
6614
|
+
payload: plan.payload
|
|
6615
|
+
};
|
|
6616
|
+
}
|
|
6617
|
+
function buildInsertDebugAst(payload) {
|
|
6618
|
+
return {
|
|
6619
|
+
version: 1,
|
|
6620
|
+
kind: "insert",
|
|
6621
|
+
tableName: payload.table_name,
|
|
6622
|
+
input: {
|
|
6623
|
+
values: payload.insert_body,
|
|
6624
|
+
returning: payload.columns,
|
|
6625
|
+
count: payload.count,
|
|
6626
|
+
head: payload.head,
|
|
6627
|
+
defaultToNull: payload.default_to_null
|
|
6628
|
+
},
|
|
6629
|
+
transport: {
|
|
6630
|
+
mode: "insert",
|
|
6631
|
+
endpoint: "/gateway/insert",
|
|
6632
|
+
payload
|
|
6633
|
+
}
|
|
6634
|
+
};
|
|
6635
|
+
}
|
|
6636
|
+
function buildUpsertDebugAst(payload) {
|
|
6637
|
+
return {
|
|
6638
|
+
version: 1,
|
|
6639
|
+
kind: "upsert",
|
|
6640
|
+
tableName: payload.table_name,
|
|
6641
|
+
input: {
|
|
6642
|
+
values: payload.insert_body,
|
|
6643
|
+
updateBody: payload.update_body,
|
|
6644
|
+
onConflict: payload.on_conflict,
|
|
6645
|
+
returning: payload.columns,
|
|
6646
|
+
count: payload.count,
|
|
6647
|
+
head: payload.head,
|
|
6648
|
+
defaultToNull: payload.default_to_null
|
|
6649
|
+
},
|
|
6650
|
+
transport: {
|
|
6651
|
+
mode: "upsert",
|
|
6652
|
+
endpoint: "/gateway/insert",
|
|
6653
|
+
payload
|
|
6654
|
+
}
|
|
6655
|
+
};
|
|
6656
|
+
}
|
|
6657
|
+
function buildUpdateDebugAst(input) {
|
|
6658
|
+
return {
|
|
6659
|
+
version: 1,
|
|
6660
|
+
kind: "update",
|
|
6661
|
+
tableName: resolveDebugTableName(input.payload.table_name),
|
|
6662
|
+
input: {
|
|
6663
|
+
values: input.payload.set,
|
|
6664
|
+
state: cloneTableBuilderStateAst(input.state),
|
|
6665
|
+
returning: input.payload.columns
|
|
6666
|
+
},
|
|
6667
|
+
transport: {
|
|
6668
|
+
mode: "update",
|
|
6669
|
+
endpoint: "/gateway/update",
|
|
6670
|
+
payload: input.payload
|
|
6671
|
+
}
|
|
6672
|
+
};
|
|
6673
|
+
}
|
|
6674
|
+
function buildDeleteDebugAst(input) {
|
|
6675
|
+
return {
|
|
6676
|
+
version: 1,
|
|
6677
|
+
kind: "delete",
|
|
6678
|
+
tableName: input.payload.table_name,
|
|
6679
|
+
input: {
|
|
6680
|
+
resourceId: input.payload.resource_id,
|
|
6681
|
+
state: cloneTableBuilderStateAst(input.state),
|
|
6682
|
+
returning: input.payload.columns
|
|
6683
|
+
},
|
|
6684
|
+
transport: {
|
|
6685
|
+
mode: "delete",
|
|
6686
|
+
endpoint: "/gateway/delete",
|
|
6687
|
+
payload: input.payload
|
|
6688
|
+
}
|
|
6689
|
+
};
|
|
6690
|
+
}
|
|
6691
|
+
function buildRpcDebugAst(input) {
|
|
6692
|
+
return {
|
|
6693
|
+
version: 1,
|
|
6694
|
+
kind: "rpc",
|
|
6695
|
+
functionName: input.functionName,
|
|
6696
|
+
input: {
|
|
6697
|
+
args: input.args,
|
|
6698
|
+
select: input.selectedColumns,
|
|
6699
|
+
state: cloneRpcBuilderStateAst(input.state)
|
|
6700
|
+
},
|
|
6701
|
+
transport: {
|
|
6702
|
+
mode: input.endpoint === "/gateway/rpc" ? "rpc-post" : "rpc-get",
|
|
6703
|
+
endpoint: input.endpoint,
|
|
6704
|
+
payload: input.payload
|
|
6705
|
+
}
|
|
6706
|
+
};
|
|
6707
|
+
}
|
|
6708
|
+
function buildRawQueryDebugAst(query) {
|
|
6709
|
+
return {
|
|
6710
|
+
version: 1,
|
|
6711
|
+
kind: "query",
|
|
6712
|
+
input: {
|
|
6713
|
+
query
|
|
6714
|
+
},
|
|
6715
|
+
transport: {
|
|
6716
|
+
mode: "raw-query",
|
|
6717
|
+
endpoint: "/gateway/query",
|
|
6718
|
+
payload: {
|
|
6719
|
+
query
|
|
6720
|
+
}
|
|
6721
|
+
}
|
|
6722
|
+
};
|
|
6723
|
+
}
|
|
6724
|
+
function attachAthenaDebugAst(target, ast) {
|
|
6725
|
+
if (!ast) {
|
|
6726
|
+
return;
|
|
6727
|
+
}
|
|
6728
|
+
if (!target || typeof target !== "object" && typeof target !== "function") {
|
|
6729
|
+
return;
|
|
6730
|
+
}
|
|
6731
|
+
Object.defineProperty(target, ATHENA_DEBUG_AST_KEY, {
|
|
6732
|
+
value: ast,
|
|
6733
|
+
enumerable: false,
|
|
6734
|
+
configurable: true,
|
|
6735
|
+
writable: false
|
|
6736
|
+
});
|
|
6737
|
+
}
|
|
6738
|
+
|
|
6739
|
+
// src/query-tracing.ts
|
|
6740
|
+
var QUERY_TRACE_STACK_SKIP_PATTERNS = [
|
|
6741
|
+
"src\\client.ts",
|
|
6742
|
+
"src/client.ts",
|
|
6743
|
+
"src\\query-tracing.ts",
|
|
6744
|
+
"src/query-tracing.ts",
|
|
6745
|
+
"dist\\client.",
|
|
6746
|
+
"dist/client.",
|
|
6747
|
+
"dist\\query-tracing.",
|
|
6748
|
+
"dist/query-tracing.",
|
|
6749
|
+
"node_modules\\@xylex-group\\athena",
|
|
6750
|
+
"node_modules/@xylex-group/athena",
|
|
6751
|
+
"node:internal",
|
|
6752
|
+
"internal/process"
|
|
6753
|
+
];
|
|
6754
|
+
function parseQueryTraceCallsiteFrame(frame) {
|
|
6755
|
+
const trimmed = frame.trim();
|
|
6756
|
+
if (!trimmed) {
|
|
6757
|
+
return null;
|
|
6758
|
+
}
|
|
6759
|
+
let body = trimmed.replace(/^at\s+/, "");
|
|
6760
|
+
if (body.startsWith("async ")) {
|
|
6761
|
+
body = body.slice(6);
|
|
6762
|
+
}
|
|
6763
|
+
let functionName;
|
|
6764
|
+
let location = body;
|
|
6765
|
+
const wrappedMatch = body.match(/^(.*?)\s+\((.*)\)$/);
|
|
6766
|
+
if (wrappedMatch) {
|
|
6767
|
+
functionName = wrappedMatch[1].trim() || void 0;
|
|
6768
|
+
location = wrappedMatch[2].trim();
|
|
6769
|
+
}
|
|
6770
|
+
const locationMatch = location.match(/^(.*):(\d+):(\d+)$/);
|
|
6771
|
+
if (!locationMatch) {
|
|
6772
|
+
return null;
|
|
6773
|
+
}
|
|
6774
|
+
const filePath = locationMatch[1].replace(/^file:\/\//, "");
|
|
6775
|
+
const line = Number(locationMatch[2]);
|
|
6776
|
+
const column = Number(locationMatch[3]);
|
|
6777
|
+
if (!Number.isFinite(line) || !Number.isFinite(column)) {
|
|
6778
|
+
return null;
|
|
6779
|
+
}
|
|
6780
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
6781
|
+
const fileName = normalizedPath.split("/").at(-1) ?? filePath;
|
|
6782
|
+
return {
|
|
6783
|
+
filePath,
|
|
6784
|
+
fileName,
|
|
6785
|
+
line,
|
|
6786
|
+
column,
|
|
6787
|
+
frame: trimmed,
|
|
6788
|
+
functionName
|
|
6789
|
+
};
|
|
6790
|
+
}
|
|
6791
|
+
function captureQueryTraceCallsite() {
|
|
6792
|
+
const stack = new Error().stack;
|
|
6793
|
+
if (!stack) return null;
|
|
6794
|
+
const frames = stack.split("\n").slice(2).map((frame) => frame.trim()).filter(Boolean);
|
|
6795
|
+
for (const frame of frames) {
|
|
6796
|
+
if (QUERY_TRACE_STACK_SKIP_PATTERNS.some((pattern) => frame.includes(pattern))) {
|
|
6797
|
+
continue;
|
|
6798
|
+
}
|
|
6799
|
+
const callsite = parseQueryTraceCallsiteFrame(frame);
|
|
6800
|
+
if (callsite) return callsite;
|
|
6801
|
+
}
|
|
6802
|
+
const fallback = frames.find((frame) => !frame.includes("captureQueryTraceCallsite"));
|
|
6803
|
+
return fallback ? parseQueryTraceCallsiteFrame(fallback) : null;
|
|
6804
|
+
}
|
|
6805
|
+
function defaultQueryTraceLogger(event) {
|
|
6806
|
+
const target = event.table ?? event.functionName ?? "gateway";
|
|
6807
|
+
const outcomeState = event.outcome?.error ? "error" : "ok";
|
|
6808
|
+
const banner = `[athena-js][trace] ${event.operation.toUpperCase()} ${event.endpoint} ${target} ${event.durationMs}ms ${outcomeState}`;
|
|
6809
|
+
console.info(banner, event);
|
|
6810
|
+
}
|
|
6811
|
+
function captureTraceCallsite(tracer) {
|
|
6812
|
+
return tracer?.captureCallsite() ?? null;
|
|
6813
|
+
}
|
|
6814
|
+
function createTraceCallsiteStore(tracer, initialCallsite) {
|
|
6815
|
+
let storedCallsite = initialCallsite ?? void 0;
|
|
6816
|
+
return {
|
|
6817
|
+
resolve(callsite) {
|
|
6818
|
+
if (callsite) {
|
|
6819
|
+
storedCallsite = callsite;
|
|
6820
|
+
return callsite;
|
|
6821
|
+
}
|
|
6822
|
+
if (storedCallsite !== void 0) {
|
|
6823
|
+
return storedCallsite;
|
|
6824
|
+
}
|
|
6825
|
+
const capturedCallsite = captureTraceCallsite(tracer);
|
|
6826
|
+
if (capturedCallsite) {
|
|
6827
|
+
storedCallsite = capturedCallsite;
|
|
6828
|
+
}
|
|
6829
|
+
return capturedCallsite;
|
|
6830
|
+
}
|
|
6831
|
+
};
|
|
6832
|
+
}
|
|
6833
|
+
function createQueryTracer(experimental) {
|
|
6834
|
+
const traceOption = experimental?.traceQueries;
|
|
6835
|
+
if (!traceOption) {
|
|
6836
|
+
return void 0;
|
|
6837
|
+
}
|
|
6838
|
+
const logger = typeof traceOption === "object" && traceOption.logger ? traceOption.logger : defaultQueryTraceLogger;
|
|
6839
|
+
const emit = (event) => {
|
|
6840
|
+
try {
|
|
6841
|
+
logger(event);
|
|
6842
|
+
} catch (error) {
|
|
6843
|
+
console.warn("[athena-js][trace] logger failed", error);
|
|
6844
|
+
}
|
|
6845
|
+
};
|
|
6846
|
+
return {
|
|
6847
|
+
captureCallsite: captureQueryTraceCallsite,
|
|
6848
|
+
publishSuccess(context, result, durationMs, callsite) {
|
|
6849
|
+
emit({
|
|
6850
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6851
|
+
durationMs,
|
|
6852
|
+
operation: context.operation,
|
|
6853
|
+
endpoint: context.endpoint,
|
|
6854
|
+
table: context.table,
|
|
6855
|
+
functionName: context.functionName,
|
|
6856
|
+
sql: context.sql,
|
|
6857
|
+
payload: context.payload,
|
|
6858
|
+
ast: context.ast,
|
|
6859
|
+
options: context.options,
|
|
6860
|
+
callsite,
|
|
6861
|
+
outcome: {
|
|
6862
|
+
status: result.status,
|
|
6863
|
+
error: result.error,
|
|
6864
|
+
errorDetails: result.errorDetails ?? null,
|
|
6865
|
+
count: result.count ?? null,
|
|
6866
|
+
data: result.data,
|
|
6867
|
+
raw: result.raw
|
|
6868
|
+
}
|
|
6869
|
+
});
|
|
6870
|
+
},
|
|
6871
|
+
publishFailure(context, error, durationMs, callsite) {
|
|
6872
|
+
emit({
|
|
6873
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6874
|
+
durationMs,
|
|
6875
|
+
operation: context.operation,
|
|
6876
|
+
endpoint: context.endpoint,
|
|
6877
|
+
table: context.table,
|
|
6878
|
+
functionName: context.functionName,
|
|
6879
|
+
sql: context.sql,
|
|
6880
|
+
payload: context.payload,
|
|
6881
|
+
ast: context.ast,
|
|
6882
|
+
options: context.options,
|
|
6883
|
+
callsite,
|
|
6884
|
+
thrownError: error
|
|
6885
|
+
});
|
|
6886
|
+
}
|
|
6887
|
+
};
|
|
6888
|
+
}
|
|
6889
|
+
async function executeWithQueryTrace(tracer, context, runner, callsiteOverride) {
|
|
6890
|
+
const callsite = tracer ? callsiteOverride ?? tracer.captureCallsite() : null;
|
|
6891
|
+
const startedAt = tracer ? Date.now() : 0;
|
|
6892
|
+
try {
|
|
6893
|
+
const result = await runner();
|
|
6894
|
+
attachAthenaDebugAst(result, context.ast);
|
|
6895
|
+
if (tracer) {
|
|
6896
|
+
tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
|
|
6897
|
+
}
|
|
6898
|
+
return result;
|
|
6899
|
+
} catch (error) {
|
|
6900
|
+
attachAthenaDebugAst(error, context.ast);
|
|
6901
|
+
if (tracer) {
|
|
6902
|
+
tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
|
|
6903
|
+
}
|
|
6904
|
+
throw error;
|
|
6905
|
+
}
|
|
6906
|
+
}
|
|
6907
|
+
|
|
6908
|
+
// src/schema/model-target.ts
|
|
6909
|
+
function normalizeOptionalName(value) {
|
|
6910
|
+
const normalized = value?.trim();
|
|
6911
|
+
return normalized ? normalized : void 0;
|
|
6912
|
+
}
|
|
6913
|
+
function isAthenaModelTarget(value) {
|
|
6914
|
+
if (!value || typeof value !== "object") {
|
|
6915
|
+
return false;
|
|
6916
|
+
}
|
|
6917
|
+
const candidate = value;
|
|
6918
|
+
return Boolean(candidate.meta && Array.isArray(candidate.meta.primaryKey));
|
|
6919
|
+
}
|
|
6920
|
+
function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
6921
|
+
const explicitTableName = normalizeOptionalName(target.meta.tableName);
|
|
6922
|
+
if (explicitTableName) {
|
|
6923
|
+
return explicitTableName;
|
|
6924
|
+
}
|
|
6925
|
+
const schemaName = normalizeOptionalName(target.meta.schema ?? options.fallbackSchema);
|
|
6926
|
+
const modelName = normalizeOptionalName(target.meta.model ?? options.fallbackModel);
|
|
6927
|
+
if (!modelName) {
|
|
6928
|
+
throw new Error(
|
|
6929
|
+
"Athena model target is missing meta.model or meta.tableName. Provide one of those before calling from(model)."
|
|
6930
|
+
);
|
|
6931
|
+
}
|
|
6932
|
+
return schemaName ? `${schemaName}.${modelName}` : modelName;
|
|
6933
|
+
}
|
|
6934
|
+
|
|
5505
6935
|
// src/client.ts
|
|
5506
6936
|
var DEFAULT_COLUMNS = "*";
|
|
5507
6937
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
5508
6938
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
5509
|
-
var QUERY_TRACE_STACK_SKIP_PATTERNS = [
|
|
5510
|
-
"src\\client.ts",
|
|
5511
|
-
"src/client.ts",
|
|
5512
|
-
"dist\\client.",
|
|
5513
|
-
"dist/client.",
|
|
5514
|
-
"node_modules\\@xylex-group\\athena",
|
|
5515
|
-
"node_modules/@xylex-group/athena",
|
|
5516
|
-
"node:internal",
|
|
5517
|
-
"internal/process"
|
|
5518
|
-
];
|
|
5519
6939
|
function formatResult(response) {
|
|
5520
6940
|
const result = {
|
|
5521
6941
|
data: response.data ?? null,
|
|
@@ -5657,154 +7077,6 @@ function createResultError(response, result, normalized) {
|
|
|
5657
7077
|
raw: result.raw
|
|
5658
7078
|
};
|
|
5659
7079
|
}
|
|
5660
|
-
function parseQueryTraceCallsiteFrame(frame) {
|
|
5661
|
-
const trimmed = frame.trim();
|
|
5662
|
-
if (!trimmed) {
|
|
5663
|
-
return null;
|
|
5664
|
-
}
|
|
5665
|
-
let body = trimmed.replace(/^at\s+/, "");
|
|
5666
|
-
if (body.startsWith("async ")) {
|
|
5667
|
-
body = body.slice(6);
|
|
5668
|
-
}
|
|
5669
|
-
let functionName;
|
|
5670
|
-
let location = body;
|
|
5671
|
-
const wrappedMatch = body.match(/^(.*?)\s+\((.*)\)$/);
|
|
5672
|
-
if (wrappedMatch) {
|
|
5673
|
-
functionName = wrappedMatch[1].trim() || void 0;
|
|
5674
|
-
location = wrappedMatch[2].trim();
|
|
5675
|
-
}
|
|
5676
|
-
const locationMatch = location.match(/^(.*):(\d+):(\d+)$/);
|
|
5677
|
-
if (!locationMatch) {
|
|
5678
|
-
return null;
|
|
5679
|
-
}
|
|
5680
|
-
const filePath = locationMatch[1].replace(/^file:\/\//, "");
|
|
5681
|
-
const line = Number(locationMatch[2]);
|
|
5682
|
-
const column = Number(locationMatch[3]);
|
|
5683
|
-
if (!Number.isFinite(line) || !Number.isFinite(column)) {
|
|
5684
|
-
return null;
|
|
5685
|
-
}
|
|
5686
|
-
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
5687
|
-
const fileName = normalizedPath.split("/").at(-1) ?? filePath;
|
|
5688
|
-
return {
|
|
5689
|
-
filePath,
|
|
5690
|
-
fileName,
|
|
5691
|
-
line,
|
|
5692
|
-
column,
|
|
5693
|
-
frame: trimmed,
|
|
5694
|
-
functionName
|
|
5695
|
-
};
|
|
5696
|
-
}
|
|
5697
|
-
function captureQueryTraceCallsite() {
|
|
5698
|
-
const stack = new Error().stack;
|
|
5699
|
-
if (!stack) return null;
|
|
5700
|
-
const frames = stack.split("\n").slice(2).map((frame) => frame.trim()).filter(Boolean);
|
|
5701
|
-
for (const frame of frames) {
|
|
5702
|
-
if (QUERY_TRACE_STACK_SKIP_PATTERNS.some((pattern) => frame.includes(pattern))) {
|
|
5703
|
-
continue;
|
|
5704
|
-
}
|
|
5705
|
-
const callsite = parseQueryTraceCallsiteFrame(frame);
|
|
5706
|
-
if (callsite) return callsite;
|
|
5707
|
-
}
|
|
5708
|
-
const fallback = frames.find((frame) => !frame.includes("captureQueryTraceCallsite"));
|
|
5709
|
-
return fallback ? parseQueryTraceCallsiteFrame(fallback) : null;
|
|
5710
|
-
}
|
|
5711
|
-
function defaultQueryTraceLogger(event) {
|
|
5712
|
-
const target = event.table ?? event.functionName ?? "gateway";
|
|
5713
|
-
const outcomeState = event.outcome?.error ? "error" : "ok";
|
|
5714
|
-
const banner = `[athena-js][trace] ${event.operation.toUpperCase()} ${event.endpoint} ${target} ${event.durationMs}ms ${outcomeState}`;
|
|
5715
|
-
console.info(banner, event);
|
|
5716
|
-
}
|
|
5717
|
-
function captureTraceCallsite(tracer) {
|
|
5718
|
-
return tracer?.captureCallsite() ?? null;
|
|
5719
|
-
}
|
|
5720
|
-
function createTraceCallsiteStore(tracer, initialCallsite) {
|
|
5721
|
-
let storedCallsite = initialCallsite ?? void 0;
|
|
5722
|
-
return {
|
|
5723
|
-
resolve(callsite) {
|
|
5724
|
-
if (callsite) {
|
|
5725
|
-
storedCallsite = callsite;
|
|
5726
|
-
return callsite;
|
|
5727
|
-
}
|
|
5728
|
-
if (storedCallsite !== void 0) {
|
|
5729
|
-
return storedCallsite;
|
|
5730
|
-
}
|
|
5731
|
-
const capturedCallsite = captureTraceCallsite(tracer);
|
|
5732
|
-
if (capturedCallsite) {
|
|
5733
|
-
storedCallsite = capturedCallsite;
|
|
5734
|
-
}
|
|
5735
|
-
return capturedCallsite;
|
|
5736
|
-
}
|
|
5737
|
-
};
|
|
5738
|
-
}
|
|
5739
|
-
function createQueryTracer(experimental) {
|
|
5740
|
-
const traceOption = experimental?.traceQueries;
|
|
5741
|
-
if (!traceOption) {
|
|
5742
|
-
return void 0;
|
|
5743
|
-
}
|
|
5744
|
-
const logger = typeof traceOption === "object" && traceOption.logger ? traceOption.logger : defaultQueryTraceLogger;
|
|
5745
|
-
const emit = (event) => {
|
|
5746
|
-
try {
|
|
5747
|
-
logger(event);
|
|
5748
|
-
} catch (error) {
|
|
5749
|
-
console.warn("[athena-js][trace] logger failed", error);
|
|
5750
|
-
}
|
|
5751
|
-
};
|
|
5752
|
-
return {
|
|
5753
|
-
captureCallsite: captureQueryTraceCallsite,
|
|
5754
|
-
publishSuccess(context, result, durationMs, callsite) {
|
|
5755
|
-
emit({
|
|
5756
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5757
|
-
durationMs,
|
|
5758
|
-
operation: context.operation,
|
|
5759
|
-
endpoint: context.endpoint,
|
|
5760
|
-
table: context.table,
|
|
5761
|
-
functionName: context.functionName,
|
|
5762
|
-
sql: context.sql,
|
|
5763
|
-
payload: context.payload,
|
|
5764
|
-
options: context.options,
|
|
5765
|
-
callsite,
|
|
5766
|
-
outcome: {
|
|
5767
|
-
status: result.status,
|
|
5768
|
-
error: result.error,
|
|
5769
|
-
errorDetails: result.errorDetails ?? null,
|
|
5770
|
-
count: result.count ?? null,
|
|
5771
|
-
data: result.data,
|
|
5772
|
-
raw: result.raw
|
|
5773
|
-
}
|
|
5774
|
-
});
|
|
5775
|
-
},
|
|
5776
|
-
publishFailure(context, error, durationMs, callsite) {
|
|
5777
|
-
emit({
|
|
5778
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5779
|
-
durationMs,
|
|
5780
|
-
operation: context.operation,
|
|
5781
|
-
endpoint: context.endpoint,
|
|
5782
|
-
table: context.table,
|
|
5783
|
-
functionName: context.functionName,
|
|
5784
|
-
sql: context.sql,
|
|
5785
|
-
payload: context.payload,
|
|
5786
|
-
options: context.options,
|
|
5787
|
-
callsite,
|
|
5788
|
-
thrownError: error
|
|
5789
|
-
});
|
|
5790
|
-
}
|
|
5791
|
-
};
|
|
5792
|
-
}
|
|
5793
|
-
async function executeWithQueryTrace(tracer, context, runner, callsiteOverride) {
|
|
5794
|
-
if (!tracer) {
|
|
5795
|
-
return runner();
|
|
5796
|
-
}
|
|
5797
|
-
const callsite = callsiteOverride ?? tracer.captureCallsite();
|
|
5798
|
-
const startedAt = Date.now();
|
|
5799
|
-
try {
|
|
5800
|
-
const result = await runner();
|
|
5801
|
-
tracer.publishSuccess(context, result, Date.now() - startedAt, callsite);
|
|
5802
|
-
return result;
|
|
5803
|
-
} catch (error) {
|
|
5804
|
-
tracer.publishFailure(context, error, Date.now() - startedAt, callsite);
|
|
5805
|
-
throw error;
|
|
5806
|
-
}
|
|
5807
|
-
}
|
|
5808
7080
|
function toSingleResult(response) {
|
|
5809
7081
|
const payload = response.data;
|
|
5810
7082
|
const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
|
|
@@ -5832,6 +7104,15 @@ function asAthenaJsonObject(value) {
|
|
|
5832
7104
|
function asAthenaJsonObjectArray(values) {
|
|
5833
7105
|
return values;
|
|
5834
7106
|
}
|
|
7107
|
+
function normalizeSelectColumnsInput(columns) {
|
|
7108
|
+
if (columns === void 0) {
|
|
7109
|
+
return void 0;
|
|
7110
|
+
}
|
|
7111
|
+
if (typeof columns === "string") {
|
|
7112
|
+
return columns;
|
|
7113
|
+
}
|
|
7114
|
+
return [...columns];
|
|
7115
|
+
}
|
|
5835
7116
|
function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer, initialCallsite) {
|
|
5836
7117
|
let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
|
|
5837
7118
|
let selectedOptions;
|
|
@@ -5841,25 +7122,29 @@ function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS, tracer,
|
|
|
5841
7122
|
const payloadColumns = columns ?? selectedColumns;
|
|
5842
7123
|
const payloadOptions = options ?? selectedOptions;
|
|
5843
7124
|
if (!promise) {
|
|
5844
|
-
promise = executor(
|
|
7125
|
+
promise = executor(
|
|
7126
|
+
normalizeSelectColumnsInput(payloadColumns),
|
|
7127
|
+
payloadOptions,
|
|
7128
|
+
callsiteStore.resolve(callsite)
|
|
7129
|
+
);
|
|
5845
7130
|
}
|
|
5846
7131
|
return promise;
|
|
5847
7132
|
};
|
|
5848
7133
|
const mutationQuery = {
|
|
5849
|
-
select(columns
|
|
7134
|
+
select(columns, options) {
|
|
5850
7135
|
selectedColumns = columns;
|
|
5851
7136
|
selectedOptions = options ?? selectedOptions;
|
|
5852
7137
|
return run(columns, options, captureTraceCallsite(tracer));
|
|
5853
7138
|
},
|
|
5854
|
-
returning(columns
|
|
7139
|
+
returning(columns, options) {
|
|
5855
7140
|
return mutationQuery.select(columns, options);
|
|
5856
7141
|
},
|
|
5857
|
-
single(columns
|
|
7142
|
+
single(columns, options) {
|
|
5858
7143
|
selectedColumns = columns;
|
|
5859
7144
|
selectedOptions = options ?? selectedOptions;
|
|
5860
7145
|
return run(columns, options, captureTraceCallsite(tracer)).then(toSingleResult);
|
|
5861
7146
|
},
|
|
5862
|
-
maybeSingle(columns
|
|
7147
|
+
maybeSingle(columns, options) {
|
|
5863
7148
|
return mutationQuery.single(columns, options);
|
|
5864
7149
|
},
|
|
5865
7150
|
then(onfulfilled, onrejected) {
|
|
@@ -6416,7 +7701,10 @@ function createFilterMethods(state, addCondition, self) {
|
|
|
6416
7701
|
}
|
|
6417
7702
|
function toRpcSelect(columns) {
|
|
6418
7703
|
if (!columns) return void 0;
|
|
6419
|
-
|
|
7704
|
+
if (typeof columns === "string") {
|
|
7705
|
+
return columns;
|
|
7706
|
+
}
|
|
7707
|
+
return columns.join(",");
|
|
6420
7708
|
}
|
|
6421
7709
|
function createRpcFilterMethods(filters, self) {
|
|
6422
7710
|
const addFilter = (operator, column, value) => {
|
|
@@ -6465,7 +7753,7 @@ function createRpcFilterMethods(filters, self) {
|
|
|
6465
7753
|
}
|
|
6466
7754
|
};
|
|
6467
7755
|
}
|
|
6468
|
-
function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite) {
|
|
7756
|
+
function createRpcBuilder(functionName, args, baseOptions, client, formatGatewayResult, tracer, initialCallsite, debugAstEnabled = false) {
|
|
6469
7757
|
const state = {
|
|
6470
7758
|
filters: []
|
|
6471
7759
|
};
|
|
@@ -6475,6 +7763,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6475
7763
|
const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
|
|
6476
7764
|
const executeRpc = async (columns, options, callsite) => {
|
|
6477
7765
|
const mergedOptions = mergeOptions(baseOptions, options);
|
|
7766
|
+
const normalizedSelectedColumns = normalizeSelectColumnsInput(columns);
|
|
6478
7767
|
const payload = {
|
|
6479
7768
|
function: functionName,
|
|
6480
7769
|
args,
|
|
@@ -6489,6 +7778,14 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6489
7778
|
};
|
|
6490
7779
|
const endpoint = mergedOptions?.get ? `/rpc/${functionName}` : "/gateway/rpc";
|
|
6491
7780
|
const sql = buildRpcDebugSql(payload);
|
|
7781
|
+
const debugAst = debugAstEnabled ? buildRpcDebugAst({
|
|
7782
|
+
functionName,
|
|
7783
|
+
args,
|
|
7784
|
+
selectedColumns: normalizedSelectedColumns,
|
|
7785
|
+
state,
|
|
7786
|
+
payload,
|
|
7787
|
+
endpoint
|
|
7788
|
+
}) : void 0;
|
|
6492
7789
|
return executeWithQueryTrace(
|
|
6493
7790
|
tracer,
|
|
6494
7791
|
{
|
|
@@ -6497,6 +7794,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6497
7794
|
functionName,
|
|
6498
7795
|
sql,
|
|
6499
7796
|
payload,
|
|
7797
|
+
ast: debugAst,
|
|
6500
7798
|
options: mergedOptions
|
|
6501
7799
|
},
|
|
6502
7800
|
async () => {
|
|
@@ -6517,7 +7815,7 @@ function createRpcBuilder(functionName, args, baseOptions, client, formatGateway
|
|
|
6517
7815
|
const builder = {};
|
|
6518
7816
|
const filterMethods = createRpcFilterMethods(state.filters, builder);
|
|
6519
7817
|
Object.assign(builder, filterMethods, {
|
|
6520
|
-
select(columns
|
|
7818
|
+
select(columns, options) {
|
|
6521
7819
|
selectedColumns = columns;
|
|
6522
7820
|
selectedOptions = options ?? selectedOptions;
|
|
6523
7821
|
return run(columns, options, captureTraceCallsite(tracer));
|
|
@@ -6562,6 +7860,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6562
7860
|
const state = {
|
|
6563
7861
|
conditions: []
|
|
6564
7862
|
};
|
|
7863
|
+
const debugAstEnabled = Boolean(experimental?.debugAst);
|
|
6565
7864
|
const addCondition = (operator, column, value, hints) => {
|
|
6566
7865
|
const condition = { operator };
|
|
6567
7866
|
if (column) {
|
|
@@ -6605,15 +7904,27 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6605
7904
|
addCondition,
|
|
6606
7905
|
builder
|
|
6607
7906
|
);
|
|
6608
|
-
const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite) => {
|
|
7907
|
+
const runSelect = async (columns = DEFAULT_COLUMNS, options, executionState = snapshotState(), callsite, debugAstFactory) => {
|
|
7908
|
+
const runtimeColumns = normalizeSelectColumnsInput(columns) ?? DEFAULT_COLUMNS;
|
|
6609
7909
|
const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
|
|
6610
7910
|
const plan = createSelectTransportPlan({
|
|
6611
7911
|
tableName: resolvedTableName,
|
|
6612
|
-
columns,
|
|
7912
|
+
columns: runtimeColumns,
|
|
6613
7913
|
state: executionState,
|
|
6614
7914
|
options,
|
|
6615
7915
|
buildTypedSelectQuery
|
|
6616
7916
|
});
|
|
7917
|
+
const debugAst = debugAstEnabled ? debugAstFactory?.({
|
|
7918
|
+
tableName: resolvedTableName,
|
|
7919
|
+
columns: runtimeColumns,
|
|
7920
|
+
executionState,
|
|
7921
|
+
plan
|
|
7922
|
+
}) ?? buildSelectDebugAst({
|
|
7923
|
+
tableName: resolvedTableName,
|
|
7924
|
+
columns: runtimeColumns,
|
|
7925
|
+
state: executionState,
|
|
7926
|
+
plan
|
|
7927
|
+
}) : void 0;
|
|
6617
7928
|
if (plan.kind === "query") {
|
|
6618
7929
|
return executeExperimentalRead(
|
|
6619
7930
|
experimental,
|
|
@@ -6625,6 +7936,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6625
7936
|
table: resolvedTableName,
|
|
6626
7937
|
sql: plan.query,
|
|
6627
7938
|
payload: plan.payload,
|
|
7939
|
+
ast: debugAst,
|
|
6628
7940
|
options
|
|
6629
7941
|
},
|
|
6630
7942
|
async () => {
|
|
@@ -6649,6 +7961,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6649
7961
|
table: resolvedTableName,
|
|
6650
7962
|
sql,
|
|
6651
7963
|
payload: plan.payload,
|
|
7964
|
+
ast: debugAst,
|
|
6652
7965
|
options
|
|
6653
7966
|
},
|
|
6654
7967
|
async () => {
|
|
@@ -6662,7 +7975,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6662
7975
|
const createSelectChain = (columns, options, initialCallsite) => {
|
|
6663
7976
|
const chain = {};
|
|
6664
7977
|
const callsiteStore = createTraceCallsiteStore(tracer, initialCallsite);
|
|
6665
|
-
const filterMethods2 = createFilterMethods(
|
|
7978
|
+
const filterMethods2 = createFilterMethods(
|
|
7979
|
+
state,
|
|
7980
|
+
addCondition,
|
|
7981
|
+
chain
|
|
7982
|
+
);
|
|
6666
7983
|
Object.assign(chain, filterMethods2, {
|
|
6667
7984
|
async single(cols, opts) {
|
|
6668
7985
|
const r = await runSelect(
|
|
@@ -6749,6 +8066,14 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6749
8066
|
limit: executionState.limit,
|
|
6750
8067
|
order: executionState.order
|
|
6751
8068
|
});
|
|
8069
|
+
const debugAst = debugAstEnabled ? buildFindManyDirectDebugAst({
|
|
8070
|
+
tableName: resolvedTableName,
|
|
8071
|
+
options,
|
|
8072
|
+
compiledColumns: columns,
|
|
8073
|
+
baseState,
|
|
8074
|
+
executionState,
|
|
8075
|
+
payload
|
|
8076
|
+
}) : void 0;
|
|
6752
8077
|
return executeExperimentalRead(
|
|
6753
8078
|
experimental,
|
|
6754
8079
|
() => executeWithQueryTrace(
|
|
@@ -6758,7 +8083,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6758
8083
|
endpoint: "/gateway/fetch",
|
|
6759
8084
|
table: resolvedTableName,
|
|
6760
8085
|
sql,
|
|
6761
|
-
payload
|
|
8086
|
+
payload,
|
|
8087
|
+
ast: debugAst
|
|
6762
8088
|
},
|
|
6763
8089
|
async () => {
|
|
6764
8090
|
const response = await client.fetchGateway(
|
|
@@ -6774,7 +8100,15 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6774
8100
|
columns,
|
|
6775
8101
|
void 0,
|
|
6776
8102
|
executionState,
|
|
6777
|
-
callsite
|
|
8103
|
+
callsite,
|
|
8104
|
+
debugAstEnabled ? ({ tableName: resolvedTableName, executionState: tracedState, plan }) => buildFindManyCompiledDebugAst({
|
|
8105
|
+
tableName: resolvedTableName,
|
|
8106
|
+
options,
|
|
8107
|
+
compiledColumns: columns,
|
|
8108
|
+
baseState,
|
|
8109
|
+
executionState: tracedState,
|
|
8110
|
+
plan
|
|
8111
|
+
}) : void 0
|
|
6778
8112
|
);
|
|
6779
8113
|
},
|
|
6780
8114
|
insert(values, options) {
|
|
@@ -6794,6 +8128,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6794
8128
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6795
8129
|
}
|
|
6796
8130
|
const sql = buildInsertDebugSql(payload);
|
|
8131
|
+
const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
|
|
6797
8132
|
return executeWithQueryTrace(
|
|
6798
8133
|
tracer,
|
|
6799
8134
|
{
|
|
@@ -6802,6 +8137,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6802
8137
|
table: resolvedTableName,
|
|
6803
8138
|
sql,
|
|
6804
8139
|
payload,
|
|
8140
|
+
ast: debugAst,
|
|
6805
8141
|
options: mergedOptions
|
|
6806
8142
|
},
|
|
6807
8143
|
async () => {
|
|
@@ -6827,6 +8163,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6827
8163
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6828
8164
|
}
|
|
6829
8165
|
const sql = buildInsertDebugSql(payload);
|
|
8166
|
+
const debugAst = debugAstEnabled ? buildInsertDebugAst(payload) : void 0;
|
|
6830
8167
|
return executeWithQueryTrace(
|
|
6831
8168
|
tracer,
|
|
6832
8169
|
{
|
|
@@ -6835,6 +8172,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6835
8172
|
table: resolvedTableName,
|
|
6836
8173
|
sql,
|
|
6837
8174
|
payload,
|
|
8175
|
+
ast: debugAst,
|
|
6838
8176
|
options: mergedOptions
|
|
6839
8177
|
},
|
|
6840
8178
|
async () => {
|
|
@@ -6865,6 +8203,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6865
8203
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6866
8204
|
}
|
|
6867
8205
|
const sql = buildInsertDebugSql(payload);
|
|
8206
|
+
const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
|
|
6868
8207
|
return executeWithQueryTrace(
|
|
6869
8208
|
tracer,
|
|
6870
8209
|
{
|
|
@@ -6873,6 +8212,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6873
8212
|
table: resolvedTableName,
|
|
6874
8213
|
sql,
|
|
6875
8214
|
payload,
|
|
8215
|
+
ast: debugAst,
|
|
6876
8216
|
options: mergedOptions
|
|
6877
8217
|
},
|
|
6878
8218
|
async () => {
|
|
@@ -6900,6 +8240,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6900
8240
|
payload.default_to_null = mergedOptions.defaultToNull;
|
|
6901
8241
|
}
|
|
6902
8242
|
const sql = buildInsertDebugSql(payload);
|
|
8243
|
+
const debugAst = debugAstEnabled ? buildUpsertDebugAst(payload) : void 0;
|
|
6903
8244
|
return executeWithQueryTrace(
|
|
6904
8245
|
tracer,
|
|
6905
8246
|
{
|
|
@@ -6908,6 +8249,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6908
8249
|
table: resolvedTableName,
|
|
6909
8250
|
sql,
|
|
6910
8251
|
payload,
|
|
8252
|
+
ast: debugAst,
|
|
6911
8253
|
options: mergedOptions
|
|
6912
8254
|
},
|
|
6913
8255
|
async () => {
|
|
@@ -6922,7 +8264,8 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6922
8264
|
update(values, options) {
|
|
6923
8265
|
const mutationCallsite = captureTraceCallsite(tracer);
|
|
6924
8266
|
const executeUpdate = async (columns, selectOptions, callsite) => {
|
|
6925
|
-
const
|
|
8267
|
+
const executionState = snapshotState();
|
|
8268
|
+
const filters = executionState.conditions.length ? [...executionState.conditions] : void 0;
|
|
6926
8269
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
6927
8270
|
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
6928
8271
|
const payload = {
|
|
@@ -6931,12 +8274,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6931
8274
|
conditions: filters,
|
|
6932
8275
|
strip_nulls: mergedOptions?.stripNulls ?? true
|
|
6933
8276
|
};
|
|
6934
|
-
if (
|
|
6935
|
-
if (
|
|
6936
|
-
if (
|
|
6937
|
-
if (
|
|
8277
|
+
if (executionState.order) payload.sort_by = executionState.order;
|
|
8278
|
+
if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
|
|
8279
|
+
if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
|
|
8280
|
+
if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
|
|
6938
8281
|
if (columns) payload.columns = columns;
|
|
6939
8282
|
const sql = buildUpdateDebugSql(payload);
|
|
8283
|
+
const debugAst = debugAstEnabled ? buildUpdateDebugAst({
|
|
8284
|
+
state: executionState,
|
|
8285
|
+
payload
|
|
8286
|
+
}) : void 0;
|
|
6940
8287
|
return executeWithQueryTrace(
|
|
6941
8288
|
tracer,
|
|
6942
8289
|
{
|
|
@@ -6945,6 +8292,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6945
8292
|
table: resolvedTableName,
|
|
6946
8293
|
sql,
|
|
6947
8294
|
payload,
|
|
8295
|
+
ast: debugAst,
|
|
6948
8296
|
options: mergedOptions
|
|
6949
8297
|
},
|
|
6950
8298
|
async () => {
|
|
@@ -6968,6 +8316,11 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6968
8316
|
}
|
|
6969
8317
|
const mutationCallsite = captureTraceCallsite(tracer);
|
|
6970
8318
|
const executeDelete = async (columns, selectOptions, callsite) => {
|
|
8319
|
+
const executionState = snapshotState();
|
|
8320
|
+
const debugState = {
|
|
8321
|
+
...executionState,
|
|
8322
|
+
conditions: filters ? filters.map((condition) => ({ ...condition })) : []
|
|
8323
|
+
};
|
|
6971
8324
|
const mergedOptions = mergeOptions(options, selectOptions);
|
|
6972
8325
|
const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
|
|
6973
8326
|
const payload = {
|
|
@@ -6975,12 +8328,16 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6975
8328
|
resource_id: resourceId,
|
|
6976
8329
|
conditions: filters
|
|
6977
8330
|
};
|
|
6978
|
-
if (
|
|
6979
|
-
if (
|
|
6980
|
-
if (
|
|
6981
|
-
if (
|
|
8331
|
+
if (executionState.order) payload.sort_by = executionState.order;
|
|
8332
|
+
if (executionState.currentPage !== void 0) payload.current_page = executionState.currentPage;
|
|
8333
|
+
if (executionState.pageSize !== void 0) payload.page_size = executionState.pageSize;
|
|
8334
|
+
if (executionState.totalPages !== void 0) payload.total_pages = executionState.totalPages;
|
|
6982
8335
|
if (columns) payload.columns = columns;
|
|
6983
8336
|
const sql = buildDeleteDebugSql(payload);
|
|
8337
|
+
const debugAst = debugAstEnabled ? buildDeleteDebugAst({
|
|
8338
|
+
state: debugState,
|
|
8339
|
+
payload
|
|
8340
|
+
}) : void 0;
|
|
6984
8341
|
return executeWithQueryTrace(
|
|
6985
8342
|
tracer,
|
|
6986
8343
|
{
|
|
@@ -6989,6 +8346,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
6989
8346
|
table: resolvedTableName,
|
|
6990
8347
|
sql,
|
|
6991
8348
|
payload,
|
|
8349
|
+
ast: debugAst,
|
|
6992
8350
|
options: mergedOptions
|
|
6993
8351
|
},
|
|
6994
8352
|
async () => {
|
|
@@ -7016,6 +8374,7 @@ function createTableBuilder(tableName, client, formatGatewayResult, tracer, expe
|
|
|
7016
8374
|
return builder;
|
|
7017
8375
|
}
|
|
7018
8376
|
function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
8377
|
+
const debugAstEnabled = Boolean(experimental?.debugAst);
|
|
7019
8378
|
return async function query(query, options) {
|
|
7020
8379
|
const normalizedQuery = query.trim();
|
|
7021
8380
|
if (!normalizedQuery) {
|
|
@@ -7032,6 +8391,7 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
7032
8391
|
endpoint: "/gateway/query",
|
|
7033
8392
|
sql: normalizedQuery,
|
|
7034
8393
|
payload,
|
|
8394
|
+
ast: debugAstEnabled ? buildRawQueryDebugAst(normalizedQuery) : void 0,
|
|
7035
8395
|
options
|
|
7036
8396
|
},
|
|
7037
8397
|
async () => {
|
|
@@ -7043,6 +8403,96 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
7043
8403
|
);
|
|
7044
8404
|
};
|
|
7045
8405
|
}
|
|
8406
|
+
function resolveClientServiceBaseUrl(value, label) {
|
|
8407
|
+
if (value === void 0 || value === null) {
|
|
8408
|
+
return void 0;
|
|
8409
|
+
}
|
|
8410
|
+
return normalizeAthenaGatewayBaseUrl(value, { label });
|
|
8411
|
+
}
|
|
8412
|
+
function appendServicePath(baseUrl, segment) {
|
|
8413
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8414
|
+
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8415
|
+
}
|
|
8416
|
+
function resolveServiceUrlOverride(value, label) {
|
|
8417
|
+
return resolveClientServiceBaseUrl(value, label);
|
|
8418
|
+
}
|
|
8419
|
+
function resolveServiceUrls(config) {
|
|
8420
|
+
const baseUrl = resolveClientServiceBaseUrl(config.url, "Athena public base URL");
|
|
8421
|
+
return {
|
|
8422
|
+
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),
|
|
8423
|
+
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),
|
|
8424
|
+
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8425
|
+
};
|
|
8426
|
+
}
|
|
8427
|
+
function resolveOptionalClientName(value) {
|
|
8428
|
+
if (value === void 0 || value === null) {
|
|
8429
|
+
return void 0;
|
|
8430
|
+
}
|
|
8431
|
+
const normalizedValue = value.trim();
|
|
8432
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
8433
|
+
}
|
|
8434
|
+
function resolveRequiredClientApiKey(value) {
|
|
8435
|
+
if (value === void 0 || value === null) {
|
|
8436
|
+
throw new Error(
|
|
8437
|
+
"Athena API key is required. Pass createClient(url, key) with a real API key, or set key in the config object."
|
|
8438
|
+
);
|
|
8439
|
+
}
|
|
8440
|
+
const normalizedValue = value.trim();
|
|
8441
|
+
if (!normalizedValue) {
|
|
8442
|
+
throw new Error(
|
|
8443
|
+
"Athena API key is required. Pass createClient(url, key) with a real API key, or set key in the config object."
|
|
8444
|
+
);
|
|
8445
|
+
}
|
|
8446
|
+
return normalizedValue;
|
|
8447
|
+
}
|
|
8448
|
+
function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
8449
|
+
if (!auth && defaultBaseUrl === void 0) {
|
|
8450
|
+
return void 0;
|
|
8451
|
+
}
|
|
8452
|
+
const {
|
|
8453
|
+
url,
|
|
8454
|
+
baseUrl,
|
|
8455
|
+
apiKey,
|
|
8456
|
+
bearerToken,
|
|
8457
|
+
...rest
|
|
8458
|
+
} = auth ?? {};
|
|
8459
|
+
const normalized = {
|
|
8460
|
+
...rest
|
|
8461
|
+
};
|
|
8462
|
+
const resolvedBaseUrl = resolveClientServiceBaseUrl(
|
|
8463
|
+
url ?? baseUrl ?? defaultBaseUrl,
|
|
8464
|
+
"Athena auth base URL"
|
|
8465
|
+
);
|
|
8466
|
+
if (resolvedBaseUrl !== void 0) {
|
|
8467
|
+
normalized.baseUrl = resolvedBaseUrl;
|
|
8468
|
+
}
|
|
8469
|
+
if (typeof apiKey === "string") {
|
|
8470
|
+
normalized.apiKey = apiKey;
|
|
8471
|
+
}
|
|
8472
|
+
if (typeof bearerToken === "string") {
|
|
8473
|
+
normalized.bearerToken = bearerToken;
|
|
8474
|
+
}
|
|
8475
|
+
return normalized;
|
|
8476
|
+
}
|
|
8477
|
+
function resolveCreateClientConfig(config) {
|
|
8478
|
+
const resolvedUrls = resolveServiceUrls(config);
|
|
8479
|
+
if (!resolvedUrls.dbUrl) {
|
|
8480
|
+
throw new Error(
|
|
8481
|
+
"Athena DB base URL is required. Pass createClient(url, key) for a unified root, or set db.url / gateway.url / gatewayUrl explicitly."
|
|
8482
|
+
);
|
|
8483
|
+
}
|
|
8484
|
+
return {
|
|
8485
|
+
baseUrl: resolvedUrls.dbUrl,
|
|
8486
|
+
apiKey: resolveRequiredClientApiKey(config.key),
|
|
8487
|
+
client: resolveOptionalClientName(config.client),
|
|
8488
|
+
backend: toBackendConfig(config.backend),
|
|
8489
|
+
headers: config.headers,
|
|
8490
|
+
auth: config.auth,
|
|
8491
|
+
authUrl: resolvedUrls.authUrl,
|
|
8492
|
+
storageUrl: resolvedUrls.storageUrl,
|
|
8493
|
+
experimental: config.experimental
|
|
8494
|
+
};
|
|
8495
|
+
}
|
|
7046
8496
|
function createClientFromConfig(config) {
|
|
7047
8497
|
const gatewayHeaders = {
|
|
7048
8498
|
...config.headers ?? {}
|
|
@@ -7057,16 +8507,33 @@ function createClientFromConfig(config) {
|
|
|
7057
8507
|
backend: config.backend,
|
|
7058
8508
|
headers: gatewayHeaders
|
|
7059
8509
|
});
|
|
7060
|
-
const formatGatewayResult = createResultFormatter();
|
|
8510
|
+
const formatGatewayResult = createResultFormatter(config.experimental);
|
|
7061
8511
|
const queryTracer = createQueryTracer(config.experimental);
|
|
7062
|
-
const auth = createAuthClient(config.auth);
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
8512
|
+
const auth = createAuthClient(normalizeAuthClientConfig(config.auth, config.authUrl));
|
|
8513
|
+
function from(tableOrModel, options) {
|
|
8514
|
+
if (isAthenaModelTarget(tableOrModel)) {
|
|
8515
|
+
if (options?.schema !== void 0) {
|
|
8516
|
+
throw new Error(
|
|
8517
|
+
"from(model) does not accept a schema override because the model already defines its target."
|
|
8518
|
+
);
|
|
8519
|
+
}
|
|
8520
|
+
return createTableBuilder(
|
|
8521
|
+
resolveAthenaModelTargetTableName(tableOrModel),
|
|
8522
|
+
gateway,
|
|
8523
|
+
formatGatewayResult,
|
|
8524
|
+
queryTracer,
|
|
8525
|
+
config.experimental
|
|
8526
|
+
);
|
|
8527
|
+
}
|
|
8528
|
+
const resolvedTableName = resolveTableNameForCall(tableOrModel, options?.schema);
|
|
8529
|
+
return createTableBuilder(
|
|
8530
|
+
resolvedTableName,
|
|
8531
|
+
gateway,
|
|
8532
|
+
formatGatewayResult,
|
|
8533
|
+
queryTracer,
|
|
8534
|
+
config.experimental
|
|
8535
|
+
);
|
|
8536
|
+
}
|
|
7070
8537
|
const rpc = (fn, args, options) => {
|
|
7071
8538
|
const normalizedFn = fn.trim();
|
|
7072
8539
|
if (!normalizedFn) {
|
|
@@ -7079,10 +8546,16 @@ function createClientFromConfig(config) {
|
|
|
7079
8546
|
gateway,
|
|
7080
8547
|
formatGatewayResult,
|
|
7081
8548
|
queryTracer,
|
|
7082
|
-
captureTraceCallsite(queryTracer)
|
|
8549
|
+
captureTraceCallsite(queryTracer),
|
|
8550
|
+
Boolean(config.experimental?.debugAst)
|
|
7083
8551
|
);
|
|
7084
8552
|
};
|
|
7085
|
-
const query = createQueryBuilder(
|
|
8553
|
+
const query = createQueryBuilder(
|
|
8554
|
+
gateway,
|
|
8555
|
+
formatGatewayResult,
|
|
8556
|
+
config.experimental,
|
|
8557
|
+
queryTracer
|
|
8558
|
+
);
|
|
7086
8559
|
const db = createDbModule({ from, rpc, query });
|
|
7087
8560
|
const sdkClient = {
|
|
7088
8561
|
from,
|
|
@@ -7095,27 +8568,27 @@ function createClientFromConfig(config) {
|
|
|
7095
8568
|
if (config.experimental?.athenaStorageBackend) {
|
|
7096
8569
|
const storageClient = {
|
|
7097
8570
|
...sdkClient,
|
|
7098
|
-
storage: createStorageModule(gateway,
|
|
8571
|
+
storage: createStorageModule(gateway, {
|
|
8572
|
+
...config.experimental.storage,
|
|
8573
|
+
...config.storageUrl ? {
|
|
8574
|
+
baseUrl: config.storageUrl,
|
|
8575
|
+
stripBasePath: true
|
|
8576
|
+
} : {}
|
|
8577
|
+
})
|
|
7099
8578
|
};
|
|
7100
8579
|
return storageClient;
|
|
7101
8580
|
}
|
|
7102
8581
|
return sdkClient;
|
|
7103
8582
|
}
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
client: options?.client,
|
|
7114
|
-
backend: toBackendConfig(options?.backend),
|
|
7115
|
-
headers: options?.headers,
|
|
7116
|
-
auth: options?.auth,
|
|
7117
|
-
experimental: options?.experimental
|
|
7118
|
-
});
|
|
8583
|
+
function createClient(configOrUrl, apiKey, options) {
|
|
8584
|
+
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8585
|
+
return createClientFromConfig(resolveCreateClientConfig({
|
|
8586
|
+
url: configOrUrl,
|
|
8587
|
+
key: apiKey ?? "",
|
|
8588
|
+
...options
|
|
8589
|
+
}));
|
|
8590
|
+
}
|
|
8591
|
+
return createClientFromConfig(resolveCreateClientConfig(configOrUrl));
|
|
7119
8592
|
}
|
|
7120
8593
|
|
|
7121
8594
|
// src/schema/postgres-introspection-core.ts
|
|
@@ -7698,6 +9171,7 @@ async function runSchemaGenerator(options = {}) {
|
|
|
7698
9171
|
return {
|
|
7699
9172
|
...generated,
|
|
7700
9173
|
configPath,
|
|
9174
|
+
config,
|
|
7701
9175
|
writtenFiles
|
|
7702
9176
|
};
|
|
7703
9177
|
}
|
|
@@ -7712,6 +9186,7 @@ function rootUsage() {
|
|
|
7712
9186
|
"",
|
|
7713
9187
|
"Examples:",
|
|
7714
9188
|
" athena-js generate",
|
|
9189
|
+
" DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/app_db athena-js generate --dry-run",
|
|
7715
9190
|
" athena-js generate --config ./athena.config.ts --dry-run",
|
|
7716
9191
|
" athena-js generate --help"
|
|
7717
9192
|
].join("\n");
|
|
@@ -7725,14 +9200,42 @@ function generateUsage() {
|
|
|
7725
9200
|
"",
|
|
7726
9201
|
"Options:",
|
|
7727
9202
|
" --config <path> Explicit path to athena.config.ts or athena-js.config.ts",
|
|
7728
|
-
" --dry-run Build generated files in memory without writing them to disk",
|
|
9203
|
+
" --dry-run Build generated files in memory without writing them to disk and print mode/target hints",
|
|
7729
9204
|
" -h, --help Show help for generate",
|
|
7730
9205
|
"",
|
|
9206
|
+
"Config resolution:",
|
|
9207
|
+
" - uses athena.config.* discovery first",
|
|
9208
|
+
" - falls back to env-only direct mode when DATABASE_URL/PG_URL is present",
|
|
9209
|
+
" - falls back to env-only gateway mode when ATHENA_URL + ATHENA_API_KEY are present",
|
|
9210
|
+
"",
|
|
7731
9211
|
"Examples:",
|
|
7732
9212
|
" athena-js generate",
|
|
9213
|
+
" DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/app_db athena-js generate --dry-run",
|
|
7733
9214
|
" athena-js generate --config ./athena.config.ts --dry-run"
|
|
7734
9215
|
].join("\n");
|
|
7735
9216
|
}
|
|
9217
|
+
function usesSchemaScopedModelTarget(target) {
|
|
9218
|
+
return /\{schema(?:_[a-z]+)?\}/.test(target);
|
|
9219
|
+
}
|
|
9220
|
+
function formatGeneratorModeLines(result) {
|
|
9221
|
+
const lines = [
|
|
9222
|
+
`[mode] format=${result.config.output.format} modelTarget=${result.config.output.targets.model}`
|
|
9223
|
+
];
|
|
9224
|
+
if (result.config.output.format === "define-model") {
|
|
9225
|
+
lines.push(
|
|
9226
|
+
'[note] Zero-style table-builder files are not active. Set output.format="table-builder" or ATHENA_GENERATOR_OUTPUT_FORMAT=table-builder to emit table(...).schema(...).columns(...).primaryKey(...).'
|
|
9227
|
+
);
|
|
9228
|
+
}
|
|
9229
|
+
lines.push(
|
|
9230
|
+
"[note] Table-builder generation is stable. experimental.findManyAst only affects runtime findMany(...) transport and does not enable generator table output."
|
|
9231
|
+
);
|
|
9232
|
+
if (usesSchemaScopedModelTarget(result.config.output.targets.model)) {
|
|
9233
|
+
lines.push(
|
|
9234
|
+
'[note] Flat athena/models/*.ts output is opt-in. Set output.targets.model="athena/models/{model_kebab}.ts" or ATHENA_GENERATOR_MODEL_TARGET=athena/models/{model_kebab}.ts; multi-schema collisions are still auto-scoped by schema when needed.'
|
|
9235
|
+
);
|
|
9236
|
+
}
|
|
9237
|
+
return lines;
|
|
9238
|
+
}
|
|
7736
9239
|
function usage(topic = "root") {
|
|
7737
9240
|
return topic === "generate" ? generateUsage() : rootUsage();
|
|
7738
9241
|
}
|
|
@@ -7834,12 +9337,18 @@ async function runCLI(argv, runtime = {}) {
|
|
|
7834
9337
|
}
|
|
7835
9338
|
if (parsed.dryRun) {
|
|
7836
9339
|
log(`[dry-run] Generated ${result.files.length} files from ${result.configPath}`);
|
|
9340
|
+
for (const line of formatGeneratorModeLines(result)) {
|
|
9341
|
+
log(line);
|
|
9342
|
+
}
|
|
7837
9343
|
for (const file of result.files) {
|
|
7838
9344
|
log(` - ${file.path}`);
|
|
7839
9345
|
}
|
|
7840
9346
|
return;
|
|
7841
9347
|
}
|
|
7842
9348
|
log(`Generated ${result.writtenFiles.length} files from ${result.configPath}`);
|
|
9349
|
+
for (const line of formatGeneratorModeLines(result)) {
|
|
9350
|
+
log(line);
|
|
9351
|
+
}
|
|
7843
9352
|
for (const filePath of result.writtenFiles) {
|
|
7844
9353
|
log(` - ${filePath}`);
|
|
7845
9354
|
}
|