Skip to content

Commit

Permalink
12.1.1 (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr authored Apr 29, 2023
1 parent 6b1ff00 commit 770471a
Show file tree
Hide file tree
Showing 30 changed files with 141 additions and 150 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# CHANGELOG

## master
## 12.1.1 Apr 29, 2023

Changes:

- Add shareable `identity` & `noop` functions
- Flatten `Buffer | Uint8Array` types (as used) to base-only `Uint8Array`
- Apply `readonly` specifiers to private class fields where applicable
- Adjust compilation output for `__internal__` class fields
- Remove unused types from `util`
- Upgrade dependencies to latest stable versions


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"versions": {
"git": "12.0.2-2-x",
"npm": "12.0.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/hw-ledger-transports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@ledgerhq/hw-transport": "^6.28.2",
"@ledgerhq/hw-transport-webhid": "^6.27.13",
"@ledgerhq/hw-transport-webusb": "^6.27.13",
"@polkadot/util": "12.0.2-2-x",
"@polkadot/util": "12.1.0",
"tslib": "^2.5.0"
},
"optionalDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/hw-ledger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"main": "index.js",
"dependencies": {
"@polkadot/hw-ledger-transports": "12.0.2-2-x",
"@polkadot/util": "12.0.2-2-x",
"@polkadot/hw-ledger-transports": "12.1.0",
"@polkadot/util": "12.1.0",
"@zondax/ledger-substrate": "^0.40.7",
"tslib": "^2.5.0"
}
Expand Down
10 changes: 5 additions & 5 deletions packages/keyring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"main": "index.js",
"dependencies": {
"@polkadot/util": "12.0.2-2-x",
"@polkadot/util-crypto": "12.0.2-2-x",
"@polkadot/util": "12.1.0",
"@polkadot/util-crypto": "12.1.0",
"tslib": "^2.5.0"
},
"peerDependencies": {
"@polkadot/util": "12.0.2-2-x",
"@polkadot/util-crypto": "12.0.2-2-x"
"@polkadot/util": "12.1.0",
"@polkadot/util-crypto": "12.1.0"
}
}
6 changes: 3 additions & 3 deletions packages/networks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"main": "index.js",
"dependencies": {
"@polkadot/util": "12.0.2-2-x",
"@polkadot/util": "12.1.0",
"@substrate/ss58-registry": "^1.40.0",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/hw-ledger": "12.0.2-2-x"
"@polkadot/hw-ledger": "12.1.0"
}
}
12 changes: 6 additions & 6 deletions packages/util-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"browser": {
"crypto": false,
"stream": false
Expand All @@ -29,16 +29,16 @@
"dependencies": {
"@noble/curves": "1.0.0",
"@noble/hashes": "1.3.0",
"@polkadot/networks": "12.0.2-2-x",
"@polkadot/util": "12.0.2-2-x",
"@polkadot/networks": "12.1.0",
"@polkadot/util": "12.1.0",
"@polkadot/wasm-crypto": "^7.1.2",
"@polkadot/wasm-util": "^7.1.2",
"@polkadot/x-bigint": "12.0.2-2-x",
"@polkadot/x-randomvalues": "12.0.2-2-x",
"@polkadot/x-bigint": "12.1.0",
"@polkadot/x-randomvalues": "12.1.0",
"@scure/base": "1.1.1",
"tslib": "^2.5.0"
},
"peerDependencies": {
"@polkadot/util": "12.0.2-2-x"
"@polkadot/util": "12.1.0"
}
}
12 changes: 6 additions & 6 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.2-2-x",
"version": "12.1.0",
"main": "index.js",
"exports": {
"./hex/toU8a": {
Expand All @@ -35,15 +35,15 @@
}
},
"dependencies": {
"@polkadot/x-bigint": "12.0.2-2-x",
"@polkadot/x-global": "12.0.2-2-x",
"@polkadot/x-textdecoder": "12.0.2-2-x",
"@polkadot/x-textencoder": "12.0.2-2-x",
"@polkadot/x-bigint": "12.1.0",
"@polkadot/x-global": "12.1.0",
"@polkadot/x-textdecoder": "12.1.0",
"@polkadot/x-textencoder": "12.1.0",
"@types/bn.js": "^5.1.1",
"bn.js": "^5.2.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/x-randomvalues": "12.0.2-2-x"
"@polkadot/x-randomvalues": "12.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/util/src/array/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
export function arrayChunk <T> (array: T[], chunkSize: number): T[][] {
const outputSize = Math.ceil(array.length / chunkSize);

// noop for the single-split case
// shortcut for the single-split case
if (outputSize === 1) {
return [array];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/array/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* ```
*/
export function arrayFlatten <T> (arrays: readonly T[][]): T[] {
// noop for the empty & single-entry case
// shortcuts for the empty & single-entry case
if (arrays.length === 0) {
return [];
} else if (arrays.length === 1) {
Expand Down
7 changes: 4 additions & 3 deletions packages/util/src/array/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* @description Splits a single [K, V][] into [K[], V[]]
*/
export function arrayUnzip <K, V> (entries: readonly [K, V][]): [K[], V[]] {
const keys = new Array<K>(entries.length);
const values = new Array<V>(entries.length);
const count = entries.length;
const keys = new Array<K>(count);
const values = new Array<V>(count);

for (let i = 0; i < entries.length; i++) {
for (let i = 0; i < count; i++) {
[keys[i], values[i]] = entries[i];
}

Expand Down
5 changes: 3 additions & 2 deletions packages/util/src/array/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export function arrayZip <K, V> (keys: readonly K[], values: readonly V[]): [K, V][] {
const result = new Array<[K, V]>(keys.length);
const count = keys.length;
const result = new Array<[K, V]>(count);

for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
result[i] = [keys[i], values[i]];
}

Expand Down
1 change: 1 addition & 0 deletions packages/util/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export * from './lazy.js';
export * from './logger.js';
export * from './memoize.js';
export * from './nextTick.js';
export * from './noop.js';
export * from './number/index.js';
export * from './object/index.js';
export * from './promisify.js';
Expand Down
23 changes: 10 additions & 13 deletions packages/util/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Logger, Logger$Data } from './types.js';
import type { Logger } from './types.js';

import { xglobal } from '@polkadot/x-global';

Expand All @@ -14,6 +14,7 @@ import { isU8a } from './is/u8a.js';
import { u8aToHex } from './u8a/toHex.js';
import { u8aToU8a } from './u8a/toU8a.js';
import { hasProcess } from './has.js';
import { noop } from './noop.js';

type ConsoleType = 'error' | 'log' | 'warn';
type LogType = ConsoleType | 'debug';
Expand Down Expand Up @@ -65,7 +66,7 @@ function formatWithLength (maxLength: number): (v: unknown) => unknown {
};
}

function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1): void {
function apply (log: LogType, type: string, values: unknown[], maxSize = -1): void {
if (values.length === 1 && isFunction(values[0])) {
const fnResult = values[0]() as unknown;

Expand All @@ -81,10 +82,6 @@ function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1):
);
}

function noop (): void {
// noop
}

function isDebugOn (e: string, type: string): boolean {
return !!e && (
e === '*' ||
Expand Down Expand Up @@ -149,17 +146,17 @@ function parseEnv (type: string): [boolean, number] {
* const l = logger('test');
* ```
*/
export function logger (_type: string): Logger {
const type = `${_type.toUpperCase()}:`.padStart(16);
const [isDebug, maxSize] = parseEnv(_type.toLowerCase());
export function logger (origin: string): Logger {
const type = `${origin.toUpperCase()}:`.padStart(16);
const [isDebug, maxSize] = parseEnv(origin.toLowerCase());

return {
debug: isDebug
? (...values: Logger$Data) => apply('debug', type, values, maxSize)
? (...values: unknown[]) => apply('debug', type, values, maxSize)
: noop,
error: (...values: Logger$Data) => apply('error', type, values),
log: (...values: Logger$Data) => apply('log', type, values),
error: (...values: unknown[]) => apply('error', type, values),
log: (...values: unknown[]) => apply('log', type, values),
noop,
warn: (...values: Logger$Data) => apply('warn', type, values)
warn: (...values: unknown[]) => apply('warn', type, values)
};
}
16 changes: 16 additions & 0 deletions packages/util/src/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0

/**
* A sharable identity function. Returns the input as-is with no transformation applied.
*/
export function identity <T> (value: T): T {
return value;
}

/**
* A sharable noop function. As the name suggests, does nothing
*/
export function noop (): void {
// noop
}
50 changes: 10 additions & 40 deletions packages/util/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

import type { BN } from './bn/bn.js';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface Constructor<T = any> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new(...value: any[]): T;
export interface Constructor<T extends object = object> {
prototype: T;
new (...args: never[]): T;

hasOwnProperty (prop: string): boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
isPrototypeOf (other: any): boolean;
isPrototypeOf (other: unknown): boolean;
}

export interface ToBigInt {
Expand All @@ -27,15 +25,12 @@ export interface SiDef {
value: string;
}

type Logger$Data$Fn = () => unknown[];
export type Logger$Data = (unknown | Logger$Data$Fn)[];

export interface Logger {
debug: (...values: Logger$Data) => void;
error: (...values: Logger$Data) => void;
log: (...values: Logger$Data) => void;
noop: (...values: Logger$Data) => void;
warn: (...values: Logger$Data) => void;
debug: (...values: unknown[]) => void;
error: (...values: unknown[]) => void;
log: (...values: unknown[]) => void;
noop: (...values: unknown[]) => void;
warn: (...values: unknown[]) => void;
}

export interface ToBnOptions {
Expand All @@ -56,11 +51,6 @@ export interface NumberOptions extends ToBnOptions {
bitLength?: number;
}

export type BnList = {
0: BN;
1: BN;
} & BN[];

export interface Time {
days: number;
hours: number;
Expand Down Expand Up @@ -90,32 +80,12 @@ export interface BufferObj extends Uint8Array {

// We define a scappy low-level interface to mock Buffer
// (this removes the need for the node typings in built bundles)
export interface BufferObjConstructor extends Function {
export interface BufferObjConstructor extends Constructor<BufferObj> {
isBuffer: (value: unknown) => boolean;
}

export type U8aLike = HexString | number[] | Uint8Array | AnyString;

export interface IBigIntConstructor {
new (value: string | number | bigint | boolean): bigint;

/**
* Interprets the low bits of a BigInt as a 2's-complement signed integer.
* All higher bits are discarded.
* @param bits The number of low bits to use
* @param int The BigInt whose bits to extract
*/
asIntN (bits: number, int: bigint): bigint;

/**
* Interprets the low bits of a BigInt as an unsigned integer.
* All higher bits are discarded.
* @param bits The number of low bits to use
* @param int The BigInt whose bits to extract
*/
asUintN (bits: number, int: bigint): bigint;
}

export interface Observable {
next: (...params: unknown[]) => unknown;
}
5 changes: 3 additions & 2 deletions packages/util/src/u8a/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import { u8aToU8a } from './toU8a.js';
* ```
*/
export function u8aConcat (...list: readonly U8aLike[]): Uint8Array {
const u8as = new Array<Uint8Array>(list.length);
const count = list.length;
const u8as = new Array<Uint8Array>(count);
let length = 0;

for (let i = 0; i < list.length; i++) {
for (let i = 0; i < count; i++) {
u8as[i] = u8aToU8a(list[i]);
length += u8as[i].length;
}
Expand Down
Loading

0 comments on commit 770471a

Please sign in to comment.