@architect/inventory 2.2.1 → 3.0.0-RC.3

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 (69) hide show
  1. package/changelog.md +41 -0
  2. package/package.json +8 -6
  3. package/readme.md +5 -4
  4. package/src/config/_upsert.js +1 -1
  5. package/src/config/arc.js +3 -3
  6. package/src/config/pragmas/app.js +1 -1
  7. package/src/config/pragmas/events.js +3 -2
  8. package/src/config/pragmas/http.js +5 -4
  9. package/src/config/pragmas/index.js +16 -5
  10. package/src/config/pragmas/meta/custom-lambdas.js +10 -0
  11. package/src/config/pragmas/{src-dirs.js → meta/src-dirs.js} +13 -10
  12. package/src/config/pragmas/plugins.js +104 -4
  13. package/src/config/pragmas/populate-lambda/_custom-lambdas.js +10 -0
  14. package/src/config/pragmas/populate-lambda/_events.js +17 -11
  15. package/src/config/pragmas/populate-lambda/_http.js +18 -10
  16. package/src/config/pragmas/populate-lambda/_scheduled.js +18 -10
  17. package/src/config/pragmas/populate-lambda/_tables-streams.js +20 -23
  18. package/src/config/pragmas/populate-lambda/_ws.js +26 -0
  19. package/src/config/pragmas/populate-lambda/get-handler.js +86 -13
  20. package/src/config/pragmas/populate-lambda/get-lambda.js +23 -0
  21. package/src/config/pragmas/populate-lambda/get-runtime.js +8 -7
  22. package/src/config/pragmas/populate-lambda/index.js +104 -86
  23. package/src/config/pragmas/queues.js +3 -2
  24. package/src/config/pragmas/scheduled.js +3 -2
  25. package/src/config/pragmas/shared.js +41 -44
  26. package/src/config/pragmas/sort/http.js +2 -2
  27. package/src/config/pragmas/static.js +1 -2
  28. package/src/config/pragmas/tables-indexes.js +3 -10
  29. package/src/config/pragmas/tables-streams.js +7 -5
  30. package/src/config/pragmas/tables.js +1 -1
  31. package/src/config/pragmas/validate/_events.js +1 -1
  32. package/src/config/pragmas/validate/_http.js +3 -3
  33. package/src/config/pragmas/validate/_lib.js +1 -1
  34. package/src/config/pragmas/validate/_scheduled.js +2 -2
  35. package/src/config/pragmas/validate/_shared.js +1 -1
  36. package/src/config/pragmas/validate/_tables-streams.js +6 -8
  37. package/src/config/pragmas/validate/_tables.js +2 -2
  38. package/src/config/pragmas/validate/index.js +2 -2
  39. package/src/config/pragmas/views.js +39 -37
  40. package/src/config/pragmas/ws.js +6 -4
  41. package/src/config/project/index.js +34 -18
  42. package/src/config/project/plugins/env.js +33 -0
  43. package/src/config/project/plugins/index.js +7 -0
  44. package/src/config/project/plugins/runtimes.js +56 -0
  45. package/src/config/project/prefs/dotenv.js +73 -0
  46. package/src/config/project/{prefs.js → prefs/index.js} +32 -14
  47. package/src/config/project/validate/index.js +1 -1
  48. package/src/defaults/index.js +20 -13
  49. package/src/env/index.js +76 -61
  50. package/src/get.js +1 -2
  51. package/src/index.js +17 -15
  52. package/src/lib/asap-src.js +3 -3
  53. package/src/lib/error-fmt.js +2 -10
  54. package/src/lib/get-lambda-dirs.js +37 -0
  55. package/src/lib/index.js +28 -0
  56. package/src/lib/is.js +3 -1
  57. package/src/lib/merge-env-vars.js +32 -0
  58. package/src/lib/pragmas.js +19 -3
  59. package/src/read/reader.js +1 -1
  60. package/src/validate/config.js +12 -6
  61. package/src/validate/index.js +3 -11
  62. package/src/validate/layers.js +2 -2
  63. package/src/validate/tables-children.js +5 -5
  64. package/src/config/pragmas/indexes.js +0 -19
  65. package/src/config/pragmas/macros.js +0 -5
  66. package/src/config/pragmas/populate-lambda/_plugins.js +0 -25
  67. package/src/config/pragmas/populate-lambda/_websockets.js +0 -19
  68. package/src/config/project/plugins.js +0 -31
  69. package/src/lib/http-methods.js +0 -2
package/src/env/index.js CHANGED
@@ -1,76 +1,91 @@
1
+ let { mergeEnvVars } = require('../lib')
2
+
1
3
  /**
2
4
  * Read env vars out of SSM
3
5
  */
