Skip to content

Commit ff83982

Browse files
committed
refactor: streamline Turso driver configuration and plugin integration in objectstack.config.ts
1 parent 9348a76 commit ff83982

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

apps/server/objectstack.config.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,12 @@ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL
3434
? `https://${process.env.VERCEL_URL}` : undefined)
3535
?? 'http://localhost:3000';
3636

37-
// Turso persistent storage — enabled when env vars are configured
38-
const tursoUrl = process.env.TURSO_DATABASE_URL;
39-
const tursoToken = process.env.TURSO_AUTH_TOKEN;
40-
const useTurso = !!(tursoUrl && tursoToken);
41-
42-
const driverPlugins = useTurso
43-
? [
44-
new DriverPlugin(new InMemoryDriver(), 'memory'),
45-
new DriverPlugin(new TursoDriver({ url: tursoUrl!, authToken: tursoToken! }), 'turso'),
46-
]
47-
: [new DriverPlugin(new InMemoryDriver(), 'memory')];
37+
// Turso driver for sys namespace — remote when env vars are configured, local SQLite otherwise
38+
const tursoDriver = new TursoDriver(
39+
process.env.TURSO_DATABASE_URL
40+
? { url: process.env.TURSO_DATABASE_URL, authToken: process.env.TURSO_AUTH_TOKEN }
41+
: { url: 'file:.objectstack/data/dev.db' },
42+
);
4843

4944
export default defineStack({
5045
manifest: {
@@ -57,7 +52,8 @@ export default defineStack({
5752
},
5853
plugins: [
5954
new ObjectQLPlugin(),
60-
...driverPlugins,
55+
new DriverPlugin(new InMemoryDriver(), 'memory'),
56+
new DriverPlugin(tursoDriver, 'turso'),
6157
new AppPlugin(CrmApp),
6258
new AppPlugin(TodoApp),
6359
new AppPlugin(BiPluginManifest),
@@ -74,11 +70,8 @@ export default defineStack({
7470
new AutomationServicePlugin(),
7571
new AnalyticsServicePlugin(),
7672
],
77-
// When Turso is configured, route sys namespace to persistent storage
78-
...(useTurso && {
79-
datasourceMapping: [
80-
{ namespace: 'sys', datasource: 'turso' },
81-
{ default: true, datasource: 'memory' },
82-
],
83-
}),
73+
datasourceMapping: [
74+
{ namespace: 'sys', datasource: 'turso' },
75+
{ default: true, datasource: 'memory' },
76+
],
8477
});

0 commit comments

Comments
 (0)