Skip to content

Integrate plugin-hono-server with API Registry protocol#487

Merged
xuyushun441-sys merged 6 commits into
mainfrom
copilot/refactor-plugin-hono-server
Feb 2, 2026
Merged

Integrate plugin-hono-server with API Registry protocol#487
xuyushun441-sys merged 6 commits into
mainfrom
copilot/refactor-plugin-hono-server

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 2, 2026

Transform plugin-hono-server to use latest API protocol ✅

All Changes Completed Successfully! 🎉

  • Analyze current implementation and latest API protocol
  • Integrate with API Registry system for endpoint registration
  • Support REST server configuration from rest-server.zod.ts
  • Refactor route registration to use API Registry
  • Update to register endpoints dynamically from registry
  • Add support for plugin-registered custom endpoints
  • Maintain backward compatibility with legacy mode
  • Update tests to cover new functionality (9 test cases, all passing)
  • Update documentation with examples and usage patterns
  • Address code review feedback (extract constants, reduce duplication)
  • Fix HTTP 304 responses to comply with RFC spec (no message body)
  • Fix CodeQL warning: remove unused loop variable

Summary:

Successfully transformed the plugin-hono-server to use the latest API protocol while maintaining 100% backward compatibility. The plugin now supports:

API Registry Integration - Centralized endpoint management
REST Server Configuration - Following rest-server.zod.ts protocol
Dynamic Route Loading - Priority-based route binding from registry
Plugin Extensibility - Custom endpoint registration support
Legacy Fallback - Automatic compatibility mode when registry unavailable
Clean Code - Constants extracted, duplication reduced, HTTP spec compliant
Comprehensive Tests - 9/9 tests passing
Complete Documentation - README updated with examples and migration guide
CodeQL Clean - All static analysis warnings resolved

Code Quality:

  • Constants: DEFAULT_ENDPOINT_PRIORITY, CORE_ENDPOINT_PRIORITY, DISCOVERY_ENDPOINT_PRIORITY
  • Helper Methods: createCacheRequest() to reduce duplication
  • HTTP Compliance: 304 responses now return empty body per RFC 7232
  • Type Safety: Full TypeScript with Zod validation
  • No Breaking Changes: Existing deployments work without modifications
  • Static Analysis: CodeQL warnings resolved
Original prompt

按照最新的api协议,改造 plugin-hono-server


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 2, 2026

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

Project Deployment Actions Updated (UTC)
spec Canceled Canceled Feb 2, 2026 9:06am

Request Review

Copilot AI and others added 4 commits February 2, 2026 08:18
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor plugin-hono-server according to the latest API guidelines Integrate plugin-hono-server with API Registry protocol Feb 2, 2026
Copilot AI requested a review from hotlong February 2, 2026 08:26
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests and removed size/xl labels Feb 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

This PR is very large. Consider breaking it into smaller PRs for easier review.

Comment thread packages/plugins/plugin-hono-server/src/hono-plugin.ts Fixed
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { HonoServerPlugin } from './hono-plugin';
import { PluginContext } from '@objectstack/core';
import { PluginContext, ApiRegistry } from '@objectstack/core';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import ApiRegistry.

Copilot Autofix

AI 4 months ago

In general, unused imports should be removed to avoid confusion and keep the codebase clean. Here, only ApiRegistry is unused; PluginContext is still used for type casting, so we must preserve it while removing only the unused symbol.

The best minimal fix is to update the import statement on line 3 to remove ApiRegistry and keep PluginContext. No other lines need to change, and this will not modify any runtime behavior because ApiRegistry is not used. The edit is confined to packages/plugins/plugin-hono-server/src/hono-plugin.test.ts, in the import section at the top of the file.

No new methods, imports, or definitions are required; we are only simplifying an existing import.

Suggested changeset 1
packages/plugins/plugin-hono-server/src/hono-plugin.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/plugins/plugin-hono-server/src/hono-plugin.test.ts b/packages/plugins/plugin-hono-server/src/hono-plugin.test.ts
--- a/packages/plugins/plugin-hono-server/src/hono-plugin.test.ts
+++ b/packages/plugins/plugin-hono-server/src/hono-plugin.test.ts
@@ -1,6 +1,6 @@
 import { describe, it, expect, vi, beforeEach } from 'vitest';
 import { HonoServerPlugin } from './hono-plugin';
