Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign meta #7

Merged
merged 36 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2fac706
Remove deprecated components
aedart Mar 6, 2024
7fa9ce1
Change release notes
aedart Mar 6, 2024
2354d9c
Add general meta exception interface
aedart Mar 6, 2024
3e3fa8d
Add meta repository interface
aedart Mar 6, 2024
9e4773b
Fix style
aedart Mar 6, 2024
a2c4a0b
Add Meta Error
aedart Mar 6, 2024
92f09db
Change return type of set method
aedart Mar 6, 2024
2d96a9b
Change set, adapt to fit decorator usage
aedart Mar 6, 2024
c572a7b
Add InitializerCallback type alias
aedart Mar 6, 2024
296d655
Change set, remove exception thrown
aedart Mar 6, 2024
46634db
Add decorator types
aedart Mar 6, 2024
78bc536
Add decorator result types
aedart Mar 6, 2024
4556c4e
Extract decorator types into own file
aedart Mar 6, 2024
e2bce8a
Fix style
aedart Mar 6, 2024
f601595
Change return type of set to DecoratorResult
aedart Mar 6, 2024
db51ed5
Add context as part of target context
aedart Mar 6, 2024
34775c0
Refactor meta(), extract logic into Meta Repository
aedart Mar 6, 2024
51e8a09
Add hasMeta util function
aedart Mar 6, 2024
e2c36a1
Change release notes
aedart Mar 6, 2024
738be6b
Fix return type (JSDoc)
aedart Mar 6, 2024
529585e
Fix missing return type for has() - JSDoc
aedart Mar 6, 2024
0bf3a9b
Add Target Repository interface
aedart Mar 6, 2024
1b7cbb6
Improve property descriptions
aedart Mar 7, 2024
4adf770
Fix import
aedart Mar 7, 2024
b94a034
Add Meta Target Context
aedart Mar 7, 2024
1cbd15e
Refactor, use new target context
aedart Mar 7, 2024
755d986
Cleanup
aedart Mar 7, 2024
e4aba0c
Add Meta Entry class
aedart Mar 7, 2024
4e15dc2
Refactor, use new Meta Entry
aedart Mar 7, 2024
d37d020
Fix JSDoc
aedart Mar 7, 2024
2dcf043
Add inherit method
aedart Mar 7, 2024
87efda1
Change Entry, add static make method and resolve with prefix
aedart Mar 7, 2024
d81021b
Change Target Context, add static make method
aedart Mar 7, 2024
7da7454
Improve description / note, for inherit()
aedart Mar 7, 2024
23fba68
Refactor/Redesign targetMeta utils
aedart Mar 7, 2024
848a399
Change release notes
aedart Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* `hasMeta()` util, in `@aedart/support/meta`.
* `MetaRepository`, `TargetMetaRepository`, `TargetContext`, `Entry`, and `hasTargetMeta()` in `@aedart/support/meta`.
* `ClassDecorator`, `ClassMethodDecorator`, `ClassGetterDecorator`, `ClassSetterDecorator`, `ClassFieldDecorator`, `ClassAutoAccessorDecorator`, and `Decorator` types, in `@aedart/contracts`.
* `ClassDecoratorResult`, `ClassMethodDecoratorResult`, `ClassGetterDecoratorResult`, `ClassSetterDecoratorResult`, `ClassFieldDecoratorResult`, `ClassAutoAccessorDecoratorResult`, and `DecoratorResult` types, in `@aedart/contracts`.

### Changed

**Breaking**

* `targetMeta()` and `inheritTargetMeta()` now throw `MetaError` (_`TypeError` was previously thrown_), in `@aedart/support/meta`.

**Non-breaking Changes**

* Refactored / Redesigned `meta()`, `getMeta()`, and `getAllMeta()` to use new `MetaRepository` as its underlying core component for dealing with metadata.
* Refactored / Redesigned `targetMeta()`, `getTargetMeta()`, and `inheritTargetMeta()` to use new `TargetMetaRepository` underneath.
* Return type of `meta()` changed to `Decorator`.
* `MetaTargetContext` expanded with a `context: Context` property. `@aedart/contracts/support/meta`.

### Fixed

* Broken links in support/exceptions and in support/objects docs.

### Removed

* `ClassContext`, `MethodContext`, `GetterContext`, `SetterContext`, `FieldContext`, `AccessorContext` and `MetadataContext`, in `@aedart/contracts/support/meta` (_components were deprecated in `v0.7.0`_).
* `MemberContext` type in `@aedart/contracts/support/meta` (_type was deprecated in `v0.7.0`_).

## [0.9.0] - 2024-03-05

### Added
Expand Down
93 changes: 93 additions & 0 deletions packages/contracts/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Class Decorator Result
*/
export type ClassDecoratorResult = object | void;

/**
* Class Method Decorator Result
*/
export type ClassMethodDecoratorResult = object | void;

