Skip to main content
Home
This package has been archived, and as such it is read-only.

Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, Bun, Browsers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads31/wk
Published2 months ago (0.3.1)

01Edu AI framework for Sqlite & Deno based app

Example

import type { RequestContext } from '@01edu/framework/context'
import { logger } from '@01edu/framework/log'
import { server } from '@01edu/framework/server'
import { NUM, STR } from '@01edu/framework/validator'
import { makeRouter, route } from '@01edu/framework/router'

// The session is anything you want, it's optional, defaults to undefined
type Session = {
  userId: number
}

const log = await logger({
  filters: new Set(['in', 'out']),
})

const activeSession = new Map<string, Session>()
const requireSession = (ctx: RequestContext): Session => {
  const session = activeSession.get(ctx.cookies.session)
  if (session) return session
  throw Error('user must have a session')
  // Throwing in the authorize session will return an Unauthorized response to the client
}

const routeHandler = makeRouter(log, {
  'GET/user': route({
    description: 'Return the id of the user of the current session',
    output: NUM('id of the current user'),
    input: STR('some text to print'),
    // Authorize method must return the session
    authorize: requireSession,
    fn: (ctx, name) => {
      console.log('name input:', { name }) // name is a string here
      return ctx.session.userId
    },
  }),
})

export default {
  fetch: server({ log, routeHandler }),
}
Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.