effortless-aws 0.20.0 → 0.22.0

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.
@@ -126,13 +126,49 @@ var createTableClient = (tableName, options) => {
126
126
  if (setClauses.length) parts.push(`SET ${setClauses.join(", ")}`);
127
127
  if (removeClauses.length) parts.push(`REMOVE ${removeClauses.join(", ")}`);
128
128
  if (!parts.length) return;
129
- await getClient2().updateItem({
129
+ const request = {
130
130
  TableName: tableName,
131
131
  Key: marshallKey(key),
132
132
  UpdateExpression: parts.join(" "),
133
133
  ExpressionAttributeNames: names,
134
134
  ...Object.keys(values).length ? { ExpressionAttributeValues: marshall(values, { removeUndefinedValues: true }) } : {}
135
- });
135
+ };
136
+ try {
137
+ await getClient2().updateItem(request);
138
+ } catch (err) {
139
+ if (needsDataAlias && err.name === "ValidationException") {
140
+ const dataMap = {};
141
+ if (actions.set) Object.assign(dataMap, actions.set);
142
+ if (actions.append) Object.assign(dataMap, actions.append);
143
+ const retryNames = { "#data": "data" };
144
+ const retryValues = { ":fullData": dataMap };
145
+ const retrySets = ["#data = :fullData"];
146
+ if (actions.tag !== void 0) {
147
+ retryNames["#tag"] = "tag";
148
+ retryValues[":tagVal"] = actions.tag;
149
+ retrySets.push("#tag = :tagVal");
150
+ }
151
+ if (actions.ttl !== void 0 && actions.ttl !== null) {
152
+ retryNames["#ttl"] = "ttl";
153
+ retryValues[":ttlVal"] = actions.ttl;
154
+ retrySets.push("#ttl = :ttlVal");
155
+ }
156
+ const retryParts = [`SET ${retrySets.join(", ")}`];
157
+ if (actions.ttl === null) {
158
+ retryNames["#ttl"] = "ttl";
159
+ retryParts.push("REMOVE #ttl");
160
+ }
161
+ await getClient2().updateItem({
162
+ TableName: tableName,
163
+ Key: marshallKey(key),
164
+ UpdateExpression: retryParts.join(" "),
165
+ ExpressionAttributeNames: retryNames,
166
+ ExpressionAttributeValues: marshall(retryValues, { removeUndefinedValues: true })
167
+ });
168
+ } else {
169
+ throw err;
170
+ }
171
+ }
136
172
  },
137
173
  async query(params) {
138
174
  const names = { "#pk": "pk" };
@@ -282,6 +318,56 @@ var createEmailClient = () => {
282
318
  };
283
319
  };
284
320
 
321
+ // src/runtime/queue-client.ts
322
+ import { SQS } from "@aws-sdk/client-sqs";
323
+ var createQueueClient = (queueName) => {
324
+ let client2 = null;
325
+ const getClient2 = () => client2 ??= new SQS({});
326
+ let resolvedUrl;
327
+ const getQueueUrl = async () => {
328
+ if (resolvedUrl) return resolvedUrl;
329
+ const result = await getClient2().getQueueUrl({ QueueName: `${queueName}.fifo` });
330
+ resolvedUrl = result.QueueUrl;
331
+ return resolvedUrl;
332
+ };
333
+ return {
334
+ queueName,
335
+ async send(input) {
336
+ const queueUrl = await getQueueUrl();
337
+ await getClient2().sendMessage({
338
+ QueueUrl: queueUrl,
339
+ MessageBody: JSON.stringify(input.body),
340
+ MessageGroupId: input.groupId,
341
+ ...input.deduplicationId ? { MessageDeduplicationId: input.deduplicationId } : {},
342
+ ...input.messageAttributes ? {
343
+ MessageAttributes: Object.fromEntries(
344
+ Object.entries(input.messageAttributes).map(([k, v]) => [k, {
345
+ DataType: v.dataType,
346
+ StringValue: v.stringValue
347
+ }])
348
+ )
349
+ } : {}
350
+ });
351
+ },
352
+ async sendBatch(messages) {
353
+ const queueUrl = await getQueueUrl();
354
+ const entries = messages.map((msg, i) => ({
355
+ Id: String(i),
356
+ MessageBody: JSON.stringify(msg.body),
357
+ MessageGroupId: msg.groupId,
358
+ ...msg.deduplicationId ? { MessageDeduplicationId: msg.deduplicationId } : {}
359
+ }));
360
+ const result = await getClient2().sendMessageBatch({
361
+ QueueUrl: queueUrl,
362
+ Entries: entries
363
+ });
364
+ if (result.Failed && result.Failed.length > 0) {
365
+ throw new Error(`Failed to send ${result.Failed.length} message(s): ${result.Failed.map((f) => f.Message).join(", ")}`);
366
+ }
367
+ }
368
+ };
369
+ };
370
+
285
371
  // src/runtime/ssm-client.ts
286
372
  import { SSM } from "@aws-sdk/client-ssm";
287
373
  var client = null;
@@ -319,7 +405,8 @@ var DEP_FACTORIES = {
319
405
  return createTableClient(name, tagField ? { tagField } : void 0);
320
406
  },
321
407
  bucket: (name) => createBucketClient(name),
322
- mailer: () => createEmailClient()
408
+ mailer: () => createEmailClient(),
409
+ queue: (name) => createQueueClient(name)
323
410
  };
324
411
  var parseDepValue = (raw) => {
325
412
  const idx = raw.indexOf(":");