Skip to content

Add @neaps/api HTTP JSON API package#192

Merged
bkeepers merged 22 commits into
mainfrom
copilot-worktree-2026-01-20T12-42-16
Feb 2, 2026
Merged

Add @neaps/api HTTP JSON API package#192
bkeepers merged 22 commits into
mainfrom
copilot-worktree-2026-01-20T12-42-16

Conversation

@bkeepers
Copy link
Copy Markdown
Contributor

Summary

This PR adds a new @neaps/api package that provides a REST API for tide predictions with OpenAPI specification.

Key Features

  • Express-based HTTP API with 6 REST endpoints
  • OpenAPI 3.0 specification for easy integration
  • Comprehensive test coverage (34 tests, 93% coverage)
  • Node-optimized build (ESM-only, target Node 18+)
  • Full coordinate format support (lat/latitude, lon/lng/longitude)
  • Subordinate station handling with appropriate error messages

API Endpoints

  • GET /extremes - Get high/low tide predictions for a location
  • GET /timeline - Get water level predictions at intervals
  • GET /stations - Find stations by ID or near coordinates
  • GET /stations/:id/extremes - Get extremes for a specific station
  • GET /stations/:id/timeline - Get timeline for a specific station
  • GET /openapi.json - OpenAPI 3.0 specification

Usage

import { startServer } from '@neaps/api';

// Start standalone server
startServer(3000);

// Or use as Express middleware
import { createApp } from '@neaps/api';
import express from 'express';

const app = express();
app.use('/api', createApp());
app.listen(3000);

Package Structure

  • src/index.ts - Main Express app with middleware
  • src/routes/index.ts - Route handlers for all endpoints
  • src/openapi.json - OpenAPI 3.0 specification
  • test/index.test.ts - Comprehensive test suite
  • tsdown.config.js - Node-optimized build configuration

Testing

All tests pass with 93% code coverage:

  • ✅ 34 tests across all endpoints
  • ✅ Parameter validation tests
  • ✅ Station resolution tests (reference and subordinate)
  • ✅ Error handling tests
  • ✅ OpenAPI spec validation

Documentation

  • Added comprehensive README for @neaps/api package
  • Updated root README with API usage examples
  • All code passes linting and formatting checks

Build Configuration

Uses Node-optimized tsdown config:

  • ESM-only output (no CJS)
  • Target: Node 18+
  • Platform: node
  • Smaller, faster builds for server environments

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (84732a2) to head (6c47e33).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #192   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           65        67    +2     
  Lines          531       581   +50     
  Branches        58        71   +13     
=========================================
+ Hits           531       581   +50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Adds a new @neaps/api workspace package that exposes the neaps tide prediction functionality over an Express-based HTTP JSON REST API, including an OpenAPI 3.0 spec and endpoint-level tests.

Changes:

  • Introduces @neaps/api package with Express router, OpenAPI spec, and ESM build configuration.
  • Adds a comprehensive Vitest + Supertest suite covering the API endpoints and error cases.
  • Updates the monorepo root README and workspaces list to include/document the new package.

Reviewed changes

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

Show a summary per file
File Description
packages/api/vitest.config.ts Adds Vitest config for the new API package.
packages/api/tsdown.config.js Adds tsdown build config targeting Node 18+ ESM output.
packages/api/tsconfig.json Adds package-local TS config (typecheck-oriented).
packages/api/test/index.test.ts Adds Supertest-driven endpoint tests.
packages/api/src/routes.ts Implements Express routes + OpenAPI request/response validation + error middleware.
packages/api/src/openapi.ts Defines the OpenAPI 3.0 document served/used for validation.
packages/api/src/index.ts Exposes createApp and exports for router/spec.
packages/api/package.json Defines new workspace package metadata, build scripts, and dependencies.
packages/api/README.md Adds package-level usage and endpoint documentation.
package.json Updates workspace list to include packages/api.
README.md Documents @neaps/api usage and endpoints at the repo root.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/api/test/index.test.ts
Comment thread packages/api/src/index.ts
Comment thread packages/api/src/routes.ts Outdated
Comment thread packages/api/src/openapi.ts
Comment thread packages/api/package.json Outdated
Comment thread packages/api/src/routes.ts Outdated
Comment thread packages/api/src/routes.ts Outdated
Comment thread packages/api/src/routes.ts
Comment thread packages/api/test/index.test.ts Outdated
Comment thread packages/api/test/index.test.ts
Copy link
Copy Markdown

Copilot AI commented Jan 27, 2026

@bkeepers I've opened a new pull request, #194, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Jan 27, 2026

@bkeepers I've opened a new pull request, #195, to work on those changes. Once the pull request is ready, I'll request review from you.

@bkeepers bkeepers force-pushed the copilot-worktree-2026-01-20T12-42-16 branch 2 times, most recently from c25e81c to d1d24a8 Compare January 28, 2026 11:14
- Create new Express-based HTTP API package exposing tide prediction functionality
- Implement REST endpoints for extremes, timeline, and station queries
- Add comprehensive OpenAPI 3.0 specification
- Support all GeolibInputCoordinates variations (lat/latitude, lon/lng/longitude)
- Handle both reference and subordinate stations appropriately
- Include 34 comprehensive tests with 93% code coverage
- Configure Node-optimized tsdown build (ESM-only, target node18)
- Update root README with API documentation and usage examples
- Remove startServer function in favor of calling .listen() directly on the Express app
- Update all documentation to show the .listen() pattern
- Add comprehensive error handling tests
- Add tests for NaN coordinate validation across all endpoints
- Achieve 99.05% test coverage (39 tests, all passing)
- Simplify API usage patterns in README examples
- Add NextFunction parameter to error handler (required by Express)
- Add comprehensive error validation tests for NaN coordinates
- Achieve 97.16% coverage for API package (99.29% overall)
- 37 tests passing
- Remaining uncovered lines are edge cases (error fallback message)
@bkeepers bkeepers force-pushed the copilot-worktree-2026-01-20T12-42-16 branch from 17e3cc4 to a5cd7e5 Compare February 1, 2026 21:32
@bkeepers bkeepers merged commit abd154d into main Feb 2, 2026
6 checks passed
@bkeepers bkeepers deleted the copilot-worktree-2026-01-20T12-42-16 branch February 2, 2026 13:28
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