triangle-utils 1.4.72 → 1.4.74

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.
@@ -19,6 +19,7 @@ export declare class UtilsDynamoDB {
19
19
  undefined_attribute_names?: string[];
20
20
  defined_attribute_names?: string[];
21
21
  attribute_names?: string[];
22
+ max_num_items?: number;
22
23
  }): Promise<Record<string, any>[]>;
23
24
  query_prefix(table_index_name: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
24
25
  reverse?: boolean;
@@ -27,6 +28,7 @@ export declare class UtilsDynamoDB {
27
28
  undefined_attribute_names?: string[];
28
29
  defined_attribute_names?: string[];
29
30
  attribute_names?: string[];
31
+ max_num_items?: number;
30
32
  }): Promise<Record<string, any>[]>;
31
33
  query_range(table_index_name: string, primary_key: Record<string, any>, secondary_key_range: Record<string, (string | number)[]>, options?: {
32
34
  reverse?: boolean;
@@ -35,6 +37,7 @@ export declare class UtilsDynamoDB {
35
37
  undefined_attribute_names?: string[];
36
38
  defined_attribute_names?: string[];
37
39
  attribute_names?: string[];
40
+ max_num_items?: number;
38
41
  }): Promise<Record<string, any>[]>;
39
42
  set(table_name: string, key: Record<string, any>, attributes: Record<string, any>): Promise<void>;
40
43
  append(table_name: string, key: Record<string, any>, attributes: Record<string, any[]>): Promise<void>;
@@ -227,7 +227,8 @@ export class UtilsDynamoDB {
227
227
  FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
228
228
  ProjectionExpression: projection_expression.length > 0 ? projection_expression : undefined,
229
229
  KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
230
- ScanIndexForward: !reverse
230
+ ScanIndexForward: !reverse,
231
+ Limit: options.max_num_items
231
232
  };
232
233
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
233
234
  // .then(async items => index_name === undefined || !project ? items :
@@ -287,7 +288,8 @@ export class UtilsDynamoDB {
287
288
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
288
289
  ...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
289
290
  ].join(" AND "),
290
- ScanIndexForward: !reverse
291
+ ScanIndexForward: !reverse,
292
+ Limit: options.max_num_items
291
293
  };
292
294
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
293
295
  // .then(async items => index_name === undefined || !project ? items :
@@ -350,7 +352,8 @@ export class UtilsDynamoDB {
350
352
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
351
353
  ...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
352
354
  ].join(" AND "),
353
- ScanIndexForward: !reverse
355
+ ScanIndexForward: !reverse,
356
+ Limit: options.max_num_items
354
357
  };
355
358
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile);
356
359
  // .then(async items => index_name === undefined || !project ? items :
@@ -1,11 +1,11 @@
1
- import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig.js";
1
+ import { GlobalConfig } from "./types/GlobalConfig.js";
2
2
  interface Encryption {
3
3
  iv: string;
4
4
  ciphertext: string;
5
5
  }
6
6
  export declare class UtilsMisc {
7
- readonly config: TriangleUtilsConfig;
8
- constructor(config: TriangleUtilsConfig);
7
+ readonly config: GlobalConfig;
8
+ constructor(config: GlobalConfig);
9
9
  safe_run<T>(f: () => Promise<T>): Promise<T | undefined>;
10
10
  iterate<T, U>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<U>, num_iterators?: number, print_option?: number | boolean): Promise<(U | undefined)[]>;
11
11
  static wait(duration: number): Promise<unknown>;
@@ -1,4 +1,3 @@
1
- import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig.js";
2
1
  import { UtilsDynamoDB } from "./UtilsDynamoDB.js";
3
2
  import { UtilsS3 } from "./UtilsS3.js";
4
3
  import { UtilsBedrock } from "./UtilsBedrock.js";
@@ -11,6 +10,7 @@ import { UtilsYoutube } from "./UtilsYoutube.js";
11
10
  import { UtilsXAI } from "./UtilsXAI.js";
12
11
  import { UtilsAnthropic } from "./UtilsAnthropic.js";
13
12
  import { UtilsTwitter } from "./UtilsTwitter.js";
