@e-mc/watch 0.5.2 → 0.5.4

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
- 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
- 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.
1
+ Copyright 2023 Mile Square Park
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
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,5 +1,7 @@
1
- ### @e-mc/watch
1
+ # @e-mc/watch
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
@@ -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;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  var _a, _b, _c, _d, _e;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const types_1 = require("../../types");
5
- const core_1 = require("../../core");
4
+ const types_1 = require("@e-mc/types");
5
+ const core_1 = require("@e-mc/core");
6
6
  const kPaused = Symbol('paused');
7
7
  const kServer = Symbol('server');
8
8
  const kAssets = Symbol('assets');
@@ -132,7 +132,7 @@ class FileGroup extends core_1.AbortComponent {
132
132
  set related(value) {
133
133
  this._related = value.map(item => {
134
134
  item = FileGroup.cloneAsset(item);
135
- item.flags = 1 /* ASSET_FLAG.IGNORE */;
135
+ item.flags = 1;
136
136
  return item;
137
137
  });
138
138
  }
@@ -187,7 +187,7 @@ class FileGroup extends core_1.AbortComponent {
187
187
  }
188
188
  }
189
189
  _a = kServer, _b = kPaused, _c = kEtag, _d = kLastModified, _e = kSockets;
190
- FileGroup.CONNECTION_TIMEOUT = 10 * 60000 /* TIME.m */;
190
+ FileGroup.CONNECTION_TIMEOUT = 10 * 60000;
191
191
  FileGroup.CLIENT_SESSION = new Map();
192
192
  exports.default = FileGroup;
193
193
 
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;
package/index.js CHANGED
@@ -6,11 +6,11 @@ const fs = require("fs");
6
6
  const https = require("https");
7
7
  const ws = require("ws");
8
8
  const pm = require("picomatch");
9
- const util_1 = require("../request/util");
10
- const types_1 = require("../types");
11
- const core_1 = require("../core");
12
- const request_1 = require("../request");
13
- const filegroup_1 = require("./filegroup");
9
+ const util_1 = require("@e-mc/request/util");
10
+ const types_1 = require("@e-mc/types");
11
+ const core_1 = require("@e-mc/core");
12
+ const request_1 = require("@e-mc/request");
13
+ const filegroup_1 = require("@e-mc/watch/filegroup");
14
14
  const kInterval = Symbol('interval');
15
15
  const kPort = Symbol('port');
16
16
  const kSecurePort = Symbol('securePort');
@@ -91,7 +91,7 @@ class Watch extends core_1.Client {
91
91
  }
92
92
  }
93
93
  catch (err) {
94
- this.writeFail("Unknown" /* ERR_MESSAGE.UNKNOWN */, err);
94
+ this.writeFail("Unknown", err);
95
95
  }
96
96
  if (wss) {
97
97
  wss.on('connection', function (socket) {
@@ -149,8 +149,8 @@ class Watch extends core_1.Client {
149
149
  this._extensions = [];
150
150
  this._hostEvents = [];
151
151
  this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
152
- this[_b] = 80 /* HTTP.PORT */;
153
- this[_c] = 443 /* HTTP.PORT_SECURE */;
152
+ this[_b] = 80;
153
+ this[_c] = 443;
154
154
  this[_d] = '';
155
155
  this[_e] = '';
156
156
  this[_f] = '';
@@ -204,7 +204,7 @@ class Watch extends core_1.Client {
204
204
  continue;
205
205
  }
206
206
  let watchInterval, bundleMain;
207
- if (dest[0] === ':') {
207
+ if (dest.startsWith(':')) {
208
208
  items.sort((a, b) => a.bundleIndex - b.bundleIndex);
209
209
  bundleMain = items[0];
210
210
  dest = bundleMain.localUri;
@@ -226,7 +226,7 @@ class Watch extends core_1.Client {
226
226
  other = filegroup_1.default.cloneAsset(other);
227
227
  other.watch = { ...watch };
228
228
  }
229
- other.flags &= ~1 /* ASSET_FLAG.IGNORE */;
229
+ other.flags &= ~1;
230
230
  other.invalid = undefined;
231
231
  items.push(other);
232
232
  }
@@ -243,10 +243,10 @@ class Watch extends core_1.Client {
243
243
  const uri = target.value.uri;
244
244
  delete map[uri];
245
245
  abortTimeout(target);
246
- this.writeFail(["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, uri], err, 16 /* LOG_TYPE.WATCH */);
246
+ this.writeFail(["Unable to watch file", uri], err, 16);
247
247
  };
248
248
  const watchExpired = (map, target, message = 'Expired') => {
249
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
249
+ this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
250
250
  const data = map[target.uri];
251
251
  if (!data || data.size === 0) {
252
252
  delete map[target.uri];
@@ -303,7 +303,7 @@ class Watch extends core_1.Client {
303
303
  wss = Watch.createServer(port || (port = this.port));
304
304
  }
305
305
  if (!wss) {
306
- this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, 'port: ' + (port || "Unknown" /* ERR_MESSAGE.UNKNOWN */)), 16 /* LOG_TYPE.WATCH */);
306
+ this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
307
307
  socketId = undefined;
308
308
  port = undefined;
309
309
  secure = undefined;
@@ -315,7 +315,7 @@ class Watch extends core_1.Client {
315
315
  }
316
316
  const interval = getInterval(item) || watchInterval || this.interval;
317
317
  const watching = (uri, esm) => {
318
- const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)" /* ABORT_NAME.WATCH */));
318
+ const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
319
319
  group.add(expires, socketId, id);
320
320
  if (main) {
321
321
  group.main = main;
@@ -388,7 +388,7 @@ class Watch extends core_1.Client {
388
388
  wss.close();
389
389
  }
390
390
  message = 'Destination already watched @ ' + (current.secure ? 'wss' : 'ws') + '://hostname:' + current.port;
391
- return 3 /* ERR.SERVER */;
391
+ return 3;
392
392
  }
393
393
  }
394
394
  const socket = socketId && current.find(socketId);
@@ -398,18 +398,18 @@ class Watch extends core_1.Client {
398
398
  else {
399
399
  current.add(expires, socketId, id);
400
400
  }
401
- return 0 /* ERR.NONE */;
401
+ return 0;
402
402
  }
403
403
  }
404
404
  data.set(dest, target);
405
- return 0 /* ERR.NONE */;
405
+ return 0;
406
406
  };
407
407
  if (core_1.Client.isFile(uri, 'http/s')) {
408
408
  group.url = item.url;
409
409
  group.etag = item.etag;
410
410
  group.lastModified = item.lastModified;
411
411
  if (!group.etag && !group.lastModified) {
412
- return 1 /* ERR.ETAG */;
412
+ return 1;
413
413
  }
414
414
  if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
415
415
  return status;
@@ -431,7 +431,7 @@ class Watch extends core_1.Client {
431
431
  return;
432
432
  }
433
433
  const statusCode = res.statusCode;
434
- const valid = statusCode >= 200 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */;
434
+ const valid = statusCode >= 200 && statusCode < 300;
435
435
  const map = HTTP_MAP[uri];
436
436
  const etag = res.headers.etag;
437
437
  const lastModified = res.headers['last-modified'];
@@ -483,15 +483,15 @@ class Watch extends core_1.Client {
483
483
  resolve();
484
484
  })
485
485
  .on('error', err => {
486
- if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10 /* HTTP.TIMEOUT_LIMIT */)) {
486
+ if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
487
487
  reject(err);
488
488
  return;
489
489
  }
490
490
  resolve();
491
491
  })
492
492
  .on('timeout', () => {
493
- if (!timeout.aborted && ++timeout.retries > 10 /* HTTP.TIMEOUT_LIMIT */) {
494
- reject((0, types_1.errorMessage)(408 /* HTTP_STATUS.REQUEST_TIMEOUT */, 'HTTP request timeout'));
493
+ if (!timeout.aborted && ++timeout.retries > 10) {
494
+ reject((0, types_1.errorMessage)(408, 'HTTP request timeout'));
495
495
  return;
496
496
  }
497
497
  resolve();
@@ -561,7 +561,7 @@ class Watch extends core_1.Client {
561
561
  break;
562
562
  }
563
563
  catch (err) {
564
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false });
564
+ this.writeFail(["Unable to read file", path.basename(uri)], err, { type: 32, fatal: false });
565
565
  }
566
566
  }
567
567
  }
@@ -577,9 +577,9 @@ class Watch extends core_1.Client {
577
577
  DISK_MAP[uri] = new Map([[dest, target]]);
578
578
  }
579
579
  else {
580
- return 2 /* ERR.LOCAL_ACCESS */;
580
+ return 2;
581
581
  }
582
- return 0 /* ERR.NONE */;
582
+ return 0;
583
583
  };
584
584
  if ((0, types_1.isArray)(sourceFiles) && sourceFiles.some(file => this.canRead(file, { hostPermissionOnly: !!this.host }))) {
585
585
  let index = 0;
@@ -601,34 +601,34 @@ class Watch extends core_1.Client {
601
601
  if (status > 0) {
602
602
  if (!message) {
603
603
  switch (status) {
604
- case 1 /* ERR.ETAG */:
604
+ case 1:
605
605
  if ((0, types_1.existsFlag)(item.flags)) {
606
606
  continue;
607
607
  }
608
608
  message = 'ETag unavailable';
609
609
  break;
610
- case 2 /* ERR.LOCAL_ACCESS */:
610
+ case 2:
611
611
  message = 'No read permission';
612
612
  break;
613
- case 3 /* ERR.SERVER */:
613
+ case 3:
614
614
  message = 'Server already in use';
615
615
  break;
616
616
  default:
617
- message = "Unknown" /* ERR_MESSAGE.UNKNOWN */;
617
+ message = "Unknown";
618
618
  break;
619
619
  }
620
620
  }
621
- this.formatFail((16 /* LOG_TYPE.WATCH */ | (status === 2 /* ERR.LOCAL_ACCESS */ ? 8192 /* LOG_TYPE.PERMISSION */ : 0)), 'WATCH', ["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
621
+ this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
622
622
  }
623
623
  else {
624
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
624
+ this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
625
625
  }
626
626
  }
627
627
  }
628
628
  }
629
629
  }
630
630
  async modified(watch) {
631
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
631
+ this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
632
632
  const { host, assets } = this;
633
633
  let items, sanitize = false;
634
634
  if (watch.main) {
@@ -658,7 +658,7 @@ class Watch extends core_1.Client {
658
658
  }
659
659
  }
660
660
  if (!sanitize) {
661
- items.forEach(item => item.flags |= 2 /* ASSET_FLAG.CLONE */);
661
+ items.forEach(item => item.flags |= 2);
662
662
  }
663
663
  watch.captured = false;
664
664
  try {
@@ -705,7 +705,7 @@ class Watch extends core_1.Client {
705
705
  }
706
706
  }
707
707
  catch (err) {
708
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, watch.url?.pathname || path.basename(watch.uri)], err);
708
+ this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
709
709
  }
710
710
  }
711
711
  configureServer({ ca, key, cert, passphrase, version, config }) {
@@ -764,7 +764,7 @@ class Watch extends core_1.Client {
764
764
  return !!this[kTlsKey] && !!this[kTlsCert];
765
765
  }
766
766
  willAbort(value) {
767
- return this.host ? this.host.willAbort(value) : value === "(watch)" /* ABORT_NAME.WATCH */;
767
+ return this.host ? this.host.willAbort(value) : value === "(watch)";
768
768
  }
769
769
  set host(value) {
770
770
  super.host = value;
@@ -812,7 +812,7 @@ class Watch extends core_1.Client {
812
812
  }
813
813
  }
814
814
  _a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kTlsKey, _f = kTlsCert, _g = kTlsPassphrase, _h = kTlsVersion, _j = kTlsConfig;
815
- Watch.PROCESS_TIMEOUT = 5 * 1000 /* TIME.S */;
815
+ Watch.PROCESS_TIMEOUT = 5 * 1000;
816
816
  exports.default = Watch;
817
817
 
818
818
  if (exports.default) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/watch",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Watch constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/e-mc.git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
13
  "directory": "src/watch"
14
14
  },
15
15
  "keywords": [
@@ -17,13 +17,13 @@
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.5.2",
24
- "@e-mc/request": "0.5.2",
25
- "@e-mc/types": "0.5.2",
23
+ "@e-mc/core": "0.5.4",
24
+ "@e-mc/request": "0.5.4",
25
+ "@e-mc/types": "0.5.4",
26
26
  "picomatch": "^2.3.1",
27
- "ws": "^8.13.0"
27
+ "ws": "^8.16.0"
28
28
  }
29
29
  }