Skip to content

Refactor formula engine and validator into separate plugin packages#252

Merged
hotlong merged 19 commits into
mainfrom
copilot/discuss-splitting-plugins
Jan 30, 2026
Merged

Refactor formula engine and validator into separate plugin packages#252
hotlong merged 19 commits into
mainfrom
copilot/discuss-splitting-plugins

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 29, 2026

Extracted formula engine and validator from monolithic @objectql/core into dedicated plugins, improving modularity and bundle size with clean separation of concerns.

Changes

New Packages

  • @objectql/plugin-formula - FormulaEngine and FormulaPlugin (573 LOC, 109 tests)
  • @objectql/plugin-validator - Validator and ValidatorPlugin (744 LOC, 52 tests)

Core Package Updates

  • Added dependencies on new plugins (for internal use)
  • No re-exports - enforces explicit dependencies
  • Updated internal imports (repository.ts, ai-agent.ts, plugin.ts)
  • Removed 1,317 lines (moved to plugins)

Migration Path

Breaking Change: Applications must update imports to use dedicated packages:

// Before
import { FormulaEngine, Validator } from '@objectql/core';

// After
import { FormulaEngine } from '@objectql/plugin-formula';
import { Validator } from '@objectql/plugin-validator';

const kernel = new ObjectStackKernel([
  myApp,
  new FormulaPlugin({ enable_cache: false }),
  new ValidatorPlugin({ language: 'en' })
]);

Architecture

Before:

@objectql/core (monolithic)
├── Repository + Query
├── Formula Engine
└── Validator

After:

@objectql/plugin-formula (focused)
@objectql/plugin-validator (focused)
@objectql/core (lean, focused on core repository logic)

Follows existing pattern from @objectql/plugin-security. Enables tree-shaking and optional feature inclusion. Enforces clean architectural boundaries with explicit dependencies.

Testing

  • All 282 tests passing (no regressions)
  • CodeQL security scan: 0 alerts

Documentation

  • MIGRATION_GUIDE.md with migration instructions
  • Comprehensive READMEs for both plugins
  • PLUGIN_REFACTORING_SUMMARY.md with metrics
Original prompt

公式引擎和validator是否建议分拆为单独的插件软件包。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Jan 30, 2026 5:35am

Request Review

- Created @objectql/plugin-formula package with FormulaEngine and FormulaPlugin
- Created @objectql/plugin-validator package with Validator and ValidatorPlugin
- Updated @objectql/core to depend on and re-export from new plugins
- Moved all source files and tests to appropriate plugin packages
- Updated imports throughout the codebase
- All packages build successfully

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Copilot AI and others added 2 commits January 29, 2026 12:23
…ixes

- Fixed test imports and added mock-driver to plugin test directories
- Created comprehensive MIGRATION_GUIDE.md
- Fixed code formatting issues identified in review
- All 282 tests passing (109 formula, 52 validator, 121 core)
- CodeQL security scan passed with no alerts
- Backward compatibility maintained through core package re-exports

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Copilot AI changed the title [WIP] Evaluate splitting official engine and validator into separate plugins Refactor formula engine and validator into separate plugin packages Jan 29, 2026
Copilot AI requested a review from xuyushun441-sys January 29, 2026 12:28
@hotlong
Copy link
Copy Markdown
Contributor

hotlong commented Jan 29, 2026

不需要Re-exports components for backward compatibility @copilot

Per feedback, the @objectql/core package no longer re-exports components from
plugin-formula and plugin-validator. Users must now explicitly import from the
plugin packages they use, enforcing clean separation of concerns.

Breaking change: Applications must update imports:
- Before: import { FormulaEngine, Validator } from '@objectql/core';
- After: import { FormulaEngine } from '@objectql/plugin-formula';
         import { Validator } from '@objectql/plugin-validator';

Updated MIGRATION_GUIDE.md and PLUGIN_REFACTORING_SUMMARY.md to reflect
this change and remove references to backward compatibility.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 29, 2026

不需要Re-exports components for backward compatibility @copilot

Done. Removed backward compatibility re-exports from @objectql/core. Users must now explicitly import from @objectql/plugin-formula and @objectql/plugin-validator. This enforces clean separation of concerns.

Updated documentation (MIGRATION_GUIDE.md and PLUGIN_REFACTORING_SUMMARY.md) to reflect this breaking change.

All 282 tests still passing. Commit: 73822a4

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /usr/local/bin/node node ./postinstall.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 4 commits January 29, 2026 16:33
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Add plugin-validator and plugin-formula to root tsconfig references
- Update core package tsconfig to reference plugin packages
- Fix CLI import to use plugin-validator directly
- Add plugin-validator dependency to CLI package

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

