@e-mc/watch 0.6.0 → 0.6.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 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 Studio Trigger
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 Ryuko
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;
@@ -3,8 +3,8 @@ var _a, _b, _c, _d, _e, _f;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const util = require("util");
5
5
  const ws = require("ws");
6
- const types_1 = require("../../types");
7
- const core_1 = require("../../core");
6
+ const types_1 = require("@e-mc/types");
7
+ const core_1 = require("@e-mc/core");
8
8
  const kServer = Symbol('server');
9
9
  const kStarted = Symbol('started');
10
10
  const kPaused = Symbol('paused');
@@ -151,7 +151,7 @@ class FileGroup extends core_1.AbortComponent {
151
151
  set related(value) {
152
152
  this._related = value.map(item => {
153
153
  item = FileGroup.cloneAsset(item);
154
- item.flags = 1 /* ASSET_FLAG.IGNORE */;
154
+ item.flags = 1;
155
155
  return item;
156
156
  });
157
157
  }
@@ -206,7 +206,7 @@ class FileGroup extends core_1.AbortComponent {
206
206
  }
207
207
  }
208
208
  _a = kServer, _b = kStarted, _c = kPaused, _d = kEtag, _e = kLastModified, _f = kSockets;
209
- FileGroup.CONNECTION_TIMEOUT = 10 * 60000 /* TIME.m */;
209
+ FileGroup.CONNECTION_TIMEOUT = 10 * 60000;
210
210
  FileGroup.CLIENT_SESSION = new Map();
211
211
  exports.default = FileGroup;
212
212
 
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');
@@ -113,7 +113,7 @@ class Watch extends core_1.Client {
113
113
  }
114
114
  }
115
115
  catch (err) {
116
- this.writeFail("Unknown" /* ERR_MESSAGE.UNKNOWN */, err);
116
+ this.writeFail("Unknown", err);
117
117
  }
118
118
  if (!wss) {
119
119
  return null;
@@ -164,8 +164,8 @@ class Watch extends core_1.Client {
164
164
  this._extensions = [];
165
165
  this._hostEvents = [];
166
166
  this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
167
- this[_b] = 80 /* HTTP.PORT */;
168
- this[_c] = 443 /* HTTP.PORT_SECURE */;
167
+ this[_b] = 80;
168
+ this[_c] = 443;
169
169
  this[_d] = '';
170
170
  this[_e] = '';
171
171
  this[_f] = '';
@@ -218,7 +218,7 @@ class Watch extends core_1.Client {
218
218
  continue;
219
219
  }
220
220
  let watchInterval, bundleMain;
221
- if (dest[0] === ':') {
221
+ if (dest.startsWith(':')) {
222
222
  items.sort((a, b) => a.bundleIndex - b.bundleIndex);
223
223
  bundleMain = items[0];
224
224
  dest = bundleMain.localUri;
@@ -240,7 +240,7 @@ class Watch extends core_1.Client {
240
240
  other = filegroup_1.default.cloneAsset(other);
241
241
  other.watch = { ...watch };
242
242
  }
243
- other.flags &= ~1 /* ASSET_FLAG.IGNORE */;
243
+ other.flags &= ~1;
244
244
  other.invalid = undefined;
245
245
  items.push(other);
246
246
  }
@@ -259,10 +259,10 @@ class Watch extends core_1.Client {
259
259
  const uri = target.value.uri;
260
260
  delete map[uri];
261
261
  abortTimeout(target);
262
- this.writeFail(["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, uri], err, 16 /* LOG_TYPE.WATCH */);
262
+ this.writeFail(["Unable to watch file", uri], err, 16);
263
263
  };
264
264
  const watchExpired = (map, target, message = 'Expired') => {
265
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
265
+ this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
266
266
  const data = map[target.uri];
267
267
  if (!data || data.size === 0) {
268
268
  delete map[target.uri];
@@ -326,7 +326,7 @@ class Watch extends core_1.Client {
326
326
  wss = Watch.createServer(port || (port = this.port));
327
327
  }
328
328
  if (!wss) {
329
- 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 */);
329
+ this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
330
330
  socketId = undefined;
331
331
  port = undefined;
332
332
  secure = undefined;
@@ -338,7 +338,7 @@ class Watch extends core_1.Client {
338
338
  }
339
339
  const interval = getInterval(item) || watchInterval || this.interval;
340
340
  const watching = (uri, esm) => {
341
- const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)" /* ABORT_NAME.WATCH */));
341
+ const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
342
342
  group.add(expires, socketId, id);
343
343
  if (main) {
344
344
  group.main = main;
@@ -411,7 +411,7 @@ class Watch extends core_1.Client {
411
411
  wss.close();
412
412
  }
413
413
  message = 'Destination already watched @ ' + (current.secure ? 'wss' : 'ws') + '://hostname:' + current.port;
414
- return 3 /* ERR.SERVER */;
414
+ return 3;
415
415
  }
416
416
  }
417
417
  const socket = socketId && current.find(socketId);
@@ -421,18 +421,18 @@ class Watch extends core_1.Client {
421
421
  else {
422
422
  current.add(expires, socketId, id);
423
423
  }
424
- return 0 /* ERR.NONE */;
424
+ return 0;
425
425
  }
426
426
  }
427
427
  data.set(dest, target);
428
- return 0 /* ERR.NONE */;
428
+ return 0;
429
429
  };
430
430
  if (core_1.Client.isFile(uri, 'http/s')) {
431
431
  group.url = item.url;
432
432
  group.etag = item.etag;
433
433
  group.lastModified = item.lastModified;
434
434
  if (!group.etag && !group.lastModified) {
435
- return 1 /* ERR.ETAG */;
435
+ return 1;
436
436
  }
437
437
  if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
438
438
  return status;
@@ -454,7 +454,7 @@ class Watch extends core_1.Client {
454
454
  return;
455
455
  }
456
456
  const statusCode = res.statusCode;
457
- const valid = statusCode >= 200 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */;
457
+ const valid = statusCode >= 200 && statusCode < 300;
458
458
  const map = HTTP_MAP[uri];
459
459
  const etag = res.headers.etag;
460
460
  const lastModified = res.headers['last-modified'];
@@ -510,15 +510,15 @@ class Watch extends core_1.Client {
510
510
  resolve();
511
511
  })
512
512
  .on('error', err => {
513
- if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10 /* HTTP.TIMEOUT_LIMIT */)) {
513
+ if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
514
514
  reject(err);
515
515
  return;
516
516
  }
517
517
  resolve();
518
518
  })
519
519
  .on('timeout', () => {
520
- if (!timeout.aborted && ++timeout.retries > 10 /* HTTP.TIMEOUT_LIMIT */) {
521
- reject((0, types_1.errorMessage)(408 /* HTTP_STATUS.REQUEST_TIMEOUT */, 'HTTP request timeout'));
520
+ if (!timeout.aborted && ++timeout.retries > 10) {
521
+ reject((0, types_1.errorMessage)(408, 'HTTP request timeout'));
522
522
  return;
523
523
  }
524
524
  resolve();
@@ -588,7 +588,7 @@ class Watch extends core_1.Client {
588
588
  break;
589
589
  }
590
590
  catch (err) {
591
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false });
591
+ this.writeFail(["Unable to read file", path.basename(uri)], err, { type: 32, fatal: false });
592
592
  }
593
593
  }
594
594
  }
@@ -604,9 +604,9 @@ class Watch extends core_1.Client {
604
604
  DISK_MAP[uri] = new Map([[dest, target]]);
605
605
  }
606
606
  else {
607
- return 2 /* ERR.LOCAL_ACCESS */;
607
+ return 2;
608
608
  }
609
- return 0 /* ERR.NONE */;
609
+ return 0;
610
610
  };
611
611
  if ((0, types_1.isArray)(sourceFiles) && sourceFiles.some(file => this.canRead(file, { hostPermissionOnly: !!this.host }))) {
612
612
  let index = 0;
@@ -628,33 +628,33 @@ class Watch extends core_1.Client {
628
628
  if (status > 0) {
629
629
  if (!message) {
630
630
  switch (status) {
631
- case 1 /* ERR.ETAG */:
631
+ case 1:
632
632
  if ((0, types_1.existsFlag)(item.flags)) {
633
633
  continue;
634
634
  }
635
635
  message = 'ETag unavailable';
636
636
  break;
637
- case 2 /* ERR.LOCAL_ACCESS */:
637
+ case 2:
638
638
  message = 'No read permission';
639
639
  break;
640
- case 3 /* ERR.SERVER */:
640
+ case 3:
641
641
  message = 'Server already in use';
642
642
  break;
643
643
  default:
644
- message = "Unknown" /* ERR_MESSAGE.UNKNOWN */;
644
+ message = "Unknown";
645
645
  break;
646
646
  }
647
647
  }
648
- 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));
648
+ this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
649
649
  }
650
650
  else {
651
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
651
+ this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
652
652
  }
653
653
  }
654
654
  }
655
655
  }
656
656
  async modified(watch) {
657
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
657
+ this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
658
658
  const { host, assets } = this;
659
659
  let items, sanitize = false;
660
660
  if (watch.main) {
@@ -684,7 +684,7 @@ class Watch extends core_1.Client {
684
684
  }
685
685
  }
686
686
  if (!sanitize) {
687
- items.forEach(item => item.flags |= 2 /* ASSET_FLAG.CLONE */);
687
+ items.forEach(item => item.flags |= 2);
688
688
  }
689
689
  watch.captured = false;
690
690
  try {
@@ -732,7 +732,7 @@ class Watch extends core_1.Client {
732
732
  return await manager.start();
733
733
  }
734
734
  catch (err) {
735
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, watch.url?.pathname || path.basename(watch.uri)], err);
735
+ this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
736
736
  }
737
737
  }
738
738
  configureServer({ ca, key, cert, passphrase, version, config }) {
@@ -791,7 +791,7 @@ class Watch extends core_1.Client {
791
791
  return !!this[kTlsKey] && !!this[kTlsCert];
792
792
  }
793
793
  willAbort(value) {
794
- return this.host ? this.host.willAbort(value) : value === "(watch)" /* ABORT_NAME.WATCH */;
794
+ return this.host ? this.host.willAbort(value) : value === "(watch)";
795
795
  }
796
796
  set host(value) {
797
797
  super.host = value;
@@ -839,7 +839,7 @@ class Watch extends core_1.Client {
839
839
  }
840
840
  }
841
841
  _a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kTlsKey, _f = kTlsCert, _g = kTlsPassphrase, _h = kTlsVersion, _j = kTlsConfig;
842
- Watch.PROCESS_TIMEOUT = 5 * 1000 /* TIME.S */;
842
+ Watch.PROCESS_TIMEOUT = 5 * 1000;
843
843
  exports.default = Watch;
844
844
 
845
845
  if (exports.default) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/watch",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Watch constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -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.6.0",
24
- "@e-mc/request": "0.6.0",
25
- "@e-mc/types": "0.6.0",
23
+ "@e-mc/core": "0.6.1",
24
+ "@e-mc/request": "0.6.1",
25
+ "@e-mc/types": "0.6.1",
26
26
  "picomatch": "^2.3.1",
27
- "ws": "^8.13.0"
27
+ "ws": "^8.16.0"
28
28
  }
29
29
  }