@xube/kit-aws 0.0.111 → 0.0.112
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.
|
@@ -14,7 +14,7 @@ type FetchDataRequest = {
|
|
|
14
14
|
nextToken?: string;
|
|
15
15
|
queryExecutionId?: string;
|
|
16
16
|
};
|
|
17
|
-
export declare const handlePagination: (request: FetchDataRequest) => Promise<string>;
|
|
17
|
+
export declare const handlePagination: (request: FetchDataRequest, glueDatabaseName: string, glueTableName: string, s3BucketName: string, s3BucketAthenaResultsPrefix: string) => Promise<string>;
|
|
18
18
|
export declare const fetchQueryResults: (queryExecutionId: string, paginationParams: PaginationParams, limit: number) => Promise<GetQueryResultsCommandOutput>;
|
|
19
19
|
export declare const formatResponse: (resultsResponse: GetQueryResultsCommandOutput, queryExecutionId: string, paginationParams: PaginationParams) => APIGatewayProxyResult;
|
|
20
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/resources/athena/get.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGZ,4BAA4B,EAC5B,SAAS,EAEV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,eAAO,MAAM,sBAAsB,WACzB,YAAY,oBACF,MAAM,QACnB,OAAO,kBACG,MAAM,mBACL,MAAM,KACrB,OAAO,CAAC,OAAO,CAgDjB,CAAC;AAEF,eAAO,MAAM,sBAAsB,cACtB,SAAS,GAAG,SAAS,cACpB,OAAO,KAClB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAsBrB,CAAC;AAEF,UAAU,gBAAgB;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;A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EF,eAAO,MAAM,cAAc,oBACR,4BAA4B,oBAC3B,MAAM,oBACN,gBAAgB,KACjC,qBAuBF,CAAC"}
|
|
@@ -56,40 +56,33 @@ const transformAthenaResults = (resultSet, isNextPage) => {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
exports.transformAthenaResults = transformAthenaResults;
|
|
59
|
-
const
|
|
60
|
-
const GLUE_TABLE_NAME = process.env.ATHENA_GLUE_TABLE ?? "";
|
|
61
|
-
const S3_BUCKET_NAME = process.env.ATHENA_RESULTS_BUCKET ?? "";
|
|
62
|
-
const S3_BUCKET_ATHENA_RESULTS_PREFIX = process.env.ATHENA_RESULTS_PREFIX ?? "athena-results";
|
|
63
|
-
const buildQuery = (request) => {
|
|
64
|
-
const databaseName = GLUE_DATABASE_NAME;
|
|
65
|
-
const tableName = GLUE_TABLE_NAME;
|
|
59
|
+
const buildQuery = (request, glueDatabaseName, glueTableName) => {
|
|
66
60
|
const { from, to } = request;
|
|
67
61
|
if (to) {
|
|
68
62
|
return `
|
|
69
|
-
SELECT * FROM "${
|
|
63
|
+
SELECT * FROM "${glueDatabaseName}"."${glueTableName}"
|
|
70
64
|
WHERE "s" BETWEEN ${from} AND ${to}
|
|
71
65
|
ORDER BY "s" DESC
|
|
72
66
|
`;
|
|
73
67
|
}
|
|
74
68
|
else {
|
|
75
69
|
return `
|
|
76
|
-
SELECT * FROM "${
|
|
70
|
+
SELECT * FROM "${glueDatabaseName}"."${glueTableName}"
|
|
77
71
|
WHERE "s" >= ${from}
|
|
78
72
|
ORDER BY "s" DESC
|
|
79
73
|
`;
|
|
80
74
|
}
|
|
81
75
|
};
|
|
82
|
-
const executeNewQuery = async (query) => {
|
|
76
|
+
const executeNewQuery = async (query, glueDatabaseName, s3BucketName, s3BucketAthenaResultsPrefix) => {
|
|
83
77
|
const athenaClient = (0, client_1.getAthenaClient)();
|
|
84
|
-
const databaseName = GLUE_DATABASE_NAME;
|
|
85
78
|
const queryExecution = await athenaClient.send(new client_athena_1.StartQueryExecutionCommand({
|
|
86
79
|
QueryString: query,
|
|
87
80
|
QueryExecutionContext: {
|
|
88
|
-
Database:
|
|
81
|
+
Database: glueDatabaseName,
|
|
89
82
|
},
|
|
90
83
|
WorkGroup: "primary",
|
|
91
84
|
ResultConfiguration: {
|
|
92
|
-
OutputLocation: `s3://${
|
|
85
|
+
OutputLocation: `s3://${s3BucketName}/${s3BucketAthenaResultsPrefix}`,
|
|
93
86
|
},
|
|
94
87
|
}));
|
|
95
88
|
if (!queryExecution.QueryExecutionId) {
|
|
@@ -101,7 +94,7 @@ const executeNewQuery = async (query) => {
|
|
|
101
94
|
}
|
|
102
95
|
return queryExecution.QueryExecutionId;
|
|
103
96
|
};
|
|
104
|
-
const handlePagination = async (request) => {
|
|
97
|
+
const handlePagination = async (request, glueDatabaseName, glueTableName, s3BucketName, s3BucketAthenaResultsPrefix) => {
|
|
105
98
|
const paginationParams = {
|
|
106
99
|
isNextPage: !!request.nextToken && !!request.queryExecutionId,
|
|
107
100
|
queryExecutionId: request.queryExecutionId,
|
|
@@ -111,8 +104,8 @@ const handlePagination = async (request) => {
|
|
|
111
104
|
return request.queryExecutionId;
|
|
112
105
|
}
|
|
113
106
|
else {
|
|
114
|
-
const query = buildQuery(request);
|
|
115
|
-
return await executeNewQuery(query);
|
|
107
|
+
const query = buildQuery(request, glueDatabaseName, glueTableName);
|
|
108
|
+
return await executeNewQuery(query, glueDatabaseName, s3BucketName, s3BucketAthenaResultsPrefix);
|
|
116
109
|
}
|
|
117
110
|
};
|
|
118
111
|
exports.handlePagination = handlePagination;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.112",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/aws-lambda": "^8.10.119",
|
|
21
|
-
"@xube/kit-build": "^0.0.
|
|
21
|
+
"@xube/kit-build": "^0.0.112"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-athena": "^3.656.0",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@aws-sdk/client-ssm": "^3.654.0",
|
|
30
30
|
"@aws-sdk/lib-dynamodb": "^3.656.0",
|
|
31
31
|
"@aws-sdk/util-dynamodb": "^3.656.0",
|
|
32
|
-
"@xube/kit-aws-schema": "^0.0.
|
|
33
|
-
"@xube/kit-log": "^0.0.
|
|
34
|
-
"@xube/kit-request": "^0.0.
|
|
35
|
-
"@xube/kit-schema": "^0.0.
|
|
32
|
+
"@xube/kit-aws-schema": "^0.0.112",
|
|
33
|
+
"@xube/kit-log": "^0.0.112",
|
|
34
|
+
"@xube/kit-request": "^0.0.112",
|
|
35
|
+
"@xube/kit-schema": "^0.0.112",
|
|
36
36
|
"zod": "^3.23.8"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -108,47 +108,45 @@ type FetchDataRequest = {
|
|
|
108
108
|
queryExecutionId?: string;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const buildQuery = (request: FetchDataRequest): string => {
|
|
118
|
-
const databaseName = GLUE_DATABASE_NAME;
|
|
119
|
-
const tableName = GLUE_TABLE_NAME;
|
|
120
|
-
|
|
111
|
+
const buildQuery = (
|
|
112
|
+
request: FetchDataRequest,
|
|
113
|
+
glueDatabaseName: string,
|
|
114
|
+
glueTableName: string
|
|
115
|
+
): string => {
|
|
121
116
|
const { from, to } = request;
|
|
122
117
|
|
|
123
118
|
if (to) {
|
|
124
119
|
return `
|
|
125
|
-
SELECT * FROM "${
|
|
120
|
+
SELECT * FROM "${glueDatabaseName}"."${glueTableName}"
|
|
126
121
|
WHERE "s" BETWEEN ${from} AND ${to}
|
|
127
122
|
ORDER BY "s" DESC
|
|
128
123
|
`;
|
|
129
124
|
} else {
|
|
130
125
|
return `
|
|
131
|
-
SELECT * FROM "${
|
|
126
|
+
SELECT * FROM "${glueDatabaseName}"."${glueTableName}"
|
|
132
127
|
WHERE "s" >= ${from}
|
|
133
128
|
ORDER BY "s" DESC
|
|
134
129
|
`;
|
|
135
130
|
}
|
|
136
131
|
};
|
|
137
132
|
|
|
138
|
-
const executeNewQuery = async (
|
|
133
|
+
const executeNewQuery = async (
|
|
134
|
+
query: string,
|
|
135
|
+
glueDatabaseName: string,
|
|
136
|
+
s3BucketName: string,
|
|
137
|
+
s3BucketAthenaResultsPrefix: string
|
|
138
|
+
): Promise<string> => {
|
|
139
139
|
const athenaClient = getAthenaClient();
|
|
140
140
|
|
|
141
|
-
const databaseName = GLUE_DATABASE_NAME;
|
|
142
|
-
|
|
143
141
|
const queryExecution = await athenaClient.send(
|
|
144
142
|
new StartQueryExecutionCommand({
|
|
145
143
|
QueryString: query,
|
|
146
144
|
QueryExecutionContext: {
|
|
147
|
-
Database:
|
|
145
|
+
Database: glueDatabaseName,
|
|
148
146
|
},
|
|
149
147
|
WorkGroup: "primary",
|
|
150
148
|
ResultConfiguration: {
|
|
151
|
-
OutputLocation: `s3://${
|
|
149
|
+
OutputLocation: `s3://${s3BucketName}/${s3BucketAthenaResultsPrefix}`,
|
|
152
150
|
},
|
|
153
151
|
})
|
|
154
152
|
);
|
|
@@ -170,7 +168,11 @@ const executeNewQuery = async (query: string): Promise<string> => {
|
|
|
170
168
|
};
|
|
171
169
|
|
|
172
170
|
export const handlePagination = async (
|
|
173
|
-
request: FetchDataRequest
|
|
171
|
+
request: FetchDataRequest,
|
|
172
|
+
glueDatabaseName: string,
|
|
173
|
+
glueTableName: string,
|
|
174
|
+
s3BucketName: string,
|
|
175
|
+
s3BucketAthenaResultsPrefix: string
|
|
174
176
|
): Promise<string> => {
|
|
175
177
|
const paginationParams: PaginationParams = {
|
|
176
178
|
isNextPage: !!request.nextToken && !!request.queryExecutionId,
|
|
@@ -181,8 +183,13 @@ export const handlePagination = async (
|
|
|
181
183
|
if (paginationParams.isNextPage) {
|
|
182
184
|
return request.queryExecutionId!;
|
|
183
185
|
} else {
|
|
184
|
-
const query = buildQuery(request);
|
|
185
|
-
return await executeNewQuery(
|
|
186
|
+
const query = buildQuery(request, glueDatabaseName, glueTableName);
|
|
187
|
+
return await executeNewQuery(
|
|
188
|
+
query,
|
|
189
|
+
glueDatabaseName,
|
|
190
|
+
s3BucketName,
|
|
191
|
+
s3BucketAthenaResultsPrefix
|
|
192
|
+
);
|
|
186
193
|
}
|
|
187
194
|
};
|
|
188
195
|
|