triangle-utils 1.4.15 → 1.4.17

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.
@@ -2,7 +2,7 @@ export declare class UtilsDynamoDB {
2
2
  private readonly dynamodb;
3
3
  constructor(region: string);
4
4
  get_table_key_names(table_name: string): Promise<string[] | undefined>;
5
- scan(table: string, options?: {
5
+ scan(table_index_name: string, options?: {
6
6
  filters?: Record<string, any>;
7
7
  undefined_attribute_names?: string[];
8
8
  defined_attribute_names?: string[];
@@ -98,7 +98,9 @@ export class UtilsDynamoDB {
98
98
  .filter(table_key_name => table_key_name !== undefined);
99
99
  return table_key_names;
100
100
  }
101
- async scan(table, options = {}) {
101
+ async scan(table_index_name, options = {}) {
102
+ const table_name = table_index_name.split(":")[0];
103
+ const index_name = table_index_name.split(":")[1];
102
104
  const filters = options.filters !== undefined ? options.filters : {};
103
105
  const undefined_attribute_names = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : [];
104
106
  const defined_attribute_names = options.defined_attribute_names !== undefined ? options.defined_attribute_names : [];
@@ -118,7 +120,8 @@ export class UtilsDynamoDB {
118
120
  ].join(" AND ");
119
121
  const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ");
120
122
  const request = {
121
- TableName: table,
123
+ TableName: table_name,
124
+ IndexName: index_name,
122
125
  ExpressionAttributeNames: Object.keys(expression_attribute_names).length > 0 ? expression_attribute_names : undefined,
123
126
  ExpressionAttributeValues: Object.keys(expression_attribute_values).length > 0 ? expression_attribute_values : undefined,
124
127
  FilterExpression: filter_expression.length > 0 ? filter_expression : undefined,
@@ -28,6 +28,10 @@ export declare class UtilsMisc {
28
28
  chunk_index: [number, number];
29
29
  chunk_text: string;
30
30
  }[];
31
+ static chunkify_pages(pages: string[], max_length?: number, overlap?: number): {
32
+ chunk_index: [number, number];
33
+ chunk_text: string;
34
+ }[];
31
35
  static instantiate<T>(constructor: new (x: any) => T, x: any): T | undefined;
32
36
  static instantiator<T>(constructor: new (x: any) => T): (x: any) => T | undefined;
33
37
  }
@@ -153,6 +153,20 @@ export class UtilsMisc {
153
153
  chunk_text: text.substring(...chunk_index)
154
154
  }));
155
155
  }
156
+ static chunkify_pages(pages, max_length = 2500, overlap = 50) {
157
+ const chunks = [];
158
+ for (const page of pages) {
159
+ const page_chunks = UtilsMisc.chunkify(page, max_length, overlap);
160
+ const start_index = (chunks.length > 0 ? (chunks[chunks.length - 1].chunk_index[1]) : 0);
161
+ for (const page_chunk of page_chunks) {
162
+ chunks.push({
163
+ chunk_index: [page_chunk.chunk_index[0] + start_index, page_chunk.chunk_index[1] + start_index],
164
+ chunk_text: page_chunk.chunk_text + "\n\n"
165
+ });
166
+ }
167
+ }
168
+ return chunks;
169
+ }
156
170
  static instantiate(constructor, x) {
157
171
  try {
158
172
  const instance = new constructor(x);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -106,7 +106,7 @@ export class UtilsDynamoDB {
106
106
  }
107
107
 
108
108
  async scan(
109
- table : string,
109
+ table_index_name : string,
110
110
  options : {
111
111
  filters? : Record<string, any>,
112
112
  undefined_attribute_names? : string[],
@@ -115,6 +115,8 @@ export class UtilsDynamoDB {
115
115
  concurrency? : number
116
116
  } = {}
117
117
  ) : Promise<Record<string, any>[]> {
118
+ const table_name : string = table_index_name.split(":")[0]
119
+ const index_name : string | undefined = table_index_name.split(":")[1]
118
120
  const filters = options.filters !== undefined ? options.filters : {}
119
121
  const undefined_attribute_names : string[] = options.undefined_attribute_names !== undefined ? options.undefined_attribute_names : []
120
122
  const defined_attribute_names : string[] = options.defined_attribute_names !== undefined ? options.defined_attribute_names : []
@@ -138,7 +140,8 @@ export class UtilsDynamoDB {
138
140
  ].join(" AND ")
139
141
  const projection_expression = attribute_names.map(attribute_name => "#" + attribute_name).join(", ")
140
142
  const request : ScanCommandInput = {
141
- TableName : table,
143
+ TableName : table_name,
144
+ IndexName : index_name,
142
145
  ExpressionAttributeNames : Object.keys(expression_attribute_names).length > 0 ? expression_attribute_names : undefined,
143
146
  ExpressionAttributeValues : Object.keys(expression_attribute_values).length > 0 ? expression_attribute_values : undefined,
144
147
  FilterExpression : filter_expression.length > 0 ? filter_expression : undefined,