@dedot/codegen 0.0.1-next.8d06d348.17 → 0.0.1-next.8d3b3cd0.51

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.
Files changed (79) hide show
  1. package/cjs/generator/ConstsGen.js +13 -14
  2. package/cjs/generator/ErrorsGen.js +15 -16
  3. package/cjs/generator/EventsGen.js +16 -17
  4. package/cjs/generator/IndexGen.js +9 -10
  5. package/cjs/generator/JsonRpcGen.js +59 -0
  6. package/cjs/generator/QueryGen.js +27 -19
  7. package/cjs/generator/RuntimeApisGen.js +107 -33
  8. package/cjs/generator/TxGen.js +23 -21
  9. package/cjs/generator/TypeImports.js +13 -3
  10. package/cjs/generator/TypesGen.js +27 -36
  11. package/cjs/generator/index.js +10 -10
  12. package/cjs/{helpers/KnownCodecRegistry.js → generator/known-codecs.js} +59 -71
  13. package/cjs/generator/utils.js +30 -1
  14. package/cjs/index.js +40 -40
  15. package/cjs/templates/consts.hbs +1 -1
  16. package/cjs/templates/errors.hbs +1 -1
  17. package/cjs/templates/events.hbs +1 -1
  18. package/cjs/templates/index.hbs +15 -10
  19. package/cjs/templates/json-rpc.hbs +5 -0
  20. package/cjs/templates/query.hbs +1 -1
  21. package/cjs/templates/runtime.hbs +1 -1
  22. package/cjs/templates/tx.hbs +1 -1
  23. package/generator/ApiGen.d.ts +2 -2
  24. package/generator/ConstsGen.d.ts +2 -2
  25. package/generator/ConstsGen.js +7 -8
  26. package/generator/ErrorsGen.d.ts +2 -2
  27. package/generator/ErrorsGen.js +8 -9
  28. package/generator/EventsGen.d.ts +2 -2
  29. package/generator/EventsGen.js +8 -9
  30. package/generator/IndexGen.d.ts +3 -4
  31. package/generator/IndexGen.js +7 -8
  32. package/generator/JsonRpcGen.d.ts +7 -0
  33. package/generator/JsonRpcGen.js +55 -0
  34. package/generator/QueryGen.d.ts +2 -2
  35. package/generator/QueryGen.js +23 -15
  36. package/generator/RuntimeApisGen.d.ts +6 -6
  37. package/generator/RuntimeApisGen.js +97 -23
  38. package/generator/TxGen.d.ts +2 -2
  39. package/generator/TxGen.js +13 -11
  40. package/generator/TypeImports.d.ts +8 -1
  41. package/generator/TypeImports.js +13 -3
  42. package/generator/TypesGen.d.ts +4 -6
  43. package/generator/TypesGen.js +14 -23
  44. package/generator/index.d.ts +10 -10
  45. package/generator/index.js +10 -10
  46. package/generator/known-codecs.d.ts +23 -0
  47. package/generator/known-codecs.js +120 -0
  48. package/generator/utils.d.ts +5 -0
  49. package/generator/utils.js +28 -0
  50. package/index.d.ts +3 -4
  51. package/index.js +32 -32
  52. package/package.json +9 -18
  53. package/templates/consts.hbs +1 -1
  54. package/templates/errors.hbs +1 -1
  55. package/templates/events.hbs +1 -1
  56. package/templates/index.hbs +15 -10
  57. package/templates/json-rpc.hbs +5 -0
  58. package/templates/query.hbs +1 -1
  59. package/templates/runtime.hbs +1 -1
  60. package/templates/tx.hbs +1 -1
  61. package/cjs/genSupportedChainTypes.js +0 -79
  62. package/cjs/generator/RpcGen.js +0 -175
  63. package/cjs/helpers/index.js +0 -17
  64. package/cjs/packageInfo.js +0 -5
  65. package/cjs/templates/rpc.hbs +0 -7
  66. package/cjs/types.js +0 -2
  67. package/genSupportedChainTypes.d.ts +0 -1
  68. package/genSupportedChainTypes.js +0 -74
  69. package/generator/RpcGen.d.ts +0 -10
  70. package/generator/RpcGen.js +0 -171
  71. package/helpers/KnownCodecRegistry.d.ts +0 -22
  72. package/helpers/KnownCodecRegistry.js +0 -135
  73. package/helpers/index.d.ts +0 -1
  74. package/helpers/index.js +0 -1
  75. package/packageInfo.d.ts +0 -4
  76. package/packageInfo.js +0 -2
  77. package/templates/rpc.hbs +0 -7
  78. package/types.d.ts +0 -14
  79. package/types.js +0 -1
@@ -1,135 +0,0 @@
1
- import * as $ from '@dedot/shape';
2
- import * as Codecs from '@dedot/codecs';
3
- import { $AccountId20, $AccountId32, $Bytes, $ConsensusEngineId, $Era, $EthereumAddress, $MultiAddress, $OpaqueExtrinsic, $PrefixedStorageKey, $RawBytes, $StorageData, $StorageKey, $UncheckedExtrinsic, } from '@dedot/codecs';
4
- export const normalizeCodecName = (name) => {
5
- return name.startsWith('$') ? name : `$${name}`;
6
- };
7
- // Known paths for codecs (primitives) that are shared between
8
- // different substrate-based blockchains
9
- const KNOWN_PATHS = [
10
- 'sp_core::crypto::AccountId32',
11
- 'sp_runtime::generic::era::Era',
12
- 'sp_runtime::multiaddress::MultiAddress',
13
- /^sp_runtime::DispatchError$/,
14
- 'sp_runtime::ModuleError',
15
- 'sp_runtime::TokenError',
16
- 'sp_arithmetic::ArithmeticError',
17
- 'sp_runtime::TransactionalError',
18
- 'frame_support::dispatch::DispatchInfo',
19
- 'frame_system::Phase',
20
- 'sp_version::RuntimeVersion',
21
- 'fp_account::AccountId20',
22
- 'account::AccountId20',
23
- 'polkadot_runtime_common::claims::EthereumAddress',
24
- 'pallet_identity::types::Data',
25
- 'sp_runtime::generic::digest::Digest',
26
- 'sp_runtime::generic::digest::DigestItem',
27
- 'sp_runtime::generic::header::Header',
28
- 'sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic',
29
- /^primitive_types::\w+$/,
30
- /^sp_arithmetic::per_things::\w+$/,
31
- /^sp_arithmetic::fixed_point::\w+$/,
32
- ];
33
- const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/;
34
- const TUPLE_TYPE_REGEX = /^\[(.*)]$/;
35
- const KNOWN_WRAPPER_TYPES = ['Option', 'Vec', 'Result', 'Array'];
36
- /**
37
- * Collection of codec types with loose input types
38
- *
39
- * Loose codecs are codecs with different typeIn & typeOut,
40
- * E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32`
41
- *
42
- * This registry keep track the list of codecs which follow this convention
43
- */
44
- export const looseTypeCodecs = {
45
- $AccountId20,
46
- $EthereumAddress,
47
- $AccountId32,
48
- $ConsensusEngineId,
49
- $StorageKey,
50
- $StorageData,
51
- $PrefixedStorageKey,
52
- $Bytes,
53
- $RawBytes,
54
- $MultiAddress,
55
- $OpaqueExtrinsic,
56
- $UncheckedExtrinsic,
57
- $Era,
58
- };
59
- /**
60
- * A codec registry for both known and portable codecs,
61
- */
62
- export class KnownCodecRegistry {
63
- findCodec(name) {
64
- return this.#findKnownCodec(name);
65
- }
66
- findCodecType(name) {
67
- const normalizedName = normalizeCodecName(name);
68
- const $knownCodec = looseTypeCodecs[normalizedName];
69
- if ($knownCodec) {
70
- return {
71
- name: normalizedName,
72
- $codec: $knownCodec,
73
- typeIn: `${name}Like`,
74
- typeOut: name,
75
- };
76
- }
77
- const $codec = this.findCodec(name);
78
- if ($codec.nativeType && $[name]) {
79
- return {
80
- name: normalizedName,
81
- $codec,
82
- typeIn: $codec.nativeType,
83
- typeOut: $codec.nativeType,
84
- };
85
- }
86
- return {
87
- name: normalizedName,
88
- $codec,
89
- typeIn: name,
90
- typeOut: name,
91
- };
92
- }
93
- #findKnownCodec(typeName) {
94
- // @ts-ignore
95
- const $codec = this.#findKnownWrapperCodec(typeName) || Codecs[normalizeCodecName(typeName)] || $[typeName];
96
- if (!$codec) {
97
- throw new Error(`Unsupported codec - ${typeName}`);
98
- }
99
- // This only works with top-level $.deferred codecs
100
- // We should make it work for nested $.deferred codecs as well
101
- if ($codec.metadata && $codec.metadata[0].name === '$.deferred') {
102
- const getShape = $codec.metadata[0].args[0];
103
- return $.deferred(() => getShape(this));
104
- }
105
- return $codec;
106
- }
107
- #findKnownWrapperCodec(typeName) {
108
- const matchNames = typeName.match(WRAPPER_TYPE_REGEX);
109
- if (matchNames) {
110
- const [_, wrapper, inner] = matchNames;
111
- if (KNOWN_WRAPPER_TYPES.includes(wrapper)) {
112
- // @ts-ignore
113
- const $Wrapper = $[wrapper];
114
- if (inner.match(TUPLE_TYPE_REGEX) || inner.match(WRAPPER_TYPE_REGEX)) {
115
- return $Wrapper(this.#findKnownWrapperCodec(inner));
116
- }
117
- const $inners = inner.split(',').map((one) => this.#findKnownCodec(one.trim()));
118
- return $Wrapper(...$inners);
119
- }
120
- throw new Error(`Unknown wrapper type ${wrapper} from ${typeName}`);
121
- }
122
- else if (typeName.match(TUPLE_TYPE_REGEX)) {
123
- const $inner = typeName
124
- .slice(1, -1)
125
- .split(',')
126
- .filter((x) => x)
127
- .map((one) => this.#findKnownCodec(one.trim()));
128
- return $.Tuple(...$inner);
129
- }
130
- }
131
- isKnownType(path) {
132
- const joinedPath = Array.isArray(path) ? path.join('::') : path;
133
- return KNOWN_PATHS.some((one) => joinedPath.match(one));
134
- }
135
- }
@@ -1 +0,0 @@
1
- export * from './KnownCodecRegistry';
package/helpers/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './KnownCodecRegistry';
package/packageInfo.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare const packageInfo: {
2
- name: string;
3
- version: string;
4
- };
package/packageInfo.js DELETED
@@ -1,2 +0,0 @@
1
- // THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
2
- export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.26' };
package/templates/rpc.hbs DELETED
@@ -1,7 +0,0 @@
1
- // Generated by @dedot/codegen
2
-
3
- {{{ importTypes }}}
4
-
5
- export interface RpcCalls extends GenericRpcCalls {
6
- {{{rpcCallsOut}}}
7
- }
package/types.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { AnyShape } from '@dedot/shape';
2
- export type NetworkInfo = {
3
- chain: string;
4
- endpoint?: string;
5
- metadataHex?: string;
6
- rpcMethods?: string[];
7
- };
8
- export type CodecName = `$${string}`;
9
- export interface CodecType {
10
- name: CodecName;
11
- $codec: AnyShape;
12
- typeIn: string;
13
- typeOut: string;
14
- }
package/types.js DELETED
@@ -1 +0,0 @@
1
- export {};