@faasjs/load 7.0.4 → 7.1.0

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
@@ -15,6 +15,7 @@ npm install @faasjs/load
15
15
 
16
16
  - [detectNodeRuntime](functions/detectNodeRuntime.md)
17
17
  - [loadConfig](functions/loadConfig.md)
18
+ - [loadFunc](functions/loadFunc.md)
18
19
  - [loadPackage](functions/loadPackage.md)
19
20
  - [resetRuntime](functions/resetRuntime.md)
20
21
 
package/dist/index.cjs CHANGED
@@ -111,7 +111,15 @@ async function loadPackage(name, defaultNames = "default") {
111
111
  throw Error("Unknown runtime");
112
112
  }
113
113
 
114
+ // src/load_func.ts
115
+ async function loadFunc(root, filename, staging) {
116
+ const func = await loadPackage(filename);
117
+ func.config = await loadConfig(root, filename, staging);
118
+ return func.export().handler;
119
+ }
120
+
114
121
  exports.detectNodeRuntime = detectNodeRuntime;
115
122
  exports.loadConfig = loadConfig;
123
+ exports.loadFunc = loadFunc;
116
124
  exports.loadPackage = loadPackage;
117
125
  exports.resetRuntime = resetRuntime;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Config } from '@faasjs/func';
1
+ import { Config, ExportedHandler } from '@faasjs/func';
2
2
  import { Logger } from '@faasjs/logger';
3
3
 
4
4
  /**
@@ -6,6 +6,31 @@ import { Logger } from '@faasjs/logger';
6
6
  */
7
7
  declare function loadConfig(root: string, filename: string, staging: string, logger?: Logger): Config;
8
8
 
9
+ /**
10
+ * Load a FaasJS function and its configuration, returning the handler.
11
+ *
12
+ * @param root - Project root directory used to resolve configuration
13
+ * @param filename - Path to the packaged FaasJS function file to load
14
+ * @param staging - Staging directory name (used when locating config)
15
+ *
16
+ * @returns A Promise that resolves to the function handler
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { loadFunc } from '@faasjs/load'
21
+ *
22
+ * const handler = await loadFunc(
23
+ * process.cwd(),
24
+ * __dirname + '/example.func.ts',
25
+ * 'development'
26
+ * )
27
+ *
28
+ * const result = await handler(event, context)
29
+ * console.log(result)
30
+ * ```
31
+ */
32
+ declare function loadFunc<TEvent = any, TContext = any, TResult = any>(root: string, filename: string, staging: string): Promise<ExportedHandler<TEvent, TContext, TResult>>;
33
+
9
34
  type NodeRuntime = 'commonjs' | 'module';
10
35
  declare function resetRuntime(): void;
11
36
  /**
@@ -36,4 +61,4 @@ declare function detectNodeRuntime(): NodeRuntime;
36
61
  */
37
62
  declare function loadPackage<T = unknown>(name: string, defaultNames?: string | string[]): Promise<T>;
38
63
 
39
- export { type NodeRuntime, detectNodeRuntime, loadConfig, loadPackage, resetRuntime };
64
+ export { type NodeRuntime, detectNodeRuntime, loadConfig, loadFunc, loadPackage, resetRuntime };
package/dist/index.mjs CHANGED
@@ -108,4 +108,11 @@ async function loadPackage(name, defaultNames = "default") {
108
108
  throw Error("Unknown runtime");
109
109
  }
110
110
 
111
- export { detectNodeRuntime, loadConfig, loadPackage, resetRuntime };
111
+ // src/load_func.ts
112
+ async function loadFunc(root, filename, staging) {
113
+ const func = await loadPackage(filename);
114
+ func.config = await loadConfig(root, filename, staging);
115
+ return func.export().handler;
116
+ }
117
+
118
+ export { detectNodeRuntime, loadConfig, loadFunc, loadPackage, resetRuntime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "7.0.4",
3
+ "version": "7.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -32,15 +32,15 @@
32
32
  "peerDependencies": {
33
33
  "js-yaml": "*",
34
34
  "tsx": "*",
35
- "@faasjs/deep_merge": ">=7.0.4",
36
- "@faasjs/func": ">=7.0.4"
35
+ "@faasjs/deep_merge": ">=7.1.0",
36
+ "@faasjs/func": ">=7.1.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "js-yaml": "*",
40
40
  "tsx": "*",
41
41
  "@types/js-yaml": "*",
42
- "@faasjs/deep_merge": ">=7.0.4",
43
- "@faasjs/func": ">=7.0.4"
42
+ "@faasjs/deep_merge": ">=7.1.0",
43
+ "@faasjs/func": ">=7.1.0"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=24.0.0",