@@ -3,9 +3,12 @@ import { setupWorker } from 'msw/browser';
33import {
44 Plugin ,
55 PluginContext ,
6- ObjectStackRuntimeProtocol ,
7- ObjectKernel
6+ ObjectKernel ,
7+ ObjectStackProtocolImplementation ,
8+ IDataEngine
89} from '@objectstack/runtime' ;
10+ import { IObjectStackProtocol } from '@objectstack/spec/api' ;
11+ // import { IDataEngine } from '@objectstack/core';
912
1013export interface MSWPluginOptions {
1114 /**
@@ -33,10 +36,10 @@ export interface MSWPluginOptions {
3336 * ObjectStack Server Mock - Provides mock database functionality
3437 */
3538export class ObjectStackServer {
36- private static protocol : ObjectStackRuntimeProtocol | null = null ;
39+ private static protocol : IObjectStackProtocol | null = null ;
3740 private static logger : ( ( message : string , ...meta : any [ ] ) => void ) | null = null ;
3841
39- static init ( protocol : ObjectStackRuntimeProtocol , logger ?: ( message : string , ...meta : any [ ] ) => void ) {
42+ static init ( protocol : IObjectStackProtocol , logger ?: ( message : string , ...meta : any [ ] ) => void ) {
4043 this . protocol = protocol ;
4144 this . logger = logger || console . log ;
4245 }
@@ -173,7 +176,7 @@ export class MSWPlugin implements Plugin {
173176 private options : MSWPluginOptions ;
174177 private worker : any ;
175178 private handlers : Array < any > = [ ] ;
176- private protocol ?: ObjectStackRuntimeProtocol ;
179+ private protocol ?: IObjectStackProtocol ;
177180
178181 constructor ( options : MSWPluginOptions = { } ) {
179182 this . options = {
@@ -196,12 +199,12 @@ export class MSWPlugin implements Plugin {
196199 * Start phase
197200 */
198201 async start ( ctx : PluginContext ) {
199- // Get the kernel and create protocol
200- if ( ctx . getKernel ) {
201- const kernel = ctx . getKernel ( ) ;
202- this . protocol = new ObjectStackRuntimeProtocol ( kernel ) ;
203- } else {
204- throw new Error ( '[MSWPlugin] Cannot access kernel from context - getKernel() not available ' ) ;
202+ try {
203+ const dataEngine = ctx . getService < IDataEngine > ( 'objectql' ) ;
204+ this . protocol = new ObjectStackProtocolImplementation ( dataEngine ) ;
205+ } catch ( e ) {
206+ console . error ( '[MSWPlugin] Failed to initialize protocol' , e ) ;
207+ throw new Error ( '[MSWPlugin] Failed to initialize protocol (missing objectql service?) ' ) ;
205208 }
206209
207210 this . setupHandlers ( ) ;
0 commit comments