@enspirit/opspicy 0.0.0-stage → 0.2.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -2
  3. package/bin/entry.js +27 -0
  4. package/bin/opspicy +19 -0
  5. package/dist/addresses.js +27 -0
  6. package/dist/behind.js +64 -0
  7. package/dist/citizens.js +71 -0
  8. package/dist/configuration.d.ts +56 -0
  9. package/dist/configuration.js +66 -0
  10. package/dist/explorer/afresh.js +43 -0
  11. package/dist/explorer/api.js +101 -0
  12. package/dist/explorer/asking.js +59 -0
  13. package/dist/explorer/build.js +11 -0
  14. package/dist/explorer/calls.js +42 -0
  15. package/dist/explorer/document.js +109 -0
  16. package/dist/explorer/elo-refs.js +153 -0
  17. package/dist/explorer/elo.js +95 -0
  18. package/dist/explorer/fonts/OFL.txt +93 -0
  19. package/dist/explorer/fonts/dm-sans-latin.woff2 +0 -0
  20. package/dist/explorer/html.js +59 -0
  21. package/dist/explorer/index.js +61 -0
  22. package/dist/explorer/json.js +33 -0
  23. package/dist/explorer/machine.js +34 -0
  24. package/dist/explorer/masking.js +57 -0
  25. package/dist/explorer/operation.js +94 -0
  26. package/dist/explorer/pages.js +132 -0
  27. package/dist/explorer/script/base.js +103 -0
  28. package/dist/explorer/script/call.js +161 -0
  29. package/dist/explorer/script/calling.js +103 -0
  30. package/dist/explorer/script/connection.js +83 -0
  31. package/dist/explorer/script/copying.js +75 -0
  32. package/dist/explorer/script/filter.js +56 -0
  33. package/dist/explorer/script/formaldef.js +37 -0
  34. package/dist/explorer/script/main.js +82 -0
  35. package/dist/explorer/script/markdown.js +143 -0
  36. package/dist/explorer/script/notes.js +184 -0
  37. package/dist/explorer/script/noting.js +38 -0
  38. package/dist/explorer/script/peek.js +62 -0
  39. package/dist/explorer/script/peeking.js +19 -0
  40. package/dist/explorer/script/ranking.js +91 -0
  41. package/dist/explorer/script/review.js +126 -0
  42. package/dist/explorer/script/rows.js +58 -0
  43. package/dist/explorer/script/run.js +168 -0
  44. package/dist/explorer/script/running.js +66 -0
  45. package/dist/explorer/script/search.js +122 -0
  46. package/dist/explorer/script/sending.js +64 -0
  47. package/dist/explorer/script/served.js +51 -0
  48. package/dist/explorer/serve.js +41 -0
  49. package/dist/explorer/server.js +143 -0
  50. package/dist/explorer/site.js +77 -0
  51. package/dist/explorer/style.css +241 -0
  52. package/dist/explorer/telling.js +30 -0
  53. package/dist/explorer/tests.js +78 -0
  54. package/dist/explorer/wiki.js +76 -0
  55. package/dist/files.js +176 -0
  56. package/dist/finding.js +17 -0
  57. package/dist/judging.js +75 -0
  58. package/dist/lines.js +30 -0
  59. package/dist/main.js +128 -0
  60. package/dist/meaning.js +100 -0
  61. package/dist/modelling.js +115 -0
  62. package/dist/naming.js +84 -0
  63. package/dist/notation.js +119 -0
  64. package/dist/planning.js +32 -0
  65. package/dist/reading.js +120 -0
  66. package/dist/report-file.js +42 -0
  67. package/dist/report.js +62 -0
  68. package/dist/running.js +102 -0
  69. package/dist/selecting.js +71 -0
  70. package/dist/starting.js +41 -0
  71. package/dist/suite.js +29 -0
  72. package/dist/words.js +103 -0
  73. package/dist/world.js +128 -0
  74. package/package.json +57 -4
