diff --git a/cds-plugin.js b/cds-plugin.js index f0490a3..1275029 100644 --- a/cds-plugin.js +++ b/cds-plugin.js @@ -1,7 +1,7 @@ const cds = require('@sap/cds') const isChangeTracked = (entity) => ( - entity['@changelog'] || entity['@changelog.keys'] + entity['@changelog'] || entity.elements && Object.values(entity.elements).some(e => e['@changelog']) ) diff --git a/lib/entity-helper.js b/lib/entity-helper.js index d69e942..21815ea 100644 --- a/lib/entity-helper.js +++ b/lib/entity-helper.js @@ -73,7 +73,7 @@ const getCurObjFromReqData = function (reqData, nodePathVal, pathVal) { async function getObjectId (entityName, fields, curObj) { let all = [], { curObjFromReqData: req_data={}, curObjFromDbQuery: db_data={} } = curObj let entity = cds.model.definitions[entityName] - if (!fields?.length) fields = entity["@changelog.keys"]?.map(k => k['='] || k) || [] + if (!fields?.length) fields = entity["@changelog"]?.map?.(k => k['='] || k) || [] for (let field of fields) { let path = field.split('.') if (path.length > 1) { diff --git a/tests/bookshop/db/schema.cds b/tests/bookshop/db/schema.cds index a77427b..fd0f782 100644 --- a/tests/bookshop/db/schema.cds +++ b/tests/bookshop/db/schema.cds @@ -67,7 +67,7 @@ entity Authors : managed, cuid { } @title : '{i18n>volumns.objectTitle}' -@changelog.keys : [title] +@changelog : [title] entity Volumns : managed, cuid { @changelog @title : '{i18n>volumns.title}' @@ -80,7 +80,7 @@ entity Volumns : managed, cuid { } @title : '{i18n>bookStoreRegistry.objectTitle}' -@changelog.keys : [code] +@changelog : [code] entity BookStoreRegistry : managed, cuid { @title : '{i18n>bookStoreRegistry.code}' code : String; diff --git a/tests/bookshop/srv/admin-service.cds b/tests/bookshop/srv/admin-service.cds index 8af503a..a8741d4 100644 --- a/tests/bookshop/srv/admin-service.cds +++ b/tests/bookshop/srv/admin-service.cds @@ -17,7 +17,7 @@ annotate AdminService.Authors with { name @(Common.Label : '{i18n>serviceAuthors.name}'); }; -annotate AdminService.BookStores with @changelog.keys : [name]{ +annotate AdminService.BookStores with @changelog : [name]{ name @changelog; location @changelog; books @changelog : [books.title]; @@ -29,7 +29,7 @@ annotate AdminService.BookStores with @changelog.keys : [name]{ }; -annotate AdminService.Books with @changelog.keys : [ +annotate AdminService.Books with @changelog : [ title, author.name.firstName, author.name.lastName @@ -47,7 +47,7 @@ annotate AdminService.Books with @changelog.keys : [ ]; }; -annotate AdminService.Authors with @changelog.keys : [ +annotate AdminService.Authors with @changelog : [ name.firstName, name.lastName ]{ diff --git a/tests/integration/fiori-draft-disabled.test.js b/tests/integration/fiori-draft-disabled.test.js index 1350c7e..18d8b59 100644 --- a/tests/integration/fiori-draft-disabled.test.js +++ b/tests/integration/fiori-draft-disabled.test.js @@ -179,7 +179,7 @@ describe("change log draft disabled test", () => { }); it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { - cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [ + cds.services.AdminService.entities.OrderItem["@changelog"] = [ { "=": "customer.city" }, { "=": "order.status" }, { "=": "price" }, @@ -194,11 +194,11 @@ describe("change log draft disabled test", () => { const change = changes[0]; expect(change.objectID).to.equal("Ōsaka, Post, 5, 14"); - delete cds.services.AdminService.entities.OrderItem["@changelog.keys"]; + delete cds.services.AdminService.entities.OrderItem["@changelog"]; }); it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { - cds.services.AdminService.entities.Authors["@changelog.keys"] = [ + cds.services.AdminService.entities.Authors["@changelog"] = [ { "=": "placeOfBirth" }, { "=": "name.firstName" }, { "=": "name.lastName" }, @@ -216,14 +216,14 @@ describe("change log draft disabled test", () => { const change = changes[0]; expect(change.objectID).to.equal("new placeOfBirth, Emily, Brontë, Haworth, Yorkshire, 1848-12-19, 1818-07-30"); - cds.services.AdminService.entities.Authors["@changelog.keys"] = [ + cds.services.AdminService.entities.Authors["@changelog"] = [ { "=": "name.firstName" }, { "=": "name.lastName" }, ]; }); it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { - cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [ + cds.services.AdminService.entities.OrderItem["@changelog"] = [ { "=": "customer.city" }, { "=": "order.status" }, { "=": "customer.country" }, @@ -238,7 +238,7 @@ describe("change log draft disabled test", () => { const change = changes[0]; expect(change.objectID).to.equal("Ōsaka, Post, Japan, Honda"); - delete cds.services.AdminService.entities.OrderItem["@changelog.keys"]; + delete cds.services.AdminService.entities.OrderItem["@changelog"]; }); 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", () => { }); it("7.2 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => { - cds.services.AdminService.entities.OrderItem["@changelog.keys"] = [ + cds.services.AdminService.entities.OrderItem["@changelog"] = [ { "=": "order.report.comment" }, { "=": "order.status" }, { "=": "customer.name" }, @@ -296,7 +296,7 @@ describe("change log draft disabled test", () => { const change = changes[0]; expect(change.objectID).to.equal("some comment, Post, Honda"); - delete cds.services.AdminService.entities.OrderItem["@changelog.keys"]; + delete cds.services.AdminService.entities.OrderItem["@changelog"]; }); 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", () => { }); 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 () => { - cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }]; + cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }]; await PATCH(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)`, { header: { ID: "8567d0de-d44f-11ed-afa1-0242ac120002", @@ -352,12 +352,12 @@ describe("change log draft disabled test", () => { expect(headerChange.valueChangedTo).to.equal("Ordered"); expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31"); expect(headerChange.parentObjectID).to.equal("Post"); - delete cds.services.AdminService.entities.Order["@changelog.keys"]; + delete cds.services.AdminService.entities.Order["@changelog"]; }); 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 () => { // Check if the object ID obtaining failed due to lacking parentKey would lead to dump - cds.services.AdminService.entities.Order["@changelog.keys"] = [{ "=": "status" }]; + cds.services.AdminService.entities.Order["@changelog"] = [{ "=": "status" }]; await DELETE(`/admin/Order(ID=0a41a187-a2ff-4df6-bd12-fae8996e6e31)/header`); const changes = await adminService.run(SELECT.from(ChangeView)); @@ -372,6 +372,6 @@ describe("change log draft disabled test", () => { expect(headerChange.valueChangedTo).to.equal(""); expect(headerChange.parentKey).to.equal("0a41a187-a2ff-4df6-bd12-fae8996e6e31"); expect(headerChange.parentObjectID).to.equal("Post"); - delete cds.services.AdminService.entities.Order["@changelog.keys"]; + delete cds.services.AdminService.entities.Order["@changelog"]; }); }); diff --git a/tests/integration/fiori-draft-enabled.test.js b/tests/integration/fiori-draft-enabled.test.js index af200a6..9124203 100644 --- a/tests/integration/fiori-draft-enabled.test.js +++ b/tests/integration/fiori-draft-enabled.test.js @@ -248,10 +248,10 @@ describe("change log integration test", () => { }); it("2.4 Child entity update without objectID annotation - should log object type for object ID (ERP4SMEPREPWORKAPPPLAT-32 ERP4SMEPREPWORKAPPPLAT-613 ERP4SMEPREPWORKAPPPLAT-538)", async () => { - delete cds.services.AdminService.entities.Books["@changelog.keys"]; - delete cds.services.AdminService.entities.BookStores["@changelog.keys"]; - delete cds.db.entities.Books["@changelog.keys"]; - delete cds.db.entities.BookStores["@changelog.keys"]; + delete cds.services.AdminService.entities.Books["@changelog"]; + delete cds.services.AdminService.entities.BookStores["@changelog"]; + delete cds.db.entities.Books["@changelog"]; + delete cds.db.entities.BookStores["@changelog"]; const action = PATCH.bind({}, `/admin/Books(ID=9d703c23-54a8-4eff-81c1-cdce6b8376b1,IsActiveEntity=false)`, { title: "new title", @@ -271,12 +271,12 @@ describe("change log integration test", () => { expect(change.objectID).to.equal("Book"); expect(change.parentObjectID).to.equal("Book Store"); - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "author.name.firstName" }, { "=": "author.name.lastName" }, ]; - cds.services.AdminService.entities.BookStores["@changelog.keys"] = [ + cds.services.AdminService.entities.BookStores["@changelog"] = [ { "=": "name", }, @@ -286,7 +286,7 @@ describe("change log integration test", () => { it("4.1 Annotate multiple native and attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { // After appending object id as below, the object ID sequence should be: // title, author.name.firstName, author.name.lastName, stock, bookStore.name, bookStore.location - cds.services.AdminService.entities.Books["@changelog.keys"].push( + cds.services.AdminService.entities.Books["@changelog"].push( { "=": "stock" }, { "=": "bookStore.name" }, { "=": "bookStore.location" } @@ -330,7 +330,7 @@ describe("change log integration test", () => { // After adjusting object id as below, the object ID sequence should be: // title, bookStore.name, bookStore.location, stock, author.name.firstName, author.name.lastName - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "bookStore.name" }, { "=": "bookStore.location" }, @@ -358,7 +358,7 @@ describe("change log integration test", () => { // After adjusting object id as below, the object ID sequence should be: // bookStore.name, title, bookStore.location, author.name.firstName, stock, author.name.lastName - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "bookStore.name" }, { "=": "title" }, { "=": "bookStore.location" }, @@ -383,7 +383,7 @@ describe("change log integration test", () => { expect(deleteTitleChange.objectID).to.equal("Shakespeare and Company, test title 1, Paris, Emily, 1, Brontë"); // Recover the object ID of entity Books as defined in admin-service - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "author.name.firstName" }, { "=": "author.name.lastName" }, @@ -391,7 +391,7 @@ describe("change log integration test", () => { }); it("4.2 Annotate multiple native attributes as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "price" }, { "=": "title" }, { "=": "stock" }, @@ -415,7 +415,7 @@ describe("change log integration test", () => { const titleChange = titleChanges[0]; expect(titleChange.objectID).to.equal("11.11, new title, 12"); - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "author.name.firstName" }, { "=": "author.name.lastName" }, @@ -423,7 +423,7 @@ describe("change log integration test", () => { }); it("4.3 Annotate multiple attributes comming from one or more associated table as the object ID (ERP4SMEPREPWORKAPPPLAT-913)", async () => { - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "bookStore.location" }, { "=": "author.name.lastName" }, { "=": "author.name.firstName" }, @@ -449,7 +449,7 @@ describe("change log integration test", () => { const titleChange = titleChanges[0]; expect(titleChange.objectID).to.equal("Paris, Brontë, Charlotte, Shakespeare and Company, 16"); - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "author.name.firstName" }, { "=": "author.name.lastName" }, @@ -694,7 +694,7 @@ describe("change log integration test", () => { }); it("6.3 Attributes from the code list could be annotated as object ID (ERP4SMEPREPWORKAPPPLAT-1055)", async () => { - cds.services.AdminService.entities.BookStores["@changelog.keys"] = [ + cds.services.AdminService.entities.BookStores["@changelog"] = [ { "=": "name" }, { "=": "lifecycleStatus.name" }, ]; @@ -726,7 +726,7 @@ describe("change log integration test", () => { expect(lifecycleStatusChange.modification).to.equal("Create"); expect(lifecycleStatusChange.objectID).to.equal("test name, In Preparation"); - cds.services.AdminService.entities.BookStores["@changelog.keys"] = [ + cds.services.AdminService.entities.BookStores["@changelog"] = [ { "=": "lifecycleStatus.name" }, { "=": "name" }, ]; @@ -756,11 +756,11 @@ describe("change log integration test", () => { expect(lifecycleStatusUpdateChange.modification).to.equal("Update"); expect(lifecycleStatusUpdateChange.objectID).to.equal("Closed, new test name"); - cds.services.AdminService.entities.BookStores["@changelog.keys"] = [{ "=": "name" }]; + cds.services.AdminService.entities.BookStores["@changelog"] = [{ "=": "name" }]; }); it("7.1 Annotate fields from chained associated entities as objectID (ERP4SMEPREPWORKAPPPLAT-993)", async () => { - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "bookStore.lifecycleStatus.name" }, { "=": "bookStore.location" }, { "=": "bookStore.city.name" }, @@ -783,7 +783,7 @@ describe("change log integration test", () => { const titleChange = titleChanges[0]; expect(titleChange.objectID).to.equal("In Preparation, Paris, Paris, FR"); - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "bookStore.lifecycleStatus.name" }, { "=": "bookStore.city.country.countryName.name" }, @@ -812,7 +812,7 @@ describe("change log integration test", () => { const deleteTitleChange = deleteTitleChanges[0]; expect(deleteTitleChange.objectID).to.equal("new title, In Preparation, France"); - cds.services.AdminService.entities.Books["@changelog.keys"] = [ + cds.services.AdminService.entities.Books["@changelog"] = [ { "=": "title" }, { "=": "author.name.firstName" }, { "=": "author.name.lastName" }, @@ -877,7 +877,7 @@ describe("change log integration test", () => { }); it("9.1 Localization should handle the cases that reading the change view without required parameters obtained (ERP4SMEPREPWORKAPPPLAT-1414)", async () => { - delete cds.services.AdminService.entities.BookStores["@changelog.keys"]; + delete cds.services.AdminService.entities.BookStores["@changelog"]; const action = POST.bind( {}, `/admin/BookStores(ID=64625905-c234-4d0d-9bc1-283ee8946770,IsActiveEntity=false)/books`, @@ -923,7 +923,7 @@ describe("change log integration test", () => { const bookChangeObjectId = bookElementChanges[3]; expect(bookChangeObjectId.objectID).to.equal(""); - cds.services.AdminService.entities.BookStores["@changelog.keys"] = [ + cds.services.AdminService.entities.BookStores["@changelog"] = [ { "=": "name", }, diff --git a/tests/integration/service-api.test.js b/tests/integration/service-api.test.js index d18ae51..0c55bd6 100644 --- a/tests/integration/service-api.test.js +++ b/tests/integration/service-api.test.js @@ -101,7 +101,7 @@ describe("change log integration test", () => { }); it("10.8 Composition of one node deep updated by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-2913 ERP4SMEPREPWORKAPPPLAT-3063)", async () => { - cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [ + cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [ { "=": "code" }, { "=": "validOn" }, ]; @@ -127,7 +127,7 @@ describe("change log integration test", () => { expect(changes[0].valueChangedTo).to.equal("2022-01-01"); expect(changes[0].parentKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770"); expect(changes[0].parentObjectID).to.equal("Shakespeare and Company"); - cds.services.AdminService.entities.BookStoreRegistry["@changelog.keys"] = [{ "=": "code" }]; + cds.services.AdminService.entities.BookStoreRegistry["@changelog"] = [{ "=": "code" }]; }); it("10.9 Child entity deep delete by QL API - should log changes on root entity (ERP4SMEPREPWORKAPPPLAT-3063)", async () => {