@unifig/core
Advanced tools
Comparing version 0.11.0 to 0.11.1-beta.1
export type ConfigSource = { | ||
[key: string]: ConfigSourceEntry; | ||
}; | ||
export type ConfigSourceEntry = string | number | boolean | ConfigSource | Array<ConfigSourceEntry>; | ||
export type ConfigSourceEntry = string | number | boolean | ConfigSource; | ||
export interface ConfigAdapter { | ||
@@ -6,0 +6,0 @@ /** |
import { ConfigSource } from '../adapters'; | ||
import { ClassConstructor } from '../utils/class-constructor.interface'; | ||
import { LoaderOptions } from './loader.options'; | ||
export interface Loader { | ||
load<TTemplate>(template: ClassConstructor<TTemplate>, source: ConfigSource, options: LoaderOptions): TTemplate; | ||
load<TTemplate>(template: ClassConstructor<TTemplate>, source: ConfigSource): TTemplate; | ||
} |
import { ClassConstructor } from '../utils/class-constructor.interface'; | ||
import { ConfigSource } from '../adapters/adapter'; | ||
import { LoaderOptions } from './loader.options'; | ||
import { Loader } from './loader'; | ||
export declare class ConfigLoader implements Loader { | ||
load<TTemplate>(template: ClassConstructor<TTemplate>, source: ConfigSource, options: LoaderOptions): TTemplate; | ||
load<TTemplate>(template: ClassConstructor<TTemplate>, source: ConfigSource): TTemplate; | ||
private formatObject; | ||
private getSourceValue; | ||
} |
@@ -8,9 +8,5 @@ "use strict"; | ||
class ConfigLoader { | ||
load(template, source, options) { | ||
var _a; | ||
load(template, source) { | ||
const plain = this.formatObject(template, (0, override_object_1.overrideObject)({}, source), source); | ||
return (class_transformer_1.plainToInstance !== null && class_transformer_1.plainToInstance !== void 0 ? class_transformer_1.plainToInstance : class_transformer_1.plainToClass)(template, plain, { | ||
enableImplicitConversion: (_a = options.enableImplicitConversion) !== null && _a !== void 0 ? _a : true, | ||
enableCircularCheck: true, | ||
}); | ||
return (class_transformer_1.plainToInstance !== null && class_transformer_1.plainToInstance !== void 0 ? class_transformer_1.plainToInstance : class_transformer_1.plainToClass)(template, plain, { enableImplicitConversion: true }); | ||
} | ||
@@ -28,4 +24,2 @@ formatObject(template, skeleton, source) { | ||
for (const [targetKey, subTemplate] of nesting) { | ||
if (Array.isArray(skeleton[targetKey])) | ||
continue; | ||
skeleton[targetKey] = (_a = skeleton[targetKey]) !== null && _a !== void 0 ? _a : {}; | ||
@@ -32,0 +26,0 @@ Object.assign(skeleton[targetKey], this.formatObject(subTemplate(), skeleton[targetKey], source)); |
@@ -13,3 +13,3 @@ import 'reflect-metadata'; | ||
constructor(_validator: Validator, _sourceGroupFactory: typeof sourceGroupFactory); | ||
register(...options: ConfigManagerRegisterOptions[]): Promise<import("..").ConfigValidationError | undefined>; | ||
register(...configs: ConfigManagerRegisterOptions[]): Promise<import("..").ConfigValidationError | undefined>; | ||
registerOrReject(...configs: ConfigManagerRegisterOptions[]): Promise<void>; | ||
@@ -16,0 +16,0 @@ private initSourceGroups; |
@@ -12,4 +12,4 @@ "use strict"; | ||
} | ||
async register(...options) { | ||
const groups = options.map((config) => this.initSourceGroups(config)); | ||
async register(...configs) { | ||
const groups = configs.map((config) => this.initSourceGroups(config)); | ||
const loadResults = await Promise.all(groups.map((group) => group.load(true))); | ||
@@ -29,9 +29,9 @@ const configsValues = [].concat(...loadResults); | ||
} | ||
initSourceGroups(options) { | ||
let templates = options.templates; | ||
initSourceGroups(config) { | ||
let templates = config.templates; | ||
if (!templates) | ||
templates = [options.template]; | ||
templates = [config.template]; | ||
const sourceGroup = this._sourceGroupFactory(); | ||
// Register only templates that were not registered already | ||
sourceGroup.init(options.adapter, templates.filter((template) => !this._groups.has(template)), options); | ||
sourceGroup.init(config.adapter, templates.filter((template) => !this._groups.has(template))); | ||
return sourceGroup; | ||
@@ -38,0 +38,0 @@ } |
import { ConfigAdapter } from '../adapters'; | ||
import { ClassConstructor } from '../utils/class-constructor.interface'; | ||
import { SourceGroupOptions } from './source-group/source-group.options'; | ||
export type ConfigManagerRegisterOptions = RegisterSingleTemplateOptions | RegisterMultipleTemplatesOptions; | ||
interface RegisterTemplatesOptions extends SourceGroupOptions { | ||
export interface RegisterSingleTemplateOptions { | ||
template: ClassConstructor; | ||
adapter: ConfigAdapter; | ||
} | ||
export interface RegisterSingleTemplateOptions extends RegisterTemplatesOptions { | ||
template: ClassConstructor; | ||
} | ||
export interface RegisterMultipleTemplatesOptions extends RegisterTemplatesOptions { | ||
export interface RegisterMultipleTemplatesOptions { | ||
templates: ClassConstructor[]; | ||
adapter: ConfigAdapter; | ||
} | ||
export {}; |
import { ConfigAdapter } from '../../adapters'; | ||
import { ClassConstructor } from '../../utils/class-constructor.interface'; | ||
import { EditableConfigContainer } from '../container/editable-container'; | ||
import { SourceGroupOptions } from './source-group.options'; | ||
export interface SourceGroup { | ||
readonly templates: ClassConstructor<any>[]; | ||
init(adapter: ConfigAdapter, templates: ClassConstructor[], options: SourceGroupOptions): void; | ||
init(adapter: ConfigAdapter, templates: ClassConstructor[]): void; | ||
getContainer(template: ClassConstructor): EditableConfigContainer<any> | undefined; | ||
load(skipValidation?: boolean): Promise<any[]>; | ||
} |
@@ -7,3 +7,2 @@ import { ConfigAdapter } from '../../adapters'; | ||
import { EditableConfigContainer } from '../container/editable-container'; | ||
import { SourceGroupOptions } from './source-group.options'; | ||
import { SourceGroup } from './source-group'; | ||
@@ -14,7 +13,6 @@ export declare class ConfigSourceGroup implements SourceGroup { | ||
private readonly _containerFactory; | ||
private _options; | ||
private _adapter; | ||
private readonly _containers; | ||
constructor(_loader: Loader, _validator: Validator, _containerFactory: typeof containerFactory); | ||
init(adapter: ConfigAdapter, templates: ClassConstructor[], options: SourceGroupOptions): void; | ||
init(adapter: ConfigAdapter, templates: ClassConstructor[]): void; | ||
get templates(): ClassConstructor<any>[]; | ||
@@ -21,0 +19,0 @@ getContainer(template: ClassConstructor): EditableConfigContainer<any> | undefined; |
@@ -11,4 +11,3 @@ "use strict"; | ||
} | ||
init(adapter, templates, options) { | ||
this._options = options; | ||
init(adapter, templates) { | ||
this._adapter = adapter; | ||
@@ -29,3 +28,3 @@ templates.forEach((template) => this._containers.set(template, this._containerFactory(this))); | ||
const source = await this._adapter.load(); | ||
const values = this.templates.map((template) => this._loader.load(template, source, this._options)); | ||
const values = this.templates.map((template) => this._loader.load(template, source)); | ||
if (!skipValidation) { | ||
@@ -32,0 +31,0 @@ const validationResult = this._validator.validate(values); |
@@ -1,7 +0,1 @@ | ||
/** | ||
* Deep Object.assign behavior. | ||
* @param {Record<string, any>} base | ||
* @param {Record<string, any>} data | ||
* @returns {Record<string, any>} | ||
*/ | ||
export declare const overrideObject: (base: Record<string, any>, data: Record<string, any>) => Record<string, any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.overrideObject = void 0; | ||
/** | ||
* Deep Object.assign behavior. | ||
* @param {Record<string, any>} base | ||
* @param {Record<string, any>} data | ||
* @returns {Record<string, any>} | ||
*/ | ||
const overrideObject = (base, data) => { | ||
@@ -11,0 +5,0 @@ var _a; |
{ | ||
"name": "@unifig/core", | ||
"version": "0.11.0", | ||
"version": "0.11.1-beta.1+770b119", | ||
"description": "Universal, typed and validated configuration manager", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "ea02008325b80eacd1f4a918ad5caa336cd3d567" | ||
"gitHead": "770b119e2331247ff2c746c62726d57f723d6a25" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48547
1