appc-connector-utils
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -6,9 +6,6 @@ const metadataValidator = require('./utils/metadataValidator') | ||
const container = Arrow.getGlobal() | ||
const connector = getConnector(container, conn) | ||
const arrowUtils = require('./utils/arrow')(Arrow) | ||
const modelAPI = require('./model/api')(Arrow) | ||
const connector = arrowUtils.getConnector(container, conn) | ||
if (!connector) { | ||
throw new Error('You must specify options.connector or options.connectorName to create connector') | ||
} | ||
return { | ||
@@ -19,19 +16,9 @@ createModels: createModels, | ||
validateModelMetadata: metadataValidator.validateModelMetadata, | ||
getParentModelName: modelAPI.getParentModelName | ||
} | ||
function getConnector (container, connector) { | ||
if (!connector) { | ||
throw new Error('There is no connector information') | ||
getParentModelName: modelAPI.getParentModelName, | ||
test: { | ||
getConnectorStatic: arrowUtils.getConnectorStatic, | ||
getConnectorDynamic: arrowUtils.getConnectorDynamic, | ||
startArrowHttp: arrowUtils.startArrowHttp, | ||
stopArrowHttp: arrowUtils.stopArrowHttp | ||
} | ||
if (typeof connector === 'object') { | ||
return connector | ||
} | ||
if (typeof connector === 'string') { | ||
return container.getConnector(connector) | ||
} | ||
throw new Error('Invalid connector type passed. Pass the connector instance or connector name.') | ||
} | ||
@@ -38,0 +25,0 @@ |
{ | ||
"name": "appc-connector-utils", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Utilities for Arrow Connectors", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"check-security": "nsp check || true", | ||
"check-deps": "retire || true", | ||
"checks": "npm run check-deps && npm run check-security", | ||
"test": "npm run lint-fix && npm run test:all", | ||
@@ -13,4 +16,3 @@ "test:all": "tap test/unit/*.js test/integration/*.js --color --bail --cov", | ||
"lint-fix": "standard --fix | snazzy", | ||
"precommit": "npm run lint", | ||
"s": "tap test/index.js" | ||
"precommit": "npm run lint" | ||
}, | ||
@@ -36,7 +38,10 @@ "repository": { | ||
"devDependencies": { | ||
"arrow": "*", | ||
"husky": "^0.13.1", | ||
"nsp": "^2.6.3", | ||
"request": "^2.81.0", | ||
"retire": "^1.2.12", | ||
"snazzy": "^6.0.0", | ||
"standard": "^8.6.0", | ||
"tap": "^10.1.0", | ||
"arrow": "*" | ||
"tap": "^10.3.0" | ||
}, | ||
@@ -54,2 +59,2 @@ "standard": { | ||
} | ||
} | ||
} |
@@ -5,10 +5,18 @@ # Utilities for Arrow Connectors | ||
**NOTE: Please use fixed version of this modules until it reaches 1.0.0 due to expected breaking changes in the interface.** | ||
# Overview | ||
Arrow Connectors transform data structures from third party services and databases into the data model used in Arrow. | ||
Arrow Connectors transform data structures from third party services and databases into the data model used in Arrow. This project offers reusable utilitites across the connector projects. | ||
This project offers some reusable utilitites across the connector projects. It has some real value in use cases related with dynamic service discovery. | ||
## Utilities List | ||
The project defines object schemas for metadata needed to create Arrow Models. Passing proper metadata guarantees the proper generation of models and endpoints by Arrow Framework. The object schemas are specified in the form of [Joi](https://github.com/hapijs/joi) object descriptions. | ||
Among the utilities are: | ||
* **Standartization of dynamic Arrow components generation:** The project defines object schemas for metadata needed to create Arrow Models (and other types of components eventually). Passing proper metadata guarantees the proper generation of models and endpoints by Arrow Framework. The object schemas are specified in the form of [Joi](https://github.com/hapijs/joi) object descriptions. | ||
* **Test Utilites:** Clean lifecycle how to get static and dynamic connectors as well as arrow in plain and http mode in your test suites. | ||
* **Extras:** Random extras like model namespacing, parent model name finder etc. | ||
# How to use it? | ||
@@ -20,8 +28,11 @@ | ||
Require it in your project passing the connector and options as context | ||
Since this modules is supposed to work in the context of Arrow Application it must be configured with the following context: | ||
```javascript | ||
const utils = require('appc-connector-utils')(connector, options) | ||
``` | ||
* the Arrow library | ||
* the connector name or instance | ||
Once configured the resulting API could be used according to the project needs. | ||
# How to run the test suite? | ||
@@ -28,0 +39,0 @@ |
@@ -6,19 +6,9 @@ const Arrow = require('arrow') | ||
const arrowConfig = require('../conf/arrow') | ||
const connectorConfig = require('../conf/connector') | ||
const server = new Arrow(arrowConfig, true) | ||
const DEFAULT_CONNECTOR_NAME = 'appc.test' | ||
const DEFAULT_CONNECTOR_METADATA = { | ||
name: DEFAULT_CONNECTOR_NAME, | ||
connect: function () { }, | ||
create: function (Model, value, callback) { } | ||
} | ||
const Connector = Arrow.Connector.extend(DEFAULT_CONNECTOR_METADATA) | ||
const connector = new Connector(connectorConfig) | ||
// const library = require('../../lib')(Arrow, DEFAULT_CONNECTOR_NAME) | ||
const container = new Arrow(arrowConfig, true) | ||
const connectorFactory = require('../utils/connectorFactory') | ||
const connector = connectorFactory() | ||
const library = require('../../lib')(Arrow, connector) | ||
test('server, connector, and library', function (t) { | ||
t.ok(server) | ||
test('server, connector, and library', t => { | ||
t.ok(container) | ||
t.ok(connector) | ||
@@ -29,3 +19,3 @@ t.ok(library) | ||
test('createModels', function (t) { | ||
test('createModels', t => { | ||
t.notOk(connector.models) | ||
@@ -41,3 +31,3 @@ const models = library.createModels(modelMetadata2) | ||
test('createModels delayed attachment', function (t) { | ||
test('createModels delayed attachment', t => { | ||
t.notOk(connector.models) | ||
@@ -52,3 +42,3 @@ const models = library.createModels(modelMetadata2, {delayModelsAttachment: true}) | ||
test('createModels - missing metadata', function (t) { | ||
test('createModels - missing metadata', t => { | ||
t.throws(library.createModels) | ||
@@ -58,3 +48,3 @@ t.end() | ||
test('getConnector', function (t) { | ||
test('getConnector', t => { | ||
t.same(connector, library.getConnector()) | ||
@@ -64,3 +54,3 @@ t.end() | ||
test('getConnectorConfig', function (t) { | ||
test('getConnectorConfig', t => { | ||
t.ok(library.getConnectorConfig()) | ||
@@ -70,3 +60,3 @@ t.end() | ||
test('validateModelMetadata - ok', function (t) { | ||
test('validateModelMetadata - ok', t => { | ||
const metadata = modelMetadata1['GoodMetadata'] | ||
@@ -78,3 +68,3 @@ const result = library.validateModelMetadata(metadata) | ||
test('validateModelMetadata - missing metadata', function (t) { | ||
test('validateModelMetadata - missing metadata', t => { | ||
const result = library.validateModelMetadata() | ||
@@ -85,3 +75,3 @@ t.notOk(result) | ||
test('getParentModelName', function (t) { | ||
test('getParentModelName', t => { | ||
const name1 = 'appc.test/myModel1' | ||
@@ -88,0 +78,0 @@ const name2 = 'myModel2' |
@@ -7,3 +7,3 @@ const test = require('tap').test | ||
test('validate - ok', function (t) { | ||
test('validate - ok', t => { | ||
const metadata = modelMetadata['GoodMetadata'] | ||
@@ -15,3 +15,3 @@ const result = dataValidator.validate(metadata, metadataSchema) | ||
test('validate - ko', function (t) { | ||
test('validate - ko', t => { | ||
const metadata = modelMetadata['BadMetadata'] | ||
@@ -24,3 +24,3 @@ const result = dataValidator.validate(metadata, metadataSchema) | ||
test('validate - missing metadata and schema', function (t) { | ||
test('validate - missing metadata and schema', t => { | ||
t.throws(dataValidator.validate) | ||
@@ -30,3 +30,3 @@ t.end() | ||
test('validate - missing schema', function (t) { | ||
test('validate - missing schema', t => { | ||
t.throws(validate) | ||
@@ -33,0 +33,0 @@ t.end() |
@@ -6,3 +6,3 @@ const test = require('tap').test | ||
test('validateModelMetadata - missing metadata', function (t) { | ||
test('validateModelMetadata - missing metadata', t => { | ||
const result = metadataValidator.validateModelMetadata() | ||
@@ -13,3 +13,3 @@ t.notOk(result) | ||
test('validateModelMetadata - ok', function (t) { | ||
test('validateModelMetadata - ok', t => { | ||
const metadata = modelMetadata['GoodMetadata'] | ||
@@ -16,0 +16,0 @@ const result = metadataValidator.validateModelMetadata(metadata) |
@@ -6,22 +6,15 @@ const Arrow = require('arrow') | ||
const arrowConfig = require('../conf/arrow') | ||
const connectorConfig = require('../conf/connector') | ||
const container = new Arrow(arrowConfig, true) | ||
const connectorFactory = require('../utils/connectorFactory') | ||
const connector = connectorFactory() | ||
const arrow = new Arrow(arrowConfig, true) | ||
console.log(arrow) | ||
const DEFAULT_CONNECTOR_NAME = 'appc.test' | ||
const DEFAULT_CONNECTOR_METADATA = { | ||
name: DEFAULT_CONNECTOR_NAME, | ||
connect: function () { }, | ||
create: function (Model, value, callback) { } | ||
} | ||
const Connector = Arrow.Connector.extend(DEFAULT_CONNECTOR_METADATA) | ||
const connector = new Connector(connectorConfig) | ||
const modelApi = require('../../lib/model/api')(Arrow) | ||
// const connector = arrow.getConnector('appc.test') | ||
// const arrow = utils.createArrowWithConnector({arrowConfig, connectorConfig}) | ||
// const connector = arrow.connector | ||
test('environment', t => { | ||
t.ok(container) | ||
t.ok(connector) | ||
t.end() | ||
}) | ||
const modelApi = require('../../lib/model/api')(Arrow) | ||
test('createFromMetadata - missing mandatory parameters', function (t) { | ||
test('createFromMetadata - missing mandatory parameters', t => { | ||
t.throws(modelApi.createFromMetadata) | ||
@@ -31,3 +24,3 @@ t.end() | ||
test('createFromMetadata - missing connector', function (t) { | ||
test('createFromMetadata - missing connector', t => { | ||
t.throws(createFromMetadata) | ||
@@ -41,3 +34,3 @@ t.end() | ||
test('createFromMetadata - missing metadata', function (t) { | ||
test('createFromMetadata - missing metadata', t => { | ||
t.throws(createFromMetadata) | ||
@@ -51,3 +44,3 @@ t.end() | ||
test('createFromMetadata', function (t) { | ||
test('createFromMetadata', t => { | ||
const models = modelApi.createFromMetadata(connector, modelMetadata2) | ||
@@ -60,3 +53,3 @@ t.equal(Object.keys(models).length, 2) | ||
test('createFromMetadata - check extra fields are set', function (t) { | ||
test('createFromMetadata - check extra fields are set', t => { | ||
const models = modelApi.createFromMetadata(connector, modelMetadata3) | ||
@@ -79,3 +72,3 @@ t.equal(Object.keys(models).length, 1) | ||
test('getParentModelName', function (t) { | ||
test('getParentModelName', t => { | ||
const name1 = 'appc.test/myModel1' | ||
@@ -82,0 +75,0 @@ const name2 = 'myModel2' |
41600
22
792
42
8