@@ -83,18 +83,6 @@ async function ensureKernel(): Promise<ObjectKernel> {
8383
8484 await kernel . use ( new DriverPlugin ( tursoDriver , 'turso' ) ) ;
8585
86- // Configure datasource mapping: sys namespace → Turso, everything else → Memory
87- const ql = await kernel . getServiceAsync < ObjectQL > ( 'objectql' ) ;
88- if ( ql && typeof ql . setDatasourceMapping === 'function' ) {
89- ql . setDatasourceMapping ( [
90- // System objects (sys namespace) use Turso for persistent storage
91- { namespace : 'sys' , datasource : 'turso' } ,
92- // All other objects use Memory driver as default
93- { default : true , datasource : 'memory' } ,
94- ] ) ;
95- console . log ( '[Vercel] Datasource mapping configured: sys → turso, default → memory' ) ;
96- }
97-
9886 // Load app manifests (BEFORE plugins that need object schemas)
9987 await kernel . use ( new AppPlugin ( CrmApp ) ) ;
10088 await kernel . use ( new AppPlugin ( TodoApp ) ) ;
@@ -129,6 +117,18 @@ async function ensureKernel(): Promise<ObjectKernel> {
129117
130118 await kernel . bootstrap ( ) ;
131119
120+ // Configure datasource mapping AFTER bootstrap (ObjectQL service is registered during init)
121+ const ql = await kernel . getServiceAsync < ObjectQL > ( 'objectql' ) ;
122+ if ( ql && typeof ql . setDatasourceMapping === 'function' ) {
123+ ql . setDatasourceMapping ( [
124+ // System objects (sys namespace) use Turso for persistent storage
125+ { namespace : 'sys' , datasource : 'turso' } ,
126+ // All other objects use Memory driver as default
127+ { default : true , datasource : 'memory' } ,
128+ ] ) ;
129+ console . log ( '[Vercel] Datasource mapping configured: sys → turso, default → memory' ) ;
130+ }
131+
132132 _kernel = kernel ;
133133 console . log ( '[Vercel] Kernel ready.' ) ;
134134 return kernel ;
0 commit comments