Skip to content

Commit

Permalink
chore: bring internal module manager APIs from #926
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 committed Oct 14, 2024
1 parent 4897a18 commit 2685d8e
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
19 changes: 19 additions & 0 deletions projects/ngx-meta/api-extractor/ngx-meta.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ export type _ProvideNgxMetaManagerOptions = Partial<{
// @public
export const provideNgxMetaMetadataLoader: () => Provider[];

// @internal (undocumented)
export const _provideNgxMetaModuleManager: <Type extends object, Key extends Extract<keyof Type, string>>(key: Key, scope: ReadonlyArray<string>, options?: _ProvideNgxMetaModuleManagerOptions<Type[Key]>) => FactoryProvider;

// @internal (undocumented)
export type _ProvideNgxMetaModuleManagerOptions<T> = Partial<{
f: MetadataSetterFactory<T>;
n: NgxMetaElementNameAttribute;
gS: true;
}> & _ProvideNgxMetaManagerOptions;

// @public
export const provideNgxMetaOpenGraph: () => Provider[];

Expand Down Expand Up @@ -620,6 +630,12 @@ export const withManagerJsonPath: (...jsonPath: MetadataResolverOptions['jsonPat
// @alpha
export const withManagerObjectMerging: () => _ProvideNgxMetaManagerOptions;

// @internal (undocumented)
export const _withModuleManagerNameAttribute: <T>(nameAttribute: _ProvideNgxMetaModuleManagerOptions<T>['n']) => _ProvideNgxMetaModuleManagerOptions<T>;

// @internal (undocumented)
export const _withModuleManagerSetterFactory: <T>(setterFactory: _ProvideNgxMetaModuleManagerOptions<T>['f']) => _ProvideNgxMetaModuleManagerOptions<T>;

// @public
export const withNameAttribute: (value: string) => readonly ["name", string];

Expand All @@ -635,6 +651,9 @@ export const withOptions: <T extends object>(...options: ReadonlyArray<T>) => T;
// @public
export const withPropertyAttribute: (value: string) => readonly ["property", string];

// @internal (undocumented)
export const _withSameNameGlobal: <T>() => _ProvideNgxMetaModuleManagerOptions<T>;

// (No @packageDocumentation comment for this package)

```
7 changes: 7 additions & 0 deletions projects/ngx-meta/src/core/src/managers/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export {
withManagerJsonPath,
_ProvideNgxMetaManagerOptions,
} from './provide-ngx-meta-manager'
export {
_provideNgxMetaModuleManager,
_ProvideNgxMetaModuleManagerOptions,
_withModuleManagerNameAttribute,
_withModuleManagerSetterFactory,
_withSameNameGlobal,
} from './provide-ngx-meta-module-manager'
export {
makeMetadataManagerProviderFromSetterFactory,
MetadataSetterFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
_ProvideNgxMetaManagerOptions,
provideNgxMetaManager,
withManagerDeps,
withManagerGlobal,
withManagerJsonPath,
} from './provide-ngx-meta-manager'
import {
NgxMetaElementNameAttribute,
NgxMetaElementsService,
withContentAttribute,
withNameAttribute,
} from '../../meta-elements'
import { MetadataSetterFactory } from './make-metadata-manager-provider-from-setter-factory'
import { withOptions } from '../../utils'

/**
* @internal
*/
export const _provideNgxMetaModuleManager = <
Type extends object,
Key extends StringKey<Type>,
>(
key: Key,
scope: ReadonlyArray<string>,
options: _ProvideNgxMetaModuleManagerOptions<Type[Key]> = {},
) =>
provideNgxMetaManager(
withManagerJsonPath(...scope, key),
options.f ??
((metaElementsService: NgxMetaElementsService) => (value) =>
metaElementsService.set(
options.n ?? withNameAttribute(key),
withContentAttribute(value as string | null | undefined),
)),
withOptions(
withManagerDeps(options.d ?? [NgxMetaElementsService]),
options.gS ? withManagerGlobal(key) : {},
options,
),
)

type StringKey<T = object> = Extract<keyof T, string>

/**
* @internal
*/
export type _ProvideNgxMetaModuleManagerOptions<T> = Partial<{
f: MetadataSetterFactory<T>
n: NgxMetaElementNameAttribute
gS: true
}> &
_ProvideNgxMetaManagerOptions

/**
* @internal
*/
export const _withModuleManagerSetterFactory = <T>(
setterFactory: _ProvideNgxMetaModuleManagerOptions<T>['f'],
): _ProvideNgxMetaModuleManagerOptions<T> => ({
f: setterFactory,
})

/**
* @internal
*/
export const _withModuleManagerNameAttribute = <T>(
nameAttribute: _ProvideNgxMetaModuleManagerOptions<T>['n'],
): _ProvideNgxMetaModuleManagerOptions<T> => ({
n: nameAttribute,
})

/**
* @internal
*/
export const _withSameNameGlobal = <
T,
>(): _ProvideNgxMetaModuleManagerOptions<T> => ({
gS: true,
})

0 comments on commit 2685d8e

Please sign in to comment.