-
Notifications
You must be signed in to change notification settings - Fork 199
/
index.js
67 lines (52 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const { MODULE_VERSION } = require('./lib/schemapack.js');
const _ = require('lodash'),
SchemaPack = require('./lib/schemapack.js').SchemaPack,
UserError = require('./lib/common/UserError'),
DEFAULT_INVALID_ERROR = 'Provided definition is invalid';
module.exports = {
// Old API wrapping the new API
convert: function(input, options, cb) {
var schema = new SchemaPack(input, options);
if (schema.validated) {
return schema.convert(cb);
}
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},
convertV2: function(input, options, cb) {
var schema = new SchemaPack(input, options, MODULE_VERSION.V2);
if (schema.validated) {
return schema.convertV2(cb);
}
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},
validate: function (input) {
var schema = new SchemaPack(input);
return schema.validationResult;
},
getMetaData: function (input, cb) {
var schema = new SchemaPack(input);
schema.getMetaData(cb);
},
mergeAndValidate: function (input, cb) {
var schema = new SchemaPack(input);
schema.mergeAndValidate(cb);
},
getOptions: function(mode, criteria) {
return SchemaPack.getOptions(mode, criteria);
},
detectRootFiles: async function(input) {
var schema = new SchemaPack(input);
return schema.detectRootFiles();
},
detectRelatedFiles: async function(input) {
var schema = new SchemaPack(input);
return schema.detectRelatedFiles();
},
bundle: async function(input) {
var schema = new SchemaPack(input, _.has(input, 'options') ? input.options : {});
return schema.bundle();
},
// new API
SchemaPack
};