Copilot AI and others added 6 commits January 29, 2026 17:16
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Revert core re-exports to avoid circular dependency
- Update test to import from @objectql/plugin-validator
- Add plugin-validator as devDependency to platform-node

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Remove validation.test.ts from platform-node (not its responsibility)
- Remove plugin-validator devDependency from platform-node
- Validation tests already exist in plugin-validator package (52 tests)

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Add comprehensive validation tests to plugin-validator (uniqueness, business rules, cross-field, state machine, triggers, severity)
- Remove validation.test.ts from platform-node (tests now in correct package)
- Platform-node tests pass (5 tests) - focused on platform responsibilities
- Plugin-validator now has 71 tests total (some failing due to incomplete implementation - to be fixed separately)

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

Comment on lines +10 to +19
import {
ValidationContext,
CrossFieldValidationRule,
StateMachineValidationRule,
UniquenessValidationRule,
BusinessRuleValidationRule,
CustomValidationRule,
FieldConfig,
AnyValidationRule,
} from '@objectql/types';
Copilot AI and others added 4 commits January 30, 2026 00:53
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

@hotlong hotlong marked this pull request as ready for review January 30, 2026 06:17
Copilot AI review requested due to automatic review settings January 30, 2026 06:17
@hotlong hotlong merged commit 789e00d into main Jan 30, 2026
4 checks passed
@hotlong hotlong deleted the copilot/discuss-splitting-plugins branch January 30, 2026 06:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors ObjectQL by extracting the formula engine and validation engine from @objectql/core into two dedicated plugin packages, improving modularity and enabling explicit, opt-in dependencies.

Changes:

  • Introduced @objectql/plugin-formula and @objectql/plugin-validator packages (engines + plugin wrappers + tests/docs).
  • Updated @objectql/core to depend on (but not re-export) the new plugins; updated internal imports accordingly.
  • Updated CLI and shared type definitions to reflect the new plugin-based architecture.

Reviewed changes

Copilot reviewed 30 out of 39 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tsconfig.json Adds TS project references for the new plugin packages.
packages/tools/cli/tsconfig.json Adds plugin-validator reference so CLI builds with the new dependency.
packages/tools/cli/src/commands/ai.ts Switches Validator import from core to @objectql/plugin-validator.
packages/tools/cli/package.json Adds @objectql/plugin-validator dependency.
packages/foundation/types/src/validation.ts Extends validation schema types (business-rule shorthand + cross-field shorthand).
packages/foundation/plugin-validator/tsconfig.json New TS config for validator plugin package.
packages/foundation/plugin-validator/test/validator.test.ts New validator engine tests in plugin package.
packages/foundation/plugin-validator/test/validator-plugin.test.ts New validator plugin wrapper tests.
packages/foundation/plugin-validator/test/validation-spec-compliance.test.ts Spec compliance coverage for validator behavior.
packages/foundation/plugin-validator/src/validator.ts Validator engine implementation moved into plugin package + enhancements.
packages/foundation/plugin-validator/src/validator-plugin.ts Validator plugin wrapper (kernel integration hooks).
packages/foundation/plugin-validator/src/index.ts Plugin package public exports.
packages/foundation/plugin-validator/package.json New plugin package manifest.
packages/foundation/plugin-validator/jest.config.js Jest config for plugin package tests.
packages/foundation/plugin-validator/README.md Plugin documentation and usage examples.
packages/foundation/plugin-formula/tsconfig.json New TS config for formula plugin package.
packages/foundation/plugin-formula/test/mock-driver.ts Test helper driver for formula integration tests.
packages/foundation/plugin-formula/test/formula-spec-compliance.test.ts Spec compliance tests for formula behavior.
packages/foundation/plugin-formula/test/formula-plugin.test.ts New formula plugin wrapper tests.
packages/foundation/plugin-formula/test/formula-integration.test.ts Updates integration test import to use @objectql/core.
packages/foundation/plugin-formula/test/formula-engine.test.ts Formula engine unit tests moved into plugin package.
packages/foundation/plugin-formula/src/index.ts Plugin package public exports.
packages/foundation/plugin-formula/src/formula-plugin.ts Formula plugin wrapper (kernel provider + hook registration).
packages/foundation/plugin-formula/src/formula-engine.ts Formula engine implementation moved into plugin package.
packages/foundation/plugin-formula/package.json New plugin package manifest.
packages/foundation/plugin-formula/jest.config.js Jest config for plugin package tests.
packages/foundation/plugin-formula/README.md Plugin documentation and usage examples.
packages/foundation/platform-node/test/validation.test.ts Removes platform-node validation tests migrated to plugin-validator.
packages/foundation/core/tsconfig.json Adds TS project references to the new plugin packages.
packages/foundation/core/test/validator.test.ts Removes core validator tests migrated to plugin-validator.
packages/foundation/core/test/plugin-integration.test.ts Updates integration tests to import/mocks from new plugin packages.
packages/foundation/core/src/repository.ts Switches internal imports to plugin-based Validator/FormulaEngine.
packages/foundation/core/src/plugin.ts Switches internal imports to plugin-based ValidatorPlugin/FormulaPlugin.
packages/foundation/core/src/index.ts Stops re-exporting validator/formula engines & plugins from core.
packages/foundation/core/src/ai-agent.ts Switches Validator import from core-local to plugin package.
packages/foundation/core/package.json Adds dependencies on @objectql/plugin-formula and @objectql/plugin-validator.
PLUGIN_REFACTORING_SUMMARY.md Adds refactor summary/metrics and migration overview.
MIGRATION_GUIDE.md Adds migration guide and new import paths/examples.
Comments suppressed due to low confidence (8)

