@adobe/spacecat-shared-data-access 2.0.4 → 2.0.5
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 +7 -0
- package/README.md +16 -7
- package/package.json +4 -4
- package/src/index.js +14 -0
- package/src/readme.md +16 -0
- package/src/service/index.js +5 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v2.0.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.0.4...@adobe/spacecat-shared-data-access-v2.0.5) (2025-01-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([#561](https://github.com/adobe/spacecat-shared/issues/561)) ([e922c1d](https://github.com/adobe/spacecat-shared/commit/e922c1df3b9a7bfcf6a5699d65bcb02dc130393a))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-data-access-v2.0.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.0.3...@adobe/spacecat-shared-data-access-v2.0.4) (2025-01-18)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ The module provides the following DAOs:
|
|
|
102
102
|
## Integrating Data Access in AWS Lambda Functions
|
|
103
103
|
|
|
104
104
|
Our `spacecat-shared-data-access` module includes a wrapper that can be easily integrated into AWS Lambda functions using `@adobe/helix-shared-wrap`.
|
|
105
|
-
This integration allows your Lambda functions to access and manipulate data
|
|
105
|
+
This integration allows your Lambda functions to access and manipulate data.
|
|
106
106
|
|
|
107
107
|
### Steps for Integration
|
|
108
108
|
|
|
@@ -111,10 +111,19 @@ This integration allows your Lambda functions to access and manipulate data seam
|
|
|
111
111
|
Along with other wrappers and utilities, import the `dataAccessWrapper`.
|
|
112
112
|
|
|
113
113
|
```javascript
|
|
114
|
-
import dataAccessWrapper from '@adobe/spacecat-shared-data-access
|
|
114
|
+
import dataAccessWrapper from '@adobe/spacecat-shared-data-access';
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
2. **
|
|
117
|
+
2. **Provide Required Environment Variables**
|
|
118
|
+
|
|
119
|
+
The `dataAccessWrapper` requires the `DYNAMO_TABLE_NAME_DATA` environment variable to be set via AWS
|
|
120
|
+
secret assigned to your Lambda function.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
const { DYNAMO_TABLE_NAME_DATA } = context.env;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. **Modify Your Lambda Wrapper Script**
|
|
118
127
|
|
|
119
128
|
Include `dataAccessWrapper` in the chain of wrappers when defining your Lambda handler.
|
|
120
129
|
|
|
@@ -127,7 +136,7 @@ This integration allows your Lambda functions to access and manipulate data seam
|
|
|
127
136
|
.with(helixStatus);
|
|
128
137
|
```
|
|
129
138
|
|
|
130
|
-
|
|
139
|
+
4. **Access Data in Your Lambda Function**
|
|
131
140
|
|
|
132
141
|
Use the `dataAccess` object from the context to interact with your data layer.
|
|
133
142
|
|
|
@@ -136,7 +145,7 @@ This integration allows your Lambda functions to access and manipulate data seam
|
|
|
136
145
|
const { dataAccess } = context;
|
|
137
146
|
|
|
138
147
|
// Example: Retrieve all sites
|
|
139
|
-
const sites = await dataAccess.getSites();
|
|
148
|
+
const sites = await dataAccess.Site.getSites();
|
|
140
149
|
// ... more logic ...
|
|
141
150
|
}
|
|
142
151
|
```
|
|
@@ -147,7 +156,7 @@ Here's a complete example of a Lambda function utilizing the data access wrapper
|
|
|
147
156
|
|
|
148
157
|
```javascript
|
|
149
158
|
import wrap from '@adobe/helix-shared-wrap';
|
|
150
|
-
import dataAccessWrapper from '@adobe/spacecat-shared-data-access
|
|
159
|
+
import dataAccessWrapper from '@adobe/spacecat-shared-data-access';
|
|
151
160
|
import sqsEventAdapter from './sqsEventAdapter';
|
|
152
161
|
import sqs from './sqs';
|
|
153
162
|
import secrets from '@adobe/helix-shared-secrets';
|
|
@@ -156,7 +165,7 @@ import helixStatus from '@adobe/helix-status';
|
|
|
156
165
|
async function run(message, context) {
|
|
157
166
|
const { dataAccess } = context;
|
|
158
167
|
try {
|
|
159
|
-
const sites = await dataAccess.getSites();
|
|
168
|
+
const sites = await dataAccess.Site.getSites();
|
|
160
169
|
// Function logic here
|
|
161
170
|
} catch (error) {
|
|
162
171
|
// Error handling
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-data-access",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Data Access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/spacecat-shared-utils": "1.26.4",
|
|
38
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
39
|
-
"@aws-sdk/lib-dynamodb": "3.
|
|
38
|
+
"@aws-sdk/client-dynamodb": "3.734.0",
|
|
39
|
+
"@aws-sdk/lib-dynamodb": "3.734.0",
|
|
40
40
|
"@types/joi": "17.2.3",
|
|
41
|
-
"aws-xray-sdk": "3.10.
|
|
41
|
+
"aws-xray-sdk": "3.10.3",
|
|
42
42
|
"electrodb": "3.0.1",
|
|
43
43
|
"joi": "17.13.3",
|
|
44
44
|
"pluralize": "8.0.0",
|
package/src/index.js
CHANGED
|
@@ -16,7 +16,21 @@ export * from './service/index.js';
|
|
|
16
16
|
|
|
17
17
|
const TABLE_NAME_DATA = 'spacecat-services-data-dev';
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Wrapper for data access layer
|
|
21
|
+
* @param {function} fn - The function to wrap
|
|
22
|
+
* @returns {function} - The wrapped function
|
|
23
|
+
*/
|
|
19
24
|
export default function dataAccessWrapper(fn) {
|
|
25
|
+
/**
|
|
26
|
+
* Wrapper for data access layer. This wrapper will create a data access layer if it is not
|
|
27
|
+
* already created. It requires the context to have a log object. It will also use the
|
|
28
|
+
* DYNAMO_TABLE_NAME_DATA environment variable to create the data access layer.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} request - The request object
|
|
31
|
+
* @param {object} context - The context object
|
|
32
|
+
* @returns {Promise<object>} - The wrapped function
|
|
33
|
+
*/
|
|
20
34
|
return async (request, context) => {
|
|
21
35
|
if (!context.dataAccess) {
|
|
22
36
|
const { log } = context;
|
package/src/readme.md
CHANGED
|
@@ -215,3 +215,19 @@ await user.save();
|
|
|
215
215
|
## Consideration for Indexes
|
|
216
216
|
|
|
217
217
|
Indexes cost money and complexity. Do not add indexes lightly. Determine which query patterns you truly need and only then introduce additional indexes.
|
|
218
|
+
|
|
219
|
+
## Data Access Service
|
|
220
|
+
|
|
221
|
+
You can use the data layer by obtaining a service instance through the `createDataAccess` function:
|
|
222
|
+
|
|
223
|
+
```javascript
|
|
224
|
+
const { createDataAccess } = require('@adobe/spacecat-shared-data-access');
|
|
225
|
+
|
|
226
|
+
const dataAccess = createDataAccess({
|
|
227
|
+
tableNameData: 'spacecat-services-data-dev',
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// You can now use the dataAccess object to interact with the data layer
|
|
231
|
+
const sites = await dataAccess.Site.getSites();
|
|
232
|
+
```
|
|
233
|
+
|
package/src/service/index.js
CHANGED
|
@@ -50,18 +50,12 @@ const createElectroService = (client, config, log) => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Creates a data access
|
|
53
|
+
* Creates a data access layer for interacting with DynamoDB using ElectroDB.
|
|
54
54
|
*
|
|
55
|
-
* @param {{
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* tableNameImportJobs: string, pkAllImportJobs: string, indexNameAllImportJobs: string,
|
|
60
|
-
* tableNameSiteTopPages: string, indexNameAllOrganizations: string,
|
|
61
|
-
* indexNameAllOrganizationsByImsOrgId: string, pkAllOrganizations: string}} config configuration
|
|
62
|
-
* @param {Logger} log log
|
|
63
|
-
* @param client custom dynamo client
|
|
64
|
-
* @returns {object} data access object
|
|
55
|
+
* @param {{tableNameData: string}} config - Configuration object containing table name
|
|
56
|
+
* @param {object} log - Logger instance, defaults to console
|
|
57
|
+
* @param {DynamoDB} [client] - Optional custom DynamoDB client instance
|
|
58
|
+
* @returns {object} Data access collections for interacting with entities
|
|
65
59
|
*/
|
|
66
60
|
export const createDataAccess = (config, log = console, client = undefined) => {
|
|
67
61
|
const rawClient = createRawClient(client);
|