Skip to content

Commit 15681c6

Browse files
authored
@changelog.keys -> @changelog (#23)
...
1 parent 92e496f commit 15681c6

File tree

7 files changed

+43
-43
lines changed

7 files changed

+43
-43
lines changed

cds-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const cds = require('@sap/cds')
22

33
const isChangeTracked = (entity) => (
4-
entity['@changelog'] || entity['@changelog.keys']
4+
entity['@changelog']
55
|| entity.elements && Object.values(entity.elements).some(e => e['@changelog'])
66
)
77

lib/entity-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const getCurObjFromReqData = function (reqData, nodePathVal, pathVal) {
7373
async function getObjectId (entityName, fields, curObj) {
7474
let all = [], { curObjFromReqData: req_data={}, curObjFromDbQuery: db_data={} } = curObj
7575
let entity = cds.model.definitions[entityName]
76-
if (!fields?.length) fields = entity["@changelog.keys"]?.map(k => k['='] || k) || []
76+
if (!fields?.length) fields = entity["@changelog"]?.map?.(k => k['='] || k) || []
7777
for (let field of fields) {
7878
let path = field.split('.')
7979
if (path.length > 1) {

tests/bookshop/db/schema.cds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ entity Authors : managed, cuid {
6767
}
6868

6969
@title : '{i18n>volumns.objectTitle}'
70-
@changelog.keys : [title]
70+
@changelog : [title]
7171
entity Volumns : managed, cuid {
7272
@changelog
7373
@title : '{i18n>volumns.title}'
@@ -80,7 +80,7 @@ entity Volumns : managed, cuid {
8080
}
8181

8282
@title : '{i18n>bookStoreRegistry.objectTitle}'
83-
@changelog.keys : [code]
83+
@changelog : [code]
8484
entity BookStoreRegistry : managed, cuid {
8585
@title : '{i18n>bookStoreRegistry.code}'
8686
code : String;

tests/bookshop/srv/admin-service.cds

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ annotate AdminService.Authors with {
1717
name @(Common.Label : '{i18n>serviceAuthors.name}');
1818
};
1919

20-
annotate AdminService.BookStores with @changelog.keys : [name]{
20+
annotate AdminService.BookStores with @changelog : [name]{
2121
name @changelog;
2222
location @changelog;
2323
books @changelog : [books.title];
@@ -29,7 +29,7 @@ annotate AdminService.BookStores with @changelog.keys : [name]{
2929
};
3030

3131

32-
annotate AdminService.Books with @changelog.keys : [
32+
annotate AdminService.Books with @changelog : [
3333
title,
3434
author.name.firstName,
3535
author.name.lastName
@@ -47,7 +47,7 @@ annotate AdminService.Books with @changelog.keys : [
4747
];
4848
};
4949

50-
annotate AdminService.Authors with @changelog.keys : [
50+
annotate AdminService.Authors with @changelog : [
5151
name.firstName,
5252
name.lastName
5353
]{

tests/integration/fiori-draft-disabled.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe("change log draft disabled test", () => {
179179
});
180180

181181
it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
182-
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
182+
cds.services.AdminService.entities.OrderItem["@changelog"] = [
183183
{ "=": "customer.city" },
184184
{ "=": "order.status" },
185185
{ "=": "price" },
@@ -194,11 +194,11 @@ describe("change log draft disabled test", () => {
194194
const change = changes[0];
195195
expect(change.objectID).to.equal("Ōsaka, Post, 5, 14");
196196

197-
delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
197+
delete cds.services.AdminService.entities.OrderItem["@changelog"];
198198
});
199199

200200
it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
201-
cds.services.AdminService.entities.Authors["@changelog.keys"] = [
201+
cds.services.AdminService.entities.Authors["@changelog"] = [
202202
{ "=": "placeOfBirth" },
203203
{ "=": "name.firstName" },
204204
{ "=": "name.lastName" },
@@ -216,14 +216,14 @@ describe("change log draft disabled test", () => {
216216
const change = changes[0];
217217
expect(change.objectID).to.equal("new placeOfBirth, Emily, Brontë, Haworth, Yorkshire, 1848-12-19, 1818-07-30");
218218

219-
cds.services.AdminService.entities.Authors["@changelog.keys"] = [
219+
cds.services.AdminService.entities.Authors["@changelog"] = [
220220
{ "=": "name.firstName" },
221221
{ "=": "name.lastName" },
222222
];
223223
});
224224

225225
it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
226-
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
226+
cds.services.AdminService.entities.OrderItem["@changelog"] = [
227227
{ "=": "customer.city" },
228228
{ "=": "order.status" },
229229
{ "=": "customer.country" },
@@ -238,7 +238,7 @@ describe("change log draft disabled test", () => {
238238
const change = changes[0];
239239
expect(change.objectID).to.equal("Ōsaka, Post, Japan, Honda");
240240

241-
delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
241+
delete cds.services.AdminService.entities.OrderItem["@changelog"];
242242
});
243243

244244
it("5.1 value data type records data type of native attributes of the entity or attributes from association table which are annotated as the displayed value(ERP4SMEPREPWORKAPPPLAT-873)", async () => {
@@ -282,7 +282,7 @@ describe("change log draft disabled test", () => {
282282
});
283283

284284
it("7.2 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => {
285-
cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [
285+
cds.services.AdminService.entities.OrderItem["@changelog"] = [
286286
{ "=": "order.report.comment" },
287287
{ "=": "order.status" },
288288
{ "=": "customer.name" },
@@ -296,7 +296,7 @@ describe("change log draft disabled test", () => {
296296
const change = changes[0];
297297
expect(change.objectID).to.equal("some comment, Post, Honda");
298298

299-
delete cds.services.AdminService.entities.OrderItem["@changelog.keys"];
299+
delete cds.services.AdminService.entities.OrderItem["@changelog"];
300300
});
301301

302302
it("8.2 Annotate fields from chained associated entities as displayed value (ERP4SMEPREPWORKAPPPLAT-1094)", async () => {
@@ -332,7 +332,7 @@ describe("change log draft disabled test", () => {
332332
});
333333

334334
it("10.2 Composition of one update by odata request on draft disabled entity - should log changes for root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
335-
cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }];
335+
cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }];
336336
await PATCH(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)`, {
337337
header: {
338338
ID: "8567d0de-d44f-11ed-afa1-0242ac120002",
@@ -352,12 +352,12 @@ describe("change log draft disabled test", () => {
352352
expect(headerChange.valueChangedTo).to.equal("Ordered");
353353
expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31");
354354
expect(headerChange.parentObjectID).to.equal("Post");
355-
delete cds.services.AdminService.entities.Order["@changelog.keys"];
355+
delete cds.services.AdminService.entities.Order["@changelog"];
356356
});
357357

358358
it("10.3 Composition of one delete by odata request on draft disabled entity - should log changes for root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
359359
// Check if the object ID obtaining failed due to lacking parentKey would lead to dump
360-
cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }];
360+
cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }];
361361
await DELETE(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)/header`);
362362

363363
const changes = await adminService.run(SELECT.from(ChangeView));
@@ -372,6 +372,6 @@ describe("change log draft disabled test", () => {
372372
expect(headerChange.valueChangedTo).to.equal("");
373373
expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31");
374374
expect(headerChange.parentObjectID).to.equal("Post");
375-
delete cds.services.AdminService.entities.Order["@changelog.keys"];
375+
delete cds.services.AdminService.entities.Order["@changelog"];
376376
});
377377
});

tests/integration/fiori-draft-enabled.test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ describe("change log integration test", () => {
248248
});
249249

250250
it("2.4 Child entity update without objectID annotation - should log object type for object ID (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613 ERP4SMEPREPWORKAPPPLAT-538)", async () => {
251-
delete cds.services.AdminService.entities.Books["@changelog.keys"];
252-
delete cds.services.AdminService.entities.BookStores["@changelog.keys"];
253-
delete cds.db.entities.Books["@changelog.keys"];
254-
delete cds.db.entities.BookStores["@changelog.keys"];
251+
delete cds.services.AdminService.entities.Books["@changelog"];
252+
delete cds.services.AdminService.entities.BookStores["@changelog"];
253+
delete cds.db.entities.Books["@changelog"];
254+
delete cds.db.entities.BookStores["@changelog"];
255255

256256
const action = PATCH.bind({}, `/admin/Books(ID=9d703c23-54a8-4eff-81c1-cdce6b8376b1,IsActiveEntity=false)`, {
257257
title: "new title",
@@ -271,12 +271,12 @@ describe("change log integration test", () => {
271271
expect(change.objectID).to.equal("Book");
272272
expect(change.parentObjectID).to.equal("Book Store");
273273

274-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
274+
cds.services.AdminService.entities.Books["@changelog"] = [
275275
{ "=": "title" },
276276
{ "=": "author.name.firstName" },
277277
{ "=": "author.name.lastName" },
278278
];
279-
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
279+
cds.services.AdminService.entities.BookStores["@changelog"] = [
280280
{
281281
"=": "name",
282282
},
@@ -286,7 +286,7 @@ describe("change log integration test", () => {
286286
it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
287287
// After appending object id as below, the object ID sequence should be:
288288
// title, author.name.firstName, author.name.lastName, stock, bookStore.name, bookStore.location
289-
cds.services.AdminService.entities.Books["@changelog.keys"].push(
289+
cds.services.AdminService.entities.Books["@changelog"].push(
290290
{ "=": "stock" },
291291
{ "=": "bookStore.name" },
292292
{ "=": "bookStore.location" }
@@ -330,7 +330,7 @@ describe("change log integration test", () => {
330330

331331
// After adjusting object id as below, the object ID sequence should be:
332332
// title, bookStore.name, bookStore.location, stock, author.name.firstName, author.name.lastName
333-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
333+
cds.services.AdminService.entities.Books["@changelog"] = [
334334
{ "=": "title" },
335335
{ "=": "bookStore.name" },
336336
{ "=": "bookStore.location" },
@@ -358,7 +358,7 @@ describe("change log integration test", () => {
358358

359359
// After adjusting object id as below, the object ID sequence should be:
360360
// bookStore.name, title, bookStore.location, author.name.firstName, stock, author.name.lastName
361-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
361+
cds.services.AdminService.entities.Books["@changelog"] = [
362362
{ "=": "bookStore.name" },
363363
{ "=": "title" },
364364
{ "=": "bookStore.location" },
@@ -383,15 +383,15 @@ describe("change log integration test", () => {
383383
expect(deleteTitleChange.objectID).to.equal("Shakespeare and Company, test title 1, Paris, Emily, 1, Brontë");
384384

385385
// Recover the object ID of entity Books as defined in admin-service
386-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
386+
cds.services.AdminService.entities.Books["@changelog"] = [
387387
{ "=": "title" },
388388
{ "=": "author.name.firstName" },
389389
{ "=": "author.name.lastName" },
390390
];
391391
});
392392

393393
it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
394-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
394+
cds.services.AdminService.entities.Books["@changelog"] = [
395395
{ "=": "price" },
396396
{ "=": "title" },
397397
{ "=": "stock" },
@@ -415,15 +415,15 @@ describe("change log integration test", () => {
415415
const titleChange = titleChanges[0];
416416
expect(titleChange.objectID).to.equal("11.11, new title, 12");
417417

418-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
418+
cds.services.AdminService.entities.Books["@changelog"] = [
419419
{ "=": "title" },
420420
{ "=": "author.name.firstName" },
421421
{ "=": "author.name.lastName" },
422422
];
423423
});
424424

425425
it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => {
426-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
426+
cds.services.AdminService.entities.Books["@changelog"] = [
427427
{ "=": "bookStore.location" },
428428
{ "=": "author.name.lastName" },
429429
{ "=": "author.name.firstName" },
@@ -449,7 +449,7 @@ describe("change log integration test", () => {
449449
const titleChange = titleChanges[0];
450450
expect(titleChange.objectID).to.equal("Paris, Brontë, Charlotte, Shakespeare and Company, 16");
451451

452-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
452+
cds.services.AdminService.entities.Books["@changelog"] = [
453453
{ "=": "title" },
454454
{ "=": "author.name.firstName" },
455455
{ "=": "author.name.lastName" },
@@ -694,7 +694,7 @@ describe("change log integration test", () => {
694694
});
695695

696696
it("6.3 Attributes from the code list could be annotated as object ID (ERP4SMEPREPWORKAPPPLAT-1055)", async () => {
697-
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
697+
cds.services.AdminService.entities.BookStores["@changelog"] = [
698698
{ "=": "name" },
699699
{ "=": "lifecycleStatus.name" },
700700
];
@@ -726,7 +726,7 @@ describe("change log integration test", () => {
726726
expect(lifecycleStatusChange.modification).to.equal("Create");
727727
expect(lifecycleStatusChange.objectID).to.equal("test name, In Preparation");
728728

729-
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
729+
cds.services.AdminService.entities.BookStores["@changelog"] = [
730730
{ "=": "lifecycleStatus.name" },
731731
{ "=": "name" },
732732
];
@@ -756,11 +756,11 @@ describe("change log integration test", () => {
756756
expect(lifecycleStatusUpdateChange.modification).to.equal("Update");
757757
expect(lifecycleStatusUpdateChange.objectID).to.equal("Closed, new test name");
758758

759-
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [{ "=": "name" }];
759+
cds.services.AdminService.entities.BookStores["@changelog"] = [{ "=": "name" }];
760760
});
761761

762762
it("7.1 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => {
763-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
763+
cds.services.AdminService.entities.Books["@changelog"] = [
764764
{ "=": "bookStore.lifecycleStatus.name" },
765765
{ "=": "bookStore.location" },
766766
{ "=": "bookStore.city.name" },
@@ -783,7 +783,7 @@ describe("change log integration test", () => {
783783
const titleChange = titleChanges[0];
784784
expect(titleChange.objectID).to.equal("In Preparation, Paris, Paris, FR");
785785

786-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
786+
cds.services.AdminService.entities.Books["@changelog"] = [
787787
{ "=": "title" },
788788
{ "=": "bookStore.lifecycleStatus.name" },
789789
{ "=": "bookStore.city.country.countryName.name" },
@@ -812,7 +812,7 @@ describe("change log integration test", () => {
812812
const deleteTitleChange = deleteTitleChanges[0];
813813
expect(deleteTitleChange.objectID).to.equal("new title, In Preparation, France");
814814

815-
cds.services.AdminService.entities.Books["@changelog.keys"] = [
815+
cds.services.AdminService.entities.Books["@changelog"] = [
816816
{ "=": "title" },
817817
{ "=": "author.name.firstName" },
818818
{ "=": "author.name.lastName" },
@@ -877,7 +877,7 @@ describe("change log integration test", () => {
877877
});
878878

879879
it("9.1 Localization should handle the cases that reading the change view without required parameters obtained (ERP4SMEPREPWORKAPPPLAT-1414)", async () => {
880-
delete cds.services.AdminService.entities.BookStores["@changelog.keys"];
880+
delete cds.services.AdminService.entities.BookStores["@changelog"];
881881
const action = POST.bind(
882882
{},
883883
`/admin/BookStores(ID=64625905-c234-4d0d-9bc1-283ee8946770,IsActiveEntity=false)/books`,
@@ -923,7 +923,7 @@ describe("change log integration test", () => {
923923
const bookChangeObjectId = bookElementChanges[3];
924924
expect(bookChangeObjectId.objectID).to.equal("");
925925

926-
cds.services.AdminService.entities.BookStores["@changelog.keys"] = [
926+
cds.services.AdminService.entities.BookStores["@changelog"] = [
927927
{
928928
"=": "name",
929929
},

tests/integration/service-api.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe("change log integration test", () => {
101101
});
102102

103103
it("10.8 Composition of one node deep updated by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => {
104-
cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [
104+
cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [
105105
{ "=": "code" },
106106
{ "=": "validOn" },
107107
];
@@ -127,7 +127,7 @@ describe("change log integration test", () => {
127127
expect(changes[0].valueChangedTo).to.equal("2022-01-01");
128128
expect(changes[0].parentKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770");
129129
expect(changes[0].parentObjectID).to.equal("Shakespeare and Company");
130-
cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [{ "=": "code" }];
130+
cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [{ "=": "code" }];
131131
});
132132

133133
it("10.9 Child entity deep delete by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-3063)", async () => {

0 commit comments

Comments
 (0)