-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (32 loc) · 1.1 KB
/
index.js
File metadata and controls
33 lines (32 loc) · 1.1 KB
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
const scriptPort = require('ut-port-script');
module.exports = function({namespace, methods, imports, validations}) {
let namespaces = namespace && [].concat(namespace);
if (!namespaces) {
[methods, imports, validations] = arguments;
namespaces = Array.from(
new Set(
Object.keys(methods).map(name => name.split('.', 2)[0])));
}
if (!namespaces.length) throw new Error('Missing namespace for dispatch');
const id = namespaces[0].replace(/[\\/]/g, '-');
return (...params) => ({
[id]: class extends scriptPort(...params) {
get defaults() {
return {
namespace: namespaces,
imports,
validations
};
}
handlers() {
return {
...namespaces.reduce((prev, name) => ({
...prev,
[name + '.service.get']: () => params[0].utMethod.pkg
}), {}),
...methods
};
}
}
}[id]);
};