@loaders.gl/core 5.0.0-alpha.7 → 5.0.0-alpha.9
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/dist/dist.dev.js +308 -52
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +293 -60
- package/dist/index.cjs.map +3 -3
- package/dist/lib/api/create-data-source.d.ts +1 -1
- package/dist/lib/api/create-data-source.d.ts.map +1 -1
- package/dist/lib/api/create-data-source.js +23 -2
- package/dist/lib/api/create-data-source.js.map +1 -1
- package/dist/lib/api/load-in-batches.d.ts.map +1 -1
- package/dist/lib/api/load-in-batches.js +17 -6
- package/dist/lib/api/load-in-batches.js.map +1 -1
- package/dist/lib/api/load.d.ts +3 -3
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +14 -5
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse-file.d.ts.map +1 -1
- package/dist/lib/api/parse-file.js +6 -2
- package/dist/lib/api/parse-file.js.map +1 -1
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +6 -1
- package/dist/lib/api/parse-in-batches.js.map +1 -1
- package/dist/lib/api/parse.d.ts.map +1 -1
- package/dist/lib/api/parse.js +6 -1
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js +4 -13
- package/dist/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-defaults.js +1 -0
- package/dist/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts +7 -0
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +29 -0
- package/dist/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/lib/utils/response-utils.js +2 -11
- package/dist/lib/utils/response-utils.js.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +6 -6
- package/src/lib/api/create-data-source.ts +31 -2
- package/src/lib/api/load-in-batches.ts +18 -11
- package/src/lib/api/load.ts +44 -6
- package/src/lib/api/parse-file.ts +15 -2
- package/src/lib/api/parse-in-batches.ts +11 -1
- package/src/lib/api/parse.ts +11 -1
- package/src/lib/loader-utils/get-fetch-function.ts +4 -15
- package/src/lib/loader-utils/option-defaults.ts +1 -0
- package/src/lib/loader-utils/option-utils.ts +34 -0
- package/src/lib/utils/response-utils.ts +2 -12
package/dist/index.cjs
CHANGED
|
@@ -1181,13 +1181,17 @@ function validateWorkerVersion(worker, coreVersion = VERSION2) {
|
|
|
1181
1181
|
|
|
1182
1182
|
// ../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts
|
|
1183
1183
|
function canParseWithWorker(loader, options) {
|
|
1184
|
-
var _a;
|
|
1184
|
+
var _a, _b, _c;
|
|
1185
|
+
if ((_b = (_a = options == null ? void 0 : options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.some(
|
|
1186
|
+
(credential) => credential.type === "request" || "token" in credential && typeof credential.token === "function"
|
|
1187
|
+
))
|
|
1188
|
+
return false;
|
|
1185
1189
|
const workerOptions = getWorkerOptions(options);
|
|
1186
1190
|
const nodeWorkers = workerOptions._nodeWorkers;
|
|
1187
1191
|
if (!isBrowser2 && !nodeWorkers) {
|
|
1188
1192
|
return false;
|
|
1189
1193
|
}
|
|
1190
|
-
if (loader.id === "las" && (((
|
|
1194
|
+
if (loader.id === "las" && (((_c = options == null ? void 0 : options.las) == null ? void 0 : _c.shape) ?? "arrow-table") === "arrow-table") {
|
|
1191
1195
|
return false;
|
|
1192
1196
|
}
|
|
1193
1197
|
if (loader.id === "csv" && !shouldParseCSVWithWorker(options)) {
|
|
@@ -1278,7 +1282,12 @@ function callParseOnMainThread(parseOnMainThread, input, options, context) {
|
|
|
1278
1282
|
return parseOnMainThread(input, void 0, options, context);
|
|
1279
1283
|
}
|
|
1280
1284
|
function getWorkerOptions(options = {}, loader) {
|
|
1281
|
-
const serializedOptions = JSON.parse(
|
|
1285
|
+
const serializedOptions = JSON.parse(
|
|
1286
|
+
JSON.stringify({
|
|
1287
|
+
...options,
|
|
1288
|
+
...options.core ? { core: { ...options.core, authentications: void 0 } } : {}
|
|
1289
|
+
})
|
|
1290
|
+
);
|
|
1282
1291
|
const workerOptions = {
|
|
1283
1292
|
...serializedOptions.core,
|
|
1284
1293
|
...serializedOptions
|
|
@@ -1353,6 +1362,19 @@ function concatenateArrayBuffersFromArray(sources) {
|
|
|
1353
1362
|
return result.buffer;
|
|
1354
1363
|
}
|
|
1355
1364
|
|
|
1365
|
+
// ../loader-utils/src/lib/binary-utils/encode-array-buffer-to-base64.ts
|
|
1366
|
+
function encodeArrayBufferToBase64(arrayBuffer) {
|
|
1367
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
1368
|
+
const encodedChunks = [];
|
|
1369
|
+
const chunkByteLength = 3 * 4096;
|
|
1370
|
+
for (let byteOffset = 0; byteOffset < bytes.length; byteOffset += chunkByteLength) {
|
|
1371
|
+
encodedChunks.push(
|
|
1372
|
+
btoa(String.fromCharCode(...bytes.subarray(byteOffset, byteOffset + chunkByteLength)))
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
return encodedChunks.join("");
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1356
1378
|
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
1357
1379
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1358
1380
|
const textDecoder = new TextDecoder(void 0, options);
|
|
@@ -1487,6 +1509,7 @@ var RequestScheduler = class {
|
|
|
1487
1509
|
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
1488
1510
|
requestQueue = [];
|
|
1489
1511
|
requestMap = /* @__PURE__ */ new Map();
|
|
1512
|
+
/** Pending arrival debounce or next-tick refill; only new arrivals replace this timer. */
|
|
1490
1513
|
updateTimer = null;
|
|
1491
1514
|
constructor(props = {}) {
|
|
1492
1515
|
this.props = { ...DEFAULT_PROPS2, ...props };
|
|
@@ -1554,20 +1577,27 @@ var RequestScheduler = class {
|
|
|
1554
1577
|
isDone = true;
|
|
1555
1578
|
this.requestMap.delete(handle);
|
|
1556
1579
|
this.activeRequestCount--;
|
|
1557
|
-
this.
|
|
1580
|
+
this.scheduleRefill();
|
|
1558
1581
|
}
|
|
1559
1582
|
};
|
|
1560
1583
|
this.activeRequestCount++;
|
|
1561
1584
|
return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
|
|
1562
1585
|
}
|
|
1563
|
-
/**
|
|
1586
|
+
/** Refills freed slots on the next tick while preserving any pending arrival debounce. */
|
|
1587
|
+
scheduleRefill() {
|
|
1588
|
+
if (this.updateTimer !== null) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), 0);
|
|
1592
|
+
}
|
|
1593
|
+
/** Restarts the quiet period when a new request enters the queue. */
|
|
1564
1594
|
_issueNewRequests() {
|
|
1565
1595
|
if (this.updateTimer !== null) {
|
|
1566
1596
|
clearTimeout(this.updateTimer);
|
|
1567
1597
|
}
|
|
1568
1598
|
this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
1569
1599
|
}
|
|
1570
|
-
/**
|
|
1600
|
+
/** Clears timer ownership before updating priorities and dispatching queued requests. */
|
|
1571
1601
|
_issueNewRequestsAsync() {
|
|
1572
1602
|
if (this.updateTimer !== null) {
|
|
1573
1603
|
clearTimeout(this.updateTimer);
|
|
@@ -1609,25 +1639,110 @@ var RequestScheduler = class {
|
|
|
1609
1639
|
}
|
|
1610
1640
|
};
|
|
1611
1641
|
|
|
1642
|
+
// ../loader-utils/src/lib/request-utils/authentication.ts
|
|
1643
|
+
function resolveCredentials(credentials, authentications = []) {
|
|
1644
|
+
if (credentials.every(isAuthentication)) return credentials;
|
|
1645
|
+
return credentials.map((credential, index) => {
|
|
1646
|
+
if (isAuthentication(credential)) return credential;
|
|
1647
|
+
const AuthenticationClass = authentications.find(
|
|
1648
|
+
(authentication2) => authentication2.type === (credential == null ? void 0 : credential.type)
|
|
1649
|
+
);
|
|
1650
|
+
if (!AuthenticationClass) {
|
|
1651
|
+
throw new Error(`No authentication class registered for credential at index ${index}.`);
|
|
1652
|
+
}
|
|
1653
|
+
let authentication;
|
|
1654
|
+
try {
|
|
1655
|
+
authentication = new AuthenticationClass(credential);
|
|
1656
|
+
} catch {
|
|
1657
|
+
throw new Error(`Invalid authentication configuration at index ${index}.`);
|
|
1658
|
+
}
|
|
1659
|
+
if (!isAuthentication(authentication)) {
|
|
1660
|
+
throw new Error(`Authentication class returned an invalid credential at index ${index}.`);
|
|
1661
|
+
}
|
|
1662
|
+
return authentication;
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
function resolveAuthenticationOptions(options) {
|
|
1666
|
+
var _a, _b;
|
|
1667
|
+
if (!((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length)) return options;
|
|
1668
|
+
const credentials = resolveCredentials(options.core.credentials, options.core.authentications);
|
|
1669
|
+
if (credentials === options.core.credentials) return options;
|
|
1670
|
+
return { ...options, core: { ...options.core, credentials } };
|
|
1671
|
+
}
|
|
1672
|
+
async function resolveLoaderAuthenticationOptions(loader, url, options) {
|
|
1673
|
+
var _a, _b, _c, _d;
|
|
1674
|
+
if (!((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) || options.core.credentials.every(isAuthentication)) {
|
|
1675
|
+
return options;
|
|
1676
|
+
}
|
|
1677
|
+
const contributions = await ((_c = loader == null ? void 0 : loader.getAuthentications) == null ? void 0 : _c.call(loader, url, options));
|
|
1678
|
+
if (!(contributions == null ? void 0 : contributions.length)) return resolveAuthenticationOptions(options);
|
|
1679
|
+
return resolveAuthenticationOptions({
|
|
1680
|
+
...options,
|
|
1681
|
+
core: {
|
|
1682
|
+
...options.core,
|
|
1683
|
+
authentications: [...((_d = options.core) == null ? void 0 : _d.authentications) || [], ...contributions]
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
function isAuthentication(credential) {
|
|
1688
|
+
if (!credential || typeof credential !== "object") return false;
|
|
1689
|
+
if (typeof credential.id !== "string" || !Array.isArray(credential.origins)) return false;
|
|
1690
|
+
if (credential.type === "request") return typeof credential.authenticate === "function";
|
|
1691
|
+
return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1612
1694
|
// ../loader-utils/src/lib/request-utils/request-credentials.ts
|
|
1613
1695
|
var AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
|
|
1614
1696
|
var refreshPromises = /* @__PURE__ */ new WeakMap();
|
|
1615
1697
|
function createAuthenticatedFetch(options) {
|
|
1616
|
-
const
|
|
1617
|
-
|
|
1618
|
-
const
|
|
1619
|
-
|
|
1698
|
+
const suppliedFetch = options.fetch || ((url, requestOptions) => fetch(url, requestOptions));
|
|
1699
|
+
const existingMetadata = suppliedFetch[AUTHENTICATED_FETCH];
|
|
1700
|
+
const credentialResolutions = new Map(existingMetadata == null ? void 0 : existingMetadata.credentialResolutions);
|
|
1701
|
+
const resolvedCredentials = resolveCredentials(
|
|
1702
|
+
options.credentials.map((credential) => credentialResolutions.get(credential) || credential),
|
|
1703
|
+
options.authentications
|
|
1704
|
+
);
|
|
1705
|
+
options.credentials.forEach((credential, index) => {
|
|
1706
|
+
credentialResolutions.set(credential, resolvedCredentials[index]);
|
|
1707
|
+
});
|
|
1708
|
+
if (!options.fetchOptions && (!resolvedCredentials.length || (existingMetadata == null ? void 0 : existingMetadata.credentials.length) === resolvedCredentials.length && resolvedCredentials.every(
|
|
1709
|
+
(credential, index) => credential === existingMetadata.credentials[index]
|
|
1710
|
+
)))
|
|
1711
|
+
return suppliedFetch;
|
|
1712
|
+
const baseFetch = (existingMetadata == null ? void 0 : existingMetadata.fetch) || suppliedFetch;
|
|
1713
|
+
const credentials = existingMetadata ? [.../* @__PURE__ */ new Set([...resolvedCredentials, ...existingMetadata.credentials])] : resolvedCredentials;
|
|
1714
|
+
const fetchOptions = mergeFetchOptions(
|
|
1715
|
+
(existingMetadata == null ? void 0 : existingMetadata.fetchOptions) || {},
|
|
1716
|
+
options.fetchOptions
|
|
1717
|
+
);
|
|
1718
|
+
const tokenCredentials = credentials.filter(
|
|
1719
|
+
(credential) => credential.type !== "request"
|
|
1720
|
+
);
|
|
1721
|
+
const requestCredentials = credentials.filter(
|
|
1722
|
+
(credential) => credential.type === "request"
|
|
1723
|
+
);
|
|
1724
|
+
for (const credential of requestCredentials) normalizeRequestOrigins(credential.origins);
|
|
1620
1725
|
const authenticatedFetch = async (url, requestOptions = {}) => {
|
|
1621
|
-
var _a, _b, _c;
|
|
1726
|
+
var _a, _b, _c, _d;
|
|
1727
|
+
requestOptions = mergeFetchOptions(fetchOptions, requestOptions);
|
|
1728
|
+
if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError3();
|
|
1729
|
+
if (!credentials.length) return baseFetch(url, requestOptions);
|
|
1622
1730
|
const resolvedURL = parseHTTPURL(url);
|
|
1623
|
-
|
|
1624
|
-
const
|
|
1625
|
-
const response = await baseFetch(
|
|
1731
|
+
const authorization = resolvedURL ? await authorizeRequest(resolvedURL, requestOptions, tokenCredentials) : { url, options: requestOptions, credentials: [] };
|
|
1732
|
+
const signedRequest = await authenticateRequest(authorization, requestCredentials, "request");
|
|
1733
|
+
const response = await baseFetch(signedRequest.url, signedRequest.options);
|
|
1626
1734
|
const refreshableCredentials = authorization.credentials.filter(
|
|
1627
1735
|
({ credential }) => typeof credential.token === "function" && credential.refreshStatusCodes.includes(response.status)
|
|
1628
1736
|
);
|
|
1629
|
-
|
|
1630
|
-
|
|
1737
|
+
const shouldRetrySignature = signedRequest.credentials.some(
|
|
1738
|
+
(credential) => {
|
|
1739
|
+
var _a2;
|
|
1740
|
+
return (_a2 = credential.refreshStatusCodes) == null ? void 0 : _a2.includes(response.status);
|
|
1741
|
+
}
|
|
1742
|
+
);
|
|
1743
|
+
if (!refreshableCredentials.length && !shouldRetrySignature || !isReplayableRequest(requestOptions) || !isReplayableRequest(signedRequest.options))
|
|
1744
|
+
return response;
|
|
1745
|
+
if ((_b = requestOptions.signal) == null ? void 0 : _b.aborted) throw createAbortError3();
|
|
1631
1746
|
const refreshedTokens = /* @__PURE__ */ new Map();
|
|
1632
1747
|
await Promise.all(
|
|
1633
1748
|
refreshableCredentials.map(async ({ credential }) => {
|
|
@@ -1635,24 +1750,95 @@ function createAuthenticatedFetch(options) {
|
|
|
1635
1750
|
if (token) refreshedTokens.set(credential, token);
|
|
1636
1751
|
})
|
|
1637
1752
|
);
|
|
1638
|
-
if (!refreshedTokens.size) return response;
|
|
1639
|
-
await ((
|
|
1753
|
+
if (!refreshedTokens.size && !shouldRetrySignature) return response;
|
|
1754
|
+
await ((_c = response.body) == null ? void 0 : _c.cancel().catch(() => {
|
|
1640
1755
|
}));
|
|
1641
|
-
if ((
|
|
1642
|
-
const replayAuthorization = await authorizeRequest(
|
|
1756
|
+
if ((_d = requestOptions.signal) == null ? void 0 : _d.aborted) throw createAbortError3();
|
|
1757
|
+
const replayAuthorization = resolvedURL ? await authorizeRequest(
|
|
1643
1758
|
resolvedURL,
|
|
1644
1759
|
requestOptions,
|
|
1645
|
-
|
|
1760
|
+
tokenCredentials,
|
|
1646
1761
|
refreshedTokens,
|
|
1647
1762
|
authorization.credentials
|
|
1763
|
+
) : { url, options: requestOptions };
|
|
1764
|
+
const replayRequest = await authenticateRequest(
|
|
1765
|
+
replayAuthorization,
|
|
1766
|
+
requestCredentials,
|
|
1767
|
+
"retry",
|
|
1768
|
+
response
|
|
1648
1769
|
);
|
|
1649
|
-
return baseFetch(
|
|
1770
|
+
return baseFetch(replayRequest.url, replayRequest.options);
|
|
1650
1771
|
};
|
|
1651
1772
|
Object.defineProperty(authenticatedFetch, AUTHENTICATED_FETCH, {
|
|
1652
|
-
value:
|
|
1773
|
+
value: {
|
|
1774
|
+
fetch: baseFetch,
|
|
1775
|
+
credentials,
|
|
1776
|
+
credentialResolutions,
|
|
1777
|
+
fetchOptions
|
|
1778
|
+
}
|
|
1653
1779
|
});
|
|
1654
1780
|
return authenticatedFetch;
|
|
1655
1781
|
}
|
|
1782
|
+
function mergeFetchOptions(defaultOptions, requestOptions) {
|
|
1783
|
+
const mergedOptions = { ...defaultOptions, ...requestOptions };
|
|
1784
|
+
if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
|
|
1785
|
+
const headers = new Headers(defaultOptions.headers);
|
|
1786
|
+
new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
|
|
1787
|
+
mergedOptions.headers = headers;
|
|
1788
|
+
}
|
|
1789
|
+
return mergedOptions;
|
|
1790
|
+
}
|
|
1791
|
+
async function authenticateRequest(request, credentials, reason, response) {
|
|
1792
|
+
const appliedCredentials = [];
|
|
1793
|
+
const signal = request.options.signal;
|
|
1794
|
+
for (const credential of credentials) {
|
|
1795
|
+
const origin = getRequestOrigin(request.url);
|
|
1796
|
+
if (!origin || !normalizeRequestOrigins(credential.origins).includes(origin)) continue;
|
|
1797
|
+
if (signal == null ? void 0 : signal.aborted) throw createAbortError3();
|
|
1798
|
+
const authenticatedRequest = await credential.authenticate({
|
|
1799
|
+
url: request.url,
|
|
1800
|
+
options: { ...request.options, headers: new Headers(request.options.headers) },
|
|
1801
|
+
reason,
|
|
1802
|
+
response: response ? { status: response.status, headers: new Headers(response.headers) } : void 0
|
|
1803
|
+
});
|
|
1804
|
+
if (!authenticatedRequest || typeof authenticatedRequest.url !== "string" || !authenticatedRequest.options || typeof authenticatedRequest.options !== "object") {
|
|
1805
|
+
throw new Error("Authentication callback returned an invalid request.");
|
|
1806
|
+
}
|
|
1807
|
+
request = {
|
|
1808
|
+
url: authenticatedRequest.url,
|
|
1809
|
+
options: { ...authenticatedRequest.options, ...signal ? { signal } : {} }
|
|
1810
|
+
};
|
|
1811
|
+
appliedCredentials.push(credential);
|
|
1812
|
+
}
|
|
1813
|
+
if (signal == null ? void 0 : signal.aborted) throw createAbortError3();
|
|
1814
|
+
return { ...request, credentials: appliedCredentials };
|
|
1815
|
+
}
|
|
1816
|
+
function getRequestOrigin(url) {
|
|
1817
|
+
try {
|
|
1818
|
+
const parsedURL = new URL(url);
|
|
1819
|
+
if (!parsedURL.host || parsedURL.username || parsedURL.password) return null;
|
|
1820
|
+
return parsedURL.origin !== "null" ? parsedURL.origin : `${parsedURL.protocol}//${parsedURL.host}`;
|
|
1821
|
+
} catch {
|
|
1822
|
+
return null;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
function normalizeRequestOrigins(origins) {
|
|
1826
|
+
if (!origins.length)
|
|
1827
|
+
throw new Error("Request authentication requires at least one exact origin.");
|
|
1828
|
+
return origins.map((origin) => {
|
|
1829
|
+
const resolvedOrigin = getRequestOrigin(origin);
|
|
1830
|
+
let url;
|
|
1831
|
+
try {
|
|
1832
|
+
url = new URL(origin);
|
|
1833
|
+
} catch {
|
|
1834
|
+
throw new Error("Invalid request authentication origin.");
|
|
1835
|
+
}
|
|
1836
|
+
if (!resolvedOrigin || url.pathname && url.pathname !== "/" || url.search || url.hash) {
|
|
1837
|
+
throw new Error("Invalid request authentication origin.");
|
|
1838
|
+
}
|
|
1839
|
+
return resolvedOrigin;
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1656
1842
|
async function authorizeRequest(sourceURL, requestOptions, credentials, tokenOverrides = /* @__PURE__ */ new Map(), previousCredentials = []) {
|
|
1657
1843
|
const url = new URL(sourceURL);
|
|
1658
1844
|
const headers = new Headers(requestOptions.headers);
|
|
@@ -2222,19 +2408,11 @@ async function getInitialDataUrl(resource) {
|
|
|
2222
2408
|
}
|
|
2223
2409
|
if (resource instanceof ArrayBuffer) {
|
|
2224
2410
|
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
2225
|
-
const base64 =
|
|
2411
|
+
const base64 = encodeArrayBufferToBase64(slice);
|
|
2226
2412
|
return `data:base64,${base64}`;
|
|
2227
2413
|
}
|
|
2228
2414
|
return null;
|
|
2229
2415
|
}
|
|
2230
|
-
function arrayBufferToBase64(buffer) {
|
|
2231
|
-
let binary = "";
|
|
2232
|
-
const bytes = new Uint8Array(buffer);
|
|
2233
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
2234
|
-
binary += String.fromCharCode(bytes[i]);
|
|
2235
|
-
}
|
|
2236
|
-
return btoa(binary);
|
|
2237
|
-
}
|
|
2238
2416
|
|
|
2239
2417
|
// dist/lib/fetch/fetch-file.js
|
|
2240
2418
|
function isNodePath(url) {
|
|
@@ -2349,6 +2527,7 @@ var ConsoleLog = class {
|
|
|
2349
2527
|
|
|
2350
2528
|
// dist/lib/loader-utils/option-defaults.js
|
|
2351
2529
|
var DEFAULT_LOADER_OPTIONS = {
|
|
2530
|
+
searchParams: void 0,
|
|
2352
2531
|
core: {
|
|
2353
2532
|
baseUrl: void 0,
|
|
2354
2533
|
// baseUrl
|
|
@@ -2455,6 +2634,27 @@ var CORE_LOADER_OPTION_KEYS = [
|
|
|
2455
2634
|
"metadata",
|
|
2456
2635
|
"transforms"
|
|
2457
2636
|
];
|
|
2637
|
+
function applySearchParamsToUrl(url, options) {
|
|
2638
|
+
const searchParams = options == null ? void 0 : options.searchParams;
|
|
2639
|
+
if (!searchParams || Object.keys(searchParams).length === 0 || /^(?:data|blob):/i.test(url)) {
|
|
2640
|
+
return url;
|
|
2641
|
+
}
|
|
2642
|
+
const hashIndex = url.indexOf("#");
|
|
2643
|
+
const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
|
|
2644
|
+
const urlWithoutHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url;
|
|
2645
|
+
const queryIndex = urlWithoutHash.indexOf("?");
|
|
2646
|
+
const path = queryIndex >= 0 ? urlWithoutHash.slice(0, queryIndex) : urlWithoutHash;
|
|
2647
|
+
const query = queryIndex >= 0 ? urlWithoutHash.slice(queryIndex + 1) : "";
|
|
2648
|
+
const existingSearchParams = new URLSearchParams(query);
|
|
2649
|
+
const appendedSearchParams = new URLSearchParams();
|
|
2650
|
+
for (const [key, value] of Object.entries(searchParams)) {
|
|
2651
|
+
if (!existingSearchParams.has(key)) {
|
|
2652
|
+
appendedSearchParams.set(key, String(value));
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
const serializedAppendedSearchParams = appendedSearchParams.toString();
|
|
2656
|
+
return `${path}${queryIndex >= 0 ? `?${query}` : ""}${serializedAppendedSearchParams ? `${queryIndex >= 0 ? "&" : "?"}${serializedAppendedSearchParams}` : ""}${hash}`;
|
|
2657
|
+
}
|
|
2458
2658
|
function getGlobalLoaderState() {
|
|
2459
2659
|
globalThis.loaders = globalThis.loaders || {};
|
|
2460
2660
|
const { loaders } = globalThis;
|
|
@@ -3211,7 +3411,7 @@ function getIterableFromData(data) {
|
|
|
3211
3411
|
|
|
3212
3412
|
// dist/lib/loader-utils/get-fetch-function.js
|
|
3213
3413
|
function getFetchFunction(options, context) {
|
|
3214
|
-
var _a, _b;
|
|
3414
|
+
var _a, _b, _c;
|
|
3215
3415
|
const globalOptions = getGlobalLoaderOptions();
|
|
3216
3416
|
const loaderOptions = options || globalOptions;
|
|
3217
3417
|
const fetchOption = loaderOptions.fetch ?? ((_a = loaderOptions.core) == null ? void 0 : _a.fetch);
|
|
@@ -3219,8 +3419,7 @@ function getFetchFunction(options, context) {
|
|
|
3219
3419
|
if (typeof fetchOption === "function") {
|
|
3220
3420
|
fetchFunction = fetchOption;
|
|
3221
3421
|
} else if (isObject(fetchOption)) {
|
|
3222
|
-
|
|
3223
|
-
fetchFunction = (url, requestOptions) => baseFetch(url, mergeFetchOptions(fetchOption, requestOptions));
|
|
3422
|
+
fetchFunction = (context == null ? void 0 : context.fetch) || fetchFile;
|
|
3224
3423
|
} else if (context == null ? void 0 : context.fetch) {
|
|
3225
3424
|
fetchFunction = context.fetch;
|
|
3226
3425
|
} else {
|
|
@@ -3228,18 +3427,11 @@ function getFetchFunction(options, context) {
|
|
|
3228
3427
|
}
|
|
3229
3428
|
return createAuthenticatedFetch({
|
|
3230
3429
|
fetch: fetchFunction,
|
|
3231
|
-
credentials: ((_b = loaderOptions.core) == null ? void 0 : _b.credentials) || []
|
|
3430
|
+
credentials: ((_b = loaderOptions.core) == null ? void 0 : _b.credentials) || [],
|
|
3431
|
+
authentications: (_c = loaderOptions.core) == null ? void 0 : _c.authentications,
|
|
3432
|
+
fetchOptions: isObject(fetchOption) ? fetchOption : void 0
|
|
3232
3433
|
});
|
|
3233
3434
|
}
|
|
3234
|
-
function mergeFetchOptions(defaultOptions, requestOptions) {
|
|
3235
|
-
const options = { ...defaultOptions, ...requestOptions };
|
|
3236
|
-
if (defaultOptions.headers || (requestOptions == null ? void 0 : requestOptions.headers)) {
|
|
3237
|
-
const headers = new Headers(defaultOptions.headers);
|
|
3238
|
-
new Headers(requestOptions == null ? void 0 : requestOptions.headers).forEach((value, key) => headers.set(key, value));
|
|
3239
|
-
options.headers = headers;
|
|
3240
|
-
}
|
|
3241
|
-
return options;
|
|
3242
|
-
}
|
|
3243
3435
|
|
|
3244
3436
|
// dist/lib/api/load-loader.js
|
|
3245
3437
|
var loaderImplementationPromises = /* @__PURE__ */ new Map();
|
|
@@ -3340,6 +3532,7 @@ async function importLoaderImplementation(implementationSpecifier, loaderId) {
|
|
|
3340
3532
|
|
|
3341
3533
|
// dist/lib/api/parse-file.js
|
|
3342
3534
|
async function parseFile(file, loaders, options, context) {
|
|
3535
|
+
var _a, _b;
|
|
3343
3536
|
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3344
3537
|
context = void 0;
|
|
3345
3538
|
options = loaders;
|
|
@@ -3356,7 +3549,9 @@ async function parseFile(file, loaders, options, context) {
|
|
|
3356
3549
|
if (isSourceLoader(loader)) {
|
|
3357
3550
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parseFile().`);
|
|
3358
3551
|
}
|
|
3359
|
-
const
|
|
3552
|
+
const normalizedOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
3553
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
3554
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url, normalizedOptions);
|
|
3360
3555
|
context = getLoaderContext(
|
|
3361
3556
|
// @ts-expect-error candidateLoaders may be a single forced loader
|
|
3362
3557
|
{ url, _parse: parse, loaders: candidateLoaders },
|
|
@@ -3469,6 +3664,7 @@ function makeBatchFromTable(table) {
|
|
|
3469
3664
|
|
|
3470
3665
|
// dist/lib/api/parse-in-batches.js
|
|
3471
3666
|
async function parseInBatches(data, loaders, options, context) {
|
|
3667
|
+
var _a, _b;
|
|
3472
3668
|
const loaderArray = Array.isArray(loaders) ? loaders : void 0;
|
|
3473
3669
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3474
3670
|
context = void 0;
|
|
@@ -3482,7 +3678,9 @@ async function parseInBatches(data, loaders, options, context) {
|
|
|
3482
3678
|
if (!loader) {
|
|
3483
3679
|
return [];
|
|
3484
3680
|
}
|
|
3485
|
-
const
|
|
3681
|
+
const normalizedOptions = normalizeOptions(options, loader, loaderArray, url);
|
|
3682
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
3683
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url || "", normalizedOptions);
|
|
3486
3684
|
context = getLoaderContext({ url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray }, strictOptions, context || null);
|
|
3487
3685
|
const loaderWithParser = await getLoaderImplementation(loader, strictOptions, context.url);
|
|
3488
3686
|
return await parseWithLoaderInBatches(loader, loaderWithParser, data, strictOptions, context);
|
|
@@ -3562,17 +3760,24 @@ function loadInBatches(files, loaders, options, context) {
|
|
|
3562
3760
|
} else {
|
|
3563
3761
|
loadersArray = loaders;
|
|
3564
3762
|
}
|
|
3565
|
-
const fetch2 = getFetchFunction(options || {});
|
|
3566
3763
|
if (!Array.isArray(files)) {
|
|
3567
|
-
return loadOneFileInBatches(files, loadersArray, options || {}
|
|
3764
|
+
return loadOneFileInBatches(files, loadersArray, options || {});
|
|
3568
3765
|
}
|
|
3569
|
-
const promises = files.map((file) => loadOneFileInBatches(file, loadersArray, options || {}
|
|
3766
|
+
const promises = files.map((file) => loadOneFileInBatches(file, loadersArray, options || {}));
|
|
3570
3767
|
return promises;
|
|
3571
3768
|
}
|
|
3572
|
-
async function loadOneFileInBatches(file, loaders, options
|
|
3769
|
+
async function loadOneFileInBatches(file, loaders, options) {
|
|
3770
|
+
var _a, _b;
|
|
3573
3771
|
if (typeof file === "string") {
|
|
3574
3772
|
const url = file;
|
|
3575
|
-
const
|
|
3773
|
+
const loader = await selectLoader(url, loaders, {
|
|
3774
|
+
...options,
|
|
3775
|
+
core: { ...options.core, nothrow: true }
|
|
3776
|
+
});
|
|
3777
|
+
const authenticationLoader = loader && !loader.getAuthentications && ((_b = (_a = options.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, options, url) : loader;
|
|
3778
|
+
options = await resolveLoaderAuthenticationOptions(authenticationLoader, url, options);
|
|
3779
|
+
const fetch2 = getFetchFunction(options);
|
|
3780
|
+
const response = await fetch2(applySearchParamsToUrl(url, options));
|
|
3576
3781
|
return Array.isArray(loaders) ? await parseInBatches(response, loaders, options) : await parseInBatches(response, loaders, options);
|
|
3577
3782
|
}
|
|
3578
3783
|
return Array.isArray(loaders) ? await parseInBatches(file, loaders, options) : await parseInBatches(file, loaders, options);
|
|
@@ -3591,8 +3796,10 @@ async function load(url, loaders, options, context) {
|
|
|
3591
3796
|
resolvedLoaders = loaders;
|
|
3592
3797
|
resolvedOptions = options;
|
|
3593
3798
|
}
|
|
3799
|
+
resolvedOptions ||= getGlobalLoaderOptions();
|
|
3594
3800
|
if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
|
|
3595
3801
|
const sourceLoader = await resolveSourceLoader(resolvedLoaders, url, resolvedOptions);
|
|
3802
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(resolvedLoaders.getAuthentications ? resolvedLoaders : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3596
3803
|
const runtimeCoreApi = {
|
|
3597
3804
|
fetchFile,
|
|
3598
3805
|
parse,
|
|
@@ -3606,6 +3813,7 @@ async function load(url, loaders, options, context) {
|
|
|
3606
3813
|
}
|
|
3607
3814
|
if (Array.isArray(resolvedLoaders) && resolvedLoaders.length === 1 && isSourceLoader(resolvedLoaders[0])) {
|
|
3608
3815
|
const sourceLoader = await resolveSourceLoader(resolvedLoaders[0], url, resolvedOptions);
|
|
3816
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(resolvedLoaders[0].getAuthentications ? resolvedLoaders[0] : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3609
3817
|
const runtimeCoreApi = {
|
|
3610
3818
|
fetchFile,
|
|
3611
3819
|
parse,
|
|
@@ -3624,6 +3832,7 @@ async function load(url, loaders, options, context) {
|
|
|
3624
3832
|
});
|
|
3625
3833
|
if (selectedLoader && isSourceLoader(selectedLoader)) {
|
|
3626
3834
|
const sourceLoader = await resolveSourceLoader(selectedLoader, url, resolvedOptions);
|
|
3835
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(selectedLoader.getAuthentications ? selectedLoader : sourceLoader, typeof url === "string" ? url : "", resolvedOptions || {});
|
|
3627
3836
|
return sourceLoader.createDataSource(url, resolvedOptions || {}, {
|
|
3628
3837
|
fetchFile,
|
|
3629
3838
|
parse,
|
|
@@ -3636,15 +3845,20 @@ async function load(url, loaders, options, context) {
|
|
|
3636
3845
|
}
|
|
3637
3846
|
if (selectedLoader && typeof url === "string") {
|
|
3638
3847
|
const loaderImplementation = await getLoaderImplementation(selectedLoader, resolvedOptions, url);
|
|
3848
|
+
resolvedOptions = await resolveLoaderAuthenticationOptions(selectedLoader.getAuthentications ? selectedLoader : loaderImplementation, url, resolvedOptions || {});
|
|
3639
3849
|
const parseUrl = loaderImplementation.parseUrl;
|
|
3640
|
-
if (parseUrl)
|
|
3641
|
-
|
|
3850
|
+
if (parseUrl) {
|
|
3851
|
+
const requestUrl = applySearchParamsToUrl(url, resolvedOptions);
|
|
3852
|
+
return await parseUrl(requestUrl, resolvedOptions, context);
|
|
3853
|
+
}
|
|
3642
3854
|
}
|
|
3643
3855
|
}
|
|
3856
|
+
if (resolvedOptions)
|
|
3857
|
+
resolvedOptions = resolveAuthenticationOptions(resolvedOptions);
|
|
3644
3858
|
const fetch2 = getFetchFunction(resolvedOptions);
|
|
3645
3859
|
let data = url;
|
|
3646
3860
|
if (typeof url === "string") {
|
|
3647
|
-
data = await fetch2(url);
|
|
3861
|
+
data = await fetch2(applySearchParamsToUrl(url, resolvedOptions));
|
|
3648
3862
|
}
|
|
3649
3863
|
if (isBlob(url)) {
|
|
3650
3864
|
data = await fetch2(url);
|
|
@@ -3727,6 +3941,7 @@ function getLoadersFromContext(loaders, context) {
|
|
|
3727
3941
|
|
|
3728
3942
|
// dist/lib/api/parse.js
|
|
3729
3943
|
async function parse(data, loaders, options, context) {
|
|
3944
|
+
var _a, _b;
|
|
3730
3945
|
if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
3731
3946
|
context = void 0;
|
|
3732
3947
|
options = loaders;
|
|
@@ -3744,7 +3959,9 @@ async function parse(data, loaders, options, context) {
|
|
|
3744
3959
|
if (isSourceLoader(loader)) {
|
|
3745
3960
|
throw new Error(`${loader.id} is a SourceLoader. Use load() to create a runtime source object instead of parse().`);
|
|
3746
3961
|
}
|
|
3747
|
-
const
|
|
3962
|
+
const normalizedOptions = normalizeOptions(options, loader, candidateLoaders, url);
|
|
3963
|
+
const authenticationLoader = !loader.getAuthentications && ((_b = (_a = normalizedOptions.core) == null ? void 0 : _a.credentials) == null ? void 0 : _b.length) ? await getLoaderImplementation(loader, normalizedOptions, url || (context == null ? void 0 : context.url)) : loader;
|
|
3964
|
+
const strictOptions = await resolveLoaderAuthenticationOptions(authenticationLoader, url || "", normalizedOptions);
|
|
3748
3965
|
context = getLoaderContext(
|
|
3749
3966
|
// @ts-expect-error
|
|
3750
3967
|
{ url, _parse: parse, loaders: candidateLoaders },
|
|
@@ -3918,8 +4135,8 @@ function getTemporaryFilename(filename2) {
|
|
|
3918
4135
|
}
|
|
3919
4136
|
|
|
3920
4137
|
// dist/lib/api/create-data-source.js
|
|
3921
|
-
function createDataSource(data, sources, options) {
|
|
3922
|
-
var _a;
|
|
4138
|
+
function createDataSource(data, sources, options = {}) {
|
|
4139
|
+
var _a, _b, _c, _d, _e;
|
|
3923
4140
|
const resolvedOptions = options || {};
|
|
3924
4141
|
const type = ((_a = resolvedOptions == null ? void 0 : resolvedOptions.core) == null ? void 0 : _a.type) || resolvedOptions.type || "auto";
|
|
3925
4142
|
const source = sources.length === 1 ? sources[0] : type === "auto" ? selectLoaderSync(data, sources, {
|
|
@@ -3931,7 +4148,23 @@ function createDataSource(data, sources, options) {
|
|
|
3931
4148
|
if (!source) {
|
|
3932
4149
|
throw new Error("Not a valid source type");
|
|
3933
4150
|
}
|
|
3934
|
-
|
|
4151
|
+
const contributions = ((_c = (_b = resolvedOptions.core) == null ? void 0 : _b.credentials) == null ? void 0 : _c.length) ? (_d = source.getAuthentications) == null ? void 0 : _d.call(source, typeof data === "string" ? data : "", resolvedOptions) : void 0;
|
|
4152
|
+
if (contributions && "then" in contributions) {
|
|
4153
|
+
void contributions.catch(() => {
|
|
4154
|
+
});
|
|
4155
|
+
throw new Error("Use load() with an asynchronous getAuthentications() hook.");
|
|
4156
|
+
}
|
|
4157
|
+
const authenticatedOptions = resolveAuthenticationOptions((contributions == null ? void 0 : contributions.length) ? {
|
|
4158
|
+
...resolvedOptions,
|
|
4159
|
+
core: {
|
|
4160
|
+
...resolvedOptions.core,
|
|
4161
|
+
authentications: [
|
|
4162
|
+
...((_e = resolvedOptions.core) == null ? void 0 : _e.authentications) || [],
|
|
4163
|
+
...contributions || []
|
|
4164
|
+
]
|
|
4165
|
+
}
|
|
4166
|
+
} : resolvedOptions);
|
|
4167
|
+
return source.createDataSource(data, authenticatedOptions, coreApi);
|
|
3935
4168
|
}
|
|
3936
4169
|
function getSourceOfType(type, sources) {
|
|
3937
4170
|
for (const service of sources) {
|
|
@@ -4005,7 +4238,7 @@ function makeStream(source, options) {
|
|
|
4005
4238
|
}
|
|
4006
4239
|
|
|
4007
4240
|
// dist/null-loader.js
|
|
4008
|
-
var VERSION4 = true ? "5.0.0-alpha.
|
|
4241
|
+
var VERSION4 = true ? "5.0.0-alpha.9" : "latest";
|
|
4009
4242
|
var NullWorkerLoader = {
|
|
4010
4243
|
dataType: null,
|
|
4011
4244
|
batchType: null,
|