@loaders.gl/loader-utils 4.0.0-alpha.9 → 4.0.0-beta.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/es5/index.js +63 -2
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/json-loader.js +1 -1
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/file-provider/data-view-file.js +146 -0
- package/dist/es5/lib/file-provider/data-view-file.js.map +1 -0
- package/dist/es5/lib/file-provider/file-handle-file.js +236 -0
- package/dist/es5/lib/file-provider/file-handle-file.js.map +1 -0
- package/dist/es5/lib/file-provider/file-handle.js +98 -0
- package/dist/es5/lib/file-provider/file-handle.js.map +1 -0
- package/dist/es5/lib/file-provider/file-provider.js +11 -0
- package/dist/es5/lib/file-provider/file-provider.js.map +1 -0
- package/dist/es5/lib/filesystems/filesystem.js +2 -0
- package/dist/es5/lib/filesystems/filesystem.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +28 -62
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/es5/lib/node/fs.browser.js +9 -0
- package/dist/es5/lib/node/fs.browser.js.map +1 -0
- package/dist/es5/lib/node/fs.js +28 -34
- package/dist/es5/lib/node/fs.js.map +1 -1
- package/dist/es5/lib/node/stream.browser.js +9 -0
- package/dist/es5/lib/node/stream.browser.js.map +1 -0
- package/dist/es5/lib/node/stream.js +6 -7
- package/dist/es5/lib/node/stream.js.map +1 -1
- package/dist/es5/lib/option-utils/merge-loader-options.js +1 -1
- package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -1
- package/dist/es5/lib/sources/data-source.js +67 -0
- package/dist/es5/lib/sources/data-source.js.map +1 -0
- package/dist/es5/lib/sources/image-source.js +31 -0
- package/dist/es5/lib/sources/image-source.js.map +1 -0
- package/dist/es5/lib/sources/image-tile-source.js +2 -0
- package/dist/es5/lib/sources/image-tile-source.js.map +1 -0
- package/dist/es5/lib/sources/tile-source.js +2 -0
- package/dist/es5/lib/sources/tile-source.js.map +1 -0
- package/dist/es5/lib/sources/utils/image-type.js +2 -0
- package/dist/es5/lib/sources/utils/image-type.js.map +1 -0
- package/dist/es5/lib/sources/utils/utils.js +36 -0
- package/dist/es5/lib/sources/utils/utils.js.map +1 -0
- package/dist/es5/lib/sources/vector-tile-source.js +2 -0
- package/dist/es5/lib/sources/vector-tile-source.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +2 -2
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/es5/loader-types.js +58 -0
- package/dist/es5/loader-types.js.map +1 -0
- package/dist/es5/service-types.js +2 -0
- package/dist/es5/service-types.js.map +1 -0
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/writer-types.js +2 -0
- package/dist/es5/writer-types.js.map +1 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/json-loader.js.map +1 -1
- package/dist/esm/lib/file-provider/data-view-file.js +33 -0
- package/dist/esm/lib/file-provider/data-view-file.js.map +1 -0
- package/dist/esm/lib/file-provider/file-handle-file.js +59 -0
- package/dist/esm/lib/file-provider/file-handle-file.js.map +1 -0
- package/dist/esm/lib/file-provider/file-handle.js +33 -0
- package/dist/esm/lib/file-provider/file-handle.js.map +1 -0
- package/dist/esm/lib/file-provider/file-provider.js +4 -0
- package/dist/esm/lib/file-provider/file-provider.js.map +1 -0
- package/dist/esm/lib/filesystems/filesystem.js +2 -0
- package/dist/esm/lib/filesystems/filesystem.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js +18 -25
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/esm/lib/node/fs.browser.js +2 -0
- package/dist/esm/lib/node/fs.browser.js.map +1 -0
- package/dist/esm/lib/node/fs.js +16 -27
- package/dist/esm/lib/node/fs.js.map +1 -1
- package/dist/esm/lib/node/stream.browser.js +2 -0
- package/dist/esm/lib/node/stream.browser.js.map +1 -0
- package/dist/esm/lib/node/stream.js +2 -5
- package/dist/esm/lib/node/stream.js.map +1 -1
- package/dist/esm/lib/option-utils/merge-loader-options.js +1 -1
- package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -1
- package/dist/esm/lib/sources/data-source.js +43 -0
- package/dist/esm/lib/sources/data-source.js.map +1 -0
- package/dist/esm/lib/sources/image-source.js +6 -0
- package/dist/esm/lib/sources/image-source.js.map +1 -0
- package/dist/esm/lib/sources/image-tile-source.js +2 -0
- package/dist/esm/lib/sources/image-tile-source.js.map +1 -0
- package/dist/esm/lib/sources/tile-source.js +2 -0
- package/dist/esm/lib/sources/tile-source.js.map +1 -0
- package/dist/esm/lib/sources/utils/image-type.js +2 -0
- package/dist/esm/lib/sources/utils/image-type.js.map +1 -0
- package/dist/esm/lib/sources/utils/utils.js +21 -0
- package/dist/esm/lib/sources/utils/utils.js.map +1 -0
- package/dist/esm/lib/sources/vector-tile-source.js +2 -0
- package/dist/esm/lib/sources/vector-tile-source.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +2 -2
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/esm/loader-types.js +16 -0
- package/dist/esm/loader-types.js.map +1 -0
- package/dist/esm/service-types.js +2 -0
- package/dist/esm/service-types.js.map +1 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/writer-types.js +2 -0
- package/dist/esm/writer-types.js.map +1 -0
- package/dist/index.d.ts +22 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/json-loader.d.ts +1 -1
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/lib/file-provider/data-view-file.d.ts +37 -0
- package/dist/lib/file-provider/data-view-file.d.ts.map +1 -0
- package/dist/lib/file-provider/file-handle-file.d.ts +53 -0
- package/dist/lib/file-provider/file-handle-file.d.ts.map +1 -0
- package/dist/lib/file-provider/file-handle.d.ts +40 -0
- package/dist/lib/file-provider/file-handle.d.ts.map +1 -0
- package/dist/lib/file-provider/file-provider.d.ts +45 -0
- package/dist/lib/file-provider/file-provider.d.ts.map +1 -0
- package/dist/lib/filesystems/filesystem.d.ts +80 -0
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/node-filesystem.d.ts +4 -4
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/lib/node/fs.browser.d.ts +2 -0
- package/dist/lib/node/fs.browser.d.ts.map +1 -0
- package/dist/lib/node/fs.d.ts +19 -14
- package/dist/lib/node/fs.d.ts.map +1 -1
- package/dist/lib/node/stream.browser.d.ts +2 -0
- package/dist/lib/node/stream.browser.d.ts.map +1 -0
- package/dist/lib/node/stream.d.ts +4 -1
- package/dist/lib/node/stream.d.ts.map +1 -1
- package/dist/lib/option-utils/merge-loader-options.d.ts +1 -1
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -1
- package/dist/lib/sources/data-source.d.ts +33 -0
- package/dist/lib/sources/data-source.d.ts.map +1 -0
- package/dist/lib/sources/image-source.d.ts +81 -0
- package/dist/lib/sources/image-source.d.ts.map +1 -0
- package/dist/lib/sources/image-tile-source.d.ts +11 -0
- package/dist/lib/sources/image-tile-source.d.ts.map +1 -0
- package/dist/lib/sources/tile-source.d.ts +105 -0
- package/dist/lib/sources/tile-source.d.ts.map +1 -0
- package/dist/lib/sources/utils/image-type.d.ts +10 -0
- package/dist/lib/sources/utils/image-type.d.ts.map +1 -0
- package/dist/lib/sources/utils/utils.d.ts +13 -0
- package/dist/lib/sources/utils/utils.d.ts.map +1 -0
- package/dist/lib/sources/vector-tile-source.d.ts +10 -0
- package/dist/lib/sources/vector-tile-source.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +1 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +1 -1
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +2 -2
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/loader-types.d.ts +209 -0
- package/dist/loader-types.d.ts.map +1 -0
- package/dist/service-types.d.ts +10 -0
- package/dist/service-types.d.ts.map +1 -0
- package/dist/types.d.ts +1 -240
- package/dist/types.d.ts.map +1 -1
- package/dist/writer-types.d.ts +34 -0
- package/dist/writer-types.d.ts.map +1 -0
- package/package.json +9 -5
- package/src/index.ts +57 -17
- package/src/json-loader.ts +1 -1
- package/src/lib/file-provider/data-view-file.ts +72 -0
- package/src/lib/file-provider/file-handle-file.ts +116 -0
- package/src/lib/file-provider/file-handle.ts +79 -0
- package/src/lib/file-provider/file-provider.ts +56 -0
- package/src/lib/filesystems/filesystem.ts +87 -0
- package/src/lib/filesystems/node-filesystem.ts +19 -31
- package/src/lib/node/fs.browser.ts +1 -0
- package/src/lib/node/fs.ts +20 -50
- package/src/lib/node/stream.browser.ts +1 -0
- package/src/lib/node/stream.ts +3 -11
- package/src/lib/option-utils/merge-loader-options.ts +2 -2
- package/src/lib/sources/data-source.ts +74 -0
- package/src/lib/sources/image-source.ts +95 -0
- package/src/lib/sources/image-tile-source.ts +14 -0
- package/src/lib/sources/tile-source.ts +101 -0
- package/src/lib/sources/utils/image-type.ts +10 -0
- package/src/lib/sources/utils/utils.ts +42 -0
- package/src/lib/sources/vector-tile-source.ts +13 -0
- package/src/lib/worker-loader-utils/create-loader-worker.ts +20 -4
- package/src/lib/worker-loader-utils/encode-with-worker.ts +1 -1
- package/src/lib/worker-loader-utils/parse-with-worker.ts +2 -2
- package/src/loader-types.ts +367 -0
- package/src/service-types.ts +12 -0
- package/src/types.ts +2 -351
- package/src/writer-types.ts +56 -0
- package/dist/index.js +0 -122
- package/dist/json-loader.js +0 -27
- package/dist/lib/binary-utils/array-buffer-utils.js +0 -84
- package/dist/lib/binary-utils/dataview-copy-utils.js +0 -97
- package/dist/lib/binary-utils/get-first-characters.js +0 -45
- package/dist/lib/binary-utils/memory-conversion-utils.js +0 -73
- package/dist/lib/binary-utils/memory-copy-utils.js +0 -61
- package/dist/lib/env-utils/assert.js +0 -13
- package/dist/lib/env-utils/globals.js +0 -30
- package/dist/lib/filesystems/node-filesystem.js +0 -73
- package/dist/lib/filesystems/readable-file.js +0 -25
- package/dist/lib/filesystems/writable-file.js +0 -48
- package/dist/lib/iterators/async-iteration.js +0 -53
- package/dist/lib/iterators/text-iterators.js +0 -61
- package/dist/lib/node/buffer.browser.js +0 -22
- package/dist/lib/node/buffer.js +0 -36
- package/dist/lib/node/fs.js +0 -49
- package/dist/lib/node/promisify.js +0 -22
- package/dist/lib/node/stream.js +0 -17
- package/dist/lib/option-utils/merge-loader-options.js +0 -27
- package/dist/lib/parser-utils/parse-json.js +0 -16
- package/dist/lib/path-utils/file-aliases.js +0 -47
- package/dist/lib/path-utils/get-cwd.js +0 -12
- package/dist/lib/path-utils/path.js +0 -178
- package/dist/lib/request-utils/request-scheduler.js +0 -142
- package/dist/lib/worker-loader-utils/create-loader-worker.js +0 -98
- package/dist/lib/worker-loader-utils/encode-with-worker.js +0 -21
- package/dist/lib/worker-loader-utils/parse-with-worker.js +0 -81
- package/dist/types.js +0 -3
- package/dist/workers/json-worker.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-loader.js","names":["VERSION","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parseTextSync","parse","arrayBuffer","TextDecoder","decode","options","JSON"],"sources":["../../src/json-loader.ts"],"sourcesContent":["import type {LoaderWithParser, LoaderOptions} from './types';\nimport type {Table, TableBatch} from '@loaders.gl/schema';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type JSONLoaderOptions = LoaderOptions;\n\n/**\n * A JSON Micro loader (minimal bundle size)\n * Alternative to `@loaders.gl/json`\n */\nexport const JSONLoader: LoaderWithParser<Table, TableBatch, JSONLoaderOptions> = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n category: 'json',\n text: true,\n parseTextSync,\n parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),\n options: {}\n};\n\n// TODO - deprecated\nfunction parseTextSync(text) {\n return JSON.parse(text);\n}\n"],"mappings":"AAKA,MAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"json-loader.js","names":["VERSION","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parseTextSync","parse","arrayBuffer","TextDecoder","decode","options","JSON"],"sources":["../../src/json-loader.ts"],"sourcesContent":["import type {LoaderWithParser, LoaderOptions} from './loader-types';\nimport type {Table, TableBatch} from '@loaders.gl/schema';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type JSONLoaderOptions = LoaderOptions;\n\n/**\n * A JSON Micro loader (minimal bundle size)\n * Alternative to `@loaders.gl/json`\n */\nexport const JSONLoader: LoaderWithParser<Table, TableBatch, JSONLoaderOptions> = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n category: 'json',\n text: true,\n parseTextSync,\n parse: async (arrayBuffer) => parseTextSync(new TextDecoder().decode(arrayBuffer)),\n options: {}\n};\n\n// TODO - deprecated\nfunction parseTextSync(text) {\n return JSON.parse(text);\n}\n"],"mappings":"AAKA,MAAMA,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAQ3E,OAAO,MAAMC,UAAkE,GAAG;EAChFC,IAAI,EAAE,MAAM;EACZC,EAAE,EAAE,MAAM;EACVC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;EAC/BC,SAAS,EAAE,CAAC,kBAAkB,CAAC;EAC/BC,QAAQ,EAAE,MAAM;EAChBC,IAAI,EAAE,IAAI;EACVC,aAAa;EACbC,KAAK,EAAE,MAAOC,WAAW,IAAKF,aAAa,CAAC,IAAIG,WAAW,CAAC,CAAC,CAACC,MAAM,CAACF,WAAW,CAAC,CAAC;EAClFG,OAAO,EAAE,CAAC;AACZ,CAAC;AAGD,SAASL,aAAaA,CAACD,IAAI,EAAE;EAC3B,OAAOO,IAAI,CAACL,KAAK,CAACF,IAAI,CAAC;AACzB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
const toNumber = bigint => {
|
|
3
|
+
if (bigint > Number.MAX_SAFE_INTEGER) {
|
|
4
|
+
throw new Error('Offset is out of bounds');
|
|
5
|
+
}
|
|
6
|
+
return Number(bigint);
|
|
7
|
+
};
|
|
8
|
+
export class DataViewFile {
|
|
9
|
+
constructor(file) {
|
|
10
|
+
_defineProperty(this, "file", void 0);
|
|
11
|
+
this.file = file;
|
|
12
|
+
}
|
|
13
|
+
async destroy() {}
|
|
14
|
+
async getUint8(offset) {
|
|
15
|
+
return this.file.getUint8(toNumber(offset));
|
|
16
|
+
}
|
|
17
|
+
async getUint16(offset) {
|
|
18
|
+
return this.file.getUint16(toNumber(offset), true);
|
|
19
|
+
}
|
|
20
|
+
async getUint32(offset) {
|
|
21
|
+
return this.file.getUint32(toNumber(offset), true);
|
|
22
|
+
}
|
|
23
|
+
async getBigUint64(offset) {
|
|
24
|
+
return this.file.getBigUint64(toNumber(offset), true);
|
|
25
|
+
}
|
|
26
|
+
async slice(startOffset, endOffset) {
|
|
27
|
+
return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
|
|
28
|
+
}
|
|
29
|
+
get length() {
|
|
30
|
+
return BigInt(this.file.byteLength);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=data-view-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-view-file.js","names":["toNumber","bigint","Number","MAX_SAFE_INTEGER","Error","DataViewFile","constructor","file","_defineProperty","destroy","getUint8","offset","getUint16","getUint32","getBigUint64","slice","startOffset","endOffset","buffer","length","BigInt","byteLength"],"sources":["../../../../src/lib/file-provider/data-view-file.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\n\n/**\n * Checks if bigint can be converted to number and convert it if possible\n * @param bigint bigint to be converted\n * @returns number\n */\nconst toNumber = (bigint: bigint) => {\n if (bigint > Number.MAX_SAFE_INTEGER) {\n throw new Error('Offset is out of bounds');\n }\n return Number(bigint);\n};\n\n/** Provides file data using DataView */\nexport class DataViewFile implements FileProvider {\n /** The DataView from which data is provided */\n private file: DataView;\n\n constructor(file: DataView) {\n this.file = file;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n async destroy(): Promise<void> {}\n\n /**\n * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint8(offset: bigint): Promise<number> {\n return this.file.getUint8(toNumber(offset));\n }\n\n /**\n * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint16(offset: bigint): Promise<number> {\n return this.file.getUint16(toNumber(offset), true);\n }\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint32(offset: bigint): Promise<number> {\n return this.file.getUint32(toNumber(offset), true);\n }\n\n /**\n * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getBigUint64(offset: bigint): Promise<bigint> {\n return this.file.getBigUint64(toNumber(offset), true);\n }\n\n /**\n * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.\n * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.\n * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.\n */\n async slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer> {\n return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));\n }\n\n /** the length (in bytes) of the data. */\n get length() {\n return BigInt(this.file.byteLength);\n }\n}\n"],"mappings":";AAOA,MAAMA,QAAQ,GAAIC,MAAc,IAAK;EACnC,IAAIA,MAAM,GAAGC,MAAM,CAACC,gBAAgB,EAAE;IACpC,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;EAC5C;EACA,OAAOF,MAAM,CAACD,MAAM,CAAC;AACvB,CAAC;AAGD,OAAO,MAAMI,YAAY,CAAyB;EAIhDC,WAAWA,CAACC,IAAc,EAAE;IAAAC,eAAA;IAC1B,IAAI,CAACD,IAAI,GAAGA,IAAI;EAClB;EAGA,MAAME,OAAOA,CAAA,EAAkB,CAAC;EAMhC,MAAMC,QAAQA,CAACC,MAAc,EAAmB;IAC9C,OAAO,IAAI,CAACJ,IAAI,CAACG,QAAQ,CAACV,QAAQ,CAACW,MAAM,CAAC,CAAC;EAC7C;EAMA,MAAMC,SAASA,CAACD,MAAc,EAAmB;IAC/C,OAAO,IAAI,CAACJ,IAAI,CAACK,SAAS,CAACZ,QAAQ,CAACW,MAAM,CAAC,EAAE,IAAI,CAAC;EACpD;EAMA,MAAME,SAASA,CAACF,MAAc,EAAmB;IAC/C,OAAO,IAAI,CAACJ,IAAI,CAACM,SAAS,CAACb,QAAQ,CAACW,MAAM,CAAC,EAAE,IAAI,CAAC;EACpD;EAMA,MAAMG,YAAYA,CAACH,MAAc,EAAmB;IAClD,OAAO,IAAI,CAACJ,IAAI,CAACO,YAAY,CAACd,QAAQ,CAACW,MAAM,CAAC,EAAE,IAAI,CAAC;EACvD;EAOA,MAAMI,KAAKA,CAACC,WAAmB,EAAEC,SAAiB,EAAwB;IACxE,OAAO,IAAI,CAACV,IAAI,CAACW,MAAM,CAACH,KAAK,CAACf,QAAQ,CAACgB,WAAW,CAAC,EAAEhB,QAAQ,CAACiB,SAAS,CAAC,CAAC;EAC3E;EAGA,IAAIE,MAAMA,CAAA,EAAG;IACX,OAAOC,MAAM,CAAC,IAAI,CAACb,IAAI,CAACc,UAAU,CAAC;EACrC;AACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { FileHandle } from './file-handle';
|
|
3
|
+
import { resolvePath } from '../path-utils/file-aliases';
|
|
4
|
+
export class FileHandleFile {
|
|
5
|
+
static async from(path) {
|
|
6
|
+
path = resolvePath(path);
|
|
7
|
+
const fileDescriptor = await FileHandle.open(path);
|
|
8
|
+
return new FileHandleFile(fileDescriptor, fileDescriptor.stat.size);
|
|
9
|
+
}
|
|
10
|
+
constructor(fileDescriptor, size) {
|
|
11
|
+
_defineProperty(this, "fileDescriptor", void 0);
|
|
12
|
+
_defineProperty(this, "size", void 0);
|
|
13
|
+
this.fileDescriptor = fileDescriptor;
|
|
14
|
+
this.size = size;
|
|
15
|
+
}
|
|
16
|
+
async destroy() {
|
|
17
|
+
await this.fileDescriptor.close();
|
|
18
|
+
}
|
|
19
|
+
async getUint8(offset) {
|
|
20
|
+
const val = new Uint8Array((await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer).at(0);
|
|
21
|
+
if (val === undefined) {
|
|
22
|
+
throw new Error('something went wrong');
|
|
23
|
+
}
|
|
24
|
+
return val;
|
|
25
|
+
}
|
|
26
|
+
async getUint16(offset) {
|
|
27
|
+
const val = new Uint16Array((await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer).at(0);
|
|
28
|
+
if (val === undefined) {
|
|
29
|
+
throw new Error('something went wrong');
|
|
30
|
+
}
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
33
|
+
async getUint32(offset) {
|
|
34
|
+
const val = new Uint32Array((await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer).at(0);
|
|
35
|
+
if (val === undefined) {
|
|
36
|
+
throw new Error('something went wrong');
|
|
37
|
+
}
|
|
38
|
+
return val;
|
|
39
|
+
}
|
|
40
|
+
async getBigUint64(offset) {
|
|
41
|
+
const val = new BigInt64Array((await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer).at(0);
|
|
42
|
+
if (val === undefined) {
|
|
43
|
+
throw new Error('something went wrong');
|
|
44
|
+
}
|
|
45
|
+
return val;
|
|
46
|
+
}
|
|
47
|
+
async slice(startOffsset, endOffset) {
|
|
48
|
+
const bigLength = endOffset - startOffsset;
|
|
49
|
+
if (bigLength > Number.MAX_SAFE_INTEGER) {
|
|
50
|
+
throw new Error('too big slice');
|
|
51
|
+
}
|
|
52
|
+
const length = Number(bigLength);
|
|
53
|
+
return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer.buffer;
|
|
54
|
+
}
|
|
55
|
+
get length() {
|
|
56
|
+
return this.size;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=file-handle-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-handle-file.js","names":["FileHandle","resolvePath","FileHandleFile","from","path","fileDescriptor","open","stat","size","constructor","_defineProperty","destroy","close","getUint8","offset","val","Uint8Array","read","Buffer","alloc","buffer","at","undefined","Error","getUint16","Uint16Array","getUint32","Uint32Array","getBigUint64","BigInt64Array","slice","startOffsset","endOffset","bigLength","Number","MAX_SAFE_INTEGER","length"],"sources":["../../../../src/lib/file-provider/file-handle-file.ts"],"sourcesContent":["import {FileProvider} from './file-provider';\nimport {FileHandle} from './file-handle';\nimport {resolvePath} from '../path-utils/file-aliases';\n\n/**\n * Provides file data using node fs library\n */\nexport class FileHandleFile implements FileProvider {\n /**\n * Returns a new copy of FileHandleFile\n * @param path The path to the file in file system\n */\n static async from(path: string): Promise<FileHandleFile> {\n path = resolvePath(path);\n const fileDescriptor = await FileHandle.open(path);\n return new FileHandleFile(fileDescriptor, fileDescriptor.stat.size);\n }\n\n /**\n * The FileHandle from which data is provided\n */\n private fileDescriptor: FileHandle;\n\n /**\n * The file length in bytes\n */\n private size: bigint;\n\n private constructor(fileDescriptor: FileHandle, size: bigint) {\n this.fileDescriptor = fileDescriptor;\n this.size = size;\n }\n\n /** Close file */\n async destroy(): Promise<void> {\n await this.fileDescriptor.close();\n }\n\n /**\n * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint8(offset: bigint): Promise<number> {\n const val = new Uint8Array(\n (await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer\n ).at(0);\n if (val === undefined) {\n throw new Error('something went wrong');\n }\n return val;\n }\n\n /**\n * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint16(offset: bigint): Promise<number> {\n const val = new Uint16Array(\n (await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer\n ).at(0);\n if (val === undefined) {\n throw new Error('something went wrong');\n }\n return val;\n }\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getUint32(offset: bigint): Promise<number> {\n const val = new Uint32Array(\n (await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer\n ).at(0);\n if (val === undefined) {\n throw new Error('something went wrong');\n }\n return val;\n }\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n async getBigUint64(offset: bigint): Promise<bigint> {\n const val = new BigInt64Array(\n (await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer\n ).at(0);\n if (val === undefined) {\n throw new Error('something went wrong');\n }\n return val;\n }\n\n /**\n * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.\n * @param startOffsset The offset, in byte, from the start of the file where to start reading the data.\n * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.\n */\n async slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer> {\n const bigLength = endOffset - startOffsset;\n if (bigLength > Number.MAX_SAFE_INTEGER) {\n throw new Error('too big slice');\n }\n const length = Number(bigLength);\n return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer\n .buffer;\n }\n\n /**\n * the length (in bytes) of the data.\n */\n get length(): bigint {\n return this.size;\n }\n}\n"],"mappings":";AACA,SAAQA,UAAU,QAAO,eAAe;AACxC,SAAQC,WAAW,QAAO,4BAA4B;AAKtD,OAAO,MAAMC,cAAc,CAAyB;EAKlD,aAAaC,IAAIA,CAACC,IAAY,EAA2B;IACvDA,IAAI,GAAGH,WAAW,CAACG,IAAI,CAAC;IACxB,MAAMC,cAAc,GAAG,MAAML,UAAU,CAACM,IAAI,CAACF,IAAI,CAAC;IAClD,OAAO,IAAIF,cAAc,CAACG,cAAc,EAAEA,cAAc,CAACE,IAAI,CAACC,IAAI,CAAC;EACrE;EAYQC,WAAWA,CAACJ,cAA0B,EAAEG,IAAY,EAAE;IAAAE,eAAA;IAAAA,eAAA;IAC5D,IAAI,CAACL,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACG,IAAI,GAAGA,IAAI;EAClB;EAGA,MAAMG,OAAOA,CAAA,EAAkB;IAC7B,MAAM,IAAI,CAACN,cAAc,CAACO,KAAK,CAAC,CAAC;EACnC;EAMA,MAAMC,QAAQA,CAACC,MAAc,EAAmB;IAC9C,MAAMC,GAAG,GAAG,IAAIC,UAAU,CACxB,CAAC,MAAM,IAAI,CAACX,cAAc,CAACY,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEL,MAAM,CAAC,EAAEM,MAAM,CAACA,MACzE,CAAC,CAACC,EAAE,CAAC,CAAC,CAAC;IACP,IAAIN,GAAG,KAAKO,SAAS,EAAE;MACrB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,OAAOR,GAAG;EACZ;EAMA,MAAMS,SAASA,CAACV,MAAc,EAAmB;IAC/C,MAAMC,GAAG,GAAG,IAAIU,WAAW,CACzB,CAAC,MAAM,IAAI,CAACpB,cAAc,CAACY,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEL,MAAM,CAAC,EAAEM,MAAM,CAACA,MACzE,CAAC,CAACC,EAAE,CAAC,CAAC,CAAC;IACP,IAAIN,GAAG,KAAKO,SAAS,EAAE;MACrB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,OAAOR,GAAG;EACZ;EAMA,MAAMW,SAASA,CAACZ,MAAc,EAAmB;IAC/C,MAAMC,GAAG,GAAG,IAAIY,WAAW,CACzB,CAAC,MAAM,IAAI,CAACtB,cAAc,CAACY,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEL,MAAM,CAAC,EAAEM,MAAM,CAACA,MACzE,CAAC,CAACC,EAAE,CAAC,CAAC,CAAC;IACP,IAAIN,GAAG,KAAKO,SAAS,EAAE;MACrB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,OAAOR,GAAG;EACZ;EAMA,MAAMa,YAAYA,CAACd,MAAc,EAAmB;IAClD,MAAMC,GAAG,GAAG,IAAIc,aAAa,CAC3B,CAAC,MAAM,IAAI,CAACxB,cAAc,CAACY,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAEL,MAAM,CAAC,EAAEM,MAAM,CAACA,MACzE,CAAC,CAACC,EAAE,CAAC,CAAC,CAAC;IACP,IAAIN,GAAG,KAAKO,SAAS,EAAE;MACrB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,OAAOR,GAAG;EACZ;EAOA,MAAMe,KAAKA,CAACC,YAAoB,EAAEC,SAAiB,EAAwB;IACzE,MAAMC,SAAS,GAAGD,SAAS,GAAGD,YAAY;IAC1C,IAAIE,SAAS,GAAGC,MAAM,CAACC,gBAAgB,EAAE;MACvC,MAAM,IAAIZ,KAAK,CAAC,eAAe,CAAC;IAClC;IACA,MAAMa,MAAM,GAAGF,MAAM,CAACD,SAAS,CAAC;IAChC,OAAO,CAAC,MAAM,IAAI,CAAC5B,cAAc,CAACY,IAAI,CAACC,MAAM,CAACC,KAAK,CAACiB,MAAM,CAAC,EAAE,CAAC,EAAEA,MAAM,EAAEL,YAAY,CAAC,EAAEX,MAAM,CAC1FA,MAAM;EACX;EAKA,IAAIgB,MAAMA,CAAA,EAAW;IACnB,OAAO,IAAI,CAAC5B,IAAI;EAClB;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import * as fs from '../node/fs';
|
|
3
|
+
export class FileHandle {
|
|
4
|
+
constructor(fileDescriptor, stats) {
|
|
5
|
+
_defineProperty(this, "fileDescriptor", void 0);
|
|
6
|
+
_defineProperty(this, "stats", void 0);
|
|
7
|
+
_defineProperty(this, "read", (buffer, offset, length, position) => {
|
|
8
|
+
return new Promise(s => {
|
|
9
|
+
fs.read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) => s({
|
|
10
|
+
bytesRead,
|
|
11
|
+
buffer
|
|
12
|
+
}));
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
this.fileDescriptor = fileDescriptor;
|
|
16
|
+
this.stats = stats;
|
|
17
|
+
}
|
|
18
|
+
static async open(path) {
|
|
19
|
+
const [fd, stats] = await Promise.all([new Promise((resolve, reject) => {
|
|
20
|
+
fs.open(path, undefined, undefined, (_err, fd) => _err ? reject(_err) : resolve(fd));
|
|
21
|
+
}), fs.stat(path, {
|
|
22
|
+
bigint: true
|
|
23
|
+
})]);
|
|
24
|
+
return new FileHandle(fd, stats);
|
|
25
|
+
}
|
|
26
|
+
async close() {
|
|
27
|
+
return fs.close(this.fileDescriptor);
|
|
28
|
+
}
|
|
29
|
+
get stat() {
|
|
30
|
+
return this.stats;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=file-handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-handle.js","names":["fs","FileHandle","constructor","fileDescriptor","stats","_defineProperty","buffer","offset","length","position","Promise","s","read","_err","bytesRead","open","path","fd","all","resolve","reject","undefined","stat","bigint","close"],"sources":["../../../../src/lib/file-provider/file-handle.ts"],"sourcesContent":["import * as fs from '../node/fs';\n\n/** file reading result */\nexport type FileReadResult = {\n /** amount of the bytes read */\n bytesRead: number;\n /** the buffer filled with data from file*/\n buffer: Buffer;\n};\n\n/** Object handling file info */\nexport class FileHandle {\n private fileDescriptor: number;\n private stats: fs.BigIntStats;\n\n private constructor(fileDescriptor: number, stats: fs.BigIntStats) {\n this.fileDescriptor = fileDescriptor;\n this.stats = stats;\n }\n /**\n * Opens a `FileHandle`.\n *\n * @param path path to the file\n * @return Fulfills with a {FileHandle} object.\n */\n\n static async open(path: string): Promise<FileHandle> {\n const [fd, stats] = await Promise.all([\n new Promise<number>((resolve, reject) => {\n fs.open(path, undefined, undefined, (_err, fd) => (_err ? reject(_err) : resolve(fd)));\n }),\n fs.stat(path, {bigint: true})\n // new Promise<fs.BigIntStats>((resolve, reject) => {\n // console.error(fs.stat)\n // fs.stat(path, {bigint: true}, (_err, stats) => (_err ? reject(_err) : resolve(stats)));\n // console.error(fs.open)\n // })\n ]);\n return new FileHandle(fd, stats);\n }\n\n /** Close file */\n async close(): Promise<void> {\n return fs.close(this.fileDescriptor);\n // return new Promise<void>((resolve) => {\n // // @ts-expect-error\n // fs.close(this.fileDescriptor, (_err) => resolve());\n // });\n }\n\n /**\n * Reads data from the file and stores that in the given buffer.\n *\n * If the file is not modified concurrently, the end-of-file is reached when the\n * number of bytes read is zero.\n * @param buffer A buffer that will be filled with the file data read.\n * @param offset The location in the buffer at which to start filling.\n * @param length The number of bytes to read.\n * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an\n * integer, the current file position will remain unchanged.\n * @return Fulfills upon success with a FileReadResult object\n */\n read = (\n buffer: Buffer,\n offset: number,\n length: number,\n position: number | bigint\n ): Promise<FileReadResult> => {\n return new Promise((s) => {\n fs.read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) =>\n s({bytesRead, buffer})\n );\n });\n };\n\n get stat(): fs.BigIntStats {\n return this.stats;\n }\n}\n"],"mappings":";AAAA,OAAO,KAAKA,EAAE,MAAM,YAAY;AAWhC,OAAO,MAAMC,UAAU,CAAC;EAIdC,WAAWA,CAACC,cAAsB,EAAEC,KAAqB,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA,eA+C5D,CACLC,MAAc,EACdC,MAAc,EACdC,MAAc,EACdC,QAAyB,KACG;MAC5B,OAAO,IAAIC,OAAO,CAAEC,CAAC,IAAK;QACxBX,EAAE,CAACY,IAAI,CAAC,IAAI,CAACT,cAAc,EAAEG,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE,CAACI,IAAI,EAAEC,SAAS,EAAER,MAAM,KACrFK,CAAC,CAAC;UAACG,SAAS;UAAER;QAAM,CAAC,CACvB,CAAC;MACH,CAAC,CAAC;IACJ,CAAC;IAzDC,IAAI,CAACH,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;EAQA,aAAaW,IAAIA,CAACC,IAAY,EAAuB;IACnD,MAAM,CAACC,EAAE,EAAEb,KAAK,CAAC,GAAG,MAAMM,OAAO,CAACQ,GAAG,CAAC,CACpC,IAAIR,OAAO,CAAS,CAACS,OAAO,EAAEC,MAAM,KAAK;MACvCpB,EAAE,CAACe,IAAI,CAACC,IAAI,EAAEK,SAAS,EAAEA,SAAS,EAAE,CAACR,IAAI,EAAEI,EAAE,KAAMJ,IAAI,GAAGO,MAAM,CAACP,IAAI,CAAC,GAAGM,OAAO,CAACF,EAAE,CAAE,CAAC;IACxF,CAAC,CAAC,EACFjB,EAAE,CAACsB,IAAI,CAACN,IAAI,EAAE;MAACO,MAAM,EAAE;IAAI,CAAC,CAAC,CAM9B,CAAC;IACF,OAAO,IAAItB,UAAU,CAACgB,EAAE,EAAEb,KAAK,CAAC;EAClC;EAGA,MAAMoB,KAAKA,CAAA,EAAkB;IAC3B,OAAOxB,EAAE,CAACwB,KAAK,CAAC,IAAI,CAACrB,cAAc,CAAC;EAKtC;EA2BA,IAAImB,IAAIA,CAAA,EAAmB;IACzB,OAAO,IAAI,CAAClB,KAAK;EACnB;AACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const isFileProvider = fileProvider => {
|
|
2
|
+
return (fileProvider === null || fileProvider === void 0 ? void 0 : fileProvider.getUint8) && (fileProvider === null || fileProvider === void 0 ? void 0 : fileProvider.slice) && (fileProvider === null || fileProvider === void 0 ? void 0 : fileProvider.length);
|
|
3
|
+
};
|
|
4
|
+
//# sourceMappingURL=file-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-provider.js","names":["isFileProvider","fileProvider","getUint8","slice","length"],"sources":["../../../../src/lib/file-provider/file-provider.ts"],"sourcesContent":["/**\n * Interface for providing file data\n */\nexport interface FileProvider {\n /**\n * Cleanup class data\n */\n destroy(): Promise<void>;\n /**\n * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n getUint8(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the start of the file where to read the data.\n */\n getUint16(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in bytes, from the file of the view where to read the data.\n */\n getUint32(offset: bigint): Promise<number>;\n\n /**\n * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.\n * @param offset The offset, in byte, from the file of the view where to read the data.\n */\n getBigUint64(offset: bigint): Promise<bigint>;\n\n /**\n * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.\n * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.\n * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.\n */\n slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;\n\n /**\n * the length (in bytes) of the data.\n */\n length: bigint;\n}\n\n/**\n * Check is the object has FileProvider members\n * @param fileProvider - tested object\n */\nexport const isFileProvider = (fileProvider: unknown) => {\n return (\n (fileProvider as FileProvider)?.getUint8 &&\n (fileProvider as FileProvider)?.slice &&\n (fileProvider as FileProvider)?.length\n );\n};\n"],"mappings":"AAiDA,OAAO,MAAMA,cAAc,GAAIC,YAAqB,IAAK;EACvD,OACE,CAACA,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAmBC,QAAQ,MACvCD,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAmBE,KAAK,MACpCF,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAmBG,MAAM;AAE1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem.js","names":[],"sources":["../../../../src/lib/filesystems/filesystem.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nexport type ReadOptions = {};\n\nexport type Stat = {\n size: number;\n isDirectory: () => boolean;\n};\n\n/**\n * A FileSystem interface can encapsulate various file sources,\n * a FileList, a ZipFile, a GoogleDrive etc.\n */\nexport interface FileSystem {\n /**\n * Return a list of file names\n * @param dirname directory name. file system root directory if omitted\n */\n readdir(dirname?: string, options?: {recursive?: boolean}): Promise<string[]>;\n\n /**\n * Gets information from a local file from the filesystem\n * @param filename file name to stat\n * @param options currently unused\n * @throws if filename is not in local filesystem\n */\n stat(filename: string, options?: object): Promise<{size: number}>;\n\n /**\n * Fetches a local file from the filesystem (or a URL)\n * @param filename\n * @param options\n */\n fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;\n}\n\n/**\n * A random access file system\n */\nexport interface RandomAccessReadFileSystem extends FileSystem {\n open(path: string, flags: unknown, mode?: unknown): Promise<any>;\n close(fd: unknown): Promise<void>;\n fstat(fd: unknown): Promise<Stat>;\n read(fd: any, options?: ReadOptions): Promise<{bytesRead: number; buffer: Uint8Array}>;\n // read(\n // fd: any,\n // buffer: ArrayBuffer | ArrayBufferView,\n // offset?: number,\n // length?: number,\n // position?: number\n // ): Promise<{bytesRead: number; buffer: ArrayBuffer}>;\n}\n\n/**\n * A FileSystem interface can encapsulate a FileList, a ZipFile, a GoogleDrive etc.\n *\nexport interface IFileSystem {\n /**\n * Return a list of file names\n * @param dirname directory name. file system root directory if omitted\n *\n readdir(dirname?: string, options?: {recursive?: boolean}): Promise<string[]>;\n\n /**\n * Gets information from a local file from the filesystem\n * @param filename file name to stat\n * @param options currently unused\n * @throws if filename is not in local filesystem\n *\n stat(filename: string, options?: object): Promise<{size: number}>;\n\n /**\n * Fetches a local file from the filesystem (or a URL)\n * @param filename\n * @param options\n *\n fetch(filename: string, options?: object): Promise<Response>;\n}\n\ntype ReadOptions = {buffer?: ArrayBuffer; offset?: number; length?: number; position?: number};\nexport interface IRandomAccessReadFileSystem extends IFileSystem {\n open(path: string, flags: string | number, mode?: any): Promise<any>;\n close(fd: any): Promise<void>;\n fstat(fd: any): Promise<object>;\n read(fd: any, options?: ReadOptions): Promise<{bytesRead: number; buffer: Buffer}>;\n}\n*/\n"],"mappings":""}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
export default class NodeFileSystem {
|
|
1
|
+
export class NodeFileSystem {
|
|
3
2
|
constructor(options) {
|
|
4
|
-
|
|
3
|
+
var _globalThis$loaders;
|
|
4
|
+
if ((_globalThis$loaders = globalThis.loaders) !== null && _globalThis$loaders !== void 0 && _globalThis$loaders.NodeFileSystem) {
|
|
5
|
+
return new globalThis.loaders.NodeFileSystem(options);
|
|
6
|
+
}
|
|
7
|
+
throw new Error('Can\'t instantiate NodeFileSystem in browser. Make sure to import @loaders.gl/polyfills first.');
|
|
5
8
|
}
|
|
6
9
|
async readdir() {
|
|
7
10
|
let dirname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.';
|
|
8
11
|
let options = arguments.length > 1 ? arguments[1] : undefined;
|
|
9
|
-
return
|
|
12
|
+
return [];
|
|
10
13
|
}
|
|
11
14
|
async stat(path, options) {
|
|
12
|
-
const info = await fs.stat(path, options);
|
|
13
15
|
return {
|
|
14
|
-
size:
|
|
15
|
-
isDirectory: () => false
|
|
16
|
-
info
|
|
16
|
+
size: 0,
|
|
17
|
+
isDirectory: () => false
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
async fetch(path, options) {
|
|
20
|
-
|
|
21
|
-
return fallbackFetch(path, options);
|
|
21
|
+
return globalThis.fetch(path, options);
|
|
22
22
|
}
|
|
23
23
|
async open(path, flags, mode) {
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
async close(fd) {
|
|
27
|
-
return await fs.close(fd);
|
|
24
|
+
return 0;
|
|
28
25
|
}
|
|
26
|
+
async close(fd) {}
|
|
29
27
|
async fstat(fd) {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return {
|
|
29
|
+
size: 0,
|
|
30
|
+
isDirectory: () => false
|
|
31
|
+
};
|
|
32
32
|
}
|
|
33
33
|
async read(fd, _ref) {
|
|
34
34
|
let {
|
|
@@ -37,16 +37,9 @@ export default class NodeFileSystem {
|
|
|
37
37
|
length = buffer.byteLength,
|
|
38
38
|
position = null
|
|
39
39
|
} = _ref;
|
|
40
|
-
let totalBytesRead = 0;
|
|
41
|
-
while (totalBytesRead < length) {
|
|
42
|
-
const {
|
|
43
|
-
bytesRead
|
|
44
|
-
} = await fs.read(fd, buffer, offset + totalBytesRead, length - totalBytesRead, position + totalBytesRead);
|
|
45
|
-
totalBytesRead += bytesRead;
|
|
46
|
-
}
|
|
47
40
|
return {
|
|
48
|
-
bytesRead:
|
|
49
|
-
buffer
|
|
41
|
+
bytesRead: 0,
|
|
42
|
+
buffer: new Uint8Array(0)
|
|
50
43
|
};
|
|
51
44
|
}
|
|
52
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-filesystem.js","names":["
|
|
1
|
+
{"version":3,"file":"node-filesystem.js","names":["NodeFileSystem","constructor","options","_globalThis$loaders","globalThis","loaders","Error","readdir","dirname","arguments","length","undefined","stat","path","size","isDirectory","fetch","open","flags","mode","close","fd","fstat","read","_ref","buffer","offset","byteLength","position","bytesRead","Uint8Array"],"sources":["../../../../src/lib/filesystems/node-filesystem.ts"],"sourcesContent":["import * as fs from '../node/fs';\nimport {FileSystem, RandomAccessReadFileSystem} from './filesystem';\n// import {fetchFile} from \"../fetch/fetch-file\"\n// import {selectLoader} from \"../api/select-loader\";\n\ntype Stat = {\n size: number;\n isDirectory: () => boolean;\n info?: fs.Stats;\n};\n\ntype ReadOptions = {\n buffer?: Buffer;\n offset?: number;\n length?: number;\n position?: number;\n};\n\n/**\n * FileSystem pass-through for Node.js\n * Compatible with BrowserFileSystem.\n * @param options\n */\nexport class NodeFileSystem implements FileSystem, RandomAccessReadFileSystem {\n // implements FileSystem\n constructor(options: {[key: string]: any}) {\n if (globalThis.loaders?.NodeFileSystem) {\n return new globalThis.loaders.NodeFileSystem(options);\n }\n throw new Error(\n 'Can\\'t instantiate NodeFileSystem in browser. Make sure to import @loaders.gl/polyfills first.'\n );\n }\n\n async readdir(dirname = '.', options?: {}): Promise<any[]> {\n return [];\n }\n\n async stat(path: string, options?: {}): Promise<Stat> {\n return {size: 0, isDirectory: () => false};\n }\n\n async fetch(path: string, options: {[key: string]: any}) {\n return globalThis.fetch(path, options);\n }\n\n // implements IRandomAccessFileSystem\n\n async open(path: string, flags: string | number, mode?: any): Promise<number> {\n return 0;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n async close(fd: number): Promise<void> {}\n\n async fstat(fd: number): Promise<Stat> {\n return {size: 0, isDirectory: () => false};\n }\n\n async read(\n fd: number,\n // @ts-ignore Possibly null\n {buffer = null, offset = 0, length = buffer.byteLength, position = null}: ReadOptions\n ): Promise<{bytesRead: number; buffer: Uint8Array}> {\n return {bytesRead: 0, buffer: new Uint8Array(0)};\n }\n}\n"],"mappings":"AAuBA,OAAO,MAAMA,cAAc,CAAmD;EAE5EC,WAAWA,CAACC,OAA6B,EAAE;IAAA,IAAAC,mBAAA;IACzC,KAAAA,mBAAA,GAAIC,UAAU,CAACC,OAAO,cAAAF,mBAAA,eAAlBA,mBAAA,CAAoBH,cAAc,EAAE;MACtC,OAAO,IAAII,UAAU,CAACC,OAAO,CAACL,cAAc,CAACE,OAAO,CAAC;IACvD;IACA,MAAM,IAAII,KAAK,CACb,gGACF,CAAC;EACH;EAEA,MAAMC,OAAOA,CAAA,EAA8C;IAAA,IAA7CC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,GAAG;IAAA,IAAEP,OAAY,GAAAO,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;IACvC,OAAO,EAAE;EACX;EAEA,MAAMC,IAAIA,CAACC,IAAY,EAAEX,OAAY,EAAiB;IACpD,OAAO;MAACY,IAAI,EAAE,CAAC;MAAEC,WAAW,EAAEA,CAAA,KAAM;IAAK,CAAC;EAC5C;EAEA,MAAMC,KAAKA,CAACH,IAAY,EAAEX,OAA6B,EAAE;IACvD,OAAOE,UAAU,CAACY,KAAK,CAACH,IAAI,EAAEX,OAAO,CAAC;EACxC;EAIA,MAAMe,IAAIA,CAACJ,IAAY,EAAEK,KAAsB,EAAEC,IAAU,EAAmB;IAC5E,OAAO,CAAC;EACV;EAGA,MAAMC,KAAKA,CAACC,EAAU,EAAiB,CAAC;EAExC,MAAMC,KAAKA,CAACD,EAAU,EAAiB;IACrC,OAAO;MAACP,IAAI,EAAE,CAAC;MAAEC,WAAW,EAAEA,CAAA,KAAM;IAAK,CAAC;EAC5C;EAEA,MAAMQ,IAAIA,CACRF,EAAU,EAAAG,IAAA,EAGwC;IAAA,IADlD;MAACC,MAAM,GAAG,IAAI;MAAEC,MAAM,GAAG,CAAC;MAAEhB,MAAM,GAAGe,MAAM,CAACE,UAAU;MAAEC,QAAQ,GAAG;IAAiB,CAAC,GAAAJ,IAAA;IAErF,OAAO;MAACK,SAAS,EAAE,CAAC;MAAEJ,MAAM,EAAE,IAAIK,UAAU,CAAC,CAAC;IAAC,CAAC;EAClD;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.browser.js","names":["isSupported"],"sources":["../../../../src/lib/node/fs.browser.ts"],"sourcesContent":["export const isSupported = false;\n"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GAAG,KAAK"}
|
package/dist/esm/lib/node/fs.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as fsPromises from 'fs/promises';
|
|
2
3
|
import { toArrayBuffer } from './buffer';
|
|
3
4
|
import { promisify2, promisify3 } from './promisify';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
stat = promisify2(fs.stat);
|
|
19
|
-
readFile = fs.readFile;
|
|
20
|
-
readFileSync = fs.readFileSync;
|
|
21
|
-
writeFile = promisify3(fs.writeFile);
|
|
22
|
-
writeFileSync = fs.writeFileSync;
|
|
23
|
-
open = fs.open;
|
|
24
|
-
close = fd => new Promise((resolve, reject) => fs.close(fd, err => err ? reject(err) : resolve()));
|
|
25
|
-
read = fs.read;
|
|
26
|
-
fstat = fs.fstat;
|
|
27
|
-
createWriteStream = fs.createWriteStream;
|
|
28
|
-
isSupported = Boolean(fs);
|
|
29
|
-
} catch {}
|
|
5
|
+
export const readdir = promisify2(fs.readdir);
|
|
6
|
+
export const stat = fsPromises.stat;
|
|
7
|
+
export const statSync = fs.statSync;
|
|
8
|
+
export const readFile = fs.readFile;
|
|
9
|
+
export const readFileSync = fs.readFileSync;
|
|
10
|
+
export const writeFile = promisify3(fs.writeFile);
|
|
11
|
+
export const writeFileSync = fs.writeFileSync;
|
|
12
|
+
export const open = fs.open;
|
|
13
|
+
export const close = fd => new Promise((resolve, reject) => fs.close(fd, err => err ? reject(err) : resolve()));
|
|
14
|
+
export const read = fs.read;
|
|
15
|
+
export const fstat = fs.fstat;
|
|
16
|
+
export const createReadStream = fs.createReadStream;
|
|
17
|
+
export const createWriteStream = fs.createWriteStream;
|
|
18
|
+
export const isSupported = Boolean(fs);
|
|
30
19
|
export async function _readToArrayBuffer(fd, start, length) {
|
|
31
20
|
const buffer = Buffer.alloc(length);
|
|
32
21
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","names":["fs","toArrayBuffer","promisify2","promisify3","readdir","stat","readFile","readFileSync","writeFile","writeFileSync","open","close","
|
|
1
|
+
{"version":3,"file":"fs.js","names":["fs","fsPromises","toArrayBuffer","promisify2","promisify3","readdir","stat","statSync","readFile","readFileSync","writeFile","writeFileSync","open","close","fd","Promise","resolve","reject","err","read","fstat","createReadStream","createWriteStream","isSupported","Boolean","_readToArrayBuffer","start","length","buffer","Buffer","alloc","bytesRead","Error"],"sources":["../../../../src/lib/node/fs.ts"],"sourcesContent":["// fs wrapper (promisified fs + avoids bundling fs in browsers)\nimport * as fs from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport {toArrayBuffer} from './buffer';\nimport {promisify2, promisify3} from './promisify';\n\nexport type {BigIntStats, Stats} from 'fs';\nexport type {ReadStream, WriteStream} from 'fs';\n\n/** Wrapper for Node.js fs method */\nexport const readdir: any = promisify2(fs.readdir);\n/** Wrapper for Node.js fs method */\nexport const stat: any = fsPromises.stat;\nexport const statSync = fs.statSync;\n\n/** Wrapper for Node.js fs method */\nexport const readFile: any = fs.readFile;\n/** Wrapper for Node.js fs method */\nexport const readFileSync = fs.readFileSync;\n/** Wrapper for Node.js fs method */\nexport const writeFile: any = promisify3(fs.writeFile);\n/** Wrapper for Node.js fs method */\nexport const writeFileSync = fs.writeFileSync;\n\n// file descriptors\n\n/** Wrapper for Node.js fs method */\nexport const open: any = fs.open;\n/** Wrapper for Node.js fs method */\nexport const close = (fd: number) =>\n new Promise<void>((resolve, reject) => fs.close(fd, (err) => (err ? reject(err) : resolve())));\n/** Wrapper for Node.js fs method */\nexport const read: any = fs.read;\n/** Wrapper for Node.js fs method */\nexport const fstat: any = fs.fstat;\n\nexport const createReadStream = fs.createReadStream;\nexport const createWriteStream = fs.createWriteStream;\n\nexport const isSupported = Boolean(fs);\n\nexport async function _readToArrayBuffer(fd: number, start: number, length: number) {\n const buffer = Buffer.alloc(length);\n const {bytesRead} = await read(fd, buffer, 0, length, start);\n if (bytesRead !== length) {\n throw new Error('fs.read failed');\n }\n return toArrayBuffer(buffer);\n}\n"],"mappings":"AACA,OAAO,KAAKA,EAAE,MAAM,IAAI;AACxB,OAAO,KAAKC,UAAU,MAAM,aAAa;AACzC,SAAQC,aAAa,QAAO,UAAU;AACtC,SAAQC,UAAU,EAAEC,UAAU,QAAO,aAAa;AAMlD,OAAO,MAAMC,OAAY,GAAGF,UAAU,CAACH,EAAE,CAACK,OAAO,CAAC;AAElD,OAAO,MAAMC,IAAS,GAAGL,UAAU,CAACK,IAAI;AACxC,OAAO,MAAMC,QAAQ,GAAGP,EAAE,CAACO,QAAQ;AAGnC,OAAO,MAAMC,QAAa,GAAGR,EAAE,CAACQ,QAAQ;AAExC,OAAO,MAAMC,YAAY,GAAGT,EAAE,CAACS,YAAY;AAE3C,OAAO,MAAMC,SAAc,GAAGN,UAAU,CAACJ,EAAE,CAACU,SAAS,CAAC;AAEtD,OAAO,MAAMC,aAAa,GAAGX,EAAE,CAACW,aAAa;AAK7C,OAAO,MAAMC,IAAS,GAAGZ,EAAE,CAACY,IAAI;AAEhC,OAAO,MAAMC,KAAK,GAAIC,EAAU,IAC9B,IAAIC,OAAO,CAAO,CAACC,OAAO,EAAEC,MAAM,KAAKjB,EAAE,CAACa,KAAK,CAACC,EAAE,EAAGI,GAAG,IAAMA,GAAG,GAAGD,MAAM,CAACC,GAAG,CAAC,GAAGF,OAAO,CAAC,CAAE,CAAC,CAAC;AAEhG,OAAO,MAAMG,IAAS,GAAGnB,EAAE,CAACmB,IAAI;AAEhC,OAAO,MAAMC,KAAU,GAAGpB,EAAE,CAACoB,KAAK;AAElC,OAAO,MAAMC,gBAAgB,GAAGrB,EAAE,CAACqB,gBAAgB;AACnD,OAAO,MAAMC,iBAAiB,GAAGtB,EAAE,CAACsB,iBAAiB;AAErD,OAAO,MAAMC,WAAW,GAAGC,OAAO,CAACxB,EAAE,CAAC;AAEtC,OAAO,eAAeyB,kBAAkBA,CAACX,EAAU,EAAEY,KAAa,EAAEC,MAAc,EAAE;EAClF,MAAMC,MAAM,GAAGC,MAAM,CAACC,KAAK,CAACH,MAAM,CAAC;EACnC,MAAM;IAACI;EAAS,CAAC,GAAG,MAAMZ,IAAI,CAACL,EAAE,EAAEc,MAAM,EAAE,CAAC,EAAED,MAAM,EAAED,KAAK,CAAC;EAC5D,IAAIK,SAAS,KAAKJ,MAAM,EAAE;IACxB,MAAM,IAAIK,KAAK,CAAC,gBAAgB,CAAC;EACnC;EACA,OAAO9B,aAAa,CAAC0B,MAAM,CAAC;AAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.browser.js","names":["isSupported"],"sources":["../../../../src/lib/node/stream.browser.ts"],"sourcesContent":["export const isSupported = false;\n"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GAAG,KAAK"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import stream from 'stream';
|
|
2
|
-
export
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
export const Transform = stream.Transform;
|
|
3
3
|
export const isSupported = Boolean(stream);
|
|
4
|
-
try {
|
|
5
|
-
Transform = stream.Transform;
|
|
6
|
-
} catch {}
|
|
7
4
|
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","names":["stream","Transform","isSupported","Boolean"],"sources":["../../../../src/lib/node/stream.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport stream from 'stream';\n\nexport type {Writable} from 'stream';\n\
|
|
1
|
+
{"version":3,"file":"stream.js","names":["stream","Transform","isSupported","Boolean"],"sources":["../../../../src/lib/node/stream.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport * as stream from 'stream';\n\nexport type {Writable} from 'stream';\n\n/** Wrapper for Node.js stream method */\nexport const Transform = stream.Transform;\n\nexport const isSupported = Boolean(stream);\n"],"mappings":"AAEA,OAAO,KAAKA,MAAM,MAAM,QAAQ;AAKhC,OAAO,MAAMC,SAAS,GAAGD,MAAM,CAACC,SAAS;AAEzC,OAAO,MAAMC,WAAW,GAAGC,OAAO,CAACH,MAAM,CAAC"}
|
|
@@ -6,7 +6,7 @@ function mergeOptionsRecursively(baseOptions, newOptions) {
|
|
|
6
6
|
...baseOptions
|
|
7
7
|
};
|
|
8
8
|
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
9
|
-
if (newValue && typeof newValue === 'object') {
|
|
9
|
+
if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {
|
|
10
10
|
options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key]);
|
|
11
11
|
} else {
|
|
12
12
|
options[key] = newOptions[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-loader-options.js","names":["mergeLoaderOptions","baseOptions","newOptions","mergeOptionsRecursively","options","key","newValue","Object","entries"],"sources":["../../../../src/lib/option-utils/merge-loader-options.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {LoaderOptions} from '../../types';\n\n/**\n *\n * @param baseOptions Can be undefined, in which case a fresh options object will be minted\n * @param newOptions\n * @returns\n */\nexport function mergeLoaderOptions<Options extends LoaderOptions>(\n baseOptions: Options | undefined,\n newOptions: Options\n): Options {\n return mergeOptionsRecursively(baseOptions || {}, newOptions) as Options;\n}\n\nfunction mergeOptionsRecursively(\n baseOptions: Record<string, unknown>,\n newOptions: Record<string, unknown>\n): Record<string, unknown> {\n const options = {...baseOptions};\n for (const [key, newValue] of Object.entries(newOptions)) {\n if (newValue && typeof newValue === 'object') {\n options[key] = mergeOptionsRecursively(\n (options[key] as Record<string, unknown>) || {},\n newOptions[key] as Record<string, unknown>\n );\n // Object.assign(options[key] as object, newOptions[key]);\n } else {\n options[key] = newOptions[key];\n }\n }\n return options as Record<string, unknown>;\n}\n"],"mappings":"AAUA,OAAO,SAASA,kBAAkBA,CAChCC,WAAgC,EAChCC,UAAmB,EACV;EACT,OAAOC,uBAAuB,CAACF,WAAW,IAAI,CAAC,CAAC,EAAEC,UAAU,CAAC;AAC/D;AAEA,SAASC,uBAAuBA,CAC9BF,WAAoC,EACpCC,UAAmC,EACV;EACzB,MAAME,OAAO,GAAG;IAAC,GAAGH;EAAW,CAAC;EAChC,KAAK,MAAM,CAACI,GAAG,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,UAAU,CAAC,EAAE;IACxD,IAAII,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"merge-loader-options.js","names":["mergeLoaderOptions","baseOptions","newOptions","mergeOptionsRecursively","options","key","newValue","Object","entries","Array","isArray"],"sources":["../../../../src/lib/option-utils/merge-loader-options.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {LoaderOptions} from '../../loader-types';\n\n/**\n *\n * @param baseOptions Can be undefined, in which case a fresh options object will be minted\n * @param newOptions\n * @returns\n */\nexport function mergeLoaderOptions<Options extends LoaderOptions>(\n baseOptions: Options | undefined,\n newOptions: Options\n): Options {\n return mergeOptionsRecursively(baseOptions || {}, newOptions) as Options;\n}\n\nfunction mergeOptionsRecursively(\n baseOptions: Record<string, unknown>,\n newOptions: Record<string, unknown>\n): Record<string, unknown> {\n const options = {...baseOptions};\n for (const [key, newValue] of Object.entries(newOptions)) {\n if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) {\n options[key] = mergeOptionsRecursively(\n (options[key] as Record<string, unknown>) || {},\n newOptions[key] as Record<string, unknown>\n );\n // Object.assign(options[key] as object, newOptions[key]);\n } else {\n options[key] = newOptions[key];\n }\n }\n return options as Record<string, unknown>;\n}\n"],"mappings":"AAUA,OAAO,SAASA,kBAAkBA,CAChCC,WAAgC,EAChCC,UAAmB,EACV;EACT,OAAOC,uBAAuB,CAACF,WAAW,IAAI,CAAC,CAAC,EAAEC,UAAU,CAAC;AAC/D;AAEA,SAASC,uBAAuBA,CAC9BF,WAAoC,EACpCC,UAAmC,EACV;EACzB,MAAME,OAAO,GAAG;IAAC,GAAGH;EAAW,CAAC;EAChC,KAAK,MAAM,CAACI,GAAG,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACN,UAAU,CAAC,EAAE;IACxD,IAAII,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAI,CAACG,KAAK,CAACC,OAAO,CAACJ,QAAQ,CAAC,EAAE;MACxEF,OAAO,CAACC,GAAG,CAAC,GAAGF,uBAAuB,CACnCC,OAAO,CAACC,GAAG,CAAC,IAAgC,CAAC,CAAC,EAC/CH,UAAU,CAACG,GAAG,CAChB,CAAC;IAEH,CAAC,MAAM;MACLD,OAAO,CAACC,GAAG,CAAC,GAAGH,UAAU,CAACG,GAAG,CAAC;IAChC;EACF;EACA,OAAOD,OAAO;AAChB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
export class DataSource {
|
|
3
|
+
constructor(props) {
|
|
4
|
+
_defineProperty(this, "fetch", void 0);
|
|
5
|
+
_defineProperty(this, "loadOptions", void 0);
|
|
6
|
+
_defineProperty(this, "_needsRefresh", true);
|
|
7
|
+
_defineProperty(this, "props", void 0);
|
|
8
|
+
this.props = {
|
|
9
|
+
...props
|
|
10
|
+
};
|
|
11
|
+
this.loadOptions = {
|
|
12
|
+
...props.loadOptions
|
|
13
|
+
};
|
|
14
|
+
this.fetch = getFetchFunction(this.loadOptions);
|
|
15
|
+
}
|
|
16
|
+
setProps(props) {
|
|
17
|
+
this.props = Object.assign(this.props, props);
|
|
18
|
+
this.setNeedsRefresh();
|
|
19
|
+
}
|
|
20
|
+
setNeedsRefresh() {
|
|
21
|
+
this._needsRefresh = true;
|
|
22
|
+
}
|
|
23
|
+
getNeedsRefresh() {
|
|
24
|
+
let clear = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
25
|
+
const needsRefresh = this._needsRefresh;
|
|
26
|
+
if (clear) {
|
|
27
|
+
this._needsRefresh = false;
|
|
28
|
+
}
|
|
29
|
+
return needsRefresh;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function getFetchFunction(options) {
|
|
33
|
+
const fetchFunction = options === null || options === void 0 ? void 0 : options.fetch;
|
|
34
|
+
if (fetchFunction && typeof fetchFunction === 'function') {
|
|
35
|
+
return (url, fetchOptions) => fetchFunction(url, fetchOptions);
|
|
36
|
+
}
|
|
37
|
+
const fetchOptions = options === null || options === void 0 ? void 0 : options.fetch;
|
|
38
|
+
if (fetchOptions && typeof fetchOptions !== 'function') {
|
|
39
|
+
return url => fetch(url, fetchOptions);
|
|
40
|
+
}
|
|
41
|
+
return url => fetch(url);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=data-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.js","names":["DataSource","constructor","props","_defineProperty","loadOptions","fetch","getFetchFunction","setProps","Object","assign","setNeedsRefresh","_needsRefresh","getNeedsRefresh","clear","arguments","length","undefined","needsRefresh","options","fetchFunction","url","fetchOptions"],"sources":["../../../../src/lib/sources/data-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** Common properties for all data sources */\nexport type DataSourceProps = {\n /** LoaderOptions provide an option to override `fetch`. Will also be passed to any sub loaders */\n loadOptions?: LoaderOptions;\n};\n\n/** base class of all data sources */\nexport abstract class DataSource<PropsT extends DataSourceProps = DataSourceProps> {\n /** A resolved fetch function extracted from loadOptions prop */\n fetch: (url: string, options?: RequestInit) => Promise<Response>;\n /** The actual load options, if calling a loaders.gl loader */\n loadOptions: LoaderOptions;\n _needsRefresh: boolean = true;\n\n props: PropsT;\n\n constructor(props: PropsT) {\n this.props = {...props};\n this.loadOptions = {...props.loadOptions};\n this.fetch = getFetchFunction(this.loadOptions);\n }\n\n setProps(props: PropsT) {\n this.props = Object.assign(this.props, props);\n // TODO - add a shallow compare to avoid setting refresh if no change?\n this.setNeedsRefresh();\n }\n\n /** Mark this data source as needing a refresh (redraw) */\n setNeedsRefresh(): void {\n this._needsRefresh = true;\n }\n\n /**\n * Does this data source need refreshing?\n * @note The specifics of the refresh mechanism depends on type of data source\n */\n getNeedsRefresh(clear: boolean = true) {\n const needsRefresh = this._needsRefresh;\n if (clear) {\n this._needsRefresh = false;\n }\n return needsRefresh;\n }\n}\n\n/**\n * Gets the current fetch function from options\n * @todo - move to loader-utils module\n * @todo - use in core module counterpart\n * @param options\n * @param context\n */\nexport function getFetchFunction(options?: LoaderOptions) {\n const fetchFunction = options?.fetch;\n\n // options.fetch can be a function\n if (fetchFunction && typeof fetchFunction === 'function') {\n return (url: string, fetchOptions?: RequestInit) => fetchFunction(url, fetchOptions);\n }\n\n // options.fetch can be an options object, use global fetch with those options\n const fetchOptions = options?.fetch;\n if (fetchOptions && typeof fetchOptions !== 'function') {\n return (url) => fetch(url, fetchOptions);\n }\n\n // else return the global fetch function\n return (url) => fetch(url);\n}\n"],"mappings":";AAWA,OAAO,MAAeA,UAAU,CAAmD;EASjFC,WAAWA,CAACC,KAAa,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA,wBAJF,IAAI;IAAAA,eAAA;IAK3B,IAAI,CAACD,KAAK,GAAG;MAAC,GAAGA;IAAK,CAAC;IACvB,IAAI,CAACE,WAAW,GAAG;MAAC,GAAGF,KAAK,CAACE;IAAW,CAAC;IACzC,IAAI,CAACC,KAAK,GAAGC,gBAAgB,CAAC,IAAI,CAACF,WAAW,CAAC;EACjD;EAEAG,QAAQA,CAACL,KAAa,EAAE;IACtB,IAAI,CAACA,KAAK,GAAGM,MAAM,CAACC,MAAM,CAAC,IAAI,CAACP,KAAK,EAAEA,KAAK,CAAC;IAE7C,IAAI,CAACQ,eAAe,CAAC,CAAC;EACxB;EAGAA,eAAeA,CAAA,EAAS;IACtB,IAAI,CAACC,aAAa,GAAG,IAAI;EAC3B;EAMAC,eAAeA,CAAA,EAAwB;IAAA,IAAvBC,KAAc,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IACnC,MAAMG,YAAY,GAAG,IAAI,CAACN,aAAa;IACvC,IAAIE,KAAK,EAAE;MACT,IAAI,CAACF,aAAa,GAAG,KAAK;IAC5B;IACA,OAAOM,YAAY;EACrB;AACF;AASA,OAAO,SAASX,gBAAgBA,CAACY,OAAuB,EAAE;EACxD,MAAMC,aAAa,GAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEb,KAAK;EAGpC,IAAIc,aAAa,IAAI,OAAOA,aAAa,KAAK,UAAU,EAAE;IACxD,OAAO,CAACC,GAAW,EAAEC,YAA0B,KAAKF,aAAa,CAACC,GAAG,EAAEC,YAAY,CAAC;EACtF;EAGA,MAAMA,YAAY,GAAGH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEb,KAAK;EACnC,IAAIgB,YAAY,IAAI,OAAOA,YAAY,KAAK,UAAU,EAAE;IACtD,OAAQD,GAAG,IAAKf,KAAK,CAACe,GAAG,EAAEC,YAAY,CAAC;EAC1C;EAGA,OAAQD,GAAG,IAAKf,KAAK,CAACe,GAAG,CAAC;AAC5B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { DataSource } from './data-source';
|
|
3
|
+
export class ImageSource extends DataSource {}
|
|
4
|
+
_defineProperty(ImageSource, "type", 'template');
|
|
5
|
+
_defineProperty(ImageSource, "testURL", url => false);
|
|
6
|
+
//# sourceMappingURL=image-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-source.js","names":["DataSource","ImageSource","_defineProperty","url"],"sources":["../../../../src/lib/sources/image-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {DataSourceProps} from './data-source';\nimport {DataSource} from './data-source';\nimport {ImageType} from './utils/image-type';\n\n/**\n * Normalized capabilities of an Image service\n * @example\n * The WMSService will normalize the response to the WMS `GetCapabilities`\n * data structure extracted from WMS XML response into an ImageSourceMetadata.\n */\nexport type ImageSourceMetadata = {\n name: string;\n title?: string;\n abstract?: string;\n keywords: string[];\n layers: ImageSourceLayer[];\n};\n\n/** Description of one data layer in the image source */\nexport type ImageSourceLayer = {\n /** Name of this layer */\n name?: string;\n /** Human readable title of this layer */\n title?: string;\n /** Coordinate systems supported by this layer */\n crs?: string[];\n /** layer limits in unspecified CRS:84-like lng/lat, for quick access w/o CRS calculations. */\n geographicBoundingBox?: [min: [x: number, y: number], max: [x: number, y: number]];\n /** Sub layers of this layer */\n layers?: ImageSourceLayer[];\n\n /** @deprecated from v3.4: non-vis.gl style bounding box. Use `.geographicBoundingBox` instead */\n boundingBox?: [number, number, number, number];\n};\n\n/** Generic parameters for requesting an image from an image source */\nexport type GetImageParameters = {\n /** Layers to render */\n layers: string | string[];\n /** Styling */\n styles?: unknown;\n /** bounding box of the requested map image */\n bbox: [number, number, number, number];\n /** pixel width of returned image */\n width: number;\n /** pixels */\n height: number;\n /** crs for the image (not the bounding box) */\n crs?: string;\n /** requested format for the return image */\n format?: 'image/png';\n};\n\n// Attempt to break down GetImageParameters\nexport type ImageFilters = {\n /** Layers to render */\n layers: string | string[];\n /** Styling */\n styles?: unknown;\n};\n\nexport type ImageRegion = {\n /** bounding box of the requested map image */\n bbox: [number, number, number, number];\n};\n\nexport type ImageFormat = {\n /** pixel width of returned image */\n width: number;\n /** pixels */\n height: number;\n /** crs for the image (not the bounding box) */\n crs?: string;\n /** requested format for the return image */\n format?: 'image/png';\n};\n\nexport type ImageSourceProps = DataSourceProps;\n\n/**\n * MapImageSource - data sources that allow data to be queried by (geospatial) extents\n * @note\n * - If geospatial, bounding box is expected to be in web mercator coordinates\n */\nexport abstract class ImageSource<\n PropsT extends ImageSourceProps = ImageSourceProps\n> extends DataSource<PropsT> {\n static type: string = 'template';\n static testURL = (url: string): boolean => false;\n\n abstract getMetadata(): Promise<ImageSourceMetadata>;\n abstract getImage(parameters: GetImageParameters): Promise<ImageType>;\n}\n"],"mappings":";AAGA,SAAQA,UAAU,QAAO,eAAe;AAmFxC,OAAO,MAAeC,WAAW,SAEvBD,UAAU,CAAS;AAM5BE,eAAA,CARqBD,WAAW,UAGT,UAAU;AAAAC,eAAA,CAHZD,WAAW,aAIbE,GAAW,IAAc,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-tile-source.js","names":[],"sources":["../../../../src/lib/sources/image-tile-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {ImageType} from './utils/image-type';\nimport type {TileSource, TileSourceMetadata} from './tile-source';\nimport type {GetTileParameters} from './tile-source';\n\n/**\n * MapTileSource - data sources that allow data to be queried by (geospatial) tile\n * @note If geospatial, bounding box is expected to be in web mercator coordinates\n */\nexport interface ImageTileSource<MetadataT extends TileSourceMetadata = TileSourceMetadata>\n extends TileSource<MetadataT> {\n getImageTile(parameters: GetTileParameters): Promise<ImageType | null>;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-source.js","names":[],"sources":["../../../../src/lib/sources/tile-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n/**\n * Normalized capabilities of an Image service\n * Sources are expected to normalize the response to capabilities\n * @example\n * A WMS service would normalize the response to the WMS `GetCapabilities` data structure extracted from WMS XML response\n * into an TileSourceMetadata.\n */\nexport type TileSourceMetadata = {\n format?: string;\n formatHeader?: unknown;\n\n /** Name of the tileset (extracted from JSON metadata if available) */\n name?: string;\n title?: string;\n abstract?: string;\n keywords?: string[];\n /** Attribution string (extracted from JSON metadata if available) */\n attributions?: string[];\n\n /** Minimal zoom level of tiles in this tileset */\n minZoom?: number;\n /** Maximal zoom level of tiles in this tileset */\n maxZoom?: number;\n /** Bounding box of tiles in this tileset `[[w, s], [e, n]]` */\n boundingBox?: [min: [x: number, y: number], max: [x: number, y: number]];\n\n /** Layer information */\n layer?: {\n name: string;\n title?: string;\n srs?: string[];\n boundingBox?: [number, number, number, number];\n layers: TileSourceLayer[];\n };\n};\n\n/**\n * Description of one data layer in the image source\n */\nexport type TileSourceLayer = {\n name: string;\n title?: string;\n srs?: string[];\n boundingBox?: [number, number, number, number];\n layers: TileSourceLayer[];\n};\n\n/**\n * Generic parameters for requesting an image from an image source\n */\nexport type GetTileParameters = {\n /** Layers to render */\n layers: string | string[];\n /** Styling */\n styles?: unknown;\n /** bounding box of the requested map image */\n zoom: number;\n /** tile x coordinate */\n x: number;\n /** tile y coordinate */\n y: number;\n /** srs for the image (not the bounding box) */\n srs?: string;\n /** requested format for the return image */\n format?: 'image/png';\n};\n\nexport type TileLoadParameters = {\n index: {x: number; y: number; z: number};\n id: string;\n bbox: TileBoundingBox;\n zoom?: number;\n url?: string | null;\n signal?: AbortSignal;\n userData?: Record<string, any>;\n};\n\n/** deck.gl compatible bounding box */\nexport type TileBoundingBox = NonGeoBoundingBox | GeoBoundingBox;\nexport type GeoBoundingBox = {west: number; north: number; east: number; south: number};\nexport type NonGeoBoundingBox = {left: number; top: number; right: number; bottom: number};\n\n/**\n * Props for a TileSource\n */\nexport type TileSourceProps = {};\n\n/**\n * MapTileSource - data sources that allow data to be queried by (geospatial) extents\n * @note\n * - If geospatial, bounding box is expected to be in web mercator coordinates\n */\nexport interface TileSource<MetadataT extends TileSourceMetadata> {\n getMetadata(): Promise<MetadataT>;\n /** Flat parameters */\n getTile(parameters: GetTileParameters): Promise<unknown>;\n /** deck.gl style parameters */\n getTileData(parameters: TileLoadParameters): Promise<unknown | null>;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-type.js","names":[],"sources":["../../../../../src/lib/sources/utils/image-type.ts"],"sourcesContent":["/** Supported Image Types @note duplicates definition in images/schema to avoid circular deps */\nexport type ImageType = ImageBitmap | ImageDataType | HTMLImageElement;\n\n/** data images @note duplicates definition in images/schema to avoid circular deps */\nexport type ImageDataType = {\n data: Uint8Array;\n width: number;\n height: number;\n compressed?: boolean;\n};\n"],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getFetchFunction(options) {
|
|
2
|
+
const fetchFunction = options === null || options === void 0 ? void 0 : options.fetch;
|
|
3
|
+
if (fetchFunction && typeof fetchFunction === 'function') {
|
|
4
|
+
return (url, fetchOptions) => fetchFunction(url, fetchOptions);
|
|
5
|
+
}
|
|
6
|
+
const fetchOptions = options === null || options === void 0 ? void 0 : options.fetch;
|
|
7
|
+
if (fetchOptions && typeof fetchOptions !== 'function') {
|
|
8
|
+
return url => fetch(url, fetchOptions);
|
|
9
|
+
}
|
|
10
|
+
return url => fetch(url);
|
|
11
|
+
}
|
|
12
|
+
export function mergeImageServiceProps(props) {
|
|
13
|
+
return {
|
|
14
|
+
...props,
|
|
15
|
+
loadOptions: {
|
|
16
|
+
...props.loadOptions,
|
|
17
|
+
fetch: getFetchFunction(props.loadOptions)
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["getFetchFunction","options","fetchFunction","fetch","url","fetchOptions","mergeImageServiceProps","props","loadOptions"],"sources":["../../../../../src/lib/sources/utils/utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/**\n * Gets the current fetch function from options\n * @todo - move to loader-utils module\n * @todo - use in core module counterpart\n * @param options\n * @param context\n */\nexport function getFetchFunction(options?: LoaderOptions) {\n const fetchFunction = options?.fetch;\n\n // options.fetch can be a function\n if (fetchFunction && typeof fetchFunction === 'function') {\n return (url: string, fetchOptions?: RequestInit) => fetchFunction(url, fetchOptions);\n }\n\n // options.fetch can be an options object, use global fetch with those options\n const fetchOptions = options?.fetch;\n if (fetchOptions && typeof fetchOptions !== 'function') {\n return (url) => fetch(url, fetchOptions);\n }\n\n // else return the global fetch function\n return (url) => fetch(url);\n}\n\nexport function mergeImageServiceProps<Props extends {loadOptions?: any}>(\n props: Props\n): Required<Props> {\n // @ts-expect-error\n return {\n // Default fetch\n ...props,\n loadOptions: {\n ...props.loadOptions,\n fetch: getFetchFunction(props.loadOptions)\n }\n };\n}\n"],"mappings":"AAWA,OAAO,SAASA,gBAAgBA,CAACC,OAAuB,EAAE;EACxD,MAAMC,aAAa,GAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,KAAK;EAGpC,IAAID,aAAa,IAAI,OAAOA,aAAa,KAAK,UAAU,EAAE;IACxD,OAAO,CAACE,GAAW,EAAEC,YAA0B,KAAKH,aAAa,CAACE,GAAG,EAAEC,YAAY,CAAC;EACtF;EAGA,MAAMA,YAAY,GAAGJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,KAAK;EACnC,IAAIE,YAAY,IAAI,OAAOA,YAAY,KAAK,UAAU,EAAE;IACtD,OAAQD,GAAG,IAAKD,KAAK,CAACC,GAAG,EAAEC,YAAY,CAAC;EAC1C;EAGA,OAAQD,GAAG,IAAKD,KAAK,CAACC,GAAG,CAAC;AAC5B;AAEA,OAAO,SAASE,sBAAsBA,CACpCC,KAAY,EACK;EAEjB,OAAO;IAEL,GAAGA,KAAK;IACRC,WAAW,EAAE;MACX,GAAGD,KAAK,CAACC,WAAW;MACpBL,KAAK,EAAEH,gBAAgB,CAACO,KAAK,CAACC,WAAW;IAC3C;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-source.js","names":[],"sources":["../../../../src/lib/sources/vector-tile-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {TileSource, TileSourceMetadata} from './tile-source';\nimport {GetTileParameters} from './tile-source';\n\n/**\n * MapTileSource - data sources that allow data to be queried by (geospatial) tile\n * @note If geospatial, bounding box is expected to be in web mercator coordinates\n */\nexport interface VectorTileSource<MetadataT extends TileSourceMetadata = TileSourceMetadata>\n extends TileSource<MetadataT> {\n getVectorTile(parameters: GetTileParameters): Promise<unknown | null>;\n}\n"],"mappings":""}
|