@awsless/awsless 0.0.666 → 0.0.668
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 +976 -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 +83 -9
- package/dist/stack.json +1 -1
- package/dist/stack.stage.json +1 -1
- package/package.json +13 -12
|
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,82 @@ 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
|
+
launchType: "FARGATE",
|
|
71
|
+
networkConfiguration: {
|
|
72
|
+
awsvpcConfiguration: {
|
|
73
|
+
subnets,
|
|
74
|
+
securityGroups: [securityGroup],
|
|
75
|
+
assignPublicIp: "ENABLED"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
overrides: {
|
|
79
|
+
containerOverrides: [
|
|
80
|
+
{
|
|
81
|
+
name: `container-${jobName}`,
|
|
82
|
+
environment: [
|
|
83
|
+
{ name: "PAYLOAD", value: JSON.stringify(payload) }
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
count: 1
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
if (result.failures && result.failures.length > 0) {
|
|
92
|
+
const { reason, detail } = result.failures[0];
|
|
93
|
+
throw new Error(`Job RunTask failed: ${reason}${detail ? ` - ${detail}` : ""}`);
|
|
94
|
+
}
|
|
95
|
+
return { taskArn: result.tasks?.[0]?.taskArn };
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return ctx[name];
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// src/lib/mock/job.ts
|
|
103
|
+
var mockJob = (cb) => {
|
|
104
|
+
const list = {};
|
|
105
|
+
const mock = createProxy((stack) => {
|
|
106
|
+
return createProxy((name) => {
|
|
107
|
+
return (handle) => {
|
|
108
|
+
list[getJobName(name, stack)] = vi.fn(handle);
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
cb(mock);
|
|
113
|
+
beforeEach && beforeEach(() => {
|
|
114
|
+
for (const item of Object.values(list)) {
|
|
115
|
+
item.mockClear();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return createProxy((stack) => {
|
|
119
|
+
return createProxy((name) => {
|
|
120
|
+
return list[getJobName(name, stack)];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/lib/mock/alert.ts
|
|
126
|
+
import { mockSNS } from "@awsless/sns";
|
|
127
|
+
|
|
59
128
|
// src/lib/server/alert.ts
|
|
129
|
+
import { stringify } from "@awsless/json";
|
|
130
|
+
import { publish } from "@awsless/sns";
|
|
60
131
|
var getAlertName = bindGlobalResourceName("alert");
|
|
61
132
|
var Alert = /* @__PURE__ */ createProxy((name) => {
|
|
62
133
|
const topic = getAlertName(name);
|
|
@@ -681,13 +752,13 @@ var getSearchProps = (name, stack = STACK) => {
|
|
|
681
752
|
var Search = /* @__PURE__ */ createProxy((stack) => {
|
|
682
753
|
return createProxy((name) => {
|
|
683
754
|
const { domain } = getSearchProps(name, stack);
|
|
684
|
-
let
|
|
755
|
+
let client2;
|
|
685
756
|
return {
|
|
686
757
|
domain,
|
|
687
758
|
defineTable(tableName, schema) {
|
|
688
759
|
return define(tableName, schema, () => {
|
|
689
|
-
if (!
|
|
690
|
-
return
|
|
760
|
+
if (!client2) client2 = searchClient({ node: `https://${domain}` }, "es");
|
|
761
|
+
return client2;
|
|
691
762
|
});
|
|
692
763
|
}
|
|
693
764
|
};
|
|
@@ -747,6 +818,7 @@ export {
|
|
|
747
818
|
Cron,
|
|
748
819
|
Fn,
|
|
749
820
|
Function,
|
|
821
|
+
Job,
|
|
750
822
|
Metric,
|
|
751
823
|
PubSub,
|
|
752
824
|
QoS,
|
|
@@ -764,6 +836,7 @@ export {
|
|
|
764
836
|
getConfigValue,
|
|
765
837
|
getCronName,
|
|
766
838
|
getFunctionName,
|
|
839
|
+
getJobName,
|
|
767
840
|
getMetricName,
|
|
768
841
|
getMetricNamespace,
|
|
769
842
|
getPubSubTopic,
|
|
@@ -779,6 +852,7 @@ export {
|
|
|
779
852
|
mockAlert,
|
|
780
853
|
mockCache,
|
|
781
854
|
mockFunction,
|
|
855
|
+
mockJob,
|
|
782
856
|
mockMetric,
|
|
783
857
|
mockPubSub,
|
|
784
858
|
mockQueue,
|