Skip to content

Commit

Permalink
Merge pull request #50 from inbeta-group/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
bennobuilder authored Jul 10, 2024
2 parents 165238b + 4c9c5e4 commit 08777d5
Show file tree
Hide file tree
Showing 96 changed files with 2,945 additions and 346 deletions.
7 changes: 6 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"access": "public",
"baseBranch": "origin/main",
"updateInternalDependencies": "patch",
"ignore": ["basic", "counter"]
"ignore": [
"feature-form-react-basic",
"feature-state-react-counter",
"openapi-router-express-petstore",
"openapi-router-hono-petstore"
]
}
15 changes: 15 additions & 0 deletions .changeset/proud-mugs-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'google-webfonts-client': patch
'validation-adapters': patch
'validation-adapter': patch
'feature-logger': patch
'@ibg/openapi-router': patch
'feature-fetch': patch
'feature-state': patch
'figma-connect': patch
'feature-form': patch
'@ibg/types': patch
'@ibg/cli': patch
---

Updated README.md
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Brought to you by [dyn.art](https://github.com/dyn-art/monorepo). An open-source
| [validation-adapter](https://github.com/inbeta-group/monorepo/blob/develop/packages/validation-adapter) | Universal validation adapter that integrates various validation libraries like Zod, Valibot, and Yup | [`validation-adapter`](https://www.npmjs.com/package/validation-adapter) |
| [validation-adapters](https://github.com/inbeta-group/monorepo/blob/develop/packages/validation-adapters) | Pre-made validation adapters for the validation-adapter library, including adapters for Zod and Valibot | [`validation-adapters`](https://www.npmjs.com/package/validation-adapters) |

## 👀 Examples
### 📚 Examples

> See [`/examples`](https://github.com/inbeta-group/monorepo/tree/develop/examples)
Expand All @@ -43,3 +43,7 @@ Brought to you by [dyn.art](https://github.com/dyn-art/monorepo). An open-source
### `feature-form`
- [`feature-form/react/basic`](https://github.com/inbeta-group/monorepo/tree/develop/examples/feature-form/react/basic)

### `openapi-router`
- [`openapi-router/hono/petstore`](https://github.com/inbeta-group/monorepo/tree/develop/examples/openapi-router/hono/petstore)
- [`openapi-router/express/petstore`](https://github.com/inbeta-group/monorepo/tree/develop/examples/openapi-router/express/petstore)

2 changes: 1 addition & 1 deletion examples/feature-form/react/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "basic",
"name": "feature-form-react-basic",
"private": true,
"version": "0.0.2",
"type": "module",
Expand Down
24 changes: 12 additions & 12 deletions examples/feature-form/react/basic/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
bitwiseFlag,
createForm,
createValidationAdapter,
createValidator,
FormFieldReValidateMode,
FormFieldValidateMode,
TFormFieldValidationAdapter
TFormFieldValidator
} from 'feature-form';
import { useForm } from 'feature-react/form';
import { withGlobalBind } from 'feature-react/state';
Expand All @@ -15,8 +15,8 @@ import { randomHex, shortId } from '@ibg/utils';

import './App.css';

import { valibotAdapter } from 'validation-adapters/valibot';
import { zodAdapter } from 'validation-adapters/zod';
import { vValidator } from 'validation-adapters/valibot';
import { zValidator } from 'validation-adapters/zod';

import { StatusMessage } from './components';
import { isLightColor } from './utils';
Expand All @@ -35,7 +35,7 @@ type TFormData = {
};
};

const valibotNameValidator = valibotAdapter(
const valibotNameValidator = vValidator(
v.pipe(v.string(), v.minLength(2), v.maxLength(10), v.regex(/^([^0-9]*)$/))
);

Expand All @@ -44,8 +44,8 @@ const $form = withGlobalBind(
createForm<TFormData>({
fields: {
firstName: {
validationAdapter: valibotNameValidator.clone().append(
createValidationAdapter([
validator: valibotNameValidator.clone().append(
createValidator([
{
key: 'jeff',
validate: (cx) => {
Expand All @@ -62,11 +62,11 @@ const $form = withGlobalBind(
defaultValue: ''
},
lastName: {
validationAdapter: valibotNameValidator,
validator: valibotNameValidator,
defaultValue: ''
},
gender: {
validationAdapter: createValidationAdapter([
validator: createValidator([
{
key: 'gender',
validate: (cx) => {
Expand All @@ -78,15 +78,15 @@ const $form = withGlobalBind(
}
}
}
]) as TFormFieldValidationAdapter<TGender>,
]) as TFormFieldValidator<TGender>,
defaultValue: 'female'
},
email: {
validationAdapter: zodAdapter(z.string().email().max(30).min(1)),
validator: zValidator(z.string().email().max(30).min(1)),
defaultValue: ''
},
image: {
validationAdapter: createValidationAdapter([
validator: createValidator([
{
key: 'color',
validate: (cx) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/feature-state/react/counter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "counter",
"name": "feature-state-react-counter",
"private": true,
"version": "0.0.2",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/openapi-router/express/petstore/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "petstore",
"name": "openapi-router-express-petstore",
"version": "1.0.1",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ components:
type: string
xml:
name: '##default'
ServiceError:
AppError:
type: object
description: Error Response
properties:
Expand Down
2 changes: 1 addition & 1 deletion examples/openapi-router/express/petstore/src/gen/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export interface components {
* "additional_errors": []
* }
*/
ServiceError: {
AppError: {
/** @description Error code */
error_code?: string;
/** @description Error description */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type express from 'express';
import { ServiceError } from '@ibg/openapi-router';
import { AppError } from '@ibg/openapi-router';

import { type components } from '../gen/v1';

Expand All @@ -10,15 +10,15 @@ export function errorMiddleware(
_next: express.NextFunction
): void {
let statusCode = 500;
const jsonResponse: components['schemas']['ServiceError'] = {
const jsonResponse: components['schemas']['AppError'] = {
error_code: '#ERR_UNKNOWN',
error_description: null,
error_uri: null,
additional_errors: []
};

// Handle application-specific errors (instances of AppError)
if (err instanceof ServiceError) {
if (err instanceof AppError) {
statusCode = err.status;
jsonResponse.error_code = err.code;
jsonResponse.error_description = err.description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type express from 'express';
import { ServiceError } from '@ibg/openapi-router';
import { AppError } from '@ibg/openapi-router';

export function invalidPathMiddleware(
req: express.Request,
_res: express.Response,
next: express.NextFunction
): void {
next(
new ServiceError('#ERR_PATH_NOT_FOUND', 404, {
new AppError('#ERR_PATH_NOT_FOUND', 404, {
description: `The specified path '${req.path}' does not exist!`
})
);
Expand Down
16 changes: 14 additions & 2 deletions examples/openapi-router/express/petstore/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import { Router } from 'express';
import * as v from 'valibot';
import { valibotAdapter } from 'validation-adapters/valibot';
import { vValidator } from 'validation-adapters/valibot';
import { createExpressOpenApiRouter } from '@ibg/openapi-router';

import { type paths } from './gen/v1';
import { PetSchema } from './schemas';

export const router: Router = Router();
export const openApiRouter = createExpressOpenApiRouter<paths>(router);

openApiRouter.get('/pet/{petId}', {
pathAdapter: valibotAdapter(
pathValidator: vValidator(
v.object({
petId: v.number()
})
),
handler: (req, res) => {
const { petId } = req.params;

res.send({
name: 'Falko',
photoUrls: []
});
}
});

openApiRouter.post('/pet', {
bodyValidator: vValidator(PetSchema),
handler: (req, res) => {
const { name, photoUrls } = req.body;

res.send({ name, photoUrls });
}
});
20 changes: 20 additions & 0 deletions examples/openapi-router/express/petstore/src/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as v from 'valibot';

export const CategorySchema = v.object({
id: v.optional(v.number()),
name: v.optional(v.string())
});

export const TagSchema = v.object({
id: v.optional(v.number()),
name: v.optional(v.string())
});

export const PetSchema = v.object({
id: v.optional(v.number()),
name: v.string(),
category: v.optional(CategorySchema),
photoUrls: v.array(v.string()),
tags: v.optional(v.array(TagSchema)),
status: v.optional(v.picklist(['available', 'pending', 'sold']))
});
28 changes: 28 additions & 0 deletions examples/openapi-router/hono/petstore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# deps
node_modules/

# env
.env
.env.production

# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
8 changes: 8 additions & 0 deletions examples/openapi-router/hono/petstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```
npm install
npm run dev
```

```
open http://localhost:3000
```
19 changes: 19 additions & 0 deletions examples/openapi-router/hono/petstore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "openapi-router-hono-petstore",
"scripts": {
"dev": "tsx watch src/index.ts",
"gen:openapi": "npx openapi-typescript ./resources/openapi-v1.yaml -o ./src/gen/v1.ts"
},
"dependencies": {
"@ibg/openapi-router": "workspace:*",
"@hono/node-server": "^1.12.0",
"@hono/zod-validator": "^0.2.2",
"hono": "^4.4.12",
"validation-adapters": "workspace:*",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20.11.17",
"tsx": "^4.7.1"
}
}
Loading

0 comments on commit 08777d5

Please sign in to comment.