-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'redesign-config-loading' into add-core
- Loading branch information
Showing
34 changed files
with
2,092 additions
and
994 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,23 @@ | ||
import type { ResolveException } from "@aedart/contracts/config"; | ||
import { configureCustomError } from "@aedart/support/exceptions"; | ||
|
||
/** | ||
* Configuration Resolve Error | ||
* | ||
* @see {ResolveException} | ||
*/ | ||
export default class ResolveError extends Error implements ResolveException | ||
{ | ||
/** | ||
* Create new Resolve Error instance | ||
* | ||
* @param {string} [message] | ||
* @param {ErrorOptions} [options] | ||
*/ | ||
constructor(message?: string, options?: ErrorOptions) | ||
{ | ||
super(message, options); | ||
|
||
configureCustomError(this); | ||
} | ||
} |
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,24 @@ | ||
import type { UnsupportedSourceException } from "@aedart/contracts/config"; | ||
import { configureCustomError } from "@aedart/support/exceptions"; | ||
import ResolveError from "./ResolveError"; | ||
|
||
/** | ||
* Unsupported Configuration Source Error | ||
* | ||
* @see {UnsupportedSourceException} | ||
*/ | ||
export default class UnsupportedSourceError extends ResolveError implements UnsupportedSourceException | ||
{ | ||
/** | ||
* Create new Unsupported Source Error instance | ||
* | ||
* @param {string} [message] | ||
* @param {ErrorOptions} [options] | ||
*/ | ||
constructor(message?: string, options?: ErrorOptions) | ||
{ | ||
super(message, options); | ||
|
||
configureCustomError(this); | ||
} | ||
} |
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,6 @@ | ||
import ResolveError from './ResolveError'; | ||
import UnsupportedSourceError from "./UnsupportedSourceError"; | ||
export { | ||
ResolveError, | ||
UnsupportedSourceError | ||
} |
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
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,60 @@ | ||
import type { Items, Resolver, Source, ResolveCallback } from "@aedart/contracts/config"; | ||
import { isPromise, isCallable } from "@aedart/support/reflections"; | ||
import { getErrorMessage } from "@aedart/support/exceptions"; | ||
import ResolveError from "../exceptions/ResolveError"; | ||
import UnsupportedSourceError from "../exceptions/UnsupportedSourceError"; | ||
|
||
/** | ||
* Default Configuration Resolver | ||
* | ||
* @see {Resolver} | ||
*/ | ||
export default class DefaultResolver implements Resolver | ||
{ | ||
/** | ||
* Resolves configuration items from the given source | ||
* | ||
* @param {Source} source | ||
* | ||
* @returns {Promise<Items>} | ||
* | ||
* @throws {ResolveException} | ||
*/ | ||
public async resolve(source: Source): Promise<Items> | ||
{ | ||
if (isPromise(source)) { | ||
return this.resolveItems(source as Promise<Items>); | ||
} | ||
|
||
if (typeof source === 'object') { | ||
return this.resolveItems(new Promise<Items>((resolve) => { | ||
resolve(source as Items); | ||
})); | ||
} | ||
|
||
if (isCallable(source)) { | ||
return this.resolveItems((source as ResolveCallback)()); | ||
} | ||
|
||
throw new UnsupportedSourceError('Unable to resolve configuration items from source', { cause: { source: source } }); | ||
} | ||
|
||
/** | ||
* Resolves configuration items from the given promise | ||
* | ||
* @param {Promise<Items>} promise | ||
* | ||
* @returns {Promise<Items>} | ||
* | ||
* @protected | ||
*/ | ||
protected async resolveItems(promise: Promise<Items>): Promise<Items> | ||
{ | ||
try { | ||
return await promise; | ||
} catch (e) { | ||
const reason: string = getErrorMessage(e); | ||
throw new ResolveError(`Unable to resolve configuration items: ${reason}`, { cause: { source: promise } }); | ||
} | ||
} | ||
} |
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,4 @@ | ||
import DefaultResolver from "./DefaultResolver"; | ||
export { | ||
DefaultResolver | ||
} |
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 @@ | ||
import { Items, Source } from './types'; | ||
|
||
/** | ||
* Configuration Resolver | ||
*/ | ||
export default interface Resolver | ||
{ | ||
/** | ||
* Resolves configuration items from the given source | ||
* | ||
* @param {Source} source | ||
* | ||
* @returns {Promise<Items>} | ||
* | ||
* @throws {ResolveException} | ||
*/ | ||
resolve(source: Source): Promise<Items>; | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/contracts/src/config/exceptions/ResolveException.ts
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,10 @@ | ||
import { Throwable } from "@aedart/contracts/support/exceptions"; | ||
|
||
/** | ||
* Configuration Resolve Exception | ||
* | ||
* To be thrown whenever configuration [items]{@link import('@aedart/contracts/config').Items} | ||
* cannot be resolved. | ||
*/ | ||
export default interface ResolveException extends Throwable | ||
{} |
10 changes: 10 additions & 0 deletions
10
packages/contracts/src/config/exceptions/UnsupportedSourceException.ts
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,10 @@ | ||
import ResolveException from './ResolveException'; | ||
|
||
/** | ||
* Unsupported Configuration Source Exception | ||
* | ||
* To be thrown whenever a [Resolver]{@link import('@aedart/contracts/config').Resolver} is unable to | ||
* resolve configuration items, due to an unsupported [source]{@link import('@aedart/contracts/config').Source}. | ||
*/ | ||
export default interface UnsupportedSourceException extends ResolveException | ||
{} |
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,6 @@ | ||
import ResolveException from "./ResolveException"; | ||
import UnsupportedSourceException from "./UnsupportedSourceException"; | ||
export { | ||
type ResolveException, | ||
type UnsupportedSourceException | ||
} |
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,7 +1,14 @@ | ||
/** | ||
* Configuration Items | ||
* | ||
* A general type for describing a key-value store containing configuration items | ||
* for an application or component. | ||
* A key-value store containing configuration items for an application, its service, and or component. | ||
*/ | ||
export type Items = Record<PropertyKey, any>; /* eslint-disable-line @typescript-eslint/no-explicit-any */ | ||
export type Items = Record<PropertyKey, any>; /* eslint-disable-line @typescript-eslint/no-explicit-any */ | ||
|
||
/** | ||
* Callback that is responsible for resolving configuration {@link Items}. | ||
*/ | ||
export type ResolveCallback = () => Promise<Items>; | ||
|
||
/** | ||
* A source that ultimately must resolve into configuration {@link Items}. | ||
*/ | ||
export type Source = Items | Promise<Items> | ResolveCallback; |
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
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
Oops, something went wrong.