onetable-cli
Advanced tools
Comparing version 1.1.0 to 1.2.0
165
dist/cli.js
@@ -7,4 +7,3 @@ #!/usr/bin/env node | ||
Migrations: | ||
onetable migrate [all, down, list, outstanding, repeat, reset, status, up, N.N.N] | ||
onetable generate [migration] | ||
onetable [all, down, generate, list, outstanding, repeat, reset, status, up, N.N.N] | ||
@@ -21,3 +20,2 @@ Reads migrate.json: | ||
nulls: false, | ||
schema: 'path/to/schema.js', | ||
typeField: 'type', | ||
@@ -32,5 +30,6 @@ aws: {accessKeyId, secretAccessKey, region}, | ||
import AWS from 'aws-sdk'; | ||
import { Table } from 'dynamodb-onetable'; | ||
import { Migrate } from 'onetable-migrate'; | ||
// import {Migrate} from './onetable-migrate/dist/mjs/index.js' | ||
// DEV | ||
// import {Table} from '../../onetable/dist/mjs/index.js' | ||
// import {Migrate} from '../../onetable-migrate/dist/mjs/index.js' | ||
import Blend from 'js-blend'; | ||
@@ -40,2 +39,3 @@ import Dates from 'js-dates'; | ||
import SenseLogs from 'senselogs'; | ||
// import SenseLogs from '../../senselogs/dist/mjs/index.js' | ||
const MigrationTemplate = ` | ||
@@ -61,18 +61,13 @@ export default { | ||
onetable migrate ... | ||
onetable generate ... | ||
Generate: | ||
onetable generate migration # Generate a stub migration file | ||
Migrations: | ||
onetable migrate 1.2.3 # Apply migrations up or down to version 1.2.3 | ||
onetable migrate all # Apply all outstanding migrations (upwards) | ||
onetable migrate down # Rervert the last applied migration | ||
onetable migrate list # List all applied migrations | ||
onetable migrate outstanding # List migrations yet to be applied | ||
onetable migrate repeat # Repeat the last migration | ||
onetable migrate reset # Reset the database with latest migration | ||
onetable migrate status # Show most recently applied migration | ||
onetable migrate up # Apply the next migration | ||
onetable 1.2.3 # Apply migrations up or down to version 1.2.3 | ||
onetable all # Apply all outstanding migrations (upwards) | ||
onetable down # Rervert the last applied migration | ||
onetable generate # Generate a stub migration file | ||
onetable list # List all applied migrations | ||
onetable outstanding # List migrations yet to be applied | ||
onetable repeat # Repeat the last migration | ||
onetable reset # Reset the database with latest migration | ||
onetable status # Show most recently applied migration | ||
onetable up # Apply the next migration | ||
@@ -93,3 +88,2 @@ Options: | ||
--quiet # Run as quietly as possible | ||
--schema ./path/to/schema.js # Database schema module | ||
--version # Emit version number | ||
@@ -116,20 +110,20 @@ `; | ||
this.debug(`Using configuration profile "${config.profile}"`); | ||
this.log = new SenseLogs({ name: 'onetable', destination: 'console' }); | ||
this.log = new SenseLogs({ name: 'onetable', destination: 'console', format: 'human' }); | ||
/* | ||
OneTable expects the crypto to be defined under a "primary" property. | ||
*/ | ||
let cot = config.onetable; | ||
let crypto = this.crypto || cot.crypto || config.crypto; | ||
let onetable = config.onetable; | ||
let crypto = this.crypto || onetable.crypto || config.crypto; | ||
if (crypto) { | ||
cot.crypto = crypto.primary ? crypto : { primary: crypto }; | ||
onetable.crypto = crypto.primary ? crypto : { primary: crypto }; | ||
} | ||
cot.schema = await this.readSchema(cot.schema); | ||
let location; | ||
if (cot.arn) { | ||
this.verbose(`Accessing DynamoDb "${cot.name}" via proxy at ${cot.arn}`); | ||
this.migrate = new Proxy(config, this); | ||
location = cot.arn; | ||
if (config.arn) { | ||
this.verbose(`Accessing DynamoDb "${onetable.name}" via proxy at ${config.arn}`); | ||
this.migrate = new Proxy(config.onetable, config.arn, config.aws, this); | ||
location = config.arn; | ||
} | ||
else { | ||
let endpoint = this.endpoint || cot.endpoint || cot.aws.endpoint || process.env.DB_ENDPOINT; | ||
let endpoint = this.endpoint || config.endpoint || | ||
config.aws.endpoint || process.env.DB_ENDPOINT; | ||
let args; | ||
@@ -142,3 +136,3 @@ if (endpoint) { | ||
else { | ||
args = cot.aws; | ||
args = config.aws; | ||
if (!args || Object.keys(args).length == 0) { | ||
@@ -151,6 +145,5 @@ location = process.env.AWS_PROFILE; | ||
} | ||
this.verbose(`Accessing DynamoDb "${cot.name}" at "${location}"`); | ||
cot.client = new AWS.DynamoDB.DocumentClient(args); | ||
cot.senselogs = this.log; | ||
let onetable = new Table(cot); | ||
this.verbose(`Accessing DynamoDb "${onetable.name}" at "${location}"`); | ||
onetable.client = new AWS.DynamoDB.DocumentClient(args); | ||
onetable.senselogs = this.log; | ||
this.migrate = new Migrate(onetable, { | ||
@@ -166,27 +159,5 @@ migrations: config.migrations, | ||
catch (err) { | ||
error(`Cannot communicate with DynamoDB "${cot.name}" at "${location}"\n` + err.message); | ||
error(`Cannot communicate with DynamoDB "${onetable.name}" at "${location}"\n` + err.message); | ||
} | ||
} | ||
async readSchema(path) { | ||
path = Path.resolve(process.cwd(), this.schema || path || './schema.json'); | ||
if (!Fs.existsSync(path)) { | ||
error(`Cannot find schema definition in "${path}"`); | ||
} | ||
this.debug(`Importing schema from "${path}"`); | ||
try { | ||
let imported = await import('file:///' + path); | ||
let schema = imported.Schema || imported.default; | ||
for (let [name, model] of Object.entries(schema.models)) { | ||
for (let [key, field] of Object.entries(model)) { | ||
if (field.validate) { | ||
field.validate = field.validate.toString(); | ||
} | ||
} | ||
} | ||
return schema; | ||
} | ||
catch (err) { | ||
error(`Cannot load schema ${path}`, err); | ||
} | ||
} | ||
async command() { | ||
@@ -196,9 +167,8 @@ let args = this.args; | ||
let cmd = args[1]; | ||
if (scope != 'migrate' && scope != 'generate') { | ||
cmd = scope; | ||
scope = 'migrate'; | ||
} | ||
if (scope == 'generate') { | ||
if (cmd == 'migration') { | ||
await this.generateMigration(); | ||
} | ||
else { | ||
this.usage(); | ||
} | ||
await this.generateMigration(); | ||
} | ||
@@ -222,3 +192,3 @@ else if (scope == 'migrate') { | ||
else if (args.length) { | ||
await this.move(args[1]); | ||
await this.move(cmd); | ||
} | ||
@@ -248,11 +218,2 @@ else { | ||
} | ||
getIndexed() { | ||
let schema = this.config.onetable.schema; | ||
let indexed = {}; | ||
for (let index of Object.values(schema.indexes)) { | ||
indexed[index.hash] = true; | ||
indexed[index.sort] = true; | ||
} | ||
return indexed; | ||
} | ||
async status() { | ||
@@ -273,7 +234,7 @@ print(await this.migrate.getCurrentVersion()); | ||
else { | ||
print('Date Version Description'); | ||
print('Date Version Description'); | ||
} | ||
for (let m of pastMigrations) { | ||
let date = Dates.format(m.time, 'HH:MM:ss mmm d, yyyy'); | ||
print(`${date} ${m.version} ${m.description}`); | ||
print(`${date} ${m.version.padStart(7)} ${m.description}`); | ||
} | ||
@@ -372,2 +333,3 @@ } | ||
catch (err) { | ||
console.log(err); | ||
error('Migration failed', err.message, err.details); | ||
@@ -468,5 +430,2 @@ } | ||
} | ||
else if (arg == '--schema' || arg == '-s') { | ||
this.schema = argv[++i]; | ||
} | ||
else if (arg == '--verbose' || arg == '-v') { | ||
@@ -501,17 +460,14 @@ this.verbosity = true; | ||
} | ||
let config = await File.readJson(migrateConfig); | ||
profile = profile || config.profile || process.env.PROFILE; | ||
if (profile && config.profiles) { | ||
Blend(config, config.profiles[profile]); | ||
delete config.profiles; | ||
let cfg = await File.readJson(migrateConfig); | ||
profile = profile || cfg.profile || process.env.PROFILE; | ||
if (profile && cfg.profiles) { | ||
Blend(cfg, cfg.profiles[profile]); | ||
delete cfg.profiles; | ||
} | ||
if (!config.onetable) { | ||
config = { onetable: config }; | ||
} | ||
if (config.onetable.config) { | ||
for (let path of config.onetable.config) { | ||
if (cfg.config) { | ||
for (let path of cfg.config) { | ||
if (Fs.existsSync(path)) { | ||
this.debug(`Loading ${path}`); | ||
let data = await File.readJson(path); | ||
config = Blend(config, data); | ||
cfg = Blend(cfg, data); | ||
} | ||
@@ -523,12 +479,13 @@ else { | ||
} | ||
if (profile && config.profiles) { | ||
Blend(config, config.profiles[profile]); | ||
delete config.profiles; | ||
delete cfg.config; | ||
if (profile && cfg.profiles) { | ||
Blend(cfg, cfg.profiles[profile]); | ||
delete cfg.profiles; | ||
} | ||
if (profile) { | ||
config.profile = profile; | ||
cfg.profile = profile; | ||
} | ||
this.profile = config.profile; | ||
config.onetable.aws = config.onetable.aws || this.aws || {}; | ||
return config; | ||
this.profile = cfg.profile; | ||
cfg.aws = cfg.aws || this.aws || {}; | ||
return cfg; | ||
} | ||
@@ -553,8 +510,7 @@ verbose(...args) { | ||
class Proxy { | ||
constructor(config, cli) { | ||
constructor(config, arn, aws, cli) { | ||
this.cli = cli; | ||
this.arn = arn; | ||
this.config = config; | ||
this.cli = cli; | ||
let args = config.onetable.aws; | ||
this.arn = config.onetable.arn; | ||
this.lambda = new AWS.Lambda(args); | ||
this.lambda = new AWS.Lambda(aws); | ||
} | ||
@@ -574,3 +530,3 @@ async apply(direction, version) { | ||
async invoke(action, args) { | ||
let params = { action }; | ||
let params = { action, config: this.config }; | ||
if (args) { | ||
@@ -616,3 +572,2 @@ params.args = args; | ||
catch (err) { | ||
print(err); | ||
error(err.message); | ||
@@ -619,0 +574,0 @@ throw err; |
{ | ||
"name": "onetable-cli", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"type": "module", | ||
@@ -56,3 +56,3 @@ "description": "DynamoDB OneTable CLI", | ||
"semver": "^6.3.0", | ||
"senselogs": "^0.8.1" | ||
"senselogs": "^0" | ||
}, | ||
@@ -59,0 +59,0 @@ "files": [ |
@@ -50,33 +50,18 @@ # OneTable Migrate CLI | ||
{ | ||
name: 'your-dynamo-table', | ||
schema: 'schema.mjs', | ||
onetable: { | ||
name: 'your-dynamo-table', | ||
// Other onetable configuration parameters. | ||
} | ||
} | ||
``` | ||
Set the `name` property to the name of your DynamoDB table. Set the `schema` property to point to your OneTable schema in a `.mjs` JavaScript file. (yes the extension is mjs). | ||
Set the `name` property to the name of your DynamoDB table. | ||
The schema file should use `export default` to export the schema. In this manner, the same schema file can be used for your DynamoDB access layer and for the OneTable CLI. For example: | ||
``` | ||
export default { | ||
indexes: { | ||
primary: { hash: 'pk', sort: 'sk' }, | ||
}, | ||
models: { | ||
user: { | ||
pk: { type: String, value: 'user:${email}' }, | ||
sk: { type: String, value: 'user:' }, | ||
email: { type: String }, | ||
} | ||
} | ||
} | ||
``` | ||
If you need to have your migrations in a different directory, you can set the migrate.json `dir` property to point to the directory containing the migrations themselves. | ||
Your configuration should match your OneTable configuration with respect to the OneTable `crypto`, `delimiter`, `nulls` and `typeField` settings. If you have these set to non-default settings, add them to your migrate.json to match. | ||
You pass your OneTable configuration via the `onetable` collection. Ensure your `crypto`, `delimiter`, `nulls` and `typeField` settings match your deployed code. If you have these set to non-default settings in your code, add them to your migrate.json `onetable` map to match. | ||
Generate a stub migration | ||
Migrations are Javascript files that export the methods `up` and `down` to apply the migration and a `description` property. | ||
Migrations are Javascript files that export the methods `up` and `down` to apply the migration and a `description` property. The migration must nominate a version and provide the OneTable schema that applies for the table data at this version level. | ||
@@ -89,2 +74,3 @@ ```sh | ||
This will create a `0.0.1.js` migration that contains the following. Edit the `up` and `down` methods and description to suit. | ||
The `db` property is the OneTable `Table` instance. This `migrate` property is an instance of the CLI Migrate class. | ||
@@ -94,3 +80,5 @@ | ||
export default { | ||
version: '0.0.1', | ||
description: 'Purpose of this migration', | ||
schema: Schema, | ||
async up(db, migrate) { | ||
@@ -110,3 +98,3 @@ // await db.create('Model', {}) | ||
```sh | ||
onetable migrate up | ||
onetable up | ||
``` | ||
@@ -117,3 +105,3 @@ | ||
```sh | ||
onetable migrate down | ||
onetable down | ||
``` | ||
@@ -124,3 +112,3 @@ | ||
```sh | ||
onetable migrate repeat | ||
onetable repeat | ||
``` | ||
@@ -131,3 +119,3 @@ | ||
```sh | ||
onetable migrate 0.1.3 | ||
onetable 0.1.3 | ||
``` | ||
@@ -138,3 +126,3 @@ | ||
```sh | ||
onetable migrate all | ||
onetable all | ||
``` | ||
@@ -145,3 +133,3 @@ | ||
```sh | ||
onetable migrate status | ||
onetable status | ||
``` | ||
@@ -152,3 +140,3 @@ | ||
```sh | ||
onetable migrate list | ||
onetable list | ||
``` | ||
@@ -159,3 +147,3 @@ | ||
```sh | ||
onetable migrate outstanding | ||
onetable outstanding | ||
``` | ||
@@ -166,3 +154,3 @@ | ||
```sh | ||
onetable migrate reset | ||
onetable reset | ||
``` | ||
@@ -173,3 +161,3 @@ | ||
```sh | ||
onetable migrate --bump 2.4.3 generate | ||
onetable --bump 2.4.3 generate | ||
``` | ||
@@ -180,3 +168,3 @@ | ||
```sh | ||
onetable migrate --dry up | ||
onetable --dry up | ||
``` | ||
@@ -199,7 +187,5 @@ | ||
--quiet # Run as quietly as possible | ||
--schema ./path/to/schema.js # Database schema module | ||
--version # Emit version number | ||
``` | ||
### Accessing AWS | ||
@@ -217,3 +203,3 @@ | ||
``` | ||
onetable migrate --aws-access-key key --aws-secret-key secret --aws-region us-east-1 | ||
onetable --aws-access-key key --aws-secret-key secret --aws-region us-east-1 | ||
``` | ||
@@ -282,6 +268,9 @@ | ||
Sample latest.js migration | ||
Sample latest.js migration: | ||
```javascript | ||
export default { | ||
version: '0.0.1', | ||
description: 'Database reset to latest version', | ||
schema: Schema, | ||
async up(db, migrate) { | ||
@@ -309,2 +298,32 @@ if (migrate.params.profile == 'dev') { | ||
### Profiles | ||
You can use profiles in your `migrate.json` to have specific configuration for different build profiles. | ||
Profiles are implemented by copying the properties from the relevant `profile.NAME` collection to the top level. For example: | ||
Here is a sample migrate.json with profiles: | ||
```javascript | ||
{ | ||
profiles: { | ||
dev: { | ||
dir: './migrations', | ||
name: 'sensedb', | ||
endpoint: 'http://localhost:8000' | ||
}, | ||
qa: { | ||
name: 'sensedb', | ||
arn: 'arn:aws:lambda:us-east-1:xxxx:function:migrate-qa-invoke' | ||
}, | ||
prod: { | ||
name: 'sensedb', | ||
arn: 'arn:aws:lambda:us-east-1:xxxx:function:migrate-prod-invoke' | ||
} | ||
} | ||
} | ||
``` | ||
If the profile is set to 'dev', the dev profile properties of `dir`, `name`, and `endpoint` are copied to the root level. | ||
### References | ||
@@ -311,0 +330,0 @@ |
166
src/cli.js
@@ -7,4 +7,3 @@ #!/usr/bin/env node | ||
Migrations: | ||
onetable migrate [all, down, list, outstanding, repeat, reset, status, up, N.N.N] | ||
onetable generate [migration] | ||
onetable [all, down, generate, list, outstanding, repeat, reset, status, up, N.N.N] | ||
@@ -21,3 +20,2 @@ Reads migrate.json: | ||
nulls: false, | ||
schema: 'path/to/schema.js', | ||
typeField: 'type', | ||
@@ -36,4 +34,7 @@ aws: {accessKeyId, secretAccessKey, region}, | ||
import {Migrate} from 'onetable-migrate' | ||
// import {Migrate} from './onetable-migrate/dist/mjs/index.js' | ||
// DEV | ||
// import {Table} from '../../onetable/dist/mjs/index.js' | ||
// import {Migrate} from '../../onetable-migrate/dist/mjs/index.js' | ||
import Blend from 'js-blend' | ||
@@ -44,2 +45,4 @@ import Dates from 'js-dates' | ||
// import SenseLogs from '../../senselogs/dist/mjs/index.js' | ||
const MigrationTemplate = ` | ||
@@ -67,18 +70,13 @@ export default { | ||
onetable migrate ... | ||
onetable generate ... | ||
Generate: | ||
onetable generate migration # Generate a stub migration file | ||
Migrations: | ||
onetable migrate 1.2.3 # Apply migrations up or down to version 1.2.3 | ||
onetable migrate all # Apply all outstanding migrations (upwards) | ||
onetable migrate down # Rervert the last applied migration | ||
onetable migrate list # List all applied migrations | ||
onetable migrate outstanding # List migrations yet to be applied | ||
onetable migrate repeat # Repeat the last migration | ||
onetable migrate reset # Reset the database with latest migration | ||
onetable migrate status # Show most recently applied migration | ||
onetable migrate up # Apply the next migration | ||
onetable 1.2.3 # Apply migrations up or down to version 1.2.3 | ||
onetable all # Apply all outstanding migrations (upwards) | ||
onetable down # Rervert the last applied migration | ||
onetable generate # Generate a stub migration file | ||
onetable list # List all applied migrations | ||
onetable outstanding # List migrations yet to be applied | ||
onetable repeat # Repeat the last migration | ||
onetable reset # Reset the database with latest migration | ||
onetable status # Show most recently applied migration | ||
onetable up # Apply the next migration | ||
@@ -99,3 +97,2 @@ Options: | ||
--quiet # Run as quietly as possible | ||
--schema ./path/to/schema.js # Database schema module | ||
--version # Emit version number | ||
@@ -127,3 +124,3 @@ ` | ||
this.log = new SenseLogs({name: 'onetable', destination: 'console'}) | ||
this.log = new SenseLogs({name: 'onetable', destination: 'console', format: 'human'}) | ||
@@ -133,17 +130,17 @@ /* | ||
*/ | ||
let cot = config.onetable | ||
let crypto = this.crypto || cot.crypto || config.crypto | ||
let onetable = config.onetable | ||
let crypto = this.crypto || onetable.crypto || config.crypto | ||
if (crypto) { | ||
cot.crypto = crypto.primary ? crypto : {primary: crypto} | ||
onetable.crypto = crypto.primary ? crypto : {primary: crypto} | ||
} | ||
cot.schema = await this.readSchema(cot.schema) | ||
let location | ||
if (cot.arn) { | ||
this.verbose(`Accessing DynamoDb "${cot.name}" via proxy at ${cot.arn}`) | ||
this.migrate = new Proxy(config, this) | ||
location = cot.arn | ||
if (config.arn) { | ||
this.verbose(`Accessing DynamoDb "${onetable.name}" via proxy at ${config.arn}`) | ||
this.migrate = new Proxy(config.onetable, config.arn, config.aws, this) | ||
location = config.arn | ||
} else { | ||
let endpoint = this.endpoint || cot.endpoint || cot.aws.endpoint || process.env.DB_ENDPOINT | ||
let endpoint = this.endpoint || config.endpoint || | ||
config.aws.endpoint || process.env.DB_ENDPOINT | ||
let args | ||
@@ -155,3 +152,3 @@ if (endpoint) { | ||
} else { | ||
args = cot.aws | ||
args = config.aws | ||
if (!args || Object.keys(args).length == 0) { | ||
@@ -163,7 +160,6 @@ location = process.env.AWS_PROFILE | ||
} | ||
this.verbose(`Accessing DynamoDb "${cot.name}" at "${location}"`) | ||
cot.client = new AWS.DynamoDB.DocumentClient(args) | ||
cot.senselogs = this.log | ||
this.verbose(`Accessing DynamoDb "${onetable.name}" at "${location}"`) | ||
onetable.client = new AWS.DynamoDB.DocumentClient(args) | ||
onetable.senselogs = this.log | ||
let onetable = new Table(cot) | ||
this.migrate = new Migrate(onetable, { | ||
@@ -178,28 +174,6 @@ migrations: config.migrations, | ||
} catch (err) { | ||
error(`Cannot communicate with DynamoDB "${cot.name}" at "${location}"\n` + err.message) | ||
error(`Cannot communicate with DynamoDB "${onetable.name}" at "${location}"\n` + err.message) | ||
} | ||
} | ||
async readSchema(path) { | ||
path = Path.resolve(process.cwd(), this.schema || path || './schema.json') | ||
if (!Fs.existsSync(path)) { | ||
error(`Cannot find schema definition in "${path}"`) | ||
} | ||
this.debug(`Importing schema from "${path}"`) | ||
try { | ||
let imported = await import('file:///' + path) | ||
let schema = imported.Schema || imported.default | ||
for (let [name, model] of Object.entries(schema.models)) { | ||
for (let [key, field] of Object.entries(model)) { | ||
if (field.validate) { | ||
field.validate = field.validate.toString() | ||
} | ||
} | ||
} | ||
return schema | ||
} catch (err) { | ||
error(`Cannot load schema ${path}`, err) | ||
} | ||
} | ||
async command() { | ||
@@ -209,8 +183,9 @@ let args = this.args | ||
let cmd = args[1] | ||
if (scope != 'migrate' && scope != 'generate') { | ||
cmd = scope | ||
scope = 'migrate' | ||
} | ||
if (scope == 'generate') { | ||
if (cmd == 'migration') { | ||
await this.generateMigration() | ||
} else { | ||
this.usage() | ||
} | ||
await this.generateMigration() | ||
} else if (scope == 'migrate') { | ||
@@ -228,3 +203,3 @@ if (cmd == 'all') { | ||
} else if (args.length) { | ||
await this.move(args[1]) | ||
await this.move(cmd) | ||
} else { | ||
@@ -253,12 +228,2 @@ this.usage() | ||
getIndexed() { | ||
let schema = this.config.onetable.schema | ||
let indexed = {} | ||
for (let index of Object.values(schema.indexes)) { | ||
indexed[index.hash] = true | ||
indexed[index.sort] = true | ||
} | ||
return indexed | ||
} | ||
async status() { | ||
@@ -278,7 +243,7 @@ print(await this.migrate.getCurrentVersion()) | ||
} else { | ||
print('Date Version Description') | ||
print('Date Version Description') | ||
} | ||
for (let m of pastMigrations) { | ||
let date = Dates.format(m.time, 'HH:MM:ss mmm d, yyyy') | ||
print(`${date} ${m.version} ${m.description}`) | ||
print(`${date} ${m.version.padStart(7)} ${m.description}`) | ||
} | ||
@@ -379,2 +344,3 @@ } | ||
} catch (err) { | ||
console.log(err) | ||
error('Migration failed', err.message, err.details) | ||
@@ -463,4 +429,2 @@ } | ||
this.quiet = true | ||
} else if (arg == '--schema' || arg == '-s') { | ||
this.schema = argv[++i] | ||
} else if (arg == '--verbose' || arg == '-v') { | ||
@@ -493,19 +457,16 @@ this.verbosity = true | ||
} | ||
let config = await File.readJson(migrateConfig) | ||
let cfg = await File.readJson(migrateConfig) | ||
profile = profile || config.profile || process.env.PROFILE | ||
profile = profile || cfg.profile || process.env.PROFILE | ||
if (profile && config.profiles) { | ||
Blend(config, config.profiles[profile]) | ||
delete config.profiles | ||
if (profile && cfg.profiles) { | ||
Blend(cfg, cfg.profiles[profile]) | ||
delete cfg.profiles | ||
} | ||
if (!config.onetable) { | ||
config = {onetable: config} | ||
} | ||
if (config.onetable.config) { | ||
for (let path of config.onetable.config) { | ||
if (cfg.config) { | ||
for (let path of cfg.config) { | ||
if (Fs.existsSync(path)) { | ||
this.debug(`Loading ${path}`) | ||
let data = await File.readJson(path) | ||
config = Blend(config, data) | ||
cfg = Blend(cfg, data) | ||
} else { | ||
@@ -516,12 +477,13 @@ error(`Cannot read ${path}`) | ||
} | ||
if (profile && config.profiles) { | ||
Blend(config, config.profiles[profile]) | ||
delete config.profiles | ||
delete cfg.config | ||
if (profile && cfg.profiles) { | ||
Blend(cfg, cfg.profiles[profile]) | ||
delete cfg.profiles | ||
} | ||
if (profile) { | ||
config.profile = profile | ||
cfg.profile = profile | ||
} | ||
this.profile = config.profile | ||
config.onetable.aws = config.onetable.aws || this.aws || {} | ||
return config | ||
this.profile = cfg.profile | ||
cfg.aws = cfg.aws || this.aws || {} | ||
return cfg | ||
} | ||
@@ -550,8 +512,7 @@ | ||
class Proxy { | ||
constructor(config, cli) { | ||
constructor(config, arn, aws, cli) { | ||
this.cli = cli | ||
this.arn = arn | ||
this.config = config | ||
this.cli = cli | ||
let args = config.onetable.aws | ||
this.arn = config.onetable.arn | ||
this.lambda = new AWS.Lambda(args) | ||
this.lambda = new AWS.Lambda(aws) | ||
} | ||
@@ -576,3 +537,3 @@ | ||
async invoke(action, args) { | ||
let params = {action} | ||
let params = {action, config: this.config} | ||
if (args) { | ||
@@ -620,3 +581,2 @@ params.args = args | ||
} catch (err) { | ||
print(err) | ||
error(err.message) | ||
@@ -623,0 +583,0 @@ throw err |
332
77953
1609
+ Addedsenselogs@0.10.0(transitive)
- Removedsenselogs@0.8.4(transitive)
Updatedsenselogs@^0