@enhance/core

0.0.2-RC.0 • Public • Published

[!WARNING]
This work is in progress!

WIP: @enhance/app-core "Core"

goals

mainly:

Create an intermediary library between @enhance/arc-plugin-enhance and @enhance/ssr

  • scope: create router from pre-loaded routes Map. marshall pre-defined element functions. return a method routeAndRender() that does:
    • req → { route, execute api, render template, return } → result
  • Agnostic to Architect (mostly - see below about i/o)
    • this library doesn't consider many Arc things or Arc-specific parts of arc-plugin-enhance.
  • more easily tested
  • adaptable to other Node.js servers - even other runtimes like Deno and the browser
    • there are no Node.js dependencies in this library

also...

  • use @architect/function#http-style input and output
    • adapters could be used to convert to/from other formats like native IncomingMessage and ServerResponse - the advantag here is that implementation is above Core
  • outsource routing to external dep (not a hard requirement, but many benefits)
    • will require some adapting to fit Enhance path param API
  • don't swallow user-land exceptions
    • the Core consumer can handle errors as it sees fit
  • Core router doesn't render errors, just throws
    • only throws on missing or incomplete route: err.message is "404"
    • if user-land code throws, log the exception and throw
  • don't search for head file - but allow it to be provided
  • don't load state for api fn (so no preflight)
    • but allow additional state at request-time for routeAndRender()
    • also allow initial router state to be provided
  • expose decent type defs for configuration and returned values

notes

  • the main method is routeAndRender(), but render() is also very helpful
    • and elements override in render() could be a perf vector
  • the radix3 router (currently implemented) is a good router candidate
    • it will never be a bottleneck
    • but it uses : to denote params, Enhance uses $

next

  • [ ] fix session and state passing
  • [x] handle path params
  • [ ] add middleware considerations
  • [x] expand options/config to allow pre-loaded routes, handlers, pages, and elements
  • [x] swap linter config
  • [x] drop into existing arc-plugin-enhance as sidecar, run tests

samples

check out the smoke-test for a few examples of how to use this library

Readme

Keywords

none

Package Sidebar

Install

npm i @enhance/core

Weekly Downloads

28

Version

0.0.2-RC.0

License

none

Unpacked Size

3.2 kB

Total Files

2

Last publish

Collaborators

  • colepeters
  • ryanbethel
  • brianleroux
  • tbeseda
  • macdonst
  • ryanblock
  • dam