File
Blob: src/node/async_hooks.ts
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | // |
| 5 | |
| 6 | import { default as async_hooks } from 'node-internal:async_hooks'; |
| 7 | |
| 8 | class AsyncHook { |
| 9 | enable(): this { |
| 10 | return this; |
| 11 | } |
| 12 | |
| 13 | disable(): this { |
| 14 | return this; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | export const { AsyncLocalStorage, AsyncResource } = async_hooks; |
| 19 | |
| 20 | // Async wrap provider type constants matching Node.js's ProviderType enum in |
| 21 | // async_wrap.h. While we don't use most of these internally, they are exported |
| 22 | // for compatibility with code that references them. |
| 23 | export const asyncWrapProviders: Record<string, number> = { |
| 24 | NONE: 0, |
| 25 | DIRHANDLE: 0, |
| 26 | DNSCHANNEL: 0, |
| 27 | ELDHISTOGRAM: 0, |
| 28 | FILEHANDLE: 0, |
| 29 | FILEHANDLECLOSEREQ: 0, |
| 30 | BLOBREADER: 0, |
| 31 | FSEVENTWRAP: 0, |
| 32 | FSREQCALLBACK: 0, |
| 33 | FSREQPROMISE: 0, |
| 34 | GETADDRINFOREQWRAP: 0, |
| 35 | GETNAMEINFOREQWRAP: 0, |
| 36 | HEAPSNAPSHOT: 0, |
| 37 | HTTP2SESSION: 0, |
| 38 | HTTP2STREAM: 0, |
| 39 | HTTP2PING: 0, |
| 40 | HTTP2SETTINGS: 0, |
| 41 | HTTPINCOMINGMESSAGE: 0, |
| 42 | HTTPCLIENTREQUEST: 0, |
| 43 | LOCKS: 0, |
| 44 | JSSTREAM: 0, |
| 45 | JSUDPWRAP: 0, |
| 46 | MESSAGEPORT: 0, |
| 47 | PIPECONNECTWRAP: 0, |
| 48 | PIPESERVERWRAP: 0, |
| 49 | PIPEWRAP: 0, |
| 50 | PROCESSWRAP: 0, |
| 51 | PROMISE: 0, |
| 52 | QUERYWRAP: 0, |
| 53 | QUIC_ENDPOINT: 0, |
| 54 | QUIC_LOGSTREAM: 0, |
| 55 | QUIC_SESSION: 0, |
| 56 | QUIC_STREAM: 0, |
| 57 | QUIC_UDP: 0, |
| 58 | SHUTDOWNWRAP: 0, |
| 59 | SIGNALWRAP: 0, |
| 60 | STATWATCHER: 0, |
| 61 | STREAMPIPE: 0, |
| 62 | TCPCONNECTWRAP: 0, |
| 63 | TCPSERVERWRAP: 0, |
| 64 | TCPWRAP: 0, |
| 65 | TTYWRAP: 0, |
| 66 | UDPSENDWRAP: 0, |
| 67 | UDPWRAP: 0, |
| 68 | SIGINTWATCHDOG: 0, |
| 69 | WORKER: 0, |
| 70 | WORKERCPUPROFILE: 0, |
| 71 | WORKERCPUUSAGE: 0, |
| 72 | WORKERHEAPPROFILE: 0, |
| 73 | WORKERHEAPSNAPSHOT: 0, |
| 74 | WORKERHEAPSTATISTICS: 0, |
| 75 | WRITEWRAP: 0, |
| 76 | ZLIB: 0, |
| 77 | CHECKPRIMEREQUEST: 0, |
| 78 | PBKDF2REQUEST: 0, |
| 79 | KEYPAIRGENREQUEST: 0, |
| 80 | KEYGENREQUEST: 0, |
| 81 | KEYEXPORTREQUEST: 0, |
| 82 | ARGON2REQUEST: 0, |
| 83 | CIPHERREQUEST: 0, |
| 84 | DERIVEBITSREQUEST: 0, |
| 85 | HASHREQUEST: 0, |
| 86 | RANDOMBYTESREQUEST: 0, |
| 87 | RANDOMPRIMEREQUEST: 0, |
| 88 | SCRYPTREQUEST: 0, |
| 89 | SIGNREQUEST: 0, |
| 90 | TLSWRAP: 0, |
| 91 | VERIFYREQUEST: 0, |
| 92 | QUIC_PACKET: 0, |
| 93 | }; |
| 94 | |
| 95 | export function createHook(): AsyncHook { |
| 96 | // Even though we don't implement this function, we return a default value |
| 97 | // in order to preserve backward compatibility and avoid breaking changes |
| 98 | // with unenv polyfills. |
| 99 | return new AsyncHook(); |
| 100 | } |
| 101 | |
| 102 | export function executionAsyncId(): number { |
| 103 | // Even though we don't implement this function, we return a default value |
| 104 | // in order to preserve backward compatibility and avoid breaking changes |
| 105 | // with unenv polyfills. |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | export function executionAsyncResource(): Record<string, string> { |
| 110 | // Even though we don't implement this function, we return a default value |
| 111 | // in order to preserve backward compatibility and avoid breaking changes |
| 112 | // with unenv polyfills. |
| 113 | // eslint-disable-next-line @typescript-eslint/no-unsafe-return |
| 114 | return Object.create(null); |
| 115 | } |
| 116 | |
| 117 | export function triggerAsyncId(): number { |
| 118 | // Even though we don't implement this function, we return a default value |
| 119 | // in order to preserve backward compatibility and avoid breaking changes |
| 120 | // with unenv polyfills. |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | export default { |
| 125 | AsyncLocalStorage, |
| 126 | AsyncResource, |
| 127 | asyncWrapProviders, |
| 128 | createHook, |
| 129 | executionAsyncId, |
| 130 | executionAsyncResource, |
| 131 | triggerAsyncId, |
| 132 | }; |