Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-form-builder): dynamodb storage ops (#1955)
- Loading branch information
1 parent
b73983e
commit 8dff8e1
Showing
66 changed files
with
2,442 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("../../.babel.node")({ path: __dirname }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Webiny | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @webiny/api-form-builder-so-ddb | ||
[![](https://img.shields.io/npm/dw/@webiny/api-form-builder-so-ddb.svg)](https://www.npmjs.com/package/@webiny/api-form-builder-so-ddb) | ||
[![](https://img.shields.io/npm/v/@webiny/api-form-builder-so-ddb.svg)](https://www.npmjs.com/package/@webiny/api-form-builder-so-ddb) | ||
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) | ||
|
||
The DynamoDB Storage Operations for the [Webiny Forms (@webiny/api-form-builder)](../api-form-builder) API. | ||
|
||
## Install | ||
With yarn: | ||
``` | ||
yarn add @webiny/api-form-builder-so-ddb | ||
``` |
56 changes: 56 additions & 0 deletions
56
packages/api-form-builder-so-ddb/__tests__/__api__/environment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { DynamoDbDriver } = require("@webiny/db-dynamodb"); | ||
const { DocumentClient } = require("aws-sdk/clients/dynamodb"); | ||
const dbPlugins = require("@webiny/handler-db").default; | ||
const NodeEnvironment = require("jest-environment-node"); | ||
const dynamoDbPlugins = require("@webiny/db-dynamodb/plugins").default; | ||
/** | ||
* For this to work it must load plugins that have already been built | ||
*/ | ||
const { createFormBuilderStorageOperations } = require("../../dist/index"); | ||
|
||
if (typeof createFormBuilderStorageOperations !== "function") { | ||
throw new Error( | ||
`Loaded "createFormBuilderStorageOperations" must be a function that will return the storage operations.` | ||
); | ||
} | ||
|
||
class FormBuilderTestEnvironment extends NodeEnvironment { | ||
async setup() { | ||
await super.setup(); | ||
const documentClient = new DocumentClient({ | ||
convertEmptyValues: true, | ||
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT || "http://localhost:8001", | ||
sslEnabled: false, | ||
region: "local", | ||
accessKeyId: "test", | ||
secretAccessKey: "test" | ||
}); | ||
/** | ||
* This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. | ||
*/ | ||
this.global.__getStorageOperations = () => { | ||
return { | ||
createStorageOperations: () => { | ||
return createFormBuilderStorageOperations({ | ||
table: "DynamoDB", | ||
documentClient, | ||
plugins: [...dynamoDbPlugins()] | ||
}); | ||
}, | ||
getGlobalPlugins: () => { | ||
return [ | ||
...dbPlugins({ | ||
table: "DynamoDB", | ||
driver: new DynamoDbDriver({ | ||
documentClient | ||
}) | ||
}), | ||
...dynamoDbPlugins() | ||
]; | ||
} | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
module.exports = FormBuilderTestEnvironment; |
10 changes: 10 additions & 0 deletions
10
packages/api-form-builder-so-ddb/__tests__/__api__/presets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const path = require("path"); | ||
|
||
const presets = [ | ||
{ | ||
testEnvironment: path.resolve(__dirname, "environment.js"), | ||
setupFilesAfterEnv: [path.resolve(__dirname, "setupAfterEnv.js")] | ||
} | ||
]; | ||
|
||
module.exports = presets; |
24 changes: 24 additions & 0 deletions
24
packages/api-form-builder-so-ddb/__tests__/__api__/setupAfterEnv.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const jestDynalite = require("jest-dynalite"); | ||
const path = require("path"); | ||
/** | ||
* Must be a root of this package. | ||
*/ | ||
jestDynalite.setup(path.resolve(__dirname, "../../")); | ||
/** | ||
* Assign all required dynalite lifecycle methods. | ||
* And add custom lifecycle methods that are defined in the environment.js global | ||
*/ | ||
beforeAll(async () => { | ||
await jestDynalite.startDb(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await jestDynalite.createTables(); | ||
}); | ||
afterEach(async () => { | ||
await jestDynalite.deleteTables(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await jestDynalite.stopDb(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
tables: [ | ||
{ | ||
TableName: "DynamoDB", | ||
KeySchema: [ | ||
{ AttributeName: "PK", KeyType: "HASH" }, | ||
{ AttributeName: "SK", KeyType: "RANGE" } | ||
], | ||
AttributeDefinitions: [ | ||
{ AttributeName: "PK", AttributeType: "S" }, | ||
{ AttributeName: "SK", AttributeType: "S" }, | ||
{ AttributeName: "GSI1_PK", AttributeType: "S" }, | ||
{ AttributeName: "GSI1_SK", AttributeType: "S" } | ||
], | ||
ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }, | ||
GlobalSecondaryIndexes: [ | ||
{ | ||
IndexName: "GSI1", | ||
KeySchema: [ | ||
{ AttributeName: "GSI1_PK", KeyType: "HASH" }, | ||
{ AttributeName: "GSI1_SK", KeyType: "RANGE" } | ||
], | ||
Projection: { | ||
ProjectionType: "ALL" | ||
}, | ||
ProvisionedThroughput: { | ||
ReadCapacityUnits: 1, | ||
WriteCapacityUnits: 1 | ||
} | ||
} | ||
] | ||
} | ||
], | ||
basePort: 8000 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const dynamoDbPreset = require("jest-dynalite/jest-preset"); | ||
const base = require("../../jest.config.base"); | ||
|
||
module.exports = { | ||
...base({ path: __dirname }, [dynamoDbPreset]) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "@webiny/api-form-builder-so-ddb", | ||
"version": "5.16.0", | ||
"main": "index.js", | ||
"keywords": [ | ||
"@webiny/api-form-builder", | ||
"storage-operations", | ||
"dynamodb", | ||
"fb:ddb" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/webiny/webiny-js.git", | ||
"directory": "packages/api-form-builder-so-ddb" | ||
}, | ||
"contributors": [ | ||
"Pavel Denisjuk <pavel@webiny.com>", | ||
"Sven Al Hamad <sven@webiny.com>", | ||
"Adrian Smijulj <adrian@webiny.com>" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"@babel/runtime": "^7.5.5", | ||
"@webiny/api-form-builder": "^5.15.0", | ||
"@webiny/db-dynamodb": "^5.15.0", | ||
"@webiny/error": "^5.15.0", | ||
"@webiny/plugins": "^5.15.0", | ||
"@webiny/utils": "^5.15.0", | ||
"dynamodb-toolbox": "^0.3.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"@babel/preset-typescript": "^7.8.3", | ||
"@webiny/cli": "^5.15.0", | ||
"@webiny/handler-db": "^5.15.0", | ||
"@webiny/project-utils": "^5.15.0", | ||
"csvtojson": "^2.0.10", | ||
"jest": "^26.6.3", | ||
"jest-dynalite": "^3.2.0", | ||
"jest-environment-node": "^27.2.4", | ||
"rimraf": "^3.0.2", | ||
"ttypescript": "^1.5.12", | ||
"typescript": "^4.1.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
}, | ||
"scripts": { | ||
"build": "yarn webiny run build", | ||
"watch": "yarn webiny run watch" | ||
}, | ||
"gitHead": "b8aec8a1be3f25c3b428b357fe1e352c7cbff9ae" | ||
} |
Oops, something went wrong.