-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Adjust objectql to integrate with dataengine plugin #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec8fd1a
7992974
a59cd2e
bc82cda
a2199cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| title: Data Engine | ||
| description: Data Engine protocol schemas | ||
| --- | ||
|
|
||
| # Data Engine | ||
|
|
||
| <Callout type="info"> | ||
| **Source:** `packages/spec/src/system/data-engine.zod.ts` | ||
| </Callout> | ||
|
|
||
| ## TypeScript Usage | ||
|
|
||
| ```typescript | ||
| import { DataEngineSchema, DataEngineFilterSchema, DataEngineQueryOptionsSchema } from '@objectstack/spec/system'; | ||
| import type { DataEngine, DataEngineFilter, DataEngineQueryOptions } from '@objectstack/spec/system'; | ||
|
|
||
| // Validate data | ||
| const result = DataEngineSchema.parse(data); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## DataEngine | ||
|
|
||
| Data Engine Interface | ||
|
|
||
| ### Properties | ||
|
|
||
| | Property | Type | Required | Description | | ||
| | :--- | :--- | :--- | :--- | | ||
|
|
||
| --- | ||
|
|
||
| ## DataEngineFilter | ||
|
|
||
| Data Engine query filter conditions | ||
|
|
||
| --- | ||
|
|
||
| ## DataEngineQueryOptions | ||
|
|
||
| Query options for IDataEngine.find() operations | ||
|
|
||
| ### Properties | ||
|
|
||
| | Property | Type | Required | Description | | ||
| | :--- | :--- | :--- | :--- | | ||
| | **filter** | `Record<string, any>` | optional | Data Engine query filter conditions | | ||
| | **select** | `string[]` | optional | | | ||
| | **sort** | `Record<string, Enum<'1' \| '-1' \| 'asc' \| 'desc'>>` | optional | | | ||
| | **limit** | `number` | optional | | | ||
| | **skip** | `number` | optional | | | ||
| | **top** | `number` | optional | | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| "pages": [ | ||
| "audit", | ||
| "context", | ||
| "data-engine", | ||
| "datasource", | ||
| "driver", | ||
| "events", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,122 +1,8 @@ | ||
| /** | ||
| * IDataEngine - Standard Data Engine Interface | ||
| * | ||
| * Abstract interface for data persistence capabilities. | ||
| * This allows plugins to interact with data engines without knowing | ||
| * the underlying implementation (SQL, MongoDB, Memory, etc.). | ||
| * | ||
| * Follows Dependency Inversion Principle - plugins depend on this interface, | ||
| * not on concrete database implementations. | ||
| */ | ||
|
|
||
| /** | ||
| * Query filter conditions | ||
| */ | ||
| export interface QueryFilter { | ||
| [field: string]: any; | ||
| } | ||
|
|
||
| /** | ||
| * Query options for find operations | ||
| * Re-exports the data engine interface from the spec package. | ||
| * This provides backward compatibility for imports from @objectstack/runtime. | ||
| */ | ||
| export interface QueryOptions { | ||
| /** Filter conditions */ | ||
| filter?: QueryFilter; | ||
| /** Fields to select */ | ||
| select?: string[]; | ||
| /** Sort order */ | ||
| sort?: Record<string, 1 | -1 | 'asc' | 'desc'>; | ||
| /** Limit number of results (alternative name for top, used by some drivers) */ | ||
| limit?: number; | ||
| /** Skip number of results (for pagination) */ | ||
| skip?: number; | ||
| /** Maximum number of results (OData-style, takes precedence over limit if both specified) */ | ||
| top?: number; | ||
| } | ||
|
|
||
| /** | ||
| * IDataEngine - Data persistence capability interface | ||
| * | ||
| * Defines the contract for data engine implementations. | ||
| * Concrete implementations (ObjectQL, Prisma, TypeORM) should implement this interface. | ||
| */ | ||
| export interface IDataEngine { | ||
| /** | ||
| * Insert a new record | ||
| * | ||
| * @param objectName - Name of the object/table (e.g., 'user', 'order') | ||
| * @param data - Data to insert | ||
| * @returns Promise resolving to the created record (including generated ID) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const user = await engine.insert('user', { | ||
| * name: 'John Doe', | ||
| * email: 'john@example.com' | ||
| * }); | ||
| * console.log(user.id); // Auto-generated ID | ||
| * ``` | ||
| */ | ||
| insert(objectName: string, data: any): Promise<any>; | ||
|
|
||
| /** | ||
| * Find records matching a query | ||
| * | ||
| * @param objectName - Name of the object/table | ||
| * @param query - Query conditions (optional) | ||
| * @returns Promise resolving to an array of matching records | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // Find all users | ||
| * const allUsers = await engine.find('user'); | ||
| * | ||
| * // Find with filter | ||
| * const activeUsers = await engine.find('user', { | ||
| * filter: { status: 'active' } | ||
| * }); | ||
| * | ||
| * // Find with limit and sort | ||
| * const recentUsers = await engine.find('user', { | ||
| * sort: { createdAt: -1 }, | ||
| * limit: 10 | ||
| * }); | ||
| * ``` | ||
| */ | ||
| find(objectName: string, query?: QueryOptions): Promise<any[]>; | ||
|
|
||
| /** | ||
| * Update a record by ID | ||
| * | ||
| * @param objectName - Name of the object/table | ||
| * @param id - Record ID | ||
| * @param data - Updated data (partial update) | ||
| * @returns Promise resolving to the updated record | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const updatedUser = await engine.update('user', '123', { | ||
| * name: 'Jane Doe', | ||
| * email: 'jane@example.com' | ||
| * }); | ||
| * ``` | ||
| */ | ||
| update(objectName: string, id: any, data: any): Promise<any>; | ||
|
|
||
| /** | ||
| * Delete a record by ID | ||
| * | ||
| * @param objectName - Name of the object/table | ||
| * @param id - Record ID | ||
| * @returns Promise resolving to true if deleted, false otherwise | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const deleted = await engine.delete('user', '123'); | ||
| * if (deleted) { | ||
| * console.log('User deleted successfully'); | ||
| * } | ||
| * ``` | ||
| */ | ||
| delete(objectName: string, id: any): Promise<boolean>; | ||
| } | ||
| export type { IDataEngine, DataEngineQueryOptions, DataEngineFilter } from '@objectstack/spec/system'; |
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ | ||||||||||||||||||||||||||||||||
| * and IDataEngine interfaces without depending on concrete implementations. | |||||||||||||||||||||||||||||||||
| */ | |||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||
| import { IHttpServer, IDataEngine, RouteHandler, IHttpRequest, IHttpResponse, Middleware, QueryOptions } from './index.js'; | |||||||||||||||||||||||||||||||||
| import { IHttpServer, IDataEngine, RouteHandler, IHttpRequest, IHttpResponse, Middleware, DataEngineQueryOptions } from './index.js'; | |||||||||||||||||||||||||||||||||
Check noticeCode scanning / CodeQL Unused variable, import, function or class Note test
Unused imports IHttpRequest, IHttpResponse.
Copilot AutofixAI about 8 hours ago To fix the problem, we should remove the unused imports Concretely, in import { IHttpServer, IDataEngine, RouteHandler, IHttpRequest, IHttpResponse, Middleware, DataEngineQueryOptions } from './index.js';with: import { IHttpServer, IDataEngine, RouteHandler, Middleware, DataEngineQueryOptions } from './index.js';No additional methods, imports, or definitions are needed. This is a minimal change that only removes unused imports and preserves all existing functionality.
Suggested changeset
1
packages/runtime/src/test-interfaces.ts
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||
| import { IHttpServer, IDataEngine, RouteHandler, IHttpRequest, IHttpResponse, Middleware, DataEngineQueryOptions } from './index.js'; | |
| import { IHttpServer, IDataEngine, RouteHandler, Middleware, DataEngineQueryOptions } from './index.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation references a type
DataEnginethat doesn't exist in the schema file. The schema file exportsDataEngineSchemabut doesn't export a corresponding type derived from it usingz.infer.Following the established pattern in other schema files (like driver.zod.ts which exports
export type DriverInterface = z.infer<typeof DriverInterfaceSchema>), you should add:after line 98 in the schema file. However, note that the manually defined
IDataEngineinterface (lines 102-107) serves the same purpose but with better type safety for optional parameters. Consider whether you need both or if the documentation should referenceIDataEngineinstead.