effect-start 0.17.2 → 0.19.0

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 (80) hide show
  1. package/dist/Development.d.ts +7 -2
  2. package/dist/Development.js +12 -6
  3. package/dist/PlatformRuntime.d.ts +4 -0
  4. package/dist/PlatformRuntime.js +9 -0
  5. package/dist/Route.d.ts +6 -2
  6. package/dist/Route.js +22 -0
  7. package/dist/RouteHttp.d.ts +1 -1
  8. package/dist/RouteHttp.js +12 -19
  9. package/dist/RouteMount.d.ts +2 -1
  10. package/dist/Start.d.ts +1 -5
  11. package/dist/Start.js +1 -8
  12. package/dist/Unique.d.ts +50 -0
  13. package/dist/Unique.js +187 -0
  14. package/dist/bun/BunHttpServer.js +5 -6
  15. package/dist/bun/BunRoute.d.ts +1 -1
  16. package/dist/bun/BunRoute.js +2 -2
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/node/Effectify.d.ts +209 -0
  20. package/dist/node/Effectify.js +19 -0
  21. package/dist/node/FileSystem.d.ts +3 -5
  22. package/dist/node/FileSystem.js +42 -62
  23. package/dist/node/PlatformError.d.ts +46 -0
  24. package/dist/node/PlatformError.js +43 -0
  25. package/dist/testing/TestLogger.js +1 -1
  26. package/package.json +10 -5
  27. package/src/Development.ts +13 -18
  28. package/src/PlatformRuntime.ts +11 -0
  29. package/src/Route.ts +31 -2
  30. package/src/RouteHttp.ts +15 -31
  31. package/src/RouteMount.ts +1 -1
  32. package/src/Start.ts +1 -15
  33. package/src/Unique.ts +232 -0
  34. package/src/bun/BunHttpServer.ts +6 -9
  35. package/src/bun/BunRoute.ts +3 -3
  36. package/src/index.ts +1 -0
  37. package/src/node/Effectify.ts +262 -0
  38. package/src/node/FileSystem.ts +59 -97
  39. package/src/node/PlatformError.ts +102 -0
  40. package/src/testing/TestLogger.ts +1 -1
  41. package/dist/Random.d.ts +0 -5
  42. package/dist/Random.js +0 -49
  43. package/src/Commander.test.ts +0 -1639
  44. package/src/ContentNegotiation.test.ts +0 -603
  45. package/src/Development.test.ts +0 -119
  46. package/src/Entity.test.ts +0 -592
  47. package/src/FileRouterPattern.test.ts +0 -147
  48. package/src/FileRouter_files.test.ts +0 -64
  49. package/src/FileRouter_path.test.ts +0 -145
  50. package/src/FileRouter_tree.test.ts +0 -132
  51. package/src/Http.test.ts +0 -319
  52. package/src/HttpAppExtra.test.ts +0 -103
  53. package/src/HttpUtils.test.ts +0 -85
  54. package/src/PathPattern.test.ts +0 -648
  55. package/src/Random.ts +0 -59
  56. package/src/RouteBody.test.ts +0 -232
  57. package/src/RouteHook.test.ts +0 -40
  58. package/src/RouteHttp.test.ts +0 -2909
  59. package/src/RouteMount.test.ts +0 -481
  60. package/src/RouteSchema.test.ts +0 -427
  61. package/src/RouteSse.test.ts +0 -249
  62. package/src/RouteTree.test.ts +0 -494
  63. package/src/RouteTrie.test.ts +0 -322
  64. package/src/RouterPattern.test.ts +0 -676
  65. package/src/Values.test.ts +0 -263
  66. package/src/bun/BunBundle.test.ts +0 -268
  67. package/src/bun/BunBundle_imports.test.ts +0 -48
  68. package/src/bun/BunHttpServer.test.ts +0 -251
  69. package/src/bun/BunImportTrackerPlugin.test.ts +0 -77
  70. package/src/bun/BunRoute.test.ts +0 -162
  71. package/src/bundler/BundleHttp.test.ts +0 -132
  72. package/src/effect/HttpRouter.test.ts +0 -548
  73. package/src/experimental/EncryptedCookies.test.ts +0 -488
  74. package/src/hyper/HyperHtml.test.ts +0 -209
  75. package/src/hyper/HyperRoute.test.tsx +0 -197
  76. package/src/middlewares/BasicAuthMiddleware.test.ts +0 -84
  77. package/src/testing/TestHttpClient.test.ts +0 -83
  78. package/src/testing/TestLogger.test.ts +0 -51
  79. package/src/x/datastar/Datastar.test.ts +0 -266
  80. package/src/x/tailwind/TailwindPlugin.test.ts +0 -333
@@ -1,147 +0,0 @@
1
- import * as test from "bun:test"
2
- import * as FileRouterPattern from "./FileRouterPattern.ts"
3
-
4
- test.it("empty path", () => {
5
- test
6
- .expect(FileRouterPattern.parse(""))
7
- .toEqual([])
8
- test
9
- .expect(FileRouterPattern.parse("/"))
10
- .toEqual([])
11
- })
12
-
13
- test.it("groups", () => {
14
- test
15
- .expect(FileRouterPattern.parse("(admin)"))
16
- .toEqual([
17
- { _tag: "GroupSegment", name: "admin" },
18
- ])
19
- test
20
- .expect(FileRouterPattern.parse("/(admin)/users"))
21
- .toEqual([
22
- { _tag: "GroupSegment", name: "admin" },
23
- { _tag: "LiteralSegment", value: "users" },
24
- ])
25
- test
26
- .expect(FileRouterPattern.parse("(auth)/login/(step1)"))
27
- .toEqual([
28
- { _tag: "GroupSegment", name: "auth" },
29
- { _tag: "LiteralSegment", value: "login" },
30
- { _tag: "GroupSegment", name: "step1" },
31
- ])
32
- })
33
-
34
- test.it("handle files parsed as Literal", () => {
35
- test
36
- .expect(FileRouterPattern.parse("route.ts"))
37
- .toEqual([
38
- { _tag: "LiteralSegment", value: "route.ts" },
39
- ])
40
- test
41
- .expect(FileRouterPattern.parse("/api/route.js"))
42
- .toEqual([
43
- { _tag: "LiteralSegment", value: "api" },
44
- { _tag: "LiteralSegment", value: "route.js" },
45
- ])
46
- test
47
- .expect(FileRouterPattern.parse("layer.tsx"))
48
- .toEqual([
49
- { _tag: "LiteralSegment", value: "layer.tsx" },
50
- ])
51
- test
52
- .expect(FileRouterPattern.parse("/blog/layer.jsx"))
53
- .toEqual([
54
- { _tag: "LiteralSegment", value: "blog" },
55
- { _tag: "LiteralSegment", value: "layer.jsx" },
56
- ])
57
- })
58
-
59
- test.it("params and rest", () => {
60
- test
61
- .expect(FileRouterPattern.parse("users/[userId]/posts"))
62
- .toEqual([
63
- { _tag: "LiteralSegment", value: "users" },
64
- { _tag: "ParamSegment", name: "userId" },
65
- { _tag: "LiteralSegment", value: "posts" },
66
- ])
67
- test
68
- .expect(FileRouterPattern.parse("api/[[...path]]"))
69
- .toEqual([
70
- { _tag: "LiteralSegment", value: "api" },
71
- { _tag: "RestSegment", name: "path", optional: true },
72
- ])
73
- })
74
-
75
- test.it("invalid paths", () => {
76
- test
77
- .expect(() => FileRouterPattern.parse("$..."))
78
- .toThrow()
79
- test
80
- .expect(() => FileRouterPattern.parse("invalid%char"))
81
- .toThrow()
82
- test
83
- .expect(() => FileRouterPattern.parse("path with spaces"))
84
- .toThrow()
85
- })
86
-
87
- test.it("segments with extensions (literal with dots)", () => {
88
- test
89
- .expect(FileRouterPattern.parse("events.json/route.ts"))
90
- .toEqual([
91
- { _tag: "LiteralSegment", value: "events.json" },
92
- { _tag: "LiteralSegment", value: "route.ts" },
93
- ])
94
- })
95
-
96
- test.it("formatSegment", () => {
97
- test
98
- .expect(
99
- FileRouterPattern.formatSegment({
100
- _tag: "LiteralSegment",
101
- value: "users",
102
- }),
103
- )
104
- .toBe("users")
105
- test
106
- .expect(
107
- FileRouterPattern.formatSegment({ _tag: "ParamSegment", name: "id" }),
108
- )
109
- .toBe("[id]")
110
- test
111
- .expect(
112
- FileRouterPattern.formatSegment({ _tag: "GroupSegment", name: "admin" }),
113
- )
114
- .toBe("(admin)")
115
- test
116
- .expect(
117
- FileRouterPattern.formatSegment({ _tag: "RestSegment", name: "path" }),
118
- )
119
- .toBe("[...path]")
120
- })
121
-
122
- test.it("format", () => {
123
- test
124
- .expect(FileRouterPattern.format([]))
125
- .toBe("/")
126
- test
127
- .expect(
128
- FileRouterPattern.format([{ _tag: "LiteralSegment", value: "users" }]),
129
- )
130
- .toBe("/users")
131
- test
132
- .expect(
133
- FileRouterPattern.format([
134
- { _tag: "GroupSegment", name: "admin" },
135
- { _tag: "LiteralSegment", value: "users" },
136
- ]),
137
- )
138
- .toBe("/(admin)/users")
139
- test
140
- .expect(
141
- FileRouterPattern.format([
142
- { _tag: "LiteralSegment", value: "users" },
143
- { _tag: "ParamSegment", name: "id" },
144
- ]),
145
- )
146
- .toBe("/users/[id]")
147
- })
@@ -1,64 +0,0 @@
1
- import * as test from "bun:test"
2
- import { MemoryFileSystem } from "effect-memfs"
3
- import * as Effect from "effect/Effect"
4
- import * as FileRouter from "./FileRouter.ts"
5
- import { effectFn } from "./testing"
6
-
7
- const Files = {
8
- "/routes/about/layer.tsx": "",
9
- "/routes/about/route.tsx": "",
10
- "/routes/users/route.tsx": "",
11
- "/routes/users/layer.tsx": "",
12
- "/routes/users/[userId]/route.tsx": "",
13
- "/routes/layer.tsx": "",
14
- }
15
-
16
- const effect = effectFn()
17
-
18
- test.it("walks routes", () =>
19
- effect(function*() {
20
- const files = yield* FileRouter.walkRoutesDirectory("/routes").pipe(
21
- Effect.provide(MemoryFileSystem.layerWith(Files)),
22
- )
23
-
24
- test
25
- .expect(
26
- files.map(v => v.modulePath),
27
- )
28
- .toEqual([
29
- "layer.tsx",
30
- "about/layer.tsx",
31
- "about/route.tsx",
32
- "users/layer.tsx",
33
- "users/route.tsx",
34
- "users/[userId]/route.tsx",
35
- ])
36
- }))
37
-
38
- test.it("walks routes with rest", () =>
39
- effect(function*() {
40
- const files = yield* FileRouter.walkRoutesDirectory("/routes").pipe(
41
- Effect.provide(
42
- MemoryFileSystem.layerWith({
43
- ...Files,
44
- "/routes/[[...rest]]/route.tsx": "",
45
- "/routes/users/[...path]/route.tsx": "",
46
- }),
47
- ),
48
- )
49
-
50
- test
51
- .expect(
52
- files.map(v => v.modulePath),
53
- )
54
- .toEqual([
55
- "layer.tsx",
56
- "about/layer.tsx",
57
- "about/route.tsx",
58
- "users/layer.tsx",
59
- "users/route.tsx",
60
- "users/[userId]/route.tsx",
61
- "users/[...path]/route.tsx",
62
- "[[...rest]]/route.tsx",
63
- ])
64
- }))
@@ -1,145 +0,0 @@
1
- import * as test from "bun:test"
2
- import * as FileRouter from "./FileRouter.ts"
3
-
4
- test.it("empty path", () => {
5
- test
6
- .expect(FileRouter.parse(""))
7
- .toEqual([])
8
- test
9
- .expect(FileRouter.parse("/"))
10
- .toEqual([])
11
- })
12
-
13
- test.it("groups", () => {
14
- test
15
- .expect(FileRouter.parse("(admin)"))
16
- .toEqual([
17
- { _tag: "GroupSegment", name: "admin" },
18
- ])
19
- test
20
- .expect(FileRouter.parse("/(admin)/users"))
21
- .toEqual([
22
- { _tag: "GroupSegment", name: "admin" },
23
- { _tag: "LiteralSegment", value: "users" },
24
- ])
25
- test
26
- .expect(FileRouter.parse("(auth)/login/(step1)"))
27
- .toEqual([
28
- { _tag: "GroupSegment", name: "auth" },
29
- { _tag: "LiteralSegment", value: "login" },
30
- { _tag: "GroupSegment", name: "step1" },
31
- ])
32
- })
33
-
34
- test.it("handle files parsed as Literal", () => {
35
- test
36
- .expect(FileRouter.parse("route.ts"))
37
- .toEqual([
38
- { _tag: "LiteralSegment", value: "route.ts" },
39
- ])
40
- test
41
- .expect(FileRouter.parse("/api/route.js"))
42
- .toEqual([
43
- { _tag: "LiteralSegment", value: "api" },
44
- { _tag: "LiteralSegment", value: "route.js" },
45
- ])
46
- test
47
- .expect(FileRouter.parse("layer.tsx"))
48
- .toEqual([
49
- { _tag: "LiteralSegment", value: "layer.tsx" },
50
- ])
51
- test
52
- .expect(FileRouter.parse("/blog/layer.jsx"))
53
- .toEqual([
54
- { _tag: "LiteralSegment", value: "blog" },
55
- { _tag: "LiteralSegment", value: "layer.jsx" },
56
- ])
57
- })
58
-
59
- test.it("parseRoute extracts handle from Literal", () => {
60
- const route = FileRouter.parseRoute("users/route.tsx")
61
- test
62
- .expect(route.handle)
63
- .toBe("route")
64
- test
65
- .expect(route.routePath)
66
- .toBe("/users")
67
- test
68
- .expect(route.segments)
69
- .toEqual([
70
- { _tag: "LiteralSegment", value: "users" },
71
- ])
72
-
73
- const layer = FileRouter.parseRoute("api/layer.ts")
74
- test
75
- .expect(layer.handle)
76
- .toBe("layer")
77
- test
78
- .expect(layer.routePath)
79
- .toBe("/api")
80
- })
81
-
82
- test.it("parseRoute with groups", () => {
83
- const route = FileRouter.parseRoute("(admin)/users/route.tsx")
84
- test
85
- .expect(route.handle)
86
- .toBe("route")
87
- test
88
- .expect(route.routePath)
89
- .toBe("/users")
90
- test
91
- .expect(route.segments)
92
- .toEqual([
93
- { _tag: "GroupSegment", name: "admin" },
94
- { _tag: "LiteralSegment", value: "users" },
95
- ])
96
- })
97
-
98
- test.it("parseRoute with params and rest", () => {
99
- const route = FileRouter.parseRoute("users/[userId]/posts/route.tsx")
100
- test
101
- .expect(route.handle)
102
- .toBe("route")
103
- test
104
- .expect(route.routePath)
105
- .toBe("/users/[userId]/posts")
106
- test
107
- .expect(route.segments)
108
- .toEqual([
109
- { _tag: "LiteralSegment", value: "users" },
110
- { _tag: "ParamSegment", name: "userId" },
111
- { _tag: "LiteralSegment", value: "posts" },
112
- ])
113
-
114
- const rest = FileRouter.parseRoute("api/[[...path]]/route.ts")
115
- test
116
- .expect(rest.handle)
117
- .toBe("route")
118
- test
119
- .expect(rest.segments)
120
- .toEqual([
121
- { _tag: "LiteralSegment", value: "api" },
122
- { _tag: "RestSegment", name: "path", optional: true },
123
- ])
124
- })
125
-
126
- test.it("invalid paths", () => {
127
- test
128
- .expect(() => FileRouter.parse("$..."))
129
- .toThrow()
130
- test
131
- .expect(() => FileRouter.parse("invalid%char"))
132
- .toThrow()
133
- test
134
- .expect(() => FileRouter.parse("path with spaces"))
135
- .toThrow()
136
- })
137
-
138
- test.it("segments with extensions (literal with dots)", () => {
139
- test
140
- .expect(FileRouter.parse("events.json/route.ts"))
141
- .toEqual([
142
- { _tag: "LiteralSegment", value: "events.json" },
143
- { _tag: "LiteralSegment", value: "route.ts" },
144
- ])
145
- })
@@ -1,132 +0,0 @@
1
- import * as test from "bun:test"
2
- import * as FileRouter from "./FileRouter.ts"
3
-
4
- test.it("tree with root only", () => {
5
- const handles = [
6
- "route.tsx",
7
- "layer.tsx",
8
- ]
9
- .map(FileRouter.parseRoute)
10
- const tree = FileRouter.treeFromRouteHandles(handles)
11
-
12
- test
13
- .expect(tree)
14
- .toEqual({
15
- path: "/",
16
- handles: [
17
- test.expect.objectContaining({
18
- handle: "route",
19
- }),
20
- test.expect.objectContaining({
21
- handle: "layer",
22
- }),
23
- ],
24
- })
25
- })
26
-
27
- test.it("tree without root", () => {
28
- const handles = []
29
- .map(FileRouter.parseRoute)
30
- const tree = FileRouter.treeFromRouteHandles(handles)
31
-
32
- test
33
- .expect(tree)
34
- .toEqual({
35
- path: "/",
36
- handles: [],
37
- })
38
- })
39
-
40
- test.it("deep tree", () => {
41
- const handles = [
42
- "users/route.tsx",
43
- "users/layer.tsx",
44
- "users/[userId]/route.tsx",
45
- "layer.tsx",
46
- ]
47
- .map(FileRouter.parseRoute)
48
- const tree = FileRouter.treeFromRouteHandles(handles)
49
-
50
- test
51
- .expect(tree)
52
- .toEqual({
53
- path: "/",
54
- handles: [
55
- test.expect.objectContaining({
56
- handle: "layer",
57
- }),
58
- ],
59
- children: [
60
- {
61
- path: "/users",
62
- handles: [
63
- test.expect.objectContaining({
64
- handle: "route",
65
- }),
66
- test.expect.objectContaining({
67
- handle: "layer",
68
- }),
69
- ],
70
- children: [
71
- {
72
- path: "/[userId]",
73
- handles: [
74
- test.expect.objectContaining({
75
- handle: "route",
76
- }),
77
- ],
78
- },
79
- ],
80
- },
81
- ],
82
- })
83
- })
84
-
85
- test.it("throws on overlapping routes from groups", () => {
86
- test
87
- .expect(() => {
88
- const handles = [
89
- "(admin)/users/route.tsx",
90
- "users/route.tsx",
91
- ]
92
- .map(FileRouter.parseRoute)
93
-
94
- FileRouter.getRouteHandlesFromPaths(
95
- handles.map(h => h.modulePath),
96
- )
97
- })
98
- .toThrow("Conflicting routes detected at path /users")
99
- })
100
-
101
- test.it("throws on overlapping routes with same path", () => {
102
- test
103
- .expect(() => {
104
- const handles = [
105
- "about/route.tsx",
106
- "about/route.ts",
107
- ]
108
- .map(FileRouter.parseRoute)
109
-
110
- FileRouter.getRouteHandlesFromPaths(
111
- handles.map(h => h.modulePath),
112
- )
113
- })
114
- .toThrow("Conflicting routes detected at path /about")
115
- })
116
-
117
- test.it("allows route and layer at same path", () => {
118
- test
119
- .expect(() => {
120
- const handles = [
121
- "users/route.tsx",
122
- "users/layer.tsx",
123
- ]
124
- .map(FileRouter.parseRoute)
125
-
126
- FileRouter.getRouteHandlesFromPaths(
127
- handles.map(h => h.modulePath),
128
- )
129
- })
130
- .not
131
- .toThrow()
132
- })