@wener/utils 1.1.50 → 1.1.51

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 (85) hide show
  1. package/lib/asyncs/createAsyncIterator.js.map +1 -1
  2. package/lib/cn/division/DivisionCode.js +21 -15
  3. package/lib/cn/division/DivisionCode.js.map +1 -1
  4. package/lib/crypto/getNodeCrypto.js +1 -1
  5. package/lib/crypto/getNodeCrypto.js.map +1 -1
  6. package/lib/crypto/ulid.js +1 -1
  7. package/lib/crypto/ulid.js.map +1 -1
  8. package/lib/fetch/createFetchWith.js +1 -1
  9. package/lib/fetch/createFetchWith.js.map +1 -1
  10. package/lib/fetch/createFetchWithLogging.js.map +1 -1
  11. package/lib/fetch/createFetchWithRetry.js +1 -1
  12. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  13. package/lib/index.js +9 -7
  14. package/lib/index.js.map +1 -1
  15. package/lib/io/ArrayBuffers.js +1 -1
  16. package/lib/io/ArrayBuffers.js.map +1 -1
  17. package/lib/io/isTransferable.js +1 -1
  18. package/lib/io/isTransferable.js.map +1 -1
  19. package/lib/langs/AsyncCloser.js.map +1 -0
  20. package/lib/langs/Closer.js.map +1 -0
  21. package/lib/langs/getGlobalStates.js +11 -3
  22. package/lib/langs/getGlobalStates.js.map +1 -1
  23. package/lib/langs/ifPresent.js +5 -0
  24. package/lib/langs/ifPresent.js.map +1 -0
  25. package/lib/scripts/getGenerateContext.js +2 -1
  26. package/lib/scripts/getGenerateContext.js.map +1 -1
  27. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +1 -1
  28. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
  29. package/lib/server/fetch/createFetchWithProxyByUndici.js +1 -1
  30. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
  31. package/lib/server/polyfill/polyfillCrypto.js +1 -1
  32. package/lib/server/polyfill/polyfillCrypto.js.map +1 -1
  33. package/lib/server/polyfill/polyfillJsDom.js +1 -1
  34. package/lib/server/polyfill/polyfillJsDom.js.map +1 -1
  35. package/lib/server/polyfill/polyfillWebSocket.js +1 -1
  36. package/lib/server/polyfill/polyfillWebSocket.js.map +1 -1
  37. package/lib/web/getGlobalThis.js.map +1 -0
  38. package/lib/{crypto → web}/getRandomValues.js +2 -2
  39. package/lib/web/getRandomValues.js.map +1 -0
  40. package/lib/{crypto → web}/randomUUID.js +1 -1
  41. package/lib/web/randomUUID.js.map +1 -0
  42. package/lib/web/requestIdleCallback.js +13 -0
  43. package/lib/web/requestIdleCallback.js.map +1 -0
  44. package/lib/web/structuredClone.js.map +1 -0
  45. package/package.json +3 -6
  46. package/src/asyncs/createAsyncIterator.ts +1 -1
  47. package/src/cn/division/DivisionCode.ts +25 -7
  48. package/src/cn/division/division.test.ts +18 -2
  49. package/src/crypto/getNodeCrypto.ts +1 -1
  50. package/src/crypto/hashing.test.ts +1 -1
  51. package/src/crypto/ulid.test.ts +1 -1
  52. package/src/crypto/ulid.ts +1 -1
  53. package/src/fetch/createFetchWith.ts +2 -2
  54. package/src/fetch/createFetchWithLogging.ts +1 -1
  55. package/src/fetch/createFetchWithRetry.ts +1 -1
  56. package/src/index.ts +9 -8
  57. package/src/io/ArrayBuffers.ts +1 -1
  58. package/src/io/isTransferable.ts +1 -1
  59. package/src/langs/getGlobalStates.ts +13 -3
  60. package/src/langs/ifPresent.ts +3 -0
  61. package/src/scripts/getGenerateContext.ts +3 -1
  62. package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +2 -2
  63. package/src/server/fetch/createFetchWithProxyByUndici.ts +1 -1
  64. package/src/server/polyfill/polyfillCrypto.ts +1 -1
  65. package/src/server/polyfill/polyfillJsDom.ts +1 -1
  66. package/src/server/polyfill/polyfillWebSocket.ts +1 -1
  67. package/src/validations/isUUID.test.ts +1 -1
  68. package/src/{crypto → web}/getRandomValues.ts +2 -2
  69. package/src/{crypto → web}/randomUUID.ts +1 -1
  70. package/src/web/requestIdleCallback.ts +14 -0
  71. package/lib/crypto/getRandomValues.js.map +0 -1
  72. package/lib/crypto/randomUUID.js.map +0 -1
  73. package/lib/runtime/AsyncCloser.js.map +0 -1
  74. package/lib/runtime/Closer.js.map +0 -1
  75. package/lib/runtime/getGlobalThis.js.map +0 -1
  76. package/lib/runtime/structuredClone.js.map +0 -1
  77. /package/lib/{runtime → langs}/AsyncCloser.js +0 -0
  78. /package/lib/{runtime → langs}/Closer.js +0 -0
  79. /package/lib/{runtime → web}/getGlobalThis.js +0 -0
  80. /package/lib/{runtime → web}/structuredClone.js +0 -0
  81. /package/src/{runtime → langs}/AsyncCloser.ts +0 -0
  82. /package/src/{runtime → langs}/Closer.ts +0 -0
  83. /package/src/{runtime → web}/getGlobalThis.ts +0 -0
  84. /package/src/{runtime → web}/structuredClone.test.ts +0 -0
  85. /package/src/{runtime → web}/structuredClone.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/scripts/getGenerateContext.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { Errors, formatBytes, type MaybePromise } from '@wener/utils';\nimport { getPackageDir } from '../server';\n\nlet _root: GenerateContext;\n\nexport interface GenerateContext {\n pkgDir: string;\n rootDataDir: string;\n rootCacheDir: string;\n dataDir: string;\n cacheDir: string;\n srcDir: string;\n cache: (url: string) => Promise<string>;\n writeData: (path: string, content: string) => Promise<void>;\n writeSrc: (path: string, content: string) => Promise<void>;\n}\n\nasync function cache(dir: string, url: string): Promise<string> {\n const key = path.basename(url);\n await fs.mkdir(path.join(dir), { recursive: true });\n const file = path.join(dir, key);\n try {\n await fs.stat(file);\n console.info('[cache] hit', url);\n return await fs.readFile(file, 'utf-8');\n } catch (e) {}\n console.info('[cache] miss', url);\n const text = await fetch(url).then((v) => {\n if (v.status >= 300) {\n throw new Error(`[cache] fetch ${url} ${v.status} ${v.statusText}`);\n }\n return v.text();\n });\n const size = new Blob([text]).size;\n console.info(`[cache] write ${file} ${formatBytes(size)} (${size})`);\n await fs.writeFile(file, text);\n return text;\n}\n\nexport function getGenerateContext(prefix?: string): MaybePromise<GenerateContext> {\n if (prefix) {\n return Promise.resolve(getGenerateContext()).then((c) => {\n const cacheDir = path.resolve(c.cacheDir, prefix);\n const dataDir = path.resolve(c.dataDir, prefix);\n const srcDir = path.resolve(c.srcDir, prefix);\n return {\n ...c,\n dataDir,\n cacheDir,\n srcDir,\n cache: (url: string) => cache(cacheDir, url),\n writeData: (file: string, content: string) => write(dataDir, file, content),\n writeSrc: (file: string, content: string) => write(srcDir, file, content),\n };\n });\n }\n return (\n _root ||\n Promise.resolve().then(async () => {\n const pkgDir = await getPackageDir();\n Errors.BadRequest.check(pkgDir, 'pkgDir not found');\n const dataDir = path.resolve(pkgDir, 'data');\n const cacheDir = path.resolve(pkgDir, 'cache');\n const srcDir = path.resolve(pkgDir, 'src');\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.mkdir(dataDir, { recursive: true });\n return (_root = Object.freeze({\n pkgDir,\n dataDir,\n cacheDir,\n srcDir,\n rootCacheDir: cacheDir,\n rootDataDir: dataDir,\n cache: (url: string) => cache(cacheDir, url),\n writeData: (file: string, content: string) => write(dataDir, file, content),\n writeSrc: (file: string, content: string) => write(srcDir, file, content),\n }));\n })\n );\n}\n\nasync function write(dir: string, file: string, content: string) {\n const size = new Blob([content]).size;\n const dst = path.join(dir, file);\n let last;\n try {\n last = (await fs.stat(dst)).size;\n } catch {}\n console.info(\n `[write] ${path.relative(_root.pkgDir, dir)} ${file} ${\n last ? (last !== size ? `${formatBytes(last)} (${last}) -> ` : 'SAME SIZE ') : ''\n }${formatBytes(size)} (${size})`,\n );\n await fs.writeFile(dst, content);\n}\n"],"names":["fs","path","Errors","formatBytes","getPackageDir","_root","cache","dir","url","key","basename","mkdir","join","recursive","file","stat","console","info","readFile","e","text","fetch","then","v","status","Error","statusText","size","Blob","writeFile","getGenerateContext","prefix","Promise","resolve","c","cacheDir","dataDir","srcDir","writeData","content","write","writeSrc","pkgDir","BadRequest","check","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B,IAAIoC;IACJ,IAAI;QACFA,OAAO,AAAC,CAAA,MAAMlD,GAAGe,IAAI,CAACkC,IAAG,EAAGtB,IAAI;IAClC,EAAE,OAAM,CAAC;IACTX,QAAQC,IAAI,CACV,CAAC,QAAQ,EAAEhB,KAAKkD,QAAQ,CAAC9C,MAAMqC,MAAM,EAAEnC,KAAK,CAAC,EAAEO,KAAK,CAAC,EACnDoC,OAAQA,SAASvB,OAAO,GAAGxB,YAAY+C,MAAM,EAAE,EAAEA,KAAK,KAAK,CAAC,GAAG,eAAgB,KAC9E/C,YAAYwB,MAAM,EAAE,EAAEA,KAAK,CAAC,CAAC;IAElC,MAAM3B,GAAG6B,SAAS,CAACoB,KAAKV;AAC1B"}
