@confect/cli 1.0.0-next.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/CHANGELOG.md +12 -0
- package/LICENSE +7 -0
- package/dist/FunctionPath.mjs +19 -0
- package/dist/FunctionPath.mjs.map +1 -0
- package/dist/FunctionPaths.mjs +41 -0
- package/dist/FunctionPaths.mjs.map +1 -0
- package/dist/GroupPath.mjs +52 -0
- package/dist/GroupPath.mjs.map +1 -0
- package/dist/GroupPaths.mjs +9 -0
- package/dist/GroupPaths.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.mjs +28 -0
- package/dist/cliApp.mjs +13 -0
- package/dist/cliApp.mjs.map +1 -0
- package/dist/confect/codegen.mjs +111 -0
- package/dist/confect/codegen.mjs.map +1 -0
- package/dist/confect/dev.mjs +253 -0
- package/dist/confect/dev.mjs.map +1 -0
- package/dist/confect.mjs +14 -0
- package/dist/confect.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/log.mjs +25 -0
- package/dist/log.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeCommandExecutor.mjs +12 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeCommandExecutor.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeFileSystem.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeFileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodePath.mjs +25 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodePath.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeRuntime.mjs +12 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeRuntime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeTerminal.mjs +17 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/NodeTerminal.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/commandExecutor.mjs +129 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/commandExecutor.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/error.mjs +43 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/error.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.mjs +329 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.mjs +51 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.mjs +31 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.mjs +24 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.mjs +91 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/terminal.mjs +75 -0
- package/dist/node_modules/.pnpm/@effect_platform-node-shared@0.53.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/terminal.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeContext.mjs +21 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeContext.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeFileSystem.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeFileSystem.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeRuntime.mjs +15 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeRuntime.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeWorker.mjs +27 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/NodeWorker.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/internal/worker.mjs +71 -0
- package/dist/node_modules/.pnpm/@effect_platform-node@0.100.0_@effect_cluster@0.52.9_@effect_platform@0.93.2_effect@3.1_a15ca1802d939cd85cc564105ef862ac/node_modules/@effect/platform-node/dist/esm/internal/worker.mjs.map +1 -0
- package/dist/packages/cli/package.mjs +6 -0
- package/dist/packages/cli/package.mjs.map +1 -0
- package/dist/packages/core/dist/Spec.mjs +23 -0
- package/dist/packages/core/dist/Spec.mjs.map +1 -0
- package/dist/packages/core/dist/_virtual/rolldown_runtime.mjs +14 -0
- package/dist/packages/core/dist/_virtual/rolldown_runtime.mjs.map +1 -0
- package/dist/services/ConfectDirectory.mjs +31 -0
- package/dist/services/ConfectDirectory.mjs.map +1 -0
- package/dist/services/ConvexDirectory.mjs +41 -0
- package/dist/services/ConvexDirectory.mjs.map +1 -0
- package/dist/services/ProjectRoot.mjs +35 -0
- package/dist/services/ProjectRoot.mjs.map +1 -0
- package/dist/templates.mjs +204 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/utils.mjs +162 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +86 -0
- package/src/FunctionPath.ts +28 -0
- package/src/FunctionPaths.ts +103 -0
- package/src/GroupPath.ts +117 -0
- package/src/GroupPaths.ts +7 -0
- package/src/cliApp.ts +8 -0
- package/src/confect/codegen.ts +228 -0
- package/src/confect/dev.ts +611 -0
- package/src/confect.ts +19 -0
- package/src/index.ts +22 -0
- package/src/log.ts +106 -0
- package/src/services/ConfectDirectory.ts +41 -0
- package/src/services/ConvexDirectory.ts +67 -0
- package/src/services/ProjectRoot.ts +49 -0
- package/src/templates.ts +380 -0
- package/src/utils.ts +332 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { handleErrnoException } from "./error.mjs";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { pipe } from "effect/Function";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
6
|
+
import * as Stream from "effect/Stream";
|
|
7
|
+
import * as FileSystem from "@effect/platform/FileSystem";
|
|
8
|
+
import { effectify } from "@effect/platform/Effectify";
|
|
9
|
+
import * as Error from "@effect/platform/Error";
|
|
10
|
+
import * as Crypto from "node:crypto";
|
|
11
|
+
import * as NFS from "node:fs";
|
|
12
|
+
import * as OS from "node:os";
|
|
13
|
+
import * as Path from "node:path";
|
|
14
|
+
|
|
15
|
+
//#region ../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.js
|
|
16
|
+
const handleBadArgument = (method) => (cause) => new Error.BadArgument({
|
|
17
|
+
module: "FileSystem",
|
|
18
|
+
method,
|
|
19
|
+
cause
|
|
20
|
+
});
|
|
21
|
+
const access = /* @__PURE__ */ (() => {
|
|
22
|
+
const nodeAccess = /* @__PURE__ */ effectify(NFS.access, /* @__PURE__ */ handleErrnoException("FileSystem", "access"), /* @__PURE__ */ handleBadArgument("access"));
|
|
23
|
+
return (path, options) => {
|
|
24
|
+
let mode = NFS.constants.F_OK;
|
|
25
|
+
if (options?.readable) mode |= NFS.constants.R_OK;
|
|
26
|
+
if (options?.writable) mode |= NFS.constants.W_OK;
|
|
27
|
+
return nodeAccess(path, mode);
|
|
28
|
+
};
|
|
29
|
+
})();
|
|
30
|
+
const copy = /* @__PURE__ */ (() => {
|
|
31
|
+
const nodeCp = /* @__PURE__ */ effectify(NFS.cp, /* @__PURE__ */ handleErrnoException("FileSystem", "copy"), /* @__PURE__ */ handleBadArgument("copy"));
|
|
32
|
+
return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
|
|
33
|
+
force: options?.overwrite ?? false,
|
|
34
|
+
preserveTimestamps: options?.preserveTimestamps ?? false,
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
const copyFile = /* @__PURE__ */ (() => {
|
|
39
|
+
const nodeCopyFile = /* @__PURE__ */ effectify(NFS.copyFile, /* @__PURE__ */ handleErrnoException("FileSystem", "copyFile"), /* @__PURE__ */ handleBadArgument("copyFile"));
|
|
40
|
+
return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
|
|
41
|
+
})();
|
|
42
|
+
const chmod = /* @__PURE__ */ (() => {
|
|
43
|
+
const nodeChmod = /* @__PURE__ */ effectify(NFS.chmod, /* @__PURE__ */ handleErrnoException("FileSystem", "chmod"), /* @__PURE__ */ handleBadArgument("chmod"));
|
|
44
|
+
return (path, mode) => nodeChmod(path, mode);
|
|
45
|
+
})();
|
|
46
|
+
const chown = /* @__PURE__ */ (() => {
|
|
47
|
+
const nodeChown = /* @__PURE__ */ effectify(NFS.chown, /* @__PURE__ */ handleErrnoException("FileSystem", "chown"), /* @__PURE__ */ handleBadArgument("chown"));
|
|
48
|
+
return (path, uid, gid) => nodeChown(path, uid, gid);
|
|
49
|
+
})();
|
|
50
|
+
const link = /* @__PURE__ */ (() => {
|
|
51
|
+
const nodeLink = /* @__PURE__ */ effectify(NFS.link, /* @__PURE__ */ handleErrnoException("FileSystem", "link"), /* @__PURE__ */ handleBadArgument("link"));
|
|
52
|
+
return (existingPath, newPath) => nodeLink(existingPath, newPath);
|
|
53
|
+
})();
|
|
54
|
+
const makeDirectory = /* @__PURE__ */ (() => {
|
|
55
|
+
const nodeMkdir = /* @__PURE__ */ effectify(NFS.mkdir, /* @__PURE__ */ handleErrnoException("FileSystem", "makeDirectory"), /* @__PURE__ */ handleBadArgument("makeDirectory"));
|
|
56
|
+
return (path, options) => nodeMkdir(path, {
|
|
57
|
+
recursive: options?.recursive ?? false,
|
|
58
|
+
mode: options?.mode
|
|
59
|
+
});
|
|
60
|
+
})();
|
|
61
|
+
const makeTempDirectoryFactory = (method) => {
|
|
62
|
+
const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
63
|
+
return (options) => Effect.suspend(() => {
|
|
64
|
+
const prefix = options?.prefix ?? "";
|
|
65
|
+
const directory = typeof options?.directory === "string" ? Path.join(options.directory, ".") : OS.tmpdir();
|
|
66
|
+
return nodeMkdtemp(prefix ? Path.join(directory, prefix) : directory + "/");
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const makeTempDirectory = /* @__PURE__ */ makeTempDirectoryFactory("makeTempDirectory");
|
|
70
|
+
const removeFactory = (method) => {
|
|
71
|
+
const nodeRm = effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
72
|
+
return (path, options) => nodeRm(path, {
|
|
73
|
+
recursive: options?.recursive ?? false,
|
|
74
|
+
force: options?.force ?? false
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const remove = /* @__PURE__ */ removeFactory("remove");
|
|
78
|
+
const makeTempDirectoryScoped = /* @__PURE__ */ (() => {
|
|
79
|
+
const makeDirectory$1 = /* @__PURE__ */ makeTempDirectoryFactory("makeTempDirectoryScoped");
|
|
80
|
+
const removeDirectory = /* @__PURE__ */ removeFactory("makeTempDirectoryScoped");
|
|
81
|
+
return (options) => Effect.acquireRelease(makeDirectory$1(options), (directory) => Effect.orDie(removeDirectory(directory, { recursive: true })));
|
|
82
|
+
})();
|
|
83
|
+
const openFactory = (method) => {
|
|
84
|
+
const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
85
|
+
const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
86
|
+
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)));
|
|
87
|
+
};
|
|
88
|
+
const open = /* @__PURE__ */ openFactory("open");
|
|
89
|
+
const makeFile = /* @__PURE__ */ (() => {
|
|
90
|
+
const nodeReadFactory = (method) => effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
91
|
+
const nodeRead = /* @__PURE__ */ nodeReadFactory("read");
|
|
92
|
+
const nodeReadAlloc = /* @__PURE__ */ nodeReadFactory("readAlloc");
|
|
93
|
+
const nodeStat = /* @__PURE__ */ effectify(NFS.fstat, /* @__PURE__ */ handleErrnoException("FileSystem", "stat"), /* @__PURE__ */ handleBadArgument("stat"));
|
|
94
|
+
const nodeTruncate = /* @__PURE__ */ effectify(NFS.ftruncate, /* @__PURE__ */ handleErrnoException("FileSystem", "truncate"), /* @__PURE__ */ handleBadArgument("truncate"));
|
|
95
|
+
const nodeSync = /* @__PURE__ */ effectify(NFS.fsync, /* @__PURE__ */ handleErrnoException("FileSystem", "sync"), /* @__PURE__ */ handleBadArgument("sync"));
|
|
96
|
+
const nodeWriteFactory = (method) => effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
|
|
97
|
+
const nodeWrite = /* @__PURE__ */ nodeWriteFactory("write");
|
|
98
|
+
const nodeWriteAll = /* @__PURE__ */ nodeWriteFactory("writeAll");
|
|
99
|
+
class FileImpl {
|
|
100
|
+
fd;
|
|
101
|
+
append;
|
|
102
|
+
[FileSystem.FileTypeId];
|
|
103
|
+
semaphore = /* @__PURE__ */ Effect.unsafeMakeSemaphore(1);
|
|
104
|
+
position = 0n;
|
|
105
|
+
constructor(fd, append) {
|
|
106
|
+
this.fd = fd;
|
|
107
|
+
this.append = append;
|
|
108
|
+
this[FileSystem.FileTypeId] = FileSystem.FileTypeId;
|
|
109
|
+
}
|
|
110
|
+
get stat() {
|
|
111
|
+
return Effect.map(nodeStat(this.fd), makeFileInfo);
|
|
112
|
+
}
|
|
113
|
+
get sync() {
|
|
114
|
+
return nodeSync(this.fd);
|
|
115
|
+
}
|
|
116
|
+
seek(offset, from) {
|
|
117
|
+
const offsetSize = FileSystem.Size(offset);
|
|
118
|
+
return this.semaphore.withPermits(1)(Effect.sync(() => {
|
|
119
|
+
if (from === "start") this.position = offsetSize;
|
|
120
|
+
else if (from === "current") this.position = this.position + offsetSize;
|
|
121
|
+
return this.position;
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
read(buffer) {
|
|
125
|
+
return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeRead(this.fd, {
|
|
126
|
+
buffer,
|
|
127
|
+
position: this.position
|
|
128
|
+
})), (bytesRead) => {
|
|
129
|
+
const sizeRead = FileSystem.Size(bytesRead);
|
|
130
|
+
this.position = this.position + sizeRead;
|
|
131
|
+
return sizeRead;
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
readAlloc(size) {
|
|
135
|
+
const sizeNumber = Number(size);
|
|
136
|
+
return this.semaphore.withPermits(1)(Effect.flatMap(Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)), (buffer) => Effect.map(nodeReadAlloc(this.fd, {
|
|
137
|
+
buffer,
|
|
138
|
+
position: this.position
|
|
139
|
+
}), (bytesRead) => {
|
|
140
|
+
if (bytesRead === 0) return Option.none();
|
|
141
|
+
this.position = this.position + BigInt(bytesRead);
|
|
142
|
+
if (bytesRead === sizeNumber) return Option.some(buffer);
|
|
143
|
+
const dst = Buffer.allocUnsafeSlow(bytesRead);
|
|
144
|
+
buffer.copy(dst, 0, 0, bytesRead);
|
|
145
|
+
return Option.some(dst);
|
|
146
|
+
})));
|
|
147
|
+
}
|
|
148
|
+
truncate(length) {
|
|
149
|
+
return this.semaphore.withPermits(1)(Effect.map(nodeTruncate(this.fd, length ? Number(length) : void 0), () => {
|
|
150
|
+
if (!this.append) {
|
|
151
|
+
const len = BigInt(length ?? 0);
|
|
152
|
+
if (this.position > len) this.position = len;
|
|
153
|
+
}
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
write(buffer) {
|
|
157
|
+
return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeWrite(this.fd, buffer, void 0, void 0, this.append ? void 0 : Number(this.position))), (bytesWritten) => {
|
|
158
|
+
const sizeWritten = FileSystem.Size(bytesWritten);
|
|
159
|
+
if (!this.append) this.position = this.position + sizeWritten;
|
|
160
|
+
return sizeWritten;
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
writeAllChunk(buffer) {
|
|
164
|
+
return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, void 0, void 0, this.append ? void 0 : Number(this.position))), (bytesWritten) => {
|
|
165
|
+
if (bytesWritten === 0) return Effect.fail(new Error.SystemError({
|
|
166
|
+
module: "FileSystem",
|
|
167
|
+
method: "writeAll",
|
|
168
|
+
reason: "WriteZero",
|
|
169
|
+
pathOrDescriptor: this.fd,
|
|
170
|
+
description: "write returned 0 bytes written"
|
|
171
|
+
}));
|
|
172
|
+
if (!this.append) this.position = this.position + BigInt(bytesWritten);
|
|
173
|
+
return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect.void;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
writeAll(buffer) {
|
|
177
|
+
return this.semaphore.withPermits(1)(this.writeAllChunk(buffer));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return (fd, append) => new FileImpl(fd, append);
|
|
181
|
+
})();
|
|
182
|
+
const makeTempFileFactory = (method) => {
|
|
183
|
+
const makeDirectory$1 = makeTempDirectoryFactory(method);
|
|
184
|
+
const open$1 = openFactory(method);
|
|
185
|
+
const randomHexString = (bytes) => Effect.sync(() => Crypto.randomBytes(bytes).toString("hex"));
|
|
186
|
+
return (options) => pipe(Effect.zip(makeDirectory$1(options), randomHexString(6)), Effect.map(([directory, random]) => Path.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open$1(path, { flag: "w+" }))));
|
|
187
|
+
};
|
|
188
|
+
const makeTempFile = /* @__PURE__ */ makeTempFileFactory("makeTempFile");
|
|
189
|
+
const makeTempFileScoped = /* @__PURE__ */ (() => {
|
|
190
|
+
const makeFile$1 = /* @__PURE__ */ makeTempFileFactory("makeTempFileScoped");
|
|
191
|
+
const removeDirectory = /* @__PURE__ */ removeFactory("makeTempFileScoped");
|
|
192
|
+
return (options) => Effect.acquireRelease(makeFile$1(options), (file) => Effect.orDie(removeDirectory(Path.dirname(file), { recursive: true })));
|
|
193
|
+
})();
|
|
194
|
+
const readDirectory = (path, options) => Effect.tryPromise({
|
|
195
|
+
try: () => NFS.promises.readdir(path, options),
|
|
196
|
+
catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path])
|
|
197
|
+
});
|
|
198
|
+
const readFile = (path) => Effect.async((resume, signal) => {
|
|
199
|
+
try {
|
|
200
|
+
NFS.readFile(path, { signal }, (err, data) => {
|
|
201
|
+
if (err) resume(Effect.fail(handleErrnoException("FileSystem", "readFile")(err, [path])));
|
|
202
|
+
else resume(Effect.succeed(data));
|
|
203
|
+
});
|
|
204
|
+
} catch (err) {
|
|
205
|
+
resume(Effect.fail(handleBadArgument("readFile")(err)));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
const readLink = /* @__PURE__ */ (() => {
|
|
209
|
+
const nodeReadLink = /* @__PURE__ */ effectify(NFS.readlink, /* @__PURE__ */ handleErrnoException("FileSystem", "readLink"), /* @__PURE__ */ handleBadArgument("readLink"));
|
|
210
|
+
return (path) => nodeReadLink(path);
|
|
211
|
+
})();
|
|
212
|
+
const realPath = /* @__PURE__ */ (() => {
|
|
213
|
+
const nodeRealPath = /* @__PURE__ */ effectify(NFS.realpath, /* @__PURE__ */ handleErrnoException("FileSystem", "realPath"), /* @__PURE__ */ handleBadArgument("realPath"));
|
|
214
|
+
return (path) => nodeRealPath(path);
|
|
215
|
+
})();
|
|
216
|
+
const rename = /* @__PURE__ */ (() => {
|
|
217
|
+
const nodeRename = /* @__PURE__ */ effectify(NFS.rename, /* @__PURE__ */ handleErrnoException("FileSystem", "rename"), /* @__PURE__ */ handleBadArgument("rename"));
|
|
218
|
+
return (oldPath, newPath) => nodeRename(oldPath, newPath);
|
|
219
|
+
})();
|
|
220
|
+
const makeFileInfo = (stat$1) => ({
|
|
221
|
+
type: stat$1.isFile() ? "File" : stat$1.isDirectory() ? "Directory" : stat$1.isSymbolicLink() ? "SymbolicLink" : stat$1.isBlockDevice() ? "BlockDevice" : stat$1.isCharacterDevice() ? "CharacterDevice" : stat$1.isFIFO() ? "FIFO" : stat$1.isSocket() ? "Socket" : "Unknown",
|
|
222
|
+
mtime: Option.fromNullable(stat$1.mtime),
|
|
223
|
+
atime: Option.fromNullable(stat$1.atime),
|
|
224
|
+
birthtime: Option.fromNullable(stat$1.birthtime),
|
|
225
|
+
dev: stat$1.dev,
|
|
226
|
+
rdev: Option.fromNullable(stat$1.rdev),
|
|
227
|
+
ino: Option.fromNullable(stat$1.ino),
|
|
228
|
+
mode: stat$1.mode,
|
|
229
|
+
nlink: Option.fromNullable(stat$1.nlink),
|
|
230
|
+
uid: Option.fromNullable(stat$1.uid),
|
|
231
|
+
gid: Option.fromNullable(stat$1.gid),
|
|
232
|
+
size: FileSystem.Size(stat$1.size),
|
|
233
|
+
blksize: Option.map(Option.fromNullable(stat$1.blksize), FileSystem.Size),
|
|
234
|
+
blocks: Option.fromNullable(stat$1.blocks)
|
|
235
|
+
});
|
|
236
|
+
const stat = /* @__PURE__ */ (() => {
|
|
237
|
+
const nodeStat = /* @__PURE__ */ effectify(NFS.stat, /* @__PURE__ */ handleErrnoException("FileSystem", "stat"), /* @__PURE__ */ handleBadArgument("stat"));
|
|
238
|
+
return (path) => Effect.map(nodeStat(path), makeFileInfo);
|
|
239
|
+
})();
|
|
240
|
+
const symlink = /* @__PURE__ */ (() => {
|
|
241
|
+
const nodeSymlink = /* @__PURE__ */ effectify(NFS.symlink, /* @__PURE__ */ handleErrnoException("FileSystem", "symlink"), /* @__PURE__ */ handleBadArgument("symlink"));
|
|
242
|
+
return (target, path) => nodeSymlink(target, path);
|
|
243
|
+
})();
|
|
244
|
+
const truncate = /* @__PURE__ */ (() => {
|
|
245
|
+
const nodeTruncate = /* @__PURE__ */ effectify(NFS.truncate, /* @__PURE__ */ handleErrnoException("FileSystem", "truncate"), /* @__PURE__ */ handleBadArgument("truncate"));
|
|
246
|
+
return (path, length) => nodeTruncate(path, length !== void 0 ? Number(length) : void 0);
|
|
247
|
+
})();
|
|
248
|
+
const utimes = /* @__PURE__ */ (() => {
|
|
249
|
+
const nodeUtimes = /* @__PURE__ */ effectify(NFS.utimes, /* @__PURE__ */ handleErrnoException("FileSystem", "utime"), /* @__PURE__ */ handleBadArgument("utime"));
|
|
250
|
+
return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
|
|
251
|
+
})();
|
|
252
|
+
const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquireRelease(Effect.sync(() => {
|
|
253
|
+
const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path$1) => {
|
|
254
|
+
if (!path$1) return;
|
|
255
|
+
switch (event) {
|
|
256
|
+
case "rename":
|
|
257
|
+
emit.fromEffect(Effect.matchEffect(stat(path$1), {
|
|
258
|
+
onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path: path$1 })),
|
|
259
|
+
onFailure: (err) => err._tag === "SystemError" && err.reason === "NotFound" ? Effect.succeed(FileSystem.WatchEventRemove({ path: path$1 })) : Effect.fail(err)
|
|
260
|
+
}));
|
|
261
|
+
return;
|
|
262
|
+
case "change":
|
|
263
|
+
emit.single(FileSystem.WatchEventUpdate({ path: path$1 }));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
watcher.on("error", (error) => {
|
|
268
|
+
emit.fail(new Error.SystemError({
|
|
269
|
+
module: "FileSystem",
|
|
270
|
+
reason: "Unknown",
|
|
271
|
+
method: "watch",
|
|
272
|
+
pathOrDescriptor: path,
|
|
273
|
+
cause: error
|
|
274
|
+
}));
|
|
275
|
+
});
|
|
276
|
+
watcher.on("close", () => {
|
|
277
|
+
emit.end();
|
|
278
|
+
});
|
|
279
|
+
return watcher;
|
|
280
|
+
}), (watcher) => Effect.sync(() => watcher.close())));
|
|
281
|
+
const watch = (backend, path, options) => stat(path).pipe(Effect.map((stat$1) => backend.pipe(Option.flatMap((_) => _.register(path, stat$1, options)), Option.getOrElse(() => watchNode(path, options)))), Stream.unwrap);
|
|
282
|
+
const writeFile = (path, data, options) => Effect.async((resume, signal) => {
|
|
283
|
+
try {
|
|
284
|
+
NFS.writeFile(path, data, {
|
|
285
|
+
signal,
|
|
286
|
+
flag: options?.flag,
|
|
287
|
+
mode: options?.mode
|
|
288
|
+
}, (err) => {
|
|
289
|
+
if (err) resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])));
|
|
290
|
+
else resume(Effect.void);
|
|
291
|
+
});
|
|
292
|
+
} catch (err) {
|
|
293
|
+
resume(Effect.fail(handleBadArgument("writeFile")(err)));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
const makeFileSystem = /* @__PURE__ */ Effect.map(/* @__PURE__ */ Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
|
|
297
|
+
access,
|
|
298
|
+
chmod,
|
|
299
|
+
chown,
|
|
300
|
+
copy,
|
|
301
|
+
copyFile,
|
|
302
|
+
link,
|
|
303
|
+
makeDirectory,
|
|
304
|
+
makeTempDirectory,
|
|
305
|
+
makeTempDirectoryScoped,
|
|
306
|
+
makeTempFile,
|
|
307
|
+
makeTempFileScoped,
|
|
308
|
+
open,
|
|
309
|
+
readDirectory,
|
|
310
|
+
readFile,
|
|
311
|
+
readLink,
|
|
312
|
+
realPath,
|
|
313
|
+
remove,
|
|
314
|
+
rename,
|
|
315
|
+
stat,
|
|
316
|
+
symlink,
|
|
317
|
+
truncate,
|
|
318
|
+
utimes,
|
|
319
|
+
watch(path, options) {
|
|
320
|
+
return watch(backend, path, options);
|
|
321
|
+
},
|
|
322
|
+
writeFile
|
|
323
|
+
}));
|
|
324
|
+
/** @internal */
|
|
325
|
+
const layer = /* @__PURE__ */ Layer.effect(FileSystem.FileSystem, makeFileSystem);
|
|
326
|
+
|
|
327
|
+
//#endregion
|
|
328
|
+
export { layer };
|
|
329
|
+
//# sourceMappingURL=fileSystem.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystem.mjs","names":["makeDirectory","open","makeFile","stat","path"],"sources":["../../../../../../../../../../../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/fileSystem.js"],"sourcesContent":["import { effectify } from \"@effect/platform/Effectify\";\nimport * as Error from \"@effect/platform/Error\";\nimport * as FileSystem from \"@effect/platform/FileSystem\";\nimport * as Effect from \"effect/Effect\";\nimport { pipe } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport * as Stream from \"effect/Stream\";\nimport * as Crypto from \"node:crypto\";\nimport * as NFS from \"node:fs\";\nimport * as OS from \"node:os\";\nimport * as Path from \"node:path\";\nimport { handleErrnoException } from \"./error.js\";\nconst handleBadArgument = method => cause => new Error.BadArgument({\n module: \"FileSystem\",\n method,\n cause\n});\n// == access\nconst access = /*#__PURE__*/(() => {\n const nodeAccess = /*#__PURE__*/effectify(NFS.access, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"access\"), /*#__PURE__*/handleBadArgument(\"access\"));\n return (path, options) => {\n let mode = NFS.constants.F_OK;\n if (options?.readable) {\n mode |= NFS.constants.R_OK;\n }\n if (options?.writable) {\n mode |= NFS.constants.W_OK;\n }\n return nodeAccess(path, mode);\n };\n})();\n// == copy\nconst copy = /*#__PURE__*/(() => {\n const nodeCp = /*#__PURE__*/effectify(NFS.cp, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"copy\"), /*#__PURE__*/handleBadArgument(\"copy\"));\n return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {\n force: options?.overwrite ?? false,\n preserveTimestamps: options?.preserveTimestamps ?? false,\n recursive: true\n });\n})();\n// == copyFile\nconst copyFile = /*#__PURE__*/(() => {\n const nodeCopyFile = /*#__PURE__*/effectify(NFS.copyFile, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"copyFile\"), /*#__PURE__*/handleBadArgument(\"copyFile\"));\n return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);\n})();\n// == chmod\nconst chmod = /*#__PURE__*/(() => {\n const nodeChmod = /*#__PURE__*/effectify(NFS.chmod, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"chmod\"), /*#__PURE__*/handleBadArgument(\"chmod\"));\n return (path, mode) => nodeChmod(path, mode);\n})();\n// == chown\nconst chown = /*#__PURE__*/(() => {\n const nodeChown = /*#__PURE__*/effectify(NFS.chown, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"chown\"), /*#__PURE__*/handleBadArgument(\"chown\"));\n return (path, uid, gid) => nodeChown(path, uid, gid);\n})();\n// == link\nconst link = /*#__PURE__*/(() => {\n const nodeLink = /*#__PURE__*/effectify(NFS.link, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"link\"), /*#__PURE__*/handleBadArgument(\"link\"));\n return (existingPath, newPath) => nodeLink(existingPath, newPath);\n})();\n// == makeDirectory\nconst makeDirectory = /*#__PURE__*/(() => {\n const nodeMkdir = /*#__PURE__*/effectify(NFS.mkdir, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"makeDirectory\"), /*#__PURE__*/handleBadArgument(\"makeDirectory\"));\n return (path, options) => nodeMkdir(path, {\n recursive: options?.recursive ?? false,\n mode: options?.mode\n });\n})();\n// == makeTempDirectory\nconst makeTempDirectoryFactory = method => {\n const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n return options => Effect.suspend(() => {\n const prefix = options?.prefix ?? \"\";\n const directory = typeof options?.directory === \"string\" ? Path.join(options.directory, \".\") : OS.tmpdir();\n return nodeMkdtemp(prefix ? Path.join(directory, prefix) : directory + \"/\");\n });\n};\nconst makeTempDirectory = /*#__PURE__*/makeTempDirectoryFactory(\"makeTempDirectory\");\n// == remove\nconst removeFactory = method => {\n const nodeRm = effectify(NFS.rm, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n return (path, options) => nodeRm(path, {\n recursive: options?.recursive ?? false,\n force: options?.force ?? false\n });\n};\nconst remove = /*#__PURE__*/removeFactory(\"remove\");\n// == makeTempDirectoryScoped\nconst makeTempDirectoryScoped = /*#__PURE__*/(() => {\n const makeDirectory = /*#__PURE__*/makeTempDirectoryFactory(\"makeTempDirectoryScoped\");\n const removeDirectory = /*#__PURE__*/removeFactory(\"makeTempDirectoryScoped\");\n return options => Effect.acquireRelease(makeDirectory(options), directory => Effect.orDie(removeDirectory(directory, {\n recursive: true\n })));\n})();\n// == open\nconst openFactory = method => {\n const nodeOpen = effectify(NFS.open, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n const nodeClose = effectify(NFS.close, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n 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)));\n};\nconst open = /*#__PURE__*/openFactory(\"open\");\nconst makeFile = /*#__PURE__*/(() => {\n const nodeReadFactory = method => effectify(NFS.read, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n const nodeRead = /*#__PURE__*/nodeReadFactory(\"read\");\n const nodeReadAlloc = /*#__PURE__*/nodeReadFactory(\"readAlloc\");\n const nodeStat = /*#__PURE__*/effectify(NFS.fstat, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"stat\"), /*#__PURE__*/handleBadArgument(\"stat\"));\n const nodeTruncate = /*#__PURE__*/effectify(NFS.ftruncate, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"truncate\"), /*#__PURE__*/handleBadArgument(\"truncate\"));\n const nodeSync = /*#__PURE__*/effectify(NFS.fsync, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"sync\"), /*#__PURE__*/handleBadArgument(\"sync\"));\n const nodeWriteFactory = method => effectify(NFS.write, handleErrnoException(\"FileSystem\", method), handleBadArgument(method));\n const nodeWrite = /*#__PURE__*/nodeWriteFactory(\"write\");\n const nodeWriteAll = /*#__PURE__*/nodeWriteFactory(\"writeAll\");\n class FileImpl {\n fd;\n append;\n [FileSystem.FileTypeId];\n semaphore = /*#__PURE__*/Effect.unsafeMakeSemaphore(1);\n position = 0n;\n constructor(fd, append) {\n this.fd = fd;\n this.append = append;\n this[FileSystem.FileTypeId] = FileSystem.FileTypeId;\n }\n get stat() {\n return Effect.map(nodeStat(this.fd), makeFileInfo);\n }\n get sync() {\n return nodeSync(this.fd);\n }\n seek(offset, from) {\n const offsetSize = FileSystem.Size(offset);\n return this.semaphore.withPermits(1)(Effect.sync(() => {\n if (from === \"start\") {\n this.position = offsetSize;\n } else if (from === \"current\") {\n this.position = this.position + offsetSize;\n }\n return this.position;\n }));\n }\n read(buffer) {\n return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeRead(this.fd, {\n buffer,\n position: this.position\n })), bytesRead => {\n const sizeRead = FileSystem.Size(bytesRead);\n this.position = this.position + sizeRead;\n return sizeRead;\n }));\n }\n readAlloc(size) {\n const sizeNumber = Number(size);\n return this.semaphore.withPermits(1)(Effect.flatMap(Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)), buffer => Effect.map(nodeReadAlloc(this.fd, {\n buffer,\n position: this.position\n }), bytesRead => {\n if (bytesRead === 0) {\n return Option.none();\n }\n this.position = this.position + BigInt(bytesRead);\n if (bytesRead === sizeNumber) {\n return Option.some(buffer);\n }\n const dst = Buffer.allocUnsafeSlow(bytesRead);\n buffer.copy(dst, 0, 0, bytesRead);\n return Option.some(dst);\n })));\n }\n truncate(length) {\n return this.semaphore.withPermits(1)(Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {\n if (!this.append) {\n const len = BigInt(length ?? 0);\n if (this.position > len) {\n this.position = len;\n }\n }\n }));\n }\n write(buffer) {\n return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeWrite(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), bytesWritten => {\n const sizeWritten = FileSystem.Size(bytesWritten);\n if (!this.append) {\n this.position = this.position + sizeWritten;\n }\n return sizeWritten;\n }));\n }\n writeAllChunk(buffer) {\n return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), bytesWritten => {\n if (bytesWritten === 0) {\n return Effect.fail(new Error.SystemError({\n module: \"FileSystem\",\n method: \"writeAll\",\n reason: \"WriteZero\",\n pathOrDescriptor: this.fd,\n description: \"write returned 0 bytes written\"\n }));\n }\n if (!this.append) {\n this.position = this.position + BigInt(bytesWritten);\n }\n return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : Effect.void;\n });\n }\n writeAll(buffer) {\n return this.semaphore.withPermits(1)(this.writeAllChunk(buffer));\n }\n }\n return (fd, append) => new FileImpl(fd, append);\n})();\n// == makeTempFile\nconst makeTempFileFactory = method => {\n const makeDirectory = makeTempDirectoryFactory(method);\n const open = openFactory(method);\n const randomHexString = bytes => Effect.sync(() => Crypto.randomBytes(bytes).toString(\"hex\"));\n return options => pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => Path.join(directory, random + (options?.suffix ?? \"\"))), Effect.tap(path => Effect.scoped(open(path, {\n flag: \"w+\"\n }))));\n};\nconst makeTempFile = /*#__PURE__*/makeTempFileFactory(\"makeTempFile\");\n// == makeTempFileScoped\nconst makeTempFileScoped = /*#__PURE__*/(() => {\n const makeFile = /*#__PURE__*/makeTempFileFactory(\"makeTempFileScoped\");\n const removeDirectory = /*#__PURE__*/removeFactory(\"makeTempFileScoped\");\n return options => Effect.acquireRelease(makeFile(options), file => Effect.orDie(removeDirectory(Path.dirname(file), {\n recursive: true\n })));\n})();\n// == readDirectory\nconst readDirectory = (path, options) => Effect.tryPromise({\n try: () => NFS.promises.readdir(path, options),\n catch: err => handleErrnoException(\"FileSystem\", \"readDirectory\")(err, [path])\n});\n// == readFile\nconst readFile = path => Effect.async((resume, signal) => {\n try {\n NFS.readFile(path, {\n signal\n }, (err, data) => {\n if (err) {\n resume(Effect.fail(handleErrnoException(\"FileSystem\", \"readFile\")(err, [path])));\n } else {\n resume(Effect.succeed(data));\n }\n });\n } catch (err) {\n resume(Effect.fail(handleBadArgument(\"readFile\")(err)));\n }\n});\n// == readLink\nconst readLink = /*#__PURE__*/(() => {\n const nodeReadLink = /*#__PURE__*/effectify(NFS.readlink, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"readLink\"), /*#__PURE__*/handleBadArgument(\"readLink\"));\n return path => nodeReadLink(path);\n})();\n// == realPath\nconst realPath = /*#__PURE__*/(() => {\n const nodeRealPath = /*#__PURE__*/effectify(NFS.realpath, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"realPath\"), /*#__PURE__*/handleBadArgument(\"realPath\"));\n return path => nodeRealPath(path);\n})();\n// == rename\nconst rename = /*#__PURE__*/(() => {\n const nodeRename = /*#__PURE__*/effectify(NFS.rename, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"rename\"), /*#__PURE__*/handleBadArgument(\"rename\"));\n return (oldPath, newPath) => nodeRename(oldPath, newPath);\n})();\n// == stat\nconst makeFileInfo = stat => ({\n type: stat.isFile() ? \"File\" : stat.isDirectory() ? \"Directory\" : stat.isSymbolicLink() ? \"SymbolicLink\" : stat.isBlockDevice() ? \"BlockDevice\" : stat.isCharacterDevice() ? \"CharacterDevice\" : stat.isFIFO() ? \"FIFO\" : stat.isSocket() ? \"Socket\" : \"Unknown\",\n mtime: Option.fromNullable(stat.mtime),\n atime: Option.fromNullable(stat.atime),\n birthtime: Option.fromNullable(stat.birthtime),\n dev: stat.dev,\n rdev: Option.fromNullable(stat.rdev),\n ino: Option.fromNullable(stat.ino),\n mode: stat.mode,\n nlink: Option.fromNullable(stat.nlink),\n uid: Option.fromNullable(stat.uid),\n gid: Option.fromNullable(stat.gid),\n size: FileSystem.Size(stat.size),\n blksize: Option.map(Option.fromNullable(stat.blksize), FileSystem.Size),\n blocks: Option.fromNullable(stat.blocks)\n});\nconst stat = /*#__PURE__*/(() => {\n const nodeStat = /*#__PURE__*/effectify(NFS.stat, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"stat\"), /*#__PURE__*/handleBadArgument(\"stat\"));\n return path => Effect.map(nodeStat(path), makeFileInfo);\n})();\n// == symlink\nconst symlink = /*#__PURE__*/(() => {\n const nodeSymlink = /*#__PURE__*/effectify(NFS.symlink, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"symlink\"), /*#__PURE__*/handleBadArgument(\"symlink\"));\n return (target, path) => nodeSymlink(target, path);\n})();\n// == truncate\nconst truncate = /*#__PURE__*/(() => {\n const nodeTruncate = /*#__PURE__*/effectify(NFS.truncate, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"truncate\"), /*#__PURE__*/handleBadArgument(\"truncate\"));\n return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);\n})();\n// == utimes\nconst utimes = /*#__PURE__*/(() => {\n const nodeUtimes = /*#__PURE__*/effectify(NFS.utimes, /*#__PURE__*/handleErrnoException(\"FileSystem\", \"utime\"), /*#__PURE__*/handleBadArgument(\"utime\"));\n return (path, atime, mtime) => nodeUtimes(path, atime, mtime);\n})();\n// == watch\nconst watchNode = (path, options) => Stream.asyncScoped(emit => Effect.acquireRelease(Effect.sync(() => {\n const watcher = NFS.watch(path, {\n recursive: options?.recursive\n }, (event, path) => {\n if (!path) return;\n switch (event) {\n case \"rename\":\n {\n emit.fromEffect(Effect.matchEffect(stat(path), {\n onSuccess: _ => Effect.succeed(FileSystem.WatchEventCreate({\n path\n })),\n onFailure: err => err._tag === \"SystemError\" && err.reason === \"NotFound\" ? Effect.succeed(FileSystem.WatchEventRemove({\n path\n })) : Effect.fail(err)\n }));\n return;\n }\n case \"change\":\n {\n emit.single(FileSystem.WatchEventUpdate({\n path\n }));\n return;\n }\n }\n });\n watcher.on(\"error\", error => {\n emit.fail(new Error.SystemError({\n module: \"FileSystem\",\n reason: \"Unknown\",\n method: \"watch\",\n pathOrDescriptor: path,\n cause: error\n }));\n });\n watcher.on(\"close\", () => {\n emit.end();\n });\n return watcher;\n}), watcher => Effect.sync(() => watcher.close())));\nconst 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);\n// == writeFile\nconst writeFile = (path, data, options) => Effect.async((resume, signal) => {\n try {\n NFS.writeFile(path, data, {\n signal,\n flag: options?.flag,\n mode: options?.mode\n }, err => {\n if (err) {\n resume(Effect.fail(handleErrnoException(\"FileSystem\", \"writeFile\")(err, [path])));\n } else {\n resume(Effect.void);\n }\n });\n } catch (err) {\n resume(Effect.fail(handleBadArgument(\"writeFile\")(err)));\n }\n});\nconst makeFileSystem = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.serviceOption(FileSystem.WatchBackend), backend => FileSystem.make({\n access,\n chmod,\n chown,\n copy,\n copyFile,\n link,\n makeDirectory,\n makeTempDirectory,\n makeTempDirectoryScoped,\n makeTempFile,\n makeTempFileScoped,\n open,\n readDirectory,\n readFile,\n readLink,\n realPath,\n remove,\n rename,\n stat,\n symlink,\n truncate,\n utimes,\n watch(path, options) {\n return watch(backend, path, options);\n },\n writeFile\n}));\n/** @internal */\nexport const layer = /*#__PURE__*/Layer.effect(FileSystem.FileSystem, makeFileSystem);\n//# sourceMappingURL=fileSystem.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;AAaA,MAAM,qBAAoB,YAAU,UAAS,IAAI,MAAM,YAAY;CACjE,QAAQ;CACR;CACA;CACD,CAAC;AAEF,MAAM,SAAsB,uBAAO;CACjC,MAAM,aAA0B,0BAAU,IAAI,QAAqB,qCAAqB,cAAc,SAAS,EAAe,kCAAkB,SAAS,CAAC;AAC1J,SAAQ,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O;AAElN,MAAM,aAAa,MAAM,MAAM,YAAY,OAAO,OAAO,QAAQ,WAAW;AAC1E,KAAI;AACF,MAAI,UAAU,MAAM,MAAM;GACxB;GACA,MAAM,SAAS;GACf,MAAM,SAAS;GAChB,GAAE,QAAO;AACR,OAAI,IACF,QAAO,OAAO,KAAK,qBAAqB,cAAc,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;OAEjF,QAAO,OAAO,KAAK;IAErB;UACK,KAAK;AACZ,SAAO,OAAO,KAAK,kBAAkB,YAAY,CAAC,IAAI,CAAC,CAAC;;EAE1D;AACF,MAAM,iBAA8B,uBAAO,IAAiB,uBAAO,cAAc,WAAW,aAAa,GAAE,YAAW,WAAW,KAAK;CACpI;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM,MAAM,SAAS;AACnB,SAAO,MAAM,SAAS,MAAM,QAAQ;;CAEtC;CACD,CAAC,CAAC;;AAEH,MAAa,QAAqB,sBAAM,OAAO,WAAW,YAAY,eAAe"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import { BadArgument } from "@effect/platform/Error";
|
|
4
|
+
import * as NodePath from "node:path";
|
|
5
|
+
import * as NodeUrl from "node:url";
|
|
6
|
+
import { Path, TypeId } from "@effect/platform/Path";
|
|
7
|
+
|
|
8
|
+
//#region ../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.js
|
|
9
|
+
const fromFileUrl = (url) => Effect.try({
|
|
10
|
+
try: () => NodeUrl.fileURLToPath(url),
|
|
11
|
+
catch: (error) => new BadArgument({
|
|
12
|
+
module: "Path",
|
|
13
|
+
method: "fromFileUrl",
|
|
14
|
+
description: `Invalid file URL: ${url}`,
|
|
15
|
+
cause: error
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
const toFileUrl = (path) => Effect.try({
|
|
19
|
+
try: () => NodeUrl.pathToFileURL(path),
|
|
20
|
+
catch: (error) => new BadArgument({
|
|
21
|
+
module: "Path",
|
|
22
|
+
method: "toFileUrl",
|
|
23
|
+
description: `Invalid path: ${path}`,
|
|
24
|
+
cause: error
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
/** @internal */
|
|
28
|
+
const layerPosix = /* @__PURE__ */ Layer.succeed(Path, /* @__PURE__ */ Path.of({
|
|
29
|
+
[TypeId]: TypeId,
|
|
30
|
+
...NodePath.posix,
|
|
31
|
+
fromFileUrl,
|
|
32
|
+
toFileUrl
|
|
33
|
+
}));
|
|
34
|
+
/** @internal */
|
|
35
|
+
const layerWin32 = /* @__PURE__ */ Layer.succeed(Path, /* @__PURE__ */ Path.of({
|
|
36
|
+
[TypeId]: TypeId,
|
|
37
|
+
...NodePath.win32,
|
|
38
|
+
fromFileUrl,
|
|
39
|
+
toFileUrl
|
|
40
|
+
}));
|
|
41
|
+
/** @internal */
|
|
42
|
+
const layer = /* @__PURE__ */ Layer.succeed(Path, /* @__PURE__ */ Path.of({
|
|
43
|
+
[TypeId]: TypeId,
|
|
44
|
+
...NodePath,
|
|
45
|
+
fromFileUrl,
|
|
46
|
+
toFileUrl
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { layer, layerPosix, layerWin32 };
|
|
51
|
+
//# sourceMappingURL=path.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.mjs","names":[],"sources":["../../../../../../../../../../../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/path.js"],"sourcesContent":["import { BadArgument } from \"@effect/platform/Error\";\nimport { Path, TypeId } from \"@effect/platform/Path\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as NodePath from \"node:path\";\nimport * as NodeUrl from \"node:url\";\nconst fromFileUrl = url => Effect.try({\n try: () => NodeUrl.fileURLToPath(url),\n catch: error => new BadArgument({\n module: \"Path\",\n method: \"fromFileUrl\",\n description: `Invalid file URL: ${url}`,\n cause: error\n })\n});\nconst toFileUrl = path => Effect.try({\n try: () => NodeUrl.pathToFileURL(path),\n catch: error => new BadArgument({\n module: \"Path\",\n method: \"toFileUrl\",\n description: `Invalid path: ${path}`,\n cause: error\n })\n});\n/** @internal */\nexport const layerPosix = /*#__PURE__*/Layer.succeed(Path, /*#__PURE__*/Path.of({\n [TypeId]: TypeId,\n ...NodePath.posix,\n fromFileUrl,\n toFileUrl\n}));\n/** @internal */\nexport const layerWin32 = /*#__PURE__*/Layer.succeed(Path, /*#__PURE__*/Path.of({\n [TypeId]: TypeId,\n ...NodePath.win32,\n fromFileUrl,\n toFileUrl\n}));\n/** @internal */\nexport const layer = /*#__PURE__*/Layer.succeed(Path, /*#__PURE__*/Path.of({\n [TypeId]: TypeId,\n ...NodePath,\n fromFileUrl,\n toFileUrl\n}));\n//# sourceMappingURL=path.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;AAMA,MAAM,eAAc,QAAO,OAAO,IAAI;CACpC,WAAW,QAAQ,cAAc,IAAI;CACrC,QAAO,UAAS,IAAI,YAAY;EAC9B,QAAQ;EACR,QAAQ;EACR,aAAa,qBAAqB;EAClC,OAAO;EACR,CAAC;CACH,CAAC;AACF,MAAM,aAAY,SAAQ,OAAO,IAAI;CACnC,WAAW,QAAQ,cAAc,KAAK;CACtC,QAAO,UAAS,IAAI,YAAY;EAC9B,QAAQ;EACR,QAAQ;EACR,aAAa,iBAAiB;EAC9B,OAAO;EACR,CAAC;CACH,CAAC;;AAEF,MAAa,aAA0B,sBAAM,QAAQ,MAAmB,qBAAK,GAAG;EAC7E,SAAS;CACV,GAAG,SAAS;CACZ;CACA;CACD,CAAC,CAAC;;AAEH,MAAa,aAA0B,sBAAM,QAAQ,MAAmB,qBAAK,GAAG;EAC7E,SAAS;CACV,GAAG,SAAS;CACZ;CACA;CACD,CAAC,CAAC;;AAEH,MAAa,QAAqB,sBAAM,QAAQ,MAAmB,qBAAK,GAAG;EACxE,SAAS;CACV,GAAG;CACH;CACA;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { constVoid } from "effect/Function";
|
|
2
|
+
import { makeRunMain } from "@effect/platform/Runtime";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.js
|
|
5
|
+
/** @internal */
|
|
6
|
+
const runMain = /* @__PURE__ */ makeRunMain(({ fiber, teardown }) => {
|
|
7
|
+
const keepAlive = setInterval(constVoid, 2 ** 31 - 1);
|
|
8
|
+
let receivedSignal = false;
|
|
9
|
+
fiber.addObserver((exit) => {
|
|
10
|
+
if (!receivedSignal) {
|
|
11
|
+
process.removeListener("SIGINT", onSigint);
|
|
12
|
+
process.removeListener("SIGTERM", onSigint);
|
|
13
|
+
}
|
|
14
|
+
clearInterval(keepAlive);
|
|
15
|
+
teardown(exit, (code) => {
|
|
16
|
+
if (receivedSignal || code !== 0) process.exit(code);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
function onSigint() {
|
|
20
|
+
receivedSignal = true;
|
|
21
|
+
process.removeListener("SIGINT", onSigint);
|
|
22
|
+
process.removeListener("SIGTERM", onSigint);
|
|
23
|
+
fiber.unsafeInterruptAsFork(fiber.id());
|
|
24
|
+
}
|
|
25
|
+
process.on("SIGINT", onSigint);
|
|
26
|
+
process.on("SIGTERM", onSigint);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { runMain };
|
|
31
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../../../../../../../../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/runtime.js"],"sourcesContent":["import { makeRunMain } from \"@effect/platform/Runtime\";\nimport { constVoid } from \"effect/Function\";\n/** @internal */\nexport const runMain = /*#__PURE__*/makeRunMain(({\n fiber,\n teardown\n}) => {\n const keepAlive = setInterval(constVoid, 2 ** 31 - 1);\n let receivedSignal = false;\n fiber.addObserver(exit => {\n if (!receivedSignal) {\n process.removeListener(\"SIGINT\", onSigint);\n process.removeListener(\"SIGTERM\", onSigint);\n }\n clearInterval(keepAlive);\n teardown(exit, code => {\n if (receivedSignal || code !== 0) {\n process.exit(code);\n }\n });\n });\n function onSigint() {\n receivedSignal = true;\n process.removeListener(\"SIGINT\", onSigint);\n process.removeListener(\"SIGTERM\", onSigint);\n fiber.unsafeInterruptAsFork(fiber.id());\n }\n process.on(\"SIGINT\", onSigint);\n process.on(\"SIGTERM\", onSigint);\n});\n//# sourceMappingURL=runtime.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;AAGA,MAAa,UAAuB,6BAAa,EAC/C,OACA,eACI;CACJ,MAAM,YAAY,YAAY,WAAW,KAAK,KAAK,EAAE;CACrD,IAAI,iBAAiB;AACrB,OAAM,aAAY,SAAQ;AACxB,MAAI,CAAC,gBAAgB;AACnB,WAAQ,eAAe,UAAU,SAAS;AAC1C,WAAQ,eAAe,WAAW,SAAS;;AAE7C,gBAAc,UAAU;AACxB,WAAS,OAAM,SAAQ;AACrB,OAAI,kBAAkB,SAAS,EAC7B,SAAQ,KAAK,KAAK;IAEpB;GACF;CACF,SAAS,WAAW;AAClB,mBAAiB;AACjB,UAAQ,eAAe,UAAU,SAAS;AAC1C,UAAQ,eAAe,WAAW,SAAS;AAC3C,QAAM,sBAAsB,MAAM,IAAI,CAAC;;AAEzC,SAAQ,GAAG,UAAU,SAAS;AAC9B,SAAQ,GAAG,WAAW,SAAS;EAC/B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { writeInput } from "./stream.mjs";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Deferred from "effect/Deferred";
|
|
4
|
+
import * as Channel from "effect/Channel";
|
|
5
|
+
import * as Sink from "effect/Sink";
|
|
6
|
+
|
|
7
|
+
//#region ../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.js
|
|
8
|
+
/** @internal */
|
|
9
|
+
const fromWritable = (evaluate, onError, options) => Sink.fromChannel(fromWritableChannel(evaluate, onError, options));
|
|
10
|
+
/** @internal */
|
|
11
|
+
const fromWritableChannel = (writable, onError, options) => Channel.flatMap(Effect.zip(Effect.sync(() => writable()), Deferred.make()), ([writable$1, deferred]) => Channel.embedInput(writableOutput(writable$1, deferred, onError), writeInput(writable$1, (cause) => Deferred.failCause(deferred, cause), options, Deferred.complete(deferred, Effect.void))));
|
|
12
|
+
const writableOutput = (writable, deferred, onError) => Effect.suspend(() => {
|
|
13
|
+
function handleError(err) {
|
|
14
|
+
Deferred.unsafeDone(deferred, Effect.fail(onError(err)));
|
|
15
|
+
}
|
|
16
|
+
writable.on("error", handleError);
|
|
17
|
+
return Effect.ensuring(Deferred.await(deferred), Effect.sync(() => {
|
|
18
|
+
writable.removeListener("error", handleError);
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { fromWritable };
|
|
24
|
+
//# sourceMappingURL=sink.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink.mjs","names":["writable"],"sources":["../../../../../../../../../../../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/sink.js"],"sourcesContent":["import * as Channel from \"effect/Channel\";\nimport * as Deferred from \"effect/Deferred\";\nimport * as Effect from \"effect/Effect\";\nimport * as Sink from \"effect/Sink\";\nimport { writeInput } from \"./stream.js\";\n/** @internal */\nexport const fromWritable = (evaluate, onError, options) => Sink.fromChannel(fromWritableChannel(evaluate, onError, options));\n/** @internal */\nexport const fromWritableChannel = (writable, onError, options) => Channel.flatMap(Effect.zip(Effect.sync(() => writable()), Deferred.make()), ([writable, deferred]) => Channel.embedInput(writableOutput(writable, deferred, onError), writeInput(writable, cause => Deferred.failCause(deferred, cause), options, Deferred.complete(deferred, Effect.void))));\nconst writableOutput = (writable, deferred, onError) => Effect.suspend(() => {\n function handleError(err) {\n Deferred.unsafeDone(deferred, Effect.fail(onError(err)));\n }\n writable.on(\"error\", handleError);\n return Effect.ensuring(Deferred.await(deferred), Effect.sync(() => {\n writable.removeListener(\"error\", handleError);\n }));\n});\n//# sourceMappingURL=sink.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;AAMA,MAAa,gBAAgB,UAAU,SAAS,YAAY,KAAK,YAAY,oBAAoB,UAAU,SAAS,QAAQ,CAAC;;AAE7H,MAAa,uBAAuB,UAAU,SAAS,YAAY,QAAQ,QAAQ,OAAO,IAAI,OAAO,WAAW,UAAU,CAAC,EAAE,SAAS,MAAM,CAAC,GAAG,CAACA,YAAU,cAAc,QAAQ,WAAW,eAAeA,YAAU,UAAU,QAAQ,EAAE,WAAWA,aAAU,UAAS,SAAS,UAAU,UAAU,MAAM,EAAE,SAAS,SAAS,SAAS,UAAU,OAAO,KAAK,CAAC,CAAC,CAAC;AAChW,MAAM,kBAAkB,UAAU,UAAU,YAAY,OAAO,cAAc;CAC3E,SAAS,YAAY,KAAK;AACxB,WAAS,WAAW,UAAU,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC;;AAE1D,UAAS,GAAG,SAAS,YAAY;AACjC,QAAO,OAAO,SAAS,SAAS,MAAM,SAAS,EAAE,OAAO,WAAW;AACjE,WAAS,eAAe,SAAS,YAAY;GAC7C,CAAC;EACH"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import "effect/Cause";
|
|
2
|
+
import * as Chunk from "effect/Chunk";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Exit from "effect/Exit";
|
|
5
|
+
import "effect/Fiber";
|
|
6
|
+
import "effect/Function";
|
|
7
|
+
import "effect/Runtime";
|
|
8
|
+
import * as Stream from "effect/Stream";
|
|
9
|
+
import * as MutableRef from "effect/MutableRef";
|
|
10
|
+
import * as Channel from "effect/Channel";
|
|
11
|
+
import { SystemError } from "@effect/platform/Error";
|
|
12
|
+
|
|
13
|
+
//#region ../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.js
|
|
14
|
+
/** @internal */
|
|
15
|
+
const fromReadable = (evaluate, onError, options) => Stream.fromChannel(fromReadableChannel(evaluate, onError, options));
|
|
16
|
+
/** @internal */
|
|
17
|
+
const fromReadableChannel = (evaluate, onError, options) => Channel.suspend(() => unsafeReadableRead(evaluate(), onError, MutableRef.make(void 0), options));
|
|
18
|
+
/** @internal */
|
|
19
|
+
const writeInput = (writable, onFailure, { encoding, endOnDone = true } = {}, onDone = Effect.void) => {
|
|
20
|
+
const write = writeEffect(writable, encoding);
|
|
21
|
+
const close = endOnDone ? Effect.async((resume) => {
|
|
22
|
+
if ("closed" in writable && writable.closed) resume(Effect.void);
|
|
23
|
+
else {
|
|
24
|
+
writable.once("finish", () => resume(Effect.void));
|
|
25
|
+
writable.end();
|
|
26
|
+
}
|
|
27
|
+
}) : Effect.void;
|
|
28
|
+
return {
|
|
29
|
+
awaitRead: () => Effect.void,
|
|
30
|
+
emit: write,
|
|
31
|
+
error: (cause) => Effect.zipRight(close, onFailure(cause)),
|
|
32
|
+
done: (_) => Effect.zipRight(close, onDone)
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** @internal */
|
|
36
|
+
const writeEffect = (writable, encoding) => (chunk) => chunk.length === 0 ? Effect.void : Effect.async((resume) => {
|
|
37
|
+
const iterator = chunk[Symbol.iterator]();
|
|
38
|
+
let next = iterator.next();
|
|
39
|
+
function loop() {
|
|
40
|
+
const item = next;
|
|
41
|
+
next = iterator.next();
|
|
42
|
+
const success = writable.write(item.value, encoding);
|
|
43
|
+
if (next.done) resume(Effect.void);
|
|
44
|
+
else if (success) loop();
|
|
45
|
+
else writable.once("drain", loop);
|
|
46
|
+
}
|
|
47
|
+
loop();
|
|
48
|
+
});
|
|
49
|
+
const unsafeReadableRead = (readable, onError, exit, options) => {
|
|
50
|
+
if (!readable.readable) return Channel.void;
|
|
51
|
+
const latch = Effect.unsafeMakeLatch(false);
|
|
52
|
+
function onReadable() {
|
|
53
|
+
latch.unsafeOpen();
|
|
54
|
+
}
|
|
55
|
+
function onErr(err) {
|
|
56
|
+
exit.current = Exit.fail(onError(err));
|
|
57
|
+
latch.unsafeOpen();
|
|
58
|
+
}
|
|
59
|
+
function onEnd() {
|
|
60
|
+
exit.current = Exit.void;
|
|
61
|
+
latch.unsafeOpen();
|
|
62
|
+
}
|
|
63
|
+
readable.on("readable", onReadable);
|
|
64
|
+
readable.on("error", onErr);
|
|
65
|
+
readable.on("end", onEnd);
|
|
66
|
+
const chunkSize = options?.chunkSize ? Number(options.chunkSize) : void 0;
|
|
67
|
+
const read = Channel.suspend(function loop() {
|
|
68
|
+
let item = readable.read(chunkSize);
|
|
69
|
+
if (item === null) {
|
|
70
|
+
if (exit.current) return Channel.fromEffect(exit.current);
|
|
71
|
+
latch.unsafeClose();
|
|
72
|
+
return Channel.flatMap(latch.await, loop);
|
|
73
|
+
}
|
|
74
|
+
const arr = [item];
|
|
75
|
+
while (true) {
|
|
76
|
+
item = readable.read(chunkSize);
|
|
77
|
+
if (item === null) return Channel.flatMap(Channel.write(Chunk.unsafeFromArray(arr)), loop);
|
|
78
|
+
arr.push(item);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return Channel.ensuring(read, Effect.sync(() => {
|
|
82
|
+
readable.off("readable", onReadable);
|
|
83
|
+
readable.off("error", onErr);
|
|
84
|
+
readable.off("end", onEnd);
|
|
85
|
+
if (options?.closeOnDone !== false && "closed" in readable && !readable.closed) readable.destroy();
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { fromReadable, writeInput };
|
|
91
|
+
//# sourceMappingURL=stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.mjs","names":[],"sources":["../../../../../../../../../../../../node_modules/.pnpm/@effect+platform-node-shared@0.53.0_@effect+cluster@0.52.9_@effect+platform@0.93.2_effe_e0eeb3aae5ffec3060feb87d17ffb17c/node_modules/@effect/platform-node-shared/dist/esm/internal/stream.js"],"sourcesContent":["import { SystemError } from \"@effect/platform/Error\";\nimport * as Cause from \"effect/Cause\";\nimport * as Channel from \"effect/Channel\";\nimport * as Chunk from \"effect/Chunk\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Fiber from \"effect/Fiber\";\nimport { dual } from \"effect/Function\";\nimport * as MutableRef from \"effect/MutableRef\";\nimport * as Runtime from \"effect/Runtime\";\nimport * as Stream from \"effect/Stream\";\nimport { Readable } from \"node:stream\";\n/** @internal */\nexport const fromReadable = (evaluate, onError, options) => Stream.fromChannel(fromReadableChannel(evaluate, onError, options));\n/** @internal */\nexport const toString = (readable, options) => {\n const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;\n return Effect.acquireUseRelease(Effect.sync(() => {\n const stream = readable();\n stream.setEncoding(options.encoding ?? \"utf8\");\n return stream;\n }), stream => Effect.async(resume => {\n let string = \"\";\n let bytes = 0;\n stream.once(\"error\", err => {\n resume(Effect.fail(options.onFailure(err)));\n });\n stream.once(\"end\", () => {\n resume(Effect.succeed(string));\n });\n stream.on(\"data\", chunk => {\n string += chunk;\n bytes += Buffer.byteLength(chunk);\n if (maxBytesNumber && bytes > maxBytesNumber) {\n resume(Effect.fail(options.onFailure(new Error(\"maxBytes exceeded\"))));\n }\n });\n }), stream => Effect.sync(() => {\n if (\"closed\" in stream && !stream.closed) {\n stream.destroy();\n }\n }));\n};\n/** @internal */\nexport const toUint8Array = (readable, options) => {\n const maxBytesNumber = options.maxBytes ? Number(options.maxBytes) : undefined;\n return Effect.acquireUseRelease(Effect.sync(readable), stream => Effect.async(resume => {\n let buffer = Buffer.alloc(0);\n let bytes = 0;\n stream.once(\"error\", err => {\n resume(Effect.fail(options.onFailure(err)));\n });\n stream.once(\"end\", () => {\n resume(Effect.succeed(buffer));\n });\n stream.on(\"data\", chunk => {\n buffer = Buffer.concat([buffer, chunk]);\n bytes += chunk.length;\n if (maxBytesNumber && bytes > maxBytesNumber) {\n resume(Effect.fail(options.onFailure(new Error(\"maxBytes exceeded\"))));\n }\n });\n }), stream => Effect.sync(() => {\n if (\"closed\" in stream && !stream.closed) {\n stream.destroy();\n }\n }));\n};\n/** @internal */\nexport const fromDuplex = (evaluate, onError, options) => Channel.suspend(() => {\n const duplex = evaluate();\n if (!duplex.readable) {\n return Channel.void;\n }\n const exit = MutableRef.make(undefined);\n return Channel.embedInput(unsafeReadableRead(duplex, onError, exit, options), writeInput(duplex, cause => Effect.sync(() => MutableRef.set(exit, Exit.failCause(cause))), options));\n});\n/** @internal */\nexport const pipeThroughDuplex = /*#__PURE__*/dual(args => Stream.StreamTypeId in args[0], (self, duplex, onError, options) => Stream.pipeThroughChannelOrFail(self, fromDuplex(duplex, onError, options)));\n/** @internal */\nexport const pipeThroughSimple = /*#__PURE__*/dual(2, (self, duplex) => Stream.pipeThroughChannelOrFail(self, fromDuplex(duplex, cause => new SystemError({\n module: \"Stream\",\n method: \"pipeThroughSimple\",\n reason: \"Unknown\",\n cause\n}))));\n/** @internal */\nexport const fromReadableChannel = (evaluate, onError, options) => Channel.suspend(() => unsafeReadableRead(evaluate(), onError, MutableRef.make(undefined), options));\n/** @internal */\nexport const writeInput = (writable, onFailure, {\n encoding,\n endOnDone = true\n} = {}, onDone = Effect.void) => {\n const write = writeEffect(writable, encoding);\n const close = endOnDone ? Effect.async(resume => {\n if (\"closed\" in writable && writable.closed) {\n resume(Effect.void);\n } else {\n writable.once(\"finish\", () => resume(Effect.void));\n writable.end();\n }\n }) : Effect.void;\n return {\n awaitRead: () => Effect.void,\n emit: write,\n error: cause => Effect.zipRight(close, onFailure(cause)),\n done: _ => Effect.zipRight(close, onDone)\n };\n};\n/** @internal */\nexport const writeEffect = (writable, encoding) => chunk => chunk.length === 0 ? Effect.void : Effect.async(resume => {\n const iterator = chunk[Symbol.iterator]();\n let next = iterator.next();\n function loop() {\n const item = next;\n next = iterator.next();\n const success = writable.write(item.value, encoding);\n if (next.done) {\n resume(Effect.void);\n } else if (success) {\n loop();\n } else {\n writable.once(\"drain\", loop);\n }\n }\n loop();\n});\nconst unsafeReadableRead = (readable, onError, exit, options) => {\n if (!readable.readable) {\n return Channel.void;\n }\n const latch = Effect.unsafeMakeLatch(false);\n function onReadable() {\n latch.unsafeOpen();\n }\n function onErr(err) {\n exit.current = Exit.fail(onError(err));\n latch.unsafeOpen();\n }\n function onEnd() {\n exit.current = Exit.void;\n latch.unsafeOpen();\n }\n readable.on(\"readable\", onReadable);\n readable.on(\"error\", onErr);\n readable.on(\"end\", onEnd);\n const chunkSize = options?.chunkSize ? Number(options.chunkSize) : undefined;\n const read = Channel.suspend(function loop() {\n let item = readable.read(chunkSize);\n if (item === null) {\n if (exit.current) {\n return Channel.fromEffect(exit.current);\n }\n latch.unsafeClose();\n return Channel.flatMap(latch.await, loop);\n }\n const arr = [item];\n while (true) {\n item = readable.read(chunkSize);\n if (item === null) {\n return Channel.flatMap(Channel.write(Chunk.unsafeFromArray(arr)), loop);\n }\n arr.push(item);\n }\n });\n return Channel.ensuring(read, Effect.sync(() => {\n readable.off(\"readable\", onReadable);\n readable.off(\"error\", onErr);\n readable.off(\"end\", onEnd);\n if (options?.closeOnDone !== false && \"closed\" in readable && !readable.closed) {\n readable.destroy();\n }\n }));\n};\nclass StreamAdapter extends Readable {\n readLatch;\n fiber = undefined;\n constructor(runtime, stream) {\n super({});\n this.readLatch = Effect.unsafeMakeLatch(false);\n this.fiber = Runtime.runFork(runtime)(this.readLatch.whenOpen(Stream.runForEachChunk(stream, chunk => this.readLatch.whenOpen(Effect.sync(() => {\n if (chunk.length === 0) return;\n this.readLatch.unsafeClose();\n for (const item of chunk) {\n if (typeof item === \"string\") {\n this.push(item, \"utf8\");\n } else {\n this.push(item);\n }\n }\n })))));\n this.fiber.addObserver(exit => {\n this.fiber = undefined;\n if (Exit.isSuccess(exit)) {\n this.push(null);\n } else {\n this.destroy(Cause.squash(exit.cause));\n }\n });\n }\n _read(_size) {\n this.readLatch.unsafeOpen();\n }\n _destroy(error, callback) {\n if (!this.fiber) {\n return callback(error);\n }\n Effect.runFork(Fiber.interrupt(this.fiber)).addObserver(exit => {\n callback(exit._tag === \"Failure\" ? Cause.squash(exit.cause) : error);\n });\n }\n}\n/** @internal */\nexport const toReadable = stream => Effect.map(Effect.runtime(), runtime => new StreamAdapter(runtime, stream));\n/** @internal */\nexport const toReadableNever = stream => new StreamAdapter(Runtime.defaultRuntime, stream);\n//# sourceMappingURL=stream.js.map"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,gBAAgB,UAAU,SAAS,YAAY,OAAO,YAAY,oBAAoB,UAAU,SAAS,QAAQ,CAAC;;AA0E/H,M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