Skip to content

Commit 8694d3e

Browse files
Copilothuangyiirene
andcommitted
feat: Create @objectql/types v4.0.0 with plugin interfaces
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 1857b5a commit 8694d3e

14 files changed

Lines changed: 896 additions & 0 deletions

packages/core/types/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
*.tsbuildinfo
4+
coverage
5+
.DS_Store

packages/core/types/CHANGELOG.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# @objectql/types v4.0.0
2+
3+
## [4.0.0] - 2026-01-21
4+
5+
### Breaking Changes
6+
7+
- Complete rewrite of type system for plugin-based architecture
8+
- Removed types now in @objectstack/spec:
9+
- `Driver` interface (use `DriverInterface` from @objectstack/spec)
10+
- Removed types now in @objectstack/runtime:
11+
- `MetadataRegistry` class
12+
- `Context` types
13+
- `Hook` types
14+
- `Action` types
15+
16+
### Added
17+
18+
- New plugin interfaces:
19+
- `QueryProcessorPlugin` - For query validation, optimization, and transformation
20+
- `RepositoryPlugin` - For extending repository with batch operations, audit tracking
21+
- `BasePlugin` - Base interface for all plugins
22+
- Query-specific types:
23+
- `UnifiedQuery` - Core query structure
24+
- `FilterExpression` - Type-safe filter expressions
25+
- `QueryResult` - Query result wrapper with pagination
26+
- `QueryOptions` - Query execution options
27+
- Runtime types:
28+
- `RuntimeContext` - Context available to plugins during execution
29+
- `ValidationResult` - Query validation result
30+
- `ValidationError` - Validation error details
31+
32+
### Dependencies
33+
34+
- Added `@objectstack/spec` ^0.2.0
35+
- Added `@objectstack/runtime` ^0.2.0
36+
37+
### Migration Guide
38+
39+
If you were using types that are now removed:
40+
41+
```typescript
42+
// Old (v3.x)
43+
import { Driver, MetadataRegistry, Hook } from '@objectql/types';
44+
45+
// New (v4.x)
46+
import { DriverInterface } from '@objectstack/spec';
47+
// MetadataRegistry, Hook, Action are now part of @objectstack/runtime
48+
```
49+
50+
For plugin development:
51+
52+
```typescript
53+
// New in v4.x
54+
import { QueryProcessorPlugin, RepositoryPlugin } from '@objectql/types';
55+
56+
export function myPlugin(): QueryProcessorPlugin {
57+
return {
58+
name: '@myorg/plugin',
59+
version: '1.0.0',
60+
type: 'query-processor',
61+
async beforeQuery(ast, context) {
62+
// Transform query
63+
return ast;
64+
}
65+
};
66+
}
67+
```

packages/core/types/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# @objectql/types
2+
3+
Type definitions and plugin interfaces for ObjectQL v4.0.
4+
5+
## Overview
6+
7+
This package provides the core TypeScript type definitions for ObjectQL's plugin architecture. It includes:
8+
9+
- **Plugin Interfaces**: Define custom query plugins, repository extensions, and query processors
10+
- **Query Types**: Type-safe query construction and manipulation
11+
- **Helper Types**: Utility types for working with ObjectQL queries
12+
13+
## Key Principles
14+
15+
1. **Zero Dependencies on Internal Packages**: This package depends only on `@objectstack/spec` and `@objectstack/runtime`
16+
2. **Protocol-Driven**: Types define the contract, implementation follows
17+
3. **Strict Type Safety**: All types use TypeScript strict mode
18+
19+
## Installation
20+
21+
```bash
22+
npm install @objectql/types
23+
```
24+
25+
## Usage
26+
27+
```typescript
28+
import { QueryPlugin, RepositoryPlugin, UnifiedQuery } from '@objectql/types';
29+
30+
// Define a custom query plugin
31+
export function myQueryPlugin(): QueryPlugin {
32+
return {
33+
name: '@myorg/query-plugin',
34+
version: '1.0.0',
35+
type: 'query-processor',
36+
async beforeQuery(ast, context) {
37+
// Transform query before execution
38+
return ast;
39+
}
40+
};
41+
}
42+
```
43+
44+
## Migration from v3.x
45+
46+
In v4.0, ObjectQL has transitioned to a plugin-based architecture built on `@objectstack/runtime`:
47+
48+
- **Driver Interface**: Now uses `DriverInterface` from `@objectstack/spec`
49+
- **Metadata & Context**: Now managed by `@objectstack/runtime`
50+
- **Hooks & Actions**: Now part of `@objectstack/runtime`
51+
52+
This package focuses exclusively on query-specific types and plugin interfaces.
53+
54+
## License
55+
56+
MIT © ObjectStack Inc.

