diff --git a/CHANGELOG.md b/CHANGELOG.md index 4889b98d..687a593b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Changed - Removed `@sap/xsenv` dependency. +- Attachments usage changed to `using { sap.attachments.Attachments } from '@cap-js/attachments'`. ## Version 1.2.1 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7feab975..14c0ccb5 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ In this guide, we use the [Incidents Management reference sample app](https://gi To use Attachments, simply add an element referring to the pre-defined `Attachments` type as follows: ```cds -using { Attachments } from '@cap-js/attachments'; +using { sap.attachments.Attachments } from '@cap-js/attachments'; entity Incidents { // ... @@ -49,6 +49,8 @@ entity Incidents { } ``` +> [! Important Note] +> Starting from version 2.0.0, the usage of attachments has changed. In the updated version, it should be using { sap.attachments.Attachments }. Be sure to update your code to reflect this change for compatibility. ## Test-drive Locally With the steps above, we have successfully set up asset handling for our reference application. Let's see that in action. diff --git a/index.cds b/index.cds index 77169e18..a8ffc0a0 100644 --- a/index.cds +++ b/index.cds @@ -1,4 +1,5 @@ using { managed, cuid } from '@sap/cds/common'; +namespace sap.attachments; aspect MediaData @(_is_media_data) { url : String; diff --git a/lib/plugin.js b/lib/plugin.js index 926a891d..f2e42d06 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -5,10 +5,9 @@ const DEBUG = LOG._debug ? LOG.debug : undefined const attachmentIDRegex = /\/\w+\(.*ID=([0-9a-fA-F-]{36})/ cds.on(cds.version >= "8.6.0" ? "compile.to.edmx" : "loaded", unfoldModel); - function unfoldModel (csn) { const meta = csn.meta ??= {} - if (!("Attachments" in csn.definitions)) return + if (!("sap.attachments.Attachments" in csn.definitions)) return if (meta._enhanced_for_attachments) return // const csnCopy = structuredClone(csn) // REVISIT: Why did we add this cloning? cds.linked(csn).forall("Composition", (comp) => { @@ -27,10 +26,8 @@ function unfoldModel (csn) { } cds.once("served", async function registerPluginHandlers () { - if (!("Attachments" in cds.model.definitions)) return - + if (!("sap.attachments.Attachments" in cds.model.definitions)) return const AttachmentsSrv = await cds.connect.to("attachments") - // Searching all associations to attachments to add respective handlers for (let srv of cds.services) { if (srv instanceof cds.ApplicationService) { diff --git a/tests/incidents-app/db/attachments.cds b/tests/incidents-app/db/attachments.cds index f58acd59..68b203d7 100644 --- a/tests/incidents-app/db/attachments.cds +++ b/tests/incidents-app/db/attachments.cds @@ -1,6 +1,6 @@ using { sap.capire.incidents as my } from './schema'; -using { Attachments } from '@cap-js/attachments'; +using { sap.attachments.Attachments } from '@cap-js/attachments'; extend my.Incidents with { attachments: Composition of many Attachments; diff --git a/tests/integration/attachments.test.js b/tests/integration/attachments.test.js index e7216b4e..ed564478 100644 --- a/tests/integration/attachments.test.js +++ b/tests/integration/attachments.test.js @@ -72,7 +72,6 @@ describe("Tests for uploading/deleting attachments through API calls - in-memory } catch (err) { expect(err).to.be.undefined; } - //read attachment in active table try { const response = await GET( diff --git a/xmpl/db/attachments.cds b/xmpl/db/attachments.cds index c2b281cb..f5c4418e 100644 --- a/xmpl/db/attachments.cds +++ b/xmpl/db/attachments.cds @@ -1,6 +1,6 @@ using { sap.capire.incidents as my } from '@capire/incidents/db/schema'; -using { Attachments } from '@cap-js/attachments'; +using { sap.attachments.Attachments } from '@cap-js/attachments'; extend my.Incidents with { attachments: Composition of many Attachments;