UNPKG

next-safe-action-query

Version:

Type-safe server actions with built-in validation for Next.js

162 lines (117 loc) • 4.17 kB
# next-safe-action-query Type-safe server actions with built-in validation for Next.js ## Features - šŸ”„ **Dual Package**: Supports both ESM and CommonJS - šŸ“¦ **Zero Config**: Works out of the box with Next.js - šŸ›”ļø **Type Safe**: Full TypeScript support with proper type exports - šŸ”§ **pnpm**: Optimized for pnpm package manager - šŸ“ **Changesets**: Automated versioning and changelog generation - šŸ”’ **Fixed Versions**: Enforced exact dependency versions with syncpack ## Installation ```bash npm install next-safe-action-query # or pnpm add next-safe-action-query # or yarn add next-safe-action-query ``` ## Usage ### ESM (ES Modules) ```typescript import { createSafeAction, type ActionResult } from 'next-safe-action-query'; const result = await createSafeAction(async () => { return { message: 'Hello, World!' }; }); ``` ### CommonJS ```javascript const { createSafeAction } = require('next-safe-action-query'); const result = await createSafeAction(async () => { return { message: 'Hello, World!' }; }); ``` ## Development ### Prerequisites - Node.js 18+ - pnpm 8+ ### Setup ```bash # Install dependencies pnpm install # Build the package pnpm build # Check dependency consistency pnpm lint:deps # Fix dependency issues pnpm fix:deps ``` ### Build System This package uses a modern dual-build system: - **ESM**: Built to `dist/esm/` with native ES modules - **CJS**: Built to `dist/cjs/` with CommonJS format - **Types**: TypeScript declarations in `dist/types/` ### Scripts - `pnpm build` - Build all formats (ESM, CJS, and types) - `pnpm clean` - Remove build artifacts - `pnpm changeset` - Add a changeset for versioning - `pnpm version` - Update versions based on changesets - `pnpm release` - Build and publish to npm - `pnpm lint:deps` - Check dependency consistency - `pnpm fix:deps` - Fix dependency version mismatches ### Version Management This project uses [Changesets](https://github.com/changesets/changesets) for version management: 1. **Make changes** to the codebase 2. **Add a changeset**: `pnpm changeset` 3. **Commit the changeset** with your changes 4. **Release when ready**: `pnpm version && pnpm release` ### Dependency Management [Syncpack](https://github.com/JamieMason/syncpack) ensures all dependencies use exact versions: - All package versions are pinned (no `^` or `~` ranges) - Consistent formatting across all package.json files - Automatic detection and fixing of version mismatches ## Package Structure ``` next-safe-action-query/ ā”œā”€ā”€ src/ # TypeScript source files ā”œā”€ā”€ dist/ # Build output (gitignored) │ ā”œā”€ā”€ esm/ # ES Modules build │ ā”œā”€ā”€ cjs/ # CommonJS build │ └── types/ # TypeScript declarations ā”œā”€ā”€ .changeset/ # Changeset configuration ā”œā”€ā”€ build.js # Build script ā”œā”€ā”€ tsconfig.json # TypeScript config ā”œā”€ā”€ tsconfig.build.json # Build-specific TS config ā”œā”€ā”€ .syncpackrc.json # Syncpack configuration └── package.json # Package configuration ``` ## Configuration Files ### TypeScript Config (`tsconfig.json`) - Uses `NodeNext` module resolution for modern Node.js compatibility - Strict type checking enabled - Configured for optimal library development ### Build Config (`tsconfig.build.json`) - Extends main config - Generates only type declarations - Excludes test files ### Syncpack Config (`.syncpackrc.json`) - Enforces exact versions (no semver ranges) - Maintains consistent package.json formatting - Ensures reproducible builds ### Changesets Config (`.changeset/config.json`) - Configured for public npm publishing - Automatic changelog generation - Semantic versioning support ## Publishing This package is configured for automated publishing: 1. **Manual**: Use `pnpm release` 2. **CI/CD**: Set up GitHub Actions with changesets action ## License MIT ## Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add a changeset: `pnpm changeset` 5. Submit a pull request --- Built with ā¤ļø using modern TypeScript tooling