Skip to content

Refactor example files for reuse#7

Closed
bufferings wants to merge 1 commit intomainfrom
cursor/refactor-example-files-for-reuse-137e
Closed

Refactor example files for reuse#7
bufferings wants to merge 1 commit intomainfrom
cursor/refactor-example-files-for-reuse-137e

Conversation

@bufferings
Copy link
Copy Markdown
Owner

Refactor Kori example files to use configure functions for reusability and eliminate code duplication in index.ts.

…cation

Co-authored-by: bufferings+cursor <bufferings+cursor@gmail.com>
Copilot AI review requested due to automatic review settings June 30, 2025 16:41
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 PR refactors the Kori example files to remove duplicated route definitions by exporting configure functions from each example and mounting them in index.ts. Key changes include:

  • Main index.ts now imports and mounts each example via createChild({ prefix, configure }).
  • Individual example files (01–09) are converted from standalone apps to configure(app) functions.
  • Duplicate imports and manual route definitions are eliminated to improve maintainability.

Reviewed Changes

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

Show a summary per file
File Description
packages/kori-example/src/index.ts Mounted examples with createChild/configure.
packages/kori-example/src/05-plugin-system.ts Refactored plugin example into configure functions.
packages/kori-example/src/06-child-instances.ts Converted child-instances example to configure and updated type assertions.
packages/kori-example/src/04-lifecycle-hooks.ts Refactored lifecycle-hooks example to configure.
packages/kori-example/src/01-getting-started.ts Removed standalone app, added configure.
Comments suppressed due to low confidence (3)

packages/kori-example/src/05-plugin-system.ts:1

  • Missing imports for timingPlugin, createCorsPlugin, and createRateLimitPlugin which are applied later in configure. Add the appropriate import statements to avoid undefined references.
import { defineKoriPlugin, type Kori, type KoriEnvironment, type KoriRequest, type KoriResponse } from 'kori';

packages/kori-example/src/04-lifecycle-hooks.ts:1

  • The getMethodString import is no longer used in this file. Removing unused imports will keep the code clean.
import { getMethodString, type Kori, type KoriEnvironment, type KoriRequest, type KoriResponse } from 'kori';

packages/kori-example/src/01-getting-started.ts:8

  • The createKori import is no longer used after converting to configure. You can remove it (and any unused validator imports) to avoid dead code.
import { createKori, type Kori, type KoriEnvironment, type KoriRequest, type KoriResponse } from 'kori';

<a href="/errors/validation">GET /errors/validation</a>
<a href="/08-error-handling/error/basic">GET /error/basic</a><br>
<a href="/08-error-handling/error/custom">GET /error/custom</a><br>
<a href="/08-error-handling/safe/divide">GET /safe/divide</a>
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

The 'safe/divide' link points to /08-error-handling, but the graceful handler is mounted under /08-graceful-errors. Update the href or the mount prefix so that the route is reachable.

Suggested change
<a href="/08-error-handling/safe/divide">GET /safe/divide</a>
<a href="/08-graceful-errors/safe/divide">GET /safe/divide</a>

Copilot uses AI. Check for mistakes.
.get('/users', (ctx) =>
ctx.res.json({
apiVersion: ctx.req.apiVersion,
appVersion: (ctx.req as any).appVersion,
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The use of as any bypasses type safety for appVersion. Consider extending the KoriRequest type to include appVersion so you can access it without type assertions.

Suggested change
appVersion: (ctx.req as any).appVersion,
appVersion: ctx.req.appVersion,

Copilot uses AI. Check for mistakes.
@bufferings bufferings closed this Jul 1, 2025
@bufferings bufferings deleted the cursor/refactor-example-files-for-reuse-137e branch July 1, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants