cornfield 0.51.8 → 0.52.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/cli/cornfield.js +7 -0
- package/core/config.js +2 -1
- package/core/map-tokens.js +2 -4
- package/core/repo.js +59 -4
- package/core/strings.js +5 -0
- package/core/text.js +18 -0
- package/core/validate.js +17 -10
- package/explorer/engine/flow-legend.js +28 -0
- package/explorer/engine/flow-ui.js +3 -22
- package/explorer/engine/keyboard.js +28 -15
- package/explorer/engine/map-rect.js +2 -2
- package/explorer/engine/piece.js +27 -2
- package/explorer/engine/render.js +7 -4
- package/explorer/engine/roots.js +71 -0
- package/explorer/engine/search-status.js +2 -8
- package/explorer/flows.js +2 -1
- package/explorer/instance.js +39 -10
- package/explorer/pieces/around.js +114 -0
- package/explorer/pieces/layers.js +28 -14
- package/explorer/pieces/map.js +14 -1
- package/explorer/pieces/node-panel.js +33 -15
- package/explorer/pieces/search.js +43 -12
- package/explorer/scene.js +1 -1
- package/explorer/search-match.js +53 -0
- package/explorer/search-model.js +6 -48
- package/package.json +1 -1
- package/plugins/cloud/index.js +5 -3
- package/plugins/compose/index.js +12 -6
- package/plugins/docs/site.js +2 -2
- package/plugins/openapi/index.js +10 -5
- package/plugins/starter/index.js +2 -2
- package/plugins/world/index.js +3 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/search-match
|
|
3
|
+
*
|
|
4
|
+
* Whether a node matches a search, and how well (spec 0008 D3): the half of search-model.js the map itself needs, to halo what a query finds
|
|
5
|
+
* (scene.js `matchIds`). Pure. search-model.js builds the list, its groups and its words on it, and re-exports these.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The ranks, best first */
|
|
9
|
+
export const RANK = Object.freeze({ labelStart: 0, wordStart: 1, label: 2, idOrFile: 3, typeOrKind: 4 });
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The layer's name for each node type, as the Layers menu says it (layers.js `LAYER_DEFS`; a test keeps the two together).
|
|
13
|
+
* A type not here is its own name with a capital.
|
|
14
|
+
*/
|
|
15
|
+
export const TYPE_NAMES = Object.freeze({
|
|
16
|
+
root: 'Root', app: 'Apps', pkg: 'Packages', page: 'Pages & Routes', atom: 'Atoms', molecule: 'Molecules', token: 'Design Tokens',
|
|
17
|
+
tool: 'Dev Tools', core: 'Core', store: 'Stores', table: 'Tables', rom: 'ROM', service: 'Services', external: 'Cloud', stack: 'Infra',
|
|
18
|
+
machine: 'Machines', container: 'Containers', device: 'Devices', floor: 'House', room: 'House', persona: 'People',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const capital = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s);
|
|
22
|
+
|
|
23
|
+
/** The name of the group a node is listed under: its layer's name */
|
|
24
|
+
export const groupName = (node) => TYPE_NAMES[node.type] || capital(String(node.type || ''));
|
|
25
|
+
|
|
26
|
+
const lower = (s) => (typeof s === 'string' ? s.toLowerCase() : '');
|
|
27
|
+
const WORD_BREAK = /[^\p{L}\p{N}]+/u;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How well `query` (trimmed) matches a node, as a RANK, or -1 for no match
|
|
31
|
+
* @param {{label?: string, id?: string, file?: string, type?: string, kind?: string}} node
|
|
32
|
+
* @param {string} query
|
|
33
|
+
*/
|
|
34
|
+
export function rankOf(node, query) {
|
|
35
|
+
const term = String(query || '').toLowerCase();
|
|
36
|
+
if (!term) return -1;
|
|
37
|
+
const label = lower(node.label);
|
|
38
|
+
if (label.startsWith(term)) return RANK.labelStart;
|
|
39
|
+
if (label.split(WORD_BREAK).some((w) => w && w.startsWith(term))) return RANK.wordStart;
|
|
40
|
+
if (label.includes(term)) return RANK.label;
|
|
41
|
+
if (lower(node.id).includes(term) || lower(node.file).includes(term)) return RANK.idOrFile;
|
|
42
|
+
if (lower(node.type).includes(term) || lower(groupName(node)).includes(term) || lower(node.kind).includes(term)) return RANK.typeOrKind;
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The ids a query matches (what the map halos): a Set, empty for no query */
|
|
47
|
+
export function matchIds(nodes, query) {
|
|
48
|
+
const term = String(query || '').trim().toLowerCase();
|
|
49
|
+
const ids = new Set();
|
|
50
|
+
if (!term) return ids;
|
|
51
|
+
for (const node of nodes) if (rankOf(node, term) >= 0) ids.add(node.id);
|
|
52
|
+
return ids;
|
|
53
|
+
}
|
package/explorer/search-model.js
CHANGED
|
@@ -12,53 +12,20 @@
|
|
|
12
12
|
* - It groups by type, under the layer's name with a count, groups in the order of their best match, and puts the matches
|
|
13
13
|
* in layers that are off last, under their own heading.
|
|
14
14
|
*
|
|
15
|
-
* Substring matching only: no fuzzy matching, so a reviewer can always see why a node matched.
|
|
15
|
+
* Substring matching only: no fuzzy matching, so a reviewer can always see why a node matched. The matching itself is search-match.js.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
// Whether a node matches, and how well: search-match.js (what the map needs to halo the matches); kept as this module's too
|
|
19
|
+
import { RANK, TYPE_NAMES, groupName, rankOf, matchIds } from './search-match.js';
|
|
20
|
+
|
|
21
|
+
export { RANK, TYPE_NAMES, groupName, rankOf, matchIds };
|
|
22
|
+
|
|
18
23
|
/** The heading of the matches in layers that are off */
|
|
19
24
|
export const OFF_GROUP = 'In layers that are off';
|
|
20
25
|
|
|
21
26
|
/** Rows the list shows before "and N more" */
|
|
22
27
|
export const MAX_ROWS = 50;
|
|
23
28
|
|
|
24
|
-
/** The ranks, best first */
|
|
25
|
-
export const RANK = Object.freeze({ labelStart: 0, wordStart: 1, label: 2, idOrFile: 3, typeOrKind: 4 });
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The layer's name for each node type, as the Layers menu says it (layers.js `LAYER_DEFS`; a test keeps the two together).
|
|
29
|
-
* A type not here is its own name with a capital.
|
|
30
|
-
*/
|
|
31
|
-
export const TYPE_NAMES = Object.freeze({
|
|
32
|
-
root: 'Root', app: 'Apps', pkg: 'Packages', page: 'Pages & Routes', atom: 'Atoms', molecule: 'Molecules', token: 'Design Tokens',
|
|
33
|
-
tool: 'Dev Tools', core: 'Core', store: 'Stores', table: 'Tables', rom: 'ROM', service: 'Services', external: 'Cloud', stack: 'Infra',
|
|
34
|
-
machine: 'Machines', container: 'Containers', device: 'Devices', floor: 'House', room: 'House', persona: 'People',
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const capital = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s);
|
|
38
|
-
|
|
39
|
-
/** The name of the group a node is listed under: its layer's name */
|
|
40
|
-
export const groupName = (node) => TYPE_NAMES[node.type] || capital(String(node.type || ''));
|
|
41
|
-
|
|
42
|
-
const lower = (s) => (typeof s === 'string' ? s.toLowerCase() : '');
|
|
43
|
-
const WORD_BREAK = /[^\p{L}\p{N}]+/u;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* How well `query` (trimmed) matches a node, as a RANK, or -1 for no match
|
|
47
|
-
* @param {{label?: string, id?: string, file?: string, type?: string, kind?: string}} node
|
|
48
|
-
* @param {string} query
|
|
49
|
-
*/
|
|
50
|
-
export function rankOf(node, query) {
|
|
51
|
-
const term = String(query || '').toLowerCase();
|
|
52
|
-
if (!term) return -1;
|
|
53
|
-
const label = lower(node.label);
|
|
54
|
-
if (label.startsWith(term)) return RANK.labelStart;
|
|
55
|
-
if (label.split(WORD_BREAK).some((w) => w && w.startsWith(term))) return RANK.wordStart;
|
|
56
|
-
if (label.includes(term)) return RANK.label;
|
|
57
|
-
if (lower(node.id).includes(term) || lower(node.file).includes(term)) return RANK.idOrFile;
|
|
58
|
-
if (lower(node.type).includes(term) || lower(groupName(node)).includes(term) || lower(node.kind).includes(term)) return RANK.typeOrKind;
|
|
59
|
-
return -1;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
29
|
/**
|
|
63
30
|
* Every node the query finds, in the order the list shows them.
|
|
64
31
|
* @param {object[]} nodes the topology nodes
|
|
@@ -116,15 +83,6 @@ export function searchNodes(nodes, query, opts = {}) {
|
|
|
116
83
|
return out;
|
|
117
84
|
}
|
|
118
85
|
|
|
119
|
-
/** The ids a query matches (what the map halos): a Set, empty for no query */
|
|
120
|
-
export function matchIds(nodes, query) {
|
|
121
|
-
const term = String(query || '').trim().toLowerCase();
|
|
122
|
-
const ids = new Set();
|
|
123
|
-
if (!term) return ids;
|
|
124
|
-
for (const node of nodes) if (rankOf(node, term) >= 0) ids.add(node.id);
|
|
125
|
-
return ids;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
86
|
/**
|
|
129
87
|
* The match `by` steps (+1 or -1) from the one with id `currentId`, wrapping round; the first (or, going back, the last) when
|
|
130
88
|
* there is no current one or it is not among them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/plugins/cloud/index.js
CHANGED
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
|
|
32
32
|
import { CLOUD_FILE, deriveCloud, EVIDENCE_KINDS } from '../../core/cloud.js';
|
|
33
33
|
import { hostsIn } from './hosts.js';
|
|
34
|
-
import { leavesRepo, outsideProblem } from '../../core/repo.js';
|
|
34
|
+
import { fileOptionProblem, leavesRepo, outsideProblem } from '../../core/repo.js';
|
|
35
|
+
import { quote } from '../../core/text.js';
|
|
35
36
|
import { caddyEvidence, dockerfileSources, imageRef, workflowSources } from './sources.js';
|
|
36
37
|
|
|
37
38
|
const WORKFLOW_DIRS = ['.github/workflows', '.forgejo/workflows'];
|
|
@@ -152,8 +153,9 @@ export default {
|
|
|
152
153
|
|
|
153
154
|
// Caddyfiles the config names
|
|
154
155
|
for (const { file, from } of options.caddyfiles || []) {
|
|
155
|
-
|
|
156
|
-
if (
|
|
156
|
+
const bad = fileOptionProblem(ctx, 'cloud', 'caddyfiles[].file', file);
|
|
157
|
+
if (bad) { problems.push(bad); continue; }
|
|
158
|
+
if (!ctx.exists(file)) { warnings.push(`cloud: caddyfile ${quote(file)} does not exist.`); continue; }
|
|
157
159
|
for (const e of caddyEvidence(ctx.read(file))) add({ ...e, from, when: 'renew', file });
|
|
158
160
|
}
|
|
159
161
|
|
package/plugins/compose/index.js
CHANGED
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
import { caddyRoutes, labelsOf, traefikRoutes } from './routes.js';
|
|
38
|
-
import {
|
|
38
|
+
import { eachPlaceOnce, fileOptionProblem } from '../../core/repo.js';
|
|
39
|
+
import { quote } from '../../core/text.js';
|
|
39
40
|
|
|
40
41
|
export const COMPOSE_NAMES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
|
|
41
42
|
const CADDYFILE = /(?:^|\/)(?:Caddyfile|[\w.-]+\.caddyfile)$/i;
|
|
@@ -89,8 +90,12 @@ const targetPort = (p) => {
|
|
|
89
90
|
/** The compose files: the config's, else the first compose name in each folder */
|
|
90
91
|
function composeFiles(ctx, options, problems) {
|
|
91
92
|
if (Array.isArray(options.files)) {
|
|
92
|
-
const named = options.files.filter((f) =>
|
|
93
|
-
|
|
93
|
+
const named = eachPlaceOnce(options.files).filter((f) => {
|
|
94
|
+
const bad = fileOptionProblem(ctx, 'compose', 'files', f);
|
|
95
|
+
if (bad) problems.push(bad);
|
|
96
|
+
return !bad;
|
|
97
|
+
});
|
|
98
|
+
for (const f of named) if (!ctx.exists(f)) throw new Error(`compose file ${quote(f)} does not exist.`);
|
|
94
99
|
return named;
|
|
95
100
|
}
|
|
96
101
|
const found = ctx.walk('', (f) => COMPOSE_NAMES.includes(f.slice(f.lastIndexOf('/') + 1)));
|
|
@@ -170,11 +175,12 @@ const compose = {
|
|
|
170
175
|
for (const r of traefikRoutes(svc.name, svc.labels, svc.firstPort)) routes.push({ ...r, stack: s, from: s.file });
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
|
-
const caddyfiles = Array.isArray(options.caddyfiles) ? options.caddyfiles : ctx.walk('', (f) => CADDYFILE.test(f));
|
|
178
|
+
const caddyfiles = Array.isArray(options.caddyfiles) ? eachPlaceOnce(options.caddyfiles) : ctx.walk('', (f) => CADDYFILE.test(f));
|
|
174
179
|
const outside = new Set();
|
|
175
180
|
for (const file of caddyfiles) {
|
|
176
|
-
|
|
177
|
-
if (
|
|
181
|
+
const bad = fileOptionProblem(ctx, 'compose', 'caddyfiles', file);
|
|
182
|
+
if (bad) { problems.push(bad); continue; }
|
|
183
|
+
if (!ctx.exists(file)) { warnings.push(`compose: caddyfile ${quote(file)} does not exist.`); continue; }
|
|
178
184
|
const here = dirOf(file);
|
|
179
185
|
for (const r of caddyRoutes(ctx.read(file))) {
|
|
180
186
|
const serving = stacks.filter((s) => s.services.some((x) => x.name === r.service || x.containerName === r.service));
|
package/plugins/docs/site.js
CHANGED
|
@@ -19,7 +19,7 @@ import { deriveTopology } from '../../core/derive.js';
|
|
|
19
19
|
import { readTopology } from '../../core/validate.js';
|
|
20
20
|
import { renderMarkdown, safeUrl } from './markdown.js';
|
|
21
21
|
import docsDeriver, { resolveLink, SITE_OUTPUTS } from './index.js';
|
|
22
|
-
import { repoReader } from '../../core/repo.js';
|
|
22
|
+
import { outsideError, repoReader } from '../../core/repo.js';
|
|
23
23
|
|
|
24
24
|
/** The file a built site holds, so a rebuild knows the folder is its own */
|
|
25
25
|
export const SITE_MARKER = SITE_OUTPUTS[2];
|
|
@@ -223,7 +223,7 @@ export async function buildSite({ config, derivers, out, sourceUrl = sourceUrlOf
|
|
|
223
223
|
// What the site reads is the repo's: a path that leads out of it, by `..` or a symlink, is as if it were not there
|
|
224
224
|
const io = repoReader(root);
|
|
225
225
|
const read = (rel) => {
|
|
226
|
-
if (!io.inside(rel)) throw
|
|
226
|
+
if (!io.inside(rel)) throw outsideError(rel);
|
|
227
227
|
return fs.readFileSync(path.join(root, rel), 'utf8');
|
|
228
228
|
};
|
|
229
229
|
const exists = (rel) => io.inside(rel) && io.exists(rel);
|
package/plugins/openapi/index.js
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
* hand-written page under that app is removed. YAML needs the optional dependency js-yaml.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import { fileOptionProblem } from '../../core/repo.js';
|
|
29
|
+
import { quote } from '../../core/text.js';
|
|
29
30
|
|
|
30
31
|
const SPEC_FILE = /(?:^|\/)(?:openapi|swagger|[\w.-]+\.openapi|opencollection)\.(?:json|ya?ml)$/i;
|
|
31
32
|
const METHOD_ORDER = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'TRACE'];
|
|
@@ -130,9 +131,13 @@ export function specKind(doc) {
|
|
|
130
131
|
|
|
131
132
|
/** The specs to read: `[{ file, app, prefix }]` */
|
|
132
133
|
function specsOf(ctx, options, warnings, problems) {
|
|
133
|
-
const inRepo = (
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
const inRepo = (option) => (s) => {
|
|
135
|
+
const bad = fileOptionProblem(ctx, 'openapi', option, s.file);
|
|
136
|
+
if (bad) problems.push(bad);
|
|
137
|
+
return !bad;
|
|
138
|
+
};
|
|
139
|
+
if (Array.isArray(options.specs)) return options.specs.map((s) => ({ app: DEFAULT_APP, ...s })).filter(inRepo('specs[].file'));
|
|
140
|
+
if (typeof options.file === 'string') return [{ file: options.file, app: options.app || DEFAULT_APP, prefix: options.prefix }].filter(inRepo('file'));
|
|
136
141
|
const found = ctx.walk('', (f) => SPEC_FILE.test(f));
|
|
137
142
|
if (found.length > 1) {
|
|
138
143
|
warnings.push(`openapi: ${found.length} API description files (${found.join(', ')}); name the ones to draw: { use: 'openapi', options: { specs: [{ file, app }] } }.`);
|
|
@@ -157,7 +162,7 @@ const openapi = {
|
|
|
157
162
|
const mapNodes = (ctx.map && ctx.map.nodes) || [];
|
|
158
163
|
let yaml;
|
|
159
164
|
for (const spec of specs) {
|
|
160
|
-
if (!spec.file || !ctx.exists(spec.file)) throw new Error(`API description ${spec.file} does not exist.`);
|
|
165
|
+
if (!spec.file || !ctx.exists(spec.file)) throw new Error(`API description ${quote(spec.file)} does not exist.`);
|
|
161
166
|
const text = ctx.read(spec.file);
|
|
162
167
|
let doc;
|
|
163
168
|
if (/\.json$/i.test(spec.file)) {
|
package/plugins/starter/index.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
import { LANGUAGES, TEST_FILES, docSummary, expandMembers, goImports, goManifest, goWorkDirs, manifestLanguage, pyName, pythonImports, pythonManifest, rustManifest, rustName, rustUses } from './languages.js';
|
|
38
|
-
import { leavesRepo, outsideProblem } from '../../core/repo.js';
|
|
38
|
+
import { eachPlaceOnce, leavesRepo, outsideProblem } from '../../core/repo.js';
|
|
39
39
|
|
|
40
40
|
const DEFAULT_EXTENSIONS = LANGUAGES.js.extensions;
|
|
41
41
|
const TEST_DIRS = new Set(['test', 'tests', '__tests__', '__fixtures__', 'fixtures']);
|
|
@@ -97,7 +97,7 @@ function expandPatterns(patterns, io) {
|
|
|
97
97
|
for (const name of io.list(base)) if (!name.startsWith('.') && io.isDir(`${base}/${name}`)) dirs.push(`${base}/${name}`);
|
|
98
98
|
} else if (io.isDir(p)) dirs.push(p);
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return eachPlaceOnce(dirs).sort(); // one place once, however it is spelled (`''` and `.` are the repo itself)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
const readJson = (io, rel) => {
|
package/plugins/world/index.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
import { slug } from '../compose/index.js';
|
|
36
|
-
import {
|
|
36
|
+
import { fileOptionProblem } from '../../core/repo.js';
|
|
37
37
|
|
|
38
38
|
export const WORLD_FILE = 'stacks/world.json';
|
|
39
39
|
const FILE_KEYS = ['version', 'hosts', 'runs'];
|
|
@@ -64,7 +64,8 @@ const world = {
|
|
|
64
64
|
const options = ctx.options || {};
|
|
65
65
|
const file = options.file || WORLD_FILE;
|
|
66
66
|
const parent = options.parent || 'root';
|
|
67
|
-
|
|
67
|
+
const refused = fileOptionProblem(ctx, 'world', 'file', file);
|
|
68
|
+
if (refused) return { nodes: [], edges: [], warnings: [], problems: [refused], info: { machines: [] } };
|
|
68
69
|
if (!ctx.exists(file)) return { nodes: [], edges: [], warnings: [], problems: [], info: { machines: [] } };
|
|
69
70
|
|
|
70
71
|
let doc;
|