update papi to latest version

This commit is contained in:
Victor Oliva
2024-11-05 18:20:58 +01:00
parent 83210911f9
commit 479bf1226d
5 changed files with 408 additions and 329 deletions

View File

@@ -20,9 +20,9 @@
"@polkadot-api/descriptors": "file:.papi/descriptors",
"@polkadot-api/ledger-signer": "^0.1.6",
"@polkadot-api/metadata-builders": "^0.9.1",
"@polkadot-api/observable-client": "^0.5.14",
"@polkadot-api/observable-client": "^0.6.0",
"@polkadot-api/substrate-bindings": "^0.9.3",
"@polkadot-api/substrate-client": "^0.2.2",
"@polkadot-api/substrate-client": "^0.3.0",
"@polkadot-api/utils": "^0.1.2",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-label": "^2.1.0",
@@ -38,7 +38,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.454.0",
"polkadot-api": "^1.6.5",
"polkadot-api": "^1.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-portal": "^4.2.2",
@@ -52,31 +52,30 @@
"uuid": "^11.0.2"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@types/node": "^22.8.2",
"@eslint/js": "^9.14.0",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.0",
"@types/react-portal": "^4.0.7",
"@types/uuid": "^10.0.0",
"@vitejs/plugin-react": "^4.3.2",
"autoprefixer": "^10.4.20",
"eslint": "^9.11.1",
"eslint": "^9.14.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.9.0",
"globals": "^15.12.0",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"tailwindcss": "^3.4.14",
"typescript": "^5.5.3",
"typescript-eslint": "^8.12.1",
"typescript-eslint": "^8.13.0",
"vite": "^5.4.10"
},
"packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228",
"pnpm": {
"patchedDependencies": {
"react18-json-view@0.2.8": "patches/react18-json-view@0.2.8.patch",
"@polkadot-api/observable-client": "patches/@polkadot-api__observable-client.patch",
"@polkadot-api/substrate-client": "patches/@polkadot-api__substrate-client.patch"
"@polkadot-api/observable-client": "patches/@polkadot-api__observable-client.patch"
}
}
}

View File

