@dsh-workbench/shared 0.2.13 → 0.2.15
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/dist/api/dsh.d.ts +1 -0
- package/dist/components/FormActions.css +13 -0
- package/dist/components/FormActions.d.ts +15 -0
- package/dist/components/FormActions.js +38 -0
- package/dist/components/FormRows.css +21 -5
- package/dist/components/SaveBar.d.ts +0 -1
- package/dist/components/SaveBar.js +13 -5
- package/dist/components/SelectField.css +20 -0
- package/dist/components/SelectField.d.ts +3 -1
- package/dist/components/SelectField.js +43 -25
- package/dist/components/SelectFieldNodes.d.ts +21 -0
- package/dist/components/SelectFieldNodes.js +17 -0
- package/dist/config/constants.d.ts +1 -0
- package/dist/config/constants.js +1 -0
- package/dist/host/tool-kit.d.ts +1 -0
- package/dist/host/tool-kit.js +4 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.js +1 -0
- package/dist/i18n/en.js +17 -0
- package/dist/i18n/index.d.ts +18 -1
- package/dist/i18n/zh.d.ts +17 -0
- package/dist/i18n/zh.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/diy-debug.d.ts +38 -0
- package/dist/lib/diy-debug.js +77 -0
- package/package.json +1 -1
- package/src/api/dsh.ts +6 -1
- package/src/components/FormActions.css +13 -0
- package/src/components/FormActions.test.tsx +157 -0
- package/src/components/FormActions.tsx +75 -0
- package/src/components/FormRows.css +21 -5
- package/src/components/FormRows.test.tsx +56 -0
- package/src/components/SaveBar.tsx +14 -18
- package/src/components/SelectField.css +20 -0
- package/src/components/SelectField.test.tsx +63 -0
- package/src/components/SelectField.tsx +56 -81
- package/src/components/SelectFieldNodes.tsx +77 -0
- package/src/config/constants.ts +2 -0
- package/src/host/tool-kit.ts +5 -0
- package/src/host.ts +1 -0
- package/src/i18n/en.ts +18 -0
- package/src/i18n/zh.ts +18 -0
- package/src/index.ts +2 -0
- package/src/lib/diy-debug.test.ts +103 -0
- package/src/lib/diy-debug.ts +122 -0
- package/src/components/SaveBar.css +0 -7
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export type DebugPhase = 'debugging' | 'paused';
|
|
2
|
+
|
|
3
|
+
export const DEBUG_STALE_MS = 4 * 60 * 60 * 1000;
|
|
4
|
+
|
|
5
|
+
export interface DebugState {
|
|
6
|
+
readonly phase: DebugPhase;
|
|
7
|
+
readonly sessionId: string;
|
|
8
|
+
readonly workspace: string;
|
|
9
|
+
readonly board: string;
|
|
10
|
+
readonly unit: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly startedAt: number;
|
|
13
|
+
readonly at: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DebugPact {
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
readonly workspace: string;
|
|
19
|
+
readonly board: string;
|
|
20
|
+
readonly unit: string;
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly now: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type DebugRefusal =
|
|
26
|
+
| 'already-held'
|
|
27
|
+
| 'held-by-other'
|
|
28
|
+
| 'not-owner'
|
|
29
|
+
| 'none'
|
|
30
|
+
| 'already-paused'
|
|
31
|
+
| 'already-debugging';
|
|
32
|
+
|
|
33
|
+
export type DebugMove =
|
|
34
|
+
| { readonly ok: true; readonly state: DebugState }
|
|
35
|
+
| { readonly ok: false; readonly code: DebugRefusal };
|
|
36
|
+
|
|
37
|
+
export interface DebugStore {
|
|
38
|
+
live(now: number): DebugState | null;
|
|
39
|
+
begin(pact: DebugPact): DebugMove;
|
|
40
|
+
stall(sessionId: string, now: number): DebugMove;
|
|
41
|
+
pause(sessionId: string, now: number): DebugMove;
|
|
42
|
+
resume(sessionId: string, now: number): DebugMove;
|
|
43
|
+
stop(sessionId: string, now: number): DebugMove;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function alive(state: DebugState | null, now: number): DebugState | null {
|
|
47
|
+
if (state === null) return null;
|
|
48
|
+
return now - state.at <= DEBUG_STALE_MS ? state : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function ownerOf(state: DebugState | null, sessionId: string, now: number): DebugRefusal | DebugState {
|
|
52
|
+
const held = alive(state, now);
|
|
53
|
+
if (held === null) return 'none';
|
|
54
|
+
return held.sessionId === sessionId ? held : 'not-owner';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createDebugStore(): DebugStore {
|
|
58
|
+
let held: DebugState | null = null;
|
|
59
|
+
|
|
60
|
+
const live = (now: number): DebugState | null => alive(held, now);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
live,
|
|
64
|
+
|
|
65
|
+
begin(pact) {
|
|
66
|
+
const current = alive(held, pact.now);
|
|
67
|
+
if (current !== null) {
|
|
68
|
+
return { ok: false, code: current.sessionId === pact.sessionId ? 'already-held' : 'held-by-other' };
|
|
69
|
+
}
|
|
70
|
+
const state: DebugState = {
|
|
71
|
+
phase: 'debugging',
|
|
72
|
+
sessionId: pact.sessionId,
|
|
73
|
+
workspace: pact.workspace,
|
|
74
|
+
board: pact.board,
|
|
75
|
+
unit: pact.unit,
|
|
76
|
+
name: pact.name,
|
|
77
|
+
startedAt: pact.now,
|
|
78
|
+
at: pact.now,
|
|
79
|
+
};
|
|
80
|
+
held = state;
|
|
81
|
+
return { ok: true, state };
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
stall(sessionId, now) {
|
|
85
|
+
const found = ownerOf(held, sessionId, now);
|
|
86
|
+
if (typeof found === 'string') return { ok: false, code: found };
|
|
87
|
+
if (found.phase === 'paused') return { ok: false, code: 'already-paused' };
|
|
88
|
+
const state: DebugState = { ...found, phase: 'paused', at: now };
|
|
89
|
+
held = state;
|
|
90
|
+
return { ok: true, state };
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
pause(sessionId, now) {
|
|
94
|
+
const found = ownerOf(held, sessionId, now);
|
|
95
|
+
if (typeof found === 'string') return { ok: false, code: found };
|
|
96
|
+
if (found.phase === 'paused') return { ok: false, code: 'already-paused' };
|
|
97
|
+
const state: DebugState = { ...found, phase: 'paused', at: now };
|
|
98
|
+
held = state;
|
|
99
|
+
return { ok: true, state };
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
resume(sessionId, now) {
|
|
103
|
+
const found = ownerOf(held, sessionId, now);
|
|
104
|
+
if (typeof found === 'string') return { ok: false, code: found };
|
|
105
|
+
if (found.phase === 'debugging') return { ok: false, code: 'already-debugging' };
|
|
106
|
+
const state: DebugState = { ...found, phase: 'debugging', at: now };
|
|
107
|
+
held = state;
|
|
108
|
+
return { ok: true, state };
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
stop(sessionId, now) {
|
|
112
|
+
const found = ownerOf(held, sessionId, now);
|
|
113
|
+
if (typeof found === 'string') return { ok: false, code: found };
|
|
114
|
+
held = null;
|
|
115
|
+
return { ok: true, state: found };
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function debugOwnerText(state: DebugState): string {
|
|
121
|
+
return `会话 ${state.sessionId}(自 ${new Date(state.startedAt).toISOString().slice(11, 19)}Z 起在调试 ${state.unit})`;
|
|
122
|
+
}
|