triangle-utils 1.4.149 → 1.4.150
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/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/f.txt +0 -0
- package/package.json +2 -1
- 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/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/f.txt
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triangle-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.150",
|
|
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/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)
|