-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ee5733e
commit c9cd4b7
Showing
254 changed files
with
13,071 additions
and
3,182 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 @@ | ||
{ | ||
"name": "API Headless CMS DynamoDB / Elasticsearch", | ||
"entryPoints": ["types.ts"] | ||
} |
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,18 @@ | ||
# @webiny/api-headless-cms-ddb-es | ||
|
||
[![](https://img.shields.io/npm/dw/@webiny/api-headless-cms-ddb-es.svg)](https://www.npmjs.com/package/@webiny/api-headless-cms-ddb-es) | ||
[![](https://img.shields.io/npm/v/@webiny/api-headless-cms-ddb-es.svg)](https://www.npmjs.com/package/@webiny/api-headless-cms-ddb-es) | ||
[![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) | ||
|
||
## Install | ||
|
||
``` | ||
npm install --save @webiny/api-headless-cms-ddb-es | ||
``` | ||
|
||
Or if you prefer yarn: | ||
|
||
``` | ||
yarn add @webiny/api-headless-cms-ddb-es | ||
``` |
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
124 changes: 124 additions & 0 deletions
124
packages/api-headless-cms-ddb-es/__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,124 @@ | ||
const dbPlugins = require("@webiny/handler-db").default; | ||
const { DynamoDbDriver } = require("@webiny/db-dynamodb"); | ||
const { DocumentClient } = require("aws-sdk/clients/dynamodb"); | ||
const elasticSearch = require("@webiny/api-plugin-elastic-search-client").default; | ||
const { createHandler } = require("@webiny/handler-aws"); | ||
const dynamoToElastic = require("@webiny/api-dynamodb-to-elasticsearch/handler").default; | ||
const { Client } = require("@elastic/elasticsearch"); | ||
const { simulateStream } = require("@webiny/project-utils/testing/dynamodb"); | ||
const NodeEnvironment = require("jest-environment-node"); | ||
/** | ||
* For this to work it must load plugins that have already been built | ||
*/ | ||
const plugins = require("../../dist/index").default; | ||
|
||
if (typeof plugins !== "function") { | ||
throw new Error(`Loaded plugins file must export a function that returns an array of plugins.`); | ||
} | ||
|
||
const ELASTICSEARCH_PORT = process.env.ELASTICSEARCH_PORT || "9200"; | ||
|
||
const getStorageOperationsPlugins = ({ | ||
elasticsearchClient, | ||
documentClient, | ||
elasticSearchContext | ||
}) => { | ||
// Intercept DocumentClient operations and trigger dynamoToElastic function (almost like a DynamoDB Stream trigger) | ||
simulateStream(documentClient, createHandler(elasticSearchContext, dynamoToElastic())); | ||
|
||
return () => { | ||
return [ | ||
plugins(), | ||
dbPlugins({ | ||
table: "HeadlessCms", | ||
driver: new DynamoDbDriver({ | ||
documentClient | ||
}) | ||
}), | ||
elasticSearchContext, | ||
{ | ||
type: "context", | ||
async apply() { | ||
await elasticsearchClient.indices.putTemplate({ | ||
name: "headless-cms-entries-index", | ||
body: { | ||
index_patterns: ["*headless-cms*"], | ||
settings: { | ||
analysis: { | ||
analyzer: { | ||
lowercase_analyzer: { | ||
type: "custom", | ||
filter: ["lowercase", "trim"], | ||
tokenizer: "keyword" | ||
} | ||
} | ||
} | ||
}, | ||
mappings: { | ||
properties: { | ||
property: { | ||
type: "text", | ||
fields: { | ||
keyword: { | ||
type: "keyword", | ||
ignore_above: 256 | ||
} | ||
}, | ||
analyzer: "lowercase_analyzer" | ||
}, | ||
rawValues: { | ||
type: "object", | ||
enabled: false | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
]; | ||
}; | ||
}; | ||
|
||
class CmsTestEnvironment extends NodeEnvironment { | ||
async setup() { | ||
await super.setup(); | ||
|
||
const elasticsearchClient = new Client({ | ||
node: `http://localhost:${ELASTICSEARCH_PORT}` | ||
}); | ||
const documentClient = new DocumentClient({ | ||
convertEmptyValues: true, | ||
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT || "http://localhost:8001", | ||
sslEnabled: false, | ||
region: "local", | ||
accessKeyId: "test", | ||
secretAccessKey: "test" | ||
}); | ||
const elasticSearchContext = elasticSearch({ | ||
endpoint: `http://localhost:${ELASTICSEARCH_PORT}`, | ||
auth: {} | ||
}); | ||
const clearEsIndices = async () => { | ||
return elasticsearchClient.indices.delete({ | ||
index: "_all" | ||
}); | ||
}; | ||
/** | ||
* This is a global function that will be called inside the tests to get all relevant plugins, methods and objects. | ||
*/ | ||
this.global.__getStorageOperationsPlugins = () => { | ||
return getStorageOperationsPlugins({ | ||
elasticsearchClient, | ||
elasticSearchContext, | ||
documentClient | ||
}); | ||
}; | ||
this.global.__beforeEach = clearEsIndices; | ||
this.global.__afterEach = clearEsIndices; | ||
this.global.__beforeAll = clearEsIndices; | ||
this.global.__afterAll = clearEsIndices; | ||
} | ||
} | ||
|
||
module.exports = CmsTestEnvironment; |
Oops, something went wrong.