@maria_rcks/t1code 0.0.5 → 0.0.7
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/bin/t1code.js +38 -4
- package/dist/index.mjs +10 -4
- package/dist/server/BunPTY-tfevpp75.js +114 -0
- package/dist/server/NodePTY-shw8pxrb.js +115 -0
- package/dist/server/NodeSqliteClient-1zz4vbn2.js +180 -0
- package/dist/server/SqliteClient-53018gfq.js +147 -0
- package/dist/server/index-313s4ptc.js +18 -0
- package/dist/server/index-8anfbrkb.js +844 -0
- package/dist/server/index-9kq36ye2.js +584 -0
- package/dist/server/index-jgecjkfd.js +34490 -0
- package/dist/server/index-wckvcay0.js +48 -0
- package/dist/server/index-wrajk4wc.js +523 -0
- package/dist/server/index-z7xpvjdt.js +247 -0
- package/dist/server/index.js +56202 -0
- package/dist/server/node_modules/node-pty/LICENSE +69 -0
- package/dist/server/node_modules/node-pty/README.md +165 -0
- package/dist/server/node_modules/node-pty/lib/conpty_console_list_agent.js +16 -0
- package/dist/server/node_modules/node-pty/lib/conpty_console_list_agent.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/eventEmitter2.js +47 -0
- package/dist/server/node_modules/node-pty/lib/eventEmitter2.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/eventEmitter2.test.js +30 -0
- package/dist/server/node_modules/node-pty/lib/eventEmitter2.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/index.js +52 -0
- package/dist/server/node_modules/node-pty/lib/index.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/interfaces.js +7 -0
- package/dist/server/node_modules/node-pty/lib/interfaces.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/shared/conout.js +11 -0
- package/dist/server/node_modules/node-pty/lib/shared/conout.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/terminal.js +190 -0
- package/dist/server/node_modules/node-pty/lib/terminal.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/terminal.test.js +139 -0
- package/dist/server/node_modules/node-pty/lib/terminal.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/testUtils.test.js +28 -0
- package/dist/server/node_modules/node-pty/lib/testUtils.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/types.js +7 -0
- package/dist/server/node_modules/node-pty/lib/types.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/unixTerminal.js +346 -0
- package/dist/server/node_modules/node-pty/lib/unixTerminal.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/unixTerminal.test.js +351 -0
- package/dist/server/node_modules/node-pty/lib/unixTerminal.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/utils.js +39 -0
- package/dist/server/node_modules/node-pty/lib/utils.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/windowsConoutConnection.js +125 -0
- package/dist/server/node_modules/node-pty/lib/windowsConoutConnection.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/windowsPtyAgent.js +320 -0
- package/dist/server/node_modules/node-pty/lib/windowsPtyAgent.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/windowsPtyAgent.test.js +90 -0
- package/dist/server/node_modules/node-pty/lib/windowsPtyAgent.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/windowsTerminal.js +199 -0
- package/dist/server/node_modules/node-pty/lib/windowsTerminal.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/windowsTerminal.test.js +219 -0
- package/dist/server/node_modules/node-pty/lib/windowsTerminal.test.js.map +1 -0
- package/dist/server/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/dist/server/node_modules/node-pty/lib/worker/conoutSocketWorker.js.map +1 -0
- package/dist/server/node_modules/node-pty/package.json +64 -0
- package/dist/server/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/conpty_console_list.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/pty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/pty.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/winpty-agent.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-arm64/winpty.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/conpty_console_list.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/pty.node +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/pty.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/winpty-agent.pdb +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
- package/dist/server/node_modules/node-pty/prebuilds/win32-x64/winpty.pdb +0 -0
- package/dist/server/node_modules/node-pty/typings/node-pty.d.ts +211 -0
- package/package.json +3 -2
- package/dist/server/BunPTY-BulfMn1P.cjs +0 -92
- package/dist/server/BunPTY-BulfMn1P.cjs.map +0 -1
- package/dist/server/BunPTY-Cueq2gzZ.mjs +0 -92
- package/dist/server/BunPTY-Cueq2gzZ.mjs.map +0 -1
- package/dist/server/NodePTY-AdcStdsu.mjs +0 -86
- package/dist/server/NodePTY-AdcStdsu.mjs.map +0 -1
- package/dist/server/NodePTY-DmqnQV86.cjs +0 -87
- package/dist/server/NodePTY-DmqnQV86.cjs.map +0 -1
- package/dist/server/NodeSqliteClient-BTK-dUey.mjs +0 -156
- package/dist/server/NodeSqliteClient-BTK-dUey.mjs.map +0 -1
- package/dist/server/NodeSqliteClient-ViK8pcdH.cjs +0 -174
- package/dist/server/NodeSqliteClient-ViK8pcdH.cjs.map +0 -1
- package/dist/server/index.cjs +0 -20457
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.mjs +0 -20413
- package/dist/server/index.mjs.map +0 -1
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const require_index = require('./index.cjs');
|
|
4
|
-
let effect = require("effect");
|
|
5
|
-
|
|
6
|
-
//#region src/terminal/Layers/BunPTY.ts
|
|
7
|
-
var BunPtyProcess = class {
|
|
8
|
-
dataListeners = /* @__PURE__ */ new Set();
|
|
9
|
-
exitListeners = /* @__PURE__ */ new Set();
|
|
10
|
-
decoder = new TextDecoder();
|
|
11
|
-
didExit = false;
|
|
12
|
-
constructor(process) {
|
|
13
|
-
this.process = process;
|
|
14
|
-
this.process.exited.then((exitCode) => {
|
|
15
|
-
this.emitExit({
|
|
16
|
-
exitCode: Number.isInteger(exitCode) ? exitCode : 0,
|
|
17
|
-
signal: typeof this.process.signalCode === "number" ? this.process.signalCode : null
|
|
18
|
-
});
|
|
19
|
-
}).catch(() => {
|
|
20
|
-
this.emitExit({
|
|
21
|
-
exitCode: 1,
|
|
22
|
-
signal: null
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
get pid() {
|
|
27
|
-
return this.process.pid;
|
|
28
|
-
}
|
|
29
|
-
write(data) {
|
|
30
|
-
if (!this.process.terminal) throw new Error("Bun PTY terminal handle is unavailable");
|
|
31
|
-
this.process.terminal.write(data);
|
|
32
|
-
}
|
|
33
|
-
resize(cols, rows) {
|
|
34
|
-
if (!this.process.terminal?.resize) throw new Error("Bun PTY resize is unavailable");
|
|
35
|
-
this.process.terminal.resize(cols, rows);
|
|
36
|
-
}
|
|
37
|
-
kill(signal) {
|
|
38
|
-
if (!signal) {
|
|
39
|
-
this.process.kill();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.process.kill(signal);
|
|
43
|
-
}
|
|
44
|
-
onData(callback) {
|
|
45
|
-
this.dataListeners.add(callback);
|
|
46
|
-
return () => {
|
|
47
|
-
this.dataListeners.delete(callback);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
onExit(callback) {
|
|
51
|
-
this.exitListeners.add(callback);
|
|
52
|
-
return () => {
|
|
53
|
-
this.exitListeners.delete(callback);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
emitData(data) {
|
|
57
|
-
if (this.didExit) return;
|
|
58
|
-
const text = this.decoder.decode(data, { stream: true });
|
|
59
|
-
if (text.length === 0) return;
|
|
60
|
-
for (const listener of this.dataListeners) listener(text);
|
|
61
|
-
}
|
|
62
|
-
emitExit(event) {
|
|
63
|
-
if (this.didExit) return;
|
|
64
|
-
this.didExit = true;
|
|
65
|
-
const remainder = this.decoder.decode();
|
|
66
|
-
if (remainder.length > 0) for (const listener of this.dataListeners) listener(remainder);
|
|
67
|
-
for (const listener of this.exitListeners) listener(event);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const layer = effect.Layer.effect(require_index.PtyAdapter, effect.Effect.gen(function* () {
|
|
71
|
-
if (process.platform === "win32") return yield* effect.Effect.die("Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.");
|
|
72
|
-
return { spawn: (input) => effect.Effect.sync(() => {
|
|
73
|
-
let processHandle = null;
|
|
74
|
-
const command = [input.shell, ...input.args ?? []];
|
|
75
|
-
processHandle = new BunPtyProcess(Bun.spawn(command, {
|
|
76
|
-
cwd: input.cwd,
|
|
77
|
-
env: input.env,
|
|
78
|
-
terminal: {
|
|
79
|
-
cols: input.cols,
|
|
80
|
-
rows: input.rows,
|
|
81
|
-
data: (_terminal, data) => {
|
|
82
|
-
processHandle?.emitData(data);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
return processHandle;
|
|
87
|
-
}) };
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
exports.layer = layer;
|
|
92
|
-
//# sourceMappingURL=BunPTY-BulfMn1P.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BunPTY-BulfMn1P.cjs","names":["Layer","PtyAdapter","Effect"],"sources":["../src/terminal/Layers/BunPTY.ts"],"sourcesContent":["import { Effect, Layer } from \"effect\";\nimport { PtyAdapter, PtyAdapterShape, PtyExitEvent, PtyProcess } from \"../Services/PTY\";\n\nclass BunPtyProcess implements PtyProcess {\n private readonly dataListeners = new Set<(data: string) => void>();\n private readonly exitListeners = new Set<(event: PtyExitEvent) => void>();\n private readonly decoder = new TextDecoder();\n private didExit = false;\n\n constructor(private readonly process: Bun.Subprocess) {\n void this.process.exited\n .then((exitCode) => {\n this.emitExit({\n exitCode: Number.isInteger(exitCode) ? exitCode : 0,\n signal: typeof this.process.signalCode === \"number\" ? this.process.signalCode : null,\n });\n })\n .catch(() => {\n this.emitExit({ exitCode: 1, signal: null });\n });\n }\n\n get pid(): number {\n return this.process.pid;\n }\n\n write(data: string): void {\n if (!this.process.terminal) {\n throw new Error(\"Bun PTY terminal handle is unavailable\");\n }\n this.process.terminal.write(data);\n }\n\n resize(cols: number, rows: number): void {\n if (!this.process.terminal?.resize) {\n throw new Error(\"Bun PTY resize is unavailable\");\n }\n this.process.terminal.resize(cols, rows);\n }\n\n kill(signal?: string): void {\n if (!signal) {\n this.process.kill();\n return;\n }\n this.process.kill(signal as NodeJS.Signals);\n }\n\n onData(callback: (data: string) => void): () => void {\n this.dataListeners.add(callback);\n return () => {\n this.dataListeners.delete(callback);\n };\n }\n\n onExit(callback: (event: PtyExitEvent) => void): () => void {\n this.exitListeners.add(callback);\n return () => {\n this.exitListeners.delete(callback);\n };\n }\n\n emitData(data: Uint8Array): void {\n if (this.didExit) return;\n const text = this.decoder.decode(data, { stream: true });\n if (text.length === 0) return;\n for (const listener of this.dataListeners) {\n listener(text);\n }\n }\n\n private emitExit(event: PtyExitEvent): void {\n if (this.didExit) return;\n this.didExit = true;\n\n const remainder = this.decoder.decode();\n if (remainder.length > 0) {\n for (const listener of this.dataListeners) {\n listener(remainder);\n }\n }\n\n for (const listener of this.exitListeners) {\n listener(event);\n }\n }\n}\n\nexport const layer = Layer.effect(\n PtyAdapter,\n Effect.gen(function* () {\n if (process.platform === \"win32\") {\n return yield* Effect.die(\n \"Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.\",\n );\n }\n return {\n spawn: (input) =>\n Effect.sync(() => {\n let processHandle: BunPtyProcess | null = null;\n const command = [input.shell, ...(input.args ?? [])];\n const subprocess = Bun.spawn(command, {\n cwd: input.cwd,\n env: input.env,\n terminal: {\n cols: input.cols,\n rows: input.rows,\n data: (_terminal, data) => {\n processHandle?.emitData(data);\n },\n },\n });\n processHandle = new BunPtyProcess(subprocess);\n return processHandle;\n }),\n } satisfies PtyAdapterShape;\n }),\n);\n"],"mappings":";;;;;;AAGA,IAAM,gBAAN,MAA0C;CACxC,AAAiB,gCAA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1C,MAAI,KAAK,QAAS;AAClB,OAAK,UAAU;EAEf,MAAM,YAAY,KAAK,QAAQ,QAAQ;AACvC,MAAI,UAAU,SAAS,EACrB,MAAK,MAAM,YAAY,KAAK,cAC1B,UAAS,UAAU;AAIvB,OAAK,MAAM,YAAY,KAAK,cAC1B,UAAS,MAAM;;;AAKrB,MAAa,QAAQA,aAAM,OACzBC,0BACAC,cAAO,IAAI,aAAa;AACtB,KAAI,QAAQ,aAAa,QACvB,QAAO,OAAOA,cAAO,IACnB,6GACD;AAEH,QAAO,EACL,QAAQ,UACNA,cAAO,WAAW;EAChB,IAAI,gBAAsC;EAC1C,MAAM,UAAU,CAAC,MAAM,OAAO,GAAI,MAAM,QAAQ,EAAE,CAAE;AAYpD,kBAAgB,IAAI,cAXD,IAAI,MAAM,SAAS;GACpC,KAAK,MAAM;GACX,KAAK,MAAM;GACX,UAAU;IACR,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,OAAO,WAAW,SAAS;AACzB,oBAAe,SAAS,KAAK;;IAEhC;GACF,CAAC,CAC2C;AAC7C,SAAO;GACP,EACL;EACD,CACH"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { t as PtyAdapter } from "./index.mjs";
|
|
4
|
-
import { Effect, Layer } from "effect";
|
|
5
|
-
|
|
6
|
-
//#region src/terminal/Layers/BunPTY.ts
|
|
7
|
-
var BunPtyProcess = class {
|
|
8
|
-
dataListeners = /* @__PURE__ */ new Set();
|
|
9
|
-
exitListeners = /* @__PURE__ */ new Set();
|
|
10
|
-
decoder = new TextDecoder();
|
|
11
|
-
didExit = false;
|
|
12
|
-
constructor(process) {
|
|
13
|
-
this.process = process;
|
|
14
|
-
this.process.exited.then((exitCode) => {
|
|
15
|
-
this.emitExit({
|
|
16
|
-
exitCode: Number.isInteger(exitCode) ? exitCode : 0,
|
|
17
|
-
signal: typeof this.process.signalCode === "number" ? this.process.signalCode : null
|
|
18
|
-
});
|
|
19
|
-
}).catch(() => {
|
|
20
|
-
this.emitExit({
|
|
21
|
-
exitCode: 1,
|
|
22
|
-
signal: null
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
get pid() {
|
|
27
|
-
return this.process.pid;
|
|
28
|
-
}
|
|
29
|
-
write(data) {
|
|
30
|
-
if (!this.process.terminal) throw new Error("Bun PTY terminal handle is unavailable");
|
|
31
|
-
this.process.terminal.write(data);
|
|
32
|
-
}
|
|
33
|
-
resize(cols, rows) {
|
|
34
|
-
if (!this.process.terminal?.resize) throw new Error("Bun PTY resize is unavailable");
|
|
35
|
-
this.process.terminal.resize(cols, rows);
|
|
36
|
-
}
|
|
37
|
-
kill(signal) {
|
|
38
|
-
if (!signal) {
|
|
39
|
-
this.process.kill();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.process.kill(signal);
|
|
43
|
-
}
|
|
44
|
-
onData(callback) {
|
|
45
|
-
this.dataListeners.add(callback);
|
|
46
|
-
return () => {
|
|
47
|
-
this.dataListeners.delete(callback);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
onExit(callback) {
|
|
51
|
-
this.exitListeners.add(callback);
|
|
52
|
-
return () => {
|
|
53
|
-
this.exitListeners.delete(callback);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
emitData(data) {
|
|
57
|
-
if (this.didExit) return;
|
|
58
|
-
const text = this.decoder.decode(data, { stream: true });
|
|
59
|
-
if (text.length === 0) return;
|
|
60
|
-
for (const listener of this.dataListeners) listener(text);
|
|
61
|
-
}
|
|
62
|
-
emitExit(event) {
|
|
63
|
-
if (this.didExit) return;
|
|
64
|
-
this.didExit = true;
|
|
65
|
-
const remainder = this.decoder.decode();
|
|
66
|
-
if (remainder.length > 0) for (const listener of this.dataListeners) listener(remainder);
|
|
67
|
-
for (const listener of this.exitListeners) listener(event);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const layer = Layer.effect(PtyAdapter, Effect.gen(function* () {
|
|
71
|
-
if (process.platform === "win32") return yield* Effect.die("Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.");
|
|
72
|
-
return { spawn: (input) => Effect.sync(() => {
|
|
73
|
-
let processHandle = null;
|
|
74
|
-
const command = [input.shell, ...input.args ?? []];
|
|
75
|
-
processHandle = new BunPtyProcess(Bun.spawn(command, {
|
|
76
|
-
cwd: input.cwd,
|
|
77
|
-
env: input.env,
|
|
78
|
-
terminal: {
|
|
79
|
-
cols: input.cols,
|
|
80
|
-
rows: input.rows,
|
|
81
|
-
data: (_terminal, data) => {
|
|
82
|
-
processHandle?.emitData(data);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
return processHandle;
|
|
87
|
-
}) };
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
export { layer };
|
|
92
|
-
//# sourceMappingURL=BunPTY-Cueq2gzZ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BunPTY-Cueq2gzZ.mjs","names":[],"sources":["../src/terminal/Layers/BunPTY.ts"],"sourcesContent":["import { Effect, Layer } from \"effect\";\nimport { PtyAdapter, PtyAdapterShape, PtyExitEvent, PtyProcess } from \"../Services/PTY\";\n\nclass BunPtyProcess implements PtyProcess {\n private readonly dataListeners = new Set<(data: string) => void>();\n private readonly exitListeners = new Set<(event: PtyExitEvent) => void>();\n private readonly decoder = new TextDecoder();\n private didExit = false;\n\n constructor(private readonly process: Bun.Subprocess) {\n void this.process.exited\n .then((exitCode) => {\n this.emitExit({\n exitCode: Number.isInteger(exitCode) ? exitCode : 0,\n signal: typeof this.process.signalCode === \"number\" ? this.process.signalCode : null,\n });\n })\n .catch(() => {\n this.emitExit({ exitCode: 1, signal: null });\n });\n }\n\n get pid(): number {\n return this.process.pid;\n }\n\n write(data: string): void {\n if (!this.process.terminal) {\n throw new Error(\"Bun PTY terminal handle is unavailable\");\n }\n this.process.terminal.write(data);\n }\n\n resize(cols: number, rows: number): void {\n if (!this.process.terminal?.resize) {\n throw new Error(\"Bun PTY resize is unavailable\");\n }\n this.process.terminal.resize(cols, rows);\n }\n\n kill(signal?: string): void {\n if (!signal) {\n this.process.kill();\n return;\n }\n this.process.kill(signal as NodeJS.Signals);\n }\n\n onData(callback: (data: string) => void): () => void {\n this.dataListeners.add(callback);\n return () => {\n this.dataListeners.delete(callback);\n };\n }\n\n onExit(callback: (event: PtyExitEvent) => void): () => void {\n this.exitListeners.add(callback);\n return () => {\n this.exitListeners.delete(callback);\n };\n }\n\n emitData(data: Uint8Array): void {\n if (this.didExit) return;\n const text = this.decoder.decode(data, { stream: true });\n if (text.length === 0) return;\n for (const listener of this.dataListeners) {\n listener(text);\n }\n }\n\n private emitExit(event: PtyExitEvent): void {\n if (this.didExit) return;\n this.didExit = true;\n\n const remainder = this.decoder.decode();\n if (remainder.length > 0) {\n for (const listener of this.dataListeners) {\n listener(remainder);\n }\n }\n\n for (const listener of this.exitListeners) {\n listener(event);\n }\n }\n}\n\nexport const layer = Layer.effect(\n PtyAdapter,\n Effect.gen(function* () {\n if (process.platform === \"win32\") {\n return yield* Effect.die(\n \"Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.\",\n );\n }\n return {\n spawn: (input) =>\n Effect.sync(() => {\n let processHandle: BunPtyProcess | null = null;\n const command = [input.shell, ...(input.args ?? [])];\n const subprocess = Bun.spawn(command, {\n cwd: input.cwd,\n env: input.env,\n terminal: {\n cols: input.cols,\n rows: input.rows,\n data: (_terminal, data) => {\n processHandle?.emitData(data);\n },\n },\n });\n processHandle = new BunPtyProcess(subprocess);\n return processHandle;\n }),\n } satisfies PtyAdapterShape;\n }),\n);\n"],"mappings":";;;;;;AAGA,IAAM,gBAAN,MAA0C;CACxC,AAAiB,gCAAgB,IAAI,KAA6B;CAClE,AAAiB,gCAAgB,IAAI,KAAoC;CACzE,AAAiB,UA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Q,QAAQ;AACvC,MAAI,UAAU,SAAS,EACrB,MAAK,MAAM,YAAY,KAAK,cAC1B,UAAS,UAAU;AAIvB,OAAK,MAAM,YAAY,KAAK,cAC1B,UAAS,MAAM;;;AAKrB,MAAa,QAAQ,MAAM,OACzB,YACA,OAAO,IAAI,aAAa;AACtB,KAAI,QAAQ,aAAa,QACvB,QAAO,OAAO,OAAO,IACnB,6GACD;AAEH,QAAO,EACL,QAAQ,UACN,OAAO,WAAW;EAChB,IAAI,gBAAsC;EAC1C,MAAM,UAAU,CAAC,MAAM,OAAO,GAAI,MAAM,QAAQ,EAAE,CAAE;AAYpD,kBAAgB,IAAI,cAXD,IAAI,MAAM,SAAS;GACpC,KAAK,MAAM;GACX,KAAK,MAAM;GACX,UAAU;IACR,MAAM,MAAM;IACZ,MAAM,MAAM;IACZ,OAAO,WAAW,SAAS;AACzB,oBAAe,SAAS,KAAK;;IAEhC;GACF,CAAC,CAC2C;AAC7C,SAAO;GACP,EACL;EACD,CACH"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { t as PtyAdapter } from "./index.mjs";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { Effect, FileSystem, Layer, Path } from "effect";
|
|
6
|
-
|
|
7
|
-
//#region src/terminal/Layers/NodePTY.ts
|
|
8
|
-
let didEnsureSpawnHelperExecutable = false;
|
|
9
|
-
const resolveNodePtySpawnHelperPath = Effect.gen(function* () {
|
|
10
|
-
const requireForNodePty = createRequire(import.meta.url);
|
|
11
|
-
const path = yield* Path.Path;
|
|
12
|
-
const fs = yield* FileSystem.FileSystem;
|
|
13
|
-
const packageJsonPath = requireForNodePty.resolve("node-pty/package.json");
|
|
14
|
-
const packageDir = path.dirname(packageJsonPath);
|
|
15
|
-
const candidates = [
|
|
16
|
-
path.join(packageDir, "build", "Release", "spawn-helper"),
|
|
17
|
-
path.join(packageDir, "build", "Debug", "spawn-helper"),
|
|
18
|
-
path.join(packageDir, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper")
|
|
19
|
-
];
|
|
20
|
-
for (const candidate of candidates) if (yield* fs.exists(candidate)) return candidate;
|
|
21
|
-
return null;
|
|
22
|
-
}).pipe(Effect.orElseSucceed(() => null));
|
|
23
|
-
const ensureNodePtySpawnHelperExecutable = Effect.fn(function* (explicitPath) {
|
|
24
|
-
const fs = yield* FileSystem.FileSystem;
|
|
25
|
-
if (process.platform === "win32") return;
|
|
26
|
-
if (!explicitPath && didEnsureSpawnHelperExecutable) return;
|
|
27
|
-
const helperPath = explicitPath ?? (yield* resolveNodePtySpawnHelperPath);
|
|
28
|
-
if (!helperPath) return;
|
|
29
|
-
if (!explicitPath) didEnsureSpawnHelperExecutable = true;
|
|
30
|
-
if (!(yield* fs.exists(helperPath))) return;
|
|
31
|
-
yield* fs.chmod(helperPath, 493).pipe(Effect.orElseSucceed(() => void 0));
|
|
32
|
-
});
|
|
33
|
-
var NodePtyProcess = class {
|
|
34
|
-
constructor(process) {
|
|
35
|
-
this.process = process;
|
|
36
|
-
}
|
|
37
|
-
get pid() {
|
|
38
|
-
return this.process.pid;
|
|
39
|
-
}
|
|
40
|
-
write(data) {
|
|
41
|
-
this.process.write(data);
|
|
42
|
-
}
|
|
43
|
-
resize(cols, rows) {
|
|
44
|
-
this.process.resize(cols, rows);
|
|
45
|
-
}
|
|
46
|
-
kill(signal) {
|
|
47
|
-
this.process.kill(signal);
|
|
48
|
-
}
|
|
49
|
-
onData(callback) {
|
|
50
|
-
const disposable = this.process.onData(callback);
|
|
51
|
-
return () => {
|
|
52
|
-
disposable.dispose();
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
onExit(callback) {
|
|
56
|
-
const disposable = this.process.onExit((event) => {
|
|
57
|
-
callback({
|
|
58
|
-
exitCode: event.exitCode,
|
|
59
|
-
signal: event.signal ?? null
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
return () => {
|
|
63
|
-
disposable.dispose();
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const layer = Layer.effect(PtyAdapter, Effect.gen(function* () {
|
|
68
|
-
const fs = yield* FileSystem.FileSystem;
|
|
69
|
-
const path = yield* Path.Path;
|
|
70
|
-
const nodePty = yield* Effect.promise(() => import("node-pty"));
|
|
71
|
-
const ensureNodePtySpawnHelperExecutableCached = yield* Effect.cached(ensureNodePtySpawnHelperExecutable().pipe(Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), Effect.orElseSucceed(() => void 0)));
|
|
72
|
-
return { spawn: Effect.fn(function* (input) {
|
|
73
|
-
yield* ensureNodePtySpawnHelperExecutableCached;
|
|
74
|
-
return new NodePtyProcess(nodePty.spawn(input.shell, input.args ?? [], {
|
|
75
|
-
cwd: input.cwd,
|
|
76
|
-
cols: input.cols,
|
|
77
|
-
rows: input.rows,
|
|
78
|
-
env: input.env,
|
|
79
|
-
name: globalThis.process.platform === "win32" ? "xterm-color" : "xterm-256color"
|
|
80
|
-
}));
|
|
81
|
-
}) };
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
export { ensureNodePtySpawnHelperExecutable, layer };
|
|
86
|
-
//# sourceMappingURL=NodePTY-AdcStdsu.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodePTY-AdcStdsu.mjs","names":[],"sources":["../src/terminal/Layers/NodePTY.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { Effect, FileSystem, Layer, Path } from \"effect\";\nimport { PtyAdapter, PtyAdapterShape, PtyExitEvent, PtyProcess } from \"../Services/PTY\";\n\nlet didEnsureSpawnHelperExecutable = false;\n\nconst resolveNodePtySpawnHelperPath = Effect.gen(function* () {\n const requireForNodePty = createRequire(import.meta.url);\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n\n const packageJsonPath = requireForNodePty.resolve(\"node-pty/package.json\");\n const packageDir = path.dirname(packageJsonPath);\n const candidates = [\n path.join(packageDir, \"build\", \"Release\", \"spawn-helper\"),\n path.join(packageDir, \"build\", \"Debug\", \"spawn-helper\"),\n path.join(packageDir, \"prebuilds\", `${process.platform}-${process.arch}`, \"spawn-helper\"),\n ];\n\n for (const candidate of candidates) {\n if (yield* fs.exists(candidate)) {\n return candidate;\n }\n }\n return null;\n}).pipe(Effect.orElseSucceed(() => null));\n\nexport const ensureNodePtySpawnHelperExecutable = Effect.fn(function* (explicitPath?: string) {\n const fs = yield* FileSystem.FileSystem;\n if (process.platform === \"win32\") return;\n if (!explicitPath && didEnsureSpawnHelperExecutable) return;\n\n const helperPath = explicitPath ?? (yield* resolveNodePtySpawnHelperPath);\n if (!helperPath) return;\n if (!explicitPath) {\n didEnsureSpawnHelperExecutable = true;\n }\n\n if (!(yield* fs.exists(helperPath))) {\n return;\n }\n\n // Best-effort: avoid FileSystem.stat in packaged mode where some fs metadata can be missing.\n yield* fs.chmod(helperPath, 0o755).pipe(Effect.orElseSucceed(() => undefined));\n});\n\nclass NodePtyProcess implements PtyProcess {\n constructor(private readonly process: import(\"node-pty\").IPty) {}\n\n get pid(): number {\n return this.process.pid;\n }\n\n write(data: string): void {\n this.process.write(data);\n }\n\n resize(cols: number, rows: number): void {\n this.process.resize(cols, rows);\n }\n\n kill(signal?: string): void {\n this.process.kill(signal);\n }\n\n onData(callback: (data: string) => void): () => void {\n const disposable = this.process.onData(callback);\n return () => {\n disposable.dispose();\n };\n }\n\n onExit(callback: (event: PtyExitEvent) => void): () => void {\n const disposable = this.process.onExit((event) => {\n callback({\n exitCode: event.exitCode,\n signal: event.signal ?? null,\n });\n });\n return () => {\n disposable.dispose();\n };\n }\n}\n\nexport const layer = Layer.effect(\n PtyAdapter,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n\n const nodePty = yield* Effect.promise(() => import(\"node-pty\"));\n\n const ensureNodePtySpawnHelperExecutableCached = yield* Effect.cached(\n ensureNodePtySpawnHelperExecutable().pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n Effect.provideService(Path.Path, path),\n Effect.orElseSucceed(() => undefined),\n ),\n );\n\n return {\n spawn: Effect.fn(function* (input) {\n yield* ensureNodePtySpawnHelperExecutableCached;\n const ptyProcess = nodePty.spawn(input.shell, input.args ?? [], {\n cwd: input.cwd,\n cols: input.cols,\n rows: input.rows,\n env: input.env,\n name: globalThis.process.platform === \"win32\" ? \"xterm-color\" : \"xterm-256color\",\n });\n return new NodePtyProcess(ptyProcess);\n }),\n } satisfies PtyAdapterShape;\n }),\n);\n"],"mappings":";;;;;;;AAKA,IAAI,iCAAiC;AAErC,MAAM,gCAAgC,OAAO,IAAI,aAAa;CAC5D,MAAM,oBAAoB,cAAc,OAAO,KAAK,IAAI;CACxD,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,KAAK,OAAO,WAAW;CAE7B,MAAM,kBAAkB,kBAAkB,QAAQ,wBAAwB;CAC1E,MAAM,aAAa,KAAK,QAAQ,gBAAgB;CAChD,MAAM,aAAa;EACjB,KAAK,KAAK,YAAY,SAAS,WAAW,eAAe;EACzD,KAAK,KAAK,YAAY,SAAS,SAAS,eAAe;EACvD,KAAK,KAAK,YAAY,aAAa,GAAG,QAAQ,SAAS,GAAG,QAAQ,QAAQ,eAAe;EAC1F;AAED,MAAK,MAAM,aAAa,WACtB,KAAI,OAAO,GAAG,OAAO,UAAU,CAC7B,QAAO;AAGX,QAAO;EACP,CAAC,KAAK,OAAO,oBAAoB,KAAK,CAAC;AAEzC,MAAa,qCAAqC,OAAO,GAAG,WAAW,cAAuB;CAC5F,MAAM,KAAK,OAAO,WAAW;AAC7B,KAAI,QAAQ,aAAa,QAAS;AAClC,KAAI,CAAC,gBAAgB,+BAAgC;CAErD,MAAM,aAAa,iBAAiB,OAAO;AAC3C,KAAI,CAAC,WAAY;AACjB,KAAI,CAAC,aACH,kCAAiC;AAGnC,KAAI,EAAE,OAAO,GAAG,OAAO,WA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;GACrC,EACH;EACD,CACH"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const require_index = require('./index.cjs');
|
|
4
|
-
let effect = require("effect");
|
|
5
|
-
let node_module = require("node:module");
|
|
6
|
-
|
|
7
|
-
//#region src/terminal/Layers/NodePTY.ts
|
|
8
|
-
let didEnsureSpawnHelperExecutable = false;
|
|
9
|
-
const resolveNodePtySpawnHelperPath = effect.Effect.gen(function* () {
|
|
10
|
-
const requireForNodePty = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
11
|
-
const path = yield* effect.Path.Path;
|
|
12
|
-
const fs = yield* effect.FileSystem.FileSystem;
|
|
13
|
-
const packageJsonPath = requireForNodePty.resolve("node-pty/package.json");
|
|
14
|
-
const packageDir = path.dirname(packageJsonPath);
|
|
15
|
-
const candidates = [
|
|
16
|
-
path.join(packageDir, "build", "Release", "spawn-helper"),
|
|
17
|
-
path.join(packageDir, "build", "Debug", "spawn-helper"),
|
|
18
|
-
path.join(packageDir, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper")
|
|
19
|
-
];
|
|
20
|
-
for (const candidate of candidates) if (yield* fs.exists(candidate)) return candidate;
|
|
21
|
-
return null;
|
|
22
|
-
}).pipe(effect.Effect.orElseSucceed(() => null));
|
|
23
|
-
const ensureNodePtySpawnHelperExecutable = effect.Effect.fn(function* (explicitPath) {
|
|
24
|
-
const fs = yield* effect.FileSystem.FileSystem;
|
|
25
|
-
if (process.platform === "win32") return;
|
|
26
|
-
if (!explicitPath && didEnsureSpawnHelperExecutable) return;
|
|
27
|
-
const helperPath = explicitPath ?? (yield* resolveNodePtySpawnHelperPath);
|
|
28
|
-
if (!helperPath) return;
|
|
29
|
-
if (!explicitPath) didEnsureSpawnHelperExecutable = true;
|
|
30
|
-
if (!(yield* fs.exists(helperPath))) return;
|
|
31
|
-
yield* fs.chmod(helperPath, 493).pipe(effect.Effect.orElseSucceed(() => void 0));
|
|
32
|
-
});
|
|
33
|
-
var NodePtyProcess = class {
|
|
34
|
-
constructor(process) {
|
|
35
|
-
this.process = process;
|
|
36
|
-
}
|
|
37
|
-
get pid() {
|
|
38
|
-
return this.process.pid;
|
|
39
|
-
}
|
|
40
|
-
write(data) {
|
|
41
|
-
this.process.write(data);
|
|
42
|
-
}
|
|
43
|
-
resize(cols, rows) {
|
|
44
|
-
this.process.resize(cols, rows);
|
|
45
|
-
}
|
|
46
|
-
kill(signal) {
|
|
47
|
-
this.process.kill(signal);
|
|
48
|
-
}
|
|
49
|
-
onData(callback) {
|
|
50
|
-
const disposable = this.process.onData(callback);
|
|
51
|
-
return () => {
|
|
52
|
-
disposable.dispose();
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
onExit(callback) {
|
|
56
|
-
const disposable = this.process.onExit((event) => {
|
|
57
|
-
callback({
|
|
58
|
-
exitCode: event.exitCode,
|
|
59
|
-
signal: event.signal ?? null
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
return () => {
|
|
63
|
-
disposable.dispose();
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const layer = effect.Layer.effect(require_index.PtyAdapter, effect.Effect.gen(function* () {
|
|
68
|
-
const fs = yield* effect.FileSystem.FileSystem;
|
|
69
|
-
const path = yield* effect.Path.Path;
|
|
70
|
-
const nodePty = yield* effect.Effect.promise(() => import("node-pty"));
|
|
71
|
-
const ensureNodePtySpawnHelperExecutableCached = yield* effect.Effect.cached(ensureNodePtySpawnHelperExecutable().pipe(effect.Effect.provideService(effect.FileSystem.FileSystem, fs), effect.Effect.provideService(effect.Path.Path, path), effect.Effect.orElseSucceed(() => void 0)));
|
|
72
|
-
return { spawn: effect.Effect.fn(function* (input) {
|
|
73
|
-
yield* ensureNodePtySpawnHelperExecutableCached;
|
|
74
|
-
return new NodePtyProcess(nodePty.spawn(input.shell, input.args ?? [], {
|
|
75
|
-
cwd: input.cwd,
|
|
76
|
-
cols: input.cols,
|
|
77
|
-
rows: input.rows,
|
|
78
|
-
env: input.env,
|
|
79
|
-
name: globalThis.process.platform === "win32" ? "xterm-color" : "xterm-256color"
|
|
80
|
-
}));
|
|
81
|
-
}) };
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
exports.ensureNodePtySpawnHelperExecutable = ensureNodePtySpawnHelperExecutable;
|
|
86
|
-
exports.layer = layer;
|
|
87
|
-
//# sourceMappingURL=NodePTY-DmqnQV86.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodePTY-DmqnQV86.cjs","names":["Effect","Path","FileSystem","Layer","PtyAdapter"],"sources":["../src/terminal/Layers/NodePTY.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nimport { Effect, FileSystem, Layer, Path } from \"effect\";\nimport { PtyAdapter, PtyAdapterShape, PtyExitEvent, PtyProcess } from \"../Services/PTY\";\n\nlet didEnsureSpawnHelperExecutable = false;\n\nconst resolveNodePtySpawnHelperPath = Effect.gen(function* () {\n const requireForNodePty = createRequire(import.meta.url);\n const path = yield* Path.Path;\n const fs = yield* FileSystem.FileSystem;\n\n const packageJsonPath = requireForNodePty.resolve(\"node-pty/package.json\");\n const packageDir = path.dirname(packageJsonPath);\n const candidates = [\n path.join(packageDir, \"build\", \"Release\", \"spawn-helper\"),\n path.join(packageDir, \"build\", \"Debug\", \"spawn-helper\"),\n path.join(packageDir, \"prebuilds\", `${process.platform}-${process.arch}`, \"spawn-helper\"),\n ];\n\n for (const candidate of candidates) {\n if (yield* fs.exists(candidate)) {\n return candidate;\n }\n }\n return null;\n}).pipe(Effect.orElseSucceed(() => null));\n\nexport const ensureNodePtySpawnHelperExecutable = Effect.fn(function* (explicitPath?: string) {\n const fs = yield* FileSystem.FileSystem;\n if (process.platform === \"win32\") return;\n if (!explicitPath && didEnsureSpawnHelperExecutable) return;\n\n const helperPath = explicitPath ?? (yield* resolveNodePtySpawnHelperPath);\n if (!helperPath) return;\n if (!explicitPath) {\n didEnsureSpawnHelperExecutable = true;\n }\n\n if (!(yield* fs.exists(helperPath))) {\n return;\n }\n\n // Best-effort: avoid FileSystem.stat in packaged mode where some fs metadata can be missing.\n yield* fs.chmod(helperPath, 0o755).pipe(Effect.orElseSucceed(() => undefined));\n});\n\nclass NodePtyProcess implements PtyProcess {\n constructor(private readonly process: import(\"node-pty\").IPty) {}\n\n get pid(): number {\n return this.process.pid;\n }\n\n write(data: string): void {\n this.process.write(data);\n }\n\n resize(cols: number, rows: number): void {\n this.process.resize(cols, rows);\n }\n\n kill(signal?: string): void {\n this.process.kill(signal);\n }\n\n onData(callback: (data: string) => void): () => void {\n const disposable = this.process.onData(callback);\n return () => {\n disposable.dispose();\n };\n }\n\n onExit(callback: (event: PtyExitEvent) => void): () => void {\n const disposable = this.process.onExit((event) => {\n callback({\n exitCode: event.exitCode,\n signal: event.signal ?? null,\n });\n });\n return () => {\n disposable.dispose();\n };\n }\n}\n\nexport const layer = Layer.effect(\n PtyAdapter,\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n\n const nodePty = yield* Effect.promise(() => import(\"node-pty\"));\n\n const ensureNodePtySpawnHelperExecutableCached = yield* Effect.cached(\n ensureNodePtySpawnHelperExecutable().pipe(\n Effect.provideService(FileSystem.FileSystem, fs),\n Effect.provideService(Path.Path, path),\n Effect.orElseSucceed(() => undefined),\n ),\n );\n\n return {\n spawn: Effect.fn(function* (input) {\n yield* ensureNodePtySpawnHelperExecutableCached;\n const ptyProcess = nodePty.spawn(input.shell, input.args ?? [], {\n cwd: input.cwd,\n cols: input.cols,\n rows: input.rows,\n env: input.env,\n name: globalThis.process.platform === \"win32\" ? \"xterm-color\" : \"xterm-256color\",\n });\n return new NodePtyProcess(ptyProcess);\n }),\n } satisfies PtyAdapterShape;\n }),\n);\n"],"mappings":";;;;;;;AAKA,IAAI,iCAAiC;AAErC,MAAM,gCAAgCA,cAAO,IAAI,aAAa;C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IxB,OAAO,UAAqD;EAC1D,MAAM,aAAa,KAAK,QAAQ,QAAQ,UAAU;AAChD,YAAS;IACP,UAAU,MAAM;IAChB,QAAQ,MAAM,UAAU;IACzB,CAAC;IACF;AACF,eAAa;AACX,cAAW,SAAS;;;;AAK1B,MAAa,QAAQG,aAAM,OACzBC,0BACAJ,cAAO,IAAI,aAAa;CACtB,MAAM,KAAK,OAAOE,kBAAW;CAC7B,MAAM,OAAO,OAAOD,YAAK;CAEzB,MAAM,UAAU,OAAOD,cAAO,cAAc,OAAO,YAAY;CAE/D,MAAM,2CAA2C,OAAOA,cAAO,OAC7D,oCAAoC,CAAC,KACnCA,cAAO,eAAeE,kBAAW,YAAY,GAAG,EAChDF,cAAO,eAAeC,YAAK,MAAM,KAAK,EACtCD,cAAO,oBAAoB,OAAU,CACtC,CACF;AAED,QAAO,EACL,OAAOA,cAAO,GAAG,WAAW,OAAO;AACjC,SAAO;AAQP,SAAO,IAAI,eAPQ,QAAQ,MAAM,MAAM,OAAO,MAAM,QAAQ,EAAE,EAAE;GAC9D,KAAK,MAAM;GACX,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,KAAK,MAAM;GACX,MAAM,WAAW,QAAQ,aAAa,UAAU,gBAAgB;GACjE,CAAC,CACmC;GACrC,EACH;EACD,CACH"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Layer from "effect/Layer";
|
|
5
|
-
import * as Client from "effect/unstable/sql/SqlClient";
|
|
6
|
-
import * as Semaphore from "effect/Semaphore";
|
|
7
|
-
import { DatabaseSync } from "node:sqlite";
|
|
8
|
-
import * as Cache from "effect/Cache";
|
|
9
|
-
import * as Config from "effect/Config";
|
|
10
|
-
import * as Duration from "effect/Duration";
|
|
11
|
-
import * as Fiber from "effect/Fiber";
|
|
12
|
-
import { identity } from "effect/Function";
|
|
13
|
-
import * as Scope from "effect/Scope";
|
|
14
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
15
|
-
import * as Stream from "effect/Stream";
|
|
16
|
-
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
17
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
18
|
-
import * as Statement from "effect/unstable/sql/Statement";
|
|
19
|
-
|
|
20
|
-
//#region src/persistence/NodeSqliteClient.ts
|
|
21
|
-
/**
|
|
22
|
-
* Port of `@effect/sql-sqlite-node` that uses the native `node:sqlite`
|
|
23
|
-
* bindings instead of `better-sqlite3`.
|
|
24
|
-
*
|
|
25
|
-
* @module SqliteClient
|
|
26
|
-
*/
|
|
27
|
-
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
28
|
-
const TypeId = "~local/sqlite-node/SqliteClient";
|
|
29
|
-
/**
|
|
30
|
-
* SqliteClient - Effect service tag for the sqlite SQL client.
|
|
31
|
-
*/
|
|
32
|
-
const SqliteClient = ServiceMap.Service("t3/persistence/NodeSqliteClient");
|
|
33
|
-
/**
|
|
34
|
-
* Verify that the current Node.js version includes the `node:sqlite` APIs
|
|
35
|
-
* used by `NodeSqliteClient` — specifically `StatementSync.columns()` (added
|
|
36
|
-
* in Node 22.16.0 / 23.11.0).
|
|
37
|
-
*
|
|
38
|
-
* @see https://github.com/nodejs/node/pull/57490
|
|
39
|
-
*/
|
|
40
|
-
const checkNodeSqliteCompat = () => {
|
|
41
|
-
const parts = process.versions.node.split(".").map(Number);
|
|
42
|
-
const major = parts[0] ?? 0;
|
|
43
|
-
const minor = parts[1] ?? 0;
|
|
44
|
-
if (!(major === 22 && minor >= 16 || major === 23 && minor >= 11 || major >= 24)) return Effect.die(`Node.js ${process.versions.node} is missing required node:sqlite APIs (StatementSync.columns). Upgrade to Node.js >=22.16, >=23.11, or >=24.`);
|
|
45
|
-
return Effect.void;
|
|
46
|
-
};
|
|
47
|
-
const makeWithDatabase = (options, openDatabase) => Effect.gen(function* () {
|
|
48
|
-
yield* checkNodeSqliteCompat();
|
|
49
|
-
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
50
|
-
const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : void 0;
|
|
51
|
-
const makeConnection = Effect.gen(function* () {
|
|
52
|
-
const scope = yield* Effect.scope;
|
|
53
|
-
const db = openDatabase();
|
|
54
|
-
yield* Scope.addFinalizer(scope, Effect.sync(() => db.close()));
|
|
55
|
-
const statementReaderCache = /* @__PURE__ */ new WeakMap();
|
|
56
|
-
const hasRows = (statement) => {
|
|
57
|
-
const cached = statementReaderCache.get(statement);
|
|
58
|
-
if (cached !== void 0) return cached;
|
|
59
|
-
const value = statement.columns().length > 0;
|
|
60
|
-
statementReaderCache.set(statement, value);
|
|
61
|
-
return value;
|
|
62
|
-
};
|
|
63
|
-
const prepareCache = yield* Cache.make({
|
|
64
|
-
capacity: options.prepareCacheSize ?? 200,
|
|
65
|
-
timeToLive: options.prepareCacheTTL ?? Duration.minutes(10),
|
|
66
|
-
lookup: (sql) => Effect.try({
|
|
67
|
-
try: () => db.prepare(sql),
|
|
68
|
-
catch: (cause) => new SqlError({
|
|
69
|
-
cause,
|
|
70
|
-
message: "Failed to prepare statement"
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
const runStatement = (statement, params, raw) => Effect.withFiber((fiber) => {
|
|
75
|
-
statement.setReadBigInts(Boolean(ServiceMap.get(fiber.services, Client.SafeIntegers)));
|
|
76
|
-
try {
|
|
77
|
-
if (hasRows(statement)) return Effect.succeed(statement.all(...params));
|
|
78
|
-
const result = statement.run(...params);
|
|
79
|
-
return Effect.succeed(raw ? result : []);
|
|
80
|
-
} catch (cause) {
|
|
81
|
-
return Effect.fail(new SqlError({
|
|
82
|
-
cause,
|
|
83
|
-
message: "Failed to execute statement"
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const run = (sql, params, raw = false) => Effect.flatMap(Cache.get(prepareCache, sql), (s) => runStatement(s, params, raw));
|
|
88
|
-
const runValues = (sql, params) => Effect.acquireUseRelease(Cache.get(prepareCache, sql), (statement) => Effect.try({
|
|
89
|
-
try: () => {
|
|
90
|
-
if (hasRows(statement)) {
|
|
91
|
-
statement.setReturnArrays(true);
|
|
92
|
-
return statement.all(...params);
|
|
93
|
-
}
|
|
94
|
-
statement.run(...params);
|
|
95
|
-
return [];
|
|
96
|
-
},
|
|
97
|
-
catch: (cause) => new SqlError({
|
|
98
|
-
cause,
|
|
99
|
-
message: "Failed to execute statement"
|
|
100
|
-
})
|
|
101
|
-
}), (statement) => Effect.sync(() => {
|
|
102
|
-
if (hasRows(statement)) statement.setReturnArrays(false);
|
|
103
|
-
}));
|
|
104
|
-
return identity({
|
|
105
|
-
execute(sql, params, rowTransform) {
|
|
106
|
-
return rowTransform ? Effect.map(run(sql, params), rowTransform) : run(sql, params);
|
|
107
|
-
},
|
|
108
|
-
executeRaw(sql, params) {
|
|
109
|
-
return run(sql, params, true);
|
|
110
|
-
},
|
|
111
|
-
executeValues(sql, params) {
|
|
112
|
-
return runValues(sql, params);
|
|
113
|
-
},
|
|
114
|
-
executeUnprepared(sql, params, rowTransform) {
|
|
115
|
-
const effect = runStatement(db.prepare(sql), params ?? [], false);
|
|
116
|
-
return rowTransform ? Effect.map(effect, rowTransform) : effect;
|
|
117
|
-
},
|
|
118
|
-
executeStream(_sql, _params) {
|
|
119
|
-
return Stream.die("executeStream not implemented");
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
const semaphore = yield* Semaphore.make(1);
|
|
124
|
-
const connection = yield* makeConnection;
|
|
125
|
-
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
126
|
-
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
127
|
-
const fiber = Fiber.getCurrent();
|
|
128
|
-
const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope);
|
|
129
|
-
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
130
|
-
});
|
|
131
|
-
return yield* Client.make({
|
|
132
|
-
acquirer,
|
|
133
|
-
compiler,
|
|
134
|
-
transactionAcquirer,
|
|
135
|
-
spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
|
|
136
|
-
transformRows
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
const make = (options) => makeWithDatabase(options, () => new DatabaseSync(options.filename, {
|
|
140
|
-
readOnly: options.readonly ?? false,
|
|
141
|
-
allowExtension: options.allowExtension ?? false
|
|
142
|
-
}));
|
|
143
|
-
const makeMemory = (config = {}) => makeWithDatabase({
|
|
144
|
-
...config,
|
|
145
|
-
filename: ":memory:",
|
|
146
|
-
readonly: false
|
|
147
|
-
}, () => {
|
|
148
|
-
return new DatabaseSync(":memory:", { allowExtension: config.allowExtension ?? false });
|
|
149
|
-
});
|
|
150
|
-
const layerConfig = (config) => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map((client) => ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
|
|
151
|
-
const layer = (config) => Layer.effectServices(Effect.map(make(config), (client) => ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
|
|
152
|
-
const layerMemory = (config = {}) => Layer.effectServices(Effect.map(makeMemory(config), (client) => ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
export { SqliteClient, TypeId, layer, layerConfig, layerMemory };
|
|
156
|
-
//# sourceMappingURL=NodeSqliteClient-BTK-dUey.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeSqliteClient-BTK-dUey.mjs","names":[],"sources":["../src/persistence/NodeSqliteClient.ts"],"sourcesContent":["/**\n * Port of `@effect/sql-sqlite-node` that uses the native `node:sqlite`\n * bindings instead of `better-sqlite3`.\n *\n * @module SqliteClient\n */\nimport { DatabaseSync, type StatementSync } from \"node:sqlite\";\n\nimport * as Cache from \"effect/Cache\";\nimport * as Config from \"effect/Config\";\nimport * as Duration from \"effect/Duration\";\nimport * as Effect from \"effect/Effect\";\nimport * as Fiber from \"effect/Fiber\";\nimport { identity } from \"effect/Function\";\nimport * as Layer from \"effect/Layer\";\nimport * as Scope from \"effect/Scope\";\nimport * as Semaphore from \"effect/Semaphore\";\nimport * as ServiceMap from \"effect/ServiceMap\";\nimport * as Stream from \"effect/Stream\";\nimport * as Reactivity from \"effect/unstable/reactivity/Reactivity\";\nimport * as Client from \"effect/unstable/sql/SqlClient\";\nimport type { Connection } from \"effect/unstable/sql/SqlConnection\";\nimport { SqlError } from \"effect/unstable/sql/SqlError\";\nimport * as Statement from \"effect/unstable/sql/Statement\";\n\nconst ATTR_DB_SYSTEM_NAME = \"db.system.name\";\n\nexport const TypeId: TypeId = \"~local/sqlite-node/SqliteClient\";\n\nexport type TypeId = \"~local/sqlite-node/SqliteClient\";\n\n/**\n * SqliteClient - Effect service tag for the sqlite SQL client.\n */\nexport const SqliteClient = ServiceMap.Service<Client.SqlClient>(\"t3/persistence/NodeSqliteClient\");\n\nexport interface SqliteClientConfig {\n readonly filename: string;\n readonly readonly?: boolean | undefined;\n readonly allowExtension?: boolean | undefined;\n readonly prepareCacheSize?: number | undefined;\n readonly prepareCacheTTL?: Duration.Input | undefined;\n readonly spanAttributes?: Record<string, unknown> | undefined;\n readonly transformResultNames?: ((str: string) => string) | undefined;\n readonly transformQueryNames?: ((str: string) => string) | undefined;\n}\n\nexport interface SqliteMemoryClientConfig extends Omit<\n SqliteClientConfig,\n \"filename\" | \"readonly\"\n> {}\n\n/**\n * Verify that the current Node.js version includes the `node:sqlite` APIs\n * used by `NodeSqliteClient` — specifically `StatementSync.columns()` (added\n * in Node 22.16.0 / 23.11.0).\n *\n * @see https://github.com/nodejs/node/pull/57490\n */\nconst checkNodeSqliteCompat = () => {\n const parts = process.versions.node.split(\".\").map(Number);\n const major = parts[0] ?? 0;\n const minor = parts[1] ?? 0;\n const supported = (major === 22 && minor >= 16) || (major === 23 && minor >= 11) || major >= 24;\n\n if (!supported) {\n return Effect.die(\n `Node.js ${process.versions.node} is missing required node:sqlite APIs ` +\n `(StatementSync.columns). Upgrade to Node.js >=22.16, >=23.11, or >=24.`,\n );\n }\n return Effect.void;\n};\n\nconst makeWithDatabase = (\n options: SqliteClientConfig,\n openDatabase: () => DatabaseSync,\n): Effect.Effect<Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> =>\n Effect.gen(function* () {\n yield* checkNodeSqliteCompat();\n\n const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);\n const transformRows = options.transformResultNames\n ? Statement.defaultTransforms(options.transformResultNames).array\n : undefined;\n\n const makeConnection = Effect.gen(function* () {\n const scope = yield* Effect.scope;\n const db = openDatabase();\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => db.close()),\n );\n\n const statementReaderCache = new WeakMap<StatementSync, boolean>();\n const hasRows = (statement: StatementSync): boolean => {\n const cached = statementReaderCache.get(statement);\n if (cached !== undefined) {\n return cached;\n }\n const value = statement.columns().length > 0;\n statementReaderCache.set(statement, value);\n return value;\n };\n\n const prepareCache = yield* Cache.make({\n capacity: options.prepareCacheSize ?? 200,\n timeToLive: options.prepareCacheTTL ?? Duration.minutes(10),\n lookup: (sql: string) =>\n Effect.try({\n try: () => db.prepare(sql),\n catch: (cause) => new SqlError({ cause, message: \"Failed to prepare statement\" }),\n }),\n });\n\n const runStatement = (\n statement: StatementSync,\n params: ReadonlyArray<unknown>,\n raw: boolean,\n ) =>\n Effect.withFiber<ReadonlyArray<any>, SqlError>((fiber) => {\n statement.setReadBigInts(Boolean(ServiceMap.get(fiber.services, Client.SafeIntegers)));\n try {\n if (hasRows(statement)) {\n return Effect.succeed(statement.all(...(params as any)));\n }\n const result = statement.run(...(params as any));\n return Effect.succeed(raw ? (result as unknown as ReadonlyArray<any>) : []);\n } catch (cause) {\n return Effect.fail(new SqlError({ cause, message: \"Failed to execute statement\" }));\n }\n });\n\n const run = (sql: string, params: ReadonlyArray<unknown>, raw = false) =>\n Effect.flatMap(Cache.get(prepareCache, sql), (s) => runStatement(s, params, raw));\n\n const runValues = (sql: string, params: ReadonlyArray<unknown>) =>\n Effect.acquireUseRelease(\n Cache.get(prepareCache, sql),\n (statement) =>\n Effect.try({\n try: () => {\n if (hasRows(statement)) {\n statement.setReturnArrays(true);\n // Safe to cast to array after we've setReturnArrays(true)\n return statement.all(...(params as any)) as unknown as ReadonlyArray<\n ReadonlyArray<unknown>\n >;\n }\n statement.run(...(params as any));\n return [];\n },\n catch: (cause) => new SqlError({ cause, message: \"Failed to execute statement\" }),\n }),\n (statement) =>\n Effect.sync(() => {\n if (hasRows(statement)) {\n statement.setReturnArrays(false);\n }\n }),\n );\n\n return identity<Connection>({\n execute(sql, params, rowTransform) {\n return rowTransform ? Effect.map(run(sql, params), rowTransform) : run(sql, params);\n },\n executeRaw(sql, params) {\n return run(sql, params, true);\n },\n executeValues(sql, params) {\n return runValues(sql, params);\n },\n executeUnprepared(sql, params, rowTransform) {\n const effect = runStatement(db.prepare(sql), params ?? [], false);\n return rowTransform ? Effect.map(effect, rowTransform) : effect;\n },\n executeStream(_sql, _params) {\n return Stream.die(\"executeStream not implemented\");\n },\n });\n });\n\n const semaphore = yield* Semaphore.make(1);\n const connection = yield* makeConnection;\n\n const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));\n const transactionAcquirer = Effect.uninterruptibleMask((restore) => {\n const fiber = Fiber.getCurrent()!;\n const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope);\n return Effect.as(\n Effect.tap(restore(semaphore.take(1)), () =>\n Scope.addFinalizer(scope, semaphore.release(1)),\n ),\n connection,\n );\n });\n\n return yield* Client.make({\n acquirer,\n compiler,\n transactionAcquirer,\n spanAttributes: [\n ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),\n [ATTR_DB_SYSTEM_NAME, \"sqlite\"],\n ],\n transformRows,\n });\n });\n\nconst make = (\n options: SqliteClientConfig,\n): Effect.Effect<Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> =>\n makeWithDatabase(\n options,\n () =>\n new DatabaseSync(options.filename, {\n readOnly: options.readonly ?? false,\n allowExtension: options.allowExtension ?? false,\n }),\n );\n\nconst makeMemory = (\n config: SqliteMemoryClientConfig = {},\n): Effect.Effect<Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> =>\n makeWithDatabase(\n {\n ...config,\n filename: \":memory:\",\n readonly: false,\n },\n () => {\n const database = new DatabaseSync(\":memory:\", {\n allowExtension: config.allowExtension ?? false,\n });\n return database;\n },\n );\n\nexport const layerConfig = (\n config: Config.Wrap<SqliteClientConfig>,\n): Layer.Layer<Client.SqlClient, Config.ConfigError> =>\n Layer.effectServices(\n Config.unwrap(config)\n .asEffect()\n .pipe(\n Effect.flatMap(make),\n Effect.map((client) =>\n ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client)),\n ),\n ),\n ).pipe(Layer.provide(Reactivity.layer));\n\nexport const layer = (config: SqliteClientConfig): Layer.Layer<Client.SqlClient> =>\n Layer.effectServices(\n Effect.map(make(config), (client) =>\n ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client)),\n ),\n ).pipe(Layer.provide(Reactivity.layer));\n\nexport const layerMemory = (config: SqliteMemoryClientConfig = {}): Layer.Layer<Client.SqlClient> =>\n Layer.effectServices(\n Effect.map(makeMemory(config), (client) =>\n ServiceMap.make(SqliteClient, client).pipe(ServiceMap.add(Client.SqlClient, client)),\n ),\n ).pipe(Layer.provide(Reactivity.layer));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,sBAAsB;AAE5B,MAAa,SA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