Skip to content

Commit b8f92c3

Browse files
committed
refactor: update fetch binding in ObjectStackClient and ObjectStackAdapter for consistency
1 parent 152301f commit b8f92c3

File tree

13 files changed

+200
-135
lines changed

13 files changed

+200
-135
lines changed

examples/crm-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@object-ui/plugin-grid": "workspace:*",
2121
"@object-ui/react": "workspace:*",
2222
"@object-ui/types": "workspace:*",
23+
"@object-ui/example-crm": "workspace:*",
2324
"@objectstack/client": "^0.4.1",
2425
"@objectstack/core": "^0.6.1",
2526
"@objectstack/runtime": "^0.6.1",

examples/crm-app/src/data.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/crm-app/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client';
33
import App from './App';
44
import './index.css';
55

6-
import { startMockServer } from './mocks/runtime';
6+
import { startMockServer } from './mocks/browser';
77
import { initClient } from './client';
88

99
async function enableMocking() {
Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { ObjectKernel, DriverPlugin, AppPlugin } from '@objectstack/runtime';
22
import { ObjectQLPlugin } from '@objectstack/objectql';
33
import { InMemoryDriver } from '@objectstack/driver-memory';
44
import { MSWPlugin } from '@objectstack/plugin-msw';
5-
import appConfig from '../objectstack.config';
6-
import { mockData } from '../data';
5+
import { config as crmConfig } from '@object-ui/example-crm';
76
import { http, HttpResponse } from 'msw';
87

98
let kernel: ObjectKernel | null = null;
@@ -24,7 +23,7 @@ export async function startMockServer() {
2423
// Register the driver
2524
.use(new DriverPlugin(driver, 'memory'))
2625
// Load app config as a plugin
27-
.use(new AppPlugin(appConfig))
26+
.use(new AppPlugin(crmConfig))
2827
// MSW Plugin (intercepts network requests)
2928
.use(new MSWPlugin({
3029
enableBrowser: true,
@@ -36,13 +35,13 @@ export async function startMockServer() {
3635
// We use closure 'driver' variable to bypass objectql service issues
3736
try {
3837
// Use IDataEngine interface directly via driver
39-
const user = (await driver.findOne('user', 'current')) || {};
40-
const contacts = await driver.find('contact', {});
41-
const opportunities = await driver.find('opportunity', {});
38+
// const user = (await driver.findOne('user', 'current')) || {};
39+
const contacts = await driver.find('contact', { object: 'contact' });
40+
const opportunities = await driver.find('opportunity', { object: 'opportunity' });
4241
const stats = { revenue: 125000, leads: 45, deals: 12 };
4342

4443
return HttpResponse.json({
45-
user,
44+
user: { name: "Demo User", role: "admin" }, // simple mock
4645
stats,
4746
contacts,
4847
opportunities
@@ -58,48 +57,26 @@ export async function startMockServer() {
5857
await kernel.bootstrap();
5958

6059
// Seed Data
61-
await initializeMockData(kernel, driver);
60+
await initializeMockData(driver);
6261

6362
return kernel;
6463
}
6564

6665
// Helper to seed data into the in-memory driver
67-
async function initializeMockData(kernel: ObjectKernel, driver: InMemoryDriver) {
68-
console.log('[MockServer] Initializing mock data (fresh)...');
66+
async function initializeMockData(driver: InMemoryDriver) {
67+
console.log('[MockServer] Initializing mock data from manifest...');
6968

70-
try {
71-
// Seed User
72-
if (mockData.user) {
73-
await driver.create('user', { ...mockData.user, id: 'current', _id: 'current' });
74-
}
75-
76-
// Seed Contacts
77-
if (mockData.contacts) {
78-
for (const contact of mockData.contacts) {
79-
await driver.create('contact', { ...contact, _id: contact.id });
80-
}
81-
}
82-
83-
// Seed Opportunities
84-
if (mockData.opportunities) {
85-
for (const opp of mockData.opportunities) {
86-
await driver.create('opportunity', { ...opp, _id: opp.id });
69+
// @ts-ignore
70+
const manifest = crmConfig.manifest;
71+
if (manifest && manifest.data) {
72+
for (const dataSet of manifest.data) {
73+
console.log(`[MockServer] Seeding ${dataSet.object}...`);
74+
if (dataSet.records) {
75+
for (const record of dataSet.records) {
76+
await driver.create(dataSet.object, record);
77+
}
8778
}
8879
}
89-
90-
// Seed Accounts
91-
const accounts = [
92-
{ id: '1', name: 'Acme Corp', industry: 'Technology' },
93-
{ id: '2', name: 'TechStart Inc', industry: 'Startup' },
94-
{ id: '3', name: 'Global Solutions', industry: 'Consulting' }
95-
];
96-
97-
for (const acc of accounts) {
98-
await driver.create('account', { ...acc, _id: acc.id });
99-
}
100-
101-
console.log('[MockServer] Data seeded successfully');
102-
} catch (err) {
103-
console.error('[MockServer] Seeding failed:', err);
10480
}
10581
}
82+

examples/crm-app/src/objectstack.config.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

examples/crm/objectstack.config.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { defineStack } from '@objectstack/spec';
2+
import { App } from '@objectstack/spec/ui';
3+
import { AccountObject } from './src/objects/account.object';
4+
import { ContactObject } from './src/objects/contact.object';
5+
import { OpportunityObject } from './src/objects/opportunity.object';
6+
7+
export default defineStack({
8+
objects: [
9+
AccountObject,
10+
ContactObject,
11+
OpportunityObject
12+
],
13+
apps: [
14+
App.create({
15+
name: 'crm_app',
16+
label: 'CRM',
17+
icon: 'users',
18+
navigation: [
19+
{
20+
id: 'nav_contacts',
21+
type: 'object',
22+
objectName: 'contact',
23+
label: 'Contacts'
24+
},
25+
{
26+
id: 'nav_opportunities',
27+
type: 'object',
28+
objectName: 'opportunity',
29+
label: 'Opportunities'
30+
}
31+
]
32+
})
33+
],
34+
manifest: {
35+
id: 'com.example.crm',
36+
version: '1.0.0',
37+
type: 'app',
38+
name: 'CRM Example',
39+
description: 'CRM App Definition',
40+
data: [
41+
{
42+
object: 'contact',
43+
mode: 'upsert', // upsert based on ID (which is usually _id or id)
44+
records: [
45+
{ _id: "1", name: "Alice Johnson", email: "alice@example.com", phone: "555-0101", title: "VP Sales", company: "TechCorp", status: "Active" },
46+
{ _id: "2", name: "Bob Smith", email: "bob@tech.com", phone: "555-0102", title: "Developer", company: "Software Inc", status: "Lead" },
47+
{ _id: "3", name: "Charlie Brown", email: "charlie@peanuts.com", phone: "555-0103", title: "Manager", company: "Good Grief LLC", status: "Customer" }
48+
]
49+
},
50+
{
51+
object: 'opportunity',
52+
mode: 'upsert',
53+
records: [
54+
{
55+
_id: "101",
56+
name: "TechCorp Enterprise License",
57+
amount: 50000,
58+
stage: "Proposal",
59+
closeDate: new Date("2024-06-30"),
60+
accountId: "1", // This would ideally link to an account record
61+
contactIds: ["1", "2"], // Corrected IDs
62+
description: "Enterprise software license for 500 users. Includes premium support and training."
63+
},
64+
{
65+
_id: "102",
66+
name: "Software Inc Pilot",
67+
amount: 5000,
68+
stage: "Closed Won",
69+
closeDate: new Date("2024-01-15"),
70+
accountId: "2",
71+
contactIds: ["2"],
72+
description: "Pilot program for 50 users."
73+
},
74+
{
75+
_id: "103",
76+
name: "Good Grief Consultant",
77+
amount: 12000,
78+
stage: "Negotiation",
79+
closeDate: new Date("2024-05-20"),
80+
accountId: "3",
81+
contactIds: ["3"],
82+
description: "Consulting services for Q2 implementation."
83+
}
84+
]
85+
}
86+
]
87+
}
88+
});

examples/crm/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@object-ui/example-crm",
3+
"version": "0.1.0",
4+
"description": "CRM Metadata Example using ObjectStack Protocol",
5+
"private": true,
6+
"main": "dist/objectstack.json",
7+
"types": "src/index.ts",
8+
"exports": {
9+
".": "./src/index.ts",
10+
"./objectstack.config": "./objectstack.config.ts"
11+
},
12+
"scripts": {
13+
"build": "objectstack compile objectstack.config.ts dist/objectstack.json"
14+
},
15+
"dependencies": {
16+
"@objectstack/spec": "^0.6.1"
17+
},
18+
"devDependencies": {
19+
"typescript": "^5.0.0",
20+
"@objectstack/cli": "^0.6.1"
21+
}
22+
}

examples/crm/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './objects/account.object';
2+
export * from './objects/contact.object';
3+
export * from './objects/opportunity.object';
4+
export { default as config } from '../objectstack.config';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ObjectSchema, Field } from '@objectstack/spec/data';
2+
3+
export const AccountObject = ObjectSchema.create({
4+
name: 'account',
5+
label: 'Account',
6+
fields: {
7+
name: Field.text({ label: 'Account Name', required: true }),
8+
industry: Field.text({ label: 'Industry' })
9+
}
10+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ObjectSchema, Field } from '@objectstack/spec/data';
2+
3+
export const ContactObject = ObjectSchema.create({
4+
name: 'contact',
5+
label: 'Contact',
6+
fields: {
7+
name: Field.text({ label: 'Name', required: true }),
8+
email: Field.email({ label: 'Email' }),
9+
phone: Field.text({ label: 'Phone' }),
10+
title: Field.text({ label: 'Title' }),
11+
company: Field.text({ label: 'Company' }),
12+
status: Field.select(['Active', 'Lead', 'Customer'], { label: 'Status' })
13+
}
14+
});

0 commit comments

Comments
 (0)