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.0.11 to 0.1.0

test/data/callsMetadata.js

15

lib/index.js

@@ -10,2 +10,4 @@ const metadataValidator = require('./utils/metadataValidator')

return {
createCollectionFromModel: createCollectionFromModel,
createInstanceFromModel: createInstanceFromModel,
createModels: createModels,

@@ -15,3 +17,3 @@ getConnector: () => connector,

validateModelMetadata: metadataValidator.validateModelMetadata,
getParentModelName: modelAPI.getParentModelName,
getRootModelName: modelAPI.getRootModelName,
test: {

@@ -24,3 +26,12 @@ getConnectorStatic: arrowUtils.getConnectorStatic,

}
function createCollectionFromModel (Model, modelsData, primaryKey) {
return modelsData.map((modelData, index) => {
return createInstanceFromModel(Model, modelData, primaryKey)
})
}
function createInstanceFromModel (Model, data, primaryKey) {
const instance = Model.instance(data, true)
instance.setPrimaryKey(data[primaryKey])
return instance
}
function createModels (modelsMetadata, options) {

@@ -27,0 +38,0 @@ options = options || {}

10

lib/model/api.js

@@ -7,3 +7,3 @@ const dataValidator = require('../tools/dataValidator')

createFromMetadata: createFromMetadata,
getParentModelName: getParentModelName
getRootModelName: getRootModelName
}

@@ -34,3 +34,7 @@

*/
function getParentModelName (model) {
function getRootModelName (model) {
if (!model) {
throw new Error('Please provide Arrow Model')
}
const namespaceDelimiter = '/'

@@ -42,3 +46,3 @@ var parent = model

if (!parent.name) {
throw new Error('The provided model has no parent with name and has no name itself')
throw new Error('The provided model has no name or parent with name')
}

@@ -45,0 +49,0 @@ return {

{
"name": "appc-connector-utils",
"version": "0.0.11",
"version": "0.1.0",
"description": "Utilities for Arrow Connectors",

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

{
"Call": {
"fields": {
"sid": {
"type": "String",
"description": "A34 character String that uniquely identifies this resource."
},
"dateCreated": {
"type": "String",
"description": "The date that this resource was created, given as GMT in RFC2822 format."
},
"parentCallSid": {
"type": "String",
"description": "A34 character String that uniquely identifies the call that created this leg."
},
"to": {
"type": "String",
"required": true,
"description": "The phone number, SIP address or Client identifier that received this call. Phone numbers are in E.164 format (e.g. +16175551212). SIP addresses are formated as name@company.com. Client identifiers are formatted client:name."
},
"from": {
"type": "String",
"description": "The phone number, SIP address or Client identifier that made this call. Phone numbers are in E.164 format (e.g. +16175551212). SIP addresses are formated as name@company.com. Client identifiers are formatted client:name."
},
"fromFormatted": {
"type": "String",
"description": "The formatted phone number, Sip, address or Client that made this call"
},
"phoneNumberSid": {
"type": "String",
"description": "If the call was inbound, this is the Sid of the IncomingPhoneNumber that received the call. If the call was outbound, it is the Sid of the OutgoingCallerId from which the call was placed."
},
"status": {
"type": "String",
"description": "A String representing the status of the call. May be queued, ringing, in-progress, canceled, completed, failed, busy or no-answer."
},
"startTime": {
"type": "String",
"description": "The start time of the call, given as GMT in RFC2822 format. Empty if the call has not yet been dialed."
},
"endTime": {
"type": "String",
"description": "The end time of the call, given as GMT in RFC2822 format. Empty if the call has not yet been completed."
},
"duration": {
"type": "String",
"description": "The length of the call in seconds. This value is empty for busy, failed, unanswered or ongoing calls."
},
"price": {
"type": "String",
"description": "The charge for this call, in the currency associated with the account. Populated after the call is completed. May not be immediately available."
},
"priceUnit": {
"type": "String",
"description": "The currency in which Price is measured, in ISO4127 format (e.g. USD, EUR, JPY). Always capitalized for calls."
},
"direction": {
"type": "String",
"description": "A String describing the direction of the call. inbound for inbound calls, outbound-api for calls initiated via the REST API or outbound-dial for calls initiated by a <Dial> verb."
},
"answeredBy": {
"type": "String",
"description": "If this call was initiated with answering machine detection, either human or machine. Empty otherwise."
},
"annotation": {
"type": "String",
"description": "An annotation is a metadatum (e.g. a comment, explanation, presentational markup)"
},
"apiVersion": {
"type": "String",
"description": "Version of the Twilio API"
},
"forwardedFrom": {
"type": "String",
"description": "If this call was an incoming call forwarded from another number, the forwarding phone number (depends on carrier supporting forwarding). Empty otherwise."
},
"groupSid": {
"type": "String",
"description": "A34 character String that uniquely identifies this resource."
},
"callerName": {
"type": "String",
"description": "If this call was an incoming call to a phone number with Caller ID Lookup enabled, the caller name. Empty otherwise."
},
"uri": {
"type": "String",
"description": "The URI for this resource, relative to 'api.twilio.com'"
},
"subresourceUris": {
"type": "Object",
"description": "The subresource URI for this resource"
}
},
"actions": [
"create",
"read",
"delete"
]
},
"People": {

@@ -6,15 +104,15 @@ "name": "People",

"FirstName": {
"type": "string",
"type": "String",
"required": true
},
"LastName": {
"type": "string",
"type": "String",
"required": false
},
"MiddleName": {
"type": "string",
"type": "String",
"required": false
},
"Gender": {
"type": "string",
"type": "String",
"required": true

@@ -39,3 +137,3 @@ },

"FavoriteFeature": {
"type": "string",
"type": "String",
"required": true

@@ -53,3 +151,3 @@ },

"BestFriend": {
"type": "string",
"type": "String",
"required": false,

@@ -72,3 +170,3 @@ "model": "Person"

"Name": {
"type": "string",
"type": "String",
"required": false

@@ -75,0 +173,0 @@ }

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

const modelMetadata2 = require('../data/modelMetadata2')
const callsMetadata = require('../data/callsMetadata')
const arrowConfig = require('../conf/arrow')

@@ -23,5 +24,6 @@ const container = new Arrow(arrowConfig, true)

t.same(models, connector.models)
t.equal(Object.keys(models).length, 2)
t.equal(Object.keys(models).length, 3)
t.ok(models['People'])
t.ok(models['Airlines'])
t.ok(models['Call'])
connector.models = null

@@ -35,5 +37,6 @@ t.end()

t.notOk(connector.models)
t.equal(Object.keys(models).length, 2)
t.equal(Object.keys(models).length, 3)
t.ok(models['People'])
t.ok(models['Airlines'])
t.ok(models['Call'])
t.end()

@@ -70,3 +73,3 @@ })

test('getParentModelName', t => {
test('getRootModelName', t => {
const name1 = 'appc.test/myModel1'

@@ -85,25 +88,50 @@ const name2 = 'myModel2'

const name1Result = library.getParentModelName(modelWithNamespace)
const name1Result = library.getRootModelName(modelWithNamespace)
t.equal(name1Result.nameOnly, 'myModel1')
t.equal(name1Result.withNamespace, name1)
const name2Result = library.getParentModelName(modelWithoutNamespace)
const name2Result = library.getRootModelName(modelWithoutNamespace)
t.equal(name2Result.nameOnly, name2)
t.equal(name2Result.withNamespace, name2)
const name3Result = library.getParentModelName(modelWithParent)
const name3Result = library.getRootModelName(modelWithParent)
t.equal(name3Result.nameOnly, name3)
t.equal(name3Result.withNamespace, name3)
const name4Result = library.getParentModelName(modelWithParentNamespaced)
const name4Result = library.getRootModelName(modelWithParentNamespaced)
t.equal(name4Result.nameOnly, 'myModel4')
t.equal(name4Result.withNamespace, name4)
const name5Result = library.getParentModelName(modelWithParentNoName)
const name5Result = library.getRootModelName(modelWithParentNoName)
t.equal(name5Result.nameOnly, 'myModel5')
t.equal(name5Result.withNamespace, name5)
t.throws(library.getParentModelName.bind(null, wrongModel))
t.throws(library.getRootModelName.bind(null, wrongModel))
t.end()
})
test('createInstanceFromModel', t => {
// Simulate model creation and get it
library.createModels(modelMetadata2)
const model = connector.models.Call
// Use it to create instance from this Model
var result = library.createInstanceFromModel(model, callsMetadata[0], 'sid')
t.ok(result)
t.equal(typeof result, 'object')
t.end()
})
test('createCollectionFromModel', t => {
// Simulate model creation and get it
library.createModels(modelMetadata2)
const model = connector.models.Call
// Use it to create collection from this Model
const result = library.createCollectionFromModel(model, callsMetadata, 'sid')
t.ok(result)
t.ok(result instanceof Array)
t.ok(result.length === 3)
t.end()
})

@@ -43,5 +43,6 @@ const Arrow = require('arrow')

const models = modelApi.createFromMetadata(connector, modelMetadata2)
t.equal(Object.keys(models).length, 2)
t.equal(Object.keys(models).length, 3)
t.ok(models['People'])
t.ok(models['Airlines'])
t.ok(models['Call'])
t.end()

@@ -68,3 +69,3 @@ })

test('getParentModelName', t => {
test('getRootModelName', t => {
const name1 = 'appc.test/myModel1'

@@ -83,23 +84,23 @@ const name2 = 'myModel2'

const name1Result = modelApi.getParentModelName(modelWithNamespace)
const name1Result = modelApi.getRootModelName(modelWithNamespace)
t.equal(name1Result.nameOnly, 'myModel1')
t.equal(name1Result.withNamespace, name1)
const name2Result = modelApi.getParentModelName(modelWithoutNamespace)
const name2Result = modelApi.getRootModelName(modelWithoutNamespace)
t.equal(name2Result.nameOnly, name2)
t.equal(name2Result.withNamespace, name2)
const name3Result = modelApi.getParentModelName(modelWithParent)
const name3Result = modelApi.getRootModelName(modelWithParent)
t.equal(name3Result.nameOnly, name3)
t.equal(name3Result.withNamespace, name3)
const name4Result = modelApi.getParentModelName(modelWithParentNamespaced)
const name4Result = modelApi.getRootModelName(modelWithParentNamespaced)
t.equal(name4Result.nameOnly, 'myModel4')
t.equal(name4Result.withNamespace, name4)
const name5Result = modelApi.getParentModelName(modelWithParentNoName)
const name5Result = modelApi.getRootModelName(modelWithParentNoName)
t.equal(name5Result.nameOnly, 'myModel5')
t.equal(name5Result.withNamespace, name5)
t.throws(modelApi.getParentModelName.bind(null, wrongModel))
t.throws(modelApi.getRootModelName.bind(null, wrongModel))

@@ -106,0 +107,0 @@ t.end()

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