@geek-fun/serverlessinsight 0.3.4 → 0.4.1

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 (43) hide show
  1. package/README.md +209 -21
  2. package/README.zh-CN.md +232 -0
  3. package/dist/package.json +33 -33
  4. package/dist/src/commands/index.js +50 -12
  5. package/dist/src/commands/local.js +6 -3
  6. package/dist/src/commands/template.js +3 -1
  7. package/dist/src/common/constants.js +3 -1
  8. package/dist/src/common/context.js +56 -30
  9. package/dist/src/common/credentials.js +15 -0
  10. package/dist/src/common/iacHelper.js +39 -4
  11. package/dist/src/common/index.d.ts +2 -1
  12. package/dist/src/common/index.js +2 -1
  13. package/dist/src/common/logger.js +6 -0
  14. package/dist/src/common/requestHelper.js +16 -0
  15. package/dist/src/common/rosClient.js +3 -0
  16. package/dist/src/parser/eventParser.js +1 -1
  17. package/dist/src/parser/index.d.ts +2 -1
  18. package/dist/src/parser/index.js +32 -1
  19. package/dist/src/stack/localStack/aliyunFc.js +145 -0
  20. package/dist/src/stack/localStack/bucket.js +226 -0
  21. package/dist/src/stack/localStack/event.js +133 -26
  22. package/dist/src/stack/localStack/function.js +120 -0
  23. package/dist/src/stack/localStack/functionRunner.js +270 -0
  24. package/dist/src/stack/localStack/index.d.ts +4 -1
  25. package/dist/src/stack/localStack/index.js +14 -4
  26. package/dist/src/stack/localStack/localServer.js +111 -0
  27. package/dist/src/stack/localStack/utils.js +36 -0
  28. package/dist/src/stack/rosStack/bootstrap.js +1 -1
  29. package/dist/src/types/localStack/index.d.ts +81 -0
  30. package/dist/src/types/localStack/index.js +10 -0
  31. package/dist/src/validator/iacSchema.js +17 -2
  32. package/dist/src/validator/rootSchema.js +46 -0
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/layers/si-bootstrap-sdk/README.md +63 -0
  35. package/layers/si-bootstrap-sdk/package-lock.json +39 -33
  36. package/layers/si-bootstrap-sdk/package.json +5 -5
  37. package/layers/si-bootstrap-sdk/support/operation-collection/README.md +47 -0
  38. package/layers/si-bootstrap-sdk/support/operation-collection/package-lock.json +298 -0
  39. package/layers/si-bootstrap-sdk/support/operation-collection/package.json +18 -0
  40. package/layers/si-bootstrap-sdk/support/operation-collection/publish.js +257 -0
  41. package/package.json +33 -33
  42. package/samples/aliyun-poc-es.yml +16 -12
  43. package/dist/src/common/domainHelper.js +0 -10
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.invokeFunction = exports.runFunction = void 0;
37
+ const node_fs_1 = require("node:fs");
38
+ const node_path_1 = __importStar(require("node:path"));
39
+ const node_url_1 = require("node:url");
40
+ const node_worker_threads_1 = require("node:worker_threads");
41
+ // ============================================================================
42
+ // Worker Thread Code (runs in worker context)
43
+ // ============================================================================
44
+ const parseHandler = (handler) => {
45
+ const [handlerFile, handlerMethod] = handler.split('.');
46
+ return [handlerFile, handlerMethod];
47
+ };
48
+ const resolveHandlerPath = (codeDir, servicePath, handlerFile) => servicePath
49
+ ? node_path_1.default.resolve(servicePath, codeDir, handlerFile)
50
+ : node_path_1.default.resolve(codeDir, handlerFile);
51
+ const loadHandlerModule = async (handlerPath) => {
52
+ try {
53
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
54
+ return require(handlerPath);
55
+ }
56
+ catch {
57
+ const fileUrl = (0, node_url_1.pathToFileURL)(handlerPath + '.js').href;
58
+ return (await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s))));
59
+ }
60
+ };
61
+ const getHandlerFunction = (handlerModule, handlerMethod, handlerPath) => {
62
+ const handlerFn = handlerModule[handlerMethod];
63
+ if (typeof handlerFn !== 'function') {
64
+ throw new Error(`Handler "${handlerMethod}" not found or is not a function in ${handlerPath}`);
65
+ }
66
+ return handlerFn;
67
+ };
68
+ const invokeHandler = (handlerFn, event, context) => new Promise((resolve, reject) => {
69
+ // Callback-style handler (3+ parameters)
70
+ if (handlerFn.length >= 3) {
71
+ try {
72
+ handlerFn(event, context, (error, result) => {
73
+ return error ? reject(error) : resolve(result);
74
+ });
75
+ }
76
+ catch (error) {
77
+ reject(error);
78
+ }
79
+ }
80
+ else {
81
+ return Promise.resolve(handlerFn(event, context)).then(resolve).catch(reject);
82
+ }
83
+ });
84
+ const createTimeoutHandler = (port, timeoutMs) => {
85
+ const timeoutId = setTimeout(() => {
86
+ port.postMessage(new Error(`Function execution timed out after ${timeoutMs}ms`));
87
+ port.close();
88
+ }, timeoutMs);
89
+ return {
90
+ timeoutId,
91
+ clearTimer: () => clearTimeout(timeoutId),
92
+ };
93
+ };
94
+ const executeHandler = async ({ event, context, port }) => {
95
+ let clearTimer;
96
+ try {
97
+ const wd = node_worker_threads_1.workerData;
98
+ const { codeDir, handler, servicePath, timeout } = wd;
99
+ const timer = createTimeoutHandler(port, timeout);
100
+ clearTimer = timer.clearTimer;
101
+ // Convert Uint8Array back to Buffer if needed (worker thread serialization converts Buffers to Uint8Arrays)
102
+ let actualEvent = event;
103
+ if (event instanceof Uint8Array && !Buffer.isBuffer(event)) {
104
+ actualEvent = Buffer.from(event);
105
+ }
106
+ // Reconstruct logger and tracing function for Aliyun FC contexts
107
+ let actualContext = context;
108
+ if (context &&
109
+ typeof context === 'object' &&
110
+ 'requestId' in context &&
111
+ !('logger' in context) &&
112
+ 'function' in context &&
113
+ 'service' in context) {
114
+ const requestId = context.requestId;
115
+ const formatLog = (level, message) => {
116
+ const timestamp = new Date().toISOString();
117
+ console.log(`${timestamp} ${requestId} [${level}] ${message}`);
118
+ };
119
+ const baseContext = context;
120
+ actualContext = {
121
+ ...baseContext,
122
+ tracing: {
123
+ ...baseContext.tracing,
124
+ parseOpenTracingBaggages: () => ({}),
125
+ },
126
+ logger: {
127
+ debug: (message) => formatLog('DEBUG', message),
128
+ info: (message) => formatLog('INFO', message),
129
+ warn: (message) => formatLog('WARNING', message),
130
+ error: (message) => formatLog('ERROR', message),
131
+ log: (message) => formatLog('INFO', message),
132
+ },
133
+ };
134
+ }
135
+ const [handlerFile, handlerMethod] = parseHandler(handler);
136
+ const handlerPath = resolveHandlerPath(codeDir, servicePath, handlerFile);
137
+ const handlerModule = await loadHandlerModule(handlerPath);
138
+ const handlerFn = getHandlerFunction(handlerModule, handlerMethod, handlerPath);
139
+ const result = await invokeHandler(handlerFn, actualEvent, actualContext);
140
+ clearTimer();
141
+ port.postMessage(result);
142
+ port.close();
143
+ }
144
+ catch (error) {
145
+ if (clearTimer)
146
+ clearTimer();
147
+ port.postMessage(error instanceof Error ? error : new Error(String(error)));
148
+ port.close();
149
+ }
150
+ };
151
+ // Initialize worker thread message handler
152
+ if (!node_worker_threads_1.isMainThread) {
153
+ node_worker_threads_1.parentPort?.on('message', async (message) => {
154
+ try {
155
+ await executeHandler(message);
156
+ }
157
+ catch (error) {
158
+ message.port.postMessage(error instanceof Error ? error : new Error(String(error)));
159
+ message.port.close();
160
+ }
161
+ });
162
+ }
163
+ // ============================================================================
164
+ // Main Thread Code (functional API)
165
+ // ============================================================================
166
+ const resolveWorkerPath = () => {
167
+ const localPath = (0, node_path_1.join)(__dirname, 'functionRunner.js');
168
+ if ((0, node_fs_1.existsSync)(localPath)) {
169
+ return localPath;
170
+ }
171
+ // Fallback to dist directory
172
+ const distPath = __dirname.replace(/src\/stack\/localStack$/, 'dist/src/stack/localStack');
173
+ return (0, node_path_1.join)(distPath, 'functionRunner.js');
174
+ };
175
+ const createWorker = (funOptions, env) => {
176
+ const { codeDir, functionKey, handler, servicePath, timeout } = funOptions;
177
+ const workerPath = resolveWorkerPath();
178
+ return new node_worker_threads_1.Worker(workerPath, {
179
+ env,
180
+ workerData: {
181
+ codeDir,
182
+ functionKey,
183
+ handler,
184
+ servicePath,
185
+ timeout,
186
+ },
187
+ });
188
+ };
189
+ const createMessageHandler = (port, resolve, reject) => {
190
+ let resolved = false;
191
+ const handleMessage = (value) => {
192
+ if (resolved)
193
+ return;
194
+ resolved = true;
195
+ port.close();
196
+ return value instanceof Error ? reject(value) : resolve(value);
197
+ };
198
+ const handleError = (err) => {
199
+ if (resolved)
200
+ return;
201
+ resolved = true;
202
+ port.close();
203
+ reject(err);
204
+ };
205
+ const handleClose = () => {
206
+ if (resolved)
207
+ return;
208
+ resolved = true;
209
+ reject(new Error('Port closed before receiving response'));
210
+ };
211
+ port.on('message', handleMessage).on('error', handleError).on('close', handleClose);
212
+ return () => {
213
+ port.off('message', handleMessage);
214
+ port.off('error', handleError);
215
+ port.off('close', handleClose);
216
+ port.close();
217
+ };
218
+ };
219
+ const sendMessage = (worker, event, context, port2) => {
220
+ worker.postMessage({
221
+ context,
222
+ event,
223
+ port: port2,
224
+ }, [port2]);
225
+ };
226
+ const runFunction = (funOptions, env) => {
227
+ const worker = createWorker(funOptions, env);
228
+ const execute = (event, context) => new Promise((resolve, reject) => {
229
+ const { port1, port2 } = new node_worker_threads_1.MessageChannel();
230
+ const cleanup = createMessageHandler(port1, resolve, reject);
231
+ // Handle worker errors/exit
232
+ const handleWorkerError = (err) => {
233
+ cleanup();
234
+ reject(err);
235
+ };
236
+ const handleWorkerExit = (code) => {
237
+ if (code !== 0) {
238
+ cleanup();
239
+ reject(new Error(`Worker stopped with exit code ${code}`));
240
+ }
241
+ };
242
+ worker.once('error', handleWorkerError);
243
+ worker.once('exit', handleWorkerExit);
244
+ try {
245
+ sendMessage(worker, event, context, port2);
246
+ }
247
+ catch (error) {
248
+ worker.off('error', handleWorkerError);
249
+ worker.off('exit', handleWorkerExit);
250
+ cleanup();
251
+ reject(error instanceof Error ? error : new Error(String(error)));
252
+ }
253
+ });
254
+ const terminate = () => worker.terminate();
255
+ return {
256
+ execute,
257
+ terminate,
258
+ };
259
+ };
260
+ exports.runFunction = runFunction;
261
+ const invokeFunction = async (funOptions, env, event, context) => {
262
+ const runner = (0, exports.runFunction)(funOptions, env);
263
+ try {
264
+ return await runner.execute(event, context);
265
+ }
266
+ finally {
267
+ await runner.terminate();
268
+ }
269
+ };
270
+ exports.invokeFunction = invokeFunction;
@@ -1,2 +1,5 @@
1
+ import { stopLocal } from './localServer';
2
+ import { ServerlessIac } from '../../types';
1
3
  export * from './event';
