Skip to content

Commit 1e8318f

Browse files
Copilothotlong
andcommitted
Address code review: improve type safety and error handling
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2daf8bc commit 1e8318f

File tree

8 files changed

+37
-10
lines changed

8 files changed

+37
-10
lines changed

examples/showcase/enterprise-erp/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"resolveJsonModule": true
77
},
88
"include": ["src/**/*"],
9-
"exclude": ["node_modules", "dist"]
9+
"exclude": ["node_modules", "dist"],
10+
"references": [
11+
{ "path": "../../../packages/foundation/types" }
12+
]
1013
}

packages/foundation/core/src/app.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ export class ObjectQL implements IObjectQL {
7777
if (config.registry) {
7878
// Copy metadata from provided registry to kernel's registry
7979
for (const type of config.registry.getTypes()) {
80-
for (const item of config.registry.list(type)) {
80+
const items = config.registry.list(type);
81+
for (const item of items) {
82+
// Safely extract the item's id/name
83+
const itemId = typeof item === 'object' && item !== null
84+
? (item as { name?: string; id?: string }).name || (item as { name?: string; id?: string }).id || 'unknown'
85+
: 'unknown';
86+
8187
this.kernel.metadata.register(type, {
8288
type,
83-
id: (item as any).name || (item as any).id,
89+
id: itemId,
8490
content: item
8591
});
8692
}

packages/foundation/core/src/query/filter-translator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import type { Filter } from '@objectql/types';
1010
import type { FilterNode } from '@objectstack/spec';
11+
import { ObjectQLError } from '@objectql/types';
1112

1213
/**
1314
* Filter Translator
@@ -63,7 +64,10 @@ export class FilterTranslator {
6364

6465
// Note: $not operator is not currently supported in the legacy FilterNode format
6566
if (filter.$not) {
66-
throw new Error('$not operator is not supported. Use $ne for field negation instead.');
67+
throw new ObjectQLError({
68+
code: 'UNSUPPORTED_OPERATOR',
69+
message: '$not operator is not supported. Use $ne for field negation instead.'
70+
});
6771
}
6872

6973
// Process field conditions

packages/foundation/core/src/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ObjectRepository {
3838
return this.app.getKernel();
3939
}
4040

41-
private getOptions(extra: any = {}) {
41+
private getOptions(extra: Record<string, unknown> = {}) {
4242
return {
4343
transaction: this.context.transactionHandle,
4444
...extra

packages/foundation/platform-node/src/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function registerObject(registry: MetadataRegistry, obj: any, file: string, pack
298298
// Check for existing object to Merge
299299
const existing = registry.getEntry('object', obj.name);
300300
if (existing) {
301-
const base = existing.content;
301+
const base = existing.content as ObjectConfig;
302302

303303
// Merge Fields: New fields overwrite old ones
304304
if (obj.fields) {

packages/foundation/types/src/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export interface Metadata {
2323
id: string;
2424
path?: string;
2525
package?: string;
26-
content: any;
26+
content: unknown;
2727
}

packages/objectstack/runtime/src/actions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
* Provides a system for registering and executing custom actions on objects
66
*/
77

8+
/**
9+
* Runtime Error
10+
* Simple error class for runtime package
11+
*/
12+
export class RuntimeError extends Error {
13+
constructor(public code: string, message: string) {
14+
super(message);
15+
this.name = 'RuntimeError';
16+
}
17+
}
18+
819
/**
920
* Action Context
1021
* Context passed to action handlers
@@ -80,7 +91,10 @@ export class ActionManager {
8091
const entry = this.actions.get(key);
8192

8293
if (!entry) {
83-
throw new Error(`Action '${actionName}' not found for object '${objectName}'`);
94+
throw new RuntimeError(
95+
'ACTION_NOT_FOUND',
96+
`Action '${actionName}' not found for object '${objectName}'`
97+
);
8498
}
8599

86100
return await entry.handler(ctx);

packages/objectstack/runtime/src/metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface MetadataItem {
1616
/** Unique identifier */
1717
id: string;
1818
/** The actual metadata content */
19-
content: any;
19+
content: unknown;
2020
/** Package name this metadata belongs to */
2121
packageName?: string;
2222
/** Optional path to the metadata source file */
@@ -113,7 +113,7 @@ export class MetadataRegistry {
113113
const items = this.packages.get(packageName);
114114
if (!items) {
115115
// Also try to find by scanning all entries (for compatibility)
116-
for (const [type, typeMap] of this.store.entries()) {
116+
for (const [, typeMap] of this.store.entries()) {
117117
const entriesToDelete: string[] = [];
118118
for (const [id, item] of typeMap.entries()) {
119119
if (item.package === packageName || item.packageName === packageName) {

0 commit comments

Comments
 (0)