Skip to content

Commit

Permalink
feat(runtime): add ts lsp server and enhance module require (#1621)
Browse files Browse the repository at this point in the history
* feat(runtime): add ts lsp server and enhance module require

* chore(server): ban relative path in function name

* chore(runtime): add global definition

* fix return msg

* fix(runtime): fix global type definitions

* fix(runtime): fix relative path of cloud function imports

---------

Co-authored-by: maslow <[email protected]>
  • Loading branch information
0fatal and maslow authored Nov 1, 2023
1 parent 62cc5a7 commit 15f8fe2
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 57 deletions.
2 changes: 1 addition & 1 deletion runtimes/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export appid=your-app-id
telepresence intercept $appid -n laf-runtime -p 8000:8000 -e $(pwd)/.env

# after intercept command, you can use following command to check if intercept active
telepresence list -n $appid
telepresence list -n laf-runtime

# Start local service first, required nodejs version >= 18.0.0
npm install
Expand Down
93 changes: 93 additions & 0 deletions runtimes/nodejs/functions/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
declare class FunctionConsole {
private _logs
get logs(): any[]
log(...params: any[]): void
}

interface File {
fieldname: string
originalname: string
encoding: string
mimetype: string
size: number
destination: string
filename: string
path: string
}

/**
* Params of cloud function
*/
interface FunctionContext {
/**
* payload object parsed from JWT token
*/
user?: any

/**
* files uploaded
*/
files?: File[]

/**
* HTTP headers
*/
headers?: IncomingHttpHeaders

/**
* HTTP query params
* @see https://expressjs.com/en/4x/api.html#req.query
*/
query?: {
[key: string]: string
}

/**
* HTTP body data
* @see https://expressjs.com/en/4x/api.html#req.body
*/
body?: any

/**
* HTTP request id
*/
requestId?: string

/**
* HTTP methods
*/
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'WebSocket:connection' | 'WebSocket:close' | 'WebSocket:message' | 'WebSocket:error'

/**
* Response object of express
* @see https://expressjs.com/en/4x/api.html#res
*/
response: HttpResponse

/**
* WebSocket object
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
*/
socket?: WebSocket
}

interface IModule {
exports: IExports
}

interface IExports {
/**
* 主函数,云函数的入口函数
*/
main: (ctx: FunctionContext) => any
}

declare const module: IModule
declare const exports: IExports
declare const console: FunctionConsole
declare const global: typeof globalThis

/**
* 主函数,云函数的入口函数
*/
declare function main(ctx: FunctionContext): any
12 changes: 12 additions & 0 deletions runtimes/nodejs/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["./*"]
}
},
"include": [
"./*"
]
}
Loading

0 comments on commit 15f8fe2

Please sign in to comment.