effect-start 0.25.0 → 0.27.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 (174) hide show
  1. package/package.json +20 -86
  2. package/src/Entity.ts +6 -6
  3. package/src/FileRouterCodegen.ts +4 -4
  4. package/src/FileSystem.ts +4 -8
  5. package/src/RouteHook.ts +1 -1
  6. package/src/RouteSse.ts +3 -3
  7. package/src/SqlIntrospect.ts +2 -2
  8. package/src/Start.ts +102 -2
  9. package/src/Values.ts +11 -0
  10. package/src/bun/BunRoute.ts +1 -1
  11. package/src/bun/BunRuntime.ts +5 -5
  12. package/src/hyper/HyperHtml.ts +11 -7
  13. package/src/hyper/jsx.d.ts +1 -1
  14. package/src/lint/plugin.js +174 -4
  15. package/src/sql/SqlClient.ts +355 -0
  16. package/src/sql/bun/index.ts +117 -50
  17. package/src/sql/index.ts +1 -1
  18. package/src/sql/libsql/index.ts +91 -77
  19. package/src/sql/libsql/libsql.d.ts +4 -1
  20. package/src/sql/mssql/index.ts +141 -108
  21. package/src/sql/mssql/mssql.d.ts +1 -0
  22. package/src/testing/TestLogger.ts +4 -4
  23. package/src/x/tailwind/compile.ts +6 -14
  24. package/dist/ChildProcess.js +0 -42
  25. package/dist/Commander.js +0 -410
  26. package/dist/ContentNegotiation.js +0 -465
  27. package/dist/Cookies.js +0 -371
  28. package/dist/Development.js +0 -94
  29. package/dist/Effectify.js +0 -27
  30. package/dist/Entity.js +0 -289
  31. package/dist/Fetch.js +0 -192
  32. package/dist/FilePathPattern.js +0 -97
  33. package/dist/FileRouter.js +0 -204
  34. package/dist/FileRouterCodegen.js +0 -298
  35. package/dist/FileSystem.js +0 -132
  36. package/dist/Http.js +0 -107
  37. package/dist/PathPattern.js +0 -451
  38. package/dist/PlatformError.js +0 -40
  39. package/dist/PlatformRuntime.js +0 -71
  40. package/dist/Route.js +0 -143
  41. package/dist/RouteBody.js +0 -92
  42. package/dist/RouteError.js +0 -76
  43. package/dist/RouteHook.js +0 -64
  44. package/dist/RouteHttp.js +0 -367
  45. package/dist/RouteHttpTracer.js +0 -90
  46. package/dist/RouteMount.js +0 -86
  47. package/dist/RouteSchema.js +0 -271
  48. package/dist/RouteSse.js +0 -94
  49. package/dist/RouteTree.js +0 -119
  50. package/dist/RouteTrie.js +0 -179
  51. package/dist/SchemaExtra.js +0 -99
  52. package/dist/Socket.js +0 -40
  53. package/dist/SqlIntrospect.js +0 -515
  54. package/dist/Start.js +0 -79
  55. package/dist/StartApp.js +0 -3
  56. package/dist/StreamExtra.js +0 -135
  57. package/dist/System.js +0 -38
  58. package/dist/TuplePathPattern.js +0 -74
  59. package/dist/Unique.js +0 -226
  60. package/dist/Values.js +0 -52
  61. package/dist/bun/BunBundle.js +0 -186
  62. package/dist/bun/BunChildProcessSpawner.js +0 -142
  63. package/dist/bun/BunImportTrackerPlugin.js +0 -91
  64. package/dist/bun/BunRoute.js +0 -157
  65. package/dist/bun/BunRuntime.js +0 -41
  66. package/dist/bun/BunServer.js +0 -285
  67. package/dist/bun/BunVirtualFilesPlugin.js +0 -54
  68. package/dist/bun/_BunEnhancedResolve.js +0 -127
  69. package/dist/bun/index.js +0 -5
  70. package/dist/bundler/Bundle.js +0 -92
  71. package/dist/bundler/BundleFiles.js +0 -154
  72. package/dist/bundler/BundleRoute.js +0 -62
  73. package/dist/client/Overlay.js +0 -33
  74. package/dist/client/ScrollState.js +0 -106
  75. package/dist/client/index.js +0 -97
  76. package/dist/console/Console.js +0 -42
  77. package/dist/console/ConsoleErrors.js +0 -211
  78. package/dist/console/ConsoleLogger.js +0 -56
  79. package/dist/console/ConsoleMetrics.js +0 -72
  80. package/dist/console/ConsoleProcess.js +0 -59
  81. package/dist/console/ConsoleStore.js +0 -72
  82. package/dist/console/ConsoleTracer.js +0 -107
  83. package/dist/console/Simulation.js +0 -784
  84. package/dist/console/index.js +0 -3
  85. package/dist/console/routes/tree.js +0 -30
  86. package/dist/datastar/actions/fetch.js +0 -536
  87. package/dist/datastar/actions/peek.js +0 -13
  88. package/dist/datastar/actions/setAll.js +0 -19
  89. package/dist/datastar/actions/toggleAll.js +0 -19
  90. package/dist/datastar/attributes/attr.js +0 -49
  91. package/dist/datastar/attributes/bind.js +0 -194
  92. package/dist/datastar/attributes/class.js +0 -54
  93. package/dist/datastar/attributes/computed.js +0 -25
  94. package/dist/datastar/attributes/effect.js +0 -10
  95. package/dist/datastar/attributes/indicator.js +0 -33
  96. package/dist/datastar/attributes/init.js +0 -27
  97. package/dist/datastar/attributes/jsonSignals.js +0 -33
  98. package/dist/datastar/attributes/on.js +0 -81
  99. package/dist/datastar/attributes/onIntersect.js +0 -53
  100. package/dist/datastar/attributes/onInterval.js +0 -31
  101. package/dist/datastar/attributes/onSignalPatch.js +0 -51
  102. package/dist/datastar/attributes/ref.js +0 -11
  103. package/dist/datastar/attributes/show.js +0 -32
  104. package/dist/datastar/attributes/signals.js +0 -18
  105. package/dist/datastar/attributes/style.js +0 -57
  106. package/dist/datastar/attributes/text.js +0 -29
  107. package/dist/datastar/engine.js +0 -1145
  108. package/dist/datastar/index.js +0 -25
  109. package/dist/datastar/utils.js +0 -250
  110. package/dist/datastar/watchers/patchElements.js +0 -486
  111. package/dist/datastar/watchers/patchSignals.js +0 -14
  112. package/dist/experimental/EncryptedCookies.js +0 -328
  113. package/dist/experimental/index.js +0 -1
  114. package/dist/hyper/Hyper.js +0 -28
  115. package/dist/hyper/HyperHtml.js +0 -165
  116. package/dist/hyper/HyperNode.js +0 -13
  117. package/dist/hyper/HyperRoute.js +0 -45
  118. package/dist/hyper/html.js +0 -30
  119. package/dist/hyper/index.js +0 -5
  120. package/dist/hyper/jsx-runtime.js +0 -14
  121. package/dist/index.js +0 -8
  122. package/dist/node/NodeFileSystem.js +0 -675
  123. package/dist/node/NodeUtils.js +0 -23
  124. package/dist/sql/Sql.js +0 -8
  125. package/dist/sql/bun/index.js +0 -142
  126. package/dist/sql/index.js +0 -1
  127. package/dist/sql/libsql/index.js +0 -156
  128. package/dist/sql/mssql/docker.js +0 -110
  129. package/dist/sql/mssql/index.js +0 -194
  130. package/dist/testing/TestLogger.js +0 -42
  131. package/dist/testing/index.js +0 -2
  132. package/dist/testing/utils.js +0 -61
  133. package/dist/x/cloudflare/CloudflareTunnel.js +0 -63
  134. package/dist/x/cloudflare/index.js +0 -1
  135. package/dist/x/tailscale/TailscaleTunnel.js +0 -94
  136. package/dist/x/tailscale/index.js +0 -1
  137. package/dist/x/tailwind/TailwindPlugin.js +0 -294
  138. package/dist/x/tailwind/compile.js +0 -210
  139. package/dist/x/tailwind/plugin.js +0 -17
  140. package/src/console/Console.ts +0 -42
  141. package/src/console/ConsoleErrors.ts +0 -213
  142. package/src/console/ConsoleLogger.ts +0 -56
  143. package/src/console/ConsoleMetrics.ts +0 -72
  144. package/src/console/ConsoleProcess.ts +0 -59
  145. package/src/console/ConsoleStore.ts +0 -187
  146. package/src/console/ConsoleTracer.ts +0 -107
  147. package/src/console/Simulation.ts +0 -814
  148. package/src/console/console.html +0 -340
  149. package/src/console/index.ts +0 -3
  150. package/src/console/routes/errors/route.tsx +0 -97
  151. package/src/console/routes/fiberDetail.tsx +0 -54
  152. package/src/console/routes/fibers/route.tsx +0 -45
  153. package/src/console/routes/git/route.tsx +0 -64
  154. package/src/console/routes/layout.tsx +0 -4
  155. package/src/console/routes/logs/route.tsx +0 -77
  156. package/src/console/routes/metrics/route.tsx +0 -36
  157. package/src/console/routes/route.tsx +0 -8
  158. package/src/console/routes/routes/route.tsx +0 -30
  159. package/src/console/routes/services/route.tsx +0 -21
  160. package/src/console/routes/system/route.tsx +0 -43
  161. package/src/console/routes/traceDetail.tsx +0 -22
  162. package/src/console/routes/traces/route.tsx +0 -81
  163. package/src/console/routes/tree.ts +0 -30
  164. package/src/console/ui/Errors.tsx +0 -76
  165. package/src/console/ui/Fibers.tsx +0 -321
  166. package/src/console/ui/Git.tsx +0 -182
  167. package/src/console/ui/Logs.tsx +0 -46
  168. package/src/console/ui/Metrics.tsx +0 -78
  169. package/src/console/ui/Routes.tsx +0 -125
  170. package/src/console/ui/Services.tsx +0 -273
  171. package/src/console/ui/Shell.tsx +0 -62
  172. package/src/console/ui/System.tsx +0 -131
  173. package/src/console/ui/Traces.tsx +0 -426
  174. package/src/sql/Sql.ts +0 -51
@@ -1,675 +0,0 @@
1
- /*
2
- * Adapted from @effect/platform
3
- */
4
- import * as Effect from "effect/Effect"
5
- import * as Function from "effect/Function"
6
- import * as Layer from "effect/Layer"
7
- import * as Option from "effect/Option"
8
- import * as FileSystem from "../FileSystem.js"
9
- import * as Stream from "effect/Stream"
10
- import * as NCrypto from "node:crypto"
11
- import * as NFS from "node:fs"
12
- import * as NOS from "node:os"
13
- import * as NPath from "node:path"
14
- import * as PlatformError from "../PlatformError.js"
15
- import * as Effectify from "../Effectify.js"
16
-
17
- const handleBadArgument = (method) => (cause) =>
18
- new PlatformError.BadArgument({
19
- module: "FileSystem",
20
- method,
21
- cause,
22
- })
23
-
24
- const access = (() => {
25
- const nodeAccess = Effectify.effectify(
26
- NFS.access,
27
- handleErrnoException("FileSystem", "access"),
28
- handleBadArgument("access"),
29
- )
30
- return (path, options) => {
31
- let mode = NFS.constants.F_OK
32
- if (options?.readable) {
33
- mode |= NFS.constants.R_OK
34
- }
35
- if (options?.writable) {
36
- mode |= NFS.constants.W_OK
37
- }
38
- return nodeAccess(path, mode)
39
- }
40
- })()
41
-
42
- const copy = (() => {
43
- const nodeCp = Effectify.effectify(
44
- NFS.cp,
45
- handleErrnoException("FileSystem", "copy"),
46
- handleBadArgument("copy"),
47
- )
48
- return (fromPath, toPath, options) =>
49
- nodeCp(fromPath, toPath, {
50
- force: options?.overwrite ?? false,
51
- preserveTimestamps: options?.preserveTimestamps ?? false,
52
- recursive: true,
53
- })
54
- })()
55
-
56
- const copyFile = (() => {
57
- const nodeCopyFile = Effectify.effectify(
58
- NFS.copyFile,
59
- handleErrnoException("FileSystem", "copyFile"),
60
- handleBadArgument("copyFile"),
61
- )
62
- return (fromPath, toPath) => nodeCopyFile(fromPath, toPath)
63
- })()
64
-
65
- const chmod = (() => {
66
- const nodeChmod = Effectify.effectify(
67
- NFS.chmod,
68
- handleErrnoException("FileSystem", "chmod"),
69
- handleBadArgument("chmod"),
70
- )
71
- return (path, mode) => nodeChmod(path, mode)
72
- })()
73
-
74
- const chown = (() => {
75
- const nodeChown = Effectify.effectify(
76
- NFS.chown,
77
- handleErrnoException("FileSystem", "chown"),
78
- handleBadArgument("chown"),
79
- )
80
- return (path, uid, gid) => nodeChown(path, uid, gid)
81
- })()
82
-
83
- const link = (() => {
84
- const nodeLink = Effectify.effectify(
85
- NFS.link,
86
- handleErrnoException("FileSystem", "link"),
87
- handleBadArgument("link"),
88
- )
89
- return (existingPath, newPath) => nodeLink(existingPath, newPath)
90
- })()
91
-
92
- const makeDirectory = (() => {
93
- const nodeMkdir = Effectify.effectify(
94
- NFS.mkdir,
95
- handleErrnoException("FileSystem", "makeDirectory"),
96
- handleBadArgument("makeDirectory"),
97
- )
98
- return (path, options) =>
99
- nodeMkdir(path, {
100
- recursive: options?.recursive ?? false,
101
- mode: options?.mode,
102
- })
103
- })()
104
-
105
- const makeTempDirectoryFactory = (method) => {
106
- const nodeMkdtemp = Effectify.effectify(
107
- NFS.mkdtemp,
108
- handleErrnoException("FileSystem", method),
109
- handleBadArgument(method),
110
- )
111
- return (options) =>
112
- Effect.suspend(() => {
113
- const prefix = options?.prefix ?? ""
114
- const directory =
115
- typeof options?.directory === "string" ? NPath.join(options.directory, ".") : NOS.tmpdir()
116
-
117
- return nodeMkdtemp(prefix ? NPath.join(directory, prefix) : directory + "/")
118
- })
119
- }
120
- const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory")
121
-
122
- const removeFactory = (method) => {
123
- const nodeRm = Effectify.effectify(
124
- NFS.rm,
125
- handleErrnoException("FileSystem", method),
126
- handleBadArgument(method),
127
- )
128
- return (path, options) =>
129
- nodeRm(path, {
130
- recursive: options?.recursive ?? false,
131
- force: options?.force ?? false,
132
- })
133
- }
134
- const remove = removeFactory("remove")
135
-
136
- const makeTempDirectoryScoped = (() => {
137
- const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped")
138
- const removeDirectory = removeFactory("makeTempDirectoryScoped")
139
- return (options) =>
140
- Effect.acquireRelease(makeDirectory(options), (directory) =>
141
- Effect.orDie(removeDirectory(directory, { recursive: true })),
142
- )
143
- })()
144
-
145
- const openFactory = (method) => {
146
- const nodeOpen = Effectify.effectify(
147
- NFS.open,
148
- handleErrnoException("FileSystem", method),
149
- handleBadArgument(method),
150
- )
151
- const nodeClose = Effectify.effectify(
152
- NFS.close,
153
- handleErrnoException("FileSystem", method),
154
- handleBadArgument(method),
155
- )
156
-
157
- return (path, options) =>
158
- Function.pipe(
159
- Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) =>
160
- Effect.orDie(nodeClose(fd)),
161
- ),
162
- Effect.map((fd) =>
163
- makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false),
164
- ),
165
- )
166
- }
167
- const open = openFactory("open")
168
-
169
- const makeFile = (() => {
170
- const nodeReadFactory = (method) =>
171
- Effectify.effectify(
172
- NFS.read,
173
- handleErrnoException("FileSystem", method),
174
- handleBadArgument(method),
175
- )
176
- const nodeRead = nodeReadFactory("read")
177
- const nodeReadAlloc = nodeReadFactory("readAlloc")
178
- const nodeStat = Effectify.effectify(
179
- NFS.fstat,
180
- handleErrnoException("FileSystem", "stat"),
181
- handleBadArgument("stat"),
182
- )
183
- const nodeTruncate = Effectify.effectify(
184
- NFS.ftruncate,
185
- handleErrnoException("FileSystem", "truncate"),
186
- handleBadArgument("truncate"),
187
- )
188
-
189
- const nodeSync = Effectify.effectify(
190
- NFS.fsync,
191
- handleErrnoException("FileSystem", "sync"),
192
- handleBadArgument("sync"),
193
- )
194
-
195
- const nodeWriteFactory = (method) =>
196
- Effectify.effectify(
197
- NFS.write,
198
- handleErrnoException("FileSystem", method),
199
- handleBadArgument(method),
200
- )
201
- const nodeWrite = nodeWriteFactory("write")
202
- const nodeWriteAll = nodeWriteFactory("writeAll")
203
-
204
- class FileImpl {
205
- [FileSystem.FileTypeId]
206
- fd
207
- append
208
-
209
- semaphore = Effect.unsafeMakeSemaphore(1)
210
- position = 0n
211
-
212
- constructor(fd, append) {
213
- this[FileSystem.FileTypeId] = FileSystem.FileTypeId
214
- this.fd = fd
215
- this.append = append
216
- }
217
-
218
- get stat() {
219
- return Effect.map(nodeStat(this.fd), makeFileInfo)
220
- }
221
-
222
- get sync() {
223
- return nodeSync(this.fd)
224
- }
225
-
226
- seek(offset, from) {
227
- const offsetSize = FileSystem.Size(offset)
228
- return this.semaphore.withPermits(1)(
229
- Effect.sync(() => {
230
- if (from === "start") {
231
- this.position = offsetSize
232
- } else if (from === "current") {
233
- this.position = this.position + offsetSize
234
- }
235
-
236
- return this.position
237
- }),
238
- )
239
- }
240
-
241
- read(buffer) {
242
- return this.semaphore.withPermits(1)(
243
- Effect.map(
244
- Effect.suspend(() =>
245
- nodeRead(this.fd, {
246
- buffer,
247
- position: this.position,
248
- }),
249
- ),
250
- (bytesRead) => {
251
- const sizeRead = FileSystem.Size(bytesRead)
252
- this.position = this.position + sizeRead
253
- return sizeRead
254
- },
255
- ),
256
- )
257
- }
258
-
259
- readAlloc(size) {
260
- const sizeNumber = Number(size)
261
- return this.semaphore.withPermits(1)(
262
- Effect.flatMap(
263
- Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)),
264
- (buffer) =>
265
- Effect.map(
266
- nodeReadAlloc(this.fd, {
267
- buffer,
268
- position: this.position,
269
- }),
270
- (bytesRead) => {
271
- if (bytesRead === 0) {
272
- return Option.none()
273
- }
274
-
275
- this.position = this.position + BigInt(bytesRead)
276
- if (bytesRead === sizeNumber) {
277
- return Option.some(buffer)
278
- }
279
-
280
- const dst = Buffer.allocUnsafeSlow(bytesRead)
281
- buffer.copy(dst, 0, 0, bytesRead)
282
- return Option.some(dst)
283
- },
284
- ),
285
- ),
286
- )
287
- }
288
-
289
- truncate(length) {
290
- return this.semaphore.withPermits(1)(
291
- Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {
292
- if (!this.append) {
293
- const len = BigInt(length ?? 0)
294
- if (this.position > len) {
295
- this.position = len
296
- }
297
- }
298
- }),
299
- )
300
- }
301
-
302
- write(buffer) {
303
- return this.semaphore.withPermits(1)(
304
- Effect.map(
305
- Effect.suspend(() =>
306
- nodeWrite(
307
- this.fd,
308
- buffer,
309
- undefined,
310
- undefined,
311
- this.append ? undefined : Number(this.position),
312
- ),
313
- ),
314
- (bytesWritten) => {
315
- const sizeWritten = FileSystem.Size(bytesWritten)
316
- if (!this.append) {
317
- this.position = this.position + sizeWritten
318
- }
319
-
320
- return sizeWritten
321
- },
322
- ),
323
- )
324
- }
325
-
326
- writeAllChunk(buffer) {
327
- return Effect.flatMap(
328
- Effect.suspend(() =>
329
- nodeWriteAll(
330
- this.fd,
331
- buffer,
332
- undefined,
333
- undefined,
334
- this.append ? undefined : Number(this.position),
335
- ),
336
- ),
337
- (bytesWritten) => {
338
- if (bytesWritten === 0) {
339
- return Effect.fail(
340
- new PlatformError.SystemError({
341
- module: "FileSystem",
342
- method: "writeAll",
343
- reason: "WriteZero",
344
- pathOrDescriptor: this.fd,
345
- description: "write returned 0 bytes written",
346
- }),
347
- )
348
- }
349
-
350
- if (!this.append) {
351
- this.position = this.position + BigInt(bytesWritten)
352
- }
353
-
354
- return bytesWritten < buffer.length
355
- ? this.writeAllChunk(buffer.subarray(bytesWritten))
356
- : Effect.void
357
- },
358
- )
359
- }
360
-
361
- writeAll(buffer) {
362
- return this.semaphore.withPermits(1)(this.writeAllChunk(buffer))
363
- }
364
- }
365
-
366
- return (fd, append) =>
367
- new FileImpl(fd, append)
368
- })()
369
-
370
- const makeTempFileFactory = (method) => {
371
- const makeDirectory = makeTempDirectoryFactory(method)
372
- const open = openFactory(method)
373
- const randomHexString = (bytes) =>
374
- Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"))
375
- return (options) =>
376
- Function.pipe(
377
- Effect.zip(makeDirectory(options), randomHexString(6)),
378
- Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))),
379
- Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))),
380
- )
381
- }
382
- const makeTempFile = makeTempFileFactory("makeTempFile")
383
-
384
- const makeTempFileScoped = (() => {
385
- const makeFile = makeTempFileFactory("makeTempFileScoped")
386
- const removeDirectory = removeFactory("makeTempFileScoped")
387
- return (options) =>
388
- Effect.acquireRelease(makeFile(options), (file) =>
389
- Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })),
390
- )
391
- })()
392
-
393
- const readDirectory = (path, options) =>
394
- Effect.tryPromise({
395
- try: () => NFS.promises.readdir(path, options),
396
- catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path]),
397
- })
398
-
399
- const readFile = (path) =>
400
- Effect.async((resume, signal) => {
401
- try {
402
- NFS.readFile(path, { signal }, (err, data) => {
403
- if (err) {
404
- resume(Effect.fail(handleErrnoException("FileSystem", "readFile")(err, [path])))
405
- } else {
406
- resume(Effect.succeed(data))
407
- }
408
- })
409
- } catch (err) {
410
- resume(Effect.fail(handleBadArgument("readFile")(err)))
411
- }
412
- })
413
-
414
- const readLink = (() => {
415
- const nodeReadLink = Effectify.effectify(
416
- NFS.readlink,
417
- handleErrnoException("FileSystem", "readLink"),
418
- handleBadArgument("readLink"),
419
- )
420
- return (path) => nodeReadLink(path)
421
- })()
422
-
423
- const realPath = (() => {
424
- const nodeRealPath = Effectify.effectify(
425
- NFS.realpath,
426
- handleErrnoException("FileSystem", "realPath"),
427
- handleBadArgument("realPath"),
428
- )
429
- return (path) => nodeRealPath(path)
430
- })()
431
-
432
- const rename = (() => {
433
- const nodeRename = Effectify.effectify(
434
- NFS.rename,
435
- handleErrnoException("FileSystem", "rename"),
436
- handleBadArgument("rename"),
437
- )
438
- return (oldPath, newPath) => nodeRename(oldPath, newPath)
439
- })()
440
-
441
- const makeFileInfo = (stat) => ({
442
- type: stat.isFile()
443
- ? "File"
444
- : stat.isDirectory()
445
- ? "Directory"
446
- : stat.isSymbolicLink()
447
- ? "SymbolicLink"
448
- : stat.isBlockDevice()
449
- ? "BlockDevice"
450
- : stat.isCharacterDevice()
451
- ? "CharacterDevice"
452
- : stat.isFIFO()
453
- ? "FIFO"
454
- : stat.isSocket()
455
- ? "Socket"
456
- : "Unknown",
457
- mtime: Option.fromNullable(stat.mtime),
458
- atime: Option.fromNullable(stat.atime),
459
- birthtime: Option.fromNullable(stat.birthtime),
460
- dev: stat.dev,
461
- rdev: Option.fromNullable(stat.rdev),
462
- ino: Option.fromNullable(stat.ino),
463
- mode: stat.mode,
464
- nlink: Option.fromNullable(stat.nlink),
465
- uid: Option.fromNullable(stat.uid),
466
- gid: Option.fromNullable(stat.gid),
467
- size: FileSystem.Size(stat.size),
468
- blksize: Option.map(Option.fromNullable(stat.blksize), FileSystem.Size),
469
- blocks: Option.fromNullable(stat.blocks),
470
- })
471
- const stat = (() => {
472
- const nodeStat = Effectify.effectify(
473
- NFS.stat,
474
- handleErrnoException("FileSystem", "stat"),
475
- handleBadArgument("stat"),
476
- )
477
- return (path) => Effect.map(nodeStat(path), makeFileInfo)
478
- })()
479
-
480
- const symlink = (() => {
481
- const nodeSymlink = Effectify.effectify(
482
- NFS.symlink,
483
- handleErrnoException("FileSystem", "symlink"),
484
- handleBadArgument("symlink"),
485
- )
486
- return (target, path) => nodeSymlink(target, path)
487
- })()
488
-
489
- const truncate = (() => {
490
- const nodeTruncate = Effectify.effectify(
491
- NFS.truncate,
492
- handleErrnoException("FileSystem", "truncate"),
493
- handleBadArgument("truncate"),
494
- )
495
- return (path, length) =>
496
- nodeTruncate(path, length !== undefined ? Number(length) : undefined)
497
- })()
498
-
499
- const utimes = (() => {
500
- const nodeUtimes = Effectify.effectify(
501
- NFS.utimes,
502
- handleErrnoException("FileSystem", "utime"),
503
- handleBadArgument("utime"),
504
- )
505
- return (path, atime, mtime) =>
506
- nodeUtimes(path, atime, mtime)
507
- })()
508
-
509
- const watchNode = (path, options) =>
510
- Stream.asyncScoped((emit) =>
511
- Effect.acquireRelease(
512
- Effect.sync(() => {
513
- const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
514
- if (!path) return
515
- switch (event) {
516
- case "rename": {
517
- emit.fromEffect(
518
- Effect.matchEffect(stat(path), {
519
- onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path })),
520
- onFailure: (err) =>
521
- err._tag === "SystemError" && err.reason === "NotFound"
522
- ? Effect.succeed(FileSystem.WatchEventRemove({ path }))
523
- : Effect.fail(err),
524
- }),
525
- )
526
- return
527
- }
528
- case "change": {
529
- emit.single(FileSystem.WatchEventUpdate({ path }))
530
- return
531
- }
532
- }
533
- })
534
- watcher.on("error", (error) => {
535
- emit.fail(
536
- new PlatformError.SystemError({
537
- module: "FileSystem",
538
- reason: "Unknown",
539
- method: "watch",
540
- pathOrDescriptor: path,
541
- cause: error,
542
- }),
543
- )
544
- })
545
- watcher.on("close", () => {
546
- emit.end()
547
- })
548
- return watcher
549
- }),
550
- (watcher) => Effect.sync(() => watcher.close()),
551
- ),
552
- )
553
-
554
- const watch = (
555
- backend,
556
- path,
557
- options,
558
- ) =>
559
- stat(path).pipe(
560
- Effect.map((stat) =>
561
- backend.pipe(
562
- Option.flatMap((_) => _.register(path, stat, options)),
563
- Option.getOrElse(() => watchNode(path, options)),
564
- ),
565
- ),
566
- Stream.unwrap,
567
- )
568
-
569
- const writeFile = (path, data, options) =>
570
- Effect.async((resume, signal) => {
571
- try {
572
- NFS.writeFile(
573
- path,
574
- data,
575
- {
576
- signal,
577
- flag: options?.flag,
578
- mode: options?.mode,
579
- },
580
- (err) => {
581
- if (err) {
582
- resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])))
583
- } else {
584
- resume(Effect.void)
585
- }
586
- },
587
- )
588
- } catch (err) {
589
- resume(Effect.fail(handleBadArgument("writeFile")(err)))
590
- }
591
- })
592
-
593
- const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) =>
594
- FileSystem.make({
595
- access,
596
- chmod,
597
- chown,
598
- copy,
599
- copyFile,
600
- link,
601
- makeDirectory,
602
- makeTempDirectory,
603
- makeTempDirectoryScoped,
604
- makeTempFile,
605
- makeTempFileScoped,
606
- open,
607
- readDirectory,
608
- readFile,
609
- readLink,
610
- realPath,
611
- remove,
612
- rename,
613
- stat,
614
- symlink,
615
- truncate,
616
- utimes,
617
- watch(path, options) {
618
- return watch(backend, path, options)
619
- },
620
- writeFile,
621
- }),
622
- )
623
-
624
- export const layer = Layer.effect(FileSystem.FileSystem, make)
625
-
626
- export { PlatformError as Error }
627
-
628
- export function handleErrnoException(module, method) {
629
- return function (
630
- err,
631
- [path],
632
- ) {
633
- let reason = "Unknown"
634
-
635
- switch (err.code) {
636
- case "ENOENT":
637
- reason = "NotFound"
638
- break
639
-
640
- case "EACCES":
641
- reason = "PermissionDenied"
642
- break
643
-
644
- case "EEXIST":
645
- reason = "AlreadyExists"
646
- break
647
-
648
- case "EISDIR":
649
- reason = "BadResource"
650
- break
651
-
652
- case "ENOTDIR":
653
- reason = "BadResource"
654
- break
655
-
656
- case "EBUSY":
657
- reason = "Busy"
658
- break
659
-
660
- case "ELOOP":
661
- reason = "BadResource"
662
- break
663
- }
664
-
665
- return new PlatformError.SystemError({
666
- reason,
667
- module,
668
- method,
669
- pathOrDescriptor: path,
670
- syscall: err.syscall,
671
- description: err.message,
672
- cause: err,
673
- })
674
- }
675
- }
@@ -1,23 +0,0 @@
1
- import * as NFS from "node:fs/promises"
2
- import * as NPath from "node:path"
3
-
4
- export const getEntrypoint = () => NPath.dirname(process.argv[1])
5
-
6
- export const findClosestPackageJson = async (path) => {
7
- const resolved = NPath.resolve(path)
8
- const stat = await NFS.stat(resolved).catch(() => undefined)
9
- let dir = stat?.isDirectory() ? resolved : NPath.dirname(resolved)
10
- const root = NPath.parse(dir).root
11
-
12
- while (dir !== root) {
13
- const candidate = NPath.join(dir, "package.json")
14
- try {
15
- await NFS.access(candidate)
16
- return candidate
17
- } catch {
18
- dir = NPath.dirname(dir)
19
- }
20
- }
21
-
22
- return undefined
23
- }
package/dist/sql/Sql.js DELETED
@@ -1,8 +0,0 @@
1
- import * as Context from "effect/Context"
2
- import * as Data from "effect/Data"
3
-
4
- export class SqlError extends Data.TaggedError("SqlError") {}
5
-
6
- export const SqlClient = Context.GenericTag(
7
- "effect-start/Sql/SqlClient",
8
- )