Skip to content

Commit

Permalink
Improve repository with various enhancements
Browse files Browse the repository at this point in the history
---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/owenthereal/jqplay?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
owenthereal committed Jan 20, 2025
1 parent edabd9a commit e72a172
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 72 deletions.
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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/<your-username>/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.
62 changes: 0 additions & 62 deletions README.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/api/jq/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion src/app/api/snippets/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
8 changes: 4 additions & 4 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});

Expand All @@ -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<SnippetType | null> {
const whereClause = uuidValidateV4(slug)
? { id: slug } // If valid UUID v4, search by ID
: { slug: slug }; // Otherwise, search by slug
Expand All @@ -28,7 +28,7 @@ export async function GetSnippet(slug: string) {
});
}

export async function UpsertSnippet(snippet: SnippetType) {
export async function UpsertSnippet(snippet: SnippetType): Promise<SnippetType> {
const slug = generateSlug(snippet);
return prisma.snippets.upsert({
where: { slug },
Expand Down Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 '';
}

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(', ');
}

0 comments on commit e72a172

Please sign in to comment.