@mistriwork/engine 1.0.0-rc.14 → 1.0.0-rc.16
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/dist/adapters/cache/cacheStore.d.ts +1 -1
- package/dist/adapters/cache/cacheStore.js +1 -1
- package/dist/server/cli/startup.js +7 -2
- package/dist/server/cli/usage.d.ts +2 -0
- package/dist/server/cli/usage.js +12 -1
- package/dist/server/clientHttp.js +20 -3
- package/dist/server/config/profile.d.ts +10 -3
- package/dist/server/config/profile.js +28 -4
- package/dist/server/connections.js +1 -1
- package/dist/server/demo.js +3 -3
- package/dist/server/http/baselineHeaders.d.ts +13 -3
- package/dist/server/http/baselineHeaders.js +6 -0
- package/dist/server/http/frontDoor.d.ts +41 -0
- package/dist/server/http/frontDoor.js +36 -0
- package/dist/server/http/rateLimit.d.ts +2 -2
- package/dist/server/http/rateLimit.js +16 -2
- package/dist/server/http/recordCompose.d.ts +3 -0
- package/dist/server/http/recordCompose.js +1 -0
- package/dist/server/http/serverCore.d.ts +2 -2
- package/dist/server/http/serverCore.js +16 -32
- package/dist/server/migrate/cli.js +8 -1
- package/dist/server/migrate/desired.js +2 -2
- package/dist/server/migrate/target.d.ts +8 -0
- package/dist/server/migrate/target.js +15 -0
- package/dist/server/seed/seed.js +46 -11
- package/dist/server/startupWarnings.js +1 -1
- package/dist/shared/appCards.d.ts +4 -0
- package/dist/shared/appCards.js +5 -0
- package/dist/shared/breakdown.js +8 -2
- package/dist/shared/computed.d.ts +16 -2
- package/dist/shared/computed.js +23 -4
- package/dist/shared/computedValue.js +23 -0
- package/dist/shared/iconWeights.js +1 -0
- package/dist/shared/listPresentations.d.ts +9 -2
- package/dist/shared/listPresentations.js +2 -0
- package/dist/shared/listQuestion.d.ts +9 -0
- package/dist/shared/listQuestion.js +18 -0
- package/dist/shared/mentionLookup.js +3 -1
- package/dist/shared/page.d.ts +8 -1
- package/dist/shared/page.js +151 -7
- package/dist/shared/pageAnatomy.js +2 -0
- package/dist/shared/pageConfig.d.ts +1 -1
- package/dist/shared/pageConfig.js +106 -19
- package/dist/shared/pageModel.d.ts +62 -5
- package/dist/shared/pagePaths.js +4 -1
- package/dist/shared/pagePlans.d.ts +4 -2
- package/dist/shared/pagePlans.js +6 -4
- package/dist/shared/recordLabel.d.ts +12 -3
- package/dist/shared/recordLabel.js +39 -18
- package/dist/shared/recordReads.d.ts +6 -30
- package/dist/shared/recordReads.js +13 -1
- package/dist/shared/rollups.d.ts +4 -4
- package/dist/shared/rollups.js +1 -1
- package/dist/shared/schema.d.ts +7 -0
- package/dist/shared/schema.js +17 -0
- package/dist/shared/servedApp.d.ts +5 -1
- package/dist/shared/viewLabels.js +22 -17
- package/package.json +3 -2
- package/schema/model.d.ts +14 -5
- package/schema/theme.d.ts +1 -1
package/dist/shared/page.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import { ANYONE, saidAt } from './query.js';
|
|
29
29
|
import { listEmptyConfig } from './listEmpty.js';
|
|
30
30
|
import { withDefaultAside } from './pageAnatomy.js';
|
|
31
|
-
import { columnKind, columnOrRollup, findTable, primaryKey, looksLikeDate, rowName, referencesTo, tableNamed, } from './schema.js';
|
|
31
|
+
import { columnKind, columnOrRollup, findTable, primaryKey, looksLikeDate, rowName, referencesTo, referencesFrom, tableNamed, } from './schema.js';
|
|
32
32
|
import { tryResolvePath } from './viewPaths.js';
|
|
33
33
|
import { hopName, parseViewQuery, validateView } from './view.js';
|
|
34
34
|
import { DATE_UNITS } from './breakdown.js';
|
|
@@ -134,6 +134,7 @@ function validated(schema, page) {
|
|
|
134
134
|
if (error)
|
|
135
135
|
return { ...page, error: `document: "number": ${error}` };
|
|
136
136
|
}
|
|
137
|
+
const reactions = new Map();
|
|
137
138
|
for (const [i, section] of page.sections.entries()) {
|
|
138
139
|
const at = section.title ? `"${section.title}"` : `section ${i + 1}`;
|
|
139
140
|
/* A note reads nothing. Nor does a history (the record's own writes), a flows section (the runs are the record's
|
|
@@ -186,6 +187,12 @@ function validated(schema, page) {
|
|
|
186
187
|
error: `${at}: "was" is a number or money column beside the figure; "${section.was}" is ${was.resolved.column.type || 'untyped'}.`,
|
|
187
188
|
};
|
|
188
189
|
}
|
|
190
|
+
/* The line under the figure is read from the record, so it must name something there. */
|
|
191
|
+
if (section.subtitle !== undefined) {
|
|
192
|
+
const line = tryResolvePath(schema, page.base, section.subtitle);
|
|
193
|
+
if (!line.resolved)
|
|
194
|
+
return { ...page, error: `${at}: "subtitle" names "${section.subtitle}", ${line.error?.message ?? 'which does not resolve'}` };
|
|
195
|
+
}
|
|
189
196
|
if (section.status !== undefined && !columnOrRollup(base, section.status)) {
|
|
190
197
|
return { ...page, error: `${at}: the header's status "${section.status}" is not a column on ${base.name}.` };
|
|
191
198
|
}
|
|
@@ -228,7 +235,7 @@ function validated(schema, page) {
|
|
|
228
235
|
error: `${here}: "${stream.at}" is ${atCol.type || 'untyped'} — a timeline orders by a date column. See \`mistri docs dates-and-types\`.`,
|
|
229
236
|
};
|
|
230
237
|
}
|
|
231
|
-
for (const path of [stream.
|
|
238
|
+
for (const path of [stream.text, stream.badge, stream.by].filter((p) => Boolean(p))) {
|
|
232
239
|
/* A bare name is a column of `from`; a dotted path walks references
|
|
233
240
|
to a column of the table it reaches, and is judged the way a
|
|
234
241
|
list column is — `author_id.name`, not a chain of references. */
|
|
@@ -257,6 +264,14 @@ function validated(schema, page) {
|
|
|
257
264
|
const sides = timelineSides(schema, section);
|
|
258
265
|
if (sides.error)
|
|
259
266
|
return { ...page, error: `${at}${sides.error}` };
|
|
267
|
+
/* Reactions name their columns, or have the one candidate each: the page is served with them named, so the
|
|
268
|
+
browser reads and the check refuses the same three. */
|
|
269
|
+
if (section.reactions) {
|
|
270
|
+
const reacted = timelineReactions(schema, section);
|
|
271
|
+
if ('error' in reacted)
|
|
272
|
+
return { ...page, error: `${at}: ${reacted.error}` };
|
|
273
|
+
reactions.set(i, reacted.reactions);
|
|
274
|
+
}
|
|
260
275
|
continue;
|
|
261
276
|
}
|
|
262
277
|
/* A custom section's reads are judged as the lists they are planned
|
|
@@ -325,6 +340,11 @@ function validated(schema, page) {
|
|
|
325
340
|
const problem = relatedMatchProblem(schema, page, section);
|
|
326
341
|
if (problem)
|
|
327
342
|
return { ...page, error: `${at}: ${problem}` };
|
|
343
|
+
if (section.opens) {
|
|
344
|
+
const reference = table.columns.find((column) => column.name === section.opens)?.references;
|
|
345
|
+
if (!reference || !findTable(schema, reference.table))
|
|
346
|
+
return { ...page, error: `${at}: "opens" names "${section.opens}", which is not a reference column of ${table.name}.` };
|
|
347
|
+
}
|
|
328
348
|
}
|
|
329
349
|
if (section.kind === 'metric' && section.fn !== 'count' && !section.column) {
|
|
330
350
|
return { ...page, error: `${at}: "${section.fn}" needs a column to ${section.fn}.` };
|
|
@@ -377,7 +397,112 @@ function validated(schema, page) {
|
|
|
377
397
|
}
|
|
378
398
|
}
|
|
379
399
|
}
|
|
380
|
-
|
|
400
|
+
if (!reactions.size)
|
|
401
|
+
return { ...page, error: undefined };
|
|
402
|
+
return {
|
|
403
|
+
...page,
|
|
404
|
+
sections: page.sections.map((section, i) => section.kind === 'timeline' && reactions.has(i) ? { ...section, reactions: reactions.get(i) } : section),
|
|
405
|
+
error: undefined,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* A timeline's reactions with their three columns named: `whose`, the column of `from` that refers to an entry of one
|
|
410
|
+
* of the streams; `by`, the one that refers to the table people are rows of (`person`, an App's `auth.me`), read as
|
|
411
|
+
* `<by> = me`; `column`, the text column the kinds are values of. Each one the author left out is the one candidate
|
|
412
|
+
* `from` has, and two or none is refused with the key to add. A kind the column's database constraint does not allow
|
|
413
|
+
* is refused by name.
|
|
414
|
+
*/
|
|
415
|
+
function timelineReactions(schema, section) {
|
|
416
|
+
const r = section.reactions;
|
|
417
|
+
const from = findTable(schema, r.from);
|
|
418
|
+
if (!from)
|
|
419
|
+
return { error: `"reactions" reads "${r.from}", which is not a table here.` };
|
|
420
|
+
const entries = new Set(section.streams.map((stream) => findTable(schema, stream.from)?.id).filter(Boolean));
|
|
421
|
+
const listed = (columns) => columns.map((c) => `"${c.name}"`).join(', ');
|
|
422
|
+
const choose = (key, candidates, what) => {
|
|
423
|
+
if (candidates.length === 1)
|
|
424
|
+
return candidates[0];
|
|
425
|
+
return {
|
|
426
|
+
error: candidates.length
|
|
427
|
+
? `"reactions" names no "${key}", and ${listed(candidates)} could each be ${what}. Add "${key}": the one that is.`
|
|
428
|
+
: `"reactions" names no "${key}", and no column of ${from.name} is ${what}. Add "${key}": the column that is.`,
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
const refs = singleReferences(schema, from.id);
|
|
432
|
+
const refersTo = (tables) => (c) => tables.has(findTable(schema, refs.get(c.name)?.table ?? '')?.id);
|
|
433
|
+
const column = (key, name) => {
|
|
434
|
+
const found = from.columns.find((c) => c.name === name);
|
|
435
|
+
return found ?? { error: `reactions.${key} names "${name}", which is not a column on ${from.name}.` };
|
|
436
|
+
};
|
|
437
|
+
const whose = r.whose
|
|
438
|
+
? column('whose', r.whose)
|
|
439
|
+
: choose('whose', from.columns.filter(refersTo(entries)), `the entry a reaction is to (a reference to ${[...entries].join(' or ')})`);
|
|
440
|
+
if ('error' in whose)
|
|
441
|
+
return whose;
|
|
442
|
+
if (r.whose && !refersTo(entries)(whose))
|
|
443
|
+
return {
|
|
444
|
+
error: `reactions.whose names "${r.whose}", which does not refer to an entry of this timeline (${[...entries].join(' or ')}).`,
|
|
445
|
+
};
|
|
446
|
+
/* A press runs the command on the entry the reaction names, by the column `whose` refers to as its key: a reference
|
|
447
|
+
to another unique column (a post's slug) would hand the command a value that is not the entry's key. */
|
|
448
|
+
const target = refs.get(whose.name);
|
|
449
|
+
const entry = findTable(schema, target.table);
|
|
450
|
+
const entryKey = primaryKey(entry);
|
|
451
|
+
if (entryKey.length !== 1 || entryKey[0] !== target.column)
|
|
452
|
+
return {
|
|
453
|
+
error: `reactions.whose "${whose.name}" refers to ${entry.name}.${target.column}, which is not ${entry.name}'s primary key` +
|
|
454
|
+
`${entryKey.length ? ` (${entryKey.join(', ')})` : ''}; a reaction is pressed on its entry by that key, so "whose" must refer to it.`,
|
|
455
|
+
};
|
|
456
|
+
const person = r.person === undefined ? undefined : findTable(schema, r.person)?.id;
|
|
457
|
+
if (!r.by && !person)
|
|
458
|
+
return {
|
|
459
|
+
error: `"reactions" names no "by", and the App does not say which table people are rows of (auth.me). Add "by": the column of ${from.name} that holds who reacted.`,
|
|
460
|
+
};
|
|
461
|
+
const by = r.by
|
|
462
|
+
? column('by', r.by)
|
|
463
|
+
: choose('by', from.columns.filter((c) => c.name !== whose.name && refersTo(new Set([person]))(c)), `who reacted (a reference to ${person})`);
|
|
464
|
+
if ('error' in by)
|
|
465
|
+
return by;
|
|
466
|
+
if (by.name === whose.name)
|
|
467
|
+
return { error: `reactions.by and reactions.whose both name "${by.name}"; a reaction is someone's, to something.` };
|
|
468
|
+
const kinds = (c) => !c.allowed || r.kinds.every((kind) => c.allowed.includes(kind));
|
|
469
|
+
const kind = r.column
|
|
470
|
+
? column('column', r.column)
|
|
471
|
+
: choose('column', from.columns.filter((c) => !c.primaryKey && !refs.has(c.name) && c.name !== whose.name && c.name !== by.name && columnKind(c.type) === 'text' && kinds(c)), `the kind of a reaction (a text column holding ${r.kinds.map((k) => `"${k}"`).join(', ')})`);
|
|
472
|
+
if ('error' in kind)
|
|
473
|
+
return kind;
|
|
474
|
+
if (kind.name === whose.name || kind.name === by.name)
|
|
475
|
+
return { error: `reactions.column names "${kind.name}", which is already "${kind.name === whose.name ? 'whose' : 'by'}".` };
|
|
476
|
+
const allowed = kind.allowed;
|
|
477
|
+
const stray = allowed && r.kinds.find((each) => !allowed.includes(each));
|
|
478
|
+
if (stray)
|
|
479
|
+
return { error: `reactions.kinds names "${stray}", which ${from.name}.${kind.name} does not allow (${allowed.join(', ')}).` };
|
|
480
|
+
return { reactions: { ...r, whose: whose.name, by: by.name, column: kind.name } };
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The column of a stream's table a timeline's reactions name its entries by — the column `whose` refers to — or
|
|
484
|
+
* undefined where the stream's rows are not what the reactions are to. Read on a validated page, whose `whose` is named.
|
|
485
|
+
*/
|
|
486
|
+
export function reactedColumn(schema, section, stream) {
|
|
487
|
+
const r = section.reactions;
|
|
488
|
+
if (!r?.whose)
|
|
489
|
+
return undefined;
|
|
490
|
+
const from = findTable(schema, r.from);
|
|
491
|
+
const ref = from && singleReferences(schema, from.id).get(r.whose);
|
|
492
|
+
const table = findTable(schema, stream.from);
|
|
493
|
+
return ref && table && findTable(schema, ref.table)?.id === table.id ? ref.column : undefined;
|
|
494
|
+
}
|
|
495
|
+
/** The table a timeline's reactions are to: the one `whose` refers to, on a validated page. */
|
|
496
|
+
export function reactionEntryTable(schema, reactions) {
|
|
497
|
+
const from = findTable(schema, reactions.from);
|
|
498
|
+
const ref = from && reactions.whose ? singleReferences(schema, from.id).get(reactions.whose) : undefined;
|
|
499
|
+
return ref && findTable(schema, ref.table)?.id;
|
|
500
|
+
}
|
|
501
|
+
/* A table's one-column references by the column that holds each: the only kind a reaction's entry or person can be. */
|
|
502
|
+
function singleReferences(schema, tableId) {
|
|
503
|
+
return new Map(referencesFrom(schema, tableId)
|
|
504
|
+
.filter((fk) => fk.from.columns.length === 1)
|
|
505
|
+
.map((fk) => [fk.from.columns[0], { table: fk.to.table, column: fk.to.columns[0] }]));
|
|
381
506
|
}
|
|
382
507
|
/**
|
|
383
508
|
* Which rows of each timeline stream are the other party's: the condition each stream is asked, with `record.` reached
|
|
@@ -685,6 +810,7 @@ function createConfig(create) {
|
|
|
685
810
|
export function sectionConfig(s) {
|
|
686
811
|
const common = {
|
|
687
812
|
...(s.title !== undefined ? { title: s.title } : {}),
|
|
813
|
+
...(s.icon ? { icon: s.icon } : {}),
|
|
688
814
|
...(s.region !== undefined ? { region: s.region } : {}),
|
|
689
815
|
...(s.tab !== undefined ? { tab: s.tab } : {}),
|
|
690
816
|
...(s.width && s.width !== 'full' ? { width: s.width } : {}),
|
|
@@ -729,6 +855,7 @@ export function sectionConfig(s) {
|
|
|
729
855
|
show: s.paths ?? [],
|
|
730
856
|
...(s.actions ? { links: s.actions.map((a) => ('view' in a ? (({ view, ...rest }) => ({ ...rest, to: view }))(a) : a)) } : {}),
|
|
731
857
|
...(s.subfigure !== undefined ? { subfigure: s.subfigure } : {}),
|
|
858
|
+
...(s.subtitle !== undefined ? { subtitle: s.subtitle } : {}),
|
|
732
859
|
...(s.was !== undefined ? { was: s.was } : {}),
|
|
733
860
|
...(s.note !== undefined ? { note: s.note } : {}),
|
|
734
861
|
};
|
|
@@ -740,6 +867,7 @@ export function sectionConfig(s) {
|
|
|
740
867
|
...(s.names === false ? { names: false } : {}),
|
|
741
868
|
...(s.presentation ? { presentation: s.presentation } : {}),
|
|
742
869
|
...(s.edit ? { editable: true } : {}),
|
|
870
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
743
871
|
};
|
|
744
872
|
case 'timeline':
|
|
745
873
|
return {
|
|
@@ -750,8 +878,8 @@ export function sectionConfig(s) {
|
|
|
750
878
|
from: stream.from,
|
|
751
879
|
whose: stream.path,
|
|
752
880
|
at: stream.at,
|
|
753
|
-
|
|
754
|
-
|
|
881
|
+
text: stream.text,
|
|
882
|
+
badge: stream.badge,
|
|
755
883
|
author: stream.by,
|
|
756
884
|
query: stream.filter,
|
|
757
885
|
...(stream.of ? { about: stream.of } : {}),
|
|
@@ -765,6 +893,18 @@ export function sectionConfig(s) {
|
|
|
765
893
|
...(s.tone ? { tone: s.tone } : {}),
|
|
766
894
|
...(s.compact ? { compact: s.compact } : {}),
|
|
767
895
|
...(s.side ? { side: s.side } : {}),
|
|
896
|
+
...(s.reactions
|
|
897
|
+
? {
|
|
898
|
+
reactions: {
|
|
899
|
+
from: s.reactions.from,
|
|
900
|
+
kinds: s.reactions.kinds,
|
|
901
|
+
command: s.reactions.command,
|
|
902
|
+
...(s.reactions.whose ? { whose: s.reactions.whose } : {}),
|
|
903
|
+
...(s.reactions.by ? { by: s.reactions.by } : {}),
|
|
904
|
+
...(s.reactions.column ? { column: s.reactions.column } : {}),
|
|
905
|
+
},
|
|
906
|
+
}
|
|
907
|
+
: {}),
|
|
768
908
|
};
|
|
769
909
|
case 'metric':
|
|
770
910
|
return {
|
|
@@ -799,7 +939,8 @@ export function sectionConfig(s) {
|
|
|
799
939
|
whose: s.path,
|
|
800
940
|
show: s.labels ? s.columns?.map((column) => (s.labels[column] ? { column, label: s.labels[column] } : column)) : s.columns,
|
|
801
941
|
query: s.filter,
|
|
802
|
-
...(s.empty ? { empty: listEmptyConfig(s.empty) } : {}),
|
|
942
|
+
...(s.emptyMode === 'hide' ? { empty: 'hide' } : s.empty ? { empty: listEmptyConfig(s.empty) } : {}),
|
|
943
|
+
...(s.opens ? { opens: s.opens } : {}),
|
|
803
944
|
sort: s.orderBy?.map((o) => (o.direction === 'desc' ? `${o.column} desc` : o.column)).join(', '),
|
|
804
945
|
};
|
|
805
946
|
return {
|
|
@@ -849,6 +990,7 @@ export function sectionConfig(s) {
|
|
|
849
990
|
: { measure: [s.fn, s.column].filter(Boolean).join(' ') }),
|
|
850
991
|
query: s.filter,
|
|
851
992
|
limit: s.limit,
|
|
993
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
852
994
|
...(s.format !== undefined ? { format: s.format } : {}),
|
|
853
995
|
...(s.unit !== undefined ? { unit: s.unit } : {}),
|
|
854
996
|
};
|
|
@@ -872,6 +1014,9 @@ export function sectionConfig(s) {
|
|
|
872
1014
|
limit: s.limit,
|
|
873
1015
|
...(s.height !== undefined ? { height: s.height } : {}),
|
|
874
1016
|
...(s.target !== undefined ? { target: s.target } : {}),
|
|
1017
|
+
...(s.curve ? { curve: s.curve } : {}),
|
|
1018
|
+
...(s.total ? { total: s.total } : {}),
|
|
1019
|
+
...(s.emptyMode ? { empty: s.emptyMode } : {}),
|
|
875
1020
|
...(s.format !== undefined ? { format: s.format } : {}),
|
|
876
1021
|
...(s.unit !== undefined ? { unit: s.unit } : {}),
|
|
877
1022
|
};
|
|
@@ -881,7 +1026,6 @@ export function sectionConfig(s) {
|
|
|
881
1026
|
kind: s.kind,
|
|
882
1027
|
text: s.text,
|
|
883
1028
|
...(s.variant ? { variant: s.variant } : {}),
|
|
884
|
-
...(s.icon ? { icon: s.icon } : {}),
|
|
885
1029
|
...(s.action ? { action: 'view' in s.action ? { label: s.action.label, to: s.action.view } : s.action } : {}),
|
|
886
1030
|
};
|
|
887
1031
|
case 'custom':
|
|
@@ -358,6 +358,8 @@ export function withDefaultAside(schema, page) {
|
|
|
358
358
|
shown.add(section.status);
|
|
359
359
|
if (section.was)
|
|
360
360
|
shown.add(section.was.split('.')[0]);
|
|
361
|
+
if (section.subtitle)
|
|
362
|
+
shown.add(section.subtitle.split('.')[0]);
|
|
361
363
|
}
|
|
362
364
|
const name = labelColumn(base);
|
|
363
365
|
const paths = railOf(base.columns.filter((column) => readable(base, column) && column.name !== name && !shown.has(column.name)));
|
|
@@ -15,7 +15,7 @@ export declare const APP_PAGE_KEYS: ("aside" | "base" | "empty" | "layout" | "li
|
|
|
15
15
|
/** The keys each page section kind takes. Anything else is refused by name. A `segment` is read before the
|
|
16
16
|
section is (appSegments.ts unfoldSegments), as its word in `query`. */
|
|
17
17
|
export declare const PAGE_SECTION_KEYS: Record<PageSection['kind'] | 'view' | 'header' | 'current' | 'card' | 'headline', readonly string[]>;
|
|
18
|
-
export declare const STREAM_KEYS: readonly ['from', 'whose', 'at', '
|
|
18
|
+
export declare const STREAM_KEYS: readonly ['from', 'whose', 'at', 'text', 'badge', 'author', 'query', 'about', 'side', 'tone', 'compact'];
|
|
19
19
|
/**
|
|
20
20
|
* One page body: a tablewalk.json page, whose `id` is its own or derives
|
|
21
21
|
* from the name, or an App page, whose id is its key. The body is the same
|
|
@@ -9,7 +9,7 @@ import { parseRelatedCreate } from './relatedCreate.js';
|
|
|
9
9
|
import { parseListEmpty } from './listEmpty.js';
|
|
10
10
|
import { CHART_SHAPES, FIGURE_FORMATS, FIGURE_FORMAT_WORDS, allowKeys, humanName } from './model.js';
|
|
11
11
|
import { headingOf } from './appNoun.js';
|
|
12
|
-
import { CARDS_MAX_LINES, parseCards, parseFacts } from './appCards.js';
|
|
12
|
+
import { CARDS_MAX_LINES, HEADER_MAX_FACTS, parseCards, parseFacts } from './appCards.js';
|
|
13
13
|
import { parseIcon } from './appIcons.js';
|
|
14
14
|
import { slug } from './slug.js';
|
|
15
15
|
import { parsePageLayout } from './pageLayouts.js';
|
|
@@ -74,7 +74,7 @@ export const PAGE_KEYS = ['label', 'base', 'connection', 'listTabs', 'empty', 's
|
|
|
74
74
|
export const APP_PAGE_KEYS = PAGE_KEYS.filter((key) => key !== 'connection' && key !== 'label');
|
|
75
75
|
/* `aside` and `layout` are an App page's alone: the Workbench's pages draw what they say, in the record's one skeleton. */
|
|
76
76
|
const WORKBENCH_PAGE_KEYS = PAGE_KEYS.filter((key) => key !== 'aside' && key !== 'layout');
|
|
77
|
-
const SECTION_COMMON = ['kind', 'title', 'region', 'tab', 'width', 'offsetLeft', 'offsetRight', 'hidden', 'when'];
|
|
77
|
+
const SECTION_COMMON = ['kind', 'title', 'icon', 'region', 'tab', 'width', 'offsetLeft', 'offsetRight', 'hidden', 'when'];
|
|
78
78
|
/** A tab's name is a word or two across the strip, not a sentence. */
|
|
79
79
|
const MAX_TAB_NAME = 40;
|
|
80
80
|
/** The keys each page section kind takes. Anything else is refused by name. A `segment` is read before the
|
|
@@ -82,22 +82,22 @@ const MAX_TAB_NAME = 40;
|
|
|
82
82
|
/* `view` is an authored kind with no section of its own: `embed(view, { whose })`
|
|
83
83
|
is read into a related list that remembers the view (PageList.view). */
|
|
84
84
|
export const PAGE_SECTION_KEYS = {
|
|
85
|
-
fields: [...SECTION_COMMON, 'show', 'columns', 'names', 'presentation', 'editable'],
|
|
85
|
+
fields: [...SECTION_COMMON, 'show', 'columns', 'names', 'presentation', 'editable', 'empty'],
|
|
86
86
|
/* The record a reference names, in a box of its own: the first shown field is its title, the rest its facts. */
|
|
87
87
|
card: [...SECTION_COMMON, 'show'],
|
|
88
88
|
/* A figure with its facts, its earlier value, its estimate and the calls to action beside it. */
|
|
89
|
-
headline: [...SECTION_COMMON, 'show', 'links', 'subfigure', 'was', 'note'],
|
|
89
|
+
headline: [...SECTION_COMMON, 'show', 'links', 'subfigure', 'subtitle', 'was', 'note'],
|
|
90
90
|
/* The record's head: drawn where the head is, so nothing that would place it elsewhere. */
|
|
91
91
|
header: ['kind', 'status', 'facts', 'primary', 'destructive', 'actions'],
|
|
92
92
|
/* The one current related row as a card: nothing to page, sum or add under it. */
|
|
93
|
-
current: ['kind', 'title', 'region', 'tab', 'width', 'when', 'from', 'whose', 'show', 'query', 'sort', 'empty'],
|
|
94
|
-
timeline: [...SECTION_COMMON, 'streams', 'limit', 'create', 'newest', 'composer', 'tone', 'compact', 'side'],
|
|
93
|
+
current: ['kind', 'title', 'icon', 'region', 'tab', 'width', 'when', 'from', 'whose', 'show', 'query', 'sort', 'empty', 'opens'],
|
|
94
|
+
timeline: [...SECTION_COMMON, 'streams', 'limit', 'create', 'newest', 'composer', 'tone', 'compact', 'side', 'reactions'],
|
|
95
95
|
history: [...SECTION_COMMON, 'limit'],
|
|
96
96
|
flows: [...SECTION_COMMON],
|
|
97
97
|
diagram: [...SECTION_COMMON],
|
|
98
98
|
custom: [...SECTION_COMMON, 'component', 'record', 'rows', 'figures', 'props'],
|
|
99
99
|
metric: [...SECTION_COMMON, 'from', 'whose', 'about', 'measure', 'query', 'segment', 'format', 'unit'],
|
|
100
|
-
breakdown: [...SECTION_COMMON, 'from', 'whose', 'about', 'by', 'measure', 'query', 'segment', 'limit', 'format', 'unit'],
|
|
100
|
+
breakdown: [...SECTION_COMMON, 'from', 'whose', 'about', 'by', 'measure', 'query', 'segment', 'limit', 'format', 'unit', 'empty'],
|
|
101
101
|
chart: [
|
|
102
102
|
...SECTION_COMMON,
|
|
103
103
|
'from',
|
|
@@ -106,6 +106,8 @@ export const PAGE_SECTION_KEYS = {
|
|
|
106
106
|
'by',
|
|
107
107
|
'measure',
|
|
108
108
|
'shape',
|
|
109
|
+
'curve',
|
|
110
|
+
'total',
|
|
109
111
|
'sort',
|
|
110
112
|
'query',
|
|
111
113
|
'segment',
|
|
@@ -114,8 +116,9 @@ export const PAGE_SECTION_KEYS = {
|
|
|
114
116
|
'target',
|
|
115
117
|
'format',
|
|
116
118
|
'unit',
|
|
119
|
+
'empty',
|
|
117
120
|
],
|
|
118
|
-
note: [...SECTION_COMMON, 'text', '
|
|
121
|
+
note: [...SECTION_COMMON, 'text', 'action', 'variant'],
|
|
119
122
|
view: [...SECTION_COMMON, 'view', 'whose', 'about', 'limit'],
|
|
120
123
|
list: [
|
|
121
124
|
...SECTION_COMMON,
|
|
@@ -133,12 +136,13 @@ export const PAGE_SECTION_KEYS = {
|
|
|
133
136
|
'totals',
|
|
134
137
|
'same',
|
|
135
138
|
'near',
|
|
139
|
+
'opens',
|
|
136
140
|
'rowActions',
|
|
137
141
|
'actions',
|
|
138
142
|
'group',
|
|
139
143
|
],
|
|
140
144
|
};
|
|
141
|
-
export const STREAM_KEYS = ['from', 'whose', 'at', '
|
|
145
|
+
export const STREAM_KEYS = ['from', 'whose', 'at', 'text', 'badge', 'author', 'query', 'about', 'side', 'tone', 'compact'];
|
|
142
146
|
/**
|
|
143
147
|
* One page body: a tablewalk.json page, whose `id` is its own or derives
|
|
144
148
|
* from the name, or an App page, whose id is its key. The body is the same
|
|
@@ -366,6 +370,7 @@ function parseSection(entry, at, config) {
|
|
|
366
370
|
const placement = {
|
|
367
371
|
...(region === undefined ? {} : { region }),
|
|
368
372
|
...(tab === undefined ? {} : { tab }),
|
|
373
|
+
...(s.icon === undefined ? {} : { icon: parseIcon(s.icon, at) }),
|
|
369
374
|
};
|
|
370
375
|
if (s.create !== undefined && kind !== 'list' && kind !== 'timeline')
|
|
371
376
|
throw new Error(`${at}: create belongs on a related list or a timeline.`);
|
|
@@ -393,6 +398,7 @@ function parseSection(entry, at, config) {
|
|
|
393
398
|
? {
|
|
394
399
|
actions: `belongs on a headline(figure, { links }). ${retiredFieldsForms()}`,
|
|
395
400
|
subfigure: `belongs on a headline(figure, { subfigure }). ${retiredFieldsForms()}`,
|
|
401
|
+
subtitle: `belongs on a headline(figure, { subtitle }). ${retiredFieldsForms()}`,
|
|
396
402
|
was: `belongs on a headline(figure, { was }). ${retiredFieldsForms()}`,
|
|
397
403
|
note: `belongs on a headline(figure, { note }). ${retiredFieldsForms()}`,
|
|
398
404
|
}
|
|
@@ -418,12 +424,18 @@ function parseSection(entry, at, config) {
|
|
|
418
424
|
if (s.editable === true && s.presentation !== undefined && !['summary', 'properties'].includes(s.presentation)) {
|
|
419
425
|
throw new Error(`${at}: "editable" belongs on the fields a reader edits — a summary or a property rail; a ${String(s.presentation)} says values, it does not hold them.`);
|
|
420
426
|
}
|
|
427
|
+
if (s.empty !== undefined && s.empty !== 'hide' && s.empty !== 'show') {
|
|
428
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A block of fields leaves out the values a record does not have ('hide') or says each as a dash ('show'); a property rail hides them unless it says 'show'.`);
|
|
429
|
+
}
|
|
421
430
|
if (s.was !== undefined && (typeof s.was !== 'string' || !FIELD_PATH.test(s.was.trim()))) {
|
|
422
431
|
throw new Error(`${at} has a "was" that is not a field name, like "was_price": the figure's earlier value.`);
|
|
423
432
|
}
|
|
424
433
|
if (s.subfigure !== undefined && (typeof s.subfigure !== 'string' || !FIELD_PATH.test(s.subfigure.trim()))) {
|
|
425
434
|
throw new Error(`${at} has a "subfigure" that is not a field name or a label path like "account_id.name".`);
|
|
426
435
|
}
|
|
436
|
+
if (s.subtitle !== undefined && (typeof s.subtitle !== 'string' || !FIELD_PATH.test(s.subtitle.trim()))) {
|
|
437
|
+
throw new Error(`${at} has a "subtitle" that is not a field name or a label path like "income_frequency": the line under the figure.`);
|
|
438
|
+
}
|
|
427
439
|
if (s.note !== undefined && (typeof s.note !== 'string' || !s.note.trim() || s.note.trim().length > 300)) {
|
|
428
440
|
throw new Error(`${at} has a "note" that is not text of at most 300 characters.`);
|
|
429
441
|
}
|
|
@@ -446,8 +458,10 @@ function parseSection(entry, at, config) {
|
|
|
446
458
|
names: s.names === false ? false : undefined,
|
|
447
459
|
...(s.presentation === undefined ? {} : { presentation: s.presentation }),
|
|
448
460
|
...(s.editable === true ? { edit: true } : {}),
|
|
461
|
+
...(s.empty === 'hide' || s.empty === 'show' ? { emptyMode: s.empty } : {}),
|
|
449
462
|
...(s.links === undefined ? {} : { actions: parseHeadlineActions(s.links, at) }),
|
|
450
463
|
...(s.subfigure === undefined ? {} : { subfigure: s.subfigure.trim() }),
|
|
464
|
+
...(s.subtitle === undefined ? {} : { subtitle: s.subtitle.trim() }),
|
|
451
465
|
...(s.was === undefined ? {} : { was: s.was.trim() }),
|
|
452
466
|
...(s.note === undefined ? {} : { note: s.note.trim() }),
|
|
453
467
|
};
|
|
@@ -467,6 +481,14 @@ function parseSection(entry, at, config) {
|
|
|
467
481
|
throw new Error(`${here} is not an object.`);
|
|
468
482
|
const t = raw;
|
|
469
483
|
refuseRenamed(t, here, ['path', 'tint']);
|
|
484
|
+
/* The parts as the row draws them. `show` and `detail` read the opposite of how they were drawn (the main value
|
|
485
|
+
leads, the badge sits beside who and when): they are refused with their new names, not read. */
|
|
486
|
+
for (const [was, now] of [
|
|
487
|
+
['show', 'text'],
|
|
488
|
+
['detail', 'badge'],
|
|
489
|
+
])
|
|
490
|
+
if (t[was] !== undefined)
|
|
491
|
+
throw new Error(`${here} has "${was}", which is now "${now}"${now === 'text' ? " — the row's main value" : ' — the quiet word beside who and when'}.`);
|
|
470
492
|
allowKeys(t, STREAM_KEYS, here);
|
|
471
493
|
const from = typeof t.from === 'string' ? t.from.trim() : '';
|
|
472
494
|
if (!from)
|
|
@@ -477,9 +499,9 @@ function parseSection(entry, at, config) {
|
|
|
477
499
|
const atCol = typeof t.at === 'string' ? t.at.trim() : '';
|
|
478
500
|
if (!atCol)
|
|
479
501
|
throw new Error(`${here} has no "at" — the date column the stream is ordered by.`);
|
|
480
|
-
const
|
|
481
|
-
if (!
|
|
482
|
-
throw new Error(`${here} has no "
|
|
502
|
+
const text = typeof t.text === 'string' ? t.text.trim() : '';
|
|
503
|
+
if (!text)
|
|
504
|
+
throw new Error(`${here} has no "text" — the line each row becomes.`);
|
|
483
505
|
/* `query` is the one spelling; the internal stream keeps its `filter`.
|
|
484
506
|
`author` says who wrote a row, where `by` groups one everywhere else;
|
|
485
507
|
the internal stream keeps its `by`. */
|
|
@@ -501,8 +523,8 @@ function parseSection(entry, at, config) {
|
|
|
501
523
|
from,
|
|
502
524
|
path,
|
|
503
525
|
at: atCol,
|
|
504
|
-
|
|
505
|
-
|
|
526
|
+
text,
|
|
527
|
+
badge: t.badge === undefined ? undefined : String(t.badge).trim() || undefined,
|
|
506
528
|
by: t.author === undefined ? undefined : String(t.author).trim() || undefined,
|
|
507
529
|
filter: filterRaw === undefined ? undefined : String(filterRaw).trim() || undefined,
|
|
508
530
|
...(typeof t.side === 'string' ? { side: t.side.trim() } : {}),
|
|
@@ -526,6 +548,7 @@ function parseSection(entry, at, config) {
|
|
|
526
548
|
throw new Error(`${at} has a "side" that is not a condition like "author_id = record.caller_id".`);
|
|
527
549
|
}
|
|
528
550
|
const side = typeof s.side === 'string' ? s.side.trim() : undefined;
|
|
551
|
+
const reactions = s.reactions === undefined ? undefined : parseTimelineReactions(s.reactions, at);
|
|
529
552
|
if (composer && s.create !== undefined) {
|
|
530
553
|
throw new Error(`${at} has both "composer" and "create": a conversation's composer is the commands' (reply, note), and "create" is the form's. Keep one.`);
|
|
531
554
|
}
|
|
@@ -544,6 +567,7 @@ function parseSection(entry, at, config) {
|
|
|
544
567
|
...(tone ? { tone } : {}),
|
|
545
568
|
...(compact ? { compact } : {}),
|
|
546
569
|
...(side ? { side } : {}),
|
|
570
|
+
...(reactions ? { reactions } : {}),
|
|
547
571
|
...(s.create === undefined ? {} : { create: parseRelatedCreate(s.create, at) }),
|
|
548
572
|
...(when ? { when } : {}),
|
|
549
573
|
};
|
|
@@ -629,7 +653,6 @@ function parseSection(entry, at, config) {
|
|
|
629
653
|
...(when ? { when } : {}),
|
|
630
654
|
...(s.variant === undefined ? {} : { variant: s.variant }),
|
|
631
655
|
text: s.text.trim(),
|
|
632
|
-
...(s.icon === undefined ? {} : { icon: parseIcon(s.icon, at) }),
|
|
633
656
|
...(action ? { action } : {}),
|
|
634
657
|
};
|
|
635
658
|
}
|
|
@@ -679,7 +702,10 @@ function parseSection(entry, at, config) {
|
|
|
679
702
|
editable: 'is gone: the lines of a record are edited in its form (a form\'s "lines")',
|
|
680
703
|
order: 'is gone with the editable lines; a list sorts with "sort"',
|
|
681
704
|
}
|
|
682
|
-
: {
|
|
705
|
+
: {
|
|
706
|
+
subtitle: "is a second line under a record's own figure, read from a column of the record (headline(figure, { subtitle })); " +
|
|
707
|
+
'a measured figure has no record\'s column to read it from. Say it in the figure\'s "unit" or its title',
|
|
708
|
+
});
|
|
683
709
|
const from = typeof s.from === 'string' ? s.from.trim() : '';
|
|
684
710
|
if (!from)
|
|
685
711
|
throw new Error(`${at} has no "from" table.`);
|
|
@@ -766,6 +792,20 @@ function parseSection(entry, at, config) {
|
|
|
766
792
|
sort = parsed[0].direction === 'desc' ? `${parsed[0].column} desc` : parsed[0].column;
|
|
767
793
|
}
|
|
768
794
|
}
|
|
795
|
+
if (s.curve !== undefined) {
|
|
796
|
+
if (s.curve !== 'smooth' && s.curve !== 'straight')
|
|
797
|
+
throw new Error(`${at} has a "curve" of ${JSON.stringify(s.curve)}. Use "smooth" or "straight".`);
|
|
798
|
+
if (s.shape !== undefined && s.shape !== 'line')
|
|
799
|
+
throw new Error(`${at} is a ${String(s.shape)} chart; only a line has a "curve".`);
|
|
800
|
+
}
|
|
801
|
+
if (s.total !== undefined) {
|
|
802
|
+
if (s.shape !== 'donut')
|
|
803
|
+
throw new Error(`${at} has a "total", which names a donut's middle figure; it is not a donut.`);
|
|
804
|
+
if (typeof s.total !== 'string' || !s.total.trim() || s.total.trim().length > 40)
|
|
805
|
+
throw new Error(`${at} has a "total" that is not a few words (at most 40 characters): what the middle figure counts.`);
|
|
806
|
+
}
|
|
807
|
+
if (s.empty !== undefined && s.empty !== 'hide')
|
|
808
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A chart takes 'hide', which leaves it out while it has nothing to draw.`);
|
|
769
809
|
const { fn, column } = parseMeasure(s.measure, at);
|
|
770
810
|
return {
|
|
771
811
|
kind: 'chart',
|
|
@@ -788,6 +828,9 @@ function parseSection(entry, at, config) {
|
|
|
788
828
|
...(s.limit === undefined ? {} : { limit: s.limit }),
|
|
789
829
|
...(s.height === undefined ? {} : { height: s.height }),
|
|
790
830
|
...(s.target === undefined ? {} : { target: s.target }),
|
|
831
|
+
...(s.curve === undefined ? {} : { curve: s.curve }),
|
|
832
|
+
...(s.total === undefined ? {} : { total: s.total.trim() }),
|
|
833
|
+
...(s.empty === 'hide' ? { emptyMode: 'hide' } : {}),
|
|
791
834
|
...figureWords,
|
|
792
835
|
};
|
|
793
836
|
}
|
|
@@ -799,6 +842,8 @@ function parseSection(entry, at, config) {
|
|
|
799
842
|
if (s.limit !== undefined && (typeof s.limit !== 'number' || !Number.isInteger(s.limit) || s.limit < 1)) {
|
|
800
843
|
throw new Error(`${at} has a "limit" that is not a positive whole number.`);
|
|
801
844
|
}
|
|
845
|
+
if (s.empty !== undefined && s.empty !== 'hide')
|
|
846
|
+
throw new Error(`${at} has "empty": ${JSON.stringify(s.empty)}. A breakdown takes 'hide', which leaves it out while it has nothing to count.`);
|
|
802
847
|
const measure = parseMeasure(s.measure, at);
|
|
803
848
|
return {
|
|
804
849
|
kind: 'breakdown',
|
|
@@ -819,6 +864,7 @@ function parseSection(entry, at, config) {
|
|
|
819
864
|
by,
|
|
820
865
|
filter,
|
|
821
866
|
limit: s.limit,
|
|
867
|
+
...(s.empty === 'hide' ? { emptyMode: 'hide' } : {}),
|
|
822
868
|
...figureWords,
|
|
823
869
|
};
|
|
824
870
|
}
|
|
@@ -838,8 +884,13 @@ function parseSection(entry, at, config) {
|
|
|
838
884
|
/* The one current row as a card — the active lease, the latest visit —
|
|
839
885
|
chosen by the list's query and sort: one row, so nothing to page, sum
|
|
840
886
|
or add under it. */
|
|
841
|
-
|
|
842
|
-
|
|
887
|
+
/* The reference a card over a link table opens, instead of the link row: judged against the catalog with the page. */
|
|
888
|
+
if (s.opens !== undefined && !current)
|
|
889
|
+
throw new Error(`${at} has "opens", which belongs on a current() card.`);
|
|
890
|
+
if (s.opens !== undefined && (typeof s.opens !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(s.opens.trim())))
|
|
891
|
+
throw new Error(`${at} has an "opens" that is not a reference column of "${from}", e.g. "conversation_id".`);
|
|
892
|
+
if (current && (s.empty === false || s.empty === 'collapse'))
|
|
893
|
+
throw new Error(`${at} is a current() card; say what no row means with "empty" guidance, or leave it out while there is none with empty: 'hide'.`);
|
|
843
894
|
if (s.presentation !== undefined && s.presentation !== 'gallery' && !current) {
|
|
844
895
|
const raw = s.presentation;
|
|
845
896
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || raw.kind !== 'cards') {
|
|
@@ -927,6 +978,7 @@ function parseSection(entry, at, config) {
|
|
|
927
978
|
...(shown?.labels ? { labels: shown.labels } : {}),
|
|
928
979
|
filter,
|
|
929
980
|
limit: s.presentation === 'card' ? 1 : s.limit,
|
|
981
|
+
...(typeof s.opens === 'string' ? { opens: s.opens.trim() } : {}),
|
|
930
982
|
orderBy: parseSort(s.sort, at),
|
|
931
983
|
...(s.create === undefined ? {} : s.create === false ? { noCreate: true } : { create: parseRelatedCreate(s.create, at) }),
|
|
932
984
|
...(s.empty === undefined || emptyMode ? {} : { empty: parseListEmpty(s.empty, at) }),
|
|
@@ -1045,7 +1097,7 @@ function parseHeader(s, at) {
|
|
|
1045
1097
|
if (['status', 'facts', 'primary', 'destructive', 'actions'].every((key) => s[key] === undefined)) {
|
|
1046
1098
|
throw new Error(`${at}: a record header says something: a "status", "facts", its "primary" verb, its "destructive" ones or the "actions" it draws.`);
|
|
1047
1099
|
}
|
|
1048
|
-
const facts = s.facts === undefined ? undefined : parseFacts(s.facts, `${at}, header
|
|
1100
|
+
const facts = s.facts === undefined ? undefined : parseFacts(s.facts, `${at}, header`, 'facts', HEADER_MAX_FACTS);
|
|
1049
1101
|
return {
|
|
1050
1102
|
kind: 'fields',
|
|
1051
1103
|
presentation: 'header',
|
|
@@ -1076,6 +1128,41 @@ function parseTimelineComposer(raw, at) {
|
|
|
1076
1128
|
const templates = c.templates === undefined ? undefined : parseComposerTemplates(c.templates, at);
|
|
1077
1129
|
return { reply, ...(note === undefined ? {} : { note }), ...(templates ? { templates } : {}) };
|
|
1078
1130
|
}
|
|
1131
|
+
/* Reactions under each entry: the table that holds them, the kinds offered, and the command that gives or takes one
|
|
1132
|
+
back. Its columns are judged against the catalog with the rest of the section (page.ts timelineReactions). */
|
|
1133
|
+
function parseTimelineReactions(raw, at) {
|
|
1134
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
1135
|
+
throw new Error(`${at} has "reactions" that is not { from, kinds, command, whose?, by?, column? }: the table reactions are rows of, the kinds offered, and the command that toggles one.`);
|
|
1136
|
+
const r = raw;
|
|
1137
|
+
allowKeys(r, ['from', 'kinds', 'command', 'whose', 'by', 'column'], `${at}, reactions`);
|
|
1138
|
+
for (const key of ['from', 'command']) {
|
|
1139
|
+
if (typeof r[key] !== 'string' || !r[key].trim())
|
|
1140
|
+
throw new Error(`${at}: reactions needs "${key}", ${key === 'from' ? 'the table whose rows are the reactions' : "the name of the App's command that gives a reaction or takes it back"}.`);
|
|
1141
|
+
}
|
|
1142
|
+
for (const key of ['whose', 'by', 'column']) {
|
|
1143
|
+
if (r[key] !== undefined && (typeof r[key] !== 'string' || !r[key].trim()))
|
|
1144
|
+
throw new Error(`${at}: reactions.${key} is not a column's name.`);
|
|
1145
|
+
}
|
|
1146
|
+
const kinds = r.kinds;
|
|
1147
|
+
if (!Array.isArray(kinds) || !kinds.length || kinds.some((kind) => typeof kind !== 'string' || !kind.trim()))
|
|
1148
|
+
throw new Error(`${at}: reactions needs "kinds", the values a reaction may be, in the order they are drawn: ['like', 'thanks'].`);
|
|
1149
|
+
const trimmed = kinds.map((kind) => kind.trim());
|
|
1150
|
+
const twice = trimmed.find((kind, i) => trimmed.indexOf(kind) !== i);
|
|
1151
|
+
if (twice !== undefined)
|
|
1152
|
+
throw new Error(`${at}: reactions.kinds names "${twice}" twice.`);
|
|
1153
|
+
if (trimmed.length > MAX_REACTION_KINDS)
|
|
1154
|
+
throw new Error(`${at}: reactions.kinds names ${trimmed.length} kinds; a row of reactions holds at most ${MAX_REACTION_KINDS}.`);
|
|
1155
|
+
return {
|
|
1156
|
+
from: r.from.trim(),
|
|
1157
|
+
kinds: trimmed,
|
|
1158
|
+
command: r.command.trim(),
|
|
1159
|
+
...(typeof r.whose === 'string' ? { whose: r.whose.trim() } : {}),
|
|
1160
|
+
...(typeof r.by === 'string' ? { by: r.by.trim() } : {}),
|
|
1161
|
+
...(typeof r.column === 'string' ? { column: r.column.trim() } : {}),
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
/* A row of reactions under an entry stays one quiet line: more kinds than this is a survey, not a reaction. */
|
|
1165
|
+
const MAX_REACTION_KINDS = 8;
|
|
1079
1166
|
/* Canned replies: the rows of a resource, each a label to pick and the text it puts in the box. */
|
|
1080
1167
|
function parseComposerTemplates(raw, at) {
|
|
1081
1168
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|