1
+ {"version":3,"sources":["../../src/scripts/getGenerateContext.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { MaybePromise } from '../asyncs/MaybePromise';\nimport { Errors } from '../errors/Errors';\nimport { getPackageDir } from '../server';\nimport { formatBytes } from '../strings/formatBytes';\n\nlet _root: GenerateContext;\n\nexport interface GenerateContext {\n pkgDir: string;\n rootDataDir: string;\n rootCacheDir: string;\n dataDir: string;\n cacheDir: string;\n srcDir: string;\n cache: (url: string) => Promise<string>;\n writeData: (path: string, content: string) => Promise<void>;\n writeSrc: (path: string, content: string) => Promise<void>;\n}\n\nasync function cache(dir: string, url: string): Promise<string> {\n const key = path.basename(url);\n await fs.mkdir(path.join(dir), { recursive: true });\n const file = path.join(dir, key);\n try {\n await fs.stat(file);\n console.info('[cache] hit', url);\n return await fs.readFile(file, 'utf-8');\n } catch (e) {}\n console.info('[cache] miss', url);\n const text = await fetch(url).then((v) => {\n if (v.status >= 300) {\n throw new Error(`[cache] fetch ${url} ${v.status} ${v.statusText}`);\n }\n return v.text();\n });\n const size = new Blob([text]).size;\n console.info(`[cache] write ${file} ${formatBytes(size)} (${size})`);\n await fs.writeFile(file, text);\n return text;\n}\n\nexport function getGenerateContext(prefix?: string): MaybePromise<GenerateContext> {\n if (prefix) {\n return Promise.resolve(getGenerateContext()).then((c) => {\n const cacheDir = path.resolve(c.cacheDir, prefix);\n const dataDir = path.resolve(c.dataDir, prefix);\n const srcDir = path.resolve(c.srcDir, prefix);\n return {\n ...c,\n dataDir,\n cacheDir,\n srcDir,\n cache: (url: string) => cache(cacheDir, url),\n writeData: (file: string, content: string) => write(dataDir, file, content),\n writeSrc: (file: string, content: string) => write(srcDir, file, content),\n };\n });\n }\n return (\n _root ||\n Promise.resolve().then(async () => {\n const pkgDir = await getPackageDir();\n Errors.BadRequest.check(pkgDir, 'pkgDir not found');\n const dataDir = path.resolve(pkgDir, 'data');\n const cacheDir = path.resolve(pkgDir, 'cache');\n const srcDir = path.resolve(pkgDir, 'src');\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.mkdir(dataDir, { recursive: true });\n return (_root = Object.freeze({\n pkgDir,\n dataDir,\n cacheDir,\n srcDir,\n rootCacheDir: cacheDir,\n rootDataDir: dataDir,\n cache: (url: string) => cache(cacheDir, url),\n writeData: (file: string, content: string) => write(dataDir, file, content),\n writeSrc: (file: string, content: string) => write(srcDir, file, content),\n }));\n })\n );\n}\n\nasync function write(dir: string, file: string, content: string) {\n const size = new Blob([content]).size;\n const dst = path.join(dir, file);\n let last;\n try {\n last = (await fs.stat(dst)).size;\n } catch {}\n console.info(\n `[write] ${path.relative(_root.pkgDir, dir)} ${file} ${\n last ? (last !== size ? `${formatBytes(last)} (${last}) -> ` : 'SAME SIZE ') : ''\n }${formatBytes(size)} (${size})`,\n );\n await fs.writeFile(dst, content);\n}\n"],"names":["fs","path","Errors","getPackageDir","formatBytes","_root","cache","dir","url","key","basename","mkdir","join","recursive","file","stat","console","info","readFile","e","text","fetch","then","v","status","Error","statusText","size","Blob","writeFile","getGenerateContext","prefix","Promise","resolve","c","cacheDir","dataDir","srcDir","writeData","content","write","writeSrc","pkgDir","BadRequest","check","Object","freeze","rootCacheDir","rootDataDir","dst","last","relative"],"mappings":"AAAA,OAAO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AAO,AAAC,CAAA,MAAMlD,GAAGe,IAAI,CAACkC,IAAG,EAAGtB,IAAI;IAClC,EAAE,OAAM,CAAC;IACTX,QAAQC,IAAI,CACV,CAAC,QAAQ,EAAEhB,KAAKkD,QAAQ,CAAC9C,MAAMqC,MAAM,EAAEnC,KAAK,CAAC,EAAEO,KAAK,CAAC,EACnDoC,OAAQA,SAASvB,OAAO,GAAGvB,YAAY8C,MAAM,EAAE,EAAEA,KAAK,KAAK,CAAC,GAAG,eAAgB,KAC9E9C,YAAYuB,MAAM,EAAE,EAAEA,KAAK,CAAC,CAAC;IAElC,MAAM3B,GAAG6B,SAAS,CAACoB,KAAKV;AAC1B"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export function createFetchWithProxyByNodeFetch({ proxy, fetch } = {}) {
3
3
  const globalThis = getGlobalThis();
4
4
  if (!proxy) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["getGlobalThis","createFetchWithProxyByNodeFetch","proxy","fetch","globalThis","agent","Request","NodeRequest","NodeFetch","url","init","default","createHttpsProxyAgent"],"mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,SAASC,gCAAgC,EAC9CC,KAAK,EACLC,KAAK,EACiC,GAAG,CAAC,CAAC;IAC3C,MAAMC,aAAaJ;IACnB,IAAI,CAACE,OAAO;QACV,OAAOC,SAASC,WAAWD,KAAK;IAClC;IAEA,IAAIE;IACJ,MAAMC,UAAUF,WAAWE,OAAO;IAClC,IAAIC;IACJ,IAAIC;IACJ,OAAO,OAAOC,KAAKC;QACjB,IAAI,CAACL,OAAO;YACV,MAAM,EAAEM,SAASC,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC;YACxDP,QAAQ,AAACO,sBAA8BV;QACzC;QAEA,oCAAoC;QACpC,IAAI,CAACK,aAAa;YACf,CAAA,EAAED,SAASC,WAAW,EAAEI,SAASH,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAY;QAC3E;QAEAL,UAAUK;QAEV,IAAIC,eAAeH,SAAS;YAC1B,OAAO,AAACH,MAAc,IAAIG,QAAQG,KAAK;gBAAEJ;YAAM;QACjD;QACA,IAAI,AAACI,eAAuBF,aAAa;YACvC,OAAO,AAACJ,MAAc,IAAII,YAAYE,KAAK;gBAAEJ;YAAM;QACrD;QACA,OAAO,AAACF,MAAcM,KAAK;YACzB,GAAGC,IAAI;YACPL;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import type { FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../web/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["getGlobalThis","createFetchWithProxyByNodeFetch","proxy","fetch","globalThis","agent","Request","NodeRequest","NodeFetch","url","init","default","createHttpsProxyAgent"],"mappings":"AACA,SAASA,aAAa,QAAQ,0BAA0B;AAExD,OAAO,SAASC,gCAAgC,EAC9CC,KAAK,EACLC,KAAK,EACiC,GAAG,CAAC,CAAC;IAC3C,MAAMC,aAAaJ;IACnB,IAAI,CAACE,OAAO;QACV,OAAOC,SAASC,WAAWD,KAAK;IAClC;IAEA,IAAIE;IACJ,MAAMC,UAAUF,WAAWE,OAAO;IAClC,IAAIC;IACJ,IAAIC;IACJ,OAAO,OAAOC,KAAKC;QACjB,IAAI,CAACL,OAAO;YACV,MAAM,EAAEM,SAASC,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC;YACxDP,QAAQ,AAACO,sBAA8BV;QACzC;QAEA,oCAAoC;QACpC,IAAI,CAACK,aAAa;YACf,CAAA,EAAED,SAASC,WAAW,EAAEI,SAASH,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAY;QAC3E;QAEAL,UAAUK;QAEV,IAAIC,eAAeH,SAAS;YAC1B,OAAO,AAACH,MAAc,IAAIG,QAAQG,KAAK;gBAAEJ;YAAM;QACjD;QACA,IAAI,AAACI,eAAuBF,aAAa;YACvC,OAAO,AAACJ,MAAc,IAAII,YAAYE,KAAK;gBAAEJ;YAAM;QACrD;QACA,OAAO,AAACF,MAAcM,KAAK;YACzB,GAAGC,IAAI;YACPL;QACF;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { createFetchWith } from '../../fetch/index.js';
2
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
2
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
3
3
  export function createFetchWithProxyByUndici({ proxy, token: _token, fetch, undici } = {}) {
4
4
  if (!proxy) {
5
5
  return fetch || globalThis.fetch;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByUndici.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { createFetchWith, type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\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\n if ((getGlobalThis() as any).Bun) {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req, next }) => {\n return next(url, {\n ...req,\n // https://github.com/oven-sh/bun/issues/1829\n proxy,\n } as RequestInit);\n },\n });\n }\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":["createFetchWith","getGlobalThis","createFetchWithProxyByUndici","proxy","token","_token","fetch","undici","globalThis","Bun","onRequest","url","req","next","agent","args","init","body","ReadableStream","Symbol","asyncIterator","duplex","uri","u","URL","e","username","password","btoa","toString","mod","ProxyAgent","dispatcher"],"mappings":"AACA,SAASA,eAAe,QAAwB,cAAc;AAC9D,SAASC,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,SAASC,6BAA6B,EAC3CC,KAAK,EACLC,OAAOC,MAAM,EACbC,KAAK,EACLC,MAAM,EAMP,GAAG,CAAC,CAAC;IACJ,IAAI,CAACJ,OAAO;QACV,OAAOG,SAASE,WAAWF,KAAK;IAClC;IAEA,IAAI,AAACL,gBAAwBQ,GAAG,EAAE;QAChC,OAAOT,gBAAgB;YACrBM;YACAI,WAAW,CAAC,EAAEC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAE;gBAC5B,OAAOA,KAAKF,KAAK;oBACf,GAAGC,GAAG;oBACN,6CAA6C;oBAC7CT;gBACF;YACF;QACF;IACF;IAEA,IAAIW;IACJ,0EAA0E;IAC1E,OAAO,OAAO,GAAGC;QACf,MAAMC,OAAQD,IAAI,CAAC,EAAE,KAAK,CAAC;QAI3B;YACE,MAAME,OAAOD,KAAKC,IAAI;YACtB,IAAI,OAAOA,SAAS,YAAYA,QAASA,CAAAA,gBAAgBC,kBAAkBC,OAAOC,aAAa,IAAIH,IAAG,GAAI;gBACxG,kFAAkF;gBAClFD,KAAKK,MAAM,KAAK;YAClB;QACF;QACA,IAAI,CAACP,OAAO;YACV,IAAIQ,MAAMnB;YACV,IAAIC,QAAQC;YACZ;gBACE,IAAIkB;gBACJ,IAAI;oBACFA,IAAI,IAAIC,IAAIrB;gBACd,EAAE,OAAOsB,GAAG,CAAC;gBACb,IAAI,CAACrB,SAASmB,KAAMA,CAAAA,EAAEG,QAAQ,IAAIH,EAAEI,QAAQ,AAAD,GAAI;oBAC7CvB,QAAQ,CAAC,MAAM,EAAEwB,KAAK,GAAGL,EAAEG,QAAQ,IAAI,GAAG,CAAC,EAAEH,EAAEI,QAAQ,EAAE,GAAG;oBAC5DJ,EAAEG,QAAQ,GAAG;oBACbH,EAAEI,QAAQ,GAAG;oBACbL,MAAMC,EAAEM,QAAQ;gBAClB;YACF;YACA,6CAA6C;YAC7CtB,WAAW,MAAM,CAAC;YAClB,MAAMuB,MAAM,MAAMvB;YAClB,MAAMwB,aAAaD,IAAIC,UAAU;YACjCzB,UAAUwB,IAAIxB,KAAK;YACnB,oEAAoE;YACpEQ,QAAQ,IAAIiB,WAAW;gBACrBT;gBACAlB;YACF;QACA,sEAAsE;QACtE,oEAAoE;QACpE,yEAAyE;QAC3E;QACAY,KAAKgB,UAAU,GAAGlB;QAClB,OAAO,MAAMR,SAAUS;IACzB;AACF"}
1
+ {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByUndici.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { createFetchWith, type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../web/getGlobalThis';\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\n if ((getGlobalThis() as any).Bun) {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req, next }) => {\n return next(url, {\n ...req,\n // https://github.com/oven-sh/bun/issues/1829\n proxy,\n } as RequestInit);\n },\n });\n }\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":["createFetchWith","getGlobalThis","createFetchWithProxyByUndici","proxy","token","_token","fetch","undici","globalThis","Bun","onRequest","url","req","next","agent","args","init","body","ReadableStream","Symbol","asyncIterator","duplex","uri","u","URL","e","username","password","btoa","toString","mod","ProxyAgent","dispatcher"],"mappings":"AACA,SAASA,eAAe,QAAwB,cAAc;AAC9D,SAASC,aAAa,QAAQ,0BAA0B;AAExD,OAAO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AaD,IAAIC,UAAU;YACjCzB,UAAUwB,IAAIxB,KAAK;YACnB,oEAAoE;YACpEQ,QAAQ,IAAIiB,WAAW;gBACrBT;gBACAlB;YACF;QACA,sEAAsE;QACtE,oEAAoE;QACpE,yEAAyE;QAC3E;QACAY,KAAKgB,UAAU,GAAGlB;QAClB,OAAO,MAAMR,SAAUS;IACzB;AACF"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export async function polyfillCrypto() {
3
3
  const globalThis = getGlobalThis();
4
4
  if ('crypto' in globalThis) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../../runtime/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":["getGlobalThis","polyfillCrypto","globalThis","crypto","webcrypto"],"mappings":"AAAA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,eAAeC;IACpB,MAAMC,aAAaF;IACnB,IAAI,YAAYE,YAAY;QAC1B,OAAO;IACT;IACCA,WAAmBC,MAAM,GAAG,AAAC,CAAA,MAAM,MAAM,CAAC,cAAa,EAAGC,SAAS;IACpE,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../../web/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":["getGlobalThis","polyfillCrypto","globalThis","crypto","webcrypto"],"mappings":"AAAA,SAASA,aAAa,QAAQ,0BAA0B;AAExD,OAAO,eAAeC;IACpB,MAAMC,aAAaF;IACnB,IAAI,YAAYE,YAAY;QAC1B,OAAO;IACT;IACCA,WAAmBC,MAAM,GAAG,AAAC,CAAA,MAAM,MAAM,CAAC,cAAa,EAAGC,SAAS;IACpE,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export async function polyfillJsDom() {
3
3
  if (typeof window !== 'undefined') {
4
4
  return false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../../runtime/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":["getGlobalThis","polyfillJsDom","window","globalThis","ResourceLoader","JSDOM","Window","constructor","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","Object","assign","defaultJsdomConfig","protectedProperties","getOwnPropertyNames","filter","prop","installEnv","args","properties","arg","Array","isArray","userJsdomConfig","includes","indexOf","forEach","defineProperty","configurable","get","url"],"mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,eAAeC;IACpB,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,aAAaH;IAEnB,MAAM,EAAEI,cAAc,EAAEC,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;IAE/C,gEAAgE;IAChE,kEAAkE;IAClE,IAAA,AAAMC,SAAN,MAAMA;QACJC,YAAYC,OAA8D,CAAC,CAAC,CAAE;YAC5E,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;YACtD,MAAMK,YAAY,IAAIT,eAAe;gBACnCK;gBACAC;gBACAC;YACF;YACA,OAAO,IAAIN,MACT,IACAS,OAAOC,MAAM,CAACH,WAAW;gBACvBC;YACF,IACAX,MAAM;QACV;IACF;IAEA,qEAAqE;IACrE,wBAAwB;IACxB,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAMc,qBAAqB;IAK3B;IACA,+EAA+E;IAC/E,2CAA2C;IAC3C,MAAMC,sBAAsB,AAAC,CAAA,IAC3BH,OAAOI,mBAAmB,CAAC,IAAIZ,OAAOU,qBAAqBG,MAAM,CAC/D,CAACC,OAAS,OAAOjB,UAAU,CAACiB,KAAgC,KAAK,YACnE;IAEF,SAASC,WAAW,GAAGC,IAAW;QAChC,qCAAqC;QACrC,4BAA4B;QAC5B,MAAMC,aAAaD,KAAKH,MAAM,CAAC,CAACK,MAAaC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QACnE,MAAMG,kBAAkBL,KAAKH,MAAM,CAAC,CAACK,MAAa,CAACC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QAEzE,uBAAuB;QACvB,MAAMtB,UAAS,IAAII,OAAOQ,OAAOC,MAAM,CAAC,CAAC,GAAGY,iBAAiBX;QAE7D,oCAAoC;QACpCF,OAAOI,mBAAmB,CAAChB,QAEzB,8BAA8B;SAC7BiB,MAAM,CAAC,CAACC,OAAS,CAACH,oBAAoBW,QAAQ,CAACR,MAEhD,6EAA6E;SAC5ED,MAAM,CAAC,CAACC,OAAS,CAAEG,CAAAA,cAAcA,WAAWM,OAAO,CAACT,UAAU,CAAC,CAAA,GAC/DD,MAAM,CAAC,CAACC;YACP,OAAQA;gBACN,KAAK;oBACH,OAAO;YACX;YACA,OAAO;QACT,EAEA,+CAA+C;SAC9CU,OAAO,CAAC,CAACV;YACR,8CAA8C;YAC9CN,OAAOiB,cAAc,CAAC5B,YAAYiB,MAAM;gBACtCY,cAAc;gBACdC,KAAK,IAAM/B,OAAM,CAACkB,KAAqB;YACzC;QACF;QAEF,OAAOlB;IACT;IAEAmB,WAAW;QAAEa,KAAK;IAAmB;IACrC,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../../web/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":["getGlobalThis","polyfillJsDom","window","globalThis","ResourceLoader","JSDOM","Window","constructor","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","Object","assign","defaultJsdomConfig","protectedProperties","getOwnPropertyNames","filter","prop","installEnv","args","properties","arg","Array","isArray","userJsdomConfig","includes","indexOf","forEach","defineProperty","configurable","get","url"],"mappings":"AACA,SAASA,aAAa,QAAQ,0BAA0B;AAExD,OAAO,eAAeC;IACpB,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,aAAaH;IAEnB,MAAM,EAAEI,cAAc,EAAEC,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;IAE/C,gEAAgE;IAChE,kEAAkE;IAClE,IAAA,AAAMC,SAAN,MAAMA;QACJC,YAAYC,OAA8D,CAAC,CAAC,CAAE;YAC5E,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;YACtD,MAAMK,YAAY,IAAIT,eAAe;gBACnCK;gBACAC;gBACAC;YACF;YACA,OAAO,IAAIN,MACT,IACAS,OAAOC,MAAM,CAACH,WAAW;gBACvBC;YACF,IACAX,MAAM;QACV;IACF;IAEA,qEAAqE;IACrE,wBAAwB;IACxB,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAMc,qBAAqB;IAK3B;IACA,+EAA+E;IAC/E,2CAA2C;IAC3C,MAAMC,sBAAsB,AAAC,CAAA,IAC3BH,OAAOI,mBAAmB,CAAC,IAAIZ,OAAOU,qBAAqBG,MAAM,CAC/D,CAACC,OAAS,OAAOjB,UAAU,CAACiB,KAAgC,KAAK,YACnE;IAEF,SAASC,WAAW,GAAGC,IAAW;QAChC,qCAAqC;QACrC,4BAA4B;QAC5B,MAAMC,aAAaD,KAAKH,MAAM,CAAC,CAACK,MAAaC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QACnE,MAAMG,kBAAkBL,KAAKH,MAAM,CAAC,CAACK,MAAa,CAACC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QAEzE,uBAAuB;QACvB,MAAMtB,UAAS,IAAII,OAAOQ,OAAOC,MAAM,CAAC,CAAC,GAAGY,iBAAiBX;QAE7D,oCAAoC;QACpCF,OAAOI,mBAAmB,CAAChB,QAEzB,8BAA8B;SAC7BiB,MAAM,CAAC,CAACC,OAAS,CAACH,oBAAoBW,QAAQ,CAACR,MAEhD,6EAA6E;SAC5ED,MAAM,CAAC,CAACC,OAAS,CAAEG,CAAAA,cAAcA,WAAWM,OAAO,CAACT,UAAU,CAAC,CAAA,GAC/DD,MAAM,CAAC,CAACC;YACP,OAAQA;gBACN,KAAK;oBACH,OAAO;YACX;YACA,OAAO;QACT,EAEA,+CAA+C;SAC9CU,OAAO,CAAC,CAACV;YACR,8CAA8C;YAC9CN,OAAOiB,cAAc,CAAC5B,YAAYiB,MAAM;gBACtCY,cAAc;gBACdC,KAAK,IAAM/B,OAAM,CAACkB,KAAqB;YACzC;QACF;QAEF,OAAOlB;IACT;IAEAmB,WAAW;QAAEa,KAAK;IAAmB;IACrC,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export function polyfillWebSocket(ws) {
3
3
  const globalThis = getGlobalThis();
4
4
  if ('WebSocket' in globalThis) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillWebSocket.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport function polyfillWebSocket(ws: any): boolean;\nexport function polyfillWebSocket(ws?: undefined): Promise<boolean>;\nexport function polyfillWebSocket(ws?: any): MaybePromise<boolean> {\n const globalThis = getGlobalThis();\n if ('WebSocket' in globalThis) {\n return false;\n }\n if (ws && 'then' in ws) {\n return ws.then((v: any) => {\n return polyfillWebSocket(v?.default || v);\n });\n }\n if (ws) {\n const { WebSocket } = ws;\n Object.assign(globalThis, { WebSocket });\n }\n return import('ws').then((ws) => polyfillWebSocket(ws));\n}\n"],"names":["getGlobalThis","polyfillWebSocket","ws","globalThis","then","v","default","WebSocket","Object","assign"],"mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAI5D,OAAO,SAASC,kBAAkBC,EAAQ;IACxC,MAAMC,aAAaH;IACnB,IAAI,eAAeG,YAAY;QAC7B,OAAO;IACT;IACA,IAAID,MAAM,UAAUA,IAAI;QACtB,OAAOA,GAAGE,IAAI,CAAC,CAACC;YACd,OAAOJ,kBAAkBI,GAAGC,WAAWD;QACzC;IACF;IACA,IAAIH,IAAI;QACN,MAAM,EAAEK,SAAS,EAAE,GAAGL;QACtBM,OAAOC,MAAM,CAACN,YAAY;YAAEI;QAAU;IACxC;IACA,OAAO,MAAM,CAAC,MAAMH,IAAI,CAAC,CAACF,KAAOD,kBAAkBC;AACrD"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillWebSocket.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { getGlobalThis } from '../../web/getGlobalThis';\n\nexport function polyfillWebSocket(ws: any): boolean;\nexport function polyfillWebSocket(ws?: undefined): Promise<boolean>;\nexport function polyfillWebSocket(ws?: any): MaybePromise<boolean> {\n const globalThis = getGlobalThis();\n if ('WebSocket' in globalThis) {\n return false;\n }\n if (ws && 'then' in ws) {\n return ws.then((v: any) => {\n return polyfillWebSocket(v?.default || v);\n });\n }\n if (ws) {\n const { WebSocket } = ws;\n Object.assign(globalThis, { WebSocket });\n }\n return import('ws').then((ws) => polyfillWebSocket(ws));\n}\n"],"names":["getGlobalThis","polyfillWebSocket","ws","globalThis","then","v","default","WebSocket","Object","assign"],"mappings":"AACA,SAASA,aAAa,QAAQ,0BAA0B;AAIxD,OAAO,SAASC,kBAAkBC,EAAQ;IACxC,MAAMC,aAAaH;IACnB,IAAI,eAAeG,YAAY;QAC7B,OAAO;IACT;IACA,IAAID,MAAM,UAAUA,IAAI;QACtB,OAAOA,GAAGE,IAAI,CAAC,CAACC;YACd,OAAOJ,kBAAkBI,GAAGC,WAAWD;QACzC;IACF;IACA,IAAIH,IAAI;QACN,MAAM,EAAEK,SAAS,EAAE,GAAGL;QACtBM,OAAOC,MAAM,CAACN,YAAY;YAAEI;QAAU;IACxC;IACA,OAAO,MAAM,CAAC,MAAMH,IAAI,CAAC,CAACF,KAAOD,kBAAkBC;AACrD"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/getGlobalThis.ts"],"sourcesContent":["declare const global: typeof globalThis;\n\n/**\n * isomorphic globalThis\n *\n * globalThis supported by ff 65, Chrome 71, Node 12, babel\n *\n * non-standard globalThis supported for Alipay Miniprogram\n *\n * @see https://caniuse.com/#search=globalThis\n * @see https://v8.dev/features/globalthis\n */\nexport const getGlobalThis = (): typeof globalThis => {\n if (typeof globalThis !== 'undefined') return globalThis;\n if (typeof self !== 'undefined') return self;\n if (typeof window !== 'undefined') return window;\n if (typeof global !== 'undefined') return global as any;\n if (typeof this !== 'undefined') return this as any;\n throw new Error('Unable to locate global `this`');\n};\n"],"names":["getGlobalThis","globalThis","self","window","global","Error"],"mappings":"AAEA;;;;;;;;;CASC,GACD,OAAO,MAAMA,gBAAgB;IAC3B,IAAI,OAAOC,eAAe,aAAa,OAAOA;IAC9C,IAAI,OAAOC,SAAS,aAAa,OAAOA;IACxC,IAAI,OAAOC,WAAW,aAAa,OAAOA;IAC1C,IAAI,OAAOC,WAAW,aAAa,OAAOA;IAC1C,IAAI,OAAO,IAAI,KAAK,aAAa,OAAO,IAAI;IAC5C,MAAM,IAAIC,MAAM;AAClB,EAAE"}
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
2
- import { getGlobalThis } from '../runtime/getGlobalThis.js';
3
- import { getNodeCrypto } from './getNodeCrypto.js';
2
+ import { getNodeCrypto } from '../crypto/getNodeCrypto.js';
3
+ import { getGlobalThis } from './getGlobalThis.js';
4
4
  const globalThis = getGlobalThis();
5
5
  // chrome 11+, safari 5+, nodejs 17.4+
6
6
  // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { getNodeCrypto } from '../crypto/getNodeCrypto';\nimport type { TypedArray } from '../io/ArrayBuffers';\nimport { getGlobalThis } from './getGlobalThis';\n\nconst globalThis = getGlobalThis();\n\n// chrome 11+, safari 5+, nodejs 17.4+\n// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\nexport let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =\n globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||\n (globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||\n (() => {\n throw new Error('[getRandomValues]: No secure random number generator available.');\n });\n\nfunction _getRandomValues<T extends Exclude<TypedArray, Float32Array | Float64Array>>(buf: T) {\n const nodeCrypto = getNodeCrypto();\n // avoid type error\n let wc = nodeCrypto?.webcrypto as any;\n if (wc?.getRandomValues) {\n getRandomValues = wc.getRandomValues?.bind(nodeCrypto?.webcrypto);\n return wc.getRandomValues(buf);\n }\n if (nodeCrypto?.randomBytes) {\n if (!(buf instanceof Uint8Array)) {\n throw new TypeError('expected Uint8Array');\n }\n if (buf.length > 65536) {\n const e: any = new Error();\n e.code = 22;\n e.message = `Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`;\n e.name = 'QuotaExceededError';\n throw e;\n }\n const bytes = nodeCrypto.randomBytes(buf.length);\n buf.set(bytes);\n return buf;\n }\n throw new Error('[getRandomValues]: No secure random number generator available.');\n}\n"],"names":["getNodeCrypto","getGlobalThis","globalThis","getRandomValues","crypto","bind","msCrypto","Error","_getRandomValues","buf","nodeCrypto","wc","webcrypto","randomBytes","Uint8Array","TypeError","length","e","code","message","name","bytes","set"],"mappings":"AAAA,sEAAsE;AACtE,SAASA,aAAa,QAAQ,0BAA0B;AAExD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaD;AAEnB,sCAAsC;AACtC,0EAA0E;AAC1E,OAAO,IAAIE,kBACTD,WAAWE,MAAM,EAAED,iBAAiBE,KAAKH,WAAWE,MAAM,KAC1D,AAACF,WAAmBI,QAAQ,EAAEH,iBAAiBE,KAAK,AAACH,WAAmBI,QAAQ,KAC/E,CAAA;IACC,MAAM,IAAIC,MAAM;AAClB,CAAA,EAAG;AAEL,SAASC,iBAA6EC,GAAM;IAC1F,MAAMC,aAAaV;IACnB,mBAAmB;IACnB,IAAIW,KAAKD,YAAYE;IACrB,IAAID,IAAIR,iBAAiB;QACvBA,kBAAkBQ,GAAGR,eAAe,EAAEE,KAAKK,YAAYE;QACvD,OAAOD,GAAGR,eAAe,CAACM;IAC5B;IACA,IAAIC,YAAYG,aAAa;QAC3B,IAAI,CAAEJ,CAAAA,eAAeK,UAAS,GAAI;YAChC,MAAM,IAAIC,UAAU;QACtB;QACA,IAAIN,IAAIO,MAAM,GAAG,OAAO;YACtB,MAAMC,IAAS,IAAIV;YACnBU,EAAEC,IAAI,GAAG;YACTD,EAAEE,OAAO,GAAG,CAAC,oFAAoF,EAAEV,IAAIO,MAAM,CAAC,wEAAwE,CAAC;YACvLC,EAAEG,IAAI,GAAG;YACT,MAAMH;QACR;QACA,MAAMI,QAAQX,WAAWG,WAAW,CAACJ,IAAIO,MAAM;QAC/CP,IAAIa,GAAG,CAACD;QACR,OAAOZ;IACT;IACA,MAAM,IAAIF,MAAM;AAClB"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from './getGlobalThis.js';
2
2
  const globalThis = getGlobalThis();
3
3
  /**
4
4
  * generate random UUIDv4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/randomUUID.ts"],"sourcesContent":["import { getGlobalThis } from './getGlobalThis';\n\nconst globalThis = getGlobalThis();\n\n/**\n * generate random UUIDv4\n */\nexport const randomUUID: () => string = globalThis.crypto?.randomUUID?.bind(globalThis.crypto) || _randomUUID;\n\n/**\n * @internal\n */\nexport function _randomUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["getGlobalThis","globalThis","randomUUID","crypto","bind","_randomUUID","replace","c","r","Math","random","v","toString"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaD;AAEnB;;CAEC,GACD,OAAO,MAAME,aAA2BD,WAAWE,MAAM,EAAED,YAAYE,KAAKH,WAAWE,MAAM,KAAKE,YAAY;AAE9G;;CAEC,GACD,OAAO,SAASA;IACd,OAAO,uCAAuCC,OAAO,CAAC,SAAS,CAACC;QAC9D,MAAMC,IAAI,AAACC,KAAKC,MAAM,KAAK,KAAM;QACjC,MAAMC,IAAIJ,MAAM,MAAMC,IAAI,AAACA,IAAI,MAAO;QACtC,OAAOG,EAAEC,QAAQ,CAAC;IACpB;AACF"}
@@ -0,0 +1,13 @@
1
+ // for safari
2
+ export const requestIdleCallback = globalThis.requestIdleCallback || ((callback, options)=>{
3
+ const start = Date.now();
4
+ const deadline = {
5
+ didTimeout: false,
6
+ timeRemaining: ()=>Math.max(0, 50 - (Date.now() - start))
7
+ };
8
+ // skip options?.timeout
9
+ return setTimeout(()=>callback(deadline), 1);
10
+ });
11
+ export const cancelIdleCallback = globalThis.cancelIdleCallback || ((id)=>clearTimeout(id));
12
+
13
+ //# sourceMappingURL=requestIdleCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/requestIdleCallback.ts"],"sourcesContent":["// for safari\nexport const requestIdleCallback =\n globalThis.requestIdleCallback ||\n ((callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => {\n const start = Date.now();\n const deadline: IdleDeadline = {\n didTimeout: false,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - start)),\n };\n // skip options?.timeout\n return setTimeout(() => callback(deadline), 1);\n });\n\nexport const cancelIdleCallback = globalThis.cancelIdleCallback || ((id: number) => clearTimeout(id));\n"],"names":["requestIdleCallback","globalThis","callback","options","start","Date","now","deadline","didTimeout","timeRemaining","Math","max","setTimeout","cancelIdleCallback","id","clearTimeout"],"mappings":"AAAA,aAAa;AACb,OAAO,MAAMA,sBACXC,WAAWD,mBAAmB,IAC7B,CAAA,CAACE,UAA4CC;IAC5C,MAAMC,QAAQC,KAAKC,GAAG;IACtB,MAAMC,WAAyB;QAC7BC,YAAY;QACZC,eAAe,IAAMC,KAAKC,GAAG,CAAC,GAAG,KAAMN,CAAAA,KAAKC,GAAG,KAAKF,KAAI;IAC1D;IACA,wBAAwB;IACxB,OAAOQ,WAAW,IAAMV,SAASK,WAAW;AAC9C,CAAA,EAAG;AAEL,OAAO,MAAMM,qBAAqBZ,WAAWY,kBAAkB,IAAK,CAAA,CAACC,KAAeC,aAAaD,GAAE,EAAG"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/structuredClone.ts"],"sourcesContent":["/* eslint no-proto:0 */\nimport { classOf } from '../langs/classOf';\n\n/**\n * Clone an object using structured cloning algorithm\n *\n * - Chrome 98, Safari 15.4, NodeJS 17\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/structuredClone structuredClone}\n * @see {@link https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js core-js}\n */\nexport const structuredClone: <T>(value: T, options?: StructuredSerializeOptions) => T =\n globalThis.structuredClone || _clone;\n\nfunction set(obj: any, key: any, val: any) {\n if (typeof val.value === 'object') val.value = _clone(val.value);\n if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {\n Object.defineProperty(obj, key, val);\n } else obj[key] = val.value;\n}\n\n/**\n * @see {@link https://github.com/lukeed/klona/blob/master/src/full.js klona}\n */\nexport function _clone(x: any): any {\n // too complex\n // https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js\n\n if (typeof x !== 'object') return x;\n\n let i = 0;\n let k;\n let list;\n let tmp: any;\n const str = classOf(x);\n switch (str) {\n case 'Array':\n tmp = Array(x.length);\n break;\n case 'Object':\n tmp = Object.create(x.__proto__ || null);\n break;\n case 'Set':\n tmp = new Set();\n x.forEach(function (val: any) {\n tmp.add(_clone(val));\n });\n break;\n case 'Map':\n tmp = new Map();\n x.forEach(function (val: any, key: any) {\n tmp.set(_clone(key), _clone(val));\n });\n break;\n case 'Date':\n tmp = new Date(+x);\n break;\n case 'RegExp':\n tmp = new RegExp(x.source, x.flags);\n break;\n case 'DataView':\n tmp = new x.constructor(_clone(x.buffer));\n break;\n case 'ArrayBuffer':\n tmp = x.slice(0);\n break;\n default:\n // typed arrays\n if (str.endsWith('Array')) {\n // ArrayBuffer.isView(x)\n // ~> `new` bcuz `Buffer.slice` => ref\n tmp = new x.constructor(x);\n }\n }\n\n if (tmp) {\n for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {\n set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));\n }\n\n for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {\n if (Object.hasOwnProperty.call(tmp, (k = list[i])) && tmp[k] === x[k]) continue;\n set(tmp, k, Object.getOwnPropertyDescriptor(x, k));\n }\n }\n\n return tmp || x;\n}\n"],"names":["classOf","structuredClone","globalThis","_clone","set","obj","key","val","value","enumerable","get","configurable","writable","Object","defineProperty","x","i","k","list","tmp","str","Array","length","create","__proto__","Set","forEach","add","Map","Date","RegExp","source","flags","constructor","buffer","slice","endsWith","getOwnPropertySymbols","getOwnProp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AAEgB,MAAM,EAAEhB,EAAEiB,KAAK;YAClC;QACF,KAAK;YACHb,MAAM,IAAIJ,EAAEkB,WAAW,CAAC9B,OAAOY,EAAEmB,MAAM;YACvC;QACF,KAAK;YACHf,MAAMJ,EAAEoB,KAAK,CAAC;YACd;QACF;YACE,eAAe;YACf,IAAIf,IAAIgB,QAAQ,CAAC,UAAU;gBACzB,wBAAwB;gBACxB,sCAAsC;gBACtCjB,MAAM,IAAIJ,EAAEkB,WAAW,CAAClB;YAC1B;IACJ;IAEA,IAAII,KAAK;QACP,IAAKD,OAAOL,OAAOwB,qBAAqB,CAACtB,IAAIC,IAAIE,KAAKI,MAAM,EAAEN,IAAK;YACjEZ,IAAIe,KAAKD,IAAI,CAACF,EAAE,EAAEH,OAAOyB,wBAAwB,CAACvB,GAAGG,IAAI,CAACF,EAAE;QAC9D;QAEA,IAAKA,IAAI,GAAGE,OAAOL,OAAO0B,mBAAmB,CAACxB,IAAIC,IAAIE,KAAKI,MAAM,EAAEN,IAAK;YACtE,IAAIH,OAAO2B,cAAc,CAACC,IAAI,CAACtB,KAAMF,IAAIC,IAAI,CAACF,EAAE,KAAMG,GAAG,CAACF,EAAE,KAAKF,CAAC,CAACE,EAAE,EAAE;YACvEb,IAAIe,KAAKF,GAAGJ,OAAOyB,wBAAwB,CAACvB,GAAGE;QACjD;IACF;IAEA,OAAOE,OAAOJ;AAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.50",
3
+ "version": "1.1.51",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -70,12 +70,9 @@
70
70
  "lodash"
71
71
  ],
72
72
  "devDependencies": {
73
- "@sinclair/typebox": "^0.33.15",
74
- "@types/lodash": "^4.17.10",
73
+ "@sinclair/typebox": "^0.33.16",
75
74
  "@types/ws": "^8.5.12",
76
- "@wener/utils": "link:",
77
75
  "https-proxy-agent": "^7.0.5",
78
- "lodash": "^4.17.21",
79
76
  "node-fetch": "^3.3.2",
80
77
  "undici": "^6.20.0",
81
78
  "zod": "^3.23.8"
@@ -86,7 +83,7 @@
86
83
  },
87
84
  "sideEffects": false,
88
85
  "scripts": {
89
- "build": "make prepublish",
86
+ "build": "make build",
90
87
  "clean": "make clean",
91
88
  "dev": "make dev",
92
89
  "test": "make test"
@@ -1,5 +1,5 @@
1
1
  import { createLazyPromise, type LazyPromise } from './createLazyPromise';
2
- import { type MaybePromise } from './MaybePromise';
2
+ import type { MaybePromise } from './MaybePromise';
3
3
 
4
4
  type Val<T> = [val: MaybePromise<T> | undefined, done: boolean, err?: any];
5
5
 
@@ -39,12 +39,12 @@ const DivisionCodeLevels = [
39
39
  *
40
40
  * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码
41
41
  */
42
- export class DivisionCodeFormat {
43
- static levels = DivisionCodeLevels;
42
+ export namespace DivisionCode {
43
+ export const levels = DivisionCodeLevels;
44
44
 
45
- regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
45
+ export const regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
46
46
 
47
- provinces: Array<[number, string]> = [
47
+ const provinces: Array<[number, string]> = [
48
48
  [11, '北京市'],
49
49
  [12, '天津市'],
50
50
  [13, '河北省'],
@@ -82,9 +82,16 @@ export class DivisionCodeFormat {
82
82
  // 9 国外
83
83
  ];
84
84
 
85
- parse(code: string) {
85
+ export type ParsedCode = {
86
+ province: string;
87
+ city?: string;
88
+ county?: string;
89
+ town?: string;
90
+ village?: string;
91
+ };
92
+
93
+ export function parse(code: string): ParsedCode | undefined {
86
94
  if (!code) return;
87
- const { regex } = this;
88
95
  const match = regex.exec(code);
89
96
  if (!match) return;
90
97
  const { province, city, county, town, village } = match.groups ?? {};
@@ -98,6 +105,15 @@ export class DivisionCodeFormat {
98
105
  village,
99
106
  };
100
107
  }
108
+
109
+ export function random(level: DivisionCodeLevel = 'County'): string {
110
+ const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];
111
+ const l1 = randomPick(provinces);
112
+ if (l.level === 1) {
113
+ return String(l1[0]);
114
+ }
115
+ return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));
116
+ }
101
117
  }
102
118
 
103
119
  interface DivisionTreeNode {
@@ -152,4 +168,6 @@ export interface CodeName {
152
168
  // return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');
153
169
  // }
154
170
 
155
- export const DivisionCode = new DivisionCodeFormat();
171
+ export function randomPick<T>(s: T[]) {
172
+ return s[Math.floor(Math.random() * s.length)];
173
+ }
@@ -1,6 +1,22 @@
1
- import { test } from 'vitest';
1
+ import { expect, test } from 'vitest';
2
2
  import { DivisionCode } from './DivisionCode';
3
3
 
4
4
  test('division', () => {
5
- console.log(DivisionCode.parse('441900003001'));
5
+ for (const [a, b] of [
6
+ [
7
+ '441900003001',
8
+ {
9
+ province: '44',
10
+ city: '19',
11
+ county: '00',
12
+ town: '003',
13
+ village: '001',
14
+ },
15
+ ],
16
+ ['31', { province: '31' }],
17
+ ['4', undefined],
18
+ ['', undefined],
19
+ ] as Array<[string, any]>) {
20
+ expect(DivisionCode.parse(a)).toMatchObject(b);
21
+ }
6
22
  });
@@ -1,5 +1,5 @@
1
1
  // import type * as NodeCrypto from 'node:crypto';
2
- import { getGlobalThis } from '../runtime/getGlobalThis';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
3
3
 
4
4
  let nodeCrypto;
5
5
  // globalThis.process?.release?.name
@@ -2,10 +2,10 @@ import { assert, beforeAll, expect, test } from 'vitest';
2
2
  import { ArrayBuffers } from '../io/ArrayBuffers';
3
3
  import { polyfillCrypto } from '../server/polyfill/polyfillCrypto';
4
4
  import { isUUID } from '../validations/isUUID';
5
+ import { _randomUUID } from '../web/randomUUID';
5
6
  import { hex } from './base';
6
7
  import { hmac, sha1, sha256, sha384, sha512 } from './hashing';
7
8
  import { md5 } from './md5';
8
- import { _randomUUID } from './randomUUID';
9
9
 
10
10
  beforeAll(async () => {
11
11
  await polyfillCrypto();
@@ -1,5 +1,5 @@
1
1
  import { expect, test } from 'vitest';
2
- import { randomUUID } from './randomUUID';
2
+ import { randomUUID } from '../web/randomUUID';
3
3
  import { createULID, isULID, parseULID, ulid } from './ulid';
4
4
 
5
5
  test('isULID', () => {
@@ -1,4 +1,4 @@
1
- import { getRandomValues } from './getRandomValues';
1
+ import { getRandomValues } from '../web/getRandomValues';
2
2
 
3
3
  type PRNG = () => number;
4
4
 
@@ -1,6 +1,6 @@
1
1
  import type { MaybePromise } from '../asyncs/MaybePromise';
2
- import { getGlobalThis } from '../runtime/getGlobalThis';
3
- import { type FetchLike } from './types';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
3
+ import type { FetchLike } from './types';
4
4
 
5
5
  export function createFetchWith({
6
6
  fetch = getGlobalThis().fetch,
@@ -1,7 +1,7 @@
1
1
  import { createFetchWith } from './createFetchWith';
2
2
  import { dumpRequest } from './dumpRequest';
3
3
  import { dumpResponse } from './dumpResponse';
4
- import { type FetchLike } from './types';
4
+ import type { FetchLike } from './types';
5
5
 
6
6
  export function createFetchWithLogging({
7
7
  fetch,
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis';
1
+ import { getGlobalThis } from '../web/getGlobalThis';
2
2
  import type { FetchLike } from './types';
3
3
 
4
4
  type RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export { isClass } from './langs/isClass';
42
42
  export { isDefined } from './langs/isDefined';
43
43
  export { isEmptyObject } from './langs/isEmptyObject';
44
44
  export { isPlainObject } from './langs/isPlainObject';
45
+ export { ifPresent } from './langs/ifPresent';
45
46
  export { parseBoolean } from './langs/parseBoolean';
46
47
  export { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';
47
48
  export { memoize } from './langs/memoize';
@@ -50,8 +51,8 @@ export type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mix
50
51
  export { getObjectId } from './langs/getObjectId';
51
52
  export { getGlobalStates, setGlobalStates } from './langs/getGlobalStates';
52
53
 
53
- export { AsyncCloser } from './runtime/AsyncCloser';
54
- export { Closer } from './runtime/Closer';
54
+ export { AsyncCloser } from './langs/AsyncCloser';
55
+ export { Closer } from './langs/Closer';
55
56
 
56
57
  export { isUUID } from './validations/isUUID';
57
58
  export { parseTimestamp } from './validations/parseTimestamp';
@@ -89,14 +90,14 @@ export { copy } from './browsers/copy';
89
90
  export { download } from './browsers/download';
90
91
  export { loadScripts, loadStyles } from './browsers/loaders';
91
92
  export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
92
-
93
- // polyfills
94
- export { getGlobalThis } from './runtime/getGlobalThis';
95
- export { structuredClone } from './runtime/structuredClone';
93
+ // web & spec
94
+ export { requestIdleCallback, cancelIdleCallback } from './web/requestIdleCallback';
95
+ export { randomUUID } from './web/randomUUID';
96
+ export { getRandomValues } from './web/getRandomValues';
97
+ export { getGlobalThis } from './web/getGlobalThis';
98
+ export { structuredClone } from './web/structuredClone';
96
99
 
97
100
  // crypto
98
- export { randomUUID } from './crypto/randomUUID';
99
- export { getRandomValues } from './crypto/getRandomValues';
100
101
  export { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';
101
102
  export { md5 } from './crypto/md5';
102
103
  export { hex } from './crypto/base';
@@ -1,5 +1,5 @@
1
1
  import { classOf } from '../langs/classOf';
2
- import { getGlobalThis } from '../runtime/getGlobalThis';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
3
3
  import { decodeBase64ToUint8Array, encodeArrayBufferToBase64 } from './base64';
4
4
  import { isBuffer } from './isBuffer';
5
5
 
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis';
1
+ import { getGlobalThis } from '../web/getGlobalThis';
2
2
 
3
3
  const globalThis = getGlobalThis();
4
4
 
@@ -1,9 +1,19 @@
1
- import { computeIfAbsent, getGlobalThis } from '@wener/utils';
1
+ import { computeIfAbsent } from '../objects/computeIfAbsent';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
2
3
 
3
4
  let _holder: any;
4
5
 
5
- export function setGlobalStates(states: Record<string, any>) {
6
- _holder = states;
6
+ export function setGlobalStates(states: Record<string, any>): Record<string, any>;
7
+ export function setGlobalStates<V = any>(key: string, value: V): V | undefined;
8
+ export function setGlobalStates(a: any, b?: any) {
9
+ if (typeof a === 'string') {
10
+ let s = getGlobalStates();
11
+ const last = s[a];
12
+ s[a] = b;
13
+ return last;
14
+ } else if (typeof a === 'object') {
15
+ _holder = a;
16
+ }
7
17
  }
8
18
 
9
19
  export function getGlobalStates(): Record<string, any>;
@@ -0,0 +1,3 @@
1
+ export function ifPresent<T, R>(value: T, fn: (v: T) => R): R | undefined {
2
+ return value ? fn(value) : undefined;
3
+ }
@@ -1,7 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { Errors, formatBytes, type MaybePromise } from '@wener/utils';
3
+ import type { MaybePromise } from '../asyncs/MaybePromise';
4
+ import { Errors } from '../errors/Errors';
4
5
  import { getPackageDir } from '../server';
6
+ import { formatBytes } from '../strings/formatBytes';
5
7
 
6
8
  let _root: GenerateContext;
7
9
 
@@ -1,5 +1,5 @@
1
- import { type FetchLike } from '../../fetch';
2
- import { getGlobalThis } from '../../runtime/getGlobalThis';
1
+ import type { FetchLike } from '../../fetch';
2
+ import { getGlobalThis } from '../../web/getGlobalThis';
3
3
 
4
4
  export function createFetchWithProxyByNodeFetch({
5
5
  proxy,
@@ -1,6 +1,6 @@
1
1
  import type { MaybePromise } from '../../asyncs/MaybePromise';
2
2
  import { createFetchWith, type FetchLike } from '../../fetch';
3
- import { getGlobalThis } from '../../runtime/getGlobalThis';
3
+ import { getGlobalThis } from '../../web/getGlobalThis';
4
4
 
5
5
  export function createFetchWithProxyByUndici({
6
6
  proxy,
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis';
1
+ import { getGlobalThis } from '../../web/getGlobalThis';
2
2
 
3
3
  export async function polyfillCrypto() {
4
4
  const globalThis = getGlobalThis();
@@ -1,5 +1,5 @@
1
1
  import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
2
- import { getGlobalThis } from '../../runtime/getGlobalThis';
2
+ import { getGlobalThis } from '../../web/getGlobalThis';
3
3
 
4
4
  export async function polyfillJsDom() {
5
5
  if (typeof window !== 'undefined') {
@@ -1,5 +1,5 @@
1
1
  import type { MaybePromise } from '../../asyncs/MaybePromise';
2
- import { getGlobalThis } from '../../runtime/getGlobalThis';
2
+ import { getGlobalThis } from '../../web/getGlobalThis';
3
3
 
4
4
  export function polyfillWebSocket(ws: any): boolean;
5
5
  export function polyfillWebSocket(ws?: undefined): Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import { expect, test } from 'vitest';
2
- import { randomUUID } from '../crypto/randomUUID';
2
+ import { randomUUID } from '../web/randomUUID';
3
3
  import { isUUID } from './isUUID';
4
4
 
5
5
  test('isUUID', () => {
@@ -1,7 +1,7 @@
1
1
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
2
+ import { getNodeCrypto } from '../crypto/getNodeCrypto';
2
3
  import type { TypedArray } from '../io/ArrayBuffers';
3
- import { getGlobalThis } from '../runtime/getGlobalThis';
4
- import { getNodeCrypto } from './getNodeCrypto';
4
+ import { getGlobalThis } from './getGlobalThis';
5
5
 
6
6
  const globalThis = getGlobalThis();
7
7
 
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis';
1
+ import { getGlobalThis } from './getGlobalThis';
2
2
 
3
3
  const globalThis = getGlobalThis();
4
4
 
@@ -0,0 +1,14 @@
1
+ // for safari
2
+ export const requestIdleCallback =
3
+ globalThis.requestIdleCallback ||
4
+ ((callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => {
5
+ const start = Date.now();
6
+ const deadline: IdleDeadline = {
7
+ didTimeout: false,
8
+ timeRemaining: () => Math.max(0, 50 - (Date.now() - start)),
9
+ };
10
+ // skip options?.timeout
11
+ return setTimeout(() => callback(deadline), 1);
12
+ });
13
+
14
+ export const cancelIdleCallback = globalThis.cancelIdleCallback || ((id: number) => clearTimeout(id));