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.
- package/dist/Development.d.ts +7 -2
- package/dist/Development.js +12 -6
- package/dist/PlatformRuntime.d.ts +4 -0
- package/dist/PlatformRuntime.js +9 -0
- package/dist/Route.d.ts +6 -2
- package/dist/Route.js +22 -0
- package/dist/RouteHttp.d.ts +1 -1
- package/dist/RouteHttp.js +12 -19
- package/dist/RouteMount.d.ts +2 -1
- package/dist/Start.d.ts +1 -5
- package/dist/Start.js +1 -8
- package/dist/Unique.d.ts +50 -0
- package/dist/Unique.js +187 -0
- package/dist/bun/BunHttpServer.js +5 -6
- package/dist/bun/BunRoute.d.ts +1 -1
- package/dist/bun/BunRoute.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/node/Effectify.d.ts +209 -0
- package/dist/node/Effectify.js +19 -0
- package/dist/node/FileSystem.d.ts +3 -5
- package/dist/node/FileSystem.js +42 -62
- package/dist/node/PlatformError.d.ts +46 -0
- package/dist/node/PlatformError.js +43 -0
- package/dist/testing/TestLogger.js +1 -1
- package/package.json +10 -5
- package/src/Development.ts +13 -18
- package/src/PlatformRuntime.ts +11 -0
- package/src/Route.ts +31 -2
- package/src/RouteHttp.ts +15 -31
- package/src/RouteMount.ts +1 -1
- package/src/Start.ts +1 -15
- package/src/Unique.ts +232 -0
- package/src/bun/BunHttpServer.ts +6 -9
- package/src/bun/BunRoute.ts +3 -3
- package/src/index.ts +1 -0
- package/src/node/Effectify.ts +262 -0
- package/src/node/FileSystem.ts +59 -97
- package/src/node/PlatformError.ts +102 -0
- package/src/testing/TestLogger.ts +1 -1
- package/dist/Random.d.ts +0 -5
- package/dist/Random.js +0 -49
- package/src/Commander.test.ts +0 -1639
- package/src/ContentNegotiation.test.ts +0 -603
- package/src/Development.test.ts +0 -119
- package/src/Entity.test.ts +0 -592
- package/src/FileRouterPattern.test.ts +0 -147
- package/src/FileRouter_files.test.ts +0 -64
- package/src/FileRouter_path.test.ts +0 -145
- package/src/FileRouter_tree.test.ts +0 -132
- package/src/Http.test.ts +0 -319
- package/src/HttpAppExtra.test.ts +0 -103
- package/src/HttpUtils.test.ts +0 -85
- package/src/PathPattern.test.ts +0 -648
- package/src/Random.ts +0 -59
- package/src/RouteBody.test.ts +0 -232
- package/src/RouteHook.test.ts +0 -40
- package/src/RouteHttp.test.ts +0 -2909
- package/src/RouteMount.test.ts +0 -481
- package/src/RouteSchema.test.ts +0 -427
- package/src/RouteSse.test.ts +0 -249
- package/src/RouteTree.test.ts +0 -494
- package/src/RouteTrie.test.ts +0 -322
- package/src/RouterPattern.test.ts +0 -676
- package/src/Values.test.ts +0 -263
- package/src/bun/BunBundle.test.ts +0 -268
- package/src/bun/BunBundle_imports.test.ts +0 -48
- package/src/bun/BunHttpServer.test.ts +0 -251
- package/src/bun/BunImportTrackerPlugin.test.ts +0 -77
- package/src/bun/BunRoute.test.ts +0 -162
- package/src/bundler/BundleHttp.test.ts +0 -132
- package/src/effect/HttpRouter.test.ts +0 -548
- package/src/experimental/EncryptedCookies.test.ts +0 -488
- package/src/hyper/HyperHtml.test.ts +0 -209
- package/src/hyper/HyperRoute.test.tsx +0 -197
- package/src/middlewares/BasicAuthMiddleware.test.ts +0 -84
- package/src/testing/TestHttpClient.test.ts +0 -83
- package/src/testing/TestLogger.test.ts +0 -51
- package/src/x/datastar/Datastar.test.ts +0 -266
- package/src/x/tailwind/TailwindPlugin.test.ts +0 -333
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
interface Callback<E, A> {
|
|
3
|
+
(err: E, a?: A): void;
|
|
4
|
+
}
|
|
5
|
+
type ArgsWithCallback<Args extends Array<any>, E, A> = [...args: Args, cb: Callback<E, A>];
|
|
6
|
+
type WithoutNull<A> = unknown extends A ? void : Exclude<A, null | undefined>;
|
|
7
|
+
type Effectify<T, E> = T extends {
|
|
8
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
9
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
10
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
11
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
12
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
13
|
+
(...args: ArgsWithCallback<infer Args6, infer _E6, infer A6>): infer _R6;
|
|
14
|
+
(...args: ArgsWithCallback<infer Args7, infer _E7, infer A7>): infer _R7;
|
|
15
|
+
(...args: ArgsWithCallback<infer Args8, infer _E8, infer A8>): infer _R8;
|
|
16
|
+
(...args: ArgsWithCallback<infer Args9, infer _E9, infer A9>): infer _R9;
|
|
17
|
+
(...args: ArgsWithCallback<infer Args10, infer _E10, infer A10>): infer _R10;
|
|
18
|
+
} ? {
|
|
19
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
20
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
21
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
22
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
23
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
24
|
+
(...args: Args6): Effect.Effect<WithoutNull<A6>, E>;
|
|
25
|
+
(...args: Args7): Effect.Effect<WithoutNull<A7>, E>;
|
|
26
|
+
(...args: Args8): Effect.Effect<WithoutNull<A8>, E>;
|
|
27
|
+
(...args: Args9): Effect.Effect<WithoutNull<A9>, E>;
|
|
28
|
+
(...args: Args10): Effect.Effect<WithoutNull<A10>, E>;
|
|
29
|
+
} : T extends {
|
|
30
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
31
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
32
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
33
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
34
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
35
|
+
(...args: ArgsWithCallback<infer Args6, infer _E6, infer A6>): infer _R6;
|
|
36
|
+
(...args: ArgsWithCallback<infer Args7, infer _E7, infer A7>): infer _R7;
|
|
37
|
+
(...args: ArgsWithCallback<infer Args8, infer _E8, infer A8>): infer _R8;
|
|
38
|
+
(...args: ArgsWithCallback<infer Args9, infer _E9, infer A9>): infer _R9;
|
|
39
|
+
} ? {
|
|
40
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
41
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
42
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
43
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
44
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
45
|
+
(...args: Args6): Effect.Effect<WithoutNull<A6>, E>;
|
|
46
|
+
(...args: Args7): Effect.Effect<WithoutNull<A7>, E>;
|
|
47
|
+
(...args: Args8): Effect.Effect<WithoutNull<A8>, E>;
|
|
48
|
+
(...args: Args9): Effect.Effect<WithoutNull<A9>, E>;
|
|
49
|
+
} : T extends {
|
|
50
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
51
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
52
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
53
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
54
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
55
|
+
(...args: ArgsWithCallback<infer Args6, infer _E6, infer A6>): infer _R6;
|
|
56
|
+
(...args: ArgsWithCallback<infer Args7, infer _E7, infer A7>): infer _R7;
|
|
57
|
+
(...args: ArgsWithCallback<infer Args8, infer _E8, infer A8>): infer _R8;
|
|
58
|
+
} ? {
|
|
59
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
60
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
61
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
62
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
63
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
64
|
+
(...args: Args6): Effect.Effect<WithoutNull<A6>, E>;
|
|
65
|
+
(...args: Args7): Effect.Effect<WithoutNull<A7>, E>;
|
|
66
|
+
(...args: Args8): Effect.Effect<WithoutNull<A8>, E>;
|
|
67
|
+
} : T extends {
|
|
68
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
69
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
70
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
71
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
72
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
73
|
+
(...args: ArgsWithCallback<infer Args6, infer _E6, infer A6>): infer _R6;
|
|
74
|
+
(...args: ArgsWithCallback<infer Args7, infer _E7, infer A7>): infer _R7;
|
|
75
|
+
} ? {
|
|
76
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
77
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
78
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
79
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
80
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
81
|
+
(...args: Args6): Effect.Effect<WithoutNull<A6>, E>;
|
|
82
|
+
(...args: Args7): Effect.Effect<WithoutNull<A7>, E>;
|
|
83
|
+
} : T extends {
|
|
84
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
85
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
86
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
87
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
88
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
89
|
+
(...args: ArgsWithCallback<infer Args6, infer _E6, infer A6>): infer _R6;
|
|
90
|
+
} ? {
|
|
91
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
92
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
93
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
94
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
95
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
96
|
+
(...args: Args6): Effect.Effect<WithoutNull<A6>, E>;
|
|
97
|
+
} : T extends {
|
|
98
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
99
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
100
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
101
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
102
|
+
(...args: ArgsWithCallback<infer Args5, infer _E5, infer A5>): infer _R5;
|
|
103
|
+
} ? {
|
|
104
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
105
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
106
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
107
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
108
|
+
(...args: Args5): Effect.Effect<WithoutNull<A5>, E>;
|
|
109
|
+
} : T extends {
|
|
110
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
111
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
112
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
113
|
+
(...args: ArgsWithCallback<infer Args4, infer _E4, infer A4>): infer _R4;
|
|
114
|
+
} ? {
|
|
115
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
116
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
117
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
118
|
+
(...args: Args4): Effect.Effect<WithoutNull<A4>, E>;
|
|
119
|
+
} : T extends {
|
|
120
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
121
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
122
|
+
(...args: ArgsWithCallback<infer Args3, infer _E3, infer A3>): infer _R3;
|
|
123
|
+
} ? {
|
|
124
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
125
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
126
|
+
(...args: Args3): Effect.Effect<WithoutNull<A3>, E>;
|
|
127
|
+
} : T extends {
|
|
128
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
129
|
+
(...args: ArgsWithCallback<infer Args2, infer _E2, infer A2>): infer _R2;
|
|
130
|
+
} ? {
|
|
131
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
132
|
+
(...args: Args2): Effect.Effect<WithoutNull<A2>, E>;
|
|
133
|
+
} : T extends {
|
|
134
|
+
(...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
|
|
135
|
+
} ? {
|
|
136
|
+
(...args: Args1): Effect.Effect<WithoutNull<A1>, E>;
|
|
137
|
+
} : never;
|
|
138
|
+
type EffectifyError<T> = T extends {
|
|
139
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
140
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
141
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
142
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
143
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
144
|
+
(...args: ArgsWithCallback<infer _Args6, infer E6, infer _A6>): infer _R6;
|
|
145
|
+
(...args: ArgsWithCallback<infer _Args7, infer E7, infer _A7>): infer _R7;
|
|
146
|
+
(...args: ArgsWithCallback<infer _Args8, infer E8, infer _A8>): infer _R8;
|
|
147
|
+
(...args: ArgsWithCallback<infer _Args9, infer E9, infer _A9>): infer _R9;
|
|
148
|
+
(...args: ArgsWithCallback<infer _Args10, infer E10, infer _A10>): infer _R10;
|
|
149
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 | E10> : T extends {
|
|
150
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
151
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
152
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
153
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
154
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
155
|
+
(...args: ArgsWithCallback<infer _Args6, infer E6, infer _A6>): infer _R6;
|
|
156
|
+
(...args: ArgsWithCallback<infer _Args7, infer E7, infer _A7>): infer _R7;
|
|
157
|
+
(...args: ArgsWithCallback<infer _Args8, infer E8, infer _A8>): infer _R8;
|
|
158
|
+
(...args: ArgsWithCallback<infer _Args9, infer E9, infer _A9>): infer _R9;
|
|
159
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9> : T extends {
|
|
160
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
161
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
162
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
163
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
164
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
165
|
+
(...args: ArgsWithCallback<infer _Args6, infer E6, infer _A6>): infer _R6;
|
|
166
|
+
(...args: ArgsWithCallback<infer _Args7, infer E7, infer _A7>): infer _R7;
|
|
167
|
+
(...args: ArgsWithCallback<infer _Args8, infer E8, infer _A8>): infer _R8;
|
|
168
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8> : T extends {
|
|
169
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
170
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
171
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
172
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
173
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
174
|
+
(...args: ArgsWithCallback<infer _Args6, infer E6, infer _A6>): infer _R6;
|
|
175
|
+
(...args: ArgsWithCallback<infer _Args7, infer E7, infer _A7>): infer _R7;
|
|
176
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5 | E6 | E7> : T extends {
|
|
177
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
178
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
179
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
180
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
181
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
182
|
+
(...args: ArgsWithCallback<infer _Args6, infer E6, infer _A6>): infer _R6;
|
|
183
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5 | E6> : T extends {
|
|
184
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
185
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
186
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
187
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
188
|
+
(...args: ArgsWithCallback<infer _Args5, infer E5, infer _A5>): infer _R5;
|
|
189
|
+
} ? NonNullable<E1 | E2 | E3 | E4 | E5> : T extends {
|
|
190
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
191
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
192
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
193
|
+
(...args: ArgsWithCallback<infer _Args4, infer E4, infer _A4>): infer _R4;
|
|
194
|
+
} ? NonNullable<E1 | E2 | E3 | E4> : T extends {
|
|
195
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
196
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
197
|
+
(...args: ArgsWithCallback<infer _Args3, infer E3, infer _A3>): infer _R3;
|
|
198
|
+
} ? NonNullable<E1 | E2 | E3> : T extends {
|
|
199
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
200
|
+
(...args: ArgsWithCallback<infer _Args2, infer E2, infer _A2>): infer _R2;
|
|
201
|
+
} ? NonNullable<E1 | E2> : T extends {
|
|
202
|
+
(...args: ArgsWithCallback<infer _Args1, infer E1, infer _A1>): infer _R1;
|
|
203
|
+
} ? NonNullable<E1> : never;
|
|
204
|
+
export declare const effectify: {
|
|
205
|
+
<F extends (...args: Array<any>) => any>(fn: F): Effectify<F, EffectifyError<F>>;
|
|
206
|
+
<F extends (...args: Array<any>) => any, E>(fn: F, onError: (error: EffectifyError<F>, args: Parameters<F>) => E): Effectify<F, E>;
|
|
207
|
+
<F extends (...args: Array<any>) => any, E, E2>(fn: F, onError: (error: EffectifyError<F>, args: Parameters<F>) => E, onSyncError: (error: unknown, args: Parameters<F>) => E2): Effectify<F, E | E2>;
|
|
208
|
+
};
|
|
209
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Adapted from @effect/platform
|
|
3
|
+
*/
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
export const effectify = ((fn, onError, onSyncError) => (...args) => Effect.async((resume) => {
|
|
6
|
+
try {
|
|
7
|
+
fn(...args, (err, result) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
resume(Effect.fail(onError ? onError(err, args) : err));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resume(Effect.succeed(result));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
resume(onSyncError ? Effect.fail(onSyncError(err, args)) : Effect.die(err));
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as Error from "@effect/platform/Error";
|
|
2
|
-
import type { PlatformError } from "@effect/platform/Error";
|
|
3
|
-
import { SystemError } from "@effect/platform/Error";
|
|
4
1
|
import * as FileSystem from "@effect/platform/FileSystem";
|
|
5
2
|
import * as Layer from "effect/Layer";
|
|
6
3
|
import * as NFS from "node:fs";
|
|
4
|
+
import * as PlatformError from "./PlatformError.ts";
|
|
7
5
|
export declare const layer: Layer.Layer<FileSystem.FileSystem, never, never>;
|
|
8
|
-
export {
|
|
9
|
-
export declare function handleErrnoException(module: SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError;
|
|
6
|
+
export { FileSystem, PlatformError as Error, };
|
|
7
|
+
export declare function handleErrnoException(module: PlatformError.SystemError["module"], method: string): (err: NodeJS.ErrnoException, [path]: [path: NFS.PathLike | number, ...args: Array<any>]) => PlatformError.PlatformError;
|
package/dist/node/FileSystem.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Adapted from @effect/platform
|
|
3
3
|
*/
|
|
4
|
-
import { effectify } from "@effect/platform/Effectify";
|
|
5
|
-
import * as Error from "@effect/platform/Error";
|
|
6
|
-
import { SystemError } from "@effect/platform/Error";
|
|
7
4
|
import * as FileSystem from "@effect/platform/FileSystem";
|
|
8
5
|
import * as Effect from "effect/Effect";
|
|
9
|
-
import
|
|
6
|
+
import * as Function from "effect/Function";
|
|
10
7
|
import * as Layer from "effect/Layer";
|
|
11
8
|
import * as Option from "effect/Option";
|
|
12
9
|
import * as Stream from "effect/Stream";
|
|
13
|
-
import * as
|
|
10
|
+
import * as NCrypto from "node:crypto";
|
|
14
11
|
import * as NFS from "node:fs";
|
|
15
12
|
import * as NOS from "node:os";
|
|
16
13
|
import * as NPath from "node:path";
|
|
17
|
-
|
|
14
|
+
import * as Effectify from "./Effectify.js";
|
|
15
|
+
import * as PlatformError from "./PlatformError.js";
|
|
16
|
+
const handleBadArgument = (method) => (cause) => new PlatformError.BadArgument({
|
|
18
17
|
module: "FileSystem",
|
|
19
18
|
method,
|
|
20
19
|
cause,
|
|
21
20
|
});
|
|
22
|
-
// == access
|
|
23
21
|
const access = (() => {
|
|
24
|
-
const nodeAccess = effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
|
|
22
|
+
const nodeAccess = Effectify.effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
|
|
25
23
|
return (path, options) => {
|
|
26
24
|
let mode = NFS.constants.F_OK;
|
|
27
25
|
if (options?.readable) {
|
|
@@ -33,46 +31,39 @@ const access = (() => {
|
|
|
33
31
|
return nodeAccess(path, mode);
|
|
34
32
|
};
|
|
35
33
|
})();
|
|
36
|
-
// == copy
|
|
37
34
|
const copy = (() => {
|
|
38
|
-
const nodeCp = effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
|
|
35
|
+
const nodeCp = Effectify.effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
|
|
39
36
|
return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
|
|
40
37
|
force: options?.overwrite ?? false,
|
|
41
38
|
preserveTimestamps: options?.preserveTimestamps ?? false,
|
|
42
39
|
recursive: true,
|
|
43
40
|
});
|
|
44
41
|
})();
|
|
45
|
-
// == copyFile
|
|
46
42
|
const copyFile = (() => {
|
|
47
|
-
const nodeCopyFile = effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
|
|
43
|
+
const nodeCopyFile = Effectify.effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
|
|
48
44
|
return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
|
|
49
45
|
})();
|
|
50
|
-
// == chmod
|
|
51
46
|
const chmod = (() => {
|
|
52
|
-
const nodeChmod = effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
|
|
47
|
+
const nodeChmod = Effectify.effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
|
|
53
48
|
return (path, mode) => nodeChmod(path, mode);
|
|
54
49
|
})();
|
|
55
|
-
// == chown
|
|
56
50
|
const chown = (() => {
|
|
57
|
-
const nodeChown = effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
|
|
51
|
+
const nodeChown = Effectify.effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
|
|
58
52
|
return (path, uid, gid) => nodeChown(path, uid, gid);
|
|
59
53
|
})();
|
|
60
|
-
// == link
|
|
61
54
|
const link = (() => {
|
|
62
|
-
const nodeLink = effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
|
|
55
|
+
const nodeLink = Effectify.effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
|
|
63
56
|
return (existingPath, newPath) => nodeLink(existingPath, newPath);
|
|
64
57
|
})();
|
|
65
|
-
// == makeDirectory
|
|
66
58
|
const makeDirectory = (() => {
|
|
67
|
-
const nodeMkdir = effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
|
|
59
|
+
const nodeMkdir = Effectify.effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
|
|
68
60
|
return (path, options) => nodeMkdir(path, {
|
|
69
61
|
recursive: options?.recursive ?? false,
|
|
70
62
|
mode: options?.mode,
|
|
71
63
|
});
|
|
72
64
|
})();
|
|
73
|
-
// == makeTempDirectory
|
|
74
65
|
const makeTempDirectoryFactory = (method) => {
|
|
75
|
-
const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
66
|
+
const nodeMkdtemp = Effectify.effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
76
67
|
return (options) => Effect.suspend(() => {
|
|
77
68
|
const prefix = options?.prefix ?? "";
|
|
78
69
|
const directory = typeof options?.directory === "string"
|
|
@@ -82,36 +73,33 @@ const makeTempDirectoryFactory = (method) => {
|
|
|
82
73
|
});
|
|
83
74
|
};
|
|
84
75
|
const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory");
|
|
85
|
-
// == remove
|
|
86
76
|
const removeFactory = (method) => {
|
|
87
|
-
const nodeRm = effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
77
|
+
const nodeRm = Effectify.effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
88
78
|
return (path, options) => nodeRm(path, {
|
|
89
79
|
recursive: options?.recursive ?? false,
|
|
90
80
|
force: options?.force ?? false,
|
|
91
81
|
});
|
|
92
82
|
};
|
|
93
83
|
const remove = removeFactory("remove");
|
|
94
|
-
// == makeTempDirectoryScoped
|
|
95
84
|
const makeTempDirectoryScoped = (() => {
|
|
96
85
|
const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped");
|
|
97
86
|
const removeDirectory = removeFactory("makeTempDirectoryScoped");
|
|
98
87
|
return (options) => Effect.acquireRelease(makeDirectory(options), (directory) => Effect.orDie(removeDirectory(directory, { recursive: true })));
|
|
99
88
|
})();
|
|
100
|
-
// == open
|
|
101
89
|
const openFactory = (method) => {
|
|
102
|
-
const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
103
|
-
const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
104
|
-
return (path, options) => pipe(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect.orDie(nodeClose(fd))), Effect.map((fd) => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
|
|
90
|
+
const nodeOpen = Effectify.effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
91
|
+
const nodeClose = Effectify.effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
92
|
+
return (path, options) => Function.pipe(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect.orDie(nodeClose(fd))), Effect.map((fd) => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
|
|
105
93
|
};
|
|
106
94
|
const open = openFactory("open");
|
|
107
95
|
const makeFile = (() => {
|
|
108
|
-
const nodeReadFactory = (method) => effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
96
|
+
const nodeReadFactory = (method) => Effectify.effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
109
97
|
const nodeRead = nodeReadFactory("read");
|
|
110
98
|
const nodeReadAlloc = nodeReadFactory("readAlloc");
|
|
111
|
-
const nodeStat = effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
|
|
112
|
-
const nodeTruncate = effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
|
|
113
|
-
const nodeSync = effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
|
|
114
|
-
const nodeWriteFactory = (method) => effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
99
|
+
const nodeStat = Effectify.effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
|
|
100
|
+
const nodeTruncate = Effectify.effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
|
|
101
|
+
const nodeSync = Effectify.effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
|
|
102
|
+
const nodeWriteFactory = (method) => Effectify.effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
115
103
|
const nodeWrite = nodeWriteFactory("write");
|
|
116
104
|
const nodeWriteAll = nodeWriteFactory("writeAll");
|
|
117
105
|
class FileImpl {
|
|
@@ -193,7 +181,7 @@ const makeFile = (() => {
|
|
|
193
181
|
writeAllChunk(buffer) {
|
|
194
182
|
return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
|
|
195
183
|
if (bytesWritten === 0) {
|
|
196
|
-
return Effect.fail(new
|
|
184
|
+
return Effect.fail(new PlatformError.SystemError({
|
|
197
185
|
module: "FileSystem",
|
|
198
186
|
method: "writeAll",
|
|
199
187
|
reason: "WriteZero",
|
|
@@ -215,26 +203,22 @@ const makeFile = (() => {
|
|
|
215
203
|
}
|
|
216
204
|
return (fd, append) => new FileImpl(fd, append);
|
|
217
205
|
})();
|
|
218
|
-
// == makeTempFile
|
|
219
206
|
const makeTempFileFactory = (method) => {
|
|
220
207
|
const makeDirectory = makeTempDirectoryFactory(method);
|
|
221
208
|
const open = openFactory(method);
|
|
222
|
-
const randomHexString = (bytes) => Effect.sync(() =>
|
|
223
|
-
return (options) => pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))));
|
|
209
|
+
const randomHexString = (bytes) => Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"));
|
|
210
|
+
return (options) => Function.pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))));
|
|
224
211
|
};
|
|
225
212
|
const makeTempFile = makeTempFileFactory("makeTempFile");
|
|
226
|
-
// == makeTempFileScoped
|
|
227
213
|
const makeTempFileScoped = (() => {
|
|
228
214
|
const makeFile = makeTempFileFactory("makeTempFileScoped");
|
|
229
215
|
const removeDirectory = removeFactory("makeTempFileScoped");
|
|
230
216
|
return (options) => Effect.acquireRelease(makeFile(options), (file) => Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })));
|
|
231
217
|
})();
|
|
232
|
-
// == readDirectory
|
|
233
218
|
const readDirectory = (path, options) => Effect.tryPromise({
|
|
234
219
|
try: () => NFS.promises.readdir(path, options),
|
|
235
220
|
catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path]),
|
|
236
221
|
});
|
|
237
|
-
// == readFile
|
|
238
222
|
const readFile = (path) => Effect.async((resume, signal) => {
|
|
239
223
|
try {
|
|
240
224
|
NFS.readFile(path, { signal }, (err, data) => {
|
|
@@ -250,22 +234,18 @@ const readFile = (path) => Effect.async((resume, signal) => {
|
|
|
250
234
|
resume(Effect.fail(handleBadArgument("readFile")(err)));
|
|
251
235
|
}
|
|
252
236
|
});
|
|
253
|
-
// == readLink
|
|
254
237
|
const readLink = (() => {
|
|
255
|
-
const nodeReadLink = effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
|
|
238
|
+
const nodeReadLink = Effectify.effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
|
|
256
239
|
return (path) => nodeReadLink(path);
|
|
257
240
|
})();
|
|
258
|
-
// == realPath
|
|
259
241
|
const realPath = (() => {
|
|
260
|
-
const nodeRealPath = effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
|
|
242
|
+
const nodeRealPath = Effectify.effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
|
|
261
243
|
return (path) => nodeRealPath(path);
|
|
262
244
|
})();
|
|
263
|
-
// == rename
|
|
264
245
|
const rename = (() => {
|
|
265
|
-
const nodeRename = effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
|
|
246
|
+
const nodeRename = Effectify.effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
|
|
266
247
|
return (oldPath, newPath) => nodeRename(oldPath, newPath);
|
|
267
248
|
})();
|
|
268
|
-
// == stat
|
|
269
249
|
const makeFileInfo = (stat) => ({
|
|
270
250
|
type: stat.isFile()
|
|
271
251
|
? "File"
|
|
@@ -297,25 +277,21 @@ const makeFileInfo = (stat) => ({
|
|
|
297
277
|
blocks: Option.fromNullable(stat.blocks),
|
|
298
278
|
});
|
|
299
279
|
const stat = (() => {
|
|
300
|
-
const nodeStat = effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
|
|
280
|
+
const nodeStat = Effectify.effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
|
|
301
281
|
return (path) => Effect.map(nodeStat(path), makeFileInfo);
|
|
302
282
|
})();
|
|
303
|
-
// == symlink
|
|
304
283
|
const symlink = (() => {
|
|
305
|
-
const nodeSymlink = effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
|
|
284
|
+
const nodeSymlink = Effectify.effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
|
|
306
285
|
return (target, path) => nodeSymlink(target, path);
|
|
307
286
|
})();
|
|
308
|
-
// == truncate
|
|
309
287
|
const truncate = (() => {
|
|
310
|
-
const nodeTruncate = effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
|
|
288
|
+
const nodeTruncate = Effectify.effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
|
|
311
289
|
return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);
|
|
312
290
|
})();
|
|
313
|
-
// == utimes
|
|
314
291
|
const utimes = (() => {
|
|
315
|
-
const nodeUtimes = effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
|
|
292
|
+
const nodeUtimes = Effectify.effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
|
|
316
293
|
return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
|
|
317
294
|
})();
|
|
318
|
-
// == watch
|
|
319
295
|
const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquireRelease(Effect.sync(() => {
|
|
320
296
|
const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
|
|
321
297
|
if (!path)
|
|
@@ -337,7 +313,7 @@ const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquire
|
|
|
337
313
|
}
|
|
338
314
|
});
|
|
339
315
|
watcher.on("error", (error) => {
|
|
340
|
-
emit.fail(new
|
|
316
|
+
emit.fail(new PlatformError.SystemError({
|
|
341
317
|
module: "FileSystem",
|
|
342
318
|
reason: "Unknown",
|
|
343
319
|
method: "watch",
|
|
@@ -351,7 +327,6 @@ const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquire
|
|
|
351
327
|
return watcher;
|
|
352
328
|
}), (watcher) => Effect.sync(() => watcher.close())));
|
|
353
329
|
const watch = (backend, path, options) => stat(path).pipe(Effect.map((stat) => backend.pipe(Option.flatMap((_) => _.register(path, stat, options)), Option.getOrElse(() => watchNode(path, options)))), Stream.unwrap);
|
|
354
|
-
// == writeFile
|
|
355
330
|
const writeFile = (path, data, options) => Effect.async((resume, signal) => {
|
|
356
331
|
try {
|
|
357
332
|
NFS.writeFile(path, data, {
|
|
@@ -371,7 +346,7 @@ const writeFile = (path, data, options) => Effect.async((resume, signal) => {
|
|
|
371
346
|
resume(Effect.fail(handleBadArgument("writeFile")(err)));
|
|
372
347
|
}
|
|
373
348
|
});
|
|
374
|
-
const
|
|
349
|
+
const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
|
|
375
350
|
access,
|
|
376
351
|
chmod,
|
|
377
352
|
chown,
|
|
@@ -399,8 +374,13 @@ const makeFileSystem = Effect.map(Effect.serviceOption(FileSystem.WatchBackend),
|
|
|
399
374
|
},
|
|
400
375
|
writeFile,
|
|
401
376
|
}));
|
|
402
|
-
export const layer = Layer.
|
|
403
|
-
|
|
377
|
+
export const layer = Layer.unwrapEffect(Effect
|
|
378
|
+
.gen(function* () {
|
|
379
|
+
const mod = yield* Effect.tryPromise(() => import("@effect/platform/FileSystem"));
|
|
380
|
+
return Layer.effect(mod.FileSystem, make);
|
|
381
|
+
})
|
|
382
|
+
.pipe(Effect.catchAll(() => Effect.die(new globalThis.Error("@effect/platform is not installed")))));
|
|
383
|
+
export { FileSystem, PlatformError as Error, };
|
|
404
384
|
export function handleErrnoException(module, method) {
|
|
405
385
|
return function (err, [path]) {
|
|
406
386
|
let reason = "Unknown";
|
|
@@ -427,7 +407,7 @@ export function handleErrnoException(module, method) {
|
|
|
427
407
|
reason = "BadResource";
|
|
428
408
|
break;
|
|
429
409
|
}
|
|
430
|
-
return new SystemError({
|
|
410
|
+
return new PlatformError.SystemError({
|
|
431
411
|
reason,
|
|
432
412
|
module,
|
|
433
413
|
method,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type * as Cause from "effect/Cause";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import type * as Types from "effect/Types";
|
|
4
|
+
import { TypeId as TypeId_ } from "@effect/platform/Error";
|
|
5
|
+
export declare const TypeId: typeof TypeId_;
|
|
6
|
+
export type TypeId = typeof TypeId;
|
|
7
|
+
export declare const isPlatformError: (u: unknown) => u is PlatformError;
|
|
8
|
+
export declare const TypeIdError: <const TypeId extends symbol, const Tag extends string>(typeId: TypeId, tag: Tag) => new <A extends Record<string, any>>(args: Types.Simplify<A>) => Cause.YieldableError & Record<TypeId, TypeId> & {
|
|
9
|
+
readonly _tag: Tag;
|
|
10
|
+
} & Readonly<A>;
|
|
11
|
+
export declare const Module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
|
|
12
|
+
declare const BadArgument_base: Schema.TaggedErrorClass<BadArgument, "BadArgument", {
|
|
13
|
+
readonly _tag: Schema.tag<"BadArgument">;
|
|
14
|
+
} & {
|
|
15
|
+
module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
|
|
16
|
+
method: typeof Schema.String;
|
|
17
|
+
description: Schema.optional<typeof Schema.String>;
|
|
18
|
+
cause: Schema.optional<typeof Schema.Defect>;
|
|
19
|
+
}>;
|
|
20
|
+
export declare class BadArgument extends BadArgument_base {
|
|
21
|
+
readonly [TypeId]: typeof TypeId;
|
|
22
|
+
get message(): string;
|
|
23
|
+
}
|
|
24
|
+
export declare const SystemErrorReason: Schema.Literal<["AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero"]>;
|
|
25
|
+
export type SystemErrorReason = typeof SystemErrorReason.Type;
|
|
26
|
+
declare const SystemError_base: Schema.TaggedErrorClass<SystemError, "SystemError", {
|
|
27
|
+
readonly _tag: Schema.tag<"SystemError">;
|
|
28
|
+
} & {
|
|
29
|
+
reason: Schema.Literal<["AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero"]>;
|
|
30
|
+
module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
|
|
31
|
+
method: typeof Schema.String;
|
|
32
|
+
description: Schema.optional<typeof Schema.String>;
|
|
33
|
+
syscall: Schema.optional<typeof Schema.String>;
|
|
34
|
+
pathOrDescriptor: Schema.optional<Schema.Union<[typeof Schema.String, typeof Schema.Number]>>;
|
|
35
|
+
cause: Schema.optional<typeof Schema.Defect>;
|
|
36
|
+
}>;
|
|
37
|
+
export declare class SystemError extends SystemError_base {
|
|
38
|
+
readonly [TypeId]: typeof TypeId;
|
|
39
|
+
get message(): string;
|
|
40
|
+
}
|
|
41
|
+
export type PlatformError = BadArgument | SystemError;
|
|
42
|
+
export declare const PlatformError: Schema.Union<[
|
|
43
|
+
typeof BadArgument,
|
|
44
|
+
typeof SystemError
|
|
45
|
+
]>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Data from "effect/Data";
|
|
2
|
+
import * as Predicate from "effect/Predicate";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { TypeId as TypeId_ } from "@effect/platform/Error";
|
|
5
|
+
export const TypeId = TypeId_;
|
|
6
|
+
export const isPlatformError = (u) => Predicate.hasProperty(u, TypeId);
|
|
7
|
+
export const TypeIdError = (typeId, tag) => {
|
|
8
|
+
class Base extends Data.Error {
|
|
9
|
+
_tag = tag;
|
|
10
|
+
}
|
|
11
|
+
;
|
|
12
|
+
Base.prototype[typeId] = typeId;
|
|
13
|
+
Base.prototype.name = tag;
|
|
14
|
+
return Base;
|
|
15
|
+
};
|
|
16
|
+
export const Module = Schema.Literal("Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal");
|
|
17
|
+
export class BadArgument extends Schema.TaggedError("@effect/platform/Error/BadArgument")("BadArgument", {
|
|
18
|
+
module: Module,
|
|
19
|
+
method: Schema.String,
|
|
20
|
+
description: Schema.optional(Schema.String),
|
|
21
|
+
cause: Schema.optional(Schema.Defect),
|
|
22
|
+
}) {
|
|
23
|
+
[TypeId] = TypeId;
|
|
24
|
+
get message() {
|
|
25
|
+
return `${this.module}.${this.method}${this.description ? `: ${this.description}` : ""}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const SystemErrorReason = Schema.Literal("AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero");
|
|
29
|
+
export class SystemError extends Schema.TaggedError("@effect/platform/Error/SystemError")("SystemError", {
|
|
30
|
+
reason: SystemErrorReason,
|
|
31
|
+
module: Module,
|
|
32
|
+
method: Schema.String,
|
|
33
|
+
description: Schema.optional(Schema.String),
|
|
34
|
+
syscall: Schema.optional(Schema.String),
|
|
35
|
+
pathOrDescriptor: Schema.optional(Schema.Union(Schema.String, Schema.Number)),
|
|
36
|
+
cause: Schema.optional(Schema.Defect),
|
|
37
|
+
}) {
|
|
38
|
+
[TypeId] = TypeId;
|
|
39
|
+
get message() {
|
|
40
|
+
return `${this.reason}: ${this.module}.${this.method}${this.pathOrDescriptor !== undefined ? ` (${this.pathOrDescriptor})` : ""}${this.description ? `: ${this.description}` : ""}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const PlatformError = Schema.Union(BadArgument, SystemError);
|
|
@@ -15,7 +15,7 @@ export function layer() {
|
|
|
15
15
|
const mutableRef = messages.ref;
|
|
16
16
|
const customLogger = Logger.make(({ message, logLevel, cause }) => {
|
|
17
17
|
const causeStr = !Cause.isEmpty(cause)
|
|
18
|
-
? ` ${Cause.pretty(cause)}`
|
|
18
|
+
? ` ${Cause.pretty(cause, { renderErrorCause: true })}`
|
|
19
19
|
: "";
|
|
20
20
|
MutableRef.update(mutableRef, (msgs) => [...msgs, `[${logLevel._tag}] ${String(message)}${causeStr}`]);
|
|
21
21
|
});
|