@torpor/build 0.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 (71) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +55 -0
  3. package/dist/bin/index.cjs +137 -0
  4. package/dist/bin/index.cjs.map +1 -0
  5. package/dist/bin/index.d.cts +1 -0
  6. package/dist/bin/index.d.ts +1 -0
  7. package/dist/bin/index.js +114 -0
  8. package/dist/bin/index.js.map +1 -0
  9. package/dist/index.cjs +55 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +150 -0
  12. package/dist/index.d.ts +150 -0
  13. package/dist/index.js +27 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/metafile-cjs.json +1 -0
  16. package/dist/metafile-esm.json +1 -0
  17. package/dist/response.cjs +150 -0
  18. package/dist/response.cjs.map +1 -0
  19. package/dist/response.d.cts +162 -0
  20. package/dist/response.d.ts +162 -0
  21. package/dist/response.js +109 -0
  22. package/dist/response.js.map +1 -0
  23. package/dist/state.cjs +41 -0
  24. package/dist/state.cjs.map +1 -0
  25. package/dist/state.d.cts +6 -0
  26. package/dist/state.d.ts +6 -0
  27. package/dist/state.js +14 -0
  28. package/dist/state.js.map +1 -0
  29. package/package.json +49 -0
  30. package/src/bin/index.ts +41 -0
  31. package/src/index.ts +24 -0
  32. package/src/response/badRequest.ts +14 -0
  33. package/src/response/created.ts +13 -0
  34. package/src/response/forbidden.ts +14 -0
  35. package/src/response/methodNotAllowed.ts +14 -0
  36. package/src/response/moved.ts +16 -0
  37. package/src/response/notFound.ts +17 -0
  38. package/src/response/notModified.ts +14 -0
  39. package/src/response/ok.ts +20 -0
  40. package/src/response/redirect.ts +17 -0
  41. package/src/response/response.ts +22 -0
  42. package/src/response/seeOther.ts +13 -0
  43. package/src/response/serverError.ts +10 -0
  44. package/src/response/transfer.ts +14 -0
  45. package/src/response/unauthorized.ts +12 -0
  46. package/src/response/unprocessable.ts +12 -0
  47. package/src/response.ts +33 -0
  48. package/src/site/FileSystemRouter.ts +24 -0
  49. package/src/site/buildRoutePath.ts +25 -0
  50. package/src/site/clientEntry.ts +191 -0
  51. package/src/site/defineConfig.ts +5 -0
  52. package/src/site/defineSite.ts +74 -0
  53. package/src/site/lazyRoute.ts +72 -0
  54. package/src/site/routeHandlers.ts +113 -0
  55. package/src/site/serverEntry.ts +384 -0
  56. package/src/state/$page.ts +11 -0
  57. package/src/state.ts +3 -0
  58. package/src/types/CookieHelper.ts +7 -0
  59. package/src/types/PageEndPoint.ts +37 -0
  60. package/src/types/PageEvent.ts +14 -0
  61. package/src/types/PageServerEndPoint.ts +18 -0
  62. package/src/types/RouteHandler.ts +12 -0
  63. package/src/types/RouteHandlerCollection.ts +7 -0
  64. package/src/types/RouteLayoutHandler.ts +5 -0
  65. package/src/types/RouteMatchResult.ts +7 -0
  66. package/src/types/ServerEndPoint.ts +37 -0
  67. package/src/types/ServerEvent.ts +27 -0
  68. package/src/types/ServerHook.ts +13 -0
  69. package/src/types/UserConfig.ts +3 -0
  70. package/tsconfig.json +4 -0
  71. package/tsup.config.ts +10 -0
