@fastly/expressly 1.0.0-alpha.3 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,11 +17,11 @@ First, head over to [developer.fastly.com](https://developer.fastly.com) to get
17
17
  Install expressly from the [npm registry](https://www.npmjs.com/package/@fastly/expressly):
18
18
 
19
19
  ```shell
20
- npm i @fastly/expressly@1.0.0-alpha.3
20
+ npm i @fastly/expressly@1.0.0-alpha.4
21
21
  ```
22
22
 
23
23
  ```shell
24
- yarn add @fastly/expressly@1.0.0-alpha.3
24
+ yarn add @fastly/expressly@1.0.0-alpha.4
25
25
  ```
26
26
 
27
27
  ### Your first expressly app
@@ -1,8 +1,7 @@
1
1
  /// <reference types="@fastly/js-compute" />
2
- import { ECommonObject } from "../common";
3
2
  import { CookieMap } from "./cookie-map";
4
3
  import { EConfig } from "..";
5
- export declare class ERequest extends ECommonObject {
4
+ export declare class ERequest extends Request {
6
5
  private config;
7
6
  private event;
8
7
  readonly clientInfo: ClientInfo;
@@ -15,14 +14,17 @@ export declare class ERequest extends ECommonObject {
15
14
  };
16
15
  cookies: CookieMap;
17
16
  constructor(config: EConfig, event: FetchEvent);
18
- get url(): string;
19
17
  get path(): string;
20
18
  get ip(): string;
21
19
  get protocol(): string;
22
20
  get secure(): boolean;
23
21
  get subdomains(): Array<string>;
24
22
  get hostname(): string;
25
- json(): Promise<any>;
26
- text(): Promise<string>;
27
- arrayBuffer(): Promise<ArrayBuffer>;
23
+ set(headerNameOrObject: string | {
24
+ [key: string]: string;
25
+ }, value?: string): void;
26
+ private appendHeader;
27
+ append(headerNameOrObject: string | {
28
+ [key: string]: string | string[];
29
+ }, value?: string | string[]): void;
28
30
  }
@@ -1,25 +1,23 @@
1
- import { ECommonObject } from "../common";
2
1
  import { CookieMap } from "./cookie-map";
3
- export class ERequest extends ECommonObject {
2
+ export class ERequest extends Request {
4
3
  constructor(config, event) {
5
- super();
4
+ super(event.request);
6
5
  this.config = config;
7
6
  this.event = event;
8
7
  this.params = {};
9
8
  this.clientInfo = event.client;
10
- this.method = event.request.method;
11
9
  this.urlObj = new URL(event.request.url);
12
10
  this.query = this.urlObj.searchParams;
13
- this.headers = event.request.headers;
14
11
  // Parse cookies.
15
12
  if (this.config.parseCookie) {
16
13
  this.cookies = new CookieMap(this.headers);
17
14
  }
18
15
  }
19
16
  // Express-like URL helpers.
20
- get url() {
21
- return this.urlObj.toString();
22
- }
17
+ // get url(): string {
18
+ // console.log("custom getter");
19
+ // return this.urlObj.toString();
20
+ // }
23
21
  get path() {
24
22
  return this.urlObj.pathname;
25
23
  }
@@ -38,13 +36,35 @@ export class ERequest extends ECommonObject {
38
36
  get hostname() {
39
37
  return this.urlObj.hostname;
40
38
  }
41
- async json() {
42
- return await this.event.request.json();
39
+ // Header helpers.
40
+ set(headerNameOrObject, value) {
41
+ if (typeof headerNameOrObject === "string") {
42
+ this.headers.set(headerNameOrObject, value);
43
+ }
44
+ else {
45
+ Object.keys(headerNameOrObject).forEach((headerName) => {
46
+ this.headers.set(headerName, headerNameOrObject[headerName]);
47
+ });
48
+ }
43
49
  }
44
- async text() {
45
- return await this.event.request.text();
50
+ appendHeader(headerName, headerValue) {
51
+ if (typeof headerValue === "string") {
52
+ this.headers.append(headerName, headerValue);
53
+ }
54
+ else if (Array.isArray(headerValue)) {
55
+ headerValue.forEach((v) => {
56
+ this.headers.append(headerName, v);
57
+ });
58
+ }
46
59
  }
47
- async arrayBuffer() {
48
- return await this.event.request.arrayBuffer();
60
+ append(headerNameOrObject, value) {
61
+ if (typeof headerNameOrObject === "string") {
62
+ this.appendHeader(headerNameOrObject, value);
63
+ }
64
+ else {
65
+ Object.keys(headerNameOrObject).forEach((headerName) => {
66
+ this.appendHeader(headerName, headerNameOrObject[headerName]);
67
+ });
68
+ }
49
69
  }
50
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastly/expressly",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "Express-style router for Fastly's Compute@Edge.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",