@@ -0,0 +1,95 @@
1
+ // Elo, highlighted. The grammar is Elo's own, for highlight.js (`@enspirit/highlightjs-elo`): which
2
+ // words are its keywords, its functions and its types is said there, and nowhere here. It is
3
+ // applied when the document is written, so the page carries no library and works offline.
4
+ // Pure: text in, tokens out, and the tokens say the whole text, every character once.
5
+ import grammar from '@enspirit/highlightjs-elo';
6
+ import hljs from 'highlight.js/lib/core';
7
+ import { refsIn } from './elo-refs.js';
8
+ import { esc } from './html.js';
9
+ export { refsOf } from './elo-refs.js';
10
+ hljs.registerLanguage('elo', grammar);
11
+ /** The kind of a token, by the scope the grammar gives it: a date and a duration are numbers there, a data path a variable. */
12
+ const SCOPES = [
13
+ ['comment', 'comment'],
14
+ ['string', 'string'],
15
+ ['number', 'number'],
16
+ ['keyword', 'keyword'],
17
+ ['literal', 'literal'],
18
+ ['built_in', 'builtin'],
19
+ ['type', 'type'],
20
+ ['title', 'fn'],
21
+ ['punctuation', 'op'],
22
+ ['operator', 'op'],
23
+ ['variable', 'member'],
24
+ ];
25
+ const kindOf = (classes) => SCOPES.find(([scope]) => classes.split(' ')[0] === `hljs-${scope}`)?.[1] ?? 'text';
26
+ /** What highlight.js writes instead of the characters that mean something in HTML. */
27
+ const WRITTEN = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#x27;': "'" };
28
+ const read = (html) => html.replace(/&(?:amp|lt|gt|quot|#x27);/g, (entity) => WRITTEN[entity] ?? entity);
29
+ /**
30
+ * The tokens of a text: concatenated, they are the text. highlight.js gives spans, one inside
31
+ * another where a text holds an escape: a token is the outermost, whole, and what is in no span
32
+ * is plain text.
33
+ */
34
+ export function tokensOf(text) {
35
+ const tokens = [];
36
+ let depth = 0;
37
+ for (const [, opened, closed, said] of hljs.highlight(text, { language: 'elo' }).value.matchAll(/<span class="([^"]*)">|(<\/span>)|([^<]+)/g)) {
38
+ if (opened !== undefined && depth++ === 0)
39
+ tokens.push({ kind: kindOf(opened), text: '' });
40
+ else if (closed)
41
+ depth--;
42
+ else if (said !== undefined)
43
+ append(tokens, depth, read(said));
44
+ }
45
+ return tokens;
46
+ }
47
+ /** Adds what is said to the token it is of: the span that is open, or the plain text that was being said. */
48
+ function append(tokens, depth, text) {
49
+ const last = tokens[tokens.length - 1];
50
+ if (last && (depth > 0 || last.kind === 'text'))
51
+ last.text += text;
52
+ else
53
+ tokens.push({ kind: 'text', text });
54
+ }
55
+ /** The words of the code, where they start: those of the plain tokens, never of a text, a comment or a member. */
56
+ function wordsOf(tokens) {
57
+ const words = [];
58
+ let at = 0;
59
+ for (const token of tokens) {
60
+ if (token.kind === 'text')
61
+ for (const found of token.text.matchAll(/[A-Za-z_]\w*/g))
62
+ words.push({ at: at + found.index, text: found[0] });
63
+ at += token.text.length;
64
+ }
65
+ return words;
66
+ }
67
+ /** What a token says, with the names in it that lead to a citizen as links. */
68
+ function linked(text, at, refs) {
69
+ let html = '';
70
+ let from = 0;
71
+ for (const ref of refs.filter((one) => one.at >= at && one.at + one.length <= at + text.length)) {
72
+ const start = ref.at - at;
73
+ html += `${esc(text.slice(from, start))}<a class="ref" href="${esc(`#${ref.anchor}`)}">${esc(text.slice(start, start + ref.length))}</a>`;
74
+ from = start + ref.length;
75
+ }
76
+ return html + esc(text.slice(from));
77
+ }
78
+ /**
79
+ * The text, highlighted: each kind of token is a span of its own class, the others are plain.
80
+ * Given what the suite names, a name that Elo's parser reads as a citizen leads to it (elo-refs.ts):
81
+ * about the citizen whose formaldef this is, which is not linked, and the parameters it is given.
82
+ */
83
+ export function eloHtml(text, refs, about = {}) {
84
+ const tokens = tokensOf(text);
85
+ const links = refs ? refsIn(text, wordsOf(tokens), refs, about) : [];
86
+ let at = 0;
87
+ return tokens
88
+ .map((token) => {
89
+ // A function of Elo's own, called, is that function: never the state or the word a suite gave the same name.
90
+ const html = linked(token.text, at, token.kind === 'fn' ? links.filter((one) => !one.called) : links);
91
+ at += token.text.length;
92
+ return token.kind === 'text' ? html : `<span class="e-${token.kind}">${html}</span>`;
93
+ })
94
+ .join('');
95
+ }
@@ -0,0 +1,93 @@
1
+ Copyright 2014 The DM Sans Project Authors (https://github.com/googlefonts/dm-fonts)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,59 @@
1
+ // Small pieces of HTML, and the one pattern every citizen is shown with: its name, its
2
+ // description, and its formaldef, folded. Pure: text in, markup out.
3
+ import { eloHtml } from './elo.js';
4
+ const ENTITIES = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
5
+ /** Any value, as text of a page: every name, sentence and value of the suite goes through here. */
6
+ export const esc = (value) => String(value).replace(/[&<>"']/g, (character) => ENTITIES[character] ?? character);
7
+ /** A value as a line of JSON, for what a case sends. */
8
+ export const compact = (value) => (value === undefined ? '' : JSON.stringify(value));
9
+ export const link = (href, text) => `<a href="${esc(href)}">${esc(text)}</a>`;
10
+ export const mono = (text) => `<span class="mono">${esc(text)}</span>`;
11
+ /** Elo code, highlighted, as a block: a name of the suite leads to its citizen, when what the suite names is given. */
12
+ export const elo = (text, refs, about) => `<pre class="elo">${eloHtml(text, refs, about)}</pre>`;
13
+ /** A description, as its file says it: what it sets between backticks is code. */
14
+ export const said = (description) => esc(description).replace(/`([^`]+)`/g, '<code>$1</code>');
15
+ export const RESULT = {
16
+ passed: '<span class="res ok">✓ passed</span>',
17
+ failed: '<span class="res ko">✗ failed</span>',
18
+ notrun: '<span class="res nr">○ not run</span>',
19
+ };
20
+ const HOW = {
21
+ checked: { mark: '✔', words: 'Checked', short: 'checked' },
22
+ complete: { mark: '✚', words: 'Checked in the complete run only, by reading the database', short: 'checked in the complete run only' },
23
+ told: { mark: '○', words: 'Told, not checked: nothing decides it', short: 'told, not checked' },
24
+ };
25
+ /** How a clause is checked, as a mark with its words: by its formaldef, in the complete run only, or told. */
26
+ export function markOf(clause) {
27
+ const kind = !clause.formaldef ? 'told' : clause.mark === 'complete' ? 'complete' : 'checked';
28
+ const how = HOW[kind];
29
+ return `<span class="mk ${kind}" title="${esc(how.words)}" aria-label="${esc(how.words)}">${how.mark}</span>`;
30
+ }
31
+ /** What the marks mean: each as a clause shows it, a disc, beside its words. */
32
+ export const LEGEND = `<p class="legend">${Object.keys(HOW).map((kind) => `<span><span class="mk ${kind}" aria-hidden="true">${HOW[kind].mark}</span> ${HOW[kind].short}</span>`).join('')}</p>`;
33
+ /** A count, with the word for it, singular or plural. */
34
+ export const plural = (count, word) => `${count} ${count === 1 ? word : word.endsWith('y') ? `${word.slice(0, -1)}ies` : `${word}s`}`;
35
+ export const list = (items, cls = '') => (items.length ? `<ul class="list ${cls}">${items.map((item) => `<li>${item}</li>`).join('')}</ul>` : '');
36
+ const colgroup = (widths) => (widths ? `<colgroup>${widths.map((width) => `<col style="width:${width}">`).join('')}</colgroup>` : '');
37
+ const thead = (headers) => (headers.some(Boolean) ? `<thead><tr>${headers.map((header) => `<th>${esc(header)}</th>`).join('')}</tr></thead>` : '');
38
+ /** A table: its headers, then its rows, each a list of cells already written. Its columns may be given their widths, so that tables of one kind line up. */
39
+ export const table = (headers, rows, widths) => `<div class="scroll"><table class="t">${colgroup(widths)}${thead(headers)}<tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${cell}</td>`).join('')}</tr>`).join('')}</tbody></table></div>`;
40
+ const TOGGLE = '<button type="button" class="fd-toggle" aria-expanded="false" title="Show or hide the formaldef of each one">formaldef</button>';
41
+ function citizenRows(one, span) {
42
+ const cells = [one.name, one.description, ...(one.more ?? [])].map((cell) => `<td>${cell}</td>`).join('');
43
+ const formal = one.formaldef ? `<tr class="formal-row"><td colspan="${span}"><div class="formaldef">${one.formaldef}</div></td></tr>` : '';
44
+ const told = [['id', one.id], ['class', 'citizen'], ['data-home', one.home], ['data-case', one.kase], ['data-source', one.source], ['data-request', one.request]].map(([name, value]) => (value ? ` ${name}="${esc(value)}"` : '')).join('');
45
+ return `<tr${told}>${cells}</tr>${formal}`;
46
+ }
47
+ /**
48
+ * The citizens of one kind, as every page shows them: a heading, then a row each with its name
49
+ * and its description, and its formaldef under it, folded until the heading's toggle, the
50
+ * sidebar's switch or its own address opens it.
51
+ */
52
+ export function citizens(title, all, { level = 'h2', columns = [], widths, note } = {}) {
53
+ if (!all.length)
54
+ return `<${level}>${esc(title)}</${level}><p class="sub">None.</p>`;
55
+ const span = 2 + Math.max(0, ...all.map((one) => one.more?.length ?? 0));
56
+ const toggle = all.some((one) => one.formaldef) ? ` ${TOGGLE}` : '';
57
+ const heading = `<${level} class="group"><span>${esc(title)}${toggle}</span><span class="m s">${esc(note ?? plural(all.length, 'entry'))}</span></${level}>`;
58
+ return `<section class="citizens">${heading}<div class="scroll"><table class="t">${colgroup(widths)}${thead(columns)}<tbody>${all.map((one) => citizenRows(one, span)).join('')}</tbody></table></div></section>`;
59
+ }
@@ -0,0 +1,61 @@
1
+ // What the search of the explorer finds: one entry per page, and one per citizen at its own
2
+ // address, clauses and cases among them. Pure: the wiki and its pages are given.
3
+ //
4
+ // An entry is `{h, k, n, x, c, ctx}`: its anchor, its kind, its name or its sentence, what else
5
+ // it says, its formaldef as text, and the title of the page it is on. A row that only lists a
6
+ // citizen at home elsewhere is not one: a citizen is found once, where it is. What an example
7
+ // alone also shows is a clause, at an address in the row of its example.
8
+ //
9
+ // The search reads those six. A note taken on a citizen reads three more, where they apply, to
10
+ // say what it is about: `a`, its area; `w`, where it stands (`ReqPre 2`, `example 1`, the name of
11
+ // a condition); `q`, its description as written, when `n` is its name and not what it says.
12
+ import { PRE } from '../suite.js';
13
+ import { areaTitle } from './operation.js';
14
+ import { idOf, violating } from './wiki.js';
15
+ const AGENTS = 'Agents and actors';
16
+ const STATE = 'State and world';
17
+ const answered = (then) => `${then.status}${then.code ? ` ${then.code}` : ''}`;
18
+ const told = (...parts) => parts.filter(Boolean).join(' · ');
19
+ const definition = (one, ctx) => ({ h: idOf(one.kind, one.name), k: one.kind === 'predicate' ? 'Predicate' : 'Function', n: one.name, x: one.description, c: one.formaldef, ctx, a: one.area, q: one.description });
20
+ /** A condition is found by its sentence; its name is where it stands. */
21
+ const condition = (one, ctx) => ({ h: idOf('condition', one.name), k: 'Condition', n: one.description, x: told(one.name, one.violated && `violated as ${one.violated.actor}: ${answered(one.violated.then)}`), c: one.formaldef, ctx, a: one.area, w: one.name });
22
+ const wordsOf = (area) => {
23
+ const ctx = areaTitle(area.name);
24
+ return [
25
+ ...[...area.predicates, ...area.functions].map((one) => definition(one, ctx)),
26
+ ...area.conditions.map((one) => condition(one, ctx)),
27
+ ...area.types.map((one) => ({ h: idOf('type', one.name), k: 'Type', n: one.name, x: one.description, c: `${one.name} = ${one.formaldef}`, ctx, a: one.area, q: one.description })),
28
+ ];
29
+ };
30
+ /** A clause is found by its sentence, and a precondition by the counterexamples that refuse it too. */
31
+ function clause(operation, one) {
32
+ const refused = PRE.includes(one.kind) ? violating(operation, one.description).map((kase) => kase.description) : [];
33
+ const at = operation.clauses.filter((other) => other.kind === one.kind).indexOf(one) + 1;
34
+ return { h: idOf('clause', one.name), k: 'Clause', n: one.description, x: told(one.kind, refused.length ? `refused when ${refused.join('; ')}` : ''), c: one.formaldef ?? '', ctx: operation.name, a: operation.area, w: `${one.kind} ${at}` };
35
+ }
36
+ /** A case is found by its `when`, by who calls and what is answered, and by what it alone also shows. */
37
+ function kase(operation, one) {
38
+ const sent = typeof one.input === 'string' ? one.input : one.input === null || one.input === undefined ? '' : JSON.stringify(one.input);
39
+ const x = told(one.kind, one.given.actor, one.given.seed, answered(one.then), one.for && `refuses ${one.for}`, ...one.and.map((also) => also.description), sent);
40
+ const w = one.generated ? 'counterexample, from a condition' : `${one.kind} ${operation.cases.filter((other) => other.kind === one.kind).indexOf(one) + 1}`;
41
+ return { h: idOf('case', one.name), k: 'Case', n: one.description, x, c: one.and.map((also) => also.formaldef ?? '').filter(Boolean).join('\n'), ctx: operation.name, a: operation.area, w };
42
+ }
43
+ /** What an example alone also shows is a clause too, found by its sentence: it stands in its example. */
44
+ function also(operation, one) {
45
+ const example = operation.cases.filter((other) => other.kind === one.kind).indexOf(one) + 1;
46
+ return one.and.map((clause, at) => ({ h: idOf('clause', clause.name), k: 'Clause', n: clause.description, x: told('and', `shown when ${one.description}`), c: clause.formaldef ?? '', ctx: operation.name, a: operation.area, w: `${one.kind} ${example}, and ${at + 1}` }));
47
+ }
48
+ /** A citizen that has no formaldef in Elo: found by its name, and by what it says. */
49
+ const plain = (kind, label, ctx, one, also = '') => ({ h: idOf(kind, one.name), k: label, n: one.name, x: told(one.description, also), c: '', ctx, q: one.description });
50
+ /** Every entry of the search: the pages, then the citizens, each at its address. */
51
+ export function indexOf(wiki, pages) {
52
+ return [
53
+ ...pages.map((page) => ({ h: page.id, k: page.kind, n: page.title, x: page.said ?? '', c: '', ctx: '', ...(page.area ? { a: page.area } : {}), ...(page.quote ? { q: page.quote } : {}) })),
54
+ ...wiki.areas.flatMap(wordsOf),
55
+ ...wiki.operations.flatMap((operation) => [...operation.clauses.map((one) => clause(operation, one)), ...operation.cases.flatMap((one) => [kase(operation, one), ...also(operation, one)])]),
56
+ ...wiki.state.map((one) => plain('state', 'State', STATE, one, `GET ${one.path}`)),
57
+ ...wiki.relations.map((one) => ({ h: idOf('relation', one.name), k: 'Relation', n: `db.${one.name}`, x: told(one.description, one.table, one.attributes.join(', ')), c: '', ctx: STATE, q: one.description })),
58
+ ...wiki.backgrounds.map((one) => plain('background', 'Background', STATE, one)),
59
+ ...wiki.actors.map((one) => plain('actor', 'Actor', AGENTS, one, one.is)),
60
+ ];
61
+ }
@@ -0,0 +1,33 @@
1
+ // JSON, highlighted: the keys, strings, numbers, literals and punctuation of a JSON text, each
2
+ // in its class. Pure: text in, markup out; the tokens say the whole text, every character once.
3
+ import { esc } from './html.js';
4
+ const TOKENS = [
5
+ [/"(?:\\.|[^"\\])*"(?=\s*:)/y, 'key'],
6
+ [/"(?:\\.|[^"\\])*"/y, 'str'],
7
+ [/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/y, 'num'],
8
+ [/true|false|null/y, 'lit'],
9
+ [/[{}[\],:]/y, 'p'],
10
+ [/\s+/y, 'text'],
11
+ [/[\s\S]/y, 'text'],
12
+ ];
13
+ /** The JSON text, highlighted: each kind of token is a span of its own class. */
14
+ export function jsonHtml(text) {
15
+ let out = '';
16
+ let at = 0;
17
+ while (at < text.length) {
18
+ let matched = '';
19
+ let kind = 'text';
20
+ for (const [pattern, name] of TOKENS) {
21
+ pattern.lastIndex = at;
22
+ const found = pattern.exec(text);
23
+ if (found && found[0].length > 0) {
24
+ matched = found[0];
25
+ kind = name;
26
+ break;
27
+ }
28
+ }
29
+ out += kind === 'text' ? esc(matched) : `<span class="j-${kind}">${esc(matched)}</span>`;
30
+ at += matched.length;
31
+ }
32
+ return out;
33
+ }
@@ -0,0 +1,34 @@
1
+ // This machine, as a request or an option names it. Pure.
2
+ //
3
+ // The API of a served explorer runs cases and signs actors in, so it is offered on this machine
4
+ // and answers its own page: who asks is told by the host a request names and by the origin it
5
+ // comes from, which a browser says for a page and a page cannot change. What is not plainly this
6
+ // machine is not: a name that only resolves to it, a short form of its address.
7
+ /** The name in a host, without its port: `[::1]:8080` names `::1`, `LocalHost.:8080` names `localhost`. */
8
+ function named(host) {
9
+ const bracketed = /^\[([0-9a-f.]*:[0-9a-f:.]*)\](?::\d+)?$/i.exec(host);
10
+ if (bracketed)
11
+ return (bracketed[1] ?? '').toLowerCase();
12
+ // More than one colon is an address of IPv6 said bare, as `--host=::1` says it: it has no port.
13
+ const bare = (host.match(/:/g) ?? []).length > 1 ? host : host.replace(/:\d+$/, '');
14
+ return bare.toLowerCase().replace(/\.$/, '');
15
+ }
16
+ /** An address of IPv4 that never leaves the machine: 127.0.0.0/8, each part written plainly. */
17
+ const LOOPBACK = /^127(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
18
+ /** A host that is this machine: `localhost`, `::1`, an address under 127, whatever its port, its case, or the dot that ends its name. */
19
+ export function isLoopback(host) {
20
+ const name = named(host);
21
+ return name === 'localhost' || name === '::1' || LOOPBACK.test(name);
22
+ }
23
+ /**
24
+ * Whether a request is the page's own: it names this machine, and comes from nowhere else. A
25
+ * browser says the origin of whatever is more than a reading, so a request that says none is no
26
+ * page of another site.
27
+ */
28
+ export function ownPage(host, origin) {
29
+ if (host === undefined || !isLoopback(host))
30
+ return false;
31
+ return origin === undefined || origin.toLowerCase() === `http://${host.toLowerCase()}`;
32
+ }
33
+ /** Where a server is, as a reader types it: an address of IPv6 between brackets. */
34
+ export const urlOf = (host, port) => `http://${host.includes(':') ? `[${host}]` : host}:${port}/`;
@@ -0,0 +1,57 @@
1
+ // What is told of a run, without what the world keeps to itself. Pure.
2
+ //
3
+ // The world of a suite holds what its actors sign in with, and what the system told once: a
4
+ // token a seed planted. A case may send them (an input computed from `world`), a system may say
5
+ // them back, and a sign-in that fails may name them. The page of a run is told none of it: a
6
+ // text that is one of those values is said as `•••`, and so is the part of a longer text that is
7
+ // one of eight characters or more, which nobody says by chance. A shorter one is a name as often
8
+ // as a secret (`member`, `fr`): it is hidden where it stands alone, and left inside a sentence.
9
+ import { credentialsOf } from '../suite.js';
10
+ export const MASK = '•••';
11
+ const LONG = 8;
12
+ const textsIn = (value) => (typeof value === 'string' ? [value] : value && typeof value === 'object' ? Object.values(value).flatMap(textsIn) : []);
13
+ /** The texts of the world, at whatever depth: what each actor signs in with, and what else `world.yml` says. */
14
+ export function secretsOf(model) {
15
+ const all = new Set([...textsIn(credentialsOf(model)), ...textsIn(model.world)].filter(Boolean));
16
+ return { all, long: [...all].filter((one) => one.length >= LONG).sort((a, b) => b.length - a.length) };
17
+ }
18
+ /** A text, as it is told: the mask where it is a secret, or holds a long one. */
19
+ export const hidden = (text, { all, long }) => (all.has(text) ? MASK : long.reduce((told, secret) => told.split(secret).join(MASK), text));
20
+ /** Data, as it is told: each text of it hidden. The keys are left: they are names, not values. */
21
+ export function masked(value, secrets) {
22
+ if (typeof value === 'string')
23
+ return hidden(value, secrets);
24
+ if (Array.isArray(value))
25
+ return value.map((one) => masked(one, secrets));
26
+ if (!value || typeof value !== 'object')
27
+ return value;
28
+ return Object.fromEntries(Object.entries(value).map(([name, one]) => [name, masked(one, secrets)]));
29
+ }
30
+ /** A part of a path, as it is told: read as it was before it was made safe for a path, and left as it is written when nothing of it is hidden. */
31
+ function part(text, secrets) {
32
+ let written = text;
33
+ try {
34
+ written = decodeURIComponent(text);
35
+ }
36
+ catch {
37
+ // What is no part made safe is read as it stands.
38
+ }
39
+ const told = hidden(written, secrets);
40
+ return told === written ? text : told.split(MASK).map(encodeURIComponent).join(MASK);
41
+ }
42
+ /** A path, as it is told: each part of its route and each value of its query hidden. */
43
+ export function maskedPath(path, secrets) {
44
+ const [route = '', ...query] = path.split('?');
45
+ const pair = (one) => (one.includes('=') ? `${one.slice(0, one.indexOf('='))}=${part(one.slice(one.indexOf('=') + 1), secrets)}` : one);
46
+ const asked = query.length ? `?${query.join('?').split('&').map(pair).join('&')}` : '';
47
+ return `${route.split('/').map((one) => part(one, secrets)).join('/')}${asked}`;
48
+ }
49
+ /** What a case did, as it is told: of each call, where it went, what it sent and what it was answered. */
50
+ export function maskedWire(wire, secrets) {
51
+ return wire.map((one) => {
52
+ if (!('method' in one))
53
+ return one;
54
+ const sent = one.sent === undefined ? {} : { sent: masked(one.sent, secrets) };
55
+ return { ...one, path: maskedPath(one.path, secrets), ...sent, body: masked(one.body, secrets) };
56
+ });
57
+ }
@@ -0,0 +1,94 @@
1
+ // The page of an operation: what it is, its input and its output, its clauses, its examples and
2
+ // its counterexamples. What the suite says, and nothing of a run: that is in tests.ts.
3
+ // Pure: the wiki is given, markup is what comes out.
4
+ import { PRE, SAID, sameSentence } from '../suite.js';
5
+ import { requestOf } from './calls.js';
6
+ import { eloHtml } from './elo.js';
7
+ import { jsonHtml } from './json.js';
8
+ import { citizens, compact, elo, esc, link, list, markOf, mono, said } from './html.js';
9
+ import { idOf, violating } from './wiki.js';
10
+ /** What each group of clauses says: what is, and what is required, before and after the call. */
11
+ const GROUP = {
12
+ DomPre: 'Before the call, of the domain',
13
+ ReqPre: 'Before the call, required of it',
14
+ DomPost: 'After the call, of the domain',
15
+ ReqPost: 'After the call, required of it',
16
+ ReqTrig: 'When it is performed without being asked',
17
+ and: 'What one example alone also shows',
18
+ };
19
+ export const crumbs = (...parts) => `<p class="crumb">${parts.join('<span aria-hidden="true">›</span>')}</p>`;
20
+ export const areaTitle = (name) => (name === '_shared' ? 'Shared' : name.charAt(0).toUpperCase() + name.slice(1));
21
+ const row = (label, value) => `<dt>${esc(label)}</dt><dd>${value}</dd>`;
22
+ const typeLink = (name) => (name ? link(`#${idOf('type', name)}`, name) : '<span class="m">nothing</span>');
23
+ /** Who calls, and from which Background: a name for a table cell, each leading to who and what it is. */
24
+ export const callerOf = (kase) => {
25
+ const who = kase.given.actor ? link(`#${idOf('actor', kase.given.actor)}`, kase.given.actor) : '<span class="m">nobody</span>';
26
+ return kase.given.seed ? `${who}<br><span class="m s">${link(`#${idOf('background', kase.given.seed)}`, kase.given.seed)}</span>` : who;
27
+ };
28
+ /** What a case sends, as a cell: its data, or the Elo expression that gives it. */
29
+ export const sentOf = (kase, refs) => typeof kase.input === 'string' ? `<code class="elo">${eloHtml(kase.input, refs)}</code>` : `<span class="mono">${kase.input === null || kase.input === undefined ? 'nothing' : jsonHtml(compact(kase.input))}</span>`;
30
+ /** What a case is answered, as a cell: its status, and the code of a refusal. */
31
+ export const answeredOf = (kase) => mono(`${kase.then.status}${kase.then.code ? ` ${kase.then.code}` : ''}`);
32
+ /** A clause, as a citizen: its mark for a name, its sentence, its formaldef, and where a condition gives it, the way there. */
33
+ function clauseShown(operation, clause, { conditions, refs }) {
34
+ const shared = clause.from === 'shared' ? conditions.find((one) => sameSentence(one.description, clause.description)) : undefined;
35
+ const origin = shared ? ` <a class="m s" href="#${esc(idOf('condition', shared.name))}">condition</a>` : '';
36
+ const against = PRE.includes(clause.kind) ? violating(operation, clause.description) : [];
37
+ const refused = against.length ? against.map((kase) => said(kase.description)).join('<br>') : '<span class="m">none</span>';
38
+ return { id: idOf('clause', clause.name), source: clause.source, name: markOf(clause), description: `${said(clause.description)}${origin}`, formaldef: clause.formaldef ? elo(clause.formaldef, refs) : undefined, more: PRE.includes(clause.kind) ? [refused] : [] };
39
+ }
40
+ /** One group of clauses, as citizens: before the call, with the counterexamples that refuse each. */
41
+ function clauseGroup(operation, kind, around) {
42
+ const clauses = operation.clauses.filter((one) => one.kind === kind);
43
+ if (!clauses.length)
44
+ return '';
45
+ const pre = PRE.includes(kind);
46
+ return citizens(kind, clauses.map((clause) => clauseShown(operation, clause, around)), { level: 'h3', note: GROUP[kind], columns: pre ? ['', '', 'Refused when'] : [], widths: pre ? ['3%', '67%', '30%'] : ['3%', '97%'] });
47
+ }
48
+ /** A main section of a page: its title, and its content, which the toggle at the top of the page collapses. */
49
+ const fold = (title, content) => `<details class="fold" open><summary class="fold-title">${esc(title)}</summary>${content}</details>`;
50
+ /** What one example alone also shows: each sentence with its mark, at an address of its own as any clause has, then with what decides it. */
51
+ const alsoShown = (kase) => kase.and.map((clause) => `<span class="also" id="${esc(idOf('clause', clause.name))}"${clause.source ? ` data-source="${esc(clause.source)}"` : ''}>${markOf(clause)} ${said(clause.description)}</span>`).join('<br>');
52
+ const alsoDecided = (kase, refs) => kase.and.filter((clause) => clause.formaldef).map((clause) => `<p class="m s">${said(clause.description)}</p>${elo(clause.formaldef ?? '', refs)}`).join('');
53
+ /** The columns of the examples and of the counterexamples: the same widths, so the two tables line up. */
54
+ const CASE_WIDTHS = ['24%', '14%', '26%', '14%', '22%'];
55
+ function casesShown(operation, kind, refs) {
56
+ const cases = operation.cases.filter((kase) => kase.kind === kind);
57
+ const example = kind === 'example';
58
+ if (!cases.length)
59
+ return `<p class="sub">No ${kind}.</p>`;
60
+ const shown = cases.map((kase) => ({
61
+ id: idOf('case', kase.name),
62
+ source: kase.source,
63
+ request: JSON.stringify(requestOf(operation, kase)),
64
+ name: `${said(kase.description)}${kase.generated ? '<br><span class="m s">from a condition</span>' : ''}`,
65
+ description: callerOf(kase),
66
+ formaldef: alsoDecided(kase, refs) || undefined,
67
+ more: [sentOf(kase, refs), answeredOf(kase), example ? alsoShown(kase) : said(kase.for ?? '')],
68
+ }));
69
+ return citizens(example ? 'Examples' : 'Counterexamples', shown, { level: 'h3', columns: ['When', 'Caller', 'Sends', 'Answers', example ? 'Also shows' : 'Refuses'], widths: CASE_WIDTHS, note: `${cases.length} of them` });
70
+ }
71
+ /** One side of the input or the output: what the type is, and its declaration, highlighted as Elo. */
72
+ function typeSide(label, name, { types, refs }) {
73
+ const type = name ? types.get(name) : undefined;
74
+ if (!name)
75
+ return `<section aria-label="${label}"><p class="m">nothing</p></section>`;
76
+ if (!type)
77
+ return `<section aria-label="${label}"><p class="sub">${esc(name)}: not declared in a types.elo.</p></section>`;
78
+ return `<section aria-label="${label}"><p class="sub">${said(type.description)}</p>${elo(`${type.name} = ${type.formaldef}`, refs, { self: idOf('type', type.name) })}</section>`;
79
+ }
80
+ export function operationPage(operation, around) {
81
+ const gaps = operation.gaps.length ? fold('Gaps', `<p class="sub">What no case shows, or no counterexample violates.</p>${list(operation.gaps.map((gap) => `<span class="m">· ${esc(gap)}</span>`))}`) : '';
82
+ const kind = operation.observes ? 'Observation: it only reads, so it is checked to change nothing' : 'Operation';
83
+ const meta = [row('Performed by', link(`#${idOf('agent', operation.agent)}`, operation.agent)), row('Route', mono(`${operation.entry.method} ${operation.entry.path}`)), row('Kind', esc(kind)), row('Input', typeLink(operation.input)), row('Output', typeLink(operation.output)), row('Specification', mono(operation.file)), row('Tests', link(`#${idOf('test', operation.name)}`, 'Results of the last run'))];
84
+ const io = `<div class="io">${typeSide('Input', operation.input, around)}<span class="arrow" aria-hidden="true">→</span>${typeSide('Output', operation.output, around)}</div>`;
85
+ const body = `<div class="page-top">${crumbs(link('#home', 'Specification'), link(`#${idOf('area', operation.area)}`, areaTitle(operation.area)))}<button type="button" class="fold-all" aria-expanded="true">Collapse all</button></div>
86
+ <h1 class="code">${esc(operation.name)}</h1>
87
+ <p class="lead">${said(operation.description)}</p>
88
+ <dl class="meta">${meta.join('')}</dl>
89
+ ${fold('Input and output', io)}
90
+ ${fold('Clauses', SAID.map((group) => clauseGroup(operation, group, around)).join(''))}
91
+ ${fold('Cases', `${casesShown(operation, 'example', around.refs)}${casesShown(operation, 'counterexample', around.refs)}`)}
92
+ ${gaps}`;
93
+ return { id: idOf('op', operation.name), kind: operation.observes ? 'Observation' : 'Operation', title: operation.name, nav: idOf('area', operation.area), source: operation.source, said: `${operation.description} ${operation.entry.method} ${operation.entry.path}`, area: operation.area, quote: operation.description, body };
94
+ }