Skip to content

Commit

Permalink
Refactor configuration, use new "Items" type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Oct 3, 2024
1 parent d324c2e commit 241f920
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
21 changes: 12 additions & 9 deletions packages/config/src/Repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Repository as RepositoryContract } from "@aedart/contracts/config";
import type {
Repository as RepositoryContract,
Items
} from "@aedart/contracts/config";
import type { Key } from "@aedart/contracts/support";
import {
set,
Expand All @@ -18,18 +21,18 @@ export default class Repository implements RepositoryContract
/**
* The configuration items
*
* @type {Record<PropertyKey, any>}
* @type {Items}
*
* @protected
*/
protected items: Record<PropertyKey, any>; /* eslint-disable-line @typescript-eslint/no-explicit-any */
protected items: Items;

/**
* Create a new Configuration Repository instance
*
* @param {Record<PropertyKey, any>} [items]
* @param {Items} [items]
*/
public constructor(items: Record<PropertyKey, any> = {}) /* eslint-disable-line @typescript-eslint/no-explicit-any */
public constructor(items: Items = {})
{
this.items = shallowMerge(items);
}
Expand Down Expand Up @@ -136,11 +139,11 @@ export default class Repository implements RepositoryContract
*
* **Caution**: _Merging is performed via [shallow coping](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) of items._
*
* @param {Record<PropertyKey, any>} items
* @param {Items} items
*
* @return {this}
*/
public merge(items: Record<PropertyKey, any>): this /* eslint-disable-line @typescript-eslint/no-explicit-any */
public merge(items: Items): this
{
this.items = shallowMerge(this.items, items);

Expand All @@ -150,9 +153,9 @@ export default class Repository implements RepositoryContract
/**
* Get all configuration items
*
* @return {Record<PropertyKey, any>}
* @return {Items}
*/
public all(): Record<PropertyKey, any> /* eslint-disable-line @typescript-eslint/no-explicit-any */
public all(): Items
{
return this.items;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts/src/config/Repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Key } from "@aedart/contracts/support";
import { Items } from './types';

/**
* Configuration Repository
Expand Down Expand Up @@ -75,16 +76,16 @@ export default interface Repository
*
* **Caution**: _Merging is performed via [shallow coping](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) of items._
*
* @param {Record<PropertyKey, any>} items
* @param {Items} items
*
* @return {this}
*/
merge(items: Record<PropertyKey, any>): this; /* eslint-disable-line @typescript-eslint/no-explicit-any */
merge(items: Items): this;

/**
* Get all configuration items
*
* @return {Record<PropertyKey, any>}
* @return {Items}
*/
all(): Record<PropertyKey, any>; /* eslint-disable-line @typescript-eslint/no-explicit-any */
all(): Items;
}
4 changes: 3 additions & 1 deletion packages/contracts/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export const CONFIG: unique symbol = Symbol('@aedart/contracts/config');
import Repository from './Repository';
export {
type Repository
}
}

export type * from './types';
7 changes: 7 additions & 0 deletions packages/contracts/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Configuration Items
*
* A general type for describing a key-value store containing configuration items
* for an application or component.
*/
export type Items = Record<PropertyKey, any>; /* eslint-disable-line @typescript-eslint/no-explicit-any */
5 changes: 3 additions & 2 deletions packages/contracts/src/core/configuration/Configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IdentifierAliasTuple,
IdentifierInstanceTuple,
} from "@aedart/contracts/container";
import { Items } from "@aedart/contracts/config";
import BootstrapperConstructor from "../BootstrapperConstructor";
import Application from '../Application';

Expand All @@ -32,11 +33,11 @@ export default interface Configurator
*
* @see {import('@aedart/contracts/config').Repository}
*
* @param {Record<PropertyKey, any>} items
* @param {Items} items
*
* @return {this}
*/
with(items: Record<PropertyKey, any>): this; /* eslint-disable-line @typescript-eslint/no-explicit-any */
with(items: Items): this;

/**
* Add "core" bindings to be registered
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/configuration/BaseConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
IdentifierAliasTuple,
IdentifierInstanceTuple
} from "@aedart/contracts/container";
import type { Repository } from "@aedart/contracts/config";
import type { Repository, Items } from "@aedart/contracts/config";
import { CONFIG } from "@aedart/contracts/config";
import { AbstractClassError } from "@aedart/support/exceptions";
import { isset } from "@aedart/support/misc";
Expand Down Expand Up @@ -40,11 +40,11 @@ export default abstract class BaseConfigurator implements Configurator {
/**
* Configuration items for the application
*
* @type {Record<PropertyKey, any>}
* @type {Items}
*
* @protected
*/
protected configurationItems: Record<PropertyKey, any> = {};
protected configurationItems: Items = {};

/**
* List of bindings to be registered
Expand Down Expand Up @@ -135,11 +135,11 @@ export default abstract class BaseConfigurator implements Configurator {
*
* @see {import('@aedart/contracts/config').Repository}
*
* @param {Record<PropertyKey, any>} items
* @param {Items} items
*
* @return {this}
*/
public with(items: Record<PropertyKey, any>): this /* eslint-disable-line @typescript-eslint/no-explicit-any */
public with(items: Items): this
{
this.configurationItems = shallowMerge(this.configurationItems, items);

Expand Down

0 comments on commit 241f920

Please sign in to comment.