triangle-utils 1.4.1 → 1.4.3

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.
@@ -16,10 +16,6 @@ export class UtilsBee {
16
16
  url: url,
17
17
  params: params
18
18
  });
19
- if (response.status !== 200) {
20
- console.log("Status", response.status);
21
- return undefined;
22
- }
23
19
  const text = this.text_decoder.decode(response.data);
24
20
  return text;
25
21
  }
@@ -11,14 +11,17 @@ export declare class UtilsDynamoDB {
11
11
  get(table: string, key: Record<string, any>, consistent?: boolean): Promise<Record<string, any> | undefined>;
12
12
  get_max(table: string, primary_key: Record<string, any>): Promise<Record<string, any> | undefined>;
13
13
  query(table: string, primary_key: Record<string, any>, options?: {
14
+ index_name?: string;
14
15
  reverse?: boolean;
15
16
  compile?: boolean;
16
17
  }): Promise<Record<string, any>[]>;
17
18
  query_prefix(table: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
19
+ index_name?: string;
18
20
  reverse?: boolean;
19
21
  compile?: boolean;
20
22
  }): Promise<Record<string, any>[]>;
21
23
  query_range(table: string, primary_key: Record<string, any>, secondary_key_range: Record<string, (string | number)[]>, options?: {
24
+ index_name?: string;
22
25
  reverse?: boolean;
23
26
  compile?: boolean;
24
27
  }): Promise<Record<string, any>[]>;
@@ -174,6 +174,7 @@ export class UtilsDynamoDB {
174
174
  return converted_output;
175
175
  }
176
176
  async query(table, primary_key, options = {}) {
177
+ const index_name = options.index_name !== undefined ? options.index_name : undefined;
177
178
  const reverse = options.reverse !== undefined ? options.reverse : false;
178
179
  const compile = options.compile !== undefined ? options.compile : true;
179
180
  if (Object.keys(primary_key).length !== 1) {
@@ -186,6 +187,7 @@ export class UtilsDynamoDB {
186
187
  }
187
188
  const request = {
188
189
  TableName: table,
190
+ IndexName: index_name,
189
191
  ExpressionAttributeNames: {
190
192
  "#a": key
191
193
  },
@@ -198,6 +200,7 @@ export class UtilsDynamoDB {
198
200
  return await compile_pages(request, (request) => this.dynamodb.query(request), compile);
199
201
  }
200
202
  async query_prefix(table, primary_key, secondary_key_prefix, options = {}) {
203
+ const index_name = options.index_name !== undefined ? options.index_name : undefined;
201
204
  const reverse = options.reverse !== undefined ? options.reverse : false;
202
205
  const compile = options.compile !== undefined ? options.compile : true;
203
206
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_prefix).length !== 1) {
@@ -210,6 +213,7 @@ export class UtilsDynamoDB {
210
213
  }
211
214
  const request = {
212
215
  TableName: table,
216
+ IndexName: index_name,
213
217
  ExpressionAttributeNames: {
214
218
  "#a": Object.keys(primary_key)[0],
215
219
  "#b": Object.keys(secondary_key_prefix)[0]
@@ -224,6 +228,7 @@ export class UtilsDynamoDB {
224
228
  return await compile_pages(request, (request) => this.dynamodb.query(request), compile);
225
229
  }
226
230
  async query_range(table, primary_key, secondary_key_range, options = {}) {
231
+ const index_name = options.index_name !== undefined ? options.index_name : undefined;
227
232
  const reverse = options.reverse !== undefined ? options.reverse : false;
228
233
  const compile = options.compile !== undefined ? options.compile : true;
229
234
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
@@ -237,6 +242,7 @@ export class UtilsDynamoDB {
237
242
  }
238
243
  const request = {
239
244
  TableName: table,
245
+ IndexName: index_name,
240
246
  ExpressionAttributeNames: {
241
247
  "#a": Object.keys(primary_key)[0],
242
248
  "#b": Object.keys(secondary_key_range)[0]
@@ -3,6 +3,7 @@ export declare class UtilsS3 {
3
3
  constructor(region: string);
4
4
  file_exists(s3_filename: string): Promise<boolean | undefined>;
5
5
  get_file(s3_filename: string): Promise<string | undefined>;
6
+ get_file_stream(s3_filename: string): Promise<(import("node:stream").Readable & import("@smithy/types").SdkStreamMixin) | (Blob & import("@smithy/types").SdkStreamMixin) | (ReadableStream<any> & import("@smithy/types").SdkStreamMixin) | undefined>;
6
7
  create_file(s3_filename: string, content: string | Buffer, options?: {
7
8
  content_type?: string;
8
9
  }): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
@@ -48,6 +48,26 @@ export class UtilsS3 {
48
48
  throw error;
49
49
  }
50
50
  }
51
+ async get_file_stream(s3_filename) {
52
+ const s3_key = parse_s3_filename(s3_filename);
53
+ if (s3_key === undefined) {
54
+ return undefined;
55
+ }
56
+ try {
57
+ const response = await this.s3.getObject(s3_key);
58
+ const body = response.Body;
59
+ if (body === undefined) {
60
+ return undefined;
61
+ }
62
+ return body;
63
+ }
64
+ catch (error) {
65
+ if (error instanceof NoSuchKey) {
66
+ return undefined;
67
+ }
68
+ throw error;
69
+ }
70
+ }
51
71
  async create_file(s3_filename, content, options = {}) {
52
72
  const content_type = options.content_type !== undefined ? options.content_type : undefined;
53
73
  const exists = await this.file_exists(s3_filename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "main": "dist/src/index.js",
5
5
  "directories": {
6
6
  "test": "vitest"
package/src/UtilsBee.ts CHANGED
@@ -20,10 +20,6 @@ export class UtilsBee {
20
20
  url : url,
21
21
  params : params
22
22
  })
23
- if (response.status !== 200) {
24
- console.log("Status", response.status)
25
- return undefined
26
- }
27
23
  const text = this.text_decoder.decode(response.data)
28
24
  return text
29
25
  } catch (error) {
@@ -204,10 +204,12 @@ export class UtilsDynamoDB {
204
204
  table : string,
205
205
  primary_key : Record<string, any>,
206
206
  options : {
207
+ index_name? : string,
207
208
  reverse? : boolean,
208
209
  compile? : boolean
209
210
  } = {}
210
211
  ) : Promise<Record<string, any>[]>{
212
+ const index_name = options.index_name !== undefined ? options.index_name : undefined
211
213
  const reverse = options.reverse !== undefined ? options.reverse : false
212
214
  const compile = options.compile !== undefined ? options.compile : true
213
215
  if (Object.keys(primary_key).length !== 1) {
@@ -220,6 +222,7 @@ export class UtilsDynamoDB {
220
222
  }
221
223
  const request : QueryCommandInput = {
222
224
  TableName : table,
225
+ IndexName : index_name,
223
226
  ExpressionAttributeNames: {
224
227
  "#a": key
225
228
  },
@@ -237,10 +240,12 @@ export class UtilsDynamoDB {
237
240
  primary_key : Record<string, any>,
238
241
  secondary_key_prefix : Record<string, string>,
239
242
  options : {
243
+ index_name? : string,
240
244
  reverse? : boolean,
241
245
  compile? : boolean
242
246
  } = {}
243
247
  ) : Promise<Record<string, any>[]>{
248
+ const index_name = options.index_name !== undefined ? options.index_name : undefined
244
249
  const reverse = options.reverse !== undefined ? options.reverse : false
245
250
  const compile = options.compile !== undefined ? options.compile : true
246
251
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_prefix).length !== 1) {
@@ -253,6 +258,7 @@ export class UtilsDynamoDB {
253
258
  }
254
259
  const request : QueryCommandInput = {
255
260
  TableName : table,
261
+ IndexName : index_name,
256
262
  ExpressionAttributeNames: {
257
263
  "#a": Object.keys(primary_key)[0],
258
264
  "#b": Object.keys(secondary_key_prefix)[0]
@@ -272,10 +278,12 @@ export class UtilsDynamoDB {
272
278
  primary_key : Record<string, any>,
273
279
  secondary_key_range : Record<string, (string|number)[]>,
274
280
  options : {
281
+ index_name? : string,
275
282
  reverse? : boolean,
276
283
  compile? : boolean
277
284
  } = {}
278
285
  ) : Promise<Record<string, any>[]>{
286
+ const index_name = options.index_name !== undefined ? options.index_name : undefined
279
287
  const reverse = options.reverse !== undefined ? options.reverse : false
280
288
  const compile = options.compile !== undefined ? options.compile : true
281
289
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
@@ -289,6 +297,7 @@ export class UtilsDynamoDB {
289
297
  }
290
298
  const request : QueryCommandInput = {
291
299
  TableName : table,
300
+ IndexName : index_name,
292
301
  ExpressionAttributeNames: {
293
302
  "#a": Object.keys(primary_key)[0],
294
303
  "#b": Object.keys(secondary_key_range)[0]
package/src/UtilsS3.ts CHANGED
@@ -58,6 +58,26 @@ export class UtilsS3 {
58
58
  }
59
59
  }
60
60
 
61
+ async get_file_stream(s3_filename : string) {
62
+ const s3_key = parse_s3_filename(s3_filename)
63
+ if (s3_key === undefined) {
64
+ return undefined
65
+ }
66
+ try {
67
+ const response = await this.s3.getObject(s3_key)
68
+ const body = response.Body
69
+ if (body === undefined) {
70
+ return undefined
71
+ }
72
+ return body
73
+ } catch (error) {
74
+ if (error instanceof NoSuchKey) {
75
+ return undefined
76
+ }
77
+ throw error
78
+ }
79
+ }
80
+
61
81
  async create_file(s3_filename : string, content : string | Buffer, options : {
62
82
  content_type? : string
63
83
  } = {}) {