0.4.4 • Published 4 years ago

@juntoz/joi-schema v0.4.4

Weekly downloads
1
License
UNLICENSED
Repository
github
Last release
4 years ago

joi-schema

Repository containing the schemas necessary to interact with Juntoz platform

How to use?

First install it

npm i @juntoz/joi-schema

Validate Schema

To validate schema you would need first to import the schema namespace and then validate again the needed schema.

const schema = require('@juntoz/joi-schema');

var myuser = {...};
await schema.User.validateAsync(myuser);

Define your own schemas

If you want to define your own schema in your application, and want to use Juntoz Schema as a basis, there are several utilities you can use.

JuntozSchema is {
    JoiEntry,
    partials: {
        InSite
        CreateAudit
        UpdateAudit
        DeleteAudit
    },
    utils: {
        utcNow,
        uuid
    }
    ... (the rest of the schemas)
}

First there is the JoiEntry property which contains all the joi extensions that we use in our schemas, in order to inherit all of these, you need to use this object instead of the Joi default.

- const Joi = require('@hapi/joi');
+ const Joi = require('@juntoz/joi-schema').JoiEntry;

// your own schema
const myschema = Joi.object().keys({});

Second, there are partials that allow to inject definitions into your own schemas. So if you want to apply e.g. creation audit fields, you can do the following:

const JuntozSchema = require('@juntoz/joi-schema');

const myschema = Joi.object().keys({})
    .concat(JuntozSchema.partials.CreateAudit);

TIP: To use the partials, you do not need to use JoiEntry.

Third, also there are some utility functions to easily fill the objects like uuid or utcNow.

Contributing

  • Try inserting one schema per file
  • Always use base.js as the basis for all schemas. To do it in your schema file you should:
// do not use Joi from the library
const Joi = require('./base');

const schema = Joi.object({
    id: Joi.string()
        .required()
  • Finally import the schema in index.js.
  • ALWAYS create a test for the schema. Help everyone make sure this stays running in the future.
  • To publish, you MUST use publish.cmd in the root folder.

How to debug a test in jest?

You can use this link: https://github.com/microsoft/vscode-recipes/tree/master/debugging-jest-tests which basically is to add this to your launch.json:

      {
        "type": "node",
        "request": "launch",
        "name": "Jest Current File",
        "program": "${workspaceFolder}/node_modules/.bin/jest",
        "args": [
          "${fileBasenameNoExtension}",
        ],
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "disableOptimisticBPs": true,
        "windows": {
          "program": "${workspaceFolder}/node_modules/jest/bin/jest",
        }
      }
0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.1

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.3.0

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.4

4 years ago

0.2.0

4 years ago

0.1.24

4 years ago

0.1.25

4 years ago

0.1.23

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.20

4 years ago

0.1.19

4 years ago

0.1.15

4 years ago

0.1.16

4 years ago

0.1.18

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago