@architect/inventory 2.2.0-RC.0 → 3.0.0-RC.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +41 -1
- package/package.json +7 -7
- package/src/config/_upsert.js +1 -1
- package/src/config/pragmas/app.js +1 -1
- package/src/config/pragmas/events.js +3 -2
- package/src/config/pragmas/http.js +8 -4
- package/src/config/pragmas/index.js +16 -5
- package/src/config/pragmas/meta/custom-lambdas.js +10 -0
- package/src/config/pragmas/{src-dirs.js → meta/src-dirs.js} +13 -10
- package/src/config/pragmas/plugins.js +104 -4
- package/src/config/pragmas/populate-lambda/_custom-lambdas.js +10 -0
- package/src/config/pragmas/populate-lambda/_events.js +17 -11
- package/src/config/pragmas/populate-lambda/_http.js +18 -10
- package/src/config/pragmas/populate-lambda/_scheduled.js +18 -10
- package/src/config/pragmas/populate-lambda/_tables-streams.js +20 -23
- package/src/config/pragmas/populate-lambda/_ws.js +26 -0
- package/src/config/pragmas/populate-lambda/get-handler.js +86 -13
- package/src/config/pragmas/populate-lambda/get-lambda.js +23 -0
- package/src/config/pragmas/populate-lambda/get-runtime.js +8 -7
- package/src/config/pragmas/populate-lambda/index.js +104 -86
- package/src/config/pragmas/queues.js +3 -2
- package/src/config/pragmas/scheduled.js +3 -2
- package/src/config/pragmas/shared.js +41 -44
- package/src/config/pragmas/sort/http.js +72 -0
- package/src/config/pragmas/static.js +1 -2
- package/src/config/pragmas/tables-indexes.js +3 -10
- package/src/config/pragmas/tables-streams.js +7 -5
- package/src/config/pragmas/tables.js +1 -1
- package/src/config/pragmas/validate/_events.js +1 -1
- package/src/config/pragmas/validate/_http.js +4 -4
- package/src/config/pragmas/validate/_lib.js +1 -1
- package/src/config/pragmas/validate/_scheduled.js +2 -2
- package/src/config/pragmas/validate/_shared.js +1 -1
- package/src/config/pragmas/validate/_tables-streams.js +6 -8
- package/src/config/pragmas/validate/_tables.js +2 -2
- package/src/config/pragmas/validate/index.js +2 -2
- package/src/config/pragmas/views.js +39 -37
- package/src/config/pragmas/ws.js +6 -4
- package/src/config/project/index.js +15 -10
- package/src/config/project/plugins/index.js +5 -0
- package/src/config/project/plugins/runtimes.js +56 -0
- package/src/config/project/prefs.js +7 -7
- package/src/config/project/validate/index.js +1 -1
- package/src/defaults/index.js +13 -11
- package/src/env/index.js +1 -1
- package/src/get.js +1 -2
- package/src/index.js +17 -15
- package/src/lib/error-fmt.js +2 -10
- package/src/lib/get-lambda-dirs.js +37 -0
- package/src/lib/index.js +26 -0
- package/src/lib/is.js +3 -1
- package/src/lib/pragmas.js +18 -3
- package/src/read/reader.js +1 -1
- package/src/validate/config.js +12 -6
- package/src/validate/index.js +3 -11
- package/src/validate/layers.js +2 -2
- package/src/validate/tables-children.js +5 -5
- package/src/config/pragmas/indexes.js +0 -19
- package/src/config/pragmas/macros.js +0 -5
- package/src/config/pragmas/populate-lambda/_plugins.js +0 -25
- package/src/config/pragmas/populate-lambda/_websockets.js +0 -19
- package/src/config/project/plugins.js +0 -31
package/src/lib/error-fmt.js
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
let { basename } = require('path')
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Common error formatter
|
|
5
3
|
*
|
|
6
4
|
* @param params {object}
|
|
7
5
|
* @param params.type {string} - Inventory error type: `manifest`, `validation`, or `configuration`
|
|
8
6
|
* @param params.errors {array} - Array of one or more errors to output
|
|
9
|
-
* @param params.meta {string} - Appends optional info to primary error message
|
|
10
7
|
* @param params.inventory {object} - Inventory object
|
|
11
8
|
*
|
|
12
9
|
* @returns Formatted Error + appended ARC_ERRORS property
|
|
13
10
|
*/
|
|
14
11
|
module.exports = function format (params) {
|
|
15
|
-
let { type, errors
|
|
16
|
-
if (!meta && type === 'validation') {
|
|
17
|
-
meta = inventory._project.manifest
|
|
18
|
-
? ` in ${basename(inventory._project.manifest)}`
|
|
19
|
-
: ''
|
|
20
|
-
}
|
|
12
|
+
let { type, errors } = params
|
|
21
13
|
let output = errors.map(err => `- ${err}`).join('\n')
|
|
22
14
|
let errType = type[0].toUpperCase() + type.substr(1)
|
|
23
|
-
let err = Error(`${errType} error${errors.length > 1 ? 's' : ''}
|
|
15
|
+
let err = Error(`${errType} error${errors.length > 1 ? 's' : ''}:\n${output}`)
|
|
24
16
|
err.ARC_ERRORS = { type, errors }
|
|
25
17
|
return err
|
|
26
18
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
let { join } = require('path')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the src (and build) dirs for a Lambda
|
|
5
|
+
* - Arc Lambdas: pass a name + pragma || relative file path
|
|
6
|
+
* - Plugin Lambdas: pass a relative file path || absolute file path
|
|
7
|
+
*/
|
|
8
|
+
function getLambdaDirs (params, options) {
|
|
9
|
+
let { cwd, item, projSrc, projBuild, type: pragma } = params
|
|
10
|
+
let { name, plugin, customSrc } = options
|
|
11
|
+
let lambdaDirs = {}
|
|
12
|
+
|
|
13
|
+
if (plugin) {
|
|
14
|
+
let src = normalizeSrc(cwd, item.src)
|
|
15
|
+
lambdaDirs.src = src
|
|
16
|
+
if (projBuild) {
|
|
17
|
+
lambdaDirs.build = src.replace(src, projBuild)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
let root = customSrc ? cwd : projSrc
|
|
22
|
+
let path = customSrc || join(pragma, name)
|
|
23
|
+
lambdaDirs.src = join(root, path)
|
|
24
|
+
if (projBuild) {
|
|
25
|
+
lambdaDirs.build = join(projBuild, path)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return lambdaDirs
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normalizeSrc (cwd, dir) {
|
|
32
|
+
if (!dir.startsWith(cwd)) return join(cwd, dir)
|
|
33
|
+
return dir
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getLambdaDirs.normalizeSrc = normalizeSrc
|
|
37
|
+
module.exports = getLambdaDirs
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
let asapSrc = require('./asap-src')
|
|
2
|
+
let errorFmt = require('./error-fmt')
|
|
3
|
+
let getLambdaDirs = require('./get-lambda-dirs')
|
|
4
|
+
let is = require('./is')
|
|
5
|
+
let pragmas = require('./pragmas')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Why take up a whole fs block when smol libs can just live here?
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// For setting `lambda.build`, compiled + transpiled are effectively the same
|
|
12
|
+
let compiledRuntimes = [ 'compiled', 'transpiled' ]
|
|
13
|
+
|
|
14
|
+
// `any` must come last for Sandbox route sorting purposes
|
|
15
|
+
let httpMethods = [ 'get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'any' ]
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
asapSrc,
|
|
19
|
+
compiledRuntimes,
|
|
20
|
+
errorFmt,
|
|
21
|
+
getLambdaDirs,
|
|
22
|
+
normalizeSrc: getLambdaDirs.normalizeSrc,
|
|
23
|
+
httpMethods,
|
|
24
|
+
is,
|
|
25
|
+
pragmas,
|
|
26
|
+
}
|
package/src/lib/is.js
CHANGED
|
@@ -4,10 +4,12 @@ module.exports = {
|
|
|
4
4
|
// Types
|
|
5
5
|
array: item => Array.isArray(item),
|
|
6
6
|
bool: item => typeof item === 'boolean',
|
|
7
|
+
defined: item => typeof item !== 'undefined',
|
|
8
|
+
fn: item => typeof item === 'function',
|
|
9
|
+
nullish: item => typeof item === 'undefined' || item === null,
|
|
7
10
|
number: item => Number.isInteger(item),
|
|
8
11
|
object: item => typeof item === 'object' && !Array.isArray(item),
|
|
9
12
|
string: item => typeof item === 'string',
|
|
10
|
-
defined: item => typeof item !== 'undefined' && item !== null,
|
|
11
13
|
// Filesystem
|
|
12
14
|
exists: path => existsSync(path),
|
|
13
15
|
folder: path => existsSync(path) && lstatSync(path).isDirectory(),
|
package/src/lib/pragmas.js
CHANGED
|
@@ -6,8 +6,6 @@ module.exports = {
|
|
|
6
6
|
'cdn',
|
|
7
7
|
'events',
|
|
8
8
|
'http',
|
|
9
|
-
'indexes', // -> transitioning to @tables-indexes
|
|
10
|
-
'macros',
|
|
11
9
|
'plugins',
|
|
12
10
|
'proxy',
|
|
13
11
|
'queues',
|
|
@@ -24,10 +22,27 @@ module.exports = {
|
|
|
24
22
|
lambdas: [
|
|
25
23
|
'events',
|
|
26
24
|
'http',
|
|
27
|
-
'plugins',
|
|
28
25
|
'queues',
|
|
29
26
|
'scheduled',
|
|
30
27
|
'tables-streams',
|
|
31
28
|
'ws',
|
|
32
29
|
],
|
|
30
|
+
// Reserved pragma names that map to internal Inventory properties
|
|
31
|
+
reserved: [
|
|
32
|
+
'customLambdas',
|
|
33
|
+
],
|
|
34
|
+
// Retired pragmas no longer in active use
|
|
35
|
+
retired: [
|
|
36
|
+
'indexes',
|
|
37
|
+
'macros',
|
|
38
|
+
'slack',
|
|
39
|
+
// Static types
|
|
40
|
+
'css',
|
|
41
|
+
'html',
|
|
42
|
+
'js',
|
|
43
|
+
'json',
|
|
44
|
+
'jsonapi',
|
|
45
|
+
'text',
|
|
46
|
+
'xml',
|
|
47
|
+
]
|
|
33
48
|
}
|
package/src/read/reader.js
CHANGED
package/src/validate/config.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
let is = require('../lib
|
|
2
|
-
let { lambdas } =
|
|
1
|
+
let { is, pragmas } = require('../lib')
|
|
2
|
+
let { lambdas } = pragmas
|
|
3
3
|
let { aliases, runtimeList } = require('lambda-runtimes')
|
|
4
|
-
let allRuntimes = runtimeList.concat([ 'deno' ])
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Configuration validator
|
|
8
7
|
*/
|
|
9
8
|
module.exports = function configValidator (params, inventory, errors) {
|
|
10
|
-
let {
|
|
9
|
+
let {
|
|
10
|
+
runtime: globalRuntime,
|
|
11
|
+
memory: globalMemory,
|
|
12
|
+
timeout: globalTimeout
|
|
13
|
+
} = inventory.aws
|
|
14
|
+
|
|
15
|
+
let customRuntimes = inventory._project?.customRuntimes?.runtimes || []
|
|
16
|
+
let allRuntimes = runtimeList.concat([ 'deno', ...customRuntimes ])
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Global config
|
|
14
20
|
*/
|
|
15
21
|
// Memory
|
|
16
|
-
if (is.
|
|
22
|
+
if (!is.nullish(globalMemory) && invalidMemory(globalMemory)) {
|
|
17
23
|
errors.push(invalidMemoryMsg(`${globalMemory} MB (@aws)`))
|
|
18
24
|
}
|
|
19
25
|
// Runtime
|
|
@@ -23,7 +29,7 @@ module.exports = function configValidator (params, inventory, errors) {
|
|
|
23
29
|
errors.push(`Invalid project-level runtime: ${globalRuntime}`)
|
|
24
30
|
}
|
|
25
31
|
// Timeout
|
|
26
|
-
if (is.
|
|
32
|
+
if (!is.nullish(globalTimeout) && invalidTimeout(globalTimeout)) {
|
|
27
33
|
errors.push(invalidTimeoutMsg(`${globalTimeout} seconds (@aws)`))
|
|
28
34
|
}
|
|
29
35
|
|
package/src/validate/index.js
CHANGED
|
@@ -21,24 +21,16 @@ module.exports = function finalValidation (params, inventory) {
|
|
|
21
21
|
// TODO add deeper policy validation here
|
|
22
22
|
|
|
23
23
|
if (errors.length) {
|
|
24
|
-
return errorFmt({
|
|
25
|
-
type: 'configuration',
|
|
26
|
-
errors,
|
|
27
|
-
inventory,
|
|
28
|
-
})
|
|
24
|
+
return errorFmt({ type: 'configuration', errors })
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
28
|
* Deal with project validation errors
|
|
33
29
|
*/
|
|
34
|
-
// Ensure @tables children (@tables-streams, @indexes) have parent tables present
|
|
30
|
+
// Ensure @tables children (@tables-streams, @tables-indexes) have parent tables present
|
|
35
31
|
tablesChildren(inventory, errors)
|
|
36
32
|
|
|
37
33
|
if (errors.length) {
|
|
38
|
-
return errorFmt({
|
|
39
|
-
type: 'validation',
|
|
40
|
-
errors,
|
|
41
|
-
inventory,
|
|
42
|
-
})
|
|
34
|
+
return errorFmt({ type: 'validation', errors })
|
|
43
35
|
}
|
|
44
36
|
}
|
package/src/validate/layers.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Ensure @tables children (@tables-streams, @indexes) have parent tables present
|
|
2
|
+
* Ensure @tables children (@tables-streams, @tables-indexes) have parent tables present
|
|
3
3
|
* - If not, configuration is invalid
|
|
4
4
|
*/
|
|
5
5
|
module.exports = function validateTablesChildren (inventory, errors) {
|
|
6
|
-
let { indexes, 'tables-streams':
|
|
6
|
+
let { 'tables-indexes': indexes, 'tables-streams': streams, tables } = inventory
|
|
7
7
|
|
|
8
8
|
function check (table, type) {
|
|
9
9
|
if (!tables.some(t => t.name === table)) {
|
|
10
10
|
errors.push(`@${type} ${table} missing corresponding table`)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
if (streams) {
|
|
14
|
+
streams.forEach(stream => check(stream.table, 'tables-streams'))
|
|
15
15
|
}
|
|
16
16
|
if (indexes) {
|
|
17
|
-
indexes.forEach(index => check(index.name, 'indexes'))
|
|
17
|
+
indexes.forEach(index => check(index.name, 'tables-indexes'))
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
let validate = require('./validate')
|
|
2
|
-
let { getIndexes } = require('./tables-indexes')
|
|
3
|
-
|
|
4
|
-
module.exports = function configureIndexes ({ arc, errors }) {
|
|
5
|
-
if (!arc.indexes || !arc.indexes.length) return null
|
|
6
|
-
if (arc.indexes && !arc.tables) {
|
|
7
|
-
errors.push(`Specifying @indexes requires specifying corresponding @tables`)
|
|
8
|
-
return null
|
|
9
|
-
}
|
|
10
|
-
if (arc['tables-indexes']?.length && arc.indexes?.length) {
|
|
11
|
-
errors.push(`Either @tables-indexes or @indexes can be specified, but not both`)
|
|
12
|
-
return null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let indexes = getIndexes(arc, 'indexes', errors)
|
|
16
|
-
validate.indexes(indexes, '@indexes', errors)
|
|
17
|
-
|
|
18
|
-
return indexes
|
|
19
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
let { getLambdaName } = require('@architect/utils')
|
|
2
|
-
|
|
3
|
-
module.exports = function populatePlugins ({ item: pluginName, cwd, inventory, errors }) {
|
|
4
|
-
if (inventory._project.plugins[pluginName]) {
|
|
5
|
-
let pluginModule = inventory._project.plugins[pluginName]
|
|
6
|
-
if (pluginModule.functions || pluginModule.pluginFunctions) {
|
|
7
|
-
let funk = pluginModule.functions || pluginModule.pluginFunctions
|
|
8
|
-
let lambdas = funk({
|
|
9
|
-
arc: inventory._project.arc,
|
|
10
|
-
inventory: { inv: inventory }
|
|
11
|
-
}).map(f => {
|
|
12
|
-
// strip leading `src/` from the path to the plugin function relative to project root
|
|
13
|
-
let pathToCode = f.src.replace(cwd, '').replace(/^\.?\/?\\?/, '').replace(/^src\/?\\?/, '')
|
|
14
|
-
let name = getLambdaName(pathToCode)
|
|
15
|
-
f.name = name
|
|
16
|
-
return f
|
|
17
|
-
})
|
|
18
|
-
if (lambdas.length) {
|
|
19
|
-
return lambdas
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
errors.push(`Invalid @plugins item: ${pluginName}`)
|
|
25
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
let { join } = require('path')
|
|
2
|
-
let is = require('../../../lib/is')
|
|
3
|
-
|
|
4
|
-
module.exports = function populateWebSockets ({ item, dir, cwd, errors }) {
|
|
5
|
-
if (is.string(item)) {
|
|
6
|
-
let name = item
|
|
7
|
-
let route = name // Same as name, just what AWS calls it
|
|
8
|
-
let src = join(cwd, dir, name)
|
|
9
|
-
return { name, route, src }
|
|
10
|
-
}
|
|
11
|
-
else if (is.object(item)) {
|
|
12
|
-
let name = Object.keys(item)[0]
|
|
13
|
-
let route = name
|
|
14
|
-
// Add back src switch on presence of item[name].src when WS gets more options
|
|
15
|
-
let src = join(cwd, item[name].src)
|
|
16
|
-
return { name, route, src }
|
|
17
|
-
}
|
|
18
|
-
errors.push(`Invalid @ws item: ${item}`)
|
|
19
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
let { join } = require('path')
|
|
2
|
-
let { existsSync } = require('fs')
|
|
3
|
-
|
|
4
|
-
module.exports = function getPluginModules (project, errors) {
|
|
5
|
-
let arc = project.arc
|
|
6
|
-
if (!arc.plugins || !arc.plugins.length) return null
|
|
7
|
-
let plugins = {}
|
|
8
|
-
let cwd = project.src
|
|
9
|
-
for (let name of arc.plugins) {
|
|
10
|
-
let pluginPath = null
|
|
11
|
-
let localPath = join(cwd, 'src', 'plugins', `${name}.js`)
|
|
12
|
-
let localPath1 = join(cwd, 'src', 'plugins', name)
|
|
13
|
-
let modulePath = join(cwd, 'node_modules', name)
|
|
14
|
-
let modulePath1 = join(cwd, 'node_modules', `@${name}`)
|
|
15
|
-
if (existsSync(localPath)) pluginPath = localPath
|
|
16
|
-
else if (existsSync(localPath1)) pluginPath = localPath1
|
|
17
|
-
else if (existsSync(modulePath)) pluginPath = modulePath
|
|
18
|
-
else if (existsSync(modulePath1)) pluginPath = modulePath1
|
|
19
|
-
if (pluginPath) {
|
|
20
|
-
try {
|
|
21
|
-
// eslint-disable-next-line
|
|
22
|
-
plugins[name] = require(pluginPath)
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
errors.push(`Unable to load plugin '${name}': ${err.message.split('\n')[0]}`)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else errors.push(`Cannot find plugin '${name}'! Are you sure you have installed or created it correctly?`)
|
|
29
|
-
}
|
|
30
|
-
return plugins
|
|
31
|
-
}
|