triangle-utils 1.4.78 → 1.4.80
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.
|
@@ -13,7 +13,9 @@ export declare class UtilsDynamoDB {
|
|
|
13
13
|
max_num_items?: number;
|
|
14
14
|
last_key?: Record<string, any>;
|
|
15
15
|
}): Promise<Record<string, any>[]>;
|
|
16
|
-
get(table: string, key: Record<string, any>,
|
|
16
|
+
get(table: string, key: Record<string, any>, options?: {
|
|
17
|
+
consistent?: boolean;
|
|
18
|
+
}): Promise<Record<string, any> | undefined>;
|
|
17
19
|
get_max(table_index_name: string, primary_key: Record<string, string | number>): Promise<Record<string, any> | undefined>;
|
|
18
20
|
query(table_index_name: string, primary_key: Record<string, any>, options?: {
|
|
19
21
|
reverse?: boolean;
|
|
@@ -141,7 +141,8 @@ export class UtilsDynamoDB {
|
|
|
141
141
|
const items = segments.flat().filter(is_item);
|
|
142
142
|
return items;
|
|
143
143
|
}
|
|
144
|
-
async get(table, key,
|
|
144
|
+
async get(table, key, options = {}) {
|
|
145
|
+
const consistent = options.consistent !== undefined ? options.consistent : false;
|
|
145
146
|
const converted_key = convert_input(key)?.M;
|
|
146
147
|
if (converted_key === undefined) {
|
|
147
148
|
return undefined;
|
|
@@ -411,7 +412,7 @@ export class UtilsDynamoDB {
|
|
|
411
412
|
this.dynamodb.updateItem(request);
|
|
412
413
|
}
|
|
413
414
|
async add(table_name, key, attributes) {
|
|
414
|
-
const item = await this.get(table_name, key, true);
|
|
415
|
+
const item = await this.get(table_name, key, { consistent: true });
|
|
415
416
|
if (item === undefined) {
|
|
416
417
|
return;
|
|
417
418
|
}
|
|
@@ -443,7 +444,7 @@ export class UtilsDynamoDB {
|
|
|
443
444
|
await this.dynamodb.updateItem(request);
|
|
444
445
|
}
|
|
445
446
|
async create(table_name, key, attributes = {}) {
|
|
446
|
-
const item = await this.get(table_name, key, true);
|
|
447
|
+
const item = await this.get(table_name, key, { consistent: true });
|
|
447
448
|
if (item !== undefined) {
|
|
448
449
|
return;
|
|
449
450
|
}
|
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class UtilsMisc {
|
|
|
11
11
|
static wait(duration: number): Promise<unknown>;
|
|
12
12
|
static get_current_time(): string;
|
|
13
13
|
static get_current_milliseconds(): number;
|
|
14
|
+
static get_random_string(length: number, encoding?: "binary" | "hex" | "base64"): string;
|
|
14
15
|
static sha256(input: string): Promise<string>;
|
|
15
16
|
static encrypt(secret_key: string, text: string): Encryption;
|
|
16
17
|
static decrypt(secret_key: string, encryption: Encryption): string;
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -51,6 +51,9 @@ export class UtilsMisc {
|
|
|
51
51
|
static get_current_milliseconds() {
|
|
52
52
|
return (new Date()).getTime();
|
|
53
53
|
}
|
|
54
|
+
static get_random_string(length, encoding = "hex") {
|
|
55
|
+
return Buffer.from(crypto.randomBytes(length)).toString(encoding);
|
|
56
|
+
}
|
|
54
57
|
static async sha256(input) {
|
|
55
58
|
const text_encoder = new TextEncoder();
|
|
56
59
|
const input_buffer = text_encoder.encode(input);
|
package/package.json
CHANGED
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -169,8 +169,11 @@ export class UtilsDynamoDB {
|
|
|
169
169
|
async get(
|
|
170
170
|
table : string,
|
|
171
171
|
key : Record<string, any>,
|
|
172
|
-
|
|
172
|
+
options : {
|
|
173
|
+
consistent? : boolean
|
|
174
|
+
} = {}
|
|
173
175
|
) : Promise<Record<string, any> | undefined> {
|
|
176
|
+
const consistent = options.consistent !== undefined ? options.consistent : false
|
|
174
177
|
const converted_key = convert_input(key)?.M
|
|
175
178
|
if (converted_key === undefined) {
|
|
176
179
|
return undefined
|
|
@@ -510,7 +513,7 @@ export class UtilsDynamoDB {
|
|
|
510
513
|
}
|
|
511
514
|
|
|
512
515
|
async add(table_name : string, key : Record<string, any>, attributes : Record<string, any[]>) : Promise<void> {
|
|
513
|
-
const item = await this.get(table_name, key, true)
|
|
516
|
+
const item = await this.get(table_name, key, { consistent : true })
|
|
514
517
|
if (item === undefined) {
|
|
515
518
|
return
|
|
516
519
|
}
|
|
@@ -546,7 +549,7 @@ export class UtilsDynamoDB {
|
|
|
546
549
|
}
|
|
547
550
|
|
|
548
551
|
async create(table_name : string, key : Record<string, any>, attributes : Record<string, any> = {}) : Promise<void> {
|
|
549
|
-
const item = await this.get(table_name, key, true)
|
|
552
|
+
const item = await this.get(table_name, key, { consistent : true })
|
|
550
553
|
if (item !== undefined) {
|
|
551
554
|
return
|
|
552
555
|
}
|
package/src/UtilsMisc.ts
CHANGED
|
@@ -66,6 +66,10 @@ export class UtilsMisc {
|
|
|
66
66
|
return (new Date()).getTime()
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
static get_random_string(length : number, encoding : "binary" | "hex" | "base64" = "hex") : string {
|
|
70
|
+
return Buffer.from(crypto.randomBytes(length)).toString(encoding)
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
static async sha256(input : string) : Promise<string> {
|
|
70
74
|
const text_encoder = new TextEncoder()
|
|
71
75
|
const input_buffer = text_encoder.encode(input);
|