MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / createInstance

Method createInstance

packages/cloud/src/CloudService.ts:382–423  ·  view source on GitHub ↗
(
		context: ExtensionContext,
		log?: (...args: unknown[]) => void,
		eventHandlers?: Partial<{
			[K in keyof CloudServiceEvents]: (...args: CloudServiceEvents[K]) => void
		}>,
	)

Source from the content-addressed store, hash-verified

380 }
381
382 static async createInstance(
383 context: ExtensionContext,
384 log?: (...args: unknown[]) => void,
385 eventHandlers?: Partial<{
386 [K in keyof CloudServiceEvents]: (...args: CloudServiceEvents[K]) => void
387 }>,
388 ): Promise<CloudService> {
389 if (this._instance) {
390 throw new Error("CloudService instance already created")
391 }
392
393 const instance = new CloudService(context, log)
394 this._instance = instance
395
396 try {
397 await instance.initialize()
398
399 if (eventHandlers) {
400 for (const [event, handler] of Object.entries(eventHandlers)) {
401 if (handler) {
402 instance.on(
403 event as keyof CloudServiceEvents,
404 handler as (...args: CloudServiceEvents[keyof CloudServiceEvents]) => void,
405 )
406 }
407 }
408 }
409
410 await instance.authService?.broadcast()
411
412 return instance
413 } catch (error) {
414 try {
415 instance.dispose()
416 } catch {
417 // Best effort cleanup only.
418 }
419
420 this._instance = null
421 throw error
422 }
423 }
424
425 static hasInstance(): boolean {
426 return this._instance !== null && this._instance.isInitialized

Callers 1

Calls 5

initializeMethod · 0.95
disposeMethod · 0.95
entriesMethod · 0.80
onMethod · 0.65
broadcastMethod · 0.65

Tested by

no test coverage detected