@addozhang/dsh-discord 0.1.0 → 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/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Render generation and terminal fences (design.md §8, task 11.4). Every
|
|
3
|
-
* async edit belongs to a generation; a late chunk from a superseded
|
|
4
|
-
* generation is dropped, never overwriting newer output. `finalize` is the
|
|
5
|
-
* terminal fence: it freezes the final content, and after it nothing —
|
|
6
|
-
* stale or current — mutates what Discord saw.
|
|
7
|
-
*/
|
|
8
|
-
export interface PublishResult {
|
|
9
|
-
published: boolean;
|
|
10
|
-
visible: string;
|
|
11
|
-
}
|
|
12
|
-
export type FinalizeResult = {
|
|
13
|
-
ok: true;
|
|
14
|
-
} | {
|
|
15
|
-
ok: false;
|
|
16
|
-
error: 'stale-generation' | 'already-final';
|
|
17
|
-
};
|
|
18
|
-
export interface RenderFence {
|
|
19
|
-
/** Open a new generation and return its id. */
|
|
20
|
-
beginGeneration(): number;
|
|
21
|
-
current(): number;
|
|
22
|
-
visible(): string;
|
|
23
|
-
isFinal(): boolean;
|
|
24
|
-
publish(content: string, generation: number): PublishResult;
|
|
25
|
-
finalize(generation: number, finalContent: string): FinalizeResult;
|
|
26
|
-
}
|
|
27
|
-
export declare function createRenderFence(): RenderFence;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Render generation and terminal fences (design.md §8, task 11.4). Every
|
|
3
|
-
* async edit belongs to a generation; a late chunk from a superseded
|
|
4
|
-
* generation is dropped, never overwriting newer output. `finalize` is the
|
|
5
|
-
* terminal fence: it freezes the final content, and after it nothing —
|
|
6
|
-
* stale or current — mutates what Discord saw.
|
|
7
|
-
*/
|
|
8
|
-
export function createRenderFence() {
|
|
9
|
-
let generation = 0;
|
|
10
|
-
let visible = '';
|
|
11
|
-
let final = false;
|
|
12
|
-
return {
|
|
13
|
-
beginGeneration() {
|
|
14
|
-
generation += 1;
|
|
15
|
-
return generation;
|
|
16
|
-
},
|
|
17
|
-
current: () => generation,
|
|
18
|
-
visible: () => visible,
|
|
19
|
-
isFinal: () => final,
|
|
20
|
-
publish(content, gen) {
|
|
21
|
-
if (final || gen !== generation) {
|
|
22
|
-
return { published: false, visible };
|
|
23
|
-
}
|
|
24
|
-
visible = content;
|
|
25
|
-
return { published: true, visible };
|
|
26
|
-
},
|
|
27
|
-
finalize(gen, finalContent) {
|
|
28
|
-
if (final)
|
|
29
|
-
return { ok: false, error: 'already-final' };
|
|
30
|
-
if (gen !== generation)
|
|
31
|
-
return { ok: false, error: 'stale-generation' };
|
|
32
|
-
visible = finalContent;
|
|
33
|
-
final = true;
|
|
34
|
-
return { ok: true };
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|