How to use the @marblejs/middleware-io.t.partial function in @marblejs/middleware-io

To help you get started, we’ve selected a few @marblejs/middleware-io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edbzn / reactive-blog / packages / server / src / utils / collection-query.validator.ts View on Github external
export const createQuery = (opts: CollectionQueryValidatorOpts) =>
  t.partial({
    sortBy: t.union(opts.sortBy.map(s => t.literal(s)) as any),
    sortDir: t.union([
      t.refinement(t.union([t.string, t.number]), n => Number(n) === SortDir.ASC, 'SortDir.ASC'),
      t.refinement(t.union([t.string, t.number]), n => Number(n) === SortDir.DESC, 'SortDir.DESC'),
    ]),
    limit: t.refinement(t.union([t.string, t.number]), n => Number(n) >= 0, 'number.0+'),
    page: t.refinement(t.union([t.string, t.number]), n => Number(n) >= 1, 'number.1+'),
  });