Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ActorDriver,
AnyActorInstance,
} from "@rivetkit/core/driver-helpers";
} from "@/driver-helpers/mod";
import type { FileSystemGlobalState } from "./global-state";

export type ActorDriverContext = Record<never, never>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "node:fs/promises";
import * as fsSync from "node:fs";
import * as path from "node:path";
import type { ActorKey } from "@rivetkit/core";
import type { ActorKey } from "@/actor/mod";
import { logger } from "./log";
import {
getStoragePath,
Expand All @@ -10,6 +10,7 @@ import {
ensureDirectoryExistsSync,
} from "./utils";
import invariant from "invariant";
import { serializeEmptyPersistData } from "@/driver-helpers/mod";

/**
* Interface representing a actor's state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLogger } from "@rivetkit/core/log";
import { getLogger } from "@/common/log";

export const LOGGER_NAME = "driver-fs";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type {
ManagerDriver,
ActorOutput,
CreateInput,
} from "@rivetkit/core/driver-helpers";
import { ActorAlreadyExists } from "@rivetkit/core/errors";
} from "@/driver-helpers/mod";
import { ActorAlreadyExists } from "@/actor/errors";
import { logger } from "./log";
import type { FileSystemGlobalState } from "./global-state";
import { ActorState } from "./global-state";
import type { Registry } from "@rivetkit/core";
import type { Registry } from "@/registry/mod";

export class FileSystemManagerDriver implements ManagerDriver {
#state: FileSystemGlobalState;
Expand All @@ -22,7 +22,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
// });

constructor(
private readonly registry: Registry<any>,
state: FileSystemGlobalState,
) {
this.#state = state;
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/drivers/file-system/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DriverConfig } from "@/registry/run-config";
import { FileSystemActorDriver } from "./actor";
import { FileSystemGlobalState } from "./global-state";
import { FileSystemManagerDriver } from "./manager";

export { getStoragePath } from "./utils";
export { FileSystemActorDriver } from "./actor";
export { FileSystemManagerDriver } from "./manager";
export { FileSystemGlobalState } from "./global-state";

export function createFileSystemDriver(): DriverConfig {
const state = new FileSystemGlobalState();
return {
topology: "standalone",
manager: new FileSystemManagerDriver(state),
actor: new FileSystemActorDriver(state),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import * as fs from "fs/promises";
import * as fsSync from "fs";
import * as path from "path";
import * as crypto from "crypto";
import envPaths from "env-paths";
import * as os from "os";

// Get platform-specific data directory
const paths = envPaths("rivetkit", { suffix: "" });
const paths = { data: getDataPath("rivetkit") };

/**
* Create a hash for a path, normalizing it first
*/
function createHashForPath(dirPath: string): string {
// Normalize the path first
const normalizedPath = path.normalize(dirPath);

// Extract the last path component for readability
const lastComponent = path.basename(normalizedPath);

// Create SHA-256 hash
const hash = crypto
.createHash("sha256")
.update(normalizedPath)
.digest("hex")
.substring(0, 8); // Take first 8 characters for brevity

return `${lastComponent}-${hash}`;
}

Expand Down Expand Up @@ -58,8 +58,10 @@ export async function pathExists(path: string): Promise<boolean> {
/**
* Ensure a directory exists, creating it if necessary
*/
export async function ensureDirectoryExists(directoryPath: string): Promise<void> {
if (!await pathExists(directoryPath)) {
export async function ensureDirectoryExists(
directoryPath: string,
): Promise<void> {
if (!(await pathExists(directoryPath))) {
await fs.mkdir(directoryPath, { recursive: true });
}
}
Expand All @@ -74,3 +76,25 @@ export function ensureDirectoryExistsSync(directoryPath: string): void {
}
}

/**
* Returns platform-specific data directory
*/
function getDataPath(appName: string): string {
const platform = process.platform;
const homeDir = os.homedir();

switch (platform) {
case "win32":
return path.join(
process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"),
appName,
);
case "darwin":
return path.join(homeDir, "Library", "Application Support", appName);
default: // linux and others
return path.join(
process.env.XDG_DATA_HOME || path.join(homeDir, ".local", "share"),
appName,
);
}
}
7 changes: 5 additions & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { logger } from "./actor/log";
import { createMemoryDriver } from "./drivers/memory/mod";
import { createRivetManagerDriver } from "./drivers/rivet/mod";
import { type DriverConfig, UserError } from "./mod";
import { createFileSystemDriver } from "./drivers/file-system/mod";

export const VERSION = pkgJson.version;

Expand Down Expand Up @@ -39,8 +40,10 @@ export type UpgradeWebSocket = (
*/
export function createDefaultDriver(): DriverConfig {
const driver = getEnvUniversal("RIVETKIT_DRIVER");
console.log("driver", driver);
if (!driver || driver === "memory") {
if (!driver || driver === "file-system") {
logger().info("using default file system driver");
return createFileSystemDriver();
} else if (driver === "memory") {
logger().info("using default memory driver");
return createMemoryDriver();
} else if (driver === "rivet") {
Expand Down
44 changes: 0 additions & 44 deletions packages/drivers/file-system/package.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/drivers/file-system/src/mod.ts

This file was deleted.

35 changes: 0 additions & 35 deletions packages/drivers/file-system/tests/driver-tests.test.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/drivers/file-system/tsconfig.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/drivers/file-system/tsup.config.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/drivers/file-system/turbo.json

This file was deleted.

37 changes: 0 additions & 37 deletions pnpm-lock.yaml

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

Loading