@jinshuju/cli 0.9.0 → 0.10.0

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/README.md CHANGED
@@ -160,6 +160,8 @@ jinshuju entry aggregate --form Kp7mQ2 --metric count:field_1 --by created_at:mo
160
160
 
161
161
  jinshuju entry summary --form Kp7mQ2
162
162
  jinshuju entry summary --form Kp7mQ2 --fields field_3,field_7 --no-overview
163
+
164
+ jinshuju entry count --form Kp7mQ2 --view aB3dE9 --filter 'field_3 gte 80' # only what the view shows
163
165
  ```
164
166
 
165
167
  `--metric <func>:<field>` is repeatable, 1–20 of them; `--by <field>[:day|week|month]`
@@ -244,6 +244,17 @@ function batchRows(input) {
244
244
  throw new UsageError('--batch must be a list');
245
245
  return rows;
246
246
  }
247
+ const ANALYSIS_VIEW_OPTION = {
248
+ name: '--view',
249
+ type: 'string',
250
+ placeholder: '<view>',
251
+ description: 'Only the entries this view shows; a filter narrows them further'
252
+ };
253
+ /** Through a view, an analysis covers only the entries that view shows. */
254
+ function analysisPath(input, read) {
255
+ const view = input.options.view;
256
+ return `${containerPath(input)}${view ? `/views/${view}` : ''}/entries/${read}`;
257
+ }
247
258
  /**
248
259
  * Batch writes are served under the forms path alone, and it takes a table's
249
260
  * token just as well, so a table batches through the same URL.
@@ -336,23 +347,23 @@ export const ENTRY = [
336
347
  options: [
337
348
  ...CONTAINER_LIST_OPTIONS,
338
349
  { name: '--keyword', type: 'string', placeholder: '<kw>', description: 'Search every searchable field at once' },
350
+ ANALYSIS_VIEW_OPTION,
339
351
  FILTER_OPTION,
340
352
  FILTERS_OPTION
341
353
  ],
342
354
  request: (input) => {
343
- const { tokens, kind } = resolveContainers(input.options, MAX_COUNTED_CONTAINERS);
355
+ const { tokens } = resolveContainers(input.options, MAX_COUNTED_CONTAINERS);
344
356
  const query = { filters: filters(input), keyword: input.options.keyword };
345
- if (tokens.length === 1) {
346
- return {
347
- method: 'GET',
348
- path: `${API}/${kind === 'table' ? 'tables' : 'forms'}/${tokens[0]}/entries/count`,
349
- query
350
- };
357
+ if (tokens.length === 1)
358
+ return { method: 'GET', path: analysisPath(input, 'count'), query };
359
+ if (input.options.view !== undefined) {
360
+ throw new UsageError('--view belongs to one form or table, so it counts one container, not several');
351
361
  }
352
362
  return { method: 'GET', path: `${API}/entries/count`, query: { ...query, form_tokens: tokens.join(',') } };
353
363
  },
354
364
  examples: [
355
365
  "jinshuju entry count --form Kp7mQ2 --filter 'field_3 gte 80'",
366
+ 'jinshuju entry count --form Kp7mQ2 --view aB3dE9',
356
367
  'jinshuju entry count --form Kp7mQ2 --form Vn4xR8 --form aB3dE9'
357
368
  ]
358
369
  },
@@ -495,6 +506,7 @@ export const ENTRY = [
495
506
  placeholder: '<n>',
496
507
  description: 'How many groups, ranked by the first metric (default 20, max 200)'
497
508
  },
509
+ ANALYSIS_VIEW_OPTION,
498
510
  FILTER_OPTION,
499
511
  FILTERS_OPTION
500
512
  ],
@@ -505,7 +517,7 @@ export const ENTRY = [
505
517
  const dimensions = input.options.by ?? [];
506
518
  return {
507
519
  method: 'GET',
508
- path: `${containerPath(input)}/entries/aggregate`,
520
+ path: analysisPath(input, 'aggregate'),
509
521
  query: {
510
522
  metrics: JSON.stringify(metrics.map(parseMetric)),
511
523
  dimensions: dimensions.length > 0 ? JSON.stringify(dimensions.map(parseDimension)) : undefined,
@@ -518,6 +530,7 @@ export const ENTRY = [
518
530
  examples: [
519
531
  'jinshuju entry aggregate --form Kp7mQ2 --metric avg:field_3',
520
532
  'jinshuju entry aggregate --form Kp7mQ2 --metric count:field_1 --by created_at:month',
533
+ 'jinshuju entry aggregate --form Kp7mQ2 --view aB3dE9 --metric sum:field_5',
521
534
  "jinshuju entry aggregate --form Kp7mQ2 --metric sum:field_5 --by field_7 --limit 5 --filter 'created_at within_last 30d'"
522
535
  ]
523
536
  },
@@ -537,12 +550,13 @@ export const ENTRY = [
537
550
  description: 'Profile only these fields, at most 60'
538
551
  },
539
552
  { name: '--no-overview', type: 'boolean', description: 'Leave out the form-level totals' },
553
+ ANALYSIS_VIEW_OPTION,
540
554
  FILTER_OPTION,
541
555
  FILTERS_OPTION
542
556
  ],
543
557
  request: (input) => ({
544
558
  method: 'GET',
545
- path: `${containerPath(input)}/entries/summary`,
559
+ path: analysisPath(input, 'summary'),
546
560
  query: {
547
561
  fields: list(input.options.fields),
548
562
  include_overview: input.options.no_overview ? 'false' : undefined,
@@ -551,6 +565,7 @@ export const ENTRY = [
551
565
  }),
552
566
  examples: [
553
567
  'jinshuju entry summary --form Kp7mQ2',
568
+ 'jinshuju entry summary --form Kp7mQ2 --view aB3dE9',
554
569
  'jinshuju entry summary --form Kp7mQ2 --fields field_3,field_7 --no-overview'
555
570
  ]
556
571
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {