@lwrjs/diagnostics 0.7.0-alpha.9 → 0.7.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.
@@ -1,9 +1,25 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2
7
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
8
  var __export = (target, all) => {
4
9
  for (var name in all)
5
10
  __defProp(target, name, {get: all[name], enumerable: true});
6
11
  };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
7
23
 
8
24
  // packages/@lwrjs/diagnostics/src/errors.ts
9
25
  __markAsModule(exports);
@@ -12,9 +28,11 @@ __export(exports, {
12
28
  LwrConfigValidationError: () => LwrConfigValidationError,
13
29
  LwrServerError: () => LwrServerError,
14
30
  LwrUnresolvableError: () => LwrUnresolvableError,
31
+ createReturnStatus: () => createReturnStatus,
15
32
  createSingleDiagnosticError: () => createSingleDiagnosticError,
16
33
  isNodeError: () => isNodeError
17
34
  });
35
+ var import_descriptions = __toModule(require("./descriptions/index.cjs"));
18
36
  function isNodeError(error) {
19
37
  return error instanceof Error;
20
38
  }
@@ -46,3 +64,16 @@ var LwrUnresolvableError = class extends DiagnosticsError {
46
64
  };
47
65
  var LwrServerError = class extends DiagnosticsError {
48
66
  };
67
+ function createReturnStatus(name, error) {
68
+ let returnStatus = {status: 501, message: ""};
69
+ if (isNodeError(error) && error.code === "NO_LWC_MODULE_FOUND") {
70
+ returnStatus = {status: 404, message: import_descriptions.descriptions.UNRESOLVABLE.LWC_MODULE(name).message};
71
+ } else if (error instanceof LwrUnresolvableError && error.diagnostics[0].description.category === "lwrUnresolvable/invalid") {
72
+ returnStatus = {status: 400, message: error.message};
73
+ } else if (error instanceof LwrUnresolvableError) {
74
+ returnStatus = {status: 404, message: error.message};
75
+ } else {
76
+ returnStatus = {status: 500, message: import_descriptions.descriptions.UNRESOLVABLE.SERVER_ERROR(name).message};
77
+ }
78
+ return returnStatus;
79
+ }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Diagnostic, Diagnostics } from './types';
2
+ import { Diagnostic, Diagnostics } from './types.js';
3
3
  export declare function isNodeError(error: unknown): error is NodeJS.ErrnoException;
4
4
  export declare function createSingleDiagnosticError(diag: Diagnostic, errorClass?: typeof DiagnosticsError): DiagnosticsError;
5
5
  export declare class DiagnosticsError extends Error {
@@ -15,4 +15,14 @@ export declare class LwrUnresolvableError extends DiagnosticsError {
15
15
  }
16
16
  export declare class LwrServerError extends DiagnosticsError {
17
17
  }
18
+ /**
19
+ * Create a status object Express can return when there is an error
20
+ *
21
+ * @param name - string name of the problem module/resource
22
+ * @param error - an Error/Diagnostic object; thrown from try/catch
23
+ */
24
+ export declare function createReturnStatus(name: string, error: unknown): {
25
+ status: number;
26
+ message: string;
27
+ };
18
28
  //# sourceMappingURL=errors.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { descriptions } from './descriptions/index.js';
1
2
  // The NodeJS Error is different from the JavaScript Error (e.g. NodeJS Error has a code)
2
3
  export function isNodeError(error) {
3
4
  return error instanceof Error;
@@ -32,4 +33,27 @@ export class LwrUnresolvableError extends DiagnosticsError {
32
33
  }
33
34
  export class LwrServerError extends DiagnosticsError {
34
35
  }
36
+ /**
37
+ * Create a status object Express can return when there is an error
38
+ *
39
+ * @param name - string name of the problem module/resource
40
+ * @param error - an Error/Diagnostic object; thrown from try/catch
41
+ */
42
+ export function createReturnStatus(name, error) {
43
+ let returnStatus = { status: 501, message: '' };
44
+ if (isNodeError(error) && error.code === 'NO_LWC_MODULE_FOUND') {
45
+ returnStatus = { status: 404, message: descriptions.UNRESOLVABLE.LWC_MODULE(name).message };
46
+ }
47
+ else if (error instanceof LwrUnresolvableError &&
48
+ error.diagnostics[0].description.category === 'lwrUnresolvable/invalid') {
49
+ returnStatus = { status: 400, message: error.message };
50
+ }
51
+ else if (error instanceof LwrUnresolvableError) {
52
+ returnStatus = { status: 404, message: error.message };
53
+ }
54
+ else {
55
+ returnStatus = { status: 500, message: descriptions.UNRESOLVABLE.SERVER_ERROR(name).message };
56
+ }
57
+ return returnStatus;
58
+ }
35
59
  //# sourceMappingURL=errors.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.9",
7
+ "version": "0.7.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,10 +30,10 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "devDependencies": {
33
- "@lwrjs/types": "0.7.0-alpha.9"
33
+ "@lwrjs/types": "0.7.0"
34
34
  },
35
35
  "engines": {
36
- "node": ">=14.15.4 <17"
36
+ "node": ">=14.15.4 <19"
37
37
  },
38
- "gitHead": "522665298cc74f1898da6ed018fa72504bd72645"
38
+ "gitHead": "c6dcb52144a8da80170e30d49a87e29d2da30f9b"
39
39
  }