From 5f134b3d39c78e6c6809095bc4f21aeb2623c996 Mon Sep 17 00:00:00 2001 From: Mihir Jayavant Date: Tue, 3 Dec 2024 20:39:08 +0530 Subject: [PATCH 1/3] monorepo created --- deno.json | 20 +- deno.lock | 19 +- libs/server/LICENSE | 201 ++++++++++++++++++ libs/server/README.md | 5 + libs/server/deno.json | 21 ++ .../server/middlewares}/scalar.ts | 0 .../server/middlewares/swagger}/config.ts | 0 .../server/middlewares/swagger/swagger.ts | 0 .../server/middlewares/swagger}/ui.ts | 0 libs/server/mod.ts | 0 .../server/router}/request-handler.ts | 9 +- {src => libs/server/router}/rest-handler.ts | 3 +- {src => libs/server/router}/router.ts | 9 +- {src => libs/server}/server.ts | 11 +- {src => libs/server}/virtual-entity.ts | 0 libs/utils/LICENSE | 201 ++++++++++++++++++ libs/utils/README.md | 5 + libs/utils/deno.json | 17 ++ libs/utils/mod.ts | 8 + {src => libs/utils}/open-api/helpers.spec.ts | 0 {src => libs/utils}/open-api/helpers.ts | 2 +- {src => libs/utils}/open-api/open-api.ts | 4 +- .../utils/pagination}/cursor-pagination.ts | 0 .../core => libs/utils/pagination}/filters.ts | 0 .../pagination}/offset-pagination.spec.ts | 0 .../utils/pagination}/offset-pagination.ts | 0 {src/http => libs/utils/result}/methods.ts | 0 .../http => libs/utils/result}/result.spec.ts | 0 {src/http => libs/utils/result}/result.ts | 2 +- {src/core => libs/utils}/utility.types.ts | 0 src/index.ts | 6 - 31 files changed, 499 insertions(+), 44 deletions(-) create mode 100644 libs/server/LICENSE create mode 100644 libs/server/README.md create mode 100644 libs/server/deno.json rename {src/open-api => libs/server/middlewares}/scalar.ts (100%) rename {src/open-api => libs/server/middlewares/swagger}/config.ts (100%) rename src/open-api/renderer.ts => libs/server/middlewares/swagger/swagger.ts (100%) rename {src/open-api => libs/server/middlewares/swagger}/ui.ts (100%) create mode 100644 libs/server/mod.ts rename {src => libs/server/router}/request-handler.ts (84%) rename {src => libs/server/router}/rest-handler.ts (87%) rename {src => libs/server/router}/router.ts (92%) rename {src => libs/server}/server.ts (82%) rename {src => libs/server}/virtual-entity.ts (100%) create mode 100644 libs/utils/LICENSE create mode 100644 libs/utils/README.md create mode 100644 libs/utils/deno.json create mode 100644 libs/utils/mod.ts rename {src => libs/utils}/open-api/helpers.spec.ts (100%) rename {src => libs/utils}/open-api/helpers.ts (97%) rename {src => libs/utils}/open-api/open-api.ts (93%) rename {src/core => libs/utils/pagination}/cursor-pagination.ts (100%) rename {src/core => libs/utils/pagination}/filters.ts (100%) rename {src/core => libs/utils/pagination}/offset-pagination.spec.ts (100%) rename {src/core => libs/utils/pagination}/offset-pagination.ts (100%) rename {src/http => libs/utils/result}/methods.ts (100%) rename {src/http => libs/utils/result}/result.spec.ts (100%) rename {src/http => libs/utils/result}/result.ts (96%) rename {src/core => libs/utils}/utility.types.ts (100%) delete mode 100644 src/index.ts diff --git a/deno.json b/deno.json index 0f4b949..f9af76f 100644 --- a/deno.json +++ b/deno.json @@ -1,26 +1,10 @@ { - "name": "@serverx/server", - "version": "0.2.0", - "exports": "./src/index.ts", + "workspace": ["./libs/utils", "./libs/server"], "tasks": { "user-api": "deno run --allow-net --watch ./example/app.ts" }, - "publish": { - "include": [ - "LICENSE", - "README.md", - "src/**/*.ts" - ] - }, "imports": { - "@hono/hono": "jsr:@hono/hono@^4.6.5", "@std/assert": "jsr:@std/assert@^1.0.8", - "@std/testing": "jsr:@std/testing@^1.0.5", - "@zod/zod": "npm:zod@^3.23.8" - }, - "test": { - "include": [ - "src/**/*.spec.ts" - ] + "@std/testing": "jsr:@std/testing@^1.0.5" } } diff --git a/deno.lock b/deno.lock index 3daec73..955e0dc 100644 --- a/deno.lock +++ b/deno.lock @@ -4,6 +4,7 @@ "jsr:@hono/hono@^4.6.5": "4.6.10", "jsr:@std/assert@*": "1.0.6", "jsr:@std/assert@^1.0.8": "1.0.8", + "jsr:@std/async@^1.0.8": "1.0.9", "jsr:@std/data-structures@^1.0.4": "1.0.4", "jsr:@std/fs@^1.0.5": "1.0.5", "jsr:@std/internal@^1.0.4": "1.0.4", @@ -32,6 +33,9 @@ "jsr:@std/internal@^1.0.5" ] }, + "@std/async@1.0.9": { + "integrity": "c6472fd0623b3f3daae023cdf7ca5535e1b721dfbf376562c0c12b3fb4867f91" + }, "@std/data-structures@1.0.4": { "integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0" }, @@ -54,6 +58,7 @@ "integrity": "6e693cbec94c81a1ad3df668685c7ba8e20742bb10305bc7137faa5cf16d2ec4", "dependencies": [ "jsr:@std/assert@^1.0.8", + "jsr:@std/async", "jsr:@std/data-structures", "jsr:@std/fs", "jsr:@std/internal@^1.0.5", @@ -80,10 +85,16 @@ }, "workspace": { "dependencies": [ - "jsr:@hono/hono@^4.6.5", "jsr:@std/assert@^1.0.8", - "jsr:@std/testing@^1.0.5", - "npm:zod@^3.23.8" - ] + "jsr:@std/testing@^1.0.5" + ], + "members": { + "libs/server": { + "dependencies": [ + "jsr:@hono/hono@^4.6.5", + "npm:zod@^3.23.8" + ] + } + } } } diff --git a/libs/server/LICENSE b/libs/server/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/libs/server/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/libs/server/README.md b/libs/server/README.md new file mode 100644 index 0000000..b8abd07 --- /dev/null +++ b/libs/server/README.md @@ -0,0 +1,5 @@ +# ServerX Utils + +- Helper packages needed on day to day basis for creating apis + +### Work in progress diff --git a/libs/server/deno.json b/libs/server/deno.json new file mode 100644 index 0000000..4c33ef7 --- /dev/null +++ b/libs/server/deno.json @@ -0,0 +1,21 @@ +{ + "name": "@serverx/server", + "version": "0.3.0", + "exports": "./mod.ts", + "publish": { + "include": [ + "LICENSE", + "README.md", + "src/**/*.ts" + ] + }, + "imports": { + "@hono/hono": "jsr:@hono/hono@^4.6.5", + "@zod/zod": "npm:zod@^3.23.8" + }, + "test": { + "include": [ + "./**/*.spec.ts" + ] + } +} diff --git a/src/open-api/scalar.ts b/libs/server/middlewares/scalar.ts similarity index 100% rename from src/open-api/scalar.ts rename to libs/server/middlewares/scalar.ts diff --git a/src/open-api/config.ts b/libs/server/middlewares/swagger/config.ts similarity index 100% rename from src/open-api/config.ts rename to libs/server/middlewares/swagger/config.ts diff --git a/src/open-api/renderer.ts b/libs/server/middlewares/swagger/swagger.ts similarity index 100% rename from src/open-api/renderer.ts rename to libs/server/middlewares/swagger/swagger.ts diff --git a/src/open-api/ui.ts b/libs/server/middlewares/swagger/ui.ts similarity index 100% rename from src/open-api/ui.ts rename to libs/server/middlewares/swagger/ui.ts diff --git a/libs/server/mod.ts b/libs/server/mod.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/request-handler.ts b/libs/server/router/request-handler.ts similarity index 84% rename from src/request-handler.ts rename to libs/server/router/request-handler.ts index be5747c..a141dde 100644 --- a/src/request-handler.ts +++ b/libs/server/router/request-handler.ts @@ -1,5 +1,10 @@ -import type { JsonType, Task } from "./core/utility.types.ts"; -import { errorResult, type Result, statusCodes } from "./http/result.ts"; +import { + errorResult, + type JsonType, + type Result, + statusCodes, + type Task, +} from "@serverx/utils"; import type { AnyZodObject } from "@zod/zod"; export type RequestHandler = ( diff --git a/src/rest-handler.ts b/libs/server/router/rest-handler.ts similarity index 87% rename from src/rest-handler.ts rename to libs/server/router/rest-handler.ts index 62cb713..cf6fd35 100644 --- a/src/rest-handler.ts +++ b/libs/server/router/rest-handler.ts @@ -1,7 +1,6 @@ import type { Context } from "@hono/hono"; import type { RequestHandler } from "./request-handler.ts"; -import { isSuccess } from "./http/result.ts"; -import type { JsonType } from "./core/utility.types.ts"; +import { isSuccess, type JsonType } from "@serverx/utils"; import type { TypedResponse } from "@hono/hono"; type RestHandler = { diff --git a/src/router.ts b/libs/server/router/router.ts similarity index 92% rename from src/router.ts rename to libs/server/router/router.ts index b7d2c52..c8b19ba 100644 --- a/src/router.ts +++ b/libs/server/router/router.ts @@ -1,14 +1,15 @@ import { Hono } from "@hono/hono"; import type { Context, Next } from "@hono/hono"; -import type { HttpMethod } from "./http/methods.ts"; -import { type ApiDocs, OpenApi } from "./open-api/open-api.ts"; import type { + ApiDocs, + HttpMethod, JsonType, OptionalExcept, Prettify, + Result, Task, -} from "./core/utility.types.ts"; -import { isSuccess, type Result } from "./http/result.ts"; +} from "@serverx/utils"; +import { isSuccess, OpenApi } from "@serverx/utils"; type Config = { basePath?: string; diff --git a/src/server.ts b/libs/server/server.ts similarity index 82% rename from src/server.ts rename to libs/server/server.ts index 0a6f2d4..73cd85f 100644 --- a/src/server.ts +++ b/libs/server/server.ts @@ -1,9 +1,12 @@ import { Hono } from "@hono/hono"; import type { Context, Next } from "@hono/hono"; -import type { Router } from "./router.ts"; -import { swaggerUI } from "./open-api/ui.ts"; -import { OpenApi, type OpenApiUiOption } from "./open-api/open-api.ts"; -import { apiReference, type ApiReferenceOptions } from "./open-api/scalar.ts"; +import type { Router } from "./router/router.ts"; +import { swaggerUI } from "./middlewares/swagger/ui.ts"; +import { OpenApi, type OpenApiUiOption } from "@serverx/utils"; +import { + apiReference, + type ApiReferenceOptions, +} from "./middlewares/scalar.ts"; export class Server { #router = new Hono(); diff --git a/src/virtual-entity.ts b/libs/server/virtual-entity.ts similarity index 100% rename from src/virtual-entity.ts rename to libs/server/virtual-entity.ts diff --git a/libs/utils/LICENSE b/libs/utils/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/libs/utils/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/libs/utils/README.md b/libs/utils/README.md new file mode 100644 index 0000000..b8abd07 --- /dev/null +++ b/libs/utils/README.md @@ -0,0 +1,5 @@ +# ServerX Utils + +- Helper packages needed on day to day basis for creating apis + +### Work in progress diff --git a/libs/utils/deno.json b/libs/utils/deno.json new file mode 100644 index 0000000..4598ee1 --- /dev/null +++ b/libs/utils/deno.json @@ -0,0 +1,17 @@ +{ + "name": "@serverx/utils", + "version": "0.3.0", + "exports": "./mod.ts", + "publish": { + "include": [ + "LICENSE", + "README.md", + "src/**/*.ts" + ] + }, + "test": { + "include": [ + "./**/*.spec.ts" + ] + } +} diff --git a/libs/utils/mod.ts b/libs/utils/mod.ts new file mode 100644 index 0000000..86235d4 --- /dev/null +++ b/libs/utils/mod.ts @@ -0,0 +1,8 @@ +export * from "./utility.types.ts"; +export * from "./result/result.ts"; +export * from "./result/methods.ts"; +export * from "./pagination/filters.ts"; +export * from "./pagination/cursor-pagination.ts"; +export * from "./pagination/offset-pagination.ts"; +export * from "./open-api/helpers.ts"; +export * from "./open-api/open-api.ts"; diff --git a/src/open-api/helpers.spec.ts b/libs/utils/open-api/helpers.spec.ts similarity index 100% rename from src/open-api/helpers.spec.ts rename to libs/utils/open-api/helpers.spec.ts diff --git a/src/open-api/helpers.ts b/libs/utils/open-api/helpers.ts similarity index 97% rename from src/open-api/helpers.ts rename to libs/utils/open-api/helpers.ts index c7d40a3..39992b5 100644 --- a/src/open-api/helpers.ts +++ b/libs/utils/open-api/helpers.ts @@ -1,4 +1,4 @@ -import type { StatusCode } from "../http/result.ts"; +import type { StatusCode } from "../result/result.ts"; type PrimitiveType = "string" | "number" | "boolean"; diff --git a/src/open-api/open-api.ts b/libs/utils/open-api/open-api.ts similarity index 93% rename from src/open-api/open-api.ts rename to libs/utils/open-api/open-api.ts index f83e6a7..c63f889 100644 --- a/src/open-api/open-api.ts +++ b/libs/utils/open-api/open-api.ts @@ -1,5 +1,5 @@ -import type { OptionalExcept, Prettify } from "../core/utility.types.ts"; -import type { HttpMethod } from "../http/methods.ts"; +import type { OptionalExcept, Prettify } from "../utility.types.ts"; +import type { HttpMethod } from "../result/methods.ts"; export type ApiDocs = { path: string; diff --git a/src/core/cursor-pagination.ts b/libs/utils/pagination/cursor-pagination.ts similarity index 100% rename from src/core/cursor-pagination.ts rename to libs/utils/pagination/cursor-pagination.ts diff --git a/src/core/filters.ts b/libs/utils/pagination/filters.ts similarity index 100% rename from src/core/filters.ts rename to libs/utils/pagination/filters.ts diff --git a/src/core/offset-pagination.spec.ts b/libs/utils/pagination/offset-pagination.spec.ts similarity index 100% rename from src/core/offset-pagination.spec.ts rename to libs/utils/pagination/offset-pagination.spec.ts diff --git a/src/core/offset-pagination.ts b/libs/utils/pagination/offset-pagination.ts similarity index 100% rename from src/core/offset-pagination.ts rename to libs/utils/pagination/offset-pagination.ts diff --git a/src/http/methods.ts b/libs/utils/result/methods.ts similarity index 100% rename from src/http/methods.ts rename to libs/utils/result/methods.ts diff --git a/src/http/result.spec.ts b/libs/utils/result/result.spec.ts similarity index 100% rename from src/http/result.spec.ts rename to libs/utils/result/result.spec.ts diff --git a/src/http/result.ts b/libs/utils/result/result.ts similarity index 96% rename from src/http/result.ts rename to libs/utils/result/result.ts index 43d7b48..63da0ba 100644 --- a/src/http/result.ts +++ b/libs/utils/result/result.ts @@ -1,4 +1,4 @@ -import type { JsonType } from "../core/utility.types.ts"; +import type { JsonType } from "../utility.types.ts"; export const statusCodes = { Ok: 200, diff --git a/src/core/utility.types.ts b/libs/utils/utility.types.ts similarity index 100% rename from src/core/utility.types.ts rename to libs/utils/utility.types.ts diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index d9245bb..0000000 --- a/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from "./server.ts"; -export * from "./router.ts"; -export * from "./request-handler.ts"; -export * from "./rest-handler.ts"; -export * from "./virtual-entity.ts"; -export * from "./open-api/helpers.ts"; From 3dbff53f8bf5147c95e702578a3e6fed35c78517 Mon Sep 17 00:00:00 2001 From: Mihir Jayavant Date: Tue, 3 Dec 2024 22:26:29 +0530 Subject: [PATCH 2/3] mono repo done --- deno.json | 3 ++- deno.lock | 6 +++--- example/app.ts | 3 +-- example/profile/get-profile.action.ts | 8 ++------ example/profile/get-profile.handler.ts | 4 ++-- example/profile/get-profiles.action.ts | 4 +--- example/profile/post-profile.action.ts | 8 ++++---- example/profile/profile.ts | 2 +- libs/server/deno.json | 3 +-- libs/server/middlewares/cors.ts | 1 + libs/server/middlewares/swagger/ui.ts | 2 +- libs/server/mod.ts | 6 ++++++ 12 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 libs/server/middlewares/cors.ts diff --git a/deno.json b/deno.json index f9af76f..572fb7f 100644 --- a/deno.json +++ b/deno.json @@ -5,6 +5,7 @@ }, "imports": { "@std/assert": "jsr:@std/assert@^1.0.8", - "@std/testing": "jsr:@std/testing@^1.0.5" + "@std/testing": "jsr:@std/testing@^1.0.5", + "@zod/zod": "npm:zod@^3.23.8" } } diff --git a/deno.lock b/deno.lock index 955e0dc..3fd01d7 100644 --- a/deno.lock +++ b/deno.lock @@ -86,13 +86,13 @@ "workspace": { "dependencies": [ "jsr:@std/assert@^1.0.8", - "jsr:@std/testing@^1.0.5" + "jsr:@std/testing@^1.0.5", + "npm:zod@^3.23.8" ], "members": { "libs/server": { "dependencies": [ - "jsr:@hono/hono@^4.6.5", - "npm:zod@^3.23.8" + "jsr:@hono/hono@^4.6.5" ] } } diff --git a/example/app.ts b/example/app.ts index d91a305..0fd8539 100644 --- a/example/app.ts +++ b/example/app.ts @@ -1,6 +1,5 @@ -import { Server } from "../src/server.ts"; +import { cors, Server } from "@serverx/server"; import { profileRouter } from "./profile/profile.ts"; -import { cors } from "@hono/hono/cors"; const app = new Server(); diff --git a/example/profile/get-profile.action.ts b/example/profile/get-profile.action.ts index 213fea3..bd8f6f4 100644 --- a/example/profile/get-profile.action.ts +++ b/example/profile/get-profile.action.ts @@ -1,9 +1,5 @@ -import { httpMethods } from "../../src/http/methods.ts"; -import { - type ActionContext, - openApiParameter, - openApiResponse, -} from "../../src/index.ts"; +import { httpMethods, openApiParameter, openApiResponse } from "@serverx/utils"; +import { type ActionContext } from "@serverx/server"; import { getProfileHandler } from "./get-profile.handler.ts"; export const tags = ["user"]; diff --git a/example/profile/get-profile.handler.ts b/example/profile/get-profile.handler.ts index affb176..1d35e57 100644 --- a/example/profile/get-profile.handler.ts +++ b/example/profile/get-profile.handler.ts @@ -1,5 +1,5 @@ -import { errorResult, successResult } from "../../src/http/result.ts"; -import { baseHandler } from "../../src/index.ts"; +import { errorResult, successResult } from "@serverx/utils"; +import { baseHandler } from "@serverx/server"; import { z } from "@zod/zod"; type Input = { diff --git a/example/profile/get-profiles.action.ts b/example/profile/get-profiles.action.ts index 4dd6978..c512e2a 100644 --- a/example/profile/get-profiles.action.ts +++ b/example/profile/get-profiles.action.ts @@ -1,6 +1,4 @@ -import { httpMethods } from "../../src/http/methods.ts"; -import { successResult } from "../../src/http/result.ts"; -import { openApiResponse } from "../../src/index.ts"; +import { httpMethods, openApiResponse, successResult } from "@serverx/utils"; export const tags = ["user"]; export const path = "/"; diff --git a/example/profile/post-profile.action.ts b/example/profile/post-profile.action.ts index ea66b32..dad022d 100644 --- a/example/profile/post-profile.action.ts +++ b/example/profile/post-profile.action.ts @@ -1,10 +1,10 @@ -import { httpMethods } from "../../src/http/methods.ts"; -import { successResult } from "../../src/http/result.ts"; import { - type ActionContext, + httpMethods, openApiRequestBody, openApiResponse, -} from "../../src/index.ts"; + successResult, +} from "@serverx/utils"; +import { type ActionContext } from "@serverx/server"; export const tags = ["user"]; export const path = "/"; diff --git a/example/profile/profile.ts b/example/profile/profile.ts index 54f060e..875274f 100644 --- a/example/profile/profile.ts +++ b/example/profile/profile.ts @@ -1,4 +1,4 @@ -import { Router } from "../../src/router.ts"; +import { Router } from "@serverx/server"; import * as getProfiles from "./get-profiles.action.ts"; import * as getProfile from "./get-profile.action.ts"; import * as postPorfile from "./post-profile.action.ts"; diff --git a/libs/server/deno.json b/libs/server/deno.json index 4c33ef7..264b39c 100644 --- a/libs/server/deno.json +++ b/libs/server/deno.json @@ -10,8 +10,7 @@ ] }, "imports": { - "@hono/hono": "jsr:@hono/hono@^4.6.5", - "@zod/zod": "npm:zod@^3.23.8" + "@hono/hono": "jsr:@hono/hono@^4.6.5" }, "test": { "include": [ diff --git a/libs/server/middlewares/cors.ts b/libs/server/middlewares/cors.ts new file mode 100644 index 0000000..02620bc --- /dev/null +++ b/libs/server/middlewares/cors.ts @@ -0,0 +1 @@ +export { cors } from "@hono/hono/cors"; diff --git a/libs/server/middlewares/swagger/ui.ts b/libs/server/middlewares/swagger/ui.ts index 1dd76d5..29e46f1 100644 --- a/libs/server/middlewares/swagger/ui.ts +++ b/libs/server/middlewares/swagger/ui.ts @@ -3,7 +3,7 @@ import { html } from "@hono/hono/html"; import { type DistSwaggerUIOptions, renderSwaggerUIOptions, -} from "./renderer.ts"; +} from "./swagger.ts"; export type AssetURLs = { css: string[]; diff --git a/libs/server/mod.ts b/libs/server/mod.ts index e69de29..ee2d899 100644 --- a/libs/server/mod.ts +++ b/libs/server/mod.ts @@ -0,0 +1,6 @@ +export * from "./server.ts"; +export * from "./virtual-entity.ts"; +export * from "./middlewares/cors.ts"; +export * from "./router/router.ts"; +export * from "./router/rest-handler.ts"; +export * from "./router/request-handler.ts"; From fd0cbc19fa1ae8f6f35b65bc73b4901f8a913a1f Mon Sep 17 00:00:00 2001 From: Mihir Jayavant Date: Tue, 3 Dec 2024 23:00:51 +0530 Subject: [PATCH 3/3] publish fix --- libs/server/deno.json | 2 +- libs/utils/deno.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/server/deno.json b/libs/server/deno.json index 264b39c..4ab2469 100644 --- a/libs/server/deno.json +++ b/libs/server/deno.json @@ -6,7 +6,7 @@ "include": [ "LICENSE", "README.md", - "src/**/*.ts" + "./**/*.ts" ] }, "imports": { diff --git a/libs/utils/deno.json b/libs/utils/deno.json index 4598ee1..6ee207a 100644 --- a/libs/utils/deno.json +++ b/libs/utils/deno.json @@ -6,7 +6,7 @@ "include": [ "LICENSE", "README.md", - "src/**/*.ts" + "./**/*.ts" ] }, "test": {