@faasjs/http 8.0.0-beta.5 → 8.0.0-beta.7

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/dist/index.d.ts CHANGED
@@ -1,164 +1,176 @@
1
- import { Plugin, MountData, Next, InvokeData, UseifyPlugin } from '@faasjs/func';
2
- import { Logger } from '@faasjs/logger';
1
+ import { InvokeData, MountData, Next, Plugin, UseifyPlugin } from "@faasjs/func";
2
+ import { Logger } from "@faasjs/logger";
3
3
 
4
+ //#region src/session.d.ts
4
5
  type SessionOptions = {
5
- key: string;
6
- secret: string;
7
- salt?: string;
8
- signedSalt?: string;
9
- keylen?: number;
10
- iterations?: number;
11
- digest?: string;
12
- cipherName?: string;
6
+ key: string;
7
+ secret: string;
8
+ salt?: string;
9
+ signedSalt?: string;
10
+ keylen?: number;
11
+ iterations?: number;
12
+ digest?: string;
13
+ cipherName?: string;
13
14
  };
14
15
  type SessionContent = string | number | {
15
- [key: string]: any;
16
+ [key: string]: any;
16
17
  } | null | undefined;
17
18
  declare class Session<S extends Record<string, string> = any, C extends Record<string, string> = any> {
18
- content: Record<string, string | number>;
19
- readonly config: {
20
- key: string;
21
- secret: string;
22
- salt: string;
23
- signedSalt: string;
24
- keylen: number;
25
- iterations: number;
26
- digest: string;
27
- cipherName: string;
28
- };
29
- private readonly secret;
30
- private readonly signedSecret;
31
- private readonly cookie;
32
- private changed?;
33
- constructor(cookie: Cookie<C, S>, config: SessionOptions);
34
- invoke(cookie?: string, logger?: Logger): void;
35
- encode(text: SessionContent): string;
36
- decode<TData = any>(text: string): TData | SessionContent;
37
- read(key: string): string | number;
38
- write(key: string, value?: string | number | null): Session<S, C>;
39
- update(): Session<S, C>;
19
+ content: Record<string, string | number>;
20
+ readonly config: {
21
+ key: string;
22
+ secret: string;
23
+ salt: string;
24
+ signedSalt: string;
25
+ keylen: number;
26
+ iterations: number;
27
+ digest: string;
28
+ cipherName: string;
29
+ };
30
+ private readonly secret;
31
+ private readonly signedSecret;
32
+ private readonly cookie;
33
+ private changed?;
34
+ constructor(cookie: Cookie<C, S>, config: SessionOptions);
35
+ invoke(cookie?: string, logger?: Logger): void;
36
+ encode(text: SessionContent): string;
37
+ decode<TData = any>(text: string): TData | SessionContent;
38
+ read(key: string): string | number;
39
+ write(key: string, value?: string | number | null): Session<S, C>;
40
+ update(): Session<S, C>;
40
41
  }
