Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Logger from '@faasjs/logger';
import { existsSync } from 'fs';
import { sep } from 'path';
import New from './commands/new';
import Deploy from './commands/deploy';
import Server from './commands/server';
require('ts-node').register({
project: process.cwd() + '/tsconfig.json',
compilerOptions: {
module: 'commonjs'
}
});
const commander: Command = new Command();
const logger = new Logger('Cli');
// 设置命令
commander
.version('beta')
.usage('[command] [flags]')
.option('-v --verbose', '显示调试日志')
.option('-r --root
constructor (data: DeployData) {
data.name = data.filename.replace(data.root, '').replace('.func.ts', '').replace(/^\/?[^/]+\//, '').replace(/\/$/, '');
data.version = new Date().toLocaleString('zh-CN', {
hour12: false,
timeZone: 'Asia/Shanghai',
}).replace(/(\/|:|\s)/g, '_');
data.logger = new Logger('Deployer');
const Config = loadConfig(data.root, data.filename);
if (!data.env) {
data.env = process.env.FaasEnv || Config.defaults.deploy.env;
}
data.config = Config[data.env!];
if (!data.config) {
throw Error(`Config load failed: ${data.env}`);
}
data.tmp = `${data.root}/tmp/${data.env}/${data.name}/${data.version}/`;
data.tmp.split('/').reduce(function (acc: string, cur: string) {
constructor (config: {
plugins?: Plugin[];
handler: Handler;
}) {
this.logger = new Logger('Func');
if (typeof config.handler !== 'function') {
throw Error('Unknown handler');
}
this.handler = config.handler;
this.plugins = config.plugins || [];
this.plugins.push(new RunHandler());
this.config = {
providers: Object.create(null),
plugins: Object.create(null)
};
this.mounted = false;
this.cachedFunctions = Object.create(null);
}
constructor (config?: {
name?: string;
adapterType?: string;
config?: SqlConfig;
}) {
this.type = 'sql';
if (config) {
this.name = config.name || 'sql';
this.adapterType = config.adapterType;
this.config = config.config || Object.create(null);
} else {
this.name = 'sql';
this.config = Object.create(null);
}
this.logger = new Logger('Sql');
}
export function action (type: string, name: string, plguins: string[]) {
const logger = new Logger();
switch (type) {
case 'func':
newFunc(logger, name, plguins);
break;
default:
logger.error(`Unknown type: ${type} (should be func)`);
break;
}
}
constructor (config: CloudFunctionConfig = Object.create(null)) {
this.logger = new Logger('CloudFunction');
this.type = 'cloud_function';
this.name = config.name;
this.config = config.config || Object.create(null);
if (config.validator) {
this.validatorConfig = config.validator;
}
}
constructor (config: {
event?: ValidatorConfig;
}) {
this.eventConfig = config.event;
this.logger = new Logger('CloudFunction.Validator');
}
import * as http from 'http';
import * as https from 'https';
import { stringify } from 'querystring';
import * as URL from 'url';
import Logger from '@faasjs/logger';
const log = new Logger('request');
export interface Request {
headers?: http.OutgoingHttpHeaders;
method?: string;
host?: string;
path?: string;
query?: http.OutgoingHttpHeaders;
body?: any;
}
export interface Response {
request?: Request;
statusCode?: number;
statusMessage?: string;
headers: http.OutgoingHttpHeaders;
body: any;
constructor (config: TencentcloudConfig) {
this.config = config;
this.logger = new Logger('Tencentcloud');
}
/**
constructor (root: string, opts?: {
cache: boolean;
}) {
this.root = root.endsWith(sep) ? root : root + sep;
this.logger = new Logger('Server');
this.opts = Object.assign({
cache: false
}, opts || {});
this.cachedFuncs = {};
this.logger.debug('init with %s %o', this.root, this.opts);
}