88import { ObjectStackKernel } from '@objectstack/runtime' ;
99import { InMemoryDriver } from '@objectstack/driver-memory' ;
1010import { MSWPlugin } from '@objectstack/plugin-msw' ;
11- import appConfig from '../../objectstack.config' ;
11+ // import appConfig from '../../objectstack.config';
12+ import todoConfig from '@objectstack/example-todo/objectstack.config' ;
1213
1314let kernel : ObjectStackKernel | null = null ;
1415
@@ -19,9 +20,12 @@ export async function startMockServer() {
1920
2021 const driver = new InMemoryDriver ( ) ;
2122
23+ // Define Seed Data using the Dataset Protocol
24+ // We use the data defined in the Todo App config
25+
2226 kernel = new ObjectStackKernel ( [
23- // App Config
24- appConfig ,
27+ // Todo App Config (contains objects and data)
28+ todoConfig ,
2529
2630 // In-Memory Database (runs in browser)
2731 driver ,
@@ -36,50 +40,6 @@ export async function startMockServer() {
3640
3741 await kernel . start ( ) ;
3842
39- // Seed Data: Use the driver directly
40- if ( driver ) {
41- const tasks = [
42- {
43- id : '1' ,
44- subject : 'Complete MSW integration example' ,
45- priority : 1 ,
46- isCompleted : false ,
47- createdAt : new Date ( ) . toISOString ( )
48- } ,
49- {
50- id : '2' ,
51- subject : 'Test CRUD operations with React' ,
52- priority : 2 ,
53- isCompleted : false ,
54- createdAt : new Date ( ) . toISOString ( )
55- } ,
56- {
57- id : '3' ,
58- subject : 'Write documentation' ,
59- priority : 3 ,
60- isCompleted : true ,
61- createdAt : new Date ( ) . toISOString ( )
62- }
63- ] ;
64-
65- // Ensure schema exists (Driver internal API)
66- if ( driver . syncSchema ) {
67- await driver . syncSchema ( 'task' , { } ) ;
68- }
69-
70- // Insert Data
71- if ( driver . create ) {
72- for ( const task of tasks ) {
73- try {
74- await driver . create ( 'task' , task ) ;
75- } catch ( e ) {
76- // Ignore key conflict if seeded
77- }
78- }
79- console . log ( '[MSW] Seeded initial data.' ) ;
80- }
81- }
82-
8343 return kernel ;
8444}
8545
0 commit comments