@torpor/build 1.0.0 → 1.0.1

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.
Files changed (174) hide show
  1. package/dist/{flattenHeaders-C_YYLdOq.mjs → Server-BnjLJleZ.mjs} +2 -12
  2. package/dist/Server-BnjLJleZ.mjs.map +1 -0
  3. package/dist/{Server-C_IKav_e.d.mts → Server-Cler2w5O.d.mts} +3 -48
  4. package/dist/Server-Cler2w5O.d.mts.map +1 -0
  5. package/dist/ServerEvent-CTx3Q-hk.d.mts +48 -0
  6. package/dist/ServerEvent-CTx3Q-hk.d.mts.map +1 -0
  7. package/dist/{Site-CMa153FA.d.mts → Site-CE0_o5Ci.d.mts} +3 -2
  8. package/dist/Site-CE0_o5Ci.d.mts.map +1 -0
  9. package/dist/bin/index.js +1 -1
  10. package/dist/clientEntry.d.mts +1 -0
  11. package/dist/clientEntry.mjs +59 -0
  12. package/dist/clientEntry.mjs.map +1 -0
  13. package/dist/clientEntryDev.d.mts +1 -0
  14. package/dist/clientEntryDev.mjs +7 -0
  15. package/dist/clientEntryDev.mjs.map +1 -0
  16. package/dist/dev.d.mts +3 -0
  17. package/dist/dev.mjs +3 -0
  18. package/dist/endpoint-EULRGCKA.mjs +108 -0
  19. package/dist/endpoint-EULRGCKA.mjs.map +1 -0
  20. package/dist/flattenHeaders-DM5qsSqO.mjs +13 -0
  21. package/dist/flattenHeaders-DM5qsSqO.mjs.map +1 -0
  22. package/dist/index.d.mts +1 -1
  23. package/dist/load-BntzvmwL.mjs +228 -0
  24. package/dist/load-BntzvmwL.mjs.map +1 -0
  25. package/dist/nav.mjs +1 -225
  26. package/dist/nav.mjs.map +1 -1
  27. package/dist/openapi.d.mts +1 -1
  28. package/dist/run.d.mts +1 -1
  29. package/dist/run.d.mts.map +1 -1
  30. package/dist/run.mjs +1 -1
  31. package/dist/{runOpenApi-BUi1RH1l.mjs → runOpenApi-DlOgF2Il.mjs} +54 -16
  32. package/dist/runOpenApi-DlOgF2Il.mjs.map +1 -0
  33. package/dist/server/Server.d.mts +2 -0
  34. package/dist/server/Server.mjs +2 -0
  35. package/dist/server.d.mts +2 -1
  36. package/dist/server.d.mts.map +1 -1
  37. package/dist/server.mjs +2 -1
  38. package/dist/server.mjs.map +1 -1
  39. package/dist/serverEntry-1qY3wZig.mjs +351 -0
  40. package/dist/serverEntry-1qY3wZig.mjs.map +1 -0
  41. package/dist/serverEntry-BAO8m03V.d.mts +6 -0
  42. package/dist/serverEntry-BAO8m03V.d.mts.map +1 -0
  43. package/dist/serverEntry.d.mts +2 -0
  44. package/dist/serverEntry.mjs +2 -0
  45. package/dist/test.d.mts +2 -2
  46. package/dist/test.mjs +2 -104
  47. package/dist/test.mjs.map +1 -1
  48. package/package.json +9 -8
  49. package/dist/Server-C_IKav_e.d.mts.map +0 -1
  50. package/dist/Site-CMa153FA.d.mts.map +0 -1
  51. package/dist/flattenHeaders-C_YYLdOq.mjs.map +0 -1
  52. package/dist/runOpenApi-BUi1RH1l.mjs.map +0 -1
  53. package/src/bin/index.ts +0 -22
  54. package/src/dev.ts +0 -10
  55. package/src/form/formDataToRecord.ts +0 -23
  56. package/src/form/readForm.ts +0 -71
  57. package/src/form.ts +0 -4
  58. package/src/index.ts +0 -82
  59. package/src/nav/api.test-d.ts +0 -79
  60. package/src/nav/api.ts +0 -104
  61. package/src/nav/formSubmit.ts +0 -70
  62. package/src/nav/load.ts +0 -9
  63. package/src/nav/loadData.ts +0 -134
  64. package/src/nav/navigate.ts +0 -189
  65. package/src/nav/reload.ts +0 -9
  66. package/src/nav/route.ts +0 -38
  67. package/src/nav.ts +0 -6
  68. package/src/openapi/docsHtml.ts +0 -25
  69. package/src/openapi/document.ts +0 -154
  70. package/src/openapi/plugin.ts +0 -78
  71. package/src/openapi/types.ts +0 -82
  72. package/src/openapi.ts +0 -14
  73. package/src/response/TypedResponse.ts +0 -17
  74. package/src/response/badRequest.ts +0 -31
  75. package/src/response/created.ts +0 -31
  76. package/src/response/forbidden.ts +0 -21
  77. package/src/response/found.ts +0 -30
  78. package/src/response/methodNotAllowed.ts +0 -18
  79. package/src/response/movedPermanently.ts +0 -25
  80. package/src/response/notFound.ts +0 -24
  81. package/src/response/notModified.ts +0 -34
  82. package/src/response/ok.ts +0 -38
  83. package/src/response/permanentRedirect.ts +0 -30
  84. package/src/response/response.ts +0 -22
  85. package/src/response/seeOther.ts +0 -19
  86. package/src/response/serverError.ts +0 -24
  87. package/src/response/temporaryRedirect.ts +0 -31
  88. package/src/response/transfer.ts +0 -14
  89. package/src/response/unauthorized.ts +0 -21
  90. package/src/response/unprocessable.ts +0 -30
  91. package/src/response.ts +0 -37
  92. package/src/run/depCache.ts +0 -175
  93. package/src/run/devPlugin.ts +0 -128
  94. package/src/run/prepareTemplate.ts +0 -42
  95. package/src/run/run.ts +0 -86
  96. package/src/run/runBuild.ts +0 -128
  97. package/src/run/runDev.ts +0 -177
  98. package/src/run/runOpenApi.ts +0 -52
  99. package/src/run/runPreview.ts +0 -84
  100. package/src/run/staleTorpCopies.ts +0 -100
  101. package/src/run.ts +0 -7
  102. package/src/schema.ts +0 -7
  103. package/src/server/CookieHelper.ts +0 -46
  104. package/src/server/HeaderHelper.ts +0 -25
  105. package/src/server/Server.ts +0 -168
  106. package/src/server/ServerEvent.ts +0 -62
  107. package/src/server/connect/connectMiddleware.ts +0 -85
  108. package/src/server/connect/flattenHeaders.ts +0 -22
  109. package/src/server/connect/nodeMessageToNodeResponse.ts +0 -89
  110. package/src/server/connect/requestToNodeMessage.ts +0 -29
  111. package/src/server/contentType.ts +0 -85
  112. package/src/server/types/HttpMethod.ts +0 -12
  113. package/src/server/types/MiddlewareFunction.ts +0 -22
  114. package/src/server/types/ServerFunction.ts +0 -7
  115. package/src/server.ts +0 -7
  116. package/src/site/Router.ts +0 -175
  117. package/src/site/Site.ts +0 -388
  118. package/src/site/checkLayoutSlots.ts +0 -114
  119. package/src/site/checkRoutes.ts +0 -435
  120. package/src/site/clientEntry.ts +0 -121
  121. package/src/site/clientEntryDev.ts +0 -3
  122. package/src/site/defaultAdapter.ts +0 -11
  123. package/src/site/layoutSlots.ts +0 -53
  124. package/src/site/manifest.ts +0 -173
  125. package/src/site/serverEntry.ts +0 -648
  126. package/src/state/$page.ts +0 -25
  127. package/src/state/$serverPage.ts +0 -22
  128. package/src/state/client.ts +0 -15
  129. package/src/state.ts +0 -3
  130. package/src/test/runTest.ts +0 -538
  131. package/src/test.ts +0 -3
  132. package/src/types/Adapter.ts +0 -20
  133. package/src/types/ClientState.ts +0 -8
  134. package/src/types/InternalState.ts +0 -7
  135. package/src/types/Jsonify.ts +0 -20
  136. package/src/types/LayoutHandler.ts +0 -5
  137. package/src/types/LayoutPath.ts +0 -10
  138. package/src/types/ManifestRoute.ts +0 -6
  139. package/src/types/PageData.test-d.ts +0 -136
  140. package/src/types/PageData.ts +0 -35
  141. package/src/types/PageEndPoint.ts +0 -55
  142. package/src/types/PageForm.test-d.ts +0 -78
  143. package/src/types/PageForm.ts +0 -29
  144. package/src/types/PageLoadEvent.ts +0 -26
  145. package/src/types/PageLoadReturn.ts +0 -13
  146. package/src/types/PageProps.ts +0 -14
  147. package/src/types/PageServerAction.ts +0 -13
  148. package/src/types/PageServerEndPoint.test-d.ts +0 -105
  149. package/src/types/PageServerEndPoint.ts +0 -110
  150. package/src/types/PageServerLoad.ts +0 -15
  151. package/src/types/PageState.ts +0 -8
  152. package/src/types/ParseRouteParams.test-d.ts +0 -84
  153. package/src/types/ParseRouteParams.ts +0 -64
  154. package/src/types/Route.ts +0 -30
  155. package/src/types/RouteHandler.ts +0 -23
  156. package/src/types/RouteLayoutHandler.ts +0 -5
  157. package/src/types/RouteMatchResult.ts +0 -7
  158. package/src/types/RouteType.ts +0 -19
  159. package/src/types/ServerEndPoint.test-d.ts +0 -77
  160. package/src/types/ServerEndPoint.ts +0 -169
  161. package/src/types/ServerHook.ts +0 -18
  162. package/src/types/ServerLoadEvent.ts +0 -82
  163. package/src/types/ServerRequest.ts +0 -15
  164. package/src/types/SitePlugin.ts +0 -24
  165. package/src/types/StandardSchema.ts +0 -109
  166. package/src/utils/pathToRegex.ts +0 -17
  167. package/src/utils/pathTrie.ts +0 -182
  168. package/src/utils/searchParamsToRecord.ts +0 -18
  169. package/src/utils/torporPackages.ts +0 -150
  170. package/src/utils/tsconfigAliases.ts +0 -90
  171. package/src/validation/ValidationError.ts +0 -18
  172. package/src/validation/endpoint.ts +0 -83
  173. package/src/validation/validate.ts +0 -26
  174. package/src/vite-env.d.ts +0 -2
