@jinshuju/cli 0.9.0 → 0.11.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]`
@@ -285,7 +287,7 @@ needs the `submit_entries` scope for these.
285
287
 
286
288
  ## Working with files
287
289
 
288
- Four commands take a file. The CLI uploads with its own credential; there is no
290
+ Five commands take a file. The CLI uploads with its own credential; there is no
289
291
  ticket to fetch first.
290
292
 
291
293
  ```bash
@@ -295,6 +297,7 @@ jinshuju entry import --table Vn4xR8 ./rows.csv --map field_1=1 --map field_2=2
295
297
  jinshuju entry create --form Kp7mQ2 --json '{"field_1":"Alice"}' --attach field_5=./id-card.jpg
296
298
  jinshuju form theme set Kp7mQ2 --wallpaper ./bg.png
297
299
  jinshuju opensearch edit Qy7nR3 --header ./banner.png
300
+ jinshuju form image upload ./venue-map.png # answers with a url for an <img> in a form or field description
298
301
  ```
299
302
 
300
303
  ```bash
@@ -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
  },
@@ -1,7 +1,7 @@
1
1
  import { FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, MINE_OPTION, PAGINATION_OPTIONS, SORT_OPTION, UsageError } from '../options.js';
2
2
  import { API, FOLDER_OPTION, LISTING, filters, given, keywords, overriding, paging, payload, refuseWithMine, sort } from './shared.js';
3
3
  import { validateContainerPayload } from '../payload.js';
4
- import { uploadFormImage } from './upload.js';
4
+ import { upload, uploadFormImage } from './upload.js';
5
5
  /**
6
6
  * The shape behind `--json` on a form, shown rather than described: `fields` is
7
7
  * the part nothing else hints at, and one choice field carries more of the
@@ -372,6 +372,16 @@ export const FORM = [
372
372
  'jinshuju form theme set Kp7mQ2 --wallpaper ./bg.png'
373
373
  ]
374
374
  },
375
+ {
376
+ path: ['form', 'image', 'upload'],
377
+ summary: 'Upload an image for a form or field description',
378
+ description: "Answers with a url to put in an <img src> inside a form's description or a field's notes. " +
379
+ 'The image belongs to the first form saved with a description that refers to it; one that no ' +
380
+ 'form takes within 7 days is removed.',
381
+ args: [{ name: 'file', required: true, description: 'Image file' }],
382
+ request: (input) => upload(`${API}/form_image_attachments`, input.args.file, { image_type: 'description' }),
383
+ examples: ['jinshuju form image upload ./venue-map.png']
384
+ },
375
385
  {
376
386
  path: ['form', 'rule', 'get'],
377
387
  summary: 'Show the field display rules of a form',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {