@faasjs/load 8.0.0-beta.4 → 8.0.0-beta.6

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.cjs CHANGED
@@ -8,6 +8,57 @@ var jsYaml = require('js-yaml');
8
8
 
9
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
10
  // src/load_config.ts
11
+ function isObject(value) {
12
+ return !!value && typeof value === "object" && !Array.isArray(value);
13
+ }
14
+ function createConfigError(filePath, keyPath, reason) {
15
+ return Error(
16
+ `[loadConfig] Invalid faas.yaml ${filePath} at "${keyPath}": ${reason}`
17
+ );
18
+ }
19
+ function validateServerConfig(filePath, staging, server) {
20
+ if (!isObject(server))
21
+ throw createConfigError(filePath, `${staging}.server`, "must be an object");
22
+ if (typeof server.root !== "undefined" && typeof server.root !== "string")
23
+ throw createConfigError(
24
+ filePath,
25
+ `${staging}.server.root`,
26
+ "must be a string"
27
+ );
28
+ if (typeof server.base !== "undefined" && typeof server.base !== "string")
29
+ throw createConfigError(
30
+ filePath,
31
+ `${staging}.server.base`,
32
+ "must be a string"
33
+ );
34
+ }
35
+ function validateFaasYaml(filePath, config) {
36
+ if (typeof config === "undefined" || config === null)
37
+ return /* @__PURE__ */ Object.create(null);
38
+ if (!isObject(config))
39
+ throw createConfigError(filePath, "<root>", "must be an object");
40
+ for (const staging in config) {
41
+ if (staging === "types")
42
+ throw createConfigError(
43
+ filePath,
44
+ "types",
45
+ "has been removed, move related settings out of faas.yaml"
46
+ );
47
+ const stageConfig = config[staging];
48
+ if (typeof stageConfig === "undefined" || stageConfig === null) continue;
49
+ if (!isObject(stageConfig))
50
+ throw createConfigError(filePath, staging, "must be an object");
51
+ if (Object.hasOwn(stageConfig, "types"))
52
+ throw createConfigError(
53
+ filePath,
54
+ `${staging}.types`,
55
+ "has been removed, move related settings out of faas.yaml"
56
+ );
57
+ if (Object.hasOwn(stageConfig, "server"))
58
+ validateServerConfig(filePath, staging, stageConfig.server);
59
+ }
60
+ return config;
61
+ }
11
62
  var Config = class {
12
63
  root;
13
64
  filename;
@@ -32,7 +83,10 @@ var Config = class {
32
83
  const faas = path.join(root2, "faas.yaml");
33
84
  if (fs.existsSync(faas))
34
85
  configs.push(
35
- jsYaml.load(fs.readFileSync(faas).toString())
86
+ validateFaasYaml(
87
+ faas,
88
+ jsYaml.load(fs.readFileSync(faas).toString())
89
+ )
36
90
  );
37
91
  return root2;
38
92
  });
package/dist/index.mjs CHANGED
@@ -5,6 +5,57 @@ import { Logger } from '@faasjs/logger';
5
5
  import { load } from 'js-yaml';
6
6
 
7
7
  // src/load_config.ts
8
+ function isObject(value) {
9
+ return !!value && typeof value === "object" && !Array.isArray(value);
10
+ }
11
+ function createConfigError(filePath, keyPath, reason) {
12
+ return Error(
13
+ `[loadConfig] Invalid faas.yaml ${filePath} at "${keyPath}": ${reason}`
14
+ );
15
+ }
16
+ function validateServerConfig(filePath, staging, server) {
17
+ if (!isObject(server))
18
+ throw createConfigError(filePath, `${staging}.server`, "must be an object");
19
+ if (typeof server.root !== "undefined" && typeof server.root !== "string")
20
+ throw createConfigError(
21
+ filePath,
22
+ `${staging}.server.root`,
23
+ "must be a string"
24
+ );
25
+ if (typeof server.base !== "undefined" && typeof server.base !== "string")
26
+ throw createConfigError(
27
+ filePath,
28
+ `${staging}.server.base`,
29
+ "must be a string"
30
+ );
31
+ }
32
+ function validateFaasYaml(filePath, config) {
33
+ if (typeof config === "undefined" || config === null)
34
+ return /* @__PURE__ */ Object.create(null);
35
+ if (!isObject(config))
36
+ throw createConfigError(filePath, "<root>", "must be an object");
37
+ for (const staging in config) {
38
+ if (staging === "types")
39
+ throw createConfigError(
40
+ filePath,
41
+ "types",
42
+ "has been removed, move related settings out of faas.yaml"
43
+ );
44
+ const stageConfig = config[staging];
45
+ if (typeof stageConfig === "undefined" || stageConfig === null) continue;
46
+ if (!isObject(stageConfig))
47
+ throw createConfigError(filePath, staging, "must be an object");
48
+ if (Object.hasOwn(stageConfig, "types"))
49
+ throw createConfigError(
50
+ filePath,
51
+ `${staging}.types`,
52
+ "has been removed, move related settings out of faas.yaml"
53
+ );
54
+ if (Object.hasOwn(stageConfig, "server"))
55
+ validateServerConfig(filePath, staging, stageConfig.server);
56
+ }
57
+ return config;
58
+ }
8
59
  var Config = class {
9
60
  root;
10
61
  filename;
@@ -29,7 +80,10 @@ var Config = class {
29
80
  const faas = join(root2, "faas.yaml");
30
81
  if (existsSync(faas))
31
82
  configs.push(
32
- load(readFileSync(faas).toString())
83
+ validateFaasYaml(
84
+ faas,
85
+ load(readFileSync(faas).toString())
86
+ )
33
87
  );
34
88
  return root2;
35
89
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/load",
3
- "version": "v8.0.0-beta.4",
3
+ "version": "8.0.0-beta.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -31,14 +31,14 @@
31
31
  ],
32
32
  "peerDependencies": {
33
33
  "js-yaml": "*",
34
- "@faasjs/deep_merge": ">=v8.0.0-beta.4",
35
- "@faasjs/func": ">=v8.0.0-beta.4"
34
+ "@faasjs/deep_merge": ">=8.0.0-beta.6",
35
+ "@faasjs/func": ">=8.0.0-beta.6"
36
36
  },
37
37
  "devDependencies": {
38
38
  "js-yaml": "*",
39
39
  "@types/js-yaml": "*",
40
- "@faasjs/deep_merge": ">=v8.0.0-beta.4",
41
- "@faasjs/func": ">=v8.0.0-beta.4"
40
+ "@faasjs/deep_merge": ">=8.0.0-beta.6",
41
+ "@faasjs/func": ">=8.0.0-beta.6"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=24.0.0",