arocapi 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +277 -35
- package/dist/app.d.ts +9 -6
- package/dist/app.js +69 -17
- package/dist/app.js.map +1 -1
- package/dist/express.d.ts +3 -2
- package/dist/express.js +11 -11
- package/dist/express.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/routes/{entities/index.js → entities.js} +2 -2
- package/dist/routes/entities.js.map +1 -0
- package/dist/routes/{entity/index.js → entity.js} +2 -2
- package/dist/routes/entity.js.map +1 -0
- package/dist/routes/{search/index.js → search.js} +2 -2
- package/dist/routes/search.js.map +1 -0
- package/package.json +6 -4
- package/prisma/models/entity.prisma +17 -0
- package/prisma/schema.prisma +1 -20
- package/prisma.config.ts +1 -7
- package/src/app.ts +89 -31
- package/src/express.ts +12 -11
- package/src/index.ts +35 -0
- package/src/routes/{entities/index.ts → entities.ts} +2 -3
- package/src/routes/{entity/index.ts → entity.ts} +1 -1
- package/src/routes/{search/index.ts → search.ts} +1 -1
- package/dist/plugins/cors.d.ts +0 -3
- package/dist/plugins/cors.js +0 -6
- package/dist/plugins/cors.js.map +0 -1
- package/dist/plugins/opensearch.d.ts +0 -9
- package/dist/plugins/opensearch.js +0 -22
- package/dist/plugins/opensearch.js.map +0 -1
- package/dist/plugins/prisma.d.ts +0 -8
- package/dist/plugins/prisma.js +0 -11
- package/dist/plugins/prisma.js.map +0 -1
- package/dist/plugins/sensible.d.ts +0 -3
- package/dist/plugins/sensible.js +0 -6
- package/dist/plugins/sensible.js.map +0 -1
- package/dist/plugins/support.d.ts +0 -9
- package/dist/plugins/support.js +0 -5
- package/dist/plugins/support.js.map +0 -1
- package/dist/plugins/validation.d.ts +0 -3
- package/dist/plugins/validation.js +0 -32
- package/dist/plugins/validation.js.map +0 -1
- package/dist/routes/entities/index.js.map +0 -1
- package/dist/routes/entity/index.js.map +0 -1
- package/dist/routes/search/index.js.map +0 -1
- package/src/plugins/README.md +0 -16
- package/src/plugins/cors.ts +0 -11
- package/src/plugins/opensearch.ts +0 -32
- package/src/plugins/prisma.ts +0 -23
- package/src/plugins/sensible.ts +0 -11
- package/src/plugins/support.ts +0 -20
- package/src/plugins/validation.ts +0 -48
- package/src/routes/README.md +0 -29
- /package/dist/routes/{entities/index.d.ts → entities.d.ts} +0 -0
- /package/dist/routes/{entity/index.d.ts → entity.d.ts} +0 -0
- /package/dist/routes/{search/index.d.ts → search.d.ts} +0 -0
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import fp from 'fastify-plugin';
|
|
2
|
-
import {
|
|
3
|
-
type FastifyPluginAsyncZod,
|
|
4
|
-
hasZodFastifySchemaValidationErrors,
|
|
5
|
-
isResponseSerializationError,
|
|
6
|
-
serializerCompiler,
|
|
7
|
-
validatorCompiler,
|
|
8
|
-
} from 'fastify-type-provider-zod';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* This plugins allows us to validate parameters using zod
|
|
12
|
-
*
|
|
13
|
-
* @see https://github.com/turkerdev/fastify-type-provider-zod
|
|
14
|
-
*/
|
|
15
|
-
export default fp<FastifyPluginAsyncZod>(async (fastify) => {
|
|
16
|
-
fastify.setValidatorCompiler(validatorCompiler);
|
|
17
|
-
fastify.setSerializerCompiler(serializerCompiler);
|
|
18
|
-
|
|
19
|
-
fastify.setErrorHandler((err, req, reply) => {
|
|
20
|
-
if (hasZodFastifySchemaValidationErrors(err)) {
|
|
21
|
-
return reply.code(400).send({
|
|
22
|
-
error: 'Response Validation Error',
|
|
23
|
-
message: "Request doesn't match the schema",
|
|
24
|
-
details: {
|
|
25
|
-
issues: err.validation,
|
|
26
|
-
method: req.method,
|
|
27
|
-
url: req.url,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (isResponseSerializationError(err)) {
|
|
33
|
-
return reply.code(500).send({
|
|
34
|
-
error: 'Internal Server Error',
|
|
35
|
-
message: "Response doesn't match the schema",
|
|
36
|
-
details: {
|
|
37
|
-
issues: err.cause.issues,
|
|
38
|
-
method: err.method,
|
|
39
|
-
url: err.url,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// NOTE: We are exposing the error message here for development purposes.
|
|
45
|
-
// In production, consider hiding error details to avoid leaking sensitive information.
|
|
46
|
-
reply.status(500).send({ errors: [err.message] });
|
|
47
|
-
});
|
|
48
|
-
});
|
package/src/routes/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# Routes Folder
|
|
2
|
-
|
|
3
|
-
Routes define the pathways within your application.
|
|
4
|
-
Fastify's structure supports the modular monolith approach, where your
|
|
5
|
-
application is organized into distinct, self-contained modules.
|
|
6
|
-
This facilitates easier scaling and future transition to a microservice architecture.
|
|
7
|
-
In the future you might want to independently deploy some of those.
|
|
8
|
-
|
|
9
|
-
In this folder you should define all the routes that define the endpoints
|
|
10
|
-
of your web application.
|
|
11
|
-
Each service is a [Fastify
|
|
12
|
-
plugin](https://fastify.dev/docs/latest/Reference/Plugins/), it is
|
|
13
|
-
encapsulated (it can have its own independent plugins) and it is
|
|
14
|
-
typically stored in a file; be careful to group your routes logically,
|
|
15
|
-
e.g. all `/users` routes in a `users.js` file. We have added
|
|
16
|
-
a `root.js` file for you with a '/' root added.
|
|
17
|
-
|
|
18
|
-
If a single file becomes too large, create a folder and add a `index.js` file there:
|
|
19
|
-
this file must be a Fastify plugin, and it will be loaded automatically
|
|
20
|
-
by the application. You can now add as many files as you want inside that folder.
|
|
21
|
-
In this way you can create complex routes within a single monolith,
|
|
22
|
-
and eventually extract them.
|
|
23
|
-
|
|
24
|
-
If you need to share functionality between routes, place that
|
|
25
|
-
functionality into the `plugins` folder, and share it via
|
|
26
|
-
[decorators](https://fastify.dev/docs/latest/Reference/Decorators/).
|
|
27
|
-
|
|
28
|
-
If you're a bit confused about using `async/await` to write routes, you would
|
|
29
|
-
better take a look at [Promise resolution](https://fastify.dev/docs/latest/Reference/Routes/#promise-resolution) for more details.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|