Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 7107d33

Browse files
committed
chore: update default driver to file system driver (#1013)
1 parent 41bd54c commit 7107d33

File tree

14 files changed

+61
-154
lines changed

14 files changed

+61
-154
lines changed

packages/drivers/file-system/src/actor.ts renamed to packages/core/src/drivers/file-system/actor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
22
ActorDriver,
33
AnyActorInstance,
4-
} from "@rivetkit/core/driver-helpers";
4+
} from "@/driver-helpers/mod";
55
import type { FileSystemGlobalState } from "./global-state";
66

77
export type ActorDriverContext = Record<never, never>;

packages/drivers/file-system/src/global-state.ts renamed to packages/core/src/drivers/file-system/global-state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "node:fs/promises";
22
import * as fsSync from "node:fs";
33
import * as path from "node:path";
4-
import type { ActorKey } from "@rivetkit/core";
4+
import type { ActorKey } from "@/actor/mod";
55
import { logger } from "./log";
66
import {
77
getStoragePath,
@@ -10,6 +10,7 @@ import {
1010
ensureDirectoryExistsSync,
1111
} from "./utils";
1212
import invariant from "invariant";
13+
import { serializeEmptyPersistData } from "@/driver-helpers/mod";
1314

1415
/**
1516
* Interface representing a actor's state

packages/drivers/file-system/src/log.ts renamed to packages/core/src/drivers/file-system/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getLogger } from "@rivetkit/core/log";
1+
import { getLogger } from "@/common/log";
22

33
export const LOGGER_NAME = "driver-fs";
44

packages/drivers/file-system/src/manager.ts renamed to packages/core/src/drivers/file-system/manager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import type {
66
ManagerDriver,
77
ActorOutput,
88
CreateInput,
9-
} from "@rivetkit/core/driver-helpers";
10-
import { ActorAlreadyExists } from "@rivetkit/core/errors";
9+
} from "@/driver-helpers/mod";
10+
import { ActorAlreadyExists } from "@/actor/errors";
1111
import { logger } from "./log";
1212
import type { FileSystemGlobalState } from "./global-state";
1313
import { ActorState } from "./global-state";
14-
import type { Registry } from "@rivetkit/core";
14+
import type { Registry } from "@/registry/mod";
1515

1616
export class FileSystemManagerDriver implements ManagerDriver {
1717
#state: FileSystemGlobalState;
@@ -22,7 +22,6 @@ export class FileSystemManagerDriver implements ManagerDriver {
2222
// });
2323

2424
constructor(
25-
private readonly registry: Registry<any>,
2625
state: FileSystemGlobalState,
2726
) {
2827
this.#state = state;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { DriverConfig } from "@/registry/run-config";
2+
import { FileSystemActorDriver } from "./actor";
3+
import { FileSystemGlobalState } from "./global-state";
4+
import { FileSystemManagerDriver } from "./manager";
5+
6+
export { getStoragePath } from "./utils";
7+
export { FileSystemActorDriver } from "./actor";
8+
export { FileSystemManagerDriver } from "./manager";
9+
export { FileSystemGlobalState } from "./global-state";
10+
11+
export function createFileSystemDriver(): DriverConfig {
12+
const state = new FileSystemGlobalState();
13+
return {
14+
topology: "standalone",
15+
manager: new FileSystemManagerDriver(state),
16+
actor: new FileSystemActorDriver(state),
17+
};
18+
}

packages/drivers/file-system/src/utils.ts renamed to packages/core/src/drivers/file-system/utils.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ import * as fs from "fs/promises";
22
import * as fsSync from "fs";
33
import * as path from "path";
44
import * as crypto from "crypto";
5-
import envPaths from "env-paths";
5+
import * as os from "os";
66

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

1010
/**
1111
* Create a hash for a path, normalizing it first
1212
*/
1313
function createHashForPath(dirPath: string): string {
1414
// Normalize the path first
1515
const normalizedPath = path.normalize(dirPath);
16-
16+
1717
// Extract the last path component for readability
1818
const lastComponent = path.basename(normalizedPath);
19-
19+
2020
// Create SHA-256 hash
2121
const hash = crypto
2222
.createHash("sha256")
2323
.update(normalizedPath)
2424
.digest("hex")
2525
.substring(0, 8); // Take first 8 characters for brevity
26-
26+
2727
return `${lastComponent}-${hash}`;
2828
}
2929

@@ -58,8 +58,10 @@ export async function pathExists(path: string): Promise<boolean> {
5858
/**
5959
* Ensure a directory exists, creating it if necessary
6060
*/
61-
export async function ensureDirectoryExists(directoryPath: string): Promise<void> {
62-
if (!await pathExists(directoryPath)) {
61+
export async function ensureDirectoryExists(
62+
directoryPath: string,
63+
): Promise<void> {
64+
if (!(await pathExists(directoryPath))) {
6365
await fs.mkdir(directoryPath, { recursive: true });
6466
}
6567
}
@@ -74,3 +76,25 @@ export function ensureDirectoryExistsSync(directoryPath: string): void {
7476
}
7577
}
7678

79+
/**
80+
* Returns platform-specific data directory
81+
*/
82+
function getDataPath(appName: string): string {
83+
const platform = process.platform;
84+
const homeDir = os.homedir();
85+
86+
switch (platform) {
87+
case "win32":
88+
return path.join(
89+
process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"),
90+
appName,
91+
);
92+
case "darwin":
93+
return path.join(homeDir, "Library", "Application Support", appName);
94+
default: // linux and others
95+
return path.join(
96+
process.env.XDG_DATA_HOME || path.join(homeDir, ".local", "share"),
97+
appName,
98+
);
99+
}
100+
}

packages/core/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { logger } from "./actor/log";
77
import { createMemoryDriver } from "./drivers/memory/mod";
88
import { createRivetManagerDriver } from "./drivers/rivet/mod";
99
import { type DriverConfig, UserError } from "./mod";
10+
import { createFileSystemDriver } from "./drivers/file-system/mod";
1011

1112
export const VERSION = pkgJson.version;
1213

@@ -39,8 +40,10 @@ export type UpgradeWebSocket = (
3940
*/
4041
export function createDefaultDriver(): DriverConfig {
4142
const driver = getEnvUniversal("RIVETKIT_DRIVER");
42-
console.log("driver", driver);
43-
if (!driver || driver === "memory") {
43+
if (!driver || driver === "file-system") {
44+
logger().info("using default file system driver");
45+
return createFileSystemDriver();
46+
} else if (driver === "memory") {
4447
logger().info("using default memory driver");
4548
return createMemoryDriver();
4649
} else if (driver === "rivet") {

packages/drivers/file-system/package.json

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/drivers/file-system/src/mod.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/drivers/file-system/tests/driver-tests.test.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)