Gathering detailed insights and metrics for @winhillsen/joi-extract-type
Gathering detailed insights and metrics for @winhillsen/joi-extract-type
Gathering detailed insights and metrics for @winhillsen/joi-extract-type
Gathering detailed insights and metrics for @winhillsen/joi-extract-type
npm install @winhillsen/joi-extract-type
Typescript
Module System
Node Version
NPM Version
71.5
Supply Chain
98.9
Quality
74.7
Maintenance
50
Vulnerability
100
License
TypeScript (100%)
Total Downloads
2,406
Last Day
1
Last Week
2
Last Month
5
Last Year
203
152 Stars
72 Commits
27 Forks
8 Watching
12 Branches
8 Contributors
Latest Version
0.0.15
Package Id
@winhillsen/joi-extract-type@0.0.15
Unpacked Size
27.70 kB
Size
6.74 kB
File Count
11
NPM Version
5.6.0
Node Version
9.11.2
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
100%
2
Compared to previous week
Last month
0%
5
Compared to previous month
Last year
-52.3%
203
Compared to previous year
Provides native type extraction from Joi Schemas for Typescript.
Joi Schemas are great. But if you use Typescrypt to define your entities, it is easy to dupplicate the definition inside the Schemas and all application interfaces.
This library enhances Joi interfaces to provides an utility to infer the type from a Schema.
Why should you use it
Limitation
npm i --save joi-extract-type
Built for typescript@^3
For typescript 2.9 support checkout branch /typescript@2 or install with:
npm i --save joi-extract-type@ts2-1
Import the library and patch Joi's typings:
1import * as Joi from 'joi'; 2import './index';
Create the schemas and use Joi.extractType
to infer the type:
1const is_enabled = Joi.boolean(); 2type extractBoolean = Joi.extractType<typeof is_enabled>; 3export const extractedBoolean: extractBoolean = true;
Examples
The following code is copied from this library spec, which compiles the code with tsc
that should not output any errors.
1const is_enabled = Joi.boolean();
2type extractBoolean = Joi.extractType<typeof is_enabled>;
3export const extractedBoolean: extractBoolean = true;
4
5const full_name = Joi.string();
6type extractString = Joi.extractType<typeof full_name>;
7export const extractedString: extractString = 'string';
8
9const user = Joi.object({ full_name, is_enabled });
10type extractObject = Joi.extractType<typeof user>;
11export const extractedObject: extractObject = { full_name: extractedString, is_enabled: extractedBoolean };
12
13const roles = Joi.array().items(Joi.string());
14type extractArray = Joi.extractType<typeof roles>;
15export const extactedArray: extractArray = ['admin'];
16
17const apply = Joi.array().items(Joi.object({ id: Joi.string() }));
18type extractApply = Joi.extractType<typeof apply>;
19export const extractedApply: extractApply = [{ id: '3' }, { id: '4' }];
20
21const rule = Joi.object({ apply });
22type extractRule = Joi.extractType<typeof rule>;
23export const extractedRule: extractRule = { apply: extractedApply };
24
25export const jobOperatorRoleSchema = Joi.object({
26 id: Joi.string().required(),
27 user_id: Joi.string().required(),
28 job_id: Joi.string().required(),
29 role: Joi.string().valid([ 'recruiter', 'requester' ]),
30 pipeline_rules: Joi.array().items(rule),
31});
32type extractComplexType = Joi.extractType<typeof jobOperatorRoleSchema>;
33export const extractedComplexType: extractComplexType = {
34 id: '2015',
35 user_id: '102',
36 job_id: '52',
37 role: 'admin',
38 pipeline_rules: [extractedRule]
39};
40
41// typeof extractedComplexType
42// const extractedComplexType: Joi.extractMap<{
43// id: Joi.StringSchema;
44// user_id: Joi.StringSchema;
45// job_id: Joi.StringSchema;
46// role: Joi.StringSchema;
47// pipeline_rules: Joi.ArraySchema<Joi.extractMap<{
48// apply: Joi.ArraySchema<Joi.extractMap<{
49// id: Joi.StringSchema;
50// }>>;
51// }>>;
52// }>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 6/25 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More