@architect/inventory 3.4.0-RC.0 → 3.4.1
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 +1 -3
- package/src/config/pragmas/plugins.js +18 -27
- package/src/config/pragmas/tables-indexes.js +22 -1
- package/src/index.js +41 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@architect/inventory",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "Architect project resource enumeration utility",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"@architect/asap": "~5.1.1",
|
|
25
25
|
"@architect/parser": "~6.0.2",
|
|
26
26
|
"@architect/utils": "~3.1.2",
|
|
27
|
-
"esm": "~3.2.25",
|
|
28
27
|
"lambda-runtimes": "~1.1.3"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
@@ -35,7 +34,6 @@
|
|
|
35
34
|
"dotenv": "~16.0.3",
|
|
36
35
|
"eslint": "~8.32.0",
|
|
37
36
|
"mock-fs": "~5.2.0",
|
|
38
|
-
"mock-require": "~3.0.3",
|
|
39
37
|
"nyc": "~15.1.0",
|
|
40
38
|
"tap-spec": "^5.0.0",
|
|
41
39
|
"tape": "^5.6.3"
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
let { join } = require('path')
|
|
1
|
+
let { join, sep } = require('path')
|
|
2
2
|
let { existsSync } = require('fs')
|
|
3
|
-
let { is,
|
|
3
|
+
let { is, pragmas, tidyError, validationPatterns } = require('../../lib')
|
|
4
4
|
let { lambdas } = pragmas
|
|
5
5
|
let nonLambdaSetters = [ 'customLambdas', 'env', 'proxy', 'runtimes', 'shared', 'static', 'views', 'tables', 'tables-indexes' ]
|
|
6
6
|
let setters = [ ...lambdas, ...nonLambdaSetters ]
|
|
7
7
|
let pluginMethods = [ 'deploy', 'hydrate', 'sandbox' ]
|
|
8
8
|
let reservedNames = [ '_methods' ]
|
|
9
|
-
let requireEsm
|
|
10
9
|
|
|
11
|
-
module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
10
|
+
module.exports = async function getPluginModules ({ arc, inventory, errors }) {
|
|
12
11
|
if (!arc?.plugins?.length && !arc?.macros?.length) return null
|
|
13
12
|
let plugins = {}
|
|
14
13
|
let methods = {}
|
|
@@ -31,7 +30,7 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
|
31
30
|
else if (is.object(plugin)) {
|
|
32
31
|
name = Object.keys(plugin)[0]
|
|
33
32
|
pluginPath = plugin[name].src
|
|
34
|
-
?
|
|
33
|
+
? resolve('.' + sep + plugin[name].src, cwd)
|
|
35
34
|
: join(cwd, 'src', type + 's', name)
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -43,6 +42,7 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
|
43
42
|
errors.push('Plugin names can only contain [a-zA-Z0-9/\\-._]')
|
|
44
43
|
continue
|
|
45
44
|
}
|
|
45
|
+
|
|
46
46
|
if (pluginPath) {
|
|
47
47
|
try {
|
|
48
48
|
/* istanbul ignore next: idk why but for some reason nyc isn't picking up the catches; all cases are covered in tests, though! */
|
|
@@ -52,22 +52,15 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
|
52
52
|
plugins[name] = require(pluginPath)
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
|
-
// TODO: if we refactor all pragma visitors to async we can use Node's built in support for dynamic import within CJS
|
|
56
55
|
if (hasEsmError(err)) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let plugin = requireEsm(pluginPath)
|
|
63
|
-
plugins[name] = plugin.default ? plugin.default : plugin
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
errors.push(err)
|
|
67
|
-
}
|
|
56
|
+
let path = process.platform.startsWith('win')
|
|
57
|
+
? 'file://' + pluginPath
|
|
58
|
+
: pluginPath
|
|
59
|
+
let plugin = await import(path)
|
|
60
|
+
plugins[name] = plugin.default ? plugin.default : plugin
|
|
68
61
|
}
|
|
69
62
|
else {
|
|
70
|
-
|
|
63
|
+
throw err
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
66
|
}
|
|
@@ -123,24 +116,23 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
|
123
116
|
return plugins
|
|
124
117
|
}
|
|
125
118
|
|
|
126
|
-
/* istanbul ignore next: per above, nyc isn't picking this up, but it is covered! */
|
|
127
119
|
function getPath (cwd, srcDir, name) {
|
|
128
120
|
let path1 = join(cwd, 'src', srcDir, `${name}.js`)
|
|
129
121
|
let path2 = join(cwd, 'src', srcDir, `${name}.mjs`)
|
|
130
122
|
let path3 = join(cwd, 'src', srcDir, name)
|
|
131
|
-
let path4 = join(cwd, 'node_modules', name)
|
|
132
|
-
let path5 = join(cwd, 'node_modules', `@${name}`)
|
|
133
123
|
/**/ if (existsSync(path1)) return path1
|
|
134
124
|
else if (existsSync(path2)) return path2
|
|
135
|
-
else if (existsSync(path3)) return path3
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
else if (existsSync(path3)) return resolve(path3, cwd)
|
|
126
|
+
return resolve(name, cwd)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function resolve (path, cwd) {
|
|
138
130
|
try {
|
|
139
|
-
return require.resolve(
|
|
131
|
+
return require.resolve(path, { paths: [ cwd ] })
|
|
140
132
|
}
|
|
141
133
|
catch {
|
|
142
134
|
try {
|
|
143
|
-
return require.resolve(`@${
|
|
135
|
+
return require.resolve(`@${path}`, { paths: [ cwd ] })
|
|
144
136
|
}
|
|
145
137
|
catch {
|
|
146
138
|
return
|
|
@@ -154,5 +146,4 @@ let esmErrors = [
|
|
|
154
146
|
'require() of ES Module',
|
|
155
147
|
'Must use import to load ES Module',
|
|
156
148
|
]
|
|
157
|
-
/* istanbul ignore next: per above, nyc isn't picking this up, but it is covered! */
|
|
158
149
|
let hasEsmError = err => esmErrors.some(msg => err.message.includes(msg))
|
|
@@ -20,6 +20,8 @@ module.exports = function configureTablesIndexes ({ arc, inventory, errors }) {
|
|
|
20
20
|
sortKey: null,
|
|
21
21
|
sortKeyType: null,
|
|
22
22
|
indexName: null,
|
|
23
|
+
projectionType: 'ALL',
|
|
24
|
+
projectionAttributes: null,
|
|
23
25
|
})
|
|
24
26
|
|
|
25
27
|
let indexes = []
|
|
@@ -38,6 +40,7 @@ module.exports = function configureTablesIndexes ({ arc, inventory, errors }) {
|
|
|
38
40
|
let i = indexTemplate()
|
|
39
41
|
i.name = Object.keys(index)[0]
|
|
40
42
|
Object.entries(index[i.name]).forEach(([ key, value ]) => {
|
|
43
|
+
let setting = key?.toLowerCase()
|
|
41
44
|
if (is.sortKey(value)) {
|
|
42
45
|
i.sortKey = key
|
|
43
46
|
i.sortKeyType = value.replace('**', '').toLowerCase()
|
|
@@ -48,9 +51,27 @@ module.exports = function configureTablesIndexes ({ arc, inventory, errors }) {
|
|
|
48
51
|
i.partitionKeyType = value.replace('*', '').toLowerCase()
|
|
49
52
|
if (!i.partitionKeyType) i.partitionKeyType = 'string'
|
|
50
53
|
}
|
|
51
|
-
else if (
|
|
54
|
+
else if (setting === 'name') {
|
|
52
55
|
i.indexName = value
|
|
53
56
|
}
|
|
57
|
+
else if (setting === 'projection') {
|
|
58
|
+
let val = (is.string(value) && value.toLowerCase()) || value
|
|
59
|
+
if (val === 'all') {
|
|
60
|
+
i.projectionType = 'ALL'
|
|
61
|
+
}
|
|
62
|
+
else if (val === 'keys') {
|
|
63
|
+
i.projectionType = 'KEYS_ONLY'
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
i.projectionType = 'INCLUDE'
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
i.projectionAttributes = value
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
i.projectionAttributes = [ value ]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
54
75
|
})
|
|
55
76
|
return i
|
|
56
77
|
}
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let { callbackify } = require('util')
|
|
1
2
|
let parse = require('@architect/parser')
|
|
2
3
|
let read = require('./read')
|
|
3
4
|
let inventoryDefaults = require('./defaults')
|
|
@@ -6,6 +7,7 @@ let getEnv = require('./env')
|
|
|
6
7
|
let validate = require('./validate')
|
|
7
8
|
let get = require('./get')
|
|
8
9
|
let { errorFmt } = require('./lib')
|
|
10
|
+
let plugins = callbackify(config.pragmas.plugins)
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Architect Inventory
|
|
@@ -64,46 +66,53 @@ module.exports = function architectInventory (params = {}, callback) {
|
|
|
64
66
|
inventory._arc = config._arc(project)
|
|
65
67
|
|
|
66
68
|
// @plugins come first, as they register hooks all around the project
|
|
67
|
-
|
|
69
|
+
plugins(project, (err, result) => {
|
|
70
|
+
/* istanbul ignore next: yeah we know what happens here */
|
|
71
|
+
if (err) callback(err)
|
|
72
|
+
else {
|
|
73
|
+
inventory.plugins = result
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
// Establish default function config from project + Arc defaults
|
|
76
|
+
inventory._project = config._project(project)
|
|
71
77
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
// End here if plugins failed
|
|
79
|
+
if (errors.length) {
|
|
80
|
+
callback(errorFmt({ type: 'plugin', errors }))
|
|
81
|
+
return promise
|
|
82
|
+
}
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
// Userland: fill out the pragmas, starting with @plugins
|
|
85
|
+
inventory = {
|
|
86
|
+
...inventory,
|
|
87
|
+
...config.pragmas(project)
|
|
88
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
// End here if first-pass validation failed
|
|
91
|
+
if (errors.length) {
|
|
92
|
+
callback(errorFmt({ type: 'validation', errors }))
|
|
93
|
+
return promise
|
|
94
|
+
}
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
// Final validation pass
|
|
97
|
+
let err = validate(params, inventory)
|
|
98
|
+
if (err) {
|
|
99
|
+
callback(err)
|
|
100
|
+
return promise
|
|
101
|
+
}
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
// Maybe get env vars
|
|
104
|
+
getEnv(params, inventory, function done (err) {
|
|
105
|
+
/* istanbul ignore next: yeah we know what happens here */
|
|
106
|
+
if (err) callback(err)
|
|
107
|
+
else {
|
|
108
|
+
callback(null, {
|
|
109
|
+
inv: inventory,
|
|
110
|
+
get: get(inventory)
|
|
111
|
+
})
|
|
112
|
+
}
|
|
105
113
|
})
|
|
106
114
|
}
|
|
107
115
|
})
|
|
116
|
+
|
|
108
117
|
return promise
|
|
109
118
|
}
|