@@ -0,0 +1,162 @@
1
+ /**
2
+ * 400 Bad Request
3
+ *
4
+ * The server cannot or will not process the request due to something that is
5
+ * perceived to be a client error (e.g., malformed request syntax, invalid
6
+ * request message framing, or deceptive request routing).
7
+ *
8
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
9
+ */
10
+ declare function badRequest(body?: object | string): Response;
11
+
12
+ /**
13
+ * 201 Created
14
+ *
15
+ * The request succeeded, and a new resource was created as a result. This is
16
+ * typically the response sent after POST requests, or some PUT requests.
17
+ *
18
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
19
+ */
20
+ declare function created(body?: object | string): Response;
21
+
22
+ /**
23
+ * 403 Forbidden
24
+ *
25
+ * The client does not have access rights to the content; that is, it is
26
+ * unauthorized, so the server is refusing to give the requested resource.
27
+ * Unlike 401 Unauthorized, the client's identity is known to the server.
28
+ *
29
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
30
+ */
31
+ declare function forbidden(body?: object | string): Response;
32
+
33
+ /**
34
+ * 405 Method Not Allowed
35
+ *
36
+ * The request method is known by the server but is not supported by the target
37
+ * resource. For example, an API may not allow calling DELETE to remove a
38
+ * resource.
39
+ *
40
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
41
+ */
42
+ declare function methodNotAllowed(body?: object | string): Response;
43
+
44
+ /**
45
+ * 308 Permanent Redirect
46
+ *
47
+ * This means that the resource is now permanently located at another URI,
48
+ * specified by the Location: HTTP Response header. This has the same semantics
49
+ * as the 301 Moved Permanently HTTP response code, with the exception that the
50
+ * user agent must not change the HTTP method used: if a POST was used in the
51
+ * first request, a POST must be used in the second request.
52
+ *
53
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
54
+ */
55
+ declare function moved(location: string): Response;
56
+
57
+ /**
58
+ * 404 Not Found
59
+ *
60
+ * The server cannot find the requested resource. In the browser, this means the
61
+ * URL is not recognized. In an API, this can also mean that the endpoint is
62
+ * valid but the resource itself does not exist. Servers may also send this
63
+ * response instead of 403 Forbidden to hide the existence of a resource from an
64
+ * unauthorized client. This response code is probably the most well known due
65
+ * to its frequent occurrence on the web.
66
+ *
67
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
68
+ */
69
+ declare function notFound(body?: object | string): Response;
70
+
71
+ /**
72
+ * 304 Not Modified
73
+ *
74
+ * This is used for caching purposes. It tells the client that the response has
75
+ * not been modified, so the client can continue to use the same cached version
76
+ * of the response.
77
+ *
78
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304
79
+ */
80
+ declare function notModified(location: string): Response;
81
+
82
+ /**
83
+ * 200 OK
84
+ *
85
+ * The request succeeded. The result meaning of "success" depends on the HTTP
86
+ * method:
87
+ * - GET: The resource has been fetched and transmitted in the message body.
88
+ * - HEAD: The representation headers are included in the response without any
89
+ * message body.
90
+ * - PUT or POST: The resource describing the result of the action is
91
+ * transmitted in the message body.
92
+ * - TRACE: The message body contains the request message as received by the
93
+ * server.
94
+ *
95
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200
96
+ */
97
+ declare function ok(body?: object | string): Response;
98
+
99
+ /**
100
+ * 307 Temporary Redirect
101
+ *
102
+ * The server sends this response to direct the client to get the requested
103
+ * resource at another URI with the same method that was used in the prior
104
+ * request. This has the same semantics as the 302 Found HTTP response code,
105
+ * with the exception that the user agent must not change the HTTP method used:
106
+ * if a POST was used in the first request, a POST must be used in the second
107
+ * request.
108
+ *
109
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307
110
+ */
111
+ declare function redirect(location: string): Response;
112
+
113
+ /**
114
+ * Creates a response with the supplied status code and optional body.
115
+ *
116
+ * If the body is an object, it will be converted to JSON and the content-type
117
+ * header set to "application/json". Otherwise, if the body is a string, the
118
+ * content-type header will be set to "text/plain".
119
+ */
120
+ declare function response(status: number, body?: object | string): Response;
121
+
122
+ /**
123
+ * 303 See Other
124
+ *
125
+ * The server sent this response to direct the client to get the requested
126
+ * resource at another URI with a GET request.
127
+ *
128
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
129
+ */
130
+ declare function seeOther(location: string): Response;
131
+
132
+ /**
133
+ * The server has encountered a situation it does not know how to handle.
134
+ *
135
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
136
+ */
137
+ declare function serverError(body?: object | string): Response;
138
+
139
+ /**
140
+ * Creates a redirect response with the supplied status code.
141
+ */
142
+ declare function transfer(status: 300 | 301 | 302 | 303 | 304 | 307 | 308, location: string): Response;
143
+
144
+ /**
145
+ * Although the HTTP standard specifies "unauthorized", semantically this
146
+ * response means "unauthenticated". That is, the client must authenticate
147
+ * itself to get the requested response.
148
+ *
149
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
150
+ */
151
+ declare function unauthorized(body?: object | string): Response;
152
+
153
+ /**
154
+ * 422 Unprocessable Content
155
+ *
156
+ * The request was well-formed but was unable to be followed due to semantic errors.
157
+ *
158
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422
159
+ */
160
+ declare function unprocessable(body?: object | string): Response;
161
+
162
+ export { badRequest, created, forbidden, methodNotAllowed, moved, notFound, notModified, ok, redirect, response, seeOther, serverError, transfer, unauthorized, unprocessable };
@@ -0,0 +1,109 @@
1
+ // src/response/response.ts
2
+ function response(status, body) {
3
+ let headers = void 0;
4
+ if (body) {
5
+ if (typeof body === "object") {
6
+ headers = { "content-type": "application/json" };
7
+ body = JSON.stringify(body);
8
+ } else {
9
+ headers = { "content-type": "text/plain" };
10
+ }
11
+ }
12
+ return new Response(body, {
13
+ status,
14
+ headers
15
+ });
16
+ }
17
+
18
+ // src/response/badRequest.ts
19
+ function badRequest(body) {
20
+ return response(400, body);
21
+ }
22
+
23
+ // src/response/created.ts
24
+ function created(body) {
25
+ return response(201, body);
26
+ }
27
+
28
+ // src/response/forbidden.ts
29
+ function forbidden(body) {
30
+ return response(403, body);
31
+ }
32
+
33
+ // src/response/methodNotAllowed.ts
34
+ function methodNotAllowed(body) {
35
+ return response(405, body);
36
+ }
37
+
38
+ // src/response/transfer.ts
39
+ function transfer(status, location) {
40
+ return new Response(null, {
41
+ status,
42
+ headers: {
43
+ location
44
+ }
45
+ });
46
+ }
47
+
48
+ // src/response/moved.ts
49
+ function moved(location) {
50
+ return transfer(308, location);
51
+ }
52
+
53
+ // src/response/notFound.ts
54
+ function notFound(body) {
55
+ return response(404, body);
56
+ }
57
+
58
+ // src/response/notModified.ts
59
+ function notModified(location) {
60
+ return transfer(304, location);
61
+ }
62
+
63
+ // src/response/ok.ts
64
+ function ok(body) {
65
+ return response(200, body);
66
+ }
67
+
68
+ // src/response/redirect.ts
69
+ function redirect(location) {
70
+ return transfer(307, location);
71
+ }
72
+
73
+ // src/response/seeOther.ts
74
+ function seeOther(location) {
75
+ return transfer(303, location);
76
+ }
77
+
78
+ // src/response/serverError.ts
79
+ function serverError(body) {
80
+ return response(500, body);
81
+ }
82
+
83
+ // src/response/unauthorized.ts
84
+ function unauthorized(body) {
85
+ return response(401, body);
86
+ }
87
+
88
+ // src/response/unprocessable.ts
89
+ function unprocessable(body) {
90
+ return response(422, body);
91
+ }
92
+ export {
93
+ badRequest,
94
+ created,
95
+ forbidden,
96
+ methodNotAllowed,
97
+ moved,
98
+ notFound,
99
+ notModified,
100
+ ok,
101
+ redirect,
102
+ response,
103
+ seeOther,
104
+ serverError,
105
+ transfer,
106
+ unauthorized,
107
+ unprocessable
108
+ };
109
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/response/response.ts","../src/response/badRequest.ts","../src/response/created.ts","../src/response/forbidden.ts","../src/response/methodNotAllowed.ts","../src/response/transfer.ts","../src/response/moved.ts","../src/response/notFound.ts","../src/response/notModified.ts","../src/response/ok.ts","../src/response/redirect.ts","../src/response/seeOther.ts","../src/response/serverError.ts","../src/response/unauthorized.ts","../src/response/unprocessable.ts"],"sourcesContent":["/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the content-type\n * header set to \"application/json\". Otherwise, if the body is a string, the\n * content-type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string) {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\theaders = { \"content-type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(body);\n\t\t} else {\n\t\t\theaders = { \"content-type\": \"text/plain\" };\n\t\t}\n\t}\n\treturn new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t});\n}\n","import response from \"./response\";\n\n/**\n * 400 Bad Request\n *\n * The server cannot or will not process the request due to something that is\n * perceived to be a client error (e.g., malformed request syntax, invalid\n * request message framing, or deceptive request routing).\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400\n */\nexport default function badRequest(body?: object | string): Response {\n\treturn response(400, body);\n}\n","import response from \"./response\";\n\n/**\n * 201 Created\n *\n * The request succeeded, and a new resource was created as a result. This is\n * typically the response sent after POST requests, or some PUT requests.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201\n */\nexport default function created(body?: object | string): Response {\n\treturn response(201, body);\n}\n","import response from \"./response\";\n\n/**\n * 403 Forbidden\n *\n * The client does not have access rights to the content; that is, it is\n * unauthorized, so the server is refusing to give the requested resource.\n * Unlike 401 Unauthorized, the client's identity is known to the server.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403\n */\nexport default function forbidden(body?: object | string): Response {\n\treturn response(403, body);\n}\n","import response from \"./response\";\n\n/**\n * 405 Method Not Allowed\n *\n * The request method is known by the server but is not supported by the target\n * resource. For example, an API may not allow calling DELETE to remove a\n * resource.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405\n */\nexport default function methodNotAllowed(body?: object | string): Response {\n\treturn response(405, body);\n}\n","/**\n * Creates a redirect response with the supplied status code.\n */\nexport default function transfer(\n\tstatus: 300 | 301 | 302 | 303 | 304 | 307 | 308,\n\tlocation: string,\n): Response {\n\treturn new Response(null, {\n\t\tstatus,\n\t\theaders: {\n\t\t\tlocation,\n\t\t},\n\t});\n}\n","import transfer from \"./transfer\";\n\n/**\n * 308 Permanent Redirect\n *\n * This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header. This has the same semantics\n * as the 301 Moved Permanently HTTP response code, with the exception that the\n * user agent must not change the HTTP method used: if a POST was used in the\n * first request, a POST must be used in the second request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308\n */\nexport default function moved(location: string): Response {\n\treturn transfer(308, location);\n}\n","import response from \"./response\";\n\n/**\n * 404 Not Found\n *\n * The server cannot find the requested resource. In the browser, this means the\n * URL is not recognized. In an API, this can also mean that the endpoint is\n * valid but the resource itself does not exist. Servers may also send this\n * response instead of 403 Forbidden to hide the existence of a resource from an\n * unauthorized client. This response code is probably the most well known due\n * to its frequent occurrence on the web.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404\n */\nexport default function notFound(body?: object | string): Response {\n\treturn response(404, body);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 304 Not Modified\n *\n * This is used for caching purposes. It tells the client that the response has\n * not been modified, so the client can continue to use the same cached version\n * of the response.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304\n */\nexport default function notModified(location: string): Response {\n\treturn transfer(304, location);\n}\n","import response from \"./response\";\n\n/**\n * 200 OK\n *\n * The request succeeded. The result meaning of \"success\" depends on the HTTP\n * method:\n * - GET: The resource has been fetched and transmitted in the message body.\n * - HEAD: The representation headers are included in the response without any\n * message body.\n * - PUT or POST: The resource describing the result of the action is\n * transmitted in the message body.\n * - TRACE: The message body contains the request message as received by the\n * server.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200\n */\nexport default function ok(body?: object | string): Response {\n\treturn response(200, body);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 307 Temporary Redirect\n *\n * The server sends this response to direct the client to get the requested\n * resource at another URI with the same method that was used in the prior\n * request. This has the same semantics as the 302 Found HTTP response code,\n * with the exception that the user agent must not change the HTTP method used:\n * if a POST was used in the first request, a POST must be used in the second\n * request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307\n */\nexport default function redirect(location: string): Response {\n\treturn transfer(307, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 303 See Other\n *\n * The server sent this response to direct the client to get the requested\n * resource at another URI with a GET request.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303\n */\nexport default function seeOther(location: string): Response {\n\treturn transfer(303, location);\n}\n","import response from \"./response\";\n\n/**\n * The server has encountered a situation it does not know how to handle.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body);\n}\n","import response from \"./response\";\n\n/**\n * Although the HTTP standard specifies \"unauthorized\", semantically this\n * response means \"unauthenticated\". That is, the client must authenticate\n * itself to get the requested response.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401\n */\nexport default function unauthorized(body?: object | string): Response {\n\treturn response(401, body);\n}\n","import response from \"./response\";\n\n/**\n * 422 Unprocessable Content\n *\n * The request was well-formed but was unable to be followed due to semantic errors.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422\n */\nexport default function unprocessable(body?: object | string): Response {\n\treturn response(422, body);\n}\n"],"mappings":";AAOe,SAAR,SAA0B,QAAgB,MAAwB;AACxE,MAAI,UAA8C;AAClD,MAAI,MAAM;AACT,QAAI,OAAO,SAAS,UAAU;AAC7B,gBAAU,EAAE,gBAAgB,mBAAmB;AAC/C,aAAO,KAAK,UAAU,IAAI;AAAA,IAC3B,OAAO;AACN,gBAAU,EAAE,gBAAgB,aAAa;AAAA,IAC1C;AAAA,EACD;AACA,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,EACD,CAAC;AACF;;;ACVe,SAAR,WAA4B,MAAkC;AACpE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACHe,SAAR,QAAyB,MAAkC;AACjE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACDe,SAAR,UAA2B,MAAkC;AACnE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACFe,SAAR,iBAAkC,MAAkC;AAC1E,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACVe,SAAR,SACN,QACA,UACW;AACX,SAAO,IAAI,SAAS,MAAM;AAAA,IACzB;AAAA,IACA,SAAS;AAAA,MACR;AAAA,IACD;AAAA,EACD,CAAC;AACF;;;ACAe,SAAR,MAAuB,UAA4B;AACzD,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACDe,SAAR,SAA0B,MAAkC;AAClE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACLe,SAAR,YAA6B,UAA4B;AAC/D,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACIe,SAAR,GAAoB,MAAkC;AAC5D,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACLe,SAAR,SAA0B,UAA4B;AAC5D,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACNe,SAAR,SAA0B,UAA4B;AAC5D,SAAO,SAAS,KAAK,QAAQ;AAC9B;;;ACLe,SAAR,YAA6B,MAAkC;AACrE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACAe,SAAR,aAA8B,MAAkC;AACtE,SAAO,SAAS,KAAK,IAAI;AAC1B;;;ACFe,SAAR,cAA+B,MAAkC;AACvE,SAAO,SAAS,KAAK,IAAI;AAC1B;","names":[]}
package/dist/state.cjs ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/state.ts
21
+ var state_exports = {};
22
+ __export(state_exports, {
23
+ $page: () => page_default
24
+ });
25
+ module.exports = __toCommonJS(state_exports);
26
+
27
+ // src/state/$page.ts
28
+ var import_view = require("@torpor/view");
29
+ var $page = (0, import_view.$watch)(
30
+ {
31
+ status: 404,
32
+ url: new URL("http://localhost")
33
+ },
34
+ { shallow: true }
35
+ );
36
+ var page_default = $page;
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ $page
40
+ });
41
+ //# sourceMappingURL=state.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state.ts","../src/state/$page.ts"],"sourcesContent":["import $page from \"./state/$page\";\n\nexport { $page };\n","import { $watch } from \"@torpor/view\";\n\nconst $page = $watch(\n\t{\n\t\tstatus: 404,\n\t\turl: new URL(\"http://localhost\"),\n\t},\n\t{ shallow: true },\n);\n\nexport default $page;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAuB;AAEvB,IAAM,YAAQ;AAAA,EACb;AAAA,IACC,QAAQ;AAAA,IACR,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAChC;AAAA,EACA,EAAE,SAAS,KAAK;AACjB;AAEA,IAAO,eAAQ;","names":[]}
@@ -0,0 +1,6 @@
1
+ declare const $page: {
2
+ status: number;
3
+ url: URL;
4
+ };
5
+
6
+ export { $page };
@@ -0,0 +1,6 @@
1
+ declare const $page: {
2
+ status: number;
3
+ url: URL;
4
+ };
5
+
6
+ export { $page };
package/dist/state.js ADDED
@@ -0,0 +1,14 @@
1
+ // src/state/$page.ts
2
+ import { $watch } from "@torpor/view";
3
+ var $page = $watch(
4
+ {
5
+ status: 404,
6
+ url: new URL("http://localhost")
7
+ },
8
+ { shallow: true }
9
+ );
10
+ var page_default = $page;
11
+ export {
12
+ page_default as $page
13
+ };
14
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\n\nconst $page = $watch(\n\t{\n\t\tstatus: 404,\n\t\turl: new URL(\"http://localhost\"),\n\t},\n\t{ shallow: true },\n);\n\nexport default $page;\n"],"mappings":";AAAA,SAAS,cAAc;AAEvB,IAAM,QAAQ;AAAA,EACb;AAAA,IACC,QAAQ;AAAA,IACR,KAAK,IAAI,IAAI,kBAAkB;AAAA,EAChC;AAAA,EACA,EAAE,SAAS,KAAK;AACjB;AAEA,IAAO,eAAQ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@torpor/build",
3
+ "version": "0.0.1",
4
+ "description": "A framework for building sites and apps with Torpor",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./response": {
16
+ "types": "./dist/response.d.ts",
17
+ "import": "./dist/response.js",
18
+ "require": "./dist/response.cjs"
19
+ },
20
+ "./state": {
21
+ "types": "./dist/state.d.ts",
22
+ "import": "./dist/state.js",
23
+ "require": "./dist/state.cjs"
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "bin": {
30
+ "tb": "./dist/bin/index.js"
31
+ },
32
+ "keywords": [],
33
+ "author": "",
34
+ "license": "ISC",
35
+ "dependencies": {
36
+ "vinxi": "^0.5.1",
37
+ "@torpor/unplugin": "^0.0.1",
38
+ "@torpor/view": "^0.0.1"
39
+ },
40
+ "devDependencies": {
41
+ "@trivago/prettier-plugin-sort-imports": "^5.2.0",
42
+ "lilconfig": "^3.1.3",
43
+ "tsup": "^8.3.5"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "build:watch": "tsup --watch"
48
+ }
49
+ }
@@ -0,0 +1,41 @@
1
+ #! /usr/bin/env node
2
+ //import { existsSync, promises as fs } from "node:fs";
3
+ import fs from "node:fs";
4
+ import path from "path";
5
+ import defineSite from "../site/defineSite";
6
+ import type UserConfig from "../types/UserConfig";
7
+
8
+ // Check for a torpor.config.js/ts file in the working directory
9
+ // TODO: Make sure it's valid, try/catch, etc
10
+ // TODO: There has GOT to be an easier way
11
+ let options: UserConfig | undefined;
12
+ const workingDir = process.cwd();
13
+ const jsConfigFile = path.join(workingDir, "torpor.config.js");
14
+ const tsConfigFile = path.join(workingDir, "torpor.config.ts");
15
+ let source: string | undefined;
16
+ if (fs.existsSync(jsConfigFile)) {
17
+ //const configFile = path.relative(".", tsConfigFile);
18
+ //options = await import(configFile);
19
+ source = fs.readFileSync(jsConfigFile, "utf8");
20
+ source = source
21
+ .replace(
22
+ /import\s+\{\s+defineConfig\s+\}\s+from\s+["']@torpor\/build["']/,
23
+ "const defineConfig = (x) => x",
24
+ )
25
+ .replace("export default", "");
26
+ } else if (fs.existsSync(tsConfigFile)) {
27
+ console.log("TS config file is not supported");
28
+ }
29
+
30
+ if (source) {
31
+ options = eval(source);
32
+ }
33
+
34
+ const app = defineSite(options);
35
+
36
+ // This already gets done in vinxi.createApp so we can't do it twice
37
+ //if (process.argv.includes("--dev")) {
38
+ // await app.dev();
39
+ //} else if (process.argv.includes("--build")) {
40
+ // await app.build();
41
+ //}
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
1
+ import buildRoutePath from "./site/buildRoutePath";
2
+ import defineConfig from "./site/defineConfig";
3
+ import type PageEndPoint from "./types/PageEndPoint";
4
+ import type PageEvent from "./types/PageEvent";
5
+ import type PageServerEndPoint from "./types/PageServerEndPoint";
6
+ import type ServerEndPoint from "./types/ServerEndPoint";
7
+ import type ServerEvent from "./types/ServerEvent";
8
+ import type ServerHook from "./types/ServerHook";
9
+ import type UserConfig from "./types/UserConfig";
10
+
11
+ // NOTE: Do not export anything that relies on vinxi/vite from here, or it will
12
+ // cause problems when they are re-imported when routes are lazily loaded
13
+
14
+ export { defineConfig, buildRoutePath };
15
+
16
+ export type {
17
+ UserConfig,
18
+ PageEndPoint,
19
+ PageServerEndPoint,
20
+ ServerEndPoint,
21
+ ServerHook,
22
+ PageEvent,
23
+ ServerEvent,
24
+ };
@@ -0,0 +1,14 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 400 Bad Request
5
+ *
6
+ * The server cannot or will not process the request due to something that is
7
+ * perceived to be a client error (e.g., malformed request syntax, invalid
8
+ * request message framing, or deceptive request routing).
9
+ *
10
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
11
+ */
12
+ export default function badRequest(body?: object | string): Response {
13
+ return response(400, body);
14
+ }
@@ -0,0 +1,13 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 201 Created
5
+ *
6
+ * The request succeeded, and a new resource was created as a result. This is
7
+ * typically the response sent after POST requests, or some PUT requests.
8
+ *
9
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
10
+ */
11
+ export default function created(body?: object | string): Response {
12
+ return response(201, body);
13
+ }
@@ -0,0 +1,14 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 403 Forbidden
5
+ *
6
+ * The client does not have access rights to the content; that is, it is
7
+ * unauthorized, so the server is refusing to give the requested resource.
8
+ * Unlike 401 Unauthorized, the client's identity is known to the server.
9
+ *
10
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
11
+ */
12
+ export default function forbidden(body?: object | string): Response {
13
+ return response(403, body);
14
+ }
@@ -0,0 +1,14 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 405 Method Not Allowed
5
+ *
6
+ * The request method is known by the server but is not supported by the target
7
+ * resource. For example, an API may not allow calling DELETE to remove a
8
+ * resource.
9
+ *
10
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
11
+ */
12
+ export default function methodNotAllowed(body?: object | string): Response {
13
+ return response(405, body);
14
+ }
@@ -0,0 +1,16 @@
1
+ import transfer from "./transfer";
2
+
3
+ /**
4
+ * 308 Permanent Redirect
5
+ *
6
+ * This means that the resource is now permanently located at another URI,
7
+ * specified by the Location: HTTP Response header. This has the same semantics
8
+ * as the 301 Moved Permanently HTTP response code, with the exception that the
9
+ * user agent must not change the HTTP method used: if a POST was used in the
10
+ * first request, a POST must be used in the second request.
11
+ *
12
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
13
+ */
14
+ export default function moved(location: string): Response {
15
+ return transfer(308, location);
16
+ }
@@ -0,0 +1,17 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 404 Not Found
5
+ *
6
+ * The server cannot find the requested resource. In the browser, this means the
7
+ * URL is not recognized. In an API, this can also mean that the endpoint is
8
+ * valid but the resource itself does not exist. Servers may also send this
9
+ * response instead of 403 Forbidden to hide the existence of a resource from an
10
+ * unauthorized client. This response code is probably the most well known due
11
+ * to its frequent occurrence on the web.
12
+ *
13
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404
14
+ */
15
+ export default function notFound(body?: object | string): Response {
16
+ return response(404, body);
17
+ }
@@ -0,0 +1,14 @@
1
+ import transfer from "./transfer";
2
+
3
+ /**
4
+ * 304 Not Modified
5
+ *
6
+ * This is used for caching purposes. It tells the client that the response has
7
+ * not been modified, so the client can continue to use the same cached version
8
+ * of the response.
9
+ *
10
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304
11
+ */
12
+ export default function notModified(location: string): Response {
13
+ return transfer(304, location);
14
+ }
@@ -0,0 +1,20 @@
1
+ import response from "./response";
2
+
3
+ /**
4
+ * 200 OK
5
+ *
6
+ * The request succeeded. The result meaning of "success" depends on the HTTP
7
+ * method:
8
+ * - GET: The resource has been fetched and transmitted in the message body.
9
+ * - HEAD: The representation headers are included in the response without any
10
+ * message body.
11
+ * - PUT or POST: The resource describing the result of the action is
12
+ * transmitted in the message body.
13
+ * - TRACE: The message body contains the request message as received by the
14
+ * server.
15
+ *
16
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200
17
+ */
18
+ export default function ok(body?: object | string): Response {
19
+ return response(200, body);
20
+ }
@@ -0,0 +1,17 @@
1
+ import transfer from "./transfer";
2
+
3
+ /**
4
+ * 307 Temporary Redirect
5
+ *
6
+ * The server sends this response to direct the client to get the requested
7
+ * resource at another URI with the same method that was used in the prior
8
+ * request. This has the same semantics as the 302 Found HTTP response code,
9
+ * with the exception that the user agent must not change the HTTP method used:
10
+ * if a POST was used in the first request, a POST must be used in the second
11
+ * request.
12
+ *
13
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307
14
+ */
15
+ export default function redirect(location: string): Response {
16
+ return transfer(307, location);
17
+ }
@@ -0,0 +1,22 @@
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) {
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
+ }