41
-
42
+ //#endregion
43
+ //#region src/cookie.d.ts
42
44
  type CookieOptions = {
45
+ domain?: string;
46
+ path?: string;
47
+ expires?: number;
48
+ secure?: boolean;
49
+ httpOnly?: boolean;
50
+ sameSite?: 'Strict' | 'Lax' | 'None';
51
+ session?: SessionOptions;
52
+ [key: string]: any;
53
+ };
54
+ declare class Cookie<C extends Record<string, string> = any, S extends Record<string, string> = any> {
55
+ session: Session<S, C>;
56
+ content: Record<string, string>;
57
+ readonly config: {
58
+ domain?: string;
59
+ path: string;
60
+ expires: number;
61
+ secure: boolean;
62
+ httpOnly: boolean;
63
+ sameSite?: 'Strict' | 'Lax' | 'None';
64
+ session: SessionOptions;
65
+ };
66
+ logger: Logger | undefined;
67
+ private setCookie;
68
+ constructor(config: CookieOptions, logger?: Logger);
69
+ invoke(cookie: string | undefined, logger: Logger): Cookie<C, S>;
70
+ read(key: string): any;
71
+ write(key: string, value: string | null | undefined, opts?: {
43
72
  domain?: string;
44
73
  path?: string;
45
- expires?: number;
74
+ expires?: number | string;
46
75
  secure?: boolean;
47
76
  httpOnly?: boolean;
48
77
  sameSite?: 'Strict' | 'Lax' | 'None';
49
- session?: SessionOptions;
50
- [key: string]: any;
51
- };
52
- declare class Cookie<C extends Record<string, string> = any, S extends Record<string, string> = any> {
53
- session: Session<S, C>;
54
- content: Record<string, string>;
55
- readonly config: {
56
- domain?: string;
57
- path: string;
58
- expires: number;
59
- secure: boolean;
60
- httpOnly: boolean;
61
- sameSite?: 'Strict' | 'Lax' | 'None';
62
- session: SessionOptions;
63
- };
64
- logger: Logger;
65
- private setCookie;
66
- constructor(config: CookieOptions, logger?: Logger);
67
- invoke(cookie: string | undefined, logger: Logger): Cookie<C, S>;
68
- read(key: string): any;
69
- write(key: string, value: string, opts?: {
70
- domain?: string;
71
- path?: string;
72
- expires?: number | string;
73
- secure?: boolean;
74
- httpOnly?: boolean;
75
- sameSite?: 'Strict' | 'Lax' | 'None';
76
- }): Cookie<C, S>;
77
- headers(): {
78
- 'Set-Cookie'?: string[];
79
- };
78
+ }): Cookie<C, S>;
79
+ headers(): {
80
+ 'Set-Cookie'?: string[];
81
+ };
80
82
  }
81
-
83
+ //#endregion
84
+ //#region src/index.d.ts
82
85
  declare const ContentType: {
83
- [key: string]: string;
86
+ [key: string]: string;
84
87
  };
85
88
  type HttpConfig = {
86
- [key: string]: any;
87
- name?: string;
88
- config?: {
89
- [key: string]: any;
90
- /** POST as default */
91
- method?: 'BEGIN' | 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PUT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'ANY';
92
- timeout?: number;
93
- /** file relative path as default */
94
- path?: string;
95
- ignorePathPrefix?: string;
96
- functionName?: string;
97
- cookie?: CookieOptions;
98
- };
89
+ [key: string]: any;
90
+ name?: string;
91
+ config?: {
92
+ [key: string]: any; /** POST as default */
93
+ method?: 'BEGIN' | 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PUT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'ANY';
94
+ timeout?: number; /** file relative path as default */
95
+ path?: string;
96
+ ignorePathPrefix?: string;
97
+ functionName?: string;
98
+ cookie?: CookieOptions;
99
+ };
99
100
  };
100
101
  type Response = {
101
- statusCode?: number;
102
- headers?: {
103
- [key: string]: string;
104
- };
105
- body?: string | ReadableStream;
106
- message?: string;
102
+ statusCode?: number;
103
+ headers?: {
104
+ [key: string]: string;
105
+ };
106
+ body?: string | ReadableStream;
107
+ message?: string;
107
108
  };
108
109
  declare class HttpError extends Error {
109
- readonly statusCode: number;
110
- readonly message: string;
111
- constructor({ statusCode, message, }: {
112
- statusCode?: number;
113
- message: string;
114
- });
110
+ readonly statusCode: number;
111
+ readonly message: string;
112
+ constructor({
113
+ statusCode,
114
+ message
115
+ }: {
116
+ statusCode?: number;
117
+ message: string;
118
+ });
115
119
  }
