This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Enhance skygear cloud type definition #9
Open
limouren
wants to merge
4
commits into
oursky:master
Choose a base branch
from
limouren:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,15 @@ declare module "skygear" { | |
constructor(name: string); | ||
} | ||
|
||
// NOTE(limouren): Node doesn't have Blob. Copy the type definition here to | ||
// make tsc happy. | ||
// https://github.com/Microsoft/TypeScript/blob/8794ebdff5c00a92bb197a5afba02d573681538e/src/lib/dom.generated.d.ts#L2233 | ||
interface Blob { | ||
readonly size: number; | ||
readonly type: string; | ||
slice(start?: number, end?: number, contentType?: string): Blob; | ||
} | ||
|
||
// NOTE(louis): I do not want to copy this but | ||
// in react native environment we cannot use --lib DOM | ||
// so File is undefined. | ||
|
@@ -490,6 +499,9 @@ declare module "skygear" { | |
} | ||
|
||
declare module "skygear/cloud" { | ||
import { Fields, Files } from "formidable"; | ||
import { Url } from "url"; | ||
|
||
export interface OpParams { | ||
action: string; | ||
args: Array<any>; | ||
|
@@ -536,26 +548,82 @@ declare module "skygear/cloud" { | |
options?: EventOptions | ||
): void; | ||
|
||
export interface handlerOptions { | ||
export function handler( | ||
path: string, | ||
func: HandlerFunc, | ||
options?: HandlerOptions | ||
): void; | ||
|
||
export type HandlerFunc = ( | ||
req: SkygearRequest, | ||
options: HandlerFunc.Options | ||
) => any; | ||
export namespace HandlerFunc { | ||
interface Options { | ||
context: { [key: string]: any }; | ||
container: CloudCodeContainer; | ||
} | ||
} | ||
|
||
export interface HandlerOptions { | ||
method?: string[] | string; | ||
keyRequired?: boolean; | ||
userRequired?: boolean; | ||
} | ||
|
||
export type handlerReq = any; | ||
export class SkygearRequest { | ||
constructor(param: SkygearRequest.Param); | ||
|
||
export type handlerFuncOptions = any; | ||
header: { [key: string]: string }; | ||
method: string; | ||
path: string; | ||
queryString: string; | ||
body: string; | ||
url: Url; | ||
|
||
export type handlerFunc = ( | ||
req: handlerReq, | ||
options: handlerFuncOptions | ||
) => any; | ||
query: string; | ||
json: any; | ||
|
||
export function handler( | ||
path: string, | ||
func: handlerFunc, | ||
options?: handlerOptions | ||
): void; | ||
form(callback: SkygearRequest.FormCallback): void; | ||
} | ||
export namespace SkygearRequest { | ||
interface Param { | ||
header: { [key: string]: string }; | ||
method: string; | ||
path: string; | ||
query_string: string; | ||
body: string; | ||
url: string; | ||
} | ||
|
||
// it is the callback from formidable parse | ||
type FormCallback = (err: any, fields: Fields, files: Files) => any; | ||
} | ||
|
||
export class SkygearResponse { | ||
constructor(options: SkygearResponse.Options); | ||
|
||
setHeader(name: string, value: string): void; | ||
getHeader(name: string): string | undefined; | ||
removeHeader(name: string): void; | ||
|
||
write(chunk: string): void; | ||
|
||
toResultJSON(): { [key: string]: any }; | ||
} | ||
export namespace SkygearResponse { | ||
interface Options { | ||
headers?: { [key: string]: string }; | ||
statusCode?: number; | ||
body?: string; | ||
} | ||
|
||
interface ResultJSON { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unused in this commit. |
||
header: { [key: string]: string }; | ||
status: number; | ||
body: string; | ||
} | ||
} | ||
|
||
export type ProviderCls = Function; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,13 @@ | |
"version": "0.4.0", | ||
"main": "index.js", | ||
"license": "Apache-2.0", | ||
"files": ["index.d.ts"], | ||
"files": [ | ||
"index.d.ts" | ||
], | ||
"dependencies": { | ||
"@types/formidable": "*", | ||
"@types/node": "*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can avoid |
||
}, | ||
"devDependencies": { | ||
"typescript": "2.9.2" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,24 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@types/events@*": | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" | ||
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== | ||
|
||
"@types/formidable@*": | ||
version "1.0.31" | ||
resolved "https://registry.yarnpkg.com/@types/formidable/-/formidable-1.0.31.tgz#274f9dc2d0a1a9ce1feef48c24ca0859e7ec947b" | ||
integrity sha512-dIhM5t8lRP0oWe2HF8MuPvdd1TpPTjhDMAqemcq6oIZQCBQTovhBAdTQ5L5veJB4pdQChadmHuxtB0YzqvfU3Q== | ||
dependencies: | ||
"@types/events" "*" | ||
"@types/node" "*" | ||
|
||
"@types/node@*": | ||
version "11.9.5" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.9.5.tgz#011eece9d3f839a806b63973e228f85967b79ed3" | ||
integrity sha512-vVjM0SVzgaOUpflq4GYBvCpozes8OgIIS5gVXVka+OfK3hvnkC1i93U8WiY2OtNE4XUWyyy/86Kf6e0IHTQw1Q== | ||
|
||
[email protected]: | ||
version "2.9.2" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the definition is small enough that we can copy instead.
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/formidable/index.d.ts#L32
I would like to reduce the number of dependencies.