@@ -1,21 +0,0 @@
1
- import response from "./response";
2
-
3
- /**
4
- * 403 Forbidden
5
- *
6
- * The HTTP 403 Forbidden client error response status code indicates that the
7
- * server understood the request but refused to process it. This status is
8
- * similar to 401, except that for 403 Forbidden responses, authenticating or
9
- * re-authenticating makes no difference. The request failure is tied to
10
- * application logic, such as insufficient permissions to a resource or action.
11
- *
12
- * Clients that receive a 403 response should expect that repeating the request
13
- * without modification will fail with the same error. Server owners may decide
14
- * to send a 404 response instead of a 403 if acknowledging the existence of a
15
- * resource to clients with insufficient privileges is not desired.
16
- *
17
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403
18
- */
19
- export default function forbidden(body?: object | string): Response {
20
- return response(403, body ?? "Forbidden");
21
- }
@@ -1,30 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 302 Found
5
- *
6
- * The HTTP 302 Found redirection response status code indicates that the
7
- * requested resource has been temporarily moved to the URL in the Location
8
- * header.
9
- *
10
- * A browser receiving this status will automatically request the resource at
11
- * the URL in the Location header, redirecting the user to the new page. Search
12
- * engines receiving this response will not attribute links to the original URL
13
- * to the new resource, meaning no SEO value is transferred to the new URL.
14
- *
15
- * > Note: In the Fetch Standard, when a user agent receives a 302 in response
16
- * > to a POST request, it uses the GET method in the subsequent redirection
17
- * > request, as permitted by the HTTP specification. To avoid user agents
18
- * > modifying the request, use 307 Temporary Redirect instead, as altering the
19
- * > method after a 307 response is prohibited.
20
- *
21
- * > In cases where you want any request method to be changed to GET, use 303
22
- * > See Other. This is useful when you want to give a response to a PUT method
23
- * > that is not the uploaded resource but a confirmation message such as: "you
24
- * > successfully uploaded XYZ".
25
- *
26
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302
27
- */
28
- export default function found(location: string): Response {
29
- return transfer(302, location);
30
- }
@@ -1,18 +0,0 @@
1
- import response from "./response";
2
-
3
- /**
4
- * 405 Method Not Allowed
5
- *
6
- * The HTTP 405 Method Not Allowed client error response status code indicates
7
- * that the server knows the request method, but the target resource doesn't
8
- * support this method. The server must generate an Allow header in a 405
9
- * response with a list of methods that the target resource currently supports.
10
- *
11
- * Improper server-side permissions set on files or directories may cause a 405
12
- * response when the request would otherwise be expected to succeed.
13
- *
14
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/405
15
- */
16
- export default function methodNotAllowed(body?: object | string): Response {
17
- return response(405, body ?? "Method not allowed");
18
- }
@@ -1,25 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 301 Moved Permanently
5
- *
6
- * The HTTP 301 Moved Permanently redirection response status code indicates
7
- * that the requested resource has been permanently moved to the URL in the
8
- * Location header.
9
- *
10
- * A browser receiving this status will automatically request the resource at
11
- * the URL in the Location header, redirecting the user to the new page. Search
12
- * engines receiving this response will attribute links to the original URL to
13
- * the redirected resource, passing the SEO ranking to the new URL.
14
- *
15
- * > Note: In the Fetch Standard, when a user agent receives a 301 in response
16
- * > to a POST request, it uses the GET method in the subsequent redirection
17
- * > request, as permitted by the HTTP specification. To avoid user agents
18
- * > modifying the request, use 308 Permanent Redirect instead, as altering the
19
- * > method after a 308 response is prohibited.
20
- *
21
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301
22
- */
23
- export default function movedPermanently(location: string): Response {
24
- return transfer(301, location);
25
- }
@@ -1,24 +0,0 @@
1
- import response from "./response";
2
-
3
- /**
4
- * 404 Not Found
5
- *
6
- * The HTTP 404 Not Found client error response status code indicates that the
7
- * server cannot find the requested resource. Links that lead to a 404 page are
8
- * often called broken or dead links and can be subject to link rot.
9
- *
10
- * A 404 status code only indicates that the resource is missing without
11
- * indicating if this is temporary or permanent. If a resource is permanently
12
- * removed, servers should send the 410 Gone status instead.
13
- *
14
- * 404 errors on a website can lead to a poor user experience for your visitors,
15
- * so the number of broken links (internal and external) should be minimized to
16
- * prevent frustration for readers. Common causes of 404 responses are mistyped
17
- * URLs or pages that are moved or deleted without redirection. For more
18
- * information, see the Redirections in HTTP guide.
19
- *
20
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404
21
- */
22
- export default function notFound(body?: object | string): Response {
23
- return response(404, body ?? "Not found");
24
- }
@@ -1,34 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 304 Not Modified
5
- *
6
- * The HTTP 304 Not Modified redirection response status code indicates that
7
- * there is no need to retransmit the requested resources.
8
- *
9
- * This response code is sent when the request is a conditional GET or HEAD
10
- * request with an If-None-Match or an If-Modified-Since header and the
11
- * condition evaluates to 'false'. It confirms that the resource cached by the
12
- * client is still valid and that the server would have sent a 200 OK response
13
- * with the resource if the condition evaluated to 'true'. See HTTP caching for
14
- * more information.
15
- *
16
- * The response must not contain a body and must include the headers that would
17
- * have been sent in an equivalent 200 response, such as:
18
- *
19
- * - Cache-Control
20
- * - Content-Location
21
- * - Date
22
- * - ETag
23
- * - Expires
24
- * - Vary
25
- *
26
- * > Note: Many developer tools' network panels of browsers create extraneous
27
- * > requests leading to 304 responses, so that access to the local cache is
28
- * > visible to developers.
29
- *
30
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304
31
- */
32
- export default function notModified(): Response {
33
- return transfer(304, "");
34
- }
@@ -1,38 +0,0 @@
1
- import type { Jsonify } from "../types/Jsonify";
2
- import type TypedResponse from "./TypedResponse";
3
- import response from "./response";
4
-
5
- type OkResponse<T extends object | string | undefined> = T extends object
6
- ? TypedResponse<Jsonify<T>>
7
- : Response;
8
-
9
- /**
10
- * 200 OK
11
- *
12
- * The HTTP 200 OK successful response status code indicates that a request has
13
- * succeeded. A 200 OK response is cacheable by default.
14
- *
15
- * A 200 OK response has a different meaning and format depending on the HTTP
16
- * request method. Here's how they vary for different methods:
17
- *
18
- * - GET: A resource was retrieved by the server and included in the response
19
- * body.
20
- * - POST: An action succeeded; the response has a message body describing the
21
- * result.
22
- * - HEAD: Identical to GET, except there is no message body.
23
- * - TRACE: The response has a message body containing the request as received
24
- * by the server.
25
- *
26
- * Although possible, successful PUT or DELETE requests often do not result in
27
- * a 200 OK response. It is more common to see 201 Created if the resource is
28
- * uploaded or created for the first time, or 204 No Content upon successful
29
- * deletion of a resource.
30
- *
31
- * An object body is typed: the client sees its JSON form through
32
- * `makeApi`-created callers.
33
- *
34
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/200
35
- */
36
- export default function ok<T extends object | string | undefined>(body?: T): OkResponse<T> {
37
- return response(200, body) as OkResponse<T>;
38
- }
@@ -1,30 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 308 Permanent Redirect
5
- *
6
- * The HTTP 308 Permanent Redirect redirection response status code indicates
7
- * that the requested resource has been permanently moved to the URL given by
8
- * the Location header.
9
- *
10
- * A browser receiving this status will automatically request the resource at
11
- * the URL in the Location header, redirecting the user to the new page. Search
12
- * engines receiving this response will attribute links to the original URL to
13
- * the redirected resource, passing the SEO ranking to the new URL.
14
- *
15
- * The request method and the body will not be modified by the client in the
16
- * redirected request. A 301 Moved Permanently requires the request method and
17
- * the body to remain unchanged when redirection is performed, but this is
18
- * incorrectly handled by older clients to use the GET method instead.
19
- *
20
- * > Note: Some Web applications may use the 308 Permanent Redirect in a
21
- * > non-standard way and for different purposes. For example, Google Drive uses
22
- * > a 308 Resume Incomplete response to indicate to the client when an
23
- * > unfinished upload has stalled. See Perform a resumable download on the
24
- * > Google Drive documentation for more information.
25
- *
26
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308
27
- */
28
- export default function permanentRedirect(location: string): Response {
29
- return transfer(308, location);
30
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Creates a response with the supplied status code and optional body.
3
- *
4
- * If the body is an object, it will be converted to JSON and the Content-Type
5
- * header set to "application/json". Otherwise, if the body is a string, the
6
- * Content-Type header will be set to "text/plain".
7
- */
8
- export default function response(status: number, body?: object | string): Response {
9
- let headers: Record<string, string> | undefined = undefined;
10
- if (body) {
11
- if (typeof body === "object") {
12
- headers = { "Content-Type": "application/json" };
13
- body = JSON.stringify(body);
14
- } else {
15
- headers = { "Content-Type": "text/plain" };
16
- }
17
- }
18
- return new Response(body, {
19
- status,
20
- headers,
21
- });
22
- }
@@ -1,19 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 303 See Other
5
- *
6
- * The HTTP 303 See Other redirection response status code indicates that the
7
- * browser should redirect to the URL in the Location header instead of
8
- * rendering the requested resource.
9
- *
10
- * This response code is often sent back as a result of PUT or POST methods so
11
- * the client may retrieve a confirmation, or view a representation of a
12
- * real-world object (see HTTP range-14). The method to retrieve the redirected
13
- * resource is always GET.
14
- *
15
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303
16
- */
17
- export default function seeOther(location: string): Response {
18
- return transfer(303, location);
19
- }
@@ -1,24 +0,0 @@
1
- import response from "./response";
2
-
3
- /**
4
- * 500 Server Error
5
- *
6
- * The HTTP 500 Internal Server Error server error response status code
7
- * indicates that the server encountered an unexpected condition that prevented
8
- * it from fulfilling the request. This error is a generic "catch-all" response
9
- * to server issues, indicating that the server cannot find a more appropriate
10
- * 5XX error to respond with.
11
- *
12
- * If you're a visitor seeing 500 errors on a web page, these issues require
13
- * investigation by server owners or administrators. There are many possible
14
- * causes of 500 errors, including: improper server configuration, out-of-memory
15
- * (OOM) issues, unhandled exceptions, improper file permissions, or other
16
- * complex factors. Server administrators may proactively log occurrences of
17
- * server error responses, like the 500 status code, with details about the
18
- * initiating requests to improve the stability of a service in the future.
19
- *
20
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500
21
- */
22
- export default function serverError(body?: object | string): Response {
23
- return response(500, body ?? "Server error");
24
- }
@@ -1,31 +0,0 @@
1
- import transfer from "./transfer";
2
-
3
- /**
4
- * 307 Temporary Redirect
5
- *
6
- * The HTTP 307 Temporary Redirect redirection response status code indicates
7
- * that the resource requested has been temporarily moved to the URL in the
8
- * Location header.
9
- *
10
- * A browser receiving this status will automatically request the resource at
11
- * the URL in the Location header, redirecting the user to the new page. Search
12
- * engines receiving this response will not attribute links to the original URL
13
- * to the new resource, meaning no SEO value is transferred to the new URL.
14
- *
15
- * The method and the body of the original request are reused to perform the
16
- * redirected request. In the cases where you want the request method to be
17
- * changed to GET, use 303 See Other instead. This is useful when you want to
18
- * give an answer to a successful PUT request that is not the uploaded resource,
19
- * but a status monitor or confirmation message like "You have successfully
20
- * uploaded XYZ".
21
- *
22
- * The difference between 307 and 302 is that 307 guarantees that the client
23
- * will not change the request method and body when the redirected request is
24
- * made. With 302, older clients incorrectly changed the method to GET. 307 and
25
- * 302 responses are identical when the request method is GET.
26
- *
27
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307
28
- */
29
- export default function temporaryRedirect(location: string): Response {
30
- return transfer(307, location);
31
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Creates a redirect response with the supplied status code.
3
- */
4
- export default function transfer(
5
- status: 300 | 301 | 302 | 303 | 304 | 307 | 308,
6
- location: string,
7
- ): Response {
8
- return new Response(null, {
9
- status,
10
- headers: {
11
- location,
12
- },
13
- });
14
- }
@@ -1,21 +0,0 @@
1
- import response from "./response";
2
-
3
- /**
4
- * 401 Unauthorized
5
- *
6
- * The HTTP 401 Unauthorized client error response status code indicates that a
7
- * request was not successful because it lacks valid authentication credentials
8
- * for the requested resource. This status code is sent with an HTTP
9
- * WWW-Authenticate response header that contains information on the
10
- * authentication scheme the server expects the client to include to make the
11
- * request successfully.
12
- *
13
- * A 401 Unauthorized is similar to the 403 Forbidden response, except that a
14
- * 403 is returned when a request contains valid credentials, but the client
15
- * does not have permissions to perform a certain action.
16
- *
17
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401
18
- */
19
- export default function unauthorized(body?: object | string): Response {
20
- return response(401, body ?? "Unauthorized");
21
- }
@@ -1,30 +0,0 @@
1
- import response from "./response";
2
- import type { Jsonify } from "../types/Jsonify";
3
- import type TypedResponse from "./TypedResponse";
4
-
5
- type UnprocessableResponse<T extends object | string | undefined> = T extends object
6
- ? TypedResponse<Jsonify<T>>
7
- : Response;
8
-
9
- /**
10
- * 422 Unprocessable Content
11
- *
12
- * The HTTP 422 Unprocessable Content client error response status code
13
- * indicates that the server understood the content type of the request content,
14
- * and the syntax of the request content was correct, but it was unable to
15
- * process the contained instructions.
16
- *
17
- * Clients that receive a 422 response should expect that repeating the request
18
- * without modification will fail with the same error.
19
- *
20
- * An object body is typed: it becomes the page's `$props.form` (with its JSON
21
- * form) after a form submit, so validation errors can be surfaced with their
22
- * field types via `PageForm`.
23
- *
24
- * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/422
25
- */
26
- export default function unprocessable<T extends object | string | undefined>(
27
- body?: T,
28
- ): UnprocessableResponse<T> {
29
- return response(422, body ?? "Unprocessable") as UnprocessableResponse<T>;
30
- }
package/src/response.ts DELETED
@@ -1,37 +0,0 @@
1
- import badRequest from "./response/badRequest";
2
- import created from "./response/created";
3
- import forbidden from "./response/forbidden";
4
- import found from "./response/found";
5
- import methodNotAllowed from "./response/methodNotAllowed";
6
- import movedPermanently from "./response/movedPermanently";
7
- import notFound from "./response/notFound";
8
- import notModified from "./response/notModified";
9
- import ok from "./response/ok";
10
- import permanentRedirect from "./response/permanentRedirect";
11
- import response from "./response/response";
12
- import seeOther from "./response/seeOther";
13
- import serverError from "./response/serverError";
14
- import temporaryRedirect from "./response/temporaryRedirect";
15
- import transfer from "./response/transfer";
16
- import unauthorized from "./response/unauthorized";
17
- import unprocessable from "./response/unprocessable";
18
-
19
- export {
20
- response,
21
- ok,
22
- created,
23
- transfer,
24
- movedPermanently,
25
- found,
26
- seeOther,
27
- notModified,
28
- temporaryRedirect,
29
- permanentRedirect,
30
- badRequest,
31
- unauthorized,
32
- forbidden,
33
- notFound,
34
- methodNotAllowed,
35
- unprocessable,
36
- serverError,
37
- };
@@ -1,175 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import {
3
- existsSync,
4
- readFileSync,
5
- readdirSync,
6
- realpathSync,
7
- rmSync,
8
- statSync,
9
- writeFileSync,
10
- } from "node:fs";
11
- import { createRequire } from "node:module";
12
- import path from "node:path";
13
- import type { PackageJson } from "../utils/torporPackages";
14
-
15
- /**
16
- * Vite's dep-optimization cache (node_modules/.vite) keys off the lockfile
17
- * and config, but not the content of workspace packages. When a workspace
18
- * package is rebuilt while the cache holds prebundled copies of it, dev SSR
19
- * keeps executing the stale modules -- producing bizarre errors (missing
20
- * runtime identifiers, "$cache must be used in a getter", ...) that only a
21
- * manual cache delete fixes.
22
- *
23
- * clearStaleDepCache runs at `tb --dev` startup: it fingerprints every
24
- * workspace package the site depends on (path, size and mtime of each file)
25
- * and, when the fingerprint differs from the previous run, deletes the cache
26
- * so Vite re-optimizes from the rebuilt packages.
27
- *
28
- * Live rebuilds while the server is up are still not hot-invalidated (that
29
- * needs a watcher feeding Vite's module graph); this closes the "restart and
30
- * hope you remember the trick" gap.
31
- */
32
-
33
- const STORE_NAME = ".torpor-dev-cache.json";
34
-
35
- /**
36
- * Clears site/node_modules/.vite when workspace packages changed since the
37
- * last dev run. Returns true when the cache was removed.
38
- */
39
- export function clearStaleDepCache(siteRoot: string, log?: (message: string) => void): boolean {
40
- try {
41
- const workspaceRoot = findWorkspaceRoot(siteRoot);
42
- if (!workspaceRoot) return false;
43
-
44
- const cacheDir = path.join(siteRoot, "node_modules", ".vite");
45
- const storePath = path.join(siteRoot, "node_modules", STORE_NAME);
46
-
47
- const fingerprint = fingerprintWorkspacePackages(siteRoot, workspaceRoot);
48
- if (fingerprint === undefined) return false;
49
-
50
- const previous = readStore(storePath);
51
-
52
- let cleared = false;
53
- if (existsSync(cacheDir) && previous !== fingerprint) {
54
- rmSync(cacheDir, { recursive: true, force: true });
55
- cleared = true;
56
- log?.("Workspace packages changed; clearing the Vite dep cache");
57
- }
58
- writeFileSync(storePath, JSON.stringify({ fingerprint }));
59
-
60
- return cleared;
61
- } catch (e) {
62
- if (process.env.TORPOR_DEBUG_CACHE) throw e;
63
- // Never break dev startup over cache bookkeeping
64
- return false;
65
- }
66
- }
67
-
68
- export function findWorkspaceRoot(from: string): string | undefined {
69
- let dir = path.resolve(from);
70
- while (true) {
71
- // pnpm-style marker, or a root package.json declaring npm workspaces
72
- if (existsSync(path.join(dir, "pnpm-workspace.yaml"))) {
73
- return dir;
74
- }
75
- if (hasWorkspacesField(dir)) {
76
- return dir;
77
- }
78
- const parent = path.dirname(dir);
79
- if (parent === dir) return undefined;
80
- dir = parent;
81
- }
82
- }
83
-
84
- function hasWorkspacesField(dir: string): boolean {
85
- const packageJsonPath = path.join(dir, "package.json");
86
- if (!existsSync(packageJsonPath)) return false;
87
- try {
88
- const pkg: PackageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
89
- return Array.isArray(pkg.workspaces) && pkg.workspaces.length > 0;
90
- } catch {
91
- return false;
92
- }
93
- }
94
-
95
- function readStore(storePath: string): string | undefined {
96
- if (!existsSync(storePath)) return undefined;
97
- try {
98
- const store = JSON.parse(readFileSync(storePath, "utf8")) as { fingerprint?: string };
99
- return store.fingerprint;
100
- } catch {
101
- return undefined;
102
- }
103
- }
104
-
105
- /**
106
- * Resolves every site dependency that lives inside the workspace to its
107
- * package folder. Shared with the other dev-startup checks (e.g. the stale
108
- * .torp copy report), which need the same set of packages.
109
- */
110
- export function workspaceDependencyDirs(siteRoot: string, workspaceRoot: string): string[] {
111
- const sitePackageJson = path.join(siteRoot, "package.json");
112
- if (!existsSync(sitePackageJson)) return [];
113
-
114
- const pkg: PackageJson = JSON.parse(readFileSync(sitePackageJson, "utf8"));
115
- const require = createRequire(sitePackageJson);
116
-
117
- const packageDirs = new Set<string>();
118
- for (const name of dependencyNames(pkg)) {
119
- const dir = resolvePackageDir(name, require);
120
- if (dir && insideWorkspace(realpathSync(dir), workspaceRoot)) {
121
- packageDirs.add(realpathSync(dir));
122
- }
123
- }
124
- return [...packageDirs].sort();
125
- }
126
-
127
- function fingerprintWorkspacePackages(siteRoot: string, workspaceRoot: string): string | undefined {
128
- const sitePackageJson = path.join(siteRoot, "package.json");
129
- if (!existsSync(sitePackageJson)) return undefined;
130
-
131
- const packageDirs = workspaceDependencyDirs(siteRoot, workspaceRoot);
132
- if (packageDirs.length === 0) return undefined;
133
-
134
- const hash = createHash("sha1");
135
- for (let dir of packageDirs) {
136
- hash.update(`package:${dir}\n`);
137
- fingerprintDir(dir, dir, hash);
138
- }
139
- return hash.digest("hex");
140
- }
141
-
142
- function dependencyNames(pkg: PackageJson): string[] {
143
- return [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})];
144
- }
145
-
146
- function resolvePackageDir(name: string, require: NodeRequire): string | undefined {
147
- try {
148
- const packageJsonPath = require.resolve(`${name}/package.json`);
149
- return path.dirname(packageJsonPath);
150
- } catch {
151
- return undefined;
152
- }
153
- }
154
-
155
- function insideWorkspace(dir: string, workspaceRoot: string): boolean {
156
- const relative = path.relative(workspaceRoot, dir);
157
- return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
158
- }
159
-
160
- function fingerprintDir(dir: string, root: string, hash: import("node:crypto").Hash): void {
161
- for (let entry of readdirSync(dir, { withFileTypes: true })) {
162
- if (entry.name === "node_modules" || entry.name === ".git") continue;
163
- const full = path.join(dir, entry.name);
164
- if (entry.isDirectory()) {
165
- fingerprintDir(full, root, hash);
166
- continue;
167
- }
168
- if (!entry.isFile()) continue;
169
- const stats = statSync(full);
170
- // NOTE: hash.update takes (data, encoding) -- join into one string
171
- hash.update(
172
- `file:${path.relative(root, full).replaceAll("\\", "/")}:${stats.size}:${Math.floor(stats.mtimeMs)}\n`,
173
- );
174
- }
175
- }