@reventlessdev/rescript-aws-sdk 2.2.0-alpha.20

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/LICENSE +202 -0
  3. package/README.md +21 -0
  4. package/package.json +44 -0
  5. package/rescript.json +23 -0
  6. package/src/CloudWatchEvents.res +162 -0
  7. package/src/CloudWatchEvents.res.mjs +94 -0
  8. package/src/CognitoIdentityServiceProvider.res +117 -0
  9. package/src/CognitoIdentityServiceProvider.res.mjs +70 -0
  10. package/src/DynamoDb.res +3 -0
  11. package/src/DynamoDb.res.mjs +15 -0
  12. package/src/DynamoDb_DocumentClient.res +905 -0
  13. package/src/DynamoDb_DocumentClient.res.mjs +338 -0
  14. package/src/DynamoDb_DynamoDb.res +189 -0
  15. package/src/DynamoDb_DynamoDb.res.mjs +70 -0
  16. package/src/DynamoDb_Util.res +128 -0
  17. package/src/DynamoDb_Util.res.mjs +35 -0
  18. package/src/DynamoDb_Util_Helpers.res +7 -0
  19. package/src/DynamoDb_Util_Helpers.res.mjs +23 -0
  20. package/src/ECS.res +96 -0
  21. package/src/ECS.res.mjs +46 -0
  22. package/src/IAM.res +20 -0
  23. package/src/IAM.res.mjs +9 -0
  24. package/src/Kinesis.res +50 -0
  25. package/src/Kinesis.res.mjs +39 -0
  26. package/src/Metadata.res +9 -0
  27. package/src/Metadata.res.mjs +2 -0
  28. package/src/NodeHttpHandler.res +6 -0
  29. package/src/NodeHttpHandler.res.mjs +2 -0
  30. package/src/S3.res +152 -0
  31. package/src/S3.res.mjs +61 -0
  32. package/src/S3_Helpers.res +20 -0
  33. package/src/S3_Helpers.res.mjs +26 -0
  34. package/src/SES.res +113 -0
  35. package/src/SES.res.mjs +59 -0
  36. package/src/SNS.res +167 -0
  37. package/src/SNS.res.mjs +98 -0
  38. package/src/SNS_Helpers.res +45 -0
  39. package/src/SNS_Helpers.res.mjs +57 -0
  40. package/src/SQS.res +241 -0
  41. package/src/SQS.res.mjs +121 -0
  42. package/src/SQS_Helpers.res +267 -0
  43. package/src/SQS_Helpers.res.mjs +227 -0
  44. package/src/SecretsManager.res +61 -0
  45. package/src/SecretsManager.res.mjs +46 -0
  46. package/src/example/DynamoDbUtilExample.res +20 -0
  47. package/src/example/DynamoDbUtilExample.res.mjs +66 -0
