@polkadot/types-create 10.9.1 → 10.11.1

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.
@@ -27,7 +27,11 @@ function getTypeClassMap(value) {
27
27
  const subs = getSubDefArray(value);
28
28
  const map = {};
29
29
  for (let i = 0, count = subs.length; i < count; i++) {
30
- map[subs[i].name] = getTypeDefType(subs[i]);
30
+ const sub = subs[i];
31
+ if (!sub.name) {
32
+ throw new Error(`No name found in definition ${(0, util_1.stringify)(sub)}`);
33
+ }
34
+ map[sub.name] = getTypeDefType(sub);
31
35
  }
32
36
  return map;
33
37
  }
@@ -56,6 +60,9 @@ const infoMapping = {
56
60
  const subs = getSubDefArray(value);
57
61
  return types_codec_1.Enum.with(subs.every(({ type }) => type === 'Null')
58
62
  ? subs.reduce((out, { index, name }, count) => {
63
+ if (!name) {
64
+ throw new Error('No name found in sub definition');
65
+ }
59
66
  out[name] = index || count;
60
67
  return out;
61
68
  }, {})
@@ -95,6 +102,9 @@ const infoMapping = {
95
102
  return types_codec_1.Result.with({ Err, Ok });
96
103
  },
97
104
  [index_js_1.TypeDefInfo.Set]: (_registry, value) => types_codec_1.CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
105
+ if (!name || !(0, util_1.isNumber)(index)) {
106
+ throw new Error('No name found in sub definition');
107
+ }
98
108
  result[name] = index;
99
109
  return result;
100
110
  }, {}), value.length),
