Compare commits
No commits in common. "master" and "dev" have entirely different histories.
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,44 @@
|
|||
declare const _default: ({
|
||||
header: string;
|
||||
content: string;
|
||||
optionList?: undefined;
|
||||
} | {
|
||||
header: string;
|
||||
optionList: ({
|
||||
name: string;
|
||||
description: string;
|
||||
type: StringConstructor;
|
||||
alias?: undefined;
|
||||
} | {
|
||||
name: string;
|
||||
description: string;
|
||||
alias: string;
|
||||
type: StringConstructor;
|
||||
} | {
|
||||
name: string;
|
||||
description: string;
|
||||
type: BooleanConstructor;
|
||||
alias?: undefined;
|
||||
})[];
|
||||
content?: undefined;
|
||||
} | {
|
||||
header: string;
|
||||
optionList: {
|
||||
name: string;
|
||||
description: string;
|
||||
alias: string;
|
||||
type: BooleanConstructor;
|
||||
}[];
|
||||
content?: undefined;
|
||||
} | {
|
||||
header: string;
|
||||
content: string[];
|
||||
optionList?: undefined;
|
||||
} | {
|
||||
header: string;
|
||||
content: {
|
||||
example: string;
|
||||
}[];
|
||||
optionList?: undefined;
|
||||
})[];
|
||||
export default _default;
|
|
@ -0,0 +1,10 @@
|
|||
export default class ComponentLogger {
|
||||
static CONTENT: string;
|
||||
static setContent(content: any): void;
|
||||
static log(m: any, color?: 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'whiteBright' | 'gray'): void;
|
||||
static info(m: any): void;
|
||||
static debug(m: any): void;
|
||||
static error(m: any): void;
|
||||
static warning(m: any): void;
|
||||
static success(m: any): void;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export default class StdoutFormatter {
|
||||
static stdoutFormatter: any;
|
||||
static initStdout(): Promise<void>;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { InputProps } from './interface/entity';
|
||||
export default class FcRemoteInvoke {
|
||||
/**
|
||||
* event 函数本地调试
|
||||
* @param inputs
|
||||
* @returns
|
||||
*/
|
||||
invoke(inputs: InputProps): Promise<any>;
|
||||
private report;
|
||||
private handlerInputs;
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,34 @@
|
|||
export interface ICredentials {
|
||||
AccountID?: string;
|
||||
AccessKeyID?: string;
|
||||
AccessKeySecret?: string;
|
||||
SecurityToken?: string;
|
||||
}
|
||||
export interface InputProps {
|
||||
props?: IProperties;
|
||||
credentials: ICredentials;
|
||||
appName: string;
|
||||
project: {
|
||||
component: string;
|
||||
access: string;
|
||||
projectName: string;
|
||||
};
|
||||
command: string;
|
||||
args: string;
|
||||
path: {
|
||||
configPath: string;
|
||||
};
|
||||
}
|
||||
export interface IProperties {
|
||||
region: string;
|
||||
serviceName: string;
|
||||
functionName: string;
|
||||
qualifier?: string;
|
||||
domainName?: string;
|
||||
}
|
||||
export declare function isProperties(args: any): args is IProperties;
|
||||
export interface IEventPayload {
|
||||
event?: string;
|
||||
eventFile?: string;
|
||||
eventStdin?: boolean;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export default class File {
|
||||
static getEvent(eventFile: any): Promise<unknown>;
|
||||
static eventPriority(eventPriority: any): Promise<any>;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export default function handlerBody(contentType: string, body: any): any;
|
|
@ -0,0 +1,32 @@
|
|||
import { IProperties, IEventPayload } from '../interface/entity';
|
||||
export default class RemoteInvoke {
|
||||
fcClient: any;
|
||||
accountId: string;
|
||||
constructor(fcClient: any, accountId: string);
|
||||
invoke(props: IProperties, eventPayload: IEventPayload, { invocationType }: {
|
||||
invocationType: any;
|
||||
}): Promise<void>;
|
||||
requestDomain(url: string, event: string): Promise<void>;
|
||||
getHttpTrigger(serviceName: any, functionName: any): Promise<any>;
|
||||
eventInvoke({ serviceName, functionName, event, qualifier, invocationType }: {
|
||||
serviceName: any;
|
||||
functionName: any;
|
||||
event: any;
|
||||
qualifier?: string;
|
||||
invocationType: any;
|
||||
}): Promise<void>;
|
||||
httpInvoke({ region, serviceName, functionName, event, qualifier }: {
|
||||
region: any;
|
||||
serviceName: any;
|
||||
functionName: any;
|
||||
event: any;
|
||||
qualifier: any;
|
||||
}): Promise<void>;
|
||||
/**
|
||||
* @param event: { body, headers, method, queries, path }
|
||||
* path 组装后的路径 /proxy/serviceName/functionName/path ,
|
||||
*/
|
||||
request(event: any): Promise<void>;
|
||||
private showLog;
|
||||
private getJsonEvent;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/// <reference types="node" />
|
||||
export declare function getStdin(): Promise<string>;
|
||||
export declare namespace getStdin {
|
||||
var buffer: () => Promise<Buffer>;
|
||||
}
|
13
package.json
13
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "fc-remote-invoke",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.18",
|
||||
"description": "This is a component demo for Serverless Devs Tool ",
|
||||
"keywords": [
|
||||
"Serverless",
|
||||
|
@ -13,7 +13,7 @@
|
|||
"author": "Serverless-Devs",
|
||||
"contributors": [],
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
|
@ -24,12 +24,11 @@
|
|||
"scripts": {
|
||||
"start": "npm run watch",
|
||||
"watch": "tsc -w",
|
||||
"prebuild": "rm -rf node_modules && rm -rf package-lock.json && npm i && rimraf dist",
|
||||
"esbuild": "esbuild src/index.ts --bundle --log-level=error --minify --platform=node --format=cjs --target=node10.4 --external:@serverless-devs/core --outfile=dist/index.js",
|
||||
"build": "npm run esbuild"
|
||||
"prebuild": "rm -rf node_modules && rm -rf package-lock.json && npm i && rimraf lib",
|
||||
"build": "ncc build src/index.ts -m -e @serverless-devs/core -o lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@serverless-devs/core": "latest",
|
||||
"@serverless-devs/core": "^0.0.*",
|
||||
"form-data": "^4.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"got": "^11.8.2",
|
||||
|
@ -47,6 +46,6 @@
|
|||
"ts-node": "^8.10.2",
|
||||
"typedoc": "^0.20.35",
|
||||
"typescript": "^3.9.7",
|
||||
"esbuild": "^0.14.0"
|
||||
"@vercel/ncc": "^0.24.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ Type: Component
|
|||
Name: fc-remote-invoke
|
||||
Provider:
|
||||
- 其它
|
||||
Version: 0.0.23
|
||||
Version: 0.0.18
|
||||
Description: 初始化component模板
|
||||
HomePage: https://www.serverless-devs.com
|
||||
Tags: #标签详情
|
||||
|
|
24
src/index.ts
24
src/index.ts
|
@ -15,12 +15,10 @@ export default class FcRemoteInvoke {
|
|||
async invoke(inputs: InputProps): Promise<any> {
|
||||
const {
|
||||
props,
|
||||
timeout,
|
||||
eventPayload,
|
||||
credentials,
|
||||
isHelp,
|
||||
invocationType,
|
||||
statefulAsyncInvocationId,
|
||||
} = await this.handlerInputs(inputs);
|
||||
await this.report('fc-remote-invoke', 'invoke', credentials?.AccountID);
|
||||
|
||||
|
@ -32,10 +30,10 @@ export default class FcRemoteInvoke {
|
|||
let fcClient;
|
||||
if (!props.domainName) {
|
||||
const fcCommon = await core.loadComponent('devsapp/fc-common');
|
||||
fcClient = await fcCommon.makeFcClient({ ...inputs, props: { region: props.region, timeout }});
|
||||
fcClient = await fcCommon.makeFcClient(inputs);
|
||||
}
|
||||
const remoteInvoke = new RemoteInvoke(fcClient, credentials.AccountID);
|
||||
await remoteInvoke.invoke(props, eventPayload, { invocationType, statefulAsyncInvocationId });
|
||||
await remoteInvoke.invoke(props, eventPayload, { invocationType });
|
||||
}
|
||||
|
||||
private async report(componentName: string, command: string, accountID: string): Promise<void> {
|
||||
|
@ -52,13 +50,11 @@ export default class FcRemoteInvoke {
|
|||
|
||||
const parsedArgs: {[key: string]: any} = core.commandParse({ ...inputs, args }, {
|
||||
boolean: ['help', 'event-stdin'],
|
||||
number: ['timeout'],
|
||||
string: ['invocation-type', 'event', 'event-file', 'region', 'domain-name','service-name', 'function-name', 'qualifier', 'stateful-async-invocation-id'],
|
||||
string: ['invocation-type', 'event', 'event-file', 'region', 'domain-name','service-name', 'function-name', 'qualifier'],
|
||||
alias: {
|
||||
'help': 'h',
|
||||
'event': 'e',
|
||||
'event-file': 'f',
|
||||
'event-stdin': 's',
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -77,7 +73,6 @@ export default class FcRemoteInvoke {
|
|||
'event-stdin': eventStdin,
|
||||
'invocation-type': invocationType = 'sync',
|
||||
'domain-name': domainName,
|
||||
'stateful-async-invocation-id': statefulAsyncInvocationId,
|
||||
} = argsData;
|
||||
const eventPayload = { event, eventFile, eventStdin };
|
||||
// @ts-ignore: 判断三个值有几个真
|
||||
|
@ -110,25 +105,12 @@ export default class FcRemoteInvoke {
|
|||
throw new Error('region/serviceName(service-name)/functionName(function-name) can not be empty.');
|
||||
}
|
||||
|
||||
// 超时时间获取的原理:https://github.com/devsapp/fc/issues/480
|
||||
const propsTimeout = argsData.timeout || inputs.props?.timeout;
|
||||
let timeout = 600;
|
||||
if (_.isNumber(propsTimeout)) {
|
||||
if (_.isEmpty(inputs.props?.runtime) || inputs.props?.runtime === 'custom-container') {
|
||||
timeout = propsTimeout + 7 * 60;
|
||||
} else {
|
||||
timeout = propsTimeout + 2 * 60;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
props,
|
||||
timeout,
|
||||
credentials: inputs.credentials,
|
||||
eventPayload,
|
||||
isHelp: false,
|
||||
invocationType: _.upperFirst(invocationType),
|
||||
statefulAsyncInvocationId,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,8 @@ export interface IProperties {
|
|||
region: string;
|
||||
serviceName: string;
|
||||
functionName: string;
|
||||
runtime?: string;
|
||||
qualifier?: string;
|
||||
domainName?: string;
|
||||
timeout?: string;
|
||||
}
|
||||
export function isProperties(args: any): args is IProperties {
|
||||
if (!args) {
|
||||
|
|
|
@ -13,7 +13,7 @@ export default class RemoteInvoke {
|
|||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType, statefulAsyncInvocationId }) {
|
||||
async invoke (props: IProperties, eventPayload: IEventPayload, { invocationType }) {
|
||||
const event = await Event.eventPriority(eventPayload);
|
||||
logger.debug(`event: ${event}`);
|
||||
|
||||
|
@ -32,7 +32,6 @@ export default class RemoteInvoke {
|
|||
const payload: any = { event, serviceName, functionName, qualifier };
|
||||
if (_.isEmpty(httpTriggers)) {
|
||||
payload.invocationType = invocationType;
|
||||
payload.statefulAsyncInvocationId = statefulAsyncInvocationId;
|
||||
payload.event = event;
|
||||
await this.eventInvoke(payload);
|
||||
} else {
|
||||
|
@ -75,15 +74,13 @@ export default class RemoteInvoke {
|
|||
functionName,
|
||||
event,
|
||||
qualifier = 'LATEST',
|
||||
invocationType,
|
||||
statefulAsyncInvocationId
|
||||
invocationType
|
||||
}) {
|
||||
|
||||
if (invocationType === 'Sync') {
|
||||
const rs = await this.fcClient.invokeFunction(serviceName, functionName, event, {
|
||||
'X-Fc-Log-Type': 'Tail',
|
||||
'X-Fc-Invocation-Code-Version': 'Latest',
|
||||
'X-Fc-Invocation-Type': invocationType,
|
||||
'X-Fc-Invocation-Type': invocationType
|
||||
}, qualifier);
|
||||
|
||||
this.showLog(rs.headers['x-fc-log-result']);
|
||||
|
@ -91,11 +88,8 @@ export default class RemoteInvoke {
|
|||
console.log(rs.data);
|
||||
console.log('\n');
|
||||
} else {
|
||||
logger.debug(`Stateful async invocation id: ${statefulAsyncInvocationId}`);
|
||||
const { headers } = await this.fcClient.invokeFunction(serviceName, functionName, event, {
|
||||
'X-Fc-Invocation-Code-Version': 'Latest',
|
||||
'X-Fc-Invocation-Type': invocationType,
|
||||
'X-Fc-Stateful-Async-Invocation-Id': statefulAsyncInvocationId || "",
|
||||
'X-Fc-Invocation-Type': invocationType
|
||||
}, qualifier);
|
||||
const rId = headers['x-fc-request-id'];
|
||||
|
||||
|
@ -120,9 +114,6 @@ export default class RemoteInvoke {
|
|||
if (!headers['X-Fc-Log-Type']) {
|
||||
headers['X-Fc-Log-Type'] = 'Tail';
|
||||
}
|
||||
if (!headers['X-Fc-Invocation-Code-Version']) {
|
||||
headers['X-Fc-Invocation-Code-Version'] = 'Latest';
|
||||
}
|
||||
|
||||
let resp;
|
||||
try {
|
||||
|
@ -155,14 +146,14 @@ export default class RemoteInvoke {
|
|||
|
||||
if (resp?.err) {
|
||||
this.showLog(resp.headers['x-fc-log-result']);
|
||||
logger.log(`\nFC Invoke Result[Code: ${resp.code}]:`, 'red');
|
||||
logger.log(`\nFC Invoke Result[code: ${resp.code}]:`, 'red');
|
||||
console.log(resp.data);
|
||||
console.log('\n');
|
||||
} else {
|
||||
if (resp) {
|
||||
this.showLog(resp.headers['x-fc-log-result']);
|
||||
|
||||
logger.log(`\nFC Invoke Result[Code: ${resp.code}]:`, 'green');
|
||||
logger.log('\nFC Invoke Result[code: ${resp.code}]:', 'green');
|
||||
console.log(resp.data);
|
||||
console.log('\n');
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
"./node_modules/@types"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
"outDir": "lib"
|
||||
},
|
||||
"exclude": [
|
||||
"**/node_modules/**",
|
||||
|
|
Loading…
Reference in New Issue