Skip to content

Commit 260aa68

Browse files
Copilothotlong
andcommitted
Fix: Extend Driver interface to be compatible with DriverInterface from @objectstack/spec
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d8a8c99 commit 260aa68

5 files changed

Lines changed: 46 additions & 18 deletions

File tree

packages/foundation/core/src/app.ts

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

99
import {
1010
MetadataRegistry,
11+
Driver,
1112
ObjectConfig,
1213
ObjectQLContext,
1314
ObjectQLContextOptions,
@@ -28,13 +29,12 @@ import { registerHookHelper, triggerHookHelper, HookEntry } from './hook';
2829
import { registerObjectHelper, getConfigsHelper } from './object';
2930
import { convertIntrospectedSchemaToObjects } from './util';
3031

31-
// Import ObjectStack engine and standard driver interface
32+
// Import ObjectStack engine for driver management
3233
import { ObjectQL as ObjectStackEngine } from '@objectstack/objectql';
33-
import { DriverInterface } from '@objectstack/spec';
3434

3535
export class ObjectQL implements IObjectQL {
3636
public metadata: MetadataRegistry;
37-
private datasources: Record<string, DriverInterface> = {};
37+
private datasources: Record<string, Driver> = {};
3838
private remotes: string[] = [];
3939
private hooks: Record<string, HookEntry[]> = {};
4040
private actions: Record<string, ActionEntry> = {};
@@ -54,9 +54,9 @@ export class ObjectQL implements IObjectQL {
5454
// Initialize ObjectStack engine for driver management
5555
this.stackEngine = new ObjectStackEngine({});
5656

57-
// Register drivers with ObjectStack engine (no wrapping needed)
57+
// Register drivers with ObjectStack engine
5858
for (const [name, driver] of Object.entries(this.datasources)) {
59-
this.stackEngine.registerDriver(driver, name === 'default');
59+
this.stackEngine.registerDriver(driver as any, name === 'default');
6060
}
6161
}
6262

@@ -90,12 +90,12 @@ export class ObjectQL implements IObjectQL {
9090
/**
9191
* Register a new driver with ObjectStack engine
9292
*/
93-
registerDriver(name: string, driver: DriverInterface, isDefault: boolean = false) {
93+
registerDriver(name: string, driver: Driver, isDefault: boolean = false) {
9494
if (this.datasources[name]) {
9595
console.warn(`[ObjectQL] Driver '${name}' already exists. Overwriting...`);
9696
}
9797
this.datasources[name] = driver;
98-
this.stackEngine.registerDriver(driver, isDefault);
98+
this.stackEngine.registerDriver(driver as any, isDefault);
9999
}
100100

101101
removePackage(name: string) {
@@ -190,7 +190,7 @@ export class ObjectQL implements IObjectQL {
190190
return getConfigsHelper(this.metadata);
191191
}
192192

193-
datasource(name: string): DriverInterface {
193+
datasource(name: string): Driver {
194194
const driver = this.datasources[name];
195195
if (!driver) {
196196
throw new Error(`Datasource '${name}' not found`);

packages/foundation/core/src/repository.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import { ObjectQLContext, IObjectQL, ObjectConfig, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext } from '@objectql/types';
10-
import { DriverInterface } from '@objectstack/spec';
9+
import { ObjectQLContext, IObjectQL, ObjectConfig, Driver, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext } from '@objectql/types';
1110
import { Validator } from './validator';
1211
import { FormulaEngine } from './formula-engine';
1312

@@ -24,7 +23,7 @@ export class ObjectRepository {
2423
this.formulaEngine = new FormulaEngine();
2524
}
2625

27-
private getDriver(): DriverInterface {
26+
private getDriver(): Driver {
2827
const obj = this.getSchema();
2928
const datasourceName = obj.datasource || 'default';
3029
return this.app.datasource(datasourceName);

packages/foundation/types/src/app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
*/
88

99
import { ObjectConfig } from "./object";
10+
import { Driver } from "./driver";
1011
import { MetadataRegistry } from "./registry";
1112
import { HookName, HookHandler, HookContext } from "./hook";
1213
import { ActionHandler, ActionContext } from "./action";
1314
import { LoaderPlugin } from "./loader";
14-
// Import DriverInterface from @objectstack/spec
15-
import type { DriverInterface } from "@objectstack/spec";
1615

1716
export interface IObjectQL {
1817
getObject(name: string): ObjectConfig | undefined;
1918
getConfigs(): Record<string, ObjectConfig>;
20-
datasource(name: string): DriverInterface;
19+
datasource(name: string): Driver;
2120
init(): Promise<void>;
2221
close?(): Promise<void>;
2322
removePackage(name: string): void;

packages/foundation/types/src/config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
*/
88

99
import { MetadataRegistry } from "./registry";
10+
import { Driver } from "./driver";
1011
import { ObjectConfig } from "./object";
1112
import { ObjectQLPlugin } from "./plugin";
12-
// Import DriverInterface from @objectstack/spec
13-
import type { DriverInterface } from "@objectstack/spec";
1413

1514
export interface ObjectQLConfig {
1615
registry?: MetadataRegistry;
17-
datasources?: Record<string, DriverInterface>;
16+
datasources?: Record<string, Driver>;
1817
/**
1918
* Optional connection string for auto-configuration.
2019
* e.g. "sqlite://dev.db", "postgres://localhost/db", "mongodb://localhost/db"

packages/foundation/types/src/driver.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,45 @@ export interface IntrospectedSchema {
6363
}
6464

6565
export interface Driver {
66+
// Required for DriverInterface compatibility
67+
name?: string;
68+
version?: string;
69+
supports?: {
70+
transactions?: boolean;
71+
joins?: boolean;
72+
fullTextSearch?: boolean;
73+
jsonFields?: boolean;
74+
arrayFields?: boolean;
75+
};
76+
77+
// Core CRUD methods (existing)
6678
find(objectName: string, query: any, options?: any): Promise<any[]>;
6779
findOne(objectName: string, id: string | number, query?: any, options?: any): Promise<any>;
6880
create(objectName: string, data: any, options?: any): Promise<any>;
6981
update(objectName: string, id: string | number, data: any, options?: any): Promise<any>;
7082
delete(objectName: string, id: string | number, options?: any): Promise<any>;
7183
count(objectName: string, filters: any, options?: any): Promise<number>;
7284

73-
// Schema / Lifecycle
85+
// Lifecycle methods
86+
connect?(): Promise<void>;
87+
disconnect?(): Promise<void>;
88+
checkHealth?(): Promise<boolean>;
89+
90+
// Additional methods for DriverInterface compatibility
91+
execute?(command: any, parameters?: any[], options?: any): Promise<any>;
92+
findOne?(objectName: string, id: string | number, query?: any, options?: any): Promise<any>;
93+
bulkCreate?(objectName: string, data: any[], options?: any): Promise<any>;
94+
bulkUpdate?(objectName: string, updates: Array<{id: string | number, data: any}>, options?: any): Promise<any>;
95+
bulkDelete?(objectName: string, ids: Array<string | number>, options?: any): Promise<any>;
96+
distinct?(objectName: string, field: string, filters?: any, options?: any): Promise<any[]>;
97+
aggregate?(objectName: string, aggregations: any[], filters?: any, options?: any): Promise<any[]>;
98+
99+
// Transaction support
100+
beginTransaction?(): Promise<any>;
101+
commitTransaction?(transaction: any): Promise<void>;
102+
rollbackTransaction?(transaction: any): Promise<void>;
103+
104+
// Schema / Lifecycle (existing)
74105
init?(objects: any[]): Promise<void>;
75106

76107
/**

0 commit comments

Comments
 (0)