Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"node": ">=20.0.0"
},
"dependencies": {
"@tigrisdata/storage": "^3.1.1",
"@tigrisdata/storage": "^3.2.0",
"just-bash": "^2.14.2"
},
"release": {
Expand Down
9 changes: 5 additions & 4 deletions playground/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@auth0/auth0-spa-js": "^2.19.2",
"@tigrisdata/agent-shell": "^0.5.0",
"@tigrisdata/agent-shell": "^0.5.1",
"@xterm/addon-fit": "^0.11.0",
"@xterm/xterm": "^6.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions src/repl/session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { listBuckets } from "@tigrisdata/storage";
import type { BashExecResult } from "just-bash";
import { TigrisShell } from "../shell.js";
import type { TigrisConfig } from "../types.js";
import { type TigrisConfig, withConfigDefaults } from "../types.js";
import type { LoginFn } from "./auth.js";
import type { ReplIO } from "./io.js";

Expand Down Expand Up @@ -121,7 +121,8 @@ export class ReplSession {
authMethod: "access-key" | "oauth",
io: ReplIO,
): Promise<void> {
const bucketsResult = await listBuckets({ config: newConfig });
const config = withConfigDefaults(newConfig);
const bucketsResult = await listBuckets({ config });
if ("error" in bucketsResult) {
const newShell = new TigrisShell(newConfig);
this.commitSession(newConfig, newShell, authMethod);
Expand Down
17 changes: 9 additions & 8 deletions src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createPresignCommand } from "./commands/presign.js";
import { createSnapshotCommand } from "./commands/snapshot.js";
import { TigrisAdapter } from "./fs/tigris-adapter.js";
import type { ShellOptions, TigrisConfig } from "./types.js";
import { validateConfig } from "./types.js";
import { validateConfig, withConfigDefaults } from "./types.js";

interface MountEntry {
bucket: string;
Expand All @@ -30,28 +30,29 @@ export class TigrisShell {

constructor(config: TigrisConfig, shellOptions?: ShellOptions) {
validateConfig(config);
this.tigrisConfig = config;
const resolvedConfig = withConfigDefaults(config);
this.tigrisConfig = resolvedConfig;

this.mountableFs = new MountableFs({ base: new InMemoryFs() });

const cwd = shellOptions?.cwd ?? "/workspace";

// Auto-mount if bucket is provided
if (config.bucket) {
this.mount(config.bucket, cwd);
if (resolvedConfig.bucket) {
this.mount(resolvedConfig.bucket, cwd);
}

this.bash = new Bash({
fs: this.mountableFs,
cwd,
...(shellOptions?.env !== undefined && { env: shellOptions.env }),
customCommands: [
createPresignCommand(config, {
createPresignCommand(resolvedConfig, {
resolveBucket: (path) => this.resolveBucketForPath(path),
}),
createSnapshotCommand(config),
createForkCommand(config),
createForksListCommand(config),
createSnapshotCommand(resolvedConfig),
createForkCommand(resolvedConfig),
createForksListCommand(resolvedConfig),
],
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface TigrisConfig {
bucket?: string;
/** Tigris endpoint. Defaults to https://t3.storage.dev */
endpoint?: string;
/** Use path-style URLs (endpoint/bucket/key) instead of virtual-hosted (bucket.endpoint/key). */
forcePathStyle?: boolean;
}

/**
Expand All @@ -31,6 +33,14 @@ export interface ShellOptions {
env?: Record<string, string>;
}

/** Return a new config with defaults applied. */
export function withConfigDefaults(config: TigrisConfig): TigrisConfig {
return {
forcePathStyle: true,
...config,
};
}

/**
* Validates that TigrisConfig has at least one auth mode.
* Throws if neither access key nor session token auth is provided.
Expand Down