@hopak/common
v1.0.1
Published
Shared types, errors, logger, filesystem helpers for Hopak.js.
Maintainers
Readme
@hopak/common
Shared primitives for Hopak.js — errors, logger, config types. Zero runtime dependencies.
bun add @hopak/common📖 Docs: hopak.dev/docs/packages/common
You rarely install this directly — @hopak/core re-exports all of it.
Errors
Every error carries an HTTP status and a code, and the framework's error handler serialises it to { error, message, details }:
import { NotFound, Forbidden, ValidationError } from '@hopak/common';
throw new NotFound('post not found'); // → 404 NOT_FOUND
throw new Forbidden('not your post'); // → 403 FORBIDDEN
throw new ValidationError('bad input', {}); // → 400 VALIDATION_ERRORAlso HopakError (base), Unauthorized, Conflict, RateLimited, InternalError, ConfigError, PluginError.
Logger
import { createLogger } from '@hopak/common';
const log = createLogger({ level: 'debug' });
log.info('started', { port: 3000 });
log.child({ requestId }).warn('slow query');Also included
HopakConfig and friends (the shape of hopak.config.ts), HttpStatus constants, and small helpers: slugify, pluralize, parseDuration, deepMerge (which drops __proto__ / constructor / prototype keys), pathExists, isFile, isDirectory.
Requirements
Bun ≥ 1.3.
Author
Volodymyr Press · [email protected]
License
MIT.
