resolve-local-event-broker
Version:
The reSolve framework's event broker for applications on a local machine.
59 lines (50 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _constants = require("../constants");
function parseSubscription(subscriptionDescription, allowedKeys) {
const subscriptionOptions = { ...subscriptionDescription
};
const allowedAndTransformedKeys = {
subscriptionId: _constants.TRANSFORM_NONE_SYMBOL,
eventSubscriber: _constants.TRANSFORM_NONE_SYMBOL,
status: _constants.TRANSFORM_NONE_SYMBOL,
deliveryStrategy: _constants.TRANSFORM_NONE_SYMBOL,
queueStrategy: _constants.TRANSFORM_NONE_SYMBOL,
eventTypes: _constants.TRANSFORM_JSON_MAPPED_ARRAY_SYMBOL,
aggregateIds: _constants.TRANSFORM_JSON_MAPPED_ARRAY_SYMBOL,
successEvent: _constants.TRANSFORM_JSON_REGULAR_SYMBOL,
failedEvent: _constants.TRANSFORM_JSON_REGULAR_SYMBOL,
errors: _constants.TRANSFORM_JSON_REGULAR_SYMBOL,
cursor: _constants.TRANSFORM_JSON_REGULAR_SYMBOL,
xaTransactionId: _constants.TRANSFORM_JSON_REGULAR_SYMBOL,
runStatus: _constants.TRANSFORM_NONE_SYMBOL,
batchId: _constants.TRANSFORM_NONE_SYMBOL,
isEventBasedRun: _constants.TRANSFORM_NONE_SYMBOL,
hasErrors: _constants.TRANSFORM_NONE_SYMBOL,
maxParallel: _constants.TRANSFORM_NONE_SYMBOL,
scopeName: _constants.TRANSFORM_NONE_SYMBOL,
properties: _constants.TRANSFORM_JSON_REGULAR_SYMBOL
};
for (const key of Object.keys(subscriptionOptions)) {
if (Array.isArray(allowedKeys) && allowedKeys.indexOf(key) < 0) {
delete subscriptionOptions[key];
}
if (allowedAndTransformedKeys[key] === _constants.TRANSFORM_JSON_MAPPED_ARRAY_SYMBOL || allowedAndTransformedKeys[key] === _constants.TRANSFORM_JSON_REGULAR_SYMBOL) {
let value = subscriptionOptions[key];
value = value != null ? JSON.parse(value) : null;
if (allowedAndTransformedKeys[key] === _constants.TRANSFORM_JSON_MAPPED_ARRAY_SYMBOL) {
value = value != null ? Object.keys(value).map(jsonPath => jsonPath.replace(/\u001aSLASH/g, '\\').replace(/\u001aDOT/g, '.').replace(/\u001aQUOTE/g, '"').replace(/\u001aSUB/g, '\u001a')) : null;
}
subscriptionOptions[key] = value;
} else if (allowedAndTransformedKeys[key] !== _constants.TRANSFORM_NONE_SYMBOL) {
delete subscriptionOptions[key];
}
}
return subscriptionOptions;
}
var _default = parseSubscription;
exports.default = _default;
//# sourceMappingURL=parse-subscription.js.map