@e-mc/watch 0.10.1 → 0.10.3

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,11 @@
1
- Copyright 2024 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 2024 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/README.md CHANGED
@@ -1,119 +1,119 @@
1
- # @e-mc/watch
2
-
3
- * NodeJS 16
4
- * ES2020
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.1/lib/index.d.ts)
13
-
14
- ```typescript
15
- import type { IFileManager, ModuleConstructor } from "./index";
16
- import type { ExternalAsset } from "./asset";
17
- import type { HostInitConfig, IClient, IPermission } from "./core";
18
- import type { FinalizeResult, PostFinalizeCallback } from "./filemanager";
19
- import type { WatchModule } from "./settings";
20
- import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions } from "./watch";
21
-
22
- import type * as ws from "ws";
23
-
24
- interface IWatch extends IClient<IFileManager, WatchModule, ModifiedPostFinalizeListener> {
25
- connectTimeout: number;
26
- init(config?: HostInitConfig): this;
27
- start(assets: ExternalAsset[], permission?: IPermission | null): void;
28
- modified(watch: IFileGroup<ExternalAsset>): Promise<FinalizeResult | void>;
29
- configureServer(options: SecureOptions): boolean;
30
- setCA(value: string): boolean;
31
- setSSLKey(value: string): boolean;
32
- setSSLCert(value: string): boolean;
33
- hasSecureProtocol(): boolean;
34
- whenModified?(assets: ExternalAsset[], postFinalize: PostFinalizeCallback): IFileManager;
35
- whenModified?(assets: ExternalAsset[], sanitize?: boolean, postFinalize?: PostFinalizeCallback): IFileManager;
36
- set assets(value: ExternalAsset[]);
37
- get assets(): ExternalAsset[];
38
- set interval(value);
39
- get interval(): number;
40
- set port(value);
41
- get port(): number;
42
- set securePort(value);
43
- get securePort(): number;
44
- }
45
-
46
- interface WatchConstructor extends ModuleConstructor {
47
- createServer(port: number, active: boolean): ws.Server | null;
48
- createServer(port: number, secure?: SecureOptions | null, active?: boolean): ws.Server | null;
49
- shutdown(): void;
50
- setTimeout(value: number | string): void;
51
- checkTimeout(client: ws): boolean;
52
- readonly prototype: IWatch;
53
- new(module?: WatchModule): IWatch;
54
- }
55
- ```
56
-
57
- ## Settings
58
-
59
- ```typescript
60
- import type { PermittedDirectories } from "./core";
61
-
62
- import type { SecureVersion } from "tls";
63
-
64
- interface WatchModule {
65
- // handler: "@e-mc/watch";
66
- extensions?: string[];
67
- timeout?: number | string;
68
- interval?: number | string;
69
- port?: number;
70
- secure?: {
71
- port?: number;
72
- ca?: string;
73
- key?: string;
74
- cert?: string;
75
- passphrase?: string;
76
- ciphers?: string;
77
- version?: SecureVersion;
78
- };
79
- settings?: {
80
- broadcast_id?: string | string[];
81
- users?: Record<string, Record<string, unknown>>;
82
- };
83
- permission?: PermittedDirectories;
84
- }
85
- ```
86
-
87
- ### Example usage
88
-
89
- ```javascript
90
- const Watch = require("@e-mc/watch");
91
-
92
- const instance = new Watch({ interval: 100, port: 8080 });
93
- instance.init();
94
-
95
- instance.whenModified = (assets) => {
96
- assets.forEach(item => console.log(item.uri));
97
- };
98
-
99
- const assets = [
100
- { localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
101
- { localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
102
- ];
103
-
104
- instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
105
- ```
106
-
107
- ## References
108
-
109
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/asset.d.ts
110
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/core.d.ts
111
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/filemanager.d.ts
112
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/settings.d.ts
113
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/watch.d.ts
114
-
115
- * https://www.npmjs.com/package/@types/ws
116
-
117
- ## LICENSE
118
-
1
+ # @e-mc/watch
2
+
3
+ * NodeJS 16
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.3/lib/index.d.ts)
13
+
14
+ ```typescript
15
+ import type { IFileManager, ModuleConstructor } from "./index";
16
+ import type { ExternalAsset } from "./asset";
17
+ import type { HostInitConfig, IClient, IPermission } from "./core";
18
+ import type { FinalizeResult, PostFinalizeCallback } from "./filemanager";
19
+ import type { WatchModule } from "./settings";
20
+ import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions } from "./watch";
21
+
22
+ import type * as ws from "ws";
23
+
24
+ interface IWatch extends IClient<IFileManager, WatchModule, ModifiedPostFinalizeListener> {
25
+ connectTimeout: number;
26
+ init(config?: HostInitConfig): this;
27
+ start(assets: ExternalAsset[], permission?: IPermission | null): void;
28
+ modified(watch: IFileGroup<ExternalAsset>): Promise<FinalizeResult | void>;
29
+ configureServer(options: SecureOptions): boolean;
30
+ setCA(value: string): boolean;
31
+ setSSLKey(value: string): boolean;
32
+ setSSLCert(value: string): boolean;
33
+ hasSecureProtocol(): boolean;
34
+ whenModified?(assets: ExternalAsset[], postFinalize: PostFinalizeCallback): IFileManager;
35
+ whenModified?(assets: ExternalAsset[], sanitize?: boolean, postFinalize?: PostFinalizeCallback): IFileManager;
36
+ set assets(value: ExternalAsset[]);
37
+ get assets(): ExternalAsset[];
38
+ set interval(value);
39
+ get interval(): number;
40
+ set port(value);
41
+ get port(): number;
42
+ set securePort(value);
43
+ get securePort(): number;
44
+ }
45
+
46
+ interface WatchConstructor extends ModuleConstructor {
47
+ createServer(port: number, active: boolean): ws.Server | null;
48
+ createServer(port: number, secure?: SecureOptions | null, active?: boolean): ws.Server | null;
49
+ shutdown(): void;
50
+ setTimeout(value: number | string): void;
51
+ checkTimeout(client: ws): boolean;
52
+ readonly prototype: IWatch;
53
+ new(module?: WatchModule): IWatch;
54
+ }
55
+ ```
56
+
57
+ ## Settings
58
+
59
+ ```typescript
60
+ import type { PermittedDirectories } from "./core";
61
+
62
+ import type { SecureVersion } from "tls";
63
+
64
+ interface WatchModule {
65
+ // handler: "@e-mc/watch";
66
+ extensions?: string[];
67
+ timeout?: number | string;
68
+ interval?: number | string;
69
+ port?: number;
70
+ secure?: {
71
+ port?: number;
72
+ ca?: string;
73
+ key?: string;
74
+ cert?: string;
75
+ passphrase?: string;
76
+ ciphers?: string;
77
+ version?: SecureVersion;
78
+ };
79
+ settings?: {
80
+ broadcast_id?: string | string[];
81
+ users?: Record<string, Record<string, unknown>>;
82
+ };
83
+ permission?: PermittedDirectories;
84
+ }
85
+ ```
86
+
87
+ ### Example usage
88
+
89
+ ```javascript
90
+ const Watch = require("@e-mc/watch");
91
+
92
+ const instance = new Watch({ interval: 100, port: 8080 });
93
+ instance.init();
94
+
95
+ instance.whenModified = (assets) => {
96
+ assets.forEach(item => console.log(item.uri));
97
+ };
98
+
99
+ const assets = [
100
+ { localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
101
+ { localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
102
+ ];
103
+
104
+ instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
105
+ ```
106
+
107
+ ## References
108
+
109
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/asset.d.ts
110
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/core.d.ts
111
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/filemanager.d.ts
112
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/settings.d.ts
113
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/watch.d.ts
114
+
115
+ * https://www.npmjs.com/package/@types/ws
116
+
117
+ ## LICENSE
118
+
119
119
  BSD 3-Clause
@@ -1,5 +1,5 @@
1
- import type { FileGroupConstructor } from '../../types/lib/watch';
2
-
3
- declare const FileGroup: FileGroupConstructor;
4
-
1
+ import type { FileGroupConstructor } from '@e-mc/types/lib/watch';
2
+
3
+ declare const FileGroup: FileGroupConstructor;
4
+
5
5
  export = FileGroup;
@@ -2,8 +2,8 @@
2
2
  var _a, _b, _c, _d, _e, _f;
3
3
  const util = require("util");
4
4
  const ws = require("ws");
5
- const core_1 = require("@e-mc/core");
6
5
  const types_1 = require("@e-mc/types");
6
+ const core_1 = require("@e-mc/core");
7
7
  const kServer = Symbol('server');
8
8
  const kStarted = Symbol('started');
9
9
  const kPaused = Symbol('paused');
@@ -98,7 +98,7 @@ class FileGroup extends core_1.AbortComponent {
98
98
  let result = false;
99
99
  if (server && (data.socketId = this.socketId)) {
100
100
  data.event = event;
101
- data.always ?? (data.always = this.always);
101
+ data.always ??= this.always;
102
102
  const value = data.value;
103
103
  if (value && (util.types.isAnyArrayBuffer(value) || util.types.isArrayBufferView(value))) {
104
104
  try {
@@ -142,7 +142,7 @@ class FileGroup extends core_1.AbortComponent {
142
142
  return this[kStartTime];
143
143
  }
144
144
  get started() {
145
- return this[kStarted] || (this[kStarted] = Date.now() >= this.startTime);
145
+ return this[kStarted] ||= Date.now() >= this.startTime;
146
146
  }
147
147
  get assets() {
148
148
  return this[kAssets];
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 '@e-mc/types/lib';
2
+
3
+ declare const Watch: WatchConstructor<IFileManager>;
4
+
5
5
  export = Watch;
package/index.js CHANGED
@@ -5,10 +5,10 @@ const fs = require("fs");
5
5
  const https = require("https");
6
6
  const ws = require("ws");
7
7
  const pm = require("picomatch");
8
- const core_1 = require("@e-mc/core");
9
- const request_1 = require("@e-mc/request");
10
8
  const types_1 = require("@e-mc/types");
9
+ const core_1 = require("@e-mc/core");
11
10
  const util_1 = require("@e-mc/request/util");
11
+ const request_1 = require("@e-mc/request");
12
12
  const filegroup_1 = require("@e-mc/watch/filegroup");
13
13
  const kInterval = Symbol('interval');
14
14
  const kPort = Symbol('port');
@@ -225,7 +225,6 @@ class Watch extends core_1.Client {
225
225
  return super.init(config);
226
226
  }
227
227
  start(assets, permission) {
228
- var _l;
229
228
  if (this.aborted) {
230
229
  return;
231
230
  }
@@ -238,10 +237,10 @@ class Watch extends core_1.Client {
238
237
  if (!(0, types_1.ignoreFlag)(item.flags)) {
239
238
  const { bundleId, uri, localUri } = item;
240
239
  if (!(0, types_1.isEmpty)(bundleId)) {
241
- (destMap[_l = ':' + bundleId] || (destMap[_l] = [])).push(item);
240
+ (destMap[':' + bundleId] ||= []).push(item);
242
241
  }
243
242
  else if (uri && localUri) {
244
- (destMap[localUri] || (destMap[localUri] = [])).push(item);
243
+ (destMap[localUri] ||= []).push(item);
245
244
  }
246
245
  }
247
246
  }
@@ -336,12 +335,12 @@ class Watch extends core_1.Client {
336
335
  const key = this[kTlsKey];
337
336
  const cert = this[kTlsCert];
338
337
  if (key && cert) {
339
- wss = Watch.createServer(port || (port = this.securePort), { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], ciphers: this[kCiphers], config: this[kTlsConfig] });
338
+ wss = Watch.createServer(port ||= this.securePort, { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], ciphers: this[kCiphers], config: this[kTlsConfig] });
340
339
  }
341
340
  secure = true;
342
341
  }
343
342
  else {
344
- wss = Watch.createServer(port || (port = this.port));
343
+ wss = Watch.createServer(port ||= this.port);
345
344
  }
346
345
  if (!wss) {
347
346
  this.writeFail("Unable to create WebSocket server", (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
@@ -453,7 +452,7 @@ class Watch extends core_1.Client {
453
452
  if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
454
453
  return status;
455
454
  }
456
- const url = group.url || (group.url = new URL(uri));
455
+ const url = group.url ||= new URL(uri);
457
456
  const request = this.host?.Request || new request_1();
458
457
  const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
459
458
  const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
@@ -643,7 +642,7 @@ class Watch extends core_1.Client {
643
642
  if (status === 0) {
644
643
  this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
645
644
  }
646
- else if (message || (message = getErrorMessage(item, status))) {
645
+ else if (message ||= getErrorMessage(item, status)) {
647
646
  this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
648
647
  }
649
648
  }
@@ -754,7 +753,7 @@ class Watch extends core_1.Client {
754
753
  if (!(0, types_1.isPlainObject)(config)) {
755
754
  config = undefined;
756
755
  }
757
- else if (version || (version = config.minVersion)) {
756
+ else if (version ||= config.minVersion) {
758
757
  delete config.minVersion;
759
758
  delete config.secureProtocol;
760
759
  }
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@e-mc/watch",
3
- "version": "0.10.1",
4
- "description": "Watch constructor for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/watch"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/core": "0.10.1",
24
- "@e-mc/request": "0.10.1",
25
- "@e-mc/types": "0.10.1",
26
- "picomatch": "^4.0.2",
27
- "ws": "^8.18.0"
28
- }
29
- }
1
+ {
2
+ "name": "@e-mc/watch",
3
+ "version": "0.10.3",
4
+ "description": "Watch constructor for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/watch"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "BSD-3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/core": "0.10.3",
24
+ "@e-mc/request": "0.10.3",
25
+ "@e-mc/types": "0.10.3",
26
+ "picomatch": "^4.0.2",
27
+ "ws": "^8.18.0"
28
+ }
29
+ }