triangle-utils 1.4.183 → 1.4.184

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,11 +1,14 @@
1
1
  export declare class UtilsRDS {
2
- private readonly rds_host;
2
+ private readonly rds_cluster_host;
3
+ private readonly rds_reader_host;
3
4
  private readonly rds_username;
4
5
  private readonly rds_password;
5
- private readonly pool;
6
- constructor(rds_host: string, rds_username: string, rds_password: string);
6
+ private readonly cluster_pool;
7
+ private readonly reader_pool;
8
+ constructor(rds_cluster_host: string, rds_reader_host: string, rds_username: string, rds_password: string);
7
9
  exec(sql: string, options?: {
8
10
  is_verbose?: boolean;
11
+ is_read?: boolean;
9
12
  }): Promise<any[]>;
10
13
  scan(table_id: string, options?: {
11
14
  filters?: Record<string, any>;
@@ -14,38 +17,48 @@ export declare class UtilsRDS {
14
17
  attribute_names?: string[];
15
18
  max_num_items?: number;
16
19
  is_verbose?: boolean;
20
+ is_read?: boolean;
17
21
  }): Promise<any[]>;
18
22
  get(table_id: string, primary_key: Record<string, any>, options?: {
19
23
  attribute_names?: string[];
20
24
  is_verbose?: boolean;
25
+ is_read?: boolean;
21
26
  }): Promise<Record<string, any> | undefined>;
22
27
  batch_get(table_id: string, primary_keys: Record<string, any>[], options?: {
23
28
  batch_num_items?: number;
24
29
  attribute_names?: string[];
25
30
  is_verbose?: boolean;
31
+ is_read?: boolean;
26
32
  }): Promise<any[]>;
27
33
  create(table_id: string, item: Record<string, any>, options?: {
28
34
  is_verbose?: boolean;
35
+ is_read?: boolean;
29
36
  }): Promise<any[] | undefined>;
30
37
  batch_create(table_id: string, items: Record<string, any>[], options?: {
31
38
  is_verbose?: boolean;
39
+ is_read?: boolean;
32
40
  batch_num_items?: number;
33
41
  }): Promise<void>;
34
42
  put(table_id: string, item: Record<string, any>, options?: {
35
43
  is_verbose?: boolean;
44
+ is_read?: boolean;
36
45
  }): Promise<any[] | undefined>;
37
46
  batch_put(table_id: string, items: Record<string, any>[], options?: {
38
47
  is_verbose?: boolean;
48
+ is_read?: boolean;
39
49
  batch_num_items?: number;
40
50
  }): Promise<void>;
41
51
  delete(table_id: string, primary_key: Record<string, any>, options?: {
42
52
  is_verbose?: boolean;
53
+ is_read?: boolean;
43
54
  }): Promise<any[]>;
44
55
  batch_delete(table_id: string, primary_keys: Record<string, any>[], options?: {
45
56
  is_verbose?: boolean;
57
+ is_read?: boolean;
46
58
  batch_num_items?: number;
47
59
  }): Promise<void>;
48
60
  set(table_id: string, primary_key: Record<string, any>, attributes: Record<string, any>, options?: {
49
61
  is_verbose?: boolean;
62
+ is_read?: boolean;
50
63
  }): Promise<any[]>;
51
64
  }
@@ -57,16 +57,29 @@ function convert_postgres_output(output, field) {
57
57
  return output[field.name];
58
58
  }
59
59
  export class UtilsRDS {
60
- rds_host;
60
+ rds_cluster_host;
61
+ rds_reader_host;
61
62
  rds_username;
62
63
  rds_password;
63
- pool;
64
- constructor(rds_host, rds_username, rds_password) {
65
- this.rds_host = rds_host;
64
+ cluster_pool;
65
+ reader_pool;
66
+ constructor(rds_cluster_host, rds_reader_host, rds_username, rds_password) {
67
+ this.rds_cluster_host = rds_cluster_host;
68
+ this.rds_reader_host = rds_reader_host;
66
69
  this.rds_username = rds_username;
67
70
  this.rds_password = rds_password;
68
- this.pool = new Pool({
69
- host: this.rds_host,
71
+ this.cluster_pool = new Pool({
72
+ host: this.rds_cluster_host,
73
+ user: this.rds_username,
74
+ password: this.rds_password,
75
+ database: "triangle",
76
+ port: 5432,
77
+ ssl: {
78
+ rejectUnauthorized: false
79
+ }
80
+ });
81
+ this.reader_pool = new Pool({
82
+ host: this.rds_reader_host,
70
83
  user: this.rds_username,
71
84
  password: this.rds_password,
72
85
  database: "triangle",
@@ -78,10 +91,12 @@ export class UtilsRDS {
78
91
  }
79
92
  async exec(sql, options = {}) {
80
93
  const is_verbose = Boolean(options.is_verbose);
94
+ const is_read = Boolean(options.is_read);
81
95
  if (is_verbose) {
82
96
  console.log(sql);
83
97
  }
84
- const response = await this.pool.query(sql);
98
+ const pool = is_read ? this.reader_pool : this.cluster_pool;
99
+ const response = await pool.query(sql);
85
100
  const items = response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
86
101
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
87
102
  if (!Array.isArray(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.scan("states")
86
+ await utils.rds.scan("federal_census_counties", { max_num_items: 1 })
87
87
  .then(console.log);
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.rds_host, config.rds_username, config.rds_password);
34
+ this.rds = new UtilsRDS(config.rds_cluster_host, config.rds_reader_host, config.rds_username, config.rds_password);
35
35
  this.s3 = new UtilsS3(config.region);
36
36
  this.s3vectors = new UtilsS3Vectors(config.region);
37
37
  this.bedrock = new UtilsBedrock(config.region);
@@ -12,7 +12,8 @@ export declare class GlobalConfig {
12
12
  readonly s3_triage: string;
13
13
  readonly rds_cluster_arn: string;
14
14
  readonly rds_secret_arn: string;
15
- readonly rds_host: string;
15
+ readonly rds_cluster_host: string;
16
+ readonly rds_reader_host: string;
16
17
  readonly rds_username: string;
17
18
  readonly rds_password: string;
18
19
  readonly super_federal_gov_api_keys: string;
@@ -12,7 +12,8 @@ export class GlobalConfig {
12
12
  s3_triage;
13
13
  rds_cluster_arn;
14
14
  rds_secret_arn;
15
- rds_host;
15
+ rds_cluster_host;
16
+ rds_reader_host;
16
17
  rds_username;
17
18
  rds_password;
18
19
  super_federal_gov_api_keys;
@@ -43,7 +44,8 @@ export class GlobalConfig {
43
44
  this.s3_triage = global_config.s3_triage;
44
45
  this.rds_cluster_arn = global_config.rds_cluster_arn;
45
46
  this.rds_secret_arn = global_config.rds_secret_arn;
46
- this.rds_host = global_config.rds_host;
47
+ this.rds_cluster_host = global_config.rds_cluster_host;
48
+ this.rds_reader_host = global_config.rds_reader_host;
47
49
  this.rds_username = global_config.rds_username;
48
50
  this.rds_password = global_config.rds_password;
49
51
  this.super_federal_gov_api_keys = global_config.super_federal_gov_api_keys;
@@ -73,7 +75,8 @@ export class GlobalConfig {
73
75
  typeof global_config.s3_triage === "string" &&
74
76
  typeof global_config.rds_cluster_arn === "string" &&
75
77
  typeof global_config.rds_secret_arn === "string" &&
76
- typeof global_config.rds_host === "string" &&
78
+ typeof global_config.rds_cluster_host === "string" &&
79
+ typeof global_config.rds_reader_host === "string" &&
77
80
  typeof global_config.rds_username === "string" &&
78
81
  typeof global_config.rds_password === "string" &&
79
82
  typeof global_config.super_federal_gov_api_keys === "string" &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.183",
3
+ "version": "1.4.184",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -57,21 +57,35 @@ function convert_postgres_output(output : any, field : FieldDef) {
57
57
 
58
58
  export class UtilsRDS {
59
59
 
60
- private readonly rds_host : string
60
+ private readonly rds_cluster_host : string
61
+ private readonly rds_reader_host : string
61
62
  private readonly rds_username : string
62
63
  private readonly rds_password : string
63
- private readonly pool : Pool
64
+ private readonly cluster_pool : Pool
65
+ private readonly reader_pool : Pool
64
66
 
65
67
  constructor(
66
- rds_host : string,
68
+ rds_cluster_host : string,
69
+ rds_reader_host : string,
67
70
  rds_username : string,
68
71
  rds_password : string
69
72
  ) {
70
- this.rds_host = rds_host
73
+ this.rds_cluster_host = rds_cluster_host
74
+ this.rds_reader_host = rds_reader_host
71
75
  this.rds_username = rds_username
72
76
  this.rds_password = rds_password
73
- this.pool = new Pool({
74
- host : this.rds_host,
77
+ this.cluster_pool = new Pool({
78
+ host : this.rds_cluster_host,
79
+ user : this.rds_username,
80
+ password : this.rds_password,
81
+ database : "triangle",
82
+ port : 5432,
83
+ ssl : {
84
+ rejectUnauthorized: false
85
+ }
86
+ })
87
+ this.reader_pool = new Pool({
88
+ host : this.rds_reader_host,
75
89
  user : this.rds_username,
76
90
  password : this.rds_password,
77
91
  database : "triangle",
@@ -85,14 +99,17 @@ export class UtilsRDS {
85
99
  async exec(
86
100
  sql : string,
87
101
  options : {
88
- is_verbose? : boolean
102
+ is_verbose? : boolean,
103
+ is_read? : boolean
89
104
  } = {}
90
105
  ) {
91
106
  const is_verbose = Boolean(options.is_verbose)
107
+ const is_read = Boolean(options.is_read)
92
108
  if (is_verbose) {
93
109
  console.log(sql)
94
110
  }
95
- const response = await this.pool.query(sql)
111
+ const pool = is_read ? this.reader_pool : this.cluster_pool
112
+ const response = await pool.query(sql)
96
113
  const items = response.rows.map(item => Object.fromEntries(
97
114
  response.fields.map(field => [field.name, convert_postgres_output(item, field)])
98
115
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
@@ -114,7 +131,8 @@ export class UtilsRDS {
114
131
  defined_attribute_names? : string[],
115
132
  attribute_names? : string[],
116
133
  max_num_items? : number,
117
- is_verbose? : boolean
134
+ is_verbose? : boolean,
135
+ is_read? : boolean
118
136
  } = {}
119
137
  ) {
120
138
  const undefined_attribute_names = options.undefined_attribute_names || []
@@ -140,7 +158,8 @@ export class UtilsRDS {
140
158
  primary_key : Record<string, any>,
141
159
  options : {
142
160
  attribute_names? : string[],
143
- is_verbose? : boolean
161
+ is_verbose? : boolean,
162
+ is_read? : boolean
144
163
  } = {}
145
164
  ) {
146
165
  const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_postgres_input(value)).join(" AND ")
@@ -155,7 +174,8 @@ export class UtilsRDS {
155
174
  options : {
156
175
  batch_num_items? : number,
157
176
  attribute_names? : string[],
158
- is_verbose? : boolean
177
+ is_verbose? : boolean,
178
+ is_read? : boolean
159
179
  } = {}
160
180
  ) {
161
181
  const batch_num_items = options.batch_num_items || 100
@@ -173,7 +193,8 @@ export class UtilsRDS {
173
193
  table_id : string,
174
194
  item : Record<string, any>,
175
195
  options : {
176
- is_verbose? : boolean
196
+ is_verbose? : boolean,
197
+ is_read? : boolean
177
198
  } = {}
178
199
  ) {
179
200
  const attribute_names = Object.keys(item).sort()
@@ -194,7 +215,8 @@ export class UtilsRDS {
194
215
  table_id : string,
195
216
  items : Record<string, any>[],
196
217
  options : {
197
- is_verbose? : boolean
218
+ is_verbose? : boolean,
219
+ is_read? : boolean
198
220
  batch_num_items? : number
199
221
  } = {}
200
222
  ) {
@@ -221,7 +243,8 @@ export class UtilsRDS {
221
243
  table_id : string,
222
244
  item : Record<string, any>,
223
245
  options : {
224
- is_verbose? : boolean
246
+ is_verbose? : boolean,
247
+ is_read? : boolean
225
248
  } = {}
226
249
  ) {
227
250
  const attribute_names = Object.keys(item).sort()
@@ -243,6 +266,7 @@ export class UtilsRDS {
243
266
  items : Record<string, any>[],
244
267
  options : {
245
268
  is_verbose? : boolean,
269
+ is_read? : boolean,
246
270
  batch_num_items? : number
247
271
  } = {}
248
272
  ) {
@@ -269,7 +293,8 @@ export class UtilsRDS {
269
293
  table_id : string,
270
294
  primary_key : Record<string, any>,
271
295
  options : {
272
- is_verbose? : boolean
296
+ is_verbose? : boolean,
297
+ is_read? : boolean
273
298
  } = {}
274
299
  ) {
275
300
  const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_postgres_input(value)).join(" AND ")
@@ -281,6 +306,7 @@ export class UtilsRDS {
281
306
  primary_keys : Record<string, any>[],
282
307
  options : {
283
308
  is_verbose? : boolean,
309
+ is_read? : boolean,
284
310
  batch_num_items? : number
285
311
  } = {}
286
312
  ) {
@@ -297,7 +323,8 @@ export class UtilsRDS {
297
323
  primary_key : Record<string, any>,
298
324
  attributes : Record<string, any>,
299
325
  options : {
300
- is_verbose? : boolean
326
+ is_verbose? : boolean,
327
+ is_read? : boolean
301
328
  } = {}
302
329
  ) {
303
330
  const attribute_names = Object.keys(attributes).sort()
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.scan("states")
110
+ await utils.rds.scan("federal_census_counties", { max_num_items : 1 })
111
111
  .then(console.log)
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ export class TriangleUtils extends UtilsMisc {
37
37
  constructor(config : GlobalConfig) {
38
38
  super(config)
39
39
  this.dynamodb = new UtilsDynamoDB(config.region)
40
- this.rds = new UtilsRDS(config.rds_host, config.rds_username, config.rds_password)
40
+ this.rds = new UtilsRDS(config.rds_cluster_host, config.rds_reader_host, config.rds_username, config.rds_password)
41
41
  this.s3 = new UtilsS3(config.region)
42
42
  this.s3vectors = new UtilsS3Vectors(config.region)
43
43
  this.bedrock = new UtilsBedrock(config.region)
@@ -12,7 +12,8 @@ export class GlobalConfig {
12
12
  readonly s3_triage : string
13
13
  readonly rds_cluster_arn : string
14
14
  readonly rds_secret_arn : string
15
- readonly rds_host : string
15
+ readonly rds_cluster_host : string
16
+ readonly rds_reader_host : string
16
17
  readonly rds_username : string
17
18
  readonly rds_password : string
18
19
  readonly super_federal_gov_api_keys : string
@@ -45,7 +46,8 @@ export class GlobalConfig {
45
46
  this.s3_triage = global_config.s3_triage
46
47
  this.rds_cluster_arn = global_config.rds_cluster_arn
47
48
  this.rds_secret_arn = global_config.rds_secret_arn
48
- this.rds_host = global_config.rds_host
49
+ this.rds_cluster_host = global_config.rds_cluster_host
50
+ this.rds_reader_host = global_config.rds_reader_host
49
51
  this.rds_username = global_config.rds_username
50
52
  this.rds_password = global_config.rds_password
51
53
  this.super_federal_gov_api_keys = global_config.super_federal_gov_api_keys
@@ -77,7 +79,8 @@ export class GlobalConfig {
77
79
  typeof global_config.s3_triage === "string" &&
78
80
  typeof global_config.rds_cluster_arn === "string" &&
79
81
  typeof global_config.rds_secret_arn === "string" &&
80
- typeof global_config.rds_host === "string" &&
82
+ typeof global_config.rds_cluster_host === "string" &&
83
+ typeof global_config.rds_reader_host === "string" &&
81
84
  typeof global_config.rds_username === "string" &&
82
85
  typeof global_config.rds_password === "string" &&
83
86
  typeof global_config.super_federal_gov_api_keys === "string" &&