@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/CHANGELOG.md +13 -0
- package/dist/cjs/__test__/client-with-cursor-encryption.test.js +696 -21
- package/dist/cjs/__test__/client-with-cursor-encryption.test.js.map +1 -1
- package/dist/cjs/__test__/client.test.js +775 -95
- package/dist/cjs/__test__/client.test.js.map +1 -1
- package/dist/cjs/client.js +1 -1
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/sandbox.js +15 -5
- package/dist/cjs/sandbox.js.map +1 -1
- package/dist/esm/__test__/client-with-cursor-encryption.test.js +696 -21
- package/dist/esm/__test__/client-with-cursor-encryption.test.js.map +1 -1
- package/dist/esm/__test__/client.test.js +776 -96
- package/dist/esm/__test__/client.test.js.map +1 -1
- package/dist/esm/client.js +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/sandbox.js +15 -5
- package/dist/esm/sandbox.js.map +1 -1
- package/package.json +4 -4
- package/src/__test__/client-with-cursor-encryption.test.ts +696 -21
- package/src/__test__/client.test.ts +782 -97
- package/src/client.ts +1 -1
- package/src/sandbox.ts +33 -19
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(
|
|
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
|
|
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
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|