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

@architect/utils

Package Overview
Dependencies
Maintainers
7
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/utils - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.eslintignore

56

init/index.js

@@ -40,3 +40,3 @@ let readArcFile = require('../read-arc')

// generate http functions
// generate minimal lambda functions
if (arc.http) {

@@ -49,10 +49,52 @@ let type = 'http'

//let eventFunctions = arc.events.map()
//let queueFunctions = arc.queues.map()
//let tableFunctions = arc.tables.map()
//let wsFunctions = arc.ws.map()
if (arc.events) {
let type = 'events'
functions = functions.concat(arc.events.map(name=> {
return code.bind({}, {type, runtime, name})
}))
}
// the holy trinity of async
parallel(functions, callback)
if (arc.queues) {
let type = 'queues'
functions = functions.concat(arc.queues.map(name=> {
return code.bind({}, {type, runtime, name})
}))
}
/**
*
* TODO scheduled
if (arc.scheduled) {
let type = 'scheduled'
functions = functions.concat(arc.scheduled.map(tuple=> {
let name = tuple.shift()
let rule = tuple.join(' ').trim()
return code.bind({}, {type, runtime, name})
}))
}
* TODO ws lamddaaaa
* TODO generate dynamo streams code
* let tables
if (arc.tables) {
let type = 'tables'
functions = functions.concat()
arc.tables.map(table=> {
let name = Object.keys(table)[0]
var hasInsert = table[name].hasOwnProperty('insert')
var hasUpdate = table[name].hasOwnProperty('update')
var hasDestroy = table[name].hasOwnProperty('destroy')
var hasTrigger = hasInsert || hasUpdate || hasDestroy
if (hasTrigger)
code.bind({}, {type, runtime, name})
})
}*/
parallel(functions, function done(err) {
if (err) callback(err)
else callback()
})
return promise
}

72

init/lambda-code.js

@@ -1,6 +0,11 @@

let getLambdaName = require('../get-lambda-name')
let fs = require('fs')
let mkdir = require('mkdirp')
let {join} = require('path')
let parallel = require('run-parallel')
let getExtension = require('./get-extension')
let getLambdaName = require('../get-lambda-name')
let writeArcConfig = require('./write-arc-config')
let writeCode = require('./write-code')
/**

@@ -11,12 +16,14 @@ * @param {string} type - required. one of: http, event, queue, table, ws

* @param {string} path - optional. of the format: /foo/:bar/baz
* @param {string} name - optional. of the format: hello-world-2020
*/
module.exports = function code({type, runtime, method, path}, callback) {
module.exports = function code({type, runtime, method, path, name}, callback) {
let folder = `${method.toLowerCase()}${getLambdaName(path)}`
let folder = type === 'http'? `${method.toLowerCase()}${getLambdaName(path)}` : name
let extension = getExtension(runtime)
let basePath = join(process.cwd(), 'src', type, folder)
let fullPath = join(basePath, `index.${extension}`)
let defaultPath = join(basePath, `index.js`)
let configPath = join(basePath, `.arc-config`)
if (fs.existsSync(fullPath) || fs.existsSync(defaultPath)) {
// immediate bail if either file exists
if (fs.existsSync(fullPath) || fs.existsSync(configPath)) {
callback()

@@ -27,43 +34,18 @@ }

let body
if (type === 'http' && extension === 'js') {
fs.writeFileSync(join(basePath, '.arc-config'), `@aws\nruntime nodejs10.x`)
body = `// learn more about http functions here: https://arc.codes/guides/http
exports.handler = async function http(req) {
return {
headers: {'content-type': 'text/html; charset=utf8'},
body: '<b>hello world from nodejs<b>'
parallel({
config(callback) {
writeArcConfig({
configPath,
runtime
}, callback)
},
code(callback) {
writeCode({
type,
runtime,
fullPath,
}, callback)
}
}, callback)
}
}`
}
if (type === 'http' && extension === 'py') {
fs.writeFileSync(join(basePath, '.arc-config'), `@aws\nruntime python3.7`)
body = `// learn more about http functions here: https://arc.codes/guides/http
def handler(req, context):
return {'headers': {'content-type': 'text/html'}, 'body': '<b>hello world from python<b>'}`
}
if (type === 'http' && extension === 'rb') {
fs.writeFileSync(join(basePath, '.arc-config'), `@aws\nruntime ruby2.5`)
body = `// learn more about http functions here: https://arc.codes/guides/http
def handler(req)
{headers: {'content-type': 'text/html'}, body: '<b>hello world from ruby<b>'}
end`
}
fs.writeFile(fullPath, body, callback)
}
}
/**
* @param {string} runtime - string that starts with: node, python, ruby
* @returns {string} one of: js, py or rb
*/
function getExtension(runtime) {
if (runtime.startsWith('node')) return 'js'
if (runtime.startsWith('python')) return 'py'
if (runtime.startsWith('ruby')) return 'rb'
throw Error('invalid runtime')
}
{
"name": "@architect/utils",
"version": "1.0.2",
"version": "1.0.3",
"description": "Common utility functions",

@@ -5,0 +5,0 @@ "scripts": {

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