triangle-utils 1.4.149 → 1.4.151
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.
- package/dist/src/UtilsRDS.d.ts +7 -4
- package/dist/src/UtilsRDS.js +30 -21
- package/dist/src/UtilsS3.d.ts +1 -1
- package/dist/src/UtilsS3.js +11 -11
- package/dist/src/UtilsTextract.d.ts +6 -0
- package/dist/src/UtilsTextract.js +45 -0
- package/dist/src/f.js +4 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/package.json +2 -1
- package/src/UtilsRDS.ts +34 -22
- package/src/UtilsS3.ts +11 -11
- package/src/UtilsTextract.ts +50 -0
- package/src/f.ts +7 -1
- package/src/index.ts +3 -0
package/dist/src/UtilsRDS.d.ts
CHANGED
|
@@ -39,7 +39,8 @@ export declare class UtilsRDS {
|
|
|
39
39
|
batch_create(table_id: string, items: Record<string, any>[], options?: {
|
|
40
40
|
is_verbose?: boolean;
|
|
41
41
|
is_forced?: boolean;
|
|
42
|
-
|
|
42
|
+
batch_num_items?: number;
|
|
43
|
+
}): Promise<void>;
|
|
43
44
|
put(table_id: string, item: Record<string, any>, options?: {
|
|
44
45
|
is_verbose?: boolean;
|
|
45
46
|
is_forced?: boolean;
|
|
@@ -47,15 +48,17 @@ export declare class UtilsRDS {
|
|
|
47
48
|
batch_put(table_id: string, items: Record<string, any>[], options?: {
|
|
48
49
|
is_verbose?: boolean;
|
|
49
50
|
is_forced?: boolean;
|
|
50
|
-
|
|
51
|
+
batch_num_items?: number;
|
|
52
|
+
}): Promise<void>;
|
|
51
53
|
delete(table_id: string, primary_key: Record<string, any>, options?: {
|
|
52
54
|
is_verbose?: boolean;
|
|
53
55
|
is_forced?: boolean;
|
|
54
56
|
}): Promise<any[]>;
|
|
55
|
-
batch_delete(table_id: string,
|
|
57
|
+
batch_delete(table_id: string, primary_keys: Record<string, any>[], options?: {
|
|
56
58
|
is_verbose?: boolean;
|
|
57
59
|
is_forced?: boolean;
|
|
58
|
-
|
|
60
|
+
batch_num_items?: number;
|
|
61
|
+
}): Promise<void>;
|
|
59
62
|
set(table_id: string, primary_key: Record<string, any>, attributes: Record<string, any>, options?: {
|
|
60
63
|
is_verbose?: boolean;
|
|
61
64
|
is_forced?: boolean;
|
package/dist/src/UtilsRDS.js
CHANGED
|
@@ -163,15 +163,18 @@ export class UtilsRDS {
|
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
const batch_num_items = options.batch_num_items || 100;
|
|
167
|
+
for (let i = 0; i < items.length; i += batch_num_items) {
|
|
168
|
+
const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_items).map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;";
|
|
169
|
+
try {
|
|
170
|
+
await this.exec(sql, options);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.log(error.stack);
|
|
175
|
+
console.log(sql);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
async put(table_id, item, options = {}) {
|
|
@@ -192,24 +195,30 @@ export class UtilsRDS {
|
|
|
192
195
|
return;
|
|
193
196
|
}
|
|
194
197
|
const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
const items =
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
const batch_num_items = options.batch_num_items || 100;
|
|
199
|
+
for (let i = 0; i < items.length; i += batch_num_items) {
|
|
200
|
+
const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_items).map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO UPDATE SET " + attribute_names.map(attribute_name => attribute_name + " = " + "EXCLUDED." + attribute_name).join(", ") + ";";
|
|
201
|
+
try {
|
|
202
|
+
await this.exec(sql, options);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
console.log(error.stack);
|
|
206
|
+
console.log(sql);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
211
|
async delete(table_id, primary_key, options = {}) {
|
|
207
212
|
const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ");
|
|
208
213
|
return await this.exec(sql, options);
|
|
209
214
|
}
|
|
210
|
-
async batch_delete(table_id,
|
|
211
|
-
const
|
|
212
|
-
|
|
215
|
+
async batch_delete(table_id, primary_keys, options = {}) {
|
|
216
|
+
const batch_num_items = options.batch_num_items || 100;
|
|
217
|
+
const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort();
|
|
218
|
+
for (let i = 0; i < primary_keys.length; i += batch_num_items) {
|
|
219
|
+
const sql = "DELETE FROM " + table_id + " WHERE " + "(" + attribute_names.join(", ") + ")" + " IN " + "(" + primary_keys.map(primary_key => "(" + attribute_names.map(attribute_name => convert_rds_input(primary_key[attribute_name])).join(", ") + ")").join(", ") + ")";
|
|
220
|
+
await this.exec(sql, options);
|
|
221
|
+
}
|
|
213
222
|
}
|
|
214
223
|
async set(table_id, primary_key, attributes, options = {}) {
|
|
215
224
|
const attribute_names = Object.keys(attributes).sort();
|
package/dist/src/UtilsS3.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class UtilsS3 {
|
|
|
8
8
|
private readonly s3;
|
|
9
9
|
constructor(region: string);
|
|
10
10
|
get_client(): S3;
|
|
11
|
-
get_s3_input(s3_id: string): S3Input | undefined;
|
|
11
|
+
static get_s3_input(s3_id: string): S3Input | undefined;
|
|
12
12
|
get_headers(s3_id: string): Promise<{
|
|
13
13
|
DeleteMarker?: boolean | undefined;
|
|
14
14
|
AcceptRanges?: string | undefined;
|
package/dist/src/UtilsS3.js
CHANGED
|
@@ -10,7 +10,7 @@ export class UtilsS3 {
|
|
|
10
10
|
get_client() {
|
|
11
11
|
return this.s3;
|
|
12
12
|
}
|
|
13
|
-
get_s3_input(s3_id) {
|
|
13
|
+
static get_s3_input(s3_id) {
|
|
14
14
|
const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3);
|
|
15
15
|
if (bucket === undefined || path === undefined) {
|
|
16
16
|
return undefined;
|
|
@@ -18,7 +18,7 @@ export class UtilsS3 {
|
|
|
18
18
|
return { Bucket: bucket, Key: path };
|
|
19
19
|
}
|
|
20
20
|
async get_headers(s3_id) {
|
|
21
|
-
const s3_input =
|
|
21
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
22
22
|
if (s3_input === undefined) {
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
@@ -34,7 +34,7 @@ export class UtilsS3 {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async get(s3_id, encoding = "utf-8") {
|
|
37
|
-
const s3_input =
|
|
37
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
38
38
|
if (s3_input === undefined) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
@@ -55,7 +55,7 @@ export class UtilsS3 {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
async get_buffer(s3_id) {
|
|
58
|
-
const s3_input =
|
|
58
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
59
59
|
if (s3_input === undefined) {
|
|
60
60
|
return undefined;
|
|
61
61
|
}
|
|
@@ -76,7 +76,7 @@ export class UtilsS3 {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
async get_stream(s3_id) {
|
|
79
|
-
const s3_input =
|
|
79
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
80
80
|
if (s3_input === undefined) {
|
|
81
81
|
return undefined;
|
|
82
82
|
}
|
|
@@ -100,7 +100,7 @@ export class UtilsS3 {
|
|
|
100
100
|
}
|
|
101
101
|
async query_prefix(s3_id_prefix, options = {}) {
|
|
102
102
|
const compile = options.compile !== undefined ? options.compile : false;
|
|
103
|
-
const s3_input =
|
|
103
|
+
const s3_input = UtilsS3.get_s3_input(s3_id_prefix);
|
|
104
104
|
if (s3_input === undefined) {
|
|
105
105
|
return [];
|
|
106
106
|
}
|
|
@@ -140,7 +140,7 @@ export class UtilsS3 {
|
|
|
140
140
|
if (headers !== undefined) {
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
143
|
-
const s3_input =
|
|
143
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
144
144
|
if (s3_input === undefined) {
|
|
145
145
|
return undefined;
|
|
146
146
|
}
|
|
@@ -153,7 +153,7 @@ export class UtilsS3 {
|
|
|
153
153
|
async upload(s3_id, content, options = {}) {
|
|
154
154
|
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
|
|
155
155
|
const part_size = options.part_size !== undefined ? options.part_size : undefined;
|
|
156
|
-
const s3_input =
|
|
156
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
157
157
|
if (s3_input === undefined) {
|
|
158
158
|
return undefined;
|
|
159
159
|
}
|
|
@@ -169,7 +169,7 @@ export class UtilsS3 {
|
|
|
169
169
|
await upload.done();
|
|
170
170
|
}
|
|
171
171
|
async delete(s3_id) {
|
|
172
|
-
const s3_input =
|
|
172
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
173
173
|
if (s3_input === undefined) {
|
|
174
174
|
return undefined;
|
|
175
175
|
}
|
|
@@ -180,7 +180,7 @@ export class UtilsS3 {
|
|
|
180
180
|
if (headers === undefined) {
|
|
181
181
|
return undefined;
|
|
182
182
|
}
|
|
183
|
-
const s3_input =
|
|
183
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
184
184
|
if (s3_input === undefined) {
|
|
185
185
|
return undefined;
|
|
186
186
|
}
|
|
@@ -190,7 +190,7 @@ export class UtilsS3 {
|
|
|
190
190
|
}
|
|
191
191
|
async get_upload_url(s3_id, options = {}) {
|
|
192
192
|
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined;
|
|
193
|
-
const s3_input =
|
|
193
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
194
194
|
if (s3_input === undefined) {
|
|
195
195
|
return undefined;
|
|
196
196
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Textract } from "@aws-sdk/client-textract";
|
|
2
|
+
import { UtilsMisc } from "./UtilsMisc.js";
|
|
3
|
+
import { UtilsS3 } from "./UtilsS3.js";
|
|
4
|
+
export class UtilsTextract {
|
|
5
|
+
textract;
|
|
6
|
+
constructor(region) {
|
|
7
|
+
this.textract = new Textract({ region: region });
|
|
8
|
+
}
|
|
9
|
+
async get_text(s3_id) {
|
|
10
|
+
const s3_input = UtilsS3.get_s3_input(s3_id);
|
|
11
|
+
if (s3_input === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const request = {
|
|
15
|
+
DocumentLocation: {
|
|
16
|
+
S3Object: {
|
|
17
|
+
Bucket: s3_input.Bucket,
|
|
18
|
+
Name: s3_input.Key
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const job_id = await this.textract.startDocumentTextDetection(request)
|
|
23
|
+
.then(response => response.JobId);
|
|
24
|
+
if (job_id === undefined) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let token = undefined;
|
|
28
|
+
const blocks = [];
|
|
29
|
+
while (true) {
|
|
30
|
+
const result = await this.textract.getDocumentTextDetection({
|
|
31
|
+
JobId: job_id,
|
|
32
|
+
NextToken: token
|
|
33
|
+
});
|
|
34
|
+
if (result.JobStatus === "IN_PROGRESS") {
|
|
35
|
+
UtilsMisc.wait(1000);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
blocks.push(...(result.Blocks || []));
|
|
39
|
+
if (result.NextToken === undefined) {
|
|
40
|
+
return blocks;
|
|
41
|
+
}
|
|
42
|
+
token = result.NextToken;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/src/f.js
CHANGED
|
@@ -77,3 +77,7 @@ const utils = new TriangleUtils(config);
|
|
|
77
77
|
// await utils.rds.connect()
|
|
78
78
|
// console.log(await utils.rds.scan("web_articles", { is_verbose : true, is_forced : true, max_num_items : 100 }))
|
|
79
79
|
// await utils.rds.disconnect()
|
|
80
|
+
// await utils.twitter.get_user("1509572215251124226")
|
|
81
|
+
// .then(user => console.log(user))
|
|
82
|
+
// await utils.bedrock.cohere_invoke("cohere.embed-v4", "yyyyyuuuuuurrrrr")
|
|
83
|
+
// .then(response => console.log(response))
|
package/dist/src/index.d.ts
CHANGED
|
@@ -13,12 +13,14 @@ import { UtilsTwitter } from "./UtilsTwitter.js";
|
|
|
13
13
|
import { GlobalConfig } from "./types/GlobalConfig.js";
|
|
14
14
|
import { UtilsRDS } from "./UtilsRDS.js";
|
|
15
15
|
import { ApplicationConfig } from "./types/ApplicationConfig.js";
|
|
16
|
+
import { UtilsTextract } from "./UtilsTextract.js";
|
|
16
17
|
export declare class TriangleUtils extends UtilsMisc {
|
|
17
18
|
readonly dynamodb: UtilsDynamoDB;
|
|
18
19
|
readonly rds: UtilsRDS;
|
|
19
20
|
readonly s3: UtilsS3;
|
|
20
21
|
readonly s3vectors: UtilsS3Vectors;
|
|
21
22
|
readonly bedrock: UtilsBedrock;
|
|
23
|
+
readonly textract: UtilsTextract;
|
|
22
24
|
readonly cognito: UtilsCognito;
|
|
23
25
|
readonly ses: UtilsSES;
|
|
24
26
|
readonly bee: UtilsBee;
|
package/dist/src/index.js
CHANGED
|
@@ -11,12 +11,14 @@ import { UtilsXAI } from "./UtilsXAI.js";
|
|
|
11
11
|
import { UtilsAnthropic } from "./UtilsAnthropic.js";
|
|
12
12
|
import { UtilsTwitter } from "./UtilsTwitter.js";
|
|
13
13
|
import { UtilsRDS } from "./UtilsRDS.js";
|
|
14
|
+
import { UtilsTextract } from "./UtilsTextract.js";
|
|
14
15
|
export class TriangleUtils extends UtilsMisc {
|
|
15
16
|
dynamodb;
|
|
16
17
|
rds;
|
|
17
18
|
s3;
|
|
18
19
|
s3vectors;
|
|
19
20
|
bedrock;
|
|
21
|
+
textract;
|
|
20
22
|
cognito;
|
|
21
23
|
ses;
|
|
22
24
|
bee;
|
|
@@ -31,6 +33,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
31
33
|
this.s3 = new UtilsS3(config.region);
|
|
32
34
|
this.s3vectors = new UtilsS3Vectors(config.region);
|
|
33
35
|
this.bedrock = new UtilsBedrock(config.region);
|
|
36
|
+
this.textract = new UtilsTextract(config.region);
|
|
34
37
|
this.cognito = new UtilsCognito(config.region);
|
|
35
38
|
this.ses = new UtilsSES(config.region);
|
|
36
39
|
this.bee = new UtilsBee(config.scraping_bee_api_key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.151",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@aws-sdk/client-s3vectors": "^3.953.0",
|
|
27
27
|
"@aws-sdk/client-secrets-manager": "^3.965.0",
|
|
28
28
|
"@aws-sdk/client-ses": "^3.1032.0",
|
|
29
|
+
"@aws-sdk/client-textract": "^3.1117.0",
|
|
29
30
|
"@aws-sdk/lib-storage": "^3.1106.0",
|
|
30
31
|
"@aws-sdk/s3-request-presigner": "^3.1106.0",
|
|
31
32
|
"@types/jsdom": "^28.0.1",
|
package/src/UtilsRDS.ts
CHANGED
|
@@ -222,21 +222,25 @@ export class UtilsRDS {
|
|
|
222
222
|
items : Record<string, any>[],
|
|
223
223
|
options : {
|
|
224
224
|
is_verbose? : boolean,
|
|
225
|
-
is_forced? : boolean
|
|
225
|
+
is_forced? : boolean,
|
|
226
|
+
batch_num_items? : number
|
|
226
227
|
} = {}
|
|
227
228
|
) {
|
|
228
229
|
if (items.length === 0) {
|
|
229
230
|
return
|
|
230
231
|
}
|
|
231
232
|
const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
const batch_num_items = options.batch_num_items || 100
|
|
234
|
+
for (let i = 0; i < items.length; i += batch_num_items) {
|
|
235
|
+
const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_items).map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;"
|
|
236
|
+
try {
|
|
237
|
+
await this.exec(sql, options)
|
|
238
|
+
return
|
|
239
|
+
} catch (error : any) {
|
|
240
|
+
console.log(error.stack)
|
|
241
|
+
console.log(sql)
|
|
242
|
+
return
|
|
243
|
+
}
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
246
|
|
|
@@ -265,21 +269,24 @@ export class UtilsRDS {
|
|
|
265
269
|
items : Record<string, any>[],
|
|
266
270
|
options : {
|
|
267
271
|
is_verbose? : boolean,
|
|
268
|
-
is_forced? : boolean
|
|
272
|
+
is_forced? : boolean,
|
|
273
|
+
batch_num_items? : number
|
|
269
274
|
} = {}
|
|
270
275
|
) {
|
|
271
276
|
if (items.length === 0) {
|
|
272
277
|
return
|
|
273
278
|
}
|
|
274
279
|
const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
const items =
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
const batch_num_items = options.batch_num_items || 100
|
|
281
|
+
for (let i = 0; i < items.length; i += batch_num_items) {
|
|
282
|
+
const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_items).map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO UPDATE SET " + attribute_names.map(attribute_name => attribute_name + " = " + "EXCLUDED." + attribute_name).join(", ") + ";"
|
|
283
|
+
try {
|
|
284
|
+
await this.exec(sql, options)
|
|
285
|
+
} catch (error : any) {
|
|
286
|
+
console.log(error.stack)
|
|
287
|
+
console.log(sql)
|
|
288
|
+
return
|
|
289
|
+
}
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
292
|
|
|
@@ -297,14 +304,19 @@ export class UtilsRDS {
|
|
|
297
304
|
|
|
298
305
|
async batch_delete(
|
|
299
306
|
table_id : string,
|
|
300
|
-
|
|
307
|
+
primary_keys : Record<string, any>[],
|
|
301
308
|
options : {
|
|
302
309
|
is_verbose? : boolean,
|
|
303
|
-
is_forced? : boolean
|
|
310
|
+
is_forced? : boolean,
|
|
311
|
+
batch_num_items? : number
|
|
304
312
|
} = {}
|
|
305
313
|
) {
|
|
306
|
-
const
|
|
307
|
-
|
|
314
|
+
const batch_num_items = options.batch_num_items || 100
|
|
315
|
+
const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort()
|
|
316
|
+
for (let i = 0; i < primary_keys.length; i += batch_num_items) {
|
|
317
|
+
const sql = "DELETE FROM " + table_id + " WHERE " + "(" + attribute_names.join(", ") + ")" + " IN " + "(" + primary_keys.map(primary_key => "(" + attribute_names.map(attribute_name => convert_rds_input(primary_key[attribute_name])).join(", ") + ")" ).join(", ") + ")"
|
|
318
|
+
await this.exec(sql, options)
|
|
319
|
+
}
|
|
308
320
|
}
|
|
309
321
|
|
|
310
322
|
async set(
|
package/src/UtilsS3.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class UtilsS3 {
|
|
|
20
20
|
return this.s3
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
get_s3_input(s3_id : string) : S3Input | undefined {
|
|
23
|
+
static get_s3_input(s3_id : string) : S3Input | undefined {
|
|
24
24
|
const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3)
|
|
25
25
|
if (bucket === undefined || path === undefined) {
|
|
26
26
|
return undefined
|
|
@@ -29,7 +29,7 @@ export class UtilsS3 {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async get_headers(s3_id : string) {
|
|
32
|
-
const s3_input =
|
|
32
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
33
33
|
if (s3_input === undefined) {
|
|
34
34
|
return undefined
|
|
35
35
|
}
|
|
@@ -45,7 +45,7 @@ export class UtilsS3 {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
async get(s3_id : string, encoding : string = "utf-8") : Promise<string | undefined> {
|
|
48
|
-
const s3_input =
|
|
48
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
49
49
|
if (s3_input === undefined) {
|
|
50
50
|
return undefined
|
|
51
51
|
}
|
|
@@ -66,7 +66,7 @@ export class UtilsS3 {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
async get_buffer(s3_id : string) : Promise<Buffer | undefined> {
|
|
69
|
-
const s3_input =
|
|
69
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
70
70
|
if (s3_input === undefined) {
|
|
71
71
|
return undefined
|
|
72
72
|
}
|
|
@@ -87,7 +87,7 @@ export class UtilsS3 {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
async get_stream(s3_id : string) : Promise<Readable | undefined> {
|
|
90
|
-
const s3_input =
|
|
90
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
91
91
|
if (s3_input === undefined) {
|
|
92
92
|
return undefined
|
|
93
93
|
}
|
|
@@ -111,7 +111,7 @@ export class UtilsS3 {
|
|
|
111
111
|
|
|
112
112
|
async query_prefix(s3_id_prefix : string, options : { compile? : boolean } = {}) {
|
|
113
113
|
const compile = options.compile !== undefined ? options.compile : false
|
|
114
|
-
const s3_input =
|
|
114
|
+
const s3_input = UtilsS3.get_s3_input(s3_id_prefix)
|
|
115
115
|
if (s3_input === undefined) {
|
|
116
116
|
return []
|
|
117
117
|
}
|
|
@@ -155,7 +155,7 @@ export class UtilsS3 {
|
|
|
155
155
|
if (headers !== undefined) {
|
|
156
156
|
return undefined
|
|
157
157
|
}
|
|
158
|
-
const s3_input =
|
|
158
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
159
159
|
if (s3_input === undefined) {
|
|
160
160
|
return undefined
|
|
161
161
|
}
|
|
@@ -172,7 +172,7 @@ export class UtilsS3 {
|
|
|
172
172
|
} = {}) : Promise<void> {
|
|
173
173
|
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
|
|
174
174
|
const part_size = options.part_size !== undefined ? options.part_size : undefined
|
|
175
|
-
const s3_input =
|
|
175
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
176
176
|
if (s3_input === undefined) {
|
|
177
177
|
return undefined
|
|
178
178
|
}
|
|
@@ -189,7 +189,7 @@ export class UtilsS3 {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
async delete(s3_id : string) : Promise<void>{
|
|
192
|
-
const s3_input =
|
|
192
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
193
193
|
if (s3_input === undefined) {
|
|
194
194
|
return undefined
|
|
195
195
|
}
|
|
@@ -201,7 +201,7 @@ export class UtilsS3 {
|
|
|
201
201
|
if (headers === undefined) {
|
|
202
202
|
return undefined
|
|
203
203
|
}
|
|
204
|
-
const s3_input =
|
|
204
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
205
205
|
if (s3_input === undefined) {
|
|
206
206
|
return undefined
|
|
207
207
|
}
|
|
@@ -214,7 +214,7 @@ export class UtilsS3 {
|
|
|
214
214
|
content_type_id? : string
|
|
215
215
|
} = {}) : Promise<string | undefined> {
|
|
216
216
|
const content_type_id = options.content_type_id !== undefined ? options.content_type_id : undefined
|
|
217
|
-
const s3_input =
|
|
217
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
218
218
|
if (s3_input === undefined) {
|
|
219
219
|
return undefined
|
|
220
220
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Block, GetDocumentAnalysisCommandOutput, StartDocumentTextDetectionRequest, Textract } from "@aws-sdk/client-textract"
|
|
2
|
+
import { UtilsMisc } from "./UtilsMisc"
|
|
3
|
+
import { UtilsS3 } from "./UtilsS3"
|
|
4
|
+
|
|
5
|
+
export class UtilsTextract {
|
|
6
|
+
|
|
7
|
+
private readonly textract : Textract
|
|
8
|
+
|
|
9
|
+
constructor(region : string) {
|
|
10
|
+
this.textract = new Textract({ region : region })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async get_text(s3_id : string) {
|
|
14
|
+
const s3_input = UtilsS3.get_s3_input(s3_id)
|
|
15
|
+
if (s3_input === undefined) {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
const request : StartDocumentTextDetectionRequest = {
|
|
19
|
+
DocumentLocation : {
|
|
20
|
+
S3Object : {
|
|
21
|
+
Bucket : s3_input.Bucket,
|
|
22
|
+
Name : s3_input.Key
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const job_id = await this.textract.startDocumentTextDetection(request)
|
|
27
|
+
.then(response => response.JobId)
|
|
28
|
+
if (job_id === undefined) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
let token : string | undefined = undefined
|
|
32
|
+
const blocks : Block[] = []
|
|
33
|
+
while (true) {
|
|
34
|
+
const result : GetDocumentAnalysisCommandOutput = await this.textract.getDocumentTextDetection({
|
|
35
|
+
JobId : job_id,
|
|
36
|
+
NextToken : token
|
|
37
|
+
})
|
|
38
|
+
if (result.JobStatus === "IN_PROGRESS") {
|
|
39
|
+
UtilsMisc.wait(1000)
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
blocks.push(...(result.Blocks || []))
|
|
43
|
+
if (result.NextToken === undefined) {
|
|
44
|
+
return blocks
|
|
45
|
+
}
|
|
46
|
+
token = result.NextToken
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
package/src/f.ts
CHANGED
|
@@ -95,4 +95,10 @@ const utils = new TriangleUtils(config)
|
|
|
95
95
|
|
|
96
96
|
// await utils.rds.connect()
|
|
97
97
|
// console.log(await utils.rds.scan("web_articles", { is_verbose : true, is_forced : true, max_num_items : 100 }))
|
|
98
|
-
// await utils.rds.disconnect()
|
|
98
|
+
// await utils.rds.disconnect()
|
|
99
|
+
|
|
100
|
+
// await utils.twitter.get_user("1509572215251124226")
|
|
101
|
+
// .then(user => console.log(user))
|
|
102
|
+
|
|
103
|
+
// await utils.bedrock.cohere_invoke("cohere.embed-v4", "yyyyyuuuuuurrrrr")
|
|
104
|
+
// .then(response => console.log(response))
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { UtilsTwitter } from "./UtilsTwitter"
|
|
|
13
13
|
import { GlobalConfig } from "./types/GlobalConfig"
|
|
14
14
|
import { UtilsRDS } from "./UtilsRDS"
|
|
15
15
|
import { ApplicationConfig } from "./types/ApplicationConfig"
|
|
16
|
+
import { UtilsTextract } from "./UtilsTextract"
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
@@ -23,6 +24,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
23
24
|
readonly s3 : UtilsS3
|
|
24
25
|
readonly s3vectors : UtilsS3Vectors
|
|
25
26
|
readonly bedrock : UtilsBedrock
|
|
27
|
+
readonly textract : UtilsTextract
|
|
26
28
|
readonly cognito : UtilsCognito
|
|
27
29
|
readonly ses : UtilsSES
|
|
28
30
|
readonly bee : UtilsBee
|
|
@@ -38,6 +40,7 @@ export class TriangleUtils extends UtilsMisc {
|
|
|
38
40
|
this.s3 = new UtilsS3(config.region)
|
|
39
41
|
this.s3vectors = new UtilsS3Vectors(config.region)
|
|
40
42
|
this.bedrock = new UtilsBedrock(config.region)
|
|
43
|
+
this.textract = new UtilsTextract(config.region)
|
|
41
44
|
this.cognito = new UtilsCognito(config.region)
|
|
42
45
|
this.ses = new UtilsSES(config.region)
|
|
43
46
|
this.bee = new UtilsBee(config.scraping_bee_api_key)
|