diff --git a/examples/napi/__tests__/__snapshots__/values.spec.ts.md b/examples/napi/__tests__/__snapshots__/values.spec.ts.md deleted file mode 100644 index 0a177256..00000000 --- a/examples/napi/__tests__/__snapshots__/values.spec.ts.md +++ /dev/null @@ -1,1319 +0,0 @@ -# Snapshot report for `__tests__/values.spec.ts` - -The actual snapshot is saved in `values.spec.ts.snap`. - -Generated by [AVA](https://avajs.dev). - -## serde-json - -> Snapshot 1 - - [ - '@napi-rs/cli', - '@napi-rs/triples', - '@napi-rs/wasm-runtime', - '@oxc-node/core', - '@testing-library/dom', - '@types/lodash', - '@vitest/browser', - '@vitest/browser-playwright', - '@vitest/ui', - 'ava', - 'buffer', - 'core-js', - 'cross-env', - 'electron', - 'lodash', - 'playwright', - 'rxjs', - 'sinon', - 'vite', - 'vite-plugin-node-polyfills', - 'vitest', - 'web-streams-polyfill', - 'webdriverio', - ] - -## should generate correct type def file - -> Snapshot 1 - - `/* auto-generated by NAPI-RS */␊ - /* eslint-disable */␊ - ␊ - import type { ReadableStream } from 'node:stream/web'␊ - ␊ - type MaybePromise = T | Promise␊ - ␊ - export declare const NAPI_RS_SYMBOL: symbol␊ - ␊ - export declare class ExternalObject {␊ - readonly '': {␊ - readonly '': unique symbol␊ - [K: symbol]: T␊ - }␊ - }␊ - ␊ - export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array␊ - /**␊ - * \`constructor\` option for \`struct\` requires all fields to be public,␊ - * otherwise tag impl fn as constructor␊ - * #[napi(constructor)]␊ - */␊ - export declare class Animal {␊ - /** Kind of animal */␊ - readonly kind: Kind␊ - /** This is the constructor */␊ - constructor(kind: Kind, name: string)␊ - /** This is a factory method */␊ - static withKind(kind: Kind): Animal␊ - get name(): string␊ - set name(name: string)␊ - get type(): Kind␊ - set type(kind: Kind)␊ - /**␊ - * This is a␊ - * multi-line comment␊ - * with an emoji 🚀␊ - */␊ - whoami(): string␊ - /** This is static... */␊ - static getDogKind(): Kind␊ - /**␊ - * Here are some characters and character sequences␊ - * that should be escaped correctly:␊ - * \\[]{}/\\:""{␊ - * }␊ - */␊ - returnOtherClass(): Dog␊ - returnOtherClassWithCustomConstructor(): Bird␊ - overrideIndividualArgOnMethod(normalTy: string, overriddenTy: {n: string}): Bird␊ - }␊ - ␊ - export declare class AnimalWithDefaultConstructor {␊ - name: string␊ - kind: number␊ - constructor(name: string, kind: number)␊ - }␊ - ␊ - export declare class AnotherClassForEither {␊ - constructor()␊ - }␊ - ␊ - export declare class AnotherCssStyleSheet {␊ - get rules(): CssRuleList␊ - }␊ - export type AnotherCSSStyleSheet = AnotherCssStyleSheet␊ - ␊ - export declare class Asset {␊ - constructor()␊ - get filePath(): number␊ - }␊ - export type JsAsset = Asset␊ - ␊ - export declare class Assets {␊ - constructor()␊ - get(id: number): JsAsset | null␊ - }␊ - export type JsAssets = Assets␊ - ␊ - export declare class Bird {␊ - name: string␊ - constructor(name: string)␊ - getCount(): number␊ - getNameAsync(): Promise␊ - acceptSliceMethod(slice: Uint8Array): number␊ - }␊ - ␊ - /** Smoking test for type generation */␊ - export declare class Blake2BHasher {␊ - static withKey(key: Blake2bKey): Blake2BHasher␊ - update(data: Buffer): void␊ - }␊ - export type Blake2bHasher = Blake2BHasher␊ - ␊ - export declare class Blake2BKey {␊ - ␊ - }␊ - export type Blake2bKey = Blake2BKey␊ - ␊ - export declare class CatchOnConstructor {␊ - constructor()␊ - }␊ - ␊ - export declare class CatchOnConstructor2 {␊ - constructor()␊ - }␊ - ␊ - export declare class ClassInArray {␊ - constructor(value: number)␊ - }␊ - ␊ - export declare class ClassReturnInPromise {␊ - ␊ - }␊ - ␊ - export declare class ClassWithFactory {␊ - name: string␊ - static withName(name: string): ClassWithFactory␊ - static with4Name(name: string): Promise␊ - static with4NameResult(name: string): Promise␊ - setName(name: string): this␊ - }␊ - ␊ - export declare class ClassWithLifetime {␊ - constructor()␊ - getName(): string␊ - }␊ - ␊ - export declare class Context {␊ - maybeNeed?: boolean␊ - buffer: Uint8Array␊ - constructor()␊ - static withData(data: string): Context␊ - static withBuffer(buf: Uint8Array): Context␊ - method(): string␊ - }␊ - ␊ - export declare class CreateStringClass {␊ - static new(): CreateStringClass␊ - createString(): string | null␊ - createStringResult(): string␊ - }␊ - ␊ - export declare class CssRuleList {␊ - getRules(): Array␊ - get parentStyleSheet(): CSSStyleSheet␊ - get name(): string | null␊ - }␊ - export type CSSRuleList = CssRuleList␊ - ␊ - export declare class CssStyleSheet {␊ - constructor(name: string, rules: Array)␊ - get rules(): CssRuleList␊ - anotherCssStyleSheet(): AnotherCssStyleSheet␊ - }␊ - export type CSSStyleSheet = CssStyleSheet␊ - ␊ - export declare class CustomFinalize {␊ - constructor(width: number, height: number)␊ - }␊ - ␊ - export declare class CustomStruct {␊ - static customStatusCodeForFactory(): CustomStruct␊ - constructor()␊ - }␊ - ␊ - export declare class DefaultUseNullableClass {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - optionalNumberField?: number␊ - optionalStringField?: string␊ - constructor(requiredNumberField: number, requiredStringField: string, optionalNumberField?: number, optionalStringField?: string)␊ - }␊ - ␊ - export declare class Dog {␊ - name: string␊ - constructor(name: string)␊ - }␊ - ␊ - /**␊ - * This type extends JavaScript's \`Iterator\`, and so has the iterator helper␊ - * methods. It may extend the upcoming TypeScript \`Iterator\` class in the future.␊ - *␊ - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods␊ - * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods␊ - */␊ - export declare class Fib extends Iterator {␊ - constructor()␊ - next(value?: number): IteratorResult␊ - }␊ - ␊ - /**␊ - * This type extends JavaScript's \`Iterator\`, and so has the iterator helper␊ - * methods. It may extend the upcoming TypeScript \`Iterator\` class in the future.␊ - *␊ - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods␊ - * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods␊ - */␊ - export declare class Fib2 extends Iterator {␊ - static create(seed: number): Fib2␊ - next(value?: number): IteratorResult␊ - }␊ - ␊ - /**␊ - * This type extends JavaScript's \`Iterator\`, and so has the iterator helper␊ - * methods. It may extend the upcoming TypeScript \`Iterator\` class in the future.␊ - *␊ - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods␊ - * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods␊ - */␊ - export declare class Fib3 extends Iterator {␊ - current: number␊ - nextNum: number␊ - constructor(current: number, nextNum: number)␊ - next(value?: number): IteratorResult␊ - }␊ - ␊ - /**␊ - * This type extends JavaScript's \`Iterator\`, and so has the iterator helper␊ - * methods. It may extend the upcoming TypeScript \`Iterator\` class in the future.␊ - *␊ - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helper_methods␊ - * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-6.html#iterator-helper-methods␊ - */␊ - export declare class Fib4 extends Iterator {␊ - current: number␊ - nextItem: number␊ - constructor(current: number, nextItem: number)␊ - next(value?: number): IteratorResult␊ - }␊ - ␊ - export declare class GetterSetterWithClosures {␊ - constructor()␊ - }␊ - ␊ - export declare class JsClassForEither {␊ - constructor()␊ - }␊ - ␊ - export declare class JSOnlyMethodsClass {␊ - data: string␊ - processData(): string␊ - getLength(): number␊ - }␊ - export type RustOnlyMethodsClass = JSOnlyMethodsClass␊ - ␊ - export declare class JsRemote {␊ - constructor(repo: JsRepo)␊ - name(): string␊ - }␊ - ␊ - export declare class JsRepo {␊ - constructor(dir: string)␊ - remote(): JsRemote␊ - }␊ - ␊ - export declare class MyJsNamedClass {␊ - constructor(value: string)␊ - getValue(): string␊ - multiplyValue(times: number): string␊ - }␊ - export type OriginalRustNameForJsNamedStruct = MyJsNamedClass␊ - ␊ - export declare class NinjaTurtle {␊ - name: string␊ - static isInstanceOf(value: unknown): boolean␊ - /** Create your ninja turtle! 🐢 */␊ - static newRaph(): NinjaTurtle␊ - getMaskColor(): string␊ - getName(): string␊ - returnThis(): this␊ - }␊ - ␊ - export declare class NotUseNullableClass {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - optionalNumberField?: number␊ - optionalStringField?: string␊ - constructor(requiredNumberField: number, requiredStringField: string, optionalNumberField?: number, optionalStringField?: string)␊ - }␊ - ␊ - export declare class NotWritableClass {␊ - name: string␊ - constructor(name: string)␊ - setName(name: string): void␊ - }␊ - ␊ - export declare class Optional {␊ - static optionEnd(required: string, optional?: string | undefined | null): string␊ - static optionStart(optional: string | undefined | null, required: string): string␊ - static optionStartEnd(optional1: string | undefined | null, required: string, optional2?: string | undefined | null): string␊ - static optionOnly(optional?: string | undefined | null): string␊ - }␊ - ␊ - export declare class PackageJsonReader {␊ - constructor()␊ - read(): any␊ - }␊ - ␊ - export declare class Reader {␊ - ␊ - constructor()␊ - read(): Buffer␊ - }␊ - ␊ - export declare class Selector {␊ - orderBy: Array␊ - select: Array␊ - struct: string␊ - where?: string␊ - constructor(orderBy: Array, select: Array, struct: string, where?: string)␊ - }␊ - ␊ - export declare class Thing {␊ - ␊ - }␊ - ␊ - export declare class ThingList {␊ - constructor()␊ - get thing(): Thing␊ - }␊ - ␊ - export declare class UseNullableClass {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - nullableNumberField: number | null␊ - nullableStringField: string | null␊ - constructor(requiredNumberField: number, requiredStringField: string, nullableNumberField: number | null, nullableStringField: string | null)␊ - }␊ - ␊ - export declare class Width {␊ - value: number␊ - constructor(value: number)␊ - }␊ - ␊ - export interface A {␊ - foo: number␊ - }␊ - ␊ - export declare function acceptArraybuffer(fixture: ArrayBuffer): bigint␊ - ␊ - export declare function acceptSlice(fixture: Uint8Array): bigint␊ - ␊ - export declare function acceptStream(stream: ReadableStream): Promise␊ - ␊ - export declare function acceptThreadsafeFunction(func: ((err: Error | null, arg: number) => any)): void␊ - ␊ - export declare function acceptThreadsafeFunctionFatal(func: ((arg: number) => void)): void␊ - ␊ - export declare function acceptThreadsafeFunctionTupleArgs(func: ((err: Error | null, arg0: number, arg1: boolean, arg2: string) => any)): void␊ - ␊ - export declare function acceptUint8ClampedSlice(input: Uint8ClampedArray): bigint␊ - ␊ - export declare function acceptUint8ClampedSliceAndBufferSlice(a: Buffer, b: Uint8ClampedArray): bigint␊ - ␊ - export declare function acceptUntypedTypedArray(input: TypedArray): bigint␊ - ␊ - export declare function add(a: number, b: number): number␊ - ␊ - export declare const enum ALIAS {␊ - A = 0,␊ - B = 1␊ - }␊ - ␊ - export interface AliasedStruct {␊ - a: ALIAS␊ - b: number␊ - }␊ - ␊ - export interface AllOptionalObject {␊ - name?: string␊ - age?: number␊ - }␊ - ␊ - export declare function appendBuffer(buf: Buffer): Buffer␊ - ␊ - export declare function apply0(ctx: Animal, callback: () => void): void␊ - ␊ - export declare function apply1(ctx: Animal, callback: (arg: string) => void, name: string): void␊ - ␊ - export declare function arrayBufferFromData(): ArrayBuffer␊ - ␊ - export declare function arrayBufferFromExternal(): ArrayBuffer␊ - ␊ - export declare function arrayBufferPassThrough(buf: Uint8Array): Promise␊ - ␊ - export declare function arrayParams(arr: Array): number␊ - ␊ - export declare function asyncBufferToArray(buf: ArrayBuffer): Array␊ - ␊ - export declare function asyncMultiTwo(arg: number): Promise␊ - ␊ - export declare function asyncPlus100(p: Promise): Promise␊ - ␊ - export declare function asyncReduceBuffer(buf: Buffer): Promise␊ - ␊ - export declare function asyncResolveArray(inner: number): Promise␊ - ␊ - export declare function asyncTaskFinally(inner: object): Promise␊ - ␊ - export declare function asyncTaskOptionalReturn(): Promise␊ - ␊ - export declare function asyncTaskReadFile(path: string): Promise␊ - ␊ - export declare function asyncTaskVoidReturn(): Promise␊ - ␊ - export interface B {␊ - bar: number␊ - }␊ - ␊ - export declare function bigintAdd(a: bigint, b: bigint): bigint␊ - ␊ - export declare function bigintFromI128(): bigint␊ - ␊ - export declare function bigintFromI64(): bigint␊ - ␊ - export declare function bigintGetU64AsString(bi: bigint): string␊ - ␊ - export interface BindingVitePluginMeta {␊ - 'vite:import-glob': ViteImportGlobMeta␊ - }␊ - ␊ - export declare function btreeSetToJs(): Set␊ - ␊ - export declare function btreeSetToRust(set: Set): void␊ - ␊ - export declare function bufferPassThrough(buf: Buffer): Promise␊ - ␊ - export declare function bufferWithAsyncBlock(buf: Buffer): Promise␊ - ␊ - export declare function buildThreadsafeFunctionFromFunction(callback: (arg0: number, arg1: number) => number): void␊ - ␊ - export declare function buildThreadsafeFunctionFromFunctionCalleeHandle(callback: () => void): void␊ - ␊ - export interface C {␊ - baz: number␊ - }␊ - ␊ - export declare function call0(callback: () => number): number␊ - ␊ - export declare function call1(callback: (arg: number) => number, arg: number): number␊ - ␊ - export declare function call2(callback: (arg0: number, arg1: number) => number, arg1: number, arg2: number): number␊ - ␊ - export declare function callAsyncWithUnknownReturnValue(tsfn: ((err: Error | null, arg: number) => unknown)): Promise␊ - ␊ - export declare function callbackInSpawn(callback: (arg: object) => unknown): void␊ - ␊ - export declare function callbackReturnPromise(functionInput: () => T | Promise, callback: (err: Error | null, result: T) => void): T | Promise␊ - ␊ - export declare function callbackReturnPromiseAndSpawn(jsFunc: (arg0: string) => Promise): Promise␊ - ␊ - export declare function callCatchOnPromise(input: Promise): Promise␊ - ␊ - export declare function callFinallyOnPromise(input: Promise, onFinally: () => void): Promise␊ - ␊ - export declare function callFunction(cb: () => number): number␊ - ␊ - export declare function callFunctionWithArg(cb: (arg0: number, arg1: number) => number, arg0: number, arg1: number): number␊ - ␊ - export declare function callFunctionWithArgAndCtx(ctx: Animal, cb: (arg: string) => void, name: string): void␊ - ␊ - export declare function callLongThreadsafeFunction(tsfn: ((err: Error | null, arg: number) => unknown)): void␊ - ␊ - export declare function callRuleHandler(rule: Rule, arg: number): number␊ - ␊ - export declare function callThenOnPromise(input: Promise): Promise␊ - ␊ - export declare function callThreadsafeFunction(tsfn: ((err: Error | null, arg: number) => unknown)): void␊ - ␊ - export declare function captureErrorInCallback(cb1: () => void, cb2: (arg0: Error) => void): void␊ - ␊ - export declare function chronoDateAdd1Minute(input: Date): Date␊ - ␊ - export declare function chronoDateFixtureReturn1(): Date␊ - ␊ - export declare function chronoDateFixtureReturn2(): Date␊ - ␊ - export declare function chronoDateWithTimezoneReturn(): Date | null␊ - ␊ - export declare function chronoDateWithTimezoneToMillis(input: Date): number␊ - ␊ - export declare function chronoLocalDateReturn(): Date | null␊ - ␊ - export declare function chronoLocalDateToMillis(input: Date): number␊ - ␊ - export declare function chronoNativeDateTime(date: Date): number␊ - ␊ - export declare function chronoNativeDateTimeReturn(): Date | null␊ - ␊ - export declare function chronoUtcDateReturn(): Date | null␊ - ␊ - export declare function chronoUtcDateToMillis(input: Date): number␊ - ␊ - export interface CompilerAssumptions {␊ - ignoreFunctionLength?: boolean␊ - noDocumentAll?: boolean␊ - objectRestNoSymbols?: boolean␊ - pureGetters?: boolean␊ - /**␊ - * When using public class fields, assume that they don't shadow any getter in the current class,␊ - * in its subclasses or in its superclass. Thus, it's safe to assign them rather than using␊ - * \`Object.defineProperty\`.␊ - *␊ - * For example:␊ - *␊ - * Input:␊ - * \`\`\`js␊ - * class Test {␊ - * field = 2;␊ - *␊ - * static staticField = 3;␊ - * }␊ - * \`\`\`␊ - *␊ - * When \`set_public_class_fields\` is \`true\`, the output will be:␊ - * \`\`\`js␊ - * class Test {␊ - * constructor() {␊ - * this.field = 2;␊ - * }␊ - * }␊ - * Test.staticField = 3;␊ - * \`\`\`␊ - *␊ - * Otherwise, the output will be:␊ - * \`\`\`js␊ - * import _defineProperty from "@oxc-project/runtime/helpers/defineProperty";␊ - * class Test {␊ - * constructor() {␊ - * _defineProperty(this, "field", 2);␊ - * }␊ - * }␊ - * _defineProperty(Test, "staticField", 3);␊ - * \`\`\`␊ - *␊ - * NOTE: For TypeScript, if you wanted behavior is equivalent to \`useDefineForClassFields: false\`, you should␊ - * set both \`set_public_class_fields\` and [\`crate::TypeScriptOptions::remove_class_fields_without_initializer\`]␊ - * to \`true\`.␊ - */␊ - setPublicClassFields?: boolean␊ - }␊ - ␊ - export declare function compressSync(_: string | Uint8Array): Buffer␊ - ␊ - export declare function concatLatin1(s: string): string␊ - ␊ - export declare function concatStr(s: string): string␊ - ␊ - export declare function concatUtf16(s: string): string␊ - ␊ - export declare function contains(source: string, target: string): boolean␊ - ␊ - export declare function convertU32Array(input: Uint32Array): Array␊ - ␊ - export declare function createArraybuffer(): ArrayBuffer␊ - ␊ - export declare function createBigInt(): bigint␊ - ␊ - export declare function createBigIntI64(): bigint␊ - ␊ - export declare function createBufferSliceFromCopiedData(): Buffer␊ - ␊ - export declare function createExternal(size: number): ExternalObject␊ - ␊ - export declare function createExternalBufferSlice(): Buffer␊ - ␊ - export declare function createExternalLatin1CustomFinalize(): string␊ - ␊ - export declare function createExternalLatin1Empty(): string␊ - ␊ - export declare function createExternalLatin1Long(): string␊ - ␊ - export declare function createExternalLatin1Short(): string␊ - ␊ - export declare function createExternalLatin1String(): string␊ - ␊ - export declare function createExternalLatin1WithLatin1Chars(): string␊ - ␊ - export declare function createExternalRef(size: number): ExternalObject␊ - ␊ - export declare function createExternalString(content: string): ExternalObject␊ - ␊ - export declare function createExternalTypedArray(): Uint32Array␊ - ␊ - export declare function createExternalUtf16String(): string␊ - ␊ - export declare function createFunction(): (arg: number) => number␊ - ␊ - export declare function createI32ArrayFromExternal(): Int32Array␊ - ␊ - export declare function createObj(): object␊ - ␊ - export declare function createObjectRef(): object␊ - ␊ - export declare function createObjectWithClassField(): ObjectFieldClassInstance␊ - ␊ - export declare function createObjWithProperty(): { value: ArrayBuffer, get getter(): number }␊ - ␊ - export declare function createOptionalExternal(size?: number | undefined | null): ExternalObject | null␊ - ␊ - export declare function createReadableStream(): ReadableStream␊ - ␊ - export declare function createReadableStreamFromClass(readableStreamClass: typeof ReadableStream): ReadableStream␊ - ␊ - export declare function createReferenceOnFunction(cb: () => void): Promise␊ - ␊ - export declare function createStaticLatin1String(): string␊ - ␊ - export declare function createStaticUtf16String(): string␊ - ␊ - export declare function createSymbol(): symbol␊ - ␊ - export declare function createSymbolFor(desc: string): symbol␊ - ␊ - export declare function createSymbolRef(desc: string): symbol␊ - ␊ - export declare function createUint8ClampedArrayFromData(): Uint8ClampedArray␊ - ␊ - export declare function createUint8ClampedArrayFromExternal(): Uint8ClampedArray␊ - ␊ - export declare function createZeroCopyLatin1String(): string␊ - ␊ - export declare function createZeroCopyUtf16String(): string␊ - ␊ - /** You could break the step and for an new continuous value. */␊ - export declare const enum CustomNumEnum {␊ - One = 1,␊ - Two = 2,␊ - Three = 3,␊ - Four = 4,␊ - Six = 6,␊ - Eight = 8,␊ - Nine = 9,␊ - Ten = 10␊ - }␊ - ␊ - export declare function customStatusCode(): void␊ - ␊ - export declare const enum CustomStringEnum {␊ - Foo = 'my-custom-value',␊ - Bar = 'Bar',␊ - Baz = 'Baz'␊ - }␊ - ␊ - export type CustomU32 =␊ - number␊ - ␊ - export interface Data {␊ - data: string | Buffer␊ - }␊ - ␊ - export interface DatesWithTimeZone {␊ - start: Date␊ - end?: Date␊ - }␊ - ␊ - export declare function dateToNumber(input: Date): number␊ - ␊ - /** This is a const */␊ - export const DEFAULT_COST: number␊ - ␊ - export interface DefaultUseNullableStruct {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - optionalNumberField?: number␊ - optionalStringField?: string␊ - }␊ - ␊ - export declare function defineClass(): typeof DynamicRustClass␊ - ␊ - class DynamicRustClass {␊ - constructor(value: number)␊ - rustMethod(): number␊ - }␊ - ␊ - export declare function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊ - ␊ - export declare function either3(input: string | number | boolean): number␊ - ␊ - export declare function either4(input: string | number | boolean | Obj): number␊ - ␊ - export declare function eitherBoolOrFunction(input: boolean | ((arg?: unknown) => unknown)): void␊ - ␊ - export declare function eitherBoolOrTuple(input: boolean | [boolean, string]): void␊ - ␊ - export declare function eitherF64OrU32(input: number): number␊ - ␊ - export declare function eitherFromObjects(input: A | B | C): string␊ - ␊ - export declare function eitherFromOption(): JsClassForEither | undefined␊ - ␊ - export declare function eitherPromiseInEitherA(input: Promise | number | string): Promise␊ - ␊ - export declare function eitherStringOrNumber(input: string | number): number␊ - ␊ - export declare const enum Empty {␊ - ␊ - }␊ - ␊ - export declare function enumToI32(e: CustomNumEnum): number␊ - ␊ - export declare function errorMessageContainsNullByte(msg: string): void␊ - ␊ - export declare function esmResolve(next: () => Promise): Promise␊ - ␊ - export declare function extendsJavascriptError(errorClass: any): void␊ - ␊ - export type ExternalLinterLoadPluginCb =␊ - ((arg: string) => PluginLoadResult)␊ - ␊ - export type ExternalLinterLoadPluginCb2 =␊ - ((arg: string) => PluginLoadResult)␊ - ␊ - export declare function f32ArrayToArray(input: Float32Array): Array␊ - ␊ - export declare function f64ArrayToArray(input: Float64Array): Array␊ - ␊ - export declare function fibonacci(n: number): number␊ - ␊ - export declare function fnReceivedAliased(s: AliasedStruct, e: ALIAS): void␊ - ␊ - export interface FunctionData {␊ - handle: () => number␊ - }␊ - ␊ - export declare function generateFunctionAndCallIt(): FunctionData␊ - ␊ - export declare function getBigintJsonValue(value: bigint): void␊ - ␊ - export declare function getBtreeMapping(): Record␊ - ␊ - export declare function getBuffer(): Buffer␊ - ␊ - export declare function getBufferSlice(): Buffer␊ - ␊ - export declare function getClassFromArray(arr: unknown[]): number | null␊ - ␊ - export declare function getCwd(callback: (arg0: string) => void): void␊ - ␊ - export declare function getEmptyBuffer(): Buffer␊ - ␊ - export declare function getEmptyTypedArray(): Uint8Array␊ - ␊ - export declare function getExternal(external: ExternalObject): number␊ - ␊ - export declare function getGlobal(): typeof global␊ - ␊ - export declare function getIndexMapping(): Record␊ - ␊ - export declare function getIndexMappingWithHasher(): Record␊ - ␊ - export declare function getMapping(): Record␊ - ␊ - export declare function getMappingWithHasher(): Record␊ - ␊ - export declare function getModuleFileName(): string␊ - ␊ - export declare function getMyVec(): MyVec␊ - ␊ - export declare function getNestedNumArr(): number[][][]␊ - ␊ - export declare function getNull(): null␊ - ␊ - export declare function getNullByteProperty(obj: object): string | null␊ - ␊ - export declare function getNumArr(): number[]␊ - ␊ - /** Gets some numbers */␊ - export declare function getNums(): Array␊ - ␊ - export declare function getOptionalExternal(external?: ExternalObject | undefined | null): number | null␊ - ␊ - export declare function getPackageJsonName(packageJson: PackageJson): string␊ - ␊ - export declare function getStrFromObject(): void␊ - ␊ - export declare function getterFromObj(): number␊ - ␊ - export declare function getTuple(val: [number, string, number]): number␊ - ␊ - export declare function getUndefined(): void␊ - ␊ - export declare function getWords(): Array␊ - ␊ - export declare function i16ArrayToArray(input: Int16Array): Array␊ - ␊ - export declare function i32ArrayToArray(input: Int32Array): Array␊ - ␊ - export declare function i64ArrayToArray(input: BigInt64Array): Array␊ - ␊ - export declare function i8ArrayToArray(input: Int8Array): Array␊ - ␊ - export declare function indexmapPassthrough(fixture: Record): Record␊ - ␊ - export declare function indexSetToJs(): Set␊ - ␊ - export declare function indexSetToRust(set: Set): void␊ - ␊ - export declare function intoUtf8(s: string): string␊ - ␊ - export declare function jsErrorCallback(value: unknown): Array␊ - ␊ - /** default enum values are continuos i32s start from 0 */␊ - export declare const enum Kind {␊ - /** Barks */␊ - Dog = 0,␊ - /** Kills birds */␊ - Cat = 1,␊ - /** Tasty */␊ - Duck = 2␊ - }␊ - ␊ - /** default enum values are continuos i32s start from 0 */␊ - export declare const enum KindInValidate {␊ - /** Barks */␊ - Dog = 0,␊ - /** Kills birds */␊ - Cat = 1,␊ - /** Tasty */␊ - Duck = 2␊ - }␊ - ␊ - export interface Latin1MethodsResult {␊ - length: number␊ - isEmpty: boolean␊ - asSlice: Array␊ - }␊ - ␊ - export declare function listObjKeys(obj: object): Array␊ - ␊ - export interface LocalDates {␊ - start: Date␊ - end?: Date␊ - }␊ - ␊ - export declare function mapOption(val?: number | undefined | null): number | null␊ - ␊ - export declare function mergeTupleArray(t1: TupleToArray, t2: TupleToArray): TupleToArray␊ - ␊ - export interface Meta {␊ - merge: boolean␊ - }␊ - ␊ - export declare function mutateExternal(external: ExternalObject, newVal: number): void␊ - ␊ - export declare function mutateOptionalExternal(external: ExternalObject | undefined | null, newVal: number): void␊ - ␊ - export declare function mutateTypedArray(input: Float32Array): void␊ - ␊ - export type MyPromise =␊ - string | Promise␊ - ␊ - export type MyVec =␊ - Array␊ - ␊ - export interface NotUseNullableStruct {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - optionalNumberField?: number␊ - optionalStringField?: string␊ - }␊ - ␊ - export type Nullable =␊ - T | undefined | null␊ - ␊ - export interface Obj {␊ - v: string | number␊ - }␊ - ␊ - export interface ObjectFieldClassInstance {␊ - bird: Bird␊ - }␊ - ␊ - export declare function objectGetNamedPropertyShouldPerformTypecheck(obj: { foo: number; bar: string; }): void␊ - ␊ - export interface ObjectOnlyFromJs {␊ - count: number␊ - callback: ((err: Error | null, arg: number) => any)␊ - }␊ - ␊ - export interface ObjectOnlyToJs {␊ - name: number␊ - dependencies: any␊ - }␊ - ␊ - export declare function objectWithCApis(): object␊ - ␊ - export declare function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void␊ - ␊ - export declare function optionOnly(callback: (arg0?: string | undefined | null) => void): void␊ - ␊ - export declare function optionStart(callback: (arg0: string | undefined | null, arg1: string) => void): void␊ - ␊ - export declare function optionStartEnd(callback: (arg0: string | undefined | null, arg1: string, arg2?: string | undefined | null) => void): void␊ - ␊ - export declare function overrideIndividualArgOnFunction(notOverridden: string, f: () => string, notOverridden2: number): string␊ - ␊ - export declare function overrideIndividualArgOnFunctionWithCbArg(callback: (town: string, name?: string | undefined | null) => string, notOverridden: number): object␊ - ␊ - export declare function overrideWholeFunctionType(operation: 'add' | 'subtract' | 'multiply', a: number, b: number): number␊ - ␊ - /** This is an interface for package.json */␊ - export interface PackageJson {␊ - name: string␊ - /** The version of the package */␊ - version: string␊ - dependencies?: Record␊ - devDependencies?: Record␊ - }␊ - ␊ - export declare function panic(): void␊ - ␊ - export declare function panicInAsync(): Promise␊ - ␊ - export declare function passSetToJs(): Set␊ - ␊ - export declare function passSetToRust(set: Set): void␊ - ␊ - export declare function passSetWithHasherToJs(): Set␊ - ␊ - export interface Pet {␊ - name: string␊ - kind: number␊ - eitherTsfn: string | ((err: Error | null, arg: number) => number)␊ - }␊ - ␊ - export interface PluginLoadResult {␊ - name: string␊ - version: string␊ - }␊ - ␊ - export declare function plusOne(this: Width): number␊ - ␊ - export declare function promiseInEither(input: number | Promise): Promise␊ - ␊ - export declare function promiseRawReturnClassInstance(): Promise␊ - ␊ - export interface PropertyNameDigitTest {␊ - /** Property names starting with digits should be quoted */␊ - '0invalid': string␊ - '123': string␊ - }␊ - ␊ - export interface PropertyNameSpecialCharsTest {␊ - /** Special characters should be quoted */␊ - 'kebab-case': string␊ - 'with space': string␊ - 'dot.notation': string␊ - 'xml:lang': string␊ - /** Dollar sign should be quoted for backward compatibility */␊ - '$var': string␊ - }␊ - ␊ - export interface PropertyNameUnicodeTest {␊ - /** Unicode characters should NOT be quoted */␊ - café: string␊ - 日本語: string␊ - Ελληνικά: string␊ - }␊ - ␊ - export interface PropertyNameValidTest {␊ - /** Valid identifiers should NOT be quoted */␊ - camelCase: string␊ - pascalCase: string␊ - private: string␊ - with123Numbers: string␊ - }␊ - ␊ - /** napi = { version = 2, features = ["serde-json"] } */␊ - export declare function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void␊ - ␊ - export declare function readFileAsync(path: string): Promise␊ - ␊ - export declare function readPackageJson(): PackageJson␊ - ␊ - export declare function receiveAllOptionalObject(obj?: AllOptionalObject | undefined | null): void␊ - ␊ - export declare function receiveBindingVitePluginMeta(meta: BindingVitePluginMeta): void␊ - ␊ - export declare function receiveBufferSliceWithLifetime(data: Data): number␊ - ␊ - export declare function receiveClassOrNumber(either: number | JsClassForEither): number␊ - ␊ - export declare function receiveDifferentClass(either: JsClassForEither | AnotherClassForEither): number␊ - ␊ - export declare function receiveMutClassOrNumber(either: number | JsClassForEither): number␊ - ␊ - export declare function receiveObjectOnlyFromJs(obj: { count: number, callback: (err: Error | null, count: number) => void }): void␊ - ␊ - export declare function receiveObjectWithClassField(object: ObjectFieldClassInstance): Bird␊ - ␊ - export declare function receiveStrictObject(strictObject: StrictObject): void␊ - ␊ - export declare function receiveString(s: string): string␊ - ␊ - export declare function referenceAsCallback(callback: (arg0: number, arg1: number) => number, arg0: number, arg1: number): number␊ - ␊ - export declare function returnCString(): string␊ - ␊ - export declare function returnEither(input: number): string | number␊ - ␊ - export declare function returnEitherClass(input: number): number | JsClassForEither␊ - ␊ - export declare function returnFromSharedCrate(): Shared␊ - ␊ - export declare function returnNull(): null␊ - ␊ - export declare function returnObjectOnlyToJs(): ObjectOnlyToJs␊ - ␊ - export declare function returnUndefined(): void␊ - ␊ - export declare function returnUndefinedIfInvalid(input: boolean): boolean␊ - ␊ - export declare function returnUndefinedIfInvalidPromise(input: Promise): Promise␊ - ␊ - export declare function roundtripStr(s: string): string␊ - ␊ - export interface Rule {␊ - name: string␊ - handler: RuleHandler␊ - }␊ - ␊ - export type RuleHandler =␊ - (arg: Args) => Ret␊ - ␊ - export declare function runScript(script: string): unknown␊ - ␊ - export declare function setNullByteProperty(obj: object): void␊ - ␊ - export declare function setSymbolInObj(symbol: symbol): object␊ - ␊ - export declare function shorterEscapableScope(createString: () => string | null): string␊ - ␊ - export declare function shorterScope(arr: unknown[]): Array␊ - ␊ - export declare function shutdownRuntime(): void␊ - ␊ - export declare function spawnFutureLifetime(input: number): Promise␊ - ␊ - export declare function spawnThreadInThread(tsfn: ((err: Error | null, arg: number) => number)): void␊ - ␊ - export declare const enum Status {␊ - Pristine = 'Pristine',␊ - Loading = 'Loading',␊ - Ready = 'Ready'␊ - }␊ - ␊ - export declare const enum StatusInValidate {␊ - Poll = 'Poll',␊ - Ready = 'Ready',␊ - Done = 'Done'␊ - }␊ - ␊ - export interface StrictObject {␊ - name: string␊ - }␊ - ␊ - export declare const enum StringEnum {␊ - VariantOne = 'variantone',␊ - VariantTwo = 'varianttwo',␊ - VariantThree = 'variantthree'␊ - }␊ - ␊ - export type StructuredKind =␊ - | { type2: 'Hello' }␊ - | { type2: 'Greeting', name: string }␊ - | { type2: 'Birthday', name: string, age: number }␊ - | { type2: 'Tuple', field0: number, field1: number }␊ - ␊ - export type StructuredKindLowercase =␊ - | { type: 'hello' }␊ - | { type: 'greeting', name: string }␊ - | { type: 'birthday', name: string, age: number }␊ - | { type: 'tuple', field0: number, field1: number }␊ - ␊ - export declare function sumBtreeMapping(nums: Record): number␊ - ␊ - export declare function sumIndexMapping(nums: Record): number␊ - ␊ - export declare function sumMapping(nums: Record): number␊ - ␊ - export declare function sumNums(nums: Array): number␊ - ␊ - /**␊ - * Function to test escaped quotes in comments.␊ - * This comment contains escaped quotes: \\\\"g+sx\\\\" and should not break JSON parsing.␊ - * The pattern \\\\"value\\\\" is commonly used in regex and shell commands.␊ - * Another example: sed 's/old/\\\\"new\\\\"/g' where quotes are escaped.␊ - */␊ - export declare function testEscapedQuotesInComments(input: string): string␊ - ␊ - export declare function testLatin1Methods(input: string): Latin1MethodsResult␊ - ␊ - export declare function testSerdeBigNumberPrecision(number: string): any␊ - ␊ - export declare function testSerdeBufferBytes(obj: object): bigint␊ - ␊ - export declare function testSerdeRoundtrip(data: any): any␊ - ␊ - export declare function testWorkers(amount: number, completeCallback: ((err: Error | null, ) => void)): void␊ - ␊ - export declare function threadsafeFunctionBuildThrowErrorWithStatus(cb: (arg?: unknown) => unknown): void␊ - ␊ - export declare function threadsafeFunctionClosureCapture(defaultValue: Animal, func: (arg: Animal) => void): void␊ - ␊ - export declare function threadsafeFunctionFatalMode(cb: ((arg: boolean) => unknown)): void␊ - ␊ - export declare function threadsafeFunctionFatalModeError(cb: ((arg: boolean) => string)): void␊ - ␊ - export declare function threadsafeFunctionThrowError(cb: ((err: Error | null, arg: boolean) => unknown)): void␊ - ␊ - export declare function threadsafeFunctionThrowErrorWithStatus(cb: ((err: Error | null, arg: boolean) => unknown)): void␊ - ␊ - export declare function throwAsyncError(): Promise␊ - ␊ - export declare function throwError(): void␊ - ␊ - export declare function throwErrorWithCause(): void␊ - ␊ - export declare function throwSyntaxError(error: string, code?: string | undefined | null): void␊ - ␊ - export declare function toJsObj(): object␊ - ␊ - export declare function tsfnAsyncCall(func: (arg0: number, arg1: number, arg2: number) => string): Promise␊ - ␊ - export declare function tsfnCallWithCallback(tsfn: ((err: Error | null, ) => string)): void␊ - ␊ - export declare function tsfnInEither(pet: Pet): void␊ - ␊ - export declare function tsfnReturnPromise(func: ((err: Error | null, arg: number) => Promise)): Promise␊ - ␊ - export declare function tsfnReturnPromiseTimeout(func: ((err: Error | null, arg: number) => Promise)): Promise␊ - ␊ - export declare function tsfnThrowFromJs(tsfn: ((err: Error | null, arg: number) => Promise)): Promise␊ - ␊ - export declare function tsfnThrowFromJsCallbackContainsTsfn(tsfn: ((err: Error | null, arg: number) => Promise)): Promise␊ - ␊ - export declare function tsfnWeak(tsfn: (() => void)): Promise␊ - ␊ - export declare function tsRename(a: { foo: number }): string[]␊ - ␊ - export interface TsTypeChanged {␊ - typeOverride: object␊ - typeOverrideOptional?: object␊ - }␊ - ␊ - export interface TupleObject {␊ - customField: number␊ - field1: number␊ - }␊ - ␊ - export type TupleToArray =␊ - [field0: string, field1: number, field2?: Meta]␊ - ␊ - export declare function u16ArrayToArray(input: Uint16Array): Array␊ - ␊ - export declare function u32ArrayToArray(input: Uint32Array): Array␊ - ␊ - export declare function u64ArrayToArray(input: BigUint64Array): Array␊ - ␊ - export declare function u8ArrayToArray(input: Uint8Array): Array␊ - ␊ - export declare function uInit8ArrayFromString(): Promise␊ - ␊ - export declare function uint8ArrayFromData(): Uint8Array␊ - ␊ - export declare function uint8ArrayFromExternal(): Uint8Array␊ - ␊ - export interface UseNullableStruct {␊ - requiredNumberField: number␊ - requiredStringField: string␊ - nullableNumberField: number | null␊ - nullableStringField: string | null␊ - }␊ - ␊ - export interface UtcDates {␊ - start: Date␊ - end?: Date␊ - }␊ - ␊ - export declare function validateArray(arr: Array): number␊ - ␊ - export declare function validateBigint(input: bigint): bigint␊ - ␊ - export declare function validateBoolean(i: boolean): boolean␊ - ␊ - export declare function validateBuffer(b: Buffer): number␊ - ␊ - export declare function validateBufferSlice(input: Buffer): number␊ - ␊ - export declare function validateDate(d: Date): number␊ - ␊ - export declare function validateDateTime(d: Date): number␊ - ␊ - export declare function validateEnum(input: KindInValidate): number␊ - ␊ - export declare function validateExternal(e: ExternalObject): number␊ - ␊ - export declare function validateFunction(cb: () => number): number␊ - ␊ - export declare function validateHashMap(input: Record): number␊ - ␊ - export declare function validateNull(i: null): boolean␊ - ␊ - export declare function validateNumber(i: number): number␊ - ␊ - export declare function validateOptional(input1?: string | undefined | null, input2?: boolean | undefined | null): boolean␊ - ␊ - export declare function validatePromise(p: Promise): Promise␊ - ␊ - export declare function validateString(s: string): string␊ - ␊ - export declare function validateStringEnum(input: StatusInValidate): string␊ - ␊ - export declare function validateStructuredEnum(kind: StructuredKind): StructuredKind␊ - ␊ - export declare function validateStructuredEnumLowercase(kind: StructuredKindLowercase): StructuredKindLowercase␊ - ␊ - export declare function validateSymbol(s: symbol): boolean␊ - ␊ - export declare function validateTypedArray(input: Uint8Array): number␊ - ␊ - export declare function validateTypedArraySlice(input: Uint8Array): number␊ - ␊ - export declare function validateUint8ClampedSlice(input: Uint8ClampedArray): number␊ - ␊ - export declare function validateUndefined(i: undefined): boolean␊ - ␊ - export interface ViteImportGlobMeta {␊ - isSubImportsPattern?: boolean␊ - }␊ - ␊ - export type VoidNullable =␊ - Nullable␊ - ␊ - export declare function withAbortController(a: number, b: number, signal: AbortSignal): Promise␊ - ␊ - export declare function withAbortSignalHandle(signal: AbortSignal): Promise␊ - ␊ - export declare function withinAsyncRuntimeIfAvailable(): void␊ - ␊ - export declare function withoutAbortController(a: number, b: number): Promise␊ - ␊ - export declare function xxh64Alias(input: Buffer): bigint␊ - ␊ - export declare namespace xxh2 {␊ - export function xxh2Plus(a: number, b: number): number␊ - export function xxh3Xxh64Alias(input: Buffer): bigint␊ - }␊ - ␊ - export declare namespace xxh3 {␊ - /** Xxh3 class */␊ - export class Xxh3 {␊ - constructor()␊ - /** update */␊ - update(input: Buffer): void␊ - digest(): bigint␊ - }␊ - export const ALIGNMENT: number␊ - /** xxh128 function */␊ - export function xxh128(input: Buffer): bigint␊ - export function xxh3_64(input: Buffer): bigint␊ - }␊ - export declare class ComplexClass {␊ - value: string␊ - number: number␊ - constructor(value: string | ComplexClass, number: number)␊ - methodOne(): string␊ - methodTwo(): number␊ - methodThree(): string␊ - methodFour(): boolean␊ - methodFive(): string␊ - }␊ - ␊ - export interface Shared {␊ - value: number␊ - }␊ - ` diff --git a/examples/napi/__tests__/__snapshots__/values.spec.ts.snap b/examples/napi/__tests__/__snapshots__/values.spec.ts.snap deleted file mode 100644 index 893882e6..00000000 Binary files a/examples/napi/__tests__/__snapshots__/values.spec.ts.snap and /dev/null differ diff --git a/examples/napi/__tests__/values.spec.ts b/examples/napi/__tests__/values.spec.ts index 8e0fa505..d135d42e 100644 --- a/examples/napi/__tests__/values.spec.ts +++ b/examples/napi/__tests__/values.spec.ts @@ -209,6 +209,7 @@ import { chronoNativeDateTime, chronoNativeDateTimeReturn, throwAsyncError, + asyncFailInToNapiValue, getModuleFileName, throwSyntaxError, type AliasedStruct, @@ -1009,6 +1010,39 @@ test('Async error with stack trace', async (t) => { } }) +test('Async error from to_napi_value properly rejects promise', async (t) => { + // Test that errors from ToNapiValue::to_napi_value in async functions + // properly reject the promise instead of throwing synchronously + + // Test with .catch() + const err1 = await t.throwsAsync(() => asyncFailInToNapiValue()) + t.deepEqual(err1!.message, 'Fail in to_napi_value') + t.deepEqual(err1!.code, 'GenericFailure') + + // Test with .then(success, error) - using proper Promise API + const promise2 = asyncFailInToNapiValue() + await new Promise((resolve) => { + promise2.then( + () => { + t.fail('Promise should have been rejected') + resolve() + }, + (error) => { + t.deepEqual(error.message, 'Fail in to_napi_value') + resolve() + }, + ) + }) + + // Test with async/await + try-catch + try { + await asyncFailInToNapiValue() + t.fail('Should have thrown an error') + } catch (error: any) { + t.deepEqual(error.message, 'Fail in to_napi_value') + } +}) + test('custom status code in Error', (t) => { t.throws(() => customStatusCode(), { code: 'Panic',