13
+ import { GlobalConfig } from "./types/GlobalConfig.js";
14
14
  export declare class TriangleUtils extends UtilsMisc {
15
15
  readonly dynamodb: UtilsDynamoDB;
16
16
  readonly s3: UtilsS3;
@@ -23,9 +23,10 @@ export declare class TriangleUtils extends UtilsMisc {
23
23
  readonly anthropic: UtilsAnthropic;
24
24
  readonly xai: UtilsXAI;
25
25
  readonly twitter: UtilsTwitter;
26
- constructor(config: TriangleUtilsConfig);
26
+ constructor(config: GlobalConfig);
27
27
  }
28
- export * from "./types/TriangleUtilsConfig.js";
28
+ export * from "./types/ApplicationConfig.js";
29
+ export * from "./types/GlobalConfig.js";
29
30
  export * from "./UtilsMisc.js";
30
31
  export * from "./UtilsAnthropic.js";
31
32
  export * from "./UtilsDynamoDB.js";
package/dist/src/index.js CHANGED
@@ -37,7 +37,8 @@ export class TriangleUtils extends UtilsMisc {
37
37
  this.twitter = new UtilsTwitter(config.twitter_api_key);
38
38
  }
39
39
  }
40
- export * from "./types/TriangleUtilsConfig.js";
40
+ export * from "./types/ApplicationConfig.js";
41
+ export * from "./types/GlobalConfig.js";
41
42
  export * from "./UtilsMisc.js";
42
43
  export * from "./UtilsAnthropic.js";
43
44
  export * from "./UtilsDynamoDB.js";
