@iconify/tools 4.0.0-beta.4 → 4.0.0-beta.5
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/lib/download/api/config.cjs +4 -0
- package/lib/download/api/config.d.ts +12 -2
- package/lib/download/api/config.mjs +4 -1
- package/lib/download/api/download.cjs +3 -0
- package/lib/download/api/download.mjs +4 -1
- package/lib/download/api/index.cjs +9 -4
- package/lib/download/api/index.mjs +10 -5
- package/lib/download/api/queue.cjs +4 -2
- package/lib/download/api/queue.d.ts +3 -1
- package/lib/download/api/queue.mjs +4 -2
- package/lib/index.cjs +4 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { APIQueryParams } from './types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Axios config, customisable
|
|
5
6
|
*/
|
|
6
|
-
declare const axiosConfig: AxiosRequestConfig
|
|
7
|
+
declare const axiosConfig: Omit<AxiosRequestConfig, 'headers' | 'responseType' | 'url' | 'method' | 'data'>;
|
|
8
|
+
interface AxiosCallbacks {
|
|
9
|
+
onStart?: (url: string, params: APIQueryParams) => void;
|
|
10
|
+
onSuccess?: (url: string, params: APIQueryParams) => void;
|
|
11
|
+
onError?: (url: string, params: APIQueryParams, errorCode?: number) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Customisable callbacks, used for logging
|
|
15
|
+
*/
|
|
16
|
+
declare const fetchCallbacks: AxiosCallbacks;
|
|
7
17
|
|
|
8
|
-
export { axiosConfig };
|
|
18
|
+
export { axiosConfig, fetchCallbacks };
|
|
@@ -12,15 +12,18 @@ async function downloadFile(query, target) {
|
|
|
12
12
|
const params = query.params ? query.params.toString() : "";
|
|
13
13
|
const url = query.uri + (params ? "?" + params : "");
|
|
14
14
|
const headers = query.headers;
|
|
15
|
+
download_api_config.fetchCallbacks.onStart?.(url, query);
|
|
15
16
|
const response = await axios__default.get(url, {
|
|
16
17
|
...download_api_config.axiosConfig,
|
|
17
18
|
headers,
|
|
18
19
|
responseType: "arraybuffer"
|
|
19
20
|
});
|
|
20
21
|
if (response.status !== 200) {
|
|
22
|
+
download_api_config.fetchCallbacks.onError?.(url, query, response.status);
|
|
21
23
|
throw new Error(`Error downloading ${url}: ${response.status}`);
|
|
22
24
|
}
|
|
23
25
|
const data = response.data;
|
|
26
|
+
download_api_config.fetchCallbacks.onSuccess?.(url, query);
|
|
24
27
|
await promises.writeFile(target, Buffer.from(data));
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { writeFile } from 'fs/promises';
|
|
3
|
-
import { axiosConfig } from './config.mjs';
|
|
3
|
+
import { fetchCallbacks, axiosConfig } from './config.mjs';
|
|
4
4
|
|
|
5
5
|
async function downloadFile(query, target) {
|
|
6
6
|
const params = query.params ? query.params.toString() : "";
|
|
7
7
|
const url = query.uri + (params ? "?" + params : "");
|
|
8
8
|
const headers = query.headers;
|
|
9
|
+
fetchCallbacks.onStart?.(url, query);
|
|
9
10
|
const response = await axios.get(url, {
|
|
10
11
|
...axiosConfig,
|
|
11
12
|
headers,
|
|
12
13
|
responseType: "arraybuffer"
|
|
13
14
|
});
|
|
14
15
|
if (response.status !== 200) {
|
|
16
|
+
fetchCallbacks.onError?.(url, query, response.status);
|
|
15
17
|
throw new Error(`Error downloading ${url}: ${response.status}`);
|
|
16
18
|
}
|
|
17
19
|
const data = response.data;
|
|
20
|
+
fetchCallbacks.onSuccess?.(url, query);
|
|
18
21
|
await writeFile(target, Buffer.from(data));
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -32,8 +32,12 @@ async function sendAPIQuery(query, cache) {
|
|
|
32
32
|
async function sendQuery(query) {
|
|
33
33
|
const params = query.params ? query.params.toString() : "";
|
|
34
34
|
const url = query.uri + (params ? "?" + params : "");
|
|
35
|
-
console.log("Fetch:", url);
|
|
36
35
|
const headers = query.headers;
|
|
36
|
+
download_api_config.fetchCallbacks.onStart?.(url, query);
|
|
37
|
+
function fail(value) {
|
|
38
|
+
download_api_config.fetchCallbacks.onError?.(url, query, value);
|
|
39
|
+
return value ?? 404;
|
|
40
|
+
}
|
|
37
41
|
try {
|
|
38
42
|
const response = await axios__default.get(url, {
|
|
39
43
|
...download_api_config.axiosConfig,
|
|
@@ -41,14 +45,15 @@ async function sendQuery(query) {
|
|
|
41
45
|
responseType: "text"
|
|
42
46
|
});
|
|
43
47
|
if (response.status !== 200) {
|
|
44
|
-
return response.status;
|
|
48
|
+
return fail(response.status);
|
|
45
49
|
}
|
|
46
50
|
if (typeof response.data !== "string") {
|
|
47
|
-
return
|
|
51
|
+
return fail();
|
|
48
52
|
}
|
|
53
|
+
download_api_config.fetchCallbacks.onSuccess?.(url, query);
|
|
49
54
|
return response.data;
|
|
50
55
|
} catch (err) {
|
|
51
|
-
return
|
|
56
|
+
return fail();
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { apiCacheKey, getAPICache, storeAPICache } from './cache.mjs';
|
|
3
|
-
import { axiosConfig } from './config.mjs';
|
|
3
|
+
import { fetchCallbacks, axiosConfig } from './config.mjs';
|
|
4
4
|
import 'fs';
|
|
5
5
|
import 'crypto';
|
|
6
6
|
import '../../misc/scan.mjs';
|
|
@@ -26,8 +26,12 @@ async function sendAPIQuery(query, cache) {
|
|
|
26
26
|
async function sendQuery(query) {
|
|
27
27
|
const params = query.params ? query.params.toString() : "";
|
|
28
28
|
const url = query.uri + (params ? "?" + params : "");
|
|
29
|
-
console.log("Fetch:", url);
|
|
30
29
|
const headers = query.headers;
|
|
30
|
+
fetchCallbacks.onStart?.(url, query);
|
|
31
|
+
function fail(value) {
|
|
32
|
+
fetchCallbacks.onError?.(url, query, value);
|
|
33
|
+
return value ?? 404;
|
|
34
|
+
}
|
|
31
35
|
try {
|
|
32
36
|
const response = await axios.get(url, {
|
|
33
37
|
...axiosConfig,
|
|
@@ -35,14 +39,15 @@ async function sendQuery(query) {
|
|
|
35
39
|
responseType: "text"
|
|
36
40
|
});
|
|
37
41
|
if (response.status !== 200) {
|
|
38
|
-
return response.status;
|
|
42
|
+
return fail(response.status);
|
|
39
43
|
}
|
|
40
44
|
if (typeof response.data !== "string") {
|
|
41
|
-
return
|
|
45
|
+
return fail();
|
|
42
46
|
}
|
|
47
|
+
fetchCallbacks.onSuccess?.(url, query);
|
|
43
48
|
return response.data;
|
|
44
49
|
} catch (err) {
|
|
45
|
-
return
|
|
50
|
+
return fail();
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -44,10 +44,10 @@ function runConcurrentQueries(params) {
|
|
|
44
44
|
resolvedItem();
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
if (allParams.
|
|
47
|
+
if (allParams.onError) {
|
|
48
48
|
let retry;
|
|
49
49
|
try {
|
|
50
|
-
retry = allParams.
|
|
50
|
+
retry = allParams.onError(index, err, params);
|
|
51
51
|
} catch (err2) {
|
|
52
52
|
err = err2;
|
|
53
53
|
done(true);
|
|
@@ -70,9 +70,11 @@ function runConcurrentQueries(params) {
|
|
|
70
70
|
function run(index, retry) {
|
|
71
71
|
resolving.add(index);
|
|
72
72
|
const p = isCallback ? paramsWithCount.callback(index) : paramsWithPromises.promises[index];
|
|
73
|
+
allParams.onStart?.(index, params);
|
|
73
74
|
p.then((value) => {
|
|
74
75
|
resolving.delete(index);
|
|
75
76
|
results[index] = value;
|
|
77
|
+
allParams.onSuccess?.(index, params, value);
|
|
76
78
|
resolvedItem();
|
|
77
79
|
}).catch((err) => {
|
|
78
80
|
if (retry < retries) {
|
|
@@ -12,7 +12,9 @@ type GetConcurrentQueryCallback<T> = (index: number) => Promise<T>;
|
|
|
12
12
|
interface ConcurrentQueriesCommonParams<T> {
|
|
13
13
|
limit?: number;
|
|
14
14
|
retries?: number;
|
|
15
|
-
|
|
15
|
+
onError?: (index: number, error: unknown, params: ConcurrentQueriesParams<T>) => void | Promise<void>;
|
|
16
|
+
onSuccess?: (index: number, params: ConcurrentQueriesParams<T>, result: T) => void;
|
|
17
|
+
onStart?: (index: number, params: ConcurrentQueriesParams<T>) => void;
|
|
16
18
|
}
|
|
17
19
|
interface ConcurrentQueriesParamsWithCount<T> extends ConcurrentQueriesCommonParams<T> {
|
|
18
20
|
total: number;
|
|
@@ -42,10 +42,10 @@ function runConcurrentQueries(params) {
|
|
|
42
42
|
resolvedItem();
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (allParams.
|
|
45
|
+
if (allParams.onError) {
|
|
46
46
|
let retry;
|
|
47
47
|
try {
|
|
48
|
-
retry = allParams.
|
|
48
|
+
retry = allParams.onError(index, err, params);
|
|
49
49
|
} catch (err2) {
|
|
50
50
|
err = err2;
|
|
51
51
|
done(true);
|
|
@@ -68,9 +68,11 @@ function runConcurrentQueries(params) {
|
|
|
68
68
|
function run(index, retry) {
|
|
69
69
|
resolving.add(index);
|
|
70
70
|
const p = isCallback ? paramsWithCount.callback(index) : paramsWithPromises.promises[index];
|
|
71
|
+
allParams.onStart?.(index, params);
|
|
71
72
|
p.then((value) => {
|
|
72
73
|
resolving.delete(index);
|
|
73
74
|
results[index] = value;
|
|
75
|
+
allParams.onSuccess?.(index, params, value);
|
|
74
76
|
resolvedItem();
|
|
75
77
|
}).catch((err) => {
|
|
76
78
|
if (retry < retries) {
|
package/lib/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ const misc_keyword = require('./misc/keyword.cjs');
|
|
|
51
51
|
const misc_bumpVersion = require('./misc/bump-version.cjs');
|
|
52
52
|
const download_api_config = require('./download/api/config.cjs');
|
|
53
53
|
const download_api_index = require('./download/api/index.cjs');
|
|
54
|
+
const download_api_queue = require('./download/api/queue.cjs');
|
|
54
55
|
require('cheerio');
|
|
55
56
|
require('@iconify/utils');
|
|
56
57
|
require('./css/parse.cjs');
|
|
@@ -80,7 +81,6 @@ require('./import/figma/query.cjs');
|
|
|
80
81
|
require('./download/api/cache.cjs');
|
|
81
82
|
require('fs');
|
|
82
83
|
require('crypto');
|
|
83
|
-
require('./download/api/queue.cjs');
|
|
84
84
|
require('axios');
|
|
85
85
|
require('pathe');
|
|
86
86
|
require('child_process');
|
|
@@ -147,4 +147,7 @@ exports.execAsync = misc_exec.execAsync;
|
|
|
147
147
|
exports.cleanupIconKeyword = misc_keyword.cleanupIconKeyword;
|
|
148
148
|
exports.bumpVersion = misc_bumpVersion.bumpVersion;
|
|
149
149
|
exports.axiosConfig = download_api_config.axiosConfig;
|
|
150
|
+
exports.fetchCallbacks = download_api_config.fetchCallbacks;
|
|
150
151
|
exports.sendAPIQuery = download_api_index.sendAPIQuery;
|
|
152
|
+
exports.defaultQueueParams = download_api_queue.defaultQueueParams;
|
|
153
|
+
exports.runConcurrentQueries = download_api_queue.runConcurrentQueries;
|
package/lib/index.d.ts
CHANGED
|
@@ -47,8 +47,9 @@ export { untar } from './download/helpers/untar.js';
|
|
|
47
47
|
export { execAsync } from './misc/exec.js';
|
|
48
48
|
export { cleanupIconKeyword } from './misc/keyword.js';
|
|
49
49
|
export { bumpVersion } from './misc/bump-version.js';
|
|
50
|
-
export { axiosConfig } from './download/api/config.js';
|
|
50
|
+
export { axiosConfig, fetchCallbacks } from './download/api/config.js';
|
|
51
51
|
export { sendAPIQuery } from './download/api/index.js';
|
|
52
|
+
export { defaultQueueParams, runConcurrentQueries } from './download/api/queue.js';
|
|
52
53
|
import 'cheerio';
|
|
53
54
|
import '@iconify/types';
|
|
54
55
|
import '@iconify/utils/lib/customisations/defaults';
|
package/lib/index.mjs
CHANGED
|
@@ -47,8 +47,9 @@ export { untar } from './download/helpers/untar.mjs';
|
|
|
47
47
|
export { execAsync } from './misc/exec.mjs';
|
|
48
48
|
export { cleanupIconKeyword } from './misc/keyword.mjs';
|
|
49
49
|
export { bumpVersion } from './misc/bump-version.mjs';
|
|
50
|
-
export { axiosConfig } from './download/api/config.mjs';
|
|
50
|
+
export { axiosConfig, fetchCallbacks } from './download/api/config.mjs';
|
|
51
51
|
export { sendAPIQuery } from './download/api/index.mjs';
|
|
52
|
+
export { defaultQueueParams, runConcurrentQueries } from './download/api/queue.mjs';
|
|
52
53
|
import 'cheerio';
|
|
53
54
|
import '@iconify/utils';
|
|
54
55
|
import './css/parse.mjs';
|
|
@@ -78,7 +79,6 @@ import './import/figma/query.mjs';
|
|
|
78
79
|
import './download/api/cache.mjs';
|
|
79
80
|
import 'fs';
|
|
80
81
|
import 'crypto';
|
|
81
|
-
import './download/api/queue.mjs';
|
|
82
82
|
import 'axios';
|
|
83
83
|
import 'pathe';
|
|
84
84
|
import 'child_process';
|
package/package.json
CHANGED