@architect/inventory 2.2.1-RC.0 → 3.0.0-RC.2

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.
Files changed (63) hide show
  1. package/changelog.md +34 -1
  2. package/package.json +5 -5
  3. package/src/config/_upsert.js +1 -1
  4. package/src/config/pragmas/app.js +1 -1
  5. package/src/config/pragmas/events.js +3 -2
  6. package/src/config/pragmas/http.js +5 -4
  7. package/src/config/pragmas/index.js +16 -5
  8. package/src/config/pragmas/meta/custom-lambdas.js +10 -0
  9. package/src/config/pragmas/{src-dirs.js → meta/src-dirs.js} +13 -10
  10. package/src/config/pragmas/plugins.js +104 -4
  11. package/src/config/pragmas/populate-lambda/_custom-lambdas.js +10 -0
  12. package/src/config/pragmas/populate-lambda/_events.js +17 -11
  13. package/src/config/pragmas/populate-lambda/_http.js +18 -10
  14. package/src/config/pragmas/populate-lambda/_scheduled.js +18 -10
  15. package/src/config/pragmas/populate-lambda/_tables-streams.js +20 -23
  16. package/src/config/pragmas/populate-lambda/_ws.js +26 -0
  17. package/src/config/pragmas/populate-lambda/get-handler.js +86 -13
  18. package/src/config/pragmas/populate-lambda/get-lambda.js +23 -0
  19. package/src/config/pragmas/populate-lambda/get-runtime.js +8 -7
  20. package/src/config/pragmas/populate-lambda/index.js +104 -86
  21. package/src/config/pragmas/queues.js +3 -2
  22. package/src/config/pragmas/scheduled.js +3 -2
  23. package/src/config/pragmas/shared.js +41 -44
  24. package/src/config/pragmas/sort/http.js +3 -2
  25. package/src/config/pragmas/static.js +1 -2
  26. package/src/config/pragmas/tables-indexes.js +3 -10
  27. package/src/config/pragmas/tables-streams.js +7 -5
  28. package/src/config/pragmas/tables.js +1 -1
  29. package/src/config/pragmas/validate/_events.js +1 -1
  30. package/src/config/pragmas/validate/_http.js +4 -4
  31. package/src/config/pragmas/validate/_lib.js +1 -1
  32. package/src/config/pragmas/validate/_scheduled.js +2 -2
  33. package/src/config/pragmas/validate/_shared.js +1 -1
  34. package/src/config/pragmas/validate/_tables-streams.js +6 -8
  35. package/src/config/pragmas/validate/_tables.js +2 -2
  36. package/src/config/pragmas/validate/index.js +2 -2
  37. package/src/config/pragmas/views.js +39 -37
  38. package/src/config/pragmas/ws.js +6 -4
  39. package/src/config/project/index.js +15 -10
  40. package/src/config/project/plugins/index.js +5 -0
  41. package/src/config/project/plugins/runtimes.js +56 -0
  42. package/src/config/project/prefs.js +7 -7
  43. package/src/config/project/validate/index.js +1 -1
  44. package/src/defaults/index.js +15 -12
  45. package/src/env/index.js +1 -1
  46. package/src/get.js +1 -2
  47. package/src/index.js +17 -15
  48. package/src/lib/error-fmt.js +2 -10
  49. package/src/lib/get-lambda-dirs.js +37 -0
  50. package/src/lib/index.js +26 -0
  51. package/src/lib/is.js +3 -1
  52. package/src/lib/pragmas.js +19 -3
  53. package/src/read/reader.js +1 -1
  54. package/src/validate/config.js +12 -6
  55. package/src/validate/index.js +3 -11
  56. package/src/validate/layers.js +2 -2
  57. package/src/validate/tables-children.js +5 -5
  58. package/src/config/pragmas/indexes.js +0 -19
  59. package/src/config/pragmas/macros.js +0 -5
  60. package/src/config/pragmas/populate-lambda/_plugins.js +0 -25
  61. package/src/config/pragmas/populate-lambda/_websockets.js +0 -19
  62. package/src/config/project/plugins.js +0 -31
  63. package/src/lib/http-methods.js +0 -2
@@ -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(),
@@ -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,28 @@ 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
+ 'streams', // Never fully launched
40
+ // Static types
41
+ 'css',
42
+ 'html',
43
+ 'js',
44
+ 'json',
45
+ 'jsonapi',
46
+ 'text',
47
+ 'xml',
48
+ ]
33
49
  }
@@ -1,7 +1,7 @@
1
1
  let parse = require('@architect/parser')
2
2
  let { existsSync, readFileSync } = require('fs')
3
3
  let { join } = require('path')
4
- let is = require('../lib/is')
4
+ let { is } = require('../lib')
5
5
  let read = p => readFileSync(p).toString()
6
6
 
7
7
  /**
@@ -1,19 +1,25 @@
1
- let is = require('../lib/is')
2
- let { lambdas } = require('../lib/pragmas')
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 { runtime: globalRuntime, memory: globalMemory, timeout: globalTimeout } = inventory.aws
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.defined(globalMemory) && invalidMemory(globalMemory)) {
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.defined(globalTimeout) && invalidTimeout(globalTimeout)) {
32
+ if (!is.nullish(globalTimeout) && invalidTimeout(globalTimeout)) {
27
33
  errors.push(invalidTimeoutMsg(`${globalTimeout} seconds (@aws)`))
28
34
  }
29
35
 
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  let { sep } = require('path')
2
- let { lambdas } = require('../lib/pragmas')
3
- let is = require('../lib/is')
2
+ let { is, pragmas } = require('../lib')
3
+ let { lambdas } = pragmas
4
4
  let plural = arr => arr.length > 1 ? 's' : ''
5
5
 
6
6
  /**
@@ -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': tablesStreams, tables } = inventory
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 (tablesStreams) {
14
- tablesStreams.forEach(stream => check(stream.table, 'tables-streams'))
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,5 +0,0 @@
1
- module.exports = function configureMacros ({ arc }) {
2
- if (!arc.macros || !arc.macros.length) return null
3
-
4
- return arc.macros
5
- }
@@ -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
- }
@@ -1,2 +0,0 @@
1
- // Any must come last for Sandbox route sorting purposes
2
- module.exports = [ 'get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'any' ]