@mark1russell7/algebra 0.8.5 → 0.8.6
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 +66 -2
- package/build/clock-BPLEBlb6.d.ts +48 -0
- package/build/clock.d.ts +2 -47
- package/build/index.d.ts +2 -273
- package/build/index.js +4 -1009
- package/build/index.js.map +1 -1
- package/build/replay.js +24 -1
- package/build/replay.js.map +1 -0
- package/build/run-DTmtHPlK.js +1142 -0
- package/build/run-DTmtHPlK.js.map +1 -0
- package/build/run-Dol_e0Xa.d.ts +330 -0
- package/build/run.d.ts +2 -0
- package/build/run.js +1 -0
- package/build/states-DXQbSbfM.js +13 -0
- package/build/states-DXQbSbfM.js.map +1 -0
- package/package.json +5 -1
- package/build/replay-CGyXKaW3.js +0 -33
- package/build/replay-CGyXKaW3.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/algebra",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.6",
|
|
5
5
|
"description": "State machines as data, and the timer algebra over them: closed forms for a machine's timers in exact rationals, detection as the first live timer, recovery after a stall, and the replay of a trace.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"state-machine",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"types": "./build/replay.d.ts",
|
|
42
42
|
"default": "./build/replay.js"
|
|
43
43
|
},
|
|
44
|
+
"./run": {
|
|
45
|
+
"types": "./build/run.d.ts",
|
|
46
|
+
"default": "./build/run.js"
|
|
47
|
+
},
|
|
44
48
|
"./schema": {
|
|
45
49
|
"types": "./build/schema.d.ts",
|
|
46
50
|
"default": "./build/schema.js"
|
package/build/replay-CGyXKaW3.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// src/states.ts
|
|
2
|
-
/** This function gives one value or many values as an array. */
|
|
3
|
-
const arr = (value) => Array.isArray(value) ? value : [value];
|
|
4
|
-
/** This function gives the states that a transition leaves. The state "*" is each state that is not final. */
|
|
5
|
-
const fromStates = (m, from) => {
|
|
6
|
-
const out = /* @__PURE__ */ new Set();
|
|
7
|
-
for (const state of arr(from)) if (state !== "*") out.add(state);
|
|
8
|
-
else for (const [name, def] of Object.entries(m.states)) if (def.final !== true) out.add(name);
|
|
9
|
-
return [...out];
|
|
10
|
-
};
|
|
11
|
-
// src/replay.ts
|
|
12
|
-
/**
|
|
13
|
-
* This function replays a trace against a machine document, and it gives each disagreement:
|
|
14
|
-
* - Each instance starts in the state that its first transition leaves.
|
|
15
|
-
* - Each transition must leave the state where the replay of its instance is, and that state must be in the document.
|
|
16
|
-
* - The document must have a transition from that state, on that event, to that state. The state "*" is each state that is not final.
|
|
17
|
-
*/
|
|
18
|
-
const replay = (doc, transitions, options = {}) => {
|
|
19
|
-
const problems = [];
|
|
20
|
-
const at = /* @__PURE__ */ new Map();
|
|
21
|
-
for (const event of transitions) {
|
|
22
|
-
if (options.machine !== void 0 && event.machine !== options.machine) continue;
|
|
23
|
-
const where = at.get(event.instance) ?? event.from;
|
|
24
|
-
if (doc.states[where] === void 0) problems.push(`${event.instance}: the state ${where} is not in ${doc.id}`);
|
|
25
|
-
if (event.from !== where) problems.push(`${event.instance}: the runtime left ${event.from} on ${event.on}, but the replay is in ${where}`);
|
|
26
|
-
if (!doc.transitions.some((each) => fromStates(doc, each.from).includes(event.from) && arr(each.on).includes(event.on) && each.to === event.to)) problems.push(`${event.instance}: ${doc.id} has no transition from ${event.from} on ${event.on} to ${event.to}`);
|
|
27
|
-
at.set(event.instance, event.to);
|
|
28
|
-
}
|
|
29
|
-
return problems;
|
|
30
|
-
};
|
|
31
|
-
export { arr as n, fromStates as r, replay as t };
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=replay-CGyXKaW3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replay-CGyXKaW3.js","names":[],"sources":["../src/states.ts","../src/replay.ts"],"sourcesContent":["import type { Machine } from \"./machine.ts\";\n\n// The states of a document, without the schema: the replay reads them, and it does not import zod.\n\n/** This function gives one value or many values as an array. */\nexport const arr = <T>(value: T | readonly T[]): readonly T[] =>\n Array.isArray(value) ? (value as readonly T[]) : [value as T];\n\n/** This function gives the states that a transition leaves. The state \"*\" is each state that is not final. */\nexport const fromStates = (m: Pick<Machine, \"states\">, from: string | readonly string[]): string[] => {\n const out = new Set<string>();\n for (const state of arr(from)) {\n if (state !== \"*\") out.add(state);\n else for (const [name, def] of Object.entries(m.states)) if (def.final !== true) out.add(name);\n }\n return [...out];\n};\n","// @mark1russell7/algebra/replay: the replay of a trace against a machine document. A machine of\n// any name, with its own states and events, replays here. The entry does not import zod. Thus\n// a client in a browser can replay its own transitions.\n\nimport type { Machine } from \"./machine.ts\";\nimport { arr, fromStates } from \"./states.ts\";\n\n/**\n * A transition is one change of state that a running machine reports. A lifecycle event of\n * `@mark1russell7/service` is a transition, and so is a report of any other machine.\n */\nexport interface Transition {\n /** This name identifies the machine that reported. Each program names its own machines. */\n readonly machine?: string | undefined;\n /** This name identifies one machine among others of its kind: a connection, a check. */\n readonly instance: string;\n readonly from: string;\n readonly on: string;\n readonly to: string;\n /** This time is when the transition occurred, in milliseconds. The replay does not read it. */\n readonly at?: number | undefined;\n}\n\n/** These are the parts of a machine document that a replay reads. */\nexport type Replayable = Pick<Machine, \"id\" | \"states\" | \"transitions\">;\n\n/** These options tell which transitions of a trace replay. */\nexport interface ReplayOptions {\n /** Only the transitions of this machine replay. Without it, each transition of the trace replays. */\n readonly machine?: string | undefined;\n}\n\n/**\n * This function replays a trace against a machine document, and it gives each disagreement:\n * - Each instance starts in the state that its first transition leaves.\n * - Each transition must leave the state where the replay of its instance is, and that state must be in the document.\n * - The document must have a transition from that state, on that event, to that state. The state \"*\" is each state that is not final.\n */\nexport const replay = (doc: Replayable, transitions: readonly Transition[], options: ReplayOptions = {}): string[] => {\n const problems: string[] = [];\n const at = new Map<string, string>();\n for (const event of transitions) {\n if (options.machine !== undefined && event.machine !== options.machine) continue;\n const where = at.get(event.instance) ?? event.from;\n if (doc.states[where] === undefined) problems.push(`${event.instance}: the state ${where} is not in ${doc.id}`);\n if (event.from !== where)\n problems.push(`${event.instance}: the runtime left ${event.from} on ${event.on}, but the replay is in ${where}`);\n const allowed = doc.transitions.some(\n (each) => fromStates(doc, each.from).includes(event.from) && arr(each.on).includes(event.on) && each.to === event.to,\n );\n if (!allowed) problems.push(`${event.instance}: ${doc.id} has no transition from ${event.from} on ${event.on} to ${event.to}`);\n at.set(event.instance, event.to);\n }\n return problems;\n};\n"],"mappings":";;AAKA,MAAa,OAAU,UACrB,MAAM,QAAQ,KAAK,IAAK,QAAyB,CAAC,KAAU;;AAG9D,MAAa,cAAc,GAA4B,SAA+C;CACpG,MAAM,sBAAM,IAAI,IAAY;CAC5B,KAAK,MAAM,SAAS,IAAI,IAAI,GAC1B,IAAI,UAAU,KAAK,IAAI,IAAI,KAAK;MAC3B,KAAK,MAAM,CAAC,MAAM,QAAQ,OAAO,QAAQ,EAAE,MAAM,GAAG,IAAI,IAAI,UAAU,MAAM,IAAI,IAAI,IAAI;CAE/F,OAAO,CAAC,GAAG,GAAG;AAChB;;;;;;;;ACsBA,MAAa,UAAU,KAAiB,aAAoC,UAAyB,CAAC,MAAgB;CACpH,MAAM,WAAqB,CAAC;CAC5B,MAAM,qBAAK,IAAI,IAAoB;CACnC,KAAK,MAAM,SAAS,aAAa;EAC/B,IAAI,QAAQ,YAAY,KAAA,KAAa,MAAM,YAAY,QAAQ,SAAS;EACxE,MAAM,QAAQ,GAAG,IAAI,MAAM,QAAQ,KAAK,MAAM;EAC9C,IAAI,IAAI,OAAO,WAAW,KAAA,GAAW,SAAS,KAAK,GAAG,MAAM,SAAS,cAAc,MAAM,aAAa,IAAI,IAAI;EAC9G,IAAI,MAAM,SAAS,OACjB,SAAS,KAAK,GAAG,MAAM,SAAS,qBAAqB,MAAM,KAAK,MAAM,MAAM,GAAG,yBAAyB,OAAO;EAIjH,IAAI,CAHY,IAAI,YAAY,MAC7B,SAAS,WAAW,KAAK,KAAK,IAAI,CAAC,CAAC,SAAS,MAAM,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,KAAK,OAAO,MAAM,EAEzG,GAAG,SAAS,KAAK,GAAG,MAAM,SAAS,IAAI,IAAI,GAAG,0BAA0B,MAAM,KAAK,MAAM,MAAM,GAAG,MAAM,MAAM,IAAI;EAC7H,GAAG,IAAI,MAAM,UAAU,MAAM,EAAE;CACjC;CACA,OAAO;AACT"}
|