Skip to content

Commit 27efc5c

Browse files
authored
Merge pull request #38 from cap-js/no-lodash
Removed lodash + eslint fixes
2 parents f28418a + df8ebb3 commit 27efc5c

File tree

8 files changed

+35
-25
lines changed

8 files changed

+35
-25
lines changed

.eslintrc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extends: eslint:recommended
2+
env:
3+
node: true
4+
commonjs: true
5+
jest: true
6+
es2021: true
7+
parserOptions:
8+
ecmaVersion: latest
9+
rules: {}

cds-plugin.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
const cds = require("@sap/cds");
2-
const build = require('@sap/cds-dk/lib/build')
3-
const { validateNotificationTypes, readFile } = require("./lib/utils");
4-
const { createNotificationTypesMap } = require("./lib/notificationTypes");
5-
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");
1+
const cds = require("@sap/cds/lib");
62

7-
// register build plugin
8-
build.register('notifications', { impl: '@cap-js/notifications/lib/build', description: 'Notifications build plugin', taskDefaults: { src: cds.env.folders.srv } });
3+
if (cds.cli.command === "build") {
4+
// register build plugin
5+
const build = require('@sap/cds-dk/lib/build')
6+
build.register('notifications', {
7+
impl: '@cap-js/notifications/lib/build',
8+
description: 'Notifications build plugin',
9+
taskDefaults: { src: cds.env.folders.srv }
10+
})
11+
}
912

10-
cds.once("served", async () => {
11-
setGlobalLogLevel("error");
12-
const profiles = cds.env.profiles ?? [];
13-
const production = profiles.includes("production");
13+
else cds.once("served", async () => {
14+
const { validateNotificationTypes, readFile } = require("./lib/utils");
15+
const { createNotificationTypesMap } = require("./lib/notificationTypes");
16+
const production = cds.env.profiles?.includes("production");
1417

1518
// read notification types
1619
const notificationTypes = readFile(cds.env.requires?.notifications?.types);
17-
1820
if (validateNotificationTypes(notificationTypes)) {
1921
if (!production) {
2022
const notificationTypesMap = createNotificationTypesMap(notificationTypes, true);
2123
cds.notifications = { local: { types: notificationTypesMap } };
2224
}
2325
}
24-
});
26+
27+
require("@sap-cloud-sdk/util").setGlobalLogLevel("error")
28+
})

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// FIXME: should not be necessary
2-
process.env.CDS_ENV = 'better-sqlite'
32

43
const config = {
54
testTimeout: 42222,

lib/notificationTypes.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
22
const { buildHeadersForDestination } = require("@sap-cloud-sdk/connectivity");
33
const { getNotificationDestination, getPrefix, getNotificationTypesKeyWithPrefix } = require("./utils");
4-
const _ = require("lodash");
54
const NOTIFICATION_TYPES_API_ENDPOINT = "v2/NotificationType.svc";
65
const cds = require("@sap/cds");
76
const LOG = cds.log('notifications');
@@ -135,14 +134,14 @@ function _createChannelsMap(channels) {
135134
}
136135

137136
function areDeliveryChannelsEqual(oldChannels, newChannels) {
138-
if (_.size(oldChannels) !== _.size(newChannels)) {
137+
if (oldChannels.length !== newChannels.length) {
139138
return false;
140139
}
141140

142141
const oldChannelsMap = _createChannelsMap(oldChannels);
143142
const newChannelsMap = _createChannelsMap(newChannels);
144143

145-
for (type of Object.keys(oldChannelsMap)) {
144+
for (let type of Object.keys(oldChannelsMap)) {
146145
if (!(type in newChannelsMap)) return false;
147146

148147
const oldChannel = oldChannelsMap[type];
@@ -173,7 +172,7 @@ function isActionEqual(oldAction, newAction) {
173172
}
174173

175174
function areActionsEqual(oldActions, newActions) {
176-
if (_.size(oldActions) !== _.size(newActions)) {
175+
if (oldActions.length !== newActions.length) {
177176
return false;
178177
}
179178

@@ -209,7 +208,7 @@ function isTemplateEqual(oldTemplate, newTemplate) {
209208
}
210209

211210
function areTemplatesEqual(oldTemplates, newTemplates) {
212-
if (_.size(oldTemplates) !== _.size(newTemplates)) {
211+
if (oldTemplates.length !== newTemplates.length) {
213212
return false;
214213
}
215214

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const messages = {
2222
};
2323

2424
function validateNotificationTypes(notificationTypes) {
25-
for(notificationType of notificationTypes){
25+
for(let notificationType of notificationTypes){
2626
if (!("NotificationTypeKey" in notificationType)) {
2727
LOG._warn && LOG.warn(messages.INVALID_NOTIFICATION_TYPES);
2828
return false;

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
"@sap/cds-dk": "^7.3.1"
1717
},
1818
"dependencies": {
19-
"@sap-cloud-sdk/connectivity": "3.5.0",
20-
"@sap-cloud-sdk/http-client": "3.5.0",
21-
"@sap-cloud-sdk/util": "3.5.0",
22-
"lodash": "4.17.21"
19+
"@sap-cloud-sdk/connectivity": "^3.5.0",
20+
"@sap-cloud-sdk/http-client": "^3.5.0",
21+
"@sap-cloud-sdk/util": "^3.5.0"
2322
},
2423
"devDependencies": {
2524
"jest": "^29.7.0",

srv/notifyToRest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const NotificationService = require("./service")
33
const { buildHeadersForDestination } = require("@sap-cloud-sdk/connectivity");
44
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
55
const { getNotificationDestination } = require("../lib/utils");
6+
const cds = require("@sap/cds");
67
const LOG = cds.log('notifications');
78
const NOTIFICATIONS_API_ENDPOINT = "v2/Notification.svc";
89

test/lib/content-deployment.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// import required modules and functions
2-
const cds = require("@sap/cds");
32
const { validateNotificationTypes, readFile } = require("../../lib/utils");
43
const { processNotificationTypes } = require("../../lib/notificationTypes");
54
const { setGlobalLogLevel } = require("@sap-cloud-sdk/util");

0 commit comments

Comments
 (0)