@e-mc/watch 0.3.2 → 0.4.0
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/filegroup/index.js +176 -176
- package/index.js +822 -822
- package/package.json +4 -4
package/filegroup/index.js
CHANGED
|
@@ -1,179 +1,179 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a, _b, _c, _d;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const types_1 = require("../../types");
|
|
5
|
-
const core_1 = require("../../core");
|
|
6
|
-
const kPaused = Symbol('paused');
|
|
7
|
-
const kServer = Symbol('server');
|
|
8
|
-
const kEtag = Symbol('etag');
|
|
9
|
-
const kLastModified = Symbol('lastModified');
|
|
10
|
-
class SocketRequest {
|
|
11
|
-
constructor(expires, socketId, id = '') {
|
|
12
|
-
this.expires = expires;
|
|
13
|
-
this.socketId = socketId;
|
|
14
|
-
this.id = id;
|
|
15
|
-
}
|
|
16
|
-
get expired() {
|
|
17
|
-
const expires = this.expires;
|
|
18
|
-
return expires > 0 && expires !== Infinity && Date.now() > expires;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class FileGroup extends core_1.AbortComponent {
|
|
22
|
-
static checkTimeout(client) {
|
|
23
|
-
if (client.readyState === 1) {
|
|
24
|
-
const lastTime = FileGroup.CLIENT_SESSION.get(client);
|
|
25
|
-
if (!lastTime) {
|
|
26
|
-
FileGroup.CLIENT_SESSION.set(client, Date.now());
|
|
27
|
-
}
|
|
28
|
-
else if (FileGroup.CONNECTION_TIMEOUT > 0 && lastTime + FileGroup.CONNECTION_TIMEOUT <= Date.now()) {
|
|
29
|
-
client.terminate();
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
static cloneAsset(file) {
|
|
37
|
-
return (0, types_1.cloneObject)(file, (0, types_1.isPlainObject)(file.watch) && (0, types_1.isArray)(file.watch.assets) ? new WeakSet([file.watch.assets]) : true);
|
|
38
|
-
}
|
|
39
|
-
constructor(uri, assets, startTime, abortable) {
|
|
40
|
-
super();
|
|
41
|
-
this.uri = uri;
|
|
42
|
-
this.assets = assets;
|
|
43
|
-
this.captured = false;
|
|
44
|
-
this.port = NaN;
|
|
45
|
-
this.secure = false;
|
|
46
|
-
this.hot = false;
|
|
47
|
-
this.always = false;
|
|
48
|
-
this.sockets = [];
|
|
49
|
-
this._related = [];
|
|
50
|
-
this._abortable = false;
|
|
51
|
-
this[_a] = null;
|
|
52
|
-
this[_b] = false;
|
|
53
|
-
this[_c] = '';
|
|
54
|
-
this[_d] = '';
|
|
55
|
-
if (typeof startTime === 'boolean') {
|
|
56
|
-
abortable = startTime;
|
|
57
|
-
startTime = undefined;
|
|
58
|
-
}
|
|
59
|
-
if (typeof abortable === 'boolean') {
|
|
60
|
-
this._abortable = abortable;
|
|
61
|
-
}
|
|
62
|
-
this.startTime = startTime || Date.now();
|
|
63
|
-
}
|
|
64
|
-
connection(server, port = 0, secure = false) {
|
|
65
|
-
this[kServer] = server;
|
|
66
|
-
if (port > 0) {
|
|
67
|
-
this.port = port;
|
|
68
|
-
}
|
|
69
|
-
this.secure = secure;
|
|
70
|
-
}
|
|
71
|
-
add(expires, socketId = '', id) {
|
|
72
|
-
if (expires >= 0) {
|
|
73
|
-
const previous = this.find(socketId);
|
|
74
|
-
if (!previous) {
|
|
75
|
-
this.sockets.push(new SocketRequest(expires, socketId, id));
|
|
76
|
-
}
|
|
77
|
-
else if (expires === 0 || expires > previous.expires) {
|
|
78
|
-
previous.expires = expires;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
find(socketId) {
|
|
85
|
-
return this.sockets.find(item => item.socketId === socketId);
|
|
86
|
-
}
|
|
87
|
-
send(event, data) {
|
|
88
|
-
const server = this.server;
|
|
89
|
-
let result = false;
|
|
90
|
-
if (server && (data.socketId = this.socketId)) {
|
|
91
|
-
data.event = event;
|
|
92
|
-
data.always ?? (data.always = this.always);
|
|
93
|
-
const outgoing = JSON.stringify(data);
|
|
94
|
-
server.clients.forEach(client => {
|
|
95
|
-
if (FileGroup.checkTimeout(client)) {
|
|
96
|
-
client.send(outgoing);
|
|
97
|
-
result = true;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
pause() {
|
|
104
|
-
this[kPaused] = true;
|
|
105
|
-
}
|
|
106
|
-
resume() {
|
|
107
|
-
this[kPaused] = false;
|
|
108
|
-
}
|
|
109
|
-
reset() {
|
|
110
|
-
super.reset();
|
|
111
|
-
this.captured = false;
|
|
112
|
-
}
|
|
113
|
-
get server() {
|
|
114
|
-
return this[kServer];
|
|
115
|
-
}
|
|
116
|
-
set related(value) {
|
|
117
|
-
this._related = value.map(item => {
|
|
118
|
-
item = FileGroup.cloneAsset(item);
|
|
119
|
-
item.flags = 1 /* ASSET_FLAG.IGNORE */;
|
|
120
|
-
return item;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
get related() {
|
|
124
|
-
return this._related;
|
|
125
|
-
}
|
|
126
|
-
get socketId() {
|
|
127
|
-
const result = this.sockets.filter(item => item.socketId && !item.expired).map(item => item.socketId);
|
|
128
|
-
switch (result.length) {
|
|
129
|
-
case 0:
|
|
130
|
-
return '';
|
|
131
|
-
case 1:
|
|
132
|
-
return result[0];
|
|
133
|
-
default:
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
set etag(value) {
|
|
138
|
-
if (typeof value === 'string') {
|
|
139
|
-
this[kEtag] = value;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
get etag() {
|
|
143
|
-
return this[kEtag];
|
|
144
|
-
}
|
|
145
|
-
set lastModified(value) {
|
|
146
|
-
if (typeof value === 'string') {
|
|
147
|
-
this[kLastModified] = value;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
get lastModified() {
|
|
151
|
-
return this[kEtag] ? '' : this[kLastModified];
|
|
152
|
-
}
|
|
153
|
-
get expires() {
|
|
154
|
-
let result = 0;
|
|
155
|
-
for (const { expires } of this.sockets) {
|
|
156
|
-
if (expires === 0) {
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
result = Math.max(expires, result);
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
get expired() {
|
|
164
|
-
return this.sockets.every(item => item.expired);
|
|
165
|
-
}
|
|
166
|
-
get paused() {
|
|
167
|
-
return this[kPaused];
|
|
168
|
-
}
|
|
169
|
-
get abortable() {
|
|
170
|
-
return this._abortable;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
_a = kServer, _b = kPaused, _c = kEtag, _d = kLastModified;
|
|
174
|
-
FileGroup.CONNECTION_TIMEOUT = 10 * 60000 /* TIME.m */;
|
|
175
|
-
FileGroup.CLIENT_SESSION = new Map();
|
|
176
|
-
exports.default = FileGroup;
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const core_1 = require("../../core");
|
|
6
|
+
const kPaused = Symbol('paused');
|
|
7
|
+
const kServer = Symbol('server');
|
|
8
|
+
const kEtag = Symbol('etag');
|
|
9
|
+
const kLastModified = Symbol('lastModified');
|
|
10
|
+
class SocketRequest {
|
|
11
|
+
constructor(expires, socketId, id = '') {
|
|
12
|
+
this.expires = expires;
|
|
13
|
+
this.socketId = socketId;
|
|
14
|
+
this.id = id;
|
|
15
|
+
}
|
|
16
|
+
get expired() {
|
|
17
|
+
const expires = this.expires;
|
|
18
|
+
return expires > 0 && expires !== Infinity && Date.now() > expires;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class FileGroup extends core_1.AbortComponent {
|
|
22
|
+
static checkTimeout(client) {
|
|
23
|
+
if (client.readyState === 1) {
|
|
24
|
+
const lastTime = FileGroup.CLIENT_SESSION.get(client);
|
|
25
|
+
if (!lastTime) {
|
|
26
|
+
FileGroup.CLIENT_SESSION.set(client, Date.now());
|
|
27
|
+
}
|
|
28
|
+
else if (FileGroup.CONNECTION_TIMEOUT > 0 && lastTime + FileGroup.CONNECTION_TIMEOUT <= Date.now()) {
|
|
29
|
+
client.terminate();
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
static cloneAsset(file) {
|
|
37
|
+
return (0, types_1.cloneObject)(file, (0, types_1.isPlainObject)(file.watch) && (0, types_1.isArray)(file.watch.assets) ? new WeakSet([file.watch.assets]) : true);
|
|
38
|
+
}
|
|
39
|
+
constructor(uri, assets, startTime, abortable) {
|
|
40
|
+
super();
|
|
41
|
+
this.uri = uri;
|
|
42
|
+
this.assets = assets;
|
|
43
|
+
this.captured = false;
|
|
44
|
+
this.port = NaN;
|
|
45
|
+
this.secure = false;
|
|
46
|
+
this.hot = false;
|
|
47
|
+
this.always = false;
|
|
48
|
+
this.sockets = [];
|
|
49
|
+
this._related = [];
|
|
50
|
+
this._abortable = false;
|
|
51
|
+
this[_a] = null;
|
|
52
|
+
this[_b] = false;
|
|
53
|
+
this[_c] = '';
|
|
54
|
+
this[_d] = '';
|
|
55
|
+
if (typeof startTime === 'boolean') {
|
|
56
|
+
abortable = startTime;
|
|
57
|
+
startTime = undefined;
|
|
58
|
+
}
|
|
59
|
+
if (typeof abortable === 'boolean') {
|
|
60
|
+
this._abortable = abortable;
|
|
61
|
+
}
|
|
62
|
+
this.startTime = startTime || Date.now();
|
|
63
|
+
}
|
|
64
|
+
connection(server, port = 0, secure = false) {
|
|
65
|
+
this[kServer] = server;
|
|
66
|
+
if (port > 0) {
|
|
67
|
+
this.port = port;
|
|
68
|
+
}
|
|
69
|
+
this.secure = secure;
|
|
70
|
+
}
|
|
71
|
+
add(expires, socketId = '', id) {
|
|
72
|
+
if (expires >= 0) {
|
|
73
|
+
const previous = this.find(socketId);
|
|
74
|
+
if (!previous) {
|
|
75
|
+
this.sockets.push(new SocketRequest(expires, socketId, id));
|
|
76
|
+
}
|
|
77
|
+
else if (expires === 0 || expires > previous.expires) {
|
|
78
|
+
previous.expires = expires;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
find(socketId) {
|
|
85
|
+
return this.sockets.find(item => item.socketId === socketId);
|
|
86
|
+
}
|
|
87
|
+
send(event, data) {
|
|
88
|
+
const server = this.server;
|
|
89
|
+
let result = false;
|
|
90
|
+
if (server && (data.socketId = this.socketId)) {
|
|
91
|
+
data.event = event;
|
|
92
|
+
data.always ?? (data.always = this.always);
|
|
93
|
+
const outgoing = JSON.stringify(data);
|
|
94
|
+
server.clients.forEach(client => {
|
|
95
|
+
if (FileGroup.checkTimeout(client)) {
|
|
96
|
+
client.send(outgoing);
|
|
97
|
+
result = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
pause() {
|
|
104
|
+
this[kPaused] = true;
|
|
105
|
+
}
|
|
106
|
+
resume() {
|
|
107
|
+
this[kPaused] = false;
|
|
108
|
+
}
|
|
109
|
+
reset() {
|
|
110
|
+
super.reset();
|
|
111
|
+
this.captured = false;
|
|
112
|
+
}
|
|
113
|
+
get server() {
|
|
114
|
+
return this[kServer];
|
|
115
|
+
}
|
|
116
|
+
set related(value) {
|
|
117
|
+
this._related = value.map(item => {
|
|
118
|
+
item = FileGroup.cloneAsset(item);
|
|
119
|
+
item.flags = 1 /* ASSET_FLAG.IGNORE */;
|
|
120
|
+
return item;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
get related() {
|
|
124
|
+
return this._related;
|
|
125
|
+
}
|
|
126
|
+
get socketId() {
|
|
127
|
+
const result = this.sockets.filter(item => item.socketId && !item.expired).map(item => item.socketId);
|
|
128
|
+
switch (result.length) {
|
|
129
|
+
case 0:
|
|
130
|
+
return '';
|
|
131
|
+
case 1:
|
|
132
|
+
return result[0];
|
|
133
|
+
default:
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
set etag(value) {
|
|
138
|
+
if (typeof value === 'string') {
|
|
139
|
+
this[kEtag] = value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
get etag() {
|
|
143
|
+
return this[kEtag];
|
|
144
|
+
}
|
|
145
|
+
set lastModified(value) {
|
|
146
|
+
if (typeof value === 'string') {
|
|
147
|
+
this[kLastModified] = value;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
get lastModified() {
|
|
151
|
+
return this[kEtag] ? '' : this[kLastModified];
|
|
152
|
+
}
|
|
153
|
+
get expires() {
|
|
154
|
+
let result = 0;
|
|
155
|
+
for (const { expires } of this.sockets) {
|
|
156
|
+
if (expires === 0) {
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
result = Math.max(expires, result);
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
get expired() {
|
|
164
|
+
return this.sockets.every(item => item.expired);
|
|
165
|
+
}
|
|
166
|
+
get paused() {
|
|
167
|
+
return this[kPaused];
|
|
168
|
+
}
|
|
169
|
+
get abortable() {
|
|
170
|
+
return this._abortable;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
_a = kServer, _b = kPaused, _c = kEtag, _d = kLastModified;
|
|
174
|
+
FileGroup.CONNECTION_TIMEOUT = 10 * 60000 /* TIME.m */;
|
|
175
|
+
FileGroup.CLIENT_SESSION = new Map();
|
|
176
|
+
exports.default = FileGroup;
|
|
177
177
|
|
|
178
178
|
if (exports.default) {
|
|
179
179
|
module.exports = exports.default;
|