mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-10-24 20:45:04 +00:00
Move to @pezkuwi/dev 0.86 (eslint 10 toolchain)
- @pezkuwi/dev, dev-test, dev-ts ^0.86.3; disable directives renamed for the new rule names, or removed where the rule no longer reports - rethrown errors carry the original as `cause` (13 sites) - optional chains where a guard expression tested the same value - Init: the registry cache settles with the creator's own promise, dropping the entry in finally(), instead of re-wrapping it - Combinator: a typed call instead of `Function` - checkTypes.manual: synchronous checks run outside Promise.all - sortValues, createTypeUnsafe: initial values that were never read - typegen util: load docs.js for its side effect (it registers the `docs` Handlebars partial) now that its types are re-exported type-only - MockProvider keeps its Header assertion: the package's own build does not load api-augment, so createType returns a plain Codec there - Decorate keeps `delete queue[i]`: the hole marks a fired queue and later indexes must not shift
This commit is contained in:
1 parent
8c9af013b5
commit
60e0f73ffa
166 files changed
+2757
-3731
No files matched your search
@@ -139,7 +139,6 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public override eq (other?: unknown): boolean {
|
||||
// Here we are actually overriding the built-in .eq to take care of both
|
||||
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('Compact', (): void => {
|
||||
|
||||
describe('constructor', (): void => {
|
||||
it('fails on > MAX_SAFE_INTEGER', (): void => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision, no-loss-of-precision
|
||||
// eslint-disable-next-line no-loss-of-precision
|
||||
expect(() => new Compact(registry, 'u128', 9007199254740999)).toThrow(/integer <= Number.MAX_SAFE_INTEGER/);
|
||||
});
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
|
||||
let definition: CodecClass<O> | undefined;
|
||||
|
||||
// eslint-disable-next-line no-return-assign
|
||||
const setDefinition = <T> (d: CodecClass<T>) =>
|
||||
(definition = d as unknown as CodecClass<O>) as unknown as CodecClass<T>;
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ function decodeFromJSON (registry: Registry, def: TypesDef, key: string, value?:
|
||||
try {
|
||||
return createFromValue(registry, def, Object.values(def)[index].index, value);
|
||||
} catch (error) {
|
||||
throw new Error(`Enum(${key}):: ${(error as Error).message}`);
|
||||
throw new Error(`Enum(${key}):: ${(error as Error).message}`, { cause: error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTup
|
||||
? entry
|
||||
: new Types[i](registry, entry);
|
||||
} catch (error) {
|
||||
throw new Error(`Tuple: failed on ${i}:: ${(error as Error).message}`);
|
||||
throw new Error(`Tuple: failed on ${i}:: ${(error as Error).message}`, { cause: error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ describe('UInt', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('fails on > MAX_SAFE_INTEGER and float', (): void => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision, no-loss-of-precision
|
||||
// eslint-disable-next-line no-loss-of-precision
|
||||
expect(() => new UInt(registry, 9007199254740999)).toThrow(/integer <= Number.MAX_SAFE_INTEGER/);
|
||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision, no-loss-of-precision
|
||||
// eslint-disable-next-line no-loss-of-precision
|
||||
expect(() => new UInt(registry, -9007199254740999)).toThrow(/integer <= Number.MAX_SAFE_INTEGER/);
|
||||
expect(() => new UInt(registry, 9.123)).toThrow(/integer <= Number.MAX_SAFE_INTEGER/);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,6 @@ export function decodeVec<T extends Codec> (registry: Registry, result: T[], val
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 26/08/2022 this is actually a false positive - after recent eslint upgdates
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const entry = value[i];
|
||||
|
||||
try {
|
||||
@@ -88,7 +87,6 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Vec<O>> {
|
||||
let definition: CodecClass<O> | undefined;
|
||||
|
||||
// eslint-disable-next-line no-return-assign
|
||||
const setDefinition = <T> (d: CodecClass<T>) =>
|
||||
(definition = d as unknown as CodecClass<O>) as unknown as CodecClass<T>;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
public static with<O extends Codec> (Type: CodecClass<O> | string, length: number): CodecClass<VecFixed<O>> {
|
||||
let definition: CodecClass<O> | undefined;
|
||||
|
||||
// eslint-disable-next-line no-return-assign
|
||||
const setDefinition = <T> (d: CodecClass<T>) =>
|
||||
(definition = d as unknown as CodecClass<O>) as unknown as CodecClass<T>;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ function decodeSetFromU8a<V extends Codec> (registry: Registry, ValClass: CodecC
|
||||
const [decodedLength] = decodeU8aVec(registry, result, u8a, offset, ValClass);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
output.add(result[i] as unknown as V);
|
||||
output.add(result[i]);
|
||||
}
|
||||
|
||||
return [ValClass, output, decodedLength];
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('Type', (): void => {
|
||||
registry,
|
||||
new Text(registry, ' Box<Proposal> ')
|
||||
).toString()
|
||||
).toEqual('Proposal'); // eslint-disable-line
|
||||
).toEqual('Proposal');
|
||||
});
|
||||
|
||||
it('unwraps compact', (): void => {
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('Bool', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
describe('decode', (): void => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
const testDecode = (type: string, input: Uint8Array | boolean | Boolean | Bool | number, expected: boolean): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
expect(new Bool(registry, input).toJSON()).toBe(expected);
|
||||
|
||||
@@ -198,9 +198,7 @@ describe('Struct', (): void => {
|
||||
})
|
||||
)(registry, { txt: 'foo', u32: 0x123456 });
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect((struct as any).txt.toString()).toEqual('foo');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect((struct as any).u32.toNumber()).toEqual(0x123456);
|
||||
});
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
|
||||
// ignore
|
||||
}
|
||||
|
||||
throw new Error(`Struct: failed on ${jsonKey}: ${type}:: ${(error as Error).message}`);
|
||||
throw new Error(`Struct: failed on ${jsonKey}: ${type}:: ${(error as Error).message}`, { cause: error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import { formatDecimal, formatNumber } from '@pezkuwi/util';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type ExecFn = (...params: any[]) => unknown;
|
||||
|
||||
const NUM_PAD = 16;
|
||||
|
||||
@@ -11,13 +11,13 @@ export type AnyFunction = (...args: any[]) => any;
|
||||
|
||||
export type AnyNumber = BN | bigint | Uint8Array | number | string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
export type AnyFloat = Number | number | Uint8Array | string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
export type AnyString = String | string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
export type AnyBool = Boolean | boolean;
|
||||
|
||||
export type AnyTuple = Codec[];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2026 @pezkuwi/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './codec.js';
|
||||
export * from './helpers.js';
|
||||
export * from './interfaces.js';
|
||||
export * from './registry.js';
|
||||
export type * from './codec.js';
|
||||
export type * from './helpers.js';
|
||||
export type * from './interfaces.js';
|
||||
export type * from './registry.js';
|
||||
@@ -66,7 +66,7 @@ export interface IStruct<K = string, V extends Codec = Codec> extends Map<K, V>,
|
||||
toArray (): Codec[];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
export interface IText extends String, Codec {
|
||||
// nothing additional
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export function decodeU8a <T extends Codec = Codec> (registry: Registry, result:
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, 'decodeU8a', result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||
throw new Error(formatFailure(registry, 'decodeU8a', result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]), { cause: error });
|
||||
}
|
||||
|
||||
return [result, offset];
|
||||
@@ -85,7 +85,7 @@ export function decodeU8aStruct (registry: Registry, result: [string, Codec][],
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, 'decodeU8aStruct', result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||
throw new Error(formatFailure(registry, 'decodeU8aStruct', result, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]), { cause: error });
|
||||
}
|
||||
|
||||
return [result, offset];
|
||||
@@ -116,7 +116,7 @@ export function decodeU8aVec <T extends Codec = Codec> (registry: Registry, resu
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, 'decodeU8aVec', result, error as Error, u8a.subarray(offset), i, count, Type));
|
||||
throw new Error(formatFailure(registry, 'decodeU8aVec', result, error as Error, u8a.subarray(offset), i, count, Type), { cause: error });
|
||||
}
|
||||
|
||||
return [offset, offset - startAt];
|
||||
|
||||
@@ -34,11 +34,10 @@ function isNumberLike (arg: SortArg): arg is BN | bigint | number {
|
||||
/** @internal */
|
||||
function sortArray (a: Uint8Array | Codec[] | number[], b: Uint8Array | Codec[] | number[]): number {
|
||||
// Vec, Tuple, Bytes etc.
|
||||
let sortRes = 0;
|
||||
const minLen = Math.min(a.length, b.length);
|
||||
|
||||
for (let i = 0; i < minLen; ++i) {
|
||||
sortRes = sortAsc(a[i], b[i]);
|
||||
const sortRes = sortAsc(a[i], b[i]);
|
||||
|
||||
if (sortRes !== 0) {
|
||||
return sortRes;
|
||||
|
||||
Reference in new issue
Block a user