@@ -0,0 +1,11 @@
1
+ export declare class ApplicationConfig {
2
+ readonly cognito_client_id: string;
3
+ readonly cognito_client_secret: string;
4
+ readonly client_url: string;
5
+ readonly client_dev_url: string;
6
+ readonly api_url: string;
7
+ readonly api_dev_url: string;
8
+ readonly [x: string]: any;
9
+ constructor(application_config: ApplicationConfig);
10
+ static is(application_config: any): application_config is ApplicationConfig;
11
+ }
@@ -0,0 +1,28 @@
1
+ export class ApplicationConfig {
2
+ cognito_client_id;
3
+ cognito_client_secret;
4
+ client_url;
5
+ client_dev_url;
6
+ api_url;
7
+ api_dev_url;
8
+ constructor(application_config) {
9
+ if (!ApplicationConfig.is(application_config)) {
10
+ throw Error("Invalid input.");
11
+ }
12
+ this.cognito_client_id = application_config.cognito_client_id;
13
+ this.cognito_client_secret = application_config.cognito_client_secret;
14
+ this.client_url = application_config.client_url;
15
+ this.client_dev_url = application_config.client_dev_url;
16
+ this.api_url = application_config.api_url;
17
+ this.api_dev_url = application_config.api_dev_url;
18
+ }
19
+ static is(application_config) {
20
+ return (application_config !== undefined &&
21
+ typeof application_config.cognito_client_id === "string" &&
22
+ typeof application_config.cognito_client_secret === "string" &&
23
+ typeof application_config.client_url === "string" &&
24
+ typeof application_config.client_dev_url === "string" &&
25
+ typeof application_config.api_url === "string" &&
26
+ typeof application_config.api_dev_url === "string");
27
+ }
28
+ }
@@ -0,0 +1,20 @@
1
+ export declare class GlobalConfig {
2
+ readonly region: string;
3
+ readonly cognito_user_pool_id: string;
4
+ readonly secret_key: string;
5
+ readonly auth_url: string;
6
+ readonly s3_elections: string;
7
+ readonly s3_prism: string;
8
+ readonly s3_triage: string;
9
+ readonly super_federal_gov_api_keys: string;
10
+ readonly federal_gov_api_keys: string;
11
+ readonly federal_lobby_api_key: string;
12
+ readonly scraping_bee_api_key: string;
13
+ readonly twitter_api_key: string;
14
+ readonly youtube_api_key: string;
15
+ readonly anthropic_api_key: string;
16
+ readonly xai_api_key: string;
17
+ readonly [x: string]: any;
18
+ constructor(global_config: GlobalConfig);
19
+ static is(global_config: any): global_config is GlobalConfig;
20
+ }
@@ -0,0 +1,55 @@
1
+ export class GlobalConfig {
2
+ region;
3
+ cognito_user_pool_id;
4
+ secret_key;
5
+ auth_url;
6
+ s3_elections;
7
+ s3_prism;
8
+ s3_triage;
9
+ super_federal_gov_api_keys;
10
+ federal_gov_api_keys;
11
+ federal_lobby_api_key;
12
+ scraping_bee_api_key;
13
+ twitter_api_key;
14
+ youtube_api_key;
15
+ anthropic_api_key;
16
+ xai_api_key;
17
+ constructor(global_config) {
18
+ if (!GlobalConfig.is(global_config)) {
19
+ throw Error("Invalid input.");
20
+ }
21
+ this.region = global_config.region;
22
+ this.cognito_user_pool_id = global_config.cognito_user_pool_id;
23
+ this.secret_key = global_config.secret_key;
24
+ this.auth_url = global_config.auth_url;
25
+ this.s3_elections = global_config.s3_elections;
26
+ this.s3_prism = global_config.s3_prism;
27
+ this.s3_triage = global_config.s3_triage;
28
+ this.super_federal_gov_api_keys = global_config.super_federal_gov_api_keys;
29
+ this.federal_gov_api_keys = global_config.federal_gov_api_keys;
30
+ this.federal_lobby_api_key = global_config.federal_lobby_api_key;
31
+ this.scraping_bee_api_key = global_config.scraping_bee_api_key;
32
+ this.twitter_api_key = global_config.twitter_api_key;
33
+ this.youtube_api_key = global_config.youtube_api_key;
34
+ this.anthropic_api_key = global_config.anthropic_api_key;
35
+ this.xai_api_key = global_config.xai_api_key;
36
+ }
37
+ static is(global_config) {
38
+ return (global_config !== undefined &&
39
+ typeof global_config.region === "string" &&
40
+ typeof global_config.cognito_user_pool_id === "string" &&
41
+ typeof global_config.secret_key === "string" &&
42
+ typeof global_config.auth_url === "string" &&
43
+ typeof global_config.s3_elections === "string" &&
44
+ typeof global_config.s3_prism === "string" &&
45
+ typeof global_config.s3_triage === "string" &&
46
+ typeof global_config.super_federal_gov_api_keys === "string" &&
47
+ typeof global_config.federal_gov_api_keys === "string" &&
48
+ typeof global_config.federal_lobby_api_key === "string" &&
49
+ typeof global_config.scraping_bee_api_key === "string" &&
50
+ typeof global_config.twitter_api_key === "string" &&
51
+ typeof global_config.youtube_api_key === "string" &&
52
+ typeof global_config.anthropic_api_key === "string" &&
53
+ typeof global_config.xai_api_key === "string");
54
+ }
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.72",
3
+ "version": "1.4.74",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -231,7 +231,8 @@ export class UtilsDynamoDB {
231
231
  filters? : Record<string, any>,
232
232
  undefined_attribute_names? : string[],
233
233
  defined_attribute_names? : string[],
234
- attribute_names? : string[]
234
+ attribute_names? : string[],
235
+ max_num_items? : number
235
236
  } = {}
236
237
  ) : Promise<Record<string, any>[]>{
237
238
  const table_name : string = table_index_name.split(":")[0]
@@ -275,7 +276,8 @@ export class UtilsDynamoDB {
275
276
  FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,
276
277
  ProjectionExpression : projection_expression.length > 0 ? projection_expression : undefined,
277
278
  KeyConditionExpression: Object.keys(primary_key).map(key => "#" + key + " = :" + key).join(" AND "),
278
- ScanIndexForward : !reverse
279
+ ScanIndexForward : !reverse,
280
+ Limit : options.max_num_items
279
281
  }
280
282
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
281
283
  // .then(async items => index_name === undefined || !project ? items :
@@ -300,7 +302,8 @@ export class UtilsDynamoDB {
300
302
  filters? : Record<string, any>,
301
303
  undefined_attribute_names? : string[],
302
304
  defined_attribute_names? : string[],
303
- attribute_names? : string[]
305
+ attribute_names? : string[],
306
+ max_num_items? : number
304
307
  } = {}
305
308
  ) : Promise<Record<string, any>[]>{
306
309
  const table_name : string = table_index_name.split(":")[0]
@@ -351,7 +354,8 @@ export class UtilsDynamoDB {
351
354
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
352
355
  ...Object.keys(secondary_key_prefix).map(key => "begins_with(#" + key + ", :" + key + ")")
353
356
  ].join(" AND "),
354
- ScanIndexForward : !reverse
357
+ ScanIndexForward : !reverse,
358
+ Limit : options.max_num_items
355
359
  }
