restafary 13.0.0 → 13.0.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/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.02.13, v13.0.2
2
+
3
+ feature:
4
+ - d5fa7ec restafary: patchfile v5.0.0
5
+
6
+ 2026.02.04, v13.0.1
7
+
8
+ feature:
9
+ - dec7823 restafary: migrate to ESM
10
+
1
11
  2026.01.31, v13.0.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Restafary [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
2
2
 
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/restafary.svg?style=flat
4
+ [BuildStatusURL]: https://github.com/coderaiser/node-restafary/actions?query=workflow%3A%22Node+CI%22 "Build Status"
5
+ [BuildStatusIMGURL]: https://github.com/coderaiser/node-restafary/workflows/Node%20CI/badge.svg
6
+ [LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
7
+ [NPMURL]: https://npmjs.org/package/restafary "npm"
8
+ [LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
9
+
3
10
  **REST** for **CRUD** file operations.
4
11
 
5
12
  ## What is it?
@@ -18,12 +25,12 @@
18
25
  |:------------|:--------|:--------------|:------------------|:------------------------------|
19
26
  |`fs` |`GET` | | |get file or dir content |
20
27
  | | |`sort` | |sort dir content by `name`, |
21
- | | | | |`size` or `time` |
28
+ | | | | |`size` or `date` |
22
29
  | | |`order` | |order of sorting, can be: |
23
30
  | | | | |`asc` or `desc` |
24
31
  | | |`raw` | |get file or raw dir content |
25
32
  | | |`size` | |get file or dir size |
26
- | | |`raw-size` | |get raw size |
33
+ | | |`raw-size` | |get raw size |
27
34
  | | |`hash` | |get file hash |
28
35
  | | |`download` | |content disposition attachment |
29
36
  | |`PUT` | |file content |create/write file |
@@ -36,10 +43,9 @@
36
43
  ## How to use?
37
44
 
38
45
  ```js
39
- const http = require('node:http');
40
- const restafary = require('restafary');
41
-
42
- const express = require('express');
46
+ import http from 'node:http';
47
+ import {restafary} from 'restafary';
48
+ import express from 'express';
43
49
 
44
50
  const app = express();
45
51
  const server = http.createServer(app);
@@ -59,10 +65,3 @@ server.listen(port, ip);
59
65
  ## License
60
66
 
61
67
  MIT
62
-
63
- [NPMIMGURL]: https://img.shields.io/npm/v/restafary.svg?style=flat
64
- [BuildStatusURL]: https://github.com/coderaiser/node-restafary/actions?query=workflow%3A%22Node+CI%22 "Build Status"
65
- [BuildStatusIMGURL]: https://github.com/coderaiser/node-restafary/workflows/Node%20CI/badge.svg
66
- [LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
67
- [NPMURL]: https://npmjs.org/package/restafary "npm"
68
- [LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
package/client/index.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict';
2
-
3
1
  let FS = '/api/v1/fs';
4
2
  const isFn = (a) => typeof a === 'function';
5
3
 
6
- module.exports.prefix = (prefix) => {
4
+ export const prefix = (prefix) => {
7
5
  FS = prefix;
8
6
  };
9
7
 
10
- module.exports.delete = (url, data, callback) => {
8
+ export const remove = (url, data, callback) => {
11
9
  if (!callback && isFn(data)) {
12
10
  callback = data;
13
11
  data = null;
@@ -21,7 +19,7 @@ module.exports.delete = (url, data, callback) => {
21
19
  });
22
20
  };
23
21
 
24
- module.exports.patch = (url, data, callback) => {
22
+ export const patch = (url, data, callback) => {
25
23
  if (!callback && isFn(data)) {
26
24
  callback = data;
27
25
  data = null;
@@ -35,7 +33,7 @@ module.exports.patch = (url, data, callback) => {
35
33
  });
36
34
  };
37
35
 
38
- module.exports.write = (url, data, callback) => {
36
+ export const write = (url, data, callback) => {
39
37
  if (!callback && isFn(data)) {
40
38
  callback = data;
41
39
  data = null;
@@ -49,7 +47,7 @@ module.exports.write = (url, data, callback) => {
49
47
  });
50
48
  };
51
49
 
52
- module.exports.read = (url, callback) => {
50
+ export const read = (url, callback) => {
53
51
  sendRequest({
54
52
  method: 'GET',
55
53
  url: FS + url,
@@ -65,7 +63,8 @@ function sendRequest({url, data, method, callback}) {
65
63
  * when we send ajax request -
66
64
  * no need in hash so we escape #
67
65
  */
68
- module.exports._escape = escape;
66
+ export const _escape = escape;
67
+
69
68
  function escape(str) {
70
69
  return encodeURI(str).replace(/#/g, '%23');
71
70
  }
package/dist/restafary.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.restafary=t():e.restafary=t()}(globalThis,()=>(()=>{"use strict";var e={817(e){let t="/api/v1/fs";const r=e=>"function"==typeof e;function o({url:e,data:t,method:o,callback:n}){!function(e,t){const{url:o,data:a,method:n}=e,l=new XMLHttpRequest;if(!r(t))throw Error("Callback should be function!");l.open(n,o,!0),l.addEventListener("error",t),l.addEventListener("load",()=>{if(l.status>=200&&l.status<400)return t(null,l.responseText);t(Error(l.responseText))}),l.send(a)}({method:o,data:t,url:a(e)},n)}function a(e){return encodeURI(e).replace(/#/g,"%23")}e.exports.prefix=e=>{t=e},e.exports.delete=(e,a,n)=>{!n&&r(a)&&(n=a,a=null),o({method:"DELETE",url:t+e,data:a,callback:n})},e.exports.patch=(e,a,n)=>{!n&&r(a)&&(n=a,a=null),o({method:"PATCH",url:t+e,data:a,callback:n})},e.exports.write=(e,a,n)=>{!n&&r(a)&&(n=a,a=null),o({method:"PUT",url:t+e,data:a,callback:n})},e.exports.read=(e,r)=>{o({method:"GET",url:t+e,callback:r})},e.exports._escape=a}},t={};return function r(o){var a=t[o];if(void 0!==a)return a.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,r),n.exports}(817)})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.restafary=t():e.restafary=t()}(globalThis,()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{_escape:()=>s,patch:()=>l,prefix:()=>a,read:()=>c,remove:()=>n,write:()=>d});let o="/api/v1/fs";const r=e=>"function"==typeof e,a=e=>{o=e},n=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"DELETE",url:o+e,data:t,callback:a})},l=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"PATCH",url:o+e,data:t,callback:a})},d=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"PUT",url:o+e,data:t,callback:a})},c=(e,t)=>{u({method:"GET",url:o+e,callback:t})};function u({url:e,data:t,method:o,callback:a}){!function(e,t){const{url:o,data:a,method:n}=e,l=new XMLHttpRequest;if(!r(t))throw Error("Callback should be function!");l.open(n,o,!0),l.addEventListener("error",t),l.addEventListener("load",()=>{if(l.status>=200&&l.status<400)return t(null,l.responseText);t(Error(l.responseText))}),l.send(a)}({method:o,data:t,url:f(e)},a)}const s=f;function f(e){return encodeURI(e).replace(/#/g,"%23")}return t})());
2
2
  //# sourceMappingURL=restafary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"restafary.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAmB,UAAID,IAEvBD,EAAgB,UAAIC,GACrB,CATD,CASGK,WAAY,I,iCCPf,IAAIC,EAAK,aACT,MAAMC,EAAQC,GAAmB,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ClErBS,EAA2B,CAAC,E,OAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAapC,QAGrB,IAAIC,EAASgC,EAAyBE,GAAY,CAGjDnC,QAAS,CAAC,GAOX,OAHAsC,EAAoBH,GAAUlC,EAAQA,EAAOD,QAASkC,GAG/CjC,EAAOD,OACf,CCnB0BkC,CAAoB,I","sources":["file://restafary/webpack/universalModuleDefinition","file://restafary/client/index.js","file://restafary/webpack/bootstrap","file://restafary/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"restafary\"] = factory();\n\telse\n\t\troot[\"restafary\"] = factory();\n})(globalThis, () => {\nreturn ","'use strict';\n\nlet FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nmodule.exports.prefix = (prefix) => {\n FS = prefix;\n};\n\nmodule.exports.delete = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nmodule.exports._escape = escape;\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module used 'module' so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(817);\n"],"names":["root","factory","exports","module","define","amd","globalThis","FS","isFn","a","sendRequest","url","data","method","callback","params","request","XMLHttpRequest","Error","open","addEventListener","load","status","responseText","send","ajax","escape","str","encodeURI","replace","prefix","patch","write","read","_escape","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"ignoreList":[],"sourceRoot":""}
1
+ {"version":3,"file":"restafary.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAmB,UAAID,IAEvBD,EAAgB,UAAIC,GACrB,CATD,CASGK,WAAY,I,mBCRf,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IA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O,EAAQI,iBAAiB,OATZC,KACT,GAAIL,EAAQM,QAAU,KAAON,EAAQM,OAAS,IAC1C,OAAOb,EAAS,KAAMO,EAAQO,cAElCd,EAASS,MAAMF,EAAQO,iBAO3BP,EAAQQ,KAAKhB,EACjB,CArCIiB,CAAK,CAACd,SAAQH,OAAMD,IAAKmB,EAAOnB,IAAOE,EAC3C,CAMO,MAAMkB,EAAUD,EAEvB,SAASA,EAAOE,GACZ,OAAOC,UAAUD,GAAKE,QAAQ,KAAM,MACxC,C","sources":["file://restafary/webpack/universalModuleDefinition","file://restafary/webpack/bootstrap","file://restafary/webpack/runtime/define property getters","file://restafary/webpack/runtime/hasOwnProperty shorthand","file://restafary/webpack/runtime/make namespace object","file://restafary/client/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"restafary\"] = factory();\n\telse\n\t\troot[\"restafary\"] = factory();\n})(globalThis, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","let FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nexport const prefix = (prefix) => {\n FS = prefix;\n};\n\nexport const remove = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nexport const _escape = escape;\n\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","FS","isFn","a","prefix","remove","url","data","callback","sendRequest","method","patch","write","read","params","request","XMLHttpRequest","Error","open","addEventListener","load","status","responseText","send","ajax","escape","_escape","str","encodeURI","replace"],"sourceRoot":""}
@@ -24,50 +24,53 @@ return /******/ (() => { // webpackBootstrap
24
24
  /*!*************************!*\
25
25
  !*** ./client/index.js ***!
26
26
  \*************************/
27
- (module) {
27
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
28
28
 
29
- eval("{\n\nlet FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nmodule.exports.prefix = (prefix) => {\n FS = prefix;\n};\n\nmodule.exports[\"delete\"] = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nmodule.exports.read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nmodule.exports._escape = escape;\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n\n\n//# sourceURL=file://restafary/client/index.js\n}");
29
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ _escape: () => (/* binding */ _escape),\n/* harmony export */ patch: () => (/* binding */ patch),\n/* harmony export */ prefix: () => (/* binding */ prefix),\n/* harmony export */ read: () => (/* binding */ read),\n/* harmony export */ remove: () => (/* binding */ remove),\n/* harmony export */ write: () => (/* binding */ write)\n/* harmony export */ });\nlet FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nconst prefix = (prefix) => {\n FS = prefix;\n};\n\nconst remove = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nconst _escape = escape;\n\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n\n\n//# sourceURL=file://restafary/client/index.js\n}");
30
30
 
31
31
  /***/ }
32
32
 
33
33
  /******/ });
34
34
  /************************************************************************/
35
- /******/ // The module cache
36
- /******/ var __webpack_module_cache__ = {};
35
+ /******/ // The require scope
36
+ /******/ var __webpack_require__ = {};
37
37
  /******/
38
- /******/ // The require function
39
- /******/ function __webpack_require__(moduleId) {
40
- /******/ // Check if module is in cache
41
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
42
- /******/ if (cachedModule !== undefined) {
43
- /******/ return cachedModule.exports;
44
- /******/ }
45
- /******/ // Check if module exists (development only)
46
- /******/ if (__webpack_modules__[moduleId] === undefined) {
47
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
48
- /******/ e.code = 'MODULE_NOT_FOUND';
49
- /******/ throw e;
50
- /******/ }
51
- /******/ // Create a new module (and put it into the cache)
52
- /******/ var module = __webpack_module_cache__[moduleId] = {
53
- /******/ // no module.id needed
54
- /******/ // no module.loaded needed
55
- /******/ exports: {}
38
+ /************************************************************************/
39
+ /******/ /* webpack/runtime/define property getters */
40
+ /******/ (() => {
41
+ /******/ // define getter functions for harmony exports
42
+ /******/ __webpack_require__.d = (exports, definition) => {
43
+ /******/ for(var key in definition) {
44
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
45
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
46
+ /******/ }
47
+ /******/ }
56
48
  /******/ };
49
+ /******/ })();
57
50
  /******/
58
- /******/ // Execute the module function
59
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
52
+ /******/ (() => {
53
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
54
+ /******/ })();
60
55
  /******/
61
- /******/ // Return the exports of the module
62
- /******/ return module.exports;
63
- /******/ }
56
+ /******/ /* webpack/runtime/make namespace object */
57
+ /******/ (() => {
58
+ /******/ // define __esModule on exports
59
+ /******/ __webpack_require__.r = (exports) => {
60
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
61
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
62
+ /******/ }
63
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
64
+ /******/ };
65
+ /******/ })();
64
66
  /******/
65
67
  /************************************************************************/
66
68
  /******/
67
69
  /******/ // startup
68
70
  /******/ // Load entry module and return exports
69
71
  /******/ // This entry module can't be inlined because the eval devtool is used.
70
- /******/ var __webpack_exports__ = __webpack_require__("./client/index.js");
72
+ /******/ var __webpack_exports__ = {};
73
+ /******/ __webpack_modules__["./client/index.js"](0,__webpack_exports__,__webpack_require__);
71
74
  /******/
72
75
  /******/ return __webpack_exports__;
73
76
  /******/ })()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "restafary",
3
- "version": "13.0.0",
4
- "type": "commonjs",
3
+ "version": "13.0.2",
4
+ "type": "module",
5
5
  "description": "REST for CRUD file operations",
6
6
  "main": "server/restafary.js",
7
7
  "engines": {
@@ -44,7 +44,7 @@
44
44
  "jonny": "^3.0.0",
45
45
  "mellow": "^3.0.1",
46
46
  "mime-types": "^3.0.2",
47
- "patchfile": "^4.0.0",
47
+ "patchfile": "^5.0.0",
48
48
  "pipe-io": "^4.0.1",
49
49
  "ponse": "^7.0.0",
50
50
  "pullout": "^5.0.1",
package/server/fs/get.js CHANGED
@@ -1,24 +1,31 @@
1
- 'use strict';
2
-
3
- const {Buffer} = require('node:buffer');
4
- const {Readable} = require('node:stream');
5
-
6
- const {parse} = require('node:querystring');
7
- const check = require('checkup');
8
- const ashify = require('ashify');
9
- const {read} = require('win32');
10
- const {readSize} = require('redzip');
1
+ import {Buffer} from 'node:buffer';
2
+ import {Readable} from 'node:stream';
3
+ import {parse} from 'node:querystring';
4
+ import check from 'checkup';
5
+ import ashify from 'ashify';
6
+ import {read as _read} from 'win32';
7
+ import {readSize} from 'redzip';
11
8
 
12
9
  const {assign} = Object;
13
10
 
14
- module.exports = async ({query, path, root}) => {
11
+ export const get = async (overrides = {}) => {
12
+ const {
13
+ query,
14
+ path,
15
+ root,
16
+ read = _read,
17
+ } = overrides;
18
+
15
19
  check
16
20
  .type('path', path, 'string')
17
21
  .check({
18
22
  query,
19
23
  });
20
24
 
21
- const {sort = 'name', order = 'asc'} = parse(query);
25
+ const {
26
+ sort = 'name',
27
+ order = 'asc',
28
+ } = parse(query);
22
29
 
23
30
  switch(query) {
24
31
  default:
@@ -1,17 +1,14 @@
1
- 'use strict';
1
+ import {callbackify} from 'node:util';
2
+ import check from 'checkup';
3
+ import pullout from 'pullout';
4
+ import {patchfile} from 'patchfile';
2
5
 
3
- const {callbackify} = require('node:util');
4
-
5
- const check = require('checkup');
6
- const pullout = require('pullout');
7
- const patch = require('patchfile');
8
-
9
- module.exports = callbackify(async (name, readStream, options) => {
6
+ export const patch = callbackify(async (name, readStream, options) => {
10
7
  check
11
8
  .type('name', name, 'string')
12
9
  .type('readStream', readStream, 'object');
13
10
 
14
11
  const data = await pullout(readStream, 'string');
15
12
 
16
- return patch(name, data, options);
13
+ return patchfile(name, data, options);
17
14
  });
package/server/fs/put.js CHANGED
@@ -1,11 +1,8 @@
1
- 'use strict';
1
+ import {callbackify} from 'node:util';
2
+ import check from 'checkup';
3
+ import {write} from 'redzip';
2
4
 
3
- const {callbackify} = require('node:util');
4
-
5
- const check = require('checkup');
6
- const {write} = require('redzip');
7
-
8
- module.exports = callbackify(async (query, name, readStream) => {
5
+ export const put = callbackify(async (query, name, readStream) => {
9
6
  check
10
7
  .type('name', name, 'string')
11
8
  .type('readStream', readStream, 'object')
@@ -1,12 +1,8 @@
1
- 'use strict';
1
+ import check from 'checkup';
2
+ import {remove as flopRemove} from 'flop';
3
+ import pullout from 'pullout';
2
4
 
3
- const {callbackify} = require('node:util');
4
- const check = require('checkup');
5
- const {remove} = require('flop');
6
-
7
- const pullout = require('pullout');
8
-
9
- module.exports = callbackify(async (query, name, readStream) => {
5
+ export const remove = async (query, name, readStream) => {
10
6
  check
11
7
  .type('name', name, 'string')
12
8
  .type('readStream', readStream, 'object')
@@ -15,12 +11,12 @@ module.exports = callbackify(async (query, name, readStream) => {
15
11
  });
16
12
 
17
13
  if (query !== 'files')
18
- return await remove(name);
14
+ return await flopRemove(name);
19
15
 
20
16
  const files = await getBody(readStream);
21
17
 
22
- await remove(name, files);
23
- });
18
+ await flopRemove(name, files);
19
+ };
24
20
 
25
21
  async function getBody(readStream) {
26
22
  const data = await pullout(readStream, 'string');
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {join} from 'node:path';
2
2
 
3
- const {join} = require('node:path');
4
-
5
- module.exports.handleDotFolder = (root, cwd) => {
3
+ export const handleDotFolder = (root, cwd) => {
6
4
  if (root.startsWith('./')) {
7
5
  root = root.replace('./', '');
8
6
  return join(cwd, root);
@@ -1,41 +1,41 @@
1
- 'use strict';
2
-
3
- const process = require('node:process');
4
-
5
- const {
1
+ import process from 'node:process';
2
+ import {fileURLToPath} from 'node:url';
3
+ import {
6
4
  basename,
7
5
  extname,
8
6
  join,
9
- } = require('node:path');
10
-
11
- const {webToWin} = require('mellow');
7
+ dirname,
8
+ } from 'node:path';
9
+ import {webToWin} from 'mellow';
10
+ import ponse from 'ponse';
11
+ import currify from 'currify';
12
+ import {tryToCatch as _tryToCatch} from 'try-to-catch';
13
+ import pipe from 'pipe-io';
14
+ import {contentType} from 'mime-types';
15
+ import {fileTypeStream} from 'file-type';
16
+ import {handleDotFolder} from './handle-dot-dir.js';
17
+ import {get} from './fs/get.js';
18
+ import {put} from './fs/put.js';
19
+ import {patch} from './fs/patch.js';
20
+ import {remove} from './fs/remove.js';
12
21
 
13
- const ponse = require('ponse');
14
- const currify = require('currify');
15
- const {tryToCatch: _tryToCatch} = require('try-to-catch');
16
- const pipe = require('pipe-io');
17
- const {contentType} = require('mime-types');
18
- const {handleDotFolder} = require('./handle-dot-dir');
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
19
24
  const isUndefined = (a) => typeof a === 'undefined';
20
25
  const isFn = (a) => typeof a === 'function';
21
-
22
- const DIR = './';
23
26
  const WIN = process.platform === 'win32';
24
27
  const CWD = process.cwd();
25
- const Fs = {};
26
28
 
27
- for (const name of [
28
- 'get',
29
- 'put',
30
- 'patch',
31
- 'delete',
32
- ]) {
33
- Fs[name] = require(DIR + 'fs/' + name);
34
- }
29
+ const Fs = {
30
+ get,
31
+ put,
32
+ patch,
33
+ remove,
34
+ };
35
35
 
36
36
  const isDev = process.env.NODE_ENV === 'development';
37
37
 
38
- module.exports = currify(async (options, request, response, next) => {
38
+ export const restafary = currify(async (options, request, response, next) => {
39
39
  const req = request;
40
40
  const res = response;
41
41
  const isFile = /^\/restafary\.js(\.map)?$/.test(req.url);
@@ -44,6 +44,7 @@ module.exports = currify(async (options, request, response, next) => {
44
44
  prefix = '/fs',
45
45
  root = '/',
46
46
  tryToCatch = _tryToCatch,
47
+ read,
47
48
  } = options;
48
49
 
49
50
  const params = {
@@ -51,6 +52,7 @@ module.exports = currify(async (options, request, response, next) => {
51
52
  request,
52
53
  response,
53
54
  tryToCatch,
55
+ read,
54
56
  };
55
57
 
56
58
  let name = ponse.getPathName(req);
@@ -132,7 +134,7 @@ function checkPath(name, root) {
132
134
  }
133
135
 
134
136
  async function onFS(params, callback) {
135
- const {tryToCatch} = params;
137
+ const {tryToCatch, read} = params;
136
138
  const pathError = 'Could not write file/create directory in root on windows!';
137
139
  const p = params;
138
140
  const {name} = p;
@@ -179,10 +181,12 @@ async function onFS(params, callback) {
179
181
  callback(error, optionsDefaults);
180
182
  });
181
183
 
182
- case 'DELETE':
183
- return Fs.delete(query, pathOS, p.request, (error) => {
184
- callback(error, optionsDefaults);
185
- });
184
+ case 'DELETE': {
185
+ const [error] = await tryToCatch(Fs.remove, query, pathOS, p.request);
186
+
187
+ callback(error, optionsDefaults);
188
+ return;
189
+ }
186
190
 
187
191
  case 'HEAD':
188
192
  case 'GET': {
@@ -190,6 +194,7 @@ async function onFS(params, callback) {
190
194
  query,
191
195
  path: pathOS,
192
196
  root,
197
+ read,
193
198
  });
194
199
 
195
200
  if (error)
@@ -232,8 +237,6 @@ function format(msg, name) {
232
237
  }
233
238
 
234
239
  async function getContentType({type, pathWeb, stream, tryToCatch}) {
235
- const {fileTypeStream} = await import('file-type');
236
-
237
240
  if (!type)
238
241
  return [null, stream, 'text/plain'];
239
242