@@ -53,7 +53,7 @@ function createTypeUnsafe(registry, type, params = [], options = {}) {
53
53
  catch (error) {
54
54
  firstError = new Error(`createType(${type}):: ${error.message}`);
55
55
  }
56
- if (Clazz && Clazz.__fallbackType) {
56
+ if (Clazz?.__fallbackType) {
57
57
  try {
58
58
  Clazz = (0, class_js_1.createClassUnsafe)(registry, Clazz.__fallbackType);
59
59
  return initType(registry, Clazz, params, options);
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@polkadot/types-create', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.9.1' };
4
+ exports.packageInfo = { name: '@polkadot/types-create', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.11.1' };
@@ -26,4 +26,4 @@ var TypeDefInfo;
26
26
  TypeDefInfo[TypeDefInfo["VecFixed"] = 20] = "VecFixed";
27
27
  TypeDefInfo[TypeDefInfo["WrapperKeepOpaque"] = 21] = "WrapperKeepOpaque";
28
28
  TypeDefInfo[TypeDefInfo["WrapperOpaque"] = 22] = "WrapperOpaque";
29
- })(TypeDefInfo = exports.TypeDefInfo || (exports.TypeDefInfo = {}));
29
+ })(TypeDefInfo || (exports.TypeDefInfo = TypeDefInfo = {}));
@@ -38,6 +38,9 @@ function encodeSubTypes(registry, sub, asEnum, extra) {
38
38
  const inner = (0, util_1.objectSpread)({}, extra);
39
39
  for (let i = 0, count = sub.length; i < count; i++) {
40
40
  const def = sub[i];
41
+ if (!def.name) {
42
+ throw new Error(`No name found in ${(0, util_1.stringify)(def)}`);
43
+ }
41
44
  inner[def.name] = encodeTypeDef(registry, def);
42
45
  }
43
46
  return (0, util_1.stringify)(asEnum
@@ -9,7 +9,7 @@ const KNOWN_INTERNALS = ['_alias', '_fallback'];
9
9
  function getTypeString(typeOrObj) {
10
10
  return (0, util_1.isString)(typeOrObj)
11
11
  ? typeOrObj.toString()
12
- : JSON.stringify(typeOrObj);
12
+ : (0, util_1.stringify)(typeOrObj);
13
13
  }
14
14
  function isRustEnum(details) {
15
15
  const values = Object.values(details);
@@ -145,7 +145,7 @@ function _decodeDoNotConstruct(value, type, _) {
145
145
  return value;
146
146
  }
147
147
  function hasWrapper(type, [start, end]) {
148
- return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
148
+ return (type.startsWith(start)) && (type.slice(-1 * end.length) === end);
149
149
  }
150
150
  const nestedExtraction = [
151
151
  ['[', ']', index_js_1.TypeDefInfo.VecFixed, _decodeFixedVec],
package/create/class.js CHANGED
@@ -24,7 +24,11 @@ function getTypeClassMap(value) {
24
24
  const subs = getSubDefArray(value);
25
25
  const map = {};
26
26
  for (let i = 0, count = subs.length; i < count; i++) {
27
- map[subs[i].name] = getTypeDefType(subs[i]);
27
+ const sub = subs[i];
28
+ if (!sub.name) {
29
+ throw new Error(`No name found in definition ${stringify(sub)}`);
30
+ }
31
+ map[sub.name] = getTypeDefType(sub);
28
32
  }
29
33
  return map;
30
34
  }
@@ -53,6 +57,9 @@ const infoMapping = {
53
57
  const subs = getSubDefArray(value);
54
58
  return Enum.with(subs.every(({ type }) => type === 'Null')
55
59
  ? subs.reduce((out, { index, name }, count) => {
60
+ if (!name) {
61
+ throw new Error('No name found in sub definition');
62
+ }
56
63
  out[name] = index || count;
57
64
  return out;
58
65
  }, {})
@@ -92,6 +99,9 @@ const infoMapping = {
92
99
  return Result.with({ Err, Ok });
93
100
  },
94
101
  [TypeDefInfo.Set]: (_registry, value) => CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
102
+ if (!name || !isNumber(index)) {
103
+ throw new Error('No name found in sub definition');
104
+ }
95
105
  result[name] = index;
96
106
  return result;
97
107
  }, {}), value.length),
package/create/type.js CHANGED
@@ -50,7 +50,7 @@ export function createTypeUnsafe(registry, type, params = [], options = {}) {
50
50
  catch (error) {
51
51
  firstError = new Error(`createType(${type}):: ${error.message}`);
52
52
  }
53
- if (Clazz && Clazz.__fallbackType) {
53
+ if (Clazz?.__fallbackType) {
54
54
  try {
55
55
  Clazz = createClassUnsafe(registry, Clazz.__fallbackType);
56
56
  return initType(registry, Clazz, params, options);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bugs": "https://github.com/polkadot-js/api/issues",
4
4
  "description": "Type creator helpers",
5
5
  "engines": {
6
- "node": ">=16"
6
+ "node": ">=18"
7
7
  },
8
8
  "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-create#readme",
9
9
  "license": "Apache-2.0",
@@ -18,7 +18,7 @@
18
18
  "./cjs/detectPackage.js"
19
19
  ],
20
20
  "type": "module",
21
- "version": "10.9.1",
21
+ "version": "10.11.1",
22
22
  "main": "./cjs/index.js",
23
23
  "module": "./index.js",
24
24
  "types": "./index.d.ts",
@@ -145,8 +145,8 @@
145
145
  }
146
146
  },
147
147
  "dependencies": {
148
- "@polkadot/types-codec": "10.9.1",
149
- "@polkadot/util": "^12.3.1",
150
- "tslib": "^2.5.3"
148
+ "@polkadot/types-codec": "10.11.1",
149
+ "@polkadot/util": "^12.6.1",
150
+ "tslib": "^2.6.2"
151
151
  }
152
152
  }
package/packageInfo.js CHANGED
@@ -1 +1 @@
1
- export const packageInfo = { name: '@polkadot/types-create', 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.9.1' };
1
+ export const packageInfo = { name: '@polkadot/types-create', 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.1' };
@@ -1,8 +1,8 @@
1
1
  import type { Registry } from '@polkadot/types-codec/types';
2
2
  import type { TypeDef } from '@polkadot/types-create/types';
3
- type ToString = {
3
+ interface ToString {
4
4
  toString: () => string;
5
- };
5
+ }
6
6
  export declare function paramsNotation<T extends ToString>(outer: string, inner?: T | T[], transform?: (_: T) => string): string;
7
7
  export declare function encodeTypeDef(registry: Registry, typeDef: TypeDef): string;
8
8
  export declare function withTypeString(registry: Registry, typeDef: Omit<TypeDef, 'type'> & {
@@ -34,6 +34,9 @@ function encodeSubTypes(registry, sub, asEnum, extra) {
34
34
  const inner = objectSpread({}, extra);
35
35
  for (let i = 0, count = sub.length; i < count; i++) {
36
36
  const def = sub[i];
37
+ if (!def.name) {
38
+ throw new Error(`No name found in ${stringify(def)}`);
39
+ }
37
40
  inner[def.name] = encodeTypeDef(registry, def);
38
41
  }
39
42
  return stringify(asEnum
@@ -1,12 +1,12 @@
1
1
  import { sanitize } from '@polkadot/types-codec';
2
- import { isNumber, isString, objectSpread } from '@polkadot/util';
2
+ import { isNumber, isString, objectSpread, stringify } from '@polkadot/util';
3
3
  import { TypeDefInfo } from '../types/index.js';
4
4
  import { typeSplit } from './typeSplit.js';
5
5
  const KNOWN_INTERNALS = ['_alias', '_fallback'];
6
6
  function getTypeString(typeOrObj) {
7
7
  return isString(typeOrObj)
8
8
  ? typeOrObj.toString()
9
- : JSON.stringify(typeOrObj);
9
+ : stringify(typeOrObj);
10
10
  }
11
11
  function isRustEnum(details) {
12
12
  const values = Object.values(details);
@@ -142,7 +142,7 @@ function _decodeDoNotConstruct(value, type, _) {
142
142
  return value;
143
143
  }
144
144
  function hasWrapper(type, [start, end]) {
145
- return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
145
+ return (type.startsWith(start)) && (type.slice(-1 * end.length) === end);
146
146
  }
147
147
  const nestedExtraction = [
148
148
  ['[', ']', TypeDefInfo.VecFixed, _decodeFixedVec],