Skip to content

Commit b4ad3fd

Browse files
committed
Revert "feat: enhance datasource registration and seeding logic in console plugin"
This reverts commit 49673fc.
1 parent 49673fc commit b4ad3fd

2 files changed

Lines changed: 1 addition & 89 deletions

File tree

apps/console/objectstack.config.ts

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const InMemoryDriver = DriverMemoryPkg.InMemoryDriver || (DriverMemoryPkg as any
2525
const DriverPlugin = RuntimePkg.DriverPlugin || (RuntimePkg as any).default?.DriverPlugin || (RuntimePkg as any).default;
2626
// const HonoServerPlugin = HonoServerPluginPkg.HonoServerPlugin || (HonoServerPluginPkg as any).default?.HonoServerPlugin || (HonoServerPluginPkg as any).default;
2727

28-
const memoryDriver = new InMemoryDriver();
29-
3028
import ConsolePluginConfig from './plugin.js';
3129

3230
const FixedConsolePlugin = {
@@ -35,75 +33,6 @@ const FixedConsolePlugin = {
3533
start: async (ctx: any) => {
3634
console.log('DEBUG: FixedConsolePlugin start called');
3735

38-
// Official way: Configure the 'default' datasource manually
39-
try {
40-
const metadataService = ctx.metadata || ctx.getService('metadata');
41-
if (metadataService && metadataService.addDatasource) {
42-
console.log('[Config] Registering default datasource (memory)...');
43-
await metadataService.addDatasource({
44-
name: 'default',
45-
driver: 'in-memory-driver', // Using the registered service name from logs
46-
});
47-
} else {
48-
console.warn('[Config] Metadata service not available for datasource registration');
49-
}
50-
} catch (e: any) {
51-
console.error('[Config] Failed to register default datasource:', e);
52-
}
53-
54-
// --- Data Seeding Logic ---
55-
try {
56-
console.log('[Seeder] Checking for initial data...');
57-
58-
// Resolve the active driver from the runtime context
59-
let activeDriver = null;
60-
61-
try {
62-
// Try getting the service that was explicitly logged as registered
63-
// "Service 'driver.in-memory-driver' registered"
64-
const serviceName = 'driver.in-memory-driver';
65-
const service = ctx.getService(serviceName);
66-
if (service && typeof service.create === 'function') {
67-
activeDriver = service;
68-
} else if (service && service.driver && typeof service.driver.create === 'function') {
69-
activeDriver = service.driver;
70-
}
71-
} catch (err: any) {
72-
console.log(`[Seeder] Driver retrieval error: ${err.message}`);
73-
}
74-
75-
if (!activeDriver) {
76-
console.log("[Seeder] Driver 'driver.in-memory-driver' not found or invalid.");
77-
console.log("[Seeder] Available Services:", ctx.getServiceNames ? ctx.getServiceNames() : 'Unknown');
78-
// Last resort fallback
79-
activeDriver = memoryDriver;
80-
} else {
81-
console.log("[Seeder] Successfully resolved active driver from Runtime.");
82-
}
83-
84-
const manifest = sharedConfig.manifest;
85-
if (manifest && Array.isArray(manifest.data)) {
86-
for (const dataset of manifest.data) {
87-
if (dataset.object && Array.isArray(dataset.records)) {
88-
console.log(`[Seeder] Seeding ${dataset.records.length} records for ${dataset.object}`);
89-
for (const record of dataset.records) {
90-
try {
91-
await activeDriver.create(dataset.object, record);
92-
} catch (err: any) {
93-
console.warn(`[Seeder] Failed to insert ${dataset.object} record:`, err.message);
94-
}
95-
}
96-
}
97-
}
98-
console.log('[Seeder] Data seeding complete.');
99-
} else {
100-
console.log('[Seeder] No initial data found in manifest.');
101-
}
102-
} catch (e: any) {
103-
console.error('[Seeder] Critical error during data seeding:', e);
104-
}
105-
// --------------------------
106-
10736
let app = null;
10837
const staticRoot = './dist';
10938

@@ -177,8 +106,7 @@ const FixedConsolePlugin = {
177106

178107
const plugins: any[] = [
179108
new ObjectQLPlugin(),
180-
// Driver registration
181-
new DriverPlugin(memoryDriver, 'in-memory-driver'),
109+
new DriverPlugin(new InMemoryDriver(), 'memory'),
182110
// new MSWPlugin(), // Disabled in production mode
183111
// HonoServerPlugin is auto-detected
184112
FixedConsolePlugin
@@ -199,13 +127,11 @@ export default defineConfig({
199127
target: 'node18',
200128
},
201129

202-
/*
203130
datasources: {
204131
default: {
205132
driver: 'memory',
206133
},
207134
},
208-
*/
209135

210136
plugins,
211137

apps/console/src/mocks/browser.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ObjectQLPlugin } from '@objectstack/objectql';
1010
import { InMemoryDriver } from '@objectstack/driver-memory';
1111
import { MSWPlugin } from '@objectstack/plugin-msw';
1212
import { setupWorker } from 'msw/browser';
13-
import { http, HttpResponse } from 'msw';
1413
import appConfig from '../../objectstack.shared';
1514

1615
let kernel: ObjectKernel | null = null;
@@ -75,19 +74,6 @@ export async function startMockServer() {
7574
// Manually start MSW worker with correct service worker path
7675
if (typeof window !== 'undefined') {
7776
const handlers = mswPlugin.getHandlers();
78-
79-
// Manual Fix: Add discovery endpoint handler to prevent 302/404 errors during initialization
80-
handlers.unshift(
81-
http.get('*/.well-known/objectstack', () => {
82-
return HttpResponse.json({
83-
name: "ObjectStack",
84-
version: "1.0.0",
85-
api_base: "/api/v1",
86-
status: "ok"
87-
});
88-
})
89-
);
90-
9177
const worker = setupWorker(...handlers);
9278

9379
// Check if we are served under a base path (e.g. /console/)

0 commit comments

Comments
 (0)