triangle-utils 1.4.115 → 1.4.117

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.
@@ -1,7 +1,14 @@
1
+ import { S3 } from "@aws-sdk/client-s3";
1
2
  import { Readable } from "stream";
3
+ interface S3Input {
4
+ Bucket: string;
5
+ Key: string;
6
+ }
2
7
  export declare class UtilsS3 {
3
8
  private readonly s3;
4
9
  constructor(region: string);
10
+ get_client(): Promise<S3>;
11
+ get_s3_input(s3_id: string): S3Input | undefined;
5
12
  get_headers(s3_id: string): Promise<{
6
13
  DeleteMarker?: boolean | undefined;
7
14
  AcceptRanges?: string | undefined;
@@ -68,3 +75,4 @@ export declare class UtilsS3 {
68
75
  content_type_id?: string;
69
76
  }): Promise<string | undefined>;
70
77
  }
78
+ export {};
@@ -2,20 +2,23 @@ import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/clie
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
3
3
  import { Upload } from "@aws-sdk/lib-storage";
4
4
  import { Readable } from "stream";
5
- function get_s3_input(s3_id) {
6
- const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3);
7
- if (bucket === undefined || path === undefined) {
8
- return undefined;
9
- }
10
- return { Bucket: bucket, Key: path };
11
- }
12
5
  export class UtilsS3 {
13
6
  s3;
14
7
  constructor(region) {
15
8
  this.s3 = new S3({ region: region });
16
9
  }
10
+ async get_client() {
11
+ return this.s3;
12
+ }
13
+ get_s3_input(s3_id) {
14
+ const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3);
15
+ if (bucket === undefined || path === undefined) {
16
+ return undefined;
17
+ }
18
+ return { Bucket: bucket, Key: path };
19
+ }
17
20
  async get_headers(s3_id) {
18
- const s3_input = get_s3_input(s3_id);
21
+ const s3_input = this.get_s3_input(s3_id);
19
22
  if (s3_input === undefined) {
20
23
  return undefined;
21
24
  }
@@ -31,7 +34,7 @@ export class UtilsS3 {
31
34
  }
32
35
  }
33
36
  async get(s3_id, encoding = "utf-8") {
34
- const s3_input = get_s3_input(s3_id);
37
+ const s3_input = this.get_s3_input(s3_id);
35
38
  if (s3_input === undefined) {
36
39
  return undefined;
37
40
  }
@@ -52,7 +55,7 @@ export class UtilsS3 {
52
55
  }
53
56
  }
54
57
  async get_buffer(s3_id) {
55
- const s3_input = get_s3_input(s3_id);
58
+ const s3_input = this.get_s3_input(s3_id);
56
59
  if (s3_input === undefined) {
57
60
  return undefined;
58
61
  }
@@ -73,7 +76,7 @@ export class UtilsS3 {
73
76
  }
74
77
  }
