@polkadot/types-create 9.14.2 → 10.0.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.
package/bundle.js CHANGED
@@ -1,7 +1,4 @@
1
- // Copyright 2017-2023 @polkadot/types-codec authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { packageInfo } from "./packageInfo.js";
5
- export { TypeDefInfo } from "./types/index.js";
6
- export * from "./create/index.js";
7
- export * from "./util/index.js";
1
+ export { packageInfo } from './packageInfo.js';
2
+ export { TypeDefInfo } from './types/index.js';
3
+ export * from './create/index.js';
4
+ export * from './util/index.js';
package/cjs/bundle.js CHANGED
@@ -1,47 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- packageInfo: true,
8
- TypeDefInfo: true
9
- };
10
- Object.defineProperty(exports, "TypeDefInfo", {
11
- enumerable: true,
12
- get: function () {
13
- return _types.TypeDefInfo;
14
- }
15
- });
16
- Object.defineProperty(exports, "packageInfo", {
17
- enumerable: true,
18
- get: function () {
19
- return _packageInfo.packageInfo;
20
- }
21
- });
22
- var _packageInfo = require("./packageInfo");
23
- var _types = require("./types");
24
- var _create = require("./create");
25
- Object.keys(_create).forEach(function (key) {
26
- if (key === "default" || key === "__esModule") return;
27
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
- if (key in exports && exports[key] === _create[key]) return;
29
- Object.defineProperty(exports, key, {
30
- enumerable: true,
31
- get: function () {
32
- return _create[key];
33
- }
34
- });
35
- });
36
- var _util = require("./util");
37
- Object.keys(_util).forEach(function (key) {
38
- if (key === "default" || key === "__esModule") return;
39
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
40
- if (key in exports && exports[key] === _util[key]) return;
41
- Object.defineProperty(exports, key, {
42
- enumerable: true,
43
- get: function () {
44
- return _util[key];
45
- }
46
- });
47
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeDefInfo = exports.packageInfo = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var packageInfo_1 = require("./packageInfo");
6
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_1.packageInfo; } });
7
+ var types_1 = require("./types");
8
+ Object.defineProperty(exports, "TypeDefInfo", { enumerable: true, get: function () { return types_1.TypeDefInfo; } });
9
+ tslib_1.__exportStar(require("./create"), exports);
10
+ tslib_1.__exportStar(require("./util"), exports);
@@ -1,200 +1,157 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.constructTypeClass = constructTypeClass;
7
- exports.createClassUnsafe = createClassUnsafe;
8
- exports.getTypeClass = getTypeClass;
9
- var _typesCodec = require("@polkadot/types-codec");
10
- var _util = require("@polkadot/util");
11
- var _types = require("../types");
12
- var _getTypeDef = require("../util/getTypeDef");
13
- // Copyright 2017-2023 @polkadot/types-create authors & contributors
14
- // SPDX-License-Identifier: Apache-2.0
15
-
16
- function getTypeDefType(_ref) {
17
- let {
18
- lookupName,
19
- type
20
- } = _ref;
21
- return lookupName || type;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClassUnsafe = exports.getTypeClass = exports.constructTypeClass = void 0;
4
+ const types_codec_1 = require("@polkadot/types-codec");
5
+ const util_1 = require("@polkadot/util");
6
+ const types_1 = require("../types");
7
+ const getTypeDef_1 = require("../util/getTypeDef");
8
+ function getTypeDefType({ lookupName, type }) {
9
+ return lookupName || type;
22
10
  }
23
11
  function getSubDefArray(value) {
24
- if (!Array.isArray(value.sub)) {
25
- throw new Error(`Expected subtype as TypeDef[] in ${(0, _util.stringify)(value)}`);
26
- }
27
- return value.sub;
12
+ if (!Array.isArray(value.sub)) {
13
+ throw new Error(`Expected subtype as TypeDef[] in ${(0, util_1.stringify)(value)}`);
14
+ }
15
+ return value.sub;
28
16
  }
29
17
  function getSubDef(value) {
30
- if (!value.sub || Array.isArray(value.sub)) {
31
- throw new Error(`Expected subtype as TypeDef in ${(0, _util.stringify)(value)}`);
32
- }
33
- return value.sub;
18
+ if (!value.sub || Array.isArray(value.sub)) {
19
+ throw new Error(`Expected subtype as TypeDef in ${(0, util_1.stringify)(value)}`);
20
+ }
21
+ return value.sub;
34
22
  }
35
23
  function getSubType(value) {
36
- return getTypeDefType(getSubDef(value));
24
+ return getTypeDefType(getSubDef(value));
37
25
  }
38
-
39
- // create a maps of type string CodecClasss from the input
40
26
  function getTypeClassMap(value) {
41
- const subs = getSubDefArray(value);
42
- const map = {};
43
- for (let i = 0; i < subs.length; i++) {
44
- map[subs[i].name] = getTypeDefType(subs[i]);
45
- }
46
- return map;
27
+ const subs = getSubDefArray(value);
28
+ const map = {};
29
+ for (let i = 0; i < subs.length; i++) {
30
+ map[subs[i].name] = getTypeDefType(subs[i]);
31
+ }
32
+ return map;
47
33
  }
48
-
49
- // create an array of type string CodecClasss from the input
50
34
  function getTypeClassArray(value) {
51
- return getSubDefArray(value).map(getTypeDefType);
35
+ return getSubDefArray(value).map(getTypeDefType);
52
36
  }
53
- function createInt(Clazz, _ref2) {
54
- let {
55
- displayName,
56
- length
57
- } = _ref2;
58
- if (!(0, _util.isNumber)(length)) {
59
- throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
60
- }
61
- return Clazz.with(length, displayName);
37
+ function createInt(Clazz, { displayName, length }) {
38
+ if (!(0, util_1.isNumber)(length)) {
39
+ throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
40
+ }
41
+ return Clazz.with(length, displayName);
62
42
  }
63
43
  function createHashMap(Clazz, value) {
64
- const [keyType, valueType] = getTypeClassArray(value);
65
- return Clazz.with(keyType, valueType);
44
+ const [keyType, valueType] = getTypeClassArray(value);
45
+ return Clazz.with(keyType, valueType);
66
46
  }
67
47
  function createWithSub(Clazz, value) {
68
- return Clazz.with(getSubType(value));
48
+ return Clazz.with(getSubType(value));
69
49
  }
70
50
  const infoMapping = {
71
- [_types.TypeDefInfo.BTreeMap]: (registry, value) => createHashMap(_typesCodec.BTreeMap, value),
72
- [_types.TypeDefInfo.BTreeSet]: (registry, value) => createWithSub(_typesCodec.BTreeSet, value),
73
- [_types.TypeDefInfo.Compact]: (registry, value) => createWithSub(_typesCodec.Compact, value),
74
- [_types.TypeDefInfo.DoNotConstruct]: (registry, value) => _typesCodec.DoNotConstruct.with(value.displayName || value.type),
75
- [_types.TypeDefInfo.Enum]: (registry, value) => {
76
- const subs = getSubDefArray(value);
77
- return _typesCodec.Enum.with(subs.every(_ref3 => {
78
- let {
79
- type
80
- } = _ref3;
81
- return type === 'Null';
82
- }) ? subs.reduce((out, _ref4, count) => {
83
- let {
84
- index,
85
- name
86
- } = _ref4;
87
- out[name] = index || count;
88
- return out;
89
- }, {}) : getTypeClassMap(value));
90
- },
91
- [_types.TypeDefInfo.HashMap]: (registry, value) => createHashMap(_typesCodec.HashMap, value),
92
- [_types.TypeDefInfo.Int]: (registry, value) => createInt(_typesCodec.Int, value),
93
- // We have circular deps between Linkage & Struct
94
- [_types.TypeDefInfo.Linkage]: (registry, value) => {
95
- const type = `Option<${getSubType(value)}>`;
96
- // eslint-disable-next-line sort-keys
97
- const Clazz = _typesCodec.Struct.with({
98
- previous: type,
99
- next: type
100
- });
101
-
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
103
- Clazz.prototype.toRawType = function () {
104
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
105
- return `Linkage<${this.next.toRawType(true)}>`;
106
- };
107
- return Clazz;
108
- },
109
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
110
- [_types.TypeDefInfo.Null]: (registry, _) => _typesCodec.Null,
111
- [_types.TypeDefInfo.Option]: (registry, value) => {
112
- if (!value.sub || Array.isArray(value.sub)) {
113
- throw new Error('Expected type information for Option');
114
- }
115
-
116
- // NOTE This is opt-in (unhandled), not by default
117
- // if (value.sub.type === 'bool') {
118
- // return OptionBool;
119
- // }
120
-
121
- return createWithSub(_typesCodec.Option, value);
122
- },
123
- [_types.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
124
- [_types.TypeDefInfo.Range]: (registry, value) => createWithSub(_typesCodec.Range, value),
125
- [_types.TypeDefInfo.RangeInclusive]: (registry, value) => createWithSub(_typesCodec.RangeInclusive, value),
126
- [_types.TypeDefInfo.Result]: (registry, value) => {
127
- const [Ok, Err] = getTypeClassArray(value);
128
-
129
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
130
- return _typesCodec.Result.with({
131
- Err,
132
- Ok
133
- });
134
- },
135
- [_types.TypeDefInfo.Set]: (registry, value) => _typesCodec.CodecSet.with(getSubDefArray(value).reduce((result, _ref5) => {
136
- let {
137
- index,
138
- name
139
- } = _ref5;
140
- result[name] = index;
141
- return result;
142
- }, {}), value.length),
143
- [_types.TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
144
- [_types.TypeDefInfo.Struct]: (registry, value) => _typesCodec.Struct.with(getTypeClassMap(value), value.alias),
145
- [_types.TypeDefInfo.Tuple]: (registry, value) => _typesCodec.Tuple.with(getTypeClassArray(value)),
146
- [_types.TypeDefInfo.UInt]: (registry, value) => createInt(_typesCodec.UInt, value),
147
- [_types.TypeDefInfo.Vec]: (registry, _ref6) => {
148
- let {
149
- sub
150
- } = _ref6;
151
- if (!sub || Array.isArray(sub)) {
152
- throw new Error('Expected type information for vector');
153
- }
154
- return sub.type === 'u8' ? _typesCodec.Bytes : _typesCodec.Vec.with(getTypeDefType(sub));
155
- },
156
- [_types.TypeDefInfo.VecFixed]: (registry, _ref7) => {
157
- let {
158
- displayName,
159
- length,
160
- sub
161
- } = _ref7;
162
- if (!(0, _util.isNumber)(length) || !sub || Array.isArray(sub)) {
163
- throw new Error('Expected length & type information for fixed vector');
164
- }
165
- return sub.type === 'u8' ? _typesCodec.U8aFixed.with(length * 8, displayName) : _typesCodec.VecFixed.with(getTypeDefType(sub), length);
166
- },
167
- [_types.TypeDefInfo.WrapperKeepOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperKeepOpaque, value),
168
- [_types.TypeDefInfo.WrapperOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperOpaque, value)
51
+ [types_1.TypeDefInfo.BTreeMap]: (registry, value) => createHashMap(types_codec_1.BTreeMap, value),
52
+ [types_1.TypeDefInfo.BTreeSet]: (registry, value) => createWithSub(types_codec_1.BTreeSet, value),
53
+ [types_1.TypeDefInfo.Compact]: (registry, value) => createWithSub(types_codec_1.Compact, value),
54
+ [types_1.TypeDefInfo.DoNotConstruct]: (registry, value) => types_codec_1.DoNotConstruct.with(value.displayName || value.type),
55
+ [types_1.TypeDefInfo.Enum]: (registry, value) => {
56
+ const subs = getSubDefArray(value);
57
+ return types_codec_1.Enum.with(subs.every(({ type }) => type === 'Null')
58
+ ? subs.reduce((out, { index, name }, count) => {
59
+ out[name] = index || count;
60
+ return out;
61
+ }, {})
62
+ : getTypeClassMap(value));
63
+ },
64
+ [types_1.TypeDefInfo.HashMap]: (registry, value) => createHashMap(types_codec_1.HashMap, value),
65
+ [types_1.TypeDefInfo.Int]: (registry, value) => createInt(types_codec_1.Int, value),
66
+ // We have circular deps between Linkage & Struct
67
+ [types_1.TypeDefInfo.Linkage]: (registry, value) => {
68
+ const type = `Option<${getSubType(value)}>`;
69
+ // eslint-disable-next-line sort-keys
70
+ const Clazz = types_codec_1.Struct.with({ previous: type, next: type });
71
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
72
+ Clazz.prototype.toRawType = function () {
73
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
74
+ return `Linkage<${this.next.toRawType(true)}>`;
75
+ };
76
+ return Clazz;
77
+ },
78
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
+ [types_1.TypeDefInfo.Null]: (registry, _) => types_codec_1.Null,
80
+ [types_1.TypeDefInfo.Option]: (registry, value) => {
81
+ if (!value.sub || Array.isArray(value.sub)) {
82
+ throw new Error('Expected type information for Option');
83
+ }
84
+ // NOTE This is opt-in (unhandled), not by default
85
+ // if (value.sub.type === 'bool') {
86
+ // return OptionBool;
87
+ // }
88
+ return createWithSub(types_codec_1.Option, value);
89
+ },
90
+ [types_1.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
91
+ [types_1.TypeDefInfo.Range]: (registry, value) => createWithSub(types_codec_1.Range, value),
92
+ [types_1.TypeDefInfo.RangeInclusive]: (registry, value) => createWithSub(types_codec_1.RangeInclusive, value),
93
+ [types_1.TypeDefInfo.Result]: (registry, value) => {
94
+ const [Ok, Err] = getTypeClassArray(value);
95
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
96
+ return types_codec_1.Result.with({ Err, Ok });
97
+ },
98
+ [types_1.TypeDefInfo.Set]: (registry, value) => types_codec_1.CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
99
+ result[name] = index;
100
+ return result;
101
+ }, {}), value.length),
102
+ [types_1.TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
103
+ [types_1.TypeDefInfo.Struct]: (registry, value) => types_codec_1.Struct.with(getTypeClassMap(value), value.alias),
104
+ [types_1.TypeDefInfo.Tuple]: (registry, value) => types_codec_1.Tuple.with(getTypeClassArray(value)),
105
+ [types_1.TypeDefInfo.UInt]: (registry, value) => createInt(types_codec_1.UInt, value),
106
+ [types_1.TypeDefInfo.Vec]: (registry, { sub }) => {
107
+ if (!sub || Array.isArray(sub)) {
108
+ throw new Error('Expected type information for vector');
109
+ }
110
+ return (sub.type === 'u8'
111
+ ? types_codec_1.Bytes
112
+ : types_codec_1.Vec.with(getTypeDefType(sub)));
113
+ },
114
+ [types_1.TypeDefInfo.VecFixed]: (registry, { displayName, length, sub }) => {
115
+ if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
116
+ throw new Error('Expected length & type information for fixed vector');
117
+ }
118
+ return (sub.type === 'u8'
119
+ ? types_codec_1.U8aFixed.with((length * 8), displayName)
120
+ : types_codec_1.VecFixed.with(getTypeDefType(sub), length));
121
+ },
122
+ [types_1.TypeDefInfo.WrapperKeepOpaque]: (registry, value) => createWithSub(types_codec_1.WrapperKeepOpaque, value),
123
+ [types_1.TypeDefInfo.WrapperOpaque]: (registry, value) => createWithSub(types_codec_1.WrapperOpaque, value)
169
124
  };
170
125
  function constructTypeClass(registry, typeDef) {
171
- try {
172
- const Type = infoMapping[typeDef.info](registry, typeDef);
173
- if (!Type) {
174
- throw new Error('No class created');
126
+ try {
127
+ const Type = infoMapping[typeDef.info](registry, typeDef);
128
+ if (!Type) {
129
+ throw new Error('No class created');
130
+ }
131
+ // don't clobber any existing
132
+ if (!Type.__fallbackType && typeDef.fallbackType) {
133
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
134
+ // @ts-ignore ...this is the only place we we actually assign this...
135
+ Type.__fallbackType = typeDef.fallbackType;
136
+ }
137
+ return Type;
175
138
  }
176
-
177
- // don't clobber any existing
178
- if (!Type.__fallbackType && typeDef.fallbackType) {
179
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
180
- // @ts-ignore ...this is the only place we we actually assign this...
181
- Type.__fallbackType = typeDef.fallbackType;
139
+ catch (error) {
140
+ throw new Error(`Unable to construct class from ${(0, util_1.stringify)(typeDef)}: ${error.message}`);
182
141
  }
183
- return Type;
184
- } catch (error) {
185
- throw new Error(`Unable to construct class from ${(0, _util.stringify)(typeDef)}: ${error.message}`);
186
- }
187
142
  }
188
-
189
- // Returns the type Class for construction
143
+ exports.constructTypeClass = constructTypeClass;
190
144
  function getTypeClass(registry, typeDef) {
191
- return registry.getUnsafe(typeDef.type, false, typeDef);
145
+ return registry.getUnsafe(typeDef.type, false, typeDef);
192
146
  }
147
+ exports.getTypeClass = getTypeClass;
193
148
  function createClassUnsafe(registry, type) {
194
- return (
149
+ return (
195
150
  // just retrieve via name, no creation via typeDef
196
151
  registry.getUnsafe(type) ||
197
- // we don't have an existing type, create the class via typeDef
198
- getTypeClass(registry, registry.isLookupType(type) ? registry.lookup.getTypeDef(type) : (0, _getTypeDef.getTypeDef)(type))
199
- );
200
- }
152
+ // we don't have an existing type, create the class via typeDef
153
+ getTypeClass(registry, registry.isLookupType(type)
154
+ ? registry.lookup.getTypeDef(type)
155
+ : (0, getTypeDef_1.getTypeDef)(type)));
156
+ }
157
+ exports.createClassUnsafe = createClassUnsafe;
@@ -1,27 +1,5 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _class = require("./class");
7
- Object.keys(_class).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _class[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _class[key];
14
- }
15
- });
16
- });
17
- var _type = require("./type");
18
- Object.keys(_type).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _type[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _type[key];
25
- }
26
- });
27
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./class"), exports);
5
+ tslib_1.__exportStar(require("./type"), exports);
@@ -1,82 +1,67 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createTypeUnsafe = createTypeUnsafe;
7
- var _typesCodec = require("@polkadot/types-codec");
8
- var _util = require("@polkadot/util");
9
- var _class = require("./class");
10
- // Copyright 2017-2023 @polkadot/types-create authors & contributors
11
- // SPDX-License-Identifier: Apache-2.0
12
-
13
- // With isPedantic, actually check that the encoding matches that supplied. This
14
- // is much slower, but verifies that we have the correct types defined
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTypeUnsafe = void 0;
4
+ const types_codec_1 = require("@polkadot/types-codec");
5
+ const util_1 = require("@polkadot/util");
6
+ const class_1 = require("./class");
15
7
  function checkInstance(created, matcher) {
16
- const u8a = created.toU8a();
17
- const rawType = created.toRawType();
18
- const isOk =
19
- // full match, all ok
20
- (0, _util.u8aEq)(u8a, matcher) ||
21
- // on a length-prefixed type, just check the actual length
22
- ['Bytes', 'Text', 'Type'].includes(rawType) && matcher.length === created.length ||
23
- // when the created is empty and matcher is also empty, let it slide...
24
- created.isEmpty && matcher.every(v => !v);
25
- if (!isOk) {
26
- throw new Error(`${rawType}:: Decoded input doesn't match input, received ${(0, _util.u8aToHex)(matcher, 512)} (${matcher.length} bytes), created ${(0, _util.u8aToHex)(u8a, 512)} (${u8a.length} bytes)`);
27
- }
8
+ const u8a = created.toU8a();
9
+ const rawType = created.toRawType();
10
+ const isOk = (
11
+ // full match, all ok
12
+ (0, util_1.u8aEq)(u8a, matcher) ||
13
+ (
14
+ // on a length-prefixed type, just check the actual length
15
+ ['Bytes', 'Text', 'Type'].includes(rawType) &&
16
+ matcher.length === created.length) ||
17
+ (
18
+ // when the created is empty and matcher is also empty, let it slide...
19
+ created.isEmpty &&
20
+ matcher.every((v) => !v)));
21
+ if (!isOk) {
22
+ throw new Error(`${rawType}:: Decoded input doesn't match input, received ${(0, util_1.u8aToHex)(matcher, 512)} (${matcher.length} bytes), created ${(0, util_1.u8aToHex)(u8a, 512)} (${u8a.length} bytes)`);
23
+ }
28
24
  }
