Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: crud task according to workflow #19

Merged
merged 5 commits into from
Sep 13, 2024

Conversation

jean-michelet
Copy link
Contributor

Issue #15

I created a task CRUD with workflow configuration.

Comment on lines +11 to +15
"start": "npm run build && fastify start -l info dist/app.js",
"build": "tsc",
"watch": "tsc -w",
"dev": "npm run build && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"npm:watch\" \"npm:dev:start\"",
"dev:start": "fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -10,6 +10,7 @@ export default async function serviceApp(
fastify: FastifyInstance,
opts: FastifyPluginOptions
) {
delete opts.skipOverride // This option only serves testing purpose
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I feared, I think we've introduced a problem here: https://github.com/fastify/fastify-cli/pull/742/files#r1689541348

For example, @fastify/mysql passes all the given options directly to mysql2, which triggers warnings from mysql2:

Ignoring invalid configuration option passed to Connection: skipOverride. This is currently a warning, but in future versions of MySQL2, an error
will be thrown if you pass an invalid configuration option to a Connection

Maybe it's also a bad design to propagate all the options in the autoloader? Like the cli generated template suggest to do:

export default async function serviceApp(
  fastify: FastifyInstance,
  opts: FastifyPluginOptions
) {
  await fastify.register(fastifyAutoload, {
      dir: path.join(import.meta.dirname, "plugins"),
      options: { ...opts } // opts propagated here
  });
  
  // code...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to say here, but you are right. Passing all default options that results into this error, is NOT good.

src/plugins/custom/workflow.ts Outdated Show resolved Hide resolved
src/schemas/tasks.ts Outdated Show resolved Hide resolved
@jean-michelet
Copy link
Contributor Author

@melroy89 👋

@melroy89
Copy link
Contributor

Sorry about my ignorance, but why do we need all those workflow code in a demo app? The CRUD code all seems fine to me. But what does all that workflow code do? Which has even an dependency outside this demo app with @jean-michelet/workflow.

Why not just keep the demo clean, and focus on the CRUD part only? Or do I miss something.

@jean-michelet
Copy link
Contributor Author

jean-michelet commented Aug 25, 2024

EDIT: component removed.

Sorry about my ignorance, but why do we need all those workflow code in a demo app?

The workflow (state machine) is something I used professionally when I was a PHP developer and I think it's a relevant way to handle the life cycle of an entity. I needed it to my job where we handle entities workflows. But I just realize that they are flaws in my implementation as currently tasks can be PATCHed without status verification, also right for deletion should be controlled (EDIT: I plan to handle this part with authorization and roles).

Which has even an dependency outside this demo app with @jean-michelet/workflow

Yes, this is my package, this is more like a POC, I can create an official fastify package for it so it is an official dependency.

But if you think it's inappropriate, too complex, I understand. Some tasks application have very free status transitions, some of them have strict rules. I tough it was an opportunity to add this feature and make discover a way of managing an entity's status.

I am gonna wait for other reactions, thanks for your review 🙏

src/schemas/tasks.ts Outdated Show resolved Hide resolved
@jean-michelet
Copy link
Contributor Author

@gurgunday @climba03003
Any feedback?

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the demo should follow some existing well defined schema.
For example https://petstore.swagger.io/
It shows authorization, linkage between entity, multipart handling, etc.

@jean-michelet
Copy link
Contributor Author

I can take inspiration from it, but maybe we can stick to a task application. I can complete this PR with users endpoints, I just wanted a feedback on a pure CRUD. Autorisation is for a next step.

@jean-michelet
Copy link
Contributor Author

TODO:

  • Add users endpoint

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jean-michelet
Copy link
Contributor Author

Can do Users on an other PR.

@@ -41,11 +41,6 @@ To build the project:
npm run build
```

In dev mode, you can use:
```bash
npm run watch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is watch not working or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work, but will people use it now that we run it concurrently with the dev server?

src/app.ts Outdated
customOptions: {
coerceTypes: "array",
removeAdditional: "all",
allErrors: true
Copy link
Member

@climba03003 climba03003 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should enable allErrors.
Given it widen the attack factors.

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that we should follow some existing example.
But since you are the companion of this repository, your motivation on continuing the work is more important.

The only concern is about the ajv.allErrors, others code LGTM.

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jean-michelet
Copy link
Contributor Author

I still think that we should follow some existing example.

Can you elaborate please ?

@jean-michelet jean-michelet merged commit 13e73b4 into fastify:main Sep 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants