@architect/inventory 6.0.0 → 6.1.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/package.json +3 -3
- package/src/config/pragmas/plugins.js +2 -2
- package/src/config/pragmas/populate-lambda/_queues.js +32 -0
- package/src/config/pragmas/populate-lambda/get-handler.js +0 -1
- package/src/config/pragmas/populate-lambda/get-lambda.js +2 -2
- package/src/config/pragmas/populate-lambda/index.js +7 -3
- package/src/config/pragmas/sort/http.js +2 -1
- package/src/config/pragmas/validate/_events.js +14 -0
- package/src/config/project/index.js +0 -2
- package/src/config/project/prefs/dotenv.js +1 -1
- package/src/config/project/prefs/index.js +8 -5
- package/src/defaults/function-config.js +1 -1
- package/src/env/index.js +1 -1
- package/src/index.js +0 -2
- package/src/lib/asap-src.js +1 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@architect/inventory",
|
|
3
|
-
"version": "6.0.0",
|
|
3
|
+
"version": "6.1.0-RC.0",
|
|
4
4
|
"description": "Architect project resource enumeration utility",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint . --fix",
|
|
8
8
|
"test": "npm run lint && npm run test:integration && npm run test:coverage",
|
|
9
9
|
"test:integration": "node --test --test-reporter=spec test/integration/*-test.js",
|
|
10
|
-
"test:coverage": "node --test --test-reporter=spec --experimental-test-coverage test/unit/**/*-test.js",
|
|
11
|
-
"test:unit": "node --test --test-reporter=spec test/unit/**/*-test.js",
|
|
10
|
+
"test:coverage": "node --test --test-reporter=spec --experimental-test-coverage --test-coverage-lines=100 --test-coverage-exclude='test/**/*' 'test/unit/**/*-test.js'",
|
|
11
|
+
"test:unit": "node --test --test-reporter=spec --test-coverage-exclude='test/**/*' 'test/unit/**/*-test.js'",
|
|
12
12
|
"rc": "npm version prerelease --preid RC",
|
|
13
13
|
"vendor": "scripts/vendor"
|
|
14
14
|
},
|
|
@@ -53,7 +53,6 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
|
|
|
53
53
|
|
|
54
54
|
if (pluginPath) {
|
|
55
55
|
try {
|
|
56
|
-
/* istanbul ignore next: idk why but for some reason nyc isn't picking up the catches; all cases are covered in tests, though! */
|
|
57
56
|
if (type === 'plugin') {
|
|
58
57
|
try {
|
|
59
58
|
plugins[name] = require(pluginPath)
|
|
@@ -167,7 +166,8 @@ async function resolve (path, cwd) {
|
|
|
167
166
|
catch {
|
|
168
167
|
return
|
|
169
168
|
}
|
|
170
|
-
|
|
169
|
+
// idk why but for some reason we aren't picking up the catches; all cases are covered in tests, though!
|
|
170
|
+
/* node:coverage ignore next 2 */
|
|
171
171
|
if (gotSomething) return mjsPath
|
|
172
172
|
else return
|
|
173
173
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
let { is, getLambdaDirs } = require('../../../lib')
|
|
2
|
+
|
|
3
|
+
function getQueueBehaviorProps (item, name) {
|
|
4
|
+
let fifo = is.defined(item?.[name]?.fifo) ? item[name].fifo : null
|
|
5
|
+
let batchSize = is.defined(item?.[name]?.batchSize) ? item[name].batchSize : null
|
|
6
|
+
let batchWindow = is.defined(item?.[name]?.batchWindow) ? item[name].batchWindow : null
|
|
7
|
+
return { fifo, batchSize, batchWindow }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = function populateQueues (params) {
|
|
11
|
+
let { type, item, errors, plugin } = params
|
|
12
|
+
|
|
13
|
+
if (plugin) {
|
|
14
|
+
let { name, src } = item
|
|
15
|
+
if (name && src) {
|
|
16
|
+
return { ...item, ...getQueueBehaviorProps(item, name), ...getLambdaDirs(params, { plugin }) }
|
|
17
|
+
}
|
|
18
|
+
errors.push(`Invalid plugin-generated @${type} item: name: ${name}, src: ${src}`)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
else if (is.string(item)) {
|
|
22
|
+
let name = item
|
|
23
|
+
let dirs = getLambdaDirs(params, { name })
|
|
24
|
+
return { name, ...getQueueBehaviorProps(item, name), ...dirs }
|
|
25
|
+
}
|
|
26
|
+
else if (is.object(item)) {
|
|
27
|
+
let name = Object.keys(item)[0]
|
|
28
|
+
let dirs = getLambdaDirs(params, { name, customSrc: item[name].src })
|
|
29
|
+
return { name, ...getQueueBehaviorProps(item, name), ...dirs }
|
|
30
|
+
}
|
|
31
|
+
errors.push(`Invalid @${type} item: ${item}`)
|
|
32
|
+
}
|
|
@@ -22,7 +22,6 @@ module.exports = function getHandler ({ config, src, build, errors }) {
|
|
|
22
22
|
}
|
|
23
23
|
// Compiled to a binary
|
|
24
24
|
else if (customRuntimeType === 'compiled') {
|
|
25
|
-
/* istanbul ignore next */
|
|
26
25
|
let bootstrap = `bootstrap${isWin ? '.exe' : ''}`
|
|
27
26
|
handlerFile = join(build, runtimeConfig.buildSubpath || '', runtimeConfig.handlerFile || bootstrap)
|
|
28
27
|
handlerMethod = null
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
let getHTTP = require('./_http')
|
|
3
3
|
let getEvents = require('./_events')
|
|
4
4
|
let getCustomLambdas = require('./_custom-lambdas')
|
|
5
|
+
let getQueues = require('./_queues')
|
|
5
6
|
let getScheduled = require('./_scheduled')
|
|
6
7
|
let getWS = require('./_ws')
|
|
7
8
|
let getTablesStreams = require('./_tables-streams')
|
|
@@ -14,10 +15,9 @@ module.exports = function getLambda (params) {
|
|
|
14
15
|
if (type === 'http') return getHTTP(params)
|
|
15
16
|
if (type === 'events') return getEvents(params)
|
|
16
17
|
if (type === cl) return getCustomLambdas(params)
|
|
17
|
-
if (type === 'queues') return
|
|
18
|
+
if (type === 'queues') return getQueues(params)
|
|
18
19
|
if (type === 'scheduled') return getScheduled(params)
|
|
19
20
|
if (type === ts) return getTablesStreams(params)
|
|
20
21
|
if (type === 'tables') return getTablesStreams(params) // Shortcut for creating streams
|
|
21
|
-
/* istanbul ignore else: clearer to be explicit here */
|
|
22
22
|
if (type === 'ws') return getWS(params)
|
|
23
23
|
}
|
|
@@ -90,9 +90,13 @@ function populate (type, pragma, inventory, errors, plugin) {
|
|
|
90
90
|
let config = defaultProjectConfig()
|
|
91
91
|
config = { ...config, ...getKnownProps(configProps, result.config) }
|
|
92
92
|
|
|
93
|
-
// Knock out any pragma-specific early
|
|
93
|
+
// Knock out any pragma-specific bits early
|
|
94
94
|
if (type === 'queues') {
|
|
95
|
-
|
|
95
|
+
// Queues lifted up FIFO out of config and into top-level function semantics
|
|
96
|
+
// config.fifo remains for backward compat (until we want to make a breaking change), while also allowing queue functions to respect @aws global overrides
|
|
97
|
+
if (!is.nullish(result.fifo)) config.fifo = result.fifo
|
|
98
|
+
else if ((!is.nullish(config.fifo))) result.fifo = config.fifo
|
|
99
|
+
else config.fifo = result.fifo = true
|
|
96
100
|
}
|
|
97
101
|
if (type === 'http') {
|
|
98
102
|
if (name.startsWith('get ') || name.startsWith('any ')) {
|
|
@@ -170,7 +174,7 @@ function populate (type, pragma, inventory, errors, plugin) {
|
|
|
170
174
|
let normalize = path => path.replace(/[\\\/]/g, sep)
|
|
171
175
|
|
|
172
176
|
// Lambda setter plugins can technically return anything, so this ensures everything is tidy
|
|
173
|
-
let lambdaProps = [ 'cron', 'method', 'path', 'plugin', 'rate', 'route', 'table', 'type' ]
|
|
177
|
+
let lambdaProps = [ 'cron', 'batchSize', 'batchWindow', 'fifo', 'method', 'path', 'plugin', 'rate', 'route', 'table', 'type' ]
|
|
174
178
|
let configProps = [ ...Object.keys(defaultFunctionConfig()), 'fifo', 'views' ]
|
|
175
179
|
let getKnownProps = (knownProps, raw = {}) => {
|
|
176
180
|
let props = knownProps.flatMap(prop => is.defined(raw[prop]) ? [ [ prop, raw[prop] ] ] : [])
|
|
@@ -31,7 +31,8 @@ module.exports = function sortHTTP (http) {
|
|
|
31
31
|
let sorted = []
|
|
32
32
|
httpMethods.forEach(method => {
|
|
33
33
|
if (!tree[method]) return
|
|
34
|
-
|
|
34
|
+
// random test shuffles may not trigger all paths
|
|
35
|
+
/* node:coverage ignore next */
|
|
35
36
|
tree[method]
|
|
36
37
|
// Sort by depth
|
|
37
38
|
.sort((a, b) => b.depth - a.depth)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let { is } = require('../../../lib')
|
|
1
2
|
let { regex, size, unique } = require('./_lib')
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -38,6 +39,19 @@ module.exports = function validateEventsAndQueues (pragma, pragmaName, errors) {
|
|
|
38
39
|
if (n.startsWith('aws') || n.startsWith('amazon')) {
|
|
39
40
|
errors.push(`Invalid ${pragmaName} item (cannot start with 'AWS' or 'Amazon'): ${name}`)
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
if (event.pragma === 'queues') {
|
|
44
|
+
let { fifo, batchSize, batchWindow } = event
|
|
45
|
+
if (!is.nullish(fifo) && !is.bool(fifo)) {
|
|
46
|
+
errors.push(`Invalid ${pragmaName} item (fifo must be a boolean): ${name}`)
|
|
47
|
+
}
|
|
48
|
+
if (!is.nullish(batchSize) && !is.number(batchSize)) {
|
|
49
|
+
errors.push(`Invalid ${pragmaName} item (batchSize must be a number): ${name}`)
|
|
50
|
+
}
|
|
51
|
+
if (!is.nullish(batchWindow) && !is.number(batchWindow)) {
|
|
52
|
+
errors.push(`Invalid ${pragmaName} item (batchWindow must be a number): ${name}`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
41
55
|
})
|
|
42
56
|
}
|
|
43
57
|
}
|
|
@@ -33,7 +33,6 @@ module.exports = function getProjectConfig (params) {
|
|
|
33
33
|
_project[`${scope}PreferencesFile`] = p.preferencesFile
|
|
34
34
|
|
|
35
35
|
// Build out the final preferences
|
|
36
|
-
/* istanbul ignore else: jic */
|
|
37
36
|
if (!_project.preferences) _project.preferences = {}
|
|
38
37
|
Object.keys(p.preferences).forEach(pragma => {
|
|
39
38
|
// Ignore the raw data
|
|
@@ -44,7 +43,6 @@ module.exports = function getProjectConfig (params) {
|
|
|
44
43
|
return
|
|
45
44
|
}
|
|
46
45
|
// Traverse and merge individual settings
|
|
47
|
-
/* istanbul ignore else: jic */
|
|
48
46
|
if (!_project.preferences[pragma]) _project.preferences[pragma] = {}
|
|
49
47
|
Object.entries(p.preferences[pragma]).forEach(([ setting, value ]) => {
|
|
50
48
|
_project.preferences[pragma][setting] = value
|
|
@@ -25,13 +25,14 @@ module.exports = function getPrefs ({ scope, inventory, errors }) {
|
|
|
25
25
|
// Arc outputs an object of nested arrays
|
|
26
26
|
// Basically, construct a pared-down intermediate prefs obj for consumers
|
|
27
27
|
Object.entries(prefs.arc).forEach(([ key, val ]) => {
|
|
28
|
-
|
|
28
|
+
// Parser should get this, but jic ignore the else - except node test doesn't do ignore else
|
|
29
29
|
if (!preferences[key]) preferences[key] = {}
|
|
30
|
-
|
|
30
|
+
// Parser should only produce arrays, but jic
|
|
31
|
+
/* node:coverage ignore next */
|
|
31
32
|
if (is.array(val)) {
|
|
32
33
|
val.forEach(v => {
|
|
33
34
|
if (is.array(v)) {
|
|
34
|
-
|
|
35
|
+
// Single vals should be strings, but jic - except node test doesn't do ignore if
|
|
35
36
|
if (v.length === 1) preferences[key] = v[0]
|
|
36
37
|
if (v.length === 2) preferences[key][v[0]] = v[1]
|
|
37
38
|
if (v.length > 2) preferences[key][v[0]] = [ ...v.slice(1) ]
|
|
@@ -46,7 +47,8 @@ module.exports = function getPrefs ({ scope, inventory, errors }) {
|
|
|
46
47
|
// Turn env vars with spaces into strings
|
|
47
48
|
if (key === 'env') {
|
|
48
49
|
[ 'testing', 'staging', 'production' ].forEach(e => {
|
|
49
|
-
|
|
50
|
+
// Yet another jic
|
|
51
|
+
/* node:coverage ignore next */
|
|
50
52
|
if (preferences.env[e]) {
|
|
51
53
|
Object.entries(preferences.env[e]).forEach(([ key, val ]) => {
|
|
52
54
|
if (!valid.envVar.test(key)) {
|
|
@@ -62,7 +64,8 @@ module.exports = function getPrefs ({ scope, inventory, errors }) {
|
|
|
62
64
|
if (key === 'sandbox-start' || key === 'sandbox-startup') {
|
|
63
65
|
preferences[key] = val.map(v => {
|
|
64
66
|
if (is.string(v)) return v
|
|
65
|
-
|
|
67
|
+
// Yet another jic
|
|
68
|
+
/* node:coverage ignore next */
|
|
66
69
|
if (is.array(v)) return v.join(' ')
|
|
67
70
|
})
|
|
68
71
|
}
|
package/src/env/index.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = function env (params, inventory, callback) {
|
|
|
13
13
|
let { profile, region } = inventory.aws
|
|
14
14
|
let result = []
|
|
15
15
|
let awsLite = require('@aws-lite/client')
|
|
16
|
-
/*
|
|
16
|
+
/* node:coverage ignore next */
|
|
17
17
|
awsLite({ profile, region, plugins: [ import('@aws-lite/ssm') ] }).then(_aws => {
|
|
18
18
|
aws = _aws
|
|
19
19
|
|
package/src/index.js
CHANGED
|
@@ -67,7 +67,6 @@ module.exports = function architectInventory (params = {}, callback) {
|
|
|
67
67
|
|
|
68
68
|
// @plugins come first, as they register hooks all around the project
|
|
69
69
|
plugins(project, (err, result) => {
|
|
70
|
-
/* istanbul ignore next: yeah we know what happens here */
|
|
71
70
|
if (err) callback(err)
|
|
72
71
|
else {
|
|
73
72
|
inventory.plugins = result
|
|
@@ -102,7 +101,6 @@ module.exports = function architectInventory (params = {}, callback) {
|
|
|
102
101
|
|
|
103
102
|
// Maybe get env vars
|
|
104
103
|
getEnv(params, inventory, function done (err) {
|
|
105
|
-
/* istanbul ignore next: yeah we know what happens here */
|
|
106
104
|
if (err) callback(err)
|
|
107
105
|
else {
|
|
108
106
|
callback(null, {
|
package/src/lib/asap-src.js
CHANGED