alemonjs 2.1.18 → 2.1.20
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/lib/app/define-response.d.ts +0 -3
- package/lib/app/define-response.js +1 -5
- package/lib/app/define-router.d.ts +5 -0
- package/lib/app/define-router.js +20 -0
- package/lib/app/event-processor-cycleRoute.js +31 -5
- package/lib/app/hook-use-api.d.ts +14 -6
- package/lib/app/hook-use-api.js +80 -82
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +3 -2
- package/lib/app/load_modules/loadChild.js +1 -1
- package/lib/app/message-format.d.ts +30 -1
- package/lib/app/message-format.js +82 -1
- package/lib/app/store.js +14 -2
- package/lib/index.js +3 -2
- package/lib/types/event/index.d.ts +7 -0
- package/package.json +1 -1
- package/lib/app/define-chidren.d.ts +0 -2
- package/lib/app/define-chidren.js +0 -19
- package/lib/app/define-pl.ts +0 -0
- package/lib/cbp/core/connection-manager.d.ts +0 -18
- package/lib/cbp/core/connection-manager.js +0 -67
- package/lib/cbp/core/constants.d.ts +0 -19
- package/lib/cbp/core/constants.js +0 -23
- package/lib/cbp/core/load-balancer.d.ts +0 -37
- package/lib/cbp/core/load-balancer.js +0 -118
- package/lib/cbp/processor/heandle.d.ts +0 -3
- package/lib/cbp/processor/heandle.js +0 -32
- package/lib/cbp/processor/request-handler.d.ts +0 -17
- package/lib/cbp/processor/request-handler.js +0 -65
- package/lib/polyfills/fs-promises.d.ts +0 -41
- package/lib/polyfills/fs-promises.js +0 -138
- package/lib/polyfills/fs.d.ts +0 -103
- package/lib/polyfills/fs.js +0 -229
- package/lib/polyfills/util-types.d.ts +0 -33
- package/lib/polyfills/util-types.js +0 -36
- package/lib/types/event/channal/index.d.ts +0 -10
- package/lib/types/event/channal/index.js +0 -1
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
|
|
3
|
-
const createConnectionState = () => ({
|
|
4
|
-
connections: new Map(),
|
|
5
|
-
lastActivity: new Map(),
|
|
6
|
-
metadata: new Map()
|
|
7
|
-
});
|
|
8
|
-
const addConnection = (state, id, ws, metadata) => {
|
|
9
|
-
const newState = {
|
|
10
|
-
connections: new Map(state.connections),
|
|
11
|
-
lastActivity: new Map(state.lastActivity),
|
|
12
|
-
metadata: new Map(state.metadata)
|
|
13
|
-
};
|
|
14
|
-
newState.connections.set(id, ws);
|
|
15
|
-
newState.lastActivity.set(id, Date.now());
|
|
16
|
-
if (metadata) {
|
|
17
|
-
newState.metadata.set(id, metadata);
|
|
18
|
-
}
|
|
19
|
-
return newState;
|
|
20
|
-
};
|
|
21
|
-
const removeConnection = (state, id) => {
|
|
22
|
-
const newState = {
|
|
23
|
-
connections: new Map(state.connections),
|
|
24
|
-
lastActivity: new Map(state.lastActivity),
|
|
25
|
-
metadata: new Map(state.metadata)
|
|
26
|
-
};
|
|
27
|
-
const ws = newState.connections.get(id);
|
|
28
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
29
|
-
ws.close();
|
|
30
|
-
}
|
|
31
|
-
newState.connections.delete(id);
|
|
32
|
-
newState.lastActivity.delete(id);
|
|
33
|
-
newState.metadata.delete(id);
|
|
34
|
-
return newState;
|
|
35
|
-
};
|
|
36
|
-
const getConnection = (state, id) => {
|
|
37
|
-
return state.connections.get(id);
|
|
38
|
-
};
|
|
39
|
-
const getHealthyConnectionIds = (state) => {
|
|
40
|
-
const healthyIds = [];
|
|
41
|
-
for (const [id, ws] of state.connections.entries()) {
|
|
42
|
-
if (ws.readyState === WebSocket.OPEN) {
|
|
43
|
-
healthyIds.push(id);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return healthyIds;
|
|
47
|
-
};
|
|
48
|
-
const getConnectionStats = (state) => {
|
|
49
|
-
const total = state.connections.size;
|
|
50
|
-
const healthy = getHealthyConnectionIds(state).length;
|
|
51
|
-
return {
|
|
52
|
-
total,
|
|
53
|
-
healthy,
|
|
54
|
-
unhealthy: total - healthy,
|
|
55
|
-
lastUpdate: Date.now()
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
const clearAllConnections = (state) => {
|
|
59
|
-
for (const ws of state.connections.values()) {
|
|
60
|
-
if (ws.readyState === WebSocket.OPEN) {
|
|
61
|
-
ws.close();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return createConnectionState();
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { addConnection, clearAllConnections, createConnectionState, getConnection, getConnectionStats, getHealthyConnectionIds, removeConnection };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const USER_AGENT_HEADER = "user-agent";
|
|
2
|
-
export declare const DEVICE_ID_HEADER = "x-device-id";
|
|
3
|
-
export declare const FULL_RECEIVE_HEADER = "x-full-receive";
|
|
4
|
-
export declare const USER_AGENT_HEADER_VALUE_MAP: {
|
|
5
|
-
readonly platform: "platform";
|
|
6
|
-
readonly client: "client";
|
|
7
|
-
readonly testone: "testone";
|
|
8
|
-
};
|
|
9
|
-
export declare const TIME_CONFIG: {
|
|
10
|
-
readonly TIMEOUT: number;
|
|
11
|
-
readonly RECONNECT_INTERVAL: number;
|
|
12
|
-
readonly HEARTBEAT_INTERVAL: number;
|
|
13
|
-
};
|
|
14
|
-
export declare const HEALTH_CHECK_CONFIG: {
|
|
15
|
-
readonly INTERVAL: 30000;
|
|
16
|
-
readonly MAX_CONSECUTIVE_FAILURES: 3;
|
|
17
|
-
readonly PING_TIMEOUT: 5000;
|
|
18
|
-
};
|
|
19
|
-
export declare const generateUniqueId: () => string;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const USER_AGENT_HEADER = 'user-agent';
|
|
2
|
-
const DEVICE_ID_HEADER = 'x-device-id';
|
|
3
|
-
const FULL_RECEIVE_HEADER = 'x-full-receive';
|
|
4
|
-
const USER_AGENT_HEADER_VALUE_MAP = {
|
|
5
|
-
platform: 'platform',
|
|
6
|
-
client: 'client',
|
|
7
|
-
testone: 'testone'
|
|
8
|
-
};
|
|
9
|
-
const TIME_CONFIG = {
|
|
10
|
-
TIMEOUT: 1000 * 60 * 3,
|
|
11
|
-
RECONNECT_INTERVAL: 1000 * 6,
|
|
12
|
-
HEARTBEAT_INTERVAL: 1000 * 18
|
|
13
|
-
};
|
|
14
|
-
const HEALTH_CHECK_CONFIG = {
|
|
15
|
-
INTERVAL: 30000,
|
|
16
|
-
MAX_CONSECUTIVE_FAILURES: 3,
|
|
17
|
-
PING_TIMEOUT: 5000
|
|
18
|
-
};
|
|
19
|
-
const generateUniqueId = () => {
|
|
20
|
-
return Date.now().toString(36) + Math.random().toString(36).substring(2);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { DEVICE_ID_HEADER, FULL_RECEIVE_HEADER, HEALTH_CHECK_CONFIG, TIME_CONFIG, USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, generateUniqueId };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ConnectionState } from './connection-manager';
|
|
2
|
-
export type LoadBalanceStrategy = 'round-robin' | 'least-connections' | 'random' | 'first-available';
|
|
3
|
-
export declare const LoadBalanceStrategyEnum: {
|
|
4
|
-
readonly ROUND_ROBIN: "round-robin";
|
|
5
|
-
readonly LEAST_CONNECTIONS: "least-connections";
|
|
6
|
-
readonly RANDOM: "random";
|
|
7
|
-
readonly FIRST_AVAILABLE: "first-available";
|
|
8
|
-
};
|
|
9
|
-
export interface LoadBalancerState {
|
|
10
|
-
strategy: LoadBalanceStrategy;
|
|
11
|
-
roundRobinIndex: number;
|
|
12
|
-
bindingCounts: Map<string, number>;
|
|
13
|
-
}
|
|
14
|
-
export declare const createLoadBalancerState: (strategy?: LoadBalanceStrategy) => LoadBalancerState;
|
|
15
|
-
export declare const selectByRoundRobin: (availableIds: string[], currentIndex: number) => {
|
|
16
|
-
selectedId: string | null;
|
|
17
|
-
nextIndex: number;
|
|
18
|
-
};
|
|
19
|
-
export declare const selectByLeastConnections: (availableIds: string[], bindingCounts: Map<string, number>) => string | null;
|
|
20
|
-
export declare const selectByRandom: (availableIds: string[]) => string | null;
|
|
21
|
-
export declare const selectFirstAvailable: (availableIds: string[]) => string | null;
|
|
22
|
-
export declare const selectConnection: (connectionState: ConnectionState, balancerState: LoadBalancerState) => {
|
|
23
|
-
selectedId: string | null;
|
|
24
|
-
newBalancerState: LoadBalancerState;
|
|
25
|
-
};
|
|
26
|
-
export declare const incrementBindingCount: (balancerState: LoadBalancerState, connectionId: string) => LoadBalancerState;
|
|
27
|
-
export declare const decrementBindingCount: (balancerState: LoadBalancerState, connectionId: string) => LoadBalancerState;
|
|
28
|
-
export declare const getLoadBalancerStats: (balancerState: LoadBalancerState) => {
|
|
29
|
-
strategy: LoadBalanceStrategy;
|
|
30
|
-
roundRobinIndex: number;
|
|
31
|
-
totalConnections: number;
|
|
32
|
-
totalBindings: number;
|
|
33
|
-
bindingCounts: {
|
|
34
|
-
[k: string]: number;
|
|
35
|
-
};
|
|
36
|
-
lastUpdate: number;
|
|
37
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { getHealthyConnectionIds } from './connection-manager.js';
|
|
2
|
-
|
|
3
|
-
const LoadBalanceStrategyEnum = {
|
|
4
|
-
ROUND_ROBIN: 'round-robin',
|
|
5
|
-
LEAST_CONNECTIONS: 'least-connections',
|
|
6
|
-
RANDOM: 'random',
|
|
7
|
-
FIRST_AVAILABLE: 'first-available'
|
|
8
|
-
};
|
|
9
|
-
const createLoadBalancerState = (strategy = 'round-robin') => ({
|
|
10
|
-
strategy,
|
|
11
|
-
roundRobinIndex: 0,
|
|
12
|
-
bindingCounts: new Map()
|
|
13
|
-
});
|
|
14
|
-
const selectByRoundRobin = (availableIds, currentIndex) => {
|
|
15
|
-
if (availableIds.length === 0) {
|
|
16
|
-
return { selectedId: null, nextIndex: currentIndex };
|
|
17
|
-
}
|
|
18
|
-
const selectedId = availableIds[currentIndex % availableIds.length];
|
|
19
|
-
const nextIndex = (currentIndex + 1) % availableIds.length;
|
|
20
|
-
return { selectedId, nextIndex };
|
|
21
|
-
};
|
|
22
|
-
const selectByLeastConnections = (availableIds, bindingCounts) => {
|
|
23
|
-
if (availableIds.length === 0) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
let selectedId = availableIds[0];
|
|
27
|
-
let minConnections = bindingCounts.get(selectedId) || 0;
|
|
28
|
-
for (let i = 1; i < availableIds.length; i++) {
|
|
29
|
-
const id = availableIds[i];
|
|
30
|
-
const connections = bindingCounts.get(id) || 0;
|
|
31
|
-
if (connections < minConnections) {
|
|
32
|
-
minConnections = connections;
|
|
33
|
-
selectedId = id;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return selectedId;
|
|
37
|
-
};
|
|
38
|
-
const selectByRandom = (availableIds) => {
|
|
39
|
-
if (availableIds.length === 0) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
const randomIndex = Math.floor(Math.random() * availableIds.length);
|
|
43
|
-
return availableIds[randomIndex];
|
|
44
|
-
};
|
|
45
|
-
const selectFirstAvailable = (availableIds) => {
|
|
46
|
-
return availableIds.length > 0 ? availableIds[0] : null;
|
|
47
|
-
};
|
|
48
|
-
const selectConnection = (connectionState, balancerState) => {
|
|
49
|
-
const availableIds = getHealthyConnectionIds(connectionState);
|
|
50
|
-
if (availableIds.length === 0) {
|
|
51
|
-
return { selectedId: null, newBalancerState: balancerState };
|
|
52
|
-
}
|
|
53
|
-
let selectedId = null;
|
|
54
|
-
const newBalancerState = { ...balancerState };
|
|
55
|
-
switch (balancerState.strategy) {
|
|
56
|
-
case 'round-robin': {
|
|
57
|
-
const result = selectByRoundRobin(availableIds, balancerState.roundRobinIndex);
|
|
58
|
-
selectedId = result.selectedId;
|
|
59
|
-
newBalancerState.roundRobinIndex = result.nextIndex;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case 'least-connections': {
|
|
63
|
-
selectedId = selectByLeastConnections(availableIds, balancerState.bindingCounts);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'random': {
|
|
67
|
-
selectedId = selectByRandom(availableIds);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case 'first-available': {
|
|
71
|
-
selectedId = selectFirstAvailable(availableIds);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
default: {
|
|
75
|
-
const result = selectByRoundRobin(availableIds, balancerState.roundRobinIndex);
|
|
76
|
-
selectedId = result.selectedId;
|
|
77
|
-
newBalancerState.roundRobinIndex = result.nextIndex;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return { selectedId, newBalancerState };
|
|
82
|
-
};
|
|
83
|
-
const incrementBindingCount = (balancerState, connectionId) => {
|
|
84
|
-
const newBindingCounts = new Map(balancerState.bindingCounts);
|
|
85
|
-
const currentCount = newBindingCounts.get(connectionId) || 0;
|
|
86
|
-
newBindingCounts.set(connectionId, currentCount + 1);
|
|
87
|
-
return {
|
|
88
|
-
...balancerState,
|
|
89
|
-
bindingCounts: newBindingCounts
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
const decrementBindingCount = (balancerState, connectionId) => {
|
|
93
|
-
const newBindingCounts = new Map(balancerState.bindingCounts);
|
|
94
|
-
const currentCount = newBindingCounts.get(connectionId) || 0;
|
|
95
|
-
if (currentCount > 0) {
|
|
96
|
-
newBindingCounts.set(connectionId, currentCount - 1);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
newBindingCounts.delete(connectionId);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
...balancerState,
|
|
103
|
-
bindingCounts: newBindingCounts
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const getLoadBalancerStats = (balancerState) => {
|
|
107
|
-
const totalBindings = Array.from(balancerState.bindingCounts.values()).reduce((sum, count) => sum + count, 0);
|
|
108
|
-
return {
|
|
109
|
-
strategy: balancerState.strategy,
|
|
110
|
-
roundRobinIndex: balancerState.roundRobinIndex,
|
|
111
|
-
totalConnections: balancerState.bindingCounts.size,
|
|
112
|
-
totalBindings,
|
|
113
|
-
bindingCounts: Object.fromEntries(balancerState.bindingCounts),
|
|
114
|
-
lastUpdate: Date.now()
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export { LoadBalanceStrategyEnum, createLoadBalancerState, decrementBindingCount, getLoadBalancerStats, incrementBindingCount, selectByLeastConnections, selectByRandom, selectByRoundRobin, selectConnection, selectFirstAvailable };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../../core/variable.js';
|
|
2
|
-
import 'fs';
|
|
3
|
-
import 'path';
|
|
4
|
-
import 'yaml';
|
|
5
|
-
import { createResult } from '../../core/utils.js';
|
|
6
|
-
import { generateUniqueId, deviceId, apiResolves, apiTimeouts, timeoutTime } from './config.js';
|
|
7
|
-
import * as flattedJSON from 'flatted';
|
|
8
|
-
|
|
9
|
-
const sendAPI = (data) => {
|
|
10
|
-
const ApiId = generateUniqueId();
|
|
11
|
-
return new Promise(resolve => {
|
|
12
|
-
if (!global.chatbotClient?.send) {
|
|
13
|
-
resolve([createResult(ResultCode.Fail, 'Chatbot client is not available', null)]);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
data.apiId = ApiId;
|
|
17
|
-
data.DeviceId = deviceId;
|
|
18
|
-
global.chatbotClient?.send(flattedJSON.stringify(data));
|
|
19
|
-
apiResolves.set(ApiId, resolve);
|
|
20
|
-
const timeout = setTimeout(() => {
|
|
21
|
-
if (!apiResolves.has(ApiId) || !apiTimeouts.has(ApiId)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
apiResolves.delete(ApiId);
|
|
25
|
-
apiTimeouts.delete(ApiId);
|
|
26
|
-
resolve([createResult(ResultCode.Fail, '接口超时', null)]);
|
|
27
|
-
}, timeoutTime);
|
|
28
|
-
apiTimeouts.set(ApiId, timeout);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { sendAPI };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../core';
|
|
2
|
-
type ResolversValue = (value: Result[]) => void;
|
|
3
|
-
export interface RequestHandlerState {
|
|
4
|
-
resolvers: Map<string, ResolversValue>;
|
|
5
|
-
timeouts: Map<string, NodeJS.Timeout>;
|
|
6
|
-
requestType: string;
|
|
7
|
-
idField: 'actionId' | 'apiId';
|
|
8
|
-
}
|
|
9
|
-
export declare const createRequestHandlerState: (requestType: string, idField: "actionId" | "apiId") => RequestHandlerState;
|
|
10
|
-
export declare const sendRequest: <T>(state: RequestHandlerState, data: T & {
|
|
11
|
-
DeviceId?: string;
|
|
12
|
-
}) => Promise<Result[]>;
|
|
13
|
-
export declare const handleRequestResponse: (state: RequestHandlerState, requestId: string, results: Result[]) => void;
|
|
14
|
-
export declare const handleRequestTimeout: (state: RequestHandlerState, requestId: string) => void;
|
|
15
|
-
export declare const getPendingRequestCount: (state: RequestHandlerState) => number;
|
|
16
|
-
export declare const destroyRequestHandler: (state: RequestHandlerState) => void;
|
|
17
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as flattedJSON from 'flatted';
|
|
2
|
-
import { ResultCode } from '../../core/variable.js';
|
|
3
|
-
import 'fs';
|
|
4
|
-
import 'path';
|
|
5
|
-
import 'yaml';
|
|
6
|
-
import { createResult } from '../../core/utils.js';
|
|
7
|
-
import { deviceId, timeoutTime } from './config.js';
|
|
8
|
-
import { generateUniqueId } from '../core/constants.js';
|
|
9
|
-
|
|
10
|
-
const createRequestHandlerState = (requestType, idField) => ({
|
|
11
|
-
resolvers: new Map(),
|
|
12
|
-
timeouts: new Map(),
|
|
13
|
-
requestType,
|
|
14
|
-
idField
|
|
15
|
-
});
|
|
16
|
-
const sendRequest = (state, data) => {
|
|
17
|
-
const requestId = generateUniqueId();
|
|
18
|
-
return new Promise(resolve => {
|
|
19
|
-
data[state.idField] = requestId;
|
|
20
|
-
data.DeviceId = deviceId;
|
|
21
|
-
global.chatbotClient.send(flattedJSON.stringify(data));
|
|
22
|
-
state.resolvers.set(requestId, resolve);
|
|
23
|
-
const timeout = setTimeout(() => {
|
|
24
|
-
handleRequestTimeout(state, requestId);
|
|
25
|
-
}, timeoutTime);
|
|
26
|
-
state.timeouts.set(requestId, timeout);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const handleRequestResponse = (state, requestId, results) => {
|
|
30
|
-
const resolver = state.resolvers.get(requestId);
|
|
31
|
-
const timeout = state.timeouts.get(requestId);
|
|
32
|
-
if (resolver) {
|
|
33
|
-
state.resolvers.delete(requestId);
|
|
34
|
-
if (timeout) {
|
|
35
|
-
clearTimeout(timeout);
|
|
36
|
-
state.timeouts.delete(requestId);
|
|
37
|
-
}
|
|
38
|
-
resolver(results);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const handleRequestTimeout = (state, requestId) => {
|
|
42
|
-
const resolver = state.resolvers.get(requestId);
|
|
43
|
-
if (resolver) {
|
|
44
|
-
state.resolvers.delete(requestId);
|
|
45
|
-
state.timeouts.delete(requestId);
|
|
46
|
-
const timeoutResult = createResult(ResultCode.Fail, `${state.requestType}请求超时`, null);
|
|
47
|
-
resolver([timeoutResult]);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const getPendingRequestCount = (state) => {
|
|
51
|
-
return state.resolvers.size;
|
|
52
|
-
};
|
|
53
|
-
const destroyRequestHandler = (state) => {
|
|
54
|
-
for (const timeout of state.timeouts.values()) {
|
|
55
|
-
clearTimeout(timeout);
|
|
56
|
-
}
|
|
57
|
-
for (const [_requestId, resolver] of state.resolvers.entries()) {
|
|
58
|
-
const cancelResult = createResult(ResultCode.FailInternal, `${state.requestType}请求已取消`, null);
|
|
59
|
-
resolver([cancelResult]);
|
|
60
|
-
}
|
|
61
|
-
state.resolvers.clear();
|
|
62
|
-
state.timeouts.clear();
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export { createRequestHandlerState, destroyRequestHandler, getPendingRequestCount, handleRequestResponse, handleRequestTimeout, sendRequest };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export declare const readFile: (path: string, encoding?: string) => Promise<Buffer>;
|
|
2
|
-
export declare const writeFile: (path: string, data: any) => Promise<void>;
|
|
3
|
-
export declare const readdir: (path: string) => Promise<string[]>;
|
|
4
|
-
export declare const mkdir: (path: string, options?: any) => Promise<void>;
|
|
5
|
-
export declare const stat: (path: string) => Promise<any>;
|
|
6
|
-
export declare const unlink: (path: string) => Promise<void>;
|
|
7
|
-
export declare const rmdir: (path: string, options?: any) => Promise<void>;
|
|
8
|
-
export declare const rename: (oldPath: string, newPath: string) => Promise<void>;
|
|
9
|
-
export declare const copyFile: (src: string, dest: string, flags?: number) => Promise<void>;
|
|
10
|
-
export declare const appendFile: (path: string, data: string, options?: any) => Promise<void>;
|
|
11
|
-
export declare const access: (path: string, mode?: number) => Promise<void>;
|
|
12
|
-
export declare const readlink: (path: string) => Promise<string>;
|
|
13
|
-
export declare const symlink: (target: string, path: string, type?: string) => Promise<void>;
|
|
14
|
-
export declare const lstat: (path: string) => Promise<any>;
|
|
15
|
-
export declare const chmod: (path: string, mode: number) => Promise<void>;
|
|
16
|
-
export declare const chown: (path: string, uid: number, gid: number) => Promise<void>;
|
|
17
|
-
export declare const realpath: (path: string) => Promise<string>;
|
|
18
|
-
export declare const mkdtemp: (prefix: string) => Promise<string>;
|
|
19
|
-
export declare const opendir: (path: string) => Promise<any>;
|
|
20
|
-
declare const _default: {
|
|
21
|
-
readFile: (path: string, encoding?: string) => Promise<Buffer>;
|
|
22
|
-
writeFile: (path: string, data: any) => Promise<void>;
|
|
23
|
-
readdir: (path: string) => Promise<string[]>;
|
|
24
|
-
mkdir: (path: string, options?: any) => Promise<void>;
|
|
25
|
-
stat: (path: string) => Promise<any>;
|
|
26
|
-
unlink: (path: string) => Promise<void>;
|
|
27
|
-
rmdir: (path: string, options?: any) => Promise<void>;
|
|
28
|
-
rename: (oldPath: string, newPath: string) => Promise<void>;
|
|
29
|
-
copyFile: (src: string, dest: string, flags?: number) => Promise<void>;
|
|
30
|
-
appendFile: (path: string, data: string, options?: any) => Promise<void>;
|
|
31
|
-
access: (path: string, mode?: number) => Promise<void>;
|
|
32
|
-
readlink: (path: string) => Promise<string>;
|
|
33
|
-
symlink: (target: string, path: string, type?: string) => Promise<void>;
|
|
34
|
-
lstat: (path: string) => Promise<any>;
|
|
35
|
-
chmod: (path: string, mode: number) => Promise<void>;
|
|
36
|
-
chown: (path: string, uid: number, gid: number) => Promise<void>;
|
|
37
|
-
realpath: (path: string) => Promise<string>;
|
|
38
|
-
mkdtemp: (prefix: string) => Promise<string>;
|
|
39
|
-
opendir: (path: string) => Promise<any>;
|
|
40
|
-
};
|
|
41
|
-
export default _default;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
const readFile = async (path, encoding) => {
|
|
2
|
-
console.warn(`[AlemonJS Browser] fs/promises.readFile('${path}') is not available in browser, returning empty buffer`);
|
|
3
|
-
return Buffer.from('');
|
|
4
|
-
};
|
|
5
|
-
const writeFile = async (path, data) => {
|
|
6
|
-
console.warn(`[AlemonJS Browser] fs/promises.writeFile('${path}') is not available in browser, operation skipped`);
|
|
7
|
-
return Promise.resolve();
|
|
8
|
-
};
|
|
9
|
-
const readdir = async (path) => {
|
|
10
|
-
console.warn(`[AlemonJS Browser] fs/promises.readdir('${path}') is not available in browser, returning empty array`);
|
|
11
|
-
return Promise.resolve([]);
|
|
12
|
-
};
|
|
13
|
-
const mkdir = async (path, options) => {
|
|
14
|
-
console.warn(`[AlemonJS Browser] fs/promises.mkdir('${path}') is not available in browser, operation skipped`);
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
};
|
|
17
|
-
const stat = async (path) => {
|
|
18
|
-
console.warn(`[AlemonJS Browser] fs/promises.stat('${path}') is not available in browser, returning mock stats`);
|
|
19
|
-
return Promise.resolve({
|
|
20
|
-
isDirectory: () => false,
|
|
21
|
-
isFile: () => false,
|
|
22
|
-
isBlockDevice: () => false,
|
|
23
|
-
isCharacterDevice: () => false,
|
|
24
|
-
isSymbolicLink: () => false,
|
|
25
|
-
isFIFO: () => false,
|
|
26
|
-
isSocket: () => false,
|
|
27
|
-
dev: 0,
|
|
28
|
-
ino: 0,
|
|
29
|
-
mode: 0,
|
|
30
|
-
nlink: 0,
|
|
31
|
-
uid: 0,
|
|
32
|
-
gid: 0,
|
|
33
|
-
rdev: 0,
|
|
34
|
-
size: 0,
|
|
35
|
-
blksize: 0,
|
|
36
|
-
blocks: 0,
|
|
37
|
-
atimeMs: 0,
|
|
38
|
-
mtimeMs: 0,
|
|
39
|
-
ctimeMs: 0,
|
|
40
|
-
birthtimeMs: 0,
|
|
41
|
-
atime: new Date(),
|
|
42
|
-
mtime: new Date(),
|
|
43
|
-
ctime: new Date(),
|
|
44
|
-
birthtime: new Date()
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
const unlink = async (path) => {
|
|
48
|
-
console.warn(`[AlemonJS Browser] fs/promises.unlink('${path}') is not available in browser, operation skipped`);
|
|
49
|
-
return Promise.resolve();
|
|
50
|
-
};
|
|
51
|
-
const rmdir = async (path, options) => {
|
|
52
|
-
console.warn(`[AlemonJS Browser] fs/promises.rmdir('${path}') is not available in browser, operation skipped`);
|
|
53
|
-
return Promise.resolve();
|
|
54
|
-
};
|
|
55
|
-
const rename = async (oldPath, newPath) => {
|
|
56
|
-
console.warn(`[AlemonJS Browser] fs/promises.rename('${oldPath}', '${newPath}') is not available in browser, operation skipped`);
|
|
57
|
-
return Promise.resolve();
|
|
58
|
-
};
|
|
59
|
-
const copyFile = async (src, dest, flags) => {
|
|
60
|
-
console.warn(`[AlemonJS Browser] fs/promises.copyFile('${src}', '${dest}') is not available in browser, operation skipped`);
|
|
61
|
-
return Promise.resolve();
|
|
62
|
-
};
|
|
63
|
-
const appendFile = async (path, data, options) => {
|
|
64
|
-
console.warn(`[AlemonJS Browser] fs/promises.appendFile('${path}') is not available in browser, operation skipped`);
|
|
65
|
-
return Promise.resolve();
|
|
66
|
-
};
|
|
67
|
-
const access = async (path, mode) => {
|
|
68
|
-
console.warn(`[AlemonJS Browser] fs/promises.access('${path}') is not available in browser, operation skipped`);
|
|
69
|
-
return Promise.resolve();
|
|
70
|
-
};
|
|
71
|
-
const readlink = async (path) => {
|
|
72
|
-
console.warn(`[AlemonJS Browser] fs/promises.readlink('${path}') is not available in browser, returning empty string`);
|
|
73
|
-
return Promise.resolve('');
|
|
74
|
-
};
|
|
75
|
-
const symlink = async (target, path, type) => {
|
|
76
|
-
console.warn(`[AlemonJS Browser] fs/promises.symlink('${target}', '${path}') is not available in browser, operation skipped`);
|
|
77
|
-
return Promise.resolve();
|
|
78
|
-
};
|
|
79
|
-
const lstat = async (path) => {
|
|
80
|
-
console.warn(`[AlemonJS Browser] fs/promises.lstat('${path}') is not available in browser, returning mock stats`);
|
|
81
|
-
return stat(path);
|
|
82
|
-
};
|
|
83
|
-
const chmod = async (path, mode) => {
|
|
84
|
-
console.warn(`[AlemonJS Browser] fs/promises.chmod('${path}') is not available in browser, operation skipped`);
|
|
85
|
-
return Promise.resolve();
|
|
86
|
-
};
|
|
87
|
-
const chown = async (path, uid, gid) => {
|
|
88
|
-
console.warn(`[AlemonJS Browser] fs/promises.chown('${path}') is not available in browser, operation skipped`);
|
|
89
|
-
return Promise.resolve();
|
|
90
|
-
};
|
|
91
|
-
const realpath = async (path) => {
|
|
92
|
-
console.warn(`[AlemonJS Browser] fs/promises.realpath('${path}') is not available in browser, returning empty string`);
|
|
93
|
-
return Promise.resolve('');
|
|
94
|
-
};
|
|
95
|
-
const mkdtemp = async (prefix) => {
|
|
96
|
-
console.warn(`[AlemonJS Browser] fs/promises.mkdtemp('${prefix}') is not available in browser, returning mock path`);
|
|
97
|
-
return Promise.resolve(`/tmp/${prefix}${Math.random().toString(36).substr(2, 9)}`);
|
|
98
|
-
};
|
|
99
|
-
const opendir = async (path) => {
|
|
100
|
-
console.warn(`[AlemonJS Browser] fs/promises.opendir('${path}') is not available in browser, returning mock dir`);
|
|
101
|
-
const mockDir = {
|
|
102
|
-
[Symbol.asyncIterator]: () => {
|
|
103
|
-
return {
|
|
104
|
-
next: () => Promise.resolve({ done: true, value: null })
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
close: async () => {
|
|
108
|
-
console.warn('[AlemonJS Browser] Mock dir close() called');
|
|
109
|
-
},
|
|
110
|
-
path: path,
|
|
111
|
-
read: async () => null,
|
|
112
|
-
readSync: () => null
|
|
113
|
-
};
|
|
114
|
-
return Promise.resolve(mockDir);
|
|
115
|
-
};
|
|
116
|
-
var fsPromises = {
|
|
117
|
-
readFile,
|
|
118
|
-
writeFile,
|
|
119
|
-
readdir,
|
|
120
|
-
mkdir,
|
|
121
|
-
stat,
|
|
122
|
-
unlink,
|
|
123
|
-
rmdir,
|
|
124
|
-
rename,
|
|
125
|
-
copyFile,
|
|
126
|
-
appendFile,
|
|
127
|
-
access,
|
|
128
|
-
readlink,
|
|
129
|
-
symlink,
|
|
130
|
-
lstat,
|
|
131
|
-
chmod,
|
|
132
|
-
chown,
|
|
133
|
-
realpath,
|
|
134
|
-
mkdtemp,
|
|
135
|
-
opendir
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export { access, appendFile, chmod, chown, copyFile, fsPromises as default, lstat, mkdir, mkdtemp, opendir, readFile, readdir, readlink, realpath, rename, rmdir, stat, symlink, unlink, writeFile };
|
package/lib/polyfills/fs.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
export declare const existsSync: (path: string) => boolean;
|
|
2
|
-
export declare const readFileSync: (path: string, encoding?: string) => string;
|
|
3
|
-
export declare const writeFileSync: (path: string, data: string) => void;
|
|
4
|
-
export declare const mkdirSync: (path: string, options?: any) => void;
|
|
5
|
-
export declare const watch: (path: string, options?: any) => any;
|
|
6
|
-
export declare const readdirSync: (path: string) => string[];
|
|
7
|
-
export declare const statSync: (path: string) => any;
|
|
8
|
-
export declare const unlinkSync: (path: string) => void;
|
|
9
|
-
export declare const rmdirSync: (path: string, options?: any) => void;
|
|
10
|
-
export declare const renameSync: (oldPath: string, newPath: string) => void;
|
|
11
|
-
export declare const copyFileSync: (src: string, dest: string, flags?: number) => void;
|
|
12
|
-
export declare const appendFileSync: (path: string, data: string, options?: any) => void;
|
|
13
|
-
export declare const writeFile: (path: string, data: string, callback?: (err: any) => void) => void;
|
|
14
|
-
export declare const readFile: (path: string, encoding: string, callback?: (err: any, data: string) => void) => void;
|
|
15
|
-
export declare const mkdir: (path: string, options: any, callback?: (err: any) => void) => void;
|
|
16
|
-
export declare const unlink: (path: string, callback?: (err: any) => void) => void;
|
|
17
|
-
export declare const rmdir: (path: string, callback?: (err: any) => void) => void;
|
|
18
|
-
export declare const rename: (oldPath: string, newPath: string, callback?: (err: any) => void) => void;
|
|
19
|
-
export declare const promises: {
|
|
20
|
-
writeFile: (path: string, data: string) => Promise<void>;
|
|
21
|
-
readFile: (path: string, encoding?: string) => Promise<string>;
|
|
22
|
-
mkdir: (path: string, options?: any) => Promise<void>;
|
|
23
|
-
readdir: (path: string) => Promise<string[]>;
|
|
24
|
-
stat: (path: string) => Promise<any>;
|
|
25
|
-
unlink: (path: string) => Promise<void>;
|
|
26
|
-
rmdir: (path: string) => Promise<void>;
|
|
27
|
-
};
|
|
28
|
-
export declare const createReadStream: (path: string, options?: any) => any;
|
|
29
|
-
export declare const createWriteStream: (path: string, options?: any) => any;
|
|
30
|
-
export declare const constants: {
|
|
31
|
-
F_OK: number;
|
|
32
|
-
R_OK: number;
|
|
33
|
-
W_OK: number;
|
|
34
|
-
X_OK: number;
|
|
35
|
-
O_RDONLY: number;
|
|
36
|
-
O_WRONLY: number;
|
|
37
|
-
O_RDWR: number;
|
|
38
|
-
O_CREAT: number;
|
|
39
|
-
O_EXCL: number;
|
|
40
|
-
O_NOCTTY: number;
|
|
41
|
-
O_TRUNC: number;
|
|
42
|
-
O_APPEND: number;
|
|
43
|
-
O_DIRECTORY: number;
|
|
44
|
-
O_NOATIME: number;
|
|
45
|
-
O_NOFOLLOW: number;
|
|
46
|
-
O_SYNC: number;
|
|
47
|
-
O_DSYNC: number;
|
|
48
|
-
O_DIRECT: number;
|
|
49
|
-
O_NONBLOCK: number;
|
|
50
|
-
};
|
|
51
|
-
declare const _default: {
|
|
52
|
-
existsSync: (path: string) => boolean;
|
|
53
|
-
readFileSync: (path: string, encoding?: string) => string;
|
|
54
|
-
writeFileSync: (path: string, data: string) => void;
|
|
55
|
-
mkdirSync: (path: string, options?: any) => void;
|
|
56
|
-
watch: (path: string, options?: any) => any;
|
|
57
|
-
readdirSync: (path: string) => string[];
|
|
58
|
-
statSync: (path: string) => any;
|
|
59
|
-
unlinkSync: (path: string) => void;
|
|
60
|
-
rmdirSync: (path: string, options?: any) => void;
|
|
61
|
-
renameSync: (oldPath: string, newPath: string) => void;
|
|
62
|
-
copyFileSync: (src: string, dest: string, flags?: number) => void;
|
|
63
|
-
appendFileSync: (path: string, data: string, options?: any) => void;
|
|
64
|
-
writeFile: (path: string, data: string, callback?: (err: any) => void) => void;
|
|
65
|
-
readFile: (path: string, encoding: string, callback?: (err: any, data: string) => void) => void;
|
|
66
|
-
mkdir: (path: string, options: any, callback?: (err: any) => void) => void;
|
|
67
|
-
unlink: (path: string, callback?: (err: any) => void) => void;
|
|
68
|
-
rmdir: (path: string, callback?: (err: any) => void) => void;
|
|
69
|
-
rename: (oldPath: string, newPath: string, callback?: (err: any) => void) => void;
|
|
70
|
-
promises: {
|
|
71
|
-
writeFile: (path: string, data: string) => Promise<void>;
|
|
72
|
-
readFile: (path: string, encoding?: string) => Promise<string>;
|
|
73
|
-
mkdir: (path: string, options?: any) => Promise<void>;
|
|
74
|
-
readdir: (path: string) => Promise<string[]>;
|
|
75
|
-
stat: (path: string) => Promise<any>;
|
|
76
|
-
unlink: (path: string) => Promise<void>;
|
|
77
|
-
rmdir: (path: string) => Promise<void>;
|
|
78
|
-
};
|
|
79
|
-
createReadStream: (path: string, options?: any) => any;
|
|
80
|
-
createWriteStream: (path: string, options?: any) => any;
|
|
81
|
-
constants: {
|
|
82
|
-
F_OK: number;
|
|
83
|
-
R_OK: number;
|
|
84
|
-
W_OK: number;
|
|
85
|
-
X_OK: number;
|
|
86
|
-
O_RDONLY: number;
|
|
87
|
-
O_WRONLY: number;
|
|
88
|
-
O_RDWR: number;
|
|
89
|
-
O_CREAT: number;
|
|
90
|
-
O_EXCL: number;
|
|
91
|
-
O_NOCTTY: number;
|
|
92
|
-
O_TRUNC: number;
|
|
93
|
-
O_APPEND: number;
|
|
94
|
-
O_DIRECTORY: number;
|
|
95
|
-
O_NOATIME: number;
|
|
96
|
-
O_NOFOLLOW: number;
|
|
97
|
-
O_SYNC: number;
|
|
98
|
-
O_DSYNC: number;
|
|
99
|
-
O_DIRECT: number;
|
|
100
|
-
O_NONBLOCK: number;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
export default _default;
|