mirror of
https://github.com/ChainSafe/lodestar.git
synced 2026-01-07 23:04:06 -05:00
chore: use latest TS module resolution (#8419)
**Motivation** Use latest `module` and `moduleResolution` for TS. **Description** - To use [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) in the PR #8320 we need to update the module solution strategy for TS. - That requires to change the `module` for the TS as well. - Earlier tried to stay with `node18` or `node20`, but the `ts-node` does not work with that. - Maintaining different tsconfig for ts-node is more of hassle on wrong run. - So decided to stick with `nodenext` strategy for `moduleResolution` **Steps to test or reproduce** Run all tests --------- Co-authored-by: Cayman <caymannava@gmail.com>
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
"supertest": "^6.3.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.9.2",
|
||||
"typescript-docs-verifier": "^2.5.3",
|
||||
"typescript-docs-verifier": "^3.0.1",
|
||||
"vite": "^6.0.11",
|
||||
"vite-plugin-dts": "^4.5.0",
|
||||
"vite-plugin-node-polyfills": "^0.23.0",
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import Ajv, {ErrorObject} from "ajv";
|
||||
import ajvPkg, {ErrorObject} from "ajv";
|
||||
import {beforeAll, describe, expect, it} from "vitest";
|
||||
import {Endpoint, RequestWithBodyCodec, RouteDefinitions, isRequestWithoutBody} from "../../src/utils/types.js";
|
||||
import {WireFormat} from "../../src/utils/wireFormat.js";
|
||||
import {GenericServerTestCases} from "./genericServerTest.js";
|
||||
import {JsonSchema, OpenApiJson, applyRecursively, parseOpenApiSpec} from "./parseOpenApiSpec.js";
|
||||
|
||||
// Current Ajv package is a commonjs package which cause problem
|
||||
// when we have moduleResolution set to node16
|
||||
// This syntax works and tested with Node and Bun both
|
||||
const Ajv = ajvPkg.default;
|
||||
|
||||
const ajv = new Ajv({
|
||||
strict: true,
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
"@chainsafe/prometheus-gc-stats": "^1.0.0",
|
||||
"@chainsafe/pubkey-index-map": "^3.0.0",
|
||||
"@chainsafe/ssz": "^1.2.2",
|
||||
"@chainsafe/threads": "^1.11.2",
|
||||
"@chainsafe/threads": "^1.11.3",
|
||||
"@crate-crypto/node-eth-kzg": "0.8.0",
|
||||
"@ethersproject/abi": "^5.7.0",
|
||||
"@fastify/bearer-auth": "^10.0.1",
|
||||
|
||||
@@ -6,7 +6,8 @@ export async function registerSwaggerUIRoutes(
|
||||
opts: BeaconRestApiServerOpts,
|
||||
version = ""
|
||||
): Promise<void> {
|
||||
await server.register(await import("@fastify/swagger"), {
|
||||
const {fastifySwagger} = await import("@fastify/swagger");
|
||||
await server.register(fastifySwagger, {
|
||||
openapi: {
|
||||
info: {
|
||||
title: "Lodestar API",
|
||||
@@ -24,7 +25,8 @@ export async function registerSwaggerUIRoutes(
|
||||
tags: opts.api.map((namespace) => ({name: namespace})),
|
||||
},
|
||||
});
|
||||
await server.register(await import("@fastify/swagger-ui"), {
|
||||
const {fastifySwaggerUi} = await import("@fastify/swagger-ui");
|
||||
await server.register(fastifySwaggerUi, {
|
||||
theme: {
|
||||
title: "Lodestar API",
|
||||
favicon: await getFavicon(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.js";
|
||||
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score";
|
||||
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
|
||||
import {Connection, PrivateKey} from "@libp2p/interface";
|
||||
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from "node:path";
|
||||
import workerThreads from "node:worker_threads";
|
||||
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.js";
|
||||
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score";
|
||||
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
|
||||
import {ModuleThread, Thread, Worker, spawn} from "@chainsafe/threads";
|
||||
import {privateKeyToProtobuf} from "@libp2p/crypto/keys";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import worker from "node:worker_threads";
|
||||
import {Discv5} from "@chainsafe/discv5";
|
||||
import {Discv5, Discv5EventEmitter} from "@chainsafe/discv5";
|
||||
import {ENR, ENRData, SignableENR, SignableENRData} from "@chainsafe/enr";
|
||||
import {Observable, Subject} from "@chainsafe/threads/observable";
|
||||
import {expose} from "@chainsafe/threads/worker";
|
||||
@@ -59,7 +59,7 @@ const discv5 = Discv5.create({
|
||||
},
|
||||
config: workerData.config,
|
||||
metricsRegistry,
|
||||
});
|
||||
}) as Discv5 & Discv5EventEmitter;
|
||||
|
||||
// Load boot enrs
|
||||
for (const bootEnr of workerData.bootEnrs) {
|
||||
@@ -93,13 +93,13 @@ const module: Discv5WorkerApi = {
|
||||
discv5.enr.set(key, value);
|
||||
},
|
||||
async kadValues(): Promise<ENRData[]> {
|
||||
return discv5.kadValues().map((enr) => enr.toObject());
|
||||
return discv5.kadValues().map((enr: ENR) => enr.toObject());
|
||||
},
|
||||
async discoverKadValues(): Promise<void> {
|
||||
discv5.kadValues().map(onDiscovered);
|
||||
},
|
||||
async findRandomNode(): Promise<ENRData[]> {
|
||||
return (await discv5.findRandomNode()).map((enr) => enr.toObject());
|
||||
return (await discv5.findRandomNode()).map((enr: ENR) => enr.toObject());
|
||||
},
|
||||
discovered() {
|
||||
return Observable.from(subject);
|
||||
|
||||
@@ -4,7 +4,6 @@ import {ChainConfig} from "@lodestar/config";
|
||||
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
||||
import {BLSPubkey, Epoch, Slot, phase0, ssz} from "@lodestar/types";
|
||||
import {Validator} from "@lodestar/validator";
|
||||
import {PubkeyHex} from "@lodestar/validator/src/types";
|
||||
import {afterEach, describe, expect, it} from "vitest";
|
||||
import {BeaconNode} from "../../../src/node/index.js";
|
||||
import {ClockEvent} from "../../../src/util/clock.js";
|
||||
@@ -14,6 +13,8 @@ import {connect} from "../../utils/network.js";
|
||||
import {getDevBeaconNode} from "../../utils/node/beacon.js";
|
||||
import {getAndInitDevValidators} from "../../utils/node/validator.js";
|
||||
|
||||
type PubkeyHex = string;
|
||||
|
||||
// TODO: Reconsider this tests latter.
|
||||
// Doppelganger testing can be split in two items:
|
||||
// 1. Can a running beacon node detect liveness of the validator?
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {fromHexString} from "@chainsafe/ssz";
|
||||
import {routes} from "@lodestar/api";
|
||||
import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js";
|
||||
import {ChainConfig} from "@lodestar/config";
|
||||
import {TimestampFormatCode} from "@lodestar/logger";
|
||||
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
||||
@@ -99,7 +98,7 @@ describe("sync / finalized sync for fulu", () => {
|
||||
240000,
|
||||
(finalized) => finalized.epoch >= FULU_FORK_EPOCH
|
||||
),
|
||||
waitForEvent<EventData[EventType.head]>(
|
||||
waitForEvent<routes.events.EventData[routes.events.EventType.head]>(
|
||||
bn.chain.emitter,
|
||||
routes.events.EventType.head,
|
||||
100000,
|
||||
@@ -128,7 +127,7 @@ describe("sync / finalized sync for fulu", () => {
|
||||
const headSummary = bn.chain.forkChoice.getHead();
|
||||
const head = await bn.db.block.get(fromHexString(headSummary.blockRoot));
|
||||
if (!head) throw Error("First beacon node has no head block");
|
||||
const waitForSynced = waitForEvent<EventData[EventType.head]>(
|
||||
const waitForSynced = waitForEvent<routes.events.EventData[routes.events.EventType.head]>(
|
||||
bn2.chain.emitter,
|
||||
routes.events.EventType.head,
|
||||
100000,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {fromHexString} from "@chainsafe/ssz";
|
||||
import {routes} from "@lodestar/api";
|
||||
import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js";
|
||||
import {ChainConfig} from "@lodestar/config";
|
||||
import {TimestampFormatCode} from "@lodestar/logger";
|
||||
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
||||
@@ -107,7 +106,7 @@ describe("sync / unknown block sync for fulu", () => {
|
||||
afterEachCallbacks.push(() => bn.close().catch(() => {}));
|
||||
|
||||
// wait until the 2nd slot of fulu
|
||||
await waitForEvent<EventData[EventType.head]>(
|
||||
await waitForEvent<routes.events.EventData[routes.events.EventType.head]>(
|
||||
bn.chain.emitter,
|
||||
routes.events.EventType.head,
|
||||
240000,
|
||||
@@ -133,7 +132,7 @@ describe("sync / unknown block sync for fulu", () => {
|
||||
const headSummary = bn.chain.forkChoice.getHead();
|
||||
const head = await bn.db.block.get(fromHexString(headSummary.blockRoot));
|
||||
if (!head) throw Error("First beacon node has no head block");
|
||||
const waitForSynced = waitForEvent<EventData[EventType.head]>(
|
||||
const waitForSynced = waitForEvent<routes.events.EventData[routes.events.EventType.head]>(
|
||||
bn2.chain.emitter,
|
||||
routes.events.EventType.head,
|
||||
100000,
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import {ChainForkConfig} from "@lodestar/config";
|
||||
import {ForkChoice, ForkChoiceOpts, IForkChoiceStore, ProtoArray, ProtoBlock, ProtoNode} from "@lodestar/fork-choice";
|
||||
import {NotReorgedReason} from "@lodestar/fork-choice/lib/forkChoice/interface.js";
|
||||
import {
|
||||
ForkChoice,
|
||||
ForkChoiceOpts,
|
||||
IForkChoiceStore,
|
||||
ProtoArray,
|
||||
ProtoBlock,
|
||||
ProtoNode,
|
||||
NotReorgedReason,
|
||||
} from "@lodestar/fork-choice";
|
||||
import {Slot} from "@lodestar/types";
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
SLOTS_PER_EPOCH,
|
||||
} from "@lodestar/params";
|
||||
import {CachedBeaconStateAllForks, CachedBeaconStateElectra, newFilledArray} from "@lodestar/state-transition";
|
||||
import {CachedBeaconStateAltair} from "@lodestar/state-transition/src/types.js";
|
||||
import {CachedBeaconStateAltair} from "@lodestar/state-transition";
|
||||
import {Attestation, electra, phase0, ssz} from "@lodestar/types";
|
||||
import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest";
|
||||
import {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"@chainsafe/enr": "^5.0.1",
|
||||
"@chainsafe/persistent-merkle-tree": "^1.2.1",
|
||||
"@chainsafe/ssz": "^1.2.2",
|
||||
"@chainsafe/threads": "^1.11.2",
|
||||
"@chainsafe/threads": "^1.11.3",
|
||||
"@libp2p/crypto": "^5.0.15",
|
||||
"@libp2p/interface": "^2.7.0",
|
||||
"@libp2p/peer-id": "^5.1.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {registerCommandToYargs} from "@lodestar/utils";
|
||||
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
|
||||
import yargs from "yargs";
|
||||
import yargs, {Argv} from "yargs";
|
||||
import {hideBin} from "yargs/helpers";
|
||||
import {cmds} from "./cmds/index.js";
|
||||
import {globalOptions, rcConfigOption} from "./options/index.js";
|
||||
@@ -22,7 +22,7 @@ export const yarg = yargs((hideBin as (args: string[]) => string[])(process.argv
|
||||
* Common factory for running the CLI and running integration tests
|
||||
* The CLI must actually be executed in a different script
|
||||
*/
|
||||
export function getLodestarCli(): yargs.Argv {
|
||||
export function getLodestarCli(): Argv {
|
||||
const lodestar = yarg
|
||||
.env("LODESTAR")
|
||||
.parserConfiguration({
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import path from "node:path";
|
||||
import {Discv5} from "@chainsafe/discv5";
|
||||
import {ENR} from "@chainsafe/enr";
|
||||
import {HttpMetricsServer, RegistryMetricCreator, getHttpMetricsServer} from "@lodestar/beacon-node";
|
||||
import {ErrorAborted} from "@lodestar/utils";
|
||||
import {Discv5, Discv5EventEmitter} from "@chainsafe/discv5";
|
||||
import {ENR, ENRData, SignableENR} from "@chainsafe/enr";
|
||||
import {
|
||||
HttpMetricsServer,
|
||||
IBeaconNodeOptions,
|
||||
RegistryMetricCreator,
|
||||
getHttpMetricsServer,
|
||||
} from "@lodestar/beacon-node";
|
||||
import {ErrorAborted, Logger} from "@lodestar/utils";
|
||||
import {Multiaddr, multiaddr} from "@multiformats/multiaddr";
|
||||
|
||||
import {getBeaconConfigFromArgs} from "../../config/index.js";
|
||||
@@ -17,6 +22,7 @@ import {initPrivateKeyAndEnr} from "../beacon/initPeerIdAndEnr.js";
|
||||
import {BeaconArgs} from "../beacon/options.js";
|
||||
import {getBeaconPaths} from "../beacon/paths.js";
|
||||
import {BootnodeArgs} from "./options.js";
|
||||
import {PrivateKey} from "@libp2p/interface";
|
||||
|
||||
/**
|
||||
* Runs a bootnode.
|
||||
@@ -60,7 +66,7 @@ export async function bootnodeHandler(args: BootnodeArgs & GlobalArgs): Promise<
|
||||
},
|
||||
config: {enrUpdate: !enr.ip && !enr.ip6},
|
||||
metricsRegistry,
|
||||
});
|
||||
}) as Discv5 & Discv5EventEmitter;
|
||||
|
||||
// If there are any bootnodes, add them to the routing table
|
||||
for (const bootEnrStr of Array.from(new Set(discv5Args.bootEnrs).values())) {
|
||||
@@ -82,7 +88,7 @@ export async function bootnodeHandler(args: BootnodeArgs & GlobalArgs): Promise<
|
||||
void discv5.findRandomNode();
|
||||
}
|
||||
|
||||
discv5.on("multiaddrUpdated", (addr) => {
|
||||
discv5.on("multiaddrUpdated", (addr: ENRData) => {
|
||||
logger.info("Advertised socket address updated", {addr: addr.toString()});
|
||||
});
|
||||
|
||||
@@ -155,8 +161,20 @@ export async function bootnodeHandler(args: BootnodeArgs & GlobalArgs): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
export type BootNodeInitOptions = {
|
||||
discv5Args: Exclude<IBeaconNodeOptions["network"]["discv5"], null>;
|
||||
metricsArgs: IBeaconNodeOptions["metrics"];
|
||||
bootnodeDir: string;
|
||||
network: string;
|
||||
version: string;
|
||||
commit: string;
|
||||
privateKey: PrivateKey;
|
||||
enr: SignableENR;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
/** Separate function to simplify unit testing of options merging */
|
||||
export async function bootnodeHandlerInit(args: BootnodeArgs & GlobalArgs) {
|
||||
export async function bootnodeHandlerInit(args: BootnodeArgs & GlobalArgs): Promise<BootNodeInitOptions> {
|
||||
const {config, network} = getBeaconConfigFromArgs(args);
|
||||
const {version, commit} = getVersionData();
|
||||
const beaconPaths = getBeaconPaths(args, network);
|
||||
|
||||
@@ -11,5 +11,5 @@ export function removeUndefinedRecursive<T extends {[key: string]: any}>(obj: T)
|
||||
if (value && typeof value === "object") removeUndefinedRecursive(value);
|
||||
else if (value === undefined) delete obj[key];
|
||||
}
|
||||
return obj;
|
||||
return obj as RecursivePartial<T>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {registerCommandToYargs} from "@lodestar/utils";
|
||||
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
|
||||
import yargs from "yargs";
|
||||
import yargs, {Argv} from "yargs";
|
||||
import {hideBin} from "yargs/helpers";
|
||||
import {cmds} from "./cmds/index.js";
|
||||
|
||||
@@ -21,7 +21,7 @@ export const yarg = yargs((hideBin as (args: string[]) => string[])(process.argv
|
||||
* Common factory for running the CLI and running integration tests
|
||||
* The CLI must actually be executed in a different script
|
||||
*/
|
||||
export function getCli(): yargs.Argv {
|
||||
export function getCli(): Argv {
|
||||
const lodestar = yarg
|
||||
.env("FLARE")
|
||||
.parserConfiguration({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {Emitter as MittEmitter} from "mitt";
|
||||
import {LightClientHeader} from "@lodestar/types";
|
||||
import {RunStatusCode} from "./index.js";
|
||||
|
||||
@@ -14,10 +15,3 @@ export type LightclientEmitterEvents = {
|
||||
};
|
||||
|
||||
export type LightclientEmitter = MittEmitter<LightclientEmitterEvents>;
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
|
||||
export type MittEmitter<T extends Record<string, (...args: any[]) => void>> = {
|
||||
on<K extends keyof T>(type: K, handler: T[K]): void;
|
||||
off<K extends keyof T>(type: K, handler: T[K]): void;
|
||||
emit<K extends keyof T>(type: K, ...args: Parameters<T[K]>): void;
|
||||
};
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
LightClientUpdate,
|
||||
type SyncPeriod,
|
||||
} from "@lodestar/types";
|
||||
import mitt from "mitt";
|
||||
import {MittEmitter} from "../events.js";
|
||||
import mitt, {Emitter as MittEmitter} from "mitt";
|
||||
import {type LightClientTransport} from "./interface.js";
|
||||
|
||||
export type LightClientRestEvents = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {getClient} from "@lodestar/api";
|
||||
import {config} from "@lodestar/config/default";
|
||||
import {NetworkName} from "@lodestar/config/networks.js";
|
||||
import {NetworkName} from "@lodestar/config/networks";
|
||||
|
||||
// To populate packages/light-client/src/networks.ts
|
||||
//
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
"winston-transport": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@chainsafe/threads": "^1.11.2",
|
||||
"@chainsafe/threads": "^1.11.3",
|
||||
"@lodestar/test-utils": "^1.34.1",
|
||||
"@types/triple-beam": "^1.3.2",
|
||||
"triple-beam": "^1.3.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {registerCommandToYargs} from "@lodestar/utils";
|
||||
// Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131
|
||||
import yargs from "yargs";
|
||||
import yargs, {Argv} from "yargs";
|
||||
import {hideBin} from "yargs/helpers";
|
||||
import {getVersionData} from "../utils/version.js";
|
||||
import {cmds, proverProxyStartCommand} from "./cmds/index.js";
|
||||
@@ -22,7 +22,7 @@ export const yarg = yargs((hideBin as (args: string[]) => string[])(process.argv
|
||||
* Common factory for running the CLI and running integration tests
|
||||
* The CLI must actually be executed in a different script
|
||||
*/
|
||||
export function getLodestarProverCli(): yargs.Argv {
|
||||
export function getLodestarProverCli(): Argv {
|
||||
const prover = yarg
|
||||
.env("LODESTAR")
|
||||
.parserConfiguration({
|
||||
|
||||
@@ -15,7 +15,7 @@ The beacon state transition and state transition utilities
|
||||
```typescript
|
||||
import {CachedBeaconStateAllForks, stateTransition} from "@lodestar/state-transition";
|
||||
import {ssz} from "@lodestar/types";
|
||||
import {generateState} from "../test/utils/state";
|
||||
import {generateState} from "./test/utils/state.js";
|
||||
|
||||
// dummy test state
|
||||
const preState: CachedBeaconStateAllForks = generateState() as CachedBeaconStateAllForks;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import {getClient} from "@lodestar/api";
|
||||
import {config} from "@lodestar/config/default";
|
||||
import {NetworkName} from "@lodestar/config/networks.js";
|
||||
import {NetworkName} from "@lodestar/config/networks";
|
||||
import {phase0, ssz} from "@lodestar/types";
|
||||
import {
|
||||
AttesterFlags,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {NetworkName} from "@lodestar/config/networks.js";
|
||||
import {NetworkName} from "@lodestar/config/networks";
|
||||
|
||||
export function getInfuraBeaconUrl(network: NetworkName): string {
|
||||
const INFURA_ETH2_CREDENTIALS = process.env.INFURA_ETH2_CREDENTIALS;
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
"./electra": {
|
||||
"import": "./lib/electra/index.js"
|
||||
},
|
||||
"./fulu": {
|
||||
"import": "./lib/fulu/index.js"
|
||||
},
|
||||
"./phase0": {
|
||||
"import": "./lib/phase0/index.js"
|
||||
}
|
||||
|
||||
@@ -10,3 +10,4 @@ export {StringType, stringType} from "./utils/stringType.js";
|
||||
// Container utils
|
||||
export * from "./utils/container.js";
|
||||
export * from "./utils/validatorStatus.js";
|
||||
export {ExecutionAddressType} from "./utils/executionAddress.js";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from "./types.js";
|
||||
export * from "./validator.js";
|
||||
import * as ssz from "./sszTypes.js";
|
||||
import * as ts from "./types.js";
|
||||
export {ts, ssz};
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
/**
|
||||
* Recursively make all properties optional
|
||||
* From https://stackoverflow.com/questions/45372227/how-to-implement-typescript-deep-partial-mapped-type-not-breaking-array-properti/49936686#49936686
|
||||
*/
|
||||
export type RecursivePartial<T> = {
|
||||
[P in keyof T]?: T[P] extends (infer U)[]
|
||||
? RecursivePartial<U>[]
|
||||
: T[P] extends Readonly<infer U>[]
|
||||
? Readonly<RecursivePartial<U>>[]
|
||||
: RecursivePartial<T[P]>;
|
||||
};
|
||||
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
||||
type Builtin = Primitive | Date | Error | RegExp;
|
||||
|
||||
export type RecursivePartial<T> =
|
||||
// stop on built-ins (incl. Error) and functions
|
||||
T extends Builtin
|
||||
? T
|
||||
: // arrays and readonly arrays
|
||||
T extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<RecursivePartial<U>>
|
||||
: T extends Array<infer U>
|
||||
? Array<RecursivePartial<U>>
|
||||
: // (optionally: Map/Set support)
|
||||
T extends Map<infer K, infer V>
|
||||
? Map<RecursivePartial<K>, RecursivePartial<V>>
|
||||
: T extends Set<infer U>
|
||||
? Set<RecursivePartial<U>>
|
||||
: // plain objects
|
||||
T extends object
|
||||
? {[P in keyof T]?: RecursivePartial<T[P]>}
|
||||
: // fallback (shouldn’t be hit often)
|
||||
T;
|
||||
|
||||
/** Type safe wrapper for Number constructor that takes 'any' */
|
||||
export function bnToNum(bn: bigint): number {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2021",
|
||||
"lib": ["es2021", "dom"],
|
||||
"target": "es2022",
|
||||
"lib": ["es2022", "dom"],
|
||||
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
|
||||
"pretty": true,
|
||||
"strict": true,
|
||||
@@ -19,6 +19,7 @@
|
||||
"noImplicitThis": true,
|
||||
"noImplicitReturns": true,
|
||||
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
@@ -28,8 +29,6 @@
|
||||
// TODO: Investigate following errors:
|
||||
// - Cannot find module 'rollup/parseAst' or its corresponding type declarations
|
||||
"skipLibCheck": true,
|
||||
|
||||
"types": ["node", "bun", "vitest"],
|
||||
|
||||
// Required to run benchmark command from root directory
|
||||
"typeRoots": [
|
||||
|
||||
11
types/mitt/index.d.ts
vendored
Normal file
11
types/mitt/index.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare module "mitt" {
|
||||
export type Emitter<T extends Record<string, (...args: any[]) => void>> = {
|
||||
on<K extends keyof T>(type: K, handler: T[K]): void;
|
||||
off<K extends keyof T>(type: K, handler: T[K]): void;
|
||||
emit<K extends keyof T>(type: K, ...args: Parameters<T[K]>): void;
|
||||
};
|
||||
|
||||
export function mitt<T>(): Emitter<T>;
|
||||
|
||||
export default mitt;
|
||||
}
|
||||
73
yarn.lock
73
yarn.lock
@@ -840,10 +840,10 @@
|
||||
"@chainsafe/swap-or-not-shuffle-win32-arm64-msvc" "1.2.1"
|
||||
"@chainsafe/swap-or-not-shuffle-win32-x64-msvc" "1.2.1"
|
||||
|
||||
"@chainsafe/threads@^1.11.2":
|
||||
version "1.11.2"
|
||||
resolved "https://registry.yarnpkg.com/@chainsafe/threads/-/threads-1.11.2.tgz#fc400efdfec2d246e5054e3521a9066dc2dc45af"
|
||||
integrity sha512-qd5mSYWyIgK+G4LQTLhJhO4IUda4eydYhZsT6AadALFUKs5WrHaFtAf7sLol6JjgWG7wwgznUs7FFyBl0xPmoQ==
|
||||
"@chainsafe/threads@^1.11.3":
|
||||
version "1.11.3"
|
||||
resolved "https://registry.yarnpkg.com/@chainsafe/threads/-/threads-1.11.3.tgz#7dba606277bfb0e9c8a54325da0372494ec02042"
|
||||
integrity sha512-wTIHTOOJ3MMRFtnJJT6KJCuauyv8pgs79m5ipspyPjHdKM9HJnkeZcoo06G3qArx2xMvd6MqNj1TLfnh5iFvaQ==
|
||||
dependencies:
|
||||
callsites "^3.1.0"
|
||||
debug "^4.2.0"
|
||||
@@ -3607,16 +3607,6 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/statuses/-/statuses-2.0.6.tgz#66748315cc9a96d63403baa8671b2c124f8633aa"
|
||||
integrity sha512-xMAgYwceFhRA2zY+XbEA7mxYbA093wdiW8Vu6gZPGWy9cmOyU9XesH1tNcEWsKFd5Vzrqx5T3D38PWx1FIIXkA==
|
||||
|
||||
"@types/strip-bom@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.npmjs.org/@types/strip-bom/-/strip-bom-3.0.0.tgz"
|
||||
integrity sha1-FKjsOVbC6B7bdSB5CuzyHCkK69I=
|
||||
|
||||
"@types/strip-json-comments@0.0.30":
|
||||
version "0.0.30"
|
||||
resolved "https://registry.npmjs.org/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz"
|
||||
integrity sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==
|
||||
|
||||
"@types/through@*":
|
||||
version "0.0.30"
|
||||
resolved "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz"
|
||||
@@ -6711,15 +6701,6 @@ fs-constants@^1.0.0:
|
||||
resolved "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz"
|
||||
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
|
||||
|
||||
fs-extra@^10.0.0:
|
||||
version "10.1.0"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
|
||||
integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==
|
||||
dependencies:
|
||||
graceful-fs "^4.2.0"
|
||||
jsonfile "^6.0.1"
|
||||
universalify "^2.0.0"
|
||||
|
||||
fs-extra@^11.1.0, fs-extra@^11.1.1:
|
||||
version "11.1.1"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
|
||||
@@ -11895,11 +11876,6 @@ strip-indent@^3.0.0:
|
||||
dependencies:
|
||||
min-indent "^1.0.0"
|
||||
|
||||
strip-json-comments@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz"
|
||||
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
||||
|
||||
strip-json-comments@~3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz"
|
||||
@@ -12284,25 +12260,6 @@ triple-beam@^1.3.0:
|
||||
resolved "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz"
|
||||
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==
|
||||
|
||||
ts-node@^10.8.1:
|
||||
version "10.9.1"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
|
||||
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
|
||||
dependencies:
|
||||
"@cspotcode/source-map-support" "^0.8.0"
|
||||
"@tsconfig/node10" "^1.0.7"
|
||||
"@tsconfig/node12" "^1.0.7"
|
||||
"@tsconfig/node14" "^1.0.0"
|
||||
"@tsconfig/node16" "^1.0.2"
|
||||
acorn "^8.4.1"
|
||||
acorn-walk "^8.1.1"
|
||||
arg "^4.1.0"
|
||||
create-require "^1.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
v8-compile-cache-lib "^3.0.1"
|
||||
yn "3.1.1"
|
||||
|
||||
ts-node@^10.9.2:
|
||||
version "10.9.2"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f"
|
||||
@@ -12339,16 +12296,6 @@ tsconfig-paths@^4.1.2:
|
||||
minimist "^1.2.6"
|
||||
strip-bom "^3.0.0"
|
||||
|
||||
tsconfig@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.npmjs.org/tsconfig/-/tsconfig-7.0.0.tgz"
|
||||
integrity sha512-vZXmzPrL+EmC4T/4rVlT2jNVMWCi/O4DIiSj3UHg1OE5kCKbk4mfrXc6dZksLgRM/TZlKnousKH9bbTazUWRRw==
|
||||
dependencies:
|
||||
"@types/strip-bom" "^3.0.0"
|
||||
"@types/strip-json-comments" "0.0.30"
|
||||
strip-bom "^3.0.0"
|
||||
strip-json-comments "^2.0.0"
|
||||
|
||||
tslib@2.4.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
|
||||
@@ -12499,17 +12446,13 @@ typedarray@^0.0.6:
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==
|
||||
|
||||
typescript-docs-verifier@^2.5.3:
|
||||
version "2.5.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript-docs-verifier/-/typescript-docs-verifier-2.5.3.tgz#2fcb393cdae955a2c86bf272008cf6f7fb3d1fbf"
|
||||
integrity sha512-fATV69QQZzIQWDGfUzo2USUcUTK0hPqTm7XZuyHf4QOkZUshnkwDk8TEk2IxaIlHxKjbM+5RtyDgxCtKYycjXA==
|
||||
typescript-docs-verifier@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/typescript-docs-verifier/-/typescript-docs-verifier-3.0.1.tgz#63951110040a01661ff1732c0d52add445329f63"
|
||||
integrity sha512-ohQsDJ49+tfOsRoJGREUgh6Vk79KVMsk+M3263b2CHqb1eQW8vkeDhBr9euz7nITBwgRk+RujUcxjIhD3kYPpA==
|
||||
dependencies:
|
||||
chalk "^4.1.2"
|
||||
fs-extra "^10.0.0"
|
||||
ora "^5.4.1"
|
||||
strip-ansi "^7.0.1"
|
||||
ts-node "^10.8.1"
|
||||
tsconfig "^7.0.0"
|
||||
yargs "^17.5.1"
|
||||
|
||||
typescript@5.7.2:
|
||||
|
||||
Reference in New Issue
Block a user