npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

declarapi-runtime

v1.0.0

Published

Declarative API runtime

Downloads

50

Readme

License: MIT Latest version published Build Code coverage

declarapi-runtime

Runtime dependencies of declarapi

This package is being made to service declarapi, but will work without out.

Using it without the generated contracts is possible, but in that case the correctness of the contracts are not guaranteed.

This package provides all runtime functionality:

Validation the incoming and outgoing data to the specified schema

Using the yaschva validator, that provides descriptive error messages.

Catch all exceptions in the handlers and turn them into error messages

If the thrown object has a status, statusCode or code field, with a number in it that is between 400 and 599, it will be used as the response code.

Although, if there is an anticipated error, it's better to return a HandleErrorResponse object

Handle authorization

Role based access to the api endpoint is handled by the process-ed handle.

Record based access (that depends on the createdBy field), is handled by the data access layer. If a manual backend implementation is used, this must be taken care of in the custom implementation.

NOTICE

Authentication must be handled by your app, the user information must be provided to the runtime.

Provide a database communication layer

  • Elasticsearch
  • High level key-value store that is compatible with multiple backend solutions
    • In memory key value store (recommended only for development and testing)
    • Cloudflare workers KV via the HTTP API and from a worker via a custom switch
    • TODO - Redis

It is fully independent of the server

it does not relay on any nodejs functionality so it can run as a service worker (cloudflare workers serverless) and future plans contain making it Deno compatible.

It is fully independent of the communication method

it can be used with HTTP for a REST api, JSON-RPC, web sockets, etc. The handling methods return an object containing either the result of the operation or a descriptive error, along with the status code.

This is an ES6 module package

The default usage of this package are ES6 modules, although there is a commonjs included, under cjs folder, it is not very usable since it is using a package that is ES6 first. An import rewrite would be needed for cjs build to work correctly.

Testing

Aiming for 100% test coverage, since any uncovered code may be dead code. Without a test for that line, the author of the code may not have though it through, writing a test for it makes sure that the code is fully understood.

This project uses Ava for testing, with C8 for code coverage

Ava was chosen over other frameworks because it works with e6 modules without any transpilation (ie: it tests the code that will actually run in production) and that it has no magic, tests are just plain code. It makes it easy to reuse test code, with different backend providers, since they should all work the mostly the same. Ava also makes it easy to run each test multiple times, which can be very useful when testing with randomly generated data.

For integration type tests, that relay on a real database, the best course of action is to execute each test on a different database / index / prefix so there is absolutely no crosstalk between tests, and they can run in parallel to make test run much quicker.

If a test breaks in this repo, always look at the post backendPost.spec.ts first, since the other test relay on it's behavior to correctly execute.

Roadmap / plans / TODO

Roadmap / plans / TODO can be found in TODO.md