@awsless/awsless 0.0.666 → 0.0.667
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/dist/app.json +1 -1
- package/dist/app.stage.json +1 -1
- package/dist/bin.js +986 -416
- package/dist/build-json-schema.js +302 -177
- package/dist/prebuild/icon/bundle.zip +0 -0
- package/dist/prebuild/image/bundle.zip +0 -0
- package/dist/prebuild/on-error-log/bundle.zip +0 -0
- package/dist/prebuild/on-failure/bundle.zip +0 -0
- package/dist/prebuild/rpc/bundle.zip +0 -0
- package/dist/server.d.ts +12 -1
- package/dist/server.js +88 -9
- package/dist/stack.json +1 -1
- package/dist/stack.stage.json +1 -1
- package/package.json +15 -14
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/server.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ type CommandContext = {
|
|
|
18
18
|
};
|
|
19
19
|
type CommandHandler = (context: CommandContext) => Promise<void>;
|
|
20
20
|
|
|
21
|
+
interface JobMock {
|
|
22
|
+
}
|
|
23
|
+
interface JobMockResponse {
|
|
24
|
+
}
|
|
25
|
+
declare const mockJob: (cb: (mock: JobMock) => void) => JobMockResponse;
|
|
26
|
+
|
|
21
27
|
interface AlertMock {
|
|
22
28
|
}
|
|
23
29
|
interface AlertMockResponse {
|
|
@@ -54,6 +60,11 @@ interface TopicMockResponse {
|
|
|
54
60
|
}
|
|
55
61
|
declare const mockTopic: (cb: (mock: TopicMock) => void) => TopicMockResponse;
|
|
56
62
|
|
|
63
|
+
declare const getJobName: <N extends string, S extends string = "stack">(resourceName: N, stackName?: S) => `app--${S}--job--${N}`;
|
|
64
|
+
interface JobResources {
|
|
65
|
+
}
|
|
66
|
+
declare const Job: JobResources;
|
|
67
|
+
|
|
57
68
|
declare const getAlertName: <N extends string>(resourceName: N) => `app--alert--${N}`;
|
|
58
69
|
interface AlertResources {
|
|
59
70
|
}
|
|
@@ -191,4 +202,4 @@ declare const Topic: TopicResources;
|
|
|
191
202
|
declare const APP: "app";
|
|
192
203
|
declare const STACK: "stack";
|
|
193
204
|
|
|
194
|
-
export { APP, Alert, type AlertMock, type AlertMockResponse, type AlertResources, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, Config, type ConfigResources, Cron, type CronResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, 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, getCronName, getFunctionName, getMetricName, getMetricNamespace, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockAlert, mockCache, mockFunction, mockMetric, mockPubSub, mockQueue, mockTask, mockTopic, onErrorLogSchema, onFailureBucketArn, onFailureBucketName, onFailureQueueArn, onFailureQueueName, pubsubAuthorizerHandle, pubsubAuthorizerResponse, setConfigValue };
|
|
205
|
+
export { APP, Alert, type AlertMock, type AlertMockResponse, type AlertResources, Auth, type AuthResources, Cache, type CacheResources, type CommandContext, type CommandHandler, Config, type ConfigResources, Cron, type CronResources, Fn, Function, type FunctionMock, type FunctionMockResponse, type FunctionResources, Job, type JobMock, type JobMockResponse, type JobResources, 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, getCronName, getFunctionName, getJobName, getMetricName, getMetricNamespace, getPubSubTopic, getQueueName, getQueueUrl, getSearchName, getSearchProps, getSiteBucketName, getStoreName, getTableName, getTaskName, getTopicName, mockAlert, mockCache, mockFunction, mockJob, mockMetric, mockPubSub, mockQueue, mockTask, mockTopic, onErrorLogSchema, onFailureBucketArn, onFailureBucketName, onFailureQueueArn, onFailureQueueName, pubsubAuthorizerHandle, pubsubAuthorizerResponse, setConfigValue };
|
package/dist/server.js
CHANGED
|
@@ -2,12 +2,8 @@ import {
|
|
|
2
2
|
createProxy
|
|
3
3
|
} from "./chunk-2LRBH7VV.js";
|
|
4
4
|
|
|
5
|
-
// src/lib/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
// src/lib/server/alert.ts
|
|
9
|
-
import { stringify } from "@awsless/json";
|
|
10
|
-
import { publish } from "@awsless/sns";
|
|
5
|
+
// src/lib/server/job.ts
|
|
6
|
+
import { ECSClient, RunTaskCommand } from "@aws-sdk/client-ecs";
|
|
11
7
|
|
|
12
8
|
// src/lib/server/util.ts
|
|
13
9
|
import { kebabCase } from "change-case";
|
|
@@ -56,7 +52,87 @@ var bindGlobalResourceName = (resourceType) => {
|
|
|
56
52
|
};
|
|
57
53
|
};
|
|
58
54
|
|
|
55
|
+
// src/lib/server/job.ts
|
|
56
|
+
var getJobName = bindLocalResourceName("job");
|
|
57
|
+
var client = new ECSClient({});
|
|
58
|
+
var Job = /* @__PURE__ */ createProxy((stackName) => {
|
|
59
|
+
return createProxy((jobName) => {
|
|
60
|
+
const name = getJobName(jobName, stackName);
|
|
61
|
+
const ctx = {
|
|
62
|
+
[name]: async (payload) => {
|
|
63
|
+
const cluster = `${APP}-job`;
|
|
64
|
+
const subnets = JSON.parse(process.env.JOB_SUBNETS);
|
|
65
|
+
const securityGroup = process.env.JOB_SECURITY_GROUP;
|
|
66
|
+
const result = await client.send(
|
|
67
|
+
new RunTaskCommand({
|
|
68
|
+
cluster,
|
|
69
|
+
taskDefinition: name,
|
|
70
|
+
capacityProviderStrategy: [
|
|
71
|
+
{
|
|
72
|
+
capacityProvider: "FARGATE_SPOT",
|
|
73
|
+
weight: 1
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
networkConfiguration: {
|
|
77
|
+
awsvpcConfiguration: {
|
|
78
|
+
subnets,
|
|
79
|
+
securityGroups: [securityGroup],
|
|
80
|
+
assignPublicIp: "ENABLED"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
overrides: {
|
|
84
|
+
containerOverrides: [
|
|
85
|
+
{
|
|
86
|
+
name: `container-${jobName}`,
|
|
87
|
+
environment: [
|
|
88
|
+
{ name: "PAYLOAD", value: JSON.stringify(payload) }
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
count: 1
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
if (result.failures && result.failures.length > 0) {
|
|
97
|
+
const { reason, detail } = result.failures[0];
|
|
98
|
+
throw new Error(`Job RunTask failed: ${reason}${detail ? ` - ${detail}` : ""}`);
|
|
99
|
+
}
|
|
100
|
+
return { taskArn: result.tasks?.[0]?.taskArn };
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return ctx[name];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// src/lib/mock/job.ts
|
|
108
|
+
var mockJob = (cb) => {
|
|
109
|
+
const list = {};
|
|
110
|
+
const mock = createProxy((stack) => {
|
|
111
|
+
return createProxy((name) => {
|
|
112
|
+
return (handle) => {
|
|
113
|
+
list[getJobName(name, stack)] = vi.fn(handle);
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
cb(mock);
|
|
118
|
+
beforeEach && beforeEach(() => {
|
|
119
|
+
for (const item of Object.values(list)) {
|
|
120
|
+
item.mockClear();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return createProxy((stack) => {
|
|
124
|
+
return createProxy((name) => {
|
|
125
|
+
return list[getJobName(name, stack)];
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/lib/mock/alert.ts
|
|
131
|
+
import { mockSNS } from "@awsless/sns";
|
|
132
|
+
|
|
59
133
|
// src/lib/server/alert.ts
|
|
134
|
+
import { stringify } from "@awsless/json";
|
|
135
|
+
import { publish } from "@awsless/sns";
|
|
60
136
|
var getAlertName = bindGlobalResourceName("alert");
|
|
61
137
|
var Alert = /* @__PURE__ */ createProxy((name) => {
|
|
62
138
|
const topic = getAlertName(name);
|
|
@@ -681,13 +757,13 @@ var getSearchProps = (name, stack = STACK) => {
|
|
|
681
757
|
var Search = /* @__PURE__ */ createProxy((stack) => {
|
|
682
758
|
return createProxy((name) => {
|
|
683
759
|
const { domain } = getSearchProps(name, stack);
|
|
684
|
-
let
|
|
760
|
+
let client2;
|
|
685
761
|
return {
|
|
686
762
|
domain,
|
|
687
763
|
defineTable(tableName, schema) {
|
|
688
764
|
return define(tableName, schema, () => {
|
|
689
|
-
if (!
|
|
690
|
-
return
|
|
765
|
+
if (!client2) client2 = searchClient({ node: `https://${domain}` }, "es");
|
|
766
|
+
return client2;
|
|
691
767
|
});
|
|
692
768
|
}
|
|
693
769
|
};
|
|
@@ -747,6 +823,7 @@ export {
|
|
|
747
823
|
Cron,
|
|
748
824
|
Fn,
|
|
749
825
|
Function,
|
|
826
|
+
Job,
|
|
750
827
|
Metric,
|
|
751
828
|
PubSub,
|
|
752
829
|
QoS,
|
|
@@ -764,6 +841,7 @@ export {
|
|
|
764
841
|
getConfigValue,
|
|
765
842
|
getCronName,
|
|
766
843
|
getFunctionName,
|
|
844
|
+
getJobName,
|
|
767
845
|
getMetricName,
|
|
768
846
|
getMetricNamespace,
|
|
769
847
|
getPubSubTopic,
|
|
@@ -779,6 +857,7 @@ export {
|
|
|
779
857
|
mockAlert,
|
|
780
858
|
mockCache,
|
|
781
859
|
mockFunction,
|
|
860
|
+
mockJob,
|
|
782
861
|
mockMetric,
|
|
783
862
|
mockPubSub,
|
|
784
863
|
mockQueue,
|