diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..ed7430c8 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,69 @@ +# Contributing to jqplay + +Thank you for considering contributing to jqplay! We welcome contributions from everyone. By participating in this project, you agree to abide by our code of conduct. + +## How to Contribute + +### Reporting Bugs + +If you find a bug, please report it by opening an issue on our [GitHub repository](https://github.com/owenthereal/jqplay/issues). Include as much detail as possible to help us understand and reproduce the issue. + +### Suggesting Features + +We welcome feature suggestions! If you have an idea for a new feature, please open an issue on our [GitHub repository](https://github.com/owenthereal/jqplay/issues) and describe your idea in detail. + +### Submitting Pull Requests + +1. **Fork the repository**: Click the "Fork" button at the top right corner of the repository page to create a copy of the repository in your GitHub account. + +2. **Clone your fork**: Clone your forked repository to your local machine using the following command: + ```sh + git clone https://github.com//jqplay.git + cd jqplay + ``` + +3. **Create a new branch**: Create a new branch for your changes using the following command: + ```sh + git checkout -b my-feature-branch + ``` + +4. **Make your changes**: Make your changes to the codebase. Ensure that your code follows the project's coding style and conventions. + +5. **Test your changes**: Run the tests to ensure that your changes do not break any existing functionality. You can run the tests using the following command: + ```sh + npm test + ``` + +6. **Commit your changes**: Commit your changes with a descriptive commit message using the following command: + ```sh + git commit -m "Add feature XYZ" + ``` + +7. **Push your changes**: Push your changes to your forked repository using the following command: + ```sh + git push origin my-feature-branch + ``` + +8. **Create a pull request**: Go to the original repository on GitHub and click the "New pull request" button. Select your branch from the "compare" dropdown and click "Create pull request". Provide a detailed description of your changes in the pull request. + +## Code Style + +Please ensure that your code follows the project's coding style and conventions. We use [ESLint](https://eslint.org/) to enforce code quality and consistency. You can run the linter using the following command: +```sh +npm run lint +``` + +## Testing + +We use [Jest](https://jestjs.io/) for testing. Please ensure that your changes are covered by tests. You can run the tests using the following command: +```sh +npm test +``` + +## Code of Conduct + +By participating in this project, you agree to abide by our [code of conduct](CODE_OF_CONDUCT.md). Please read it to understand the expectations for behavior when interacting with the community. + +## Thank You! + +Thank you for your contributions! Your support and involvement help make jqplay better for everyone. diff --git a/README.md b/README.md deleted file mode 100644 index d7b59772..00000000 --- a/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# jqplay - -A [jq](https://jqlang.github.io/jq) playground built with [Next.js](https://nextjs.org). -Test your jq queries against JSON directly in your browser. All jq queries and HTTP requests to fetch JSON are processed **locally** in your browser. Snippets are sent to the server **only** if you choose to share them. - -✨ **Try it out at [jqplay.org](https://jqplay.org)!** - -## How It Works - -- **WebAssembly-Powered**: jqplay integrates the [jq-wasm](https://github.com/owenthereal/jq-wasm) package, a WebAssembly-based jq JSON processor for Node.js and browsers, with no native dependencies. This ensures that all jq queries run directly in your browser. -- **Local Data Processing**: Your JSON input is processed locally in your browser, ensuring your data stays private and secure. -- **Shareable Snippets**: If you share your jq query, a unique URL is generated on the server. Others can open the shared snippet, but the query will still run locally in their browser. - -## Getting Started - -Prerequisites - -- Node.js (>= 14.x recommended) -- npm or yarn package manager -- PostgreSQL (for storing shared snippets) - -## Running the App - -### 1. Clone the repository - -```console -git clone https://github.com/owenthereal/jqplay -cd jqplay -``` - -### 2. Start in Development Mode - -To start the app in development mode with hot reload enabled and a local PostgreSQL database: - -```console -docker compose up -``` - -Open your browser to to explore jqplay. - -### 3. Run a Production Build - -For a production-ready build, use: - -```console -npm run build -npm run start -``` - -Open your browser to to use jqplay locally in production mode. - -## Contributing - -Contributions are welcome! πŸŽ‰ Whether you’re fixing bugs, adding features, or improving documentation, your help is appreciated. - -## License - -πŸ“œ jqplay is licensed under the [MIT License](LICENSE). - ---- - -Happy querying! πŸš€ diff --git a/src/app/api/jq/route.ts b/src/app/api/jq/route.ts index e88b67e9..38795ba5 100644 --- a/src/app/api/jq/route.ts +++ b/src/app/api/jq/route.ts @@ -6,6 +6,6 @@ export async function GET(req: Request) { return new Response(result, { status: 200 }); } catch (e: any) { const errorMessage = e?.message || 'An unknown error occurred'; - return new Response(errorMessage, { status: 200 }); + return new Response(JSON.stringify({ error: errorMessage }), { status: 500 }); } } diff --git a/src/app/api/snippets/route.ts b/src/app/api/snippets/route.ts index feb0ca68..6a6e0963 100644 --- a/src/app/api/snippets/route.ts +++ b/src/app/api/snippets/route.ts @@ -18,6 +18,6 @@ export async function POST(req: Request) { if (error instanceof ZodError) { return NextResponse.json({ errors: error.errors }, { status: 422 }); } - return NextResponse.json({ error: 'Failed to save snippet' }, { status: 500 }); + return NextResponse.json({ error: error.message || 'Failed to save snippet' }, { status: 500 }); } } diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts index 330b2f1a..ea7d60c3 100644 --- a/src/lib/prisma.ts +++ b/src/lib/prisma.ts @@ -8,7 +8,7 @@ declare global { } // Use a single PrismaClient instance in development and production environments. -const prisma = global.prisma || new PrismaClient({ +const prisma: PrismaClient = global.prisma || new PrismaClient({ log: process.env.NODE_ENV === 'development' ? ['query', 'info', 'warn', 'error'] : ['warn', 'error'], }); @@ -18,7 +18,7 @@ if (process.env.NODE_ENV !== 'production') { export default prisma; -export async function GetSnippet(slug: string) { +export async function GetSnippet(slug: string): Promise { const whereClause = uuidValidateV4(slug) ? { id: slug } // If valid UUID v4, search by ID : { slug: slug }; // Otherwise, search by slug @@ -28,7 +28,7 @@ export async function GetSnippet(slug: string) { }); } -export async function UpsertSnippet(snippet: SnippetType) { +export async function UpsertSnippet(snippet: SnippetType): Promise { const slug = generateSlug(snippet); return prisma.snippets.upsert({ where: { slug }, @@ -75,6 +75,6 @@ function generateSlug(snippet: SnippetType, hashLen: number = 15): string { return base64Encoded.substring(0, hashLen); } -function uuidValidateV4(uuid: string) { +function uuidValidateV4(uuid: string): boolean { return uuidValidate(uuid) && uuidVersion(uuid) === 4; } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index efb544e3..daa985e8 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,10 +1,10 @@ import { ZodError } from "zod"; -export const currentUnixTimestamp = () => Math.floor(new Date().getTime() / 1000); +export const currentUnixTimestamp = (): number => Math.floor(new Date().getTime() / 1000); -export const generateMessageId = () => Math.random().toString(36).substring(2, 9); +export const generateMessageId = (): string => Math.random().toString(36).substring(2, 9); -export function normalizeLineBreaks(text: string | undefined | null) { +export function normalizeLineBreaks(text: string | undefined | null): string { if (!text) { return ''; } @@ -12,6 +12,6 @@ export function normalizeLineBreaks(text: string | undefined | null) { return text.replace(/\r\n|\r/g, '\n'); } -export function prettifyZodError(error: ZodError) { +export function prettifyZodError(error: ZodError): string { return error.errors.map(e => `${e.path.join(', ')} ${e.message}`.toLowerCase()).join(', '); }