@1mill/cloudevents 0.11.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -51
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +21 -8
- package/src/index.js +71 -0
- package/.editorconfig +0 -21
- package/index.js +0 -6
- package/v3/createCloudevent.js +0 -51
- package/v3/createEventStream.js +0 -36
- package/v3/enrichCloudevent.js +0 -15
- package/v3/index.js +0 -16
- package/v3/isEnriched.js +0 -5
- package/v3/kafka/convertFrom.js +0 -6
- package/v3/kafka/convertTo.js +0 -12
- package/v3/kafka/createAuthentication.js +0 -19
- package/v3/kafka/createEmit.js +0 -33
- package/v3/kafka/createListen.js +0 -75
- package/v3/kafka/index.js +0 -28
- package/v3/lambda/handler.js +0 -29
- package/v3/lambda/index.js +0 -7
- package/v3/lib/constants.js +0 -14
- package/v4/createCloudevent.js +0 -47
- package/v4/createEventStream.js +0 -36
- package/v4/index.js +0 -12
- package/v4/kafka/convertFrom.js +0 -6
- package/v4/kafka/convertTo.js +0 -12
- package/v4/kafka/createAuthentication.js +0 -19
- package/v4/kafka/createEmit.js +0 -33
- package/v4/kafka/createListen.js +0 -64
- package/v4/kafka/index.js +0 -28
- package/v4/lambda/handler.js +0 -9
- package/v4/lambda/index.js +0 -7
- package/v4/lib/constants.js +0 -14
- package/v5/createCloudevent.js +0 -47
- package/v5/createCloudeventStream.js +0 -42
- package/v5/index.js +0 -12
- package/v5/kafka/convertFrom.js +0 -6
- package/v5/kafka/convertTo.js +0 -12
- package/v5/kafka/createAuthentication.js +0 -19
- package/v5/kafka/createEmit.js +0 -33
- package/v5/kafka/createListen.js +0 -73
- package/v5/kafka/index.js +0 -28
- package/v5/lambda/handler.js +0 -9
- package/v5/lambda/index.js +0 -7
- package/v5/lib/constants.js +0 -14
- package/v6/index.js +0 -41
package/v5/kafka/createListen.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const { ERROR_TYPES, SIGNAL_TRAPS } = require('../lib/constants')
|
|
2
|
-
const { Kafka } = require('kafkajs')
|
|
3
|
-
const { convertFrom } = require('./convertFrom')
|
|
4
|
-
const { createAuthentication } = require('./createAuthentication')
|
|
5
|
-
|
|
6
|
-
const createListen = ({
|
|
7
|
-
id,
|
|
8
|
-
mechanism,
|
|
9
|
-
password,
|
|
10
|
-
urls,
|
|
11
|
-
username,
|
|
12
|
-
}) => {
|
|
13
|
-
const authentication = createAuthentication({
|
|
14
|
-
mechanism,
|
|
15
|
-
password,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const kafka = new Kafka({
|
|
19
|
-
...authentication,
|
|
20
|
-
brokers: urls,
|
|
21
|
-
clientId: id,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const listen = async ({ handler, types }) => {
|
|
25
|
-
const consumer = kafka.consumer({ groupId: id });
|
|
26
|
-
await consumer.connect()
|
|
27
|
-
|
|
28
|
-
const promises = types.map(type => {
|
|
29
|
-
consumer.subscribe({
|
|
30
|
-
fromBeginning: type.fromBeginning || false,
|
|
31
|
-
topic: type.type || type,
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
await Promise.all(promises)
|
|
35
|
-
|
|
36
|
-
await consumer.run({
|
|
37
|
-
eachMessage: async (event) => {
|
|
38
|
-
try {
|
|
39
|
-
const { cloudevent } = convertFrom({ event })
|
|
40
|
-
await handler({ cloudevent })
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.error(err)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// Before server stop, close subscription connections to kafka
|
|
48
|
-
ERROR_TYPES.map(errorType => {
|
|
49
|
-
process.on(errorType, async (err) => {
|
|
50
|
-
try {
|
|
51
|
-
console.log(`process.on ${errorType}`)
|
|
52
|
-
console.error(err)
|
|
53
|
-
await consumer.disconnect()
|
|
54
|
-
process.exit(0)
|
|
55
|
-
} catch (_err) {
|
|
56
|
-
process.exit(1)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
SIGNAL_TRAPS.map(signalTrap => {
|
|
61
|
-
process.once(signalTrap, async () => {
|
|
62
|
-
try {
|
|
63
|
-
await consumer.disconnect()
|
|
64
|
-
} finally {
|
|
65
|
-
process.kill(process.pid, signalTrap)
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
return { listen }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = { createListen }
|
package/v5/kafka/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { createEmit } = require('./createEmit')
|
|
2
|
-
const { createListen } = require('./createListen')
|
|
3
|
-
|
|
4
|
-
const createInstance = ({
|
|
5
|
-
id,
|
|
6
|
-
mechanism,
|
|
7
|
-
password,
|
|
8
|
-
urls,
|
|
9
|
-
username,
|
|
10
|
-
}) => {
|
|
11
|
-
const { emit } = createEmit({
|
|
12
|
-
id,
|
|
13
|
-
mechanism,
|
|
14
|
-
password,
|
|
15
|
-
urls,
|
|
16
|
-
username,
|
|
17
|
-
})
|
|
18
|
-
const { listen } = createListen({
|
|
19
|
-
id,
|
|
20
|
-
mechanism,
|
|
21
|
-
password,
|
|
22
|
-
urls,
|
|
23
|
-
username,
|
|
24
|
-
});
|
|
25
|
-
return { emit, listen }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { createInstance }
|
package/v5/lambda/handler.js
DELETED
package/v5/lambda/index.js
DELETED
package/v5/lib/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const PROTOCOL_KAFKA = 'kafka'
|
|
2
|
-
const PROTOCOL_LAMBDA = 'lambda'
|
|
3
|
-
|
|
4
|
-
const ERROR_TYPES = ['unhandledRejection', 'uncaughtException']
|
|
5
|
-
const SIGNAL_TRAPS = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
// Supported protocols
|
|
9
|
-
PROTOCOL_KAFKA,
|
|
10
|
-
PROTOCOL_LAMBDA,
|
|
11
|
-
// Other constants
|
|
12
|
-
ERROR_TYPES,
|
|
13
|
-
SIGNAL_TRAPS,
|
|
14
|
-
};
|
package/v6/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const createCloudevent = ({
|
|
2
|
-
data,
|
|
3
|
-
datacontenttype,
|
|
4
|
-
dataschema,
|
|
5
|
-
id,
|
|
6
|
-
originid,
|
|
7
|
-
originsource,
|
|
8
|
-
origintype,
|
|
9
|
-
source,
|
|
10
|
-
specversion = '1.0',
|
|
11
|
-
subject,
|
|
12
|
-
type,
|
|
13
|
-
}) => {
|
|
14
|
-
if (!id) { throw new Error('Cloudevent "id" is as required') }
|
|
15
|
-
if (!source) { throw new Error('Cloudevent "source" is as required') }
|
|
16
|
-
if (!type) { throw new Error('Cloudevent "type" is as required') }
|
|
17
|
-
|
|
18
|
-
const cloudevent = {
|
|
19
|
-
// * Defined in cloudevents specification
|
|
20
|
-
// Required defaults
|
|
21
|
-
id,
|
|
22
|
-
source,
|
|
23
|
-
specversion,
|
|
24
|
-
time: new Date().toUTCString(),
|
|
25
|
-
type,
|
|
26
|
-
|
|
27
|
-
// Optional data
|
|
28
|
-
data,
|
|
29
|
-
datacontenttype,
|
|
30
|
-
dataschema,
|
|
31
|
-
subject,
|
|
32
|
-
|
|
33
|
-
// * In-house attribute extensions
|
|
34
|
-
originid: originid || id,
|
|
35
|
-
originsource: originsource || source,
|
|
36
|
-
origintype: origintype || type,
|
|
37
|
-
}
|
|
38
|
-
return cloudevent
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = { v6: { createCloudevent } }
|