/**
* Class Getter Decorator Result
*/
export type ClassGetterDecoratorResult = object | void;

/**
* Class Setter Decorator Result
*/
export type ClassSetterDecoratorResult = object | void;

/**
* Class Field Decorator Result
*/
export type ClassFieldDecoratorResult = (initialValue: unknown) => unknown | void;

/**
* Class Auto-Accessor Decorator Result
*/
export type ClassAutoAccessorDecoratorResult = ClassAccessorDecoratorResult<object, unknown> | void

/**
* Decorator Result
*/
export type DecoratorResult = ClassDecoratorResult
| ClassMethodDecoratorResult
| ClassGetterDecoratorResult
| ClassSetterDecoratorResult
| ClassFieldDecoratorResult
| ClassAutoAccessorDecoratorResult;

/**
* Class Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassDecorator = (target: object, context: ClassDecoratorContext) => ClassDecoratorResult;

/**
* Class Method Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassMethodDecorator = (target: object, context: ClassMethodDecoratorContext) => ClassMethodDecoratorResult;

/**
* Class Getter Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassGetterDecorator = (target: object, context: ClassGetterDecoratorContext) => ClassGetterDecoratorResult;

/**
* Class Setter Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassSetterDecorator = (target: object, context: ClassSetterDecoratorContext) => ClassSetterDecoratorResult;

/**
* Class Field Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassFieldDecorator = (target: object, context: ClassFieldDecoratorContext) => ClassFieldDecoratorResult;

/**
* Class Auto-Accessor Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type ClassAutoAccessorDecorator = (target: ClassAccessorDecoratorTarget<object, unknown>, context: ClassAccessorDecoratorContext) => ClassAutoAccessorDecoratorResult;

/**
* Decorator
*
* @see https://github.com/tc39/proposal-decorators
*/
export type Decorator = ClassDecorator
| ClassMethodDecorator
| ClassGetterDecorator
| ClassSetterDecorator
| ClassFieldDecorator
| ClassAutoAccessorDecorator;
9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/AccessorContext.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/ClassContext.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/FieldContext.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/GetterContext.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/contracts/src/support/meta/MetaEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export default interface MetaEntry
*
* @type {Key}
*/
key: Key,
key: Key;

/**
* Value to store
*
* @type {unknown}
*/
value: unknown
value: unknown;
}
21 changes: 18 additions & 3 deletions packages/contracts/src/support/meta/MetaTargetContext.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import { Context } from './types';

/**
* Meta Decorator Target Context
*/
export default interface MetaTargetContext
{
/**
* The class that owns the meta
*
* @type {object}
*/
owner: object,
owner: object;

/**
* "This" argument
*
* @type {any}
*/
thisArg: any, /* eslint-disable-line @typescript-eslint/no-explicit-any */
thisArg: any; /* eslint-disable-line @typescript-eslint/no-explicit-any */

/**
* The target class, field, method... that is being decorated
*
* @type {object}
*/
target: object;

/**
* Decorator context
*
* @type {Context}
*/
target: object,
context: Context;
}
16 changes: 0 additions & 16 deletions packages/contracts/src/support/meta/MetadataContext.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/MethodContext.ts

This file was deleted.

67 changes: 67 additions & 0 deletions packages/contracts/src/support/meta/Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { DecoratorResult } from "@aedart/contracts";
import { Key } from "@aedart/contracts/support";
import { Context, MetaCallback, MetadataRecord } from "./types";

/**
* Meta Repository
*/
export default interface Repository
{
/**
* The owner class
*
* @type {object}
*/
readonly owner: object;

/**
* Set value for given key
*
* **Caution**: _Method is intended to be invoked inside a decorator!_
*
* @param {object} target Decorator target, e.g. class, field, method...etc
* @param {Context} context
* @param {Key | MetaCallback} key
* @param {any} [value] Value to be stored. Ignored if `key` argument is a callback.
*
* @return {DecoratorResult}
*/
set(
target: object,
context: Context,
key: Key | MetaCallback,
value?: any /* eslint-disable-line @typescript-eslint/no-explicit-any */
): DecoratorResult;

/**
* Get value for given key
*
* @template T Return value type
* @template D=any Type of default value
*
* @param {Key} key
* @param {D} [defaultValue]
*
* @return {T | D | undefined}
*/
get<
T,
D = any /* eslint-disable-line @typescript-eslint/no-explicit-any */
>(key: Key, defaultValue?: D): T | D | undefined;

/**
* Determine if value exists for key
*
* @param {Key} key
*
* @return {boolean}
*/
has(key: Key): boolean;

/**
* Get all metadata
*
* @return {MetadataRecord}
*/
all(): MetadataRecord;
}
9 changes: 0 additions & 9 deletions packages/contracts/src/support/meta/SetterContext.ts

This file was deleted.

Loading
Loading