@certik/skynet 0.15.0 → 0.16.1

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.1
4
+
5
+ - Removed verbose log from exponentialRetry (@certik/skynet/availablity)
6
+
7
+ ## 0.16.0
8
+
9
+ - Added: dynamodb read command to get record
10
+ - Added: dynamodb transactWrite wrapper
11
+
12
+ ## 0.15.1
13
+
14
+ - BREAKING: changed api restart behavior to never fail the allocation
15
+
3
16
  ## 0.15.0
4
17
 
5
18
  - BREAKING: only start one S3 client globally
package/app.js CHANGED
@@ -46,7 +46,7 @@ async function checkDeployEnv(env) {
46
46
  }
47
47
 
48
48
  return { name: key, ok: true };
49
- })
49
+ }),
50
50
  );
51
51
 
52
52
  const missingEnvs = envStatus.filter((s) => !s.ok).map((s) => s.name);
@@ -694,8 +694,8 @@ function api({ name, routes, serve, beforeListen, env = {}, region = "us-east-1"
694
694
  restart: {
695
695
  attempts: 3,
696
696
  delay: "15s",
697
- mode: "fail",
698
- interval: "30m",
697
+ mode: "delay",
698
+ interval: "2m",
699
699
  },
700
700
  count: serve.instances,
701
701
  killTimeout: serve.killTimeout,
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/bun.lockb CHANGED
File without changes
package/deploy.js CHANGED
@@ -134,7 +134,8 @@ const genConfig = ({
134
134
  }
135
135
 
136
136
  restart {
137
- attempts = 0
137
+ attempts = 3
138
+ delay = "15s"
138
139
  mode = "fail"
139
140
  }
140
141
  }
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/examples/api.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -43,4 +43,4 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  }
46
- }
46
+ }
@@ -1,5 +0,0 @@
1
- {
2
- "conventionalCommits.scopes": [
3
- "lib-skynet"
4
- ]
5
- }