Skip to content

Commit

Permalink
fix: 修复开发控制台 IDE 默认无 mongodb 类型提供的问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Aug 9, 2021
1 parent dcdac4e commit e75ae8c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,50 @@ interface File {
}
/**
* 云函数调用入参
*/
interface FunctionContext {
/**
* auth 对象解析自 JWT Token Payload
*/
auth?: {
uid?: string
}
/**
* 上传到云函数的文件
*/
files?: File[];
/**
* HTTP headers
*/
headers?: IncomingHttpHeaders;
/**
* HTTP Query 参数 (URL 参数),JSON 对象
*/
query?: any;
/**
* HTTP Body 参数, JSON 对象
*/
body?: any;
/**
* Trigger 调用时为触发器所带参数
*/
params?: any;
auth?: any;
/**
* HTTP Request ID
*/
requestId?: string;
/**
* 调用方法:GET | POST | PUT | DELETE | TRIGGER
*/
method?: string;
}
Expand All @@ -37,11 +70,17 @@ interface IModule {
}
interface IExports {
/**
* 主函数,云函数的入口函数
*/
main: (ctx: FunctionContext) => any
}
declare const module: IModule
declare const exports: IExports
declare const console: FunctionConsole
/**
* 主函数,云函数的入口函数
*/
declare function main(ctx: FunctionContext): any;
`
23 changes: 14 additions & 9 deletions packages/devops-admin/src/components/FunctionEditor/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class AutoImportTypings {
if (!this.isLoaded('less-api-database')) { this.loadDeclaration('less-api-database') }
if (!this.isLoaded('axios')) { this.loadDeclaration('axios') }
if (!this.isLoaded('cloud-function-engine')) { this.loadDeclaration('cloud-function-engine') }
if (!this.isLoaded('mongodb')) { this.loadDeclaration('mongodb') }
}

/**
Expand All @@ -77,17 +78,21 @@ export class AutoImportTypings {
* @returns
*/
async loadDeclaration(packageName) {
const r = await loadPackageTypings(packageName)
if (r.code) {
return
}
try {
const r = await loadPackageTypings(packageName)
if (r.code) {
return
}

const rets = r.data || []
for (const lib of rets) {
this.addExtraLib(lib)
}
const rets = r.data || []
for (const lib of rets) {
this.addExtraLib(lib)
}

this._loaded.push(packageName)
this._loaded.push(packageName)
} catch (error) {
console.error(`failed to load package: ${packageName} :`, error)
}
}

/**
Expand Down

0 comments on commit e75ae8c

Please sign in to comment.