@celljs/ta-host 4.6.1 → 4.8.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/README.en.md +70 -0
- package/README.md +16 -3
- package/cell.schema.json +21 -0
- package/cell.yml +7 -0
- package/esm/node/auth-server-impl.d.ts +2 -0
- package/esm/node/auth-server-impl.js +7 -0
- package/esm/node/auth-server-impl.js.map +1 -1
- package/esm/node/exec-environment-factory.d.ts +8 -4
- package/esm/node/exec-environment-factory.js +28 -6
- package/esm/node/exec-environment-factory.js.map +1 -1
- package/esm/node/extension-providers.d.ts +22 -0
- package/esm/node/extension-providers.js +52 -0
- package/esm/node/extension-providers.js.map +1 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/index.js.map +1 -1
- package/esm/node/package-host-extension.d.ts +4 -2
- package/esm/node/package-host-extension.js +4 -3
- package/esm/node/package-host-extension.js.map +1 -1
- package/esm/node/package-hosts.d.ts +6 -2
- package/esm/node/package-hosts.js +32 -0
- package/esm/node/package-hosts.js.map +1 -1
- package/esm/node/remote/index.d.ts +5 -0
- package/esm/node/remote/index.js +6 -0
- package/esm/node/remote/index.js.map +1 -0
- package/esm/node/remote/pi-directories.d.ts +14 -0
- package/esm/node/remote/pi-directories.js +64 -0
- package/esm/node/remote/pi-directories.js.map +1 -0
- package/esm/node/remote/port-forwards.d.ts +35 -0
- package/esm/node/remote/port-forwards.js +150 -0
- package/esm/node/remote/port-forwards.js.map +1 -0
- package/esm/node/remote/remote-hosts.d.ts +40 -0
- package/esm/node/remote/remote-hosts.js +170 -0
- package/esm/node/remote/remote-hosts.js.map +1 -0
- package/esm/node/remote/remote-protocol.d.ts +51 -0
- package/esm/node/remote/remote-protocol.js +5 -0
- package/esm/node/remote/remote-protocol.js.map +1 -0
- package/esm/node/remote/remote-server-impl.d.ts +19 -0
- package/esm/node/remote/remote-server-impl.js +66 -0
- package/esm/node/remote/remote-server-impl.js.map +1 -0
- package/esm/node/remote-ui-context.d.ts +6 -1
- package/esm/node/remote-ui-context.js +31 -3
- package/esm/node/remote-ui-context.js.map +1 -1
- package/esm/node/session-files.d.ts +18 -0
- package/esm/node/session-files.js +32 -0
- package/esm/node/session-files.js.map +1 -0
- package/esm/node/settings-server-impl.d.ts +1 -0
- package/esm/node/settings-server-impl.js +8 -0
- package/esm/node/settings-server-impl.js.map +1 -1
- package/esm/node/settings-store.d.ts +9 -2
- package/esm/node/settings-store.js +26 -5
- package/esm/node/settings-store.js.map +1 -1
- package/esm/node/ta-server-impl.d.ts +2 -0
- package/esm/node/ta-server-impl.js +16 -4
- package/esm/node/ta-server-impl.js.map +1 -1
- package/esm/node/ta-session-factory.d.ts +19 -2
- package/esm/node/ta-session-factory.js +54 -11
- package/esm/node/ta-session-factory.js.map +1 -1
- package/esm/node/ta-session.d.ts +4 -0
- package/esm/node/ta-session.js +6 -1
- package/esm/node/ta-session.js.map +1 -1
- package/esm/node/terminal-service.d.ts +18 -2
- package/esm/node/terminal-service.js +46 -10
- package/esm/node/terminal-service.js.map +1 -1
- package/esm/node/terminal-util.d.ts +14 -0
- package/esm/node/terminal-util.js +30 -1
- package/esm/node/terminal-util.js.map +1 -1
- package/esm/node/web-extension-catalog.d.ts +3 -1
- package/esm/node/web-extension-catalog.js +8 -2
- package/esm/node/web-extension-catalog.js.map +1 -1
- package/esm/node/working-directory.d.ts +12 -1
- package/esm/node/working-directory.js +22 -1
- package/esm/node/working-directory.js.map +1 -1
- package/esm/node/workspace-files.d.ts +1 -1
- package/esm/node/workspace-files.js +3 -3
- package/esm/node/workspace-files.js.map +1 -1
- package/esm/node/workspace-protocol.d.ts +2 -0
- package/esm/node/workspace-server-impl.d.ts +2 -1
- package/esm/node/workspace-server-impl.js +13 -1
- package/esm/node/workspace-server-impl.js.map +1 -1
- package/esm/node/workspace-service.d.ts +1 -0
- package/esm/node/workspace-service.js +15 -3
- package/esm/node/workspace-service.js.map +1 -1
- package/lib/node/auth-server-impl.d.ts +2 -0
- package/lib/node/auth-server-impl.d.ts.map +1 -1
- package/lib/node/auth-server-impl.js +7 -0
- package/lib/node/auth-server-impl.js.map +1 -1
- package/lib/node/exec-environment-factory.d.ts +8 -4
- package/lib/node/exec-environment-factory.d.ts.map +1 -1
- package/lib/node/exec-environment-factory.js +28 -6
- package/lib/node/exec-environment-factory.js.map +1 -1
- package/lib/node/extension-providers.d.ts +23 -0
- package/lib/node/extension-providers.d.ts.map +1 -0
- package/lib/node/extension-providers.js +55 -0
- package/lib/node/extension-providers.js.map +1 -0
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +3 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/package-host-extension.d.ts +4 -2
- package/lib/node/package-host-extension.d.ts.map +1 -1
- package/lib/node/package-host-extension.js +4 -3
- package/lib/node/package-host-extension.js.map +1 -1
- package/lib/node/package-hosts.d.ts +6 -2
- package/lib/node/package-hosts.d.ts.map +1 -1
- package/lib/node/package-hosts.js +32 -0
- package/lib/node/package-hosts.js.map +1 -1
- package/lib/node/remote/index.d.ts +6 -0
- package/lib/node/remote/index.d.ts.map +1 -0
- package/lib/node/remote/index.js +22 -0
- package/lib/node/remote/index.js.map +1 -0
- package/lib/node/remote/pi-directories.d.ts +15 -0
- package/lib/node/remote/pi-directories.d.ts.map +1 -0
- package/lib/node/remote/pi-directories.js +67 -0
- package/lib/node/remote/pi-directories.js.map +1 -0
- package/lib/node/remote/port-forwards.d.ts +36 -0
- package/lib/node/remote/port-forwards.d.ts.map +1 -0
- package/lib/node/remote/port-forwards.js +153 -0
- package/lib/node/remote/port-forwards.js.map +1 -0
- package/lib/node/remote/remote-hosts.d.ts +41 -0
- package/lib/node/remote/remote-hosts.d.ts.map +1 -0
- package/lib/node/remote/remote-hosts.js +173 -0
- package/lib/node/remote/remote-hosts.js.map +1 -0
- package/lib/node/remote/remote-protocol.d.ts +52 -0
- package/lib/node/remote/remote-protocol.d.ts.map +1 -0
- package/lib/node/remote/remote-protocol.js +8 -0
- package/lib/node/remote/remote-protocol.js.map +1 -0
- package/lib/node/remote/remote-server-impl.d.ts +20 -0
- package/lib/node/remote/remote-server-impl.d.ts.map +1 -0
- package/lib/node/remote/remote-server-impl.js +69 -0
- package/lib/node/remote/remote-server-impl.js.map +1 -0
- package/lib/node/remote/remote.spec.d.ts +2 -0
- package/lib/node/remote/remote.spec.d.ts.map +1 -0
- package/lib/node/remote/remote.spec.js +130 -0
- package/lib/node/remote/remote.spec.js.map +1 -0
- package/lib/node/remote-ui-context.d.ts +6 -1
- package/lib/node/remote-ui-context.d.ts.map +1 -1
- package/lib/node/remote-ui-context.js +31 -3
- package/lib/node/remote-ui-context.js.map +1 -1
- package/lib/node/remote-ui-context.spec.js +23 -0
- package/lib/node/remote-ui-context.spec.js.map +1 -1
- package/lib/node/session-files.d.ts +19 -0
- package/lib/node/session-files.d.ts.map +1 -0
- package/lib/node/session-files.js +36 -0
- package/lib/node/session-files.js.map +1 -0
- package/lib/node/session-files.spec.d.ts +2 -0
- package/lib/node/session-files.spec.d.ts.map +1 -0
- package/lib/node/session-files.spec.js +51 -0
- package/lib/node/session-files.spec.js.map +1 -0
- package/lib/node/settings-server-impl.d.ts +1 -0
- package/lib/node/settings-server-impl.d.ts.map +1 -1
- package/lib/node/settings-server-impl.js +8 -0
- package/lib/node/settings-server-impl.js.map +1 -1
- package/lib/node/settings-store.d.ts +9 -2
- package/lib/node/settings-store.d.ts.map +1 -1
- package/lib/node/settings-store.js +26 -5
- package/lib/node/settings-store.js.map +1 -1
- package/lib/node/settings-store.spec.js +5 -2
- package/lib/node/settings-store.spec.js.map +1 -1
- package/lib/node/ta-server-impl.d.ts +2 -0
- package/lib/node/ta-server-impl.d.ts.map +1 -1
- package/lib/node/ta-server-impl.js +16 -4
- package/lib/node/ta-server-impl.js.map +1 -1
- package/lib/node/ta-session-factory.d.ts +19 -2
- package/lib/node/ta-session-factory.d.ts.map +1 -1
- package/lib/node/ta-session-factory.js +53 -10
- package/lib/node/ta-session-factory.js.map +1 -1
- package/lib/node/ta-session.d.ts +4 -0
- package/lib/node/ta-session.d.ts.map +1 -1
- package/lib/node/ta-session.js +6 -1
- package/lib/node/ta-session.js.map +1 -1
- package/lib/node/terminal-service.d.ts +18 -2
- package/lib/node/terminal-service.d.ts.map +1 -1
- package/lib/node/terminal-service.js +45 -9
- package/lib/node/terminal-service.js.map +1 -1
- package/lib/node/terminal-service.spec.js +31 -0
- package/lib/node/terminal-service.spec.js.map +1 -1
- package/lib/node/terminal-util.d.ts +14 -0
- package/lib/node/terminal-util.d.ts.map +1 -1
- package/lib/node/terminal-util.js +30 -1
- package/lib/node/terminal-util.js.map +1 -1
- package/lib/node/terminal-util.spec.js +24 -0
- package/lib/node/terminal-util.spec.js.map +1 -1
- package/lib/node/web-extension-catalog.d.ts +3 -1
- package/lib/node/web-extension-catalog.d.ts.map +1 -1
- package/lib/node/web-extension-catalog.js +7 -1
- package/lib/node/web-extension-catalog.js.map +1 -1
- package/lib/node/web-extension-catalog.spec.js +1 -1
- package/lib/node/web-extension-catalog.spec.js.map +1 -1
- package/lib/node/working-directory.d.ts +12 -1
- package/lib/node/working-directory.d.ts.map +1 -1
- package/lib/node/working-directory.js +22 -1
- package/lib/node/working-directory.js.map +1 -1
- package/lib/node/workspace-files.d.ts +1 -1
- package/lib/node/workspace-files.d.ts.map +1 -1
- package/lib/node/workspace-files.js +3 -3
- package/lib/node/workspace-files.js.map +1 -1
- package/lib/node/workspace-protocol.d.ts +2 -0
- package/lib/node/workspace-protocol.d.ts.map +1 -1
- package/lib/node/workspace-server-impl.d.ts +2 -1
- package/lib/node/workspace-server-impl.d.ts.map +1 -1
- package/lib/node/workspace-server-impl.js +12 -0
- package/lib/node/workspace-server-impl.js.map +1 -1
- package/lib/node/workspace-service.d.ts +1 -0
- package/lib/node/workspace-service.d.ts.map +1 -1
- package/lib/node/workspace-service.js +15 -3
- package/lib/node/workspace-service.js.map +1 -1
- package/lib/node/workspace-service.spec.js +9 -0
- package/lib/node/workspace-service.spec.js.map +1 -1
- package/package.json +14 -10
- package/src/node/auth-server-impl.ts +6 -0
- package/src/node/exec-environment-factory.ts +26 -6
- package/src/node/extension-providers.ts +49 -0
- package/src/node/index.ts +3 -0
- package/src/node/package-host-extension.ts +7 -4
- package/src/node/package-hosts.ts +32 -2
- package/src/node/remote/index.ts +5 -0
- package/src/node/remote/pi-directories.ts +49 -0
- package/src/node/remote/port-forwards.ts +148 -0
- package/src/node/remote/remote-hosts.ts +170 -0
- package/src/node/remote/remote-protocol.ts +57 -0
- package/src/node/remote/remote-server-impl.ts +60 -0
- package/src/node/remote/remote.spec.ts +142 -0
- package/src/node/remote-ui-context.spec.ts +25 -0
- package/src/node/remote-ui-context.ts +34 -5
- package/src/node/session-files.spec.ts +52 -0
- package/src/node/session-files.ts +41 -0
- package/src/node/settings-server-impl.ts +9 -0
- package/src/node/settings-store.spec.ts +5 -2
- package/src/node/settings-store.ts +25 -6
- package/src/node/ta-server-impl.ts +18 -4
- package/src/node/ta-session-factory.ts +56 -10
- package/src/node/ta-session.ts +9 -1
- package/src/node/terminal-service.spec.ts +35 -0
- package/src/node/terminal-service.ts +47 -15
- package/src/node/terminal-util.spec.ts +31 -0
- package/src/node/terminal-util.ts +32 -1
- package/src/node/web-extension-catalog.spec.ts +1 -1
- package/src/node/web-extension-catalog.ts +7 -2
- package/src/node/working-directory.ts +35 -2
- package/src/node/workspace-files.ts +3 -3
- package/src/node/workspace-protocol.ts +2 -0
- package/src/node/workspace-server-impl.ts +18 -0
- package/src/node/workspace-service.spec.ts +11 -1
- package/src/node/workspace-service.ts +15 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { CODING_AGENT_OPTIONS, type CodingAgentOptions, type PiSdk, PiSdkUtil } from '@celljs/ai-coding-agent';
|
|
4
|
-
import { Component, Value } from '@celljs/core';
|
|
4
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
5
5
|
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
6
6
|
import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
|
|
7
7
|
import type { TaPackageInfo, TaSettingsScope, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
|
|
8
8
|
import { WebExtensionCatalog } from './host-protocol';
|
|
9
9
|
import { PackageSwitch } from './package-switch';
|
|
10
|
+
import { PiDirectories } from './remote/remote-protocol';
|
|
10
11
|
import { TaErrors } from './ta-errors';
|
|
11
12
|
import { type WebExtensionPackage, WebExtensionUtil } from './web-extension-util';
|
|
12
13
|
|
|
@@ -31,6 +32,9 @@ export class WebExtensionCatalogImpl implements WebExtensionCatalog {
|
|
|
31
32
|
@Value(CODING_AGENT_OPTIONS)
|
|
32
33
|
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
33
34
|
|
|
35
|
+
@Autowired(PiDirectories)
|
|
36
|
+
protected readonly directories: PiDirectories;
|
|
37
|
+
|
|
34
38
|
async packages(cwd: string): Promise<TaPackageInfo[]> {
|
|
35
39
|
const { packages } = await this.load(cwd);
|
|
36
40
|
return packages.map(pkg => WebExtensionUtil.describePackage(pkg));
|
|
@@ -131,7 +135,8 @@ export class WebExtensionCatalogImpl implements WebExtensionCatalog {
|
|
|
131
135
|
return manager.resolve(async () => 'skip');
|
|
132
136
|
}
|
|
133
137
|
|
|
134
|
-
protected async load(
|
|
138
|
+
protected async load(location: string): Promise<Loaded> {
|
|
139
|
+
const cwd = this.directories.toPi(location);
|
|
135
140
|
const sdk = await PiSdkUtil.load();
|
|
136
141
|
const agentDir = this.codingAgentOptions?.agentDir ?? sdk.getAgentDir();
|
|
137
142
|
const trusted = new sdk.ProjectTrustStore(agentDir).get(cwd) ?? !sdk.hasTrustRequiringProjectResources(cwd);
|
|
@@ -6,12 +6,22 @@ import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
|
|
|
6
6
|
|
|
7
7
|
export const TaWorkingDirectory = Symbol('TaWorkingDirectory');
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The working directory the user chose for ta serve (TaServer.setWorkingDirectory), and the hosts of the
|
|
11
|
+
* remote directories opened lately (TaRemoteServer), kept across restarts.
|
|
12
|
+
*/
|
|
10
13
|
export interface TaWorkingDirectory {
|
|
11
14
|
get(): string | undefined;
|
|
12
15
|
set(cwd: string): void;
|
|
16
|
+
/** The latest first. */
|
|
17
|
+
recentHosts(): string[];
|
|
18
|
+
addRecentHost(host: string): void;
|
|
19
|
+
removeRecentHost(host: string): void;
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
/** Hosts kept in recentHosts. */
|
|
23
|
+
const RECENT_HOSTS = 10;
|
|
24
|
+
|
|
15
25
|
/** In ta.json of the agent directory, beside Ta's other settings of its own; the file keeps its other keys. */
|
|
16
26
|
@Component(TaWorkingDirectory)
|
|
17
27
|
export class TaWorkingDirectoryImpl implements TaWorkingDirectory {
|
|
@@ -23,7 +33,30 @@ export class TaWorkingDirectoryImpl implements TaWorkingDirectory {
|
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
set(cwd: string): void {
|
|
26
|
-
|
|
36
|
+
this.write({ workingDirectory: cwd });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
recentHosts(): string[] {
|
|
40
|
+
const { remoteHosts } = this.read();
|
|
41
|
+
return Array.isArray(remoteHosts) ? remoteHosts.filter((host): host is string => typeof host === 'string') : [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
addRecentHost(host: string): void {
|
|
45
|
+
const hosts = this.recentHosts();
|
|
46
|
+
if (hosts[0] !== host) {
|
|
47
|
+
this.write({ remoteHosts: [host, ...hosts.filter(other => other !== host)].slice(0, RECENT_HOSTS) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
removeRecentHost(host: string): void {
|
|
52
|
+
const hosts = this.recentHosts();
|
|
53
|
+
if (hosts.includes(host)) {
|
|
54
|
+
this.write({ remoteHosts: hosts.filter(other => other !== host) });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected write(changes: Record<string, unknown>): void {
|
|
59
|
+
writeFileSync(`${this.file}.tmp`, `${JSON.stringify({ ...this.read(), ...changes }, null, 2)}\n`);
|
|
27
60
|
renameSync(`${this.file}.tmp`, this.file);
|
|
28
61
|
}
|
|
29
62
|
|
|
@@ -159,7 +159,7 @@ export class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
|
|
|
159
159
|
|
|
160
160
|
protected async send(request: IncomingMessage, response: ServerResponse, cwd: string, path: string): Promise<void> {
|
|
161
161
|
const env = this.environments.create(cwd);
|
|
162
|
-
const file = await this.find(env,
|
|
162
|
+
const file = await this.find(env, path);
|
|
163
163
|
if (!file) {
|
|
164
164
|
this.fail(response, 404);
|
|
165
165
|
return;
|
|
@@ -207,10 +207,10 @@ export class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/** The file at `path`, or the `index.html` of the directory there. */
|
|
210
|
-
protected async find(env: ExecEnvironment,
|
|
210
|
+
protected async find(env: ExecEnvironment, path: string): Promise<{ absolute: string; stat: FileStat } | undefined> {
|
|
211
211
|
let absolute: string;
|
|
212
212
|
try {
|
|
213
|
-
absolute = WorkspaceUtil.inside(cwd, path).absolute;
|
|
213
|
+
absolute = WorkspaceUtil.inside(env.cwd, path).absolute;
|
|
214
214
|
} catch {
|
|
215
215
|
return undefined;
|
|
216
216
|
}
|
|
@@ -12,6 +12,8 @@ export interface TaWorkspace {
|
|
|
12
12
|
listDirectory(cwd: string, path: string): Promise<TaDirEntry[]>;
|
|
13
13
|
readFile(cwd: string, path: string): Promise<TaFileContent>;
|
|
14
14
|
writeFile(cwd: string, path: string, text: string): Promise<void>;
|
|
15
|
+
/** Bytes to a file, the folders on its way made; with `append`, after what it holds. */
|
|
16
|
+
uploadFile(cwd: string, path: string, data: Uint8Array, append: boolean): Promise<void>;
|
|
15
17
|
findFiles(cwd: string, query: string, limit?: number): Promise<string[]>;
|
|
16
18
|
runCommand(cwd: string, command: string, args: string[], options?: TaRunCommandOptions): Promise<TaCommandOutput>;
|
|
17
19
|
}
|
|
@@ -3,6 +3,7 @@ import { Rpc } from '@celljs/rpc';
|
|
|
3
3
|
import { RpcContext } from '@celljs/rpc/lib/node';
|
|
4
4
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
5
5
|
import {
|
|
6
|
+
TA_UPLOAD_PART_BYTES,
|
|
6
7
|
type TaCommandOutput,
|
|
7
8
|
type TaDirEntry,
|
|
8
9
|
type TaFileContent,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
type TaRunCommandOptions,
|
|
11
12
|
type TaTerminalInfo,
|
|
12
13
|
TaTerminalServer,
|
|
14
|
+
type TaUploadOptions,
|
|
13
15
|
TaWorkspaceServer,
|
|
14
16
|
} from '@celljs/ta-protocol';
|
|
15
17
|
import { TaErrors } from './ta-errors';
|
|
@@ -40,6 +42,22 @@ export class TaWorkspaceServerImpl implements TaWorkspaceServer {
|
|
|
40
42
|
return TaErrors.guard(async () => this.workspace.writeFile(await this.cwd(cwd), path, text));
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
uploadFile(path: string, data: string, options: TaUploadOptions = {}): Promise<void> {
|
|
46
|
+
return TaErrors.guard(async () => {
|
|
47
|
+
if (typeof data !== 'string') {
|
|
48
|
+
throw TaErrors.invalidArgument('No bytes to write.', 'Pass the bytes of the file in base64.');
|
|
49
|
+
}
|
|
50
|
+
const bytes = Buffer.from(data, 'base64');
|
|
51
|
+
if (bytes.length > TA_UPLOAD_PART_BYTES) {
|
|
52
|
+
throw TaErrors.invalidArgument(
|
|
53
|
+
'The part is too large.',
|
|
54
|
+
`Send the file in parts of at most ${TA_UPLOAD_PART_BYTES} bytes, each after the first with append.`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
await this.workspace.uploadFile(await this.cwd(options.cwd), path, bytes, options.append === true);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
43
61
|
fileUrl(path: string, cwd?: string): Promise<string> {
|
|
44
62
|
return TaErrors.guard(async () => this.files.url(await this.cwd(cwd), path));
|
|
45
63
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
|
|
2
2
|
import { execSync } from 'node:child_process';
|
|
3
|
-
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { LocalExecEnvironment } from '@celljs/ta-exec';
|
|
@@ -77,6 +77,16 @@ describe('DefaultTaWorkspace', () => {
|
|
|
77
77
|
await expect(workspace().writeFile(repo, '../secret.txt', 'a')).rejects.toThrow('outside');
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
it('uploads bytes in parts, making the folders on the way', async () => {
|
|
81
|
+
await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([0, 1, 2]), false);
|
|
82
|
+
await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([3]), true);
|
|
83
|
+
expect([...readFileSync(join(root, 'up/load/a.bin'))]).toEqual([0, 1, 2, 3]);
|
|
84
|
+
await workspace().uploadFile(root, 'up/load/a.bin', new Uint8Array([9]), false);
|
|
85
|
+
expect([...readFileSync(join(root, 'up/load/a.bin'))]).toEqual([9]);
|
|
86
|
+
await expect(workspace().uploadFile(root, 'up', new Uint8Array([1]), false)).rejects.toThrow('is a directory');
|
|
87
|
+
await expect(workspace().uploadFile(root, '../out.bin', new Uint8Array([1]), false)).rejects.toThrow('outside');
|
|
88
|
+
});
|
|
89
|
+
|
|
80
90
|
it('reads the start of a large file', async () => {
|
|
81
91
|
write(join(root, 'big/large.txt'), 'x'.repeat(1024 * 1024 + 10));
|
|
82
92
|
const content = await workspace().readFile(join(root, 'big'), 'large.txt');
|
|
@@ -58,7 +58,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
|
|
|
58
58
|
|
|
59
59
|
async listDirectory(cwd: string, path: string): Promise<TaDirEntry[]> {
|
|
60
60
|
const env = this.environments.create(cwd);
|
|
61
|
-
const target = WorkspaceUtil.inside(cwd, path);
|
|
61
|
+
const target = WorkspaceUtil.inside(env.cwd, path);
|
|
62
62
|
const stat = await env.stat(target.absolute);
|
|
63
63
|
if (!stat?.isDirectory) {
|
|
64
64
|
throw TaErrors.invalidArgument(`${path} is not a directory.`, 'Pass the path of a directory inside the workspace.');
|
|
@@ -82,7 +82,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
|
|
|
82
82
|
|
|
83
83
|
async readFile(cwd: string, path: string): Promise<TaFileContent> {
|
|
84
84
|
const env = this.environments.create(cwd);
|
|
85
|
-
const target = WorkspaceUtil.inside(cwd, path);
|
|
85
|
+
const target = WorkspaceUtil.inside(env.cwd, path);
|
|
86
86
|
const stat = await env.stat(target.absolute);
|
|
87
87
|
if (!stat || stat.isDirectory) {
|
|
88
88
|
throw TaErrors.invalidArgument(`${path} is not a file.`, 'Pass the path of a file inside the workspace.');
|
|
@@ -101,7 +101,7 @@ export class DefaultTaWorkspace implements TaWorkspace {
|
|
|
101
101
|
|
|
102
102
|
async writeFile(cwd: string, path: string, text: string): Promise<void> {
|
|
103
103
|
const env = this.environments.create(cwd);
|
|
104
|
-
const target = WorkspaceUtil.inside(cwd, path);
|
|
104
|
+
const target = WorkspaceUtil.inside(env.cwd, path);
|
|
105
105
|
const [stat, parent] = await Promise.all([env.stat(target.absolute), env.stat(dirname(target.absolute))]);
|
|
106
106
|
if (stat?.isDirectory || !parent?.isDirectory) {
|
|
107
107
|
throw TaErrors.invalidArgument(
|
|
@@ -112,6 +112,18 @@ export class DefaultTaWorkspace implements TaWorkspace {
|
|
|
112
112
|
await env.writeFile(target.absolute, text);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
async uploadFile(cwd: string, path: string, data: Uint8Array, append: boolean): Promise<void> {
|
|
116
|
+
const env = this.environments.create(cwd);
|
|
117
|
+
const target = WorkspaceUtil.inside(env.cwd, path);
|
|
118
|
+
if (!target.relative || (await env.stat(target.absolute))?.isDirectory) {
|
|
119
|
+
throw TaErrors.invalidArgument(`${path || '.'} is a directory.`, 'Pass the path of a file inside the workspace.');
|
|
120
|
+
}
|
|
121
|
+
if (!append) {
|
|
122
|
+
await env.mkdir(dirname(target.absolute));
|
|
123
|
+
}
|
|
124
|
+
await env.writeFile(target.absolute, data, { append });
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
async findFiles(cwd: string, query: string, limit = DEFAULT_FIND_LIMIT): Promise<string[]> {
|
|
116
128
|
const env = this.environments.create(cwd);
|
|
117
129
|
return WorkspaceUtil.fuzzyFind(await this.listFiles(env), query, Math.max(1, limit));
|