lynnix 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 (70) hide show
  1. package/README.md +542 -0
  2. package/dist/index.d.ts +17 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +13 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lynnix.d.ts +46 -0
  7. package/dist/lynnix.d.ts.map +1 -0
  8. package/dist/lynnix.js +199 -0
  9. package/dist/lynnix.js.map +1 -0
  10. package/dist/utils/augmentRequest.d.ts +12 -0
  11. package/dist/utils/augmentRequest.d.ts.map +1 -0
  12. package/dist/utils/augmentRequest.js +66 -0
  13. package/dist/utils/augmentRequest.js.map +1 -0
  14. package/dist/utils/augmentResponse.d.ts +17 -0
  15. package/dist/utils/augmentResponse.d.ts.map +1 -0
  16. package/dist/utils/augmentResponse.js +56 -0
  17. package/dist/utils/augmentResponse.js.map +1 -0
  18. package/dist/utils/buildRoutesMap.d.ts +19 -0
  19. package/dist/utils/buildRoutesMap.d.ts.map +1 -0
  20. package/dist/utils/buildRoutesMap.js +48 -0
  21. package/dist/utils/buildRoutesMap.js.map +1 -0
  22. package/dist/utils/error.d.ts +18 -0
  23. package/dist/utils/error.d.ts.map +1 -0
  24. package/dist/utils/error.js +20 -0
  25. package/dist/utils/error.js.map +1 -0
  26. package/dist/utils/findClosestBoundary.d.ts +14 -0
  27. package/dist/utils/findClosestBoundary.d.ts.map +1 -0
  28. package/dist/utils/findClosestBoundary.js +29 -0
  29. package/dist/utils/findClosestBoundary.js.map +1 -0
  30. package/dist/utils/getMiddlewareChain.d.ts +19 -0
  31. package/dist/utils/getMiddlewareChain.d.ts.map +1 -0
  32. package/dist/utils/getMiddlewareChain.js +31 -0
  33. package/dist/utils/getMiddlewareChain.js.map +1 -0
  34. package/dist/utils/handleHttpError.d.ts +24 -0
  35. package/dist/utils/handleHttpError.d.ts.map +1 -0
  36. package/dist/utils/handleHttpError.js +23 -0
  37. package/dist/utils/handleHttpError.js.map +1 -0
  38. package/dist/utils/handleNotFound.d.ts +33 -0
  39. package/dist/utils/handleNotFound.d.ts.map +1 -0
  40. package/dist/utils/handleNotFound.js +71 -0
  41. package/dist/utils/handleNotFound.js.map +1 -0
  42. package/dist/utils/lruCache.d.ts +17 -0
  43. package/dist/utils/lruCache.d.ts.map +1 -0
  44. package/dist/utils/lruCache.js +36 -0
  45. package/dist/utils/lruCache.js.map +1 -0
  46. package/dist/utils/lynnixRequest.d.ts +22 -0
  47. package/dist/utils/lynnixRequest.d.ts.map +1 -0
  48. package/dist/utils/lynnixRequest.js +21 -0
  49. package/dist/utils/lynnixRequest.js.map +1 -0
  50. package/dist/utils/lynnixResponse.d.ts +53 -0
  51. package/dist/utils/lynnixResponse.d.ts.map +1 -0
  52. package/dist/utils/lynnixResponse.js +142 -0
  53. package/dist/utils/lynnixResponse.js.map +1 -0
  54. package/dist/utils/matchRoute.d.ts +20 -0
  55. package/dist/utils/matchRoute.d.ts.map +1 -0
  56. package/dist/utils/matchRoute.js +55 -0
  57. package/dist/utils/matchRoute.js.map +1 -0
  58. package/dist/utils/parseReqBody.d.ts +28 -0
  59. package/dist/utils/parseReqBody.d.ts.map +1 -0
  60. package/dist/utils/parseReqBody.js +415 -0
  61. package/dist/utils/parseReqBody.js.map +1 -0
  62. package/dist/utils/runMiddlewares.d.ts +5 -0
  63. package/dist/utils/runMiddlewares.d.ts.map +1 -0
  64. package/dist/utils/runMiddlewares.js +18 -0
  65. package/dist/utils/runMiddlewares.js.map +1 -0
  66. package/dist/utils/sortRoutes.d.ts +16 -0
  67. package/dist/utils/sortRoutes.d.ts.map +1 -0
  68. package/dist/utils/sortRoutes.js +44 -0
  69. package/dist/utils/sortRoutes.js.map +1 -0
  70. package/package.json +68 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ import findClosestBoundary from "./findClosestBoundary.js";
