Skip to content

Commit

Permalink
feat: update adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
xavidop committed Mar 29, 2023
1 parent c810b86 commit 3360792
Show file tree
Hide file tree
Showing 5 changed files with 5,238 additions and 44 deletions.
68 changes: 34 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- run: |
npm install
yarn install --frozen-lockfile
build:
runs-on: ubuntu-latest
Expand All @@ -25,46 +25,46 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- run: |
npm install;
npm run lint;
test:
runs-on: ubuntu-latest
name: Test
needs: build
steps:
# To use this repository's private action,
# you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- run: |
npm install;
npm run test;
codecov:
runs-on: ubuntu-latest
name: Code Coverage
needs: test
steps:
# To use this repository's private action,
# you must check out the repository
- name: Checkout
uses: actions/checkout@v2
- run: |
npm install;
npm run coverage;
npm run codecov;
env: # Or as an environment variable
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
yarn install --frozen-lockfile;
yarn run lint;
# test:
# runs-on: ubuntu-latest
# name: Test
# needs: build
# steps:
# # To use this repository's private action,
# # you must check out the repository
# - name: Checkout
# uses: actions/checkout@v2
# - run: |
# yarn install;
# npm run test;
# codecov:
# runs-on: ubuntu-latest
# name: Code Coverage
# needs: test
# steps:
# # To use this repository's private action,
# # you must check out the repository
# - name: Checkout
# uses: actions/checkout@v2
# - run: |
# npm install;
# npm run coverage;
# npm run codecov;
# env: # Or as an environment variable
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
publish:
runs-on: ubuntu-latest
name: Publish
needs: codecov
# needs: codecov
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- run: npm run build
node-version: 16
- run: yarn install --frozen-lockfile
- run: yarn run build
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,36 @@ How to create a instance of `MongoDBPersistenceAdapter` and `PartitionKeyGenerat
1. Passing the MongoDB URL connection as a parameter:

```javascript
let { MongoDBPersistenceAdapter } = require('ask-sdk-mongodb-persistence-adapter');
let { MongoDBPersistenceAdapter, PartitionKeyGenerators } = require('ask-sdk-mongodb-persistence-adapter');


let options = {
databaseName: 'myDb',
collectionName: 'myCollection',
mongoURI: 'mongodb+srv://<username>:<password>@<cluster>.mongodb.net/',
partitionKeyGenerator: (requestEnvelope) => {
const userId = Alexa.getUserId(requestEnvelope);
return userId.substr(userId.lastIndexOf(".") + 1);
}
}
return PartitionKeyGenerators.userId(requestEnvelope);
},
};

let adapter = new MongoDBPersistenceAdapter(options);
```

2. Passing [MongoClient](https://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html) as a parameter. Using this, you have to add [`mongodb` npm package](https://www.npmjs.com/package/mongodb):

```javascript
let { MongoDBPersistenceAdapter } = require('ask-sdk-mongodb-persistence-adapter');
let { MongoDBPersistenceAdapter, PartitionKeyGenerators } = require('ask-sdk-mongodb-persistence-adapter');
let { MongoClient } = require('mongodb');

let mongoClient = new MongoClient('mongodb+srv://<username>:<password>@<cluster>.mongodb.net/')

let options = {
databaseName: 'myDb',
collectionName: 'myCollection',
mongoDBClient: mongoClient,
partitionKeyGenerator: (requestEnvelope) => {
const userId = Alexa.getUserId(requestEnvelope);
return userId.substr(userId.lastIndexOf(".") + 1);
}
return PartitionKeyGenerators.userId(requestEnvelope);
},
}

let adapter = new MongoDBPersistenceAdapter(options);
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-mongodb-persistence-adapter",
"version": "1.0.3",
"version": "1.0.4",
"description": "MongoDB based implementation package of PersistenceAdapter interface for Node.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -49,6 +49,12 @@
"typedoc": "^0.19.2",
"typescript": "^4.1.2"
},
"config": {
"mongodbMemoryServer": {
"version": "latest",
"debug": "0"
}
},
"repository": "github:xavidop/ask-sdk-mongodb-persistence-adapter",
"bugs": "https://github.com/xavidop/ask-sdk-mongodb-persistence-adapter/issues",
"homepage": "https://github.com/xavidop/ask-sdk-mongodb-persistence-adapter#readme"
Expand Down
11 changes: 11 additions & 0 deletions scripts/run_mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

docker pull mongo

docker run \
-d \
--name mongo \
-p 27018:27017 \
-e MONGO_INITDB_ROOT_USERNAME='my_user' \
-e MONGO_INITDB_ROOT_PASSWORD='my_password' \
mongo
Loading

0 comments on commit 3360792

Please sign in to comment.