Closed OrJDev closed 7 months ago
Regarding this solution, the hard part is finally done, i was able to make the plugin plugin transform this:
import { builder$ } from '@solid-mediakit/prpc'
export const helloBuilder = builder$()
.middleware$(() => {
console.log('middleware 1')
return {
hello: 1,
}
})
.middleware$((ctx) => {
console.log('middleware 2')
return {
...ctx,
world: 2,
}
})
.middleware$((ctx) => {
console.log('middleware 3')
return {
...ctx,
sdsdgsdg: 'sdg',
}
})
export const byeBuilder = builder$()
.middleware$(() => {
console.log('bye middleware das')
return {
bye: 1,
}
})
.middleware$(() => {
console.log('bye middleware das 2')
return {
hehe: 1,
}
})
into this:
import { callMiddleware$ } from "@solid-mediakit/prpc";
import { getRequestEvent } from "solid-js/web";
import { cache } from "@solidjs/router";
import { validateZod } from "@solid-mediakit/prpc";
import { builder$ } from '@solid-mediakit/prpc';
export const helloBuilder = builder$();
export const byeBuilder = builder$();
export const _$$helloBuilder_mws = [() => {
console.log('middleware 1');
return {
hello: 1
};
}, ctx => {
console.log('middleware 2');
return {
...ctx,
world: 2
};
}, ctx => {
console.log('middleware 3');
return {
...ctx,
sdsdgsdg: 'sdg'
};
}];
export const _$$byeBuilder_mws = [() => {
console.log('bye middleware das');
return {
bye: 1
};
}, () => {
console.log('bye middleware das 2');
return {
hehe: 1
};
}];
now i just need to implement it on the consumption
changes were pushed here: https://github.com/solidjs-community/mediakit/commit/19867296b662380d2aa032f8a9ddc272187fe368
I'm aware it leaks i only realized after publishing and I didn't want to revert, i already thought of a fix but its late here so i couldn't implement it, what we are going to do is instead of using the
callMw
from the builder we are going to he transforming the builder file asWell. So basicallyFile 1
File 2
Turn into
File 1
File 2
Basically this allows us to import the function directly and only run it on the server as expected