diff --git a/src/lib/decorators/description.decorator.spec.ts b/src/lib/decorators/description.decorator.spec.ts index db6d776..c4fa6ad 100644 --- a/src/lib/decorators/description.decorator.spec.ts +++ b/src/lib/decorators/description.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Description', () => { it('should decorate a class', () => { @Description('This is a class') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -19,7 +19,7 @@ describe('Description', () => { class Foo { @Description('This is a property') - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') diff --git a/src/lib/decorators/description.decorator.ts b/src/lib/decorators/description.decorator.ts index f870949..779845f 100644 --- a/src/lib/decorators/description.decorator.ts +++ b/src/lib/decorators/description.decorator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -57,7 +58,7 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; */ export function Description(description: string) { - function Description(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Description(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) diff --git a/src/lib/decorators/example.decorator.spec.ts b/src/lib/decorators/example.decorator.spec.ts index e7484c3..2c59a74 100644 --- a/src/lib/decorators/example.decorator.spec.ts +++ b/src/lib/decorators/example.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Example', () => { it('should decorate a class', () => { @Example({ foo: 'fooooo!!!'}) class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -19,7 +19,7 @@ describe('Example', () => { class Foo { @Example('fooooo!!!') - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') diff --git a/src/lib/decorators/example.decorator.ts b/src/lib/decorators/example.decorator.ts index 11454da..8f6e9f0 100644 --- a/src/lib/decorators/example.decorator.ts +++ b/src/lib/decorators/example.decorator.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -61,7 +61,7 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; */ export function Example(value: any): (target: object, name?: string, propertyDescriptor?: TypedPropertyDescriptor | number) => void { - function Example(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Example(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) : MetadataDescriptor.for(target, name); diff --git a/src/lib/decorators/label.decorator.spec.ts b/src/lib/decorators/label.decorator.spec.ts index d391c1e..b8e2672 100644 --- a/src/lib/decorators/label.decorator.spec.ts +++ b/src/lib/decorators/label.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Label', () => { it('should decorate a class', () => { @Label('Foo') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -19,7 +19,7 @@ describe('Label', () => { class Foo { @Label('Foo') - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') @@ -55,7 +55,7 @@ describe('Label', () => { it('should set the plural', () => { @Label('Foo', 'Foos') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) diff --git a/src/lib/decorators/label.decorator.ts b/src/lib/decorators/label.decorator.ts index 08d6d14..789341f 100644 --- a/src/lib/decorators/label.decorator.ts +++ b/src/lib/decorators/label.decorator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -55,10 +56,10 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * @decoratorKind Metadata * @decoratorPropertyType any */ -export function Label(label: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void -export function Label(...args: string[]) { +export function Label(label: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void +export function Label(...args: any[]) { - function Label(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Label(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) diff --git a/src/lib/decorators/noun.decorator.spec.ts b/src/lib/decorators/noun.decorator.spec.ts index 084b56c..019fcc8 100644 --- a/src/lib/decorators/noun.decorator.spec.ts +++ b/src/lib/decorators/noun.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Noun', () => { it('should decorate a class', () => { @Noun('foo') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -19,7 +19,7 @@ describe('Noun', () => { class Foo { @Noun('foo') - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') @@ -55,7 +55,7 @@ describe('Noun', () => { it('should set the plural', () => { @Noun('foo', 'foos') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) diff --git a/src/lib/decorators/noun.decorator.ts b/src/lib/decorators/noun.decorator.ts index 7b51a09..6f0602b 100644 --- a/src/lib/decorators/noun.decorator.ts +++ b/src/lib/decorators/noun.decorator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -54,10 +55,10 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * @decoratorKind Metadata * @decoratorPropertyType any */ -export function Noun(noun: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void -export function Noun(...args: string[]) { +export function Noun(noun: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void +export function Noun(...args: any[]) { - function Noun(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Noun(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) diff --git a/src/lib/decorators/sensitive.decorator.spec.ts b/src/lib/decorators/sensitive.decorator.spec.ts index c38a749..4dd64b7 100644 --- a/src/lib/decorators/sensitive.decorator.spec.ts +++ b/src/lib/decorators/sensitive.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Label', () => { it('should decorate a class', () => { @Sensitive class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -17,7 +17,7 @@ describe('Label', () => { it('should set sensitive to false', () => { @Sensitive(false) class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -28,7 +28,7 @@ describe('Label', () => { class Foo { @Sensitive - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') diff --git a/src/lib/decorators/sensitive.decorator.ts b/src/lib/decorators/sensitive.decorator.ts index f45bc0b..148e0ce 100644 --- a/src/lib/decorators/sensitive.decorator.ts +++ b/src/lib/decorators/sensitive.decorator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -65,21 +66,21 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * @decoratorKind Metadata * @decoratorPropertyType any */ -export function Sensitive(sensitive?: boolean): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void -export function Sensitive(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number): void -export function Sensitive(...args: never[] ): ((target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void) | void { +export function Sensitive(sensitive?: boolean): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void +export function Sensitive(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number): void +export function Sensitive(...args: any[]): ((target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void) | void { let sensitive = true; - let target: object; - let name: string; - let indexOrPropertyDescriptor: TypedPropertyDescriptor | number; + let target: object | Class | undefined; + let name: string | undefined; + let indexOrPropertyDescriptor: TypedPropertyDescriptor | number | undefined; if (args.length === 0) sensitive = true; else if (args.length === 1 && typeof args[0] === 'boolean') sensitive = args[0]; else [target, name, indexOrPropertyDescriptor] = args, sensitive = true; - function Sensitive(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Sensitive(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) diff --git a/src/lib/decorators/token.decorator.spec.ts b/src/lib/decorators/token.decorator.spec.ts index c821303..12689ed 100644 --- a/src/lib/decorators/token.decorator.spec.ts +++ b/src/lib/decorators/token.decorator.spec.ts @@ -8,7 +8,7 @@ describe('Token', () => { it('should decorate a class', () => { @Token('foo') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) @@ -19,7 +19,7 @@ describe('Token', () => { class Foo { @Token('foo') - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo, 'foo') @@ -55,7 +55,7 @@ describe('Token', () => { it('should set the plural', () => { @Token('foo', 'foos') class Foo { - foo: string; + foo!: string; } const d = MetadataDescriptor.for(Foo) diff --git a/src/lib/decorators/token.decorator.ts b/src/lib/decorators/token.decorator.ts index 59daac5..b6e4430 100644 --- a/src/lib/decorators/token.decorator.ts +++ b/src/lib/decorators/token.decorator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; @@ -57,10 +58,10 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * @decoratorKind Metadata * @decoratorPropertyType any */ -export function Token(token: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void -export function Token(...args: string[]) { +export function Token(token: string | undefined, plural?: string): (target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) => void +export function Token(...args: any[]) { - function Token(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { + function Token(target: object | Class, name?: string, index?: TypedPropertyDescriptor | number) { const descriptor = index !== undefined && typeof index === "number" ? MetadataDescriptor.for(target, name, index) diff --git a/src/lib/descriptors/metadata.descriptor.spec.ts b/src/lib/descriptors/metadata.descriptor.spec.ts index 4adb6f1..f3ed570 100644 --- a/src/lib/descriptors/metadata.descriptor.spec.ts +++ b/src/lib/descriptors/metadata.descriptor.spec.ts @@ -2,7 +2,7 @@ import { MetadataDescriptor } from './metadata.descriptor'; describe('MetadataDescriptor', () => { - let d: MetadataDescriptor; + let d: MetadataDescriptor | undefined; beforeEach(() => { d = undefined; @@ -52,7 +52,7 @@ describe('MetadataDescriptor', () => { }) it('should get the descriptor for a property', () => { class Foo { - foo: string; + foo!: string; } d = MetadataDescriptor.for(Foo.prototype, 'foo') @@ -61,7 +61,7 @@ describe('MetadataDescriptor', () => { }) it('should get the descriptor for a parameter', () => { class Foo { - foo: string; + foo!: string; } d = MetadataDescriptor.for(Foo.prototype, 'foo', 0) diff --git a/src/lib/descriptors/metadata.descriptor.ts b/src/lib/descriptors/metadata.descriptor.ts index 30a8ca8..1e7ca94 100644 --- a/src/lib/descriptors/metadata.descriptor.ts +++ b/src/lib/descriptors/metadata.descriptor.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import 'reflect-metadata'; @@ -22,11 +23,11 @@ export class MetadataDescriptor { description?: string; - example?: unknown; + example?: any; static for(target: Class | object, property?: string, index?: number): MetadataDescriptor { const prototype = typeof target === 'function' ? target.prototype : target; - const token = index !== undefined ? property : `${property}:${index}`; + const token = index !== undefined ? `${property}:${index}` : property || ''; let descriptor = Reflect.getMetadata('agape:metadata', prototype, token); if (descriptor) return descriptor; @@ -36,4 +37,10 @@ export class MetadataDescriptor { return descriptor; } + + static get(target: Class | object, property?: string, index?: number): MetadataDescriptor | undefined { + const prototype = typeof target === 'function' ? target.prototype : target; + const token = index !== undefined ? `${property}:${index}` : property || ''; + return Reflect.getMetadata('agape:metadata', prototype, token); + } } diff --git a/src/lib/functions/description.spec.ts b/src/lib/functions/description.spec.ts index eeffa4a..38a8f3d 100644 --- a/src/lib/functions/description.spec.ts +++ b/src/lib/functions/description.spec.ts @@ -14,7 +14,7 @@ describe('description', () => { it('should work with properties', () => { class Foo { @Description('description') - foo: string; + foo!: string; } expect(description(Foo, 'foo')).toBe('description') diff --git a/src/lib/functions/description.ts b/src/lib/functions/description.ts index 044651e..a2766a4 100644 --- a/src/lib/functions/description.ts +++ b/src/lib/functions/description.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function description(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).description; +/** + * Retrieves the description metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `description` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Description + * + * ```ts + * const desc = description(MyClass); + * ``` + * + * ### Property Level Description + * + * ```ts + * const desc = description(MyClass, 'title'); + * ``` + * + * ### Parameter Level Description + * + * ```ts + * const desc = description(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The description metadata if found; otherwise, `undefined`. + */ +export function description(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.description; } diff --git a/src/lib/functions/example.spec.ts b/src/lib/functions/example.spec.ts index f0706b1..7df66df 100644 --- a/src/lib/functions/example.spec.ts +++ b/src/lib/functions/example.spec.ts @@ -14,7 +14,7 @@ describe('sensitive', () => { it('should work with properties', () => { class Foo { @Sensitive - foo: string; + foo!: string; } expect(sensitive(Foo, 'foo')).toBe(true); diff --git a/src/lib/functions/example.ts b/src/lib/functions/example.ts index a97acd6..c9d34a5 100644 --- a/src/lib/functions/example.ts +++ b/src/lib/functions/example.ts @@ -1,6 +1,39 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function example(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).example; +/** + * Retrieves the example metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `example` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Example + * + * ```ts + * const metadata = example(MyClass); + * ``` + * + * ### Property Level Example + * + * ```ts + * const metadata = example(MyClass, 'title'); + * ``` + * + * ### Parameter Level Example + * + * ```ts + * const metadata = example(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The example metadata if found; otherwise, `undefined`. + */ +export function example(target: Class, property?: string, index?: number): any | undefined { + return MetadataDescriptor.get(target, property, index)?.example; } diff --git a/src/lib/functions/label.spec.ts b/src/lib/functions/label.spec.ts index 6e53571..32de863 100644 --- a/src/lib/functions/label.spec.ts +++ b/src/lib/functions/label.spec.ts @@ -14,7 +14,7 @@ describe('label', () => { it('should work with properties', () => { class Foo { @Label('Foo') - foo: string; + foo!: string; } expect(label(Foo, 'foo')).toBe('Foo') diff --git a/src/lib/functions/label.ts b/src/lib/functions/label.ts index 4a9384a..e53a613 100644 --- a/src/lib/functions/label.ts +++ b/src/lib/functions/label.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function label(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).label; +/** + * Retrieves the label metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `label` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Label + * + * ```ts + * const metadata = label(MyClass); + * ``` + * + * ### Property Level Label + * + * ```ts + * const metadata = label(MyClass, 'title'); + * ``` + * + * ### Parameter Level Label + * + * ```ts + * const metadata = label(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The label metadata if found; otherwise, `undefined`. + */ +export function label(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.label; } diff --git a/src/lib/functions/labels.spec.ts b/src/lib/functions/labels.spec.ts index dab28da..fa808c3 100644 --- a/src/lib/functions/labels.spec.ts +++ b/src/lib/functions/labels.spec.ts @@ -14,7 +14,7 @@ describe('labels', () => { it('should work with properties', () => { class Foo { @Label('Foo', 'Foos') - foo: string; + foo!: string; } expect(labels(Foo, 'foo')).toBe('Foos') diff --git a/src/lib/functions/labels.ts b/src/lib/functions/labels.ts index eb65e1d..6c778b7 100644 --- a/src/lib/functions/labels.ts +++ b/src/lib/functions/labels.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function labels(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).labels; +/** + * Retrieves the label metadata (plural form) associated with a class, property, or method parameter. + * + * This function is used to fetch the `labels` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Labels + * + * ```ts + * const metadata = labels(MyClass); + * ``` + * + * ### Property Level Labels + * + * ```ts + * const metadata = labels(MyClass, 'title'); + * ``` + * + * ### Parameter Level Labels + * + * ```ts + * const metadata = labels(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The labels metadata if found; otherwise, `undefined`. + */ +export function labels(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.labels; } diff --git a/src/lib/functions/noun.spec.ts b/src/lib/functions/noun.spec.ts index d91e86a..f25e813 100644 --- a/src/lib/functions/noun.spec.ts +++ b/src/lib/functions/noun.spec.ts @@ -14,7 +14,7 @@ describe('noun', () => { it('should work with properties', () => { class Foo { @Noun('foo') - foo: string; + foo!: string; } expect(noun(Foo, 'foo')).toBe('foo') diff --git a/src/lib/functions/noun.ts b/src/lib/functions/noun.ts index 089e560..5e437ca 100644 --- a/src/lib/functions/noun.ts +++ b/src/lib/functions/noun.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function noun(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).noun; +/** + * Retrieves the noun metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `noun` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Noun + * + * ```ts + * const metadata = noun(MyClass); + * ``` + * + * ### Property Level Noun + * + * ```ts + * const metadata = noun(MyClass, 'title'); + * ``` + * + * ### Parameter Level Noun + * + * ```ts + * const metadata = noun(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The noun metadata if found; otherwise, `undefined`. + */ +export function noun(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.noun; } diff --git a/src/lib/functions/nouns.spec.ts b/src/lib/functions/nouns.spec.ts index 8166669..0f5a528 100644 --- a/src/lib/functions/nouns.spec.ts +++ b/src/lib/functions/nouns.spec.ts @@ -14,7 +14,7 @@ describe('nouns', () => { it('should work with properties', () => { class Foo { @Noun('foo', 'foos') - foo: string; + foo!: string; } expect(nouns(Foo, 'foo')).toBe('foos') diff --git a/src/lib/functions/nouns.ts b/src/lib/functions/nouns.ts index d0939a2..e270380 100644 --- a/src/lib/functions/nouns.ts +++ b/src/lib/functions/nouns.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function nouns(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).nouns; +/** + * Retrieves the noun metadata (plural form) associated with a class, property, or method parameter. + * + * This function is used to fetch the `nouns` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Nouns + * + * ```ts + * const metadata = nouns(MyClass); + * ``` + * + * ### Property Level Nouns + * + * ```ts + * const metadata = nouns(MyClass, 'title'); + * ``` + * + * ### Parameter Level Nouns + * + * ```ts + * const metadata = nouns(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The nouns metadata if found; otherwise, `undefined`. + */ +export function nouns(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.nouns; } diff --git a/src/lib/functions/sensitive.spec.ts b/src/lib/functions/sensitive.spec.ts index f0706b1..7df66df 100644 --- a/src/lib/functions/sensitive.spec.ts +++ b/src/lib/functions/sensitive.spec.ts @@ -14,7 +14,7 @@ describe('sensitive', () => { it('should work with properties', () => { class Foo { @Sensitive - foo: string; + foo!: string; } expect(sensitive(Foo, 'foo')).toBe(true); diff --git a/src/lib/functions/sensitive.ts b/src/lib/functions/sensitive.ts index 3853888..54358b1 100644 --- a/src/lib/functions/sensitive.ts +++ b/src/lib/functions/sensitive.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function sensitive(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).sensitive; +/** + * Retrieves the sensitive metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `sensitive` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Sensitive + * + * ```ts + * const metadata = sensitive(MyClass); + * ``` + * + * ### Property Level Sensitive + * + * ```ts + * const metadata = sensitive(MyClass, 'password'); + * ``` + * + * ### Parameter Level Sensitive + * + * ```ts + * const metadata = sensitive(MyClass, 'setPassword', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The sensitive metadata if found; otherwise, `undefined`. + */ +export function sensitive(target: Class, property?: string, index?: number): boolean | undefined { + return MetadataDescriptor.get(target, property, index)?.sensitive; } diff --git a/src/lib/functions/token.spec.ts b/src/lib/functions/token.spec.ts index 58f873f..5685606 100644 --- a/src/lib/functions/token.spec.ts +++ b/src/lib/functions/token.spec.ts @@ -14,7 +14,7 @@ describe('token', () => { it('should work with properties', () => { class Foo { @Token('foo') - foo: string; + foo!: string; } expect(token(Foo, 'foo')).toBe('foo') diff --git a/src/lib/functions/token.ts b/src/lib/functions/token.ts index 322639f..0634afe 100644 --- a/src/lib/functions/token.ts +++ b/src/lib/functions/token.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function token(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).token; +/** + * Retrieves the token metadata associated with a class, property, or method parameter. + * + * This function is used to fetch the `token` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Token + * + * ```ts + * const metadata = token(MyClass); + * ``` + * + * ### Property Level Token + * + * ```ts + * const metadata = token(MyClass, 'title'); + * ``` + * + * ### Parameter Level Token + * + * ```ts + * const metadata = token(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The token metadata if found; otherwise, `undefined`. + */ +export function token(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.token; } diff --git a/src/lib/functions/tokens.spec.ts b/src/lib/functions/tokens.spec.ts index 6a3ce83..eaae574 100644 --- a/src/lib/functions/tokens.spec.ts +++ b/src/lib/functions/tokens.spec.ts @@ -14,7 +14,7 @@ describe('tokens', () => { it('should work with properties', () => { class Foo { @Token('foo', 'foos') - foo: string; + foo!: string; } expect(tokens(Foo, 'foo')).toBe('foos') diff --git a/src/lib/functions/tokens.ts b/src/lib/functions/tokens.ts index 50b6100..b0a4e15 100644 --- a/src/lib/functions/tokens.ts +++ b/src/lib/functions/tokens.ts @@ -1,6 +1,38 @@ import { Class } from '@agape/types'; import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; -export function tokens(target: Class, property?: string, index?: number) { - return MetadataDescriptor.for(target, property, index).tokens; +/** + * Retrieves the tokens metadata (plural form) associated with a class, property, or method parameter. + * + * This function is used to fetch the `tokens` value stored via metadata for the given target. + * It supports metadata attached at the class level, property level, or parameter level depending + * on which arguments are provided. + * + * ## Usage + * + * ### Class Level Tokens + * + * ```ts + * const metadata = tokens(MyClass); + * ``` + * + * ### Property Level Tokens + * + * ```ts + * const metadata = tokens(MyClass, 'title'); + * ``` + * + * ### Parameter Level Tokens + * + * ```ts + * const metadata = tokens(MyClass, 'setTitle', 0); + * ``` + * + * @param target - The target class constructor to retrieve metadata from. + * @param property - The name of the property or method to retrieve metadata for. + * @param index - The index of the parameter if retrieving metadata for a method parameter. + * @returns The tokens metadata if found; otherwise, `undefined`. + */ +export function tokens(target: Class, property?: string, index?: number): string | undefined { + return MetadataDescriptor.get(target, property, index)?.tokens; }