@enspirit/opspicy 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -26
- package/bin/help.js +6 -1
- package/dist/configuration.d.ts +16 -1
- package/dist/explorer/api.js +4 -3
- package/dist/explorer/elo-refs.js +6 -3
- package/dist/explorer/index.js +1 -2
- package/dist/explorer/operation.js +2 -4
- package/dist/explorer/pages.js +9 -14
- package/dist/explorer/script/ranking.js +2 -2
- package/dist/explorer/wiki.js +1 -2
- package/dist/files.js +27 -16
- package/dist/judging.js +2 -34
- package/dist/main.js +1 -1
- package/dist/meaning.js +2 -2
- package/dist/modelling.js +99 -25
- package/dist/naming.js +44 -15
- package/dist/notation.js +18 -3
- package/dist/observing.js +112 -0
- package/dist/planning.js +3 -3
- package/dist/reach.js +244 -140
- package/dist/reading.js +14 -18
- package/dist/running.js +18 -8
- package/dist/starting.js +4 -3
- package/dist/suite.js +8 -1
- package/dist/upgrade.js +3 -9
- package/dist/upgrading-state.js +197 -0
- package/dist/upgrading.js +13 -2
- package/dist/variables.js +62 -0
- package/dist/world.js +12 -40
- package/package.json +1 -1
package/dist/reach.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
// What
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// nothing is run.
|
|
1
|
+
// What a case reads of the state, to judge it: the state variables that the formaldefs of its
|
|
2
|
+
// clauses read, before the call and after it, derived from the formaldefs alone (doc/derived.md).
|
|
3
|
+
// Nothing is said by the specification of what is read. Pure: Elo's parser reads each expression,
|
|
4
|
+
// and nothing is run.
|
|
5
5
|
//
|
|
6
|
-
// A
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
6
|
+
// A formaldef is followed as Elo would apply it, with what each name stands for in place of a
|
|
7
|
+
// value: a collection, one item of it by a key that is said, a variable that is no collection, or
|
|
8
|
+
// something of what the operation is given. So what is read is named as narrowly as it is said:
|
|
9
|
+
// `board(input.id).name` reads one attribute of one board, `count(boards)` which boards there are,
|
|
10
|
+
// `map(boards, b ~> b.count)` one attribute of every board, and `boards == old.boards` all of them.
|
|
11
|
+
// A predicate or a function reads what its formaldef reads, of what it is given.
|
|
12
|
+
//
|
|
13
|
+
// A variable is read at a moment, before the call or after it, and through a mechanism: the front
|
|
14
|
+
// door, as who calls or as somebody else (`seenBy.<actor>.`), or the database (`db.`).
|
|
10
15
|
import { parse } from '@enspirit/elo';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
16
|
+
import { TRIGGER, isBefore } from './suite.js';
|
|
17
|
+
import { unparsed } from './variables.js';
|
|
18
|
+
const UNKNOWN = { is: 'unknown' };
|
|
19
|
+
const given = (source, answered = false) => ({ is: 'given', source, answered });
|
|
20
|
+
const isGiven = (value) => value.is === 'given';
|
|
21
|
+
/** What may be a key: something given, or each of a list that is. */
|
|
22
|
+
const isKey = (value) => value.is === 'given' || value.is === 'each';
|
|
23
|
+
/** What Elo applies to each item of a list: what it gives then says how the list is read. */
|
|
24
|
+
const OVER = ['map', 'all', 'any', 'filter', 'find'];
|
|
15
25
|
function treeOf(text) {
|
|
16
26
|
try {
|
|
17
27
|
return parse(text);
|
|
@@ -21,157 +31,251 @@ function treeOf(text) {
|
|
|
21
31
|
return null;
|
|
22
32
|
}
|
|
23
33
|
}
|
|
24
|
-
/** The
|
|
25
|
-
export function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
34
|
+
/** The variables an expression reads, said at a moment: before the call (a precondition, an input), or after it (a postcondition, which reads before through `old`). */
|
|
35
|
+
export function readsOf(text, at, readable) {
|
|
36
|
+
const reads = new Map();
|
|
37
|
+
let whole = false;
|
|
38
|
+
const variables = new Map(readable.state.map((one) => [one.name, one]));
|
|
39
|
+
const items = new Map(readable.state.flatMap((one) => (one.item ? [[one.item.name, one]] : [])));
|
|
40
|
+
const words = new Map(readable.definitions.map((one) => [one.name, one]));
|
|
41
|
+
let depth = 0;
|
|
42
|
+
const read = (view, ref) => void reads.set(`${view.via} ${view.by ?? ''} ${view.when} ${JSON.stringify(ref)}`, { via: view.via, ...(view.by ? { by: view.by } : {}), when: view.when, ref });
|
|
43
|
+
/** A value that is used whole: everything it stands for is read. */
|
|
44
|
+
const used = (value) => {
|
|
45
|
+
if (value.is === 'collection')
|
|
46
|
+
(read(value.view, { variable: value.variable, of: 'whole' }), read(value.view, { variable: value.variable, of: 'every' }));
|
|
47
|
+
if (value.is === 'item')
|
|
48
|
+
read(value.view, value.key ? { variable: value.variable, of: 'item', key: value.key } : { variable: value.variable, of: 'every' });
|
|
49
|
+
if (value.is === 'value')
|
|
50
|
+
read(value.view, { variable: value.variable, of: 'whole' });
|
|
51
|
+
if (value.is === 'view' || value.is === 'seenBy' || value.is === 'observed')
|
|
52
|
+
whole = true;
|
|
53
|
+
};
|
|
54
|
+
/** A predicate or a function, applied to what it is given, as seen from where it is named. */
|
|
55
|
+
const said = (word, args, view) => {
|
|
56
|
+
const tree = depth < 32 ? treeOf(word.formaldef) : null;
|
|
57
|
+
if (!tree)
|
|
58
|
+
return UNKNOWN;
|
|
59
|
+
depth++;
|
|
60
|
+
const gives = follow(tree, new Map(word.parameters.map((name, at) => [name, args[at] ?? UNKNOWN])), view);
|
|
61
|
+
depth--;
|
|
62
|
+
// What reads no state is said by its name: `me`, not what `me` is made of.
|
|
63
|
+
if (!isGiven(gives) || !args.every(isGiven))
|
|
64
|
+
return gives;
|
|
65
|
+
return given(word.parameters.length ? `${word.name}(${args.map((one) => one.source).join(', ')})` : word.name, gives.answered || args.some((one) => one.answered));
|
|
41
66
|
};
|
|
42
|
-
/**
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
/** One item, by what it is known by: a key that reads no state, and that is known when the item is read. */
|
|
68
|
+
const itemOf = (collection, args, view) => {
|
|
69
|
+
for (const one of args)
|
|
70
|
+
used(one);
|
|
71
|
+
const keyed = args.length === collection.item.key.length && args.every(isKey) && !(view.when === 'before' && args.filter(isKey).some((one) => one.answered));
|
|
72
|
+
return { is: 'item', view, variable: collection.name, key: keyed ? args.filter(isKey).map((one) => one.source) : null };
|
|
73
|
+
};
|
|
74
|
+
/** What a name is, where it is said: a state variable, or a predicate or a function that is given nothing. */
|
|
75
|
+
const named = (name, view) => {
|
|
76
|
+
const variable = variables.get(name);
|
|
77
|
+
if (variable)
|
|
78
|
+
return { is: variable.item ? 'collection' : 'value', view, variable: name };
|
|
79
|
+
const word = words.get(name);
|
|
80
|
+
if (word && !word.parameters.length)
|
|
81
|
+
return said(word, [], view);
|
|
82
|
+
const collection = items.get(name);
|
|
83
|
+
// An item that is given no key is any of them.
|
|
84
|
+
if (collection)
|
|
85
|
+
return (used({ is: 'item', view, variable: collection.name, key: null }), UNKNOWN);
|
|
58
86
|
return null;
|
|
59
87
|
};
|
|
60
|
-
const
|
|
88
|
+
const variable = (name, scope, view) => {
|
|
89
|
+
const bound = scope.get(name);
|
|
90
|
+
if (bound)
|
|
91
|
+
return bound;
|
|
92
|
+
if (name === 'input' || name === 'world')
|
|
93
|
+
return given(name);
|
|
94
|
+
if (name === 'output')
|
|
95
|
+
return given(name, true);
|
|
96
|
+
if (name === 'old')
|
|
97
|
+
return { is: 'view', view: { ...view, when: 'before' } };
|
|
98
|
+
if (name === 'db')
|
|
99
|
+
return { is: 'view', view: { via: 'db', when: view.when } };
|
|
100
|
+
if (name === 'seenBy')
|
|
101
|
+
return { is: 'seenBy', view };
|
|
102
|
+
if (name === '_')
|
|
103
|
+
return { is: 'observed' };
|
|
104
|
+
if (name === 'nothingChanged')
|
|
105
|
+
whole = true;
|
|
106
|
+
return named(name, view) ?? UNKNOWN;
|
|
107
|
+
};
|
|
108
|
+
const member = (of, property) => {
|
|
109
|
+
switch (of.is) {
|
|
110
|
+
case 'view':
|
|
111
|
+
if (property === 'db')
|
|
112
|
+
return { is: 'view', view: { via: 'db', when: of.view.when } };
|
|
113
|
+
if (property === 'seenBy')
|
|
114
|
+
return { is: 'seenBy', view: of.view };
|
|
115
|
+
return named(property, of.view) ?? UNKNOWN;
|
|
116
|
+
case 'seenBy': return { is: 'view', view: { via: 'web', by: property, when: of.view.when } };
|
|
117
|
+
case 'observed':
|
|
118
|
+
if (property === 'before' || property === 'after')
|
|
119
|
+
return { is: 'view', view: { via: 'web', when: property } };
|
|
120
|
+
if (property === 'input' || property === 'world' || property === 'output')
|
|
121
|
+
return given(property, property === 'output');
|
|
122
|
+
whole = true;
|
|
123
|
+
return UNKNOWN;
|
|
124
|
+
case 'item': return (read(of.view, { variable: of.variable, of: of.key ? 'item' : 'every', ...(of.key ? { key: of.key } : {}), attribute: property }), UNKNOWN);
|
|
125
|
+
case 'value': return (read(of.view, { variable: of.variable, of: 'whole', attribute: property }), UNKNOWN);
|
|
126
|
+
case 'given': return given(`${of.source}.${property}`, of.answered);
|
|
127
|
+
default: return (used(of), UNKNOWN);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/** What a name gives when it is applied: an item by its key, a predicate or a function of what it is given. */
|
|
131
|
+
const applied = (name, args, view) => {
|
|
132
|
+
const collection = items.get(name);
|
|
133
|
+
if (collection)
|
|
134
|
+
return itemOf(collection, args, view);
|
|
135
|
+
const word = words.get(name);
|
|
136
|
+
return word ? said(word, args, view) : null;
|
|
137
|
+
};
|
|
138
|
+
/** `find(boards, b ~> b.id == input.id)`: the key such a lambda says, when it says the key of the item and nothing else. */
|
|
139
|
+
const keySaid = (lambda, collection, scope, view) => {
|
|
140
|
+
const state = variables.get(collection.variable);
|
|
141
|
+
// The database knows an item by columns of its own, in the order of the key.
|
|
142
|
+
const columns = collection.view.via === 'db' ? state.db?.key ?? [] : state.item.key;
|
|
143
|
+
const [item = ''] = lambda.params;
|
|
144
|
+
const parts = (node) => (node.type === 'binary' && node.operator === '&&' ? [...parts(node.left), ...parts(node.right)] : [node]);
|
|
145
|
+
const isColumn = (node) => (node.type === 'member_access' && node.object.type === 'variable' && node.object.name === item ? node.property : null);
|
|
146
|
+
const key = new Map();
|
|
147
|
+
for (const part of parts(lambda.body)) {
|
|
148
|
+
if (part.type !== 'binary' || part.operator !== '==')
|
|
149
|
+
return null;
|
|
150
|
+
const [column, other] = isColumn(part.left) ? [isColumn(part.left), part.right] : [isColumn(part.right), part.left];
|
|
151
|
+
if (!column || !columns.includes(column) || key.has(column) || mentions(other, item))
|
|
152
|
+
return null;
|
|
153
|
+
const value = follow(other, scope, view);
|
|
154
|
+
if (!isGiven(value) || (collection.view.when === 'before' && value.answered))
|
|
155
|
+
return null;
|
|
156
|
+
key.set(column, value.source);
|
|
157
|
+
}
|
|
158
|
+
return columns.length && key.size === columns.length ? columns.map((column) => key.get(column)) : null;
|
|
159
|
+
};
|
|
160
|
+
/** A function of Elo's: what it reads of a collection it is given follows from what it does with each item. */
|
|
161
|
+
const builtIn = (name, args, scope, view) => {
|
|
162
|
+
const [first, ...others] = args;
|
|
163
|
+
const of = first ? follow(first, scope, view) : UNKNOWN;
|
|
164
|
+
const lambda = others[0]?.type === 'lambda' ? others[0] : null;
|
|
165
|
+
if (of.is === 'collection' && name === 'count' && !others.length)
|
|
166
|
+
return (read(of.view, { variable: of.variable, of: 'whole' }), UNKNOWN);
|
|
167
|
+
if (of.is === 'collection' && lambda && others.length === 1 && OVER.includes(name)) {
|
|
168
|
+
const key = name === 'find' ? keySaid(lambda, of, scope, view) : null;
|
|
169
|
+
if (key)
|
|
170
|
+
return { is: 'item', view: of.view, variable: of.variable, key };
|
|
171
|
+
const each = new Map([...scope, ...lambda.params.map((param, at) => [param, at === 0 ? { is: 'item', view: of.view, variable: of.variable, key: null } : UNKNOWN])]);
|
|
172
|
+
used(follow(lambda.body, each, view));
|
|
173
|
+
return name === 'find' ? { is: 'item', view: of.view, variable: of.variable, key: null } : name === 'filter' ? of : UNKNOWN;
|
|
174
|
+
}
|
|
175
|
+
// Over a list that is given, a lambda names each of it: an item it reads by that is each of those items.
|
|
176
|
+
if (isGiven(of) && lambda && others.length === 1 && OVER.includes(name)) {
|
|
177
|
+
const each = new Map([...scope, ...lambda.params.map((param, at) => [param, at === 0 ? { is: 'each', source: of.source, answered: of.answered } : UNKNOWN])]);
|
|
178
|
+
used(follow(lambda.body, each, view));
|
|
179
|
+
return UNKNOWN;
|
|
180
|
+
}
|
|
181
|
+
const values = [of, ...others.map((one) => follow(one, scope, view))];
|
|
182
|
+
for (const one of values)
|
|
183
|
+
used(one);
|
|
184
|
+
return first && values.every(isGiven) ? given(`${name}(${values.map((one) => one.source).join(', ')})`, values.some((one) => one.answered)) : UNKNOWN;
|
|
185
|
+
};
|
|
186
|
+
const follow = (node, scope, view) => {
|
|
61
187
|
switch (node.type) {
|
|
62
|
-
case '
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
walk(one, scope, when);
|
|
73
|
-
return;
|
|
74
|
-
case 'member_access': {
|
|
75
|
-
const to = reached(node, scope, when);
|
|
76
|
-
if (to)
|
|
77
|
-
return named(to.name, to.when);
|
|
78
|
-
return walk(node.object, scope, when);
|
|
188
|
+
case 'literal':
|
|
189
|
+
case 'null':
|
|
190
|
+
case 'string': return given(unparsed(node) ?? 'null');
|
|
191
|
+
case 'variable': return variable(node.name, scope, view);
|
|
192
|
+
case 'member_access': return member(follow(node.object, scope, view), node.property);
|
|
193
|
+
case 'function_call': {
|
|
194
|
+
if (scope.has(node.name))
|
|
195
|
+
return (node.args.forEach((one) => used(follow(one, scope, view))), UNKNOWN);
|
|
196
|
+
// What a function of Elo's is given is followed by what it does with it, and once.
|
|
197
|
+
return items.has(node.name) || words.has(node.name) ? applied(node.name, node.args.map((one) => follow(one, scope, view)), view) ?? UNKNOWN : builtIn(node.name, node.args, scope, view);
|
|
79
198
|
}
|
|
80
199
|
case 'apply': {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
200
|
+
// `old.board(input.id)`, `seenBy.cy.owed(me)`: named where it is seen from, and given what is said where it is written.
|
|
201
|
+
const from = node.fn.type === 'member_access' ? follow(node.fn.object, scope, view) : UNKNOWN;
|
|
202
|
+
const args = node.args.map((one) => follow(one, scope, view));
|
|
203
|
+
const gives = from.is === 'view' && node.fn.type === 'member_access' ? applied(node.fn.property, args, from.view) : null;
|
|
204
|
+
if (gives)
|
|
205
|
+
return gives;
|
|
206
|
+
for (const one of [node.fn.type === 'member_access' ? from : follow(node.fn, scope, view), ...args])
|
|
207
|
+
used(one);
|
|
208
|
+
return UNKNOWN;
|
|
209
|
+
}
|
|
210
|
+
case 'binary': {
|
|
211
|
+
const [left, right] = [follow(node.left, scope, view), follow(node.right, scope, view)];
|
|
212
|
+
// Whether a collection is told at all, `boards != null`, reads nothing of its items.
|
|
213
|
+
const asked = node.left.type === 'null' ? right : node.right.type === 'null' ? left : null;
|
|
214
|
+
if (asked?.is === 'collection' && (node.operator === '==' || node.operator === '!='))
|
|
215
|
+
return (read(asked.view, { variable: asked.variable, of: 'whole' }), UNKNOWN);
|
|
216
|
+
used(left);
|
|
217
|
+
used(right);
|
|
218
|
+
return isGiven(left) && isGiven(right) ? given(`(${left.source} ${node.operator} ${right.source})`, left.answered || right.answered) : UNKNOWN;
|
|
219
|
+
}
|
|
220
|
+
case 'unary': {
|
|
221
|
+
const of = follow(node.operand, scope, view);
|
|
222
|
+
used(of);
|
|
223
|
+
return isGiven(of) ? given(`(${node.operator}${of.source})`, of.answered) : UNKNOWN;
|
|
89
224
|
}
|
|
90
|
-
case 'lambda':
|
|
91
|
-
return walk(node.body, bind(scope, node.params), when);
|
|
92
225
|
case 'let': {
|
|
93
|
-
|
|
94
|
-
for (const one of node.bindings)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
226
|
+
const inner = new Map(scope);
|
|
227
|
+
for (const one of node.bindings)
|
|
228
|
+
inner.set(one.name, follow(one.value, inner, view));
|
|
229
|
+
return follow(node.body, inner, view);
|
|
230
|
+
}
|
|
231
|
+
case 'lambda':
|
|
232
|
+
used(follow(node.body, new Map([...scope, ...node.params.map((param) => [param, UNKNOWN])]), view));
|
|
233
|
+
return UNKNOWN;
|
|
234
|
+
case 'alternative': {
|
|
235
|
+
// `emails | []`: what is read, where the rest is given.
|
|
236
|
+
const values = node.alternatives.map((one) => follow(one, scope, view));
|
|
237
|
+
const state = values.filter((one) => !isGiven(one));
|
|
238
|
+
if (state.length === 1 && state[0].is !== 'unknown')
|
|
239
|
+
return state[0];
|
|
240
|
+
for (const one of values)
|
|
241
|
+
used(one);
|
|
242
|
+
return UNKNOWN;
|
|
99
243
|
}
|
|
100
|
-
case '
|
|
101
|
-
|
|
244
|
+
case 'array': {
|
|
245
|
+
const values = node.elements.map((one) => follow(one, scope, view));
|
|
246
|
+
for (const one of values)
|
|
247
|
+
used(one);
|
|
248
|
+
return values.every(isGiven) ? given(`[${values.map((one) => one.source).join(', ')}]`, values.some((one) => one.answered)) : UNKNOWN;
|
|
249
|
+
}
|
|
250
|
+
case 'typedef': return follow(node.body, new Map([...scope, ...node.definitions.map((one) => [one.name, UNKNOWN])]), view);
|
|
102
251
|
default:
|
|
103
252
|
for (const child of childrenOf(node))
|
|
104
|
-
|
|
253
|
+
used(follow(child, scope, view));
|
|
254
|
+
return UNKNOWN;
|
|
105
255
|
}
|
|
106
256
|
};
|
|
107
257
|
const tree = treeOf(text);
|
|
108
258
|
if (tree)
|
|
109
|
-
|
|
110
|
-
return
|
|
259
|
+
used(follow(tree, new Map(), { via: 'web', when: at }));
|
|
260
|
+
return { reads: [...reads.values()], whole };
|
|
111
261
|
}
|
|
262
|
+
/** Whether an expression names something, where it does not bind it itself: as a text would, which is enough to say that it may. */
|
|
263
|
+
const mentions = (node, name) => new RegExp(`"name":"${name}"`).test(JSON.stringify(node));
|
|
112
264
|
function childrenOf(node) {
|
|
113
265
|
switch (node.type) {
|
|
114
|
-
case 'binary': return [node.left, node.right];
|
|
115
|
-
case 'unary': return [node.operand];
|
|
116
266
|
case 'if': return [node.condition, node.then, node.else];
|
|
117
267
|
case 'object': return node.properties.map((one) => one.value);
|
|
118
|
-
case 'array': return node.elements;
|
|
119
|
-
case 'alternative': return node.alternatives;
|
|
120
268
|
case 'guard': return [...node.constraints.map((one) => one.condition), node.body];
|
|
121
269
|
default: return [];
|
|
122
270
|
}
|
|
123
271
|
}
|
|
272
|
+
const together = (all) => ({ reads: all.flatMap((one) => one.reads), whole: all.some((one) => one.whole) });
|
|
273
|
+
/** What clauses read: a precondition, and what triggers the operation, before the call; a postcondition, and what an example alone also shows, before and after it. */
|
|
274
|
+
export const readByClauses = (clauses, readable) => together(clauses.filter((clause) => clause.formaldef).map((clause) => readsOf(clause.formaldef ?? '', isBefore(clause) ? 'before' : 'after', readable)));
|
|
124
275
|
/**
|
|
125
|
-
*
|
|
126
|
-
* which
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
export const observedIn = (reach, all) => (reach.whole ? all : all.filter((name) => reach.monitors.includes(name) || reach.controls.includes(name)));
|
|
130
|
-
const ordered = (all, readable) => readable.state.map((one) => one.name).filter((name) => all.has(name));
|
|
131
|
-
/**
|
|
132
|
-
* What an operation reads, from its formaldefs: what each precondition reads, before the call;
|
|
133
|
-
* what each postcondition, and what an example alone also shows, reads before and after it; what
|
|
134
|
-
* the input of a case reads, before it.
|
|
276
|
+
* What a case reads, to be judged: what the clauses of the operation read, but what triggers it,
|
|
277
|
+
* which no case checks; what the case alone also shows; and its input, when the state gives it.
|
|
278
|
+
* Which clauses are read is the run's choice: a fast run is given the operation without its (+)
|
|
279
|
+
* clauses (`mustOnly`), so what they read is not observed.
|
|
135
280
|
*/
|
|
136
|
-
export
|
|
137
|
-
const all = { before: new Set(), after: new Set(), whole: false };
|
|
138
|
-
const add = (read) => {
|
|
139
|
-
for (const name of read.before)
|
|
140
|
-
all.before.add(name);
|
|
141
|
-
for (const name of read.after)
|
|
142
|
-
all.after.add(name);
|
|
143
|
-
all.whole ||= Boolean(read.whole);
|
|
144
|
-
};
|
|
145
|
-
for (const clause of [...operation.clauses, ...operation.cases.flatMap((kase) => kase.and)])
|
|
146
|
-
if (clause.formaldef)
|
|
147
|
-
add(statesRead(clause.formaldef, isPre(clause) ? 'before' : 'after', readable));
|
|
148
|
-
for (const kase of operation.cases)
|
|
149
|
-
if (typeof kase.input === 'string')
|
|
150
|
-
add(statesRead(kase.input, 'before', readable));
|
|
151
|
-
return all;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Its reach, said or derived. Derived, it controls what a postcondition reads after the call (an
|
|
155
|
-
* observation, nothing): what it may change, since a postcondition that reads a state after the call
|
|
156
|
-
* may as well say it is unchanged. It monitors what it reads before the call, and what it reads
|
|
157
|
-
* after it and does not control.
|
|
158
|
-
*/
|
|
159
|
-
export function reachOf(operation, readable, said = {}) {
|
|
160
|
-
const read = readBy(operation, readable);
|
|
161
|
-
const controls = said.controls ?? (operation.observes ? [] : ordered(read.after, readable));
|
|
162
|
-
const monitors = said.monitors ?? ordered(new Set([...read.before, ...[...read.after].filter((name) => !controls.includes(name))]), readable);
|
|
163
|
-
return { monitors, controls, said: { monitors: said.monitors !== undefined, controls: said.controls !== undefined }, ...(read.whole ? { whole: true } : {}) };
|
|
164
|
-
}
|
|
165
|
-
/** What an operation says of its reach that cannot be: a state that is none, an observation that controls, a state it reads and says it neither monitors nor controls. */
|
|
166
|
-
export function reachProblems(operation, readable, reach) {
|
|
167
|
-
const states = readable.state.map((one) => one.name);
|
|
168
|
-
const named = [...(reach.said.monitors ? reach.monitors : []), ...(reach.said.controls ? reach.controls : [])];
|
|
169
|
-
const problems = [...new Set(named.filter((name) => !states.includes(name)))].map((name) => `"${name}" is not a state of state.yml: an operation monitors and controls states`);
|
|
170
|
-
if (operation.observes && reach.controls.length)
|
|
171
|
-
problems.push('an observation changes nothing: it controls no state');
|
|
172
|
-
if (!reach.said.monitors)
|
|
173
|
-
return problems;
|
|
174
|
-
const read = readBy(operation, readable);
|
|
175
|
-
const unreached = ordered(new Set([...read.before, ...read.after]), readable).filter((name) => !reach.monitors.includes(name) && !reach.controls.includes(name));
|
|
176
|
-
return [...problems, ...unreached.map((name) => `it reads "${name}", which it says it neither monitors nor controls`)];
|
|
177
|
-
}
|
|
281
|
+
export const readByCase = (operation, kase, readable) => together([readByClauses(operation.clauses.filter((clause) => clause.kind !== TRIGGER), readable), readByClauses(kase.and, readable), ...(typeof kase.input === 'string' ? [readsOf(kase.input, 'before', readable)] : [])]);
|
package/dist/reading.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { a, listOf, record, sentenceOf, text } from './citizens.js';
|
|
5
5
|
import { placeOf } from './lines.js';
|
|
6
6
|
import { readsDatabase } from './behind.js';
|
|
7
|
-
import { reachOf, reachProblems } from './reach.js';
|
|
8
7
|
import { NO_REFUSAL, entryOf, givenOf, marked, placeholders, refuses, thenOf } from './notation.js';
|
|
9
8
|
import { SAID, TRIGGER, isA, isForType, isPre, named, sameSentence } from './suite.js';
|
|
10
9
|
const OPERATION_KEYS = ['name', 'description', 'agent', 'entry', 'input', 'output', 'monitors', 'controls', ...SAID, 'examples', 'counterexamples'];
|
|
@@ -45,14 +44,21 @@ function meant(kind, item, where, { conditions, definitions }, problems, source)
|
|
|
45
44
|
const shared = conditions.find((condition) => sameSentence(condition.description, description));
|
|
46
45
|
const formaldef = said.formaldef ?? shared?.formaldef;
|
|
47
46
|
const behind = attempt([], () => readsDatabase(formaldef ?? '', definitions), false);
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// What triggers an operation may say what it means, of the state before it is performed: it is told all the same.
|
|
48
|
+
if (kind === TRIGGER)
|
|
49
|
+
return triggering({ ...said, formaldef }, where, Boolean(shared), problems, source);
|
|
50
50
|
if (shared && said.formaldef)
|
|
51
51
|
problems.push(`${kind} "${description}" has a formaldef here and another as a condition: keep one`);
|
|
52
52
|
problems.push(...mismarked(kind, description, said.mark, long, { own: Boolean(said.formaldef), shared: Boolean(shared), behind }));
|
|
53
53
|
const mark = long ? (!formaldef ? 'told' : behind ? 'complete' : 'checked') : said.mark;
|
|
54
54
|
return { kind, name: said.name ?? where, source, description, ...(formaldef ? { formaldef } : {}), from: said.formaldef ? 'here' : shared ? 'shared' : 'nowhere', mark };
|
|
55
55
|
}
|
|
56
|
+
/** What triggers an operation: a sentence, told, with the formaldef that says it of the state when it has one. One call shows nothing of it, so it says no mark that would have it checked. */
|
|
57
|
+
function triggering(said, where, shared, problems, source) {
|
|
58
|
+
if (said.mark && said.mark !== 'told')
|
|
59
|
+
problems.push(`${TRIGGER} "${said.description}" is marked (${MARKED[said.mark]}): what triggers an operation is told, with a formaldef or without, since one call shows nothing of it`);
|
|
60
|
+
return { kind: TRIGGER, name: said.name ?? where, source, description: said.description, ...(said.formaldef ? { formaldef: said.formaldef } : {}), from: !said.formaldef ? 'nowhere' : shared ? 'shared' : 'here', mark: 'told' };
|
|
61
|
+
}
|
|
56
62
|
const clausesOf = (raw, name, model, problems, place) => SAID.flatMap((kind) => listOf(`"${kind}"`, raw[kind], problems).map((item, at) => meant(kind, item, `${name}/${kind}/${at + 1}`, model, problems, place(kind, at)))).filter((clause) => clause !== null);
|
|
57
63
|
/** The precondition a counterexample is for, in the operation's words: with its mark or without. */
|
|
58
64
|
const forOf = (written, problems) => attempt(problems, () => marked(text(written)).description, text(written));
|
|
@@ -102,23 +108,16 @@ function headProblems(raw, { agents }) {
|
|
|
102
108
|
found.push(`"${text(raw.agent)}" is not an agent of agents.yml`);
|
|
103
109
|
return found;
|
|
104
110
|
}
|
|
105
|
-
/** A list of states an operation says it monitors, or controls: what it says, when it says one. */
|
|
106
|
-
function statesSaid(raw, key, problems) {
|
|
107
|
-
if (raw[key] === undefined || raw[key] === null)
|
|
108
|
-
return {};
|
|
109
|
-
const said = raw[key];
|
|
110
|
-
if (!Array.isArray(said) || said.some((one) => typeof one !== 'string' || !one.trim())) {
|
|
111
|
-
problems.push(`"${key}" says a list of states, by their names, got ${JSON.stringify(said)}`);
|
|
112
|
-
return {};
|
|
113
|
-
}
|
|
114
|
-
return { [key]: said.map((one) => one.trim()) };
|
|
115
|
-
}
|
|
116
111
|
/** An operation, from its file; an observation when it is filed as one. */
|
|
117
112
|
export function operationOf(file, written, model, observes = false, lines) {
|
|
118
113
|
const raw = record(written);
|
|
119
114
|
const problems = [];
|
|
120
115
|
const name = text(raw.name) || file;
|
|
121
116
|
unknownKeys(raw, OPERATION_KEYS, 'the operation', problems);
|
|
117
|
+
// Removed for now: what an operation reads is derived from its clauses, and what it changes is not said. Known, so that they are told as removed alone.
|
|
118
|
+
for (const key of ['monitors', 'controls'])
|
|
119
|
+
if (key in raw)
|
|
120
|
+
problems.push(`the operation: "${key}" is removed: what the clauses read is derived from them, and nothing says what the operation changes`);
|
|
122
121
|
problems.push(...headProblems(raw, model));
|
|
123
122
|
const entry = attempt(problems, () => entryOf(raw.entry), { method: 'GET', path: '/' });
|
|
124
123
|
const place = placeOf(file, lines);
|
|
@@ -127,9 +126,6 @@ export function operationOf(file, written, model, observes = false, lines) {
|
|
|
127
126
|
problems.push(...cases.flatMap((kase) => caseProblems(kase, { agent: text(raw.agent), clauses, input: text(raw.input) || undefined }, model)), ...twice(cases));
|
|
128
127
|
if (placeholders(entry.path).length && !text(raw.input))
|
|
129
128
|
problems.push(`the entry takes ${placeholders(entry.path).join(', ')} from the input: the operation says its "input"`);
|
|
130
|
-
const
|
|
131
|
-
const reach = reachOf({ observes, clauses, cases }, model, said);
|
|
132
|
-
problems.push(...reachProblems({ observes, clauses, cases }, model, reach));
|
|
133
|
-
const operation = { file, source: place('name'), area: file.split(/[\\/]/)[0] ?? '', name, description: text(raw.description), agent: text(raw.agent), observes, entry, input: text(raw.input) || undefined, output: text(raw.output) || undefined, clauses, cases, reach };
|
|
129
|
+
const operation = { file, source: place('name'), area: file.split(/[\\/]/)[0] ?? '', name, description: text(raw.description), agent: text(raw.agent), observes, entry, input: text(raw.input) || undefined, output: text(raw.output) || undefined, clauses, cases };
|
|
134
130
|
return { operation, problems: problems.map((problem) => `${file}: ${problem}`) };
|
|
135
131
|
}
|
package/dist/running.js
CHANGED
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
// Then judging.ts says what does not hold
|
|
11
11
|
import { Unrunnable, unrun, whole } from './finding.js';
|
|
12
12
|
import { inputMisfit, judge } from './judging.js';
|
|
13
|
-
import {
|
|
13
|
+
import { readByCase } from './reach.js';
|
|
14
|
+
import { observe, planOf } from './observing.js';
|
|
14
15
|
import { addressed, queryOf } from './notation.js';
|
|
15
16
|
import { witnessesOf } from './planning.js';
|
|
16
17
|
import { credentialsOf } from './suite.js';
|
|
17
|
-
import { atRest, browserOf
|
|
18
|
+
import { asking, atRest, browserOf } from './world.js';
|
|
18
19
|
function ears(listening) {
|
|
19
20
|
const wire = [];
|
|
20
21
|
let now = 'signs in';
|
|
@@ -73,26 +74,35 @@ function mayEmpty(config) {
|
|
|
73
74
|
if (config.mayEmptyTheDatabase !== true)
|
|
74
75
|
throw new Unrunnable('the configuration does not say that the database may be emptied, and setting a Background empties it');
|
|
75
76
|
}
|
|
77
|
+
/** Nothing observed: what a key is decided over, which reads no state. */
|
|
78
|
+
const NOTHING = { seenBy: {}, db: {} };
|
|
79
|
+
/** What a key gives for a case: an expression of what the operation is given, answers and knows of the world. Nothing while what it reads is not there. */
|
|
80
|
+
const deciding = (meaning, said) => (source) => meaning.value(source, { ...said, before: NOTHING, after: NOTHING }, 'post');
|
|
76
81
|
async function run(reach, model, meaning, operation, kase, origin, heard) {
|
|
77
82
|
mayEmpty(reach.config);
|
|
78
83
|
const callers = callersOf(model, operation, kase);
|
|
79
84
|
await rested(reach, heard);
|
|
80
85
|
await heard.step({ doing: 'sets the Background', seed: kase.given.seed }, () => reach.config.background(kase.given.seed));
|
|
81
86
|
const { requester, witnesses } = await browsers(reach, callers, origin, heard);
|
|
87
|
+
const lookers = { requester, witnesses, query: asking(reach) };
|
|
82
88
|
const world = worldOf(model, kase);
|
|
83
|
-
//
|
|
84
|
-
const
|
|
89
|
+
// What the case reads, as its clauses say it: a fast run is given its operation without the (+) clauses (mustOnly), a complete run with them.
|
|
90
|
+
const read = readByCase(operation, kase, model);
|
|
91
|
+
const looking = (said) => observe(lookers, model, planOf(read, model, Object.keys(witnesses), deciding(meaning, { ...said, world }), { complete: reach.complete }));
|
|
85
92
|
heard.doing('observes, before');
|
|
86
|
-
|
|
87
|
-
const
|
|
93
|
+
// An input the state gives is known once the state is: what it reads is looked at first, then what the case reads of what it is given.
|
|
94
|
+
const given = typeof kase.input === 'string' ? await looking({ input: null }) : null;
|
|
95
|
+
const input = given ? meaning.value(kase.input, { before: given, world }, 'given') : kase.input;
|
|
96
|
+
const before = await looking({ input });
|
|
88
97
|
heard.doing('calls');
|
|
89
98
|
const answer = await call(requester, operation, input);
|
|
90
99
|
// What an operation starts and does not wait for is part of what it brings about: the state is observed once it is done.
|
|
91
100
|
if (operation.entry.method !== 'GET' && answer.status < 400)
|
|
92
101
|
await rested(reach, heard);
|
|
93
102
|
heard.doing('observes, after');
|
|
94
|
-
const after = await
|
|
95
|
-
|
|
103
|
+
const after = await looking({ input, output: answer.body });
|
|
104
|
+
const observed = { input, world, before, after, status: answer.status, body: answer.body };
|
|
105
|
+
return [...inputMisfit(operation, kase, input, meaning), ...judge(operation, kase, observed, meaning, reach.config.refusal)];
|
|
96
106
|
}
|
|
97
107
|
/** What a case decided, from what was found: told whole to who runs it, and kept without what was seen. */
|
|
98
108
|
export const outcomeOf = (kase, found, ms, wire = []) => ({ kase, findings: found.map(whole), kept: found.map((one) => one.says), ms, wire });
|
package/dist/starting.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// a system that answers. Each that is missing is told in a sentence, as a `NotStarted`, and
|
|
3
3
|
// nothing is run: a run that dies on one of them after its cases has told nothing.
|
|
4
4
|
import { closeSync, openSync } from 'node:fs';
|
|
5
|
+
import { observedBy } from './suite.js';
|
|
5
6
|
import { reader } from './world.js';
|
|
6
7
|
/** What keeps a run from starting: said in a line. */
|
|
7
8
|
export class NotStarted extends Error {
|
|
@@ -24,12 +25,12 @@ export function writable(file) {
|
|
|
24
25
|
}
|
|
25
26
|
/** How the run reaches what it reads: the database, when the configuration names one. Its address is not told: it holds a password. */
|
|
26
27
|
export async function reachOf(suite, config, fast) {
|
|
27
|
-
if (suite.model.
|
|
28
|
-
throw new NotStarted('The state
|
|
28
|
+
if (observedBy(suite.model, 'db').length > 0 && !fast && !config.database)
|
|
29
|
+
throw new NotStarted('The state says what the database shows of it, and the configuration no database to read it from.');
|
|
29
30
|
const unreached = (error) => {
|
|
30
31
|
throw new NotStarted(`The database cannot be reached: ${why(error)}`);
|
|
31
32
|
};
|
|
32
|
-
return { config, database: config.database ? await reader(config.database).catch(unreached) : null,
|
|
33
|
+
return { config, database: config.database ? await reader(config.database).catch(unreached) : null, complete: !fast };
|
|
33
34
|
}
|
|
34
35
|
/** The system answers at its front door, whatever it answers: asked once, so that a system that is not there is one sentence and not every case. */
|
|
35
36
|
export async function answering(config, withinMs = 15_000) {
|
package/dist/suite.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// What a specification is made of, once read: its citizens. Each has a name and a description,
|
|
2
|
+
// and some a formal definition, its formaldef: what the suite speaks of (areas, agents, Backgrounds,
|
|
3
|
+
// actors, the state), its words (predicates, functions, conditions, types), its operations.
|
|
1
4
|
export const PRE = ['DomPre', 'ReqPre'];
|
|
2
5
|
export const POST = ['DomPost', 'ReqPost'];
|
|
3
6
|
/** The four that can be checked, then when an operation is performed without being asked: told, since one call shows nothing of it. */
|
|
@@ -8,11 +11,13 @@ export const SAID = ['DomPre', 'DomPost', 'ReqPre', 'ReqPost', TRIGGER];
|
|
|
8
11
|
/** How a mark is written. */
|
|
9
12
|
export const MARKS = { x: 'checked', '+': 'complete', ' ': 'told' };
|
|
10
13
|
/** A suite that says nothing. */
|
|
11
|
-
export const NOTHING_SAID = { system: {}, descriptions: {}, areas: [], agents: [], backgrounds: [], actors: [], world: {}, state: [],
|
|
14
|
+
export const NOTHING_SAID = { system: {}, descriptions: {}, areas: [], agents: [], backgrounds: [], actors: [], world: {}, state: [], definitions: [], conditions: [], types: [] };
|
|
12
15
|
/** Two sentences are the same whatever their case and spacing. */
|
|
13
16
|
export const sameSentence = (a, b) => normal(a) === normal(b);
|
|
14
17
|
const normal = (sentence) => sentence.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
15
18
|
export const isPre = (clause) => PRE.includes(clause.kind);
|
|
19
|
+
/** Whether a clause speaks of the state the call starts from: a precondition, and what triggers the operation, which holds before it is performed. */
|
|
20
|
+
export const isBefore = (clause) => isPre(clause) || clause.kind === TRIGGER;
|
|
16
21
|
/**
|
|
17
22
|
* Whether a counterexample is for the type of the input: its input is not one, on purpose. Every
|
|
18
23
|
* operation refuses what is not of its type, a precondition no operation says; a counterexample
|
|
@@ -21,6 +26,8 @@ export const isPre = (clause) => PRE.includes(clause.kind);
|
|
|
21
26
|
export const isForType = (operation, kase) => kase.kind === 'counterexample' && Boolean(operation.input) && kase.for === operation.input;
|
|
22
27
|
/** The citizen of that name, among those of one kind. */
|
|
23
28
|
export const named = (all, name) => all.find((one) => one.name === name);
|
|
29
|
+
/** The states a mechanism observes. */
|
|
30
|
+
export const observedBy = (model, mechanism) => model.state.filter((one) => one[mechanism]);
|
|
24
31
|
/** What each actor signs in with, by name: `world.actors`. */
|
|
25
32
|
export const credentialsOf = (model) => Object.fromEntries(model.actors.map((actor) => [actor.name, actor.with]));
|
|
26
33
|
/** Whether an agent is another, itself or through what it is: an Administrator is a Member, who is a Visitor. */
|