@e-mc/watch 0.8.4 → 0.8.6

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,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { IFileManager, ModuleConstructor } from "./index";
@@ -23,7 +23,7 @@ import type * as ws from "ws";
23
23
 
24
24
  interface IWatch extends IClient<IFileManager, WatchModule, ModifiedPostFinalizeListener> {
25
25
  connectTimeout: number;
26
- start(assets: ExternalAsset[], permission?: IPermission): void;
26
+ start(assets: ExternalAsset[], permission?: IPermission | null): void;
27
27
  modified(watch: IFileGroup<ExternalAsset>): Promise<FinalizeResult | void>;
28
28
  configureServer(options: SecureOptions): boolean;
29
29
  setCA(value: string): boolean;
@@ -57,11 +57,11 @@ interface WatchConstructor extends ModuleConstructor {
57
57
 
58
58
  ## References
59
59
 
60
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/asset.d.ts
61
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
62
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/filemanager.d.ts
63
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
64
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/watch.d.ts
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
65
65
 
66
66
  ## LICENSE
67
67
 
@@ -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.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');
@@ -116,7 +116,7 @@ class Watch extends core_1.Client {
116
116
  }
117
117
  }
118
118
  catch (err) {
119
- this.writeFail("Unknown" /* ERR_MESSAGE.UNKNOWN */, err);
119
+ this.writeFail("Unknown", err);
120
120
  }
121
121
  if (!wss) {
122
122
  return null;
@@ -163,8 +163,8 @@ class Watch extends core_1.Client {
163
163
  this._extensions = [];
164
164
  this._hostEvents = [];
165
165
  this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
166
- this[_b] = 80 /* HTTP.PORT */;
167
- this[_c] = 443 /* HTTP.PORT_SECURE */;
166
+ this[_b] = 80;
167
+ this[_c] = 443;
168
168
  this[_d] = '';
169
169
  this[_e] = '';
170
170
  this[_f] = '';
@@ -239,7 +239,7 @@ class Watch extends core_1.Client {
239
239
  other = filegroup_1.default.cloneAsset(other);
240
240
  other.watch = { ...watch };
241
241
  }
242
- other.flags &= ~1 /* ASSET_FLAG.IGNORE */;
242
+ other.flags &= ~1;
243
243
  other.invalid = undefined;
244
244
  items.push(other);
245
245
  }
@@ -258,10 +258,10 @@ class Watch extends core_1.Client {
258
258
  const uri = target.value.uri;
259
259
  map.delete(uri);
260
260
  abortTimeout(target);
261
- this.writeFail(["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, uri], err, 16 /* LOG_TYPE.WATCH */);
261
+ this.writeFail(["Unable to watch file", uri], err, 16);
262
262
  };
263
263
  const watchExpired = (map, target, message = 'Expired') => {
264
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
264
+ this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
265
265
  const data = map.get(target.uri);
266
266
  if (!data?.size) {
267
267
  map.delete(target.uri);
@@ -325,7 +325,7 @@ class Watch extends core_1.Client {
325
325
  wss = Watch.createServer(port || (port = this.port));
326
326
  }
327
327
  if (!wss) {
328
- 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 */);
328
+ this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
329
329
  socketId = undefined;
330
330
  port = undefined;
331
331
  secure = undefined;
@@ -337,7 +337,7 @@ class Watch extends core_1.Client {
337
337
  }
338
338
  const interval = getInterval(item) || watchInterval || this.interval;
339
339
  const watching = (uri, esm) => {
340
- const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)" /* ABORT_NAME.WATCH */));
340
+ const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
341
341
  group.add(expires, socketId, id);
342
342
  if (main) {
343
343
  group.main = main;
@@ -410,7 +410,7 @@ class Watch extends core_1.Client {
410
410
  wss.close();
411
411
  }
412
412
  message = 'Destination already watched @ ' + (current.secure ? 'wss' : 'ws') + '://hostname:' + current.port;
413
- return 3 /* ERR.SERVER */;
413
+ return 3;
414
414
  }
415
415
  }
416
416
  const socket = socketId && current.find(socketId);
@@ -420,18 +420,18 @@ class Watch extends core_1.Client {
420
420
  else {
421
421
  current.add(expires, socketId, id);
422
422
  }
423
- return 0 /* ERR.NONE */;
423
+ return 0;
424
424
  }
425
425
  }
426
426
  data.set(dest, target);
427
- return 0 /* ERR.NONE */;
427
+ return 0;
428
428
  };
429
429
  if (core_1.Client.isFile(uri, 'http/s')) {
430
430
  group.url = item.url;
431
431
  group.etag = item.etag;
432
432
  group.lastModified = item.lastModified;
433
433
  if (!group.etag && !group.lastModified) {
434
- return 1 /* ERR.ETAG */;
434
+ return 1;
435
435
  }
436
436
  if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
437
437
  return status;
@@ -453,7 +453,7 @@ class Watch extends core_1.Client {
453
453
  return;
454
454
  }
455
455
  const statusCode = res.statusCode;
456
- const valid = statusCode >= 200 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */;
456
+ const valid = statusCode >= 200 && statusCode < 300;
457
457
  const map = HTTP_MAP.get(uri);
458
458
  const etag = res.headers.etag;
459
459
  const lastModified = res.headers['last-modified'];
@@ -509,15 +509,15 @@ class Watch extends core_1.Client {
509
509
  resolve();
510
510
  })
511
511
  .on('error', err => {
512
- if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10 /* HTTP.TIMEOUT_LIMIT */)) {
512
+ if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
513
513
  reject(err);
514
514
  return;
515
515
  }
516
516
  resolve();
517
517
  })
518
518
  .on('timeout', () => {
519
- if (!timeout.aborted && ++timeout.retries > 10 /* HTTP.TIMEOUT_LIMIT */) {
520
- reject((0, types_1.errorMessage)(408 /* HTTP_STATUS.REQUEST_TIMEOUT */, 'HTTP request timeout'));
519
+ if (!timeout.aborted && ++timeout.retries > 10) {
520
+ reject((0, types_1.errorMessage)(408, 'HTTP request timeout'));
521
521
  return;
522
522
  }
523
523
  resolve();
@@ -585,7 +585,7 @@ class Watch extends core_1.Client {
585
585
  break;
586
586
  }
587
587
  catch (err) {
588
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false });
588
+ this.writeFail(["Unable to read file", path.basename(uri)], err, { type: 32, fatal: false });
589
589
  }
590
590
  }
591
591
  }
@@ -601,9 +601,9 @@ class Watch extends core_1.Client {
601
601
  DISK_MAP.set(uri, new Map([[dest, target]]));
602
602
  }
603
603
  else {
604
- return 2 /* ERR.LOCAL_ACCESS */;
604
+ return 2;
605
605
  }
606
- return 0 /* ERR.NONE */;
606
+ return 0;
607
607
  };
608
608
  if ((0, types_1.isArray)(sourceFiles) && sourceFiles.some(file => this.canRead(file, { hostPermissionOnly: !!this.host }))) {
609
609
  let index = 0;
@@ -625,33 +625,33 @@ class Watch extends core_1.Client {
625
625
  if (status > 0) {
626
626
  if (!message) {
627
627
  switch (status) {
628
- case 1 /* ERR.ETAG */:
628
+ case 1:
629
629
  if ((0, types_1.existsFlag)(item.flags)) {
630
630
  continue;
631
631
  }
632
632
  message = 'ETag unavailable';
633
633
  break;
634
- case 2 /* ERR.LOCAL_ACCESS */:
634
+ case 2:
635
635
  message = 'No read permission';
636
636
  break;
637
- case 3 /* ERR.SERVER */:
637
+ case 3:
638
638
  message = 'Server already in use';
639
639
  break;
640
640
  default:
641
- message = "Unknown" /* ERR_MESSAGE.UNKNOWN */;
641
+ message = "Unknown";
642
642
  break;
643
643
  }
644
644
  }
645
- 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));
645
+ this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
646
646
  }
647
647
  else {
648
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
648
+ this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
649
649
  }
650
650
  }
651
651
  }
652
652
  }
653
653
  async modified(watch) {
654
- this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
654
+ this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
655
655
  const { host, assets } = this;
656
656
  let items, sanitize = false;
657
657
  if (watch.main) {
@@ -681,7 +681,7 @@ class Watch extends core_1.Client {
681
681
  }
682
682
  }
683
683
  if (!sanitize) {
684
- items.forEach(item => item.flags |= 2 /* ASSET_FLAG.CLONE */);
684
+ items.forEach(item => item.flags |= 2);
685
685
  }
686
686
  watch.captured = false;
687
687
  try {
@@ -729,7 +729,7 @@ class Watch extends core_1.Client {
729
729
  return await manager.start();
730
730
  }
731
731
  catch (err) {
732
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, watch.url?.pathname || path.basename(watch.uri)], err);
732
+ this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
733
733
  }
734
734
  }
735
735
  configureServer({ ca, key, cert, passphrase, version, config }) {
@@ -788,7 +788,7 @@ class Watch extends core_1.Client {
788
788
  return !!this[kTlsKey] && !!this[kTlsCert];
789
789
  }
790
790
  willAbort(value) {
791
- return this.host ? this.host.willAbort(value) : value === "(watch)" /* ABORT_NAME.WATCH */;
791
+ return this.host ? this.host.willAbort(value) : value === "(watch)";
792
792
  }
793
793
  set host(value) {
794
794
  super.host = value;
@@ -836,7 +836,7 @@ class Watch extends core_1.Client {
836
836
  }
837
837
  }
838
838
  _a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kTlsKey, _f = kTlsCert, _g = kTlsPassphrase, _h = kTlsVersion, _j = kTlsConfig;
839
- Watch.PROCESS_TIMEOUT = 5 * 1000 /* TIME.S */;
839
+ Watch.PROCESS_TIMEOUT = 5 * 1000;
840
840
  exports.default = Watch;
841
841
 
842
842
  if (exports.default) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/watch",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Watch constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.4",
24
- "@e-mc/request": "0.8.4",
25
- "@e-mc/types": "0.8.4",
23
+ "@e-mc/core": "0.8.6",
24
+ "@e-mc/request": "0.8.6",
25
+ "@e-mc/types": "0.8.6",
26
26
  "picomatch": "^3.0.1",
27
27
  "ws": "^8.16.0"
28
28
  }