356
360
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
357
361
  // .then(async items => index_name === undefined || !project ? items :
@@ -376,7 +380,8 @@ export class UtilsDynamoDB {
376
380
  filters? : Record<string, any>,
377
381
  undefined_attribute_names? : string[],
378
382
  defined_attribute_names? : string[],
379
- attribute_names? : string[]
383
+ attribute_names? : string[],
384
+ max_num_items? : number
380
385
  } = {}
381
386
  ) : Promise<Record<string, any>[]>{
382
387
  const table_name : string = table_index_name.split(":")[0]
@@ -430,7 +435,8 @@ export class UtilsDynamoDB {
430
435
  ...Object.keys(primary_key).map(key => "#" + key + " = :" + key),
431
436
  ...Object.keys(secondary_key_range).map(key => "(#" + key + " BETWEEN :" + key + "_min AND :" + key + "_max)")
432
437
  ].join(" AND "),
433
- ScanIndexForward : !reverse
438
+ ScanIndexForward : !reverse,
439
+ Limit : options.max_num_items
434
440
  }
435
441
  const items = await compile_pages(request, (request) => this.dynamodb.query(request), compile)
436
442
  // .then(async items => index_name === undefined || !project ? items :
package/src/UtilsMisc.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as crypto from "crypto"
2
2
 
3
- import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig"
3
+ import { GlobalConfig } from "./types/GlobalConfig"
4
4
 
