@loaders.gl/core 3.3.2 → 3.4.0-alpha.2
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.min.js +242 -186
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +2 -2
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +2 -2
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js +31 -0
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/es5/lib/loader-utils/loader-context.js +2 -2
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +20 -43
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/null-loader.js +1 -1
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/load-in-batches.js +1 -1
- package/dist/esm/lib/api/load-in-batches.js.map +1 -1
- package/dist/esm/lib/api/load.js +1 -1
- package/dist/esm/lib/api/load.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/get-fetch-function.js +25 -0
- package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -0
- package/dist/esm/lib/loader-utils/loader-context.js +1 -1
- package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js +2 -20
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/esm/null-loader.js.map +1 -1
- package/dist/lib/api/encode.d.ts +5 -5
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +1 -0
- package/dist/lib/api/load-in-batches.js +2 -2
- package/dist/lib/api/load.d.ts.map +1 -1
- package/dist/lib/api/load.js +3 -2
- package/dist/lib/loader-utils/get-fetch-function.d.ts +9 -0
- package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -0
- package/dist/lib/loader-utils/get-fetch-function.js +31 -0
- package/dist/lib/loader-utils/loader-context.js +2 -2
- package/dist/lib/loader-utils/option-utils.d.ts +5 -15
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +10 -31
- package/dist/null-worker.js +1 -1
- package/package.json +5 -5
- package/src/lib/api/encode.ts +7 -6
- package/src/lib/api/load-in-batches.ts +1 -1
- package/src/lib/api/load.ts +3 -2
- package/src/lib/loader-utils/get-fetch-function.ts +38 -0
- package/src/lib/loader-utils/loader-context.ts +1 -1
- package/src/lib/loader-utils/option-utils.ts +17 -44
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-context.js","names":["getFetchFunction","getLoaderContext","context","options","previousContext","resolvedContext","fetch","Array","isArray","loaders","getLoadersFromContext","candidateLoaders","contextLoaders","length"],"sources":["../../../../src/lib/loader-utils/loader-context.ts"],"sourcesContent":["import type {Loader, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';\nimport {getFetchFunction} from './
|
|
1
|
+
{"version":3,"file":"loader-context.js","names":["getFetchFunction","getLoaderContext","context","options","previousContext","resolvedContext","fetch","Array","isArray","loaders","getLoadersFromContext","candidateLoaders","contextLoaders","length"],"sources":["../../../../src/lib/loader-utils/loader-context.ts"],"sourcesContent":["import type {Loader, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';\nimport {getFetchFunction} from './get-fetch-function';\n\n/**\n * \"sub\" loaders invoked by other loaders get a \"context\" injected on `this`\n * The context will inject core methods like `parse` and contain information\n * about loaders and options passed in to the top-level `parse` call.\n *\n * @param context\n * @param options\n * @param previousContext\n */\nexport function getLoaderContext(\n context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>,\n options?: LoaderOptions,\n previousContext: LoaderContext | null = null\n): LoaderContext {\n // For recursive calls, we already have a context\n // TODO - add any additional loaders to context?\n if (previousContext) {\n return previousContext;\n }\n\n const resolvedContext: LoaderContext = {\n fetch: getFetchFunction(options, context),\n ...context\n };\n\n // Recursive loading does not use single loader\n if (!Array.isArray(resolvedContext.loaders)) {\n resolvedContext.loaders = null;\n }\n\n return resolvedContext;\n}\n\n// eslint-disable-next-line complexity\nexport function getLoadersFromContext(\n loaders: Loader[] | Loader | undefined,\n context?: LoaderContext\n) {\n // A single non-array loader is force selected, but only on top-level (context === null)\n if (!context && loaders && !Array.isArray(loaders)) {\n return loaders;\n }\n\n // Create a merged list\n let candidateLoaders;\n if (loaders) {\n candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];\n }\n if (context && context.loaders) {\n const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];\n candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;\n }\n // If no loaders, return null to look in globally registered loaders\n return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;\n}\n"],"mappings":"AACA,SAAQA,gBAAgB,QAAO,sBAAsB;;AAWrD,OAAO,SAASC,gBAAgB,CAC9BC,OAA6E,EAC7EC,OAAuB,EAER;EAAA,IADfC,eAAqC,uEAAG,IAAI;EAI5C,IAAIA,eAAe,EAAE;IACnB,OAAOA,eAAe;EACxB;EAEA,MAAMC,eAA8B,GAAG;IACrCC,KAAK,EAAEN,gBAAgB,CAACG,OAAO,EAAED,OAAO,CAAC;IACzC,GAAGA;EACL,CAAC;;EAGD,IAAI,CAACK,KAAK,CAACC,OAAO,CAACH,eAAe,CAACI,OAAO,CAAC,EAAE;IAC3CJ,eAAe,CAACI,OAAO,GAAG,IAAI;EAChC;EAEA,OAAOJ,eAAe;AACxB;;AAGA,OAAO,SAASK,qBAAqB,CACnCD,OAAsC,EACtCP,OAAuB,EACvB;EAEA,IAAI,CAACA,OAAO,IAAIO,OAAO,IAAI,CAACF,KAAK,CAACC,OAAO,CAACC,OAAO,CAAC,EAAE;IAClD,OAAOA,OAAO;EAChB;;EAGA,IAAIE,gBAAgB;EACpB,IAAIF,OAAO,EAAE;IACXE,gBAAgB,GAAGJ,KAAK,CAACC,OAAO,CAACC,OAAO,CAAC,GAAGA,OAAO,GAAG,CAACA,OAAO,CAAC;EACjE;EACA,IAAIP,OAAO,IAAIA,OAAO,CAACO,OAAO,EAAE;IAC9B,MAAMG,cAAc,GAAGL,KAAK,CAACC,OAAO,CAACN,OAAO,CAACO,OAAO,CAAC,GAAGP,OAAO,CAACO,OAAO,GAAG,CAACP,OAAO,CAACO,OAAO,CAAC;IAC3FE,gBAAgB,GAAGA,gBAAgB,GAAG,CAAC,GAAGA,gBAAgB,EAAE,GAAGC,cAAc,CAAC,GAAGA,cAAc;EACjG;EAEA,OAAOD,gBAAgB,IAAIA,gBAAgB,CAACE,MAAM,GAAGF,gBAAgB,GAAG,IAAI;AAC9E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import { isPureObject, isObject } from '../../javascript-utils/is-type';
|
|
2
|
-
import { fetchFile } from '../fetch/fetch-file';
|
|
3
4
|
import { probeLog, NullLog } from './loggers';
|
|
4
5
|
import { DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS } from './option-defaults';
|
|
5
6
|
|
|
@@ -34,25 +35,6 @@ export function normalizeOptions(options, loader, loaders, url) {
|
|
|
34
35
|
return normalizeOptionsInternal(loader, options, url);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function getFetchFunction(options, context) {
|
|
38
|
-
const globalOptions = getGlobalLoaderOptions();
|
|
39
|
-
const fetchOptions = options || globalOptions;
|
|
40
|
-
|
|
41
|
-
if (typeof fetchOptions.fetch === 'function') {
|
|
42
|
-
return fetchOptions.fetch;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (isObject(fetchOptions.fetch)) {
|
|
46
|
-
return url => fetchFile(url, fetchOptions);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (context !== null && context !== void 0 && context.fetch) {
|
|
50
|
-
return context === null || context === void 0 ? void 0 : context.fetch;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return fetchFile;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
38
|
function validateOptions(options, loaders) {
|
|
57
39
|
validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);
|
|
58
40
|
for (const loader of loaders) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-utils.js","names":["isPureObject","isObject","fetchFile","probeLog","NullLog","DEFAULT_LOADER_OPTIONS","REMOVED_LOADER_OPTIONS","getGlobalLoaderState","globalThis","loaders","_state","getGlobalLoaderOptions","state","globalOptions","setGlobalOptions","options","normalizeOptionsInternal","normalizeOptions","loader","url","Array","isArray","validateOptions","getFetchFunction","context","fetchOptions","fetch","validateOptionsObject","idOptions","id","loaderOptions","deprecatedOptions","defaultOptions","loaderName","prefix","key","isSubOptions","isBaseUriOption","isWorkerUrlOption","warn","suggestion","findSimilarOption","optionKey","lowerCaseOptionKey","toLowerCase","bestSuggestion","lowerCaseKey","isPartialMatch","startsWith","loaderDefaultOptions","mergedOptions","addUrlOptions","log","mergeNestedFields","value","baseUri"],"sources":["../../../../src/lib/loader-utils/option-utils.ts"],"sourcesContent":["import type {Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {isPureObject, isObject} from '../../javascript-utils/is-type';\nimport {fetchFile} from '../fetch/fetch-file';\nimport {probeLog, NullLog} from './loggers';\nimport {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';\n/**\n * Global state for loaders.gl. Stored on `global.loaders._state`\n */\ntype GlobalLoaderState = {\n loaderRegistry: Loader[];\n globalOptions: {[key: string]: any};\n};\n\n/**\n * Helper for safely accessing global loaders.gl variables\n * Wraps initialization of global variable in function to defeat overly aggressive tree-shakers\n */\nexport function getGlobalLoaderState(): GlobalLoaderState {\n // @ts-ignore\n globalThis.loaders = globalThis.loaders || {};\n // @ts-ignore\n const {loaders} = globalThis;\n\n // Add _state object to keep separate from modules added to globalThis.loaders\n loaders._state = loaders._state || {};\n return loaders._state;\n}\n\n/**\n * Store global loader options on the global object to increase chances of cross loaders-version interoperability\n * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks\n * @returns global loader options merged with default loader options\n */\nexport const getGlobalLoaderOptions = () => {\n const state = getGlobalLoaderState();\n // Ensure all default loader options from this library are mentioned\n state.globalOptions = state.globalOptions || {...DEFAULT_LOADER_OPTIONS};\n return state.globalOptions;\n};\n\n/**\n * Set global loader options\n * @param options\n */\nexport function setGlobalOptions(options: object): void {\n const state = getGlobalLoaderState();\n const globalOptions = getGlobalLoaderOptions();\n state.globalOptions = normalizeOptionsInternal(globalOptions, options);\n}\n\n/**\n * Merges options with global opts and loader defaults, also injects baseUri\n * @param options\n * @param loader\n * @param loaders\n * @param url\n */\nexport function normalizeOptions(\n options: object,\n loader: Loader,\n loaders?: Loader[],\n url?: string\n): object {\n loaders = loaders || [];\n loaders = Array.isArray(loaders) ? loaders : [loaders];\n\n validateOptions(options, loaders);\n return normalizeOptionsInternal(loader, options, url);\n}\n\n/**\n * Gets the current fetch function from options and context\n * @param options\n * @param context\n */\nexport function getFetchFunction(\n options?: LoaderOptions,\n context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>\n) {\n const globalOptions = getGlobalLoaderOptions();\n\n const fetchOptions = options || globalOptions;\n\n // options.fetch can be a function\n if (typeof fetchOptions.fetch === 'function') {\n return fetchOptions.fetch;\n }\n\n // options.fetch can be an options object\n if (isObject(fetchOptions.fetch)) {\n return (url) => fetchFile(url, fetchOptions);\n }\n\n // else refer to context (from parent loader) if available\n if (context?.fetch) {\n return context?.fetch;\n }\n\n // else return the default fetch function\n return fetchFile;\n}\n\n// VALIDATE OPTIONS\n\n/**\n * Warn for unsupported options\n * @param options\n * @param loaders\n */\nfunction validateOptions(options: LoaderOptions, loaders: Loader[]) {\n // Check top level options\n validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);\n for (const loader of loaders) {\n // Get the scoped, loader specific options from the user supplied options\n const idOptions = (options && options[loader.id]) || {};\n\n // Get scoped, loader specific default and deprecated options from the selected loader\n const loaderOptions = (loader.options && loader.options[loader.id]) || {};\n const deprecatedOptions =\n (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};\n\n // Validate loader specific options\n validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);\n }\n}\n\n// eslint-disable-next-line max-params, complexity\nfunction validateOptionsObject(\n options,\n id: string | null,\n defaultOptions,\n deprecatedOptions,\n loaders: Loader[]\n) {\n const loaderName = id || 'Top level';\n const prefix = id ? `${id}.` : '';\n\n for (const key in options) {\n // If top level option value is an object it could options for a loader, so ignore\n const isSubOptions = !id && isObject(options[key]);\n const isBaseUriOption = key === 'baseUri' && !id;\n const isWorkerUrlOption = key === 'workerUrl' && id;\n // <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.\n if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {\n // Issue deprecation warnings\n if (key in deprecatedOptions) {\n probeLog.warn(\n `${loaderName} loader option \\'${prefix}${key}\\' no longer supported, use \\'${deprecatedOptions[key]}\\'`\n )();\n } else if (!isSubOptions) {\n const suggestion = findSimilarOption(key, loaders);\n probeLog.warn(\n `${loaderName} loader option \\'${prefix}${key}\\' not recognized. ${suggestion}`\n )();\n }\n }\n }\n}\n\nfunction findSimilarOption(optionKey, loaders) {\n const lowerCaseOptionKey = optionKey.toLowerCase();\n let bestSuggestion = '';\n for (const loader of loaders) {\n for (const key in loader.options) {\n if (optionKey === key) {\n return `Did you mean \\'${loader.id}.${key}\\'?`;\n }\n const lowerCaseKey = key.toLowerCase();\n const isPartialMatch =\n lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);\n if (isPartialMatch) {\n bestSuggestion = bestSuggestion || `Did you mean \\'${loader.id}.${key}\\'?`;\n }\n }\n }\n return bestSuggestion;\n}\n\nfunction normalizeOptionsInternal(loader, options, url?: string) {\n const loaderDefaultOptions = loader.options || {};\n\n const mergedOptions = {...loaderDefaultOptions};\n\n addUrlOptions(mergedOptions, url);\n\n // LOGGING: options.log can be set to `null` to defeat logging\n if (mergedOptions.log === null) {\n mergedOptions.log = new NullLog();\n }\n\n mergeNestedFields(mergedOptions, getGlobalLoaderOptions());\n mergeNestedFields(mergedOptions, options);\n\n return mergedOptions;\n}\n\n// Merge nested options objects\nfunction mergeNestedFields(mergedOptions, options) {\n for (const key in options) {\n // Check for nested options\n // object in options => either no key in defaultOptions or object in defaultOptions\n if (key in options) {\n const value = options[key];\n if (isPureObject(value) && isPureObject(mergedOptions[key])) {\n mergedOptions[key] = {\n ...mergedOptions[key],\n ...options[key]\n };\n } else {\n mergedOptions[key] = options[key];\n }\n }\n // else: No need to merge nested opts, and the initial merge already copied over the nested options\n }\n}\n\n// Harvest information from the url\n// TODO - baseUri should be a directory, i.e. remove file component from baseUri\n// TODO - extract extension?\n// TODO - extract query parameters?\n// TODO - should these be injected on context instead of options?\nfunction addUrlOptions(options, url?: string) {\n if (url && !('baseUri' in options)) {\n options.baseUri = url;\n }\n}\n"],"mappings":"AACA,SAAQA,YAAY,EAAEC,QAAQ,QAAO,gCAAgC;AACrE,SAAQC,SAAS,QAAO,qBAAqB;AAC7C,SAAQC,QAAQ,EAAEC,OAAO,QAAO,WAAW;AAC3C,SAAQC,sBAAsB,EAAEC,sBAAsB,QAAO,mBAAmB;;AAahF,OAAO,SAASC,oBAAoB,GAAsB;EAExDC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;EAE7C,MAAM;IAACA;EAAO,CAAC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IONS","getGlobalLoaderState","globalThis","loaders","_state","getGlobalLoaderOptions","state","globalOptions","setGlobalOptions","options","normalizeOptionsInternal","normalizeOptions","loader","url","Array","isArray","validateOptions","validateOptionsObject","idOptions","id","loaderOptions","deprecatedOptions","defaultOptions","loaderName","prefix","key","isSubOptions","isBaseUriOption","isWorkerUrlOption","warn","suggestion","findSimilarOption","optionKey","lowerCaseOptionKey","toLowerCase","bestSuggestion","lowerCaseKey","isPartialMatch","startsWith","loaderDefaultOptions","mergedOptions","addUrlOptions","log","mergeNestedFields","value","baseUri"],"sources":["../../../../src/lib/loader-utils/option-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {isPureObject, isObject} from '../../javascript-utils/is-type';\nimport {probeLog, NullLog} from './loggers';\nimport {DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS} from './option-defaults';\n\n/**\n * Global state for loaders.gl. Stored on `global.loaders._state`\n */\ntype GlobalLoaderState = {\n loaderRegistry: Loader[];\n globalOptions: LoaderOptions;\n};\n\n/**\n * Helper for safely accessing global loaders.gl variables\n * Wraps initialization of global variable in function to defeat overly aggressive tree-shakers\n */\nexport function getGlobalLoaderState(): GlobalLoaderState {\n // @ts-ignore\n globalThis.loaders = globalThis.loaders || {};\n // @ts-ignore\n const {loaders} = globalThis;\n\n // Add _state object to keep separate from modules added to globalThis.loaders\n loaders._state = loaders._state || {};\n return loaders._state;\n}\n\n/**\n * Store global loader options on the global object to increase chances of cross loaders-version interoperability\n * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks\n * @returns global loader options merged with default loader options\n */\nexport const getGlobalLoaderOptions = (): LoaderOptions => {\n const state = getGlobalLoaderState();\n // Ensure all default loader options from this library are mentioned\n state.globalOptions = state.globalOptions || {...DEFAULT_LOADER_OPTIONS};\n return state.globalOptions;\n};\n\n/**\n * Set global loader options\n * @param options\n */\nexport function setGlobalOptions(options: LoaderOptions): void {\n const state = getGlobalLoaderState();\n const globalOptions = getGlobalLoaderOptions();\n state.globalOptions = normalizeOptionsInternal(globalOptions, options);\n}\n\n/**\n * Merges options with global opts and loader defaults, also injects baseUri\n * @param options\n * @param loader\n * @param loaders\n * @param url\n */\nexport function normalizeOptions(\n options: LoaderOptions,\n loader: Loader,\n loaders?: Loader[],\n url?: string\n): LoaderOptions {\n loaders = loaders || [];\n loaders = Array.isArray(loaders) ? loaders : [loaders];\n\n validateOptions(options, loaders);\n return normalizeOptionsInternal(loader, options, url);\n}\n\n// VALIDATE OPTIONS\n\n/**\n * Warn for unsupported options\n * @param options\n * @param loaders\n */\nfunction validateOptions(options: LoaderOptions, loaders: Loader[]) {\n // Check top level options\n validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);\n for (const loader of loaders) {\n // Get the scoped, loader specific options from the user supplied options\n const idOptions = (options && options[loader.id]) || {};\n\n // Get scoped, loader specific default and deprecated options from the selected loader\n const loaderOptions = (loader.options && loader.options[loader.id]) || {};\n const deprecatedOptions =\n (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};\n\n // Validate loader specific options\n validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);\n }\n}\n\n// eslint-disable-next-line max-params, complexity\nfunction validateOptionsObject(\n options,\n id: string | null,\n defaultOptions,\n deprecatedOptions,\n loaders: Loader[]\n) {\n const loaderName = id || 'Top level';\n const prefix = id ? `${id}.` : '';\n\n for (const key in options) {\n // If top level option value is an object it could options for a loader, so ignore\n const isSubOptions = !id && isObject(options[key]);\n const isBaseUriOption = key === 'baseUri' && !id;\n const isWorkerUrlOption = key === 'workerUrl' && id;\n // <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.\n if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {\n // Issue deprecation warnings\n if (key in deprecatedOptions) {\n probeLog.warn(\n `${loaderName} loader option \\'${prefix}${key}\\' no longer supported, use \\'${deprecatedOptions[key]}\\'`\n )();\n } else if (!isSubOptions) {\n const suggestion = findSimilarOption(key, loaders);\n probeLog.warn(\n `${loaderName} loader option \\'${prefix}${key}\\' not recognized. ${suggestion}`\n )();\n }\n }\n }\n}\n\nfunction findSimilarOption(optionKey, loaders) {\n const lowerCaseOptionKey = optionKey.toLowerCase();\n let bestSuggestion = '';\n for (const loader of loaders) {\n for (const key in loader.options) {\n if (optionKey === key) {\n return `Did you mean \\'${loader.id}.${key}\\'?`;\n }\n const lowerCaseKey = key.toLowerCase();\n const isPartialMatch =\n lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);\n if (isPartialMatch) {\n bestSuggestion = bestSuggestion || `Did you mean \\'${loader.id}.${key}\\'?`;\n }\n }\n }\n return bestSuggestion;\n}\n\nfunction normalizeOptionsInternal(loader, options, url?: string) {\n const loaderDefaultOptions = loader.options || {};\n\n const mergedOptions = {...loaderDefaultOptions};\n\n addUrlOptions(mergedOptions, url);\n\n // LOGGING: options.log can be set to `null` to defeat logging\n if (mergedOptions.log === null) {\n mergedOptions.log = new NullLog();\n }\n\n mergeNestedFields(mergedOptions, getGlobalLoaderOptions());\n mergeNestedFields(mergedOptions, options);\n\n return mergedOptions;\n}\n\n// Merge nested options objects\nfunction mergeNestedFields(mergedOptions, options) {\n for (const key in options) {\n // Check for nested options\n // object in options => either no key in defaultOptions or object in defaultOptions\n if (key in options) {\n const value = options[key];\n if (isPureObject(value) && isPureObject(mergedOptions[key])) {\n mergedOptions[key] = {\n ...mergedOptions[key],\n ...options[key]\n };\n } else {\n mergedOptions[key] = options[key];\n }\n }\n // else: No need to merge nested opts, and the initial merge already copied over the nested options\n }\n}\n\n/**\n * Harvest information from the url\n * @deprecated This is mainly there to support a hack in the GLTFLoader\n * TODO - baseUri should be a directory, i.e. remove file component from baseUri\n * TODO - extract extension?\n * TODO - extract query parameters?\n * TODO - should these be injected on context instead of options?\n */\nfunction addUrlOptions(options, url?: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,aAAa,CAACE,GAAG,KAAK,IAAI,EAAE;IAC9BF,aAAa,CAACE,GAAG,GAAG,IAAI5C,OAAO,EAAE;EACnC;EAEA6C,iBAAiB,CAACH,aAAa,EAAEnC,sBAAsB,EAAE,CAAC;EAC1DsC,iBAAiB,CAACH,aAAa,EAAE/B,OAAO,CAAC;EAEzC,OAAO+B,aAAa;AACtB;;AAGA,SAASG,iBAAiB,CAACH,aAAa,EAAE/B,OAAO,EAAE;EACjD,KAAK,MAAMgB,GAAG,IAAIhB,OAAO,EAAE;IAGzB,IAAIgB,GAAG,IAAIhB,OAAO,EAAE;MAClB,MAAMmC,KAAK,GAAGnC,OAAO,CAACgB,GAAG,CAAC;MAC1B,IAAI9B,YAAY,CAACiD,KAAK,CAAC,IAAIjD,YAAY,CAAC6C,aAAa,CAACf,GAAG,CAAC,CAAC,EAAE;QAC3De,aAAa,CAACf,GAAG,CAAC,GAAG;UACnB,GAAGe,aAAa,CAACf,GAAG,CAAC;UACrB,GAAGhB,OAAO,CAACgB,GAAG;QAChB,CAAC;MACH,CAAC,MAAM;QACLe,aAAa,CAACf,GAAG,CAAC,GAAGhB,OAAO,CAACgB,GAAG,CAAC;MACnC;IACF;EAEF;AACF;;AAUA,SAASgB,aAAa,CAAChC,OAAO,EAAEI,GAAY,EAAE;EAC5C,IAAIA,GAAG,IAAI,EAAE,SAAS,IAAIJ,OAAO,CAAC,EAAE;IAClCA,OAAO,CAACoC,OAAO,GAAGhC,GAAG;EACvB;AACF"}
|
package/dist/esm/null-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"null-loader.js","names":["VERSION","NullWorkerLoader","name","id","module","version","worker","mimeTypes","extensions","tests","options","null","parseSync","arrayBuffer","context","echoParameters","JSON","parse","stringify","NullLoader","parseInBatches","generator","asyncIterator","batch"],"sources":["../../src/null-loader.ts"],"sourcesContent":["// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nimport {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\n\n/**\n * Loads any data and returns null (or optionally passes through data unparsed)\n */\nexport const NullWorkerLoader: Loader = {\n name: 'Null loader',\n id: 'null',\n module: 'core',\n version: VERSION,\n worker: true,\n mimeTypes: ['application/x.empty'],\n extensions: ['null'],\n tests: [() => false],\n options: {\n null: {}\n }\n};\n\n/**\n * Returns arguments passed to the parse API in a format that can be transfered to a\n * web worker. The `context` parameter is stripped using JSON.stringify & parse.\n */\nfunction parseSync(arrayBuffer, options, context) {\n if (!options.null.echoParameters) return null;\n context = context && JSON.parse(JSON.stringify(context));\n return {arrayBuffer, options, context};\n}\n\n/**\n * Loads any data and returns null (or optionally passes through data unparsed)\n */\nexport const NullLoader: LoaderWithParser = {\n name: 'Null loader',\n id: 'null',\n module: 'core',\n version: VERSION,\n mimeTypes: ['application/x.empty'],\n extensions: ['null'],\n parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options, context),\n parseSync,\n parseInBatches: async function* generator(asyncIterator, options, context) {\n for await (const batch of asyncIterator) {\n yield parseSync(batch, options, context);\n }\n },\n tests: [() => false],\n options: {\n null: {\n echoParameters: false\n }\n }\n};\n"],"mappings":";AAEA,MAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"null-loader.js","names":["VERSION","NullWorkerLoader","name","id","module","version","worker","mimeTypes","extensions","tests","options","null","parseSync","arrayBuffer","context","echoParameters","JSON","parse","stringify","NullLoader","parseInBatches","generator","asyncIterator","batch"],"sources":["../../src/null-loader.ts"],"sourcesContent":["// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nimport {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\n\n/**\n * Loads any data and returns null (or optionally passes through data unparsed)\n */\nexport const NullWorkerLoader: Loader = {\n name: 'Null loader',\n id: 'null',\n module: 'core',\n version: VERSION,\n worker: true,\n mimeTypes: ['application/x.empty'],\n extensions: ['null'],\n tests: [() => false],\n options: {\n null: {}\n }\n};\n\n/**\n * Returns arguments passed to the parse API in a format that can be transfered to a\n * web worker. The `context` parameter is stripped using JSON.stringify & parse.\n */\nfunction parseSync(arrayBuffer, options, context) {\n if (!options.null.echoParameters) return null;\n context = context && JSON.parse(JSON.stringify(context));\n return {arrayBuffer, options, context};\n}\n\n/**\n * Loads any data and returns null (or optionally passes through data unparsed)\n */\nexport const NullLoader: LoaderWithParser = {\n name: 'Null loader',\n id: 'null',\n module: 'core',\n version: VERSION,\n mimeTypes: ['application/x.empty'],\n extensions: ['null'],\n parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options, context),\n parseSync,\n parseInBatches: async function* generator(asyncIterator, options, context) {\n for await (const batch of asyncIterator) {\n yield parseSync(batch, options, context);\n }\n },\n tests: [() => false],\n options: {\n null: {\n echoParameters: false\n }\n }\n};\n"],"mappings":";AAEA,MAAMA,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAO3E,OAAO,MAAMC,gBAAwB,GAAG;EACtCC,IAAI,EAAE,aAAa;EACnBC,EAAE,EAAE,MAAM;EACVC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,SAAS,EAAE,CAAC,qBAAqB,CAAC;EAClCC,UAAU,EAAE,CAAC,MAAM,CAAC;EACpBC,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC;EACpBC,OAAO,EAAE;IACPC,IAAI,EAAE,CAAC;EACT;AACF,CAAC;;AAMD,SAASC,SAAS,CAACC,WAAW,EAAEH,OAAO,EAAEI,OAAO,EAAE;EAChD,IAAI,CAACJ,OAAO,CAACC,IAAI,CAACI,cAAc,EAAE,OAAO,IAAI;EAC7CD,OAAO,GAAGA,OAAO,IAAIE,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,SAAS,CAACJ,OAAO,CAAC,CAAC;EACxD,OAAO;IAACD,WAAW;IAAEH,OAAO;IAAEI;EAAO,CAAC;AACxC;;AAKA,OAAO,MAAMK,UAA4B,GAAG;EAC1CjB,IAAI,EAAE,aAAa;EACnBC,EAAE,EAAE,MAAM;EACVC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAChBO,SAAS,EAAE,CAAC,qBAAqB,CAAC;EAClCC,UAAU,EAAE,CAAC,MAAM,CAAC;EACpBS,KAAK,EAAE,OAAOJ,WAAW,EAAEH,OAAO,EAAEI,OAAO,KAAKF,SAAS,CAACC,WAAW,EAAEH,OAAO,EAAEI,OAAO,CAAC;EACxFF,SAAS;EACTQ,cAAc,EAAE,gBAAgBC,SAAS,CAACC,aAAa,EAAEZ,OAAO,EAAEI,OAAO,EAAE;IACzE,WAAW,MAAMS,KAAK,IAAID,aAAa,EAAE;MACvC,MAAMV,SAAS,CAACW,KAAK,EAAEb,OAAO,EAAEI,OAAO,CAAC;IAC1C;EACF,CAAC;EACDL,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC;EACpBC,OAAO,EAAE;IACPC,IAAI,EAAE;MACJI,cAAc,EAAE;IAClB;EACF;AACF,CAAC"}
|
package/dist/lib/api/encode.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Writer,
|
|
1
|
+
import { Writer, WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
/**
|
|
3
3
|
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
4
4
|
*/
|
|
5
|
-
export declare function encode(data: any, writer: Writer, options?:
|
|
5
|
+
export declare function encode(data: any, writer: Writer, options?: WriterOptions): Promise<ArrayBuffer>;
|
|
6
6
|
/**
|
|
7
7
|
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
8
8
|
*/
|
|
9
|
-
export declare function encodeSync(data: any, writer: Writer, options?:
|
|
9
|
+
export declare function encodeSync(data: any, writer: Writer, options?: WriterOptions): ArrayBuffer;
|
|
10
10
|
/**
|
|
11
11
|
* Encode loaded data to text using the specified Writer
|
|
12
12
|
* @note This is a convenience function not intended for production use on large input data.
|
|
13
13
|
* It is not optimized for performance. Data maybe converted from text to binary and back.
|
|
14
14
|
* @throws if the writer does not generate text output
|
|
15
15
|
*/
|
|
16
|
-
export declare function encodeText(data: any, writer: Writer, options?:
|
|
16
|
+
export declare function encodeText(data: any, writer: Writer, options?: WriterOptions): Promise<string>;
|
|
17
17
|
/**
|
|
18
18
|
* Encode loaded data into a sequence (iterator) of binary ArrayBuffers using the specified Writer.
|
|
19
19
|
*/
|
|
20
|
-
export declare function encodeInBatches(data: any, writer: Writer, options?:
|
|
20
|
+
export declare function encodeInBatches(data: any, writer: Writer, options?: WriterOptions): AsyncIterable<ArrayBuffer>;
|
|
21
21
|
/**
|
|
22
22
|
* Encode data stored in a file (on disk) to another file.
|
|
23
23
|
* @note Node.js only. This function enables using command-line converters as "writers".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/lib/api/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,aAAa,EAAsB,MAAM,0BAA0B,CAAC;AAQpF;;GAEG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/lib/api/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,aAAa,EAAsB,MAAM,0BAA0B,CAAC;AAQpF;;GAEG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,WAAW,CAAC,CAsDtB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,WAAW,CAK1F;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACtB,aAAa,CAAC,WAAW,CAAC,CAO5B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,QAAQ,KAAA,EACR,SAAS,KAAA,EACT,MAAM,EAAE,MAAM,EACd,OAAO,KAAA,GACN,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
package/dist/lib/api/encode.js
CHANGED
|
@@ -13,6 +13,7 @@ const loader_options_1 = require("./loader-options");
|
|
|
13
13
|
*/
|
|
14
14
|
async function encode(data, writer, options) {
|
|
15
15
|
const globalOptions = (0, loader_options_1.getLoaderOptions)();
|
|
16
|
+
// const globalOptions: WriterOptions = {}; // getWriterOptions();
|
|
16
17
|
options = { ...globalOptions, ...options };
|
|
17
18
|
if ((0, loader_utils_1.canEncodeWithWorker)(writer, options)) {
|
|
18
19
|
return await (0, worker_utils_1.processOnWorker)(writer, data, options);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadInBatches = void 0;
|
|
4
4
|
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
5
|
-
const
|
|
5
|
+
const get_fetch_function_1 = require("../loader-utils/get-fetch-function");
|
|
6
6
|
const parse_in_batches_1 = require("./parse-in-batches");
|
|
7
7
|
function loadInBatches(files, loaders, options, context) {
|
|
8
8
|
// Signature: load(url, options)
|
|
@@ -12,7 +12,7 @@ function loadInBatches(files, loaders, options, context) {
|
|
|
12
12
|
loaders = null;
|
|
13
13
|
}
|
|
14
14
|
// Select fetch function
|
|
15
|
-
const fetch = (0,
|
|
15
|
+
const fetch = (0, get_fetch_function_1.getFetchFunction)(options || {});
|
|
16
16
|
// Single url/file
|
|
17
17
|
if (!Array.isArray(files)) {
|
|
18
18
|
return loadOneFileInBatches(files, loaders, options, fetch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/lib/api/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAO7F;;;;;;;;GAQG;AAEH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,GAAG,QAAQ,EACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/lib/api/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAO7F;;;;;;;;GAQG;AAEH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,GAAG,QAAQ,EACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,GAAG,CAAC,CA2Bd"}
|
package/dist/lib/api/load.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.load = void 0;
|
|
4
4
|
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
5
|
const normalize_loader_1 = require("../loader-utils/normalize-loader");
|
|
6
|
-
const
|
|
6
|
+
const get_fetch_function_1 = require("../loader-utils/get-fetch-function");
|
|
7
7
|
const parse_1 = require("./parse");
|
|
8
8
|
/**
|
|
9
9
|
* Parses `data` using a specified loader
|
|
@@ -23,7 +23,7 @@ async function load(url, loaders, options, context) {
|
|
|
23
23
|
loaders = undefined;
|
|
24
24
|
}
|
|
25
25
|
// Select fetch function
|
|
26
|
-
const fetch = (0,
|
|
26
|
+
const fetch = (0, get_fetch_function_1.getFetchFunction)(options);
|
|
27
27
|
// at this point, `url` could be already loaded binary data
|
|
28
28
|
let data = url;
|
|
29
29
|
// url is a string, fetch the url
|
|
@@ -33,6 +33,7 @@ async function load(url, loaders, options, context) {
|
|
|
33
33
|
}
|
|
34
34
|
if ((0, is_type_1.isBlob)(url)) {
|
|
35
35
|
// The fetch response object will contain blob.name
|
|
36
|
+
// @ts-expect-error TODO - This may not work for overridden fetch functions
|
|
36
37
|
data = await fetch(url);
|
|
37
38
|
}
|
|
38
39
|
// Data is loaded (at least we have a `Response` object) so time to hand over to `parse`
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LoaderContext, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { fetchFile } from '../fetch/fetch-file';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the current fetch function from options and context
|
|
5
|
+
* @param options
|
|
6
|
+
* @param context
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFetchFunction(options?: LoaderOptions, context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>): ((url: string, options?: RequestInit | undefined) => Promise<Response>) | typeof fetchFile;
|
|
9
|
+
//# sourceMappingURL=get-fetch-function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-fetch-function.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/get-fetch-function.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAG9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,8FAuB/E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getFetchFunction = void 0;
|
|
5
|
+
const is_type_1 = require("../../javascript-utils/is-type");
|
|
6
|
+
const fetch_file_1 = require("../fetch/fetch-file");
|
|
7
|
+
const option_utils_1 = require("./option-utils");
|
|
8
|
+
/**
|
|
9
|
+
* Gets the current fetch function from options and context
|
|
10
|
+
* @param options
|
|
11
|
+
* @param context
|
|
12
|
+
*/
|
|
13
|
+
function getFetchFunction(options, context) {
|
|
14
|
+
const globalOptions = (0, option_utils_1.getGlobalLoaderOptions)();
|
|
15
|
+
const fetchOptions = options || globalOptions;
|
|
16
|
+
// options.fetch can be a function
|
|
17
|
+
if (typeof fetchOptions.fetch === 'function') {
|
|
18
|
+
return fetchOptions.fetch;
|
|
19
|
+
}
|
|
20
|
+
// options.fetch can be an options object
|
|
21
|
+
if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
|
|
22
|
+
return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
|
|
23
|
+
}
|
|
24
|
+
// else refer to context (from parent loader) if available
|
|
25
|
+
if (context?.fetch) {
|
|
26
|
+
return context?.fetch;
|
|
27
|
+
}
|
|
28
|
+
// else return the default fetch function
|
|
29
|
+
return fetch_file_1.fetchFile;
|
|
30
|
+
}
|
|
31
|
+
exports.getFetchFunction = getFetchFunction;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLoadersFromContext = exports.getLoaderContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const get_fetch_function_1 = require("./get-fetch-function");
|
|
5
5
|
/**
|
|
6
6
|
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
7
7
|
* The context will inject core methods like `parse` and contain information
|
|
@@ -18,7 +18,7 @@ function getLoaderContext(context, options, previousContext = null) {
|
|
|
18
18
|
return previousContext;
|
|
19
19
|
}
|
|
20
20
|
const resolvedContext = {
|
|
21
|
-
fetch: (0,
|
|
21
|
+
fetch: (0, get_fetch_function_1.getFetchFunction)(options, context),
|
|
22
22
|
...context
|
|
23
23
|
};
|
|
24
24
|
// Recursive loading does not use single loader
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { Loader,
|
|
1
|
+
import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
/**
|
|
3
3
|
* Global state for loaders.gl. Stored on `global.loaders._state`
|
|
4
4
|
*/
|
|
5
5
|
type GlobalLoaderState = {
|
|
6
6
|
loaderRegistry: Loader[];
|
|
7
|
-
globalOptions:
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
};
|
|
7
|
+
globalOptions: LoaderOptions;
|
|
10
8
|
};
|
|
11
9
|
/**
|
|
12
10
|
* Helper for safely accessing global loaders.gl variables
|
|
@@ -18,14 +16,12 @@ export declare function getGlobalLoaderState(): GlobalLoaderState;
|
|
|
18
16
|
* NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
|
|
19
17
|
* @returns global loader options merged with default loader options
|
|
20
18
|
*/
|
|
21
|
-
export declare const getGlobalLoaderOptions: () =>
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
19
|
+
export declare const getGlobalLoaderOptions: () => LoaderOptions;
|
|
24
20
|
/**
|
|
25
21
|
* Set global loader options
|
|
26
22
|
* @param options
|
|
27
23
|
*/
|
|
28
|
-
export declare function setGlobalOptions(options:
|
|
24
|
+
export declare function setGlobalOptions(options: LoaderOptions): void;
|
|
29
25
|
/**
|
|
30
26
|
* Merges options with global opts and loader defaults, also injects baseUri
|
|
31
27
|
* @param options
|
|
@@ -33,12 +29,6 @@ export declare function setGlobalOptions(options: object): void;
|
|
|
33
29
|
* @param loaders
|
|
34
30
|
* @param url
|
|
35
31
|
*/
|
|
36
|
-
export declare function normalizeOptions(options:
|
|
37
|
-
/**
|
|
38
|
-
* Gets the current fetch function from options and context
|
|
39
|
-
* @param options
|
|
40
|
-
* @param context
|
|
41
|
-
*/
|
|
42
|
-
export declare function getFetchFunction(options?: LoaderOptions, context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>): any;
|
|
32
|
+
export declare function normalizeOptions(options: LoaderOptions, loader: Loader, loaders?: Loader[], url?: string): LoaderOptions;
|
|
43
33
|
export {};
|
|
44
34
|
//# sourceMappingURL=option-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"option-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/option-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKpE;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CASxD;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAO,aAKzC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAI7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,aAAa,CAMf"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
+
exports.normalizeOptions = exports.setGlobalOptions = exports.getGlobalLoaderOptions = exports.getGlobalLoaderState = void 0;
|
|
4
5
|
const is_type_1 = require("../../javascript-utils/is-type");
|
|
5
|
-
const fetch_file_1 = require("../fetch/fetch-file");
|
|
6
6
|
const loggers_1 = require("./loggers");
|
|
7
7
|
const option_defaults_1 = require("./option-defaults");
|
|
8
8
|
/**
|
|
@@ -55,30 +55,6 @@ function normalizeOptions(options, loader, loaders, url) {
|
|
|
55
55
|
return normalizeOptionsInternal(loader, options, url);
|
|
56
56
|
}
|
|
57
57
|
exports.normalizeOptions = normalizeOptions;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the current fetch function from options and context
|
|
60
|
-
* @param options
|
|
61
|
-
* @param context
|
|
62
|
-
*/
|
|
63
|
-
function getFetchFunction(options, context) {
|
|
64
|
-
const globalOptions = (0, exports.getGlobalLoaderOptions)();
|
|
65
|
-
const fetchOptions = options || globalOptions;
|
|
66
|
-
// options.fetch can be a function
|
|
67
|
-
if (typeof fetchOptions.fetch === 'function') {
|
|
68
|
-
return fetchOptions.fetch;
|
|
69
|
-
}
|
|
70
|
-
// options.fetch can be an options object
|
|
71
|
-
if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
|
|
72
|
-
return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
|
|
73
|
-
}
|
|
74
|
-
// else refer to context (from parent loader) if available
|
|
75
|
-
if (context?.fetch) {
|
|
76
|
-
return context?.fetch;
|
|
77
|
-
}
|
|
78
|
-
// else return the default fetch function
|
|
79
|
-
return fetch_file_1.fetchFile;
|
|
80
|
-
}
|
|
81
|
-
exports.getFetchFunction = getFetchFunction;
|
|
82
58
|
// VALIDATE OPTIONS
|
|
83
59
|
/**
|
|
84
60
|
* Warn for unsupported options
|
|
@@ -169,11 +145,14 @@ function mergeNestedFields(mergedOptions, options) {
|
|
|
169
145
|
// else: No need to merge nested opts, and the initial merge already copied over the nested options
|
|
170
146
|
}
|
|
171
147
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Harvest information from the url
|
|
150
|
+
* @deprecated This is mainly there to support a hack in the GLTFLoader
|
|
151
|
+
* TODO - baseUri should be a directory, i.e. remove file component from baseUri
|
|
152
|
+
* TODO - extract extension?
|
|
153
|
+
* TODO - extract query parameters?
|
|
154
|
+
* TODO - should these be injected on context instead of options?
|
|
155
|
+
*/
|
|
177
156
|
function addUrlOptions(options, url) {
|
|
178
157
|
if (url && !('baseUri' in options)) {
|
|
179
158
|
options.baseUri = url;
|
package/dist/null-worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-alpha.2",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.3.1",
|
|
45
|
-
"@loaders.gl/loader-utils": "3.
|
|
46
|
-
"@loaders.gl/worker-utils": "3.
|
|
47
|
-
"@probe.gl/log": "^
|
|
45
|
+
"@loaders.gl/loader-utils": "3.4.0-alpha.2",
|
|
46
|
+
"@loaders.gl/worker-utils": "3.4.0-alpha.2",
|
|
47
|
+
"@probe.gl/log": "^4.0.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f1c00c124d8d0c41a138ff40afb0d1a00711bf2e"
|
|
50
50
|
}
|
package/src/lib/api/encode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Writer,
|
|
1
|
+
import {Writer, WriterOptions, canEncodeWithWorker} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {processOnWorker} from '@loaders.gl/worker-utils';
|
|
3
3
|
import {concatenateArrayBuffers, resolvePath} from '@loaders.gl/loader-utils';
|
|
4
4
|
import {isBrowser} from '@loaders.gl/loader-utils';
|
|
@@ -12,9 +12,10 @@ import {getLoaderOptions} from './loader-options';
|
|
|
12
12
|
export async function encode(
|
|
13
13
|
data: any,
|
|
14
14
|
writer: Writer,
|
|
15
|
-
options?:
|
|
15
|
+
options?: WriterOptions
|
|
16
16
|
): Promise<ArrayBuffer> {
|
|
17
|
-
const globalOptions = getLoaderOptions();
|
|
17
|
+
const globalOptions = getLoaderOptions() as WriterOptions;
|
|
18
|
+
// const globalOptions: WriterOptions = {}; // getWriterOptions();
|
|
18
19
|
options = {...globalOptions, ...options};
|
|
19
20
|
if (canEncodeWithWorker(writer, options)) {
|
|
20
21
|
return await processOnWorker(writer, data, options);
|
|
@@ -71,7 +72,7 @@ export async function encode(
|
|
|
71
72
|
/**
|
|
72
73
|
* Encode loaded data into a binary ArrayBuffer using the specified Writer.
|
|
73
74
|
*/
|
|
74
|
-
export function encodeSync(data: any, writer: Writer, options?:
|
|
75
|
+
export function encodeSync(data: any, writer: Writer, options?: WriterOptions): ArrayBuffer {
|
|
75
76
|
if (writer.encodeSync) {
|
|
76
77
|
return writer.encodeSync(data, options);
|
|
77
78
|
}
|
|
@@ -87,7 +88,7 @@ export function encodeSync(data: any, writer: Writer, options?: LoaderOptions):
|
|
|
87
88
|
export async function encodeText(
|
|
88
89
|
data: any,
|
|
89
90
|
writer: Writer,
|
|
90
|
-
options?:
|
|
91
|
+
options?: WriterOptions
|
|
91
92
|
): Promise<string> {
|
|
92
93
|
if (writer.text && writer.encodeText) {
|
|
93
94
|
return await writer.encodeText(data, options);
|
|
@@ -107,7 +108,7 @@ export async function encodeText(
|
|
|
107
108
|
export function encodeInBatches(
|
|
108
109
|
data: any,
|
|
109
110
|
writer: Writer,
|
|
110
|
-
options?:
|
|
111
|
+
options?: WriterOptions
|
|
111
112
|
): AsyncIterable<ArrayBuffer> {
|
|
112
113
|
if (writer.encodeInBatches) {
|
|
113
114
|
const dataIterator = getIterator(data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {LoaderWithParser, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
3
|
-
import {getFetchFunction} from '../loader-utils/
|
|
3
|
+
import {getFetchFunction} from '../loader-utils/get-fetch-function';
|
|
4
4
|
|
|
5
5
|
import {parseInBatches} from './parse-in-batches';
|
|
6
6
|
|
package/src/lib/api/load.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {DataType, Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {isBlob} from '../../javascript-utils/is-type';
|
|
3
3
|
import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
4
|
-
import {getFetchFunction} from '../loader-utils/
|
|
4
|
+
import {getFetchFunction} from '../loader-utils/get-fetch-function';
|
|
5
5
|
|
|
6
6
|
import {parse} from './parse';
|
|
7
7
|
|
|
@@ -41,9 +41,10 @@ export async function load(
|
|
|
41
41
|
|
|
42
42
|
if (isBlob(url)) {
|
|
43
43
|
// The fetch response object will contain blob.name
|
|
44
|
+
// @ts-expect-error TODO - This may not work for overridden fetch functions
|
|
44
45
|
data = await fetch(url);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
// Data is loaded (at least we have a `Response` object) so time to hand over to `parse`
|
|
48
|
-
return await parse(data, loaders, options);
|
|
49
|
+
return await parse(data, loaders as Loader[], options);
|
|
49
50
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
4
|
+
import {isObject} from '../../javascript-utils/is-type';
|
|
5
|
+
import {fetchFile} from '../fetch/fetch-file';
|
|
6
|
+
import {getGlobalLoaderOptions} from './option-utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the current fetch function from options and context
|
|
10
|
+
* @param options
|
|
11
|
+
* @param context
|
|
12
|
+
*/
|
|
13
|
+
export function getFetchFunction(
|
|
14
|
+
options?: LoaderOptions,
|
|
15
|
+
context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>
|
|
16
|
+
) {
|
|
17
|
+
const globalOptions = getGlobalLoaderOptions();
|
|
18
|
+
|
|
19
|
+
const fetchOptions = options || globalOptions;
|
|
20
|
+
|
|
21
|
+
// options.fetch can be a function
|
|
22
|
+
if (typeof fetchOptions.fetch === 'function') {
|
|
23
|
+
return fetchOptions.fetch;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// options.fetch can be an options object
|
|
27
|
+
if (isObject(fetchOptions.fetch)) {
|
|
28
|
+
return (url) => fetchFile(url, fetchOptions as RequestInit);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// else refer to context (from parent loader) if available
|
|
32
|
+
if (context?.fetch) {
|
|
33
|
+
return context?.fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// else return the default fetch function
|
|
37
|
+
return fetchFile;
|
|
38
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {Loader, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
|
-
import {getFetchFunction} from './
|
|
2
|
+
import {getFetchFunction} from './get-fetch-function';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|