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

adrians-typescript-api-standard

v0.0.4

Published

Its is an attempt to define some universal solution for keeping synchronised API of SPA frontend and Node backend. The plan is to support: simple JSON exchanges, files upload solution, WebSocket solution

Downloads

3

Readme

adrians-typescript-api-standard (very early version) WORK IN PROGRESS TO ACHIVE MVP

The problem

Having any API seems in the usual case a heavy load for developers to maintain it, in worse cases it is so bad that developers are afraid to refactor it, or change it. Usually it has heavy testing on both sides of the communication, still not eliminating all bugs and temporal time-downs. Seeing the problems during years of professional experience, seeing lots of money burned because of it, brings to me many ideas how to fix it, this is implementation of one of those ideas.

Idea

The idea is to have a common code base for both sides of API communications. It is impossible to have it in any case, but for many cases it could be possible.

What is should solve

  • expensive API changes
  • bugs related to path typos
  • bugs related to DTO out-of-sync or typos in its keys
  • bugs related to different validation of the DTO's
  • clean-code contribution
  • all exchanges should be easily visible in the browser 'Network' dev-tool
  • HTTP errors code should be not confusing any more (there are many different and contrary opinions when to use what), and the service may return eather a valid response, or an error as string in every case
  • HTTP methods should be not cnfusing any more (there are many different and contrary opinions when to use what), as all the exchanges should use always PUT method
  • renaming/refactoring/moving a DTO entry key, should be automatically done by IDE on both sides of the communication, due to strong typing and common code base
  • simple request validation errors could be immediately detected by the customer, without sending the request
  • simple response validation errors could be immediately detected by the service, without sending the response

Cases

  • standard JSON exchanges, cusomer sends JSON/void as request body, service responds with JSON/void
  • files transfers, file names should be UUID so nobody should be able to guess it, then the name should be stored/handled by JSON exchange
  • WebSockets, for events triggered by service, although it does not seems clear and simple

Limitations

  • it is only limited to TypeScript so practically it means any modern WEB browser frontend with some SPA, does not matter if it is Angular, React or Vue, and some Node backend, or serverless Node functions. It does not work directly with Java, Go, Ruby, Phyton, although with some Node middleware it should work, but then the whole idea is broken, as there would be next API that will be again very expensive.
  • both sides of the communications spruce code have to be in one file-system, to be able to reference the common code. Usually they are anyway in one repository, and this is perfect
  • it can not solve problems with many things: badly qualified developers, or managers, or micromanagement, or if one of the side of the communication uses other language than typescript
  • it should not be used directly with JS, although it is possible, because then the whole sense is broken, and the typing checks will be anyway useless
  • echanges key names should not contain special characters, in worse case iti would contain '.' that is used to join nested objects

Intendent use

  • Install it:
npm i adrians-typescript-api-standard
  • define common code with JsonExchanges, TDD all processing functions
  • create the agent on the customer side, take care of the auth data and backend prefix. the same origin is advised due to possible CORS problems
  • create the agent on the service side, and register a handle for each exchange - that is custom to your bussness needs

Hints

  • common code should define an object with JsonExchange's as values, or other objects containing JsonExchange's as values. Keys should briefly explain what the exchange is responsible for.
  • Optionally some JsonExchange's may contain 'preProcessing' and 'postProcessing' code, that is intended for basic validations of the sended/received DTO's, and those functions are the only code that should be unit tested. Basic validation is strongly advised for any DTO types other than void.
  • Use always strong typing and strict tsconfig setting for everything
  • Backend can not trust the frontend.
  • DTO should be just interfaces, although they should inherit if business relevant