polkadot-api 1.3.3 → 1.4.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/dist/index.d.ts CHANGED
@@ -66,9 +66,13 @@ type EventsFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = E
66
66
  type ErrorsFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractPlain<T["__error"]>;
67
67
  type ConstFromPalletsDef<T extends PalletsTypedef<any, any, any, any, any>> = ExtractPlain<T["__const"]>;
68
68
 
69
+ declare class RuntimeToken<D = unknown> {
70
+ private constructor();
71
+ protected _runtime(value: D): void;
72
+ }
69
73
  declare class CompatibilityToken<D = unknown> {
70
74
  private constructor();
71
- protected _phantom(value: D): void;
75
+ protected _compatibility(value: D): void;
72
76
  }
73
77
  interface CompatibilityFunctions<D> {
74
78
  /**
@@ -103,9 +107,24 @@ interface CompatibilityFunctions<D> {
103
107
  isCompatible(threshold: CompatibilityLevel, compatibilityToken: CompatibilityToken<D>): boolean;
104
108
  }
105
109
 
106
- interface ConstantEntry<D, T> extends CompatibilityFunctions<D> {
110
+ type ConstantEntry<Unsafe, D, T> = Unsafe extends true ? {
111
+ /**
112
+ * Constants are simple key-value structures found in the runtime
113
+ * metadata.
114
+ *
115
+ * @returns Promise that will resolve in the value of the constant.
116
+ */
117
+ (): Promise<T>;
107
118
  /**
108
- * Constants are simple key-value structures found in the runtime metadata.
119
+ * @param runtimeToken Token from got with `await
120
+ * typedApi.runtimeToken`
121
+ * @returns Synchronously returns value of the constant.
122
+ */
123
+ (runtimeToken: RuntimeToken): T;
124
+ } : {
125
+ /**
126
+ * Constants are simple key-value structures found in the runtime
127
+ * metadata.
109
128
  *
110
129
  * @returns Promise that will resolve in the value of the constant.
111
130
  */
@@ -116,7 +135,7 @@ interface ConstantEntry<D, T> extends CompatibilityFunctions<D> {
116
135
  * @returns Synchronously returns value of the constant.
117
136
  */
118
137
  (compatibilityToken: CompatibilityToken): T;
119
- }
138
+ } & CompatibilityFunctions<D>;
120
139
 
121
140
  type EventPhase = {
122
141
  type: "ApplyExtrinsic";
@@ -141,7 +160,7 @@ type EvPull<T> = () => Promise<Array<{
141
160
  payload: T;
142
161
  }>>;
143
162
  type EvFilter<T> = (collection: SystemEvent["event"][]) => Array<T>;
144
- type EvClient<D, T> = {
163
+ type EvClient<Unsafe, D, T> = {
145
164
  /**
146
165
  * Multicast and stateful Observable watching for new events (matching the
147
166
  * event kind chosen) in the latest known `finalized` block.
@@ -162,7 +181,7 @@ type EvClient<D, T> = {
162
181
  * @param collection Array of `SystemEvent` to filter.
163
182
  */
164
183
  filter: EvFilter<T>;
165
- } & CompatibilityFunctions<D>;
184
+ } & (Unsafe extends true ? {} : CompatibilityFunctions<D>);
166
185
  type SystemEvent = {
167
186
  phase: EventPhase;
168
187
  event: {
@@ -180,7 +199,7 @@ type CallOptions$1 = Partial<{
180
199
  signal: AbortSignal;
181
200
  }>;
182
201
  type WithCallOptions$1<Args extends Array<any>> = Args["length"] extends 0 ? [options?: CallOptions$1] : [...args: Args, options?: CallOptions$1];
183
- interface RuntimeCall<D, Args extends Array<any>, Payload> extends CompatibilityFunctions<D> {
202
+ type RuntimeCall<Unsafe, D, Args extends Array<any>, Payload> = {
184
203
  /**
185
204
  * Get `Payload` (Promise-based) for the runtime call.
186
205
  *
@@ -189,7 +208,7 @@ interface RuntimeCall<D, Args extends Array<any>, Payload> extends Compatibility
189
208
  * known finalized is the default) and an AbortSignal.
190
209
  */
191
210
  (...args: WithCallOptions$1<Args>): Promise<Payload>;
192
- }
211
+ } & (Unsafe extends true ? {} : CompatibilityFunctions<D>);
193
212
 
194
213
  type CallOptions = Partial<{
195
214
  /**
@@ -211,7 +230,7 @@ type PossibleParents<A extends Array<any>> = A extends [...infer Left, any] ? Le
211
230
  type ArrayPossibleParents<A extends Array<any>, Count extends Array<any> = [], R = []> = A extends Array<infer T> & {
212
231
  length: infer L;
213
232
  } ? number extends L ? Array<T> : L extends Count["length"] ? R : ArrayPossibleParents<A, [...Count, T], R | Count> : never;
214
- type StorageEntryWithoutKeys<D, Payload> = {
233
+ type StorageEntryWithoutKeys<Unsafe, D, Payload> = {
215
234
  /**
216
235
  * Get `Payload` (Promise-based) for the storage entry.
217
236
  *
@@ -226,8 +245,8 @@ type StorageEntryWithoutKeys<D, Payload> = {
226
245
  * changes, `best` or `finalized` (default)
227
246
  */
228
247
  watchValue: (bestOrFinalized?: "best" | "finalized") => Observable<Payload>;
229
- } & CompatibilityFunctions<D>;
230
- type StorageEntryWithKeys<D, Args extends Array<any>, Payload> = {
248
+ } & (Unsafe extends true ? {} : CompatibilityFunctions<D>);
249
+ type StorageEntryWithKeys<Unsafe, D, Args extends Array<any>, Payload> = {
231
250
  /**
232
251
  * Get `Payload` (Promise-based) for the storage entry with a specific set of
233
252
  * `Args`.
@@ -273,8 +292,8 @@ type StorageEntryWithKeys<D, Args extends Array<any>, Payload> = {
273
292
  keyArgs: Args;
274
293
  value: NonNullable<Payload>;
275
294
  }>>;
276
- } & CompatibilityFunctions<D>;
277
- type StorageEntry<D, Args extends Array<any>, Payload> = Args extends [] ? StorageEntryWithoutKeys<D, Payload> : StorageEntryWithKeys<D, Args, Payload>;
295
+ } & (Unsafe extends true ? {} : CompatibilityFunctions<D>);
296
+ type StorageEntry<Unsafe, D, Args extends Array<any>, Payload> = Args extends [] ? StorageEntryWithoutKeys<Unsafe, D, Payload> : StorageEntryWithKeys<Unsafe, D, Args, Payload>;
278
297
 
279
298
  type TxEvent = TxSigned | TxBroadcasted | TxBestBlocksState | TxFinalized;
280
299
  type TxBroadcastEvent = TxSigned | TxBroadcasted | TxBestBlocksState | TxFinalized;
@@ -410,6 +429,21 @@ interface TxCall {
410
429
  */
411
430
  (compatibilityToken: CompatibilityToken): Binary;
412
431
  }
432
+ interface UnsafeTxCall {
433
+ /**
434
+ * SCALE-encoded callData of the transaction.
435
+ *
436
+ * @returns Promise resolving in the encoded data.
437
+ */
438
+ (): Promise<Binary>;
439
+ /**
440
+ * SCALE-encoded callData of the transaction.
441
+ *
442
+ * @param runtimeToken Token from got with `await typedApi.runtimeToken`
443
+ * @returns Synchronously returns encoded data.
444
+ */
445
+ (runtimeToken: RuntimeToken): Binary;
446
+ }
413
447
  type TxSignFn<Asset> = (from: PolkadotSigner, txOptions?: TxOptions<Asset>) => Promise<HexString>;
414
448
  type PaymentInfo = {
415
449
  weight: {
@@ -423,7 +457,7 @@ type PaymentInfo = {
423
457
  }>;
424
458
  partial_fee: bigint;
425
459
  };
426
- type Transaction<Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = {
460
+ type InnerTransaction<Unsafe, Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = {
427
461
  /**
428
462
  * Pack the transaction, sends it to the signer, and return the signature
429
463
  * asynchronously. If the signer fails (or the user cancels the signature)
@@ -459,7 +493,7 @@ type Transaction<Arg extends {} | undefined, Pallet extends string, Name extends
459
493
  /**
460
494
  * SCALE-encoded callData of the transaction.
461
495
  */
462
- getEncodedData: TxCall;
496
+ getEncodedData: Unsafe extends true ? UnsafeTxCall : TxCall;
463
497
  /**
464
498
  * Estimate fees against the latest known `finalizedBlock`
465
499
  *
@@ -487,43 +521,75 @@ type Transaction<Arg extends {} | undefined, Pallet extends string, Name extends
487
521
  }>;
488
522
  }>;
489
523
  };
490
- interface TxEntry<D, Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> extends CompatibilityFunctions<D> {
524
+ type Transaction<Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = InnerTransaction<false, Arg, Pallet, Name, Asset>;
525
+ type UnsafeTransaction<Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = InnerTransaction<true, Arg, Pallet, Name, Asset>;
526
+ type InnerTxEntry<Unsafe, D, Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = Unsafe extends true ? {
527
+ /**
528
+ * Synchronously create the transaction object ready to sign, submit,
529
+ * estimate fees, etc.
530
+ *
531
+ * @param args All parameters required by the transaction.
532
+ * @returns Transaction object.
533
+ */
534
+ (...args: Arg extends undefined ? [] : [data: Arg]): UnsafeTransaction<Arg, Pallet, Name, Asset>;
535
+ } : {
491
536
  /**
492
- * Synchronously create the transaction object ready to sign, submit, estimate
493
- * fees, etc.
537
+ * Synchronously create the transaction object ready to sign, submit,
538
+ * estimate fees, etc.
494
539
  *
495
540
  * @param args All parameters required by the transaction.
496
541
  * @returns Transaction object.
497
542
  */
498
543
  (...args: Arg extends undefined ? [] : [data: Arg]): Transaction<Arg, Pallet, Name, Asset>;
499
- }
500
- interface TxFromBinary<Asset> {
544
+ } & CompatibilityFunctions<D>;
545
+ type TxEntry<D, Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = InnerTxEntry<false, D, Arg, Pallet, Name, Asset>;
546
+ type UnsafeTxEntry<D, Arg extends {} | undefined, Pallet extends string, Name extends string, Asset> = InnerTxEntry<true, D, Arg, Pallet, Name, Asset>;
547
+ type TxFromBinary<Unsafe, Asset> = Unsafe extends true ? {
501
548
  /**
502
- * Asynchronously create the transaction object from a binary call data ready
503
- * to sign, submit, estimate fees, etc.
549
+ * Asynchronously create the transaction object from a binary call data
550
+ * ready to sign, submit, estimate fees, etc.
504
551
  *
505
552
  * @param callData SCALE-encoded call data.
506
553
  * @returns Transaction object.
507
554
  */
508
- (callData: Binary): Promise<Transaction<any, any, any, Asset>>;
555
+ (callData: Binary): Promise<UnsafeTransaction<any, string, string, Asset>>;
556
+ /**
557
+ * Synchronously create the transaction object from a binary call data
558
+ * ready to sign, submit, estimate fees, etc.
559
+ *
560
+ * @param callData SCALE-encoded call data.
561
+ * @param runtimeToken Token from got with `await
562
+ * typedApi.runtimeToken`
563
+ * @returns Transaction object.
564
+ */
565
+ (callData: Binary, runtimeToken: RuntimeToken): UnsafeTransaction<any, string, string, Asset>;
566
+ } : {
509
567
  /**
510
- * Synchronously create the transaction object from a binary call data ready
511
- * to sign, submit, estimate fees, etc.
568
+ * Asynchronously create the transaction object from a binary call data
569
+ * ready to sign, submit, estimate fees, etc.
570
+ *
571
+ * @param callData SCALE-encoded call data.
572
+ * @returns Transaction object.
573
+ */
574
+ (callData: Binary): Promise<Transaction<any, string, string, Asset>>;
575
+ /**
576
+ * Synchronously create the transaction object from a binary call data
577
+ * ready to sign, submit, estimate fees, etc.
512
578
  *
513
579
  * @param callData SCALE-encoded call data.
514
580
  * @param compatibilityToken Token from got with `await
515
581
  * typedApi.compatibilityToken`
516
582
  * @returns Transaction object.
517
583
  */
518
- (callData: Binary, compatibilityToken: CompatibilityToken): Transaction<any, any, any, Asset>;
519
- }
584
+ (callData: Binary, compatibilityToken: CompatibilityToken): Transaction<any, string, string, Asset>;
585
+ };
520
586
 
521
587
  declare class InvalidTxError extends Error {
522
588
  error: any;
523
589
  constructor(e: any);
524
590
  }
525
591
 
526
- type StorageApi<D, A extends Record<string, Record<string, {
592
+ type StorageApi<Unsafe, D, A extends Record<string, Record<string, {
527
593
  KeyArgs: Array<any>;
528
594
  Value: any;
529
595
  IsOptional: false | true;
@@ -533,38 +599,51 @@ type StorageApi<D, A extends Record<string, Record<string, {
533
599
  KeyArgs: Array<any>;
534
600
  Value: any;
535
601
  IsOptional: false | true;
536
- } ? StorageEntry<D, A[K][KK]["KeyArgs"], A[K][KK]["IsOptional"] extends true ? A[K][KK]["Value"] | undefined : A[K][KK]["Value"]> : unknown;
602
+ } ? StorageEntry<Unsafe, D, A[K][KK]["KeyArgs"], A[K][KK]["IsOptional"] extends true ? A[K][KK]["Value"] | undefined : A[K][KK]["Value"]> : unknown;
537
603
  };
538
604
  };
539
- type RuntimeCallsApi<D, A extends Record<string, Record<string, RuntimeDescriptor<Array<any>, any>>>> = {
605
+ type RuntimeCallsApi<Unsafe, D, A extends Record<string, Record<string, RuntimeDescriptor<Array<any>, any>>>> = {
540
606
  [K in keyof A]: {
541
- [KK in keyof A[K]]: A[K][KK] extends RuntimeDescriptor<infer Args, infer Value> ? RuntimeCall<D, Args, Value> : unknown;
607
+ [KK in keyof A[K]]: A[K][KK] extends RuntimeDescriptor<infer Args, infer Value> ? RuntimeCall<Unsafe, D, Args, Value> : unknown;
542
608
  };
543
609
  };
544
- type TxApi<D, A extends Record<string, Record<string, any>>, Asset> = {
610
+ type TxApi<Unsafe, D, A extends Record<string, Record<string, any>>, Asset> = {
545
611
  [K in keyof A]: {
546
- [KK in keyof A[K]]: A[K][KK] extends {} | undefined ? TxEntry<D, A[K][KK], K & string, KK & string, Asset> : unknown;
612
+ [KK in keyof A[K]]: A[K][KK] extends {} | undefined ? InnerTxEntry<Unsafe, D, A[K][KK], K & string, KK & string, Asset> : unknown;
547
613
  };
548
614
  };
549
- type EvApi<D, A extends Record<string, Record<string, any>>> = {
615
+ type EvApi<Unsafe, D, A extends Record<string, Record<string, any>>> = {
550
616
  [K in keyof A]: {
551
- [KK in keyof A[K]]: EvClient<D, A[K][KK]>;
617
+ [KK in keyof A[K]]: EvClient<Unsafe, D, A[K][KK]>;
552
618
  };
553
619
  };
554
- type ConstApi<D, A extends Record<string, Record<string, any>>> = {
620
+ type ConstApi<Unsafe, D, A extends Record<string, Record<string, any>>> = {
555
621
  [K in keyof A]: {
556
- [KK in keyof A[K]]: ConstantEntry<D, A[K][KK]>;
622
+ [KK in keyof A[K]]: ConstantEntry<Unsafe, D, A[K][KK]>;
557
623
  };
558
624
  };
559
- type TypedApi<D extends ChainDefinition> = {
560
- query: StorageApi<D, QueryFromPalletsDef<D["descriptors"]["pallets"]>>;
561
- tx: TxApi<D, TxFromPalletsDef<D["descriptors"]["pallets"]>, D["asset"]["_type"]>;
562
- txFromCallData: TxFromBinary<D["asset"]["_type"]>;
563
- event: EvApi<D, EventsFromPalletsDef<D["descriptors"]["pallets"]>>;
564
- apis: RuntimeCallsApi<D, D["descriptors"]["apis"]>;
565
- constants: ConstApi<D, ConstFromPalletsDef<D["descriptors"]["pallets"]>>;
625
+ type UnsafeEntry<T> = Record<string, Record<string, T>>;
626
+ type AnyApi<Unsafe extends true | false, D> = D extends ChainDefinition ? {
627
+ query: StorageApi<Unsafe, D, QueryFromPalletsDef<D["descriptors"]["pallets"]>>;
628
+ tx: TxApi<Unsafe, D, TxFromPalletsDef<D["descriptors"]["pallets"]>, D["asset"]["_type"]>;
629
+ txFromCallData: TxFromBinary<Unsafe, D["asset"]["_type"]>;
630
+ event: EvApi<Unsafe, D, EventsFromPalletsDef<D["descriptors"]["pallets"]>>;
631
+ apis: RuntimeCallsApi<Unsafe, D, D["descriptors"]["apis"]>;
632
+ constants: ConstApi<Unsafe, D, ConstFromPalletsDef<D["descriptors"]["pallets"]>>;
633
+ } : {
634
+ query: UnsafeEntry<StorageEntryWithKeys<true, D, any, any>>;
635
+ tx: UnsafeEntry<UnsafeTxEntry<D, any, string, string, any>>;
636
+ txFromCallData: TxFromBinary<Unsafe, any>;
637
+ event: UnsafeEntry<EvClient<true, D, any>>;
638
+ apis: UnsafeEntry<RuntimeCall<true, D, any, any>>;
639
+ constants: UnsafeEntry<ConstantEntry<true, D, any>>;
640
+ };
641
+ type TypedApi<D extends ChainDefinition> = AnyApi<false, D> & {
566
642
  compatibilityToken: Promise<CompatibilityToken<D>>;
567
643
  };
644
+ type UnsafeApi<D> = AnyApi<true, D> & {
645
+ runtimeToken: Promise<RuntimeToken<D>>;
646
+ };
568
647
  type TransactionValidityError<D extends ChainDefinition> = (D["descriptors"]["apis"]["TaggedTransactionQueue"]["validate_transaction"][1] & {
569
648
  success: false;
570
649
  })["value"];
@@ -656,6 +735,14 @@ interface PolkadotClient {
656
735
  * generated by `papi` CLI.
657
736
  */
658
737
  getTypedApi: <D extends ChainDefinition>(descriptors: D) => TypedApi<D>;
738
+ /**
739
+ * Returns an instance of a `UnsafeApi`.
740
+ *
741
+ * Note that this method is only meant for advanced users that really know
742
+ * what are they doing. This API does not provide any runtime compatibility
743
+ * checks protection and the consumer should implement them on their own.
744
+ */
745
+ getUnsafeApi: <D>() => UnsafeApi<D>;
659
746
  /**
660
747
  * This will `unfollow` the provider, disconnect and error every subscription.
661
748
  * After calling it nothing can be done with the client.
@@ -711,4 +798,4 @@ type TxCallData = {
711
798
  */
712
799
  declare function createClient(provider: JsonRpcProvider): PolkadotClient;
713
800
 
714
- export { type ApisTypedef, type ChainDefinition, CompatibilityToken, type ConstFromPalletsDef, type DescriptorEntry, type ErrorsFromPalletsDef, type EventPhase, type EventsFromPalletsDef, type FixedSizeArray, InvalidTxError, type PalletsTypedef, type PlainDescriptor, type PolkadotClient, type QueryFromPalletsDef, type RuntimeDescriptor, type StorageDescriptor, type Transaction, type TransactionValidityError, type TxBestBlocksState, type TxBroadcastEvent, type TxBroadcasted, type TxCall, type TxCallData, type TxDescriptor, type TxEntry, type TxEvent, type TxEventsPayload, type TxFinalized, type TxFinalizedPayload, type TxFromPalletsDef, type TxInBestBlocksFound, type TxInBestBlocksNotFound, type TxObservable, type TxOptions, type TxPromise, type TxSignFn, type TxSigned, type TypedApi, createClient };
801
+ export { type ApisTypedef, type ChainDefinition, CompatibilityToken, type ConstFromPalletsDef, type DescriptorEntry, type ErrorsFromPalletsDef, type EventPhase, type EventsFromPalletsDef, type FixedSizeArray, InvalidTxError, type PalletsTypedef, type PlainDescriptor, type PolkadotClient, type QueryFromPalletsDef, type RuntimeDescriptor, RuntimeToken, type StorageDescriptor, type Transaction, type TransactionValidityError, type TxBestBlocksState, type TxBroadcastEvent, type TxBroadcasted, type TxCall, type TxCallData, type TxDescriptor, type TxEntry, type TxEvent, type TxEventsPayload, type TxFinalized, type TxFinalizedPayload, type TxFromPalletsDef, type TxInBestBlocksFound, type TxInBestBlocksNotFound, type TxObservable, type TxOptions, type TxPromise, type TxSignFn, type TxSigned, type TypedApi, type UnsafeTransaction, type UnsafeTxCall, type UnsafeTxEntry, createClient };
package/dist/index.js CHANGED
@@ -9,15 +9,23 @@ var utils = require('@polkadot-api/utils');
9
9
  var signer = require('@polkadot-api/signer');
10
10
  var metadataBuilders = require('@polkadot-api/metadata-builders');
11
11
 
12
+ class RuntimeToken {
13
+ constructor() {
14
+ }
15
+ // @ts-ignore
16
+ _runtime(value) {
17
+ }
18
+ }
12
19
  class CompatibilityToken {
13
20
  constructor() {
14
21
  }
15
22
  // @ts-ignore
16
- _phantom(value) {
23
+ _compatibility(value) {
17
24
  }
18
25
  }
19
26
  const compatibilityTokenApi = /* @__PURE__ */ new WeakMap();
20
- const getCompatibilityApi = (token) => compatibilityTokenApi.get(token);
27
+ const runtimeTokenApi = /* @__PURE__ */ new WeakMap();
28
+ const getCompatibilityApi = (token) => token instanceof RuntimeToken ? runtimeTokenApi.get(token) : compatibilityTokenApi.get(token);
21
29
  var OpType = /* @__PURE__ */ ((OpType2) => {
22
30
  OpType2["Storage"] = "storage";
23
31
  OpType2["Tx"] = "tx";
@@ -55,6 +63,22 @@ const createCompatibilityToken = (chainDefinition, chainHead) => {
55
63
  });
56
64
  return promise;
57
65
  };
66
+ const createRuntimeToken = (chainHead) => {
67
+ const awaitedRuntime = new Promise(async (resolve) => {
68
+ const loadedRuntime$ = chainHead.runtime$.pipe(rxjs.filter((v) => v != null));
69
+ let latest = await rxjs.firstValueFrom(loadedRuntime$);
70
+ loadedRuntime$.subscribe((v) => latest = v);
71
+ resolve(() => latest);
72
+ });
73
+ const promise = awaitedRuntime.then((runtime) => {
74
+ const token = new RuntimeToken();
75
+ runtimeTokenApi.set(token, {
76
+ runtime
77
+ });
78
+ return token;
79
+ });
80
+ return promise;
81
+ };
58
82
  const metadataCache = /* @__PURE__ */ new WeakMap();
59
83
  const getMetadataCache = (ctx) => {
60
84
  if (!metadataCache.has(ctx.metadataRaw)) {
@@ -73,6 +97,12 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
73
97
  return (_a = cache.typeNodes)[id] || (_a[id] = metadataCompatibility.mapLookupToTypedef(cache.lookup(id)));
74
98
  };
75
99
  function getCompatibilityLevels(descriptors2, ctx) {
100
+ if (descriptors2 instanceof RuntimeToken) {
101
+ return {
102
+ args: metadataCompatibility.CompatibilityLevel.Identical,
103
+ values: metadataCompatibility.CompatibilityLevel.Identical
104
+ };
105
+ }
76
106
  const compatibilityApi = compatibilityTokenApi.get(descriptors2);
77
107
  ctx || (ctx = compatibilityApi.runtime());
78
108
  const descriptorEntryPoint = getDescriptorEntryPoint(compatibilityApi);
@@ -102,6 +132,7 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
102
132
  waitDescriptors()
103
133
  ]).pipe(rxjs.map(([[x, ctx], descriptors2]) => [x, descriptors2, ctx]));
104
134
  const argsAreCompatible = (descriptors2, ctx, args) => {
135
+ if (descriptors2 instanceof RuntimeToken) return true;
105
136
  const levels = getCompatibilityLevels(descriptors2, ctx);
106
137
  if (levels.args === metadataCompatibility.CompatibilityLevel.Incompatible) return false;
107
138
  if (levels.args > metadataCompatibility.CompatibilityLevel.Partial) return true;
@@ -114,6 +145,7 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
114
145
  );
115
146
  };
116
147
  const valuesAreCompatible = (descriptors2, ctx, values) => {
148
+ if (descriptors2 instanceof RuntimeToken) return true;
117
149
  const level = getCompatibilityLevels(descriptors2, ctx).values;
118
150
  if (level === metadataCompatibility.CompatibilityLevel.Incompatible) return false;
119
151
  if (level > metadataCompatibility.CompatibilityLevel.Partial) return true;
@@ -140,7 +172,7 @@ const compatibilityHelper = (descriptors, getDescriptorEntryPoint, getRuntimeEnt
140
172
  const minCompatLevel = (levels) => Math.min(levels.args, levels.values);
141
173
  const withOptionalToken = (compatibilityToken, fn) => (...args) => {
142
174
  const lastElement = args.at(-1);
143
- if (lastElement instanceof CompatibilityToken) {
175
+ if (lastElement instanceof CompatibilityToken || lastElement instanceof RuntimeToken) {
144
176
  return fn(...args);
145
177
  }
146
178
  return compatibilityToken.then((token) => fn(...args, token));
@@ -167,11 +199,11 @@ const createConstantEntry = (palletName, name, {
167
199
  cachedResults.set(ctx, result);
168
200
  return result;
169
201
  };
170
- const fn = (compatibilityToken) => {
171
- if (compatibilityToken) {
172
- const ctx = getCompatibilityApi(compatibilityToken).runtime();
202
+ const fn = (token) => {
203
+ if (token) {
204
+ const ctx = getCompatibilityApi(token).runtime();
173
205
  const value = getValueWithContext(ctx);
174
- if (!valuesAreCompatible(compatibilityToken, ctx, value))
206
+ if (!valuesAreCompatible(token, ctx, value))
175
207
  throw new Error(
176
208
  `Incompatible runtime entry Constant(${palletName}.${name})`
177
209
  );
@@ -980,10 +1012,10 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
980
1012
  const getCallData$ = (arg2, options = {}) => compatibleRuntime$(chainHead, null).pipe(
981
1013
  rxjs.map(([runtime]) => getCallDataWithContext(runtime, arg2, options))
982
1014
  );
983
- const getEncodedData = (compatibilityToken) => {
984
- if (!compatibilityToken)
1015
+ const getEncodedData = (token) => {
1016
+ if (!token)
985
1017
  return rxjs.firstValueFrom(getCallData$(arg).pipe(rxjs.map((x) => x.callData)));
986
- return getCallDataWithContext(compatibilityToken, arg).callData;
1018
+ return getCallDataWithContext(token, arg).callData;
987
1019
  };
988
1020
  const sign$ = (from, { ..._options }, atBlock) => getCallData$(arg, _options).pipe(
989
1021
  rxjs.mergeMap(
@@ -1058,7 +1090,7 @@ const createTxEntry = (pallet, name, chainHead, broadcast, {
1058
1090
  });
1059
1091
  };
1060
1092
 
1061
- const createTypedApi = (compatibilityToken, chainHead, broadcast$) => {
1093
+ const createApi = (compatibilityToken, chainHead, broadcast$) => {
1062
1094
  const target = {};
1063
1095
  const createProxy = (propCall) => new Proxy(target, {
1064
1096
  get(_, prop) {
@@ -1182,8 +1214,7 @@ const createTypedApi = (compatibilityToken, chainHead, broadcast$) => {
1182
1214
  tx,
1183
1215
  event,
1184
1216
  apis,
1185
- constants,
1186
- compatibilityToken
1217
+ constants
1187
1218
  };
1188
1219
  };
1189
1220
  function createClient(provider) {
@@ -1192,12 +1223,14 @@ function createClient(provider) {
1192
1223
  const chainHead = client.chainHead$();
1193
1224
  const { getChainSpecData } = rawClient;
1194
1225
  const _request = rawClient.request;
1226
+ let runtimeToken;
1195
1227
  const compatibilityToken = /* @__PURE__ */ new WeakMap();
1196
1228
  const getChainToken = (chainDefinition) => {
1197
1229
  const result = compatibilityToken.get(chainDefinition) || createCompatibilityToken(chainDefinition, chainHead);
1198
1230
  compatibilityToken.set(chainDefinition, result);
1199
1231
  return result;
1200
1232
  };
1233
+ const getRuntimeToken = () => runtimeToken ?? (runtimeToken = createRuntimeToken(chainHead));
1201
1234
  const { broadcastTx$ } = client;
1202
1235
  return {
1203
1236
  getChainSpecData,
@@ -1210,7 +1243,19 @@ function createClient(provider) {
1210
1243
  getBlockHeader: (hash) => rxjs.firstValueFrom(chainHead.header$(hash ?? null)),
1211
1244
  submit: (...args) => submit(chainHead, broadcastTx$, ...args),
1212
1245
  submitAndWatch: (...args) => submit$(chainHead, broadcastTx$, ...args),
1213
- getTypedApi: (chainDefinition) => createTypedApi(getChainToken(chainDefinition), chainHead, broadcastTx$),
1246
+ getTypedApi: (chainDefinition) => {
1247
+ const token = getChainToken(chainDefinition);
1248
+ return Object.assign(
1249
+ createApi(token, chainHead, broadcastTx$),
1250
+ { compatibilityToken: token }
1251
+ );
1252
+ },
1253
+ getUnsafeApi: () => {
1254
+ const token = getRuntimeToken();
1255
+ return Object.assign(createApi(token, chainHead, broadcastTx$), {
1256
+ runtimeToken: token
1257
+ });
1258
+ },
1214
1259
  destroy: () => {
1215
1260
  chainHead.unfollow();
1216
1261
  client.destroy();