Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0e307f9
New test for discard deleting content
eric-pSAP Feb 5, 2026
16ddf40
Update tests/integration/attachments.test.js
eric-pSAP Feb 5, 2026
832532d
Merge branch 'main' into deletingDiscardDraft
eric-pSAP Feb 5, 2026
dace316
req.diff() replaced
eric-pSAP Feb 10, 2026
24ed48c
Remove semicolons
eric-pSAP Feb 10, 2026
7172d56
Better filter out attachment compositions
eric-pSAP Feb 11, 2026
256418b
Refactor columns selection
eric-pSAP Feb 11, 2026
d3aa0c0
Syntax adjustment
eric-pSAP Feb 11, 2026
ddb26cf
Remove initial *
eric-pSAP Feb 12, 2026
3925a82
Initial commit for single attachment
eric-pSAP Feb 18, 2026
ca1e765
Merge branch 'main' into singleAttachment
eric-pSAP Feb 18, 2026
8a1d26c
Update tests/incidents-app/db/schema.cds
eric-pSAP Feb 18, 2026
ee53aaa
Fix bot edit
eric-pSAP Feb 18, 2026
19e40c7
ID checks to make bot happy
eric-pSAP Feb 18, 2026
9771096
Remove reference to non-existent field
eric-pSAP Feb 18, 2026
8dd385a
Prettier should ignore test headers
eric-pSAP Feb 18, 2026
0edf07f
Clean up indentation
eric-pSAP Feb 18, 2026
f00bb12
Data added and tests updated
eric-pSAP Feb 20, 2026
06b68c0
Prettier
eric-pSAP Feb 20, 2026
888a2a0
Merge branch 'main' into singleAttachment
eric-pSAP Feb 20, 2026
531f68f
Code refactoring
eric-pSAP Apr 15, 2026
c516c04
Test bug fixes 1
eric-pSAP Apr 15, 2026
fd7d395
Basic size limit bug fix
eric-pSAP Apr 16, 2026
53ecb16
ESLint 10 for testing
eric-pSAP Apr 16, 2026
4bc262e
POST size limit bug fix
eric-pSAP Apr 16, 2026
863aa22
Merge remote-tracking branch 'origin/main' into singleAttachment
eric-pSAP Apr 16, 2026
f51f4c4
Merge
eric-pSAP Apr 16, 2026
2f3aefa
More merge conflict resolution
eric-pSAP Apr 16, 2026
1823042
Lint fixes
eric-pSAP Apr 16, 2026
3629fdd
Make lint happy
eric-pSAP Apr 16, 2026
2e2d6c6
Make Postgres happy
eric-pSAP Apr 16, 2026
b5f0012
Merge conflict
eric-pSAP Apr 17, 2026
e622052
Merge conflict
eric-pSAP Apr 17, 2026
b275606
Naming of tests fixed
eric-pSAP Apr 17, 2026
e50a472
Re-add conditional changes
eric-pSAP Apr 17, 2026
df5eecc
Remove attachment hard-coding
eric-pSAP Apr 17, 2026
0be1e75
Bug fixes
eric-pSAP Apr 17, 2026
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
16 changes: 10 additions & 6 deletions db/index.cds
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The common root-level aspect used in applications like that:
// using { Attachments } from '@cap-js/attachments'
aspect Attachments : sap.attachments.Attachments {}
type Attachment : sap.attachments.Attachment;

using {
managed,
Expand All @@ -10,16 +11,19 @@ using {

context sap.attachments {

aspect MediaData @(_is_media_data) {
type Attachment @(_is_media_data) {
url : String @UI.Hidden;
content : LargeBinary @title: '{i18n>Attachment}'; // only for db-based services
content : LargeBinary @title: '{i18n>Attachment}' @Core.MediaType: 'application/octet-stream'; // only for db-based services
mimeType : String default 'application/octet-stream' @title: '{i18n>MediaType}';
filename : String @title: '{i18n>FileName}';
hash : String @UI.Hidden @Core.Computed;
status : String default 'Unscanned' @title: '{i18n>ScanStatus}' @Common.Text: statusNav.name @Common.TextArrangement: #TextOnly;
hash : String @UI.Hidden @Core.Computed;
status : String default 'Unscanned' @title: '{i18n>ScanStatus}' @readonly;
lastScan : Timestamp @title: '{i18n>LastScan}' @Core.Computed @readonly;
}

aspect MediaData : Attachment {
statusNav : Association to one ScanStates
on statusNav.code = status;
lastScan : Timestamp @title: '{i18n>LastScan}' @Core.Computed;
}

entity ScanStates : CodeList {
Expand Down Expand Up @@ -48,7 +52,7 @@ context sap.attachments {
annotate MediaData with @UI.MediaResource: {Stream: content} {
content @Core.MediaType: mimeType @odata.draft.skip;
mimeType @Core.IsMediaType;
status @readonly;
status @Common.Text: statusNav.name @Common.TextArrangement: #TextOnly;
}

annotate Attachments with @UI: {
Expand Down
17 changes: 17 additions & 0 deletions lib/csn-runtime-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ function collectAttachments(
return resultSet
}

function getInlineAttachmentPrefixes(entity) {
if (entity?.["@_is_media_data"]) return [] // entity itself is composition-based
const prefixes = []
for (const [name, elem] of Object.entries(entity?.elements ?? {})) {
if (name.endsWith("_content") && elem?.["@_is_media_data"]) {
prefixes.push(name.slice(0, -"_content".length))
}
}
return prefixes
}

function hasAttachmentsComposition(entity, visitedEdges = new Set()) {
if (!entity?.compositions) return false

Expand Down Expand Up @@ -57,6 +68,12 @@ Object.defineProperty(cds.builtin.classes.entity.prototype, "_attachments", {
get isAttachmentsEntity() {
return !!entity?.["@_is_media_data"]
},
get inlineAttachmentPrefixes() {
return getInlineAttachmentPrefixes(entity)
},
get hasInlineAttachments() {
return getInlineAttachmentPrefixes(entity).length > 0
},
}
},
})
Loading
Loading