Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions examples/custom-objectql-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* custom configuration.
*/

import { ObjectStackKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, ObjectQL } from '@objectstack/runtime';
import { InMemoryDriver } from '@objectstack/driver-memory';

(async () => {
Expand All @@ -27,18 +27,22 @@ import { InMemoryDriver } from '@objectstack/driver-memory';
});

// Create kernel with the custom ObjectQL instance
const kernel = new ObjectStackKernel([
const kernel = new ObjectKernel();

kernel
// Register your custom ObjectQL instance
new ObjectQLPlugin(customQL),
.use(new ObjectQLPlugin(customQL))

// Add your driver
new InMemoryDriver(),
.use(new DriverPlugin(new InMemoryDriver(), 'memory'));

// Add other plugins and app configs as needed
]);

await kernel.start();
await kernel.bootstrap();

console.log('✅ Kernel started with custom ObjectQL instance');
console.log('ObjectQL instance:', kernel.ql);

// Access ObjectQL via service registry
const objectql = kernel.getService('objectql');
console.log('ObjectQL instance:', objectql);
})();
15 changes: 8 additions & 7 deletions examples/host/debug-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { ObjectStackKernel, ObjectQLPlugin } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';
import { SchemaRegistry, ObjectQL } from '@objectstack/objectql';
import { InMemoryDriver } from '@objectstack/driver-memory';

Expand All @@ -10,13 +10,14 @@ import TodoApp from '@objectstack/example-todo/objectstack.config';
console.log('Apps:', [TodoApp.name]);
console.log('Objects inside App:', TodoApp.objects?.map((o: any) => o.name));

const kernel = new ObjectStackKernel([
new ObjectQLPlugin(),
TodoApp,
new InMemoryDriver()
]);
const kernel = new ObjectKernel();

await kernel.start();
kernel
.use(new ObjectQLPlugin())
.use(new DriverPlugin(new InMemoryDriver(), 'memory'))
.use(new AppManifestPlugin(TodoApp));

await kernel.bootstrap();

console.log('--- Post Start ---');

Expand Down
38 changes: 16 additions & 22 deletions examples/host/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectStackKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import ObjectQL.

Copilot Autofix

AI 2 months ago

In general, unused imports should be removed from the import list so the code only brings in what it actually uses. This improves readability and avoids potential linting or compilation warnings.

The best fix here is to edit examples/host/src/index.ts and modify the first import statement: remove ObjectQL from the destructured import from @objectstack/runtime, keeping the remaining imported names unchanged. No other code changes or new imports are required, and this will not alter runtime behavior because ObjectQL was never referenced.

Concretely: in examples/host/src/index.ts, line 1 currently imports { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL }. Replace that line with an import that only includes { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin }.

Suggested changeset 1
examples/host/src/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/host/src/index.ts b/examples/host/src/index.ts
--- a/examples/host/src/index.ts
+++ b/examples/host/src/index.ts
@@ -1,4 +1,4 @@
-import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';
+import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';
 import { InMemoryDriver } from '@objectstack/driver-memory';
 import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
 
EOF
@@ -1,4 +1,4 @@
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';
import { InMemoryDriver } from '@objectstack/driver-memory';
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';

Copilot is powered by AI and may make mistakes. Always verify output.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import ObjectQL.

Suggested change
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin, ObjectQL } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';

Copilot uses AI. Check for mistakes.
import { InMemoryDriver } from '@objectstack/driver-memory';
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';

Expand All @@ -9,32 +9,26 @@
(async () => {
console.log('🚀 Booting Kernel...');

// Option 1: Use default ObjectQL via plugin (recommended)
const kernel = new ObjectStackKernel([
// Register ObjectQL engine explicitly via plugin
new ObjectQLPlugin(),

// App manifests
CrmApp,
TodoApp,
BiPluginManifest,
// Use MiniKernel architecture
const kernel = new ObjectKernel();

kernel
// Register ObjectQL engine
.use(new ObjectQLPlugin())

// Database driver
new InMemoryDriver(),
.use(new DriverPlugin(new InMemoryDriver(), 'memory'))

// App manifests
.use(new AppManifestPlugin(CrmApp))
.use(new AppManifestPlugin(TodoApp))
.use(new AppManifestPlugin(BiPluginManifest))

// Load the Hono Server Plugin
new HonoServerPlugin({
.use(new HonoServerPlugin({
port: 3004,
staticRoot: './public'
})
]);

// Option 2: Use custom ObjectQL instance
// const customQL = new ObjectQL({ env: 'production', customConfig: true });
// const kernel = new ObjectStackKernel([
// new ObjectQLPlugin(customQL),
// ...other plugins
// ]);
}));

await kernel.start();
await kernel.bootstrap();
})();
31 changes: 15 additions & 16 deletions examples/msw-react-crud/src/mocks/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* and the MSW Plugin which automatically exposes the API.
*/

