@polkadot/types-create 8.5.1 → 8.5.2-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,7 +116,10 @@ const infoMapping = {
116
116
  },
117
117
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
118
118
  [_types.TypeDefInfo.Null]: (registry, _) => _typesCodec.Null,
119
- [_types.TypeDefInfo.Option]: (registry, value) => createWithSub(_typesCodec.Option, value),
119
+ [_types.TypeDefInfo.Option]: (registry, value) => {
120
+ (0, _util.assert)(value.sub && !Array.isArray(value.sub), 'Expected type information for Option');
121
+ return value.sub.type === 'bool' ? _typesCodec.OptionBool : createWithSub(_typesCodec.Option, value);
122
+ },
120
123
  [_types.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
121
124
  [_types.TypeDefInfo.Range]: (registry, value) => createWithSub(_typesCodec.Range, value),
122
125
  [_types.TypeDefInfo.RangeInclusive]: (registry, value) => createWithSub(_typesCodec.RangeInclusive, value),
@@ -183,5 +186,8 @@ function getTypeClass(registry, typeDef) {
183
186
  }
184
187
 
185
188
  function createClassUnsafe(registry, type) {
186
- return getTypeClass(registry, registry.isLookupType(type) ? registry.lookup.getTypeDef(type) : (0, _getTypeDef.getTypeDef)(type));
189
+ return (// just retrieve via name, no creation via typeDef
190
+ registry.getUnsafe(type) || // we don't have an existing type, create the class via typeDef
191
+ getTypeClass(registry, registry.isLookupType(type) ? registry.lookup.getTypeDef(type) : (0, _getTypeDef.getTypeDef)(type))
192
+ );
187
193
  }
@@ -27,14 +27,11 @@ function checkInstance(created, matcher) {
27
27
 
28
28
  function checkPedantic(created, _ref) {
29
29
  let [value] = _ref;
30
- let isPedantic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
31
30
 
32
- if (isPedantic) {
33
- if ((0, _util.isU8a)(value)) {
34
- checkInstance(created, value);
35
- } else if ((0, _util.isHex)(value)) {
36
- checkInstance(created, (0, _util.u8aToU8a)(value));
37
- }
31
+ if ((0, _util.isU8a)(value)) {
32
+ checkInstance(created, value);
33
+ } else if ((0, _util.isHex)(value)) {
34
+ checkInstance(created, (0, _util.u8aToU8a)(value));
38
35
  }
39
36
  } // Initializes a type with a value. This also checks for fallbacks and in the cases
40
37
  // where isPedantic is specified (storage decoding), also check the format/structure
@@ -48,7 +45,7 @@ function initType(registry, Type) {
48
45
  isPedantic
49
46
  } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
50
47
  const created = new (isOptional ? _typesCodec.Option.with(Type) : Type)(registry, ...params);
51
- checkPedantic(created, params, isPedantic);
48
+ isPedantic && checkPedantic(created, params);
52
49
 
53
50
  if (blockHash) {
54
51
  created.createdAtHash = createTypeUnsafe(registry, 'Hash', [blockHash]);
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/types-create',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '8.5.1'
14
+ version: '8.5.2-10'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
package/create/class.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-create authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@polkadot/types-codec';
3
+ import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, OptionBool, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@polkadot/types-codec';
4
4
  import { assert, isNumber, stringify } from '@polkadot/util';
5
5
  import { TypeDefInfo } from "../types/index.js";
6
6
  import { getTypeDef } from "../util/getTypeDef.js";
@@ -97,7 +97,10 @@ const infoMapping = {
97
97
  },
98
98
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
99
99
  [TypeDefInfo.Null]: (registry, _) => Null,
100
- [TypeDefInfo.Option]: (registry, value) => createWithSub(Option, value),
100
+ [TypeDefInfo.Option]: (registry, value) => {
101
+ assert(value.sub && !Array.isArray(value.sub), 'Expected type information for Option');
102
+ return value.sub.type === 'bool' ? OptionBool : createWithSub(Option, value);
103
+ },
101
104
  [TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
102
105
  [TypeDefInfo.Range]: (registry, value) => createWithSub(Range, value),
103
106
  [TypeDefInfo.RangeInclusive]: (registry, value) => createWithSub(RangeInclusive, value),
@@ -158,5 +161,8 @@ export function getTypeClass(registry, typeDef) {
158
161
  return registry.getUnsafe(typeDef.type, false, typeDef);
159
162
  }
160
163
  export function createClassUnsafe(registry, type) {
161
- return getTypeClass(registry, registry.isLookupType(type) ? registry.lookup.getTypeDef(type) : getTypeDef(type));
164
+ return (// just retrieve via name, no creation via typeDef
165
+ registry.getUnsafe(type) || // we don't have an existing type, create the class via typeDef
166
+ getTypeClass(registry, registry.isLookupType(type) ? registry.lookup.getTypeDef(type) : getTypeDef(type))
167
+ );
162
168
  }
package/create/type.js CHANGED
@@ -15,13 +15,11 @@ function checkInstance(created, matcher) {
15
15
  assert(isOk, () => `${rawType}:: Decoded input doesn't match input, received ${u8aToHex(matcher, 512)} (${matcher.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`);
16
16
  }
17
17
 
18
- function checkPedantic(created, [value], isPedantic = false) {
19
- if (isPedantic) {
20
- if (isU8a(value)) {
21
- checkInstance(created, value);
22
- } else if (isHex(value)) {
23
- checkInstance(created, u8aToU8a(value));
24
- }
18
+ function checkPedantic(created, [value]) {
19
+ if (isU8a(value)) {
20
+ checkInstance(created, value);
21
+ } else if (isHex(value)) {
22
+ checkInstance(created, u8aToU8a(value));
25
23
  }
26
24
  } // Initializes a type with a value. This also checks for fallbacks and in the cases
27
25
  // where isPedantic is specified (storage decoding), also check the format/structure
@@ -33,7 +31,7 @@ function initType(registry, Type, params = [], {
33
31
  isPedantic
34
32
  } = {}) {
35
33
  const created = new (isOptional ? Option.with(Type) : Type)(registry, ...params);
36
- checkPedantic(created, params, isPedantic);
34
+ isPedantic && checkPedantic(created, params);
37
35
 
38
36
  if (blockHash) {
39
37
  created.createdAtHash = createTypeUnsafe(registry, 'Hash', [blockHash]);
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.5.1",
23
+ "version": "8.5.2-10",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
@@ -121,7 +121,7 @@
121
121
  },
122
122
  "dependencies": {
123
123
  "@babel/runtime": "^7.18.0",
124
- "@polkadot/types-codec": "8.5.1",
125
- "@polkadot/util": "^9.2.1"
124
+ "@polkadot/types-codec": "8.5.2-10",
125
+ "@polkadot/util": "^9.2.2-15"
126
126
  }
127
127
  }
package/packageInfo.js CHANGED
@@ -5,5 +5,5 @@ export const packageInfo = {
5
5
  name: '@polkadot/types-create',
6
6
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
7
  type: 'esm',
8
- version: '8.5.1'
8
+ version: '8.5.2-10'
9
9
  };