jijejo-spec

jijejo specification

Usage no npm install needed!

<script type="module">
  import jijejoSpec from 'https://cdn.skypack.dev/jijejo-spec';
</script>

README

jijejo-spec

Jijejo is a universal and easy api for all yours applications or libraries. Jijejo is a human and light alternative of json:api, json-ld, hal, openapi, graphql, joi, zod, yup, hydra ... Back to basics to get ahead in your business.

jijejo = (j)son (i)n + (j)son (e)rr + (j)son (o)ut

https://cloud.githubusercontent.com/assets/svg/draft.svg

Specifications

jijejo's specifications can be summarized in 4 rules, nothing else to learn.

rule n°1: ji = (j)son (i)n

When you call a function, first param is a json with always/only two attributs .meta={...}, .in=<any> (second param is zero or many adapters, Hexagonal architecture)

{
    "in":  [] | {} | "string" | true | false | null, // 'in' payload
    "meta": {}, // optionnal meta content
}

rule n°2: je = (j)son (e)rr

When function detect an error then it always/only return a json with 4 attributs .meta={...}, .isout=false, .iserr=true, .err=<any>, .

{
    "isout": false, // if error then .isout always 'false'
    "iserr": true,  // if error then .iserr always 'true'
    "err":  [] | {} | "string" | true | false | null, // 'err' payload
    "meta": {}, // optionnal meta content
}

rule n°3: jo = (j)son (o)ut

When function run without error then it always/only return a json with 4 attributs .meta={...}, .isout=true, .iserr=false, .out=<any>.

{
    "iserr": false,  // if ok then .iserr always 'false'
    "isout": true,   // if ok then .isout always 'true'
    "out":  [] | {} | "string" | true | false | null, // 'out' payload
    "meta": {}, // optionnal meta content
}

rule n°4: nothing else allow

You must catch all unpredictables errors and return a json that respects a (j)son (e)rr.

Javascript example:

try{ 
    throw new Error("unpredictable error");
} catch(error) {  
    return { err: { message: error.message }, iserr: true, isout: false, meta: { ... } }
}

bonus rules: never trust

  • never trust incoming (j)son (i)n, always validate it before usage.
  • never trust your (j)son (e)rr, always validate it before return.
  • never trust your (j)son (o)out, always validate it before return.

toolkit

  • jijejo-node helps to quickly create jsonerr, jsonout jsonin, or to validate them.

license

Jijejo's specifications are under license CC-BY-NC-ND-4.0

License: CC-BY-NC-ND-4.0