-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (31 loc) · 1022 Bytes
/
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
'use strict'
const Action = require('oja').Action
function getTypeNameFromTopics (topics) {
return typeof topics.Model !== 'undefined' && topics.Model.typeName
}
function consume (consumeFn, topics, cb) {
const typeName = getTypeNameFromTopics(topics)
return typeName ? consumeFn(typeName, cb) : consumeFn(topics, cb)
}
class FashionModelAction extends Action {
define (topics, cb) {
const typeName = getTypeNameFromTopics(topics)
if (typeName) {
const errors = []
const wrapped = topics.wrap(arguments[1], errors)
if (errors.length) {
return super.define(typeName,
new Error(`Error wrapping action model: "${errors.join(',')}"`), cb)
}
return super.define(typeName, wrapped, cb)
}
return super.define(topics, cb)
}
consume (topics, cb) {
return consume(super.consume.bind(this), topics, cb)
}
consumeStream (topics, cb) {
return consume(super.consumeStream.bind(this), topics, cb)
}
}
module.exports = FashionModelAction