triangle-utils 1.4.16 → 1.4.18
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/dist/src/UtilsDynamoDB.d.ts +1 -1
- package/dist/src/UtilsDynamoDB.js +5 -2
- package/dist/src/UtilsS3.d.ts +1 -0
- package/dist/src/UtilsS3.js +22 -1
- package/package.json +1 -1
- package/src/UtilsDynamoDB.ts +5 -2
- package/src/UtilsS3.ts +22 -1
|
@@ -2,7 +2,7 @@ export declare class UtilsDynamoDB {
|
|
|
2
2
|
private readonly dynamodb;
|
|
3
3
|
constructor(region: string);
|
|
4
4
|
get_table_key_names(table_name: string): Promise<string[] | undefined>;
|
|
5
|
-
scan(
|
|
5
|
+
scan(table_index_name: string, options?: {
|
|
6
6
|
filters?: Record<string, any>;
|
|
7
7
|
undefined_attribute_names?: string[];
|
|
8
8
|
defined_attribute_names?: string[];
|
|
@@ -98,7 +98,9 @@ export class UtilsDynamoDB {
|
|
|
98
98
|
.filter(table_key_name => table_key_name !== undefined);
|
|
99
99
|
return table_key_names;
|
|
100
100
|
}
|
|
101
|
-
async scan(
|
|
101
|
+
async scan(table_index_name, options = {}) {
|
|
102
|
+
const table_name = table_index_name.split(":")[0];
|
|
103
|
+
const index_name = table_index_name.split(":")[1];
|
|
102
104
|
const filters = options.filters !== undefined ? options.filters : {};
|
|
103
105
|
const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
|
|
104
106
|
const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
|
|
@@ -118,7 +120,8 @@ export class UtilsDynamoDB {
|
|
|
118
120
|
].join(" AND ");
|
|
119
121
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
|
|
120
122
|
const request = {
|
|
121
|
-
TableName:
|
|
123
|
+
TableName: table_name,
|
|
124
|
+
IndexName: index_name,
|
|
122
125
|
ExpressionAttributeNames: Object.keys(expression_attribute_names).length > 0 ? expression_attribute_names : undefined,
|
|
123
126
|
ExpressionAttributeValues: Object.keys(expression_attribute_values).length > 0 ? expression_attribute_values : undefined,
|
|
124
127
|
FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
|
package/dist/src/UtilsS3.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class UtilsS3 {
|
|
|
4
4
|
constructor(region: string);
|
|
5
5
|
file_exists(s3_filename: string): Promise<boolean | undefined>;
|
|
6
6
|
get_file(s3_filename: string): Promise<string | undefined>;
|
|
7
|
+
get_file_buffer(s3_filename: string): Promise<Buffer | undefined>;
|
|
7
8
|
get_file_stream(s3_filename: string): Promise<Readable | undefined>;
|
|
8
9
|
create_file(s3_filename: string, content: string | Buffer, options?: {
|
|
9
10
|
content_type?: string;
|
package/dist/src/UtilsS3.js
CHANGED
|
@@ -39,7 +39,7 @@ export class UtilsS3 {
|
|
|
39
39
|
if (body === undefined) {
|
|
40
40
|
return undefined;
|
|
41
41
|
}
|
|
42
|
-
const text = body.transformToString("utf-8");
|
|
42
|
+
const text = await body.transformToString("utf-8");
|
|
43
43
|
return text;
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
@@ -49,6 +49,27 @@ export class UtilsS3 {
|
|
|
49
49
|
throw error;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
async get_file_buffer(s3_filename) {
|
|
53
|
+
const s3_key = parse_s3_filename(s3_filename);
|
|
54
|
+
if (s3_key === undefined) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const response = await this.s3.getObject(s3_key);
|
|
59
|
+
const body = response.Body;
|
|
60
|
+
if (body === undefined) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const buffer = Buffer.from(await body.transformToByteArray());
|
|
64
|
+
return buffer;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error instanceof NoSuchKey) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
52
73
|
async get_file_stream(s3_filename) {
|
|
53
74
|
const s3_key = parse_s3_filename(s3_filename);
|
|
54
75
|
if (s3_key === undefined) {
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -106,7 +106,7 @@ export class UtilsDynamoDB {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
async scan(
|
|
109
|
-
|
|
109
|
+
table_index_name : string,
|
|
110
110
|
options : {
|
|
111
111
|
filters? : Record<string, any>,
|
|
112
112
|
undefined_attribute_names? : string[],
|
|
@@ -115,6 +115,8 @@ export class UtilsDynamoDB {
|
|
|
115
115
|
concurrency? : number
|
|
116
116
|
} = {}
|
|
117
117
|
) : Promise<Record<string, any>[]> {
|
|
118
|
+
const table_name : string = table_index_name.split(":")[0]
|
|
119
|
+
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
118
120
|
const filters = options.filters !== undefined ? options.filters : {}
|
|
119
121
|
const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
|
|
120
122
|
const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
|
|
@@ -138,7 +140,8 @@ export class UtilsDynamoDB {
|
|
|
138
140
|
].join(" AND ")
|
|
139
141
|
const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
|
|
140
142
|
const request : ScanCommandInput = {
|
|
141
|
-
TableName :
|
|
143
|
+
TableName : table_name,
|
|
144
|
+
IndexName : index_name,
|
|
142
145
|
ExpressionAttributeNames : Object.keys(expression_attribute_names).length > 0 ? expression_attribute_names : undefined,
|
|
143
146
|
ExpressionAttributeValues : Object.keys(expression_attribute_values).length > 0 ? expression_attribute_values : undefined,
|
|
144
147
|
FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
|
package/src/UtilsS3.ts
CHANGED
|
@@ -49,7 +49,7 @@ export class UtilsS3 {
|
|
|
49
49
|
if (body === undefined) {
|
|
50
50
|
return undefined
|
|
51
51
|
}
|
|
52
|
-
const text = body.transformToString("utf-8")
|
|
52
|
+
const text = await body.transformToString("utf-8")
|
|
53
53
|
return text
|
|
54
54
|
} catch (error) {
|
|
55
55
|
if (error instanceof NoSuchKey) {
|
|
@@ -59,6 +59,27 @@ export class UtilsS3 {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
async get_file_buffer(s3_filename : string) : Promise<Buffer | undefined> {
|
|
63
|
+
const s3_key = parse_s3_filename(s3_filename)
|
|
64
|
+
if (s3_key === undefined) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const response = await this.s3.getObject(s3_key)
|
|
69
|
+
const body = response.Body
|
|
70
|
+
if (body === undefined) {
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
const buffer = Buffer.from(await body.transformToByteArray())
|
|
74
|
+
return buffer
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof NoSuchKey) {
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
async get_file_stream(s3_filename : string) : Promise<Readable | undefined> {
|
|
63
84
|
const s3_key = parse_s3_filename(s3_filename)
|
|
64
85
|
if (s3_key === undefined) {
|