@crowdedkingdoms/crowdyjs 18.11.0-dev.1 → 18.13.0-dev.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/MIGRATION.md +51 -0
- package/README.md +19 -1
- package/dist/generated/graphql-schema.d.ts +5 -5
- package/dist/generated/graphql-schema.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kit/index.d.ts +11 -0
- package/dist/kit/index.d.ts.map +1 -1
- package/dist/kit/index.js +11 -0
- package/dist/kit/kit.d.ts +99 -2
- package/dist/kit/kit.d.ts.map +1 -1
- package/dist/kit/kit.js +128 -2
- package/dist/kit/modules/arenas.d.ts +87 -0
- package/dist/kit/modules/arenas.d.ts.map +1 -0
- package/dist/kit/modules/arenas.js +66 -0
- package/dist/kit/modules/encounters.d.ts +75 -0
- package/dist/kit/modules/encounters.d.ts.map +1 -0
- package/dist/kit/modules/encounters.js +57 -0
- package/dist/kit/modules/instances.d.ts +78 -0
- package/dist/kit/modules/instances.d.ts.map +1 -0
- package/dist/kit/modules/instances.js +72 -0
- package/dist/kit/modules/leaderboards.d.ts +79 -0
- package/dist/kit/modules/leaderboards.d.ts.map +1 -0
- package/dist/kit/modules/leaderboards.js +69 -0
- package/dist/kit/modules/market.d.ts +159 -0
- package/dist/kit/modules/market.d.ts.map +1 -0
- package/dist/kit/modules/market.js +141 -0
- package/dist/kit/modules/minigames.d.ts +59 -0
- package/dist/kit/modules/minigames.d.ts.map +1 -0
- package/dist/kit/modules/minigames.js +55 -0
- package/dist/kit/modules/player.d.ts +264 -0
- package/dist/kit/modules/player.d.ts.map +1 -0
- package/dist/kit/modules/player.js +258 -0
- package/dist/kit/modules/racing.d.ts +131 -0
- package/dist/kit/modules/racing.d.ts.map +1 -0
- package/dist/kit/modules/racing.js +113 -0
- package/dist/kit/modules/tables.d.ts +76 -0
- package/dist/kit/modules/tables.d.ts.map +1 -0
- package/dist/kit/modules/tables.js +73 -0
- package/dist/kit/modules/tactics.d.ts +79 -0
- package/dist/kit/modules/tactics.d.ts.map +1 -0
- package/dist/kit/modules/tactics.js +67 -0
- package/dist/kit/modules/territory.d.ts +92 -0
- package/dist/kit/modules/territory.d.ts.map +1 -0
- package/dist/kit/modules/territory.js +84 -0
- package/dist/kit/protocol.d.ts +2 -0
- package/dist/kit/protocol.d.ts.map +1 -1
- package/dist/kit/protocol.js +2 -0
- package/dist/kit/runtime.d.ts.map +1 -1
- package/dist/kit/runtime.js +6 -1
- package/dist/live-coding/assets/browser-authoring-index.json +1 -1
- package/dist/live-coding/assets/manifest.json +1 -1
- package/dist/live-coding/browser-authoring-index.generated.d.ts.map +1 -1
- package/dist/live-coding/browser-authoring-index.generated.js +4776 -149
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { HubState } from '../mirror.js';
|
|
2
|
+
import type { KitRuntime } from '../runtime.js';
|
|
3
|
+
export interface TacticsUnitStats {
|
|
4
|
+
hp: number;
|
|
5
|
+
attack: number;
|
|
6
|
+
defense: number;
|
|
7
|
+
moves: number;
|
|
8
|
+
range: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TacticsUnit {
|
|
11
|
+
id: number;
|
|
12
|
+
team: 'players' | 'enemies';
|
|
13
|
+
/** The player it belongs to; null for the hub's. */
|
|
14
|
+
owner: number | null;
|
|
15
|
+
x: number;
|
|
16
|
+
z: number;
|
|
17
|
+
hp: number;
|
|
18
|
+
stats: TacticsUnitStats;
|
|
19
|
+
moved: boolean;
|
|
20
|
+
acted: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** What the `battle` topic carries. */
|
|
23
|
+
export interface TacticsBattleView {
|
|
24
|
+
phase: 'lobby' | 'players' | 'enemies' | 'won' | 'lost';
|
|
25
|
+
round: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
obstacles: Array<[number, number]>;
|
|
29
|
+
units: TacticsUnit[];
|
|
30
|
+
players: number[];
|
|
31
|
+
host: number | null;
|
|
32
|
+
/** Players who ended this phase's turn. */
|
|
33
|
+
ended_turn: number[];
|
|
34
|
+
/** When the players' phase runs out (Unix ms). */
|
|
35
|
+
phase_ends: number | null;
|
|
36
|
+
log: string[];
|
|
37
|
+
}
|
|
38
|
+
/** Grid battles (the `tactics` starter): {@link battle} by key. */
|
|
39
|
+
export declare class TacticsKit {
|
|
40
|
+
private readonly runtime;
|
|
41
|
+
private readonly nodeType;
|
|
42
|
+
private readonly battles;
|
|
43
|
+
constructor(runtime: KitRuntime, nodeType?: string);
|
|
44
|
+
battle(key: string): TacticsBattle;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One battle in turns: each player's unit moves (within its move points, around obstacles and
|
|
48
|
+
* units) and attacks once a phase; when every player ends their turn, or the phase's time runs
|
|
49
|
+
* out, the hub's units act. The battle ends when one side has no unit standing.
|
|
50
|
+
*/
|
|
51
|
+
export declare class TacticsBattle {
|
|
52
|
+
private readonly runtime;
|
|
53
|
+
readonly nodeType: string;
|
|
54
|
+
readonly key: string;
|
|
55
|
+
/** The `battle` topic: the whole battle. */
|
|
56
|
+
readonly battle: HubState<TacticsBattleView>;
|
|
57
|
+
constructor(runtime: KitRuntime, nodeType: string, key: string);
|
|
58
|
+
watch(): Promise<TacticsBattleView>;
|
|
59
|
+
unwatch(): Promise<void>;
|
|
60
|
+
/** The player's units, as the mirror last saw them. */
|
|
61
|
+
myUnits(): Promise<TacticsUnit[]>;
|
|
62
|
+
/** @throws {KitError} `started`, `full`. */
|
|
63
|
+
join(): Promise<boolean>;
|
|
64
|
+
/** @throws {KitError} `forbidden` (the host starts it), `started`. */
|
|
65
|
+
start(): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Moves the player's unit to `(x, z)`.
|
|
68
|
+
* @throws {KitError} `not_your_turn`, `conflict` (it moved), `out_of_reach`, `not_member`.
|
|
69
|
+
*/
|
|
70
|
+
move(x: number, z: number): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Attacks unit `target` with the player's unit.
|
|
73
|
+
* @throws {KitError} `not_your_turn`, `conflict` (it attacked), `out_of_reach`, `forbidden` (its own side), `not_found`.
|
|
74
|
+
*/
|
|
75
|
+
attack(target: number): Promise<boolean>;
|
|
76
|
+
/** Ends the player's turn this phase. */
|
|
77
|
+
endTurn(): Promise<boolean>;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=tactics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tactics.d.ts","sourceRoot":"","sources":["../../../src/kit/modules/tactics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,oDAAoD;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,gBAAgB,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAA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OAAO,CAAC,OAAO,CAAC;IAI5C;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC,yCAAyC;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CAG5B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { HubState } from '../mirror.js';
|
|
2
|
+
/** Grid battles (the `tactics` starter): {@link battle} by key. */
|
|
3
|
+
export class TacticsKit {
|
|
4
|
+
constructor(runtime, nodeType = 'tactics') {
|
|
5
|
+
this.runtime = runtime;
|
|
6
|
+
this.nodeType = nodeType;
|
|
7
|
+
this.battles = new Map();
|
|
8
|
+
}
|
|
9
|
+
battle(key) {
|
|
10
|
+
let b = this.battles.get(key);
|
|
11
|
+
if (!b) {
|
|
12
|
+
b = new TacticsBattle(this.runtime, this.nodeType, key);
|
|
13
|
+
this.battles.set(key, b);
|
|
14
|
+
}
|
|
15
|
+
return b;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One battle in turns: each player's unit moves (within its move points, around obstacles and
|
|
20
|
+
* units) and attacks once a phase; when every player ends their turn, or the phase's time runs
|
|
21
|
+
* out, the hub's units act. The battle ends when one side has no unit standing.
|
|
22
|
+
*/
|
|
23
|
+
export class TacticsBattle {
|
|
24
|
+
constructor(runtime, nodeType, key) {
|
|
25
|
+
this.runtime = runtime;
|
|
26
|
+
this.nodeType = nodeType;
|
|
27
|
+
this.key = key;
|
|
28
|
+
this.battle = new HubState(runtime, nodeType, key, 'battle');
|
|
29
|
+
}
|
|
30
|
+
watch() {
|
|
31
|
+
return this.battle.start();
|
|
32
|
+
}
|
|
33
|
+
unwatch() {
|
|
34
|
+
return this.battle.stop();
|
|
35
|
+
}
|
|
36
|
+
/** The player's units, as the mirror last saw them. */
|
|
37
|
+
async myUnits() {
|
|
38
|
+
const me = await this.runtime.playerId();
|
|
39
|
+
return (this.battle.get()?.units ?? []).filter((u) => me !== null && String(u.owner) === me);
|
|
40
|
+
}
|
|
41
|
+
/** @throws {KitError} `started`, `full`. */
|
|
42
|
+
join() {
|
|
43
|
+
return this.runtime.call(this.nodeType, this.key, 'join', null, { action: true });
|
|
44
|
+
}
|
|
45
|
+
/** @throws {KitError} `forbidden` (the host starts it), `started`. */
|
|
46
|
+
start() {
|
|
47
|
+
return this.runtime.call(this.nodeType, this.key, 'start', null, { action: true });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Moves the player's unit to `(x, z)`.
|
|
51
|
+
* @throws {KitError} `not_your_turn`, `conflict` (it moved), `out_of_reach`, `not_member`.
|
|
52
|
+
*/
|
|
53
|
+
move(x, z) {
|
|
54
|
+
return this.runtime.call(this.nodeType, this.key, 'move', { x, z }, { action: true });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Attacks unit `target` with the player's unit.
|
|
58
|
+
* @throws {KitError} `not_your_turn`, `conflict` (it attacked), `out_of_reach`, `forbidden` (its own side), `not_found`.
|
|
59
|
+
*/
|
|
60
|
+
attack(target) {
|
|
61
|
+
return this.runtime.call(this.nodeType, this.key, 'attack', { target }, { action: true });
|
|
62
|
+
}
|
|
63
|
+
/** Ends the player's turn this phase. */
|
|
64
|
+
endTurn() {
|
|
65
|
+
return this.runtime.call(this.nodeType, this.key, 'end_turn', null, { action: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { HubState } from '../mirror.js';
|
|
2
|
+
import type { KitRuntime } from '../runtime.js';
|
|
3
|
+
export interface TerritoryPoint {
|
|
4
|
+
id: string;
|
|
5
|
+
owner: string | null;
|
|
6
|
+
/** The faction pressing a capture, and how far it is, 0 to 1. */
|
|
7
|
+
capturing: string | null;
|
|
8
|
+
progress: number;
|
|
9
|
+
/** Members on the point at the last scan, by faction. */
|
|
10
|
+
present: Record<string, number>;
|
|
11
|
+
}
|
|
12
|
+
/** What the `territory` topic carries. */
|
|
13
|
+
export interface TerritoryView {
|
|
14
|
+
phase: 'open' | 'won';
|
|
15
|
+
points: TerritoryPoint[];
|
|
16
|
+
scores: Record<string, number>;
|
|
17
|
+
/** Members by faction. */
|
|
18
|
+
members: Record<string, number>;
|
|
19
|
+
winner: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface ZoneContender {
|
|
22
|
+
player: number;
|
|
23
|
+
hp: number;
|
|
24
|
+
/** Outside the circle at the last scan. */
|
|
25
|
+
outside: boolean;
|
|
26
|
+
/** 1 for the winner; set as each player is eliminated. */
|
|
27
|
+
place: number | null;
|
|
28
|
+
}
|
|
29
|
+
/** What the `zone` topic carries. */
|
|
30
|
+
export interface ZoneView {
|
|
31
|
+
phase: 'lobby' | 'running' | 'finished';
|
|
32
|
+
/** The circle's centre, in chunks. */
|
|
33
|
+
center: [number, number];
|
|
34
|
+
radius: number;
|
|
35
|
+
/** The phase under way, and the radius it shrinks to. */
|
|
36
|
+
stage: number | null;
|
|
37
|
+
next_radius: number | null;
|
|
38
|
+
players: ZoneContender[];
|
|
39
|
+
alive: number;
|
|
40
|
+
winner: number | null;
|
|
41
|
+
}
|
|
42
|
+
/** Control points and shrinking circles (the `territory` starter, types `territory` and `zone`). */
|
|
43
|
+
export declare class TerritoryKit {
|
|
44
|
+
private readonly runtime;
|
|
45
|
+
private readonly territoryType;
|
|
46
|
+
private readonly zoneType;
|
|
47
|
+
private readonly maps;
|
|
48
|
+
private readonly zones;
|
|
49
|
+
constructor(runtime: KitRuntime, territoryType?: string, zoneType?: string);
|
|
50
|
+
/** The war on map `key`. */
|
|
51
|
+
map(key: string): TerritoryMap;
|
|
52
|
+
/** The circle of match `key`. */
|
|
53
|
+
zone(key: string): ZoneMatch;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* One war over a map's control points: a faction captures a point by having more members standing
|
|
57
|
+
* on it than any other (the hub reads where players are; a client never says it is on a point),
|
|
58
|
+
* a capture decays when nobody presses it, each point held pays its faction, and the first to the
|
|
59
|
+
* winning score wins. `view.onEvent` hears `captured`, `income` and `won`.
|
|
60
|
+
*/
|
|
61
|
+
export declare class TerritoryMap {
|
|
62
|
+
private readonly runtime;
|
|
63
|
+
readonly nodeType: string;
|
|
64
|
+
readonly key: string;
|
|
65
|
+
readonly view: HubState<TerritoryView>;
|
|
66
|
+
constructor(runtime: KitRuntime, nodeType: string, key: string);
|
|
67
|
+
watch(): Promise<TerritoryView>;
|
|
68
|
+
unwatch(): Promise<void>;
|
|
69
|
+
/** Joins a faction, once: a player keeps theirs. @throws {KitError} `conflict`, `bad_request`, `full`. */
|
|
70
|
+
join(faction: string): Promise<boolean>;
|
|
71
|
+
/** A new war. Developers only. */
|
|
72
|
+
reset(): Promise<boolean>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One match's circle: it holds, then shrinks, phase by phase, and wears down every player outside
|
|
76
|
+
* it (the hub reads where players are) until one is left. `view.onEvent` hears `warning`,
|
|
77
|
+
* `shrinking`, `settled`, `final`, `eliminated` and `won`.
|
|
78
|
+
*/
|
|
79
|
+
export declare class ZoneMatch {
|
|
80
|
+
private readonly runtime;
|
|
81
|
+
readonly nodeType: string;
|
|
82
|
+
readonly key: string;
|
|
83
|
+
readonly view: HubState<ZoneView>;
|
|
84
|
+
constructor(runtime: KitRuntime, nodeType: string, key: string);
|
|
85
|
+
watch(): Promise<ZoneView>;
|
|
86
|
+
unwatch(): Promise<void>;
|
|
87
|
+
/** @throws {KitError} `started`, `full`. */
|
|
88
|
+
join(): Promise<boolean>;
|
|
89
|
+
/** The first to join, or a developer. @throws {KitError} `forbidden`, `not_ready`, `started`. */
|
|
90
|
+
start(): Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=territory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"territory.d.ts","sourceRoot":"","sources":["../../../src/kit/modules/territory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,C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,MAAM;IAKtB,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,4CAA4C;IAC5C,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxB,iGAAiG;IACjG,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;CAG1B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { HubState } from '../mirror.js';
|
|
2
|
+
/** Control points and shrinking circles (the `territory` starter, types `territory` and `zone`). */
|
|
3
|
+
export class TerritoryKit {
|
|
4
|
+
constructor(runtime, territoryType = 'territory', zoneType = 'zone') {
|
|
5
|
+
this.runtime = runtime;
|
|
6
|
+
this.territoryType = territoryType;
|
|
7
|
+
this.zoneType = zoneType;
|
|
8
|
+
this.maps = new Map();
|
|
9
|
+
this.zones = new Map();
|
|
10
|
+
}
|
|
11
|
+
/** The war on map `key`. */
|
|
12
|
+
map(key) {
|
|
13
|
+
let m = this.maps.get(key);
|
|
14
|
+
if (!m) {
|
|
15
|
+
m = new TerritoryMap(this.runtime, this.territoryType, key);
|
|
16
|
+
this.maps.set(key, m);
|
|
17
|
+
}
|
|
18
|
+
return m;
|
|
19
|
+
}
|
|
20
|
+
/** The circle of match `key`. */
|
|
21
|
+
zone(key) {
|
|
22
|
+
let z = this.zones.get(key);
|
|
23
|
+
if (!z) {
|
|
24
|
+
z = new ZoneMatch(this.runtime, this.zoneType, key);
|
|
25
|
+
this.zones.set(key, z);
|
|
26
|
+
}
|
|
27
|
+
return z;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One war over a map's control points: a faction captures a point by having more members standing
|
|
32
|
+
* on it than any other (the hub reads where players are; a client never says it is on a point),
|
|
33
|
+
* a capture decays when nobody presses it, each point held pays its faction, and the first to the
|
|
34
|
+
* winning score wins. `view.onEvent` hears `captured`, `income` and `won`.
|
|
35
|
+
*/
|
|
36
|
+
export class TerritoryMap {
|
|
37
|
+
constructor(runtime, nodeType, key) {
|
|
38
|
+
this.runtime = runtime;
|
|
39
|
+
this.nodeType = nodeType;
|
|
40
|
+
this.key = key;
|
|
41
|
+
this.view = new HubState(runtime, nodeType, key, 'territory');
|
|
42
|
+
}
|
|
43
|
+
watch() {
|
|
44
|
+
return this.view.start();
|
|
45
|
+
}
|
|
46
|
+
unwatch() {
|
|
47
|
+
return this.view.stop();
|
|
48
|
+
}
|
|
49
|
+
/** Joins a faction, once: a player keeps theirs. @throws {KitError} `conflict`, `bad_request`, `full`. */
|
|
50
|
+
join(faction) {
|
|
51
|
+
return this.runtime.call(this.nodeType, this.key, 'join', { faction }, { action: true });
|
|
52
|
+
}
|
|
53
|
+
/** A new war. Developers only. */
|
|
54
|
+
reset() {
|
|
55
|
+
return this.runtime.call(this.nodeType, this.key, 'reset', null, { action: true });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* One match's circle: it holds, then shrinks, phase by phase, and wears down every player outside
|
|
60
|
+
* it (the hub reads where players are) until one is left. `view.onEvent` hears `warning`,
|
|
61
|
+
* `shrinking`, `settled`, `final`, `eliminated` and `won`.
|
|
62
|
+
*/
|
|
63
|
+
export class ZoneMatch {
|
|
64
|
+
constructor(runtime, nodeType, key) {
|
|
65
|
+
this.runtime = runtime;
|
|
66
|
+
this.nodeType = nodeType;
|
|
67
|
+
this.key = key;
|
|
68
|
+
this.view = new HubState(runtime, nodeType, key, 'zone');
|
|
69
|
+
}
|
|
70
|
+
watch() {
|
|
71
|
+
return this.view.start();
|
|
72
|
+
}
|
|
73
|
+
unwatch() {
|
|
74
|
+
return this.view.stop();
|
|
75
|
+
}
|
|
76
|
+
/** @throws {KitError} `started`, `full`. */
|
|
77
|
+
join() {
|
|
78
|
+
return this.runtime.call(this.nodeType, this.key, 'join', null, { action: true });
|
|
79
|
+
}
|
|
80
|
+
/** The first to join, or a developer. @throws {KitError} `forbidden`, `not_ready`, `started`. */
|
|
81
|
+
start() {
|
|
82
|
+
return this.runtime.call(this.nodeType, this.key, 'start', null, { action: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
package/dist/kit/protocol.d.ts
CHANGED
|
@@ -90,6 +90,8 @@ export declare const KIT_CODES: {
|
|
|
90
90
|
readonly EXPIRED: "expired";
|
|
91
91
|
readonly INSUFFICIENT: "insufficient";
|
|
92
92
|
readonly ALREADY_DONE: "already_done";
|
|
93
|
+
/** A hub the call needed did not answer: the kit sends it again with its action id. */
|
|
94
|
+
readonly UNAVAILABLE: "unavailable";
|
|
93
95
|
};
|
|
94
96
|
/**
|
|
95
97
|
* A kit hub refused the call (`AppError` with a `kit:<code>:` message): `code` is what to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/kit/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,sDAAsD;AACtD,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;AAExE,4CAA4C;AAC5C,MAAM,WAAW,SAAS;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MA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ED: 'expired',
|
|
82
82
|
INSUFFICIENT: 'insufficient',
|
|
83
83
|
ALREADY_DONE: 'already_done',
|
|
84
|
+
/** A hub the call needed did not answer: the kit sends it again with its action id. */
|
|
85
|
+
UNAVAILABLE: 'unavailable',
|
|
84
86
|
};
|
|
85
87
|
/**
|
|
86
88
|
* A kit hub refused the call (`AppError` with a `kit:<code>:` message): `code` is what to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/kit/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAG5B,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,uDAAuD;AACvD,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,6FAA6F;IAC7F,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,sDAAsD;AACtD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA8CD;;;;;;GAMG;AACH,qBAAa,UAAU;IAYnB,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ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xD,2CAA2C;IACrC,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;YAY7B,IAAI;IAmBlB,mFAAmF;IAC7E,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQxC;;;OAGG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EACpB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC;IAgCb;;;;OAIG;IACG,SAAS,CAAC,CAAC,GAAG,OAAO,EACzB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IA2B/B,sDAAsD;IACtD,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,yFAAyF;IACzF,WAAW,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAKzD,wFAAwF;IACxF,aAAa,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAK7D,mEAAmE;IACnE,KAAK,IAAI,IAAI;CAMd"}
|
package/dist/kit/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CrowdyExecError, } from '../domains/exec.js';
|
|
2
|
-
import { KitError, newActionId, withActionId } from './protocol.js';
|
|
2
|
+
import { KIT_CODES, KitError, newActionId, withActionId } from './protocol.js';
|
|
3
3
|
/** Subscriptions one connection holds at most (the gateway refuses the next). */
|
|
4
4
|
export const KIT_SUBSCRIPTIONS_MAX = 256;
|
|
5
5
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -120,6 +120,11 @@ export class KitRuntime {
|
|
|
120
120
|
}
|
|
121
121
|
catch (e) {
|
|
122
122
|
const err = KitError.from(e);
|
|
123
|
+
// A hub that could not hear from another one did not finish, and keeps no receipt.
|
|
124
|
+
if (attempt < this.retries && actionId && err instanceof KitError && err.code === KIT_CODES.UNAVAILABLE) {
|
|
125
|
+
await sleep(Math.min(2000, 200 * 2 ** attempt) * (0.5 + Math.random() / 2));
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
123
128
|
if (attempt < this.retries && err instanceof CrowdyExecError && !(err instanceof KitError)) {
|
|
124
129
|
if (err.status === 'Busy' && err.rateLimited) {
|
|
125
130
|
this.budget.hold(err.retryAfterMs ?? 1000);
|