From 6d1b9cbfb256617762f8d9bdec4ecff297c75a50 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 18 Dec 2021 12:15:15 +0100 Subject: [PATCH] Split rpc augmentation (#4349) * Split rpc augmentation * CC * Split augmentation trigger * Exports --- .codeclimate.yml | 1 + packages/api-augment/package.json | 3 +- packages/api-augment/src/bundle.ts | 7 +- packages/api-augment/src/types.ts | 12 ++ packages/api-derive/package.json | 1 + packages/api-derive/src/augment.ts | 5 + packages/api-derive/src/types.ts | 2 +- packages/api/src/augment.ts | 5 + packages/api/src/types.ts | 6 +- packages/rpc-augment/LICENSE | 201 ++++++++++++++++++ packages/rpc-augment/README.md | 3 + packages/rpc-augment/package.json | 30 +++ packages/rpc-augment/src/augment/index.ts | 5 + .../src/augment/rpc.ts | 4 +- packages/rpc-augment/src/bundle.ts | 9 + packages/rpc-augment/src/detectPackage.ts | 9 + packages/rpc-augment/src/index.ts | 6 + packages/rpc-augment/src/packageInfo.ts | 6 + packages/rpc-augment/src/types.ts | 16 ++ packages/rpc-augment/tsconfig.json | 11 + packages/rpc-core/package.json | 1 + packages/rpc-core/src/augment.ts | 4 + packages/rpc-core/src/cached.spec.ts | 2 +- packages/rpc-core/src/replay.spec.ts | 2 +- packages/rpc-core/src/types.jsonrpc.ts | 12 -- packages/rpc-core/src/types.ts | 17 +- packages/rpc-core/tsconfig.json | 1 + packages/typegen/package.json | 1 + packages/typegen/scripts/aliases.cjs | 1 + packages/typegen/src/generate/rpc.ts | 4 +- packages/typegen/src/templates/rpc.hbs | 2 +- rollup.config.mjs | 2 +- tsconfig.base.json | 2 + tsconfig.eslint.json | 6 +- tsconfig.json | 1 + yarn.lock | 14 +- 36 files changed, 365 insertions(+), 49 deletions(-) create mode 100644 packages/api-augment/src/types.ts create mode 100644 packages/api-derive/src/augment.ts create mode 100644 packages/api/src/augment.ts create mode 100644 packages/rpc-augment/LICENSE create mode 100644 packages/rpc-augment/README.md create mode 100644 packages/rpc-augment/package.json create mode 100644 packages/rpc-augment/src/augment/index.ts rename packages/{api-augment => rpc-augment}/src/augment/rpc.ts (99%) create mode 100644 packages/rpc-augment/src/bundle.ts create mode 100644 packages/rpc-augment/src/detectPackage.ts create mode 100644 packages/rpc-augment/src/index.ts create mode 100644 packages/rpc-augment/src/packageInfo.ts create mode 100644 packages/rpc-augment/src/types.ts create mode 100644 packages/rpc-augment/tsconfig.json create mode 100644 packages/rpc-core/src/augment.ts delete mode 100644 packages/rpc-core/src/types.jsonrpc.ts diff --git a/.codeclimate.yml b/.codeclimate.yml index 394f70db32..d46eadcd48 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -20,6 +20,7 @@ exclude_patterns: - "docs/**/*.js" - "docs/**/*.ts" - "packages/api-augment/" +- "packages/rpc-augment/" - "packages/typegen/scripts" - "packages/typegen/src" - "packages/types/src/interfaces/" diff --git a/packages/api-augment/package.json b/packages/api-augment/package.json index 26f1a7f126..75e72e4b71 100644 --- a/packages/api-augment/package.json +++ b/packages/api-augment/package.json @@ -26,7 +26,6 @@ "@babel/runtime": "^7.16.5", "@polkadot/api-base": "6.12.2-13", "@polkadot/rpc-core": "6.12.2-13", - "@polkadot/types": "6.12.2-13", - "@polkadot/util": "^8.1.2" + "@polkadot/types": "6.12.2-13" } } diff --git a/packages/api-augment/src/bundle.ts b/packages/api-augment/src/bundle.ts index c616ab3b87..2a2ed3266c 100644 --- a/packages/api-augment/src/bundle.ts +++ b/packages/api-augment/src/bundle.ts @@ -6,9 +6,4 @@ import '@polkadot/api-augment/augment'; export { packageInfo } from './packageInfo'; -// Important: we do the exports here via the full package name -export * from '@polkadot/api-augment/consts'; -export * from '@polkadot/api-augment/errors'; -export * from '@polkadot/api-augment/events'; -export * from '@polkadot/api-augment/query'; -export * from '@polkadot/api-augment/tx'; +export * from './types'; diff --git a/packages/api-augment/src/types.ts b/packages/api-augment/src/types.ts new file mode 100644 index 0000000000..baa1a40afe --- /dev/null +++ b/packages/api-augment/src/types.ts @@ -0,0 +1,12 @@ +// Copyright 2017-2021 @polkadot/api-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// trigger in the same way as we do externally +import '@polkadot/api-augment/augment'; + +// Important: we do the exports here via the full package name +export * from '@polkadot/api-augment/consts'; +export * from '@polkadot/api-augment/errors'; +export * from '@polkadot/api-augment/events'; +export * from '@polkadot/api-augment/query'; +export * from '@polkadot/api-augment/tx'; diff --git a/packages/api-derive/package.json b/packages/api-derive/package.json index a78b9ec576..301be11a16 100644 --- a/packages/api-derive/package.json +++ b/packages/api-derive/package.json @@ -26,6 +26,7 @@ "@babel/runtime": "^7.16.5", "@polkadot/api-augment": "6.12.2-13", "@polkadot/api-base": "6.12.2-13", + "@polkadot/rpc-augment": "6.12.2-13", "@polkadot/rpc-core": "6.12.2-13", "@polkadot/types": "6.12.2-13", "@polkadot/types-codec": "6.12.2-13" diff --git a/packages/api-derive/src/augment.ts b/packages/api-derive/src/augment.ts new file mode 100644 index 0000000000..f0ee4b9ed0 --- /dev/null +++ b/packages/api-derive/src/augment.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import '@polkadot/api-augment/augment'; +import '@polkadot/rpc-augment/augment'; diff --git a/packages/api-derive/src/types.ts b/packages/api-derive/src/types.ts index 7d4fdf01e0..9e10b63752 100644 --- a/packages/api-derive/src/types.ts +++ b/packages/api-derive/src/types.ts @@ -1,7 +1,7 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 -import '@polkadot/api-augment/augment'; +import './augment'; import type { ApiInterfaceRx } from '@polkadot/api-base/types'; import type { u32 } from '@polkadot/types'; diff --git a/packages/api/src/augment.ts b/packages/api/src/augment.ts new file mode 100644 index 0000000000..f83e35e1f8 --- /dev/null +++ b/packages/api/src/augment.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2021 @polkadot/api authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import '@polkadot/api-augment/augment'; +import '@polkadot/rpc-augment/augment'; diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 49c3689e3c..dbf04e5c46 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -1,13 +1,12 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 -import '@polkadot/api-augment/augment'; +import './augment'; import type { QueryableConsts } from '@polkadot/api-augment/consts'; import type { DecoratedErrors } from '@polkadot/api-augment/errors'; import type { DecoratedEvents } from '@polkadot/api-augment/events'; import type { QueryableStorage } from '@polkadot/api-augment/query'; -import type { SubmittableExtrinsics } from '@polkadot/api-augment/tx'; import type { ApiInterfaceRx as ApiInterfaceBase, ApiTypes, QueryableStorageMulti } from '@polkadot/api-base/types'; import type { DeriveCustom } from '@polkadot/api-derive'; import type { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types'; @@ -21,12 +20,11 @@ import type { AllDerives } from './util/decorate'; export * from '@polkadot/api-base/types'; +export type { AugmentedConsts, AugmentedErrors, AugmentedEvents, AugmentedQueries, AugmentedSubmittables, QueryableConsts, DecoratedErrors, DecoratedEvents, QueryableStorage, QueryableStorageAt, SubmittableExtrinsics } from '@polkadot/api-augment'; export { Signer, SignerResult } from '@polkadot/types/types'; export { ApiBase } from './base'; -export type { DecoratedErrors, DecoratedEvents, QueryableConsts, QueryableStorage, SubmittableExtrinsics }; - // A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic export interface ApiInterfaceRx extends ApiInterfaceBase { derive: AllDerives<'rxjs'>; diff --git a/packages/rpc-augment/LICENSE b/packages/rpc-augment/LICENSE new file mode 100644 index 0000000000..0d381b2e97 --- /dev/null +++ b/packages/rpc-augment/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/packages/rpc-augment/README.md b/packages/rpc-augment/README.md new file mode 100644 index 0000000000..c45d91fe41 --- /dev/null +++ b/packages/rpc-augment/README.md @@ -0,0 +1,3 @@ +# @polkadot/api-augment + +Generated augmentation. diff --git a/packages/rpc-augment/package.json b/packages/rpc-augment/package.json new file mode 100644 index 0000000000..cf3d952d71 --- /dev/null +++ b/packages/rpc-augment/package.json @@ -0,0 +1,30 @@ +{ + "author": "Jaco Greeff ", + "bugs": "https://github.com/polkadot-js/api/issues", + "contributors": [], + "description": "RPC generated augmentation", + "engines": { + "node": ">=14.0.0" + }, + "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-augment#readme", + "license": "Apache-2.0", + "maintainers": [], + "name": "@polkadot/rpc-augment", + "repository": { + "directory": "packages/rpc-augment", + "type": "git", + "url": "https://github.com/polkadot-js/api.git" + }, + "sideEffects": [ + "./detectPackage.js", + "./detectPackage.cjs" + ], + "type": "module", + "version": "6.12.2-13", + "main": "index.js", + "dependencies": { + "@babel/runtime": "^7.16.5", + "@polkadot/types": "6.12.2-13", + "rxjs": "^7.4.0" + } +} diff --git a/packages/rpc-augment/src/augment/index.ts b/packages/rpc-augment/src/augment/index.ts new file mode 100644 index 0000000000..66ee8b7943 --- /dev/null +++ b/packages/rpc-augment/src/augment/index.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import '@polkadot/types/augment'; +import './rpc'; diff --git a/packages/api-augment/src/augment/rpc.ts b/packages/rpc-augment/src/augment/rpc.ts similarity index 99% rename from packages/api-augment/src/augment/rpc.ts rename to packages/rpc-augment/src/augment/rpc.ts index 0c8e235a65..78270dc70b 100644 --- a/packages/api-augment/src/augment/rpc.ts +++ b/packages/rpc-augment/src/augment/rpc.ts @@ -1,8 +1,8 @@ // Auto-generated via `yarn polkadot-types-from-chain`, do not edit /* eslint-disable */ -declare module '@polkadot/rpc-core/types.jsonrpc' { - import type { AugmentedRpc } from '@polkadot/rpc-core/types'; +declare module '@polkadot/rpc-augment/rpc' { + import type { AugmentedRpc } from '@polkadot/rpc-augment/types'; import type { Bytes, HashMap, Json, Metadata, Null, Option, StorageKey, Text, U256, U64, Vec, bool, u32, u64 } from '@polkadot/types'; import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author'; import type { EpochAuthorship } from '@polkadot/types/interfaces/babe'; diff --git a/packages/rpc-augment/src/bundle.ts b/packages/rpc-augment/src/bundle.ts new file mode 100644 index 0000000000..721652445e --- /dev/null +++ b/packages/rpc-augment/src/bundle.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// trigger in the same way as we do externally +import '@polkadot/rpc-augment/augment'; + +export { packageInfo } from './packageInfo'; + +export * from '@polkadot/rpc-augment/rpc'; diff --git a/packages/rpc-augment/src/detectPackage.ts b/packages/rpc-augment/src/detectPackage.ts new file mode 100644 index 0000000000..16d8ee2b59 --- /dev/null +++ b/packages/rpc-augment/src/detectPackage.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { packageInfo as typesInfo } from '@polkadot/types/packageInfo'; +import { detectPackage } from '@polkadot/util'; + +import { packageInfo } from './packageInfo'; + +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [typesInfo]); diff --git a/packages/rpc-augment/src/index.ts b/packages/rpc-augment/src/index.ts new file mode 100644 index 0000000000..ba005b6dd4 --- /dev/null +++ b/packages/rpc-augment/src/index.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import './detectPackage'; + +export * from './bundle'; diff --git a/packages/rpc-augment/src/packageInfo.ts b/packages/rpc-augment/src/packageInfo.ts new file mode 100644 index 0000000000..7ae35e576a --- /dev/null +++ b/packages/rpc-augment/src/packageInfo.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// Auto-generated by @polkadot/dev, do not edit + +export const packageInfo = { name: '@polkadot/rpc-augment', version: '6.12.2-13' }; diff --git a/packages/rpc-augment/src/types.ts b/packages/rpc-augment/src/types.ts new file mode 100644 index 0000000000..e984724ee3 --- /dev/null +++ b/packages/rpc-augment/src/types.ts @@ -0,0 +1,16 @@ +// Copyright 2017-2021 @polkadot/rpc-augment authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { Observable } from 'rxjs'; +import type { AnyFunction, Codec, DefinitionRpc } from '@polkadot/types/types'; + +export interface RpcInterfaceMethod { + (...params: unknown[]): Observable; + raw (...params: unknown[]): Observable; + meta: DefinitionRpc; +} + +export type AugmentedRpc = F & { + raw: (...params: Parameters) => Observable; + meta: DefinitionRpc; +}; diff --git a/packages/rpc-augment/tsconfig.json b/packages/rpc-augment/tsconfig.json new file mode 100644 index 0000000000..062eb84f27 --- /dev/null +++ b/packages/rpc-augment/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "outDir": "./build", + "rootDir": "./src" + }, + "references": [ + { "path": "../types" } + ] +} diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 630feb4fd3..7c16f70482 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -24,6 +24,7 @@ "main": "index.js", "dependencies": { "@babel/runtime": "^7.16.5", + "@polkadot/rpc-augment": "6.12.2-13", "@polkadot/rpc-provider": "6.12.2-13", "@polkadot/types": "6.12.2-13", "@polkadot/util": "^8.1.2", diff --git a/packages/rpc-core/src/augment.ts b/packages/rpc-core/src/augment.ts new file mode 100644 index 0000000000..f0ba912821 --- /dev/null +++ b/packages/rpc-core/src/augment.ts @@ -0,0 +1,4 @@ +// Copyright 2017-2021 @polkadot/rpc-core authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import '@polkadot/rpc-augment/augment'; diff --git a/packages/rpc-core/src/cached.spec.ts b/packages/rpc-core/src/cached.spec.ts index bc1658391b..d35d79708e 100644 --- a/packages/rpc-core/src/cached.spec.ts +++ b/packages/rpc-core/src/cached.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2021 @polkadot/rpc-core authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { RpcInterface } from '@polkadot/rpc-core/types.jsonrpc'; +import type { RpcInterface } from './types'; import { createTestPairs } from '@polkadot/keyring/testingPairs'; import { MockProvider } from '@polkadot/rpc-provider/mock'; diff --git a/packages/rpc-core/src/replay.spec.ts b/packages/rpc-core/src/replay.spec.ts index f6c9c16d9e..43e3f8662a 100644 --- a/packages/rpc-core/src/replay.spec.ts +++ b/packages/rpc-core/src/replay.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2021 @polkadot/rpc-core authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { RpcInterface } from '@polkadot/rpc-core/types.jsonrpc'; +import type { RpcInterface } from './types'; import { MockProvider } from '@polkadot/rpc-provider/mock'; import { TypeRegistry } from '@polkadot/types/create'; diff --git a/packages/rpc-core/src/types.jsonrpc.ts b/packages/rpc-core/src/types.jsonrpc.ts deleted file mode 100644 index fef32f27bf..0000000000 --- a/packages/rpc-core/src/types.jsonrpc.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017-2021 @polkadot/rpc-core authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { AugmentedRpc } from './types'; - -export interface RpcInterface { - [section: string]: { - [method: string]: AugmentedRpc<(...params: any[]) => any>; - } -} - -export const __PHANTOM_RPC = 'phantom-rpc'; diff --git a/packages/rpc-core/src/types.ts b/packages/rpc-core/src/types.ts index 071e232b5d..92789dc62b 100644 --- a/packages/rpc-core/src/types.ts +++ b/packages/rpc-core/src/types.ts @@ -1,18 +1,7 @@ // Copyright 2017-2021 @polkadot/rpc-core authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { Observable } from 'rxjs'; -import type { AnyFunction, Codec, DefinitionRpc } from '@polkadot/types/types'; +import './augment'; -export * from '@polkadot/rpc-core/types.jsonrpc'; - -export interface RpcInterfaceMethod { - (...params: unknown[]): Observable; - raw (...params: unknown[]): Observable; - meta: DefinitionRpc; -} - -export type AugmentedRpc = F & { - raw: (...params: Parameters) => Observable; - meta: DefinitionRpc; -}; +export type { RpcInterface } from '@polkadot/rpc-augment/rpc'; +export type { AugmentedRpc, RpcInterfaceMethod } from '@polkadot/rpc-augment/types'; diff --git a/packages/rpc-core/tsconfig.json b/packages/rpc-core/tsconfig.json index 4c160b0abd..d9c7dd7502 100644 --- a/packages/rpc-core/tsconfig.json +++ b/packages/rpc-core/tsconfig.json @@ -6,6 +6,7 @@ "rootDir": "./src" }, "references": [ + { "path": "../rpc-augment" }, { "path": "../rpc-provider" } ] } diff --git a/packages/typegen/package.json b/packages/typegen/package.json index dd9ce678a1..496a8b1fa4 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -34,6 +34,7 @@ "@babel/register": "^7.16.5", "@babel/runtime": "^7.16.5", "@polkadot/api": "6.12.2-13", + "@polkadot/rpc-augment": "6.12.2-13", "@polkadot/rpc-provider": "6.12.2-13", "@polkadot/types": "6.12.2-13", "@polkadot/types-codec": "6.12.2-13", diff --git a/packages/typegen/scripts/aliases.cjs b/packages/typegen/scripts/aliases.cjs index 7754f3921b..54006cdf97 100644 --- a/packages/typegen/scripts/aliases.cjs +++ b/packages/typegen/scripts/aliases.cjs @@ -9,6 +9,7 @@ module.exports = { '^@polkadot/api-base(.*)': './packages/api-base/src\\1', '^@polkadot/api-derive(.*)': './packages/api-derive/src\\1', '^@polkadot/api(.*)': './packages/api/src/\\1', + '^@polkadot/rpc-augment(.*)': './packages/rpc-augment/src\\1', '^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1', '^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1', '^@polkadot/types-codec(.*)': './packages/types-codec/src\\1', diff --git a/packages/typegen/src/generate/rpc.ts b/packages/typegen/src/generate/rpc.ts index a74e832ed0..c9594571b7 100644 --- a/packages/typegen/src/generate/rpc.ts +++ b/packages/typegen/src/generate/rpc.ts @@ -135,7 +135,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec types: Object.keys(imports.localTypes[packagePath]) })), { - file: '@polkadot/rpc-core/types', + file: '@polkadot/rpc-augment/types', types: ['AugmentedRpc'] } ] @@ -143,7 +143,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec }); } -export function generateDefaultRpc (dest = 'packages/api-augment/src/augment/rpc.ts', extraTypes: ExtraTypes = {}): void { +export function generateDefaultRpc (dest = 'packages/rpc-augment/src/augment/rpc.ts', extraTypes: ExtraTypes = {}): void { const { registry } = initMeta(undefined, extraTypes); generateRpcTypes( diff --git a/packages/typegen/src/templates/rpc.hbs b/packages/typegen/src/templates/rpc.hbs index 32ea9fb837..bd098792bd 100644 --- a/packages/typegen/src/templates/rpc.hbs +++ b/packages/typegen/src/templates/rpc.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/rpc-core/types.jsonrpc' { +declare module '@polkadot/rpc-augment/rpc' { {{{ importsPackage }}} export interface RpcInterface { diff --git a/rollup.config.mjs b/rollup.config.mjs index da868a02df..0ff028faaa 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -24,7 +24,7 @@ function expand (prefix, all) { const entries = [ ...expand('api', ['augment', 'base', 'derive']), - ...expand('rpc', ['core', 'provider']), + ...expand('rpc', ['augment', 'core', 'provider']), ...expand('types', ['codec', 'create', 'helpers', 'known']) ].reduce((all, p) => ({ ...all, diff --git a/tsconfig.base.json b/tsconfig.base.json index 04de989c98..061781065d 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -13,6 +13,8 @@ "@polkadot/api-contract/*": ["api-contract/src/*"], "@polkadot/api-derive": ["api-derive/src"], "@polkadot/api-derive/*": ["api-derive/src/*"], + "@polkadot/rpc-augment": ["rpc-augment/src"], + "@polkadot/rpc-augment/*": ["rpc-augment/src/*"], "@polkadot/rpc-core": ["rpc-core/src"], "@polkadot/rpc-core/*": ["rpc-core/src/*"], "@polkadot/rpc-provider": ["rpc-provider/src"], diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 57e508f8bb..43f49c8809 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -3,6 +3,10 @@ "compilerOptions": { "baseUrl": "./packages" }, - "include": ["packages/**/src/**/*", "packages/**/scripts/**/*", "packages/**/test/**/*"], + "include": [ + "packages/**/src/**/*", + "packages/**/scripts/**/*", + "packages/**/test/**/*" + ], "exclue": ["**/node_modules/**/*"] } diff --git a/tsconfig.json b/tsconfig.json index cd18c4add2..471bca48d1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ { "path": "./packages/api-contract" }, { "path": "./packages/api-contract/tsconfig.spec.json" }, { "path": "./packages/api-derive" }, + { "path": "./packages/rpc-augment" }, { "path": "./packages/rpc-core" }, { "path": "./packages/rpc-provider" }, { "path": "./packages/typegen" }, diff --git a/yarn.lock b/yarn.lock index 14a99b660e..7c3f23f0ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1875,7 +1875,6 @@ __metadata: "@polkadot/api-base": 6.12.2-13 "@polkadot/rpc-core": 6.12.2-13 "@polkadot/types": 6.12.2-13 - "@polkadot/util": ^8.1.2 languageName: unknown linkType: soft @@ -1910,6 +1909,7 @@ __metadata: "@polkadot/api": 6.12.2-13 "@polkadot/api-augment": 6.12.2-13 "@polkadot/api-base": 6.12.2-13 + "@polkadot/rpc-augment": 6.12.2-13 "@polkadot/rpc-core": 6.12.2-13 "@polkadot/types": 6.12.2-13 "@polkadot/types-codec": 6.12.2-13 @@ -2052,12 +2052,23 @@ __metadata: languageName: node linkType: hard +"@polkadot/rpc-augment@6.12.2-13, @polkadot/rpc-augment@workspace:packages/rpc-augment": + version: 0.0.0-use.local + resolution: "@polkadot/rpc-augment@workspace:packages/rpc-augment" + dependencies: + "@babel/runtime": ^7.16.5 + "@polkadot/types": 6.12.2-13 + rxjs: ^7.4.0 + languageName: unknown + linkType: soft + "@polkadot/rpc-core@6.12.2-13, @polkadot/rpc-core@workspace:packages/rpc-core": version: 0.0.0-use.local resolution: "@polkadot/rpc-core@workspace:packages/rpc-core" dependencies: "@babel/runtime": ^7.16.5 "@polkadot/keyring": ^8.1.2 + "@polkadot/rpc-augment": 6.12.2-13 "@polkadot/rpc-provider": 6.12.2-13 "@polkadot/types": 6.12.2-13 "@polkadot/util": ^8.1.2 @@ -2100,6 +2111,7 @@ __metadata: "@babel/register": ^7.16.5 "@babel/runtime": ^7.16.5 "@polkadot/api": 6.12.2-13 + "@polkadot/rpc-augment": 6.12.2-13 "@polkadot/rpc-provider": 6.12.2-13 "@polkadot/types": 6.12.2-13 "@polkadot/types-codec": 6.12.2-13