@wener/utils 1.1.54 → 1.1.56

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 (57) hide show
  1. package/lib/arrays/arrayFromAsync.js +11 -3
  2. package/lib/asyncs/AsyncInterval.js +11 -3
  3. package/lib/asyncs/Promises.js +6 -5
  4. package/lib/asyncs/createAsyncIterator.js +11 -3
  5. package/lib/asyncs/createLazyPromise.test.js +11 -3
  6. package/lib/asyncs/generatorOfStream.js +11 -3
  7. package/lib/browsers/download.js +11 -3
  8. package/lib/browsers/loaders.js +11 -3
  9. package/lib/crypto/hashing.js +11 -3
  10. package/lib/crypto/hashing.test.js +11 -3
  11. package/lib/crypto/pem/pem.js +1 -1
  12. package/lib/fetch/createFetchWith.js +11 -3
  13. package/lib/fetch/dumpRequest.js +12 -4
  14. package/lib/fetch/dumpRequest.test.js +11 -3
  15. package/lib/fetch/dumpResponse.js +11 -3
  16. package/lib/fetch/dumpResponse.test.js +11 -3
  17. package/lib/io/ArrayBuffers.js +2 -2
  18. package/lib/io/ByteBuffer.test.js +11 -3
  19. package/lib/io/parseDataUri.js +11 -3
  20. package/lib/io/parseDataUri.test.js +31 -11
  21. package/lib/langs/AsyncCloser.js +11 -3
  22. package/lib/langs/deepFreeze.js +5 -5
  23. package/lib/langs/mixin.js +6 -12
  24. package/lib/langs/mixin.test.js +53 -5
  25. package/lib/langs/mixin2.js +26 -0
  26. package/lib/langs/parseBoolean.js +3 -2
  27. package/lib/langs/shallowEqual.js +5 -5
  28. package/lib/libs/ms.js +1 -1
  29. package/lib/maths/random.js +12 -4
  30. package/lib/objects/merge/isMergeableObject.js +1 -1
  31. package/lib/objects/merge/merge.js +1 -1
  32. package/lib/objects/merge/merge.test.js +11 -3
  33. package/lib/objects/set.js +10 -2
  34. package/lib/objects/set.test.js +2 -2
  35. package/lib/scripts/getGenerateContext.js +13 -5
  36. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +11 -3
  37. package/lib/server/fetch/createFetchWithProxyByUndici.js +11 -3
  38. package/lib/server/polyfill/polyfillBrowser.js +11 -3
  39. package/lib/server/polyfill/polyfillBrowser.test.js +11 -3
  40. package/lib/server/polyfill/polyfillCrypto.js +11 -3
  41. package/lib/server/polyfill/polyfillJsDom.js +31 -11
  42. package/lib/strings/renderTemplate.test.js +2 -2
  43. package/lib/web/getRandomValues.js +1 -1
  44. package/lib/web/structuredClone.js +2 -2
  45. package/package.json +8 -4
  46. package/src/asyncs/Promises.ts +2 -1
  47. package/src/asyncs/timeout.ts +1 -1
  48. package/src/crypto/hashing.ts +7 -6
  49. package/src/crypto/pem/pem.ts +3 -2
  50. package/src/fetch/dumpRequest.ts +1 -1
  51. package/src/langs/mixin.test.ts +35 -5
  52. package/src/langs/mixin.ts +46 -65
  53. package/src/langs/mixin2.ts +80 -0
  54. package/src/langs/parseBoolean.ts +9 -1
  55. package/src/objects/set.ts +10 -1
  56. package/src/types.d.ts +1 -1
  57. package/tsconfig.json +5 -2
@@ -1,5 +1,6 @@
1
- export function parseBoolean(s) {
2
- var strict = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1
+ export function parseBoolean(s, options) {
2
+ var _ref;
3
+ var strict = typeof options === 'boolean' ? options : (_ref = options === null || options === void 0 ? void 0 : options.strict) !== null && _ref !== void 0 ? _ref : false;
3
4
  if (typeof s === 'boolean') {
4
5
  return s;
5
6
  }
@@ -1,12 +1,12 @@
1
+ function _type_of(obj) {
2
+ "@swc/helpers - typeof";
3
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
+ }
1
5
  /**
2
6
  * shallow compare - support object, array
3
7
  *
4
8
  * @see {@link https://github.com/pmndrs/zustand/blob/main/src/shallow.ts zustand/src/shallow.ts}
5
- */ function _type_of(obj) {
6
- "@swc/helpers - typeof";
7
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
8
- }
9
- export function shallowEqual(objA, objB) {
9
+ */ export function shallowEqual(objA, objB) {
10
10
  if (Object.is(objA, objB)) {
11
11
  return true;
12
12
  }
package/lib/libs/ms.js CHANGED
@@ -1,8 +1,8 @@
1
- // Helpers.
2
1
  function _type_of(obj) {
3
2
  "@swc/helpers - typeof";
4
3
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
4
  }
5
+ // Helpers.
6
6
  var s = 1000;
7
7
  var m = s * 60;
8
8
  var h = m * 60;
@@ -1,4 +1,3 @@
1
- // LCG pseudo random
2
1
  function _define_property(obj, key, value) {
3
2
  if (key in obj) {
4
3
  Object.defineProperty(obj, key, {
@@ -21,9 +20,17 @@ function _ts_generator(thisArg, body) {
21
20
  },
22
21
  trys: [],
23
22
  ops: []
24
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
25
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
26
- return this;
23
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
24
+ return d(g, "next", {
25
+ value: verb(0)
26
+ }), d(g, "throw", {
27
+ value: verb(1)
28
+ }), d(g, "return", {
29
+ value: verb(2)
30
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
31
+ value: function() {
32
+ return this;
33
+ }
27
34
  }), g;
28
35
  function verb(n) {
29
36
  return function(v) {
@@ -103,6 +110,7 @@ function _ts_generator(thisArg, body) {
103
110
  };
104
111
  }
105
112
  }
113
+ // LCG pseudo random
106
114
  export function createRandom() {
107
115
  var _seed = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : Date.now();
108
116
  var seed = 0;
@@ -1,8 +1,8 @@
1
- // https://github.com/TehShrike/is-mergeable-object/blob/master/index.js
2
1
  function _type_of(obj) {
3
2
  "@swc/helpers - typeof";
4
3
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
4
  }
5
+ // https://github.com/TehShrike/is-mergeable-object/blob/master/index.js
6
6
  export function isMergeableObject(value) {
7
7
  return isNonNullObject(value) && !isSpecial(value);
8
8
  }
@@ -1,4 +1,3 @@
1
- // https://github.com/TehShrike/deepmerge/blob/master/index.js
2
1
  function _define_property(obj, key, value) {
3
2
  if (key in obj) {
4
3
  Object.defineProperty(obj, key, {
@@ -53,6 +52,7 @@ function _object_spread_props(target, source) {
53
52
  }
54
53
  return target;
55
54
  }
55
+ // https://github.com/TehShrike/deepmerge/blob/master/index.js
56
56
  import { isMergeableObject as defaultIsMergeableObject } from "./isMergeableObject.js";
57
57
  function emptyTarget(val) {
58
58
  return Array.isArray(val) ? [] : {};
@@ -70,9 +70,17 @@ function _ts_generator(thisArg, body) {
70
70
  },
71
71
  trys: [],
72
72
  ops: []
73
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
74
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
75
- return this;
73
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
74
+ return d(g, "next", {
75
+ value: verb(0)
76
+ }), d(g, "throw", {
77
+ value: verb(1)
78
+ }), d(g, "return", {
79
+ value: verb(2)
80
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
81
+ value: function () {
82
+ return this;
83
+ }
76
84
  }), g;
77
85
  function verb(n) {
78
86
  return function (v) {
@@ -16,11 +16,19 @@ import { parseObjectPath } from "./parseObjectPath.js";
16
16
  var x, k;
17
17
  while (i < len) {
18
18
  k = path[i++];
19
+ // Security: Prevent prototype pollution
19
20
  if (k === "__proto__" || k === "constructor" || k === "prototype")
20
21
  break;
21
22
  // noinspection PointlessArithmeticExpressionJS
22
- current = current[k] = i === len ? merging ? merge(current[k], val) : val : _type_of(x = current[k]) === (typeof path === "undefined" ? "undefined" : _type_of(path)) ? x : path[i] * 0 !== 0 || !!~("" + path[i]).indexOf(".") // eslint-disable-line
23
- ? {} : [];
23
+ current = current[k] = i === len ? merging ? merge(current[k], val) : val : _type_of(x = current[k]) === (typeof path === "undefined" ? "undefined" : _type_of(path)) ? x : // If the next key is NOT an integer-like index, or contains a dot, create an Object.
24
+ // Otherwise, create an Array.
25
+ //
26
+ // path[i] * 0 !== 0 checks if it is NOT a number (NaN * 0 is NaN).
27
+ // !!~('' + path[i]).indexOf('.') checks if it contains a dot.
28
+ //
29
+ // @ts-expect-error hacky type check from dset
30
+ path[i] * 0 !== 0 || !!~("" + path[i]).indexOf(".") // eslint-disable-line
31
+ ? {} : [];
24
32
  }
25
33
  }
26
34
  export function merge(a, b) {
@@ -1,4 +1,4 @@
1
- /* eslint no-proto:0 no-prototype-builtins:0 */ function _instanceof(left, right) {
1
+ function _instanceof(left, right) {
2
2
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
3
3
  return !!right[Symbol.hasInstance](left);
4
4
  }
@@ -6,7 +6,7 @@
6
6
  return left instanceof right;
7
7
  }
8
8
  }
9
- import { describe, expect, it, test } from "vitest";
9
+ /* eslint no-proto:0 no-prototype-builtins:0 */ import { describe, expect, it, test } from "vitest";
10
10
  import { set } from "./set.js";
11
11
  test("set basics", function () {
12
12
  expect(set({}, "c", 3), "should not give return value").toBe(undefined);
@@ -93,9 +93,17 @@ function _ts_generator(thisArg, body) {
93
93
  },
94
94
  trys: [],
95
95
  ops: []
96
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
97
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
98
- return this;
96
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
97
+ return d(g, "next", {
98
+ value: verb(0)
99
+ }), d(g, "throw", {
100
+ value: verb(1)
101
+ }), d(g, "return", {
102
+ value: verb(2)
103
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
104
+ value: function () {
105
+ return this;
106
+ }
99
107
  }), g;
100
108
  function verb(n) {
101
109
  return function (v) {
@@ -347,7 +355,7 @@ export function getGenerateContext(prefix) {
347
355
  }
348
356
  function write(dir, file, content) {
349
357
  return _async_to_generator(function () {
350
- var size, dst, last, e;
358
+ var size, dst, last, unused;
351
359
  return _ts_generator(this, function (_state) {
352
360
  switch (_state.label) {
353
361
  case 0:
@@ -374,7 +382,7 @@ function write(dir, file, content) {
374
382
  4
375
383
  ];
376
384
  case 3:
377
- e = _state.sent();
385
+ unused = _state.sent();
378
386
  return [
379
387
  3,
380
388
  4
@@ -101,9 +101,17 @@ function _ts_generator(thisArg, body) {
101
101
  },
102
102
  trys: [],
103
103
  ops: []
104
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
105
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
106
- return this;
104
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
105
+ return d(g, "next", {
106
+ value: verb(0)
107
+ }), d(g, "throw", {
108
+ value: verb(1)
109
+ }), d(g, "return", {
110
+ value: verb(2)
111
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
112
+ value: function () {
113
+ return this;
114
+ }
107
115
  }), g;
108
116
  function verb(n) {
109
117
  return function (v) {
@@ -139,9 +139,17 @@ function _ts_generator(thisArg, body) {
139
139
  },
140
140
  trys: [],
141
141
  ops: []
142
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
143
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
144
- return this;
142
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
143
+ return d(g, "next", {
144
+ value: verb(0)
145
+ }), d(g, "throw", {
146
+ value: verb(1)
147
+ }), d(g, "return", {
148
+ value: verb(2)
149
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
150
+ value: function () {
151
+ return this;
152
+ }
145
153
  }), g;
146
154
  function verb(n) {
147
155
  return function (v) {
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
39
39
  },
40
40
  trys: [],
41
41
  ops: []
42
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
43
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
44
- return this;
42
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
43
+ return d(g, "next", {
44
+ value: verb(0)
45
+ }), d(g, "throw", {
46
+ value: verb(1)
47
+ }), d(g, "return", {
48
+ value: verb(2)
49
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
50
+ value: function () {
51
+ return this;
52
+ }
45
53
  }), g;
46
54
  function verb(n) {
47
55
  return function (v) {
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
39
39
  },
40
40
  trys: [],
41
41
  ops: []
42
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
43
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
44
- return this;
42
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
43
+ return d(g, "next", {
44
+ value: verb(0)
45
+ }), d(g, "throw", {
46
+ value: verb(1)
47
+ }), d(g, "return", {
48
+ value: verb(2)
49
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
50
+ value: function () {
51
+ return this;
52
+ }
45
53
  }), g;
46
54
  function verb(n) {
47
55
  return function (v) {
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
39
39
  },
40
40
  trys: [],
41
41
  ops: []
42
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
43
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
44
- return this;
42
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
43
+ return d(g, "next", {
44
+ value: verb(0)
45
+ }), d(g, "throw", {
46
+ value: verb(1)
47
+ }), d(g, "return", {
48
+ value: verb(2)
49
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
50
+ value: function () {
51
+ return this;
52
+ }
45
53
  }), g;
46
54
  function verb(n) {
47
55
  return function (v) {
@@ -37,12 +37,24 @@ function _class_call_check(instance, Constructor) {
37
37
  function _object_without_properties(source, excluded) {
38
38
  if (source == null)
39
39
  return {};
40
- var target = _object_without_properties_loose(source, excluded);
41
- var key, i;
40
+ var target = {}, sourceKeys, key, i;
41
+ if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
42
+ sourceKeys = Reflect.ownKeys(source);
43
+ for (i = 0; i < sourceKeys.length; i++) {
44
+ key = sourceKeys[i];
45
+ if (excluded.indexOf(key) >= 0)
46
+ continue;
47
+ if (!Object.prototype.propertyIsEnumerable.call(source, key))
48
+ continue;
49
+ target[key] = source[key];
50
+ }
51
+ return target;
52
+ }
53
+ target = _object_without_properties_loose(source, excluded);
42
54
  if (Object.getOwnPropertySymbols) {
43
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
44
- for (i = 0; i < sourceSymbolKeys.length; i++) {
45
- key = sourceSymbolKeys[i];
55
+ sourceKeys = Object.getOwnPropertySymbols(source);
56
+ for (i = 0; i < sourceKeys.length; i++) {
57
+ key = sourceKeys[i];
46
58
  if (excluded.indexOf(key) >= 0)
47
59
  continue;
48
60
  if (!Object.prototype.propertyIsEnumerable.call(source, key))
@@ -55,13 +67,13 @@ function _object_without_properties(source, excluded) {
55
67
  function _object_without_properties_loose(source, excluded) {
56
68
  if (source == null)
57
69
  return {};
58
- var target = {};
59
- var sourceKeys = Object.keys(source);
60
- var key, i;
70
+ var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
61
71
  for (i = 0; i < sourceKeys.length; i++) {
62
72
  key = sourceKeys[i];
63
73
  if (excluded.indexOf(key) >= 0)
64
74
  continue;
75
+ if (!Object.prototype.propertyIsEnumerable.call(source, key))
76
+ continue;
65
77
  target[key] = source[key];
66
78
  }
67
79
  return target;
@@ -76,9 +88,17 @@ function _ts_generator(thisArg, body) {
76
88
  },
77
89
  trys: [],
78
90
  ops: []
79
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
80
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
81
- return this;
91
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
92
+ return d(g, "next", {
93
+ value: verb(0)
94
+ }), d(g, "throw", {
95
+ value: verb(1)
96
+ }), d(g, "return", {
97
+ value: verb(2)
98
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
99
+ value: function () {
100
+ return this;
101
+ }
82
102
  }), g;
83
103
  function verb(n) {
84
104
  return function (v) {
@@ -1,4 +1,4 @@
1
- /* eslint no-template-curly-in-string:0 */ function _array_like_to_array(arr, len) {
1
+ function _array_like_to_array(arr, len) {
2
2
  if (len == null || len > arr.length)
3
3
  len = arr.length;
4
4
  for (var i = 0, arr2 = new Array(len); i < len; i++)
@@ -59,7 +59,7 @@ function _unsupported_iterable_to_array(o, minLen) {
59
59
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
60
60
  return _array_like_to_array(o, minLen);
61
61
  }
62
- import { expect, test } from "vitest";
62
+ /* eslint no-template-curly-in-string:0 */ import { expect, test } from "vitest";
63
63
  import { renderTemplate } from "./renderTemplate.js";
64
64
  test("renderTemplate", function () {
65
65
  var obj = {
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
2
1
  function _instanceof(left, right) {
3
2
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
4
3
  return !!right[Symbol.hasInstance](left);
@@ -8,6 +7,7 @@ function _instanceof(left, right) {
8
7
  }
9
8
  }
10
9
  var _globalThis_crypto_getRandomValues, _globalThis_crypto, _globalThis_msCrypto_getRandomValues, _globalThis_msCrypto;
10
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
11
11
  import { getNodeCrypto } from "../crypto/getNodeCrypto.js";
12
12
  import { getGlobalThis } from "./getGlobalThis.js";
13
13
  var globalThis = getGlobalThis();
@@ -1,8 +1,8 @@
1
- /* eslint no-proto:0 */ function _type_of(obj) {
1
+ function _type_of(obj) {
2
2
  "@swc/helpers - typeof";
3
3
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
4
  }
5
- import { classOf } from "../langs/classOf.js";
5
+ /* eslint no-proto:0 */ import { classOf } from "../langs/classOf.js";
6
6
  /**
7
7
  * Clone an object using structured cloning algorithm
8
8
  *
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.54",
3
+ "version": "1.1.56",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/wener/wode.git"
8
+ "url": "https://github.com/wenerme/wener.git",
9
+ "directory": "packages/wener-utils"
9
10
  },
10
- "homepage": "https://github.com/wenerme/wode#readme",
11
+ "homepage": "https://github.com/wenerme/wener/tree/main/packages/wener-utils",
11
12
  "author": "wener",
12
13
  "license": "MIT",
14
+ "imports": {
15
+ "#/*": "./src/*"
16
+ },
13
17
  "exports": {
14
18
  ".": {
15
19
  "types": "./src/index.ts",
@@ -70,7 +74,7 @@
70
74
  "https-proxy-agent": "^7.0.6",
71
75
  "node-fetch": "^3.3.2",
72
76
  "undici": "^7.16.0",
73
- "zod": "^4.1.12"
77
+ "zod": "^4.1.13"
74
78
  },
75
79
  "publishConfig": {
76
80
  "registry": "https://registry.npmjs.org",
@@ -20,7 +20,8 @@ export class Promises {
20
20
  }
21
21
  let resolve: (value: T | PromiseLike<T>) => void;
22
22
  let reject: (reason?: any) => void;
23
- // @ts-ignore
23
+ // @ts-ignore -- Polyfill/Fallback for environment without Promise.withResolvers
24
+ // eslint-disable-next-line
24
25
  const promise = new Promise<T>((res, rej) => {
25
26
  resolve = res;
26
27
  reject = rej;
@@ -3,7 +3,7 @@ export function timeout<T = any>(
3
3
  ms: number,
4
4
  ): Promise<T> {
5
5
  const error = new TimeoutError();
6
- let timeout: any;
6
+ let timeout: ReturnType<typeof setTimeout>;
7
7
  let ac: AbortController | undefined;
8
8
  if (typeof pending === 'function') {
9
9
  ac = new AbortController();
@@ -1,10 +1,11 @@
1
1
  import { ArrayBuffers } from '../io/ArrayBuffers';
2
+ import type { Bytes } from '../io/types';
2
3
 
3
4
  type HashEncoding = 'hex' | 'base64' | 'buffer';
4
5
 
5
6
  type HashFunction = {
6
7
  (s: BinaryLike, o?: 'hex' | 'base64' | undefined): Promise<string>;
7
- (s: BinaryLike, o: 'buffer'): Promise<ArrayBuffer>;
8
+ (s: BinaryLike, o: 'buffer'): Promise<Bytes>;
8
9
  };
9
10
 
10
11
  function createDigestFunction(a: string): HashFunction {
@@ -17,27 +18,27 @@ function createDigestFunction(a: string): HashFunction {
17
18
  }) as HashFunction;
18
19
  }
19
20
 
20
- export function sha1(s: BinaryLike, o?: undefined | 'buffer'): Promise<Buffer>;
21
+ export function sha1(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
21
22
  export function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
22
23
  export function sha1(s: BinaryLike, o?: DigestOptions) {
23
24
  return digestOf('SHA-1', s, o);
24
25
  }
25
26
 
26
- export function sha256(s: BinaryLike, o?: undefined | 'buffer'): Promise<Buffer>;
27
+ export function sha256(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
27
28
  export function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
28
29
 
29
30
  export function sha256(s: BinaryLike, o?: DigestOptions) {
30
31
  return digestOf('SHA-256', s, o);
31
32
  }
32
33
 
33
- export function sha384(s: BinaryLike, o?: undefined | 'buffer'): Promise<Buffer>;
34
+ export function sha384(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
34
35
  export function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
35
36
 
36
37
  export function sha384(s: BinaryLike, o?: DigestOptions) {
37
38
  return digestOf('SHA-384', s, o);
38
39
  }
39
40
 
40
- export function sha512(s: BinaryLike, o?: undefined | 'buffer'): Promise<Buffer>;
41
+ export function sha512(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
41
42
  export function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
42
43
 
43
44
  export function sha512(s: BinaryLike, o?: DigestOptions) {
@@ -84,7 +85,7 @@ export function hmac<O extends DigestOptions>(
84
85
  key: BinaryLike | CryptoKey,
85
86
  data: BinaryLike,
86
87
  o?: O,
87
- ): Promise<IsStringCoding<O> extends true ? string : Buffer>;
88
+ ): Promise<IsStringCoding<O> extends true ? string : Bytes>;
88
89
 
89
90
  export async function hmac(
90
91
  hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',
@@ -1,4 +1,5 @@
1
1
  import { ArrayBuffers } from '../../io/ArrayBuffers';
2
+ import type { Bytes } from '../../io/types';
2
3
 
3
4
  export interface Block {
4
5
  /**
@@ -30,7 +31,7 @@ export interface Block {
30
31
  | 'SM2 PARAMETERS';
31
32
 
32
33
  header: Record<string, string>;
33
- bytes: BufferSource;
34
+ bytes: Bytes;
34
35
  }
35
36
 
36
37
  export class PEM {
@@ -53,7 +54,7 @@ export class PEM {
53
54
  type,
54
55
  header,
55
56
  // avoid replaceAll
56
- bytes: ArrayBuffers.from(b64.replace(/[\r\n]/g, ''), 'base64'),
57
+ bytes: ArrayBuffers.from(b64.replace(/[\r\n]/g, ''), 'base64', Uint8Array),
57
58
  },
58
59
  head: data.slice(0, match.index || 0),
59
60
  tail: data.slice((match.index || 0) + match[0].length),
@@ -130,7 +130,7 @@ export async function dumpBodyContent({
130
130
  if (typeof value === 'string') {
131
131
  result += `${key}: ${value}\n`;
132
132
  } else {
133
- result += `${key}: [File: ${value.name || 'unknown'}]\n`;
133
+ result += `${key}: [File: ${(value as File).name || 'unknown'}]\n`;
134
134
  }
135
135
  }
136
136
  return result;
@@ -1,9 +1,43 @@
1
1
  import { expect, test } from 'vitest';
2
2
  import { mixin } from './mixin';
3
3
 
4
- export type Constructor<T = {}> = new (...args: any[]) => T;
4
+ // import type { Constructor } from '#/types';
5
+ type Constructor<T = {}> = new (...args: any[]) => T;
6
+ function Ent<T extends Function>(): (target: T) => void {
7
+ return () => {};
8
+ }
5
9
 
6
10
  test('mixin', () => {
11
+ // @Ent()
12
+ class User extends mixin(BaseResource, withFooFields) {
13
+ a?: string;
14
+ }
15
+ // @Ent()
16
+ class User2 extends mixin(BaseEnt, withFooFields) {
17
+ x: string = 'x';
18
+ }
19
+
20
+ // type works
21
+ const usr = new User();
22
+ expect(usr.foo, 'foo');
23
+
24
+ const u2 = new User2();
25
+ console.log(u2);
26
+ });
27
+
28
+ // <T extends EntityClass<unknown>>(options?: EntityOptions<T>): (target: T) => void;
29
+
30
+ // @Ent()
31
+ class BaseResource {
32
+ id?: string = '';
33
+ }
34
+
35
+ // @Ent()
36
+ class BaseEnt extends BaseResource {
37
+ base: string = 'base';
38
+ }
39
+
40
+ test('mixin deep not working', () => {
7
41
  // @ts-ignore
8
42
  class User extends mixin(BaseResource, createBarFields()) {}
9
43
 
@@ -14,10 +48,6 @@ test('mixin', () => {
14
48
  expect(usr).toEqual({ foo: 'foo', bar: 'bar', id: '' });
15
49
  });
16
50
 
17
- class BaseResource {
18
- id?: string = '';
19
- }
20
-
21
51
  function createBarFields() {
22
52
  return <TBase extends Constructor>(Base: TBase) => {
23
53
  // nested type not working