triangle-utils 1.4.178 → 1.4.180

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.
@@ -3,10 +3,7 @@ export declare class UtilsRDS {
3
3
  private readonly rds_username;
4
4
  private readonly rds_password;
5
5
  private readonly pool;
6
- constructor(region: string, rds_cluster_arn: string, rds_secret_arn: string, rds_host: string, rds_username: string, rds_password: string);
7
- query(sql: string, options?: {
8
- is_verbose?: boolean;
9
- }): Promise<any[]>;
6
+ constructor(rds_host: string, rds_username: string, rds_password: string);
10
7
  exec(sql: string, options?: {
11
8
  is_verbose?: boolean;
12
9
  }): Promise<any[]>;
@@ -1,4 +1,5 @@
1
1
  import { Pool } from "pg";
2
+ import wkx from "wkx";
2
3
  function convert_postgres_input(input) {
3
4
  if (input === undefined) {
4
5
  return "NULL";
@@ -16,8 +17,8 @@ function convert_postgres_input(input) {
16
17
  return "ARRAY[" + input.map(a => convert_postgres_input(a)).join(", ") + "]";
17
18
  }
18
19
  else if (typeof input === "object") {
19
- if (input.expression !== undefined) {
20
- return input.expression;
20
+ if (input.wkt !== undefined) {
21
+ return "ST_GEOMFROMTEXT('" + input.wkt + "')";
21
22
  }
22
23
  }
23
24
  return "NULL";
@@ -50,6 +51,9 @@ function convert_postgres_output(output, field) {
50
51
  if (field.dataTypeID === 712048) {
51
52
  return JSON.parse(output[field.name]);
52
53
  }
54
+ if (field.dataTypeID === 110963) {
55
+ return { wkt: wkx.Geometry.parse(output[field.name]).toWkt() };
56
+ }
53
57
  return output[field.name];
54
58
  }
55
59
  export class UtilsRDS {
@@ -57,7 +61,7 @@ export class UtilsRDS {
57
61
  rds_username;
58
62
  rds_password;
59
63
  pool;
60
- constructor(region, rds_cluster_arn, rds_secret_arn, rds_host, rds_username, rds_password) {
64
+ constructor(rds_host, rds_username, rds_password) {
61
65
  this.rds_host = rds_host;
62
66
  this.rds_username = rds_username;
63
67
  this.rds_password = rds_password;
@@ -72,21 +76,14 @@ export class UtilsRDS {
72
76
  }
73
77
  });
74
78
  }
75
- async query(sql, options = {}) {
79
+ async exec(sql, options = {}) {
76
80
  const is_verbose = Boolean(options.is_verbose);
77
81
  if (is_verbose) {
78
82
  console.log(sql);
79
83
  }
80
84
  const response = await this.pool.query(sql);
81
- return response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
85
+ const items = response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
82
86
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
83
- }
84
- async exec(sql, options = {}) {
85
- const is_verbose = Boolean(options.is_verbose);
86
- if (is_verbose) {
87
- console.log(sql);
88
- }
89
- const items = await this.query(sql, options);
90
87
  if (!Array.isArray(items)) {
91
88
  if (is_verbose) {
92
89
  console.log("Bad items:", items);
package/dist/src/f.js CHANGED
@@ -83,5 +83,5 @@ const utils = new TriangleUtils(config);
83
83
  // .then(response => console.log(response))
84
84
  // await utils.s3.get_download_url("s3://triangle-675045717295-us-east-1-an/tenant_documents/a3a9627f-a94d-4d47-a110-307a6f5563af/a146d789-da40-4e3c-a132-8b7110f3f7df.pdf", { name : "hye.pdf" })
85
85
  // .then(response => console.log(response))
86
- await utils.rds.query("SELECT * FROM twitter_tweets LIMIT 10")
86
+ await utils.rds.scan("state_voters", { max_num_items: 1, attribute_names: ["address_residence_geom"] })
87
87
  .then(console.log);
@@ -12,7 +12,6 @@ import { UtilsAnthropic } from "./UtilsAnthropic.js";
12
12
  import { UtilsTwitter } from "./UtilsTwitter.js";
13
13
  import { GlobalConfig } from "./types/GlobalConfig.js";
14
14
  import { UtilsRDS } from "./UtilsRDS.js";
15
- import { ApplicationConfig } from "./types/ApplicationConfig.js";
16
15
  import { UtilsTextract } from "./UtilsTextract.js";
17
16
  import { UtilsBrave } from "./UtilsBrave.js";
18
17
  export declare class TriangleUtils extends UtilsMisc {
@@ -30,9 +29,8 @@ export declare class TriangleUtils extends UtilsMisc {
30
29
  readonly anthropic: UtilsAnthropic;
31
30
  readonly xai: UtilsXAI;
32
31
  readonly twitter: UtilsTwitter;
33
- constructor(config: ApplicationConfig & GlobalConfig);
32
+ constructor(config: GlobalConfig);
34
33
  }
35
- export * from "./types/ApplicationConfig.js";
36
34
  export * from "./types/GlobalConfig.js";
37
35
  export * from "./UtilsAnthropic.js";
38
36
  export * from "./UtilsDynamoDB.js";
package/dist/src/index.js CHANGED
@@ -31,7 +31,7 @@ export class TriangleUtils extends UtilsMisc {
31
31
  constructor(config) {
32
32
  super(config);
33
33
  this.dynamodb = new UtilsDynamoDB(config.region);
34
- this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn, config.rds_host, config.rds_username, config.rds_password);
34
+ this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn);
35
35
  this.s3 = new UtilsS3(config.region);
36
36
  this.s3vectors = new UtilsS3Vectors(config.region);
37
37
  this.bedrock = new UtilsBedrock(config.region);
@@ -46,7 +46,6 @@ export class TriangleUtils extends UtilsMisc {
46
46
  this.twitter = new UtilsTwitter(config.twitter_api_key);
47
47
  }
48
48
  }
49
- export * from "./types/ApplicationConfig.js";
50
49
  export * from "./types/GlobalConfig.js";
51
50
  export * from "./UtilsAnthropic.js";
52
51
  export * from "./UtilsDynamoDB.js";
@@ -1,6 +1,8 @@
1
1
  export declare class GlobalConfig {
2
2
  readonly region: string;
3
3
  readonly cognito_user_pool_id: string;
4
+ readonly cognito_client_id: string;
5
+ readonly cognito_client_secret: string;
4
6
  readonly secret_key: string;
5
7
  readonly auth_url: string;
6
8
  readonly s3_triangle: string;
@@ -20,6 +22,7 @@ export declare class GlobalConfig {
20
22
  readonly scraping_bee_api_key: string;
21
23
  readonly twitter_api_key: string;
22
24
  readonly youtube_api_key: string;
25
+ readonly anthropic_api_key: string;
23
26
  readonly xai_api_key: string;
24
27
  readonly ballotpedia_api_key: string;
25
28
  readonly brave_api_key: string;
@@ -1,6 +1,8 @@
1
1
  export class GlobalConfig {
2
2
  region;
3
3
  cognito_user_pool_id;
4
+ cognito_client_id;
5
+ cognito_client_secret;
4
6
  secret_key;
5
7
  auth_url;
6
8
  s3_triangle;
@@ -20,6 +22,7 @@ export class GlobalConfig {
20
22
  scraping_bee_api_key;
21
23
  twitter_api_key;
22
24
  youtube_api_key;
25
+ anthropic_api_key;
23
26
  xai_api_key;
24
27
  ballotpedia_api_key;
25
28
  brave_api_key;
@@ -29,6 +32,8 @@ export class GlobalConfig {
29
32
  }
30
33
  this.region = global_config.region;
31
34
  this.cognito_user_pool_id = global_config.cognito_user_pool_id;
35
+ this.cognito_client_id = global_config.cognito_client_id;
36
+ this.cognito_client_secret = global_config.cognito_client_secret;
32
37
  this.secret_key = global_config.secret_key;
33
38
  this.auth_url = global_config.auth_url;
34
39
  this.s3_triangle = global_config.s3_triangle;
@@ -48,6 +53,7 @@ export class GlobalConfig {
48
53
  this.scraping_bee_api_key = global_config.scraping_bee_api_key;
49
54
  this.twitter_api_key = global_config.twitter_api_key;
50
55
  this.youtube_api_key = global_config.youtube_api_key;
56
+ this.anthropic_api_key = global_config.anthropic_api_key;
51
57
  this.xai_api_key = global_config.xai_api_key;
52
58
  this.ballotpedia_api_key = global_config.ballotpedia_api_key;
53
59
  this.brave_api_key = global_config.brave_api_key;
@@ -56,6 +62,8 @@ export class GlobalConfig {
56
62
  return (global_config !== undefined &&
57
63
  typeof global_config.region === "string" &&
58
64
  typeof global_config.cognito_user_pool_id === "string" &&
65
+ typeof global_config.cognito_client_id === "string" &&
66
+ typeof global_config.cognito_client_secret === "string" &&
59
67
  typeof global_config.secret_key === "string" &&
60
68
  typeof global_config.auth_url === "string" &&
61
69
  typeof global_config.s3_triangle === "string" &&
@@ -75,6 +83,7 @@ export class GlobalConfig {
75
83
  typeof global_config.scraping_bee_api_key === "string" &&
76
84
  typeof global_config.twitter_api_key === "string" &&
77
85
  typeof global_config.youtube_api_key === "string" &&
86
+ typeof global_config.anthropic_api_key === "string" &&
78
87
  typeof global_config.xai_api_key === "string" &&
79
88
  typeof global_config.ballotpedia_api_key === "string" &&
80
89
  typeof global_config.brave_api_key === "string");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.178",
3
+ "version": "1.4.180",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -36,7 +36,8 @@
36
36
  "googleapis": "^170.0.0",
37
37
  "jsdom": "^29.0.1",
38
38
  "pg": "^8.23.0",
39
- "scrapingbee": "^1.8.2"
39
+ "scrapingbee": "^1.8.2",
40
+ "wkx": "^0.5.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@eslint/js": "^9.39.2",
package/src/UtilsRDS.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FieldDef, Pool } from "pg"
2
+ import wkx from "wkx"
2
3
 
3
4
  function convert_postgres_input(input : string | boolean | number | any[] | Record<string, any> | undefined) : string {
4
5
  if (input === undefined) {
@@ -12,8 +13,8 @@ function convert_postgres_input(input : string | boolean | number | any[] | Reco
12
13
  } else if (Array.isArray(input)) {
13
14
  return "ARRAY[" + input.map(a => convert_postgres_input(a)).join(", ") + "]"
14
15
  } else if (typeof input === "object") {
15
- if (input.expression !== undefined) {
16
- return input.expression
16
+ if (input.wkt !== undefined) {
17
+ return "ST_GEOMFROMTEXT('" + input.wkt + "')"
17
18
  }
18
19
  }
19
20
  return "NULL"
@@ -48,6 +49,9 @@ function convert_postgres_output(output : any, field : FieldDef) {
48
49
  if (field.dataTypeID === 712048) {
49
50
  return JSON.parse(output[field.name])
50
51
  }
52
+ if (field.dataTypeID === 110963) {
53
+ return { wkt : wkx.Geometry.parse(output[field.name]).toWkt() }
54
+ }
51
55
  return output[field.name]
52
56
  }
53
57
 
@@ -59,9 +63,6 @@ export class UtilsRDS {
59
63
  private readonly pool : Pool
60
64
 
61
65
  constructor(
62
- region : string,
63
- rds_cluster_arn : string,
64
- rds_secret_arn : string,
65
66
  rds_host : string,
66
67
  rds_username : string,
67
68
  rds_password : string
@@ -81,7 +82,7 @@ export class UtilsRDS {
81
82
  })
82
83
  }
83
84
 
84
- async query(
85
+ async exec(
85
86
  sql : string,
86
87
  options : {
87
88
  is_verbose? : boolean
@@ -92,23 +93,10 @@ export class UtilsRDS {
92
93
  console.log(sql)
93
94
  }
94
95
  const response = await this.pool.query(sql)
95
- return response.rows.map(item => Object.fromEntries(
96
+ const items = response.rows.map(item => Object.fromEntries(
96
97
  response.fields.map(field => [field.name, convert_postgres_output(item, field)])
97
98
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
98
99
  ))
99
- }
100
-
101
- async exec(
102
- sql : string,
103
- options : {
104
- is_verbose? : boolean
105
- } = {}
106
- ) {
107
- const is_verbose = Boolean(options.is_verbose)
108
- if (is_verbose) {
109
- console.log(sql)
110
- }
111
- const items = await this.query(sql, options)
112
100
  if (!Array.isArray(items)) {
113
101
  if (is_verbose) {
114
102
  console.log("Bad items:", items)
package/src/f.ts CHANGED
@@ -107,5 +107,5 @@ const utils = new TriangleUtils(config)
107
107
  // .then(response => console.log(response))
108
108
 
109
109
 
110
- await utils.rds.query("SELECT * FROM twitter_tweets LIMIT 10")
110
+ await utils.rds.scan("state_voters", { max_num_items : 1, attribute_names : ["address_residence_geom"]})
111
111
  .then(console.log)
package/src/index.ts CHANGED
@@ -12,7 +12,6 @@ import { UtilsAnthropic } from "./UtilsAnthropic"
12
12
  import { UtilsTwitter } from "./UtilsTwitter"
13
13
  import { GlobalConfig } from "./types/GlobalConfig"
14
14
  import { UtilsRDS } from "./UtilsRDS"
15
- import { ApplicationConfig } from "./types/ApplicationConfig"
16
15
  import { UtilsTextract } from "./UtilsTextract"
17
16
  import { UtilsBrave } from "./UtilsBrave"
18
17
 
@@ -35,10 +34,10 @@ export class TriangleUtils extends UtilsMisc {
35
34
  readonly xai : UtilsXAI
36
35
  readonly twitter : UtilsTwitter
37
36
 
38
- constructor(config : ApplicationConfig & GlobalConfig) {
37
+ constructor(config : GlobalConfig) {
39
38
  super(config)
40
39
  this.dynamodb = new UtilsDynamoDB(config.region)
41
- this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn, config.rds_host, config.rds_username, config.rds_password)
40
+ this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn)
42
41
  this.s3 = new UtilsS3(config.region)
43
42
  this.s3vectors = new UtilsS3Vectors(config.region)
44
43
  this.bedrock = new UtilsBedrock(config.region)
@@ -54,7 +53,6 @@ export class TriangleUtils extends UtilsMisc {
54
53
  }
55
54
  }
56
55
 
57
- export * from "./types/ApplicationConfig"
58
56
  export * from "./types/GlobalConfig"
59
57
  export * from "./UtilsAnthropic"
60
58
  export * from "./UtilsDynamoDB"
@@ -1,6 +1,8 @@
1
1
  export class GlobalConfig {
2
2
  readonly region : string
3
3
  readonly cognito_user_pool_id : string
4
+ readonly cognito_client_id : string
5
+ readonly cognito_client_secret : string
4
6
  readonly secret_key : string
5
7
  readonly auth_url : string
6
8
  readonly s3_triangle : string
@@ -20,6 +22,7 @@ export class GlobalConfig {
20
22
  readonly scraping_bee_api_key : string
21
23
  readonly twitter_api_key : string
22
24
  readonly youtube_api_key : string
25
+ readonly anthropic_api_key : string
23
26
  readonly xai_api_key : string
24
27
  readonly ballotpedia_api_key : string
25
28
  readonly brave_api_key : string
@@ -31,6 +34,8 @@ export class GlobalConfig {
31
34
  }
32
35
  this.region = global_config.region
33
36
  this.cognito_user_pool_id = global_config.cognito_user_pool_id
37
+ this.cognito_client_id = global_config.cognito_client_id
38
+ this.cognito_client_secret = global_config.cognito_client_secret
34
39
  this.secret_key = global_config.secret_key
35
40
  this.auth_url = global_config.auth_url
36
41
  this.s3_triangle = global_config.s3_triangle
@@ -50,6 +55,7 @@ export class GlobalConfig {
50
55
  this.scraping_bee_api_key = global_config.scraping_bee_api_key
51
56
  this.twitter_api_key = global_config.twitter_api_key
52
57
  this.youtube_api_key = global_config.youtube_api_key
58
+ this.anthropic_api_key = global_config.anthropic_api_key
53
59
  this.xai_api_key = global_config.xai_api_key
54
60
  this.ballotpedia_api_key = global_config.ballotpedia_api_key
55
61
  this.brave_api_key = global_config.brave_api_key
@@ -60,6 +66,8 @@ export class GlobalConfig {
60
66
  global_config !== undefined &&
61
67
  typeof global_config.region === "string" &&
62
68
  typeof global_config.cognito_user_pool_id === "string" &&
69
+ typeof global_config.cognito_client_id === "string" &&
70
+ typeof global_config.cognito_client_secret === "string" &&
63
71
  typeof global_config.secret_key === "string" &&
64
72
  typeof global_config.auth_url === "string" &&
65
73
  typeof global_config.s3_triangle === "string" &&
@@ -79,6 +87,7 @@ export class GlobalConfig {
79
87
  typeof global_config.scraping_bee_api_key === "string" &&
80
88
  typeof global_config.twitter_api_key === "string" &&
81
89
  typeof global_config.youtube_api_key === "string" &&
90
+ typeof global_config.anthropic_api_key === "string" &&
82
91
  typeof global_config.xai_api_key === "string" &&
83
92
  typeof global_config.ballotpedia_api_key === "string" &&
84
93
  typeof global_config.brave_api_key === "string"
@@ -1,25 +0,0 @@
1
-
2
- export class ApplicationConfig {
3
- readonly cognito_client_id : string
4
- readonly cognito_client_secret : string
5
- readonly anthropic_api_key? : string
6
- readonly [x : string] : any
7
-
8
- constructor(application_config : ApplicationConfig) {
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.anthropic_api_key = application_config.anthropic_api_key
15
- }
16
-
17
- static is(application_config : any) : application_config is ApplicationConfig {
18
- return (
19
- application_config !== undefined &&
20
- typeof application_config.cognito_client_id === "string" &&
21
- typeof application_config.cognito_client_secret === "string" &&
22
- (application_config.anthropic_api_key === undefined || typeof application_config.anthropic_api_key === "string")
23
- )
24
- }
25
- }