Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sap/cds-messaging

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap/cds-messaging - npm Package Compare versions

Comparing version 1.5.0 to 1.7.0

lib/utils/commitAndRollback.js

20

CHANGELOG.md

@@ -9,2 +9,22 @@ # Changelog

## Version 1.7.0 - 2020-02-19
### Changed
- Updated version number for public release
## Version 1.6.0 - 2020-02-05
### Added
- Support for `prefix` credentials options to prefix topics
### Changed
- You can no longer set the namespace outside of the `credentials` block
### Fixed
- Fixed bug where non-trimmed data causes problems in file-based messaging
## Version 1.5.0 - 2019-12-10

@@ -11,0 +31,0 @@

13

lib/cds.js
const injection = {
inject (cds) {
if (!cds || typeof cds !== 'object') {
throw new Error('Injected value is not of type `cds`')
cds: global.cds,
inject (cds, force = false) {
if (force || !injection.cds) {
if (!cds || typeof cds !== 'object') {
throw new Error('Injected value is not of type `cds`')
}
injection.cds = cds
}
injection.cds = cds
}

@@ -9,0 +12,0 @@ }

const { resolve } = require('../utils/thenable')
const { commit, rollback } = require('../utils/commitAndRollback')

@@ -30,6 +31,9 @@ class Message {

(event && !entity && !each.entity && each.event === event) ||
(!event && !entity && each.topic === topic)
each.topic === topic
)
if (!matchedHandlers.length) return
if (!matchedHandlers.length) {
raw.done()
return
}

@@ -46,9 +50,15 @@ let payload

.reduce((chain, handler) => chain.then(() => handler.handler(msg)), resolve())
.then(() => raw.done())
.catch(err => {
.then(async () => {
await commit(msg)
raw.done()
})
.catch(async err => {
console.error(err)
const chain = errHandlers.reduce((chain, errHandler) => chain.then(() => errHandler(err)), resolve())
return chain.then(() => raw.done())
try {
await errHandlers.reduce((chain, errHandler) => chain.then(() => errHandler(err)), resolve())
} catch (e) {}
raw.done()
return rollback(msg)
})
}
module.exports = dataHandler

@@ -19,3 +19,4 @@ const dataHandler = require('./dataHandler')

} else {
const normalized = _normalizeOnArgs(event, entity, handler)
const prefixForUnmanagedTopic = _getPrefixForUnmanagedTopic(options)
const normalized = _normalizeOnArgs(event, entity, handler, prefixForUnmanagedTopic)

@@ -29,7 +30,7 @@ _onNormalized.call(this, normalized, options)

function _deriveSource ({ queueEnd, appName, appID, ownNamespace }) {
function _deriveSource ({ shrunkService, appName, appID, ownNamespace }) {
const shrunkAppID = appID.substring(0, 4)
return ownNamespace
? `queue:${ownNamespace}/${appName}/${shrunkAppID}/${queueEnd}`
: `queue:${appName}/${shrunkAppID}/${queueEnd}`
? `queue:${ownNamespace}/${appName}/${shrunkAppID}/${shrunkService}`
: `queue:${appName}/${shrunkAppID}/${shrunkService}`
}

@@ -56,5 +57,3 @@

const namespaceOfService =
process.env.MESSAGING_NAMESPACE ||
msgOptions.namespace ||
(msgOptions.credentials && msgOptions.credentials.namespace)
process.env.MESSAGING_NAMESPACE || (msgOptions.credentials && msgOptions.credentials.namespace)
const vcapApplication = process.env.VCAP_APPLICATION && JSON.parse(process.env.VCAP_APPLICATION)

@@ -65,3 +64,2 @@ const appName = (vcapApplication && vcapApplication.application_name.replace(INVALID_SYMBOLS, '')) || 'unknownApp'

const prefix = msgOptions.credentials && msgOptions.credentials.prefix
const queueEnd = (msgOptions.credentials && msgOptions.credentials.prefix) || shrunkService
const customSource = msgOptions.credentials && msgOptions.credentials.queue && `queue:${msgOptions.credentials.queue}`

@@ -76,3 +74,2 @@

customSource,
queueEnd,
namespaceOfService,

@@ -97,6 +94,10 @@ prefix,

function _getPrefixForTopic (options, client) {
function _getPrefixForManagedTopic (options, client) {
return options.prefix || `${options.namespaceOfService || client._options.namespace}/${options.shrunkService}`
}
function _getPrefixForUnmanagedTopic (options) {
return options.prefix
}
function _addSubscription (onHandler, options) {

@@ -108,3 +109,4 @@ _pendingOperations(this)

const queueName = _getQueueNameFromSource(source)
const topic = _getTopicFromOnHandler(onHandler, _getPrefixForTopic(options, client))
const prefixForManagedTopic = _getPrefixForManagedTopic(options, client)
const topic = _getTopicFromOnHandler(onHandler, prefixForManagedTopic)
if (client._options.kind === 'enterprise-messaging') {

@@ -133,3 +135,8 @@ _pendingOperations(client)

options.customSource ||
_deriveSource({ queueEnd: options.queueEnd, appName: options.appName, appID: options.appID, ownNamespace })
_deriveSource({
shrunkService: options.shrunkService,
appName: options.appName,
appID: options.appID,
ownNamespace
})
)

@@ -142,4 +149,4 @@ }

const queueName = _getQueueNameFromSource(source)
const prefixForTopic = _getPrefixForTopic(options, client)
const topic = _getTopicFromOnHandler(normalizedHandler, prefixForTopic)
const prefixForManagedTopic = _getPrefixForManagedTopic(options, client)
const topic = _getTopicFromOnHandler(normalizedHandler, prefixForManagedTopic)
if (client._options.kind === 'enterprise-messaging') {

@@ -155,3 +162,3 @@ client._pendingOperations = _pendingOperations(client)

}
client.on(dataHandler(options.onHandlers, options.errHandlers, prefixForTopic), null, source)
client.on(dataHandler(options.onHandlers, options.errHandlers, prefixForManagedTopic), null, source)
this.release(client)

@@ -195,11 +202,11 @@ })

function _getTopicFromOnHandler (onHandler, prefix) {
function _getTopicFromOnHandler (onHandler, prefixForManagedTopic) {
return onHandler.topic
? onHandler.topic
: onHandler.entity
? `${prefix}/${onHandler.entity}/${onHandler.event}`
: `${prefix}/${onHandler.event}`
? `${prefixForManagedTopic}/${onHandler.entity}/${onHandler.event}`
: `${prefixForManagedTopic}/${onHandler.event}`
}
function _normalizeOnArgs (event, entity, handler) {
function _normalizeOnArgs (event, entity, handler, prefixForUnmanagedTopic) {
if (entity && entity._entityName) {

@@ -213,3 +220,5 @@ const splitted = entity._entityName.split('.')

? event.startsWith('topic:') || event.includes('/')
? [undefined, undefined, entity, event.replace(/^topic:/, '')]
? prefixForUnmanagedTopic
? [undefined, undefined, entity, event.replace(/^topic:/, '').replace(/^/, `${prefixForUnmanagedTopic}/`)]
: [undefined, undefined, entity, event.replace(/^topic:/, '')]
: [event, undefined, entity, undefined]

@@ -249,5 +258,12 @@ : ['*', '*', event, undefined]

this.acquire({}, 'messaging').then(client => {
const namespace = options.namespaceOfService || client._options.namespace
const shrunkService = options.shrunkService
const [target, msg] = _getTargetAndMessage(payload, namespace, shrunkService, entity, event, header)
const prefixForManagedTopic = _getPrefixForManagedTopic(options, client)
const prefixForUnmanagedTopic = options.prefix
const [target, msg] = _getTargetAndMessage(
payload,
entity,
event,
header,
prefixForManagedTopic,
prefixForUnmanagedTopic
)
client.emit(msg, target)

@@ -264,16 +280,20 @@ this.release(client)

function _handleEventAsString (payload, namespace, shrunkService, entity, event) {
function _handleEventAsString (payload, entity, event, prefixForManagedTopic, prefixForUnmanagedTopic) {
return event.startsWith('topic:')
? [event, { data: entity, ...payload }]
? prefixForUnmanagedTopic
? [event.replace(/^topic:/, `topic:${prefixForUnmanagedTopic}/`), { data: entity, ...payload }]
: [event, { data: entity, ...payload }]
: event.includes('/')
? [`topic:${event}`, { data: entity, ...payload }]
: [`topic:${namespace}/${shrunkService}/${event}`, { data: entity, ...payload }]
? prefixForUnmanagedTopic
? [`topic:${prefixForUnmanagedTopic}/${event}`, { data: entity, ...payload }]
: [`topic:${event}`, { data: entity, ...payload }]
: [`topic:${prefixForManagedTopic}/${event}`, { data: entity, ...payload }]
}
function _getTargetAndMessage (payload, namespace, shrunkService, entity, event, header) {
function _getTargetAndMessage (payload, entity, event, header, prefixForManagedTopic, prefixForUnmanagedTopic) {
return typeof payload === 'object' && typeof entity !== 'object'
? [`topic:${namespace}/${shrunkService}/${entity}/${event}`, { data: payload, ...header }]
? [`topic:${prefixForManagedTopic}/${entity}/${event}`, { data: payload, ...header }]
: entity
? typeof event === 'string'
? _handleEventAsString(payload, namespace, shrunkService, entity, event)
? _handleEventAsString(payload, entity, event, prefixForManagedTopic, prefixForUnmanagedTopic)
: [null, { data: event, ...entity }]

@@ -280,0 +300,0 @@ : [null, { data: event, ...payload }]

@@ -23,2 +23,12 @@ const fs = require('fs')

_trimmedLinesFromData (data) {
return (
data &&
data
.trim()
.split('\n')
.map(line => line && line.trim())
)
}
disconnect () {

@@ -117,6 +127,7 @@ this._watcher.close()

const data = fs.readFileSync(this._options.mock, 'utf-8')
if (!data) {
if (!data || !data.trim()) {
this._processing = false
return
}
const lines = data && data.trim().split('\n')
const lines = this._trimmedLinesFromData(data)
this._processLines(lines)

@@ -170,3 +181,3 @@ } catch (err) {}

const data = fs.readFileSync(source, 'utf-8')
const lines = data && data.trim().split('\n')
const lines = this._trimmedLinesFromData(data)
if (lines) {

@@ -173,0 +184,0 @@ this._removeUsedLine(lines, processedLine)

@@ -1,1 +0,1 @@

{"bundleDependencies":false,"dependencies":{},"deprecated":false,"description":"","engines":{"node":">= 8.9.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-messaging","version":"1.5.0","license":"SEE LICENSE IN developer-license-3.1.txt"}
{"bundleDependencies":false,"dependencies":{},"deprecated":false,"description":"","engines":{"node":">= 8.9.0"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"{lib,test}/**/*.js":["prettier-standard","standard --fix","git add"]},"main":"lib/index.js","name":"@sap/cds-messaging","version":"1.7.0","license":"SEE LICENSE IN developer-license-3.1.txt"}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc