Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments namespace #120

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.1.10

### Changed

- Usage while importing changed from `using { Attachments } from '@cap-js/attachments'` to `using { sap.attachments.Attachments } from '@cap-js/attachments'`.

## Version 1.1.9

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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 {
// ...
Expand Down
1 change: 1 addition & 0 deletions index.cds
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using { managed, cuid } from '@sap/cds/common';
namespace sap.attachments;

aspect MediaData @(_is_media_data) {
url : String;
Expand Down
5 changes: 2 additions & 3 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const DEBUG = LOG._debug ? LOG.debug : undefined;
const attachmentIDRegex = /\/\w+\(.*ID=([0-9a-fA-F-]{36})/;

cds.on("loaded", function unfoldModel(csn) {
if (!("Attachments" in csn.definitions)) return;
if (!("sap.attachments.Attachments" in csn.definitions)) return;
const csnCopy = structuredClone(csn)
cds.linked(csnCopy).forall("Composition", (comp) => {
if (comp._target && comp._target["@_is_media_data"] && comp.parent && comp.is2many) {
Expand All @@ -23,8 +23,7 @@ cds.on("loaded", 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
Expand Down
2 changes: 1 addition & 1 deletion tests/incidents-app/db/attachments.cds
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/attachments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
let utils = null;
let sampleDocID = null;
let incidentID = null;
let db = null;

Check warning on line 15 in tests/integration/attachments.test.js

View workflow job for this annotation

GitHub Actions / lint

'db' is assigned a value but never used
let attachmentsService = null;

Check warning on line 16 in tests/integration/attachments.test.js

View workflow job for this annotation

GitHub Actions / lint

'attachmentsService' is assigned a value but never used

describe("Tests for uploading/deleting attachments through API calls - in-memory db", () => {
beforeAll(async () => {
Expand Down Expand Up @@ -72,7 +72,7 @@
} catch (err) {
expect(err).to.be.undefined;
}

// api call, table name
//read attachment in active table
try {
const response = await GET(
Expand Down Expand Up @@ -158,7 +158,7 @@

//content should not be there
try {
const response = await GET(

Check warning on line 161 in tests/integration/attachments.test.js

View workflow job for this annotation

GitHub Actions / lint

'response' is assigned a value but never used
`odata/v4/processor/Incidents(ID=${incidentID},IsActiveEntity=true)/attachments(up__ID=${incidentID},ID=${sampleDocID},IsActiveEntity=true)/content`
);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion xmpl/db/attachments.cds
Original file line number Diff line number Diff line change
@@ -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;
Expand Down