@zenfs/dom 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fetch.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  export declare const fetchIsAvailable: boolean;
3
2
  /**
4
3
  * Asynchronously download a file as a buffer or a JSON object.
@@ -7,9 +6,9 @@ export declare const fetchIsAvailable: boolean;
7
6
  * constants.
8
7
  * @hidden
9
8
  */
10
- export declare function fetchFile(p: string, type: 'buffer'): Promise<Buffer>;
9
+ export declare function fetchFile(p: string, type: 'buffer'): Promise<Uint8Array>;
11
10
  export declare function fetchFile(p: string, type: 'json'): Promise<any>;
12
- export declare function fetchFile(p: string, type: string): Promise<any>;
11
+ export declare function fetchFile(p: string, type: 'buffer' | 'json'): Promise<any>;
13
12
  /**
14
13
  * Asynchronously retrieves the size of the given file in bytes.
15
14
  * @hidden
package/dist/fetch.js CHANGED
@@ -1,16 +1,6 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /**
11
2
  * Contains utility methods for network I/O (using fetch)
12
3
  */
13
- import { Buffer } from 'buffer';
14
4
  import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
15
5
  export const fetchIsAvailable = typeof fetch !== 'undefined' && fetch !== null;
16
6
  /**
@@ -19,34 +9,29 @@ export const fetchIsAvailable = typeof fetch !== 'undefined' && fetch !== null;
19
9
  function convertError(e) {
20
10
  throw new ApiError(ErrorCode.EIO, e.message);
21
11
  }
22
- export function fetchFile(p, type) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const response = yield fetch(p).catch(convertError);
25
- if (!response.ok) {
26
- throw new ApiError(ErrorCode.EIO, `fetch error: response returned code ${response.status}`);
27
- }
28
- switch (type) {
29
- case 'buffer':
30
- const buf = yield response.arrayBuffer().catch(convertError);
31
- return Buffer.from(buf);
32
- case 'json':
33
- const json = yield response.json().catch(convertError);
34
- return json;
35
- default:
36
- throw new ApiError(ErrorCode.EINVAL, 'Invalid download type: ' + type);
37
- }
38
- });
12
+ export async function fetchFile(p, type) {
13
+ const response = await fetch(p).catch(convertError);
14
+ if (!response.ok) {
15
+ throw new ApiError(ErrorCode.EIO, `fetch error: response returned code ${response.status}`);
16
+ }
17
+ switch (type) {
18
+ case 'buffer':
19
+ const arrayBuffer = await response.arrayBuffer().catch(convertError);
20
+ return new Uint8Array(arrayBuffer);
21
+ case 'json':
22
+ return response.json().catch(convertError);
23
+ default:
24
+ throw new ApiError(ErrorCode.EINVAL, 'Invalid download type: ' + type);
25
+ }
39
26
  }
40
27
  /**
41
28
  * Asynchronously retrieves the size of the given file in bytes.
42
29
  * @hidden
43
30
  */
44
- export function fetchFileSize(p) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const response = yield fetch(p, { method: 'HEAD' }).catch(convertError);
47
- if (!response.ok) {
48
- throw new ApiError(ErrorCode.EIO, `fetch HEAD error: response returned code ${response.status}`);
49
- }
50
- return parseInt(response.headers.get('Content-Length') || '-1', 10);
51
- });
31
+ export async function fetchFileSize(p) {
32
+ const response = await fetch(p, { method: 'HEAD' }).catch(convertError);
33
+ if (!response.ok) {
34
+ throw new ApiError(ErrorCode.EIO, `fetch HEAD error: response returned code ${response.status}`);
35
+ }
36
+ return parseInt(response.headers.get('Content-Length') || '-1', 10);
52
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -37,31 +37,20 @@
37
37
  "format": "prettier --write src",
38
38
  "format:check": "prettier --check src",
39
39
  "lint": "eslint src",
40
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
41
40
  "build": "node scripts/build.mjs",
42
- "build:docs": "typedoc --out docs --name ZenFS src/index.ts",
41
+ "build:docs": "typedoc --out docs --name 'ZenFS DOM' src/index.ts",
43
42
  "prepublishOnly": "npm run build"
44
43
  },
45
44
  "devDependencies": {
46
- "@jest/globals": "^29.5.0",
47
- "@types/jest": "^29.5.1",
48
- "@types/node": "^14.18.62",
49
45
  "@typescript-eslint/eslint-plugin": "^5.55.0",
50
46
  "@typescript-eslint/parser": "^5.55.0",
51
- "archiver": "~2.1.1",
52
- "buffer": "~5.1.0",
53
- "cross-env": "^7.0.3",
54
47
  "esbuild": "^0.17.18",
55
- "esbuild-plugin-polyfill-node": "^0.3.0",
56
48
  "eslint": "^8.36.0",
57
- "jest": "^29.5.0",
58
- "path": "^0.12.7",
59
49
  "prettier": "^2.8.7",
60
- "ts-jest": "^29.1.0",
61
50
  "typedoc": "^0.25.1",
62
51
  "typescript": "5.2.2"
63
52
  },
64
53
  "dependencies": {
65
- "@zenfs/core": "^0.0.8"
54
+ "@zenfs/core": "^0.1.0"
66
55
  }
67
56
  }