kalai-attach 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,19 +13,30 @@ function collectAttachments(ent, resultSet = [], path = []) {
13
13
  return resultSet
14
14
  }
15
15
 
16
- Object.defineProperty(cds.builtin.classes.entity.prototype, '_attachments', {
17
- get() {
18
- const entity = this;
19
- return {
20
- get hasAttachmentsComposition() {
21
- return entity.compositions && Object.keys(entity.compositions).some(ele => entity.compositions[ele]._target?.["@_is_media_data"] || entity.compositions[ele]._target?._attachments?.hasAttachmentsComposition)
22
- },
23
- get attachmentCompositions() {
24
- return collectAttachments(entity)
25
- },
26
- get isAttachmentsEntity() {
27
- return !!entity?.["@_is_media_data"]
28
- }
29
- }
30
- },
31
- })
16
+ // Check if the property already exists to prevent crashes
17
+ if (!Object.prototype.hasOwnProperty.call(cds.builtin.classes.entity.prototype, '_attachments')) {
18
+
19
+ Object.defineProperty(cds.builtin.classes.entity.prototype, '_attachments', {
20
+ configurable: true, // <--- CRITICAL: Allows redefinition/extension without crashing
21
+ enumerable: false,
22
+ get() {
23
+ const entity = this;
24
+ return {
25
+ get hasAttachmentsComposition() {
26
+ return entity.compositions &&
27
+ Object.keys(entity.compositions).some(ele =>
28
+ entity.compositions[ele]._target?.["@_is_media_data"] ||
29
+ entity.compositions[ele]._target?._attachments?.hasAttachmentsComposition
30
+ );
31
+ },
32
+ get attachmentCompositions() {
33
+ // Ensure collectAttachments is imported/available in your lib
34
+ return collectAttachments(entity);
35
+ },
36
+ get isAttachmentsEntity() {
37
+ return !!entity?.["@_is_media_data"];
38
+ }
39
+ };
40
+ },
41
+ });
42
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kalai-attach",
3
3
  "description": "CAP cds-plugin providing image and attachment storing out-of-the-box.",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "repository": "capjsattachments-kalai",
6
6
  "author": "Kalai",
7
7
  "homepage": "https://github.com/Kalaikovan-airdit",
@@ -42,10 +42,10 @@
42
42
  "requires": {
43
43
  "kinds": {
44
44
  "attachments-azure": {
45
- "impl": "./srv/azure-blob-storage"
45
+ "impl": "kalai-attach/srv/azure-blob-storage"
46
46
  },
47
47
  "malwareScanner-mocked": {
48
- "model": "./srv/malwareScanner-mocked"
48
+ "model": "kalai-attach/srv/malwareScanner-mocked"
49
49
  }
50
50
  },
51
51
  "attachments": {