@prestack/thread 0.0.3 → 0.1.1
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/CHANGELOG.md +310 -0
- package/dist/core/{asking.d.ts → answers.d.ts} +6 -14
- package/dist/core/{asking.js → answers.js} +13 -332
- package/dist/core/{asking.ts → answers.ts} +14 -357
- package/dist/core/attach.js +2 -2
- package/dist/core/attach.ts +2 -3
- package/dist/core/chain.js +4 -11
- package/dist/core/chain.ts +4 -3
- package/dist/core/client.d.ts +57 -0
- package/dist/core/client.js +243 -0
- package/dist/core/client.ts +279 -0
- package/dist/core/descend.d.ts +2 -0
- package/dist/core/descend.js +109 -16
- package/dist/core/descend.ts +120 -16
- package/dist/core/files.d.ts +45 -0
- package/dist/core/files.js +145 -0
- package/dist/core/files.ts +193 -0
- package/dist/core/init.d.ts +1 -0
- package/dist/core/init.js +10 -2
- package/dist/core/init.ts +8 -2
- package/dist/core/invoked.js +1 -1
- package/dist/core/invoked.ts +1 -1
- package/dist/core/rows.d.ts +2 -0
- package/dist/core/rows.js +65 -0
- package/dist/core/rows.ts +58 -0
- package/dist/core/tree.js +1 -1
- package/dist/core/tree.ts +1 -1
- package/dist/derivation/attach.js +0 -12
- package/dist/derivation/attach.ts +0 -12
- package/dist/derivation/generators/build.js +8 -7
- package/dist/derivation/generators/build.ts +8 -7
- package/dist/derivation/generators/release.d.ts +1 -1
- package/dist/derivation/generators/release.js +15 -23
- package/dist/derivation/generators/release.ts +15 -15
- package/dist/integrations/attach.js +1 -19
- package/dist/integrations/attach.ts +1 -19
- package/dist/integrations/generators/read.js +2 -2
- package/dist/integrations/generators/read.ts +4 -4
- package/dist/integrations/generators/vault.js +4 -12
- package/dist/integrations/generators/vault.ts +4 -4
- package/dist/integrations/module.js +5 -3
- package/dist/integrations/module.ts +5 -3
- package/dist/integrations/vault.js +5 -5
- package/dist/integrations/vault.ts +5 -5
- package/dist/integrity/attach.js +0 -12
- package/dist/integrity/attach.ts +0 -12
- package/dist/integrity/check-threads.js +1 -1
- package/dist/integrity/check-threads.ts +1 -1
- package/dist/integrity/constraint.d.ts +11 -2
- package/dist/integrity/constraint.js +163 -20
- package/dist/integrity/constraint.ts +174 -22
- package/dist/integrity/generators/compiler.js +7 -1
- package/dist/integrity/generators/compiler.ts +10 -1
- package/dist/integrity/generators/gate.js +23 -18
- package/dist/integrity/generators/gate.ts +29 -9
- package/dist/integrity/generators/publish.js +14 -26
- package/dist/integrity/generators/publish.ts +14 -17
- package/dist/integrity/generators/trial.d.ts +2 -2
- package/dist/integrity/generators/trial.js +108 -50
- package/dist/integrity/generators/trial.ts +107 -48
- package/dist/integrity/lint.js +3 -3
- package/dist/integrity/lint.ts +3 -3
- package/dist/integrity/lsp/diagnostics.js +1 -1
- package/dist/integrity/lsp/diagnostics.ts +1 -1
- package/dist/integrity/lsp/lint.js +1 -1
- package/dist/integrity/lsp/lint.ts +1 -1
- package/dist/integrity/slopnator.d.ts +1 -14
- package/dist/integrity/slopnator.js +8 -40
- package/dist/integrity/slopnator.ts +9 -51
- package/dist/integrity/slopnators/sl_broken_lineage.js +4 -2
- package/dist/integrity/slopnators/sl_broken_lineage.ts +4 -2
- package/dist/integrity/slopnators/sl_declared_elsewhere.js +24 -3
- package/dist/integrity/slopnators/sl_declared_elsewhere.ts +24 -3
- package/dist/integrity/slopnators/sl_derived_drift.js +10 -4
- package/dist/integrity/slopnators/sl_derived_drift.ts +10 -4
- package/dist/integrity/slopnators/sl_inert_island.js +7 -13
- package/dist/integrity/slopnators/sl_inert_island.ts +7 -16
- package/dist/integrity/slopnators/sl_inert_slopnator.js +8 -8
- package/dist/integrity/slopnators/sl_inert_slopnator.ts +8 -8
- package/dist/integrity/slopnators/sl_missing_row.js +14 -9
- package/dist/integrity/slopnators/sl_missing_row.ts +14 -10
- package/dist/integrity/slopnators/sl_no_child_process.js +8 -8
- package/dist/integrity/slopnators/sl_no_child_process.ts +8 -8
- package/dist/integrity/slopnators/sl_no_import_cycle.js +1 -1
- package/dist/integrity/slopnators/sl_no_import_cycle.ts +1 -1
- package/dist/integrity/slopnators/sl_no_such_command.js +20 -5
- package/dist/integrity/slopnators/sl_no_such_command.ts +22 -5
- package/dist/integrity/slopnators/sl_only_takes_a_literal.js +8 -8
- package/dist/integrity/slopnators/sl_only_takes_a_literal.ts +8 -8
- package/dist/integrity/slopnators/sl_stale_path.js +91 -18
- package/dist/integrity/slopnators/sl_stale_path.ts +97 -18
- package/dist/integrity/slopnators/sl_twice_meant.js +25 -2
- package/dist/integrity/slopnators/sl_twice_meant.ts +28 -2
- package/dist/integrity/slopnators/sl_twice_parented.js +26 -5
- package/dist/integrity/slopnators/sl_twice_parented.ts +26 -5
- package/dist/integrity/slopnators/sl_undeclared_node.js +18 -2
- package/dist/integrity/slopnators/sl_undeclared_node.ts +18 -2
- package/dist/integrity/slopnators/sl_undeclared_operation.js +3 -1
- package/dist/integrity/slopnators/sl_undeclared_operation.ts +3 -1
- package/dist/integrity/slopnators/sl_undeclared_variant.js +6 -2
- package/dist/integrity/slopnators/sl_undeclared_variant.ts +6 -2
- package/dist/integrity/slopnators/sl_ungoverned_island.js +3 -4
- package/dist/integrity/slopnators/sl_ungoverned_island.ts +3 -4
- package/dist/integrity/slopnators/sl_unkept_rows.js +1 -1
- package/dist/integrity/slopnators/sl_unkept_rows.ts +1 -1
- package/dist/integrity/slopnators/sl_unpaired_member.js +13 -8
- package/dist/integrity/slopnators/sl_unpaired_member.ts +16 -8
- package/dist/integrity/slopnators/sl_unpaired_slopnator.js +16 -3
- package/dist/integrity/slopnators/sl_unpaired_slopnator.ts +16 -3
- package/dist/integrity/slopnators/sl_unthreaded.d.ts +1 -0
- package/dist/integrity/slopnators/sl_unthreaded.js +18 -10
- package/dist/integrity/slopnators/sl_unthreaded.ts +19 -11
- package/dist/integrity/slopnators/sl_untranslated_key.js +1 -1
- package/dist/integrity/slopnators/sl_untranslated_key.ts +1 -1
- package/dist/integrity/slopnators/sl_unversioned.js +16 -2
- package/dist/integrity/slopnators/sl_unversioned.ts +16 -2
- package/dist/integrity/sweep.js +17 -3
- package/dist/integrity/sweep.ts +20 -3
- package/dist/knowledge/attach.js +0 -6
- package/dist/knowledge/attach.ts +0 -6
- package/dist/knowledge/generators/docsgen.js +12 -3
- package/dist/knowledge/generators/docsgen.ts +12 -2
- package/dist/knowledge/generators/glossary.js +1 -1
- package/dist/knowledge/generators/glossary.ts +1 -1
- package/dist/operations/attach.js +2 -26
- package/dist/operations/attach.ts +2 -27
- package/dist/operations/dispatch.js +2 -3
- package/dist/operations/dispatch.ts +2 -3
- package/dist/operations/generators/capability.js +4 -7
- package/dist/operations/generators/capability.ts +3 -6
- package/dist/operations/generators/compile.js +8 -13
- package/dist/operations/generators/compile.ts +8 -4
- package/dist/operations/generators/permits.js +4 -13
- package/dist/operations/generators/permits.ts +3 -3
- package/dist/operations/generators/seed.js +5 -2
- package/dist/operations/generators/seed.ts +6 -2
- package/dist/operations/generators/trial.js +10 -10
- package/dist/operations/generators/trial.ts +10 -10
- package/dist/operations/http.js +4 -1
- package/dist/operations/http.ts +6 -1
- package/package.json +2 -2
- package/dist/core/cli.d.ts +0 -2
- package/dist/core/cli.js +0 -1761
- package/dist/core/cli.ts +0 -2004
- package/dist/core/generators/meta.d.ts +0 -2
- package/dist/core/generators/meta.js +0 -829
- package/dist/core/generators/meta.ts +0 -1006
- package/dist/derivation/generators/derivation.d.ts +0 -3
- package/dist/derivation/generators/derivation.js +0 -273
- package/dist/derivation/generators/derivation.ts +0 -347
- package/dist/derivation/makers/release.d.ts +0 -1
- package/dist/derivation/makers/release.js +0 -107
- package/dist/derivation/makers/release.ts +0 -135
- package/dist/integrations/generators/secret.d.ts +0 -1
- package/dist/integrations/generators/secret.js +0 -233
- package/dist/integrations/generators/secret.ts +0 -289
- package/dist/integrations/generators/target.d.ts +0 -1
- package/dist/integrations/generators/target.js +0 -775
- package/dist/integrations/generators/target.ts +0 -944
- package/dist/integrity/generators/rule.d.ts +0 -2
- package/dist/integrity/generators/rule.js +0 -213
- package/dist/integrity/generators/rule.ts +0 -271
- package/dist/integrity/generators/seal.d.ts +0 -4
- package/dist/integrity/generators/seal.js +0 -101
- package/dist/integrity/generators/seal.ts +0 -117
- package/dist/integrity/sealed.d.ts +0 -1
- package/dist/integrity/sealed.js +0 -56
- package/dist/integrity/sealed.ts +0 -56
- package/dist/knowledge/generators/skills.d.ts +0 -1
- package/dist/knowledge/generators/skills.js +0 -222
- package/dist/knowledge/generators/skills.ts +0 -263
- package/dist/operations/generators/grant.d.ts +0 -1
- package/dist/operations/generators/grant.js +0 -267
- package/dist/operations/generators/grant.ts +0 -336
- package/dist/operations/generators/operation.d.ts +0 -1
- package/dist/operations/generators/operation.js +0 -811
- package/dist/operations/generators/operation.ts +0 -972
- package/dist/operations/makers/capability.d.ts +0 -1
- package/dist/operations/makers/capability.js +0 -117
- package/dist/operations/makers/capability.ts +0 -166
- package/dist/operations/makers/trial.d.ts +0 -1
- package/dist/operations/makers/trial.js +0 -413
- package/dist/operations/makers/trial.ts +0 -520
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { spawnSync } from 'node:child_process';
|
|
10
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
-
import { relative, resolve } from 'node:path';
|
|
12
|
-
import { exit, stderr, stdout } from 'node:process';
|
|
13
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
|
-
import { answer, asking, given, only, refuse, slug, wordsIn } from "../../core/asking.js";
|
|
15
|
-
import { generators, settling } from "../../core/chain.js";
|
|
16
|
-
import { descend, shapeFields } from "../../core/descend.js";
|
|
17
|
-
import { listBounds, withRow } from "../../core/rows.js";
|
|
18
|
-
import { findTree, inTree } from "../../core/tree.js";
|
|
19
|
-
import { PUBLIC_ROLE } from "../../core/actor.js";
|
|
20
|
-
import { declaredWords, undeclared } from "../access.js";
|
|
21
|
-
import { operations, types } from "../generators/seed.js";
|
|
22
|
-
const TREE = findTree();
|
|
23
|
-
const SCENARIOS = 'SCENARIOS';
|
|
24
|
-
import { quoted } from "../../core/rows.js";
|
|
25
|
-
async function sheet(file, list) {
|
|
26
|
-
const at = inTree(TREE, file);
|
|
27
|
-
if (!existsSync(at))
|
|
28
|
-
return [];
|
|
29
|
-
try {
|
|
30
|
-
const held = (await import(__rewriteRelativeImportExtension(pathToFileURL(at).href)));
|
|
31
|
-
return held[list] ?? [];
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const pass = descend();
|
|
38
|
-
const known = types(pass);
|
|
39
|
-
const declared = [...operations(pass, known)]
|
|
40
|
-
.map(([id, one]) => {
|
|
41
|
-
const takes = one.takes[0]?.at;
|
|
42
|
-
if (takes === undefined || one.body === undefined)
|
|
43
|
-
return undefined;
|
|
44
|
-
return {
|
|
45
|
-
id,
|
|
46
|
-
describes: pass.stated.get(id)?.describes ?? '',
|
|
47
|
-
requires: one.requires,
|
|
48
|
-
takes,
|
|
49
|
-
body: one.body,
|
|
50
|
-
};
|
|
51
|
-
})
|
|
52
|
-
.filter((one) => one !== undefined)
|
|
53
|
-
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
54
|
-
if (declared.length === 0) {
|
|
55
|
-
refuse('this app declares no compiled operation, so there is nothing to run. Make one with `thread create operation`.');
|
|
56
|
-
}
|
|
57
|
-
async function scenarios(takes) {
|
|
58
|
-
const at = resolve(TREE.at, takes);
|
|
59
|
-
if (!existsSync(at))
|
|
60
|
-
return [];
|
|
61
|
-
try {
|
|
62
|
-
const held = (await import(__rewriteRelativeImportExtension(pathToFileURL(at).href)));
|
|
63
|
-
return held.SCENARIOS ?? [];
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const already = new Map();
|
|
70
|
-
for (const one of declared)
|
|
71
|
-
already.set(one.id, await scenarios(one.takes));
|
|
72
|
-
const listing = [
|
|
73
|
-
`${String(declared.length)} operation(s):`,
|
|
74
|
-
...declared.flatMap((one) => {
|
|
75
|
-
const mine = already.get(one.id) ?? [];
|
|
76
|
-
return [
|
|
77
|
-
` ${one.id} — ${one.describes}`,
|
|
78
|
-
` requires ${one.requires.join(', ') || 'nothing'}`,
|
|
79
|
-
` ${mine.length === 0 ? 'no scenario yet — nothing has ever run it' : `tried with ${mine.map((each) => each.id).join(', ')}`}`,
|
|
80
|
-
];
|
|
81
|
-
}),
|
|
82
|
-
].join('\n');
|
|
83
|
-
const entities = await sheet('entities.ts', 'ENTITIES');
|
|
84
|
-
const keyIn = (one) => (one.must ?? []).flatMap((each) => (each.unique?.length === 1 ? [each.unique[0]] : []))[0];
|
|
85
|
-
const wordsFrom = (held) => {
|
|
86
|
-
if (typeof held === 'string')
|
|
87
|
-
return [held];
|
|
88
|
-
if (Array.isArray(held))
|
|
89
|
-
return held.filter((each) => typeof each === 'string');
|
|
90
|
-
return [];
|
|
91
|
-
};
|
|
92
|
-
const casting = entities.flatMap((one) => {
|
|
93
|
-
const said = one.actor;
|
|
94
|
-
const key = keyIn(one);
|
|
95
|
-
if (said === undefined || key === undefined)
|
|
96
|
-
return [];
|
|
97
|
-
return (one.rows ?? []).flatMap((row) => {
|
|
98
|
-
const named = row[key];
|
|
99
|
-
if (typeof named !== 'string')
|
|
100
|
-
return [];
|
|
101
|
-
return [
|
|
102
|
-
{
|
|
103
|
-
id: named,
|
|
104
|
-
entity: one.id,
|
|
105
|
-
roles: wordsFrom(row[said.roles]),
|
|
106
|
-
entitlements: said.entitlements === undefined ? [] : wordsFrom(row[said.entitlements]),
|
|
107
|
-
},
|
|
108
|
-
];
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
const callers = casting.map((one) => ` ${one.id} — a ${one.entity}, ${one.roles.join(' and ') || 'holding no role'}` +
|
|
112
|
-
`${one.entitlements.length === 0 ? '' : `, entitled to ${one.entitlements.join(' and ')}`}`);
|
|
113
|
-
const seedable = entities.flatMap((one) => {
|
|
114
|
-
const key = keyIn(one);
|
|
115
|
-
if (key === undefined)
|
|
116
|
-
return [];
|
|
117
|
-
return (one.rows ?? []).flatMap((row) => {
|
|
118
|
-
const named = row[key];
|
|
119
|
-
return typeof named === 'string' ? [{ id: named, entity: one.id, row }] : [];
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
const words = wordsIn([]);
|
|
123
|
-
stdout.write(`${listing}\n`);
|
|
124
|
-
const SAYS = new Map([
|
|
125
|
-
['id', 'what to call this scenario'],
|
|
126
|
-
['describes', 'what this scenario is, in one sentence somebody who has not seen it could act on'],
|
|
127
|
-
['input', 'the input to run the operation with, as JSON — blank for {}'],
|
|
128
|
-
['actor', 'who is running it — name a declared row of an entity that says who its callers are'],
|
|
129
|
-
['rows', 'rows this starts from — name declared rows, comma separated, blank for an empty store'],
|
|
130
|
-
['answers', 'what each declared call answers with — a call nothing answers gets a 404'],
|
|
131
|
-
]);
|
|
132
|
-
const SCENARIO = fileURLToPath(new URL('../generators/trial.ts', import.meta.url));
|
|
133
|
-
const SHAPE = shapeFields('Scenario', relative(TREE.at, SCENARIO).split('\\').join('/'));
|
|
134
|
-
if (SHAPE.length === 0) {
|
|
135
|
-
refuse('the shape of a scenario could not be read, so what this command may ask for is unknown. Asking anyway ' +
|
|
136
|
-
'would write a row against a shape nothing checked — which is how a scenario ends up stating fields no ' +
|
|
137
|
-
'trial reads, and fields the runner reads that nothing ever wrote.');
|
|
138
|
-
}
|
|
139
|
-
const ASKS = SHAPE.filter((one) => SAYS.has(one.name)).map((one) => ({ key: one.name, says: SAYS.get(one.name) ?? '' }));
|
|
140
|
-
const UNASKED = SHAPE.filter((one) => !SAYS.has(one.name)).map((one) => one.name);
|
|
141
|
-
const TAKES = ASKS.map((one) => one.key);
|
|
142
|
-
const ASKED = ASKS.map((one) => ` ${`${one.key}:`.padEnd(16)}${one.says}`);
|
|
143
|
-
const method = () => [
|
|
144
|
-
'',
|
|
145
|
-
'what this runs:',
|
|
146
|
-
'',
|
|
147
|
-
' thread run trial <operation>',
|
|
148
|
-
'',
|
|
149
|
-
'it takes, as a flag on one command:',
|
|
150
|
-
'',
|
|
151
|
-
` thread run trial <operation> --<answer> <value> ... `,
|
|
152
|
-
'',
|
|
153
|
-
'That form needs no terminal, which is what makes it the one that always works. One answer to a',
|
|
154
|
-
'line on stdin does the same, and so does a file of them named by `--answers <path>`.',
|
|
155
|
-
'',
|
|
156
|
-
'the answers:',
|
|
157
|
-
'',
|
|
158
|
-
...ASKED,
|
|
159
|
-
'',
|
|
160
|
-
'It asks for the input to try the operation with, checks it against that operation\'s own schema',
|
|
161
|
-
'before writing anything, adds the scenario to the file the operation already takes, and then runs',
|
|
162
|
-
'`thread trials` — which hands the compiled function to this app\'s own dispatch and records',
|
|
163
|
-
'everything the run did.',
|
|
164
|
-
'',
|
|
165
|
-
'DO NOT INVENT A CALLER. `actor` names a row this app already declares, and the roles and',
|
|
166
|
-
'entitlements that row holds are read off it. There is no field here for typing a role, because a',
|
|
167
|
-
'role is one of the options on the column an entity names as saying what its callers may do — the',
|
|
168
|
-
'app declares the closed set and this command holds you to it. Naming somebody who is not declared',
|
|
169
|
-
'is refused, and the refusal lists who IS. Blank leaves the scenario with no actor at all, which is',
|
|
170
|
-
'the right answer for an operation anybody may run, and the wrong one for an operation with a grant.',
|
|
171
|
-
'',
|
|
172
|
-
'Same for `rows`. Name rows the entities already declare. A store put into a state nobody declared',
|
|
173
|
-
'is a trial proving something about data that does not exist anywhere else in this app.',
|
|
174
|
-
'',
|
|
175
|
-
...(callers.length === 0
|
|
176
|
-
? [
|
|
177
|
-
'This app declares no entity that says who its callers are, so there is nobody to name and every',
|
|
178
|
-
'scenario here runs anonymous. An entity says so by naming the column its roles come from.',
|
|
179
|
-
'',
|
|
180
|
-
]
|
|
181
|
-
: ['who this app declares as callers:', '', ...callers, '']),
|
|
182
|
-
'An operation that reaches a declared target is asked one more thing: what each of its calls',
|
|
183
|
-
'answers with. That is the only part of an outward call nothing can derive — the verb, the path,',
|
|
184
|
-
'the address and the credential all come off rows. A call nothing answers gets a 404, which is a',
|
|
185
|
-
'real answer about an operation that did not handle one.',
|
|
186
|
-
'',
|
|
187
|
-
'Running it again with the same operation adds another scenario rather than replacing one. A',
|
|
188
|
-
'recording is evidence, and evidence is not overwritten because somebody ran the command twice.',
|
|
189
|
-
...(UNASKED.length === 0
|
|
190
|
-
? []
|
|
191
|
-
: [
|
|
192
|
-
'',
|
|
193
|
-
`A scenario also states ${UNASKED.join(', ')}, and this command cannot write ${UNASKED.length === 1 ? 'it' : 'them'}.`,
|
|
194
|
-
'The trial runner reads what is there. Nothing here can put it there, so no scenario this command',
|
|
195
|
-
'writes will ever carry one — said out loud because a field nobody can reach reads as a field',
|
|
196
|
-
'nobody needs, and that is how four of them sat unwritable without anyone noticing.',
|
|
197
|
-
]),
|
|
198
|
-
].join('\n');
|
|
199
|
-
const which = words[0];
|
|
200
|
-
if (which === undefined) {
|
|
201
|
-
stdout.write(`${method()}\n`);
|
|
202
|
-
exit(1);
|
|
203
|
-
}
|
|
204
|
-
const one = declared.find((each) => each.id === which);
|
|
205
|
-
if (one === undefined) {
|
|
206
|
-
refuse(`\`${which}\` is not a compiled operation of this app. What is here is ${declared.map((each) => each.id).join(', ')}`);
|
|
207
|
-
}
|
|
208
|
-
const from = resolve(TREE.at, one.takes);
|
|
209
|
-
if (!existsSync(from)) {
|
|
210
|
-
refuse(`\`${one.id}\` takes ${one.takes} and that file is not there. Run \`thread seed\`.`);
|
|
211
|
-
}
|
|
212
|
-
const taking = (await import(__rewriteRelativeImportExtension(pathToFileURL(from).href)));
|
|
213
|
-
const schema = taking.input;
|
|
214
|
-
if (schema === undefined) {
|
|
215
|
-
refuse(`${one.takes} exports no \`input\`, so nothing states what \`${one.id}\` takes. Run \`thread seed\`.`);
|
|
216
|
-
}
|
|
217
|
-
const targets = await sheet('targets.ts', 'TARGETS');
|
|
218
|
-
const calls = await sheet('targets.ts', 'CALLS');
|
|
219
|
-
const reachable = targets
|
|
220
|
-
.filter((each) => one.requires.includes(each.id))
|
|
221
|
-
.flatMap((each) => calls.filter((call) => call.of === each.id && each.takes.includes(call.id)));
|
|
222
|
-
const piped = given();
|
|
223
|
-
only(piped, TAKES, 'a trial');
|
|
224
|
-
const { ask, shut } = asking(piped);
|
|
225
|
-
const mine = already.get(one.id) ?? [];
|
|
226
|
-
const suggested = `s${String(mine.length + 1)}`;
|
|
227
|
-
const named = slug(piped.length > 0 ? (answer(piped, 'id') ?? suggested) : (await ask('id', `what to call this scenario (blank for "${suggested}"): `)) || suggested);
|
|
228
|
-
if (mine.some((each) => each.id === named)) {
|
|
229
|
-
shut();
|
|
230
|
-
refuse(`\`${one.id}\` already has a scenario called \`${named}\`, and a trial is named after the one it ran`);
|
|
231
|
-
}
|
|
232
|
-
const meaning = (piped.length > 0
|
|
233
|
-
? (answer(piped, 'describes') ?? '')
|
|
234
|
-
: await ask('describes', 'what this scenario is, in one sentence: ')).trim();
|
|
235
|
-
if (meaning === '') {
|
|
236
|
-
shut();
|
|
237
|
-
refuse(`a scenario states what it is, and \`${named}\` is only a name. Every declared thing here carries a ` +
|
|
238
|
-
'`describes`, because the word on its own tells the next person nothing about which scenario they are ' +
|
|
239
|
-
'looking at or why it was worth recording. Say what world this run is given and what it is meant to show.');
|
|
240
|
-
}
|
|
241
|
-
const typed = (piped.length > 0
|
|
242
|
-
? (answer(piped, 'input') ?? '')
|
|
243
|
-
: await ask('input', `the input to run ${one.id} with, as JSON (blank for {}): `)).trim();
|
|
244
|
-
let value;
|
|
245
|
-
try {
|
|
246
|
-
value = typed === '' ? {} : JSON.parse(typed);
|
|
247
|
-
}
|
|
248
|
-
catch (thrown) {
|
|
249
|
-
shut();
|
|
250
|
-
refuse(`that is not JSON: ${thrown instanceof Error ? thrown.message : String(thrown)}. Nothing was written.`);
|
|
251
|
-
}
|
|
252
|
-
const held = schema.safeParse(value);
|
|
253
|
-
if (!held.success) {
|
|
254
|
-
shut();
|
|
255
|
-
refuse(`\`${one.id}\` would refuse that input, so a trial of it would record a refusal and prove nothing: ` +
|
|
256
|
-
`${JSON.stringify(held.error)}. Nothing was written.`);
|
|
257
|
-
}
|
|
258
|
-
const listed = (said) => said
|
|
259
|
-
.split(',')
|
|
260
|
-
.map((one) => one.trim())
|
|
261
|
-
.filter((one) => one !== '');
|
|
262
|
-
const running = (piped.length > 0
|
|
263
|
-
? (answer(piped, 'actor') ?? '')
|
|
264
|
-
: await ask('actor', 'who is running it — name a declared row (blank for nobody, which is anonymous): ')).trim();
|
|
265
|
-
if (running !== '' && casting.length === 0) {
|
|
266
|
-
shut();
|
|
267
|
-
refuse(`this app declares nobody to run \`${one.id}\` as. An entity says who its callers are by naming the ` +
|
|
268
|
-
'column its roles come from, and then declaring rows on it. Until one does, every scenario here runs ' +
|
|
269
|
-
'anonymous, and naming somebody would be inventing them.');
|
|
270
|
-
}
|
|
271
|
-
const played = casting.find((each) => each.id === running);
|
|
272
|
-
if (running !== '' && played === undefined) {
|
|
273
|
-
shut();
|
|
274
|
-
refuse(`this app declares no caller called \`${running}\` — it declares ` +
|
|
275
|
-
`${casting.map((each) => `\`${each.id}\``).join(', ')}. A caller is a row an entity declares, not a name ` +
|
|
276
|
-
'to type here: the roles it holds are read off that row, so somebody invented at this prompt would carry ' +
|
|
277
|
-
'roles this app never granted and the trial would prove access that does not exist.');
|
|
278
|
-
}
|
|
279
|
-
if (played !== undefined) {
|
|
280
|
-
for (const which of ['roles', 'entitlements']) {
|
|
281
|
-
const wrong = undeclared(played[which].join(','), declaredWords(entities, which, PUBLIC_ROLE), which);
|
|
282
|
-
if (wrong !== undefined) {
|
|
283
|
-
shut();
|
|
284
|
-
refuse(`\`${played.id}\` is a declared row of \`${played.entity}\` and ${wrong}. The row holds a word its own ` +
|
|
285
|
-
'column does not offer, so running as it would prove access against a role this app never declared. ' +
|
|
286
|
-
'Fix the row, not the scenario. Nothing was written.');
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
const actor = played === undefined
|
|
291
|
-
? undefined
|
|
292
|
-
: { id: played.id, roles: [...played.roles], entitlements: [...played.entitlements] };
|
|
293
|
-
const seeded = (piped.length > 0
|
|
294
|
-
? (answer(piped, 'rows') ?? '')
|
|
295
|
-
: await ask('rows', 'rows this starts from — declared rows, comma separated, blank for an empty store: ')).trim();
|
|
296
|
-
const wanted = listed(seeded);
|
|
297
|
-
const stray = wanted.filter((each) => !seedable.some((one) => one.id === each));
|
|
298
|
-
if (stray.length > 0) {
|
|
299
|
-
shut();
|
|
300
|
-
refuse(`this app declares no row called ${stray.map((each) => `\`${each}\``).join(', ')} — ` +
|
|
301
|
-
(seedable.length === 0
|
|
302
|
-
? 'it declares none at all. A store starts from rows the entities themselves declare, so that what a ' +
|
|
303
|
-
'trial proves is about data this app really has. Declare them with `thread create entity edit`.'
|
|
304
|
-
: `it declares ${seedable.map((one) => `\`${one.id}\``).join(', ')}. Nothing was written.`));
|
|
305
|
-
}
|
|
306
|
-
const starting = wanted.flatMap((each) => {
|
|
307
|
-
const found = seedable.find((one) => one.id === each);
|
|
308
|
-
return found === undefined ? [] : [{ entity: found.entity, row: found.row }];
|
|
309
|
-
});
|
|
310
|
-
const answers = {};
|
|
311
|
-
if (piped.length > 0) {
|
|
312
|
-
const said = (answer(piped, 'answers') ?? '').trim();
|
|
313
|
-
if (said !== '') {
|
|
314
|
-
try {
|
|
315
|
-
Object.assign(answers, JSON.parse(said));
|
|
316
|
-
}
|
|
317
|
-
catch (thrown) {
|
|
318
|
-
shut();
|
|
319
|
-
refuse(`\`answers\` is not JSON: ${thrown instanceof Error ? thrown.message : String(thrown)}. Nothing was written.`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else if (reachable.length > 0) {
|
|
324
|
-
stdout.write(`\n${one.id} can make ${String(reachable.length)} declared call(s). What does each answer with?\n`);
|
|
325
|
-
for (const call of reachable) {
|
|
326
|
-
const key = `${call.method} ${call.path}`;
|
|
327
|
-
const status = (await ask('status', ` ${key} — status (blank to leave it unanswered, which is a 404): `)).trim();
|
|
328
|
-
if (status === '')
|
|
329
|
-
continue;
|
|
330
|
-
const code = Number(status);
|
|
331
|
-
if (!Number.isInteger(code) || code < 100 || code > 599) {
|
|
332
|
-
shut();
|
|
333
|
-
refuse(`"${status}" is not an HTTP status. Nothing was written.`);
|
|
334
|
-
}
|
|
335
|
-
const body = (await ask('body', ' body, as JSON or blank: ')).trim();
|
|
336
|
-
answers[key] = body === '' ? { status: code } : { status: code, body };
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
shut();
|
|
340
|
-
const row = [
|
|
341
|
-
' {',
|
|
342
|
-
` id: ${quoted(named)},`,
|
|
343
|
-
` describes: ${quoted(meaning)},`,
|
|
344
|
-
` input: ${JSON.stringify(value)},`,
|
|
345
|
-
...(actor === undefined ? [] : [` actor: ${JSON.stringify(actor)},`]),
|
|
346
|
-
...(starting.length === 0 ? [] : [` rows: ${JSON.stringify(starting)},`]),
|
|
347
|
-
...(Object.keys(answers).length === 0 ? [] : [` answers: ${JSON.stringify(answers)},`]),
|
|
348
|
-
' },',
|
|
349
|
-
].join('\n');
|
|
350
|
-
const SEEDED = 'export const input = z.unknown()';
|
|
351
|
-
const NAMEABLE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
352
|
-
function stated(value) {
|
|
353
|
-
if (typeof value === 'string')
|
|
354
|
-
return 'z.string()';
|
|
355
|
-
if (typeof value === 'number')
|
|
356
|
-
return 'z.number()';
|
|
357
|
-
if (typeof value === 'boolean')
|
|
358
|
-
return 'z.boolean()';
|
|
359
|
-
if (value === null)
|
|
360
|
-
return 'z.null()';
|
|
361
|
-
if (Array.isArray(value)) {
|
|
362
|
-
const first = value[0];
|
|
363
|
-
const of = first === undefined ? undefined : stated(first);
|
|
364
|
-
return of === undefined ? undefined : `z.array(${of})`;
|
|
365
|
-
}
|
|
366
|
-
if (typeof value !== 'object')
|
|
367
|
-
return undefined;
|
|
368
|
-
const parts = [];
|
|
369
|
-
for (const [key, held] of Object.entries(value)) {
|
|
370
|
-
const one = stated(held);
|
|
371
|
-
if (one === undefined)
|
|
372
|
-
return undefined;
|
|
373
|
-
parts.push(`${NAMEABLE.test(key) ? key : quoted(key)}: ${one}`);
|
|
374
|
-
}
|
|
375
|
-
return `z.object({ ${parts.join(', ')} })`;
|
|
376
|
-
}
|
|
377
|
-
function stating(text, value) {
|
|
378
|
-
const schema = stated(value);
|
|
379
|
-
if (schema === undefined || !text.includes(SEEDED))
|
|
380
|
-
return text;
|
|
381
|
-
return text.replace(SEEDED, `export const input = ${schema}`);
|
|
382
|
-
}
|
|
383
|
-
let text = readFileSync(from, 'utf8');
|
|
384
|
-
const bounds = listBounds(text, SCENARIOS);
|
|
385
|
-
if (bounds === undefined) {
|
|
386
|
-
text = `${text.trimEnd()}\n\nexport const ${SCENARIOS}: readonly Scenario[] = [\n${row}\n]\n`;
|
|
387
|
-
text = text.replace("import { z } from 'zod'\n", "import { z } from 'zod'\n\nimport type { Scenario } from '../generators/trial.ts'\n");
|
|
388
|
-
text = stating(text, value);
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
text = withRow(text, bounds, row);
|
|
392
|
-
}
|
|
393
|
-
writeFileSync(from, text, 'utf8');
|
|
394
|
-
stdout.write(`\ntrial: wrote scenario \`${named}\` into ${one.takes}.\n`);
|
|
395
|
-
const ran = spawnSync('npx', ['thread', 'trials'], { cwd: TREE.at, encoding: 'utf8' });
|
|
396
|
-
stdout.write(`${`${ran.stdout ?? ''}${ran.stderr ?? ''}`.trim()}\n`);
|
|
397
|
-
if (ran.status !== 0) {
|
|
398
|
-
stdout.write('trial: the recording was refused above. The scenario is written and stands.\n');
|
|
399
|
-
exit(1);
|
|
400
|
-
}
|
|
401
|
-
const checked = spawnSync('npx', ['thread', 'trials', '--check'], { cwd: TREE.at, encoding: 'utf8' });
|
|
402
|
-
stdout.write(`${`${checked.stdout ?? ''}${checked.stderr ?? ''}`.trim()}\n`);
|
|
403
|
-
if (checked.status !== 0)
|
|
404
|
-
exit(1);
|
|
405
|
-
const settled = settling(TREE.at, await generators(TREE), ['thread trials', 'thread run trial']);
|
|
406
|
-
for (const one of settled.ran)
|
|
407
|
-
stdout.write(`${one}\n`);
|
|
408
|
-
if (settled.unsettled.length > 0) {
|
|
409
|
-
stderr.write(`trial: the scenario is written and the run is recorded, and ${settled.unsettled.join(', ')} would not settle ` +
|
|
410
|
-
`after ${String(settled.rounds)} round(s). Run it yourself and read what it says.\n`);
|
|
411
|
-
exit(1);
|
|
412
|
-
}
|
|
413
|
-
exit(0);
|