Skip to content

Commit

Permalink
Added /runtime-safe export to all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
NuroDev committed Feb 24, 2024
1 parent d87f87e commit d0dc0e5
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
"exports": {
".": "./dist/index",
"./package.json": "./package.json",
"./runtime-safe": "./dist/runtime-safe",
"./types": "./dist/types",
"./zod": "./dist/zod"
},
"typesVersions": {
"*": {
"runtime-safe": [
"./dist/runtime-safe.d.ts"
],
"types": [
"./dist/types.d.ts"
],
Expand Down
34 changes: 34 additions & 0 deletions packages/hackernews/src/runtimeSafe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { initUntypeable } from "untypeable";

import { ItemSchema, ItemParamsSchema } from "./items/items.validators";
import {
AskStoriesSchema,
BestStoriesSchema,
JobStoriesSchema,
LiveDataParamsSchema,
MaxItemIdSchema,
NewStoriesSchema,
ShowStoriesSchema,
TopStoriesSchema,
UpdatesSchema,
} from "./liveData/liveData.validators";
import { UserSchema, UserParamsSchema } from "./users/users.validators";

const u = initUntypeable();

export const hackerNewsSafeRouter = u.router({
"/v0/askstories.json": u.input(LiveDataParamsSchema).output(AskStoriesSchema),
"/v0/beststories.json": u
.input(LiveDataParamsSchema)
.output(BestStoriesSchema),
"/v0/item/:id.json": u.input(ItemParamsSchema).output(ItemSchema),
"/v0/jobstories.json": u.input(LiveDataParamsSchema).output(JobStoriesSchema),
"/v0/maxitem.json": u.input(LiveDataParamsSchema).output(MaxItemIdSchema),
"/v0/newstories.json": u.input(LiveDataParamsSchema).output(NewStoriesSchema),
"/v0/showstories.json": u
.input(LiveDataParamsSchema)
.output(ShowStoriesSchema),
"/v0/topstories.json": u.input(LiveDataParamsSchema).output(TopStoriesSchema),
"/v0/updates.json": u.input(LiveDataParamsSchema).output(UpdatesSchema),
"/v0/user/:id.json": u.input(UserParamsSchema).output(UserSchema),
});
1 change: 1 addition & 0 deletions packages/hackernews/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ watch = false }) => ({
},
entry: {
index: "src/index.ts",
"runtime-safe": "src/runtimeSafe.ts",
types: "src/types.ts",
zod: "src/zod.ts",
},
Expand Down
4 changes: 4 additions & 0 deletions packages/jsonplaceholder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
"exports": {
".": "./dist/index",
"./package.json": "./package.json",
"./runtime-safe": "./dist/runtime-safe",
"./types": "./dist/types",
"./zod": "./dist/zod"
},
"typesVersions": {
"*": {
"runtime-safe": [
"./dist/runtime-safe.d.ts"
],
"types": [
"./dist/types.d.ts"
],
Expand Down
129 changes: 129 additions & 0 deletions packages/jsonplaceholder/src/runtimeSafe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { initUntypeable } from "untypeable";

import {
AlbumSchema,
AlbumParamsSchema,
AlbumsSchema,
AlbumsParamsSchema,
CreatedAlbumSchema,
CreatedAlbumParamsSchema,
} from "./album/album.validators";
import {
CommentSchema,
CommentParamsSchema,
CommentsSchema,
CommentsParamsSchema,
CreatedCommentSchema,
CreatedCommentParamsSchema,
} from "./comment/comment.validators";
import {
CreatedPhotoSchema,
CreatedPhotoParamsSchema,
PhotoSchema,
PhotoParamsSchema,
PhotosSchema,
PhotosParamsSchema,
} from "./photo/photo.validators";
import {
CreatedPostSchema,
CreatedPostParamsSchema,
PostSchema,
PostParamsSchema,
PostsSchema,
PostsParamsSchema,
} from "./post/post.validators";
import {
CreatedTodoSchema,
CreatedTodoParamsSchema,
TodoSchema,
TodoParamsSchema,
TodosSchema,
TodosParamsSchema,
} from "./todo/todo.validators";
import {
CreatedUserSchema,
CreatedUserParamsSchema,
UserSchema,
UserParamsSchema,
UsersSchema,
UsersParamsSchema,
} from "./user/user.validators";

const u = initUntypeable();

const allResources = u.pushArg<"GET" | "POST">();
const allResourcesRouter = allResources.router({
"/albums": {
GET: allResources.input(AlbumsParamsSchema).output(AlbumsSchema),
POST: allResources
.input(CreatedAlbumParamsSchema)
.output(CreatedAlbumSchema),
},
"/comments": {
GET: allResources.input(CommentsParamsSchema).output(CommentsSchema),
POST: allResources
.input(CreatedCommentParamsSchema)
.output(CreatedCommentSchema),
},
"/photos": {
GET: allResources.input(PhotosParamsSchema).output(PhotosSchema),
POST: allResources
.input(CreatedPhotoParamsSchema)
.output(CreatedPhotoSchema),
},
"/posts": {
GET: allResources.input(PostsParamsSchema).output(PostsSchema),
POST: allResources.input(CreatedPostParamsSchema).output(CreatedPostSchema),
},
"/todos": {
GET: allResources.input(TodosParamsSchema).output(TodosSchema),
POST: allResources.input(CreatedTodoParamsSchema).output(CreatedTodoSchema),
},
"/users": {
GET: allResources.input(UsersParamsSchema).output(UsersSchema),
POST: allResources.input(CreatedUserParamsSchema).output(CreatedUserSchema),
},
});

const singleResource = u.pushArg<"GET" | "PUT" | "PATCH" | "DELETE">();
const singleResourceRouter = singleResource.router({
"/albums/:id": {
GET: singleResource.input(AlbumParamsSchema).output(AlbumSchema),
},
"/albums/:id/comments": {
GET: singleResource.input(AlbumParamsSchema).output(CommentsSchema),
},
"/comments/:id": {
GET: singleResource.input(CommentParamsSchema).output(CommentSchema),
},
"/comments/:id/comments": {
GET: singleResource.input(CommentParamsSchema).output(CommentsSchema),
},
"/photos/:id": {
GET: singleResource.input(PhotoParamsSchema).output(PhotoSchema),
},
"/photos/:id/comments": {
GET: singleResource.input(PhotoParamsSchema).output(CommentsSchema),
},
"/posts/:id": {
GET: singleResource.input(PostParamsSchema).output(PostSchema),
},
"/posts/:id/comments": {
GET: singleResource.input(PostParamsSchema).output(CommentsSchema),
},
"/todos/:id": {
GET: singleResource.input(TodoParamsSchema).output(TodoSchema),
},
"/todos/:id/comments": {
GET: singleResource.input(TodoParamsSchema).output(CommentsSchema),
},
"/users/:id": {
GET: singleResource.input(UserParamsSchema).output(UserSchema),
},
"/users/:id/comments": {
GET: singleResource.input(UserParamsSchema).output(CommentsSchema),
},
});

export const jsonPlaceholderSafeRouter =
allResourcesRouter.merge(singleResourceRouter);
1 change: 1 addition & 0 deletions packages/jsonplaceholder/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ watch = false }) => ({
},
entry: {
index: "src/index.ts",
"runtime-safe": "src/runtimeSafe.ts",
types: "src/types.ts",
zod: "src/zod.ts",
},
Expand Down
4 changes: 4 additions & 0 deletions packages/lil.apis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
"exports": {
".": "./dist/index",
"./package.json": "./package.json",
"./runtime-safe": "./dist/runtime-safe",
"./types": "./dist/types",
"./zod": "./dist/zod"
},
"typesVersions": {
"*": {
"runtime-safe": [
"./dist/runtime-safe.d.ts"
],
"types": [
"./dist/types.d.ts"
],
Expand Down
16 changes: 16 additions & 0 deletions packages/lil.apis/src/runtimeSafe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { initUntypeable } from "untypeable";

import { NewsSchema } from "./news/news.validators";
import { StockSchema, StocksParamsSchema } from "./stocks/stocks.validators";
import {
WeatherSchema,
WeatherParamsSchema,
} from "./weather/weather.validators";

const u = initUntypeable();

export const lilSafeRouter = u.router({
"/news": u.output(NewsSchema),
"/stocks": u.input(StocksParamsSchema).output(StockSchema),
"/weather": u.input(WeatherParamsSchema).output(WeatherSchema),
});
1 change: 1 addition & 0 deletions packages/lil.apis/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ watch = false }) => ({
},
entry: {
index: "src/index.ts",
"runtime-safe": "src/runtimeSafe.ts",
types: "src/types.ts",
zod: "src/zod.ts",
},
Expand Down
4 changes: 4 additions & 0 deletions packages/logsnag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
"exports": {
".": "./dist/index",
"./package.json": "./package.json",
"./runtime-safe": "./dist/runtime-safe",
"./types": "./dist/types",
"./zod": "./dist/zod"
},
"typesVersions": {
"*": {
"runtime-safe": [
"./dist/runtime-safe.d.ts"
],
"types": [
"./dist/types.d.ts"
],
Expand Down
11 changes: 11 additions & 0 deletions packages/logsnag/src/runtimeSafe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { initUntypeable } from "untypeable";

import { InsightSchema } from "./insight/insight.validators";
import { LogSchema } from "./log/log.validators";

const u = initUntypeable();

export const logSnagSafeRouter = u.router({
"/insight": u.input(InsightSchema).output(InsightSchema),
"/log": u.input(LogSchema).output(LogSchema),
});
1 change: 1 addition & 0 deletions packages/logsnag/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ watch = false }) => ({
},
entry: {
index: "src/index.ts",
"runtime-safe": "src/runtimeSafe.ts",
types: "src/types.ts",
zod: "src/zod.ts",
},
Expand Down
4 changes: 4 additions & 0 deletions packages/spacex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
"exports": {
".": "./dist/index",
"./package.json": "./package.json",
"./runtime-safe": "./dist/runtime-safe",
"./types": "./dist/types",
"./zod": "./dist/zod"
},
"typesVersions": {
"*": {
"runtime-safe": [
"./dist/runtime-safe.d.ts"
],
"types": [
"./dist/types.d.ts"
],
Expand Down
Loading

0 comments on commit d0dc0e5

Please sign in to comment.