diff --git a/README.md b/README.md index 5fd4c33..567305e 100644 --- a/README.md +++ b/README.md @@ -55,55 +55,7 @@ class User { @Description('Account creation timestamp') createdAt!: Date; } - -// Use metadata in your application -const content = ` -

Edit ${label(User)}

-
${description(User)}
-
- - - - - -
-`; ``` - ---- - -## 🔧 Functions - -### `description(target, property?, index?)` -Retrieves the description metadata for a class, property, or parameter. - -### `name(target, property?, index?)` -Retrieves the name metadata for a class, property, or parameter. - -### `label(target, property?, index?)` -Retrieves the label metadata for a class, property, or parameter. - -### `sensitive(target, property?, index?)` -Checks if a class, property, or parameter is marked as sensitive. - -### `token(target, property?, index?)` -Retrieves the token metadata for a class, property, or parameter. - -### `noun(target, property?, index?)` -Retrieves the noun metadata for a class, property, or parameter. - -### `example(target, property?, index?)` -Retrieves the example metadata for a class, property, or parameter. - -### `labels(target, property?, index?)` -Retrieves the plural label for a class, property, or parameter. - -### `tokens(target, property?, index?)` -Retrieves the plural token for a class, property, or parameter. - -### `nouns(target, property?, index?)` -Retrieves the plural noun for a class, property, or parameter. - --- ## 🏗️ MetadataDescriptor @@ -114,28 +66,6 @@ Creates or retrieves a metadata descriptor for a class, property, or parameter. ### `MetadataDescriptor.get(target, property?, index?)` Retrieves an existing metadata descriptor for a class, property, or parameter. -### Example -```ts -import { MetadataDescriptor } from '@agape/metadata'; - -// Get descriptor for a property -const descriptor = MetadataDescriptor.for(User, 'email'); - -// Access all metadata properties -console.log(descriptor.description); // "The user's email address..." -console.log(descriptor.label); // "Email Address" -console.log(descriptor.name); // "email" -console.log(descriptor.sensitive); // true -console.log(descriptor.token); // "user.email" -console.log(descriptor.noun); // "email" -console.log(descriptor.nouns); // "emails" -console.log(descriptor.example); // "john.doe@example.com" - -// Set metadata directly -descriptor.description = "Updated description"; -descriptor.sensitive = false; -``` - --- ## 📚 Documentation diff --git a/package.json b/package.json index e8167c0..329ddca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@agape/metadata", - "version": "0.1.0", + "version": "0.1.1", "description": "Metadata annotations", "main": "./cjs/index.js", "module": "./es2020/index.js", diff --git a/src/index.ts b/src/index.ts index 2953bea..a84ba5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,13 +6,3 @@ export * from './lib/decorators/noun.decorator'; export * from './lib/decorators/sensitive.decorator'; export * from './lib/decorators/token.decorator'; export * from './lib/descriptors/metadata.descriptor'; -export * from './lib/functions/description'; -export * from './lib/functions/example'; -export * from './lib/functions/label'; -export * from './lib/functions/labels'; -export * from './lib/functions/name'; -export * from './lib/functions/noun'; -export * from './lib/functions/nouns'; -export * from './lib/functions/sensitive'; -export * from './lib/functions/token'; -export * from './lib/functions/tokens'; diff --git a/src/lib/decorators/label.decorator.spec.ts b/src/lib/decorators/label.decorator.spec.ts index b8e2672..682ed86 100644 --- a/src/lib/decorators/label.decorator.spec.ts +++ b/src/lib/decorators/label.decorator.spec.ts @@ -59,6 +59,6 @@ describe('Label', () => { } const d = MetadataDescriptor.for(Foo) - expect(d.labels).toBe('Foos') + expect(d.labelPlural).toBe('Foos') }) }) diff --git a/src/lib/decorators/label.decorator.ts b/src/lib/decorators/label.decorator.ts index d88806e..87012df 100644 --- a/src/lib/decorators/label.decorator.ts +++ b/src/lib/decorators/label.decorator.ts @@ -8,7 +8,7 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * Labels can be used when displaying in user interfaces such as form inputs, * tables, and auto-generated documentation. * - * > This decorator sets the `label` and `labels` properties + * > This decorator sets the `label` and `labelPlural` properties * on the associated {@link MetadataDescriptor}. * * @example @@ -69,7 +69,7 @@ export function Label(...args: any[]) { descriptor.label = args[0]; - if (args.length > 1) descriptor.labels = args[1]; + if (args.length > 1) descriptor.labelPlural = args[1]; } return Label diff --git a/src/lib/decorators/noun.decorator.spec.ts b/src/lib/decorators/noun.decorator.spec.ts index 019fcc8..9c6c74b 100644 --- a/src/lib/decorators/noun.decorator.spec.ts +++ b/src/lib/decorators/noun.decorator.spec.ts @@ -59,6 +59,6 @@ describe('Noun', () => { } const d = MetadataDescriptor.for(Foo) - expect(d.nouns).toBe('foos') + expect(d.nounPlural).toBe('foos') }) }) diff --git a/src/lib/decorators/noun.decorator.ts b/src/lib/decorators/noun.decorator.ts index 152ab58..7555723 100644 --- a/src/lib/decorators/noun.decorator.ts +++ b/src/lib/decorators/noun.decorator.ts @@ -7,7 +7,7 @@ import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; * * Nouns can be used when referencing the object or attribute. * - * > This decorator sets the `noun` and `nouns` properties + * > This decorator sets the `noun` and `nounPlural` properties * on the associated {@link MetadataDescriptor}. * * @example @@ -68,7 +68,7 @@ export function Noun(...args: any[]) { descriptor.noun = args[0]; - if (args.length > 1) descriptor.nouns = args[1]; + if (args.length > 1) descriptor.nounPlural = args[1]; } return Noun diff --git a/src/lib/descriptors/metadata.descriptor.spec.ts b/src/lib/descriptors/metadata.descriptor.spec.ts index f9d156d..06f72b7 100644 --- a/src/lib/descriptors/metadata.descriptor.spec.ts +++ b/src/lib/descriptors/metadata.descriptor.spec.ts @@ -15,9 +15,9 @@ describe('MetadataDescriptor', () => { it('should set some properties', () => { d = new MetadataDescriptor('TestName'); d.label = 'Label'; - d.labels = 'Labels'; + d.labelPlural = 'Labels'; d.noun = 'noun'; - d.nouns = 'nouns'; + d.nounPlural = 'nouns'; d.token = 'token'; d.tokens = 'tokens'; d.sensitive = true; @@ -26,9 +26,9 @@ describe('MetadataDescriptor', () => { expect(d.name).toEqual('TestName'); expect(d.label).toEqual('Label'); - expect(d.labels).toEqual('Labels'); + expect(d.labelPlural).toEqual('Labels'); expect(d.noun).toEqual('noun'); - expect(d.nouns).toEqual('nouns'); + expect(d.nounPlural).toEqual('nouns'); expect(d.token).toEqual('token'); expect(d.tokens).toEqual('tokens'); expect(d.sensitive).toEqual(true); diff --git a/src/lib/descriptors/metadata.descriptor.ts b/src/lib/descriptors/metadata.descriptor.ts index b108570..e2ab639 100644 --- a/src/lib/descriptors/metadata.descriptor.ts +++ b/src/lib/descriptors/metadata.descriptor.ts @@ -6,7 +6,7 @@ import 'reflect-metadata'; * A descriptor that holds metadata information for classes, properties, methods, and parameters. * * The `MetadataDescriptor` class is used to store and retrieve metadata associated with various - * elements in your codebase. It supports storing information like names, labels, descriptions, + * elements in your codebase. It supports storing information like names, labelPlural, descriptions, * and other metadata that can be used for serialization, validation, documentation generation, * and other metadata-driven operations. * @@ -39,7 +39,7 @@ import 'reflect-metadata'; * * @example * ### Example - * + * * ```ts * class User { * @Label('Email address') @@ -86,7 +86,7 @@ export class MetadataDescriptor { * Used when displaying multiple instances of the decorated element, * such as in table headers or list titles. */ - labels?: string; + labelPlural?: string; /** * A noun that represents the decorated element. @@ -101,7 +101,7 @@ export class MetadataDescriptor { * * Used when referring to multiple instances of the decorated element. */ - nouns?: string; + nounPlural?: string; /** * A token identifier for the decorated element. diff --git a/src/lib/functions/description.spec.ts b/src/lib/functions/description.spec.ts deleted file mode 100644 index 38a8f3d..0000000 --- a/src/lib/functions/description.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Description } from '../decorators/description.decorator' -import { description } from './description'; - -describe('description', () => { - it('should return the description', () => { - @Description('description') - class Foo { } - - expect(description(Foo)).toBe('description') - }) - - it('should work with properties', () => { - class Foo { - @Description('description') - foo!: string; - } - - expect(description(Foo, 'foo')).toBe('description') - }) - - it('should work with methods', () => { - class Foo { - @Description('description') - foo() { - - } - } - - expect(description(Foo, 'foo')).toBe('description') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Description('description') bar: string) { - - } - } - - expect(description(Foo, 'foo', 0)).toBe('description') - }) -}) diff --git a/src/lib/functions/description.ts b/src/lib/functions/description.ts deleted file mode 100644 index 0755dc1..0000000 --- a/src/lib/functions/description.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Description - * - * ```ts - * const desc = description(MyClass); - * ``` - * - * @example - * ### Property Level Description - * - * ```ts - * const desc = description(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index 7df66df..0000000 --- a/src/lib/functions/example.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Sensitive } from '../decorators/sensitive.decorator' -import { sensitive } from './sensitive'; - -describe('sensitive', () => { - it('should return the sensitive', () => { - @Sensitive - class Foo { } - - expect(sensitive(Foo)).toBe(true); - }) - - it('should work with properties', () => { - class Foo { - @Sensitive - foo!: string; - } - - expect(sensitive(Foo, 'foo')).toBe(true); - }) - - it('should work with methods', () => { - class Foo { - @Sensitive - foo() { - - } - } - - expect(sensitive(Foo, 'foo')).toBe(true); - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Sensitive bar: string) { - - } - } - - expect(sensitive(Foo, 'foo', 0)).toBe(true); - }) -}) diff --git a/src/lib/functions/example.ts b/src/lib/functions/example.ts deleted file mode 100644 index 3002499..0000000 --- a/src/lib/functions/example.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Example - * - * ```ts - * const metadata = example(MyClass); - * ``` - * - * @example - * ### Property Level Example - * - * ```ts - * const metadata = example(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index 32de863..0000000 --- a/src/lib/functions/label.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Label } from '../decorators/label.decorator' -import { label } from './label'; - -describe('label', () => { - it('should return the label', () => { - @Label('Foo') - class Foo { } - - expect(label(Foo)).toBe('Foo') - }) - - it('should work with properties', () => { - class Foo { - @Label('Foo') - foo!: string; - } - - expect(label(Foo, 'foo')).toBe('Foo') - }) - - it('should work with methods', () => { - class Foo { - @Label('Foo') - foo() { - - } - } - - expect(label(Foo, 'foo')).toBe('Foo') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Label('Bar') bar: string) { - - } - } - - expect(label(Foo, 'foo', 0)).toBe('Bar') - }) -}) diff --git a/src/lib/functions/label.ts b/src/lib/functions/label.ts deleted file mode 100644 index 3edd6ed..0000000 --- a/src/lib/functions/label.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Label - * - * ```ts - * const metadata = label(MyClass); - * ``` - * - * @example - * ### Property Level Label - * - * ```ts - * const metadata = label(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index fa808c3..0000000 --- a/src/lib/functions/labels.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Label } from '../decorators/label.decorator' -import { labels } from './labels'; - -describe('labels', () => { - it('should return the label', () => { - @Label('Foo', 'Foos') - class Foo { } - - expect(labels(Foo)).toBe('Foos') - }) - - it('should work with properties', () => { - class Foo { - @Label('Foo', 'Foos') - foo!: string; - } - - expect(labels(Foo, 'foo')).toBe('Foos') - }) - - it('should work with methods', () => { - class Foo { - @Label('Foo', 'Foos') - foo() { - - } - } - - expect(labels(Foo, 'foo')).toBe('Foos') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Label('Bar', 'Bars') bar: string) { - - } - } - - expect(labels(Foo, 'foo', 0)).toBe('Bars') - }) -}) diff --git a/src/lib/functions/labels.ts b/src/lib/functions/labels.ts deleted file mode 100644 index dac9087..0000000 --- a/src/lib/functions/labels.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Labels - * - * ```ts - * const metadata = labels(MyClass); - * ``` - * - * @example - * ### Property Level Labels - * - * ```ts - * const metadata = labels(MyClass, 'title'); - * ``` - * - * @example - * ### 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/name.spec.ts b/src/lib/functions/name.spec.ts deleted file mode 100644 index b4130df..0000000 --- a/src/lib/functions/name.spec.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { name } from './name'; -import { Name } from '../decorators/name.decorator'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -describe('name', () => { - - it('should get name from class', () => { - @Name('Product') - class Product { - name!: string; - } - - const result = name(Product); - expect(result).toEqual('Product'); - }); - - it('should get name from property', () => { - class Product { - @Name('skuCode') - sku!: string; - } - - const result = name(Product, 'sku'); - expect(result).toEqual('skuCode'); - }); - - it('should get name from method', () => { - class ProductService { - @Name('createProduct') - create(): void { - // ... - } - } - - const result = name(ProductService, 'create'); - expect(result).toEqual('createProduct'); - }); - - it('should get name from parameter', () => { - class ProductService { - create(@Name('product') product: any): void { - // ... - } - } - - const result = name(ProductService, 'create', 0); - expect(result).toEqual('product'); - }); - - it('should return undefined when no name is set', () => { - class Product { - sku!: string; - } - - const classResult = name(Product); - const propertyResult = name(Product, 'sku'); - - expect(classResult).toBeUndefined(); - expect(propertyResult).toBeUndefined(); - }); - - it('should return automatically set name when no decorator is used', () => { - class Product { - sku!: string; - } - - // Get descriptors to trigger automatic name setting - MetadataDescriptor.for(Product); - MetadataDescriptor.for(Product, 'sku'); - - const classResult = name(Product); - const propertyResult = name(Product, 'sku'); - - expect(classResult).toEqual('Product'); - expect(propertyResult).toEqual('sku'); - }); - -}); diff --git a/src/lib/functions/name.ts b/src/lib/functions/name.ts deleted file mode 100644 index bab5311..0000000 --- a/src/lib/functions/name.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * Retrieves the name metadata associated with a class, property, or method parameter. - * - * This function is used to fetch the `name` 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. - * - * @example - * ### Class Level Name - * - * ```ts - * const metadata = name(MyClass); - * ``` - * - * @example - * ### Property Level Name - * - * ```ts - * const metadata = name(MyClass, 'title'); - * ``` - * - * @example - * ### Parameter Level Name - * - * ```ts - * const metadata = name(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 name metadata if found; otherwise, `undefined`. - */ -export function name(target: Class, property?: string, index?: number): string | undefined { - return MetadataDescriptor.get(target, property, index)?.name; -} diff --git a/src/lib/functions/noun.spec.ts b/src/lib/functions/noun.spec.ts deleted file mode 100644 index f25e813..0000000 --- a/src/lib/functions/noun.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Noun } from '../decorators/noun.decorator' -import { noun } from './noun'; - -describe('noun', () => { - it('should return the noun', () => { - @Noun('foo') - class Foo { } - - expect(noun(Foo)).toBe('foo') - }) - - it('should work with properties', () => { - class Foo { - @Noun('foo') - foo!: string; - } - - expect(noun(Foo, 'foo')).toBe('foo') - }) - - it('should work with methods', () => { - class Foo { - @Noun('foo') - foo() { - - } - } - - expect(noun(Foo, 'foo')).toBe('foo') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Noun('bar') bar: string) { - - } - } - - expect(noun(Foo, 'foo', 0)).toBe('bar') - }) -}) diff --git a/src/lib/functions/noun.ts b/src/lib/functions/noun.ts deleted file mode 100644 index db72acd..0000000 --- a/src/lib/functions/noun.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Noun - * - * ```ts - * const metadata = noun(MyClass); - * ``` - * - * @example - * ### Property Level Noun - * - * ```ts - * const metadata = noun(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index 0f5a528..0000000 --- a/src/lib/functions/nouns.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Noun } from '../decorators/noun.decorator' -import { nouns } from './nouns'; - -describe('nouns', () => { - it('should return the noun', () => { - @Noun('foo', 'foos') - class Foo { } - - expect(nouns(Foo)).toBe('foos') - }) - - it('should work with properties', () => { - class Foo { - @Noun('foo', 'foos') - foo!: string; - } - - expect(nouns(Foo, 'foo')).toBe('foos') - }) - - it('should work with methods', () => { - class Foo { - @Noun('foo', 'foos') - foo() { - - } - } - - expect(nouns(Foo, 'foo')).toBe('foos') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Noun('Bar', 'Bars') bar: string) { - - } - } - - expect(nouns(Foo, 'foo', 0)).toBe('Bars') - }) -}) diff --git a/src/lib/functions/nouns.ts b/src/lib/functions/nouns.ts deleted file mode 100644 index bd2e8fb..0000000 --- a/src/lib/functions/nouns.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Nouns - * - * ```ts - * const metadata = nouns(MyClass); - * ``` - * - * @example - * ### Property Level Nouns - * - * ```ts - * const metadata = nouns(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index 7df66df..0000000 --- a/src/lib/functions/sensitive.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Sensitive } from '../decorators/sensitive.decorator' -import { sensitive } from './sensitive'; - -describe('sensitive', () => { - it('should return the sensitive', () => { - @Sensitive - class Foo { } - - expect(sensitive(Foo)).toBe(true); - }) - - it('should work with properties', () => { - class Foo { - @Sensitive - foo!: string; - } - - expect(sensitive(Foo, 'foo')).toBe(true); - }) - - it('should work with methods', () => { - class Foo { - @Sensitive - foo() { - - } - } - - expect(sensitive(Foo, 'foo')).toBe(true); - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Sensitive bar: string) { - - } - } - - expect(sensitive(Foo, 'foo', 0)).toBe(true); - }) -}) diff --git a/src/lib/functions/sensitive.ts b/src/lib/functions/sensitive.ts deleted file mode 100644 index 326c883..0000000 --- a/src/lib/functions/sensitive.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Sensitive - * - * ```ts - * const metadata = sensitive(MyClass); - * ``` - * - * @example - * ### Property Level Sensitive - * - * ```ts - * const metadata = sensitive(MyClass, 'password'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index 5685606..0000000 --- a/src/lib/functions/token.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Token } from '../decorators/token.decorator' -import { token } from './token'; - -describe('token', () => { - it('should return the token', () => { - @Token('foo') - class Foo { } - - expect(token(Foo)).toBe('foo') - }) - - it('should work with properties', () => { - class Foo { - @Token('foo') - foo!: string; - } - - expect(token(Foo, 'foo')).toBe('foo') - }) - - it('should work with methods', () => { - class Foo { - @Token('foo') - foo() { - - } - } - - expect(token(Foo, 'foo')).toBe('foo') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Token('bar') bar: string) { - - } - } - - expect(token(Foo, 'foo', 0)).toBe('bar') - }) -}) diff --git a/src/lib/functions/token.ts b/src/lib/functions/token.ts deleted file mode 100644 index 4cf83cd..0000000 --- a/src/lib/functions/token.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Token - * - * ```ts - * const metadata = token(MyClass); - * ``` - * - * @example - * ### Property Level Token - * - * ```ts - * const metadata = token(MyClass, 'title'); - * ``` - * - * @example - * ### 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 deleted file mode 100644 index eaae574..0000000 --- a/src/lib/functions/tokens.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { Token } from '../decorators/token.decorator' -import { tokens } from './tokens'; - -describe('tokens', () => { - it('should return the token', () => { - @Token('foo', 'foos') - class Foo { } - - expect(tokens(Foo)).toBe('foos') - }) - - it('should work with properties', () => { - class Foo { - @Token('foo', 'foos') - foo!: string; - } - - expect(tokens(Foo, 'foo')).toBe('foos') - }) - - it('should work with methods', () => { - class Foo { - @Token('foo', 'foos') - foo() { - - } - } - - expect(tokens(Foo, 'foo')).toBe('foos') - }) - - it('should work with parameters', () => { - class Foo { - - foo(@Token('Bar', 'Bars') bar: string) { - - } - } - - expect(tokens(Foo, 'foo', 0)).toBe('Bars') - }) -}) diff --git a/src/lib/functions/tokens.ts b/src/lib/functions/tokens.ts deleted file mode 100644 index 41c04a4..0000000 --- a/src/lib/functions/tokens.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Class } from '@agape/types'; -import { MetadataDescriptor } from '../descriptors/metadata.descriptor'; - -/** - * 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. - * - * @example - * ### Class Level Tokens - * - * ```ts - * const metadata = tokens(MyClass); - * ``` - * - * @example - * ### Property Level Tokens - * - * ```ts - * const metadata = tokens(MyClass, 'title'); - * ``` - * - * @example - * ### 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; -}