@dnax/core 0.45.2 → 0.45.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/utils/index.ts +92 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.45.2",
3
+ "version": "0.45.4",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/utils/index.ts CHANGED
@@ -14,6 +14,7 @@ import mime from "mime-types";
14
14
  import * as uuid from "uuid";
15
15
  import * as urlencode from "urlencode";
16
16
  import dotJson from "dot-object";
17
+ import fs from "fs-extra";
17
18
  import deepCopy from "deepcopy";
18
19
  import { applyPatch, createPatch, Pointer } from "rfc6902";
19
20
 
@@ -383,8 +384,99 @@ const password = {
383
384
  verify: verifyHashPassword,
384
385
  };
385
386
 
387
+ const file = {
388
+ cp: async (src: string, des: string) => {
389
+ return new Promise(async (resolve, reject) => {
390
+ try {
391
+ await fs.copyFile(src, des);
392
+ let file = await Bun.file(des);
393
+ resolve({
394
+ original_name: file.name,
395
+ name: file.name,
396
+ lastModified: moment.unix(file.lastModified).toDate(),
397
+ size: file.size,
398
+ type: file.type,
399
+ });
400
+ } catch (err: any) {
401
+ reject(err?.message);
402
+ }
403
+ });
404
+ },
405
+ mv: async (source: string, destination: string) => {
406
+ return new Promise(async (resolve, reject) => {
407
+ try {
408
+ await fs.move(source, destination);
409
+ resolve(true);
410
+ } catch (err: any) {
411
+ reject(err?.message);
412
+ }
413
+ });
414
+ },
415
+ exist: async (path: string): Promise<boolean> => {
416
+ return new Promise(async (resolve, reject) => {
417
+ try {
418
+ let exist = await fs.pathExists(path);
419
+ resolve(exist);
420
+ } catch (err: any) {
421
+ reject(err?.message);
422
+ }
423
+ });
424
+ },
425
+ saveToDisk: async (
426
+ path: string,
427
+ data: any
428
+ ): Promise<{
429
+ size: number;
430
+ type: string;
431
+ lastModified: Date;
432
+ original_name: string | undefined;
433
+ name: string | undefined;
434
+ }> => {
435
+ // save to disk
436
+ return new Promise(async (resolve, reject) => {
437
+ try {
438
+ await Bun.write(path, data, {
439
+ createPath: true,
440
+ });
441
+ let file = await Bun.file(path);
442
+ resolve({
443
+ original_name: file.name,
444
+ name: file.name,
445
+ lastModified: moment.unix(file.lastModified).toDate(),
446
+ size: file.size,
447
+ type: file.type,
448
+ });
449
+ } catch (err: any) {
450
+ reject(err?.message);
451
+ }
452
+ });
453
+ },
454
+
455
+ deleteFromDisk: async (path: string) => {
456
+ return new Promise(async (resolve, reject) => {
457
+ try {
458
+ // check if path file exists
459
+ let exist = await fs.pathExists(path);
460
+ let stat = await fs.stat(path);
461
+ if (stat.isDirectory()) {
462
+ reject("delete directory not allowed");
463
+ }
464
+
465
+ if (!exist) {
466
+ reject("File not found");
467
+ }
468
+ await fs.unlink(path);
469
+ resolve(true);
470
+ } catch (err: any) {
471
+ reject(err?.message);
472
+ }
473
+ });
474
+ },
475
+ };
476
+
386
477
  const contextError = ContextError;
387
478
  export {
479
+ file,
388
480
  mime,
389
481
  dotJson,
390
482
  uuid,