Skip to content

Commit

Permalink
Merge pull request #2 from fleetfn/types
Browse files Browse the repository at this point in the history
Create the new fleetfn/types package
  • Loading branch information
matuzalemsteles authored Dec 31, 2020
2 parents 0c524b8 + d95813a commit 25da2f7
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/types/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Fleet FN, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
96 changes: 96 additions & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
export interface FleetRequest {
/**
* The body
*/
body: any;

/**
* The function name that was defined in the fleet.yml manifest
*/
functionName: string;

/**
* Uid of the function
*/
functionUid: string;

/**
* The request headers object
* - Key-value pairs of header names and values. Header names are lower-cased.
*/
headers: {[k: string]: any};

/**
* Hostname of the incoming request
*/
hostname: string;

/**
* Method of the incoming request
* - GET
* - POST
* - PUT
* - PATCH
* - HEAD
* - OPTIONS
* - DELETE
*/
method: string;

/**
* Parsed querystring
*/
query: {[k: string]: any};

/**
* This contains only the URL that is present in the actual HTTP request.
*/
url: string;
}

export interface FleetResponse {
/**
* Sets the status code. By default it is 200.
*/
code: (code: number) => FleetResponse;

/**
* Retrieves the header defined before.
*/
getHeader: (key: string) => string;

/**
* Check if a header has been set.
*/
hasHeader: (key: string) => boolean;

/**
* Redirect to the specified URL, code is optional (Default value 302).
*/
redirect: (url: string, code: number) => void;

/**
* Remove the value of a previously set header.
*/
removeHeader: (key: string) => FleetResponse;

/**
* Sends the payload to the user, it can be plain text, a buffer, JSON or an Error object.
*/
send: (payload?: any) => void;

/**
* Sets a custom serializer for the payload.
*/
serializer: (fn: Function) => FleetResponse;

/**
* Sets a response header.
*/
setHeader: (key: string, value: any) => FleetResponse;

/**
* Sets the header Content-Type.
*/
type: (type: string) => FleetResponse;
}
10 changes: 10 additions & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@fleetfn/types",
"description": "TypeScript definitions for Fleet",
"version": "1.0.0-alpha.1",
"author": "Fleet FN, Inc",
"main": "",
"types": "index.d.ts",
"license": "MIT",
"typeScriptVersion": "3.2"
}
18 changes: 18 additions & 0 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"files": [
"index.d.ts",
],
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "./",
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}

0 comments on commit 25da2f7

Please sign in to comment.