@0xobelisk/react 1.2.0-pre.79 → 1.2.0-pre.83

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.
@@ -140,14 +140,37 @@ function useDubheConfig(config) {
140
140
  }
141
141
 
142
142
  // src/sui/provider.tsx
143
- import { createContext, useContext, useRef } from "react";
143
+ import {
144
+ createContext,
145
+ useContext,
146
+ useRef,
147
+ useState,
148
+ useCallback,
149
+ useEffect
150
+ } from "react";
144
151
  import { Dubhe } from "@0xobelisk/sui-client";
145
152
  import { createDubheGraphqlClient } from "@0xobelisk/graphql-client";
146
153
  import { createECSWorld } from "@0xobelisk/ecs";
154
+ import { DubheGrpcClient } from "@0xobelisk/grpc-client";
147
155
  import { jsx } from "react/jsx-runtime";
148
156
  var DubheContext = createContext(null);
149
157
  function DubheProvider({ config, children }) {
150
- const finalConfig = useDubheConfig(config);
158
+ const [currentConfig, setCurrentConfig] = useState(() => {
159
+ if (typeof window !== "undefined") {
160
+ try {
161
+ const saved = localStorage.getItem("dubhe-config");
162
+ if (saved) {
163
+ const parsedConfig = JSON.parse(saved);
164
+ console.log("Restored Dubhe configuration from localStorage");
165
+ return { ...config, ...parsedConfig };
166
+ }
167
+ } catch (error) {
168
+ console.warn("Failed to restore Dubhe configuration from localStorage", error);
169
+ }
170
+ }
171
+ return config;
172
+ });
173
+ const finalConfig = useDubheConfig(currentConfig);
151
174
  const startTimeRef = useRef(performance.now());
152
175
  const contractRef = useRef(void 0);
153
176
  const getContract = () => {
@@ -186,6 +209,23 @@ function DubheProvider({ config, children }) {
186
209
  }
187
210
  return graphqlClientRef.current;
188
211
  };
212
+ const grpcClientRef = useRef(null);
213
+ const hasInitializedGrpc = useRef(false);
214
+ const getGrpcClient = () => {
215
+ if (!hasInitializedGrpc.current && finalConfig.endpoints?.grpc) {
216
+ try {
217
+ console.log("Initializing gRPC client instance (one-time)");
218
+ grpcClientRef.current = new DubheGrpcClient({
219
+ baseUrl: finalConfig.endpoints.grpc
220
+ });
221
+ hasInitializedGrpc.current = true;
222
+ } catch (error) {
223
+ console.error("gRPC client initialization failed:", error);
224
+ throw error;
225
+ }
226
+ }
227
+ return grpcClientRef.current;
228
+ };
189
229
  const ecsWorldRef = useRef(null);
190
230
  const hasInitializedEcs = useRef(false);
191
231
  const getEcsWorld = () => {
@@ -220,13 +260,125 @@ function DubheProvider({ config, children }) {
220
260
  // Can be enhanced with actual tracking
221
261
  lastActivity: Date.now()
222
262
  });
263
+ const resetClients = useCallback(
264
+ (options) => {
265
+ const opts = {
266
+ resetContract: true,
267
+ resetGraphql: true,
268
+ resetGrpc: true,
269
+ resetEcs: true,
270
+ ...options
271
+ };
272
+ console.log("Resetting Dubhe client instances", opts);
273
+ if (opts.resetContract) {
274
+ contractRef.current = void 0;
275
+ }
276
+ if (opts.resetGraphql) {
277
+ graphqlClientRef.current = null;
278
+ hasInitializedGraphql.current = false;
279
+ }
280
+ if (opts.resetGrpc) {
281
+ grpcClientRef.current = null;
282
+ hasInitializedGrpc.current = false;
283
+ }
284
+ if (opts.resetEcs) {
285
+ ecsWorldRef.current = null;
286
+ hasInitializedEcs.current = false;
287
+ }
288
+ startTimeRef.current = performance.now();
289
+ },
290
+ []
291
+ );
292
+ const updateConfig = useCallback((newConfig) => {
293
+ console.log("Updating Dubhe configuration (reactive)");
294
+ setCurrentConfig((prev) => {
295
+ const updated = { ...prev, ...newConfig };
296
+ if (typeof window !== "undefined") {
297
+ try {
298
+ localStorage.setItem("dubhe-config", JSON.stringify(updated));
299
+ console.log("Persisted Dubhe configuration to localStorage");
300
+ } catch (error) {
301
+ console.warn("Failed to persist Dubhe configuration", error);
302
+ }
303
+ }
304
+ return updated;
305
+ });
306
+ }, []);
307
+ useEffect(() => {
308
+ if (contractRef.current) {
309
+ console.log("Contract config dependencies changed, updating...");
310
+ contractRef.current.updateConfig({
311
+ networkType: finalConfig.network,
312
+ packageId: finalConfig.packageId,
313
+ metadata: finalConfig.metadata,
314
+ secretKey: finalConfig.credentials?.secretKey,
315
+ mnemonics: finalConfig.credentials?.mnemonics
316
+ });
317
+ }
318
+ }, [
319
+ finalConfig.network,
320
+ finalConfig.packageId,
321
+ finalConfig.metadata,
322
+ finalConfig.credentials?.secretKey,
323
+ finalConfig.credentials?.mnemonics
324
+ ]);
325
+ useEffect(() => {
326
+ if (graphqlClientRef.current) {
327
+ console.log("GraphQL endpoint dependencies changed, updating...");
328
+ graphqlClientRef.current.updateConfig({
329
+ endpoint: finalConfig.endpoints?.graphql,
330
+ subscriptionEndpoint: finalConfig.endpoints?.websocket
331
+ });
332
+ ecsWorldRef.current = null;
333
+ hasInitializedEcs.current = false;
334
+ }
335
+ }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);
336
+ useEffect(() => {
337
+ if (graphqlClientRef.current && finalConfig.dubheMetadata) {
338
+ console.log("GraphQL metadata changed, updating...");
339
+ graphqlClientRef.current.updateConfig({
340
+ dubheMetadata: finalConfig.dubheMetadata
341
+ });
342
+ }
343
+ }, [finalConfig.dubheMetadata]);
344
+ useEffect(() => {
345
+ if (grpcClientRef.current && finalConfig.endpoints?.grpc) {
346
+ console.log("gRPC config dependencies changed, updating...");
347
+ grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });
348
+ }
349
+ }, [finalConfig.endpoints?.grpc]);
350
+ useEffect(() => {
351
+ if (ecsWorldRef.current) {
352
+ console.log("ECS config dependencies changed, updating...");
353
+ ecsWorldRef.current.updateConfig({
354
+ dubheMetadata: finalConfig.dubheMetadata,
355
+ queryConfig: {
356
+ enableBatchOptimization: finalConfig.options?.enableBatchOptimization,
357
+ defaultCacheTimeout: finalConfig.options?.cacheTimeout
358
+ },
359
+ subscriptionConfig: {
360
+ defaultDebounceMs: finalConfig.options?.debounceMs,
361
+ reconnectOnError: finalConfig.options?.reconnectOnError
362
+ }
363
+ });
364
+ }
365
+ }, [
366
+ finalConfig.dubheMetadata,
367
+ finalConfig.options?.enableBatchOptimization,
368
+ finalConfig.options?.cacheTimeout,
369
+ finalConfig.options?.debounceMs,
370
+ finalConfig.options?.reconnectOnError
371
+ ]);
223
372
  const contextValue = {
224
373
  getContract,
225
374
  getGraphqlClient,
375
+ getGrpcClient,
226
376
  getEcsWorld,
227
377
  getAddress,
228
378
  getMetrics,
229
- config: finalConfig
379
+ config: finalConfig,
380
+ updateConfig,
381
+ resetClients
230
382
  };
231
383
  return /* @__PURE__ */ jsx(DubheContext.Provider, { value: contextValue, children });
232
384
  }
@@ -243,6 +395,7 @@ function useDubheFromProvider() {
243
395
  const context = useDubheContext();
244
396
  const contract = context.getContract();
245
397
  const graphqlClient = context.getGraphqlClient();
398
+ const grpcClient = context.getGrpcClient();
246
399
  const ecsWorld = context.getEcsWorld();
247
400
  const address = context.getAddress();
248
401
  const metrics = context.getMetrics();
@@ -284,6 +437,7 @@ function useDubheFromProvider() {
284
437
  return {
285
438
  contract: enhancedContract,
286
439
  graphqlClient,
440
+ grpcClient,
287
441
  ecsWorld,
288
442
  metadata: context.config.metadata,
289
443
  network: context.config.network,
@@ -306,6 +460,10 @@ function useDubheECSFromProvider() {
306
460
  const { getEcsWorld } = useDubheContext();
307
461
  return getEcsWorld();
308
462
  }
463
+ function useDubheConfigUpdate() {
464
+ const { updateConfig, resetClients, config } = useDubheContext();
465
+ return { updateConfig, resetClients, config };
466
+ }
309
467
 
310
468
  // src/sui/hooks.ts
311
469
  function useDubhe() {
@@ -320,6 +478,9 @@ function useDubheGraphQL() {
320
478
  function useDubheECS() {
321
479
  return useDubheECSFromProvider();
322
480
  }
481
+ function useDubheConfigUpdate2() {
482
+ return useDubheConfigUpdate();
483
+ }
323
484
  var useContract = useDubhe;
324
485
 
325
486
  export {
@@ -333,6 +494,7 @@ export {
333
494
  useDubheContract,
334
495
  useDubheGraphQL,
335
496
  useDubheECS,
497
+ useDubheConfigUpdate2 as useDubheConfigUpdate,
336
498
  useContract
337
499
  };
338
- //# sourceMappingURL=chunk-7KXBMX2H.mjs.map
500
+ //# sourceMappingURL=chunk-RDLQECAX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sui/config.ts","../src/sui/utils.ts","../src/sui/provider.tsx","../src/sui/hooks.ts"],"sourcesContent":["/**\n * Configuration Management for Dubhe React Integration\n *\n * Features:\n * - Type-safe configuration interface\n * - Configuration validation and error handling\n * - Smart merging of defaults and explicit config\n * - No environment variable handling (developers should handle environment variables themselves)\n */\n\nimport { useMemo } from 'react';\nimport type { DubheConfig } from './types';\nimport { mergeConfigurations, validateConfig } from './utils';\n\n/**\n * Default configuration object with sensible defaults\n */\nexport const DEFAULT_CONFIG: Partial<DubheConfig> = {\n endpoints: {\n graphql: 'http://localhost:4000/graphql',\n websocket: 'ws://localhost:4000/graphql'\n },\n options: {\n enableBatchOptimization: true,\n cacheTimeout: 5000,\n debounceMs: 100,\n reconnectOnError: true\n }\n};\n\n/**\n * Configuration Hook: useDubheConfig\n *\n * Merges defaults with explicit configuration provided by the developer\n *\n * Note: Environment variables should be handled by the developer before passing to this hook\n *\n * @param config - Complete or partial configuration object\n * @returns Complete, validated DubheConfig\n *\n * @example\n * ```typescript\n * // Basic usage with explicit config\n * const config = useDubheConfig({\n * network: 'testnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // Handle env vars yourself\n * }\n * });\n *\n * // With helper function to handle environment variables\n * const getConfigFromEnv = () => ({\n * network: process.env.NEXT_PUBLIC_NETWORK as NetworkType,\n * packageId: process.env.NEXT_PUBLIC_PACKAGE_ID,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * });\n *\n * const config = useDubheConfig({\n * ...getConfigFromEnv(),\n * metadata: contractMetadata\n * });\n * ```\n */\nexport function useDubheConfig(config: Partial<DubheConfig>): DubheConfig {\n // Memoize the stringified config to detect actual changes\n const configKey = useMemo(() => {\n return JSON.stringify(config);\n }, [config]);\n\n return useMemo(() => {\n // Merge configurations: defaults -> user provided config\n const mergedConfig = mergeConfigurations(DEFAULT_CONFIG, config);\n\n // Validate the final configuration\n const validatedConfig = validateConfig(mergedConfig);\n\n // if (process.env.NODE_ENV === 'development') {\n // console.log('🔧 Dubhe Config:', {\n // ...validatedConfig,\n // credentials: validatedConfig.credentials?.secretKey ? '[REDACTED]' : undefined\n // });\n // }\n\n return validatedConfig;\n }, [configKey]);\n}\n","/**\n * Utility Functions for Dubhe Configuration Management\n *\n * Features:\n * - Configuration validation and error handling\n * - Smart configuration merging with proper type safety\n * - Type-safe configuration validation\n */\n\nimport type { DubheConfig } from './types';\n\n/**\n * Merge multiple configuration objects with proper deep merging\n * Later configurations override earlier ones\n *\n * @param baseConfig - Base configuration (usually defaults)\n * @param overrideConfig - Override configuration (user provided)\n * @returns Merged configuration\n */\nexport function mergeConfigurations(\n baseConfig: Partial<DubheConfig>,\n overrideConfig?: Partial<DubheConfig>\n): Partial<DubheConfig> {\n if (!overrideConfig) {\n return { ...baseConfig };\n }\n\n const result: Partial<DubheConfig> = { ...baseConfig };\n\n // Merge top-level properties\n Object.assign(result, overrideConfig);\n\n // Deep merge nested objects\n if (overrideConfig.credentials || baseConfig.credentials) {\n result.credentials = {\n ...baseConfig.credentials,\n ...overrideConfig.credentials\n };\n }\n\n if (overrideConfig.endpoints || baseConfig.endpoints) {\n result.endpoints = {\n ...baseConfig.endpoints,\n ...overrideConfig.endpoints\n };\n }\n\n if (overrideConfig.options || baseConfig.options) {\n result.options = {\n ...baseConfig.options,\n ...overrideConfig.options\n };\n }\n\n return result;\n}\n\n/**\n * Validate configuration and ensure required fields are present\n * Throws descriptive errors for missing required fields\n *\n * @param config - Configuration to validate\n * @returns Validated and typed configuration\n * @throws Error if required fields are missing or invalid\n */\nexport function validateConfig(config: Partial<DubheConfig>): DubheConfig {\n const errors: string[] = [];\n\n // Check required fields\n if (!config.network) {\n errors.push('network is required');\n }\n\n if (!config.packageId) {\n errors.push('packageId is required');\n }\n\n if (!config.metadata) {\n errors.push('metadata is required');\n } else {\n // Basic metadata validation\n if (typeof config.metadata !== 'object') {\n errors.push('metadata must be an object');\n } else if (Object.keys(config.metadata).length === 0) {\n errors.push('metadata cannot be empty');\n }\n }\n\n // Validate network type\n if (config.network && !['mainnet', 'testnet', 'devnet', 'localnet'].includes(config.network)) {\n errors.push(\n `invalid network: ${config.network}. Must be one of: mainnet, testnet, devnet, localnet`\n );\n }\n\n // Validate package ID format (enhanced check)\n if (config.packageId) {\n if (!config.packageId.startsWith('0x')) {\n errors.push('packageId must start with 0x');\n } else if (config.packageId.length < 3) {\n errors.push('packageId must be longer than 0x');\n } else if (!/^0x[a-fA-F0-9]+$/.test(config.packageId)) {\n errors.push('packageId must contain only hexadecimal characters after 0x');\n }\n }\n\n // Validate dubheMetadata if provided\n if (config.dubheMetadata !== undefined) {\n if (typeof config.dubheMetadata !== 'object' || config.dubheMetadata === null) {\n errors.push('dubheMetadata must be an object');\n } else if (!config.dubheMetadata.components && !config.dubheMetadata.resources) {\n errors.push('dubheMetadata must contain components or resources');\n }\n }\n\n // Validate credentials if provided\n if (config.credentials) {\n if (config.credentials.secretKey && typeof config.credentials.secretKey !== 'string') {\n errors.push('credentials.secretKey must be a string');\n }\n if (config.credentials.mnemonics && typeof config.credentials.mnemonics !== 'string') {\n errors.push('credentials.mnemonics must be a string');\n }\n }\n\n // Validate URLs if provided\n if (config.endpoints?.graphql && !isValidUrl(config.endpoints.graphql)) {\n errors.push('endpoints.graphql must be a valid URL');\n }\n\n if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {\n errors.push('endpoints.websocket must be a valid URL');\n }\n\n // Validate numeric options\n if (\n config.options?.cacheTimeout !== undefined &&\n (typeof config.options.cacheTimeout !== 'number' || config.options.cacheTimeout < 0)\n ) {\n errors.push('options.cacheTimeout must be a non-negative number');\n }\n\n if (\n config.options?.debounceMs !== undefined &&\n (typeof config.options.debounceMs !== 'number' || config.options.debounceMs < 0)\n ) {\n errors.push('options.debounceMs must be a non-negative number');\n }\n\n if (errors.length > 0) {\n const errorMessage = `Invalid Dubhe configuration (${errors.length} error${\n errors.length > 1 ? 's' : ''\n }):\\n${errors.map((e) => `- ${e}`).join('\\n')}`;\n console.error('Configuration validation failed:', { errors, config });\n throw new Error(errorMessage);\n }\n\n return config as DubheConfig;\n}\n\n/**\n * Simple URL validation helper\n *\n * @param url - URL string to validate\n * @returns true if URL is valid, false otherwise\n */\nfunction isValidUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Generate a configuration summary for debugging\n * Hides sensitive information like private keys\n *\n * @param config - Configuration to summarize\n * @returns Safe configuration summary\n */\nexport function getConfigSummary(config: DubheConfig): object {\n return {\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n hasMetadata: !!config.metadata,\n hasDubheMetadata: !!config.dubheMetadata,\n hasCredentials: !!config.credentials?.secretKey,\n endpoints: config.endpoints,\n options: config.options\n };\n}\n","/**\n * Dubhe Provider - useRef Pattern for Client Management\n *\n * Features:\n * - 🎯 Single client instances across application lifecycle\n * - ⚡ useRef-based storage (no re-initialization on re-renders)\n * - 🔧 Provider pattern for dependency injection\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing\n */\n\nimport {\n createContext,\n useContext,\n useRef,\n ReactNode,\n useState,\n useCallback,\n useEffect\n} from 'react';\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport { useDubheConfig } from './config';\nimport type { DubheConfig, DubheReturn } from './types';\n\n/**\n * Context interface for Dubhe client instances\n * All clients are stored using useRef to ensure single initialization\n */\ninterface DubheContextValue {\n getContract: () => Dubhe;\n getGraphqlClient: () => any | null;\n getGrpcClient: () => DubheGrpcClient | null;\n getEcsWorld: () => any | null;\n getAddress: () => string;\n getMetrics: () => {\n initTime: number;\n requestCount: number;\n lastActivity: number;\n };\n config: DubheConfig;\n updateConfig: (newConfig: Partial<DubheConfig>) => void;\n resetClients: (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => void;\n}\n\n/**\n * Context for sharing Dubhe clients across the application\n * Uses useRef pattern to ensure clients are created only once\n */\nconst DubheContext = createContext<DubheContextValue | null>(null);\n\n/**\n * Props interface for DubheProvider component\n */\ninterface DubheProviderProps {\n /** Configuration for Dubhe initialization */\n config: Partial<DubheConfig>;\n /** Child components that will have access to Dubhe clients */\n children: ReactNode;\n}\n\n/**\n * DubheProvider Component - useRef Pattern Implementation\n *\n * This Provider uses useRef to store client instances, ensuring they are:\n * 1. Created only once during component lifecycle\n * 2. Persisted across re-renders without re-initialization\n * 3. Shared efficiently via React Context\n *\n * Key advantages over useMemo:\n * - useRef guarantees single initialization (useMemo can re-run on dependency changes)\n * - No dependency array needed (eliminates potential re-initialization bugs)\n * - Better performance for heavy client objects\n * - Clearer separation of concerns via Provider pattern\n *\n * @param props - Provider props containing config and children\n * @returns Provider component wrapping children with Dubhe context\n *\n * @example\n * ```typescript\n * // App root setup\n * function App() {\n * const dubheConfig = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={dubheConfig}>\n * <MyApplication />\n * </DubheProvider>\n * );\n * }\n * ```\n */\nexport function DubheProvider({ config, children }: DubheProviderProps) {\n // Use state to manage config for dynamic updates with persistence\n const [currentConfig, setCurrentConfig] = useState<Partial<DubheConfig>>(() => {\n // Try to restore config from localStorage\n if (typeof window !== 'undefined') {\n try {\n const saved = localStorage.getItem('dubhe-config');\n if (saved) {\n const parsedConfig = JSON.parse(saved);\n console.log('Restored Dubhe configuration from localStorage');\n return { ...config, ...parsedConfig };\n }\n } catch (error) {\n console.warn('Failed to restore Dubhe configuration from localStorage', error);\n }\n }\n return config;\n });\n\n // Merge configuration with defaults\n const finalConfig = useDubheConfig(currentConfig);\n\n // Track initialization start time (useRef ensures single timestamp)\n const startTimeRef = useRef<number>(performance.now());\n\n // useRef for contract instance - guarantees single initialization\n // Unlike useMemo, useRef.current is never re-calculated\n const contractRef = useRef<Dubhe | undefined>(undefined);\n const getContract = (): Dubhe => {\n if (!contractRef.current) {\n try {\n console.log('Initializing Dubhe contract instance (one-time)');\n contractRef.current = new Dubhe({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey\n });\n } catch (error) {\n console.error('Contract initialization failed:', error);\n throw error;\n }\n }\n return contractRef.current;\n };\n\n // useRef for GraphQL client instance - single initialization guaranteed\n const graphqlClientRef = useRef<any | null>(null);\n const hasInitializedGraphql = useRef(false);\n const getGraphqlClient = (): any | null => {\n if (!hasInitializedGraphql.current && finalConfig.dubheMetadata) {\n try {\n console.log('Initializing GraphQL client instance (one-time)');\n graphqlClientRef.current = createDubheGraphqlClient({\n endpoint: finalConfig.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: finalConfig.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: finalConfig.dubheMetadata\n });\n hasInitializedGraphql.current = true;\n } catch (error) {\n console.error('GraphQL client initialization failed:', error);\n throw error;\n }\n }\n return graphqlClientRef.current;\n };\n\n // useRef for gRPC client instance - single initialization guaranteed\n const grpcClientRef = useRef<DubheGrpcClient | null>(null);\n const hasInitializedGrpc = useRef(false);\n const getGrpcClient = (): DubheGrpcClient | null => {\n if (!hasInitializedGrpc.current && finalConfig.endpoints?.grpc) {\n try {\n console.log('Initializing gRPC client instance (one-time)');\n grpcClientRef.current = new DubheGrpcClient({\n baseUrl: finalConfig.endpoints.grpc\n });\n hasInitializedGrpc.current = true;\n } catch (error) {\n console.error('gRPC client initialization failed:', error);\n throw error;\n }\n }\n return grpcClientRef.current;\n };\n\n // useRef for ECS World instance - depends on GraphQL client\n const ecsWorldRef = useRef<any | null>(null);\n const hasInitializedEcs = useRef(false);\n const getEcsWorld = (): any | null => {\n const graphqlClient = getGraphqlClient();\n if (!hasInitializedEcs.current && graphqlClient) {\n try {\n console.log('Initializing ECS World instance (one-time)');\n ecsWorldRef.current = createECSWorld(graphqlClient, {\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs ?? 100,\n reconnectOnError: finalConfig.options?.reconnectOnError ?? true\n }\n });\n hasInitializedEcs.current = true;\n } catch (error) {\n console.error('ECS World initialization failed:', error);\n throw error;\n }\n }\n return ecsWorldRef.current;\n };\n\n // Address getter - calculated from contract\n const getAddress = (): string => {\n return getContract().getAddress();\n };\n\n // Metrics getter - performance tracking\n const getMetrics = () => ({\n initTime: performance.now() - (startTimeRef.current || 0),\n requestCount: 0, // Can be enhanced with actual tracking\n lastActivity: Date.now()\n });\n\n // Selective reset client instances\n const resetClients = useCallback(\n (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => {\n const opts = {\n resetContract: true,\n resetGraphql: true,\n resetGrpc: true,\n resetEcs: true,\n ...options\n };\n\n console.log('Resetting Dubhe client instances', opts);\n\n if (opts.resetContract) {\n contractRef.current = undefined;\n }\n if (opts.resetGraphql) {\n graphqlClientRef.current = null;\n hasInitializedGraphql.current = false;\n }\n if (opts.resetGrpc) {\n grpcClientRef.current = null;\n hasInitializedGrpc.current = false;\n }\n if (opts.resetEcs) {\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n\n startTimeRef.current = performance.now();\n },\n []\n );\n\n // Update config without resetting clients (reactive update)\n const updateConfig = useCallback((newConfig: Partial<DubheConfig>) => {\n console.log('Updating Dubhe configuration (reactive)');\n setCurrentConfig((prev) => {\n const updated = { ...prev, ...newConfig };\n // Persist to localStorage\n if (typeof window !== 'undefined') {\n try {\n localStorage.setItem('dubhe-config', JSON.stringify(updated));\n console.log('Persisted Dubhe configuration to localStorage');\n } catch (error) {\n console.warn('Failed to persist Dubhe configuration', error);\n }\n }\n return updated;\n });\n }, []);\n\n // Reactive configuration updates via useEffect\n\n // Monitor Contract configuration changes\n useEffect(() => {\n if (contractRef.current) {\n console.log('Contract config dependencies changed, updating...');\n contractRef.current.updateConfig({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics\n });\n }\n }, [\n finalConfig.network,\n finalConfig.packageId,\n finalConfig.metadata,\n finalConfig.credentials?.secretKey,\n finalConfig.credentials?.mnemonics\n ]);\n\n // Monitor GraphQL endpoint changes\n useEffect(() => {\n if (graphqlClientRef.current) {\n console.log('GraphQL endpoint dependencies changed, updating...');\n graphqlClientRef.current.updateConfig({\n endpoint: finalConfig.endpoints?.graphql,\n subscriptionEndpoint: finalConfig.endpoints?.websocket\n });\n // Reset ECS World when GraphQL endpoints change (needs new connection)\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);\n\n // Monitor GraphQL metadata changes\n useEffect(() => {\n if (graphqlClientRef.current && finalConfig.dubheMetadata) {\n console.log('GraphQL metadata changed, updating...');\n graphqlClientRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata\n });\n // Note: ECS will handle its own metadata update via its useEffect\n }\n }, [finalConfig.dubheMetadata]);\n\n // Monitor gRPC configuration changes\n useEffect(() => {\n if (grpcClientRef.current && finalConfig.endpoints?.grpc) {\n console.log('gRPC config dependencies changed, updating...');\n grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });\n }\n }, [finalConfig.endpoints?.grpc]);\n\n // Monitor ECS configuration changes\n useEffect(() => {\n if (ecsWorldRef.current) {\n console.log('ECS config dependencies changed, updating...');\n ecsWorldRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs,\n reconnectOnError: finalConfig.options?.reconnectOnError\n }\n });\n }\n }, [\n finalConfig.dubheMetadata,\n finalConfig.options?.enableBatchOptimization,\n finalConfig.options?.cacheTimeout,\n finalConfig.options?.debounceMs,\n finalConfig.options?.reconnectOnError\n ]);\n\n // Context value - stable reference (no re-renders for consumers)\n const contextValue: DubheContextValue = {\n getContract,\n getGraphqlClient,\n getGrpcClient,\n getEcsWorld,\n getAddress,\n getMetrics,\n config: finalConfig,\n updateConfig,\n resetClients\n };\n\n return <DubheContext.Provider value={contextValue}>{children}</DubheContext.Provider>;\n}\n\n/**\n * Custom hook to access Dubhe context\n * Provides type-safe access to all Dubhe client instances\n *\n * @returns DubheContextValue with all client getters and config\n * @throws Error if used outside of DubheProvider\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const dubheContext = useDubheContext();\n *\n * const contract = dubheContext.getContract();\n * const graphqlClient = dubheContext.getGraphqlClient();\n * const ecsWorld = dubheContext.getEcsWorld();\n * const address = dubheContext.getAddress();\n *\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubheContext(): DubheContextValue {\n const context = useContext(DubheContext);\n\n if (!context) {\n throw new Error(\n 'useDubheContext must be used within a DubheProvider. ' +\n 'Make sure to wrap your app with <DubheProvider config={...}>'\n );\n }\n\n return context;\n}\n\n/**\n * Enhanced hook that mimics the original useDubhe API\n * Uses the Provider pattern internally but maintains backward compatibility\n *\n * @returns DubheReturn object with all instances and metadata\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const { contract, graphqlClient, ecsWorld, address } = useDubheFromProvider();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheFromProvider(): DubheReturn {\n const context = useDubheContext();\n\n // Get instances (lazy initialization via getters)\n const contract = context.getContract();\n const graphqlClient = context.getGraphqlClient();\n const grpcClient = context.getGrpcClient();\n const ecsWorld = context.getEcsWorld();\n const address = context.getAddress();\n const metrics = context.getMetrics();\n\n // Enhanced contract with additional methods (similar to original implementation)\n const enhancedContract = contract as any;\n\n // Add transaction methods with error handling (if not already added)\n if (!enhancedContract.txWithOptions) {\n enhancedContract.txWithOptions = (system: string, method: string, options: any = {}) => {\n return async (params: any) => {\n try {\n const startTime = performance.now();\n const result = await contract.tx[system][method](params);\n const executionTime = performance.now() - startTime;\n\n if (process.env.NODE_ENV === 'development') {\n console.log(\n `Transaction ${system}.${method} completed in ${executionTime.toFixed(2)}ms`\n );\n }\n\n options.onSuccess?.(result);\n return result;\n } catch (error) {\n options.onError?.(error);\n throw error;\n }\n };\n };\n }\n\n // Add query methods with performance tracking (if not already added)\n if (!enhancedContract.queryWithOptions) {\n enhancedContract.queryWithOptions = (system: string, method: string, _options: any = {}) => {\n return async (params: any) => {\n const startTime = performance.now();\n const result = await contract.query[system][method](params);\n const executionTime = performance.now() - startTime;\n\n if (process.env.NODE_ENV === 'development') {\n console.log(`Query ${system}.${method} completed in ${executionTime.toFixed(2)}ms`);\n }\n\n return result;\n };\n };\n }\n\n return {\n contract: enhancedContract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: context.config.metadata,\n network: context.config.network,\n packageId: context.config.packageId,\n dubheSchemaId: context.config.dubheSchemaId,\n address,\n options: context.config.options,\n metrics\n };\n}\n\n/**\n * Individual client hooks for components that only need specific instances\n * These are more efficient than useDubheFromProvider for single-client usage\n */\n\n/**\n * Hook for accessing only the Dubhe contract instance\n */\nexport function useDubheContractFromProvider(): Dubhe {\n const { contract } = useDubheFromProvider();\n return contract;\n}\n\n/**\n * Hook for accessing only the GraphQL client instance\n */\nexport function useDubheGraphQLFromProvider(): any | null {\n const { getGraphqlClient } = useDubheContext();\n return getGraphqlClient();\n}\n\n/**\n * Hook for accessing only the ECS World instance\n */\nexport function useDubheECSFromProvider(): any | null {\n const { getEcsWorld } = useDubheContext();\n return getEcsWorld();\n}\n\n/**\n * Hook for accessing only the gRPC client instance\n */\nexport function useDubheGrpcFromProvider(): DubheGrpcClient | null {\n const { getGrpcClient } = useDubheContext();\n return getGrpcClient();\n}\n\n/**\n * Hook for accessing configuration update methods\n *\n * @returns Object with updateConfig and resetClients methods\n *\n * @example\n * ```typescript\n * function ConfigUpdater() {\n * const { updateConfig, resetClients, config } = useDubheConfigUpdate();\n *\n * const switchNetwork = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xnew...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Current network: {config.network}</p>\n * <button onClick={switchNetwork}>Switch to Testnet</button>\n * <button onClick={resetClients}>Reset Clients</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n const { updateConfig, resetClients, config } = useDubheContext();\n return { updateConfig, resetClients, config };\n}\n","/**\n * Modern Dubhe React Hooks - Provider Pattern\n *\n * Features:\n * - 🎯 Simple API design with Provider pattern\n * - ⚡ Single client initialization with useRef\n * - 🔧 Configuration-driven setup (developers handle environment variables themselves)\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing across components\n */\nimport { Dubhe } from '@0xobelisk/sui-client';\n\nimport {\n useDubheFromProvider,\n useDubheContractFromProvider,\n useDubheGraphQLFromProvider,\n useDubheECSFromProvider,\n useDubheConfigUpdate as useDubheConfigUpdateFromProvider\n} from './provider';\nimport type { DubheReturn } from './types';\n\n/**\n * Primary Hook: useDubhe\n *\n * Uses Provider pattern to access shared Dubhe clients with guaranteed single initialization.\n * Must be used within a DubheProvider.\n *\n * @returns Complete Dubhe ecosystem with contract, GraphQL, ECS, and metadata\n *\n * @example\n * ```typescript\n * // App setup with Provider\n * function App() {\n * const config = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={config}>\n * <MyDApp />\n * </DubheProvider>\n * );\n * }\n *\n * // Component usage\n * function MyDApp() {\n * const { contract, address } = useDubhe();\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubhe(): DubheReturn {\n return useDubheFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheContract\n *\n * Returns only the Dubhe contract instance from Provider context.\n * More efficient than useDubhe() when only contract access is needed.\n *\n * @returns Dubhe contract instance\n *\n * @example\n * ```typescript\n * function TransactionComponent() {\n * const contract = useDubheContract();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheContract(): Dubhe {\n return useDubheContractFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheGraphQL\n *\n * Returns only the GraphQL client from Provider context.\n * More efficient than useDubhe() when only GraphQL access is needed.\n *\n * @returns GraphQL client instance (null if dubheMetadata not provided)\n *\n * @example\n * ```typescript\n * function DataComponent() {\n * const graphqlClient = useDubheGraphQL();\n *\n * useEffect(() => {\n * if (graphqlClient) {\n * graphqlClient.query({ ... }).then(setData);\n * }\n * }, [graphqlClient]);\n *\n * return <div>{data && JSON.stringify(data)}</div>;\n * }\n * ```\n */\nexport function useDubheGraphQL(): any | null {\n return useDubheGraphQLFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheECS\n *\n * Returns only the ECS World instance from Provider context.\n * More efficient than useDubhe() when only ECS access is needed.\n *\n * @returns ECS World instance (null if GraphQL client not available)\n *\n * @example\n * ```typescript\n * function ECSComponent() {\n * const ecsWorld = useDubheECS();\n *\n * useEffect(() => {\n * if (ecsWorld) {\n * ecsWorld.getComponent('MyComponent').then(setComponent);\n * }\n * }, [ecsWorld]);\n *\n * return <div>ECS Component Data</div>;\n * }\n * ```\n */\nexport function useDubheECS(): any | null {\n return useDubheECSFromProvider();\n}\n\n/**\n * Hook for dynamic configuration updates\n *\n * Provides methods to update provider configuration at runtime\n *\n * @returns Object with updateConfig, resetClients methods and current config\n *\n * @example\n * ```typescript\n * function NetworkSwitcher() {\n * const { updateConfig, config } = useDubheConfigUpdate();\n *\n * const switchToTestnet = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xTestnetPackageId...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Network: {config.network}</p>\n * <button onClick={switchToTestnet}>Switch to Testnet</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n return useDubheConfigUpdateFromProvider();\n}\n\n/**\n * Compatibility alias for useDubhe\n */\nexport const useContract = useDubhe;\n"],"mappings":";AAUA,SAAS,eAAe;;;ACSjB,SAAS,oBACd,YACA,gBACsB;AACtB,MAAI,CAAC,gBAAgB;AACnB,WAAO,EAAE,GAAG,WAAW;AAAA,EACzB;AAEA,QAAM,SAA+B,EAAE,GAAG,WAAW;AAGrD,SAAO,OAAO,QAAQ,cAAc;AAGpC,MAAI,eAAe,eAAe,WAAW,aAAa;AACxD,WAAO,cAAc;AAAA,MACnB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,aAAa,WAAW,WAAW;AACpD,WAAO,YAAY;AAAA,MACjB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,WAAW,WAAW,SAAS;AAChD,WAAO,UAAU;AAAA,MACf,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;AAUO,SAAS,eAAe,QAA2C;AACxE,QAAM,SAAmB,CAAC;AAG1B,MAAI,CAAC,OAAO,SAA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AEA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,QAAQ,OAAO;AAAA,IACzB,SAAS,QAAQ,OAAO;AAAA,IACxB,WAAW,QAAQ,OAAO;AAAA,IAC1B,eAAe,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,SAAS,QAAQ,OAAO;AAAA,IACxB;AAAA,EACF;AACF;AAUO,SAAS,+BAAsC;AACpD,QAAM,EAAE,SAAS,IAAI,qBAAqB;AAC1C,SAAO;AACT;AAKO,SAAS,8BAA0C;AACxD,QAAM,EAAE,iBAAiB,IAAI,gBAAgB;AAC7C,SAAO,iBAAiB;AAC1B;AAKO,SAAS,0BAAsC;AACpD,QAAM,EAAE,YAAY,IAAI,gBAAgB;AACxC,SAAO,YAAY;AACrB;AAqCO,SAAS,uBAAuB;AACrC,QAAM,EAAE,cAAc,cAAc,OAAO,IAAI,gBAAgB;AAC/D,SAAO,EAAE,cAAc,cAAc,OAAO;AAC9C;;;ACvgBO,SAAS,WAAwB;AACtC,SAAO,qBAAqB;AAC9B;AAwBO,SAAS,mBAA0B;AACxC,SAAO,6BAA6B;AACtC;AAyBO,SAAS,kBAA8B;AAC5C,SAAO,4BAA4B;AACrC;AAyBO,SAAS,cAA0B;AACxC,SAAO,wBAAwB;AACjC;AA8BO,SAASA,wBAAuB;AACrC,SAAO,qBAAiC;AAC1C;AAKO,IAAM,cAAc;","names":["useDubheConfigUpdate"]}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.mjs';
1
+ export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.mjs';
2
2
  import '@0xobelisk/sui-client';
3
3
  import '@0xobelisk/graphql-client';
4
4
  import '@0xobelisk/ecs';
5
+ import '@0xobelisk/grpc-client';
5
6
  import 'react/jsx-runtime';
6
7
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.js';
1
+ export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.js';
2
2
  import '@0xobelisk/sui-client';
3
3
  import '@0xobelisk/graphql-client';
4
4
  import '@0xobelisk/ecs';
5
+ import '@0xobelisk/grpc-client';
5
6
  import 'react/jsx-runtime';
6
7
  import 'react';
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  useContract: () => useContract,
28
28
  useDubhe: () => useDubhe,
29
29
  useDubheConfig: () => useDubheConfig,
30
+ useDubheConfigUpdate: () => useDubheConfigUpdate2,
30
31
  useDubheContract: () => useDubheContract,
31
32
  useDubheECS: () => useDubheECS,
32
33
  useDubheGraphQL: () => useDubheGraphQL,
@@ -180,10 +181,26 @@ var import_react2 = require("react");
180
181
  var import_sui_client = require("@0xobelisk/sui-client");
181
182
  var import_graphql_client = require("@0xobelisk/graphql-client");
182
183
  var import_ecs = require("@0xobelisk/ecs");
184
+ var import_grpc_client = require("@0xobelisk/grpc-client");
183
185
  var import_jsx_runtime = require("react/jsx-runtime");
184
186
  var DubheContext = (0, import_react2.createContext)(null);
185
187
  function DubheProvider({ config, children }) {
186
- const finalConfig = useDubheConfig(config);
188
+ const [currentConfig, setCurrentConfig] = (0, import_react2.useState)(() => {
189
+ if (typeof window !== "undefined") {
190
+ try {
191
+ const saved = localStorage.getItem("dubhe-config");
192
+ if (saved) {
193
+ const parsedConfig = JSON.parse(saved);
194
+ console.log("Restored Dubhe configuration from localStorage");
195
+ return { ...config, ...parsedConfig };
196
+ }
197
+ } catch (error) {
198
+ console.warn("Failed to restore Dubhe configuration from localStorage", error);
199
+ }
200
+ }
201
+ return config;
202
+ });
203
+ const finalConfig = useDubheConfig(currentConfig);
187
204
  const startTimeRef = (0, import_react2.useRef)(performance.now());
188
205
  const contractRef = (0, import_react2.useRef)(void 0);
189
206
  const getContract = () => {
@@ -222,6 +239,23 @@ function DubheProvider({ config, children }) {
222
239
  }
223
240
  return graphqlClientRef.current;
224
241
  };
242
+ const grpcClientRef = (0, import_react2.useRef)(null);
243
+ const hasInitializedGrpc = (0, import_react2.useRef)(false);
244
+ const getGrpcClient = () => {
245
+ if (!hasInitializedGrpc.current && finalConfig.endpoints?.grpc) {
246
+ try {
247
+ console.log("Initializing gRPC client instance (one-time)");
248
+ grpcClientRef.current = new import_grpc_client.DubheGrpcClient({
249
+ baseUrl: finalConfig.endpoints.grpc
250
+ });
251
+ hasInitializedGrpc.current = true;
252
+ } catch (error) {
253
+ console.error("gRPC client initialization failed:", error);
254
+ throw error;
255
+ }
256
+ }
257
+ return grpcClientRef.current;
258
+ };
225
259
  const ecsWorldRef = (0, import_react2.useRef)(null);
226
260
  const hasInitializedEcs = (0, import_react2.useRef)(false);
227
261
  const getEcsWorld = () => {
@@ -256,13 +290,125 @@ function DubheProvider({ config, children }) {
256
290
  // Can be enhanced with actual tracking
257
291
  lastActivity: Date.now()
258
292
  });
293
+ const resetClients = (0, import_react2.useCallback)(
294
+ (options) => {
295
+ const opts = {
296
+ resetContract: true,
297
+ resetGraphql: true,
298
+ resetGrpc: true,
299
+ resetEcs: true,
300
+ ...options
301
+ };
302
+ console.log("Resetting Dubhe client instances", opts);
303
+ if (opts.resetContract) {
304
+ contractRef.current = void 0;
305
+ }
306
+ if (opts.resetGraphql) {
307
+ graphqlClientRef.current = null;
308
+ hasInitializedGraphql.current = false;
309
+ }
310
+ if (opts.resetGrpc) {
311
+ grpcClientRef.current = null;
312
+ hasInitializedGrpc.current = false;
313
+ }
314
+ if (opts.resetEcs) {
315
+ ecsWorldRef.current = null;
316
+ hasInitializedEcs.current = false;
317
+ }
318
+ startTimeRef.current = performance.now();
319
+ },
320
+ []
321
+ );
322
+ const updateConfig = (0, import_react2.useCallback)((newConfig) => {
323
+ console.log("Updating Dubhe configuration (reactive)");
324
+ setCurrentConfig((prev) => {
325
+ const updated = { ...prev, ...newConfig };
326
+ if (typeof window !== "undefined") {
327
+ try {
328
+ localStorage.setItem("dubhe-config", JSON.stringify(updated));
329
+ console.log("Persisted Dubhe configuration to localStorage");
330
+ } catch (error) {
331
+ console.warn("Failed to persist Dubhe configuration", error);
332
+ }
333
+ }
334
+ return updated;
335
+ });
336
+ }, []);
337
+ (0, import_react2.useEffect)(() => {
338
+ if (contractRef.current) {
339
+ console.log("Contract config dependencies changed, updating...");
340
+ contractRef.current.updateConfig({
341
+ networkType: finalConfig.network,
342
+ packageId: finalConfig.packageId,
343
+ metadata: finalConfig.metadata,
344
+ secretKey: finalConfig.credentials?.secretKey,
345
+ mnemonics: finalConfig.credentials?.mnemonics
346
+ });
347
+ }
348
+ }, [
349
+ finalConfig.network,
350
+ finalConfig.packageId,
351
+ finalConfig.metadata,
352
+ finalConfig.credentials?.secretKey,
353
+ finalConfig.credentials?.mnemonics
354
+ ]);
355
+ (0, import_react2.useEffect)(() => {
356
+ if (graphqlClientRef.current) {
357
+ console.log("GraphQL endpoint dependencies changed, updating...");
358
+ graphqlClientRef.current.updateConfig({
359
+ endpoint: finalConfig.endpoints?.graphql,
360
+ subscriptionEndpoint: finalConfig.endpoints?.websocket
361
+ });
362
+ ecsWorldRef.current = null;
363
+ hasInitializedEcs.current = false;
364
+ }
365
+ }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);
366
+ (0, import_react2.useEffect)(() => {
367
+ if (graphqlClientRef.current && finalConfig.dubheMetadata) {
368
+ console.log("GraphQL metadata changed, updating...");
369
+ graphqlClientRef.current.updateConfig({
370
+ dubheMetadata: finalConfig.dubheMetadata
371
+ });
372
+ }
373
+ }, [finalConfig.dubheMetadata]);
374
+ (0, import_react2.useEffect)(() => {
375
+ if (grpcClientRef.current && finalConfig.endpoints?.grpc) {
376
+ console.log("gRPC config dependencies changed, updating...");
377
+ grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });
378
+ }
379
+ }, [finalConfig.endpoints?.grpc]);
380
+ (0, import_react2.useEffect)(() => {
381
+ if (ecsWorldRef.current) {
382
+ console.log("ECS config dependencies changed, updating...");
383
+ ecsWorldRef.current.updateConfig({
384
+ dubheMetadata: finalConfig.dubheMetadata,
385
+ queryConfig: {
386
+ enableBatchOptimization: finalConfig.options?.enableBatchOptimization,
387
+ defaultCacheTimeout: finalConfig.options?.cacheTimeout
388
+ },
389
+ subscriptionConfig: {
390
+ defaultDebounceMs: finalConfig.options?.debounceMs,
391
+ reconnectOnError: finalConfig.options?.reconnectOnError
392
+ }
393
+ });
394
+ }
395
+ }, [
396
+ finalConfig.dubheMetadata,
397
+ finalConfig.options?.enableBatchOptimization,
398
+ finalConfig.options?.cacheTimeout,
399
+ finalConfig.options?.debounceMs,
400
+ finalConfig.options?.reconnectOnError
401
+ ]);
259
402
  const contextValue = {
260
403
  getContract,
261
404
  getGraphqlClient,
405
+ getGrpcClient,
262
406
  getEcsWorld,
263
407
  getAddress,
264
408
  getMetrics,
265
- config: finalConfig
409
+ config: finalConfig,
410
+ updateConfig,
411
+ resetClients
266
412
  };
267
413
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DubheContext.Provider, { value: contextValue, children });
268
414
  }
@@ -279,6 +425,7 @@ function useDubheFromProvider() {
279
425
  const context = useDubheContext();
280
426
  const contract = context.getContract();
281
427
  const graphqlClient = context.getGraphqlClient();
428
+ const grpcClient = context.getGrpcClient();
282
429
  const ecsWorld = context.getEcsWorld();
283
430
  const address = context.getAddress();
284
431
  const metrics = context.getMetrics();
@@ -320,6 +467,7 @@ function useDubheFromProvider() {
320
467
  return {
321
468
  contract: enhancedContract,
322
469
  graphqlClient,
470
+ grpcClient,
323
471
  ecsWorld,
324
472
  metadata: context.config.metadata,
325
473
  network: context.config.network,
@@ -342,6 +490,10 @@ function useDubheECSFromProvider() {
342
490
  const { getEcsWorld } = useDubheContext();
343
491
  return getEcsWorld();
344
492
  }
493
+ function useDubheConfigUpdate() {
494
+ const { updateConfig, resetClients, config } = useDubheContext();
495
+ return { updateConfig, resetClients, config };
496
+ }
345
497
 
346
498
  // src/sui/hooks.ts
347
499
  function useDubhe() {
@@ -356,6 +508,9 @@ function useDubheGraphQL() {
356
508
  function useDubheECS() {
357
509
  return useDubheECSFromProvider();
358
510
  }
511
+ function useDubheConfigUpdate2() {
512
+ return useDubheConfigUpdate();
513
+ }
359
514
  var useContract = useDubhe;
360
515
  // Annotate the CommonJS export names for ESM import in node:
361
516
  0 && (module.exports = {
@@ -366,6 +521,7 @@ var useContract = useDubhe;
366
521
  useContract,
367
522
  useDubhe,
368
523
  useDubheConfig,
524
+ useDubheConfigUpdate,
369
525
  useDubheContract,
370
526
  useDubheECS,
371
527
  useDubheGraphQL,