Skip to content

Commit 1b19db7

Browse files
Copilothotlong
andcommitted
Fix platform-node Jest config to handle @objectstack packages
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent cf65974 commit 1b19db7

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

packages/foundation/platform-node/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ module.exports = {
1212
testMatch: ['**/test/**/*.test.ts'],
1313
moduleNameMapper: {
1414
'^@objectql/(.*)$': '<rootDir>/../$1/src',
15+
'^@objectstack/runtime$': '<rootDir>/test/__mocks__/@objectstack/runtime.ts',
1516
},
1617
transform: {
1718
'^.+\\.ts$': ['ts-jest', {
1819
isolatedModules: true,
20+
tsconfig: {
21+
esModuleInterop: true,
22+
allowSyntheticDefaultImports: true,
23+
}
1924
}],
2025
},
26+
transformIgnorePatterns: [
27+
'node_modules/(?!(@objectstack))',
28+
],
2129
};
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Mock for @objectstack/runtime
3+
* This mock is needed because the npm package has issues with Jest
4+
* and we want to focus on testing ObjectQL's logic, not the kernel integration.
5+
*
6+
* For now, this mock delegates to the legacy driver to maintain backward compatibility
7+
* during the migration phase.
8+
*/
9+
10+
export class ObjectStackKernel {
11+
public ql: unknown = null;
12+
private plugins: any[] = [];
13+
private driver: any = null; // Will be set by the ObjectQL app
14+
15+
constructor(plugins: any[] = []) {
16+
this.plugins = plugins;
17+
}
18+
19+
// Method to set the driver for delegation during migration
20+
setDriver(driver: any): void {
21+
this.driver = driver;
22+
}
23+
24+
async start(): Promise<void> {
25+
// Mock implementation that calls plugin lifecycle methods
26+
for (const plugin of this.plugins) {
27+
if (plugin.install) {
28+
await plugin.install({ engine: this });
29+
}
30+
}
31+
for (const plugin of this.plugins) {
32+
if (plugin.onStart) {
33+
await plugin.onStart({ engine: this });
34+
}
35+
}
36+
}
37+
38+
async seed(): Promise<void> {
39+
// Mock implementation
40+
}
41+
42+
async find(objectName: string, query: any): Promise<{ value: Record<string, any>[]; count: number }> {
43+
// Delegate to driver during migration phase
44+
if (this.driver) {
45+
// Convert QueryAST back to UnifiedQuery format for driver
46+
const unifiedQuery: any = {};
47+
48+
if (query.fields) {
49+
unifiedQuery.fields = query.fields;
50+
}
51+
if (query.filters) {
52+
unifiedQuery.filters = query.filters;
53+
}
54+
if (query.sort) {
55+
unifiedQuery.sort = query.sort.map((s: any) => [s.field, s.order]);
56+
}
57+
if (query.top !== undefined) {
58+
unifiedQuery.limit = query.top;
59+
}
60+
if (query.skip !== undefined) {
61+
unifiedQuery.skip = query.skip;
62+
}
63+
if (query.aggregations) {
64+
unifiedQuery.aggregate = query.aggregations.map((agg: any) => ({
65+
func: agg.function,
66+
field: agg.field,
67+
alias: agg.alias
68+
}));
69+
}
70+
if (query.groupBy) {
71+
unifiedQuery.groupBy = query.groupBy;
72+
}
73+
74+
const results = await this.driver.find(objectName, unifiedQuery, {});
75+
return { value: results, count: results.length };
76+
}
77+
return { value: [], count: 0 };
78+
}
79+
80+
async get(objectName: string, id: string): Promise<Record<string, any>> {
81+
// Delegate to driver during migration phase
82+
if (this.driver) {
83+
return await this.driver.findOne(objectName, id, {}, {});
84+
}
85+
return {};
86+
}
87+
88+
async create(objectName: string, data: any): Promise<Record<string, any>> {
89+
// Delegate to driver during migration phase
90+
if (this.driver) {
91+
return await this.driver.create(objectName, data, {});
92+
}
93+
return data;
94+
}
95+
96+
async update(objectName: string, id: string, data: any): Promise<Record<string, any>> {
97+
// Delegate to driver during migration phase
98+
if (this.driver) {
99+
return await this.driver.update(objectName, id, data, {});
100+
}
101+
return data;
102+
}
103+
104+
async delete(objectName: string, id: string): Promise<boolean> {
105+
// Delegate to driver during migration phase
106+
if (this.driver) {
107+
await this.driver.delete(objectName, id, {});
108+
return true;
109+
}
110+
return true;
111+
}
112+
113+
getMetadata(objectName: string): any {
114+
return {};
115+
}
116+
117+
getView(objectName: string, viewType?: 'list' | 'form'): any {
118+
return null;
119+
}
120+
}
121+
122+
export class ObjectStackRuntimeProtocol {}
123+
124+
export interface RuntimeContext {
125+
engine: ObjectStackKernel;
126+
}
127+
128+
export interface RuntimePlugin {
129+
name: string;
130+
install?: (ctx: RuntimeContext) => void | Promise<void>;
131+
onStart?: (ctx: RuntimeContext) => void | Promise<void>;
132+
}

0 commit comments

Comments
 (0)