Type-safe server actions with built-in validation for Next.js
npm install next-safe-action-queryType-safe server actions with built-in validation for Next.js
- š 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
``bash`
npm install next-safe-action-queryor
pnpm add next-safe-action-queryor
yarn add next-safe-action-query
typescript
import { createSafeAction, type ActionResult } from 'next-safe-action-query';const result = await createSafeAction(async () => {
return { message: 'Hello, World!' };
});
`$3
`javascript
const { createSafeAction } = require('next-safe-action-query');const result = await createSafeAction(async () => {
return { message: 'Hello, World!' };
});
`Development
$3
- Node.js 18+
- pnpm 8+
$3
`bash
Install dependencies
pnpm installBuild the package
pnpm buildCheck dependency consistency
pnpm lint:depsFix dependency issues
pnpm fix:deps
`$3
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/$3
-
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$3
This project uses 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$3
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 mismatchesPackage 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
$3
- Uses NodeNext module resolution for modern Node.js compatibility
- Strict type checking enabled
- Configured for optimal library development$3
- Extends main config
- Generates only type declarations
- Excludes test files$3
- Enforces exact versions (no semver ranges)
- Maintains consistent package.json formatting
- Ensures reproducible builds$3
- Configured for public npm publishing
- Automatic changelog generation
- Semantic versioning supportPublishing
This package is configured for automated publishing:
1. Manual: Use
pnpm release
2. CI/CD: Set up GitHub Actions with changesets actionLicense
MIT
Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add a changeset:
pnpm changeset`---
Built with ā¤ļø using modern TypeScript tooling