@fluxerjs/core 1.4.0 → 2.0.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/README.md +8 -1
- package/dist/client.d.mts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +3958 -2632
- package/dist/client.mjs +3957 -2630
- package/dist/cluster.d.mts +153 -0
- package/dist/cluster.d.ts +153 -0
- package/dist/cluster.js +5730 -0
- package/dist/cluster.mjs +5718 -0
- package/dist/index.d.mts +19 -36
- package/dist/index.d.ts +19 -36
- package/dist/index.js +4414 -2666
- package/dist/index.mjs +4462 -2742
- package/dist/message.d.mts +3 -3
- package/dist/message.d.ts +3 -3
- package/dist/message.js +358 -257
- package/dist/message.mjs +359 -255
- package/dist/subpath-message-Acbzr5HA.d.mts +2725 -0
- package/dist/subpath-message-Acbzr5HA.d.ts +2725 -0
- package/package.json +14 -9
- package/dist/subpath-message-DSs_mdc4.d.mts +0 -2179
- package/dist/subpath-message-DSs_mdc4.d.ts +0 -2179
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-Acbzr5HA.mjs';
|
|
3
|
+
import '@fluxerjs/collection';
|
|
4
|
+
import '@fluxerjs/types';
|
|
5
|
+
import '@fluxerjs/rest';
|
|
6
|
+
import '@fluxerjs/ws';
|
|
7
|
+
import '@fluxerjs/builders';
|
|
8
|
+
import '@fluxerjs/util';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @beta ClientCluster lifecycle event names.
|
|
12
|
+
* These are supervisor events — bot gateway events stay on each runtime's `client`.
|
|
13
|
+
*/
|
|
14
|
+
declare const ClientClusterEvents: {
|
|
15
|
+
readonly RuntimeAdded: "runtimeAdded";
|
|
16
|
+
readonly RuntimeReady: "runtimeReady";
|
|
17
|
+
readonly RuntimeRemoved: "runtimeRemoved";
|
|
18
|
+
readonly RuntimeError: "runtimeError";
|
|
19
|
+
};
|
|
20
|
+
type ClientClusterEventName = (typeof ClientClusterEvents)[keyof typeof ClientClusterEvents];
|
|
21
|
+
/**
|
|
22
|
+
* @beta Typed payloads for {@link ClientCluster} lifecycle events.
|
|
23
|
+
*/
|
|
24
|
+
interface ClientClusterEventMap {
|
|
25
|
+
[ClientClusterEvents.RuntimeAdded]: [runtime: ClientRuntime];
|
|
26
|
+
[ClientClusterEvents.RuntimeReady]: [runtime: ClientRuntime];
|
|
27
|
+
[ClientClusterEvents.RuntimeRemoved]: [runtime: ClientRuntime];
|
|
28
|
+
[ClientClusterEvents.RuntimeError]: [runtime: ClientRuntime, error: Error];
|
|
29
|
+
}
|
|
30
|
+
type ClientClusterEventListener<K extends keyof ClientClusterEventMap> = (...args: ClientClusterEventMap[K]) => void;
|
|
31
|
+
|
|
32
|
+
/** @beta Warning emitted once per process when a ClientCluster is constructed. */
|
|
33
|
+
declare const BETA_CLIENT_CLUSTER_WARNING: string;
|
|
34
|
+
/** @beta Lifecycle status for a managed runtime. */
|
|
35
|
+
type ClientRuntimeStatus = 'connecting' | 'connected' | 'ready' | 'error' | 'disconnecting' | 'destroyed';
|
|
36
|
+
/**
|
|
37
|
+
* @beta A managed Client inside a {@link ClientCluster}.
|
|
38
|
+
* Does not store or expose the bot token.
|
|
39
|
+
*/
|
|
40
|
+
interface ClientRuntime {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly client: Client;
|
|
43
|
+
readonly status: ClientRuntimeStatus;
|
|
44
|
+
/** Last client error, if any. Never includes the bot token. */
|
|
45
|
+
readonly lastError?: Error;
|
|
46
|
+
}
|
|
47
|
+
/** @beta Options for constructing a ClientCluster. */
|
|
48
|
+
interface ClientClusterOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Called before `login` for every successfully constructed client.
|
|
51
|
+
* Attach message/event handlers here so dynamically-added runtimes get the same wiring.
|
|
52
|
+
*/
|
|
53
|
+
configure?: (runtime: ClientRuntime) => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Suppress the process-level beta warning (tests / controlled deployments only).
|
|
56
|
+
* Default: `false`.
|
|
57
|
+
*/
|
|
58
|
+
suppressBetaWarning?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @beta Input for {@link ClientCluster.add}.
|
|
62
|
+
* Exactly one of `discovery`, `clientOptions`, or `client` may be used to build the client
|
|
63
|
+
* (or none — hosted defaults). `token` is always required and must be issued by that instance.
|
|
64
|
+
*/
|
|
65
|
+
interface AddClientRuntimeOptions {
|
|
66
|
+
/** Unique runtime id within this cluster (not a snowflake). */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Bot token issued by the target instance. Required; never shared across runtimes. */
|
|
69
|
+
token: string;
|
|
70
|
+
/** Discover endpoints via `GET /.well-known/fluxer` from this origin. */
|
|
71
|
+
discovery?: DiscoveryOrigin;
|
|
72
|
+
/** Construct a new Client with these options (ignored when `client` or `discovery` is set). */
|
|
73
|
+
clientOptions?: ClientOptions;
|
|
74
|
+
/** Prebuilt, not-yet-logged-in Client. Must not already be connected. */
|
|
75
|
+
client?: Client;
|
|
76
|
+
/** Abort signal for this add operation (also aborted by `remove` / `destroy`). */
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
/** @beta Options for {@link ClientCluster.restart}. Token must be re-supplied (never stored). */
|
|
80
|
+
interface RestartClientRuntimeOptions {
|
|
81
|
+
/** Bot token issued by the target instance. */
|
|
82
|
+
token: string;
|
|
83
|
+
signal?: AbortSignal;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @beta In-memory supervisor for multiple independently-tokened Fluxer clients in one process.
|
|
87
|
+
*
|
|
88
|
+
* - One {@link Client} per runtime / instance
|
|
89
|
+
* - Add and remove runtimes without restarting the process
|
|
90
|
+
* - No required “main” instance
|
|
91
|
+
* - Tokens are never stored on the runtime object
|
|
92
|
+
*
|
|
93
|
+
* **Beta:** API shape may change. Prefer attaching handlers via `configure`.
|
|
94
|
+
*/
|
|
95
|
+
declare class ClientCluster extends EventEmitter {
|
|
96
|
+
private readonly runtimes;
|
|
97
|
+
private readonly pending;
|
|
98
|
+
private readonly configure?;
|
|
99
|
+
private destroyed;
|
|
100
|
+
constructor(options?: ClientClusterOptions);
|
|
101
|
+
on<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
102
|
+
on(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
103
|
+
once<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
104
|
+
once(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
105
|
+
off<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
106
|
+
off(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
107
|
+
emit<K extends keyof ClientClusterEventMap>(event: K, ...args: ClientClusterEventMap[K]): boolean;
|
|
108
|
+
emit(event: string | symbol, ...args: unknown[]): boolean;
|
|
109
|
+
/** Number of managed runtimes (including those still connecting). */
|
|
110
|
+
get size(): number;
|
|
111
|
+
has(id: string): boolean;
|
|
112
|
+
get(id: string): ClientRuntime | undefined;
|
|
113
|
+
/** Snapshot of current runtimes. */
|
|
114
|
+
values(): ClientRuntime[];
|
|
115
|
+
/**
|
|
116
|
+
* @beta Allocation-free iterator over current runtimes.
|
|
117
|
+
* Prefer this over {@link values} when you only need to iterate once.
|
|
118
|
+
*/
|
|
119
|
+
runtimeValues(): IterableIterator<ClientRuntime>;
|
|
120
|
+
/**
|
|
121
|
+
* @beta Add and connect a runtime. Requires a token issued by that instance.
|
|
122
|
+
* Safe to call while other runtimes are already connected.
|
|
123
|
+
*/
|
|
124
|
+
add(input: AddClientRuntimeOptions): Promise<ClientRuntime>;
|
|
125
|
+
/**
|
|
126
|
+
* @beta Add multiple runtimes concurrently. Uses `Promise.allSettled` so one failure
|
|
127
|
+
* does not abort the rest.
|
|
128
|
+
*/
|
|
129
|
+
addAll(inputs: readonly AddClientRuntimeOptions[]): Promise<PromiseSettledResult<ClientRuntime>[]>;
|
|
130
|
+
/**
|
|
131
|
+
* @beta Rebuild a runtime with a freshly supplied token (never stored on the cluster).
|
|
132
|
+
* Removes the existing runtime, then re-adds it with the same non-secret build config.
|
|
133
|
+
* Prebuilt-client runtimes cannot be restarted (`RuntimeConflict`).
|
|
134
|
+
*/
|
|
135
|
+
restart(id: string, opts: RestartClientRuntimeOptions): Promise<ClientRuntime>;
|
|
136
|
+
/**
|
|
137
|
+
* @beta Disconnect and remove a runtime. Idempotent — returns `false` if unknown.
|
|
138
|
+
* Does not affect other runtimes.
|
|
139
|
+
*/
|
|
140
|
+
remove(id: string): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* @beta Destroy every runtime and prevent further adds. Idempotent.
|
|
143
|
+
* Also clears cluster lifecycle listeners.
|
|
144
|
+
*/
|
|
145
|
+
destroy(): Promise<void>;
|
|
146
|
+
private toPublic;
|
|
147
|
+
private detachHandlers;
|
|
148
|
+
private runAdd;
|
|
149
|
+
}
|
|
150
|
+
/** @internal Test helper — reset process-level beta warning latch. */
|
|
151
|
+
declare function resetClientClusterBetaWarningForTests(): void;
|
|
152
|
+
|
|
153
|
+
export { type AddClientRuntimeOptions, BETA_CLIENT_CLUSTER_WARNING, ClientCluster, type ClientClusterEventListener, type ClientClusterEventMap, type ClientClusterEventName, ClientClusterEvents, type ClientClusterOptions, type ClientRuntime, type ClientRuntimeStatus, type RestartClientRuntimeOptions, resetClientClusterBetaWarningForTests };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-Acbzr5HA.js';
|
|
3
|
+
import '@fluxerjs/collection';
|
|
4
|
+
import '@fluxerjs/types';
|
|
5
|
+
import '@fluxerjs/rest';
|
|
6
|
+
import '@fluxerjs/ws';
|
|
7
|
+
import '@fluxerjs/builders';
|
|
8
|
+
import '@fluxerjs/util';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @beta ClientCluster lifecycle event names.
|
|
12
|
+
* These are supervisor events — bot gateway events stay on each runtime's `client`.
|
|
13
|
+
*/
|
|
14
|
+
declare const ClientClusterEvents: {
|
|
15
|
+
readonly RuntimeAdded: "runtimeAdded";
|
|
16
|
+
readonly RuntimeReady: "runtimeReady";
|
|
17
|
+
readonly RuntimeRemoved: "runtimeRemoved";
|
|
18
|
+
readonly RuntimeError: "runtimeError";
|
|
19
|
+
};
|
|
20
|
+
type ClientClusterEventName = (typeof ClientClusterEvents)[keyof typeof ClientClusterEvents];
|
|
21
|
+
/**
|
|
22
|
+
* @beta Typed payloads for {@link ClientCluster} lifecycle events.
|
|
23
|
+
*/
|
|
24
|
+
interface ClientClusterEventMap {
|
|
25
|
+
[ClientClusterEvents.RuntimeAdded]: [runtime: ClientRuntime];
|
|
26
|
+
[ClientClusterEvents.RuntimeReady]: [runtime: ClientRuntime];
|
|
27
|
+
[ClientClusterEvents.RuntimeRemoved]: [runtime: ClientRuntime];
|
|
28
|
+
[ClientClusterEvents.RuntimeError]: [runtime: ClientRuntime, error: Error];
|
|
29
|
+
}
|
|
30
|
+
type ClientClusterEventListener<K extends keyof ClientClusterEventMap> = (...args: ClientClusterEventMap[K]) => void;
|
|
31
|
+
|
|
32
|
+
/** @beta Warning emitted once per process when a ClientCluster is constructed. */
|
|
33
|
+
declare const BETA_CLIENT_CLUSTER_WARNING: string;
|
|
34
|
+
/** @beta Lifecycle status for a managed runtime. */
|
|
35
|
+
type ClientRuntimeStatus = 'connecting' | 'connected' | 'ready' | 'error' | 'disconnecting' | 'destroyed';
|
|
36
|
+
/**
|
|
37
|
+
* @beta A managed Client inside a {@link ClientCluster}.
|
|
38
|
+
* Does not store or expose the bot token.
|
|
39
|
+
*/
|
|
40
|
+
interface ClientRuntime {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly client: Client;
|
|
43
|
+
readonly status: ClientRuntimeStatus;
|
|
44
|
+
/** Last client error, if any. Never includes the bot token. */
|
|
45
|
+
readonly lastError?: Error;
|
|
46
|
+
}
|
|
47
|
+
/** @beta Options for constructing a ClientCluster. */
|
|
48
|
+
interface ClientClusterOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Called before `login` for every successfully constructed client.
|
|
51
|
+
* Attach message/event handlers here so dynamically-added runtimes get the same wiring.
|
|
52
|
+
*/
|
|
53
|
+
configure?: (runtime: ClientRuntime) => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Suppress the process-level beta warning (tests / controlled deployments only).
|
|
56
|
+
* Default: `false`.
|
|
57
|
+
*/
|
|
58
|
+
suppressBetaWarning?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @beta Input for {@link ClientCluster.add}.
|
|
62
|
+
* Exactly one of `discovery`, `clientOptions`, or `client` may be used to build the client
|
|
63
|
+
* (or none — hosted defaults). `token` is always required and must be issued by that instance.
|
|
64
|
+
*/
|
|
65
|
+
interface AddClientRuntimeOptions {
|
|
66
|
+
/** Unique runtime id within this cluster (not a snowflake). */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Bot token issued by the target instance. Required; never shared across runtimes. */
|
|
69
|
+
token: string;
|
|
70
|
+
/** Discover endpoints via `GET /.well-known/fluxer` from this origin. */
|
|
71
|
+
discovery?: DiscoveryOrigin;
|
|
72
|
+
/** Construct a new Client with these options (ignored when `client` or `discovery` is set). */
|
|
73
|
+
clientOptions?: ClientOptions;
|
|
74
|
+
/** Prebuilt, not-yet-logged-in Client. Must not already be connected. */
|
|
75
|
+
client?: Client;
|
|
76
|
+
/** Abort signal for this add operation (also aborted by `remove` / `destroy`). */
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
/** @beta Options for {@link ClientCluster.restart}. Token must be re-supplied (never stored). */
|
|
80
|
+
interface RestartClientRuntimeOptions {
|
|
81
|
+
/** Bot token issued by the target instance. */
|
|
82
|
+
token: string;
|
|
83
|
+
signal?: AbortSignal;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @beta In-memory supervisor for multiple independently-tokened Fluxer clients in one process.
|
|
87
|
+
*
|
|
88
|
+
* - One {@link Client} per runtime / instance
|
|
89
|
+
* - Add and remove runtimes without restarting the process
|
|
90
|
+
* - No required “main” instance
|
|
91
|
+
* - Tokens are never stored on the runtime object
|
|
92
|
+
*
|
|
93
|
+
* **Beta:** API shape may change. Prefer attaching handlers via `configure`.
|
|
94
|
+
*/
|
|
95
|
+
declare class ClientCluster extends EventEmitter {
|
|
96
|
+
private readonly runtimes;
|
|
97
|
+
private readonly pending;
|
|
98
|
+
private readonly configure?;
|
|
99
|
+
private destroyed;
|
|
100
|
+
constructor(options?: ClientClusterOptions);
|
|
101
|
+
on<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
102
|
+
on(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
103
|
+
once<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
104
|
+
once(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
105
|
+
off<K extends keyof ClientClusterEventMap>(event: K, listener: ClientClusterEventListener<K>): this;
|
|
106
|
+
off(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
107
|
+
emit<K extends keyof ClientClusterEventMap>(event: K, ...args: ClientClusterEventMap[K]): boolean;
|
|
108
|
+
emit(event: string | symbol, ...args: unknown[]): boolean;
|
|
109
|
+
/** Number of managed runtimes (including those still connecting). */
|
|
110
|
+
get size(): number;
|
|
111
|
+
has(id: string): boolean;
|
|
112
|
+
get(id: string): ClientRuntime | undefined;
|
|
113
|
+
/** Snapshot of current runtimes. */
|
|
114
|
+
values(): ClientRuntime[];
|
|
115
|
+
/**
|
|
116
|
+
* @beta Allocation-free iterator over current runtimes.
|
|
117
|
+
* Prefer this over {@link values} when you only need to iterate once.
|
|
118
|
+
*/
|
|
119
|
+
runtimeValues(): IterableIterator<ClientRuntime>;
|
|
120
|
+
/**
|
|
121
|
+
* @beta Add and connect a runtime. Requires a token issued by that instance.
|
|
122
|
+
* Safe to call while other runtimes are already connected.
|
|
123
|
+
*/
|
|
124
|
+
add(input: AddClientRuntimeOptions): Promise<ClientRuntime>;
|
|
125
|
+
/**
|
|
126
|
+
* @beta Add multiple runtimes concurrently. Uses `Promise.allSettled` so one failure
|
|
127
|
+
* does not abort the rest.
|
|
128
|
+
*/
|
|
129
|
+
addAll(inputs: readonly AddClientRuntimeOptions[]): Promise<PromiseSettledResult<ClientRuntime>[]>;
|
|
130
|
+
/**
|
|
131
|
+
* @beta Rebuild a runtime with a freshly supplied token (never stored on the cluster).
|
|
132
|
+
* Removes the existing runtime, then re-adds it with the same non-secret build config.
|
|
133
|
+
* Prebuilt-client runtimes cannot be restarted (`RuntimeConflict`).
|
|
134
|
+
*/
|
|
135
|
+
restart(id: string, opts: RestartClientRuntimeOptions): Promise<ClientRuntime>;
|
|
136
|
+
/**
|
|
137
|
+
* @beta Disconnect and remove a runtime. Idempotent — returns `false` if unknown.
|
|
138
|
+
* Does not affect other runtimes.
|
|
139
|
+
*/
|
|
140
|
+
remove(id: string): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* @beta Destroy every runtime and prevent further adds. Idempotent.
|
|
143
|
+
* Also clears cluster lifecycle listeners.
|
|
144
|
+
*/
|
|
145
|
+
destroy(): Promise<void>;
|
|
146
|
+
private toPublic;
|
|
147
|
+
private detachHandlers;
|
|
148
|
+
private runAdd;
|
|
149
|
+
}
|
|
150
|
+
/** @internal Test helper — reset process-level beta warning latch. */
|
|
151
|
+
declare function resetClientClusterBetaWarningForTests(): void;
|
|
152
|
+
|
|
153
|
+
export { type AddClientRuntimeOptions, BETA_CLIENT_CLUSTER_WARNING, ClientCluster, type ClientClusterEventListener, type ClientClusterEventMap, type ClientClusterEventName, ClientClusterEvents, type ClientClusterOptions, type ClientRuntime, type ClientRuntimeStatus, type RestartClientRuntimeOptions, resetClientClusterBetaWarningForTests };
|