Skip to content

Commit

Permalink
chore: doc/vscode (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
solaris007 authored Jan 24, 2025
1 parent 04a97ba commit a3f193b
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 18 deletions.
94 changes: 94 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"version": "0.2.0",
"compounds": [
{
"name": "All Packages: Unit Tests",
"configurations": [
"Data Access: Unit Tests",
"Utils: Unit Tests",
"RUM API: Unit Tests"
]
}
],
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Data Access: Unit Tests",
"cwd": "${workspaceFolder}/packages/spacecat-shared-data-access",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"test/unit/**/*.test.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Utils: Unit Tests",
"cwd": "${workspaceFolder}/packages/spacecat-shared-utils",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"test/unit/**/*.test.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "RUM API: Unit Tests",
"cwd": "${workspaceFolder}/packages/spacecat-shared-rum-api-client",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"test/unit/**/*.test.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Current Test File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"${file}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "Current Test Suite",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
"${fileDirname}/**/*.test.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
}
]
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"eslint.workingDirectories": [
"./packages/spacecat-shared-data-access",
"./packages/spacecat-shared-utils",
"./packages/spacecat-shared-rum-api-client"
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": true,
"javascript.format.enable": false,
"eslint.alwaysShowStatus": true,
"eslint.debug": true,
"files.eol": "\n"
}
23 changes: 16 additions & 7 deletions packages/spacecat-shared-data-access/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The module provides the following DAOs:
## Integrating Data Access in AWS Lambda Functions

Our `spacecat-shared-data-access` module includes a wrapper that can be easily integrated into AWS Lambda functions using `@adobe/helix-shared-wrap`.
This integration allows your Lambda functions to access and manipulate data seamlessly.
This integration allows your Lambda functions to access and manipulate data.

### Steps for Integration

Expand All @@ -111,10 +111,19 @@ This integration allows your Lambda functions to access and manipulate data seam
Along with other wrappers and utilities, import the `dataAccessWrapper`.

```javascript
import dataAccessWrapper from '@adobe/spacecat-shared-data-access/wrapper';
import dataAccessWrapper from '@adobe/spacecat-shared-data-access';
```

2. **Modify Your Lambda Wrapper Script**
2. **Provide Required Environment Variables**

The `dataAccessWrapper` requires the `DYNAMO_TABLE_NAME_DATA` environment variable to be set via AWS
secret assigned to your Lambda function.

```javascript
const { DYNAMO_TABLE_NAME_DATA } = context.env;
```

3. **Modify Your Lambda Wrapper Script**

Include `dataAccessWrapper` in the chain of wrappers when defining your Lambda handler.

Expand All @@ -127,7 +136,7 @@ This integration allows your Lambda functions to access and manipulate data seam
.with(helixStatus);
```

3. **Access Data in Your Lambda Function**
4. **Access Data in Your Lambda Function**

Use the `dataAccess` object from the context to interact with your data layer.

Expand All @@ -136,7 +145,7 @@ This integration allows your Lambda functions to access and manipulate data seam
const { dataAccess } = context;

// Example: Retrieve all sites
const sites = await dataAccess.getSites();
const sites = await dataAccess.Site.getSites();
// ... more logic ...
}
```
Expand All @@ -147,7 +156,7 @@ Here's a complete example of a Lambda function utilizing the data access wrapper

```javascript
import wrap from '@adobe/helix-shared-wrap';
import dataAccessWrapper from '@adobe/spacecat-shared-data-access/wrapper';
import dataAccessWrapper from '@adobe/spacecat-shared-data-access';
import sqsEventAdapter from './sqsEventAdapter';
import sqs from './sqs';
import secrets from '@adobe/helix-shared-secrets';
Expand All @@ -156,7 +165,7 @@ import helixStatus from '@adobe/helix-status';
async function run(message, context) {
const { dataAccess } = context;
try {
const sites = await dataAccess.getSites();
const sites = await dataAccess.Site.getSites();
// Function logic here
} catch (error) {
// Error handling
Expand Down
14 changes: 14 additions & 0 deletions packages/spacecat-shared-data-access/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ export * from './service/index.js';

const TABLE_NAME_DATA = 'spacecat-services-data-dev';

/**
* Wrapper for data access layer
* @param {function} fn - The function to wrap
* @returns {function} - The wrapped function
*/
export default function dataAccessWrapper(fn) {
/**
* Wrapper for data access layer. This wrapper will create a data access layer if it is not
* already created. It requires the context to have a log object. It will also use the
* DYNAMO_TABLE_NAME_DATA environment variable to create the data access layer.
*
* @param {object} request - The request object
* @param {object} context - The context object
* @returns {Promise<object>} - The wrapped function
*/
return async (request, context) => {
if (!context.dataAccess) {
const { log } = context;
Expand Down
16 changes: 16 additions & 0 deletions packages/spacecat-shared-data-access/src/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,19 @@ await user.save();
## Consideration for Indexes

Indexes cost money and complexity. Do not add indexes lightly. Determine which query patterns you truly need and only then introduce additional indexes.

## Data Access Service

You can use the data layer by obtaining a service instance through the `createDataAccess` function:

```javascript
const { createDataAccess } = require('@adobe/spacecat-shared-data-access');

const dataAccess = createDataAccess({
tableNameData: 'spacecat-services-data-dev',
});

// You can now use the dataAccess object to interact with the data layer
const sites = await dataAccess.Site.getSites();
```

16 changes: 5 additions & 11 deletions packages/spacecat-shared-data-access/src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,12 @@ const createElectroService = (client, config, log) => {
};

/**
* Creates a data access object.
* Creates a data access layer for interacting with DynamoDB using ElectroDB.
*
* @param {{pkAllSites: string, pkAllLatestAudits: string, indexNameAllLatestAuditScores: string,
* tableNameAudits: string,tableNameLatestAudits: string, indexNameAllSitesOrganizations: string,
* tableNameSites: string, tableNameOrganizations: string, tableNameExperiments: string,
* indexNameAllSites: string,
* tableNameImportJobs: string, pkAllImportJobs: string, indexNameAllImportJobs: string,
* tableNameSiteTopPages: string, indexNameAllOrganizations: string,
* indexNameAllOrganizationsByImsOrgId: string, pkAllOrganizations: string}} config configuration
* @param {Logger} log log
* @param client custom dynamo client
* @returns {object} data access object
* @param {{tableNameData: string}} config - Configuration object containing table name
* @param {object} log - Logger instance, defaults to console
* @param {DynamoDB} [client] - Optional custom DynamoDB client instance
* @returns {object} Data access collections for interacting with entities
*/
export const createDataAccess = (config, log = console, client = undefined) => {
const rawClient = createRawClient(client);
Expand Down

0 comments on commit a3f193b

Please sign in to comment.