node-datalith 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/lib/file.d.ts +2 -2
  2. package/lib/lib.js +47 -49
  3. package/package.json +12 -9
package/lib/file.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { TimeoutResponse } from "fetch-helper-x";
2
- import { ImageSize } from "./image.js";
1
+ import type { TimeoutResponse } from "fetch-helper-x";
2
+ import type { ImageSize } from "./image.js";
3
3
  /**
4
4
  * Represents a file resource with metadata such as ETag, content type, and size.
5
5
  *
package/lib/lib.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Readable } from "node:stream";
2
2
  import { nodeReadableToWebReadableStream, timeoutFetch } from "fetch-helper-x";
3
- import { BadRequestError, NotFoundError, PayloadTooLargeError } from "./errors.js";
3
+ import { BadRequestError, NotFoundError, PayloadTooLargeError, } from "./errors.js";
4
4
  import { File } from "./file.js";
5
5
  import { Image } from "./image.js";
6
6
  import { Resource } from "./resource.js";
@@ -169,22 +169,21 @@ export class Datalith {
169
169
  idleTimeout: typeof options.idleTimeout !== "undefined" ? options.idleTimeout : DEFAULT_IDLE_TIMEOUT,
170
170
  });
171
171
  switch (response.status) {
172
- case 200:
173
- {
174
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175
- const etag = response.headers.get("etag");
176
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
177
- const date = response.headers.get("date");
178
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
179
- const contentType = response.headers.get("content-type");
180
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
181
- const contentLength = parseInt(response.headers.get("content-length"));
182
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
183
- const contentDisposition = response.headers.get("content-disposition");
184
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
185
- const body = response.body;
186
- return new File(response, etag, date, contentType, contentLength, contentDisposition, body);
187
- }
172
+ case 200: {
173
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
174
+ const etag = response.headers.get("etag");
175
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
176
+ const date = response.headers.get("date");
177
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
178
+ const contentType = response.headers.get("content-type");
179
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
180
+ const contentLength = parseInt(response.headers.get("content-length"));
181
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
182
+ const contentDisposition = response.headers.get("content-disposition");
183
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
184
+ const body = response.body;
185
+ return new File(response, etag, date, contentType, contentLength, contentDisposition, body);
186
+ }
188
187
  case 400:
189
188
  await response.cancelBody();
190
189
  throw new BadRequestError();
@@ -220,38 +219,37 @@ export class Datalith {
220
219
  idleTimeout: typeof options.idleTimeout !== "undefined" ? options.idleTimeout : DEFAULT_IDLE_TIMEOUT,
221
220
  });
222
221
  switch (response.status) {
223
- case 200:
224
- {
225
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
226
- const etag = response.headers.get("etag");
227
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
228
- const date = response.headers.get("date");
229
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
230
- const contentType = response.headers.get("content-type");
231
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
232
- const contentLength = parseInt(response.headers.get("content-length"));
233
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
234
- const contentDisposition = response.headers.get("content-disposition");
235
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
236
- const body = response.body;
237
- const getNullableNumber = (fieldName) => {
238
- const s = response.headers.get(fieldName);
239
- if (s === null) {
240
- return null;
241
- }
242
- return parseInt(s);
243
- };
244
- const imageWidth = getNullableNumber("x-image-width");
245
- const imageHeight = getNullableNumber("x-image-height");
246
- let imageSize = null;
247
- if (imageWidth !== null && imageHeight !== null) {
248
- imageSize = {
249
- width: imageWidth,
250
- height: imageHeight,
251
- };
222
+ case 200: {
223
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
224
+ const etag = response.headers.get("etag");
225
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
226
+ const date = response.headers.get("date");
227
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
228
+ const contentType = response.headers.get("content-type");
229
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
230
+ const contentLength = parseInt(response.headers.get("content-length"));
231
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
232
+ const contentDisposition = response.headers.get("content-disposition");
233
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
234
+ const body = response.body;
235
+ const getNullableNumber = (fieldName) => {
236
+ const s = response.headers.get(fieldName);
237
+ if (s === null) {
238
+ return null;
252
239
  }
253
- return new File(response, etag, date, contentType, contentLength, contentDisposition, body, imageSize);
240
+ return parseInt(s);
241
+ };
242
+ const imageWidth = getNullableNumber("x-image-width");
243
+ const imageHeight = getNullableNumber("x-image-height");
244
+ let imageSize = null;
245
+ if (imageWidth !== null && imageHeight !== null) {
246
+ imageSize = {
247
+ width: imageWidth,
248
+ height: imageHeight,
249
+ };
254
250
  }
251
+ return new File(response, etag, date, contentType, contentLength, contentDisposition, body, imageSize);
252
+ }
255
253
  case 400:
256
254
  await response.cancelBody();
257
255
  throw new BadRequestError();
@@ -357,7 +355,7 @@ export const validateCenterCrop = (centerCrop) => {
357
355
  if (typeof centerCrop === "undefined") {
358
356
  return true;
359
357
  }
360
- return (/^-?\d+\.?\d*:-?\d+\.?\d*$/).test(centerCrop);
358
+ return (/^-?\d+\.?\d*:-?\d+\.?\d*$/u).test(centerCrop);
361
359
  };
362
360
  /**
363
361
  * Validates if the given resolution is either `undefined`, `"original"`, or follows the format of `"<positive integer>x"`.
@@ -369,5 +367,5 @@ export const validateResolution = (resolution) => {
369
367
  if (resolution === "original") {
370
368
  return true;
371
369
  }
372
- return (/^[1-9][0-9]*x$/).test(resolution);
370
+ return (/^[1-9][0-9]*x$/u).test(resolution);
373
371
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-datalith",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Datalith is a file management system powered by SQLite for metadata storage and the file system for file storage. This library can help you conmunicate with Datalith in Node.js.",
5
5
  "type": "module",
6
6
  "exports": "./lib/lib.js",
@@ -42,20 +42,23 @@
42
42
  },
43
43
  "homepage": "https://magiclen.org/datalith/",
44
44
  "dependencies": {
45
- "@types/node": "^22.5.4",
46
- "fetch-helper-x": "^0.1.5"
45
+ "@types/node": "^22.7.7",
46
+ "fetch-helper-x": "^0.1.7"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/jest": "^29.5.12",
50
- "@typescript-eslint/eslint-plugin": "^7.18.0",
51
- "@typescript-eslint/parser": "^7.18.0",
52
- "eslint": "^8.57.0",
49
+ "@eslint/js": "^9.13.0",
50
+ "@stylistic/eslint-plugin": "^2.9.0",
51
+ "@types/eslint__js": "^8.42.3",
52
+ "@types/jest": "^29.5.13",
53
+ "eslint": "^9.13.0",
53
54
  "eslint-import-resolver-typescript": "^3.6.3",
54
- "eslint-plugin-import": "^2.30.0",
55
+ "eslint-plugin-import": "^2.31.0",
56
+ "globals": "^15.11.0",
55
57
  "jest": "^29.7.0",
56
58
  "rimraf": "^6.0.1",
57
59
  "ts-jest": "^29.2.5",
58
- "typescript": "^5.5.4",
60
+ "typescript": "~5.5.4",
61
+ "typescript-eslint": "^8.10.0",
59
62
  "web-streams-polyfill": "^4.0.0"
60
63
  }
61
64
  }