-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobjectstack.config.ts
More file actions
103 lines (97 loc) · 3.89 KB
/
objectstack.config.ts
File metadata and controls
103 lines (97 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* ObjectQL Demo — Application Configuration
*
* ObjectStack configuration for the demo application.
* Uses @objectql/driver-turso when TURSO_DATABASE_URL is set,
* falls back to MemoryDriver for zero-config local development.
*
* For local development: `pnpm dev` (uses @objectstack/cli)
* For Vercel deployment: configured via api/[[...route]].ts
*/
import { createRequire } from 'module';
import * as path from 'path';
// Polyfill require and __dirname for ESM
if (typeof globalThis.require === 'undefined') {
const require = createRequire(import.meta.url);
(globalThis as any).require = require;
}
if (typeof globalThis.__dirname === 'undefined') {
(globalThis as any).__dirname = path.dirname(new URL(import.meta.url).pathname);
}
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
import { AuthPlugin } from '@objectstack/plugin-auth';
import { ConsolePlugin } from '@object-ui/console';
import { ObjectQLPlugin } from '@objectstack/objectql';
import { QueryPlugin } from '@objectql/plugin-query';
import { ValidatorPlugin } from '@objectql/plugin-validator';
import { FormulaPlugin } from '@objectql/plugin-formula';
import { ObjectQLSecurityPlugin } from '@objectql/plugin-security';
import { createApiRegistryPlugin } from '@objectstack/core';
import { MemoryDriver } from '@objectql/driver-memory';
import { createTursoDriver } from '@objectql/driver-turso';
import { createAppPlugin } from '@objectql/platform-node';
// Choose driver based on environment — Turso when TURSO_DATABASE_URL is set,
// MemoryDriver otherwise (zero-config fallback for quick starts).
function createDefaultDriver() {
const tursoUrl = process.env.TURSO_DATABASE_URL;
if (tursoUrl) {
console.log(`🗄️ Driver: Turso (${tursoUrl})`);
const syncUrl = process.env.TURSO_SYNC_URL;
return createTursoDriver({
url: tursoUrl,
authToken: process.env.TURSO_AUTH_TOKEN,
syncUrl,
sync: syncUrl
? {
intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
onConnect: true,
}
: undefined,
});
}
console.log('🗄️ Driver: Memory (in-memory, non-persistent)');
return new MemoryDriver();
}
const defaultDriver = createDefaultDriver();
// Load the project-tracker showcase metadata.
const projectTrackerPlugin = createAppPlugin({
id: 'project-tracker',
dir: path.join(__dirname, '../../examples/showcase/project-tracker/src'),
label: 'Project Tracker',
description: 'A showcase of ObjectQL capabilities including all field types.',
});
export default {
metadata: {
name: 'objectql-demo',
version: '1.0.0',
},
plugins: [
createApiRegistryPlugin(),
new HonoServerPlugin({}),
new ConsolePlugin(),
// Register the active driver as 'driver.default' service so upstream
// ObjectQLPlugin can discover it during start() phase.
{
name: 'driver-default',
init: async (ctx: any) => {
ctx.registerService('driver.default', defaultDriver);
},
start: async () => {
// Connect Turso driver if applicable (MemoryDriver.connect() is a no-op)
if (typeof (defaultDriver as any).connect === 'function') {
await (defaultDriver as { connect: () => Promise<void> }).connect();
}
},
},
projectTrackerPlugin,
new ObjectQLPlugin(),
new QueryPlugin({ datasources: { default: defaultDriver } }),
new ValidatorPlugin(),
new FormulaPlugin(),
new ObjectQLSecurityPlugin({ enableAudit: false }),
new AuthPlugin({
secret: process.env.AUTH_SECRET || 'objectql-demo-dev-secret-change-me-in-production',
trustedOrigins: ['http://localhost:*'],
}),
],
};