@faasjs/func 0.0.2-beta.394 → 0.0.2-beta.397

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
@@ -16,7 +16,7 @@ FaasJS's function module.
16
16
 
17
17
  - [Func](classes/Func.md)
18
18
 
19
- ### Type aliases
19
+ ### Type Aliases
20
20
 
21
21
  - [Config](#config)
22
22
  - [DeployData](#deploydata)
@@ -36,7 +36,7 @@ FaasJS's function module.
36
36
  - [useFunc](#usefunc)
37
37
  - [usePlugin](#useplugin)
38
38
 
39
- ## Type aliases
39
+ ## Type Aliases
40
40
 
41
41
  ### Config
42
42
 
@@ -239,10 +239,10 @@ ___
239
239
  | Name | Type |
240
240
  | :------ | :------ |
241
241
  | `name` | `string` |
242
- | `type` | `string` |
243
242
  | `onDeploy?` | (`data`: [`DeployData`](#deploydata), `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
244
- | `onInvoke?` | (`data`: [`InvokeData`](#invokedata)<`any`, `any`, `any`\>, `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
243
+ | `onInvoke?` | (`data`: [`InvokeData`](#invokedata), `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
245
244
  | `onMount?` | (`data`: [`MountData`](#mountdata), `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
245
+ | `type` | `string` |
246
246
 
247
247
  ___
248
248
 
@@ -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(key: LifeCycleKey): (data: any, next?: () => void) => any;
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(config?: Config): {
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
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -62,7 +63,7 @@ var Func = class {
62
63
  constructor(config) {
63
64
  this.logger = new import_logger.Logger("Func");
64
65
  this.handler = config.handler;
65
- this.plugins = config.plugins ?? [];
66
+ this.plugins = config.plugins || [];
66
67
  this.plugins.push(new RunHandler());
67
68
  this.config = {
68
69
  providers: /* @__PURE__ */ Object.create(null),
@@ -155,9 +156,7 @@ var Func = class {
155
156
  data.response = error;
156
157
  }
157
158
  }
158
- export(config) {
159
- if (!this.config)
160
- this.config = config || /* @__PURE__ */ Object.create(null);
159
+ export() {
161
160
  const handler = async (event, context, callback) => {
162
161
  const logger = new import_logger.Logger();
163
162
  if (startedAt) {
@@ -195,15 +194,6 @@ var plugins = [];
195
194
  function usePlugin(plugin) {
196
195
  if (!plugins.find((p) => p.name === plugin.name))
197
196
  plugins.push(plugin);
198
- if (plugin.mount == null)
199
- plugin.mount = async function({ config }) {
200
- if (plugin.onMount)
201
- await plugin.onMount({
202
- config,
203
- event: {},
204
- context: {}
205
- }, async () => await Promise.resolve());
206
- };
207
197
  return plugin;
208
198
  }
209
199
  function useFunc(handler) {
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ var Func = class {
37
37
  constructor(config) {
38
38
  this.logger = new Logger("Func");
39
39
  this.handler = config.handler;
40
- this.plugins = config.plugins ?? [];
40
+ this.plugins = config.plugins || [];
41
41
  this.plugins.push(new RunHandler());
42
42
  this.config = {
43
43
  providers: /* @__PURE__ */ Object.create(null),
@@ -130,9 +130,7 @@ var Func = class {
130
130
  data.response = error;
131
131
  }
132
132
  }
133
- export(config) {
134
- if (!this.config)
135
- this.config = config || /* @__PURE__ */ Object.create(null);
133
+ export() {
136
134
  const handler = async (event, context, callback) => {
137
135
  const logger = new Logger();
138
136
  if (startedAt) {
@@ -170,15 +168,6 @@ var plugins = [];
170
168
  function usePlugin(plugin) {
171
169
  if (!plugins.find((p) => p.name === plugin.name))
172
170
  plugins.push(plugin);
173
- if (plugin.mount == null)
174
- plugin.mount = async function({ config }) {
175
- if (plugin.onMount)
176
- await plugin.onMount({
177
- config,
178
- event: {},
179
- context: {}
180
- }, async () => await Promise.resolve());
181
- };
182
171
  return plugin;
183
172
  }
184
173
  function useFunc(handler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/func",
3
- "version": "0.0.2-beta.394",
3
+ "version": "0.0.2-beta.397",
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.394",
26
- "@faasjs/logger": "^0.0.2-beta.394"
25
+ "@faasjs/deep_merge": "^0.0.2-beta.397",
26
+ "@faasjs/logger": "^0.0.2-beta.397"
27
27
  },
28
28
  "devDependencies": {
29
29
  "tsup": "*",