@e-mc/watch 0.8.6 → 0.8.8

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 CHANGED
@@ -1,11 +1,7 @@
1
1
  Copyright 2024 An Pham
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
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
- 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.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/watch
2
2
 
3
3
  * NodeJS 14
4
- * ES2020
4
+ * ES2019
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { IFileManager, ModuleConstructor } from "./index";
@@ -57,12 +57,12 @@ interface WatchConstructor extends ModuleConstructor {
57
57
 
58
58
  ## References
59
59
 
60
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/asset.d.ts
61
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
62
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/filemanager.d.ts
63
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
64
- - https://www.unpkg.com/@e-mc/types@0.8.6/lib/watch.d.ts
60
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/asset.d.ts
61
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/core.d.ts
62
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/filemanager.d.ts
63
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/settings.d.ts
64
+ - https://www.unpkg.com/@e-mc/types@0.8.8/lib/watch.d.ts
65
65
 
66
66
  ## LICENSE
67
67
 
68
- BSD 3-Clause
68
+ MIT
@@ -95,11 +95,12 @@ class FileGroup extends core_1.AbortComponent {
95
95
  return this.sockets.find(item => item.socketId === socketId);
96
96
  }
97
97
  send(event, data) {
98
+ var _g;
98
99
  const server = this.server;
99
100
  let result = false;
100
101
  if (server && (data.socketId = this.socketId)) {
101
102
  data.event = event;
102
- data.always ?? (data.always = this.always);
103
+ (_g = data.always) !== null && _g !== void 0 ? _g : (data.always = this.always);
103
104
  const value = data.value;
104
105
  if (value && (util.types.isAnyArrayBuffer(value) || util.types.isArrayBufferView(value))) {
105
106
  try {
package/index.js CHANGED
@@ -26,15 +26,6 @@ const DISK_MAP = new Map();
26
26
  const PORT_MAP = new Map();
27
27
  const SECURE_MAP = new Map();
28
28
  let STATE_MAP = new WeakSet();
29
- function isConnectionTimeout(err) {
30
- switch (err instanceof Error && err.code) {
31
- case 'ETIMEDOUT':
32
- case 'ECONNRESET':
33
- return true;
34
- default:
35
- return false;
36
- }
37
- }
38
29
  function abortTimeout(group) {
39
30
  group.timeout.aborted = true;
40
31
  const watcher = group.watcher;
@@ -91,7 +82,7 @@ class Watch extends core_1.Client {
91
82
  ca: ca && request_1.default.readCACert(ca, true) || undefined,
92
83
  key: passphrase ? [{ pem: key, passphrase }] : key,
93
84
  cert,
94
- minVersion: version || config?.minVersion
85
+ minVersion: version || (config === null || config === void 0 ? void 0 : config.minVersion)
95
86
  });
96
87
  server.listen(port);
97
88
  wss = new ws.Server({ server });
@@ -191,6 +182,7 @@ class Watch extends core_1.Client {
191
182
  }
192
183
  start(assets, permission) {
193
184
  var _k;
185
+ var _l;
194
186
  if (this.aborted) {
195
187
  return;
196
188
  }
@@ -205,7 +197,7 @@ class Watch extends core_1.Client {
205
197
  }
206
198
  const { bundleId, uri, localUri } = item;
207
199
  if (!(0, types_1.isEmpty)(bundleId)) {
208
- (destMap[_k = ':' + bundleId] || (destMap[_k] = [])).push(item);
200
+ (destMap[_l = ':' + bundleId] || (destMap[_l] = [])).push(item);
209
201
  }
210
202
  else if (uri && localUri) {
211
203
  (destMap[localUri] || (destMap[localUri] = [])).push(item);
@@ -230,7 +222,7 @@ class Watch extends core_1.Client {
230
222
  for (let i = 0, length = items.length; i < length; ++i) {
231
223
  const watch = items[i].watch;
232
224
  if ((0, types_1.isObject)(watch)) {
233
- watch.assets?.forEach(other => {
225
+ (_k = watch.assets) === null || _k === void 0 ? void 0 : _k.forEach(other => {
234
226
  if (items.includes(other)) {
235
227
  return;
236
228
  }
@@ -263,7 +255,7 @@ class Watch extends core_1.Client {
263
255
  const watchExpired = (map, target, message = 'Expired') => {
264
256
  this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
265
257
  const data = map.get(target.uri);
266
- if (!data?.size) {
258
+ if (!(data === null || data === void 0 ? void 0 : data.size)) {
267
259
  map.delete(target.uri);
268
260
  return true;
269
261
  }
@@ -337,6 +329,7 @@ class Watch extends core_1.Client {
337
329
  }
338
330
  const interval = getInterval(item) || watchInterval || this.interval;
339
331
  const watching = (uri, esm) => {
332
+ var _k;
340
333
  const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
341
334
  group.add(expires, socketId, id);
342
335
  if (main) {
@@ -366,13 +359,14 @@ class Watch extends core_1.Client {
366
359
  const timeout = { interval, retries: 0, aborted: false };
367
360
  const target = { value: group, timeout, watcher: null };
368
361
  const isMap = (value) => value ? value.size > 0 : false;
369
- const wasAborted = (result, current) => result?.aborted && current.abortable && current.abort();
362
+ const wasAborted = (result, current) => (result === null || result === void 0 ? void 0 : result.aborted) && current.abortable && current.abort();
370
363
  const checkPreceding = (map) => {
364
+ var _k;
371
365
  const data = map.get(uri);
372
366
  if (!data) {
373
367
  return;
374
368
  }
375
- const current = data.get(dest)?.value;
369
+ const current = (_k = data.get(dest)) === null || _k === void 0 ? void 0 : _k.value;
376
370
  if (current && !current.expired) {
377
371
  let reset;
378
372
  if (id) {
@@ -437,7 +431,7 @@ class Watch extends core_1.Client {
437
431
  return status;
438
432
  }
439
433
  const url = group.url || (group.url = new URL(uri));
440
- const request = this.host?.Request || new request_1.default();
434
+ const request = ((_k = this.host) === null || _k === void 0 ? void 0 : _k.Request) || new request_1.default();
441
435
  const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
442
436
  const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
443
437
  (function recurse() {
@@ -457,7 +451,7 @@ class Watch extends core_1.Client {
457
451
  const map = HTTP_MAP.get(uri);
458
452
  const etag = res.headers.etag;
459
453
  const lastModified = res.headers['last-modified'];
460
- if (valid && map?.size && (etag || lastModified)) {
454
+ if (valid && (map === null || map === void 0 ? void 0 : map.size) && (etag || lastModified)) {
461
455
  for (const [destUrl, input] of map) {
462
456
  const value = input.value;
463
457
  if (value.paused) {
@@ -509,7 +503,7 @@ class Watch extends core_1.Client {
509
503
  resolve();
510
504
  })
511
505
  .on('error', err => {
512
- if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
506
+ if (!timeout.aborted && !(core_1.Client.isErrorCode(err, 'ETIMEDOUT', 'ECONNRESET') && ++timeout.retries <= 10)) {
513
507
  reject(err);
514
508
  return;
515
509
  }
@@ -540,7 +534,7 @@ class Watch extends core_1.Client {
540
534
  })
541
535
  .catch(err => {
542
536
  fatalError(HTTP_MAP, target, err);
543
- client?.destroy();
537
+ client === null || client === void 0 ? void 0 : client.destroy();
544
538
  });
545
539
  }).call(this);
546
540
  HTTP_MAP.set(uri, new Map([[dest, target]]));
@@ -651,6 +645,7 @@ class Watch extends core_1.Client {
651
645
  }
652
646
  }
653
647
  async modified(watch) {
648
+ var _k, _l, _m, _o;
654
649
  this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
655
650
  const { host, assets } = this;
656
651
  let items, sanitize = false;
@@ -685,7 +680,7 @@ class Watch extends core_1.Client {
685
680
  }
686
681
  watch.captured = false;
687
682
  try {
688
- const manager = this.whenModified?.(items, sanitize);
683
+ const manager = (_k = this.whenModified) === null || _k === void 0 ? void 0 : _k.call(this, items, sanitize);
689
684
  for (const callback of this.extensions) {
690
685
  try {
691
686
  const listener = callback(watch, items);
@@ -707,7 +702,7 @@ class Watch extends core_1.Client {
707
702
  if (host && watch.document) {
708
703
  for (const { instance } of host.Document) {
709
704
  if (host.hasDocument(instance, watch.document)) {
710
- const result = instance.watchInit?.(watch, items, sanitize);
705
+ const result = (_l = instance.watchInit) === null || _l === void 0 ? void 0 : _l.call(instance, watch, items, sanitize);
711
706
  if (result) {
712
707
  if ((0, types_1.isArray)(result.using)) {
713
708
  manager.using(...result.using);
@@ -719,7 +714,7 @@ class Watch extends core_1.Client {
719
714
  }
720
715
  }
721
716
  }
722
- const listener = instance.watchModified?.(watch, items);
717
+ const listener = (_m = instance.watchModified) === null || _m === void 0 ? void 0 : _m.call(instance, watch, items);
723
718
  if (typeof listener === 'function') {
724
719
  manager.on('end', listener);
725
720
  }
@@ -729,7 +724,7 @@ class Watch extends core_1.Client {
729
724
  return await manager.start();
730
725
  }
731
726
  catch (err) {
732
- this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
727
+ this.writeFail(["Unknown", ((_o = watch.url) === null || _o === void 0 ? void 0 : _o.pathname) || path.basename(watch.uri)], err);
733
728
  }
734
729
  }
735
730
  configureServer({ ca, key, cert, passphrase, version, config }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/watch",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "Watch constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,12 +17,12 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.6",
24
- "@e-mc/request": "0.8.6",
25
- "@e-mc/types": "0.8.6",
23
+ "@e-mc/core": "0.8.8",
24
+ "@e-mc/request": "0.8.8",
25
+ "@e-mc/types": "0.8.8",
26
26
  "picomatch": "^3.0.1",
27
27
  "ws": "^8.16.0"
28
28
  }