#How to create a plugin system and decaroaters

11 messages · Page 1 of 1 (latest)

placid gazelle
#

Hello I want to make a plugin system and decerators like how the fastify framework does but I cant get types working for the decerators and the overall system for plugins to work.
some docs about how it works in fastify
https://fastify.dev/docs/latest/Reference/Plugins/
and then the system in typescript for plugins
https://fastify.dev/docs/latest/Reference/TypeScript#plugins

you will see how the plugins can add vars, class, functions, objects, etc to the main instance of the program using fastify.decorate("name", thing) and then they add the type

if someone can help me code a system like this i would be super happy

placid gazelle
#

!helper

rain matrix
#

Put rather bluntly but with no intention to offend: As it is, your question will probably not be answered, as it is far too vague. You could as well be asking "please help me develop my software", which people don't have time for.

placid gazelle
#

@rain matrix so I have my base object we can call myPackage and I want to make a system where you can register plugins to add functionality and interact with the bare object like add functions like myPackage.registeredfunctionfromplugin() but I don’t know how to add the types from the plugin into the base object

carmine gale
#

This sounds fairly close to what I'm attempting to do here ->

wind eagleBOT
#
didyouknowthis#0

Preview:```ts
export type StoreOptions<
S,
A extends Record<string, (...args: any[]) => any>,
G

= {
state: () => S
actions: {
[K in keyof A]: (
state: S,
...args: Parameters<A[K]>
) => any
}
getters: {[K in keyof G]: (state: S) => G[K]}
}

export type Store<
S,
A extends Record<string, (...args: any[]) => any>,
G

= S & {
[K
...```

carmine gale
#

You're defining a "package" then trying to add new properties onto it, that can be called, and have access to the package instance.

placid gazelle
carmine gale
#

Yes, take a look at the getters for example in the playground I shared.

placid gazelle
#

So how would I get that to work as a plugin system