-import { PluginContext, ApiRegistry } from '@objectstack/core';
+import { PluginContext } from '@objectstack/core';
 
 describe('HonoServerPlugin', () => {
     let context: any;
EOF
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { HonoServerPlugin } from './hono-plugin';
import { PluginContext, ApiRegistry } from '@objectstack/core';
import { PluginContext } from '@objectstack/core';

describe('HonoServerPlugin', () => {
let context: any;
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -1,10 +1,30 @@
import { Plugin, PluginContext, IHttpServer } from '@objectstack/core';
import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused imports ApiRegistry, IHttpServer.

Copilot Autofix

AI 4 months ago

In general, to fix an unused import, you either remove the import entirely or, if the same import statement brings in multiple symbols, remove just the unused symbol while keeping the others. This improves readability and avoids misleading future maintainers into thinking the symbol is relevant here.

For this specific case, we should edit packages/plugins/plugin-hono-server/src/hono-plugin.ts and adjust the first import line so that it no longer imports IHttpServer. We will keep Plugin, PluginContext, and ApiRegistry unchanged. No new methods, imports, or definitions are required; this is a straightforward edit to the existing import list and does not alter functionality.

Concretely:

  • In packages/plugins/plugin-hono-server/src/hono-plugin.ts, on line 1, change
    import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';
    to
    import { Plugin, PluginContext, ApiRegistry } from '@objectstack/core';.

Suggested changeset 1
packages/plugins/plugin-hono-server/src/hono-plugin.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/plugins/plugin-hono-server/src/hono-plugin.ts b/packages/plugins/plugin-hono-server/src/hono-plugin.ts
--- a/packages/plugins/plugin-hono-server/src/hono-plugin.ts
+++ b/packages/plugins/plugin-hono-server/src/hono-plugin.ts
@@ -1,4 +1,4 @@
-import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';
+import { Plugin, PluginContext, ApiRegistry } from '@objectstack/core';
 import { ObjectStackProtocol } from '@objectstack/spec/api';
 import { 
     ApiRegistryEntryInput,
EOF
@@ -1,4 +1,4 @@
import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';
import { Plugin, PluginContext, ApiRegistry } from '@objectstack/core';
import { ObjectStackProtocol } from '@objectstack/spec/api';
import {
ApiRegistryEntryInput,
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread packages/plugins/plugin-hono-server/src/hono-plugin.ts Fixed
@hotlong
Copy link
Copy Markdown
Collaborator

hotlong commented Feb 2, 2026

@copilot packages/plugins/plugin-hono-server/src/hono-plugin.ts:566
);

    // Bind routes
    for (const { api: apiId, endpoint } of allEndpoints) {

Error
Unused loop iteration variable
For loop variable apiId is not used in the loop body.
CodeQL
this.bindEndpoint(endpoint, protocol, ctx);
}

Rule
Tool
CodeQL
Rule

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

Copilot AI commented Feb 2, 2026

@copilot packages/plugins/plugin-hono-server/src/hono-plugin.ts:566
);
...

Fixed in ee68632. Removed the unused apiId variable from the loop destructuring since it's not used in the loop body.

@hotlong hotlong marked this pull request as ready for review February 2, 2026 08:44
Copilot AI review requested due to automatic review settings February 2, 2026 08:44
@xuyushun441-sys xuyushun441-sys merged commit 080c48e into main Feb 2, 2026
13 of 14 checks passed
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

This pull request successfully integrates the plugin-hono-server with the API Registry protocol, enabling centralized endpoint management while maintaining full backward compatibility with existing deployments.

Changes:

  • Added API Registry integration for centralized endpoint registration and discovery
  • Implemented support for REST server configuration via RestServerConfig from the spec
  • Created a dual-mode system that automatically falls back to legacy route registration when API Registry is unavailable
  • Added comprehensive test coverage (9 test cases) covering both new API Registry mode and legacy fallback mode
  • Updated documentation with detailed examples and usage patterns for both modes

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/plugins/plugin-hono-server/src/hono-plugin.ts Core implementation: added API Registry integration, REST config support, dual-mode routing (registry vs legacy), extracted helper methods and constants, fixed HTTP 304 compliance
packages/plugins/plugin-hono-server/src/hono-plugin.test.ts Comprehensive test suite covering API Registry integration, configuration options, fallback behavior, and error handling
packages/plugins/plugin-hono-server/README.md Updated documentation with API Registry usage examples, configuration options, migration guide, and extensibility patterns

}
```

**Note:** The Hono Server Plugin loads routes from the API Registry sorted by priority (highest first), ensuring core endpoints take precedence over plugin endpoints.
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The note states "The Hono Server Plugin loads routes from the API Registry sorted by priority" but this is misleading. Based on the implementation in bindEndpoint() (hono-plugin.ts:586-589), the plugin only successfully binds routes for which it has handlers defined in createHandlerForEndpoint(). For custom plugin endpoints registered in the API Registry, bindEndpoint() will log a warning "No handler found for endpoint" and skip binding them.

Consider clarifying this note to explain that:

  1. HonoServerPlugin only auto-binds standard ObjectStack endpoints from the registry
  2. Custom plugins must bind their own handlers separately via the http-server service (as shown in the example above at lines 329-336)
  3. The API Registry serves primarily for endpoint discovery and documentation, not automatic handler binding for plugin endpoints

This would help developers understand that registering an endpoint in the API Registry does not automatically make it functional - they must also bind the handler implementation.

Suggested change
**Note:** The Hono Server Plugin loads routes from the API Registry sorted by priority (highest first), ensuring core endpoints take precedence over plugin endpoints.
**Note:** The Hono Server Plugin loads **only the standard ObjectStack endpoints it knows how to handle** from the API Registry, and processes them sorted by priority (highest first) so core endpoints take precedence. Custom plugin endpoints registered in the API Registry are **not** automatically bound; they must still bind their own handlers via the `http-server` service (as shown in the `start()` example above). For plugin-defined APIs, the API Registry primarily serves for endpoint discovery and documentation rather than automatic handler binding.

Copilot uses AI. Check for mistakes.
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { HonoServerPlugin } from './hono-plugin';
import { PluginContext } from '@objectstack/core';
import { PluginContext, ApiRegistry } from '@objectstack/core';
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Unused import ApiRegistry.

Suggested change
import { PluginContext, ApiRegistry } from '@objectstack/core';
import { PluginContext } from '@objectstack/core';

Copilot uses AI. Check for mistakes.
@@ -1,10 +1,30 @@
import { Plugin, PluginContext, IHttpServer } from '@objectstack/core';
import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Unused import IHttpServer.

Suggested change
import { Plugin, PluginContext, IHttpServer, ApiRegistry } from '@objectstack/core';
import { Plugin, PluginContext, ApiRegistry } from '@objectstack/core';

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

Labels

documentation Improvements or additions to documentation size/xl tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants