@wener/utils 1.1.17 → 1.1.19

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 (101) hide show
  1. package/dist/cjs/index.cjs +7 -7
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/server.cjs +1 -1
  4. package/dist/cjs/server.cjs.map +1 -1
  5. package/dist/esm/index.js +11 -11
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/server.js +1 -1
  8. package/dist/esm/server.js.map +1 -1
  9. package/dist/system/index.js +5 -5
  10. package/dist/system/index.js.map +1 -1
  11. package/dist/system/server.js +1 -1
  12. package/dist/system/server.js.map +1 -1
  13. package/lib/asyncs/createAsyncIterator.js +39 -0
  14. package/lib/asyncs/createAsyncIterator.js.map +1 -0
  15. package/lib/asyncs/createLazyPromise.js.map +1 -1
  16. package/lib/browsers/download.js.map +1 -1
  17. package/lib/browsers/getFileFromDataTransfer.js.map +1 -1
  18. package/lib/browsers/loaders.js.map +1 -1
  19. package/lib/crypto/getNodeCrypto.js.map +1 -1
  20. package/lib/crypto/getRandomValues.js.map +1 -1
  21. package/lib/crypto/pem/pem.js.map +1 -1
  22. package/lib/crypto/ulid.js +4 -1
  23. package/lib/crypto/ulid.js.map +1 -1
  24. package/lib/fetch/dumpRequest.js.map +1 -1
  25. package/lib/fetch/dumpResponse.js.map +1 -1
  26. package/lib/i18n/createTranslate.js.map +1 -1
  27. package/lib/index.js +2 -0
  28. package/lib/index.js.map +1 -1
  29. package/lib/io/ArrayBuffers.js +142 -164
  30. package/lib/io/ArrayBuffers.js.map +1 -1
  31. package/lib/io/Buffer.js +5 -6
  32. package/lib/io/Buffer.js.map +1 -1
  33. package/lib/libs/ms.js.map +1 -1
  34. package/lib/modules/parseModuleId.js.map +1 -1
  35. package/lib/objects/merge/isMergeableObject.js +18 -0
  36. package/lib/objects/merge/isMergeableObject.js.map +1 -0
  37. package/lib/objects/merge/merge.js +90 -0
  38. package/lib/objects/merge/merge.js.map +1 -0
  39. package/lib/server.js +9 -7
  40. package/lib/server.js.map +1 -1
  41. package/lib/servers/crypto/md5.js.map +1 -0
  42. package/lib/servers/fetch/createFetchWithProxy.js.map +1 -0
  43. package/lib/servers/fetch/createFetchWithProxyByUndici.js.map +1 -0
  44. package/lib/servers/{createFetchWithRetry.js → fetch/createFetchWithRetry.js} +1 -1
  45. package/lib/servers/fetch/createFetchWithRetry.js.map +1 -0
  46. package/lib/servers/getPackageDir.js +18 -0
  47. package/lib/servers/getPackageDir.js.map +1 -0
  48. package/lib/servers/polyfill/polyfillBrowser.js.map +1 -0
  49. package/lib/servers/{polyfillCrypto.js → polyfill/polyfillCrypto.js} +1 -1
  50. package/lib/servers/polyfill/polyfillCrypto.js.map +1 -0
  51. package/lib/servers/polyfill/polyfillFetch.js.map +1 -0
  52. package/lib/servers/{polyfillJsDom.js → polyfill/polyfillJsDom.js} +1 -1
  53. package/lib/servers/polyfill/polyfillJsDom.js.map +1 -0
  54. package/lib/servers/polyfill/polyfillWebSocket.js +16 -0
  55. package/lib/servers/polyfill/polyfillWebSocket.js.map +1 -0
  56. package/lib/strings/formatBytes.js.map +1 -1
  57. package/lib/validations/isUUID.js +1 -1
  58. package/lib/validations/isUUID.js.map +1 -1
  59. package/lib/validations/parseTimestamp.js.map +1 -1
  60. package/package.json +6 -9
  61. package/src/asyncs/createAsyncIterator.ts +40 -0
  62. package/src/crypto/hashing.test.ts +4 -1
  63. package/src/crypto/ulid.test.ts +14 -1
  64. package/src/crypto/ulid.ts +5 -2
  65. package/src/index.ts +2 -0
  66. package/src/langs/hashCode.ts +37 -0
  67. package/src/logging/Logger.ts +6 -6
  68. package/src/logging/slog.test.ts +8 -0
  69. package/src/logging/slog.ts +100 -0
  70. package/src/objects/merge/index.ts +1 -0
  71. package/src/objects/merge/isMergeableObject.ts +23 -0
  72. package/src/objects/merge/merge.test.ts +912 -0
  73. package/src/objects/merge/merge.ts +140 -0
  74. package/src/server.ts +9 -7
  75. package/src/servers/{createFetchWithProxyByNodeFetch.ts → fetch/createFetchWithProxyByNodeFetch.ts} +2 -2
  76. package/src/servers/{createFetchWithProxyByUndici.ts → fetch/createFetchWithProxyByUndici.ts} +2 -2
  77. package/src/servers/{createFetchWithRetry.ts → fetch/createFetchWithRetry.ts} +2 -2
  78. package/src/servers/getPackageDir.ts +16 -0
  79. package/src/servers/{polyfillCrypto.ts → polyfill/polyfillCrypto.ts} +1 -1
  80. package/src/servers/{polyfillFetch.ts → polyfill/polyfillFetch.ts} +1 -1
  81. package/src/servers/{polyfillJsDom.ts → polyfill/polyfillJsDom.ts} +1 -1
  82. package/src/servers/{polyfillWebSocket.ts → polyfill/polyfillWebSocket.ts} +2 -2
  83. package/src/validations/isUUID.test.ts +14 -0
  84. package/src/validations/isUUID.ts +2 -2
  85. package/lib/servers/createFetchWithProxy.js.map +0 -1
  86. package/lib/servers/createFetchWithProxyByUndici.js.map +0 -1
  87. package/lib/servers/createFetchWithRetry.js.map +0 -1
  88. package/lib/servers/md5.js.map +0 -1
  89. package/lib/servers/polyfillBrowser.js.map +0 -1
  90. package/lib/servers/polyfillCrypto.js.map +0 -1
  91. package/lib/servers/polyfillFetch.js.map +0 -1
  92. package/lib/servers/polyfillJsDom.js.map +0 -1
  93. /package/lib/servers/{md5.js → crypto/md5.js} +0 -0
  94. /package/lib/servers/{createFetchWithProxy.js → fetch/createFetchWithProxy.js} +0 -0
  95. /package/lib/servers/{createFetchWithProxyByUndici.js → fetch/createFetchWithProxyByUndici.js} +0 -0
  96. /package/lib/servers/{polyfillBrowser.js → polyfill/polyfillBrowser.js} +0 -0
  97. /package/lib/servers/{polyfillFetch.js → polyfill/polyfillFetch.js} +0 -0
  98. /package/src/servers/{md5.ts → crypto/md5.ts} +0 -0
  99. /package/src/servers/{createFetchWithProxy.ts → fetch/createFetchWithProxy.ts} +0 -0
  100. /package/src/servers/{polyfillBrowser.test.ts → polyfill/polyfillBrowser.test.ts} +0 -0
  101. /package/src/servers/{polyfillBrowser.ts → polyfill/polyfillBrowser.ts} +0 -0
@@ -0,0 +1,140 @@
1
+ // https://github.com/TehShrike/deepmerge/blob/master/index.js
2
+ import { isMergeableObject as defaultIsMergeableObject } from './isMergeableObject';
3
+
4
+ function emptyTarget(val: any) {
5
+ return Array.isArray(val) ? [] : {};
6
+ }
7
+
8
+ function cloneUnlessOtherwiseSpecified(value: any, options: Options) {
9
+ return options.clone !== false && options.isMergeableObject(value)
10
+ ? merge(emptyTarget(value), value, options)
11
+ : value;
12
+ }
13
+
14
+ function defaultArrayMerge(target: any, source: any, options: Options) {
15
+ return target.concat(source).map(function (element: any) {
16
+ return cloneUnlessOtherwiseSpecified(element, options);
17
+ });
18
+ }
19
+
20
+ type Merger = (x: any, y: any, options: Options) => any;
21
+
22
+ function getMergeFunction(key: any, options: Options): Merger {
23
+ if (!options.customMerge) {
24
+ return merge;
25
+ }
26
+ var customMerge = options.customMerge(key);
27
+ return typeof customMerge === 'function' ? customMerge : merge;
28
+ }
29
+
30
+ function getEnumerableOwnPropertySymbols(target: any): any {
31
+ return Object.getOwnPropertySymbols
32
+ ? Object.getOwnPropertySymbols(target).filter(function (symbol) {
33
+ return Object.propertyIsEnumerable.call(target, symbol);
34
+ })
35
+ : [];
36
+ }
37
+
38
+ function getKeys(target: any) {
39
+ return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
40
+ }
41
+
42
+ function propertyIsOnObject(object: any, property: any) {
43
+ try {
44
+ return property in object;
45
+ } catch (_) {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ // Protects from prototype poisoning and unexpected merging up the prototype chain.
51
+ function propertyIsUnsafe(target: any, key: string) {
52
+ return (
53
+ propertyIsOnObject(target, key) && // Properties are safe to merge if they don't exist in the target yet,
54
+ !(
55
+ Object.hasOwnProperty.call(target, key) && // unsafe if they exist up the prototype chain,
56
+ Object.propertyIsEnumerable.call(target, key)
57
+ )
58
+ ); // and also unsafe if they're nonenumerable.
59
+ }
60
+
61
+ function mergeObject(target: any, source: any, options: Options) {
62
+ const destination: Record<string, any> = {};
63
+ if (options.isMergeableObject(target)) {
64
+ getKeys(target).forEach((key) => {
65
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
66
+ });
67
+ }
68
+ getKeys(source).forEach((key) => {
69
+ if (propertyIsUnsafe(target, key)) {
70
+ return;
71
+ }
72
+
73
+ if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
74
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
75
+ } else {
76
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
77
+ }
78
+ });
79
+ return destination;
80
+ }
81
+
82
+ export function merge<T1, T2>(x: Partial<T1>, y: Partial<T2>, options?: MergeOptions): T1 & T2;
83
+ export function merge<T>(x: Partial<T>, y: Partial<T>, options?: MergeOptions): T;
84
+
85
+ export function merge(target: any, source: any, opts?: any): any {
86
+ const options = {
87
+ arrayMerge: defaultArrayMerge,
88
+ isMergeableObject: defaultIsMergeableObject,
89
+ ...opts,
90
+ // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
91
+ // implementations can use it. The caller may not replace it.
92
+ cloneUnlessOtherwiseSpecified,
93
+ } as Options & ArrayMergeOptions;
94
+
95
+ let sourceIsArray = Array.isArray(source);
96
+ let targetIsArray = Array.isArray(target);
97
+ let sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
98
+
99
+ if (!sourceAndTargetTypesMatch) {
100
+ return cloneUnlessOtherwiseSpecified(source, options);
101
+ } else if (sourceIsArray) {
102
+ return options.arrayMerge(target, source, options);
103
+ } else {
104
+ return mergeObject(target, source, options);
105
+ }
106
+ }
107
+
108
+ merge.all = function deepmergeAll(array: any[], options?: MergeOptions) {
109
+ if (!Array.isArray(array)) {
110
+ throw new Error('first argument should be an array');
111
+ }
112
+
113
+ return array.reduce(function (prev, next) {
114
+ return merge(prev, next, options);
115
+ }, {});
116
+ };
117
+
118
+ export interface MergeOptions {
119
+ arrayMerge?(target: any[], source: any[], options?: ArrayMergeOptions): any[];
120
+
121
+ clone?: boolean;
122
+ customMerge?: (key: string, options?: MergeOptions) => ((x: any, y: any) => any) | undefined;
123
+
124
+ isMergeableObject?(value: object): boolean;
125
+ }
126
+
127
+ interface Options {
128
+ arrayMerge(target: any[], source: any[], options?: ArrayMergeOptions): any[];
129
+
130
+ clone: boolean;
131
+ customMerge: (key: string, options?: MergeOptions) => ((x: any, y: any) => any) | undefined;
132
+
133
+ isMergeableObject(value: object): boolean;
134
+ }
135
+
136
+ export interface ArrayMergeOptions {
137
+ isMergeableObject(value: object): boolean;
138
+
139
+ cloneUnlessOtherwiseSpecified(value: object, options?: MergeOptions): object;
140
+ }
package/src/server.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { polyfillCrypto } from './servers/polyfillCrypto';
2
- export { polyfillJsDom } from './servers/polyfillJsDom';
3
- export { polyfillBrowser } from './servers/polyfillBrowser';
4
- export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici';
5
- export { createFetchWithProxy } from './servers/createFetchWithProxy';
6
- export { createFetchWithRetry, type FetchWithRetryOptions } from './servers/createFetchWithRetry';
1
+ export { polyfillCrypto } from './servers/polyfill/polyfillCrypto';
2
+ export { polyfillJsDom } from './servers/polyfill/polyfillJsDom';
3
+ export { polyfillBrowser } from './servers/polyfill/polyfillBrowser';
4
+ export { polyfillWebSocket } from './servers/polyfill/polyfillWebSocket';
5
+ export { createFetchWithProxyByUndici } from './servers/fetch/createFetchWithProxyByUndici';
6
+ export { createFetchWithProxy } from './servers/fetch/createFetchWithProxy';
7
+ export { createFetchWithRetry, type FetchWithRetryOptions } from './servers/fetch/createFetchWithRetry';
7
8
 
8
- export { md5 } from './servers/md5';
9
+ export { md5 } from './servers/crypto/md5';
10
+ export { getPackageDir } from './servers/getPackageDir';
@@ -1,5 +1,5 @@
1
- import { type FetchLike } from '../fetch';
2
- import { getGlobalThis } from '../isomorphics/getGlobalThis';
1
+ import { type FetchLike } from '../../fetch';
2
+ import { getGlobalThis } from '../../isomorphics/getGlobalThis';
3
3
 
4
4
  export function createFetchWithProxyByNodeFetch({
5
5
  proxy,
@@ -1,5 +1,5 @@
1
- import { MaybePromise } from '../asyncs/MaybePromise';
2
- import { FetchLike } from '../fetch';
1
+ import { MaybePromise } from '../../asyncs/MaybePromise';
2
+ import { FetchLike } from '../../fetch';
3
3
 
4
4
  export function createFetchWithProxyByUndici({
5
5
  proxy,
@@ -1,5 +1,5 @@
1
- import { FetchLike } from '../fetch';
2
- import { getGlobalThis } from '../isomorphics/getGlobalThis';
1
+ import { FetchLike } from '../../fetch';
2
+ import { getGlobalThis } from '../../isomorphics/getGlobalThis';
3
3
 
4
4
  type RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;
5
5
  type RequestRetryOnFunction = (
@@ -0,0 +1,16 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ export function getPackageDir(currentDir: string = __dirname) {
9
+ while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
10
+ currentDir = path.resolve(currentDir, '..');
11
+ if (currentDir === '/') {
12
+ return undefined;
13
+ }
14
+ }
15
+ return currentDir;
16
+ }
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../isomorphics/getGlobalThis';
1
+ import { getGlobalThis } from '../../isomorphics/getGlobalThis';
2
2
 
3
3
  export async function polyfillCrypto() {
4
4
  const globalThis = getGlobalThis();
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from '../asyncs/MaybePromise';
1
+ import type { MaybePromise } from '../../asyncs/MaybePromise';
2
2
 
3
3
  export function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;
4
4
  export function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
2
- import { getGlobalThis } from '../isomorphics/getGlobalThis';
2
+ import { getGlobalThis } from '../../isomorphics/getGlobalThis';
3
3
 
4
4
  export async function polyfillJsDom() {
5
5
  if (typeof window !== 'undefined') {
@@ -1,5 +1,5 @@
1
- import type { MaybePromise } from '../asyncs/MaybePromise';
2
- import { getGlobalThis } from '../isomorphics/getGlobalThis';
1
+ import type { MaybePromise } from '../../asyncs/MaybePromise';
2
+ import { getGlobalThis } from '../../isomorphics/getGlobalThis';
3
3
 
4
4
  export function polyfillWebSocket(ws: any): boolean;
5
5
  export function polyfillWebSocket(ws?: undefined): Promise<boolean>;
@@ -0,0 +1,14 @@
1
+ import { expect, test } from 'vitest';
2
+ import { randomUUID } from '../crypto/randomUUID';
3
+ import { isUUID } from './isUUID';
4
+
5
+ test('isUUID', () => {
6
+ for (const [a, b] of [
7
+ [undefined, false],
8
+ [null, false],
9
+ ['', false],
10
+ [randomUUID(), true],
11
+ ] as const) {
12
+ expect(isUUID(a), `${a} -> ${b}`).toEqual(b);
13
+ }
14
+ });
@@ -1,3 +1,3 @@
1
- export function isUUID(str: string) {
2
- return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
1
+ export function isUUID(str: string | undefined | null) {
2
+ return Boolean(str) && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(str));
3
3
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport const createFetchWithProxy = createFetchWithProxyByUndici;\n"],"names":[],"mappings":";;AAEO,MAAM,oBAAuB,GAAA;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from '../asyncs/MaybePromise';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n // fixme should unwrap error https://github.com/nodejs/undici/issues/1248\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":[],"mappings":"AAGO,SAAS,4BAA6B,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,KAAO,EAAA,MAAA;AAAA,EACP,KAAA;AAAA,EACA,MAAA;AACF,CAAA,GAKI,EAAe,EAAA;AACjB,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA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CAAA;AACvB,MAAA,KAAA,KAAA,KAAA,GAAU,GAAI,CAAA,KAAA,CAAA,CAAA;AAEd,MAAA,KAAA,GAAQ,IAAI,UAAW,CAAA;AAAA,QACrB,GAAA;AAAA,QACA,KAAA;AAAA,OACD,CAAA,CAAA;AAAA,KAIH;AACA,IAAA,IAAA,CAAK,UAAa,GAAA,KAAA,CAAA;AAClB,IAAO,OAAA,MAAM,KAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7B,CAAA;AACF;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFetchWithRetry.js","sources":["../../src/servers/createFetchWithRetry.ts"],"sourcesContent":["import { FetchLike } from '../fetch';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n }, delay);\n }\n\n wrappedFetch(0);\n });\n };\n}\n"],"names":["error"],"mappings":";;AAiBO,SAAS,oBAAqB,CAAA;AAAA,EACnC,KAAA,GAAQ,eAAgB,CAAA,KAAA;AAAA,EACxB,OAAU,GAAA,CAAA;AAAA,EACV,UAAa,GAAA,GAAA;AAAA,EACb,UAAU,EAAC;AACb,CAAA,GAA2B,EAAe,EAAA;AAGxC,EAAO,OAAA,SAAS,UAAW,CAAA,KAAA,EAAyB,IAAoB,EAAA;AACtE,IAAA,OAAO,IAAI,OAAA,CAAQ,SAAU,OAAA,EAAS,MAAQ,EAAA;AAC5C,MAAI,IAAA,YAAA,GAAe,SAAU,OAAiB,EAAA;AAG5C,QAAI,IAAA,MAAA,GAAS,OAAO,OAAY,KAAA,WAAA,IAAe,iBAAiB,OAAU,GAAA,KAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAC1F,QAAA,KAAA,CAAM,MAAQ,EAAA,IAAI,CACf,CAAA,IAAA,CAAK,SAAU,QAAU,EAAA;AACxB,UAAI,IAAA,KAAA,CAAM,QAAQ,OAAO,CAAA,IAAK,QAAQ,OAAQ,CAAA,QAAA,CAAS,MAAM,CAAA,KAAM,CAAI,CAAA,EAAA;AACrE,YAAA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AAA,CAAOA,MAAK,CAAA,CAAA;AAAA,eACb,CAAA,CAAA;AAAA,qBACIA,MAAP,EAAA;AACA,cAAA,MAAA,CAAOA,MAAK,CAAA,CAAA;AAAA,aACd;AAAA,WACF,MAAA,IAAW,UAAU,OAAS,EAAA;AAC5B,YAAM,KAAA,CAAA,OAAA,EAAS,OAAO,IAAI,CAAA,CAAA;AAAA,WACrB,MAAA;AACL,YAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,WACd;AAAA,SACD,CAAA,CAAA;AAAA,OACL,CAAA;AAEA,MAAS,SAAA,KAAA,CAAM,OAAiB,EAAA,KAAA,EAAY,QAA2B,EAAA;AACrE,QAAI,IAAA,KAAA,GAAQ,OAAO,UAAe,KAAA,UAAA,GAAa,WAAW,OAAS,EAAA,KAAA,EAAO,QAAQ,CAAI,GAAA,UAAA,CAAA;AACtF,QAAA,UAAA,CAAW,WAAY;AACrB,UAAA,YAAA,CAAa,EAAE,OAAO,CAAA,CAAA;AAAA,WACrB,KAAK,CAAA,CAAA;AAAA,OACV;AAEA,MAAA,YAAA,CAAa,CAAC,CAAA,CAAA;AAAA,KACf,CAAA,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"md5.js","sources":["../../src/servers/md5.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\nexport function md5(input: Buffer | string) {\n return createHash('md5').update(input).digest('hex') as string;\n}\n"],"names":[],"mappings":";;AAEO,SAAS,IAAI,KAAwB,EAAA;AAC1C,EAAA,OAAO,WAAW,KAAK,CAAA,CAAE,OAAO,KAAK,CAAA,CAAE,OAAO,KAAK,CAAA,CAAA;AACrD;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfillBrowser.js","sources":["../../src/servers/polyfillBrowser.ts"],"sourcesContent":["import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n"],"names":[],"mappings":";;;;AAYA,eAAsB,eAAkB,GAAA;AACtC,EAAA,MAAM,cAAe,EAAA,CAAA;AACrB,EAAA,MAAM,aAAc,EAAA,CAAA;AACpB,EAAA,MAAM,aAAc,EAAA,CAAA;AACtB;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfillCrypto.js","sources":["../../src/servers/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":[],"mappings":";;AAEA,eAAsB,cAAiB,GAAA;AACrC,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AACjC,EAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAC,UAAmB,CAAA,MAAA,GAAA,CAAU,MAAM,OAAO,aAAa,CAAG,EAAA,SAAA,CAAA;AAC3D,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfillFetch.js","sources":["../../src/servers/polyfillFetch.ts"],"sourcesContent":["import type { MaybePromise } from '../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n"],"names":[],"mappings":"AAIO,SAAS,cAAc,SAAgE,EAAA;AAC5F,EAAA,IAAI,WAAW,UAAY,EAAA;AACzB,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,IAAI,SAAW,EAAA;AACb,IAAM,MAAA,EAAE,OAAS,EAAA,KAAA,EAAO,QAAU,EAAA,OAAA,EAAS,OAAS,EAAA,UAAA,EAAY,UAAY,EAAA,QAAA,EAAU,IAAM,EAAA,IAAA,EAAS,GAAA,SAAA,CAAA;AACrG,IAAA,MAAA,CAAO,OAAO,UAAY,EAAA;AAAA,MACxB,KAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,IAAA;AAAA,KACD,CAAA,CAAA;AAED,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,OAAO,YAAY,CAAE,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,aAAA,CAAc,CAAC,CAAC,CAAA,CAAA;AAC1D;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfillJsDom.js","sources":["../../src/servers/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["window"],"mappings":";;AAGA,eAAsB,aAAgB,GAAA;AACpC,EAAI,IAAA,OAAO,WAAW,WAAa,EAAA;AACjC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AAEjC,EAAA,MAAM,EAAE,cAAgB,EAAA,KAAA,EAAU,GAAA,MAAM,OAAO,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