Skip to content

Commit

Permalink
Merge pull request #3 from monolithst/upgrade-aws
Browse files Browse the repository at this point in the history
Upgrade to aws. Fix build tools.
  • Loading branch information
macornwell authored Mar 13, 2024
2 parents 68d720d + 7ff56fd commit 8d24f00
Show file tree
Hide file tree
Showing 17 changed files with 612 additions and 712 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
}
},
"parserOptions": {
"project": ['./tsconfig.json'],
"ecmaFeatures": {
"jsx": true
}
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Functional Models ORM Dynamo
# Functional Models ORM Dynamo

![Unit Tests](https://github.com/monolithst/functional-models-orm-dynamo/actions/workflows/ut.yml/badge.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/monolithst/functional-models-orm-dynamo/badge.svg?branch=master)](https://coveralls.io/github/monolithst/functional-models-orm-dynamo?branch=master)
Provides an functional-models-orm datastore provider for AWS Dynamo.

## AWS SDK 3.0

This library now supports AWS SDK 3.0 as an injectable library.

## Run Feature Tests

To run the feature tests, you need to set up an actual Dynamodb table within AWS and then call cucumber lik the following:

```npm run feature-tests -- --world-parameters '{"awsRegion":"YOUR_REGION", "testTable":"YOUR_TEST_TABLE"}'```
`npm run feature-tests -- --world-parameters '{"awsRegion":"YOUR_REGION", "testTable":"YOUR_TEST_TABLE"}'`

IMPORTANT WORD OF CAUTION: I would not attempt to use this table for anything other than this feature tests, as the table is completely deleted without remorse.
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
const assert = require('chai').assert
const { Before, After, Given, When, Then } = require('cucumber')
const { TextProperty, Model, UniqueId } = require('functional-models')
const { ormQuery, orm } = require('functional-models-orm')
const createDatastoreProvider = require('../../dist/datastoreProvider').default
import { assert } from 'chai'
import { Before, After, Given, When, Then } from '@cucumber/cucumber'
import functionalModels from 'functional-models'
import { ormQuery, orm } from 'functional-models-orm'
import createDatastoreProvider from '../../dist/datastoreProvider.js'
import * as dynamo from '@aws-sdk/client-dynamodb'
import * as libDynamo from '@aws-sdk/lib-dynamodb'

const createDynamoDatastoreProvider = (context) => {
const { TextProperty, Model, UniqueId } = functionalModels

const createDynamoDatastoreProvider = context => {
if (!context.parameters.testTable) {
throw new Error(`Must include a testing table that exists in the world parameters.`)
throw new Error(
`Must include a testing table that exists in the world parameters.`
)
}
if (!context.parameters.awsRegion) {
throw new Error(`Must include awsRegion in the world parameters.`)
}
this.table = context.parameters.testTable
return createDatastoreProvider({
AWS: require('aws-sdk'),
context.table = context.parameters.testTable
return createDatastoreProvider.default({
aws3: {
...dynamo,
...libDynamo,
},
dynamoOptions: {
region: context.parameters.awsRegion
region: context.parameters.awsRegion,
},
getTableNameForModel: () => {
return `${this.table}`
}
return `${context.table}`
},
})
}

Expand All @@ -33,7 +42,7 @@ const MODELS = {
{
properties: {
name: TextProperty(),
}
},
},
],
}
Expand All @@ -44,28 +53,36 @@ const MODEL_DATA = {
name: 'test-name',
},
SearchResult1: {
instances: [{
id: 'test-id',
name: 'test-name',
}],
page: null
instances: [
{
id: 'test-id',
name: 'test-name',
},
],
page: null,
},
EmptyModel: {},
'undefined': undefined,
undefined: undefined,
}

const QUERIES = {
SearchQuery1: ormQuery.ormQueryBuilder()
SearchQuery1: ormQuery
.ormQueryBuilder()
.property('name', 'test-name')
.take(1)
.compile(),
}

const _emptyDatastoreProvider = async (model, datastoreProvider) => {
await datastoreProvider.search(model, ormQuery.ormQueryBuilder().compile())
.then(async obj => Promise.all(obj.instances.map(x => {
return model.create(x).delete()
})))
await datastoreProvider
.search(model, ormQuery.ormQueryBuilder().compile())
.then(async obj =>
Promise.all(
obj.instances.map(x => {
return model.create(x).delete()
})
)
)
}

Given('orm using the {word}', function (store) {
Expand All @@ -78,7 +95,7 @@ Given('orm using the {word}', function (store) {
this.datastoreProvider = store
})

Given('the datastore is emptied of models', function() {
Given('the datastore is emptied of models', function () {
return _emptyDatastoreProvider(this.model, this.datastoreProvider)
})

Expand All @@ -105,13 +122,16 @@ When('instances of the model are created with {word}', function (dataKey) {
this.instances = MODEL_DATA[dataKey].map(this.model.create)
})

When('an instance of the model is created with {word}', async function (dataKey) {
const data = MODEL_DATA[dataKey]
if (!data) {
throw new Error(`${dataKey} did not result in a data object.`)
When(
'an instance of the model is created with {word}',
async function (dataKey) {
const data = MODEL_DATA[dataKey]
if (!data) {
throw new Error(`${dataKey} did not result in a data object.`)
}
this.modelInstance = this.model.create(data)
}
this.modelInstance = this.model.create(data)
})
)

When('save is called on the instances', function () {
return Promise.all(this.instances.map(x => x.save()))
Expand All @@ -122,9 +142,7 @@ When('save is called on the model', function () {
})

When('delete is called on the model', function () {
return this.modelInstance
.delete()
.then(x => (this.deleteResult = x))
return this.modelInstance.delete().then(x => (this.deleteResult = x))
})

When("the datastore's retrieve is called with values", function (table) {
Expand All @@ -144,7 +162,6 @@ When("the datastore's delete is called with modelInstance", function () {
When("the datastore's search is called with {word}", function (key) {
const query = QUERIES[key]
return this.datastoreProvider.search(this.model, query).then(async obj => {
console.log(obj)
this.result = obj
})
})
Expand Down
47 changes: 26 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "functional-models-orm-dynamo",
"version": "2.0.4",
"version": "2.1.0",
"description": "An implmentation of functional-models-orm for dynamodb.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha -r ts-node/register test/**/*.test.ts",
"test": "export TS_NODE_TRANSPILE_ONLY=true && export TS_NODE_PROJECT='./tsconfig.test.json' && mocha -r ts-node/register 'test/**/*.test.ts'",
"test:coverage": "nyc npm run test",
"feature-tests": "./node_modules/.bin/cucumber-js",
"coverage": "nyc --all --reporter=lcov npm test",
Expand Down Expand Up @@ -49,32 +49,37 @@
"report-dir": "coverage"
},
"dependencies": {
"functional-models": "^2.0.5",
"@aws-sdk/client-dynamodb": "^3.529.1",
"@aws-sdk/lib-dynamodb": "^3.529.1",
"functional-models": "^2.0.14",
"functional-models-orm": "^2.0.17",
"lodash": "^4.17.21"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/chai": "^4.3.0",
"@types/lodash": "^4.14.177",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.7",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^10.0.6",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@cucumber/cucumber": "^9.6.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.12",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.27",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.0",
"cucumber": "^7.0.0-rc.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-functional": "^3.2.1",
"eslint-plugin-import": "^2.22.1",
"mocha": "^8.2.1",
"chai": "^4.2.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-functional": "^6.1.1",
"eslint-plugin-import": "^2.29.1",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^3.2.5",
"proxyquire": "^2.1.3",
"sinon": "^11.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.2"
"sinon": "^17.0.1",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.2"
},
"homepage": "https://github.com/monolithst/functional-models-orm-dynamo#readme"
}
5 changes: 1 addition & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,4 @@ const RESERVED_KEYWORDS = {

const SCAN_RETURN_THRESHOLD = 1000

export {
RESERVED_KEYWORDS,
SCAN_RETURN_THRESHOLD,
}
export { RESERVED_KEYWORDS, SCAN_RETURN_THRESHOLD }
Loading

0 comments on commit 8d24f00

Please sign in to comment.