@architect/inventory 2.2.1 → 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 +31 -0
- package/package.json +5 -5
- 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 +5 -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 +2 -2
- 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 +3 -3
- 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 +13 -8
- package/src/config/project/plugins/index.js +5 -0
- package/src/config/project/plugins/runtimes.js +56 -0
- package/src/config/project/prefs.js +2 -2
- package/src/config/project/validate/index.js +1 -1
- package/src/defaults/index.js +13 -11
- 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/http-methods.js +0 -2
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
|
-
}
|
package/src/lib/http-methods.js
DELETED