@faasjs/func 0.0.2-beta.396 → 0.0.2-beta.399
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 +20 -0
- package/dist/index.d.ts +36 -15
- package/dist/index.js +3 -5
- package/dist/index.mjs +3 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -275,6 +275,26 @@ ___
|
|
|
275
275
|
|
|
276
276
|
▸ **useFunc**<`TEvent`, `TContext`, `TResult`\>(`handler`): [`Func`](classes/Func.md)<`TEvent`, `TContext`, `TResult`\>
|
|
277
277
|
|
|
278
|
+
```ts
|
|
279
|
+
// pure function
|
|
280
|
+
export default useFunc(() => {
|
|
281
|
+
return () => {
|
|
282
|
+
return 'Hello World'
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
// with http
|
|
287
|
+
import { useHttp } from '@faasjs/http'
|
|
288
|
+
|
|
289
|
+
export default useFunc(() => {
|
|
290
|
+
const http = useHttp<{ name: string }>()
|
|
291
|
+
|
|
292
|
+
return () => {
|
|
293
|
+
return `Hello ${http.params.name}`
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
```
|
|
297
|
+
|
|
278
298
|
#### Type parameters
|
|
279
299
|
|
|
280
300
|
| Name | Type |
|
package/dist/index.d.ts
CHANGED
|
@@ -89,23 +89,23 @@ declare class Func<TEvent = any, TContext = any, TResult = any> {
|
|
|
89
89
|
filename?: string;
|
|
90
90
|
private cachedFunctions;
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param config {object}
|
|
94
|
-
* @param config.plugins {Plugin[]}
|
|
95
|
-
* @param config.handler {Handler}
|
|
92
|
+
* Create a cloud function
|
|
93
|
+
* @param config {object} config
|
|
94
|
+
* @param config.plugins {Plugin[]} plugins list
|
|
95
|
+
* @param config.handler {Handler} business logic
|
|
96
96
|
*/
|
|
97
97
|
constructor(config: FuncConfig<TEvent, TContext>);
|
|
98
|
-
compose
|
|
98
|
+
private compose;
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
101
|
-
* @param data {object}
|
|
102
|
-
* @param data.root {string}
|
|
103
|
-
* @param data.filename {string}
|
|
104
|
-
* @param data.env {string}
|
|
100
|
+
* Deploy the function
|
|
101
|
+
* @param data {object} data
|
|
102
|
+
* @param data.root {string} root path
|
|
103
|
+
* @param data.filename {string} filename
|
|
104
|
+
* @param data.env {string} environment
|
|
105
105
|
*/
|
|
106
106
|
deploy(data: DeployData): any;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* First time mount the function
|
|
109
109
|
*/
|
|
110
110
|
mount(data: {
|
|
111
111
|
event: TEvent;
|
|
@@ -113,14 +113,14 @@ declare class Func<TEvent = any, TContext = any, TResult = any> {
|
|
|
113
113
|
config?: Config;
|
|
114
114
|
}): Promise<void>;
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @param data {object}
|
|
116
|
+
* Invoke the function
|
|
117
|
+
* @param data {object} data
|
|
118
118
|
*/
|
|
119
119
|
invoke(data: InvokeData<TEvent, TContext, TResult>): Promise<void>;
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Export the function
|
|
122
122
|
*/
|
|
123
|
-
export(
|
|
123
|
+
export(): {
|
|
124
124
|
handler: ExportedHandler<TEvent, TContext, TResult>;
|
|
125
125
|
};
|
|
126
126
|
}
|
|
@@ -130,6 +130,27 @@ declare type UseifyPlugin = {
|
|
|
130
130
|
}) => Promise<void>;
|
|
131
131
|
};
|
|
132
132
|
declare function usePlugin<T extends Plugin>(plugin: T & UseifyPlugin): T & UseifyPlugin;
|
|
133
|
+
/**
|
|
134
|
+
* ```ts
|
|
135
|
+
* // pure function
|
|
136
|
+
* export default useFunc(() => {
|
|
137
|
+
* return () => {
|
|
138
|
+
* return 'Hello World'
|
|
139
|
+
* }
|
|
140
|
+
* })
|
|
141
|
+
*
|
|
142
|
+
* // with http
|
|
143
|
+
* import { useHttp } from '@faasjs/http'
|
|
144
|
+
*
|
|
145
|
+
* export default useFunc(() => {
|
|
146
|
+
* const http = useHttp<{ name: string }>()
|
|
147
|
+
*
|
|
148
|
+
* return () => {
|
|
149
|
+
* return `Hello ${http.params.name}`
|
|
150
|
+
* }
|
|
151
|
+
* })
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
133
154
|
declare function useFunc<TEvent = any, TContext = any, TResult = any>(handler: () => Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
134
155
|
|
|
135
156
|
export { Config, DeployData, ExportedHandler, Func, FuncConfig, Handler, InvokeData, LifeCycleKey, MountData, Next, Plugin, ProviderConfig, UseifyPlugin, useFunc, usePlugin };
|
package/dist/index.js
CHANGED
|
@@ -156,9 +156,7 @@ var Func = class {
|
|
|
156
156
|
data.response = error;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
export(
|
|
160
|
-
if (!this.config)
|
|
161
|
-
this.config = config || /* @__PURE__ */ Object.create(null);
|
|
159
|
+
export() {
|
|
162
160
|
const handler = async (event, context, callback) => {
|
|
163
161
|
const logger = new import_logger.Logger();
|
|
164
162
|
if (startedAt) {
|
|
@@ -196,14 +194,14 @@ var plugins = [];
|
|
|
196
194
|
function usePlugin(plugin) {
|
|
197
195
|
if (!plugins.find((p) => p.name === plugin.name))
|
|
198
196
|
plugins.push(plugin);
|
|
199
|
-
if (plugin.mount
|
|
197
|
+
if (!plugin.mount)
|
|
200
198
|
plugin.mount = async function({ config }) {
|
|
201
199
|
if (plugin.onMount)
|
|
202
200
|
await plugin.onMount({
|
|
203
201
|
config,
|
|
204
202
|
event: {},
|
|
205
203
|
context: {}
|
|
206
|
-
}, async () =>
|
|
204
|
+
}, async () => Promise.resolve());
|
|
207
205
|
};
|
|
208
206
|
return plugin;
|
|
209
207
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
// src/index.ts
|
|
4
2
|
import { Logger } from "@faasjs/logger";
|
|
5
3
|
|
|
@@ -132,9 +130,7 @@ var Func = class {
|
|
|
132
130
|
data.response = error;
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
|
-
export(
|
|
136
|
-
if (!this.config)
|
|
137
|
-
this.config = config || /* @__PURE__ */ Object.create(null);
|
|
133
|
+
export() {
|
|
138
134
|
const handler = async (event, context, callback) => {
|
|
139
135
|
const logger = new Logger();
|
|
140
136
|
if (startedAt) {
|
|
@@ -172,14 +168,14 @@ var plugins = [];
|
|
|
172
168
|
function usePlugin(plugin) {
|
|
173
169
|
if (!plugins.find((p) => p.name === plugin.name))
|
|
174
170
|
plugins.push(plugin);
|
|
175
|
-
if (plugin.mount
|
|
171
|
+
if (!plugin.mount)
|
|
176
172
|
plugin.mount = async function({ config }) {
|
|
177
173
|
if (plugin.onMount)
|
|
178
174
|
await plugin.onMount({
|
|
179
175
|
config,
|
|
180
176
|
event: {},
|
|
181
177
|
context: {}
|
|
182
|
-
}, async () =>
|
|
178
|
+
}, async () => Promise.resolve());
|
|
183
179
|
};
|
|
184
180
|
return plugin;
|
|
185
181
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/func",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.399",
|
|
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/deep_merge": "^0.0.2-beta.
|
|
26
|
-
"@faasjs/logger": "^0.0.2-beta.
|
|
25
|
+
"@faasjs/deep_merge": "^0.0.2-beta.399",
|
|
26
|
+
"@faasjs/logger": "^0.0.2-beta.399"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"tsup": "*",
|