Skip to content

Commit fbb2209

Browse files
committed
refactor: convert methods in MemoryProtocol to class properties for consistency
1 parent 70de8b6 commit fbb2209

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

examples/crm-app/src/mocks/MemoryProtocol.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ export class MemoryProtocol implements IObjectStackProtocol {
1212
this.objects = objects;
1313
}
1414

15-
async findData(object: string, params?: any): Promise<any[]> {
15+
findData = async (object: string, params?: any): Promise<any[]> => {
1616
const items = this.data[object] || [];
1717
// Minimal mock filtering could go here
1818
return items;
1919
}
2020

21-
async getData(object: string, id: string): Promise<any> {
21+
getData = async (object: string, id: string): Promise<any> => {
2222
const items = this.data[object] || [];
2323
const item = items.find((i: any) => i.id === id);
2424
if (!item) throw new Error(`Record not found: ${object} ${id}`);
2525
return item;
2626
}
2727

28-
async createData(object: string, data: any): Promise<any> {
28+
createData = async (object: string, data: any): Promise<any> => {
2929
if (!this.data[object]) this.data[object] = [];
3030
const newItem = { id: Math.random().toString(36).substr(2, 9), ...data };
3131
this.data[object].push(newItem);
3232
return newItem;
3333
}
3434

35-
async updateData(object: string, id: string, data: any): Promise<any> {
35+
updateData = async (object: string, id: string, data: any): Promise<any> => {
3636
const items = this.data[object] || [];
3737
const index = items.findIndex((i: any) => i.id === id);
3838
if (index === -1) throw new Error(`Record not found: ${object} ${id}`);
@@ -42,7 +42,7 @@ export class MemoryProtocol implements IObjectStackProtocol {
4242
return updated;
4343
}
4444

45-
async deleteData(object: string, id: string): Promise<any> {
45+
deleteData = async (object: string, id: string): Promise<any> => {
4646
if (!this.data[object]) return { success: false };
4747
const initialLength = this.data[object].length;
4848
this.data[object] = this.data[object].filter((i: any) => i.id !== id);

examples/crm-app/src/mocks/handlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MemoryProtocol } from './MemoryProtocol';
77
// Initialize the mock server with our protocol definition
88
// The JSON protocol def is insufficient for methods, so we wrap it or replace it with an implementation
99
const memoryProtocol = new MemoryProtocol({}, (protocol as any).objects);
10+
console.log('[MockServer] Initializing with MemoryProtocol', memoryProtocol);
1011
ObjectStackServer.init(memoryProtocol as any);
1112

1213
export const seedData = async () => {

0 commit comments

Comments
 (0)