@persistica/flux-mesh 0.0.26 → 0.0.27
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/index.js +30 -30
- package/package.json +1 -1
- package/src/_managers/authority.manager.d.ts +2 -2
- package/src/_managers/global/global-client.manager.d.ts +2 -0
- package/src/_managers/local/local-authority.manager.d.ts +2 -2
- package/src/_routes/auth/network-client.post.route.d.ts +3 -3
- package/src/business-logic/channels/channel-manager.class.d.ts +5 -14
- package/src/business-logic/channels/channel-manager.utils.d.ts +4 -0
- package/src/business-logic/processes/process.class.d.ts +27 -0
- package/src/main.d.ts +1 -0
- package/src/register/network-agent-redis-cache.class.d.ts +1 -1
- package/src/register/{network-authority-redis-cache.class.d.ts → network-authority-cache.class.d.ts} +1 -1
- package/src/routing/redis/redis-connection.class.d.ts +23 -14
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TAddress, type TClientId } from '@flux/shared/types';
|
|
2
2
|
import { RedisConnection } from '../routing/redis/redis-connection.class';
|
|
3
3
|
import { TConnectedClientSocket } from '../connected-client-socket.types';
|
|
4
|
-
import {
|
|
4
|
+
import { NetworkAuthorityCache } from '../register/network-authority-cache.class';
|
|
5
5
|
export declare class AuthorityManager {
|
|
6
6
|
private readonly _redisConnection;
|
|
7
7
|
private readonly _clientMap;
|
|
@@ -10,6 +10,6 @@ export declare class AuthorityManager {
|
|
|
10
10
|
private readonly processAddress;
|
|
11
11
|
private readonly _globalClientManager;
|
|
12
12
|
private readonly _localAuthorityManager;
|
|
13
|
-
constructor(_redisConnection: RedisConnection, _clientMap: Map<TClientId, TConnectedClientSocket>, _networkAuthorityRedisCache:
|
|
13
|
+
constructor(_redisConnection: RedisConnection, _clientMap: Map<TClientId, TConnectedClientSocket>, _networkAuthorityRedisCache: NetworkAuthorityCache);
|
|
14
14
|
kick(authorityAddress: TAddress): void;
|
|
15
15
|
}
|
|
@@ -8,6 +8,8 @@ import { RedisConnection } from '../../routing/redis/redis-connection.class';
|
|
|
8
8
|
export declare class GlobalClientManager {
|
|
9
9
|
private readonly _redisConnection;
|
|
10
10
|
private readonly processAddress;
|
|
11
|
+
private readonly networkAgentRedisService;
|
|
12
|
+
private readonly networkAuthorityRedisService;
|
|
11
13
|
constructor(_redisConnection: RedisConnection);
|
|
12
14
|
/**
|
|
13
15
|
* Sends a global message to kick a client.
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { TClientId } from '@flux/shared/types';
|
|
5
5
|
import type { TConnectedClientSocket } from '../../connected-client-socket.types';
|
|
6
|
-
import {
|
|
6
|
+
import { NetworkAuthorityCache } from '../../register/network-authority-cache.class';
|
|
7
7
|
export declare class LocalAuthorityManager {
|
|
8
8
|
private readonly _clientMap;
|
|
9
9
|
private readonly _networkAuthorityRedisCache;
|
|
10
|
-
constructor(_clientMap: Map<TClientId, TConnectedClientSocket>, _networkAuthorityRedisCache:
|
|
10
|
+
constructor(_clientMap: Map<TClientId, TConnectedClientSocket>, _networkAuthorityRedisCache: NetworkAuthorityCache);
|
|
11
11
|
kickAuthority(clientId: TClientId): Promise<void>;
|
|
12
12
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { BunRequest } from 'bun';
|
|
2
2
|
import type { GlobalRPCClient } from '../../routing/rpc/core/global-rpc-client.class';
|
|
3
|
-
import type {
|
|
3
|
+
import type { NetworkAuthorityCache } from '../../register/network-authority-cache.class';
|
|
4
4
|
/**
|
|
5
5
|
* This route is used to authorize an agent connection.
|
|
6
6
|
*
|
|
7
7
|
* @param { BunRequest } request - The incoming HTTP request
|
|
8
|
-
* @param {
|
|
8
|
+
* @param { NetworkAuthorityCache } networkAuthorityManager - The network authority manager
|
|
9
9
|
* @param { GlobalRPCClient<'authorizeAgentConnection'> } globalRPCClient - The global RPC client
|
|
10
10
|
*
|
|
11
11
|
* @returns { Promise<Response> } The HTTP response with auth token or error
|
|
12
12
|
*/
|
|
13
|
-
export declare const authorizeAgentConnection: (request: BunRequest, networkAuthorityManager:
|
|
13
|
+
export declare const authorizeAgentConnection: (request: BunRequest, networkAuthorityManager: NetworkAuthorityCache, globalRPCClient: GlobalRPCClient<"authorizeAgentConnection">) => Promise<Response>;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { type TAddress, type TChannelName, type TNetworkId_S, type TSubscription_S } from '@flux/shared/types';
|
|
2
2
|
import type { GlobalChannelPubsub } from '../../routing/global-channel/global-channel-pubsub.class';
|
|
3
|
-
export declare const MAX_CHANNEL_MEMBERS_BY_SUBSCRIPTION_TYPE: {
|
|
4
|
-
[key in TSubscription_S]: number;
|
|
5
|
-
};
|
|
6
|
-
export declare const MAX_CHANNEL_MEMBERS: number;
|
|
7
|
-
export declare const normalizeSubscriptionType: (subscriptionType?: unknown) => TSubscription_S | undefined;
|
|
8
|
-
export declare const resolveSubscriptionTypeOrDefault: (subscriptionType?: unknown) => TSubscription_S;
|
|
9
|
-
export declare const readMaxChannelMembers: (subscriptionType?: unknown) => number;
|
|
10
|
-
export declare const readSubscriptionTypeFromClaim: (claim?: unknown) => TSubscription_S | undefined;
|
|
11
|
-
export declare const canChannelHaveMoreMembers: (memberCount: number, subscriptionType?: TSubscription_S) => boolean;
|
|
12
3
|
export declare class NetworkChannelManager {
|
|
13
4
|
private readonly _globalChannelPubsub;
|
|
14
5
|
private readonly channelUsageCount;
|
|
15
6
|
private readonly redisConnection;
|
|
16
|
-
private readonly
|
|
7
|
+
private readonly networkChannelService;
|
|
17
8
|
constructor(_globalChannelPubsub: GlobalChannelPubsub);
|
|
18
9
|
/**
|
|
19
10
|
* Checks if a channel can have more members.
|
|
@@ -33,12 +24,12 @@ export declare class NetworkChannelManager {
|
|
|
33
24
|
* Leaves all network channels.
|
|
34
25
|
*/
|
|
35
26
|
leaveAllNetworkChannels(networkId: TNetworkId_S, clientAddress: TAddress, channelNames: Set<TChannelName>): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a network channel if it does not exist.
|
|
38
|
-
*/
|
|
39
|
-
private createNetworkChannelIfNotExist;
|
|
40
27
|
/**
|
|
41
28
|
* Increases the usage count of a channel.
|
|
42
29
|
*/
|
|
43
30
|
increaseUsageCount(networkId: TNetworkId_S, channelName: TChannelName, usage: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a network channel if it does not exist.
|
|
33
|
+
*/
|
|
34
|
+
private createNetworkChannelIfNotExist;
|
|
44
35
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TSubscription_S } from '@flux/shared/types';
|
|
2
|
+
export declare const resolveSubscriptionTypeOrDefault: (subscriptionType?: unknown) => TSubscription_S;
|
|
3
|
+
export declare const readSubscriptionTypeFromClaim: (claim?: unknown) => TSubscription_S | undefined;
|
|
4
|
+
export declare const canChannelHaveMoreMembers: (memberCount: number, subscriptionType?: TSubscription_S) => boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type TProcessAddress, type TMachineAddress } from '@flux/shared/types';
|
|
2
|
+
import { RedisConnection } from '../../routing/redis/redis-connection.class';
|
|
3
|
+
import { NetworkChannelManager } from '../channels/channel-manager.class';
|
|
4
|
+
export declare class ProcessClass {
|
|
5
|
+
private readonly _redisConnection;
|
|
6
|
+
private readonly _networkChannelManager;
|
|
7
|
+
private readonly networkAgentRedisRepository;
|
|
8
|
+
private readonly networkChannelService;
|
|
9
|
+
private readonly networkAgentRedisService;
|
|
10
|
+
constructor(_redisConnection: RedisConnection, _networkChannelManager: NetworkChannelManager);
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
cleanupOrphans(machineAddress: TMachineAddress): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Marks the given address as connected in Redis.
|
|
17
|
+
*/
|
|
18
|
+
setConnected(processAddress: TProcessAddress): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Marks the given address as disconnected in Redis.
|
|
21
|
+
*/
|
|
22
|
+
setDisconnected(processAddress: TProcessAddress): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns up to 3 lost processes while prioritizing ones that have been running on this machine, and oldest.
|
|
25
|
+
*/
|
|
26
|
+
private readDisconnectedAddresses;
|
|
27
|
+
}
|
package/src/main.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class FluxMeshServer {
|
|
|
12
12
|
private readonly globalChannelPubsub;
|
|
13
13
|
private readonly channelManager;
|
|
14
14
|
private readonly agentManager;
|
|
15
|
+
private readonly processClass;
|
|
15
16
|
constructor(optionsOrPort?: (TOptions | number) | undefined);
|
|
16
17
|
onReady(fn: () => void): void;
|
|
17
18
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NetworkAgentRedisService } from '@flux/mesh/store/redis/network-agent';
|
|
2
2
|
import { NetworkUsageRedisCacheService } from '@flux/mesh/store/redis/network-usage';
|
|
3
3
|
import type { TAddress, TClientId, TAgentOwnUId, TNetworkId_S } from '@flux/shared/types';
|
|
4
4
|
import type { TFluxClientUID } from '@flux/shared/utils';
|
package/src/register/{network-authority-redis-cache.class.d.ts → network-authority-cache.class.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TAddress, type TClientId, type TNetworkId_S } from '@flux/shared/types';
|
|
2
2
|
import type { TFluxClientUID } from '@flux/shared/utils';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class NetworkAuthorityCache {
|
|
4
4
|
private readonly redisConnection;
|
|
5
5
|
private readonly cache;
|
|
6
6
|
private readonly clientCache;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { TAddress, TClientId, TNetworkId_S, TNetworkToken_S, TProcessAddress } from '@flux/shared/types';
|
|
2
|
-
import { NetworkAuthorityRedisSortedSet } from '@flux/mesh/store/redis/network-authority';
|
|
3
|
-
import { NetworkAgentRedisService } from '@flux/mesh/store/redis/network-agent';
|
|
4
2
|
import type { TGlobalChannel } from '../global-channel/global-channel-pubsub.class';
|
|
5
3
|
/**
|
|
6
4
|
* Singleton function to get the Redis connection.
|
|
@@ -12,17 +10,16 @@ import type { TGlobalChannel } from '../global-channel/global-channel-pubsub.cla
|
|
|
12
10
|
export declare const getMeshRedisConnection: (_connectionString?: string) => RedisConnection;
|
|
13
11
|
export type MessageCallback = (message: string, channel?: string) => unknown;
|
|
14
12
|
export declare class RedisConnection {
|
|
15
|
-
private readonly _optionsOrURL;
|
|
16
13
|
private readonly cacheClient;
|
|
17
14
|
private readonly pubSub;
|
|
18
|
-
readonly networkAuthoritySet: NetworkAuthorityRedisSortedSet;
|
|
19
|
-
readonly networkAgentRedisService: NetworkAgentRedisService;
|
|
20
15
|
readonly hash: {
|
|
21
16
|
sadd: (key: Bun.RedisClient.KeyLike, ...members: string[]) => Promise<number>;
|
|
22
17
|
hset: {
|
|
23
18
|
(key: Bun.RedisClient.KeyLike, fields: Record<string | number, Bun.RedisClient.KeyLike | number>): Promise<number>;
|
|
24
19
|
(key: Bun.RedisClient.KeyLike, field: Bun.RedisClient.KeyLike, value: Bun.RedisClient.KeyLike, ...rest: Bun.RedisClient.KeyLike[]): Promise<number>;
|
|
25
20
|
};
|
|
21
|
+
hget: (key: Bun.RedisClient.KeyLike, field: Bun.RedisClient.KeyLike) => Promise<string | null>;
|
|
22
|
+
hdel: (key: Bun.RedisClient.KeyLike, field: Bun.RedisClient.KeyLike, ...rest: Bun.RedisClient.KeyLike[]) => Promise<number>;
|
|
26
23
|
smembers: (key: Bun.RedisClient.KeyLike) => Promise<string[]>;
|
|
27
24
|
srem: (key: Bun.RedisClient.KeyLike, ...members: string[]) => Promise<number>;
|
|
28
25
|
scard: (key: Bun.RedisClient.KeyLike) => Promise<number>;
|
|
@@ -34,7 +31,25 @@ export declare class RedisConnection {
|
|
|
34
31
|
};
|
|
35
32
|
expire: (key: Bun.RedisClient.KeyLike, seconds: number) => Promise<number>;
|
|
36
33
|
};
|
|
37
|
-
|
|
34
|
+
readonly sortedSet: {
|
|
35
|
+
zadd: (key: Bun.RedisClient.KeyLike, ...args: (string | number)[]) => Promise<number>;
|
|
36
|
+
zrem: (key: Bun.RedisClient.KeyLike, member: Bun.RedisClient.KeyLike, ...members: Bun.RedisClient.KeyLike[]) => Promise<number>;
|
|
37
|
+
zscore: (key: Bun.RedisClient.KeyLike, member: string) => Promise<number | null>;
|
|
38
|
+
zrangebylex: {
|
|
39
|
+
(key: Bun.RedisClient.KeyLike, min: string, max: string): Promise<string[]>;
|
|
40
|
+
(key: Bun.RedisClient.KeyLike, min: string, max: string, limit: "LIMIT", offset: number, count: number): Promise<string[]>;
|
|
41
|
+
(key: Bun.RedisClient.KeyLike, min: string, max: string, ...options: (string | number)[]): Promise<string[]>;
|
|
42
|
+
};
|
|
43
|
+
zrangebyscore: {
|
|
44
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number): Promise<string[]>;
|
|
45
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number, withscores: "WITHSCORES"): Promise<[string, number][]>;
|
|
46
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number, limit: "LIMIT", offset: number, count: number): Promise<string[]>;
|
|
47
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number, withscores: "WITHSCORES", ...options: (string | number)[]): Promise<[string, number][]>;
|
|
48
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number, withscores: "WITHSCORES", limit: "LIMIT", offset: number, count: number, ...options: (string | number)[]): Promise<[string, number][]>;
|
|
49
|
+
(key: Bun.RedisClient.KeyLike, min: string | number, max: string | number, ...options: (string | number)[]): Promise<string[]>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
constructor(optionsOrURL: string | {
|
|
38
53
|
name?: string;
|
|
39
54
|
url: string;
|
|
40
55
|
});
|
|
@@ -76,6 +91,8 @@ export declare class RedisConnection {
|
|
|
76
91
|
getNetworkTokenValues(networkId: TNetworkId_S): Promise<TNetworkToken_S[]>;
|
|
77
92
|
publishCustom(subChannel: 'kick-client-agent' | 'kick-client-authority', destinationProcessAddress: TProcessAddress, message: string): Promise<number>;
|
|
78
93
|
subscribeToCustom(subChannel: 'kick-client-agent' | 'kick-client-authority', destinationProcessAddress: TProcessAddress, callback: (data: string) => void): void;
|
|
94
|
+
publishGlobal(networkId: TNetworkId_S, channel: 'agent-count-change' | `agent-throughput` | 'agent-created' | 'agent-deleted' | 'authority-count-change' | 'authority-created' | 'authority-deleted' | 'channel-created' | 'channel-usage' | 'channel-count' | 'channel-updated' | 'channel-deleted', message: string): Promise<number>;
|
|
95
|
+
subscribeGlobal(networkId: TNetworkId_S, channel: 'agent-count-change' | `agent-throughput` | 'agent-created' | 'agent-deleted' | 'authority-count-change' | 'authority-created' | 'authority-deleted' | 'channel-created' | 'channel-usage' | 'channel-count' | 'channel-updated' | 'channel-deleted', callback: (data: string) => void): Promise<void>;
|
|
79
96
|
/**
|
|
80
97
|
* Publishes a message directly to an address.
|
|
81
98
|
*/
|
|
@@ -97,14 +114,6 @@ export declare class RedisConnection {
|
|
|
97
114
|
* Unsubscribes a callback from data packets on a specific network channel.
|
|
98
115
|
*/
|
|
99
116
|
unsubscribeFromNetworkChannel(networkId: string, channelName: string, callback: (clientId: TClientId, data: string) => void): void;
|
|
100
|
-
/**
|
|
101
|
-
* Marks the given address as connected in Redis.
|
|
102
|
-
*/
|
|
103
|
-
setConnected(address: string): Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Marks the given address as disconnected in Redis.
|
|
106
|
-
*/
|
|
107
|
-
setDisconnected(_address: string): Promise<void>;
|
|
108
117
|
/**
|
|
109
118
|
* Disconnects the Redis cache and pub/sub.
|
|
110
119
|
*
|