75
78
  async get_stream(s3_id) {
76
- const s3_input = get_s3_input(s3_id);
79
+ const s3_input = this.get_s3_input(s3_id);
77
80
  if (s3_input === undefined) {
78
81
  return undefined;
79
82
  }
@@ -97,7 +100,7 @@ export class UtilsS3 {
97
100
  }
98
101
  async query_prefix(s3_id_prefix, options = {}) {
99
102
  const compile = options.compile !== undefined ? options.compile : false;
100
- const s3_input = get_s3_input(s3_id_prefix);
103
+ const s3_input = this.get_s3_input(s3_id_prefix);
101
104
  if (s3_input === undefined) {
102
105
  return [];
103
106
  }
@@ -137,7 +140,7 @@ export class UtilsS3 {
137
140
  if (headers !== undefined) {
138
141
  return undefined;
139
142
  }
140
- const s3_input = get_s3_input(s3_id);
143
+ const s3_input = this.get_s3_input(s3_id);
141
144
  if (s3_input === undefined) {
142
145
  return undefined;
143
146
  }
@@ -149,7 +152,7 @@ export class UtilsS3 {
149
152
  }
150
153
  async upload(s3_id, content, options = {}) {
151
154
  const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
152
- const s3_input = get_s3_input(s3_id);
155
+ const s3_input = this.get_s3_input(s3_id);
153
156
  if (s3_input === undefined) {
154
157
  return undefined;
155
158
  }
@@ -164,7 +167,7 @@ export class UtilsS3 {
164
167
  await upload.done();
165
168
  }
166
169
  async delete(s3_id) {
167
- const s3_input = get_s3_input(s3_id);
170
+ const s3_input = this.get_s3_input(s3_id);
168
171
  if (s3_input === undefined) {
169
172
  return undefined;
170
173
  }
@@ -175,7 +178,7 @@ export class UtilsS3 {
175
178
  if (headers === undefined) {
176
179
  return undefined;
177
180
  }
178
- const s3_input = get_s3_input(s3_id);
181
+ const s3_input = this.get_s3_input(s3_id);
179
182
  if (s3_input === undefined) {
180
183
  return undefined;
181
184
  }
@@ -185,7 +188,7 @@ export class UtilsS3 {
185
188
  }
186
189
  async get_upload_url(s3_id, options = {}) {
187
190
  const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
188
- const s3_input = get_s3_input(s3_id);
191
+ const s3_input = this.get_s3_input(s3_id);
189
192
  if (s3_input === undefined) {
190
193
  return undefined;
191
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.115",
3
+ "version": "1.4.117",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsS3.ts CHANGED
@@ -8,14 +8,6 @@ interface S3Input {
8
8
  Key : string
9
9
  }
10
10
 
11
- function get_s3_input(s3_id : string) : S3Input | undefined {
12
- const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3)
13
- if (bucket === undefined || path === undefined) {
14
- return undefined
15
- }
16
- return { Bucket : bucket, Key : path }
17
- }
18
-
19
11
  export class UtilsS3 {
20
12
 
21
13
  private readonly s3 : S3
@@ -24,8 +16,20 @@ export class UtilsS3 {
24
16
  this.s3 = new S3({ region : region })
25
17
  }
26
18
 
19
+ async get_client() {
20
+ return this.s3
21
+ }
22
+
23
+ get_s3_input(s3_id : string) : S3Input | undefined {
24
+ const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3)
25
+ if (bucket === undefined || path === undefined) {
26
+ return undefined
27
+ }
28
+ return { Bucket : bucket, Key : path }
29
+ }
30
+
27
31
  async get_headers(s3_id : string) {
28
- const s3_input = get_s3_input(s3_id)
32
+ const s3_input = this.get_s3_input(s3_id)
29
33
  if (s3_input === undefined) {
30
34
  return undefined
31
35
  }
@@ -41,7 +45,7 @@ export class UtilsS3 {
41
45
  }
42
46
 
43
47
  async get(s3_id : string, encoding : string = "utf-8") : Promise<string | undefined> {
44
- const s3_input = get_s3_input(s3_id)
48
+ const s3_input = this.get_s3_input(s3_id)
45
49
  if (s3_input === undefined) {
46
50
  return undefined
47
51
  }
@@ -62,7 +66,7 @@ export class UtilsS3 {
62
66
  }
63
67
 
64
68
  async get_buffer(s3_id : string) : Promise<Buffer | undefined> {
65
- const s3_input = get_s3_input(s3_id)
69
+ const s3_input = this.get_s3_input(s3_id)
66
70
  if (s3_input === undefined) {
67
71
  return undefined
68
72
  }
@@ -83,7 +87,7 @@ export class UtilsS3 {
83
87
  }
84
88
 
85
89
  async get_stream(s3_id : string) : Promise<Readable | undefined> {
86
- const s3_input = get_s3_input(s3_id)
90
+ const s3_input = this.get_s3_input(s3_id)
87
91
  if (s3_input === undefined) {
88
92
  return undefined
89
93
  }
@@ -107,7 +111,7 @@ export class UtilsS3 {
107
111
 
108
112
  async query_prefix(s3_id_prefix : string, options : { compile? : boolean } = {}) {
109
113
  const compile = options.compile !== undefined ? options.compile : false
110
- const s3_input = get_s3_input(s3_id_prefix)
114
+ const s3_input = this.get_s3_input(s3_id_prefix)
111
115
  if (s3_input === undefined) {
112
116
  return []
113
117
  }
@@ -151,7 +155,7 @@ export class UtilsS3 {
151
155
  if (headers !== undefined) {
152
156
  return undefined
153
157
  }
154
- const s3_input = get_s3_input(s3_id)
158
+ const s3_input = this.get_s3_input(s3_id)
155
159
  if (s3_input === undefined) {
156
160
  return undefined
157
161
  }
@@ -166,7 +170,7 @@ export class UtilsS3 {
166
170
  content_type_id? : string
167
171
  } = {}) : Promise<void> {
168
172
  const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
169
- const s3_input = get_s3_input(s3_id)
173
+ const s3_input = this.get_s3_input(s3_id)
170
174
  if (s3_input === undefined) {
171
175
  return undefined
172
176
  }
@@ -182,7 +186,7 @@ export class UtilsS3 {
182
186
  }
183
187
 
184
188
  async delete(s3_id : string) : Promise<void>{
185
- const s3_input = get_s3_input(s3_id)
189
+ const s3_input = this.get_s3_input(s3_id)
186
190
  if (s3_input === undefined) {
187
191
  return undefined
188
192
  }
@@ -194,7 +198,7 @@ export class UtilsS3 {
194
198
  if (headers === undefined) {
195
199
  return undefined
196
200
  }
197
- const s3_input = get_s3_input(s3_id)
201
+ const s3_input = this.get_s3_input(s3_id)
198
202
  if (s3_input === undefined) {
199
203
  return undefined
200
204
  }
@@ -207,7 +211,7 @@ export class UtilsS3 {
207
211
  content_type_id? : string
208
212
  } = {}) : Promise<string | undefined> {
209
213
  const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
210
- const s3_input = get_s3_input(s3_id)
214
+ const s3_input = this.get_s3_input(s3_id)
211
215
  if (s3_input === undefined) {
212
216
  return undefined
213
217
  }