Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appc-connector-utils

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appc-connector-utils - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

lib/utils/fs.js

48

lib/index.js
const metadataValidator = require('./utils/metadataValidator')
const fsUtils = require('./utils/fs')

@@ -11,11 +12,18 @@ module.exports = (Arrow, conn, options) => {

return {
createCollectionFromModel: createCollectionFromModel,
createInstanceFromModel: createInstanceFromModel,
createModels: createModels,
createEndpoints: endpointAPI.createEndpoints,
getConnector: () => connector,
getConnectorConfig: () => connector.config,
validateModelMetadata: metadataValidator.validateModelMetadata,
validateEndpointMetadata: metadataValidator.validateEndpointMetadata,
getRootModelName: modelAPI.getRootModelName,
context: {
config: connector.config,
connector: connector
},
load: {
models: createModels,
endpoints: endpointAPI.createEndpoints
},
create: {
arrowCollection: createArrowCollection,
modelInstance: createModelInstance
},
validate: {
modelMetadata: metadataValidator.validateModelMetadata,
endpointMetadata: metadataValidator.validateEndpointMetadata
},
test: {

@@ -26,10 +34,12 @@ getConnectorStatic: arrowUtils.getConnectorStatic,

stopArrowHttp: arrowUtils.stopArrowHttp
}
},
getRootModelName: modelAPI.getRootModelName,
createDir: fsUtils.createDir
}
function createCollectionFromModel (Model, modelsData, primaryKey) {
return modelsData.map((modelData, index) => {
return createInstanceFromModel(Model, modelData, primaryKey)
})
function createArrowCollection (Model, modelsData, primaryKey) {
return new Arrow.Collection(Model, modelsData.map((modelData, index) => {
return createModelInstance(Model, modelData, primaryKey)
}))
}
function createInstanceFromModel (Model, data, primaryKey) {
function createModelInstance (Model, data, primaryKey) {
const instance = Model.instance(data, true)

@@ -41,3 +51,9 @@ instance.setPrimaryKey(data[primaryKey])

options = options || {}
const models = preserveNamespace(modelAPI.createFromMetadata(connector, modelsMetadata))
var models
const persistModels = connector.config.persistModels
if (persistModels) {
models = preserveNamespace(modelAPI.createFromFileSystem(connector, modelsMetadata))
} else {
models = preserveNamespace(modelAPI.createFromMetadata(connector, modelsMetadata))
}

@@ -44,0 +60,0 @@ if (!options.delayModelsAttachment) {

const pluralize = require('pluralize')
const dataValidator = require('../tools/dataValidator')
const metadataSchema = require('./metadataSchema')
const utils = require('../utils/fs')

@@ -8,5 +9,19 @@ module.exports = (Arrow) => {

createFromMetadata: createFromMetadata,
createFromFileSystem: createFromFileSystem,
getRootModelName: getRootModelName
}
function createFromFileSystem (connector, modelsMetadata) {
connector.modelDir = utils.createDir(connector.name)
createFromMetadata(connector, modelsMetadata)
return Arrow.loadModelsForConnector(connector.name, module, connector.modelDir)
}
/**
* Create models in memory on persist them on disk depending on the configured strategy.
*
* @param {object} connector
* @param {object} modelsMetadata
* @return object that holds all the models or empty object in case we use persistence strategy
*/
function createFromMetadata (connector, modelsMetadata) {

@@ -20,14 +35,18 @@ if (!connector || !modelsMetadata) {

return Object.keys(modelsMetadata).reduce(function (previousModels, modelName) {
const persistModels = connector.config.persistModels
if (loadModels && loadModels.indexOf(modelName) === -1) {
return previousModels
}
const metadata = modelsMetadata[modelName]
metadata.autogen = !!connector.config.modelAutogen
metadata.generated = true
metadata.connector = connector
metadata.connector = connector.name
dataValidator.validate(metadata, metadataSchema)
previousModels[modelName] = Arrow.createModel(createModelName(connector, modelName), metadata)
if (persistModels) {
utils.saveModelSync(createModelName(connector, modelName), metadata, connector.modelDir)
} else {
previousModels[modelName] = Arrow.createModel(createModelName(connector, modelName), metadata)
}
return previousModels

@@ -34,0 +53,0 @@ }, {})

{
"name": "appc-connector-utils",
"version": "0.3.4",
"version": "0.4.0",
"description": "Utilities for Arrow Connectors",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -21,3 +21,3 @@ const Arrow = require('arrow')

t.notOk(connector.models)
const models = library.createModels(modelMetadata2)
const models = library.load.models(modelMetadata2)
t.same(models, connector.models)

@@ -34,3 +34,3 @@ t.equal(Object.keys(models).length, 3)

t.notOk(connector.models)
const models = library.createModels(modelMetadata2, {delayModelsAttachment: true})
const models = library.load.models(modelMetadata2, {delayModelsAttachment: true})
t.notOk(connector.models)

@@ -45,3 +45,3 @@ t.equal(Object.keys(models).length, 3)

test('createModels - missing metadata', t => {
t.throws(library.createModels)
t.throws(library.load.models)
t.end()

@@ -51,3 +51,3 @@ })

test('getConnector', t => {
t.same(connector, library.getConnector())
t.same(connector, library.context.connector)
t.end()

@@ -57,3 +57,3 @@ })

test('getConnectorConfig', t => {
t.ok(library.getConnectorConfig())
t.ok(library.context.config)
t.end()

@@ -64,3 +64,3 @@ })

const metadata = modelMetadata1['GoodMetadata']
const result = library.validateModelMetadata(metadata)
const result = library.validate.modelMetadata(metadata)
t.same(result.value, metadata)

@@ -71,3 +71,3 @@ t.end()

test('validateModelMetadata - missing metadata', t => {
const result = library.validateModelMetadata()
const result = library.validate.modelMetadata()
t.notOk(result)

@@ -118,7 +118,7 @@ t.end()

// Simulate model creation and get it
library.createModels(modelMetadata2)
library.load.models(modelMetadata2)
const model = connector.models['appc.test/Call']
// Use it to create instance from this Model
var result = library.createInstanceFromModel(model, callsMetadata[0], 'sid')
var result = library.create.modelInstance(model, callsMetadata[0], 'sid')
t.ok(result)

@@ -131,7 +131,7 @@ t.equal(typeof result, 'object')

// Simulate model creation and get it
library.createModels(modelMetadata2)
library.load.models(modelMetadata2)
const model = connector.models['appc.test/Call']
// Use it to create collection from this Model
const result = library.createCollectionFromModel(model, callsMetadata, 'sid')
const result = library.create.arrowCollection(model, callsMetadata, 'sid')
t.ok(result)

@@ -138,0 +138,0 @@ t.ok(result instanceof Array)

@@ -68,3 +68,3 @@ const Arrow = require('arrow')

t.ok(createdModel.autogen)
t.same(createdModel.connector, connector)
t.same(createdModel.connector, connector.name)
t.ok(createdModel.disabledActions)

@@ -89,3 +89,3 @@ t.ok(createdModel.fields.Name)

t.ok(createdModel.autogen)
t.same(createdModel.connector, connector)
t.same(createdModel.connector, connector.name)
t.ok(createdModel.disabledActions)

@@ -92,0 +92,0 @@ t.ok(createdModel.fields.Name)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc