Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fix internalBinding type definitions #47373

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ const experimentalModuleList = new SafeSet();
};
}

// Set up internalBinding() in the closure.
/**
* Set up internalBinding() in the closure.
* @type {InternalBinding}
*/
let internalBinding;
Expand Down Expand Up @@ -439,3 +439,4 @@ setInternalLoaders(internalBinding, requireBuiltin);

// Setup per-realm bindings.
setupPrepareStackTrace();
setInternalLoaders(internalBinding, requireBuiltin);
18 changes: 2 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@
"include": ["lib", "doc"],
"exclude": ["src", "tools", "out"],
"files": [
"./typings/internalBinding/async_wrap.d.ts",
"./typings/internalBinding/blob.d.ts",
"./typings/internalBinding/config.d.ts",
"./typings/internalBinding/constants.d.ts",
"./typings/internalBinding/fs.d.ts",
"./typings/internalBinding/http_parser.d.ts",
"./typings/internalBinding/messaging.d.ts",
"./typings/internalBinding/options.d.ts",
"./typings/internalBinding/os.d.ts",
"./typings/internalBinding/serdes.d.ts",
"./typings/internalBinding/symbols.d.ts",
"./typings/internalBinding/timers.d.ts",
"./typings/internalBinding/types.d.ts",
"./typings/internalBinding/url.d.ts",
"./typings/internalBinding/util.d.ts",
"./typings/internalBinding/worker.d.ts",
"./typings/internalBinding/*.d.ts",
"./typings/bindings.d.ts",
"./typings/globals.d.ts",
"./typings/primordials.d.ts"
],
Expand Down
37 changes: 37 additions & 0 deletions typings/bindings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { AsyncWrapBinding } from './internalBinding/async_wrap';
import type { BlobBinding } from "./internalBinding/blob";
import type { ConfigBinding } from "./internalBinding/config";
import type { ConstantsBinding } from "./internalBinding/constants";
import type { FSBinding } from "./internalBinding/fs";
import type { HttpParserBinding } from "./internalBinding/http_parser";
import type { MessagingBinding } from "./internalBinding/messaging";
import type { OptionsBinding } from "./internalBinding/options";
import type { OSBinding } from "./internalBinding/os";
import type { SerdesBinding } from "./internalBinding/serdes";
import type { SymbolsBinding } from "./internalBinding/symbols";
import type { TimersBinding } from "./internalBinding/timers";
import type { TypesBinding } from "./internalBinding/types";
import type { URLBinding } from "./internalBinding/url";
import type { UtilBindings } from "./internalBinding/util";
import type { WorkerBinding } from "./internalBinding/worker";

export type InternalBindingMap = {
async_wrap: AsyncWrapBinding;
blob: BlobBinding;
config: ConfigBinding;
constants: ConstantsBinding;
fs: FSBinding;
http_parser: HttpParserBinding;
messaging: MessagingBinding;
options: OptionsBinding;
os: OSBinding;
serdes: SerdesBinding;
symbols: SymbolsBinding;
timers: TimersBinding;
types: TypesBinding;
url: URLBinding;
util: UtilBindings;
worker: WorkerBinding;
}

export type InternalBinding<T extends keyof InternalBindingMap> = (binding: T) => InternalBindingMap[T];
4 changes: 2 additions & 2 deletions typings/internalBinding/async_wrap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ declare namespace InternalAsyncWrapBinding {
}
}

declare function InternalBinding(binding: 'async_wrap'): {
export type AsyncWrapBinding = {
setupHooks(): {
init: (
asyncId: number,
Expand Down Expand Up @@ -129,4 +129,4 @@ declare function InternalBinding(binding: 'async_wrap'): {
kDefaultTriggerAsyncId: 3;
};
Providers: InternalAsyncWrapBinding.Providers;
};
}
2 changes: 1 addition & 1 deletion typings/internalBinding/blob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare namespace InternalBlobBinding {
}
}

declare function InternalBinding(binding: 'blob'): {
export type BlobBinding = {
createBlob(sources: Array<Uint8Array | InternalBlobBinding.BlobHandle>, length: number): InternalBlobBinding.BlobHandle;
FixedSizeBlobCopyJob: typeof InternalBlobBinding.FixedSizeBlobCopyJob;
getDataObject(id: string): [handle: InternalBlobBinding.BlobHandle | undefined, length: number, type: string] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function InternalBinding(binding: 'config'): {
export type ConfigBinding = {
isDebugBuild: boolean;
hasOpenSSL: boolean;
fipsMode: boolean;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function InternalBinding(binding: 'constants'): {
export type ConstantsBinding = {
os: {
UV_UDP_REUSEADDR: 4;
dlopen: {
Expand Down
6 changes: 3 additions & 3 deletions typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ declare namespace InternalFSBinding {

function internalModuleReadJSON(path: string): [] | [string, boolean];
function internalModuleStat(path: string): number;

function lchown(path: string, uid: number, gid: number, req: FSReqCallback): void;
function lchown(path: string, uid: number, gid: number, req: undefined, ctx: FSSyncContext): void;
function lchown(path: string, uid: number, gid: number, usePromises: typeof kUsePromises): Promise<void>;
Expand Down Expand Up @@ -198,7 +198,7 @@ declare namespace InternalFSBinding {
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, req: FSReqCallback): void;
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, req: undefined, ctx: FSSyncContext): void;
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, usePromises: typeof kUsePromises): Promise<void>;

function unlink(path: string, req: FSReqCallback): void;
function unlink(path: string, req: undefined, ctx: FSSyncContext): void;
function unlink(path: string, usePromises: typeof kUsePromises): Promise<void>;
Expand All @@ -220,7 +220,7 @@ declare namespace InternalFSBinding {
function writeString(fd: number, value: string, pos: unknown, encoding: unknown, usePromises: typeof kUsePromises): Promise<number>;
}

declare function InternalBinding(binding: 'fs'): {
export type FSBinding = {
FSReqCallback: typeof InternalFSBinding.FSReqCallback;

FileHandle: typeof InternalFSBinding.FileHandle;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/http_parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare namespace InternalHttpParserBinding {
}
}

declare function InternalBinding(binding: 'http_parser'): {
export type HttpParserBinding = {
methods: string[];
HTTPParser: typeof InternalHttpParserBinding.HTTPParser;
};
6 changes: 4 additions & 2 deletions typings/internalBinding/messaging.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DOMException } from 'internal/per_context/domexception';

declare namespace InternalMessagingBinding {
class MessageChannel {
port1: MessagePort;
Expand All @@ -17,8 +19,8 @@ declare namespace InternalMessagingBinding {
}


declare function InternalBinding(binding: 'messaging'): {
DOMException: typeof import('internal/per_context/domexception').DOMException;
export type MessagingBinding = {
DOMException: typeof DOMException;
MessageChannel: typeof InternalMessagingBinding.MessageChannel;
MessagePort: typeof InternalMessagingBinding.MessagePort;
JSTransferable: typeof InternalMessagingBinding.JSTransferable;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/options.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function InternalBinding(binding: 'options'): {
export type OptionsBinding = {
getOptions(): {
options: Map<
string,
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/os.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare namespace InternalOSBinding {
type OSContext = {};
}

declare function InternalBinding(binding: 'os'): {
export type OSBinding = {
getHostname(ctx: InternalOSBinding.OSContext): string | undefined;
getLoadAvg(array: Float64Array): void;
getUptime(): number;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/serdes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare namespace InternalSerdesBinding {
}
}

declare function InternalBinding(binding: 'serdes'): {
export type SerdesBinding = {
Serializer: typeof InternalSerdesBinding.Serializer;
Deserializer: typeof InternalSerdesBinding.Deserializer;
};
2 changes: 1 addition & 1 deletion typings/internalBinding/symbols.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const owner_symbol: unique symbol;
export const onpskexchange_symbol: unique symbol;
export const trigger_async_id_symbol: unique symbol;

declare function InternalBinding(binding: 'symbols'): {
export type SymbolsBinding = {
async_id_symbol: typeof async_id_symbol;
handle_onclose_symbol: typeof handle_onclose_symbol;
no_message_symbol: typeof no_message_symbol;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/timers.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function InternalBinding(binding: 'timers'): {
export type TimersBinding = {
getLibuvNow(): number;
setupTimers(immediateCallback: () => void, timersCallback: (now: number) => void): void;
scheduleTimer(msecs: number): void;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function InternalBinding(binding: 'types'): {
export type TypesBinding = {
isAsyncFunction(value: unknown): value is (...args: unknown[]) => Promise<unknown>;
isGeneratorFunction(value: unknown): value is GeneratorFunction;
isAnyArrayBuffer(value: unknown): value is (ArrayBuffer | SharedArrayBuffer);
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/url.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { urlUpdateActions } from 'internal/url'

declare function InternalBinding(binding: 'url'): {
export type URLBinding = {
urlComponents: Uint32Array;

domainToASCII(input: string): string;
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare namespace InternalUtilBinding {
}
}

declare function InternalBinding(binding: 'util'): {
export type UtilBindings = {
// PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES, defined in src/env_properties.h
arrow_message_private_symbol: 1;
contextify_context_private_symbol: 2;
Expand Down
4 changes: 3 additions & 1 deletion typings/internalBinding/worker.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { InternalMessagingBinding } from "./messaging";

declare namespace InternalWorkerBinding {
class Worker {
constructor(
Expand All @@ -18,7 +20,7 @@ declare namespace InternalWorkerBinding {
}
}

declare function InternalBinding(binding: 'worker'): {
export type WorkerBinding = {
Worker: typeof InternalWorkerBinding.Worker;
getEnvMessagePort(): InternalMessagingBinding.MessagePort;
threadId: number;
Expand Down
2 changes: 2 additions & 0 deletions typings/primordials.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { TypedArray } from './globals';

type UncurryThis<T extends (this: unknown, ...args: unknown[]) => unknown> =
(self: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
type UncurryThisStaticApply<T extends (this: unknown, ...args: unknown[]) => unknown> =
Expand Down