@@ -1,5 +1,5 @@
diff --git a/dist/esm/chainHead/chainHead.mjs b/dist/esm/chainHead/chainHead.mjs
index f1962b05e17ac7c3c66c0ab453a61cbece1525e0..f9ab1b168f3b72410055cc315ba1864576254f9d 100644
index 694f29035186d89e0db3d4171d05a939f026570e..bff0a740c625f3bfb56938d2b8859d00d4a53b52 100644
--- a/dist/esm/chainHead/chainHead.mjs
+++ b/dist/esm/chainHead/chainHead.mjs
@@ -157,7 +157,7 @@ const getChainHead$ = (chainHead) => {
@@ -11,63 +11,19 @@ index f1962b05e17ac7c3c66c0ab453a61cbece1525e0..f9ab1b168f3b72410055cc315ba18645
const _storage$ = commonEnhancer(lazyFollower("storage"));
const storage$ = withOptionalHash$(
(hash, withCanonicalChain2, type, keyMapper, childTrie = null, mapper) => pinnedBlocks$.pipe(
@@ -237,11 +237,11 @@ const getChainHead$ = (chainHead) => {
runtime$,
metadata$,
header$,
- body$,
- call$: withCanonicalChain(call$),
- storage$: withCanonicalChain(storage$),
+ body$: withCanonicalChain(body$, false),
+ call$: withCanonicalChain(call$, false),
+ storage$: withCanonicalChain(storage$, false),
storageQueries$,
- eventsAt$: withCanonicalChain(eventsAt$),
+ eventsAt$: withCanonicalChain(eventsAt$, false),
trackTx$,
trackTxWithoutEvents$,
validateTx$,
diff --git a/dist/esm/getObservableClient.mjs b/dist/esm/getObservableClient.mjs
index 511be34f2b04e0125858e03ff1dfce2759d3041b..b86e02a655903e3f5277269c5f46ca03b00b7ada 100644
--- a/dist/esm/getObservableClient.mjs
+++ b/dist/esm/getObservableClient.mjs
@@ -2,15 +2,30 @@ import { getChainHead$ } from './chainHead/chainHead.mjs';
import 'rxjs';
import getBroadcastTx$ from './tx.mjs';
-const getObservableClient = ({
- chainHead,
- transaction,
- destroy
-}) => ({
- chainHead$: () => getChainHead$(chainHead),
- broadcastTx$: getBroadcastTx$(transaction),
- destroy
-});
+const clientCache = /* @__PURE__ */ new Map();
+const getObservableClient = (substrateClient) => {
+ const cached = clientCache.get(substrateClient);
+ if (cached) {
+ cached.refCount++;
+ return cached.client;
+ }
+ const destroy = () => {
+ const cached2 = clientCache.get(substrateClient);
+ if (!cached2 || cached2.refCount <= 1) {
+ clientCache.delete(substrateClient);
+ substrateClient.destroy();
+ } else {
+ cached2.refCount--;
+ }
+ };
+ const client = {
+ chainHead$: () => getChainHead$(substrateClient.chainHead),
+ broadcastTx$: getBroadcastTx$(substrateClient.transaction),
+ destroy
+ };
+ clientCache.set(substrateClient, { client, refCount: 1 });
+ return client;
+};
export { getObservableClient };
//# sourceMappingURL=getObservableClient.mjs.map
@@ -244,11 +244,11 @@ const getChainHead$ = (chainHead) => {
runtime$,
metadata$,
header$,
- body$,
- call$: withCanonicalChain(call$),
- storage$: withCanonicalChain(storage$),
+ body$: withCanonicalChain(body$, false),
+ call$: withCanonicalChain(call$, false),
+ storage$: withCanonicalChain(storage$, false),
storageQueries$,
- eventsAt$: withCanonicalChain(eventsAt$),
+ eventsAt$: withCanonicalChain(eventsAt$, false),
trackTx$,
trackTxWithoutEvents$,
validateTx$,

View File

@@ -1,42 +0,0 @@
diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs
index 67004332b2bd4d8ce97a6e2c04f64a810597a95a..6219a52e26932c9b9f698eeb2491281175660b16 100644
--- a/dist/esm/index.mjs
+++ b/dist/esm/index.mjs
@@ -8,18 +8,35 @@ import { abortablePromiseFn } from './internal-utils/abortablePromiseFn.mjs';
import { createGetChainSpec } from './chainspec.mjs';
export { AbortError } from '@polkadot-api/utils';
+const clientCache = /* @__PURE__ */ new Map();
const createClient = (provider) => {
+ const cached = clientCache.get(provider);
+ if (cached) {
+ cached.refCount++;
+ return cached.client;
+ }
const { request, disconnect } = createClient$1(provider);
- return {
+ const destroy = () => {
+ const cached2 = clientCache.get(provider);
+ if (!cached2 || cached2.refCount <= 1) {
+ clientCache.delete(provider);
+ disconnect();
+ } else {
+ cached2.refCount--;
+ }
+ };
+ const client = {
chainHead: getChainHead(request),
transaction: getTransaction(request),
getChainSpecData: createGetChainSpec(request),
- destroy: disconnect,
+ destroy,
request: abortablePromiseFn(
(onSuccess, onError, method, params) => request(method, params, { onSuccess, onError })
),
_request: request
};
+ clientCache.set(provider, { client, refCount: 1 });
+ return client;
};
export { createClient };

585
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -58,14 +58,16 @@ export const chainClient$ = state(
selectedSource$.pipe(
map((src) => [src.id, getProvider(src)] as const),
switchMap(([id, provider]) => {
const client = createClient(provider)
const substrateClient = createSubstrateClient(provider)
const observableClient = getObservableClient(substrateClient)
const chainHead = observableClient.chainHead$(2)
const client = createClient(provider)
return concat(
of({ id, client, substrateClient, observableClient }),
of({ id, client, substrateClient, observableClient, chainHead }),
NEVER,
).pipe(
finalize(() => {
chainHead.unfollow()
client.destroy()
observableClient.destroy()
}),
@@ -74,12 +76,7 @@ export const chainClient$ = state(
),
)
export const chainHead$ = state(
chainClient$.pipe(
switchMap(({ observableClient }) => {
const chainHead = observableClient.chainHead$()
return concat(of(chainHead), NEVER).pipe(finalize(chainHead.unfollow))
}),
),
chainClient$.pipe(map(({ chainHead }) => chainHead)),
)
export const unsafeApi$ = chainClient$.pipeState(