@dedot/api 0.8.0 → 0.8.1-next.4880b708.2
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.
|
@@ -87,13 +87,44 @@ class BaseSubstrateClient extends index_js_2.JsonRpcClient {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
if (shouldUpdateCache && this._localCache) {
|
|
90
|
-
|
|
90
|
+
const encodedMetadata = (0, utils_1.u8aToHex)(codecs_1.$Metadata.tryEncode(metadata));
|
|
91
|
+
await this.safeSetMetadataToCache(metadataKey, encodedMetadata);
|
|
91
92
|
}
|
|
92
93
|
if (!metadata) {
|
|
93
94
|
throw new Error('Cannot load metadata');
|
|
94
95
|
}
|
|
95
96
|
this.setMetadata(metadata);
|
|
96
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Safely set metadata to cache with fallback cleanup if storage limit is exceeded
|
|
100
|
+
*/
|
|
101
|
+
async safeSetMetadataToCache(key, value) {
|
|
102
|
+
if (!this._localCache)
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
// First attempt to set the metadata
|
|
106
|
+
await this._localCache.set(key, value);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.warn('Failed to store metadata in cache, attempting to clean up old entries:', error);
|
|
110
|
+
try {
|
|
111
|
+
// Get all keys that start with RAW_META/
|
|
112
|
+
const allKeys = await this._localCache.keys();
|
|
113
|
+
const metadataKeys = allKeys.filter(k => k.startsWith('RAW_META/') && k !== key);
|
|
114
|
+
// Remove all other metadata entries
|
|
115
|
+
for (const metaKey of metadataKeys) {
|
|
116
|
+
await this._localCache.remove(metaKey);
|
|
117
|
+
}
|
|
118
|
+
console.info(`Cleaned up ${metadataKeys.length} old metadata entries, trying again`);
|
|
119
|
+
// Try again after cleanup
|
|
120
|
+
await this._localCache.set(key, value);
|
|
121
|
+
}
|
|
122
|
+
catch (cleanupError) {
|
|
123
|
+
// If it still fails after cleanup, log the error but continue
|
|
124
|
+
console.error('Failed to store metadata even after cleanup:', cleanupError);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
97
128
|
setMetadata(metadata) {
|
|
98
129
|
this._metadata = metadata;
|
|
99
130
|
this._registry = new codecs_1.PortableRegistry(metadata.latest, this.options.hasher);
|
|
@@ -24,6 +24,10 @@ export declare abstract class BaseSubstrateClient<Rv extends RpcVersion, ChainAp
|
|
|
24
24
|
protected normalizeOptions(options: ApiOptions | JsonRpcProvider): ApiOptions;
|
|
25
25
|
protected initializeLocalCache(): Promise<void>;
|
|
26
26
|
protected setupMetadata(preloadMetadata: Metadata | undefined): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Safely set metadata to cache with fallback cleanup if storage limit is exceeded
|
|
29
|
+
*/
|
|
30
|
+
protected safeSetMetadataToCache(key: string, value: string): Promise<void>;
|
|
27
31
|
protected setMetadata(metadata: Metadata): void;
|
|
28
32
|
protected getMetadataKey(runtime?: SubstrateRuntimeVersion): MetadataKey;
|
|
29
33
|
get currentMetadataKey(): string;
|
|
@@ -83,13 +83,44 @@ export class BaseSubstrateClient extends JsonRpcClient {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
if (shouldUpdateCache && this._localCache) {
|
|
86
|
-
|
|
86
|
+
const encodedMetadata = u8aToHex($Metadata.tryEncode(metadata));
|
|
87
|
+
await this.safeSetMetadataToCache(metadataKey, encodedMetadata);
|
|
87
88
|
}
|
|
88
89
|
if (!metadata) {
|
|
89
90
|
throw new Error('Cannot load metadata');
|
|
90
91
|
}
|
|
91
92
|
this.setMetadata(metadata);
|
|
92
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Safely set metadata to cache with fallback cleanup if storage limit is exceeded
|
|
96
|
+
*/
|
|
97
|
+
async safeSetMetadataToCache(key, value) {
|
|
98
|
+
if (!this._localCache)
|
|
99
|
+
return;
|
|
100
|
+
try {
|
|
101
|
+
// First attempt to set the metadata
|
|
102
|
+
await this._localCache.set(key, value);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.warn('Failed to store metadata in cache, attempting to clean up old entries:', error);
|
|
106
|
+
try {
|
|
107
|
+
// Get all keys that start with RAW_META/
|
|
108
|
+
const allKeys = await this._localCache.keys();
|
|
109
|
+
const metadataKeys = allKeys.filter(k => k.startsWith('RAW_META/') && k !== key);
|
|
110
|
+
// Remove all other metadata entries
|
|
111
|
+
for (const metaKey of metadataKeys) {
|
|
112
|
+
await this._localCache.remove(metaKey);
|
|
113
|
+
}
|
|
114
|
+
console.info(`Cleaned up ${metadataKeys.length} old metadata entries, trying again`);
|
|
115
|
+
// Try again after cleanup
|
|
116
|
+
await this._localCache.set(key, value);
|
|
117
|
+
}
|
|
118
|
+
catch (cleanupError) {
|
|
119
|
+
// If it still fails after cleanup, log the error but continue
|
|
120
|
+
console.error('Failed to store metadata even after cleanup:', cleanupError);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
93
124
|
setMetadata(metadata) {
|
|
94
125
|
this._metadata = metadata;
|
|
95
126
|
this._registry = new PortableRegistry(metadata.latest, this.options.hasher);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-next.4880b708.2+4880b70",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/api",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.8.
|
|
17
|
-
"@dedot/providers": "0.8.
|
|
18
|
-
"@dedot/runtime-specs": "0.8.
|
|
19
|
-
"@dedot/shape": "0.8.
|
|
20
|
-
"@dedot/storage": "0.8.
|
|
21
|
-
"@dedot/types": "0.8.
|
|
22
|
-
"@dedot/utils": "0.8.
|
|
16
|
+
"@dedot/codecs": "0.8.1-next.4880b708.2+4880b70",
|
|
17
|
+
"@dedot/providers": "0.8.1-next.4880b708.2+4880b70",
|
|
18
|
+
"@dedot/runtime-specs": "0.8.1-next.4880b708.2+4880b70",
|
|
19
|
+
"@dedot/shape": "0.8.1-next.4880b708.2+4880b70",
|
|
20
|
+
"@dedot/storage": "0.8.1-next.4880b708.2+4880b70",
|
|
21
|
+
"@dedot/types": "0.8.1-next.4880b708.2+4880b70",
|
|
22
|
+
"@dedot/utils": "0.8.1-next.4880b708.2+4880b70"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "4880b708ff98e75c257bf82ec80b3d63b0fb1458",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|