Skip to content

Commit

Permalink
Feat: use fastify-schema-to-ts (#86)
Browse files Browse the repository at this point in the history
* feat: install local fastify schema to ts

* feat: use fastify schema to ts

* feat: install fastify schema to ts from npm
  • Loading branch information
raipen authored Nov 14, 2023
1 parent c007310 commit 0de523e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 33 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dotenv": "^16.3.1",
"fastify": "^4.19.1",
"fastify-plugin": "^4.5.0",
"fastify-schema-to-ts": "^1.0.1",
"json-schema-to-ts": "^2.9.2",
"jsonwebtoken": "^9.0.1"
},
Expand Down
26 changes: 0 additions & 26 deletions src/DTO/index.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,3 @@ export type ErrorInterface = FromSchema<{
toast: { type: 'string', enum: string[] }
}
}>;

export type SchemaToInterface<
T extends {
body?: JSONSchema;
querystring?: JSONSchema;
params?: JSONSchema;
headers?: JSONSchema;
response: { [key: string]: JSONSchema };
},
Option extends [{ pattern: unknown; output: unknown }] | false = false
> = {
Body: T['body'] extends JSONSchema ? FromSchema<T['body']> : unknown;
Querystring: T['querystring'] extends JSONSchema
? FromSchema<T['querystring']>
: unknown;
Params: T['params'] extends JSONSchema ? FromSchema<T['params']> : unknown;
Headers: T['headers'] extends JSONSchema
? FromSchema<T['headers']>
: unknown;
Reply: {
[key in keyof T['response']]: FromSchema<
T['response'][key],
{ deserialize: Option }
>;
};
};
2 changes: 1 addition & 1 deletion src/DTO/menu.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';

export const getMenuListSchema = {
tags: ['menu'],
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/mileage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Mileage as prismaMileage } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Mileage = prismaMileage;

export const getMileageSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/order.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Order as prismaOrder } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Order = prismaOrder;

export const newOrderSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/preOrder.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PreOrder as prismaPreOrder } from '@prisma/client';
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type PreOrder = prismaPreOrder;

export const newPreOrderSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/stock.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
StoreAuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';

export const createStockSchema = {
tags: ['stock'],
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/store.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Store as prismaStore } from '@prisma/client';
import {
AuthorizationHeader,
errorSchema,
SchemaToInterface,
StoreAuthorizationHeader,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type Store = prismaStore;

export const newStoreSchema = {
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { User as prismaUser } from '@prisma/client';
import {
AuthorizationHeader,
errorSchema,
SchemaToInterface,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';
export type User = prismaUser;

export const phoneSchema = {
Expand Down

0 comments on commit 0de523e

Please sign in to comment.