116
120
  declare class Http<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any> implements Plugin {
117
- readonly type = "http";
118
- readonly name: string;
119
- headers: {
120
- [key: string]: string;
121
- };
122
- body: any;
123
- params: TParams;
124
- cookie: Cookie<TCookie, TSession>;
125
- session: Session<TSession, TCookie>;
126
- config: HttpConfig;
127
- private response;
128
- constructor(config?: HttpConfig);
129
- onMount(data: MountData, next: Next): Promise<void>;
130
- onInvoke(data: InvokeData, next: Next): Promise<void>;
131
- /**
132
- * set header
133
- * @param key {string} key
134
- * @param value {string} value
135
- */
136
- setHeader(key: string, value: string): Http<TParams, TCookie, TSession>;
137
- /**
138
- * set Content-Type
139
- * @param type {string} 类型
140
- * @param charset {string} 编码
141
- */
142
- setContentType(type: string, charset?: string): Http<TParams, TCookie, TSession>;
143
- /**
144
- * set status code
145
- * @param code {number} 状态码
146
- */
147
- setStatusCode(code: number): Http<TParams, TCookie, TSession>;
148
- /**
149
- * set body
150
- * @param body {*} 内容
151
- */
152
- setBody(body: string): Http<TParams, TCookie, TSession>;
121
+ readonly type = "http";
122
+ readonly name: string;
123
+ headers: {
124
+ [key: string]: string;
125
+ };
126
+ body: any;
127
+ params: TParams;
128
+ cookie: Cookie<TCookie, TSession>;
129
+ session: Session<TSession, TCookie>;
130
+ config: HttpConfig;
131
+ private response;
132
+ constructor(config?: HttpConfig);
133
+ onMount(data: MountData, next: Next): Promise<void>;
134
+ onInvoke(data: InvokeData, next: Next): Promise<void>;
135
+ /**
136
+ * set header
137
+ * @param key {string} key
138
+ * @param value {string} value
139
+ */
140
+ setHeader(key: string, value: string): Http<TParams, TCookie, TSession>;
141
+ /**
142
+ * set Content-Type
143
+ * @param type {string} 类型
144
+ * @param charset {string} 编码
145
+ */
146
+ setContentType(type: string, charset?: string): Http<TParams, TCookie, TSession>;
147
+ /**
148
+ * set status code
149
+ * @param code {number} 状态码
150
+ */
151
+ setStatusCode(code: number): Http<TParams, TCookie, TSession>;
152
+ /**
153
+ * set body
154
+ * @param body {*} 内容
155
+ */
156
+ setBody(body: string): Http<TParams, TCookie, TSession>;
153
157
  }
154
158
  declare function useHttp<TParams extends Record<string, any> = any, TCookie extends Record<string, string> = any, TSession extends Record<string, string> = any>(config?: HttpConfig): UseifyPlugin<Http<TParams, TCookie, TSession>>;
155
- type HttpFuncHandler<TParams extends Record<string, any> = Record<string, any>, TCookie extends Record<string, string> = Record<string, string>, TSession extends Record<string, any> = Record<string, any>, TResult = any> = (data: InvokeData<{
156
- [key: string]: any;
157
- params?: TParams;
158
- }> & {
159
- params?: TParams;
160
- cookie?: Cookie<TCookie, TSession>;
161
- session?: Session<TSession, TCookie>;
162
- }) => Promise<TResult>;
163
-
164
- export { ContentType, Cookie, type CookieOptions, Http, type HttpConfig, HttpError, type HttpFuncHandler, type Response, Session, type SessionOptions, useHttp };
159
+ declare module '@faasjs/func' {
160
+ interface FaasPluginEventMap {
161
+ http: {
162
+ headers?: Record<string, any>;
163
+ body?: any;
164
+ params?: Record<string, any>;
165
+ queryString?: Record<string, any>;
166
+ httpMethod?: string;
167
+ path?: string;
168
+ raw?: {
169
+ request?: unknown;
170
+ response?: unknown;
171
+ };
172
+ };
173
+ }
174
+ }
175
+ //#endregion
176
+ export { ContentType, Cookie, type CookieOptions, Http, HttpConfig, HttpError, Response, Session, type SessionContent, type SessionOptions, useHttp };