@awsless/awsless 0.0.548 → 0.0.549

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.
Binary file
Binary file
@@ -1 +1 @@
1
- d1258c2679b1f5ce95dd7c9c463ab8518a1160f8
1
+ 355b49989570d95758c09af3e91d59c93fcf2284
Binary file
package/dist/server.d.ts CHANGED
@@ -31,6 +31,8 @@ interface FunctionMockResponse {
31
31
  }
32
32
  declare const mockFunction: (cb: (mock: FunctionMock) => void) => FunctionMockResponse;
33
33
 
34
+ declare const mockMetric: () => void;
35
+
34
36
  declare const mockPubSub: () => vitest.Mock<any, any>;
35
37
 
36
38
  interface QueueMock {
@@ -89,6 +91,12 @@ interface InstanceResources {
89
91
  }
90
92
  declare const Instance: InstanceResources;
91
93
 
94
+ declare const getMetricName: (name: string) => string;
95
+ declare const getMetricNamespace: (stack?: string, app?: string) => string;
96
+ interface MetricResources {
97
+ }
98
+ declare const Metric: MetricResources;
99
+
92
100
  declare const getPubSubTopic: <N extends string>(name: N) => `app/pubsub/${N}`;
93
101
 
94
102
  type PublishOptions = {
@@ -163,4 +171,4 @@ declare const Topic: TopicResources;
163
171
  declare const APP: "app";
164
172
  declare const STACK: "stack";
165
173
 
166
- export { APP, Alert, type AlertMock, type AlertMockResponse, type AlertResources, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, Config, type ConfigResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, Instance, type InstanceResources, PubSub, type PublishOptions, Queue, type QueueMock, type QueueMockResponse, type QueueResources, type RpcAuthorizerResponse, STACK, Search, type SearchResources, Store, type StoreResources, Table, type TableResources, Task, type TaskMock, type TaskMockResponse, type TaskResources, Topic, type TopicMock, type TopicMockResponse, type TopicResources, getAlertName, getAuthProps, getCacheProps, getConfigName, getConfigValue, getFunctionName, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockAlert, mockCache, mockFunction, mockPubSub, mockQueue, mockTask, mockTopic, pubsubAuthorizerHandle, pubsubAuthorizerResponse, setConfigValue };
174
+ export { APP, Alert, type AlertMock, type AlertMockResponse, type AlertResources, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, Config, type ConfigResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, Instance, type InstanceResources, Metric, type MetricResources, PubSub, type PublishOptions, Queue, type QueueMock, type QueueMockResponse, type QueueResources, type RpcAuthorizerResponse, STACK, Search, type SearchResources, Store, type StoreResources, Table, type TableResources, Task, type TaskMock, type TaskMockResponse, type TaskResources, Topic, type TopicMock, type TopicMockResponse, type TopicResources, getAlertName, getAuthProps, getCacheProps, getConfigName, getConfigValue, getFunctionName, getMetricName, getMetricNamespace, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockAlert, mockCache, mockFunction, mockMetric, mockPubSub, mockQueue, mockTask, mockTopic, pubsubAuthorizerHandle, pubsubAuthorizerResponse, setConfigValue };
package/dist/server.js CHANGED
@@ -153,6 +153,12 @@ var mockFunction = (cb) => {
153
153
  });
154
154
  };
155
155
 
156
+ // src/lib/mock/metric.ts
157
+ import { mockCloudWatch } from "@awsless/cloudwatch";
158
+ var mockMetric = () => {
159
+ return mockCloudWatch();
160
+ };
161
+
156
162
  // src/lib/mock/pubsub.ts
157
163
  import { mockIoT } from "@awsless/iot";
158
164
  var mockPubSub = () => {
@@ -222,6 +228,11 @@ import { mockScheduler } from "@awsless/scheduler";
222
228
  // src/lib/server/task.ts
223
229
  import { invoke as invoke2 } from "@awsless/lambda";
224
230
  import { schedule } from "@awsless/scheduler";
231
+
232
+ // src/lib/server/on-failure.ts
233
+ var onFailureQueue = bindGlobalResourceName("on-failure")("failure");
234
+
235
+ // src/lib/server/task.ts
225
236
  var getTaskName = bindLocalResourceName("task");
226
237
  var Task = /* @__PURE__ */ createProxy((stackName) => {
227
238
  return createProxy((taskName) => {
@@ -236,8 +247,7 @@ var Task = /* @__PURE__ */ createProxy((stackName) => {
236
247
  schedule: options.schedule,
237
248
  group: resourceTaskName("group"),
238
249
  roleArn: `arn:aws:iam::${process.env.AWS_ACCOUNT_ID}:role/${resourceTaskName("schedule")}`,
239
- deadLetterArn: process.env.ON_FAILURE_QUEUE_ARN
240
- // deadLetterArn: bindGlobalResourceName('on-failure')('failure'),
250
+ deadLetterArn: onFailureQueue
241
251
  });
242
252
  } else {
243
253
  await invoke2({
@@ -440,6 +450,52 @@ var Instance = /* @__PURE__ */ createProxy((stack) => {
440
450
  });
441
451
  });
442
452
 
453
+ // src/lib/server/metric.ts
454
+ import {
455
+ batchPutData,
456
+ createDurationMetric,
457
+ createMetric,
458
+ createSizeMetric,
459
+ putData
460
+ } from "@awsless/cloudwatch";
461
+ import { constantCase as constantCase4, kebabCase as kebabCase3 } from "change-case";
462
+ var getMetricName = (name) => {
463
+ return kebabCase3(name);
464
+ };
465
+ var getMetricNamespace = (stack = STACK, app = APP) => {
466
+ return `awsless/${kebabCase3(app)}/${kebabCase3(stack)}`;
467
+ };
468
+ var Metric = /* @__PURE__ */ createProxy((stack) => {
469
+ if (stack === "batch") {
470
+ return batchPutData;
471
+ }
472
+ return createProxy((metricName) => {
473
+ const name = getMetricName(metricName);
474
+ const namespace = getMetricNamespace(stack);
475
+ const unit = process.env[`METRIC_${constantCase4(metricName)}`];
476
+ if (!unit) {
477
+ throw new TypeError(`Metric "${name}" isn't defined in your stack.`);
478
+ }
479
+ const factories = {
480
+ number: createMetric,
481
+ size: createSizeMetric,
482
+ duration: createDurationMetric
483
+ };
484
+ const metric = factories[unit]({
485
+ name,
486
+ namespace
487
+ });
488
+ return {
489
+ name,
490
+ namespace,
491
+ unit,
492
+ put(value, options) {
493
+ return putData(metric, value, options);
494
+ }
495
+ };
496
+ });
497
+ });
498
+
443
499
  // src/lib/server/pubsub.ts
444
500
  import { hours, toSeconds } from "@awsless/duration";
445
501
  import { publish as publish3, QoS } from "@awsless/iot";
@@ -530,11 +586,11 @@ var pubsubAuthorizerResponse = (props) => {
530
586
 
531
587
  // src/lib/server/search.ts
532
588
  import { define, searchClient } from "@awsless/open-search";
533
- import { constantCase as constantCase4 } from "change-case";
589
+ import { constantCase as constantCase5 } from "change-case";
534
590
  var getSearchName = bindLocalResourceName("search");
535
591
  var getSearchProps = (name, stack = STACK) => {
536
592
  return {
537
- domain: process.env[`SEARCH_${constantCase4(stack)}_${constantCase4(name)}_DOMAIN`]
593
+ domain: process.env[`SEARCH_${constantCase5(stack)}_${constantCase5(name)}_DOMAIN`]
538
594
  };
539
595
  };
540
596
  var Search = /* @__PURE__ */ createProxy((stack) => {
@@ -606,6 +662,7 @@ export {
606
662
  Fn,
607
663
  Function,
608
664
  Instance,
665
+ Metric,
609
666
  PubSub,
610
667
  QoS,
611
668
  Queue,
@@ -621,6 +678,8 @@ export {
621
678
  getConfigName,
622
679
  getConfigValue,
623
680
  getFunctionName,
681
+ getMetricName,
682
+ getMetricNamespace,
624
683
  getPubSubTopic,
625
684
  getQueueName,
626
685
  getQueueUrl,
@@ -634,6 +693,7 @@ export {
634
693
  mockAlert,
635
694
  mockCache,
636
695
  mockFunction,
696
+ mockMetric,
637
697
  mockPubSub,
638
698
  mockQueue,
639
699
  mockTask,