tshex-cli 1.0.24 → 1.0.26

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/source/main.ts CHANGED
@@ -55,7 +55,13 @@ function executeCreateReactContext(templatesDir: string, contextDir: string) {
55
55
  }
56
56
  }
57
57
 
58
- function executeCreateTests(sourceDir: string, destinationDir: string, fileContents: string, ignoredSourceDir?: string) {
58
+ function executeCreateTests(
59
+ sourceDir: string,
60
+ destinationDir: string,
61
+ fileContents: string,
62
+ ignoredSourceDir?: string,
63
+ rootSourceDir: string = sourceDir
64
+ ) {
59
65
  const entries = fs.readdirSync(sourceDir, { withFileTypes: true })
60
66
 
61
67
  if (fs.existsSync(destinationDir) === false) {
@@ -67,7 +73,7 @@ function executeCreateTests(sourceDir: string, destinationDir: string, fileConte
67
73
  const destinationPath = path.join(destinationDir, entry.name)
68
74
 
69
75
  if (entry.isDirectory()) {
70
- if (entry.name === 'shared') {
76
+ if (entry.name === 'shared' && sourceDir === rootSourceDir) {
71
77
  continue
72
78
  }
73
79
 
@@ -79,7 +85,7 @@ function executeCreateTests(sourceDir: string, destinationDir: string, fileConte
79
85
  continue
80
86
  }
81
87
 
82
- executeCreateTests(sourcePath, destinationPath, fileContents, ignoredSourceDir)
88
+ executeCreateTests(sourcePath, destinationPath, fileContents, ignoredSourceDir, rootSourceDir)
83
89
  continue
84
90
  }
85
91
 
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @description Http request handler to process incoming requests and generate responses.
3
+ */
4
+ export interface HttpRequestHandler {
5
+ handle(request: Request): Response | Promise<Response>
6
+ }
7
+
8
+ /**
9
+ * @description An HTTP middleware that pipes requests through handlers.
10
+ */
11
+ export interface HttpMiddleware {
12
+ process(request: Request, handler: HttpRequestHandler): Response | Promise<Response>
13
+ }
14
+
15
+ /**
16
+ * @description HTTP error with a specific status code and message.
17
+ */
18
+ export class HttpError extends Error {
19
+ public static readonly messages: { [code: number]: string } = Object.freeze({
20
+ 400: 'Bad Request',
21
+ 401: 'Unauthorized',
22
+ 402: 'Payment Required',
23
+ 403: 'Forbidden',
24
+ 404: 'Not Found',
25
+ 405: 'Method Not Allowed',
26
+ 406: 'Not Acceptable',
27
+ 407: 'Proxy Authentication Required',
28
+ 408: 'Request Timeout',
29
+ 409: 'Conflict',
30
+ 410: 'Gone',
31
+ 411: 'Length Required',
32
+ 412: 'Precondition Failed',
33
+ 413: 'Content Too Large',
34
+ 414: 'URI Too Long',
35
+ 415: 'Unsupported Media Type',
36
+ 416: 'Range Not Satisfiable',
37
+ 417: 'Expectation Failed',
38
+ 418: "I'm a teapot",
39
+ 421: 'Misdirected Request',
40
+ 422: 'Unprocessable Content',
41
+ 423: 'Locked',
42
+ 424: 'Failed Dependency',
43
+ 425: 'Too Early',
44
+ 426: 'Upgrade Required',
45
+ 428: 'Precondition Required',
46
+ 429: 'Too Many Requests',
47
+ 431: 'Request Header Fields Too Large',
48
+ 451: 'Unavailable For Legal Reasons',
49
+ 500: 'Internal Server Error',
50
+ 501: 'Not Implemented',
51
+ 502: 'Bad Gateway',
52
+ 503: 'Service Unavailable',
53
+ 504: 'Gateway Timeout',
54
+ 505: 'HTTP Version Not Supported',
55
+ 506: 'Variant Also Negotiates',
56
+ 507: 'Insufficient Storage',
57
+ 508: 'Loop Detected',
58
+ 510: 'Not Extended',
59
+ 511: 'Network Authentication Required'
60
+ })
61
+
62
+ public readonly code: number
63
+
64
+ /**
65
+ * Creates an instance of HttpError.
66
+ *
67
+ * @constructor
68
+ * @param {number} code - The HTTP status code.
69
+ * @param {string} [message] - Fallback message if the status code is not recognized.
70
+ */
71
+ constructor(code: number, message?: string) {
72
+ super(message ?? HttpError.messages[code] ?? 'Unknown Error')
73
+ this.code = code
74
+ this.name = 'HttpError'
75
+ }
76
+ }