Skip to content

Commit

Permalink
refactor-to-align-with-solid-js
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Mar 10, 2024
1 parent b454256 commit 057e88b
Show file tree
Hide file tree
Showing 62 changed files with 7,704 additions and 9,663 deletions.
60 changes: 60 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module.exports = {
env: {
browser: true,
es2020: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:tailwindcss/recommended',
],
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'react'],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'linebreak-style': ['error', 'unix'],
'no-constant-condition': ['error', { checkLoops: false }],
quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'always'],
'@typescript-eslint/consistent-type-imports': 'error',
'no-param-reassign': 'error',
'no-var': 'error',
'prefer-const': 'error',
},
settings: {
'import/resolver': {
node: {
extensions: ['.cjs', '.d.ts', '.js', '.jsx', '.mjs', '.ts', '.tsx'],
},
},
react: {
version: 'detect',
},
},
};
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '16'
- run: npm install
- run: npm run build
- run: TZ=Europe/Zurich npm test -- run --coverage
- run: npm install -g pnpm@latest
- run: pnpm install
- run: pnpm run build
- run: TZ=Europe/Zurich pnpm test -- --coverage
node18:
name: Node 18
runs-on: ubuntu-22.04
Expand All @@ -32,9 +33,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm install
- run: npm run build
- run: TZ=Europe/Zurich npm test -- run --coverage
- run: npm install -g pnpm@latest
- run: pnpm install
- run: pnpm run build
- run: TZ=Europe/Zurich pnpm test -- --coverage
node20:
name: Node 20
runs-on: ubuntu-22.04
Expand All @@ -45,9 +47,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install
- run: npm run build
- run: TZ=Europe/Zurich npm test -- run --coverage
- run: npm install -g pnpm@latest
- run: pnpm install
- run: pnpm run build
- run: TZ=Europe/Zurich pnpm test -- --coverage
- name: coveralls.io
uses: coverallsapp/github-action@master
with:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-petstore

[![CI](https://github.com/chubbyts/react-petstore/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/react-petstore/actions?query=workflow%3ACI)
[![CI](https://github.com/chubbyts/react-petstore/actions/workflows/ci.yml/badge.svg)](https://github.com/chubbyts/react-petstore/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/chubbyts/react-petstore/badge.svg?branch=master)](https://coveralls.io/github/chubbyts/react-petstore?branch=master)

[![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_react-petstore&metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyts_react-petstore)
Expand All @@ -17,23 +17,23 @@

## Description

This is a react frontend for the petstore skeleton.
This is a reactjs frontend for the petstore skeleton.

## Scripts

### Compiles and hot-reloads for development
```
npm start
pnpm start
```

### Compiles and minifies for production
```
npm run build
pnpm build
```

### Run your unit tests
```
npm test
pnpm test
```

## Copyright
Expand Down
23 changes: 10 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Petstore</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Petstore</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
63 changes: 63 additions & 0 deletions model/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { z } from 'zod';

export const numberSchema = z.union([
z
.string()
.refine((number) => !Number.isNaN(parseInt(number, 10)))
.transform((number) => parseInt(number, 10)),
z.number(),
]);

export const sortSchema = z.union([z.literal('asc'), z.literal('desc')]);

const linkSchema = z.object({
href: z.string(),
});

export const modelRequestSchema = z.object({}).strict();

export type ModelRequest = z.infer<typeof modelRequestSchema>;

export const modelResponseSchema = z
.object({
id: z.string(),
createdAt: z.string(),
updatedAt: z.string().nullish(),
_links: z
.object({
read: linkSchema.nullish(),
update: linkSchema.nullish(),
delete: linkSchema.nullish(),
})
.strict(),
})
.strict();

export type ModelResponse = z.infer<typeof modelResponseSchema>;

export const modelListRequestSchema = z
.object({
offset: numberSchema.optional(),
limit: numberSchema.optional(),
filters: z.object({}).strict().optional(),
sort: z.object({}).strict().optional(),
})
.strict();

export type ModelListRequest = z.infer<typeof modelListRequestSchema>;

export const modelListResponseSchema = z
.object({
offset: numberSchema,
limit: numberSchema,
filters: z.object({}).strict(),
sort: z.object({}).strict(),
count: numberSchema,
items: z.array(modelResponseSchema),
_links: z.object({
create: linkSchema.nullish(),
}),
})
.strict();

export type ModelListResponse = z.infer<typeof modelListResponseSchema>;
57 changes: 57 additions & 0 deletions model/pet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { z } from 'zod';
import {
modelRequestSchema,
modelResponseSchema,
modelListRequestSchema,
sortSchema,
modelListResponseSchema,
} from './model';

export const petRequestSchema = z.object({
...modelRequestSchema.shape,
name: z.string(),
tag: z.string().nullish(),
vaccinations: z.array(
z.object({
name: z.string(),
}),
),
});

export type PetRequest = z.infer<typeof petRequestSchema>;

export const petResponseSchema = z.object({
...modelResponseSchema.shape,
...petRequestSchema.shape,
});

export type PetResponse = z.infer<typeof petResponseSchema>;

export const petFiltersSchema = z.object({
name: z.string().nullish(),
});

export type PetFilters = z.infer<typeof petFiltersSchema>;

export const petSortSchema = z.object({
name: sortSchema.nullish(),
});

export type PetSort = z.infer<typeof petSortSchema>;

export const petListRequestSchema = z.object({
...modelListRequestSchema.shape,
filters: petFiltersSchema.optional(),
sort: petSortSchema.optional(),
});

export type PetListRequest = z.infer<typeof petListRequestSchema>;

export const petListResponseSchema = z.object({
...modelListResponseSchema.shape,
filters: petFiltersSchema,
sort: petSortSchema,
items: z.array(petResponseSchema),
});

export type PetListResponse = z.infer<typeof petListResponseSchema>;
Loading

0 comments on commit 057e88b

Please sign in to comment.