styled-map-package 2.2.1 → 3.0.0
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/bin/smp-download.js +3 -3
- package/bin/smp-mbtiles.js +1 -1
- package/bin/smp-view.js +2 -2
- package/dist/download.cjs +101 -0
- package/dist/download.d.cts +65 -0
- package/dist/{lib/download.d.ts → download.d.ts} +22 -6
- package/dist/download.js +77 -0
- package/dist/from-mbtiles.cjs +91 -0
- package/dist/from-mbtiles.d.cts +17 -0
- package/dist/from-mbtiles.d.ts +17 -0
- package/dist/from-mbtiles.js +57 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +18 -0
- package/dist/reader-watch.cjs +135 -0
- package/dist/reader-watch.d.cts +24 -0
- package/dist/reader-watch.d.ts +24 -0
- package/dist/reader-watch.js +101 -0
- package/dist/reader.cjs +167 -0
- package/dist/reader.d.cts +62 -0
- package/dist/{lib/reader.d.ts → reader.d.ts} +16 -5
- package/dist/reader.js +138 -0
- package/dist/reporters.cjs +122 -0
- package/dist/reporters.d.cts +10 -0
- package/dist/{lib/reporters.d.ts → reporters.d.ts} +5 -2
- package/dist/reporters.js +88 -0
- package/dist/server.cjs +79 -0
- package/dist/server.d.cts +37 -0
- package/dist/server.d.ts +37 -0
- package/dist/server.js +45 -0
- package/dist/style-downloader.cjs +312 -0
- package/dist/style-downloader.d.cts +120 -0
- package/dist/{lib/style-downloader.d.ts → style-downloader.d.ts} +23 -13
- package/dist/style-downloader.js +288 -0
- package/dist/tile-downloader.cjs +158 -0
- package/dist/tile-downloader.d.cts +84 -0
- package/dist/{lib/tile-downloader.d.ts → tile-downloader.d.ts} +22 -10
- package/dist/tile-downloader.js +126 -0
- package/dist/{lib/writer.d.ts → types-B4Xn1F9K.d.cts} +74 -14
- package/dist/types-B4Xn1F9K.d.ts +189 -0
- package/dist/utils/errors.cjs +41 -0
- package/dist/utils/errors.d.cts +18 -0
- package/dist/{lib/utils → utils}/errors.d.ts +4 -2
- package/dist/utils/errors.js +16 -0
- package/dist/utils/fetch.cjs +96 -0
- package/dist/utils/fetch.d.cts +51 -0
- package/dist/{lib/utils → utils}/fetch.d.ts +10 -4
- package/dist/utils/fetch.js +62 -0
- package/dist/utils/file-formats.cjs +98 -0
- package/dist/utils/file-formats.d.cts +35 -0
- package/dist/{lib/utils → utils}/file-formats.d.ts +13 -3
- package/dist/utils/file-formats.js +62 -0
- package/dist/utils/geo.cjs +84 -0
- package/dist/utils/geo.d.cts +46 -0
- package/dist/{lib/utils → utils}/geo.d.ts +8 -6
- package/dist/utils/geo.js +56 -0
- package/dist/utils/mapbox.cjs +121 -0
- package/dist/utils/mapbox.d.cts +43 -0
- package/dist/utils/mapbox.d.ts +43 -0
- package/dist/utils/mapbox.js +91 -0
- package/dist/utils/misc.cjs +39 -0
- package/{lib/utils/misc.js → dist/utils/misc.d.cts} +5 -9
- package/dist/{lib/utils → utils}/misc.d.ts +5 -3
- package/dist/utils/misc.js +13 -0
- package/dist/utils/streams.cjs +130 -0
- package/dist/utils/streams.d.cts +73 -0
- package/dist/{lib/utils → utils}/streams.d.ts +14 -10
- package/dist/utils/streams.js +103 -0
- package/dist/utils/style.cjs +126 -0
- package/dist/utils/style.d.cts +69 -0
- package/dist/{lib/utils → utils}/style.d.ts +19 -9
- package/dist/utils/style.js +98 -0
- package/dist/utils/templates.cjs +114 -0
- package/dist/utils/templates.d.cts +78 -0
- package/dist/{lib/utils → utils}/templates.d.ts +24 -14
- package/dist/utils/templates.js +79 -0
- package/dist/writer.cjs +401 -0
- package/dist/writer.d.cts +7 -0
- package/dist/writer.d.ts +7 -0
- package/dist/writer.js +374 -0
- package/package.json +87 -33
- package/dist/lib/from-mbtiles.d.ts +0 -13
- package/dist/lib/index.d.ts +0 -10
- package/dist/lib/reader-watch.d.ts +0 -13
- package/dist/lib/server.d.ts +0 -15
- package/dist/lib/types.d.ts +0 -64
- package/dist/lib/utils/mapbox.d.ts +0 -41
- package/lib/download.js +0 -114
- package/lib/from-mbtiles.js +0 -83
- package/lib/index.js +0 -11
- package/lib/reader-watch.js +0 -133
- package/lib/reader.js +0 -165
- package/lib/reporters.js +0 -92
- package/lib/server.js +0 -81
- package/lib/style-downloader.js +0 -363
- package/lib/tile-downloader.js +0 -188
- package/lib/types.ts +0 -104
- package/lib/utils/errors.js +0 -24
- package/lib/utils/fetch.js +0 -100
- package/lib/utils/file-formats.js +0 -85
- package/lib/utils/geo.js +0 -87
- package/lib/utils/mapbox.js +0 -155
- package/lib/utils/streams.js +0 -165
- package/lib/utils/style.js +0 -174
- package/lib/utils/templates.js +0 -136
- package/lib/writer.js +0 -478
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var mapbox_exports = {};
|
|
20
|
+
__export(mapbox_exports, {
|
|
21
|
+
API_URL: () => API_URL,
|
|
22
|
+
isMapboxURL: () => isMapboxURL,
|
|
23
|
+
normalizeGlyphsURL: () => normalizeGlyphsURL,
|
|
24
|
+
normalizeSourceURL: () => normalizeSourceURL,
|
|
25
|
+
normalizeSpriteURL: () => normalizeSpriteURL,
|
|
26
|
+
normalizeStyleURL: () => normalizeStyleURL,
|
|
27
|
+
normalizeTileURL: () => normalizeTileURL
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(mapbox_exports);
|
|
30
|
+
const API_URL = "https://api.mapbox.com";
|
|
31
|
+
const HELP = "See https://www.mapbox.com/api-documentation/#access-tokens";
|
|
32
|
+
function makeAPIURL(urlObject, accessToken) {
|
|
33
|
+
const apiUrlObject = parseUrl(API_URL);
|
|
34
|
+
urlObject.protocol = apiUrlObject.protocol;
|
|
35
|
+
urlObject.authority = apiUrlObject.authority;
|
|
36
|
+
if (!accessToken) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`An API access token is required to use a Mapbox style. ${HELP}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (accessToken[0] === "s") {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Use a public access token (pk.*) not a secret access token (sk.*). ${HELP}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
urlObject.params.push(`access_token=${accessToken}`);
|
|
47
|
+
return formatUrl(urlObject);
|
|
48
|
+
}
|
|
49
|
+
function isMapboxURL(url) {
|
|
50
|
+
return url.indexOf("mapbox:") === 0;
|
|
51
|
+
}
|
|
52
|
+
function normalizeStyleURL(url, accessToken) {
|
|
53
|
+
if (!isMapboxURL(url)) return url;
|
|
54
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
55
|
+
const urlObject = parseUrl(url);
|
|
56
|
+
urlObject.path = `/styles/v1${urlObject.path}`;
|
|
57
|
+
return makeAPIURL(urlObject, accessToken);
|
|
58
|
+
}
|
|
59
|
+
function normalizeGlyphsURL(url, accessToken) {
|
|
60
|
+
if (!isMapboxURL(url)) return url;
|
|
61
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
62
|
+
const urlObject = parseUrl(url);
|
|
63
|
+
urlObject.path = `/fonts/v1${urlObject.path}`;
|
|
64
|
+
return makeAPIURL(urlObject, accessToken);
|
|
65
|
+
}
|
|
66
|
+
function normalizeSourceURL(url, accessToken) {
|
|
67
|
+
if (!isMapboxURL(url)) return url;
|
|
68
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
69
|
+
const urlObject = parseUrl(url);
|
|
70
|
+
urlObject.path = `/v4/${urlObject.authority}.json`;
|
|
71
|
+
urlObject.params.push("secure");
|
|
72
|
+
return makeAPIURL(urlObject, accessToken);
|
|
73
|
+
}
|
|
74
|
+
function normalizeSpriteURL(url, format, extension, accessToken) {
|
|
75
|
+
const urlObject = parseUrl(url);
|
|
76
|
+
if (!isMapboxURL(url)) {
|
|
77
|
+
urlObject.path += `${format}${extension}`;
|
|
78
|
+
return formatUrl(urlObject);
|
|
79
|
+
}
|
|
80
|
+
urlObject.path = `/styles/v1${urlObject.path}/sprite${format}${extension}`;
|
|
81
|
+
return makeAPIURL(urlObject, accessToken);
|
|
82
|
+
}
|
|
83
|
+
const imageExtensionRe = /(\.(png|jpg)\d*)(?=$)/;
|
|
84
|
+
function normalizeTileURL(tileURL, sourceURL, tileSize, { devicePixelRatio = 1, supportsWebp = false } = {}) {
|
|
85
|
+
if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;
|
|
86
|
+
const urlObject = parseUrl(tileURL);
|
|
87
|
+
const suffix = devicePixelRatio >= 2 || tileSize === 512 ? "@2x" : "";
|
|
88
|
+
const extension = supportsWebp ? ".webp" : "$1";
|
|
89
|
+
urlObject.path = urlObject.path.replace(
|
|
90
|
+
imageExtensionRe,
|
|
91
|
+
`${suffix}${extension}`
|
|
92
|
+
);
|
|
93
|
+
return formatUrl(urlObject);
|
|
94
|
+
}
|
|
95
|
+
const urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
|
|
96
|
+
function parseUrl(url) {
|
|
97
|
+
const parts = url.match(urlRe);
|
|
98
|
+
if (!parts) {
|
|
99
|
+
throw new Error("Unable to parse URL object");
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
protocol: parts[1],
|
|
103
|
+
authority: parts[2],
|
|
104
|
+
path: parts[3] || "/",
|
|
105
|
+
params: parts[4] ? parts[4].split("&") : []
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function formatUrl(obj) {
|
|
109
|
+
const params = obj.params.length ? `?${obj.params.join("&")}` : "";
|
|
110
|
+
return `${obj.protocol}://${obj.authority}${obj.path}${params}`;
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
API_URL,
|
|
115
|
+
isMapboxURL,
|
|
116
|
+
normalizeGlyphsURL,
|
|
117
|
+
normalizeSourceURL,
|
|
118
|
+
normalizeSpriteURL,
|
|
119
|
+
normalizeStyleURL,
|
|
120
|
+
normalizeTileURL
|
|
121
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @param {string} url */
|
|
2
|
+
declare function isMapboxURL(url: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @param {string} [accessToken]
|
|
6
|
+
*/
|
|
7
|
+
declare function normalizeStyleURL(url: string, accessToken?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} url
|
|
10
|
+
* @param {string} [accessToken]
|
|
11
|
+
*/
|
|
12
|
+
declare function normalizeGlyphsURL(url: string, accessToken?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {string} [accessToken]
|
|
16
|
+
*/
|
|
17
|
+
declare function normalizeSourceURL(url: string, accessToken?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @param {'' | '@2x'} format
|
|
21
|
+
* @param {'.png' | '.json'} extension
|
|
22
|
+
* @param {string} [accessToken]
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} tileURL
|
|
27
|
+
* @param {string} sourceURL
|
|
28
|
+
* @param {256 | 512} [tileSize]
|
|
29
|
+
* @param {{ devicePixelRatio?: number; supportsWebp?: boolean; }} [opts]
|
|
30
|
+
*/
|
|
31
|
+
declare function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
|
|
32
|
+
devicePixelRatio?: number;
|
|
33
|
+
supportsWebp?: boolean;
|
|
34
|
+
}): any;
|
|
35
|
+
declare const API_URL: "https://api.mapbox.com";
|
|
36
|
+
type URLObject = {
|
|
37
|
+
protocol: string;
|
|
38
|
+
authority: string;
|
|
39
|
+
path: string;
|
|
40
|
+
params: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { API_URL, type URLObject, isMapboxURL, normalizeGlyphsURL, normalizeSourceURL, normalizeSpriteURL, normalizeStyleURL, normalizeTileURL };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @param {string} url */
|
|
2
|
+
declare function isMapboxURL(url: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @param {string} [accessToken]
|
|
6
|
+
*/
|
|
7
|
+
declare function normalizeStyleURL(url: string, accessToken?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} url
|
|
10
|
+
* @param {string} [accessToken]
|
|
11
|
+
*/
|
|
12
|
+
declare function normalizeGlyphsURL(url: string, accessToken?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {string} [accessToken]
|
|
16
|
+
*/
|
|
17
|
+
declare function normalizeSourceURL(url: string, accessToken?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @param {'' | '@2x'} format
|
|
21
|
+
* @param {'.png' | '.json'} extension
|
|
22
|
+
* @param {string} [accessToken]
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} tileURL
|
|
27
|
+
* @param {string} sourceURL
|
|
28
|
+
* @param {256 | 512} [tileSize]
|
|
29
|
+
* @param {{ devicePixelRatio?: number; supportsWebp?: boolean; }} [opts]
|
|
30
|
+
*/
|
|
31
|
+
declare function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
|
|
32
|
+
devicePixelRatio?: number;
|
|
33
|
+
supportsWebp?: boolean;
|
|
34
|
+
}): any;
|
|
35
|
+
declare const API_URL: "https://api.mapbox.com";
|
|
36
|
+
type URLObject = {
|
|
37
|
+
protocol: string;
|
|
38
|
+
authority: string;
|
|
39
|
+
path: string;
|
|
40
|
+
params: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { API_URL, type URLObject, isMapboxURL, normalizeGlyphsURL, normalizeSourceURL, normalizeSpriteURL, normalizeStyleURL, normalizeTileURL };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const API_URL = "https://api.mapbox.com";
|
|
2
|
+
const HELP = "See https://www.mapbox.com/api-documentation/#access-tokens";
|
|
3
|
+
function makeAPIURL(urlObject, accessToken) {
|
|
4
|
+
const apiUrlObject = parseUrl(API_URL);
|
|
5
|
+
urlObject.protocol = apiUrlObject.protocol;
|
|
6
|
+
urlObject.authority = apiUrlObject.authority;
|
|
7
|
+
if (!accessToken) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
`An API access token is required to use a Mapbox style. ${HELP}`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (accessToken[0] === "s") {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Use a public access token (pk.*) not a secret access token (sk.*). ${HELP}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
urlObject.params.push(`access_token=${accessToken}`);
|
|
18
|
+
return formatUrl(urlObject);
|
|
19
|
+
}
|
|
20
|
+
function isMapboxURL(url) {
|
|
21
|
+
return url.indexOf("mapbox:") === 0;
|
|
22
|
+
}
|
|
23
|
+
function normalizeStyleURL(url, accessToken) {
|
|
24
|
+
if (!isMapboxURL(url)) return url;
|
|
25
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
26
|
+
const urlObject = parseUrl(url);
|
|
27
|
+
urlObject.path = `/styles/v1${urlObject.path}`;
|
|
28
|
+
return makeAPIURL(urlObject, accessToken);
|
|
29
|
+
}
|
|
30
|
+
function normalizeGlyphsURL(url, accessToken) {
|
|
31
|
+
if (!isMapboxURL(url)) return url;
|
|
32
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
33
|
+
const urlObject = parseUrl(url);
|
|
34
|
+
urlObject.path = `/fonts/v1${urlObject.path}`;
|
|
35
|
+
return makeAPIURL(urlObject, accessToken);
|
|
36
|
+
}
|
|
37
|
+
function normalizeSourceURL(url, accessToken) {
|
|
38
|
+
if (!isMapboxURL(url)) return url;
|
|
39
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
40
|
+
const urlObject = parseUrl(url);
|
|
41
|
+
urlObject.path = `/v4/${urlObject.authority}.json`;
|
|
42
|
+
urlObject.params.push("secure");
|
|
43
|
+
return makeAPIURL(urlObject, accessToken);
|
|
44
|
+
}
|
|
45
|
+
function normalizeSpriteURL(url, format, extension, accessToken) {
|
|
46
|
+
const urlObject = parseUrl(url);
|
|
47
|
+
if (!isMapboxURL(url)) {
|
|
48
|
+
urlObject.path += `${format}${extension}`;
|
|
49
|
+
return formatUrl(urlObject);
|
|
50
|
+
}
|
|
51
|
+
urlObject.path = `/styles/v1${urlObject.path}/sprite${format}${extension}`;
|
|
52
|
+
return makeAPIURL(urlObject, accessToken);
|
|
53
|
+
}
|
|
54
|
+
const imageExtensionRe = /(\.(png|jpg)\d*)(?=$)/;
|
|
55
|
+
function normalizeTileURL(tileURL, sourceURL, tileSize, { devicePixelRatio = 1, supportsWebp = false } = {}) {
|
|
56
|
+
if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;
|
|
57
|
+
const urlObject = parseUrl(tileURL);
|
|
58
|
+
const suffix = devicePixelRatio >= 2 || tileSize === 512 ? "@2x" : "";
|
|
59
|
+
const extension = supportsWebp ? ".webp" : "$1";
|
|
60
|
+
urlObject.path = urlObject.path.replace(
|
|
61
|
+
imageExtensionRe,
|
|
62
|
+
`${suffix}${extension}`
|
|
63
|
+
);
|
|
64
|
+
return formatUrl(urlObject);
|
|
65
|
+
}
|
|
66
|
+
const urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
|
|
67
|
+
function parseUrl(url) {
|
|
68
|
+
const parts = url.match(urlRe);
|
|
69
|
+
if (!parts) {
|
|
70
|
+
throw new Error("Unable to parse URL object");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
protocol: parts[1],
|
|
74
|
+
authority: parts[2],
|
|
75
|
+
path: parts[3] || "/",
|
|
76
|
+
params: parts[4] ? parts[4].split("&") : []
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function formatUrl(obj) {
|
|
80
|
+
const params = obj.params.length ? `?${obj.params.join("&")}` : "";
|
|
81
|
+
return `${obj.protocol}://${obj.authority}${obj.path}${params}`;
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
API_URL,
|
|
85
|
+
isMapboxURL,
|
|
86
|
+
normalizeGlyphsURL,
|
|
87
|
+
normalizeSourceURL,
|
|
88
|
+
normalizeSpriteURL,
|
|
89
|
+
normalizeStyleURL,
|
|
90
|
+
normalizeTileURL
|
|
91
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var misc_exports = {};
|
|
20
|
+
__export(misc_exports, {
|
|
21
|
+
clone: () => clone,
|
|
22
|
+
hasOwn: () => hasOwn,
|
|
23
|
+
noop: () => noop
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(misc_exports);
|
|
26
|
+
function clone(obj) {
|
|
27
|
+
return JSON.parse(JSON.stringify(obj));
|
|
28
|
+
}
|
|
29
|
+
function noop() {
|
|
30
|
+
}
|
|
31
|
+
function hasOwn(obj, key) {
|
|
32
|
+
return Object.hasOwn(obj, key);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
clone,
|
|
37
|
+
hasOwn,
|
|
38
|
+
noop
|
|
39
|
+
});
|
|
@@ -7,12 +7,8 @@
|
|
|
7
7
|
* @param {T} obj
|
|
8
8
|
* @returns {T}
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function noop() {}
|
|
15
|
-
|
|
10
|
+
declare function clone<T>(obj: T): T;
|
|
11
|
+
declare function noop(): void;
|
|
16
12
|
/**
|
|
17
13
|
* Like `Object.hasOwn`, but refines the type of `key`.
|
|
18
14
|
*
|
|
@@ -21,6 +17,6 @@ export function noop() {}
|
|
|
21
17
|
* @param {string} key
|
|
22
18
|
* @returns {key is (keyof T)}
|
|
23
19
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
20
|
+
declare function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
|
|
21
|
+
|
|
22
|
+
export { clone, hasOwn, noop };
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* @param {T} obj
|
|
8
8
|
* @returns {T}
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
declare function clone<T>(obj: T): T;
|
|
11
|
+
declare function noop(): void;
|
|
12
12
|
/**
|
|
13
13
|
* Like `Object.hasOwn`, but refines the type of `key`.
|
|
14
14
|
*
|
|
@@ -17,4 +17,6 @@ export function noop(): void;
|
|
|
17
17
|
* @param {string} key
|
|
18
18
|
* @returns {key is (keyof T)}
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
declare function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
|
|
21
|
+
|
|
22
|
+
export { clone, hasOwn, noop };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var streams_exports = {};
|
|
20
|
+
__export(streams_exports, {
|
|
21
|
+
ProgressStream: () => ProgressStream,
|
|
22
|
+
fromWebReadableStream: () => fromWebReadableStream,
|
|
23
|
+
isWebReadableStream: () => isWebReadableStream,
|
|
24
|
+
writeStreamFromAsync: () => writeStreamFromAsync
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(streams_exports);
|
|
27
|
+
var import_readable_stream = require("readable-stream");
|
|
28
|
+
function writeStreamFromAsync(fn, { concurrency = 16 } = {}) {
|
|
29
|
+
return new import_readable_stream.Writable({
|
|
30
|
+
highWaterMark: concurrency,
|
|
31
|
+
objectMode: true,
|
|
32
|
+
write(chunk, encoding, callback) {
|
|
33
|
+
fn.apply(null, chunk).then(() => callback(), callback);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function fromWebReadableStream(readableStream, options = {}) {
|
|
38
|
+
if (!isWebReadableStream(readableStream)) {
|
|
39
|
+
throw new Error("First argument must be a ReadableStream");
|
|
40
|
+
}
|
|
41
|
+
const { highWaterMark, encoding, objectMode = false, signal } = options;
|
|
42
|
+
if (encoding !== void 0 && !Buffer.isEncoding(encoding))
|
|
43
|
+
throw new Error("Invalid encoding");
|
|
44
|
+
const reader = readableStream.getReader();
|
|
45
|
+
let closed = false;
|
|
46
|
+
const readable = new import_readable_stream.Readable({
|
|
47
|
+
objectMode,
|
|
48
|
+
highWaterMark,
|
|
49
|
+
encoding,
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
signal,
|
|
52
|
+
read() {
|
|
53
|
+
reader.read().then(
|
|
54
|
+
(chunk) => {
|
|
55
|
+
if (chunk.done) {
|
|
56
|
+
readable.push(null);
|
|
57
|
+
} else {
|
|
58
|
+
readable.push(chunk.value);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
(error) => readable.destroy(error)
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
destroy(error, callback) {
|
|
65
|
+
function done() {
|
|
66
|
+
try {
|
|
67
|
+
callback(error);
|
|
68
|
+
} catch (error2) {
|
|
69
|
+
process.nextTick(() => {
|
|
70
|
+
throw error2;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!closed) {
|
|
75
|
+
reader.cancel(error).then(done, done);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
done();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
reader.closed.then(
|
|
82
|
+
() => {
|
|
83
|
+
closed = true;
|
|
84
|
+
},
|
|
85
|
+
(error) => {
|
|
86
|
+
closed = true;
|
|
87
|
+
readable.destroy(error);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
return readable;
|
|
91
|
+
}
|
|
92
|
+
function isWebReadableStream(obj) {
|
|
93
|
+
return !!(typeof obj === "object" && obj !== null && "pipeThrough" in obj && typeof obj.pipeThrough === "function" && "getReader" in obj && typeof obj.getReader === "function" && "cancel" in obj && typeof obj.cancel === "function");
|
|
94
|
+
}
|
|
95
|
+
class ProgressStream extends import_readable_stream.Transform {
|
|
96
|
+
#onprogress;
|
|
97
|
+
#byteLength = 0;
|
|
98
|
+
/**
|
|
99
|
+
* @param {ProgressStreamOptions} [opts]
|
|
100
|
+
*/
|
|
101
|
+
constructor({ onprogress, ...opts } = {}) {
|
|
102
|
+
super(opts);
|
|
103
|
+
this.#onprogress = onprogress;
|
|
104
|
+
}
|
|
105
|
+
/** Total bytes that have passed through this stream */
|
|
106
|
+
get byteLength() {
|
|
107
|
+
return this.#byteLength;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @override
|
|
111
|
+
* @param {Buffer | Uint8Array} chunk
|
|
112
|
+
* @param {Parameters<Transform['_transform']>[1]} encoding
|
|
113
|
+
* @param {Parameters<Transform['_transform']>[2]} callback
|
|
114
|
+
*/
|
|
115
|
+
_transform(chunk, encoding, callback) {
|
|
116
|
+
this.#byteLength += chunk.length;
|
|
117
|
+
this.#onprogress?.({
|
|
118
|
+
totalBytes: this.#byteLength,
|
|
119
|
+
chunkBytes: chunk.length
|
|
120
|
+
});
|
|
121
|
+
callback(null, chunk);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
ProgressStream,
|
|
127
|
+
fromWebReadableStream,
|
|
128
|
+
isWebReadableStream,
|
|
129
|
+
writeStreamFromAsync
|
|
130
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
import * as readable_stream from 'readable-stream';
|
|
3
|
+
import { Transform, TransformOptions } from 'readable-stream';
|
|
4
|
+
|
|
5
|
+
/** @import { TransformOptions } from 'readable-stream' */
|
|
6
|
+
/**
|
|
7
|
+
* Create a writable stream from an async function. Default concurrecy is 16 -
|
|
8
|
+
* this is the number of parallel functions that will be pending before
|
|
9
|
+
* backpressure is applied on the stream.
|
|
10
|
+
*
|
|
11
|
+
* @template {(...args: any[]) => Promise<void>} T
|
|
12
|
+
* @param {T} fn
|
|
13
|
+
* @returns {import('readable-stream').Writable}
|
|
14
|
+
*/
|
|
15
|
+
declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
|
|
16
|
+
concurrency?: number | undefined;
|
|
17
|
+
}): readable_stream.Writable;
|
|
18
|
+
/**
|
|
19
|
+
* From https://github.com/nodejs/node/blob/430c0269/lib/internal/webstreams/adapters.js#L509
|
|
20
|
+
*
|
|
21
|
+
* @param {ReadableStream} readableStream
|
|
22
|
+
* @param {{
|
|
23
|
+
* highWaterMark? : number,
|
|
24
|
+
* encoding? : string,
|
|
25
|
+
* objectMode? : boolean,
|
|
26
|
+
* signal? : AbortSignal,
|
|
27
|
+
* }} [options]
|
|
28
|
+
* @returns {import('stream').Readable}
|
|
29
|
+
*/
|
|
30
|
+
declare function fromWebReadableStream(readableStream: ReadableStream, options?: {
|
|
31
|
+
highWaterMark?: number;
|
|
32
|
+
encoding?: string;
|
|
33
|
+
objectMode?: boolean;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}): stream.Readable;
|
|
36
|
+
/**
|
|
37
|
+
* @param {unknown} obj
|
|
38
|
+
* @returns {obj is ReadableStream}
|
|
39
|
+
*/
|
|
40
|
+
declare function isWebReadableStream(obj: unknown): obj is ReadableStream;
|
|
41
|
+
/** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
|
|
42
|
+
/** @typedef {TransformOptions & { onprogress?: ProgressCallback }} ProgressStreamOptions */
|
|
43
|
+
/**
|
|
44
|
+
* Passthrough stream that counts the bytes passing through it. Pass an optional
|
|
45
|
+
* `onprogress` callback that will be called with the accumulated total byte
|
|
46
|
+
* count and the chunk byte count after each chunk.
|
|
47
|
+
* @extends {Transform}
|
|
48
|
+
*/
|
|
49
|
+
declare class ProgressStream extends Transform {
|
|
50
|
+
/**
|
|
51
|
+
* @param {ProgressStreamOptions} [opts]
|
|
52
|
+
*/
|
|
53
|
+
constructor({ onprogress, ...opts }?: ProgressStreamOptions);
|
|
54
|
+
/** Total bytes that have passed through this stream */
|
|
55
|
+
get byteLength(): number;
|
|
56
|
+
/**
|
|
57
|
+
* @override
|
|
58
|
+
* @param {Buffer | Uint8Array} chunk
|
|
59
|
+
* @param {Parameters<Transform['_transform']>[1]} encoding
|
|
60
|
+
* @param {Parameters<Transform['_transform']>[2]} callback
|
|
61
|
+
*/
|
|
62
|
+
override _transform(chunk: Buffer | Uint8Array, encoding: Parameters<Transform["_transform"]>[1], callback: Parameters<Transform["_transform"]>[2]): void;
|
|
63
|
+
#private;
|
|
64
|
+
}
|
|
65
|
+
type ProgressCallback = (opts: {
|
|
66
|
+
totalBytes: number;
|
|
67
|
+
chunkBytes: number;
|
|
68
|
+
}) => void;
|
|
69
|
+
type ProgressStreamOptions = TransformOptions & {
|
|
70
|
+
onprogress?: ProgressCallback;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { type ProgressCallback, ProgressStream, type ProgressStreamOptions, fromWebReadableStream, isWebReadableStream, writeStreamFromAsync };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
import * as readable_stream from 'readable-stream';
|
|
3
|
+
import { Transform, TransformOptions } from 'readable-stream';
|
|
4
|
+
|
|
1
5
|
/** @import { TransformOptions } from 'readable-stream' */
|
|
2
6
|
/**
|
|
3
7
|
* Create a writable stream from an async function. Default concurrecy is 16 -
|
|
@@ -8,9 +12,9 @@
|
|
|
8
12
|
* @param {T} fn
|
|
9
13
|
* @returns {import('readable-stream').Writable}
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
|
|
12
16
|
concurrency?: number | undefined;
|
|
13
|
-
}):
|
|
17
|
+
}): readable_stream.Writable;
|
|
14
18
|
/**
|
|
15
19
|
* From https://github.com/nodejs/node/blob/430c0269/lib/internal/webstreams/adapters.js#L509
|
|
16
20
|
*
|
|
@@ -23,17 +27,17 @@ export function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>
|
|
|
23
27
|
* }} [options]
|
|
24
28
|
* @returns {import('stream').Readable}
|
|
25
29
|
*/
|
|
26
|
-
|
|
30
|
+
declare function fromWebReadableStream(readableStream: ReadableStream, options?: {
|
|
27
31
|
highWaterMark?: number;
|
|
28
32
|
encoding?: string;
|
|
29
33
|
objectMode?: boolean;
|
|
30
34
|
signal?: AbortSignal;
|
|
31
|
-
}):
|
|
35
|
+
}): stream.Readable;
|
|
32
36
|
/**
|
|
33
37
|
* @param {unknown} obj
|
|
34
38
|
* @returns {obj is ReadableStream}
|
|
35
39
|
*/
|
|
36
|
-
|
|
40
|
+
declare function isWebReadableStream(obj: unknown): obj is ReadableStream;
|
|
37
41
|
/** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
|
|
38
42
|
/** @typedef {TransformOptions & { onprogress?: ProgressCallback }} ProgressStreamOptions */
|
|
39
43
|
/**
|
|
@@ -42,7 +46,7 @@ export function isWebReadableStream(obj: unknown): obj is ReadableStream;
|
|
|
42
46
|
* count and the chunk byte count after each chunk.
|
|
43
47
|
* @extends {Transform}
|
|
44
48
|
*/
|
|
45
|
-
|
|
49
|
+
declare class ProgressStream extends Transform {
|
|
46
50
|
/**
|
|
47
51
|
* @param {ProgressStreamOptions} [opts]
|
|
48
52
|
*/
|
|
@@ -58,12 +62,12 @@ export class ProgressStream extends Transform {
|
|
|
58
62
|
override _transform(chunk: Buffer | Uint8Array, encoding: Parameters<Transform["_transform"]>[1], callback: Parameters<Transform["_transform"]>[2]): void;
|
|
59
63
|
#private;
|
|
60
64
|
}
|
|
61
|
-
|
|
65
|
+
type ProgressCallback = (opts: {
|
|
62
66
|
totalBytes: number;
|
|
63
67
|
chunkBytes: number;
|
|
64
68
|
}) => void;
|
|
65
|
-
|
|
69
|
+
type ProgressStreamOptions = TransformOptions & {
|
|
66
70
|
onprogress?: ProgressCallback;
|
|
67
71
|
};
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
|
|
73
|
+
export { type ProgressCallback, ProgressStream, type ProgressStreamOptions, fromWebReadableStream, isWebReadableStream, writeStreamFromAsync };
|