@live-change/cli 0.9.198 → 0.9.199

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 (2) hide show
  1. package/lib/starter.js +166 -46
  2. package/package.json +9 -8
package/lib/starter.js CHANGED
@@ -6,6 +6,7 @@ import path from 'path'
6
6
  import http from 'http'
7
7
  import fs from 'fs'
8
8
  import yargs from 'yargs'
9
+ import YAML from 'yaml'
9
10
 
10
11
  import { createProxyMiddleware } from 'http-proxy-middleware'
11
12
  import { readFile } from 'fs/promises'
@@ -364,9 +365,42 @@ export default function starter(servicesConfig = null, args = {}, extraArgs = {}
364
365
  default: '*'
365
366
  })
366
367
  yargs.option('json', {
367
- describe: 'print json',
368
+ describe: 'print json (deprecated, use --output json)',
368
369
  type: 'boolean'
369
370
  })
371
+ yargs.option('output', {
372
+ describe: 'output format: text | json | yaml',
373
+ type: 'string',
374
+ choices: ['text', 'json', 'yaml']
375
+ })
376
+ yargs.option('model', {
377
+ describe: 'filter by model name',
378
+ type: 'string'
379
+ })
380
+ yargs.option('index', {
381
+ describe: 'filter by index name',
382
+ type: 'string'
383
+ })
384
+ yargs.option('action', {
385
+ describe: 'filter by action name',
386
+ type: 'string'
387
+ })
388
+ yargs.option('view', {
389
+ describe: 'filter by view name',
390
+ type: 'string'
391
+ })
392
+ yargs.option('trigger', {
393
+ describe: 'filter by trigger name',
394
+ type: 'string'
395
+ })
396
+ yargs.option('event', {
397
+ describe: 'filter by event name',
398
+ type: 'string'
399
+ })
400
+ yargs.option('query', {
401
+ describe: 'filter by query name',
402
+ type: 'string'
403
+ })
370
404
  }, async (argv) => {
371
405
  await setupTelemetry(argv, servicesConfig)
372
406
  await describe(argv)
@@ -478,62 +512,148 @@ export async function describe(argv) {
478
512
  const services = new Services(argv.services)
479
513
  await services.loadServices()
480
514
  await services.processDefinitions()
481
- function describeService(service) {
482
- console.log("Service", service.name)
483
- if(argv.json) {
484
- console.log(JSON.stringify(service.toJSON(), null, " "))
485
- return
515
+
516
+ const output = argv.output || (argv.json ? 'json' : 'text')
517
+ const hasFilters =
518
+ argv.model || argv.index || argv.action ||
519
+ argv.view || argv.trigger || argv.event || argv.query
520
+
521
+ function buildFilteredDescription(service) {
522
+ const json = service.toJSON ? service.toJSON() : service
523
+ const result = {
524
+ service: service.name
525
+ }
526
+
527
+ if(argv.model) {
528
+ const model = json.models && json.models[argv.model]
529
+ result.model = model ? { [argv.model]: model } : null
486
530
  }
487
- if(Object.keys(service.models).length > 0) console.log(" models:")
488
- for(const modelName in service.models) {
489
- const model = service.models[modelName]
490
- const properties = Object.keys(model.properties ?? {})
491
- console.log(" ", modelName, "(", properties.join(', '), ")")
492
- for(const indexName in model.indexes) {
493
- const index = model.indexes[indexName]
494
- console.log(" ", indexName)
531
+
532
+ if(argv.index) {
533
+ const globalIndex = json.indexes && json.indexes[argv.index]
534
+ let modelIndex = null
535
+ if(json.models) {
536
+ for(const modelName in json.models) {
537
+ const model = json.models[modelName]
538
+ if(model.indexes && model.indexes[argv.index]) {
539
+ modelIndex = {
540
+ model: modelName,
541
+ index: model.indexes[argv.index]
542
+ }
543
+ break
544
+ }
545
+ }
546
+ }
547
+ result.index = {
548
+ global: globalIndex || null,
549
+ model: modelIndex
495
550
  }
496
551
  }
497
- if(Object.keys(service.indexes).length > 0) console.log(" indexes:")
498
- for(const indexName in service.indexes) {
499
- const index = service.indexes[indexName]
500
- console.log(" ", indexName)
552
+
553
+ if(argv.action) {
554
+ const action = json.actions && json.actions[argv.action]
555
+ result.action = action ? { [argv.action]: action } : null
501
556
  }
502
- if(Object.keys(service.actions).length > 0) console.log(" actions:")
503
- for(const actionName in service.actions) {
504
- const action = service.actions[actionName]
505
- const properties = Object.keys(action.properties ?? {})
506
- console.log(" ", actionName, "(", properties.join(', '), ")")
557
+
558
+ if(argv.view) {
559
+ const view = json.views && json.views[argv.view]
560
+ result.view = view ? { [argv.view]: view } : null
507
561
  }
508
- if(Object.keys(service.views).length > 0) console.log(" views:")
509
- for(const viewName in service.views) {
510
- const view = service.views[viewName]
511
- const properties = Object.keys(view.properties ?? {})
512
- console.log(" ", viewName, "(", properties.join(', '), ")",
513
- view.global ? "global" : "", view.internal ? "internal" : "", view.remote ? "remote" : "")
562
+
563
+ if(argv.trigger) {
564
+ const trigger = json.triggers && json.triggers[argv.trigger]
565
+ result.trigger = trigger ? { [argv.trigger]: trigger } : null
514
566
  }
515
- if(Object.keys(service.triggers).length > 0) console.log(" triggers:")
516
- for(const triggerName in service.triggers) {
517
- const triggers = service.triggers[triggerName]
518
- for(const trigger of triggers) {
519
- const properties = Object.keys(trigger.properties ?? {})
520
- console.log(" ", triggerName, "(", properties.join(', '), ")")
521
- }
567
+
568
+ if(argv.event) {
569
+ const event = json.events && json.events[argv.event]
570
+ result.event = event ? { [argv.event]: event } : null
571
+ }
572
+
573
+ if(argv.query) {
574
+ const query = json.queries && json.queries[argv.query]
575
+ result.query = query ? { [argv.query]: query } : null
576
+ }
577
+
578
+ return result
579
+ }
580
+
581
+ function printStructured(data) {
582
+ if(output === 'json') {
583
+ console.log(JSON.stringify(data, null, 2))
584
+ } else {
585
+ console.log(YAML.stringify(JSON.parse(JSON.stringify(data))))
522
586
  }
523
- if(Object.keys(service.events).length > 0) console.log(" events:")
524
- for(const eventName in service.events) {
525
- const event = service.events[eventName]
526
- const properties = Object.keys(event.properties ?? {})
527
- console.log(" ", eventName, "(", properties.join(', '), ")")
587
+ }
588
+
589
+ function describeService(service) {
590
+ if(output === 'text' && !hasFilters) {
591
+ console.log("Service", service.name)
592
+ if(Object.keys(service.models).length > 0) console.log(" models:")
593
+ for(const modelName in service.models) {
594
+ const model = service.models[modelName]
595
+ const properties = Object.keys(model.properties ?? {})
596
+ console.log(" ", modelName, "(", properties.join(', '), ")")
597
+ for(const indexName in model.indexes) {
598
+ const index = model.indexes[indexName]
599
+ console.log(" ", indexName)
600
+ }
601
+ }
602
+ if(Object.keys(service.indexes).length > 0) console.log(" indexes:")
603
+ for(const indexName in service.indexes) {
604
+ const index = service.indexes[indexName]
605
+ console.log(" ", indexName)
606
+ }
607
+ if(Object.keys(service.actions).length > 0) console.log(" actions:")
608
+ for(const actionName in service.actions) {
609
+ const action = service.actions[actionName]
610
+ const properties = Object.keys(action.properties ?? {})
611
+ console.log(" ", actionName, "(", properties.join(', '), ")")
612
+ }
613
+ if(Object.keys(service.views).length > 0) console.log(" views:")
614
+ for(const viewName in service.views) {
615
+ const view = service.views[viewName]
616
+ const properties = Object.keys(view.properties ?? {})
617
+ console.log(" ", viewName, "(", properties.join(', '), ")",
618
+ view.global ? "global" : "", view.internal ? "internal" : "", view.remote ? "remote" : "")
619
+ }
620
+ if(Object.keys(service.triggers).length > 0) console.log(" triggers:")
621
+ for(const triggerName in service.triggers) {
622
+ const triggers = service.triggers[triggerName]
623
+ for(const trigger of triggers) {
624
+ const properties = Object.keys(trigger.properties ?? {})
625
+ console.log(" ", triggerName, "(", properties.join(', '), ")")
626
+ }
627
+ }
628
+ if(Object.keys(service.events).length > 0) console.log(" events:")
629
+ for(const eventName in service.events) {
630
+ const event = service.events[eventName]
631
+ const properties = Object.keys(event.properties ?? {})
632
+ console.log(" ", eventName, "(", properties.join(', '), ")")
633
+ }
634
+ if(Object.keys(service.queries).length > 0) console.log(" queries:")
635
+ for(const queryName in service.queries) {
636
+ const query = service.queries[queryName]
637
+ const properties = Object.keys(query.properties ?? {})
638
+ console.log(" ", queryName, "(", properties.join(', '), ")")
639
+ }
640
+ return
528
641
  }
529
- if(Object.keys(service.queries).length > 0) console.log(" queries:")
530
- for(const queryName in service.queries) {
531
- const query = service.queries[queryName]
532
- const properties = Object.keys(query.properties ?? {})
533
- console.log(" ", queryName, "(", properties.join(', '), ")")
642
+
643
+ if(hasFilters) {
644
+ const filtered = buildFilteredDescription(service)
645
+ printStructured(filtered)
646
+ } else {
647
+ const json = service.toJSON ? service.toJSON() : service
648
+ printStructured(json)
534
649
  }
535
650
  }
651
+
536
652
  if(argv.service === '*') {
653
+ if(hasFilters) {
654
+ console.error("When using filters like --model, --action, etc. you must specify a concrete --service")
655
+ process.exit(1)
656
+ }
537
657
  for(const service of services.serviceDefinitions) {
538
658
  describeService(service)
539
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/cli",
3
- "version": "0.9.198",
3
+ "version": "0.9.199",
4
4
  "description": "Live Change Framework - command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,12 +25,12 @@
25
25
  "type": "module",
26
26
  "homepage": "https://github.com/live-change/live-change-stack",
27
27
  "dependencies": {
28
- "@live-change/dao": "^0.9.198",
29
- "@live-change/dao-sockjs": "^0.9.198",
30
- "@live-change/dao-websocket": "^0.9.198",
31
- "@live-change/db-server": "^0.9.198",
32
- "@live-change/framework": "^0.9.198",
33
- "@live-change/server": "^0.9.198",
28
+ "@live-change/dao": "^0.9.199",
29
+ "@live-change/dao-sockjs": "^0.9.199",
30
+ "@live-change/dao-websocket": "^0.9.199",
31
+ "@live-change/db-server": "^0.9.199",
32
+ "@live-change/framework": "^0.9.199",
33
+ "@live-change/server": "^0.9.199",
34
34
  "dotenv": "^17.2.1",
35
35
  "express": "^4.18.2",
36
36
  "http-proxy-middleware": "2.0.6",
@@ -38,7 +38,8 @@
38
38
  "serialize-javascript": "^6.0.2",
39
39
  "sockjs": "^0.3.24",
40
40
  "websocket": "^1.0.34",
41
+ "yaml": "^2.5.0",
41
42
  "yargs": "^17.7.2"
42
43
  },
43
- "gitHead": "7e485dcbaa2af7fb17052a40238210dc8bdf0c09"
44
+ "gitHead": "1900043a10cf9ad49b9cc33a539fb973706de962"
44
45
  }