-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
58 lines (50 loc) · 1.18 KB
/
scripts.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
Shuttler.Scripts = new Mongo.Collection('shuttler:scripts');
Shuttler.Scripts.Schema = new SimpleSchema({
source: {
type: String
},
script: {
type: String,
optional: true
},
type: {
type: String
},
error: {
type: new SimpleSchema({
name: { type: String },
message: { type: String },
line: { type: Number },
column: { type: Number }
}),
optional: true
}
});
Shuttler.Scripts.Helpers = {
isScript: true,
eval() {
var module = {
exports: {}
};
((module, exports) => {
eval(this.script);
})(module, module.exports);
return module;
}
};
Shuttler.Scripts.attachScripts = function(collection) {
collection.attachSchema(Shuttler.Scripts.Schema);
collection.helpers(Shuttler.Scripts.Helpers);
if (Meteor.isServer) {
collection.after.insert(function(userId, doc) {
Shuttler.Scripts._types[doc.type].apply(collection, arguments);
});
collection.after.update(function(userId, doc) {
if (this.previous.source != doc.source || this.previous.type != doc.type)
Shuttler.Scripts._types[doc.type].apply(collection, arguments);
});
}
collection.isScripts = true;
};
Shuttler.Scripts.attachScripts(Shuttler.Scripts);
Shuttler.Scripts._types = {};