forked from lukemorales/next-safe-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5199e12
Showing
15 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ | ||
"repo": "lukemorales/safe-next-navigation" | ||
} | ||
], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.eslintrc* | ||
*.config.js | ||
/.jest/* | ||
/coverage/* | ||
/dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore | ||
|
||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Caches | ||
|
||
.cache | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# IntelliJ based IDEs | ||
.idea | ||
|
||
# Finder (MacOS) folder config | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# safe-next-router | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
bun install | ||
``` | ||
|
||
To run: | ||
|
||
```bash | ||
bun run src/index.ts | ||
``` | ||
|
||
This project was created using `bun init` in bun v1.0.23. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"name": "safe-next-navigation", | ||
"version": "0.0.1", | ||
"author": "Luke Morales <[email protected]>", | ||
"description": "Type-safe navigation for NextJS App router", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/lukemorales/safe-next-navigation.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/lukemorales/safe-next-navigation/issues" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "run-p build:*", | ||
"build:tsup": "tsup --dts --minify", | ||
"changeset": "changeset", | ||
"clean": "rimraf dist", | ||
"dev": "bun run test:coverage --ui", | ||
"lint": "run-p lint:*", | ||
"lint:eslint": "eslint src --ext .ts", | ||
"lint:eslint:fix": "bun run lint:eslint --fix", | ||
"lint:format": "prettier --check \"src/**/*.ts\"", | ||
"lint:format:fix": "bun run lint:format --write", | ||
"lint:tsc": "tsc --project tsconfig.json --noEmit", | ||
"test": "vitest --passWithNoTests", | ||
"test:ci": "bun run test:coverage --run", | ||
"test:coverage": "bun run test --coverage" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"lukemorales/oss", | ||
"lukemorales/jest" | ||
] | ||
}, | ||
"prettier": "@lukemorales/prettier-config", | ||
"devDependencies": { | ||
"@changesets/changelog-github": "^0.5.0", | ||
"@changesets/cli": "^2.27.1", | ||
"@lukemorales/prettier-config": "^1.1.0", | ||
"@testing-library/react": "^14.2.0", | ||
"@types/bun": "latest", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"@vitest/coverage-v8": "^1.2.2", | ||
"@vitest/ui": "^1.2.2", | ||
"eslint-config-lukemorales": "^0.3.0", | ||
"jsdom": "^24.0.0", | ||
"next": "^14.1.0", | ||
"npm-run-all": "^4.1.5", | ||
"tsup": "^8.0.1", | ||
"typescript": "^4.8.2", | ||
"vitest": "^1.2.2", | ||
"zod": "^3.22.4" | ||
}, | ||
"peerDependencies": { | ||
"typescript": ">=4.8.2", | ||
"next": ">=13.0.0", | ||
"zod": ">=3.20.0" | ||
}, | ||
"keywords": [ | ||
"next", | ||
"nextjs", | ||
"next.js", | ||
"next-js", | ||
"app router", | ||
"app-router", | ||
"vercel", | ||
"typescript", | ||
"type-safety", | ||
"router", | ||
"navigation", | ||
"zod", | ||
"runtime validation", | ||
"validation" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./create-router-config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { z } from 'zod'; | ||
import { createRouterConfig } from './create-router-config'; | ||
|
||
export const { routes, useSafeParams, useSafeSearchParams } = | ||
createRouterConfig((route) => ({ | ||
home: route('/'), | ||
signup: route('/signup', { | ||
search: z.object({ | ||
invitationId: z.string().optional(), | ||
}), | ||
}), | ||
organization: route('/org/[orgId]', { | ||
params: z.object({ orgId: z.string() }), | ||
}), | ||
organizationUsers: route('/org/[orgId]/users', { | ||
params: z.object({ orgId: z.string() }), | ||
search: z.object({ order: z.enum(['asc', 'desc']) }), | ||
}), | ||
})); | ||
|
||
//@ts-expect-error Route "home" does not have params declared | ||
const invalid = useSafeParams('home'); | ||
// ^? const invalid: never | ||
|
||
const params = useSafeParams('organization'); | ||
// ^? const params: { orgId: string; } | ||
|
||
const signUpSearch = useSafeSearchParams('signup'); | ||
// ^? const signUpSearch: { invitationId?: string | null | undefined; } | ||
|
||
//@ts-expect-error Route "organization" does not have params declared | ||
const invalidSearch = useSafeSearchParams('organization'); | ||
// ^? const invalidSearch: never | ||
|
||
routes.home(); //? | ||
routes.signup({ search: { invitationId: 'invite_123' } }); // "/signup?invitationId=invite_123" | ||
routes.organization({ orgId: 'org_123' }); // "/org/org_123" | ||
routes.organizationUsers({ orgId: 'org_123', search: { order: 'asc' } }); // "/org/org_123/users?order=asc" | ||
|
||
routes.signup.$parseSearchParams({ invitationId: 'invite_345' }); | ||
routes.organization.$parseParams({ orgId: 'org_123' }); | ||
routes.organizationUsers.$parseParams({ orgId: 'org_123' }); | ||
routes.organizationUsers.$parseSearchParams({ order: 'desc' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ESNext", "DOM.Iterable"], | ||
"target": "ESNext", | ||
"module": "ES2020", | ||
"outDir": "./dist", | ||
"jsx": "react-jsx", | ||
"declaration": true, | ||
"noEmit": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"skipLibCheck": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": false, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noUncheckedIndexedAccess": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"isolatedModules": true, | ||
"types": ["vitest/globals"], | ||
}, | ||
} |
Oops, something went wrong.