Skip to content

feat: implement core utility functions #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged

Conversation

nullcoder
Copy link
Owner

Summary

  • Implemented edge-compatible logger with environment-aware log levels
  • Created comprehensive error handling utilities with HTTP status mapping
  • Built validation utilities for input sanitization and security
  • Added ID generation using nanoid with various formats
  • Created centralized environment detection for edge runtime

Implementation Details

Logger (lib/logger.ts)

  • Environment-aware logging (debug/info only in development)
  • Child logger support for context-specific logging
  • Structured log format with timestamps
  • Edge runtime compatible (no Node.js dependencies)

Error Handling (lib/errors.ts)

  • Custom error classes for all application error types
  • HTTP status code mapping
  • Error response formatting for API routes
  • Async handler wrapper with automatic error catching

Validation (lib/validation.ts)

  • Input sanitization for strings and HTML
  • Filename validation with security checks
  • PIN validation (alphanumeric with special chars)
  • Size and count validation for files/gists
  • ISO date validation and expiry checking
  • URL and content type validation

ID Generation (lib/id.ts)

  • Multiple ID formats (standard, readable, short, prefixed)
  • Timestamp-based IDs for sorting
  • Version IDs for gist versions
  • Collision-resistant unique ID generation

Environment Detection (lib/environment.ts)

  • Build-time environment detection (replaced at build)
  • Runtime environment detection for Cloudflare Workers
  • Centralized logic used across all utilities

Test Coverage

All utilities have comprehensive test coverage:

  • ✅ Logger: 12 tests
  • ✅ Errors: 23 tests
  • ✅ Validation: 40 tests
  • ✅ ID Generation: 21 tests
  • ✅ Environment: 8 tests

Total: 104 tests, all passing

Breaking Changes

None - this is new functionality

Checklist

  • All tests pass
  • ESLint and TypeScript checks pass
  • Documentation added (JSDoc comments)
  • Edge runtime compatible
  • No Node.js dependencies

Closes #28

🤖 Generated with Claude Code

Created edge-compatible utilities for GhostPaste:
- Logger with environment-aware log levels and child logger support
- Error handling with custom error classes and HTTP status mapping
- Validation utilities for input sanitization and security
- ID generation using nanoid with various formats
- Environment detection for edge runtime compatibility
- Comprehensive test coverage for all utilities

Updated configuration module to use centralized environment detection.
All utilities are designed to work in Cloudflare Workers edge runtime.

Closes #28

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Copy link

cloudflare-workers-and-pages bot commented Jun 6, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ghostpaste 183c5b9 Visit preview Jun 06 2025, 06:41 AM

Updated TODO.md to reflect completion of utility tasks from PR #34:
- Logger utility (edge-compatible)
- Error handling utilities
- Validation utilities
- ID generation utility using nanoid

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
@nullcoder nullcoder merged commit 3a70b1d into main Jun 6, 2025
1 check was pending
@nullcoder nullcoder deleted the feat/core-utilities branch June 6, 2025 06:40
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.

Implement core utility functions
1 participant