@model-ts/dynamodb 3.0.1 → 3.0.3

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/src/client.ts CHANGED
@@ -741,7 +741,7 @@ export class Client {
741
741
  ? E.left({ ...state, rollbackSuccessful: true })
742
742
  : E.right(state)
743
743
 
744
- const [currentBatch, remaining] = A.splitAt(25)(operations)
744
+ const [currentBatch, remaining] = A.splitAt(100)(operations)
745
745
 
746
746
  try {
747
747
  const transactItems = currentBatch
package/src/sandbox.ts CHANGED
@@ -5,17 +5,29 @@ import diff from "snapshot-diff"
5
5
  import { Client } from "./client"
6
6
  import { GSI_NAMES } from "./gsi"
7
7
 
8
+ /**
9
+ * Returns a random endpoint from the LOCAL_ENDPOINT environment variable.
10
+ */
11
+ function getEndpoint() {
12
+ if (!process.env.LOCAL_ENDPOINT) throw new Error("LOCAL_ENDPOINT is not set")
13
+
14
+ const endpoints = process.env.LOCAL_ENDPOINT.split(",")
15
+ return endpoints[Math.floor(Math.random() * endpoints.length)]
16
+ }
17
+
18
+ const endpoint = getEndpoint()
19
+
8
20
  const ddb = new DynamoDB({
9
21
  accessKeyId: "xxx",
10
22
  secretAccessKey: "xxx",
11
- endpoint: process.env.LOCAL_ENDPOINT,
23
+ endpoint,
12
24
  region: "local",
13
25
  })
14
26
 
15
27
  const docClient = new DynamoDB.DocumentClient({
16
28
  accessKeyId: "xxx",
17
29
  secretAccessKey: "xxx",
18
- endpoint: process.env.LOCAL_ENDPOINT,
30
+ endpoint,
19
31
  region: "local",
20
32
  })
21
33
 
@@ -125,23 +137,25 @@ export const createSandbox = async (client: Client): Promise<Sandbox> => {
125
137
  seed: async (...args: Array<{ [key: string]: any }>) => {
126
138
  const chunks = chunksOf(25)(args)
127
139
 
128
- for (const chunk of chunks) {
129
- const items = chunk.map((i) =>
130
- typeof i?._model?.__dynamoDBEncode === "function"
131
- ? i._model.__dynamoDBEncode(i)
132
- : typeof i.encode === "function"
133
- ? i.encode()
134
- : i
135
- )
136
-
137
- await client.documentClient
138
- .batchWrite({
139
- RequestItems: {
140
- [tableName]: items.map((i) => ({ PutRequest: { Item: i } })),
141
- },
142
- })
143
- .promise()
144
- }
140
+ await Promise.all(
141
+ chunks.map(async (chunk) => {
142
+ const items = chunk.map((i) =>
143
+ typeof i?._model?.__dynamoDBEncode === "function"
144
+ ? i._model.__dynamoDBEncode(i)
145
+ : typeof i.encode === "function"
146
+ ? i.encode()
147
+ : i
148
+ )
149
+
150
+ return client.documentClient
151
+ .batchWrite({
152
+ RequestItems: {
153
+ [tableName]: items.map((i) => ({ PutRequest: { Item: i } })),
154
+ },
155
+ })
156
+ .promise()
157
+ })
158
+ )
145
159
  },
146
160
  get: (pk: string, sk: string) =>
147
161
  client.documentClient