@adobe/spacecat-shared-data-access 2.88.9 → 2.90.0

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.
@@ -10,13 +10,23 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { hasText, isNonEmptyObject, isNumber } from '@adobe/spacecat-shared-utils';
13
+ import {
14
+ hasText, isBoolean, isNonEmptyObject, isNumber,
15
+ } from '@adobe/spacecat-shared-utils';
14
16
 
15
17
  import ValidationError from '../errors/validation.error.js';
16
18
 
17
19
  function validateValue(context, keyName, value) {
18
20
  const { type } = context.schema.getAttribute(keyName);
19
- const validator = type === 'number' ? isNumber : hasText;
21
+
22
+ let validator;
23
+ if (type === 'number') {
24
+ validator = isNumber;
25
+ } else if (type === 'boolean') {
26
+ validator = isBoolean;
27
+ } else {
28
+ validator = hasText;
29
+ }
20
30
 
21
31
  if (!validator(value)) {
22
32
  throw new ValidationError(`${keyName} is required`);
package/src/util/index.js CHANGED
@@ -26,3 +26,13 @@ export {
26
26
  registerLogger,
27
27
  getLogger,
28
28
  } from './logger-registry.js';
29
+
30
+ /**
31
+ * Datastore types that collections can use to declare their storage backend.
32
+ * @readonly
33
+ * @enum {string}
34
+ */
35
+ export const DATASTORE_TYPE = Object.freeze({
36
+ DYNAMO: 'dynamo',
37
+ S3: 's3',
38
+ });
@@ -137,6 +137,24 @@ class Patcher {
137
137
  this.updates = { ...this.updates, ...update };
138
138
  }
139
139
 
140
+ /**
141
+ * Gets the primary key values for the entity from the schema's primary index.
142
+ * This supports composite primary keys (e.g., siteId + url).
143
+ * @return {Object} - An object containing the primary key values.
144
+ * @private
145
+ */
146
+ #getPrimaryKeyValues() {
147
+ const primaryKeys = this.schema.getIndexKeys('primary');
148
+ if (isNonEmptyArray(primaryKeys)) {
149
+ return primaryKeys.reduce((acc, key) => {
150
+ acc[key] = this.record[key];
151
+ return acc;
152
+ }, {});
153
+ }
154
+ // Fallback to default id name
155
+ return { [this.idName]: this.record[this.idName] };
156
+ }
157
+
140
158
  /**
141
159
  * Gets the patch record for the entity. If it does not exist, it will be created.
142
160
  * @return {Object} - The patch record for the entity.
@@ -144,7 +162,7 @@ class Patcher {
144
162
  */
145
163
  #getPatchRecord() {
146
164
  if (!this.patchRecord) {
147
- this.patchRecord = this.entity.patch({ [this.idName]: this.record[this.idName] });
165
+ this.patchRecord = this.entity.patch(this.#getPrimaryKeyValues());
148
166
  }
149
167
  return this.patchRecord;
150
168
  }