@certik/skynet 0.15.1 → 0.16.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.16.2
4
+
5
+ - Doubled log-shipper cpu and memory
6
+
7
+ ## 0.16.1
8
+
9
+ - Removed verbose log from exponentialRetry (@certik/skynet/availablity)
10
+
11
+ ## 0.16.0
12
+
13
+ - Added: dynamodb read command to get record
14
+ - Added: dynamodb transactWrite wrapper
15
+
3
16
  ## 0.15.1
4
17
 
5
18
  - BREAKING: changed api restart behavior to never fail the allocation
package/availability.js CHANGED
@@ -32,9 +32,9 @@ export async function exponentialRetry(func, { maxRetry, initialDuration, growFa
32
32
  while (!test(result) && retries > 0) {
33
33
  if (verbose) {
34
34
  console.log("failed attempt result", result);
35
+ console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
35
36
  }
36
37
 
37
- console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
38
38
  retries = retries - 1;
39
39
 
40
40
  await wait(duration);
package/deploy.js CHANGED
@@ -129,8 +129,8 @@ const genConfig = ({
129
129
  kill_timeout = "120s"
130
130
 
131
131
  resources {
132
- cpu = 100 # MHz
133
- memory = 100 # MB
132
+ cpu = 200 # MHz
133
+ memory = 200 # MB
134
134
  }
135
135
 
136
136
  restart {
package/dynamodb.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  PutCommand,
7
7
  QueryCommand,
8
8
  UpdateCommand,
9
+ TransactWriteCommand,
9
10
  } from "@aws-sdk/lib-dynamodb";
10
11
  import { DynamoDBClient, DescribeTableCommand } from "@aws-sdk/client-dynamodb";
11
12
  import { getAWSSDKConfig } from "./env.js";
@@ -153,6 +154,21 @@ async function createRecord(tableName, fields, verbose = false) {
153
154
  return docClient.send(new PutCommand(params));
154
155
  }
155
156
 
157
+ async function readRecord(tableName, key, verbose = false) {
158
+ if (verbose) {
159
+ console.log("reading", tableName, key);
160
+ }
161
+
162
+ const docClient = getDocClient();
163
+
164
+ const record = await docClient.send(new GetCommand({
165
+ TableName: tableName,
166
+ Key: key,
167
+ }));
168
+
169
+ return record.Item;
170
+ }
171
+
156
172
  async function getRecordsByKey(tableName, keys, indexName) {
157
173
  const docClient = getDocClient();
158
174
 
@@ -199,13 +215,18 @@ async function getRecordsByKey(tableName, keys, indexName) {
199
215
  }
200
216
  }
201
217
 
218
+ // Dual purpose for compatibility. If indexName is provided, it will use query command to get the record; if not, use get command which is most efficient.
202
219
  async function getRecordByKey(tableName, keys, indexName) {
203
- const records = await getRecordsByKey(tableName, keys, indexName);
220
+ if (indexName) {
221
+ const records = await getRecordsByKey(tableName, keys, indexName);
204
222
 
205
- if (records) {
206
- return records[0];
223
+ if (records) {
224
+ return records[0];
225
+ } else {
226
+ return null;
227
+ }
207
228
  } else {
208
- return null;
229
+ return readRecord(tableName, keys);
209
230
  }
210
231
  }
211
232
 
@@ -451,6 +472,16 @@ async function deleteRecordsByHashKey(tableName, indexName, hashKeyValue, verbos
451
472
  return totalDeleted;
452
473
  }
453
474
 
475
+ async function transactWrite(items) {
476
+ const docClient = getDocClient();
477
+
478
+ return docClient.send(
479
+ new TransactWriteCommand({
480
+ TransactItems: items,
481
+ }),
482
+ );
483
+ }
484
+
454
485
  export {
455
486
  getDocClient,
456
487
  // export common dynamodb commands to make it easier to use
@@ -469,4 +500,5 @@ export {
469
500
  batchDeleteRecords,
470
501
  deleteRecordsByHashKey,
471
502
  createTableIfNotExist,
503
+ transactWrite,
472
504
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.15.1",
3
+ "version": "0.16.2",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",