29
- function checkPedantic(created, _ref) {
30
- let [value] = _ref;
31
- if ((0, _util.isU8a)(value)) {
32
- checkInstance(created, value);
33
- } else if ((0, _util.isHex)(value)) {
34
- checkInstance(created, (0, _util.u8aToU8a)(value));
35
- }
25
+ function checkPedantic(created, [value]) {
26
+ if ((0, util_1.isU8a)(value)) {
27
+ checkInstance(created, value);
28
+ }
29
+ else if ((0, util_1.isHex)(value)) {
30
+ checkInstance(created, (0, util_1.u8aToU8a)(value));
31
+ }
36
32
  }
37
-
38
- // Initializes a type with a value. This also checks for fallbacks and in the cases
39
- // where isPedantic is specified (storage decoding), also check the format/structure
40
- function initType(registry, Type) {
41
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
42
- let {
43
- blockHash,
44
- isFallback,
45
- isOptional,
46
- isPedantic
47
- } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
48
- const created = new (isOptional ? _typesCodec.Option.with(Type) : Type)(registry, ...params);
49
- isPedantic && checkPedantic(created, params);
50
- if (blockHash) {
51
- created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]);
52
- }
53
- if (isFallback) {
54
- created.isStorageFallback = true;
55
- }
56
- return created;
33
+ function initType(registry, Type, params = [], { blockHash, isFallback, isOptional, isPedantic } = {}) {
34
+ const created = new (isOptional
35
+ ? types_codec_1.Option.with(Type)
36
+ : Type)(registry, ...params);
37
+ isPedantic && checkPedantic(created, params);
38
+ if (blockHash) {
39
+ created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]);
40
+ }
41
+ if (isFallback) {
42
+ created.isStorageFallback = true;
43
+ }
44
+ return created;
57
45
  }
58
-
59
- // An unsafe version of the `createType` below. It's unsafe because the `type`
60
- // argument here can be any string, which, when it cannot parse, will yield a
61
- // runtime error.
62
- function createTypeUnsafe(registry, type) {
63
- let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
64
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
65
- let Clazz = null;
66
- let firstError = null;
67
- try {
68
- Clazz = (0, _class.createClassUnsafe)(registry, type);
69
- return initType(registry, Clazz, params, options);
70
- } catch (error) {
71
- firstError = new Error(`createType(${type}):: ${error.message}`);
72
- }
73
- if (Clazz && Clazz.__fallbackType) {
46
+ function createTypeUnsafe(registry, type, params = [], options = {}) {
47
+ let Clazz = null;
48
+ let firstError = null;
74
49
  try {
75
- Clazz = (0, _class.createClassUnsafe)(registry, Clazz.__fallbackType);
76
- return initType(registry, Clazz, params, options);
77
- } catch {
78
- // swallow, we will throw the first error again
50
+ Clazz = (0, class_1.createClassUnsafe)(registry, type);
51
+ return initType(registry, Clazz, params, options);
52
+ }
53
+ catch (error) {
54
+ firstError = new Error(`createType(${type}):: ${error.message}`);
79
55
  }
80
- }
81
- throw firstError;
82
- }
56
+ if (Clazz && Clazz.__fallbackType) {
57
+ try {
58
+ Clazz = (0, class_1.createClassUnsafe)(registry, Clazz.__fallbackType);
59
+ return initType(registry, Clazz, params, options);
60
+ }
61
+ catch {
62
+ // swallow, we will throw the first error again
63
+ }
64
+ }
65
+ throw firstError;
66
+ }
67
+ exports.createTypeUnsafe = createTypeUnsafe;
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _packageInfo = require("@polkadot/types-codec/cjs/packageInfo");
8
- // Copyright 2017-2023 @polkadot/types-create authors & contributors
9
- // SPDX-License-Identifier: Apache-2.0
10
- var _default = [_packageInfo.packageInfo];
11
- exports.default = _default;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const packageInfo_1 = require("@polkadot/types-codec/cjs/packageInfo");
4
+ exports.default = [packageInfo_1.packageInfo];
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _util = require("@polkadot/util");
5
- var _detectOther = _interopRequireDefault(require("./detectOther"));
6
- var _packageInfo = require("./packageInfo");
7
- // Copyright 2017-2023 @polkadot/types-create authors & contributors
8
- // SPDX-License-Identifier: Apache-2.0
9
-
10
- // Do not edit, auto-generated by @polkadot/dev
11
-
12
- (0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const util_1 = require("@polkadot/util");
5
+ const detectOther_1 = tslib_1.__importDefault(require("./detectOther"));
6
+ const packageInfo_1 = require("./packageInfo");
7
+ (0, util_1.detectPackage)(packageInfo_1.packageInfo, null, detectOther_1.default);
package/cjs/index.js CHANGED
@@ -1,17 +1,5 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
6
4
  require("./detectPackage");
7
- var _bundle = require("./bundle");
8
- Object.keys(_bundle).forEach(function (key) {
9
- if (key === "default" || key === "__esModule") return;
10
- if (key in exports && exports[key] === _bundle[key]) return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function () {
14
- return _bundle[key];
15
- }
16
- });
17
- });
5
+ tslib_1.__exportStar(require("./bundle"), exports);