import { ObjectStackKernel, ObjectQLPlugin } from '@objectstack/runtime';
import { ObjectKernel, ObjectQLPlugin, DriverPlugin, AppManifestPlugin } from '@objectstack/runtime';
import { InMemoryDriver } from '@objectstack/driver-memory';
import { MSWPlugin } from '@objectstack/plugin-msw';
// import appConfig from '../../objectstack.config';
import todoConfig from '@objectstack/example-todo/objectstack.config';

let kernel: ObjectStackKernel | null = null;
let kernel: ObjectKernel | null = null;

export async function startMockServer() {
if (kernel) return;
Expand All @@ -20,28 +20,27 @@ export async function startMockServer() {

const driver = new InMemoryDriver();

// Define Seed Data using the Dataset Protocol
// We use the data defined in the Todo App config
// Create kernel with MiniKernel architecture
kernel = new ObjectKernel();

kernel = new ObjectStackKernel([
// Register ObjectQL engine explicitly
new ObjectQLPlugin(),
kernel
// Register ObjectQL engine
.use(new ObjectQLPlugin())

// Todo App Config (contains objects and data)
todoConfig,
// Register the driver
.use(new DriverPlugin(driver, 'memory'))

// In-Memory Database (runs in browser)
driver,
// Load todo app config as a plugin
.use(new AppManifestPlugin(todoConfig))

// MSW Plugin (intercepts network requests)
new MSWPlugin({
.use(new MSWPlugin({
enableBrowser: true,
baseUrl: '/api/v1',
logRequests: true
})
]);

await kernel.start();
}));

await kernel.bootstrap();

return kernel;
}
Expand Down
98 changes: 92 additions & 6 deletions packages/plugin-msw/src/msw-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { http, HttpResponse } from 'msw';
import { setupWorker } from 'msw/browser';
import { RuntimePlugin, RuntimeContext, ObjectStackRuntimeProtocol } from '@objectstack/runtime';
import {
RuntimePlugin,
RuntimeContext,
Plugin,
PluginContext,
ObjectStackRuntimeProtocol,
ObjectKernel
Comment on lines +8 to +9
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import ObjectKernel.

Suggested change
ObjectStackRuntimeProtocol,
ObjectKernel
ObjectStackRuntimeProtocol

Copilot uses AI. Check for mistakes.
} from '@objectstack/runtime';
Comment on lines +3 to +10

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import ObjectKernel.

Copilot Autofix

AI 2 months ago

To fix the unused import, remove ObjectKernel from the import list on line 3 while leaving all actually used imports intact. This will eliminate the unused symbol without affecting existing functionality.

Concretely, in packages/plugin-msw/src/msw-plugin.ts, edit the import from @objectstack/runtime so that ObjectKernel is no longer included in the named imports. No additional code changes or imports are needed, and no other lines must be modified.

Suggested changeset 1
packages/plugin-msw/src/msw-plugin.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/plugin-msw/src/msw-plugin.ts b/packages/plugin-msw/src/msw-plugin.ts
--- a/packages/plugin-msw/src/msw-plugin.ts
+++ b/packages/plugin-msw/src/msw-plugin.ts
@@ -5,10 +5,10 @@
     RuntimeContext, 
     Plugin, 
     PluginContext, 
-    ObjectStackRuntimeProtocol,
-    ObjectKernel 
+    ObjectStackRuntimeProtocol
 } from '@objectstack/runtime';
 
+
 export interface MSWPluginOptions {
     /**
      * Enable MSW in the browser environment
EOF
@@ -5,10 +5,10 @@
RuntimeContext,
Plugin,
PluginContext,
ObjectStackRuntimeProtocol,
ObjectKernel
ObjectStackRuntimeProtocol
} from '@objectstack/runtime';


export interface MSWPluginOptions {
/**
* Enable MSW in the browser environment
Copilot is powered by AI and may make mistakes. Always verify output.

export interface MSWPluginOptions {
/**
Expand Down Expand Up @@ -149,10 +156,20 @@
* This plugin enables Mock Service Worker integration for testing and development.
* It automatically mocks API endpoints using the ObjectStack runtime protocol.
*
* Supports both legacy RuntimePlugin and new Plugin interfaces.
*
* @example
* ```typescript
* import { MSWPlugin } from '@objectstack/plugin-msw';
*
* // With new ObjectKernel
* const kernel = new ObjectKernel();
* kernel.use(new MSWPlugin({
* enableBrowser: true,
* baseUrl: '/api/v1'
* }));
*
* // With legacy ObjectStackKernel
* const runtime = new ObjectStackRuntime({
* plugins: [
* new MSWPlugin({
Expand All @@ -163,11 +180,14 @@
* });
* ```
*/
export class MSWPlugin implements RuntimePlugin {
name = 'msw';
export class MSWPlugin implements Plugin, RuntimePlugin {
name = 'com.objectstack.plugin.msw';
version = '1.0.0';
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSWPlugin should declare a dependency on the ObjectQL plugin since it creates an ObjectStackRuntimeProtocol that requires ObjectQL to be available. Add dependencies = ['com.objectstack.engine.objectql'] to ensure proper initialization order. Without this, the plugin might start before ObjectQL is initialized, causing runtime errors.

Suggested change
version = '1.0.0';
version = '1.0.0';
dependencies = ['com.objectstack.engine.objectql'];

Copilot uses AI. Check for mistakes.

private options: MSWPluginOptions;
private worker: any;
private handlers: Array<any> = [];
private protocol?: ObjectStackRuntimeProtocol;

constructor(options: MSWPluginOptions = {}) {
this.options = {
Expand All @@ -178,9 +198,69 @@
};
}

/**
* New Plugin interface - init phase
*/
async init(ctx: PluginContext) {
// Protocol will be created in start phase
ctx.logger.log('[MSWPlugin] Initialized');
}

/**
* New Plugin interface - start phase
*/
async start(ctx: PluginContext) {
// Get the kernel and create protocol
if (ctx.getKernel) {
const kernel = ctx.getKernel();
this.protocol = new ObjectStackRuntimeProtocol(kernel);
} else {
throw new Error('[MSWPlugin] Cannot access kernel from context - getKernel() not available');
}

this.setupHandlers();
await this.startWorker();
}

/**
* New Plugin interface - destroy phase
*/
async destroy() {
await this.stopWorker();
}

/**
* Legacy RuntimePlugin interface - install
*/
install(ctx: RuntimeContext) {
const { engine } = ctx;
const protocol = new ObjectStackRuntimeProtocol(engine);
this.protocol = new ObjectStackRuntimeProtocol(engine);
this.setupHandlers();
}

/**
* Legacy RuntimePlugin interface - onStart
*/
async onStart(ctx: RuntimeContext) {
await this.startWorker();
}

/**
* Legacy RuntimePlugin interface - onStop
*/
async onStop() {
await this.stopWorker();
}

/**
* Setup MSW handlers
*/
private setupHandlers() {
if (!this.protocol) {
throw new Error('[MSWPlugin] Protocol not initialized');
}

const protocol = this.protocol;

// Initialize ObjectStackServer
ObjectStackServer.init(
Expand Down Expand Up @@ -312,7 +392,10 @@
console.log(`[MSWPlugin] Installed ${this.handlers.length} request handlers.`);
}

async onStart(ctx: RuntimeContext) {
/**
* Start the MSW worker
*/
private async startWorker() {
if (this.options.enableBrowser && typeof window !== 'undefined') {
// Browser environment
this.worker = setupWorker(...this.handlers);
Expand All @@ -325,7 +408,10 @@
}
}

async onStop() {
/**
* Stop the MSW worker
*/
private async stopWorker() {
if (this.worker) {
this.worker.stop();
console.log(`[MSWPlugin] Stopped MSW worker.`);
Expand Down
Loading
Loading