@polkadot/types-codec
Advanced tools
Comparing version 10.11.2 to 10.11.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
require("./detectPackage.js"); | ||
require("./packageDetect.js"); | ||
tslib_1.__exportStar(require("./bundle.js"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packageInfo = void 0; | ||
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.11.2' }; | ||
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.11.3' }; |
@@ -13,2 +13,6 @@ "use strict"; | ||
} | ||
/** @internal **/ | ||
function isOption(arg) { | ||
return (0, util_1.isCodec)(arg) && (0, util_1.isBoolean)(arg.isSome) && (0, util_1.isCodec)(arg.value); | ||
} | ||
/** @internal */ | ||
@@ -31,2 +35,16 @@ function isNumberLike(arg) { | ||
} | ||
/** @internal */ | ||
function checkForDuplicates(container, seen, arg) { | ||
// Convert the value to hex. | ||
if ((0, util_1.isCodec)(arg)) { | ||
const hex = arg.toHex(); | ||
// Check if we have seen the value. | ||
if (seen.has(hex)) { | ||
// Duplicates are not allowed. | ||
throw new Error(`Duplicate value in ${container}: ${(0, util_1.stringify)(arg)}`); | ||
} | ||
seen.add(hex); | ||
} | ||
return true; | ||
} | ||
/** | ||
@@ -47,2 +65,5 @@ * Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap | ||
} | ||
else if (isOption(a) && isOption(b)) { | ||
return sortAsc(a.isNone ? 0 : 1, b.isNone ? 0 : 1) || sortAsc(a.value, b.value); | ||
} | ||
else if (isArrayLike(a) && isArrayLike(b)) { | ||
@@ -59,8 +80,10 @@ return sortArray(a, b); | ||
function sortSet(set) { | ||
return new Set(Array.from(set).sort(sortAsc)); | ||
const seen = new Set(); | ||
return new Set(Array.from(set).filter((value) => checkForDuplicates('BTreeSet', seen, value)).sort(sortAsc)); | ||
} | ||
exports.sortSet = sortSet; | ||
function sortMap(map) { | ||
return new Map(Array.from(map.entries()).sort(([keyA], [keyB]) => sortAsc(keyA, keyB))); | ||
const seen = new Set(); | ||
return new Map(Array.from(map.entries()).filter(([key]) => checkForDuplicates('BTreeMap', seen, key)).sort(([keyA], [keyB]) => sortAsc(keyA, keyB))); | ||
} | ||
exports.sortMap = sortMap; |
@@ -1,2 +0,2 @@ | ||
import './detectPackage.js'; | ||
import './packageDetect.js'; | ||
export * from './bundle.js'; |
@@ -1,2 +0,2 @@ | ||
import './detectPackage.js'; | ||
import './packageDetect.js'; | ||
export * from './bundle.js'; |
@@ -17,7 +17,7 @@ { | ||
"sideEffects": [ | ||
"./detectPackage.js", | ||
"./cjs/detectPackage.js" | ||
"./packageDetect.js", | ||
"./cjs/packageDetect.js" | ||
], | ||
"type": "module", | ||
"version": "10.11.2", | ||
"version": "10.11.3", | ||
"main": "./cjs/index.js", | ||
@@ -149,14 +149,2 @@ "module": "./index.js", | ||
}, | ||
"./detectOther": { | ||
"types": "./detectOther.d.ts", | ||
"module": "./detectOther.js", | ||
"require": "./cjs/detectOther.js", | ||
"default": "./detectOther.js" | ||
}, | ||
"./detectPackage": { | ||
"types": "./detectPackage.d.ts", | ||
"module": "./detectPackage.js", | ||
"require": "./cjs/detectPackage.js", | ||
"default": "./detectPackage.js" | ||
}, | ||
"./extended": { | ||
@@ -315,2 +303,8 @@ "types": "./extended/index.d.ts", | ||
}, | ||
"./packageDetect": { | ||
"types": "./packageDetect.d.ts", | ||
"module": "./packageDetect.js", | ||
"require": "./cjs/packageDetect.js", | ||
"default": "./packageDetect.js" | ||
}, | ||
"./packageInfo.js": { | ||
@@ -317,0 +311,0 @@ "types": "./packageInfo.d.ts", |
@@ -1,1 +0,1 @@ | ||
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.11.2' }; | ||
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.11.3' }; |
@@ -1,2 +0,2 @@ | ||
import { bnToBn, isBigInt, isBn, isCodec, isNumber, stringify } from '@polkadot/util'; | ||
import { bnToBn, isBigInt, isBn, isBoolean, isCodec, isNumber, stringify } from '@polkadot/util'; | ||
/** @internal **/ | ||
@@ -10,2 +10,6 @@ function isArrayLike(arg) { | ||
} | ||
/** @internal **/ | ||
function isOption(arg) { | ||
return isCodec(arg) && isBoolean(arg.isSome) && isCodec(arg.value); | ||
} | ||
/** @internal */ | ||
@@ -28,2 +32,16 @@ function isNumberLike(arg) { | ||
} | ||
/** @internal */ | ||
function checkForDuplicates(container, seen, arg) { | ||
// Convert the value to hex. | ||
if (isCodec(arg)) { | ||
const hex = arg.toHex(); | ||
// Check if we have seen the value. | ||
if (seen.has(hex)) { | ||
// Duplicates are not allowed. | ||
throw new Error(`Duplicate value in ${container}: ${stringify(arg)}`); | ||
} | ||
seen.add(hex); | ||
} | ||
return true; | ||
} | ||
/** | ||
@@ -44,2 +62,5 @@ * Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap | ||
} | ||
else if (isOption(a) && isOption(b)) { | ||
return sortAsc(a.isNone ? 0 : 1, b.isNone ? 0 : 1) || sortAsc(a.value, b.value); | ||
} | ||
else if (isArrayLike(a) && isArrayLike(b)) { | ||
@@ -55,6 +76,8 @@ return sortArray(a, b); | ||
export function sortSet(set) { | ||
return new Set(Array.from(set).sort(sortAsc)); | ||
const seen = new Set(); | ||
return new Set(Array.from(set).filter((value) => checkForDuplicates('BTreeSet', seen, value)).sort(sortAsc)); | ||
} | ||
export function sortMap(map) { | ||
return new Map(Array.from(map.entries()).sort(([keyA], [keyB]) => sortAsc(keyA, keyB))); | ||
const seen = new Set(); | ||
return new Map(Array.from(map.entries()).filter(([key]) => checkForDuplicates('BTreeMap', seen, key)).sort(([keyA], [keyB]) => sortAsc(keyA, keyB))); | ||
} |
649500
13362
240