5
5
  interface Encryption {
6
6
  iv : string,
@@ -9,9 +9,9 @@ interface Encryption {
9
9
 
10
10
  export class UtilsMisc {
11
11
 
12
- readonly config : TriangleUtilsConfig
12
+ readonly config : GlobalConfig
13
13
 
14
- constructor(config : TriangleUtilsConfig) {
14
+ constructor(config : GlobalConfig) {
15
15
  this.config = config
16
16
  }
17
17
 
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { TriangleUtilsConfig } from "./types/TriangleUtilsConfig"
2
1
  import { UtilsDynamoDB } from "./UtilsDynamoDB"
3
2
  import { UtilsS3 } from "./UtilsS3"
4
3
  import { UtilsBedrock } from "./UtilsBedrock"
@@ -11,6 +10,7 @@ import { UtilsYoutube } from "./UtilsYoutube"
11
10
  import { UtilsXAI } from "./UtilsXAI"
12
11
  import { UtilsAnthropic } from "./UtilsAnthropic"
13
12
  import { UtilsTwitter } from "./UtilsTwitter"
13
+ import { GlobalConfig } from "./types/GlobalConfig"
14
14
 
15
15
 
16
16
 
@@ -28,7 +28,7 @@ export class TriangleUtils extends UtilsMisc {
28
28
  readonly xai : UtilsXAI
29
29
  readonly twitter : UtilsTwitter
30
30
 
31
- constructor(config : TriangleUtilsConfig) {
31
+ constructor(config : GlobalConfig) {
32
32
  super(config)
33
33
  this.dynamodb = new UtilsDynamoDB(config.region)
34
34
  this.s3 = new UtilsS3(config.region)
@@ -44,7 +44,8 @@ export class TriangleUtils extends UtilsMisc {
44
44
  }
45
45
  }
46
46
 
47
- export * from "./types/TriangleUtilsConfig"
47
+ export * from "./types/ApplicationConfig"
48
+ export * from "./types/GlobalConfig"
48
49
  export * from "./UtilsMisc"
49
50
  export * from "./UtilsAnthropic"
50
51
  export * from "./UtilsDynamoDB"
@@ -0,0 +1,34 @@
1
+
2
+ export class ApplicationConfig {
3
+ readonly cognito_client_id : string
4
+ readonly cognito_client_secret : string
5
+ readonly client_url : string
6
+ readonly client_dev_url : string
7
+ readonly api_url : string
8
+ readonly api_dev_url : string
9
+ readonly [x : string] : any
10
+
11
+ constructor(application_config : ApplicationConfig) {
12
+ if (!ApplicationConfig.is(application_config)) {
13
+ throw Error("Invalid input.")
14
+ }
15
+ this.cognito_client_id = application_config.cognito_client_id
16
+ this.cognito_client_secret = application_config.cognito_client_secret
17
+ this.client_url = application_config.client_url
18
+ this.client_dev_url = application_config.client_dev_url
19
+ this.api_url = application_config.api_url
20
+ this.api_dev_url = application_config.api_dev_url
21
+ }
22
+
23
+ static is(application_config : any) : application_config is ApplicationConfig {
24
+ return (
25
+ application_config !== undefined &&
26
+ typeof application_config.cognito_client_id === "string" &&
27
+ typeof application_config.cognito_client_secret === "string" &&
28
+ typeof application_config.client_url === "string" &&
29
+ typeof application_config.client_dev_url === "string" &&
30
+ typeof application_config.api_url === "string" &&
31
+ typeof application_config.api_dev_url === "string"
32
+ )
33
+ }
34
+ }
@@ -0,0 +1,60 @@
1
+ export class GlobalConfig {
2
+ readonly region : string
3
+ readonly cognito_user_pool_id : string
4
+ readonly secret_key : string
5
+ readonly auth_url : string
6
+ readonly s3_elections : string
7
+ readonly s3_prism : string
8
+ readonly s3_triage : string
9
+ readonly super_federal_gov_api_keys : string
10
+ readonly federal_gov_api_keys : string
11
+ readonly federal_lobby_api_key : string
12
+ readonly scraping_bee_api_key : string
13
+ readonly twitter_api_key : string
14
+ readonly youtube_api_key : string
15
+ readonly anthropic_api_key : string
16
+ readonly xai_api_key : string
17
+ readonly [x : string] : any
18
+
19
+ constructor(global_config : GlobalConfig) {
20
+ if (!GlobalConfig.is(global_config)) {
21
+ throw Error("Invalid input.")
22
+ }
23
+ this.region = global_config.region
24
+ this.cognito_user_pool_id = global_config.cognito_user_pool_id
25
+ this.secret_key = global_config.secret_key
26
+ this.auth_url = global_config.auth_url
27
+ this.s3_elections = global_config.s3_elections
28
+ this.s3_prism = global_config.s3_prism
29
+ this.s3_triage = global_config.s3_triage
30
+ this.super_federal_gov_api_keys = global_config.super_federal_gov_api_keys
31
+ this.federal_gov_api_keys = global_config.federal_gov_api_keys
32
+ this.federal_lobby_api_key = global_config.federal_lobby_api_key
33
+ this.scraping_bee_api_key = global_config.scraping_bee_api_key
34
+ this.twitter_api_key = global_config.twitter_api_key
35
+ this.youtube_api_key = global_config.youtube_api_key
36
+ this.anthropic_api_key = global_config.anthropic_api_key
37
+ this.xai_api_key = global_config.xai_api_key
38
+ }
39
+
40
+ static is(global_config : any) : global_config is GlobalConfig {
41
+ return (
42
+ global_config !== undefined &&
43
+ typeof global_config.region === "string" &&
44
+ typeof global_config.cognito_user_pool_id === "string" &&
45
+ typeof global_config.secret_key === "string" &&
46
+ typeof global_config.auth_url === "string" &&
47
+ typeof global_config.s3_elections === "string" &&
48
+ typeof global_config.s3_prism === "string" &&
49
+ typeof global_config.s3_triage === "string" &&
50
+ typeof global_config.super_federal_gov_api_keys === "string" &&
51
+ typeof global_config.federal_gov_api_keys === "string" &&
52
+ typeof global_config.federal_lobby_api_key === "string" &&
53
+ typeof global_config.scraping_bee_api_key === "string" &&
54
+ typeof global_config.twitter_api_key === "string" &&
55
+ typeof global_config.youtube_api_key === "string" &&
56
+ typeof global_config.anthropic_api_key === "string" &&
57
+ typeof global_config.xai_api_key === "string"
58
+ )
59
+ }
60
+ }
@@ -1,6 +0,0 @@
1
- export interface TriangleUtilsConfig {
2
- region : string,
3
- scraping_bee_api_key? : string,
4
- youtube_api_key? : string,
5
- [key : string]: any
6
- }