10
+ export function handleHttpError({ res, mutor, pathname, isHtmxReq, routes, routesMap, data, code, error, }) {
11
+ const boundary = isHtmxReq ? "fragmentError" : "error";
12
+ const nearestError = findClosestBoundary(pathname, boundary, routes, routesMap);
13
+ if (!nearestError?.paths?.[boundary]) {
14
+ return res.status(code).html("");
15
+ }
16
+ const html = mutor.renderFile(nearestError.paths[boundary], {
17
+ error,
18
+ data: data || {},
19
+ pathname,
20
+ });
21
+ return res.status(code).html(html);
22
+ }
23
+ //# sourceMappingURL=handleHttpError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleHttpError.js","sourceRoot":"","sources":["../../src/utils/handleHttpError.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAG3D,MAAM,UAAU,eAAe,CAAC,EAC/B,GAAG,EACH,KAAK,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,KAAK,GAWL;IACA,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;IACvD,MAAM,YAAY,GAAG,mBAAmB,CACvC,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,CACT,CAAC;IAEF,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;QAC3D,KAAK;QACL,IAAI,EAAE,IAAI,IAAI,EAAE;QAChB,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ import type Mutor from "mutorjs/server";
10
+ import type { RoutesMap } from "../types.js";
11
+ import { NotFoundError } from "./error.js";
12
+ import type LynnixRequest from "./lynnixRequest.js";
13
+ import type LynnixResponse from "./lynnixResponse.js";
14
+ /**
15
+ * Handles the not found error by finding the closest boundary and
16
+ * optionally running middlewares before rendering the not found page.
17
+ *
18
+ * @param param0 An object containing the request, response, and other context.
19
+ * @param shouldRunMiddlewares Specifies whether to run middlewares before rendering the not found page.
20
+ * @returns
21
+ */
22
+ export declare function handleNotFound({ req, res, mutor, isHtmxReq, routesMap, routes, pathname, data, error, }: {
23
+ res: LynnixResponse;
24
+ req: LynnixRequest;
25
+ mutor: Mutor;
26
+ isHtmxReq: boolean;
27
+ routes: string[];
28
+ routesMap: RoutesMap;
29
+ pathname: string;
30
+ data?: unknown;
31
+ error: NotFoundError;
32
+ }, shouldRunMiddlewares?: boolean): Promise<void>;
33
+ //# sourceMappingURL=handleNotFound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleNotFound.d.ts","sourceRoot":"","sources":["../../src/utils/handleNotFound.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAa,aAAa,EAAE,MAAM,YAAY,CAAC;AAGtD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAGtD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CACnC,EACC,GAAG,EACH,GAAG,EACH,KAAK,EACL,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,KAAK,GACL,EAAE;IACF,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,aAAa,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,aAAa,CAAC;CACrB,EACD,oBAAoB,CAAC,EAAE,OAAO,iBAmE9B"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ import { HttpError, NotFoundError } from "./error.js";
10
+ import findClosestBoundary from "./findClosestBoundary.js";
11
+ import { handleHttpError } from "./handleHttpError.js";
12
+ import runMiddlewares from "./runMiddlewares.js";
13
+ /**
14
+ * Handles the not found error by finding the closest boundary and
15
+ * optionally running middlewares before rendering the not found page.
16
+ *
17
+ * @param param0 An object containing the request, response, and other context.
18
+ * @param shouldRunMiddlewares Specifies whether to run middlewares before rendering the not found page.
19
+ * @returns
20
+ */
21
+ export async function handleNotFound({ req, res, mutor, isHtmxReq, routesMap, routes, pathname, data, error, }, shouldRunMiddlewares) {
22
+ const boundary = isHtmxReq ? "fragmentNotFound" : "notFound";
23
+ const nearestNotFound = findClosestBoundary(pathname, boundary, routes, routesMap);
24
+ // Run middlewares optionally
25
+ if (shouldRunMiddlewares) {
26
+ try {
27
+ await runMiddlewares(req, res, nearestNotFound?.accessedRoute || "/", routesMap);
28
+ }
29
+ catch (err) {
30
+ if (err instanceof NotFoundError) {
31
+ await handleNotFound({
32
+ req,
33
+ res,
34
+ mutor,
35
+ isHtmxReq,
36
+ routesMap,
37
+ routes,
38
+ pathname,
39
+ data,
40
+ error: err,
41
+ });
42
+ return;
43
+ }
44
+ handleHttpError({
45
+ res,
46
+ mutor,
47
+ isHtmxReq,
48
+ routesMap,
49
+ routes,
50
+ pathname,
51
+ data,
52
+ code: 500,
53
+ error: err instanceof HttpError ? err : new HttpError(500, err),
54
+ });
55
+ return;
56
+ }
57
+ }
58
+ if (res.raw.writableEnded) {
59
+ return;
60
+ }
61
+ if (!nearestNotFound?.paths?.[boundary]) {
62
+ return res.status(404).html("");
63
+ }
64
+ const html = mutor.renderFile(nearestNotFound.paths[boundary], {
65
+ error,
66
+ data: data || {},
67
+ pathname,
68
+ });
69
+ res.status(404).html(html);
70
+ }
71
+ //# sourceMappingURL=handleNotFound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleNotFound.js","sourceRoot":"","sources":["../../src/utils/handleNotFound.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,EACC,GAAG,EACH,GAAG,EACH,KAAK,EACL,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,KAAK,GAWL,EACD,oBAA8B;IAE9B,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,UAAU,CAAC;IAC7D,MAAM,eAAe,GAAG,mBAAmB,CAC1C,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,CACT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,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ export default class LRUCache<K, V> {
10
+ private size;
11
+ private cache;
12
+ constructor(size?: number);
13
+ set(key: K, value: V): void;
14
+ get(key: K): V;
15
+ has(key: K): boolean;
16
+ }
17
+ //# sourceMappingURL=lruCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lruCache.d.ts","sourceRoot":"","sources":["../../src/utils/lruCache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,OAAO,OAAO,QAAQ,CAAC,CAAC,EAAE,CAAC;IAGrB,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,KAAK,CAAwB;gBAEjB,IAAI,SAAQ;IAEhC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;IAYpB,GAAG,CAAC,GAAG,EAAE,CAAC;IAaV,GAAG,CAAC,GAAG,EAAE,CAAC;CAGV"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ export default class LRUCache {
10
+ constructor(size = 5000) {
11
+ this.size = size;
12
+ this.cache = new Map();
13
+ }
14
+ set(key, value) {
15
+ if (this.cache.has(key)) {
16
+ this.cache.delete(key);
17
+ }
18
+ if (this.cache.size >= this.size) {
19
+ this.cache.delete(this.cache.keys().next().value);
20
+ }
21
+ this.cache.set(key, value);
22
+ }
23
+ get(key) {
24
+ if (!this.cache.has(key)) {
25
+ return null;
26
+ }
27
+ const value = this.cache.get(key);
28
+ this.cache.delete(key);
29
+ this.cache.set(key, value);
30
+ return value;
31
+ }
32
+ has(key) {
33
+ return this.cache.has(key);
34
+ }
35
+ }
36
+ //# sourceMappingURL=lruCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lruCache.js","sourceRoot":"","sources":["../../src/utils/lruCache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAG5B,YAAoB,OAAO,IAAK;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFxB,UAAK,GAAc,IAAI,GAAG,EAAE,CAAC;IAEF,CAAC;IAEpC,GAAG,CAAC,GAAM,EAAE,KAAQ;QACnB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAU,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,GAAG,CAAC,GAAM;QACT,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAU,CAAC,CAAC;QAEhC,OAAO,KAAU,CAAC;IACnB,CAAC;IAED,GAAG,CAAC,GAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACD"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ import type * as http from "node:http";
10
+ import type { Cookies, HtmxHeaders, LynnixServerRequest, LynnixUploadedFiles } from "../types.js";
11
+ export default class LynnixRequest implements LynnixServerRequest {
12
+ readonly raw: http.IncomingMessage;
13
+ body: Record<string, unknown>;
14
+ files: LynnixUploadedFiles;
15
+ cookies: Cookies;
16
+ query: LynnixServerRequest["query"];
17
+ params: Record<string, string | undefined>;
18
+ htmx: HtmxHeaders;
19
+ isHtmx: boolean;
20
+ constructor(raw: http.IncomingMessage);
21
+ }
22
+ //# sourceMappingURL=lynnixRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynnixRequest.d.ts","sourceRoot":"","sources":["../../src/utils/lynnixRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EACX,OAAO,EACP,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,mBAAmB;aASpC,GAAG,EAAE,IAAI,CAAC,eAAe;IARrD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACnC,KAAK,EAAE,mBAAmB,CAAM;IAChC,OAAO,EAAE,OAAO,CAAM;IACtB,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAM;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAM;IAChD,IAAI,EAAE,WAAW,CAAqB;IACtC,MAAM,UAAS;gBAEa,GAAG,EAAE,IAAI,CAAC,eAAe;CACrD"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ export default class LynnixRequest {
10
+ constructor(raw) {
11
+ this.raw = raw;
12
+ this.body = {};
13
+ this.files = {};
14
+ this.cookies = {};
15
+ this.query = {};
16
+ this.params = {};
17
+ this.htmx = {};
18
+ this.isHtmx = false;
19
+ }
20
+ }
21
+ //# sourceMappingURL=lynnixRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynnixRequest.js","sourceRoot":"","sources":["../../src/utils/lynnixRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,MAAM,CAAC,OAAO,OAAO,aAAa;IASjC,YAA4B,GAAyB;QAAzB,QAAG,GAAH,GAAG,CAAsB;QARrD,SAAI,GAA4B,EAAE,CAAC;QACnC,UAAK,GAAwB,EAAE,CAAC;QAChC,YAAO,GAAY,EAAE,CAAC;QACtB,UAAK,GAAiC,EAAE,CAAC;QACzC,WAAM,GAAuC,EAAE,CAAC;QAChD,SAAI,GAAgB,EAAiB,CAAC;QACtC,WAAM,GAAG,KAAK,CAAC;IAEyC,CAAC;CACzD"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ import type * as http from "node:http";
10
+ import type { CookieOptions, Cookies, LynnixServerResponse } from "../types.js";
11
+ type CookieModule = {
12
+ serialize(name: string, value: string, options?: CookieOptions): string;
13
+ parseSetCookie(cookieHeader: string): {
14
+ name: string;
15
+ value: string;
16
+ };
17
+ };
18
+ export default class LynnixResponse implements LynnixServerResponse {
19
+ readonly raw: http.ServerResponse<http.IncomingMessage>;
20
+ private readonly isHtmx;
21
+ private readonly cookieModule;
22
+ cookies: Cookies;
23
+ constructor(raw: http.ServerResponse<http.IncomingMessage>, isHtmx: boolean, cookieModule: CookieModule | null, cookies?: Cookies);
24
+ setCookie(name: string, value: string, options: CookieOptions): void;
25
+ deleteCookie(name: string): void;
26
+ redirect(url: string, permanent?: boolean): void;
27
+ html(content: string): void;
28
+ json(content: unknown): void;
29
+ status(code: number): this;
30
+ htmxTrigger(event: string | Record<string, unknown>): void;
31
+ htmxTriggerAfterSwap(event: string | Record<string, unknown>): void;
32
+ htmxTriggerAfterSettle(event: string | Record<string, unknown>): void;
33
+ htmxPush(url: string | false): void;
34
+ htmxReswap(strategy: "innerHTML" | "outerHTML" | "beforebegin" | "afterbegin" | "beforeend" | "afterend" | "delete" | "none"): void;
35
+ htmxReplaceUrl(url: string | false): void;
36
+ htmxRetarget(selector: string): void;
37
+ htmxReselect(selector: string): void;
38
+ htmxRefresh(): void;
39
+ htmxRedirect(url: string): void;
40
+ htmxLocation(location: string | {
41
+ path: string;
42
+ target?: string;
43
+ swap?: string;
44
+ select?: string;
45
+ values?: Record<string, unknown>;
46
+ headers?: Record<string, string>;
47
+ }): void;
48
+ private normalizeSetCookieHeader;
49
+ private getSetCookieName;
50
+ end(value?: unknown): void;
51
+ }
52
+ export type { CookieModule };
53
+ //# sourceMappingURL=lynnixResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynnixResponse.d.ts","sourceRoot":"","sources":["../../src/utils/lynnixResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,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KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IASrE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAMnC,UAAU,CACT,QAAQ,EACL,WAAW,GACX,WAAW,GACX,aAAa,GACb,YAAY,GACZ,WAAW,GACX,UAAU,GACV,QAAQ,GACR,MAAM,GACP,IAAI;IAMP,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAMzC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMpC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMpC,WAAW,IAAI,IAAI;IAMnB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAM/B,YAAY,CACX,QAAQ,EACL,MAAM,GACN;QACA,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,GACF,IAAI;IASP,OAAO,CAAC,wBAAwB;IAgBhC,OAAO,CAAC,gBAAgB;IAYxB,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO;CAGnB;AAED,YAAY,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ export default class LynnixResponse {
10
+ constructor(raw, isHtmx, cookieModule, cookies = {}) {
11
+ this.raw = raw;
12
+ this.isHtmx = isHtmx;
13
+ this.cookieModule = cookieModule;
14
+ this.cookies = cookies;
15
+ }
16
+ setCookie(name, value, options) {
17
+ if (!this.cookieModule) {
18
+ console.error('[Lynnix] Setting cookies requires the optional peer dependency "cookie"');
19
+ return;
20
+ }
21
+ const serializedCookie = this.cookieModule.serialize(name, value, options);
22
+ const existingCookies = this.normalizeSetCookieHeader(this.raw.getHeader("Set-Cookie")).filter((cookie) => this.getSetCookieName(cookie) !== name);
23
+ existingCookies.push(serializedCookie);
24
+ this.raw.setHeader("Set-Cookie", existingCookies);
25
+ this.cookies[name] = value;
26
+ }
27
+ deleteCookie(name) {
28
+ if (!this.cookieModule) {
29
+ console.error('[Lynnix] Deleting cookies requires the optional peer dependency "cookie"');
30
+ return;
31
+ }
32
+ const existingCookies = this.normalizeSetCookieHeader(this.raw.getHeader("Set-Cookie")).filter((cookie) => this.getSetCookieName(cookie) !== name);
33
+ const expiredCookie = this.cookieModule.serialize(name, "", {
34
+ maxAge: 0,
35
+ path: "/",
36
+ });
37
+ existingCookies.push(expiredCookie);
38
+ this.raw.setHeader("Set-Cookie", existingCookies);
39
+ delete this.cookies[name];
40
+ }
41
+ redirect(url, permanent) {
42
+ this.raw.statusCode = permanent ? 301 : 302;
43
+ if (this.isHtmx) {
44
+ this.raw.setHeader("HX-Redirect", url);
45
+ }
46
+ else {
47
+ this.raw.setHeader("Location", url);
48
+ }
49
+ this.raw.end();
50
+ }
51
+ html(content) {
52
+ this.raw.setHeader("Content-Type", "text/html; charset=utf-8");
53
+ this.raw.end(content);
54
+ }
55
+ json(content) {
56
+ this.raw.setHeader("Content-Type", "application/json; charset=utf-8");
57
+ this.raw.end(JSON.stringify(content));
58
+ }
59
+ status(code) {
60
+ this.raw.statusCode = code;
61
+ return this;
62
+ }
63
+ htmxTrigger(event) {
64
+ if (this.isHtmx) {
65
+ this.raw.setHeader("HX-Trigger", typeof event === "string" ? event : JSON.stringify(event));
66
+ }
67
+ }
68
+ htmxTriggerAfterSwap(event) {
69
+ if (this.isHtmx) {
70
+ this.raw.setHeader("HX-Trigger-After-Swap", typeof event === "string" ? event : JSON.stringify(event));
71
+ }
72
+ }
73
+ htmxTriggerAfterSettle(event) {
74
+ if (this.isHtmx) {
75
+ this.raw.setHeader("HX-Trigger-After-Settle", typeof event === "string" ? event : JSON.stringify(event));
76
+ }
77
+ }
78
+ htmxPush(url) {
79
+ if (this.isHtmx) {
80
+ this.raw.setHeader("HX-Push-Url", url === false ? "false" : url);
81
+ }
82
+ }
83
+ htmxReswap(strategy) {
84
+ if (this.isHtmx) {
85
+ this.raw.setHeader("HX-Reswap", strategy);
86
+ }
87
+ }
88
+ htmxReplaceUrl(url) {
89
+ if (this.isHtmx) {
90
+ this.raw.setHeader("HX-Replace-Url", url === false ? "false" : url);
91
+ }
92
+ }
93
+ htmxRetarget(selector) {
94
+ if (this.isHtmx) {
95
+ this.raw.setHeader("HX-Retarget", selector);
96
+ }
97
+ }
98
+ htmxReselect(selector) {
99
+ if (this.isHtmx) {
100
+ this.raw.setHeader("HX-Reselect", selector);
101
+ }
102
+ }
103
+ htmxRefresh() {
104
+ if (this.isHtmx) {
105
+ this.raw.setHeader("HX-Refresh", "true");
106
+ }
107
+ }
108
+ htmxRedirect(url) {
109
+ if (this.isHtmx) {
110
+ this.raw.setHeader("HX-Redirect", url);
111
+ }
112
+ }
113
+ htmxLocation(location) {
114
+ if (this.isHtmx) {
115
+ this.raw.setHeader("HX-Location", typeof location === "string" ? location : JSON.stringify(location));
116
+ }
117
+ }
118
+ normalizeSetCookieHeader(header) {
119
+ if (Array.isArray(header)) {
120
+ return header.filter((value) => typeof value === "string");
121
+ }
122
+ if (typeof header === "string") {
123
+ return [header];
124
+ }
125
+ return [];
126
+ }
127
+ getSetCookieName(cookieHeader) {
128
+ if (!this.cookieModule) {
129
+ return "";
130
+ }
131
+ try {
132
+ return this.cookieModule.parseSetCookie(cookieHeader).name;
133
+ }
134
+ catch {
135
+ return "";
136
+ }
137
+ }
138
+ end(value) {
139
+ this.raw.end(value);
140
+ }
141
+ }
142
+ //# sourceMappingURL=lynnixResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lynnixResponse.js","sourceRoot":"","sources":["../../src/utils/lynnixResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,MAAM,CAAC,OAAO,OAAO,cAAc;IAGlC,YACiB,GAA8C,EAC7C,MAAe,EACf,YAAiC,EAClD,UAAmB,EAAE;QAHL,QAAG,GAAH,GAAG,CAA2C;QAC7C,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAqB;QAGlD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,OAAsB;QAC5D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CACZ,yEAAyE,CACzE,CAAC;YACF,OAAO;QACR,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3E,MAAM,eAAe,GAAG,IAAI,CAAC,wBAAwB,CACpD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAChC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAE7D,eAAe,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACvC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,IAAY;QACxB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CACZ,0EAA0E,CAC1E,CAAC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,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAClE,CAAC;QACH,CAAC;IACF,CAAC;IAEO,wBAAwB,CAC/B,MAA8C;QAE9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,MAAM,CACnB,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CACrD,CAAC;QACH,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC;QAED,OAAO,EAAE,CAAC;IACX,CAAC;IAEO,gBAAgB,CAAC,YAAoB;QAC5C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,EAAE,CAAC;QACX,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;IAED,GAAG,CAAC,KAAe;QAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACD"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ /**
10
+ * Matches a given path against a list of routes and returns the matching route and parameters.
11
+ *
12
+ * @param path The path to match against the routes.
13
+ * @param routes The list of routes to match against.
14
+ * @returns The matching route and parameters, or null if no match is found.
15
+ */
16
+ export default function matchRoute(path: string, routes: string[]): {
17
+ params: Record<string, string>;
18
+ route: string;
19
+ };
20
+ //# sourceMappingURL=matchRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchRoute.d.ts","sourceRoot":"","sources":["../../src/utils/matchRoute.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;;;EAgDhE"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ /**
10
+ * Matches a given path against a list of routes and returns the matching route and parameters.
11
+ *
12
+ * @param path The path to match against the routes.
13
+ * @param routes The list of routes to match against.
14
+ * @returns The matching route and parameters, or null if no match is found.
15
+ */
16
+ export default function matchRoute(path, routes) {
17
+ if (path === "/") {
18
+ return routes.includes("/") ? { params: {}, route: "/" } : null;
19
+ }
20
+ const pathChunks = path.split("/").filter(Boolean);
21
+ outer: for (let i = 0; i < routes.length; i++) {
22
+ const params = {};
23
+ const route = routes[i];
24
+ const routeChunks = route.split("/").filter(Boolean);
25
+ let isMatch = true;
26
+ const isCatchAll = routeChunks.some((chunk) => /^\[\[.+\]\]$/.test(chunk));
27
+ if (!isCatchAll && pathChunks.length !== routeChunks.length) {
28
+ continue;
29
+ }
30
+ for (let j = 0; j < routeChunks.length; j++) {
31
+ const routeChunk = routeChunks[j];
32
+ const pathChunk = pathChunks[j];
33
+ if (/^\[\[.+\]\]$/.test(routeChunk)) {
34
+ params[routeChunk.slice(2, -2)] = pathChunks
35
+ .slice(j)
36
+ .map(decodeURIComponent)
37
+ .join("/");
38
+ return { params, route };
39
+ }
40
+ if (/^\[.+\]$/.test(routeChunk)) {
41
+ params[routeChunk.slice(1, -1)] = decodeURIComponent(pathChunk);
42
+ continue;
43
+ }
44
+ if (routeChunk !== pathChunk) {
45
+ isMatch = false;
46
+ continue outer;
47
+ }
48
+ }
49
+ if (isMatch) {
50
+ return { params, route };
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ //# sourceMappingURL=matchRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchRoute.js","sourceRoot":"","sources":["../../src/utils/matchRoute.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,IAAY,EAAE,MAAgB;IAChE,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnD,KAAK,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/C,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,OAAO,GAAG,IAAI,CAAC;QAEnB,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAE3E,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;YAC7D,SAAS;QACV,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAEhC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACrC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU;qBAC1C,KAAK,CAAC,CAAC,CAAC;qBACR,GAAG,CAAC,kBAAkB,CAAC;qBACvB,IAAI,CAAC,GAAG,CAAC,CAAC;gBACZ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YAC1B,CAAC;YAED,IAAI,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;gBAChE,SAAS;YACV,CAAC;YAED,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC9B,OAAO,GAAG,KAAK,CAAC;gBAChB,SAAS,KAAK,CAAC;YAChB,CAAC;QACF,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Lynnix
3
+ * File-based hypermedia routing middleware for Node.js, Mutor.js, and HTMX.
4
+ *
5
+ * @author Onah Victor <victoronah.dev@gmail.com>
6
+ * @repository https://github.com/allAboutJS/Lynnix
7
+ * @license MIT
8
+ */
9
+ /**
10
+ * Parse an incoming request body into a Lynnix-friendly shape.
11
+ *
12
+ * Supported content types:
13
+ * - `application/json`
14
+ * - `application/x-www-form-urlencoded`
15
+ * - `multipart/form-data`
16
+ *
17
+ * Parsed text values are assigned to `req.body` and uploaded files are assigned
18
+ * to `req.files`, similar to middleware such as multer/formidable.
19
+ *
20
+ * Design goals:
21
+ * - stream-based parsing for forms/uploads
22
+ * - bounded in-memory buffering for cross-environment compatibility
23
+ * - no temporary filesystem dependency, so it works in serverless runtimes too
24
+ * - dynamic imports for optional peer dependencies like `@fastify/busboy` and `qs`
25
+ */
26
+ import type { LynnixServerRequest, LynnixServerResponse, ParsedRequestBody, ParseReqBodyOptions } from "../types.js";
27
+ export default function parseReqBody(req: LynnixServerRequest, res: LynnixServerResponse, options?: ParseReqBodyOptions): Promise<ParsedRequestBody>;
28
+ //# sourceMappingURL=parseReqBody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseReqBody.d.ts","sourceRoot":"","sources":["../../src/utils/parseReqBody.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAGX,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EAEjB,mBAAmB,EAEnB,MAAM,aAAa,CAAC;AAarB,wBAA8B,YAAY,CACzC,GAAG,EAAE,mBAAmB,EACxB,GAAG,EAAE,oBAAoB,EACzB,OAAO,GAAE,mBAAwB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CA0D5B"}