{"_id":"r-gatekeeper","_rev":"5-003d731ce151b76fb0845a4904c929ec","name":"r-gatekeeper","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"r-gatekeeper","version":"0.1.0","keywords":["typescript","utility","type-safe"],"author":{"name":"riskrisk"},"license":"MIT","_id":"r-gatekeeper@0.1.0","maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"homepage":"https://github.com/risk/r-gatekeeper#readme","bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"dist":{"shasum":"5800593da141a03ce55a3d6fc7199f0723225594","tarball":"https://registry.npmjs.org/r-gatekeeper/-/r-gatekeeper-0.1.0.tgz","fileCount":33,"integrity":"sha512-GiP5juZWx/EvV6kKpbXg6+Gwv0t3MImiUyF2hUn+GI2PQN1164dfT9olj/lru+MDQkNWoC6X1eudzzVHtpfv/A==","signatures":[{"sig":"MEQCIF3EGu4n1+aql58eqveIMXAoQPHzwCvtUr1695MKA0J5AiB4xqV6L/RW3D5qmEz7H+xAcvv/w2YsDSgAYDdnYk3kVQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":70767},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.esm.js","gitHead":"1a5224681f50241824585e07ff310366044ec770","scripts":{"dev":"rollup -c -w","lint":"eslint src/**/*.ts","test":"vitest --coverage","build":"rollup -c","format":"prettier --write src/**/*.ts","test:ui":"vitest --coverage --ui","lint:fix":"eslint src/**/*.ts --fix","test:watch":"vitest --coverage --watch","version:major":"npm version major --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:minor":"npm version minor --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:patch":"npm version patch --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"riskrisk","email":"risk.masu@gmail.com"},"overrides":{"eslint":"^9.17.0","@typescript-eslint/utils":"^8.15.0"},"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"_npmVersion":"10.8.2","description":"A TypeScript utility library","directories":{},"_nodeVersion":"20.19.0","dependencies":{"zod":"^4.1.12"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tslib":"^2.8.1","eslint":"^9.17.0","rollup":"^4.28.1","vitest":"^4.0.8","globals":"^15.11.0","prettier":"^3.4.2","@eslint/js":"^9.17.0","@vitest/ui":"^4.0.8","typescript":"^5.7.2","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.15.0","@vitest/coverage-v8":"^4.0.8","eslint-plugin-import":"^2.31.0","eslint-plugin-vitest":"^0.5.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-typescript":"^12.1.1","@vitest/coverage-istanbul":"^4.0.8","@rollup/plugin-node-resolve":"^15.2.3","@tony.ganchev/eslint-plugin-header":"^3.1.8"},"_npmOperationalInternal":{"tmp":"tmp/r-gatekeeper_0.1.0_1762888117743_0.9994339584546992","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"r-gatekeeper","version":"0.1.1","keywords":["typescript","utility","type-safe"],"author":{"name":"riskrisk"},"license":"MIT","_id":"r-gatekeeper@0.1.1","maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"homepage":"https://github.com/risk/r-gatekeeper#readme","bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"dist":{"shasum":"1847c8a1fae8e6cd816b73a664e37bd09deca123","tarball":"https://registry.npmjs.org/r-gatekeeper/-/r-gatekeeper-0.1.1.tgz","fileCount":25,"integrity":"sha512-ckFHD9CWK6euw03IdUaGPz7PQqbfOPacaiLvVfjWHpdIFB19DRlMyR69i1npYDVr50NcbaZic4om7LTV7Yr0ew==","signatures":[{"sig":"MEQCIG25ZTK4Az9kcIi2ehBdI8K6hMrASmi8i9iUDxK/vGkoAiBnRPkHilLy764uV8wdDPwS53uWLCMfagrFKdMA3KXa6g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":62976},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.esm.js","gitHead":"8dc03405b7e8f7a1f295c68222a1e2eb775ee647","scripts":{"dev":"rollup -c -w","lint":"eslint src/**/*.ts","test":"vitest --coverage","build":"rollup -c","format":"prettier --write src/**/*.ts","test:ui":"vitest --coverage --ui","lint:fix":"eslint src/**/*.ts --fix","test:watch":"vitest --coverage --watch","version:major":"npm version major --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:minor":"npm version minor --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:patch":"npm version patch --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"riskrisk","email":"risk.masu@gmail.com"},"overrides":{"eslint":"^9.17.0","@typescript-eslint/utils":"^8.15.0"},"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"_npmVersion":"10.8.2","description":"Type-safe input/output gates for your handlers, powered by Zod.","directories":{},"_nodeVersion":"20.19.5","dependencies":{"zod":"^4.1.12"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tslib":"^2.8.1","eslint":"^9.17.0","rollup":"^4.28.1","vitest":"^4.0.8","globals":"^15.11.0","prettier":"^3.4.2","@eslint/js":"^9.17.0","@vitest/ui":"^4.0.8","typescript":"^5.7.2","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.15.0","@vitest/coverage-v8":"^4.0.8","eslint-plugin-import":"^2.31.0","eslint-plugin-vitest":"^0.5.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-typescript":"^12.1.1","@vitest/coverage-istanbul":"^4.0.8","@rollup/plugin-node-resolve":"^15.2.3","@tony.ganchev/eslint-plugin-header":"^3.1.8"},"_npmOperationalInternal":{"tmp":"tmp/r-gatekeeper_0.1.1_1762889266398_0.18139905861412986","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"r-gatekeeper","version":"0.1.2","keywords":["typescript","utility","type-safe"],"author":{"name":"riskrisk"},"license":"MIT","_id":"r-gatekeeper@0.1.2","maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"homepage":"https://github.com/risk/r-gatekeeper#readme","bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"dist":{"shasum":"5534d171196ab79aecd7c7561f2ca879febb2ba7","tarball":"https://registry.npmjs.org/r-gatekeeper/-/r-gatekeeper-0.1.2.tgz","fileCount":25,"integrity":"sha512-YdZnTfolMIt0Rc01jZcPDE0JHf+Wv2XNqsj0FAl3QMZqKX0A/Odq2j6XKEpY5FTHmha4spl3fAW1niiPasxCnw==","signatures":[{"sig":"MEYCIQCNdHfX57HEsD9VQbweLAfjK/iZ3zZNdTBvOTS/2A/qlAIhAMFdYmpolFZhz4W5UEJGhoNsnNLYFEH+lUqotEdLbG9Z","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":62976},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.esm.js","gitHead":"1672bcb00e17d983fc865a3e1b9eebed7bf51d28","scripts":{"dev":"rollup -c -w","lint":"eslint src/**/*.ts","test":"vitest --coverage","build":"rollup -c","format":"prettier --write src/**/*.ts","test:ui":"vitest --coverage --ui","lint:fix":"eslint src/**/*.ts --fix","test:watch":"vitest --coverage --watch","version:major":"npm version major --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:minor":"npm version minor --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:patch":"npm version patch --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"riskrisk","email":"risk.masu@gmail.com"},"overrides":{"eslint":"^9.17.0","@typescript-eslint/utils":"^8.15.0"},"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"_npmVersion":"10.8.2","description":"Type-safe input/output gates for your handlers, powered by Zod.","directories":{},"_nodeVersion":"20.19.5","dependencies":{"zod":"^4.1.12"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tslib":"^2.8.1","eslint":"^9.17.0","rollup":"^4.28.1","vitest":"^4.0.8","globals":"^15.11.0","prettier":"^3.4.2","@eslint/js":"^9.17.0","@vitest/ui":"^4.0.8","typescript":"^5.7.2","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.15.0","@vitest/coverage-v8":"^4.0.8","eslint-plugin-import":"^2.31.0","eslint-plugin-vitest":"^0.5.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-typescript":"^12.1.1","@vitest/coverage-istanbul":"^4.0.8","@rollup/plugin-node-resolve":"^15.2.3","@tony.ganchev/eslint-plugin-header":"^3.1.8"},"_npmOperationalInternal":{"tmp":"tmp/r-gatekeeper_0.1.2_1762892692211_0.4573583355031783","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"r-gatekeeper","version":"0.1.3","keywords":["typescript","utility","type-safe"],"author":{"name":"riskrisk"},"license":"MIT","_id":"r-gatekeeper@0.1.3","maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"homepage":"https://github.com/risk/r-gatekeeper#readme","bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"dist":{"shasum":"d99d9ce7e55578dfa7490e410dbcf14a7f354bc8","tarball":"https://registry.npmjs.org/r-gatekeeper/-/r-gatekeeper-0.1.3.tgz","fileCount":25,"integrity":"sha512-SW1q4SowRY3feJ3GWddDaOxa/hlZPKBF09YagDHHhr+uZkXMkVLkDNBb3QRSSzWpHk1IlctTElYvcAA44LZXYg==","signatures":[{"sig":"MEYCIQCNUE670B3hAgL1AkJTS98vDnmlZxrHz8nsxzC6q+0LEgIhAO+7a/4cPZkfviDANVHb4RsRJDJx+npGnL0M8Y6ctAJi","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63163},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","module":"dist/index.esm.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.js","default":"./dist/index.esm.js","require":"./dist/index.js"}},"gitHead":"59ca508df0d9739191da5ea5acaa17ca1b095ef6","scripts":{"dev":"rollup -c -w","lint":"eslint src/**/*.ts","test":"vitest --coverage","build":"rollup -c","format":"prettier --write src/**/*.ts","test:ui":"vitest --coverage --ui","lint:fix":"eslint src/**/*.ts --fix","test:watch":"vitest --coverage --watch","version:major":"npm version major --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:minor":"npm version minor --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:patch":"npm version patch --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","prepublishOnly":"npm run build && npm test"},"_npmUser":{"name":"riskrisk","email":"risk.masu@gmail.com"},"overrides":{"eslint":"^9.17.0","@typescript-eslint/utils":"^8.15.0"},"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"_npmVersion":"10.8.2","description":"Type-safe input/output gates for your handlers, powered by Zod.","directories":{},"_nodeVersion":"20.19.5","dependencies":{"zod":"^4.1.12"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tslib":"^2.8.1","eslint":"^9.17.0","rollup":"^4.28.1","vitest":"^4.0.8","globals":"^15.11.0","prettier":"^3.4.2","@eslint/js":"^9.17.0","@vitest/ui":"^4.0.8","typescript":"^5.7.2","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.15.0","@vitest/coverage-v8":"^4.0.8","eslint-plugin-import":"^2.31.0","eslint-plugin-vitest":"^0.5.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-typescript":"^12.1.1","@vitest/coverage-istanbul":"^4.0.8","@rollup/plugin-node-resolve":"^15.2.3","@tony.ganchev/eslint-plugin-header":"^3.1.8"},"_npmOperationalInternal":{"tmp":"tmp/r-gatekeeper_0.1.3_1762893062514_0.2405134557260049","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"_id":"r-gatekeeper@0.2.0","bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"dist":{"shasum":"a5415b91343b1332c0d7dc48f0d8916f57f0bd82","tarball":"https://registry.npmjs.org/r-gatekeeper/-/r-gatekeeper-0.2.0.tgz","fileCount":25,"integrity":"sha512-pbPt2cM9YnoEQ8rVuIko3FghgOg0tOtkQnhWkfLHCkprqKGy/nl9ZGVbzmNGUT6prDt1zTGXfW8vLgUoBroezg==","signatures":[{"sig":"MEQCIEN5HHh/DYAuBdqMo9GrOkclejImz3TigrgplNx50dvhAiBCt884Noz5A+rouUQ8isjPE0/olwUPHhrJzDa0z2n/4w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCPdVhJok6+LtQmYiMLOFXNRIkKI829zHfTSgioVqUSnQIhANYc5s53HvcpovfD1WE9uD8v0rxbmLaeKbbTEuz44UpQ"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/r-gatekeeper@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":62526},"main":"dist/index.js","name":"r-gatekeeper","type":"module","types":"dist/index.d.ts","author":{"name":"riskrisk"},"module":"dist/index.esm.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.js","default":"./dist/index.esm.js","require":"./dist/index.js"}},"gitHead":"9eae699d7d9f21ef00c46b1e1ab1816066c87842","license":"MIT","scripts":{"dev":"rollup -c -w","lint":"eslint src/**/*.ts","test":"vitest --coverage","build":"rollup -c","format":"prettier --write src/**/*.ts","test:ui":"vitest --coverage --ui","lint:fix":"eslint src/**/*.ts --fix","test:watch":"vitest --coverage --watch","version:major":"npm version major --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:minor":"npm version minor --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","version:patch":"npm version patch --no-git-tag-version && git add package.json package-lock.json && git commit -S -m \"chore: bump version to $(node -p \"require('./package.json').version\")\" && git tag -s v$(node -p \"require('./package.json').version\") -m \"Release v$(node -p \"require('./package.json').version\")\" && git push --follow-tags","prepublishOnly":"npm run build && npm test"},"version":"0.2.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"4bdbbbf0-588c-431b-93fb-8a5dbd7a2b16"}},"homepage":"https://github.com/risk/r-gatekeeper#readme","keywords":["typescript","utility","type-safe"],"overrides":{"eslint":"^9.17.0","@typescript-eslint/utils":"^8.15.0"},"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"_npmVersion":"11.19.0","description":"Type-safe input/output gates for your handlers, powered by Zod.","directories":{},"maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"_nodeVersion":"24.21.0","dependencies":{"zod":"^4.1.12"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tslib":"^2.8.1","eslint":"^9.17.0","rollup":"^4.28.1","vitest":"^4.0.8","globals":"^15.11.0","prettier":"^3.4.2","@eslint/js":"^9.17.0","@vitest/ui":"^4.0.8","typescript":"^5.7.2","rollup-plugin-dts":"^6.1.1","typescript-eslint":"^8.15.0","@vitest/coverage-v8":"^4.0.8","eslint-plugin-import":"^2.31.0","eslint-plugin-vitest":"^0.5.4","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.2.1","@rollup/plugin-commonjs":"^28.0.0","@rollup/plugin-typescript":"^12.1.1","@vitest/coverage-istanbul":"^4.0.8","@rollup/plugin-node-resolve":"^15.2.3","@tony.ganchev/eslint-plugin-header":"^3.1.8"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/r-gatekeeper_0.2.0_1791729588557_0.21659942834674006"}}},"time":{"created":"2025-11-11T19:08:37.670Z","modified":"2026-10-11T14:39:49.000Z","0.1.0":"2025-11-11T19:08:37.943Z","0.1.1":"2025-11-11T19:27:46.579Z","0.1.2":"2025-11-11T20:24:52.399Z","0.1.3":"2025-11-11T20:31:02.752Z","0.2.0":"2026-10-11T14:39:48.636Z"},"bugs":{"url":"https://github.com/risk/r-gatekeeper/issues"},"author":{"name":"riskrisk"},"license":"MIT","homepage":"https://github.com/risk/r-gatekeeper#readme","keywords":["typescript","utility","type-safe"],"repository":{"url":"git+https://github.com/risk/r-gatekeeper.git","type":"git"},"description":"Type-safe input/output gates for your handlers, powered by Zod.","maintainers":[{"name":"riskrisk","email":"risk.masu@gmail.com"}],"readme":"# r-gatekeeper\n\nType-safe input/output gates around your handlers, powered by [Zod](https://github.com/colinhacks/zod).\n\n`r-gatekeeper` sits at the boundary between “outside world” and “inside world” and makes sure:\n\n- 🚫 **No unexpected data comes in** – inputs are validated before your handler runs.\n- 🚫 **No unexpected data leaks out** – outputs are validated before they leave the gate.\n- ✅ **Your handler receives validated input**. What it returns stays untyped until the output schema accepts it.\n- ✅ **Errors are normalized** as a small discriminated union (`GateResult`).\n\nIt is intentionally small and focused: no DI container、no framework、just gates.\n\n---\n\n## Installation\n\n```bash\nnpm install r-gatekeeper zod\n# or\nyarn add r-gatekeeper zod\npnpm add r-gatekeeper zod\n```\n\n---\n\n## Core concepts\n\nr-gatekeeper is built around three ideas:\n\n1. **Schemas at the boundary**  \n   You describe the input/output of a handler with Zod schemas.\n\n2. **Handlers receive validated input and return untyped data**  \n   Handlers receive `z.infer<IN>`. Their return is `unknown`, because data coming back from outside is not trusted. `schemas.out` is what stabilizes that return into `z.infer<OUT>`. Returning an `Error` is a handler-level failure and is not passed to the output schema.\n\n3. **Uniform result shape**  \n   Gates always return a `GateResult<T>`:\n\n```ts\ntype GateResult<T> = { ok: true; data: T } | { ok: false; error: GateError }\n\ntype GateError =\n  | { kind: 'input'; error: ZodError } // invalid input\n  | { kind: 'output'; error: ZodError } // invalid output\n  | { kind: 'handler'; error: Error } // handler-level failure\n```\n\nYou decide how to log / map / rethrow errors based on `kind`.\n\n---\n\n## Quick start\n\n```ts\nimport { z } from 'zod'\nimport { withGate } from 'r-gatekeeper'\n\n// 1. Define schemas for the boundary\nconst schemas = {\n  in: z.object({\n    id: z.string().uuid(),\n  }),\n  out: z.object({\n    id: z.string().uuid(),\n    name: z.string(),\n  }),\n}\n\n// 2. Implement your handler using validated types\nconst getUser = withGate(schemas, ({ id }) => {\n  // input is already validated: id is a UUID string\n  const user = findUserById(id) // e.g. from a repository\n  if (!user) {\n    return new Error('User not found')\n  }\n  return user\n})\n\n// 3. Use the gate at a boundary (e.g. HTTP handler)\nasync function httpHandler(req: Request): Promise<Response> {\n  const body = await req.json()\n  const result = getUser(body)\n\n  if (!result.ok) {\n    // You can branch on error kind\n    switch (result.error.kind) {\n      case 'input':\n        return new Response('Bad Request', { status: 400 })\n      case 'handler':\n        return new Response('Not Found', { status: 404 })\n      case 'output':\n        // output schema mismatch -> our side is wrong\n        console.error(result.error.error)\n        return new Response('Internal Server Error', { status: 500 })\n    }\n  }\n\n  return new Response(JSON.stringify(result.data), {\n    status: 200,\n    headers: { 'Content-Type': 'application/json' },\n  })\n}\n```\n\n---\n\n## API\n\nAll functions are fully typed and built on top of Zod.\n\n### `withGate`\n\n```ts\nimport { withGate } from 'r-gatekeeper'\nimport { z } from 'zod'\n\nconst gate = withGate(\n  {\n    in: z.object({ value: z.number() }),\n    out: z.object({ doubled: z.number() }),\n  },\n  ({ value }) => ({ doubled: value * 2 })\n)\n\nconst result = gate({ value: 2 }) // value: unknown\n// result: GateResult<{ doubled: number }>\n```\n\n- Input type: `unknown`  \n  → validated by `schemas.in.safeParse`\n- Handler input: `z.infer<typeof schemas.in>`\n- Handler return: `unknown` (an `Error` is taken as a handler failure before output validation)\n- Output type: `GateResult<z.infer<typeof schemas.out>>`\n\nUse this at **outer boundaries** where raw data flows in (HTTP, queues, CLIs, etc.).\n\n### `withGateFixedIn`\n\n```ts\nimport { withGateFixedIn } from 'r-gatekeeper'\n\nconst schemas = {\n  in: z.preprocess(value => (typeof value === 'string' ? JSON.parse(value) : value), z.object({ value: z.number() })),\n  out: z.object({ doubled: z.number() }),\n}\n\nconst gate = withGateFixedIn(schemas, ({ value }) => ({ doubled: value * 2 }))\n\n// accepts the Zod \"input type\", not unknown\nconst result = gate('{\"value\": 2}')\n```\n\n- Input type: `z.input<IN_SCHEMA>`\n- Handler input: `z.infer<IN_SCHEMA>`\n- Output type: `GateResult<z.infer<OUT_SCHEMA>>`\n\nUse this when you want the **function signature** to expose the exact Zod input type (including `preprocess` / `transform` chains).\n\n### Async variants\n\n```ts\nimport { withGateAsync, withGateFixedInAsync } from 'r-gatekeeper'\n\nconst gate = withGateAsync(\n  {\n    in: z.object({ id: z.string() }),\n    out: z.object({ id: z.string(), name: z.string() }),\n  },\n  async ({ id }) => {\n    const user = await repo.findById(id)\n    if (!user) return new Error('User not found')\n    return user\n  }\n)\n\nconst result = await gate({ id: '123' })\n// result: Promise<GateResult<{ id: string; name: string }>>\n```\n\n- `withGateAsync` – same as `withGate`, but:\n  - Handler may return `unknown` or `Error`, or a `Promise` of either.\n  - Uses `safeParseAsync` for input/output.\n- `withGateFixedInAsync` – async version of `withGateFixedIn`.\n\n---\n\n## Error handling helpers\n\nHelpers for narrowing `GateResult` と `GateError`:\n\n```ts\nimport {\n  isGateResultOk,\n  isGateResultError,\n  isGateInputError,\n  isGateOutputError,\n  isGateHandlerError,\n} from 'r-gatekeeper'\n\nconst result = gate(someInput)\n\nif (isGateResultOk(result)) {\n  // result.data is available here\n} else if (isGateResultError(result)) {\n  if (isGateInputError(result.error)) {\n    // schemas.in validation failed\n  } else if (isGateOutputError(result.error)) {\n    // schemas.out validation failed\n  } else if (isGateHandlerError(result.error)) {\n    // handler returned an Error\n  }\n}\n```\n\nOf course, you can also use a `switch` statement on the discriminated union if you prefer.\n\n---\n\n## TypeScript and Zod notes\n\n- `GateSchemaType` is a thin alias around `z.ZodType`.\n- The library does **not** force `z.strict()`.\n  → Whether to use strict schemas or not is a design decision on the consumer side.\n- Handlers are **not thrown from inside the library**.\n  If you want to signal a handler-level failure, return an `Error` value (it will become `kind: 'handler'`).\n  If you want to `throw`, do it at the outer boundary after inspecting the `GateResult`.\n\n---\n\n## When to use r-gatekeeper\n\nTypical scenarios where r-gatekeeper works well:\n\n- Controller / Presenter layers in API servers.\n- Server Actions / Route Handlers in frameworks like Next.js or Remix.\n- Message queue consumers/producers and batch job boundaries.\n- As a boundary in front of/behind other libraries (for example, `r-pipeline`).\n\nUse it when you don't want to change your inner business logic, but you do want to make the boundary between \"outside\" and \"inside\" explicit, validated, and safe.\n\n---\n\n## Credits\n\nThis project was built collaboratively between human design and AI assistance.\n\nDesign and coding by risk  \nDesign assistance and coding support by ChatGPT  \nCode review by ChatGPT and Cursor AI  \nDocumentation generated by ChatGPT and Cursor AI\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n\n# Build the project\nnpm run build\n\n# Run linting\nnpm run lint\n\n# Format code\nnpm run format\n```\n\n---\n\n## License\n\nMIT\n","readmeFilename":"README.md"}