diff --git a/projects/ngx-meta/e2e/a15/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts b/projects/ngx-meta/e2e/a15/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts index c490c39d..080bf751 100644 --- a/projects/ngx-meta/e2e/a15/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts +++ b/projects/ngx-meta/e2e/a15/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core' -import { MetadataService, MetadataValues } from '@davidlj95/ngx-meta/core' +import { MetadataService } from '@davidlj95/ngx-meta/core' import { ActivatedRoute } from '@angular/router' import { OPEN_GRAPH_TYPE_BOOK, @@ -42,8 +42,6 @@ export class MetaSetByRouteAndServiceComponent implements OnInit { } ngOnInit(): void { - this.metadataService.set( - this.overriddenMetadata as unknown as MetadataValues, - ) + this.metadataService.set(this.overriddenMetadata) } } diff --git a/projects/ngx-meta/e2e/a16/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts b/projects/ngx-meta/e2e/a16/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts index c490c39d..080bf751 100644 --- a/projects/ngx-meta/e2e/a16/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts +++ b/projects/ngx-meta/e2e/a16/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core' -import { MetadataService, MetadataValues } from '@davidlj95/ngx-meta/core' +import { MetadataService } from '@davidlj95/ngx-meta/core' import { ActivatedRoute } from '@angular/router' import { OPEN_GRAPH_TYPE_BOOK, @@ -42,8 +42,6 @@ export class MetaSetByRouteAndServiceComponent implements OnInit { } ngOnInit(): void { - this.metadataService.set( - this.overriddenMetadata as unknown as MetadataValues, - ) + this.metadataService.set(this.overriddenMetadata) } } diff --git a/projects/ngx-meta/e2e/a17/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts b/projects/ngx-meta/e2e/a17/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts index 5fff9594..43f72143 100644 --- a/projects/ngx-meta/e2e/a17/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts +++ b/projects/ngx-meta/e2e/a17/src/app/meta-set-by-route-and-service/meta-set-by-route-and-service.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core' -import { MetadataService, MetadataValues } from '@davidlj95/ngx-meta/core' +import { MetadataService } from '@davidlj95/ngx-meta/core' import { JsonPipe } from '@angular/common' import { ActivatedRoute } from '@angular/router' import { @@ -45,8 +45,6 @@ export class MetaSetByRouteAndServiceComponent implements OnInit { } ngOnInit(): void { - this.metadataService.set( - this.overriddenMetadata as unknown as MetadataValues, - ) + this.metadataService.set(this.overriddenMetadata) } } diff --git a/projects/ngx-meta/src/core/src/metadata-json-resolver.ts b/projects/ngx-meta/src/core/src/metadata-json-resolver.ts index f115e1a9..a29b0ce9 100644 --- a/projects/ngx-meta/src/core/src/metadata-json-resolver.ts +++ b/projects/ngx-meta/src/core/src/metadata-json-resolver.ts @@ -6,21 +6,23 @@ import { Injectable } from '@angular/core' @Injectable({ providedIn: 'root' }) export class MetadataJsonResolver { - get(definition: Metadata, values?: MetadataValues): T | undefined { + get(metadata: Metadata, values?: MetadataValues): T | undefined { if (values === undefined) { return } - const keys = [...definition.jsonPath] + const keys = [...metadata.jsonPath] let value: unknown = values for (const key of keys) { if (value === undefined || value === null) { break } - value = (value as MetadataValues)[key] + value = (value as IndexedObject)[key] } const globalValue = - definition.global !== undefined ? values[definition.global] : undefined + metadata.global !== undefined + ? (values as IndexedObject)[metadata.global] + : undefined if (value !== undefined && !globalValue) { return value as MaybeUndefined } @@ -33,3 +35,5 @@ export class MetadataJsonResolver { return globalValue as MaybeUndefined } } + +type IndexedObject = Record diff --git a/projects/ngx-meta/src/core/src/metadata-values.ts b/projects/ngx-meta/src/core/src/metadata-values.ts index 83543cc9..ed0728c4 100644 --- a/projects/ngx-meta/src/core/src/metadata-values.ts +++ b/projects/ngx-meta/src/core/src/metadata-values.ts @@ -1,3 +1 @@ -export interface MetadataValues { - [key: string]: unknown -} +export type MetadataValues = object diff --git a/projects/ngx-meta/src/core/src/route-metadata-values.spec.ts b/projects/ngx-meta/src/core/src/route-metadata-values.spec.ts index 2d5a54cd..44ec8ab6 100644 --- a/projects/ngx-meta/src/core/src/route-metadata-values.spec.ts +++ b/projects/ngx-meta/src/core/src/route-metadata-values.spec.ts @@ -4,13 +4,12 @@ import { RouteMetadataValues } from './route-metadata-values' import { enableAutoSpy } from '../../__tests__/enable-auto-spy' import { MockProviders } from 'ng-mocks' import { Router } from '@angular/router' -import { MetadataValues } from './metadata-values' describe('RouteMetadataValues', () => { enableAutoSpy() let sut: RouteMetadataValues let router: jasmine.SpyObj - const dummyValues: MetadataValues = { foo: 'bar' } + const dummyValues = { foo: 'bar' } const url = '/set-url' beforeEach(() => { diff --git a/projects/ngx-meta/src/routing/src/metadata-route-data.ts b/projects/ngx-meta/src/routing/src/metadata-route-data.ts index 6ec38f9c..6d1bbb45 100644 --- a/projects/ngx-meta/src/routing/src/metadata-route-data.ts +++ b/projects/ngx-meta/src/routing/src/metadata-route-data.ts @@ -1,5 +1,5 @@ -import { GlobalMetadata, MetadataValues } from '@davidlj95/ngx-meta/core' +import { MetadataValues } from '@davidlj95/ngx-meta/core' -export interface MetadataRouteData { - meta: GlobalMetadata & MetadataValues +export interface MetadataRouteData { + meta: M } diff --git a/projects/ngx-meta/src/routing/src/metadata-route-strategy.ts b/projects/ngx-meta/src/routing/src/metadata-route-strategy.ts index 3448d660..9ec2205b 100644 --- a/projects/ngx-meta/src/routing/src/metadata-route-strategy.ts +++ b/projects/ngx-meta/src/routing/src/metadata-route-strategy.ts @@ -1,10 +1,12 @@ import { InjectionToken } from '@angular/core' import { ActivatedRouteSnapshot } from '@angular/router' +import { MetadataValues } from '@davidlj95/ngx-meta/core' -export type MetadataRouteStrategy = ( +export type MetadataRouteStrategy = ( activatedRouteSnapshot: ActivatedRouteSnapshot, -) => T | undefined +) => MetadataValues | undefined -export const METADATA_ROUTE_STRATEGY = new InjectionToken( - ngDevMode ? 'NgxMeta Metadata Route Strategy' : 'NgxMetaMRS', -) +export const METADATA_ROUTE_STRATEGY = + new InjectionToken( + ngDevMode ? 'NgxMeta Metadata Route Strategy' : 'NgxMetaMRS', + )