dedot 0.0.1-alpha.26 → 0.0.1-alpha.4

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.
@@ -259,7 +259,7 @@ class Dedot {
259
259
  return { endpoint: options };
260
260
  }
261
261
  else {
262
- let { metadata } = options || {};
262
+ let { metadata } = options;
263
263
  if (metadata && typeof metadata === 'string') {
264
264
  metadata = {
265
265
  [exports.CATCH_ALL_METADATA_KEY]: (0, util_1.hexAddPrefix)(metadata),
@@ -10,10 +10,10 @@ exports.FallbackRuntimeApis = [
10
10
  ];
11
11
  class RuntimeApiExecutor extends Executor_1.Executor {
12
12
  execute(runtimeApi, method) {
13
- const runtimeApiName = (0, util_1.stringPascalCase)(runtimeApi);
14
- const methodName = (0, utils_1.stringSnakeCase)(method);
15
- const callName = this.#callName({ runtimeApiName, methodName });
16
- const callSpec = this.#findRuntimeApiMethodSpec(runtimeApiName, methodName);
13
+ runtimeApi = (0, util_1.stringPascalCase)(runtimeApi);
14
+ method = (0, utils_1.stringSnakeCase)(method);
15
+ const callName = `${runtimeApi}_${method}`;
16
+ const callSpec = this.#findRuntimeApiMethodSpec(runtimeApi, method);
17
17
  (0, utils_1.assert)(callSpec, `Runtime Api not found: ${callName}`);
18
18
  const callFn = async (...args) => {
19
19
  const { params } = callSpec;
@@ -30,40 +30,23 @@ class RuntimeApiExecutor extends Executor_1.Executor {
30
30
  return callFn;
31
31
  }
32
32
  tryDecode(callSpec, raw) {
33
- const $codec = this.#findCodec(callSpec, `Codec not found to decode respond data for ${this.#callName(callSpec)}`);
34
- return $codec.tryDecode(raw);
35
- }
36
- tryEncode(paramSpec, value) {
37
- const $codec = this.#findCodec(paramSpec, `Codec not found to encode input for param ${paramSpec.name}`);
38
- return $codec.tryEncode(value);
39
- }
40
- #findCodec(spec, error) {
41
- const { codec, typeId, type } = spec;
42
- if (codec)
43
- return codec;
33
+ const { type, typeId } = callSpec;
44
34
  if ((0, util_1.isNumber)(typeId)) {
45
- return this.registry.findPortableCodec(typeId);
46
- }
47
- if (type) {
48
- return this.registry.findCodec(type);
35
+ return this.registry.findPortableCodec(typeId).tryDecode(raw);
49
36
  }
50
- throw new Error(error || 'Codec not found');
37
+ return this.registry.findCodec(type).tryDecode(raw);
51
38
  }
52
- #callName({ runtimeApiName, methodName }) {
53
- return `${runtimeApiName}_${methodName}`;
39
+ tryEncode(paramSpec, value) {
40
+ const { type, typeId } = paramSpec;
41
+ const $codec = (0, util_1.isNumber)(typeId) ? this.registry.findPortableCodec(typeId) : this.registry.findCodec(type);
42
+ return $codec.tryEncode(value);
54
43
  }
55
44
  #findRuntimeApiMethodSpec(runtimeApi, method) {
56
- const targetVersion = this.#findTargetRuntimeApiVersion(runtimeApi);
57
- if (!(0, util_1.isNumber)(targetVersion))
58
- return undefined;
59
- const userDefinedSpec = this.#findUserDefinedSpec(runtimeApi, method, targetVersion);
60
- if (userDefinedSpec)
61
- return userDefinedSpec;
62
45
  const methodDef = this.#findRuntimeApiMethodDef(runtimeApi, method);
63
46
  if (methodDef) {
64
47
  return this.#toMethodSpec(runtimeApi, methodDef);
65
48
  }
66
- return this.#findExternalSpec(runtimeApi, method, targetVersion);
49
+ return this.#findRuntimeApiMethodExternalSpec(runtimeApi, method);
67
50
  }
68
51
  #findRuntimeApiMethodDef(runtimeApi, method) {
69
52
  try {
@@ -79,36 +62,32 @@ class RuntimeApiExecutor extends Executor_1.Executor {
79
62
  catch { }
80
63
  }
81
64
  #toMethodSpec(runtimeApi, methodDef) {
65
+ if (!methodDef)
66
+ return undefined;
82
67
  const { name, inputs, output, docs } = methodDef;
83
68
  return {
84
69
  docs,
85
70
  runtimeApiName: runtimeApi,
86
71
  methodName: name,
72
+ type: '', // TODO generate type name
87
73
  typeId: output,
88
74
  params: inputs.map(({ name, typeId }) => ({
89
75
  name,
76
+ type: '', // TODO generate type name
90
77
  typeId,
91
78
  })),
92
79
  };
93
80
  }
94
- #findTargetRuntimeApiVersion(runtimeApi) {
95
- const runtimeApiHash = (0, utils_1.calculateRuntimeApiHash)(runtimeApi);
81
+ #findRuntimeApiMethodExternalSpec(runtimeApi, method) {
82
+ const targetRuntimeApiHash = (0, utils_1.calculateRuntimeApiHash)(runtimeApi);
96
83
  const runtimeApiVersions = this.api.runtimeVersion?.apis || exports.FallbackRuntimeApis;
97
- const foundVersion = runtimeApiVersions
98
- .find(([supportedRuntimeApiHash]) => runtimeApiHash === supportedRuntimeApiHash)
84
+ const targetRuntimeApiVersion = runtimeApiVersions
85
+ .find(([supportedRuntimeApiHash]) => targetRuntimeApiHash === supportedRuntimeApiHash)
99
86
  ?.at(1);
100
- return foundVersion;
101
- }
102
- #findExternalSpec(runtimeApiName, methodName, targetRuntimeApiVersion) {
103
- return (0, specs_1.findRuntimeApiMethodSpec)(this.#callName({ runtimeApiName, methodName }), targetRuntimeApiVersion);
104
- }
105
- #findUserDefinedSpec(runtimeApi, method, runtimeApiVersion) {
106
- const userDefinedSpecs = this.api.options.runtime;
107
- if (!userDefinedSpecs)
87
+ if (!(0, util_1.isNumber)(targetRuntimeApiVersion)) {
108
88
  return undefined;
109
- const methodSpecs = (0, specs_1.extractRuntimeApisModule)(userDefinedSpecs).map(specs_1.extractRuntimeApiSpec).flat();
110
- return methodSpecs.find(({ runtimeApiName, methodName, version }) => `${(0, util_1.stringPascalCase)(runtimeApiName)}_${(0, utils_1.stringSnakeCase)(methodName)}` === `${runtimeApi}_${method}` &&
111
- runtimeApiVersion === version);
89
+ }
90
+ return (0, specs_1.findRuntimeApiMethodSpec)(`${runtimeApi}_${method}`, targetRuntimeApiVersion);
112
91
  }
113
92
  }
114
93
  exports.RuntimeApiExecutor = RuntimeApiExecutor;
@@ -2,4 +2,4 @@
2
2
  // THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.packageInfo = void 0;
5
- exports.packageInfo = { name: 'dedot', version: '0.0.1-alpha.25' };
5
+ exports.packageInfo = { name: 'dedot', version: '0.0.1-alpha.23' };
package/client/Dedot.js CHANGED
@@ -253,7 +253,7 @@ export class Dedot {
253
253
  return { endpoint: options };
254
254
  }
255
255
  else {
256
- let { metadata } = options || {};
256
+ let { metadata } = options;
257
257
  if (metadata && typeof metadata === 'string') {
258
258
  metadata = {
259
259
  [CATCH_ALL_METADATA_KEY]: hexAddPrefix(metadata),
@@ -1,5 +1,5 @@
1
- import type { GenericRuntimeApiMethod, GenericSubstrateApi, RuntimeApiMethodSpec, RuntimeApiMethodParamSpec } from '@dedot/types';
2
1
  import { Executor } from './Executor';
2
+ import { GenericRuntimeApiMethod, GenericSubstrateApi, RuntimeApiMethodParamSpec, RuntimeApiMethodSpec } from '@dedot/types';
3
3
  export declare const FallbackRuntimeApis: (string | number)[][];
4
4
  export declare class RuntimeApiExecutor<ChainApi extends GenericSubstrateApi = GenericSubstrateApi> extends Executor<ChainApi> {
5
5
  #private;
@@ -1,16 +1,16 @@
1
1
  import { Executor } from './Executor';
2
2
  import { assert, calculateRuntimeApiHash, stringSnakeCase } from '@dedot/utils';
3
3
  import { isNumber, stringPascalCase, u8aConcat, u8aToHex } from '@polkadot/util';
4
- import { extractRuntimeApisModule, extractRuntimeApiSpec, findRuntimeApiMethodSpec } from '@dedot/specs';
4
+ import { findRuntimeApiMethodSpec } from '@dedot/specs';
5
5
  export const FallbackRuntimeApis = [
6
6
  ['0x37e397fc7c91f5e4', 2], // Metadata Api v2
7
7
  ];
8
8
  export class RuntimeApiExecutor extends Executor {
9
9
  execute(runtimeApi, method) {
10
- const runtimeApiName = stringPascalCase(runtimeApi);
11
- const methodName = stringSnakeCase(method);
12
- const callName = this.#callName({ runtimeApiName, methodName });
13
- const callSpec = this.#findRuntimeApiMethodSpec(runtimeApiName, methodName);
10
+ runtimeApi = stringPascalCase(runtimeApi);
11
+ method = stringSnakeCase(method);
12
+ const callName = `${runtimeApi}_${method}`;
13
+ const callSpec = this.#findRuntimeApiMethodSpec(runtimeApi, method);
14
14
  assert(callSpec, `Runtime Api not found: ${callName}`);
15
15
  const callFn = async (...args) => {
16
16
  const { params } = callSpec;
@@ -27,40 +27,23 @@ export class RuntimeApiExecutor extends Executor {
27
27
  return callFn;
28
28
  }
29
29
  tryDecode(callSpec, raw) {
30
- const $codec = this.#findCodec(callSpec, `Codec not found to decode respond data for ${this.#callName(callSpec)}`);
31
- return $codec.tryDecode(raw);
32
- }
33
- tryEncode(paramSpec, value) {
34
- const $codec = this.#findCodec(paramSpec, `Codec not found to encode input for param ${paramSpec.name}`);
35
- return $codec.tryEncode(value);
36
- }
37
- #findCodec(spec, error) {
38
- const { codec, typeId, type } = spec;
39
- if (codec)
40
- return codec;
30
+ const { type, typeId } = callSpec;
41
31
  if (isNumber(typeId)) {
42
- return this.registry.findPortableCodec(typeId);
43
- }
44
- if (type) {
45
- return this.registry.findCodec(type);
32
+ return this.registry.findPortableCodec(typeId).tryDecode(raw);
46
33
  }
47
- throw new Error(error || 'Codec not found');
34
+ return this.registry.findCodec(type).tryDecode(raw);
48
35
  }
49
- #callName({ runtimeApiName, methodName }) {
50
- return `${runtimeApiName}_${methodName}`;
36
+ tryEncode(paramSpec, value) {
37
+ const { type, typeId } = paramSpec;
38
+ const $codec = isNumber(typeId) ? this.registry.findPortableCodec(typeId) : this.registry.findCodec(type);
39
+ return $codec.tryEncode(value);
51
40
  }
52
41
  #findRuntimeApiMethodSpec(runtimeApi, method) {
53
- const targetVersion = this.#findTargetRuntimeApiVersion(runtimeApi);
54
- if (!isNumber(targetVersion))
55
- return undefined;
56
- const userDefinedSpec = this.#findUserDefinedSpec(runtimeApi, method, targetVersion);
57
- if (userDefinedSpec)
58
- return userDefinedSpec;
59
42
  const methodDef = this.#findRuntimeApiMethodDef(runtimeApi, method);
60
43
  if (methodDef) {
61
44
  return this.#toMethodSpec(runtimeApi, methodDef);
62
45
  }
63
- return this.#findExternalSpec(runtimeApi, method, targetVersion);
46
+ return this.#findRuntimeApiMethodExternalSpec(runtimeApi, method);
64
47
  }
65
48
  #findRuntimeApiMethodDef(runtimeApi, method) {
66
49
  try {
@@ -76,35 +59,31 @@ export class RuntimeApiExecutor extends Executor {
76
59
  catch { }
77
60
  }
78
61
  #toMethodSpec(runtimeApi, methodDef) {
62
+ if (!methodDef)
63
+ return undefined;
79
64
  const { name, inputs, output, docs } = methodDef;
80
65
  return {
81
66
  docs,
82
67
  runtimeApiName: runtimeApi,
83
68
  methodName: name,
69
+ type: '', // TODO generate type name
84
70
  typeId: output,
85
71
  params: inputs.map(({ name, typeId }) => ({
86
72
  name,
73
+ type: '', // TODO generate type name
87
74
  typeId,
88
75
  })),
89
76
  };
90
77
  }
91
- #findTargetRuntimeApiVersion(runtimeApi) {
92
- const runtimeApiHash = calculateRuntimeApiHash(runtimeApi);
78
+ #findRuntimeApiMethodExternalSpec(runtimeApi, method) {
79
+ const targetRuntimeApiHash = calculateRuntimeApiHash(runtimeApi);
93
80
  const runtimeApiVersions = this.api.runtimeVersion?.apis || FallbackRuntimeApis;
94
- const foundVersion = runtimeApiVersions
95
- .find(([supportedRuntimeApiHash]) => runtimeApiHash === supportedRuntimeApiHash)
81
+ const targetRuntimeApiVersion = runtimeApiVersions
82
+ .find(([supportedRuntimeApiHash]) => targetRuntimeApiHash === supportedRuntimeApiHash)
96
83
  ?.at(1);
97
- return foundVersion;
98
- }
99
- #findExternalSpec(runtimeApiName, methodName, targetRuntimeApiVersion) {
100
- return findRuntimeApiMethodSpec(this.#callName({ runtimeApiName, methodName }), targetRuntimeApiVersion);
101
- }
102
- #findUserDefinedSpec(runtimeApi, method, runtimeApiVersion) {
103
- const userDefinedSpecs = this.api.options.runtime;
104
- if (!userDefinedSpecs)
84
+ if (!isNumber(targetRuntimeApiVersion)) {
105
85
  return undefined;
106
- const methodSpecs = extractRuntimeApisModule(userDefinedSpecs).map(extractRuntimeApiSpec).flat();
107
- return methodSpecs.find(({ runtimeApiName, methodName, version }) => `${stringPascalCase(runtimeApiName)}_${stringSnakeCase(methodName)}` === `${runtimeApi}_${method}` &&
108
- runtimeApiVersion === version);
86
+ }
87
+ return findRuntimeApiMethodSpec(`${runtimeApi}_${method}`, targetRuntimeApiVersion);
109
88
  }
110
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dedot",
3
- "version": "0.0.1-alpha.26",
3
+ "version": "0.0.1-alpha.4+cef1b29",
4
4
  "description": "A fast & lightweight JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot",
@@ -12,11 +12,11 @@
12
12
  "main": "./cjs/index.js",
13
13
  "type": "module",
14
14
  "dependencies": {
15
- "@dedot/chaintypes": "0.0.1-alpha.26",
16
- "@dedot/codecs": "0.0.1-alpha.26",
17
- "@dedot/shape": "0.0.1-alpha.26",
18
- "@dedot/specs": "0.0.1-alpha.26",
19
- "@dedot/utils": "0.0.1-alpha.26",
15
+ "@dedot/chaintypes": "0.0.1-alpha.4+cef1b29",
16
+ "@dedot/codecs": "0.0.1-alpha.4+cef1b29",
17
+ "@dedot/shape": "0.0.1-alpha.4+cef1b29",
18
+ "@dedot/specs": "0.0.1-alpha.4+cef1b29",
19
+ "@dedot/utils": "0.0.1-alpha.4+cef1b29",
20
20
  "@polkadot/rpc-provider": "^10.11.2",
21
21
  "@polkadot/util": "^12.6.2",
22
22
  "@polkadot/util-crypto": "^12.6.2",
@@ -36,7 +36,7 @@
36
36
  "@polkadot/keyring": "^12.6.2",
37
37
  "@polkadot/types": "^10.11.2"
38
38
  },
39
- "gitHead": "5b114a0d2359316f07654915f3c03b44761cac73",
39
+ "gitHead": "cef1b29a1f5b0d92fb8c9893dfabff20b658fa5f",
40
40
  "module": "./index.js",
41
41
  "types": "./index.d.ts",
42
42
  "exports": {
package/packageInfo.js CHANGED
@@ -1,3 +1,2 @@
1
1
  // THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
2
-
3
- export const packageInfo = { name: 'dedot', version: '0.0.1-alpha.26' };
2
+ export const packageInfo = { name: 'dedot', version: '0.0.1-alpha.23' };
package/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { ProviderInterface } from '@polkadot/rpc-provider/types';
2
2
  import { HexString } from '@dedot/utils';
3
3
  import { AnySignedExtension } from './extrinsic';
4
- import { RuntimeApiSpec } from '@dedot/types';
5
4
  export type NetworkEndpoint = string;
6
5
  export type MetadataKey = `RAW_META/${string}`;
7
6
  export interface ApiOptions {
@@ -39,7 +38,6 @@ export interface ApiOptions {
39
38
  * @description User-defined chain-specific signed extensions
40
39
  */
41
40
  signedExtensions?: Record<string, AnySignedExtension>;
42
- runtime?: Record<string, RuntimeApiSpec[]>;
43
41
  }
44
42
  export interface NormalizedApiOptions extends ApiOptions {
45
43
  metadata?: Record<string, HexString>;