-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.js
71 lines (69 loc) · 1.98 KB
/
meta.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
68
69
70
71
var path = require('path');
var async = require('async');
var Meta = module.exports = function(tree, stuff) {
var self = this;
self.tree = tree;
self.operations = stuff.operations;
self.operations.init(tree);
self.controllers = stuff.controllers;
// else if (ch.type === 'del') {
// // Get the type
// var type = key[0];
// // If a controller exists for the type
// if (self.controllers[type]) {
// // Delete the metadata for it
// if (self.controllers[type].model) {
// var rows = [];
// rows.push({type: 'del', key: key});
// self.tree.meta.batch(rows);
// }
// // Call the onDel for the metadata
// if (self.controllers[type].onDel) {
// self.controllers[type].onDel(key);
// }
// };
// }
};
Meta.prototype.store = function(ch, cb) {
var self = this;
var key = ch.key;
var storeRequests = [];
// Get the type
var type = key[0];
// If a controller exists for the type
if (self.controllers[type]) {
// Create a new metadata for it
// using the controller's model
if (self.controllers[type].model) {
var value = new self.controllers[type].model();
var rows = [];
rows.push({type: 'put', key: key, value: value});
storeRequests.push(function(cb) {
self.tree.meta.batch(rows, cb);
});
}
// else {
// cb();
// }
// Call the onPut for the metadata
if (self.controllers[type].onPut) {
storeRequests.push(function(cb) {
self.controllers[type].onPut({key: key, value: value, callback: cb});
});
}
};
async.parallel(storeRequests, cb);
}
// options: key, callback, field
Meta.prototype.get = function(options) {
var self = this;
var key = options.key;
self.operations.getValue({key: options.key, callback: function(err, value) {
if (options.field) {
options.callback(err, value[options.field]);
}
else {
options.callback(err, value);
}
}});
};