2
- export declare const startLocalStack: () => Promise<void>;
4
+ export { stopLocal };
5
+ export declare const startLocalStack: (iac: ServerlessIac) => Promise<void>;
@@ -14,10 +14,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.startLocalStack = void 0;
17
+ exports.startLocalStack = exports.stopLocal = void 0;
18
+ const localStack_1 = require("../../types/localStack");
19
+ const localServer_1 = require("./localServer");
20
+ Object.defineProperty(exports, "stopLocal", { enumerable: true, get: function () { return localServer_1.stopLocal; } });
21
+ const event_1 = require("./event");
22
+ const function_1 = require("./function");
23
+ const bucket_1 = require("./bucket");
18
24
  __exportStar(require("./event"), exports);
19
- const startLocalStack = async () => {
20
- // Placeholder for starting local stack logic
21
- console.log('Local stack started');
25
+ const handlers = [
26
+ { kind: localStack_1.RouteKind.SI_FUNCTIONS, handler: function_1.functionsHandler },
27
+ { kind: localStack_1.RouteKind.SI_EVENTS, handler: event_1.eventsHandler },
28
+ { kind: localStack_1.RouteKind.SI_BUCKETS, handler: bucket_1.bucketsHandler },
29
+ ];
30
+ const startLocalStack = async (iac) => {
31
+ await (0, localServer_1.servLocal)(handlers, iac);
22
32
  };
23
33
  exports.startLocalStack = startLocalStack;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stopLocal = exports.servLocal = void 0;
7
+ const localStack_1 = require("../../types/localStack");
8
+ const common_1 = require("../../common");
9
+ const node_http_1 = __importDefault(require("node:http"));
10
+ let localServer;
11
+ const cleanPathSegments = (pathname) => pathname
12
+ .split('/')
13
+ .map((segment) => segment.trim())
14
+ .filter((segment) => segment.length > 0);
15
+ const respondJson = (res, status, body, headers = {}) => {
16
+ res.writeHead(status, { 'Content-Type': 'application/json', ...headers });
17
+ res.end(JSON.stringify(body));
18
+ };
19
+ const respondRaw = (res, status, body, headers = {}) => {
20
+ res.writeHead(status, headers);
21
+ res.end(body);
22
+ };
23
+ const parseRequest = (req) => {
24
+ const url = new URL(req.url ?? '/', 'http://localhost');
25
+ const [routeSegment, identifierSegment, ...rest] = cleanPathSegments(url.pathname);
26
+ if (!routeSegment) {
27
+ return undefined;
28
+ }
29
+ const kindKey = routeSegment.toUpperCase();
30
+ const kind = localStack_1.RouteKind[kindKey];
31
+ if (!kind) {
32
+ return undefined;
33
+ }
34
+ const subPath = rest.length > 0 ? `/${rest.join('/')}` : '/';
35
+ return {
36
+ kind,
37
+ identifier: identifierSegment,
38
+ url: subPath,
39
+ method: req.method ?? 'GET',
40
+ query: Object.fromEntries(url.searchParams.entries()),
41
+ rawUrl: url.pathname,
42
+ };
43
+ };
44
+ const servLocal = async (handlers, iac) => {
45
+ if (localServer) {
46
+ common_1.logger.info(`localServer already running on http://localhost:${common_1.SI_LOCALSTACK_SERVER_PORT}`);
47
+ return;
48
+ }
49
+ localServer = node_http_1.default.createServer(async (req, res) => {
50
+ try {
51
+ const parsed = parseRequest(req);
52
+ if (!parsed) {
53
+ respondJson(res, 404, { error: 'Route not found' });
54
+ return;
55
+ }
56
+ const route = handlers.find((h) => h.kind === parsed.kind);
57
+ if (!route) {
58
+ respondJson(res, 404, { error: `Handler for ${parsed.kind} not registered` });
59
+ return;
60
+ }
61
+ const outcome = await route.handler(req, parsed, iac);
62
+ if (!outcome) {
63
+ respondJson(res, 204, {});
64
+ return;
65
+ }
66
+ // Raw responses (e.g., from bucket handler) include both Content-Type and Content-Length headers
67
+ // and the body is already formatted as a string (not a JSON object)
68
+ const isRawResponse = typeof outcome.body === 'string' &&
69
+ outcome.headers?.['Content-Type'] &&
70
+ outcome.headers?.['Content-Length'];
71
+ if (isRawResponse) {
72
+ respondRaw(res, outcome.statusCode, outcome.body, outcome.headers);
73
+ }
74
+ else {
75
+ respondJson(res, outcome.statusCode, outcome.body ?? {}, outcome.headers);
76
+ }
77
+ }
78
+ catch (err) {
79
+ common_1.logger.error({ err }, 'Local gateway error');
80
+ respondJson(res, 500, { error: 'Local gateway failure' });
81
+ }
82
+ });
83
+ await new Promise((resolve, reject) => {
84
+ localServer.listen(common_1.SI_LOCALSTACK_SERVER_PORT, '0.0.0.0', () => {
85
+ common_1.logger.info(`Local Server listening on http://localhost:${common_1.SI_LOCALSTACK_SERVER_PORT}`);
86
+ resolve();
87
+ });
88
+ localServer.once('error', reject);
89
+ });
90
+ };
91
+ exports.servLocal = servLocal;
92
+ const stopLocal = async () => {
93
+ if (!localServer) {
94
+ common_1.logger.info('localServer is not running');
95
+ return;
96
+ }
97
+ await new Promise((resolve, reject) => {
98
+ localServer.close((err) => {
99
+ if (err) {
100
+ common_1.logger.error({ err }, 'Error stopping localServer');
101
+ reject(err);
102
+ }
103
+ else {
104
+ localServer = undefined;
105
+ common_1.logger.info('localServer stopped');
106
+ resolve();
107
+ }
108
+ });
109
+ });
110
+ };
111
+ exports.stopLocal = stopLocal;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractZipFile = void 0;
7
+ const jszip_1 = __importDefault(require("jszip"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const node_os_1 = __importDefault(require("node:os"));
11
+ const extractZipFile = async (zipPath) => {
12
+ const zipData = node_fs_1.default.readFileSync(zipPath);
13
+ const zip = await jszip_1.default.loadAsync(zipData);
14
+ const tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'si-function-'));
15
+ for (const [relativePath, file] of Object.entries(zip.files)) {
16
+ if (file.dir) {
17
+ node_fs_1.default.mkdirSync(node_path_1.default.join(tempDir, relativePath), { recursive: true });
18
+ }
19
+ else {
20
+ const content = await file.async('nodebuffer');
21
+ const filePath = node_path_1.default.join(tempDir, relativePath);
22
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
23
+ node_fs_1.default.writeFileSync(filePath, content);
24
+ }
25
+ }
26
+ // Check if there's a single root directory in the zip
27
+ const entries = node_fs_1.default.readdirSync(tempDir);
28
+ if (entries.length === 1) {
29
+ const singleEntry = node_path_1.default.join(tempDir, entries[0]);
30
+ if (node_fs_1.default.statSync(singleEntry).isDirectory()) {
31
+ return singleEntry;
32
+ }
33
+ }
34
+ return tempDir;
35
+ };
36
+ exports.extractZipFile = extractZipFile;
@@ -33,7 +33,7 @@ const getBootstrapTemplate = async (context) => {
33
33
  Description: 'ServerlessInsight Bootstrap API',
34
34
  Handler: 'index.handler',
35
35
  Runtime: 'nodejs20',
36
- Layers: [`acs:fc:${context.region}:1990893136649406:layers/si-bootstrap-sdk/versions/18`],
36
+ Layers: [`acs:fc:${context.region}:1990893136649406:layers/si-bootstrap-sdk/versions/26`],
37
37
  Code: {
38
38
  SourceCode: `
39
39
  const { bootstrapHandler } = require('@geek-fun/si-bootstrap-sdk');
@@ -0,0 +1,81 @@
1
+ import { IncomingMessage } from 'node:http';
2
+ import { ServerlessIac } from '../index';
3
+ export declare enum RouteKind {
4
+ SI_FUNCTIONS = "SI_FUNCTIONS",
5
+ SI_BUCKETS = "SI_BUCKETS",
6
+ SI_WEBSITE_BUCKETS = "SI_WEBSITE_BUCKETS",
7
+ SI_EVENTS = "SI_EVENTS"
8
+ }
9
+ export type ParsedRequest = {
10
+ kind: RouteKind;
11
+ identifier: string;
12
+ url: string;
13
+ method: string;
14
+ query: Record<string, string>;
15
+ rawUrl: string;
16
+ };
17
+ export type RouteResponse = {
18
+ statusCode: number;
19
+ headers?: Record<string, string>;
20
+ body?: unknown;
21
+ };
22
+ export type RouteHandler = (req: IncomingMessage, parsed: ParsedRequest, iac: ServerlessIac) => Promise<RouteResponse | void> | RouteResponse | void;
23
+ export type FunctionOptions = {
24
+ codeDir: string;
25
+ functionKey: string;
26
+ handler: string;
27
+ servicePath: string;
28
+ timeout: number;
29
+ };
30
+ export type AliyunApiGatewayContext = {
31
+ requestId: string;
32
+ region: string;
33
+ accountId: string;
34
+ credentials: {
35
+ accessKeyId: string;
36
+ accessKeySecret: string;
37
+ securityToken: string;
38
+ };
39
+ function: {
40
+ name: string;
41
+ handler: string;
42
+ memory: number;
43
+ timeout: number;
44
+ initializer: string;
45
+ };
46
+ service: {
47
+ name: string;
48
+ logProject: string;
49
+ logStore: string;
50
+ qualifier: string;
51
+ versionId: string;
52
+ };
53
+ tracing: {
54
+ spanContext: string;
55
+ jaegerEndpoint: string;
56
+ spanBaggages: Record<string, string>;
57
+ parseOpenTracingBaggages: () => Record<string, string>;
58
+ };
59
+ logger: {
60
+ debug: (message: string) => void;
61
+ info: (message: string) => void;
62
+ warn: (message: string) => void;
63
+ error: (message: string) => void;
64
+ log: (message: string) => void;
65
+ };
66
+ };
67
+ export type AliyunServerlessEvent = {
68
+ path: string;
69
+ httpMethod: string;
70
+ headers: Record<string, string>;
71
+ queryParameters: Record<string, string>;
72
+ pathParameters: Record<string, string>;
73
+ body: string | undefined;
74
+ isBase64Encoded: boolean;
75
+ };
76
+ export type AliyunFCResponse = {
77
+ isBase64Encoded: boolean;
78
+ statusCode: string | number;
79
+ headers?: Record<string, string>;
80
+ body: string | unknown;
81
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouteKind = void 0;
4
+ var RouteKind;
5
+ (function (RouteKind) {
6
+ RouteKind["SI_FUNCTIONS"] = "SI_FUNCTIONS";
7
+ RouteKind["SI_BUCKETS"] = "SI_BUCKETS";
8
+ RouteKind["SI_WEBSITE_BUCKETS"] = "SI_WEBSITE_BUCKETS";
9
+ RouteKind["SI_EVENTS"] = "SI_EVENTS";
10
+ })(RouteKind || (exports.RouteKind = RouteKind = {}));
@@ -14,14 +14,29 @@ const bucketSchema_1 = require("./bucketSchema");
14
14
  const tableschema_1 = require("./tableschema");
15
15
  class IacSchemaErrors extends Error {
16
16
  constructor(errors) {
17
- super(`Invalid yaml`);
18
- this.schemaErrors = errors.map((error) => ({
17
+ const schemaErrors = errors.map((error) => ({
19
18
  instancePath: error.instancePath,
20
19
  schemaPath: error.schemaPath,
21
20
  message: error.message,
22
21
  allowedValues: error.params?.allowedValues,
23
22
  type: error.keyword,
24
23
  }));
24
+ const formattedMessage = schemaErrors
25
+ .map((error, index) => {
26
+ const parts = [
27
+ `Error ${index + 1}:`,
28
+ ` Path: ${error.instancePath || '/'}`,
29
+ ` Type: ${error.type}`,
30
+ ` Message: ${error.message}`,
31
+ ];
32
+ if (error.allowedValues) {
33
+ parts.push(` Allowed values: ${error.allowedValues.join(', ')}`);
34
+ }
35
+ return parts.join('\n');
36
+ })
37
+ .join('\n\n');
38
+ super(`Invalid yaml:\n\n${formattedMessage}`);
39
+ this.schemaErrors = schemaErrors;
25
40
  }
26
41
  get errors() {
27
42
  return this.schemaErrors;
@@ -12,6 +12,52 @@ exports.rootSchema = {
12
12
  name: { type: 'string', enum: ['huawei', 'aliyun'] },
13
13
  region: { type: 'string' },
14
14
  },
15
+ required: ['name', 'region'],
16
+ allOf: [
17
+ {
18
+ if: {
19
+ properties: {
20
+ name: { const: 'aliyun' },
21
+ },
22
+ required: ['name'],
23
+ },
24
+ then: {
25
+ properties: {
26
+ region: {
27
+ type: 'string',
28
+ enum: [
29
+ 'cn-qingdao',
30
+ 'cn-beijing',
31
+ 'cn-zhangjiakou',
32
+ 'cn-huhehaote',
33
+ 'cn-wulanchabu',
34
+ 'cn-hangzhou',
35
+ 'cn-shanghai',
36
+ 'cn-shenzhen',
37
+ 'cn-heyuan',
38
+ 'cn-guangzhou',
39
+ 'cn-chengdu',
40
+ 'cn-hongkong',
41
+ 'ap-southeast-1',
42
+ 'ap-southeast-3',
43
+ 'ap-southeast-5',
44
+ 'ap-southeast-6',
45
+ 'ap-southeast-7',
46
+ 'ap-northeast-1',
47
+ 'ap-northeast-2',
48
+ 'eu-central-1',
49
+ 'eu-west-1',
50
+ 'us-east-1',
51
+ 'us-west-1',
52
+ 'na-south-1',
53
+ 'me-east-1',
54
+ 'me-central-1',
55
+ ],
56
+ },
57
+ },
58
+ },
59
+ },
60
+ ],
15
61
  },
16
62
  service: { type: 'string' },
17
63
  vars: {
@@ -1 +1 @@
1
- {"root":["../src/index.ts","../src/commands/deploy.ts","../src/commands/destroy.ts","../src/commands/index.ts","../src/commands/local.ts","../src/commands/template.ts","../src/commands/validate.ts","../src/common/base64.ts","../src/common/constants.ts","../src/common/context.ts","../src/common/domainHelper.ts","../src/common/getVersion.ts","../src/common/iacHelper.ts","../src/common/imsClient.ts","../src/common/index.ts","../src/common/logger.ts","../src/common/providerEnum.ts","../src/common/rosAssets.ts","../src/common/rosClient.ts","../src/lang/index.ts","../src/parser/bucketParser.ts","../src/parser/databaseParser.ts","../src/parser/eventParser.ts","../src/parser/functionParser.ts","../src/parser/index.ts","../src/parser/tableParser.ts","../src/parser/tagParser.ts","../src/stack/deploy.ts","../src/stack/index.ts","../src/stack/localStack/event.ts","../src/stack/localStack/index.ts","../src/stack/rfsStack/function.ts","../src/stack/rfsStack/index.ts","../src/stack/rosStack/bootstrap.ts","../src/stack/rosStack/bucket.ts","../src/stack/rosStack/database.ts","../src/stack/rosStack/event.ts","../src/stack/rosStack/function.ts","../src/stack/rosStack/index.ts","../src/stack/rosStack/stage.ts","../src/stack/rosStack/table.ts","../src/stack/rosStack/tag.ts","../src/stack/rosStack/vars.ts","../src/types/assets.ts","../src/types/index.ts","../src/types/domains/bucket.ts","../src/types/domains/context.ts","../src/types/domains/database.ts","../src/types/domains/event.ts","../src/types/domains/function.ts","../src/types/domains/provider.ts","../src/types/domains/table.ts","../src/types/domains/tag.ts","../src/types/domains/vars.ts","../src/validator/bucketSchema.ts","../src/validator/databaseSchema.ts","../src/validator/eventSchema.ts","../src/validator/functionSchema.ts","../src/validator/iacSchema.ts","../src/validator/index.ts","../src/validator/rootSchema.ts","../src/validator/tableschema.ts"],"version":"5.9.2"}
1
+ {"root":["../src/index.ts","../src/commands/deploy.ts","../src/commands/destroy.ts","../src/commands/index.ts","../src/commands/local.ts","../src/commands/template.ts","../src/commands/validate.ts","../src/common/base64.ts","../src/common/constants.ts","../src/common/context.ts","../src/common/credentials.ts","../src/common/getVersion.ts","../src/common/iacHelper.ts","../src/common/imsClient.ts","../src/common/index.ts","../src/common/logger.ts","../src/common/providerEnum.ts","../src/common/requestHelper.ts","../src/common/rosAssets.ts","../src/common/rosClient.ts","../src/lang/index.ts","../src/parser/bucketParser.ts","../src/parser/databaseParser.ts","../src/parser/eventParser.ts","../src/parser/functionParser.ts","../src/parser/index.ts","../src/parser/tableParser.ts","../src/parser/tagParser.ts","../src/stack/deploy.ts","../src/stack/index.ts","../src/stack/localStack/aliyunFc.ts","../src/stack/localStack/bucket.ts","../src/stack/localStack/event.ts","../src/stack/localStack/function.ts","../src/stack/localStack/functionRunner.ts","../src/stack/localStack/index.ts","../src/stack/localStack/localServer.ts","../src/stack/localStack/utils.ts","../src/stack/rfsStack/function.ts","../src/stack/rfsStack/index.ts","../src/stack/rosStack/bootstrap.ts","../src/stack/rosStack/bucket.ts","../src/stack/rosStack/database.ts","../src/stack/rosStack/event.ts","../src/stack/rosStack/function.ts","../src/stack/rosStack/index.ts","../src/stack/rosStack/stage.ts","../src/stack/rosStack/table.ts","../src/stack/rosStack/tag.ts","../src/stack/rosStack/vars.ts","../src/types/assets.ts","../src/types/index.ts","../src/types/domains/bucket.ts","../src/types/domains/context.ts","../src/types/domains/database.ts","../src/types/domains/event.ts","../src/types/domains/function.ts","../src/types/domains/provider.ts","../src/types/domains/table.ts","../src/types/domains/tag.ts","../src/types/domains/vars.ts","../src/types/localStack/index.ts","../src/validator/bucketSchema.ts","../src/validator/databaseSchema.ts","../src/validator/eventSchema.ts","../src/validator/functionSchema.ts","../src/validator/iacSchema.ts","../src/validator/index.ts","../src/validator/rootSchema.ts","../src/validator/tableschema.ts"],"version":"5.9.3"}