4
6
  module.exports = function env (params, inventory, callback) {
5
- if (params.env) {
6
- /* istanbul ignore next */
7
- try {
8
- // eslint-disable-next-line
9
- var aws = require('aws-sdk')
10
- }
11
- catch (err) {
12
- let msg = `'aws-sdk' not found, please install locally or globally (see also readme#aws-sdk-caveat)`
13
- return callback(Error(msg))
14
- }
15
- let name = inventory.app
16
- let { region } = inventory.aws
17
- let ssm = new aws.SSM({ region })
18
- let result = []
19
-
20
- function getSomeEnvVars (name, NextToken, callback) {
21
- // Base query to ssm
22
- let query = {
23
- Path: `/${name}`,
24
- Recursive: true,
25
- MaxResults: 10,
26
- WithDecryption: true
27
- }
7
+ if (!params.env) {
8
+ return callback()
9
+ }
28
10
 
29
- // Check if we're paginating
30
- /* istanbul ignore if */
31
- if (NextToken) query.NextToken = NextToken
11
+ /* istanbul ignore next */
12
+ try {
13
+ // eslint-disable-next-line
14
+ var aws = require('aws-sdk')
15
+ }
16
+ catch (err) {
17
+ let msg = `'aws-sdk' not found, please install locally or globally (see also readme#aws-sdk-caveat)`
18
+ return callback(Error(msg))
19
+ }
20
+ let name = inventory.app
21
+ let { region } = inventory.aws
22
+ let ssm = new aws.SSM({ region })
23
+ let result = []
32
24
 
33
- // Perform the query
34
- ssm.getParametersByPath(query, function _query (err, data) {
35
- if (err) callback(err)
36
- else {
37
- // Tidy up the response
38
- result = result.concat(data.Parameters.map(function (param) {
39
- let bits = param.Name.split('/')
40
- return {
41
- app: name, // jic
42
- env: bits[2],
43
- name: bits[3],
44
- value: param.Value,
45
- }
46
- }))
47
- // Check for more data and, if so, recurse
48
- /* istanbul ignore if: Sadly no way to easily mock this for testing */
49
- if (data.NextToken) {
50
- getSomeEnvVars(name, data.NextToken, callback)
51
- }
52
- else callback(null, result)
53
- }
54
- })
25
+ function getSomeEnvVars (name, NextToken, callback) {
26
+ // Base query to ssm
27
+ let query = {
28
+ Path: `/${name}`,
29
+ Recursive: true,
30
+ MaxResults: 10,
31
+ WithDecryption: true
55
32
  }
56
33
 
57
- getSomeEnvVars(name, false, function done (err, result) {
34
+ // Check if we're paginating
35
+ /* istanbul ignore if */
36
+ if (NextToken) query.NextToken = NextToken
37
+
38
+ // Perform the query
39
+ ssm.getParametersByPath(query, function _query (err, data) {
58
40
  if (err) callback(err)
59
41
  else {
60
- if (result.length) {
61
- let testing = null
62
- let staging = null
63
- let production = null
64
- result.forEach(r => {
65
- if (r.env === 'testing') testing = Object.assign({}, testing, { [r.name]: r.value })
66
- if (r.env === 'staging') staging = Object.assign({}, staging, { [r.name]: r.value })
67
- if (r.env === 'production') production = Object.assign({}, production, { [r.name]: r.value })
68
- })
69
- inventory._project.env = { testing, staging, production }
42
+ // Tidy up the response
43
+ result = result.concat(data.Parameters.map(function (param) {
44
+ let bits = param.Name.split('/')
45
+ return {
46
+ app: name, // jic
47
+ env: bits[2],
48
+ name: bits[3],
49
+ value: param.Value,
50
+ }
51
+ }))
52
+ // Check for more data and, if so, recurse
53
+ /* istanbul ignore if: Sadly no way to easily mock this for testing */
54
+ if (data.NextToken) {
55
+ getSomeEnvVars(name, data.NextToken, callback)
70
56
  }
71
- callback()
57
+ else callback(null, result)
72
58
  }
73
59
  })
74
60
  }
75
- else callback()
61
+
62
+ getSomeEnvVars(name, false, function done (err, result) {
63
+ if (err) callback(err)
64
+ else {
65
+ let testing = null
66
+ let staging = null
67
+ let production = null
68
+ if (result.length) {
69
+ // TODO refactor into a reducer?
70
+ result.forEach(({ env, name: k, value: v }) => {
71
+ if (env === 'testing') testing = Object.assign({}, testing, { [k]: v })
72
+ if (env === 'staging') staging = Object.assign({}, staging, { [k]: v })
73
+ if (env === 'production') production = Object.assign({}, production, { [k]: v })
74
+ })
75
+ }
76
+
77
+ let errors = []
78
+ inventory._project.env.aws = mergeEnvVars({
79
+ env: 'Application',
80
+ source: inventory._project.env.plugins,
81
+ target: { testing, staging, production },
82
+ errors,
83
+ })
84
+ if (errors.length) {
85
+ callback(Error(errors[0]))
86
+ return
87
+ }
88
+ callback()
89
+ }
90
+ })
76
91
  }
package/src/get.js CHANGED
@@ -1,4 +1,4 @@
1
- let is = require('./lib/is')
1
+ let { is } = require('./lib')
2
2
 
3
3
  module.exports = function _get (inventory) {
4
4
  function getter (prag, name) {
@@ -38,5 +38,4 @@ module.exports = function _get (inventory) {
38
38
  // These refer to other pragmas, and thus may allow multiple same/same-named entities
39
39
  let multipleResults = [
40
40
  'tables-indexes',
41
- 'indexes',
42
41
  ]
package/src/index.js CHANGED
@@ -5,7 +5,7 @@ let config = require('./config')
5
5
  let getEnv = require('./env')
6
6
  let validate = require('./validate')
7
7
  let get = require('./get')
8
- let errorFmt = require('./lib/error-fmt')
8
+ let { errorFmt } = require('./lib')
9
9
 
10
10
  /**
11
11
  * Architect Inventory
@@ -50,10 +50,7 @@ module.exports = function architectInventory (params = {}, callback) {
50
50
 
51
51
  // Exit early if supplied Arc is fundamentally broken
52
52
  if (errors.length) {
53
- callback(errorFmt({
54
- type: 'manifest',
55
- errors,
56
- }))
53
+ callback(errorFmt({ type: 'manifest', errors }))
57
54
  return promise
58
55
  }
59
56
 
@@ -61,27 +58,32 @@ module.exports = function architectInventory (params = {}, callback) {
61
58
  let inventory = inventoryDefaults(params)
62
59
 
63
60
  // Set up project params for config
64
- let project = { cwd, arc, raw, filepath, inventory }
61
+ let project = { arc, cwd, errors, filepath, inventory, raw }
65
62
 
66
63
  // Populate inventory.arc
67
64
  inventory._arc = config._arc(project)
68
65
 
66
+ // @plugins come first, as they register hooks all around the project
67
+ inventory.plugins = config.pragmas.plugins(project)
68
+
69
69
  // Establish default function config from project + Arc defaults
70
- inventory._project = config._project(project, errors)
70
+ inventory._project = config._project(project)
71
+
72
+ // End here if plugins failed
73
+ if (errors.length) {
74
+ callback(errorFmt({ type: 'plugin', errors }))
75
+ return promise
76
+ }
71
77
 
72
- // Userland: fill out the pragmas
78
+ // Userland: fill out the pragmas, starting with @plugins
73
79
  inventory = {
74
80
  ...inventory,
75
- ...config.pragmas(project, errors)
81
+ ...config.pragmas(project)
76
82
  }
77
83
 
78
- // End here if first-pass pragma validation failed
84
+ // End here if first-pass validation failed
79
85
  if (errors.length) {
80
- callback(errorFmt({
81
- type: 'validation',
82
- errors,
83
- inventory,
84
- }))
86
+ callback(errorFmt({ type: 'validation', errors }))
85
87
  return promise
86
88
  }
87
89
 
@@ -17,7 +17,7 @@ module.exports = function asapSrc () {
17
17
  try {
18
18
  return require.resolve('@architect/asap')
19
19
  }
20
- catch (err) { /* Swallow */ }
21
-
22
- throw Error('Cannot find ASAP module!')
20
+ catch (err) {
21
+ throw Error('Cannot find ASAP module!')
22
+ }
23
23
  }
@@ -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, meta, inventory } = params
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' : ''}${meta ? meta : ''}:\n${output}`)
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
@@ -0,0 +1,28 @@
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 mergeEnvVars = require('./merge-env-vars')
6
+ let pragmas = require('./pragmas')
7
+
8
+ /**
9
+ * Why take up a whole fs block when smol libs can just live here?
10
+ */
11
+
12
+ // For setting `lambda.build`, compiled + transpiled are effectively the same
13
+ let compiledRuntimes = [ 'compiled', 'transpiled' ]
14
+
15
+ // `any` must come last for Sandbox route sorting purposes
16
+ let httpMethods = [ 'get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'any' ]
17
+
18
+ module.exports = {
19
+ asapSrc,
20
+ compiledRuntimes,
21
+ errorFmt,
22
+ getLambdaDirs,
23
+ httpMethods,
24
+ is,
25
+ mergeEnvVars,
26
+ normalizeSrc: getLambdaDirs.normalizeSrc,
27
+ pragmas,
28
+ }
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(),
@@ -0,0 +1,32 @@
1
+ let envs = [ 'testing', 'staging', 'production' ]
2
+
3
+ module.exports = function mergeEnvVars (params) {
4
+ let { name, source, target, errors } = params
5
+ if (source === null) return target
6
+ if (target === null) return source
7
+ let probs = []
8
+
9
+ // Deep copy to reset any potential refs
10
+ let merged = JSON.parse(JSON.stringify(target))
11
+ envs.forEach(env => {
12
+ if (!source[env]) return
13
+ Object.keys(source[env]).forEach(k => {
14
+ if (merged[env]?.[k]) {
15
+ probs.push(`'${env}' variable '${k}'`)
16
+ }
17
+ else {
18
+ if (!merged[env]) merged[env] = {}
19
+ merged[env][k] = source[env][k]
20
+ }
21
+ })
22
+ })
23
+
24
+ if (probs.length) {
25
+ let s = probs.length > 1 ? 's' : ''
26
+ let msg = `${name} env var${s} conflicts with plugin:\n` +
27
+ `- ${probs.join('\n- ')}`
28
+ errors.push(msg)
29
+ }
30
+
31
+ return merged
32
+ }
@@ -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' ]