packages/foundation/core/src/ai-agent.ts:24

  • Unused imports AnyValidationRule, ObjectConfig, ValidationContext, ValidationResult.
import { 
    ObjectConfig, 
    AnyValidationRule, 
    ValidationContext,
    ValidationResult 
} from '@objectql/types';

packages/foundation/core/src/repository.ts:9

  • Unused import Filter.
import { ObjectQLContext, IObjectQL, ObjectConfig, Driver, UnifiedQuery, ActionContext, HookAPI, RetrievalHookContext, MutationHookContext, UpdateHookContext, ValidationContext, ValidationError, ValidationRuleResult, FormulaContext, Filter } from '@objectql/types';

packages/foundation/core/src/repository.ts:457

  • Unused variable driver.
        const driver = this.getDriver();

packages/tools/cli/src/commands/ai.ts:395

  • Unused variable validator.
    packages/foundation/core/src/ai-agent.ts:258
  • The value assigned to parsedMetadata here is unused.
                parsedMetadata = yaml.load(options.metadata);

packages/foundation/core/src/ai-agent.ts:271

  • The value assigned to parsedMetadata here is unused.
            parsedMetadata = options.metadata;

packages/foundation/core/src/plugin.ts:97

  constructor(private config: ObjectQLPluginConfig = {}, ql?: any) {

packages/foundation/plugin-validator/src/validator.ts:637

  • This use of variable 'valid' always evaluates to true.

Comment on lines +223 to +227
/** Shorthand: Field to check (alternative to using rule property) */
field?: string;
/** Shorthand: Comparison operator (alternative to using rule property) */
operator?: ValidationOperator;
/** Shorthand: Value to compare against (mutually exclusive with compare_to) */
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new shorthand operator is typed as ValidationOperator, but the implementation now normalizes aliases like gte, lte, eq, etc. If those aliases are supported inputs (e.g., from YAML), the type should be widened to include them (or alias normalization removed) so TypeScript and runtime behavior stay consistent.

Copilot uses AI. Check for mistakes.
Comment thread MIGRATION_GUIDE.md
Comment on lines +161 to +169
2. Review the [API Documentation](../../docs/api/)
3. Open a new issue if needed

## Additional Resources

- [Formula Plugin README](../packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](../packages/foundation/plugin-validator/README.md)
- [API Documentation](../../docs/api/)
- [Examples](../../examples/)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These documentation links are broken as written. From the repository root, ../../docs/api/ points outside the repo, and the examples link ../../examples/ also points outside the repo. Update them to valid in-repo paths (or to the published docs site URLs if that’s the intent).

Suggested change
2. Review the [API Documentation](../../docs/api/)
3. Open a new issue if needed
## Additional Resources
- [Formula Plugin README](../packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](../packages/foundation/plugin-validator/README.md)
- [API Documentation](../../docs/api/)
- [Examples](../../examples/)
2. Review the [API Documentation](./api/)
3. Open a new issue if needed
## Additional Resources
- [Formula Plugin README](../packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](../packages/foundation/plugin-validator/README.md)
- [API Documentation](./api/)
- [Examples](../examples/)

Copilot uses AI. Check for mistakes.
Comment thread MIGRATION_GUIDE.md
Comment on lines +161 to +169
2. Review the [API Documentation](../../docs/api/)
3. Open a new issue if needed

## Additional Resources

- [Formula Plugin README](../packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](../packages/foundation/plugin-validator/README.md)
- [API Documentation](../../docs/api/)
- [Examples](../../examples/)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Additional Resources” links use ../packages/... from the repo root, which resolves outside the repo and will 404 on GitHub. These should be ./packages/... (or another correct relative path).

Suggested change
2. Review the [API Documentation](../../docs/api/)
3. Open a new issue if needed
## Additional Resources
- [Formula Plugin README](../packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](../packages/foundation/plugin-validator/README.md)
- [API Documentation](../../docs/api/)
- [Examples](../../examples/)
2. Review the [API Documentation](./docs/api/)
3. Open a new issue if needed
## Additional Resources
- [Formula Plugin README](./packages/foundation/plugin-formula/README.md)
- [Validator Plugin README](./packages/foundation/plugin-validator/README.md)
- [API Documentation](./docs/api/)
- [Examples](./examples/)

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +19
import {
ValidationContext,
CrossFieldValidationRule,
StateMachineValidationRule,
UniquenessValidationRule,
BusinessRuleValidationRule,
CustomValidationRule,
FieldConfig,
AnyValidationRule,
} from '@objectql/types';
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import AnyValidationRule.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants