effect-start 0.17.0 → 0.17.2

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 (148) hide show
  1. package/dist/Commander.d.ts +103 -0
  2. package/dist/Commander.js +333 -0
  3. package/dist/ContentNegotiation.d.ts +13 -0
  4. package/dist/ContentNegotiation.js +364 -0
  5. package/dist/Development.d.ts +34 -0
  6. package/dist/Development.js +52 -0
  7. package/dist/Entity.d.ts +47 -0
  8. package/dist/Entity.js +224 -0
  9. package/dist/FileRouter.d.ts +61 -0
  10. package/dist/FileRouter.js +203 -0
  11. package/dist/FileRouterCodegen.d.ts +19 -0
  12. package/dist/FileRouterCodegen.js +176 -0
  13. package/dist/FileRouterPattern.d.ts +9 -0
  14. package/dist/FileRouterPattern.js +35 -0
  15. package/dist/Http.d.ts +37 -0
  16. package/dist/Http.js +92 -0
  17. package/dist/HttpAppExtra.d.ts +7 -0
  18. package/dist/HttpAppExtra.js +320 -0
  19. package/dist/HttpUtils.d.ts +3 -0
  20. package/dist/HttpUtils.js +11 -0
  21. package/dist/PathPattern.d.ts +134 -0
  22. package/dist/PathPattern.js +415 -0
  23. package/dist/Random.d.ts +5 -0
  24. package/dist/Random.js +49 -0
  25. package/dist/Route.d.ts +98 -0
  26. package/dist/Route.js +81 -0
  27. package/dist/RouteBody.d.ts +53 -0
  28. package/dist/RouteBody.js +67 -0
  29. package/dist/RouteHook.d.ts +12 -0
  30. package/dist/RouteHook.js +45 -0
  31. package/dist/RouteHttp.d.ts +21 -0
  32. package/dist/RouteHttp.js +260 -0
  33. package/dist/RouteHttpTracer.d.ts +10 -0
  34. package/dist/RouteHttpTracer.js +62 -0
  35. package/dist/RouteMount.d.ts +119 -0
  36. package/dist/RouteMount.js +77 -0
  37. package/dist/RouteSchema.d.ts +65 -0
  38. package/dist/RouteSchema.js +155 -0
  39. package/dist/RouteSse.d.ts +21 -0
  40. package/dist/RouteSse.js +85 -0
  41. package/dist/RouteTree.d.ts +56 -0
  42. package/dist/RouteTree.js +91 -0
  43. package/dist/RouteTrie.d.ts +20 -0
  44. package/dist/RouteTrie.js +157 -0
  45. package/dist/RouterPattern.d.ts +118 -0
  46. package/dist/RouterPattern.js +269 -0
  47. package/dist/SchemaExtra.d.ts +7 -0
  48. package/dist/SchemaExtra.js +74 -0
  49. package/dist/Start.d.ts +19 -0
  50. package/dist/Start.js +23 -0
  51. package/dist/StartApp.d.ts +19 -0
  52. package/dist/StartApp.js +21 -0
  53. package/dist/StreamExtra.d.ts +28 -0
  54. package/dist/StreamExtra.js +100 -0
  55. package/dist/TuplePathPattern.d.ts +9 -0
  56. package/dist/TuplePathPattern.js +63 -0
  57. package/dist/Values.d.ts +26 -0
  58. package/dist/Values.js +30 -0
  59. package/dist/bun/BunBundle.d.ts +12 -0
  60. package/dist/bun/BunBundle.js +145 -0
  61. package/dist/bun/BunHttpServer.d.ts +44 -0
  62. package/dist/bun/BunHttpServer.js +187 -0
  63. package/dist/bun/BunHttpServer_web.d.ts +60 -0
  64. package/dist/bun/BunHttpServer_web.js +252 -0
  65. package/dist/bun/BunImportTrackerPlugin.d.ts +13 -0
  66. package/dist/bun/BunImportTrackerPlugin.js +71 -0
  67. package/dist/bun/BunRoute.d.ts +49 -0
  68. package/dist/bun/BunRoute.js +131 -0
  69. package/dist/bun/BunRuntime.d.ts +1 -0
  70. package/dist/bun/BunRuntime.js +26 -0
  71. package/dist/bun/BunVirtualFilesPlugin.d.ts +4 -0
  72. package/dist/bun/BunVirtualFilesPlugin.js +40 -0
  73. package/dist/bun/_BunEnhancedResolve.d.ts +45 -0
  74. package/dist/bun/_BunEnhancedResolve.js +104 -0
  75. package/dist/bun/index.d.ts +4 -0
  76. package/dist/bun/index.js +4 -0
  77. package/dist/bundler/Bundle.d.ts +60 -0
  78. package/dist/bundler/Bundle.js +48 -0
  79. package/dist/bundler/BundleFiles.d.ts +13 -0
  80. package/dist/bundler/BundleFiles.js +94 -0
  81. package/dist/bundler/BundleHttp.d.ts +45 -0
  82. package/dist/bundler/BundleHttp.js +176 -0
  83. package/dist/client/Overlay.d.ts +2 -0
  84. package/dist/client/Overlay.js +32 -0
  85. package/dist/client/ScrollState.d.ts +6 -0
  86. package/dist/client/ScrollState.js +98 -0
  87. package/dist/client/index.d.ts +6 -0
  88. package/dist/client/index.js +81 -0
  89. package/dist/experimental/EncryptedCookies.d.ts +51 -0
  90. package/dist/experimental/EncryptedCookies.js +243 -0
  91. package/dist/experimental/SseHttpResponse.d.ts +7 -0
  92. package/dist/experimental/SseHttpResponse.js +28 -0
  93. package/dist/experimental/index.d.ts +2 -0
  94. package/dist/experimental/index.js +2 -0
  95. package/dist/hyper/Hyper.d.ts +32 -0
  96. package/dist/hyper/Hyper.js +34 -0
  97. package/dist/hyper/HyperHtml.d.ts +23 -0
  98. package/dist/hyper/HyperHtml.js +144 -0
  99. package/dist/hyper/HyperNode.d.ts +14 -0
  100. package/dist/hyper/HyperNode.js +11 -0
  101. package/dist/hyper/HyperRoute.d.ts +8 -0
  102. package/dist/hyper/HyperRoute.js +32 -0
  103. package/dist/hyper/HyperRoute.test.d.ts +1 -0
  104. package/dist/hyper/HyperRoute.test.js +72 -0
  105. package/dist/hyper/index.d.ts +4 -0
  106. package/dist/hyper/index.js +4 -0
  107. package/dist/hyper/jsx-runtime.d.ts +7 -0
  108. package/dist/hyper/jsx-runtime.js +8 -0
  109. package/dist/index.d.ts +6 -0
  110. package/dist/index.js +6 -0
  111. package/dist/inference_check.d.ts +1 -0
  112. package/dist/inference_check.js +15 -0
  113. package/dist/middlewares/BasicAuthMiddleware.d.ts +8 -0
  114. package/dist/middlewares/BasicAuthMiddleware.js +22 -0
  115. package/dist/middlewares/index.d.ts +1 -0
  116. package/dist/middlewares/index.js +1 -0
  117. package/dist/node/FileSystem.d.ts +9 -0
  118. package/dist/node/FileSystem.js +440 -0
  119. package/dist/node/Utils.d.ts +1 -0
  120. package/dist/node/Utils.js +19 -0
  121. package/dist/repro_fail.d.ts +1 -0
  122. package/dist/repro_fail.js +14 -0
  123. package/dist/testing/TestHttpClient.d.ts +13 -0
  124. package/dist/testing/TestHttpClient.js +68 -0
  125. package/dist/testing/TestLogger.d.ts +13 -0
  126. package/dist/testing/TestLogger.js +29 -0
  127. package/dist/testing/index.d.ts +3 -0
  128. package/dist/testing/index.js +3 -0
  129. package/dist/testing/utils.d.ts +9 -0
  130. package/dist/testing/utils.js +39 -0
  131. package/dist/x/cloudflare/CloudflareTunnel.d.ts +13 -0
  132. package/dist/x/cloudflare/CloudflareTunnel.js +43 -0
  133. package/dist/x/cloudflare/index.d.ts +1 -0
  134. package/dist/x/cloudflare/index.js +1 -0
  135. package/dist/x/datastar/Datastar.d.ts +6 -0
  136. package/dist/x/datastar/Datastar.js +46 -0
  137. package/dist/x/datastar/index.d.ts +2 -0
  138. package/dist/x/datastar/index.js +2 -0
  139. package/dist/x/tailwind/TailwindPlugin.d.ts +23 -0
  140. package/dist/x/tailwind/TailwindPlugin.js +219 -0
  141. package/dist/x/tailwind/compile.d.ts +19 -0
  142. package/dist/x/tailwind/compile.js +156 -0
  143. package/dist/x/tailwind/plugin.d.ts +2 -0
  144. package/dist/x/tailwind/plugin.js +15 -0
  145. package/package.json +68 -16
  146. package/src/RouteBody.test.ts +18 -0
  147. package/src/RouteBody.ts +126 -2
  148. package/src/x/tailwind/compile.ts +8 -2
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Renders Hyper JSX nodes to HTML.
3
+ *
4
+ * Effect Start comes with {@link Hyper} and {@link JsxRuntime} to enable
5
+ * JSX support. The advantage of using JSX over HTML strings or templates
6
+ * is type safety and better editor support.
7
+ *
8
+ * JSX nodes are compatible with React's and Solid's.
9
+
10
+ * You can enable JSX support by updating `tsconfig.json`:
11
+ *
12
+ * {
13
+ * compilerOptions: {
14
+ * jsx: "react-jsx",
15
+ * jsxImportSource: "effect-start" | "react" | "praect" // etc.
16
+ * }
17
+ * }
18
+ */
19
+ const EMPTY_TAGS = [
20
+ "area",
21
+ "base",
22
+ "br",
23
+ "col",
24
+ "command",
25
+ "embed",
26
+ "hr",
27
+ "img",
28
+ "input",
29
+ "keygen",
30
+ "link",
31
+ "meta",
32
+ "param",
33
+ "source",
34
+ "track",
35
+ "wbr",
36
+ ];
37
+ // escape an attribute
38
+ let esc = (str) => String(str).replace(/[&<>"']/g, (s) => `&${map[s]};`);
39
+ let map = {
40
+ "&": "amp",
41
+ "<": "lt",
42
+ ">": "gt",
43
+ "\"": "quot",
44
+ "'": "apos",
45
+ };
46
+ export function renderToString(node, hooks) {
47
+ const stack = [node];
48
+ let result = "";
49
+ while (stack.length > 0) {
50
+ const current = stack.pop();
51
+ if (typeof current === "string") {
52
+ if (current.startsWith("<") && current.endsWith(">")) {
53
+ // This is a closing tag, don't escape it
54
+ result += current;
55
+ }
56
+ else {
57
+ result += esc(current);
58
+ }
59
+ continue;
60
+ }
61
+ if (typeof current === "number") {
62
+ result += esc(current);
63
+ continue;
64
+ }
65
+ if (typeof current === "boolean") {
66
+ // React-like behavior: booleans render nothing
67
+ continue;
68
+ }
69
+ if (current === null || current === undefined) {
70
+ // React-like behavior: null/undefined render nothing
71
+ continue;
72
+ }
73
+ if (Array.isArray(current)) {
74
+ // Handle arrays by pushing all items to stack in reverse order
75
+ for (let i = current.length - 1; i >= 0; i--) {
76
+ stack.push(current[i]);
77
+ }
78
+ continue;
79
+ }
80
+ if (current && typeof current === "object" && current.type) {
81
+ hooks?.onNode?.(current);
82
+ if (typeof current.type === "function") {
83
+ const componentResult = current.type(current.props);
84
+ if (componentResult != null) {
85
+ stack.push(componentResult);
86
+ }
87
+ continue;
88
+ }
89
+ const { type, props } = current;
90
+ result += `<${type}`;
91
+ for (const key in props) {
92
+ if (key !== "children"
93
+ && key !== "innerHTML" // Solid-specific
94
+ && key !== "dangerouslySetInnerHTML" // React-specific
95
+ && props[key] !== false
96
+ && props[key] != null) {
97
+ if (props[key] === true) {
98
+ result += ` ${esc(key)}`;
99
+ }
100
+ else {
101
+ const resolvedKey = key === "className" ? "class" : key;
102
+ const value = props[key];
103
+ if (key.startsWith("data-") && typeof value === "object") {
104
+ result += ` ${esc(resolvedKey)}="${esc(JSON.stringify(value))}"`;
105
+ }
106
+ else {
107
+ result += ` ${esc(resolvedKey)}="${esc(value)}"`;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ result += ">";
113
+ if (!EMPTY_TAGS.includes(type)) {
114
+ stack.push(`</${type}>`);
115
+ // React-specific
116
+ const html = props.dangerouslySetInnerHTML?.__html
117
+ ?? props.innerHTML;
118
+ if (html) {
119
+ result += html;
120
+ }
121
+ else {
122
+ const children = props.children;
123
+ if (type === "script" && typeof children === "function") {
124
+ result += `(${children.toString()})(window)`;
125
+ }
126
+ else if (Array.isArray(children)) {
127
+ for (let i = children.length - 1; i >= 0; i--) {
128
+ stack.push(children[i]);
129
+ }
130
+ }
131
+ else if (children != null) {
132
+ stack.push(children);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ else if (current && typeof current === "object") {
138
+ // Handle objects without type property - convert to string or ignore
139
+ // This prevents [object Object] from appearing
140
+ continue;
141
+ }
142
+ }
143
+ return result;
144
+ }
@@ -0,0 +1,14 @@
1
+ export declare const TypeId: unique symbol;
2
+ export type TypeId = typeof TypeId;
3
+ type Primitive = string | number | boolean | null | undefined;
4
+ export type Type = string | HyperComponent;
5
+ export type Props = {
6
+ [key: string]: Primitive | HyperNode | Iterable<Primitive | HyperNode> | Record<string, unknown> | ((window: Window) => void);
7
+ };
8
+ export type HyperComponent = (props: Props) => HyperNode | Primitive;
9
+ export interface HyperNode {
10
+ type: Type;
11
+ props: Props;
12
+ }
13
+ export declare function make(type: Type, props: Props): HyperNode;
14
+ export {};
@@ -0,0 +1,11 @@
1
+ export const TypeId = Symbol.for("effect-start/HyperNode");
2
+ const NoChildren = Object.freeze([]);
3
+ export function make(type, props) {
4
+ return {
5
+ type,
6
+ props: {
7
+ ...props,
8
+ children: props.children ?? NoChildren,
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,8 @@
1
+ import * as Route from "../Route.ts";
2
+ import type * as RouteBody from "../RouteBody.ts";
3
+ import type { JSX } from "./jsx.d.ts";
4
+ export declare function html<D extends Route.RouteDescriptor.Any, B extends {}, I extends Route.Route.Tuple, E = never, R = never>(handler: RouteBody.HandlerInput<NoInfer<D & B & Route.ExtractBindings<I> & {
5
+ format: "html";
6
+ }>, JSX.Children, E, R>): (self: Route.RouteSet.RouteSet<D, B, I>) => Route.RouteSet.RouteSet<D, B, [...I, Route.Route.Route<{
7
+ format: "html";
8
+ }, {}, string, E, R>]>;
@@ -0,0 +1,32 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Entity from "../Entity.js";
3
+ import * as Route from "../Route.js";
4
+ import * as HyperHtml from "./HyperHtml.js";
5
+ function renderValue(value) {
6
+ if (Entity.isEntity(value)) {
7
+ return Entity.make(HyperHtml.renderToString(value.body), {
8
+ status: value.status,
9
+ url: value.url,
10
+ headers: value.headers,
11
+ });
12
+ }
13
+ return HyperHtml.renderToString(value);
14
+ }
15
+ function normalizeToEffect(handler, context, next) {
16
+ if (Effect.isEffect(handler)) {
17
+ return handler;
18
+ }
19
+ if (typeof handler === "function") {
20
+ const result = handler(context, next);
21
+ if (Effect.isEffect(result)) {
22
+ return result;
23
+ }
24
+ return Effect.gen(function* () {
25
+ return yield* result;
26
+ });
27
+ }
28
+ return Effect.succeed(handler);
29
+ }
30
+ export function html(handler) {
31
+ return Route.html((context, next) => Effect.map(normalizeToEffect(handler, context, next), renderValue));
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "effect-start/jsx-runtime";
2
+ /** @jsxImportSource effect-start */
3
+ import * as test from "bun:test";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Entity from "../Entity.js";
6
+ import * as Http from "../Http.js";
7
+ import * as Route from "../Route.js";
8
+ import * as RouteHttp from "../RouteHttp.js";
9
+ import * as HyperRoute from "./HyperRoute.js";
10
+ test.describe("HyperRoute.html", () => {
11
+ test.it("renders JSX to HTML string", async () => {
12
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(_jsx("div", { children: "Hello World" }))));
13
+ const response = await Http.fetch(handler, { path: "/" });
14
+ test.expect(response.status).toBe(200);
15
+ test.expect(response.headers.get("Content-Type")).toBe("text/html; charset=utf-8");
16
+ test.expect(await response.text()).toBe("<div>Hello World</div>");
17
+ });
18
+ test.it("renders nested JSX elements", async () => {
19
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(_jsxs("div", { class: "container", children: [_jsx("h1", { children: "Title" }), _jsx("p", { children: "Paragraph" })] }))));
20
+ const response = await Http.fetch(handler, { path: "/" });
21
+ test.expect(await response.text()).toBe("<div class=\"container\"><h1>Title</h1><p>Paragraph</p></div>");
22
+ });
23
+ test.it("renders JSX from Effect", async () => {
24
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(Effect.succeed(_jsx("span", { children: "From Effect" })))));
25
+ const response = await Http.fetch(handler, { path: "/" });
26
+ test.expect(await response.text()).toBe("<span>From Effect</span>");
27
+ });
28
+ test.it("renders JSX from generator function", async () => {
29
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(Effect.gen(function* () {
30
+ const name = yield* Effect.succeed("World");
31
+ return (_jsxs("div", { children: ["Hello ", name] }));
32
+ }))));
33
+ const response = await Http.fetch(handler, { path: "/" });
34
+ test.expect(await response.text()).toBe("<div>Hello World</div>");
35
+ });
36
+ test.it("renders JSX from handler function", async () => {
37
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html((context) => Effect.succeed(_jsx("div", { children: "Request received" })))));
38
+ const response = await Http.fetch(handler, { path: "/" });
39
+ test.expect(await response.text()).toBe("<div>Request received</div>");
40
+ });
41
+ test.it("renders JSX with dynamic content", async () => {
42
+ const items = ["Apple", "Banana", "Cherry"];
43
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(_jsx("ul", { children: items.map((item) => (_jsx("li", { children: item }))) }))));
44
+ const response = await Http.fetch(handler, { path: "/" });
45
+ test.expect(await response.text()).toBe("<ul><li>Apple</li><li>Banana</li><li>Cherry</li></ul>");
46
+ });
47
+ test.it("handles Entity with JSX body", async () => {
48
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(Entity.make(_jsx("div", { children: "With Entity" }), { status: 201 }))));
49
+ const response = await Http.fetch(handler, { path: "/" });
50
+ test.expect(response.status).toBe(201);
51
+ test.expect(await response.text()).toBe("<div>With Entity</div>");
52
+ });
53
+ test.it("renders data-* attributes with object values as JSON", async () => {
54
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(_jsx("div", { "data-signals": {
55
+ draft: "",
56
+ pendingDraft: "",
57
+ username: "User123",
58
+ }, children: "Content" }))));
59
+ const response = await Http.fetch(handler, { path: "/" });
60
+ test.expect(await response.text()).toBe("<div data-signals=\"{&quot;draft&quot;:&quot;&quot;,&quot;pendingDraft&quot;:&quot;&quot;,&quot;username&quot;:&quot;User123&quot;}\">Content</div>");
61
+ });
62
+ test.it("renders script with function child as IIFE", async () => {
63
+ const handler = RouteHttp.toWebHandler(Route.get(HyperRoute.html(_jsx("script", { children: (window) => {
64
+ console.log("Hello from", window.document.title);
65
+ } }))));
66
+ const response = await Http.fetch(handler, { path: "/" });
67
+ const text = await response.text();
68
+ test.expect(text).toContain("<script>(");
69
+ test.expect(text).toContain(")(window)</script>");
70
+ test.expect(text).toContain("window.document.title");
71
+ });
72
+ });
@@ -0,0 +1,4 @@
1
+ export * as Hyper from "./Hyper.ts";
2
+ export * as HyperHtml from "./HyperHtml.ts";
3
+ export * as HyperNode from "./HyperNode.ts";
4
+ export * as HyperRoute from "./HyperRoute.ts";
@@ -0,0 +1,4 @@
1
+ export * as Hyper from "./Hyper.js";
2
+ export * as HyperHtml from "./HyperHtml.js";
3
+ export * as HyperNode from "./HyperNode.js";
4
+ export * as HyperRoute from "./HyperRoute.js";
@@ -0,0 +1,7 @@
1
+ import * as HyperNode from "./HyperNode.ts";
2
+ import type { JSX } from "./jsx.d.ts";
3
+ declare function Fragment(props: {
4
+ children: JSX.Element;
5
+ }): HyperNode.HyperNode;
6
+ declare function jsx<T extends HyperNode.Type>(type: T, props: T extends string ? HyperNode.Props : T extends (props: infer P) => any ? P : never): HyperNode.HyperNode;
7
+ export { Fragment, type JSX, jsx, jsx as jsxDEV, jsx as jsxs, };
@@ -0,0 +1,8 @@
1
+ import * as HyperNode from "./HyperNode.js";
2
+ function Fragment(props) {
3
+ return props.children;
4
+ }
5
+ function jsx(type, props) {
6
+ return HyperNode.make(type, props);
7
+ }
8
+ export { Fragment, jsx, jsx as jsxDEV, jsx as jsxs, };
@@ -0,0 +1,6 @@
1
+ export * as Bundle from "./bundler/Bundle.ts";
2
+ export * as Development from "./Development.ts";
3
+ export * as Entity from "./Entity.ts";
4
+ export * as FileRouter from "./FileRouter.ts";
5
+ export * as Route from "./Route.ts";
6
+ export * as Start from "./Start.ts";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * as Bundle from "./bundler/Bundle.js";
2
+ export * as Development from "./Development.js";
3
+ export * as Entity from "./Entity.js";
4
+ export * as FileRouter from "./FileRouter.js";
5
+ export * as Route from "./Route.js";
6
+ export * as Start from "./Start.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { Effect, Context } from "effect";
2
+ import * as Route from "./RouteBody";
3
+ const ServiceA = Context.GenericTag("ServiceA");
4
+ const ServiceB = Context.GenericTag("ServiceB");
5
+ const handler = function* () {
6
+ yield* ServiceA;
7
+ yield* ServiceB;
8
+ return "ok";
9
+ };
10
+ // Check 2: What does 'handle' infer?
11
+ const resultHandler = Route.handle(handler);
12
+ // Let's see if we can provide ServiceA and ServiceB and get a runnable effect (R=never)
13
+ const provided = Effect.provideService(Effect.provideService(resultHandler({}, () => null), ServiceA, { status: 200 }), ServiceB, { status: 200 });
14
+ const runnable = (e) => { };
15
+ runnable(provided);
@@ -0,0 +1,8 @@
1
+ import * as HttpServerRequest from "@effect/platform/HttpServerRequest";
2
+ import * as HttpServerResponse from "@effect/platform/HttpServerResponse";
3
+ import * as Effect from "effect/Effect";
4
+ export interface BasicAuthConfig {
5
+ readonly username: string;
6
+ readonly password: string;
7
+ }
8
+ export declare const make: (config: BasicAuthConfig) => <E, R>(app: import("@effect/platform/HttpApp").Default<E, R>) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, HttpServerRequest.HttpServerRequest | R>;
@@ -0,0 +1,22 @@
1
+ import * as HttpMiddleware from "@effect/platform/HttpMiddleware";
2
+ import * as HttpServerRequest from "@effect/platform/HttpServerRequest";
3
+ import * as HttpServerResponse from "@effect/platform/HttpServerResponse";
4
+ import * as Effect from "effect/Effect";
5
+ const unauthorizedResponse = HttpServerResponse.empty({
6
+ status: 401,
7
+ headers: { "WWW-Authenticate": "Basic" },
8
+ });
9
+ export const make = (config) => HttpMiddleware.make((app) => Effect.gen(function* () {
10
+ const request = yield* HttpServerRequest.HttpServerRequest;
11
+ const authHeader = request.headers.authorization;
12
+ if (!authHeader || !authHeader.startsWith("Basic ")) {
13
+ return unauthorizedResponse;
14
+ }
15
+ const base64Credentials = authHeader.slice(6);
16
+ const credentials = atob(base64Credentials);
17
+ const [username, password] = credentials.split(":");
18
+ if (username !== config.username || password !== config.password) {
19
+ return unauthorizedResponse;
20
+ }
21
+ return yield* app;
22
+ }));
@@ -0,0 +1 @@
1
+ export * as BasicAuthMiddleware from "./BasicAuthMiddleware.ts";
@@ -0,0 +1 @@
1
+ export * as BasicAuthMiddleware from "./BasicAuthMiddleware.js";
@@ -0,0 +1,9 @@
1
+ import * as Error from "@effect/platform/Error";
2
+ import type { PlatformError } from "@effect/platform/Error";
3
+ import { SystemError } from "@effect/platform/Error";
4
+ import * as FileSystem from "@effect/platform/FileSystem";
5
+ import * as Layer from "effect/Layer";
6
+ import * as NFS from "node:fs";
7
+ export declare const layer: Layer.Layer<FileSystem.FileSystem, never, never>;
8
+ export { Error, FileSystem, };
9
+ export declare function handleErrnoException(module: SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError;