electron-incremental-update 2.2.2 → 2.2.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.
@@ -1,10 +1,12 @@
1
- import { I as IProvider, U as UpdateJSONWithURL, a as UpdateInfoWithURL, D as DownloadingInfo, O as OnDownloading, b as URLHandler } from './types-CStrrQPl.js';
2
- import { c as defaultVerifySignature, f as defaultUnzipFile } from './zip-DQdr8pFv.js';
3
- import { d as defaultIsLowerVersion, a as UpdateJSON } from './version-Bl_0oO5f.js';
4
- import { Arrayable } from '@subframe7536/type-utils';
1
+ import { c as defaultVerifySignature, l as defaultUnzipFile } from './zip-DbfskMQi.js';
2
+ export { j as defaultDownloadAsar, f as defaultDownloadJSON, i as defaultDownloadUpdateJSON, e as downloadUtil, g as getHeader } from './zip-DbfskMQi.js';
3
+ import { e as UpdateInfoWithURL, I as IProvider, d as defaultIsLowerVersion, D as DownloadingInfo, f as URLHandler } from './types-C5M2xRjF.js';
4
+ export { b as UpdateJSONWithURL } from './types-C5M2xRjF.js';
5
+ import '@subframe7536/type-utils';
6
+ import 'electron';
5
7
  import 'node:url';
6
8
 
