@azrico/webobject 1.4.139 → 1.4.141

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.
@@ -1,5 +1,5 @@
1
- import { ClassType } from "@azrico/types";
2
1
  import WebObject from "./WebObject";
2
+ type PathFunction<T> = string | ((w: T) => string);
3
3
  export declare class WebObjectPathHelper {
4
4
  static readonly defaultPaths: {
5
5
  lock: string;
@@ -23,6 +23,6 @@ export declare class WebObjectPathHelper {
23
23
  * @param override
24
24
  * @returns
25
25
  */
26
- static override_path(obj: ClassType<WebObject> | string, pn: string, override: string): Promise<string | false>;
26
+ static override_path<T>(obj: T | string, pn: string, override: PathFunction<T>): Promise<false | PathFunction<T>>;
27
27
  }
28
28
  export default WebObjectPathHelper;
@@ -35,11 +35,12 @@ var WebObjectPathHelper = exports.WebObjectPathHelper = /*#__PURE__*/function ()
35
35
  usepath = WebObjectPathHelper.defaultPaths[pn];
36
36
  }
37
37
  if (!usepath) usepath = WebObjectPathHelper.defaultPaths["save"];
38
- usepath = usepath.replaceAll("{wn}", obj.get_webname());
39
- usepath = usepath.replaceAll("{wp}", obj.__web_path);
40
- usepath = usepath.replaceAll("{id}", obj.getID());
38
+ if (typeof usepath === "function") usepath = String(usepath(obj));
39
+ /* ----------------------------- place variables ---------------------------- */
40
+ usepath = String(usepath).replaceAll("{wn}", obj.get_webname()).replaceAll("{wp}", obj.__web_path).replaceAll("{id}", obj.getID());
41
+ /* -------------------------------------------------------------------------- */
41
42
  return _context.abrupt("return", usepath);
42
- case 9:
43
+ case 8:
43
44
  case "end":
44
45
  return _context.stop();
45
46
  }
@@ -98,4 +98,25 @@ describe("WebObjectPathHelper", function () {
98
98
  }
99
99
  }, _callee2);
100
100
  })));
101
+ it("override_path with function", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
102
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
103
+ while (1) switch (_context3.prev = _context3.next) {
104
+ case 0:
105
+ _context3.next = 2;
106
+ return _WebObjectPathHelper["default"].override_path(wobj, "save", function (s) {
107
+ return s._id;
108
+ });
109
+ case 2:
110
+ _context3.t0 = expect;
111
+ _context3.next = 5;
112
+ return _WebObjectPathHelper["default"].get_path(wobj, "save");
113
+ case 5:
114
+ _context3.t1 = _context3.sent;
115
+ (0, _context3.t0)(_context3.t1).toBe(wobj.getID());
116
+ case 7:
117
+ case "end":
118
+ return _context3.stop();
119
+ }
120
+ }, _callee3);
121
+ })));
101
122
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.139",
3
+ "version": "1.4.141",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",