triangle-utils 1.3.3 → 1.3.4

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.
@@ -5,7 +5,7 @@ export declare class Utils_Bee {
5
5
  readonly bee: ScrapingBeeClient | undefined;
6
6
  readonly text_decoder: TextDecoder;
7
7
  constructor(config: Config);
8
- get(url: string, params?: Record<string, string>): Promise<string>;
8
+ get(url: string, params?: Record<string, string>): Promise<string | undefined>;
9
9
  google_search(query: string, news?: boolean): Promise<any>;
10
10
  youtube_search(query: string, options?: {}): Promise<any>;
11
11
  }
@@ -15,7 +15,7 @@ export declare class Utils_DynamoDB {
15
15
  query(table: string, primary_key: Record<string, any>, options?: {
16
16
  reverse?: boolean;
17
17
  compile?: boolean;
18
- }): Promise<Record<string, any>[] | undefined>;
18
+ }): Promise<Record<string, any>[]>;
19
19
  query_prefix(table: string, primary_key: Record<string, any>, secondary_key_prefix: Record<string, string>, options?: {
20
20
  reverse?: boolean;
21
21
  compile?: boolean;
@@ -23,7 +23,7 @@ export declare class Utils_DynamoDB {
23
23
  query_range(table: string, primary_key: Record<string, any>, secondary_key_range: Record<string, string | number[]>, options?: {
24
24
  reverse?: boolean;
25
25
  compile?: boolean;
26
- }): Promise<Record<string, any>[] | undefined>;
26
+ }): Promise<Record<string, any>[]>;
27
27
  set(table: string, key: Record<string, any>, attributes: Record<string, any>): Promise<void>;
28
28
  append(table: string, key: Record<string, any>, attributes: Record<string, any[]>): Promise<void>;
29
29
  add(table: string, key: Record<string, any>, attributes: Record<string, any[]>): Promise<void>;
@@ -177,12 +177,12 @@ export class Utils_DynamoDB {
177
177
  const reverse = options.reverse !== undefined ? options.reverse : false;
178
178
  const compile = options.compile !== undefined ? options.compile : true;
179
179
  if (Object.keys(primary_key).length !== 1) {
180
- return undefined;
180
+ return [];
181
181
  }
182
182
  const key = Object.keys(primary_key)[0];
183
183
  const value = convert_input(Object.values(primary_key)[0]);
184
184
  if (value === undefined) {
185
- return undefined;
185
+ return [];
186
186
  }
187
187
  const request = {
188
188
  TableName: table,
@@ -227,13 +227,13 @@ export class Utils_DynamoDB {
227
227
  const reverse = options.reverse !== undefined ? options.reverse : false;
228
228
  const compile = options.compile !== undefined ? options.compile : true;
229
229
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
230
- return undefined;
230
+ return [];
231
231
  }
232
232
  const converted_primary_value = convert_input(Object.values(primary_key)[0]);
233
233
  const converted_secondary_range_start_value = convert_input(Object.values(secondary_key_range)[0][0]);
234
234
  const converted_secondary_range_end_value = convert_input(Object.values(secondary_key_range)[0][1]);
235
235
  if (converted_primary_value === undefined || converted_secondary_range_start_value === undefined || converted_secondary_range_end_value === undefined) {
236
- return undefined;
236
+ return [];
237
237
  }
238
238
  const request = {
239
239
  TableName: table,
@@ -7,7 +7,7 @@ interface Encryption {
7
7
  export declare class Utils_Misc {
8
8
  readonly config: Config;
9
9
  readonly text_encoder: TextEncoder;
10
- readonly transporter: nodemailer.Transporter<import("nodemailer/lib/smtp-transport").SentMessageInfo, import("nodemailer/lib/smtp-transport").Options>;
10
+ readonly transporter: nodemailer.Transporter<import("nodemailer/lib/smtp-transport").SentMessageInfo, import("nodemailer/lib/smtp-transport").Options> | undefined;
11
11
  constructor(config: Config);
12
12
  wait(duration: number): Promise<unknown>;
13
13
  get_current_time(): string;
@@ -3,11 +3,11 @@ import { Config } from "./types/Config.js";
3
3
  export declare class Utils_S3 {
4
4
  readonly s3: S3;
5
5
  constructor(config: Config);
6
- file_exists(s3_filename: string): Promise<boolean>;
6
+ file_exists(s3_filename: string): Promise<boolean | undefined>;
7
7
  get_file(s3_filename: string): Promise<string | undefined>;
8
8
  create_file(s3_filename: string, content: string | Buffer, options?: {
9
9
  content_type?: string;
10
- }): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
10
+ }): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
11
11
  delete_file(s3_filename: string): Promise<void>;
12
12
  generate_download_url(s3_filename: string): Promise<string | undefined>;
13
13
  generate_upload_url(s3_filename: string): Promise<string | undefined>;
@@ -10,11 +10,11 @@ export declare class Utils_S3Vectors {
10
10
  constructor(config: Config);
11
11
  scan(vector_bucket: string, vector_index: string): Promise<string[]>;
12
12
  get(vector_bucket: string, vector_index: string, vector_key: string): Promise<Vector | undefined>;
13
- batch_get(vector_bucket: string, vector_index: string, vector_keys: string[]): Promise<Vector[]>;
13
+ batch_get(vector_bucket: string, vector_index: string, vector_keys: string[]): Promise<(Vector | undefined)[]>;
14
14
  create(vector_bucket: string, vector_index: string, vector: Vector): Promise<void>;
15
15
  batch_create(vector_bucket: string, vector_index: string, vectors: Vector[]): Promise<void>;
16
16
  delete(vector_bucket: string, vector_index: string, vector_key: string): Promise<void>;
17
17
  batch_delete(vector_bucket: string, vector_index: string, vector_keys: string[]): Promise<void>;
18
- query(vector_bucket: string, vector_index: string, data: number[], num_vectors: number, filters?: Record<string, any>): Promise<import("@aws-sdk/client-s3vectors").QueryOutputVector[]>;
18
+ query(vector_bucket: string, vector_index: string, data: number[], num_vectors: number, filters?: Record<string, any>): Promise<import("@aws-sdk/client-s3vectors").QueryOutputVector[] | undefined>;
19
19
  }
20
20
  export {};
@@ -4,5 +4,5 @@ export declare class Utils_Youtube {
4
4
  readonly config: Config;
5
5
  readonly youtube: youtube_v3.Youtube;
6
6
  constructor(config: Config);
7
- batch_get_videos(video_ids: string[], attributes?: string[]): Promise<youtube_v3.Schema$Video[]>;
7
+ batch_get_videos(video_ids: string[], attributes?: string[]): Promise<youtube_v3.Schema$Video[] | undefined>;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "main": "dist/src/Utils.js",
5
5
  "directories": {
6
6
  "test": "test"
@@ -165,7 +165,10 @@ export class Utils_DynamoDB {
165
165
  return converted_output
166
166
  }
167
167
 
168
- async get_max(table : string, primary_key : Record<string, any>) : Promise<Record<string, any> | undefined> {
168
+ async get_max(
169
+ table : string,
170
+ primary_key : Record<string, any>
171
+ ) : Promise<Record<string, any> | undefined> {
169
172
  if (Object.keys(primary_key).length !== 1) {
170
173
  return undefined
171
174
  }
@@ -205,16 +208,16 @@ export class Utils_DynamoDB {
205
208
  reverse? : boolean,
206
209
  compile? : boolean
207
210
  } = {}
208
- ) : Promise<Record<string, any>[] | undefined>{
211
+ ) : Promise<Record<string, any>[]>{
209
212
  const reverse = options.reverse !== undefined ? options.reverse : false
210
213
  const compile = options.compile !== undefined ? options.compile : true
211
214
  if (Object.keys(primary_key).length !== 1) {
212
- return undefined
215
+ return []
213
216
  }
214
217
  const key = Object.keys(primary_key)[0]
215
218
  const value = convert_input(Object.values(primary_key)[0])
216
219
  if (value === undefined) {
217
- return undefined
220
+ return []
218
221
  }
219
222
  const request : QueryCommandInput = {
220
223
  TableName : table,
@@ -273,17 +276,17 @@ export class Utils_DynamoDB {
273
276
  reverse? : boolean,
274
277
  compile? : boolean
275
278
  } = {}
276
- ) : Promise<Record<string, any>[] | undefined>{
279
+ ) : Promise<Record<string, any>[]>{
277
280
  const reverse = options.reverse !== undefined ? options.reverse : false
278
281
  const compile = options.compile !== undefined ? options.compile : true
279
282
  if (Object.keys(primary_key).length !== 1 || Object.keys(secondary_key_range).length !== 1 || Object.values(secondary_key_range)[0].length !== 2) {
280
- return undefined
283
+ return []
281
284
  }
282
285
  const converted_primary_value = convert_input(Object.values(primary_key)[0])
283
286
  const converted_secondary_range_start_value = convert_input(Object.values(secondary_key_range)[0][0])
284
287
  const converted_secondary_range_end_value = convert_input(Object.values(secondary_key_range)[0][1])
285
288
  if (converted_primary_value === undefined || converted_secondary_range_start_value === undefined || converted_secondary_range_end_value === undefined) {
286
- return undefined
289
+ return []
287
290
  }
288
291
  const request : QueryCommandInput = {
289
292
  TableName : table,
package/src/Utils_Misc.ts CHANGED
@@ -652,4 +652,27 @@ export class Utils_Misc {
652
652
  }))
653
653
  return chunks
654
654
  }
655
+
656
+ chunkify_lined(text : string, max_length = 2500, overlap = 50) : {
657
+ chunk_index : [number, number],
658
+ chunk_text : string
659
+ }[] {
660
+ const chunk_indices : [number, number][] = this.get_chunk_indices(text.length, max_length, overlap)
661
+ const lined_chunk_indices : [number, number][] = []
662
+ for (const chunk_index of chunk_indices) {
663
+ const lined_chunk_index : [number, number] = [
664
+ text.lastIndexOf("\n", chunk_index[0]) + 1,
665
+ text.indexOf("\n", chunk_index[1]) + 1
666
+ ]
667
+ if (lined_chunk_index[1] < lined_chunk_index[0]) {
668
+ lined_chunk_index[1] += text.length
669
+ }
670
+ lined_chunk_indices.push(lined_chunk_index)
671
+ }
672
+ return lined_chunk_indices.map(chunk_index => ({
673
+ chunk_index : chunk_index,
674
+ chunk_text : text.substring(...chunk_index)
675
+ }))
676
+ }
677
+
655
678
  }
package/tsconfig.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "declaration": true,
15
15
  // Allow JS files to be imported from TS and vice versa
16
16
  "allowJs": true,
17
-
17
+ "strict" : true,
18
18
  // Use correct ESM import behavior
19
19
  "esModuleInterop": true,
20
20
  "resolveJsonModule": true,