@@ -0,0 +1,227 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as SQS$AwsSdk from "./SQS.res.mjs";
4
+ import * as Stdlib_Math from "@rescript/runtime/lib/es6/Stdlib_Math.js";
5
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
6
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+ import * as ClientSqs from "@aws-sdk/client-sqs";
9
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
10
+
11
+ function arn2Url(arn) {
12
+ let match = arn.split(":");
13
+ if (match.length !== 6) {
14
+ return "";
15
+ }
16
+ let service = match[2];
17
+ let region = match[3];
18
+ let account = match[4];
19
+ let queueName = match[5];
20
+ return `https://` + service + `.` + region + `.amazonaws.com/` + account + `/` + queueName;
21
+ }
22
+
23
+ function validateDelay(__x) {
24
+ return Stdlib_Option.map(__x, delay => {
25
+ if (delay > 900) {
26
+ console.log("WARNING: [" + ("SQS_Helpers-AwsSdk" + (":" + ((16).toString() + "] SQS.sendMessage was called with a delay set to higher than 900 seconds, which is the maximum amount supported by AWS."))), "DelaySeconds was automatically set to 900 to prevent failure.");
27
+ return 900;
28
+ } else {
29
+ return delay;
30
+ }
31
+ });
32
+ }
33
+
34
+ async function sendMessage(queueId, messageBody, messageGroupId, messageDeduplicationId, delay) {
35
+ await SQS$AwsSdk.SendMessageCommand.send(new ClientSqs.SendMessageCommand({
36
+ MessageBody: messageBody,
37
+ QueueUrl: queueId,
38
+ DelaySeconds: Stdlib_Option.map(delay, delay => {
39
+ if (delay > 900) {
40
+ console.log("WARNING: [" + ("SQS_Helpers-AwsSdk" + (":" + ((47).toString() + "] SQS.sendMessage was called with a delay set to higher than 900 seconds, which is the maximum amount supported by AWS."))), "DelaySeconds was automatically set to 900 to prevent failure.");
41
+ return 900;
42
+ } else {
43
+ return delay;
44
+ }
45
+ }),
46
+ MessageDeduplicationId: messageDeduplicationId,
47
+ MessageGroupId: Stdlib_Option.map(messageGroupId, id => id.replace(/ /g, ""))
48
+ }));
49
+ }
50
+
51
+ function makeBatchEntry(messageBody, messageId, delay) {
52
+ return {
53
+ Id: messageId,
54
+ MessageBody: messageBody,
55
+ DelaySeconds: validateDelay(delay)
56
+ };
57
+ }
58
+
59
+ function makeBatchEntryFifo(groupId, messageBody, messageId, delay) {
60
+ return {
61
+ Id: messageId,
62
+ MessageBody: messageBody,
63
+ DelaySeconds: validateDelay(delay),
64
+ MessageGroupId: groupId.replace(/ /g, "")
65
+ };
66
+ }
67
+
68
+ function handleSendBatchPromises(promises, entries, name) {
69
+ return Promise.all(promises.map(async (promise, idx) => {
70
+ let batchNr = (idx + 1 | 0).toString();
71
+ let response;
72
+ try {
73
+ response = await promise;
74
+ } catch (raw_exn) {
75
+ let exn = Primitive_exceptions.internalToException(raw_exn);
76
+ let error = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), exn => Stdlib_JsExn.message(exn)), "unknown error");
77
+ console.log(`Error: SQS.` + name + ` batch ` + batchNr + ` failed: ` + error);
78
+ let start = idx * 10 | 0;
79
+ let end = start + 10 | 0;
80
+ return entries.slice(start, end).map(entry => entry.Id);
81
+ }
82
+ return Stdlib_Option.getOr(response.Failed, []).map(failure => {
83
+ let id = failure.Id;
84
+ let failureCode = failure.Code;
85
+ let failureMessage = Stdlib_Option.getOr(failure.Message, "unknown message");
86
+ console.log(`Error: SQS.` + name + ` batch ` + batchNr + ` entry failed: ` + id + `, ` + failureCode + `, ` + failureMessage);
87
+ return id;
88
+ });
89
+ }));
90
+ }
91
+
92
+ function handleBatchResult(failedIds) {
93
+ let failedIds$1 = failedIds.flat();
94
+ if (failedIds$1.length !== 0) {
95
+ return {
96
+ TAG: "Error",
97
+ _0: failedIds$1
98
+ };
99
+ } else {
100
+ return {
101
+ TAG: "Ok",
102
+ _0: undefined
103
+ };
104
+ }
105
+ }
106
+
107
+ async function sendMessagesParallel(queueId, entries) {
108
+ let totalMessageCount = entries.length;
109
+ let batchNr = 0;
110
+ let start = 0;
111
+ let batchPromises = [];
112
+ let sliceBatch = start => {
113
+ let end = {
114
+ contents: start
115
+ };
116
+ let batchBytes = 0;
117
+ let messageBytes = () => entries[end.contents].MessageBody.length;
118
+ while (end.contents < totalMessageCount && end.contents < (start + 10 | 0) && (batchBytes + messageBytes() | 0) <= 262144) {
119
+ batchBytes = batchBytes + messageBytes() | 0;
120
+ end.contents = end.contents + 1 | 0;
121
+ };
122
+ if (end.contents === start) {
123
+ console.log("SQS.sendMessagesParallel: no message sent !!");
124
+ }
125
+ return [
126
+ end.contents,
127
+ entries.slice(start, end.contents)
128
+ ];
129
+ };
130
+ while (start < totalMessageCount) {
131
+ let match = sliceBatch(start);
132
+ let batchEntries = match[1];
133
+ batchNr = batchNr + 1 | 0;
134
+ start = match[0];
135
+ let messages = batchEntries.map(param => param.MessageBody);
136
+ let messageCountStr = messages.length.toString();
137
+ let messageBytes = messages.map(message => message.length);
138
+ let batchBytes = Stdlib_Array.reduce(messageBytes, 0, (acc, a) => acc + a | 0);
139
+ let messageBytesStr = messageBytes.map(size => size.toString()).join(",");
140
+ console.log(`SQS.sendMessagesParallel: batchNr:` + batchNr.toString() + ` messageCount:` + messageCountStr + ` batchBytes: ` + batchBytes.toString() + `, messageBytes: ` + messageBytesStr);
141
+ batchPromises.push(SQS$AwsSdk.SendMessageBatchCommand.send(new ClientSqs.SendMessageBatchCommand({
142
+ Entries: batchEntries,
143
+ QueueUrl: queueId
144
+ })));
145
+ };
146
+ return handleBatchResult(await handleSendBatchPromises(batchPromises, entries, "sendMessagesParallel"));
147
+ }
148
+
149
+ function handleDeleteBatchPromises(promises, entries, name) {
150
+ return Promise.all(promises.map(async (promise, idx) => {
151
+ let batchNr = (idx + 1 | 0).toString();
152
+ let output;
153
+ try {
154
+ output = await promise;
155
+ } catch (raw_exn) {
156
+ let exn = Primitive_exceptions.internalToException(raw_exn);
157
+ let error = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), exn => Stdlib_JsExn.message(exn)), "unknown error");
158
+ console.log(`Error: SQS.` + name + ` batch ` + batchNr + ` failed: ` + error);
159
+ let start = idx * 10 | 0;
160
+ let end = start + 10 | 0;
161
+ return entries.slice(start, end).map(entry => entry.Id);
162
+ }
163
+ return Stdlib_Option.getOr(output.Failed, []).map(failure => {
164
+ let id = failure.Id;
165
+ let failureCode = failure.Code;
166
+ let failureMessage = Stdlib_Option.getOr(failure.Message, "unknown message");
167
+ console.log(`Error: SQS.` + name + ` batch ` + batchNr + ` entry failed: ` + id + `, ` + failureCode + `, ` + failureMessage);
168
+ return id;
169
+ });
170
+ }));
171
+ }
172
+
173
+ async function deleteMessagesParallel(queueId, entries) {
174
+ let arraySize = Stdlib_Math.Int.ceil(entries.length / 10);
175
+ return handleBatchResult(await handleDeleteBatchPromises(Stdlib_Array.fromInitializer(arraySize, batchNr => {
176
+ let start = batchNr * 10 | 0;
177
+ let end = start + 10 | 0;
178
+ return SQS$AwsSdk.DeleteMessageBatchCommand.send(new ClientSqs.DeleteMessageBatchCommand({
179
+ QueueUrl: queueId,
180
+ Entries: entries.slice(start, end)
181
+ }));
182
+ }), entries, "deleteMessagesParallel"));
183
+ }
184
+
185
+ async function getQueuePolicy(queueArn) {
186
+ let response = await SQS$AwsSdk.GetQueueAttributesCommand.send(new ClientSqs.GetQueueAttributesCommand({
187
+ AttributeNames: ["Policy"],
188
+ QueueUrl: arn2Url(queueArn)
189
+ }));
190
+ return JSON.parse(response.Attributes.Policy);
191
+ }
192
+
193
+ async function setQueuePolicy(queueArn, policy) {
194
+ let newPolicy = JSON.stringify(policy);
195
+ if (newPolicy !== undefined) {
196
+ await SQS$AwsSdk.SetQueueAttributesCommand.send(new ClientSqs.SetQueueAttributesCommand({
197
+ Attributes: {
198
+ Policy: newPolicy
199
+ },
200
+ QueueUrl: arn2Url(queueArn)
201
+ }));
202
+ } else {
203
+ console.log("Couldn't stringify policy");
204
+ }
205
+ }
206
+
207
+ let maxBatchMessages = 10;
208
+
209
+ let maxBatchBytes = 262144;
210
+
211
+ export {
212
+ arn2Url,
213
+ validateDelay,
214
+ sendMessage,
215
+ makeBatchEntry,
216
+ makeBatchEntryFifo,
217
+ maxBatchMessages,
218
+ maxBatchBytes,
219
+ handleSendBatchPromises,
220
+ handleBatchResult,
221
+ sendMessagesParallel,
222
+ handleDeleteBatchPromises,
223
+ deleteMessagesParallel,
224
+ getQueuePolicy,
225
+ setQueuePolicy,
226
+ }
227
+ /* SQS-AwsSdk Not a pure module */
@@ -0,0 +1,61 @@
1
+ /*** @aws-sdk/client-secrets-manager
2
+ see: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/secrets-manager/
3
+ */
4
+ type client
5
+
6
+ type options = {
7
+ region?: string,
8
+ maxAttempts?: int,
9
+ requestHandler?: NodeHttpHandler.t,
10
+ }
11
+
12
+ module Raw = {
13
+ @module("@aws-sdk/client-secrets-manager") @new
14
+ external client: (~options: options, unit) => client = "SecretsManagerClient"
15
+ }
16
+
17
+ let instance = ref(None)
18
+
19
+ let client = () =>
20
+ switch instance.contents {
21
+ | None =>
22
+ let client = Raw.client(
23
+ ~options={
24
+ maxAttempts: 3,
25
+ requestHandler: NodeHttpHandler.make({
26
+ connectionTimeout: 1000,
27
+ requestTimeout: 5000,
28
+ }),
29
+ },
30
+ (),
31
+ )
32
+ instance := Some(client)
33
+ client
34
+ | Some(client) => client
35
+ }
36
+
37
+ module GetSecretValueCommand = {
38
+ type t
39
+
40
+ type input = {
41
+ @as("SecretId") secretId: string,
42
+ @as("VersionId") versionId?: string,
43
+ @as("VersionStage") versionStage?: string,
44
+ }
45
+
46
+ type output = {
47
+ @as("SecretString") secretString: option<string>,
48
+ @as("VersionId") versionId: option<string>,
49
+ @as("VersionStage") versionStage: option<string>,
50
+ }
51
+
52
+ @new @module("@aws-sdk/client-secrets-manager")
53
+ external make: input => t = "GetSecretValueCommand"
54
+
55
+ module Raw = {
56
+ @send
57
+ external send: (client, t) => promise<output> = "send"
58
+ }
59
+
60
+ let send: t => promise<output> = command => Raw.send(client(), command)
61
+ }
@@ -0,0 +1,46 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
4
+ import * as NodeHttpHandler from "@smithy/node-http-handler";
5
+ import * as ClientSecretsManager from "@aws-sdk/client-secrets-manager";
6
+
7
+ let Raw = {};
8
+
9
+ let instance = {
10
+ contents: undefined
11
+ };
12
+
13
+ function client() {
14
+ let client$1 = instance.contents;
15
+ if (client$1 !== undefined) {
16
+ return Primitive_option.valFromOption(client$1);
17
+ }
18
+ let client$2 = new ClientSecretsManager.SecretsManagerClient({
19
+ maxAttempts: 3,
20
+ requestHandler: Primitive_option.some(new NodeHttpHandler.NodeHttpHandler({
21
+ connectionTimeout: 1000,
22
+ requestTimeout: 5000
23
+ }))
24
+ });
25
+ instance.contents = Primitive_option.some(client$2);
26
+ return client$2;
27
+ }
28
+
29
+ let Raw$1 = {};
30
+
31
+ function send(command) {
32
+ return client().send(command);
33
+ }
34
+
35
+ let GetSecretValueCommand = {
36
+ Raw: Raw$1,
37
+ send: send
38
+ };
39
+
40
+ export {
41
+ Raw,
42
+ instance,
43
+ client,
44
+ GetSecretValueCommand,
45
+ }
46
+ /* @smithy/node-http-handler Not a pure module */
@@ -0,0 +1,20 @@
1
+ open DynamoDb_Util
2
+ open DynamoDb_Util_Helpers
3
+
4
+ Console.log("----MARSHALL----")
5
+ type a = {a: int, b: bool}
6
+ let r = MarshallOptions.topLevelContainerConverted(~wrapNumbers=true)
7
+ let test = {a: 42, b: true}->marshall(~options=r)
8
+ Console.log(test) // `{ M: { a: { N: '42' }, b: { BOOL: true } } }`
9
+
10
+ Console.log("----UNMARSHALL----")
11
+ let num = {number: "42"}
12
+ let bool = {bool: true}
13
+ let dict = [("a", num), ("b", bool)]->Dict.fromArray
14
+ let result = unmarshallDict(dict)
15
+ Console.log(result)
16
+ let attrV = {map: dict}
17
+ let result = unmarshall(attrV)
18
+ Console.log(result)
19
+ let result = unmarshall(bool)
20
+ Console.log(result)
@@ -0,0 +1,66 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as DynamoDb_Util$AwsSdk from "../DynamoDb_Util.res.mjs";
4
+ import * as UtilDynamodb from "@aws-sdk/util-dynamodb";
5
+ import * as DynamoDb_Util_Helpers$AwsSdk from "../DynamoDb_Util_Helpers.res.mjs";
6
+
7
+ console.log("----MARSHALL----");
8
+
9
+ let r = DynamoDb_Util$AwsSdk.MarshallOptions.topLevelContainerConverted(undefined, undefined, undefined, true);
10
+
11
+ let test = UtilDynamodb.marshall({
12
+ a: 42,
13
+ b: true
14
+ }, r);
15
+
16
+ console.log(test);
17
+
18
+ console.log("----UNMARSHALL----");
19
+
20
+ let num = {
21
+ N: "42"
22
+ };
23
+
24
+ let bool = {
25
+ BOOL: true
26
+ };
27
+
28
+ let dict = Object.fromEntries([
29
+ [
30
+ "a",
31
+ num
32
+ ],
33
+ [
34
+ "b",
35
+ bool
36
+ ]
37
+ ]);
38
+
39
+ let result = DynamoDb_Util_Helpers$AwsSdk.unmarshallDict(undefined, dict);
40
+
41
+ console.log(result);
42
+
43
+ let attrV_M = dict;
44
+
45
+ let attrV = {
46
+ M: attrV_M
47
+ };
48
+
49
+ let result$1 = DynamoDb_Util_Helpers$AwsSdk.unmarshall(undefined, attrV);
50
+
51
+ console.log(result$1);
52
+
53
+ let result$2 = DynamoDb_Util_Helpers$AwsSdk.unmarshall(undefined, bool);
54
+
55
+ console.log(result$2);
56
+
57
+ export {
58
+ r,
59
+ test,
60
+ num,
61
+ bool,
62
+ dict,
63
+ attrV,
64
+ result$2 as result,
65
+ }
66
+ /* Not a pure module */