packages/core/types/jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['**/__tests__/**/*.test.ts'],
5+
collectCoverageFrom: [
6+
'src/**/*.ts',
7+
'!src/**/*.d.ts',
8+
],
9+
};

packages/core/types/package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/types/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@objectql/types",
3+
"version": "4.0.0",
4+
"description": "Type definitions and plugin interfaces for ObjectQL - Query-specific types and plugin architecture",
5+
"keywords": [
6+
"objectql",
7+
"types",
8+
"typescript",
9+
"interfaces",
10+
"plugin",
11+
"query",
12+
"ai-native"
13+
],
14+
"license": "MIT",
15+
"main": "dist/index.js",
16+
"types": "dist/index.d.ts",
17+
"files": [
18+
"dist"
19+
],
20+
"scripts": {
21+
"build": "tsc",
22+
"test": "jest --passWithNoTests"
23+
},
24+
"dependencies": {
25+
"@objectstack/spec": "^0.2.0",
26+
"@objectstack/runtime": "^0.2.0"
27+
}
28+
}

packages/core/types/src/index.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* ObjectQL
3+
* Copyright (c) 2026-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* @objectql/types - Type definitions for ObjectQL v4.0
11+
*
12+
* This package provides the core TypeScript type definitions for ObjectQL's
13+
* plugin-based architecture. It includes:
14+
*
15+
* - Plugin interfaces (QueryProcessorPlugin, RepositoryPlugin)
16+
* - Query types (UnifiedQuery, FilterExpression)
17+
* - Runtime context and options
18+
*
19+
* Key principles:
20+
* - Zero dependencies on other @objectql packages
21+
* - Depends only on @objectstack/spec and @objectstack/runtime
22+
* - Strict type safety
23+
* - Protocol-driven design
24+
*/
25+
26+
// ============================================================================
27+
// Plugin System
28+
// ============================================================================
29+
30+
export * from './plugin';
31+
export * from './query-processor';
32+
export * from './repository';
33+
34+
// ============================================================================
35+
// Query System
36+
// ============================================================================
37+
38+
export * from './query';
39+
40+
// ============================================================================
41+
// Re-exports from @objectstack packages
42+
// ============================================================================
43+
44+
/**
45+
* Re-export commonly used types from @objectstack/spec
46+
* This provides a convenient import path for ObjectQL users.
47+
*/
48+
export type {
49+
DriverInterface,
50+
// Add other spec types as needed
51+
} from '@objectstack/spec';
52+
53+
/**
54+
* Re-export commonly used types from @objectstack/runtime
55+
* This provides a convenient import path for ObjectQL users.
56+
*/
57+
export type {
58+
// RuntimePlugin,
59+
// Runtime,
60+
// Add other runtime types as needed
61+
} from '@objectstack/runtime';

packages/core/types/src/plugin.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* ObjectQL
3+
* Copyright (c) 2026-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* Base plugin metadata required by all ObjectQL plugins.
11+
*
12+
* This extends the RuntimePlugin from @objectstack/runtime with
13+
* ObjectQL-specific plugin types.
14+
*/
15+
export interface PluginMetadata {
16+
/** Unique plugin identifier (e.g., '@objectql/query-validation') */
17+
name: string;
18+
19+
/** Semantic version (e.g., '4.0.0') */
20+
version: string;
21+
22+
/** Plugin type discriminator */
23+
type: PluginType;
24+
25+
/** Required plugin dependencies */
26+
dependencies?: string[];
27+
28+
/** Optional plugin dependencies that enhance functionality */
29+
optionalDependencies?: string[];
30+
31+
/** Plugins that conflict with this one */
32+
conflicts?: string[];
33+
}
34+
35+
/**
36+
* Supported ObjectQL plugin types.
37+
*/
38+
export type PluginType =
39+
| 'driver'
40+
| 'query-processor'
41+
| 'repository'
42+
| 'feature'
43+
| 'custom';
44+
45+
/**
46+
* Plugin lifecycle methods.
47+
*/
48+
export interface PluginLifecycle {
49+
/**
50+
* Called when the plugin is registered with the runtime.
51+
* Use this to initialize resources, register handlers, etc.
52+
*/
53+
setup?(runtime: any): Promise<void>;
54+
55+
/**
56+
* Called when the runtime is shutting down.
57+
* Use this to cleanup resources, close connections, etc.
58+
*/
59+
teardown?(runtime: any): Promise<void>;
60+
}
61+
62+
/**
63+
* Base plugin interface that all ObjectQL plugins must implement.
64+
*
65+
* This is a minimal interface that can be extended by specific plugin types.
66+
*/
67+
export interface BasePlugin extends PluginMetadata, PluginLifecycle {}

0 commit comments

Comments
 (0)