7
- declare abstract class BaseProvider implements IProvider {
9
+ declare abstract class BaseProvider<T extends UpdateInfoWithURL = UpdateInfoWithURL> implements IProvider<T> {
8
10
  name: string;
9
11
  /**
10
12
  * @inheritdoc
@@ -21,45 +23,13 @@ declare abstract class BaseProvider implements IProvider {
21
23
  /**
22
24
  * @inheritdoc
23
25
  */
24
- abstract downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<UpdateJSONWithURL>;
26
+ abstract downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<T>;
25
27
  /**
26
28
  * @inheritdoc
27
29
  */
28
30
  abstract downloadAsar(info: UpdateInfoWithURL, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
29
31
  }
30
32
 
31
- /**
32
- * Safe get value from header
33
- * @param headers response header
34
- * @param key target header key
35
- */
36
- declare function getHeader(headers: Record<string, Arrayable<string>>, key: any): any;
37
- type ResolveDataFn = (data: string, resolve: (data: any) => void, reject: (e: any) => void) => void;
38
- /**
39
- * Default function to download json and parse to UpdateJson
40
- * @param url target url
41
- * @param headers extra headers
42
- * @param signal abort signal
43
- * @param resolveData on resolve
44
- */
45
- declare function defaultDownloadJSON<T>(url: string, headers: Record<string, any>, signal: AbortSignal, resolveData?: ResolveDataFn): Promise<T>;
46
- /**
47
- * Default function to download json and parse to UpdateJson
48
- * @param url target url
49
- * @param headers extra headers
50
- * @param signal abort signal
51
- */
52
- declare function defaultDownloadUpdateJSON(url: string, headers: Record<string, any>, signal: AbortSignal): Promise<UpdateJSON>;
53
- /**
54
- * Default function to download asar buffer,
55
- * get total size from `Content-Length` header
56
- * @param url target url
57
- * @param headers extra headers
58
- * @param signal abort signal
59
- * @param onDownloading on downloading callback
60
- */
61
- declare function defaultDownloadAsar(url: string, headers: Record<string, any>, signal: AbortSignal, onDownloading?: OnDownloading): Promise<Buffer>;
62
-
63
33
  interface GitHubProviderOptions {
64
34
  /**
65
35
  * Github user name
@@ -89,7 +59,7 @@ interface GitHubProviderOptions {
89
59
  */
90
60
  urlHandler?: URLHandler;
91
61
  }
92
- declare class GitHubProvider extends BaseProvider {
62
+ declare class GitHubProvider<T extends UpdateInfoWithURL = UpdateInfoWithURL> extends BaseProvider<T> {
93
63
  name: string;
94
64
  private options;
95
65
  /**
@@ -108,7 +78,7 @@ declare class GitHubProvider extends BaseProvider {
108
78
  /**
109
79
  * @inheritdoc
110
80
  */
111
- downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<UpdateJSONWithURL>;
81
+ downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<T>;
112
82
  /**
113
83
  * @inheritdoc
114
84
  */
@@ -137,7 +107,7 @@ interface GitHubApiProviderOptions {
137
107
  */
138
108
  urlHandler?: URLHandler;
139
109
  }
140
- declare class GitHubApiProvider extends BaseProvider {
110
+ declare class GitHubApiProvider<T extends UpdateInfoWithURL = UpdateInfoWithURL> extends BaseProvider<T> {
141
111
  name: string;
142
112
  private options;
143
113
  /**
@@ -157,11 +127,11 @@ declare class GitHubApiProvider extends BaseProvider {
157
127
  /**
158
128
  * @inheritdoc
159
129
  */
160
- downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<UpdateJSONWithURL>;
130
+ downloadJSON(name: string, versionPath: string, signal: AbortSignal): Promise<T>;
161
131
  /**
162
132
  * @inheritdoc
163
133
  */
164
134
  downloadAsar(info: UpdateInfoWithURL, signal: AbortSignal, onDownloading?: (info: DownloadingInfo) => void): Promise<Buffer>;
165
135
  }
166
136
 
167
- export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, OnDownloading, URLHandler, UpdateInfoWithURL, UpdateJSONWithURL, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
137
+ export { BaseProvider, DownloadingInfo, GitHubApiProvider, type GitHubApiProviderOptions, GitHubProvider, type GitHubProviderOptions, IProvider, URLHandler, UpdateInfoWithURL };
package/dist/provider.js CHANGED
@@ -1,6 +1,6 @@
1
- import { defaultVerifySignature, defaultUnzipFile } from './chunk-XGWQQVIZ.js';
2
- import { defaultIsLowerVersion, isUpdateJSON } from './chunk-AAAM44NW.js';
3
- import electron from 'electron';
1
+ import { defaultVerifySignature, defaultUnzipFile, defaultDownloadUpdateJSON, defaultDownloadAsar, defaultDownloadJSON } from './chunk-D7NXTCQW.js';
2
+ export { defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, downloadUtil, getHeader } from './chunk-D7NXTCQW.js';
3
+ import { defaultIsLowerVersion } from './chunk-AAAM44NW.js';
4
4
  import { URL } from 'node:url';
5
5
 
6
6
  // src/provider/base.ts
@@ -19,97 +19,6 @@ var BaseProvider = class {
19
19
  */
20
20
  unzipFile = defaultUnzipFile;
21
21
  };
22
- function getHeader(headers, key) {
23
- const value = headers[key];
24
- if (Array.isArray(value)) {
25
- return value.length === 0 ? null : value[value.length - 1];
26
- } else {
27
- return value;
28
- }
29
- }
30
- async function downloadFn(url, headers, signal, onResponse) {
31
- await electron.app.whenReady();
32
- return new Promise((resolve, reject) => {
33
- const request = electron.net.request({ url, method: "GET", redirect: "follow", headers, cache: "no-cache" });
34
- signal.addEventListener("abort", () => request.abort(), { once: true });
35
- request.on("response", (resp) => {
36
- resp.on("aborted", () => reject(new Error("aborted")));
37
- resp.on("error", () => reject(new Error("download error")));
38
- onResponse(resp, resolve, reject);
39
- });
40
- request.on("error", reject);
41
- request.end();
42
- });
43
- }
44
- function trimData(data) {
45
- return data.trim().slice(0, 5e3).replace(/\s+/g, " ");
46
- }
47
- var defaultResolveDataFn = (data, resolve, reject) => {
48
- try {
49
- resolve(JSON.parse(data));
50
- } catch {
51
- reject(new Error(`Invalid json, "${trimData(data)}"`));
52
- }
53
- };
54
- async function defaultDownloadJSON(url, headers, signal, resolveData = defaultResolveDataFn) {
55
- return await downloadFn(
56
- url,
57
- headers,
58
- signal,
59
- (resp, resolve, reject) => {
60
- let data = "";
61
- resp.on("data", (chunk) => data += chunk);
62
- resp.on("end", () => resolveData(data, resolve, reject));
63
- }
64
- );
65
- }
66
- async function defaultDownloadUpdateJSON(url, headers, signal) {
67
- return await defaultDownloadJSON(
68
- url,
69
- headers,
70
- signal,
71
- (data, resolve, reject) => {
72
- try {
73
- const json = JSON.parse(data);
74
- if (isUpdateJSON(json)) {
75
- resolve(json);
76
- } else {
77
- throw Error;
78
- }
79
- } catch {
80
- reject(new Error(`Invalid update json, "${trimData(data)}"`));
81
- }
82
- }
83
- );
84
- }
85
- async function defaultDownloadAsar(url, headers, signal, onDownloading) {
86
- let transferred = 0;
87
- let time = Date.now();
88
- return await downloadFn(
89
- url,
90
- headers,
91
- signal,
92
- (resp, resolve) => {
93
- const total = +getHeader(resp.headers, "content-length") || -1;
94
- const data = [];
95
- resp.on("data", (chunk) => {
96
- const delta = chunk.length;
97
- transferred += delta;
98
- const current = Date.now();
99
- onDownloading?.({
100
- percent: total > 0 ? +(transferred / total).toFixed(2) * 100 : -1,
101
- total,
102
- transferred,
103
- delta,
104
- bps: delta / (current - time)
105
- });
106
- time = current;
107
- data.push(chunk);
108
- });
109
- resp.on("end", () => resolve(Buffer.concat(data)));
110
- }
111
- );
112
- }
113
22
  var GitHubProvider = class extends BaseProvider {
114
23
  name = "GithubProvider";
115
24
  options;
@@ -266,4 +175,4 @@ var GitHubApiProvider = class extends BaseProvider {
266
175
  }
267
176
  };
268
177
 
269
- export { BaseProvider, GitHubApiProvider, GitHubProvider, defaultDownloadAsar, defaultDownloadJSON, defaultDownloadUpdateJSON, getHeader };
178
+ export { BaseProvider, GitHubApiProvider, GitHubProvider };
@@ -1,11 +1,82 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
  import { URL } from 'node:url';
3
- import { U as UpdateInfo } from './version-Bl_0oO5f.js';
3
+
4
+ interface Version {
5
+ /**
6
+ * `4` of `4.3.2-beta.1`
7
+ */
8
+ major: number;
9
+ /**
10
+ * `3` of `4.3.2-beta.1`
11
+ */
12
+ minor: number;
13
+ /**
14
+ * `2` of `4.3.2-beta.1`
15
+ */
16
+ patch: number;
17
+ /**
18
+ * `beta` of `4.3.2-beta.1`
19
+ */
20
+ stage: string;
21
+ /**
22
+ * `1` of `4.3.2-beta.1`
23
+ */
24
+ stageVersion: number;
25
+ }
26
+ /**
27
+ * Parse version string to {@link Version}, like `0.2.0-beta.1`
28
+ * @param version version string
29
+ */
30
+ declare function parseVersion(version: string): Version;
31
+ /**
32
+ * Default function to check the old version is less than new version
33
+ * @param oldVer old version string
34
+ * @param newVer new version string
35
+ */
36
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
37
+ /**
38
+ * Update info json
39
+ */
40
+ type UpdateInfo = {
41
+ /**
42
+ * Update Asar signature
43
+ */
44
+ signature: string;
45
+ /**
46
+ * Minimum version
47
+ */
48
+ minimumVersion: string;
49
+ /**
50
+ * Target version
51
+ */
52
+ version: string;
53
+ };
54
+ /**
55
+ * {@link UpdateInfo} with beta
56
+ */
57
+ type UpdateJSON = UpdateInfo & {
58
+ /**
59
+ * Beta update info
60
+ */
61
+ beta: UpdateInfo;
62
+ };
63
+ /**
64
+ * Check is `UpdateJSON`
65
+ * @param json any variable
66
+ */
67
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
68
+ /**
69
+ * Default function to generate `UpdateJSON`
70
+ * @param existingJson exising update json
71
+ * @param signature sigature
72
+ * @param version target version
73
+ * @param minimumVersion minimum version
74
+ */
75
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
4
76
 
5
77
  type UpdateInfoWithURL = UpdateInfo & {
6
78
  url: string;
7
79
  };
8
- type OnDownloading = (progress: DownloadingInfo) => void;
9
80
  interface DownloadingInfo {
10
81
  /**
11
82
  * Download buffer delta
@@ -77,4 +148,4 @@ interface IProvider<T extends UpdateInfoWithURL = UpdateInfoWithURL> {
77
148
  }
78
149
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
79
150
 
80
- export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, UpdateJSONWithURL as U, UpdateInfoWithURL as a, URLHandler as b };
151
+ export { type DownloadingInfo as D, type IProvider as I, type UpdateInfo as U, type Version as V, type UpdateJSON as a, type UpdateJSONWithURL as b, defaultVersionJsonGenerator as c, defaultIsLowerVersion as d, type UpdateInfoWithURL as e, type URLHandler as f, isUpdateJSON as i, parseVersion as p };
@@ -1,11 +1,82 @@
1
1
  import { Promisable } from '@subframe7536/type-utils';
2
2
  import { URL } from 'node:url';
3
- import { U as UpdateInfo } from './version-Bl_0oO5f.cjs';
3
+
4
+ interface Version {
5
+ /**
6
+ * `4` of `4.3.2-beta.1`
7
+ */
8
+ major: number;
9
+ /**
10
+ * `3` of `4.3.2-beta.1`
11
+ */
12
+ minor: number;
13
+ /**
14
+ * `2` of `4.3.2-beta.1`
15
+ */
16
+ patch: number;
17
+ /**
18
+ * `beta` of `4.3.2-beta.1`
19
+ */
20
+ stage: string;
21
+ /**
22
+ * `1` of `4.3.2-beta.1`
23
+ */
24
+ stageVersion: number;
25
+ }
26
+ /**
27
+ * Parse version string to {@link Version}, like `0.2.0-beta.1`
28
+ * @param version version string
29
+ */
30
+ declare function parseVersion(version: string): Version;
31
+ /**
32
+ * Default function to check the old version is less than new version
33
+ * @param oldVer old version string
34
+ * @param newVer new version string
35
+ */
36
+ declare function defaultIsLowerVersion(oldVer: string, newVer: string): boolean;
37
+ /**
38
+ * Update info json
39
+ */
40
+ type UpdateInfo = {
41
+ /**
42
+ * Update Asar signature
43
+ */
44
+ signature: string;
45
+ /**
46
+ * Minimum version
47
+ */
48
+ minimumVersion: string;
49
+ /**
50
+ * Target version
51
+ */
52
+ version: string;
53
+ };
54
+ /**
55
+ * {@link UpdateInfo} with beta
56
+ */
57
+ type UpdateJSON = UpdateInfo & {
58
+ /**
59
+ * Beta update info
60
+ */
61
+ beta: UpdateInfo;
62
+ };
63
+ /**
64
+ * Check is `UpdateJSON`
65
+ * @param json any variable
66
+ */
67
+ declare function isUpdateJSON(json: any): json is UpdateJSON;
68
+ /**
69
+ * Default function to generate `UpdateJSON`
70
+ * @param existingJson exising update json
71
+ * @param signature sigature
72
+ * @param version target version
73
+ * @param minimumVersion minimum version
74
+ */
75
+ declare function defaultVersionJsonGenerator(existingJson: UpdateJSON, signature: string, version: string, minimumVersion: string): UpdateJSON;
4
76
 
5
77
  type UpdateInfoWithURL = UpdateInfo & {
6
78
  url: string;
7
79
  };
8
- type OnDownloading = (progress: DownloadingInfo) => void;
9
80
  interface DownloadingInfo {
10
81
  /**
11
82
  * Download buffer delta
@@ -77,4 +148,4 @@ interface IProvider<T extends UpdateInfoWithURL = UpdateInfoWithURL> {
77
148
  }
78
149
  type URLHandler = (url: URL) => Promisable<URL | string | undefined | null>;
79
150
 
80
- export type { DownloadingInfo as D, IProvider as I, OnDownloading as O, UpdateJSONWithURL as U, UpdateInfoWithURL as a, URLHandler as b };
151
+ export { type DownloadingInfo as D, type IProvider as I, type UpdateInfo as U, type Version as V, type UpdateJSON as a, type UpdateJSONWithURL as b, defaultVersionJsonGenerator as c, defaultIsLowerVersion as d, type UpdateInfoWithURL as e, type URLHandler as f, isUpdateJSON as i, parseVersion as p };