Skip to content

Commit 9ec5c51

Browse files
committed
add initMetadata and expose
1 parent ba9e5fe commit 9ec5c51

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { Sole, useConfig } from './use/config'
66
import { useClient } from './use/client'
77
import { useAuth } from './use/auth'
88
import { useFiles } from './use/files'
9-
import { useMetadata } from './use/metadata'
9+
import { useMetadata, initMetadata } from './use/metadata'
1010
import { useFormatters } from './use/formatters'
1111
import * as css from './components/css'
1212

1313
// Export component types
1414
export * from './components/types'
1515
export * from './types'
1616

17-
export { useUtils, useConfig, useClient, useAuth, useMetadata, useFiles, useFormatters, css }
17+
export { useUtils, useConfig, useClient, useAuth, useMetadata, initMetadata, useFiles, useFormatters, css }
1818

1919
// Import components (this will be excluded from type generation)
2020

src/use/metadata.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -449,29 +449,39 @@ async function loadMetadata(args:{
449449
}
450450
}
451451
if (!hasMetadata) {
452-
// If provided user-defined paths
453-
if (resolvePath || resolve) {
454-
await downloadMetadata(resolvePath || metadataPath, resolve)
455-
if (Sole.metadata.value != null) return
456-
}
457452

458453
// If has registered API client
459454
// Using inject requires use within setup()
460455
const client = args.client ?? inject<JsonServiceClient>('client')
461-
if (client != null) {
462-
const api = await client.api(new MetadataApp())
463-
if (api.succeeded) {
464-
setMetadata(api.response)
465-
}
466-
}
467-
if (Sole.metadata.value != null) return
468-
469-
// Default to /metadata/app.json
470-
await downloadMetadata(metadataPath)
456+
await initMetadata({ client, resolvePath, resolve })
471457
}
472458
return Sole.metadata.value as any // avoid type explosion in api.d.ts until needed
473459
}
474460

461+
export async function initMetadata(args:{
462+
client?:JsonServiceClient
463+
resolvePath?: string,
464+
resolve?:() => Promise<Response>
465+
}) {
466+
const { client, resolvePath, resolve } = args
467+
// If provided user-defined paths
468+
if (resolvePath || resolve) {
469+
await downloadMetadata(resolvePath || metadataPath, resolve)
470+
if (Sole.metadata.value != null) return
471+
}
472+
if (client != null) {
473+
const api = await client.api(new MetadataApp())
474+
if (api.succeeded) {
475+
setMetadata(api.response)
476+
}
477+
}
478+
if (Sole.metadata.value != null) return
479+
480+
// Default to /metadata/app.json
481+
await downloadMetadata(metadataPath)
482+
return Sole.metadata.value as any
483+
}
484+
475485
/**
476486
* Resolve {MetadataType} for DTO name
477487
* @param name - Find MetadataType by name

0 commit comments

Comments
 (0)