@juntoz/joi-schema v0.4.4
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",
}
}
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago