@e-mc/watch 0.9.8 → 0.9.10

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,118 +1,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.9.8/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
- version?: SecureVersion;
77
- };
78
- settings?: {
79
- broadcast_id?: string | string[];
80
- users?: Record<string, Record<string, unknown>>;
81
- };
82
- permission?: PermittedDirectories;
83
- }
84
- ```
85
-
86
- ### Example usage
87
-
88
- ```javascript
89
- const Watch = require("@e-mc/watch");
90
-
91
- const instance = new Watch({ interval: 100, port: 8080 });
92
- instance.init();
93
-
94
- instance.whenModified = (assets) => {
95
- assets.forEach(item => console.log(item.uri));
96
- };
97
-
98
- const assets = [
99
- { localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
100
- { localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
101
- ];
102
-
103
- instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
104
- ```
105
-
106
- ## References
107
-
108
- - https://www.unpkg.com/@e-mc/types@0.9.8/lib/asset.d.ts
109
- - https://www.unpkg.com/@e-mc/types@0.9.8/lib/core.d.ts
110
- - https://www.unpkg.com/@e-mc/types@0.9.8/lib/filemanager.d.ts
111
- - https://www.unpkg.com/@e-mc/types@0.9.8/lib/settings.d.ts
112
- - https://www.unpkg.com/@e-mc/types@0.9.8/lib/watch.d.ts
113
-
114
- * https://www.npmjs.com/package/@types/ws
115
-
116
- ## LICENSE
117
-
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.9.10/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
+ version?: SecureVersion;
77
+ };
78
+ settings?: {
79
+ broadcast_id?: string | string[];
80
+ users?: Record<string, Record<string, unknown>>;
81
+ };
82
+ permission?: PermittedDirectories;
83
+ }
84
+ ```
85
+
86
+ ### Example usage
87
+
88
+ ```javascript
89
+ const Watch = require("@e-mc/watch");
90
+
91
+ const instance = new Watch({ interval: 100, port: 8080 });
92
+ instance.init();
93
+
94
+ instance.whenModified = (assets) => {
95
+ assets.forEach(item => console.log(item.uri));
96
+ };
97
+
98
+ const assets = [
99
+ { localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
100
+ { localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
101
+ ];
102
+
103
+ instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
104
+ ```
105
+
106
+ ## References
107
+
108
+ - https://www.unpkg.com/@e-mc/types@0.9.10/lib/asset.d.ts
109
+ - https://www.unpkg.com/@e-mc/types@0.9.10/lib/core.d.ts
110
+ - https://www.unpkg.com/@e-mc/types@0.9.10/lib/filemanager.d.ts
111
+ - https://www.unpkg.com/@e-mc/types@0.9.10/lib/settings.d.ts
112
+ - https://www.unpkg.com/@e-mc/types@0.9.10/lib/watch.d.ts
113
+
114
+ * https://www.npmjs.com/package/@types/ws
115
+
116
+ ## LICENSE
117
+
118
118
  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 '../../types/lib/watch';
2
+
3
+ declare const FileGroup: FileGroupConstructor;
4
+
5
5
  export = FileGroup;
@@ -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.js CHANGED
@@ -184,7 +184,6 @@ class Watch extends core_1.Client {
184
184
  return super.init(config);
185
185
  }
186
186
  start(assets, permission) {
187
- var _k;
188
187
  if (this.aborted) {
189
188
  return;
190
189
  }
@@ -197,10 +196,10 @@ class Watch extends core_1.Client {
197
196
  if (!(0, types_1.ignoreFlag)(item.flags)) {
198
197
  const { bundleId, uri, localUri } = item;
199
198
  if (!(0, types_1.isEmpty)(bundleId)) {
200
- (destMap[_k = ':' + bundleId] || (destMap[_k] = [])).push(item);
199
+ (destMap[':' + bundleId] ||= []).push(item);
201
200
  }
202
201
  else if (uri && localUri) {
203
- (destMap[localUri] || (destMap[localUri] = [])).push(item);
202
+ (destMap[localUri] ||= []).push(item);
204
203
  }
205
204
  }
206
205
  }
@@ -310,12 +309,12 @@ class Watch extends core_1.Client {
310
309
  const key = this[kTlsKey];
311
310
  const cert = this[kTlsCert];
312
311
  if (key && cert) {
313
- wss = Watch.createServer(port || (port = this.securePort), { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], config: this[kTlsConfig] });
312
+ wss = Watch.createServer(port ||= this.securePort, { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], config: this[kTlsConfig] });
314
313
  }
315
314
  secure = true;
316
315
  }
317
316
  else {
318
- wss = Watch.createServer(port || (port = this.port));
317
+ wss = Watch.createServer(port ||= this.port);
319
318
  }
320
319
  if (!wss) {
321
320
  this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
@@ -429,7 +428,7 @@ class Watch extends core_1.Client {
429
428
  if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
430
429
  return status;
431
430
  }
432
- const url = group.url || (group.url = new URL(uri));
431
+ const url = group.url ||= new URL(uri);
433
432
  const request = this.host?.Request || new request_1();
434
433
  const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
435
434
  const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
@@ -738,7 +737,7 @@ class Watch extends core_1.Client {
738
737
  if (!(0, types_1.isPlainObject)(config)) {
739
738
  config = undefined;
740
739
  }
741
- else if (version || (version = config.minVersion)) {
740
+ else if (version ||= config.minVersion) {
742
741
  delete config.minVersion;
743
742
  delete config.secureProtocol;
744
743
  }
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@e-mc/watch",
3
- "version": "0.9.8",
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.9.8",
24
- "@e-mc/request": "0.9.8",
25
- "@e-mc/types": "0.9.8",
26
- "picomatch": "^4.0.2",
27
- "ws": "^8.18.0"
28
- }
29
- }
1
+ {
2
+ "name": "@e-mc/watch",
3
+ "version": "0.9.10",
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.9.10",
24
+ "@e-mc/request": "0.9.10",
25
+ "@e-mc/types": "0.9.10",
26
+ "picomatch": "^4.0.2",
27
+ "ws": "^8.18.0"
28
+ }
29
+ }