@adobe/spacecat-shared-data-access 1.61.4 → 1.61.6

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.61.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.61.5...@adobe/spacecat-shared-data-access-v1.61.6) (2024-12-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * isNonEmptyArray from utils ([#512](https://github.com/adobe/spacecat-shared/issues/512)) ([21b87ed](https://github.com/adobe/spacecat-shared/commit/21b87edc507f20285355becd5d51a9b7010e9651))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v1.61.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.61.4...@adobe/spacecat-shared-data-access-v1.61.5) (2024-12-30)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * replace expiresAt with recordExporesAt in ImportUrl ([#511](https://github.com/adobe/spacecat-shared/issues/511)) ([7349c9c](https://github.com/adobe/spacecat-shared/commit/7349c9c66659fae4b62edb27e2e03a83a0af2e13))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v1.61.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.61.3...@adobe/spacecat-shared-data-access-v1.61.4) (2024-12-30)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.61.4",
3
+ "version": "1.61.6",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/spacecat-shared-dynamo": "1.5.0",
38
- "@adobe/spacecat-shared-utils": "1.25.0",
38
+ "@adobe/spacecat-shared-utils": "1.25.1",
39
39
  "@aws-sdk/client-dynamodb": "3.716.0",
40
40
  "@aws-sdk/lib-dynamodb": "3.716.0",
41
41
  "@types/joi": "17.2.3",
@@ -12,6 +12,7 @@
12
12
 
13
13
  import {
14
14
  hasText,
15
+ isNonEmptyArray,
15
16
  isNonEmptyObject,
16
17
  isObject,
17
18
  } from '@adobe/spacecat-shared-utils';
@@ -24,7 +25,6 @@ import { createAccessors } from '../../util/accessor.utils.js';
24
25
  import { guardId } from '../../util/guards.js';
25
26
  import {
26
27
  entityNameToAllPKValue,
27
- isNonEmptyArray,
28
28
  removeElectroProperties,
29
29
  } from '../../util/util.js';
30
30
 
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { isNonEmptyObject } from '@adobe/spacecat-shared-utils';
13
+ import { isNonEmptyArray, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import { DataAccessError } from '../../errors/index.js';
16
16
  import { createAccessors } from '../../util/accessor.utils.js';
@@ -19,7 +19,6 @@ import {
19
19
  capitalize,
20
20
  entityNameToIdName,
21
21
  idNameToEntityName,
22
- isNonEmptyArray,
23
22
  } from '../../util/util.js';
24
23
 
25
24
  import Reference from './reference.js';
@@ -204,6 +203,14 @@ class BaseModel {
204
203
  return this.record.updatedAt;
205
204
  }
206
205
 
206
+ /**
207
+ * Gets the expiration timestamp of the current entity.
208
+ * @returns {string} - The ISO string representing when the entity will expire.
209
+ */
210
+ getRecordExpiresAt() {
211
+ return this.record.recordExpiresAt;
212
+ }
213
+
207
214
  /**
208
215
  * Removes the current entity from the database. This method also removes any dependent
209
216
  * entities associated with the current entity. For example, if the current entity has
@@ -21,6 +21,7 @@ export interface BaseModel {
21
21
  _remove(): Promise<this>;
22
22
  getCreatedAt(): string;
23
23
  getId(): string;
24
+ getRecordExpiresAt(): string;
24
25
  getUpdatedAt(): string;
25
26
  remove(): Promise<this>;
26
27
  save(): Promise<this>;
@@ -10,13 +10,12 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { hasText, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
13
+ import { hasText, isNonEmptyArray, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import ReferenceError from '../../errors/reference.error.js';
16
16
  import {
17
17
  entityNameToCollectionName,
18
18
  entityNameToIdName,
19
- isNonEmptyArray,
20
19
  keyNamesToMethodName,
21
20
  referenceToBaseMethodName,
22
21
  } from '../../util/util.js';
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {
14
- hasText, isBoolean, isInteger, isNonEmptyObject,
14
+ hasText, isBoolean, isInteger, isNonEmptyArray, isNonEmptyObject,
15
15
  } from '@adobe/spacecat-shared-utils';
16
16
 
17
17
  import { v4 as uuid, validate as uuidValidate } from 'uuid';
@@ -21,7 +21,7 @@ import {
21
21
  decapitalize,
22
22
  entityNameToAllPKValue,
23
23
  entityNameToIdName,
24
- isNonEmptyArray,
24
+ isPositiveInteger,
25
25
  } from '../../util/util.js';
26
26
 
27
27
  import BaseModel from './base.model.js';
@@ -186,6 +186,29 @@ class SchemaBuilder {
186
186
  return this;
187
187
  }
188
188
 
189
+ /**
190
+ * Sets an expiry time for records in this entity.
191
+ * The record will be automatically removed by DynamoDB
192
+ *
193
+ * @param {number} ttlInDays - The time-to-live (TTL) in days.
194
+ * @returns {SchemaBuilder}
195
+ */
196
+ withRecordExpiry(ttlInDays) {
197
+ if (!isPositiveInteger(ttlInDays)) {
198
+ throw new SchemaBuilderError(this, 'TTL must be a positive integer.');
199
+ }
200
+
201
+ this.addAttribute('recordExpiresAt', {
202
+ type: 'number',
203
+ required: true,
204
+ readOnly: true,
205
+ default: () => Date.now() + ttlInDays * 24 * 60 * 60 * 1000,
206
+ set: () => Date.now() + ttlInDays * 24 * 60 * 60 * 1000,
207
+ });
208
+
209
+ return this;
210
+ }
211
+
189
212
  /**
190
213
  * By default a schema allows removes. This method allows
191
214
  * to disable removes for this entity. Note that this does
@@ -10,14 +10,13 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { hasText, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
13
+ import { hasText, isNonEmptyArray, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import { SchemaError, SchemaValidationError } from '../../errors/index.js';
16
16
  import {
17
17
  classExtends,
18
18
  entityNameToCollectionName,
19
19
  entityNameToIdName,
20
- isNonEmptyArray,
21
20
  isPositiveInteger,
22
21
  keyNamesToMethodName,
23
22
  modelNameToEntityName,
@@ -12,7 +12,7 @@
12
12
 
13
13
  /* c8 ignore start */
14
14
 
15
- import { isIsoDate, isValidUrl } from '@adobe/spacecat-shared-utils';
15
+ import { isValidUrl } from '@adobe/spacecat-shared-utils';
16
16
 
17
17
  import SchemaBuilder from '../base/schema.builder.js';
18
18
  import ImportUrl from './import-url.model.js';
@@ -26,17 +26,8 @@ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
26
26
  */
27
27
 
28
28
  const schema = new SchemaBuilder(ImportUrl, ImportUrlCollection)
29
+ .withRecordExpiry(ImportUrl.IMPORT_URL_EXPIRES_IN_DAYS)
29
30
  .addReference('belongs_to', 'ImportJob', ['status'])
30
- .addAttribute('expiresAt', {
31
- type: 'string',
32
- required: true,
33
- validate: (value) => isIsoDate(value),
34
- default: () => {
35
- const date = new Date();
36
- date.setDate(date.getDate() + ImportUrl.IMPORT_URL_EXPIRES_IN_DAYS);
37
- return date.toISOString();
38
- },
39
- })
40
31
  .addAttribute('file', {
41
32
  type: 'string',
42
33
  })
@@ -13,7 +13,6 @@
13
13
  import type { BaseCollection, BaseModel, ImportJob } from '../index';
14
14
 
15
15
  export interface ImportUrl extends BaseModel {
16
- getExpiresAt(): string,
17
16
  getFile(): string,
18
17
  getImportJob(): Promise<ImportJob>,
19
18
  getImportJobId(): string,
@@ -21,7 +20,6 @@ export interface ImportUrl extends BaseModel {
21
20
  getReason(): string,
22
21
  getStatus(): string,
23
22
  getUrl(): string,
24
- setExpiresAt(expiresAt: string): void,
25
23
  setFile(file: string): void,
26
24
  setImportJobId(importJobId: string): void,
27
25
  setPath(path: string): void,
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { isObject } from '@adobe/spacecat-shared-utils';
13
+ import { isNonEmptyArray, isObject } from '@adobe/spacecat-shared-utils';
14
14
 
15
15
  import ValidationError from '../errors/validation.error.js';
16
16
 
@@ -25,7 +25,6 @@ import {
25
25
  guardSet,
26
26
  guardString,
27
27
  } from './index.js';
28
- import { isNonEmptyArray } from './util.js';
29
28
 
30
29
  /**
31
30
  * Checks if a property is read-only and throws an error if it is.
@@ -80,8 +80,6 @@ const sanitizeIdAndAuditFields = (entityName, data) => {
80
80
 
81
81
  const incrementVersion = (version) => (isInteger(version) ? parseInt(version, 10) + 1 : 1);
82
82
 
83
- const isNonEmptyArray = (value) => Array.isArray(value) && value.length > 0;
84
-
85
83
  const zeroPad = (num, length) => {
86
84
  const str = String(num);
87
85
  return str.length >= length
@@ -99,7 +97,6 @@ export {
99
97
  entityNameToIdName,
100
98
  idNameToEntityName,
101
99
  incrementVersion,
102
- isNonEmptyArray,
103
100
  isPositiveInteger,
104
101
  keyNamesToIndexName,
105
102
  keyNamesToMethodName,