-
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.
- Loading branch information
1 parent
037ca36
commit 8f29e95
Showing
25 changed files
with
524 additions
and
43 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
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,20 @@ | ||
|
||
import type { FileManager } from '@jitar/sourcing'; | ||
|
||
const filename = 'jitar.js'; | ||
const code = `export default async (specifier) => import(specifier);`; | ||
|
||
export default class JitarBuilder | ||
{ | ||
#fileManager: FileManager; | ||
|
||
constructor(fileManager: FileManager) | ||
{ | ||
this.#fileManager = fileManager; | ||
} | ||
|
||
build(): Promise<void> | ||
{ | ||
return this.#fileManager.write(filename, code); | ||
} | ||
} |
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
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,35 +1,31 @@ | ||
|
||
import { type FileManager, FileManagerBuilder } from '@jitar/sourcing'; | ||
import { RuntimeConfiguration, RuntimeConfigurationBuilder } from './runtime'; | ||
import { ServerConfiguration, ServerConfigurationBuilder } from './server'; | ||
import { ConfigurationReader, ConfigurationValidator } from './utils'; | ||
|
||
import Configuration from './models/Configuration'; | ||
|
||
const DEFAULT_CONFIGURATION_FILENAME = 'jitar.json'; | ||
const DEFAULT_ROOT_PATH = './'; | ||
|
||
export default class ConfigurationManager | ||
{ | ||
#fileManager: FileManager; | ||
#runtimeConfigurationBuilder: RuntimeConfigurationBuilder; | ||
#serverConfigurationBuilder : ServerConfigurationBuilder; | ||
|
||
constructor() | ||
constructor(rootPath = DEFAULT_ROOT_PATH) | ||
{ | ||
this.#fileManager = new FileManagerBuilder('./').buildLocal(); | ||
} | ||
const reader = new ConfigurationReader(rootPath); | ||
const validator = new ConfigurationValidator(); | ||
|
||
async configure(filename = DEFAULT_CONFIGURATION_FILENAME): Promise<Configuration> | ||
{ | ||
return await this.#fileManager.exists(filename) | ||
? this.#configureFromFile(filename) | ||
: this.#configureDefault(); | ||
this.#runtimeConfigurationBuilder = new RuntimeConfigurationBuilder(reader, validator); | ||
this.#serverConfigurationBuilder = new ServerConfigurationBuilder(reader, validator); | ||
} | ||
|
||
async #configureFromFile(filename: string): Promise<Configuration> | ||
configureRuntime(filename?: string): Promise<RuntimeConfiguration> | ||
{ | ||
const file = this.#fileManager.read(filename); | ||
|
||
return new Configuration("source", "target"); | ||
return this.#runtimeConfigurationBuilder.build(filename); | ||
} | ||
|
||
#configureDefault(): Configuration | ||
configureServer(filename: string): Promise<ServerConfiguration> | ||
{ | ||
return new Configuration('./dist', './dist'); | ||
return this.#serverConfigurationBuilder.build(filename); | ||
} | ||
} |
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,3 +1,5 @@ | ||
|
||
export { default as Configuration } from './models/Configuration'; | ||
export { RuntimeConfiguration } from './runtime'; | ||
export { ServerConfiguration, StandaloneConfiguration, ProxyConfiguration, WorkerConfiguration, GatewayConfiguration, RepositoryConfiguration } from './server'; | ||
|
||
export { default as ConfigurationManager } from './ConfigurationManager'; |
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
packages/configuration/src/runtime/ConfigurationBuilder.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,33 @@ | ||
|
||
import type { ConfigurationReader, ConfigurationValidator } from '../utils'; | ||
|
||
import RuntimeConfiguration, { DefaultValues, validationScheme } from './definitions/RuntimeConfiguration'; | ||
import RuntimeConfigurationInvalid from './errors/RuntimeConfigurationInvalid'; | ||
|
||
export default class ConfigurationBuilder | ||
{ | ||
#reader: ConfigurationReader; | ||
#validator: ConfigurationValidator; | ||
|
||
constructor(reader: ConfigurationReader, validator: ConfigurationValidator) | ||
{ | ||
this.#reader = reader; | ||
this.#validator = validator; | ||
} | ||
|
||
async build(filename: string = DefaultValues.FILENAME): Promise<RuntimeConfiguration> | ||
{ | ||
const configuration = await this.#reader.read(filename) as RuntimeConfiguration; | ||
const validation = this.#validator.validate(configuration, validationScheme); | ||
|
||
if (validation.valid === false) | ||
{ | ||
throw new RuntimeConfigurationInvalid(validation); | ||
} | ||
|
||
configuration.source ??= DefaultValues.SOURCE; | ||
configuration.target ??= DefaultValues.TARGET; | ||
|
||
return configuration; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/configuration/src/runtime/definitions/RuntimeConfiguration.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,25 @@ | ||
|
||
import { ValidationScheme } from '../../utils'; | ||
|
||
type RuntimeConfiguration = | ||
{ | ||
source: string; | ||
target: string; | ||
}; | ||
|
||
export default RuntimeConfiguration; | ||
|
||
const DefaultValues = | ||
{ | ||
FILENAME: './jitar.json', | ||
SOURCE: './src', | ||
TARGET: './dist' | ||
} as const; | ||
|
||
const validationScheme: ValidationScheme = | ||
{ | ||
source: { type: 'string', required: false }, | ||
target: { type: 'string', required: false } | ||
} as const; | ||
|
||
export { DefaultValues, validationScheme }; |
10 changes: 10 additions & 0 deletions
10
packages/configuration/src/runtime/errors/RuntimeConfigurationInvalid.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 { ValidationResult } from '../../utils'; | ||
|
||
export default class RuntimeConfigurationInvalid extends Error | ||
{ | ||
public constructor(validation: ValidationResult) | ||
{ | ||
super(validation.errors.join('\n')); | ||
} | ||
} |
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,3 @@ | ||
|
||
export { default as RuntimeConfiguration } from './definitions/RuntimeConfiguration'; | ||
export { default as RuntimeConfigurationBuilder } from './ConfigurationBuilder'; |
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,30 @@ | ||
|
||
import type { ConfigurationReader, ConfigurationValidator } from '../utils'; | ||
|
||
import ServerConfiguration, { validationScheme } from './definitions/ServerConfiguration'; | ||
import ServerConfigurationInvalid from './errors/ServerConfigurationInvalid'; | ||
|
||
export default class ConfigurationBuilder | ||
{ | ||
#reader: ConfigurationReader; | ||
#validator: ConfigurationValidator; | ||
|
||
constructor(reader: ConfigurationReader, validator: ConfigurationValidator) | ||
{ | ||
this.#reader = reader; | ||
this.#validator = validator; | ||
} | ||
|
||
async build(filename: string): Promise<ServerConfiguration> | ||
{ | ||
const configuration = await this.#reader.read(filename) as ServerConfiguration; | ||
const validation = this.#validator.validate(configuration, validationScheme); | ||
|
||
if (validation.valid === false) | ||
{ | ||
throw new ServerConfigurationInvalid(validation); | ||
} | ||
|
||
return configuration; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/configuration/src/server/definitions/GatewayConfiguration.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,22 @@ | ||
|
||
import { ValidationScheme } from '../../utils'; | ||
|
||
type GatewayConfiguration = | ||
{ | ||
monitor: number; | ||
middleware: string[]; | ||
healthChecks: string[]; | ||
trustKey?: string; | ||
}; | ||
|
||
export default GatewayConfiguration; | ||
|
||
const validationScheme: ValidationScheme = | ||
{ | ||
monitor: { type: 'integer', required: false }, | ||
middleware: { type: 'list', required: false, items: { type: 'string' } }, | ||
healthChecks: { type: 'list', required: false, items: { type: 'string' } }, | ||
trustKey: { type: 'string', required: false } | ||
} as const; | ||
|
||
export { validationScheme }; |
20 changes: 20 additions & 0 deletions
20
packages/configuration/src/server/definitions/ProxyConfiguration.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,20 @@ | ||
|
||
import { ValidationScheme } from '../../utils'; | ||
|
||
type ProxyConfiguration = | ||
{ | ||
gateway: string; | ||
repository: string; | ||
middleware: string[]; | ||
}; | ||
|
||
export default ProxyConfiguration; | ||
|
||
const validationScheme: ValidationScheme = | ||
{ | ||
gateway: { type: 'url', required: true }, | ||
repository: { type: 'url', required: true }, | ||
middleware: { type: 'list', required: false, items: { type: 'string' } } | ||
} as const; | ||
|
||
export { validationScheme }; |
20 changes: 20 additions & 0 deletions
20
packages/configuration/src/server/definitions/RepositoryConfiguration.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,20 @@ | ||
|
||
import { ValidationScheme } from '../../utils'; | ||
|
||
type RepositoryConfiguration = | ||
{ | ||
index: string; | ||
serveIndexOnNotFound: boolean; | ||
assets: string[]; | ||
}; | ||
|
||
export default RepositoryConfiguration; | ||
|
||
const validationScheme: ValidationScheme = | ||
{ | ||
index: { type: 'string', required: false }, | ||
serveIndexOnNotFound: { type: 'boolean', required: false }, | ||
assets: { type: 'list', required: false, items: { type: 'string' } } | ||
} as const; | ||
|
||
export { validationScheme }; |
38 changes: 38 additions & 0 deletions
38
packages/configuration/src/server/definitions/ServerConfiguration.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,38 @@ | ||
|
||
import { ValidationScheme } from '../../utils'; | ||
|
||
import GatewayConfiguration, { validationScheme as gatewayValidationScheme } from './GatewayConfiguration'; | ||
import ProxyConfiguration, { validationScheme as proxyValidationScheme } from './ProxyConfiguration'; | ||
import RepositoryConfiguration, { validationScheme as repositoryValidationScheme } from './RepositoryConfiguration'; | ||
import StandaloneConfiguration, { validationScheme as standaloneValidationScheme } from './StandaloneConfiguration'; | ||
import WorkerConfiguration, { validationScheme as workerValidationScheme } from './WorkerConfiguration'; | ||
|
||
type ServerConfiguration = | ||
{ | ||
url: string; | ||
setup?: string[]; | ||
teardown?: string[]; | ||
|
||
gateway?: GatewayConfiguration; | ||
proxy?: ProxyConfiguration; | ||
repository?: RepositoryConfiguration; | ||
standalone?: StandaloneConfiguration; | ||
worker?: WorkerConfiguration; | ||
}; | ||
|
||
export default ServerConfiguration; | ||
|
||
const validationScheme: ValidationScheme = | ||
{ | ||
url: { type: 'url', required: true }, | ||
setup: { type: 'list', required: false, items: { type: 'string' } }, | ||
teardown: { type: 'list', required: false, items: { type: 'string' } }, | ||
|
||
gateway: { type: 'group', required: false, fields: gatewayValidationScheme }, | ||
proxy: { type: 'group', required: false, fields: proxyValidationScheme }, | ||
repository: { type: 'group', required: false, fields: repositoryValidationScheme }, | ||
standalone: { type: 'group', required: false, fields: standaloneValidationScheme }, | ||
worker: { type: 'group', required: false, fields: workerValidationScheme } | ||
} as const; | ||
|
||
export { validationScheme }; |
Oops, something went wrong.