hideEvent

API for the hideEvent function

This function will be used to remove the event$ object from the context passed to a function.

Usage

import { hideEvent, middleware$, pipe$, query$ } from '@solid-mediakit/prpc'
import { z } from 'zod'

const myMiddleware1 = middleware$(({ event$ }) => {
  console.log('ua', event$.request.headers.get('user-agent'))
  return { test: null }
})

const middleWare2 = pipe$(myMiddleware1, (ctx) => {
  return {
    test: ctx.test,
    o: 1,
  }
})

const middleware3 = pipe$(middleWare2, (ctx) => {
  return {
    ...ctx,
    b: 2,
  }
})

export const add = query$({
  queryFn: ({ payload, ctx$ }) => {
    console.log({ ctx$: hideEvent(ctx$) })
    const result = payload.a + payload.b
    return { result }
  },
  key: 'add',
  schema: z.object({
    a: z.number().max(5),
    b: z.number().max(10),
  }),
  middleware: middleware3,
})

Parameters

hideEvent also takes in a second argument - fully, setting this to true will use the delete op to remove the event$ from the context, so you can use this a bit differently:

export const add = query$({
  queryFn: ({ payload, ctx$ }) => {
    hideEvent(ctx$, true)
    console.log({ ctx$ })
    const result = payload.a + payload.b
    return { result }
  },
  key: 'add',
  schema: z.object({
    a: z.number().max(5),
    b: z.number().max(10),
  }),
  middleware: middleware3,
})