Skip to content

Commit 068c40f

Browse files
Copilothotlong
andcommitted
Fix code review issues: improve error handling and type safety
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent b8a22bf commit 068c40f

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

packages/plugin-msw/src/msw-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class MSWPlugin implements Plugin, RuntimePlugin {
215215
const kernel = ctx.getKernel();
216216
this.protocol = new ObjectStackRuntimeProtocol(kernel);
217217
} else {
218-
ctx.logger.warn('[MSWPlugin] Cannot access kernel from context');
218+
throw new Error('[MSWPlugin] Cannot access kernel from context - getKernel() not available');
219219
}
220220

221221
this.setupHandlers();

packages/runtime/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ export { ObjectQL, SchemaRegistry } from '@objectstack/objectql';
33

44
// Export Kernels
55
export { ObjectKernel } from './mini-kernel.js';
6-
// @deprecated Use ObjectKernel instead
6+
7+
/**
8+
* @deprecated Use ObjectKernel instead for better modularity and plugin architecture.
9+
* ObjectStackKernel is kept for backward compatibility only.
10+
* @see {ObjectKernel} - The recommended MiniKernel implementation
11+
*/
712
export { ObjectStackKernel } from './kernel.js';
813

914
// Export Plugins

packages/runtime/src/protocol.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ export class ObjectStackRuntimeProtocol {
2020
if (engine instanceof ObjectStackKernel) {
2121
this.legacyKernel = engine;
2222
} else if (engine instanceof ObjectKernel) {
23-
// Get ObjectQL service from kernel
23+
// Get ObjectQL service from kernel - will be validated when needed
2424
try {
2525
this.objectql = engine.getService<ObjectQL>('objectql');
2626
} catch (e) {
27-
console.warn('[Protocol] ObjectQL service not found in kernel');
27+
// Don't fail construction - some protocol methods may still work
28+
// Error will be thrown when getObjectQL() is called
29+
console.warn('[Protocol] ObjectQL service not found in kernel - data operations will fail');
2830
}
2931
}
3032
}
3133

3234
/**
3335
* Get ObjectQL instance - works with both kernel types
36+
* @throws Error if ObjectQL is not available
3437
*/
3538
private getObjectQL(): ObjectQL {
3639
if (this.legacyKernel) {
@@ -40,7 +43,7 @@ export class ObjectStackRuntimeProtocol {
4043
return this.legacyKernel.ql;
4144
}
4245
if (!this.objectql) {
43-
throw new Error('[Protocol] ObjectQL service not available');
46+
throw new Error('[Protocol] ObjectQL service not available in kernel. Ensure ObjectQLPlugin is registered and initialized.');
4447
}
4548
return this.objectql;
4649
}
@@ -155,7 +158,7 @@ export class ObjectStackRuntimeProtocol {
155158
return await this.legacyKernel.find(objectName, query);
156159
}
157160
const ql = this.getObjectQL();
158-
const results = await ql.find(objectName, { top: 100 });
161+
const results = await ql.find(objectName, query || { top: 100 });
159162
return { value: results, count: results.length };
160163
}
161164

@@ -165,7 +168,7 @@ export class ObjectStackRuntimeProtocol {
165168
return await this.legacyKernel.find(objectName, body);
166169
}
167170
const ql = this.getObjectQL();
168-
const results = await ql.find(objectName, { top: 100 });
171+
const results = await ql.find(objectName, body || { top: 100 });
169172
return { value: results, count: results.length };
170173
}
171174

@@ -175,7 +178,9 @@ export class ObjectStackRuntimeProtocol {
175178
return await this.legacyKernel.get(objectName, id);
176179
}
177180
const ql = this.getObjectQL();
178-
const results = await ql.find(objectName, { top: 1 });
181+
// TODO: Implement proper ID-based lookup once ObjectQL supports it
182+
// For now, this is a limitation of the current ObjectQL API
183+
const results = await ql.find(objectName, { top: 1, filter: { id } });
179184
return results[0];
180185
}
181186

packages/runtime/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface PluginContext {
6767
* Get the kernel instance (for advanced use cases)
6868
* @returns Kernel instance
6969
*/
70-
getKernel?(): any;
70+
getKernel?(): ObjectStackKernel | ObjectKernel;
7171
}
7272

7373
/**

0 commit comments

Comments
 (0)