forked from retro/apitizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapitizer.js
63 lines (59 loc) · 1.42 KB
/
apitizer.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
define([
'tv4',
'./lib/types',
'lodash/collections/forEach',
'./lib/fixtures',
'./lib/store',
'./lib/api',
'./lib/error',
], function(tv4, types, _forEach, fixture, Store, API, ApitizerError){
var __originalXHR = null;
types.formats = types.formats || {};
_forEach(types.formats, function(format, name){
tv4.addFormat(name, function(val){
if(format.validate(val)){
return null;
}
return 'failed validation by the ' + name + ' format';
});
});
return {
addSchema : function(name, schema){
Store.addSchema(name, schema);
},
getSchema : function(name){
return Store.getSchema(name);
},
dropSchemas : function(){
Store.dropSchemas();
},
validateWithSchema : function(name, data){
return Store.validateWithSchema(name, data);
},
generateFromSchema : function(name, overrides){
return (new Store(name, 0, overrides, this.API)).generate();
},
schemaStore : function(name, count, overrides, api){
return new Store(name, count, overrides, api || this.API);
},
addFormat : function(name, format){
Store.addFormat(name, format);
},
start : function(){
if(!__originalXHR){
__originalXHR = window.XMLHttpRequest;
window.XMLHttpRequest = fixture.responder;
}
},
stop : function(){
if(__originalXHR){
window.XMLHttpRequest = __originalXHR;
__originalXHR = null;
}
},
types : types,
fixture : fixture,
API : API,
Error : ApitizerError
};
})