@fgv/ts-res 5.0.0-28 → 5.0.0-29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ts-res.d.ts
CHANGED
|
@@ -1828,12 +1828,18 @@ declare namespace Config {
|
|
|
1828
1828
|
export {
|
|
1829
1829
|
Model,
|
|
1830
1830
|
Convert_9 as Convert,
|
|
1831
|
+
createQualifierTypeFactory,
|
|
1832
|
+
createResourceTypeFactory,
|
|
1833
|
+
QualifierTypeFactoryFunction,
|
|
1834
|
+
ResourceTypeFactoryFunction,
|
|
1831
1835
|
IConfigInitFactory,
|
|
1832
1836
|
ChainedConfigInitFactory,
|
|
1833
1837
|
BuiltInQualifierTypeFactory,
|
|
1834
1838
|
QualifierTypeFactory,
|
|
1839
|
+
ValidatingQualifierTypeFactory,
|
|
1835
1840
|
BuiltInResourceTypeFactory,
|
|
1836
1841
|
ResourceTypeFactory,
|
|
1842
|
+
ValidatingResourceTypeFactory,
|
|
1837
1843
|
updateSystemConfigurationQualifierDefaultValues,
|
|
1838
1844
|
ISystemConfigurationInitParams,
|
|
1839
1845
|
SystemConfiguration,
|
|
@@ -2349,6 +2355,14 @@ declare namespace Convert_9 {
|
|
|
2349
2355
|
}
|
|
2350
2356
|
}
|
|
2351
2357
|
|
|
2358
|
+
/**
|
|
2359
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a factory function.
|
|
2360
|
+
* @param fn - The factory function to wrap.
|
|
2361
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
2362
|
+
* @public
|
|
2363
|
+
*/
|
|
2364
|
+
declare function createQualifierTypeFactory<T extends QualifierType = QualifierType>(fn: QualifierTypeFactoryFunction<T>): IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T>;
|
|
2365
|
+
|
|
2352
2366
|
/**
|
|
2353
2367
|
* Creates a {@link QualifierTypes.QualifierType | QualifierType} from a configuration object.
|
|
2354
2368
|
* This factory function determines the appropriate qualifier type based on the systemType
|
|
@@ -2373,6 +2387,14 @@ declare function createQualifierTypeFromConfig(typeConfig: Config_2.IAnyQualifie
|
|
|
2373
2387
|
*/
|
|
2374
2388
|
declare function createQualifierTypeFromSystemConfig(typeConfig: Config_2.ISystemQualifierTypeConfig): Result<SystemQualifierType>;
|
|
2375
2389
|
|
|
2390
|
+
/**
|
|
2391
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a resource type factory function.
|
|
2392
|
+
* @param fn - The factory function to wrap.
|
|
2393
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
2394
|
+
* @public
|
|
2395
|
+
*/
|
|
2396
|
+
declare function createResourceTypeFactory(fn: ResourceTypeFactoryFunction): IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>;
|
|
2397
|
+
|
|
2376
2398
|
/**
|
|
2377
2399
|
* Creates a {@link ResourceTypes.ResourceType | ResourceType} from a configuration object.
|
|
2378
2400
|
* @param config - The {@link ResourceTypes.Config.IResourceTypeConfig | configuration object}
|
|
@@ -7521,14 +7543,23 @@ declare function qualifierTypeConfig<T, TD = unknown>(config: Converter<T, TD>):
|
|
|
7521
7543
|
declare class QualifierTypeFactory<T extends QualifierType = SystemQualifierType> extends ChainedConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T | SystemQualifierType> {
|
|
7522
7544
|
/**
|
|
7523
7545
|
* Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.
|
|
7524
|
-
* @param factories - Array of
|
|
7546
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
7547
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
7548
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
7549
|
+
* - A mix of both
|
|
7525
7550
|
* These are tried in order before falling back to built-in types.
|
|
7526
7551
|
* @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always appended to handle
|
|
7527
7552
|
* system qualifier types (Language, Territory, Literal).
|
|
7528
7553
|
*/
|
|
7529
|
-
constructor(factories: IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T>
|
|
7554
|
+
constructor(factories: Array<IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>>);
|
|
7530
7555
|
}
|
|
7531
7556
|
|
|
7557
|
+
/**
|
|
7558
|
+
* Function signature for creating a qualifier type from configuration.
|
|
7559
|
+
* @public
|
|
7560
|
+
*/
|
|
7561
|
+
declare type QualifierTypeFactoryFunction<T extends QualifierType = QualifierType> = (config: QualifierTypes.Config.IAnyQualifierTypeConfig) => Result<T>;
|
|
7562
|
+
|
|
7532
7563
|
/**
|
|
7533
7564
|
* Branded number representing a validated qualifier type index.
|
|
7534
7565
|
* @public
|
|
@@ -9257,12 +9288,21 @@ declare const resourceTypeConfig: ObjectConverter<IResourceTypeConfig<JsonObject
|
|
|
9257
9288
|
declare class ResourceTypeFactory extends ChainedConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> {
|
|
9258
9289
|
/**
|
|
9259
9290
|
* Constructor for a resource type factory.
|
|
9260
|
-
* @param factories -
|
|
9291
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
9292
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
9293
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
9294
|
+
* - A mix of both
|
|
9261
9295
|
* @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.
|
|
9262
9296
|
*/
|
|
9263
|
-
constructor(factories: IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>
|
|
9297
|
+
constructor(factories: Array<IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction>);
|
|
9264
9298
|
}
|
|
9265
9299
|
|
|
9300
|
+
/**
|
|
9301
|
+
* Function signature for creating a resource type from configuration.
|
|
9302
|
+
* @public
|
|
9303
|
+
*/
|
|
9304
|
+
declare type ResourceTypeFactoryFunction = (config: ResourceTypes.Config.IResourceTypeConfig) => Result<ResourceType>;
|
|
9305
|
+
|
|
9266
9306
|
/**
|
|
9267
9307
|
* Branded number representing a validated resource type index.
|
|
9268
9308
|
* @public
|
|
@@ -10100,6 +10140,77 @@ declare function validateSystemConfiguration(config: unknown): Result<ISystemCon
|
|
|
10100
10140
|
*/
|
|
10101
10141
|
declare function validateZipArchiveManifest(manifest: unknown): Result<Json_2.IZipArchiveManifest>;
|
|
10102
10142
|
|
|
10143
|
+
/**
|
|
10144
|
+
* A factory that validates and creates {@link QualifierTypes.QualifierType | QualifierType} instances
|
|
10145
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
10146
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
10147
|
+
*
|
|
10148
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
10149
|
+
* branded types across different package instances.
|
|
10150
|
+
*
|
|
10151
|
+
* @example
|
|
10152
|
+
* ```typescript
|
|
10153
|
+
* // Accept weakly-typed config from external source
|
|
10154
|
+
* const validatingFactory = new ValidatingQualifierTypeFactory([customFactory]);
|
|
10155
|
+
*
|
|
10156
|
+
* // Config can have plain string types instead of branded types
|
|
10157
|
+
* const config = {
|
|
10158
|
+
* name: 'my-qualifier', // plain string, not QualifierTypeName
|
|
10159
|
+
* systemType: 'custom', // plain string
|
|
10160
|
+
* configuration: { ... }
|
|
10161
|
+
* };
|
|
10162
|
+
*
|
|
10163
|
+
* const result = validatingFactory.create(config); // Validates and converts internally
|
|
10164
|
+
* ```
|
|
10165
|
+
*
|
|
10166
|
+
* @public
|
|
10167
|
+
*/
|
|
10168
|
+
declare class ValidatingQualifierTypeFactory<T extends QualifierType = SystemQualifierType> implements IConfigInitFactory<unknown, T | SystemQualifierType> {
|
|
10169
|
+
private readonly _innerFactory;
|
|
10170
|
+
/**
|
|
10171
|
+
* Constructor for a validating qualifier type factory.
|
|
10172
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
10173
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
10174
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
10175
|
+
* - A mix of both
|
|
10176
|
+
*/
|
|
10177
|
+
constructor(factories: Array<IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>>);
|
|
10178
|
+
/**
|
|
10179
|
+
* Creates a qualifier type from a weakly-typed configuration object.
|
|
10180
|
+
* @param config - The configuration object to validate and use for creation.
|
|
10181
|
+
* @returns A result containing the new qualifier type if successful.
|
|
10182
|
+
*/
|
|
10183
|
+
create(config: unknown): Result<T | SystemQualifierType>;
|
|
10184
|
+
}
|
|
10185
|
+
|
|
10186
|
+
/**
|
|
10187
|
+
* A factory that validates and creates {@link ResourceTypes.ResourceType | ResourceType} instances
|
|
10188
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
10189
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
10190
|
+
*
|
|
10191
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
10192
|
+
* branded types across different package instances.
|
|
10193
|
+
*
|
|
10194
|
+
* @public
|
|
10195
|
+
*/
|
|
10196
|
+
declare class ValidatingResourceTypeFactory implements IConfigInitFactory<unknown, ResourceType> {
|
|
10197
|
+
private readonly _innerFactory;
|
|
10198
|
+
/**
|
|
10199
|
+
* Constructor for a validating resource type factory.
|
|
10200
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
10201
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
10202
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
10203
|
+
* - A mix of both
|
|
10204
|
+
*/
|
|
10205
|
+
constructor(factories: Array<IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction>);
|
|
10206
|
+
/**
|
|
10207
|
+
* Creates a resource type from a weakly-typed configuration object.
|
|
10208
|
+
* @param config - The configuration object to validate and use for creation.
|
|
10209
|
+
* @returns A result containing the new resource type if successful.
|
|
10210
|
+
*/
|
|
10211
|
+
create(config: unknown): Result<ResourceType>;
|
|
10212
|
+
}
|
|
10213
|
+
|
|
10103
10214
|
/**
|
|
10104
10215
|
* A {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} with a
|
|
10105
10216
|
* {@link Runtime.Context.ContextQualifierProviderValidator | validator} property that enables
|
|
@@ -3,6 +3,16 @@ import { QualifierType, SystemQualifierType } from '../qualifier-types';
|
|
|
3
3
|
import * as QualifierTypes from '../qualifier-types';
|
|
4
4
|
import * as ResourceTypes from '../resource-types';
|
|
5
5
|
import { ResourceType } from '../resource-types';
|
|
6
|
+
/**
|
|
7
|
+
* Function signature for creating a qualifier type from configuration.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type QualifierTypeFactoryFunction<T extends QualifierType = QualifierType> = (config: QualifierTypes.Config.IAnyQualifierTypeConfig) => Result<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Function signature for creating a resource type from configuration.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export type ResourceTypeFactoryFunction = (config: ResourceTypes.Config.IResourceTypeConfig) => Result<ResourceType>;
|
|
6
16
|
/**
|
|
7
17
|
* Interface for a factory that creates a new instance of a configuration object.
|
|
8
18
|
* @public
|
|
@@ -15,6 +25,20 @@ export interface IConfigInitFactory<TConfig, T> {
|
|
|
15
25
|
*/
|
|
16
26
|
create(config: TConfig): Result<T>;
|
|
17
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a factory function.
|
|
30
|
+
* @param fn - The factory function to wrap.
|
|
31
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function createQualifierTypeFactory<T extends QualifierType = QualifierType>(fn: QualifierTypeFactoryFunction<T>): IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a resource type factory function.
|
|
37
|
+
* @param fn - The factory function to wrap.
|
|
38
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare function createResourceTypeFactory(fn: ResourceTypeFactoryFunction): IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>;
|
|
18
42
|
/**
|
|
19
43
|
* A factory that chains multiple factories together.
|
|
20
44
|
* @public
|
|
@@ -87,12 +111,57 @@ export declare class BuiltInQualifierTypeFactory implements IConfigInitFactory<Q
|
|
|
87
111
|
export declare class QualifierTypeFactory<T extends QualifierType = SystemQualifierType> extends ChainedConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T | SystemQualifierType> {
|
|
88
112
|
/**
|
|
89
113
|
* Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.
|
|
90
|
-
* @param factories - Array of
|
|
114
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
115
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
116
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
117
|
+
* - A mix of both
|
|
91
118
|
* These are tried in order before falling back to built-in types.
|
|
92
119
|
* @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always appended to handle
|
|
93
120
|
* system qualifier types (Language, Territory, Literal).
|
|
94
121
|
*/
|
|
95
|
-
constructor(factories: IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T>
|
|
122
|
+
constructor(factories: Array<IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>>);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A factory that validates and creates {@link QualifierTypes.QualifierType | QualifierType} instances
|
|
126
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
127
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
128
|
+
*
|
|
129
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
130
|
+
* branded types across different package instances.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* // Accept weakly-typed config from external source
|
|
135
|
+
* const validatingFactory = new ValidatingQualifierTypeFactory([customFactory]);
|
|
136
|
+
*
|
|
137
|
+
* // Config can have plain string types instead of branded types
|
|
138
|
+
* const config = {
|
|
139
|
+
* name: 'my-qualifier', // plain string, not QualifierTypeName
|
|
140
|
+
* systemType: 'custom', // plain string
|
|
141
|
+
* configuration: { ... }
|
|
142
|
+
* };
|
|
143
|
+
*
|
|
144
|
+
* const result = validatingFactory.create(config); // Validates and converts internally
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export declare class ValidatingQualifierTypeFactory<T extends QualifierType = SystemQualifierType> implements IConfigInitFactory<unknown, T | SystemQualifierType> {
|
|
150
|
+
private readonly _innerFactory;
|
|
151
|
+
/**
|
|
152
|
+
* Constructor for a validating qualifier type factory.
|
|
153
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
154
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
155
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
156
|
+
* - A mix of both
|
|
157
|
+
*/
|
|
158
|
+
constructor(factories: Array<IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>>);
|
|
159
|
+
/**
|
|
160
|
+
* Creates a qualifier type from a weakly-typed configuration object.
|
|
161
|
+
* @param config - The configuration object to validate and use for creation.
|
|
162
|
+
* @returns A result containing the new qualifier type if successful.
|
|
163
|
+
*/
|
|
164
|
+
create(config: unknown): Result<T | SystemQualifierType>;
|
|
96
165
|
}
|
|
97
166
|
/**
|
|
98
167
|
* A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}.
|
|
@@ -110,9 +179,39 @@ export declare class BuiltInResourceTypeFactory implements IConfigInitFactory<Re
|
|
|
110
179
|
export declare class ResourceTypeFactory extends ChainedConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> {
|
|
111
180
|
/**
|
|
112
181
|
* Constructor for a resource type factory.
|
|
113
|
-
* @param factories -
|
|
182
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
183
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
184
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
185
|
+
* - A mix of both
|
|
114
186
|
* @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.
|
|
115
187
|
*/
|
|
116
|
-
constructor(factories: IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>
|
|
188
|
+
constructor(factories: Array<IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction>);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A factory that validates and creates {@link ResourceTypes.ResourceType | ResourceType} instances
|
|
192
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
193
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
194
|
+
*
|
|
195
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
196
|
+
* branded types across different package instances.
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
export declare class ValidatingResourceTypeFactory implements IConfigInitFactory<unknown, ResourceType> {
|
|
201
|
+
private readonly _innerFactory;
|
|
202
|
+
/**
|
|
203
|
+
* Constructor for a validating resource type factory.
|
|
204
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
205
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
206
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
207
|
+
* - A mix of both
|
|
208
|
+
*/
|
|
209
|
+
constructor(factories: Array<IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction>);
|
|
210
|
+
/**
|
|
211
|
+
* Creates a resource type from a weakly-typed configuration object.
|
|
212
|
+
* @param config - The configuration object to validate and use for creation.
|
|
213
|
+
* @returns A result containing the new resource type if successful.
|
|
214
|
+
*/
|
|
215
|
+
create(config: unknown): Result<ResourceType>;
|
|
117
216
|
}
|
|
118
217
|
//# sourceMappingURL=configInitFactory.d.ts.map
|
|
@@ -54,10 +54,34 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
54
54
|
};
|
|
55
55
|
})();
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.ResourceTypeFactory = exports.BuiltInResourceTypeFactory = exports.QualifierTypeFactory = exports.BuiltInQualifierTypeFactory = exports.ChainedConfigInitFactory = void 0;
|
|
57
|
+
exports.ValidatingResourceTypeFactory = exports.ResourceTypeFactory = exports.BuiltInResourceTypeFactory = exports.ValidatingQualifierTypeFactory = exports.QualifierTypeFactory = exports.BuiltInQualifierTypeFactory = exports.ChainedConfigInitFactory = void 0;
|
|
58
|
+
exports.createQualifierTypeFactory = createQualifierTypeFactory;
|
|
59
|
+
exports.createResourceTypeFactory = createResourceTypeFactory;
|
|
58
60
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
59
61
|
const QualifierTypes = __importStar(require("../qualifier-types"));
|
|
60
62
|
const ResourceTypes = __importStar(require("../resource-types"));
|
|
63
|
+
/**
|
|
64
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a factory function.
|
|
65
|
+
* @param fn - The factory function to wrap.
|
|
66
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
function createQualifierTypeFactory(fn) {
|
|
70
|
+
return {
|
|
71
|
+
create: fn
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a resource type factory function.
|
|
76
|
+
* @param fn - The factory function to wrap.
|
|
77
|
+
* @returns An `IConfigInitFactory` instance that delegates to the function.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
function createResourceTypeFactory(fn) {
|
|
81
|
+
return {
|
|
82
|
+
create: fn
|
|
83
|
+
};
|
|
84
|
+
}
|
|
61
85
|
/**
|
|
62
86
|
* A factory that chains multiple factories together.
|
|
63
87
|
* @public
|
|
@@ -146,16 +170,70 @@ exports.BuiltInQualifierTypeFactory = BuiltInQualifierTypeFactory;
|
|
|
146
170
|
class QualifierTypeFactory extends ChainedConfigInitFactory {
|
|
147
171
|
/**
|
|
148
172
|
* Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.
|
|
149
|
-
* @param factories - Array of
|
|
173
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
174
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
175
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
176
|
+
* - A mix of both
|
|
150
177
|
* These are tried in order before falling back to built-in types.
|
|
151
178
|
* @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always appended to handle
|
|
152
179
|
* system qualifier types (Language, Territory, Literal).
|
|
153
180
|
*/
|
|
154
181
|
constructor(factories) {
|
|
155
|
-
|
|
182
|
+
const normalizedFactories = factories.map((f) => typeof f === 'function' ? createQualifierTypeFactory(f) : f);
|
|
183
|
+
super([...normalizedFactories, new BuiltInQualifierTypeFactory()]);
|
|
156
184
|
}
|
|
157
185
|
}
|
|
158
186
|
exports.QualifierTypeFactory = QualifierTypeFactory;
|
|
187
|
+
/**
|
|
188
|
+
* A factory that validates and creates {@link QualifierTypes.QualifierType | QualifierType} instances
|
|
189
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
190
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
191
|
+
*
|
|
192
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
193
|
+
* branded types across different package instances.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Accept weakly-typed config from external source
|
|
198
|
+
* const validatingFactory = new ValidatingQualifierTypeFactory([customFactory]);
|
|
199
|
+
*
|
|
200
|
+
* // Config can have plain string types instead of branded types
|
|
201
|
+
* const config = {
|
|
202
|
+
* name: 'my-qualifier', // plain string, not QualifierTypeName
|
|
203
|
+
* systemType: 'custom', // plain string
|
|
204
|
+
* configuration: { ... }
|
|
205
|
+
* };
|
|
206
|
+
*
|
|
207
|
+
* const result = validatingFactory.create(config); // Validates and converts internally
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
class ValidatingQualifierTypeFactory {
|
|
213
|
+
/**
|
|
214
|
+
* Constructor for a validating qualifier type factory.
|
|
215
|
+
* @param factories - Array of factories for custom qualifier types. Can be:
|
|
216
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
217
|
+
* - {@link Config.QualifierTypeFactoryFunction | Factory functions}
|
|
218
|
+
* - A mix of both
|
|
219
|
+
*/
|
|
220
|
+
constructor(factories) {
|
|
221
|
+
this._innerFactory = new QualifierTypeFactory(factories);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Creates a qualifier type from a weakly-typed configuration object.
|
|
225
|
+
* @param config - The configuration object to validate and use for creation.
|
|
226
|
+
* @returns A result containing the new qualifier type if successful.
|
|
227
|
+
*/
|
|
228
|
+
create(config) {
|
|
229
|
+
return QualifierTypes.Config.Convert.anyQualifierTypeConfig
|
|
230
|
+
.convert(config)
|
|
231
|
+
.onSuccess((validatedConfig) => {
|
|
232
|
+
return this._innerFactory.create(validatedConfig);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.ValidatingQualifierTypeFactory = ValidatingQualifierTypeFactory;
|
|
159
237
|
/**
|
|
160
238
|
* A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}.
|
|
161
239
|
* @public
|
|
@@ -175,13 +253,50 @@ exports.BuiltInResourceTypeFactory = BuiltInResourceTypeFactory;
|
|
|
175
253
|
class ResourceTypeFactory extends ChainedConfigInitFactory {
|
|
176
254
|
/**
|
|
177
255
|
* Constructor for a resource type factory.
|
|
178
|
-
* @param factories -
|
|
256
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
257
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
258
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
259
|
+
* - A mix of both
|
|
179
260
|
* @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.
|
|
180
261
|
*/
|
|
181
262
|
constructor(factories) {
|
|
182
263
|
factories = factories !== null && factories !== void 0 ? factories : [];
|
|
183
|
-
|
|
264
|
+
const normalizedFactories = factories.map((f) => typeof f === 'function' ? createResourceTypeFactory(f) : f);
|
|
265
|
+
super([...normalizedFactories, new BuiltInResourceTypeFactory()]);
|
|
184
266
|
}
|
|
185
267
|
}
|
|
186
268
|
exports.ResourceTypeFactory = ResourceTypeFactory;
|
|
269
|
+
/**
|
|
270
|
+
* A factory that validates and creates {@link ResourceTypes.ResourceType | ResourceType} instances
|
|
271
|
+
* from weakly-typed configuration objects. This factory accepts configurations with unvalidated
|
|
272
|
+
* string properties and validates them before delegating to the underlying factory chain.
|
|
273
|
+
*
|
|
274
|
+
* This pattern is useful at package boundaries where type identity issues may occur with
|
|
275
|
+
* branded types across different package instances.
|
|
276
|
+
*
|
|
277
|
+
* @public
|
|
278
|
+
*/
|
|
279
|
+
class ValidatingResourceTypeFactory {
|
|
280
|
+
/**
|
|
281
|
+
* Constructor for a validating resource type factory.
|
|
282
|
+
* @param factories - Array of factories for resource types. Can be:
|
|
283
|
+
* - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
|
|
284
|
+
* - {@link Config.ResourceTypeFactoryFunction | Factory functions}
|
|
285
|
+
* - A mix of both
|
|
286
|
+
*/
|
|
287
|
+
constructor(factories) {
|
|
288
|
+
this._innerFactory = new ResourceTypeFactory(factories);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Creates a resource type from a weakly-typed configuration object.
|
|
292
|
+
* @param config - The configuration object to validate and use for creation.
|
|
293
|
+
* @returns A result containing the new resource type if successful.
|
|
294
|
+
*/
|
|
295
|
+
create(config) {
|
|
296
|
+
return ResourceTypes.Config.Convert.resourceTypeConfig.convert(config).onSuccess((validatedConfig) => {
|
|
297
|
+
return this._innerFactory.create(validatedConfig);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.ValidatingResourceTypeFactory = ValidatingResourceTypeFactory;
|
|
187
302
|
//# sourceMappingURL=configInitFactory.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-res",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-29",
|
|
4
4
|
"description": "Multi-dimensional Resource Runtime",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-res.d.ts",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"@rushstack/heft-node-rig": "2.9.5",
|
|
45
45
|
"@types/heft-jest": "1.0.6",
|
|
46
46
|
"eslint-plugin-tsdoc": "~0.4.0",
|
|
47
|
-
"@fgv/ts-
|
|
48
|
-
"@fgv/ts-
|
|
47
|
+
"@fgv/ts-utils-jest": "5.0.0-29",
|
|
48
|
+
"@fgv/ts-extras": "5.0.0-29"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"luxon": "^3.7.2",
|
|
52
52
|
"fflate": "~0.8.2",
|
|
53
|
-
"@fgv/ts-
|
|
54
|
-
"@fgv/ts-
|
|
55
|
-
"@fgv/ts-
|
|
56
|
-
"@fgv/ts-json": "5.0.0-
|
|
53
|
+
"@fgv/ts-utils": "5.0.0-29",
|
|
54
|
+
"@fgv/ts-json-base": "5.0.0-29",
|
|
55
|
+
"@fgv/ts-bcp47": "5.0.0-29",
|
|
56
|
+
"@fgv/ts-json": "5.0.0-29"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "heft build --clean",
|