@e-mc/watch 0.3.3 → 0.4.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/LICENSE +10 -10
- package/filegroup/index.d.ts +5 -5
- package/filegroup/index.js +192 -176
- package/index.d.ts +4 -4
- package/index.js +816 -822
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2023 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/filegroup/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FileGroupConstructor } from '../../types/lib/watch';
|
|
2
|
-
import type { ExternalAsset } from '../../types/lib/asset';
|
|
3
|
-
|
|
4
|
-
declare const FileGroup: FileGroupConstructor<ExternalAsset>;
|
|
5
|
-
|
|
1
|
+
import type { FileGroupConstructor } from '../../types/lib/watch';
|
|
2
|
+
import type { ExternalAsset } from '../../types/lib/asset';
|
|
3
|
+
|
|
4
|
+
declare const FileGroup: FileGroupConstructor<ExternalAsset>;
|
|
5
|
+
|
|
6
6
|
export = FileGroup;
|
package/filegroup/index.js
CHANGED
|
@@ -1,179 +1,195 @@
|
|
|
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
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this
|
|
52
|
-
this[
|
|
53
|
-
this[
|
|
54
|
-
this[
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (typeof
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
get
|
|
124
|
-
return this
|
|
125
|
-
}
|
|
126
|
-
get
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
get
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
get
|
|
167
|
-
return this[
|
|
168
|
-
}
|
|
169
|
-
get
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d, _e;
|
|
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 kAssets = Symbol('assets');
|
|
9
|
+
const kSockets = Symbol('sockets');
|
|
10
|
+
const kStartTime = Symbol('startTime');
|
|
11
|
+
const kUri = Symbol('uri');
|
|
12
|
+
const kEtag = Symbol('etag');
|
|
13
|
+
const kLastModified = Symbol('lastModified');
|
|
14
|
+
class SocketRequest {
|
|
15
|
+
constructor(expires, socketId, id = '') {
|
|
16
|
+
this.expires = expires;
|
|
17
|
+
this.socketId = socketId;
|
|
18
|
+
this.id = id;
|
|
19
|
+
}
|
|
20
|
+
get expired() {
|
|
21
|
+
const expires = this.expires;
|
|
22
|
+
return expires > 0 && expires !== Infinity && Date.now() > expires;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class FileGroup extends core_1.AbortComponent {
|
|
26
|
+
static checkTimeout(client) {
|
|
27
|
+
if (client.readyState === 1) {
|
|
28
|
+
const lastTime = FileGroup.CLIENT_SESSION.get(client);
|
|
29
|
+
if (!lastTime) {
|
|
30
|
+
FileGroup.CLIENT_SESSION.set(client, Date.now());
|
|
31
|
+
}
|
|
32
|
+
else if (FileGroup.CONNECTION_TIMEOUT > 0 && lastTime + FileGroup.CONNECTION_TIMEOUT <= Date.now()) {
|
|
33
|
+
client.terminate();
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
static cloneAsset(file) {
|
|
41
|
+
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);
|
|
42
|
+
}
|
|
43
|
+
constructor(uri, assets, startTime, abortable) {
|
|
44
|
+
super();
|
|
45
|
+
this.captured = false;
|
|
46
|
+
this.port = NaN;
|
|
47
|
+
this.secure = false;
|
|
48
|
+
this.hot = false;
|
|
49
|
+
this.always = false;
|
|
50
|
+
this._related = [];
|
|
51
|
+
this._abortable = false;
|
|
52
|
+
this[_a] = null;
|
|
53
|
+
this[_b] = false;
|
|
54
|
+
this[_c] = '';
|
|
55
|
+
this[_d] = '';
|
|
56
|
+
this[_e] = [];
|
|
57
|
+
this[kUri] = uri;
|
|
58
|
+
this[kAssets] = assets;
|
|
59
|
+
if (typeof startTime === 'boolean') {
|
|
60
|
+
abortable = startTime;
|
|
61
|
+
startTime = undefined;
|
|
62
|
+
}
|
|
63
|
+
if (typeof abortable === 'boolean') {
|
|
64
|
+
this._abortable = abortable;
|
|
65
|
+
}
|
|
66
|
+
this[kStartTime] = startTime || Date.now();
|
|
67
|
+
}
|
|
68
|
+
connection(server, port = 0, secure = false) {
|
|
69
|
+
this[kServer] = server;
|
|
70
|
+
if (port > 0) {
|
|
71
|
+
this.port = port;
|
|
72
|
+
}
|
|
73
|
+
this.secure = secure;
|
|
74
|
+
}
|
|
75
|
+
add(expires, socketId = '', id) {
|
|
76
|
+
if (expires >= 0) {
|
|
77
|
+
const previous = this.find(socketId);
|
|
78
|
+
if (!previous) {
|
|
79
|
+
this.sockets.push(new SocketRequest(expires, socketId, id));
|
|
80
|
+
}
|
|
81
|
+
else if (expires === 0 || expires > previous.expires) {
|
|
82
|
+
previous.expires = expires;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
find(socketId) {
|
|
89
|
+
return this.sockets.find(item => item.socketId === socketId);
|
|
90
|
+
}
|
|
91
|
+
send(event, data) {
|
|
92
|
+
const server = this.server;
|
|
93
|
+
let result = false;
|
|
94
|
+
if (server && (data.socketId = this.socketId)) {
|
|
95
|
+
data.event = event;
|
|
96
|
+
data.always ?? (data.always = this.always);
|
|
97
|
+
const outgoing = JSON.stringify(data);
|
|
98
|
+
server.clients.forEach(client => {
|
|
99
|
+
if (FileGroup.checkTimeout(client)) {
|
|
100
|
+
client.send(outgoing);
|
|
101
|
+
result = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
pause() {
|
|
108
|
+
this[kPaused] = true;
|
|
109
|
+
}
|
|
110
|
+
resume() {
|
|
111
|
+
this[kPaused] = false;
|
|
112
|
+
}
|
|
113
|
+
reset() {
|
|
114
|
+
super.reset();
|
|
115
|
+
this.captured = false;
|
|
116
|
+
}
|
|
117
|
+
get server() {
|
|
118
|
+
return this[kServer];
|
|
119
|
+
}
|
|
120
|
+
get uri() {
|
|
121
|
+
return this[kUri];
|
|
122
|
+
}
|
|
123
|
+
get sockets() {
|
|
124
|
+
return this[kSockets];
|
|
125
|
+
}
|
|
126
|
+
get startTime() {
|
|
127
|
+
return this[kStartTime];
|
|
128
|
+
}
|
|
129
|
+
get assets() {
|
|
130
|
+
return this[kAssets];
|
|
131
|
+
}
|
|
132
|
+
set related(value) {
|
|
133
|
+
this._related = value.map(item => {
|
|
134
|
+
item = FileGroup.cloneAsset(item);
|
|
135
|
+
item.flags = 1 /* ASSET_FLAG.IGNORE */;
|
|
136
|
+
return item;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
get related() {
|
|
140
|
+
return this._related;
|
|
141
|
+
}
|
|
142
|
+
get socketId() {
|
|
143
|
+
const result = this.sockets.filter(item => item.socketId && !item.expired).map(item => item.socketId);
|
|
144
|
+
switch (result.length) {
|
|
145
|
+
case 0:
|
|
146
|
+
return '';
|
|
147
|
+
case 1:
|
|
148
|
+
return result[0];
|
|
149
|
+
default:
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
set etag(value) {
|
|
154
|
+
if (typeof value === 'string') {
|
|
155
|
+
this[kEtag] = value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
get etag() {
|
|
159
|
+
return this[kEtag];
|
|
160
|
+
}
|
|
161
|
+
set lastModified(value) {
|
|
162
|
+
if (typeof value === 'string') {
|
|
163
|
+
this[kLastModified] = value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
get lastModified() {
|
|
167
|
+
return this[kEtag] ? '' : this[kLastModified];
|
|
168
|
+
}
|
|
169
|
+
get expires() {
|
|
170
|
+
let result = 0;
|
|
171
|
+
for (const { expires } of this.sockets) {
|
|
172
|
+
if (expires === 0) {
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
result = Math.max(expires, result);
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
get expired() {
|
|
180
|
+
return this.sockets.every(item => item.expired);
|
|
181
|
+
}
|
|
182
|
+
get paused() {
|
|
183
|
+
return this[kPaused];
|
|
184
|
+
}
|
|
185
|
+
get abortable() {
|
|
186
|
+
return this._abortable;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
_a = kServer, _b = kPaused, _c = kEtag, _d = kLastModified, _e = kSockets;
|
|
190
|
+
FileGroup.CONNECTION_TIMEOUT = 10 * 60000 /* TIME.m */;
|
|
191
|
+
FileGroup.CLIENT_SESSION = new Map();
|
|
192
|
+
exports.default = FileGroup;
|
|
177
193
|
|
|
178
194
|
if (exports.default) {
|
|
179
195
|
module.exports = exports.default;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IFileManager, WatchConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Watch: WatchConstructor<IFileManager>;
|
|
4
|
-
|
|
1
|
+
import type { IFileManager, WatchConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Watch: WatchConstructor<IFileManager>;
|
|
4
|
+
|
|
5
5
|
export = Watch;
|