-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from medishen/dev/v2
refactor(metadata): overhaul metadata handling with improved scoping and type safety
- Loading branch information
Showing
7 changed files
with
684 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Metadata Key Prefix | ||
*/ | ||
export const PREFIX = 'meta'; | ||
/** | ||
* Metadata Separator | ||
*/ | ||
export const KEY_SEPARATOR = '::'; | ||
/** | ||
* Metadata Scope | ||
*/ | ||
export const MetadataScope = { | ||
CLASS: 'class', | ||
METHOD: 'method', | ||
PROPERTY: 'property', | ||
PARAMETER: 'param', | ||
FUNCTION: 'function', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { MetadataKey, MetadataTarget, MetadataValue } from '../types/metadata.types'; | ||
|
||
export interface MetadataStorage { | ||
get(target: MetadataTarget): Map<MetadataKey, MetadataValue>; | ||
set(target: MetadataTarget, key: MetadataKey, value: MetadataValue): void; | ||
get<K extends MetadataKey, V>(target: MetadataTarget): Map<MetadataKey<K>, MetadataValue<V>>; | ||
set<K extends MetadataKey, V>(target: MetadataTarget, key: MetadataKey<K>, value: MetadataValue<V>): void; | ||
has(target: MetadataTarget, key: MetadataKey): boolean; | ||
delete(target: MetadataTarget, key: MetadataKey): boolean; | ||
clear(target: MetadataTarget): void; | ||
keys(): string[]; | ||
list(target: MetadataTarget): Map<MetadataKey, MetadataValue> | null; | ||
allList(): Map<string, Map<MetadataKey, MetadataValue>>; | ||
} | ||
list<K extends MetadataKey, V>(target: MetadataTarget): Map<MetadataKey<K>, MetadataValue<V>> | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
export type MetadataKey = string | symbol; | ||
export type MetadataValue = unknown; | ||
import { MetadataScope } from '../constant'; | ||
export type MetadataKey<K = string | symbol> = K; | ||
export type MetadataValue<T extends unknown> = T; | ||
export type MetadataTarget = object | Function; | ||
export type MetadataPropertyKey = string | symbol; | ||
export type MetadataParameterIndex = number; | ||
export type Decorator = ClassDecorator & PropertyDecorator & MethodDecorator & ParameterDecorator; | ||
export type TargetType = 'class' | 'method' | 'function' | 'object' | 'unknown'; | ||
export type TargetIdentification = { type: TargetType; target: MetadataTarget }; | ||
export type MetadataScopeType = keyof typeof MetadataScope; |
Oops, something went wrong.