@faasjs/http 0.0.2-beta.361 → 0.0.2-beta.365
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 +215 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +48 -103
- package/dist/index.mjs +48 -116
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,9 +1,221 @@
|
|
|
1
1
|
# @faasjs/http
|
|
2
2
|
|
|
3
|
-
http 插件
|
|
4
|
-
|
|
5
3
|
[](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/http/LICENSE)
|
|
6
4
|
[](https://www.npmjs.com/package/@faasjs/http)
|
|
7
5
|
[](https://www.npmjs.com/package/@faasjs/http)
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
FaasJS's http plugin.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
npm install @faasjs/http
|
|
12
|
+
|
|
13
|
+
## Modules
|
|
14
|
+
|
|
15
|
+
### Classes
|
|
16
|
+
|
|
17
|
+
- [Cookie](classes/Cookie.md)
|
|
18
|
+
- [Http](classes/Http.md)
|
|
19
|
+
- [HttpError](classes/HttpError.md)
|
|
20
|
+
- [Session](classes/Session.md)
|
|
21
|
+
- [Validator](classes/Validator.md)
|
|
22
|
+
|
|
23
|
+
### Type aliases
|
|
24
|
+
|
|
25
|
+
- [CookieOptions](#cookieoptions)
|
|
26
|
+
- [HttpConfig](#httpconfig)
|
|
27
|
+
- [Response](#response)
|
|
28
|
+
- [SessionOptions](#sessionoptions)
|
|
29
|
+
- [ValidatorConfig](#validatorconfig)
|
|
30
|
+
- [ValidatorOptions](#validatoroptions)
|
|
31
|
+
- [ValidatorRuleOptions](#validatorruleoptions)
|
|
32
|
+
|
|
33
|
+
### Variables
|
|
34
|
+
|
|
35
|
+
- [ContentType](#contenttype)
|
|
36
|
+
|
|
37
|
+
### Functions
|
|
38
|
+
|
|
39
|
+
- [useHttp](#usehttp)
|
|
40
|
+
|
|
41
|
+
## Type aliases
|
|
42
|
+
|
|
43
|
+
### CookieOptions
|
|
44
|
+
|
|
45
|
+
Ƭ **CookieOptions**: `Object`
|
|
46
|
+
|
|
47
|
+
#### Index signature
|
|
48
|
+
|
|
49
|
+
▪ [key: `string`]: `any`
|
|
50
|
+
|
|
51
|
+
#### Type declaration
|
|
52
|
+
|
|
53
|
+
| Name | Type |
|
|
54
|
+
| :------ | :------ |
|
|
55
|
+
| `domain?` | `string` |
|
|
56
|
+
| `expires?` | `number` |
|
|
57
|
+
| `httpOnly?` | `boolean` |
|
|
58
|
+
| `path?` | `string` |
|
|
59
|
+
| `sameSite?` | ``"Strict"`` \| ``"Lax"`` \| ``"None"`` |
|
|
60
|
+
| `secure?` | `boolean` |
|
|
61
|
+
| `session?` | [`SessionOptions`](#sessionoptions) |
|
|
62
|
+
|
|
63
|
+
___
|
|
64
|
+
|
|
65
|
+
### HttpConfig
|
|
66
|
+
|
|
67
|
+
Ƭ **HttpConfig**<`TParams`, `TCookie`, `TSession`\>: `Object`
|
|
68
|
+
|
|
69
|
+
#### Type parameters
|
|
70
|
+
|
|
71
|
+
| Name | Type |
|
|
72
|
+
| :------ | :------ |
|
|
73
|
+
| `TParams` | extends `Record`<`string`, `any`\> = `any` |
|
|
74
|
+
| `TCookie` | extends `Record`<`string`, `string`\> = `any` |
|
|
75
|
+
| `TSession` | extends `Record`<`string`, `string`\> = `any` |
|
|
76
|
+
|
|
77
|
+
#### Index signature
|
|
78
|
+
|
|
79
|
+
▪ [key: `string`]: `any`
|
|
80
|
+
|
|
81
|
+
#### Type declaration
|
|
82
|
+
|
|
83
|
+
| Name | Type |
|
|
84
|
+
| :------ | :------ |
|
|
85
|
+
| `config?` | { [key: string]: `any`; `cookie?`: [`CookieOptions`](#cookieoptions) ; `functionName?`: `string` ; `ignorePathPrefix?`: `string` ; `method?`: ``"BEGIN"`` \| ``"GET"`` \| ``"POST"`` \| ``"DELETE"`` \| ``"HEAD"`` \| ``"PUT"`` \| ``"OPTIONS"`` \| ``"TRACE"`` \| ``"PATCH"`` \| ``"ANY"`` ; `path?`: `string` ; `timeout?`: `number` } |
|
|
86
|
+
| `config.cookie?` | [`CookieOptions`](#cookieoptions) |
|
|
87
|
+
| `config.functionName?` | `string` |
|
|
88
|
+
| `config.ignorePathPrefix?` | `string` |
|
|
89
|
+
| `config.method?` | ``"BEGIN"`` \| ``"GET"`` \| ``"POST"`` \| ``"DELETE"`` \| ``"HEAD"`` \| ``"PUT"`` \| ``"OPTIONS"`` \| ``"TRACE"`` \| ``"PATCH"`` \| ``"ANY"`` |
|
|
90
|
+
| `config.path?` | `string` |
|
|
91
|
+
| `config.timeout?` | `number` |
|
|
92
|
+
| `name?` | `string` |
|
|
93
|
+
| `validator?` | [`ValidatorConfig`](#validatorconfig)<`TParams`, `TCookie`, `TSession`\> |
|
|
94
|
+
|
|
95
|
+
___
|
|
96
|
+
|
|
97
|
+
### Response
|
|
98
|
+
|
|
99
|
+
Ƭ **Response**: `Object`
|
|
100
|
+
|
|
101
|
+
#### Type declaration
|
|
102
|
+
|
|
103
|
+
| Name | Type |
|
|
104
|
+
| :------ | :------ |
|
|
105
|
+
| `body?` | `string` |
|
|
106
|
+
| `headers?` | { [key: string]: `string`; } |
|
|
107
|
+
| `message?` | `string` |
|
|
108
|
+
| `statusCode?` | `number` |
|
|
109
|
+
|
|
110
|
+
___
|
|
111
|
+
|
|
112
|
+
### SessionOptions
|
|
113
|
+
|
|
114
|
+
Ƭ **SessionOptions**: `Object`
|
|
115
|
+
|
|
116
|
+
#### Type declaration
|
|
117
|
+
|
|
118
|
+
| Name | Type |
|
|
119
|
+
| :------ | :------ |
|
|
120
|
+
| `cipherName?` | `string` |
|
|
121
|
+
| `digest?` | `string` |
|
|
122
|
+
| `iterations?` | `number` |
|
|
123
|
+
| `key` | `string` |
|
|
124
|
+
| `keylen?` | `number` |
|
|
125
|
+
| `salt?` | `string` |
|
|
126
|
+
| `secret` | `string` |
|
|
127
|
+
| `signedSalt?` | `string` |
|
|
128
|
+
|
|
129
|
+
___
|
|
130
|
+
|
|
131
|
+
### ValidatorConfig
|
|
132
|
+
|
|
133
|
+
Ƭ **ValidatorConfig**<`TParams`, `TCookie`, `TSession`\>: `Object`
|
|
134
|
+
|
|
135
|
+
#### Type parameters
|
|
136
|
+
|
|
137
|
+
| Name | Type |
|
|
138
|
+
| :------ | :------ |
|
|
139
|
+
| `TParams` | extends `Record`<`string`, `any`\> = `any` |
|
|
140
|
+
| `TCookie` | extends `Record`<`string`, `string`\> = `any` |
|
|
141
|
+
| `TSession` | extends `Record`<`string`, `string`\> = `any` |
|
|
142
|
+
|
|
143
|
+
#### Type declaration
|
|
144
|
+
|
|
145
|
+
| Name | Type |
|
|
146
|
+
| :------ | :------ |
|
|
147
|
+
| `before?` | `BeforeOption` |
|
|
148
|
+
| `cookie?` | [`ValidatorOptions`](#validatoroptions)<`TCookie`\> |
|
|
149
|
+
| `params?` | [`ValidatorOptions`](#validatoroptions)<`TParams`\> |
|
|
150
|
+
| `session?` | [`ValidatorOptions`](#validatoroptions)<`TSession`\> |
|
|
151
|
+
|
|
152
|
+
___
|
|
153
|
+
|
|
154
|
+
### ValidatorOptions
|
|
155
|
+
|
|
156
|
+
Ƭ **ValidatorOptions**<`Content`\>: `Object`
|
|
157
|
+
|
|
158
|
+
#### Type parameters
|
|
159
|
+
|
|
160
|
+
| Name | Type |
|
|
161
|
+
| :------ | :------ |
|
|
162
|
+
| `Content` | `Record`<`string`, `any`\> |
|
|
163
|
+
|
|
164
|
+
#### Type declaration
|
|
165
|
+
|
|
166
|
+
| Name | Type |
|
|
167
|
+
| :------ | :------ |
|
|
168
|
+
| `rules` | { [k in keyof Content]?: ValidatorRuleOptions } |
|
|
169
|
+
| `whitelist?` | ``"error"`` \| ``"ignore"`` |
|
|
170
|
+
| `onError?` | (`type`: `string`, `key`: `string` \| `string`[], `value?`: `any`) => `void` \| { `message`: `any` ; `statusCode?`: `number` } |
|
|
171
|
+
|
|
172
|
+
___
|
|
173
|
+
|
|
174
|
+
### ValidatorRuleOptions
|
|
175
|
+
|
|
176
|
+
Ƭ **ValidatorRuleOptions**: `Object`
|
|
177
|
+
|
|
178
|
+
#### Type declaration
|
|
179
|
+
|
|
180
|
+
| Name | Type |
|
|
181
|
+
| :------ | :------ |
|
|
182
|
+
| `config?` | `Partial`<[`ValidatorOptions`](#validatoroptions)\> |
|
|
183
|
+
| `default?` | `any` |
|
|
184
|
+
| `in?` | `any`[] |
|
|
185
|
+
| `regexp?` | `RegExp` |
|
|
186
|
+
| `required?` | `boolean` |
|
|
187
|
+
| `type?` | `ValidatorRuleOptionsType` |
|
|
188
|
+
|
|
189
|
+
## Variables
|
|
190
|
+
|
|
191
|
+
### ContentType
|
|
192
|
+
|
|
193
|
+
• **ContentType**: `Object`
|
|
194
|
+
|
|
195
|
+
#### Index signature
|
|
196
|
+
|
|
197
|
+
▪ [key: `string`]: `string`
|
|
198
|
+
|
|
199
|
+
## Functions
|
|
200
|
+
|
|
201
|
+
### useHttp
|
|
202
|
+
|
|
203
|
+
▸ **useHttp**<`TParams`, `TCookie`, `TSession`\>(`config?`): [`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession`\> & `UseifyPlugin`
|
|
204
|
+
|
|
205
|
+
#### Type parameters
|
|
206
|
+
|
|
207
|
+
| Name | Type |
|
|
208
|
+
| :------ | :------ |
|
|
209
|
+
| `TParams` | extends `Record`<`string`, `any`\> = `any` |
|
|
210
|
+
| `TCookie` | extends `Record`<`string`, `string`\> = `any` |
|
|
211
|
+
| `TSession` | extends `Record`<`string`, `string`\> = `any` |
|
|
212
|
+
|
|
213
|
+
#### Parameters
|
|
214
|
+
|
|
215
|
+
| Name | Type |
|
|
216
|
+
| :------ | :------ |
|
|
217
|
+
| `config?` | [`HttpConfig`](#httpconfig)<`TParams`, `TCookie`, `TSession`\> |
|
|
218
|
+
|
|
219
|
+
#### Returns
|
|
220
|
+
|
|
221
|
+
[`Http`](classes/Http.md)<`TParams`, `TCookie`, `TSession`\> & `UseifyPlugin`
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare type SessionContent = string | number | {
|
|
|
15
15
|
[key: string]: any;
|
|
16
16
|
} | null | undefined;
|
|
17
17
|
declare class Session<S extends Record<string, string> = any, C extends Record<string, string> = any> {
|
|
18
|
-
content: Record<string, string>;
|
|
18
|
+
content: Record<string, string | number>;
|
|
19
19
|
readonly config: {
|
|
20
20
|
key: string;
|
|
21
21
|
secret: string;
|
|
@@ -33,9 +33,9 @@ declare class Session<S extends Record<string, string> = any, C extends Record<s
|
|
|
33
33
|
constructor(cookie: Cookie<C, S>, config: SessionOptions);
|
|
34
34
|
invoke(cookie?: string): void;
|
|
35
35
|
encode(text: SessionContent): string;
|
|
36
|
-
decode(text: string): SessionContent;
|
|
37
|
-
read(key: string): string;
|
|
38
|
-
write(key: string, value?: string): Session<S, C>;
|
|
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
39
|
update(): Session<S, C>;
|
|
40
40
|
}
|
|
41
41
|
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
13
20
|
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
14
23
|
var __export = (target, all) => {
|
|
15
24
|
for (var name in all)
|
|
16
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -23,96 +32,12 @@ var __reExport = (target, module2, copyDefault, desc) => {
|
|
|
23
32
|
}
|
|
24
33
|
return target;
|
|
25
34
|
};
|
|
26
|
-
var __toESM = (module2, isNodeMode) => {
|
|
27
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
28
|
-
};
|
|
29
35
|
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
30
36
|
return (module2, temp) => {
|
|
31
37
|
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
32
38
|
};
|
|
33
39
|
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
40
|
|
|
35
|
-
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
36
|
-
var init_cjs_shims = __esm({
|
|
37
|
-
"../../node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ../deep_merge/dist/index.js
|
|
42
|
-
var require_dist = __commonJS({
|
|
43
|
-
"../deep_merge/dist/index.js"(exports, module2) {
|
|
44
|
-
init_cjs_shims();
|
|
45
|
-
var __defProp2 = Object.defineProperty;
|
|
46
|
-
var __defProps = Object.defineProperties;
|
|
47
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
48
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
49
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
50
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
51
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
52
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
53
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
54
|
-
var __spreadValues = (a, b) => {
|
|
55
|
-
for (var prop in b || (b = {}))
|
|
56
|
-
if (__hasOwnProp2.call(b, prop))
|
|
57
|
-
__defNormalProp(a, prop, b[prop]);
|
|
58
|
-
if (__getOwnPropSymbols)
|
|
59
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
60
|
-
if (__propIsEnum.call(b, prop))
|
|
61
|
-
__defNormalProp(a, prop, b[prop]);
|
|
62
|
-
}
|
|
63
|
-
return a;
|
|
64
|
-
};
|
|
65
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
66
|
-
var __markAsModule2 = (target) => __defProp2(target, "__esModule", { value: true });
|
|
67
|
-
var __export2 = (target, all) => {
|
|
68
|
-
for (var name in all)
|
|
69
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
70
|
-
};
|
|
71
|
-
var __reExport2 = (target, module22, copyDefault, desc) => {
|
|
72
|
-
if (module22 && typeof module22 === "object" || typeof module22 === "function") {
|
|
73
|
-
for (let key of __getOwnPropNames2(module22))
|
|
74
|
-
if (!__hasOwnProp2.call(target, key) && (copyDefault || key !== "default"))
|
|
75
|
-
__defProp2(target, key, { get: () => module22[key], enumerable: !(desc = __getOwnPropDesc2(module22, key)) || desc.enumerable });
|
|
76
|
-
}
|
|
77
|
-
return target;
|
|
78
|
-
};
|
|
79
|
-
var __toCommonJS2 = /* @__PURE__ */ ((cache) => {
|
|
80
|
-
return (module22, temp) => {
|
|
81
|
-
return cache && cache.get(module22) || (temp = __reExport2(__markAsModule2({}), module22, 1), cache && cache.set(module22, temp), temp);
|
|
82
|
-
};
|
|
83
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
84
|
-
var src_exports2 = {};
|
|
85
|
-
__export2(src_exports2, {
|
|
86
|
-
deepMerge: () => deepMerge3
|
|
87
|
-
});
|
|
88
|
-
var shouldMerge = function(item) {
|
|
89
|
-
const type = Object.prototype.toString.call(item);
|
|
90
|
-
return type === "[object Object]" || type === "[object Array]";
|
|
91
|
-
};
|
|
92
|
-
function deepMerge3(...sources) {
|
|
93
|
-
let acc = /* @__PURE__ */ Object.create(null);
|
|
94
|
-
for (const source of sources)
|
|
95
|
-
if (source instanceof Array) {
|
|
96
|
-
if (!(acc instanceof Array))
|
|
97
|
-
acc = [];
|
|
98
|
-
acc = [...new Set(source.concat(...acc))];
|
|
99
|
-
} else if (shouldMerge(source))
|
|
100
|
-
for (const [key, value] of Object.entries(source)) {
|
|
101
|
-
let val;
|
|
102
|
-
if (shouldMerge(value))
|
|
103
|
-
val = deepMerge3(acc[key], value);
|
|
104
|
-
else
|
|
105
|
-
val = value;
|
|
106
|
-
acc = __spreadProps(__spreadValues({}, acc), {
|
|
107
|
-
[key]: val
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return acc;
|
|
111
|
-
}
|
|
112
|
-
module2.exports = __toCommonJS2(src_exports2);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
41
|
// src/index.ts
|
|
117
42
|
var src_exports = {};
|
|
118
43
|
__export(src_exports, {
|
|
@@ -124,16 +49,38 @@ __export(src_exports, {
|
|
|
124
49
|
Validator: () => Validator,
|
|
125
50
|
useHttp: () => useHttp
|
|
126
51
|
});
|
|
127
|
-
init_cjs_shims();
|
|
128
52
|
var import_func = require("@faasjs/func");
|
|
129
|
-
var import_deep_merge2 = __toESM(require_dist());
|
|
130
|
-
var import_logger = require("@faasjs/logger");
|
|
131
53
|
|
|
132
|
-
// src/
|
|
133
|
-
|
|
54
|
+
// ../deep_merge/src/index.ts
|
|
55
|
+
var shouldMerge = function(item) {
|
|
56
|
+
const type = Object.prototype.toString.call(item);
|
|
57
|
+
return type === "[object Object]" || type === "[object Array]";
|
|
58
|
+
};
|
|
59
|
+
function deepMerge(...sources) {
|
|
60
|
+
let acc = /* @__PURE__ */ Object.create(null);
|
|
61
|
+
for (const source of sources)
|
|
62
|
+
if (source instanceof Array) {
|
|
63
|
+
if (!(acc instanceof Array))
|
|
64
|
+
acc = [];
|
|
65
|
+
acc = [...new Set(source.concat(...acc))];
|
|
66
|
+
} else if (shouldMerge(source))
|
|
67
|
+
for (const [key, value] of Object.entries(source)) {
|
|
68
|
+
let val;
|
|
69
|
+
if (shouldMerge(value))
|
|
70
|
+
val = deepMerge(acc[key], value);
|
|
71
|
+
else
|
|
72
|
+
val = value;
|
|
73
|
+
acc = __spreadProps(__spreadValues({}, acc), {
|
|
74
|
+
[key]: val
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return acc;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/index.ts
|
|
81
|
+
var import_logger = require("@faasjs/logger");
|
|
134
82
|
|
|
135
83
|
// src/session.ts
|
|
136
|
-
init_cjs_shims();
|
|
137
84
|
var import_crypto = require("crypto");
|
|
138
85
|
var Session = class {
|
|
139
86
|
constructor(cookie, config) {
|
|
@@ -210,10 +157,9 @@ var Session = class {
|
|
|
210
157
|
};
|
|
211
158
|
|
|
212
159
|
// src/cookie.ts
|
|
213
|
-
var import_deep_merge = __toESM(require_dist());
|
|
214
160
|
var Cookie = class {
|
|
215
161
|
constructor(config) {
|
|
216
|
-
this.config =
|
|
162
|
+
this.config = deepMerge({
|
|
217
163
|
path: "/",
|
|
218
164
|
expires: 31536e3,
|
|
219
165
|
secure: true,
|
|
@@ -276,7 +222,6 @@ var Cookie = class {
|
|
|
276
222
|
};
|
|
277
223
|
|
|
278
224
|
// src/validator.ts
|
|
279
|
-
init_cjs_shims();
|
|
280
225
|
var Validator = class {
|
|
281
226
|
constructor(config, logger) {
|
|
282
227
|
this.paramsConfig = config.params;
|
|
@@ -457,7 +402,7 @@ var Http = class {
|
|
|
457
402
|
await next();
|
|
458
403
|
this.logger.debug("\u7EC4\u88C5\u7F51\u5173\u914D\u7F6E");
|
|
459
404
|
this.logger.debug("%j", data);
|
|
460
|
-
const config = data.config.plugins ?
|
|
405
|
+
const config = data.config.plugins ? deepMerge(data.config.plugins[this.name || this.type], { config: this.config }) : { config: this.config };
|
|
461
406
|
if (!config.config.path) {
|
|
462
407
|
config.config.path = "/" + ((_a = data.name) == null ? void 0 : _a.replace(/_/g, "/").replace(/\/index$/, ""));
|
|
463
408
|
if (config.config.path === "/index")
|
|
@@ -476,7 +421,7 @@ var Http = class {
|
|
|
476
421
|
async onMount(data, next) {
|
|
477
422
|
this.logger.debug("[onMount] merge config");
|
|
478
423
|
if (data.config.plugins && data.config.plugins[this.name || this.type])
|
|
479
|
-
this.config =
|
|
424
|
+
this.config = deepMerge(this.config, data.config.plugins[this.name || this.type].config);
|
|
480
425
|
this.logger.debug("[onMount] prepare cookie & session");
|
|
481
426
|
this.cookie = new Cookie(this.config.cookie || {});
|
|
482
427
|
this.session = this.cookie.session;
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
8
20
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
21
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
22
|
}) : x)(function(x) {
|
|
@@ -12,120 +24,42 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
12
24
|
return require.apply(this, arguments);
|
|
13
25
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
14
26
|
});
|
|
15
|
-
var __esm = (fn, res) => function __init() {
|
|
16
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
19
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
-
};
|
|
21
|
-
var __reExport = (target, module, copyDefault, desc) => {
|
|
22
|
-
if (module && typeof module === "object" || typeof module === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(module))
|
|
24
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
25
|
-
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (module, isNodeMode) => {
|
|
30
|
-
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", !isNodeMode && module && module.__esModule ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// ../../node_modules/tsup/assets/esm_shims.js
|
|
34
|
-
import { fileURLToPath } from "url";
|
|
35
|
-
import path from "path";
|
|
36
|
-
var init_esm_shims = __esm({
|
|
37
|
-
"../../node_modules/tsup/assets/esm_shims.js"() {
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ../deep_merge/dist/index.js
|
|
42
|
-
var require_dist = __commonJS({
|
|
43
|
-
"../deep_merge/dist/index.js"(exports, module) {
|
|
44
|
-
init_esm_shims();
|
|
45
|
-
var __defProp2 = Object.defineProperty;
|
|
46
|
-
var __defProps = Object.defineProperties;
|
|
47
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
48
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
49
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
50
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
51
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
52
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
53
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
54
|
-
var __spreadValues = (a, b) => {
|
|
55
|
-
for (var prop in b || (b = {}))
|
|
56
|
-
if (__hasOwnProp2.call(b, prop))
|
|
57
|
-
__defNormalProp(a, prop, b[prop]);
|
|
58
|
-
if (__getOwnPropSymbols)
|
|
59
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
60
|
-
if (__propIsEnum.call(b, prop))
|
|
61
|
-
__defNormalProp(a, prop, b[prop]);
|
|
62
|
-
}
|
|
63
|
-
return a;
|
|
64
|
-
};
|
|
65
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
66
|
-
var __markAsModule2 = (target) => __defProp2(target, "__esModule", { value: true });
|
|
67
|
-
var __export = (target, all) => {
|
|
68
|
-
for (var name in all)
|
|
69
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
70
|
-
};
|
|
71
|
-
var __reExport2 = (target, module2, copyDefault, desc) => {
|
|
72
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
73
|
-
for (let key of __getOwnPropNames2(module2))
|
|
74
|
-
if (!__hasOwnProp2.call(target, key) && (copyDefault || key !== "default"))
|
|
75
|
-
__defProp2(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc2(module2, key)) || desc.enumerable });
|
|
76
|
-
}
|
|
77
|
-
return target;
|
|
78
|
-
};
|
|
79
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
80
|
-
return (module2, temp) => {
|
|
81
|
-
return cache && cache.get(module2) || (temp = __reExport2(__markAsModule2({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
82
|
-
};
|
|
83
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
84
|
-
var src_exports = {};
|
|
85
|
-
__export(src_exports, {
|
|
86
|
-
deepMerge: () => deepMerge3
|
|
87
|
-
});
|
|
88
|
-
var shouldMerge = function(item) {
|
|
89
|
-
const type = Object.prototype.toString.call(item);
|
|
90
|
-
return type === "[object Object]" || type === "[object Array]";
|
|
91
|
-
};
|
|
92
|
-
function deepMerge3(...sources) {
|
|
93
|
-
let acc = /* @__PURE__ */ Object.create(null);
|
|
94
|
-
for (const source of sources)
|
|
95
|
-
if (source instanceof Array) {
|
|
96
|
-
if (!(acc instanceof Array))
|
|
97
|
-
acc = [];
|
|
98
|
-
acc = [...new Set(source.concat(...acc))];
|
|
99
|
-
} else if (shouldMerge(source))
|
|
100
|
-
for (const [key, value] of Object.entries(source)) {
|
|
101
|
-
let val;
|
|
102
|
-
if (shouldMerge(value))
|
|
103
|
-
val = deepMerge3(acc[key], value);
|
|
104
|
-
else
|
|
105
|
-
val = value;
|
|
106
|
-
acc = __spreadProps(__spreadValues({}, acc), {
|
|
107
|
-
[key]: val
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return acc;
|
|
111
|
-
}
|
|
112
|
-
module.exports = __toCommonJS(src_exports);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
27
|
|
|
116
28
|
// src/index.ts
|
|
117
|
-
init_esm_shims();
|
|
118
|
-
var import_deep_merge2 = __toESM(require_dist());
|
|
119
29
|
import {
|
|
120
30
|
usePlugin
|
|
121
31
|
} from "@faasjs/func";
|
|
122
|
-
import { Logger } from "@faasjs/logger";
|
|
123
32
|
|
|
124
|
-
// src/
|
|
125
|
-
|
|
33
|
+
// ../deep_merge/src/index.ts
|
|
34
|
+
var shouldMerge = function(item) {
|
|
35
|
+
const type = Object.prototype.toString.call(item);
|
|
36
|
+
return type === "[object Object]" || type === "[object Array]";
|
|
37
|
+
};
|
|
38
|
+
function deepMerge(...sources) {
|
|
39
|
+
let acc = /* @__PURE__ */ Object.create(null);
|
|
40
|
+
for (const source of sources)
|
|
41
|
+
if (source instanceof Array) {
|
|
42
|
+
if (!(acc instanceof Array))
|
|
43
|
+
acc = [];
|
|
44
|
+
acc = [...new Set(source.concat(...acc))];
|
|
45
|
+
} else if (shouldMerge(source))
|
|
46
|
+
for (const [key, value] of Object.entries(source)) {
|
|
47
|
+
let val;
|
|
48
|
+
if (shouldMerge(value))
|
|
49
|
+
val = deepMerge(acc[key], value);
|
|
50
|
+
else
|
|
51
|
+
val = value;
|
|
52
|
+
acc = __spreadProps(__spreadValues({}, acc), {
|
|
53
|
+
[key]: val
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return acc;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
import { Logger } from "@faasjs/logger";
|
|
126
61
|
|
|
127
62
|
// src/session.ts
|
|
128
|
-
init_esm_shims();
|
|
129
63
|
import {
|
|
130
64
|
randomBytes,
|
|
131
65
|
pbkdf2Sync,
|
|
@@ -208,10 +142,9 @@ var Session = class {
|
|
|
208
142
|
};
|
|
209
143
|
|
|
210
144
|
// src/cookie.ts
|
|
211
|
-
var import_deep_merge = __toESM(require_dist());
|
|
212
145
|
var Cookie = class {
|
|
213
146
|
constructor(config) {
|
|
214
|
-
this.config =
|
|
147
|
+
this.config = deepMerge({
|
|
215
148
|
path: "/",
|
|
216
149
|
expires: 31536e3,
|
|
217
150
|
secure: true,
|
|
@@ -274,7 +207,6 @@ var Cookie = class {
|
|
|
274
207
|
};
|
|
275
208
|
|
|
276
209
|
// src/validator.ts
|
|
277
|
-
init_esm_shims();
|
|
278
210
|
var Validator = class {
|
|
279
211
|
constructor(config, logger) {
|
|
280
212
|
this.paramsConfig = config.params;
|
|
@@ -459,7 +391,7 @@ var Http = class {
|
|
|
459
391
|
await next();
|
|
460
392
|
this.logger.debug("\u7EC4\u88C5\u7F51\u5173\u914D\u7F6E");
|
|
461
393
|
this.logger.debug("%j", data);
|
|
462
|
-
const config = data.config.plugins ?
|
|
394
|
+
const config = data.config.plugins ? deepMerge(data.config.plugins[this.name || this.type], { config: this.config }) : { config: this.config };
|
|
463
395
|
if (!config.config.path) {
|
|
464
396
|
config.config.path = "/" + ((_a = data.name) == null ? void 0 : _a.replace(/_/g, "/").replace(/\/index$/, ""));
|
|
465
397
|
if (config.config.path === "/index")
|
|
@@ -478,7 +410,7 @@ var Http = class {
|
|
|
478
410
|
async onMount(data, next) {
|
|
479
411
|
this.logger.debug("[onMount] merge config");
|
|
480
412
|
if (data.config.plugins && data.config.plugins[this.name || this.type])
|
|
481
|
-
this.config =
|
|
413
|
+
this.config = deepMerge(this.config, data.config.plugins[this.name || this.type].config);
|
|
482
414
|
this.logger.debug("[onMount] prepare cookie & session");
|
|
483
415
|
this.cookie = new Cookie(this.config.cookie || {});
|
|
484
416
|
this.session = this.cookie.session;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/http",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.365",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@faasjs/func": "^0.0.2-beta.
|
|
26
|
-
"@faasjs/logger": "^0.0.2-beta.
|
|
25
|
+
"@faasjs/func": "^0.0.2-beta.365",
|
|
26
|
+
"@faasjs/logger": "^0.0.2-beta.365"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"tsup": "*",
|