From e4d0ece093cda6d5f41ddc19cad54897effb661c Mon Sep 17 00:00:00 2001 From: coderiaser Date: Thu, 29 Jan 2026 18:31:10 +0200 Subject: [PATCH] feature: client: dom: rest: migrate to ESM --- client/dom/buffer.mjs | 2 +- client/dom/files.mjs | 2 +- client/dom/index.mjs | 4 +-- client/dom/operations/rename-current.js | 2 +- client/dom/rest.js | 44 ------------------------- client/dom/rest.mjs | 40 ++++++++++++++++++++++ client/modules/markdown.js | 2 +- client/modules/menu/index.js | 2 +- package.json | 1 + 9 files changed, 48 insertions(+), 51 deletions(-) delete mode 100644 client/dom/rest.js create mode 100644 client/dom/rest.mjs diff --git a/client/dom/buffer.mjs b/client/dom/buffer.mjs index 800f88ae..c6d20ccd 100644 --- a/client/dom/buffer.mjs +++ b/client/dom/buffer.mjs @@ -1,6 +1,6 @@ /* global CloudCmd*/ -import tryToPromiseAll from '../../common/try-to-promise-all.js'; import * as Storage from '#dom/storage'; +import tryToPromiseAll from '../../common/try-to-promise-all.js'; const CLASS = 'cut-file'; const COPY = 'copy'; diff --git a/client/dom/files.mjs b/client/dom/files.mjs index 238384be..395ac0fa 100644 --- a/client/dom/files.mjs +++ b/client/dom/files.mjs @@ -2,7 +2,7 @@ import itype from 'itype'; import {promisify} from 'es6-promisify'; import * as load from '#dom/load'; -import RESTful from './rest.js'; +import * as RESTful from '#dom/rest'; const Promises = {}; const FILES_JSON = 'config|modules'; diff --git a/client/dom/index.mjs b/client/dom/index.mjs index 31af2e3e..9b4d23a0 100644 --- a/client/dom/index.mjs +++ b/client/dom/index.mjs @@ -4,9 +4,9 @@ import * as Files from '#dom/files'; import * as Dialog from '#dom/dialog'; import * as Events from '#dom/events'; import {getExt} from '#common/util'; -import * as Images from './images.mjs'; -import RESTful from './rest.js'; import * as Storage from '#dom/storage'; +import * as Images from './images.mjs'; +import * as RESTful from '#dom/rest'; import renameCurrent from './operations/rename-current.js'; import * as CurrentFile from './current-file.mjs'; import * as DOMTree from './dom-tree.mjs'; diff --git a/client/dom/operations/rename-current.js b/client/dom/operations/rename-current.js index 06ccf251..e8d29987 100644 --- a/client/dom/operations/rename-current.js +++ b/client/dom/operations/rename-current.js @@ -5,7 +5,7 @@ const capitalize = require('just-capitalize'); const _Dialog = require('#dom/dialog'); const Storage = require('#dom/storage'); -const RESTful = require('../rest'); +const RESTful = require('#dom/rest'); const _currentFile = require('../current-file.mjs'); diff --git a/client/dom/rest.js b/client/dom/rest.js deleted file mode 100644 index d9ee6c13..00000000 --- a/client/dom/rest.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -const {tryToCatch} = require('try-to-catch'); - -const {encode} = require('../../common/entity'); - -const Images = require('./images.mjs'); -const IO = require('./io'); -const Dialog = require('#dom/dialog'); - -const handleError = (promise) => async (...args) => { - const [e, data] = await tryToCatch(promise, ...args); - - if (!e) - return [e, data]; - - const encoded = encode(e.message); - - Images.show.error(encoded); - Dialog.alert(encoded); - - return [e, data]; -}; - -module.exports.delete = handleError(IO.delete); -module.exports.patch = handleError(IO.patch); -module.exports.write = handleError(IO.write); -module.exports.createDirectory = handleError(IO.createDirectory); -module.exports.read = handleError(IO.read); -module.exports.copy = handleError(IO.copy); -module.exports.pack = handleError(IO.pack); -module.exports.extract = handleError(IO.extract); -module.exports.move = handleError(IO.move); -module.exports.rename = handleError(IO.rename); - -module.exports.Config = { - read: handleError(IO.Config.read), - write: handleError(IO.Config.write), -}; - -module.exports.Markdown = { - read: handleError(IO.Markdown.read), - render: handleError(IO.Markdown.render), -}; diff --git a/client/dom/rest.mjs b/client/dom/rest.mjs new file mode 100644 index 00000000..092096df --- /dev/null +++ b/client/dom/rest.mjs @@ -0,0 +1,40 @@ +import {tryToCatch} from 'try-to-catch'; +import * as Dialog from '#dom/dialog'; +import {encode} from '../../common/entity.js'; +import * as Images from './images.mjs'; +import IO from './io/index.js'; + +const handleError = (promise) => async (...args) => { + const [e, data] = await tryToCatch(promise, ...args); + + if (!e) + return [e, data]; + + const encoded = encode(e.message); + + Images.show.error(encoded); + Dialog.alert(encoded); + + return [e, data]; +}; + +export const remove = handleError(IO.delete); +export const patch = handleError(IO.patch); +export const write = handleError(IO.write); +export const createDirectory = handleError(IO.createDirectory); +export const read = handleError(IO.read); +export const copy = handleError(IO.copy); +export const pack = handleError(IO.pack); +export const extract = handleError(IO.extract); +export const move = handleError(IO.move); +export const rename = handleError(IO.rename); + +export const Config = { + read: handleError(IO.Config.read), + write: handleError(IO.Config.write), +}; + +export const Markdown = { + read: handleError(IO.Markdown.read), + render: handleError(IO.Markdown.render), +}; diff --git a/client/modules/markdown.js b/client/modules/markdown.js index 16d73546..3ccd5805 100644 --- a/client/modules/markdown.js +++ b/client/modules/markdown.js @@ -6,7 +6,7 @@ CloudCmd.Markdown = exports; const createElement = require('@cloudcmd/create-element'); const Images = require('../dom/images.mjs'); -const {Markdown} = require('../dom/rest'); +const {Markdown} = require('#dom/rest'); const {alert} = require('#dom/dialog'); module.exports.init = async () => { diff --git a/client/modules/menu/index.js b/client/modules/menu/index.js index b8b04e11..e709dc44 100644 --- a/client/modules/menu/index.js +++ b/client/modules/menu/index.js @@ -8,7 +8,7 @@ const createElement = require('@cloudcmd/create-element'); const {FS} = require('../../../common/cloudfunc.mjs'); const {getIdBySrc} = require('#dom/load'); -const RESTful = require('../../dom/rest'); +const RESTful = require('#dom/rest'); const {config, Key} = CloudCmd; diff --git a/package.json b/package.json index d6f85a30..4c3cb32a 100644 --- a/package.json +++ b/package.json @@ -224,6 +224,7 @@ "#dom/files": "./client/dom/files.mjs", "#dom/upload-files": "./client/dom/upload-files.mjs", "#dom/storage": "./client/dom/storage.mjs", + "#dom/rest": "./client/dom/rest.mjs", "#common/util": "./common/util.mjs" }, "engines": {