Skip to content

Commit

Permalink
Merge pull request #38 from cap-js/no-lodash
Browse files Browse the repository at this point in the history
Removed lodash + eslint fixes
  • Loading branch information
danjoa authored Dec 20, 2023
2 parents f28418a + df8ebb3 commit 27efc5c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends: eslint:recommended
env:
node: true
commonjs: true
jest: true
es2021: true
parserOptions:
ecmaVersion: latest
rules: {}
30 changes: 17 additions & 13 deletions cds-plugin.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const cds = require("@sap/cds");
const build = require('@sap/cds-dk/lib/build')
const { validateNotificationTypes, readFile } = require("./lib/utils");
const { createNotificationTypesMap } = require("./lib/notificationTypes");
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
const cds = require("@sap/cds/lib");

// register build plugin
build.register('notifications', { impl: '@cap-js/notifications/lib/build', description: 'Notifications build plugin', taskDefaults: { src: cds.env.folders.srv } });
if (cds.cli.command === "build") {
// register build plugin
const build = require('@sap/cds-dk/lib/build')
build.register('notifications', {
impl: '@cap-js/notifications/lib/build',
description: 'Notifications build plugin',
taskDefaults: { src: cds.env.folders.srv }
})
}

cds.once("served", async () => {
setGlobalLogLevel("error");
const profiles = cds.env.profiles ?? [];
const production = profiles.includes("production");
else cds.once("served", async () => {
const { validateNotificationTypes, readFile } = require("./lib/utils");
const { createNotificationTypesMap } = require("./lib/notificationTypes");
const production = cds.env.profiles?.includes("production");

// read notification types
const notificationTypes = readFile(cds.env.requires?.notifications?.types);

if (validateNotificationTypes(notificationTypes)) {
if (!production) {
const notificationTypesMap = createNotificationTypesMap(notificationTypes, true);
cds.notifications = { local: { types: notificationTypesMap } };
}
}
});

require("@sap-cloud-sdk/util").setGlobalLogLevel("error")
})
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// FIXME: should not be necessary
process.env.CDS_ENV = 'better-sqlite'

const config = {
testTimeout: 42222,
Expand Down
9 changes: 4 additions & 5 deletions lib/notificationTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
const { buildHeadersForDestination } = require("@sap-cloud-sdk/connectivity");
const { getNotificationDestination, getPrefix, getNotificationTypesKeyWithPrefix } = require("./utils");
const _ = require("lodash");
const NOTIFICATION_TYPES_API_ENDPOINT = "v2/NotificationType.svc";
const cds = require("@sap/cds");
const LOG = cds.log('notifications');
Expand Down Expand Up @@ -135,14 +134,14 @@ function _createChannelsMap(channels) {
}

function areDeliveryChannelsEqual(oldChannels, newChannels) {
if (_.size(oldChannels) !== _.size(newChannels)) {
if (oldChannels.length !== newChannels.length) {
return false;
}

const oldChannelsMap = _createChannelsMap(oldChannels);
const newChannelsMap = _createChannelsMap(newChannels);

for (type of Object.keys(oldChannelsMap)) {
for (let type of Object.keys(oldChannelsMap)) {
if (!(type in newChannelsMap)) return false;

const oldChannel = oldChannelsMap[type];
Expand Down Expand Up @@ -173,7 +172,7 @@ function isActionEqual(oldAction, newAction) {
}

function areActionsEqual(oldActions, newActions) {
if (_.size(oldActions) !== _.size(newActions)) {
if (oldActions.length !== newActions.length) {
return false;
}

Expand Down Expand Up @@ -209,7 +208,7 @@ function isTemplateEqual(oldTemplate, newTemplate) {
}

function areTemplatesEqual(oldTemplates, newTemplates) {
if (_.size(oldTemplates) !== _.size(newTemplates)) {
if (oldTemplates.length !== newTemplates.length) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const messages = {
};

function validateNotificationTypes(notificationTypes) {
for(notificationType of notificationTypes){
for(let notificationType of notificationTypes){
if (!("NotificationTypeKey" in notificationType)) {
LOG._warn && LOG.warn(messages.INVALID_NOTIFICATION_TYPES);
return false;
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
"@sap/cds-dk": "^7.3.1"
},
"dependencies": {
"@sap-cloud-sdk/connectivity": "3.5.0",
"@sap-cloud-sdk/http-client": "3.5.0",
"@sap-cloud-sdk/util": "3.5.0",
"lodash": "4.17.21"
"@sap-cloud-sdk/connectivity": "^3.5.0",
"@sap-cloud-sdk/http-client": "^3.5.0",
"@sap-cloud-sdk/util": "^3.5.0"
},
"devDependencies": {
"jest": "^29.7.0",
Expand Down
1 change: 1 addition & 0 deletions srv/notifyToRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const NotificationService = require("./service")
const { buildHeadersForDestination } = require("@sap-cloud-sdk/connectivity");
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
const { getNotificationDestination } = require("../lib/utils");
const cds = require("@sap/cds");
const LOG = cds.log('notifications');
const NOTIFICATIONS_API_ENDPOINT = "v2/Notification.svc";

Expand Down
1 change: 0 additions & 1 deletion test/lib/content-deployment.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// import required modules and functions
const cds = require("@sap/cds");
const { validateNotificationTypes, readFile } = require("../../lib/utils");
const { processNotificationTypes } = require("../../lib/notificationTypes");
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
Expand Down

0 comments on commit 27efc5c

Please sign in to comment.